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

Last change on this file since 446 was 446, checked in by djay, 10 years ago

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