summaryrefslogtreecommitdiff
path: root/man/netsnmp_read_config.3
blob: e6fbf3d36c0dae4a73875c3dca80918078f7ca75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
.TH "parsing various configuration files at run time" 3 "23 May 2010" "Version 5.4.3.pre1" "net-snmp" \" -*- nroff -*-
.ad l
.nh
.SH NAME
parsing various configuration files at run time \- 
.PP
The read_config related functions are a fairly extensible system of parsing various configuration files at the run time.  

.SS "Defines"

.in +1c
.ti -1c
.RI "#define \fBSNMP_CONFIG_DELIMETERS\fP   ' \\t='"
.br
.in -1c
.SS "Functions"

.in +1c
.ti -1c
.RI "struct \fBconfig_line\fP * \fBregister_prenetsnmp_mib_handler\fP (const char *type, const char *token, void(*parser)(const char *, char *), void(*releaser)(void), const char *help)"
.br
.ti -1c
.RI "struct \fBconfig_line\fP * \fBregister_app_prenetsnmp_mib_handler\fP (const char *token, void(*parser)(const char *, char *), void(*releaser)(void), const char *help)"
.br
.ti -1c
.RI "struct \fBconfig_line\fP * \fBregister_config_handler\fP (const char *type, const char *token, void(*parser)(const char *, char *), void(*releaser)(void), const char *help)"
.br
.RI "\fIregister_config_handler registers handlers for certain tokens specified in certain types of files. \fP"
.ti -1c
.RI "struct \fBconfig_line\fP * \fBregister_app_config_handler\fP (const char *token, void(*parser)(const char *, char *), void(*releaser)(void), const char *help)"
.br
.ti -1c
.RI "void \fBunregister_config_handler\fP (const char *type_param, const char *token)"
.br
.RI "\fIuregister_config_handler un-registers handlers given a specific type_param and token. \fP"
.ti -1c
.RI "void \fBunregister_app_config_handler\fP (const char *token)"
.br
.ti -1c
.RI "void \fBunregister_all_config_handlers\fP ()"
.br
.ti -1c
.RI "struct \fBconfig_line\fP * \fBread_config_get_handlers\fP (const char *type)"
.br
.ti -1c
.RI "void \fBread_config_with_type_when\fP (const char *filename, const char *type, int when)"
.br
.ti -1c
.RI "void \fBread_config_with_type\fP (const char *filename, const char *type)"
.br
.ti -1c
.RI "struct \fBconfig_line\fP * \fBread_config_find_handler\fP (struct \fBconfig_line\fP *line_handlers, const char *token)"
.br
.ti -1c
.RI "int \fBrun_config_handler\fP (struct \fBconfig_line\fP *lptr, const char *token, char *cptr, int when)"
.br
.ti -1c
.RI "int \fBsnmp_config_when\fP (char *line, int when)"
.br
.ti -1c
.RI "int \fBnetsnmp_config\fP (char *line)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_remember_in_list\fP (char *line, struct \fBread_config_memory\fP **mem)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_remember_free_list\fP (struct \fBread_config_memory\fP **mem)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_process_memory_list\fP (struct \fBread_config_memory\fP **memp, int when, int clear)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_remember\fP (char *line)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_process_memories\fP (void)"
.br
.ti -1c
.RI "void \fBnetsnmp_config_process_memories_when\fP (int when, int clear)"
.br
.ti -1c
.RI "void \fBread_config\fP (const char *filename, struct \fBconfig_line\fP *line_handler, int when)"
.br
.ti -1c
.RI "void \fBfree_config\fP (void)"
.br
.ti -1c
.RI "void \fBread_configs_optional\fP (const char *optional_config, int when)"
.br
.ti -1c
.RI "void \fBread_configs\fP (void)"
.br
.ti -1c
.RI "void \fBread_premib_configs\fP (void)"
.br
.ti -1c
.RI "void \fBset_configuration_directory\fP (const char *dir)"
.br
.ti -1c
.RI "const char * \fBget_configuration_directory\fP ()"
.br
.ti -1c
.RI "void \fBset_persistent_directory\fP (const char *dir)"
.br
.ti -1c
.RI "const char * \fBget_persistent_directory\fP ()"
.br
.ti -1c
.RI "void \fBset_temp_file_pattern\fP (const char *pattern)"
.br
.ti -1c
.RI "const char * \fBget_temp_file_pattern\fP ()"
.br
.ti -1c
.RI "void \fBread_config_files\fP (int when)"
.br
.ti -1c
.RI "void \fBread_config_print_usage\fP (const char *lead)"
.br
.ti -1c
.RI "void \fBread_config_store\fP (const char *type, const char *line)"
.br
.RI "\fIread_config_store intended for use by applications to store permenant configuration information generated by sets or persistent counters. \fP"
.ti -1c
.RI "void \fBread_app_config_store\fP (const char *line)"
.br
.ti -1c
.RI "void \fBsnmp_save_persistent\fP (const char *type)"
.br
.ti -1c
.RI "void \fBsnmp_clean_persistent\fP (const char *type)"
.br
.ti -1c
.RI "void \fBconfig_perror\fP (const char *str)"
.br
.ti -1c
.RI "void \fBconfig_pwarn\fP (const char *str)"
.br
.ti -1c
.RI "char * \fBskip_white\fP (char *ptr)"
.br
.ti -1c
.RI "char * \fBskip_not_white\fP (char *ptr)"
.br
.ti -1c
.RI "char * \fBskip_token\fP (char *ptr)"
.br
.ti -1c
.RI "char * \fBcopy_nword\fP (char *from, char *to, int len)"
.br
.ti -1c
.RI "char * \fBcopy_word\fP (char *from, char *to)"
.br
.ti -1c
.RI "char * \fBread_config_save_octet_string\fP (char *saveto, u_char *str, size_t len)"
.br
.ti -1c
.RI "char * \fBread_config_read_octet_string\fP (char *readfrom, u_char **str, size_t *len)"
.br
.ti -1c
.RI "char * \fBread_config_save_objid\fP (char *saveto, oid *objid, size_t len)"
.br
.ti -1c
.RI "char * \fBread_config_read_objid\fP (char *readfrom, oid **objid, size_t *len)"
.br
.ti -1c
.RI "char * \fBread_config_read_data\fP (int type, char *readfrom, void *dataptr, size_t *len)"
.br
.RI "\fIread_config_read_data reads data of a given type from a token(s) on a configuration line. \fP"
.ti -1c
.RI "char * \fBread_config_read_memory\fP (int type, char *readfrom, char *dataptr, size_t *len)"
.br
.ti -1c
.RI "char * \fBread_config_store_data\fP (int type, char *storeto, void *dataptr, size_t *len)"
.br
.RI "\fIread_config_store_data stores data of a given type to a configuration line into the storeto buffer. \fP"
.ti -1c
.RI "char * \fBread_config_store_data_prefix\fP (char prefix, int type, char *storeto, void *dataptr, size_t len)"
.br
.in -1c
.SS "Variables"

