cvs: php-src /ext/snmp snmp.c
| From: | Harrie Hazewinkel | Date: | Mon, 11 Apr 2005 14:59:43 +0000 |
| Subject: | cvs: php-src /ext/snmp snmp.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-31349@lists.php.net to get a copy of this message | ||
harrie Mon Apr 11 10:59:43 2005 EDT
Modified files:
/php-src/ext/snmp snmp.c
Log:
Converting the usage of the integer based internal commands into
MACROS to ease future extensions.
http://cvs.php.net/diff.php/php-src/ext/snmp/snmp.c?r1=1.99&r2=1.100&ty=u Index: php-src/ext/snmp/snmp.c diff -u php-src/ext/snmp/snmp.c:1.99 php-src/ext/snmp/snmp.c:1.100 --- php-src/ext/snmp/snmp.c:1.99 Mon Apr 11 10:56:44 2005 +++ php-src/ext/snmp/snmp.c Mon Apr 11 10:59:42 2005 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: snmp.c,v 1.99 2005/04/11 14:56:44 harrie Exp $ */ +/* $Id: snmp.c,v 1.100 2005/04/11 14:59:42 harrie Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -146,6 +146,12 @@ }; /* }}} */ +#define SNMP_CMD_GET 1 +#define SNMP_CMD_GETNEXT 2 +#define SNMP_CMD_WALK 3 +#define SNMP_CMD_REALWALK 4 +#define SNMP_CMD_SET 11 + /* {{{ snmp_module_entry */ zend_module_entry snmp_module_entry = { @@ -326,14 +332,13 @@ * * Generic SNMP object fetcher (for all SNMP versions) * -* st=1 get - query an agent with SNMP-GET. -* st=2 getnext - query an agent with SNMP-GETNEXT. -* st=3 walk - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET get - query an agent with SNMP-GET. +* st=SNMP_CMD_GETNEXT getnext - query an agent with SNMP-GETNEXT. +* st=SNMP_CMD_WALK walk - walk the mib and return a single dimensional array * containing the values. -* st=4 realwalk() and walkoid() - walk the mib and return an +* st=SNMP_CMD_REALWALK realwalk() and walkoid() - walk the mib and return an * array of oid,value pairs. -* st=5-8 ** Reserved ** -* st=11 set() - query an agent and set a single value +* st=SNMP_CMD_SET set() - query an agent and set a single value * */ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, @@ -357,7 +362,7 @@ char *err; zval *snmpval = NULL; - if (st >= 3) { /* walk */ + if (st >= SNMP_CMD_WALK) { /* walk */ rootlen = MAX_NAME_LEN; if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */ if (snmp_parse_oid(objid, root, &rootlen)) { @@ -381,12 +386,12 @@ RETURN_FALSE; } - if (st >= 3) { + if (st >= SNMP_CMD_WALK) { memmove((char *)name, (char *)root, rootlen * sizeof(oid)); name_length = rootlen; switch(st) { - case 3: - case 4: + case SNMP_CMD_WALK: + case SNMP_CMD_REALWALK: array_init(return_value); break; default: @@ -397,8 +402,8 @@ while (keepwalking) { keepwalking = 0; - if ((st == 1) || (st == 2)) { - pdu = snmp_pdu_create((st == 1) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT); + if ((st == SNMP_CMD_GET) || (st == SNMP_CMD_GETNEXT)) { + pdu = snmp_pdu_create((st == SNMP_CMD_GET) ? 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); @@ -406,7 +411,7 @@ RETURN_FALSE; } snmp_add_null_var(pdu, name, name_length); - } else if (st == 11) { + } else if (st == SNMP_CMD_SET) { pdu = snmp_pdu_create(SNMP_MSG_SET); if (snmp_add_var(pdu, name, name_length, type, value)) { #ifdef HAVE_NET_SNMP @@ -418,7 +423,7 @@ snmp_close(ss); RETURN_FALSE; } - } else if (st >= 3) { + } else if (st >= SNMP_CMD_WALK) { if (session->version == SNMP_VERSION_1) { pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); } else { @@ -434,29 +439,29 @@ if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { for (vars = response->variables; vars; vars = vars->next_variable) { - if (st >= 3 && st != 11 && + if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { continue; /* not part of this subtree */ } - if (st != 11) { + if (st != SNMP_CMD_SET) { MAKE_STD_ZVAL(snmpval); php_snmp_getvalue(vars, snmpval TSRMLS_CC); } - if (st == 1) { + if (st == SNMP_CMD_GET) { *return_value = *snmpval; zval_copy_ctor(return_value); snmp_close(ss); return; - } else if (st == 2) { + } else if (st == SNMP_CMD_GETNEXT) { *return_value = *snmpval; zval_copy_ctor(return_value); snmp_close(ss); return; - } else if (st == 3) { + } else if (st == SNMP_CMD_WALK) { add_next_index_zval(return_value,snmpval); /* Add to returned array */ - } else if (st == 4) { + } else if (st == SNMP_CMD_REALWALK) { #ifdef HAVE_NET_SNMP snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); #else @@ -464,7 +469,7 @@ #endif add_assoc_zval(return_value,buf2,snmpval); } - if (st >= 3 && st != 11) { + if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET) { if (vars->type != SNMP_ENDOFMIBVIEW && vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) { memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid)); @@ -474,7 +479,7 @@ } } } else { - if (st != 3 || response->errstat != SNMP_ERR_NOSUCHNAME) { + if (st != SNMP_CMD_WALK || 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; @@ -488,19 +493,19 @@ } php_error_docref(NULL TSRMLS_CC, E_WARNING, "This name does not exist: %s",buf); } - if (st == 1) { + if (st == SNMP_CMD_GET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) { goto retry; } - } else if (st == 11) { + } else if (st == SNMP_CMD_SET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) { goto retry; } - } else if (st == 2) { + } else if (st == SNMP_CMD_GETNEXT) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) { goto retry; } - } else if (st >= 3) { /* Here we do walks. */ + } else if (st >= SNMP_CMD_WALK) { /* Here we do walks. */ if ((pdu = snmp_fix_pdu(response, ((session->version == SNMP_VERSION_1) ? SNMP_MSG_GETNEXT : SNMP_MSG_GETBULK))) != NULL) { @@ -513,14 +518,14 @@ } } else if (status == STAT_TIMEOUT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername); - if (st == 3 || st == 4) { + if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) { 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 == 3 || st == 4) { + if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) { zval_dtor(return_value); } snmp_close(ss); @@ -540,14 +545,14 @@ * This function makes use of the internal SNMP object fetcher. * The object fetcher is shared with SNMPv3. * -* st=1 get - query an agent with SNMP-GET. -* st=2 getnext - query an agent with SNMP-GETNEXT. -* st=3 walk - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET get - query an agent with SNMP-GET. +* st=SNMP_CMD_GETNEXT getnext - query an agent with SNMP-GETNEXT. +* st=SNMP_CMD_WALK walk - walk the mib and return a single dimensional array * containing the values. -* st=4 realwalk() and walkoid() - walk the mib and return an +* st=SNMP_CMD_REALWALK realwalk() and walkoid() - walk the mib and return an * array of oid,value pairs. * st=5-8 ** Reserved ** -* st=11 set() - query an agent and set a single value +* st=SNMP_CMD_SET set() - query an agent and set a single value * */ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) @@ -572,7 +577,7 @@ convert_to_string_ex(a2); convert_to_string_ex(a3); - if (st == 11) { + if (st == SNMP_CMD_SET) { if (myargc < 5) { WRONG_PARAM_COUNT; } @@ -638,7 +643,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmpget) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_1); } /* }}} */ @@ -646,7 +651,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmpgetnext) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_1); } /* }}} */ @@ -654,7 +659,7 @@ Return all objects under the specified object id */ PHP_FUNCTION(snmpwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_1); } /* }}} */ @@ -662,7 +667,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmprealwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_1); } /* }}} */ @@ -740,7 +745,7 @@ Set the value of a SNMP object */ PHP_FUNCTION(snmpset) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_1); } /* }}} */ @@ -913,7 +918,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmp2_get) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_2c); } /* }}} */ @@ -921,7 +926,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmp2_getnext) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_2c); } /* }}} */ @@ -929,7 +934,7 @@ Return all objects under the specified object id */ PHP_FUNCTION(snmp2_walk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_2c); } /* }}} */ @@ -937,7 +942,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmp2_real_walk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_2c); } /* }}} */ @@ -945,7 +950,7 @@ Set the value of a SNMP object */ PHP_FUNCTION(snmp2_set) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_2c); } /* }}} */ @@ -954,13 +959,13 @@ * Generic SNMPv3 object fetcher * 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_getnext() - query an agent and return the next single value. -* st=3 snmp3_walk() - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET snmp3_get() - query an agent and return a single value. +* st=SNMP_CMD_GETNEXT snmp3_getnext() - query an agent and return the next single value. +* st=SNMP_CMD_WALK snmp3_walk() - walk the mib and return a single dimensional array * containing the values. -* st=4 snmp3_real_walk() - walk the mib and return an +* st=SNMP_CMD_REALWALK 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 +* st=SNMP_CMD_SET snmp3_set() - query an agent and set a single value * */ static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st) @@ -1038,7 +1043,7 @@ RETURN_FALSE; } - if (st == 11) { + if (st == SNMP_CMD_SET) { if (myargc < 10) { WRONG_PARAM_COUNT; } @@ -1076,7 +1081,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_get) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET); } /* }}} */ @@ -1084,7 +1089,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_getnext) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT); } /* }}} */ @@ -1092,7 +1097,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK); } /* }}} */ @@ -1100,7 +1105,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_real_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 4); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_REALWALK); } /* }}} */ @@ -1108,7 +1113,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_set) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 11); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET); } /* }}} */
http://cvs.php.net/diff.php/php-src/ext/snmp/snmp.c?r1=1.99&r2=1.100&ty=u Index: php-src/ext/snmp/snmp.c diff -u php-src/ext/snmp/snmp.c:1.99 php-src/ext/snmp/snmp.c:1.100 --- php-src/ext/snmp/snmp.c:1.99 Mon Apr 11 10:56:44 2005 +++ php-src/ext/snmp/snmp.c Mon Apr 11 10:59:42 2005 @@ -20,7 +20,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: snmp.c,v 1.99 2005/04/11 14:56:44 harrie Exp $ */ +/* $Id: snmp.c,v 1.100 2005/04/11 14:59:42 harrie Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -146,6 +146,12 @@ }; /* }}} */ +#define SNMP_CMD_GET 1 +#define SNMP_CMD_GETNEXT 2 +#define SNMP_CMD_WALK 3 +#define SNMP_CMD_REALWALK 4 +#define SNMP_CMD_SET 11 + /* {{{ snmp_module_entry */ zend_module_entry snmp_module_entry = { @@ -326,14 +332,13 @@ * * Generic SNMP object fetcher (for all SNMP versions) * -* st=1 get - query an agent with SNMP-GET. -* st=2 getnext - query an agent with SNMP-GETNEXT. -* st=3 walk - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET get - query an agent with SNMP-GET. +* st=SNMP_CMD_GETNEXT getnext - query an agent with SNMP-GETNEXT. +* st=SNMP_CMD_WALK walk - walk the mib and return a single dimensional array * containing the values. -* st=4 realwalk() and walkoid() - walk the mib and return an +* st=SNMP_CMD_REALWALK realwalk() and walkoid() - walk the mib and return an * array of oid,value pairs. -* st=5-8 ** Reserved ** -* st=11 set() - query an agent and set a single value +* st=SNMP_CMD_SET set() - query an agent and set a single value * */ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, @@ -357,7 +362,7 @@ char *err; zval *snmpval = NULL; - if (st >= 3) { /* walk */ + if (st >= SNMP_CMD_WALK) { /* walk */ rootlen = MAX_NAME_LEN; if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */ if (snmp_parse_oid(objid, root, &rootlen)) { @@ -381,12 +386,12 @@ RETURN_FALSE; } - if (st >= 3) { + if (st >= SNMP_CMD_WALK) { memmove((char *)name, (char *)root, rootlen * sizeof(oid)); name_length = rootlen; switch(st) { - case 3: - case 4: + case SNMP_CMD_WALK: + case SNMP_CMD_REALWALK: array_init(return_value); break; default: @@ -397,8 +402,8 @@ while (keepwalking) { keepwalking = 0; - if ((st == 1) || (st == 2)) { - pdu = snmp_pdu_create((st == 1) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT); + if ((st == SNMP_CMD_GET) || (st == SNMP_CMD_GETNEXT)) { + pdu = snmp_pdu_create((st == SNMP_CMD_GET) ? 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); @@ -406,7 +411,7 @@ RETURN_FALSE; } snmp_add_null_var(pdu, name, name_length); - } else if (st == 11) { + } else if (st == SNMP_CMD_SET) { pdu = snmp_pdu_create(SNMP_MSG_SET); if (snmp_add_var(pdu, name, name_length, type, value)) { #ifdef HAVE_NET_SNMP @@ -418,7 +423,7 @@ snmp_close(ss); RETURN_FALSE; } - } else if (st >= 3) { + } else if (st >= SNMP_CMD_WALK) { if (session->version == SNMP_VERSION_1) { pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); } else { @@ -434,29 +439,29 @@ if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { for (vars = response->variables; vars; vars = vars->next_variable) { - if (st >= 3 && st != 11 && + if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { continue; /* not part of this subtree */ } - if (st != 11) { + if (st != SNMP_CMD_SET) { MAKE_STD_ZVAL(snmpval); php_snmp_getvalue(vars, snmpval TSRMLS_CC); } - if (st == 1) { + if (st == SNMP_CMD_GET) { *return_value = *snmpval; zval_copy_ctor(return_value); snmp_close(ss); return; - } else if (st == 2) { + } else if (st == SNMP_CMD_GETNEXT) { *return_value = *snmpval; zval_copy_ctor(return_value); snmp_close(ss); return; - } else if (st == 3) { + } else if (st == SNMP_CMD_WALK) { add_next_index_zval(return_value,snmpval); /* Add to returned array */ - } else if (st == 4) { + } else if (st == SNMP_CMD_REALWALK) { #ifdef HAVE_NET_SNMP snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length); #else @@ -464,7 +469,7 @@ #endif add_assoc_zval(return_value,buf2,snmpval); } - if (st >= 3 && st != 11) { + if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET) { if (vars->type != SNMP_ENDOFMIBVIEW && vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) { memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid)); @@ -474,7 +479,7 @@ } } } else { - if (st != 3 || response->errstat != SNMP_ERR_NOSUCHNAME) { + if (st != SNMP_CMD_WALK || 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; @@ -488,19 +493,19 @@ } php_error_docref(NULL TSRMLS_CC, E_WARNING, "This name does not exist: %s",buf); } - if (st == 1) { + if (st == SNMP_CMD_GET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) { goto retry; } - } else if (st == 11) { + } else if (st == SNMP_CMD_SET) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) { goto retry; } - } else if (st == 2) { + } else if (st == SNMP_CMD_GETNEXT) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) { goto retry; } - } else if (st >= 3) { /* Here we do walks. */ + } else if (st >= SNMP_CMD_WALK) { /* Here we do walks. */ if ((pdu = snmp_fix_pdu(response, ((session->version == SNMP_VERSION_1) ? SNMP_MSG_GETNEXT : SNMP_MSG_GETBULK))) != NULL) { @@ -513,14 +518,14 @@ } } else if (status == STAT_TIMEOUT) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername); - if (st == 3 || st == 4) { + if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) { 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 == 3 || st == 4) { + if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) { zval_dtor(return_value); } snmp_close(ss); @@ -540,14 +545,14 @@ * This function makes use of the internal SNMP object fetcher. * The object fetcher is shared with SNMPv3. * -* st=1 get - query an agent with SNMP-GET. -* st=2 getnext - query an agent with SNMP-GETNEXT. -* st=3 walk - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET get - query an agent with SNMP-GET. +* st=SNMP_CMD_GETNEXT getnext - query an agent with SNMP-GETNEXT. +* st=SNMP_CMD_WALK walk - walk the mib and return a single dimensional array * containing the values. -* st=4 realwalk() and walkoid() - walk the mib and return an +* st=SNMP_CMD_REALWALK realwalk() and walkoid() - walk the mib and return an * array of oid,value pairs. * st=5-8 ** Reserved ** -* st=11 set() - query an agent and set a single value +* st=SNMP_CMD_SET set() - query an agent and set a single value * */ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) @@ -572,7 +577,7 @@ convert_to_string_ex(a2); convert_to_string_ex(a3); - if (st == 11) { + if (st == SNMP_CMD_SET) { if (myargc < 5) { WRONG_PARAM_COUNT; } @@ -638,7 +643,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmpget) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_1); } /* }}} */ @@ -646,7 +651,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmpgetnext) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_1); } /* }}} */ @@ -654,7 +659,7 @@ Return all objects under the specified object id */ PHP_FUNCTION(snmpwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_1); } /* }}} */ @@ -662,7 +667,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmprealwalk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_1); } /* }}} */ @@ -740,7 +745,7 @@ Set the value of a SNMP object */ PHP_FUNCTION(snmpset) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11, SNMP_VERSION_1); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_1); } /* }}} */ @@ -913,7 +918,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmp2_get) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_2c); } /* }}} */ @@ -921,7 +926,7 @@ Fetch a SNMP object */ PHP_FUNCTION(snmp2_getnext) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_2c); } /* }}} */ @@ -929,7 +934,7 @@ Return all objects under the specified object id */ PHP_FUNCTION(snmp2_walk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_2c); } /* }}} */ @@ -937,7 +942,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmp2_real_walk) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_2c); } /* }}} */ @@ -945,7 +950,7 @@ Set the value of a SNMP object */ PHP_FUNCTION(snmp2_set) { - php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11, SNMP_VERSION_2c); + php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_2c); } /* }}} */ @@ -954,13 +959,13 @@ * Generic SNMPv3 object fetcher * 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_getnext() - query an agent and return the next single value. -* st=3 snmp3_walk() - walk the mib and return a single dimensional array +* st=SNMP_CMD_GET snmp3_get() - query an agent and return a single value. +* st=SNMP_CMD_GETNEXT snmp3_getnext() - query an agent and return the next single value. +* st=SNMP_CMD_WALK snmp3_walk() - walk the mib and return a single dimensional array * containing the values. -* st=4 snmp3_real_walk() - walk the mib and return an +* st=SNMP_CMD_REALWALK 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 +* st=SNMP_CMD_SET snmp3_set() - query an agent and set a single value * */ static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st) @@ -1038,7 +1043,7 @@ RETURN_FALSE; } - if (st == 11) { + if (st == SNMP_CMD_SET) { if (myargc < 10) { WRONG_PARAM_COUNT; } @@ -1076,7 +1081,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_get) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET); } /* }}} */ @@ -1084,7 +1089,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_getnext) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT); } /* }}} */ @@ -1092,7 +1097,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK); } /* }}} */ @@ -1100,7 +1105,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_real_walk) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 4); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_REALWALK); } /* }}} */ @@ -1108,7 +1113,7 @@ Fetch the value of a SNMP object */ PHP_FUNCTION(snmp3_set) { - php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 11); + php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET); } /* }}} */