1 .TH READ_CONFIG 3 "07 Mar 2002" "" "Net-SNMP"
4 register_config_handler, register_premib_handler
5 unregister_config_handler, register_mib_handlers, read_configs,
6 read_premib_configs, config_perror, config_pwarn - read_config functions
8 .B #include <net-snmp/config_api.h>
10 .B struct config_line *
12 .BI " register_config_handler(const char *" filePrefix ",
14 .BI " const char *" token ,
16 .BI " void (*" parser ")(const char *, char *),"
18 .BI " void (*" releaser ")(void),"
20 .BI " const char *"usageLine ");"
22 .B struct config_line *
24 .BI " register_premib_handler(const char *" filePrefix ",
26 .BI " const char *" token ,
28 .BI " void (*" parser ")(const char *, char *),"
30 .BI " void (*" releaser ")(void),"
32 .BI " const char *" usageLine ");"
34 .BI "void unregister_config_handler(const char *" filePrefix ","
36 .BI " const char *" token ");"
38 .B struct config_line *
40 .BI " register_app_config_handler(const char *" token ,
42 .BI " void (*" parser ")(const char *, char *),"
44 .BI " void (*" releaser ")(void),"
46 .BI " const char *"usageLine ");"
48 .B struct config_line *
50 .BI " register_app_premib_handler(const char *" token ,
52 .BI " void (*" parser ")(const char *, char *),"
54 .BI " void (*" releaser ")(void),"
56 .BI " const char *" usageLine ");"
58 .BI "void unregister_app_config_handler(const char *" token ");"
60 .BI "void read_config_print_usage(char *" lead ");"
62 .B "void read_configs(void);"
64 .B "void read_premib_configs(void);"
66 .BI "void config_pwarn(const char *" string ");"
68 .BI "void config_perror(const char *" string ");"
71 The functions are a fairly extensible system of parsing various
72 configuration files at the run time of an application. The
73 configuration file flow is broken into the following phases:
77 Registration of handlers.
80 Reading of the configuration files for pre-MIB parsing requirements.
83 Reading and parsing of the textual MIB files.
86 Reading of the configuration files for configuration directives.
89 Optionally re-reading the configuration files at a future date.
92 The idea is that the calling application is able to register
96 specified in certain types of
100 function can then be called to look for all the files that it has
101 registrations for, find the first word on each line, and pass the
102 remainder to the appropriately registered handler.
105 Handler functions should have the following signature:
108 .BI "void handler(const char *" token ", char *" line ");"
111 The function will be called with two arguments, the first being the
112 token that triggered the call to this function (which would be one of
113 the tokens that the function had been registered for), and the second
114 being the remainder of the configuration file line beyond the white
115 space following the token.
116 .SH RESOURCE FREEING HANDLERS
121 .B register_config_handler
122 is non-NULL, then the function specified is called if and when the
123 configuration files are re-read. This function should free any
124 resources allocated by the token handler function and reset its notion
125 of the configuration to its default. The token handler function will
126 then be called again. No arguments are passed to the resource freeing
128 .SH REGISTERING A HANDLER
130 .B register_config_handler()
133 function above could be registered for the configuration file
137 and the help string (discussed later)
139 using the following call to the
140 .B register_config_handler()
145 register_config_handler("snmp", "genericToken", handler, NULL, "ARG1 [ARG2]");
149 This would register the
151 function so that it will get called every time the first word of a
154 configuration file(s) matches "genericToken" (see
157 .B register_premib_handler()
159 .B register_premib_handler()
160 function works identically to the
161 .B register_config_handler()
162 function but is intended for config file tokens that need to be read
163 in before the textual MIBs are read in, probably because they will be
164 used to configure the MIB parser. It is rarely the case that anything
165 but the SNMP library itself should need to use this function.
167 .B unregister_config_handler()
168 Removes the registered configuration handler for the
174 .B register_app_config_handler()
176 .B register_app_premib_handler()
178 .B unregister_app_config_handler()
179 These functions are analagous to
180 .BR register_config_handler() ", " register_premib_handler() " and "
181 .B unregister_config_handler()
182 but don't require the file type argument (which is filled in by the
183 application). It is intended that MIB modules written for the agent
184 use these functions to allow the agent to have more control over which
185 configuration files are read (typically the
193 .B register_config_handler()
194 and similar calls, is used to display help information when the
195 .B read_config_print_usage()
196 function is called. This function is used by all of the applications
199 flag is passed on the command line. It prints a summary of all of the
200 configuration file lines, and the associated files, that the
201 configuration system understands. The
203 parameter should be a list of arguments expected after the token, and
204 not a lengthy description (which should go into a manual page
207 prefix will be prepended to each line that the function prints to
208 stderr, where it displays its output.
212 function should be called before the
213 .B read_config_print_usage()
214 function is called, so that the library can register its configuration
215 file directives as well for the
216 .B read_config_print_usage()
218 .SH READING CONFIGURATION FILES
221 Once the relevant configuration token parsers have been registered,
223 should be called. It will parse the configuration file tokens
225 .B register_premib_handler(),
226 read in the textual MIB files using
228 and finally parse the configuration file tokens registered with
229 .BR register_config_handler() .
233 function is used, none of the following functions need to be called by
236 .B register_mib_handlers()
237 The SNMP library's routine to register its configuration file
240 .B read_premib_configs()
241 The routine that parses the configuration files for tokens registered
242 to be dealt with before the textual MIBs are read in. See
247 Reads all the configuration files it can find in the
249 environment variable (or its default value) for tokens and
250 appropriately calls the handlers registered to it, or prints a
251 "Unknown token" warning message. It looks for any file that it has
252 previously received a registration request for.
253 .SH CONFIGURATION FILES READ
255 The configuration files read are found by using the colon separated
257 environment variable (or its default value, which will be
258 SYSCONFDIR/snmp, followed by
259 DATADIR/snmp, followed by LIBDIR/snmp, followed by $HOME/.snmp) and
260 reading in the files found that match both the prefix registered and
265 The idea behind the two different suffixes is that the first file can
266 be shared (via rdist or an NFS mount) across a large number of
267 machines and the second file can be used to configure local settings
268 for one particular machine. They do not need to be present, and will
269 only be read if found.
270 .SH ERROR HANDLING FUNCTIONS
276 both take an error string as an argument and print it to stderr along
277 with the file and line number that caused the error. A call to the
278 second function will also force
280 to eventually return with an error code indicating to it's calling
281 function that it should abort the operation of the application.
282 .SH "ENVIRONMENT VARIABLES"
285 A colon separated list of directories to search for configuration
287 Default: SYSCONFDIR/snmp:DATADIR/snmp:LIBDIR/snmp:$HOME/.snmp
289 .BR mib_api "(3), " snmp_api (3)