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

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

Print specific headers when a [headers] section was added to the main.cfg file (can add headers such as X-Powered-By for instance). Handle reading file in cache as binary (solving file size not corresponding for text files).

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