diff options
author | Harrie Hazewinkel <harrie@php.net> | 2005-04-11 14:59:42 +0000 |
---|---|---|
committer | Harrie Hazewinkel <harrie@php.net> | 2005-04-11 14:59:42 +0000 |
commit | e9224d0bd1e06028f8f40257a736a00216fefe66 (patch) | |
tree | ba4b22ea5b304419ff66a007f0c219f2b50f0d6c /ext/snmp/snmp.c | |
parent | 452b4cdba162a458b814c5f2144521eab3f5570f (diff) | |
download | php-git-e9224d0bd1e06028f8f40257a736a00216fefe66.tar.gz |
Converting the usage of the integer based internal commands into
MACROS to ease future extensions.
Diffstat (limited to 'ext/snmp/snmp.c')
-rw-r--r-- | ext/snmp/snmp.c | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 2ae7a69176..da2bd2e38f 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -146,6 +146,12 @@ function_entry snmp_functions[] = { }; /* }}} */ +#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 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D * * 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 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 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 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 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 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 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 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 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 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 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 @@ retry: 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 @@ retry: #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 @@ retry: } } } 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 @@ retry: } 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 @@ retry: } } 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 @@ retry: * 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 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) 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 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) 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 @@ PHP_FUNCTION(snmpget) 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 @@ PHP_FUNCTION(snmpgetnext) 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 @@ PHP_FUNCTION(snmpwalk) 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 @@ PHP_FUNCTION(snmp_set_oid_numeric_print) 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 @@ static int netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass TSRM 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 @@ PHP_FUNCTION(snmp2_get) 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 @@ PHP_FUNCTION(snmp2_getnext) 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 @@ PHP_FUNCTION(snmp2_walk) 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 @@ PHP_FUNCTION(snmp2_real_walk) 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 @@ PHP_FUNCTION(snmp2_set) * 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 @@ static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st) RETURN_FALSE; } - if (st == 11) { + if (st == SNMP_CMD_SET) { if (myargc < 10) { WRONG_PARAM_COUNT; } @@ -1076,7 +1081,7 @@ static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st) 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 @@ PHP_FUNCTION(snmp3_get) 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 @@ PHP_FUNCTION(snmp3_getnext) 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 @@ PHP_FUNCTION(snmp3_walk) 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 @@ PHP_FUNCTION(snmp3_real_walk) 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); } /* }}} */ |