php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #53594
Patch patch-ext-snmp-tests revision 2011-01-05 18:00 UTC by lytboris at gmail dot com
revision 2010-12-29 16:50 UTC by lytboris at gmail dot com
revision 2010-12-22 18:53 UTC by lytboris at gmail dot com
Patch patch-ext-snmp-src revision 2011-01-05 17:59 UTC by lytboris at gmail dot com
revision 2010-12-29 16:50 UTC by lytboris at gmail dot com
Patch patch-ext-snmp-trunk revision 2010-12-23 06:18 UTC by lytboris at gmail dot com
revision 2010-12-23 06:16 UTC by lytboris at gmail dot com
Patch php-ext-snmp-source revision 2010-12-22 18:52 UTC by lytboris at gmail dot com

Patch php-ext-snmp-source for SNMP related Bug #53594

Patch version 2010-12-22 18:52 UTC

Return to Bug #53594 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: lytboris@gmail.com

--- ext/snmp/php_snmp.h	2010-01-03 12:23:27.000000000 +0300
+++ ext/snmp/php_snmp.h	2010-12-17 22:35:51.000000000 +0300
@@ -43,7 +43,9 @@
 PHP_MINFO_FUNCTION(snmp);
 
 PHP_FUNCTION(snmpget);
+PHP_FUNCTION(snmprealget);
 PHP_FUNCTION(snmpgetnext);
+PHP_FUNCTION(snmprealgetnext);
 PHP_FUNCTION(snmpwalk);
 PHP_FUNCTION(snmprealwalk);
 PHP_FUNCTION(snmp_get_quick_print);
@@ -53,13 +55,17 @@
 PHP_FUNCTION(snmpset);
 
 PHP_FUNCTION(snmp2_get);
+PHP_FUNCTION(snmp2_real_get);
 PHP_FUNCTION(snmp2_getnext);
+PHP_FUNCTION(snmp2_real_getnext);
 PHP_FUNCTION(snmp2_walk);
 PHP_FUNCTION(snmp2_real_walk);
 PHP_FUNCTION(snmp2_set);
 
 PHP_FUNCTION(snmp3_get);
+PHP_FUNCTION(snmp3_real_get);
 PHP_FUNCTION(snmp3_getnext);
+PHP_FUNCTION(snmp3_real_getnext);
 PHP_FUNCTION(snmp3_walk);
 PHP_FUNCTION(snmp3_real_walk);
 PHP_FUNCTION(snmp3_set);
--- ext/snmp/snmp.c	2010-01-03 12:23:27.000000000 +0300
+++ ext/snmp/snmp.c	2010-12-22 13:22:23.000000000 +0300
@@ -1,3 +1,4 @@
+
 /*
    +----------------------------------------------------------------------+
    | PHP Version 5                                                        |
@@ -97,6 +98,23 @@
  */
 #define OIDSIZE(p) (sizeof(p)/sizeof(oid))
 
+/* Another ugly macros, since UCD-SNMP has no snprint_* */
+#ifdef HAVE_NET_SNMP
+#define SNMP_SNPRINT_OBJID(dst, dstlen, src, srclen) (snprint_objid((dst), (dstlen), (src), (srclen)))
+#define SNMP_SNPRINT_VALUE(dst, dstlen, srcname, srcnamelen, src) (snprint_value((dst), (dstlen), (srcname), (srcnamelen), (src)))
+#else
+#define SNMP_SNPRINT_OBJID(dst, dstlen, src, srclen) (sprint_objid((dst), (src), (srclen)))
+#define SNMP_SNPRINT_VALUE(dst, dstlen, srcname, srcnamelen, src) (sprint_value((dst), (srcname), (srcnamelen), (src)))
+#endif
+
+
+#if PHP_VERSION_ID < 50300
+#define Z_ISREF_PP(oid) (PZVAL_IS_REF(*(oid)))
+#define zend_parse_parameters_none() zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
+        
+#endif
+
+
 /* For really old ucd-snmp versions.. */
 #ifndef HAVE_SNMP_PARSE_OID
 #define snmp_parse_oid read_objid
@@ -112,47 +130,317 @@
 /* constant - can be shared among threads */
 static oid objid_mib[] = {1, 3, 6, 1, 2, 1};
 
+/* {{{ arginfo */
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmpget, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmprealget, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmpgetnext, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmprealgetnext, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmpwalk, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmprealwalk, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_get_quick_print, 0, 0, 1)
+	ZEND_ARG_INFO(0, d)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_quick_print, 0, 0, 1)
+	ZEND_ARG_INFO(0, quick_print)
+ZEND_END_ARG_INFO()
+
+#ifdef HAVE_NET_SNMP
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_enum_print, 0, 0, 1)
+	ZEND_ARG_INFO(0, enum_print)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_oid_output_format, 0, 0, 1)
+	ZEND_ARG_INFO(0, oid_format)
+ZEND_END_ARG_INFO()
+#endif
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmpset, 0, 0, 5)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, type)
+	ZEND_ARG_INFO(0, value)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_get, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_real_get, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_getnext, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_real_getnext, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_walk, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_real_walk, 0, 0, 3)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp2_set, 0, 0, 5)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, community)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, type)
+	ZEND_ARG_INFO(0, value)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_php_snmpv3, 0, 0, 2)
+	ZEND_ARG_INFO(0, s)
+	ZEND_ARG_INFO(0, st)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_get, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_real_get, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_getnext, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_real_getnext, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_walk, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_real_walk, 0, 0, 8)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp3_set, 0, 0, 10)
+	ZEND_ARG_INFO(0, host)
+	ZEND_ARG_INFO(0, sec_name)
+	ZEND_ARG_INFO(0, sec_level)
+	ZEND_ARG_INFO(0, auth_protocol)
+	ZEND_ARG_INFO(0, auth_passphrase)
+	ZEND_ARG_INFO(0, priv_protocol)
+	ZEND_ARG_INFO(0, priv_passphrase)
+	ZEND_ARG_INFO(0, object_id)
+	ZEND_ARG_INFO(0, type)
+	ZEND_ARG_INFO(0, value)
+	ZEND_ARG_INFO(0, timeout)
+	ZEND_ARG_INFO(0, retries)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_valueretrieval, 0, 0, 1)
+	ZEND_ARG_INFO(0, method)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_snmp_get_valueretrieval, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_read_mib, 0, 0, 1)
+	ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+/* }}} */
+
+typedef struct _snmpobjarg {
+	char *oid;
+	char type;
+	char *value;
+
+} snmpobjarg;
+
+#define SNMP_MAXOIDS_IN_PDU 64
+struct objid_set {
+	int count;
+	int array_output;
+	snmpobjarg vars[SNMP_MAXOIDS_IN_PDU];
+};
+
 /* {{{ snmp_functions[]
  */
