diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h index ce9849588b19e..906fabbcc89c5 100644 --- a/ext/snmp/php_snmp.h +++ b/ext/snmp/php_snmp.h @@ -50,6 +50,13 @@ typedef struct _php_snmp_object { int valueretrieval; int quick_print; int enum_print; + int numeric_index; + int numeric_timeticks; + int extended_index; + int dont_print_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 d116339dd1f40..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); @@ -1224,6 +1229,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->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 + 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->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 + 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,12 +1436,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.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) { @@ -1412,9 +1453,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_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); } } /* }}} */ @@ -1493,6 +1533,78 @@ PHP_FUNCTION(snmp_set_enum_print) } /* }}} */ +/* {{{ Set walk option. */ +PHP_FUNCTION(snmp_set_mib_option) +{ + zend_long a1, a2; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &a1, &a2) == 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); + break; + default: + zend_argument_value_error(1, "must be an SNMP_MIB_* constant"); + RETURN_THROWS(); + } +} +/* }}} */ + +/* {{{ Set the string output format. */ +PHP_FUNCTION(snmp_set_string_output_format) +{ + zend_long a1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &a1) == FAILURE) { + RETURN_THROWS(); + } + + 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); + break; + default: + zend_argument_value_error(1, "must be an SNMP_STRING_OUTPUT_* constant"); + RETURN_THROWS(); + } +} +/* }}} */ + +/* {{{ Set output format option. */ +PHP_FUNCTION(snmp_set_output_option) +{ + zend_long a1, a2; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lb", &a1, &a2) == FAILURE) { + RETURN_THROWS(); + } + + 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); + break; + default: + zend_argument_value_error(1, "must be an SNMP_OUTPUT_* constant"); + RETURN_THROWS(); + } +} +/* }}} */ + /* {{{ Set the OID output format. */ PHP_FUNCTION(snmp_set_oid_output_format) { @@ -1673,9 +1785,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->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; } @@ -1988,6 +2098,12 @@ 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(dont_print_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) \ @@ -1997,6 +2113,7 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print) } 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) @@ -2051,9 +2168,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(oid_increasing_check) +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(dont_print_units) +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) @@ -2102,11 +2243,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(dont_print_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} }; @@ -2173,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) { @@ -2199,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), diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 0a303aea77ff0..c64154a16f9e8 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,8 +202,14 @@ function snmp_set_quick_print(bool $enable): true {} function snmp_set_enum_print(bool $enable): true {} +function snmp_set_mib_option(int $option, bool $enable): void {} + function snmp_set_oid_output_format(int $format): true {} +function snmp_set_output_option(int $option, bool $enable): 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 {} @@ -212,11 +291,18 @@ 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_index; + public bool $numeric_timeticks; + public bool $extended_index; + 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 1ee821f0538da..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: e2451ac3ea0fa5eb1158e8b7252e61c6794d514f */ + * 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) @@ -42,10 +42,21 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_enum_print 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() + 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_output_option arginfo_snmp_set_mib_option + +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() + #define arginfo_snmp_set_oid_numeric_print arginfo_snmp_set_oid_output_format #define arginfo_snmp2_get arginfo_snmpget @@ -171,7 +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_mib_option); ZEND_FUNCTION(snmp_set_oid_output_format); +ZEND_FUNCTION(snmp_set_output_option); +ZEND_FUNCTION(snmp_set_string_output_format); ZEND_FUNCTION(snmp2_get); ZEND_FUNCTION(snmp2_getnext); ZEND_FUNCTION(snmp2_walk); @@ -205,7 +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_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_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) @@ -238,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); @@ -352,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); @@ -370,18 +401,60 @@ 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); + 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_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); zend_string *property_oid_output_format_name = zend_string_init("oid_output_format", sizeof("oid_output_format") - 1, true); 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); diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt index a8fccd406b7e3..4f8519c4f4ade 100644 --- a/ext/snmp/tests/snmp-object-properties.phpt +++ b/ext/snmp/tests/snmp-object-properties.phpt @@ -92,16 +92,30 @@ 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) + ["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) } @@ -117,16 +131,30 @@ 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) + ["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) } @@ -142,16 +170,30 @@ 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) + ["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) } @@ -172,16 +214,30 @@ 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) + ["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) ["123"]=>