1 #ifndef NET_SNMP_OUTPUT_API_H
2 #define NET_SNMP_OUTPUT_API_H
3
4 /**
5 * Library API routines concerned with logging and message output
6 * (including error handling and debugging).
7 */
8
9 #include <stdarg.h> /* for va_list */
10 #include <net-snmp/types.h>
11 #include <net-snmp/library/netsnmp-attribute-format.h>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 /* Error reporting */
18 NETSNMP_IMPORT
19 void snmp_error(netsnmp_session *sess, int *clib_errorno,
20 int *snmp_errorno, char **errstring);
21 NETSNMP_IMPORT
22 void snmp_sess_error( void *sess, int *clib_errorno,
23 int *snmp_errorno, char **errstring);
24
25 NETSNMP_IMPORT
26 const char *snmp_api_errstring(int snmp_errorno); /* library errors */
27 NETSNMP_IMPORT
28 const char *snmp_errstring(int snmp_errorno); /* protocol errors */
29
30 NETSNMP_IMPORT
31 void snmp_perror(const char *msg); /* for parsing errors only */
32
33 NETSNMP_IMPORT
34 void snmp_sess_perror(const char *msg, netsnmp_session *sess);
35 /* for all other SNMP library errors */
36 NETSNMP_IMPORT
37 void snmp_log_perror(const char *msg);
38 /* for system library errors */
39
40 /* Logging messages */
41
42 NETSNMP_IMPORT
43 int snmp_log( int priority, const char *format, ...)
44 NETSNMP_ATTRIBUTE_FORMAT(printf, 2, 3);
45 NETSNMP_IMPORT
46 int snmp_vlog(int priority, const char *format, va_list ap);
47 NETSNMP_IMPORT
48 int snmp_get_do_logging( void);
49 NETSNMP_IMPORT
50 void netsnmp_logging_restart(void);
51 NETSNMP_IMPORT
52 void snmp_disable_log( void);
53 NETSNMP_IMPORT
54 void shutdown_snmp_logging( void);
55
56 #undef _LOG_ATTR
57
58 /* Debug messages */
59 #ifndef NETSNMP_NO_DEBUGGING
60 #include <net-snmp/library/snmp_debug.h> /* for internal macros */
61 #define DEBUGMSG(x) do {if (_DBG_IF_) {debugmsg x;} }while(0)
62 #define DEBUGMSGT(x) do {if (_DBG_IF_) {__DBGMSGT(x);} }while(0)
63 #define DEBUGTRACE do {if (_DBG_IF_) {__DBGTRACE;} }while(0)
64 #define DEBUGTRACETOK(x) do {if (_DBG_IF_) {__DBGTRACETOK(x);} }while(0)
65 #define DEBUGMSGL(x) do {if (_DBG_IF_) {__DBGMSGL(x);} }while(0)
66 #define DEBUGMSGTL(x) do {if (_DBG_IF_) {__DBGMSGTL(x);} }while(0)
67 #define DEBUGMSGOID(x) do {if (_DBG_IF_) {__DBGMSGOID(x);} }while(0)
68 #define DEBUGMSGSUBOID(x) do {if (_DBG_IF_) {__DBGMSGSUBOID(x);} }while(0)
69 #define DEBUGMSGVAR(x) do {if (_DBG_IF_) {__DBGMSGVAR(x);} }while(0)
70 #define DEBUGMSGOIDRANGE(x) do {if (_DBG_IF_) {__DBGMSGOIDRANGE(x);} }while(0)
71 #define DEBUGMSGHEX(x) do {if (_DBG_IF_) {__DBGMSGHEX(x);} }while(0)
72 #define DEBUGMSGHEXTLI(x) do {if (_DBG_IF_) {__DBGMSGHEXTLI(x);} }while(0)
73 #define DEBUGINDENTADD(x) do {if (_DBG_IF_) {__DBGINDENTADD(x);} }while(0)
74 #define DEBUGINDENTMORE() do {if (_DBG_IF_) {__DBGINDENTMORE();} }while(0)
75 #define DEBUGINDENTLESS() do {if (_DBG_IF_) {__DBGINDENTLESS();} }while(0)
76 #define DEBUGPRINTINDENT(token) \
77 do {if (_DBG_IF_) {__DBGPRINTINDENT(token);} }while(0)
78 #define DEBUGDUMPHEADER(token,x) \
79 do {if (_DBG_IF_) {__DBGDUMPHEADER(token,x);} }while(0)
80 #define DEBUGDUMPSECTION(token,x) \
81 do {if (_DBG_IF_) {__DBGDUMPSECTION(token,x);} }while(0)
82 #define DEBUGDUMPSETUP(token,buf,len) \
83 do {if (_DBG_IF_) {__DBGDUMPSETUP(token,buf,len);} }while(0)
84 #define DEBUGMSG_NC(x) do { __DBGMSG_NC(x); }while(0)
85 #define DEBUGMSGT_NC(x) do { __DBGMSGT_NC(x); }while(0)
86
87 #else /* NETSNMP_NO_DEBUGGING := enable streamlining of the code */
88
89 NETSNMP_STATIC_INLINE void
netsnmp_debug_no_msg(const char * token,const char * fmt,...)90 netsnmp_debug_no_msg(const char *token, const char *fmt, ...)
91 { }
92
93 NETSNMP_STATIC_INLINE void
netsnmp_debug_no_tracetok(const char * token)94 netsnmp_debug_no_tracetok(const char *token)
95 { }
96
97 NETSNMP_STATIC_INLINE void
netsnmp_debug_no_oid(const char * token,const oid * oid,size_t oid_len)98 netsnmp_debug_no_oid(const char *token, const oid *oid, size_t oid_len)
99 { }
100
101 struct variable_list;
102
103 NETSNMP_STATIC_INLINE void
netsnmp_debug_no_var(const char * token,const struct variable_list * var)104 netsnmp_debug_no_var(const char *token, const struct variable_list *var)
105 { }
106
107 NETSNMP_STATIC_INLINE void
netsnmp_debug_no_dumpsetup(const char * token,const void * buf,size_t len)108 netsnmp_debug_no_dumpsetup(const char *token, const void *buf, size_t len)
109 { }
110
111 #define DEBUGMSG(x) do { netsnmp_debug_no_msg x; } while (0)
112 #define DEBUGMSGT(x) do { netsnmp_debug_no_msg x; } while (0)
113 #define DEBUGTRACE do { } while (0)
114 #define DEBUGTRACETOK(x) \
115 do { netsnmp_debug_no_tracetok(x); } while (0)
116 #define DEBUGMSGL(x) do { netsnmp_debug_no_msg x; } while (0)
117 #define DEBUGMSGTL(x) do { netsnmp_debug_no_msg x; } while (0)
118 #define DEBUGMSGOID(x) do { netsnmp_debug_no_oid x; } while (0)
119 #define DEBUGMSGSUBOID(x) do { netsnmp_debug_no_oid x; } while (0)
120 #define DEBUGMSGVAR(x) do { netsnmp_debug_no_var x; } while (0)
121 #define DEBUGMSGOIDRANGE(x)
122 #define DEBUGMSGHEX(x)
123 #define DEBUGIF(x) if(0)
124 #define DEBUGDUMP(t,b,l,p)
125 #define DEBUGINDENTMORE()
126 #define DEBUGINDENTLESS()
127 #define DEBUGINDENTADD(x)
128 #define DEBUGMSGHEXTLI(x)
129 #define DEBUGPRINTINDENT(token)
130 #define DEBUGDUMPHEADER(token,x)
131 #define DEBUGDUMPSECTION(token,x)
132 #define DEBUGDUMPSETUP(token, buf, len) \
133 do { netsnmp_debug_no_dumpsetup(token, buf, len); } while (0)
134
135 #define DEBUGMSG_NC(x) do { netsnmp_debug_no_msg x; } while (0)
136 #define DEBUGMSGT_NC(x) do { netsnmp_debug_no_msg x; } while (0)
137
138 #endif /* NETSNMP_NO_DEBUGGING */
139
140 NETSNMP_IMPORT
141 void debug_register_tokens(const char *tokens);
142 NETSNMP_IMPORT
143 int debug_enable_token_logs (const char *token);
144 NETSNMP_IMPORT
145 int debug_disable_token_logs (const char *token);
146 NETSNMP_IMPORT
147 int debug_is_token_registered(const char *token);
148 NETSNMP_IMPORT
149 void snmp_set_do_debugging(int);
150 NETSNMP_IMPORT
151 int snmp_get_do_debugging(void);
152 #ifndef NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL
153 NETSNMP_IMPORT
154 void netsnmp_set_debug_log_level(int val);
155 NETSNMP_IMPORT
156 int netsnmp_get_debug_log_level(void);
157 #endif /* NETSNMP_DISABLE_DYNAMIC_LOG_LEVEL */
158
159 /*
160 * Having extracted the main ("public API") calls relevant
161 * to this area of the Net-SNMP project, the next step is to
162 * identify the related "public internal API" routines.
163 *
164 * In due course, these should probably be gathered
165 * together into a companion 'library/output_api.h' header file.
166 * [Or some suitable name]
167 *
168 * But for the time being, the expectation is that the
169 * traditional headers that provided the above definitions
170 * will probably also cover the relevant internal API calls.
171 * Hence they are listed here:
172 */
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #include <net-snmp/library/snmp_api.h>
179 #include <net-snmp/library/snmp_client.h>
180 #include <net-snmp/library/snmp_debug.h>
181 #include <net-snmp/library/snmp_logging.h>
182
183 #ifndef ERROR_MSG
184 #define ERROR_MSG(string) snmp_set_detail(string)
185 #endif
186
187 #endif /* NET_SNMP_OUTPUT_API_H */
188