[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ config.m4 snmp.c tests/snmp-object-errno-errstr.phpt tests/wrong_hostname.phpt

2011-05-10 Thread Boris Lytochkin
lytboris Tue, 10 May 2011 20:04:26 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=310936

Log:
fixed typos in tests
ucd-snmp epoch is over, drop legacy memory allocation (non e*)
tune 'buggy snmp_snprint_value' detection on some systems

Changed paths:
U   php/php-src/trunk/ext/snmp/config.m4
U   php/php-src/trunk/ext/snmp/snmp.c
U   php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt
U   php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt

Modified: php/php-src/trunk/ext/snmp/config.m4
===
--- php/php-src/trunk/ext/snmp/config.m42011-05-10 19:59:07 UTC (rev 
310935)
+++ php/php-src/trunk/ext/snmp/config.m42011-05-10 20:04:26 UTC (rev 
310936)
@@ -62,7 +62,7 @@
   dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834)
   AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[
 save_CFLAGS=$CFLAGS
-CFLAGS=$CFLAGS -I${SNMP_PREFIX}/include
+CFLAGS=$CFLAGS -I${SNMP_PREFIX}/include $SNMP_SHARED_LIBADD
 AC_TRY_RUN( [
 #include stdio.h
 #include stdlib.h

Modified: php/php-src/trunk/ext/snmp/snmp.c
===
--- php/php-src/trunk/ext/snmp/snmp.c   2011-05-10 19:59:07 UTC (rev 310935)
+++ php/php-src/trunk/ext/snmp/snmp.c   2011-05-10 20:04:26 UTC (rev 310936)
@@ -440,12 +440,20 @@
 }
 /* }}} */

+#define PHP_SNMP_SESSION_FREE(a) { \
+   if ((*session)-a) { \
+   efree((*session)-a); \
+   (*session)-a = NULL; \
+   } \
+}
+
 static void netsnmp_session_free(php_snmp_session **session)
 {
if (*session) {
-   if ((*session)-peername) {
-   efree((*session)-peername);
-   }
+   PHP_SNMP_SESSION_FREE(peername);
+   PHP_SNMP_SESSION_FREE(community);
+   PHP_SNMP_SESSION_FREE(securityName);
+   PHP_SNMP_SESSION_FREE(contextEngineID);
efree(*session);
*session = NULL;
}
@@ -1115,11 +1123,11 @@

if (version == SNMP_VERSION_3) {
/* Setting the security name. */
-   session-securityName = strdup(community);
+   session-securityName = estrdup(community);
session-securityNameLen = strlen(session-securityName);
} else {
session-authenticator = NULL;
-   session-community = (u_char *)community;
+   session-community = (u_char *)estrdup(community);
session-community_len = strlen(community);
}

@@ -1222,7 +1230,7 @@
 static int netsnmp_session_set_contextEngineID(struct snmp_session *s, char * 
contextEngineID TSRMLS_DC)
 {
size_t  ebuf_len = 32, eout_len = 0;
-   u_char  *ebuf = (u_char *) malloc(ebuf_len); /* memory freed by SNMP 
library, malloc NOT emalloc */
+   u_char  *ebuf = (u_char *) emalloc(ebuf_len);

if (ebuf == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, malloc failure 
setting contextEngineID);
@@ -1230,12 +1238,12 @@
}
if (!snmp_hex_to_binary(ebuf, ebuf_len, eout_len, 1, 
contextEngineID)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Bad engine ID 
value '%s', contextEngineID);
-   free(ebuf);
+   efree(ebuf);
return (-1);
}

if (s-contextEngineID) {
-   free(s-contextEngineID);
+   efree(s-contextEngineID);
}

s-contextEngineID = ebuf;

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt
===
--- php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt  
2011-05-10 19:59:07 UTC (rev 310935)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt  
2011-05-10 20:04:26 UTC (rev 310936)
@@ -1,5 +1,5 @@
 --TEST--
-OO API: getErrno  getError functions
+OO API: getErrno  getError methods
 --CREDITS--
 Boris Lytochkin
 --SKIPIF--

Modified: php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt
===
--- php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt2011-05-10 
19:59:07 UTC (rev 310935)
+++ php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt2011-05-10 
20:04:26 UTC (rev 310936)
@@ -1,5 +1,5 @@
 --TEST--
-Generic timeout (wrong community)
+Wrong hostname
 --CREDITS--
 Boris Lytochkin
 --SKIPIF--

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ config.m4 snmp.c

2011-04-06 Thread Boris Lytochkin
lytboris Wed, 06 Apr 2011 06:58:25 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=309976

Log:
* Net-SNMP version detection and proper processing
* more UCD-SNMP-related code removal

Changed paths:
U   php/php-src/trunk/ext/snmp/config.m4
U   php/php-src/trunk/ext/snmp/snmp.c

Modified: php/php-src/trunk/ext/snmp/config.m4
===
--- php/php-src/trunk/ext/snmp/config.m42011-04-06 02:16:55 UTC (rev 
309975)
+++ php/php-src/trunk/ext/snmp/config.m42011-04-06 06:58:25 UTC (rev 
309976)
@@ -20,23 +20,34 @@
 SNMP_LIBS=`$SNMP_CONFIG --netsnmp-libs`
 SNMP_LIBS=$SNMP_LIBS `$SNMP_CONFIG --external-libs`
 SNMP_PREFIX=`$SNMP_CONFIG --prefix`
-
-if test -n $SNMP_LIBS  test -n $SNMP_PREFIX; then
-  PHP_ADD_INCLUDE(${SNMP_PREFIX}/include)
-  PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD)
-  SNMP_LIBNAME=netsnmp
+snmp_full_version=`$SNMP_CONFIG --version`
+ac_IFS=$IFS
+IFS=.
+set $snmp_full_version
+IFS=$ac_IFS
+SNMP_VERSION=`expr [$]1 \* 1000 + [$]2`
+if test $SNMP_VERSION -ge 5003; then
+  if test -n $SNMP_LIBS  test -n $SNMP_PREFIX; then
+PHP_ADD_INCLUDE(${SNMP_PREFIX}/include)
+PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD)
+SNMP_LIBNAME=netsnmp
+  else
+AC_MSG_ERROR([Could not find the required paths. Please check your 
net-snmp installation.])
+  fi
 else
