question about config code
David Relson
relson at osagesoftware.com
Mon Nov 25 13:49:30 CET 2002
Gram,
You've overlooked an important detail in the design. NULL pointers are
used for two purposes.
Each entry in the parm_desc struct has a "type" field (CP_ALGORITHM,
CP_INTEGER, etc). A switch statement branches on the type and either does
inline processing to get a value and store it (for simple types like
CP_INTEGER, CP_DOUBLE, etc), or it calls a function to process the
parameter (for CP_ALGORITHM and CP_WORDLIST).
CP_ALGORITH has a NULL pointer because the work is done by function
select_method().
That's the first part of what goes on. There's a second part.
Some options apply to bogofilter as a whole. Some apply to a particular
algorithm, but not to the others. The parm_desc struct in config.c gives
the handling info for the global parameters. The algorithm files
(graham.c, robinson.c, and fisher.c) have their own parm_desc structs for
their private parameters.
When CP_ALGORITHM is encountered, a method pointer is set and the method's
parm_desc struct is retrieved (as a pointer) and saved in global variable
"method". Having this info, process_config_lines) can be called twice -
once to see if the option belongs to the algorithm and, it not found, a
second time to see if it belongs to the global parm_desc. All options
should be found during one of these calls to process_config_line(). If
not, then the option is bogus.
Unfortunately, there's a slight problem with this. Consider the bogofilter
admin who's testing the different algorithms and their options. He/she
will want to change options as easily as possible, likely by using the
'-g', '-r', and '-f' command line switches. He/she will also want a single
config that has options for all the methods. If all config.c knows is the
global options and those that pertain to the selected algorithm, the other
options will generate warning messages (even though they are valid for a
different algorithm). Not good. To avoid this, config.c has dummy entries
at the end of its parm_desc struct for the method specific options. The 4
options currently there are surrounded by #ifdefs and all have NULL
pointers. NULL tells process_config_line() to ignore the value.
I know this is long, but the code is somewhat intricate and tricky. I'll
probably edit this message and convert it to some comments in config.c.
Thanks for looking at code, working to understand it, and pointing out a
piece whose functioning is neither obvious nor documented.
David
More information about the bogofilter-dev
mailing list