Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ext/snmp/php_snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ typedef struct _php_snmp_object {
struct snmp_session *session;
int max_oids;
int valueretrieval;
int quick_print;
int enum_print;
bool quick_print;
bool enum_print;
int oid_output_format;
int snmp_errno;
int oid_increasing_check;
bool oid_increasing_check;
int exceptions_enabled;
char snmp_errstr[256];
zend_object zo;
Expand All @@ -60,8 +60,8 @@ typedef struct _php_snmp_object {

#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);
typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval);
typedef zend_result (*php_snmp_read_t)(php_snmp_object *snmp_object, zval *retval);
typedef zend_result (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval);

typedef struct _ptp_snmp_prop_handler {
const char *name;
Expand Down
65 changes: 31 additions & 34 deletions ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval, int val
char sbuf[512];
char *buf = &(sbuf[0]);
char *dbuf = (char *)NULL;
int buflen = sizeof(sbuf) - 1;
int val_len = vars->val_len;
size_t buflen = sizeof(sbuf) - 1;
size_t val_len = vars->val_len;

/* use emalloc() for large values, use static array otherwise */

Expand Down Expand Up @@ -1265,7 +1265,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
zend_long retries = SNMP_DEFAULT_RETRIES;
struct objid_query objid_query;
php_snmp_session *session;
int session_less_mode = (getThis() == NULL);
bool session_less_mode = (getThis() == NULL);
uint32_t timeout_arg_num = 0;
uint32_t oid_arg_num = 1, type_arg_num = 0, value_arg_num = 0;
php_snmp_object *snmp_object;
Expand Down Expand Up @@ -1502,48 +1502,48 @@ PHP_FUNCTION(snmp_get_quick_print)
/* {{{ Return all objects including their respective object id within the specified one */
PHP_FUNCTION(snmp_set_quick_print)
{
bool a1;
bool quick_print;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &quick_print) == FAILURE) {
RETURN_THROWS();
}

netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, (int)a1);
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, (int)quick_print);
RETURN_TRUE;
}
/* }}} */

/* {{{ Return all values that are enums with their enum value instead of the raw integer */
PHP_FUNCTION(snmp_set_enum_print)
{
bool a1;
bool enum_print;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &enum_print) == FAILURE) {
RETURN_THROWS();
}

netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int) a1);
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int)enum_print);
RETURN_TRUE;
}
/* }}} */

/* {{{ Set the OID output format. */
PHP_FUNCTION(snmp_set_oid_output_format)
{
zend_long a1;
zend_long format;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &a1) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &format) == FAILURE) {
RETURN_THROWS();
}

switch (a1) {
switch (format) {
case NETSNMP_OID_OUTPUT_SUFFIX:
case NETSNMP_OID_OUTPUT_MODULE:
case NETSNMP_OID_OUTPUT_FULL:
case NETSNMP_OID_OUTPUT_NUMERIC:
case NETSNMP_OID_OUTPUT_UCD:
case NETSNMP_OID_OUTPUT_NONE:
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, format);
RETURN_TRUE;
default:
zend_argument_value_error(1, "must be an SNMP_OID_OUTPUT_* constant");
Expand Down Expand Up @@ -1696,14 +1696,14 @@ PHP_METHOD(SNMP, __construct)
{
php_snmp_object *snmp_object;
zval *object = ZEND_THIS;
zend_string *a1, *a2;
zend_string *hostname, *community;
zend_long timeout = SNMP_DEFAULT_TIMEOUT;
zend_long retries = SNMP_DEFAULT_RETRIES;
zend_long version = SNMP_DEFAULT_VERSION;

snmp_object = Z_SNMP_P(object);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "lPP|ll", &version, &a1, &a2, &timeout, &retries) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "lPP|ll", &version, &hostname, &community, &timeout, &retries) == FAILURE) {
RETURN_THROWS();
}

Expand All @@ -1722,7 +1722,7 @@ PHP_METHOD(SNMP, __construct)
snmp_session_free(&(snmp_object->session));
}