-  AC_MSG_ERROR([Could not find the required paths. Please check your 
net-snmp installation.])
+  AC_MSG_ERROR([Net-SNMP version 5.3 or greater reqired (detected 
$snmp_full_version).])
 fi
   else
 AC_MSG_ERROR([Could not find net-snmp-config binary. Please check your 
net-snmp installation.])
   fi

-  dnl Check whether snmp_parse_oid() exists.
-  PHP_CHECK_LIBRARY($SNMP_LIBNAME, snmp_parse_oid,
+  dnl Test build.
+  PHP_CHECK_LIBRARY($SNMP_LIBNAME, init_snmp,
   [
-AC_DEFINE(HAVE_SNMP_PARSE_OID, 1, [ ])
-  ], [], [
+AC_DEFINE(HAVE_SNMP,1,[ ])
+  ], [
+AC_MSG_ERROR([SNMP sanity check failed. Please check config.log for more 
information.])
+  ], [
 $SNMP_SHARED_LIBADD
   ])

@@ -48,16 +59,6 @@
 $SNMP_SHARED_LIBADD
   ])

-  dnl Test build.
-  PHP_CHECK_LIBRARY($SNMP_LIBNAME, init_snmp,
-  [
-AC_DEFINE(HAVE_SNMP,1,[ ])
-  ], [
-AC_MSG_ERROR([SNMP sanity check failed. Please check config.log for more 
information.])
-  ], [
-$SNMP_SHARED_LIBADD
-  ])
-
   dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834)
   AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[
 save_CFLAGS=$CFLAGS

Modified: php/php-src/trunk/ext/snmp/snmp.c
===
--- php/php-src/trunk/ext/snmp/snmp.c   2011-04-06 02:16:55 UTC (rev 309975)
+++ php/php-src/trunk/ext/snmp/snmp.c   2011-04-06 06:58:25 UTC (rev 309976)
@@ -75,11 +75,6 @@
 #include net-snmp/net-snmp-config.h
 #include net-snmp/net-snmp-includes.h

-/* Ugly macro, since the length of OIDs in UCD-SNMP and NET-SNMP
- * is different and this way the code is not full of 'ifdef's.
- */
-#define OIDSIZE(p) (sizeof(p)/sizeof(oid))
-
 #if PHP_VERSION_ID  50300
 #define Z_ADDREF_P(pz) pz-refcount++
 #define Z_ISREF_PP(oid) (PZVAL_IS_REF(*(oid)))
@@ -99,11 +94,6 @@
}
 #endif

-/* For really old ucd-snmp versions.. */
-#ifndef HAVE_SNMP_PARSE_OID
-#define snmp_parse_oid read_objid
-#endif
-
 #define SNMP_VALUE_LIBRARY 0
 #define SNMP_VALUE_PLAIN   1
 #define SNMP_VALUE_OBJECT  2
@@ -1092,11 +1082,7 @@
session-securityNameLen = strlen(session-securityName);
} else {
session-authenticator = NULL;
-#ifdef UCD_SNMP_HACK
-   session-community = (u_char *)strdup(community); /* memory 
freed by SNMP library, strdup NOT estrdup */
-#else
session-community = (u_char *)community;
-#endif
session-community_len = strlen(community);
}

