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

Last change on this file since 552 was 550, checked in by djay, 10 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
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#define zSleep Sleep
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}
55#else
56#define zStrdup strdup
57#define zMkdir mkdir
58#define zOpen open
59#define zWrite write
60#define zSleep sleep
61#define zGettimeofday gettimeofday
62#define ztimeval timeval
63#endif
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69#ifdef WIN32
70#ifdef USE_MS
71#include <mapserver.h>
72#endif
73#endif
74#include <stdlib.h>
75#include <ctype.h>
76#include <stdio.h>
77#include <string.h>
78#ifndef WIN32
79#ifndef bool
80#define bool int
81#endif
82#ifndef true
83#define true 1
84#define false -1
85#endif
86#endif
87
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
93
94#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
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*)
99
100#define SHMSZ     27
101
102#include "version.h"
103
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
111  /**
112   * \struct map
113   * \brief KVP linked list
114   *
115   * Deal with WPS KVP (name,value).
116   * A map is defined as:
117   *  - name : a key,
118   *  - value: a value,
119   *  - next : a pointer to the next map if any.
120   */
121  typedef struct map{
122    char* name;
123    char* value;
124    struct map* next;
125  } map;
126
127#ifdef WIN32
128#define NULLMAP ((map*) 0)
129#else
130#define NULLMAP NULL
131#endif
132
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   */
152  static void _dumpMap(map* t){
153    if(t!=NULL){
154      fprintf(stderr,"%s: %s\n",t->name,t->value);
155      fflush(stderr);
156        }else{
157      fprintf(stderr,"NULL\n");
158      fflush(stderr);
159    }
160  }
161
162  static void dumpMap(map* t){
163    map* tmp=t;
164    while(tmp!=NULL){
165      _dumpMap(tmp);
166      tmp=tmp->next;
167    }
168  }
169
170  static void dumpMapToFile(map* t,FILE* file){
171    map* tmp=t;
172    while(tmp!=NULL){
173#ifdef DEBUG
174      fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
175#endif
176      fprintf(file,"%s = %s\n",tmp->name,tmp->value);
177      tmp=tmp->next;
178    }
179  }
180
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
190  static void dumpMapsToFile(maps* m,char* file_path){
191    FILE* file=fopen(file_path,"w");
192    maps* tmp=m;
193    if(tmp!=NULL){
194      fprintf(file,"[%s]\n",tmp->name);
195      dumpMapToFile(tmp->content,file);
196      fflush(file);
197    }
198    fclose(file);
199  }
200
201  static map* createMap(const char* name,const char* value){
202    map* tmp=(map *)malloc(MAP_SIZE);
203    tmp->name=zStrdup(name);
204    tmp->value=zStrdup(value);
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   
219  static bool hasKey(map* m,const char *key){
220    map* tmp=m;
221    while(tmp!=NULL){
222      if(strcasecmp(tmp->name,key)==0)
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
232  static maps* getMaps(maps* m,const char *key){
233    maps* tmp=m;
234    while(tmp!=NULL){
235      if(strcasecmp(tmp->name,key)==0){
236        return tmp;
237      }
238      tmp=tmp->next;
239    }
240    return NULL;
241  }
242
243  static map* getMap(map* m,const char *key){
244    map* tmp=m;
245    while(tmp!=NULL){
246      if(strcasecmp(tmp->name,key)==0){
247        return tmp;
248      }
249      tmp=tmp->next;
250    }
251    return NULL;
252  }
253
254
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
266  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
267    maps* _tmpm=getMaps(m,key);
268    if(_tmpm!=NULL){
269      map* _ztmpm=getMap(_tmpm->content,subkey);
270      return _ztmpm;
271    }
272    else return NULL;
273  }
274
275
276  static void freeMap(map** mo){
277    map* _cursor=*mo;
278    if(_cursor!=NULL){
279#ifdef DEBUG
280      fprintf(stderr,"freeMap\n");
281#endif
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
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  }
308
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   */
318  typedef struct iotype{
319    struct map* content;
320    struct iotype* next;
321  } iotype;
322
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   */
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
360  static bool hasElement(elements* e,const char* key){
361    elements* tmp=e;
362    while(tmp!=NULL){
363      if(strcasecmp(key,tmp->name)==0)
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){
373      if(strcasecmp(tmp->name,key)==0)
374        return tmp;
375      tmp=tmp->next;
376    }
377    return NULL;
378  }
379
380
381  static void freeIOType(iotype** i){
382    iotype* _cursor=*i;
383    if(_cursor!=NULL){
384      if(_cursor->next!=NULL){
385        freeIOType(&_cursor->next);
386        free(_cursor->next);
387      }
388      freeMap(&_cursor->content);
389      free(_cursor->content);
390    }
391  }
392
393  static void freeElements(elements** e){
394    elements* tmp=*e;
395    if(tmp!=NULL){
396      if(tmp->name!=NULL)
397        free(tmp->name);
398      freeMap(&tmp->content);
399      if(tmp->content!=NULL)
400        free(tmp->content);
401      freeMap(&tmp->metadata);
402      if(tmp->metadata!=NULL)
403        free(tmp->metadata);
404      if(tmp->format!=NULL)
405        free(tmp->format);
406      freeIOType(&tmp->defaults);
407      if(tmp->defaults!=NULL)
408        free(tmp->defaults);
409      freeIOType(&tmp->supported);
410      if(tmp->supported!=NULL){
411        free(tmp->supported);
412      }
413      freeElements(&tmp->next);
414      if(tmp->next!=NULL)
415        free(tmp->next);
416    }
417  }
418
419  static void freeService(service** s){
420    service* tmp=*s;
421    if(tmp!=NULL){
422      if(tmp->name!=NULL)
423        free(tmp->name);
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
439  static void addToMap(map* m,const char* n,const char* v){
440    if(hasKey(m,n)==false){
441      map* _cursor=m;
442      while(_cursor->next!=NULL){
443        _cursor=_cursor->next;
444      }
445      _cursor->next=createMap(n,v);
446    }
447    else{
448      map *tmp=getMap(m,n);
449      if(tmp->value!=NULL)
450        free(tmp->value);
451      tmp->value=zStrdup(v);
452    }
453  }
454
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
475  static void addMapToMap(map** mo,map* mi){
476    map* tmp=mi;
477    map* _cursor=*mo;
478    while(tmp!=NULL){
479      if(_cursor==NULL){
480        *mo=createMap(tmp->name,tmp->value);
481        (*mo)->next=NULL;
482      }
483      else{
484#ifdef DEBUG
485        fprintf(stderr,"_CURSOR\n");
486        dumpMap(_cursor);
487#endif
488        while(_cursor->next!=NULL)
489          _cursor=_cursor->next;
490        map* tmp1=getMap(*mo,tmp->name);
491        if(tmp1==NULL){
492          _cursor->next=createMap(tmp->name,tmp->value);
493        }
494        else{
495          addToMap(*mo,tmp->name,tmp->value);
496        }
497      }
498      _cursor=*mo;
499      tmp=tmp->next;
500#ifdef DEBUG
501      fprintf(stderr,"MO\n");
502      dumpMap(*mo);
503#endif
504    }
505  }
506
507  static void addMapToIoType(iotype** io,map* mi){
508    iotype* tmp=*io;
509    while(tmp->next!=NULL){
510      tmp=tmp->next;
511    }
512    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
513    tmp->next->content=NULL;
514    addMapToMap(&tmp->next->content,mi);
515    tmp->next->next=NULL;
516  }
517
518  static map* getMapOrFill(map** m,const char *key,const char* value){
519    map* tmp=*m;
520    map* tmpMap=getMap(tmp,key);
521    if(tmpMap==NULL){
522      if(tmp!=NULL){
523        addToMap((*m),key,value);
524      }
525      else
526        (*m)=createMap(key,value);
527      tmpMap=getMap(*m,key);
528    }
529    return tmpMap;
530  }
531
532  static bool contains(map* m,map* i){
533    while(i!=NULL){     
534      if(strcasecmp(i->name,"value")!=0 &&
535         strcasecmp(i->name,"xlink:href")!=0 &&
536         strcasecmp(i->name,"useMapServer")!=0 &&
537         strcasecmp(i->name,"asReference")!=0){
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  }
547
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
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
611  static maps* dupMaps(maps** mo){
612    maps* _cursor=*mo;
613    maps* res=NULL;
614    if(_cursor!=NULL){
615      res=(maps*)malloc(MAPS_SIZE);
616      res->name=zStrdup(_cursor->name);
617      res->content=NULL;
618      res->next=NULL;
619      map* mc=_cursor->content;
620      if(mc!=NULL){
621        addMapToMap(&res->content,mc);
622        loadMapBinaries(&res->content,mc);
623      }
624      res->next=dupMaps(&_cursor->next);
625    }
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;
639        maps* tmp1=getMaps(*mo,tmp->name);
640        if(tmp1==NULL)
641          _cursor->next=dupMaps(&tmp);
642        else
643          addMapToMap(&tmp1->content,tmp->content);
644        _cursor=*mo;
645      }
646      tmp=tmp->next;
647    }
648  }
649
650  static map* getMapArray(map* m,const char* key,int index){
651    char tmp[1024];
652    if(index>0)
653      sprintf(tmp,"%s_%d",key,index);
654    else
655      sprintf(tmp,"%s",key);
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  }
666
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
673      sprintf(tmp,"%s",key);
674    map* tmpSize=getMapArray(m,"size",index);
675    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
676#ifdef DEBUG
677      fprintf(stderr,"%s\n",tmpSize->value);
678#endif
679      map* ptr=getMapOrFill(&m,tmp,(char *)"");
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){
689    map* tmap=getMap(mt,(char *)"mimeType");
690    if(tmap==NULL){
691      tmap=getMap(mt,"dataType");
692      if(tmap==NULL){
693        tmap=getMap(mt,"CRS");
694      }
695    }
696#ifdef DEBUG
697        dumpMap(tmap);
698#endif
699    return tmap;
700  }
701
702  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
703    maps* tmp=mi;   
704    maps* _cursor=getMaps(*mo,tmp->name);
705
706    if(_cursor==NULL)
707      return -1;
708
709    map* tmpLength=getMap(_cursor->content,"length");
710    char tmpLen[10];
711    int len=1;
712    if(tmpLength!=NULL){
713      len=atoi(tmpLength->value);
714    }
715
716    char *tmpV[11]={
717      (char*)"size",
718      (char*)"value",
719      (char*)"uom",
720      (char*)"Reference",
721      (char*)"cache_file",
722      (char*)"fmimeType",
723      (char*)"xlink:href",
724      typ,
725      (char*)"schema",
726      (char*)"encoding",
727      (char*)"isCached"
728    };
729    sprintf(tmpLen,"%d",len+1);
730    addToMap(_cursor->content,"length",tmpLen);
731    int i=0;
732    for(i=0;i<11;i++){
733      map* tmpVI=getMap(tmp->content,tmpV[i]);
734      if(tmpVI!=NULL){
735#ifdef DEBUG
736        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
737#endif
738        if(i<7)
739          setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
740        else
741          if(strncasecmp(tmpV[7],"mimeType",8)==0)
742            setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
743      }
744    }
745   
746    addToMap(_cursor->content,"isArray","true");
747    return 0;
748  }
749
750  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
751    maps* _tmpm=getMaps(m,key);
752    if(_tmpm!=NULL){
753      map* _ztmpm=getMap(_tmpm->content,subkey);
754      if(_ztmpm!=NULL){
755        if(_ztmpm->value!=NULL)
756          free(_ztmpm->value);
757        _ztmpm->value=zStrdup(value);
758      }else{
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);
766      }
767    }else{
768      maps *tmp=(maps*)malloc(MAPS_SIZE);
769      tmp->name=zStrdup(key);
770      tmp->content=createMap(subkey,value);
771      tmp->next=NULL;
772      addMapsToMaps(&m,tmp);
773      freeMaps(&tmp);
774      free(tmp);
775    }
776  }
777
778
779  static void dumpElements(elements* e){
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
809  static void dumpElementsAsYAML(elements* e){
810    elements* tmp=e;
811    int i;
812    while(tmp!=NULL){
813      for(i=0;i<2;i++)
814        fprintf(stderr," ");
815      fprintf(stderr,"%s:\n",tmp->name);
816      map* mcurs=tmp->content;
817      while(mcurs!=NULL){
818        for(i=0;i<4;i++)
819          fprintf(stderr," ");
820        _dumpMap(mcurs);
821        mcurs=mcurs->next;
822      }
823      mcurs=tmp->metadata;
824      if(mcurs!=NULL){
825        for(i=0;i<4;i++)
826          fprintf(stderr," ");
827        fprintf(stderr,"MetaData:\n");
828        while(mcurs!=NULL){
829          for(i=0;i<6;i++)
830            fprintf(stderr," ");
831          _dumpMap(mcurs);
832          mcurs=mcurs->next;
833        }
834      }
835      for(i=0;i<4;i++)
836        fprintf(stderr," ");
837      fprintf(stderr,"%s:\n",tmp->format);
838      iotype* tmpio=tmp->defaults;
839      int ioc=0;
840      while(tmpio!=NULL){
841        for(i=0;i<6;i++)
842          fprintf(stderr," ");
843        fprintf(stderr,"default:\n");
844        mcurs=tmpio->content;
845        while(mcurs!=NULL){
846          for(i=0;i<8;i++)
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){
860        for(i=0;i<6;i++)
861          fprintf(stderr," ");
862        fprintf(stderr,"supported:\n");
863        mcurs=tmpio->content;
864        while(mcurs!=NULL){
865          for(i=0;i<8;i++)
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
881  static elements* dupElements(elements* e){
882    elements* cursor=e;
883    elements* tmp=NULL;
884    if(cursor!=NULL){
885#ifdef DEBUG
886      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
887      dumpElements(e);
888      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
889#endif
890      tmp=(elements*)malloc(ELEMENTS_SIZE);
891      tmp->name=zStrdup(e->name);
892      tmp->content=NULL;
893      addMapToMap(&tmp->content,e->content);
894      tmp->metadata=NULL;
895      addMapToMap(&tmp->metadata,e->metadata);
896      tmp->format=zStrdup(e->format);
897      if(e->defaults!=NULL){
898        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
899        tmp->defaults->content=NULL;
900        addMapToMap(&tmp->defaults->content,e->defaults->content);
901        tmp->defaults->next=NULL;
902#ifdef DEBUG
903        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
904        dumpMap(tmp->defaults->content);
905#endif
906      }else
907        tmp->defaults=NULL;
908      if(e->supported!=NULL){
909        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
910        tmp->supported->content=NULL;
911        addMapToMap(&tmp->supported->content,e->supported->content);
912        tmp->supported->next=NULL;
913        iotype *tmp2=e->supported->next;
914        while(tmp2!=NULL){
915          addMapToIoType(&tmp->supported,tmp2->content);
916#ifdef DEBUG
917          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
918          dumpMap(tmp->defaults->content);
919#endif
920          tmp2=tmp2->next;
921        }
922      }
923      else
924        tmp->supported=NULL;
925      tmp->next=dupElements(cursor->next);
926    }
927    return tmp;
928  }
929
930  static void addToElements(elements** m,elements* e){
931    elements* tmp=e;
932    if(*m==NULL){
933      *m=dupElements(tmp);
934    }else{
935      addToElements(&(*m)->next,tmp);
936    }
937  }
938
939  static void dumpService(service* s){
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
958  static void dumpServiceAsYAML(service* s){
959    int i;
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){
968          for(i=0;i<2;i++)
969            fprintf(stderr," ");
970          _dumpMap(mcurs);
971          mcurs=mcurs->next;
972        }
973      }
974    }
975    if(s->inputs!=NULL){
976      fprintf(stderr,"\ninputs:\n");
977      dumpElementsAsYAML(s->inputs);
978    }
979    if(s->outputs!=NULL){
980      fprintf(stderr,"\noutputs:\n");
981      dumpElementsAsYAML(s->outputs);
982    }
983  }
984
985  static void mapsToCharXXX(maps* m,char*** c){
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
1015  static void charxxxToMaps(char*** c,maps**m){
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
1032          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
1033      }
1034      trorf=trorf->next;
1035    }
1036    m=&trorf;
1037  }
1038
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){
1076              int j;
1077              for(j=0;j<atoi(hasLength->value);j++){
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
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