aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c167
1 files changed, 123 insertions, 44 deletions
diff --git a/src/config.c b/src/config.c
index 13f90ce..ed0bafd 100644
--- a/src/config.c
+++ b/src/config.c
@@ -832,6 +832,26 @@ static void
cfg_mail_admin_stat (gsc_config_file_t *file, char *kw, char *val,
void *unused)
{
+ char *word;
+
+ if (!val)
+ {
+ file->error_msg (file->file_name, file->line,
+ "missing message template identifier");
+ file->error_count++;
+ return;
+ }
+
+ word = get_word (&val);
+
+ admin_stat_message_template = find_message_template (word);
+ if (!admin_stat_message_template)
+ {
+ file->error_msg (file->file_name, file->line,
+ "no such message template: %s", word);
+ file->error_count++;
+ return;
+ }
_cfg_statmask (file, val, &mail_admin_mask);
}
@@ -918,16 +938,43 @@ _cfg_raw_read (gsc_config_file_t *file, char *val, struct obstack *stk)
file->error_count++;
}
}
-
+
static void
-cfg_admin_stat_message (gsc_config_file_t *file, char *kw, char *val,
- void *unused)
+cfg_define_message (gsc_config_file_t *file, char *kw, char *val, void *unused)
{
+ char *word;
+ if (!val)
+ {
+ file->error_msg (file->file_name, file->line,
+ "missing message identifier");
+ file->error_count++;
+ return;
+ }
+
+ word = xstrdup (get_word (&val));
if (_cfg_raw_read (file, val, &cfg_stk) == 0)
- admin_stat_message_template = obstack_finish (&cfg_stk);
+ register_message_template (word, obstack_finish (&cfg_stk));
}
+int
+string_to (char *what, char *str,
+ const char **args, int *vals,
+ int *pret,
+ gsc_config_file_t *file)
+{
+ ptrdiff_t x = ARGMATCH (str, args, vals);
+
+ if (x == (ptrdiff_t)-1)
+ {
+ file->error_msg (file->file_name, file->line,
+ "unknown %s: %s", what, str);
+ file->error_count++;
+ return 1;
+ }
+ *pret = vals[x];
+ return 0;
+}
static const char *event_args[] = {
"success",
@@ -937,7 +984,7 @@ static const char *event_args[] = {
NULL
};
-static enum notification_event event_types[] = {
+static int event_types[] = {
ev_success,
ev_bad_ownership,
ev_bad_directive_signature,
@@ -946,30 +993,69 @@ static enum notification_event event_types[] = {
ARGMATCH_VERIFY (event_args, event_types);
+const char *
+notification_event_str (enum notification_event evt)
+{
+ return event_args[evt];
+}
+
int
string_to_notification_event (gsc_config_file_t *file, char *val,
enum notification_event *pret)
{
- ptrdiff_t x = ARGMATCH (val, event_args, event_types);
-
- if (x == (ptrdiff_t)-1)
- {
- file->error_msg (file->file_name, file->line,
- "unknown notification type: %s", val);
- file->error_count++;
- return 1;
- }
- *pret = event_types[x];
- return 0;
+ int rc, res;
+ rc = string_to ("notification event", val,
+ event_args, event_types,
+ &res,
+ file);
+ *pret = res;
+ return rc;
+}
+
+static const char *target_args[] = {
+ "admin",
+ "user",
+ "owner",
+ NULL
+};
+
+static int target_types[] = {
+ notify_admin, /* System administrator */
+ notify_owner, /* Project admin */
+ notify_user /* User (uploader) */
+};
+
+ARGMATCH_VERIFY (target_args, target_types);
+
+const char *
+notification_target_str (enum notification_target tgt)
+{
+ return target_args[tgt];
+}
+
+int
+string_to_notification_target (gsc_config_file_t *file, char *val,
+ enum notification_target *pret)
+{
+ int rc, res;
+ rc = string_to ("notification target", val,
+ target_args, target_types,
+ &res,
+ file);
+ *pret = res;
+ return rc;
}
static void
-cfg_mail_user (gsc_config_file_t *file, char *kw, char *val, void *unused)
+cfg_notify_event (gsc_config_file_t *file, char *kw, char *val, void *unused)
{
- int i;
int argc;
char **argv;
-
+ enum notification_event evt;
+ enum notification_target tgt;
+ struct message_template *msg;
+ int rc;
+
if (argcv_get (val, NULL, NULL, &argc, &argv))
{
file->error_msg (file->file_name, file->line,
@@ -978,38 +1064,32 @@ cfg_mail_user (gsc_config_file_t *file, char *kw, char *val, void *unused)
return;
}
- for (i = 0; i < argc; i++)
+ if (argc != 3)
{
- enum notification_event evt;
-
- if (string_to_notification_event (file, argv[i], &evt))
- break;
- owner_notification_flags |= STAT_MASK (evt);
+ file->error_msg (file->file_name, file->line,
+ "wrong number of arguments");
+ file->error_count++;
+ argcv_free (argc, argv);
+ return;
}
- argcv_free (argc, argv);
-}
-
-static void
-cfg_user_message (gsc_config_file_t *file, char *kw, char *val, void *unused)
-{
- enum notification_event evt;
- char *word = get_word (&val);
- if (!*word)
+ rc = string_to_notification_event (file, argv[0], &evt)
+ | string_to_notification_target (file, argv[1], &tgt);
+ if ((msg = find_message_template (argv[2])) == NULL)
{
+ rc = 1;
file->error_msg (file->file_name, file->line,
- "not enough arguments");
+ "undefined message: %s", argv[2]);
file->error_count++;
- return;
}
-
- if (string_to_notification_event (file, word, &evt))
- return;
- if (_cfg_raw_read (file, val, &cfg_stk) == 0)
- user_message_template[evt] = obstack_finish (&cfg_stk);
+ if (rc == 0)
+ register_notification (evt, tgt, msg);
+
+ argcv_free (argc, argv);
}
+
static struct gsc_config_keyword kw_handler[] = {
@@ -1032,9 +1112,8 @@ static struct gsc_config_keyword kw_handler[] = {
{ "admin-address", cfg_admin_address },
{ "from-address", cfg_from_address },
{ "mail-admin-stat", cfg_mail_admin_stat },
- { "admin-stat-message", cfg_admin_stat_message },
- { "mail-user", cfg_mail_user },
- { "user-message", cfg_user_message },
+ { "define-message", cfg_define_message },
+ { "notify-event", cfg_notify_event },
{ NULL }
};

Return to:

Send suggestions and report system problems to the System administrator.