Changeset 967 for trunk/zoo-project/zoo-kernel/service.c
- Timestamp:
- Dec 18, 2020, 2:13:22 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service.c
r961 r967 39 39 * See https://dxr.mozilla.org/mozilla-central/source/media/mtransport/third_party/nrappkit/src/util/util.c 40 40 */ 41 int snprintf(char * buffer, size_t n, const char *format, ...)41 int snprintf(char *pcBuffer, size_t n, const char *pccFormat, ...) 42 42 { 43 43 va_list argp; 44 44 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); 48 48 va_end(argp); 49 49 return ret; … … 54 54 * Dump a map on stderr 55 55 * 56 * @param tthe map to dump57 */ 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 */ 58 void _dumpMap(map* pmMap){ 59 if(pmMap!=NULL){ 60 fprintf(stderr,"%s: %s\n",pmMap->name,pmMap->value); 61 61 fflush(stderr); 62 62 }else{ … … 69 69 * Dump a map on stderr, see _dumpMap() 70 70 * 71 * @param tthe map to dump72 */ 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 */ 73 void dumpMap(map* pmMap){ 74 map* pmTmp=pmMap; 75 while(pmTmp!=NULL){ 76 _dumpMap(pmTmp); 77 pmTmp=pmTmp->next; 78 78 } 79 79 } … … 82 82 * Dump a map to a file 83 83 * 84 * @param tthe map to dump to file85 * @param file the file pointer to store the map86 */ 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 */ 87 void 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; 92 92 } 93 93 } … … 96 96 * Dump a maps on stderr, see dumpMap(). 97 97 * 98 * @param mthe map to dump99 */ 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 */ 100 void 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; 112 112 } 113 113 } … … 116 116 * Dump a maps to a file, see dumpMapToFile(). 117 117 * 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 */ 122 void _dumpMapsToFile(maps* pmsMaps,FILE* psFile,int iLimit){ 123 maps* tmp=pmsMaps; 123 124 int cnt=0; 124 125 while(tmp!=NULL){ 125 fprintf( file,"[%s]\n",tmp->name);126 fprintf(psFile,"[%s]\n",tmp->name); 126 127 if(tmp->child!=NULL){ 127 _dumpMapsToFile(tmp->child, file,limit);128 _dumpMapsToFile(tmp->child,psFile,iLimit); 128 129 }else 129 dumpMapToFile(tmp->content, file);130 fflush( file);130 dumpMapToFile(tmp->content,psFile); 131 fflush(psFile); 131 132 tmp=tmp->next; 132 133 cnt++; 133 if( limit>=0 && cnt==limit)134 if(iLimit>=0 && cnt==iLimit) 134 135 tmp=NULL; 135 136 } 136 fflush( file);137 fflush(psFile); 137 138 } 138 139 … … 140 141 * Dump a maps to a file, see _dumpMapsToFile(). 141 142 * 142 * @param mthe map to dump143 * @param file_path the full path to the file nameto store the map144 * @param limit the number limiting the maps to be dumped145 */ 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 */ 147 void dumpMapsToFile(maps* pmsMaps,char* pcaFilePath,int iLimit){ 148 FILE* psFile=fopen(pcaFilePath,"w+"); 149 _dumpMapsToFile(pmsMaps,psFile,iLimit); 150 fflush(psFile); 151 fclose(psFile); 151 152 } 152 153 … … 157 158 */ 158 159 iotype* 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; 163 164 } 164 165 … … 166 167 * Create a new map 167 168 * 168 * @param name the key to add to the map169 * @param value the corresponding value to add to the map169 * @param pccName the key to add to the map 170 * @param pccValue the corresponding value to add to the map 170 171 * @return a pointer to the allocated map 171 172 */ 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;173 map* 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; 178 179 } 179 180 … … 181 182 * Create a new maps with the given name 182 183 * 183 * @param name of the maps184 * @param pccName of the maps 184 185 * @return the allocated map 185 186 */ 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;187 maps* 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; 193 194 } 194 195 … … 196 197 * Count number of map in a map 197 198 * 198 * @param mthe map to count199 * @param pmMap the map to count 199 200 * @return number of map in a map 200 201 */ 201 int count(map* m){202 map* tmp=m;202 int count(map* pmMap){ 203 map* pmTmp=pmMap; 203 204 int c=0; 204 while( tmp!=NULL){205 while(pmTmp!=NULL){ 205 206 c++; 206 tmp=tmp->next;207 pmTmp=pmTmp->next; 207 208 } 208 209 return c; … … 212 213 * Count number of maps in a maps 213 214 * 214 * @param mthe maps to count215 * @param pmMap the maps to count 215 216 * @return number of maps in a maps 216 217 */ 217 int maps_length(maps* m){218 maps* tmp=m;218 int maps_length(maps* pmMap){ 219 maps* pmTmp=pmMap; 219 220 int c=0; 220 while( tmp!=NULL){221 while(pmTmp!=NULL){ 221 222 c++; 222 tmp=tmp->next;223 pmTmp=pmTmp->next; 223 224 } 224 225 return c; … … 228 229 * Verify if a key exist in a map 229 230 * 230 * @param mthe map to search for the key231 * @param key the key to search in the map231 * @param pmMap the map to search for the key 232 * @param pccKey the key to search in the map 232 233 * @return true if the key wwas found, false in other case 233 234 */ 234 bool hasKey(map* m,const char *key){235 map* tmp=m;236 while( tmp!=NULL){237 if(strcasecmp( tmp->name,key)==0)235 bool hasKey(map* pmMap,const char *pccKey){ 236 map* pmTmp=pmMap; 237 while(pmTmp!=NULL){ 238 if(strcasecmp(pmTmp->name,pccKey)==0) 238 239 return true; 239 tmp=tmp->next;240 pmTmp=pmTmp->next; 240 241 } 241 242 #ifdef DEBUG_MAP … … 248 249 * Access a specific maps 249 250 * 250 * @param mthe maps to search for the key251 * @param key the key to search in the maps251 * @param pmMap the maps to search for the key 252 * @param pccKey the key to search in the maps 252 253 * @return a pointer on the maps found or NULL if not found 253 254 */ 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;255 maps* 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; 261 262 } 262 263 return NULL; … … 266 267 * Access a specific map 267 268 * 268 * @param mthe map to search for the key269 * @param key the key to search in the map269 * @param pmMap the map to search for the key 270 * @param pccKey the key to search in the map 270 271 * @return a pointer on the map found or NULL if not found 271 272 */ 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;273 map* 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; 279 280 } 280 281 return NULL; … … 285 286 * Access the last map 286 287 * 287 * @param mthe map to search for the lastest map288 * @param pmMap the map to search for the lastest map 288 289 * @return a pointer on the lastest map found or NULL if not found 289 290 */ 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;291 map* getLastMap(map* pmMap){ 292 map* pmTmp=pmMap; 293 while(pmTmp!=NULL){ 294 if(pmTmp->next==NULL){ 295 return pmTmp; 296 } 297 pmTmp=pmTmp->next; 297 298 } 298 299 return NULL; … … 302 303 * Access a specific map from a maps 303 304 * 304 * @param mthe maps to search for the key305 * @param key the key to search in the maps306 * @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) 307 308 * @return a pointer on the map found or NULL if not found 308 309 */ 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;310 map* 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; 314 315 } 315 316 else return NULL; … … 320 321 * Require to call free on mo after calling this function. 321 322 * 322 * @param mothe map to free323 */ 324 void freeMap(map** mo){325 map* _cursor=*mo;326 if( _cursor!=NULL){323 * @param pmMap the map to free 324 */ 325 void freeMap(map** pmMap){ 326 map* pmCursor=*pmMap; 327 if(pmCursor!=NULL){ 327 328 #ifdef DEBUG 328 329 fprintf(stderr,"freeMap\n"); 329 330 #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); 338 339 } 339 340 } … … 344 345 * Require to call free on mo after calling this function. 345 346 * 346 * @param mothe maps to free347 */ 348 void freeMaps(maps** mo){349 maps* _cursor=*mo;350 if( _cursor && _cursor!=NULL){347 * @param pmMap the maps to free 348 */ 349 void freeMaps(maps** pmMap){ 350 maps* pmCursor=*pmMap; 351 if(pmCursor && pmCursor!=NULL){ 351 352 #ifdef DEBUG 352 353 fprintf(stderr,"freeMaps\n"); 353 354 #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); 366 367 } 367 368 } … … 371 372 * Verify if an elements contains a name equal to the given key. 372 373 * 373 * @param ethe elements to search for the key374 * @param key the elements name to search374 * @param peElem the elements to search for the key 375 * @param pccKey the elements name to search 375 376 * @return true if the elements contains the name, false in other cases. 376 377 */ 377 bool hasElement(elements* e,const char* key){378 elements* tmp=e;379 while( tmp!=NULL){380 if(strcasecmp( key,tmp->name)==0)378 bool hasElement(elements* peElem,const char* pccKey){ 379 elements* peTmp=peElem; 380 while(peTmp!=NULL){ 381 if(strcasecmp(pccKey,peTmp->name)==0) 381 382 return true; 382 tmp=tmp->next;383 peTmp=peTmp->next; 383 384 } 384 385 return false; … … 388 389 * Access a specific elements named key. 389 390 * 390 * @param m the elements to search391 * @param key the elements name to search391 * @param peElem the elements to search 392 * @param pccKey the elements name to search 392 393 * @return a pointer to the specific element if found, NULL in other case. 393 394 */ 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;395 elements* 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; 400 401 } 401 402 return NULL; … … 406 407 * Require to call free on i after calling this function. 407 408 * 408 * @param ithe iotype to free409 */ 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 */ 411 void 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); 419 420 } 420 421 } … … 424 425 * Require to call free on e after calling this function. 425 426 * 426 * @param ethe iotype to free427 */ 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 */ 429 void 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); 459 460 } 460 461 } … … 469 470 */ 470 471 service* 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; 479 480 } 480 481 … … 483 484 * Require to be invoked for every createService call. 484 485 * 485 * @param sthe service to free486 */ 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 */ 488 void 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); 507 508 } 508 509 } … … 511 512 * Add key value pair to an existing map. 512 513 * 513 * @param mthe map to add the KVP514 * @param nthe key to add515 * @param vthe corresponding value to add516 */ 517 void addToMap(map* m,const char* n,const char* v){518 if (m!= NULL) { // knut: add NULL-pointer check519 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 527 map *tmp = getMap(m, n);528 529 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 */ 518 void 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 } 533 534 } 534 535 … … 536 537 * Add a key and an integer value to an existing map. 537 538 * 538 * @param mthe map to add the KVP539 * @param nthe key to add540 * @param vthe corresponding value to add541 */ 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 */ 543 void 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); 551 552 } 552 553 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); 557 558 } 558 559 } … … 561 562 * Add a key and a binary value to an existing map. 562 563 * 563 * @param mthe map to add the KVP564 * @param nthe key to add565 * @param vthe corresponding value to add566 * @param size the size of the given value564 * @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 567 568 * @return a pointer to the updated map m 568 569 */ 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;570 map* 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; 575 576 if(_cursor!=NULL){ 576 addToMap( m,n,"");577 addToMap(pMap,pccName,""); 577 578 }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; 593 594 } 594 595 … … 596 597 * Add a map at the end of another map. 597 598 * 598 * @param mo the map to add mi599 * @param mi the map to add to mo600 */ 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 */ 602 void 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; 608 609 } 609 610 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); 615 616 } 616 617 else{ 617 addToMap(* mo,tmp->name,tmp->value);618 addToMap(*pmMapOut,pmTmp->name,pmTmp->value); 618 619 } 619 620 } 620 _cursor=*mo;621 tmp=tmp->next;621 pmCursor=*pmMapOut; 622 pmTmp=pmTmp->next; 622 623 } 623 624 } … … 626 627 * Add a map to iotype. 627 628 * 628 * @param iothe iotype to add the map629 * @param mithe map to add to io630 */ 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 */ 632 void 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; 640 641 } 641 642 … … 643 644 * Access a specific map or set its value. 644 645 * 645 * @param mthe map to search for the key646 * @param key the key to search/add in the map647 * @param value the value to add if the key does not exist646 * @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 648 649 * @return a pointer on the map found or NULL if not found 649 650 */ 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);651 map* 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); 656 657 } 657 658 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; 662 663 } 663 664 … … 665 666 * Verify if a map is contained in another map. 666 667 * 667 * @param mthe map to search for i668 * @param ithe map to search in m668 * @param pmMap the map to search for i 669 * @param pmSearch the map to search in m 669 670 * @return true if i was found in m, false in other case 670 671 */ 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){672 bool 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){ 677 678 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) 680 682 return false; 681 683 } 682 i=i->next;684 pmSearch=pmSearch->next; 683 685 } 684 686 return true; … … 688 690 * Access a specific iotype from an elements. 689 691 * 690 * @param ethe elements to search for the name691 * @param name the name to search in the elements e692 * @param values the map to verify it was contained in the defaults or692 * @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 693 695 * supported content of the elements e 694 696 * @return a pointer on the iotype found or NULL if not found 695 697 */ 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;698 iotype* 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; 703 705 else{ 704 iotype* tmp= cursor->supported;706 iotype* tmp=peCursor->supported; 705 707 while(tmp!=NULL){ 706 if(contains(tmp->content, values)==true)708 if(contains(tmp->content,pcValues)==true) 707 709 return tmp; 708 710 tmp=tmp->next; … … 710 712 } 711 713 } 712 cursor=cursor->next;714 peCursor=peCursor->next; 713 715 } 714 716 }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; 718 720 } 719 cursor=cursor->next;721 peCursor=peCursor->next; 720 722 } 721 723 } … … 726 728 * Load binary values from a map (in) and add them to another map (out) 727 729 * 728 * @param out the map to add binaries values729 * @param in the map containing the binary values to add ti out730 * @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 */ 734 void 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){ 737 739 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; 747 749 }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 759 761 /** 760 762 * Load binary values from a map (in) and add them to another map (out). … … 762 764 * @see loadMapBinary 763 765 * 764 * @param out the map to add binaries values765 * @param in the map containing the binary values to add ti out766 */ 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 */ 769 void 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){ 772 774 #ifdef DEBUG 773 775 fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__); … … 775 777 return ; 776 778 } 777 if( length!=NULL){778 int len=atoi( length->value);779 if(pmLength!=NULL){ 780 int len=atoi(pmLength->value); 779 781 int i=0; 780 782 for(i=0;i<len;i++){ 781 loadMapBinary( out,in,i);783 loadMapBinary(ppmOut,pmIn,i); 782 784 } 783 785 } 784 786 else 785 if( size!=NULL)786 loadMapBinary( out,in,-1);787 if(pmSize!=NULL) 788 loadMapBinary(ppmOut,pmIn,-1); 787 789 } 788 790 … … 790 792 * Duplicate a Maps 791 793 * 792 * @param mothe maps to clone794 * @param ppmsOut the maps to clone 793 795 * @return the allocated maps containing a copy of the mo maps 794 796 */ 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;797 maps* 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; 812 814 } 813 815 … … 816 818 * 817 819 * @see addMapToMap, dupMaps, getMaps 818 * @param mothe maps to add mi819 * @param mithe maps to add to mo820 */ 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 */ 823 void 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); 827 829 } 828 830 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); 836 838 else 837 _cursor->next->child=NULL;839 pmsCursor->next->child=NULL; 838 840 } 839 841 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); 843 845 else 844 tmp1->child=NULL;846 pmsTmp1->child=NULL; 845 847 } 846 _cursor=*mo;847 } 848 tmp=tmp->next;848 pmsCursor=*ppmsOut; 849 } 850 pmsTmp=pmsTmp->next; 849 851 } 850 852 } … … 853 855 * Access a specific map array element 854 856 * 855 * @param mthe map to search for the key856 * @param key the key to search in the map857 * @param i ndex of the MapArray857 * @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 858 860 * @return a pointer on the map found or NULL if not found 859 861 */ 860 map* getMapArray(map* m,const char* key,int index){861 char tmp[1024];862 map* tmpMap;863 if(i ndex>0)864 sprintf( tmp,"%s_%d",key,index);862 map* 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); 865 867 else 866 sprintf( tmp,"%s",key);868 sprintf(acTmp,"%s",pccKey); 867 869 #ifdef DEBUG 868 fprintf(stderr,"** KEY %s\n", tmp);870 fprintf(stderr,"** KEY %s\n",acTmp); 869 871 #endif 870 tmpMap=getMap(m,tmp);872 pmTmp=getMap(pmMap,acTmp); 871 873 #ifdef DEBUG 872 if( tmpMap!=NULL)873 dumpMap( tmpMap);874 if(pmTmp!=NULL) 875 dumpMap(pmTmp); 874 876 #endif 875 return tmpMap;877 return pmTmp; 876 878 } 877 879 … … 879 881 * Add a key value in a MapArray for a specific index 880 882 * 881 * @param mthe map to search for the key882 * @param key the key to search in the map883 * @param i ndex the index of the MapArray884 * @param value the value to set in the MapArray883 * @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 885 887 * @return a pointer on the map found or NULL if not found 886 888 */ 887 void setMapArray(map* m,const char* key,int index,const char* value){888 char tmp[1024];889 map* tmpSize;890 if(i ndex>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);889 void 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); 897 899 } 898 900 } 899 901 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* p tr=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 *)""); 906 908 #ifdef DEBUG 907 fprintf(stderr,"%s\n", tmpSize->value);909 fprintf(stderr,"%s\n",pmSize->value); 908 910 #endif 909 free(p tr->value);910 p tr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));911 memcpy(p tr->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)); 912 914 } 913 915 else 914 addToMap( m,tmp,value);916 addToMap(pmMap,acTmp,pccValue); 915 917 } 916 918 … … 918 920 * Add a key and an integer value to an existing map array. 919 921 * 920 * @param mthe map to add the KVP921 * @param nthe key to add922 * @param i ndex the index of the MapArray923 * @param vthe corresponding value to add924 */ 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 */ 927 void 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); 929 931 } 930 932 … … 932 934 * Access the map "type" 933 935 * 934 * @param mtthe map936 * @param pmMap the map 935 937 * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in 936 938 * other case 937 939 */ 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");940 map* 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"); 944 946 } 945 947 } 946 948 #ifdef DEBUG 947 dumpMap( tmap);949 dumpMap(pmMime); 948 950 #endif 949 return tmap;951 return pmMime; 950 952 } 951 953 … … 954 956 * 955 957 * @see getMapType 956 * @param mothe maps957 * @param mithe maps958 * @param typthe map "type"958 * @param pmsOut the maps 959 * @param pmsIn the maps 960 * @param pcType the map "type" 959 961 * @return 960 962 */ 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]={963 int 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]={ 967 969 (char*)"size", 968 970 (char*)"value", … … 973 975 (char*)"fmimeType", 974 976 (char*)"xlink:href", 975 typ,977 pcType, 976 978 (char*)"schema", 977 979 (char*)"encoding", … … 980 982 (char*)"UpperCorner" 981 983 }; 982 int i =0;983 map* tmpLength;984 int iCounter=0; 985 map* pmLength; 984 986 985 if( _cursor==NULL)987 if(pmsCursor==NULL) 986 988 return -1; 987 989 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){ 998 1000 #ifdef DEBUG 999 fprintf(stderr,"%s = %s\n", tmpV[i],tmpVI->value);1001 fprintf(stderr,"%s = %s\n",pmTmp[iCounter],pmTmp->value); 1000 1002 #endif 1001 setMapArray( _cursor->content,tmpV[i],len,tmpVI->value);1003 setMapArray(pmsCursor->content,acV[iCounter],iLen,pmTmp->value); 1002 1004 } 1003 1005 } 1004 1006 1005 addToMap( _cursor->content,"isArray","true");1007 addToMap(pmsCursor->content,"isArray","true"); 1006 1008 return 0; 1007 1009 } … … 1010 1012 * Set a key value pair to a map contained in a Maps 1011 1013 * 1012 * @param mthe maps1013 * @param key the maps name1014 * @param subkey the map name included in the maps corresponding to key1015 * @param value the corresponding value to add in the map1016 */ 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 */ 1019 void 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); 1025 1027 }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); 1031 1033 } 1032 1034 }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); 1038 1040 } 1039 1041 } … … 1045 1047 */ 1046 1048 elements* 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; 1058 1060 } 1059 1061 … … 1061 1063 * Create a named elements 1062 1064 * 1063 * @param name the elements name1065 * @param pcName the elements name 1064 1066 * @return a pointer to the allocated elements 1065 1067 */ 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;1068 elements* 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; 1078 1080 } 1079 1081 … … 1081 1083 * Set the name of an elements 1082 1084 * 1083 * @param name the elements name 1085 * @param peElem the elements to modify 1086 * @param pcName the elements name 1084 1087 * @return a pointer to the allocated elements 1085 1088 */ 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;1089 void 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; 1096 1099 } 1097 1100 … … 1099 1102 * Dump an elements on stderr 1100 1103 * 1101 * @param ethe elements to dump1102 */ 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 */ 1106 void dumpElements(elements* peElem){ 1107 elements* peTmp=peElem; 1108 while(peTmp!=NULL){ 1109 iotype* piotTmp=peTmp->defaults; 1107 1110 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; 1120 1123 ioc++; 1121 1124 } 1122 tmpio=tmp->supported;1125 piotTmp=peTmp->supported; 1123 1126 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; 1128 1131 ioc++; 1129 1132 } 1130 if( tmp->child!=NULL){1133 if(peTmp->child!=NULL){ 1131 1134 fprintf(stderr," > CHILD \n"); 1132 dumpElements( tmp->child);1135 dumpElements(peTmp->child); 1133 1136 } 1134 1137 fprintf(stderr,"------------------\n"); 1135 tmp=tmp->next;1138 peTmp=peTmp->next; 1136 1139 } 1137 1140 } … … 1140 1143 * Dump an elements on stderr using the YAML syntaxe 1141 1144 * 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 */ 1148 void dumpElementsAsYAML(elements* peElem,int iLevel){ 1149 elements* peTmp=peElem; 1146 1150 int i; 1147 while( tmp!=NULL){1148 map* mcurs=tmp->content;1151 while(peTmp!=NULL){ 1152 map* pmCurs=peTmp->content; 1149 1153 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++) 1152 1156 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++) 1156 1160 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++) 1163 1167 fprintf(stderr," "); 1164 1168 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++) 1167 1171 fprintf(stderr," "); 1168 _dumpMap( mcurs);1169 mcurs=mcurs->next;1172 _dumpMap(pmCurs); 1173 pmCurs=pmCurs->next; 1170 1174 } 1171 1175 } 1172 for(i=0;i<4+(4* level);i++)1176 for(i=0;i<4+(4*iLevel);i++) 1173 1177 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); 1176 1180 else{ 1177 1181 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++) 1184 1188 fprintf(stderr," "); 1185 1189 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++) 1189 1193 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); 1192 1196 }else 1193 _dumpMap( mcurs);1194 mcurs=mcurs->next;1197 _dumpMap(pmCurs); 1198 pmCurs=pmCurs->next; 1195 1199 } 1196 tmpio=tmpio->next;1200 piotTmp=piotTmp->next; 1197 1201 ioc++; 1198 1202 } 1199 tmpio=tmp->supported;1203 piotTmp=peTmp->supported; 1200 1204 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++) 1203 1207 fprintf(stderr," "); 1204 1208 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++) 1208 1212 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); 1211 1215 }else 1212 _dumpMap( mcurs);1213 mcurs=mcurs->next;1216 _dumpMap(pmCurs); 1217 pmCurs=pmCurs->next; 1214 1218 } 1215 tmpio=tmpio->next;1219 piotTmp=piotTmp->next; 1216 1220 ioc++; 1217 1221 } 1218 tmp=tmp->next;1222 peTmp=peTmp->next; 1219 1223 } 1220 1224 } … … 1223 1227 * Duplicate an elements 1224 1228 * 1225 * @param ethe elements to clone1229 * @param peElem the elements to clone 1226 1230 * @return the allocated elements containing a copy of the elements e 1227 1231 */ 1228 elements* dupElements(elements* e){1229 elements* cursor=e;1230 elements* tmp=NULL;1231 if( cursor!=NULL && cursor->name!=NULL){1232 elements* dupElements(elements* peElem){ 1233 elements* peCursor=peElem; 1234 elements* peTmp=NULL; 1235 if(peCursor!=NULL && peCursor->name!=NULL){ 1232 1236 #ifdef DEBUG 1233 1237 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); … … 1235 1239 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1236 1240 #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); 1247 1251 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; 1254 1258 #ifdef DEBUG 1255 1259 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1256 dumpMap( tmp->defaults->content);1260 dumpMap(peTmp->defaults->content); 1257 1261 #endif 1258 1262 }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); 1268 1272 #ifdef DEBUG 1269 1273 fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); 1270 dumpMap( tmp->defaults->content);1274 dumpMap(peTmp->defaults->content); 1271 1275 #endif 1272 tmp2=tmp2->next;1276 piotTmp=piotTmp->next; 1273 1277 } 1274 1278 } 1275 1279 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); 1279 1283 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); 1283 1287 else 1284 tmp->next=NULL;1285 } 1286 return tmp;1288 peTmp->next=NULL; 1289 } 1290 return peTmp; 1287 1291 } 1288 1292 … … 1291 1295 * 1292 1296 * @see dupElements 1293 * @param m the elements to add the e1294 * @param ethe elements to be added to m1295 */ 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 */ 1300 void addToElements(elements** ppeElem,elements* peELem){ 1301 elements* peTmp=peELem; 1302 if(*ppeElem==NULL){ 1303 (*ppeElem)=dupElements(peTmp); 1300 1304 }else{ 1301 addToElements(&(* m)->next,tmp);1305 addToElements(&(*ppeElem)->next,peTmp); 1302 1306 } 1303 1307 } … … 1306 1310 * Set the name of a service 1307 1311 * 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 */ 1315 void 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; 1317 1322 } 1318 1323 … … 1320 1325 * Dump a service on stderr 1321 1326 * 1322 * @param sthe service to dump1323 */ 1324 void dumpService(service* s){1325 if( s==NULL)1327 * @param psServ the service to dump 1328 */ 1329 void dumpService(service* psServ){ 1330 if(psServ==NULL) 1326 1331 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){ 1329 1334 fprintf(stderr,"CONTENT MAP\n"); 1330 dumpMap( s->content);1331 if( s->metadata!=NULL)1335 dumpMap(psServ->content); 1336 if(psServ->metadata!=NULL) 1332 1337 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) 1335 1340 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); 1345 1350 } 1346 1351 fprintf(stderr,"++++++++++++++++++\n"); … … 1350 1355 * Dump a service on stderr using the YAML syntaxe 1351 1356 * 1352 * @param sthe service to dump1353 */ 1354 void dumpServiceAsYAML(service* s){1357 * @param psServ the service to dump 1358 */ 1359 void dumpServiceAsYAML(service* psServ){ 1355 1360 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){ 1362 1367 fprintf(stderr,"MetaData:\n"); 1363 while( mcurs!=NULL){1368 while(pmCurs!=NULL){ 1364 1369 for(i=0;i<2;i++) 1365 1370 fprintf(stderr," "); 1366 _dumpMap( mcurs);1367 mcurs=mcurs->next;1371 _dumpMap(pmCurs); 1372 pmCurs=pmCurs->next; 1368 1373 } 1369 1374 } 1370 1375 } 1371 if( s->inputs!=NULL){1376 if(psServ->inputs!=NULL){ 1372 1377 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){ 1376 1381 fprintf(stderr,"\noutputs:\n"); 1377 dumpElementsAsYAML( s->outputs,0);1382 dumpElementsAsYAML(psServ->outputs,0); 1378 1383 } 1379 1384 } … … 1382 1387 * Duplicate a service 1383 1388 * 1384 * @param sthe service to clone1389 * @param psServ the service to clone 1385 1390 * @return the allocated service containing a copy of the serfvice s 1386 1391 */ 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;1392 service* 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; 1399 1404 } 1400 1405 … … 1402 1407 * Print the registry on stderr. 1403 1408 * 1404 * @param rthe registry1405 */ 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 */ 1411 void 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; 1417 1422 } 1418 1423 } … … 1421 1426 * Add a service to the registry 1422 1427 * 1423 * @param reg the resgitry to add the service1424 * @param name the registry name to update1425 * @param content the service to add1426 */ 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 */ 1432 bool addServiceToRegistry(registry** prReg,char* pcName,service* psContent){ 1433 registry *l=*prReg; 1429 1434 int isInitial=-1; 1430 1435 if(l==NULL){ … … 1435 1440 int hasLevel=-1; 1436 1441 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){ 1438 1443 hasLevel=1; 1439 1444 break; … … 1444 1449 if(isInitial<0) 1445 1450 l=(registry*)malloc(REGISTRY_SIZE); 1446 l->name=zStrdup( name);1451 l->name=zStrdup(pcName); 1447 1452 l->content=NULL; 1448 1453 l->next=NULL; … … 1450 1455 if(l->content==NULL){ 1451 1456 l->content=(services*)malloc(SERVICES_SIZE); 1452 l->content->content=dupService( content);1457 l->content->content=dupService(psContent); 1453 1458 l->content->next=NULL; 1454 1459 } 1455 1460 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; 1462 1467 } 1463 1468 l->next=NULL; 1464 1469 if(isInitial>0) 1465 * reg=l;1470 *prReg=l; 1466 1471 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; 1472 1477 } 1473 1478 return true; … … 1480 1485 * Free memory allocated for the registry 1481 1486 * 1482 * @param rthe registry1483 */ 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 */ 1489 void 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; 1496 1501 } 1497 1502 } 1498 lr=lr->next;1503 prLocalRef=prLocalRef->next; 1499 1504 } 1500 1505 } … … 1503 1508 * Access a service in the registry 1504 1509 * 1505 * @param rthe registry1506 * @param level the regitry to search ("concept", "generic" or "implementation")1507 * @param sname the service name1510 * @param prReg the registry 1511 * @param pcLevel the regitry to search ("concept", "generic" or "implementation") 1512 * @param pcName the service name 1508 1513 * @return the service pointer if a corresponding service was found or NULL 1509 1514 */ 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;1515 service* 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; 1519 1524 } 1520 1525 break; 1521 1526 } 1522 lr=lr->next;1527 prLocalRef=prLocalRef->next; 1523 1528 } 1524 1529 return NULL; … … 1528 1533 * Apply inheritance to an out map from a reference in map 1529 1534 * 1530 * @param out the map to update1531 * @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 */ 1538 void inheritMap(map** ppmOut,map* pmIn){ 1539 map* pmContent=pmIn; 1540 if((*ppmOut)==NULL){ 1541 addMapToMap(ppmOut,pmIn); 1537 1542 return; 1538 1543 } 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; 1544 1549 } 1545 1550 } … … 1548 1553 * Apply inheritance to an out iotype from a reference in iotype 1549 1554 * 1550 * @param out the iotype to update1551 * @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 */ 1558 void 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); 1564 1569 }else{ 1565 inheritIOType(& oio->next,io->next);1570 inheritIOType(&ppiotOutCursor->next,piotInCurosor->next); 1566 1571 } 1567 1572 } … … 1571 1576 * Apply inheritance to an out elements from a reference in elements 1572 1577 * 1573 * @param out the elements to update1574 * @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 */ 1581 void 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); 1582 1587 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); 1590 1595 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; 1595 1600 } 1596 1601 } 1597 1602 } 1598 content=content->next;1603 peContent=peContent->next; 1599 1604 } 1600 1605 } … … 1603 1608 * Apply inheritance to a service based on a registry 1604 1609 * 1605 * @param rthe registry storing profiles hierarchy1606 * @param sthe service to update depending on its inheritance1607 */ 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 */ 1613 void inheritance(registry *prReg,service** psServ){ 1614 service* psCursor=*psServ; 1610 1615 map *profile,*level; 1611 if( r==NULL)1616 if(prReg==NULL) 1612 1617 return; 1613 if( ls==NULL || ls->content==NULL)1618 if(psCursor==NULL || psCursor->content==NULL) 1614 1619 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"); 1617 1622 if(profile!=NULL&&level!=NULL){ 1618 1623 service* s1; 1619 1624 if(strncasecmp(level->value,"profile",7)==0) 1620 s1=getServiceFromRegistry( r,(char*)"generic",profile->value);1625 s1=getServiceFromRegistry(prReg,(char*)"generic",profile->value); 1621 1626 else 1622 s1=getServiceFromRegistry( r,level->value,profile->value);1627 s1=getServiceFromRegistry(prReg,level->value,profile->value); 1623 1628 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); 1628 1633 }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); 1633 1638 }else 1634 inheritElements(& ls->outputs,s1->outputs);1639 inheritElements(&psCursor->outputs,s1->outputs); 1635 1640 } 1636 1641 } … … 1639 1644 * Convert a maps to a char*** (only used for Fortran support) 1640 1645 * 1641 * @param mthe maps to convert1642 * @param cthe resulting array1643 */ 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 */ 1649 void mapsToCharXXX(maps* pmsMap,char*** pppcValues){ 1650 maps* pmsCursor=pmsMap; 1646 1651 int i=0; 1647 1652 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; 1652 1657 if(i>=10) 1653 1658 break; 1654 strcpy( tmp[i][j],"name");1659 strcpy(aaacTmp[i][j],"name"); 1655 1660 j++; 1656 strcpy( tmp[i][j],tm->name);1661 strcpy(aaacTmp[i][j],pmsCursor->name); 1657 1662 j++; 1658 while( tc!=NULL){1663 while(pmContent!=NULL){ 1659 1664 if(j>=30) 1660 1665 break; 1661 strcpy( tmp[i][j],tc->name);1666 strcpy(aaacTmp[i][j],pmContent->name); 1662 1667 j++; 1663 strcpy( tmp[i][j],tc->value);1668 strcpy(aaacTmp[i][j],pmContent->value); 1664 1669 j++; 1665 tc=tc->next;1666 } 1667 tm=tm->next;1670 pmContent=pmContent->next; 1671 } 1672 pmsCursor=pmsCursor->next; 1668 1673 j=0; 1669 1674 i++; 1670 1675 } 1671 memcpy( c,tmp,10*10*1024);1676 memcpy(pppcValues,aaacTmp,10*10*1024); 1672 1677 } 1673 1678 … … 1675 1680 * Convert a char*** to a maps (only used for Fortran support) 1676 1681 * 1677 * @param cthe array to convert1678 * @param mthe resulting maps1679 */ 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 */ 1685 void charxxxToMaps(char*** pppcValues,maps** ppmsMaps){ 1686 maps* pmsCursor=*ppmsMaps; 1682 1687 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); 1685 1690 for(i=0;i<10;i++){ 1686 if(strlen( tmp[i][1])==0)1691 if(strlen(aaaTmp[i][1])==0) 1687 1692 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; 1691 1696 for(j=2;j<29;j+=2){ 1692 if(strlen( tmp[i][j+1])==0)1697 if(strlen(aaaTmp[i][j+1])==0) 1693 1698 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]); 1696 1701 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; 1702 1707 } 1703 1708 … … 1705 1710 * Verify that a map has a value 1706 1711 * 1707 * @param map pointer to map that should be checked1712 * @param pmMap pointer to map that should be checked 1708 1713 * @return true if map has a value or false if value is missing/empty/NULL 1709 1714 */ 1710 bool nonempty(map* map) {1711 return (map != NULL && map->value != NULL && strlen(map->value) > 0 && strcmp(map->value, "NULL") != 0);1715 bool nonempty(map* pmMap) { 1716 return (pmMap != NULL && pmMap->value != NULL && strlen(pmMap->value) > 0 && strcmp(pmMap->value, "NULL") != 0); 1712 1717 } 1713 1718 … … 1716 1721 * data structure, and obtain that value 1717 1722 * 1718 * @param source pointer to maps structure1719 * @param node name of maps node to search1720 * @param key name of map node to find1721 * @param kvp address to the map* if it exists, otherwise NULL1723 * @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 1722 1727 * @return true if map has a value or false if value is missing/NULL 1723 1728 * 1724 1729 * @note The map assigned to kvp is owned by the source maps 1725 1730 */ 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);1731 bool 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); 1730 1735 } 1731 1736 … … 1733 1738 * Set error message in configuration maps 1734 1739 * 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 */ 1745 void 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 */ 1767 void 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 { 1798 1809 #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 } 1803 1814 #endif 1804 1805 1806 if (text != NULL) free(text);1815 } 1816 1817 if (pcText != NULL) free(pcText); 1807 1818 } 1808 1819 … … 1815 1826 #ifdef WIN32 1816 1827 #ifndef USE_MS 1817 char *strcasestr (char const * a, char const *b)1828 char *strcasestr (char const *pccA, char const *pccB) 1818 1829 { 1819 char * x = zStrdup (a);1820 char * y = zStrdup (b);1830 char *pcX = zStrdup (pccA); 1831 char *pcY = zStrdup (pccB); 1821 1832 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); 1828 1839 return ret; 1829 1840 }; … … 1843 1854 * The memory should be deallocated by calling freeMap. 1844 1855 */ 1845 char* allocateMapValue(map* node, size_t num_bytes)1856 char* allocateMapValue(map* pmNode, size_t sNumBytes) 1846 1857 { 1847 if (node == NULL) {1848 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); 1855 1866 1856 return node->value;1857 } 1867 return pmNode->value; 1868 }
Note: See TracChangeset
for help on using the changeset viewer.