Skip to content

Commit b29bf67

Browse files
committed
ext/snmp: rename argument number variables
1 parent 555e652 commit b29bf67

1 file changed

Lines changed: 45 additions & 44 deletions

File tree

ext/snmp/snmp.c

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ static void php_free_objid_query(struct objid_query *objid_query, HashTable* oid
656656
static bool php_snmp_parse_oid(
657657
zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht,
658658
zend_string *type_str, HashTable *type_ht, zend_string *value_str, HashTable *value_ht,
659-
uint32_t oid_argument_offset, uint32_t type_argument_offset, uint32_t value_argument_offset
659+
uint32_t oid_arg_num, uint32_t type_arg_num, uint32_t value_arg_num
660660
) {
661661
char *pptr;
662662
uint32_t idx_type = 0, idx_value = 0;
@@ -683,7 +683,7 @@ static bool php_snmp_parse_oid(
683683
ZEND_ASSERT(type_str && value_str);
684684

685685
if (ZSTR_LEN(type_str) != 1) {
686-
zend_argument_value_error(type_argument_offset, "must be a single character");
686+
zend_argument_value_error(type_arg_num, "must be a single character");
687687
efree(objid_query->vars);
688688
return false;
689689
}
@@ -694,7 +694,7 @@ static bool php_snmp_parse_oid(
694694
objid_query->count++;
695695
} else if (oid_ht) { /* we got objid array */
696696
if (zend_hash_num_elements(oid_ht) == 0) {
697-
zend_argument_value_error(oid_argument_offset, "must not be empty when passed as an array");
697+
zend_argument_value_error(oid_arg_num, "must not be empty when passed as an array");
698698
return false;
699699
}
700700
objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0);
@@ -739,14 +739,14 @@ static bool php_snmp_parse_oid(
739739
char ptype = *ZSTR_VAL(type);
740740
zend_string_release(type);
741741
if (len != 1) {
742-
zend_argument_value_error(type_argument_offset, "must be a single character");
742+
zend_argument_value_error(type_arg_num, "must be a single character");
743743
php_free_objid_query(objid_query, oid_ht, value_ht, st);
744744
return false;
745745
}
746746
objid_query->vars[objid_query->count].type = ptype;
747747
idx_type++;
748748
} else {
749-
zend_argument_value_error(type_argument_offset, "must contain a type for object ID '%s'", ZSTR_VAL(tmp));
749+
zend_argument_value_error(type_arg_num, "must contain a type for object ID '%s'", ZSTR_VAL(tmp));
750750
php_free_objid_query(objid_query, oid_ht, value_ht, st);
751751
return false;
752752
}
@@ -781,7 +781,7 @@ static bool php_snmp_parse_oid(
781781
objid_query->vars[objid_query->count].value = ZSTR_VAL(tmp);
782782
idx_value++;
783783
} else {
784-
zend_argument_value_error(value_argument_offset, "must contain a value for object ID '%s'", ZSTR_VAL(tmp));
784+
zend_argument_value_error(value_arg_num, "must contain a value for object ID '%s'", ZSTR_VAL(tmp));
785785
php_free_objid_query(objid_query, oid_ht, value_ht, st);
786786
return false;
787787
}
@@ -828,7 +828,7 @@ static bool php_snmp_parse_oid(
828828
/* {{{ snmp_session_init
829829
allocates memory for session and session->peername, caller should free it manually using snmp_session_free() and efree()
830830
*/
831-
static bool snmp_session_init(php_snmp_session **session_p, int version, zend_string *hostname, zend_string *community, zend_long timeout, zend_long retries, int hostname_argument_offset, int timeout_argument_offset)
831+
static bool snmp_session_init(php_snmp_session **session_p, int version, zend_string *hostname, zend_string *community, zend_long timeout, zend_long retries, int hostname_arg_num, int timeout_arg_num)
832832
{
833833
php_snmp_session *session;
834834
char *pptr, *host_ptr;
@@ -843,23 +843,23 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
843843
ZEND_ASSERT(community != NULL);
844844

845845
if (ZSTR_LEN(hostname) >= MAX_NAME_LEN) {
846-
zend_argument_value_error(hostname_argument_offset, "length must be lower than %d", MAX_NAME_LEN);
846+
zend_argument_value_error(hostname_arg_num, "length must be lower than %d", MAX_NAME_LEN);
847847
return false;
848848
}
849849

850850
if (ZSTR_LEN(community) == 0) {
851-
zend_argument_must_not_be_empty_error(hostname_argument_offset + 1);
851+
zend_argument_must_not_be_empty_error(hostname_arg_num + 1);
852852
return false;
853853
}
854854

855-
if (timeout_argument_offset != -1) {
855+
if (timeout_arg_num != -1) {
856856
if (timeout < -1 || timeout > LONG_MAX) {
857-
zend_argument_value_error(timeout_argument_offset, "must be between -1 and %ld", LONG_MAX);
857+
zend_argument_value_error(timeout_arg_num, "must be between -1 and %ld", LONG_MAX);
858858
return false;
859859
}
860860

861861
if (retries < -1 || retries > INT_MAX) {
862-
zend_argument_value_error(timeout_argument_offset + 1, "must be between -1 and %d", INT_MAX);
862+
zend_argument_value_error(timeout_arg_num + 1, "must be between -1 and %d", INT_MAX);
863863
return false;
864864
}
865865
}
@@ -890,22 +890,22 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
890890
char *pport = pptr + 2;
891891
tmp_port = atoi(pport);
892892
if (tmp_port < 0 || tmp_port > USHRT_MAX) {
893-
zend_argument_value_error(hostname_argument_offset, "remote port must be between 0 and %u", USHRT_MAX);
893+
zend_argument_value_error(hostname_arg_num, "remote port must be between 0 and %u", USHRT_MAX);
894894
return false;
895895
}
896896
remote_port = (unsigned short)tmp_port;
897897
}
898898
*pptr = '\0';
899899
} else {
900-
zend_argument_value_error(hostname_argument_offset, "has a malformed IPv6 address, closing square bracket missing");
900+
zend_argument_value_error(hostname_arg_num, "has a malformed IPv6 address, closing square bracket missing");
901901
return false;
902902
}
903903
} else { /* IPv4 address */
904904
if ((pptr = strchr(host_ptr, ':'))) {
905905
char *pport = pptr + 1;
906906
tmp_port = atoi(pport);
907907
if (tmp_port < 0 || tmp_port > USHRT_MAX) {
908-
zend_argument_value_error(hostname_argument_offset, "remote port must be between 0 and %u", USHRT_MAX);
908+
zend_argument_value_error(hostname_arg_num, "remote port must be between 0 and %u", USHRT_MAX);
909909
return false;
910910
}
911911
remote_port = (unsigned short)tmp_port;
@@ -1114,13 +1114,13 @@ static ZEND_ATTRIBUTE_NONNULL bool snmp_session_gen_sec_key(struct snmp_session
11141114
/* }}} */
11151115

11161116
/* {{{ Set context Engine Id in the snmpv3 session */
1117-
static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string * contextEngineID, uint32_t contextEngineID_argument_offset)
1117+
static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string *contextEngineID, uint32_t context_engine_id_arg_num)
11181118
{
11191119
size_t ebuf_len = 32, eout_len = 0;
11201120
uint8_t *ebuf = (uint8_t *) emalloc(ebuf_len);
11211121

11221122
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, ZSTR_VAL(contextEngineID))) {
1123-
zend_argument_value_error(contextEngineID_argument_offset, "must be a valid context engine ID");
1123+
zend_argument_value_error(context_engine_id_arg_num, "must be a valid context engine ID");
11241124
efree(ebuf);
11251125
return false;
11261126
}
@@ -1136,13 +1136,13 @@ static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string
11361136
/* }}} */
11371137

11381138
/* {{{ Set all snmpv3-related security options
1139-
* auth_protocol_argnum and contextEngineID_argument_offset are the userland
1139+
* auth_protocol_arg_num and context_engine_id_arg_num are the userland
11401140
* argument numbers used for error reporting.
11411141
*/
11421142
static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp_session *session, zend_string *sec_level,
11431143
zend_string *auth_protocol, zend_string *auth_passphrase, zend_string *priv_protocol,
11441144
zend_string *priv_passphrase, zend_string *contextName, zend_string *contextEngineID,
1145-
uint32_t auth_protocol_argnum, uint32_t contextEngineID_argument_offset)
1145+
uint32_t auth_protocol_arg_num, uint32_t context_engine_id_arg_num)
11461146
{
11471147

11481148
/* Setting the security level. */
@@ -1154,7 +1154,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11541154
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
11551155

11561156
if (!auth_protocol) {
1157-
zend_argument_value_error(auth_protocol_argnum, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
1157+
zend_argument_value_error(auth_protocol_arg_num, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
11581158
return false;
11591159
}
11601160

@@ -1165,7 +1165,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11651165
}
11661166

11671167
if (!auth_passphrase) {
1168-
zend_argument_value_error(auth_protocol_argnum + 1, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
1168+
zend_argument_value_error(auth_protocol_arg_num + 1, "cannot be null when security level is \"authNoPriv\" or \"authPriv\"");
11691169
return false;
11701170
}
11711171

@@ -1178,7 +1178,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11781178
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
11791179

11801180
if (!priv_protocol) {
1181-
zend_argument_value_error(auth_protocol_argnum + 2, "cannot be null when security level is \"authPriv\"");
1181+
zend_argument_value_error(auth_protocol_arg_num + 2, "cannot be null when security level is \"authPriv\"");
11821182
return false;
11831183
}
11841184

@@ -1189,7 +1189,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11891189
}
11901190

11911191
if (!priv_passphrase) {
1192-
zend_argument_value_error(auth_protocol_argnum + 3, "cannot be null when security level is \"authPriv\"");
1192+
zend_argument_value_error(auth_protocol_arg_num + 3, "cannot be null when security level is \"authPriv\"");
11931193
return false;
11941194
}
11951195

@@ -1208,7 +1208,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
12081208
}
12091209

12101210
/* Setting contextEngineIS if specified */
1211-
if (contextEngineID && ZSTR_LEN(contextEngineID) && !snmp_session_set_contextEngineID(session, contextEngineID, contextEngineID_argument_offset)) {
1211+
if (contextEngineID && ZSTR_LEN(contextEngineID) && !snmp_session_set_contextEngineID(session, contextEngineID, context_engine_id_arg_num)) {
12121212
/* Warning message sent already, just bail out */
12131213
return false;
12141214
}
@@ -1235,8 +1235,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12351235
struct objid_query objid_query;
12361236
php_snmp_session *session;
12371237
int session_less_mode = (getThis() == NULL);
1238-
int timeout_argument_offset = -1;
1239-
uint32_t oid_argument_offset = 1, type_argument_offset = 0, value_argument_offset = 0;
1238+
int timeout_arg_num = -1;
1239+
uint32_t oid_arg_num = 1, type_arg_num = 0, value_arg_num = 0;
12401240
php_snmp_object *snmp_object;
12411241
php_snmp_object glob_snmp_object;
12421242

@@ -1264,10 +1264,10 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12641264
Z_PARAM_LONG(retries)
12651265
ZEND_PARSE_PARAMETERS_END();
12661266

1267-
timeout_argument_offset = 10;
1268-
oid_argument_offset = 8;
1269-
type_argument_offset = 9;
1270-
value_argument_offset = 10;
1267+
timeout_arg_num = 10;
1268+
oid_arg_num = 8;
1269+
type_arg_num = 9;
1270+
value_arg_num = 10;
12711271
} else {
12721272
/* SNMP_CMD_GET
12731273
* SNMP_CMD_GETNEXT
@@ -1287,8 +1287,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12871287
Z_PARAM_LONG(retries)
12881288
ZEND_PARSE_PARAMETERS_END();
12891289

1290-
timeout_argument_offset = 9;
1291-
oid_argument_offset = 8;
1290+
timeout_arg_num = 9;
1291+
oid_arg_num = 8;
12921292
}
12931293
} else {
12941294
if (st & SNMP_CMD_SET) {
@@ -1303,10 +1303,10 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13031303
Z_PARAM_LONG(retries)
13041304
ZEND_PARSE_PARAMETERS_END();
13051305

1306-
timeout_argument_offset = 6;
1307-
oid_argument_offset = 3;
1308-
type_argument_offset = 4;
1309-
value_argument_offset = 5;
1306+
timeout_arg_num = 6;
1307+
oid_arg_num = 3;
1308+
type_arg_num = 4;
1309+
value_arg_num = 5;
13101310
} else {
13111311
/* SNMP_CMD_GET
13121312
* SNMP_CMD_GETNEXT
@@ -1321,8 +1321,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13211321
Z_PARAM_LONG(retries)
13221322
ZEND_PARSE_PARAMETERS_END();
13231323

1324-
timeout_argument_offset = 4;
1325-
oid_argument_offset = 3;
1324+
timeout_arg_num = 4;
1325+
oid_arg_num = 3;
13261326
}
13271327
}
13281328
} else {
@@ -1332,8 +1332,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13321332
Z_PARAM_ARRAY_HT_OR_STR(type_ht, type_str)
13331333
Z_PARAM_ARRAY_HT_OR_STR(value_ht, value_str)
13341334
ZEND_PARSE_PARAMETERS_END();
1335-
type_argument_offset = 2;
1336-
value_argument_offset = 3;
1335+
type_arg_num = 2;
1336+
value_arg_num = 3;
13371337
} else if (st & SNMP_CMD_WALK) {
13381338
ZEND_PARSE_PARAMETERS_START(1, 4)
13391339
Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
@@ -1364,12 +1364,12 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13641364
}
13651365

13661366
if (!php_snmp_parse_oid(getThis(), st, &objid_query, oid_str, oid_ht, type_str, type_ht, value_str, value_ht,
1367-
oid_argument_offset, type_argument_offset, value_argument_offset)) {
1367+
oid_arg_num, type_arg_num, value_arg_num)) {
13681368
RETURN_FALSE;
13691369
}
13701370

13711371
if (session_less_mode) {
1372-
if (!snmp_session_init(&session, version, a1, a2, timeout, retries, 1, timeout_argument_offset)) {
1372+
if (!snmp_session_init(&session, version, a1, a2, timeout, retries, 1, timeout_arg_num)) {
13731373
php_free_objid_query(&objid_query, oid_ht, value_ht, st);
13741374
snmp_session_free(&session);
13751375
RETURN_FALSE;
@@ -1732,6 +1732,8 @@ PHP_METHOD(SNMP, setSecurity)
17321732
php_snmp_object *snmp_object;
17331733
zval *object = ZEND_THIS;
17341734
zend_string *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL, *a7 = NULL;
1735+
uint32_t auth_protocol_arg_num = 2;
1736+
uint32_t context_engine_id_arg_num = 7;
17351737

17361738
snmp_object = Z_SNMP_P(object);
17371739
if (!snmp_object->session) {
@@ -1743,8 +1745,7 @@ PHP_METHOD(SNMP, setSecurity)
17431745
RETURN_THROWS();
17441746
}
17451747

1746-
/* authProtocol is argument #2 and contextEngineId is argument #7. */
1747-
if (!snmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7, 2, 7)) {
1748+
if (!snmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7, auth_protocol_arg_num, context_engine_id_arg_num)) {
17481749
/* An error has already been emitted, just bail out. */
17491750
RETURN_FALSE;
17501751
}

0 commit comments

Comments
 (0)