From 24e6dfa7cffceea0cac0f3cc349192788f040939 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Tue, 1 Jan 2013 13:25:55 +0200 Subject: Update copyright years. Switch to a familiar style. --- Makefile.am | 2 +- NEWS | 6 +- README | 4 +- configure.ac | 2 +- doc/Makefile.am | 2 +- doc/wydawca.texi | 2 +- src/Makefile.am | 2 +- src/backup.c | 251 +++--- src/builtin.c | 337 ++++---- src/builtin.h | 14 +- src/cmdline.opt | 93 +-- src/config.c | 2398 ++++++++++++++++++++++++++---------------------------- src/dictionary.c | 305 ++++--- src/directive.c | 1152 +++++++++++++------------- src/diskio.c | 1155 +++++++++++++------------- src/exec.c | 253 +++--- src/gpg.c | 527 ++++++------ src/interval.c | 161 ++-- src/job.c | 572 +++++++------ src/lock.c | 434 +++++----- src/mail.c | 1069 ++++++++++++------------ src/mail.h | 9 +- src/meta.c | 221 +++-- src/net.c | 415 +++++----- src/null.c | 68 +- src/pidfile.c | 104 +-- src/process.c | 469 ++++++----- src/pushd.c | 206 +++-- src/report.c | 45 +- src/sql.c | 272 +++---- src/sql.h | 55 +- src/tcpwrap.c | 85 +- src/timer.c | 309 ++++--- src/triplet.c | 1270 ++++++++++++++--------------- src/txtacc.c | 228 +++--- src/userprivs.c | 160 ++-- src/verify.c | 538 ++++++------ src/vtab.c | 97 ++- src/watcher.c | 379 +++++---- src/wydawca.c | 608 +++++++------- src/wydawca.h | 735 ++++++++--------- 41 files changed, 7206 insertions(+), 7808 deletions(-) diff --git a/Makefile.am b/Makefile.am index bb9a634..1f44e4b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # This file is part of Wydawca -# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff +# Copyright (C) 2007, 2009-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 diff --git a/NEWS b/NEWS index f28ec2a..37a7a20 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,5 @@ -Wydawca NEWS -- history of user-visible changes. 2012-12-29 -Copyright (C) 2007-2012 Sergey Poznyakoff +Wydawca NEWS -- history of user-visible changes. 2013-01-01 +Copyright (C) 2007-2013 Sergey Poznyakoff See the end of file for copying conditions. Please send Wydawca bug reports to . @@ -164,7 +164,7 @@ Version 1.0, 2008-08-23 ---------------------------------------------------------------------- Copyright information: -Copyright (C) 2007-2012 Sergey Poznyakoff +Copyright (C) 2007-2013 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the diff --git a/README b/README index 8023707..af2f499 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ Wydawca README -Copyright (C) 2007-2008, 2010-2012 Sergey Poznyakoff +Copyright (C) 2007-2008, 2010-2013 Sergey Poznyakoff See the end of file for copying conditions. * Introduction @@ -37,7 +37,7 @@ Send bug reports to . * Copyright information: -Copyright (C) 2007, 2008, 2010-2012 Sergey Poznyakoff +Copyright (C) 2007-2008, 2010-2013 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the diff --git a/configure.ac b/configure.ac index 2683b9b..ba5e261 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # This file is part of Wydawca -*- autoconf -*- -# Copyright (C) 2007-2011 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 diff --git a/doc/Makefile.am b/doc/Makefile.am index 70a084f..31fdbb2 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,5 +1,5 @@ # This file is part of Wydawca -# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff +# Copyright (C) 2007, 2009-2013 Sergey Poznyakoff # # Wudawca is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free diff --git a/doc/wydawca.texi b/doc/wydawca.texi index 21b015a..e73a9dc 100644 --- a/doc/wydawca.texi +++ b/doc/wydawca.texi @@ -31,7 +31,7 @@ Published by the Free Software Foundation, 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA -Copyright @copyright{} 2007, 2009-2012 Sergey Poznyakoff +Copyright @copyright{} 2007, 2009-2013 Sergey Poznyakoff Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or diff --git a/src/Makefile.am b/src/Makefile.am index e042272..2c8f3c4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ # This file is part of Wydawca -# Copyright (C) 2007, 2009-2011 Sergey Poznyakoff +# Copyright (C) 2007, 2009-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 diff --git a/src/backup.c b/src/backup.c index c5c55de..7119ae1 100644 --- a/src/backup.c +++ b/src/backup.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2011, 2012 Sergey Poznyakoff + Copyright (C) 2011-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 @@ -19,147 +19,138 @@ char const *simple_backup_suffix = "~"; static const char * -split_filename (char const *file, char **pdir) +split_filename(char const *file, char **pdir) { - const char *p = strrchr (file, '/'); - - if (!p) - { - *pdir = grecs_strdup ("."); - p = file; - } - else - { - size_t len = p - file; - char *dir = grecs_malloc (len + 1); - memcpy (dir, file, len); - dir[len] = 0; - *pdir = dir; - p++; - } - return p; + const char *p = strrchr(file, '/'); + + if (!p) { + *pdir = grecs_strdup("."); + p = file; + } else { + size_t len = p - file; + char *dir = grecs_malloc(len + 1); + memcpy(dir, file, len); + dir[len] = 0; + *pdir = dir; + p++; + } + return p; } #define MINSUFSIZE 8 #define ISDIGIT(c) ('0' <= (c) && (c) <= '9') static char * -get_backup_suffix (char const *file, enum backup_type type) +get_backup_suffix(char const *file, enum backup_type type) { - char *dirname; - const char *basename; - size_t baselen; - DIR *dir; - struct dirent *ent; - char *lastsuf = NULL; - size_t lastsuflen = 0; - size_t lastsufsize = 0; - int carry = 0; - char *newsuf; - char *q; - - if (type == simple_backups) - return grecs_strdup (simple_backup_suffix); - - basename = split_filename (file, &dirname); - baselen = strlen (basename); - dir = opendir (dirname); - if (!dir) - { - int ec = errno; - free (dirname); - errno = ec; - return NULL; - } - - while ((ent = readdir (dir))) - { - size_t len = strlen (ent->d_name); - const char *p; - size_t suflen; - - if (len < baselen + 4 || memcmp (ent->d_name, basename, baselen)) - continue; - p = ent->d_name + baselen; - suflen = len - baselen; - if (p[0] == '.' && p[1] == '~' && p[suflen-1] == '~' && - (suflen > lastsuflen - || (suflen == lastsuflen && - memcmp (p, lastsuf, lastsuflen) > 0))) - { - carry = 1; - for (q = (char*) p + suflen - 2; q > p + 1 && ISDIGIT (*q); q--) - if (*q != '9') - carry = 0; - q++; - if (!ISDIGIT (*q)) - continue; - - if (suflen > lastsufsize) - { - lastsufsize = suflen; - if (!lastsuf) - { - if (lastsufsize < MINSUFSIZE) - lastsufsize = MINSUFSIZE; - lastsuf = grecs_malloc (lastsufsize); + char *dirname; + const char *basename; + size_t baselen; + DIR *dir; + struct dirent *ent; + char *lastsuf = NULL; + size_t lastsuflen = 0; + size_t lastsufsize = 0; + int carry = 0; + char *newsuf; + char *q; + + if (type == simple_backups) + return grecs_strdup(simple_backup_suffix); + + basename = split_filename(file, &dirname); + baselen = strlen(basename); + dir = opendir(dirname); + if (!dir) { + int ec = errno; + free(dirname); + errno = ec; + return NULL; + } + + while ((ent = readdir(dir))) { + size_t len = strlen(ent->d_name); + const char *p; + size_t suflen; + + if (len < baselen + 4 || + memcmp(ent->d_name, basename, baselen)) + continue; + p = ent->d_name + baselen; + suflen = len - baselen; + if (p[0] == '.' && p[1] == '~' && p[suflen - 1] == '~' && + (suflen > lastsuflen + || (suflen == lastsuflen && + memcmp(p, lastsuf, lastsuflen) > 0))) { + carry = 1; + for (q = (char *)p + suflen - 2; + q > p + 1 && ISDIGIT(*q); q--) + if (*q != '9') + carry = 0; + q++; + if (!ISDIGIT(*q)) + continue; + + if (suflen > lastsufsize) { + lastsufsize = suflen; + if (!lastsuf) { + if (lastsufsize < MINSUFSIZE) + lastsufsize = MINSUFSIZE; + lastsuf = grecs_malloc(lastsufsize); + } else + lastsuf = grecs_realloc(lastsuf, + lastsufsize); + } + memcpy(lastsuf, p, suflen); + lastsuflen = suflen; } - else - lastsuf = grecs_realloc (lastsuf, lastsufsize); - } - memcpy (lastsuf, p, suflen); - lastsuflen = suflen; } - } - closedir (dir); - free (dirname); - - if (lastsuf) - { - size_t newsuflen; - - newsuflen = lastsuflen + carry; - newsuf = grecs_malloc (newsuflen + 1); - newsuf[0] = '.'; - newsuf[1] = '~'; - newsuf[2] = '0'; - memcpy (newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3); - newsuf[newsuflen-1] = '~'; - newsuf[newsuflen] = 0; - - for (q = newsuf + newsuflen - 2; *q == '9'; q--) - *q = '0'; - ++*q; - free (lastsuf); - } - else if (type == numbered_existing_backups) - newsuf = grecs_strdup (simple_backup_suffix); - else - newsuf = grecs_strdup (".~1~"); - return newsuf; + closedir(dir); + free(dirname); + + if (lastsuf) { + size_t newsuflen; + + newsuflen = lastsuflen + carry; + newsuf = grecs_malloc(newsuflen + 1); + newsuf[0] = '.'; + newsuf[1] = '~'; + newsuf[2] = '0'; + memcpy(newsuf + 2 + carry, lastsuf + 2, lastsuflen - 3); + newsuf[newsuflen - 1] = '~'; + newsuf[newsuflen] = 0; + + for (q = newsuf + newsuflen - 2; *q == '9'; q--) + *q = '0'; + ++*q; + free(lastsuf); + } else if (type == numbered_existing_backups) + newsuf = grecs_strdup(simple_backup_suffix); + else + newsuf = grecs_strdup(".~1~"); + return newsuf; } char * -find_backup_file_name (char const *file, enum backup_type type) +find_backup_file_name(char const *file, enum backup_type type) { - size_t flen; - char *suffix; - char *newname; - - if (type == no_backups) - { - errno = 0; - return NULL; - } - - suffix = get_backup_suffix (file, type); - if (!suffix) - return NULL; - flen = strlen (file); - newname = grecs_malloc (flen + strlen (suffix) + 1); - memcpy (newname, file, flen); - strcpy (newname + flen, suffix); - free (suffix); - /* FIXME: Check newname length */ - return newname; + size_t flen; + char *suffix; + char *newname; + + if (type == no_backups) { + errno = 0; + return NULL; + } + + suffix = get_backup_suffix(file, type); + if (!suffix) + return NULL; + flen = strlen(file); + newname = grecs_malloc(flen + strlen(suffix) + 1); + memcpy(newname, file, flen); + strcpy(newname + flen, suffix); + free(suffix); + /* FIXME: Check newname length */ + return newname; } diff --git a/src/builtin.c b/src/builtin.c index f031897..72b73cd 100644 --- a/src/builtin.c +++ b/src/builtin.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2009-2011 Sergey Poznyakoff + Copyright (C) 2009-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 @@ -22,21 +22,21 @@ #endif int -builtin_init (struct dictionary *dict) +builtin_init(struct dictionary *dict) { - return 0; + return 0; } int -builtin_done (struct dictionary *dict) +builtin_done(struct dictionary *dict) { - return 0; + return 0; } void * -builtin_open (struct dictionary *dict) +builtin_open(struct dictionary *dict) { - return dict; + return dict; } #define CMP_EXACT 0 @@ -52,216 +52,203 @@ builtin_open (struct dictionary *dict) typedef int (*strcmp_fn) (const char *, const char *, int flags); static int -cmp_exact (const char *pat, const char *str, int flags) +cmp_exact(const char *pat, const char *str, int flags) { - return strcmp (pat, str) == 0; + return strcmp(pat, str) == 0; } static int -cmp_exact_ci (const char *pat, const char *str, int flags) +cmp_exact_ci(const char *pat, const char *str, int flags) { - return strcmp (pat, str) == 0; + return strcmp(pat, str) == 0; } static int -cmp_fnmatch (const char *pat, const char *str, int flags) +cmp_fnmatch(const char *pat, const char *str, int flags) { - return fnmatch (pat, str, flags) == 0; + return fnmatch(pat, str, flags) == 0; } static int -cmp_regex (const char *pat, const char *str, int flags) +cmp_regex(const char *pat, const char *str, int flags) { - int rc; - regex_t regex; - - rc = regcomp (®ex, pat, flags); - if (rc) - { - char errbuf[512]; - - regerror (rc, ®ex, errbuf, sizeof (errbuf)); - logmsg (LOG_ERR, _("%s: cannot compile regexp: %s"), pat, errbuf); - return 0; - } - - rc = regexec (®ex, str, 0, NULL, 0); - regfree (®ex); - return rc == 0; + int rc; + regex_t regex; + + rc = regcomp(®ex, pat, flags); + if (rc) { + char errbuf[512]; + + regerror(rc, ®ex, errbuf, sizeof(errbuf)); + logmsg(LOG_ERR, _("%s: cannot compile regexp: %s"), pat, + errbuf); + return 0; + } + + rc = regexec(®ex, str, 0, NULL, 0); + regfree(®ex); + return rc == 0; } int -parse_cmp_type (const char *pat, strcmp_fn *cmpfn, int *rf) +parse_cmp_type(const char *pat, strcmp_fn * cmpfn, int *rf) { - size_t len = strcspn (pat, ","); - int flags = 0; - int cmp; - - if (STRMATCH ("exact", pat, len)) - cmp = CMP_EXACT; - else if (STRMATCH ("fnmatch", pat, len)) - cmp = CMP_FNMATCH; - else if (STRMATCH ("regex", pat, len)) - cmp = CMP_REGEX; - else - return 1; - - pat += len; - if (*pat) - { - while (*++pat) - { - switch (*pat) - { - case 'i': - flags |= RF_ICASE; - break; - - case 'b': - flags |= RF_BASIC; - break; - - default: - logmsg (LOG_NOTICE, _("unrecognized comparison flag: %c"), *pat); - } + size_t len = strcspn(pat, ","); + int flags = 0; + int cmp; + + if (STRMATCH("exact", pat, len)) + cmp = CMP_EXACT; + else if (STRMATCH("fnmatch", pat, len)) + cmp = CMP_FNMATCH; + else if (STRMATCH("regex", pat, len)) + cmp = CMP_REGEX; + else + return 1; + + pat += len; + if (*pat) { + while (*++pat) { + switch (*pat) { + case 'i': + flags |= RF_ICASE; + break; + + case 'b': + flags |= RF_BASIC; + break; + + default: + logmsg(LOG_NOTICE, + _("unrecognized comparison flag: %c"), + *pat); + } + } + } + + switch (cmp) { + case CMP_EXACT: + *cmpfn = (flags & RF_ICASE) ? cmp_exact_ci : cmp_exact; + break; + + case CMP_FNMATCH: + *cmpfn = cmp_fnmatch; + *rf = FNM_NOESCAPE | FNM_PERIOD | + ((flags & RF_ICASE) ? FNM_CASEFOLD : 0); + break; + + case CMP_REGEX: + *cmpfn = cmp_regex; + *rf = ((flags & RF_BASIC) ? 0 : REG_EXTENDED) | REG_NOSUB; + if (flags & RF_ICASE) + *rf |= REG_ICASE; + break; } - } - - switch (cmp) - { - case CMP_EXACT: - *cmpfn = (flags & RF_ICASE) ? cmp_exact_ci : cmp_exact; - break; - - case CMP_FNMATCH: - *cmpfn = cmp_fnmatch; - *rf = FNM_NOESCAPE | FNM_PERIOD | - ((flags & RF_ICASE) ? FNM_CASEFOLD : 0); - break; - - case CMP_REGEX: - *cmpfn = cmp_regex; - *rf = ((flags & RF_BASIC) ? 0 : REG_EXTENDED) | REG_NOSUB; - if (flags & RF_ICASE) - *rf |= REG_ICASE; - break; - } - return 0; + return 0; } -struct builtin_data_storage -{ - struct txtacc *acc; - char **wp; +struct builtin_data_storage { + struct txtacc *acc; + char **wp; }; static int default_ncol[] = { - 4, /* project-uploader: name, realname, email, pubkey */ - 2, /* project-owner: email, realname */ + 4, /* project-uploader: name, realname, email, pubkey */ + 2, /* project-owner: email, realname */ }; int -builtin_lookup (struct dictionary *dict, void *handle, const char *req) +builtin_lookup(struct dictionary *dict, void *handle, const char *req) { - int i; - int rc; - size_t count = 0; - struct txtacc *acc; - int flags = 0; - strcmp_fn cmpfn = cmp_exact; - struct builtin_data_storage *bds; - int ncol = default_ncol[dict->id]; - - if (dict->parmc == 0) - { - dict->nrow = dict->ncol = 0; - return 0; - } + int i; + int rc; + size_t count = 0; + struct txtacc *acc; + int flags = 0; + strcmp_fn cmpfn = cmp_exact; + struct builtin_data_storage *bds; + int ncol = default_ncol[dict->id]; + + if (dict->parmc == 0) { + dict->nrow = dict->ncol = 0; + return 0; + } - acc = txtacc_create (); + acc = txtacc_create(); - for (i = 0; i < dict->parmc; i++) - { - char *pat = dict->parmv[i]; + for (i = 0; i < dict->parmc; i++) { + char *pat = dict->parmv[i]; - if (pat[0] == '/') - { - pat++; - if (*pat != '/' && parse_cmp_type (pat, &cmpfn, &flags) == 0) - continue; - } + if (pat[0] == '/') { + pat++; + if (*pat != '/' + && parse_cmp_type(pat, &cmpfn, &flags) == 0) + continue; + } + + if (i + ncol >= dict->parmc) + break; + + if (cmpfn(pat, req, flags)) { + size_t j; + for (j = 1; j <= ncol; j++) { + char *val = dict->parmv[i + j]; + txtacc_grow(acc, val, strlen(val) + 1); + } + count++; + } - if (i + ncol >= dict->parmc) - break; - - if (cmpfn (pat, req, flags)) - { - size_t j; - for (j = 1; j <= ncol; j++) - { - char *val = dict->parmv[i + j]; - txtacc_grow (acc, val, strlen (val) + 1); - } - count++; + i += ncol; } - i += ncol; - } - - dict->nrow = count; - dict->ncol = ncol; - - if (count == 0) - { - txtacc_free (acc); - bds = NULL; - rc = 1; - } - else - { - size_t i; - char *p; - - bds = grecs_malloc (sizeof (*bds)); - count *= ncol; - bds->wp = grecs_calloc (count, sizeof (bds->wp[0])); - bds->acc = acc; - p = txtacc_finish (acc, 0); - - for (i = 0; i < count; i++) - { - bds->wp[i] = p; - p += strlen (p) + 1; + dict->nrow = count; + dict->ncol = ncol; + + if (count == 0) { + txtacc_free(acc); + bds = NULL; + rc = 1; + } else { + size_t i; + char *p; + + bds = grecs_malloc(sizeof(*bds)); + count *= ncol; + bds->wp = grecs_calloc(count, sizeof(bds->wp[0])); + bds->acc = acc; + p = txtacc_finish(acc, 0); + + for (i = 0; i < count; i++) { + bds->wp[i] = p; + p += strlen(p) + 1; + } + rc = 0; } - rc = 0; - } - dict->storage = bds; + dict->storage = bds; - return rc; + return rc; } int -builtin_free_result (struct dictionary *dict, void *handle) +builtin_free_result(struct dictionary *dict, void *handle) { - if (dict->storage) - { - struct builtin_data_storage *bds = dict->storage; - txtacc_free (bds->acc); - free (bds->wp); - free (bds); - dict->storage = NULL; - } - return 0; + if (dict->storage) { + struct builtin_data_storage *bds = dict->storage; + txtacc_free(bds->acc); + free(bds->wp); + free(bds); + dict->storage = NULL; + } + return 0; } int -builtin_get (struct dictionary *dict, void *handle, - unsigned nrow, unsigned ncol) +builtin_get(struct dictionary *dict, void *handle, unsigned nrow, + unsigned ncol) { - struct builtin_data_storage *bds = dict->storage; - char *str = bds->wp[nrow * dict->ncol + ncol]; - dictionary_copy_result (dict, str, strlen (str)); - return 0; + struct builtin_data_storage *bds = dict->storage; + char *str = bds->wp[nrow * dict->ncol + ncol]; + dictionary_copy_result(dict, str, strlen(str)); + return 0; } - diff --git a/src/builtin.h b/src/builtin.h index 7e5245d..a5bcfbc 100644 --- a/src/builtin.h +++ b/src/builtin.h @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2009-2011 Sergey Poznyakoff + Copyright (C) 2009-2013 Sergey Poznyakoff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -14,9 +14,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -int builtin_init (struct dictionary *); -int builtin_done (struct dictionary *); -void *builtin_open (struct dictionary *); -int builtin_get (struct dictionary *, void *, unsigned, unsigned); -int builtin_lookup (struct dictionary *, void *, const char *); -int builtin_free_result (struct dictionary *, void *); +int builtin_init(struct dictionary *); +int builtin_done(struct dictionary *); +void *builtin_open(struct dictionary *); +int builtin_get(struct dictionary *, void *, unsigned, unsigned); +int builtin_lookup(struct dictionary *, void *, const char *); +int builtin_free_result(struct dictionary *, void *); diff --git a/src/cmdline.opt b/src/cmdline.opt index c9554b8..6f2fbf6 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon -*- c -*- - Copyright (C) 2007, 2009-2012 Sergey Poznyakoff + Copyright (C) 2007, 2009-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 @@ -22,29 +22,30 @@ static struct grecs_list *tag_list; static int string_cmp (const void *elt1, const void *elt2) { - return strcmp ((const char *)elt1, (const char *)elt2); + return strcmp ((const char *)elt1, (const char *)elt2); } int selected_spools () { - return (source_list != NULL || tag_list != NULL); + return (source_list != NULL || tag_list != NULL); } int enabled_spool_p (const struct spool *spool) { - if (source_list || tag_list) - return (source_list && grecs_list_locate (source_list, spool->source_dir)) - || (tag_list && grecs_list_locate (tag_list, spool->tag)); - return 1; + if (source_list || tag_list) + return (source_list && + grecs_list_locate (source_list, spool->source_dir)) || + (tag_list && grecs_list_locate (tag_list, spool->tag)); + return 1; } OPTIONS_BEGIN("wydawca", [], [], [], - [], + [], []) GROUP(Selecting program mode) @@ -105,23 +106,21 @@ END OPTION(spool,S,TAG, []) BEGIN - if (!tag_list) - { - tag_list = grecs_list_create (); - tag_list->cmp = string_cmp; - } - grecs_list_append (tag_list, optarg); + if (!tag_list) { + tag_list = grecs_list_create(); + tag_list->cmp = string_cmp; + } + grecs_list_append(tag_list, optarg); END OPTION(source,s,SOURCE-DIR, []) BEGIN - if (!source_list) - { - source_list = grecs_list_create (); - source_list->cmp = string_cmp; - } - grecs_list_append (source_list, optarg); + if (!source_list) { + source_list = grecs_list_create(); + source_list->cmp = string_cmp; + } + grecs_list_append(source_list, optarg); END GROUP(Logging) @@ -143,7 +142,7 @@ GROUP(Preprocessor control) OPTION(include-directory,I,DIR, []) BEGIN - grecs_preproc_add_include_dir (optarg); + grecs_preproc_add_include_dir(optarg); END OPTION(define,D,SYMBOL[=VALUE], @@ -152,15 +151,14 @@ BEGIN char *p; if (!pp_cmd_acc) - pp_cmd_acc = txtacc_create (); - txtacc_grow (pp_cmd_acc, " \"-D", 4); - for (p = optarg; *p; p++) - { - if (*p == '\\' || *p == '"') - txtacc_1grow (pp_cmd_acc, '\\'); - txtacc_1grow (pp_cmd_acc, *p); - } - txtacc_1grow (pp_cmd_acc, '"'); + pp_cmd_acc = txtacc_create (); + txtacc_grow(pp_cmd_acc, " \"-D", 4); + for (p = optarg; *p; p++) { + if (*p == '\\' || *p == '"') + txtacc_1grow(pp_cmd_acc, '\\'); + txtacc_1grow(pp_cmd_acc, *p); + } + txtacc_1grow(pp_cmd_acc, '"'); END OPTION(preprocessor,,COMMAND, @@ -186,21 +184,21 @@ END OPTION(dump-grammar-trace,,, []) BEGIN - grecs_gram_trace (1); + grecs_gram_trace(1); END OPTION(dump-lex-trace,,, []) BEGIN - grecs_lex_trace (1); + grecs_lex_trace(1); END GROUP([]) OPTION(config-help,,, []) BEGIN - config_help (); - exit (0); + config_help(); + exit(0); END OPTIONS_END @@ -208,18 +206,17 @@ OPTIONS_END void parse_options(int argc, char *argv[]) { - GETOPT(argc, argv) - if (pp_cmd_acc && grecs_preprocessor) - { - char *cmd; - size_t len = strlen (grecs_preprocessor); - txtacc_1grow (pp_cmd_acc, 0); - txtacc_grow (pp_cmd_acc, grecs_preprocessor, len + 1); - cmd = txtacc_finish (pp_cmd_acc, 1); - txtacc_free (pp_cmd_acc); - memmove (cmd + len + 1, cmd, strlen (cmd) + 1); - memcpy (cmd, grecs_preprocessor, len); - cmd[len] = ' '; - grecs_preprocessor = cmd; - } + GETOPT(argc, argv); + if (pp_cmd_acc && grecs_preprocessor) { + char *cmd; + size_t len = strlen(grecs_preprocessor); + txtacc_1grow(pp_cmd_acc, 0); + txtacc_grow(pp_cmd_acc, grecs_preprocessor, len + 1); + cmd = txtacc_finish(pp_cmd_acc, 1); + txtacc_free(pp_cmd_acc); + memmove(cmd + len + 1, cmd, strlen(cmd) + 1); + memcpy(cmd, grecs_preprocessor, len); + cmd[len] = ' '; + grecs_preprocessor = cmd; + } } diff --git a/src/config.c b/src/config.c index 509b0d5..7cc667a 100644 --- a/src/config.c +++ b/src/config.c @@ -17,48 +17,42 @@ #include "wydawca.h" #include "sql.h" #include - -struct keyword -{ - char *name; - int tok; +struct keyword { + char *name; + int tok; }; static int -keyword_to_tok (const char *str, struct keyword *kw, int *pres) +keyword_to_tok(const char *str, struct keyword *kw, int *pres) { - for (; kw->name; kw++) - if (strcmp (kw->name, str) == 0) - { - *pres = kw->tok; - return 0; - } - return 1; + for (; kw->name; kw++) + if (strcmp(kw->name, str) == 0) { + *pres = kw->tok; + return 0; + } + return 1; } static int -tok_to_keyword (int tok, struct keyword *kw, const char **pres) +tok_to_keyword(int tok, struct keyword *kw, const char **pres) { - for (; kw->name; kw++) - if (kw->tok == tok) - { - *pres = kw->name; - return 0; - } - return 1; + for (; kw->name; kw++) + if (kw->tok == tok) { + *pres = kw->name; + return 0; + } + return 1; } - static struct archive_descr default_archive_descr = { - archive_none, - NULL, - no_backups + archive_none, + NULL, + no_backups }; static struct dictionary *default_dictionary[dictionary_count]; static struct notification *default_notification = NULL; - /* safe_file_name: convert a file name possibly containig relative specs (../) into a safer form using only direct descendence. @@ -70,1485 +64,1371 @@ static struct notification *default_notification = NULL; ../file --> NULL */ char * -safe_file_name (char *file_name) +safe_file_name(char *file_name) { - int len; - char *p; - - if (!file_name) - return file_name; - - len = strlen (file_name); - - /* Empty string is returned as is */ - if (len == 0) - return file_name; - - /* delete trailing delimiter if any */ - if (len && file_name[len-1] == '/') - file_name[len-1] = 0; - - /* Eliminate any ./ and /../ */ - for (p = strchr (file_name, '.'); p; p = strchr (p, '.')) - { - if (p[1] == '/' && (p == file_name || p[-1] == '/')) - { - char *q, *s; - - s = p + 2; - q = p; - while ((*q++ = *s++)) - ; - continue; - } - else if (p[1] == '.' && (p[2] == 0 || p[2] == '/')) - { - if (p == file_name) - return NULL; - if (p[-1] == '/') - /* found */ - { - char *q, *s; - - s = p + 2; - - /* Find previous delimiter */ - for (q = p-2; *q != '/' && q >= file_name; q--) - ; - - if (q < file_name) - { - q = file_name; - s++; + int len; + char *p; + + if (!file_name) + return file_name; + + len = strlen(file_name); + + /* Empty string is returned as is */ + if (len == 0) + return file_name; + + /* delete trailing delimiter if any */ + if (len && file_name[len - 1] == '/') + file_name[len - 1] = 0; + + /* Eliminate any ./ and /../ */ + for (p = strchr(file_name, '.'); p; p = strchr(p, '.')) { + if (p[1] == '/' && (p == file_name || p[-1] == '/')) { + char *q, *s; + + s = p + 2; + q = p; + while ((*q++ = *s++)) ; + continue; + } else if (p[1] == '.' && (p[2] == 0 || p[2] == '/')) { + if (p == file_name) + return NULL; + if (p[-1] == '/') { + /* found */ + char *q, *s; + + s = p + 2; + + /* Find previous delimiter */ + for (q = p - 2; *q != '/' && q >= file_name; + q--) ; + + if (q < file_name) { + q = file_name; + s++; + } + + /* Copy stuff */ + p = q; + while ((*q++ = *s++)) ; + continue; + } } - /* Copy stuff */ - p = q; - while ((*q++ = *s++)) - ; - continue; - } + p++; } - p++; - } - - if (file_name[0] == 0) - { - file_name[0] = '/'; - file_name[1] = 0; - } + if (file_name[0] == 0) { + file_name[0] = '/'; + file_name[1] = 0; + } - return file_name; + return file_name; } /* Same as safe_file_name, but returns an allocated copy. */ char * -safe_file_name_alloc (const char *file_name) +safe_file_name_alloc(const char *file_name) { - char *s = grecs_strdup (file_name); - char *ns = safe_file_name (s); - if (!ns) - free (s); - return ns; + char *s = grecs_strdup(file_name); + char *ns = safe_file_name(s); + if (!ns) + free(s); + return ns; } - 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 }, - { NULL } + { "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 }, + {NULL} }; const char * -notification_event_str (enum notification_event evt) +notification_event_str(enum notification_event evt) { - const char *ret; - if (tok_to_keyword (evt, event_tab, &ret)) - { - grecs_error (NULL, 0, - _("INTERNAL ERROR: unknown notification event number: %d"), - evt); - return NULL; - } - return ret; + const char *ret; + if (tok_to_keyword(evt, event_tab, &ret)) { + grecs_error(NULL, 0, + _("INTERNAL ERROR: " + "unknown notification event number: %d"), + evt); + return NULL; + } + return ret; } int -string_to_notification_event (grecs_locus_t *locus, const char *val, - enum notification_event *pret) +string_to_notification_event(grecs_locus_t * locus, const char *val, + enum notification_event *pret) { - int res; - if (keyword_to_tok (val, event_tab, &res)) - { - grecs_error (locus, 0, _("unknown notification event: %s"), val); - return 1; - } - *pret = res; - return 0; + int res; + if (keyword_to_tok(val, event_tab, &res)) { + grecs_error(locus, 0, + _("unknown notification event: %s"), val); + return 1; + } + *pret = res; + return 0; } static struct keyword target_tab[] = { - { "read", notify_read }, /* Read recipients from the message headers */ - { "message", notify_read }, - { "admin", notify_admin}, /* System administrator */ - { "owner", notify_owner }, /* Project admin */ - { "user", notify_user }, /* User (uploader) */ - { NULL } + { "read", notify_read }, /* Read recipients from the message + headers */ + { "message", notify_read }, + { "admin", notify_admin }, /* System administrator */ + { "owner", notify_owner }, /* Project admin */ + { "user", notify_user }, /* User (uploader) */ + { NULL } }; - const char * -notification_target_str (enum notification_target tgt) +notification_target_str(enum notification_target tgt) { - const char *ret; - if (tok_to_keyword (tgt, target_tab, &ret)) - { - grecs_error (NULL, 0, - _("INTERNAL ERROR: unknown notification target number: %d"), - tgt); - return NULL; - } - return ret; + const char *ret; + if (tok_to_keyword(tgt, target_tab, &ret)) { + grecs_error(NULL, 0, + _("INTERNAL ERROR: " + "unknown notification target number: %d"), + tgt); + return NULL; + } + return ret; } int -string_to_notification_target (grecs_locus_t *locus, const char *val, - enum notification_target *pret) +string_to_notification_target(grecs_locus_t * locus, const char *val, + enum notification_target *pret) { - int res; - if (keyword_to_tok (val, target_tab, &res)) - { - grecs_error (locus, 0, - _("unknown notification target: %s"), - val); - return 1; - } - *pret = res; - return 0; + int res; + if (keyword_to_tok(val, target_tab, &res)) { + grecs_error(locus, 0, + _("unknown notification target: %s"), val); + return 1; + } + *pret = res; + return 0; } - int -assert_string_arg (grecs_locus_t *locus, - enum grecs_callback_command cmd, - const grecs_value_t *value) +assert_string_arg(grecs_locus_t * locus, + enum grecs_callback_command cmd, const grecs_value_t * value) { - if (cmd != grecs_callback_set_value) - { - grecs_error (locus, 0, _("Unexpected block statement")); - return 1; - } - if (!value || value->type != GRECS_TYPE_STRING) - { - grecs_error (&value->locus, 0, _("expected scalar value as a tag")); - return 1; - } - return 0; + if (cmd != grecs_callback_set_value) { + grecs_error(locus, 0, _("Unexpected block statement")); + return 1; + } + if (!value || value->type != GRECS_TYPE_STRING) { + grecs_error(&value->locus, 0, + _("expected scalar value as a tag")); + return 1; + } + return 0; } grecs_value_t * -get_arg (grecs_locus_t *locus, grecs_value_t *value, unsigned n, int type) +get_arg(grecs_locus_t * locus, grecs_value_t * value, unsigned n, int type) { - if (n >= value->v.arg.c) - { - grecs_error (locus, 0, _("not enough arguments")); - return NULL; - } - value = value->v.arg.v[n]; - if (value->type != type) - { - grecs_error (&value->locus, 0, _("argument %d has wrong type"), n); - return NULL; - } - return value; + if (n >= value->v.arg.c) { + grecs_error(locus, 0, _("not enough arguments")); + return NULL; + } + value = value->v.arg.v[n]; + if (value->type != type) { + grecs_error(&value->locus, 0, _("argument %d has wrong type"), + n); + return NULL; + } + return value; } - static int -cb_mailer (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_mailer(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - int rc; - - if (assert_string_arg (locus, cmd, value)) - return 1; - rc = mu_mailer_create (&mailer, value->v.string); - if (rc) - grecs_error (&value->locus, 0, _("cannot create mailer `%s': %s"), - value->v.string, mu_strerror (rc)); - return rc; + int rc; + + if (assert_string_arg(locus, cmd, value)) + return 1; + rc = mu_mailer_create(&mailer, value->v.string); + if (rc) + grecs_error(&value->locus, 0, + _("cannot create mailer `%s': %s"), + value->v.string, + mu_strerror(rc)); + return rc; } static int -cb_email_address (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_email_address(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - int rc = 1; - mu_address_t addr = NULL; - - switch (value->type) - { - case GRECS_TYPE_STRING: - rc = mu_address_create (&addr, value->v.string); - if (rc) - { - grecs_error (&value->locus, 0, _("%s: invalid email address: %s"), - value->v.string, mu_strerror (rc)); - return rc; - } - break; - - case GRECS_TYPE_LIST: - { + int rc = 1; + mu_address_t addr = NULL; struct grecs_list_entry *ep; - for (ep = value->v.list->head; ep; ep = ep->next) - { - const grecs_value_t *vp = ep->data; - mu_address_t a; - if (assert_string_arg (locus, cmd, vp)) - return 1; - - rc = mu_address_create (&a, vp->v.string); - if (rc == 0) - rc = mu_address_union (&addr, a); - else - { - grecs_error (&value->locus, 0, - _("%s: invalid email address: %s"), - vp->v.string, mu_strerror (rc)); - } - mu_address_destroy (&a); - if (rc) - break; - } - } - break; - - case GRECS_TYPE_ARRAY: - grecs_error (locus, 0, _("too many arguments")); - return 1; - } - - *(mu_address_t*) varptr = addr; - return rc; + switch (value->type) { + case GRECS_TYPE_STRING: + rc = mu_address_create(&addr, value->v.string); + if (rc) { + grecs_error(&value->locus, 0, + _("%s: invalid email address: %s"), + value->v.string, mu_strerror(rc)); + return rc; + } + break; + + case GRECS_TYPE_LIST: + for (ep = value->v.list->head; ep; ep = ep->next) { + const grecs_value_t *vp = ep->data; + mu_address_t a; + if (assert_string_arg(locus, cmd, vp)) + return 1; + + rc = mu_address_create(&a, vp->v.string); + if (rc == 0) + rc = mu_address_union(&addr, a); + else { + grecs_error(&value->locus, 0, + _("%s: invalid email address: %s"), + vp->v.string, + mu_strerror(rc)); + } + mu_address_destroy(&a); + if (rc) + break; + } + break; + + case GRECS_TYPE_ARRAY: + grecs_error(locus, 0, _("too many arguments")); + return 1; + } + + *(mu_address_t *) varptr = addr; + return rc; } static int -cb_interval (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_interval(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - int rc; - time_t interval; - const char *endp; - - /* FIXME 1: Support arrays */ - if (assert_string_arg (locus, cmd, value)) - return 1; - - /* FIXME 2: Support ISO intervals? */ - rc = parse_time_interval (value->v.string, &interval, &endp); - if (rc) - grecs_error (&value->locus, 0, - _("unrecognized interval format (near `%s')"), - endp); - else - *(time_t*) varptr = interval; - return 0; + int rc; + time_t interval; + const char *endp; + + /* FIXME 1: Support arrays */ + if (assert_string_arg(locus, cmd, value)) + return 1; + + /* FIXME 2: Support ISO intervals? */ + rc = parse_time_interval(value->v.string, &interval, &endp); + if (rc) + grecs_error(&value->locus, 0, + _("unrecognized interval format (near `%s')"), + endp); + else + *(time_t *) varptr = interval; + return 0; } static int -cb_absolute_name (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_absolute_name(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - char *word; - - /* FIXME 1: Support arrays */ - if (assert_string_arg (locus, cmd, value)) - return 1; - - word = safe_file_name ((char*)value->v.string); - if (!word || word[0] != '/') - grecs_error (&value->locus, 0, _("must be an absolute file name")); - else - *(char**) varptr = word; - return 0; + char *word; + + /* FIXME 1: Support arrays */ + if (assert_string_arg(locus, cmd, value)) + return 1; + + word = safe_file_name((char *)value->v.string); + if (!word || word[0] != '/') + grecs_error(&value->locus, 0, + _("must be an absolute file name")); + else + *(char **)varptr = word; + return 0; } static int -cb_set_umask (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_set_umask(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - char *p; - mode_t m; - - if (assert_string_arg (locus, cmd, value)) - return 1; - m = strtoul (value->v.string, &p, 8) & 0777; - if (*p) - grecs_error (&value->locus, 0, _("invalid umask (near %s)"), p); - else - umask (m); - return 0; + char *p; + mode_t m; + + if (assert_string_arg(locus, cmd, value)) + return 1; + m = strtoul(value->v.string, &p, 8) & 0777; + if (*p) + grecs_error(&value->locus, 0, _("invalid umask (near %s)"), p); + else + umask(m); + return 0; } - static struct keyword 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 }, + { "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) +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 (keyword_to_tok (arg, stat_tab, &x)) - { - grecs_error (&val->locus, 0, _("unknown statistics type: %s"), arg); - return 1; - } - *pmask = STAT_MASK (x); - return 0; + 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 (keyword_to_tok(arg, stat_tab, &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) +parse_statmask(grecs_locus_t * loc, grecs_value_t * val, unsigned long *pmask) { - int err = 0; - int invert = 0; - unsigned long mask = 0; - - switch (val->type) - { - case GRECS_TYPE_STRING: - err = parse_single_statmask (loc, val, &mask, &invert); - break; - - case GRECS_TYPE_ARRAY: - { + int err = 0; + int invert = 0; + unsigned long mask = 0; int i; - - 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: - { struct grecs_list_entry *ep; - 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; + 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_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_statistics(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - return parse_statmask (locus, value, varptr); + return parse_statmask(locus, value, varptr); } - static int -cb_sql_host (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_sql_host(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - struct sqlconn *pconn = varptr; - char *p; - - if (assert_string_arg (locus, cmd, value)) - return 1; - - p = strchr (value->v.string, ':'); - if (p) - { - /* FIXME: Modifies constant string */ - *p++ = 0; - if (p[0] == '/') - { - pconn->socket = grecs_strdup (p); - pconn->host = grecs_strdup ("localhost"); - } - else - { - char *end; - unsigned long n = strtoul (p, &end, 10); - if (*end) - { - grecs_error (&value->locus, 0, - _("invalid port number (near %s)"), end); - return 0; - } - if (n == 0 || n > USHRT_MAX) - { - grecs_error (&value->locus, 0, - _("port number out of range 1..%d"), - USHRT_MAX); - return 0; - } - pconn->port = n; - /* Save host name */ - pconn->host = grecs_strdup (value->v.string); - } - } - else - pconn->host = grecs_strdup (value->v.string); - return 0; + struct sqlconn *pconn = varptr; + char *p; + + if (assert_string_arg(locus, cmd, value)) + return 1; + + p = strchr(value->v.string, ':'); + if (p) { + /* FIXME: Modifies constant string */ + *p++ = 0; + if (p[0] == '/') { + pconn->socket = grecs_strdup(p); + pconn->host = grecs_strdup("localhost"); + } else { + char *end; + unsigned long n = strtoul(p, &end, 10); + if (*end) { + grecs_error(&value->locus, 0, + _("invalid port number (near %s)"), + end); + return 0; + } + if (n == 0 || n > USHRT_MAX) { + grecs_error(&value->locus, 0, + _("port number out of range 1..%d"), + USHRT_MAX); + return 0; + } + pconn->port = n; + /* Save host name */ + pconn->host = grecs_strdup(value->v.string); + } + } else + pconn->host = grecs_strdup(value->v.string); + return 0; } static int -cb_sql (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_sql(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - struct sqlconn *pconn; - void **pdata = cb_data; - - switch (cmd) { - case grecs_callback_section_begin: - if (!value || value->type != GRECS_TYPE_STRING) - { - grecs_error(value ? &value->locus : locus, 0, - _("tag must be a string")); + struct sqlconn *pconn; + void **pdata = cb_data; + + switch (cmd) { + case grecs_callback_section_begin: + if (!value || value->type != GRECS_TYPE_STRING) { + grecs_error(value ? &value->locus : locus, 0, + _("tag must be a string")); + return 0; + } + pconn = grecs_zalloc(sizeof(*pconn)); + pconn->ident = strdup(value->v.string); + *pdata = pconn; + break; + + case grecs_callback_section_end: + pconn = *pdata; + sql_register_conn(pconn); + free(pconn); + *pdata = NULL; + break; + + case grecs_callback_set_value: + grecs_error(locus, 0, _("invalid use of block statement")); + } return 0; - } - pconn = grecs_zalloc (sizeof (*pconn)); - pconn->ident = strdup (value->v.string); - *pdata = pconn; - break; - - case grecs_callback_section_end: - pconn = *pdata; - sql_register_conn (pconn); - free (pconn); - *pdata = NULL; - break; - - case grecs_callback_set_value: - grecs_error (locus, 0, _("invalid use of block statement")); - } - return 0; } static struct grecs_keyword sql_kw[] = { - { "config-file", N_("file"), N_("Read MySQL configuration from "), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, config_file) }, - { "config-group", N_("name"), - N_("Read the named group from the SQL configuration file"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, config_group) }, - { "host", N_("host"), N_("Set SQL server hostname or IP address"), - grecs_type_string, GRECS_DFLT, - NULL, 0, cb_sql_host }, - { "database", N_("dbname"), N_("Set database name"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, database), }, - { "user", N_("name"), N_("Set SQL user name"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, user) }, - { "password", N_("arg"), N_("Set SQL user password"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, password) }, - { "ssl-ca", N_("file"), N_("File name of the Certificate Authority (CA) certificate"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct sqlconn, cacert) }, - { NULL } + { "config-file", N_("file"), + N_("Read MySQL configuration from "), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, config_file) }, + { "config-group", N_("name"), + N_("Read the named group from the SQL configuration file"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, config_group) }, + { "host", N_("host"), + N_("Set SQL server hostname or IP address"), + grecs_type_string, GRECS_DFLT, + NULL, 0, cb_sql_host }, + { "database", N_("dbname"), N_("Set database name"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, database), }, + { "user", N_("name"), N_("Set SQL user name"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, user) }, + { "password", N_("arg"), N_("Set SQL user password"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, password) }, + { "ssl-ca", N_("file"), + N_("File name of the Certificate Authority (CA) certificate"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct sqlconn, cacert) }, + { NULL } }; - static int -cb_syslog_facility (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_syslog_facility(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - if (assert_string_arg (locus, cmd, value)) - return 1; + if (assert_string_arg(locus, cmd, value)) + return 1; - if (mu_string_to_syslog_facility (value->v.string, varptr)) - grecs_error (&value->locus, 0, _("Unknown syslog facility `%s'"), - value->v.string); - return 0; + if (mu_string_to_syslog_facility(value->v.string, varptr)) + grecs_error(&value->locus, 0, + _("Unknown syslog facility `%s'"), + value->v.string); + return 0; } - static int -cb_define_message (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_define_message(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - const char *ident; - - if (cmd != grecs_callback_set_value) - { - grecs_error (locus, 0, _("Unexpected block statement")); - return 1; - } - if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) - { - grecs_error (locus, 0, _("expected two arguments")); - return 1; - } - - if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) - { - grecs_error (&value->v.arg.v[0]->locus, 0, - _("first argument not a string")); - return 1; - } - ident = value->v.arg.v[0]->v.string; - - if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) - { - grecs_error (&value->v.arg.v[1]->locus, 0, - _("second argument not a string")); - return 1; - } - - register_message_template (ident, value->v.arg.v[1]->v.string); - return 0; -} + const char *ident; - + if (cmd != grecs_callback_set_value) { + grecs_error(locus, 0, _("Unexpected block statement")); + return 1; + } + if (!value || value->type != GRECS_TYPE_ARRAY || value->v.arg.c != 2) { + grecs_error(locus, 0, _("expected two arguments")); + return 1; + } + + if (value->v.arg.v[0]->type != GRECS_TYPE_STRING) { + grecs_error(&value->v.arg.v[0]->locus, 0, + _("first argument not a string")); + return 1; + } + ident = value->v.arg.v[0]->v.string; + if (value->v.arg.v[1]->type != GRECS_TYPE_STRING) { + grecs_error(&value->v.arg.v[1]->locus, 0, + _("second argument not a string")); + return 1; + } + + register_message_template(ident, value->v.arg.v[1]->v.string); + return 0; +} + static struct grecs_keyword syslog_kw[] = { - { "facility", - N_("name"), - N_("Set syslog facility. Arg is one of the following: user, daemon, " - "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), " - "or a facility number."), - grecs_type_string, GRECS_DFLT, - &log_facility, 0, cb_syslog_facility }, - { "tag", N_("string"), N_("Tag syslog messages with this string"), - grecs_type_string, GRECS_DFLT, - &syslog_tag }, - { "print-priority", N_("arg"), N_("Prefix each message with its priority"), - grecs_type_bool, GRECS_DFLT, - &syslog_include_prio }, - { NULL }, + { "facility", + N_("name"), + N_("Set syslog facility. Arg is one of the following: user, daemon, " + "auth, authpriv, mail, cron, local0 through local7 " + "(case-insensitive), or a facility number."), + grecs_type_string, GRECS_DFLT, + &log_facility, 0, cb_syslog_facility }, + { "tag", N_("string"), N_("Tag syslog messages with this string"), + grecs_type_string, GRECS_DFLT, + &syslog_tag }, + { "print-priority", N_("arg"), + N_("Prefix each message with its priority"), + grecs_type_bool, GRECS_DFLT, + &syslog_include_prio }, + { NULL }, }; - -static struct keyword backup_tab[] = -{ - { "none", no_backups }, - { "off", no_backups }, - { "simple", simple_backups }, - { "never", simple_backups }, - { "existing", numbered_existing_backups }, - { "nil", numbered_existing_backups }, - { "numbered", numbered_backups }, - { "t", numbered_backups }, - { NULL } +static struct keyword backup_tab[] = { + { "none", no_backups }, + { "off", no_backups }, + { "simple", simple_backups }, + { "never", simple_backups }, + { "existing", numbered_existing_backups }, + { "nil", numbered_existing_backups }, + { "numbered", numbered_backups }, + { "t", numbered_backups }, + { NULL } }; static enum backup_type -get_backup_version (grecs_locus_t *locus, const char *ctx, const char *version) +get_backup_version(grecs_locus_t * locus, const char *ctx, const char *version) { - int d; - - if (version == 0 || *version == 0) - return numbered_existing_backups; - else if (keyword_to_tok (version, backup_tab, &d)) - { - if (ctx) - grecs_error (locus, 0, _("%s: ambiguous backup type `%s'"), - ctx, version); - else - grecs_error (locus, 0, _("ambiguous backup type `%s'"), version); - return no_backups; - } - return d; + int d; + + if (version == 0 || *version == 0) + return numbered_existing_backups; + else if (keyword_to_tok(version, backup_tab, &d)) { + if (ctx) + grecs_error(locus, 0, + _("%s: ambiguous backup type `%s'"), ctx, + version); + else + grecs_error(locus, 0, _("ambiguous backup type `%s'"), + version); + return no_backups; + } + return d; } static int -cb_backup (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_backup(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - enum backup_type *ptype = varptr; + enum backup_type *ptype = varptr; - if (assert_string_arg (locus, cmd, value)) - return 1; - *ptype = get_backup_version (&value->locus, NULL, value->v.string); - return 0; + if (assert_string_arg(locus, cmd, value)) + return 1; + *ptype = get_backup_version(&value->locus, NULL, value->v.string); + return 0; } static struct grecs_keyword archive_kw[] = { - { "name", N_("file-or-dir"), N_("Name of archive file or directory"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct archive_descr, name) }, - { "backup", N_("type"), N_("Define backup type"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct archive_descr, backup_type), - cb_backup }, - { NULL } + { "name", N_("file-or-dir"), + N_("Name of archive file or directory"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct archive_descr, name) }, + { "backup", N_("type"), + N_("Define backup type"), + grecs_type_string, GRECS_DFLT, + NULL, offsetof(struct archive_descr, backup_type), + cb_backup }, + { NULL } }; static int -cb_archive (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_archive(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - struct archive_descr *arch = varptr; - void **pdata = cb_data; - - switch (cmd) - { - case grecs_callback_section_begin: - *pdata = arch; - /* fallthrough */ - case grecs_callback_set_value: - if (!value) - { - grecs_error (locus, 0, _("expected tag")); - return 1; - } + struct archive_descr *arch = varptr; + void **pdata = cb_data; + + switch (cmd) { + case grecs_callback_section_begin: + *pdata = arch; + /* fallthrough */ + case grecs_callback_set_value: + if (!value) { + grecs_error(locus, 0, _("expected tag")); + return 1; + } - if (value->type != GRECS_TYPE_STRING) - { - grecs_error (&value->locus, 0, - _("expected scalar value but found list")); - return 1; - } + if (value->type != GRECS_TYPE_STRING) { + grecs_error(&value->locus, 0, + _("expected scalar value but found list")); + return 1; + } - if (strcmp (value->v.string, "none") == 0) - arch->type = archive_none; - else if (strcmp (value->v.string, "tar") == 0) - arch->type = archive_tar; - else if (strcmp (value->v.string, "directory") == 0) - arch->type = archive_directory; - else - { - grecs_error (&value->locus, 0, _("unknown archive type")); - return 1; - } - if (cmd == grecs_callback_section_begin) - return 0; - break; + if (strcmp(value->v.string, "none") == 0) + arch->type = archive_none; + else if (strcmp(value->v.string, "tar") == 0) + arch->type = archive_tar; + else if (strcmp(value->v.string, "directory") == 0) + arch->type = archive_directory; + else { + grecs_error(&value->locus, 0, + _("unknown archive type")); + return 1; + } + if (cmd == grecs_callback_section_begin) + return 0; + break; - case grecs_callback_section_end: - break; - } + case grecs_callback_section_end: + break; + } - if (arch->type == archive_none) - return 0; + if (arch->type == archive_none) + return 0; - if (arch->name == NULL) - { - grecs_error (locus, 0, _("at least archive name must be set")); - return 1; - } + if (arch->name == NULL) { + grecs_error(locus, 0, _("at least archive name must be set")); + return 1; + } - if (arch->type == archive_tar && arch->backup_type != no_backups) - { - grecs_warning (locus, 0, _("backup type ignored for this archive type")); - return 1; - } + if (arch->type == archive_tar && arch->backup_type != no_backups) { + grecs_warning(locus, 0, + _("backup type ignored for this archive type")); + return 1; + } - return 0; + return 0; } - 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 }, - { "gpg-sign", - N_("key"), N_("Sign message with this key"), - grecs_type_string, GRECS_DFLT, &admin_stat_sign_key }, - { NULL } + { "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 }, + { "gpg-sign", + N_("key"), N_("Sign message with this key"), + grecs_type_string, GRECS_DFLT, &admin_stat_sign_key }, + { NULL } }; - - static int -cb_event (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_event(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - enum notification_event *pev = varptr; + enum notification_event *pev = varptr; - if (assert_string_arg (locus, cmd, value)) - return 1; - string_to_notification_event (&value->locus, value->v.string, pev); - return 0; + if (assert_string_arg(locus, cmd, value)) + return 1; + string_to_notification_event(&value->locus, value->v.string, pev); + return 0; } static int -cb_recipient (enum grecs_callback_command cmd, - grecs_locus_t *locus, - void *varptr, - grecs_value_t *value, - void *cb_data) +cb_recipient(enum grecs_callback_command cmd, + grecs_locus_t * locus, + void *varptr, grecs_value_t * value, void *cb_data) { - enum notification_target *tgt = varptr; + enum notification_target *tgt = varptr; - if (assert_string_arg (locus, cmd, value)) - return 1; - string_to_notification_target (&value->locus, value->v.string, tgt); - return 0; + if (assert_string_arg(locus, cmd, value)) + return 1; + string_to_notification_target(&value->locus, value->v.string, tgt); + return 0; } static struct grecs_keyword notify_event_kw[] = { - { "event", N_("ev-id"), N_("Event on which to notify"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct notification, ev), cb_event }, - { "recipient", N_("who"), N_("Notify this recipient"), - grecs_type_string, GRECS_DFLT, - NULL, offsetof(struct notification, tgt), - cb_recipient }, - { "message", N_("text-or-id"), - N_("Text of the notification or identifier of a defined message t