net-snmp 5.7
|
00001 /* Portions of this file are subject to the following copyright(s). See 00002 * the Net-SNMP's COPYING file for more details and other copyrights 00003 * that may apply: 00004 */ 00005 /* 00006 * Portions of this file are copyrighted by: 00007 * Copyright © 2003 Sun Microsystems, Inc. All rights reserved. 00008 * Use is subject to license terms specified in the COPYING file 00009 * distributed with the Net-SNMP package. 00010 */ 00011 #ifndef AGENT_HANDLER_H 00012 #define AGENT_HANDLER_H 00013 00014 #ifdef __cplusplus 00015 extern "C" { 00016 #endif 00017 00025 struct netsnmp_handler_registration_s; 00026 00027 /* 00028 * per mib handler flags. 00029 * NOTE: Lower bits are reserved for the agent handler's use. 00030 * The high 4 bits (31-28) are reserved for use by the handler. 00031 */ 00032 #define MIB_HANDLER_AUTO_NEXT 0x00000001 00033 #define MIB_HANDLER_AUTO_NEXT_OVERRIDE_ONCE 0x00000002 00034 #define MIB_HANDLER_INSTANCE 0x00000004 00035 00036 #define MIB_HANDLER_CUSTOM4 0x10000000 00037 #define MIB_HANDLER_CUSTOM3 0x20000000 00038 #define MIB_HANDLER_CUSTOM2 0x40000000 00039 #define MIB_HANDLER_CUSTOM1 0x80000000 00040 00041 00048 typedef struct netsnmp_mib_handler_s { 00049 char *handler_name; 00051 void *myvoid; 00053 int flags; 00054 00058 int (*access_method) (struct netsnmp_mib_handler_s *, 00059 struct 00060 netsnmp_handler_registration_s *, 00061 struct 00062 netsnmp_agent_request_info_s *, 00063 struct netsnmp_request_info_s *); 00070 void *(*data_clone)(void *myvoid); 00075 void (*data_free)(void *myvoid); 00077 struct netsnmp_mib_handler_s *next; 00078 struct netsnmp_mib_handler_s *prev; 00079 } netsnmp_mib_handler; 00080 00081 /* 00082 * per registration flags 00083 */ 00084 #define HANDLER_CAN_GETANDGETNEXT 0x01 /* must be able to do both */ 00085 #define HANDLER_CAN_SET 0x02 /* implies create, too */ 00086 #define HANDLER_CAN_GETBULK 0x04 00087 #define HANDLER_CAN_NOT_CREATE 0x08 /* auto set if ! CAN_SET */ 00088 #define HANDLER_CAN_BABY_STEP 0x10 00089 #define HANDLER_CAN_STASH 0x20 00090 00091 00092 #define HANDLER_CAN_RONLY (HANDLER_CAN_GETANDGETNEXT) 00093 #define HANDLER_CAN_RWRITE (HANDLER_CAN_GETANDGETNEXT | HANDLER_CAN_SET) 00094 #define HANDLER_CAN_SET_ONLY (HANDLER_CAN_SET | HANDLER_CAN_NOT_CREATE) 00095 #define HANDLER_CAN_DEFAULT (HANDLER_CAN_RONLY | HANDLER_CAN_NOT_CREATE) 00096 00106 typedef struct netsnmp_handler_registration_s { 00107 00109 char *handlerName; 00111 char *contextName; 00112 00116 oid *rootoid; 00117 size_t rootoid_len; 00118 00122 netsnmp_mib_handler *handler; 00123 int modes; 00124 00128 int priority; 00129 int range_subid; 00130 oid range_ubound; 00131 int timeout; 00132 int global_cacheid; 00133 00137 void * my_reg_void; 00138 00139 } netsnmp_handler_registration; 00140 00141 /* 00142 * function handler definitions 00143 */ 00144 00145 typedef int (Netsnmp_Node_Handler) (netsnmp_mib_handler *handler, 00147 netsnmp_handler_registration *reginfo, 00149 netsnmp_agent_request_info *reqinfo, 00150 netsnmp_request_info *requests); 00151 00152 typedef struct netsnmp_handler_args_s { 00153 netsnmp_mib_handler *handler; 00154 netsnmp_handler_registration *reginfo; 00155 netsnmp_agent_request_info *reqinfo; 00156 netsnmp_request_info *requests; 00157 } netsnmp_handler_args; 00158 00159 typedef struct netsnmp_delegated_cache_s { 00160 int transaction_id; 00161 netsnmp_mib_handler *handler; 00162 netsnmp_handler_registration *reginfo; 00163 netsnmp_agent_request_info *reqinfo; 00164 netsnmp_request_info *requests; 00165 void *localinfo; 00166 } netsnmp_delegated_cache; 00167 00168 /* 00169 * handler API functions 00170 */ 00171 void netsnmp_init_handler_conf(void); 00172 int netsnmp_register_handler(netsnmp_handler_registration 00173 *reginfo); 00174 int netsnmp_unregister_handler(netsnmp_handler_registration 00175 *reginfo); 00176 int 00177 netsnmp_register_handler_nocallback(netsnmp_handler_registration 00178 *reginfo); 00179 int netsnmp_inject_handler(netsnmp_handler_registration 00180 *reginfo, 00181 netsnmp_mib_handler *handler); 00182 int 00183 netsnmp_inject_handler_before(netsnmp_handler_registration *reginfo, 00184 netsnmp_mib_handler *handler, 00185 const char *before_what); 00186 netsnmp_mib_handler 00187 *netsnmp_find_handler_by_name(netsnmp_handler_registration 00188 *reginfo, const char *name); 00189 void 00190 *netsnmp_find_handler_data_by_name(netsnmp_handler_registration 00191 *reginfo, const char *name); 00192 int netsnmp_call_handlers(netsnmp_handler_registration 00193 *reginfo, 00194 netsnmp_agent_request_info 00195 *reqinfo, 00196 netsnmp_request_info *requests); 00197 int netsnmp_call_handler(netsnmp_mib_handler *next_handler, 00198 netsnmp_handler_registration 00199 *reginfo, 00200 netsnmp_agent_request_info 00201 *reqinfo, 00202 netsnmp_request_info *requests); 00203 int netsnmp_call_next_handler(netsnmp_mib_handler *current, 00204 netsnmp_handler_registration 00205 *reginfo, 00206 netsnmp_agent_request_info 00207 *reqinfo, 00208 netsnmp_request_info 00209 *requests); 00210 int netsnmp_call_next_handler_one_request(netsnmp_mib_handler *current, 00211 netsnmp_handler_registration *reginfo, 00212 netsnmp_agent_request_info *reqinfo, 00213 netsnmp_request_info *requests); 00214 00215 netsnmp_mib_handler *netsnmp_create_handler(const char *name, 00216 Netsnmp_Node_Handler * 00217 handler_access_method); 00218 netsnmp_handler_registration * 00219 netsnmp_handler_registration_create(const char *name, 00220 netsnmp_mib_handler *handler, 00221 const oid * reg_oid, size_t reg_oid_len, 00222 int modes); 00223 netsnmp_handler_registration * 00224 netsnmp_create_handler_registration(const char *name, Netsnmp_Node_Handler* 00225 handler_access_method, 00226 const oid *reg_oid, size_t reg_oid_len, 00227 int modes); 00228 00229 netsnmp_delegated_cache 00230 *netsnmp_create_delegated_cache(netsnmp_mib_handler *, 00231 netsnmp_handler_registration *, 00232 netsnmp_agent_request_info *, 00233 netsnmp_request_info *, void *); 00234 void netsnmp_free_delegated_cache(netsnmp_delegated_cache *dcache); 00235 netsnmp_delegated_cache 00236 *netsnmp_handler_check_cache(netsnmp_delegated_cache *dcache); 00237 void netsnmp_register_handler_by_name(const char *, 00238 netsnmp_mib_handler 00239 *); 00240 00241 void netsnmp_clear_handler_list(void); 00242 00243 void 00244 netsnmp_request_add_list_data(netsnmp_request_info *request, 00245 netsnmp_data_list *node); 00246 int netsnmp_request_remove_list_data(netsnmp_request_info *request, 00247 const char *name); 00248 00249 int 00250 netsnmp_request_remove_list_data(netsnmp_request_info *request, 00251 const char *name); 00252 00253 void *netsnmp_request_get_list_data(netsnmp_request_info 00254 *request, 00255 const char *name); 00256 00257 void 00258 netsnmp_free_request_data_set(netsnmp_request_info *request); 00259 00260 void 00261 netsnmp_free_request_data_sets(netsnmp_request_info *request); 00262 00263 void netsnmp_handler_free(netsnmp_mib_handler *); 00264 netsnmp_mib_handler *netsnmp_handler_dup(netsnmp_mib_handler *); 00265 netsnmp_handler_registration 00266 *netsnmp_handler_registration_dup(netsnmp_handler_registration *); 00267 void 00268 netsnmp_handler_registration_free(netsnmp_handler_registration *); 00269 00270 #define REQUEST_IS_DELEGATED 1 00271 #define REQUEST_IS_NOT_DELEGATED 0 00272 void 00273 netsnmp_handler_mark_requests_as_delegated(netsnmp_request_info *, 00274 int); 00275 void *netsnmp_handler_get_parent_data(netsnmp_request_info *, 00276 const char *); 00277 00278 #ifdef __cplusplus 00279 } 00280 #endif 00281 00282 #endif /* AGENT_HANDLER_H */ 00283