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

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

Add the optional Ruby Language Support to the ZOO-Kernel with an API similar to the Python ZOO-API. Small rewrite of Python support. Fix issue #86 and #87. Add usid in [lenv] section, this value is used to generate an unique identifier based on time and the process identifier. This usid is now used to name the stored result or the mapfile generated. Remove *some* warning messages displayed at compilation time.

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