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

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

Remove leaks from DescribeProcess? and JavaScript? support. Fix wrong ulinet update on previous commit. Use the new updateStatus/setOutputValue functions as described in #88 from longProcess. Add default value for QREncode service in ZCFG. Fix name of profile service in the ZCFG file.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 24.2 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      if(_cursor->next!=NULL){
426        addToMap(_cursor->next,n,v);
427      }else
428        _cursor->next=createMap(n,v);
429    }
430    else{
431      map *tmp=getMap(m,n);
432      if(tmp->value!=NULL)
433        free(tmp->value);
434      tmp->value=zStrdup(v);
435    }
436  }
437
438  static void addMapToMap(map** mo,map* mi){
439    map* tmp=mi;
440    map* _cursor=*mo;
441    while(tmp!=NULL){
442      if(_cursor==NULL){
443        *mo=createMap(tmp->name,tmp->value);
444        (*mo)->next=NULL;
445      }
446      else{
447#ifdef DEBUG
448        fprintf(stderr,"_CURSOR\n");
449        dumpMap(_cursor);
450#endif
451        while(_cursor->next!=NULL)
452          _cursor=_cursor->next;
453        map* tmp1=getMap(*mo,tmp->name);
454        if(tmp1==NULL){
455          _cursor->next=createMap(tmp->name,tmp->value);
456        }
457        else{
458          addToMap(*mo,tmp->name,tmp->value);
459        }
460      }
461      _cursor=*mo;
462      tmp=tmp->next;
463#ifdef DEBUG
464      fprintf(stderr,"MO\n");
465      dumpMap(*mo);
466#endif
467    }
468  }
469
470  static void addMapToIoType(iotype** io,map* mi){
471    iotype* tmp=*io;
472    while(tmp->next!=NULL){
473      tmp=tmp->next;
474    }
475    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
476    tmp->next->content=NULL;
477    addMapToMap(&tmp->next->content,mi);
478    tmp->next->next=NULL;
479  }
480
481  static map* getMapOrFill(map** m,const char *key,char* value){
482    map* tmp=*m;
483    map* tmpMap=getMap(tmp,key);
484    if(tmpMap==NULL){
485      if(tmp!=NULL)
486        addToMap(*m,key,value);
487      else
488        (*m)=createMap(key,value);
489      tmpMap=getMap(*m,key);
490    }
491    return tmpMap;
492  }
493
494  static bool contains(map* m,map* i){
495    while(i!=NULL){     
496      if(strcasecmp(i->name,"value")!=0 &&
497         strcasecmp(i->name,"xlink:href")!=0 &&
498         strcasecmp(i->name,"useMapServer")!=0 &&
499         strcasecmp(i->name,"asReference")!=0){
500        map *tmp;
501        if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
502           strcasecmp(i->value,tmp->value)!=0)
503          return false;
504      }
505      i=i->next;
506    }
507    return true;
508  }
509
510  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
511    elements* cursor=e;
512    while(cursor!=NULL){
513      if(strcasecmp(cursor->name,name)==0){
514        if(contains(cursor->defaults->content,values)==true)
515          return cursor->defaults;
516        else{
517          iotype* tmp=cursor->supported;
518          while(tmp!=NULL){
519            if(contains(tmp->content,values)==true)
520              return tmp;           
521            tmp=tmp->next;
522          }
523        }
524      }
525      cursor=cursor->next;
526    }
527    return NULL;
528  }
529
530  static maps* dupMaps(maps** mo){
531    maps* _cursor=*mo;
532    maps* res=NULL;
533    if(_cursor!=NULL){
534      res=(maps*)malloc(MAPS_SIZE);
535      res->name=zStrdup(_cursor->name);
536      res->content=NULL;
537      res->next=NULL;
538      map* mc=_cursor->content;
539      map* tmp=getMap(mc,"size");
540      char* tmpSized=NULL;
541      if(tmp!=NULL){
542        map* tmpV=getMap(mc,"value");
543        tmpSized=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
544        memmove(tmpSized,tmpV->value,atoi(tmp->value)*sizeof(char));
545      }
546      if(mc!=NULL){
547        addMapToMap(&res->content,mc);
548      }
549      if(tmp!=NULL){
550        map* tmpV=getMap(res->content,"value");
551        free(tmpV->value);
552        tmpV->value=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
553        memmove(tmpV->value,tmpSized,atoi(tmp->value)*sizeof(char));
554        tmpV->value[atoi(tmp->value)]=0;
555        free(tmpSized);
556      }
557      res->next=dupMaps(&_cursor->next);
558    }
559    return res;
560  }
561
562  static void addMapsToMaps(maps** mo,maps* mi){
563    maps* tmp=mi;
564    maps* _cursor=*mo;
565    while(tmp!=NULL){
566      if(_cursor==NULL){
567        *mo=dupMaps(&mi);
568      }
569      else{
570        while(_cursor->next!=NULL)
571          _cursor=_cursor->next;
572        maps* tmp1=getMaps(*mo,tmp->name);
573        if(tmp1==NULL)
574          _cursor->next=dupMaps(&tmp);
575        else
576          addMapToMap(&tmp1->content,tmp->content);
577        _cursor=*mo;
578      }
579      tmp=tmp->next;
580    }
581  }
582
583  static map* getMapArray(map* m,char* key,int index){
584    char tmp[1024];
585    if(index>0)
586      sprintf(tmp,"%s_%d",key,index);
587    else
588      sprintf(tmp,"%s",key);
589#ifdef DEBUG
590    fprintf(stderr,"** KEY %s\n",tmp);
591#endif
592    map* tmpMap=getMap(m,tmp);
593#ifdef DEBUG
594    if(tmpMap!=NULL)
595      dumpMap(tmpMap);
596#endif
597    return tmpMap;
598  }
599
600
601  static void setMapArray(map* m,char* key,int index,char* value){
602    char tmp[1024];
603    if(index>0)
604      sprintf(tmp,"%s_%d",key,index);
605    else
606      sprintf(tmp,"%s",key);
607    map* tmpSize=getMapArray(m,(char*)"size",index);
608    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
609#ifdef DEBUG
610      fprintf(stderr,"%s\n",tmpSize->value);
611#endif
612      map* ptr=getMapOrFill(&m,tmp,(char *)"");
613      free(ptr->value);
614      ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
615      memcpy(ptr->value,value,atoi(tmpSize->value)); 
616    }
617    else
618      addToMap(m,tmp,value);
619  }
620
621  static map* getMapType(map* mt){
622    map* tmap=getMap(mt,(char *)"mimeType");
623    if(tmap==NULL){
624      tmap=getMap(mt,"dataType");
625      if(tmap==NULL){
626        tmap=getMap(mt,"CRS");
627      }
628    }
629#ifdef DEBUG
630        dumpMap(tmap);
631#endif
632    return tmap;
633  }
634
635  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
636    maps* tmp=mi;   
637    maps* _cursor=getMaps(*mo,tmp->name);
638
639    if(_cursor==NULL)
640      return -1;
641
642    map* tmpLength=getMap(_cursor->content,"length");
643    char tmpLen[10];
644    int len=1;
645    if(tmpLength!=NULL){
646      len=atoi(tmpLength->value);
647    }
648
649    char *tmpV[8]={
650      (char*)"size",
651      (char*)"value",
652      (char*)"uom",
653      (char*)"Reference",
654      (char*)"xlink:href",
655      typ,
656      (char*)"schema",
657      (char*)"encoding"
658    };
659    sprintf(tmpLen,"%d",len+1);
660    addToMap(_cursor->content,"length",tmpLen);
661    int i=0;
662    map* tmpSizeI=getMap(tmp->content,tmpV[i]);
663    for(i=0;i<8;i++){
664      map* tmpVI=getMap(tmp->content,tmpV[i]);
665      if(tmpVI!=NULL){
666#ifdef DEBUG
667        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
668#endif
669        if(i<5)
670          setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
671        else
672          if(strncasecmp(tmpV[5],"mimeType",8)==0)
673            setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
674      }
675    }
676   
677    addToMap(_cursor->content,"isArray","true");
678    return 0;
679  }
680
681  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
682    maps* _tmpm=getMaps(m,key);
683    if(_tmpm!=NULL){
684      map* _ztmpm=getMap(_tmpm->content,subkey);
685      if(_ztmpm!=NULL){
686        if(_ztmpm->value!=NULL)
687          free(_ztmpm->value);
688        _ztmpm->value=zStrdup(value);
689      }else{
690        maps *tmp=(maps*)malloc(MAPS_SIZE);
691        tmp->name=zStrdup(key);
692        tmp->content=createMap(subkey,value);
693        tmp->next=NULL;
694        addMapsToMaps(&_tmpm,tmp);
695        freeMaps(&tmp);
696        free(tmp);
697      }
698    }else{
699      maps *tmp=(maps*)malloc(MAPS_SIZE);
700      tmp->name=zStrdup(key);
701      tmp->content=createMap(subkey,value);
702      tmp->next=NULL;
703      addMapsToMaps(&m,tmp);
704      freeMaps(&tmp);
705      free(tmp);
706    }
707  }
708
709
710  static void dumpElements(elements* e){
711    elements* tmp=e;
712    while(tmp!=NULL){
713      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
714      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
715      dumpMap(tmp->content);
716      fprintf(stderr," > METADATA [%s]\n",tmp->name);
717      dumpMap(tmp->metadata);
718      fprintf(stderr," > FORMAT [%s]\n",tmp->format);
719      iotype* tmpio=tmp->defaults;
720      int ioc=0;
721      while(tmpio!=NULL){
722        fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
723        dumpMap(tmpio->content);
724        tmpio=tmpio->next;
725        ioc++;
726      }
727      tmpio=tmp->supported;
728      ioc=0;
729      while(tmpio!=NULL){
730        fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
731        dumpMap(tmpio->content);
732        tmpio=tmpio->next;
733        ioc++;
734      }
735      fprintf(stderr,"------------------\n");
736      tmp=tmp->next;
737    }
738  }
739
740  static void dumpElementsAsYAML(elements* e){
741    elements* tmp=e;
742    int i;
743    while(tmp!=NULL){
744      for(i=0;i<2;i++)
745        fprintf(stderr," ");
746      fprintf(stderr,"%s:\n",tmp->name);
747      map* mcurs=tmp->content;
748      while(mcurs!=NULL){
749        for(i=0;i<4;i++)
750          fprintf(stderr," ");
751        _dumpMap(mcurs);
752        mcurs=mcurs->next;
753      }
754      mcurs=tmp->metadata;
755      if(mcurs!=NULL){
756        for(i=0;i<4;i++)
757          fprintf(stderr," ");
758        fprintf(stderr,"MetaData:\n");
759        while(mcurs!=NULL){
760          for(i=0;i<6;i++)
761            fprintf(stderr," ");
762          _dumpMap(mcurs);
763          mcurs=mcurs->next;
764        }
765      }
766      for(i=0;i<4;i++)
767        fprintf(stderr," ");
768      fprintf(stderr,"%s:\n",tmp->format);
769      iotype* tmpio=tmp->defaults;
770      int ioc=0;
771      while(tmpio!=NULL){
772        for(i=0;i<6;i++)
773          fprintf(stderr," ");
774        fprintf(stderr,"default:\n");
775        mcurs=tmpio->content;
776        while(mcurs!=NULL){
777          for(i=0;i<8;i++)
778            fprintf(stderr," ");
779          if(strcasecmp(mcurs->name,"range")==0){
780            fprintf(stderr,"range: \"%s\"\n",mcurs->value);
781          }else
782            _dumpMap(mcurs);
783          mcurs=mcurs->next;
784        }
785        tmpio=tmpio->next;
786        ioc++;
787      }
788      tmpio=tmp->supported;
789      ioc=0;
790      while(tmpio!=NULL){
791        for(i=0;i<6;i++)
792          fprintf(stderr," ");
793        fprintf(stderr,"supported:\n");
794        mcurs=tmpio->content;
795        while(mcurs!=NULL){
796          for(i=0;i<8;i++)
797            fprintf(stderr," ");
798          if(strcasecmp(mcurs->name,"range")==0){
799            fprintf(stderr,"range: \"%s\"\n",mcurs->value);
800          }else
801            _dumpMap(mcurs);
802          mcurs=mcurs->next;
803        }
804        tmpio=tmpio->next;
805        ioc++;
806      }
807      tmp=tmp->next;
808    }
809  }
810
811
812  static elements* dupElements(elements* e){
813    elements* cursor=e;
814    elements* tmp=NULL;
815    if(cursor!=NULL){
816#ifdef DEBUG
817      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
818      dumpElements(e);
819      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
820#endif
821      tmp=(elements*)malloc(ELEMENTS_SIZE);
822      tmp->name=zStrdup(e->name);
823      tmp->content=NULL;
824      addMapToMap(&tmp->content,e->content);
825      tmp->metadata=NULL;
826      addMapToMap(&tmp->metadata,e->metadata);
827      tmp->format=zStrdup(e->format);
828      if(e->defaults!=NULL){
829        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
830        tmp->defaults->content=NULL;
831        addMapToMap(&tmp->defaults->content,e->defaults->content);
832        tmp->defaults->next=NULL;
833#ifdef DEBUG
834        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
835        dumpMap(tmp->defaults->content);
836#endif
837      }else
838        tmp->defaults=NULL;
839      if(e->supported!=NULL){
840        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
841        tmp->supported->content=NULL;
842        addMapToMap(&tmp->supported->content,e->supported->content);
843        tmp->supported->next=NULL;
844        iotype *tmp2=e->supported->next;
845        while(tmp2!=NULL){
846          addMapToIoType(&tmp->supported,tmp2->content);
847#ifdef DEBUG
848          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
849          dumpMap(tmp->defaults->content);
850#endif
851          tmp2=tmp2->next;
852        }
853      }
854      else
855        tmp->supported=NULL;
856      tmp->next=dupElements(cursor->next);
857    }
858    return tmp;
859  }
860
861  static void addToElements(elements** m,elements* e){
862    elements* tmp=e;
863    if(*m==NULL){
864      *m=dupElements(tmp);
865    }else{
866      addToElements(&(*m)->next,tmp);
867    }
868  }
869
870  static void dumpService(service* s){
871    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
872    if(s->content!=NULL){
873      fprintf(stderr,"CONTENT MAP\n");
874      dumpMap(s->content);
875      fprintf(stderr,"CONTENT METADATA\n");
876      dumpMap(s->metadata);
877    }
878    if(s->inputs!=NULL){
879      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
880      dumpElements(s->inputs);
881    }
882    if(s->outputs!=NULL){
883      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
884      dumpElements(s->outputs);
885    }
886    fprintf(stderr,"++++++++++++++++++\n");
887  }
888
889  static void dumpServiceAsYAML(service* s){
890    int level=0;
891    int i;
892    fprintf(stderr,"# %s\n\n",s->name);
893    if(s->content!=NULL){
894      map* mcurs=s->content;
895      dumpMap(mcurs);
896      mcurs=s->metadata;
897      if(mcurs!=NULL){
898        fprintf(stderr,"MetaData:\n");
899        while(mcurs!=NULL){
900          for(i=0;i<2;i++)
901            fprintf(stderr," ");
902          _dumpMap(mcurs);
903          mcurs=mcurs->next;
904        }
905      }
906    }
907    if(s->inputs!=NULL){
908      fprintf(stderr,"\ninputs:\n",s->name);
909      dumpElementsAsYAML(s->inputs);
910    }
911    if(s->outputs!=NULL){
912      fprintf(stderr,"\noutputs:\n",s->name);
913      dumpElementsAsYAML(s->outputs);
914    }
915  }
916
917  static void mapsToCharXXX(maps* m,char*** c){
918    maps* tm=m;
919    int i=0;
920    int j=0;
921    char tmp[10][30][1024];
922    memset(tmp,0,1024*10*10);
923    while(tm!=NULL){
924      if(i>=10)
925        break;
926      strcpy(tmp[i][j],"name");
927      j++;
928      strcpy(tmp[i][j],tm->name);
929      j++;
930      map* tc=tm->content;
931      while(tc!=NULL){
932        if(j>=30)
933          break;
934        strcpy(tmp[i][j],tc->name);
935        j++;
936        strcpy(tmp[i][j],tc->value);
937        j++;
938        tc=tc->next;
939      }
940      tm=tm->next;
941      j=0;
942      i++;
943    }
944    memcpy(c,tmp,10*10*1024);
945  }
946
947  static void charxxxToMaps(char*** c,maps**m){
948    maps* trorf=*m;
949    int i,j;
950    char tmp[10][30][1024];
951    memcpy(tmp,c,10*30*1024);
952    for(i=0;i<10;i++){
953      if(strlen(tmp[i][1])==0)
954        break;
955      trorf->name=tmp[i][1];
956      trorf->content=NULL;
957      trorf->next=NULL;
958      for(j=2;j<29;j+=2){
959        if(strlen(tmp[i][j+1])==0)
960          break;
961        if(trorf->content==NULL)
962          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
963        else
964          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
965      }
966      trorf=trorf->next;
967    }
968    m=&trorf;
969  }
970
971#ifdef WIN32
972  extern char *url_encode(char *);
973
974  static char* getMapsAsKVP(maps* m,int length,int type){
975    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
976    char *dataInputsKVPi=NULL;
977    maps* curs=m;
978    int i=0;
979    while(curs!=NULL){
980      map *inRequest=getMap(curs->content,"inRequest");
981      map *hasLength=getMap(curs->content,"length");
982      if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
983         inRequest==NULL){
984        if(i==0)
985          if(type==0){
986            sprintf(dataInputsKVP,"%s=",curs->name);
987            if(hasLength!=NULL){
988              dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
989              sprintf(dataInputsKVPi,"%s=",curs->name);
990            }
991          }
992          else
993            sprintf(dataInputsKVP,"%s",curs->name);
994        else{
995          char *temp=zStrdup(dataInputsKVP);
996          if(type==0)
997            sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
998          else
999            sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
1000        }
1001        map* icurs=curs->content;
1002        if(type==0){
1003          char *temp=zStrdup(dataInputsKVP);
1004          if(getMap(curs->content,"xlink:href")!=NULL)
1005            sprintf(dataInputsKVP,"%sReference",temp);
1006          else{
1007            if(hasLength!=NULL){
1008              int j;
1009              for(j=0;j<atoi(hasLength->value);j++){
1010                map* tmp0=getMapArray(curs->content,"value",j);
1011                if(j==0)
1012                  free(temp);
1013                temp=zStrdup(dataInputsKVP);
1014                if(j==0)
1015                  sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
1016                else
1017                  sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
1018              }
1019            }
1020            else
1021              sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
1022          }
1023          free(temp);
1024        }
1025        while(icurs!=NULL){
1026          if(strncasecmp(icurs->name,"value",5)!=0 &&
1027             strncasecmp(icurs->name,"mimeType_",9)!=0 &&
1028             strncasecmp(icurs->name,"dataType_",9)!=0 &&
1029             strncasecmp(icurs->name,"size",4)!=0 &&
1030             strncasecmp(icurs->name,"length",4)!=0 &&
1031             strncasecmp(icurs->name,"isArray",7)!=0 &&
1032             strcasecmp(icurs->name,"Reference")!=0 &&
1033             strcasecmp(icurs->name,"minOccurs")!=0 &&
1034             strcasecmp(icurs->name,"maxOccurs")!=0 &&
1035             strncasecmp(icurs->name,"fmimeType",9)!=0 &&
1036             strcasecmp(icurs->name,"inRequest")!=0){
1037            char *itemp=zStrdup(dataInputsKVP);
1038            if(strcasecmp(icurs->name,"xlink:href")!=0)
1039              sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
1040            else
1041              sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
1042            free(itemp);
1043          }
1044          icurs=icurs->next;
1045        }
1046      }
1047      curs=curs->next;
1048      i++;
1049    }
1050    return dataInputsKVP;
1051  }
1052#endif
1053
1054#ifdef __cplusplus
1055}
1056#endif
1057
1058#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