@@ -659,7 +659,6 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
659
659
*
660
660
* OID parser (and type, value for SNMP_SET command)
661
661
*/
662
-
663
662
static int php_snmp_parse_oid (
664
663
zval * object , int st , struct objid_query * objid_query , zend_string * oid_str , HashTable * oid_ht ,
665
664
zend_string * type_str , HashTable * type_ht , zend_string * value_str , HashTable * value_ht
@@ -676,23 +675,23 @@ static int php_snmp_parse_oid(
676
675
if (st & SNMP_CMD_SET ) {
677
676
if (type_str && value_str ) {
678
677
if (ZSTR_LEN (type_str ) != 1 ) {
679
- php_error_docref ( NULL , E_WARNING , "Bogus type '%s', should be single char, got %zu" , ZSTR_VAL ( type_str ), ZSTR_LEN ( type_str ) );
678
+ zend_value_error ( "Type must be a character" );
680
679
efree (objid_query -> vars );
681
680
return FALSE;
682
681
}
683
682
pptr = ZSTR_VAL (type_str );
684
683
objid_query -> vars [objid_query -> count ].type = * pptr ;
685
684
objid_query -> vars [objid_query -> count ].value = ZSTR_VAL (value_str );
686
685
} else {
687
- php_error_docref ( NULL , E_WARNING , "Single objid and multiple type or values are not supported " );
686
+ zend_value_error ( "Type must be a character when Object ID is a string " );
688
687
efree (objid_query -> vars );
689
688
return FALSE;
690
689
}
691
690
}
692
691
objid_query -> count ++ ;
693
692
} else if (oid_ht ) { /* we got objid array */
694
693
if (zend_hash_num_elements (oid_ht ) == 0 ) {
695
- php_error_docref ( NULL , E_WARNING , "Got empty OID array " );
694
+ zend_value_error ( "Object ID array cannot be empty " );
696
695
return FALSE;
697
696
}
698
697
objid_query -> vars = (snmpobjarg * )safe_emalloc (sizeof (snmpobjarg ), zend_hash_num_elements (oid_ht ), 0 );
@@ -715,7 +714,7 @@ static int php_snmp_parse_oid(
715
714
if (idx_type < type_ht -> nNumUsed ) {
716
715
convert_to_string_ex (tmp_type );
717
716
if (Z_STRLEN_P (tmp_type ) != 1 ) {
718
- php_error_docref ( NULL , E_WARNING , "'%s': bogus type '%s', should be single char, got %zu" , Z_STRVAL_P ( tmp_oid ), Z_STRVAL_P ( tmp_type ), Z_STRLEN_P ( tmp_type ) );
717
+ zend_value_error ( "Type must be a character" );
719
718
efree (objid_query -> vars );
720
719
return FALSE;
721
720
}
@@ -916,6 +915,7 @@ static int netsnmp_session_set_sec_level(struct snmp_session *s, char *level)
916
915
} else if (!strcasecmp (level , "authPriv" ) || !strcasecmp (level , "ap" )) {
917
916
s -> securityLevel = SNMP_SEC_LEVEL_AUTHPRIV ;
918
917
} else {
918
+ zend_value_error ("Security level must be \"noAuthNoPriv\", \"authNoPriv\", or \"authPriv\"" );
919
919
return (-1 );
920
920
}
921
921
return (0 );
@@ -933,7 +933,7 @@ static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
933
933
s -> securityAuthProto = usmHMACSHA1AuthProtocol ;
934
934
s -> securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN ;
935
935
} else {
936
- php_error_docref ( NULL , E_WARNING , "Unknown authentication protocol '%s'" , prot );
936
+ zend_value_error ( "Authentication protocol mus be either MD5 or SHA" );
937
937
return (-1 );
938
938
}
939
939
return (0 );
@@ -953,7 +953,11 @@ static int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot)
953
953
s -> securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN ;
954
954
#endif
955
955
} else {
956
- php_error_docref (NULL , E_WARNING , "Unknown security protocol '%s'" , prot );
956
+ zend_value_error ("Security protocol must be DES"
957
+ #ifdef HAVE_AES
958
+ ", AES128, or AES"
959
+ #endif
960
+ );
957
961
return (-1 );
958
962
}
959
963
return (0 );
@@ -987,7 +991,7 @@ static int netsnmp_session_gen_sec_key(struct snmp_session *s, char *pass)
987
991
(u_char * )pass , strlen (pass ),
988
992
s -> securityPrivKey , & (s -> securityPrivKeyLen )))) {
989
993
php_error_docref (NULL , E_WARNING , "Error generating a key for privacy pass phrase '%s': %s" , pass , snmp_api_errstring (snmp_errno ));
990
- return (-2 );
994
+ return (-1 );
991
995
}
992
996
return (0 );
993
997
}
@@ -1001,6 +1005,7 @@ static int netsnmp_session_set_contextEngineID(struct snmp_session *s, char * co
1001
1005
u_char * ebuf = (u_char * ) emalloc (ebuf_len );
1002
1006
1003
1007
if (!snmp_hex_to_binary (& ebuf , & ebuf_len , & eout_len , 1 , contextEngineID )) {
1008
+ // TODO Promote to Error?
1004
1009
php_error_docref (NULL , E_WARNING , "Bad engine ID value '%s'" , contextEngineID );
1005
1010
efree (ebuf );
1006
1011
return (-1 );
@@ -1023,15 +1028,15 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
1023
1028
1024
1029
/* Setting the security level. */
1025
1030
if (netsnmp_session_set_sec_level (session , sec_level )) {
1026
- php_error_docref ( NULL , E_WARNING , "Invalid security level '%s'" , sec_level );
1031
+ /* ValueError already generated, just bail out */
1027
1032
return (-1 );
1028
1033
}
1029
1034
1030
1035
if (session -> securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session -> securityLevel == SNMP_SEC_LEVEL_AUTHPRIV ) {
1031
1036
1032
1037
/* Setting the authentication protocol. */
1033
1038
if (netsnmp_session_set_auth_protocol (session , auth_protocol )) {
1034
- /* Warning message sent already, just bail out */
1039
+ /* ValueError already generated , just bail out */
1035
1040
return (-1 );
1036
1041
}
1037
1042
@@ -1044,7 +1049,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
1044
1049
if (session -> securityLevel == SNMP_SEC_LEVEL_AUTHPRIV ) {
1045
1050
/* Setting the security protocol. */
1046
1051
if (netsnmp_session_set_sec_protocol (session , priv_protocol )) {
1047
- /* Warning message sent already, just bail out */
1052
+ /* ValueError already generated , just bail out */
1048
1053
return (-1 );
1049
1054
}
1050
1055
@@ -1220,9 +1225,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1220
1225
snmp_object = Z_SNMP_P (object );
1221
1226
session = snmp_object -> session ;
1222
1227
if (!session ) {
1223
- php_error_docref (NULL , E_WARNING , "Invalid or uninitialized SNMP object" );
1228
+ zend_throw_error (NULL , "Invalid or uninitialized SNMP object" );
1224
1229
efree (objid_query .vars );
1225
- RETURN_FALSE ;
1230
+ RETURN_THROWS () ;
1226
1231
}
1227
1232
1228
1233
if (snmp_object -> max_oids > 0 ) {
@@ -1351,11 +1356,9 @@ PHP_FUNCTION(snmp_set_oid_output_format)
1351
1356
case NETSNMP_OID_OUTPUT_NONE :
1352
1357
netsnmp_ds_set_int (NETSNMP_DS_LIBRARY_ID , NETSNMP_DS_LIB_OID_OUTPUT_FORMAT , a1 );
1353
1358
RETURN_TRUE ;
1354
- break ;
1355
1359
default :
1356
- php_error_docref (NULL , E_WARNING , "Unknown SNMP output print format '%d'" , (int ) a1 );
1357
- RETURN_FALSE ;
1358
- break ;
1360
+ zend_argument_value_error (1 , "must be one of SNMP_OID_OUTPUT_*" );
1361
+ RETURN_THROWS ();
1359
1362
}
1360
1363
}
1361
1364
/* }}} */
@@ -1443,8 +1446,8 @@ PHP_FUNCTION(snmp_set_valueretrieval)
1443
1446
SNMP_G (valueretrieval ) = method ;
1444
1447
RETURN_TRUE ;
1445
1448
} else {
1446
- php_error_docref ( NULL , E_WARNING , "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'" , method );
1447
- RETURN_FALSE ;
1449
+ zend_argument_value_error ( 1 , "must be SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, or SNMP_VALUE_OBJECT" );
1450
+ RETURN_THROWS () ;
1448
1451
}
1449
1452
}
1450
1453
/* }}} */
@@ -1827,48 +1830,46 @@ PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled)
1827
1830
/* {{{ */
1828
1831
static int php_snmp_write_info (php_snmp_object * snmp_object , zval * newval )
1829
1832
{
1830
- php_error_docref (NULL , E_WARNING , "info property is read-only" );
1833
+ zend_throw_error (NULL , "info property is read-only" );
1831
1834
return FAILURE ;
1832
1835
}
1833
1836
/* }}} */
1834
1837
1835
1838
/* {{{ */
1836
1839
static int php_snmp_write_max_oids (php_snmp_object * snmp_object , zval * newval )
1837
1840
{
1838
- int ret = SUCCESS ;
1839
1841
zend_long lval ;
1840
1842
1841
1843
if (Z_TYPE_P (newval ) == IS_NULL ) {
1842
1844
snmp_object -> max_oids = 0 ;
1843
- return ret ;
1845
+ return SUCCESS ;
1844
1846
}
1845
1847
1846
1848
lval = zval_get_long (newval );
1847
1849
1848
- if (lval > 0 ) {
1849
- snmp_object -> max_oids = lval ;
1850
- } else {
1851
- php_error_docref (NULL , E_WARNING , "max_oids should be positive integer or NULL, got " ZEND_LONG_FMT , lval );
1850
+ if (lval <= 0 ) {
1851
+ zend_value_error ("max_oids must be greater than 0 or NULL" );
1852
+ return FAILURE ;
1852
1853
}
1854
+ snmp_object -> max_oids = lval ;
1853
1855
1854
- return ret ;
1856
+ return SUCCESS ;
1855
1857
}
1856
1858
/* }}} */
1857
1859
1858
1860
/* {{{ */
1859
1861
static int php_snmp_write_valueretrieval (php_snmp_object * snmp_object , zval * newval )
1860
1862
{
1861
- int ret = SUCCESS ;
1862
1863
zend_long lval = zval_get_long (newval );
1863
1864
1864
1865
if (lval >= 0 && lval <= (SNMP_VALUE_LIBRARY |SNMP_VALUE_PLAIN |SNMP_VALUE_OBJECT )) {
1865
1866
snmp_object -> valueretrieval = lval ;
1866
1867
} else {
1867
- php_error_docref ( NULL , E_WARNING , "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'" , lval );
1868
- ret = FAILURE ;
1868
+ zend_value_error ( " SNMP retrieval method must be SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, or SNMP_VALUE_OBJECT" );
1869
+ return FAILURE ;
1869
1870
}
1870
1871
1871
- return ret ;
1872
+ return SUCCESS ;
1872
1873
}
1873
1874
/* }}} */
1874
1875
@@ -1892,7 +1893,6 @@ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check)
1892
1893
/* {{{ */
1893
1894
static int php_snmp_write_oid_output_format (php_snmp_object * snmp_object , zval * newval )
1894
1895
{
1895
- int ret = SUCCESS ;
1896
1896
zend_long lval = zval_get_long (newval );
1897
1897
1898
1898
switch (lval ) {
@@ -1903,14 +1903,11 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
1903
1903
case NETSNMP_OID_OUTPUT_UCD :
1904
1904
case NETSNMP_OID_OUTPUT_NONE :
1905
1905
snmp_object -> oid_output_format = lval ;
1906
- break ;
1906
+ return SUCCESS ;
1907
1907
default :
1908
- php_error_docref (NULL , E_WARNING , "Unknown SNMP output print format '" ZEND_LONG_FMT "'" , lval );
1909
- ret = FAILURE ;
1910
- break ;
1908
+ zend_value_error ("SNMP output print format must be one of SNMP_OID_OUTPUT_*" );
1909
+ return FAILURE ;
1911
1910
}
1912
-
1913
- return ret ;
1914
1911
}
1915
1912
/* }}} */
1916
1913
0 commit comments