/** * This function injects a "read only" handler into the handler chain * prior to serializing/registering the handler. * * The only purpose of this "read only" handler is to return an * appropriate error for any requests passed to it in a SET mode. * Inserting it into your handler chain will ensure you're never * asked to perform a SET request so you can ignore those error * conditions. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * a read only instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_read_only_instance(netsnmp_handler_registration *reginfo) { netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_read_only_handler()); return netsnmp_register_serialize(reginfo); }
/** * This function registers an instance helper handler, which is a way of * registering an exact OID such that GENEXT requests are handled entirely * by the helper. First need to inject it into the calling chain of the * handler defined by the netsnmp_handler_registration struct, reginfo. * The new handler is injected at the top of the list and will be the new * handler to be called first. This function also injects a serialize * handler before actually calling netsnmp_register_handle, registering * reginfo. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * an instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *handler = netsnmp_get_instance_handler(); handler->flags |= MIB_HANDLER_INSTANCE; netsnmp_inject_handler(reginfo, handler); return netsnmp_register_serialize(reginfo); }
int netsnmp_register_scalar_group(netsnmp_handler_registration *reginfo, oid first, oid last) { netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_scalar_group_handler(first, last)); return netsnmp_register_serialize(reginfo); }
int netsnmp_register_scalar_group(netsnmp_handler_registration *reginfo, oid first, oid last) { reginfo->rootoid = realloc(reginfo->rootoid, (reginfo->rootoid_len+2) * sizeof(oid) ); reginfo->rootoid[ reginfo->rootoid_len ] = 0; reginfo->rootoid[ reginfo->rootoid_len+1 ] = 0; netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_scalar_group_handler(first, last)); return netsnmp_register_serialize(reginfo); }
int netsnmp_register_scalar(netsnmp_handler_registration *reginfo) { /* * Extend the registered OID with space for the instance subid * (but don't extend the length just yet!) */ reginfo->rootoid = realloc(reginfo->rootoid, (reginfo->rootoid_len+1) * sizeof(oid) ); reginfo->rootoid[ reginfo->rootoid_len ] = 0; netsnmp_inject_handler(reginfo, netsnmp_get_instance_handler()); netsnmp_inject_handler(reginfo, netsnmp_get_scalar_handler()); return netsnmp_register_serialize(reginfo); }
/** * This function registers an instance helper handler, which is a way of * registering an exact OID such that GENEXT requests are handled entirely * by the helper. First need to inject it into the calling chain of the * handler defined by the netsnmp_handler_registration struct, reginfo. * The new handler is injected at the top of the list and will be the new * handler to be called first. This function also injects a serialize * handler before actually calling netsnmp_register_handle, registering * reginfo. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * an instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *handler = netsnmp_get_instance_handler(); if (handler) { handler->flags |= MIB_HANDLER_INSTANCE; if (netsnmp_inject_handler(reginfo, handler) == SNMPERR_SUCCESS) return netsnmp_register_serialize(reginfo); } snmp_log(LOG_ERR, "failed to register instance\n"); netsnmp_handler_free(handler); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }
/** * This function injects a "read only" handler into the handler chain * prior to serializing/registering the handler. * * The only purpose of this "read only" handler is to return an * appropriate error for any requests passed to it in a SET mode. * Inserting it into your handler chain will ensure you're never * asked to perform a SET request so you can ignore those error * conditions. * * @param reginfo a handler registration structure which could get created * using netsnmp_create_handler_registration. Used to register * a read only instance helper handler. * * @return * MIB_REGISTERED_OK is returned if the registration was a success. * Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */ int netsnmp_register_read_only_instance(netsnmp_handler_registration *reginfo) { netsnmp_mib_handler *h1, *h2; if (!reginfo) return MIB_REGISTRATION_FAILED; h1 = netsnmp_get_instance_handler(); h2 = netsnmp_get_read_only_handler(); if (h1 && h2 && netsnmp_inject_handler(reginfo, h1) == SNMPERR_SUCCESS) { h1 = NULL; if (netsnmp_inject_handler(reginfo, h2) == SNMPERR_SUCCESS) return netsnmp_register_serialize(reginfo); } snmp_log(LOG_ERR, "failed to register read only instance\n"); netsnmp_handler_free(h1); netsnmp_handler_free(h2); netsnmp_handler_registration_free(reginfo); return MIB_REGISTRATION_FAILED; }