lytboris                                 Sat, 26 Feb 2011 08:27:26 +0000

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

Log:
* new methods get_errno, get_error to get errno and error string
    of last SNMP-related error
* formatting markup
* some fixes in max_oids logic: NULL will set it to default value,
    do not allow non-positive user-supplied values
* unit tests for changes

Changed paths:
    U   php/php-src/trunk/ext/snmp/php_snmp.h
    U   php/php-src/trunk/ext/snmp/snmp.c
    A   php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt
    U   php/php-src/trunk/ext/snmp/tests/snmp-object-error.phpt
    U   php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt
    U   php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt
    U   php/php-src/trunk/ext/snmp/tests/snmp-object.phpt

Modified: php/php-src/trunk/ext/snmp/php_snmp.h
===================================================================
--- php/php-src/trunk/ext/snmp/php_snmp.h	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/php_snmp.h	2011-02-26 08:27:26 UTC (rev 308703)
@@ -79,17 +79,21 @@
 PHP_METHOD(SNMP, getnext);
 PHP_METHOD(SNMP, walk);
 PHP_METHOD(SNMP, set);
+PHP_METHOD(SNMP, get_errno);
+PHP_METHOD(SNMP, get_error);

 typedef struct _php_snmp_object {
-      zend_object zo;
-      struct snmp_session *session;
-      int max_oids;
-      int valueretrieval;
-      int quick_print;
+	zend_object zo;
+	struct snmp_session *session;
+	int max_oids;
+	int valueretrieval;
+	int quick_print;
 #ifdef HAVE_NET_SNMP
-      int enum_print;
-      int oid_output_format;
+	int enum_print;
+	int oid_output_format;
 #endif
+	int snmp_errno;
+	char snmp_errstr[128];
 } php_snmp_object;


@@ -97,14 +101,21 @@
 typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval TSRMLS_DC);

 typedef struct _ptp_snmp_prop_handler {
-      const char *name;
-      size_t name_length;
-      php_snmp_read_t read_func;
-      php_snmp_write_t write_func;
+	const char *name;
+	size_t name_length;
+	php_snmp_read_t read_func;
+	php_snmp_write_t write_func;
 } php_snmp_prop_handler;

+typedef struct _snmpobjarg {
+	char *oid;
+	char type;
+	char *value;
+
+} snmpobjarg;
+
 ZEND_BEGIN_MODULE_GLOBALS(snmp)
-      int valueretrieval;
+	int valueretrieval;
 ZEND_END_MODULE_GLOBALS(snmp)

 #ifdef ZTS
@@ -113,6 +124,9 @@
 #define SNMP_G(v) (snmp_globals.v)
 #endif

+#define REGISTER_PDO_CLASS_CONST_LONG(const_name, value) \
+	zend_declare_class_constant_long(php_snmp_get_ce(), const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
+
 #else

 #define snmp_module_ptr NULL

Modified: php/php-src/trunk/ext/snmp/snmp.c
===================================================================
--- php/php-src/trunk/ext/snmp/snmp.c	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/snmp.c	2011-02-26 08:27:26 UTC (rev 308703)
@@ -161,8 +161,12 @@
 	} \
 }

+#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

-
 ZEND_DECLARE_MODULE_GLOBALS(snmp)
 static PHP_GINIT_FUNCTION(snmp);

@@ -177,6 +181,11 @@
 /* Class entries */
 zend_class_entry *php_snmp_class_entry;

+zend_class_entry *php_snmp_get_ce()
+{
+	return php_snmp_class_entry;
+}
+
 /* Class object properties */
 static HashTable php_snmp_properties;

@@ -409,13 +418,6 @@
 ZEND_END_ARG_INFO()
 /* }}} */

-typedef struct _snmpobjarg {
-	char *oid;
-	char type;
-	char *value;
-
-} snmpobjarg;
-
 struct objid_query {
 	int count;
 	int offset;
@@ -546,6 +548,39 @@

 }

