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

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

Fixing issue on Linux / Mac OS X about language gesture. Fixing strange issue in some services using MapServer? support on WIN32. Use the MapServer? nmake.opt to make sure to get all the definitions settled correctly.

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