file plugin load & lookup
authorAleš Křenek <ljocha@ics.muni.cz>
Fri, 8 Apr 2005 12:52:01 +0000 (12:52 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Fri, 8 Apr 2005 12:52:01 +0000 (12:52 +0000)
org.glite.jp.primary/interface/file_plugin.h
org.glite.jp.primary/src/file_plugin.c
org.glite.jp.primary/src/soap_ops.c

index 49ed1da..ab566f4 100644 (file)
@@ -66,6 +66,6 @@ typedef int (*glite_jpps_fplug_init_t)(
 \param[out] data       Context of the plugin
 */
 
-int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t *plugin_data);
+int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t **plugin_data);
 
 #endif
index ec3db35..d703eec 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <stdlib.h>
 #include <getopt.h>
 #include <dlfcn.h>
 #include <errno.h>
@@ -11,11 +12,15 @@ static struct option opts[] = {
        { NULL }
 };
 
-static void *loadit(glite_jp_context_t ctx,const char *so)
+static int loadit(glite_jp_context_t ctx,const char *so)
 {
+/* XXX: not stored but we never dlclose() yet */
        void    *dl_handle = dlopen(so,RTLD_NOW);
+
        glite_jp_error_t        err;
        char    *e;
+       glite_jpps_fplug_data_t *data,*dp;
+       int     i;
 
        glite_jpps_fplug_init_t init;
 
@@ -23,8 +28,7 @@ static void *loadit(glite_jp_context_t ctx,const char *so)
                err.source = "dlopen()";
                err.code = EINVAL;
                err.desc = dlerror();
-               glite_jp_stack_error(ctx,&err);
-               return NULL;
+               return glite_jp_stack_error(ctx,&err);
        }
 
        dlerror();
@@ -37,29 +41,69 @@ static void *loadit(glite_jp_context_t ctx,const char *so)
                err.source = buf;
                err.code = ENOENT;
                err.desc = e;
+               return glite_jp_stack_error(ctx,&err);
        }
 
-       /* FIXME: zavolat init */
+       data = calloc(1,sizeof *data);
+
+       if (init(ctx,data)) return -1;
 
+       i = 0;
+       if (ctx->plugins) for (i=0; ctx->plugins[i]; i++);
+       ctx->plugins = realloc(ctx->plugins, (i+2) * sizeof *ctx->plugins);
+       ctx->plugins[i] = data;
+       ctx->plugins[i+1] = NULL;
+       
+       return 0;
 }
 
 int glite_jpps_fplug_load(glite_jp_context_t ctx,int *argc,char **argv)
 {
-       int     opt;
-       void    *fctx;
+       int     opt,ret;
 
        while ((opt = getopt_long(*argc,argv,"p:",opts,NULL)) != EOF) switch (opt) {
-               case 'p': fctx = loadit(ctx,optarg);
-                       if (!fctx) return -1;
+               case 'p':
+                       glite_jp_clear_error(ctx);
+
+                       if (loadit(ctx,optarg)) {
+                               glite_jp_error_t        err;
+                               err.source = __FUNCTION__;
+                               err.code = EINVAL;
+                               err.desc = optarg;
+                               return glite_jp_stack_error(ctx,&err);
+                       }
+                       break;
                default: break;
        }
 
        return 0;
 }
 
-int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t *plugin_data)
+int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t **plugin_data)
 {
-       /* TODO */
-       return 0;
+       int     i;
+
+       glite_jp_error_t        err;
+       err.source = __FUNCTION__;
+       err.code = ENOENT;
+       err.desc = (char *) uri;        /* XXX: we don't modify it, believe me, gcc! */
+
+       glite_jp_clear_error(ctx);
+       if (!ctx->plugins) {
+               return glite_jp_stack_error(ctx,&err);
+       }
+
+       for (i = 0; ctx->plugins[i]; i++) {
+               int     j;
+               glite_jpps_fplug_data_t *p = ctx->plugins[i];
+
+               for (j=0; p->uris && p->uris[j]; j++)
+                       if (!strcmp(p->uris[j],uri)) {
+                               *plugin_data = p;
+                               return 0;
+                       }
+       }
+
+       return glite_jp_stack_error(ctx,&err);
 }
 
index 9f8f93b..caf3bca 100644 (file)
@@ -166,7 +166,7 @@ SOAP_FMAC5 int SOAP_FMAC6 jpsrv__RecordTag(
 {
        CONTEXT_FROM_SOAP(soap,ctx);
        void    *file_be,*file_p;
-       glite_jpps_fplug_data_t pd;
+       glite_jpps_fplug_data_t *pd;
 
        glite_jp_tagval_t       mytag;
 
@@ -174,7 +174,7 @@ SOAP_FMAC5 int SOAP_FMAC6 jpsrv__RecordTag(
 
        /* XXX: we assume that TAGS plugin handles just one uri/class */
        if (glite_jpps_fplug_lookup(ctx,GLITE_JP_FILETYPE_TAGS,&pd)
-               || glite_jppsbe_open_file(ctx,job,pd.classes[0],NULL,
+               || glite_jppsbe_open_file(ctx,job,pd->classes[0],NULL,
                                                O_WRONLY|O_CREAT,&file_be)
        ) {
                err2fault(ctx,soap);
@@ -183,16 +183,16 @@ SOAP_FMAC5 int SOAP_FMAC6 jpsrv__RecordTag(
 
        s2jp_tag(tag,&mytag);
 
-       if (pd.ops.open(pd.fpctx,file_be,&file_p)
-               || pd.ops.generic(pd.fpctx,file_p,GLITE_JP_FPLUG_TAGS_APPEND,&mytag))
+       if (pd->ops.open(pd->fpctx,file_be,&file_p)
+               || pd->ops.generic(pd->fpctx,file_p,GLITE_JP_FPLUG_TAGS_APPEND,&mytag))
        {
                err2fault(ctx,soap);
-               if (file_p) pd.ops.close(pd.fpctx,file_p);
+               if (file_p) pd->ops.close(pd->fpctx,file_p);
                glite_jppsbe_close_file(ctx,file_be);
                return SOAP_FAULT;
        }
 
-       if (pd.ops.close(pd.fpctx,file_p)
+       if (pd->ops.close(pd->fpctx,file_p)
                || glite_jppsbe_close_file(ctx,file_be))
        {
                err2fault(ctx,soap);