Skip to content

Declare ext/snmp constants in stubs #9113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 26, 2022
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
22 changes: 20 additions & 2 deletions ext/snmp/php_snmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,26 @@ ZEND_END_MODULE_GLOBALS(snmp)
#define SNMP_G(v) (snmp_globals.v)
#endif

#define REGISTER_SNMP_CLASS_CONST_LONG(const_name, value) \
zend_declare_class_constant_long(php_snmp_ce, const_name, sizeof(const_name)-1, (zend_long)value);
#define SNMP_VALUE_LIBRARY (0 << 0)
#define SNMP_VALUE_PLAIN (1 << 0)
#define SNMP_VALUE_OBJECT (1 << 1)

#define PHP_SNMP_ERRNO_NOERROR 0
#define PHP_SNMP_ERRNO_GENERIC (1 << 1)
#define PHP_SNMP_ERRNO_TIMEOUT (1 << 2)
#define PHP_SNMP_ERRNO_ERROR_IN_REPLY (1 << 3)
#define PHP_SNMP_ERRNO_OID_NOT_INCREASING (1 << 4)
#define PHP_SNMP_ERRNO_OID_PARSING_ERROR (1 << 5)
#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES (1 << 6)
#define PHP_SNMP_ERRNO_ANY ( \
PHP_SNMP_ERRNO_GENERIC | \
PHP_SNMP_ERRNO_TIMEOUT | \
PHP_SNMP_ERRNO_ERROR_IN_REPLY | \
PHP_SNMP_ERRNO_OID_NOT_INCREASING | \
PHP_SNMP_ERRNO_OID_PARSING_ERROR | \
PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES | \
PHP_SNMP_ERRNO_NOERROR \
)

#else

Expand Down
64 changes: 4 additions & 60 deletions ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "zend_exceptions.h"
#include "zend_smart_string.h"
#include "ext/spl/spl_exceptions.h"
#include "snmp_arginfo.h"

#ifdef HAVE_SNMP

Expand Down Expand Up @@ -63,6 +62,8 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>

#include "snmp_arginfo.h"

/* For net-snmp prior to 5.4 */
#ifndef HAVE_SHUTDOWN_SNMP_LOGGING
extern netsnmp_log_handler *logh_head;
Expand All @@ -74,10 +75,6 @@ extern netsnmp_log_handler *logh_head;
}
#endif

#define SNMP_VALUE_LIBRARY (0 << 0)
#define SNMP_VALUE_PLAIN (1 << 0)
#define SNMP_VALUE_OBJECT (1 << 1)

typedef struct snmp_session php_snmp_session;

#define PHP_SNMP_ADD_PROPERTIES(a, b) \
Expand All @@ -90,23 +87,6 @@ typedef struct snmp_session php_snmp_session;
} \
}

#define PHP_SNMP_ERRNO_NOERROR 0
#define PHP_SNMP_ERRNO_GENERIC (1 << 1)
#define PHP_SNMP_ERRNO_TIMEOUT (1 << 2)
#define PHP_SNMP_ERRNO_ERROR_IN_REPLY (1 << 3)
#define PHP_SNMP_ERRNO_OID_NOT_INCREASING (1 << 4)
#define PHP_SNMP_ERRNO_OID_PARSING_ERROR (1 << 5)
#define PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES (1 << 6)
#define PHP_SNMP_ERRNO_ANY ( \
PHP_SNMP_ERRNO_GENERIC | \
PHP_SNMP_ERRNO_TIMEOUT | \
PHP_SNMP_ERRNO_ERROR_IN_REPLY | \
PHP_SNMP_ERRNO_OID_NOT_INCREASING | \
PHP_SNMP_ERRNO_OID_PARSING_ERROR | \
PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES | \
PHP_SNMP_ERRNO_NOERROR \
)

ZEND_DECLARE_MODULE_GLOBALS(snmp)
static PHP_GINIT_FUNCTION(snmp);

Expand Down Expand Up @@ -2052,47 +2032,11 @@ PHP_MINIT_FUNCTION(snmp)
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);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_MODULE", NETSNMP_OID_OUTPUT_MODULE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_FULL", NETSNMP_OID_OUTPUT_FULL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NUMERIC", NETSNMP_OID_OUTPUT_NUMERIC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_UCD", NETSNMP_OID_OUTPUT_UCD, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OID_OUTPUT_NONE", NETSNMP_OID_OUTPUT_NONE, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("SNMP_VALUE_LIBRARY", SNMP_VALUE_LIBRARY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_VALUE_PLAIN", SNMP_VALUE_PLAIN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_VALUE_OBJECT", SNMP_VALUE_OBJECT, CONST_CS | CONST_PERSISTENT);

REGISTER_LONG_CONSTANT("SNMP_BIT_STR", ASN_BIT_STR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OCTET_STR", ASN_OCTET_STR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OPAQUE", ASN_OPAQUE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_NULL", ASN_NULL, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_OBJECT_ID", ASN_OBJECT_ID, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_IPADDRESS", ASN_IPADDRESS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_COUNTER", ASN_GAUGE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_UNSIGNED", ASN_UNSIGNED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_TIMETICKS", ASN_TIMETICKS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_UINTEGER", ASN_UINTEGER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_INTEGER", ASN_INTEGER, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("SNMP_COUNTER64", ASN_COUNTER64, CONST_CS | CONST_PERSISTENT);

REGISTER_SNMP_CLASS_CONST_LONG("VERSION_1", SNMP_VERSION_1);
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2c", SNMP_VERSION_2c);
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_2C", SNMP_VERSION_2c);
REGISTER_SNMP_CLASS_CONST_LONG("VERSION_3", SNMP_VERSION_3);

REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_NOERROR", PHP_SNMP_ERRNO_NOERROR);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_ANY", PHP_SNMP_ERRNO_ANY);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_GENERIC", PHP_SNMP_ERRNO_GENERIC);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_TIMEOUT", PHP_SNMP_ERRNO_TIMEOUT);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_ERROR_IN_REPLY", PHP_SNMP_ERRNO_ERROR_IN_REPLY);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_OID_NOT_INCREASING", PHP_SNMP_ERRNO_OID_NOT_INCREASING);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_OID_PARSING_ERROR", PHP_SNMP_ERRNO_OID_PARSING_ERROR);
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_MULTIPLE_SET_QUERIES", PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES);

/* Register SNMPException class */
php_snmp_exception_ce = register_class_SNMPException(spl_ce_RuntimeException);

register_snmp_symbols(module_number);

return SUCCESS;
}
/* }}} */
Expand Down
170 changes: 170 additions & 0 deletions ext/snmp/snmp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,114 @@

/** @generate-class-entries */

/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_SUFFIX
*/
const SNMP_OID_OUTPUT_SUFFIX = UNKNOWN;
/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_MODULE
*/
const SNMP_OID_OUTPUT_MODULE = UNKNOWN;
/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_FULL
*/
const SNMP_OID_OUTPUT_FULL = UNKNOWN;
/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_NUMERIC
*/
const SNMP_OID_OUTPUT_NUMERIC = UNKNOWN;
/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_UCD
*/
const SNMP_OID_OUTPUT_UCD = UNKNOWN;
/**
* @var int
* @cvalue NETSNMP_OID_OUTPUT_NONE
*/
const SNMP_OID_OUTPUT_NONE = UNKNOWN;

/**
* @var int
* @cvalue SNMP_VALUE_LIBRARY
*/
const SNMP_VALUE_LIBRARY = UNKNOWN;
/**
* @var int
* @cvalue SNMP_VALUE_PLAIN
*/
const SNMP_VALUE_PLAIN = UNKNOWN;
/**
* @var int
* @cvalue SNMP_VALUE_OBJECT
*/
const SNMP_VALUE_OBJECT = UNKNOWN;

/**
* @var int
* @cvalue ASN_BIT_STR
*/
const SNMP_BIT_STR = UNKNOWN;
/**
* @var int
* @cvalue ASN_OCTET_STR
*/
const SNMP_OCTET_STR = UNKNOWN;
/**
* @var int
* @cvalue ASN_OPAQUE
*/
const SNMP_OPAQUE = UNKNOWN;
/**
* @var int
* @cvalue ASN_NULL
*/
const SNMP_NULL = UNKNOWN;
/**
* @var int
* @cvalue ASN_OBJECT_ID
*/
const SNMP_OBJECT_ID = UNKNOWN;
/**
* @var int
* @cvalue ASN_IPADDRESS
*/
const SNMP_IPADDRESS = UNKNOWN;
/**
* @var int
* @cvalue ASN_GAUGE
*/
const SNMP_COUNTER = UNKNOWN;
/**
* @var int
* @cvalue ASN_UNSIGNED
*/
const SNMP_UNSIGNED = UNKNOWN;
/**
* @var int
* @cvalue ASN_TIMETICKS
*/
const SNMP_TIMETICKS = UNKNOWN;
/**
* @var int
* @cvalue ASN_UINTEGER
*/
const SNMP_UINTEGER = UNKNOWN;
/**
* @var int
* @cvalue ASN_INTEGER
*/
const SNMP_INTEGER = UNKNOWN;
/**
* @var int
* @cvalue ASN_COUNTER64
*/
const SNMP_COUNTER64 = UNKNOWN;

function snmpget(string $hostname, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): mixed {}

function snmpgetnext(string $hostname, string $community, array|string $object_id, int $timeout = -1, int $retries = -1): mixed {}
Expand Down Expand Up @@ -75,6 +183,68 @@ function snmp_read_mib(string $filename): bool {}

class SNMP
{
/**
* @var int
* @cvalue SNMP_VERSION_1
*/
public const VERSION_1 = UNKNOWN;
/**
* @var int
* @cvalue SNMP_VERSION_2c
*/
public const VERSION_2c = UNKNOWN;
/**
* @var int
* @cvalue SNMP_VERSION_2c
*/
public const VERSION_2C = UNKNOWN;
/**
* @var int
* @cvalue SNMP_VERSION_3
*/
public const VERSION_3 = UNKNOWN;

/**
* @var int
* @cvalue PHP_SNMP_ERRNO_NOERROR
*/
public const ERRNO_NOERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_ANY
*/
public const ERRNO_ANY = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_GENERIC
*/
public const ERRNO_GENERIC = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_TIMEOUT
*/
public const ERRNO_TIMEOUT = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_ERROR_IN_REPLY
*/
public const ERRNO_ERROR_IN_REPLY = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_OID_NOT_INCREASING
*/
public const ERRNO_OID_NOT_INCREASING = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_OID_PARSING_ERROR
*/
public const ERRNO_OID_PARSING_ERROR = UNKNOWN;
/**
* @var int
* @cvalue PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES
*/
public const ERRNO_MULTIPLE_SET_QUERIES = UNKNOWN;

/** @readonly */
public array $info;
public ?int $max_oids;
Expand Down
Loading