CVS update: php31/ext/snmp

From: Date: Sat, 19 Sep 1998 16:50:28 +0000
Subject: CVS update: php31/ext/snmp
Groups: php.dev 
Request: Send a blank email to php-dev+get-1258@lists.php.net to get a copy of this message
Date: Saturday September 19, 1998 @ 12:50 Author: rasmus Update of /repository/php31/ext/snmp In directory asf:/u2/tmp/cvs-serv9915/ext/snmp Modified Files: php3_snmp.h readme snmp.c Added Files: configure.in.stub Log Message: Bring SNMP and LDAP modules up to date Index: php31/ext/snmp/php3_snmp.h diff -c php31/ext/snmp/php3_snmp.h:2.0 php31/ext/snmp/php3_snmp.h:2.1 *** php31/ext/snmp/php3_snmp.h:2.0 Fri Jul 3 09:14:04 1998 --- php31/ext/snmp/php3_snmp.h Sat Sep 19 12:50:27 1998 *************** *** 26,32 **** | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: php3_snmp.h,v 2.0 1998/07/03 13:14:04 rasmus Exp $ */ #ifndef _PHP3_SNMP_H #define _PHP3_SNMP_H --- 26,32 ---- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: php3_snmp.h,v 2.1 1998/09/19 16:50:27 rasmus Exp $ */ #ifndef _PHP3_SNMP_H #define _PHP3_SNMP_H *************** *** 34,51 **** #undef HAVE_SNMP #define HAVE_SNMP 1 #endif #ifndef DLEXPORT #define DLEXPORT #endif - #if HAVE_SNMP - extern php3_module_entry snmp_module_entry; #define snmp_module_ptr &snmp_module_entry - - extern DLEXPORT void php3_snmpget(INTERNAL_FUNCTION_PARAMETERS); - extern DLEXPORT void php3_snmpwalk(INTERNAL_FUNCTION_PARAMETERS); #else #define snmp_module_ptr NULL --- 34,51 ---- #undef HAVE_SNMP #define HAVE_SNMP 1 #endif + #if HAVE_SNMP #ifndef DLEXPORT #define DLEXPORT #endif extern php3_module_entry snmp_module_entry; #define snmp_module_ptr &snmp_module_entry + extern int php3i_snmp_init(INIT_FUNC_ARGS); + extern void php3_snmpget(INTERNAL_FUNCTION_PARAMETERS); + extern void php3_snmpwalk(INTERNAL_FUNCTION_PARAMETERS); + extern void php3_info_snmp(void); #else #define snmp_module_ptr NULL Index: php31/ext/snmp/readme diff -c php31/ext/snmp/readme:2.0 php31/ext/snmp/readme:2.1 *** php31/ext/snmp/readme:2.0 Fri Jul 3 09:14:05 1998 --- php31/ext/snmp/readme Sat Sep 19 12:50:27 1998 *************** *** 10,37 **** Installation ! You first need to get a hold of ucd-snmp-3.2. This extension ! hasn't been tested with any other version. ! Compile and install it. Make sure the following header files from ! the ucd-3.2/snmplib directory get copied to /usr/local/include, ! or wherever dl/Makefile tries to include files from. - asn1.h, snmp_api.h, snmp_client.h, snmp_impl.h, snmp.h, parse.h - - Then type: make snmp.so - from the php3/dl directory. - - If there is no Makefile, run ./setup - - You may also need to add some -I<path> statements to the CC line. - - - How to call it from PHP3 - - On the page where you need to make an SNMP call, load the library: - - <? dl("<path>/snmp.so"); ?> - To fetch an object: <? $value = snmpget("hostname","community","object_id"); ?> --- 10,18 ---- Installation ! You first need to get a hold of ucd-snmp-3.5 or greater. ! Compile and install it. To fetch an object: <? $value = snmpget("hostname","community","object_id"); ?> *************** *** 47,49 **** --- 28,32 ---- echo $a[$i]; } + Both snmpget and snmpwalk take two extra optional arguments. A timeout (in seconds) + and a number of retries argument. Index: php31/ext/snmp/snmp.c diff -c php31/ext/snmp/snmp.c:2.1 php31/ext/snmp/snmp.c:2.2 *** php31/ext/snmp/snmp.c:2.1 Fri Jul 3 12:24:42 1998 --- php31/ext/snmp/snmp.c Sat Sep 19 12:50:27 1998 *************** *** 26,41 **** | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: snmp.c,v 2.1 1998/07/03 16:24:42 ssb Exp $ */ - #ifndef __P - #define __P(p) p - #endif - #include "php.h" ! ! #if HAVE_SNMP ! #if COMPILE_DL #include "phpdl.h" #include "functions/dl.h" #endif --- 26,36 ---- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | +----------------------------------------------------------------------+ */ ! /* $Id: snmp.c,v 2.2 1998/09/19 16:50:27 rasmus Exp $ */ #include "php.h" ! #include "internal_functions.h" ! #if defined(COMPILE_DL) #include "phpdl.h" #include "functions/dl.h" #endif *************** *** 56,70 **** #ifdef HAVE_UNISTD_H #include <unistd.h> #endif ! #include "asn1.h" #include "snmp_api.h" #include "snmp_client.h" #include "snmp_impl.h" #include "snmp.h" #include "parse.h" ! extern int errno; /* constant - can be shared among threads */ static oid objid_mib[] = {1, 3, 6, 1, 2, 1}; --- 51,66 ---- #ifdef HAVE_UNISTD_H #include <unistd.h> #endif ! #if HAVE_SNMP #include "asn1.h" #include "snmp_api.h" #include "snmp_client.h" #include "snmp_impl.h" #include "snmp.h" #include "parse.h" + #include "mib.h" ! void _php3_snmp(INTERNAL_FUNCTION_PARAMETERS, int st); /* constant - can be shared among threads */ static oid objid_mib[] = {1, 3, 6, 1, 2, 1}; *************** *** 73,85 **** void sprint_variable(char *, oid *, int, struct variable_list *); function_entry snmp_functions[] = { ! {"snmpget", php3_snmpget}, ! {"snmpwalk", php3_snmpwalk}, {NULL,NULL} }; php3_module_entry snmp_module_entry = { ! "SNMP",snmp_functions,NULL,NULL,NULL,NULL,NULL,0,0,0,NULL }; #if COMPILE_DL --- 69,81 ---- void sprint_variable(char *, oid *, int, struct variable_list *); function_entry snmp_functions[] = { ! {"snmpget", php3_snmpget, NULL}, ! {"snmpwalk", php3_snmpwalk, NULL}, {NULL,NULL} }; php3_module_entry snmp_module_entry = { ! "SNMP",snmp_functions,php3i_snmp_init,NULL,NULL,NULL,php3_info_snmp,STANDARD_MODULE_PROPERTIES }; #if COMPILE_DL *************** *** 88,93 **** --- 84,99 ---- /* THREAD_LS snmp_module php3_snmp_module; - may need one of these at some point */ + int php3i_snmp_init(INIT_FUNC_ARGS) { + init_mib(); + return SUCCESS; + } + + void php3_info_snmp(void) { + php3_printf("ucd-snmp"); + } + + /* * Generic SNMP object fetcher * *************** *** 95,105 **** * st=2 WALK */ void _php3_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) { ! pval *a1, *a2, *a3; struct snmp_session session, *ss; struct snmp_pdu *pdu=NULL, *response; struct variable_list *vars; - char *community, *hostname; char *objid; oid name[MAX_NAME_LEN]; int name_length; --- 101,110 ---- * st=2 WALK */ void _php3_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) { ! pval *a1, *a2, *a3, *a4, *a5; struct snmp_session session, *ss; struct snmp_pdu *pdu=NULL, *response; struct variable_list *vars; char *objid; oid name[MAX_NAME_LEN]; int name_length; *************** *** 107,130 **** oid root[MAX_NAME_LEN]; char buf[2048]; int keepwalking=1; ! static int mib_init=0; ! ! if (getParameters(ht, 3, &a1, &a2, &a3) == FAILURE) { WRONG_PARAM_COUNT; } convert_to_string(a1); convert_to_string(a2); convert_to_string(a3); ! ! hostname=a1->value.str.val; ! community=a2->value.str.val; ! objid=a3->value.str.val; ! ! if (!mib_init) { ! init_mib(); ! mib_init=1; } ! if (st==2) { /* walk */ rootlen = MAX_NAME_LEN; if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */ --- 112,137 ---- oid root[MAX_NAME_LEN]; char buf[2048]; int keepwalking=1; ! long timeout=SNMP_DEFAULT_TIMEOUT; ! long retries=SNMP_DEFAULT_RETRIES; ! int myargc = ARG_COUNT(ht); ! ! if (myargc<3 || myargc>5 || getParameters(ht, myargc, &a1, &a2, &a3, &a4, &a5) == 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; ! } ! objid=a3->value.str.val; ! if (st==2) { /* walk */ rootlen = MAX_NAME_LEN; if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */ *************** *** 142,154 **** } memset(&session, 0, sizeof(struct snmp_session)); ! session.peername = hostname; session.version = SNMP_VERSION_1; ! session.community = (u_char *)community; ! session.community_len = strlen((char *)community); ! session.retries = SNMP_DEFAULT_RETRIES; ! session.timeout = SNMP_DEFAULT_TIMEOUT; session.authenticator = NULL; snmp_synch_setup(&session); --- 149,161 ---- } memset(&session, 0, sizeof(struct snmp_session)); ! session.peername = a1->value.str.val; session.version = SNMP_VERSION_1; ! session.community = (u_char *)a2->value.str.val; ! session.community_len = a2->value.str.len; ! session.retries = retries; ! session.timeout = timeout; session.authenticator = NULL; snmp_synch_setup(&session); *************** *** 166,173 **** while(keepwalking) { keepwalking=0; ! if (st==1) pdu = snmp_pdu_create(GET_REQ_MSG); ! else if (st==2) pdu = snmp_pdu_create(GETNEXT_REQ_MSG); if (st==1) { name_length = MAX_NAME_LEN; --- 173,180 ---- while(keepwalking) { keepwalking=0; ! if (st==1) pdu = snmp_pdu_create(SNMP_MSG_GET); ! else if (st==2) pdu = snmp_pdu_create(SNMP_MSG_GETNEXT); if (st==1) { name_length = MAX_NAME_LEN; *************** *** 212,226 **** php3_error(E_WARNING,"This name does not exist: %s\n",buf); } if (st==1) { ! if ((pdu = snmp_fix_pdu(response, GET_REQ_MSG)) != NULL) goto retry; } else if (st==2) { ! if ((pdu = snmp_fix_pdu(response, GETNEXT_REQ_MSG)) != NULL) goto retry; } RETURN_FALSE; } } } else if (status == STAT_TIMEOUT) { ! php3_error(E_WARNING,"No Response from %s\n", hostname); RETURN_FALSE; } else { /* status == STAT_ERROR */ php3_error(E_WARNING,"An error occurred, Quitting\n"); --- 219,233 ---- php3_error(E_WARNING,"This name does not exist: %s\n",buf); } if (st==1) { ! if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) goto retry; } else if (st==2) { ! if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) goto retry; } RETURN_FALSE; } } } else if (status == STAT_TIMEOUT) { ! php3_error(E_WARNING,"No Response from %s\n", a1->value.str.val); RETURN_FALSE; } else { /* status == STAT_ERROR */ php3_error(E_WARNING,"An error occurred, Quitting\n"); *************** *** 231,241 **** snmp_close(ss); } ! DLEXPORT void php3_snmpget(INTERNAL_FUNCTION_PARAMETERS) { _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); } ! DLEXPORT void php3_snmpwalk(INTERNAL_FUNCTION_PARAMETERS) { return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2); } --- 238,248 ---- snmp_close(ss); } ! void php3_snmpget(INTERNAL_FUNCTION_PARAMETERS) { _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1); } ! void php3_snmpwalk(INTERNAL_FUNCTION_PARAMETERS) { return _php3_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2); } -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#1258) next »