source: branches/prototype-v0/zoo-project/zoo-kernel/service.c @ 890

Last change on this file since 890 was 890, checked in by djay, 5 years ago

Make this ZOO-Kernel working properly on windows platform again.

  • Property svn:keywords set to Id
File size: 38.5 KB
Line 
1/*
2 * Author : Gérald FENOY
3 *
4 * Copyright (c) 2015 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#include "service.h"
26
27
28#if defined(_MSC_VER) && _MSC_VER < 1800
29#include <stdarg.h>
30/**
31 * snprintf for Visual Studio compiler.
32 *
33 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c
34 */
35int snprintf(char *buffer, size_t n, const char *format, ...)
36{
37  va_list argp;
38  int ret;
39  va_start(argp, format);
40  ret = _vscprintf(format, argp);
41  vsnprintf_s(buffer, n, _TRUNCATE, format, argp);
42  va_end(argp);
43  return ret;
44}
45#endif
46
47/**
48 * Dump a map on stderr
49 *
50 * @param t the map to dump
51 */
52void _dumpMap(map* t){
53  if(t!=NULL){
54    fprintf(stderr,"%s: %s\n",t->name,t->value);
55    fflush(stderr);
56  }else{
57    fprintf(stderr,"NULL\n");
58    fflush(stderr);
59  }
60}
61
62/**
63 * Dump a map on stderr, see _dumpMap()
64 *
65 * @param t the map to dump
66 */
67void dumpMap(map* t){
68  map* tmp=t;
69  while(tmp!=NULL){
70    _dumpMap(tmp);
71    tmp=tmp->next;
72  }
73}
74
75/**
76 * Dump a map to a file
77 *
78 * @param t the map to dump to file
79 * @param file the file pointer to store the map
80 */
81void dumpMapToFile(map* t,FILE* file){
82  map* tmp=t;
83  while(tmp!=NULL){
84    fprintf(file,"%s = %s\n",tmp->name,tmp->value);
85    tmp=tmp->next;
86  }
87}
88
89/**
90 * Dump a maps on stderr, see dumpMap().
91 *
92 * @param m the map to dump
93 */
94void dumpMaps(maps* m){
95  maps* tmp=m;
96  while(tmp!=NULL){
97    fprintf(stderr,"MAP => [%s] \n",tmp->name);
98    fprintf(stderr," * CONTENT [%s] \n",tmp->name);
99    dumpMap(tmp->content);
100    if(tmp->child!=NULL){
101      fprintf(stderr," * CHILD [%s] \n",tmp->name);
102      dumpMaps(tmp->child);
103      fprintf(stderr," * /CHILD [%s] \n",tmp->name);
104    }
105    tmp=tmp->next;
106  }
107}
108
109/**
110 * Dump a maps to a file, see dumpMapToFile().
111 *
112 * @param m the map to dump
113 * @param file the the file pointer to store the map
114 */
115void _dumpMapsToFile(maps* m,FILE* file,int limit){
116  maps* tmp=m;
117  int cnt=0;
118  while(tmp!=NULL){
119    fprintf(file,"[%s]\n",tmp->name);
120    if(tmp->child!=NULL){
121      _dumpMapsToFile(tmp->child,file,limit);
122    }else
123      dumpMapToFile(tmp->content,file);
124    fflush(file);
125    tmp=tmp->next;
126    if(limit>=0 && cnt==limit)
127      tmp=NULL;
128    cnt++;
129  }
130  fflush(file);
131}
132
133/**
134 * Dump a maps to a file, see _dumpMapsToFile().
135 *
136 * @param m the map to dump
137 * @param file_path the full path to the file name to store the map
138 * @param limit the number limiting the maps to be dumped
139 */
140void dumpMapsToFile(maps* m,char* file_path,int limit){
141  FILE* file=fopen(file_path,"w+");
142  _dumpMapsToFile(m,file,limit);
143  fflush(file);
144  fclose(file);
145}
146
147/**
148 * Create a new iotype*
149 *
150 * @return a pointer to the allocated iotype
151 */
152iotype* createIoType(){
153  iotype* io=(iotype*)malloc(IOTYPE_SIZE);
154  io->content=NULL;
155  io->next=NULL;
156  return io;
157}
158
159/**
160 * Create a new map
161 *
162 * @param name the key to add to the map
163 * @param value the corresponding value to add to the map
164 * @return a pointer to the allocated map
165 */
166map* createMap(const char* name,const char* value){
167  map* tmp=(map *)malloc(MAP_SIZE);
168  tmp->name=zStrdup(name);
169  tmp->value=zStrdup(value);
170  tmp->next=NULL;
171  return tmp;
172}
173
174/**
175 * Create a new maps with the given name
176 *
177 * @param name of the maps
178 * @return the allocated map
179 */
180maps* createMaps(const char* name){
181  maps* tmp = (maps *) malloc (MAPS_SIZE);
182  tmp->name = zStrdup (name);
183  tmp->content = NULL;
184  tmp->child = NULL;
185  tmp->next = NULL;
186  return tmp;
187}
188
189/**
190 * Count number of map in a map
191 *
192 * @param m the map to count
193 * @return number of map in a map
194 */
195int count(map* m){
196  map* tmp=m;
197  int c=0;
198  while(tmp!=NULL){
199    c++;
200    tmp=tmp->next;
201  }
202  return c;
203}
204
205/**
206 * Count number of maps in a maps
207 *
208 * @param m the maps to count
209 * @return number of maps in a maps
210 */
211int maps_length(maps* m){
212  maps* tmp=m;
213  int c=0;
214  while(tmp!=NULL){
215    c++;
216    tmp=tmp->next;
217  }
218  return c;
219}
220
221/**
222 * Verify if a key exist in a map
223 *
224 * @param m the map to search for the key
225 * @param key the key to search in the map
226 * @return true if the key wwas found, false in other case
227 */
228bool hasKey(map* m,const char *key){
229  map* tmp=m;
230  while(tmp!=NULL){
231    if(strcasecmp(tmp->name,key)==0)
232      return true;
233    tmp=tmp->next;
234  }
235#ifdef DEBUG_MAP
236  fprintf(stderr,"NOT FOUND \n");
237#endif
238  return false;
239}
240
241/**
242 * Access a specific maps
243 *
244 * @param m the maps to search for the key
245 * @param key the key to search in the maps
246 * @return a pointer on the maps found or NULL if not found
247 */
248maps* getMaps(maps* m,const char *key){
249  maps* tmp=m;
250  while(tmp!=NULL){
251    if(strcasecmp(tmp->name,key)==0){
252      return tmp;
253    }
254    tmp=tmp->next;
255  }
256  return NULL;
257}
258
259/**
260 * Access a specific map
261 *
262 * @param m the map to search for the key
263 * @param key the key to search in the map
264 * @return a pointer on the map found or NULL if not found
265 */
266map* getMap(map* m,const char *key){
267  map* tmp=m;
268  while(tmp!=NULL){
269    if(strcasecmp(tmp->name,key)==0){
270      return tmp;
271    }
272    tmp=tmp->next;
273  }
274  return NULL;
275}
276
277
278/**
279 * Access the last map
280 *
281 * @param m the map to search for the lastest map
282 * @return a pointer on the lastest map found or NULL if not found
283 */
284map* getLastMap(map* m){
285  map* tmp=m;
286  while(tmp!=NULL){
287    if(tmp->next==NULL){
288      return tmp;
289    }
290    tmp=tmp->next;
291  }
292  return NULL;
293}
294
295/**
296 * Access a specific map from a maps
297 *
298 * @param m the maps to search for the key
299 * @param key the key to search in the maps
300 * @param subkey the key to search in the map (found for the key, if any)
301 * @return a pointer on the map found or NULL if not found
302 */
303map* getMapFromMaps(maps* m,const char* key,const char* subkey){
304  maps* _tmpm=getMaps(m,key);
305  if(_tmpm!=NULL){
306    map* _ztmpm=getMap(_tmpm->content,subkey);
307    return _ztmpm;
308  }
309  else return NULL;
310}
311
312/**
313 * Free allocated memory of a map.
314 * Require to call free on mo after calling this function.
315 *
316 * @param mo the map to free
317 */
318void freeMap(map** mo){
319  map* _cursor=*mo;
320  if(_cursor!=NULL){
321#ifdef DEBUG
322    fprintf(stderr,"freeMap\n");
323#endif
324    free(_cursor->name);
325    free(_cursor->value);
326    if(_cursor->next!=NULL){
327      freeMap(&_cursor->next);
328      free(_cursor->next);
329    }
330  }
331}
332
333/**
334 * Free allocated memory of a maps.
335 * Require to call free on mo after calling this function.
336 *
337 * @param mo the maps to free
338 */
339void freeMaps(maps** mo){
340  maps* _cursor=*mo;
341  if(_cursor && _cursor!=NULL){
342#ifdef DEBUG
343    fprintf(stderr,"freeMaps\n");
344#endif
345    free(_cursor->name);
346    if(_cursor->content!=NULL){
347      freeMap(&_cursor->content);
348      free(_cursor->content);
349    }
350    if(_cursor->child!=NULL){
351      freeMaps(&_cursor->child);
352      free(_cursor->child);
353    }
354    if(_cursor->next!=NULL){
355      freeMaps(&_cursor->next);
356      free(_cursor->next);
357    }
358  }
359}
360
361/**
362 * Verify if an elements contains a name equal to the given key.
363 *
364 * @param e the elements to search for the key
365 * @param key the elements name to search
366 * @return true if the elements contains the name, false in other cases.
367 */ 
368bool hasElement(elements* e,const char* key){
369  elements* tmp=e;
370  while(tmp!=NULL){
371    if(strcasecmp(key,tmp->name)==0)
372      return true;
373    tmp=tmp->next;
374  }
375  return false;
376}
377
378/**
379 * Access a specific elements named key.
380 *
381 * @param m the elements to search
382 * @param key the elements name to search
383 * @return a pointer to the specific element if found, NULL in other case.
384 */ 
385elements* getElements(elements* m,char *key){
386  elements* tmp=m;
387  while(tmp!=NULL){
388    if(strcasecmp(tmp->name,key)==0)
389      return tmp;
390    tmp=tmp->next;
391  }
392  return NULL;
393}
394
395/**
396 * Free allocated memory of an iotype.
397 * Require to call free on i after calling this function.
398 *
399 * @param i the iotype to free
400 */
401void freeIOType(iotype** i){
402  iotype* _cursor=*i;
403  if(_cursor!=NULL){
404    if(_cursor->next!=NULL){
405      freeIOType(&_cursor->next);
406      free(_cursor->next);
407    }
408    freeMap(&_cursor->content);
409    free(_cursor->content);
410  }
411}
412
413/**
414 * Free allocated memory of an elements.
415 * Require to call free on e after calling this function.
416 *
417 * @param e the iotype to free
418 */
419void freeElements(elements** e){
420  elements* tmp=*e;
421  if(tmp!=NULL){
422    if(tmp->name!=NULL)
423      free(tmp->name);
424    freeMap(&tmp->content);
425    if(tmp->content!=NULL)
426      free(tmp->content);
427    freeMap(&tmp->metadata);
428    if(tmp->metadata!=NULL)
429      free(tmp->metadata);
430    freeMap(&tmp->additional_parameters);
431    if(tmp->additional_parameters!=NULL)
432      free(tmp->additional_parameters);
433    if(tmp->format!=NULL)
434      free(tmp->format);
435    freeElements(&tmp->child);
436    if(tmp->child!=NULL){
437      free(tmp->child);
438    }
439    if(tmp->defaults!=NULL){
440      freeIOType(&tmp->defaults);
441      free(tmp->defaults);
442    }
443    if(tmp->supported!=NULL){
444      freeIOType(&tmp->supported);
445      free(tmp->supported);
446    }
447    if(tmp->next!=NULL){
448      freeElements(&tmp->next);
449      free(tmp->next);
450    }
451  }
452}
453
454
455/**
456 * Allocate memory for a service.
457 * Require to call free after calling this function.
458 *
459 * @return the service
460 */
461service* createService(){
462  service *s1 = (service *) malloc (SERVICE_SIZE);
463  s1->name=NULL;
464  s1->content=NULL;
465  s1->metadata=NULL;
466  s1->additional_parameters=NULL;
467  s1->inputs=NULL;
468  s1->outputs=NULL;
469  return s1;
470}
471
472/**
473 * Free allocated memory of a service.
474 * Require to be invoked for every createService call.
475 *
476 * @param s the service to free
477 */
478void freeService(service** s){
479  service* tmp=*s;
480  if(tmp!=NULL){
481    if(tmp->name!=NULL)
482      free(tmp->name);
483    freeMap(&tmp->content);
484    if(tmp->content!=NULL)
485      free(tmp->content);
486    freeMap(&tmp->metadata);
487    if(tmp->metadata!=NULL)
488      free(tmp->metadata);
489    freeMap(&tmp->additional_parameters);
490    if(tmp->additional_parameters!=NULL)
491      free(tmp->additional_parameters);
492    freeElements(&tmp->inputs);
493    if(tmp->inputs!=NULL)
494      free(tmp->inputs);
495    freeElements(&tmp->outputs);
496    if(tmp->outputs!=NULL)
497      free(tmp->outputs);
498  }
499}
500
501/**
502 * Add key value pair to an existing map.
503 *
504 * @param m the map to add the KVP
505 * @param n the key to add
506 * @param v the corresponding value to add
507 */
508void addToMap(map* m,const char* n,const char* v){
509  if(hasKey(m,n)==false){
510    map* _cursor=m;
511    while(_cursor->next!=NULL){
512      _cursor=_cursor->next;
513    }
514    _cursor->next=createMap(n,v);
515  }
516  else{
517    map *tmp=getMap(m,n);
518    if(tmp->value!=NULL)
519      free(tmp->value);
520    tmp->value=zStrdup(v);
521  }
522}
523
524/**
525 * Add a key and an integer value to an existing map.
526 *
527 * @param m the map to add the KVP
528 * @param n the key to add
529 * @param v the corresponding value to add
530 */
531void addIntToMap(map* m,const char* n,const int v){
532  char svalue[10];
533  sprintf(svalue,"%d",v);
534  if(hasKey(m,n)==false){
535    map* _cursor=m;
536    while(_cursor->next!=NULL){
537      _cursor=_cursor->next;
538    }
539    _cursor->next=createMap(n,svalue);
540  }
541  else{
542    map *tmp=getMap(m,n);
543    if(tmp->value!=NULL)
544      free(tmp->value);
545    tmp->value=zStrdup(svalue);
546  }
547}
548
549/**
550 * Add a key and a binary value to an existing map.
551 *
552 * @param m the map to add the KVP
553 * @param n the key to add
554 * @param v the corresponding value to add
555 * @param size the size of the given value
556 * @return a pointer to the updated map m
557 */
558map* addToMapWithSize(map* m,const char* n,const char* v,int size){
559  char sin[128];
560  char sname[10]="size";
561  map *tmp;
562  if(hasKey(m,n)==false){
563    map* _cursor=m;
564    if(_cursor!=NULL){
565      addToMap(m,n,"");
566    }else{
567      m=createMap(n,"");
568    }
569  }
570  if(strlen(n)>5)
571    sprintf(sname,"size_%s",n+6);
572  tmp=getMap(m,n);
573  if(tmp->value!=NULL)
574    free(tmp->value);
575  tmp->value=(char*)malloc((size+1)*sizeof(char));
576  if(v!=NULL)
577    memmove(tmp->value,v,size*sizeof(char));
578  tmp->value[size]=0;
579  sprintf(sin,"%d",size);
580  addToMap(m,sname,sin);
581  return m;
582}
583
584/**
585 * Add a map at the end of another map.
586 *
587 * @param mo the map to add mi
588 * @param mi the map to add to mo
589 */
590void addMapToMap(map** mo,map* mi){
591  map* tmp=mi;
592  map* _cursor=*mo;
593  while(tmp!=NULL){
594    if(_cursor==NULL){
595      *mo=createMap(tmp->name,tmp->value);
596      (*mo)->next=NULL;
597    }
598    else{
599      map* tmp1=getMap(*mo,tmp->name);
600      if(tmp1==NULL){
601        while(_cursor->next!=NULL)
602          _cursor=_cursor->next;
603        _cursor->next=createMap(tmp->name,tmp->value);
604      }
605      else{
606        addToMap(*mo,tmp->name,tmp->value);
607      }
608    }
609    _cursor=*mo;
610    tmp=tmp->next;
611  }
612}
613
614/**
615 * Add a map to iotype.
616 *
617 * @param io the iotype to add the map
618 * @param mi the map to add to io
619 */
620void addMapToIoType(iotype** io,map* mi){
621  iotype* tmp=*io;
622  while(tmp->next!=NULL){
623    tmp=tmp->next;
624  }
625  tmp->next=(iotype*)malloc(IOTYPE_SIZE);
626  tmp->next->content=NULL;
627  addMapToMap(&tmp->next->content,mi);
628  tmp->next->next=NULL;
629}
630
631/**
632 * Access a specific map or set its value.
633 *
634 * @param m the map to search for the key
635 * @param key the key to search/add in the map
636 * @param value the value to add if the key does not exist
637 * @return a pointer on the map found or NULL if not found
638 */
639map* getMapOrFill(map** m,const char *key,const char* value){
640  map* tmp=*m;
641  map* tmpMap=getMap(tmp,key);
642  if(tmpMap==NULL){
643    if(tmp!=NULL){
644      addToMap((*m),key,value);
645    }
646    else
647      (*m)=createMap(key,value);
648    tmpMap=getMap(*m,key);
649  }
650  return tmpMap;
651}
652
653/**
654 * Verify if a map is contained in another map.
655 *
656 * @param m the map to search for i
657 * @param i the map to search in m
658 * @return true if i was found in m, false in other case
659 */
660bool contains(map* m,map* i){
661  while(i!=NULL){     
662    if(strcasecmp(i->name,"value")!=0 &&
663       strcasecmp(i->name,"xlink:href")!=0 &&
664       strcasecmp(i->name,"useMapServer")!=0 &&
665       strcasecmp(i->name,"asReference")!=0){
666      map *tmp;
667      if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
668         strcasecmp(i->value,tmp->value)!=0)
669        return false;
670    }
671    i=i->next;
672  }
673  return true;
674}
675
676/**
677 * Access a specific iotype from an elements.
678 *
679 * @param e the elements to search for the name
680 * @param name the name to search in the elements e
681 * @param values the map to verify it was contained in the defaults or
682 *  supported content of the elements e
683 * @return a pointer on the iotype found or NULL if not found
684 */
685iotype* getIoTypeFromElement(elements* e,char *name, map* values){
686  elements* cursor=e;
687  if(values!=NULL){
688    while(cursor!=NULL){
689      if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
690        if(contains(cursor->defaults->content,values)==true)
691          return cursor->defaults;
692        else{
693          iotype* tmp=cursor->supported;
694          while(tmp!=NULL){
695            if(contains(tmp->content,values)==true)
696              return tmp;           
697            tmp=tmp->next;
698          }
699        }
700      }
701      cursor=cursor->next;
702    }
703  }else{
704    while(cursor!=NULL){
705      if(strcasecmp(cursor->name,name)==0 && cursor->defaults!=NULL){
706        return cursor->defaults;
707      }
708      cursor=cursor->next;
709    }
710  }
711  return NULL;
712}
713
714/**
715 * Load binary values from a map (in) and add them to another map (out)
716 *
717 * @param out the map to add binaries values
718 * @param in the map containing the binary values to add ti out
719 * @param pos index of the binary in an array (in case of "MapArray")
720 */
721void loadMapBinary(map** out,map* in,int pos){
722  map* size=getMap(in,"size");
723  map *lout=*out;
724  map *tmpVin,*tmpVout;
725  if(size!=NULL && pos>0){
726    char tmp[11];
727    sprintf(tmp,"size_%d",pos);
728    size=getMap(in,tmp);
729    sprintf(tmp,"value_%d",pos);
730    tmpVin=getMap(in,tmp);
731    tmpVout=getMap(lout,tmp);
732    free(tmpVout->value);
733    tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
734    memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
735    tmpVout->value[atoi(size->value)]=0;
736  }else{
737    if(size!=NULL){
738      tmpVin=getMap(in,"value");
739      tmpVout=getMap(lout,"value");
740      free(tmpVout->value);
741      tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
742      memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
743      tmpVout->value[atoi(size->value)]=0;
744    }
745  }
746}
747 
748/**
749 * Load binary values from a map (in) and add them to another map (out).
750 * This function will take care of MapArray.
751 * @see loadMapBinary
752 *
753 * @param out the map to add binaries values
754 * @param in the map containing the binary values to add ti out
755 */
756void loadMapBinaries(map** out,map* in){
757  map* size=getMap(in,"size");
758  map* length=getMap(in,"length");
759  map* toload=getMap(in,"to_load");
760  if(toload!=NULL && strcasecmp(toload->value,"false")==0){
761#ifdef DEBUG
762    fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
763#endif
764    return ;
765  }
766  if(length!=NULL){
767    int len=atoi(length->value);
768    int i=0;
769    for(i=0;i<len;i++){
770      loadMapBinary(out,in,i);
771    }
772  }
773  else
774    if(size!=NULL)
775      loadMapBinary(out,in,-1);
776}
777
778/**
779 * Duplicate a Maps
780 *
781 * @param mo the maps to clone
782 * @return the allocated maps containing a copy of the mo maps
783 */
784maps* dupMaps(maps** mo){
785  maps* _cursor=*mo;
786  maps* res=NULL;
787  if(_cursor!=NULL){
788    map* mc=_cursor->content;
789    maps* mcs=_cursor->child;
790    res=createMaps(_cursor->name);
791    if(mc!=NULL){
792      addMapToMap(&res->content,mc);
793      loadMapBinaries(&res->content,mc);
794    }
795    if(mcs!=NULL){
796      res->child=dupMaps(&mcs);
797    }
798    res->next=dupMaps(&_cursor->next);
799  }
800  return res;
801}
802
803/**
804 * Add a maps at the end of another maps.
805 *
806 * @see addMapToMap, dupMaps, getMaps
807 * @param mo the maps to add mi
808 * @param mi the maps to add to mo
809 */
810void addMapsToMaps(maps** mo,maps* mi){
811  maps* tmp=mi;
812  maps* _cursor=*mo;
813  while(tmp!=NULL){
814    if(_cursor==NULL){
815      *mo=dupMaps(&mi);
816    }
817    else{
818      maps* tmp1=getMaps(*mo,tmp->name);
819      while(_cursor->next!=NULL)
820        _cursor=_cursor->next;
821      if(tmp1==NULL){
822        _cursor->next=dupMaps(&tmp);
823        if(tmp->child!=NULL)
824          _cursor->next->child=dupMaps(&tmp->child);
825        else
826          _cursor->next->child=NULL;
827      }
828      else{
829        addMapToMap(&tmp1->content,tmp->content);
830        if(tmp->child!=NULL)
831          tmp1->child=dupMaps(&tmp->child);
832        else
833          tmp1->child=NULL;
834      }
835      _cursor=*mo;
836    }
837    tmp=tmp->next;
838  }
839}
840
841/**
842 * Access a specific map array element
843 *
844 * @param m the map to search for the key
845 * @param key the key to search in the map
846 * @param index of the MapArray
847 * @return a pointer on the map found or NULL if not found
848 */
849map* getMapArray(map* m,const char* key,int index){
850  char tmp[1024];
851  map* tmpMap;
852  if(index>0)
853    sprintf(tmp,"%s_%d",key,index);
854  else
855    sprintf(tmp,"%s",key);
856#ifdef DEBUG
857  fprintf(stderr,"** KEY %s\n",tmp);
858#endif
859  tmpMap=getMap(m,tmp);
860#ifdef DEBUG
861  if(tmpMap!=NULL)
862    dumpMap(tmpMap);
863#endif
864  return tmpMap;
865}
866
867/**
868 * Add a key value in a MapArray for a specific index
869 *
870 * @param m the map to search for the key
871 * @param key the key to search in the map
872 * @param index the index of the MapArray
873 * @param value the value to set in the MapArray
874 * @return a pointer on the map found or NULL if not found
875 */
876void setMapArray(map* m,const char* key,int index,const char* value){
877  char tmp[1024];
878  map* tmpSize;
879  if(index>0){
880    map* len=getMap(m,"length");
881    sprintf(tmp,"%s_%d",key,index);
882    if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
883      char tmp0[5];
884      sprintf(tmp0,"%d",index+1);
885      addToMap(m,"length",tmp0);
886    }
887  }
888  else{
889    sprintf(tmp,"%s",key);
890    addToMap(m,"length","1");
891  }
892  tmpSize=getMapArray(m,"size",index);
893  if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
894    map* ptr=getMapOrFill(&m,tmp,(char *)"");
895#ifdef DEBUG
896    fprintf(stderr,"%s\n",tmpSize->value);
897#endif
898    free(ptr->value);
899    ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
900    memcpy(ptr->value,value,atoi(tmpSize->value)); 
901  }
902  else
903    addToMap(m,tmp,value);
904}
905
906/**
907 * Add a key and an integer value to an existing map array.
908 *
909 * @param m the map to add the KVP
910 * @param n the key to add
911 * @param index the index of the MapArray
912 * @param v the corresponding value to add
913 */
914void addIntToMapArray(map* m,const char* n,int index,const int v){
915  char svalue[10];
916  sprintf(svalue,"%d",v);
917  setMapArray(m,n,index,svalue);
918}
919
920/**
921 * Access the map "type"
922 *
923 * @param mt the map
924 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
925 *  other case
926 */
927map* getMapType(map* mt){
928  map* tmap=getMap(mt,(char *)"mimeType");
929  if(tmap==NULL){
930    tmap=getMap(mt,"dataType");
931    if(tmap==NULL){
932      tmap=getMap(mt,"CRS");
933    }
934  }
935#ifdef DEBUG
936  dumpMap(tmap);
937#endif
938  return tmap;
939}
940
941/**
942 * Add a Maps containing a MapArray to a Maps
943 *
944 * @see getMapType
945 * @param mo the maps
946 * @param mi the maps
947 * @param typ the map "type"
948 * @return
949 */
950int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
951  maps* tmp=mi;   
952  maps* _cursor=getMaps(*mo,tmp->name);
953  char tmpLen[10];
954  int len=1;
955  char *tmpV[14]={
956    (char*)"size",
957    (char*)"value",
958    (char*)"uom",
959    (char*)"Reference",
960    (char*)"Order",
961    (char*)"cache_file",
962    (char*)"fmimeType",
963    (char*)"xlink:href",
964    typ,
965    (char*)"schema",
966    (char*)"encoding",
967    (char*)"isCached",
968    (char*)"LowerCorner",
969    (char*)"UpperCorner"
970  };
971  int i=0;
972  map* tmpLength;
973 
974  if(_cursor==NULL)
975    return -1;
976
977  tmpLength=getMap(_cursor->content,"length");
978  if(tmpLength!=NULL){
979    len=atoi(tmpLength->value);
980  }
981
982  sprintf(tmpLen,"%d",len+1);
983  addToMap(_cursor->content,"length",tmpLen);
984  for(i=0;i<14;i++){
985    map* tmpVI=getMap(tmp->content,tmpV[i]);
986    if(tmpVI!=NULL){
987#ifdef DEBUG
988      fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
989#endif
990      setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
991    }
992  }
993   
994  addToMap(_cursor->content,"isArray","true");
995  return 0;
996}
997
998/**
999 * Set a key value pair to a map contained in a Maps
1000 *
1001 * @param m the maps
1002 * @param key the maps name
1003 * @param subkey the map name included in the maps corresponding to key
1004 * @param value the corresponding value to add in the map
1005 */
1006void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
1007  maps* _tmpm=getMaps(m,key);
1008  if(_tmpm!=NULL){
1009    map* _ztmpm=getMap(_tmpm->content,subkey);
1010    if(_ztmpm!=NULL){
1011      if(_ztmpm->value!=NULL)
1012        free(_ztmpm->value);
1013      _ztmpm->value=zStrdup(value);
1014    }else{
1015      maps *tmp=createMaps(key);
1016      tmp->content=createMap(subkey,value);
1017      addMapsToMaps(&_tmpm,tmp);
1018      freeMaps(&tmp);
1019      free(tmp);
1020    }
1021  }else{
1022    maps *tmp=createMaps(key);
1023    tmp->content=createMap(subkey,value);
1024    addMapsToMaps(&m,tmp);
1025    freeMaps(&tmp);
1026    free(tmp);
1027  }
1028}
1029
1030/**
1031 * Create an empty elements
1032 *
1033 * @return a pointer to the allocated elements
1034 */
1035elements* createEmptyElements(){
1036  elements* res=(elements*)malloc(ELEMENTS_SIZE);
1037  res->name=NULL;
1038  res->content=NULL;
1039  res->metadata=NULL;
1040  res->additional_parameters=NULL; 
1041  res->format=NULL;
1042  res->defaults=NULL;
1043  res->supported=NULL;
1044  res->child=NULL;
1045  res->next=NULL;
1046  return res;
1047}
1048
1049/**
1050 * Create a named elements
1051 *
1052 * @param name the elements name
1053 * @return a pointer to the allocated elements
1054 */
1055elements* createElements(const char* name){
1056  elements* res=(elements*)malloc(ELEMENTS_SIZE);
1057  res->name=zStrdup(name);
1058  res->content=NULL;
1059  res->metadata=NULL;
1060  res->additional_parameters=NULL;
1061  res->format=NULL;
1062  res->defaults=NULL;
1063  res->supported=NULL;
1064  res->child=NULL;
1065  res->next=NULL;
1066  return res;
1067}
1068
1069/**
1070 * Set the name of an elements
1071 *
1072 * @param name the elements name
1073 * @return a pointer to the allocated elements
1074 */
1075void setElementsName(elements** elem,char* name){
1076  elements* res=*elem;
1077  res->name=zStrdup(name);
1078  res->content=NULL;
1079  res->metadata=NULL;
1080  res->format=NULL;
1081  res->defaults=NULL;
1082  res->supported=NULL;
1083  res->child=NULL;
1084  res->next=NULL;
1085}
1086
1087/**
1088 * Dump an elements on stderr
1089 *
1090 * @param e the elements to dump
1091 */
1092void dumpElements(elements* e){
1093  elements* tmp=e;
1094  while(tmp!=NULL){
1095    iotype* tmpio=tmp->defaults;
1096    int ioc=0;
1097    fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
1098    fprintf(stderr," > CONTENT [%s]\n",tmp->name);
1099    dumpMap(tmp->content);
1100    fprintf(stderr," > METADATA [%s]\n",tmp->name);
1101    dumpMap(tmp->metadata);
1102    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
1103    dumpMap(tmp->additional_parameters);
1104    fprintf(stderr," > FORMAT [%s]\n",tmp->format);
1105    while(tmpio!=NULL){
1106      fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
1107      dumpMap(tmpio->content);
1108      tmpio=tmpio->next;
1109      ioc++;
1110    }
1111    tmpio=tmp->supported;
1112    ioc=0;
1113    while(tmpio!=NULL){
1114      fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
1115      dumpMap(tmpio->content);
1116      tmpio=tmpio->next;
1117      ioc++;
1118    }
1119    if(tmp->child!=NULL){
1120      fprintf(stderr," > CHILD \n");
1121      dumpElements(tmp->child);
1122    }
1123    fprintf(stderr,"------------------\n");
1124    tmp=tmp->next;
1125  }
1126}
1127
1128/**
1129 * Dump an elements on stderr using the YAML syntaxe
1130 *
1131 * @param e the elements to dump
1132 */
1133void dumpElementsAsYAML(elements* e,int level){
1134  elements* tmp=e;
1135  int i;
1136  while(tmp!=NULL){
1137    map* mcurs=tmp->content;
1138    int ioc=0;
1139    iotype* tmpio;
1140    for(i=0;i<2+(4*level);i++)
1141      fprintf(stderr," ");
1142    fprintf(stderr,"%s:\n",tmp->name);
1143    while(mcurs!=NULL){
1144      for(i=0;i<4+(4*level);i++)
1145        fprintf(stderr," ");
1146      _dumpMap(mcurs);
1147      mcurs=mcurs->next;
1148    }
1149    mcurs=tmp->metadata;
1150    if(mcurs!=NULL){
1151      for(i=0;i<4+(4*level);i++)
1152        fprintf(stderr," ");
1153      fprintf(stderr,"MetaData:\n");
1154      while(mcurs!=NULL){
1155        for(i=0;i<6+(4*level);i++)
1156          fprintf(stderr," ");
1157        _dumpMap(mcurs);
1158        mcurs=mcurs->next;
1159      }
1160    }
1161    for(i=0;i<4+(4*level);i++)
1162      fprintf(stderr," ");
1163    if(tmp->format!=NULL)
1164      fprintf(stderr,"%s:\n",tmp->format);
1165    else{
1166      fprintf(stderr,"Child:\n");
1167      if(tmp->child!=NULL)
1168        dumpElementsAsYAML(tmp->child,level+1);
1169    }
1170    tmpio=tmp->defaults;
1171    while(tmpio!=NULL){
1172      for(i=0;i<6+(4*level);i++)
1173        fprintf(stderr," ");
1174      fprintf(stderr,"default:\n");
1175      mcurs=tmpio->content;
1176      while(mcurs!=NULL){
1177        for(i=0;i<8+(4*level);i++)
1178          fprintf(stderr," ");
1179        if(strcasecmp(mcurs->name,"range")==0){
1180          fprintf(stderr,"range: \"%s\"\n",mcurs->value);
1181        }else
1182          _dumpMap(mcurs);
1183        mcurs=mcurs->next;
1184      }
1185      tmpio=tmpio->next;
1186      ioc++;
1187    }
1188    tmpio=tmp->supported;
1189    ioc=0;
1190    while(tmpio!=NULL){
1191      for(i=0;i<6+(4*level);i++)
1192        fprintf(stderr," ");
1193      fprintf(stderr,"supported:\n");
1194      mcurs=tmpio->content;
1195      while(mcurs!=NULL){
1196        for(i=0;i<8+(4*level);i++)
1197          fprintf(stderr," ");
1198        if(strcasecmp(mcurs->name,"range")==0){
1199          fprintf(stderr,"range: \"%s\"\n",mcurs->value);
1200        }else
1201          _dumpMap(mcurs);
1202        mcurs=mcurs->next;
1203      }
1204      tmpio=tmpio->next;
1205      ioc++;
1206    }
1207    tmp=tmp->next;
1208  }
1209}
1210
1211/**
1212 * Duplicate an elements
1213 *
1214 * @param e the elements to clone
1215 * @return the allocated elements containing a copy of the elements e
1216 */
1217elements* dupElements(elements* e){
1218  elements* cursor=e;
1219  elements* tmp=NULL;
1220  if(cursor!=NULL && cursor->name!=NULL){
1221#ifdef DEBUG
1222    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1223    dumpElements(e);
1224    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1225#endif
1226    tmp=(elements*)malloc(ELEMENTS_SIZE);
1227    tmp->name=zStrdup(cursor->name);
1228    tmp->content=NULL;
1229    addMapToMap(&tmp->content,cursor->content);
1230    tmp->metadata=NULL;
1231    addMapToMap(&tmp->metadata,cursor->metadata);
1232    tmp->additional_parameters=NULL;
1233    addMapToMap(&tmp->additional_parameters,cursor->additional_parameters);
1234    if(cursor->format!=NULL)
1235      tmp->format=zStrdup(cursor->format);
1236    else
1237      tmp->format=NULL;
1238    if(cursor->defaults!=NULL){
1239      tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
1240      tmp->defaults->content=NULL;
1241      addMapToMap(&tmp->defaults->content,cursor->defaults->content);
1242      tmp->defaults->next=NULL;
1243#ifdef DEBUG
1244      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1245      dumpMap(tmp->defaults->content);
1246#endif
1247    }else
1248      tmp->defaults=NULL;
1249    if(cursor->supported!=NULL && cursor->supported->content!=NULL){
1250      iotype *tmp2=cursor->supported->next;
1251      tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
1252      tmp->supported->content=NULL;
1253      addMapToMap(&tmp->supported->content,cursor->supported->content);
1254      tmp->supported->next=NULL;
1255            while(tmp2!=NULL){
1256        addMapToIoType(&tmp->supported,tmp2->content);
1257#ifdef DEBUG
1258        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
1259        dumpMap(tmp->defaults->content);
1260#endif
1261        tmp2=tmp2->next;
1262      }
1263    }
1264    else
1265      tmp->supported=NULL;
1266    if(cursor->child!=NULL)
1267      tmp->child=dupElements(cursor->child);
1268    else
1269      tmp->child=NULL;
1270    if(cursor->next!=NULL)
1271      tmp->next=dupElements(cursor->next);
1272    else
1273      tmp->next=NULL;
1274  }
1275  return tmp;
1276}
1277
1278/**
1279 * Add an elements to another elements.
1280 *
1281 * @see dupElements
1282 * @param m the elements to add the e
1283 * @param e the elements to be added to m
1284 */
1285void addToElements(elements** m,elements* e){
1286  elements* tmp=e;
1287  if(*m==NULL){
1288    (*m)=dupElements(tmp);
1289  }else{
1290    addToElements(&(*m)->next,tmp);
1291  }
1292}
1293
1294/**
1295 * Set the name of a service
1296 *
1297 * @param name the service name
1298 */
1299void setServiceName(service** serv,char* name){
1300  service* res=*serv;
1301  res->name=zStrdup(name);
1302  res->content=NULL;
1303  res->metadata=NULL;
1304  res->inputs=NULL;
1305  res->outputs=NULL;
1306}
1307
1308/**
1309 * Dump a service on stderr
1310 *
1311 * @param s the service to dump
1312 */
1313void dumpService(service* s){
1314  if(s==NULL)
1315    return;
1316  fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
1317  if(s->content!=NULL){
1318    fprintf(stderr,"CONTENT MAP\n");
1319    dumpMap(s->content);
1320    if(s->metadata!=NULL)
1321      fprintf(stderr,"CONTENT METADATA\n");
1322    dumpMap(s->metadata);
1323    if(s->additional_parameters!=NULL)
1324      fprintf(stderr,"CONTENT AdditionalParameters\n");
1325    dumpMap(s->additional_parameters);
1326  }
1327  if(s->inputs!=NULL){
1328    fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
1329    dumpElements(s->inputs);
1330  }
1331  if(s->outputs!=NULL){
1332    fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
1333    dumpElements(s->outputs);
1334  }
1335  fprintf(stderr,"++++++++++++++++++\n");
1336}
1337
1338/**
1339 * Dump a service on stderr using the YAML syntaxe
1340 *
1341 * @param s the service to dump
1342 */
1343void dumpServiceAsYAML(service* s){
1344  int i;
1345  fprintf(stderr,"# %s\n\n",s->name);
1346  if(s->content!=NULL){
1347    map* mcurs=s->content;
1348    dumpMap(mcurs);
1349    mcurs=s->metadata;
1350    if(mcurs!=NULL){
1351      fprintf(stderr,"MetaData:\n");
1352      while(mcurs!=NULL){
1353        for(i=0;i<2;i++)
1354          fprintf(stderr," ");
1355        _dumpMap(mcurs);
1356        mcurs=mcurs->next;
1357      }
1358    }
1359  }
1360  if(s->inputs!=NULL){
1361    fprintf(stderr,"\ninputs:\n");
1362    dumpElementsAsYAML(s->inputs,0);
1363  }
1364  if(s->outputs!=NULL){
1365    fprintf(stderr,"\noutputs:\n");
1366    dumpElementsAsYAML(s->outputs,0);
1367  }
1368}
1369
1370/**
1371 * Duplicate a service
1372 *
1373 * @param s the service to clone
1374 * @return the allocated service containing a copy of the serfvice s
1375 */
1376service* dupService(service* s){
1377  service *res=(service*)malloc(SERVICE_SIZE);
1378  res->name=zStrdup(s->name);
1379  res->content=NULL;
1380  addMapToMap(&res->content,s->content);
1381  res->metadata=NULL;
1382  addMapToMap(&res->metadata,s->metadata);
1383  res->additional_parameters=NULL;
1384  addMapToMap(&res->additional_parameters,s->additional_parameters);
1385  res->inputs=dupElements(s->inputs);
1386  res->outputs=dupElements(s->outputs);
1387  return res;
1388}
1389
1390/**
1391 * Print the registry on stderr.
1392 *
1393 * @param r the registry
1394 */
1395void dumpRegistry(registry* r){
1396  registry* p=r;
1397  while(p!=NULL){
1398    services* s=p->content;
1399    fprintf(stderr,"%s \n",p->name);
1400    s=p->content;
1401    while(s!=NULL){
1402      dumpService(s->content);
1403      s=s->next;
1404    }
1405    p=p->next;
1406  }
1407}
1408
1409/**
1410 * Add a service to the registry
1411 *
1412 * @param reg the resgitry to add the service
1413 * @param name the registry name to update
1414 * @param content the service to add
1415 */
1416bool addServiceToRegistry(registry** reg,char* name,service* content){
1417  registry *l=*reg;
1418  int isInitial=-1;
1419  if(l==NULL){
1420    l=(registry*)malloc(REGISTRY_SIZE);
1421    isInitial=1;
1422  }
1423  if(l!=NULL){
1424    int hasLevel=-1;
1425    while(isInitial<0 && l!=NULL){
1426      if(l->name!=NULL && strcasecmp(name,l->name)==0){
1427        hasLevel=1;
1428        break;
1429      }
1430      l=l->next;
1431    }
1432    if(hasLevel<0){
1433      if(isInitial<0)
1434        l=(registry*)malloc(REGISTRY_SIZE);
1435      l->name=zStrdup(name);
1436      l->content=NULL;
1437      l->next=NULL;
1438    }
1439    if(l->content==NULL){
1440      l->content=(services*)malloc(SERVICES_SIZE);
1441      l->content->content=dupService(content);
1442      l->content->next=NULL;
1443    }
1444    else{
1445      services* s=l->content;
1446      while(s->next!=NULL)
1447        s=s->next;
1448      s->next=(services*)malloc(SERVICES_SIZE);
1449      s->next->content=dupService(content);
1450      s->next->next=NULL;
1451    }
1452    l->next=NULL;
1453    if(isInitial>0)
1454      *reg=l;
1455    else{
1456      registry *r=*reg;
1457      while(r->next!=NULL)
1458        r=r->next;
1459      r->next=l;
1460      r->next->next=NULL;
1461    }
1462    return true;
1463  }
1464  else
1465    return false;
1466}
1467
1468/**
1469 * Free memory allocated for the registry
1470 *
1471 * @param r the registry
1472 */
1473void freeRegistry(registry** r){
1474  registry* lr=*r;
1475  while(lr!=NULL){
1476    services* s=lr->content;
1477    free(lr->name);
1478    while(s!=NULL){
1479      service* s1=s->content;
1480      s=s->next;
1481      if(s1!=NULL){
1482        freeService(&s1);
1483        free(s1);
1484        s1=NULL;
1485      }
1486    }
1487    lr=lr->next;
1488  }   
1489}
1490
1491/**
1492 * Access a service in the registry
1493 *
1494 * @param r the registry
1495 * @param level the regitry to search ("concept", "generic" or "implementation")
1496 * @param sname the service name
1497 * @return the service pointer if a corresponding service was found or NULL
1498 */
1499service* getServiceFromRegistry(registry* r,char  *level,char* sname){
1500  registry *lr=r;
1501  while(lr!=NULL){
1502    if(strcasecmp(lr->name,level)==0){
1503      services* s=lr->content;
1504      while(s!=NULL){
1505        if(s->content!=NULL && strcasecmp(s->content->name,sname)==0)
1506          return s->content;
1507        s=s->next;
1508      }
1509      break;
1510    }
1511    lr=lr->next;
1512  }
1513  return NULL;
1514}
1515
1516/**
1517 * Apply inheritance to an out map from a reference in map
1518 *
1519 * @param out the map to update
1520 * @param in the reference map (containing inherited properties)
1521 */
1522void inheritMap(map** out,map* in){
1523  map* content=in;
1524  if((*out)==NULL){
1525    addMapToMap(out,in);
1526    return;
1527  }
1528  while(content!=NULL){
1529    map* cmap=getMap(*out,content->name);
1530    if(cmap==NULL)
1531      addToMap(*out,content->name,content->value);
1532    content=content->next;
1533  }
1534}
1535
1536/**
1537 * Apply inheritance to an out iotype from a reference in iotype
1538 *
1539 * @param out the iotype to update
1540 * @param in the reference iotype (containing inherited properties)
1541 */
1542void inheritIOType(iotype** out,iotype* in){
1543  iotype* io=in;
1544  iotype* oio=*out;
1545  if(io!=NULL){
1546    if(*out==NULL){
1547      *out=(iotype*)malloc(IOTYPE_SIZE);
1548      (*out)->content=NULL;
1549      addMapToMap(&(*out)->content,io->content);
1550      (*out)->next=NULL;
1551      oio=*out;
1552      inheritIOType(&oio->next,io->next);
1553    }else{
1554      inheritIOType(&oio->next,io->next);
1555    }
1556  }
1557}
1558
1559/**
1560 * Apply inheritance to an out elements from a reference in elements
1561 *
1562 * @param out the elements to update
1563 * @param in the reference elements (containing inherited properties)
1564 */
1565void inheritElements(elements** out,elements* in){
1566  elements* content=in;
1567  while(content!=NULL && *out!=NULL){
1568    elements* cmap=getElements(*out,content->name);
1569    if(cmap==NULL)
1570      addToElements(out,content);
1571    else{
1572      inheritMap(&cmap->content,content->content);
1573      inheritMap(&cmap->metadata,content->metadata);
1574      if(cmap->format==NULL && content->format!=NULL)
1575        cmap->format=zStrdup(content->format);
1576      inheritIOType(&cmap->defaults,content->defaults);
1577      if(cmap->supported==NULL)
1578        inheritIOType(&cmap->supported,content->supported);
1579      else{
1580        iotype* p=content->supported;
1581        while(p!=NULL){
1582          addMapToIoType(&cmap->supported,p->content);
1583          p=p->next;
1584        }
1585      }
1586    }
1587    content=content->next;
1588  }
1589}
1590
1591/**
1592 * Apply inheritance to a service based on a registry
1593 *
1594 * @param r the registry storing profiles hierarchy
1595 * @param s the service to update depending on its inheritance
1596 */
1597void inheritance(registry *r,service** s){
1598  service* ls=*s;
1599  map *profile,*level;
1600  if(r==NULL)
1601    return;
1602  if(ls==NULL || ls->content==NULL)
1603    return;
1604  profile=getMap(ls->content,"extend");
1605  level=getMap(ls->content,"level");
1606  if(profile!=NULL&&level!=NULL){
1607    service* s1;
1608    if(strncasecmp(level->value,"profile",7)==0)
1609      s1=getServiceFromRegistry(r,(char*)"generic",profile->value);
1610    else
1611      s1=getServiceFromRegistry(r,level->value,profile->value);
1612     
1613    inheritMap(&ls->content,s1->content);
1614    inheritMap(&ls->metadata,s1->metadata);
1615    if(ls->inputs==NULL && s1->inputs!=NULL){
1616      ls->inputs=dupElements(s1->inputs);
1617    }else{
1618      inheritElements(&ls->inputs,s1->inputs);
1619    }
1620    if(ls->outputs==NULL && s1->outputs!=NULL){
1621      ls->outputs=dupElements(s1->outputs);
1622    }else
1623      inheritElements(&ls->outputs,s1->outputs);
1624  }
1625}
1626
1627/**
1628 * Convert a maps to a char*** (only used for Fortran support)
1629 *
1630 * @param m the maps to convert
1631 * @param c the resulting array
1632 */
1633void mapsToCharXXX(maps* m,char*** c){
1634  maps* tm=m;
1635  int i=0;
1636  int j=0;
1637  char tmp[10][30][1024];
1638  memset(tmp,0,1024*10*10);
1639  while(tm!=NULL){
1640    map* tc=tm->content;
1641    if(i>=10)
1642      break;
1643    strcpy(tmp[i][j],"name");
1644    j++;
1645    strcpy(tmp[i][j],tm->name);
1646    j++;
1647    while(tc!=NULL){
1648      if(j>=30)
1649        break;
1650      strcpy(tmp[i][j],tc->name);
1651      j++;
1652      strcpy(tmp[i][j],tc->value);
1653      j++;
1654      tc=tc->next;
1655    }
1656    tm=tm->next;
1657    j=0;
1658    i++;
1659  }
1660  memcpy(c,tmp,10*10*1024);
1661}
1662
1663/**
1664 * Convert a char*** to a maps (only used for Fortran support)
1665 *
1666 * @param c the array to convert
1667 * @param m the resulting maps
1668 */
1669void charxxxToMaps(char*** c,maps**m){
1670  maps* trorf=*m;
1671  int i,j;
1672  char tmp[10][30][1024];
1673  memcpy(tmp,c,10*30*1024);
1674  for(i=0;i<10;i++){
1675    if(strlen(tmp[i][1])==0)
1676      break;
1677    trorf->name=tmp[i][1];
1678    trorf->content=NULL;
1679    trorf->next=NULL;
1680    for(j=2;j<29;j+=2){
1681      if(strlen(tmp[i][j+1])==0)
1682        break;
1683      if(trorf->content==NULL)
1684        trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
1685      else
1686        addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
1687    }
1688    trorf=trorf->next;
1689  }
1690  m=&trorf;
1691}
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