| 1 |
#include <net-snmp/net-snmp-config.h> |
| 2 |
#include <net-snmp/net-snmp-includes.h> |
| 3 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 4 |
#include "updates.h" |
| 5 |
|
| 6 |
static int |
| 7 |
handle_updates(netsnmp_mib_handler *handler, |
| 8 |
netsnmp_handler_registration *reginfo, |
| 9 |
netsnmp_agent_request_info *reqinfo, |
| 10 |
netsnmp_request_info *requests) |
| 11 |
{ |
| 12 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 13 |
int *set = (int*)handler->myvoid; |
| 14 |
|
| 15 |
if (reqinfo->mode == MODE_SET_RESERVE1 && *set < 0) |
| 16 |
netsnmp_request_set_error(requests, SNMP_ERR_NOTWRITABLE); |
| 17 |
else if (reqinfo->mode == MODE_SET_COMMIT) { |
| 18 |
*set = 1; |
| 19 |
snmp_store_needed(reginfo->handlerName); |
| 20 |
} |
| 21 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 22 |
return SNMP_ERR_NOERROR; |
| 23 |
} |
| 24 |
|
| 25 |
netsnmp_handler_registration* |
| 26 |
netsnmp_create_update_handler_registration( |
| 27 |
const char* name, const oid* id, size_t idlen, int mode, int* set) |
| 28 |
{ |
| 29 |
netsnmp_handler_registration *res; |
| 30 |
netsnmp_mib_handler *hnd; |
| 31 |
|
| 32 |
hnd = netsnmp_create_handler("update", handle_updates); |
| 33 |
if (hnd == NULL) |
| 34 |
return NULL; |
| 35 |
|
| 36 |
hnd->flags |= MIB_HANDLER_AUTO_NEXT; |
| 37 |
hnd->myvoid = set; |
| 38 |
|
| 39 |
res = netsnmp_handler_registration_create(name, hnd, id, idlen, mode); |
| 40 |
if (res == NULL) { |
| 41 |
netsnmp_handler_free(hnd); |
| 42 |
return NULL; |
| 43 |
} |
| 44 |
|
| 45 |
return res; |
| 46 |
} |