aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-02-28 18:54:48 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-02-28 18:54:48 +0200
commit5fc738e4d43eb708428c4b30e60e570e2dd55470 (patch)
treea96f33c70162ff8a825b800fc9276360d95d154a /src
parent514797c56e431f37de9a00834281f990a7b15c46 (diff)
downloadwydawca-5fc738e4d43eb708428c4b30e60e570e2dd55470.tar.gz
wydawca-5fc738e4d43eb708428c4b30e60e570e2dd55470.tar.bz2
Various fixes
* doc/Makefile.am: Improve checking and final rules. * doc/fdl.texi, doc/rendition.texi: Use single-space sentence separators. * doc/wydawca.texi: Update. * src/config.c (cb_email_address): Accept a list of addresses. * src/meta.c (meta_expand_string): Take two additional arguments. Quote expansions if they are provided. * src/triplet.c (triplet_expand_method_query): New function. * src/mail.c, src/verify.c: Use triplet_expand_method_query * src/wydawca.h: Update. * src/meta.c (meta_escape): Remove.
Diffstat (limited to 'src')
-rw-r--r--src/config.c54
-rw-r--r--src/mail.c8
-rw-r--r--src/meta.c48
-rw-r--r--src/triplet.c34
-rw-r--r--src/verify.c29
-rw-r--r--src/wydawca.h10
6 files changed, 107 insertions, 76 deletions
diff --git a/src/config.c b/src/config.c
index 57bd8cb..6c8d728 100644
--- a/src/config.c
+++ b/src/config.c
@@ -278,15 +278,53 @@ cb_email_address (enum gconf_callback_command cmd,
void *cb_data)
{
int rc;
- mu_address_t addr;
+ mu_address_t addr = NULL;
- if (assert_string_arg (locus, cmd, value))
- return 1;
- rc = mu_address_create (&addr, value->v.string);
- if (rc)
- gconf_error (locus, 0, _("invalid email address: %s"), mu_strerror (rc));
- else
- *(mu_address_t*) varptr = addr;
+ switch (value->type)
+ {
+ case GCONF_TYPE_STRING:
+ rc = mu_address_create (&addr, value->v.string);
+ if (rc)
+ {
+ gconf_error (locus, 0, _("%s: invalid email address: %s"),
+ value->v.string, mu_strerror (rc));
+ return rc;
+ }
+ break;
+
+ case GCONF_TYPE_LIST:
+ {
+ const void *p;
+ gl_list_iterator_t itr = gl_list_iterator (value->v.list);
+
+ while (gl_list_iterator_next (&itr, &p, NULL))
+ {
+ const gconf_value_t *vp = p;
+ 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
+ {
+ gconf_error (locus, 0, _("%s: invalid email address: %s"),
+ vp->v.string, mu_strerror (rc));
+ }
+ mu_address_destroy (&a);
+ if (rc)
+ break;
+ }
+ }
+ break;
+
+ case GCONF_TYPE_ARRAY:
+ gconf_error (locus, 0, _("too many arguments"));
+ return 1;
+ }
+
+ *(mu_address_t*) varptr = addr;
return rc;
}
diff --git a/src/mail.c b/src/mail.c
index ba77f49..5065306 100644
--- a/src/mail.c
+++ b/src/mail.c
@@ -249,7 +249,7 @@ mail_stats ()
admin_stat_message);
return;
}
- text = meta_expand_string (tmpl, exp, NULL);
+ text = meta_expand_string (tmpl, exp, NULL, NULL, NULL);
mail_send_message (admin_address, text);
@@ -264,7 +264,6 @@ get_recipient (struct access_method *method, struct file_triplet *trp,
char **errp)
{
unsigned nrows, ncols, i;
- struct metadef def[5];
mu_address_t rcpt = NULL;
char *text;
int rc;
@@ -283,10 +282,7 @@ get_recipient (struct access_method *method, struct file_triplet *trp,
return NULL;
}
- make_default_meta (def, trp->user, trp->project);
- meta_escape (method, md, def);
- text = meta_expand_string (method->query, def, NULL);
- meta_free (def);
+ text = triplet_expand_method_query (method, md, trp);
rc = method_run (method, md, text);
free (text);
diff --git a/src/meta.c b/src/meta.c
index e60651a..eb332f5 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -50,11 +50,12 @@ find_expansion_word (const char *kw, size_t len,
}
char *
-meta_expand_string (const char *string, struct metadef *def, void *data)
+meta_expand_string (const char *string, struct metadef *def, void *data,
+ struct access_method *method, void *handle)
{
const char *p, *s;
char *res;
- struct obstack stk;
+ struct obstack stk;
if (!string)
return NULL;
@@ -81,7 +82,17 @@ meta_expand_string (const char *string, struct metadef *def, void *data)
e = strchr (p + 1, '}');
if (e && (s = find_expansion_word (p + 1, e - p - 1, def, data)))
{
- obstack_grow (&stk, s, strlen (s));
+ if (method)
+ {
+ char *newval;
+ size_t len;
+ /* FIXME: Return value? */
+ method_quote_string (method, handle, s, &newval, &len);
+ obstack_grow (&stk, newval, len);
+ free (newval);
+ }
+ else
+ obstack_grow (&stk, s, strlen (s));
p = e + 1;
}
else
@@ -99,7 +110,18 @@ meta_expand_string (const char *string, struct metadef *def, void *data)
s = p - 1;
len = 1;
}
- obstack_grow (&stk, s, len);
+
+ if (method)
+ {
+ char *newval;
+ size_t len;
+ /* FIXME: Return value? */
+ method_quote_string (method, handle, s, &newval, &len);
+ obstack_grow (&stk, newval, len);
+ free (newval);
+ }
+ else
+ obstack_grow (&stk, s, len);
p++;
}
}
@@ -113,24 +135,6 @@ meta_expand_string (const char *string, struct metadef *def, void *data)
}
void
-meta_escape (struct access_method *method, void *handle, struct metadef *def)
-{
- for (; def->kw; def++)
- {
- if (def->value)
- {
- char *newval;
-
- /* FIXME: Return value? */
- method_quote_string (method, handle, def->value, &newval, NULL);
- if (def->storage)
- free (def->storage);
- def->value = def->storage = newval;
- }
- }
-}
-
-void
meta_free (struct metadef *def)
{
for (; def->kw; def++)
diff --git a/src/triplet.c b/src/triplet.c
index e060089..24ab611 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -481,7 +481,6 @@ fill_user_data (struct file_triplet *trp)
struct access_method *method = trp->spool->access_method[user_data_method];
char *text;
unsigned nrows, ncols;
- struct metadef def[5];
struct passwd *pw;
void *md;
@@ -498,10 +497,7 @@ fill_user_data (struct file_triplet *trp)
pw = getpwuid (TRIPLET_UID (trp));
if (!pw)
return;
- make_default_meta (def, pw->pw_name, trp->project);
- meta_escape (method, md, def);
- text = meta_expand_string (method->query, def, NULL);
- meta_free (def);
+ text = triplet_expand_method_query (method, md, trp);
rc = method_run (method, md, text);
free (text);
@@ -576,6 +572,30 @@ DECL_EXPAND_TIMER(system)
DECL_TIMER(name, user), \
DECL_TIMER(name, system)
+struct metadef triplet_default_meta[] = {
+ { "u", NULL, expand_user_name, NULL },
+ { "user", NULL, expand_user_name, NULL },
+ { "user:name", NULL, expand_user_name, NULL },
+ { "p", NULL, expand_project_base, NULL },
+ { "project", NULL, expand_project_base, NULL },
+ { "url", NULL, expand_url, NULL },
+ { "spool", NULL, expand_tag, NULL },
+ { "dir", NULL, expand_relative_dir, NULL },
+ { "dest-dir", NULL, expand_dest_dir, NULL },
+ { "source-dir", NULL, expand_source_dir, NULL },
+ { NULL }
+};
+
+char *
+triplet_expand_method_query (struct access_method *method, void *handle,
+ struct file_triplet *trp)
+{
+ char *p = meta_expand_string (method->query, triplet_default_meta, trp,
+ method, handle);
+ meta_free (triplet_default_meta);
+ return p;
+}
+
struct metadef triplet_meta[] = {
{ "project", NULL, expand_project_base, NULL },
{ "url", NULL, expand_url, NULL },
@@ -595,14 +615,14 @@ struct metadef triplet_meta[] = {
{ "report", NULL, expand_report, NULL },
DECL_FULL_TIMER(wydawca),
DECL_FULL_TIMER(triplet),
- DECL_FULL_TIMER(directory),
+ DECL_FULL_TIMER(spool),
{ NULL }
};
char *
triplet_expand_param (const char *tmpl, struct file_triplet *trp)
{
- char *p = meta_expand_string (tmpl, triplet_meta, trp);
+ char *p = meta_expand_string (tmpl, triplet_meta, trp, NULL, NULL);
meta_free (triplet_meta);
return p;
}
diff --git a/src/verify.c b/src/verify.c
index d419df5..15a2d8b 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -73,22 +73,6 @@ fill_project_name (struct file_triplet *trp)
return 0;
}
-void
-make_default_meta (struct metadef def[5], const char *user,
- const char *project)
-{
- memset (def, 0, 5 * sizeof(def[0]));
- def[0].kw = "u";
- def[0].value = (char*) user;
- def[1].kw = "user";
- def[1].value = (char*) user;
- def[2].kw = "p";
- def[2].value = (char*) project;
- def[3].kw = "project";
- def[3].value = (char*) project;
- def[4].kw = NULL;
-}
-
/* Verify if USER has upload rights on the directory (project) requested
by TRP */
int
@@ -99,7 +83,6 @@ check_access_rights (struct file_triplet *trp, const struct spool *spool,
int rc;
char *command;
const char *result;
- struct metadef def[5];
void *md;
struct group *grp;
@@ -119,11 +102,7 @@ check_access_rights (struct file_triplet *trp, const struct spool *spool,
if (!md)
return 1;
- make_default_meta (def, user, trp->project);
-
- meta_escape (method, md, def);
- command = meta_expand_string (method->query, def, NULL);
- meta_free (def);
+ command = triplet_expand_method_query (method, md, trp);
rc = method_run (method, md, command);
free (command);
@@ -156,7 +135,6 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool)
struct access_method *method = spool->access_method[gpg_key_method];
const char *pubkey;
int rc;
- struct metadef def[5];
void *md;
if (!trp->file[file_directive].name)
@@ -176,10 +154,7 @@ verify_directive_file (struct file_triplet *trp, const struct spool *spool)
trp->gid = pw->pw_gid;
trp->user = xstrdup (pw->pw_name);
- make_default_meta (def, trp->user, NULL);
- meta_escape (method, md, def);
- command = meta_expand_string (method->query, def, NULL);
- meta_free (def);
+ command = triplet_expand_method_query (method, md, trp);
rc = method_run (method, md, command);
free (command);
diff --git a/src/wydawca.h b/src/wydawca.h
index 81e6509..0b54cce 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -293,13 +293,9 @@ struct metadef
void *data;
};
-char *meta_expand_string (const char *string, struct metadef *def,
- void *data);
-void meta_escape (struct access_method *method, void *handle,
- struct metadef *def);
+char *meta_expand_string (const char *string, struct metadef *def, void *data,
+ struct access_method *method, void *handle);
void meta_free (struct metadef *def);
-void make_default_meta (struct metadef kwexp[5], const char *user,
- const char *project);
/* Global variables */
@@ -385,6 +381,8 @@ void register_file (struct file_info *finfo);
void enumerate_triplets (const struct spool *);
size_t count_collected_triplets (void);
char *triplet_expand_param (const char *tmpl, struct file_triplet *trp);
+char *triplet_expand_method_query (struct access_method *method, void *handle,
+ struct file_triplet *trp);
/* General-purpose method support */
struct access_method *method_new (enum access_method_id id,

Return to:

Send suggestions and report system problems to the System administrator.