+/* {{{ php_snmp_error
+ *
+ * Record last SNMP-related error in object
+ *
+ */
+static void php_snmp_error(zval *object, const char *docref TSRMLS_DC, int type, const char *format, ...)
+{
+	va_list args;
+	php_snmp_object *snmp_object;
+
+	if (object) {
+		snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+		if (type == PHP_SNMP_ERRNO_NOERROR) {
+			memset(snmp_object->snmp_errstr, 0, sizeof(snmp_object->snmp_errstr));
+		} else {
+			va_start(args, format);
+			vsnprintf(snmp_object->snmp_errstr, sizeof(snmp_object->snmp_errstr) - 1, format, args);
+			va_end(args);
+		}
+		snmp_object->snmp_errno = type;
+	}
+
+	if (type == PHP_SNMP_ERRNO_NOERROR) {
+		return;
+	}
+
+	va_start(args, format);
+	php_verror(docref, "", E_WARNING, format, args TSRMLS_CC);
+	va_end(args);
+}
+
+/* }}} */
+
 /* {{{ php_snmp_getvalue
 *
 * SNMP value to zval converter
@@ -697,6 +732,9 @@

 	/* we start with retval=FALSE. If any actual data is aquired, retval will be set to appropriate type */
 	RETVAL_FALSE;
+
+	/* 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) {
@@ -797,7 +835,7 @@
 						}
 						SNMP_SNPRINT_OBJID(buf, sizeof(buf), vars->name, vars->name_length);
 						SNMP_SNPRINT_VALUE(buf2, sizeof(buf2), vars->name, vars->name_length, vars);
-						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet at '%s': %s", buf, buf2);
+						php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at '%s': %s", buf, buf2);
 						continue;
 					}

@@ -838,7 +876,7 @@
 					/* OID increase check */
 					if (st & SNMP_CMD_WALK) {
 						if (snmp_oid_compare(name, name_length, vars->name, vars->name_length) >= 0) {
-							php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error: OID not increasing: %s",name);
+							php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_NOT_INCREASING, "Error: OID not increasing: %s", name);
 							keepwalking = 0;
 						} else {
 							memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid));
@@ -865,9 +903,9 @@
 					}
 					if (vars) {
 						SNMP_SNPRINT_OBJID(buf, sizeof(buf), vars->name, vars->name_length);
-						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet at '%s': %s", buf, snmp_errstring(response->errstat));
+						php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at '%s': %s", buf, snmp_errstring(response->errstat));
 					} else {
-						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet at %u object_id: %s", response->errindex, snmp_errstring(response->errstat));
+						php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at %u object_id: %s", response->errindex, snmp_errstring(response->errstat));
 					}
 					if (st & (SNMP_CMD_GET | SNMP_CMD_GETNEXT)) { /* cut out bogus OID and retry */
 						if ((pdu = snmp_fix_pdu(response, ((st & SNMP_CMD_GET) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT) )) != NULL) {
@@ -884,7 +922,7 @@
 				}
 			}
 		} else if (status == STAT_TIMEOUT) {
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername);
+			php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_TIMEOUT, "No response from %s", session->peername);
 			if (objid_query->array_output) {
 				zval_dtor(return_value);
 			}
@@ -892,7 +930,7 @@
 			RETURN_FALSE;
 		} else {    /* status == STAT_ERROR */
 			snmp_error(ss, NULL, NULL, &err);
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Fatal error: %s", err);
+			php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_GENERIC, "Fatal error: %s", err);
 			free(err);
 			if (objid_query->array_output) {
 				zval_dtor(return_value);
@@ -1814,6 +1852,34 @@
 }
 /* }}} */

+/* {{{ proto long SNMP::get_errno()
+	Get last error code number */
+PHP_METHOD(snmp, get_errno)
+{
+	php_snmp_object *snmp_object;
+	zval *object = getThis();
+
+	snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+
+	RETVAL_LONG(snmp_object->snmp_errno);
+	return;
+}
+/* }}} */
+
+/* {{{ proto long SNMP::error()
+	Get last error message */
+PHP_METHOD(snmp, get_error)
+{
+	php_snmp_object *snmp_object;
+	zval *object = getThis();
+
+	snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+
+	RETVAL_STRING(snmp_object->snmp_errstr, 1);
+	return;
+}
+/* }}} */
+
 /* {{{ */
 void php_snmp_add_property(HashTable *h, const char *name, size_t name_length, php_snmp_read_t read_func, php_snmp_write_t write_func TSRMLS_DC)
 {
@@ -2053,7 +2119,11 @@
 static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval **retval TSRMLS_DC)
 {
 	MAKE_STD_ZVAL(*retval);
-	ZVAL_LONG(*retval, snmp_object->max_oids);
+	if (snmp_object->max_oids > 0) {
+		ZVAL_LONG(*retval, snmp_object->max_oids);
+	} else {
+		ZVAL_NULL(*retval);
+	}
 	return SUCCESS;
 }
 /* }}} */
