From 2ac6502ed2be20e6655ae49cca2e88fb3675e3fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Mon, 15 Aug 2005 19:47:02 +0000 Subject: [PATCH] prototypes and partial implementation of attribute type handling functions --- org.glite.jp.common/interface/attr.h | 24 ++++++++ org.glite.jp.common/interface/type_plugin.h | 38 +++++++++--- org.glite.jp.common/interface/types.h | 6 +- org.glite.jp.common/src/attr.c | 94 +++++++++++++++++++++++++++++ 4 files changed, 148 insertions(+), 14 deletions(-) create mode 100644 org.glite.jp.common/interface/attr.h diff --git a/org.glite.jp.common/interface/attr.h b/org.glite.jp.common/interface/attr.h new file mode 100644 index 0000000..2e0ec31 --- /dev/null +++ b/org.glite.jp.common/interface/attr.h @@ -0,0 +1,24 @@ +#ifndef __GLITE_JP_ATTR +#define __GLITE_JP_ATTR + +#define GLITE_JP_SYSTEM_NS "http://egee.cesnet.cz/en/WSDL/jp-system" +#define GLITE_JP_ATTR_OWNER GLITE_JP_SYSTEM_NS ":owner" + +void glite_jp_attrval_free(glite_jp_attrval_t *,int); + +/* Search through registered type plugins and call appropriate plugin method. + * See type_plugin.h for detailed description. + */ + +int glite_jp_attrval_cmp(glite_jp_context_t ctx,const glite_jp_attrval_t *a,const glite_jp_attrval_t *b,int *result); + +char *glite_jp_attrval_to_db_full(glite_jp_context_t ctx,const glite_jp_attrval_t *attr); +char *glite_jp_attrval_to_db_index(glite_jp_context_t ctx,const glite_jp_attrval_t *attr,int len); + +int *glite_jp_attrval_from_db(glite_jp_context_t ctx,const char *str,glite_jp_attrval_t *attr); +const char *glite_jp_attrval_db_type_full(glite_jp_context_t ctx,const char *attr); +const char *glite_jp_attrval_db_type_index(glite_jp_context_t ctx,const char *attr,int len); + + + +#endif diff --git a/org.glite.jp.common/interface/type_plugin.h b/org.glite.jp.common/interface/type_plugin.h index bb34744..c901a32 100644 --- a/org.glite.jp.common/interface/type_plugin.h +++ b/org.glite.jp.common/interface/type_plugin.h @@ -20,30 +20,50 @@ typedef struct _glite_jp_tplug_data_t { const glite_jp_attrval_t *b, int *result); -/** Convert to and from XML representation */ - char (*to_xml)(void *,const glite_jp_attrval_t *a); - glite_jp_attrval_t (*from_xml)(void *,const char *,const char *); +/** Convert to database string representation. + * It is guaranteed the returned value can be converted back with + * from_db(). + * The resulting value may not be suitable for indexing with db engine. + * + * \param[in] attr the attribute value to convert + * \retval NULL can't be converted + * \retval other the string representation. + * */ + char * (*to_db_full)(void *ctx,const glite_jp_attrval_t *attr); -/** Convert to and from database string representation */ - char (*to_db)(void *,const glite_jp_attrval_t *a); - glite_jp_attrval_t (*from_db)(void *,const char *); +/** Convert to a database string representation suitable for indexing. + * The function is non-decreasing (wrt. cmp() above and strcmp()), however it + * is not guaranteed to be one-to-one. + * + * \param[in] attr the value to convert + * \param[in] len maximum length of the converted value. + * \retval NULL can't be converted + * \retval other the string representation + */ + char * (*to_db_index)(void *ctx,const glite_jp_attrval_t *attr,int len); + +/** Convert from + int (*from_db)(void *ctx,const char *str,glite_jp_attrval_t *attr); -/** Query for database type. +/** Query for database types suitable to store values returned by + * to_db_full() and to_db_index(). * Useful for db column dynamic creation etc. */ - const char (*db_type)(void *,const glite_jp_attr_t *); + const char * (*db_type_full)(void *ctx,const char *attr); + const char * (*db_type_index)(void *ctx,const char *attr,int len); } glite_jp_tplug_data_t; /** Plugin init function. Must be called init, supposed to be called as many times as required for different param's (e.g. xsd files). + Registers the plugin in ctx. */ typedef int (*glite_jp_tplug_init_t)( glite_jp_context_t ctx, const char *param, - glite_jp_tplug_data *plugin_data + glite_jp_tplug_data_t *plugin_data ); #endif diff --git a/org.glite.jp.common/interface/types.h b/org.glite.jp.common/interface/types.h index eba38e0..40ab4ab 100644 --- a/org.glite.jp.common/interface/types.h +++ b/org.glite.jp.common/interface/types.h @@ -3,9 +3,6 @@ #include -#define GLITE_JP_SYSTEM_NS "http://egee.cesnet.cz/en/WSDL/jp-system" -#define GLITE_JP_ATTR_OWNER GLITE_JP_SYSTEM_NS ":owner" - typedef struct _glite_jp_error_t { int code; const char *desc; @@ -21,6 +18,7 @@ typedef struct _glite_jp_context { struct soap *other_soap; char *peer; void **plugins; + void **type_plugins; void *dbhandle; char **trusted_peers; } *glite_jp_context_t; @@ -63,6 +61,4 @@ typedef struct { glite_jp_attr_orig_t origin; } glite_jp_query_rec_t; -void glite_jp_attrval_free(glite_jp_attrval_t *,int); - #endif diff --git a/org.glite.jp.common/src/attr.c b/org.glite.jp.common/src/attr.c index 250ef5a..e94b965 100644 --- a/org.glite.jp.common/src/attr.c +++ b/org.glite.jp.common/src/attr.c @@ -1,8 +1,12 @@ #include #include +#include #include +#include #include "types.h" +#include "attr.h" +#include "type_plugin.h" void glite_jp_attrval_free(glite_jp_attrval_t *a,int f) { @@ -11,3 +15,93 @@ void glite_jp_attrval_free(glite_jp_attrval_t *a,int f) free(a->origin_detail); if (f) free(a); } + +static glite_jp_tplug_data_t *get_plugin(glite_jp_context_t ctx,const glite_jp_attrval_t *a) +{ + void **cp = ctx->type_plugins; + char *colon,*ns; + + assert(cp); + glite_jp_clear_error(ctx); + ns = strdup(a->name); + colon = strrchr(ns,':'); + if (colon) *colon = 0; else *ns = 0; + + while (*cp) { + glite_jp_tplug_data_t *p = *cp; + if (!strcmp(ns,p->namespace)) { + free(ns); + return p; + } + } + free(ns); + return NULL; +} + +#define check_ap(ap,attr,eret) \ + if (!(ap)) { \ + err.code = ENOENT; \ + snprintf(ebuf,sizeof ebuf - 1, \ + "Can't find type plugin for %s",(attr)->name); \ + ebuf[sizeof ebuf - 1] = 0; \ + err.desc = ebuf; \ + glite_jp_stack_error(ctx,&err); \ + return eret; \ + } + + +int glite_jp_attrval_cmp(glite_jp_context_t ctx,const glite_jp_attrval_t *a,const glite_jp_attrval_t *b,int *result) +{ + glite_jp_tplug_data_t *ap = get_plugin(ctx,a); + glite_jp_error_t err; + char ebuf[BUFSIZ]; + + memset(&err,0,sizeof err); + err.source = __FUNCTION__; + glite_jp_clear_error(ctx); + + if (strcmp(a->name,b->name)) { + err.code = EINVAL; + err.desc = "Can't compare different attributes"; + return glite_jp_stack_error(ctx,&err); + } + + check_ap(ap,a,err.code); + + return ap->cmp(ap->pctx,a,b,result); +} + +char *glite_jp_attrval_to_db_full(glite_jp_context_t ctx,const glite_jp_attrval_t *attr) +{ + glite_jp_tplug_data_t *ap = get_plugin(ctx,attr); + glite_jp_error_t err; + char ebuf[BUFSIZ]; + int result; + + memset(&err,0,sizeof err); + err.source = __FUNCTION__; + glite_jp_clear_error(ctx); + + check_ap(ap,attr,NULL); + return ap->to_db_full(ap->pctx,attr); +} + +char *glite_jp_attrval_to_db_index(glite_jp_context_t ctx,const glite_jp_attrval_t *attr,int len) +{ +} + + +int *glite_jp_attrval_from_db(glite_jp_context_t ctx,const char *str,glite_jp_attrval_t *attr) +{ +} + +const char *glite_jp_attrval_db_type_full(glite_jp_context_t ctx,const char *attr) +{ +} + +const char *glite_jp_attrval_db_type_index(glite_jp_context_t ctx,const char *attr,int len) +{ +} + + + -- 1.8.2.3