.in +1c
.ti -1c
.RI "struct \fBconfig_files\fP * \fBconfig_files\fP = NULL"
.br
.ti -1c
.RI "int \fBlinecount\fP"
.br
.ti -1c
.RI "const char * \fBcurfilename\fP"
.br
.in -1c
.SH "Detailed Description"
.PP 
The read_config related functions are a fairly extensible system of parsing various configuration files at the run time. 

The idea is that the calling application is able to register handlers for certain tokens specified in certain types of files. The read_configs function can then be called to look for all the files that it has registrations for, find the first word on each line, and pass the remainder to the appropriately registered handler.
.PP
For persistent configuration storage you will need to use the read_config_read_data, read_config_store, and read_config_store_data APIs in conjunction with first registering a callback so when the agent shutsdown for whatever reason data is written to your configuration files. The following explains in more detail the sequence to make this happen.
.PP
This is the callback registration API, you need to call this API with the appropriate parameters in order to configure persistent storage needs.
.PP
int snmp_register_callback(int major, int minor, SNMPCallback *new_callback, void *arg);
.PP
You will need to set major to SNMP_CALLBACK_LIBRARY, minor to SNMP_CALLBACK_STORE_DATA. arg is whatever you want.
.PP
Your callback function's prototype is: int (SNMPCallback) (int majorID, int minorID, void *serverarg, void *clientarg);
.PP
The majorID, minorID and clientarg are what you passed in the callback registration above. When the callback is called you have to essentially transfer all your state from memory to disk. You do this by generating configuration lines into a buffer. The lines are of the form token followed by token parameters.
.PP
Finally storing is done using read_config_store(type, buffer); type is the application name this can be obtained from:
.PP
netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE);
.PP
Now, reading back the data: This is done by registering a config handler for your token using the register_config_handler function. Your handler will be invoked and you can parse in the data using the read_config_read APIs. 
.SH "Function Documentation"
.PP 
.SS "char* read_config_read_data (int type, char * readfrom, void * dataptr, size_t * len)"
.PP
read_config_read_data reads data of a given type from a token(s) on a configuration line. The supported types are:
.PP
.IP "\(bu" 2
ASN_INTEGER
.IP "\(bu" 2
ASN_TIMETICKS
.IP "\(bu" 2
ASN_UNSIGNED
.IP "\(bu" 2
ASN_OCTET_STR
.IP "\(bu" 2
ASN_BIT_STR
.IP "\(bu" 2
ASN_OBJECT_ID
.PP
.PP
\fBParameters:\fP
.RS 4
\fItype\fP the asn data type to be read in.
.br
\fIreadfrom\fP the configuration line data to be read.
.br
\fIdataptr\fP an allocated pointer expected to match the type being read (int *, u_int *, char **, oid **)
.br
\fIlen\fP is the length of an asn oid or octet/bit string, not required for the asn integer, unsigned integer, and timeticks types
.RE
.PP
\fBReturns:\fP
.RS 4
the next token in the configuration line. NULL if none left or if an unknown type. 
.RE
.PP

