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

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

Fix issue with language gesture on Ubuntu platforms.

  • 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    int i;
736    while(tmp!=NULL){
737      for(i=0;i<2;i++)
738        fprintf(stderr," ");
739      fprintf(stderr,"%s:\n",tmp->name);
740      map* mcurs=tmp->content;
741      while(mcurs!=NULL){
742        for(i=0;i<4;i++)
743          fprintf(stderr," ");
744        _dumpMap(mcurs);
745        mcurs=mcurs->next;
746      }
747      mcurs=tmp->metadata;
748      if(mcurs!=NULL){
749        for(i=0;i<4;i++)
750          fprintf(stderr," ");
751        fprintf(stderr,"MetaData:\n");
752        while(mcurs!=NULL){
753          for(i=0;i<6;i++)
754            fprintf(stderr," ");
755          _dumpMap(mcurs);
756          mcurs=mcurs->next;
757        }
758      }
759      for(i=0;i<4;i++)
760        fprintf(stderr," ");
761      fprintf(stderr,"%s:\n",tmp->format);
762      iotype* tmpio=tmp->defaults;
763      int ioc=0;
764      while(tmpio!=NULL){
765        for(i=0;i<6;i++)
766          fprintf(stderr," ");
767        fprintf(stderr,"default:\n");
768        mcurs=tmpio->content;
769        while(mcurs!=NULL){
770          for(i=0;i<8;i++)
771            fprintf(stderr," ");
772          if(strcasecmp(mcurs->name,"range")==0){
773            fprintf(stderr,"range: \"%s\"\n",mcurs->value);
774          }else
775            _dumpMap(mcurs);
776          mcurs=mcurs->next;
777        }
778        tmpio=tmpio->next;
779        ioc++;
780      }
781      tmpio=tmp->supported;
782      ioc=0;
783      while(tmpio!=NULL){
784        for(i=0;i<6;i++)
785          fprintf(stderr," ");
786        fprintf(stderr,"supported:\n");
787        mcurs=tmpio->content;
788        while(mcurs!=NULL){
789          for(i=0;i<8;i++)
790            fprintf(stderr," ");
791          if(strcasecmp(mcurs->name,"range")==0){
792            fprintf(stderr,"range: \"%s\"\n",mcurs->value);
793          }else
794            _dumpMap(mcurs);
795          mcurs=mcurs->next;
796        }
797        tmpio=tmpio->next;
798        ioc++;
799      }
800      tmp=tmp->next;
801    }
802  }
803
804
805  static elements* dupElements(elements* e){
806    elements* cursor=e;
807    elements* tmp=NULL;
808    if(cursor!=NULL){
809#ifdef DEBUG
810      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
811      dumpElements(e);
812      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
813#endif
814      tmp=(elements*)malloc(ELEMENTS_SIZE);
815      tmp->name=zStrdup(e->name);
816      tmp->content=NULL;
817      addMapToMap(&tmp->content,e->content);
818      tmp->metadata=NULL;
819      addMapToMap(&tmp->metadata,e->metadata);
820      tmp->format=zStrdup(e->format);
821      if(e->defaults!=NULL){
822        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
823        tmp->defaults->content=NULL;
824        addMapToMap(&tmp->defaults->content,e->defaults->content);
825        tmp->defaults->next=NULL;
826#ifdef DEBUG
827        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
828        dumpMap(tmp->defaults->content);
829#endif
830      }else
831        tmp->defaults=NULL;
832      if(e->supported!=NULL){
833        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
834        tmp->supported->content=NULL;
835        addMapToMap(&tmp->supported->content,e->supported->content);
836        tmp->supported->next=NULL;
837        iotype *tmp2=e->supported->next;
838        while(tmp2!=NULL){
839          addMapToIoType(&tmp->supported,tmp2->content);
840#ifdef DEBUG
841          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
842          dumpMap(tmp->defaults->content);
843#endif
844          tmp2=tmp2->next;
845        }
846      }
847      else
848        tmp->supported=NULL;
849      tmp->next=dupElements(cursor->next);
850    }
851    return tmp;
852  }
853
854  static void addToElements(elements** m,elements* e){
855    elements* tmp=e;
856    if(*m==NULL){
857      *m=dupElements(tmp);
858    }else{
859      addToElements(&(*m)->next,tmp);
860    }
861  }
862
863  static void dumpService(service* s){
864    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
865    if(s->content!=NULL){
866      fprintf(stderr,"CONTENT MAP\n");
867      dumpMap(s->content);
868      fprintf(stderr,"CONTENT METADATA\n");
869      dumpMap(s->metadata);
870    }
871    if(s->inputs!=NULL){
872      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
873      dumpElements(s->inputs);
874    }
875    if(s->outputs!=NULL){
876      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
877      dumpElements(s->outputs);
878    }
879    fprintf(stderr,"++++++++++++++++++\n");
880  }
881
882  static void dumpServiceAsYAML(service* s){
883    int level=0;
884    int i;
885    fprintf(stderr,"# %s\n\n",s->name);
886    if(s->content!=NULL){
887      map* mcurs=s->content;
888      dumpMap(mcurs);
889      mcurs=s->metadata;
890      if(mcurs!=NULL){
891        fprintf(stderr,"MetaData:\n");
892        while(mcurs!=NULL){
893          for(i=0;i<2;i++)
894            fprintf(stderr," ");
895          _dumpMap(mcurs);
896          mcurs=mcurs->next;
897        }
898      }
899    }
900    if(s->inputs!=NULL){
901      fprintf(stderr,"\ninputs:\n",s->name);
902      dumpElementsAsYAML(s->inputs);
903    }
904    if(s->outputs!=NULL){
905      fprintf(stderr,"\noutputs:\n",s->name);
906      dumpElementsAsYAML(s->outputs);
907    }
908  }
909
910  static void mapsToCharXXX(maps* m,char*** c){
911    maps* tm=m;
912    int i=0;
913    int j=0;
914    char tmp[10][30][1024];
915    memset(tmp,0,1024*10*10);
916    while(tm!=NULL){
917      if(i>=10)
918        break;
919      strcpy(tmp[i][j],"name");
920      j++;
921      strcpy(tmp[i][j],tm->name);
922      j++;
923      map* tc=tm->content;
924      while(tc!=NULL){
925        if(j>=30)
926          break;
927        strcpy(tmp[i][j],tc->name);
928        j++;
929        strcpy(tmp[i][j],tc->value);
930        j++;
931        tc=tc->next;
932      }
933      tm=tm->next;
934      j=0;
935      i++;
936    }
937    memcpy(c,tmp,10*10*1024);
938  }
939
940  static void charxxxToMaps(char*** c,maps**m){
941    maps* trorf=*m;
942    int i,j;
943    char tmp[10][30][1024];
944    memcpy(tmp,c,10*30*1024);
945    for(i=0;i<10;i++){
946      if(strlen(tmp[i][1])==0)
947        break;
948      trorf->name=tmp[i][1];
949      trorf->content=NULL;
950      trorf->next=NULL;
951      for(j=2;j<29;j+=2){
952        if(strlen(tmp[i][j+1])==0)
953          break;
954        if(trorf->content==NULL)
955          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
956        else
957          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
958      }
959      trorf=trorf->next;
960    }
961    m=&trorf;
962  }
963
964#ifdef WIN32
965  extern char *url_encode(char *);
966
967  static char* getMapsAsKVP(maps* m,int length,int type){
968    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
969    char *dataInputsKVPi=NULL;
970    maps* curs=m;
971    int i=0;
972    while(curs!=NULL){
973      map *inRequest=getMap(curs->content,"inRequest");
974      map *hasLength=getMap(curs->content,"length");
975      if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
976         inRequest==NULL){
977        if(i==0)
978          if(type==0){
979            sprintf(dataInputsKVP,"%s=",curs->name);
980            if(hasLength!=NULL){
981              dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
982              sprintf(dataInputsKVPi,"%s=",curs->name);
983            }
984          }
985          else
986            sprintf(dataInputsKVP,"%s",curs->name);
987        else{
988          char *temp=zStrdup(dataInputsKVP);
989          if(type==0)
990            sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
991          else
992            sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
993        }
994        map* icurs=curs->content;
995        if(type==0){
996          char *temp=zStrdup(dataInputsKVP);
997          if(getMap(curs->content,"xlink:href")!=NULL)
998            sprintf(dataInputsKVP,"%sReference",temp);
999          else{
1000            if(hasLength!=NULL){
1001              int j;
1002              for(j=0;j<atoi(hasLength->value);j++){
1003                map* tmp0=getMapArray(curs->content,"value",j);
1004                if(j==0)
1005                  free(temp);
1006                temp=zStrdup(dataInputsKVP);
1007                if(j==0)
1008                  sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
1009                else
1010                  sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
1011              }
1012            }
1013            else
1014              sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
1015          }
1016          free(temp);
1017        }
1018        while(icurs!=NULL){
1019          if(strncasecmp(icurs->name,"value",5)!=0 &&
1020             strncasecmp(icurs->name,"mimeType_",9)!=0 &&
1021             strncasecmp(icurs->name,"dataType_",9)!=0 &&
1022             strncasecmp(icurs->name,"size",4)!=0 &&
1023             strncasecmp(icurs->name,"length",4)!=0 &&
1024             strncasecmp(icurs->name,"isArray",7)!=0 &&
1025             strcasecmp(icurs->name,"Reference")!=0 &&
1026             strcasecmp(icurs->name,"minOccurs")!=0 &&
1027             strcasecmp(icurs->name,"maxOccurs")!=0 &&
1028             strncasecmp(icurs->name,"fmimeType",9)!=0 &&
1029             strcasecmp(icurs->name,"inRequest")!=0){
1030            char *itemp=zStrdup(dataInputsKVP);
1031            if(strcasecmp(icurs->name,"xlink:href")!=0)
1032              sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
1033            else
1034              sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
1035            free(itemp);
1036          }
1037          icurs=icurs->next;
1038        }
1039      }
1040      curs=curs->next;
1041      i++;
1042    }
1043    return dataInputsKVP;
1044  }
1045#endif
1046
1047#ifdef __cplusplus
1048}
1049#endif
1050
1051#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