net-snmp 5.7
multiplexer.c
00001 #include <net-snmp/net-snmp-config.h>
00002 
00003 #include <sys/types.h>
00004 
00005 #include <net-snmp/net-snmp-includes.h>
00006 #include <net-snmp/agent/net-snmp-agent-includes.h>
00007 
00008 #include <net-snmp/agent/multiplexer.h>
00009 
00032 netsnmp_mib_handler *
00033 netsnmp_get_multiplexer_handler(netsnmp_mib_handler_methods *req)
00034 {
00035     netsnmp_mib_handler *ret = NULL;
00036 
00037     if (!req) {
00038         snmp_log(LOG_INFO,
00039                  "netsnmp_get_multiplexer_handler(NULL) called\n");
00040         return NULL;
00041     }
00042 
00043     ret =
00044         netsnmp_create_handler("multiplexer",
00045                                netsnmp_multiplexer_helper_handler);
00046     if (ret) {
00047         ret->myvoid = (void *) req;
00048     }
00049     return ret;
00050 }
00051 
00053 int
00054 netsnmp_multiplexer_helper_handler(netsnmp_mib_handler *handler,
00055                                    netsnmp_handler_registration *reginfo,
00056                                    netsnmp_agent_request_info *reqinfo,
00057                                    netsnmp_request_info *requests)
00058 {
00059 
00060     netsnmp_mib_handler_methods *methods;
00061 
00062     if (!handler->myvoid) {
00063         snmp_log(LOG_INFO, "improperly registered multiplexer found\n");
00064         return SNMP_ERR_GENERR;
00065     }
00066 
00067     methods = (netsnmp_mib_handler_methods *) handler->myvoid;
00068 
00069     switch (reqinfo->mode) {
00070     case MODE_GETBULK:
00071         handler = methods->getbulk_handler;
00072         if (handler)
00073             break;
00074         /* Deliberate fallthrough to use GetNext handler */
00075     case MODE_GETNEXT:
00076         handler = methods->getnext_handler;
00077         if (handler)
00078             break;
00079         /* Deliberate fallthrough to use Get handler */
00080     case MODE_GET:
00081         handler = methods->get_handler;
00082         if (!handler) {
00083             netsnmp_request_set_error_all(requests, SNMP_NOSUCHOBJECT);
00084         }
00085         break;
00086 
00087 #ifndef NETSNMP_NO_WRITE_SUPPORT
00088     case MODE_SET_RESERVE1:
00089     case MODE_SET_RESERVE2:
00090     case MODE_SET_ACTION:
00091     case MODE_SET_COMMIT:
00092     case MODE_SET_FREE:
00093     case MODE_SET_UNDO:
00094         handler = methods->set_handler;
00095         if (!handler) {
00096             netsnmp_request_set_error_all(requests, SNMP_ERR_NOTWRITABLE);
00097             return SNMP_ERR_NOERROR;
00098         }
00099         break;
00100 
00101         /*
00102          * XXX: process SETs specially, and possibly others 
00103          */
00104 #endif /* NETSNMP_NO_WRITE_SUPPORT */
00105     default:
00106         snmp_log(LOG_ERR, "unsupported mode for multiplexer: %d\n",
00107                  reqinfo->mode);
00108         return SNMP_ERR_GENERR;
00109     }
00110     if (!handler) {
00111         snmp_log(LOG_ERR,
00112                  "No handler enabled for mode %d in multiplexer\n",
00113                  reqinfo->mode);
00114         return SNMP_ERR_GENERR;
00115     }
00116     return netsnmp_call_handler(handler, reginfo, reqinfo, requests);
00117 }