Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google
helpers/agent_handler.h File Reference
Main Page   Data Structures   File List   Data Fields   Globals  

agent_handler.h File Reference

Go to the source code of this file.


Data Structures

struct  delegated_cache_s
struct  handler_registration_s
struct  mib_handler_s

Defines

#define HANDLER_CAN_GETANDGETNEXT   0x1
#define HANDLER_CAN_SET   0x2
#define HANDLER_CAN_GETBULK   0x4
#define HANDLER_CAN_RONLY   (HANDLER_CAN_GETANDGETNEXT)
#define HANDLER_CAN_RWRITE   (HANDLER_CAN_GETANDGETNEXT | HANDLER_CAN_SET)
#define HANDLER_CAN_DEFAULT   HANDLER_CAN_RONLY
#define REQUEST_IS_DELEGATED   1
#define REQUEST_IS_NOT_DELEGATED   0

Typedefs

typedef mib_handler_s mib_handler
typedef handler_registration_s handler_registration
typedef delegated_cache_s delegated_cache

Functions

typedef int (NodeHandler)(mib_handler *handler, handler_registration *reginfo, agent_request_info *reqinfo, request_info *requests)
int register_handler (handler_registration *reginfo)
 register a handler, as defined by the handler_registration pointer. More...

int inject_handler (handler_registration *reginfo, mib_handler *handler)
 inject a new handler into the calling chain of the handlers definedy by the handler_registration pointer. More...

mib_handlerfind_handler_by_name (handler_registration *reginfo, char *name)
 Returns a handler from a chain based on the name. More...

void * find_handler_data_by_name (handler_registration *reginfo, char *name)
 Returns a handler's void * pointer from a chain based on the name. More...

int call_handlers (handler_registration *reginfo, agent_request_info *reqinfo, request_info *requests)
int call_handler (mib_handler *next_handler, handler_registration *reginfo, agent_request_info *reqinfo, request_info *requests)
 calls a handler with with appropriate NULL checking, etc. More...

int call_next_handler (mib_handler *current, handler_registration *reginfo, agent_request_info *reqinfo, request_info *requests)
 calls the next handler in the chain after the current one with with appropriate NULL checking, etc. More...

mib_handlercreate_handler (const char *name, NodeHandler *handler_access_method)
 creates a mib_handler structure given a name and a access method. More...

handler_registrationcreate_handler_registration (const char *name, NodeHandler *handler_access_method, oid *reg_oid, size_t reg_oid_len, int modes)
 creates a handler registration structure given a name, a access_method function, a registration location oid and the modes the handler supports. More...

delegated_cachecreate_delegated_cache (mib_handler *, handler_registration *, agent_request_info *, request_info *, void *)
 creates a cache of information which can be saved for future reference. More...

delegated_cachehandler_check_cache (delegated_cache *dcache)
 check's a given cache and returns it if it is still valid (ie, the agent still considers it to be an outstanding request. More...

void request_add_list_data (request_info *request, data_list *node)
void * request_get_list_data (request_info *request, const char *name)
void free_request_data_set (request_info *request)
void free_request_data_sets (request_info *request)
void handler_mark_requests_as_delegated (request_info *, int)
 marks a list of requests as delegated (or not if isdelegaded = 0). More...

void * handler_get_parent_data (request_info *, const char *)

Define Documentation

#define HANDLER_CAN_DEFAULT   HANDLER_CAN_RONLY
 

Definition at line 29 of file helpers/agent_handler.h.

#define HANDLER_CAN_GETANDGETNEXT   0x1
 

Definition at line 23 of file helpers/agent_handler.h.

#define HANDLER_CAN_GETBULK   0x4
 

Definition at line 25 of file helpers/agent_handler.h.

#define HANDLER_CAN_RONLY   (HANDLER_CAN_GETANDGETNEXT)
 

Definition at line 27 of file helpers/agent_handler.h.

#define HANDLER_CAN_RWRITE   (HANDLER_CAN_GETANDGETNEXT | HANDLER_CAN_SET)
 

Definition at line 28 of file helpers/agent_handler.h.

#define HANDLER_CAN_SET   0x2
 

Definition at line 24 of file helpers/agent_handler.h.

#define REQUEST_IS_DELEGATED   1
 

Definition at line 112 of file helpers/agent_handler.h.

#define REQUEST_IS_NOT_DELEGATED   0
 

Definition at line 113 of file helpers/agent_handler.h.


Typedef Documentation

typedef struct delegated_cache_s delegated_cache
 

typedef struct handler_registration_s handler_registration
 