-zend_function_entry snmp_functions[] = {
-	PHP_FE(snmpget, NULL)
-	PHP_FE(snmpgetnext, NULL)
-	PHP_FE(snmpwalk, NULL)
-	PHP_FE(snmprealwalk, NULL)
-	PHP_FALIAS(snmpwalkoid, snmprealwalk, NULL)
-	PHP_FE(snmp_get_quick_print, NULL)
-	PHP_FE(snmp_set_quick_print, NULL)
+const zend_function_entry snmp_functions[] = {
+	PHP_FE(snmpget,					arginfo_snmpget)
+	PHP_FE(snmprealget,				arginfo_snmprealget)
+	PHP_FE(snmpgetnext, 				arginfo_snmpgetnext)
+	PHP_FE(snmprealgetnext, 			arginfo_snmprealgetnext)
+	PHP_FE(snmpwalk, 				arginfo_snmpwalk)
+	PHP_FE(snmprealwalk, 				arginfo_snmprealwalk)
+	PHP_FALIAS(snmpwalkoid, snmprealwalk, 	arginfo_snmprealwalk)
+	PHP_FE(snmp_get_quick_print, 			arginfo_snmp_get_quick_print)
+	PHP_FE(snmp_set_quick_print, 			arginfo_snmp_set_quick_print)
 #ifdef HAVE_NET_SNMP
-	PHP_FE(snmp_set_enum_print, NULL)
-	PHP_FE(snmp_set_oid_output_format, NULL)
-	PHP_FALIAS(snmp_set_oid_numeric_print, snmp_set_oid_output_format, NULL)
-#endif
-	PHP_FE(snmpset, NULL)
-
-	PHP_FE(snmp2_get, NULL)
-	PHP_FE(snmp2_getnext, NULL)
-	PHP_FE(snmp2_walk, NULL)
-	PHP_FE(snmp2_real_walk, NULL)
-	PHP_FE(snmp2_set, NULL)
-
-	PHP_FE(snmp3_get, NULL)
-	PHP_FE(snmp3_getnext, NULL)
-	PHP_FE(snmp3_walk, NULL)
-	PHP_FE(snmp3_real_walk, NULL)
-	PHP_FE(snmp3_set, NULL)
-	PHP_FE(snmp_set_valueretrieval, NULL)
-	PHP_FE(snmp_get_valueretrieval, NULL)
+	PHP_FE(snmp_set_enum_print, 			arginfo_snmp_set_enum_print)
+	PHP_FE(snmp_set_oid_output_format, 		arginfo_snmp_set_oid_output_format)
+	PHP_FALIAS(snmp_set_oid_numeric_print, snmp_set_oid_output_format, arginfo_snmp_set_oid_output_format)
+#endif
+	PHP_FE(snmpset, 				arginfo_snmpset)
+
+	PHP_FE(snmp2_get, 				arginfo_snmp2_get)
+	PHP_FE(snmp2_real_get, 				arginfo_snmp2_real_get)
+	PHP_FE(snmp2_getnext, 				arginfo_snmp2_getnext)
+	PHP_FE(snmp2_real_getnext, 			arginfo_snmp2_real_getnext)
+	PHP_FE(snmp2_walk, 				arginfo_snmp2_walk)
+	PHP_FE(snmp2_real_walk, 			arginfo_snmp2_real_walk)
+	PHP_FE(snmp2_set, 				arginfo_snmp2_set)
+
+	PHP_FE(snmp3_get, 				arginfo_snmp3_get)
+	PHP_FE(snmp3_real_get, 				arginfo_snmp3_real_get)
+	PHP_FE(snmp3_getnext, 				arginfo_snmp3_getnext)
+	PHP_FE(snmp3_real_getnext,			arginfo_snmp3_real_getnext)
+	PHP_FE(snmp3_walk, 				arginfo_snmp3_walk)
+	PHP_FE(snmp3_real_walk, 			arginfo_snmp3_real_walk)
+	PHP_FE(snmp3_set, 				arginfo_snmp3_set)
+	PHP_FE(snmp_set_valueretrieval, arginfo_snmp_set_valueretrieval)
+	PHP_FE(snmp_get_valueretrieval, arginfo_snmp_get_valueretrieval)
 
-	PHP_FE(snmp_read_mib, NULL)
+	PHP_FE(snmp_read_mib, 				arginfo_snmp_read_mib)
 	{NULL,NULL,NULL}
 };
 /* }}} */
 
-#define SNMP_CMD_GET		1
-#define SNMP_CMD_GETNEXT	2
-#define SNMP_CMD_WALK		3
-#define SNMP_CMD_REALWALK	4
-#define SNMP_CMD_SET		11
+/* query an agent with GET method */
+#define SNMP_CMD_GET		(1<<0)
+/* query an agent with GETNEXT method */
+#define SNMP_CMD_GETNEXT	(1<<1)
+/* query an agent with SET method */
+#define SNMP_CMD_SET		(1<<2)
+/* walk the mib */
+#define SNMP_CMD_WALK		(1<<3)
+/* force oid,value output */
+#define SNMP_ASSOC_OUTPUT	(1<<7)
 
 /* {{{ snmp_module_entry
  */
@@ -192,6 +480,7 @@
  */
 PHP_MINIT_FUNCTION(snmp)
 {
+	netsnmp_log_handler *logh;
 	init_snmp("snmpapp");
 
 #ifdef NETSNMP_DS_LIB_DONT_PERSIST_STATE
@@ -199,6 +488,13 @@
 	netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1);
 #endif
 
+	/* Disable logging, use exit status'es and related variabled to detect errors */
+	shutdown_snmp_logging();
+	logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR);
+	if (logh) {
+		logh->pri_max = LOG_ERR;
+	}
+
 #ifdef HAVE_NET_SNMP
 	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);
@@ -254,20 +550,30 @@
 static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_DC)
 {
 	zval *val;
-#if I64CHARSZ > 2047
-	char buf[I64CHARSZ + 1];
-#else
-	char buf[2048];
-#endif
+	char sbuf[64];
+	char *buf = &(sbuf[0]);
+	char *dbuf = (char *)NULL;
+	int buflen = sizeof(sbuf) - 1;
+	int val_len = vars->val_len;
+	
+	if (SNMP_G(valueretrieval) == SNMP_VALUE_LIBRARY) {
+		val_len += 32; /* snprint_value will add type info into value, make some space for it */
+	}
+
+	/* use emalloc() for large values, use static array otherwize */
+	if(val_len > buflen){
+		if ((dbuf = (char *)emalloc(val_len + 1))) {
+			buf = dbuf;
+			buflen = val_len;
+		} else {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "malloc() failed: %s, fallback to static array", strerror(errno));
+		}
+	}
 
-	buf[0] = 0;
+	*buf = 0;
 
 	if (SNMP_G(valueretrieval) == SNMP_VALUE_LIBRARY) {
-#ifdef HAVE_NET_SNMP
-		snprint_value(buf, sizeof(buf), vars->name, vars->name_length, vars);
-#else
-		sprint_value(buf,vars->name, vars->name_length, vars);
-#endif
+		SNMP_SNPRINT_VALUE(buf, buflen, vars->name, vars->name_length, vars);
 		ZVAL_STRING(snmpval, buf, 1);
 		return;
 	}
@@ -289,20 +595,15 @@
 		break;
 
 	case ASN_OBJECT_ID:		/* 0x06, asn1.h */
-#ifdef HAVE_NET_SNMP
-		snprint_objid(buf, sizeof(buf), vars->val.objid, vars->val_len / sizeof(oid));
-#else
-		sprint_objid(buf, vars->val.objid, vars->val_len / sizeof(oid));
-#endif
-
+		SNMP_SNPRINT_OBJID(buf, buflen, vars->val.objid, vars->val_len / sizeof(oid));
 		ZVAL_STRING(val, buf, 1);
 		break;
 
 	case ASN_IPADDRESS:		/* 0x40, snmp_impl.h */
-		snprintf(buf, sizeof(buf)-1, "%d.%d.%d.%d",
-		         (vars->val.string)[0], (vars->val.string)[1],
-		         (vars->val.string)[2], (vars->val.string)[3]);
-		buf[sizeof(buf)-1]=0;
+		snprintf(buf, buflen, "%d.%d.%d.%d",
+			 (vars->val.string)[0], (vars->val.string)[1],
+			 (vars->val.string)[2], (vars->val.string)[3]);
+		buf[buflen]=0;
 		ZVAL_STRING(val, buf, 1);
 		break;
 
@@ -311,17 +612,35 @@
 	/* ASN_UNSIGNED is the same as ASN_GAUGE */
 	case ASN_TIMETICKS:		/* 0x43, snmp_impl.h */
 	case ASN_UINTEGER:		/* 0x47, snmp_impl.h */
-		snprintf(buf, sizeof(buf)-1, "%lu", *vars->val.integer);
-		buf[sizeof(buf)-1]=0;
+		snprintf(buf, buflen, "%lu", *vars->val.integer);
+		buf[buflen]=0;
 		ZVAL_STRING(val, buf, 1);
 		break;
 
 	case ASN_INTEGER:		/* 0x02, asn1.h */
-		snprintf(buf, sizeof(buf)-1, "%ld", *vars->val.integer);
-		buf[sizeof(buf)-1]=0;
+		snprintf(buf, buflen, "%ld", *vars->val.integer);
+		buf[buflen]=0;
+		ZVAL_STRING(val, buf, 1);
+		break;
+
+#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
+	case ASN_OPAQUE_FLOAT:		/* 0x78, asn1.h */
+		snprintf(buf, buflen, "%f", *vars->val.floatVal);
+		ZVAL_STRING(val, buf, 1);
+		break;
+
+	case ASN_OPAQUE_DOUBLE:		/* 0x79, asn1.h */
+		snprintf(buf, buflen, "%Lf", *vars->val.doubleVal);
+		ZVAL_STRING(val, buf, 1);
+		break;
+
+	case ASN_OPAQUE_I64:		/* 0x80, asn1.h */
+		printI64(buf, vars->val.counter64);
 		ZVAL_STRING(val, buf, 1);
 		break;
 
+	case ASN_OPAQUE_U64:		/* 0x81, asn1.h */
+#endif
 	case ASN_COUNTER64:		/* 0x46, snmp_impl.h */
 		printU64(buf, vars->val.counter64);
 		ZVAL_STRING(val, buf, 1);
@@ -329,6 +648,7 @@
 
 	default:
 		ZVAL_STRING(val, "Unknown value type", 1);
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value type: %u", vars->type);
 		break;
 	}
 
@@ -340,26 +660,19 @@
 		add_property_long(snmpval, "type", vars->type);
 		add_property_zval(snmpval, "value", val);
 	}
+	if(dbuf){ /* malloc was used to store value */
+		efree(dbuf);
+	}
 }
 
 /* {{{ php_snmp_internal
 *
-* Generic SNMP object fetcher (for all SNMP versions)
-*
-* st=SNMP_CMD_GET   get - query an agent with SNMP-GET.
-* st=SNMP_CMD_GETNEXT   getnext - query an agent with SNMP-GETNEXT.
-* st=SNMP_CMD_WALK   walk - walk the mib and return a single dimensional array 
-*          containing the values.
-* st=SNMP_CMD_REALWALK   realwalk() and walkoid() - walk the mib and return an 
-*          array of oid,value pairs.
-* st=SNMP_CMD_SET  set() - query an agent and set a single value
+* SNMP object fetcher/setter for all SNMP versions
 *
 */
 static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st, 
 							struct snmp_session *session,
-							char *objid,
-							char type,
-							char* value) 
+							struct objid_set *objid_set)
 {
 	struct snmp_session *ss;
 	struct snmp_pdu *pdu=NULL, *response;
@@ -375,14 +688,23 @@
 	int keepwalking=1;
 	char *err;
 	zval *snmpval = NULL;
+	int snmp_errno;
+
+	/* we start with retval=FALSE. If any actual data is aquired, retval will be set to appropriate type */
+	RETVAL_FALSE;
 
-	if (st >= SNMP_CMD_WALK) { /* walk */
+	if (st & SNMP_CMD_WALK) {
+		if (objid_set->count > 1) {
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Multi OID walks are not supported!");
+			RETURN_FALSE;
+		}
 		rootlen = MAX_NAME_LEN;
-		if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */
-			if (snmp_parse_oid(objid, root, &rootlen)) {
+		if (strlen(objid_set->vars[0].oid)) { /* on a walk, an empty string means top of tree - no error */
+			if (snmp_parse_oid(objid_set->vars[0].oid, root, &rootlen)) {
 				gotroot = 1;
 			} else {
-				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid);
+				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid_set->vars[0].oid);
+				RETURN_FALSE;
 			}
 		}
 
@@ -391,6 +713,9 @@
 			rootlen = sizeof(objid_mib) / sizeof(oid);
 			gotroot = 1;
 		}
+
+		memmove((char *)name, (char *)root, rootlen * sizeof(oid));
+		name_length = rootlen;
 	}
 
 	if ((ss = snmp_open(session)) == NULL) {
@@ -400,45 +725,43 @@
 		RETURN_FALSE;
 	}
 
-	if (st >= SNMP_CMD_WALK) {
-		memmove((char *)name, (char *)root, rootlen * sizeof(oid));
-		name_length = rootlen;
-		switch(st) {
-			case SNMP_CMD_WALK:
-			case SNMP_CMD_REALWALK:
-				array_init(return_value);
-				break;
-			default:
-				RETVAL_TRUE;
-				break;
-		}
-	}
-
 	while (keepwalking) {
 		keepwalking = 0;
-		if ((st == SNMP_CMD_GET) || (st == SNMP_CMD_GETNEXT)) {
-			name_length = MAX_OID_LEN;
-			if (!snmp_parse_oid(objid, name, &name_length)) {
-				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid);
-				snmp_close(ss);
-				RETURN_FALSE;
+		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; count < objid_set->count; count++){
+				name_length = MAX_OID_LEN;
+				if (!snmp_parse_oid(objid_set->vars[count].oid, name, &name_length)) {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid_set->vars[count].oid);
+				} else {
+					snmp_add_null_var(pdu, name, name_length);
+				}
 			}
