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

Last change on this file since 550 was 550, checked in by djay, 9 years ago

Add otb2zcfg and OTB applications support without observer by now. Fix issue with maxOccurs and multiple downloaded value for the same input.

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