typedef struct mib_handler_s mib_handler
 


Function Documentation

int call_handler mib_handler   next_handler,
handler_registration   reginfo,
agent_request_info   reqinfo,
request_info   requests
[inline]
 

calls a handler with with appropriate NULL checking, etc.

Definition at line 136 of file helpers/agent_handler.c.

Referenced by call_next_handler(), and multiplexer_helper_handler().

00139                                                         {
00140     NodeHandler *nh;
00141     int ret;
00142     
00143     if (next_handler == NULL || reginfo == NULL || reqinfo == NULL ||
00144         requests == NULL) {
00145         snmp_log(LOG_ERR, "call_next_handler() called illegally");
00146         return  SNMP_ERR_GENERR;
00147     }
00148 
00149     nh = next_handler->access_method;
00150     if (!nh) {
00151         snmp_log(LOG_ERR, "no access method specified in handler %s.",
00152                  next_handler->handler_name);
00153         return SNMP_ERR_GENERR;
00154     }
00155 
00156     DEBUGMSGTL(("handler:calling", "calling handler %s\n",
00157                  next_handler->handler_name));
00158 
00159     ret = (*nh)(next_handler, reginfo, reqinfo, requests);
00160 
00161     DEBUGMSGTL(("handler:returned", "handler %s returned %d\n",
00162                  next_handler->handler_name, ret));
00163 
00164     return ret;
00165 }

int call_handlers handler_registration   reginfo,
agent_request_info   reqinfo,
request_info   requests
 

Definition at line 70 of file helpers/agent_handler.c.

Referenced by handle_var_requests().

00072                                                   {
00073     NodeHandler *nh;
00074     int status;
00075     
00076     if (reginfo == NULL || reqinfo == NULL || requests == NULL) {
00077         snmp_log(LOG_ERR, "call_handlers() called illegally");
00078         return  SNMP_ERR_GENERR;
00079     }
00080 
00081     if (reginfo->handler == NULL) {
00082         snmp_log(LOG_ERR, "no handler specified.");
00083         return  SNMP_ERR_GENERR;
00084     }
00085 
00086     switch(reqinfo->mode) {
00087         case MODE_GET:
00088         case MODE_GETNEXT:
00089             if (!(reginfo->modes & HANDLER_CAN_GETANDGETNEXT))
00090                 return SNMP_ERR_NOERROR; /* legal */
00091             break;
00092 
00093         case MODE_SET_RESERVE1:
00094         case MODE_SET_RESERVE2:
00095         case MODE_SET_ACTION:
00096         case MODE_SET_COMMIT:
00097         case MODE_SET_FREE:
00098         case MODE_SET_UNDO:
00099             if (!(reginfo->modes & HANDLER_CAN_SET)) {
00100                 for(; requests; requests = requests->next) {
00101                     set_request_error(reqinfo, requests, SNMP_ERR_NOTWRITABLE);
00102                 }
00103                 return SNMP_ERR_NOERROR;
00104             }
00105             break;
00106 
00107         case MODE_GETBULK:
00108             if (!(reginfo->modes & HANDLER_CAN_GETBULK))
00109                 return SNMP_ERR_NOERROR; /* XXXWWW: should never get
00110                                             here after we force a
00111                                             getbulk->getnext helper on
00112                                             them during registration
00113                                             process. */
00114             break;
00115             
00116         default:
00117             snmp_log(LOG_ERR, "unknown mode in call_handlers! bug!\n");
00118             return SNMP_ERR_GENERR;
00119     }
00120     DEBUGMSGTL(("handler:calling", "calling main handler %s\n",
00121                  reginfo->handler->handler_name));
00122     
00123     nh = reginfo->handler->access_method;
00124     if (!nh) {
00125         snmp_log(LOG_ERR, "no handler access method specified.");
00126         return SNMP_ERR_GENERR;
00127     }
00128 
00129     /* XXX: define acceptable return statuses */
00130     status = (*nh)(reginfo->handler, reginfo, reqinfo, requests);
00131 
00132     return status;
00133 }

int call_next_handler mib_handler   current,
handler_registration   reginfo,
agent_request_info   reqinfo,
request_info   requests
[inline]
 

calls the next handler in the chain after the current one with with appropriate NULL checking, etc.

Definition at line 169 of file helpers/agent_handler.c.

Referenced by instance_helper_handler(), read_only_helper(), serialize_helper_handler(), table_data_helper_handler(), table_data_set_helper_handler(), table_helper_handler(), and table_iterator_helper_handler().

