- plugins attr function interface has been changed (ns has been removed)
authorJiří Filipovič <fila@ics.muni.cz>
Wed, 31 Jan 2007 10:46:18 +0000 (10:46 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Wed, 31 Jan 2007 10:46:18 +0000 (10:46 +0000)
- some generic functions has been moved into utils.c

org.glite.jp.primary/Makefile
org.glite.jp.primary/interface/file_plugin.h
org.glite.jp.primary/src/attrs.c
org.glite.jp.primary/src/attrs.h
org.glite.jp.primary/src/classad_plugin.c
org.glite.jp.primary/src/feed.c
org.glite.jp.primary/src/sandbox_plugin.c
org.glite.jp.primary/src/utils.c [new file with mode: 0644]
org.glite.jp.primary/src/utils.h [new file with mode: 0644]

index fd3fad8..44cd51a 100644 (file)
@@ -36,7 +36,6 @@ CLASSADPLUGIN_LIBS:= ${classadslib} -lstdc++
 
 CLASSADPLUGIN_LOBJS:= classad_plugin.lo
 
-
 GLOBUS_CFLAGS:=-I${globus_prefix}/include/${nothrflavour}
 
 DEBUG:=-g -O0  -DDEBUG
@@ -59,11 +58,11 @@ sample_jobs:=sample_job_aborted  sample_job_cleared  sample_job_tagged_done  sam
 plugins:=glite-jp-ftpdauth.la glite-jp-classad.la glite-jp-sandbox.la
 
 HDRS_I=file_plugin.h
-HDRS_S=builtin_plugins.h backend.h feed.h
+HDRS_S=builtin_plugins.h backend.h feed.h utils.h
 
 SRCS:= bones_server.c soap_ops.c \
-       new_ftp_backend.c mysql.c file_plugin.c \
-       feed.c authz.c attrs.c\
+       new_ftp_backend.c mysql.c file_plugin.c utils.c\
+       feed.c authz.c attrs.c \
        tags.c\
        is_client.c \
        soap_switch.c
index 6959c5e..f322d4d 100644 (file)
@@ -40,7 +40,7 @@ typedef struct _glite_jpps_fplug_op_t {
 \retval ENOSYS this attribute is not defined by this type of file
 \retval ENOENT no value is present 
 */
-       int     (*attr)(void *fpctx,void *handle,const char *ns, const char *attr,glite_jp_attrval_t **attrval);
+       int     (*attr)(void *fpctx,void *handle, const char *attr,glite_jp_attrval_t **attrval);
 
 /** File type specific operation. 
 \param[in] fpctx       Plugin context.
index db859d8..404991f 100644 (file)
@@ -20,16 +20,6 @@ static struct {
 
 } *known_namespaces;
 
-static char* get_namespace(const char* attr){
-        char* namespace = strdup(attr);
-        char* colon = strrchr(namespace, ':');
-       if (colon)
-               namespace[strrchr(namespace, ':') - namespace] = 0;
-       else
-               namespace[0] = 0;
-       return namespace;
-}
-
 static void scan_namespaces(glite_jp_context_t ctx)
 {
         int     i,j,k;
@@ -80,7 +70,7 @@ static int merge_attrvals(glite_jp_attrval_t **out,int nout,const glite_jp_attrv
        return nout+nin;
 }
 
-void process_files(glite_jp_context_t ctx, const char *job, glite_jp_attrval_t** out, int* nout, const char* attr, const glite_jpps_fplug_data_t* plugin, const char* class, const char* uri, const char *ns){
+void process_files(glite_jp_context_t ctx, const char *job, glite_jp_attrval_t** out, int* nout, const char* attr, const glite_jpps_fplug_data_t* plugin, const char* class, const char* uri){
        void *ph, *beh; 
        char** names = NULL;
         int nnames = glite_jppsbe_get_names(ctx, job, class, &names);
@@ -90,7 +80,7 @@ void process_files(glite_jp_context_t ctx, const char *job, glite_jp_attrval_t**
                        if (!plugin->ops.open(plugin->fpctx,beh,uri,&ph)) {
                                glite_jp_attrval_t* myattr;
                                // XXX: ignore errors
-                               if (!plugin->ops.attr(plugin->fpctx,ph,ns,attr,&myattr)) {
+                               if (!plugin->ops.attr(plugin->fpctx,ph,attr,&myattr)) {
                                        int k;
                                        for (k=0; myattr[k].name; k++) {
                                                myattr[k].origin = GLITE_JP_ATTR_ORIG_FILE;
@@ -144,14 +134,13 @@ glite_jpps_get_attrs(glite_jp_context_t ctx,const char *job,char **attr,int natt
                        nout++;
                for (j = 0; known_namespaces[j].namespace; j++) {
                        void* ph;
-                       char* attr_namespace = get_namespace(other[i]);
+                       char* attr_namespace = glite_jpps_get_namespace(other[i]);
                        if (strcmp(attr_namespace, known_namespaces[j].namespace) == 0){
                                for (k = 0; known_namespaces[j].plugins[k]; k++)
                                        for (l = 0; known_namespaces[j].plugins[k]->classes[l]; l++)
                                                process_files(ctx, job, &out, &nout, other[i], known_namespaces[j].plugins[k]
                                                        , known_namespaces[j].plugins[k]->classes[l]
-                                                       , known_namespaces[j].plugins[k]->uris[l]
-                                                       , known_namespaces[j].namespace);
+                                                       , known_namespaces[j].plugins[k]->uris[l]);
                                break;
                        }
                        free(attr_namespace);
index 1f4e311..a5dbdc0 100644 (file)
@@ -1 +1,2 @@
 int glite_jpps_get_attrs(glite_jp_context_t,const char *,char **,int,glite_jp_attrval_t **);
+
index b1fe3cd..b0cde22 100644 (file)
@@ -33,7 +33,7 @@ typedef struct _classad_handle{
        time_t timestamp;
 } classad_handle;
 
-static int classad_query(void *fpctx, void *handle, const char *ns, const char *attr, glite_jp_attrval_t **attrval);
+static int classad_query(void *fpctx, void *handle, const char *attr, glite_jp_attrval_t **attrval);
 static int classad_open(void *fpctx, void *bhandle, const char *uri, void **handle);
 static int classad_open_str(void *fpctx, const char *str, const char *uri, const char *ns, void **handle);
 static int classad_close(void *fpctx, void *handle);
@@ -154,7 +154,7 @@ static int classad_close(void *fpctx,void *handle) {
 }
 
 
-static int classad_query(void *fpctx,void *handle, const char* ns, const char *attr,glite_jp_attrval_t **attrval) {
+static int classad_query(void *fpctx,void *handle, const char *attr,glite_jp_attrval_t **attrval) {
        glite_jp_context_t      ctx = (glite_jp_context_t) fpctx;
        glite_jp_error_t        err;
        glite_jp_attrval_t      *av = NULL;
index 087af71..9962d66 100644 (file)
@@ -314,7 +314,7 @@ int glite_jpps_match_file(
                        }
 
                        for (i=0; attrs[i]; i++) 
-                               if (!pd[pi]->ops.attr(pd[pi]->fpctx,ph,"",attrs[i],&oneval)) {
+                               if (!pd[pi]->ops.attr(pd[pi]->fpctx,ph,attrs[i],&oneval)) {
                                /* XXX: ignore error */
                                        for (j=0; oneval[j].name; j++);
                                        vals = realloc(vals,(nvals+j+1) * sizeof *vals);
index 6219247..f81aa3c 100644 (file)
@@ -36,7 +36,7 @@ static struct {
 //static int sandbox_append(void *,void *,int,...);
 static int sandbox_open(void *,void *,const char *uri,void **);
 static int sandbox_close(void *,void *);
-static int sandbox_attr(void *,void *,const char*,const char *,glite_jp_attrval_t **);
+static int sandbox_attr(void *,void *,const char *,glite_jp_attrval_t **);
 static int sandbox_filecom(void *,void *);
 
 int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
@@ -145,7 +145,7 @@ static int sandbox_close(void *fpctx,void *handle)
 }
 
 
-static int sandbox_attr(void *fpctx,void *handle,const char *ns,const char *attr,glite_jp_attrval_t **attrval)
+static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrval_t **attrval)
 {
        glite_jp_error_t        err;
        glite_jp_context_t      ctx = fpctx;
diff --git a/org.glite.jp.primary/src/utils.c b/org.glite.jp.primary/src/utils.c
new file mode 100644 (file)
index 0000000..533e6d1
--- /dev/null
@@ -0,0 +1,129 @@
+#include <getopt.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <limits.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "glite/jp/types.h"
+#include "glite/jp/context.h"
+#include "glite/jp/strmd5.h"
+#include "glite/jp/known_attr.h"
+#include "glite/jp/attr.h"
+#include "glite/jp/escape.h"
+
+#include "feed.h"
+#include "tags.h"
+#include "db.h"
+
+#include "utils.h"
+#include "backend.h"
+
+/*
+ * realloc the line to double size if needed
+ *
+ * \return 0 if failed, did nothing
+ * \return 1 if success
+ */
+int check_realloc_line(char **line, size_t *maxlen, size_t len) {
+        void *tmp;
+
+        if (len > *maxlen) {
+                *maxlen <<= 1;
+                tmp = realloc(*line, *maxlen);
+                if (!tmp) return 0;
+                *line = tmp;
+        }
+
+        return 1;
+}
+
+/*
+ * read next line from stream
+ *
+ * \return error code
+ */
+int glite_jppsbe_readline(
+        glite_jp_context_t ctx,
+        void *handle,
+        rl_buffer_t *buffer,
+        char **line
+)
+{
+        size_t maxlen, len, i;
+        ssize_t nbytes;
+        int retval, z, end;
+
+        maxlen = BUFSIZ;
+        i = 0;
+        len = 0;
+        *line = malloc(maxlen);
+        end = 0;
+
+        do {
+                /* read next portion */
+                if (buffer->pos >= buffer->size) {
+                        buffer->pos = 0;
+                        buffer->size = 0;
+                        if ((retval = glite_jppsbe_pread(ctx, handle, buffer->buf, BUFSIZ, buffer->offset, &nbytes)) == 0) {
+                                if (nbytes < 0) {
+                                        retval = EINVAL;
+                                        goto fail;
+                                } else {
+                                        if (nbytes) {
+                                                buffer->size = (size_t)nbytes;
+                                                buffer->offset += nbytes;
+                                        } else end = 1;
+                                }
+                        } else goto fail;
+                }
+
+                /* we have buffer->size - buffer->pos bytes */
+                i = buffer->pos;
+                do {
+                        if (i >= buffer->size) z = '\0';
+                        else {
+                                z = buffer->buf[i];
+                                if (z == '\n') z = '\0';
+                        }
+                        len++;
+
+                        if (!check_realloc_line(line, &maxlen, len)) {
+                                retval = ENOMEM;
+                                goto fail;
+                        }
+                        (*line)[len - 1] = z;
+                        i++;
+                } while (z && i < buffer->size);
+                buffer->pos = i;
+        } while (len && (*line)[len - 1] != '\0');
+
+        if ((!len || !(*line)[0]) && end) {
+                free(*line);
+                *line = NULL;
+        }
+
+        return 0;
+
+fail:
+        free(*line);
+        *line = NULL;
+        return retval;
+}
+
+char* glite_jpps_get_namespace(const char* attr){
+        char* namespace = strdup(attr);
+        char* colon = strrchr(namespace, ':');
+        if (colon)
+                namespace[strrchr(namespace, ':') - namespace] = 0;
+        else
+                namespace[0] = 0;
+        return namespace;
+}
+
diff --git a/org.glite.jp.primary/src/utils.h b/org.glite.jp.primary/src/utils.h
new file mode 100644 (file)
index 0000000..b350ada
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __GLITE_JP_UTILS
+#define __GLITE_JP_UTILS
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "feed.h"
+
+typedef struct _rl_buffer_t {
+        char                    *buf;
+        size_t                  pos, size;
+        off_t                   offset;
+} rl_buffer_t;
+
+int glite_jppsbe_readline(
+        glite_jp_context_t ctx,
+        void *handle,
+        rl_buffer_t *buffer,
+        char **line
+);
+
+char* glite_jpps_get_namespace(
+       const char* attr
+);
+
+#endif
+