diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-26 16:24:03 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-26 16:36:32 +0200 |
commit | 5b29f3ecc4e2edb172d50b23732a588b7a71ce62 (patch) | |
tree | 79b94cbcd5b3a5456ad2a2b2c410886b7e1fb143 /src/config.c | |
parent | 1eeab02e9de4d54178279b347296e98fd97e2a00 (diff) | |
download | wydawca-5b29f3ecc4e2edb172d50b23732a588b7a71ce62.tar.gz wydawca-5b29f3ecc4e2edb172d50b23732a588b7a71ce62.tar.bz2 |
Introduce loadable modules.
* .gitignore: Update.
* configure.ac: Require libtool
Require Grecs tree-api.
* Makefile.am: Incorporate libtool
* bootstrap: Create m4 if it does not exist.
* doc/Makefile.am: Use texi2html
* grecs: Upgrade
* src/module.c: New file.
* src/Makefile.am (wydawca_SOURCES): Add module.c
* src/config.c: Switch callbacks to tree-api.
Add statements for working with modules:
module-load-path, module-prepend-load-path and
module in the global scope and module and
module-config in notify-event blocks.
* src/mail.c (do_notify): Call module_notify if a module
is configured.
* src/tcpwrap.c: Switch callbacks to tree-api.
* src/wydawca.c (main): Load modules.
* src/wydawca.h (notification) <modname>
<modcfg,modnode>: New members.
(module): New struct.
(cb_module,modules_load,module_notify): New functions.
(module_load_path)
(module_prepend_load_path): New globals.
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 201 |
1 files changed, 124 insertions, 77 deletions
diff --git a/src/config.c b/src/config.c index d6f6a89..b381834 100644 --- a/src/config.c +++ b/src/config.c @@ -230,10 +230,10 @@ assert_string_arg(grecs_locus_t *locus, } grecs_value_t * -get_arg(grecs_locus_t *locus, grecs_value_t *value, unsigned n, int type) +get_arg(grecs_value_t *value, unsigned n, int type) { - if (n >= value->v.arg.c) { - grecs_error(locus, 0, _("not enough arguments")); + if (!value || value->type != GRECS_TYPE_ARRAY || n >= value->v.arg.c) { + grecs_error(&value->locus, 0, _("not enough arguments")); return NULL; } value = value->v.arg.v[n]; @@ -246,12 +246,13 @@ get_arg(grecs_locus_t *locus, grecs_value_t *value, unsigned n, int type) } static int -cb_mailer(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_mailer(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { int rc; - + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; + if (assert_string_arg(locus, cmd, value)) return 1; rc = mu_mailer_create(&mailer, value->v.string); @@ -264,12 +265,13 @@ cb_mailer(enum grecs_callback_command cmd, } static int -cb_email_address(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_email_address(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { int rc = 1; mu_address_t addr = NULL; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; struct grecs_list_entry *ep; switch (value->type) { @@ -315,13 +317,14 @@ cb_email_address(enum grecs_callback_command cmd, } static int -cb_interval(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_interval(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { int rc; time_t interval; const char *endp; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; /* FIXME 1: Support arrays */ if (assert_string_arg(locus, cmd, value)) @@ -340,10 +343,12 @@ cb_interval(enum grecs_callback_command cmd, static int cb_absolute_name(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) + grecs_node_t *node, + void *varptr, void *cb_data) { char *word; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; /* FIXME 1: Support arrays */ if (assert_string_arg(locus, cmd, value)) @@ -360,11 +365,13 @@ cb_absolute_name(enum grecs_callback_command cmd, static int cb_set_umask(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) + grecs_node_t *node, + void *varptr, void *cb_data) { char *p; mode_t m; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -474,20 +481,20 @@ parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask) } static int -cb_statistics(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { - return parse_statmask(locus, value, varptr); + return parse_statmask(&node->locus, node->v.value, varptr); } static int -cb_sql_host(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_sql_host(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct sqlconn *pconn = varptr; char *p; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -524,12 +531,13 @@ cb_sql_host(enum grecs_callback_command cmd, } static int -cb_sql(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_sql(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct sqlconn *pconn; void **pdata = cb_data; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; switch (cmd) { case grecs_callback_section_begin: @@ -586,10 +594,12 @@ static struct grecs_keyword sql_kw[] = { }; static int -cb_syslog_facility(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; + if (assert_string_arg(locus, cmd, value)) return 1; @@ -601,11 +611,12 @@ cb_syslog_facility(enum grecs_callback_command cmd, } static int -cb_define_message(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_define_message(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { const char *ident; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (cmd != grecs_callback_set_value) { grecs_error(locus, 0, _("Unexpected block statement")); @@ -684,11 +695,12 @@ get_backup_version(grecs_locus_t *locus, const char *ctx, const char *version) } static int -cb_backup(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_backup(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { enum backup_type *ptype = varptr; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -710,12 +722,13 @@ static struct grecs_keyword archive_kw[] = { }; static int -cb_archive(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_archive(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct archive_descr *arch = varptr; void **pdata = cb_data; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; switch (cmd) { case grecs_callback_section_begin: @@ -783,11 +796,12 @@ static struct grecs_keyword mail_statistics_kw[] = { }; static int -cb_event(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_event(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { enum notification_event *pev = varptr; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -796,11 +810,12 @@ cb_event(enum grecs_callback_command cmd, } static int -cb_recipient(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_recipient(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { enum notification_target *tgt = varptr; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -826,26 +841,34 @@ static struct grecs_keyword notify_event_kw[] = { N_("Sign message with this key"), grecs_type_string, GRECS_DFLT, NULL, offsetof(struct notification, sign_keys) }, + { "module", N_("name"), + N_("Name of the module to invoke on event"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct notification, modname) }, + { "module-config", NULL, + N_("Module-specific configuration data"), + grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL }, { NULL } }; static int -cb_notify_event(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_notify_event(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct notification *ntf; void **pdata = cb_data; + grecs_locus_t *locus = &node->locus; switch (cmd) { case grecs_callback_section_begin: ntf = grecs_zalloc(sizeof(*ntf)); + ntf->modnode = grecs_find_node(node->down, "module-config"); *pdata = ntf; break; case grecs_callback_section_end: ntf = *pdata; - if (!ntf->msg) + if (!ntf->msg && !ntf->modname) grecs_error(locus, 0, _("missing message definition")); else { struct notification **p = @@ -876,11 +899,12 @@ string_to_dictionary_type(const char *str) } static int -cb_dictionary_type(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_dictionary_type(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { enum dictionary_type *ptype = varptr; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -892,12 +916,13 @@ cb_dictionary_type(enum grecs_callback_command cmd, } static int -cb_dictionary_params(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_dictionary_params(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct dictionary *meth = varptr; size_t size; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (cmd != grecs_callback_set_value) { grecs_error(locus, 0, _("Unexpected block statement")); @@ -968,13 +993,14 @@ string_to_dictionary_id(grecs_locus_t *locus, } static int -cb_dictionary(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_dictionary(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct dictionary **pmeth, *meth; void **pdata = cb_data; enum dictionary_id id; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; switch (cmd) { case grecs_callback_section_begin: @@ -1023,12 +1049,13 @@ cb_dictionary(enum grecs_callback_command cmd, } static int -cb_url(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_url(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { mu_url_t *purl = varptr, url; int rc; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -1079,18 +1106,18 @@ static struct grecs_keyword spool_kw[] = { { "check-script", NULL, N_("A /bin/sh script to verify the tarball"), grecs_type_string, GRECS_DFLT, NULL, offsetof(struct spool, check_script) }, - { NULL } }; static int -cb_spool(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_spool(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct spool *spool; void **pdata = cb_data; int rc, ec, i; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; switch (cmd) { case grecs_callback_section_begin: @@ -1165,11 +1192,12 @@ cb_spool(enum grecs_callback_command cmd, } static int -cb_user(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_user(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { struct passwd *pw; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -1187,10 +1215,12 @@ cb_user(enum grecs_callback_command cmd, } static int -cb_supp_groups(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_supp_groups(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; + if (cmd != grecs_callback_set_value) { grecs_error(locus, 0, _("Unexpected block statement")); return 1; @@ -1244,10 +1274,12 @@ static struct grecs_keyword locking_kw[] = { }; static int -cb_locking(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_locking(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; + if (cmd == grecs_callback_set_value) { if (!value || value->type != GRECS_TYPE_STRING) { grecs_error(value ? &value->locus : locus, 0, @@ -1261,11 +1293,12 @@ cb_locking(enum grecs_callback_command cmd, } static int -cb_upload_version(enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, grecs_value_t *value, void *cb_data) +cb_upload_version(enum grecs_callback_command cmd, grecs_node_t *node, + void *varptr, void *cb_data) { unsigned *pversion = varptr, n; + grecs_locus_t *locus = &node->locus; + grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; @@ -1300,6 +1333,20 @@ static struct grecs_keyword wydawca_kw[] = { { "pidfile", N_("file"), N_("Set pid file name"), grecs_type_string, GRECS_DFLT, &pidfile }, + { "module-prepend-load-path", N_("path"), + N_("List of directories searched for modules prior to " + "the default module directory"), + grecs_type_string, GRECS_LIST, + &module_prepend_load_path }, + { "module-load-path", N_("path"), + N_("List of directories searched for database modules."), + grecs_type_string, GRECS_LIST, + &module_load_path }, + + { "module", N_("name: string> <path: string"), + N_("Load the specified module"), + grecs_type_string, GRECS_MULT, NULL, 0, cb_module }, + { "inotify", NULL, N_("Enable or disable inotify support"), grecs_type_bool, GRECS_DFLT, &inotify_enable }, |