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