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