[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c

2011-08-31 Thread Boris Lytochkin
lytboris Wed, 31 Aug 2011 20:16:56 +

Revision: http://svn.php.net/viewvc?view=revision&revision=315926

Log:
tune text align

Changed paths:
_U  php/php-src/branches/PHP_5_4/ext/snmp/
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
_U  php/php-src/branches/PHP_5_4/ext/snmp/tests/


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp
___
Modified: svn:mergeinfo
   - /php/php-src/trunk/ext/snmp:284726,311033-315236,315606,315608,315862
   + 
/php/php-src/trunk/ext/snmp:284726,311033-315236,315606,315608,315862,315924

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-08-31 20:16:11 UTC 
(rev 315925)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-08-31 20:16:56 UTC 
(rev 315926)
@@ -104,13 +104,13 @@
} \
 }

-#define PHP_SNMP_ERRNO_NOERROR 0
-#define PHP_SNMP_ERRNO_GENERIC 1
-#define PHP_SNMP_ERRNO_TIMEOUT 2
-#define PHP_SNMP_ERRNO_ERROR_IN_REPLY  3
-#define PHP_SNMP_ERRNO_OID_NOT_INCREASING 4
-#define PHP_SNMP_ERRNO_OID_PARSING_ERROR 5
-#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES 6
+#define PHP_SNMP_ERRNO_NOERROR 0
+#define PHP_SNMP_ERRNO_GENERIC 1
+#define PHP_SNMP_ERRNO_TIMEOUT 2
+#define PHP_SNMP_ERRNO_ERROR_IN_REPLY  3
+#define PHP_SNMP_ERRNO_OID_NOT_INCREASING  4
+#define PHP_SNMP_ERRNO_OID_PARSING_ERROR   5
+#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES6

 ZEND_DECLARE_MODULE_GLOBALS(snmp)
 static PHP_GINIT_FUNCTION(snmp);


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp/tests
___
Modified: svn:mergeinfo
   - 
/php/php-src/trunk/ext/snmp/tests:284726,311033-315236,315386,315606,315608,315862,315916
   + 
/php/php-src/trunk/ext/snmp/tests:284726,311033-315236,315386,315606,315608,315862,315916,315924

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

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c tests/snmp-object.phpt tests/snmp3-error.phpt

2011-08-31 Thread Boris Lytochkin
lytboris Wed, 31 Aug 2011 08:36:22 +

Revision: http://svn.php.net/viewvc?view=revision&revision=315865

Log:
more tuning based on discussion in FR #40816:
 * parse all OIDs earlier, detect all wrong OIDs before any query
   is made (GET-operations)
 * introduce ERRNO_MULTIPLE_SET_QUERIES:
warn if request contains more OIDs than max_oids and SET operation
(and type&value checks) will be done in chunks.
fix set method when request contains more OIDs than max_oids (2nd and
 subsequent chunk were ignored)

Bug: https://bugs.php.net/40816 (Feedback) Add "snmptranslate" function
  
Changed paths:
_U  php/php-src/branches/PHP_5_4/ext/snmp/
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
_U  php/php-src/branches/PHP_5_4/ext/snmp/tests/
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object.phpt
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp3-error.phpt


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp
___
Modified: svn:mergeinfo
   - /php/php-src/trunk/ext/snmp:284726,311033-315236,315606,315608
   + /php/php-src/trunk/ext/snmp:284726,311033-315236,315606,315608,315862

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c	2011-08-31 08:35:57 UTC (rev 315864)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c	2011-08-31 08:36:22 UTC (rev 315865)
@@ -110,6 +110,7 @@
 #define PHP_SNMP_ERRNO_ERROR_IN_REPLY	3
 #define PHP_SNMP_ERRNO_OID_NOT_INCREASING 4
 #define PHP_SNMP_ERRNO_OID_PARSING_ERROR 5
+#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES 6

 ZEND_DECLARE_MODULE_GLOBALS(snmp)
 static PHP_GINIT_FUNCTION(snmp);
@@ -670,11 +671,8 @@
 	struct snmp_session *ss;
 	struct snmp_pdu *pdu=NULL, *response;
 	struct variable_list *vars;
-	oid name[MAX_NAME_LEN];
-	size_t name_length;
 	oid root[MAX_NAME_LEN];
 	size_t rootlen = 0;
