aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-06 22:33:05 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2013-03-06 22:45:10 +0200
commit826bb71c57d903f760c89406f93d19fe0c131de0 (patch)
treef2fc240d52d9be2d668a6ea8a813ab5de5732647 /src
parent5b29f3ecc4e2edb172d50b23732a588b7a71ce62 (diff)
downloadwydawca-826bb71c57d903f760c89406f93d19fe0c131de0.tar.gz
wydawca-826bb71c57d903f760c89406f93d19fe0c131de0.tar.bz2
Replace mu_url_t with a custom URL.
Diffstat (limited to 'src')
-rw-r--r--src/config.c89
-rw-r--r--src/directive.c2
-rw-r--r--src/diskio.c11
-rw-r--r--src/process.c4
-rw-r--r--src/tcpwrap.c8
-rw-r--r--src/triplet.c2
-rw-r--r--src/vtab.c71
-rw-r--r--src/wydawca.c4
-rw-r--r--src/wydawca.h22
9 files changed, 180 insertions, 33 deletions
diff --git a/src/config.c b/src/config.c
index b381834..05d76de 100644
--- a/src/config.c
+++ b/src/config.c
@@ -47,2 +47,68 @@ tok_to_keyword(int tok, struct keyword *kw, const char **pres)
+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 = {
@@ -601,3 +667,4 @@ cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_value_t *value = node->v.value;
-
+ int fac;
+
if (assert_string_arg(locus, cmd, value))
@@ -605,3 +672,4 @@ cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
- if (mu_string_to_syslog_facility(value->v.string, varptr))
+ fac = wy_strtofac(value->v.string);
+ if (fac == -1)
grecs_error(&value->locus, 0,
@@ -609,2 +677,4 @@ cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
value->v.string);
+ else
+ *(int*)varptr = fac;
return 0;
@@ -1054,4 +1124,3 @@ cb_url(enum grecs_callback_command cmd, grecs_node_t *node,
{
- mu_url_t *purl = varptr, url;
- int rc;
+ wy_url_t *purl = varptr, url;
grecs_locus_t *locus = &node->locus;
@@ -1061,7 +1130,7 @@ cb_url(enum grecs_callback_command cmd, grecs_node_t *node,
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;
}
@@ -1160,3 +1229,3 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_error(locus, 0, _("unsupported url: %s"),
- mu_url_to_string(spool->dest_url));
+ wy_url_printable(spool->dest_url));
rc = 1;
@@ -1181,3 +1250,3 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node,
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);
diff --git a/src/directive.c b/src/directive.c
index ac7c4cc..b370855 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -463,3 +463,3 @@ run_check_script(const char *script, struct file_triplet *trp,
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);
diff --git a/src/diskio.c b/src/diskio.c
index 209d387..c369f85 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -698,3 +698,3 @@ 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)
{
@@ -703,8 +703,7 @@ dir_test_url(mu_url_t url, grecs_locus_t * locus)
- 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;
}
diff --git a/src/process.c b/src/process.c
index 0b4fd1b..e111e6b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -192,3 +192,3 @@ spool_add_new_file(const struct spool *spool, const char *name,
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);
@@ -212,3 +212,3 @@ scan_spool_unlocked(struct spool *spool, int uc, uid_t *uv)
logmsg(LOG_DEBUG, "%s -> %s", spool->source_dir,
- mu_url_to_string(spool->dest_url));
+ wy_url_printable(spool->dest_url));
diff --git a/src/tcpwrap.c b/src/tcpwrap.c
index 4a3e59b..9d7e7d0 100644
--- a/src/tcpwrap.c
+++ b/src/tcpwrap.c
@@ -17,3 +17,2 @@
#include "wydawca.h"
-#include <mailutils/syslog.h>
@@ -33,2 +32,3 @@ cb_syslog_priority(enum grecs_callback_command cmd, grecs_node_t *node,
grecs_value_t *value = node->v.value;
+ int pri;
@@ -36,6 +36,8 @@ cb_syslog_priority(enum grecs_callback_command cmd, grecs_node_t *node,
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
@@ -387,3 +387,3 @@ spool_commit_triplets(struct spool *spool, struct file_triplet *tplist)
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))
diff --git a/src/vtab.c b/src/vtab.c
index e02ebe7..6a23541 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -18,2 +18,67 @@
+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 {
@@ -37,8 +102,8 @@ 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;
diff --git a/src/wydawca.c b/src/wydawca.c
index f6767b8..1506b56 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -70,3 +70,3 @@ syslog_printer(int prio, const char *fmt, va_list ap)
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;
@@ -92,3 +92,3 @@ 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);
diff --git a/src/wydawca.h b/src/wydawca.h
index 8e2f155..b79b7e9 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -47,3 +47,2 @@
#include <mailutils/types.h>
-#include <mailutils/url.h>
#include <mailutils/errno.h>
@@ -207,4 +206,12 @@ struct file_triplet {
+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);
@@ -224,3 +231,3 @@ struct spool {
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 */
@@ -511,5 +518,10 @@ 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);
@@ -525,3 +537,3 @@ 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);

Return to:

Send suggestions and report system problems to the System administrator.