cvs: php-src /ext/snmp php_snmp.h snmp.c

From: Date: Mon, 14 Jul 2003 18:10:22 +0000
Subject: cvs: php-src /ext/snmp php_snmp.h snmp.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-22553@lists.php.net to get a copy of this message
harrie Mon Jul 14 14:10:22 2003 EDT Modified files: /php-src/ext/snmp php_snmp.h snmp.c Log: Adding an SNMP GETNEXT. This is a basic SNMP operation that retrieves the next value as the one provided to the command. NOTE: snmpgetnext does not follow the official naming convetions of functions, but now it is equal to it version 1 equivalents snmpget and snmpset. I also would like to reserve the snmp_getnext for a function to which a session can be given instead of the multiple values to create the session internally. (Work in progress).

Index: php-src/ext/snmp/php_snmp.h diff -u php-src/ext/snmp/php_snmp.h:1.19 php-src/ext/snmp/php_snmp.h:1.20 --- php-src/ext/snmp/php_snmp.h:1.19 Mon Jul 14 13:11:04 2003 +++ php-src/ext/snmp/php_snmp.h Mon Jul 14 14:10:22 2003 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_snmp.h,v 1.19 2003/07/14 17:11:04 harrie Exp $ */ +/* $Id: php_snmp.h,v 1.20 2003/07/14 18:10:22 harrie Exp $ */ #ifndef PHP_SNMP_H #define PHP_SNMP_H @@ -42,6 +42,7 @@ PHP_MINFO_FUNCTION(snmp); PHP_FUNCTION(snmpget); +PHP_FUNCTION(snmpgetnext); PHP_FUNCTION(snmpwalk); PHP_FUNCTION(snmprealwalk); PHP_FUNCTION(snmp_get_quick_print); @@ -51,6 +52,7 @@ PHP_FUNCTION(snmpset); PHP_FUNCTION(snmp3_get); +PHP_FUNCTION(snmp3_getnext); PHP_FUNCTION(snmp3_walk); PHP_FUNCTION(snmp3_real_walk); PHP_FUNCTION(snmp3_set); Index: php-src/ext/snmp/snmp.c diff -u php-src/ext/snmp/snmp.c:1.79 php-src/ext/snmp/snmp.c:1.80 --- php-src/ext/snmp/snmp.c:1.79 Mon Jul 14 13:34:56 2003 +++ php-src/ext/snmp/snmp.c Mon Jul 14 14:10:22 2003 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: snmp.c,v 1.79 2003/07/14 17:34:56 harrie Exp $ */ +/* $Id: snmp.c,v 1.80 2003/07/14 18:10:22 harrie Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -117,6 +117,7 @@ */ function_entry snmp_functions[] = { PHP_FE(snmpget, NULL) + PHP_FE(snmpgetnext, NULL) PHP_FE(snmpwalk, NULL) PHP_FE(snmprealwalk, NULL) PHP_FALIAS(snmpwalkoid, snmprealwalk, NULL) @@ -129,6 +130,7 @@ PHP_FE(snmpset, NULL) PHP_FE(snmp3_get, NULL) + PHP_FE(snmp3_getnext, NULL) PHP_FE(snmp3_walk, NULL) PHP_FE(snmp3_real_walk, NULL) PHP_FE(snmp3_set, NULL) @@ -307,9 +309,10 @@ * Generic SNMP object fetcher (for both v3 and v1) * * st=1 snmpget() - query an agent and return a single value. -* st=2 snmpwalk() - walk the mib and return a single dimensional array +* st=2 snmpget() - query an agent and return the next single value. +* st=3 snmpwalk() - walk the mib and return a single dimensional array * containing the values. -* st=3 snmprealwalk() and snmpwalkoid() - walk the mib and return an +* st=4 snmprealwalk() and snmpwalkoid() - walk the mib and return an * array of oid,value pairs. * st=5-8 ** Reserved ** * st=11 snmpset() - query an agent and set a single value @@ -336,7 +339,7 @@ char *err; zval *snmpval; - if (st >= 2) { /* walk */ + if (st >= 3) { /* walk */ rootlen = MAX_NAME_LEN; if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */ if (read_objid(objid, root, &rootlen)) { @@ -360,12 +363,12 @@ RETURN_FALSE; } - if (st >= 2) { + if (st >= 3) { memmove((char *)name, (char *)root, rootlen * sizeof(oid)); name_length = rootlen; switch(st) { - case 2: case 3: + case 4: array_init(return_value); break; default: @@ -376,8 +379,8 @@ while (keepwalking) { keepwalking = 0; - if (st == 1) { - pdu = snmp_pdu_create(SNMP_MSG_GET); + if ((st == 1) || (st == 2)) { + pdu = snmp_pdu_create((st == 1) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT); name_length = MAX_OID_LEN; if (!snmp_parse_oid(objid, name, &name_length)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid); @@ -397,7 +400,7 @@ snmp_close(ss); RETURN_FALSE; } - } else if (st >= 2) { + } else if (st >= 3) { pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); snmp_add_null_var(pdu, name, name_length); } @@ -407,7 +410,7 @@ if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { for (vars = response->variables; vars; vars = vars->next_variable) { - if (st >= 2 && st != 11 && + if (st >= 3 && st != 11 && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { continue; /* not part of this subtree */ } @@ -422,8 +425,12 @@ zval_copy_ctor(return_value); return; } else if (st == 2) { + *return_value = *snmpval; + zval_copy_ctor(return_value); + return; + } else if (st == 3) { add_next_index_zval(return_value,snmpval); /* Add to returned array */ - } else if (st == 3) { + } else if (st == 4) { #ifdef HAVE_NET_SNMP snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); #else @@ -431,7 +438,7 @@ #endif add_assoc_zval(return_value,buf2,snmpval); } - if (st >= 2 && st != 11) { + if (st >= 3 && st != 11) { if (vars->type != SNMP_ENDOFMIBVIEW && vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) { memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid)); @@ -441,7 +448,7 @@ } } } else { - if (st != 2 || response->errstat != SNMP_ERR_NOSUCHNAME) { + if (st != 3 || response->errstat != SNMP_ERR_NOSUCHNAME) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet: %s", snmp_errstring(response->errstat)); if (response->errstat == SNMP_ERR_NOSUCHNAME) { for (count=1, vars = response->variables; vars && count != response->errindex; @@ -463,7 +470,7 @@ if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) { goto retry; } - } else if (st >= 2) { + } else if (st >= 2) { /* Here we do both getnext and walks. */ if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) { goto retry; } @@ -474,14 +481,14 @@ } } else if (status == STAT_TIMEOUT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername); - if (st == 2 || st == 3) { + if (st == 3 || st == 4) { zval_dtor(return_value); } snmp_close(ss); RETURN_FALSE; } else { /* status == STAT_ERROR */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred, quitting"); - if (st == 2 || st == 3) { + if (st == 3 || st == 4) { zval_dtor(return_value); } snmp_close(ss); @@ -502,9 +509,10 @@ * The object fetcher is shared with SNMPv3. * * st=1 snmpget() - query an agent and return a single value. -* st=2 snmpwalk() - walk the mib and return a single dimensional array +* st=2 snmpgetnext() - query an agent and return the next single value. +* st=3 snmpwalk() - walk the mib and return a single dimensional array * containing the values. -* st=3 snmprealwalk() and snmpwalkoid() - walk the mib and return an +* st=4 snmprealwalk() and snmpwalkoid() - walk the mib and return an * array of oid,value pairs. * st=5-8 ** Reserved ** * st=11 snmpset() - query an agent and set a single value @@ -603,11 +611,19 @@ } /* }}} */ +/* {{{ proto string snmpgetnext(string host, string community, string object_id [, int timeout [, int retries]]) + Fetch a SNMP object */ +PHP_FUNCTION(snmpgetnext) +{ + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2); +} +/* }}} */ + /* {{{ proto array snmpwalk(string host, string community, string object_id [, int timeout [, int retries]]) Return all objects under the specified object id */ PHP_FUNCTION(snmpwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3); } /* }}} */ @@ -615,7 +631,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmprealwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4); } /* }}} */ @@ -851,9 +867,10 @@ * From here is passed on the the common internal object fetcher. * * st=1 snmp3_get() - query an agent and return a single value. -* st=2 snmp3_walk() - walk the mib and return a single dimensional array +* st=2 snmp3_getnext() - query an agent and return the next single value. +* st=3 snmp3_walk() - walk the mib and return a single dimensional array * containing the values. -* st=3 snmp3_real_walk() - walk the mib and return an +* st=4 snmp3_real_walk() - walk the mib and return an * array of oid,value pairs. * st=11 snmp3_set() - query an agent and set a single value * @@ -976,12 +993,21 @@ } /* }}} */ +/* {{{ proto int snmp3_getnext(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]]) + Fetch the value of a SNMP object */ +PHP_FUNCTION(snmp3_getnext) +{ + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); +} +/* }}} */ + +/* {{{ proto int snmp3_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]]) /* {{{ proto int snmp3_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]]) Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); } /* }}} */ @@ -989,7 +1015,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_real_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 4); } /* }}} */
« previous php.cvs (#22553) next »