.PP
Definition at line 1836 of file read_config.c.
.SS "void read_config_store (const char * type, const char * line)"
.PP
read_config_store intended for use by applications to store permenant configuration information generated by sets or persistent counters. Appends line to a file named either ENV(SNMP_PERSISTENT_FILE) or '<NETSNMP_PERSISTENT_DIRECTORY>/<type>.conf'. Adds a trailing newline to the stored file if necessary.
.PP
\fBParameters:\fP
.RS 4
\fItype\fP is the application name 
.br
\fIline\fP is the configuration line written to the application name's configuration file
.RE
.PP
\fBReturns:\fP
.RS 4
void 
.RE
.PP

.PP
Definition at line 1272 of file read_config.c.
.SS "char* read_config_store_data (int type, char * storeto, void * dataptr, size_t * len)"
.PP
read_config_store_data stores data of a given type to a configuration line into the storeto buffer. Calls read_config_store_data_prefix with the prefix parameter set to a char space. The supported types are:
.PP
.IP "\(bu" 2
ASN_INTEGER
.IP "\(bu" 2
ASN_TIMETICKS
.IP "\(bu" 2
ASN_UNSIGNED
.IP "\(bu" 2
ASN_OCTET_STR
.IP "\(bu" 2
ASN_BIT_STR
.IP "\(bu" 2
ASN_OBJECT_ID
.PP
.PP
\fBParameters:\fP
.RS 4
\fItype\fP the asn data type to be stored
.br
\fIstoreto\fP a pre-allocated char buffer which will contain the data to be stored
.br
\fIdataptr\fP contains the value to be stored, the supported pointers: (int *, u_int *, char **, oid **)
.br
\fIlen\fP is the length of the value to be stored (not required for the asn integer, unsigned integer, and timeticks types)
.RE
.PP
\fBReturns:\fP
.RS 4
character pointer to the end of the line. NULL if an unknown type. 
.RE
.PP

.PP
Definition at line 1995 of file read_config.c.
.SS "struct \fBconfig_line\fP* register_config_handler (const char * type, const char * token, void(*)(const char *, char *) parser, void(*)(void) releaser, const char * help)\fC [read]\fP"
.PP
register_config_handler registers handlers for certain tokens specified in certain types of files. Allows a \fBmodule\fP writer use/register multiple configuration files based off of the type parameter. A \fBmodule\fP writer may want to set up multiple configuration files to separate out related tasks/variables or just for management of where to put tokens as the \fBmodule\fP or modules get more complex in regard to handling token registrations.
.PP
\fBParameters:\fP
.RS 4
\fItype\fP the configuration file used, e.g., if snmp.conf is the file where the token is located use 'snmp' here. Multiple colon separated tokens might be used. If NULL or '' then the configuration file used will be <application>.conf.
.br
\fItoken\fP the token being parsed from the file. Must be non-NULL.
.br
\fIparser\fP the handler function pointer that use the specified token and the rest of the line to do whatever is required Should be non-NULL in order to make use of this API.
.br
\fIreleaser\fP if non-NULL, the function specified is called if and when the configuration files are re-read. This function should free any resources allocated by the token handler function.
.br
\fIhelp\fP if non-NULL, used to display help information on the expected arguments after the token.
.RE
.PP
\fBReturns:\fP
.RS 4
Pointer to a new config line entry or NULL on error. 
.RE
.PP

.PP
Definition at line 284 of file read_config.c.
.SS "void unregister_config_handler (const char * type_param, const char * token)"
.PP
uregister_config_handler un-registers handlers given a specific type_param and token. \fBParameters:\fP
.RS 4
\fItype_param\fP the configuration file used where the token is located. Used to lookup the config file entry
.br
\fItoken\fP the token that is being unregistered
.RE
.PP
\fBReturns:\fP
.RS 4
void 
.RE
.PP

.PP
Definition at line 315 of file read_config.c.
.SH "Author"
.PP 
Generated automatically by Doxygen for net-snmp from the source code.