diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-21 10:43:50 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-21 10:43:50 +0300 |
commit | 7d63e9e21b74f3b0ca3a87714e19ef1bbfeb7fbf (patch) | |
tree | 15b0b4a18fb91cc4b5146b9fe96070886facdcfb /include | |
parent | b21233c538ebb235a780e068641263801730339d (diff) | |
download | smap-7d63e9e21b74f3b0ca3a87714e19ef1bbfeb7fbf.tar.gz smap-7d63e9e21b74f3b0ca3a87714e19ef1bbfeb7fbf.tar.bz2 |
Implement argument transformations.
Argument transformations allow to change map and/or
key in the input query before actually processing it.
They are implemented at the module level, via additional
method in smap_module structure.
* include/smap/module.h (SMAP_MODULE_VERSION): Define to 2.
(SMAP_CAPA_DEFAULT): Change constant.
(SMAP_CAPA_XFORM): New define.
(smap_module)<smap_xform>: New member.
* src/module.c (_load_module): Fix consistency checking.
* src/query.c: New condition "key [op] value".
New target "transform dbname".
(query_cond_type): New constant query_cond_key.
(map_comparison): Rename to comparison. All uses changed.
(map_cond): Rename to comp_cond. All uses changed.
(dispatch_rule)<xform>: New member.
(query_tok)<T_TRANSFORM, T_KEY>: New tokens.
(query_kwtab): New keywords: key, transform.
(parse_dispatch_map): Rename to parse_dispatch_comp; change
signature. All uses changed.
(parse_subcond): Handle T_KEY token.
(parse_complex_dispatch): Handle T_KEY and T_TRANSFORM.
(rule_fixup): New function.
(link_dispatch_rules): Use rule_fixup.
(find_dispatch_rule): Second argument defines where to
start searching.
(dispatch_query): Handle transformations. Add checking of return
values.
* modules/guile/guile.c (guile_proc_ind)<xform_proc>: New index.
(guile_proc_name): New proc "xform".
(guile_init_db): Bail out if neither query nor xform is defined.
(guile_xform): New function.
(module): Add guile_xform.
* modules/guile/getpw.scm (smap-xform): Implement an example
transformation.
* modules/echo/echo.c (module): Update.
* modules/mailutils/mailutils.c: Likewise.
Diffstat (limited to 'include')
-rw-r--r-- | include/smap/module.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/include/smap/module.h b/include/smap/module.h index 120bf6e..27befad 100644 --- a/include/smap/module.h +++ b/include/smap/module.h @@ -20,9 +20,11 @@ #define __smap_s_cat3__(a,b,c) a ## b ## c #define SMAP_EXPORT(module,name) __smap_s_cat3__(module,_LTX_,name) -#define SMAP_MODULE_VERSION 1 +#define SMAP_MODULE_VERSION 2 #define SMAP_CAPA_NONE 0 -#define SMAP_CAPA_DEFAULT SMAP_CAPA_NONE +#define SMAP_CAPA_QUERY 0x0001 +#define SMAP_CAPA_XFORM 0x0002 +#define SMAP_CAPA_DEFAULT SMAP_CAPA_QUERY typedef struct smap_database *smap_database_t; @@ -37,9 +39,10 @@ struct smap_conninfo { struct smap_module { unsigned smap_version; - unsigned smap_capabilities; /* Unused so far */ + unsigned smap_capabilities; int (*smap_init)(int argc, char **argv); - smap_database_t (*smap_init_db)(const char *dbid, int argc, char **argv); + smap_database_t (*smap_init_db)(const char *dbid, + int argc, char **argv); int (*smap_free_db)(smap_database_t dbp); int (*smap_open) (smap_database_t hp); int (*smap_close) (smap_database_t hp); @@ -47,6 +50,10 @@ struct smap_module { smap_stream_t ostr, const char *map, const char *key, struct smap_conninfo const *conninfo); + int (*smap_xform)(smap_database_t dbp, + const char *map, const char *key, + struct smap_conninfo const *conninfo, + char **newmap, char **newkey); }; #endif |