From 4049a9424c76735fabf0ed342311cc9a116d0f5e Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Thu, 19 Mar 2026 11:56:00 +0800 Subject: [PATCH 01/16] Add functions to control more SNMP library output options --- ext/snmp/php_snmp.h | 4 +++ ext/snmp/snmp.c | 77 +++++++++++++++++++++++++++++++++++++++++ ext/snmp/snmp.stub.php | 11 ++++++ ext/snmp/snmp_arginfo.h | 36 ++++++++++++++++++- 4 files changed, 127 insertions(+), 1 deletion(-) diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index ce9849588b19e..2473a10537b7f 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -50,7 +50,11 @@ typedef struct _php_snmp_object { int valueretrieval; int quick_print; int enum_print; + int numeric_timeticks; + int extended_index; + int dontprint_units; int oid_output_format; + int mib_allow_underscores; int snmp_errno; int oid_increasing_check; int exceptions_enabled; diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index d116339dd1f40..45df4e1ca87d0 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1395,6 +1395,12 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) 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); + glob_snmp_object.numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, snmp_object->numeric_timeticks); + glob_snmp_object.extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, snmp_object->extended_index); + glob_snmp_object.dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, snmp_object->dontprint_units); glob_snmp_object.quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, snmp_object->quick_print); glob_snmp_object.oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); @@ -1413,6 +1419,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) snmp_session_free(&session); } else { netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, glob_snmp_object.enum_print); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, glob_snmp_object.numeric_timeticks); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, glob_snmp_object.extended_index); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, glob_snmp_object.dontprint_units); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, glob_snmp_object.quick_print); netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, glob_snmp_object.oid_output_format); } @@ -1493,6 +1502,48 @@ PHP_FUNCTION(snmp_set_enum_print) } /* }}} */ +/* {{{ Print timetick values as integers */ +PHP_FUNCTION(snmp_set_numeric_timeticks) +{ + bool a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + RETURN_THROWS(); + } + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, (int) a1); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ Use extended table format when printing tables */ +PHP_FUNCTION(snmp_set_extended_index) +{ + bool a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + RETURN_THROWS(); + } + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, (int) a1); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ Use extended table format */ +PHP_FUNCTION(snmp_set_dontprint_units) +{ + bool a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + RETURN_THROWS(); + } + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, (int) a1); + RETURN_TRUE; +} +/* }}} */ + /* {{{ Set the OID output format. */ PHP_FUNCTION(snmp_set_oid_output_format) { @@ -1618,6 +1669,20 @@ PHP_FUNCTION(snmp_get_valueretrieval) } /* }}} */ +/* {{{ Allow underscores in MIBs. */ +PHP_FUNCTION(snmp_mib_allow_underscores) +{ + bool a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + RETURN_THROWS(); + } + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL, (int) a1); + RETURN_TRUE; +} +/* }}} */ + /* {{{ Reads and parses a MIB file into the active MIB tree. */ PHP_FUNCTION(snmp_read_mib) { @@ -1674,6 +1739,9 @@ PHP_METHOD(SNMP, __construct) snmp_object->max_oids = 0; snmp_object->valueretrieval = SNMP_G(valueretrieval); snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); + snmp_object->numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); + snmp_object->extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); + snmp_object->dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); 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; @@ -1988,6 +2056,9 @@ static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval) 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) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_timeticks) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(extended_index) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dontprint_units) #define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \ static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \ @@ -2053,6 +2124,9 @@ static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(quick_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_timeticks) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(extended_index) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(dontprint_units) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check) /* {{{ */ @@ -2105,6 +2179,9 @@ const php_snmp_prop_handler php_snmp_property_entries[] = { PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval), PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print), + PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_timeticks), + PHP_SNMP_PROPERTY_ENTRY_RECORD(extended_index), + PHP_SNMP_PROPERTY_ENTRY_RECORD(dontprint_units), PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_output_format), PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_increasing_check), PHP_SNMP_PROPERTY_ENTRY_RECORD(exceptions_enabled), diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 0a303aea77ff0..118094f551dd6 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -129,6 +129,12 @@ function snmp_set_quick_print(bool $enable): true {} function snmp_set_enum_print(bool $enable): true {} +function snmp_set_numeric_timeticks(bool $enable): true {} + +function snmp_set_extended_index(bool $enable): true {} + +function snmp_set_dontprint_units(bool $enable): true {} + function snmp_set_oid_output_format(int $format): true {} /** @alias snmp_set_oid_output_format */ @@ -179,6 +185,8 @@ function snmp_set_valueretrieval(int $method): true {} function snmp_get_valueretrieval(): int {} +function snmp_mib_allow_underscores(bool $enable): true {} + function snmp_read_mib(string $filename): bool {} class SNMP @@ -215,6 +223,9 @@ class SNMP public int $valueretrieval; public bool $quick_print; public bool $enum_print; + public bool $numeric_timeticks; + public bool $extended_index; + public bool $dontprint_units; public int $oid_output_format; public bool $oid_increasing_check; public int $exceptions_enabled; diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 1ee821f0538da..70559157c8ac2 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: e2451ac3ea0fa5eb1158e8b7252e61c6794d514f */ + * Stub hash: f1a38e40e464dca05f9d5d84949fee121bbdc3ef */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -42,6 +42,12 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_enum_print arginfo_snmp_set_quick_print +#define arginfo_snmp_set_numeric_timeticks arginfo_snmp_set_quick_print + +#define arginfo_snmp_set_extended_index arginfo_snmp_set_quick_print + +#define arginfo_snmp_set_dontprint_units arginfo_snmp_set_quick_print + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_oid_output_format, 0, 1, IS_TRUE, 0) ZEND_ARG_TYPE_INFO(0, format, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -110,6 +116,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_get_valueretrieval, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() +#define arginfo_snmp_mib_allow_underscores arginfo_snmp_set_quick_print + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_read_mib, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -171,6 +179,9 @@ ZEND_FUNCTION(snmpset); ZEND_FUNCTION(snmp_get_quick_print); ZEND_FUNCTION(snmp_set_quick_print); ZEND_FUNCTION(snmp_set_enum_print); +ZEND_FUNCTION(snmp_set_numeric_timeticks); +ZEND_FUNCTION(snmp_set_extended_index); +ZEND_FUNCTION(snmp_set_dontprint_units); ZEND_FUNCTION(snmp_set_oid_output_format); ZEND_FUNCTION(snmp2_get); ZEND_FUNCTION(snmp2_getnext); @@ -184,6 +195,7 @@ ZEND_FUNCTION(snmp3_real_walk); ZEND_FUNCTION(snmp3_set); ZEND_FUNCTION(snmp_set_valueretrieval); ZEND_FUNCTION(snmp_get_valueretrieval); +ZEND_FUNCTION(snmp_mib_allow_underscores); ZEND_FUNCTION(snmp_read_mib); ZEND_METHOD(SNMP, __construct); ZEND_METHOD(SNMP, close); @@ -205,6 +217,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_get_quick_print, arginfo_snmp_get_quick_print) ZEND_FE(snmp_set_quick_print, arginfo_snmp_set_quick_print) ZEND_FE(snmp_set_enum_print, arginfo_snmp_set_enum_print) + ZEND_FE(snmp_set_numeric_timeticks, arginfo_snmp_set_numeric_timeticks) + ZEND_FE(snmp_set_extended_index, arginfo_snmp_set_extended_index) + ZEND_FE(snmp_set_dontprint_units, arginfo_snmp_set_dontprint_units) ZEND_FE(snmp_set_oid_output_format, arginfo_snmp_set_oid_output_format) ZEND_RAW_FENTRY("snmp_set_oid_numeric_print", zif_snmp_set_oid_output_format, arginfo_snmp_set_oid_numeric_print, 0, NULL, NULL) ZEND_FE(snmp2_get, arginfo_snmp2_get) @@ -219,6 +234,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp3_set, arginfo_snmp3_set) ZEND_FE(snmp_set_valueretrieval, arginfo_snmp_set_valueretrieval) ZEND_FE(snmp_get_valueretrieval, arginfo_snmp_get_valueretrieval) + ZEND_FE(snmp_mib_allow_underscores, arginfo_snmp_mib_allow_underscores) ZEND_FE(snmp_read_mib, arginfo_snmp_read_mib) ZEND_FE_END }; @@ -370,6 +386,24 @@ static zend_class_entry *register_class_SNMP(void) zend_declare_typed_property(class_entry, property_enum_print_name, &property_enum_print_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release_ex(property_enum_print_name, true); + zval property_numeric_timeticks_default_value; + ZVAL_UNDEF(&property_numeric_timeticks_default_value); + zend_string *property_numeric_timeticks_name = zend_string_init("numeric_timeticks", sizeof("numeric_timeticks") - 1, true); + zend_declare_typed_property(class_entry, property_numeric_timeticks_name, &property_numeric_timeticks_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_numeric_timeticks_name, true); + + zval property_extended_index_default_value; + ZVAL_UNDEF(&property_extended_index_default_value); + zend_string *property_extended_index_name = zend_string_init("extended_index", sizeof("extended_index") - 1, true); + zend_declare_typed_property(class_entry, property_extended_index_name, &property_extended_index_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_extended_index_name, true); + + zval property_dontprint_units_default_value; + ZVAL_UNDEF(&property_dontprint_units_default_value); + zend_string *property_dontprint_units_name = zend_string_init("dontprint_units", sizeof("dontprint_units") - 1, true); + zend_declare_typed_property(class_entry, property_dontprint_units_name, &property_dontprint_units_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_dontprint_units_name, true); + zval property_oid_output_format_default_value; ZVAL_UNDEF(&property_oid_output_format_default_value); zend_string *property_oid_output_format_name = zend_string_init("oid_output_format", sizeof("oid_output_format") - 1, true); From e7840bb00f5e88eabbf77f8de46646337737c477 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Thu, 19 Mar 2026 12:29:11 +0800 Subject: [PATCH 02/16] Remove allow_underscores from php_snmp_object --- ext/snmp/php_snmp.h | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index 2473a10537b7f..656dcbe14d9e0 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -54,7 +54,6 @@ typedef struct _php_snmp_object { int extended_index; int dontprint_units; int oid_output_format; - int mib_allow_underscores; int snmp_errno; int oid_increasing_check; int exceptions_enabled; From 42a4511c02e7f21fcc6110bc9dd5304309344c24 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Mon, 23 Mar 2026 20:49:15 +0800 Subject: [PATCH 03/16] Update test output --- ext/snmp/tests/snmp-object-properties.phpt | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index a8fccd406b7e3..7b58c86381989 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -98,6 +98,12 @@ object(SNMP)#%d (%d) { bool(false) ["enum_print"]=> bool(false) + ["numeric_timeticks"]=> + bool(false) + ["extended_index"]=> + bool(false) + ["dontprint_units"]=> + bool(false) ["oid_output_format"]=> int(3) ["oid_increasing_check"]=> @@ -123,6 +129,12 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_timeticks"]=> + bool(false) + ["extended_index"]=> + bool(false) + ["dontprint_units"]=> + bool(false) ["oid_output_format"]=> int(4) ["oid_increasing_check"]=> @@ -148,6 +160,12 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_timeticks"]=> + bool(false) + ["extended_index"]=> + bool(false) + ["dontprint_units"]=> + bool(false) ["oid_output_format"]=> int(3) ["oid_increasing_check"]=> @@ -178,6 +196,12 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_timeticks"]=> + bool(false) + ["extended_index"]=> + bool(false) + ["dontprint_units"]=> + bool(false) ["oid_output_format"]=> int(3) ["oid_increasing_check"]=> From 570308b4df8bab51e0ff731448d12822c3c92277 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Wed, 25 Mar 2026 15:34:21 +0800 Subject: [PATCH 04/16] Add option to set numeric index --- ext/snmp/snmp.c | 21 +++++++++++++++++++++ ext/snmp/snmp.stub.php | 2 ++ ext/snmp/snmp_arginfo.h | 6 +++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 45df4e1ca87d0..ac1d0651eae51 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1395,6 +1395,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) 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); + glob_snmp_object.numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, snmp_object->numeric_index); glob_snmp_object.numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, snmp_object->numeric_timeticks); glob_snmp_object.extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); @@ -1419,6 +1421,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) snmp_session_free(&session); } else { netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, glob_snmp_object.enum_print); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, glob_snmp_object.numeric_index); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, glob_snmp_object.numeric_timeticks); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, glob_snmp_object.extended_index); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, glob_snmp_object.dontprint_units); @@ -1502,6 +1505,20 @@ PHP_FUNCTION(snmp_set_enum_print) } /* }}} */ +/* {{{ Print table index numerically */ +PHP_FUNCTION(snmp_set_numeric_index) +{ + bool a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + RETURN_THROWS(); + } + + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, (int) a1); + RETURN_TRUE; +} +/* }}} */ + /* {{{ Print timetick values as integers */ PHP_FUNCTION(snmp_set_numeric_timeticks) { @@ -1739,6 +1756,7 @@ PHP_METHOD(SNMP, __construct) snmp_object->max_oids = 0; snmp_object->valueretrieval = SNMP_G(valueretrieval); snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); + snmp_object->numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); snmp_object->numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); snmp_object->extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); snmp_object->dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); @@ -2056,6 +2074,7 @@ static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval) 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) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(extended_index) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dontprint_units) @@ -2124,6 +2143,7 @@ static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(quick_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(extended_index) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(dontprint_units) @@ -2179,6 +2199,7 @@ const php_snmp_prop_handler php_snmp_property_entries[] = { PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval), PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print), + PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_index), PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_timeticks), PHP_SNMP_PROPERTY_ENTRY_RECORD(extended_index), PHP_SNMP_PROPERTY_ENTRY_RECORD(dontprint_units), diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 118094f551dd6..86318ef0655c6 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -129,6 +129,8 @@ function snmp_set_quick_print(bool $enable): true {} function snmp_set_enum_print(bool $enable): true {} +function snmp_set_numeric_index(bool $enable): true {} + function snmp_set_numeric_timeticks(bool $enable): true {} function snmp_set_extended_index(bool $enable): true {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 70559157c8ac2..f603910187124 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: f1a38e40e464dca05f9d5d84949fee121bbdc3ef */ + * Stub hash: 89efd2d6c0694fcb719ea024d4fb47af37148770 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -42,6 +42,8 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_enum_print arginfo_snmp_set_quick_print +#define arginfo_snmp_set_numeric_index arginfo_snmp_set_quick_print + #define arginfo_snmp_set_numeric_timeticks arginfo_snmp_set_quick_print #define arginfo_snmp_set_extended_index arginfo_snmp_set_quick_print @@ -179,6 +181,7 @@ ZEND_FUNCTION(snmpset); ZEND_FUNCTION(snmp_get_quick_print); ZEND_FUNCTION(snmp_set_quick_print); ZEND_FUNCTION(snmp_set_enum_print); +ZEND_FUNCTION(snmp_set_numeric_index); ZEND_FUNCTION(snmp_set_numeric_timeticks); ZEND_FUNCTION(snmp_set_extended_index); ZEND_FUNCTION(snmp_set_dontprint_units); @@ -217,6 +220,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_get_quick_print, arginfo_snmp_get_quick_print) ZEND_FE(snmp_set_quick_print, arginfo_snmp_set_quick_print) ZEND_FE(snmp_set_enum_print, arginfo_snmp_set_enum_print) + ZEND_FE(snmp_set_numeric_index, arginfo_snmp_set_numeric_index) ZEND_FE(snmp_set_numeric_timeticks, arginfo_snmp_set_numeric_timeticks) ZEND_FE(snmp_set_extended_index, arginfo_snmp_set_extended_index) ZEND_FE(snmp_set_dontprint_units, arginfo_snmp_set_dontprint_units) From bcb2e23aa12f93df453db38b76325c216f359e1f Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Wed, 25 Mar 2026 15:37:02 +0800 Subject: [PATCH 05/16] Fix missing item from stuct --- ext/snmp/php_snmp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index 656dcbe14d9e0..08b3b83561a4c 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -50,6 +50,7 @@ typedef struct _php_snmp_object { int valueretrieval; int quick_print; int enum_print; + int numeric_index; int numeric_timeticks; int extended_index; int dontprint_units; From ee3e676580f2ae879bf778bff6bde3e0e4d61c3b Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Wed, 25 Mar 2026 16:09:00 +0800 Subject: [PATCH 06/16] Fix for tests --- ext/snmp/tests/snmp-object-properties.phpt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index 7b58c86381989..29530e1b485d8 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -98,6 +98,8 @@ object(SNMP)#%d (%d) { bool(false) ["enum_print"]=> bool(false) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -129,6 +131,8 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -160,6 +164,8 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -196,6 +202,8 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> From 881d768e2e3a52ee99af577612f63df6e1a6890a Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Wed, 25 Mar 2026 16:55:00 +0800 Subject: [PATCH 07/16] Fix tests for real this time --- ext/snmp/tests/snmp-object-properties.phpt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index 29530e1b485d8..15f71795e3ee9 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -98,8 +98,6 @@ object(SNMP)#%d (%d) { bool(false) ["enum_print"]=> bool(false) - ["numeric_index"]=> - bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -112,6 +110,8 @@ object(SNMP)#%d (%d) { bool(true) ["exceptions_enabled"]=> int(0) + ["numeric_index"]=> + bool(false) } object(SNMP)#%d (%d) { ["info"]=> @@ -131,8 +131,6 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) - ["numeric_index"]=> - bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -145,6 +143,8 @@ object(SNMP)#%d (%d) { bool(false) ["exceptions_enabled"]=> int(0) + ["numeric_index"]=> + bool(false) } object(SNMP)#%d (%d) { ["info"]=> @@ -164,8 +164,6 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) - ["numeric_index"]=> - bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -178,6 +176,8 @@ object(SNMP)#%d (%d) { bool(true) ["exceptions_enabled"]=> int(0) + ["numeric_index"]=> + bool(false) } bool(true) bool(true) @@ -202,8 +202,6 @@ object(SNMP)#%d (%d) { bool(true) ["enum_print"]=> bool(true) - ["numeric_index"]=> - bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> @@ -216,6 +214,8 @@ object(SNMP)#%d (%d) { bool(true) ["exceptions_enabled"]=> int(0) + ["numeric_index"]=> + bool(false) ["123"]=> string(11) "param_value" } From 069ff87ad5c232ab85879d45a2197b3ae8f90652 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 10:19:25 +0800 Subject: [PATCH 08/16] Use single command with ENUM to set various options --- ext/snmp/php_snmp.h | 3 + ext/snmp/snmp.c | 154 +++++++++++++++++++++++----------------- ext/snmp/snmp.stub.php | 85 +++++++++++++++++++--- ext/snmp/snmp_arginfo.h | 49 ++++++++----- 4 files changed, 198 insertions(+), 93 deletions(-) diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index 08b3b83561a4c..aa86ca3abff72 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -54,6 +54,9 @@ typedef struct _php_snmp_object { int numeric_timeticks; int extended_index; int dontprint_units; + int escape_quotes; + int print_hex_text; + int string_output_format; int oid_output_format; int snmp_errno; int oid_increasing_check; diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index ac1d0651eae51..6c8eba4afaa91 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1224,6 +1224,44 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp } /* }}} */ +/* +* Save the snmplib state into the given php_snmp_object +*/ +static void save_snmplib_output_options(php_snmp_object *snmp_object) +{ + // Booleans + snmp_object->quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); + snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); + snmp_object->numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); + snmp_object->numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); + snmp_object->extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); + snmp_object->dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); + snmp_object->escape_quotes = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ESCAPE_QUOTES); + snmp_object->print_hex_text = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_HEX_TEXT); + // Integers + snmp_object->string_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT); + snmp_object->oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); +} + +/* +* Set the snmplib output options using the given php_snmp_object +*/ +static void set_snmplib_output_options(php_snmp_object *snmp_object) +{ + // Booleans + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, snmp_object->quick_print); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, snmp_object->enum_print); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, snmp_object->numeric_index); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, snmp_object->numeric_timeticks); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, snmp_object->extended_index); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, snmp_object->dontprint_units); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ESCAPE_QUOTES, snmp_object->escape_quotes); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_HEX_TEXT, snmp_object->print_hex_text); + // Integers + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT, snmp_object->string_output_format); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, snmp_object->oid_output_format); +} + /* {{{ php_snmp * * Generic SNMP handler for all versions. @@ -1393,20 +1431,10 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) } 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); - glob_snmp_object.numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, snmp_object->numeric_index); - glob_snmp_object.numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, snmp_object->numeric_timeticks); - glob_snmp_object.extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, snmp_object->extended_index); - glob_snmp_object.dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, snmp_object->dontprint_units); - glob_snmp_object.quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, snmp_object->quick_print); - glob_snmp_object.oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT); - netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, snmp_object->oid_output_format); + + // Save the global snmplib output options and set the options to those defined by the object instance + save_snmplib_output_options(&glob_snmp_object); + set_snmplib_output_options(snmp_object); } if (objid_query.max_repetitions < 0) { @@ -1420,13 +1448,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) if (session_less_mode) { snmp_session_free(&session); } else { - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, glob_snmp_object.enum_print); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, glob_snmp_object.numeric_index); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, glob_snmp_object.numeric_timeticks); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, glob_snmp_object.extended_index); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, glob_snmp_object.dontprint_units); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, glob_snmp_object.quick_print); - netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, glob_snmp_object.oid_output_format); + // Restore the snmplib output options back to the global state + set_snmplib_output_options(&glob_snmp_object); } } /* }}} */ @@ -1505,59 +1528,72 @@ PHP_FUNCTION(snmp_set_enum_print) } /* }}} */ -/* {{{ Print table index numerically */ -PHP_FUNCTION(snmp_set_numeric_index) +/* {{{ Set walk option. */ +PHP_FUNCTION(snmp_set_mib_option) { - bool a1; + zend_long a1, a2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &a1, &a2) == FAILURE) { RETURN_THROWS(); } - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, (int) a1); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ Print timetick values as integers */ -PHP_FUNCTION(snmp_set_numeric_timeticks) -{ - bool a1; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { - RETURN_THROWS(); + switch (a1) { + case NETSNMP_DS_LIB_MIB_PARSE_LABEL: + case NETSNMP_DS_LIB_MIB_COMMENT_TERM: + case NETSNMP_DS_LIB_MIB_REPLACE: + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, a1, (int) a2); + default: + zend_argument_value_error(1, "must be an SNMP_MIB_* constant"); + RETURN_THROWS(); } - - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, (int) a1); - RETURN_TRUE; } /* }}} */ -/* {{{ Use extended table format when printing tables */ -PHP_FUNCTION(snmp_set_extended_index) +/* {{{ Set the string output format. */ +PHP_FUNCTION(snmp_set_string_output_format) { - bool a1; + zend_long a1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &a1) == FAILURE) { RETURN_THROWS(); } - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, (int) a1); - RETURN_TRUE; + switch (a1) { + case NETSNMP_STRING_OUTPUT_GUESS: + case NETSNMP_STRING_OUTPUT_ASCII: + case NETSNMP_STRING_OUTPUT_HEX: + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT, a1); + default: + zend_argument_value_error(1, "must be an SNMP_STRING_OUTPUT_* constant"); + RETURN_THROWS(); + } } /* }}} */ -/* {{{ Use extended table format */ -PHP_FUNCTION(snmp_set_dontprint_units) +/* {{{ Set output format option. */ +PHP_FUNCTION(snmp_set_output_option) { - bool a1; + zend_long a1, a2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &a1, &a2) == FAILURE) { RETURN_THROWS(); } - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, (int) a1); - RETURN_TRUE; + switch (a1) { + case NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS: + case NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM: + case NETSNMP_DS_LIB_ESCAPE_QUOTES: + case NETSNMP_DS_LIB_QUICK_PRINT: + case NETSNMP_DS_LIB_NUMERIC_TIMETICKS: + case NETSNMP_DS_LIB_PRINT_HEX_TEXT: + case NETSNMP_DS_LIB_DONT_PRINT_UNITS: + case NETSNMP_DS_LIB_PRINT_BARE_VALUE: + case NETSNMP_DS_LIB_EXTENDED_INDEX: + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, a1, (int) a2); + default: + zend_argument_value_error(1, "must be an SNMP_OUTPUT_* constant"); + RETURN_THROWS(); + } } /* }}} */ @@ -1686,20 +1722,6 @@ PHP_FUNCTION(snmp_get_valueretrieval) } /* }}} */ -/* {{{ Allow underscores in MIBs. */ -PHP_FUNCTION(snmp_mib_allow_underscores) -{ - bool a1; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) { - RETURN_THROWS(); - } - - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL, (int) a1); - RETURN_TRUE; -} -/* }}} */ - /* {{{ Reads and parses a MIB file into the active MIB tree. */ PHP_FUNCTION(snmp_read_mib) { diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 86318ef0655c6..3664be3f0d425 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -2,6 +2,22 @@ /** @generate-class-entries */ +/** + * @var int + * @cvalue NETSNMP_DS_LIB_MIB_PARSE_LABEL + */ +const SNMP_MIB_ALLOW_UNDERSCORES = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_MIB_COMMENT_TERM + */ +const SNMP_MIB_COMMENT_TERM = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_MIB_REPLACE + */ +const SNMP_MIB_REPLACE = UNKNOWN; + /** * @var int * @cvalue NETSNMP_OID_OUTPUT_SUFFIX @@ -33,6 +49,63 @@ */ const SNMP_OID_OUTPUT_NONE = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS + */ +const SNMP_OUTPUT_NUMERIC_INDEX = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM + */ +const SNMP_OUTPUT_ENUM_PRINT = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_ESCAPE_QUOTES + */ +const SNMP_OUTPUT_ESCAPE_QUOTES = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_QUICK_PRINT + */ +const SNMP_OUTPUT_QUICK_PRINT = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_NUMERIC_TIMETICKS + */ +const SNMP_OUTPUT_NUMERIC_TIMETICKS = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_PRINT_HEX_TEXT + */ +const SNMP_OUTPUT_PRINT_HEX_TEXT = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_DONT_PRINT_UNITS + */ +const SNMP_OUTPUT_DONT_PRINT_UNITS = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_DS_LIB_EXTENDED_INDEX + */ +const SNMP_OUTPUT_EXTENDED_INDEX = UNKNOWN; + +/** + * @var int + * @cvalue NETSNMP_STRING_OUTPUT_GUESS + */ +const SNMP_STRING_OUTPUT_GUESS = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_STRING_OUTPUT_ASCII + */ +const SNMP_STRING_OUTPUT_ASCII = UNKNOWN; +/** + * @var int + * @cvalue NETSNMP_STRING_OUTPUT_HEX + */ +const SNMP_STRING_OUTPUT_HEX = UNKNOWN; + /** * @var int * @cvalue SNMP_VALUE_LIBRARY @@ -129,15 +202,13 @@ function snmp_set_quick_print(bool $enable): true {} function snmp_set_enum_print(bool $enable): true {} -function snmp_set_numeric_index(bool $enable): true {} - -function snmp_set_numeric_timeticks(bool $enable): true {} +function snmp_set_mib_option(int $option, bool $enable): void {} -function snmp_set_extended_index(bool $enable): true {} +function snmp_set_oid_output_format(int $format): true {} -function snmp_set_dontprint_units(bool $enable): true {} +function snmp_set_output_option(int $option, bool $enable): void {} -function snmp_set_oid_output_format(int $format): true {} +function snmp_set_string_output(int $format): void {} /** @alias snmp_set_oid_output_format */ function snmp_set_oid_numeric_print(int $format): true {} @@ -187,8 +258,6 @@ function snmp_set_valueretrieval(int $method): true {} function snmp_get_valueretrieval(): int {} -function snmp_mib_allow_underscores(bool $enable): true {} - function snmp_read_mib(string $filename): bool {} class SNMP diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index f603910187124..c055007a3a9b9 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: 89efd2d6c0694fcb719ea024d4fb47af37148770 */ + * Stub hash: 0b5de7cff240601a238971eee230865017c52610 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -42,15 +42,18 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_enum_print arginfo_snmp_set_quick_print -#define arginfo_snmp_set_numeric_index arginfo_snmp_set_quick_print - -#define arginfo_snmp_set_numeric_timeticks arginfo_snmp_set_quick_print +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_mib_option, 0, 2, IS_VOID, 0) + ZEND_ARG_TYPE_INFO(0, option, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0) +ZEND_END_ARG_INFO() -#define arginfo_snmp_set_extended_index arginfo_snmp_set_quick_print +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_oid_output_format, 0, 1, IS_TRUE, 0) + ZEND_ARG_TYPE_INFO(0, format, IS_LONG, 0) +ZEND_END_ARG_INFO() -#define arginfo_snmp_set_dontprint_units arginfo_snmp_set_quick_print +#define arginfo_snmp_set_output_option arginfo_snmp_set_mib_option -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_oid_output_format, 0, 1, IS_TRUE, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_string_output, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, format, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -118,8 +121,6 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_get_valueretrieval, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_snmp_mib_allow_underscores arginfo_snmp_set_quick_print - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_read_mib, 0, 1, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -181,11 +182,10 @@ ZEND_FUNCTION(snmpset); ZEND_FUNCTION(snmp_get_quick_print); ZEND_FUNCTION(snmp_set_quick_print); ZEND_FUNCTION(snmp_set_enum_print); -ZEND_FUNCTION(snmp_set_numeric_index); -ZEND_FUNCTION(snmp_set_numeric_timeticks); -ZEND_FUNCTION(snmp_set_extended_index); -ZEND_FUNCTION(snmp_set_dontprint_units); +ZEND_FUNCTION(snmp_set_mib_option); ZEND_FUNCTION(snmp_set_oid_output_format); +ZEND_FUNCTION(snmp_set_output_option); +ZEND_FUNCTION(snmp_set_string_output); ZEND_FUNCTION(snmp2_get); ZEND_FUNCTION(snmp2_getnext); ZEND_FUNCTION(snmp2_walk); @@ -198,7 +198,6 @@ ZEND_FUNCTION(snmp3_real_walk); ZEND_FUNCTION(snmp3_set); ZEND_FUNCTION(snmp_set_valueretrieval); ZEND_FUNCTION(snmp_get_valueretrieval); -ZEND_FUNCTION(snmp_mib_allow_underscores); ZEND_FUNCTION(snmp_read_mib); ZEND_METHOD(SNMP, __construct); ZEND_METHOD(SNMP, close); @@ -220,11 +219,10 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_get_quick_print, arginfo_snmp_get_quick_print) ZEND_FE(snmp_set_quick_print, arginfo_snmp_set_quick_print) ZEND_FE(snmp_set_enum_print, arginfo_snmp_set_enum_print) - ZEND_FE(snmp_set_numeric_index, arginfo_snmp_set_numeric_index) - ZEND_FE(snmp_set_numeric_timeticks, arginfo_snmp_set_numeric_timeticks) - ZEND_FE(snmp_set_extended_index, arginfo_snmp_set_extended_index) - ZEND_FE(snmp_set_dontprint_units, arginfo_snmp_set_dontprint_units) + ZEND_FE(snmp_set_mib_option, arginfo_snmp_set_mib_option) ZEND_FE(snmp_set_oid_output_format, arginfo_snmp_set_oid_output_format) + ZEND_FE(snmp_set_output_option, arginfo_snmp_set_output_option) + ZEND_FE(snmp_set_string_output, arginfo_snmp_set_string_output) ZEND_RAW_FENTRY("snmp_set_oid_numeric_print", zif_snmp_set_oid_output_format, arginfo_snmp_set_oid_numeric_print, 0, NULL, NULL) ZEND_FE(snmp2_get, arginfo_snmp2_get) ZEND_FE(snmp2_getnext, arginfo_snmp2_getnext) @@ -238,7 +236,6 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp3_set, arginfo_snmp3_set) ZEND_FE(snmp_set_valueretrieval, arginfo_snmp_set_valueretrieval) ZEND_FE(snmp_get_valueretrieval, arginfo_snmp_get_valueretrieval) - ZEND_FE(snmp_mib_allow_underscores, arginfo_snmp_mib_allow_underscores) ZEND_FE(snmp_read_mib, arginfo_snmp_read_mib) ZEND_FE_END }; @@ -258,12 +255,26 @@ static const zend_function_entry class_SNMP_methods[] = { static void register_snmp_symbols(int module_number) { + REGISTER_LONG_CONSTANT("SNMP_MIB_ALLOW_UNDERSCORES", NETSNMP_DS_LIB_MIB_PARSE_LABEL, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_MIB_COMMENT_TERM", NETSNMP_DS_LIB_MIB_COMMENT_TERM, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_MIB_REPLACE", NETSNMP_DS_LIB_MIB_REPLACE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_SUFFIX", NETSNMP_OID_OUTPUT_SUFFIX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_MODULE", NETSNMP_OID_OUTPUT_MODULE, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_FULL", NETSNMP_OID_OUTPUT_FULL, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NUMERIC", NETSNMP_OID_OUTPUT_NUMERIC, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_UCD", NETSNMP_OID_OUTPUT_UCD, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NONE", NETSNMP_OID_OUTPUT_NONE, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_NUMERIC_INDEX", NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_ENUM_PRINT", NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_ESCAPE_QUOTES", NETSNMP_DS_LIB_ESCAPE_QUOTES, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_QUICK_PRINT", NETSNMP_DS_LIB_QUICK_PRINT, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_NUMERIC_TIMETICKS", NETSNMP_DS_LIB_NUMERIC_TIMETICKS, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_PRINT_HEX_TEXT", NETSNMP_DS_LIB_PRINT_HEX_TEXT, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_DONT_PRINT_UNITS", NETSNMP_DS_LIB_DONT_PRINT_UNITS, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_OUTPUT_EXTENDED_INDEX", NETSNMP_DS_LIB_EXTENDED_INDEX, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_GUESS", NETSNMP_STRING_OUTPUT_GUESS, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_ASCII", NETSNMP_STRING_OUTPUT_ASCII, CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_HEX", NETSNMP_STRING_OUTPUT_HEX, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_VALUE_LIBRARY", SNMP_VALUE_LIBRARY, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_VALUE_PLAIN", SNMP_VALUE_PLAIN, CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_VALUE_OBJECT", SNMP_VALUE_OBJECT, CONST_PERSISTENT); From c01aff8c0e466f78c91a2257977ad1bbaa67c2f2 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 10:34:55 +0800 Subject: [PATCH 09/16] Add missing breaks to switch statements --- ext/snmp/snmp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 6c8eba4afaa91..e545067fc7d04 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1542,6 +1542,7 @@ PHP_FUNCTION(snmp_set_mib_option) case NETSNMP_DS_LIB_MIB_COMMENT_TERM: case NETSNMP_DS_LIB_MIB_REPLACE: netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, a1, (int) a2); + break; default: zend_argument_value_error(1, "must be an SNMP_MIB_* constant"); RETURN_THROWS(); @@ -1563,6 +1564,7 @@ PHP_FUNCTION(snmp_set_string_output_format) case NETSNMP_STRING_OUTPUT_ASCII: case NETSNMP_STRING_OUTPUT_HEX: netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_STRING_OUTPUT_FORMAT, a1); + break; default: zend_argument_value_error(1, "must be an SNMP_STRING_OUTPUT_* constant"); RETURN_THROWS(); @@ -1590,6 +1592,7 @@ PHP_FUNCTION(snmp_set_output_option) case NETSNMP_DS_LIB_PRINT_BARE_VALUE: case NETSNMP_DS_LIB_EXTENDED_INDEX: netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, a1, (int) a2); + break; default: zend_argument_value_error(1, "must be an SNMP_OUTPUT_* constant"); RETURN_THROWS(); From 177fd23277ec52d04346847d186ab4b99f6eecfc Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 10:47:26 +0800 Subject: [PATCH 10/16] Fix the snmp_set_string_output_format function name --- ext/snmp/snmp.stub.php | 2 +- ext/snmp/snmp_arginfo.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 3664be3f0d425..356571eb40ed5 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -208,7 +208,7 @@ function snmp_set_oid_output_format(int $format): true {} function snmp_set_output_option(int $option, bool $enable): void {} -function snmp_set_string_output(int $format): void {} +function snmp_set_string_output_format(int $format): void {} /** @alias snmp_set_oid_output_format */ function snmp_set_oid_numeric_print(int $format): true {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index c055007a3a9b9..d9b9f942b9a8c 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: 0b5de7cff240601a238971eee230865017c52610 */ + * Stub hash: fb1c0abfcc7a2703d2a3e54a5ec47dfcbfcfa2e3 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -53,7 +53,7 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_output_option arginfo_snmp_set_mib_option -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_string_output, 0, 1, IS_VOID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_string_output_format, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, format, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -185,7 +185,7 @@ ZEND_FUNCTION(snmp_set_enum_print); ZEND_FUNCTION(snmp_set_mib_option); ZEND_FUNCTION(snmp_set_oid_output_format); ZEND_FUNCTION(snmp_set_output_option); -ZEND_FUNCTION(snmp_set_string_output); +ZEND_FUNCTION(snmp_set_string_output_format); ZEND_FUNCTION(snmp2_get); ZEND_FUNCTION(snmp2_getnext); ZEND_FUNCTION(snmp2_walk); @@ -222,7 +222,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_set_mib_option, arginfo_snmp_set_mib_option) ZEND_FE(snmp_set_oid_output_format, arginfo_snmp_set_oid_output_format) ZEND_FE(snmp_set_output_option, arginfo_snmp_set_output_option) - ZEND_FE(snmp_set_string_output, arginfo_snmp_set_string_output) + ZEND_FE(snmp_set_string_output_format, arginfo_snmp_set_string_output_format) ZEND_RAW_FENTRY("snmp_set_oid_numeric_print", zif_snmp_set_oid_output_format, arginfo_snmp_set_oid_numeric_print, 0, NULL, NULL) ZEND_FE(snmp2_get, arginfo_snmp2_get) ZEND_FE(snmp2_getnext, arginfo_snmp2_getnext) From 697835e1eadd9f7e1999816907442bc64ed10f97 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 11:02:07 +0800 Subject: [PATCH 11/16] Add the missing SNMP object options --- ext/snmp/snmp.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index e545067fc7d04..9915ba1159ad1 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1229,7 +1229,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp */ static void save_snmplib_output_options(php_snmp_object *snmp_object) { - // Booleans + // Booleans snmp_object->quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT); snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); snmp_object->numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); @@ -1248,7 +1248,7 @@ static void save_snmplib_output_options(php_snmp_object *snmp_object) */ static void set_snmplib_output_options(php_snmp_object *snmp_object) { - // Booleans + // Booleans netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, snmp_object->quick_print); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, snmp_object->enum_print); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, snmp_object->numeric_index); @@ -1449,7 +1449,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version) snmp_session_free(&session); } else { // Restore the snmplib output options back to the global state - set_snmplib_output_options(&glob_snmp_object); + set_snmplib_output_options(&glob_snmp_object); } } /* }}} */ @@ -1780,13 +1780,7 @@ PHP_METHOD(SNMP, __construct) } snmp_object->max_oids = 0; snmp_object->valueretrieval = SNMP_G(valueretrieval); - snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM); - snmp_object->numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); - snmp_object->numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); - snmp_object->extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); - snmp_object->dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); - 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); + save_snmplib_output_options(snmp_object); snmp_object->oid_increasing_check = true; snmp_object->exceptions_enabled = 0; } @@ -2103,6 +2097,8 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(extended_index) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dontprint_units) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(escape_quotes) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(print_hex_text) #define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \ static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \ @@ -2112,6 +2108,7 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dontprint_units) } PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(valueretrieval) +PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(string_output_format) PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(oid_output_format) PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled) @@ -2166,13 +2163,33 @@ static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \ return SUCCESS; \ } +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(quick_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(extended_index) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(dontprint_units) -PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(escape_quotes) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(print_hex_text) + +/* {{{ */ +static int php_snmp_write_string_output_format(php_snmp_object *snmp_object, zval *newval) +{ + zend_long lval = zval_get_long(newval); + + switch(lval) { + case NETSNMP_STRING_OUTPUT_GUESS: + case NETSNMP_STRING_OUTPUT_ASCII: + case NETSNMP_STRING_OUTPUT_HEX: + snmp_object->oid_output_format = lval; + return SUCCESS; + default: + zend_value_error("SNMP string output print format must be an SNMP_STRING_OUTPUT_* constant"); + return FAILURE; + } +} +/* }}} */ /* {{{ */ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval) @@ -2221,15 +2238,18 @@ static void free_php_snmp_properties(zval *el) /* {{{ */ const php_snmp_prop_handler php_snmp_property_entries[] = { PHP_SNMP_READONLY_PROPERTY_ENTRY_RECORD(info), PHP_SNMP_PROPERTY_ENTRY_RECORD(max_oids), - PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval), + PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_increasing_check), PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print), PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_index), PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_timeticks), PHP_SNMP_PROPERTY_ENTRY_RECORD(extended_index), PHP_SNMP_PROPERTY_ENTRY_RECORD(dontprint_units), + PHP_SNMP_PROPERTY_ENTRY_RECORD(escape_quotes), + PHP_SNMP_PROPERTY_ENTRY_RECORD(print_hex_text), + PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval), + PHP_SNMP_PROPERTY_ENTRY_RECORD(string_output_format), 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} }; From f82b399beb13d40bb9917526c9ef1e4759147c26 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 11:42:32 +0800 Subject: [PATCH 12/16] Add missing properties to snmp.stub.php --- ext/snmp/snmp.stub.php | 9 ++++--- ext/snmp/snmp_arginfo.h | 52 +++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 356571eb40ed5..76eaa89bed61c 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -291,14 +291,17 @@ class SNMP /** @readonly */ public array $info; public ?int $max_oids; - public int $valueretrieval; + public bool $oid_increasing_check; public bool $quick_print; public bool $enum_print; public bool $numeric_timeticks; public bool $extended_index; - public bool $dontprint_units; + public bool $dont_print_units; + public bool $escape_quotes; + public bool $print_hex_text; + public int $valueretrieval; + public int $string_output_format; public int $oid_output_format; - public bool $oid_increasing_check; public int $exceptions_enabled; public function __construct(int $version, string $hostname, string $community, int $timeout = -1, int $retries = -1) {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index d9b9f942b9a8c..dea59df0ce613 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: fb1c0abfcc7a2703d2a3e54a5ec47dfcbfcfa2e3 */ + * Stub hash: ff6206972e345da8a22b7d949a6dd4ca22bcb31d */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -383,11 +383,11 @@ static zend_class_entry *register_class_SNMP(void) zend_declare_typed_property(class_entry, property_max_oids_name, &property_max_oids_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG|MAY_BE_NULL)); zend_string_release_ex(property_max_oids_name, true); - zval property_valueretrieval_default_value; - ZVAL_UNDEF(&property_valueretrieval_default_value); - zend_string *property_valueretrieval_name = zend_string_init("valueretrieval", sizeof("valueretrieval") - 1, true); - zend_declare_typed_property(class_entry, property_valueretrieval_name, &property_valueretrieval_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); - zend_string_release_ex(property_valueretrieval_name, true); + zval property_oid_increasing_check_default_value; + ZVAL_UNDEF(&property_oid_increasing_check_default_value); + zend_string *property_oid_increasing_check_name = zend_string_init("oid_increasing_check", sizeof("oid_increasing_check") - 1, true); + zend_declare_typed_property(class_entry, property_oid_increasing_check_name, &property_oid_increasing_check_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_oid_increasing_check_name, true); zval property_quick_print_default_value; ZVAL_UNDEF(&property_quick_print_default_value); @@ -413,11 +413,35 @@ static zend_class_entry *register_class_SNMP(void) zend_declare_typed_property(class_entry, property_extended_index_name, &property_extended_index_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release_ex(property_extended_index_name, true); - zval property_dontprint_units_default_value; - ZVAL_UNDEF(&property_dontprint_units_default_value); - zend_string *property_dontprint_units_name = zend_string_init("dontprint_units", sizeof("dontprint_units") - 1, true); - zend_declare_typed_property(class_entry, property_dontprint_units_name, &property_dontprint_units_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); - zend_string_release_ex(property_dontprint_units_name, true); + zval property_dont_print_units_default_value; + ZVAL_UNDEF(&property_dont_print_units_default_value); + zend_string *property_dont_print_units_name = zend_string_init("dont_print_units", sizeof("dont_print_units") - 1, true); + zend_declare_typed_property(class_entry, property_dont_print_units_name, &property_dont_print_units_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_dont_print_units_name, true); + + zval property_escape_quotes_default_value; + ZVAL_UNDEF(&property_escape_quotes_default_value); + zend_string *property_escape_quotes_name = zend_string_init("escape_quotes", sizeof("escape_quotes") - 1, true); + zend_declare_typed_property(class_entry, property_escape_quotes_name, &property_escape_quotes_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_escape_quotes_name, true); + + zval property_print_hex_text_default_value; + ZVAL_UNDEF(&property_print_hex_text_default_value); + zend_string *property_print_hex_text_name = zend_string_init("print_hex_text", sizeof("print_hex_text") - 1, true); + zend_declare_typed_property(class_entry, property_print_hex_text_name, &property_print_hex_text_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_print_hex_text_name, true); + + zval property_valueretrieval_default_value; + ZVAL_UNDEF(&property_valueretrieval_default_value); + zend_string *property_valueretrieval_name = zend_string_init("valueretrieval", sizeof("valueretrieval") - 1, true); + zend_declare_typed_property(class_entry, property_valueretrieval_name, &property_valueretrieval_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); + zend_string_release_ex(property_valueretrieval_name, true); + + zval property_string_output_format_default_value; + ZVAL_UNDEF(&property_string_output_format_default_value); + zend_string *property_string_output_format_name = zend_string_init("string_output_format", sizeof("string_output_format") - 1, true); + zend_declare_typed_property(class_entry, property_string_output_format_name, &property_string_output_format_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); + zend_string_release_ex(property_string_output_format_name, true); zval property_oid_output_format_default_value; ZVAL_UNDEF(&property_oid_output_format_default_value); @@ -425,12 +449,6 @@ static zend_class_entry *register_class_SNMP(void) zend_declare_typed_property(class_entry, property_oid_output_format_name, &property_oid_output_format_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG)); zend_string_release_ex(property_oid_output_format_name, true); - zval property_oid_increasing_check_default_value; - ZVAL_UNDEF(&property_oid_increasing_check_default_value); - zend_string *property_oid_increasing_check_name = zend_string_init("oid_increasing_check", sizeof("oid_increasing_check") - 1, true); - zend_declare_typed_property(class_entry, property_oid_increasing_check_name, &property_oid_increasing_check_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); - zend_string_release_ex(property_oid_increasing_check_name, true); - zval property_exceptions_enabled_default_value; ZVAL_UNDEF(&property_exceptions_enabled_default_value); zend_string *property_exceptions_enabled_name = zend_string_init("exceptions_enabled", sizeof("exceptions_enabled") - 1, true); From d3958f6ba410cd9c53307ad468b8c55733c00af8 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 11:44:11 +0800 Subject: [PATCH 13/16] Fix up for dontprint_units -> dont_print_units --- ext/snmp/php_snmp.h | 2 +- ext/snmp/snmp.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index aa86ca3abff72..906fabbcc89c5 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -53,7 +53,7 @@ typedef struct _php_snmp_object { int numeric_index; int numeric_timeticks; int extended_index; - int dontprint_units; + int dont_print_units; int escape_quotes; int print_hex_text; int string_output_format; diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 9915ba1159ad1..7b1616070b123 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1235,7 +1235,7 @@ static void save_snmplib_output_options(php_snmp_object *snmp_object) snmp_object->numeric_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS); snmp_object->numeric_timeticks = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS); snmp_object->extended_index = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX); - snmp_object->dontprint_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); + snmp_object->dont_print_units = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS); snmp_object->escape_quotes = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ESCAPE_QUOTES); snmp_object->print_hex_text = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_HEX_TEXT); // Integers @@ -1254,7 +1254,7 @@ static void set_snmplib_output_options(php_snmp_object *snmp_object) netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, snmp_object->numeric_index); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, snmp_object->numeric_timeticks); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_EXTENDED_INDEX, snmp_object->extended_index); - netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, snmp_object->dontprint_units); + netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, snmp_object->dont_print_units); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_ESCAPE_QUOTES, snmp_object->escape_quotes); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_HEX_TEXT, snmp_object->print_hex_text); // Integers @@ -2096,7 +2096,7 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(extended_index) -PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dontprint_units) +PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(dont_print_units) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(escape_quotes) PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(print_hex_text) @@ -2169,7 +2169,7 @@ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_index) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(numeric_timeticks) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(extended_index) -PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(dontprint_units) +PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(dont_print_units) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(escape_quotes) PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(print_hex_text) @@ -2244,7 +2244,7 @@ const php_snmp_prop_handler php_snmp_property_entries[] = { PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_index), PHP_SNMP_PROPERTY_ENTRY_RECORD(numeric_timeticks), PHP_SNMP_PROPERTY_ENTRY_RECORD(extended_index), - PHP_SNMP_PROPERTY_ENTRY_RECORD(dontprint_units), + PHP_SNMP_PROPERTY_ENTRY_RECORD(dont_print_units), PHP_SNMP_PROPERTY_ENTRY_RECORD(escape_quotes), PHP_SNMP_PROPERTY_ENTRY_RECORD(print_hex_text), PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval), From 4cfdeb3238f594f8ef83f142f95928ce09ac6682 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 12:33:06 +0800 Subject: [PATCH 14/16] Added missing numeric_index property and fix test data --- ext/snmp/snmp.stub.php | 1 + ext/snmp/snmp_arginfo.h | 8 ++- ext/snmp/tests/snmp-object-properties.phpt | 80 ++++++++++++++-------- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 76eaa89bed61c..c64154a16f9e8 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -294,6 +294,7 @@ class SNMP public bool $oid_increasing_check; public bool $quick_print; public bool $enum_print; + public bool $numeric_index; public bool $numeric_timeticks; public bool $extended_index; public bool $dont_print_units; diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index dea59df0ce613..b8fd8a8c42209 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit snmp.stub.php instead. - * Stub hash: ff6206972e345da8a22b7d949a6dd4ca22bcb31d */ + * Stub hash: fa515fbbf73123ccee764da8bd37ca7980d3e180 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmpget, 0, 3, IS_MIXED, 0) ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) @@ -401,6 +401,12 @@ static zend_class_entry *register_class_SNMP(void) zend_declare_typed_property(class_entry, property_enum_print_name, &property_enum_print_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); zend_string_release_ex(property_enum_print_name, true); + zval property_numeric_index_default_value; + ZVAL_UNDEF(&property_numeric_index_default_value); + zend_string *property_numeric_index_name = zend_string_init("numeric_index", sizeof("numeric_index") - 1, true); + zend_declare_typed_property(class_entry, property_numeric_index_name, &property_numeric_index_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_BOOL)); + zend_string_release_ex(property_numeric_index_name, true); + zval property_numeric_timeticks_default_value; ZVAL_UNDEF(&property_numeric_timeticks_default_value); zend_string *property_numeric_timeticks_name = zend_string_init("numeric_timeticks", sizeof("numeric_timeticks") - 1, true); diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index 15f71795e3ee9..ef143d18d506b 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -92,26 +92,32 @@ object(SNMP)#%d (%d) { } ["max_oids"]=> NULL - ["valueretrieval"]=> - int(1) + ["oid_increasing_check"]=> + bool(true) ["quick_print"]=> bool(false) ["enum_print"]=> bool(false) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> bool(false) - ["dontprint_units"]=> + ["dont_print_units"]=> + bool(false) + ["escape_quotes"]=> + bool(false) + ["print_hex_text"]=> bool(false) + ["valueretrieval"]=> + int(1) + ["string_output_format"]=> + int(0) ["oid_output_format"]=> int(3) - ["oid_increasing_check"]=> - bool(true) ["exceptions_enabled"]=> int(0) - ["numeric_index"]=> - bool(false) } object(SNMP)#%d (%d) { ["info"]=> @@ -125,26 +131,32 @@ object(SNMP)#%d (%d) { } ["max_oids"]=> int(40) - ["valueretrieval"]=> - int(0) + ["oid_increasing_check"]=> + bool(false) ["quick_print"]=> bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> bool(false) - ["dontprint_units"]=> + ["dont_print_units"]=> + bool(false) + ["escape_quotes"]=> + bool(false) + ["print_hex_text"]=> bool(false) + ["valueretrieval"]=> + int(0) + ["string_output_format"]=> + int(0) ["oid_output_format"]=> int(4) - ["oid_increasing_check"]=> - bool(false) ["exceptions_enabled"]=> int(0) - ["numeric_index"]=> - bool(false) } object(SNMP)#%d (%d) { ["info"]=> @@ -158,26 +170,32 @@ object(SNMP)#%d (%d) { } ["max_oids"]=> int(40) - ["valueretrieval"]=> - int(1) + ["oid_increasing_check"]=> + bool(true) ["quick_print"]=> bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> bool(false) - ["dontprint_units"]=> + ["dont_print_units"]=> + bool(false) + ["escape_quotes"]=> + bool(false) + ["print_hex_text"]=> bool(false) + ["string_output_format"]=> + int(0) ["oid_output_format"]=> int(3) - ["oid_increasing_check"]=> - bool(true) + ["valueretrieval"]=> + int(1) ["exceptions_enabled"]=> int(0) - ["numeric_index"]=> - bool(false) } bool(true) bool(true) @@ -196,26 +214,32 @@ object(SNMP)#%d (%d) { } ["max_oids"]=> int(40) - ["valueretrieval"]=> - int(1) + ["oid_increasing_check"]=> + bool(true) ["quick_print"]=> bool(true) ["enum_print"]=> bool(true) + ["numeric_index"]=> + bool(false) ["numeric_timeticks"]=> bool(false) ["extended_index"]=> bool(false) - ["dontprint_units"]=> + ["dont_print_units"]=> + bool(false) + ["escape_quotes"]=> + bool(false) + ["print_hex_text"]=> bool(false) + ["valueretrieval"]=> + int(1) + ["string_output_format"]=> + int(0) ["oid_output_format"]=> int(3) - ["oid_increasing_check"]=> - bool(true) ["exceptions_enabled"]=> int(0) - ["numeric_index"]=> - bool(false) ["123"]=> string(11) "param_value" } From ced141073e453d0427cfbc897f9d6b42144e37ef Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 14:00:12 +0800 Subject: [PATCH 15/16] Fix test output --- ext/snmp/tests/snmp-object-properties.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index ef143d18d506b..4f8519c4f4ade 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -188,12 +188,12 @@ object(SNMP)#%d (%d) { bool(false) ["print_hex_text"]=> bool(false) + ["valueretrieval"]=> + int(1) ["string_output_format"]=> int(0) ["oid_output_format"]=> int(3) - ["valueretrieval"]=> - int(1) ["exceptions_enabled"]=> int(0) } From 05b7d79429ee92f19d706cf897946d3399e807f8 Mon Sep 17 00:00:00 2001 From: Steve Wilton Date: Fri, 27 Mar 2026 15:14:41 +0800 Subject: [PATCH 16/16] Save and restore libsnmp environment between requests --- ext/snmp/snmp.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 7b1616070b123..25ebf345a7afc 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -91,6 +91,11 @@ typedef struct snmp_session php_snmp_session; } \ } +static php_snmp_object saved_snmp_settings; +static int saved_mib_allow_underscores; +static int saved_mib_comment_term; +static int saved_mib_replace; + ZEND_DECLARE_MODULE_GLOBALS(snmp) static PHP_GINIT_FUNCTION(snmp); @@ -2316,6 +2321,36 @@ PHP_MSHUTDOWN_FUNCTION(snmp) } /* }}} */ +/* {{{ PHP_INIT_FUNCTION */ +static PHP_RINIT_FUNCTION(snmp) +{ + // Save the output options + save_snmplib_output_options(&saved_snmp_settings); + + // Save the MIB options + saved_mib_allow_underscores = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL); + saved_mib_comment_term = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_COMMENT_TERM); + saved_mib_replace = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_REPLACE); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_RSHUTDOWN_FUNCTION */ +static PHP_RSHUTDOWN_FUNCTION(snmp) +{ + // Restore the output options + set_snmplib_output_options(&saved_snmp_settings); + + // Restore MIB options + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL, saved_mib_allow_underscores); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_COMMENT_TERM, saved_mib_comment_term); + netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_REPLACE, saved_mib_replace); + + return SUCCESS; +} +/* }}} */ + /* {{{ PHP_MINFO_FUNCTION */ PHP_MINFO_FUNCTION(snmp) { @@ -2342,8 +2377,8 @@ zend_module_entry snmp_module_entry = { ext_functions, PHP_MINIT(snmp), PHP_MSHUTDOWN(snmp), - NULL, - NULL, + PHP_RINIT(snmp), + PHP_RSHUTDOWN(snmp), PHP_MINFO(snmp), PHP_SNMP_VERSION, PHP_MODULE_GLOBALS(snmp),