From 14a7686a99f76a7ea8ea939db1a92fa70f011ca4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Wed, 31 Jan 2007 10:46:18 +0000 Subject: [PATCH] - plugins attr function interface has been changed (ns has been removed) - some generic functions has been moved into utils.c --- org.glite.jp.primary/Makefile | 7 +- org.glite.jp.primary/interface/file_plugin.h | 2 +- org.glite.jp.primary/src/attrs.c | 19 +--- org.glite.jp.primary/src/attrs.h | 1 + org.glite.jp.primary/src/classad_plugin.c | 4 +- org.glite.jp.primary/src/feed.c | 2 +- org.glite.jp.primary/src/sandbox_plugin.c | 4 +- org.glite.jp.primary/src/utils.c | 129 +++++++++++++++++++++++++++ org.glite.jp.primary/src/utils.h | 28 ++++++ 9 files changed, 171 insertions(+), 25 deletions(-) create mode 100644 org.glite.jp.primary/src/utils.c create mode 100644 org.glite.jp.primary/src/utils.h diff --git a/org.glite.jp.primary/Makefile b/org.glite.jp.primary/Makefile index fd3fad8..44cd51a 100644 --- a/org.glite.jp.primary/Makefile +++ b/org.glite.jp.primary/Makefile @@ -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 diff --git a/org.glite.jp.primary/interface/file_plugin.h b/org.glite.jp.primary/interface/file_plugin.h index 6959c5e..f322d4d 100644 --- a/org.glite.jp.primary/interface/file_plugin.h +++ b/org.glite.jp.primary/interface/file_plugin.h @@ -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. diff --git a/org.glite.jp.primary/src/attrs.c b/org.glite.jp.primary/src/attrs.c index db859d8..404991f 100644 --- a/org.glite.jp.primary/src/attrs.c +++ b/org.glite.jp.primary/src/attrs.c @@ -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); diff --git a/org.glite.jp.primary/src/attrs.h b/org.glite.jp.primary/src/attrs.h index 1f4e311..a5dbdc0 100644 --- a/org.glite.jp.primary/src/attrs.h +++ b/org.glite.jp.primary/src/attrs.h @@ -1 +1,2 @@ int glite_jpps_get_attrs(glite_jp_context_t,const char *,char **,int,glite_jp_attrval_t **); + diff --git a/org.glite.jp.primary/src/classad_plugin.c b/org.glite.jp.primary/src/classad_plugin.c index b1fe3cd..b0cde22 100644 --- a/org.glite.jp.primary/src/classad_plugin.c +++ b/org.glite.jp.primary/src/classad_plugin.c @@ -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; diff --git a/org.glite.jp.primary/src/feed.c b/org.glite.jp.primary/src/feed.c index 087af71..9962d66 100644 --- a/org.glite.jp.primary/src/feed.c +++ b/org.glite.jp.primary/src/feed.c @@ -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); diff --git a/org.glite.jp.primary/src/sandbox_plugin.c b/org.glite.jp.primary/src/sandbox_plugin.c index 6219247..f81aa3c 100644 --- a/org.glite.jp.primary/src/sandbox_plugin.c +++ b/org.glite.jp.primary/src/sandbox_plugin.c @@ -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 index 0000000..533e6d1 --- /dev/null +++ b/org.glite.jp.primary/src/utils.c @@ -0,0 +1,129 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 index 0000000..b350ada --- /dev/null +++ b/org.glite.jp.primary/src/utils.h @@ -0,0 +1,28 @@ +#ifndef __GLITE_JP_UTILS +#define __GLITE_JP_UTILS + +#include +#include +#include + +#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 + -- 1.8.2.3