summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-11 21:52:43 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-11 21:52:43 (GMT)
commit7c10eca883faa5dd5b01bf1e50b04abb792a6639 (patch) (side-by-side diff)
tree51fc8746681d42bca8034f88510ff7f144215e70
parent10a5f20232d2a57beb0a50b38b1d7196a7f5236e (diff)
downloadwydawca-7c10eca883faa5dd5b01bf1e50b04abb792a6639.tar.gz
wydawca-7c10eca883faa5dd5b01bf1e50b04abb792a6639.tar.bz2
Follow up to 87602f54.
Fix minor bugs. Update the testsuite. All tests pass now. * modules/mailutils/mod_mailutils.c (cb_statistics): Remove. Use wy_cb_statistics. (expand_email_admin, expand_email_owner): Add missing functions. * src/config.c (wy_cb_statistics): New function. (wydawca_kw): Restore "statistics" statement. * src/dictionary.c (dictionary_lookup): Fix debug levels. * src/wydawca.h (wy_cb_statistics): New proto. * tests/atlocal.in (wydawca_expandmeta): Expand @WD_MODDIR@ * tests/check-notify.at: Create notify.rc from notify.rcin * tests/notify-upl.at: Likewise. * tests/mailstats.at: Likewise. * tests/upload-dry.at: Fix the expected output. * tests/etc/mailstats.rc: Rename to tests/etc/mailstats.rcin. * tests/etc/notify.rc: Rename to tests/etc/notify.rcin. * tests/etc/Makefile.am: Update. * tests/etc/wydawca.rcin: Update to the new syntax.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--modules/mailutils/mod_mailutils.c142
-rw-r--r--src/config.c10
-rw-r--r--src/dictionary.c4
-rw-r--r--src/wydawca.h3
-rw-r--r--tests/atlocal.in6
-rw-r--r--tests/check-notify.at3
-rw-r--r--tests/etc/Makefile.am4
-rw-r--r--tests/etc/mailstats.rcin (renamed from tests/etc/mailstats.rc)20
-rw-r--r--tests/etc/notify.rcin (renamed from tests/etc/notify.rc)81
-rw-r--r--tests/etc/wydawca.rcin6
-rw-r--r--tests/mailstats.at3
-rw-r--r--tests/notify-upl.at3
-rw-r--r--tests/upload-dry.at2
13 files changed, 140 insertions, 147 deletions
diff --git a/modules/mailutils/mod_mailutils.c b/modules/mailutils/mod_mailutils.c
index 8698537..2265a76 100644
--- a/modules/mailutils/mod_mailutils.c
+++ b/modules/mailutils/mod_mailutils.c
@@ -455,117 +455,14 @@ cb_email_address(enum grecs_callback_command cmd, grecs_node_t *node,
return rc;
}
-static struct mu_kwd stat_tab[] = {
- { "errors", STAT_ERRORS },
- { "warnings", STAT_WARNINGS },
- { "bad-signatures", STAT_BAD_SIGNATURE },
- { "access-violations", STAT_ACCESS_VIOLATIONS },
- { "complete-triplets", STAT_COMPLETE_TRIPLETS },
- { "incomplete-triplets", STAT_INCOMPLETE_TRIPLETS },
- { "bad-triplets", STAT_BAD_TRIPLETS },
- { "expired-triplets", STAT_EXPIRED_TRIPLETS },
- { "triplet-success", STAT_TRIPLET_SUCCESS },
- { "uploads", STAT_UPLOADS },
- { "archives", STAT_ARCHIVES },
- { "symlinks", STAT_SYMLINKS },
- { "rmsymlinks", STAT_RMSYMLINKS },
- { NULL },
-};
-
-static int
-parse_single_statmask(grecs_locus_t *locus, const grecs_value_t *val,
- unsigned long *pmask, int *invert)
-{
- const char *arg;
- int x;
-
- if (val->type != GRECS_TYPE_STRING) {
- grecs_error(&val->locus, 0,
- _("expected scalar value but found list"));
- return 1;
- }
-
- arg = val->v.string;
-
- if (strcmp(arg, "all") == 0) {
- *pmask = STAT_MASK_ALL;
- *invert = 1;
- return 0;
- } else if (strcmp(arg, "none") == 0) {
- *pmask = STAT_MASK_NONE;
- *invert = 0;
- return 0;
- }
-
- if (mu_kwd_xlat_name(stat_tab, arg, &x)) {
- grecs_error(&val->locus, 0, _("unknown statistics type: %s"),
- arg);
- return 1;
- }
- *pmask = STAT_MASK(x);
- return 0;
-}
-
-static int
-parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask)
-{
- int err = 0;
- int invert = 0;
- unsigned long mask = 0;
- int i;
- struct grecs_list_entry *ep;
-
- switch (val->type) {
- case GRECS_TYPE_STRING:
- err = parse_single_statmask(loc, val, &mask, &invert);
- break;
-
- case GRECS_TYPE_ARRAY:
- for (i = 0; i < val->v.arg.c; i++) {
- unsigned long x;
- if (parse_single_statmask(loc, val->v.arg.v[i],
- &x, &invert))
- err = 1;
- else if (invert)
- mask &= ~x;
- else
- mask |= x;
- }
- break;
-
- case GRECS_TYPE_LIST:
- for (ep = val->v.list->head; ep; ep = ep->next) {
- const grecs_value_t *vp = ep->data;
- unsigned long x;
-
- if (parse_single_statmask(loc, vp, &x, &invert))
- err = 1;
- else if (invert)
- mask &= ~x;
- else
- mask |= x;
- }
- break;
- }
- if (!err)
- *pmask = mask;
- return err;
-}
-
-static int
-cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node,
- void *varptr, void *cb_data)
-{
- return parse_statmask(&node->locus, node->v.value, varptr);
-}
-
static struct grecs_keyword mail_statistics_kw[] = {
{ "message", N_("text"),
N_("Message text"),
grecs_type_string, GRECS_DFLT, &admin_stat_message },
{ "statistics", N_("items"),
N_("Send mail if one or more of these items are set"),
- grecs_type_string, GRECS_DFLT, &mail_admin_mask, 0, cb_statistics },
+ grecs_type_string, GRECS_DFLT, &mail_admin_mask, 0,
+ wy_cb_statistics },
{ "gpg-sign",
N_("key"), N_("Sign message with this key"),
grecs_type_string, GRECS_DFLT, &admin_stat_sign_key },
@@ -812,6 +709,39 @@ get_recipient(struct dictionary *dict, struct file_triplet const *trp,
return rcpt;
}
+const char *
+expand_email_admin(struct metadef *def, void *data)
+{
+ if (mu_address_aget_printable(admin_address, &def->storage) == 0)
+ def->value = def->storage;
+ else
+ def->value = "";
+ return def->value;
+}
+
+const char *
+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);
+ if (!addr) {
+ wy_log(LOG_ERR, _("cannot get email of the %s's owner: %s"),
+ trp->project, gettext(errp));
+ def->value = "";
+ } else {
+ if (mu_address_aget_printable(addr, &def->storage) == 0)
+ def->value = def->storage;
+ else
+ def->value = "";
+ mu_address_destroy(&addr);
+ }
+ return def->value;
+}
+
static void
t_notify(struct mailevt *evt, int ev, struct file_triplet const *trp)
{
@@ -935,8 +865,10 @@ void
mod_mailutils_LTX_notify(void *data, int ev, struct file_triplet const *trp)
{
struct mailevt *evt = data;
+
if (trp)
t_notify(evt, ev, trp);
else if (ev == ev_statistics)
mail_stats(evt);
}
+
diff --git a/src/config.c b/src/config.c
index 8dbc788..b89beff 100644
--- a/src/config.c
+++ b/src/config.c
@@ -440,6 +440,13 @@ parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask)
return err;
}
+int
+wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node,
+ void *varptr, void *cb_data)
+{
+ return parse_statmask(&node->locus, node->v.value, varptr);
+}
+
static int
cb_sql_host(enum grecs_callback_command cmd, grecs_node_t *node,
@@ -1294,6 +1301,9 @@ static struct grecs_keyword wydawca_kw[] = {
N_("Control implicit signature archivation"),
grecs_type_bool, GRECS_DFLT, &archive_signatures },
+ { "statistics", N_("items"), N_("Print these stats at the end of run"),
+ grecs_type_string, GRECS_DFLT, &print_stats, 0, wy_cb_statistics },
+
{ "sql", N_("id: string"), N_("Define SQL database"),
grecs_type_section, GRECS_DFLT, NULL, 0, cb_sql, NULL, sql_kw },
diff --git a/src/dictionary.c b/src/dictionary.c
index 4f18267..0b96543 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -129,10 +129,10 @@ dictionary_lookup(struct dictionary *dict, void *handle, const char *cmd)
struct dictionary_descr *mp = dictionary_tab + dict->type;
if (cmd)
- wy_debug(1, (_("dictionary lookup: %s \"%s\""),
+ wy_debug(2, (_("dictionary lookup: %s \"%s\""),
mp->name, cmd));
else
- wy_debug(1, (_("dictionary lookup: %s"),
+ wy_debug(2, (_("dictionary lookup: %s"),
mp->name));
if (!dict->init_passed) {
diff --git a/src/wydawca.h b/src/wydawca.h
index 89d0458..08126ac 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -275,6 +275,9 @@ enum wydawca_stat {
#define STAT_MASK(c) (1<<(c))
#define STAT_MASK_NONE 0
#define STAT_MASK_ALL (STAT_MASK(MAX_STAT) - 1)
+
+int wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node,
+ void *varptr, void *cb_data);
enum notification_event {
ev_success,
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 50c5a60..89cfd3f 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -30,7 +30,11 @@ wydawca_clean_testdirs() {
}
wydawca_expandmeta() {
- sed "s/@USER@/$USER/g;s,@WD_SRC@,$WD_SRC,g;s,@WD_DST@,$WD_DST,g;s,@WD_CONFSRC@,$WD_CONFSRC,g" $1 > $2
+ sed "s/@USER@/$USER/g;
+ s,@WD_SRC@,$WD_SRC,g;
+ s,@WD_DST@,$WD_DST,g;
+ s,@WD_CONFSRC@,$WD_CONFSRC,g;
+ s,@WD_MODDIR@,@abs_top_builddir@/modules/mailutils,g" $1 > $2
}
wydawca_config() {
diff --git a/tests/check-notify.at b/tests/check-notify.at
index 7be4741..bebfa4b 100644
--- a/tests/check-notify.at
+++ b/tests/check-notify.at
@@ -71,7 +71,8 @@ AT_CHECK([
wydawca_init_testdirs
wydawca_config wydawca.rc
mv wydawca.rc simple.rc
-cat $WD_CONFSRC/notify.rc simple.rc > wydawca.rc
+wydawca_config notify.rc
+cat notify.rc simple.rc >> wydawca.rc
wydawca_upload fail file
diff --git a/tests/etc/Makefile.am b/tests/etc/Makefile.am
index 4d1322b..086b659 100644
--- a/tests/etc/Makefile.am
+++ b/tests/etc/Makefile.am
@@ -21,9 +21,9 @@ EXTRA_DIST = \
pubring.asc\
secring.asc\
wydawca.rcin\
- notify.rc\
+ notify.rcin\
nullmail\
- mailstats.rc
+ mailstats.rcin
GPG_FLAGS = --quiet --no-permission-warning --homedir .
pubring.gpg secring.gpg: $(srcdir)/pubring.asc $(srcdir)/secring.asc
diff --git a/tests/etc/mailstats.rc b/tests/etc/mailstats.rcin
index c85345e..b3aeab7 100644
--- a/tests/etc/mailstats.rc
+++ b/tests/etc/mailstats.rcin
@@ -14,9 +14,17 @@
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
-mail-statistics {
- statistics all;
- message <<EOT
+module-prepend-load-path "@WD_MODDIR@";
+module mailutils mod_mailutils.la;
+module-init mailutils {
+ admin-address "root@localhost";
+ from-address "wydawca-noreply@localhost";
+
+ mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}";
+
+ mail-statistics {
+ statistics all;
+ message <<EOT
Subject: Wydawca stats
This is to notify you that the recent run of wydawca
@@ -39,4 +47,10 @@ symlinks removed ................... ${stat:rmsymlinks}
Regards,
Wydawca
EOT;
+ }
+}
+
+notify-event {
+ event statistics;
+ module mailutils;
}
diff --git a/tests/etc/notify.rc b/tests/etc/notify.rcin
index 635e275..55f9c72 100644
--- a/tests/etc/notify.rc
+++ b/tests/etc/notify.rcin
@@ -14,11 +14,22 @@
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
+module-prepend-load-path "@WD_MODDIR@";
+module mailutils mod_mailutils.la;
+module-init mailutils {
+ admin-address "root@localhost";
+ from-address "wydawca-noreply@localhost";
+
+ mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}";
+}
+
# Notify the user about successful uploads
notify-event {
- event success;
- recipient user;
- message <<EOT
+ event success;
+ module mailutils;
+ module-config {
+ recipient user;
+ message <<EOT
Subject: Upload of ${project} successful
Upload of ${project} to ${url}/${dir} finished successfully.
@@ -30,13 +41,16 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify project admin about a successful upload.
notify-event {
- event success;
- recipient owner;
- message <<EOT
+ event success;
+ module mailutils;
+ module-config {
+ recipient owner;
+ message <<EOT
Subject: Upload of ${project} successful
${user:real-name} (${user:email}) successfully uploaded files
@@ -48,14 +62,17 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify project admin, if someone non authorized attempted to upload some
# files for the project they run.
notify-event {
- event bad-ownership;
- recipient owner;
- message <<EOT
+ event bad-ownership;
+ module mailutils;
+ module-config {
+ recipient owner;
+ message <<EOT
Subject: Suspicious upload of ${project}
Someone not authorized to make releases for ${project}
@@ -73,6 +90,7 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify the user (submitter), if the directive signature does not match
@@ -81,9 +99,11 @@ EOT;
# stay on a safe side. Notifying project admins (see below) should be quite
# enough.
notify-event {
- event bad-directive-signature;
- recipient user;
- message <<EOT
+ event bad-directive-signature;
+ module mailutils;
+ module-config {
+ recipient user;
+ message <<EOT
Subject: Suspicious upload of ${project}
Someone (apparently you), has tried to make a release for ${project}.
@@ -101,14 +121,17 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify the project admin, if submitted directive signature did not match
# submitter record.
notify-event {
- event bad-directive-signature;
- recipient owner;
- message <<EOT
+ event bad-directive-signature;
+ module mailutils;
+ module-config {
+ recipient owner;
+ message <<EOT
Subject: Suspicious upload of ${project}
${user:real-name} (${user:email}) has tried to make a release
@@ -123,6 +146,7 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify the user (submitter), if the detached signature does not match
@@ -131,9 +155,11 @@ EOT;
# stay on a safe side. Notifying project admins (see below) should be quite
# enough.
notify-event {
- event bad-detached-signature;
- recipient user;
- message <<EOT
+ event bad-detached-signature;
+ module mailutils;
+ module-config {
+ recipient user;
+ message <<EOT
Subject: Suspicious upload of ${project}
Someone (apparently you), has tried to make a release for ${project}.
@@ -151,14 +177,17 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
# Notify the project admin, if submitted detached signature did not match
# submitter record.
notify-event {
- event bad-detached-signature;
- recipient owner;
- message <<EOT
+ event bad-detached-signature;
+ module mailutils;
+ module-config {
+ recipient owner;
+ message <<EOT
Subject: Suspicious upload of ${project}
${user:real-name} (${user:email}) has tried to make a release
@@ -173,12 +202,15 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
notify-event {
- event check-failure;
- recipient user;
- message <<EOT
+ event check-failure;
+ module mailutils;
+ module-config {
+ recipient user;
+ message <<EOT
Subject: ${triplet:dist} rejected
Your upload of ${triplet:dist} has been rejected by the distribution
@@ -192,6 +224,7 @@ Regards,
Wydawca
The Project Submission Robot
EOT;
+ }
}
diff --git a/tests/etc/wydawca.rcin b/tests/etc/wydawca.rcin
index ec87a7b..d020eff 100644
--- a/tests/etc/wydawca.rcin
+++ b/tests/etc/wydawca.rcin
@@ -95,9 +95,3 @@ spool ckok {
archive none;
check-script "exit 0";
}
-
-admin-address "root@localhost";
-from-address "wydawca-noreply@localhost";
-
-mailer "| @WD_CONFSRC@/nullmail @WD_DST@/mail.out -F ${sender} ${rcpt}";
-
diff --git a/tests/mailstats.at b/tests/mailstats.at
index 59f8e0c..e5c769d 100644
--- a/tests/mailstats.at
+++ b/tests/mailstats.at
@@ -69,7 +69,8 @@ Wydawca
AT_CHECK([
wydawca_init_testdirs
wydawca_config wydawca.rc
-cat $WD_CONFSRC/mailstats.rc >> wydawca.rc
+wydawca_config mailstats.rc
+cat mailstats.rc >> wydawca.rc
wydawca_upload test file
wydawca_expandmeta errtmpl experr
diff --git a/tests/notify-upl.at b/tests/notify-upl.at
index ee35056..b6425ba 100644
--- a/tests/notify-upl.at
+++ b/tests/notify-upl.at
@@ -82,7 +82,8 @@ AT_CHECK([
wydawca_init_testdirs
wydawca_config wydawca.rc
mv wydawca.rc simple.rc
-cat $WD_CONFSRC/notify.rc simple.rc > wydawca.rc
+wydawca_config notify.rc
+cat notify.rc simple.rc >> wydawca.rc
wydawca_upload test file
wydawca_expandmeta errtmpl experr
diff --git a/tests/upload-dry.at b/tests/upload-dry.at
index e2e4063..56ccc67 100644
--- a/tests/upload-dry.at
+++ b/tests/upload-dry.at
@@ -23,7 +23,7 @@ wydawca: [[DEBUG]] @WD_SRC@/fail -> @WD_DST@
wydawca: [[DEBUG]] @WD_SRC@/test -> @WD_DST@
wydawca: [[DEBUG]] processing spool test (@WD_DST@)
wydawca: [[DEBUG]] FILE file, DIST=file, SIG=file.sig, DIRECTIVE=file.directive.asc
-wydawca: [[NOTICE]] Good signature from Wydawca (Testsuite) <bug-wydawca@gnu.org.ua>
+wydawca: [[DEBUG]] Good signature from Wydawca (Testsuite) <bug-wydawca@gnu.org.ua>
wydawca: [[DEBUG]] file: directive file signature OK
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[DEBUG]] processing triplet `file'

Return to:

Send suggestions and report system problems to the System administrator.