diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-06 22:33:05 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-03-06 22:45:10 +0200 |
commit | 826bb71c57d903f760c89406f93d19fe0c131de0 (patch) | |
tree | f2fc240d52d9be2d668a6ea8a813ab5de5732647 /src | |
parent | 5b29f3ecc4e2edb172d50b23732a588b7a71ce62 (diff) | |
download | wydawca-826bb71c57d903f760c89406f93d19fe0c131de0.tar.gz wydawca-826bb71c57d903f760c89406f93d19fe0c131de0.tar.bz2 |
Replace mu_url_t with a custom URL.
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 87 | ||||
-rw-r--r-- | src/directive.c | 2 | ||||
-rw-r--r-- | src/diskio.c | 11 | ||||
-rw-r--r-- | src/process.c | 4 | ||||
-rw-r--r-- | src/tcpwrap.c | 8 | ||||
-rw-r--r-- | src/triplet.c | 2 | ||||
-rw-r--r-- | src/vtab.c | 71 | ||||
-rw-r--r-- | src/wydawca.c | 4 | ||||
-rw-r--r-- | src/wydawca.h | 22 |
9 files changed, 179 insertions, 32 deletions
diff --git a/src/config.c b/src/config.c index b381834..05d76de 100644 --- a/src/config.c +++ b/src/config.c @@ -45,6 +45,72 @@ tok_to_keyword(int tok, struct keyword *kw, const char **pres) return 1; } +static struct keyword kwfac[] = { + { "USER", LOG_USER }, + { "DAEMON", LOG_DAEMON }, + { "AUTH", LOG_AUTH }, + { "AUTHPRIV",LOG_AUTHPRIV }, + { "MAIL", LOG_MAIL }, + { "CRON", LOG_CRON }, + { "LOCAL0", LOG_LOCAL0 }, + { "LOCAL1", LOG_LOCAL1 }, + { "LOCAL2", LOG_LOCAL2 }, + { "LOCAL3", LOG_LOCAL3 }, + { "LOCAL4", LOG_LOCAL4 }, + { "LOCAL5", LOG_LOCAL5 }, + { "LOCAL6", LOG_LOCAL6 }, + { "LOCAL7", LOG_LOCAL7 }, + { NULL } +}; + +static struct keyword kwpri[] = { + { "EMERG", LOG_EMERG }, + { "ALERT", LOG_ALERT }, + { "CRIT", LOG_CRIT }, + { "ERR", LOG_ERR }, + { "WARNING", LOG_WARNING }, + { "NOTICE", LOG_NOTICE }, + { "INFO", LOG_INFO }, + { "DEBUG", LOG_DEBUG }, + { NULL } +}; + +int +wy_strtofac(const char *str) +{ + int res; + if (keyword_to_tok(str, kwfac, &res)) + return -1; + return res; +} + +int +wy_strtopri(const char *str) +{ + int res; + if (keyword_to_tok(str, kwpri, &res)) + return -1; + return res; +} + +const char * +wy_pritostr(int pri) +{ + const char *res; + if (tok_to_keyword(pri, kwpri, &res)) + return NULL; + return res; +} + +const char * +wy_factostr(int fac) +{ + const char *res; + if (tok_to_keyword(fac, kwfac, &res)) + return NULL; + return res; +} + static struct archive_descr default_archive_descr = { archive_none, NULL, @@ -599,14 +665,18 @@ cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; + int fac; if (assert_string_arg(locus, cmd, value)) return 1; - if (mu_string_to_syslog_facility(value->v.string, varptr)) + fac = wy_strtofac(value->v.string); + if (fac == -1) grecs_error(&value->locus, 0, _("Unknown syslog facility `%s'"), value->v.string); + else + *(int*)varptr = fac; return 0; } @@ -1052,18 +1122,17 @@ static int cb_url(enum grecs_callback_command cmd, grecs_node_t *node, void *varptr, void *cb_data) { - mu_url_t *purl = varptr, url; - int rc; + wy_url_t *purl = varptr, url; grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; if (assert_string_arg(locus, cmd, value)) return 1; - rc = mu_url_create(&url, value->v.string); - if (rc) { + url = wy_url_create(value->v.string); + if (!url) { grecs_error(&value->locus, 0, _("cannot create URL `%s': %s"), - value->v.string, mu_strerror(rc)); - return rc; + value->v.string, strerror(errno)); + return 1; } *purl = url; return 0; @@ -1158,7 +1227,7 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node, rc = 1; } else if (url_to_vtab(spool->dest_url, &spool->vtab)) { grecs_error(locus, 0, _("unsupported url: %s"), - mu_url_to_string(spool->dest_url)); + wy_url_printable(spool->dest_url)); rc = 1; } else if (spool->vtab.test_url && spool->vtab.test_url(spool->dest_url, locus)) @@ -1179,7 +1248,7 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node, if (!spool->notification) spool->notification = default_notification; - mu_url_sget_path(spool->dest_url, &spool->dest_dir); + spool->dest_dir = wy_url_printable(spool->dest_url); register_spool(spool); free(spool); *pdata = NULL; diff --git a/src/directive.c b/src/directive.c index ac7c4cc..b370855 100644 --- a/src/directive.c +++ b/src/directive.c @@ -461,7 +461,7 @@ run_check_script(const char *script, struct file_triplet *trp, setenv("WYDAWCA_SPOOL", spool->tag, 1); setenv("WYDAWCA_SOURCE", spool->source_dir, 1); - setenv("WYDAWCA_DEST", spool->dest_dir, 1); + setenv("WYDAWCA_DEST", wy_url_path(spool->dest_url), 1); setenv("WYDAWCA_URL", spool->url, 1); setenv("WYDAWCA_TRIPLET_BASE", trp->name, 1); setenv("WYDAWCA_DIST_FILE", trp->file[file_dist].name, 1); diff --git a/src/diskio.c b/src/diskio.c index 209d387..c369f85 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -696,17 +696,16 @@ dir_rmsymlink_file(struct file_triplet *trp, const char *file_name) } int -dir_test_url(mu_url_t url, grecs_locus_t * locus) +dir_test_url(wy_url_t url, grecs_locus_t * locus) { int rc; const char *dest_dir; - rc = mu_url_sget_path(url, &dest_dir); - if (rc) { + dest_dir = wy_url_path(url); + if (!dest_dir) { grecs_error(locus, 0, - _("cannot extract directory part from URL: %s"), - mu_strerror(rc)); - return rc; + _("cannot extract directory part from URL")); + return -1; } if (test_dir(dest_dir, &rc)) { if (rc) diff --git a/src/process.c b/src/process.c index 0b4fd1b..e111e6b 100644 --- a/src/process.c +++ b/src/process.c @@ -190,7 +190,7 @@ spool_add_new_file(const struct spool *spool, const char *name, { if (debug_level) logmsg(LOG_DEBUG, "%s -> %s, adding %s", spool->source_dir, - mu_url_to_string(spool->dest_url), name); + wy_url_printable(spool->dest_url), name); if (chdir(spool->source_dir)) { logmsg(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir, @@ -210,7 +210,7 @@ scan_spool_unlocked(struct spool *spool, int uc, uid_t *uv) if (debug_level) logmsg(LOG_DEBUG, "%s -> %s", spool->source_dir, - mu_url_to_string(spool->dest_url)); + wy_url_printable(spool->dest_url)); if (chdir(spool->source_dir)) { logmsg(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir, diff --git a/src/tcpwrap.c b/src/tcpwrap.c index 4a3e59b..9d7e7d0 100644 --- a/src/tcpwrap.c +++ b/src/tcpwrap.c @@ -15,7 +15,6 @@ with wydawca. If not, see <http://www.gnu.org/licenses/>. */ #include "wydawca.h" -#include <mailutils/syslog.h> #ifdef WITH_LIBWRAP # include <tcpd.h> @@ -31,13 +30,16 @@ cb_syslog_priority(enum grecs_callback_command cmd, grecs_node_t *node, { grecs_locus_t *locus = &node->locus; grecs_value_t *value = node->v.value; + int pri; if (assert_string_arg(locus, cmd, value)) return 1; - - if (mu_string_to_syslog_priority(value->v.string, varptr)) + pri = wy_strtopri(value->v.string); + if (pri == -1) grecs_error(locus, 0, _("Unknown syslog priority `%s'"), value->v.string); + else + *(int*)varptr = pri; return 0; } diff --git a/src/triplet.c b/src/triplet.c index 2df9151..abb767a 100644 --- a/src/triplet.c +++ b/src/triplet.c @@ -385,7 +385,7 @@ spool_commit_triplets(struct spool *spool, struct file_triplet *tplist) { if (debug_level) logmsg(LOG_DEBUG, _("processing spool %s (%s)"), - spool->tag, mu_url_to_string(spool->dest_url)); + spool->tag, wy_url_printable(spool->dest_url)); if (spool_open_dictionaries(spool)) return; if (tplist) { @@ -16,6 +16,71 @@ #include "wydawca.h" +struct wy_url { + char *printable; + char *scheme; + char *path; +}; + +wy_url_t +wy_url_create(const char *str) +{ + wy_url_t url; + + url = grecs_zalloc(sizeof(url[0])); + url->printable = grecs_strdup(str); + if (*str == '/') { + url->scheme = grecs_strdup("file"); + url->path = grecs_strdup(str); + } else { + size_t len = strcspn(str, ":"); + if (!str[len]) { + wy_url_free(url); + errno = EINVAL; + return NULL; + } + url->scheme = grecs_malloc(len + 1); + memcpy(url->scheme, str, len); + url->scheme[len] = 0; + + if (str[len + 1] && strncmp(str + len + 1, "//", 2) == 0) + len += 2; + if (str[len + 1]) + url->path = grecs_strdup(str + len + 1); + else + url->path = NULL; + } + return url; +} + +void +wy_url_free(wy_url_t url) +{ + free(url->printable); + free(url->scheme); + free(url->path); + free(url); +} + +const char * +wy_url_path(wy_url_t url) +{ + return url->path; +} + +const char * +wy_url_scheme(wy_url_t url) +{ + return url->scheme; +} + +const char * +wy_url_printable(wy_url_t url) +{ + return url->printable; +} + + struct virt_tab_reg { char *scheme; struct virt_tab vtab; @@ -35,12 +100,12 @@ static struct virt_tab_reg reg[] = { }; int -url_to_vtab(mu_url_t url, struct virt_tab *vtab) +url_to_vtab(wy_url_t url, struct virt_tab *vtab) { - const char *scheme; + const char *scheme = wy_url_scheme(url); int i; - if (mu_url_sget_scheme(url, &scheme)) + if (!scheme) return 1; for (i = 0; reg[i].scheme; i++) if (strcmp(reg[i].scheme, scheme) == 0) { diff --git a/src/wydawca.c b/src/wydawca.c index f6767b8..1506b56 100644 --- a/src/wydawca.c +++ b/src/wydawca.c @@ -68,7 +68,7 @@ syslog_printer(int prio, const char *fmt, va_list ap) if (syslog_include_prio) { static char *fmtbuf; static size_t fmtsize; - const char *p = mu_syslog_priority_to_string(prio); + const char *p = wy_pritostr(prio); size_t size = strlen(p) + 3 + strlen(fmt) + 1; if (size > fmtsize) { @@ -90,7 +90,7 @@ syslog_printer(int prio, const char *fmt, va_list ap) void stderr_printer(int prio, const char *fmt, va_list ap) { - const char *p = mu_syslog_priority_to_string(prio); + const char *p = wy_pritostr(prio); fprintf(stderr, "%s: ", program_name); if (p) diff --git a/src/wydawca.h b/src/wydawca.h index 8e2f155..b79b7e9 100644 --- a/src/wydawca.h +++ b/src/wydawca.h @@ -45,7 +45,6 @@ #include <regex.h> #include <mailutils/types.h> -#include <mailutils/url.h> #include <mailutils/errno.h> #include "grecs.h" @@ -205,8 +204,16 @@ struct file_triplet { /* GID is filled in after the triplet is finalized and verified */ #define TRIPLET_GID(t) ((t)->file[file_directive].sb.st_gid) +typedef struct wy_url *wy_url_t; + +wy_url_t wy_url_create(const char *str); +void wy_url_free(wy_url_t url); +const char *wy_url_path(wy_url_t url); +const char *wy_url_scheme(wy_url_t url); +const char *wy_url_printable(wy_url_t url); + struct virt_tab { - int (*test_url) (mu_url_t url, grecs_locus_t * loc); + int (*test_url) (wy_url_t url, grecs_locus_t * loc); int (*move_file) (struct file_triplet * trp, enum file_type file_id); int (*archive_file) (struct file_triplet * trp, const char *file_name); int (*symlink_file) (struct file_triplet * trp, @@ -222,7 +229,7 @@ struct spool { struct grecs_list *aliases; char *url; /* Download URL */ char *source_dir; /* Source directory */ - mu_url_t dest_url; /* Destination URL */ + wy_url_t dest_url; /* Destination URL */ const char *dest_dir; /* Directory part of the above */ struct virt_tab vtab; /* Virtual method table */ int inotify_enable; @@ -509,9 +516,14 @@ int assert_string_arg(grecs_locus_t *, enum grecs_callback_command, const grecs_value_t *); grecs_value_t *get_arg(grecs_value_t *value, unsigned n, int type); +int wy_strtofac(const char *str); +int wy_strtopri(const char *str); +const char *wy_pritostr(int pri); +const char *wy_factostr(int fac); + /* vtab.c */ -int url_to_vtab(mu_url_t url, struct virt_tab *vtab); +int url_to_vtab(wy_url_t url, struct virt_tab *vtab); int move_file(struct file_triplet *trp, enum file_type file_id); int archive_file(struct file_triplet *trp, const char *file_name); @@ -523,7 +535,7 @@ int rmsymlink_file(struct file_triplet *trp, const char *file_name); char *concat_dir(const char *base, const char *name, size_t * pbaselen); int copy_file(const char *file, const char *dst_file); -int dir_test_url(mu_url_t url, grecs_locus_t * locus); +int dir_test_url(wy_url_t url, grecs_locus_t * locus); int dir_move_file(struct file_triplet *trp, enum file_type file_id); int dir_archive_file(struct file_triplet *trp, const char *reldir); int dir_symlink_file(struct file_triplet *trp, |