From 97afb875ee24ed8c6660609f1955cbbcd0f841f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20K=C5=99enek?= Date: Thu, 4 Aug 2005 13:26:20 +0000 Subject: [PATCH] cleanup in types --- org.glite.jp.common/interface/types.h | 65 ++++---------------- org.glite.jp.common/src/attr.c | 112 +--------------------------------- org.glite.jp.common/src/context.c | 41 +++---------- 3 files changed, 23 insertions(+), 195 deletions(-) diff --git a/org.glite.jp.common/interface/types.h b/org.glite.jp.common/interface/types.h index 7cf9d98..968889e 100644 --- a/org.glite.jp.common/interface/types.h +++ b/org.glite.jp.common/interface/types.h @@ -23,45 +23,18 @@ typedef struct _glite_jp_context { } *glite_jp_context_t; typedef enum { - GLITE_JP_FILECLASS_UNDEF, - GLITE_JP_FILECLASS_INPUT, - GLITE_JP_FILECLASS_OUTPUT, - GLITE_JP_FILECLASS_LBLOG, - GLITE_JP_FILECLASS_TAGS, - GLITE_JP_FILECLASS__LAST -} glite_jp_fileclass_t; + GLITE_JP_ATTR_ORIG_ANY, /**< for queries: don't care about origin */ + GLITE_JP_ATTR_ORIG_SYSTEM, /**< JP internal, e.g. job owner */ + GLITE_JP_ATTR_ORIG_USER, /**< inserted by user explicitely */ + GLITE_JP_ATTR_ORIG_FILE /**< coming from uploaded file */ +} glite_jp_attr_orig_t; typedef struct { - char *name; - int sequence; - time_t timestamp; - int binary; - size_t size; + char *name; /**< including namespace */ char *value; -} glite_jp_tagval_t; - -typedef enum { - GLITE_JP_ATTR_UNDEF, - GLITE_JP_ATTR_OWNER, - GLITE_JP_ATTR_TIME, - GLITE_JP_ATTR_TAG, - GLITE_JP_ATTR_GENERIC, - GLITE_JP_ATTR__LAST -} glite_jp_attrtype_t; - -typedef struct { - glite_jp_attrtype_t type; - char *name,*namespace; -} glite_jp_attr_t; - -typedef struct { - glite_jp_attr_t attr; - union { - char *s; - int i; - struct timeval time; - glite_jp_tagval_t tag; - } value; + glite_jp_attr_orig_t origin; + char *origin_detail; /**< where it came from, i.e. file URI:name */ + time_t timestamp; } glite_jp_attrval_t; @@ -76,26 +49,12 @@ typedef enum { } glite_jp_queryop_t; typedef struct { - glite_jp_attr_t attr; + char *attr; glite_jp_queryop_t op; - union _glite_jp_query_rec_val { - char *s; - int i; - struct timeval time; - } value,value2; + char *value, *value2; + glite_jp_attr_orig_t origin; } glite_jp_query_rec_t; void glite_jp_attrval_free(glite_jp_attrval_t *,int); -void glite_jp_attr_free(glite_jp_attr_t *,int); -void glite_jp_attrset_free(glite_jp_attr_t *a,int); - -int glite_jp_attr_cmp(const glite_jp_attr_t *,const glite_jp_attr_t *); - -void glite_jp_attr_union(const glite_jp_attr_t *, const glite_jp_attr_t *, - glite_jp_attr_t **); - -void glite_jp_attr_sub(const glite_jp_attr_t *, const glite_jp_attr_t *, - glite_jp_attr_t **); - #endif diff --git a/org.glite.jp.common/src/attr.c b/org.glite.jp.common/src/attr.c index 3e20b69..250ef5a 100644 --- a/org.glite.jp.common/src/attr.c +++ b/org.glite.jp.common/src/attr.c @@ -6,114 +6,8 @@ void glite_jp_attrval_free(glite_jp_attrval_t *a,int f) { - switch (a->attr.type) { - case GLITE_JP_ATTR_OWNER: - case GLITE_JP_ATTR_GENERIC: - free(a->value.s); - break; - case GLITE_JP_ATTR_TAG: - if (a->value.tag.name) free(a->value.tag.name); - if (a->value.tag.value) free(a->value.tag.value); - break; - default: break; - } - - glite_jp_attr_free(&a->attr, 0); + free(a->name); + free(a->value); + free(a->origin_detail); if (f) free(a); } - -int glite_jp_attr_cmp(const glite_jp_attr_t *a,const glite_jp_attr_t *b) -{ - int c; - - if (a->type < b->type) return -1; - if (a->type > b->type) return 1; - - switch (a->type) { - case GLITE_JP_ATTR_TAG: - case GLITE_JP_ATTR_GENERIC: - if (a->namespace && b->namespace && - (c = strcmp(a->namespace,b->namespace))) return c; - return strcmp(a->name,b->name); - - default: return 0; - } -} - -static int void_attr_cmp(const void *va, const void *vb) -{ - return glite_jp_attr_cmp(va,vb); -} - -void glite_jp_attr_union(const glite_jp_attr_t *a, const glite_jp_attr_t *b, - glite_jp_attr_t **out) -{ - int ac,bc,c,i,j; - glite_jp_attr_t *res; - - assert(out); - if (a) for (ac=0; a[ac].type; ac++); else ac=0; - if (b) for (bc=0; b[bc].type; bc++); else bc=0; - - if ((c = ac+bc) == 0) { - *out = NULL; - return; - } - - res = malloc((ac+bc+1) * sizeof *res); - memcpy(res,a,ac * sizeof *a); - memcpy(res+ac,b,bc * sizeof *b); - memset(res+ac+bc,0,sizeof *res); - qsort(res,c,sizeof *res,void_attr_cmp); - - for (i=0; i i+1) { - memmove(res+i+1,res+j,c-j); - c -= j - (i+1); - } - } - - for (i=0; res[i].type; i++) switch (res[i].type) { - case GLITE_JP_ATTR_TAG: - case GLITE_JP_ATTR_GENERIC: - if (res[i].namespace) res[i].namespace = strdup(res[i].namespace); - if (res[i].name) res[i].name = strdup(res[i].name); - break; - default: break; - } - - *out = res; -} - -void glite_jp_attr_sub(const glite_jp_attr_t *a, const glite_jp_attr_t *b, - glite_jp_attr_t **out) -{ - abort(); -} - -void glite_jp_attr_free(glite_jp_attr_t *a,int f) -{ - if (a) { - switch (a->type) { - case GLITE_JP_ATTR_TAG: - case GLITE_JP_ATTR_GENERIC: - free(a->name); - free(a->namespace); - break; - default: - break; - } - if (f) free(a); - } -} - -void glite_jp_attrset_free(glite_jp_attr_t *a,int f) -{ - int i; - - if (a) { - for (i=0; a[i].type; i++) glite_jp_attr_free(a+i,0); - if (f) free(a); - } -} diff --git a/org.glite.jp.common/src/context.c b/org.glite.jp.common/src/context.c index 10f59d9..fc7b0bf 100644 --- a/org.glite.jp.common/src/context.c +++ b/org.glite.jp.common/src/context.c @@ -67,44 +67,19 @@ int glite_jp_clear_error(glite_jp_context_t ctx) void glite_jp_free_query_rec(glite_jp_query_rec_t *q) { - free(q->attr.name); q->attr.name = NULL; - switch (q->attr.type) { - case GLITE_JP_ATTR_OWNER: - case GLITE_JP_ATTR_TAG: - free(q->value.s); q->value.s = NULL; - if (q->op == GLITE_JP_QUERYOP_WITHIN) { - free(q->value2.s); - q->value2.s = NULL; - } - break; - default: break; - } -} - -int glite_jp_attr_copy(glite_jp_attr_t *dst,const glite_jp_attr_t *src) -{ - dst->name = src->name ? strdup(src->name) : NULL; - dst->type = src->type; - return 0; + free(q->attr); + free(q->value); + free(q->value2); + memset(q,0,sizeof *q); } int glite_jp_queryrec_copy(glite_jp_query_rec_t *dst, const glite_jp_query_rec_t *src) { - glite_jp_attr_copy(&dst->attr,&src->attr); + if (src->attr) dst->attr = strdup(src->attr); + if (src->value) dst->value = strdup(src->value); + if (src->value2) dst->value2 = strdup(src->value2); dst->op = src->op; - switch (src->attr.type) { - case GLITE_JP_ATTR_OWNER: - case GLITE_JP_ATTR_TAG: - dst->value.s = strdup(src->value.s); - if (dst->op == GLITE_JP_QUERYOP_WITHIN) - dst->value2.s = strdup(src->value2.s); - break; - case GLITE_JP_ATTR_TIME: - memcpy(&dst->value.time,&src->value.time,sizeof dst->value.time); - if (dst->op == GLITE_JP_QUERYOP_WITHIN) - memcpy(&dst->value2.time,&src->value2.time,sizeof dst->value2.time); - break; - } + dst->origin = src->origin; return 0; } -- 1.8.2.3