diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-26 13:03:32 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2007-08-26 13:03:32 +0000 |
commit | b89ece30bebb5b9dd06e4e061537b6bf068566f2 (patch) | |
tree | c7f65b64fccfac2f0e7e134e5f7666a4fb1907d1 /src/mail.c | |
parent | 338c0d9c35c56f35c636df1c1da0852a466e731f (diff) | |
download | wydawca-b89ece30bebb5b9dd06e4e061537b6bf068566f2.tar.gz wydawca-b89ece30bebb5b9dd06e4e061537b6bf068566f2.tar.bz2 |
Implement project owner notifications.
* wydawca/wydawca.c (syslog_printer): Reduce the number of memory
reallocations
(make_stat_expansion): Update
* wydawca/method.c: Implement a new framework: methods may return
2-dimensional arrays of strings.
* wydawca/sql.c, wydawca/sql.h: Implement the new method framework.
* wydawca/verify.c (expand_param): kw_expansion may provide
expansion functions. An additional argument supplies user-defined
data for expansions.
(escape_kwexp): Extern
(free_kwexp): Improve
(get_project_name): New function
(make_default_kwexp): New function
(check_access_rights): Call get_project_name. Use
make_default_kwexp to initialize expansions
(verify_directive_file): Use make_default_kwexp to initialize
expansions
* wydawca/wydawca.h (NITEMS): New macro
(enum access_method_type): New members: ncol, nrow
(struct directory_pair): New members url,project_owner_method,
user_data_method
(struct file_info): Replace mtime, uid with struct stat sb
(struct file_triplet): New members project, dpair, user_data
(TRIPLET_UID): Take into account the changes to struct file_info
(enum notification_event): New data type
(notify_project_owner, notify_admin, notify): New functions
(struct kw_expansion): New members static_p, expand and data.
(escape_kwexp,make_default_kwexp): New proto
(expand_param): Change signature
(triplet_expand_param): New function
(method_result): Change prototype
(method_num_rows,method_num_cols): New functions
* wydawca/config.c: New statements project-owner, user-data,
admin-address, mail-user, user-message
directory can take an optional argument specifying base URL for
notification messages
* wydawca/gpg.c (verify_directive_signature): Expand directives
even if the signature does not match. Useful for notifications.
Add notifications.
* wydawca/process.c: Add notifications.
* wydawca/directive.c: Add notifications
* wydawca/wydawca.rc: Update
* wydawca/mail.c, wydawca/mail.h: Implement project owner
notifications
* wydawca/triplet.c (triplet_expand_param): New function
* lib/cfg.c (read_cont_line): Fix counting of input lines.
git-svn-id: file:///svnroot/wydawca/trunk@297 6bb4bd81-ecc2-4fd4-a2d4-9571d19c0d33
Diffstat (limited to 'src/mail.c')
-rw-r--r-- | src/mail.c | 103 |
1 files changed, 102 insertions, 1 deletions
@@ -23,6 +23,8 @@ mu_address_t admin_address; mu_address_t from_address; unsigned long mail_admin_mask; char *admin_stat_message_template; +unsigned long owner_notification_flags; +char *user_message_template[MAX_EVENT]; void mail_init () @@ -49,6 +51,8 @@ mail_send_message (mu_address_t rcpt, const char *text) mu_header_t hdr; int mailer_flags = 0; static char *x_mailer = "wydawca (" PACKAGE_STRING ")"; + size_t size; + char *buf; mu_message_create (&msg, NULL); @@ -57,6 +61,13 @@ mail_send_message (mu_address_t rcpt, const char *text) mu_message_get_header (msg, &hdr); mu_header_append (hdr, "X-Mailer", x_mailer); + mu_address_to_string (rcpt, NULL, 0, &size); + buf = xmalloc (size + 1); + mu_address_to_string (rcpt, buf, size + 1, NULL); + + mu_header_set_value (hdr, "To", buf, 1); + free (buf); + if (debug_level > 1) { mu_debug_t debug; @@ -114,10 +125,12 @@ mail_stats () exp[0].kw = "date"; exp[0].value = xstrdup (ctime (&t)); exp[0].value [strlen (exp[0].value) - 1] = 0; + exp[0].expand = NULL; + make_stat_expansion (exp + 1); text = expand_param (admin_stat_message_template, - exp, sizeof (exp) / sizeof (exp[0])); + exp, sizeof (exp) / sizeof (exp[0]), NULL); mail_send_message (admin_address, text); @@ -131,3 +144,91 @@ mail_finish () if (mailer_opened) mu_mailer_close (mailer); } + +void +notify_owner (struct file_triplet *trp, enum notification_event ev) +{ + int rc; + struct access_method *method = trp->dpair->project_owner_method; + char *text; + mu_address_t rcpt = NULL; + unsigned nrows, ncols, i; + struct kw_expansion kwexp[4]; + + if (method->type == method_none) + { + logmsg (LOG_NOTICE, + "NOT notifying project admins: project-owner not configured in " + "[%s, %s]", trp->dpair->source_dir, trp->dpair->dest_dir); + return; + } + + if (method_init (method)) + { + logmsg (LOG_ERR, + "failed to initialize project-owner method: " + "NOT notifying project admins"); + return; + } + + make_default_kwexp (kwexp, NULL, trp->project); + escape_kwexp (method, kwexp, NITEMS (kwexp)); + text = expand_param (method->param[1], kwexp, NITEMS (kwexp), NULL); + + rc = method_run (method, text); + free (text); + if (rc) + { + logmsg (LOG_ERR, "cannot obtain owner emails for %s", + trp->project); + return; + } + + nrows = method_num_rows (method); + ncols = method_num_cols (method); + + for (i = 0; i < nrows; i++) + { + mu_address_t addr; + const char *str = method_result (method, i, 0); + if (mu_address_create (&addr, str)) + continue; + if (ncols > 0) + { + str = method_result (method, i, 1); + if (str) + mu_address_set_personal (addr, 1, str); + } + mu_address_union (&rcpt, addr); + mu_address_destroy (&addr); + } + + if (debug_level) + { + size_t size; + char *buf; + mu_address_to_string (rcpt, NULL, 0, &size); + buf = xmalloc (size + 1); + mu_address_to_string (rcpt, buf, size + 1, NULL); + logmsg (LOG_DEBUG, "Notifying admins of %s: %s", trp->project, + buf); + free (buf); + } + + if (!dry_run_mode) + { + text = triplet_expand_param (user_message_template[ev], trp); + mail_send_message (rcpt, text); + free (text); + } + + mu_address_destroy (&rcpt); +} + +void +notify (struct file_triplet *trp, enum notification_event ev) +{ + if (owner_notification_flags & STAT_MASK (ev)) + notify_owner (trp, ev); + /* FIXME */ +} |