[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c
lytboris Fri, 02 Sep 2011 08:07:58 + Revision: http://svn.php.net/viewvc?view=revisionrevision=316022 Log: remove php_snmp_get_ce() Changed paths: U php/php-src/trunk/ext/snmp/php_snmp.h U php/php-src/trunk/ext/snmp/snmp.c Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-09-02 07:18:24 UTC (rev 316021) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-09-02 08:07:58 UTC (rev 316022) @@ -127,7 +127,7 @@ #endif #define REGISTER_SNMP_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); + zend_declare_class_constant_long(php_snmp_ce, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC); #else Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-09-02 07:18:24 UTC (rev 316021) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-09-02 08:07:58 UTC (rev 316022) @@ -132,13 +132,8 @@ static zend_object_handlers php_snmp_object_handlers; /* Class entries */ -zend_class_entry *php_snmp_class_entry; +zend_class_entry *php_snmp_ce; -zend_class_entry *php_snmp_get_ce() -{ - return php_snmp_class_entry; -} - /* Class object properties */ static HashTable php_snmp_properties; @@ -2399,7 +2394,7 @@ INIT_CLASS_ENTRY(ce, SNMP, php_snmp_class_methods); ce.create_object = php_snmp_object_new; php_snmp_object_handlers.clone_obj = NULL; - php_snmp_class_entry = zend_register_internal_class(ce TSRMLS_CC); + php_snmp_ce = zend_register_internal_class(ce TSRMLS_CC); /* Register SNMP Class properties */ zend_hash_init(php_snmp_properties, 0, NULL, NULL, 1); -- 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-error.phpt tests/snmp-object-properties.phpt
lytboris Fri, 02 Sep 2011 10:04:19 + Revision: http://svn.php.net/viewvc?view=revisionrevision=316029 Log: added SNMPException class, enabling ability to throw exceptions when a known SNMP error has occured FR #55542 Bug: https://bugs.php.net/55542 (Assigned) SNMP class should use Exceptions instead of PHP Errors 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-error.phpt U php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-09-02 09:27:23 UTC (rev 316028) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-09-02 10:04:19 UTC (rev 316029) @@ -94,6 +94,7 @@ int oid_output_format; int snmp_errno; int oid_increasing_check; + int exceptions_enabled; 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-09-02 09:27:23 UTC (rev 316028) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-09-02 10:04:19 UTC (rev 316029) @@ -34,6 +34,10 @@ #include zend_exceptions.h +#if HAVE_SPL +#include ext/spl/spl_exceptions.h +#endif + #if HAVE_SNMP #include sys/types.h @@ -113,12 +117,21 @@ } #define PHP_SNMP_ERRNO_NOERROR 0 -#define PHP_SNMP_ERRNO_GENERIC 1 -#define PHP_SNMP_ERRNO_TIMEOUT 2 -#define PHP_SNMP_ERRNO_ERROR_IN_REPLY 3 -#define PHP_SNMP_ERRNO_OID_NOT_INCREASING 4 -#define PHP_SNMP_ERRNO_OID_PARSING_ERROR 5 -#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES 6 +#define PHP_SNMP_ERRNO_GENERIC (1 1) +#define PHP_SNMP_ERRNO_TIMEOUT (1 2) +#define PHP_SNMP_ERRNO_ERROR_IN_REPLY (1 3) +#define PHP_SNMP_ERRNO_OID_NOT_INCREASING (1 4) +#define PHP_SNMP_ERRNO_OID_PARSING_ERROR (1 5) +#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES (1 6) +#define PHP_SNMP_ERRNO_ANY ( \ + PHP_SNMP_ERRNO_GENERIC | \ + PHP_SNMP_ERRNO_TIMEOUT | \ + PHP_SNMP_ERRNO_ERROR_IN_REPLY | \ + PHP_SNMP_ERRNO_OID_NOT_INCREASING | \ + PHP_SNMP_ERRNO_OID_PARSING_ERROR | \ + PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES | \ + PHP_SNMP_ERRNO_NOERROR \ + ) ZEND_DECLARE_MODULE_GLOBALS(snmp) static PHP_GINIT_FUNCTION(snmp); @@ -133,6 +146,7 @@ /* Class entries */ zend_class_entry *php_snmp_ce; +zend_class_entry *php_snmp_exception_ce; /* Class object properties */ static HashTable php_snmp_properties; @@ -533,9 +547,13 @@ return; } - va_start(args, format); - php_verror(docref, , E_WARNING, format, args TSRMLS_CC); - va_end(args); + if (object (snmp_object-exceptions_enabled type)) { + zend_throw_exception_ex(php_snmp_exception_ce, type, snmp_object-snmp_errstr TSRMLS_CC); + } else { + va_start(args, format); + php_verror(docref, , E_WARNING, format, args TSRMLS_CC); + va_end(args); + } } /* }}} */ @@ -1829,6 +1847,7 @@ snmp_object-oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); snmp_object-quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); snmp_object-oid_increasing_check = TRUE; + snmp_object-exceptions_enabled = 0; } /* }}} */ @@ -2204,6 +2223,7 @@ PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(valueretrieval) PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(oid_output_format) +PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled) /* {{{ */ static int php_snmp_write_info(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) @@ -2330,6 +2350,27 @@ } /* }}} */ +/* {{{ */ +static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) +{ + zval ztmp; + int ret = SUCCESS; + if (Z_TYPE_P(newval) != IS_LONG) { + ztmp = *newval; + zval_copy_ctor(ztmp); + convert_to_long(ztmp); + newval = ztmp; + } + + snmp_object-exceptions_enabled = Z_LVAL_P(newval); + + if (newval == ztmp) { + zval_dtor(newval); + } + return ret; +} +/* }}} */ + /* {{{ php_snmp_class_methods[] */ static zend_function_entry php_snmp_class_methods[] = { PHP_ME(snmp, __construct, arginfo_snmp_create, ZEND_ACC_PUBLIC) @@ -2357,6 +2398,7 @@ PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_output_format), PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_increasing_check), + PHP_SNMP_PROPERTY_ENTRY_RECORD(exceptions_enabled), { NULL, 0, NULL, NULL} }; /* }}} */ @@ -2366,7 +2408,7 @@ PHP_MINIT_FUNCTION(snmp) { netsnmp_log_handler *logh; - zend_class_entry ce; + zend_class_entry ce, cex; le_snmp_session = zend_register_list_destructors_ex(php_snmp_session_destructor, NULL, PHP_SNMP_SESSION_RES_NAME, module_number); @@ -2424,19 +2466,28 @@ REGISTER_LONG_CONSTANT(SNMP_INTEGER, ASN_INTEGER, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(SNMP_COUNTER64, ASN_COUNTER64, CONST_CS | CONST_PERSISTENT); -
[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-errno-errstr.phpt
lytboris Sat, 27 Aug 2011 08:16:32 + Revision: http://svn.php.net/viewvc?view=revisionrevision=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_SNMP_ERRNO_ERROR_IN_REPLY);
[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-properties.phpt
lytboris Thu, 21 Jul 2011 12:47:07 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313532 Log: s/noOIDIncreasingCheck/oid_increasing_check/ 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-properties.phpt Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-07-21 12:27:00 UTC (rev 313531) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-07-21 12:47:07 UTC (rev 313532) @@ -93,7 +93,7 @@ int enum_print; int oid_output_format; int snmp_errno; - int noOIDIncreasingCheck; + int oid_increasing_check; char snmp_errstr[128]; } php_snmp_object; Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-07-21 12:27:00 UTC (rev 313531) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-07-21 12:47:07 UTC (rev 313532) @@ -376,7 +376,7 @@ long max_repetitions; int valueretrieval; int array_output; - int noOIDIncreasingCheck; + int oid_increasing_check; snmpobjarg *vars; }; @@ -879,7 +879,7 @@ /* OID increase check */ if (st SNMP_CMD_WALK) { - if (objid_query-noOIDIncreasingCheck == FALSE snmp_oid_compare(name, name_length, vars-name, vars-name_length) = 0) { + if (objid_query-oid_increasing_check == TRUE snmp_oid_compare(name, name_length, vars-name, vars-name_length) = 0) { snprint_objid(buf2, sizeof(buf2), vars-name, vars-name_length); php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_NOT_INCREASING, Error: OID not increasing: %s, buf2); keepwalking = 0; @@ -1332,7 +1332,7 @@ objid_query.max_repetitions = -1; objid_query.non_repeaters = 0; objid_query.valueretrieval = SNMP_G(valueretrieval); - objid_query.noOIDIncreasingCheck = FALSE; + objid_query.oid_increasing_check = TRUE; if (session_less_mode) { if (version == SNMP_VERSION_3) { @@ -1426,7 +1426,7 @@ objid_query.max_repetitions = snmp_object-max_oids; } } - objid_query.noOIDIncreasingCheck = snmp_object-noOIDIncreasingCheck; + objid_query.oid_increasing_check = snmp_object-oid_increasing_check; objid_query.valueretrieval = snmp_object-valueretrieval; glob_snmp_object.enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, snmp_object-enum_print); @@ -1757,6 +1757,7 @@ snmp_object-enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); snmp_object-oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); snmp_object-quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); + snmp_object-oid_increasing_check = TRUE; } /* }}} */ @@ -2118,7 +2119,7 @@ return SUCCESS; \ } -PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(noOIDIncreasingCheck) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(oid_increasing_check) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(quick_print) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print) @@ -,7 +2223,7 @@ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(quick_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print) -PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(noOIDIncreasingCheck) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check) /* {{{ */ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) @@ -2284,7 +2285,7 @@ PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_output_format), - PHP_SNMP_PROPERTY_ENTRY_RECORD(noOIDIncreasingCheck), + PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_increasing_check), { NULL, 0, NULL, NULL} }; /* }}} */ Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt === --- php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt 2011-07-21 12:27:00 UTC (rev 313531) +++ php/php-src/trunk/ext/snmp/tests/snmp-object-properties.phpt 2011-07-21 12:47:07 UTC (rev 313532) @@
[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-properties.phpt
lytboris Sun, 17 Jul 2011 19:45:05 + Revision: http://svn.php.net/viewvc?view=revisionrevision=313341 Log: new propery noOIDIncreasingCheck allowing to skip OID increasing check (userful for bogus SNMP agents) 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-properties.phpt Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-07-17 19:26:54 UTC (rev 313340) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-07-17 19:45:05 UTC (rev 313341) @@ -93,6 +93,7 @@ int enum_print; int oid_output_format; int snmp_errno; + int noOIDIncreasingCheck; char snmp_errstr[128]; } php_snmp_object; Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-07-17 19:26:54 UTC (rev 313340) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-07-17 19:45:05 UTC (rev 313341) @@ -376,6 +376,7 @@ long max_repetitions; int valueretrieval; int array_output; + int noOIDIncreasingCheck; snmpobjarg *vars; }; @@ -878,7 +879,7 @@ /* OID increase check */ if (st SNMP_CMD_WALK) { - if (snmp_oid_compare(name, name_length, vars-name, vars-name_length) = 0) { + if (objid_query-noOIDIncreasingCheck == FALSE snmp_oid_compare(name, name_length, vars-name, vars-name_length) = 0) { snprint_objid(buf2, sizeof(buf2), vars-name, vars-name_length); php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_OID_NOT_INCREASING, Error: OID not increasing: %s, buf2); keepwalking = 0; @@ -1331,6 +1332,7 @@ objid_query.max_repetitions = -1; objid_query.non_repeaters = 0; objid_query.valueretrieval = SNMP_G(valueretrieval); + objid_query.noOIDIncreasingCheck = FALSE; if (session_less_mode) { if (version == SNMP_VERSION_3) { @@ -1424,6 +1426,7 @@ objid_query.max_repetitions = snmp_object-max_oids; } } + objid_query.noOIDIncreasingCheck = snmp_object-noOIDIncreasingCheck; objid_query.valueretrieval = snmp_object-valueretrieval; glob_snmp_object.enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, snmp_object-enum_print); @@ -2107,41 +2110,28 @@ } /* }}} */ -/* {{{ */ -static int php_snmp_read_valueretrieval(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) -{ - MAKE_STD_ZVAL(*retval); - ZVAL_LONG(*retval, snmp_object-valueretrieval); - return SUCCESS; -} -/* }}} */ +#define PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(name) \ + static int php_snmp_read_##name(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) \ + { \ + MAKE_STD_ZVAL(*retval); \ + ZVAL_BOOL(*retval, snmp_object-name); \ + return SUCCESS; \ + } -/* {{{ */ -static int php_snmp_read_quick_print(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) -{ - MAKE_STD_ZVAL(*retval); - ZVAL_BOOL(*retval, snmp_object-quick_print); - return SUCCESS; -} -/* }}} */ +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(noOIDIncreasingCheck) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(quick_print) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print) -/* {{{ */ -static int php_snmp_read_enum_print(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) -{ - MAKE_STD_ZVAL(*retval); - ZVAL_BOOL(*retval, snmp_object-enum_print); - return SUCCESS; -} -/* }}} */ +#define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \ + static int php_snmp_read_##name(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) \ + { \ + MAKE_STD_ZVAL(*retval); \ + ZVAL_LONG(*retval, snmp_object-name); \ + return SUCCESS; \ + } -/* {{{ */ -static int php_snmp_read_oid_output_format(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) -{ - MAKE_STD_ZVAL(*retval); - ZVAL_LONG(*retval, snmp_object-oid_output_format); - return SUCCESS; -} -/* }}} */ +PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(valueretrieval) +PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(oid_output_format) /* {{{ */ static int php_snmp_write_info(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) @@ -2211,46
Re: [PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp-object-properties.phpt
On 07/17/2011 11:45 PM, Boris Lytochkin wrote: int enum_print; int oid_output_format; int snmp_errno; + int noOIDIncreasingCheck; char snmp_errstr[128]; @@ -159,6 +167,8 @@ bool(true) [oid_output_format]= int(3) + [noOIDIncreasingCheck]= + bool(true) [123]= string(11) param_value This sudden change from underline_separate_method to camelCaseMethod looks quite strange to me. Is there any reason to do that? -- Wbr, Antony Dovgal --- http://pinba.org - realtime profiling for PHP -- 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
lytboris Sun, 12 Jun 2011 10:07:43 + Revision: http://svn.php.net/viewvc?view=revisionrevision=312088 Log: fix method names in header Changed paths: U php/php-src/trunk/ext/snmp/php_snmp.h Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-06-12 09:08:17 UTC (rev 312087) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-06-12 10:07:43 UTC (rev 312088) @@ -82,8 +82,8 @@ PHP_METHOD(SNMP, getnext); PHP_METHOD(SNMP, walk); PHP_METHOD(SNMP, set); -PHP_METHOD(SNMP, get_errno); -PHP_METHOD(SNMP, get_error); +PHP_METHOD(SNMP, getErrno); +PHP_METHOD(SNMP, getError); typedef struct _php_snmp_object { zend_object zo; -- 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
lytboris Sun, 12 Jun 2011 10:13:30 + Revision: http://svn.php.net/viewvc?view=revisionrevision=312089 Log: no more method open Changed paths: U php/php-src/trunk/ext/snmp/php_snmp.h Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-06-12 10:07:43 UTC (rev 312088) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-06-12 10:13:30 UTC (rev 312089) @@ -75,7 +75,6 @@ PHP_FUNCTION(snmp_read_mib); -PHP_METHOD(SNMP, open); PHP_METHOD(SNMP, setSecurity); PHP_METHOD(SNMP, close); PHP_METHOD(SNMP, get); -- 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-error.phpt tests/snmp-object.phpt
lytboris Sun, 08 May 2011 13:58:37 + Revision: http://svn.php.net/viewvc?view=revisionrevision=310839 Log: * new option for SNMP::get: force keys of return array be as in request array * new option for SNMP::walk: use suffix of OID for keys in return array, not full OID 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-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-05-08 13:17:06 UTC (rev 310838) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-05-08 13:58:37 UTC (rev 310839) @@ -41,6 +41,9 @@ #include TSRM.h #endif +#include net-snmp/net-snmp-config.h +#include net-snmp/net-snmp-includes.h + PHP_MINIT_FUNCTION(snmp); PHP_MSHUTDOWN_FUNCTION(snmp); PHP_MINFO_FUNCTION(snmp); @@ -109,7 +112,8 @@ char *oid; char type; char *value; - + oid name[MAX_OID_LEN]; + size_t name_length; } snmpobjarg; ZEND_BEGIN_MODULE_GLOBALS(snmp) Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-05-08 13:17:06 UTC (rev 310838) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-05-08 13:58:37 UTC (rev 310839) @@ -421,6 +421,10 @@ #define SNMP_CMD_WALK (13) /* force values-only output */ #define SNMP_NUMERIC_KEYS (17) +/* use user-supplied OID names for keys in array output mode in GET method */ +#define SNMP_ORIGINAL_NAMES_AS_KEYS (18) +/* use OID suffix (`index') for keys in array output mode in WALK method */ +#define SNMP_USE_SUFFIX_AS_KEYS (19) #ifdef COMPILE_DL_SNMP ZEND_GET_MODULE(snmp) @@ -677,7 +681,7 @@ oid root[MAX_NAME_LEN]; size_t rootlen = 0; int gotroot = 0; - int status, count; + int status, count, found; char buf[2048]; char buf2[2048]; int keepwalking=1; @@ -716,6 +720,10 @@ memmove((char *)name, (char *)root, rootlen * sizeof(oid)); name_length = rootlen; objid_query-offset = objid_query-count; + + memmove((char *)objid_query-vars[0].name, (char *)root, rootlen * sizeof(oid)); + objid_query-vars[0].name_length = rootlen; + } if ((ss = snmp_open(session)) == NULL) { @@ -731,11 +739,11 @@ if (st (SNMP_CMD_GET | SNMP_CMD_GETNEXT)) { pdu = snmp_pdu_create((st SNMP_CMD_GET) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT); for (count = 0; objid_query-offset objid_query-count count objid_query-step; objid_query-offset++, count++){ -name_length = MAX_OID_LEN; -if (!snmp_parse_oid(objid_query-vars[objid_query-offset].oid, name, name_length)) { +objid_query-vars[objid_query-offset].name_length = MAX_OID_LEN; +if (!snmp_parse_oid(objid_query-vars[objid_query-offset].oid, objid_query-vars[objid_query-offset].name, (objid_query-vars[objid_query-offset].name_length))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid object identifier: %s, objid_query-vars[objid_query-offset].oid); } else { - snmp_add_null_var(pdu, name, name_length); + snmp_add_null_var(pdu, objid_query-vars[objid_query-offset].name, objid_query-vars[objid_query-offset].name_length); } } if(pdu-variables == NULL){ @@ -747,16 +755,16 @@ } else if (st SNMP_CMD_SET) { pdu = snmp_pdu_create(SNMP_MSG_SET); for (count = 0; objid_query-offset objid_query-count count objid_query-step; objid_query-offset++, count++){ -name_length = MAX_OID_LEN; -if (!snmp_parse_oid(objid_query-vars[objid_query-offset].oid, name, name_length)) { +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); snmp_free_pdu(pdu); snmp_close(ss); RETVAL_FALSE; return; } else { - if ((snmp_errno = snmp_add_var(pdu, name, name_length, objid_query-vars[objid_query-offset].type, objid_query-vars[objid_query-offset].value))) { - snprint_objid(buf, sizeof(buf), name, name_length); + 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)); snmp_free_pdu(pdu); snmp_close(ss); @@ -823,6
[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/generic_timeout_error.phpt tests/snmp-object-errno-errstr.phpt tests/snmp-object-error.phpt tests/snmp-object-properties.phpt tests/
lytboris Sun, 20 Mar 2011 20:07:33 + Revision: http://svn.php.net/viewvc?view=revisionrevision=309485 Log: follow CS: - method set_security should be named as setSecurity - SNMP_VERSION_2C constant 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/generic_timeout_error.phpt U 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 A + php/php-src/trunk/ext/snmp/tests/snmp-object-setSecurity_error.phpt (from php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt:r309453) D php/php-src/trunk/ext/snmp/tests/snmp-object-set_security_error.phpt U php/php-src/trunk/ext/snmp/tests/snmp-object.phpt U php/php-src/trunk/ext/snmp/tests/snmp2_set-nomib.phpt U php/php-src/trunk/ext/snmp/tests/snmp3-error.phpt U php/php-src/trunk/ext/snmp/tests/snmpset-nomib.phpt U php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-03-20 17:10:28 UTC (rev 309484) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-03-20 20:07:33 UTC (rev 309485) @@ -73,7 +73,7 @@ PHP_FUNCTION(snmp_read_mib); PHP_METHOD(SNMP, open); -PHP_METHOD(SNMP, set_security); +PHP_METHOD(SNMP, setSecurity); PHP_METHOD(SNMP, close); PHP_METHOD(SNMP, get); PHP_METHOD(SNMP, getnext); Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-03-20 17:10:28 UTC (rev 309484) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-03-20 20:07:33 UTC (rev 309485) @@ -374,7 +374,7 @@ ZEND_BEGIN_ARG_INFO(arginfo_snmp_void, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_security, 0, 0, 8) +ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_setSecurity, 0, 0, 8) ZEND_ARG_INFO(0, session) ZEND_ARG_INFO(0, sec_level) ZEND_ARG_INFO(0, auth_protocol) @@ -1847,9 +1847,9 @@ php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, (-1)); } -/* {{{ proto bool SNMP::set_security(resource session, string sec_level, [ string auth_protocol, string auth_passphrase [, string priv_protocol, string priv_passphrase [, string contextName [, string contextEngineID) +/* {{{ proto bool SNMP::setSecurity(resource session, string sec_level, [ string auth_protocol, string auth_passphrase [, string priv_protocol, string priv_passphrase [, string contextName [, string contextEngineID) Set SNMPv3 security-related session parameters */ -PHP_METHOD(snmp, set_security) +PHP_METHOD(snmp, setSecurity) { php_snmp_object *snmp_object; zval *object = getThis(); @@ -2338,7 +2338,7 @@ static zend_function_entry php_snmp_class_methods[] = { PHP_ME(snmp, open,arginfo_snmp_open, ZEND_ACC_PUBLIC) PHP_ME(snmp, close,arginfo_snmp_void, ZEND_ACC_PUBLIC) - PHP_ME(snmp, set_security, arginfo_snmp_set_security, ZEND_ACC_PUBLIC) + PHP_ME(snmp, setSecurity, arginfo_snmp_setSecurity, ZEND_ACC_PUBLIC) PHP_ME(snmp, get,arginfo_snmp_get, ZEND_ACC_PUBLIC) PHP_ME(snmp, getnext, arginfo_snmp_get, ZEND_ACC_PUBLIC) @@ -2434,6 +2434,7 @@ 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_2C, SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(SNMP_VERSION_3, SNMP_VERSION_3, CONST_CS | CONST_PERSISTENT); REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_NOERROR, (long)PHP_SNMP_ERRNO_NOERROR); Modified: php/php-src/trunk/ext/snmp/tests/generic_timeout_error.phpt === --- php/php-src/trunk/ext/snmp/tests/generic_timeout_error.phpt 2011-03-20 17:10:28 UTC (rev 309484) +++ php/php-src/trunk/ext/snmp/tests/generic_timeout_error.phpt 2011-03-20 20:07:33 UTC (rev 309485) @@ -19,4 +19,4 @@ ? --EXPECTF-- Warning: snmpget(): No response from %s in %s on line %d -bool(false) \ No newline at end of file +bool(false) Modified: php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt === --- php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt 2011-03-20 17:10:28 UTC (rev 309484) +++ php/php-src/trunk/ext/snmp/tests/snmp-object-errno-errstr.phpt 2011-03-20 20:07:33 UTC (rev 309485) @@ -38,7 +38,7 @@ $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); +$session-setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
[PHP-CVS] svn: /php/php-src/trunk/ext/snmp/ php_snmp.h snmp.c tests/snmp2_set.phpt tests/wrong_hostname.phpt
lytboris Fri, 04 Mar 2011 18:58:01 + Revision: http://svn.php.net/viewvc?view=revisionrevision=308931 Log: * fix warning about redefining REGISTER_PDO_CLASS_CONST_LONG (damn copy'n'paste) * tuned two unit test that failed at gcov.php.net/PHP_HEAD 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/snmp2_set.phpt U php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt Modified: php/php-src/trunk/ext/snmp/php_snmp.h === --- php/php-src/trunk/ext/snmp/php_snmp.h 2011-03-04 18:48:22 UTC (rev 308930) +++ php/php-src/trunk/ext/snmp/php_snmp.h 2011-03-04 18:58:01 UTC (rev 308931) @@ -124,7 +124,7 @@ #define SNMP_G(v) (snmp_globals.v) #endif -#define REGISTER_PDO_CLASS_CONST_LONG(const_name, value) \ +#define REGISTER_SNMP_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 Modified: php/php-src/trunk/ext/snmp/snmp.c === --- php/php-src/trunk/ext/snmp/snmp.c 2011-03-04 18:48:22 UTC (rev 308930) +++ php/php-src/trunk/ext/snmp/snmp.c 2011-03-04 18:58:01 UTC (rev 308931) @@ -2436,11 +2436,11 @@ 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); + REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_NOERROR, (long)PHP_SNMP_ERRNO_NOERROR); + REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_GENERIC, (long)PHP_SNMP_ERRNO_GENERIC); + REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_TIMEOUT, (long)PHP_SNMP_ERRNO_TIMEOUT); + REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_ERROR_IN_REPLY, (long)PHP_SNMP_ERRNO_ERROR_IN_REPLY); + REGISTER_SNMP_CLASS_CONST_LONG(ERRNO_OID_NOT_INCREASING, (long)PHP_SNMP_ERRNO_OID_NOT_INCREASING); return SUCCESS; } Modified: php/php-src/trunk/ext/snmp/tests/snmp2_set.phpt === --- php/php-src/trunk/ext/snmp/tests/snmp2_set.phpt 2011-03-04 18:48:22 UTC (rev 308930) +++ php/php-src/trunk/ext/snmp/tests/snmp2_set.phpt 2011-03-04 18:58:01 UTC (rev 308931) @@ -224,13 +224,13 @@ bool(true) Multiple OID, 1st bogus, single type, multiple value -Warning: snmp2_set(): Error in packet at '%s': noCreation (That table does not support row creation or that object can not ever be created) in %s on line %d +Warning: snmp2_set(): Error in packet at '%s': %rnoCreation|notWritable%r (%s) in %s on line %d bool(false) bool(true) bool(true) Multiple OID, 2nd bogus, single type, multiple value -Warning: snmp2_set(): Error in packet at '%s': noCreation (That table does not support row creation or that object can not ever be created) in %s on line %d +Warning: snmp2_set(): Error in packet at '%s': %rnoCreation|notWritable%r (%s) in %s on line %d bool(false) bool(true) bool(true) Modified: php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt === --- php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt2011-03-04 18:48:22 UTC (rev 308930) +++ php/php-src/trunk/ext/snmp/tests/wrong_hostname.phpt2011-03-04 18:58:01 UTC (rev 308931) @@ -18,5 +18,5 @@ ? --EXPECTF-- -Warning: snmpget(): Could not open snmp connection: Unknown host (192.168..6.1) (Bad file descriptor) in %s on line %d +Warning: snmpget(): Could not open snmp connection: Unknown host (192.168..6.1) (%s) in %s on line %d bool(false) \ No newline at end of file -- 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
Hi. On Thu, Mar 3, 2011 at 1:34 AM, Christopher Jones christopher.jo...@oracle.com 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
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
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=revisionrevision=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
lytboris Sat, 26 Feb 2011 08:27:26 + Revision: http://svn.php.net/viewvc?view=revisionrevision=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),