-	int gotroot = 0;
 	int status, count, found;
 	char buf[2048];
 	char buf2[2048];
@@ -689,35 +687,10 @@
 	/* reset errno and errstr */
 	php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_NOERROR, "");

-	if (st & SNMP_CMD_WALK) {
-		if (objid_query->count > 1) {
-			php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Multi OID walks are not supported!");
-			RETURN_FALSE;
-		}
-		rootlen = MAX_NAME_LEN;
-		if (strlen(objid_query->vars[0].oid)) { /* on a walk, an empty string means top of tree - no error */
-			if (snmp_parse_oid(objid_query->vars[0].oid, root, &rootlen)) {
-gotroot = 1;
-			} else {
-php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[0].oid);
-RETVAL_FALSE;
-return;
-			}
-		}
-
-		if (!gotroot) {
-			memmove((char *) root, (char *) objid_mib, sizeof(objid_mib));
-			rootlen = sizeof(objid_mib) / sizeof(oid);
-			gotroot = 1;
-		}
-
-		memmove((char *)name, (char *)root, rootlen * sizeof(oid));
-		name_length = rootlen;
+	if (st & SNMP_CMD_WALK) { /* remember root OID */
+		memmove((char *)root, (char *)(objid_query->vars[0].name), (objid_query->vars[0].name_length) * sizeof(oid));
+		rootlen = objid_query->vars[0].name_length;
 		objid_query->offset = objid_query->count;
-
-		memmove((char *)objid_query->vars[0].name, (char *)root, rootlen * sizeof(oid));
-		objid_query->vars[0].name_length = rootlen;
-
 	}

 	if ((ss = snmp_open(session)) == NULL) {
@@ -728,6 +701,10 @@
 		return;
 	}

