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

Last change on this file since 556 was 554, checked in by knut, 9 years ago

Changed the WIN32 version of function zGettimeofday. Changed return type for getShmLockId (WIN32). Changed type of _HINTERNET.mimeType from unsigned char* to char*. Fixed interconnected memory issues in functions getKeyValue and getShmLockId (WIN32). Added code to transfer the correct unique process identifier (usid) to background processes (applies to WIN32 version).

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