net-snmp 5.7
null.c
00001 #include <net-snmp/net-snmp-config.h>
00002 
00003 #include <net-snmp/net-snmp-includes.h>
00004 #include <net-snmp/agent/net-snmp-agent-includes.h>
00005 
00006 #include <net-snmp/agent/null.h>
00007 
00008 #if HAVE_STRING_H
00009 #include <string.h>
00010 #else
00011 #include <strings.h>
00012 #endif
00013 
00014 int
00015 netsnmp_register_null(oid * loc, size_t loc_len)
00016 {
00017     return netsnmp_register_null_context(loc, loc_len, NULL);
00018 }
00019 
00020 int
00021 netsnmp_register_null_context(oid * loc, size_t loc_len,
00022                               const char *contextName)
00023 {
00024     netsnmp_handler_registration *reginfo;
00025     reginfo = SNMP_MALLOC_TYPEDEF(netsnmp_handler_registration);
00026     if (reginfo != NULL) {
00027         reginfo->handlerName = strdup("");
00028         reginfo->rootoid = loc;
00029         reginfo->rootoid_len = loc_len;
00030         reginfo->handler =
00031             netsnmp_create_handler("null", netsnmp_null_handler);
00032         if (contextName)
00033             reginfo->contextName = strdup(contextName);
00034         reginfo->modes = HANDLER_CAN_DEFAULT | HANDLER_CAN_GETBULK;
00035     }
00036     return netsnmp_register_handler(reginfo);
00037 }
00038 
00039 int
00040 netsnmp_null_handler(netsnmp_mib_handler *handler,
00041                      netsnmp_handler_registration *reginfo,
00042                      netsnmp_agent_request_info *reqinfo,
00043                      netsnmp_request_info *requests)
00044 {
00045     DEBUGMSGTL(("helper:null", "Got request\n"));
00046 
00047     DEBUGMSGTL(("helper:null", "  oid:"));
00048     DEBUGMSGOID(("helper:null", requests->requestvb->name,
00049                  requests->requestvb->name_length));
00050     DEBUGMSG(("helper:null", "\n"));
00051 
00052     switch (reqinfo->mode) {
00053     case MODE_GETNEXT:
00054     case MODE_GETBULK:
00055         return SNMP_ERR_NOERROR;
00056 
00057     case MODE_GET:
00058         netsnmp_request_set_error_all(requests, SNMP_NOSUCHOBJECT);
00059         return SNMP_ERR_NOERROR;
00060 
00061     default:
00062         netsnmp_request_set_error_all(requests, SNMP_ERR_NOSUCHNAME);
00063         return SNMP_ERR_NOERROR;
00064     }
00065 }