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

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

Dumping final file fix. Add missing functions definition.

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