--- /dev/null
+#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
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
#include <sys/time.h>
-#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;
struct soap *other_soap;
char *peer;
void **plugins;
+ void **type_plugins;
void *dbhandle;
char **trusted_peers;
} *glite_jp_context_t;
glite_jp_attr_orig_t origin;
} glite_jp_query_rec_t;
-void glite_jp_attrval_free(glite_jp_attrval_t *,int);
-
#endif
#include <assert.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include "types.h"
+#include "attr.h"
+#include "type_plugin.h"
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)
+{
+}
+
+
+