output_api.h 6.8 KB

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