agent_handler.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /* Portions of this file are subject to the following copyright(s). See
  2. * the Net-SNMP's COPYING file for more details and other copyrights
  3. * that may apply:
  4. */
  5. /*
  6. * Portions of this file are copyrighted by:
  7. * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
  8. * Use is subject to license terms specified in the COPYING file
  9. * distributed with the Net-SNMP package.
  10. */
  11. #ifndef AGENT_HANDLER_H
  12. #define AGENT_HANDLER_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /** @file agent_handler.h
  17. *
  18. * @addtogroup handler
  19. *
  20. * @{
  21. */
  22. struct netsnmp_handler_registration_s;
  23. /*
  24. * per mib handler flags.
  25. * NOTE: Lower bits are reserved for the agent handler's use.
  26. * The high 4 bits (31-28) are reserved for use by the handler.
  27. */
  28. #define MIB_HANDLER_AUTO_NEXT 0x00000001
  29. #define MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE 0x00000002
  30. #define MIB_HANDLER_INSTANCE 0x00000004
  31. #define MIB_HANDLER_CUSTOM4 0x10000000
  32. #define MIB_HANDLER_CUSTOM3 0x20000000
  33. #define MIB_HANDLER_CUSTOM2 0x40000000
  34. #define MIB_HANDLER_CUSTOM1 0x80000000
  35. /** @typedef struct netsnmp_mib_handler_s netsnmp_mib_handler
  36. * Typedefs the netsnmp_mib_handler_s struct into netsnmp_mib_handler */
  37. /** @struct netsnmp_mib_handler_s
  38. * the mib handler structure to be registered
  39. */
  40. typedef struct netsnmp_mib_handler_s {
  41. char *handler_name;
  42. /** for handler's internal use */
  43. void *myvoid;
  44. /** for agent_handler's internal use */
  45. int flags;
  46. /** if you add more members, you probably also want to update */
  47. /** _clone_handler in agent_handler.c. */
  48. int (*access_method) (struct netsnmp_mib_handler_s *,
  49. struct
  50. netsnmp_handler_registration_s *,
  51. struct
  52. netsnmp_agent_request_info_s *,
  53. struct netsnmp_request_info_s *);
  54. /** data clone hook for myvoid
  55. * deep copy the myvoid member - default is to copy the pointer
  56. * This method is only called if myvoid != NULL
  57. * myvoid is the current myvoid pointer.
  58. * returns NULL on failure
  59. */
  60. void *(*data_clone)(void *myvoid);
  61. /** data free hook for myvoid
  62. * delete the myvoid member - default is to do nothing
  63. * This method is only called if myvoid != NULL
  64. */
  65. void (*data_free)(void *myvoid); /**< data free hook for myvoid */
  66. struct netsnmp_mib_handler_s *next;
  67. struct netsnmp_mib_handler_s *prev;
  68. } netsnmp_mib_handler;
  69. /*
  70. * per registration flags
  71. */
  72. #define HANDLER_CAN_GETANDGETNEXT 0x01 /* must be able to do both */
  73. #define HANDLER_CAN_SET 0x02 /* implies create, too */
  74. #define HANDLER_CAN_GETBULK 0x04
  75. #define HANDLER_CAN_NOT_CREATE 0x08 /* auto set if ! CAN_SET */
  76. #define HANDLER_CAN_BABY_STEP 0x10
  77. #define HANDLER_CAN_STASH 0x20
  78. #define HANDLER_CAN_RONLY (HANDLER_CAN_GETANDGETNEXT)
  79. #define HANDLER_CAN_RWRITE (HANDLER_CAN_GETANDGETNEXT | HANDLER_CAN_SET)
  80. #define HANDLER_CAN_SET_ONLY (HANDLER_CAN_SET | HANDLER_CAN_NOT_CREATE)
  81. #define HANDLER_CAN_DEFAULT (HANDLER_CAN_RONLY | HANDLER_CAN_NOT_CREATE)
  82. /** @typedef struct netsnmp_handler_registration_s netsnmp_handler_registration
  83. * Typedefs the netsnmp_handler_registration_s struct into netsnmp_handler_registration */
  84. /** @struct netsnmp_handler_registration_s
  85. * Root registration info.
  86. * The variables handlerName, contextName, and rootoid need to be allocated
  87. * on the heap, when the registration structure is unregistered using
  88. * unregister_mib_context() the code attempts to free them.
  89. */
  90. typedef struct netsnmp_handler_registration_s {
  91. /** for mrTable listings, and other uses */
  92. char *handlerName;
  93. /** NULL = default context */
  94. char *contextName;
  95. /**
  96. * where are we registered at?
  97. */
  98. oid *rootoid;
  99. size_t rootoid_len;
  100. /**
  101. * handler details
  102. */
  103. netsnmp_mib_handler *handler;
  104. int modes;
  105. /**
  106. * more optional stuff
  107. */
  108. int priority;
  109. int range_subid;
  110. oid range_ubound;
  111. int timeout;
  112. int global_cacheid;
  113. /**
  114. * void ptr for registeree
  115. */
  116. void * my_reg_void;
  117. } netsnmp_handler_registration;
  118. /*
  119. * function handler definitions
  120. */
  121. /**
  122. * @typedef Netsnmp_Node_Handler
  123. * @param[in] handler pointer to MIB handler.
  124. * @param[in] reginfo pointer to registration struct.
  125. * @param[in] reqinfo pointer to current transaction.
  126. * @param[in] requests SNMP requests to process.
  127. */
  128. typedef int (Netsnmp_Node_Handler) (netsnmp_mib_handler *handler,
  129. netsnmp_handler_registration *reginfo,
  130. netsnmp_agent_request_info *reqinfo,
  131. netsnmp_request_info *requests);
  132. typedef struct netsnmp_handler_args_s {
  133. netsnmp_mib_handler *handler;
  134. netsnmp_handler_registration *reginfo;
  135. netsnmp_agent_request_info *reqinfo;
  136. netsnmp_request_info *requests;
  137. } netsnmp_handler_args;
  138. typedef struct netsnmp_delegated_cache_s {
  139. int transaction_id;
  140. netsnmp_mib_handler *handler;
  141. netsnmp_handler_registration *reginfo;
  142. netsnmp_agent_request_info *reqinfo;
  143. netsnmp_request_info *requests;
  144. void *localinfo;
  145. } netsnmp_delegated_cache;
  146. /*
  147. * handler API functions
  148. */
  149. void netsnmp_init_handler_conf(void);
  150. int netsnmp_register_handler(netsnmp_handler_registration
  151. *reginfo);
  152. int netsnmp_unregister_handler(netsnmp_handler_registration
  153. *reginfo);
  154. int
  155. netsnmp_register_handler_nocallback(netsnmp_handler_registration
  156. *reginfo);
  157. int netsnmp_inject_handler(netsnmp_handler_registration
  158. *reginfo,
  159. netsnmp_mib_handler *handler);
  160. int
  161. netsnmp_inject_handler_before(netsnmp_handler_registration *reginfo,
  162. netsnmp_mib_handler *handler,
  163. const char *before_what);
  164. netsnmp_mib_handler
  165. *netsnmp_find_handler_by_name(netsnmp_handler_registration
  166. *reginfo, const char *name);
  167. void
  168. *netsnmp_find_handler_data_by_name(netsnmp_handler_registration
  169. *reginfo, const char *name);
  170. int netsnmp_call_handlers(netsnmp_handler_registration
  171. *reginfo,
  172. netsnmp_agent_request_info
  173. *reqinfo,
  174. netsnmp_request_info *requests);
  175. int netsnmp_call_handler(netsnmp_mib_handler *next_handler,
  176. netsnmp_handler_registration
  177. *reginfo,
  178. netsnmp_agent_request_info
  179. *reqinfo,
  180. netsnmp_request_info *requests);
  181. int netsnmp_call_next_handler(netsnmp_mib_handler *current,
  182. netsnmp_handler_registration
  183. *reginfo,
  184. netsnmp_agent_request_info
  185. *reqinfo,
  186. netsnmp_request_info
  187. *requests);
  188. int netsnmp_call_next_handler_one_request(netsnmp_mib_handler *current,
  189. netsnmp_handler_registration *reginfo,
  190. netsnmp_agent_request_info *reqinfo,
  191. netsnmp_request_info *requests);
  192. netsnmp_mib_handler *netsnmp_create_handler(const char *name,
  193. Netsnmp_Node_Handler *
  194. handler_access_method);
  195. netsnmp_handler_registration *
  196. netsnmp_handler_registration_create(const char *name,
  197. netsnmp_mib_handler *handler,
  198. const oid * reg_oid, size_t reg_oid_len,
  199. int modes);
  200. netsnmp_handler_registration *
  201. netsnmp_create_handler_registration(const char *name, Netsnmp_Node_Handler*
  202. handler_access_method,
  203. const oid *reg_oid, size_t reg_oid_len,
  204. int modes);
  205. netsnmp_delegated_cache
  206. *netsnmp_create_delegated_cache(netsnmp_mib_handler *,
  207. netsnmp_handler_registration *,
  208. netsnmp_agent_request_info *,
  209. netsnmp_request_info *, void *);
  210. void netsnmp_free_delegated_cache(netsnmp_delegated_cache *dcache);
  211. netsnmp_delegated_cache
  212. *netsnmp_handler_check_cache(netsnmp_delegated_cache *dcache);
  213. void netsnmp_register_handler_by_name(const char *,
  214. netsnmp_mib_handler
  215. *);
  216. void netsnmp_clear_handler_list(void);
  217. void
  218. netsnmp_request_add_list_data(netsnmp_request_info *request,
  219. netsnmp_data_list *node);
  220. int netsnmp_request_remove_list_data(netsnmp_request_info *request,
  221. const char *name);
  222. int
  223. netsnmp_request_remove_list_data(netsnmp_request_info *request,
  224. const char *name);
  225. void *netsnmp_request_get_list_data(netsnmp_request_info
  226. *request,
  227. const char *name);
  228. void
  229. netsnmp_free_request_data_set(netsnmp_request_info *request);
  230. void
  231. netsnmp_free_request_data_sets(netsnmp_request_info *request);
  232. void netsnmp_handler_free(netsnmp_mib_handler *);
  233. netsnmp_mib_handler *netsnmp_handler_dup(netsnmp_mib_handler *);
  234. netsnmp_handler_registration
  235. *netsnmp_handler_registration_dup(netsnmp_handler_registration *);
  236. void
  237. netsnmp_handler_registration_free(netsnmp_handler_registration *);
  238. #define REQUEST_IS_DELEGATED 1
  239. #define REQUEST_IS_NOT_DELEGATED 0
  240. void
  241. netsnmp_handler_mark_requests_as_delegated(netsnmp_request_info *,
  242. int);
  243. void *netsnmp_handler_get_parent_data(netsnmp_request_info *,
  244. const char *);
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248. #endif /* AGENT_HANDLER_H */
  249. /** @} */