2 * default_store.h: storage space for defaults
5 #include <net-snmp/net-snmp-config.h>
11 #include <netinet/in.h>
29 #include <net-snmp/types.h>
30 #include <net-snmp/output_api.h>
31 #include <net-snmp/config_api.h>
32 #include <net-snmp/library/default_store.h> /* for "internal" definitions */
33 #include <net-snmp/utilities.h>
35 #include <net-snmp/library/snmp_api.h>
38 static const char * stores [NETSNMP_DS_MAX_IDS] = { "LIB", "APP", "TOK" };
40 typedef struct netsnmp_ds_read_config_s {
46 struct netsnmp_ds_read_config_s *next;
47 } netsnmp_ds_read_config;
49 static netsnmp_ds_read_config *netsnmp_ds_configs = NULL;
51 static int netsnmp_ds_integers[NETSNMP_DS_MAX_IDS][NETSNMP_DS_MAX_SUBIDS];
52 static char netsnmp_ds_booleans[NETSNMP_DS_MAX_IDS][NETSNMP_DS_MAX_SUBIDS/8];
53 static char *netsnmp_ds_strings[NETSNMP_DS_MAX_IDS][NETSNMP_DS_MAX_SUBIDS];
54 static void *netsnmp_ds_voids[NETSNMP_DS_MAX_IDS][NETSNMP_DS_MAX_SUBIDS];
57 * Prototype definitions
59 void netsnmp_ds_handle_config(const char *token, char *line);
62 netsnmp_ds_set_boolean(int storeid, int which, int value)
64 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
65 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
66 return SNMPERR_GENERR;
69 DEBUGMSGTL(("netsnmp_ds_set_boolean", "Setting %s:%d = %d/%s\n",
70 stores[storeid], which, value, ((value) ? "True" : "False")));
73 netsnmp_ds_booleans[storeid][which/8] |= (1 << (which % 8));
75 netsnmp_ds_booleans[storeid][which/8] &= (0xff7f >> (7 - (which % 8)));
78 return SNMPERR_SUCCESS;
82 netsnmp_ds_toggle_boolean(int storeid, int which)
84 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
85 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
86 return SNMPERR_GENERR;
89 if ((netsnmp_ds_booleans[storeid][which/8] & (1 << (which % 8))) == 0) {
90 netsnmp_ds_booleans[storeid][which/8] |= (1 << (which % 8));
92 netsnmp_ds_booleans[storeid][which/8] &= (0xff7f >> (7 - (which % 8)));
95 DEBUGMSGTL(("netsnmp_ds_toggle_boolean", "Setting %s:%d = %d/%s\n",
96 stores[storeid], which, netsnmp_ds_booleans[storeid][which/8],
97 ((netsnmp_ds_booleans[storeid][which/8]) ? "True" : "False")));
99 return SNMPERR_SUCCESS;
103 netsnmp_ds_get_boolean(int storeid, int which)
105 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
106 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
107 return SNMPERR_GENERR;
110 return (netsnmp_ds_booleans[storeid][which/8] & (1 << (which % 8))) ? 1:0;
114 netsnmp_ds_set_int(int storeid, int which, int value)
116 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
117 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
118 return SNMPERR_GENERR;
121 DEBUGMSGTL(("netsnmp_ds_set_int", "Setting %s:%d = %d\n",
122 stores[storeid], which, value));
124 netsnmp_ds_integers[storeid][which] = value;
125 return SNMPERR_SUCCESS;
129 netsnmp_ds_get_int(int storeid, int which)
131 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
132 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
133 return SNMPERR_GENERR;
136 return netsnmp_ds_integers[storeid][which];
140 netsnmp_ds_set_string(int storeid, int which, const char *value)
142 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
143 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
144 return SNMPERR_GENERR;
147 DEBUGMSGTL(("netsnmp_ds_set_string", "Setting %s:%d = \"%s\"\n",
148 stores[storeid], which, (value ? value : "(null)")));
151 * is some silly person is calling us with our own pointer?
153 if (netsnmp_ds_strings[storeid][which] == value)
154 return SNMPERR_SUCCESS;
156 if (netsnmp_ds_strings[storeid][which] != NULL) {
157 free(netsnmp_ds_strings[storeid][which]);
158 netsnmp_ds_strings[storeid][which] = NULL;
162 netsnmp_ds_strings[storeid][which] = strdup(value);
164 netsnmp_ds_strings[storeid][which] = NULL;
167 return SNMPERR_SUCCESS;
171 netsnmp_ds_get_string(int storeid, int which)
173 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
174 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
178 return netsnmp_ds_strings[storeid][which];
182 netsnmp_ds_set_void(int storeid, int which, void *value)
184 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
185 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
186 return SNMPERR_GENERR;
189 DEBUGMSGTL(("netsnmp_ds_set_void", "Setting %s:%d = %x\n",
190 stores[storeid], which, value));
192 netsnmp_ds_voids[storeid][which] = value;
194 return SNMPERR_SUCCESS;
198 netsnmp_ds_get_void(int storeid, int which)
200 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
201 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS) {
205 return netsnmp_ds_voids[storeid][which];
209 netsnmp_ds_handle_config(const char *token, char *line)
211 netsnmp_ds_read_config *drsp;
212 char buf[SNMP_MAXBUF];
213 char *value, *endptr;
216 DEBUGMSGTL(("netsnmp_ds_handle_config", "handling %s\n", token));
218 for (drsp = netsnmp_ds_configs;
219 drsp != NULL && strcasecmp(token, drsp->token) != 0;
223 DEBUGMSGTL(("netsnmp_ds_handle_config",
224 "setting: token=%s, type=%d, id=%s, which=%d\n",
225 drsp->token, drsp->type, stores[drsp->storeid],
228 switch (drsp->type) {
230 value = strtok(line, " \t\n");
231 if (strcasecmp(value, "yes") == 0 ||
232 strcasecmp(value, "true") == 0) {
234 } else if (strcasecmp(value, "no") == 0 ||
235 strcasecmp(value, "false") == 0) {
238 itmp = strtol(value, &endptr, 10);
239 if (*endptr != 0 || itmp < 0 || itmp > 1) {
240 config_perror("Should be yes|no|true|false|0|1");
243 netsnmp_ds_set_boolean(drsp->storeid, drsp->which, itmp);
244 DEBUGMSGTL(("netsnmp_ds_handle_config", "bool: %d\n", itmp));
248 value = strtok(line, " \t\n");
249 itmp = strtol(value, &endptr, 10);
251 config_perror("Bad integer value");
253 netsnmp_ds_set_int(drsp->storeid, drsp->which, itmp);
255 DEBUGMSGTL(("netsnmp_ds_handle_config", "int: %d\n", itmp));
260 copy_nword(line, buf, sizeof(buf));
261 netsnmp_ds_set_string(drsp->storeid, drsp->which, buf);
263 netsnmp_ds_set_string(drsp->storeid, drsp->which, line);
265 DEBUGMSGTL(("netsnmp_ds_handle_config", "string: %s\n", line));
269 snmp_log(LOG_ERR, "netsnmp_ds_handle_config: type %d (0x%02x)\n",
270 drsp->type, drsp->type);
274 snmp_log(LOG_ERR, "netsnmp_ds_handle_config: no registration for %s\n",
281 netsnmp_ds_register_config(u_char type, const char *ftype, const char *token,
282 int storeid, int which)
284 netsnmp_ds_read_config *drsp;
286 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
287 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS || token == NULL) {
288 return SNMPERR_GENERR;
291 if (netsnmp_ds_configs == NULL) {
292 netsnmp_ds_configs = SNMP_MALLOC_TYPEDEF(netsnmp_ds_read_config);
293 drsp = netsnmp_ds_configs;
295 for (drsp = netsnmp_ds_configs; drsp->next != NULL; drsp = drsp->next);
296 drsp->next = SNMP_MALLOC_TYPEDEF(netsnmp_ds_read_config);
301 drsp->ftype = strdup(ftype);
302 drsp->token = strdup(token);
303 drsp->storeid = storeid;
308 register_config_handler(ftype, token, netsnmp_ds_handle_config, NULL,
309 "(1|yes|true|0|no|false)");
313 register_config_handler(ftype, token, netsnmp_ds_handle_config, NULL,
318 register_config_handler(ftype, token, netsnmp_ds_handle_config, NULL,
323 return SNMPERR_SUCCESS;
326 #ifdef BRCM_SNMP_SUPPORT
328 netsnmp_ds_register_premib(u_char type, const char *ftype, const char *token,
329 int storeid, int which)
331 netsnmp_ds_read_config *drsp;
333 if (storeid < 0 || storeid >= NETSNMP_DS_MAX_IDS ||
334 which < 0 || which >= NETSNMP_DS_MAX_SUBIDS || token == NULL) {
335 return SNMPERR_GENERR;
338 if (netsnmp_ds_configs == NULL) {
339 netsnmp_ds_configs = SNMP_MALLOC_TYPEDEF(netsnmp_ds_read_config);
340 drsp = netsnmp_ds_configs;
342 for (drsp = netsnmp_ds_configs; drsp->next != NULL; drsp = drsp->next);
343 drsp->next = SNMP_MALLOC_TYPEDEF(netsnmp_ds_read_config);
348 drsp->ftype = strdup(ftype);
349 drsp->token = strdup(token);
350 drsp->storeid = storeid;
355 register_prenetsnmp_mib_handler(ftype, token, netsnmp_ds_handle_config,
356 NULL, "(1|yes|true|0|no|false)");
360 register_prenetsnmp_mib_handler(ftype, token, netsnmp_ds_handle_config,
361 NULL, "integerValue");
365 register_prenetsnmp_mib_handler(ftype, token, netsnmp_ds_handle_config,
370 return SNMPERR_SUCCESS;
372 #endif /* BRCM_SNMP_SUPPORT */
375 netsnmp_ds_shutdown()
377 netsnmp_ds_read_config *drsp;
380 for (drsp = netsnmp_ds_configs; drsp; drsp = netsnmp_ds_configs) {
381 netsnmp_ds_configs = drsp->next;
383 unregister_config_handler(drsp->ftype, drsp->token);
384 if (drsp->ftype != NULL) {
387 if (drsp->token != NULL) {
393 for (i = 0; i < NETSNMP_DS_MAX_IDS; i++) {
394 for (j = 0; j < NETSNMP_DS_MAX_SUBIDS; j++) {
395 if (netsnmp_ds_strings[i][j] != NULL) {
396 free(netsnmp_ds_strings[i][j]);
397 netsnmp_ds_strings[i][j] = NULL;
403 #else /* BUILD_ILMI */
407 * Prototype definitions
409 void netsnmp_ds_handle_config(const char *token, char *line);
412 netsnmp_ds_set_boolean(int storeid, int which, int value)
414 return SNMPERR_SUCCESS;
418 netsnmp_ds_toggle_boolean(int storeid, int which)
420 return SNMPERR_SUCCESS;
424 netsnmp_ds_get_boolean(int storeid, int which)
426 if (which == NETSNMP_DS_LIB_REVERSE_ENCODE)
428 return SNMPERR_SUCCESS;
432 netsnmp_ds_set_int(int storeid, int which, int value)
434 return SNMPERR_SUCCESS;
438 netsnmp_ds_get_int(int storeid, int which)
440 return SNMPERR_SUCCESS;
444 netsnmp_ds_set_string(int storeid, int which, const char *value)
446 return SNMPERR_SUCCESS;
450 netsnmp_ds_get_string(int storeid, int which)
456 netsnmp_ds_set_void(int storeid, int which, void *value)
458 return SNMPERR_SUCCESS;
462 netsnmp_ds_get_void(int storeid, int which)
468 netsnmp_ds_handle_config(const char *token, char *line)
474 netsnmp_ds_register_config(u_char type, const char *ftype, const char *token,
475 int storeid, int which)
477 return SNMPERR_SUCCESS;
481 netsnmp_ds_register_premib(u_char type, const char *ftype, const char *token,
482 int storeid, int which)
484 return SNMPERR_SUCCESS;
488 netsnmp_ds_shutdown()