aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c2398
1 files changed, 1139 insertions, 1259 deletions
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 <mail.h>
-
-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 <file>"),
- 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 <file>"),
+ 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;
}