00172                                                              {
00173 
00174     if (current == NULL || reginfo == NULL || reqinfo == NULL ||
00175         requests == NULL) {
00176         snmp_log(LOG_ERR, "call_next_handler() called illegally");
00177         return  SNMP_ERR_GENERR;
00178     }
00179 
00180     return call_handler(current->next, reginfo, reqinfo, requests);
00181 }

delegated_cache* create_delegated_cache mib_handler   handler,
handler_registration   reginfo,
agent_request_info   reqinfo,
request_info   requests,
void *    localinfo
[inline]
 

creates a cache of information which can be saved for future reference.

Use handler_check_cache() later to make sure it's still valid before referencing it in the future.

Definition at line 221 of file helpers/agent_handler.c.

00225                                                              {
00226     delegated_cache *ret;
00227 
00228     ret = SNMP_MALLOC_TYPEDEF(delegated_cache);
00229     if (ret) {
00230         ret->transaction_id = reqinfo->asp->pdu->transid;
00231         ret->handler = handler;
00232         ret->reginfo = reginfo;
00233         ret->reqinfo = reqinfo;
00234         ret->requests = requests;
00235         ret->localinfo = localinfo;
00236     }
00237     return ret;
00238 }

mib_handler* create_handler const char *    name,
NodeHandler *    handler_access_method
 

creates a mib_handler structure given a name and a access method.

Definition at line 185 of file helpers/agent_handler.c.

Referenced by create_handler_registration(), get_instance_handler(), get_multiplexer_handler(), get_old_api_handler(), get_read_only_handler(), get_serialize_handler(), get_table_data_handler(), get_table_data_set_handler(), get_table_handler(), get_table_iterator_handler(), and register_null().

00185                                                                      {
00186     mib_handler *ret = SNMP_MALLOC_TYPEDEF(mib_handler);
00187     ret->handler_name = strdup(name);
00188     ret->access_method = handler_access_method;
00189     return ret;
00190 }

handler_registration* create_handler_registration const char *    name,
NodeHandler *    handler_access_method,
oid *    reg_oid,
size_t    reg_oid_len,
int    modes
 

creates a handler registration structure given a name, a access_method function, a registration location oid and the modes the handler supports.

If modes == 0, then modes will automatically be set to the default value of only HANDLER_CAN_DEFAULT, which is by default.

Definition at line 197 of file helpers/agent_handler.c.

Referenced by config_parse_table_set(), register_long_instance(), register_read_only_counter32_instance(), register_read_only_long_instance(), register_read_only_ulong_instance(), and register_ulong_instance().

00200                                        {
00201     handler_registration *the_reg;
00202     the_reg = SNMP_MALLOC_TYPEDEF(handler_registration);
00203     if (!the_reg)
00204         return NULL;
00205 
00206     if (modes)
00207         the_reg->modes = modes;
00208     else
00209         the_reg->modes = HANDLER_CAN_DEFAULT;
00210 
00211     the_reg->handler = create_handler(name, handler_access_method);
00212     memdup(&the_reg->rootoid, reg_oid, reg_oid_len * sizeof(oid));
00213     the_reg->rootoid_len = reg_oid_len;
00214     return the_reg;
00215 }

mib_handler* find_handler_by_name handler_registration   reginfo,
char *    name
 

Returns a handler from a chain based on the name.

Definition at line 300 of file helpers/agent_handler.c.

Referenced by find_handler_data_by_name().

00301 {
00302     mib_handler *it;
00303     for(it = reginfo->handler; it; it = it->next) {
00304         if (strcmp(it->handler_name, name) == 0) {
00305             return it;
00306         }
00307     }
00308     return NULL;
00309 }

void* find_handler_data_by_name handler_registration   reginfo,
char *    name
 

Returns a handler's void * pointer from a chain based on the name.

This probably shouldn't be used by the general public as the void * data may change as a handler evolves. Handlers should really advertise some function for you to use instead.

Definition at line 316 of file helpers/agent_handler.c.

Referenced by find_table_registration_info().

00318 {
00319     mib_handler *it = find_handler_by_name(reginfo, name);
00320     if (it)
00321         return it->myvoid;
00322     return NULL;
00323 }

void free_request_data_set request_info   request [inline]
 

Definition at line 285 of file helpers/agent_handler.c.

00286 {
00287   if (request)
00288     free_list_data(request->parent_data);
00289 }

void free_request_data_sets request_info   request [inline]
 

Definition at line 292 of file helpers/agent_handler.c.

00293 {
00294   if (request)
00295     free_all_list_data(request->parent_data);
00296 }

delegated_cache* handler_check_cache delegated_cache   dcache [inline]
 