if (!snmp_session_init(&(snmp_object->session), version, a1, a2, timeout, retries, 2, 4)) {
if (!snmp_session_init(&(snmp_object->session), version, hostname, community, timeout, retries, 2, 4)) {
return;
}
snmp_object->max_oids = 0;
Expand Down Expand Up @@ -1859,13 +1859,12 @@ zval *php_snmp_read_property(zend_object *object, zend_string *name, int type, v
zval *retval;
php_snmp_object *obj;
php_snmp_prop_handler *hnd;
int ret;

obj = php_snmp_fetch_object(object);
hnd = zend_hash_find_ptr(&php_snmp_properties, name);

if (hnd && hnd->read_func) {
ret = hnd->read_func(obj, rv);
zend_result ret = hnd->read_func(obj, rv);
if (ret == SUCCESS) {
retval = rv;
} else {
Expand Down Expand Up @@ -1918,17 +1917,17 @@ static int php_snmp_has_property(zend_object *object, zend_string *name, int has
{
zval rv;
php_snmp_prop_handler *hnd;
int ret = 0;
bool ret = false;

if ((hnd = zend_hash_find_ptr(&php_snmp_properties, name)) != NULL) {
switch (has_set_exists) {
case ZEND_PROPERTY_EXISTS:
ret = 1;
ret = true;
break;
case ZEND_PROPERTY_ISSET: {
zval *value = php_snmp_read_property(object, name, BP_VAR_IS, cache_slot, &rv);
if (value != &EG(uninitialized_zval)) {
ret = Z_TYPE_P(value) != IS_NULL? 1 : 0;
ret = Z_TYPE_P(value) != IS_NULL;
zval_ptr_dtor(value);
}
break;
Expand All @@ -1937,7 +1936,7 @@ static int php_snmp_has_property(zend_object *object, zend_string *name, int has
zval *value = php_snmp_read_property(object, name, BP_VAR_IS, cache_slot, &rv);
if (value != &EG(uninitialized_zval)) {
convert_to_boolean(value);
ret = Z_TYPE_P(value) == IS_TRUE? 1:0;
ret = Z_TYPE_P(value) == IS_TRUE;
}
break;
}
Expand Down Expand Up @@ -1995,7 +1994,7 @@ static zval *php_snmp_get_property_ptr_ptr(zend_object *object, zend_string *nam
}

/* {{{ */
static int php_snmp_read_info(php_snmp_object *snmp_object, zval *retval)
static zend_result php_snmp_read_info(php_snmp_object *snmp_object, zval *retval)
{
zval val;

Expand All @@ -2019,7 +2018,7 @@ static int php_snmp_read_info(php_snmp_object *snmp_object, zval *retval)
/* }}} */

/* {{{ */
static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval)
static zend_result php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval)
{
if (snmp_object->max_oids > 0) {
ZVAL_LONG(retval, snmp_object->max_oids);
Expand All @@ -2031,7 +2030,7 @@ static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval)
/* }}} */

#define PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(name) \
static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \
static zend_result php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \
{ \
ZVAL_BOOL(retval, snmp_object->name); \
return SUCCESS; \
Expand All @@ -2042,7 +2041,7 @@ 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) \
static zend_result php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \
{ \
ZVAL_LONG(retval, snmp_object->name); \
return SUCCESS; \
Expand All @@ -2053,7 +2052,7 @@ PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(oid_output_format)
PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled)

/* {{{ */
static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
static zend_result php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
{
zend_long lval;

Expand All @@ -2075,7 +2074,7 @@ static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
/* }}} */

/* {{{ */
static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
static zend_result php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
{
zend_long lval = zval_get_long(newval);

Expand All @@ -2091,7 +2090,7 @@ static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *new
/* }}} */

#define PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(name) \
static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \
static zend_result php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \
{ \
zval ztmp; \
ZVAL_COPY(&ztmp, newval); \
Expand All @@ -2108,7 +2107,7 @@ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print)
PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check)

/* {{{ */
static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval)
static zend_result php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval)
{
zend_long lval = zval_get_long(newval);

Expand All @@ -2129,13 +2128,11 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
/* }}} */

/* {{{ */
static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval *newval)
static zend_result php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval *newval)
{
int ret = SUCCESS;

snmp_object->exceptions_enabled = zval_get_long(newval);

return ret;
return SUCCESS;
}
/* }}} */

Expand Down
Loading