-			pdu = snmp_pdu_create((st == SNMP_CMD_GET) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT);
-			snmp_add_null_var(pdu, name, name_length);
-		} else if (st == SNMP_CMD_SET) {
-			pdu = snmp_pdu_create(SNMP_MSG_SET);
-			if (snmp_add_var(pdu, name, name_length, type, value)) {
-#ifdef HAVE_NET_SNMP
-				snprint_objid(buf, sizeof(buf), name, name_length);
-#else
-				sprint_objid(buf, name, name_length);
-#endif
-				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: %s %c %s", buf, type, value);
+			if(pdu->variables == NULL){
 				snmp_free_pdu(pdu);
 				snmp_close(ss);
 				RETURN_FALSE;
 			}
-		} else if (st >= SNMP_CMD_WALK) {
+		} else if (st & SNMP_CMD_SET) {
+			pdu = snmp_pdu_create(SNMP_MSG_SET);
+			for (count = 0; count < objid_set->count; count++){
+				name_length = MAX_OID_LEN;
+				if (!snmp_parse_oid(objid_set->vars[count].oid, name, &name_length)) {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid_set->vars[count].oid);
+					snmp_free_pdu(pdu);
+					snmp_close(ss);
+					RETURN_FALSE;
+				} else {
+					if ((snmp_errno = snmp_add_var(pdu, name, name_length, objid_set->vars[count].type, objid_set->vars[count].value))) {
+						SNMP_SNPRINT_OBJID(buf, sizeof(buf), name, name_length);
+						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: OID='%s' type='%c' value='%s': %s", buf, objid_set->vars[count].type, objid_set->vars[count].value, snmp_api_errstring(snmp_errno));
+						snmp_free_pdu(pdu);
+						snmp_close(ss);
+						RETURN_FALSE;
+					}
+				}
+			}
+		} else if (st & SNMP_CMD_WALK) {
 			if (session->version == SNMP_VERSION_1) {
 				pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
 			} else {
@@ -453,95 +776,90 @@
 		status = snmp_synch_response(ss, pdu, &response);
 		if (status == STAT_SUCCESS) {
 			if (response->errstat == SNMP_ERR_NOERROR) {
+				if (st & SNMP_CMD_SET) {
+					snmp_free_pdu(response);
+					snmp_close(ss);
+					RETURN_TRUE;
+				}
 				for (vars = response->variables; vars; vars = vars->next_variable) {
-					if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET && 
-						(vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) {
-						continue;       /* not part of this subtree */
+					/* do not output errors as values */
+					if ( 	vars->type == SNMP_ENDOFMIBVIEW || 
+						vars->type == SNMP_NOSUCHOBJECT || 
+						vars->type == SNMP_NOSUCHINSTANCE ) {
+						if ((st & SNMP_CMD_WALK) && Z_TYPE_P(return_value) == IS_ARRAY) {
+							break;
+						}
+						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);
+						continue;
 					}
-
-					if (st != SNMP_CMD_SET) {
-						MAKE_STD_ZVAL(snmpval);
-						php_snmp_getvalue(vars, snmpval TSRMLS_CC);
+					
+					if ((st & SNMP_CMD_WALK) && 
+						(vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { /* not part of this subtree */
+						if (Z_TYPE_P(return_value) == IS_ARRAY) { /* some records are fetched already, shut down further lookup */
+							keepwalking = 0;
+						} else {
+							/* first fetched OID is out of subtree, fallback to GET query */
+							st |= SNMP_CMD_GET;
+							st ^= SNMP_CMD_WALK;
+							keepwalking = 1;
+						}
+						break;
 					}
 
-					if (st == SNMP_CMD_GET) {
+					MAKE_STD_ZVAL(snmpval);
+					php_snmp_getvalue(vars, snmpval TSRMLS_CC);
+
+					if(objid_set->array_output && Z_TYPE_P(return_value) == IS_BOOL) {
+						array_init(return_value);
+					}
+					
+					if (st & SNMP_ASSOC_OUTPUT) {
+						SNMP_SNPRINT_OBJID(buf2, sizeof(buf2), vars->name, vars->name_length);
+						add_assoc_zval(return_value, buf2, snmpval);
+					} else if (objid_set->array_output) {
+						add_next_index_zval(return_value, snmpval);
+					} else {
 						*return_value = *snmpval;
 						zval_copy_ctor(return_value);
 						zval_ptr_dtor(&snmpval);
-						snmp_free_pdu(response);
-						snmp_close(ss);
-						return;
-					} else if (st == SNMP_CMD_GETNEXT) {
-						*return_value = *snmpval;
-						zval_copy_ctor(return_value);
-						snmp_free_pdu(response);
-						snmp_close(ss);
-						return;
-					} else if (st == SNMP_CMD_WALK) {
-						add_next_index_zval(return_value,snmpval); /* Add to returned array */
-					} else if (st == SNMP_CMD_REALWALK && vars->type != SNMP_ENDOFMIBVIEW && vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) {
-#ifdef HAVE_NET_SNMP
-						snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
-#else
-						sprint_objid(buf2, vars->name, vars->name_length);
-#endif
-						add_assoc_zval(return_value,buf2,snmpval);
+						break;
 					}
-					if (st >= SNMP_CMD_WALK && st != SNMP_CMD_SET) {
-						if (vars->type != SNMP_ENDOFMIBVIEW && 
-							vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) {
-							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);
-								keepwalking = 0;
-							} else {
-								memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid));
-								name_length = vars->name_length;
-								keepwalking = 1;
-							}
+
+					/* 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);
+							keepwalking = 0;
+						} else {
+							memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid));
+							name_length = vars->name_length;
+							keepwalking = 1;
 						}
 					}
 				}	
 			} else {
-				if (st != SNMP_CMD_WALK || response->errstat != SNMP_ERR_NOSUCHNAME) {
-					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet: %s", snmp_errstring(response->errstat));
-					if (response->errstat == SNMP_ERR_NOSUCHNAME) {
-						for (count=1, vars = response->variables; vars && count != response->errindex;
+				if (!(st & SNMP_CMD_WALK) || response->errstat != SNMP_ERR_NOSUCHNAME || Z_TYPE_P(return_value) == IS_BOOL) {
+					for (	count=1, vars = response->variables;
+						vars && count != response->errindex;
 						vars = vars->next_variable, count++);
-						if (vars) {
-#ifdef HAVE_NET_SNMP
-							snprint_objid(buf, sizeof(buf), vars->name, vars->name_length);
-#else
-							sprint_objid(buf,vars->name, vars->name_length);
-#endif
-						}
-						php_error_docref(NULL TSRMLS_CC, E_WARNING, "This name does not exist: %s",buf);
+
+					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));
+					} else {
+						php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet at %u object_id: %s", response->errindex, snmp_errstring(response->errstat));
 					}
-					if (st == SNMP_CMD_GET) {
-						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) {
-							snmp_free_pdu(response);
-							goto retry;
-						}
-					} else if (st == SNMP_CMD_SET) {
-						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) {
-							snmp_free_pdu(response);
-							goto retry;
-						}
-					} else if (st == SNMP_CMD_GETNEXT) {
-						if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) {
-							snmp_free_pdu(response);
-							goto retry;
-						}
-					} else if (st >= SNMP_CMD_WALK) { /* Here we do walks. */
-						if ((pdu = snmp_fix_pdu(response, ((session->version == SNMP_VERSION_1)
-										? SNMP_MSG_GETNEXT
-										: SNMP_MSG_GETBULK))) != NULL) {
+					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) {
 							snmp_free_pdu(response);
 							goto retry;
 						}
 					}
 					snmp_free_pdu(response);
 					snmp_close(ss);
-					if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) {
+					if (objid_set->array_output) {
 						zval_dtor(return_value);
 					}
 					RETURN_FALSE;
@@ -549,14 +867,16 @@
 			}
 		} else if (status == STAT_TIMEOUT) {
 			php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername);
-			if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) {
+			if (objid_set->array_output) {
 				zval_dtor(return_value);
 			}
 			snmp_close(ss);
 			RETURN_FALSE;
 		} else {    /* status == STAT_ERROR */
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred, quitting");
-			if (st == SNMP_CMD_WALK || st == SNMP_CMD_REALWALK) {
+			snmp_error(ss, NULL, NULL, &err);
+			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Fatal error: %s", err);
+			free(err);
+			if (objid_set->array_output) {
 				zval_dtor(return_value);
 			}
 			snmp_close(ss);
@@ -570,78 +890,164 @@
 }
 /* }}} */
 
+/* {{{ php_snmp_parse_oid
+*
+* Unified parser for OID (and type, value for SNMP_SET command)
+* Used in all SNMP protocol version functions
+*/
+
+static int php_snmp_parse_oid(int st, struct objid_set *objid_set, zval **oid, zval **type, zval **value)
+{
+	char *pptr;
+	HashPosition pos_oid, pos_type, pos_value;
+	zval **tmp_oid, **tmp_type, **tmp_value;
+
+	if (Z_TYPE_PP(oid) != IS_ARRAY) {
+		if (Z_ISREF_PP(oid)) {
+			SEPARATE_ZVAL(oid);
+		}
+		convert_to_string_ex(oid);
+	} else if (Z_TYPE_PP(oid) == IS_ARRAY) {
+		zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
+	}
+
+	if (st & SNMP_CMD_SET) {
+		if (Z_TYPE_PP(type) != IS_ARRAY) {
+			if (Z_ISREF_PP(type)) {
+				SEPARATE_ZVAL(type);
+			}
+			convert_to_string_ex(type);
+		} else if (Z_TYPE_PP(type) == IS_ARRAY) {
+			zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(type), &pos_type);
+		}
+
+		if (Z_TYPE_PP(value) != IS_ARRAY) {
+			if (Z_ISREF_PP(value)) {
+				SEPARATE_ZVAL(value);
+			}
+			convert_to_string_ex(value);
+		} else if (Z_TYPE_PP(value) == IS_ARRAY) {
+			zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(value), &pos_value);
+		}
+	}
+
+	objid_set->count = 0;
+	objid_set->array_output = ((st & (SNMP_CMD_WALK | SNMP_ASSOC_OUTPUT)) ? TRUE : FALSE);
+	if (Z_TYPE_PP(oid) == IS_STRING) {
+		objid_set->vars[objid_set->count].oid = Z_STRVAL_PP(oid);
+		if (st & SNMP_CMD_SET) {
+			if (Z_TYPE_PP(type) == IS_STRING && Z_TYPE_PP(value) == IS_STRING) {
+				if (Z_STRLEN_PP(type) != 1) {
+					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bogus type '%s', should be single char, got %u", Z_STRVAL_PP(type), Z_STRLEN_PP(type));
+					return FALSE;
+				}
+				pptr = Z_STRVAL_PP(type);
+				objid_set->vars[objid_set->count].type = *pptr;
+				objid_set->vars[objid_set->count].value = Z_STRVAL_PP(value);
+			} else {
+				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Single objid and multiple type or values are not supported");
+				return FALSE;
+			}
+		}
+		objid_set->count++;
+	} 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;
+		}
+		objid_set->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
+		for (	zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
+			zend_hash_get_current_data_ex(Z_ARRVAL_PP(oid), (void **) &tmp_oid, &pos_oid) == SUCCESS;
+			zend_hash_move_forward_ex(Z_ARRVAL_PP(oid), &pos_oid) ) {
+
+			convert_to_string_ex(tmp_oid);
+			objid_set->vars[objid_set->count].oid = Z_STRVAL_PP(tmp_oid);
+			if (st & SNMP_CMD_SET) {
+				if (Z_TYPE_PP(type) == IS_STRING) {
+					pptr = Z_STRVAL_PP(type);
+					objid_set->vars[objid_set->count].type = *pptr;
+				} else if (Z_TYPE_PP(type) == IS_ARRAY) {
+					if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(type), (void **) &tmp_type, &pos_type)) {
+						convert_to_string_ex(tmp_type);
+						if (Z_STRLEN_PP(tmp_type) != 1) {
+							php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': bogus type '%s', should be single char, got %u", Z_STRVAL_PP(tmp_oid), Z_STRVAL_PP(tmp_type), Z_STRLEN_PP(tmp_type));
+							return FALSE;
+						}
+						pptr = Z_STRVAL_PP(tmp_type);
+						objid_set->vars[objid_set->count].type = *pptr;
+						zend_hash_move_forward_ex(Z_ARRVAL_PP(type), &pos_type);
+					} else {
+						php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no type set", Z_STRVAL_PP(tmp_oid));
+						return FALSE;
+					}
+				}
+
+				if (Z_TYPE_PP(value) == IS_STRING) {
+					objid_set->vars[objid_set->count].value = Z_STRVAL_PP(value);
+				} else if (Z_TYPE_PP(value) == IS_ARRAY) {
+					if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(value), (void **) &tmp_value, &pos_value)) {
+						convert_to_string_ex(tmp_value);
+						objid_set->vars[objid_set->count].value = Z_STRVAL_PP(tmp_value);
+						zend_hash_move_forward_ex(Z_ARRVAL_PP(value), &pos_value);
+					} else {
+						php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no value set", Z_STRVAL_PP(tmp_oid));
+						return FALSE;
+					}
+				}
+			}
+
+			if (objid_set->count++ >= SNMP_MAXOIDS_IN_PDU) {
+				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not process more than %u OIDs in singe GET/GETNEXT/SET query", SNMP_MAXOIDS_IN_PDU);
+				return FALSE;
+			}
+		}
+	}
+
+	return (objid_set->count > 0);
+}
+/* }}} */
+
 /* {{{ php_snmp
 *
 * Generic community based SNMP handler for version 1 and 2.
 * This function makes use of the internal SNMP object fetcher.
 * The object fetcher is shared with SNMPv3.
 *
-* st=SNMP_CMD_GET   get - query an agent with SNMP-GET.
-* st=SNMP_CMD_GETNEXT   getnext - query an agent with SNMP-GETNEXT.
-* st=SNMP_CMD_WALK   walk - walk the mib and return a single dimensional array 
-*          containing the values.
-* st=SNMP_CMD_REALWALK   realwalk() and walkoid() - walk the mib and return an 
-*          array of oid,value pairs.
-* st=5-8 ** Reserved **
-* st=SNMP_CMD_SET  set() - query an agent and set a single value
-*
 */
 static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) 
 {
-	zval **a1, **a2, **a3, **a4, **a5, **a6, **a7;
+	char *a1, *a2;
+	int a1_len, a2_len;
+	zval **oid, **value, **type;
 	struct snmp_session session;
-	long timeout=SNMP_DEFAULT_TIMEOUT;
-	long retries=SNMP_DEFAULT_RETRIES;
-	int myargc = ZEND_NUM_ARGS();
-	char type = (char) 0;
-	char *value = (char *) 0;
+	long timeout = SNMP_DEFAULT_TIMEOUT;
+	long retries = SNMP_DEFAULT_RETRIES;
 	char hostname[MAX_NAME_LEN];
 	int remote_port = 161;
 	char *pptr;
+	int argc = ZEND_NUM_ARGS();
+	struct objid_set objid_set;
 
-	if (myargc < 3 || myargc > 7 ||
-		zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7) == FAILURE) {
-		WRONG_PARAM_COUNT;
-	}
-
-	convert_to_string_ex(a1);
-	convert_to_string_ex(a2);
-	convert_to_string_ex(a3);
-	
-	if (st == SNMP_CMD_SET) {
-		if (myargc < 5) {
-			WRONG_PARAM_COUNT;
-		}
-
-		convert_to_string_ex(a4);
-		convert_to_string_ex(a5);
-
-		if(myargc > 5) {
-			convert_to_long_ex(a6);
-			timeout = Z_LVAL_PP(a6);
-		}
-
-		if(myargc > 6) {
-			convert_to_long_ex(a7);
-			retries = Z_LVAL_PP(a7);
+	if (st & SNMP_CMD_SET) {
+		if (zend_parse_parameters(argc TSRMLS_CC, "ssZZZ|ll", &a1, &a1_len, &a2, &a2_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
+			RETURN_FALSE;
 		}
-
-		type = Z_STRVAL_PP(a4)[0];
-		value = Z_STRVAL_PP(a5);
 	} else {
-		if(myargc > 3) {
-			convert_to_long_ex(a4);
-			timeout = Z_LVAL_PP(a4);
+		/* SNMP_CMD_GET
+		 * SNMP_CMD_GETNEXT
+		 * SNMP_CMD_WALK
+		 */
+		if (zend_parse_parameters(argc TSRMLS_CC, "ssZ|ll", &a1, &a1_len, &a2, &a2_len, &oid, &timeout, &retries) == FAILURE) {
+			RETURN_FALSE;
 		}
+	}
 
-		if(myargc > 4) {
-			convert_to_long_ex(a5);
-			retries = Z_LVAL_PP(a5);
-		}
+	if (!php_snmp_parse_oid(st, &objid_set, oid, type, value)) {
+		RETURN_FALSE;
 	}
 
 	snmp_sess_init(&session);
-	strlcpy(hostname, Z_STRVAL_PP(a1), sizeof(hostname));
+	strlcpy(hostname, a1, sizeof(hostname));
 	if ((pptr = strchr (hostname, ':'))) {
 		remote_port = strtol (pptr + 1, NULL, 0);
 	}
@@ -656,49 +1062,65 @@
 	* memory it did not allocate
 	*/
 #ifdef UCD_SNMP_HACK
-	session.community = (u_char *)strdup(Z_STRVAL_PP(a2)); /* memory freed by SNMP library, strdup NOT estrdup */
+	session.community = (u_char *)strdup(a2); /* memory freed by SNMP library, strdup NOT estrdup */
 #else
-	session.community = (u_char *)Z_STRVAL_PP(a2);
+	session.community = (u_char *)a2;
 #endif
-	session.community_len = Z_STRLEN_PP(a2);
+	session.community_len = a2_len;
 	session.retries = retries;
 	session.timeout = timeout;
 	
 	session.authenticator = NULL;
 
-	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a3), type, value);
+	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, &objid_set);
 }
 /* }}} */
 
