diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-08-31 00:30:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-08-31 00:47:47 +0300 |
commit | 53417279dcc6dfd771e09801ccfd9c3178fbea41 (patch) | |
tree | e33c40098851d3c2c3211bda061bca23adc2e9a5 /mfd/prog.c | |
parent | 0aa5927f6bfaf8fa148fb4dfa3c27e14b248fffc (diff) | |
download | mailfromd-53417279dcc6dfd771e09801ccfd9c3178fbea41.tar.gz mailfromd-53417279dcc6dfd771e09801ccfd9c3178fbea41.tar.bz2 |
Begin separation of configuration from filter script.
The purpose is to separate compilation entities (filter script
and files included therein), from the actual runtime configuration.
This changeset introduces a separate mailfromd configuration file,
located in SYSCONFDIR/mailfromd.conf. The filter script is called
mailfromd.mf and located in SYSCONFDIR as well (but perhaps it
should better be located elsewhere?) The old script name,
mailfromd.rc, was a misnomer since its suffix suggested that the
file was a configuration file, which as a matter of fact it was
not. However, if this "legacy" file is present and readable, it is
used and a warning message is issued.
All `#pragma option' statements are considered deprecated, and explicit
warnings are issued if they are used in the script file.
* NEWS: Update.
* mfd/appinit.c: New file.
* mfd/Makefile.am (mailfromd_SOURCES): Add appinit.c
* mfd/gram.y (pragma_option): Update call to set_option.
Pass NULL locus to initialize_variable.
(initialize_variable): Issue the "variable already initialized"
warning only if previous initialization was in a source file,
not from command line or a configuration statement.
* mfd/mailfromd.h (DEFAULT_SCRIPT_FILE): Change definition.
(LEGACY_SCRIPT_FILE): New define.
(DEFAULT_CONFIG_FILE): New define.
(set_option): Takes four arguments.
(mu_app_rcfile): New extern.
(mfd_app_init): New prototype.
* mfd/main.c (need_config): Rename to need_script.
(struct option_cache): Rename `cumulative' to `flags'.
New member `confkw'.
(set_option): Fourth argument specifies whether the
function was called from a pragma option handler.
(set_cmdline_option): New define.
(struct arguments): New data type.
(init_arguments, flush_trace_module)
(flush_arguments, destroy_trace_item): New functions.
(parse_opt): Use set_cmdline_option to set overridable
options.
(cb_trace_program): New callback.
(mf_cfg_param): New statements: syslog-async, trace-actions,
trace-program, transcript.
(main): Use mfd_app_init instead of mu_app_init. Initialize
mu_app_rcfile beforehand.
Use legacy filter script (mailfromd.rc), if present.
* mfd/prog.c (enable_module_trace): take 2 args, the 2nd one
specifying the length of the first.
(disable_module_trace): Likewise.
(toggle_prog_trace): New function.
(enable_prog_trace,disable_prog_trace): Rewrite using
toggle_prog_trace.
* tests/atlocal.in (MFADDOPTS): New variable.
(checkstatedir): Define MFADDOPTS.
(mailfromd_start): Pass $MFADDOPTS to the mailfromd invocation.
* tests/etc/config.in: Remove.
* tests/etc/Makefile.am: Remove config.in
* tests/etc/dns.rc: Remove inclusion of config.rc
* tests/etc/greylist-ct.rc: Likewise.
* tests/etc/greylist.rc: Likewise.
* tests/greylist-ct.at: Likewise.
* tests/hasmx.at, tests/hostname.at, tests/ismx.at,
tests/rescname.at, tests/resolve.at, tests/testsuite.at: Pass
$MFADDOPTS to mailfromd invocations.
* tets/invcidr.at: update stderr expectation
(see changes to initialize_variable in gram.y)
* tests/invcidr2.at: Likewise.
* etc/mailfromd.rc: Rename to etc/mailfromd.mf
* etc/Makefile.am: Rename mailfromd.rc to mailfromd.mf.
Diffstat (limited to 'mfd/prog.c')
-rw-r--r-- | mfd/prog.c | 67 |
1 files changed, 39 insertions, 28 deletions
@@ -170,63 +170,74 @@ unsigned long prog_trace_option = 0; #define PROG_TRACE_ENGINE (prog_trace_option & BUILTIN_MASK_prog) void -enable_module_trace(char *name) +enable_module_trace(const char *name, size_t len) { struct builtin_module *mod; for (mod = builtin_module; mod->name; mod++) - if (strcmp(mod->name, name) == 0) { + if (strlen (mod->name) == len + && memcmp(mod->name, name, len) == 0) { prog_trace_option |= mod->mask; return; } - mu_error(_("no such module: %s"), name); + mu_error(_("no such module: %*.*s"), len, len, name); } void -disable_module_trace(char *name) +disable_module_trace(const char *name, size_t len) { struct builtin_module *mod; for (mod = builtin_module; mod->name; mod++) - if (strcmp(mod->name, name) == 0) { + if (strlen (mod->name) == len + && memcmp(mod->name, name, len) == 0) { prog_trace_option &= ~mod->mask; return; } - mu_error(_("no such module: %s"), name); + mu_error(_("no such module: %*.*s"), len, len, name); } void -enable_prog_trace(const char *modlist) +toggle_prog_trace(const char *modlist, + unsigned long allmask, + unsigned long nonemask, + void (*yesfn)(const char *, size_t), + void (*nofn)(const char *, size_t)) { - if (strcmp(modlist, "all") == 0) { - prog_trace_option = ULONG_MAX; - return; - } else { - char *modcopy, *s; - modcopy = xstrdup(modlist); - - for (s = strtok(modcopy,","); s; s = strtok(NULL, ",")) - enable_module_trace(s); - free(modcopy); + while (1) { + size_t len = strcspn(modlist, ","); + if (len == 3 && memcmp(modlist, "all", 3) == 0) + prog_trace_option = allmask; + else if (len == 4 && memcmp(modlist, "none", 4) == 0) + prog_trace_option = nonemask; + else { + if (len > 3 && memcmp (modlist, "no-", 3) == 0) + nofn(modlist+3, len-3); + else + yesfn(modlist, len); + } + modlist += len; + if (*modlist) + modlist++; + else + break; } } void +enable_prog_trace(const char *modlist) +{ + toggle_prog_trace(modlist, ULONG_MAX, 0, + enable_module_trace, disable_module_trace); +} + +void disable_prog_trace(const char *modlist) { - if (strcmp(modlist, "all") == 0) { - prog_trace_option = 0; - return; - } else { - char *modcopy, *s; - modcopy = xstrdup(modlist); - - for (s = strtok(modcopy,","); s; s = strtok(NULL, ",")) - disable_module_trace(s); - free(modcopy); - } + toggle_prog_trace(modlist, 0, ULONG_MAX, + disable_module_trace, enable_module_trace); } /* ======================================================================== |