aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-10-08 23:00:42 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-10-08 23:00:42 +0300
commite2bb02092abe1321c534ad8a6c168b2803245cc5 (patch)
tree080290a3d844cabb433156b17aca805e2260950a /lib
parent9b56a5b05db6630a667ad0c9b16ec45a4e52044d (diff)
downloadeclat-e2bb02092abe1321c534ad8a6c168b2803245cc5.tar.gz
eclat-e2bb02092abe1321c534ad8a6c168b2803245cc5.tar.bz2
Improve configuration syntax help.
* grecs: Upgrade. * lib/filemap.c: Revamp configuration routine. Provide configuration syntax help. * lib/gdbmmap.c: Likewamp. * lib/ldapmap.c: Provide configuration syntax help. * lib/libeclat.h (eclat_map_drv) <map_confhelp>: New member. (eclat_map_confhelp): New proto. * lib/map.c (eclat_map_confhelp): New function. * src/config.c (config_help): Call eclat_map_confhelp.
Diffstat (limited to 'lib')
-rw-r--r--lib/filemap.c58
-rw-r--r--lib/gdbmmap.c75
-rw-r--r--lib/ldapmap.c29
-rw-r--r--lib/libeclat.h2
-rw-r--r--lib/map.c15
5 files changed, 129 insertions, 50 deletions
diff --git a/lib/filemap.c b/lib/filemap.c
index bced0d4..aa2fa6d 100644
--- a/lib/filemap.c
+++ b/lib/filemap.c
@@ -23,30 +23,63 @@ struct filemap {
struct grecs_locus locus;
};
+static struct grecs_keyword filemap_kw[] = {
+ { "type", "'file", "Set map type",
+ grecs_type_null },
+ { "file", NULL, "File name",
+ grecs_type_string, GRECS_DFLT, NULL,
+ offsetof(struct filemap, name) },
+ { NULL }
+};
+
+static void
+filemap_confhelp()
+{
+ static struct grecs_keyword filemap_top[] = {
+ { "map", "name: string",
+ "Configuration for a file map",
+ grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
+ filemap_kw },
+ { NULL }
+ };
+ grecs_print_statement_array(filemap_top, 1, 0, stdout);
+}
+
+static void
+filemap_free(int dbg, void *data)
+{
+ struct filemap *filemap = data;
+ free(filemap->name);
+ free(filemap);
+}
+
static int
filemap_config(int dbg, struct grecs_node *node, void *data)
{
struct filemap *filemap, **return_filemap = data;
+ int i;
const char *filename;
struct grecs_node *p;
- if (eclat_get_string_node(node, "file", 0, &p))
- return eclat_map_failure;
filemap = grecs_malloc(sizeof(*filemap));
- filemap->name = grecs_strdup(p->v.value->v.string);
+ for (i = 0; filemap_kw[i].ident; i++)
+ filemap_kw[i].varptr = filemap;
+ if (grecs_tree_process(node->down, filemap_kw)) {
+ filemap_free(dbg, filemap);
+ return eclat_map_failure;
+ }
+ if (!filemap->name) {
+ grecs_error(&node->locus, 0, "file not specified");
+ filemap_free(dbg, filemap);
+ return eclat_map_failure;
+ }
+ if (eclat_get_string_node(node, "file", 0, &p))
+ abort(); /* shouldn't happen */
filemap->locus = p->locus;
*return_filemap = filemap;
return eclat_map_ok;
}
-static void
-filemap_free(int dbg, void *data)
-{
- struct filemap *filemap = data;
- free(filemap->name);
- free(filemap);
-}
-
static int
filemap_open(int dbg, void *data)
{
@@ -135,6 +168,7 @@ struct eclat_map_drv eclat_map_drv_file = {
filemap_open,
filemap_close,
filemap_get,
- filemap_free
+ filemap_free,
+ filemap_confhelp
};
diff --git a/lib/gdbmmap.c b/lib/gdbmmap.c
index 4fdaa33..7ecb88c 100644
--- a/lib/gdbmmap.c
+++ b/lib/gdbmmap.c
@@ -27,42 +27,66 @@ struct gdbm_map {
int nullflag;
};
+static struct grecs_keyword gdbm_map_kw[] = {
+ { "type", "'gdbm", "Set map type",
+ grecs_type_null },
+ { "file", NULL, "Database file name",
+ grecs_type_string, GRECS_DFLT, NULL,
+ offsetof(struct gdbm_map, name) },
+ { "null", NULL, "Count terminating null as part of the key",
+ grecs_type_bool, GRECS_DFLT, NULL,
+ offsetof(struct gdbm_map, nullflag) },
+ { NULL }
+};
+
+static void
+gdbm_map_free(int dbg, void *data)
+{
+ struct gdbm_map *gdbm_map = data;
+ free(gdbm_map->name);
+ free(gdbm_map);
+}
+
+static void
+gdbm_map_confhelp()
+{
+ static struct grecs_keyword gdbm_map_top[] = {
+ { "map", "name: string",
+ "Configuration for a GDBM map",
+ grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
+ gdbm_map_kw },
+ { NULL }
+ };
+ grecs_print_statement_array(gdbm_map_top, 1, 0, stdout);
+}
+
static int
gdbm_map_config(int dbg, struct grecs_node *node, void *data)
{
struct gdbm_map *gdbm_map, **return_gdbm_map = data;
- const char *filename;
struct grecs_node *p;
-
- if (eclat_get_string_node(node, "file", 0, &p))
- return eclat_map_failure;
+ int i;
+
gdbm_map = grecs_malloc(sizeof(*gdbm_map));
- gdbm_map->name = grecs_strdup(p->v.value->v.string);
- gdbm_map->locus = p->locus;
- switch (eclat_get_string_node(node, "null", 1, &p)) {
- case eclat_map_failure:
+ for (i = 0; gdbm_map_kw[i].ident; i++)
+ gdbm_map_kw[i].varptr = gdbm_map;
+ if (grecs_tree_process(node->down, gdbm_map_kw)) {
+ gdbm_map_free(dbg, gdbm_map);
+ return eclat_map_failure;
+ }
+ if (!gdbm_map->name) {
+ grecs_error(&node->locus, 0, "file not specified");
+ gdbm_map_free(dbg, gdbm_map);
return eclat_map_failure;
- case eclat_map_not_found:
- break;
- case eclat_map_ok:
- if (grecs_string_convert(&gdbm_map->nullflag, grecs_type_bool,
- p->v.value->v.string,
- &p->locus))
- return eclat_map_failure;
}
-
+
+ if (eclat_get_string_node(node, "file", 0, &p))
+ abort();
+ gdbm_map->locus = p->locus;
*return_gdbm_map = gdbm_map;
return eclat_map_ok;
}
-static void
-gdbm_map_free(int dbg, void *data)
-{
- struct gdbm_map *gdbm_map = data;
- free(gdbm_map->name);
- free(gdbm_map);
-}
-
static int
gdbm_map_open(int dbg, void *data)
{
@@ -112,5 +136,6 @@ struct eclat_map_drv eclat_map_drv_gdbm = {
gdbm_map_open,
gdbm_map_close,
gdbm_map_get,
- gdbm_map_free
+ gdbm_map_free,
+ gdbm_map_confhelp
};
diff --git a/lib/ldapmap.c b/lib/ldapmap.c
index 8d687e4..5ef20cb 100644
--- a/lib/ldapmap.c
+++ b/lib/ldapmap.c
@@ -42,16 +42,6 @@ struct ldap_map {
static void ldap_map_free(int dbg, void *data);
static int
-cb_null(enum grecs_callback_command cmd,
- grecs_locus_t *locus,
- void *varptr,
- grecs_value_t *value,
- void *cb_data)
-{
- return 0;
-}
-
-static int
cb_tls(enum grecs_callback_command cmd,
grecs_locus_t *locus,
void *varptr,
@@ -82,8 +72,7 @@ cb_tls(enum grecs_callback_command cmd,
static char *typestr;
static struct grecs_keyword ldapmap_kw[] = {
- { "type", "arg", "Set map type",
- grecs_type_string, GRECS_DFLT, NULL, 0, cb_null },
+ { "type", "'ldap", "Set map type", grecs_type_null },
{ "uri", "arg",
"Set LDAP URI",
grecs_type_string, GRECS_DFLT,
@@ -168,6 +157,19 @@ ldap_map_config(int dbg, struct grecs_node *node, void *data)
return eclat_map_ok;
}
+static void
+ldap_map_confhelp()
+{
+ static struct grecs_keyword ldapmap_top[] = {
+ { "map", "name: string",
+ "Configuration for an LDAP map",
+ grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
+ ldapmap_kw },
+ { NULL }
+ };
+ grecs_print_statement_array(ldapmap_top, 1, 0, stdout);
+
+}
static void
ldap_map_free(int dbg, void *data)
@@ -630,6 +632,7 @@ struct eclat_map_drv eclat_map_drv_ldap = {
ldap_map_open,
ldap_map_close,
ldap_map_get,
- ldap_map_free
+ ldap_map_free,
+ ldap_map_confhelp
};
diff --git a/lib/libeclat.h b/lib/libeclat.h
index 2b40f43..ecbb844 100644
--- a/lib/libeclat.h
+++ b/lib/libeclat.h
@@ -115,6 +115,7 @@ struct eclat_map_drv {
int (*map_close)(int, void *);
int (*map_get)(int, void *, const char *, char **);
void (*map_free)(int, void *);
+ void (*map_confhelp)(void);
};
struct eclat_map {
@@ -142,6 +143,7 @@ const char *eclat_map_strerror(int rc);
int eclat_map_drv_register(struct eclat_map_drv *drv);
void eclat_map_foreach(int (*fun)(struct eclat_map *, void *), void *data);
void eclat_map_free_all(void);
+void eclat_map_confhelp(void);
int eclat_get_string_node(struct grecs_node *node, const char *name,
int optional,
diff --git a/lib/map.c b/lib/map.c
index c8acfee..f723cd9 100644
--- a/lib/map.c
+++ b/lib/map.c
@@ -325,4 +325,19 @@ eclat_map_free_all()
openmap_symtab = NULL;
}
}
+
+static int
+drv_help(void *data, void *unused)
+{
+ struct eclat_map_drv *drv = data;
+ if (drv->map_confhelp)
+ drv->map_confhelp();
+ return 0;
+}
+
+void
+eclat_map_confhelp()
+{
+ grecs_symtab_enumerate(mapdrv_symtab, drv_help, NULL);
+}

Return to:

Send suggestions and report system problems to the System administrator.