-/* {{{ proto string snmpget(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmpget(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Fetch a SNMP object */
 PHP_FUNCTION(snmpget)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_1);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, SNMP_VERSION_1);
+}
+/* }}} */
+
+/* {{{ proto mixed snmprealget(string host, string community, mixed object_id [, int timeout [, int retries]]) 
+   Fetch a SNMP object */
+PHP_FUNCTION(snmprealget)
+{
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GET | SNMP_ASSOC_OUTPUT), SNMP_VERSION_1);
 }
 /* }}} */
 
-/* {{{ proto string snmpgetnext(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmpgetnext(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Fetch a SNMP object */
 PHP_FUNCTION(snmpgetnext)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_1);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, SNMP_VERSION_1);
+}
+/* }}} */
+
+/* {{{ proto mixed snmprealgetnext(string host, string community, mixed object_id [, int timeout [, int retries]]) 
+   Fetch a SNMP object */
+PHP_FUNCTION(snmprealgetnext)
+{
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GETNEXT | SNMP_ASSOC_OUTPUT), SNMP_VERSION_1);
 }
 /* }}} */
 
-/* {{{ proto array snmpwalk(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmpwalk(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Return all objects under the specified object id */
 PHP_FUNCTION(snmpwalk)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_1);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, SNMP_VERSION_1);
 }
 /* }}} */
 
-/* {{{ proto array snmprealwalk(string host, string community, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmprealwalk(string host, string community, mixed object_id [, int timeout [, int retries]])
    Return all objects including their respective object id withing the specified one */
 PHP_FUNCTION(snmprealwalk)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_1);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_ASSOC_OUTPUT), SNMP_VERSION_1);
 }
 /* }}} */
 
@@ -706,8 +1128,8 @@
    Return the current status of quick_print */
 PHP_FUNCTION(snmp_get_quick_print)
 {
-	if (ZEND_NUM_ARGS() != 0) {
-		WRONG_PARAM_COUNT;
+	if (zend_parse_parameters_none() == FAILURE) {
+		return;
 	}
 
 #ifdef HAVE_NET_SNMP
@@ -718,15 +1140,14 @@
 }
 /* }}} */
 
-/* {{{ proto void snmp_set_quick_print(int quick_print)
+/* {{{ proto bool snmp_set_quick_print(int quick_print)
    Return all objects including their respective object id withing the specified one */
 PHP_FUNCTION(snmp_set_quick_print)
 {
-	int argc = ZEND_NUM_ARGS();
 	long a1;
 
-	if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
-		return;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &a1) == FAILURE) {
+		RETURN_FALSE;
 	}
 
 #ifdef HAVE_NET_SNMP
