Debian Codegraph @

agent/mibgroup/snmp-usm-dh-objects-mib/usmDHUserKeyTable/usmDHUserKeyTable_data_access.c

raw
1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * version : 1.17 $ of : mfd-data-access.m2c,v $
4 *
5 * $Id$
6 */
7 /*
8 * standard Net-SNMP includes
9 */
10 #include <net-snmp/net-snmp-config.h>
11 #include <net-snmp/net-snmp-includes.h>
12 #include <net-snmp/agent/net-snmp-agent-includes.h>
13
14 /*
15 * include our parent header
16 */
17 #include "usmDHUserKeyTable.h"
18
19
20 #include "usmDHUserKeyTable_data_access.h"
21
22 /** @ingroup interface
23 * @addtogroup data_access data_access: Routines to access data
24 *
25 * These routines are used to locate the data used to satisfy
26 * requests.
27 *
28 * @{
29 */
30 /**********************************************************************
31 **********************************************************************
32 ***
33 *** Table usmDHUserKeyTable
34 ***
35 **********************************************************************
36 **********************************************************************/
37 /*
38 * SNMP-USM-DH-OBJECTS-MIB::usmDHUserKeyTable is subid 2 of usmDHPublicObjects.
39 * Its status is Current.
40 * OID: .1.3.6.1.3.101.1.1.2, length: 9
41 */
42
43 /**
44 * initialization for usmDHUserKeyTable data access
45 *
46 * This function is called during startup to allow you to
47 * allocate any resources you need for the data table.
48 *
49 * @param usmDHUserKeyTable_reg
50 * Pointer to usmDHUserKeyTable_registration
51 *
52 * @retval MFD_SUCCESS : success.
53 * @retval MFD_ERROR : unrecoverable error.
54 */
55 int
56 usmDHUserKeyTable_init_data(usmDHUserKeyTable_registration *
57 usmDHUserKeyTable_reg)
58 {
59 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_init_data",
60 "called\n"));
61
62 /*
63 * TODO:303:o: Initialize usmDHUserKeyTable data.
64 */
65
66 return MFD_SUCCESS;
67 } /* usmDHUserKeyTable_init_data */
68
69 /**
70 * container overview
71 *
72 */
73
74 /**
75 * container initialization
76 *
77 * @param container_ptr_ptr A pointer to a container pointer. If you
78 * create a custom container, use this parameter to return it
79 * to the MFD helper. If set to NULL, the MFD helper will
80 * allocate a container for you.
81 * @param cache A pointer to a cache structure. You can set the timeout
82 * and other cache flags using this pointer.
83 *
84 * This function is called at startup to allow you to customize certain
85 * aspects of the access method. For the most part, it is for advanced
86 * users. The default code should suffice for most cases. If no custom
87 * container is allocated, the MFD code will create one for your.
88 *
89 * This is also the place to set up cache behavior. The default, to
90 * simply set the cache timeout, will work well with the default
91 * container. If you are using a custom container, you may want to
92 * look at the cache helper documentation to see if there are any
93 * flags you want to set.
94 *
95 * @remark
96 * This would also be a good place to do any initialization needed
97 * for you data source. For example, opening a connection to another
98 * process that will supply the data, opening a database, etc.
99 */
100 void
101 usmDHUserKeyTable_container_init(netsnmp_container ** container_ptr_ptr,
102 netsnmp_cache * cache)
103 {
104 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_container_init", "called\n"));
105
106 if (NULL == container_ptr_ptr) {
107 snmp_log(LOG_ERR,
108 "bad container param to usmDHUserKeyTable_container_init\n");
109 return;
110 }
111
112 /*
113 * For advanced users, you can use a custom container. If you
114 * do not create one, one will be created for you.
115 */
116 *container_ptr_ptr = NULL;
117
118 if (NULL == cache) {
119 snmp_log(LOG_ERR,
120 "bad cache param to usmDHUserKeyTable_container_init\n");
121 return;
122 }
123
124 /*
125 * TODO:345:A: Set up usmDHUserKeyTable cache properties.
126 *
127 * Also for advanced users, you can set parameters for the
128 * cache. Do not change the magic pointer, as it is used
129 * by the MFD helper. To completely disable caching, set
130 * cache->enabled to 0.
131 *
132 * other tables access our data pool (usm user list), so not caching
133 * is the safest thing to do. The other option would be to add a
134 * callback when the list is changed, or a last changed object to
135 * verify the list hasn't changed. Until then, reload the cache for
136 * every request.
137 */
138 cache->timeout = -1; /* seconds */
139 } /* usmDHUserKeyTable_container_init */
140
141 /**
142 * container shutdown
143 *
144 * @param container_ptr A pointer to the container.
145 *
146 * This function is called at shutdown to allow you to customize certain
147 * aspects of the access method. For the most part, it is for advanced
148 * users. The default code should suffice for most cases.
149 *
150 * This function is called before usmDHUserKeyTable_container_free().
151 *
152 * @remark
153 * This would also be a good place to do any cleanup needed
154 * for you data source. For example, closing a connection to another
155 * process that supplied the data, closing a database, etc.
156 */
157 void
158 usmDHUserKeyTable_container_shutdown(netsnmp_container * container_ptr)
159 {
160 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_container_shutdown", "called\n"));
161
162 if (NULL == container_ptr) {
163 snmp_log(LOG_ERR,
164 "bad params to usmDHUserKeyTable_container_shutdown\n");
165 return;
166 }
167
168 } /* usmDHUserKeyTable_container_shutdown */
169
170 /**
171 * load initial data
172 *
173 * TODO:350:M: Implement usmDHUserKeyTable data load
174 * This function will also be called by the cache helper to load
175 * the container again (after the container free function has been
176 * called to free the previous contents).
177 *
178 * @param container container to which items should be inserted
179 *
180 * @retval MFD_SUCCESS : success.
181 * @retval MFD_RESOURCE_UNAVAILABLE : Can't access data source
182 * @retval MFD_ERROR : other error.
183 *
184 * This function is called to load the index(es) (and data, optionally)
185 * for the every row in the data set.
186 *
187 * @remark
188 * While loading the data, the only important thing is the indexes.
189 * If access to your data is cheap/fast (e.g. you have a pointer to a
190 * structure in memory), it would make sense to update the data here.
191 * If, however, the accessing the data involves more work (e.g. parsing
192 * some other existing data, or performing calculations to derive the data),
193 * then you can limit yourself to setting the indexes and saving any
194 * information you will need later. Then use the saved information in
195 * usmDHUserKeyTable_row_prep() for populating data.
196 *
197 * @note
198 * If you need consistency between rows (like you want statistics
199 * for each row to be from the same time frame), you should set all
200 * data here.
201 *
202 */
203 int
204 usmDHUserKeyTable_container_load(netsnmp_container * container)
205 {
206 usmDHUserKeyTable_rowreq_ctx *rowreq_ctx;
207 struct usmUser *usmuser;
208 size_t count = 0;
209
210 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_container_load", "called\n"));
211
212 /*
213 * TODO:351:M: |-> Load/update data in the usmDHUserKeyTable container.
214 * loop over your usmDHUserKeyTable data, allocate a rowreq context,
215 * set the index(es) [and data, optionally] and insert into
216 * the container.
217 */
218 /*
219 * Retrieve the first user from the USM DB
220 */
221 usmuser = usm_get_userList();
222 if (NULL == usmuser) {
223 return MFD_SUCCESS;
224 }
225
226 for (; usmuser; usmuser = usmuser->next) {
227
228 /*
229 * TODO:352:M: | |-> set indexes in new usmDHUserKeyTable rowreq context.
230 * data context will be set from the first param (unless NULL,
231 * in which case a new data context will be allocated)
232 * the second param will be passed, with the row context, to
233 * usmDHUserKeyTablerowreq_ctx_init.
234 */
235 rowreq_ctx = usmDHUserKeyTable_allocate_rowreq_ctx(usmuser, NULL);
236 if (NULL == rowreq_ctx) {
237 snmp_log(LOG_ERR, "memory allocation failed\n");
238 return MFD_RESOURCE_UNAVAILABLE;
239 }
240 if (MFD_SUCCESS !=
241 usmDHUserKeyTable_indexes_set(rowreq_ctx,
242 usmuser->engineID,
243 usmuser->engineIDLen,
244 usmuser->name,
245 strlen(usmuser->name))) {
246 snmp_log(LOG_ERR,
247 "error setting index while loading "
248 "usmDHUserKeyTable data.\n");
249 usmDHUserKeyTable_release_rowreq_ctx(rowreq_ctx);
250 continue;
251 }
252
253 /*
254 * TODO:352:r: | |-> populate usmDHUserKeyTable data context.
255 * Populate data context here. (optionally, delay until row prep)
256 */
257 /*
258 * non-TRANSIENT data: no need to copy. set pointer to data
259 */
260
261 /*
262 * insert into table container
263 */
264 CONTAINER_INSERT(container, rowreq_ctx);
265 ++count;
266 }
267
268 DEBUGMSGT(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_container_load", "inserted %d records\n", (int)count));
269
270 return MFD_SUCCESS;
271 } /* usmDHUserKeyTable_container_load */
272
273 /**
274 * container clean up
275 *
276 * @param container container with all current items
277 *
278 * This optional callback is called prior to all
279 * item's being removed from the container. If you
280 * need to do any processing before that, do it here.
281 *
282 * @note
283 * The MFD helper will take care of releasing all the row contexts.
284 * If you did not pass a data context pointer when allocating
285 * the rowreq context, the one that was allocated will be deleted.
286 * If you did pass one in, it will not be deleted and that memory
287 * is your responsibility.
288 *
289 */
290 void
291 usmDHUserKeyTable_container_free(netsnmp_container * container)
292 {
293 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_container_free", "called\n"));
294
295 /*
296 * TODO:380:M: Free usmDHUserKeyTable container data.
297 */
298 } /* usmDHUserKeyTable_container_free */
299
300 /**
301 * prepare row for processing.
302 *
303 * When the agent has located the row for a request, this function is
304 * called to prepare the row for processing. If you fully populated
305 * the data context during the index setup phase, you may not need to
306 * do anything.
307 *
308 * @param rowreq_ctx pointer to a context.
309 *
310 * @retval MFD_SUCCESS : success.
311 * @retval MFD_ERROR : other error.
312 */
313 int
314 usmDHUserKeyTable_row_prep(usmDHUserKeyTable_rowreq_ctx * rowreq_ctx)
315 {
316 DEBUGMSGTL(("verbose:usmDHUserKeyTable:usmDHUserKeyTable_row_prep",
317 "called\n"));
318
319 netsnmp_assert(NULL != rowreq_ctx);
320
321 /*
322 * TODO:390:o: Prepare row for request.
323 * If populating row data was delayed, this is the place to
324 * fill in the row for this request.
325 */
326
327 return MFD_SUCCESS;
328 } /* usmDHUserKeyTable_row_prep */
329
330 /** @} */