diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 44452369c9649..df1602ddb6de9 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1358,7 +1358,7 @@ PHP_FUNCTION(snmp_set_oid_output_format) RETURN_THROWS(); } - switch((int) a1) { + switch(a1) { case NETSNMP_OID_OUTPUT_SUFFIX: case NETSNMP_OID_OUTPUT_MODULE: case NETSNMP_OID_OUTPUT_FULL: @@ -1374,6 +1374,28 @@ PHP_FUNCTION(snmp_set_oid_output_format) } /* }}} */ +/* {{{ 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); + RETURN_TRUE; + default: + zend_argument_value_error(1, "must be an SNMP_STRING_OUTPUT_* constant"); + RETURN_THROWS(); + } +} +/* }}} */ + /* {{{ Fetch a SNMP object */ PHP_FUNCTION(snmp2_get) { @@ -2003,6 +2025,10 @@ PHP_MINIT_FUNCTION(snmp) REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_UCD", NETSNMP_OID_OUTPUT_UCD, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NONE", NETSNMP_OID_OUTPUT_NONE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_GUESS", NETSNMP_STRING_OUTPUT_GUESS, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_ASCII", NETSNMP_STRING_OUTPUT_ASCII, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_STRING_OUTPUT_HEX", NETSNMP_STRING_OUTPUT_HEX, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("SNMP_VALUE_LIBRARY", SNMP_VALUE_LIBRARY, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_VALUE_PLAIN", SNMP_VALUE_PLAIN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("SNMP_VALUE_OBJECT", SNMP_VALUE_OBJECT, CONST_CS | CONST_PERSISTENT); diff --git a/ext/snmp/snmp.stub.php b/ext/snmp/snmp.stub.php index 25ad96d033175..ae6861006ab3d 100644 --- a/ext/snmp/snmp.stub.php +++ b/ext/snmp/snmp.stub.php @@ -23,6 +23,8 @@ function snmp_set_enum_print(bool $enable): bool {} function snmp_set_oid_output_format(int $format): bool {} +function snmp_set_string_output_format(int $format): bool {} + /** @alias snmp_set_oid_output_format */ function snmp_set_oid_numeric_print(int $format): bool {} diff --git a/ext/snmp/snmp_arginfo.h b/ext/snmp/snmp_arginfo.h index 7a91113c50a1f..8176e5dcc44a7 100644 --- a/ext/snmp/snmp_arginfo.h +++ b/ext/snmp/snmp_arginfo.h @@ -48,6 +48,10 @@ ZEND_END_ARG_INFO() #define arginfo_snmp_set_oid_numeric_print arginfo_snmp_set_oid_output_format +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_snmp_set_string_output_format, 0, 1, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, format, IS_LONG, 0) +ZEND_END_ARG_INFO() + #define arginfo_snmp2_get arginfo_snmpget #define arginfo_snmp2_getnext arginfo_snmpget @@ -171,6 +175,7 @@ ZEND_FUNCTION(snmp_get_quick_print); ZEND_FUNCTION(snmp_set_quick_print); ZEND_FUNCTION(snmp_set_enum_print); ZEND_FUNCTION(snmp_set_oid_output_format); +ZEND_FUNCTION(snmp_set_string_output_format); ZEND_FUNCTION(snmp2_get); ZEND_FUNCTION(snmp2_getnext); ZEND_FUNCTION(snmp2_walk); @@ -207,6 +212,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(snmp_set_enum_print, arginfo_snmp_set_enum_print) ZEND_FE(snmp_set_oid_output_format, arginfo_snmp_set_oid_output_format) ZEND_FALIAS(snmp_set_oid_numeric_print, snmp_set_oid_output_format, arginfo_snmp_set_oid_numeric_print) + ZEND_FE(snmp_set_string_output_format, arginfo_snmp_set_string_output_format) ZEND_FE(snmp2_get, arginfo_snmp2_get) ZEND_FE(snmp2_getnext, arginfo_snmp2_getnext) ZEND_FE(snmp2_walk, arginfo_snmp2_walk) diff --git a/ext/snmp/tests/snmp_include.inc b/ext/snmp/tests/snmp_include.inc index b31384f7cf1e5..11dfaa76b9456 100644 --- a/ext/snmp/tests/snmp_include.inc +++ b/ext/snmp/tests/snmp_include.inc @@ -1,31 +1,33 @@ +--FILE-- +getMessage() . \PHP_EOL; +} + +echo "Checking working\n"; +var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_GUESS)); +var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_ASCII)); +var_dump(snmp_set_string_output_format(SNMP_STRING_OUTPUT_HEX)); +?> +--EXPECT-- +Checking error handling +snmp_set_string_output_format(): Argument #1 ($format) must be an SNMP_STRING_OUTPUT_* constant +Checking working +bool(true) +bool(true) +bool(true)