mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Refactoring ext/snmp
This commit is contained in:
parent
f2028491aa
commit
b36afe8dd3
2 changed files with 194 additions and 210 deletions
|
@ -85,7 +85,6 @@ PHP_METHOD(SNMP, getErrno);
|
||||||
PHP_METHOD(SNMP, getError);
|
PHP_METHOD(SNMP, getError);
|
||||||
|
|
||||||
typedef struct _php_snmp_object {
|
typedef struct _php_snmp_object {
|
||||||
zend_object zo;
|
|
||||||
struct snmp_session *session;
|
struct snmp_session *session;
|
||||||
int max_oids;
|
int max_oids;
|
||||||
int valueretrieval;
|
int valueretrieval;
|
||||||
|
@ -96,10 +95,16 @@ typedef struct _php_snmp_object {
|
||||||
int oid_increasing_check;
|
int oid_increasing_check;
|
||||||
int exceptions_enabled;
|
int exceptions_enabled;
|
||||||
char snmp_errstr[256];
|
char snmp_errstr[256];
|
||||||
|
zend_object zo;
|
||||||
} php_snmp_object;
|
} 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));
|
||||||
|
}
|
||||||
|
|
||||||
typedef int (*php_snmp_read_t)(php_snmp_object *snmp_object, zval **retval TSRMLS_DC);
|
#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_write_t)(php_snmp_object *snmp_object, zval *newval TSRMLS_DC);
|
typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval TSRMLS_DC);
|
||||||
|
|
||||||
typedef struct _ptp_snmp_prop_handler {
|
typedef struct _ptp_snmp_prop_handler {
|
||||||
|
|
391
ext/snmp/snmp.c
391
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) {
|
if (*session) {
|
||||||
PHP_SNMP_SESSION_FREE(peername);
|
PHP_SNMP_SESSION_FREE(peername);
|
||||||
|
@ -465,16 +465,18 @@ static void netsnmp_session_free(php_snmp_session **session)
|
||||||
*session = NULL;
|
*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;
|
php_snmp_session *session = (php_snmp_session *)rsrc->ptr;
|
||||||
netsnmp_session_free(&session);
|
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) {
|
if (!intern) {
|
||||||
return;
|
return;
|
||||||
|
@ -483,28 +485,25 @@ static void php_snmp_object_free_storage(void *object TSRMLS_DC)
|
||||||
netsnmp_session_free(&(intern->session));
|
netsnmp_session_free(&(intern->session));
|
||||||
|
|
||||||
zend_object_std_dtor(&intern->zo TSRMLS_CC);
|
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;
|
php_snmp_object *intern;
|
||||||
|
|
||||||
/* Allocate memory for it */
|
/* Allocate memory for it */
|
||||||
intern = emalloc(sizeof(php_snmp_object));
|
intern = ecalloc(1, sizeof(php_snmp_object) + sizeof(zval) * (class_type->default_properties_count - 1));
|
||||||
memset(&intern->zo, 0, sizeof(php_snmp_object));
|
|
||||||
|
|
||||||
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
|
zend_object_std_init(&intern->zo, class_type TSRMLS_CC);
|
||||||
object_properties_init(&intern->zo, class_type);
|
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);
|
intern->zo.handlers = &php_snmp_object_handlers;
|
||||||
retval.handlers = (zend_object_handlers *) &php_snmp_object_handlers;
|
|
||||||
|
|
||||||
return retval;
|
return &intern->zo;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_snmp_error
|
/* {{{ 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;
|
php_snmp_object *snmp_object = NULL;
|
||||||
|
|
||||||
if (object) {
|
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) {
|
if (type == PHP_SNMP_ERRNO_NOERROR) {
|
||||||
memset(snmp_object->snmp_errstr, 0, sizeof(snmp_object->snmp_errstr));
|
memset(snmp_object->snmp_errstr, 0, sizeof(snmp_object->snmp_errstr));
|
||||||
} else {
|
} 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)
|
static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval TSRMLS_DC, int valueretrieval)
|
||||||
{
|
{
|
||||||
zval *val;
|
zval val;
|
||||||
char sbuf[512];
|
char sbuf[512];
|
||||||
char *buf = &(sbuf[0]);
|
char *buf = &(sbuf[0]);
|
||||||
char *dbuf = (char *)NULL;
|
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) {
|
if (valueretrieval & SNMP_VALUE_PLAIN) {
|
||||||
*buf = 0;
|
*buf = 0;
|
||||||
switch (vars->type) {
|
switch (vars->type) {
|
||||||
case ASN_BIT_STR: /* 0x03, asn1.h */
|
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;
|
break;
|
||||||
|
|
||||||
case ASN_OCTET_STR: /* 0x04, asn1.h */
|
case ASN_OCTET_STR: /* 0x04, asn1.h */
|
||||||
case ASN_OPAQUE: /* 0x44, snmp_impl.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;
|
break;
|
||||||
|
|
||||||
case ASN_NULL: /* 0x05, asn1.h */
|
case ASN_NULL: /* 0x05, asn1.h */
|
||||||
ZVAL_NULL(val);
|
ZVAL_NULL(&val);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_OBJECT_ID: /* 0x06, asn1.h */
|
case ASN_OBJECT_ID: /* 0x06, asn1.h */
|
||||||
snprint_objid(buf, buflen, vars->val.objid, vars->val_len / sizeof(oid));
|
snprint_objid(buf, buflen, vars->val.objid, vars->val_len / sizeof(oid));
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_IPADDRESS: /* 0x40, snmp_impl.h */
|
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)[0], (vars->val.string)[1],
|
||||||
(vars->val.string)[2], (vars->val.string)[3]);
|
(vars->val.string)[2], (vars->val.string)[3]);
|
||||||
buf[buflen]=0;
|
buf[buflen]=0;
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_COUNTER: /* 0x41, snmp_impl.h */
|
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 */
|
case ASN_UINTEGER: /* 0x47, snmp_impl.h */
|
||||||
snprintf(buf, buflen, "%lu", *vars->val.integer);
|
snprintf(buf, buflen, "%lu", *vars->val.integer);
|
||||||
buf[buflen]=0;
|
buf[buflen]=0;
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_INTEGER: /* 0x02, asn1.h */
|
case ASN_INTEGER: /* 0x02, asn1.h */
|
||||||
snprintf(buf, buflen, "%ld", *vars->val.integer);
|
snprintf(buf, buflen, "%ld", *vars->val.integer);
|
||||||
buf[buflen]=0;
|
buf[buflen]=0;
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if defined(NETSNMP_WITH_OPAQUE_SPECIAL_TYPES) || defined(OPAQUE_SPECIAL_TYPES)
|
#if defined(NETSNMP_WITH_OPAQUE_SPECIAL_TYPES) || defined(OPAQUE_SPECIAL_TYPES)
|
||||||
case ASN_OPAQUE_FLOAT: /* 0x78, asn1.h */
|
case ASN_OPAQUE_FLOAT: /* 0x78, asn1.h */
|
||||||
snprintf(buf, buflen, "%f", *vars->val.floatVal);
|
snprintf(buf, buflen, "%f", *vars->val.floatVal);
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_OPAQUE_DOUBLE: /* 0x79, asn1.h */
|
case ASN_OPAQUE_DOUBLE: /* 0x79, asn1.h */
|
||||||
snprintf(buf, buflen, "%Lf", *vars->val.doubleVal);
|
snprintf(buf, buflen, "%Lf", *vars->val.doubleVal);
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_OPAQUE_I64: /* 0x80, asn1.h */
|
case ASN_OPAQUE_I64: /* 0x80, asn1.h */
|
||||||
printI64(buf, vars->val.counter64);
|
printI64(buf, vars->val.counter64);
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ASN_OPAQUE_U64: /* 0x81, asn1.h */
|
case ASN_OPAQUE_U64: /* 0x81, asn1.h */
|
||||||
#endif
|
#endif
|
||||||
case ASN_COUNTER64: /* 0x46, snmp_impl.h */
|
case ASN_COUNTER64: /* 0x46, snmp_impl.h */
|
||||||
printU64(buf, vars->val.counter64);
|
printU64(buf, vars->val.counter64);
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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);
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value type: %u", vars->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else /* use Net-SNMP value translation */ {
|
} else /* use Net-SNMP value translation */ {
|
||||||
/* we have desired string in buffer, just use it */
|
/* we have desired string in buffer, just use it */
|
||||||
ZVAL_STRING(val, buf, 1);
|
ZVAL_STRING(&val, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valueretrieval & SNMP_VALUE_OBJECT) {
|
if (valueretrieval & SNMP_VALUE_OBJECT) {
|
||||||
object_init(snmpval);
|
object_init(snmpval);
|
||||||
add_property_long(snmpval, "type", vars->type);
|
add_property_long(snmpval, "type", vars->type);
|
||||||
add_property_zval(snmpval, "value", val);
|
add_property_zval(snmpval, "value", &val);
|
||||||
} else {
|
} else {
|
||||||
*snmpval = *val;
|
ZVAL_COPY(snmpval, &val);
|
||||||
zval_copy_ctor(snmpval);
|
|
||||||
}
|
}
|
||||||
zval_ptr_dtor(&val);
|
zval_ptr_dtor(&val);
|
||||||
|
|
||||||
if(dbuf){ /* malloc was used to store value */
|
if (dbuf){ /* malloc was used to store value */
|
||||||
efree(dbuf);
|
efree(dbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -716,7 +712,7 @@ static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
|
||||||
char buf2[2048];
|
char buf2[2048];
|
||||||
int keepwalking=1;
|
int keepwalking=1;
|
||||||
char *err;
|
char *err;
|
||||||
zval *snmpval = NULL;
|
zval snmpval;
|
||||||
int snmp_errno;
|
int snmp_errno;
|
||||||
|
|
||||||
/* we start with retval=FALSE. If any actual data is acquired, retval will be set to appropriate type */
|
/* we start with retval=FALSE. If any actual data is acquired, retval will be set to appropriate type */
|
||||||
|
@ -831,15 +827,15 @@ retry:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
MAKE_STD_ZVAL(snmpval);
|
ZVAL_NULL(&snmpval);
|
||||||
php_snmp_getvalue(vars, snmpval TSRMLS_CC, objid_query->valueretrieval);
|
php_snmp_getvalue(vars, &snmpval TSRMLS_CC, objid_query->valueretrieval);
|
||||||
|
|
||||||
if (objid_query->array_output) {
|
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);
|
array_init(return_value);
|
||||||
}
|
}
|
||||||
if (st & SNMP_NUMERIC_KEYS) {
|
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) {
|
} else if (st & SNMP_ORIGINAL_NAMES_AS_KEYS && st & SNMP_CMD_GET) {
|
||||||
found = 0;
|
found = 0;
|
||||||
for (count = 0; count < objid_query->count; count++) {
|
for (count = 0; count < objid_query->count; count++) {
|
||||||
|
@ -850,7 +846,7 @@ retry:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found) {
|
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 {
|
} else {
|
||||||
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
|
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);
|
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 '.' */
|
buf2[strlen(buf2) - 1] = '\0'; /* remove trailing '.' */
|
||||||
}
|
}
|
||||||
add_assoc_zval(return_value, buf2, snmpval);
|
add_assoc_zval(return_value, buf2, &snmpval);
|
||||||
} else {
|
} else {
|
||||||
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
|
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 {
|
} else {
|
||||||
*return_value = *snmpval;
|
ZVAL_COPY_VALUE(return_value, &snmpval);
|
||||||
zval_copy_ctor(return_value);
|
|
||||||
zval_ptr_dtor(&snmpval);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -902,8 +896,8 @@ retry:
|
||||||
keepwalking = 1;
|
keepwalking = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!(st & SNMP_CMD_WALK) || response->errstat != SNMP_ERR_NOSUCHNAME || Z_TYPE_P(return_value) == IS_BOOL) {
|
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;
|
for (count=1, vars = response->variables;
|
||||||
vars && count != response->errindex;
|
vars && count != response->errindex;
|
||||||
vars = vars->next_variable, count++);
|
vars = vars->next_variable, count++);
|
||||||
|
|
||||||
|
@ -929,7 +923,7 @@ retry:
|
||||||
snmp_free_pdu(response);
|
snmp_free_pdu(response);
|
||||||
snmp_close(ss);
|
snmp_close(ss);
|
||||||
if (objid_query->array_output) {
|
if (objid_query->array_output) {
|
||||||
zval_dtor(return_value);
|
zval_ptr_dtor(return_value);
|
||||||
}
|
}
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
return;
|
return;
|
||||||
|
@ -938,7 +932,7 @@ retry:
|
||||||
} else if (status == STAT_TIMEOUT) {
|
} else if (status == STAT_TIMEOUT) {
|
||||||
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_TIMEOUT, "No response from %s", session->peername);
|
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_TIMEOUT, "No response from %s", session->peername);
|
||||||
if (objid_query->array_output) {
|
if (objid_query->array_output) {
|
||||||
zval_dtor(return_value);
|
zval_ptr_dtor(return_value);
|
||||||
}
|
}
|
||||||
snmp_close(ss);
|
snmp_close(ss);
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
|
@ -948,7 +942,7 @@ retry:
|
||||||
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_GENERIC, "Fatal error: %s", err);
|
php_snmp_error(getThis(), NULL TSRMLS_CC, PHP_SNMP_ERRNO_GENERIC, "Fatal error: %s", err);
|
||||||
free(err);
|
free(err);
|
||||||
if (objid_query->array_output) {
|
if (objid_query->array_output) {
|
||||||
zval_dtor(return_value);
|
zval_ptr_dtor(return_value);
|
||||||
}
|
}
|
||||||
snmp_close(ss);
|
snmp_close(ss);
|
||||||
RETVAL_FALSE;
|
RETVAL_FALSE;
|
||||||
|
@ -967,61 +961,67 @@ retry:
|
||||||
* OID parser (and type, value for SNMP_SET command)
|
* 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;
|
char *pptr;
|
||||||
HashPosition pos_oid, pos_type, pos_value;
|
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)) {
|
if (Z_ISREF_PP(oid)) {
|
||||||
SEPARATE_ZVAL(oid);
|
SEPARATE_ZVAL(oid);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
convert_to_string_ex(oid);
|
convert_to_string_ex(oid);
|
||||||
} else if (Z_TYPE_PP(oid) == IS_ARRAY) {
|
} else if (Z_TYPE_P(oid) == IS_ARRAY) {
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (st & SNMP_CMD_SET) {
|
if (st & SNMP_CMD_SET) {
|
||||||
if (Z_TYPE_PP(type) != IS_ARRAY) {
|
if (Z_TYPE_P(type) != IS_ARRAY) {
|
||||||
|
/*
|
||||||
if (Z_ISREF_PP(type)) {
|
if (Z_ISREF_PP(type)) {
|
||||||
SEPARATE_ZVAL(type);
|
SEPARATE_ZVAL(type);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
convert_to_string_ex(type);
|
convert_to_string_ex(type);
|
||||||
} else if (Z_TYPE_PP(type) == IS_ARRAY) {
|
} else if (Z_TYPE_P(type) == IS_ARRAY) {
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(type), &pos_type);
|
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)) {
|
if (Z_ISREF_PP(value)) {
|
||||||
SEPARATE_ZVAL(value);
|
SEPARATE_ZVAL(value);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
convert_to_string_ex(value);
|
convert_to_string_ex(value);
|
||||||
} else if (Z_TYPE_PP(value) == IS_ARRAY) {
|
} else if (Z_TYPE_P(value) == IS_ARRAY) {
|
||||||
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(value), &pos_value);
|
zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(value), &pos_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
objid_query->count = 0;
|
objid_query->count = 0;
|
||||||
objid_query->array_output = ((st & SNMP_CMD_WALK) ? TRUE : FALSE);
|
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));
|
objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
|
||||||
if (objid_query->vars == NULL) {
|
if (objid_query->vars == NULL) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid: %s", strerror(errno));
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid: %s", strerror(errno));
|
||||||
efree(objid_query->vars);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
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 (st & SNMP_CMD_SET) {
|
||||||
if (Z_TYPE_PP(type) == IS_STRING && Z_TYPE_PP(value) == IS_STRING) {
|
if (Z_TYPE_P(type) == IS_STRING && Z_TYPE_P(value) == IS_STRING) {
|
||||||
if (Z_STRLEN_PP(type) != 1) {
|
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_PP(type), Z_STRLEN_PP(type));
|
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);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
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].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 {
|
} else {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Single objid and multiple type or values are not supported");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Single objid and multiple type or values are not supported");
|
||||||
efree(objid_query->vars);
|
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++;
|
objid_query->count++;
|
||||||
} else if (Z_TYPE_PP(oid) == IS_ARRAY) { /* we got objid array */
|
} else if (Z_TYPE_P(oid) == IS_ARRAY) { /* we got objid array */
|
||||||
if (zend_hash_num_elements(Z_ARRVAL_PP(oid)) == 0) {
|
if (zend_hash_num_elements(Z_ARRVAL_P(oid)) == 0) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got empty OID array");
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Got empty OID array");
|
||||||
return FALSE;
|
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) {
|
if (objid_query->vars == NULL) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid array: %s", strerror(errno));
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "emalloc() failed while parsing oid array: %s", strerror(errno));
|
||||||
efree(objid_query->vars);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
|
objid_query->array_output = ( (st & SNMP_CMD_SET) ? FALSE : TRUE );
|
||||||
for ( zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(oid), &pos_oid);
|
for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(oid), &pos_oid);
|
||||||
zend_hash_get_current_data_ex(Z_ARRVAL_PP(oid), (void **) &tmp_oid, &pos_oid) == SUCCESS;
|
(tmp_oid = zend_hash_get_current_data_ex(Z_ARRVAL_P(oid), &pos_oid)) != NULL;
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_PP(oid), &pos_oid) ) {
|
zend_hash_move_forward_ex(Z_ARRVAL_P(oid), &pos_oid) ) {
|
||||||
|
|
||||||
convert_to_string_ex(tmp_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 (st & SNMP_CMD_SET) {
|
||||||
if (Z_TYPE_PP(type) == IS_STRING) {
|
if (Z_TYPE_P(type) == IS_STRING) {
|
||||||
pptr = Z_STRVAL_PP(type);
|
pptr = Z_STRVAL_P(type);
|
||||||
objid_query->vars[objid_query->count].type = *pptr;
|
objid_query->vars[objid_query->count].type = *pptr;
|
||||||
} else if (Z_TYPE_PP(type) == IS_ARRAY) {
|
} else if (Z_TYPE_P(type) == IS_ARRAY) {
|
||||||
if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(type), (void **) &tmp_type, &pos_type)) {
|
if ((tmp_type = zend_hash_get_current_data_ex(Z_ARRVAL_P(type), &pos_type)) != NULL) {
|
||||||
convert_to_string_ex(tmp_type);
|
convert_to_string_ex(tmp_type);
|
||||||
if (Z_STRLEN_PP(tmp_type) != 1) {
|
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_PP(tmp_oid), Z_STRVAL_PP(tmp_type), Z_STRLEN_PP(tmp_type));
|
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);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
pptr = Z_STRVAL_PP(tmp_type);
|
pptr = Z_STRVAL_P(tmp_type);
|
||||||
objid_query->vars[objid_query->count].type = *pptr;
|
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 {
|
} 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);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Z_TYPE_PP(value) == IS_STRING) {
|
if (Z_TYPE_P(value) == IS_STRING) {
|
||||||
objid_query->vars[objid_query->count].value = Z_STRVAL_PP(value);
|
objid_query->vars[objid_query->count].value = Z_STRVAL_P(value);
|
||||||
} else if (Z_TYPE_PP(value) == IS_ARRAY) {
|
} else if (Z_TYPE_P(value) == IS_ARRAY) {
|
||||||
if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(value), (void **) &tmp_value, &pos_value)) {
|
if ((tmp_value = zend_hash_get_current_data_ex(Z_ARRVAL_P(value), &pos_value)) != NULL) {
|
||||||
convert_to_string_ex(tmp_value);
|
convert_to_string_ex(tmp_value);
|
||||||
objid_query->vars[objid_query->count].value = Z_STRVAL_PP(tmp_value);
|
objid_query->vars[objid_query->count].value = Z_STRVAL_P(tmp_value);
|
||||||
zend_hash_move_forward_ex(Z_ARRVAL_PP(value), &pos_value);
|
zend_hash_move_forward_ex(Z_ARRVAL_P(value), &pos_value);
|
||||||
} else {
|
} 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);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
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)
|
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;
|
char *a1, *a2, *a3, *a4, *a5, *a6, *a7;
|
||||||
int a1_len, a2_len, a3_len, a4_len, a5_len, a6_len, a7_len;
|
int a1_len, a2_len, a3_len, a4_len, a5_len, a6_len, a7_len;
|
||||||
zend_bool use_orignames = 0, suffix_keys = 0;
|
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 (session_less_mode) {
|
||||||
if (version == SNMP_VERSION_3) {
|
if (version == SNMP_VERSION_3) {
|
||||||
if (st & SNMP_CMD_SET) {
|
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) {
|
&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &type, &value, &timeout, &retries) == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1455,14 +1455,14 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
|
||||||
* SNMP_CMD_GETNEXT
|
* SNMP_CMD_GETNEXT
|
||||||
* SNMP_CMD_WALK
|
* 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) {
|
&a4, &a4_len, &a5, &a5_len, &a6, &a6_len, &a7, &a7_len, &oid, &timeout, &retries) == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (st & SNMP_CMD_SET) {
|
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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1470,25 +1470,25 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
|
||||||
* SNMP_CMD_GETNEXT
|
* SNMP_CMD_GETNEXT
|
||||||
* SNMP_CMD_WALK
|
* 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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (st & SNMP_CMD_SET) {
|
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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
} else if (st & SNMP_CMD_WALK) {
|
} 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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
if (suffix_keys) {
|
if (suffix_keys) {
|
||||||
st |= SNMP_USE_SUFFIX_AS_KEYS;
|
st |= SNMP_USE_SUFFIX_AS_KEYS;
|
||||||
}
|
}
|
||||||
} else if (st & SNMP_CMD_GET) {
|
} 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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
if (use_orignames) {
|
if (use_orignames) {
|
||||||
|
@ -1497,7 +1497,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
|
||||||
} else {
|
} else {
|
||||||
/* SNMP_CMD_GETNEXT
|
/* 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;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1521,7 +1521,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zval *object = getThis();
|
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;
|
session = snmp_object->session;
|
||||||
if (!session) {
|
if (!session) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid or uninitialized SNMP object");
|
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();
|
int argc = ZEND_NUM_ARGS();
|
||||||
zend_error_handling error_handling;
|
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);
|
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) {
|
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;
|
php_snmp_object *snmp_object;
|
||||||
zval *object = getThis();
|
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) {
|
if (zend_parse_parameters_none() == FAILURE) {
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
|
@ -1906,6 +1906,7 @@ PHP_METHOD(snmp, set)
|
||||||
{
|
{
|
||||||
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, (-1));
|
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]]]])
|
/* {{{ 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 */
|
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 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();
|
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,
|
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) {
|
&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;
|
php_snmp_object *snmp_object;
|
||||||
zval *object = getThis();
|
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);
|
RETVAL_LONG(snmp_object->snmp_errno);
|
||||||
return;
|
return;
|
||||||
|
@ -1953,10 +1954,9 @@ PHP_METHOD(snmp, getError)
|
||||||
php_snmp_object *snmp_object;
|
php_snmp_object *snmp_object;
|
||||||
zval *object = getThis();
|
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_STRING(snmp_object->snmp_errstr);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -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.name_length = name_length;
|
||||||
p.read_func = (read_func) ? read_func : NULL;
|
p.read_func = (read_func) ? read_func : NULL;
|
||||||
p.write_func = (write_func) ? write_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])
|
/* {{{ php_snmp_read_property(zval *object, zval *member, int type[, const zend_literal *key])
|
||||||
Generic object property reader */
|
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 tmp_member;
|
||||||
zval *retval;
|
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;
|
php_snmp_prop_handler *hnd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = FAILURE;
|
obj = Z_SNMP_P(object);
|
||||||
obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
|
|
||||||
|
|
||||||
if (Z_TYPE_P(member) != IS_STRING) {
|
if (Z_TYPE_P(member) != IS_STRING) {
|
||||||
tmp_member = *member;
|
ZVAL_COPY(&tmp_member, member);
|
||||||
zval_copy_ctor(&tmp_member);
|
|
||||||
convert_to_string(&tmp_member);
|
convert_to_string(&tmp_member);
|
||||||
member = &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) {
|
if (hnd && hnd->read_func) {
|
||||||
ret = hnd->read_func(obj, &retval TSRMLS_CC);
|
ret = hnd->read_func(obj, rv TSRMLS_CC);
|
||||||
if (ret == SUCCESS) {
|
if (ret == SUCCESS) {
|
||||||
/* ensure we're creating a temporary variable */
|
retval = rv;
|
||||||
Z_SET_REFCOUNT_P(retval, 0);
|
|
||||||
} else {
|
} else {
|
||||||
retval = EG(uninitialized_zval_ptr);
|
retval = &EG(uninitialized_zval);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
|
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) {
|
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])
|
/* {{{ php_snmp_write_property(zval *object, zval *member, zval *value[, const zend_literal *key])
|
||||||
Generic object property writer */
|
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;
|
zval tmp_member;
|
||||||
php_snmp_object *obj;
|
php_snmp_object *obj;
|
||||||
php_snmp_prop_handler *hnd;
|
php_snmp_prop_handler *hnd;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (Z_TYPE_P(member) != IS_STRING) {
|
if (Z_TYPE_P(member) != IS_STRING) {
|
||||||
tmp_member = *member;
|
ZVAL_COPY(&tmp_member, member);
|
||||||
zval_copy_ctor(&tmp_member);
|
|
||||||
convert_to_string(&tmp_member);
|
convert_to_string(&tmp_member);
|
||||||
member = &tmp_member;
|
member = &tmp_member;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = FAILURE;
|
obj = Z_SNMP_P(object);
|
||||||
obj = (php_snmp_object *)zend_objects_get_address(object TSRMLS_CC);
|
|
||||||
|
|
||||||
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);
|
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);
|
Z_ADDREF_P(value);
|
||||||
zval_ptr_dtor(&value);
|
zval_ptr_dtor(&value);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} else {
|
} else {
|
||||||
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
|
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) {
|
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])
|
/* {{{ php_snmp_has_property(zval *object, zval *member, int has_set_exists[, const zend_literal *key])
|
||||||
Generic object property checker */
|
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;
|
php_snmp_prop_handler *hnd;
|
||||||
int ret = 0;
|
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) {
|
switch (has_set_exists) {
|
||||||
case 2:
|
case 2:
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
case 0: {
|
case 0: {
|
||||||
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
|
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
|
||||||
if (value != EG(uninitialized_zval_ptr)) {
|
if (value != &EG(uninitialized_zval)) {
|
||||||
ret = Z_TYPE_P(value) != IS_NULL? 1:0;
|
ret = Z_TYPE_P(value) != IS_NULL? 1 : 0;
|
||||||
/* refcount is 0 */
|
zval_ptr_dtor(value);
|
||||||
Z_ADDREF_P(value);
|
|
||||||
zval_ptr_dtor(&value);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, key TSRMLS_CC);
|
zval *value = php_snmp_read_property(object, member, BP_VAR_IS, cache_slot, &rv TSRMLS_CC);
|
||||||
if (value != EG(uninitialized_zval_ptr)) {
|
if (value != &EG(uninitialized_zval)) {
|
||||||
convert_to_boolean(value);
|
convert_to_boolean(value);
|
||||||
ret = Z_BVAL_P(value)? 1:0;
|
ret = Z_TYPE_P(value) == IS_TRUE? 1:0;
|
||||||
/* refcount is 0 */
|
|
||||||
Z_ADDREF_P(value);
|
|
||||||
zval_ptr_dtor(&value);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
zend_object_handlers * std_hnd = zend_get_std_object_handlers();
|
zend_object_handlers *std_hnd = zend_get_std_object_handlers();
|
||||||
ret = std_hnd->has_property(object, member, has_set_exists, key TSRMLS_CC);
|
ret = std_hnd->has_property(object, member, has_set_exists, cache_slot TSRMLS_CC);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2102,80 +2095,67 @@ static HashTable *php_snmp_get_properties(zval *object TSRMLS_DC)
|
||||||
php_snmp_object *obj;
|
php_snmp_object *obj;
|
||||||
php_snmp_prop_handler *hnd;
|
php_snmp_prop_handler *hnd;
|
||||||
HashTable *props;
|
HashTable *props;
|
||||||
zval *val;
|
zval rv;
|
||||||
char *key;
|
zend_string *key;
|
||||||
uint key_len;
|
|
||||||
HashPosition pos;
|
|
||||||
ulong num_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);
|
props = zend_std_get_properties(object TSRMLS_CC);
|
||||||
|
|
||||||
zend_hash_internal_pointer_reset_ex(&php_snmp_properties, &pos);
|
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, &rv);
|
||||||
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
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_update(props, key, key_len, (void *)&val, sizeof(zval *), NULL);
|
|
||||||
zend_hash_move_forward_ex(&php_snmp_properties, &pos);
|
|
||||||
}
|
|
||||||
return obj->zo.properties;
|
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) {
|
if (snmp_object->session == NULL) {
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
MAKE_STD_ZVAL(val);
|
ZVAL_STRINGL(&val, snmp_object->session->peername, strlen(snmp_object->session->peername));
|
||||||
ZVAL_STRINGL(val, snmp_object->session->peername, strlen(snmp_object->session->peername), 1);
|
add_assoc_zval(retval, "hostname", &val);
|
||||||
add_assoc_zval(*retval, "hostname", val);
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(val);
|
ZVAL_LONG(&val, snmp_object->session->remote_port);
|
||||||
ZVAL_LONG(val, snmp_object->session->remote_port);
|
add_assoc_zval(retval, "port", &val);
|
||||||
add_assoc_zval(*retval, "port", val);
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(val);
|
ZVAL_LONG(&val, snmp_object->session->timeout);
|
||||||
ZVAL_LONG(val, snmp_object->session->timeout);
|
add_assoc_zval(retval, "timeout", &val);
|
||||||
add_assoc_zval(*retval, "timeout", val);
|
|
||||||
|
|
||||||
MAKE_STD_ZVAL(val);
|
ZVAL_LONG(&val, snmp_object->session->retries);
|
||||||
ZVAL_LONG(val, snmp_object->session->retries);
|
add_assoc_zval(retval, "retries", &val);
|
||||||
add_assoc_zval(*retval, "retries", val);
|
|
||||||
|
|
||||||
return SUCCESS;
|
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) {
|
if (snmp_object->max_oids > 0) {
|
||||||
ZVAL_LONG(*retval, snmp_object->max_oids);
|
ZVAL_LONG(retval, snmp_object->max_oids);
|
||||||
} else {
|
} else {
|
||||||
ZVAL_NULL(*retval);
|
ZVAL_NULL(retval);
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
#define PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(name) \
|
#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; \
|
return SUCCESS; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2184,10 +2164,9 @@ PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(quick_print)
|
||||||
PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print)
|
PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print)
|
||||||
|
|
||||||
#define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \
|
#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; \
|
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) \
|
static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval TSRMLS_DC) \
|
||||||
{ \
|
{ \
|
||||||
zval ztmp; \
|
zval ztmp; \
|
||||||
if (Z_TYPE_P(newval) != IS_BOOL) { \
|
ZVAL_COPY(&ztmp, newval); \
|
||||||
ztmp = *newval; \
|
|
||||||
zval_copy_ctor(&ztmp); \
|
|
||||||
convert_to_boolean(&ztmp); \
|
convert_to_boolean(&ztmp); \
|
||||||
newval = &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; \
|
return SUCCESS; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2292,8 +2265,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
|
||||||
zval ztmp;
|
zval ztmp;
|
||||||
int ret = SUCCESS;
|
int ret = SUCCESS;
|
||||||
if (Z_TYPE_P(newval) != IS_LONG) {
|
if (Z_TYPE_P(newval) != IS_LONG) {
|
||||||
ztmp = *newval;
|
ZVAL_COPY(&ztmp, newval);
|
||||||
zval_copy_ctor(&ztmp);
|
|
||||||
convert_to_long(&ztmp);
|
convert_to_long(&ztmp);
|
||||||
newval = &ztmp;
|
newval = &ztmp;
|
||||||
}
|
}
|
||||||
|
@ -2314,7 +2286,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newval == &ztmp) {
|
if (newval == &ztmp) {
|
||||||
zval_dtor(newval);
|
zval_ptr_dtor(newval);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2326,8 +2298,7 @@ static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval
|
||||||
zval ztmp;
|
zval ztmp;
|
||||||
int ret = SUCCESS;
|
int ret = SUCCESS;
|
||||||
if (Z_TYPE_P(newval) != IS_LONG) {
|
if (Z_TYPE_P(newval) != IS_LONG) {
|
||||||
ztmp = *newval;
|
ZVAL_COPY(&ztmp, newval);
|
||||||
zval_copy_ctor(&ztmp);
|
|
||||||
convert_to_long(&ztmp);
|
convert_to_long(&ztmp);
|
||||||
newval = &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);
|
snmp_object->exceptions_enabled = Z_LVAL_P(newval);
|
||||||
|
|
||||||
if (newval == &ztmp) {
|
if (newval == &ztmp) {
|
||||||
zval_dtor(newval);
|
zval_ptr_dtor(newval);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
static void free_php_snmp_properties(zval *el) /* {{{ */
|
||||||
|
{
|
||||||
|
pefree(Z_PTR_P(el), 1);
|
||||||
|
}
|
||||||
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ php_snmp_class_methods[] */
|
/* {{{ php_snmp_class_methods[] */
|
||||||
static zend_function_entry php_snmp_class_methods[] = {
|
static zend_function_entry php_snmp_class_methods[] = {
|
||||||
PHP_ME(snmp, __construct, arginfo_snmp_create, ZEND_ACC_PUBLIC)
|
PHP_ME(snmp, __construct, arginfo_snmp_create, ZEND_ACC_PUBLIC)
|
||||||
|
@ -2405,11 +2382,13 @@ PHP_MINIT_FUNCTION(snmp)
|
||||||
/* Register SNMP Class */
|
/* Register SNMP Class */
|
||||||
INIT_CLASS_ENTRY(ce, "SNMP", php_snmp_class_methods);
|
INIT_CLASS_ENTRY(ce, "SNMP", php_snmp_class_methods);
|
||||||
ce.create_object = php_snmp_object_new;
|
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.clone_obj = NULL;
|
||||||
|
php_snmp_object_handlers.free_obj = php_snmp_object_free_storage;
|
||||||
php_snmp_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
php_snmp_ce = zend_register_internal_class(&ce TSRMLS_CC);
|
||||||
|
|
||||||
/* Register SNMP Class properties */
|
/* 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);
|
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);
|
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_SUFFIX", NETSNMP_OID_OUTPUT_SUFFIX, CONST_CS | CONST_PERSISTENT);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue