diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 15:03:59 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-12 15:22:13 +0200 |
commit | 1ba8cf95a5f536d4aa6293f9848271a7285bc092 (patch) | |
tree | dede8a4bccb1daad8b67530d87845e7fe05749e6 /src | |
parent | 293108d7806aa3c0c5e706237b3788b261779e66 (diff) | |
download | wydawca-1ba8cf95a5f536d4aa6293f9848271a7285bc092.tar.gz wydawca-1ba8cf95a5f536d4aa6293f9848271a7285bc092.tar.bz2 |
Namespace normalization (2). Provide installable headers.
* Makefile.am (SUBDIRS): Add include.
* configure.ac: Build include/*/Makefile
Set-up grecs as a shared convenience library. Install
its headers.
* include/Makefile.am: New file.
* include/wydawca/Makefile.am: New file.
* include/wydawca/cfg.h: New file.
* include/wydawca/wydawca.h: New file.
* modules/mailutils/Makefile.am (AM_CPPFLAGS): Add include/
* src/Makefile.am (LDADD): Use @GRECS_LDADD@
(AM_CPPFLAGS): Add include/.
* tests/Makefile.am: Likewise.
* src/wydawca.h: Include wydawca/wydawca.h.
(__cat2__, __cat3__): Move to installable header and rename.
(struct wy_user): Move to installable header.
(struct file_triplet): Rename to wy_triplet. All uses changed.
(enum notification_event): Rename to wy_event and move to
installable header.
(struct metadef): Rename to wy_metadef and move to
installable header.
(dry_run_mode): Rename to wy_dry_run and move to
installable header.
(wydawca_gpg_homedir): Rename to wy_gpg_homedir and move to
installable header.
(wy_version, wy_debug_level, wy_log_to_stderr)
(wy_log_facility, wy_syslog_tag)
(wy_log,wy_dbg): Move to installable header.
* modules/mailutils/mod_mailutils.c: Update.
* src/cmdline.opt
* src/config.c
* src/directive.c
* src/diskio.c
* src/event.c
* src/gpg.c
* src/job.c
* src/meta.c
* src/module.c
* src/null.c
* src/timer.c
* src/triplet.c
* src/verify.c
* src/vtab.c
* src/watcher.c
* src/wydawca.c
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/cmdline.opt | 2 | ||||
-rw-r--r-- | src/config.c | 26 | ||||
-rw-r--r-- | src/directive.c | 28 | ||||
-rw-r--r-- | src/diskio.c | 46 | ||||
-rw-r--r-- | src/event.c | 6 | ||||
-rw-r--r-- | src/gpg.c | 14 | ||||
-rw-r--r-- | src/job.c | 12 | ||||
-rw-r--r-- | src/meta.c | 39 | ||||
-rw-r--r-- | src/module.c | 4 | ||||
-rw-r--r-- | src/null.c | 10 | ||||
-rw-r--r-- | src/timer.c | 8 | ||||
-rw-r--r-- | src/triplet.c | 176 | ||||
-rw-r--r-- | src/verify.c | 6 | ||||
-rw-r--r-- | src/vtab.c | 8 | ||||
-rw-r--r-- | src/watcher.c | 2 | ||||
-rw-r--r-- | src/wydawca.c | 16 | ||||
-rw-r--r-- | src/wydawca.h | 150 |
18 files changed, 268 insertions, 288 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7b350e5..c4be551 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,8 +67,9 @@ SUFFIXES=.opt .c .h incdir=$(pkgdatadir)/$(VERSION)/include inc_DATA = $(PP_SETUP_FILE) -LDADD=../grecs/src/libgrecs.a @SQLLIB@ @GPGMELIB@ @LIBLTDL@ +LDADD=@GRECS_LDADD@ @SQLLIB@ @GPGMELIB@ @LIBLTDL@ AM_CPPFLAGS= \ + -I$(top_srcdir)/include\ -I$(top_srcdir)/grecs/src/ @MAILUTILS_INCLUDES@\ -DSYSCONFDIR=\"$(sysconfdir)\"\ -DLOCALSTATEDIR=\"$(localstatedir)\"\ diff --git a/src/cmdline.opt b/src/cmdline.opt index ef89222..039dc6b 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -69,7 +69,7 @@ OPTION(dry-run,n,, BEGIN wy_log_to_stderr = 1; wy_debug_level++; - dry_run_mode = 1; + wy_dry_run = 1; END OPTION(cron,,, diff --git a/src/config.c b/src/config.c index b89beff..eef4ee1 100644 --- a/src/config.c +++ b/src/config.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2007-2012 Sergey Poznyakoff + Copyright (C) 2007-2013 Sergey Poznyakoff Wydawca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -205,17 +205,17 @@ safe_file_name_alloc(const char *file_name) } static struct keyword event_tab[] = { - { "success", ev_success }, - { "bad-ownership", ev_bad_ownership }, - { "bad-directive-signature", ev_bad_directive_signature }, - { "bad-detached-signature", ev_bad_detached_signature }, - { "check-failure", ev_check_fail }, - { "statistics", ev_statistics }, + { "success", wy_ev_success }, + { "bad-ownership", wy_ev_bad_ownership }, + { "bad-directive-signature", wy_ev_bad_directive_signature }, + { "bad-detached-signature", wy_ev_bad_detached_signature }, + { "check-failure", wy_ev_check_fail }, + { "statistics", wy_ev_statistics }, {NULL} }; const char * -notification_event_str(enum notification_event evt) +wy_event_str(enum wy_event evt) { const char *ret; if (tok_to_keyword(evt, event_tab, &ret)) { @@ -229,8 +229,8 @@ notification_event_str(enum notification_event evt) } int -string_to_notification_event(grecs_locus_t *locus, const char *val, - enum notification_event *pret) +string_to_wy_event(grecs_locus_t *locus, const char *val, + enum wy_event *pret) { int res; if (keyword_to_tok(val, event_tab, &res)) { @@ -717,13 +717,13 @@ static int cb_event(enum grecs_callback_command cmd, grecs_node_t *node, void *varptr, void *cb_data) { - enum notification_event *pev = varptr; + enum wy_event *pev = varptr; grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; if (wy_assert_string_arg(locus, cmd, value)) return 1; - string_to_notification_event(&value->locus, value->v.string, pev); + string_to_wy_event(&value->locus, value->v.string, pev); return 0; } @@ -1334,7 +1334,7 @@ static struct grecs_keyword wydawca_kw[] = { grecs_type_string, GRECS_LIST, &all_spool_aliases }, { "gpg-homedir", NULL, N_("GPG home directory"), - grecs_type_string, GRECS_DFLT, &wydawca_gpg_homedir }, + grecs_type_string, GRECS_DFLT, &wy_gpg_homedir }, {NULL} }; diff --git a/src/directive.c b/src/directive.c index 481e267..c7e1817 100644 --- a/src/directive.c +++ b/src/directive.c @@ -20,7 +20,7 @@ /* Parse directives from TRP->blurb. Fill TRP->directive */ int -directive_parse(struct file_triplet *trp) +directive_parse(struct wy_triplet *trp) { size_t dcount, i, j; char *p; @@ -61,7 +61,7 @@ directive_parse(struct file_triplet *trp) /* If a directive KEY exists in the triplet TRP, return 0 and point PVAL (unless it is NULL) to its value. Othervise, return 1. */ int -directive_get_value(struct file_triplet *trp, const char *key, +directive_get_value(struct wy_triplet *trp, const char *key, const char **pval) { int keylen = strlen(key); @@ -94,7 +94,7 @@ directive_get_value(struct file_triplet *trp, const char *key, If N points past all the directive, the function returns 0. */ static int -_directive_seq_get(int n, struct file_triplet *trp, +_directive_seq_get(int n, struct wy_triplet *trp, const char **pkey, const char **pval) { char *p; @@ -121,7 +121,7 @@ _directive_seq_get(int n, struct file_triplet *trp, /* Get the first directive from TRP. Point *PKEY to its keyword and *PVAL to its value. Return 1 on success, 0 on failure. */ int -directive_first(struct file_triplet *trp, const char **pkey, const char **pval) +directive_first(struct wy_triplet *trp, const char **pkey, const char **pval) { int n = 0; return _directive_seq_get(n, trp, pkey, pval); @@ -131,7 +131,7 @@ directive_first(struct file_triplet *trp, const char **pkey, const char **pval) *PVAL to its value. Return 1 on success, 0 on failure. Return non-0 on success, 0 on failure */ int -directive_next(struct file_triplet *trp, int n, +directive_next(struct wy_triplet *trp, int n, const char **pkey, const char **pval) { return _directive_seq_get(n, trp, pkey, pval); @@ -166,7 +166,7 @@ directive_unpack_version(unsigned version, char **pbuf, size_t * psize) /* Return true if the directory file version of the triplet TRP is within the inclusive range FROM and TO (packed) */ int -directive_version_in_range_p(struct file_triplet *trp, +directive_version_in_range_p(struct wy_triplet *trp, unsigned from, unsigned to) { const char *val; @@ -238,7 +238,7 @@ find_directive(const char *key) /* Return 0 if the directory file format of the triplet TRP is OK. */ int -verify_directive_format(struct file_triplet *trp) +verify_directive_format(struct wy_triplet *trp) { int n, dnum; const char *key; @@ -387,7 +387,7 @@ stderr_redirector(const char *tag) } static int -run_check_script(const char *script, struct file_triplet *trp, +run_check_script(const char *script, struct wy_triplet *trp, const char *descr) { static char *script_file; @@ -527,7 +527,7 @@ run_check_script(const char *script, struct file_triplet *trp, } static int -external_check(struct file_triplet *trp) +external_check(struct wy_triplet *trp) { int rc; const struct spool *spool = trp->spool; @@ -557,14 +557,14 @@ external_check(struct file_triplet *trp) if (rc) { UPDATE_STATS(STAT_CHECK_FAIL); - notify(spool->notification, trp, ev_check_fail); + notify(spool->notification, trp, wy_ev_check_fail); } return rc; } static int -symlink_filelist(struct file_triplet *trp, const char *key, const char *val) +symlink_filelist(struct wy_triplet *trp, const char *key, const char *val) { int rc = 0; struct wordsplit ws; @@ -589,7 +589,7 @@ symlink_filelist(struct file_triplet *trp, const char *key, const char *val) /* Process the directives from TRP */ int -process_directives(struct file_triplet *trp) +process_directives(struct wy_triplet *trp) { int rc, n; const char *key, *val; @@ -663,7 +663,7 @@ process_directives(struct file_triplet *trp) } } - if (!dry_run_mode && unlink(trp->file[file_directive].name)) { + if (!wy_dry_run && unlink(trp->file[file_directive].name)) { wy_log(LOG_CRIT, _("%s: cannot unlink directive file: %s"), trp->file[file_directive].name, strerror(errno)); } @@ -671,6 +671,6 @@ process_directives(struct file_triplet *trp) UPDATE_STATS(STAT_TRIPLET_SUCCESS); report_finish(); timer_stop("triplet"); - notify(spool->notification, trp, ev_success); + notify(spool->notification, trp, wy_ev_success); return 0; } diff --git a/src/diskio.c b/src/diskio.c index 99d3b54..d083d2a 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -102,14 +102,14 @@ create_hierarchy(char *dir, size_t baselen) /* Create a directory BASE/NAME (with eventual intermediate directories in NAME). - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ char * create_directory(const char *base, const char *name) { size_t baselen; char *dir = concat_dir(base, name, &baselen); - if (!dry_run_mode) { + if (!wy_dry_run) { if (create_hierarchy(dir, baselen)) { free(dir); dir = NULL; @@ -225,14 +225,14 @@ do_move_file(const char *file, const char *dst_file) } /* Append the FILE to the tar ARCHIVE. - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ int tar_append_file(const char *archive, const char *file) { const char *argv[6]; wy_debug(1, (_("tarring %s to %s"), file, archive)); - if (dry_run_mode) { + if (wy_dry_run) { UPDATE_STATS(STAT_ARCHIVES); return 0; } @@ -266,7 +266,7 @@ tar_append_file(const char *archive, const char *file) ARCHIVE - Archive descriptor. RELDIR - Directory part of FILE - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ int backup_file(const char *dst_file, const char *dst_dir, const char *file, const struct archive_descr *archive, const char *reldir) @@ -288,7 +288,7 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file, wy_debug(1, (_("removing previous archive " "file `%s'"), file_name)); - if (!dry_run_mode && unlink(file_name)) { + if (!wy_dry_run && unlink(file_name)) { wy_log(LOG_ERR, _("cannot unlink previous archive " "file `%s': %s"), @@ -304,7 +304,7 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file, wy_debug(1, (_("backing up previous archive " "file `%s' to `%s'"), file_name, archive_file_name)); - if (!dry_run_mode) { + if (!wy_dry_run) { rc = do_move_file(file_name, archive_file_name); if (rc) { @@ -323,7 +323,7 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file, } wy_debug(1, (_("archiving `%s' to `%s'"), dst_file, file_name)); - if (!dry_run_mode) { + if (!wy_dry_run) { rc = do_move_file(dst_file, file_name); if (rc) wy_log(LOG_ERR, _("archiving `%s' as `%s' failed: %s"), @@ -357,7 +357,7 @@ do_archive_file(const char *dst_file, const char *dst_dir, const char *file, break; } - if (!dry_run_mode && unlink(dst_file) && errno != ENOENT) { + if (!wy_dry_run && unlink(dst_file) && errno != ENOENT) { wy_log(LOG_ERR, _("canot unlink file `%s': %s"), dst_file, strerror(errno)); return 1; @@ -366,7 +366,7 @@ do_archive_file(const char *dst_file, const char *dst_dir, const char *file, } static int -replace_allowed_p(struct file_triplet *trp) +replace_allowed_p(struct wy_triplet *trp) { const char *val; @@ -388,9 +388,9 @@ dir_get_path(struct spool *sp) TRP->SPOOL. TRP->RELATIVE_DIR gives relative directory (i.e. the directory part of the file name) for backup purposes. - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ int -dir_move_file(struct file_triplet *trp, enum file_type file_id) +dir_move_file(struct wy_triplet *trp, enum file_type file_id) { char *dst_file; int rc = 0; @@ -421,7 +421,7 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id) } } - if (!dry_run_mode && rc == 0) + if (!wy_dry_run && rc == 0) rc = do_move_file(trp->file[file_id].name, dst_file); free(dst_file); @@ -433,10 +433,10 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id) /* Archive the file FILE_NAME, located in DPAIR->dest_dir, and remove the file. Get user IDs from the triplet TRP. - Do nothing if dry_run_mode is set. + Do nothing if wy_dry_run is set. */ int -archive_single_file(struct file_triplet *trp, const char *file_name, +archive_single_file(struct wy_triplet *trp, const char *file_name, int noentok) { char *dst_file; @@ -495,10 +495,10 @@ make_signame(const char *file_name) /* Archive the file FILE_NAME, located in DPAIR->dest_dir, and remove the file. Get user IDs from the triplet TRP. Unless FILE_NAME ends in ".sig", do the same with FILE_NAME.sig, if such a file exists. - Do nothing if dry_run_mode is set. + Do nothing if wy_dry_run is set. */ int -dir_archive_file(struct file_triplet *trp, const char *file_name) +dir_archive_file(struct wy_triplet *trp, const char *file_name) { int rc; char *signame; @@ -515,9 +515,9 @@ dir_archive_file(struct file_triplet *trp, const char *file_name) /* Create a symbolic link from WANTED_SRC to WANTED_DST in the subdirectory TRP->relative_dir of SPOOL->dest_dir. - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ int -dir_symlink_file(struct file_triplet *trp, +dir_symlink_file(struct wy_triplet *trp, const char *wanted_src, const char *wanted_dst) { int rc = 0; @@ -550,7 +550,7 @@ dir_symlink_file(struct file_triplet *trp, wy_debug(1, (_("symlinking %s to %s in directory %s"), src, dst, dst_dir)); - if (!dry_run_mode) { + if (!wy_dry_run) { char *p = strrchr(dst, '/'); if (p > dst) { char *dir; @@ -639,7 +639,7 @@ do_rmsymlink_file(const char *dst_file, int noentok) return 1; } } - if (!dry_run_mode && unlink(dst_file)) { + if (!wy_dry_run && unlink(dst_file)) { wy_log(LOG_ERR, _("cannot unlink %s: %s"), dst_file, strerror(errno)); return 1; @@ -650,9 +650,9 @@ do_rmsymlink_file(const char *dst_file, int noentok) /* Remove the symbolic link TRP->spool->dest_dir/TRP->relative_dir/FILE_NAME - Do nothing if dry_run_mode is set. */ + Do nothing if wy_dry_run is set. */ int -dir_rmsymlink_file(struct file_triplet *trp, const char *file_name) +dir_rmsymlink_file(struct wy_triplet *trp, const char *file_name) { char *dst_file; int rc = 0; diff --git a/src/event.c b/src/event.c index 548a316..0e19d7b 100644 --- a/src/event.c +++ b/src/event.c @@ -1,8 +1,8 @@ #include "wydawca.h" void -notify(struct notification *n, struct file_triplet *t, - enum notification_event e) +notify(struct notification *n, struct wy_triplet *t, + enum wy_event e) { for (; n; n = n->next) if (n->ev == e) { @@ -14,7 +14,7 @@ notify(struct notification *n, struct file_triplet *t, void notify_stats() { - notify(default_notification, NULL, ev_statistics); + notify(default_notification, NULL, wy_ev_statistics); } void @@ -134,7 +134,7 @@ create_gpg_homedir() } static int -checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp) +checksig(gpgme_signature_t sig, const char *uid, struct wy_triplet *trp) { switch (gpg_err_code(sig->status)) { case GPG_ERR_NO_ERROR: @@ -184,7 +184,7 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp) static int gpg_verify_signature(gpgme_ctx_t ctx, gpgme_signature_t sig, - struct file_triplet *trp) + struct wy_triplet *trp) { if (!sig) return 0; @@ -208,7 +208,7 @@ gpg_verify_signature(gpgme_ctx_t ctx, gpgme_signature_t sig, /* Verify the directive file from TRP using public key PUBKEY */ int -verify_directive_signature(struct file_triplet *trp) +verify_directive_signature(struct wy_triplet *trp) { gpgme_ctx_t ctx; gpgme_data_t key_data, directive_data, plain = NULL; @@ -219,7 +219,7 @@ verify_directive_signature(struct file_triplet *trp) create_gpg_homedir(); fail_if_err(gpgme_new(&ctx)); - for (uptr = triplet_get_uploaders(trp); uptr; uptr = uptr->next) { + for (uptr = wy_triplet_get_uploaders(trp); uptr; uptr = uptr->next) { gpgme_import_result_t res; gpgme_import_status_t pstat; @@ -246,7 +246,7 @@ verify_directive_signature(struct file_triplet *trp) if (!gpg_verify_signature(ctx, result->signatures, trp)) { UPDATE_STATS(STAT_BAD_SIGNATURE); notify(trp->spool->notification, trp, - ev_bad_directive_signature); + wy_ev_bad_directive_signature); rc = 1; } else rc = 0; @@ -269,7 +269,7 @@ verify_directive_signature(struct file_triplet *trp) NOTE: It is assumed that the public key is already registered (by a previous call to verify_directive_signature). */ int -verify_detached_signature(struct file_triplet *trp) +verify_detached_signature(struct wy_triplet *trp) { gpgme_engine_info_t info; const char *argv[5]; @@ -302,7 +302,7 @@ verify_detached_signature(struct file_triplet *trp) case exec_fail: UPDATE_STATS(STAT_BAD_SIGNATURE); wy_log(LOG_ERR, _("BAD detached signature for %s"), trp->name); - notify(spool->notification, trp, ev_bad_detached_signature); + notify(spool->notification, trp, wy_ev_bad_detached_signature); break; case exec_error: @@ -26,7 +26,7 @@ struct job { struct job *next, *prev; int state; struct spool *spool; - struct file_triplet *triplet_list; + struct wy_triplet *triplet_list; uid_t uid; pid_t pid; time_t timestamp; @@ -57,7 +57,7 @@ set_timer(time_t interval) } void -triplet_jq_unlink(struct file_triplet *tp) +triplet_jq_unlink(struct wy_triplet *tp) { if (!tp || !tp->job) return; @@ -75,12 +75,12 @@ triplet_jq_unlink(struct file_triplet *tp) void jq_clear(struct job *job) { - struct file_triplet *tp; + struct wy_triplet *tp; if (!job->triplet_list) return; for (tp = job->triplet_list; tp; ) { - struct file_triplet *next = tp->jq_next; + struct wy_triplet *next = tp->jq_next; remove_triplet(tp, 1); tp = next; } @@ -111,7 +111,7 @@ job_active_count() static int procspool(struct spool *spool, void *data) { - struct file_triplet *trp = *(struct file_triplet **)data; + struct wy_triplet *trp = *(struct wy_triplet **)data; if (!trp) return 0; @@ -229,7 +229,7 @@ job_insert(struct job *job, struct job *elt) } void -schedule_job(struct spool *spool, uid_t uid, struct file_triplet *tp) +schedule_job(struct spool *spool, uid_t uid, struct wy_triplet *tp) { struct job *job; @@ -18,7 +18,7 @@ #include "sql.h" static const char * -meta_expand(struct metadef *def, void *data) +meta_expand(struct wy_metadef *def, void *data) { if (!def->value) { if (def->expand) @@ -29,7 +29,7 @@ meta_expand(struct metadef *def, void *data) } static const char * -find_expansion_char(int c, struct metadef *def, void *data) +find_expansion_char(int c, struct wy_metadef *def, void *data) { for (; def->kw; def++) if (def->kw[1] == 0 && def->kw[0] == c) @@ -38,7 +38,7 @@ find_expansion_char(int c, struct metadef *def, void *data) } static const char * -find_expansion_word(const char *kw, size_t len, struct metadef *def, +find_expansion_word(const char *kw, size_t len, struct wy_metadef *def, void *data) { for (; def->kw; def++) @@ -48,7 +48,7 @@ find_expansion_word(const char *kw, size_t len, struct metadef *def, } char * -meta_expand_string(const char *string, struct metadef *def, void *data, +meta_expand_string(const char *string, struct wy_metadef *def, void *data, struct dictionary *dict, void *handle) { const char *p, *s; @@ -135,7 +135,7 @@ meta_expand_string(const char *string, struct metadef *def, void *data, } void -meta_free(struct metadef *def) +meta_free(struct wy_metadef *def) { for (; def->kw; def++) { if (def->storage) { @@ -145,10 +145,10 @@ meta_free(struct metadef *def) } } -struct metadef * -metadef_join(struct metadef *a, struct metadef *b) +struct wy_metadef * +metadef_join(struct wy_metadef *a, struct wy_metadef *b) { - struct metadef *np; + struct wy_metadef *np; size_t i, j; for (i = 0; a[i].kw; i++); @@ -163,3 +163,26 @@ metadef_join(struct metadef *a, struct metadef *b) np[i + j].kw = NULL; return np; } + +char * +wy_expand_stats(const char *tmpl) +{ + struct wy_metadef *exp; + time_t t; + size_t tc; + char *text; + + tc = timer_get_count() * 3; + exp = make_stat_expansion(tc + 1); + time(&t); + exp[0].kw = "date"; + exp[0].value = exp[0].storage = grecs_strdup(ctime(&t)); + exp[0].value[strlen(exp[0].value) - 1] = 0; + timer_fill_meta(exp + 1, tc); + text = meta_expand_string(tmpl, exp, NULL, NULL, NULL); + meta_free(exp); + timer_free_meta(exp + 1, tc); + free(exp); + + return text; +} diff --git a/src/module.c b/src/module.c index aa41264..212b740 100644 --- a/src/module.c +++ b/src/module.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2007-2012 Sergey Poznyakoff + Copyright (C) 2007-2013 Sergey Poznyakoff Wydawca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -233,7 +233,7 @@ module_set_init(const char *name, grecs_node_t *node) void module_notify(const char *name, void *modcfg, - enum notification_event ev, struct file_triplet *trp) + enum wy_event ev, struct wy_triplet *trp) { struct module *mod = modlookup(name); @@ -17,14 +17,14 @@ #include "wydawca.h" int -null_move_file(struct file_triplet *trp, enum file_type file_id) +null_move_file(struct wy_triplet *trp, enum file_type file_id) { const struct spool *spool = trp->spool; const char *file_name = trp->file[file_id].name; wy_debug(1, (_("spool %s: installing file `%s/%s'"), spool->tag, trp->relative_dir, file_name)); UPDATE_STATS(STAT_UPLOADS); - if (!dry_run_mode && unlink(file_name)) { + if (!wy_dry_run && unlink(file_name)) { wy_log(LOG_ERR, _("cannot unlink %s: %s"), file_name, strerror(errno)); return 1; @@ -33,7 +33,7 @@ null_move_file(struct file_triplet *trp, enum file_type file_id) } int -null_archive_file(struct file_triplet *trp, const char *file_name) +null_archive_file(struct wy_triplet *trp, const char *file_name) { wy_debug(1, (_("spool %s: archiving `%s'"), trp->spool->tag, file_name)); @@ -42,7 +42,7 @@ null_archive_file(struct file_triplet *trp, const char *file_name) } int -null_symlink_file(struct file_triplet *trp, +null_symlink_file(struct wy_triplet *trp, const char *wanted_src, const char *wanted_dst) { wy_debug(1, (_("spool %s: symlinking `%s' to `%s'"), @@ -52,7 +52,7 @@ null_symlink_file(struct file_triplet *trp, } int -null_rmsymlink_file(struct file_triplet *trp, const char *file_name) +null_rmsymlink_file(struct wy_triplet *trp, const char *file_name) { wy_debug(1, (_("spool %s: removing symlink `%s/%s'"), trp->spool->tag, trp->relative_dir, file_name)); diff --git a/src/timer.c b/src/timer.c index 1c8d68d..1b73cbf 100644 --- a/src/timer.c +++ b/src/timer.c @@ -189,7 +189,7 @@ timer_get_count() } struct timer_data { - struct metadef *def; + struct wy_metadef *def; size_t num; }; @@ -207,7 +207,7 @@ _fill_meta(void *sym, void *data) grecs_alloc_die(); \ tp->def->kw = buf; \ tp->def->storage = \ - timer_format_time(__cat2__(timer_get_,arg)(slot)); \ + timer_format_time(wy_s_cat2(timer_get_,arg)(slot)); \ tp->def->value = tp->def->storage; \ tp->def->expand = NULL; \ tp->def++; \ @@ -222,7 +222,7 @@ _fill_meta(void *sym, void *data) } void -timer_fill_meta(struct metadef *def, size_t num) +timer_fill_meta(struct wy_metadef *def, size_t num) { struct timer_data td; if (!timer_table) @@ -233,7 +233,7 @@ timer_fill_meta(struct metadef *def, size_t num) } void -timer_free_meta(struct metadef *def, size_t num) +timer_free_meta(struct wy_metadef *def, size_t num) { while (num--) { free(def->kw); diff --git a/src/triplet.c b/src/triplet.c index 932ab86..1b3569f 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -20,15 +20,15 @@ /* Triplets are stored in a symtab: */ static struct grecs_symtab *triplet_table; /* ... and are organized into a doubly-linked list, using the prev and - next members of struct file_triplet. The list is ordered so that + next members of struct wy_triplet. The list is ordered so that prev points to a triplet older than this one, and next points to a newer triplet. The triplet_list variable points to the root of the list, i.e. the oldest triplet available. */ -static struct file_triplet *triplet_list; +static struct wy_triplet *triplet_list; /* Functions for building the ordered doubly-linked list of triplets */ static time_t -triplet_timestamp(struct file_triplet *tp) +triplet_timestamp(struct wy_triplet *tp) { int i; time_t t = 0; @@ -45,7 +45,7 @@ triplet_timestamp(struct file_triplet *tp) } static time_t -triplet_ttl(struct file_triplet *tp) +triplet_ttl(struct wy_triplet *tp) { time_t t; @@ -58,7 +58,7 @@ triplet_ttl(struct file_triplet *tp) } void -triplet_list_unlink(struct file_triplet *tp) +triplet_list_unlink(struct wy_triplet *tp) { if (tp->prev) tp->prev->next = tp->next; @@ -72,8 +72,8 @@ triplet_list_unlink(struct file_triplet *tp) } static void -triplet_list_insert_before(struct file_triplet *newp, - struct file_triplet *anchor) +triplet_list_insert_before(struct wy_triplet *newp, + struct wy_triplet *anchor) { if (!anchor) { triplet_list = newp; @@ -91,10 +91,10 @@ triplet_list_insert_before(struct file_triplet *newp, } void -triplet_list_ordered_insert(struct file_triplet *tp) +triplet_list_ordered_insert(struct wy_triplet *tp) { time_t t = triplet_timestamp(tp); - struct file_triplet *p, *prev = NULL; + struct wy_triplet *p, *prev = NULL; for (p = triplet_list; p && triplet_timestamp(p) < t; prev = p, p = p->next) ; @@ -138,7 +138,7 @@ wy_userlist_free(struct wy_user *wp) static unsigned hash_triplet_hasher(void *data, unsigned long n_buckets) { - struct file_triplet const *t = data; + struct wy_triplet const *t = data; return grecs_hash_string(t->name, n_buckets); } @@ -146,8 +146,8 @@ hash_triplet_hasher(void *data, unsigned long n_buckets) static int hash_triplet_compare(void const *data1, void const *data2) { - struct file_triplet const *t1 = data1; - struct file_triplet const *t2 = data2; + struct wy_triplet const *t1 = data1; + struct wy_triplet const *t2 = data2; return t1->spool == t2->spool && strcmp(t1->name, t2->name); } @@ -156,7 +156,7 @@ void hash_triplet_free(void *data) { int i; - struct file_triplet *tp = data; + struct wy_triplet *tp = data; free(tp->name); @@ -178,7 +178,7 @@ hash_triplet_free(void *data) } char * -triplet_strdup(struct file_triplet *tp, const char *str) +triplet_strdup(struct wy_triplet *tp, const char *str) { size_t len = strlen(str); txtacc_grow(tp->acc, str, len + 1); @@ -189,12 +189,12 @@ triplet_strdup(struct file_triplet *tp, const char *str) void register_file(struct file_info *finfo, const struct spool *spool) { - struct file_triplet key, *ret; + struct wy_triplet key, *ret; int install = 1; if (!triplet_table) { triplet_table = - grecs_symtab_create(sizeof(struct file_triplet), + grecs_symtab_create(sizeof(struct wy_triplet), hash_triplet_hasher, hash_triplet_compare, NULL, @@ -222,10 +222,10 @@ register_file(struct file_info *finfo, const struct spool *spool) triplet_list_ordered_insert(ret); } -struct file_triplet * +struct wy_triplet * triplet_lookup(struct spool *spool, const char *name) { - struct file_triplet key, *ret; + struct wy_triplet key, *ret; struct file_info finfo; if (!triplet_table) @@ -248,7 +248,7 @@ triplet_lookup(struct spool *spool, const char *name) /* Return true if any part of the triplet TRP was modified more than TTL seconds ago */ static int -triplet_expired_p(struct file_triplet *trp) +triplet_expired_p(struct wy_triplet *trp) { int i; time_t now = time(NULL); @@ -279,7 +279,7 @@ enum triplet_state { }; static enum triplet_state -check_triplet_state(struct file_triplet *trp, int noauth) +check_triplet_state(struct wy_triplet *trp, int noauth) { if (trp->file[file_directive].name) { if (verify_directive_file(trp, noauth)) @@ -310,7 +310,7 @@ check_triplet_state(struct file_triplet *trp, int noauth) /* Unlink all parts of the triplet TRP */ int -remove_triplet(struct file_triplet *trp, int check) +remove_triplet(struct wy_triplet *trp, int check) { int i; @@ -326,7 +326,7 @@ remove_triplet(struct file_triplet *trp, int check) } else { wy_log(LOG_NOTICE, _("removing %s"), trp->file[i].name); - if (!dry_run_mode && unlink(trp->file[i].name)) + if (!wy_dry_run && unlink(trp->file[i].name)) wy_log(LOG_ERR, _("cannot remove %s: %s"), trp->file[i].name, @@ -353,7 +353,7 @@ triplet_sweep(void) |