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/triplet.c | |
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/triplet.c')
-rw-r--r-- | src/triplet.c | 176 |
1 files changed, 91 insertions, 85 deletions
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) static int triplet_processor(void *data, void *proc_data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; wy_debug(1, ("FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s", trp->name, @@ -391,7 +391,7 @@ triplet_processor(void *data, void *proc_data) /* Process all triplets from the table according to the SPOOL */ void -spool_commit_triplets(struct spool *spool, struct file_triplet *tplist) +spool_commit_triplets(struct spool *spool, struct wy_triplet *tplist) { wy_debug(1, (_("processing spool %s (%s)"), spool->tag, wy_url_printable(spool->dest_url))); @@ -399,7 +399,7 @@ spool_commit_triplets(struct spool *spool, struct file_triplet *tplist) return; if (tplist) { while (tplist) { - struct file_triplet *next = tplist->jq_next; + struct wy_triplet *next = tplist->jq_next; if (tplist->spool == spool) triplet_processor(tplist, NULL); tplist = next; @@ -417,13 +417,13 @@ count_collected_triplets() } struct count_closure { - struct file_triplet *tp; + struct wy_triplet *tp; }; static int triplet_linker(void *data, void *proc_data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; struct count_closure *cp = proc_data; if (trp->job) @@ -456,7 +456,7 @@ triplet_linker(void *data, void *proc_data) return 0; } -struct file_triplet * +struct wy_triplet * link_processable_triplets() { struct count_closure clos; @@ -470,7 +470,7 @@ link_processable_triplets() void triplet_remove_file(struct spool *spool, const char *name) { - struct file_triplet *tp = triplet_lookup(spool, name); + struct wy_triplet *tp = triplet_lookup(spool, name); int i, n = 0; if (!tp) @@ -493,45 +493,45 @@ triplet_remove_file(struct spool *spool, const char *name) } static const char * -expand_project_base(struct metadef *def, void *data) +expand_project_base(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->project; } static const char * -expand_tag(struct metadef *def, void *data) +expand_tag(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->spool->tag; } static const char * -expand_url(struct metadef *def, void *data) +expand_url(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->spool->url; } static const char * -expand_relative_dir(struct metadef *def, void *data) +expand_relative_dir(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; directive_get_value(trp, "directory", (const char **)&def->value); return def->value; } static const char * -expand_dest_dir(struct metadef *def, void *data) +expand_dest_dir(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->spool->dest_dir; } static const char * -expand_source_dir(struct metadef *def, void *data) +expand_source_dir(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->spool->source_dir; } @@ -561,7 +561,7 @@ decode_file_mode(mode_t mode, char *string) static int ugswidth = 19; static int -format_file_data(struct file_triplet *trp, enum file_type type, char **pret) +format_file_data(struct wy_triplet *trp, enum file_type type, char **pret) { char modes[11]; struct file_info *info = trp->file + type; @@ -623,9 +623,9 @@ format_file_data(struct file_triplet *trp, enum file_type type, char **pret) } static const char * -expand_triplet_ls_full(struct metadef *def, void *data) +expand_triplet_ls_full(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; char *buf[FILE_TYPE_COUNT] = { NULL, NULL, NULL }; size_t size = 0; @@ -657,9 +657,9 @@ expand_triplet_ls_full(struct metadef *def, void *data) } static const char * -expand_triplet_ls_upload(struct metadef *def, void *data) +expand_triplet_ls_upload(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; char *buf[2] = { NULL, NULL }; size_t size = 0; @@ -686,57 +686,57 @@ expand_triplet_ls_upload(struct metadef *def, void *data) } static const char * -expand_triplet_dist(struct metadef *def, void *data) +expand_triplet_dist(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->file[file_dist].name; } static const char * -expand_triplet_sig(struct metadef *def, void *data) +expand_triplet_sig(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->file[file_signature].name; } static const char * -expand_triplet_dir(struct metadef *def, void *data) +expand_triplet_dir(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->file[file_directive].name; } static const char * -expand_triplet_ls_dist(struct metadef *def, void *data) +expand_triplet_ls_dist(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; format_file_data(trp, file_dist, &def->storage); def->value = def->storage; return def->value; } static const char * -expand_triplet_ls_sig(struct metadef *def, void *data) +expand_triplet_ls_sig(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; format_file_data(trp, file_signature, &def->storage); def->value = def->storage; return def->value; } static const char * -expand_triplet_ls_directive(struct metadef *def, void *data) +expand_triplet_ls_directive(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; format_file_data(trp, file_directive, &def->storage); def->value = def->storage; return def->value; } static const char * -expand_user_name(struct metadef *def, void *data) +expand_user_name(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; if (trp->uploader) return trp->uploader->name; def->value = "UNKNOWN"; @@ -744,9 +744,9 @@ expand_user_name(struct metadef *def, void *data) } static const char * -expand_user_real_name(struct metadef *def, void *data) +expand_user_real_name(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; if (trp->uploader) return trp->uploader->realname; def->value = "UNKNOWN"; @@ -754,9 +754,9 @@ expand_user_real_name(struct metadef *def, void *data) } static const char * -expand_user_email(struct metadef *def, void *data) +expand_user_email(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; if (trp->uploader) return trp->uploader->email; def->value = "UNKNOWN"; @@ -764,9 +764,9 @@ expand_user_email(struct metadef *def, void *data) } static const char * -expand_email_user(struct metadef *def, void *data) +expand_email_user(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; if (trp->uploader) { size_t size = 0; if (grecs_asprintf(&def->storage, &size, "\"%s\" <%s>", @@ -779,31 +779,31 @@ expand_email_user(struct metadef *def, void *data) } static const char * -expand_report(struct metadef *def, void *data) +expand_report(struct wy_metadef *def, void *data) { return report_string; } static const char * -expand_comment(struct metadef *def, void *data) +expand_comment(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; if (directive_get_value(trp, "comment", (const char **)&def->value)) def->value = ""; return def->value; } static const char * -expand_check_diagn(struct metadef *def, void *data) +expand_check_diagn(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; return trp->check_diag; } static const char * -expand_check_result(struct metadef *def, void *data) +expand_check_result(struct wy_metadef *def, void *data) { - struct file_triplet *trp = data; + struct wy_triplet *trp = data; int status = trp->check_result; if (status == 0) @@ -827,10 +827,10 @@ expand_check_result(struct metadef *def, void *data) #define DECL_EXPAND_TIMER(what) \ static const char * \ -__cat2__(expand_timer_,what) (struct metadef *def, void *data) \ +wy_s_cat2(expand_timer_,what) (struct wy_metadef *def, void *data) \ { \ wydawca_timer_t t = timer_stop ((char*)def->data); \ - def->storage = timer_format_time (__cat2__(timer_get_,what) (t)); \ + def->storage = timer_format_time (wy_s_cat2(timer_get_,what) (t)); \ return def->value = def->storage; \ } @@ -838,12 +838,12 @@ DECL_EXPAND_TIMER(real) DECL_EXPAND_TIMER(user) DECL_EXPAND_TIMER(system) #define DECL_TIMER(name,t) \ - { "timer:" #name ":" #t, NULL, __cat2__(expand_timer_,t), NULL, #name } + { "timer:" #name ":" #t, NULL, wy_s_cat2(expand_timer_,t), NULL, #name } #define DECL_FULL_TIMER(name) \ DECL_TIMER(name, real), \ DECL_TIMER(name, user), \ DECL_TIMER(name, system) -struct metadef triplet_default_meta[] = { +struct wy_metadef triplet_default_meta[] = { { "u", NULL, expand_user_name, NULL }, { "user", NULL, expand_user_name, NULL }, { "user:name", NULL, expand_user_name, NULL }, @@ -860,7 +860,7 @@ struct metadef triplet_default_meta[] = { char * triplet_expand_dictionary_query(struct dictionary *dict, void *handle, - struct file_triplet const *trp) + struct wy_triplet const *trp) { char *p = meta_expand_string(dict->query, triplet_default_meta, (void*) trp, @@ -869,7 +869,7 @@ triplet_expand_dictionary_query(struct dictionary *dict, void *handle, return p; } -struct metadef triplet_meta[] = { +struct wy_metadef triplet_meta[] = { { "project", NULL, expand_project_base, NULL }, { "url", NULL, expand_url, NULL }, { "spool", NULL, expand_tag, NULL }, @@ -900,11 +900,11 @@ struct metadef triplet_meta[] = { }; char * -triplet_expand_param(const char *tmpl, struct file_triplet const *trp, - struct metadef *xmeta) +wy_triplet_expand_param(const char *tmpl, struct wy_triplet const *trp, + struct wy_metadef *xmeta) { char *p; - struct metadef *mp = metadef_join(triplet_meta, xmeta); + struct wy_metadef *mp = metadef_join(triplet_meta, xmeta); p = meta_expand_string(tmpl, mp, (void *)trp, NULL, NULL); meta_free(mp); @@ -913,7 +913,7 @@ triplet_expand_param(const char *tmpl, struct file_triplet const *trp, } struct wy_user * -triplet_get_uploaders(struct file_triplet *trp) +wy_triplet_get_uploaders(struct wy_triplet *trp) { const struct spool *spool; struct dictionary *dict; @@ -1024,14 +1024,14 @@ triplet_get_uploaders(struct file_triplet *trp) } struct wy_user * -triplet_get_uploader(struct file_triplet *trp) +wy_triplet_get_uploader(struct wy_triplet *trp) { return trp->uploader; } struct wy_user * -triplet_get_admins(struct file_triplet *trp) +wy_triplet_get_admins(struct wy_triplet *trp) { const struct spool *spool; struct dictionary *dict; @@ -1116,3 +1116,9 @@ triplet_get_admins(struct file_triplet *trp) return trp->admin_list; } + +const char * +wy_triplet_project(struct wy_triplet *trp) +{ + return trp->project; +} |