@@ -1129,10 +1115,10 @@
 {
if (!strcasecmp(prot, MD5)) {
s-securityAuthProto = usmHMACMD5AuthProtocol;
-   s-securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
+   s-securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
} else if (!strcasecmp(prot, SHA)) {
s-securityAuthProto = usmHMACSHA1AuthProtocol;
-   s-securityAuthProtoLen = OIDSIZE(usmHMACSHA1AuthProtocol);
+   s-securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Unknown 
authentication protocol '%s', prot);
return (-1);
@@ -1147,39 +1133,12 @@
 {
if (!strcasecmp(prot, DES)) {
s-securityPrivProto = usmDESPrivProtocol;
-   s-securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
+   s-securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
 #ifdef HAVE_AES
-  

[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ config.m4 snmp.c

2011-02-17 Thread Boris Lytochkin
lytboris Thu, 17 Feb 2011 12:02:16 +

Revision: http://svn.php.net/viewvc?view=revisionrevision=308427

Log:
* Fix memory leak on concurrent new, open
* change comments to ANSI-C style
* added compatibility with net-snmp prior 5.4

Changed paths:
U   php/php-src/trunk/ext/snmp/config.m4
U   php/php-src/trunk/ext/snmp/snmp.c

Modified: php/php-src/trunk/ext/snmp/config.m4
===
--- php/php-src/trunk/ext/snmp/config.m42011-02-17 11:55:01 UTC (rev 
308426)
+++ php/php-src/trunk/ext/snmp/config.m42011-02-17 12:02:16 UTC (rev 
308427)
@@ -112,6 +112,14 @@
 $SNMP_SHARED_LIBADD
   ])

+  dnl Check whether shutdown_snmp_logging() exists.
+  PHP_CHECK_LIBRARY($SNMP_LIBNAME, shutdown_snmp_logging,
+  [
+AC_DEFINE(HAVE_SHUTDOWN_SNMP_LOGGING, 1, [ ])
+  ], [], [
+$SNMP_SHARED_LIBADD
+  ])
+
   dnl Test build.
   PHP_CHECK_LIBRARY($SNMP_LIBNAME, init_snmp,
   [

Modified: php/php-src/trunk/ext/snmp/snmp.c
===
--- php/php-src/trunk/ext/snmp/snmp.c   2011-02-17 11:55:01 UTC (rev 308426)
+++ php/php-src/trunk/ext/snmp/snmp.c   2011-02-17 12:02:16 UTC (rev 308427)
@@ -117,6 +117,17 @@
 #define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() 
TSRMLS_CC, )
 #endif

+/* For net-snmp prior to 5.4 */
+//#ifndef HAVE_SHUTDOWN_SNMP_LOGGING
+extern netsnmp_log_handler *logh_head;
+#define shutdown_snmp_logging() \
+   { \
+   snmp_disable_log(); \
+   while(NULL != logh_head) \
+   netsnmp_remove_loghandler( logh_head ); \
+   }
+//#endif
+
 /* For really old ucd-snmp versions.. */
 #ifndef HAVE_SNMP_PARSE_OID
 #define snmp_parse_oid read_objid
@@ -960,7 +971,7 @@
}
}
objid_set-count++;
-   } else if (Z_TYPE_PP(oid) == IS_ARRAY) { // we got objid array
+   } else if (Z_TYPE_PP(oid) == IS_ARRAY) { /* we got objid array */
if (zend_hash_num_elements(Z_ARRVAL_PP(oid)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, Got empty 
OID array);
return FALSE;
@@ -1366,7 +1377,7 @@
snmp_object = (php_snmp_object 
*)zend_object_store_get_object(object TSRMLS_CC);
if (snmp_object-max_oids  0) {
objid_set.step = snmp_object-max_oids;
-   if (max_repetitions  0) { // unspecified in function 
call, use session-wise
+   if (max_repetitions  0) { /* unspecified in function 
call, use session-wise */
max_repetitions = snmp_object-max_oids;
}
}
@@ -1385,7 +1396,7 @@
}

if (max_repetitions  0) {
-   max_repetitions = 20; // provide correct default value
+   max_repetitions = 20; /* provide correct default value */
}

php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, session, 
objid_set, non_repeaters, max_repetitions, valueretrieval);
@@ -1706,6 +1717,11 @@
return;
}

+   /* handle re-open of snmp session */
+   if (snmp_object-session) {
+   netsnmp_session_free((snmp_object-session));
+   }
+
if (netsnmp_session_init((snmp_object-session), version, a1, a2, 
timeout, retries TSRMLS_CC)) {
return;
}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php