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

Last change on this file since 379 was 379, checked in by djay, 11 years ago

Fix handling of multiple outputs. Small fix to build with bleeding edge gcc. Add missing copyright in service_internal_ms.c/h. Better gesture of session data. Update HISTORY.txt content.

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