Debian Codegraph @

agent/mibgroup/disman/expr/expObjectConf.c

raw
1 /*
2 * DisMan Expression MIB:
3 * Implementation of the object table configuration handling.
4 */
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-features.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10 #include "utilities/iquery.h"
11 #include "disman/expr/expObject.h"
12 #include "disman/expr/expObjectConf.h"
13
14 netsnmp_feature_require(iquery);
15
16 /* Initializes the expObjectConf module */
17 void
18 init_expObjectConf(void)
19 {
20 init_expObject_table_data();
21
22 /*
23 * Register config handler for persistent storage
24 * of dynamically configured entries.
25 */
26 snmpd_register_config_handler("_expOTable", parse_expOTable, NULL, NULL);
27
28 /*
29 * Register to save (non-fixed) entries when the agent shuts down
30 */
31 snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
32 store_expOTable, NULL);
33 }
34
35
36
37 /* ================================================
38 *
39 * Handlers for loading/storing persistent expression entries
40 *
41 * ================================================ */
42
43 char *
44 _parse_expOCols( char *line, struct expObject *entry )
45 {
46 void *vp;
47 size_t tmp;
48
49 vp = entry->expObjectID;
50 entry->expObjectID_len = MAX_OID_LEN;
51 line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
52 &entry->expObjectID_len);
53
54 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
55 entry->expObjectSampleType = tmp;
56
57 vp = entry->expObjDeltaD;
58 entry->expObjDeltaD_len = MAX_OID_LEN;
59 line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
60 &entry->expObjDeltaD_len);
61
62 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
63 entry->expObjDiscontinuityType = tmp;
64
65 vp = entry->expObjCond;
66 entry->expObjCond_len = MAX_OID_LEN;
67 line = read_config_read_data(ASN_OBJECT_ID, line, &vp,
68 &entry->expObjCond_len);
69
70 line = read_config_read_data(ASN_UNSIGNED, line, &tmp, NULL);
71 entry->flags |= tmp;
72
73 return line;
74 }
75
76
77 void
78 parse_expOTable(const char *token, char *line)
79 {
80 char owner[EXP_STR1_LEN+1];
81 char oname[EXP_STR1_LEN+1];
82 long idx;
83 void *vp;
84 size_t len;
85 struct expObject *entry;
86
87 DEBUGMSGTL(("disman:expr:conf", "Parsing mteObjectTable config... "));
88
89 /*
90 * Read in the index information for this entry
91 * and create a (non-fixed) data structure for it.
92 */
93 memset( owner, 0, sizeof(owner));
94 memset( oname, 0, sizeof(oname));
95 len = EXP_STR1_LEN; vp = owner;
96 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
97 len = EXP_STR1_LEN; vp = oname;
98 line = read_config_read_data(ASN_OCTET_STR, line, &vp, &len);
99 line = read_config_read_data(ASN_UNSIGNED, line, &idx, NULL);
100 entry = expObject_createEntry( owner, oname, idx, 0 );
101
102 DEBUGMSG(("disman:expr:conf", "(%s, %s, %ld) ", owner, oname, idx));
103
104 /*
105 * Read in the accessible column values.
106 */
107 line = _parse_expOCols( line, entry );
108 /*
109 * XXX - Will need to read in the 'iquery' access information
110 */
111 entry->flags |= EXP_OBJ_FLAG_VALID;
112
113 DEBUGMSG(("disman:expr:conf", "\n"));
114 }
115
116
117 int
118 store_expOTable(int majorID, int minorID, void *serverarg, void *clientarg)
119 {
120 char line[SNMP_MAXBUF];
121 char *cptr, *cp;
122 void *vp;
123 size_t tint;
124 netsnmp_tdata_row *row;
125 struct expObject *entry;
126
127
128 DEBUGMSGTL(("disman:expr:conf", "Storing expObjectTable config:\n"));
129
130 for (row = netsnmp_tdata_row_first( expObject_table_data );
131 row;
132 row = netsnmp_tdata_row_next( expObject_table_data, row )) {
133
134 /*
135 * Skip entries that were set up via static config directives
136 */
137 entry = (struct expObject *)netsnmp_tdata_row_entry( row );
138 if ( entry->flags & EXP_OBJ_FLAG_FIXED )
139 continue;
140
141 DEBUGMSGTL(("disman:expr:conf", " Storing (%s %s %lu)\n",
142 entry->expOwner, entry->expName, entry->expObjectIndex));
143
144 /*
145 * Save the basic expObject entry, indexes...
146 */
147 memset(line, 0, sizeof(line));
148 strcat(line, "_expOTable ");
149 cptr = line + strlen(line);
150
151 cp = entry->expOwner; tint = strlen( cp );
152 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
153 cp = entry->expName; tint = strlen( cp );
154 cptr = read_config_store_data( ASN_OCTET_STR, cptr, &cp, &tint );
155 tint = entry->expObjectIndex;
156 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
157
158 /*
159 * ... and column values.
160 */
161 vp = entry->expObjectID;
162 tint = entry->expObjectID_len;
163 cptr = read_config_store_data( ASN_OBJECT_ID, cptr, &vp, &tint );
164 tint = entry->expObjectSampleType;
165 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
166
167 vp = entry->expObjDeltaD;
168 tint = entry->expObjDeltaD_len;
169 cptr = read_config_store_data( ASN_OBJECT_ID, cptr, &vp, &tint );
170 tint = entry->expObjDiscontinuityType;
171 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
172
173 vp = entry->expObjCond;
174 tint = entry->expObjCond_len;
175 cptr = read_config_store_data( ASN_OBJECT_ID, cptr, &vp, &tint );
176
177 tint = entry->flags;
178 cptr = read_config_store_data( ASN_UNSIGNED, cptr, &tint, NULL );
179
180 snmpd_store_config(line);
181 }
182
183 DEBUGMSGTL(("disman:expr:conf", " done.\n"));
184 return SNMPERR_SUCCESS;
185 }