1 #include <net-snmp/net-snmp-config.h>
10 #include <net-snmp/net-snmp-includes.h>
11 #include <net-snmp/agent/net-snmp-agent-includes.h>
13 #include <net-snmp/agent/scalar.h>
14 #include <net-snmp/agent/serialize.h>
15 #include <net-snmp/agent/read_only.h>
21 /** @defgroup scalar scalar: process scalars easily.
26 netsnmp_get_scalar_handler(void)
28 return netsnmp_create_handler("scalar",
29 netsnmp_scalar_helper_handler);
33 netsnmp_register_scalar(netsnmp_handler_registration *reginfo)
35 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler());
36 return netsnmp_register_serialize(reginfo);
40 netsnmp_register_read_only_scalar(netsnmp_handler_registration *reginfo)
42 netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler());
43 netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler());
44 return netsnmp_register_serialize(reginfo);
49 netsnmp_scalar_helper_handler(netsnmp_mib_handler *handler,
50 netsnmp_handler_registration *reginfo,
51 netsnmp_agent_request_info *reqinfo,
52 netsnmp_request_info *requests)
55 netsnmp_variable_list *var = requests->requestvb;
62 oid build_space[MAX_OID_LEN];
64 DEBUGMSGTL(("helper:scalar", "Got request:\n"));
65 namelen = SNMP_MIN(requests->requestvb->name_length,
66 reginfo->rootoid_len);
67 cmp = snmp_oid_compare(requests->requestvb->name, namelen,
68 reginfo->rootoid, reginfo->rootoid_len);
70 namelen = requests->requestvb->name_length;
71 subid = requests->requestvb->name[namelen-1];
73 DEBUGMSGTL(("helper:scalar", " oid:", cmp));
74 DEBUGMSGOID(("helper:scalar", var->name, var->name_length));
75 DEBUGMSG(("helper:scalar", "\n"));
77 nosuch_err = SNMP_ERR_NOCREATION;
78 switch (reqinfo->mode) {
80 nosuch_err = SNMP_NOSUCHINSTANCE;
83 case MODE_SET_RESERVE1:
84 case MODE_SET_RESERVE2:
90 netsnmp_set_request_error(reqinfo, requests,
92 return SNMP_ERR_NOERROR;
94 if (( namelen != reginfo->rootoid_len+1) ||
96 netsnmp_set_request_error(reqinfo, requests, nosuch_err);
97 return SNMP_ERR_NOERROR;
99 return netsnmp_call_next_handler(handler, reginfo, reqinfo,
107 (cmp == 0 && namelen <= reginfo->rootoid_len) ||
108 (cmp == 0 && namelen == reginfo->rootoid_len+1 &&
109 subid == 0 && requests->inclusive)) {
110 reqinfo->mode = MODE_GET;
111 memcpy(build_space, reginfo->rootoid,
112 reginfo->rootoid_len * sizeof(oid));
113 build_space[reginfo->rootoid_len] = 0; /* add the instance subid */
115 snmp_set_var_objid(requests->requestvb, build_space,
116 reginfo->rootoid_len+1);
118 netsnmp_call_next_handler(handler, reginfo, reqinfo,
120 reqinfo->mode = MODE_GETNEXT;
123 return SNMP_ERR_NOERROR;
128 * got here only if illegal mode found
130 return SNMP_ERR_GENERR;