diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 13:26:54 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 13:26:54 +0200 |
commit | 293108d7806aa3c0c5e706237b3788b261779e66 (patch) | |
tree | f3ea5c3419c5de0284da68f1d1b6002933e02a73 /modules | |
parent | 02c6a0ad553ad51f91af9d9e6c28f2529e759305 (diff) | |
download | wydawca-293108d7806aa3c0c5e706237b3788b261779e66.tar.gz wydawca-293108d7806aa3c0c5e706237b3788b261779e66.tar.bz2 |
Improve triplet API.
* src/wydawca.h (uploader_info): Rename to wy_user.
(file_triplet) <uploader_count>: Remove.
<admin_list>: New member.
(triplet_get_uploaders,triplet_get_uploader)
(triplet_get_admins): New protos.
* src/triplet.c (wy_user_create)
(wy_userlist_free): New static functions.
(hash_triplet_free): Use wy_userlist_free.
(triplet_get_uploaders,triplet_get_uploader)
(triplet_get_admins): New functions.
* src/verify.c (verify_directive_file): Rewrite using
triplet_get_uploaders.
* src/gpg.c (verify_directive_signature): Call triplet_get_uploaders
to initialize the uploaders list.
* modules/mailutils/mod_mailutils.c (get_recipient): Remove.
(get_owner_address): New function. All callers updated.
Remove useless const qualifiers.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/mailutils/mod_mailutils.c | 95 |
1 files changed, 30 insertions, 65 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c index 1df460a..9a8d061 100644 --- a/modules/mailutils/mod_mailutils.c +++ b/modules/mailutils/mod_mailutils.c @@ -626,9 +626,9 @@ mod_mailutils_LTX_flush() } static mu_address_t -get_uploader_email(struct file_triplet const *trp, const char **errp) +get_uploader_email(struct file_triplet *trp, const char **errp) { - struct uploader_info const *info = trp->uploader; + struct wy_user const *info = triplet_get_uploader(trp); mu_address_t addr; mu_address_t rcpt = NULL; int rc; @@ -652,58 +652,21 @@ get_uploader_email(struct file_triplet const *trp, const char **errp) } static mu_address_t -get_recipient(struct dictionary *dict, struct file_triplet const *trp, - const char **errp) +get_owner_address(struct file_triplet *trp) { - unsigned nrows, ncols, i; + struct wy_user *wp; mu_address_t rcpt = NULL; - char *text; - int rc; - void *md; - - if (dict->type == dictionary_none) { - *errp = N_("dictionary is not configured"); - return NULL; - } - - md = dictionary_open(dict); - if (!md) { - *errp = N_("failed to open dictionary"); - return NULL; - } - - text = triplet_expand_dictionary_query(dict, md, trp); - rc = dictionary_lookup(dict, md, text); - free(text); - if (rc) { - *errp = N_("cannot obtain recipient emails"); - dictionary_close(dict, md); - return NULL; - } - - nrows = dictionary_num_rows(dict); - ncols = dictionary_num_cols(dict); - - if (nrows == 0) { - *errp = N_("cannot obtain recipient emails"); - return NULL; - } - - for (i = 0; i < nrows; i++) { + for (wp = triplet_get_admins(trp); wp; wp = wp->next) { mu_address_t addr; - const char *str = dictionary_result(dict, md, i, 0); - if (mu_address_create(&addr, str)) + if (mu_address_create(&addr, wp->email)) continue; - if (ncols > 0) { - str = dictionary_result(dict, md, i, 1); - if (str) - mu_address_set_personal(addr, 1, str); - } + if (wp->realname) + mu_address_set_personal(addr, 1, wp->realname); + mu_address_union(&rcpt, addr); mu_address_destroy(&addr); } - dictionary_close(dict, md); return rcpt; } @@ -723,13 +686,11 @@ expand_email_owner(struct metadef *def, void *data) { struct file_triplet *trp = data; mu_address_t addr; - const char *errp; - addr = get_recipient(trp->spool->dictionary[project_owner_dict], - trp, &errp); + addr = get_owner_address(trp); if (!addr) { - wy_log(LOG_ERR, _("cannot get email of the %s's owner: %s"), - trp->project, gettext(errp)); + wy_log(LOG_ERR, _("cannot get email of the %s's owner"), + trp->project); def->value = ""; } else { if (mu_address_aget_printable(addr, &def->storage) == 0) @@ -742,7 +703,7 @@ expand_email_owner(struct metadef *def, void *data) } static void -t_notify(struct mailevt *evt, int ev, struct file_triplet const *trp) +t_notify(struct mailevt *evt, int ev, struct file_triplet *trp) { mu_address_t rcpt = NULL; const char *errp; @@ -765,20 +726,25 @@ t_notify(struct mailevt *evt, int ev, struct file_triplet const *trp) case notify_user: rcpt = get_uploader_email(trp, &errp); + if (!rcpt) { + wy_log(LOG_ERR, + _("not notifying %s (project %s) about %s: %s"), + ntfrcpt_str(evt->rcpt), + trp->project, notification_event_str(ev), + gettext(errp)); + return; + } break; case notify_owner: - rcpt = get_recipient(trp->spool->dictionary[project_owner_dict], - trp, &errp); - } - - if (!rcpt && evt->rcpt != notify_read) { - wy_log(LOG_ERR, - _("not notifying %s (project %s) about %s: %s"), - ntfrcpt_str(evt->rcpt), - trp->project, notification_event_str(ev), - gettext(errp)); - return; + rcpt = get_owner_address(trp); + if (!rcpt) { + wy_log(LOG_ERR, + _("not notifying %s (project %s) about %s"), + ntfrcpt_str(evt->rcpt), + trp->project, notification_event_str(ev)); + return; + } } if (wy_debug_level) { @@ -861,7 +827,7 @@ mail_stats(struct mailevt *evt) } void -mod_mailutils_LTX_notify(void *data, int ev, struct file_triplet const *trp) +mod_mailutils_LTX_notify(void *data, int ev, struct file_triplet *trp) { struct mailevt *evt = data; @@ -870,4 +836,3 @@ mod_mailutils_LTX_notify(void *data, int ev, struct file_triplet const *trp) else if (ev == ev_statistics) mail_stats(evt); } - |