@@ -2109,6 +2179,12 @@
 {
 	zval ztmp;
 	int ret = SUCCESS;
+
+	if (Z_TYPE_P(newval) == IS_NULL) {
+		snmp_object->max_oids = 0;
+		return ret;
+	}
+
 	if (Z_TYPE_P(newval) != IS_LONG) {
 		ztmp = *newval;
 		zval_copy_ctor(&ztmp);
@@ -2116,7 +2192,11 @@
 		newval = &ztmp;
 	}

-	snmp_object->max_oids = Z_LVAL_P(newval);
+	if (Z_LVAL_P(newval) > 0) {
+		snmp_object->max_oids = Z_LVAL_P(newval);
+	} else {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "max_oids should be positive integer or NULL, got %ld", Z_LVAL_P(newval));
+	}

 	if (newval == &ztmp) {
 		zval_dtor(newval);
@@ -2131,6 +2211,7 @@
 {
 	zval ztmp;
 	int ret = SUCCESS;
+
 	if (Z_TYPE_P(newval) != IS_LONG) {
 		ztmp = *newval;
 		zval_copy_ctor(&ztmp);
@@ -2244,6 +2325,8 @@
 	PHP_ME(snmp,	 getnext,			arginfo_snmp_get,		ZEND_ACC_PUBLIC)
 	PHP_ME(snmp,	 walk,				arginfo_snmp_walk,		ZEND_ACC_PUBLIC)
 	PHP_ME(snmp,	 set,				arginfo_snmp_set,		ZEND_ACC_PUBLIC)
+	PHP_ME(snmp,	 get_errno,			arginfo_snmp_void,		ZEND_ACC_PUBLIC)
+	PHP_ME(snmp,	 get_error,			arginfo_snmp_void,		ZEND_ACC_PUBLIC)

 	PHP_MALIAS(snmp, __construct,	open,		arginfo_snmp_open,		ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
 	{NULL, NULL, NULL}
@@ -2305,35 +2388,41 @@
 	PHP_SNMP_ADD_PROPERTIES(&php_snmp_properties, php_snmp_property_entries);

 #ifdef HAVE_NET_SNMP
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_SUFFIX", NETSNMP_OID_OUTPUT_SUFFIX, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_MODULE", NETSNMP_OID_OUTPUT_MODULE, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_FULL", NETSNMP_OID_OUTPUT_FULL, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NUMERIC", NETSNMP_OID_OUTPUT_NUMERIC, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_UCD", NETSNMP_OID_OUTPUT_UCD, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NONE", NETSNMP_OID_OUTPUT_NONE, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_SUFFIX",	NETSNMP_OID_OUTPUT_SUFFIX,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_MODULE",	NETSNMP_OID_OUTPUT_MODULE,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_FULL",		NETSNMP_OID_OUTPUT_FULL,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NUMERIC",	NETSNMP_OID_OUTPUT_NUMERIC,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_UCD",		NETSNMP_OID_OUTPUT_UCD,		CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NONE",		NETSNMP_OID_OUTPUT_NONE,	CONST_CS | CONST_PERSISTENT);
 #endif

-	REGISTER_LONG_CONSTANT("SNMP_VALUE_LIBRARY", SNMP_VALUE_LIBRARY, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_VALUE_PLAIN", SNMP_VALUE_PLAIN, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_VALUE_OBJECT", SNMP_VALUE_OBJECT, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VALUE_LIBRARY",	SNMP_VALUE_LIBRARY,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VALUE_PLAIN",	SNMP_VALUE_PLAIN,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VALUE_OBJECT",	SNMP_VALUE_OBJECT,	CONST_CS | CONST_PERSISTENT);

-	REGISTER_LONG_CONSTANT("SNMP_BIT_STR", ASN_BIT_STR, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OCTET_STR", ASN_OCTET_STR, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OPAQUE", ASN_OPAQUE, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_NULL", ASN_NULL, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_OBJECT_ID", ASN_OBJECT_ID, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_IPADDRESS", ASN_IPADDRESS, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_COUNTER", ASN_GAUGE, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_UNSIGNED", ASN_UNSIGNED, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_TIMETICKS", ASN_TIMETICKS, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_UINTEGER", ASN_UINTEGER, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_INTEGER", ASN_INTEGER, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_COUNTER64", ASN_COUNTER64, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_BIT_STR",		ASN_BIT_STR,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OCTET_STR",	ASN_OCTET_STR,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OPAQUE",		ASN_OPAQUE,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_NULL",		ASN_NULL,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_OBJECT_ID",	ASN_OBJECT_ID,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_IPADDRESS",	ASN_IPADDRESS,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_COUNTER",		ASN_GAUGE,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_UNSIGNED",		ASN_UNSIGNED,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_TIMETICKS",	ASN_TIMETICKS,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_UINTEGER",		ASN_UINTEGER,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_INTEGER",		ASN_INTEGER,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_COUNTER64",	ASN_COUNTER64,	CONST_CS | CONST_PERSISTENT);

-	REGISTER_LONG_CONSTANT("SNMP_VERSION_1", SNMP_VERSION_1, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_VERSION_2c", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT);
-	REGISTER_LONG_CONSTANT("SNMP_VERSION_3", SNMP_VERSION_3, CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VERSION_1",	SNMP_VERSION_1,		CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VERSION_2c",	SNMP_VERSION_2c,	CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("SNMP_VERSION_3",	SNMP_VERSION_3,		CONST_CS | CONST_PERSISTENT);

+	REGISTER_PDO_CLASS_CONST_LONG("ERRNO_NOERROR",			(long)PHP_SNMP_ERRNO_NOERROR);
+	REGISTER_PDO_CLASS_CONST_LONG("ERRNO_GENERIC",			(long)PHP_SNMP_ERRNO_GENERIC);
+	REGISTER_PDO_CLASS_CONST_LONG("ERRNO_TIMEOUT",			(long)PHP_SNMP_ERRNO_TIMEOUT);
+	REGISTER_PDO_CLASS_CONST_LONG("ERRNO_ERROR_IN_REPLY",		(long)PHP_SNMP_ERRNO_ERROR_IN_REPLY);
+	REGISTER_PDO_CLASS_CONST_LONG("ERRNO_OID_NOT_INCREASING",	(long)PHP_SNMP_ERRNO_OID_NOT_INCREASING);
+
 	return SUCCESS;
 }
 /* }}} */

Added: php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt	2011-02-26 08:27:26 UTC (rev 308703)
@@ -0,0 +1,63 @@
+--TEST--
+OO API: get_errno & get_error functions
+--CREDITS--
+Boris Lytochkin
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+require_once(dirname(__FILE__).'/snmp_include.inc');
+
+//EXPECTF format is quickprint OFF
+snmp_set_enum_print(false);
+snmp_set_quick_print(false);
+snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
+snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
+
+echo "SNMP::ERRNO_NOERROR\n";
+$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
+var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
+var_dump($session->get_errno() == SNMP::ERRNO_NOERROR);
+var_dump($session->get_error());
+$session->close();
+
+echo "SNMP::ERRNO_TIMEOUT\n";
+$session = new SNMP(SNMP_VERSION_2c, $hostname, 'timeout_community_432', $timeout, $retries);
+$session->valueretrieval = SNMP_VALUE_LIBRARY;
+var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
+var_dump($session->get_errno() == SNMP::ERRNO_TIMEOUT);
+var_dump($session->get_error());
+$session->close();
+echo "SNMP::ERRNO_ERROR_IN_REPLY\n";
+$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
+var_dump(@$session->get('.1.3.6.1.2.1.1.1.110'));
+var_dump($session->get_errno() == SNMP::ERRNO_ERROR_IN_REPLY);
+var_dump($session->get_error());
+$session->close();
+echo "SNMP::ERRNO_GENERIC\n";
+$session = new SNMP(SNMP_VERSION_3, $hostname, 'somebogususer', $timeout, $retries);
+$session->set_security('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
+var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
+var_dump($session->get_errno() == SNMP::ERRNO_GENERIC);
+var_dump($session->get_error());
+$session->close();
+?>
+--EXPECTF--
+SNMP::ERRNO_NOERROR
+%string|unicode%(%d) "%s"
+bool(true)
+%string|unicode%(0) ""
+SNMP::ERRNO_TIMEOUT
+bool(false)
+bool(true)
+%string|unicode%(%d) "No response from %s"
+SNMP::ERRNO_ERROR_IN_REPLY
+bool(false)
+bool(true)
+%string|unicode%(%d) "Error in packet %s"
+SNMP::ERRNO_GENERIC
+bool(false)
+bool(true)
+%string|unicode%(%d) "Fatal error: Unknown user name"
\ No newline at end of file

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-error.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object-error.phpt	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-error.phpt	2011-02-26 08:27:26 UTC (rev 308703)
@@ -1,5 +1,5 @@
 --TEST--
-Errors in SNMP session-wise functions
+OO API: Generic errors
 --CREDITS--
 Boris Lytochkin
 --SKIPIF--
@@ -51,6 +51,10 @@
 var_dump($session->get());
 var_dump($session->set());

+var_dump($session->max_oids);
+$session->max_oids = "ttt";
+$session->max_oids = 0;
+var_dump($session->max_oids);
 ?>
 --EXPECTF--
 SNMP::__construct() expects at least 3 parameters, 2 given
@@ -82,3 +86,9 @@

 Warning: SNMP::set() expects exactly 3 parameters, 0 given in %s on line %d
 bool(false)
+NULL
+
+Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
+
+Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
+NULL
\ No newline at end of file

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt	2011-02-26 08:27:26 UTC (rev 308703)
@@ -59,6 +59,9 @@

 $session->info = array("blah" => 2);
 var_dump($session->info);
+
+$session->max_oids = NULL;
+var_dump($session->max_oids);
 ?>
 --EXPECTF--
 Check working
@@ -75,7 +78,7 @@
     int(%d)
   }
   ["max_oids"]=>
-  int(0)
+  NULL
   ["valueretrieval"]=>
   int(1)
   ["quick_print"]=>
@@ -183,4 +186,5 @@
   int(%i)
   ["retries"]=>
   int(%d)
-}
\ No newline at end of file
+}
+NULL
\ No newline at end of file

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt	2011-02-26 08:27:26 UTC (rev 308703)
@@ -1,5 +1,5 @@
 --TEST--
-OO API SNMP::set_security (errors)
+OO API: SNMP::set_security (errors)
 --CREDITS--
 Boris Lytochkin
 --SKIPIF--

Modified: php/php-src/trunk/ext/snmp/tests/snmp-object.phpt
===================================================================
--- php/php-src/trunk/ext/snmp/tests/snmp-object.phpt	2011-02-26 04:34:53 UTC (rev 308702)
+++ php/php-src/trunk/ext/snmp/tests/snmp-object.phpt	2011-02-26 08:27:26 UTC (rev 308703)
@@ -57,6 +57,16 @@
 var_dump(array_shift($z));
 var_dump($session->close());

+echo "WALK multiple on single OID, max_oids set to 30\n";
+$session = new SNMP(SNMP_VERSION_2c, $hostname, $community, $timeout, $retries);
+$session->max_oids = 30;
+$z = $session->walk('.1.3.6.1.2.1.1');
+var_dump(gettype($z));
+var_dump(count($z));
+var_dump(key($z));
+var_dump(array_shift($z));
+var_dump($session->close());
+
 echo "SNMPv3 (default security settings)\n";
 $session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
 #$session->set_security($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
@@ -134,6 +144,12 @@
 string(%d) "%S"
 string(%d) "%S"
 bool(true)
+WALK multiple on single OID, max_oids set to 30
+string(5) "array"
+int(%d)
+string(%d) "%S"
+string(%d) "%S"
+bool(true)
 SNMPv3 (default security settings)
 string(%d) "%S"
 string(%d) "%S"
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to