source: trunk/zoo-kernel/service.h @ 57

Last change on this file since 57 was 57, checked in by djay, 13 years ago

Adding contains and getIoTypeFromElement functions in service.h. Remove memory leaks from the Service Configuration Parser, add the support for multiple supported formats as before. Small modification of the ZOO-Kernel Java Support, adding the capability to access the modified main_conf HashMap? from the Kernel to let lenv message map pass when an error occurs and it is handled in the Service code. Adding same capability for the ZOO-Kernel Python Support. Use strcasecmp in service.h rather than strlen+strncasecmp. Ensure that only OWS compliant informations are available for Contact.Phone and Contact.Adress. Remove memory leak in createExceptionReportNode. Correction of the addDefaultValues function to add the default format using the informations from DataInputs? if present, this should correct the behavior of the ZOO-Kernel when choosing the extension value which should now point to the corresponding zcfg value if present. Don't set the NULL value for inputs not provided in the DataInputs?, still set NULL as default value for outputs. Avoid segfault in freeElements when some zcfg values was not set correctly. Link against the client libjvm.so file rather than the server one.

File size: 14.0 KB
Line 
1/**
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2009-2010 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 __cplusplus
31extern "C" {
32#endif
33
34#include <stdlib.h>
35#include <ctype.h>
36#include <stdio.h>
37#include <string.h>
38
39#define bool int
40#define true 1
41#define false -1
42
43#define SERVICE_ACCEPTED 0
44#define SERVICE_STARTED 1
45#define SERVICE_PAUSED 2
46#define SERVICE_SUCCEEDED 3
47#define SERVICE_FAILED 4
48
49#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
50#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
51#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
52#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
53#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
54
55#define SHMSZ     27
56
57  /**
58   * \struct maps
59   * \brief linked list of map pointer
60   *
61   * Small object to store WPS KVP set.
62   */
63  typedef struct maps{
64    char* name;         
65    struct map* content; 
66    struct maps* next;   
67  } maps;
68
69  /**
70   * \struct map
71   * \brief KVP linked list
72   *
73   * Deal with WPS KVP (name,value).
74   */
75  typedef struct map{
76    char* name;       /* The key */
77    char* value;      /* The value */
78    struct map* next; /* Next couple */
79  } map;
80
81#ifdef WIN32
82#define NULLMAP ((map*) 0)
83#else
84#define NULLMAP NULL
85#endif
86
87  static void _dumpMap(map* t){
88    if(t!=NULL){
89      fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
90      fflush(stderr);
91    }else{
92      fprintf(stderr,"NULL\n");
93      fflush(stderr);
94    }
95  }
96
97  static void dumpMap(map* t){
98    map* tmp=t;
99    while(tmp!=NULL){
100      _dumpMap(tmp);
101      tmp=tmp->next;
102    }
103  }
104
105  static void dumpMaps(maps* m){
106    maps* tmp=m;
107    while(tmp!=NULL){
108      fprintf(stderr,"MAP => [%s] \n",tmp->name);
109      dumpMap(tmp->content);
110      tmp=tmp->next;
111    }
112  }
113
114  static map* createMap(const char* name,const char* value){
115    map* tmp=(map *)malloc(MAP_SIZE);
116    tmp->name=strdup(name);
117    tmp->value=strdup(value);
118    tmp->next=NULL;
119    return tmp;
120  }
121
122  static int count(map* m){
123    map* tmp=m;
124    int c=0;
125    while(tmp!=NULL){
126      c++;
127      tmp=tmp->next;
128    }
129    return c;
130  }
131   
132  static bool hasKey(map* m,const char *key){
133    map* tmp=m;
134    while(tmp!=NULL){
135      if(strcasecmp(tmp->name,key)==0)
136        return true;
137      tmp=tmp->next;
138    }
139#ifdef DEBUG_MAP
140    fprintf(stderr,"NOT FOUND \n");
141#endif
142    return false;
143  }
144
145  static maps* getMaps(maps* m,const char *key){
146    maps* tmp=m;
147    while(tmp!=NULL){
148      if(strcasecmp(tmp->name,key)==0){
149        return tmp;
150      }
151      tmp=tmp->next;
152    }
153    return NULL;
154  }
155
156  static map* getMap(map* m,const char *key){
157    map* tmp=m;
158    while(tmp!=NULL){
159      if(strcasecmp(tmp->name,key)==0){
160        return tmp;
161      }
162      tmp=tmp->next;
163    }
164    return NULL;
165  }
166
167  static map* getMapFromMaps(maps* m,char* key,char* subkey){
168    maps* _tmpm=getMaps(m,key);
169    if(_tmpm!=NULL){
170      map* _ztmpm=getMap(_tmpm->content,subkey);
171      return _ztmpm;
172    }
173    else return NULL;
174  }
175
176  static void freeMap(map** mo){
177    map* _cursor=*mo;
178    if(_cursor!=NULL){
179#ifdef DEBUG
180      fprintf(stderr,"freeMap\n");
181#endif
182      free(_cursor->name);
183      free(_cursor->value);
184      if(_cursor->next!=NULL){
185        freeMap(&_cursor->next);
186        free(_cursor->next);
187      }
188    }
189  }
190
191  static void freeMaps(maps** mo){
192    maps* _cursor=*mo;
193    fflush(stderr);
194    if(_cursor && _cursor!=NULL){
195#ifdef DEBUG
196      fprintf(stderr,"freeMaps\n");
197#endif
198      free(_cursor->name);
199      if(_cursor->content!=NULL){
200        freeMap(&_cursor->content);
201        free(_cursor->content);
202      }
203      if(_cursor->next!=NULL){
204        freeMaps(&_cursor->next);
205        free(_cursor->next);
206      }
207    }
208  }
209
210  typedef struct iotype{
211    struct map* content;
212    struct iotype* next;
213  } iotype;
214
215  typedef struct elements{
216    char* name;
217    struct map* content;
218    struct map* metadata;
219    char* format;
220    struct iotype* defaults;
221    struct iotype* supported;
222    struct elements* next;
223  } elements;
224
225  typedef struct service{
226    char* name;
227    struct map* content;
228    struct map* metadata;
229    struct elements* inputs;
230    struct elements* outputs; 
231  } service;
232
233  typedef struct services{
234    struct service* content; 
235    struct services* next; 
236  } services;
237
238  static bool hasElement(elements* e,char* key){
239    elements* tmp=e;
240    while(tmp!=NULL){
241      if(strcasecmp(key,tmp->name)==0)
242        return true;
243      tmp=tmp->next;
244    }
245    return false;
246  }
247
248  static elements* getElements(elements* m,char *key){
249    elements* tmp=m;
250    while(tmp!=NULL){
251      if(strcasecmp(tmp->name,key)==0)
252        return tmp;
253      tmp=tmp->next;
254    }
255    return NULL;
256  }
257
258
259  static void freeIOType(iotype** i){
260    iotype* _cursor=*i;
261    if(_cursor!=NULL){
262      if(_cursor->next!=NULL){
263        freeIOType(&_cursor->next);
264        free(_cursor->next);
265      }
266      freeMap(&_cursor->content);
267      free(_cursor->content);
268    }
269  }
270
271  static void freeElements(elements** e){
272    elements* tmp=*e;
273    if(tmp!=NULL){
274      if(tmp->name!=NULL)
275        free(tmp->name);
276      freeMap(&tmp->content);
277      if(tmp->content!=NULL)
278        free(tmp->content);
279      freeMap(&tmp->metadata);
280      if(tmp->metadata!=NULL)
281        free(tmp->metadata);
282      if(tmp->format!=NULL)
283        free(tmp->format);
284      freeIOType(&tmp->defaults);
285      if(tmp->defaults!=NULL)
286        free(tmp->defaults);
287      freeIOType(&tmp->supported);
288      if(tmp->supported!=NULL){
289        free(tmp->supported);
290      }
291      freeElements(&tmp->next);
292    }
293  }
294
295  static void freeService(service** s){
296    service* tmp=*s;
297    if(tmp!=NULL){
298      if(tmp->name!=NULL)
299        free(tmp->name);
300      freeMap(&tmp->content);
301      if(tmp->content!=NULL)
302        free(tmp->content);
303      freeMap(&tmp->metadata);
304      if(tmp->metadata!=NULL)
305        free(tmp->metadata);
306      freeElements(&tmp->inputs);
307      if(tmp->inputs!=NULL)
308        free(tmp->inputs);
309      freeElements(&tmp->outputs);
310      if(tmp->outputs!=NULL)
311        free(tmp->outputs);
312    }
313  }
314
315  static void addToMap(map* m,const char* n,const char* v){
316    if(hasKey(m,n)==false){
317      map* _cursor=m;
318      while(_cursor->next!=NULL)
319        _cursor=_cursor->next;
320      _cursor->next=createMap(n,v);
321    }
322    else{
323      map *tmp=getMap(m,n);
324      if(tmp->value!=NULL)
325        free(tmp->value);
326      tmp->value=strdup(v);
327    }
328  }
329
330  static void addMapToMap(map** mo,map* mi){
331    map* tmp=mi;
332    map* _cursor=*mo;
333    if(tmp==NULL){
334      if(_cursor!=NULL){
335        while(_cursor!=NULL)
336          _cursor=_cursor->next;
337        _cursor=NULL;
338      }else
339        *mo=NULL;
340    }
341    while(tmp!=NULL){
342      if(_cursor==NULL){
343        if(*mo==NULL)
344          *mo=createMap(tmp->name,tmp->value);
345        else
346          addToMap(*mo,tmp->name,tmp->value);
347      }
348      else{
349#ifdef DEBUG
350        fprintf(stderr,"_CURSOR\n");
351        dumpMap(_cursor);
352#endif
353        while(_cursor!=NULL)
354          _cursor=_cursor->next;
355        _cursor=createMap(tmp->name,tmp->value);
356        _cursor->next=NULL;
357      }
358      tmp=tmp->next;
359#ifdef DEBUG
360      fprintf(stderr,"MO\n");
361      dumpMap(*mo);
362#endif
363    }
364  }
365
366  static void addMapToIoType(iotype** io,map* mi){
367    iotype* tmp=*io;
368    while(tmp->next!=NULL){
369      tmp=tmp->next;
370    }
371    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
372    tmp->next->content=NULL;
373    addMapToMap(&tmp->next->content,mi);
374    tmp->next->next=NULL;
375  }
376
377  static bool contains(map* m,map* i){
378    while(i!=NULL){     
379      if(strcasecmp(i->name,"value")!=0 &&
380         strcasecmp(i->name,"xlink:href")!=0){
381        map *tmp;
382        if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
383           strcasecmp(i->value,tmp->value)!=0)
384          return false;
385      }
386      i=i->next;
387    }
388    return true;
389  }
390
391  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
392    elements* cursor=e;
393    while(cursor!=NULL){
394      if(strcasecmp(cursor->name,name)==0){
395        if(contains(cursor->defaults->content,values)==true)
396          return cursor->defaults;
397        else{
398          iotype* tmp=cursor->supported;
399          while(tmp!=NULL){
400            if(contains(tmp->content,values)==true)
401              return tmp;           
402            tmp=tmp->next;
403          }
404        }
405      }
406      cursor=cursor->next;
407    }
408    return NULL;
409  }
410
411  static maps* dupMaps(maps** mo){
412    maps* _cursor=*mo;
413    maps* res=NULL;
414    if(_cursor!=NULL){
415      res=(maps*)malloc(MAPS_SIZE);
416      res->name=strdup(_cursor->name);
417      res->content=NULL;
418      res->next=NULL;
419      map* mc=_cursor->content;
420      if(mc!=NULL){
421        addMapToMap(&res->content,mc);
422      }
423      res->next=dupMaps(&_cursor->next);
424    }
425    return res;
426  }
427
428  static void addMapsToMaps(maps** mo,maps* mi){
429    maps* tmp=mi;
430    maps* _cursor=*mo;
431    while(tmp!=NULL){
432      if(_cursor==NULL){
433        *mo=dupMaps(&mi);
434        (*mo)->next=NULL;
435      }
436      else{
437        while(_cursor->next!=NULL)
438          _cursor=_cursor->next;
439        _cursor->next=dupMaps(&tmp);
440      }
441      tmp=tmp->next;
442    }
443  }
444
445
446  static void* setMapInMaps(maps* m,char* key,char* subkey,char *value){
447    maps* _tmpm=getMaps(m,key);
448    if(_tmpm!=NULL){
449      map* _ztmpm=getMap(_tmpm->content,subkey);
450      if(_ztmpm!=NULL){
451        free(_ztmpm->value);
452        _ztmpm->value=strdup(value);
453      }else{
454        addToMap(_tmpm->content,subkey,value);
455      }
456    }
457  }
458
459
460  static void dumpElements(elements* e){
461    elements* tmp=e;
462    while(tmp!=NULL){
463      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
464      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
465      dumpMap(tmp->content);
466      fprintf(stderr," > METADATA [%s]\n",tmp->name);
467      dumpMap(tmp->metadata);
468      fprintf(stderr," > FORMAT [%s]\n",tmp->format);
469      iotype* tmpio=tmp->defaults;
470      int ioc=0;
471      while(tmpio!=NULL){
472        fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
473        dumpMap(tmpio->content);
474        tmpio=tmpio->next;
475        ioc++;
476      }
477      tmpio=tmp->supported;
478      ioc=0;
479      while(tmpio!=NULL){
480        fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
481        dumpMap(tmpio->content);
482        tmpio=tmpio->next;
483        ioc++;
484      }
485      fprintf(stderr,"------------------\n");
486      tmp=tmp->next;
487    }
488  }
489
490  static elements* dupElements(elements* e){
491    elements* cursor=e;
492    elements* tmp=NULL;
493    if(cursor!=NULL){
494#ifdef DEBUG
495      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
496      dumpElements(e);
497      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
498#endif
499      tmp=(elements*)malloc(ELEMENTS_SIZE);
500      tmp->name=strdup(e->name);
501      tmp->content=NULL;
502      addMapToMap(&tmp->content,e->content);
503      tmp->metadata=NULL;
504      addMapToMap(&tmp->metadata,e->metadata);
505      tmp->format=strdup(e->format);
506      if(e->defaults!=NULL){
507        tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
508        tmp->defaults->content=NULL;
509        addMapToMap(&tmp->defaults->content,e->defaults->content);
510        tmp->defaults->next=NULL;
511#ifdef DEBUG
512        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
513        dumpMap(tmp->defaults->content);
514#endif
515      }else
516        tmp->defaults=NULL;
517      if(e->supported!=NULL){
518        tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
519        tmp->supported->content=NULL;
520        addMapToMap(&tmp->supported->content,e->supported->content);
521        tmp->supported->next=NULL;
522        iotype *tmp2=e->supported->next;
523        while(tmp2!=NULL){
524          addMapToIoType(&tmp->supported,tmp2->content);
525#ifdef DEBUG
526          fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
527          dumpMap(tmp->defaults->content);
528#endif
529          tmp2=tmp2->next;
530        }
531      }
532      else
533        tmp->supported=NULL;
534      tmp->next=dupElements(cursor->next);
535    }
536    return tmp;
537  }
538
539  static void addToElements(elements** m,elements* e){
540    elements* _cursor=*m;
541    elements* tmp=e;
542    if(_cursor==NULL){
543      *m=dupElements(tmp);
544    }else{
545      addToElements(&(*m)->next,tmp);
546    }
547  }
548
549  static void dumpService(service* s){
550    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
551    if(s->content!=NULL){
552      fprintf(stderr,"CONTENT MAP\n");
553      dumpMap(s->content);
554      fprintf(stderr,"CONTENT METADATA\n");
555      dumpMap(s->metadata);
556    }
557    if(s->inputs!=NULL){
558      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
559      dumpElements(s->inputs);
560    }
561    if(s->outputs!=NULL){
562      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
563      dumpElements(s->outputs);
564    }
565    fprintf(stderr,"++++++++++++++++++\n");
566  }
567
568  static void mapsToCharXXX(maps* m,char*** c){
569    maps* tm=m;
570    int i=0;
571    int j=0;
572    char tmp[10][30][1024];
573    memset(tmp,0,1024*10*10);
574    while(tm!=NULL){
575      if(i>=10)
576        break;
577      strcpy(tmp[i][j],"name");
578      j++;
579      strcpy(tmp[i][j],tm->name);
580      j++;
581      map* tc=tm->content;
582      while(tc!=NULL){
583        if(j>=30)
584          break;
585        strcpy(tmp[i][j],tc->name);
586        j++;
587        strcpy(tmp[i][j],tc->value);
588        j++;
589        tc=tc->next;
590      }
591      tm=tm->next;
592      j=0;
593      i++;
594    }
595    memcpy(c,tmp,10*10*1024);
596  }
597
598  static void charxxxToMaps(char*** c,maps**m){
599    maps* trorf=*m;
600    int i,j;
601    char tmp[10][30][1024];
602    memcpy(tmp,c,10*30*1024);
603    for(i=0;i<10;i++){
604      if(strlen(tmp[i][1])==0)
605        break;
606      trorf->name=tmp[i][1];
607      trorf->content=NULL;
608      trorf->next=NULL;
609      for(j=2;j<29;j+=2){
610        if(strlen(tmp[i][j+1])==0)
611          break;
612        if(trorf->content==NULL)
613          trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
614        else
615          addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
616      }
617      trorf=trorf->next;
618    }
619    m=&trorf;
620  }
621
622#ifdef __cplusplus
623}
624#endif
625
626#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