check's a given cache and returns it if it is still valid (ie, the agent still considers it to be an outstanding request.

Returns NULL if it's no longer valid.

Definition at line 244 of file helpers/agent_handler.c.

00245 {
00246     if (!dcache)
00247         return dcache;
00248     
00249     if (check_transaction_id(dcache->transaction_id) == SNMPERR_SUCCESS)
00250         return dcache;
00251 
00252     return NULL;
00253 }

void* handler_get_parent_data request_info  ,
const char *   
 

void handler_mark_requests_as_delegated request_info   requests,
int    isdelegated
 

marks a list of requests as delegated (or not if isdelegaded = 0).

Definition at line 257 of file helpers/agent_handler.c.

00258 {
00259     while(requests) {
00260         requests->delegated = isdelegated;
00261         requests = requests->next;
00262     }
00263 }

int inject_handler handler_registration   reginfo,
mib_handler   handler
 

inject a new handler into the calling chain of the handlers definedy by the handler_registration pointer.

The new handler is injected at the top of the list and hence will be the new handler to be called first.

Definition at line 60 of file helpers/agent_handler.c.

Referenced by register_instance(), register_read_only_instance(), register_read_only_table_data(), register_serialize(), register_table(), register_table_data(), register_table_data_set(), and register_table_iterator().

00060                                                                     {
00061     DEBUGMSGTL(("handler:inject", "injecting %s before %s\n", \
00062                 handler->handler_name, reginfo->handler->handler_name));
00063     handler->next = reginfo->handler;
00064     if (reginfo->handler)
00065         reginfo->handler->prev = handler;
00066     reginfo->handler = handler;
00067     return SNMPERR_SUCCESS;
00068 }

typedef int NodeHandler   
 

int register_handler handler_registration   reginfo
 

register a handler, as defined by the handler_registration pointer.

Definition at line 20 of file helpers/agent_handler.c.

Referenced by register_null(), register_old_api(), register_serialize(), and register_table().

00020                                                 {
00021     mib_handler *handler;
00022     DEBUGIF("handler::register") {
00023         DEBUGMSGTL(("handler::register", "Registering"));
00024         for(handler = reginfo->handler; handler;
00025             handler = handler->next) {
00026             DEBUGMSG(("handler::register"," %s", handler->handler_name));
00027         }
00028             
00029         DEBUGMSG(("handler::register", " at "));
00030         if (reginfo->rootoid) {
00031             DEBUGMSGOID(("handler::register", reginfo->rootoid,
00032                          reginfo->rootoid_len));
00033         } else {
00034             DEBUGMSG(("handler::register", "[null]"));
00035         }
00036         DEBUGMSG(("handler::register", "\n"));
00037     }
00038 
00039     /* don't let them register for absolutely nothing.  Probably a mistake */
00040     if (0 == reginfo->modes) {
00041         reginfo->modes = HANDLER_CAN_DEFAULT;
00042     }
00043 
00044     return register_mib_context2(reginfo->handler->handler_name,
00045                          NULL, 0, 0,
00046                          reginfo->rootoid, reginfo->rootoid_len,
00047                          reginfo->priority,
00048                          reginfo->range_subid, reginfo->range_ubound,
00049                          NULL,
00050                          reginfo->contextName,
00051                          reginfo->timeout,
00052                          0, reginfo);
00053 }

void request_add_list_data request_info   request,
data_list *    node
[inline]
 

Definition at line 266 of file helpers/agent_handler.c.

Referenced by instance_long_handler(), instance_ulong_handler(), old_api_helper(), table_data_helper_handler(), table_data_set_helper_handler(), table_helper_handler(), and table_iterator_helper_handler().

00267 {
00268   if (request) {
00269     if (request->parent_data)
00270       add_list_data(&request->parent_data, node);
00271     else
00272       request->parent_data = node;
00273   }
00274 }

void* request_get_list_data request_info   request,
const char *    name
[inline]
 

Definition at line 277 of file helpers/agent_handler.c.

Referenced by extract_array_context(), extract_iterator_context(), extract_table_data_set(), extract_table_info(), extract_table_row(), instance_long_handler(), instance_ulong_handler(), old_api_helper(), and table_data_set_helper_handler().

00278 {
00279   if (request)
00280     return get_list_data(request->parent_data,name);
00281   return NULL;
00282 }

Generated on Sat Nov 10 14:09:53 2001 for net-snmp by doxygen1.2.11 written by Dimitri van Heesch, © 1997-2001
[an error occurred while processing this directive] [an error occurred while processing this directive]

Valid CSS!


Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.