X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=userapps%2Fopensource%2Fnet-snmp%2Fagent%2Fhelpers%2Fserialize.c;fp=userapps%2Fopensource%2Fnet-snmp%2Fagent%2Fhelpers%2Fserialize.c;h=d875c6ca2e3e1291fea7133ca5e6db42c60c5401;hb=9dffd9f7659a1b28265e0dc9497343eb3d108d02;hp=0000000000000000000000000000000000000000;hpb=e48c2529a5a7e7dbf1797bb6d1bf964bc03e78a7;p=bcm963xx.git diff --git a/userapps/opensource/net-snmp/agent/helpers/serialize.c b/userapps/opensource/net-snmp/agent/helpers/serialize.c new file mode 100644 index 00000000..d875c6ca --- /dev/null +++ b/userapps/opensource/net-snmp/agent/helpers/serialize.c @@ -0,0 +1,100 @@ +#include + +#if HAVE_STRING_H +#include +#else +#include +#endif + +#include +#include + +#include + +#if HAVE_DMALLOC_H +#include +#endif + +/** @defgroup serialize serialize: Calls sub handlers one request at a time. + * @ingroup handler + * This functionally passes in one request at a time + * into lower handlers rather than a whole bunch of requests at once. + * This is useful for handlers that don't want to iterate through the + * request lists themselves. Generally, this is probably less + * efficient so use with caution. The serialize handler might be + * useable to dynamically fix handlers with broken looping code, + * however. + * @{ + */ + +/** returns a serialize handler that can be injected into a given + * handler chain. + */ +netsnmp_mib_handler * +netsnmp_get_serialize_handler(void) +{ + return netsnmp_create_handler("serialize", + netsnmp_serialize_helper_handler); +} + +/** functionally the same as calling netsnmp_register_handler() but also + * injects a serialize handler at the same time for you. */ +int +netsnmp_register_serialize(netsnmp_handler_registration *reginfo) +{ + netsnmp_inject_handler(reginfo, netsnmp_get_serialize_handler()); + return netsnmp_register_handler(reginfo); +} + +/** Implements the serial handler */ +int +netsnmp_serialize_helper_handler(netsnmp_mib_handler *handler, + netsnmp_handler_registration *reginfo, + netsnmp_agent_request_info *reqinfo, + netsnmp_request_info *requests) +{ + + netsnmp_request_info *request, *requesttmp; + + DEBUGMSGTL(("helper:serialize", "Got request\n")); + /* + * loop through requests + */ + for (request = requests; request; request = request->next) { + int ret; + + /* + * store next pointer and delete it + */ + requesttmp = request->next; + request->next = NULL; + + /* + * call the next handler + */ + ret = + netsnmp_call_next_handler(handler, reginfo, reqinfo, request); + + /* + * restore original next pointer + */ + request->next = requesttmp; + + if (ret != SNMP_ERR_NOERROR) + return ret; + } + + return SNMP_ERR_NOERROR; +} + +/** + * initializes the serialize helper which then registers a serialize + * handler as a run-time injectable handler for configuration file + * use. + */ +void +netsnmp_init_serialize(void) +{ + netsnmp_register_handler_by_name("serialize", + netsnmp_get_serialize_handler()); +}