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

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

Support metapath embedded in service name. Add support for accessing ZOO-Kernel path subdirectories for full list of available services. Fix issue #98.

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