+	if ((st & SNMP_CMD_SET) && objid_query->count > objid_query->step) {
+		php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES, "Can not fit all OIDs for SET query into one packet, using multiple queries");
+	}
+
 	while (keepwalking) {
 		keepwalking = 0;
 		if (st & SNMP_CMD_WALK) {
@@ -738,7 +715,7 @@
 pdu->non_repeaters = objid_query->non_repeaters;
 pdu->max_repetitions = objid_query->max_repetitions;
 			}
-			snmp_add_null_var(pdu, name, name_length);
+			snmp_add_null_var(pdu, objid_query->vars[0].name, objid_query->vars[0].name_length);
 		} else {
 			if (st & SNMP_CMD_GET) {
 pdu = snmp_pdu_create(SNMP_MSG_GET);
@@ -753,14 +730,6 @@
 return;
 			}
 			for (count = 0; objid_query->offset < objid_query->count && count < objid_query->step; objid_query->offset++, count++){
-objid_query->vars[objid_query->offset].name_length = MAX_OID_LEN;
-if (!snmp_parse_oid(objid_query->vars[objid_query->offset].oid, objid_query->vars[objid_query->offset].name, &(objid_query->vars[objid_query->offset].name_length))) {
-	php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[objid_query->offset].oid);
-	snmp_free_pdu(pdu);
-	snmp_close(ss);
-	RETVAL_FALSE;
-	return;
-}
 if (st & SNMP_CMD_SET) {
 	if ((snmp_errno = snmp_add_var(pdu, objid_query->vars[objid_query->offset]

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c tests/snmp2_get.phpt tests/snmpget.phpt

2011-08-27 Thread Boris Lytochkin
lytboris Sat, 27 Aug 2011 07:33:27 +

Revision: http://svn.php.net/viewvc?view=revision&revision=315607

Log:
merge from trunk:
reformat OID parsing procedure,
fail whole SNMP query on single OID parsing failure

Changed paths:
_U  php/php-src/branches/PHP_5_4/ext/snmp/
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
_U  php/php-src/branches/PHP_5_4/ext/snmp/tests/
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp2_get.phpt
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmpget.phpt


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp
___
Modified: svn:mergeinfo
   - /php/php-src/trunk/ext/snmp:284726,311033-315236
   + /php/php-src/trunk/ext/snmp:284726,311033-315236,315606

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-08-27 07:24:44 UTC 
(rev 315606)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-08-27 07:33:27 UTC 
(rev 315607)
@@ -729,24 +729,28 @@

while (keepwalking) {
keepwalking = 0;
-   if (st & (SNMP_CMD_GET | SNMP_CMD_GETNEXT)) {
-   pdu = snmp_pdu_create((st & SNMP_CMD_GET) ? 
SNMP_MSG_GET : SNMP_MSG_GETNEXT);
-   for (count = 0; objid_query->offset < 
objid_query->count && count < objid_query->step; objid_query->offset++, 
count++){
-   
objid_query->vars[objid_query->offset].name_length = MAX_OID_LEN;
-   if 
(!snmp_parse_oid(objid_query->vars[objid_query->offset].oid, 
objid_query->vars[objid_query->offset].name, 
&(objid_query->vars[objid_query->offset].name_length))) {
-   php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "Invalid object identifier: %s", 
objid_query->vars[objid_query->offset].oid);
-   } else {
-   snmp_add_null_var(pdu, 
objid_query->vars[objid_query->offset].name, 
objid_query->vars[objid_query->offset].name_length);
-   }
+   if (st & SNMP_CMD_WALK) {
+   if (session->version == SNMP_VERSION_1) {
+   pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
+   } else {
+   pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
+   pdu->non_repeaters = objid_query->non_repeaters;
+   pdu->max_repetitions = 
objid_query->max_repetitions;
}
-   if(pdu->variables == NULL){
-   snmp_free_pdu(pdu);
+   snmp_add_null_var(pdu, name, name_length);
+   } else {
+   if (st & SNMP_CMD_GET) {
+   pdu = snmp_pdu_create(SNMP_MSG_GET);
+   } else if (st & SNMP_CMD_GETNEXT) {
+   pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
+   } else if (st & SNMP_CMD_SET) {
+   pdu = snmp_pdu_create(SNMP_MSG_SET);
+   } else {
snmp_close(ss);
+   php_error_docref(NULL TSRMLS_CC, E_ERROR, 
"Unknown SNMP command (internals)");
RETVAL_FALSE;
return;
}
-   } else if (st & SNMP_CMD_SET) {
-   pdu = snmp_pdu_create(SNMP_MSG_SET);
for (count = 0; objid_query->offset < 
objid_query->count && count < objid_query->step; objid_query->offset++, 
count++){

objid_query->vars[objid_query->offset].name_length = MAX_OID_LEN;
if 
(!snmp_parse_oid(objid_query->vars[objid_query->offset].oid, 
objid_query->vars[objid_query->offset].name, 
&(objid_query->vars[objid_query->offset].name_length))) {
@@ -755,7 +759,8 @@
snmp_close(ss);
RETVAL_FALSE;
return;
-   } else {
+   }
+   if (st & SNMP_CMD_SET) {
if ((snmp_errno = snmp_add_var(pdu, 
objid_query->vars[objid_query->offset].name, 
objid_query->vars[objid_query->offset].name_length, 
objid_query->vars[objid_query->offset].type, 
objid_query->vars[objid_query->offset].value))) {
snprint_objid(buf, sizeof(buf), 
objid_query->vars[objid_query->offset].name, 
objid_query->vars[objid_query->offset].name_length);
php_error_docref(NULL 
TSRMLS_CC, E_WARNING, "C

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c tests/README tests/generic_timeout_error.phpt tests/ipv6.phpt tests/snmp-object-errno-errstr.phpt tests/snmp_include.inc tests/wrong_hostn

2011-08-20 Thread Boris Lytochkin
lytboris Sat, 20 Aug 2011 16:10:48 +

Revision: http://svn.php.net/viewvc?view=revision&revision=315237

Log:
merge from trunk two commits:
Adding IPv6 support (FR #42918)
more code coverage

Bug: https://bugs.php.net/42918 (Assigned) IPv6 addresses not supported in SNMP 
extension
  
Changed paths:
_U  php/php-src/branches/PHP_5_4/ext/snmp/
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/README
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/generic_timeout_error.phpt
A + php/php-src/branches/PHP_5_4/ext/snmp/tests/ipv6.phpt
(from php/php-src/trunk/ext/snmp/tests/ipv6.phpt:r315236)
U   
php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object-errno-errstr.phpt
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp_include.inc
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/wrong_hostname.phpt


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp
___
Modified: svn:mergeinfo
   - /php/php-src/trunk/ext/snmp:284726,311033-313324,313341,313532
   + /php/php-src/trunk/ext/snmp:284726,311033-315236

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c	2011-08-20 15:53:44 UTC (rev 315236)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c	2011-08-20 16:10:48 UTC (rev 315237)
@@ -28,6 +28,7 @@
 #endif

 #include "php.h"
+#include "main/php_network.h"
 #include "ext/standard/info.h"
 #include "php_snmp.h"

@@ -1075,9 +1076,13 @@
 */
 static int netsnmp_session_init(php_snmp_session **session_p, int version, char *hostname, char *community, int timeout, int retries TSRMLS_DC)
 {
-	int remote_port = SNMP_PORT;
 	php_snmp_session *session;
 	char *pptr;
+	char buf[MAX_NAME_LEN];
+	int force_ipv6 = FALSE;
+	int n;
+	struct sockaddr **psal;
+	struct sockaddr **res;

 	*session_p = (php_snmp_session *)emalloc(sizeof(php_snmp_session));
 	session = *session_p;
@@ -1085,26 +1090,87 @@
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed allocating session");
 		return (-1);
 	}
+	memset(session, 0, sizeof(php_snmp_session));

+	strlcpy(buf, hostname, sizeof(buf));
+
 	snmp_sess_init(session);

 	session->version = version;
+	session->remote_port = SNMP_PORT;

 	session->peername = emalloc(MAX_NAME_LEN);
-	if(session->peername == NULL) {
+	if (session->peername == NULL) {
 		php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while copying hostname");
-		netsnmp_session_free(&session);
 		return (-1);
 	}
+	*(session->peername) = '\0';

 	/* Reading the hostname and its optional non-default port number */
-	strlcpy(session->peername, hostname, MAX_NAME_LEN);
-	if ((pptr = strchr(session->peername, ':'))) {
-		remote_port = strtol(pptr + 1, NULL, 0);
+	if (*hostname == '[') { /* IPv6 address */
+		force_ipv6 = TRUE;
+		hostname++;
+		if ((pptr = strchr(hostname, ']'))) {
+			if (pptr[1] == ':') {
+session->remote_port = atoi(pptr + 2);
+			}
+			*pptr = '\0';
+		} else {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "mailformed IPv6 address, closing square bracket missing");
+			return (-1);
+		}
+	} else { /* IPv4 address */
+		if ((pptr = strchr(hostname, ':'))) {
+			session->remote_port = atoi(pptr + 1);
+			*pptr = '\0';
+		}
 	}

-	session->remote_port = remote_port;
+	/* since Net-SNMP library requires 'udp6:' prefix for all IPv6 addresses (in FQDN form too) we need to
+	   perform possible name resolution before running any SNMP queries */
+	if ((n = php_network_getaddresses(hostname, SOCK_DGRAM, &psal, NULL TSRMLS_CC)) == 0) { /* some resover error */
+		/* warnings sent, bailing out */
+		return (-1);
+	}

+	res = psal;
+	while (n-- > 0) {
+		pptr = session->peername;
+#if HAVE_GETADDRINFO && HAVE_IPV6 && HAVE_INET_NTOP
+		if (force_ipv6 && (*res)->sa_family != AF_INET6) {
+			res++;
+			continue;
+		}
+		if ((*res)->sa_family == AF_INET6) {
+			strcpy(session->peername, "udp6:");
+			pptr = session->peername + strlen(session->peername);
+			inet_ntop((*res)->sa_family, &(((struct sockaddr_in6*)(*res))->sin6_addr), pptr, MAX_NAME_LEN);
+		} else if ((*res)->sa_family == AF_INET) {
+			inet_ntop((*res)->sa_family, &(((struct sockaddr_in*)(*res))->sin_addr), pptr, MAX_NAME_LEN);
+		} else {
+			res++;
+			continue;
+		}
+#else
+		if (res->sa_family != AF_INET) {
+			res++;
+			continue;
+		}
+		strcat(pptr, inet_ntoa(res));
+#endif
+		break;
+	}
+
+	if (strlen(session->peername) == 0) {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown failure while resolving '%s'", buf);
+		return (-1);
+	}
+	/* XXX FIXME
+		There should be check for non-empty session->peername!
+	*/
+
+	php_network_freeaddresses(psal);
+
 	if (version == SNMP_VERSION_3) {
 		/* Setting the security name. */
 		session->securityName = estrdup(community);

Modified: php/php-src/branches/PHP_5_4/ext/snmp/test

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c tests/snmp-object-error.phpt tests/snmp-object.phpt

2011-07-17 Thread Boris Lytochkin
lytboris Sun, 17 Jul 2011 18:14:38 +

Revision: http://svn.php.net/viewvc?view=revision&revision=313336

Log:
swap non_repeaters and max_repetitions in walk query, max_repetitions whould be 
used more frequently

Changed paths:
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object-error.phpt
U   php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object.phpt

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-07-17 18:08:02 UTC 
(rev 313335)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-07-17 18:14:38 UTC 
(rev 313336)
@@ -345,8 +345,8 @@
 ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_walk, 0, 0, 4)
ZEND_ARG_INFO(0, object_id)
ZEND_ARG_INFO(0, suffix_keys)
+   ZEND_ARG_INFO(0, max_repetitions)
ZEND_ARG_INFO(0, non_repeaters)
-   ZEND_ARG_INFO(0, max_repetitions)
 ZEND_END_ARG_INFO()

 ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set, 0, 0, 3)
@@ -1355,7 +1355,7 @@
RETURN_FALSE;
}
} else if (st & SNMP_CMD_WALK) {
-   if (zend_parse_parameters(argc TSRMLS_CC, "Z|bll", 
&oid, &suffix_keys, &(objid_query.non_repeaters), 
&(objid_query.max_repetitions)) == FAILURE) {
+   if (zend_parse_parameters(argc TSRMLS_CC, "Z|bll", 
&oid, &suffix_keys, &(objid_query.max_repetitions), 
&(objid_query.non_repeaters)) == FAILURE) {
RETURN_FALSE;
}
if (suffix_keys) {
@@ -1763,7 +1763,7 @@
 }
 /* }}} */

-/* {{{ proto mixed SNMP::walk(mixed object_id [, bool $suffix_as_key = FALSE 
[, int $non_repeaters [, int $max_repetitions ]]])
+/* {{{ proto mixed SNMP::walk(mixed object_id [, bool $suffix_as_key = FALSE 
[, int $max_repetitions [, int $non_repeaters]])
Return all objects including their respective object id withing the 
specified one as array of oid->value pairs */
 PHP_METHOD(snmp, walk)
 {

Modified: php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object-error.phpt
===
--- php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object-error.phpt  
2011-07-17 18:08:02 UTC (rev 313335)
+++ php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object-error.phpt  
2011-07-17 18:14:38 UTC (rev 313336)
@@ -47,7 +47,7 @@

 $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, 
$retries);
 var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, ''));
-var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, 0, ''));
+var_dump($session->walk('.1.3.6.1.2.1.1', FALSE, 30, ''));
 var_dump($session->get());
 var_dump($session->getnext());
 var_dump($session->set());

Modified: php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object.phpt
===
--- php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object.phpt
2011-07-17 18:08:02 UTC (rev 313335)
+++ php/php-src/branches/PHP_5_4/ext/snmp/tests/snmp-object.phpt
2011-07-17 18:14:38 UTC (rev 313336)
@@ -48,18 +48,18 @@
 var_dump(array_shift($z));
 var_dump($session->close());

-echo "WALK multiple on single OID, non_repeaters set to 0\n";
+echo "WALK multiple on single OID, max_repetitions set to 30\n";
 $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, 
$retries);
-$z = $session->walk('.1.3.6.1.2.1.1', 0);
+$z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30);
 var_dump(gettype($z));
 var_dump(count($z));
 var_dump(key($z));
 var_dump(array_shift($z));
 var_dump($session->close());

-echo "WALK multiple on single OID, non_repeaters set to 0, max_repetitions set 
to 30\n";
+echo "WALK multiple on single OID, max_repetitions set to 30, non_repeaters 
set to 0\n";
 $session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, 
$retries);
-$z = $session->walk('.1.3.6.1.2.1.1', 0, 30);
+$z = $session->walk('.1.3.6.1.2.1.1', FALSE, 30, 0);
 var_dump(gettype($z));
 var_dump(count($z));
 var_dump(key($z));
@@ -154,13 +154,13 @@
 string(%d) "%S"
 string(%d) "%S"
 bool(true)
-WALK multiple on single OID, non_repeaters set to 0
+WALK multiple on single OID, max_repetitions set to 30
 string(5) "array"
 int(%d)
 string(%d) "%S"
 string(%d) "%S"
 bool(true)
-WALK multiple on single OID, non_repeaters set to 0, max_repetitions set to 30
+WALK multiple on single OID, max_repetitions set to 30, non_repeaters set to 0
 string(5) "array"
 int(%d)
 string(%d) "%S"

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

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c

2011-07-17 Thread Boris Lytochkin
lytboris Sun, 17 Jul 2011 14:06:05 +

Revision: http://svn.php.net/viewvc?view=revision&revision=313325

Log:
backport r313324

Changed paths:
_U  php/php-src/branches/PHP_5_4/ext/snmp/
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c


Property changes on: php/php-src/branches/PHP_5_4/ext/snmp
___
Modified: svn:mergeinfo
   - /php/php-src/trunk/ext/snmp:284726,311033-312092
   + /php/php-src/trunk/ext/snmp:284726,311033-313324

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-07-17 13:57:28 UTC 
(rev 313324)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-07-17 14:06:05 UTC 
(rev 313325)
@@ -339,10 +339,12 @@

 ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_get, 0, 0, 1)
ZEND_ARG_INFO(0, object_id)
+   ZEND_ARG_INFO(0, use_orignames)
 ZEND_END_ARG_INFO()

-ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_walk, 0, 0, 3)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_walk, 0, 0, 4)
ZEND_ARG_INFO(0, object_id)
+   ZEND_ARG_INFO(0, suffix_keys)
ZEND_ARG_INFO(0, non_repeaters)
ZEND_ARG_INFO(0, max_repetitions)
 ZEND_END_ARG_INFO()
@@ -1749,7 +1751,7 @@
 }
 /* }}} */

-/* {{{ proto mixed SNMP::get_assoc(mixed object_id)
+/* {{{ proto mixed SNMP::get(mixed object_id [, bool preserve_keys])
Fetch a SNMP object returing scalar for single OID and array of oid->value 
pairs for multi OID request */
 PHP_METHOD(snmp, get)
 {
@@ -1757,7 +1759,7 @@
 }
 /* }}} */

-/* {{{ proto mixed SNMP::getnext(mixed object_id)
+/* {{{ proto mixed SNMP::getnext(mixed object_id)
Fetch a SNMP object returing scalar for single OID and array of oid->value 
pairs for multi OID request */
 PHP_METHOD(snmp, getnext)
 {
@@ -1765,7 +1767,7 @@
 }
 /* }}} */

-/* {{{ proto mixed SNMP::walk(mixed object_id)
+/* {{{ proto mixed SNMP::walk(mixed object_id [, bool $suffix_as_key = FALSE 
[, int $non_repeaters [, int $max_repetitions ]]])
Return all objects including their respective object id withing the 
specified one as array of oid->value pairs */
 PHP_METHOD(snmp, walk)
 {

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

[PHP-CVS] svn: /php/php-src/branches/PHP_5_4/ext/snmp/ snmp.c

2011-06-12 Thread Boris Lytochkin
lytboris Sun, 12 Jun 2011 12:26:51 +

Revision: http://svn.php.net/viewvc?view=revision&revision=312094

Log:
remove PHP_VERSION_ID ifdef's, limiting to 5.4 branch

Changed paths:
U   php/php-src/branches/PHP_5_4/ext/snmp/snmp.c

Modified: php/php-src/branches/PHP_5_4/ext/snmp/snmp.c
===
--- php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-06-12 12:10:01 UTC 
(rev 312093)
+++ php/php-src/branches/PHP_5_4/ext/snmp/snmp.c2011-06-12 12:26:51 UTC 
(rev 312094)
@@ -75,14 +75,6 @@
 #include 
 #include 

-#if PHP_VERSION_ID < 50300
-#define Z_ADDREF_P(pz) pz->refcount++
-#define Z_ISREF_PP(oid) (PZVAL_IS_REF(*(oid)))
-#define Z_REFCOUNT_P(pz) pz->refcount
-#define Z_SET_REFCOUNT_P(pz, rc) pz->refcount = rc
-#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;
@@ -482,9 +474,6 @@

 static zend_object_value php_snmp_object_new(zend_class_entry *class_type 
TSRMLS_DC) /* {{{ */
 {
-#if PHP_VERSION_ID < 50399
-   zval *tmp;
-#endif
zend_object_value retval;
php_snmp_object *intern;

@@ -493,11 +482,7 @@
memset(&intern->zo, 0, sizeof(php_snmp_object));

zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
-#if PHP_VERSION_ID < 50399
-   zend_hash_copy(intern->zo.properties, &class_type->default_properties, 
(copy_ctor_func_t) zval_add_ref,(void *) &tmp, sizeof(zval *));
-#else
object_properties_init(&intern->zo, class_type);
-#endif

retval.handle = zend_objects_store_put(intern, 
(zend_objects_store_dtor_t)zend_objects_destroy_object, 
(zend_objects_free_object_storage_t) php_snmp_object_free_storage, NULL 
TSRMLS_CC);
retval.handlers = (zend_object_handlers *) &php_snmp_object_handlers;
@@ -1707,31 +1692,17 @@
long retries = SNMP_DEFAULT_RETRIES;
long version = SNMP_DEFAULT_VERSION;
int argc = ZEND_NUM_ARGS();
-#if PHP_VERSION_ID > 50300
zend_error_handling error_handling;
-#endif

snmp_object = (php_snmp_object *)zend_object_store_get_object(object 
TSRMLS_CC);
-#if PHP_VERSION_ID > 50300
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
-#else
-   php_set_error_handling(EH_THROW, zend_exception_get_default(TSRMLS_C) 
TSRMLS_CC);
-#endif

if (zend_parse_parameters(argc TSRMLS_CC, "lss|ll", &version, &a1, 
&a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) {
-#if PHP_VERSION_ID > 50300
zend_restore_error_handling(&error_handling TSRMLS_CC);
-#else
-   php_std_error_handling();
-#endif
return;
}

-#if PHP_VERSION_ID > 50300
zend_restore_error_handling(&error_handling TSRMLS_CC);
-#else
-   php_std_error_handling();
-#endif

switch(version) {
case SNMP_VERSION_1:
@@ -1877,11 +1848,7 @@

 /* {{{ php_snmp_read_property(zval *object, zval *member, int type[, const 
zend_literal *key])
Generic object property reader */
-#if PHP_VERSION_ID < 50399
-zval *php_snmp_read_property(zval *object, zval *member, int type TSRMLS_DC)
-#else
 zval *php_snmp_read_property(zval *object, zval *member, int type, const 
zend_literal *key TSRMLS_DC)
-#endif
 {
zval tmp_member;
zval *retval;
@@ -1911,11 +1878,7 @@
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
-#if PHP_VERSION_ID < 50399
-   retval = std_hnd->read_property(object, member, type TSRMLS_CC);
-#else
retval = std_hnd->read_property(object, member, type, key 
TSRMLS_CC);
-#endif
}

if (member == &tmp_member) {
@@ -1927,11 +1890,7 @@

 /* {{{ php_snmp_write_property(zval *object, zval *member, zval *value[, const 
zend_literal *key])
Generic object property writer */
-#if PHP_VERSION_ID < 50399
-void php_snmp_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
-#else
 void php_snmp_write_property(zval *object, zval *member, zval *value, const 
zend_literal *key TSRMLS_DC)
-#endif
 {
zval tmp_member;
php_snmp_object *obj;
@@ -1958,11 +1917,7 @@
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
-#if PHP_VERSION_ID < 50399
-   std_hnd->write_property(object, member, value TSRMLS_CC);
-#else
std_hnd->write_property(object, member, value, key TSRMLS_CC);
-#endif
}

if (member == &tmp_member) {
@@ -1973,11 +1928,7 @@

 /* {{{ php_snmp_has_property(zval *object, zval *member, int has_set_exists[, 
const zend_literal *key])
Generic object property checker */
-#if PHP_VERSION_ID < 50399
-static int php_snmp_has_property(zval *object, zval *member, int 
has_set_exists TSRMLS_DC)
-#else
 static int php_snmp