Ignore:
Timestamp:
Dec 18, 2020, 2:13:22 PM (3 years ago)
Author:
djay
Message:

Add support for the two inputs / outputs syntaxes discussed in SWG in both the ZOO-Kernel and the HTML basic UI. Update documentation, add a section for the ZOO-API in Python language section. Rename variables in service.c to ease readabiliy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service.c

    r961 r967  
    3939 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c
    4040 */
    41 int snprintf(char *buffer, size_t n, const char *format, ...)
     41int snprintf(char *pcBuffer, size_t n, const char *pccFormat, ...)
    4242{
    4343  va_list argp;
    4444  int ret;
    45   va_start(argp, format);
    46   ret = _vscprintf(format, argp);
    47   vsnprintf_s(buffer, n, _TRUNCATE, format, argp);
     45  va_start(argp, pccFormat);
     46  ret = _vscprintf(pccFormat, argp);
     47  vsnprintf_s(pcBuffer, n, _TRUNCATE, pccFormat, argp);
    4848  va_end(argp);
    4949  return ret;
     
    5454 * Dump a map on stderr
    5555 *
    56  * @param t the map to dump
    57  */
    58 void _dumpMap(map* t){
    59   if(t!=NULL){
    60     fprintf(stderr,"%s: %s\n",t->name,t->value);
     56 * @param pmMap the map to dump
     57 */
     58void _dumpMap(map* pmMap){
     59  if(pmMap!=NULL){
     60    fprintf(stderr,"%s: %s\n",pmMap->name,pmMap->value);
    6161    fflush(stderr);
    6262  }else{
     
    6969 * Dump a map on stderr, see _dumpMap()
    7070 *
    71  * @param t the map to dump
    72  */
    73 void dumpMap(map* t){
    74   map* tmp=t;
    75   while(tmp!=NULL){
    76     _dumpMap(tmp);
    77     tmp=tmp->next;
     71 * @param pmMap the map to dump
     72 */
     73void dumpMap(map* pmMap){
     74  map* pmTmp=pmMap;
     75  while(pmTmp!=NULL){
     76    _dumpMap(pmTmp);
     77    pmTmp=pmTmp->next;
    7878  }
    7979}
     
    8282 * Dump a map to a file
    8383 *
    84  * @param t the map to dump to file
    85  * @param file the file pointer to store the map
    86  */
    87 void dumpMapToFile(map* t,FILE* file){
    88   map* tmp=t;
    89   while(tmp!=NULL){
    90     fprintf(file,"%s = %s\n",tmp->name,tmp->value);
    91     tmp=tmp->next;
     84 * @param pmMap the map to dump to file
     85 * @param pfFile the file pointer to store the map
     86 */
     87void dumpMapToFile(map* pmMap,FILE* pfFile){
     88  map* pmTmp=pmMap;
     89  while(pmTmp!=NULL){
     90    fprintf(pfFile,"%s = %s\n",pmTmp->name,pmTmp->value);
     91    pmTmp=pmTmp->next;
    9292  }
    9393}
     
    9696 * Dump a maps on stderr, see dumpMap().
    9797 *
    98  * @param m the map to dump
    99  */
    100 void dumpMaps(maps* m){
    101   maps* tmp=m;
    102   while(tmp!=NULL){
    103     fprintf(stderr,"MAP => [%s] \n",tmp->name);
    104     fprintf(stderr," * CONTENT [%s] \n",tmp->name);
    105     dumpMap(tmp->content);
    106     if(tmp->child!=NULL){
    107       fprintf(stderr," * CHILD [%s] \n",tmp->name);
    108       dumpMaps(tmp->child);
    109       fprintf(stderr," * /CHILD [%s] \n",tmp->name);
    110     }
    111     tmp=tmp->next;
     98 * @param pmMap the map to dump
     99 */
     100void dumpMaps(maps* pmMap){
     101  maps* pmTmp=pmMap;
     102  while(pmTmp!=NULL){
     103    fprintf(stderr,"MAP => [%s] \n",pmTmp->name);
     104    fprintf(stderr," * CONTENT [%s] \n",pmTmp->name);
     105    dumpMap(pmTmp->content);
     106    if(pmTmp->child!=NULL){
     107      fprintf(stderr," * CHILD [%s] \n",pmTmp->name);
     108      dumpMaps(pmTmp->child);
     109      fprintf(stderr," * /CHILD [%s] \n",pmTmp->name);
     110    }
     111    pmTmp=pmTmp->next;
    112112  }
    113113}
     
    116116 * Dump a maps to a file, see dumpMapToFile().
    117117 *
    118  * @param m the map to dump
    119  * @param file the the file pointer to store the map
    120  */
    121 void _dumpMapsToFile(maps* m,FILE* file,int limit){
    122   maps* tmp=m;
     118 * @param pmsMaps the map to dump
     119 * @param psFile the the file pointer to store the map
     120 * @param iLimit the number of maps to print (0 for no limit)
     121 */
     122void _dumpMapsToFile(maps* pmsMaps,FILE* psFile,int iLimit){
     123  maps* tmp=pmsMaps;
    123124  int cnt=0;
    124125  while(tmp!=NULL){
    125     fprintf(file,"[%s]\n",tmp->name);
     126    fprintf(psFile,"[%s]\n",tmp->name);
    126127    if(tmp->child!=NULL){
    127       _dumpMapsToFile(tmp->child,file,limit);
     128      _dumpMapsToFile(tmp->child,psFile,iLimit);
    128129    }else
    129       dumpMapToFile(tmp->content,file);
    130     fflush(file);
     130      dumpMapToFile(tmp->content,psFile);
     131    fflush(psFile);
    131132    tmp=tmp->next;
    132133    cnt++;
    133     if(limit>=0 && cnt==limit)
     134    if(iLimit>=0 && cnt==iLimit)
    134135      tmp=NULL;
    135136  }
    136   fflush(file);
     137  fflush(psFile);
    137138}
    138139
     
    140141 * Dump a maps to a file, see _dumpMapsToFile().
    141142 *
    142  * @param m the map to dump
    143  * @param file_path the full path to the file name to store the map
    144  * @param limit the number limiting the maps to be dumped
    145  */
    146 void dumpMapsToFile(maps* m,char* file_path,int limit){
    147   FILE* file=fopen(file_path,"w+");
    148   _dumpMapsToFile(m,file,limit);
    149   fflush(file);
    150   fclose(file);
     143 * @param pmsMaps the map to dump
     144 * @param pcaFilePath the the file pointer to store the map
     145 * @param iLimit the number of maps to print (0 for no limit)
     146 */
     147void dumpMapsToFile(maps* pmsMaps,char* pcaFilePath,int iLimit){
     148  FILE* psFile=fopen(pcaFilePath,"w+");
     149  _dumpMapsToFile(pmsMaps,psFile,iLimit);
     150  fflush(psFile);
     151  fclose(psFile);
    151152}
    152153
     
    157158 */
    158159iotype* createIoType(){
    159   iotype* io=(iotype*)malloc(IOTYPE_SIZE);
    160   io->content=NULL;
    161   io->next=NULL;
    162   return io;
     160  iotype* pioIO=(iotype*)malloc(IOTYPE_SIZE);
     161  pioIO->content=NULL;
     162  pioIO->next=NULL;
     163  return pioIO;
    163164}
    164165
     
    166167 * Create a new map
    167168 *
    168  * @param name the key to add to the map
    169  * @param value the corresponding value to add to the map
     169 * @param pccName the key to add to the map
     170 * @param pccValue the corresponding value to add to the map
    170171 * @return a pointer to the allocated map
    171172 */
    172 map* createMap(const char* name,const char* value){
    173   map* tmp=(map *)malloc(MAP_SIZE);
    174   tmp->name=zStrdup(name);
    175   tmp->value=zStrdup(value);
    176   tmp->next=NULL;
    177   return tmp;
     173map* createMap(const char* pccName,const char* pccValue){
     174  map* pmTtmp=(map *)malloc(MAP_SIZE);
     175  pmTtmp->name=zStrdup(pccName);
     176  pmTtmp->value=zStrdup(pccValue);
     177  pmTtmp->next=NULL;
     178  return pmTtmp;
    178179}
    179180
     
    181182 * Create a new maps with the given name
    182183 *
    183  * @param name of the maps
     184 * @param pccName of the maps
    184185 * @return the allocated map
    185186 */
    186 maps* createMaps(const char* name){
    187   maps* tmp = (maps *) malloc (MAPS_SIZE);
    188   tmp->name = zStrdup (name);
    189   tmp->content = NULL;
    190   tmp->child = NULL;
    191   tmp->next = NULL;
    192   return tmp;
     187maps* createMaps(const char* pccName){
     188  maps* pmTmp = (maps *) malloc (MAPS_SIZE);
     189  pmTmp->name = zStrdup (pccName);
     190  pmTmp->content = NULL;
     191  pmTmp->child = NULL;
     192  pmTmp->next = NULL;
     193  return pmTmp;
    193194}
    194195
     
    196197 * Count number of map in a map
    197198 *
    198  * @param m the map to count
     199 * @param pmMap the map to count
    199200 * @return number of map in a map
    200201 */
    201 int count(map* m){
    202   map* tmp=m;
     202int count(map* pmMap){
     203  map* pmTmp=pmMap;
    203204  int c=0;
    204   while(tmp!=NULL){
     205  while(pmTmp!=NULL){
    205206    c++;
    206     tmp=tmp->next;
     207    pmTmp=pmTmp->next;
    207208  }
    208209  return c;
     
    212213 * Count number of maps in a maps
    213214 *
    214  * @param m the maps to count
     215 * @param pmMap the maps to count
    215216 * @return number of maps in a maps
    216217 */
    217 int maps_length(maps* m){
    218   maps* tmp=m;
     218int maps_length(maps* pmMap){
     219  maps* pmTmp=pmMap;
    219220  int c=0;
    220   while(tmp!=NULL){
     221  while(pmTmp!=NULL){
    221222    c++;
    222     tmp=tmp->next;
     223    pmTmp=pmTmp->next;
    223224  }
    224225  return c;
     
    228229 * Verify if a key exist in a map
    229230 *
    230  * @param m the map to search for the key
    231  * @param key the key to search in the map
     231 * @param pmMap the map to search for the key
     232 * @param pccKey the key to search in the map
    232233 * @return true if the key wwas found, false in other case
    233234 */
    234 bool hasKey(map* m,const char *key){
    235   map* tmp=m;
    236   while(tmp!=NULL){
    237     if(strcasecmp(tmp->name,key)==0)
     235bool hasKey(map* pmMap,const char *pccKey){
     236  map* pmTmp=pmMap;
     237  while(pmTmp!=NULL){
     238    if(strcasecmp(pmTmp->name,pccKey)==0)
    238239      return true;
    239     tmp=tmp->next;
     240    pmTmp=pmTmp->next;
    240241  }
    241242#ifdef DEBUG_MAP
     
    248249 * Access a specific maps
    249250 *
    250  * @param m the maps to search for the key
    251  * @param key the key to search in the maps
     251 * @param pmMap the maps to search for the key
     252 * @param pccKey the key to search in the maps
    252253 * @return a pointer on the maps found or NULL if not found
    253254 */
    254 maps* getMaps(maps* m,const char *key){
    255   maps* tmp=m;
    256   while(tmp!=NULL){
    257     if(strcasecmp(tmp->name,key)==0){
    258       return tmp;
    259     }
    260     tmp=tmp->next;
     255maps* getMaps(maps* pmsMaps,const char *pccKey){
     256  maps* pmTmp=pmsMaps;
     257  while(pmTmp!=NULL){
     258    if(strcasecmp(pmTmp->name,pccKey)==0){
     259      return pmTmp;
     260    }
     261    pmTmp=pmTmp->next;
    261262  }
    262263  return NULL;
     
    266267 * Access a specific map
    267268 *
    268  * @param m the map to search for the key
    269  * @param key the key to search in the map
     269 * @param pmMap the map to search for the key
     270 * @param pccKey the key to search in the map
    270271 * @return a pointer on the map found or NULL if not found
    271272 */
    272 map* getMap(map* m,const char *key){
    273   map* tmp=m;
    274   while(tmp!=NULL){
    275     if(strcasecmp(tmp->name,key)==0){
    276       return tmp;
    277     }
    278     tmp=tmp->next;
     273map* getMap(map* pmMap,const char *pccKey){
     274  map* pmTmp=pmMap;
     275  while(pmTmp!=NULL){
     276    if(strcasecmp(pmTmp->name,pccKey)==0){
     277      return pmTmp;
     278    }
     279    pmTmp=pmTmp->next;
    279280  }
    280281  return NULL;
     
    285286 * Access the last map
    286287 *
    287  * @param m the map to search for the lastest map
     288 * @param pmMap the map to search for the lastest map
    288289 * @return a pointer on the lastest map found or NULL if not found
    289290 */
    290 map* getLastMap(map* m){
    291   map* tmp=m;
    292   while(tmp!=NULL){
    293     if(tmp->next==NULL){
    294       return tmp;
    295     }
    296     tmp=tmp->next;
     291map* getLastMap(map* pmMap){
     292  map* pmTmp=pmMap;
     293  while(pmTmp!=NULL){
     294    if(pmTmp->next==NULL){
     295      return pmTmp;
     296    }
     297    pmTmp=pmTmp->next;
    297298  }
    298299  return NULL;
     
    302303 * Access a specific map from a maps
    303304 *
    304  * @param m the maps to search for the key
    305  * @param key the key to search in the maps
    306  * @param subkey the key to search in the map (found for the key, if any)
     305 * @param pmMap the maps to search for the key
     306 * @param pccKey the key to search in the maps
     307 * @param pccSubkey the key to search in the map (found for the key, if any)
    307308 * @return a pointer on the map found or NULL if not found
    308309 */
    309 map* getMapFromMaps(maps* m,const char* key,const char* subkey){
    310   maps* _tmpm=getMaps(m,key);
    311   if(_tmpm!=NULL){
    312     map* _ztmpm=getMap(_tmpm->content,subkey);
    313     return _ztmpm;
     310map* getMapFromMaps(maps* pmMap,const char* pccKey,const char* pccSubkey){
     311  maps* pmTmp=getMaps(pmMap,pccKey);
     312  if(pmTmp!=NULL){
     313    map* pmTmp1=getMap(pmTmp->content,pccSubkey);
     314    return pmTmp1;
    314315  }
    315316  else return NULL;
     
    320321 * Require to call free on mo after calling this function.
    321322 *
    322  * @param mo the map to free
    323  */
    324 void freeMap(map** mo){
    325   map* _cursor=*mo;
    326   if(_cursor!=NULL){
     323 * @param pmMap the map to free
     324 */
     325void freeMap(map** pmMap){
     326  map* pmCursor=*pmMap;
     327  if(pmCursor!=NULL){
    327328#ifdef DEBUG
    328329    fprintf(stderr,"freeMap\n");
    329330#endif
    330     if(_cursor->name!=NULL)
    331       free(_cursor->name);
    332     if(_cursor->value!=NULL)
    333       free(_cursor->value);
    334     if(_cursor->next!=NULL){
    335       freeMap(&_cursor->next);
    336       if(_cursor->next!=NULL)
    337         free(_cursor->next);
     331    if(pmCursor->name!=NULL)
     332      free(pmCursor->name);
     333    if(pmCursor->value!=NULL)
     334      free(pmCursor->value);
     335    if(pmCursor->next!=NULL){
     336      freeMap(&pmCursor->next);
     337      if(pmCursor->next!=NULL)
     338        free(pmCursor->next);
    338339    }
    339340  }
     
    344345 * Require to call free on mo after calling this function.
    345346 *
    346  * @param mo the maps to free
    347  */
    348 void freeMaps(maps** mo){
    349   maps* _cursor=*mo;
    350   if(_cursor && _cursor!=NULL){
     347 * @param pmMap the maps to free
     348 */
     349void freeMaps(maps** pmMap){
     350  maps* pmCursor=*pmMap;
     351  if(pmCursor && pmCursor!=NULL){
    351352#ifdef DEBUG
    352353    fprintf(stderr,"freeMaps\n");
    353354#endif
    354     free(_cursor->name);
    355     if(_cursor->content!=NULL){
    356       freeMap(&_cursor->content);
    357       free(_cursor->content);
    358     }
    359     if(_cursor->child!=NULL){
    360       freeMaps(&_cursor->child);
    361       free(_cursor->child);
    362     }
    363     if(_cursor->next!=NULL){
    364       freeMaps(&_cursor->next);
    365       free(_cursor->next);
     355    free(pmCursor->name);
     356    if(pmCursor->content!=NULL){
     357      freeMap(&pmCursor->content);
     358      free(pmCursor->content);
     359    }
     360    if(pmCursor->child!=NULL){
     361      freeMaps(&pmCursor->child);
     362      free(pmCursor->child);
     363    }
     364    if(pmCursor->next!=NULL){
     365      freeMaps(&pmCursor->next);
     366      free(pmCursor->next);
    366367    }
    367368  }
     
    371372 * Verify if an elements contains a name equal to the given key.
    372373 *
    373  * @param e the elements to search for the key
    374  * @param key the elements name to search
     374 * @param peElem the elements to search for the key
     375 * @param pccKey the elements name to search
    375376 * @return true if the elements contains the name, false in other cases.
    376377 */
    377 bool hasElement(elements* e,const char* key){
    378   elements* tmp=e;
    379   while(tmp!=NULL){
    380     if(strcasecmp(key,tmp->name)==0)
     378bool hasElement(elements* peElem,const char* pccKey){
     379  elements* peTmp=peElem;
     380  while(peTmp!=NULL){
     381    if(strcasecmp(pccKey,peTmp->name)==0)
    381382      return true;
    382     tmp=tmp->next;
     383    peTmp=peTmp->next;
    383384  }
    384385  return false;
     
    388389 * Access a specific elements named key.
    389390 *
    390  * @param m the elements to search
    391  * @param key the elements name to search
     391 * @param peElem the elements to search
     392 * @param pccKey the elements name to search
    392393 * @return a pointer to the specific element if found, NULL in other case.
    393394 */
    394 elements* getElements(elements* m,const char *key){
    395   elements* tmp=m;
    396   while(tmp!=NULL){
    397     if(strcasecmp(tmp->name,key)==0)
    398       return tmp;
    399     tmp=tmp->next;
     395elements* getElements(elements* peElem,const char *pccKey){
     396  elements* peTmp=peElem;
     397  while(peTmp!=NULL){
     398    if(strcasecmp(peTmp->name,pccKey)==0)
     399      return peTmp;
     400    peTmp=peTmp->next;
    400401  }
    401402  return NULL;
     
    406407 * Require to call free on i after calling this function.
    407408 *
    408  * @param i the iotype to free
    409  */
    410 void freeIOType(iotype** i){
    411   iotype* _cursor=*i;
    412   if(_cursor!=NULL){
    413     if(_cursor->next!=NULL){
    414       freeIOType(&_cursor->next);
    415       free(_cursor->next);
    416     }
    417     freeMap(&_cursor->content);
    418     free(_cursor->content);
     409 * @param piotIO the iotype to free
     410 */
     411void freeIOType(iotype** piotIO){
     412  iotype* piotCursor=*piotIO;
     413  if(piotCursor!=NULL){
     414    if(piotCursor->next!=NULL){
     415      freeIOType(&piotCursor->next);
     416      free(piotCursor->next);
     417    }
     418    freeMap(&piotCursor->content);
     419    free(piotCursor->content);
    419420  }
    420421}
     
    424425 * Require to call free on e after calling this function.
    425426 *
    426  * @param e the iotype to free
    427  */
    428 void freeElements(elements** e){
    429   elements* tmp=*e;
    430   if(tmp!=NULL){
    431     if(tmp->name!=NULL)
    432       free(tmp->name);
    433     freeMap(&tmp->content);
    434     if(tmp->content!=NULL)
    435       free(tmp->content);
    436     freeMap(&tmp->metadata);
    437     if(tmp->metadata!=NULL)
    438       free(tmp->metadata);
    439     freeMap(&tmp->additional_parameters);
    440     if(tmp->additional_parameters!=NULL)
    441       free(tmp->additional_parameters);
    442     if(tmp->format!=NULL)
    443       free(tmp->format);
    444     freeElements(&tmp->child);
    445     if(tmp->child!=NULL){
    446       free(tmp->child);
    447     }
    448     if(tmp->defaults!=NULL){
    449       freeIOType(&tmp->defaults);
    450       free(tmp->defaults);
    451     }
    452     if(tmp->supported!=NULL){
    453       freeIOType(&tmp->supported);
    454       free(tmp->supported);
    455     }
    456     if(tmp->next!=NULL){
    457       freeElements(&tmp->next);
    458       free(tmp->next);
     427 * @param peElem the iotype to free
     428 */
     429void freeElements(elements** peElem){
     430  elements* peTmp=*peElem;
     431  if(peTmp!=NULL){
     432    if(peTmp->name!=NULL)
     433      free(peTmp->name);
     434    freeMap(&peTmp->content);
     435    if(peTmp->content!=NULL)
     436      free(peTmp->content);
     437    freeMap(&peTmp->metadata);
     438    if(peTmp->metadata!=NULL)
     439      free(peTmp->metadata);
     440    freeMap(&peTmp->additional_parameters);
     441    if(peTmp->additional_parameters!=NULL)
     442      free(peTmp->additional_parameters);
     443    if(peTmp->format!=NULL)
     444      free(peTmp->format);
     445    freeElements(&peTmp->child);
     446    if(peTmp->child!=NULL){
     447      free(peTmp->child);
     448    }
     449    if(peTmp->defaults!=NULL){
     450      freeIOType(&peTmp->defaults);
     451      free(peTmp->defaults);
     452    }
     453    if(peTmp->supported!=NULL){
     454      freeIOType(&peTmp->supported);
     455      free(peTmp->supported);
     456    }
     457    if(peTmp->next!=NULL){
     458      freeElements(&peTmp->next);
     459      free(peTmp->next);
    459460    }
    460461  }
     
    469470 */
    470471service* createService(){
    471   service *s1 = (service *) malloc (SERVICE_SIZE);
    472   s1->name=NULL;
    473   s1->content=NULL;
    474   s1->metadata=NULL;
    475   s1->additional_parameters=NULL;
    476   s1->inputs=NULL;
    477   s1->outputs=NULL;
    478   return s1;
     472  service *psService = (service *) malloc (SERVICE_SIZE);
     473  psService->name=NULL;
     474  psService->content=NULL;
     475  psService->metadata=NULL;
     476  psService->additional_parameters=NULL;
     477  psService->inputs=NULL;
     478  psService->outputs=NULL;
     479  return psService;
    479480}
    480481
     
    483484 * Require to be invoked for every createService call.
    484485 *
    485  * @param s the service to free
    486  */
    487 void freeService(service** s){
    488   service* tmp=*s;
    489   if(tmp!=NULL){
    490     if(tmp->name!=NULL)
    491       free(tmp->name);
    492     freeMap(&tmp->content);
    493     if(tmp->content!=NULL)
    494       free(tmp->content);
    495     freeMap(&tmp->metadata);
    496     if(tmp->metadata!=NULL)
    497       free(tmp->metadata);
    498     freeMap(&tmp->additional_parameters);
    499     if(tmp->additional_parameters!=NULL)
    500       free(tmp->additional_parameters);
    501     freeElements(&tmp->inputs);
    502     if(tmp->inputs!=NULL)
    503       free(tmp->inputs);
    504     freeElements(&tmp->outputs);
    505     if(tmp->outputs!=NULL)
    506       free(tmp->outputs);
     486 * @param psService the service to free
     487 */
     488void freeService(service** psService){
     489  service* psTmp=*psService;
     490  if(psTmp!=NULL){
     491    if(psTmp->name!=NULL)
     492      free(psTmp->name);
     493    freeMap(&psTmp->content);
     494    if(psTmp->content!=NULL)
     495      free(psTmp->content);
     496    freeMap(&psTmp->metadata);
     497    if(psTmp->metadata!=NULL)
     498      free(psTmp->metadata);
     499    freeMap(&psTmp->additional_parameters);
     500    if(psTmp->additional_parameters!=NULL)
     501      free(psTmp->additional_parameters);
     502    freeElements(&psTmp->inputs);
     503    if(psTmp->inputs!=NULL)
     504      free(psTmp->inputs);
     505    freeElements(&psTmp->outputs);
     506    if(psTmp->outputs!=NULL)
     507      free(psTmp->outputs);
    507508  }
    508509}
     
    511512 * Add key value pair to an existing map.
    512513 *
    513  * @param m the map to add the KVP
    514  * @param n the key to add
    515  * @param v the corresponding value to add
    516  */
    517 void addToMap(map* m,const char* n,const char* v){
    518     if (m != NULL) { // knut: add NULL-pointer check
    519         if (hasKey(m, n) == false) {
    520             map* _cursor = m;
    521             while (_cursor->next != NULL) {
    522                 _cursor = _cursor->next;
    523             }
    524             _cursor->next = createMap(n, v);
    525         }
    526         else {
    527             map *tmp = getMap(m, n);
    528             if (tmp->value != NULL)
    529                 free(tmp->value);
    530             tmp->value = zStrdup(v);
    531         }
    532     }
     514 * @param pMap the map to add the KVP
     515 * @param pccName the key to add
     516 * @param pccValue the corresponding value to add
     517 */
     518void addToMap(map* pMap,const char* pccName,const char* pccValue){
     519  if (pMap != NULL) { // knut: add NULL-pointer check
     520    if (hasKey(pMap, pccName) == false) {
     521      map* pmCursor = pMap;
     522      while (pmCursor->next != NULL) {
     523        pmCursor = pmCursor->next;
     524      }
     525      pmCursor->next = createMap(pccName, pccValue);
     526    }
     527    else {
     528      map *tmp = getMap(pMap, pccName);
     529      if (tmp->value != NULL)
     530        free(tmp->value);
     531      tmp->value = zStrdup(pccValue);
     532    }
     533  }
    533534}
    534535
     
    536537 * Add a key and an integer value to an existing map.
    537538 *
    538  * @param m the map to add the KVP
    539  * @param n the key to add
    540  * @param v the corresponding value to add
    541  */
    542 void addIntToMap(map* m,const char* n,const int v){
    543   char svalue[10];
    544   sprintf(svalue,"%d",v);
    545   if(hasKey(m,n)==false){
    546     map* _cursor=m;
    547     while(_cursor->next!=NULL){
    548       _cursor=_cursor->next;
    549     }
    550     _cursor->next=createMap(n,svalue);
     539 * @param pMap the map to add the KVP
     540 * @param pccName the key to add
     541 * @param iValue the corresponding value to add
     542 */
     543void addIntToMap(map* pMap,const char* pccName,const int iValue){
     544  char acValue[10];
     545  sprintf(acValue,"%d",iValue);
     546  if(hasKey(pMap,pccName)==false){
     547    map* pmCursor=pMap;
     548    while(pmCursor->next!=NULL){
     549      pmCursor=pmCursor->next;
     550    }
     551    pmCursor->next=createMap(pccName,acValue);
    551552  }
    552553  else{
    553     map *tmp=getMap(m,n);
    554     if(tmp->value!=NULL)
    555       free(tmp->value);
    556     tmp->value=zStrdup(svalue);
     554    map *pmTmp=getMap(pMap,pccName);
     555    if(pmTmp->value!=NULL)
     556      free(pmTmp->value);
     557    pmTmp->value=zStrdup(acValue);
    557558  }
    558559}
     
    561562 * Add a key and a binary value to an existing map.
    562563 *
    563  * @param m the map to add the KVP
    564  * @param n the key to add
    565  * @param v the corresponding value to add
    566  * @param size the size of the given value
     564 * @param pMap the map to add the KVP
     565 * @param pccName the key to add
     566 * @param pccValue the corresponding value to add
     567 * @param iSize the size of the given value
    567568 * @return a pointer to the updated map m
    568569 */
    569 map* addToMapWithSize(map* m,const char* n,const char* v,int size){
    570   char sin[128];
    571   char sname[10]="size";
    572   map *tmp;
    573   if(hasKey(m,n)==false){
    574     map* _cursor=m;
     570map* addToMapWithSize(map* pMap,const char* pccName,const char* pccValue,int iSize){
     571  char acIn[128];
     572  char acName[10]="size";
     573  map *pmTmp;
     574  if(hasKey(pMap,pccName)==false){
     575    map* _cursor=pMap;
    575576    if(_cursor!=NULL){
    576       addToMap(m,n,"");
     577      addToMap(pMap,pccName,"");
    577578    }else{
    578       m=createMap(n,"");
    579     }
    580   }
    581   if(strlen(n)>5)
    582     sprintf(sname,"size_%s",n+6);
    583   tmp=getMap(m,n);
    584   if(tmp->value!=NULL)
    585     free(tmp->value);
    586   tmp->value=(char*)malloc((size+1)*sizeof(char));
    587   if(v!=NULL)
    588     memmove(tmp->value,v,size*sizeof(char));
    589   tmp->value[size]=0;
    590   sprintf(sin,"%d",size);
    591   addToMap(m,sname,sin);
    592   return m;
     579      pMap=createMap(pccName,"");
     580    }
     581  }
     582  if(strlen(pccName)>5)
     583    sprintf(acName,"size_%s",pccName+6);
     584  pmTmp=getMap(pMap,pccName);
     585  if(pmTmp->value!=NULL)
     586    free(pmTmp->value);
     587  pmTmp->value=(char*)malloc((iSize+1)*sizeof(char));
     588  if(pccValue!=NULL)
     589    memmove(pmTmp->value,pccValue,iSize*sizeof(char));
     590  pmTmp->value[iSize]=0;
     591  sprintf(acIn,"%d",iSize);
     592  addToMap(pMap,acName,acIn);
     593  return pMap;
    593594}
    594595
     
    596597 * Add a map at the end of another map.
    597598 *
    598  * @param mo the map to add mi
    599  * @param mi the map to add to mo
    600  */
    601 void addMapToMap(map** mo,map* mi){
    602   map* tmp=mi;
    603   map* _cursor=*mo;
    604   while(tmp!=NULL){
    605     if(_cursor==NULL){
    606       *mo=createMap(tmp->name,tmp->value);
    607       (*mo)->next=NULL;
     599 * @param pmMapOut the map to add pmMapIn to
     600 * @param pmMapIn the map to add to pmMapOut
     601 */
     602void addMapToMap(map** pmMapOut,map* pmMapIn){
     603  map* pmTmp=pmMapIn;
     604  map* pmCursor=*pmMapOut;
     605  while(pmTmp!=NULL){
     606    if(pmCursor==NULL){
     607      *pmMapOut=createMap(pmTmp->name,pmTmp->value);
     608      (*pmMapOut)->next=NULL;
    608609    }
    609610    else{
    610       map* tmp1=getMap(*mo,tmp->name);
    611       if(tmp1==NULL){
    612         while(_cursor->next!=NULL)
    613           _cursor=_cursor->next;
    614         _cursor->next=createMap(tmp->name,tmp->value);
     611      map* pmTmp1=getMap(*pmMapOut,pmTmp->name);
     612      if(pmTmp1==NULL){
     613        while(pmCursor->next!=NULL)
     614          pmCursor=pmCursor->next;
     615        pmCursor->next=createMap(pmTmp->name,pmTmp->value);
    615616      }
    616617      else{
    617         addToMap(*mo,tmp->name,tmp->value);
     618        addToMap(*pmMapOut,pmTmp->name,pmTmp->value);
    618619      }
    619620    }
    620     _cursor=*mo;
    621     tmp=tmp->next;
     621    pmCursor=*pmMapOut;
     622    pmTmp=pmTmp->next;
    622623  }
    623624}
     
    626627 * Add a map to iotype.
    627628 *
    628  * @param io the iotype to add the map
    629  * @param mi the map to add to io
    630  */
    631 void addMapToIoType(iotype** io,map* mi){
    632   iotype* tmp=*io;
    633   while(tmp->next!=NULL){
    634     tmp=tmp->next;
    635   }
    636   tmp->next=(iotype*)malloc(IOTYPE_SIZE);
    637   tmp->next->content=NULL;
    638   addMapToMap(&tmp->next->content,mi);
    639   tmp->next->next=NULL;
     629 * @param piotType the iotype to add the map
     630 * @param pmMap the map to add to io
     631 */
     632void addMapToIoType(iotype** piotType,map* pmMap){
     633  iotype* piotTmp=*piotType;
     634  while(piotTmp->next!=NULL){
     635    piotTmp=piotTmp->next;
     636  }
     637  piotTmp->next=(iotype*)malloc(IOTYPE_SIZE);
     638  piotTmp->next->content=NULL;
     639  addMapToMap(&piotTmp->next->content,pmMap);
     640  piotTmp->next->next=NULL;
    640641}
    641642
     
    643644 * Access a specific map or set its value.
    644645 *
    645  * @param m the map to search for the key
    646  * @param key the key to search/add in the map
    647  * @param value the value to add if the key does not exist
     646 * @param ppmMap the map to search for the key
     647 * @param pccKey the key to search/add in the map
     648 * @param pccValue the value to add if the key does not exist
    648649 * @return a pointer on the map found or NULL if not found
    649650 */
    650 map* getMapOrFill(map** m,const char *key,const char* value){
    651   map* tmp=*m;
    652   map* tmpMap=getMap(tmp,key);
    653   if(tmpMap==NULL){
    654     if(tmp!=NULL){
    655       addToMap((*m),key,value);
     651map* getMapOrFill(map** ppmMap,const char *pccKey,const char* pccValue){
     652  map* pmTmp=*ppmMap;
     653  map* pmTmp1=getMap(pmTmp,pccKey);
     654  if(pmTmp1==NULL){
     655    if(pmTmp!=NULL){
     656      addToMap((*ppmMap),pccKey,pccValue);
    656657    }
    657658    else
    658       (*m)=createMap(key,value);
    659     tmpMap=getMap(*m,key);
    660   }
    661   return tmpMap;
     659      (*ppmMap)=createMap(pccKey,pccValue);
     660    pmTmp1=getMap(*ppmMap,pccKey);
     661  }
     662  return pmTmp1;
    662663}
    663664
     
    665666 * Verify if a map is contained in another map.
    666667 *
    667  * @param m the map to search for i
    668  * @param i the map to search in m
     668 * @param pmMap the map to search for i
     669 * @param pmSearch the map to search in m
    669670 * @return true if i was found in m, false in other case
    670671 */
    671 bool contains(map* m,map* i){
    672   while(i!=NULL){     
    673     if(strcasecmp(i->name,"value")!=0 &&
    674        strcasecmp(i->name,"xlink:href")!=0 &&
    675        strcasecmp(i->name,"useMapServer")!=0 &&
    676        strcasecmp(i->name,"asReference")!=0){
     672bool contains(map* pmMap,map* pmSearch){
     673  while(pmSearch!=NULL){     
     674    if(strcasecmp(pmSearch->name,"value")!=0 &&
     675       strcasecmp(pmSearch->name,"xlink:href")!=0 &&
     676       strcasecmp(pmSearch->name,"useMapServer")!=0 &&
     677       strcasecmp(pmSearch->name,"asReference")!=0){
    677678      map *tmp;
    678       if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL &&
    679          strcasecmp(i->value,tmp->value)!=0)
     679      if(hasKey(pmMap,pmSearch->name) &&
     680         (tmp=getMap(pmMap,pmSearch->name))!=NULL &&
     681         strcasecmp(pmSearch->value,tmp->value)!=0)
    680682        return false;
    681683    }
    682     i=i->next;
     684    pmSearch=pmSearch->next;
    683685  }
    684686  return true;
     
    688690 * Access a specific iotype from an elements.
    689691 *
    690  * @param e the elements to search for the name
    691  * @param name the name to search in the elements e
    692  * @param values the map to verify it was contained in the defaults or
     692 * @param peElem the elements to search for the name
     693 * @param pcName the name to search in the elements e
     694 * @param pcValues the map to verify it was contained in the defaults or
    693695 *  supported content of the elements e
    694696 * @return a pointer on the iotype found or NULL if not found
    695697 */
    696 iotype* getIoTypeFromElement(elements* e,char *name, map* values){
    697   elements* cursor=e;
    698   if(values!=NULL){
    699     while(cursor!=NULL){
    700       if(strcasecmp(cursor->name,name)==0 && (cursor->defaults!=NULL || cursor->supported!=NULL)){
    701         if(contains(cursor->defaults->content,values)==true)
    702           return cursor->defaults;
     698iotype* getIoTypeFromElement(elements* peElem,char *pcName, map* pcValues){
     699  elements* peCursor=peElem;
     700  if(pcValues!=NULL){
     701    while(peCursor!=NULL){
     702      if(strcasecmp(peCursor->name,pcName)==0 && (peCursor->defaults!=NULL || peCursor->supported!=NULL)){
     703        if(contains(peCursor->defaults->content,pcValues)==true)
     704          return peCursor->defaults;
    703705        else{
    704           iotype* tmp=cursor->supported;
     706          iotype* tmp=peCursor->supported;
    705707          while(tmp!=NULL){
    706             if(contains(tmp->content,values)==true)
     708            if(contains(tmp->content,pcValues)==true)
    707709              return tmp;           
    708710            tmp=tmp->next;
     
    710712        }
    711713      }
    712       cursor=cursor->next;
     714      peCursor=peCursor->next;
    713715    }
    714716  }else{
    715     while(cursor!=NULL){
    716       if(strcasecmp(cursor->name,name)==0 && cursor->defaults!=NULL){
    717         return cursor->defaults;
     717    while(peCursor!=NULL){
     718      if(strcasecmp(peCursor->name,pcName)==0 && peCursor->defaults!=NULL){
     719        return peCursor->defaults;
    718720      }
    719       cursor=cursor->next;
     721      peCursor=peCursor->next;
    720722    }
    721723  }
     
    726728 * Load binary values from a map (in) and add them to another map (out)
    727729 *
    728  * @param out the map to add binaries values
    729  * @param in the map containing the binary values to add ti out
    730  * @param pos index of the binary in an array (in case of "MapArray")
    731  */
    732 void loadMapBinary(map** out,map* in,int pos){
    733   map* size=getMap(in,"size");
    734   map *lout=*out;
    735   map *tmpVin,*tmpVout;
    736   if(size!=NULL && pos>0){
     730 * @param pmOut the map to add binaries values
     731 * @param pmIn the map containing the binary values to add ti out
     732 * @param iPos index of the binary in an array (in case of "MapArray")
     733 */
     734void loadMapBinary(map** ppmOut,map* pmIn,int iPos){
     735  map* pmSize=getMap(pmIn,"size");
     736  map *pmOut=*ppmOut;
     737  map *pmTmpVin,*pmTmpVout;
     738  if(pmSize!=NULL && iPos>0){
    737739    char tmp[11];
    738     sprintf(tmp,"size_%d",pos);
    739     size=getMap(in,tmp);
    740     sprintf(tmp,"value_%d",pos);
    741     tmpVin=getMap(in,tmp);
    742     tmpVout=getMap(lout,tmp);
    743     free(tmpVout->value);
    744     tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
    745     memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
    746     tmpVout->value[atoi(size->value)]=0;
     740    sprintf(tmp,"size_%d",iPos);
     741    pmSize=getMap(pmIn,tmp);
     742    sprintf(tmp,"value_%d",iPos);
     743    pmTmpVin=getMap(pmIn,tmp);
     744    pmTmpVout=getMap(pmOut,tmp);
     745    free(pmTmpVout->value);
     746    pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     747    memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char));
     748    pmTmpVout->value[atoi(pmSize->value)]=0;
    747749  }else{
    748     if(size!=NULL){
    749       tmpVin=getMap(in,"value");
    750       tmpVout=getMap(lout,"value");
    751       free(tmpVout->value);
    752       tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
    753       memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
    754       tmpVout->value[atoi(size->value)]=0;
    755     }
    756   }
    757 }
    758  
     750    if(pmSize!=NULL){
     751      pmTmpVin=getMap(pmIn,"value");
     752      pmTmpVout=getMap(pmOut,"value");
     753      free(pmTmpVout->value);
     754      pmTmpVout->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     755      memmove(pmTmpVout->value,pmTmpVin->value,atoi(pmSize->value)*sizeof(char));
     756      pmTmpVout->value[atoi(pmSize->value)]=0;
     757    }
     758  }
     759}
     760
    759761/**
    760762 * Load binary values from a map (in) and add them to another map (out).
     
    762764 * @see loadMapBinary
    763765 *
    764  * @param out the map to add binaries values
    765  * @param in the map containing the binary values to add ti out
    766  */
    767 void loadMapBinaries(map** out,map* in){
    768   map* size=getMap(in,"size");
    769   map* length=getMap(in,"length");
    770   map* toload=getMap(in,"to_load");
    771   if(toload!=NULL && strcasecmp(toload->value,"false")==0){
     766 * @param ppmOut the map to add binaries values
     767 * @param pmIn the map containing the binary values to add ti out
     768 */
     769void loadMapBinaries(map** ppmOut,map* pmIn){
     770  map* pmSize=getMap(pmIn,"size");
     771  map* pmLength=getMap(pmIn,"length");
     772  map* pmToload=getMap(pmIn,"to_load");
     773  if(pmToload!=NULL && strcasecmp(pmToload->value,"false")==0){
    772774#ifdef DEBUG
    773775    fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
     
    775777    return ;
    776778  }
    777   if(length!=NULL){
    778     int len=atoi(length->value);
     779  if(pmLength!=NULL){
     780    int len=atoi(pmLength->value);
    779781    int i=0;
    780782    for(i=0;i<len;i++){
    781       loadMapBinary(out,in,i);
     783      loadMapBinary(ppmOut,pmIn,i);
    782784    }
    783785  }
    784786  else
    785     if(size!=NULL)
    786       loadMapBinary(out,in,-1);
     787    if(pmSize!=NULL)
     788      loadMapBinary(ppmOut,pmIn,-1);
    787789}
    788790
     
    790792 * Duplicate a Maps
    791793 *
    792  * @param mo the maps to clone
     794 * @param ppmsOut the maps to clone
    793795 * @return the allocated maps containing a copy of the mo maps
    794796 */
    795 maps* dupMaps(maps** mo){
    796   maps* _cursor=*mo;
    797   maps* res=NULL;
    798   if(_cursor!=NULL){
    799     map* mc=_cursor->content;
    800     maps* mcs=_cursor->child;
    801     res=createMaps(_cursor->name);
    802     if(mc!=NULL){
    803       addMapToMap(&res->content,mc);
    804       loadMapBinaries(&res->content,mc);
    805     }
    806     if(mcs!=NULL){
    807       res->child=dupMaps(&mcs);
    808     }
    809     res->next=dupMaps(&_cursor->next);
    810   }
    811   return res;
     797maps* dupMaps(maps** ppmsOut){
     798  maps* pmsCursor=*ppmsOut;
     799  maps* pmRes=NULL;
     800  if(pmsCursor!=NULL){
     801    map* pmContent=pmsCursor->content;
     802    maps* pmsChild=pmsCursor->child;
     803    pmRes=createMaps(pmsCursor->name);
     804    if(pmContent!=NULL){
     805      addMapToMap(&pmRes->content,pmContent);
     806      loadMapBinaries(&pmRes->content,pmContent);
     807    }
     808    if(pmsChild!=NULL){
     809      pmRes->child=dupMaps(&pmsChild);
     810    }
     811    pmRes->next=dupMaps(&pmsCursor->next);
     812  }
     813  return pmRes;
    812814}
    813815
     
    816818 *
    817819 * @see addMapToMap, dupMaps, getMaps
    818  * @param mo the maps to add mi
    819  * @param mi the maps to add to mo
    820  */
    821 void addMapsToMaps(maps** mo,maps* mi){
    822   maps* tmp=mi;
    823   maps* _cursor=*mo;
    824   while(tmp!=NULL){
    825     if(_cursor==NULL){
    826       *mo=dupMaps(&mi);
     820 * @param ppmsOut the maps to add mi
     821 * @param pmIn the maps to add to mo
     822 */
     823void addMapsToMaps(maps** ppmsOut,maps* pmIn){
     824  maps* pmsTmp=pmIn;
     825  maps* pmsCursor=*ppmsOut;
     826  while(pmsTmp!=NULL){
     827    if(pmsCursor==NULL){
     828      *ppmsOut=dupMaps(&pmIn);
    827829    }
    828830    else{
    829       maps* tmp1=getMaps(*mo,tmp->name);
    830       if(tmp1==NULL){
    831         while(_cursor->next!=NULL)
    832           _cursor=_cursor->next;
    833         _cursor->next=dupMaps(&tmp);
    834         if(tmp->child!=NULL)
    835           _cursor->next->child=dupMaps(&tmp->child);
     831      maps* pmsTmp1=getMaps(*ppmsOut,pmsTmp->name);
     832      if(pmsTmp1==NULL){
     833        while(pmsCursor->next!=NULL)
     834          pmsCursor=pmsCursor->next;
     835        pmsCursor->next=dupMaps(&pmsTmp);
     836        if(pmsTmp->child!=NULL)
     837          pmsCursor->next->child=dupMaps(&pmsTmp->child);
    836838        else
    837           _cursor->next->child=NULL;
     839          pmsCursor->next->child=NULL;
    838840      }
    839841      else{
    840         addMapToMap(&tmp1->content,tmp->content);
    841         if(tmp->child!=NULL)
    842           tmp1->child=dupMaps(&tmp->child);
     842        addMapToMap(&pmsTmp1->content,pmsTmp->content);
     843        if(pmsTmp->child!=NULL)
     844          pmsTmp1->child=dupMaps(&pmsTmp->child);
    843845        else
    844           tmp1->child=NULL;
     846          pmsTmp1->child=NULL;
    845847      }
    846       _cursor=*mo;
    847     }
    848     tmp=tmp->next;
     848      pmsCursor=*ppmsOut;
     849    }
     850    pmsTmp=pmsTmp->next;
    849851  }
    850852}
     
    853855 * Access a specific map array element
    854856 *
    855  * @param m the map to search for the key
    856  * @param key the key to search in the map
    857  * @param index of the MapArray
     857 * @param pmMap the map to search for the key
     858 * @param pccKey the key to search in the map
     859 * @param iIndex of the MapArray
    858860 * @return a pointer on the map found or NULL if not found
    859861 */
    860 map* getMapArray(map* m,const char* key,int index){
    861   char tmp[1024];
    862   map* tmpMap;
    863   if(index>0)
    864     sprintf(tmp,"%s_%d",key,index);
     862map* getMapArray(map* pmMap,const char* pccKey,int iIndex){
     863  char acTmp[1024];
     864  map* pmTmp;
     865  if(iIndex>0)
     866    sprintf(acTmp,"%s_%d",pccKey,iIndex);
    865867  else
    866     sprintf(tmp,"%s",key);
     868    sprintf(acTmp,"%s",pccKey);
    867869#ifdef DEBUG
    868   fprintf(stderr,"** KEY %s\n",tmp);
     870  fprintf(stderr,"** KEY %s\n",acTmp);
    869871#endif
    870   tmpMap=getMap(m,tmp);
     872  pmTmp=getMap(pmMap,acTmp);
    871873#ifdef DEBUG
    872   if(tmpMap!=NULL)
    873     dumpMap(tmpMap);
     874  if(pmTmp!=NULL)
     875    dumpMap(pmTmp);
    874876#endif
    875   return tmpMap;
     877  return pmTmp;
    876878}
    877879
     
    879881 * Add a key value in a MapArray for a specific index
    880882 *
    881  * @param m the map to search for the key
    882  * @param key the key to search in the map
    883  * @param index the index of the MapArray
    884  * @param value the value to set in the MapArray
     883 * @param pmMap the map to search for the key
     884 * @param pccKey the key to search in the map
     885 * @param iIndex the index of the MapArray
     886 * @param pccValue the value to set in the MapArray
    885887 * @return a pointer on the map found or NULL if not found
    886888 */
    887 void setMapArray(map* m,const char* key,int index,const char* value){
    888   char tmp[1024];
    889   map* tmpSize;
    890   if(index>0){
    891     map* len=getMap(m,"length");
    892     sprintf(tmp,"%s_%d",key,index);
    893     if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
    894       char tmp0[5];
    895       sprintf(tmp0,"%d",index+1);
    896       addToMap(m,"length",tmp0);
     889void setMapArray(map* pmMap,const char* pccKey,int iIndex,const char* pccValue){
     890  char acTmp[1024];
     891  map* pmSize;
     892  if(iIndex>0){
     893    map* pmLen=getMap(pmMap,"length");
     894    sprintf(acTmp,"%s_%d",pccKey,iIndex);
     895    if((pmLen!=NULL && atoi(pmLen->value)<iIndex+1) || pmLen==NULL){
     896      char acTmp0[5];
     897      sprintf(acTmp0,"%d",iIndex+1);
     898      addToMap(pmMap,"length",acTmp0);
    897899    }
    898900  }
    899901  else{
    900     sprintf(tmp,"%s",key);
    901     addToMap(m,"length","1");
    902   }
    903   tmpSize=getMapArray(m,"size",index);
    904   if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
    905     map* ptr=getMapOrFill(&m,tmp,(char *)"");
     902    sprintf(acTmp,"%s",pccKey);
     903    addToMap(pmMap,"length","1");
     904  }
     905  pmSize=getMapArray(pmMap,"size",iIndex);
     906  if(pmSize!=NULL && strncasecmp(pccKey,"value",5)==0){
     907    map* pmPtr=getMapOrFill(&pmMap,acTmp,(char *)"");
    906908#ifdef DEBUG
    907     fprintf(stderr,"%s\n",tmpSize->value);
     909    fprintf(stderr,"%s\n",pmSize->value);
    908910#endif
    909     free(ptr->value);
    910     ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
    911     memcpy(ptr->value,value,atoi(tmpSize->value));
     911    free(pmPtr->value);
     912    pmPtr->value=(char*)malloc((atoi(pmSize->value)+1)*sizeof(char));
     913    memcpy(pmPtr->value,pccValue,atoi(pmSize->value));
    912914  }
    913915  else
    914     addToMap(m,tmp,value);
     916    addToMap(pmMap,acTmp,pccValue);
    915917}
    916918
     
    918920 * Add a key and an integer value to an existing map array.
    919921 *
    920  * @param m the map to add the KVP
    921  * @param n the key to add
    922  * @param index the index of the MapArray
    923  * @param v the corresponding value to add
    924  */
    925 void addIntToMapArray(map* m,const char* n,int index,const int v){
    926   char svalue[10];
    927   sprintf(svalue,"%d",v);
    928   setMapArray(m,n,index,svalue);
     922 * @param pmMap the map to add the KVP
     923 * @param pccName the key to add
     924 * @param iIndex the index of the MapArray
     925 * @param icValue the corresponding value to add
     926 */
     927void addIntToMapArray(map* pmMap,const char* pccName,int iIndex,const int icValue){
     928  char acValue[10];
     929  sprintf(acValue,"%d",icValue);
     930  setMapArray(pmMap,pccName,iIndex,acValue);
    929931}
    930932
     
    932934 * Access the map "type"
    933935 *
    934  * @param mt the map
     936 * @param pmMap the map
    935937 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
    936938 *  other case
    937939 */
    938 map* getMapType(map* mt){
    939   map* tmap=getMap(mt,(char *)"mimeType");
    940   if(tmap==NULL){
    941     tmap=getMap(mt,"dataType");
    942     if(tmap==NULL){
    943       tmap=getMap(mt,"CRS");
     940map* getMapType(map* pmMap){
     941  map* pmMime=getMap(pmMap,(char *)"mimeType");
     942  if(pmMime==NULL){
     943    pmMime=getMap(pmMap,"dataType");
     944    if(pmMime==NULL){
     945      pmMime=getMap(pmMap,"CRS");
    944946    }
    945947  }
    946948#ifdef DEBUG
    947   dumpMap(tmap);
     949  dumpMap(pmMime);
    948950#endif
    949   return tmap;
     951  return pmMime;
    950952}
    951953
     
    954956 *
    955957 * @see getMapType
    956  * @param mo the maps
    957  * @param mi the maps
    958  * @param typ the map "type"
     958 * @param pmsOut the maps
     959 * @param pmsIn the maps
     960 * @param pcType the map "type"
    959961 * @return
    960962 */
    961 int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
    962   maps* tmp=mi;   
    963   maps* _cursor=getMaps(*mo,tmp->name);
    964   char tmpLen[10];
    965   int len=1;
    966   char *tmpV[14]={
     963int addMapsArrayToMaps(maps** pmsOut,maps* pmsIn,char* pcType){
     964  maps* pmsTmp=pmsIn;
     965  maps* pmsCursor=getMaps(*pmsOut,pmsTmp->name);
     966  char acLen[10];
     967  int iLen=1;
     968  char *acV[14]={
    967969    (char*)"size",
    968970    (char*)"value",
     
    973975    (char*)"fmimeType",
    974976    (char*)"xlink:href",
    975     typ,
     977    pcType,
    976978    (char*)"schema",
    977979    (char*)"encoding",
     
    980982    (char*)"UpperCorner"
    981983  };
    982   int i=0;
    983   map* tmpLength;
     984  int iCounter=0;
     985  map* pmLength;
    984986 
    985   if(_cursor==NULL)
     987  if(pmsCursor==NULL)
    986988    return -1;
    987989
    988   tmpLength=getMap(_cursor->content,"length");
    989   if(tmpLength!=NULL){
    990     len=atoi(tmpLength->value);
    991   }
    992 
    993   sprintf(tmpLen,"%d",len+1);
    994   addToMap(_cursor->content,"length",tmpLen);
    995   for(i=0;i<14;i++){
    996     map* tmpVI=getMap(tmp->content,tmpV[i]);
    997     if(tmpVI!=NULL){
     990  pmLength=getMap(pmsCursor->content,"length");
     991  if(pmLength!=NULL){
     992    iLen=atoi(pmLength->value);
     993  }
     994
     995  sprintf(acLen,"%d",iLen+1);
     996  addToMap(pmsCursor->content,"length",acLen);
     997  for(iCounter=0;iCounter<14;iCounter++){
     998    map* pmTmp=getMap(pmsTmp->content,acV[iCounter]);
     999    if(pmTmp!=NULL){
    9981000#ifdef DEBUG
    999       fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
     1001      fprintf(stderr,"%s = %s\n",pmTmp[iCounter],pmTmp->value);
    10001002#endif
    1001       setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
     1003      setMapArray(pmsCursor->content,acV[iCounter],iLen,pmTmp->value);
    10021004    }
    10031005  }
    10041006   
    1005   addToMap(_cursor->content,"isArray","true");
     1007  addToMap(pmsCursor->content,"isArray","true");
    10061008  return 0;
    10071009}
     
    10101012 * Set a key value pair to a map contained in a Maps
    10111013 *
    1012  * @param m the maps
    1013  * @param key the maps name
    1014  * @param subkey the map name included in the maps corresponding to key
    1015  * @param value the corresponding value to add in the map
    1016  */
    1017 void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
    1018   maps* _tmpm=getMaps(m,key);
    1019   if(_tmpm!=NULL){
    1020     map* _ztmpm=getMap(_tmpm->content,subkey);
    1021     if(_ztmpm!=NULL){
    1022       if(_ztmpm->value!=NULL)
    1023         free(_ztmpm->value);
    1024       _ztmpm->value=zStrdup(value);
     1014 * @param pmsMaps the maps
     1015 * @param pccKey the maps name
     1016 * @param pccSubkey the map name included in the maps corresponding to key
     1017 * @param pccValue the corresponding value to add in the map
     1018 */
     1019void setMapInMaps(maps* pmsMaps,const char* pccKey,const char* pccSubkey,const char *pccValue){
     1020  maps* pmsTmp=getMaps(pmsMaps,pccKey);
     1021  if(pmsTmp!=NULL){
     1022    map* pmTmpSub=getMap(pmsTmp->content,pccSubkey);
     1023    if(pmTmpSub!=NULL){
     1024      if(pmTmpSub->value!=NULL)
     1025        free(pmTmpSub->value);
     1026      pmTmpSub->value=zStrdup(pccValue);
    10251027    }else{
    1026       maps *tmp=createMaps(key);
    1027       tmp->content=createMap(subkey,value);
    1028       addMapsToMaps(&_tmpm,tmp);
    1029       freeMaps(&tmp);
    1030       free(tmp);
     1028      maps *pmsToAdd=createMaps(pccKey);
     1029      pmsToAdd->content=createMap(pccSubkey,pccValue);
     1030      addMapsToMaps(&pmsTmp,pmsToAdd);
     1031      freeMaps(&pmsToAdd);
     1032      free(pmsToAdd);
    10311033    }
    10321034  }else{
    1033     maps *tmp=createMaps(key);
    1034     tmp->content=createMap(subkey,value);
    1035     addMapsToMaps(&m,tmp);
    1036     freeMaps(&tmp);
    1037     free(tmp);
     1035    maps *pmsToAdd=createMaps(pccKey);
     1036    pmsToAdd->content=createMap(pccSubkey,pccValue);
     1037    addMapsToMaps(&pmsMaps,pmsToAdd);
     1038    freeMaps(&pmsToAdd);
     1039    free(pmsToAdd);
    10381040  }
    10391041}
     
    10451047 */
    10461048elements* createEmptyElements(){
    1047   elements* res=(elements*)malloc(ELEMENTS_SIZE);
    1048   res->name=NULL;
    1049   res->content=NULL;
    1050   res->metadata=NULL;
    1051   res->additional_parameters=NULL; 
    1052   res->format=NULL;
    1053   res->defaults=NULL;
    1054   res->supported=NULL;
    1055   res->child=NULL;
    1056   res->next=NULL;
    1057   return res;
     1049  elements* peRes=(elements*)malloc(ELEMENTS_SIZE);
     1050  peRes->name=NULL;
     1051  peRes->content=NULL;
     1052  peRes->metadata=NULL;
     1053  peRes->additional_parameters=NULL; 
     1054  peRes->format=NULL;
     1055  peRes->defaults=NULL;
     1056  peRes->supported=NULL;
     1057  peRes->child=NULL;
     1058  peRes->next=NULL;
     1059  return peRes;
    10581060}
    10591061
     
    10611063 * Create a named elements
    10621064 *
    1063  * @param name the elements name
     1065 * @param pcName the elements name
    10641066 * @return a pointer to the allocated elements
    10651067 */
    1066 elements* createElements(const char* name){
    1067   elements* res=(elements*)malloc(ELEMENTS_SIZE);
    1068   res->name=zStrdup(name);
    1069   res->content=NULL;
    1070   res->metadata=NULL;
    1071   res->additional_parameters=NULL;
    1072   res->format=NULL;
    1073   res->defaults=NULL;
    1074   res->supported=NULL;
    1075   res->child=NULL;
    1076   res->next=NULL;
    1077   return res;
     1068elements* createElements(const char* pcName){
     1069  elements* peRes=(elements*)malloc(ELEMENTS_SIZE);
     1070  peRes->name=zStrdup(pcName);
     1071  peRes->content=NULL;
     1072  peRes->metadata=NULL;
     1073  peRes->additional_parameters=NULL;
     1074  peRes->format=NULL;
     1075  peRes->defaults=NULL;
     1076  peRes->supported=NULL;
     1077  peRes->child=NULL;
     1078  peRes->next=NULL;
     1079  return peRes;
    10781080}
    10791081
     
    10811083 * Set the name of an elements
    10821084 *
    1083  * @param name the elements name
     1085 * @param peElem the elements to modify
     1086 * @param pcName the elements name
    10841087 * @return a pointer to the allocated elements
    10851088 */
    1086 void setElementsName(elements** elem,char* name){
    1087   elements* res=*elem;
    1088   res->name=zStrdup(name);
    1089   res->content=NULL;
    1090   res->metadata=NULL;
    1091   res->format=NULL;
    1092   res->defaults=NULL;
    1093   res->supported=NULL;
    1094   res->child=NULL;
    1095   res->next=NULL;
     1089void setElementsName(elements** ppeElem,char* pcName){
     1090  elements* peRes=*ppeElem;
     1091  peRes->name=zStrdup(pcName);
     1092  peRes->content=NULL;
     1093  peRes->metadata=NULL;
     1094  peRes->format=NULL;
     1095  peRes->defaults=NULL;
     1096  peRes->supported=NULL;
     1097  peRes->child=NULL;
     1098  peRes->next=NULL;
    10961099}
    10971100
     
    10991102 * Dump an elements on stderr
    11001103 *
    1101  * @param e the elements to dump
    1102  */
    1103 void dumpElements(elements* e){
    1104   elements* tmp=e;
    1105   while(tmp!=NULL){
    1106     iotype* tmpio=tmp->defaults;
     1104 * @param peElem the elements to dump
     1105 */
     1106void dumpElements(elements* peElem){
     1107  elements* peTmp=peElem;
     1108  while(peTmp!=NULL){
     1109    iotype* piotTmp=peTmp->defaults;
    11071110    int ioc=0;
    1108     fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
    1109     fprintf(stderr," > CONTENT [%s]\n",tmp->name);
    1110     dumpMap(tmp->content);
    1111     fprintf(stderr," > METADATA [%s]\n",tmp->name);
    1112     dumpMap(tmp->metadata);
    1113     fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",tmp->name);
    1114     dumpMap(tmp->additional_parameters);
    1115     fprintf(stderr," > FORMAT [%s]\n",tmp->format);
    1116     while(tmpio!=NULL){
    1117       fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
    1118       dumpMap(tmpio->content);
    1119       tmpio=tmpio->next;
     1111    fprintf(stderr,"ELEMENT [%s]\n",peTmp->name);
     1112    fprintf(stderr," > CONTENT [%s]\n",peTmp->name);
     1113    dumpMap(peTmp->content);
     1114    fprintf(stderr," > METADATA [%s]\n",peTmp->name);
     1115    dumpMap(peTmp->metadata);
     1116    fprintf(stderr," > ADDITIONAL PARAMETERS [%s]\n",peTmp->name);
     1117    dumpMap(peTmp->additional_parameters);
     1118    fprintf(stderr," > FORMAT [%s]\n",peTmp->format);
     1119    while(piotTmp!=NULL){
     1120      fprintf(stderr," > DEFAULTS [%s] (%i)\n",peTmp->name,ioc);
     1121      dumpMap(piotTmp->content);
     1122      piotTmp=piotTmp->next;
    11201123      ioc++;
    11211124    }
    1122     tmpio=tmp->supported;
     1125    piotTmp=peTmp->supported;
    11231126    ioc=0;
    1124     while(tmpio!=NULL){
    1125       fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
    1126       dumpMap(tmpio->content);
    1127       tmpio=tmpio->next;
     1127    while(piotTmp!=NULL){
     1128      fprintf(stderr," > SUPPORTED [%s] (%i)\n",peTmp->name,ioc);
     1129      dumpMap(piotTmp->content);
     1130      piotTmp=piotTmp->next;
    11281131      ioc++;
    11291132    }
    1130     if(tmp->child!=NULL){
     1133    if(peTmp->child!=NULL){
    11311134      fprintf(stderr," > CHILD \n");
    1132       dumpElements(tmp->child);
     1135      dumpElements(peTmp->child);
    11331136    }
    11341137    fprintf(stderr,"------------------\n");
    1135     tmp=tmp->next;
     1138    peTmp=peTmp->next;
    11361139  }
    11371140}
     
    11401143 * Dump an elements on stderr using the YAML syntaxe
    11411144 *
    1142  * @param e the elements to dump
    1143  */
    1144 void dumpElementsAsYAML(elements* e,int level){
    1145   elements* tmp=e;
     1145 * @param peElem the elements to dump
     1146 * @param iLevel the current level
     1147 */
     1148void dumpElementsAsYAML(elements* peElem,int iLevel){
     1149  elements* peTmp=peElem;
    11461150  int i;
    1147   while(tmp!=NULL){
    1148     map* mcurs=tmp->content;
     1151  while(peTmp!=NULL){
     1152    map* pmCurs=peTmp->content;
    11491153    int ioc=0;
    1150     iotype* tmpio;
    1151     for(i=0;i<2+(4*level);i++)
     1154    iotype* piotTmp;
     1155    for(i=0;i<2+(4*iLevel);i++)
    11521156      fprintf(stderr," ");
    1153     fprintf(stderr,"%s:\n",tmp->name);
    1154     while(mcurs!=NULL){
    1155       for(i=0;i<4+(4*level);i++)
     1157    fprintf(stderr,"%s:\n",peTmp->name);
     1158    while(pmCurs!=NULL){
     1159      for(i=0;i<4+(4*iLevel);i++)
    11561160        fprintf(stderr," ");
    1157       _dumpMap(mcurs);
    1158       mcurs=mcurs->next;
    1159     }
    1160     mcurs=tmp->metadata;
    1161     if(mcurs!=NULL){
    1162       for(i=0;i<4+(4*level);i++)
     1161      _dumpMap(pmCurs);
     1162      pmCurs=pmCurs->next;
     1163    }
     1164    pmCurs=peTmp->metadata;
     1165    if(pmCurs!=NULL){
     1166      for(i=0;i<4+(4*iLevel);i++)
    11631167        fprintf(stderr," ");
    11641168      fprintf(stderr,"MetaData:\n");
    1165       while(mcurs!=NULL){
    1166         for(i=0;i<6+(4*level);i++)
     1169      while(pmCurs!=NULL){
     1170        for(i=0;i<6+(4*iLevel);i++)
    11671171          fprintf(stderr," ");
    1168         _dumpMap(mcurs);
    1169         mcurs=mcurs->next;
     1172        _dumpMap(pmCurs);
     1173        pmCurs=pmCurs->next;
    11701174      }
    11711175    }
    1172     for(i=0;i<4+(4*level);i++)
     1176    for(i=0;i<4+(4*iLevel);i++)
    11731177      fprintf(stderr," ");
    1174     if(tmp->format!=NULL)
    1175       fprintf(stderr,"%s:\n",tmp->format);
     1178    if(peTmp->format!=NULL)
     1179      fprintf(stderr,"%s:\n",peTmp->format);
    11761180    else{
    11771181      fprintf(stderr,"Child:\n");
    1178       if(tmp->child!=NULL)
    1179         dumpElementsAsYAML(tmp->child,level+1);
    1180     }
    1181     tmpio=tmp->defaults;
    1182     while(tmpio!=NULL){
    1183       for(i=0;i<6+(4*level);i++)
     1182      if(peTmp->child!=NULL)
     1183        dumpElementsAsYAML(peTmp->child,iLevel+1);
     1184    }
     1185    piotTmp=peTmp->defaults;
     1186    while(piotTmp!=NULL){
     1187      for(i=0;i<6+(4*iLevel);i++)
    11841188        fprintf(stderr," ");
    11851189      fprintf(stderr,"default:\n");
    1186       mcurs=tmpio->content;
    1187       while(mcurs!=NULL){
    1188         for(i=0;i<8+(4*level);i++)
     1190      pmCurs=piotTmp->content;
     1191      while(pmCurs!=NULL){
     1192        for(i=0;i<8+(4*iLevel);i++)
    11891193          fprintf(stderr," ");
    1190         if(strcasecmp(mcurs->name,"range")==0){
    1191           fprintf(stderr,"range: \"%s\"\n",mcurs->value);
     1194        if(strcasecmp(pmCurs->name,"range")==0){
     1195          fprintf(stderr,"range: \"%s\"\n",pmCurs->value);
    11921196        }else
    1193           _dumpMap(mcurs);
    1194         mcurs=mcurs->next;
     1197          _dumpMap(pmCurs);
     1198        pmCurs=pmCurs->next;
    11951199      }
    1196       tmpio=tmpio->next;
     1200      piotTmp=piotTmp->next;
    11971201      ioc++;
    11981202    }
    1199     tmpio=tmp->supported;
     1203    piotTmp=peTmp->supported;
    12001204    ioc=0;
    1201     while(tmpio!=NULL){
    1202       for(i=0;i<6+(4*level);i++)
     1205    while(piotTmp!=NULL){
     1206      for(i=0;i<6+(4*iLevel);i++)
    12031207        fprintf(stderr," ");
    12041208      fprintf(stderr,"supported:\n");
    1205       mcurs=tmpio->content;
    1206       while(mcurs!=NULL){
    1207         for(i=0;i<8+(4*level);i++)
     1209      pmCurs=piotTmp->content;
     1210      while(pmCurs!=NULL){
     1211        for(i=0;i<8+(4*iLevel);i++)
    12081212          fprintf(stderr," ");
    1209         if(strcasecmp(mcurs->name,"range")==0){
    1210           fprintf(stderr,"range: \"%s\"\n",mcurs->value);
     1213        if(strcasecmp(pmCurs->name,"range")==0){
     1214          fprintf(stderr,"range: \"%s\"\n",pmCurs->value);
    12111215        }else
    1212           _dumpMap(mcurs);
    1213         mcurs=mcurs->next;
     1216          _dumpMap(pmCurs);
     1217        pmCurs=pmCurs->next;
    12141218      }
    1215       tmpio=tmpio->next;
     1219      piotTmp=piotTmp->next;
    12161220      ioc++;
    12171221    }
    1218     tmp=tmp->next;
     1222    peTmp=peTmp->next;
    12191223  }
    12201224}
     
    12231227 * Duplicate an elements
    12241228 *
    1225  * @param e the elements to clone
     1229 * @param peElem the elements to clone
    12261230 * @return the allocated elements containing a copy of the elements e
    12271231 */
    1228 elements* dupElements(elements* e){
    1229   elements* cursor=e;
    1230   elements* tmp=NULL;
    1231   if(cursor!=NULL && cursor->name!=NULL){
     1232elements* dupElements(elements* peElem){
     1233  elements* peCursor=peElem;
     1234  elements* peTmp=NULL;
     1235  if(peCursor!=NULL && peCursor->name!=NULL){
    12321236#ifdef DEBUG
    12331237    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
     
    12351239    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    12361240#endif
    1237     tmp=(elements*)malloc(ELEMENTS_SIZE);
    1238     tmp->name=zStrdup(cursor->name);
    1239     tmp->content=NULL;
    1240     addMapToMap(&tmp->content,cursor->content);
    1241     tmp->metadata=NULL;
    1242     addMapToMap(&tmp->metadata,cursor->metadata);
    1243     tmp->additional_parameters=NULL;
    1244     addMapToMap(&tmp->additional_parameters,cursor->additional_parameters);
    1245     if(cursor->format!=NULL)
    1246       tmp->format=zStrdup(cursor->format);
     1241    peTmp=(elements*)malloc(ELEMENTS_SIZE);
     1242    peTmp->name=zStrdup(peCursor->name);
     1243    peTmp->content=NULL;
     1244    addMapToMap(&peTmp->content,peCursor->content);
     1245    peTmp->metadata=NULL;
     1246    addMapToMap(&peTmp->metadata,peCursor->metadata);
     1247    peTmp->additional_parameters=NULL;
     1248    addMapToMap(&peTmp->additional_parameters,peCursor->additional_parameters);
     1249    if(peCursor->format!=NULL)
     1250      peTmp->format=zStrdup(peCursor->format);
    12471251    else
    1248       tmp->format=NULL;
    1249     if(cursor->defaults!=NULL){
    1250       tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
    1251       tmp->defaults->content=NULL;
    1252       addMapToMap(&tmp->defaults->content,cursor->defaults->content);
    1253       tmp->defaults->next=NULL;
     1252      peTmp->format=NULL;
     1253    if(peCursor->defaults!=NULL){
     1254      peTmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
     1255      peTmp->defaults->content=NULL;
     1256      addMapToMap(&peTmp->defaults->content,peCursor->defaults->content);
     1257      peTmp->defaults->next=NULL;
    12541258#ifdef DEBUG
    12551259      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    1256       dumpMap(tmp->defaults->content);
     1260      dumpMap(peTmp->defaults->content);
    12571261#endif
    12581262    }else
    1259       tmp->defaults=NULL;
    1260     if(cursor->supported!=NULL && cursor->supported->content!=NULL){
    1261       iotype *tmp2=cursor->supported->next;
    1262       tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
    1263       tmp->supported->content=NULL;
    1264       addMapToMap(&tmp->supported->content,cursor->supported->content);
    1265       tmp->supported->next=NULL;
    1266             while(tmp2!=NULL){
    1267         addMapToIoType(&tmp->supported,tmp2->content);
     1263      peTmp->defaults=NULL;
     1264    if(peCursor->supported!=NULL && peCursor->supported->content!=NULL){
     1265      iotype *piotTmp=peCursor->supported->next;
     1266      peTmp->supported=(iotype*)malloc(IOTYPE_SIZE);
     1267      peTmp->supported->content=NULL;
     1268      addMapToMap(&peTmp->supported->content,peCursor->supported->content);
     1269      peTmp->supported->next=NULL;
     1270            while(piotTmp!=NULL){
     1271        addMapToIoType(&peTmp->supported,piotTmp->content);
    12681272#ifdef DEBUG
    12691273        fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
    1270         dumpMap(tmp->defaults->content);
     1274        dumpMap(peTmp->defaults->content);
    12711275#endif
    1272         tmp2=tmp2->next;
     1276        piotTmp=piotTmp->next;
    12731277      }
    12741278    }
    12751279    else
    1276       tmp->supported=NULL;
    1277     if(cursor->child!=NULL)
    1278       tmp->child=dupElements(cursor->child);
     1280      peTmp->supported=NULL;
     1281    if(peCursor->child!=NULL)
     1282      peTmp->child=dupElements(peCursor->child);
    12791283    else
    1280       tmp->child=NULL;
    1281     if(cursor->next!=NULL)
    1282       tmp->next=dupElements(cursor->next);
     1284      peTmp->child=NULL;
     1285    if(peCursor->next!=NULL)
     1286      peTmp->next=dupElements(peCursor->next);
    12831287    else
    1284       tmp->next=NULL;
    1285   }
    1286   return tmp;
     1288      peTmp->next=NULL;
     1289  }
     1290  return peTmp;
    12871291}
    12881292
     
    12911295 *
    12921296 * @see dupElements
    1293  * @param m the elements to add the e
    1294  * @param e the elements to be added to m
    1295  */
    1296 void addToElements(elements** m,elements* e){
    1297   elements* tmp=e;
    1298   if(*m==NULL){
    1299     (*m)=dupElements(tmp);
     1297 * @param ppeElem the elements to add the e
     1298 * @param peELem the elements to be added to m
     1299 */
     1300void addToElements(elements** ppeElem,elements* peELem){
     1301  elements* peTmp=peELem;
     1302  if(*ppeElem==NULL){
     1303    (*ppeElem)=dupElements(peTmp);
    13001304  }else{
    1301     addToElements(&(*m)->next,tmp);
     1305    addToElements(&(*ppeElem)->next,peTmp);
    13021306  }
    13031307}
     
    13061310 * Set the name of a service
    13071311 *
    1308  * @param name the service name
    1309  */
    1310 void setServiceName(service** serv,char* name){
    1311   service* res=*serv;
    1312   res->name=zStrdup(name);
    1313   res->content=NULL;
    1314   res->metadata=NULL;
    1315   res->inputs=NULL;
    1316   res->outputs=NULL;
     1312 * @param ppsServ the service
     1313 * @param pcName the service name
     1314 */
     1315void setServiceName(service** ppsServ,char* pcName){
     1316  service* psRes=*ppsServ;
     1317  psRes->name=zStrdup(pcName);
     1318  psRes->content=NULL;
     1319  psRes->metadata=NULL;
     1320  psRes->inputs=NULL;
     1321  psRes->outputs=NULL;
    13171322}
    13181323
     
    13201325 * Dump a service on stderr
    13211326 *
    1322  * @param s the service to dump
    1323  */
    1324 void dumpService(service* s){
    1325   if(s==NULL)
     1327 * @param psServ the service to dump
     1328 */
     1329void dumpService(service* psServ){
     1330  if(psServ==NULL)
    13261331    return;
    1327   fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
    1328   if(s->content!=NULL){
     1332  fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",psServ->name);
     1333  if(psServ->content!=NULL){
    13291334    fprintf(stderr,"CONTENT MAP\n");
    1330     dumpMap(s->content);
    1331     if(s->metadata!=NULL)
     1335    dumpMap(psServ->content);
     1336    if(psServ->metadata!=NULL)
    13321337      fprintf(stderr,"CONTENT METADATA\n");
    1333     dumpMap(s->metadata);
    1334     if(s->additional_parameters!=NULL)
     1338    dumpMap(psServ->metadata);
     1339    if(psServ->additional_parameters!=NULL)
    13351340      fprintf(stderr,"CONTENT AdditionalParameters\n");
    1336     dumpMap(s->additional_parameters);
    1337   }
    1338   if(s->inputs!=NULL){
    1339     fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
    1340     dumpElements(s->inputs);
    1341   }
    1342   if(s->outputs!=NULL){
    1343     fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
    1344     dumpElements(s->outputs);
     1341    dumpMap(psServ->additional_parameters);
     1342  }
     1343  if(psServ->inputs!=NULL){
     1344    fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",psServ->name);
     1345    dumpElements(psServ->inputs);
     1346  }
     1347  if(psServ->outputs!=NULL){
     1348    fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",psServ->name);
     1349    dumpElements(psServ->outputs);
    13451350  }
    13461351  fprintf(stderr,"++++++++++++++++++\n");
     
    13501355 * Dump a service on stderr using the YAML syntaxe
    13511356 *
    1352  * @param s the service to dump
    1353  */
    1354 void dumpServiceAsYAML(service* s){
     1357 * @param psServ the service to dump
     1358 */
     1359void dumpServiceAsYAML(service* psServ){
    13551360  int i;
    1356   fprintf(stderr,"# %s\n\n",s->name);
    1357   if(s->content!=NULL){
    1358     map* mcurs=s->content;
    1359     dumpMap(mcurs);
    1360     mcurs=s->metadata;
    1361     if(mcurs!=NULL){
     1361  fprintf(stderr,"# %s\n\n",psServ->name);
     1362  if(psServ->content!=NULL){
     1363    map* pmCurs=psServ->content;
     1364    dumpMap(pmCurs);
     1365    pmCurs=psServ->metadata;
     1366    if(pmCurs!=NULL){
    13621367      fprintf(stderr,"MetaData:\n");
    1363       while(mcurs!=NULL){
     1368      while(pmCurs!=NULL){
    13641369        for(i=0;i<2;i++)
    13651370          fprintf(stderr," ");
    1366         _dumpMap(mcurs);
    1367         mcurs=mcurs->next;
     1371        _dumpMap(pmCurs);
     1372        pmCurs=pmCurs->next;
    13681373      }
    13691374    }
    13701375  }
    1371   if(s->inputs!=NULL){
     1376  if(psServ->inputs!=NULL){
    13721377    fprintf(stderr,"\ninputs:\n");
    1373     dumpElementsAsYAML(s->inputs,0);
    1374   }
    1375   if(s->outputs!=NULL){
     1378    dumpElementsAsYAML(psServ->inputs,0);
     1379  }
     1380  if(psServ->outputs!=NULL){
    13761381    fprintf(stderr,"\noutputs:\n");
    1377     dumpElementsAsYAML(s->outputs,0);
     1382    dumpElementsAsYAML(psServ->outputs,0);
    13781383  }
    13791384}
     
    13821387 * Duplicate a service
    13831388 *
    1384  * @param s the service to clone
     1389 * @param psServ the service to clone
    13851390 * @return the allocated service containing a copy of the serfvice s
    13861391 */
    1387 service* dupService(service* s){
    1388   service *res=(service*)malloc(SERVICE_SIZE);
    1389   res->name=zStrdup(s->name);
    1390   res->content=NULL;
    1391   addMapToMap(&res->content,s->content);
    1392   res->metadata=NULL;
    1393   addMapToMap(&res->metadata,s->metadata);
    1394   res->additional_parameters=NULL;
    1395   addMapToMap(&res->additional_parameters,s->additional_parameters);
    1396   res->inputs=dupElements(s->inputs);
    1397   res->outputs=dupElements(s->outputs);
    1398   return res;
     1392service* dupService(service* psServ){
     1393  service *psRes=(service*)malloc(SERVICE_SIZE);
     1394  psRes->name=zStrdup(psServ->name);
     1395  psRes->content=NULL;
     1396  addMapToMap(&psRes->content,psServ->content);
     1397  psRes->metadata=NULL;
     1398  addMapToMap(&psRes->metadata,psServ->metadata);
     1399  psRes->additional_parameters=NULL;
     1400  addMapToMap(&psRes->additional_parameters,psServ->additional_parameters);
     1401  psRes->inputs=dupElements(psServ->inputs);
     1402  psRes->outputs=dupElements(psServ->outputs);
     1403  return psRes;
    13991404}
    14001405
     
    14021407 * Print the registry on stderr.
    14031408 *
    1404  * @param r the registry
    1405  */
    1406 void dumpRegistry(registry* r){
    1407   registry* p=r;
    1408   while(p!=NULL){
    1409     services* s=p->content;
    1410     fprintf(stderr,"%s \n",p->name);
    1411     s=p->content;
    1412     while(s!=NULL){
    1413       dumpService(s->content);
    1414       s=s->next;
    1415     }
    1416     p=p->next;
     1409 * @param prReg the registry
     1410 */
     1411void dumpRegistry(registry* prReg){
     1412  registry* prCurs=prReg;
     1413  while(prCurs!=NULL){
     1414    services* psServ=prCurs->content;
     1415    fprintf(stderr,"%s \n",prCurs->name);
     1416    psServ=prCurs->content;
     1417    while(psServ!=NULL){
     1418      dumpService(psServ->content);
     1419      psServ=psServ->next;
     1420    }
     1421    prCurs=prCurs->next;
    14171422  }
    14181423}
     
    14211426 * Add a service to the registry
    14221427 *
    1423  * @param reg the resgitry to add the service
    1424  * @param name the registry name to update
    1425  * @param content the service to add
    1426  */
    1427 bool addServiceToRegistry(registry** reg,char* name,service* content){
    1428   registry *l=*reg;
     1428 * @param prReg the resgitry to add the service
     1429 * @param pcName the registry name to update
     1430 * @param psContent the service to add
     1431 */
     1432bool addServiceToRegistry(registry** prReg,char* pcName,service* psContent){
     1433  registry *l=*prReg;
    14291434  int isInitial=-1;
    14301435  if(l==NULL){
     
    14351440    int hasLevel=-1;
    14361441    while(isInitial<0 && l!=NULL){
    1437       if(l->name!=NULL && strcasecmp(name,l->name)==0){
     1442      if(l->name!=NULL && strcasecmp(pcName,l->name)==0){
    14381443        hasLevel=1;
    14391444        break;
     
    14441449      if(isInitial<0)
    14451450        l=(registry*)malloc(REGISTRY_SIZE);
    1446       l->name=zStrdup(name);
     1451      l->name=zStrdup(pcName);
    14471452      l->content=NULL;
    14481453      l->next=NULL;
     
    14501455    if(l->content==NULL){
    14511456      l->content=(services*)malloc(SERVICES_SIZE);
    1452       l->content->content=dupService(content);
     1457      l->content->content=dupService(psContent);
    14531458      l->content->next=NULL;
    14541459    }
    14551460    else{
    1456       services* s=l->content;
    1457       while(s->next!=NULL)
    1458         s=s->next;
    1459       s->next=(services*)malloc(SERVICES_SIZE);
    1460       s->next->content=dupService(content);
    1461       s->next->next=NULL;
     1461      services* psServ=l->content;
     1462      while(psServ->next!=NULL)
     1463        psServ=psServ->next;
     1464      psServ->next=(services*)malloc(SERVICES_SIZE);
     1465      psServ->next->content=dupService(psContent);
     1466      psServ->next->next=NULL;
    14621467    }
    14631468    l->next=NULL;
    14641469    if(isInitial>0)
    1465       *reg=l;
     1470      *prReg=l;
    14661471    else{
    1467       registry *r=*reg;
    1468       while(r->next!=NULL)
    1469         r=r->next;
    1470       r->next=l;
    1471       r->next->next=NULL;
     1472      registry *prCurs=*prReg;
     1473      while(prCurs->next!=NULL)
     1474        prCurs=prCurs->next;
     1475      prCurs->next=l;
     1476      prCurs->next->next=NULL;
    14721477    }
    14731478    return true;
     
    14801485 * Free memory allocated for the registry
    14811486 *
    1482  * @param r the registry
    1483  */
    1484 void freeRegistry(registry** r){
    1485   registry* lr=*r;
    1486   while(lr!=NULL){
    1487     services* s=lr->content;
    1488     free(lr->name);
    1489     while(s!=NULL){
    1490       service* s1=s->content;
    1491       s=s->next;
    1492       if(s1!=NULL){
    1493         freeService(&s1);
    1494         free(s1);
    1495         s1=NULL;
     1487 * @param prReg the registry
     1488 */
     1489void freeRegistry(registry** prReg){
     1490  registry* prLocalRef=*prReg;
     1491  while(prLocalRef!=NULL){
     1492    services* psServ=prLocalRef->content;
     1493    free(prLocalRef->name);
     1494    while(psServ!=NULL){
     1495      service* psServ1=psServ->content;
     1496      psServ=psServ->next;
     1497      if(psServ1!=NULL){
     1498        freeService(&psServ1);
     1499        free(psServ1);
     1500        psServ1=NULL;
    14961501      }
    14971502    }
    1498     lr=lr->next;
     1503    prLocalRef=prLocalRef->next;
    14991504  }   
    15001505}
     
    15031508 * Access a service in the registry
    15041509 *
    1505  * @param r the registry
    1506  * @param level the regitry to search ("concept", "generic" or "implementation")
    1507  * @param sname the service name
     1510 * @param prReg the registry
     1511 * @param pcLevel the regitry to search ("concept", "generic" or "implementation")
     1512 * @param pcName the service name
    15081513 * @return the service pointer if a corresponding service was found or NULL
    15091514 */
    1510 service* getServiceFromRegistry(registry* r,char  *level,char* sname){
    1511   registry *lr=r;
    1512   while(lr!=NULL){
    1513     if(strcasecmp(lr->name,level)==0){
    1514       services* s=lr->content;
    1515       while(s!=NULL){
    1516         if(s->content!=NULL && strcasecmp(s->content->name,sname)==0)
    1517           return s->content;
    1518         s=s->next;
     1515service* getServiceFromRegistry(registry* prReg,char  *pcLevel,char* pcName){
     1516  registry *prLocalRef=prReg;
     1517  while(prLocalRef!=NULL){
     1518    if(strcasecmp(prLocalRef->name,pcLevel)==0){
     1519      services* psServ=prLocalRef->content;
     1520      while(psServ!=NULL){
     1521        if(psServ->content!=NULL && strcasecmp(psServ->content->name,pcName)==0)
     1522          return psServ->content;
     1523        psServ=psServ->next;
    15191524      }
    15201525      break;
    15211526    }
    1522     lr=lr->next;
     1527    prLocalRef=prLocalRef->next;
    15231528  }
    15241529  return NULL;
     
    15281533 * Apply inheritance to an out map from a reference in map
    15291534 *
    1530  * @param out the map to update
    1531  * @param in the reference map (containing inherited properties)
    1532  */
    1533 void inheritMap(map** out,map* in){
    1534   map* content=in;
    1535   if((*out)==NULL){
    1536     addMapToMap(out,in);
     1535 * @param ppmOut the map to update
     1536 * @param pmIn the reference map (containing inherited properties)
     1537 */
     1538void inheritMap(map** ppmOut,map* pmIn){
     1539  map* pmContent=pmIn;
     1540  if((*ppmOut)==NULL){
     1541    addMapToMap(ppmOut,pmIn);
    15371542    return;
    15381543  }
    1539   while(content!=NULL){
    1540     map* cmap=getMap(*out,content->name);
    1541     if(cmap==NULL)
    1542       addToMap(*out,content->name,content->value);
    1543     content=content->next;
     1544  while(pmContent!=NULL){
     1545    map* pmCurrent=getMap(*ppmOut,pmContent->name);
     1546    if(pmCurrent==NULL)
     1547      addToMap(*ppmOut,pmCurrent->name,pmCurrent->value);
     1548    pmCurrent=pmCurrent->next;
    15441549  }
    15451550}
     
    15481553 * Apply inheritance to an out iotype from a reference in iotype
    15491554 *
    1550  * @param out the iotype to update
    1551  * @param in the reference iotype (containing inherited properties)
    1552  */
    1553 void inheritIOType(iotype** out,iotype* in){
    1554   iotype* io=in;
    1555   iotype* oio=*out;
    1556   if(io!=NULL){
    1557     if(*out==NULL){
    1558       *out=(iotype*)malloc(IOTYPE_SIZE);
    1559       (*out)->content=NULL;
    1560       addMapToMap(&(*out)->content,io->content);
    1561       (*out)->next=NULL;
    1562       oio=*out;
    1563       inheritIOType(&oio->next,io->next);
     1555 * @param ppiotOut the iotype to update
     1556 * @param piotIn the reference iotype (containing inherited properties)
     1557 */
     1558void inheritIOType(iotype** ppiotOut,iotype* piotIn){
     1559  iotype* piotInCurosor=piotIn;
     1560  iotype* ppiotOutCursor=*ppiotOut;
     1561  if(piotInCurosor!=NULL){
     1562    if(*ppiotOut==NULL){
     1563      *ppiotOut=(iotype*)malloc(IOTYPE_SIZE);
     1564      (*ppiotOut)->content=NULL;
     1565      addMapToMap(&(*ppiotOut)->content,piotInCurosor->content);
     1566      (*ppiotOut)->next=NULL;
     1567      ppiotOutCursor=*ppiotOut;
     1568      inheritIOType(&ppiotOutCursor->next,piotInCurosor->next);
    15641569    }else{
    1565       inheritIOType(&oio->next,io->next);
     1570      inheritIOType(&ppiotOutCursor->next,piotInCurosor->next);
    15661571    }
    15671572  }
     
    15711576 * Apply inheritance to an out elements from a reference in elements
    15721577 *
    1573  * @param out the elements to update
    1574  * @param in the reference elements (containing inherited properties)
    1575  */
    1576 void inheritElements(elements** out,elements* in){
    1577   elements* content=in;
    1578   while(content!=NULL && *out!=NULL){
    1579     elements* cmap=getElements(*out,content->name);
    1580     if(cmap==NULL)
    1581       addToElements(out,content);
     1578 * @param ppeOut the elements to update
     1579 * @param peIn the reference elements (containing inherited properties)
     1580 */
     1581void inheritElements(elements** ppeOut,elements* peIn){
     1582  elements* peContent=peIn;
     1583  while(peContent!=NULL && *ppeOut!=NULL){
     1584    elements* peCurrent=getElements(*ppeOut,peContent->name);
     1585    if(peCurrent==NULL)
     1586      addToElements(ppeOut,peContent);
    15821587    else{
    1583       inheritMap(&cmap->content,content->content);
    1584       inheritMap(&cmap->metadata,content->metadata);
    1585       if(cmap->format==NULL && content->format!=NULL)
    1586         cmap->format=zStrdup(content->format);
    1587       inheritIOType(&cmap->defaults,content->defaults);
    1588       if(cmap->supported==NULL)
    1589         inheritIOType(&cmap->supported,content->supported);
     1588      inheritMap(&peCurrent->content,peContent->content);
     1589      inheritMap(&peCurrent->metadata,peContent->metadata);
     1590      if(peCurrent->format==NULL && peContent->format!=NULL)
     1591        peCurrent->format=zStrdup(peContent->format);
     1592      inheritIOType(&peCurrent->defaults,peContent->defaults);
     1593      if(peCurrent->supported==NULL)
     1594        inheritIOType(&peCurrent->supported,peContent->supported);
    15901595      else{
    1591         iotype* p=content->supported;
    1592         while(p!=NULL){
    1593           addMapToIoType(&cmap->supported,p->content);
    1594           p=p->next;
     1596        iotype* piotTmp=peContent->supported;
     1597        while(piotTmp!=NULL){
     1598          addMapToIoType(&peCurrent->supported,piotTmp->content);
     1599          piotTmp=piotTmp->next;
    15951600        }
    15961601      }
    15971602    }
    1598     content=content->next;
     1603    peContent=peContent->next;
    15991604  }
    16001605}
     
    16031608 * Apply inheritance to a service based on a registry
    16041609 *
    1605  * @param r the registry storing profiles hierarchy
    1606  * @param s the service to update depending on its inheritance
    1607  */
    1608 void inheritance(registry *r,service** s){
    1609   service* ls=*s;
     1610 * @param prReg the registry storing profiles hierarchy
     1611 * @param psServ the service to update depending on its inheritance
     1612 */
     1613void inheritance(registry *prReg,service** psServ){
     1614  service* psCursor=*psServ;
    16101615  map *profile,*level;
    1611   if(r==NULL)
     1616  if(prReg==NULL)
    16121617    return;
    1613   if(ls==NULL || ls->content==NULL)
     1618  if(psCursor==NULL || psCursor->content==NULL)
    16141619    return;
    1615   profile=getMap(ls->content,"extend");
    1616   level=getMap(ls->content,"level");
     1620  profile=getMap(psCursor->content,"extend");
     1621  level=getMap(psCursor->content,"level");
    16171622  if(profile!=NULL&&level!=NULL){
    16181623    service* s1;
    16191624    if(strncasecmp(level->value,"profile",7)==0)
    1620       s1=getServiceFromRegistry(r,(char*)"generic",profile->value);
     1625      s1=getServiceFromRegistry(prReg,(char*)"generic",profile->value);
    16211626    else
    1622       s1=getServiceFromRegistry(r,level->value,profile->value);
     1627      s1=getServiceFromRegistry(prReg,level->value,profile->value);
    16231628     
    1624     inheritMap(&ls->content,s1->content);
    1625     inheritMap(&ls->metadata,s1->metadata);
    1626     if(ls->inputs==NULL && s1->inputs!=NULL){
    1627       ls->inputs=dupElements(s1->inputs);
     1629    inheritMap(&psCursor->content,s1->content);
     1630    inheritMap(&psCursor->metadata,s1->metadata);
     1631    if(psCursor->inputs==NULL && s1->inputs!=NULL){
     1632      psCursor->inputs=dupElements(s1->inputs);
    16281633    }else{
    1629       inheritElements(&ls->inputs,s1->inputs);
    1630     }
    1631     if(ls->outputs==NULL && s1->outputs!=NULL){
    1632       ls->outputs=dupElements(s1->outputs);
     1634      inheritElements(&psCursor->inputs,s1->inputs);
     1635    }
     1636    if(psCursor->outputs==NULL && s1->outputs!=NULL){
     1637      psCursor->outputs=dupElements(s1->outputs);
    16331638    }else
    1634       inheritElements(&ls->outputs,s1->outputs);
     1639      inheritElements(&psCursor->outputs,s1->outputs);
    16351640  }
    16361641}
     
    16391644 * Convert a maps to a char*** (only used for Fortran support)
    16401645 *
    1641  * @param m the maps to convert
    1642  * @param c the resulting array
    1643  */
    1644 void mapsToCharXXX(maps* m,char*** c){
    1645   maps* tm=m;
     1646 * @param pmsMap the maps to convert
     1647 * @param pppcValues the resulting array
     1648 */
     1649void mapsToCharXXX(maps* pmsMap,char*** pppcValues){
     1650  maps* pmsCursor=pmsMap;
    16461651  int i=0;
    16471652  int j=0;
    1648   char tmp[10][30][1024];
    1649   memset(tmp,0,1024*10*10);
    1650   while(tm!=NULL){
    1651     map* tc=tm->content;
     1653  char aaacTmp[10][30][1024];
     1654  memset(aaacTmp,0,1024*10*10);
     1655  while(pmsCursor!=NULL){
     1656    map* pmContent=pmsCursor->content;
    16521657    if(i>=10)
    16531658      break;
    1654     strcpy(tmp[i][j],"name");
     1659    strcpy(aaacTmp[i][j],"name");
    16551660    j++;
    1656     strcpy(tmp[i][j],tm->name);
     1661    strcpy(aaacTmp[i][j],pmsCursor->name);
    16571662    j++;
    1658     while(tc!=NULL){
     1663    while(pmContent!=NULL){
    16591664      if(j>=30)
    16601665        break;
    1661       strcpy(tmp[i][j],tc->name);
     1666      strcpy(aaacTmp[i][j],pmContent->name);
    16621667      j++;
    1663       strcpy(tmp[i][j],tc->value);
     1668      strcpy(aaacTmp[i][j],pmContent->value);
    16641669      j++;
    1665       tc=tc->next;
    1666     }
    1667     tm=tm->next;
     1670      pmContent=pmContent->next;
     1671    }
     1672    pmsCursor=pmsCursor->next;
    16681673    j=0;
    16691674    i++;
    16701675  }
    1671   memcpy(c,tmp,10*10*1024);
     1676  memcpy(pppcValues,aaacTmp,10*10*1024);
    16721677}
    16731678
     
    16751680 * Convert a char*** to a maps (only used for Fortran support)
    16761681 *
    1677  * @param c the array to convert
    1678  * @param m the resulting maps
    1679  */
    1680 void charxxxToMaps(char*** c,maps**m){
    1681   maps* trorf=*m;
     1682 * @param pppcValues the array to convert
     1683 * @param ppmsMaps the resulting maps
     1684 */
     1685void charxxxToMaps(char*** pppcValues,maps** ppmsMaps){
     1686  maps* pmsCursor=*ppmsMaps;
    16821687  int i,j;
    1683   char tmp[10][30][1024];
    1684   memcpy(tmp,c,10*30*1024);
     1688  char aaaTmp[10][30][1024];
     1689  memcpy(aaaTmp,pppcValues,10*30*1024);
    16851690  for(i=0;i<10;i++){
    1686     if(strlen(tmp[i][1])==0)
     1691    if(strlen(aaaTmp[i][1])==0)
    16871692      break;
    1688     trorf->name=tmp[i][1];
    1689     trorf->content=NULL;
    1690     trorf->next=NULL;
     1693    pmsCursor->name=aaaTmp[i][1];
     1694    pmsCursor->content=NULL;
     1695    pmsCursor->next=NULL;
    16911696    for(j=2;j<29;j+=2){
    1692       if(strlen(tmp[i][j+1])==0)
     1697      if(strlen(aaaTmp[i][j+1])==0)
    16931698        break;
    1694       if(trorf->content==NULL)
    1695         trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
     1699      if(pmsCursor->content==NULL)
     1700        pmsCursor->content=createMap(aaaTmp[i][j],aaaTmp[i][j+1]);
    16961701      else
    1697         addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
    1698     }
    1699     trorf=trorf->next;
    1700   }
    1701   m=&trorf;
     1702        addToMap(pmsCursor->content,aaaTmp[i][j],aaaTmp[i][j+1]);
     1703    }
     1704    pmsCursor=pmsCursor->next;
     1705  }
     1706  ppmsMaps=&pmsCursor;
    17021707}
    17031708
     
    17051710 * Verify that a map has a value
    17061711 *
    1707  * @param map pointer to map that should be checked
     1712 * @param pmMap pointer to map that should be checked
    17081713 * @return true if map has a value or false if value is missing/empty/NULL
    17091714 */
    1710 bool nonempty(map* map) {
    1711         return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);
     1715bool nonempty(map* pmMap) {
     1716  return (pmMap != NULL && pmMap->value != NULL && strlen(pmMap->value) > 0 && strcmp(pmMap->value, "NULL") != 0);
    17121717}
    17131718
     
    17161721 * data structure, and obtain that value
    17171722 *
    1718  * @param source pointer to maps structure
    1719  * @param node name of maps node to search
    1720  * @param key name of map node to find
    1721  * @param kvp address to the map* if it exists, otherwise NULL
     1723 * @param pmsSource pointer to maps structure
     1724 * @param pccNode name of maps node to search
     1725 * @param pccKey name of map node to find
     1726 * @param ppmKvp address to the map* if it exists, otherwise NULL
    17221727 * @return true if map has a value or false if value is missing/NULL
    17231728 *
    17241729 * @note The map assigned to kvp is owned by the source maps
    17251730 */
    1726 bool hasvalue(maps* source, const char* node, const char* key, map** kvp) {
    1727         *kvp = getMapFromMaps(source, node, key);
    1728         return (*kvp != NULL && (*kvp)->value != NULL &&
    1729                 strlen((*kvp)->value) > 0 && strcmp((*kvp)->value, "NULL") != 0);
     1731bool hasvalue(maps* pmsSource, const char* pccNode, const char* pccKey, map** ppmKvp) {
     1732  *ppmKvp = getMapFromMaps(pmsSource, pccNode, pccKey);
     1733  return (*ppmKvp != NULL && (*ppmKvp)->value != NULL &&
     1734          strlen((*ppmKvp)->value) > 0 && strcmp((*ppmKvp)->value, "NULL") != 0);
    17301735}
    17311736
     
    17331738 * Set error message in configuration maps
    17341739 *
    1735  * @param conf reference to configuration maps
    1736  * @param service name of service
    1737  * @param exc WPSException code
    1738  * @param message exception text (default: exception text in WPS specification)
    1739  */
    1740 void setErrorMessage(maps*& conf, const char* service, WPSException exc, const char* message) {
    1741 
    1742         if (message == NULL) {
    1743                 message = WPSExceptionText[exc];
    1744         }
    1745 
    1746         size_t len = strlen(service) + strlen(": ") + strlen(message) + strlen(": ") + strlen(WPSExceptionCode[exc]) + 16;
    1747         char* msg = (char*)malloc(len * sizeof(char));
    1748 
    1749         if (msg != NULL) {
    1750                 snprintf(msg, len * sizeof(char), "\n%s: %s: %s\n", service, message, WPSExceptionCode[exc]);
    1751                 setMapInMaps(conf, "lenv", "message", msg);
    1752                 free(msg);
    1753         }
    1754 }
    1755 
    1756 void logMessage(const char* source, const char* function, int line, const char* file, const char* message) { //, const char* source, const char* function, int line) {
    1757 
    1758         size_t msglen = 512;
    1759         const char empty[] = "";
    1760 
    1761         FILE* log;
    1762 
    1763         // system time, process time [nanoseconds]   
    1764         unsigned long long sys_t, proc_t;
    1765 
    1766         // processor time consumed by the program:
    1767         clock_t t = clock();
    1768 
    1769         // system time:
    1770         std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
    1771 
    1772         std::time_t now_t = std::chrono::system_clock::to_time_t(now);
    1773         std::tm* tm = localtime(&now_t);
    1774         char* str = asctime(tm);
    1775         str[strlen(str) - 1] = '\0'; // remove newline
    1776 
    1777         sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
    1778         //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
    1779         proc_t = t;
    1780 
    1781         if (message != NULL) {
    1782                 msglen += strlen(message);
    1783         }
    1784         else {
    1785                 message = empty;
    1786         }
    1787         //getLastErrorMessage(); // cgiScriptName 
    1788         char* text = (char*)malloc(sizeof(char)*msglen);
    1789 
    1790         snprintf(text, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
    1791                 zGetpid(), source, line, function, str, sys_t, proc_t, message); // __FILE__ __LINE__ __func__ //
    1792 
    1793         if (file != NULL && (log = fopen(file, "a+")) != NULL) {
    1794                 fputs(text, log);
    1795                 fclose(log);
    1796         }
    1797         else {
     1740 * @param pmsaConf reference to configuration maps
     1741 * @param pccService name of service
     1742 * @param weExc WPSException code
     1743 * @param pccMessage exception text (default: exception text in WPS specification)
     1744 */
     1745void setErrorMessage(maps*& pmsaConf, const char* pccService, WPSException weExc, const char* pccMessage) {
     1746  if (pccMessage == NULL) {
     1747    pccMessage = WPSExceptionText[weExc];
     1748  }
     1749  size_t len = strlen(pccService) + strlen(": ") + strlen(pccMessage) + strlen(": ") + strlen(WPSExceptionCode[weExc]) + 16;
     1750  char* pcMsg = (char*)malloc(len * sizeof(char));
     1751  if (pcMsg != NULL) {
     1752    snprintf(pcMsg, len * sizeof(char), "\n%s: %s: %s\n", pccService, pccMessage, WPSExceptionCode[weExc]);
     1753    setMapInMaps(pmsaConf, "lenv", "message", pcMsg);
     1754    free(pcMsg);
     1755  }
     1756}
     1757
     1758/**
     1759 * Print debug message
     1760 *
     1761 * @param pccSource the file invoking the function
     1762 * @param pccFunction the function calling for logMessage
     1763 * @param iLine the line number
     1764 * @param pccFile the file to log informations
     1765 * @param pccMessage the message to be print
     1766 */
     1767void logMessage(const char* pccSource, const char* pccFunction, int iLne, const char* pccFile, const char* pccMessage) { //, const char* source, const char* function, int line) {
     1768
     1769  size_t msglen = 512;
     1770  const char empty[] = "";
     1771
     1772  FILE* pfLog;
     1773
     1774  // system time, process time [nanoseconds]   
     1775  unsigned long long sys_t, proc_t;
     1776
     1777  // processor time consumed by the program:
     1778  clock_t t = clock();
     1779
     1780  // system time:
     1781  std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
     1782
     1783  std::time_t now_t = std::chrono::system_clock::to_time_t(now);
     1784  std::tm* tm = localtime(&now_t);
     1785  char* pcStr = asctime(tm);
     1786  pcStr[strlen(pcStr) - 1] = '\0'; // remove newline
     1787
     1788  sys_t = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
     1789  //proc_t = (unsigned long long)(1.0e9*t/CLOCKS_PER_SEC);
     1790  proc_t = t;
     1791
     1792  if (pccMessage != NULL) {
     1793    msglen += strlen(pccMessage);
     1794  }
     1795  else {
     1796    pccMessage = empty;
     1797  }
     1798  //getLastErrorMessage(); // cgiScriptName 
     1799  char* pcText = (char*)malloc(sizeof(char)*msglen);
     1800
     1801  snprintf(pcText, msglen, "pid: %d %s line %d %s() %s systime: %lld ns ticks: %lld %s\n",
     1802           zGetpid(), pccSource, iLne, pccFunction, pcStr, sys_t, proc_t, pccMessage); // __FILE__ __LINE__ __func__ //
     1803
     1804  if (pccFile != NULL && (pfLog = fopen(pccFile, "a+")) != NULL) {
     1805    fputs(pcText, pfLog);
     1806    fclose(pfLog);
     1807  }
     1808  else {
    17981809#ifdef MSG_LOG_FILE
    1799                 if ((log = fopen(MSG_LOG_FILE, "a+")) != NULL) {
    1800                         fputs(text, log);
    1801                         fclose(log);
    1802                 }
     1810    if ((pfLog = fopen(MSG_LOG_FILE, "a+")) != NULL) {
     1811      fputs(pcText, pfLog);
     1812      fclose(pfLog);
     1813    }
    18031814#endif
    1804         }
    1805 
    1806         if (text != NULL) free(text);
     1815  }
     1816
     1817  if (pcText != NULL) free(pcText);
    18071818}
    18081819
     
    18151826#ifdef WIN32
    18161827#ifndef USE_MS
    1817 char *strcasestr (char const *a, char const *b)
     1828char *strcasestr (char const *pccA, char const *pccB)
    18181829  {
    1819     char *x = zStrdup (a);
    1820     char *y = zStrdup (b);
     1830    char *pcX = zStrdup (pccA);
     1831    char *pcY = zStrdup (pccB);
    18211832 
    1822       x = _strlwr (x);
    1823       y = _strlwr (y);
    1824     char *pos = strstr (x, y);
    1825     char *ret = pos == NULL ? NULL : (char *) (a + (pos - x));
    1826       free (x);
    1827       free (y);
     1833      pcX = _strlwr (pcX);
     1834      pcY = _strlwr (pcY);
     1835    char *pos = strstr (pcX, pcY);
     1836    char *ret = pos == NULL ? NULL : (char *) (pccA + (pos - pcX));
     1837      free (pcX);
     1838      free (pcY);
    18281839      return ret;
    18291840  };
     
    18431854 * The memory should be deallocated by calling freeMap.
    18441855 */
    1845 char* allocateMapValue(map* node, size_t num_bytes)
     1856char* allocateMapValue(map* pmNode, size_t sNumBytes)
    18461857{
    1847         if (node == NULL) {
    1848                 return NULL;
    1849         }
    1850 
    1851         if (node->value != NULL) {
    1852                 free(node->value);
    1853         }
    1854         node->value = (char*) malloc(num_bytes);
     1858  if (pmNode == NULL) {
     1859    return NULL;
     1860  }
     1861
     1862  if (pmNode->value != NULL) {
     1863    free(pmNode->value);
     1864  }
     1865  pmNode->value = (char*) malloc(sNumBytes);
    18551866               
    1856         return node->value;
    1857 }
     1867  return pmNode->value;
     1868}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png