From: Aleš Křenek Date: Fri, 15 Jul 2005 11:04:45 +0000 (+0000) Subject: attribute set manipulation functions X-Git-Tag: glite-lb-ws-interface_R_2_0_0~7 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=6e46b483ce9f91f995c8eae3b776dfe17e059fc8;p=jra1mw.git attribute set manipulation functions --- diff --git a/org.glite.jp.common/interface/types.h b/org.glite.jp.common/interface/types.h index 7ad3ed8..34e46ea 100644 --- a/org.glite.jp.common/interface/types.h +++ b/org.glite.jp.common/interface/types.h @@ -87,4 +87,13 @@ typedef struct { 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); + +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 fcef59c..7599a63 100644 --- a/org.glite.jp.common/src/attr.c +++ b/org.glite.jp.common/src/attr.c @@ -1,4 +1,5 @@ #include +#include #include "types.h" @@ -16,3 +17,87 @@ void glite_jp_attrval_free(glite_jp_attrval_t *a,int f) if (f) free(a); } + +static int attr_cmp(const void *va,const void *vb) +{ + int c; + const glite_jp_attr_t *a = va, *b = vb; + + 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; + } +} + +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(a); assert(b); assert(out); + for (ac=0; a[ac].type; ac++); + for (bc=0; b[bc].type; bc++); + 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); + c = ac+bc; + qsort(res,c,sizeof *res,attr_cmp); + + for (i=0; i i+1) memmove(res+i+1,res+j,c-j); + } + + 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); + } +}