source: branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service.h @ 512

Last change on this file since 512 was 512, checked in by david, 10 years ago

-loading files configuration on startup
-devel version with probably a lot of leak
-using temporarily glib to store services

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

Search

Context Navigation

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