RecordTag operation works
authorAleš Křenek <ljocha@ics.muni.cz>
Mon, 13 Jun 2005 11:07:28 +0000 (11:07 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Mon, 13 Jun 2005 11:07:28 +0000 (11:07 +0000)
org.glite.jp.primary/Makefile
org.glite.jp.primary/examples/jpps-test.c
org.glite.jp.primary/src/new_ftp_backend.c
org.glite.jp.primary/src/soap_ops.c
org.glite.jp.primary/src/tags_plugin.c

index 0736328..73d1c5a 100644 (file)
@@ -54,7 +54,7 @@ HDRS_S=builtin_plugins.h backend.h
 
 SRCS:= bones_server.c soap_ops.c \
        new_ftp_backend.c mysql.c file_plugin.c \
-       feed.c tags.c authz.c\
+       feed.c authz.c\
        is_client.c \
        ${ps_prefix}ServerLib.c \
        ${is_prefix}ClientLib.c jpps_C.c
@@ -87,7 +87,7 @@ default all: compile
 compile: ${daemon} ${example} ${plugins}
 
 ${daemon}: ${OBJS}
-       ${LINK} -o $@ ${OBJS} ${BONESLIB} ${TRIOLIB} ${COMMONLIB} ${GSOAPLIB} ${GLOBUS_LIBS} ${MYSQLIB} 
+       ${LINK} -o $@ -export-dynamic ${OBJS} ${BONESLIB} ${TRIOLIB} ${COMMONLIB} ${GSOAPLIB} ${GLOBUS_LIBS} ${MYSQLIB} 
 
 ${example}: ${EXA_OBJS}
        ${LINK} -o $@ ${EXA_OBJS} ${GSOAPLIB} ${GLOBUS_LIBS}
index 6a7618e..857699c 100644 (file)
@@ -157,12 +157,15 @@ int main(int argc,char *argv[])
                struct _jpelem__RecordTagResponse       empty;
                struct jptype__tagValue tagval;
                
+               int seq = 0;
+       
                if (argc != 6) usage(argv[0]);
                
                in.jobid = argv[2];
                in.tag = &tagval;
                tagval.name = argv[3];
-               tagval.sequence = NULL;
+               seq = atoi(argv[4]);
+               tagval.sequence = &seq;
                tagval.timestamp = NULL;
                tagval.stringValue = argv[5];
                tagval.blobValue = NULL;
index 14b701b..930030e 100644 (file)
@@ -880,7 +880,7 @@ static int get_job_fname(
        
        /* XXX name length */
        if (asprintf(&data_basename, "%s%s%s", class,
-               (name != NULL) ? "." : "", name) == -1) {
+               (name != NULL) ? "." : "", (name != NULL) ? name : "") == -1) {
                err.code = ENOMEM;
                goto error_out;
        }
index e80825f..9411403 100644 (file)
@@ -219,7 +219,8 @@ SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__RecordTag(
 
        if (glite_jpps_fplug_lookup(ctx,GLITE_JP_FILETYPE_TAGS,&pd)
                || glite_jppsbe_open_file(ctx,in->jobid,pd[0]->classes[0],NULL,
-                                               O_WRONLY|O_CREAT,&file_be)
+                                               O_RDWR|O_CREAT,&file_be)
+                       /* XXX: tags need reading to check magic number */
        ) {
                free(pd);
                err2fault(ctx,soap);
index 7e8b32b..95dabd8 100644 (file)
@@ -2,6 +2,8 @@
 #include <assert.h>
 #include <stdarg.h>
 #include <string.h>
+#include <errno.h>
+#include <stdint.h>
 
 #include <glite/jp/types.h>
 
@@ -12,12 +14,20 @@ static int tagappend(void *,void *,int,...);
 static int tagopen(void *,void *,const char *uri,void **);
 static int tagclose(void *,void *);
 
+#define TAGS_MAGIC 0x74c016f2  /* two middle digits encode version, i.e. 01 */
+
 static int tagdummy()
 {
        puts("tagdummy()");
        return -1;
 }
 
+struct tags_handle {
+       void    *bhandle;
+       int     n;
+       glite_jp_tagval_t       *tags;
+};
+
 int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
 {
        data->fpctx = ctx;
@@ -33,19 +43,33 @@ int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
        data->ops.attr = tagdummy;
        data->ops.generic = tagappend;
        
-       printf("tags init OK\n");
+       printf("tags_plugin: URI: \"%s\"; magic number: 0x%08lx\n",GLITE_JP_FILETYPE_TAGS,TAGS_MAGIC);
        return 0;
 }
 
 static int tagopen(void *fpctx,void *bhandle,const char *uri,void **handle)
 {
-       /* we don't need anything special yet, so just pass the backend handle */
-       *handle = bhandle;
+       struct tags_handle *h = calloc(1,sizeof *h);
+       h->n = -1;
+       h->bhandle = bhandle;
+
+       *handle = h;
+
        return 0;
 }
 
 static int tagclose(void *fpctx,void *handle)
 {
+       int     i;
+       struct tags_handle *h = handle;
+
+       for (i=0; i<h->n; i++) {
+               free(h->tags[i].name);
+               free(h->tags[i].value);
+       }
+       free(h->tags);
+       free(h);
+
        return 0;
 }
 
@@ -53,12 +77,72 @@ static int tagappend(void *fpctx,void *handle,int oper,...)
 {
        glite_jp_tagval_t       *tag;
        va_list ap;
+       char    *hdr,*rec;
+       glite_jp_context_t      ctx = fpctx;
+       struct tags_handle      *h = handle;
+       uint32_t                magic,hlen,rlen,rlen_n;
+       size_t                  r;
+       glite_jp_error_t        err;
+
+       memset(&err,0,sizeof err);
+       err.source = __FUNCTION__;
+       glite_jp_clear_error(ctx);
+
        va_start(ap,oper);
        tag = va_arg(ap,glite_jp_tagval_t *);
        va_end(ap);
 
-       /* TODO */
        printf("tagappend: %s,%d,%s\n",tag->name,tag->sequence,tag->value);
+
+       assert(oper == GLITE_JP_FPLUG_TAGS_APPEND);
+
+       if (glite_jppsbe_pread(ctx,h->bhandle,&magic,sizeof magic,0,&r)) {
+               err.code = EIO;
+               err.desc = "reading magic number";
+               return glite_jp_stack_error(ctx,&err);
+       }
+
+       if (r == 0) {
+               magic = htonl(TAGS_MAGIC);
+               if (glite_jppsbe_pwrite(ctx,h->bhandle,&magic,sizeof magic,0)) {
+                       err.code = EIO;
+                       err.desc = "writing magic number";
+                       return glite_jp_stack_error(ctx,&err);
+               }
+       }
+       else if (r != sizeof magic) {
+               err.code = EIO;
+               err.desc = "can't read magic number";
+               return glite_jp_stack_error(ctx,&err);
+       }
+       else if (magic != htonl(TAGS_MAGIC)) {
+               err.code = EINVAL;
+               err.desc = "invalid magic number";
+               return glite_jp_stack_error(ctx,&err);
+       }
+
+       trio_asprintf(&hdr,"%d %ld %c",tag->sequence,
+                       tag->timestamp,tag->binary ? 'B' : 'S');
+
+       rlen = strlen(tag->name) + strlen(hdr) + 2 /* \0 after name and after hdr */ +
+               (r = tag->binary ? tag->size : (tag->value ? strlen(tag->value) : 0));
+
+       rlen_n = htonl(rlen);
+
+       rec = malloc(rlen + sizeof rlen_n);
+       *((uint32_t *) rec) = rlen_n;
+       strcpy(rec + sizeof rlen_n,tag->name);
+       strcpy(rec + (hlen = sizeof rlen_n + strlen(tag->name) + 1),hdr);
+
+       if (r) memcpy(rec + hlen + strlen(hdr) + 1,tag->value,r);
+       free(hdr);
+
+       if (glite_jppsbe_append(ctx,h->bhandle,rec,rlen + sizeof rlen_n)) {
+               err.code = EIO;
+               err.desc = "writing tag record";
+               free(rec);
+               return glite_jp_stack_error(ctx,&err);
+       }
        
        return 0;
 }