net-snmp  5.4.1
agent_handler.h
Go to the documentation of this file.
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 *);
00064 
00065         struct netsnmp_mib_handler_s *next;
00066         struct netsnmp_mib_handler_s *prev;
00067 } netsnmp_mib_handler;
00068 
00069 /*
00070  * per registration flags
00071  */
00072 #define HANDLER_CAN_GETANDGETNEXT     0x01       /* must be able to do both */
00073 #define HANDLER_CAN_SET               0x02           /* implies create, too */
00074 #define HANDLER_CAN_GETBULK           0x04
00075 #define HANDLER_CAN_NOT_CREATE        0x08         /* auto set if ! CAN_SET */
00076 #define HANDLER_CAN_BABY_STEP         0x10
00077 #define HANDLER_CAN_STASH             0x20
00078 
00079 
00080 #define HANDLER_CAN_RONLY   (HANDLER_CAN_GETANDGETNEXT)
00081 #define HANDLER_CAN_RWRITE  (HANDLER_CAN_GETANDGETNEXT | HANDLER_CAN_SET)
00082 #define HANDLER_CAN_SET_ONLY (HANDLER_CAN_SET | HANDLER_CAN_NOT_CREATE)
00083 #define HANDLER_CAN_DEFAULT (HANDLER_CAN_RONLY | HANDLER_CAN_NOT_CREATE)
00084 
00094 typedef struct netsnmp_handler_registration_s {
00095 
00097         char           *handlerName;
00099         char           *contextName;    
00100 
00104         oid            *rootoid;
00105         size_t          rootoid_len;
00106 
00110         netsnmp_mib_handler *handler;
00111         int             modes;
00112 
00116         int             priority;
00117         int             range_subid;
00118         oid             range_ubound;
00119         int             timeout;
00120         int             global_cacheid;
00121 
00125         void *          my_reg_void;
00126 
00127 } netsnmp_handler_registration;
00128 
00129 /*
00130  * function handler definitions 
00131  */
00132 
00133 typedef int (Netsnmp_Node_Handler) (netsnmp_mib_handler *handler,
00135     netsnmp_handler_registration *reginfo,
00137     netsnmp_agent_request_info *reqinfo,
00138     netsnmp_request_info *requests);
00139 
00140     typedef struct netsnmp_handler_args_s {
00141         netsnmp_mib_handler *handler;
00142         netsnmp_handler_registration *reginfo;
00143         netsnmp_agent_request_info *reqinfo;
00144         netsnmp_request_info *requests;
00145     } netsnmp_handler_args;
00146 
00147     typedef struct netsnmp_delegated_cache_s {
00148         int             transaction_id;
00149         netsnmp_mib_handler *handler;
00150         netsnmp_handler_registration *reginfo;
00151         netsnmp_agent_request_info *reqinfo;
00152         netsnmp_request_info *requests;
00153         void           *localinfo;
00154     } netsnmp_delegated_cache;
00155 
00156     /*
00157      * handler API functions 
00158      */
00159     void            netsnmp_init_handler_conf(void);
00160     int             netsnmp_register_handler(netsnmp_handler_registration
00161                                              *reginfo);
00162     int             netsnmp_unregister_handler(netsnmp_handler_registration
00163                                                *reginfo);
00164     int            
00165         netsnmp_register_handler_nocallback(netsnmp_handler_registration
00166                                             *reginfo);
00167     int             netsnmp_inject_handler(netsnmp_handler_registration
00168                                            *reginfo,
00169                                            netsnmp_mib_handler *handler);
00170     int
00171         netsnmp_inject_handler_before(netsnmp_handler_registration *reginfo,
00172                                       netsnmp_mib_handler *handler,
00173                                       const char *before_what);
00174     netsnmp_mib_handler
00175         *netsnmp_find_handler_by_name(netsnmp_handler_registration
00176                                       *reginfo, const char *name);
00177     void          
00178         *netsnmp_find_handler_data_by_name(netsnmp_handler_registration
00179                                            *reginfo, const char *name);
00180     int             netsnmp_call_handlers(netsnmp_handler_registration
00181                                           *reginfo,
00182                                           netsnmp_agent_request_info
00183                                           *reqinfo,
00184                                           netsnmp_request_info *requests);
00185     int             netsnmp_call_handler(netsnmp_mib_handler *next_handler,
00186                                          netsnmp_handler_registration
00187                                          *reginfo,
00188                                          netsnmp_agent_request_info
00189                                          *reqinfo,
00190                                          netsnmp_request_info *requests);
00191     int             netsnmp_call_next_handler(netsnmp_mib_handler *current,
00192                                               netsnmp_handler_registration
00193                                               *reginfo,
00194                                               netsnmp_agent_request_info
00195                                               *reqinfo,
00196                                               netsnmp_request_info
00197                                               *requests);
00198     int             netsnmp_call_next_handler_one_request(netsnmp_mib_handler *current,
00199                                                           netsnmp_handler_registration *reginfo,
00200                                                           netsnmp_agent_request_info *reqinfo,
00201                                                           netsnmp_request_info *requests);
00202     
00203     netsnmp_mib_handler *netsnmp_create_handler(const char *name,
00204                                                 Netsnmp_Node_Handler *
00205                                                 handler_access_method);
00206     netsnmp_handler_registration *
00207     netsnmp_handler_registration_create(const char *name,
00208                                         netsnmp_mib_handler *handler,
00209                                         oid * reg_oid, size_t reg_oid_len,
00210                                         int modes);
00211     netsnmp_handler_registration *
00212     netsnmp_create_handler_registration(const char *name, Netsnmp_Node_Handler*
00213                                         handler_access_method, oid *reg_oid,
00214                                         size_t reg_oid_len, int modes);
00215 
00216     NETSNMP_INLINE netsnmp_delegated_cache
00217         *netsnmp_create_delegated_cache(netsnmp_mib_handler *,
00218                                         netsnmp_handler_registration *,
00219                                         netsnmp_agent_request_info *,
00220                                         netsnmp_request_info *, void *);
00221     NETSNMP_INLINE void netsnmp_free_delegated_cache(netsnmp_delegated_cache
00222                                                  *dcache);
00223     NETSNMP_INLINE netsnmp_delegated_cache
00224         *netsnmp_handler_check_cache(netsnmp_delegated_cache *dcache);
00225     void            netsnmp_register_handler_by_name(const char *,
00226                                                      netsnmp_mib_handler
00227                                                      *);
00228 
00229     void            netsnmp_clear_handler_list(void);
00230 
00231     NETSNMP_INLINE void
00232         netsnmp_request_add_list_data(netsnmp_request_info *request,
00233                                       netsnmp_data_list *node);
00234 
00235     NETSNMP_INLINE int
00236         netsnmp_request_remove_list_data(netsnmp_request_info *request,
00237                                          const char *name);
00238 
00239     NETSNMP_INLINE void    *netsnmp_request_get_list_data(netsnmp_request_info
00240                                                   *request,
00241                                                   const char *name);
00242 
00243     NETSNMP_INLINE void
00244               netsnmp_free_request_data_set(netsnmp_request_info *request);
00245 
00246     NETSNMP_INLINE void
00247              netsnmp_free_request_data_sets(netsnmp_request_info *request);
00248 
00249     void            netsnmp_handler_free(netsnmp_mib_handler *);
00250     netsnmp_mib_handler *netsnmp_handler_dup(netsnmp_mib_handler *);
00251     netsnmp_handler_registration
00252         *netsnmp_handler_registration_dup(netsnmp_handler_registration *);
00253     void           
00254         netsnmp_handler_registration_free(netsnmp_handler_registration *);
00255 
00256 #define REQUEST_IS_DELEGATED     1
00257 #define REQUEST_IS_NOT_DELEGATED 0
00258     void           
00259         netsnmp_handler_mark_requests_as_delegated(netsnmp_request_info *,
00260                                                    int);
00261     void           *netsnmp_handler_get_parent_data(netsnmp_request_info *,
00262                                                     const char *);
00263 
00264 #ifdef __cplusplus
00265 }
00266 #endif
00267 
00268 #endif                          /* AGENT_HANDLER_H */
00269