@@ -734,34 +1155,34 @@
 #else
 	snmp_set_quick_print((int)a1);
 #endif
+	RETURN_TRUE;
 }
 /* }}} */
 
 #ifdef HAVE_NET_SNMP
-/* {{{ proto void snmp_set_enum_print(int enum_print)
+/* {{{ proto bool snmp_set_enum_print(int enum_print)
    Return all values that are enums with their enum value instead of the raw integer */
 PHP_FUNCTION(snmp_set_enum_print)
 {
-	int argc = ZEND_NUM_ARGS();
 	long a1;
 
-	if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
-		return;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &a1) == FAILURE) {
+		RETURN_FALSE;
 	}
 
 	netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int) a1);
+	RETURN_TRUE;
 } 
 /* }}} */
 
-/* {{{ proto void snmp_set_oid_output_format(int oid_format)
+/* {{{ proto bool snmp_set_oid_output_format(int oid_format)
    Set the OID output format. */
 PHP_FUNCTION(snmp_set_oid_output_format)
 {
-	int argc = ZEND_NUM_ARGS();
 	long a1;
 
-	if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
-		return;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &a1) == FAILURE) {
+		RETURN_FALSE;
 	}
 
 	switch ((int) a1) {
@@ -777,28 +1198,16 @@
 	}
 
 	netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
+	RETURN_TRUE;
 } 
 /* }}} */
 #endif
 
-/* {{{ proto int snmpset(string host, string community, string object_id, string type, mixed value [, int timeout [, int retries]]) 
+/* {{{ proto bool snmpset(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) 
    Set the value of a SNMP object */
 PHP_FUNCTION(snmpset)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_1);
-}
-/* }}} */
-
-/* {{{ int netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
-   Set the security name in the snmpv3 session */
-static int netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
-{
-	if ((s) && (name)) {
-		s->securityName = strdup(name);
-		s->securityNameLen = strlen(s->securityName);
-		return (0);
-	}
-	return (-1);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, SNMP_VERSION_1);
 }
 /* }}} */
 
@@ -806,19 +1215,16 @@
    Set the security level in the snmpv3 session */
 static int netsnmp_session_set_sec_level(struct snmp_session *s, char *level TSRMLS_DC)
 {
-	if ((s) && (level)) {
-		if (!strcasecmp(level, "noAuthNoPriv") || !strcasecmp(level, "nanp")) {
-			s->securityLevel = SNMP_SEC_LEVEL_NOAUTH;
-			return (0);
-		} else if (!strcasecmp(level, "authNoPriv") || !strcasecmp(level, "anp")) {
-			s->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
-			return (0);
-		} else if (!strcasecmp(level, "authPriv") || !strcasecmp(level, "ap")) {
-			s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
-			return (0);
-		}
+	if (!strcasecmp(level, "noAuthNoPriv") || !strcasecmp(level, "nanp")) {
+		s->securityLevel = SNMP_SEC_LEVEL_NOAUTH;
+	} else if (!strcasecmp(level, "authNoPriv") || !strcasecmp(level, "anp")) {
+		s->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
+	} else if (!strcasecmp(level, "authPriv") || !strcasecmp(level, "ap")) {
+		s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
+	} else {
+		return (-1);
 	}
-	return (-1);
+	return (0);
 }
 /* }}} */
 
@@ -826,18 +1232,17 @@
    Set the authentication protocol in the snmpv3 session */
 static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot TSRMLS_DC)
 {
-	if ((s) && (prot)) {
-		if (!strcasecmp(prot, "MD5")) {
-			s->securityAuthProto = usmHMACMD5AuthProtocol;
-			s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
-			return (0);
-		} else if (!strcasecmp(prot, "SHA")) {
-			s->securityAuthProto = usmHMACSHA1AuthProtocol;
-			s->securityAuthProtoLen = OIDSIZE(usmHMACSHA1AuthProtocol);
-			return (0);
-		}
+	if (!strcasecmp(prot, "MD5")) {
+		s->securityAuthProto = usmHMACMD5AuthProtocol;
+		s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
+	} else if (!strcasecmp(prot, "SHA")) {
+		s->securityAuthProto = usmHMACSHA1AuthProtocol;
+		s->securityAuthProtoLen = OIDSIZE(usmHMACSHA1AuthProtocol);
+	} else {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown authentication protocol '%s'", prot TSRMLS_DC);
+		return (-1);
 	}
-	return (-1);
+	return (0);
 }
 /* }}} */
 
@@ -845,13 +1250,11 @@
    Set the security protocol in the snmpv3 session */
 static int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot TSRMLS_DC)
 {
-	if ((s) && (prot)) {
-		if (!strcasecmp(prot, "DES")) {
-			s->securityPrivProto = usmDESPrivProtocol;
-			s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
-			return (0);
+	if (!strcasecmp(prot, "DES")) {
+		s->securityPrivProto = usmDESPrivProtocol;
+		s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
 #ifdef HAVE_AES
-		} else if (!strcasecmp(prot, "AES128")
+	} else if (!strcasecmp(prot, "AES128")
 #ifdef SNMP_VALIDATE_ERR
 /* 
 * In Net-SNMP before 5.2, the following symbols exist:
@@ -867,28 +1270,26 @@
 * array, so we cannot use the OIDSIZE macro because it uses sizeof().
 *
 */
-			|| !strcasecmp(prot, "AES")) {
-			s->securityPrivProto = usmAES128PrivProtocol;
-			s->securityPrivProtoLen = USM_PRIV_PROTO_AES128_LEN;
-			return (0);
+		|| !strcasecmp(prot, "AES")) {
+		s->securityPrivProto = usmAES128PrivProtocol;
+		s->securityPrivProtoLen = USM_PRIV_PROTO_AES128_LEN;
 #else			
-		) {
-			s->securityPrivProto = usmAES128PrivProtocol;
-			s->securityPrivProtoLen = OIDSIZE(usmAES128PrivProtocol);
-			return (0);
-		} else if (!strcasecmp(prot, "AES192")) {
-			s->securityPrivProto = usmAES192PrivProtocol;
-			s->securityPrivProtoLen = OIDSIZE(usmAES192PrivProtocol);
-			return (0);
-		} else if (!strcasecmp(prot, "AES256")) {
-			s->securityPrivProto = usmAES256PrivProtocol;
-			s->securityPrivProtoLen = OIDSIZE(usmAES256PrivProtocol);
-			return (0);
+	) {
+		s->securityPrivProto = usmAES128PrivProtocol;
+		s->securityPrivProtoLen = OIDSIZE(usmAES128PrivProtocol);
+	} else if (!strcasecmp(prot, "AES192")) {
+		s->securityPrivProto = usmAES192PrivProtocol;
+		s->securityPrivProtoLen = OIDSIZE(usmAES192PrivProtocol);
+	} else if (!strcasecmp(prot, "AES256")) {
+		s->securityPrivProto = usmAES256PrivProtocol;
+		s->securityPrivProtoLen = OIDSIZE(usmAES256PrivProtocol);
 #endif
 #endif
-		}
+	} else {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown security protocol '%s'", prot);
+		return (-1);
 	}
-	return (-1);
+	return (0);
 }
 /* }}} */
 
@@ -896,31 +1297,15 @@
    Make key from pass phrase in the snmpv3 session */
 static int netsnmp_session_gen_auth_key(struct snmp_session *s, char *pass TSRMLS_DC)
 {
-	/*
-	 * make master key from pass phrases 
-	 */
-	if ((s) && (pass) && strlen(pass)) {
-		s->securityAuthKeyLen = USM_AUTH_KU_LEN;
-		if (s->securityAuthProto == NULL) {
-			/* get .conf set default */
-			const oid *def = get_default_authtype(&(s->securityAuthProtoLen));
-			s->securityAuthProto = snmp_duplicate_objid(def, s->securityAuthProtoLen);
-		}
-		if (s->securityAuthProto == NULL) {
-			/* assume MD5 */
-			s->securityAuthProto =
-				snmp_duplicate_objid(usmHMACMD5AuthProtocol, OIDSIZE(usmHMACMD5AuthProtocol));
-			s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
-		}
-		if (generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
-				(u_char *) pass, strlen(pass),
-				s->securityAuthKey, &(s->securityAuthKeyLen)) != SNMPERR_SUCCESS) {
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for authentication pass phrase");
-			return (-2);
-		}
-		return (0);
+	int snmp_errno;
+	s->securityAuthKeyLen = USM_AUTH_KU_LEN;
+	if ((snmp_errno = generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
+			(u_char *) pass, strlen(pass),
+			s->securityAuthKey, &(s->securityAuthKeyLen)))) {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for authentication pass phrase '%s': %s", pass, snmp_api_errstring(snmp_errno));
+		return (-1);
 	}
-	return (-1);
+	return (0);
 }
 /* }}} */
 
