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

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

Add the optional YAML ZCFG support #4 and the zcfg2yaml converter. Return error messages that enable the service provider to quickly identify the root cause of errors due to configuration file syntax #90. Fix logic in addMapToMap #91. Enable multiple range definition using default and supported blocks. Add the lastest revision number in version.h (available from Python ZOO-API as zoo.VERSION).

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