source: trunk/zoo-project/zoo-kernel/service.h @ 364

Last change on this file since 364 was 364, checked in by djay, 12 years ago

Update to make ZOO-Kernel able to compile and run from Windows Platforms. A special thanks to Espen Messel, Knut Landmark and Benrd Härtwig for providing many patches that I can successfully apply on the SVN source tree and to Farkas for continuing requesting for ZOO-Kernel to run on Windows platforms privately and through the ZOO-Discuss mailing list.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 20.2 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2012 GeoLabs SARL
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#ifndef ZOO_SERVICE_H
26#define ZOO_SERVICE_H 1
27
28#pragma once
29
30#ifdef WIN32
31#define strncasecmp strnicmp
32#define strcasecmp stricmp
33#define snprintf sprintf_s
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#include <stdlib.h>
41#include <ctype.h>
42#include <stdio.h>
43#include <string.h>
44
45#ifndef WIN32
46#define bool int
47#define true 1
48#define false -1
49#endif
50
51#define SERVICE_ACCEPTED 0
52#define SERVICE_STARTED 1
53#define SERVICE_PAUSED 2
54#define SERVICE_SUCCEEDED 3
55#define SERVICE_FAILED 4
56
57#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
58#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
59#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
60#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
61#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
62
63#define SHMSZ     27
64
65
66  /**
67   * \struct map
68   * \brief KVP linked list
69   *
70   * Deal with WPS KVP (name,value).
71   * A map is defined as:
72   *  - name : a key,
73   *  - value: a value,
74   *  - next : a pointer to the next map if any.
75   */
76  typedef struct map{
77    char* name;
78    char* value;
79    struct map* next;
80  } map;
81
82#ifdef WIN32
83#define NULLMAP ((map*) 0)
84#else
85#define NULLMAP NULL
86#endif
87
88  /**
89   * \struct maps
90   * \brief linked list of map pointer
91   *
92   * Small object to store WPS KVP set.
93   * Maps is defined as:
94   *  - a name,
95   *  - a content map,
96   *  - a pointer to the next maps if any.
97   */
98  typedef struct maps{
99    char* name;         
100    struct map* content; 
101    struct maps* next;   
102  } maps;
103
104  /**
105   * \brief Dump a map on stderr
106   */
107  static void _dumpMap(map* t){
108    if(t!=NULL){
109      fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
110      fflush(stderr);
111        }else{
112      fprintf(stderr,"NULL\n");
113      fflush(stderr);
114    }
115  }
116
117  static void dumpMap(map* t){
118    map* tmp=t;
119    while(tmp!=NULL){
120      _dumpMap(tmp);
121      tmp=tmp->next;
122    }
123  }
124
125  static void dumpMapToFile(map* t,FILE* file){
126    map* tmp=t;
127    while(tmp!=NULL){
128#ifdef DEBUG
129      fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
130#endif
131      fprintf(file,"%s = %s\n",tmp->name,tmp->value);
132      tmp=tmp->next;
133    }
134  }
135
136  static void dumpMaps(maps* m){
137    maps* tmp=m;
138    while(tmp!=NULL){
139      fprintf(stderr,"MAP => [%s] \n",tmp->name);
140      dumpMap(tmp->content);
141      tmp=tmp->next;
142    }
143  }
144
145  static void dumpMapsToFile(maps* m,char* file_path){
146    FILE* file=fopen(file_path,"w");
147    maps* tmp=m;
148    if(tmp!=NULL){
149      fprintf(file,"[%s]\n",tmp->name);
150      dumpMapToFile(tmp->content,file);
151      fflush(file);
152    }
153    fclose(file);
154  }
155
156  static map* createMap(const char* name,const char* value){
157    map* tmp=(map *)malloc(MAP_SIZE);
158    tmp->name=strdup(name);
159    tmp->value=strdup(value);
160    tmp->next=NULL;
161    return tmp;
162  }
163
164  static int count(map* m){
165    map* tmp=m;
166    int c=0;
167    while(tmp!=NULL){
168      c++;
169      tmp=tmp->next;
170    }
171    return c;
172  }
173   
174  static bool hasKey(map* m,const char *key){
175    map* tmp=m;
176    while(tmp!=NULL){
177      if(strcasecmp(tmp->name,key)==0)
178        return true;
179      tmp=tmp->next;
180    }
181#ifdef DEBUG_MAP
182    fprintf(stderr,"NOT FOUND \n");
183#endif
184    return false;
185  }
186
187  static maps* getMaps(maps* m,const char *key){
188    maps* tmp=m;
189    while(tmp!=NULL){
190      if(strcasecmp(tmp->name,key)==0){
191        return tmp;
192      }
193      tmp=tmp->next;
194    }
195    return NULL;
196  }
197
198  static map* getMap(map* m,const char *key){
199    map* tmp=m;
200    while(tmp!=NULL){
201      if(strcasecmp(tmp->name,key)==0){
202        return tmp;
203      }
204      tmp=tmp->next;
205    }
206    return NULL;
207  }
208
209
210  static map* getLastMap(map* m){
211    map* tmp=m;
212    while(tmp!=NULL){
213      if(tmp->next==NULL){
214        return tmp;
215      }
216      tmp=tmp->next;
217    }
218    return NULL;
219  }
220
221  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
222    maps* _tmpm=getMaps(m,key);
223    if(_tmpm!=NULL){
224      map* _ztmpm=getMap(_tmpm->content,subkey);
225      return _ztmpm;
226    }
227    else return NULL;
228  }
229
230  static char* getMapsAsKVP(maps* m,int length,int type){
231    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
232    maps* curs=m;
233    int i=0;
234    while(curs!=NULL){
235      if(i==0)
236        if(type==0)
237          sprintf(dataInputsKVP,"%s=",curs->name);
238        else
239          sprintf(dataInputsKVP,"%s",curs->name);
240      else{
241        char *temp=strdup(dataInputsKVP);
242        if(type==0)
243          sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
244        else
245          sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
246        free(temp);
247      }
248      map* icurs=curs->content;
249      if(type==0){
250        map* tmp=getMap(curs->content,"value");
251        char *temp=strdup(dataInputsKVP);
252        if(getMap(m->content,"xlink:href")!=NULL)
253          sprintf(dataInputsKVP,"%sReference",temp);
254        else
255          sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
256        free(temp);
257      }
258      int j=0;
259      while(icurs!=NULL){
260        if(strcasecmp(icurs->name,"value")!=0 &&
261           strcasecmp(icurs->name,"Reference")!=0 &&
262           strcasecmp(icurs->name,"minOccurs")!=0 &&
263           strcasecmp(icurs->name,"maxOccurs")!=0 &&
264           strcasecmp(icurs->name,"inRequest")!=0){
265          char *itemp=strdup(dataInputsKVP);
266          sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
267          free(itemp);
268        }
269        icurs=icurs->next;
270      }
271      curs=curs->next;
272      i++;
273    }
274    return dataInputsKVP;
275  }
276
277
278  static void freeMap(map** mo){
279    map* _cursor=*mo;
280    if(_cursor!=NULL){
281#ifdef DEBUG
282      fprintf(stderr,"freeMap\n");
283#endif
284      free(_cursor->name);
285      free(_cursor->value);
286      if(_cursor->next!=NULL){
287        freeMap(&_cursor->next);
288        free(_cursor->next);
289      }
290    }
291  }
292
293  static void freeMaps(maps** mo){
294    maps* _cursor=*mo;
295    fflush(stderr);
296    if(_cursor && _cursor!=NULL){
297#ifdef DEBUG
298      fprintf(stderr,"freeMaps\n");
299#endif
300      free(_cursor->name);
301      if(_cursor->content!=NULL){
302        freeMap(&_cursor->content);
303        free(_cursor->content);
304      }
305      if(_cursor->next!=NULL){
306        freeMaps(&_cursor->next);
307        free(_cursor->next);
308      }
309    }
310  }
311
312  /**
313   * \brief Not named linked list
314   *
315   * Used to store informations about formats, such as mimeType, encoding ...
316   *
317   * An iotype is defined as :
318   *  - a content map,
319   *  - a pointer to the next iotype if any.
320   */
321  typedef struct iotype{
322    struct map* content;
323    struct iotype* next;
324  } iotype;
325
326  /**
327   * \brief Metadata information about input or output.
328   *
329   * The elements are used to store metadata informations defined in the ZCFG.
330   *
331   * An elements is defined as :
332   *  - a name,
333   *  - a content map,
334   *  - a metadata map,
335   *  - a format (possible values are LiteralData, ComplexData or
336   * BoundingBoxData),
337   *  - a default iotype,
338   *  - a pointer to the next elements id any.
339   */
340  typedef struct elements{
341    char* name;
342    struct map* content;
343    struct map* metadata;
344    char* format;
345    struct iotype* defaults;
346    struct iotype* supported;
347    struct elements* next;
348  } elements;
349
350  typedef struct service{
351    char* name;
352    struct map* content;
353    struct map* metadata;
354    struct elements* inputs;
355    struct elements* outputs; 
356  } service;
357
358  typedef struct services{
359    struct service* content; 
360    struct services* next; 
361  } services;
362
363  static bool hasElement(elements* e,const char* key){
364    elements* tmp=e;
365    while(tmp!=NULL){
366      if(strcasecmp(key,tmp->name)==0)
367        return true;
368      tmp=tmp->next;
369    }
370    return false;
371  }
372
373  static elements* getElements(elements* m,char *key){
374    elements* tmp=m;
375    while(tmp!=NULL){
376      if(strcasecmp(tmp->name,key)==0)
377        return tmp;
378      tmp=tmp->next;
379    }
380    return NULL;
381  }
382
383
384  static void freeIOType(iotype** i){
385    iotype* _cursor=*i;
386    if(_cursor!=NULL){
387      if(_cursor->next!=NULL){
388        freeIOType(&_cursor->next);
389        free(_cursor->next);
390      }
391      freeMap(&_cursor->content);
392      free(_cursor->content);
393    }
394  }
395
396  static void freeElements(elements** e){
397    elements* tmp=*e;
398    if(tmp!=NULL){
399      if(tmp->name!=NULL)
400        free(tmp->name);
401      freeMap(&tmp->content);
402      if(tmp->content!=NULL)
403        free(tmp->content);
404      freeMap(&tmp->metadata);
405      if(tmp->metadata!=NULL)
406        free(tmp->metadata);
407      if(tmp->format!=NULL)
408        free(tmp->format);
409      freeIOType(&tmp->defaults);
410      if(tmp->defaults!=NULL)
411        free(tmp->defaults);
412      freeIOType(&tmp->supported);
413      if(tmp->supported!=NULL){
414        free(tmp->supported);
415      }
416      freeElements(&tmp->next);
417      if(tmp->next!=NULL)
418        free(tmp->next);
419    }
420  }
421
422  static void freeService(service** s){
423    service* tmp=*s;
424    if(tmp!=NULL){
425      if(tmp->name!=NULL)
426        free(tmp->name);
427      freeMap(&tmp->content);
428      if(tmp->content!=NULL)
429        free(tmp->content);
430      freeMap(&tmp->metadata);
431      if(tmp->metadata!=NULL)
432        free(tmp->metadata);
433      freeElements(&tmp->inputs);
434      if(tmp->inputs!=NULL)
435        free(tmp->inputs);
436      freeElements(&tmp->outputs);
437      if(tmp->outputs!=NULL)
438        free(tmp->outputs);
439    }
440  }
441
442  static void addToMap(map* m,const char* n,const char* v){
443    if(hasKey(m,n)==false){
444      map* _cursor=m;
445      while(_cursor->next!=NULL)
446        _cursor=_cursor->next;
447      _cursor->next=createMap(n,v);
448    }
449    else{
450      map *tmp=getMap(m,n);
451      if(tmp->value!=NULL)
452        free(tmp->value);
453      tmp->value=strdup(v);
454    }
455  }
456
457  static void addMapToMap(map** mo,map* mi){
458    map* tmp=mi;
459    map* _cursor=*mo;
460    if(tmp==NULL){
461      if(_cursor!=NULL){
462        while(_cursor!=NULL)
463          _cursor=_cursor->next;
464        _cursor=NULL;
465      }else
466        *mo=NULL;
467    }
468    while(tmp!=NULL){
469      if(_cursor==NULL){
470        if(*mo==NULL)
471          *mo=createMap(tmp->name,tmp->value);
472        else
473          addToMap(*mo,tmp->name,tmp->value);
474      }
475      else{
476#ifdef DEBUG
477        fprintf(stderr,"_CURSOR\n");
478        dumpMap(_cursor);
479#endif
480        while(_cursor!=NULL)
481          _cursor=_cursor->next;
482        _cursor=createMap(tmp->name,tmp->value);
483        _cursor->next=NULL;
484      }
485      tmp=tmp->next;
486#ifdef DEBUG
487      fprintf(stderr,"MO\n");
488      dumpMap(*mo);
489#endif
490    }
491  }
492
493  static void addMapToIoType(iotype** io,map* mi){
494    iotype* tmp=*io;
495    while(tmp->next!=NULL){
496      tmp=tmp->next;
497    }
498    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
499    tmp->next->content=NULL;
500    addMapToMap(&tmp->next->content,mi);
501    tmp->next->next=NULL;
502  }
503
504  static map* getMapOrFill(map* m,const char *key,char* value){
505    map* tmp=m;
506    map* tmpMap=getMap(tmp,key);
507    if(tmpMap==NULL){
508      if(tmp!=NULL)
509        addToMap(tmp,key,value);
510      else
511        tmp=createMap(key,value);
512      tmpMap=getMap(tmp,key);
513    }
514    return tmpMap;
515  }
516
517  static bool contains(map* m,map* i){
518    while(i!=NULL){     
519      if(strcasecmp(i->name,"value")!=0 &&
520         strcasecmp(i->name,"xlink:href")!=0 &&
521         strcasecmp(i->name,"useMapServer")!=0 &&
522         strcasecmp(i->name,"asReference")!=0){
523        map *tmp;
524        if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
525           strcasecmp(i->value,tmp->value)!=0)
526          return false;
527      }
528      i=i->next;
529    }
530    return true;
531  }
532
533  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
534    elements* cursor=e;
535    while(cursor!=NULL){
536      if(strcasecmp(cursor->name,name)==0){
537        if(contains(cursor->defaults->content,values)==true)
538          return cursor->defaults;
539        else{
540          iotype* tmp=cursor->supported;
541          while(tmp!=NULL){
542            if(contains(tmp->content,values)==true)
543              return tmp;           
544            tmp=tmp->next;
545          }
546        }
547      }
548      cursor=cursor->next;
549    }
550    return NULL;
551  }
552
553  static maps* dupMaps(maps** mo){
554    maps* _cursor=*mo;
555    maps* res=NULL;
556    if(_cursor!=NULL){
557      res=(maps*)malloc(MAPS_SIZE);
558      res->name=strdup(_cursor->name);
559      res->content=NULL;
560      res->next=NULL;
561      map* mc=_cursor->content;
562      map* tmp=getMap(mc,"size");
563      char* tmpSized=NULL;
564      if(tmp!=NULL){
565        map* tmpV=getMap(mc,"value");
566        tmpSized=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
567        memmove(tmpSized,tmpV->value,atoi(tmp->value)*sizeof(char));
568      }
569      if(mc!=NULL){
570        addMapToMap(&res->content,mc);
571      }
572      if(tmp!=NULL){
573        map* tmpV=getMap(res->content,"value");
574        free(tmpV->value);
575        tmpV->value=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
576        memmove(tmpV->value,tmpSized,atoi(tmp->value)*sizeof(char));
577        tmpV->value[atoi(tmp->value)]=0;
578        free(tmpSized);
579      }
580      res->next=dupMaps(&_cursor->next);
581    }
582    return res;
583  }
584
585  static void addMapsToMaps(maps** mo,maps* mi){
586    maps* tmp=mi;
587    maps* _cursor=*mo;
588    while(tmp!=NULL){
589      if(_cursor==NULL){
590        *mo=dupMaps(&mi);
591        (*mo)->next=NULL;
592      }
593      else{
594        while(_cursor->next!=NULL)
595          _cursor=_cursor->next;
596        _cursor->next=dupMaps(&tmp);
597      }
598      tmp=tmp->next;
599    }
600  }
601
602  static map* getMapArray(map* m,char* key,int index){
603    char tmp[1024];
604    if(index>0)
605      sprintf(tmp,"%s_%d",key,index);
606    else
607      sprintf(tmp,key);
608#ifdef DEBUG
609    fprintf(stderr,"** KEY %s\n",tmp);
610#endif
611    map* tmpMap=getMap(m,tmp);
612#ifdef DEBUG
613    if(tmpMap!=NULL)
614      dumpMap(tmpMap);
615#endif
616    return tmpMap;
617  }
618
619
620  static void setMapArray(map* m,char* key,int index,char* value){
621    char tmp[1024];
622    if(index>0)
623      sprintf(tmp,"%s_%d",key,index);
624    else
625      sprintf(tmp,key);
626    map* tmpSize=getMapArray(m,"size",index);
627    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
628#ifdef DEBUG
629      fprintf(stderr,"%s\n",tmpSize->value);
630#endif
631      map* ptr=getMapOrFill(m,tmp,"");
632      free(ptr->value);
633      ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
634      memcpy(ptr->value,value,atoi(tmpSize->value)); 
635    }
636    else
637      addToMap(m,tmp,value);
638  }
639
640  static map* getMapType(map* mt){
641    map* tmap=getMap(mt,"mimeType");
642    if(tmap==NULL){
643      tmap=getMap(mt,"dataType");
644      if(tmap==NULL){
645        tmap=getMap(mt,"CRS");
646      }
647    }
648#ifdef DEBUG
649        dumpMap(tmap);
650#endif
651    return tmap;
652  }
653
654  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
655    maps* tmp=mi;   
656    maps* _cursor=getMaps(*mo,tmp->name);
657
658    if(_cursor==NULL)
659      return -1;
660
661    map* tmpLength=getMap(_cursor->content,"length");
662    char tmpLen[10];
663    int len=1;
664    if(tmpLength!=NULL){
665      len=atoi(tmpLength->value);
666    }
667
668    map* tmpValI=getMap(tmp->content,"value");
669    char *tmpV[8]={
670      "size",
671      "value",
672      "uom",
673      "Reference",
674      "xlink:href",
675      typ,
676      "schema",
677      "encoding"
678    };
679    sprintf(tmpLen,"%d",len+1);
680    addToMap(_cursor->content,"length",tmpLen);
681    int i=0;
682    map* tmpSizeI=getMap(tmp->content,tmpV[i]);
683    for(0;i<8;i++){
684      map* tmpVI=getMap(tmp->content,tmpV[i]);
685      if(tmpVI!=NULL){
686#ifdef DEBUG
687        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
688#endif
689        if(i<5)
690          setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
691        else
692          if(strncasecmp(tmpV[5],"mimeType",8)==0)
693            setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
694      }
695    }
696   
697    addToMap(_cursor->content,"isArray","true");
698    return 0;
699  }
700
701  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
702    maps* _tmpm=getMaps(m,key);
703    if(_tmpm!=NULL){
704      map* _ztmpm=getMap(_tmpm->content,subkey);
705      if(_ztmpm!=NULL){
706        if(_ztmpm->value!=NULL)
707          free(_ztmpm->value);
708        _ztmpm->value=strdup(value);
709      }else{
710        addToMap(_tmpm->content,subkey,value);
711      }
712    }else{
713      maps *tmp=(maps*)malloc(MAPS_SIZE);
714      tmp->name=strdup(key);
715      tmp->content=createMap(subkey,value);
716      tmp->next=NULL;
717      addMapsToMaps(&m,tmp);
718      freeMaps(&tmp);
719      free(tmp);
720    }
721  }
722
723
724  static void dumpElements(elements* e){
725    elements* tmp=e;
726    while(tmp!=NULL){
727      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
728      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
729      dumpMap(tmp->content);
730      fprintf(stderr," > METADATA [%s]\n",tmp->name);
731      dumpMap(tmp->metadata);
732      fprintf(stderr," > FORMAT [%s]\n",tmp->format);
733      iotype* tmpio=tmp->defaults;
734      int ioc=0;
735      while(tmpio!=NULL){
736        fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
737        dumpMap(tmpio->content);
738        tmpio=tmpio->next;
739        ioc++;
740      }
741      tmpio=tmp->supported;
742      ioc=0;
743      while(tmpio!=NULL){
744        fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
745        dumpMap(tmpio->content);
746        tmpio=tmpio->next;
747        ioc++;
748      }
749      fprintf(stderr,"------------------\n");
750      tmp=tmp->next;
751    }
752  }
753
754  static elements* dupElements(elements* e){
755    elements* cursor=e;
756    elements* tmp=NULL;
757    if(cursor!=NULL){
758#ifdef DEBUG
759      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
760      dumpElements(e);
761      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
762#endif
763      tmp=(elements*)malloc(ELEMENTS_SIZE);
764      tmp->name=strdup(e->name);
765      tmp->content=NULL;
766      addMapToMap(&tmp->content,e->content);
767      tmp->metadata=NULL;
768      addMapToMap(&tmp->metadata,e->metadata);
769      tmp->format=strdup(e->format);
770      if(e->defaults!=NULL){
771        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
772        tmp->defaults->content=NULL;
773        addMapToMap(&tmp->defaults->content,e->defaults->content);
774        tmp->defaults->next=NULL;
775#ifdef DEBUG
776        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
777        dumpMap(tmp->defaults->content);
778#endif
779      }else
780        tmp->defaults=NULL;
781      if(e->supported!=NULL){
782        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
783        tmp->supported->content=NULL;
784        addMapToMap(&tmp->supported->content,e->supported->content);
785        tmp->supported->next=NULL;
786        iotype *tmp2=e->supported->next;
787        while(tmp2!=NULL){
788          addMapToIoType(&tmp->supported,tmp2->content);
789#ifdef DEBUG
790          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
791          dumpMap(tmp->defaults->content);
792#endif
793          tmp2=tmp2->next;
794        }
795      }
796      else
797        tmp->supported=NULL;
798      tmp->next=dupElements(cursor->next);
799    }
800    return tmp;
801  }
802
803  static void addToElements(elements** m,elements* e){
804    elements* tmp=e;
805    if(*m==NULL){
806      *m=dupElements(tmp);
807    }else{
808      addToElements(&(*m)->next,tmp);
809    }
810  }
811
812  static void dumpService(service* s){
813    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
814    if(s->content!=NULL){
815      fprintf(stderr,"CONTENT MAP\n");
816      dumpMap(s->content);
817      fprintf(stderr,"CONTENT METADATA\n");
818      dumpMap(s->metadata);
819    }
820    if(s->inputs!=NULL){
821      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
822      dumpElements(s->inputs);
823    }
824    if(s->outputs!=NULL){
825      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
826      dumpElements(s->outputs);
827    }
828    fprintf(stderr,"++++++++++++++++++\n");
829  }
830
831  static void mapsToCharXXX(maps* m,char*** c){
832    maps* tm=m;
833    int i=0;
834    int j=0;
835    char tmp[10][30][1024];
836    memset(tmp,0,1024*10*10);
837    while(tm!=NULL){
838      if(i>=10)
839        break;
840      strcpy(tmp[i][j],"name");
841      j++;
842      strcpy(tmp[i][j],tm->name);
843      j++;
844      map* tc=tm->content;
845      while(tc!=NULL){
846        if(j>=30)
847          break;
848        strcpy(tmp[i][j],tc->name);
849        j++;
850        strcpy(tmp[i][j],tc->value);
851        j++;
852        tc=tc->next;
853      }
854      tm=tm->next;
855      j=0;
856      i++;
857    }
858    memcpy(c,tmp,10*10*1024);
859  }
860
861  static void charxxxToMaps(char*** c,maps**m){
862    maps* trorf=*m;
863    int i,j;
864    char tmp[10][30][1024];
865    memcpy(tmp,c,10*30*1024);
866    for(i=0;i<10;i++){
867      if(strlen(tmp[i][1])==0)
868        break;
869      trorf->name=tmp[i][1];
870      trorf->content=NULL;
871      trorf->next=NULL;
872      for(j=2;j<29;j+=2){
873        if(strlen(tmp[i][j+1])==0)
874          break;
875        if(trorf->content==NULL)
876          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
877        else
878          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
879      }
880      trorf=trorf->next;
881    }
882    m=&trorf;
883  }
884
885#ifdef __cplusplus
886}
887#endif
888
889#endif
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png