@@ -928,101 +1313,108 @@
    Make key from pass phrase in the snmpv3 session */
 static int netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass TSRMLS_DC)
 {
-	if ((s) && (pass) && strlen(pass)) {
-		s->securityPrivKeyLen = USM_PRIV_KU_LEN;
-		if (s->securityPrivProto == NULL) {
-			/* get .conf set default */
-			const oid *def = get_default_privtype(&(s->securityPrivProtoLen));
-			s->securityPrivProto = snmp_duplicate_objid(def, s->securityPrivProtoLen);
-		}
-		if (s->securityPrivProto == NULL) {
-			/* assume DES */
-			s->securityPrivProto = snmp_duplicate_objid(usmDESPrivProtocol,
-				OIDSIZE(usmDESPrivProtocol));
-			s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
-		}
-		if (generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
-				pass, strlen(pass),
-				s->securityPrivKey, &(s->securityPrivKeyLen)) != SNMPERR_SUCCESS) {
-			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for privacy pass phrase");
-			return (-2);
-		}
-		return (0);
+	int snmp_errno;
+
+	s->securityPrivKeyLen = USM_PRIV_KU_LEN;
+	if ((snmp_errno = generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
+			pass, strlen(pass),
+			s->securityPrivKey, &(s->securityPrivKeyLen)))) {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for privacy pass phrase '%s': %s", pass, snmp_api_errstring(snmp_errno));
+		return (-2);
 	}
-	return (-1);
+	return (0);
 }
 /* }}} */
 
-/* {{{ proto string snmp2_get(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmp2_get(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Fetch a SNMP object */
 PHP_FUNCTION(snmp2_get)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GET, SNMP_VERSION_2c);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, SNMP_VERSION_2c);
 }
 /* }}} */
 
-/* {{{ proto string snmp2_getnext(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmp2_real_get(string host, string community, mixed object_id [, int timeout [, int retries]]) 
+   Fetch a SNMP object */
+PHP_FUNCTION(snmp2_real_get)
+{
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GET | SNMP_ASSOC_OUTPUT), SNMP_VERSION_2c);
+}
+/* }}} */
+
+/* {{{ proto mixed snmp2_getnext(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Fetch a SNMP object */
 PHP_FUNCTION(snmp2_getnext)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_GETNEXT, SNMP_VERSION_2c);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, SNMP_VERSION_2c);
+}
+/* }}} */
+
+/* {{{ proto mixed snmp2_real_getnext(string host, string community, mixed object_id [, int timeout [, int retries]]) 
+   Fetch a SNMP object */
+PHP_FUNCTION(snmp2_real_getnext)
+{
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GETNEXT | SNMP_ASSOC_OUTPUT), SNMP_VERSION_2c);
 }
 /* }}} */
 
-/* {{{ proto array snmp2_walk(string host, string community, string object_id [, int timeout [, int retries]]) 
+/* {{{ proto mixed snmp2_walk(string host, string community, mixed object_id [, int timeout [, int retries]]) 
    Return all objects under the specified object id */
 PHP_FUNCTION(snmp2_walk)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_WALK, SNMP_VERSION_2c);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, SNMP_VERSION_2c);
 }
 /* }}} */
 
-/* {{{ proto array snmp2_real_walk(string host, string community, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmp2_real_walk(string host, string community, mixed object_id [, int timeout [, int retries]])
    Return all objects including their respective object id withing the specified one */
 PHP_FUNCTION(snmp2_real_walk)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_REALWALK, SNMP_VERSION_2c);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_ASSOC_OUTPUT), SNMP_VERSION_2c);
 }
 /* }}} */
 
-/* {{{ proto int snmp2_set(string host, string community, string object_id, string type, mixed value [, int timeout [, int retries]]) 
+/* {{{ proto bool snmp2_set(string host, string community, mixed object_id, mixed type, mixed value [, int timeout [, int retries]]) 
    Set the value of a SNMP object */
 PHP_FUNCTION(snmp2_set)
 {
-	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,SNMP_CMD_SET, SNMP_VERSION_2c);
+	php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, SNMP_VERSION_2c);
 }
 /* }}} */
 
 /* {{{ proto void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st)
 *
-* Generic SNMPv3 object fetcher
-* From here is passed on the the common internal object fetcher.
-*
-* st=SNMP_CMD_GET   snmp3_get() - query an agent and return a single value.
-* st=SNMP_CMD_GETNEXT   snmp3_getnext() - query an agent and return the next single value.
-* st=SNMP_CMD_WALK   snmp3_walk() - walk the mib and return a single dimensional array 
-*                       containing the values.
-* st=SNMP_CMD_REALWALK   snmp3_real_walk() - walk the mib and return an 
-*                            array of oid,value pairs.
-* st=SNMP_CMD_SET  snmp3_set() - query an agent and set a single value
+* SNMPv3 object fetcher/setter
 *
 */
 static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st)
 {
-	zval **a1, **a2, **a3, **a4, **a5, **a6, **a7, **a8, **a9, **a10, **a11, **a12;
+	char *a1, *a2, *a3, *a4, *a5, *a6, *a7;
+	int a1_len, a2_len, a3_len, a4_len, a5_len, a6_len, a7_len;
+	zval **oid, **value, **type;
 	struct snmp_session session;
-	long timeout=SNMP_DEFAULT_TIMEOUT;
-	long retries=SNMP_DEFAULT_RETRIES;
-	int myargc = ZEND_NUM_ARGS();
-	char type = (char) 0;
-	char *value = (char *) 0;
+	long timeout = SNMP_DEFAULT_TIMEOUT;
+	long retries = SNMP_DEFAULT_RETRIES;
 	char hostname[MAX_NAME_LEN];
 	int remote_port = 161;
 	char *pptr;
-
-	if (myargc < 8 || myargc > 12 ||
-		zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11, &a12) == FAILURE) {
-		WRONG_PARAM_COUNT;
+	int argc = ZEND_NUM_ARGS();
+	struct objid_set objid_set;
+	
+	if (st & SNMP_CMD_SET) {	
+		if (zend_parse_parameters(argc TSRMLS_CC, "sssssssZZZ|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
+			&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
+			RETURN_FALSE;
+		}
+	} else {
+		/* SNMP_CMD_GET
+		 * SNMP_CMD_GETNEXT
+		 * SNMP_CMD_WALK
+		 */
+		if (zend_parse_parameters(argc TSRMLS_CC, "sssssssZ|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
+			&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &timeout, &retries) == FAILURE) {
+			RETURN_FALSE;
+		}
 	}
 
 	snmp_sess_init(&session);
@@ -1030,93 +1422,64 @@
 	session.version = SNMP_VERSION_3;
 
 	/* Reading the hostname and its optional non-default port number */
-	convert_to_string_ex(a1);
-	strlcpy(hostname, Z_STRVAL_PP(a1), sizeof(hostname));
-	if ((pptr = strchr (hostname, ':'))) {
-		remote_port = strtol (pptr + 1, NULL, 0);
+	strlcpy(hostname, a1, sizeof(hostname));
+	if ((pptr = strchr(hostname, ':'))) {
+		remote_port = strtol(pptr + 1, NULL, 0);
 	}
 	session.peername = hostname;
 	session.remote_port = remote_port;
 
 	/* Setting the security name. */
-	convert_to_string_ex(a2);
-	if (netsnmp_session_set_sec_name(&session, Z_STRVAL_PP(a2))) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could net set security name: %s", Z_STRVAL_PP(a2));
-		RETURN_FALSE;
-	}
+	session.securityName = strdup(a2);
+	session.securityNameLen = strlen(session.securityName);
 
 	/* Setting the security level. */
-	convert_to_string_ex(a3);
-	if (netsnmp_session_set_sec_level(&session, Z_STRVAL_PP(a3) TSRMLS_CC)) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security level: %s", Z_STRVAL_PP(a3));
+	if (netsnmp_session_set_sec_level(&session, a3 TSRMLS_CC)) {
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security level '%s'", a3);
 		RETURN_FALSE;
 	}
 
-	/* Setting the authentication protocol. */
-	convert_to_string_ex(a4);
-	if (netsnmp_session_set_auth_protocol(&session, Z_STRVAL_PP(a4) TSRMLS_CC)) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid authentication protocol: %s", Z_STRVAL_PP(a4));
-		RETURN_FALSE;
-	}
+	if (session.securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
 
-	/* Setting the authentication passphrase. */
-	convert_to_string_ex(a5);
-	if (netsnmp_session_gen_auth_key(&session, Z_STRVAL_PP(a5) TSRMLS_CC)) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not generate key for authentication pass phrase: %s", Z_STRVAL_PP(a4));
-		RETURN_FALSE;
-	}
+		/* Setting the authentication protocol. */
+		if (netsnmp_session_set_auth_protocol(&session, a4 TSRMLS_CC)) {
+			/* Warning message sent already, just bail out */
+			RETURN_FALSE;
+		}
 
-	/* Setting the security protocol. */
-	convert_to_string_ex(a6);
-	if (netsnmp_session_set_sec_protocol(&session, Z_STRVAL_PP(a6) TSRMLS_CC) &&
-			(0 != strlen(Z_STRVAL_PP(a6)))) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security protocol: %s", Z_STRVAL_PP(a6));
-		RETURN_FALSE;
-	}
+		/* Setting the authentication passphrase. */
+		if (netsnmp_session_gen_auth_key(&session, a5 TSRMLS_CC)) {
+			/* Warning message sent already, just bail out */
+			RETURN_FALSE;
+		}
 
