summaryrefslogtreecommitdiff
path: root/ext/snmp
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2014-05-20 17:02:29 +0800
committerXinchen Hui <laruence@php.net>2014-05-20 17:02:29 +0800
commitb36afe8dd330039685b2b74e13e385353d662cfc (patch)
tree404b0f394d48d422d977906a4f934c12b6cd2fc9 /ext/snmp
parentf2028491aa44367dbf77cc1008e9e4b027f60666 (diff)
downloadphp-git-b36afe8dd330039685b2b74e13e385353d662cfc.tar.gz
Refactoring ext/snmp
Diffstat (limited to 'ext/snmp')
-rw-r--r--ext/snmp/php_snmp.h9
-rw-r--r--ext/snmp/snmp.c395
2 files changed, 194 insertions, 210 deletions
diff --git a/ext/snmp/php_snmp.h b/ext/snmp/php_snmp.h
index 09ab8b9e81..50bd272204 100644
--- a/ext/snmp/php_snmp.h
+++ b/ext/snmp/php_snmp.h
@@ -85,7 +85,6 @@ PHP_METHOD(SNMP, getErrno);
PHP_METHOD(SNMP, getError);
typedef struct _php_snmp_object {
- zend_object zo;
struct snmp_session *session;
int max_oids;
int valueretrieval;
@@ -96,10 +95,16 @@ typedef struct _php_snmp_object {
int oid_increasing_check;
int exceptions_enabled;
char snmp_errstr[256];
+ zend_object zo;
} php_snmp_object;
+static inline php_snmp_object *php_snmp_fetch_object(zend_object *obj) {
+ return (php_snmp_object *)((char*)(obj) - XtOffsetOf(php_snmp_object, zo));
+}
+
+#define Z_SNMP_P(zv) php_snmp_fetch_object(Z_OBJ_P((zv)))
-typedef int (*php_snmp_read_t)(php_snmp_object *snmp_object, zval **retval TSRMLS_DC);
+typedef int (*php_snmp_read_t)(php_snmp_object *snmp_object, zval *retval TSRMLS_DC);
typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval TSRMLS_DC);
typedef struct _ptp_snmp_prop_handler {
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 8b6afdee3a..3fa7583031 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -454,7 +454,7 @@ static PHP_GINIT_FUNCTION(snmp)
} \
}
-static void netsnmp_session_free(php_snmp_session **session)
+static void netsnmp_session_free(php_snmp_session **session) /* {{{ */
{
if (*session) {
PHP_SNMP_SESSION_FREE(peername);
@@ -465,16 +465,18 @@ static void netsnmp_session_free(php_snmp_session **session)
*session = NULL;
}
}
+/* }}} */
-static void php_snmp_session_destructor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
+static void php_snmp_session_destructor(zend_resource *rsrc TSRMLS_DC) /* {{{ */
{
php_snmp_session *session = (php_snmp_session *)rsrc->ptr;
netsnmp_session_free(&session);
}
+/* }}} */
-static void php_snmp_object_free_storage(void *object TSRMLS_DC)
+static void php_snmp_object_free_storage(zend_object *object TSRMLS_DC) /* {{{ */
{
- php_snmp_object *intern = (php_snmp_object *)object;
+ php_snmp_object *intern = php_snmp_fetch_object(object);
if (!intern) {
return;
@@ -483,28 +485,25 @@ static void php_snmp_object_free_storage(void *object TSRMLS_DC)
netsnmp_session_free(&(intern->session));
zend_object_std_dtor(&intern->zo TSRMLS_CC);
-
- efree(intern);
}
+/* }}} */
-static zend_object_value php_snmp_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
+static zend_object *php_snmp_object_new(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
{
- zend_object_value retval;
php_snmp_object *intern;
/* Allocate memory for it */
- intern = emalloc(sizeof(php_snmp_object));
- memset(&intern->zo, 0, sizeof(php_snmp_object));
+ intern = ecalloc(1, sizeof(php_snmp_object) + sizeof(zval) * (class_type->default_properties_count - 1));
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
object_properties_init(&intern->zo, class_type);
- retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) php_snmp_object_free_storage, NULL TSRMLS_CC);
- retval.handlers = (zend_object_handlers *) &php_snmp_object_handlers;
+ intern->zo.handlers = &php_snmp_object_handlers;
- return retval;
+ return &intern->zo;
}
+/* }}} */
/* {{{ php_snmp_error
*
@@ -517,7 +516,7 @@ static void php_snmp_error(zval *object, const char *docref TSRMLS_DC, int type,
php_snmp_object *snmp_object = NULL;
if (object) {
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
if (type == PHP_SNMP_ERRNO_NOERROR) {
memset(snmp_object->snmp_errstr, 0, sizeof(snmp_object->snmp_errstr));
} else {
@@ -550,7 +549,7 @@ static void php_snmp_error(zval *object, const char *docref TSRMLS_DC, int type,
*/
static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_DC, int valueretrieval)
{
- zval *val;
+ zval val;
char sbuf[512];
char *buf = &(sbuf[0]);
char *dbuf = (char *)NULL;
@@ -601,27 +600,25 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
}
}
- MAKE_STD_ZVAL(val);
-
if (valueretrieval & SNMP_VALUE_PLAIN) {
*buf = 0;
switch (vars->type) {
case ASN_BIT_STR: /* 0x03, asn1.h */
- ZVAL_STRINGL(val, (char *)vars->val.bitstring, vars->val_len, 1);
+ ZVAL_STRINGL(&val, (char *)vars->val.bitstring, vars->val_len);
break;
case ASN_OCTET_STR: /* 0x04, asn1.h */
case ASN_OPAQUE: /* 0x44, snmp_impl.h */
- ZVAL_STRINGL(val, (char *)vars->val.string, vars->val_len, 1);
+ ZVAL_STRINGL(&val, (char *)vars->val.string, vars->val_len);
break;
case ASN_NULL: /* 0x05, asn1.h */
- ZVAL_NULL(val);
+ ZVAL_NULL(&val);
break;
case ASN_OBJECT_ID: /* 0x06, asn1.h */
snprint_objid(buf, buflen, vars->val.objid, vars->val_len / sizeof(oid));
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_IPADDRESS: /* 0x40, snmp_impl.h */
@@ -629,7 +626,7 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
(vars->val.string)[0], (vars->val.string)[1],
(vars->val.string)[2], (vars->val.string)[3]);
buf[buflen]=0;
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_COUNTER: /* 0x41, snmp_impl.h */
@@ -639,59 +636,58 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_D
case ASN_UINTEGER: /* 0x47, snmp_impl.h */
snprintf(buf, buflen, "%lu", *vars->val.integer);
buf[buflen]=0;
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_INTEGER: /* 0x02, asn1.h */
snprintf(buf, buflen, "%ld", *vars->val.integer);
buf[buflen]=0;
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
#if defined(NETSNMP_WITH_OPAQUE_SPECIAL_TYPES) || defined(OPAQUE_SPECIAL_TYPES)
case ASN_OPAQUE_FLOAT: /* 0x78, asn1.h */
snprintf(buf, buflen, "%f", *vars->val.floatVal);
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_OPAQUE_DOUBLE: /* 0x79, asn1.h */
snprintf(buf, buflen, "%Lf", *vars->val.doubleVal);
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_OPAQUE_I64: /* 0x80, asn1.h */
printI64(buf, vars->val.counter64);
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
case ASN_OPAQUE_U64: /* 0x81, asn1.h */
#endif
case ASN_COUNTER64: /* 0x46, snmp_impl.h */
printU64(buf, vars->val.counter64);
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
break;
default:
- ZVAL_STRING(val, "Unknown value type", 1);
+ ZVAL_STRING(&val, "Unknown value type");
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value type: %u", vars->type);
break;
}
} else /* use Net-SNMP value translation */ {
/* we have desired string in buffer, just use it */
- ZVAL_STRING(val, buf, 1);
+ ZVAL_STRING(&val, buf);
}
if (valueretrieval & SNMP_VALUE_OBJECT) {
object_init(snmpval);
add_property_long(snmpval, "type", vars->type);
- add_property_zval(snmpval, "value", val);
+ add_property_zval(snmpval, "value", &val);
} else {
- *snmpval = *val;
- zval_copy_ctor(snmpval);
+ ZVAL_COPY(snmpval, &val);
}
zval_ptr_dtor(&val);
- if(dbuf){ /* malloc was used to store value */
+ if (dbuf){ /* malloc was used to store value */
efree(dbuf);
}
}
@@ -716,7 +712,7 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
char buf2[2048];
int keepwalking=1;
char *err;
- zval *snmpval = NULL;
+ zval snmpval;
int snmp_errno;
/* we start with retval=FALSE. If any actual data is acquired, retval will be set to appropriate type */
@@ -831,15 +827,15 @@ retry:
break;
}
- MAKE_STD_ZVAL(snmpval);
- php_snmp_getvalue(vars, snmpval TSRMLS_CC, objid_query->valueretrieval);
+ ZVAL_NULL(&snmpval);
+ php_snmp_getvalue(vars, &snmpval TSRMLS_CC, objid_query->valueretrieval);
if (objid_query->array_output) {
- if (Z_TYPE_P(return_value) == IS_BOOL) {
+ if (Z_TYPE_P(return_value) == IS_TRUE || Z_TYPE_P(return_value) == IS_FALSE) {
array_init(return_value);
}
if (st & SNMP_NUMERIC_KEYS) {
- add_next_index_zval(return_value, snmpval);
+ add_next_index_zval(return_value, &snmpval);
} else if (st & SNMP_ORIGINAL_NAMES_AS_KEYS && st & SNMP_CMD_GET) {
found = 0;
for (count = 0; count < objid_query->count; count++) {
@@ -850,7 +846,7 @@ retry:
}
}
if (found) {
- add_assoc_zval(return_value, objid_query->vars[count].oid, snmpval);
+ add_assoc_zval(return_value, objid_query->vars[count].oid, &snmpval);
} else {
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not find original OID name for '%s'", buf2);
@@ -867,15 +863,13 @@ retry:
}
buf2[strlen(buf2) - 1] = '\0'; /* remove trailing '.' */
}
- add_assoc_zval(return_value, buf2, snmpval);
+ add_assoc_zval(return_value, buf2, &snmpval);
} else {
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
- add_assoc_zval(return_value, buf2, snmpval);
+ add_assoc_zval(return_value, buf2, &snmpval);
}
} else {
- *return_value = *snmpval;
- zval_copy_ctor(return_value);
- zval_ptr_dtor(&snmpval);
+ ZVAL_COPY_VALUE(return_value, &snmpval);
break;
}
@@ -902,8 +896,8 @@ retry:
keepwalking = 1;
continue;
}
- if (!(st & SNMP_CMD_WALK) || response->errstat != SNMP_ERR_NOSUCHNAME || Z_TYPE_P(return_value) == IS_BOOL) {
- for ( count=1, vars = response->variables;
+ if (!(st & SNMP_CMD_WALK) || response->errstat != SNMP_ERR_NOSUCHNAME || Z_TYPE_P(return_value) == IS_TRUE || Z_TYPE_P(return_value) == IS_FALSE) {
+ for (count=1, vars = response->variables;
vars && count != response->errindex;
vars = vars->next_variable, count++);
@@ -929,7 +923,7 @@ retry:
snmp_free_pdu(response);
snmp_close(ss);
if (objid_query->array_output) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
}
RETVAL_FALSE;
return;
@@ -938,7 +932,7 @@ retry:
} else if (status == STAT_TIMEOUT) {
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_TIMEOUT, "No response from %s", session->peername);
if (objid_query->array_output) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
}
snmp_close(ss);
RETVAL_FALSE;
@@ -948,7 +942,7 @@ retry:
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_GENERIC, "Fatal error: %s", err);
free(err);
if (objid_query->array_output) {
- zval_dtor(return_value);
+ zval_ptr_dtor(return_value);
}
snmp_close(ss);
RETVAL_FALSE;
@@ -967,61 +961,67 @@ retry:
* OID parser (and type, value for SNMP_SET command)
*/
-static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_query, zval **oid, zval **type, zval **value TSRMLS_DC)
+static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_query, zval *oid, zval *type, zval *value TSRMLS_DC)
{
char *pptr;
HashPosition pos_oid, pos_type, pos_value;
- zval **tmp_oid, **tmp_type, **tmp_value;
+ zval *tmp_oid, *tmp_type, *tmp_value;
- if (Z_TYPE_PP(oid) != IS_ARRAY) {
+ if (Z_TYPE_P(oid) != IS_ARRAY) {
+ /*
if (Z_ISREF_PP(oid)) {
SEPARATE_ZVAL(oid);
}
+ */
convert_to_string_ex(oid);
- } else if (Z_TYPE_PP(oid) == IS_ARRAY) {
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
+ } else if (Z_TYPE_P(oid) == IS_ARRAY) {
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
}
if (st & SNMP_CMD_SET) {
- if (Z_TYPE_PP(type) != IS_ARRAY) {
+ if (Z_TYPE_P(type) != IS_ARRAY) {
+ /*
if (Z_ISREF_PP(type)) {
SEPARATE_ZVAL(type);
}
+ */
convert_to_string_ex(type);
- } else if (Z_TYPE_PP(type) == IS_ARRAY) {
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(type), &pos_type);
+ } else if (Z_TYPE_P(type) == IS_ARRAY) {
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(type), &pos_type);
}
- if (Z_TYPE_PP(value) != IS_ARRAY) {
+ if (Z_TYPE_P(value) != IS_ARRAY) {
+ /*
if (Z_ISREF_PP(value)) {
SEPARATE_ZVAL(value);
}
+ */
convert_to_string_ex(value);
- } else if (Z_TYPE_PP(value) == IS_ARRAY) {
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(value), &pos_value);
+ } else if (Z_TYPE_P(value) == IS_ARRAY) {
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(value), &pos_value);
}
}
objid_query->count = 0;
objid_query->array_output = ((st & SNMP_CMD_WALK) ? TRUE : FALSE);
- if (Z_TYPE_PP(oid) == IS_STRING) {
+ if (Z_TYPE_P(oid) == IS_STRING) {
objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
if (objid_query->vars == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid: %s", strerror(errno));
efree(objid_query->vars);
return FALSE;
}
- objid_query->vars[objid_query->count].oid = Z_STRVAL_PP(oid);
+ objid_query->vars[objid_query->count].oid = Z_STRVAL_P(oid);
if (st & SNMP_CMD_SET) {
- if (Z_TYPE_PP(type) == IS_STRING && Z_TYPE_PP(value) == IS_STRING) {
- if (Z_STRLEN_PP(type) != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bogus type '%s', should be single char, got %u", Z_STRVAL_PP(type), Z_STRLEN_PP(type));
+ if (Z_TYPE_P(type) == IS_STRING && Z_TYPE_P(value) == IS_STRING) {
+ if (Z_STRLEN_P(type) != 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bogus type '%s', should be single char, got %u", Z_STRVAL_P(type), Z_STRLEN_P(type));
efree(objid_query->vars);
return FALSE;
}
- pptr = Z_STRVAL_PP(type);
+ pptr = Z_STRVAL_P(type);
objid_query->vars[objid_query->count].type = *pptr;
- objid_query->vars[objid_query->count].value = Z_STRVAL_PP(value);
+ objid_query->vars[objid_query->count].value = Z_STRVAL_P(value);
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Single objid and multiple type or values are not supported");
efree(objid_query->vars);
@@ -1029,55 +1029,55 @@ static int php_snmp_parse_oid(zval *object, int st, struct objid_query *objid_qu
}
}
objid_query->count++;
- } else if (Z_TYPE_PP(oid) == IS_ARRAY) { /* we got objid array */
- if (zend_hash_num_elements(Z_ARRVAL_PP(oid)) == 0) {
+ } else if (Z_TYPE_P(oid) == IS_ARRAY) { /* we got objid array */
+ if (zend_hash_num_elements(Z_ARRVAL_P(oid)) == 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got empty OID array");
return FALSE;
}
- objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg) * zend_hash_num_elements(Z_ARRVAL_PP(oid)));
+ objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg) * zend_hash_num_elements(Z_ARRVAL_P(oid)));
if (objid_query->vars == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid array: %s", strerror(errno));
efree(objid_query->vars);
return FALSE;
}
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
- for ( zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(oid), (void **) &tmp_oid, &pos_oid) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(oid), &pos_oid) ) {
+ for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
+ (tmp_oid = zend_hash_get_current_data_ex(Z_ARRVAL_P(oid), &pos_oid)) != NULL;
+ zend_hash_move_forward_ex(Z_ARRVAL_P(oid), &pos_oid) ) {
convert_to_string_ex(tmp_oid);
- objid_query->vars[objid_query->count].oid = Z_STRVAL_PP(tmp_oid);
+ objid_query->vars[objid_query->count].oid = Z_STRVAL_P(tmp_oid);
if (st & SNMP_CMD_SET) {
- if (Z_TYPE_PP(type) == IS_STRING) {
- pptr = Z_STRVAL_PP(type);
+ if (Z_TYPE_P(type) == IS_STRING) {
+ pptr = Z_STRVAL_P(type);
objid_query->vars[objid_query->count].type = *pptr;
- } else if (Z_TYPE_PP(type) == IS_ARRAY) {
- if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(type), (void **) &tmp_type, &pos_type)) {
+ } else if (Z_TYPE_P(type) == IS_ARRAY) {
+ if ((tmp_type = zend_hash_get_current_data_ex(Z_ARRVAL_P(type), &pos_type)) != NULL) {
convert_to_string_ex(tmp_type);
- if (Z_STRLEN_PP(tmp_type) != 1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': bogus type '%s', should be single char, got %u", Z_STRVAL_PP(tmp_oid), Z_STRVAL_PP(tmp_type), Z_STRLEN_PP(tmp_type));
+ if (Z_STRLEN_P(tmp_type) != 1) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': bogus type '%s', should be single char, got %u", Z_STRVAL_P(tmp_oid), Z_STRVAL_P(tmp_type), Z_STRLEN_P(tmp_type));
efree(objid_query->vars);
return FALSE;
}
- pptr = Z_STRVAL_PP(tmp_type);
+ pptr = Z_STRVAL_P(tmp_type);
objid_query->vars[objid_query->count].type = *pptr;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(type), &pos_type);
+ zend_hash_move_forward_ex(Z_ARRVAL_P(type), &pos_type);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no type set", Z_STRVAL_PP(tmp_oid));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no type set", Z_STRVAL_P(tmp_oid));
efree(objid_query->vars);
return FALSE;
}
}
- if (Z_TYPE_PP(value) == IS_STRING) {
- objid_query->vars[objid_query->count].value = Z_STRVAL_PP(value);
- } else if (Z_TYPE_PP(value) == IS_ARRAY) {
- if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(value), (void **) &tmp_value, &pos_value)) {
+ if (Z_TYPE_P(value) == IS_STRING) {
+ objid_query->vars[objid_query->count].value = Z_STRVAL_P(value);
+ } else if (Z_TYPE_P(value) == IS_ARRAY) {
+ if ((tmp_value = zend_hash_get_current_data_ex(Z_ARRVAL_P(value), &pos_value)) != NULL) {
convert_to_string_ex(tmp_value);
- objid_query->vars[objid_query->count].value = Z_STRVAL_PP(tmp_value);
- zend_hash_move_forward_ex(Z_ARRVAL_PP(value), &pos_value);
+ objid_query->vars[objid_query->count].value = Z_STRVAL_P(tmp_value);
+ zend_hash_move_forward_ex(Z_ARRVAL_P(value), &pos_value);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no value set", Z_STRVAL_PP(tmp_oid));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s': no value set", Z_STRVAL_P(tmp_oid));
efree(objid_query->vars);
return FALSE;
}
@@ -1425,7 +1425,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
*/
static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
{
- zval **oid, **value, **type;
+ zval *oid, *value, *type;
char *a1, *a2, *a3, *a4, *a5, *a6, *a7;
int a1_len, a2_len, a3_len, a4_len, a5_len, a6_len, a7_len;
zend_bool use_orignames = 0, suffix_keys = 0;
@@ -1446,7 +1446,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
if (session_less_mode) {
if (version == SNMP_VERSION_3) {
if (st & SNMP_CMD_SET) {
- if (zend_parse_parameters(argc TSRMLS_CC, "sssssssZZZ|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
+ if (zend_parse_parameters(argc TSRMLS_CC, "ssssssszzz|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
RETURN_FALSE;
}
@@ -1455,14 +1455,14 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
* SNMP_CMD_GETNEXT
* SNMP_CMD_WALK
*/
- if (zend_parse_parameters(argc TSRMLS_CC, "sssssssZ|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
+ if (zend_parse_parameters(argc TSRMLS_CC, "sssssssz|ll", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &timeout, &retries) == FAILURE) {
RETURN_FALSE;
}
}
} else {
if (st & SNMP_CMD_SET) {
- if (zend_parse_parameters(argc TSRMLS_CC, "ssZZZ|ll", &a1, &a1_len, &a2, &a2_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "sszzz|ll", &a1, &a1_len, &a2, &a2_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
RETURN_FALSE;
}
} else {
@@ -1470,25 +1470,25 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
* SNMP_CMD_GETNEXT
* SNMP_CMD_WALK
*/
- if (zend_parse_parameters(argc TSRMLS_CC, "ssZ|ll", &a1, &a1_len, &a2, &a2_len, &oid, &timeout, &retries) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "ssz|ll", &a1, &a1_len, &a2, &a2_len, &oid, &timeout, &retries) == FAILURE) {
RETURN_FALSE;
}
}
}
} else {
if (st & SNMP_CMD_SET) {
- if (zend_parse_parameters(argc TSRMLS_CC, "ZZZ", &oid, &type, &value) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "zzz", &oid, &type, &value) == FAILURE) {
RETURN_FALSE;
}
} else if (st & SNMP_CMD_WALK) {
- if (zend_parse_parameters(argc TSRMLS_CC, "Z|bll", &oid, &suffix_keys, &(objid_query.max_repetitions), &(objid_query.non_repeaters)) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "z|bll", &oid, &suffix_keys, &(objid_query.max_repetitions), &(objid_query.non_repeaters)) == FAILURE) {
RETURN_FALSE;
}
if (suffix_keys) {
st |= SNMP_USE_SUFFIX_AS_KEYS;
}
} else if (st & SNMP_CMD_GET) {
- if (zend_parse_parameters(argc TSRMLS_CC, "Z|b", &oid, &use_orignames) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "z|b", &oid, &use_orignames) == FAILURE) {
RETURN_FALSE;
}
if (use_orignames) {
@@ -1497,7 +1497,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
} else {
/* SNMP_CMD_GETNEXT
*/
- if (zend_parse_parameters(argc TSRMLS_CC, "Z", &oid) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "z", &oid) == FAILURE) {
RETURN_FALSE;
}
}
@@ -1521,7 +1521,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
}
} else {
zval *object = getThis();
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
session = snmp_object->session;
if (!session) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or uninitialized SNMP object");
@@ -1819,7 +1819,7 @@ PHP_METHOD(snmp, __construct)
int argc = ZEND_NUM_ARGS();
zend_error_handling error_handling;
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
if (zend_parse_parameters(argc TSRMLS_CC, "lss|ll", &version, &a1, &a1_len, &a2, &a2_len, &timeout, &retries) == FAILURE) {
@@ -1864,7 +1864,7 @@ PHP_METHOD(snmp, close)
php_snmp_object *snmp_object;
zval *object = getThis();
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
if (zend_parse_parameters_none() == FAILURE) {
RETURN_FALSE;
@@ -1906,6 +1906,7 @@ PHP_METHOD(snmp, set)
{
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, (-1));
}
+/* }}} */
/* {{{ proto bool SNMP::setSecurity(string sec_level, [ string auth_protocol, string auth_passphrase [, string priv_protocol, string priv_passphrase [, string contextName [, string contextEngineID]]]])
Set SNMPv3 security-related session parameters */
@@ -1917,7 +1918,7 @@ PHP_METHOD(snmp, setSecurity)
int a1_len = 0, a2_len = 0, a3_len = 0, a4_len = 0, a5_len = 0, a6_len = 0, a7_len = 0;
int argc = ZEND_NUM_ARGS();
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
if (zend_parse_parameters(argc TSRMLS_CC, "s|ssssss", &a1, &a1_len, &a2, &a2_len, &a3, &a3_len,
&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len) == FAILURE) {
@@ -1939,7 +1940,7 @@ PHP_METHOD(snmp, getErrno)
php_snmp_object *snmp_object;
zval *object = getThis();
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
RETVAL_LONG(snmp_object->snmp_errno);
return;
@@ -1953,10 +1954,9 @@ PHP_METHOD(snmp, getError)
php_snmp_object *snmp_object;
zval *object = getThis();
- snmp_object = (php_snmp_object *)zend_object_store_get_object(object TSRMLS_CC);
+ snmp_object = Z_SNMP_P(object);
- RETVAL_STRING(snmp_object->snmp_errstr, 1);
- return;
+ RETURN_STRING(snmp_object->snmp_errstr);
}
/* }}} */
@@ -1969,13 +1969,13 @@ void php_snmp_add_property(HashTable *h, const char *name, size_t name_length, p
p.name_length = name_length;
p.read_func = (read_func) ? read_func : NULL;
p.write_func = (write_func) ? write_func : NULL;
- zend_hash_add(h, (char *)name, name_length + 1, &p, sizeof(php_snmp_prop_handler), NULL);
+ zend_hash_str_add_mem(h, (char *)name, name_length, &p, sizeof(php_snmp_prop_handler));
}
/* }}} */
/* {{{ php_snmp_read_property(zval *object, zval *member, int type[, const zend_literal *key])
Generic object property reader */
-zval *php_snmp_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
+zval *php_snmp_read_property(zval *object, zval *member, int type, zend_uint cache_slot, zval *rv TSRMLS_DC)
{
zval tmp_member;
zval *retval;
@@ -1983,113 +1983,106 @@ zval *php_snmp_read_property(zval *object, zval *member, int type, const zend_li
php_snmp_prop_handler *hnd;
int ret;
- ret = FAILURE;
- obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
+ obj = Z_SNMP_P(object);
if (Z_TYPE_P(member) != IS_STRING) {
- tmp_member = *member;
- zval_copy_ctor(&tmp_member);
+ ZVAL_COPY(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
}
- ret = zend_hash_find(&php_snmp_properties, Z_STRVAL_P(member), Z_STRLEN_P(member)+1, (void **) &hnd);
+ hnd = zend_hash_find_ptr(&php_snmp_properties, Z_STR_P(member));
- if (ret == SUCCESS && hnd->read_func) {
- ret = hnd->read_func(obj, &retval TSRMLS_CC);
+ if (hnd && hnd->read_func) {
+ ret = hnd->read_func(obj, rv TSRMLS_CC);
if (ret == SUCCESS) {
- /* ensure we're creating a temporary variable */
- Z_SET_REFCOUNT_P(retval, 0);
+ retval = rv;
} else {
- retval = EG(uninitialized_zval_ptr);
+ retval = &EG(uninitialized_zval);
}
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
- retval = std_hnd->read_property(object, member, type, key TSRMLS_CC);
+ retval = std_hnd->read_property(object, member, type, cache_slot, rv TSRMLS_CC);
}
if (member == &tmp_member) {
- zval_dtor(member);
+ zval_ptr_dtor(member);
}
- return(retval);
+
+ return retval;
}
/* }}} */
/* {{{ php_snmp_write_property(zval *object, zval *member, zval *value[, const zend_literal *key])
Generic object property writer */
-void php_snmp_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
+void php_snmp_write_property(zval *object, zval *member, zval *value, zend_uint cache_slot TSRMLS_DC)
{
zval tmp_member;
php_snmp_object *obj;
php_snmp_prop_handler *hnd;
- int ret;
if (Z_TYPE_P(member) != IS_STRING) {
- tmp_member = *member;
- zval_copy_ctor(&tmp_member);
+ ZVAL_COPY(&tmp_member, member);
convert_to_string(&tmp_member);
member = &tmp_member;
}
- ret = FAILURE;
- obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
+ obj = Z_SNMP_P(object);
- ret = zend_hash_find(&php_snmp_properties, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **) &hnd);
+ hnd = zend_hash_find_ptr(&php_snmp_properties, Z_STR_P(member));
- if (ret == SUCCESS && hnd->write_func) {
+ if (hnd && hnd->write_func) {
hnd->write_func(obj, value TSRMLS_CC);
- if (! PZVAL_IS_REF(value) && Z_REFCOUNT_P(value) == 0) {
+ /*
+ if (!PZVAL_IS_REF(value) && Z_REFCOUNT_P(value) == 0) {
Z_ADDREF_P(value);
zval_ptr_dtor(&value);
}
+ */
} else {
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
- std_hnd->write_property(object, member, value, key TSRMLS_CC);
+ std_hnd->write_property(object, member, value, cache_slot TSRMLS_CC);
}
if (member == &tmp_member) {
- zval_dtor(member);
+ zval_ptr_dtor(member);
}
}
/* }}} */
/* {{{ php_snmp_has_property(zval *object, zval *member, int has_set_exists[, const zend_literal *key])
Generic object property checker */
-static int php_snmp_has_property(zval *object, zval *member, int has_set_exists, const zend_literal *key TSRMLS_DC)
+static int php_snmp_has_property(zval *object, zval *member, int has_set_exists, zend_uint cache_slot TSRMLS_DC)
{
+ zval rv;
php_snmp_prop_handler *hnd;
int ret = 0;
- if (zend_hash_find(&php_snmp_properties, Z_STRVAL_P(member), Z_STRLEN_P(member) + 1, (void **)&hnd) == SUCCESS) {
+ if ((hnd = zend_hash_find_ptr(&php_snmp_properties, Z_STR_P(member))) != NULL) {
switch (has_set_exists) {
case 2:
ret = 1;
break;
case 0: {
- zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
- if (value != EG(uninitialized_zval_ptr)) {
- ret = Z_TYPE_P(value) != IS_NULL? 1:0;
- /* refcount is 0 */
- Z_ADDREF_P(value);
- zval_ptr_dtor(&value);
+ zval *value = php_snmp_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
+ if (value != &EG(uninitialized_zval)) {
+ ret = Z_TYPE_P(value) != IS_NULL? 1 : 0;
+ zval_ptr_dtor(value);
}
break;
}
default: {
- zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
- if (value != EG(uninitialized_zval_ptr)) {
+ zval *value = php_snmp_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
+ if (value != &EG(uninitialized_zval)) {
convert_to_boolean(value);
- ret = Z_BVAL_P(value)? 1:0;
- /* refcount is 0 */
- Z_ADDREF_P(value);
- zval_ptr_dtor(&value);
+ ret = Z_TYPE_P(value) == IS_TRUE? 1:0;
}
break;
}
}
} else {
- zend_object_handlers * std_hnd = zend_get_std_object_handlers();
- ret = std_hnd->has_property(object, member, has_set_exists, key TSRMLS_CC);
+ zend_object_handlers *std_hnd = zend_get_std_object_handlers();
+ ret = std_hnd->has_property(object, member, has_set_exists, cache_slot TSRMLS_CC);
}
return ret;
}
@@ -2102,80 +2095,67 @@ static HashTable *php_snmp_get_properties(zval *object TSRMLS_DC)
php_snmp_object *obj;
php_snmp_prop_handler *hnd;
HashTable *props;
- zval *val;
- char *key;
- uint key_len;
- HashPosition pos;
+ zval rv;
+ zend_string *key;
ulong num_key;
- obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
+ obj = Z_SNMP_P(object);
props = zend_std_get_properties(object TSRMLS_CC);
- zend_hash_internal_pointer_reset_ex(&php_snmp_properties, &pos);
-
- while (zend_hash_get_current_data_ex(&php_snmp_properties, (void**)&hnd, &pos) == SUCCESS) {
- zend_hash_get_current_key_ex(&php_snmp_properties, &key, &key_len, &num_key, 0, &pos);
- if (!hnd->read_func || hnd->read_func(obj, &val TSRMLS_CC) != SUCCESS) {
- val = EG(uninitialized_zval_ptr);
- Z_ADDREF_P(val);
+ ZEND_HASH_FOREACH_KEY_PTR(&php_snmp_properties, num_key, key, hnd) {
+ if (!hnd->read_func || hnd->read_func(obj, &rv TSRMLS_CC) != SUCCESS) {
+ ZVAL_NULL(&rv);
}
- zend_hash_update(props, key, key_len, (void *)&val, sizeof(zval *), NULL);
- zend_hash_move_forward_ex(&php_snmp_properties, &pos);
- }
+ zend_hash_update(props, key, &rv);
+ } ZEND_HASH_FOREACH_END();
+
return obj->zo.properties;
}
/* }}} */
/* {{{ */
-static int php_snmp_read_info(php_snmp_object *snmp_object, zval **retval TSRMLS_DC)
+static int php_snmp_read_info(php_snmp_object *snmp_object, zval *retval TSRMLS_DC)
{
- zval *val;
+ zval val;
- MAKE_STD_ZVAL(*retval);
- array_init(*retval);
+ array_init(retval);
if (snmp_object->session == NULL) {
return SUCCESS;
}
- MAKE_STD_ZVAL(val);
- ZVAL_STRINGL(val, snmp_object->session->peername, strlen(snmp_object->session->peername), 1);
- add_assoc_zval(*retval, "hostname", val);
+ ZVAL_STRINGL(&val, snmp_object->session->peername, strlen(snmp_object->session->peername));
+ add_assoc_zval(retval, "hostname", &val);
- MAKE_STD_ZVAL(val);
- ZVAL_LONG(val, snmp_object->session->remote_port);
- add_assoc_zval(*retval, "port", val);
+ ZVAL_LONG(&val, snmp_object->session->remote_port);
+ add_assoc_zval(retval, "port", &val);
- MAKE_STD_ZVAL(val);
- ZVAL_LONG(val, snmp_object->session->timeout);
- add_assoc_zval(*retval, "timeout", val);
+ ZVAL_LONG(&val, snmp_object->session->timeout);
+ add_assoc_zval(retval, "timeout", &val);
- MAKE_STD_ZVAL(val);
- ZVAL_LONG(val, snmp_object->session->retries);
- add_assoc_zval(*retval, "retries", val);
+ ZVAL_LONG(&val, snmp_object->session->retries);
+ add_assoc_zval(retval, "retries", &val);
return SUCCESS;
}
/* }}} */
/* {{{ */
-static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval **retval TSRMLS_DC)
+static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval TSRMLS_DC)
{
- MAKE_STD_ZVAL(*retval);
if (snmp_object->max_oids > 0) {
- ZVAL_LONG(*retval, snmp_object->max_oids);
+ ZVAL_LONG(retval, snmp_object->max_oids);
} else {
- ZVAL_NULL(*retval);
+ ZVAL_NULL(retval);
}
return SUCCESS;
}
/* }}} */
#define PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(name) \
- static int php_snmp_read_##name(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) \
+ static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval TSRMLS_DC) \
{ \
- MAKE_STD_ZVAL(*retval); \
- ZVAL_BOOL(*retval, snmp_object->name); \
+ ZVAL_BOOL(retval, snmp_object->name); \
return SUCCESS; \
}
@@ -2184,10 +2164,9 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(quick_print)
PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print)
#define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \
- static int php_snmp_read_##name(php_snmp_object *snmp_object, zval **retval TSRMLS_DC) \
+ static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval TSRMLS_DC) \
{ \
- MAKE_STD_ZVAL(*retval); \
- ZVAL_LONG(*retval, snmp_object->name); \
+ ZVAL_LONG(retval, snmp_object->name); \
return SUCCESS; \
}
@@ -2267,18 +2246,12 @@ static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *new
static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) \
{ \
zval ztmp; \
- if (Z_TYPE_P(newval) != IS_BOOL) { \
- ztmp = *newval; \
- zval_copy_ctor(&ztmp); \
- convert_to_boolean(&ztmp); \
- newval = &ztmp; \
- } \
+ ZVAL_COPY(&ztmp, newval); \
+ convert_to_boolean(&ztmp); \
+ newval = &ztmp; \
\
- snmp_object->name = Z_LVAL_P(newval); \
+ snmp_object->name = Z_TYPE_P(newval) == IS_TRUE? 1 : 0; \
\
- if (newval == &ztmp) { \
- zval_dtor(newval); \
- } \
return SUCCESS; \
}
@@ -2292,8 +2265,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
zval ztmp;
int ret = SUCCESS;
if (Z_TYPE_P(newval) != IS_LONG) {
- ztmp = *newval;
- zval_copy_ctor(&ztmp);
+ ZVAL_COPY(&ztmp, newval);
convert_to_long(&ztmp);
newval = &ztmp;
}
@@ -2314,7 +2286,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
}
if (newval == &ztmp) {
- zval_dtor(newval);
+ zval_ptr_dtor(newval);
}
return ret;
}
@@ -2326,8 +2298,7 @@ static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval
zval ztmp;
int ret = SUCCESS;
if (Z_TYPE_P(newval) != IS_LONG) {
- ztmp = *newval;
- zval_copy_ctor(&ztmp);
+ ZVAL_COPY(&ztmp, newval);
convert_to_long(&ztmp);
newval = &ztmp;
}
@@ -2335,12 +2306,18 @@ static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval
snmp_object->exceptions_enabled = Z_LVAL_P(newval);
if (newval == &ztmp) {
- zval_dtor(newval);
+ zval_ptr_dtor(newval);
}
return ret;
}
/* }}} */
+static void free_php_snmp_properties(zval *el) /* {{{ */
+{
+ pefree(Z_PTR_P(el), 1);
+}
+/* }}} */
+
/* {{{ php_snmp_class_methods[] */
static zend_function_entry php_snmp_class_methods[] = {
PHP_ME(snmp, __construct, arginfo_snmp_create, ZEND_ACC_PUBLIC)
@@ -2405,11 +2382,13 @@ PHP_MINIT_FUNCTION(snmp)
/* Register SNMP Class */
INIT_CLASS_ENTRY(ce, "SNMP", php_snmp_class_methods);
ce.create_object = php_snmp_object_new;
+ php_snmp_object_handlers.offset = XtOffsetOf(php_snmp_object, zo);
php_snmp_object_handlers.clone_obj = NULL;
+ php_snmp_object_handlers.free_obj = php_snmp_object_free_storage;
php_snmp_ce = zend_register_internal_class(&ce TSRMLS_CC);
/* Register SNMP Class properties */
- zend_hash_init(&php_snmp_properties, 0, NULL, NULL, 1);
+ zend_hash_init(&php_snmp_properties, 0, NULL, free_php_snmp_properties, 1);
PHP_SNMP_ADD_PROPERTIES(&php_snmp_properties, php_snmp_property_entries);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_SUFFIX", NETSNMP_OID_OUTPUT_SUFFIX, CONST_CS | CONST_PERSISTENT);