1 /*
2 +----------------------------------------------------------------------+
3 | PHP Version 7 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2018 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Rasmus Lerdorf <rasmus@php.net> |
16 | Mike Jackson <mhjack@tscnet.com> |
17 | Steven Lawrance <slawrance@technologist.com> |
18 | Harrie Hazewinkel <harrie@lisanza.net> |
19 | Johann Hanne <jonny@nurfuerspam.de> |
20 | Boris Lytockin <lytboris@gmail.com> |
21 +----------------------------------------------------------------------+
22 */
23
24 #ifndef PHP_SNMP_H
25 #define PHP_SNMP_H
26
27 #define PHP_SNMP_VERSION PHP_VERSION
28
29 #if HAVE_SNMP
30
31 #ifndef DLEXPORT
32 #define DLEXPORT
33 #endif
34
35 extern zend_module_entry snmp_module_entry;
36 #define snmp_module_ptr &snmp_module_entry
37
38 #ifdef ZTS
39 #include "TSRM.h"
40 #endif
41
42 #include <net-snmp/net-snmp-config.h>
43 #include <net-snmp/net-snmp-includes.h>
44
45 PHP_MINIT_FUNCTION(snmp);
46 PHP_MSHUTDOWN_FUNCTION(snmp);
47 PHP_MINFO_FUNCTION(snmp);
48
49 PHP_FUNCTION(snmpget);
50 PHP_FUNCTION(snmpgetnext);
51 PHP_FUNCTION(snmpwalk);
52 PHP_FUNCTION(snmprealwalk);
53 PHP_FUNCTION(snmpset);
54 PHP_FUNCTION(snmp_get_quick_print);
55 PHP_FUNCTION(snmp_set_quick_print);
56 PHP_FUNCTION(snmp_set_enum_print);
57 PHP_FUNCTION(snmp_set_oid_output_format);
58
59 PHP_FUNCTION(snmp2_get);
60 PHP_FUNCTION(snmp2_getnext);
61 PHP_FUNCTION(snmp2_walk);
62 PHP_FUNCTION(snmp2_real_walk);
63 PHP_FUNCTION(snmp2_set);
64
65 PHP_FUNCTION(snmp3_get);
66 PHP_FUNCTION(snmp3_getnext);
67 PHP_FUNCTION(snmp3_walk);
68 PHP_FUNCTION(snmp3_real_walk);
69 PHP_FUNCTION(snmp3_set);
70
71 PHP_FUNCTION(snmp_set_valueretrieval);
72 PHP_FUNCTION(snmp_get_valueretrieval);
73
74 PHP_FUNCTION(snmp_read_mib);
75
76 PHP_METHOD(SNMP, setSecurity);
77 PHP_METHOD(SNMP, close);
78 PHP_METHOD(SNMP, get);
79 PHP_METHOD(SNMP, getnext);
80 PHP_METHOD(SNMP, walk);
81 PHP_METHOD(SNMP, set);
82 PHP_METHOD(SNMP, getErrno);
83 PHP_METHOD(SNMP, getError);
84
85 typedef struct _php_snmp_object {
86 struct snmp_session *session;
87 int max_oids;
88 int valueretrieval;
89 int quick_print;
90 int enum_print;
91 int oid_output_format;
92 int snmp_errno;
93 int oid_increasing_check;
94 int exceptions_enabled;
95 char snmp_errstr[256];
96 zend_object zo;
97 } php_snmp_object;
98
php_snmp_fetch_object(zend_object * obj)99 static inline php_snmp_object *php_snmp_fetch_object(zend_object *obj) {
100 return (php_snmp_object *)((char*)(obj) - XtOffsetOf(php_snmp_object, zo));
101 }
102
103 #define Z_SNMP_P(zv) php_snmp_fetch_object(Z_OBJ_P((zv)))
104
105 typedef int (*php_snmp_read_t)(php_snmp_object *snmp_object, zval *retval);
106 typedef int (*php_snmp_write_t)(php_snmp_object *snmp_object, zval *newval);
107
108 typedef struct _ptp_snmp_prop_handler {
109 const char *name;
110 size_t name_length;
111 php_snmp_read_t read_func;
112 php_snmp_write_t write_func;
113 } php_snmp_prop_handler;
114
115 typedef struct _snmpobjarg {
116 char *oid;
117 char type;
118 char *value;
119 oid name[MAX_OID_LEN];
120 size_t name_length;
121 } snmpobjarg;
122
123 ZEND_BEGIN_MODULE_GLOBALS(snmp)
124 int valueretrieval;
125 ZEND_END_MODULE_GLOBALS(snmp)
126
127 #ifdef ZTS
128 #define SNMP_G(v) TSRMG(snmp_globals_id, zend_snmp_globals *, v)
129 #else
130 #define SNMP_G(v) (snmp_globals.v)
131 #endif
132
133 #define REGISTER_SNMP_CLASS_CONST_LONG(const_name, value) \
134 zend_declare_class_constant_long(php_snmp_ce, const_name, sizeof(const_name)-1, (zend_long)value);
135
136 #else
137
138 #define snmp_module_ptr NULL
139
140 #endif /* HAVE_SNMP */
141
142 #define phpext_snmp_ptr snmp_module_ptr
143
144 #endif /* PHP_SNMP_H */
145