-	/* Setting the security protocol passphrase. */
-	convert_to_string_ex(a7);
-	if (netsnmp_session_gen_sec_key(&session, Z_STRVAL_PP(a7) TSRMLS_CC) &&
-							(0 != strlen(Z_STRVAL_PP(a7)))) {
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not generate key for security pass phrase: %s", Z_STRVAL_PP(a7));
-		RETURN_FALSE;
-	}
+		if (session.securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
+			/* Setting the security protocol. */
+			if (netsnmp_session_set_sec_protocol(&session, a6 TSRMLS_CC)) {
+				/* Warning message sent already, just bail out */
+				RETURN_FALSE;
+			}
 
-	if (st == SNMP_CMD_SET) {
-		if (myargc < 10) {
-			WRONG_PARAM_COUNT;
-		}
-		if (myargc > 10) {
-			convert_to_long_ex(a11);
-			timeout = Z_LVAL_PP(a11);
-		}
-		if (myargc > 11) {
-			convert_to_long_ex(a12);
-			retries = Z_LVAL_PP(a12);
-		}
-		convert_to_string_ex(a9);
-		convert_to_string_ex(a10);
-		type = Z_STRVAL_PP(a9)[0];
-		value = Z_STRVAL_PP(a10);
-	} else {
-		if (myargc > 8) {
-			convert_to_long_ex(a9);
-			timeout = Z_LVAL_PP(a9);
-		}
-		if (myargc > 9) {
-			convert_to_long_ex(a10);
-			retries = Z_LVAL_PP(a10);
+			/* Setting the security protocol passphrase. */
+			if (netsnmp_session_gen_sec_key(&session, a7 TSRMLS_CC)) {
+				/* Warning message sent already, just bail out */
+				RETURN_FALSE;
+			}
 		}
 	}
-
+	
 	session.retries = retries;
 	session.timeout = timeout;
 
-	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a8), type, value);
+	if (!php_snmp_parse_oid(st, &objid_set, oid, type, value)) {
+		RETURN_FALSE;
+	}
+
+	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, &objid_set);
 }
 /* }}} */
 
-/* {{{ proto int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmp3_get(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
    Fetch the value of a SNMP object */
 PHP_FUNCTION(snmp3_get)
 {
@@ -1124,7 +1487,15 @@
 }
 /* }}} */
 
-/* {{{ proto int snmp3_getnext(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmp3_real_get(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmp3_real_get)
+{
+	php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GET | SNMP_ASSOC_OUTPUT));
+}
+/* }}} */
+
+/* {{{ proto mixed snmp3_getnext(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
    Fetch the value of a SNMP object */
 PHP_FUNCTION(snmp3_getnext)
 {
@@ -1132,7 +1503,15 @@
 }
 /* }}} */
 
-/* {{{ proto int snmp3_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmp3_real_getnext(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmp3_real_getnext)
+{
+	php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_GETNEXT | SNMP_ASSOC_OUTPUT));
+}
+/* }}} */
+
+/* {{{ proto mixed snmp3_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
    Fetch the value of a SNMP object */
 PHP_FUNCTION(snmp3_walk)
 {
@@ -1140,15 +1519,15 @@
 }
 /* }}} */
 
-/* {{{ proto int snmp3_real_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
+/* {{{ proto mixed snmp3_real_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id [, int timeout [, int retries]])
    Fetch the value of a SNMP object */
 PHP_FUNCTION(snmp3_real_walk)
 {
-	php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_REALWALK);
+	php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_ASSOC_OUTPUT));
 }
 /* }}} */
 
-/* {{{ proto int snmp3_set(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id, string type, mixed value [, int timeout [, int retries]])
+/* {{{ proto bool snmp3_set(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, mixed object_id, mixed type, mixed value [, int timeout [, int retries]])
    Fetch the value of a SNMP object */
 PHP_FUNCTION(snmp3_set)
 {
@@ -1156,24 +1535,20 @@
 }
 /* }}} */
 
-/* {{{ proto int snmp_set_valueretrieval(int method)
+/* {{{ proto bool snmp_set_valueretrieval(int method)
    Specify the method how the SNMP values will be returned */
 PHP_FUNCTION(snmp_set_valueretrieval)
 {
-	zval **method;
+	long method;
 
-	if (ZEND_NUM_ARGS() != 1 ||
-		zend_get_parameters_ex(ZEND_NUM_ARGS(), &method) == FAILURE) {
-		WRONG_PARAM_COUNT;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method) == FAILURE) {
+		RETURN_FALSE;
 	}
 
-	convert_to_long_ex(method);
-
-	if ((Z_LVAL_PP(method) == SNMP_VALUE_LIBRARY) ||
-	    (Z_LVAL_PP(method) == SNMP_VALUE_PLAIN) ||
-	    (Z_LVAL_PP(method) == SNMP_VALUE_OBJECT)) {
-		SNMP_G(valueretrieval) = Z_LVAL_PP(method);
+	if ((method == SNMP_VALUE_LIBRARY) || (method == SNMP_VALUE_PLAIN) || (method == SNMP_VALUE_OBJECT)) {
+		SNMP_G(valueretrieval) = method;
 	}
+	RETURN_TRUE;
 }
 /* }}} */
 
@@ -1185,25 +1560,20 @@
 }
 /* }}} */
 
-/* {{{ proto int snmp_read_mib(string filename)
+/* {{{ proto bool snmp_read_mib(string filename)
    Reads and parses a MIB file into the active MIB tree. */
 PHP_FUNCTION(snmp_read_mib)
 {
-	zval **filename;
+	char *filename;
+	int filename_len;
 
-	if (ZEND_NUM_ARGS() != 1 ||
-		zend_get_parameters_ex(ZEND_NUM_ARGS(), &filename) == FAILURE) {
-		WRONG_PARAM_COUNT;
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
+		RETURN_FALSE;
 	}
 
-	convert_to_string_ex(filename);
-
-	/* Prevent read_mib() from printing any errors. */
-	snmp_disable_stderrlog();
-	
-	if (!read_mib(Z_STRVAL_PP(filename))) {
+	if (!read_mib(filename)) {
 		char *error = strerror(errno);
-		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading MIB file '%s': %s", Z_STRVAL_PP(filename), error);
+		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error while reading MIB file '%s': %s", filename, error);
 		RETURN_FALSE;
 	}
 	RETURN_TRUE;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC