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, 9 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
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#ifndef bool
64#define bool int
65#endif
66#ifndef true
67#define true 1
68#define false -1
69#endif
70#else
71  //#include <stdbool.h>
72#endif
73
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
79
80#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
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
84#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)+sizeof(char*)+sizeof(char*)
85//#define SERVICE_SIZE sizeof(struct service)
86
87#define SHMSZ     27
88
89#include "version.h"
90
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
98  /**
99   * \struct map
100   * \brief KVP linked list
101   *
102   * Deal with WPS KVP (name,value).
103   * A map is defined as:
104   *  - name : a key,
105   *  - value: a value,
106   *  - next : a pointer to the next map if any.
107   */
108  typedef struct map{
109    char* name;
110    char* value;
111    struct map* next;
112  } map;
113
114#ifdef WIN32
115#define NULLMAP ((map*) 0)
116#else
117#define NULLMAP NULL
118#endif
119
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   */
139  static void _dumpMap(map* t){
140    if(t!=NULL){
141      fprintf(stderr,"%s: %s\n",t->name,t->value);
142      fflush(stderr);
143        }else{
144      fprintf(stderr,"NULL\n");
145      fflush(stderr);
146    }
147  }
148
149  static void dumpMap(map* t){
150    map* tmp=t;
151    while(tmp!=NULL){
152      _dumpMap(tmp);
153      tmp=tmp->next;
154    }
155  }
156
157  static void dumpMapToFile(map* t,FILE* file){
158    map* tmp=t;
159    while(tmp!=NULL){
160#ifdef DEBUG
161      fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
162#endif
163      fprintf(file,"%s = %s\n",tmp->name,tmp->value);
164      tmp=tmp->next;
165    }
166  }
167
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
177  static void dumpMapsToFile(maps* m,char* file_path){
178    FILE* file=fopen(file_path,"w");
179    maps* tmp=m;
180    if(tmp!=NULL){
181      fprintf(file,"[%s]\n",tmp->name);
182      dumpMapToFile(tmp->content,file);
183      fflush(file);
184    }
185    fclose(file);
186  }
187
188  static map* createMap(const char* name,const char* value){
189    map* tmp=(map *)malloc(MAP_SIZE);
190    tmp->name=zStrdup(name);
191    tmp->value=zStrdup(value);
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   
206  static bool hasKey(map* m,const char *key){
207    map* tmp=m;
208    while(tmp!=NULL){
209      if(strcasecmp(tmp->name,key)==0)
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
219  static maps* getMaps(maps* m,const char *key){
220    maps* tmp=m;
221    while(tmp!=NULL){
222      if(strcasecmp(tmp->name,key)==0){
223        return tmp;
224      }
225      tmp=tmp->next;
226    }
227    return NULL;
228  }
229
230  static map* getMap(map* m,const char *key){
231    map* tmp=m;
232    while(tmp!=NULL){
233      if(strcasecmp(tmp->name,key)==0){
234        return tmp;
235      }
236      tmp=tmp->next;
237    }
238    return NULL;
239  }
240
241
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
253  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
254    maps* _tmpm=getMaps(m,key);
255    if(_tmpm!=NULL){
256      map* _ztmpm=getMap(_tmpm->content,subkey);
257      return _ztmpm;
258    }
259    else return NULL;
260  }
261
262
263  static void freeMap(map** mo){
264    map* _cursor=*mo;
265    if(_cursor!=NULL){
266#ifdef DEBUG
267      fprintf(stderr,"freeMap\n");
268#endif
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
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  }
295
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   */
305  typedef struct iotype{
306    struct map* content;
307    struct iotype* next;
308  } iotype;
309
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   */
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;
336    char* identifier;
337    char * zcfg;
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
349  static bool hasElement(elements* e,const char* key){
350    elements* tmp=e;
351    while(tmp!=NULL){
352      if(strcasecmp(key,tmp->name)==0)
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){
362      if(strcasecmp(tmp->name,key)==0)
363        return tmp;
364      tmp=tmp->next;
365    }
366    return NULL;
367  }
368
369
370  static void freeIOType(iotype** i){
371    iotype* _cursor=*i;
372    if(_cursor!=NULL){
373      if(_cursor->next!=NULL){
374        freeIOType(&_cursor->next);
375        free(_cursor->next);
376      }
377      freeMap(&_cursor->content);
378      free(_cursor->content);
379    }
380  }
381
382  static void freeElements(elements** e){
383    elements* tmp=*e;
384    if(tmp!=NULL){
385      if(tmp->name!=NULL)
386        free(tmp->name);
387      freeMap(&tmp->content);
388      if(tmp->content!=NULL)
389        free(tmp->content);
390      freeMap(&tmp->metadata);
391      if(tmp->metadata!=NULL)
392        free(tmp->metadata);
393      if(tmp->format!=NULL)
394        free(tmp->format);
395      freeIOType(&tmp->defaults);
396      if(tmp->defaults!=NULL)
397        free(tmp->defaults);
398      freeIOType(&tmp->supported);
399      if(tmp->supported!=NULL){
400        free(tmp->supported);
401      }
402      freeElements(&tmp->next);
403      if(tmp->next!=NULL)
404        free(tmp->next);
405    }
406  }
407
408  static void freeService(service** s){
409    service* tmp=*s;
410    if(tmp!=NULL){
411      if(tmp->name!=NULL)
412                free(tmp->name);
413      if (tmp->identifier!=NULL)
414            free(tmp->identifier);
415      if (tmp->zcfg!=NULL)
416            free(tmp->zcfg);
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
432  static void addToMap(map* m,const char* n,const char* v){
433    if(hasKey(m,n)==false){
434      map* _cursor=m;
435      while(_cursor->next!=NULL){
436        _cursor=_cursor->next;
437      }
438      _cursor->next=createMap(n,v);
439    }
440    else{
441      map *tmp=getMap(m,n);
442      if(tmp->value!=NULL)
443        free(tmp->value);
444      tmp->value=zStrdup(v);
445    }
446  }
447
448  static void addMapToMap(map** mo,map* mi){
449    map* tmp=mi;
450    map* _cursor=*mo;
451    while(tmp!=NULL){
452      if(_cursor==NULL){
453        *mo=createMap(tmp->name,tmp->value);
454        (*mo)->next=NULL;
455      }
456      else{
457#ifdef DEBUG
458        fprintf(stderr,"_CURSOR\n");
459        dumpMap(_cursor);
460#endif
461        while(_cursor->next!=NULL)
462          _cursor=_cursor->next;
463        map* tmp1=getMap(*mo,tmp->name);
464        if(tmp1==NULL){
465          _cursor->next=createMap(tmp->name,tmp->value);
466        }
467        else{
468          addToMap(*mo,tmp->name,tmp->value);
469        }
470      }
471      _cursor=*mo;
472      tmp=tmp->next;
473#ifdef DEBUG
474      fprintf(stderr,"MO\n");
475      dumpMap(*mo);
476#endif
477    }
478  }
479
480  static void addMapToIoType(iotype** io,map* mi){
481    iotype* tmp=*io;
482    while(tmp->next!=NULL){
483      tmp=tmp->next;
484    }
485    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
486    tmp->next->content=NULL;
487    addMapToMap(&tmp->next->content,mi);
488    tmp->next->next=NULL;
489  }
490
491  static map* getMapOrFill(map** m,const char *key,const char* value){
492    map* tmp=*m;
493    map* tmpMap=getMap(tmp,key);
494    if(tmpMap==NULL){
495      if(tmp!=NULL){
496        addToMap((*m),key,value);
497      }
498      else
499        (*m)=createMap(key,value);
500      tmpMap=getMap(*m,key);
501    }
502    return tmpMap;
503  }
504
505  static bool contains(map* m,map* i){
506    while(i!=NULL){     
507      if(strcasecmp(i->name,"value")!=0 &&
508         strcasecmp(i->name,"xlink:href")!=0 &&
509         strcasecmp(i->name,"useMapServer")!=0 &&
510         strcasecmp(i->name,"asReference")!=0){
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  }
520
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
541  static maps* dupMaps(maps** mo){
542    maps* _cursor=*mo;
543    maps* res=NULL;
544    if(_cursor!=NULL){
545      res=(maps*)malloc(MAPS_SIZE);
546      res->name=zStrdup(_cursor->name);
547      res->content=NULL;
548      res->next=NULL;
549      map* mc=_cursor->content;
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      }
557      if(mc!=NULL){
558        addMapToMap(&res->content,mc);
559      }
560      if(tmp!=NULL){
561        map* tmpV=getMap(res->content,"value");
562        free(tmpV->value);
563        tmpV->value=(char*)malloc((atoi(tmp->value)+1)*sizeof(char));
564        memmove(tmpV->value,tmpSized,atoi(tmp->value)*sizeof(char));
565        tmpV->value[atoi(tmp->value)]=0;
566        free(tmpSized);
567      }
568      res->next=dupMaps(&_cursor->next);
569    }
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;
583        maps* tmp1=getMaps(*mo,tmp->name);
584        if(tmp1==NULL)
585          _cursor->next=dupMaps(&tmp);
586        else
587          addMapToMap(&tmp1->content,tmp->content);
588        _cursor=*mo;
589      }
590      tmp=tmp->next;
591    }
592  }
593
594  static map* getMapArray(map* m,const char* key,int index){
595    char tmp[1024];
596    if(index>0)
597      sprintf(tmp,"%s_%d",key,index);
598    else
599      sprintf(tmp,"%s",key);
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  }
610
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
617      sprintf(tmp,"%s",key);
618    map* tmpSize=getMapArray(m,(char*)"size",index);
619    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
620#ifdef DEBUG
621      fprintf(stderr,"%s\n",tmpSize->value);
622#endif
623      map* ptr=getMapOrFill(&m,tmp,(char *)"");
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){
633    map* tmap=getMap(mt,(char *)"mimeType");
634    if(tmap==NULL){
635      tmap=getMap(mt,"dataType");
636      if(tmap==NULL){
637        tmap=getMap(mt,"CRS");
638      }
639    }
640#ifdef DEBUG
641        dumpMap(tmap);
642#endif
643    return tmap;
644  }
645
646  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
647    maps* tmp=mi;   
648    maps* _cursor=getMaps(*mo,tmp->name);
649
650    if(_cursor==NULL)
651      return -1;
652
653    map* tmpLength=getMap(_cursor->content,"length");
654    char tmpLen[10];
655    int len=1;
656    if(tmpLength!=NULL){
657      len=atoi(tmpLength->value);
658    }
659
660    char *tmpV[8]={
661      (char*)"size",
662      (char*)"value",
663      (char*)"uom",
664      (char*)"Reference",
665      (char*)"xlink:href",
666      typ,
667      (char*)"schema",
668      (char*)"encoding"
669    };
670    sprintf(tmpLen,"%d",len+1);
671    addToMap(_cursor->content,"length",tmpLen);
672    int i=0;
673    for(i=0;i<8;i++){
674      map* tmpVI=getMap(tmp->content,tmpV[i]);
675      if(tmpVI!=NULL){
676#ifdef DEBUG
677        fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
678#endif
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
691  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
692    maps* _tmpm=getMaps(m,key);
693    if(_tmpm!=NULL){
694      map* _ztmpm=getMap(_tmpm->content,subkey);
695      if(_ztmpm!=NULL){
696        if(_ztmpm->value!=NULL)
697          free(_ztmpm->value);
698        _ztmpm->value=zStrdup(value);
699      }else{
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);
707      }
708    }else{
709      maps *tmp=(maps*)malloc(MAPS_SIZE);
710      tmp->name=zStrdup(key);
711      tmp->content=createMap(subkey,value);
712      tmp->next=NULL;
713      addMapsToMaps(&m,tmp);
714      freeMaps(&tmp);
715      free(tmp);
716    }
717  }
718
719
720  static void dumpElements(elements* e){
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
750  static void dumpElementsAsYAML(elements* e){
751    elements* tmp=e;
752    int i;
753    while(tmp!=NULL){
754      for(i=0;i<2;i++)
755        fprintf(stderr," ");
756      fprintf(stderr,"%s:\n",tmp->name);
757      map* mcurs=tmp->content;
758      while(mcurs!=NULL){
759        for(i=0;i<4;i++)
760          fprintf(stderr," ");
761        _dumpMap(mcurs);
762        mcurs=mcurs->next;
763      }
764      mcurs=tmp->metadata;
765      if(mcurs!=NULL){
766        for(i=0;i<4;i++)
767          fprintf(stderr," ");
768        fprintf(stderr,"MetaData:\n");
769        while(mcurs!=NULL){
770          for(i=0;i<6;i++)
771            fprintf(stderr," ");
772          _dumpMap(mcurs);
773          mcurs=mcurs->next;
774        }
775      }
776      for(i=0;i<4;i++)
777        fprintf(stderr," ");
778      fprintf(stderr,"%s:\n",tmp->format);
779      iotype* tmpio=tmp->defaults;
780      int ioc=0;
781      while(tmpio!=NULL){
782        for(i=0;i<6;i++)
783          fprintf(stderr," ");
784        fprintf(stderr,"default:\n");
785        mcurs=tmpio->content;
786        while(mcurs!=NULL){
787          for(i=0;i<8;i++)
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){
801        for(i=0;i<6;i++)
802          fprintf(stderr," ");
803        fprintf(stderr,"supported:\n");
804        mcurs=tmpio->content;
805        while(mcurs!=NULL){
806          for(i=0;i<8;i++)
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
822  static elements* dupElements(elements* e){
823    elements* cursor=e;
824    elements* tmp=NULL;
825    if(cursor!=NULL){
826#ifdef DEBUG
827      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
828      dumpElements(e);
829      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
830#endif
831      tmp=(elements*)malloc(ELEMENTS_SIZE);
832      tmp->name=zStrdup(e->name);
833      tmp->content=NULL;
834      addMapToMap(&tmp->content,e->content);
835      tmp->metadata=NULL;
836      addMapToMap(&tmp->metadata,e->metadata);
837      tmp->format=zStrdup(e->format);
838      if(e->defaults!=NULL){
839        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
840        tmp->defaults->content=NULL;
841        addMapToMap(&tmp->defaults->content,e->defaults->content);
842        tmp->defaults->next=NULL;
843#ifdef DEBUG
844        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
845        dumpMap(tmp->defaults->content);
846#endif
847      }else
848        tmp->defaults=NULL;
849      if(e->supported!=NULL){
850        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
851        tmp->supported->content=NULL;
852        addMapToMap(&tmp->supported->content,e->supported->content);
853        tmp->supported->next=NULL;
854        iotype *tmp2=e->supported->next;
855        while(tmp2!=NULL){
856          addMapToIoType(&tmp->supported,tmp2->content);
857#ifdef DEBUG
858          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
859          dumpMap(tmp->defaults->content);
860#endif
861          tmp2=tmp2->next;
862        }
863      }
864      else
865        tmp->supported=NULL;
866      tmp->next=dupElements(cursor->next);
867    }
868    return tmp;
869  }
870
871  static void addToElements(elements** m,elements* e){
872    elements* tmp=e;
873    if(*m==NULL){
874      *m=dupElements(tmp);
875    }else{
876      addToElements(&(*m)->next,tmp);
877    }
878  }
879
880  static void dumpService(service* s){
881    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
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);
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
903  static void dumpServiceAsYAML(service* s){
904    int i;
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){
913          for(i=0;i<2;i++)
914            fprintf(stderr," ");
915          _dumpMap(mcurs);
916          mcurs=mcurs->next;
917        }
918      }
919    }
920    if(s->inputs!=NULL){
921      fprintf(stderr,"\ninputs:\n");
922      dumpElementsAsYAML(s->inputs);
923    }
924    if(s->outputs!=NULL){
925      fprintf(stderr,"\noutputs:\n");
926      dumpElementsAsYAML(s->outputs);
927    }
928  }
929
930  static void mapsToCharXXX(maps* m,char*** c){
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
960  static void charxxxToMaps(char*** c,maps**m){
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
977          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
978      }
979      trorf=trorf->next;
980    }
981    m=&trorf;
982  }
983
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){
1021              int j;
1022              for(j=0;j<atoi(hasLength->value);j++){
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
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