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

2011-08-27 Thread Boris Lytochkin
lytboris Sat, 27 Aug 2011 08:16:32 +

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

Log:
export ERRNO_OID_PARSING_ERROR constant:
raise it evry time OID parsing has failed

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

Modified: php/php-src/trunk/ext/snmp/php_snmp.h
===
--- php/php-src/trunk/ext/snmp/php_snmp.h   2011-08-27 07:33:27 UTC (rev 
315607)
+++ php/php-src/trunk/ext/snmp/php_snmp.h   2011-08-27 08:16:32 UTC (rev 
315608)
@@ -94,7 +94,7 @@
int oid_output_format;
int snmp_errno;
int oid_increasing_check;
-   char snmp_errstr[128];
+   char snmp_errstr[256];
 } php_snmp_object;



Modified: php/php-src/trunk/ext/snmp/snmp.c
===
--- php/php-src/trunk/ext/snmp/snmp.c   2011-08-27 07:33:27 UTC (rev 315607)
+++ php/php-src/trunk/ext/snmp/snmp.c   2011-08-27 08:16:32 UTC (rev 315608)
@@ -117,6 +117,7 @@
 #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

 ZEND_DECLARE_MODULE_GLOBALS(snmp)
 static PHP_GINIT_FUNCTION(snmp);
@@ -705,7 +706,7 @@

if (st & SNMP_CMD_WALK) {
if (objid_query->count > 1) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, "Multi OID 
walks are not supported!");
+   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;
@@ -713,7 +714,7 @@
if (snmp_parse_oid(objid_query->vars[0].oid, root, 
&rootlen)) {
gotroot = 1;
} else {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Invalid object identifier: %s", objid_query->vars[0].oid);
+   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;
}
@@ -769,7 +770,7 @@
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);
+   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;
@@ -778,7 +779,7 @@
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, "Could not add variable: OID='%s' type='%c' value='%s': 
%s", buf, objid_query->vars[objid_query->offset].type, 
objid_query->vars[objid_query->offset].value, snmp_api_errstring(snmp_errno));
+   php_snmp_error(getThis(), NULL 
TSRMLS_CC, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Could not add variable: OID='%s' 
type='%c' value='%s': %s", buf, objid_query->vars[objid_query->offset].type, 
objid_query->vars[objid_query->offset].value, snmp_api_errstring(snmp_errno));
snmp_free_pdu(pdu);
snmp_close(ss);
RETVAL_FALSE;
@@ -2437,6 +2438,7 @@
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_TIMEOUT", 
(long)PHP_SNMP_ERRNO_TIMEOUT);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_ERROR_IN_REPLY",  
(long)PHP_SNM

Re: [PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-errno-errstr.phpt tests/snmp-object-error.phpt tests/snmp-object-properties.phpt tests/snmp-object-set_security_erro

2011-03-03 Thread Johannes Schlüter
On Thu, 2011-03-03 at 12:03 +0300, Lytochkin Boris wrote:
> 
> As for UPGRADING:
> SendingUPGRADING
> Transmitting file data .svn: Commit failed (details follow):
> svn: Commit blocked by pre-commit hook (exit code 1) with output:
> ***
> Access denied: Insufficient karma for lytboris to
> php/php-src/trunk/UPGRADING.
> Contact gr...@php.net for access.
> 
> Can anyone fix this? :)

Should be fixed.

johannes



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



Re: [PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-errno-errstr.phpt tests/snmp-object-error.phpt tests/snmp-object-properties.phpt tests/snmp-object-set_security_erro

2011-03-03 Thread Lytochkin Boris
Hi.

On Thu, Mar 3, 2011 at 1:34 AM, Christopher Jones
 wrote:
> Can you add these to NEWS and make sure UPGRADING has all the
> contributions you've made?

NEWS has all information needed (get_(errno|error) methods are parts
of SNMP OO API that is under development now and thus "Added OO API.
FR #53594" should to be ok).

As for UPGRADING:
SendingUPGRADING
Transmitting file data .svn: Commit failed (details follow):
svn: Commit blocked by pre-commit hook (exit code 1) with output:
***
Access denied: Insufficient karma for lytboris to php/php-src/trunk/UPGRADING.
Contact gr...@php.net for access.

Can anyone fix this? :)

-- 
Boris Lytochkin

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



Re: [PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-errno-errstr.phpt tests/snmp-object-error.phpt tests/snmp-object-properties.phpt tests/snmp-object-set_security_erro

2011-03-02 Thread Christopher Jones




On 02/26/2011 12:27 AM, Boris Lytochkin wrote:

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

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



Can you add these to NEWS and make sure UPGRADING has all the
contributions you've made?

Chris

--
Email: christopher.jo...@oracle.com
Tel:  +1 650 506 8630
Blog:  http://blogs.oracle.com/opal/

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



[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-errno-errstr.phpt tests/snmp-object-error.phpt tests/snmp-object-properties.phpt tests/snmp-object-set_security_error.ph

2011-02-26 Thread Boris Lytochkin
lytboris Sat, 26 Feb 2011 08:27:26 +

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(bu