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
@@ -42,12 +42,78 @@ tok_to_keyword(int tok, struct keyword *kw, const char **pres)
*pres = kw->name;
return 0;
}
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,
no_backups
};
@@ -596,20 +662,24 @@ static struct grecs_keyword sql_kw[] = {
static int
cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
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;
}
static int
cb_define_message(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
@@ -1049,24 +1119,23 @@ cb_dictionary(enum grecs_callback_command cmd, grecs_node_t *node,
}
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;
}
static struct grecs_keyword spool_kw[] = {
@@ -1155,13 +1224,13 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node,
if (!spool->dest_url) {
grecs_error(locus, 0, _("destination is not given"));
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))
rc = 1;
for (i = 0; i < dictionary_count; i++)
@@ -1176,13 +1245,13 @@ cb_spool(enum grecs_callback_command cmd, grecs_node_t *node,
if (rc)
return rc;
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;
break;
case grecs_callback_set_value:
diff --git a/src/directive.c b/src/directive.c
index ac7c4cc..b370855 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -458,13 +458,13 @@ run_check_script(const char *script, struct file_triplet *trp,
strerror(errno));
_exit(127);
}
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);
if (chdir(temp_homedir)) {
logmsg(LOG_CRIT, "cannot change to %s: %s",
diff --git a/src/diskio.c b/src/diskio.c
index 209d387..c369f85 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -693,23 +693,22 @@ dir_rmsymlink_file(struct file_triplet *trp, const char *file_name)
free(dst_file);
free(dst_dir);
return rc;
}
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)
grecs_error(locus, rc, _("cannot access %s"),
dest_dir);
else
diff --git a/src/process.c b/src/process.c
index 0b4fd1b..e111e6b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -187,13 +187,13 @@ spool_cwd_add_new_file(const struct spool *spool, const char *name,
int
spool_add_new_file(const struct spool *spool, const char *name,
int uc, uid_t * uv)
{
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,
strerror(errno));
return -1;
}
@@ -207,13 +207,13 @@ scan_spool_unlocked(struct spool *spool, int uc, uid_t *uv)
{
DIR *dir;
struct dirent *ent;
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,
strerror(errno));
return;
}
diff --git a/src/tcpwrap.c b/src/tcpwrap.c
index 4a3e59b..9d7e7d0 100644
--- a/src/tcpwrap.c
+++ b/src/tcpwrap.c
@@ -12,13 +12,12 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#include "wydawca.h"
-#include <mailutils/syslog.h>
#ifdef WITH_LIBWRAP
# include <tcpd.h>
static int tcpwrap_enable;
static char *tcpwrap_daemon;
@@ -28,19 +27,22 @@ int allow_severity = LOG_INFO;
static int
cb_syslog_priority(enum grecs_callback_command cmd, grecs_node_t *node,
void *varptr, void *cb_data)
{
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;
}
struct grecs_keyword tcpwrapper_kw[] = {
{ "enable", NULL,
N_("Enable TCP wrapper access control. Default is \"yes\"."),
diff --git a/src/triplet.c b/src/triplet.c
index 2df9151..abb767a 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -382,13 +382,13 @@ triplet_processor(void *data, void *proc_data)
/* Process all triplets from the table according to the SPOOL */
void
spool_commit_triplets(struct spool *spool, struct file_triplet *tplist)
{
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) {
while (tplist) {
struct file_triplet *next = tplist->jq_next;
if (tplist->spool == spool)
diff --git a/src/vtab.c b/src/vtab.c
index e02ebe7..6a23541 100644
--- a/src/vtab.c
+++ b/src/vtab.c
@@ -13,12 +13,77 @@
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
#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;
};
static struct virt_tab_reg reg[] = {
@@ -32,18 +97,18 @@ static struct virt_tab_reg reg[] = {
{ NULL, null_move_file, null_archive_file, null_symlink_file,
null_rmsymlink_file } },
{ NULL }
};
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) {
*vtab = reg[i].vtab;
return 0;
}
diff --git a/src/wydawca.c b/src/wydawca.c
index f6767b8..1506b56 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -65,13 +65,13 @@ initstats()
void
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) {
fmtsize = size;
fmtbuf = grecs_realloc(fmtbuf, fmtsize);
}
@@ -87,13 +87,13 @@ syslog_printer(int prio, const char *fmt, va_list ap)
#endif
}
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)
fprintf(stderr, "[%s] ", p);
vfprintf(stderr, fmt, ap);
diff --git a/src/wydawca.h b/src/wydawca.h
index 8e2f155..b79b7e9 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -42,13 +42,12 @@
#include <time.h>
#include <sysexits.h>
#include <fnmatch.h>
#include <regex.h>
#include <mailutils/types.h>
-#include <mailutils/url.h>
#include <mailutils/errno.h>
#include "grecs.h"
#include "wordsplit.h"
#define SP(s) ((s) ? (s) : "NONE")
@@ -202,14 +201,22 @@ struct file_triplet {
/* Macros to access owner UID and GID. */
/* The directive file is always present in the triplet */
#define TRIPLET_UID(t) ((t)->file[file_directive].sb.st_uid)
/* 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,
const char *wanted_src, const char *wanted_dst);
int (*rmsymlink_file) (struct file_triplet * trp,
const char *file_name);
@@ -219,13 +226,13 @@ struct virt_tab {
files from source to destination */
struct spool {
char *tag;
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;
time_t file_sweep_time; /* Remove invalid/unprocessed files
after this amount of time */
@@ -506,27 +513,32 @@ void config_init(void);
void config_finish(struct grecs_node *);
void config_help(void);
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);
int symlink_file(struct file_triplet *trp,
const char *wanted_src, const char *wanted_dst);
int rmsymlink_file(struct file_triplet *trp, const char *file_name);
/* diskio.c */
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,
const char *wanted_src, const char *wanted_dst);
int dir_rmsymlink_file(struct file_triplet *trp, const char *file_name);

Return to:

Send suggestions and report system problems to the System administrator.