cvs commit

From: Date: Sun, 11 Jul 1999 20:25:36 +0000
Subject: cvs commit
Groups: php.dev 
Request: Send a blank email to php-dev+get-8367@lists.php.net to get a copy of this message
From: slawrance Date: Sun Jul 11 20:25:36 1999 Modified files: php3/functions/php3_snmp.h php3/functions/snmp.c Log message: Added int snmpset(string host, string community, string object_id, string type, mixed value [, int timeout [, int retries]]), which is a function that will set the value associated with an OID on the given host and community. On lines 352, 360, 368, and 376, "return" (lowercase) was removed because SGI's compiler on IRIX6.5 considered a return of a value in a void function to be an error. Index: php3/functions/php3_snmp.h diff -u php3/functions/php3_snmp.h:1.5 php3/functions/php3_snmp.h:1.6 --- php3/functions/php3_snmp.h:1.5 Sat May 22 03:04:13 1999 +++ php3/functions/php3_snmp.h Sun Jul 11 20:25:36 1999 @@ -25,9 +25,10 @@ +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Mike Jackson <mhjack@tscnet.com> | + | Steven Lawrance <slawrance@technologist.com> | +----------------------------------------------------------------------+ */ -/* $Id: php3_snmp.h,v 1.5 1999/05/22 07:04:13 mhjack Exp $ */ +/* $Id: php3_snmp.h,v 1.6 1999/07/12 00:25:36 slawrance Exp $ */ #ifndef _PHP3_SNMP_H #define _PHP3_SNMP_H @@ -50,6 +51,7 @@ extern PHP_FUNCTION(snmpwalkoid); extern PHP_FUNCTION(snmp_get_quick_print); extern PHP_FUNCTION(snmp_set_quick_print); +extern PHP_FUNCTION(snmpset); extern void php3_info_snmp(void); #else Index: php3/functions/snmp.c diff -u php3/functions/snmp.c:1.17 php3/functions/snmp.c:1.18 --- php3/functions/snmp.c:1.17 Wed Jun 30 15:26:25 1999 +++ php3/functions/snmp.c Sun Jul 11 20:25:36 1999 @@ -25,9 +25,10 @@ +----------------------------------------------------------------------+ | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | | Mike Jackson <mhjack@tscnet.com> | + | Steven Lawrance <slawrance@technologist.com> | +----------------------------------------------------------------------+ */ -/* $Id: snmp.c,v 1.17 1999/06/30 19:26:25 jim Exp $ */ +/* $Id: snmp.c,v 1.18 1999/07/12 00:25:36 slawrance Exp $ */ #include "php.h" #include "internal_functions.h" @@ -95,6 +96,7 @@ PHP_FE(snmpwalkoid, NULL) PHP_FE(snmp_get_quick_print, NULL) PHP_FE(snmp_set_quick_print, NULL) + PHP_FE(snmpset, NULL) {NULL,NULL,NULL} }; @@ -130,10 +132,11 @@ * st=9 snmp_get_quick_print() - Return the current value for quickprint * (default setting is 0 (false)). * st=10 snmp_set_quick_print() - Set the current value for quickprint + * st=11 snmpset() - query an agent and set a single value * */ void _php3_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) { - pval *a1, *a2, *a3, *a4, *a5; + pval *a1, *a2, *a3, *a4, *a5, *a6, *a7; struct snmp_session session, *ss; struct snmp_pdu *pdu=NULL, *response; struct variable_list *vars; @@ -148,6 +151,8 @@ long timeout=SNMP_DEFAULT_TIMEOUT; long retries=SNMP_DEFAULT_RETRIES; int myargc = ARG_COUNT(ht); + char type; + char *value; switch(st) { case 4: @@ -162,19 +167,35 @@ RETURN_TRUE; } - if (myargc<3 || myargc>5 || getParameters(ht, myargc, &a1, &a2, &a3, &a4, &a5) == FAILURE) { + if (myargc<3 || myargc>7 || getParameters(ht, myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(a1); convert_to_string(a2); convert_to_string(a3); - if(myargc>3) { - convert_to_long(a4); - timeout=a4->value.lval; - } - if(myargc>4) { - convert_to_long(a5); - retries=a5->value.lval; + if (st==11) { + if (myargc<5) WRONG_PARAM_COUNT; + convert_to_string(a4); + convert_to_string(a5); + if(myargc>6) { + convert_to_long(a6); + timeout=a6->value.lval; + } + if(myargc>7) { + convert_to_long(a7); + retries=a7->value.lval; + } + type = a4->value.str.val[0]; + value = a5->value.str.val; + } else { + if(myargc>3) { + convert_to_long(a4); + timeout=a4->value.lval; + } + if(myargc>4) { + convert_to_long(a5); + retries=a5->value.lval; + } } objid=a3->value.str.val; @@ -230,6 +251,7 @@ while(keepwalking) { keepwalking=0; if (st==1) pdu = snmp_pdu_create(SNMP_MSG_GET); + else if (st==11) pdu = snmp_pdu_create(SNMP_MSG_SET); else if (st>=2) pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); if (st==1) { @@ -238,18 +260,26 @@ php3_error(E_WARNING,"Invalid object identifier: %s\n", objid); RETURN_FALSE; } + } + if (st!=11) + snmp_add_null_var(pdu, name, name_length); + else { + if (snmp_add_var(pdu, name, name_length, type, value)) { + php3_error(E_WARNING,"Could not add variable: %s\n", name); + RETURN_FALSE; + } } - snmp_add_null_var(pdu, name, name_length); retry: status = snmp_synch_response(ss, pdu, &response); if (status == STAT_SUCCESS) { if (response->errstat == SNMP_ERR_NOERROR) { for(vars = response->variables; vars; vars = vars->next_variable) { - if (st>=2 && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) + if (st>=2 && st!=11 && (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) continue; /* not part of this subtree */ - sprint_value(buf,vars->name, vars->name_length, vars); + if (st!=11) + sprint_value(buf,vars->name, vars->name_length, vars); #if 0 Debug("snmp response is: %s\n",buf); #endif @@ -262,7 +292,7 @@ sprint_objid(buf2, vars->name, vars->name_length); add_assoc_string(return_value,buf2,buf,1); } - if (st>=2) { + if (st>=2 && 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)); name_length = vars->name_length; @@ -281,6 +311,8 @@ } if (st==1) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) goto retry; + } else if (st==11) { + if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) goto retry; } else if (st>=2) { if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) goto retry; } @@ -317,7 +349,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmprealwalk) { - return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3); + _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3); } /* }}} */ @@ -325,7 +357,7 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmpwalkoid) { - return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4); + _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,4); } /* }}} */ @@ -333,7 +365,7 @@ Return the current status of quick_print */ PHP_FUNCTION(snmp_get_quick_print) { - return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,9); + _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,9); } /* }}} */ @@ -341,10 +373,17 @@ Return all objects including their respective object id withing the specified one */ PHP_FUNCTION(snmp_set_quick_print) { - return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,10); + _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,10); } /* }}} */ +/* {{{ proto int snmpset(string host, string community, string object_id, string type, mixed value [, int timeout [, int retries]]) + Fetch an SNMP object */ +void php3_snmpset(INTERNAL_FUNCTION_PARAMETERS) { + _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11); +} +/* }}} */ + #endif

« previous php.dev (#8367) next »