[1] | 1 | /** |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[360] | 4 | * Copyright (c) 2009-2012 GeoLabs SARL |
---|
[1] | 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 | |
---|
[216] | 30 | #ifdef WIN32 |
---|
[444] | 31 | #ifndef USE_MS |
---|
[375] | 32 | #define strncasecmp _strnicmp |
---|
| 33 | #define strcasecmp _stricmp |
---|
[444] | 34 | #endif |
---|
[375] | 35 | #ifndef snprintf |
---|
[216] | 36 | #define snprintf sprintf_s |
---|
[453] | 37 | #endif |
---|
| 38 | #define zStrdup _strdup |
---|
| 39 | #define zMkdir _mkdir |
---|
| 40 | #define zOpen _open |
---|
| 41 | #define zWrite _write |
---|
[379] | 42 | #else |
---|
[453] | 43 | #define zStrdup strdup |
---|
| 44 | #define zMkdir mkdir |
---|
[454] | 45 | #define zOpen open |
---|
| 46 | #define zWrite write |
---|
[216] | 47 | #endif |
---|
| 48 | |
---|
[1] | 49 | #ifdef __cplusplus |
---|
| 50 | extern "C" { |
---|
| 51 | #endif |
---|
| 52 | |
---|
[444] | 53 | #ifdef WIN32 |
---|
| 54 | #ifdef USE_MS |
---|
| 55 | #include <mapserver.h> |
---|
| 56 | #endif |
---|
| 57 | #endif |
---|
[1] | 58 | #include <stdlib.h> |
---|
| 59 | #include <ctype.h> |
---|
| 60 | #include <stdio.h> |
---|
| 61 | #include <string.h> |
---|
[364] | 62 | #ifndef WIN32 |
---|
[1] | 63 | #define bool int |
---|
| 64 | #define true 1 |
---|
| 65 | #define false -1 |
---|
[379] | 66 | #else |
---|
| 67 | //#include <stdbool.h> |
---|
[364] | 68 | #endif |
---|
[9] | 69 | |
---|
[1] | 70 | #define SERVICE_ACCEPTED 0 |
---|
| 71 | #define SERVICE_STARTED 1 |
---|
| 72 | #define SERVICE_PAUSED 2 |
---|
| 73 | #define SERVICE_SUCCEEDED 3 |
---|
| 74 | #define SERVICE_FAILED 4 |
---|
[9] | 75 | |
---|
[1] | 76 | #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*)) |
---|
[9] | 77 | #define MAP_SIZE (2*sizeof(char*))+sizeof(NULL) |
---|
| 78 | #define IOTYPE_SIZE MAP_SIZE+sizeof(NULL) |
---|
| 79 | #define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE |
---|
| 80 | #define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*) |
---|
[1] | 81 | |
---|
[26] | 82 | #define SHMSZ 27 |
---|
[1] | 83 | |
---|
| 84 | |
---|
[375] | 85 | #ifdef DEBUG_STACK |
---|
| 86 | void debugStack(const char* file,const int line){ |
---|
| 87 | int stack; |
---|
| 88 | fprintf(stderr,"stack %p (%s: %d) \n",&stack,file,line); |
---|
| 89 | } |
---|
| 90 | #endif |
---|
| 91 | |
---|
[9] | 92 | /** |
---|
| 93 | * \struct map |
---|
| 94 | * \brief KVP linked list |
---|
| 95 | * |
---|
| 96 | * Deal with WPS KVP (name,value). |
---|
[114] | 97 | * A map is defined as: |
---|
| 98 | * - name : a key, |
---|
| 99 | * - value: a value, |
---|
| 100 | * - next : a pointer to the next map if any. |
---|
[9] | 101 | */ |
---|
[1] | 102 | typedef struct map{ |
---|
[114] | 103 | char* name; |
---|
| 104 | char* value; |
---|
| 105 | struct map* next; |
---|
[1] | 106 | } map; |
---|
| 107 | |
---|
| 108 | #ifdef WIN32 |
---|
| 109 | #define NULLMAP ((map*) 0) |
---|
| 110 | #else |
---|
| 111 | #define NULLMAP NULL |
---|
| 112 | #endif |
---|
| 113 | |
---|
[114] | 114 | /** |
---|
| 115 | * \struct maps |
---|
| 116 | * \brief linked list of map pointer |
---|
| 117 | * |
---|
| 118 | * Small object to store WPS KVP set. |
---|
| 119 | * Maps is defined as: |
---|
| 120 | * - a name, |
---|
| 121 | * - a content map, |
---|
| 122 | * - a pointer to the next maps if any. |
---|
| 123 | */ |
---|
| 124 | typedef struct maps{ |
---|
| 125 | char* name; |
---|
| 126 | struct map* content; |
---|
| 127 | struct maps* next; |
---|
| 128 | } maps; |
---|
| 129 | |
---|
| 130 | /** |
---|
| 131 | * \brief Dump a map on stderr |
---|
| 132 | */ |
---|
[9] | 133 | static void _dumpMap(map* t){ |
---|
[1] | 134 | if(t!=NULL){ |
---|
| 135 | fprintf(stderr,"[%s] => [%s] \n",t->name,t->value); |
---|
| 136 | fflush(stderr); |
---|
[364] | 137 | }else{ |
---|
[1] | 138 | fprintf(stderr,"NULL\n"); |
---|
| 139 | fflush(stderr); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | |
---|
[9] | 143 | static void dumpMap(map* t){ |
---|
[1] | 144 | map* tmp=t; |
---|
| 145 | while(tmp!=NULL){ |
---|
| 146 | _dumpMap(tmp); |
---|
| 147 | tmp=tmp->next; |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
[92] | 151 | static void dumpMapToFile(map* t,FILE* file){ |
---|
| 152 | map* tmp=t; |
---|
| 153 | while(tmp!=NULL){ |
---|
[364] | 154 | #ifdef DEBUG |
---|
[254] | 155 | fprintf(stderr,"%s = %s\n",tmp->name,tmp->value); |
---|
[364] | 156 | #endif |
---|
[253] | 157 | fprintf(file,"%s = %s\n",tmp->name,tmp->value); |
---|
[92] | 158 | tmp=tmp->next; |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
[1] | 162 | static void dumpMaps(maps* m){ |
---|
| 163 | maps* tmp=m; |
---|
| 164 | while(tmp!=NULL){ |
---|
| 165 | fprintf(stderr,"MAP => [%s] \n",tmp->name); |
---|
| 166 | dumpMap(tmp->content); |
---|
| 167 | tmp=tmp->next; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | |
---|
[254] | 171 | static void dumpMapsToFile(maps* m,char* file_path){ |
---|
| 172 | FILE* file=fopen(file_path,"w"); |
---|
[92] | 173 | maps* tmp=m; |
---|
| 174 | if(tmp!=NULL){ |
---|
| 175 | fprintf(file,"[%s]\n",tmp->name); |
---|
| 176 | dumpMapToFile(tmp->content,file); |
---|
[254] | 177 | fflush(file); |
---|
[92] | 178 | } |
---|
[254] | 179 | fclose(file); |
---|
[92] | 180 | } |
---|
| 181 | |
---|
[9] | 182 | static map* createMap(const char* name,const char* value){ |
---|
[1] | 183 | map* tmp=(map *)malloc(MAP_SIZE); |
---|
[453] | 184 | tmp->name=zStrdup(name); |
---|
| 185 | tmp->value=zStrdup(value); |
---|
[1] | 186 | tmp->next=NULL; |
---|
| 187 | return tmp; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | static int count(map* m){ |
---|
| 191 | map* tmp=m; |
---|
| 192 | int c=0; |
---|
| 193 | while(tmp!=NULL){ |
---|
| 194 | c++; |
---|
| 195 | tmp=tmp->next; |
---|
| 196 | } |
---|
| 197 | return c; |
---|
| 198 | } |
---|
| 199 | |
---|
[9] | 200 | static bool hasKey(map* m,const char *key){ |
---|
[1] | 201 | map* tmp=m; |
---|
| 202 | while(tmp!=NULL){ |
---|
[57] | 203 | if(strcasecmp(tmp->name,key)==0) |
---|
[1] | 204 | return true; |
---|
| 205 | tmp=tmp->next; |
---|
| 206 | } |
---|
| 207 | #ifdef DEBUG_MAP |
---|
| 208 | fprintf(stderr,"NOT FOUND \n"); |
---|
| 209 | #endif |
---|
| 210 | return false; |
---|
| 211 | } |
---|
| 212 | |
---|
[9] | 213 | static maps* getMaps(maps* m,const char *key){ |
---|
[1] | 214 | maps* tmp=m; |
---|
| 215 | while(tmp!=NULL){ |
---|
[57] | 216 | if(strcasecmp(tmp->name,key)==0){ |
---|
[1] | 217 | return tmp; |
---|
[9] | 218 | } |
---|
[1] | 219 | tmp=tmp->next; |
---|
| 220 | } |
---|
| 221 | return NULL; |
---|
| 222 | } |
---|
| 223 | |
---|
[9] | 224 | static map* getMap(map* m,const char *key){ |
---|
[1] | 225 | map* tmp=m; |
---|
| 226 | while(tmp!=NULL){ |
---|
[57] | 227 | if(strcasecmp(tmp->name,key)==0){ |
---|
[1] | 228 | return tmp; |
---|
[9] | 229 | } |
---|
[1] | 230 | tmp=tmp->next; |
---|
| 231 | } |
---|
| 232 | return NULL; |
---|
| 233 | } |
---|
| 234 | |
---|
[281] | 235 | |
---|
[216] | 236 | static map* getLastMap(map* m){ |
---|
| 237 | map* tmp=m; |
---|
| 238 | while(tmp!=NULL){ |
---|
| 239 | if(tmp->next==NULL){ |
---|
| 240 | return tmp; |
---|
| 241 | } |
---|
| 242 | tmp=tmp->next; |
---|
| 243 | } |
---|
| 244 | return NULL; |
---|
| 245 | } |
---|
| 246 | |
---|
[114] | 247 | static map* getMapFromMaps(maps* m,const char* key,const char* subkey){ |
---|
[1] | 248 | maps* _tmpm=getMaps(m,key); |
---|
| 249 | if(_tmpm!=NULL){ |
---|
[9] | 250 | map* _ztmpm=getMap(_tmpm->content,subkey); |
---|
| 251 | return _ztmpm; |
---|
[1] | 252 | } |
---|
| 253 | else return NULL; |
---|
| 254 | } |
---|
| 255 | |
---|
[216] | 256 | |
---|
[9] | 257 | static void freeMap(map** mo){ |
---|
[1] | 258 | map* _cursor=*mo; |
---|
| 259 | if(_cursor!=NULL){ |
---|
[9] | 260 | #ifdef DEBUG |
---|
| 261 | fprintf(stderr,"freeMap\n"); |
---|
| 262 | #endif |
---|
[1] | 263 | free(_cursor->name); |
---|
| 264 | free(_cursor->value); |
---|
| 265 | if(_cursor->next!=NULL){ |
---|
| 266 | freeMap(&_cursor->next); |
---|
| 267 | free(_cursor->next); |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | |
---|
[9] | 272 | static void freeMaps(maps** mo){ |
---|
| 273 | maps* _cursor=*mo; |
---|
| 274 | fflush(stderr); |
---|
| 275 | if(_cursor && _cursor!=NULL){ |
---|
| 276 | #ifdef DEBUG |
---|
| 277 | fprintf(stderr,"freeMaps\n"); |
---|
| 278 | #endif |
---|
| 279 | free(_cursor->name); |
---|
| 280 | if(_cursor->content!=NULL){ |
---|
| 281 | freeMap(&_cursor->content); |
---|
| 282 | free(_cursor->content); |
---|
| 283 | } |
---|
| 284 | if(_cursor->next!=NULL){ |
---|
| 285 | freeMaps(&_cursor->next); |
---|
| 286 | free(_cursor->next); |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | } |
---|
[1] | 290 | |
---|
[114] | 291 | /** |
---|
| 292 | * \brief Not named linked list |
---|
| 293 | * |
---|
| 294 | * Used to store informations about formats, such as mimeType, encoding ... |
---|
| 295 | * |
---|
| 296 | * An iotype is defined as : |
---|
| 297 | * - a content map, |
---|
| 298 | * - a pointer to the next iotype if any. |
---|
| 299 | */ |
---|
[1] | 300 | typedef struct iotype{ |
---|
| 301 | struct map* content; |
---|
| 302 | struct iotype* next; |
---|
| 303 | } iotype; |
---|
| 304 | |
---|
[114] | 305 | /** |
---|
| 306 | * \brief Metadata information about input or output. |
---|
| 307 | * |
---|
| 308 | * The elements are used to store metadata informations defined in the ZCFG. |
---|
| 309 | * |
---|
| 310 | * An elements is defined as : |
---|
| 311 | * - a name, |
---|
| 312 | * - a content map, |
---|
| 313 | * - a metadata map, |
---|
| 314 | * - a format (possible values are LiteralData, ComplexData or |
---|
| 315 | * BoundingBoxData), |
---|
| 316 | * - a default iotype, |
---|
| 317 | * - a pointer to the next elements id any. |
---|
| 318 | */ |
---|
[1] | 319 | typedef struct elements{ |
---|
| 320 | char* name; |
---|
| 321 | struct map* content; |
---|
| 322 | struct map* metadata; |
---|
| 323 | char* format; |
---|
| 324 | struct iotype* defaults; |
---|
| 325 | struct iotype* supported; |
---|
| 326 | struct elements* next; |
---|
| 327 | } elements; |
---|
| 328 | |
---|
| 329 | typedef struct service{ |
---|
| 330 | char* name; |
---|
| 331 | struct map* content; |
---|
| 332 | struct map* metadata; |
---|
| 333 | struct elements* inputs; |
---|
| 334 | struct elements* outputs; |
---|
| 335 | } service; |
---|
| 336 | |
---|
| 337 | typedef struct services{ |
---|
| 338 | struct service* content; |
---|
| 339 | struct services* next; |
---|
| 340 | } services; |
---|
| 341 | |
---|
[114] | 342 | static bool hasElement(elements* e,const char* key){ |
---|
[1] | 343 | elements* tmp=e; |
---|
| 344 | while(tmp!=NULL){ |
---|
[57] | 345 | if(strcasecmp(key,tmp->name)==0) |
---|
[1] | 346 | return true; |
---|
| 347 | tmp=tmp->next; |
---|
| 348 | } |
---|
| 349 | return false; |
---|
| 350 | } |
---|
| 351 | |
---|
| 352 | static elements* getElements(elements* m,char *key){ |
---|
| 353 | elements* tmp=m; |
---|
| 354 | while(tmp!=NULL){ |
---|
[57] | 355 | if(strcasecmp(tmp->name,key)==0) |
---|
[1] | 356 | return tmp; |
---|
| 357 | tmp=tmp->next; |
---|
| 358 | } |
---|
| 359 | return NULL; |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | |
---|
[9] | 363 | static void freeIOType(iotype** i){ |
---|
[1] | 364 | iotype* _cursor=*i; |
---|
| 365 | if(_cursor!=NULL){ |
---|
[9] | 366 | if(_cursor->next!=NULL){ |
---|
| 367 | freeIOType(&_cursor->next); |
---|
| 368 | free(_cursor->next); |
---|
| 369 | } |
---|
[57] | 370 | freeMap(&_cursor->content); |
---|
| 371 | free(_cursor->content); |
---|
[1] | 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | static void freeElements(elements** e){ |
---|
| 376 | elements* tmp=*e; |
---|
| 377 | if(tmp!=NULL){ |
---|
[57] | 378 | if(tmp->name!=NULL) |
---|
| 379 | free(tmp->name); |
---|
[1] | 380 | freeMap(&tmp->content); |
---|
[57] | 381 | if(tmp->content!=NULL) |
---|
| 382 | free(tmp->content); |
---|
[1] | 383 | freeMap(&tmp->metadata); |
---|
[57] | 384 | if(tmp->metadata!=NULL) |
---|
| 385 | free(tmp->metadata); |
---|
| 386 | if(tmp->format!=NULL) |
---|
| 387 | free(tmp->format); |
---|
[1] | 388 | freeIOType(&tmp->defaults); |
---|
| 389 | if(tmp->defaults!=NULL) |
---|
| 390 | free(tmp->defaults); |
---|
| 391 | freeIOType(&tmp->supported); |
---|
[57] | 392 | if(tmp->supported!=NULL){ |
---|
[1] | 393 | free(tmp->supported); |
---|
[57] | 394 | } |
---|
[9] | 395 | freeElements(&tmp->next); |
---|
[60] | 396 | if(tmp->next!=NULL) |
---|
| 397 | free(tmp->next); |
---|
[1] | 398 | } |
---|
| 399 | } |
---|
| 400 | |
---|
[9] | 401 | static void freeService(service** s){ |
---|
[1] | 402 | service* tmp=*s; |
---|
| 403 | if(tmp!=NULL){ |
---|
[9] | 404 | if(tmp->name!=NULL) |
---|
| 405 | free(tmp->name); |
---|
[1] | 406 | freeMap(&tmp->content); |
---|
| 407 | if(tmp->content!=NULL) |
---|
| 408 | free(tmp->content); |
---|
| 409 | freeMap(&tmp->metadata); |
---|
| 410 | if(tmp->metadata!=NULL) |
---|
| 411 | free(tmp->metadata); |
---|
| 412 | freeElements(&tmp->inputs); |
---|
| 413 | if(tmp->inputs!=NULL) |
---|
| 414 | free(tmp->inputs); |
---|
| 415 | freeElements(&tmp->outputs); |
---|
| 416 | if(tmp->outputs!=NULL) |
---|
| 417 | free(tmp->outputs); |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | |
---|
[9] | 421 | static void addToMap(map* m,const char* n,const char* v){ |
---|
| 422 | if(hasKey(m,n)==false){ |
---|
| 423 | map* _cursor=m; |
---|
| 424 | while(_cursor->next!=NULL) |
---|
| 425 | _cursor=_cursor->next; |
---|
| 426 | _cursor->next=createMap(n,v); |
---|
| 427 | } |
---|
| 428 | else{ |
---|
| 429 | map *tmp=getMap(m,n); |
---|
| 430 | if(tmp->value!=NULL) |
---|
| 431 | free(tmp->value); |
---|
[453] | 432 | tmp->value=zStrdup(v); |
---|
[9] | 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | static void addMapToMap(map** mo,map* mi){ |
---|
[1] | 437 | map* tmp=mi; |
---|
| 438 | map* _cursor=*mo; |
---|
[9] | 439 | if(tmp==NULL){ |
---|
| 440 | if(_cursor!=NULL){ |
---|
| 441 | while(_cursor!=NULL) |
---|
[1] | 442 | _cursor=_cursor->next; |
---|
[9] | 443 | _cursor=NULL; |
---|
| 444 | }else |
---|
| 445 | *mo=NULL; |
---|
[1] | 446 | } |
---|
| 447 | while(tmp!=NULL){ |
---|
| 448 | if(_cursor==NULL){ |
---|
[9] | 449 | if(*mo==NULL) |
---|
| 450 | *mo=createMap(tmp->name,tmp->value); |
---|
| 451 | else |
---|
| 452 | addToMap(*mo,tmp->name,tmp->value); |
---|
[1] | 453 | } |
---|
| 454 | else{ |
---|
[9] | 455 | #ifdef DEBUG |
---|
| 456 | fprintf(stderr,"_CURSOR\n"); |
---|
| 457 | dumpMap(_cursor); |
---|
| 458 | #endif |
---|
| 459 | while(_cursor!=NULL) |
---|
[1] | 460 | _cursor=_cursor->next; |
---|
[9] | 461 | _cursor=createMap(tmp->name,tmp->value); |
---|
| 462 | _cursor->next=NULL; |
---|
[1] | 463 | } |
---|
| 464 | tmp=tmp->next; |
---|
[9] | 465 | #ifdef DEBUG |
---|
| 466 | fprintf(stderr,"MO\n"); |
---|
| 467 | dumpMap(*mo); |
---|
| 468 | #endif |
---|
[1] | 469 | } |
---|
| 470 | } |
---|
| 471 | |
---|
[9] | 472 | static void addMapToIoType(iotype** io,map* mi){ |
---|
[1] | 473 | iotype* tmp=*io; |
---|
[57] | 474 | while(tmp->next!=NULL){ |
---|
[1] | 475 | tmp=tmp->next; |
---|
| 476 | } |
---|
[57] | 477 | tmp->next=(iotype*)malloc(IOTYPE_SIZE); |
---|
| 478 | tmp->next->content=NULL; |
---|
| 479 | addMapToMap(&tmp->next->content,mi); |
---|
| 480 | tmp->next->next=NULL; |
---|
[1] | 481 | } |
---|
| 482 | |
---|
[282] | 483 | static map* getMapOrFill(map* m,const char *key,char* value){ |
---|
[281] | 484 | map* tmp=m; |
---|
| 485 | map* tmpMap=getMap(tmp,key); |
---|
| 486 | if(tmpMap==NULL){ |
---|
[284] | 487 | if(tmp!=NULL) |
---|
| 488 | addToMap(tmp,key,value); |
---|
| 489 | else |
---|
| 490 | tmp=createMap(key,value); |
---|
[281] | 491 | tmpMap=getMap(tmp,key); |
---|
| 492 | } |
---|
| 493 | return tmpMap; |
---|
| 494 | } |
---|
| 495 | |
---|
[57] | 496 | static bool contains(map* m,map* i){ |
---|
| 497 | while(i!=NULL){ |
---|
| 498 | if(strcasecmp(i->name,"value")!=0 && |
---|
[299] | 499 | strcasecmp(i->name,"xlink:href")!=0 && |
---|
| 500 | strcasecmp(i->name,"useMapServer")!=0 && |
---|
| 501 | strcasecmp(i->name,"asReference")!=0){ |
---|
[57] | 502 | map *tmp; |
---|
| 503 | if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && |
---|
| 504 | strcasecmp(i->value,tmp->value)!=0) |
---|
| 505 | return false; |
---|
| 506 | } |
---|
| 507 | i=i->next; |
---|
| 508 | } |
---|
| 509 | return true; |
---|
| 510 | } |
---|
[9] | 511 | |
---|
[57] | 512 | static iotype* getIoTypeFromElement(elements* e,char *name, map* values){ |
---|
| 513 | elements* cursor=e; |
---|
| 514 | while(cursor!=NULL){ |
---|
| 515 | if(strcasecmp(cursor->name,name)==0){ |
---|
| 516 | if(contains(cursor->defaults->content,values)==true) |
---|
| 517 | return cursor->defaults; |
---|
| 518 | else{ |
---|
| 519 | iotype* tmp=cursor->supported; |
---|
| 520 | while(tmp!=NULL){ |
---|
| 521 | if(contains(tmp->content,values)==true) |
---|
| 522 | return tmp; |
---|
| 523 | tmp=tmp->next; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | cursor=cursor->next; |
---|
| 528 | } |
---|
| 529 | return NULL; |
---|
| 530 | } |
---|
| 531 | |
---|
[9] | 532 | static maps* dupMaps(maps** mo){ |
---|
| 533 | maps* _cursor=*mo; |
---|
| 534 | maps* res=NULL; |
---|
| 535 | if(_cursor!=NULL){ |
---|
| 536 | res=(maps*)malloc(MAPS_SIZE); |
---|
[453] | 537 | res->name=zStrdup(_cursor->name); |
---|
[9] | 538 | res->content=NULL; |
---|
| 539 | res->next=NULL; |
---|
| 540 | map* mc=_cursor->content; |
---|
[59] | 541 | map* tmp=getMap(mc,"size"); |
---|
| 542 | char* tmpSized=NULL; |
---|
| 543 | if(tmp!=NULL){ |
---|
| 544 | map* tmpV=getMap(mc,"value"); |
---|
| 545 | tmpSized=(char*)malloc((atoi(tmp->value)+1)*sizeof(char)); |
---|
| 546 | memmove(tmpSized,tmpV->value,atoi(tmp->value)*sizeof(char)); |
---|
| 547 | } |
---|
[9] | 548 | if(mc!=NULL){ |
---|
| 549 | addMapToMap(&res->content,mc); |
---|
| 550 | } |
---|
[59] | 551 | if(tmp!=NULL){ |
---|
| 552 | map* tmpV=getMap(res->content,"value"); |
---|
| 553 | free(tmpV->value); |
---|
[229] | 554 | tmpV->value=(char*)malloc((atoi(tmp->value)+1)*sizeof(char)); |
---|
[59] | 555 | memmove(tmpV->value,tmpSized,atoi(tmp->value)*sizeof(char)); |
---|
[229] | 556 | tmpV->value[atoi(tmp->value)]=0; |
---|
[59] | 557 | free(tmpSized); |
---|
| 558 | } |
---|
[9] | 559 | res->next=dupMaps(&_cursor->next); |
---|
[1] | 560 | } |
---|
[9] | 561 | return res; |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | static void addMapsToMaps(maps** mo,maps* mi){ |
---|
| 565 | maps* tmp=mi; |
---|
| 566 | maps* _cursor=*mo; |
---|
| 567 | while(tmp!=NULL){ |
---|
| 568 | if(_cursor==NULL){ |
---|
| 569 | *mo=dupMaps(&mi); |
---|
| 570 | (*mo)->next=NULL; |
---|
| 571 | } |
---|
| 572 | else{ |
---|
| 573 | while(_cursor->next!=NULL) |
---|
| 574 | _cursor=_cursor->next; |
---|
| 575 | _cursor->next=dupMaps(&tmp); |
---|
| 576 | } |
---|
| 577 | tmp=tmp->next; |
---|
[1] | 578 | } |
---|
| 579 | } |
---|
| 580 | |
---|
[360] | 581 | static map* getMapArray(map* m,char* key,int index){ |
---|
| 582 | char tmp[1024]; |
---|
| 583 | if(index>0) |
---|
| 584 | sprintf(tmp,"%s_%d",key,index); |
---|
| 585 | else |
---|
[379] | 586 | sprintf(tmp,"%s",key); |
---|
[360] | 587 | #ifdef DEBUG |
---|
| 588 | fprintf(stderr,"** KEY %s\n",tmp); |
---|
| 589 | #endif |
---|
| 590 | map* tmpMap=getMap(m,tmp); |
---|
| 591 | #ifdef DEBUG |
---|
| 592 | if(tmpMap!=NULL) |
---|
| 593 | dumpMap(tmpMap); |
---|
| 594 | #endif |
---|
| 595 | return tmpMap; |
---|
| 596 | } |
---|
[1] | 597 | |
---|
[360] | 598 | |
---|
| 599 | static void setMapArray(map* m,char* key,int index,char* value){ |
---|
| 600 | char tmp[1024]; |
---|
| 601 | if(index>0) |
---|
| 602 | sprintf(tmp,"%s_%d",key,index); |
---|
| 603 | else |
---|
[379] | 604 | sprintf(tmp,"%s",key); |
---|
[360] | 605 | map* tmpSize=getMapArray(m,"size",index); |
---|
| 606 | if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){ |
---|
[364] | 607 | #ifdef DEBUG |
---|
[360] | 608 | fprintf(stderr,"%s\n",tmpSize->value); |
---|
[364] | 609 | #endif |
---|
[360] | 610 | map* ptr=getMapOrFill(m,tmp,""); |
---|
| 611 | free(ptr->value); |
---|
| 612 | ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char)); |
---|
| 613 | memcpy(ptr->value,value,atoi(tmpSize->value)); |
---|
| 614 | } |
---|
| 615 | else |
---|
| 616 | addToMap(m,tmp,value); |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | static map* getMapType(map* mt){ |
---|
| 620 | map* tmap=getMap(mt,"mimeType"); |
---|
| 621 | if(tmap==NULL){ |
---|
| 622 | tmap=getMap(mt,"dataType"); |
---|
| 623 | if(tmap==NULL){ |
---|
| 624 | tmap=getMap(mt,"CRS"); |
---|
| 625 | } |
---|
| 626 | } |
---|
[364] | 627 | #ifdef DEBUG |
---|
| 628 | dumpMap(tmap); |
---|
| 629 | #endif |
---|
[360] | 630 | return tmap; |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){ |
---|
[362] | 634 | maps* tmp=mi; |
---|
| 635 | maps* _cursor=getMaps(*mo,tmp->name); |
---|
[360] | 636 | |
---|
[362] | 637 | if(_cursor==NULL) |
---|
[360] | 638 | return -1; |
---|
| 639 | |
---|
[362] | 640 | map* tmpLength=getMap(_cursor->content,"length"); |
---|
[360] | 641 | char tmpLen[10]; |
---|
| 642 | int len=1; |
---|
| 643 | if(tmpLength!=NULL){ |
---|
| 644 | len=atoi(tmpLength->value); |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | char *tmpV[8]={ |
---|
| 648 | "size", |
---|
| 649 | "value", |
---|
| 650 | "uom", |
---|
| 651 | "Reference", |
---|
| 652 | "xlink:href", |
---|
| 653 | typ, |
---|
| 654 | "schema", |
---|
| 655 | "encoding" |
---|
| 656 | }; |
---|
| 657 | sprintf(tmpLen,"%d",len+1); |
---|
| 658 | addToMap(_cursor->content,"length",tmpLen); |
---|
| 659 | int i=0; |
---|
| 660 | map* tmpSizeI=getMap(tmp->content,tmpV[i]); |
---|
[446] | 661 | for(i=0;i<8;i++){ |
---|
[360] | 662 | map* tmpVI=getMap(tmp->content,tmpV[i]); |
---|
| 663 | if(tmpVI!=NULL){ |
---|
[364] | 664 | #ifdef DEBUG |
---|
[360] | 665 | fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value); |
---|
[364] | 666 | #endif |
---|
[360] | 667 | if(i<5) |
---|
| 668 | setMapArray(_cursor->content,tmpV[i],len,tmpVI->value); |
---|
| 669 | else |
---|
| 670 | if(strncasecmp(tmpV[5],"mimeType",8)==0) |
---|
| 671 | setMapArray(_cursor->content,tmpV[i],len,tmpVI->value); |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | |
---|
| 675 | addToMap(_cursor->content,"isArray","true"); |
---|
| 676 | return 0; |
---|
| 677 | } |
---|
| 678 | |
---|
[114] | 679 | static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){ |
---|
[26] | 680 | maps* _tmpm=getMaps(m,key); |
---|
| 681 | if(_tmpm!=NULL){ |
---|
| 682 | map* _ztmpm=getMap(_tmpm->content,subkey); |
---|
| 683 | if(_ztmpm!=NULL){ |
---|
[216] | 684 | if(_ztmpm->value!=NULL) |
---|
| 685 | free(_ztmpm->value); |
---|
[453] | 686 | _ztmpm->value=zStrdup(value); |
---|
[26] | 687 | }else{ |
---|
| 688 | addToMap(_tmpm->content,subkey,value); |
---|
| 689 | } |
---|
[361] | 690 | }else{ |
---|
| 691 | maps *tmp=(maps*)malloc(MAPS_SIZE); |
---|
[453] | 692 | tmp->name=zStrdup(key); |
---|
[361] | 693 | tmp->content=createMap(subkey,value); |
---|
| 694 | tmp->next=NULL; |
---|
| 695 | addMapsToMaps(&m,tmp); |
---|
| 696 | freeMaps(&tmp); |
---|
| 697 | free(tmp); |
---|
[26] | 698 | } |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | |
---|
[9] | 702 | static void dumpElements(elements* e){ |
---|
[1] | 703 | elements* tmp=e; |
---|
| 704 | while(tmp!=NULL){ |
---|
| 705 | fprintf(stderr,"ELEMENT [%s]\n",tmp->name); |
---|
| 706 | fprintf(stderr," > CONTENT [%s]\n",tmp->name); |
---|
| 707 | dumpMap(tmp->content); |
---|
| 708 | fprintf(stderr," > METADATA [%s]\n",tmp->name); |
---|
| 709 | dumpMap(tmp->metadata); |
---|
| 710 | fprintf(stderr," > FORMAT [%s]\n",tmp->format); |
---|
| 711 | iotype* tmpio=tmp->defaults; |
---|
| 712 | int ioc=0; |
---|
| 713 | while(tmpio!=NULL){ |
---|
| 714 | fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc); |
---|
| 715 | dumpMap(tmpio->content); |
---|
| 716 | tmpio=tmpio->next; |
---|
| 717 | ioc++; |
---|
| 718 | } |
---|
| 719 | tmpio=tmp->supported; |
---|
| 720 | ioc=0; |
---|
| 721 | while(tmpio!=NULL){ |
---|
| 722 | fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc); |
---|
| 723 | dumpMap(tmpio->content); |
---|
| 724 | tmpio=tmpio->next; |
---|
| 725 | ioc++; |
---|
| 726 | } |
---|
| 727 | fprintf(stderr,"------------------\n"); |
---|
| 728 | tmp=tmp->next; |
---|
| 729 | } |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | static elements* dupElements(elements* e){ |
---|
[9] | 733 | elements* cursor=e; |
---|
| 734 | elements* tmp=NULL; |
---|
| 735 | if(cursor!=NULL){ |
---|
[1] | 736 | #ifdef DEBUG |
---|
[9] | 737 | fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); |
---|
[1] | 738 | dumpElements(e); |
---|
[9] | 739 | fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); |
---|
[1] | 740 | #endif |
---|
[9] | 741 | tmp=(elements*)malloc(ELEMENTS_SIZE); |
---|
[453] | 742 | tmp->name=zStrdup(e->name); |
---|
[1] | 743 | tmp->content=NULL; |
---|
| 744 | addMapToMap(&tmp->content,e->content); |
---|
| 745 | tmp->metadata=NULL; |
---|
| 746 | addMapToMap(&tmp->metadata,e->metadata); |
---|
[453] | 747 | tmp->format=zStrdup(e->format); |
---|
[1] | 748 | if(e->defaults!=NULL){ |
---|
[9] | 749 | tmp->defaults=(iotype*)malloc(IOTYPE_SIZE); |
---|
[1] | 750 | tmp->defaults->content=NULL; |
---|
[9] | 751 | addMapToMap(&tmp->defaults->content,e->defaults->content); |
---|
[1] | 752 | tmp->defaults->next=NULL; |
---|
[9] | 753 | #ifdef DEBUG |
---|
| 754 | fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); |
---|
| 755 | dumpMap(tmp->defaults->content); |
---|
| 756 | #endif |
---|
| 757 | }else |
---|
| 758 | tmp->defaults=NULL; |
---|
[1] | 759 | if(e->supported!=NULL){ |
---|
[9] | 760 | tmp->supported=(iotype*)malloc(IOTYPE_SIZE); |
---|
[1] | 761 | tmp->supported->content=NULL; |
---|
[57] | 762 | addMapToMap(&tmp->supported->content,e->supported->content); |
---|
[1] | 763 | tmp->supported->next=NULL; |
---|
| 764 | iotype *tmp2=e->supported->next; |
---|
| 765 | while(tmp2!=NULL){ |
---|
[57] | 766 | addMapToIoType(&tmp->supported,tmp2->content); |
---|
[9] | 767 | #ifdef DEBUG |
---|
| 768 | fprintf(stderr,">> %s %i\n",__FILE__,__LINE__); |
---|
| 769 | dumpMap(tmp->defaults->content); |
---|
| 770 | #endif |
---|
[1] | 771 | tmp2=tmp2->next; |
---|
| 772 | } |
---|
| 773 | } |
---|
[9] | 774 | else |
---|
| 775 | tmp->supported=NULL; |
---|
| 776 | tmp->next=dupElements(cursor->next); |
---|
[1] | 777 | } |
---|
[9] | 778 | return tmp; |
---|
[1] | 779 | } |
---|
| 780 | |
---|
[9] | 781 | static void addToElements(elements** m,elements* e){ |
---|
[1] | 782 | elements* tmp=e; |
---|
[60] | 783 | if(*m==NULL){ |
---|
[9] | 784 | *m=dupElements(tmp); |
---|
| 785 | }else{ |
---|
[57] | 786 | addToElements(&(*m)->next,tmp); |
---|
[1] | 787 | } |
---|
| 788 | } |
---|
| 789 | |
---|
[9] | 790 | static void dumpService(service* s){ |
---|
[1] | 791 | fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name); |
---|
| 792 | if(s->content!=NULL){ |
---|
| 793 | fprintf(stderr,"CONTENT MAP\n"); |
---|
| 794 | dumpMap(s->content); |
---|
| 795 | fprintf(stderr,"CONTENT METADATA\n"); |
---|
| 796 | dumpMap(s->metadata); |
---|
| 797 | } |
---|
| 798 | if(s->inputs!=NULL){ |
---|
| 799 | fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name); |
---|
| 800 | dumpElements(s->inputs); |
---|
| 801 | } |
---|
| 802 | if(s->outputs!=NULL){ |
---|
| 803 | fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name); |
---|
| 804 | dumpElements(s->outputs); |
---|
| 805 | } |
---|
| 806 | fprintf(stderr,"++++++++++++++++++\n"); |
---|
| 807 | } |
---|
| 808 | |
---|
[9] | 809 | static void mapsToCharXXX(maps* m,char*** c){ |
---|
[1] | 810 | maps* tm=m; |
---|
| 811 | int i=0; |
---|
| 812 | int j=0; |
---|
| 813 | char tmp[10][30][1024]; |
---|
| 814 | memset(tmp,0,1024*10*10); |
---|
| 815 | while(tm!=NULL){ |
---|
| 816 | if(i>=10) |
---|
| 817 | break; |
---|
| 818 | strcpy(tmp[i][j],"name"); |
---|
| 819 | j++; |
---|
| 820 | strcpy(tmp[i][j],tm->name); |
---|
| 821 | j++; |
---|
| 822 | map* tc=tm->content; |
---|
| 823 | while(tc!=NULL){ |
---|
| 824 | if(j>=30) |
---|
| 825 | break; |
---|
| 826 | strcpy(tmp[i][j],tc->name); |
---|
| 827 | j++; |
---|
| 828 | strcpy(tmp[i][j],tc->value); |
---|
| 829 | j++; |
---|
| 830 | tc=tc->next; |
---|
| 831 | } |
---|
| 832 | tm=tm->next; |
---|
| 833 | j=0; |
---|
| 834 | i++; |
---|
| 835 | } |
---|
| 836 | memcpy(c,tmp,10*10*1024); |
---|
| 837 | } |
---|
| 838 | |
---|
[9] | 839 | static void charxxxToMaps(char*** c,maps**m){ |
---|
[1] | 840 | maps* trorf=*m; |
---|
| 841 | int i,j; |
---|
| 842 | char tmp[10][30][1024]; |
---|
| 843 | memcpy(tmp,c,10*30*1024); |
---|
| 844 | for(i=0;i<10;i++){ |
---|
| 845 | if(strlen(tmp[i][1])==0) |
---|
| 846 | break; |
---|
| 847 | trorf->name=tmp[i][1]; |
---|
| 848 | trorf->content=NULL; |
---|
| 849 | trorf->next=NULL; |
---|
| 850 | for(j=2;j<29;j+=2){ |
---|
| 851 | if(strlen(tmp[i][j+1])==0) |
---|
| 852 | break; |
---|
| 853 | if(trorf->content==NULL) |
---|
| 854 | trorf->content=createMap(tmp[i][j],tmp[i][j+1]); |
---|
| 855 | else |
---|
[9] | 856 | addToMap(trorf->content,tmp[i][j],tmp[i][j+1]); |
---|
[1] | 857 | } |
---|
| 858 | trorf=trorf->next; |
---|
| 859 | } |
---|
| 860 | m=&trorf; |
---|
| 861 | } |
---|
| 862 | |
---|
[458] | 863 | #ifdef WIN32 |
---|
| 864 | extern char *url_encode(char *); |
---|
| 865 | |
---|
| 866 | static char* getMapsAsKVP(maps* m,int length,int type){ |
---|
| 867 | char *dataInputsKVP=(char*) malloc(length*sizeof(char)); |
---|
| 868 | char *dataInputsKVPi=NULL; |
---|
| 869 | maps* curs=m; |
---|
| 870 | int i=0; |
---|
| 871 | while(curs!=NULL){ |
---|
| 872 | map *inRequest=getMap(curs->content,"inRequest"); |
---|
| 873 | map *hasLength=getMap(curs->content,"length"); |
---|
| 874 | if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) || |
---|
| 875 | inRequest==NULL){ |
---|
| 876 | if(i==0) |
---|
| 877 | if(type==0){ |
---|
| 878 | sprintf(dataInputsKVP,"%s=",curs->name); |
---|
| 879 | if(hasLength!=NULL){ |
---|
| 880 | dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char)); |
---|
| 881 | sprintf(dataInputsKVPi,"%s=",curs->name); |
---|
| 882 | } |
---|
| 883 | } |
---|
| 884 | else |
---|
| 885 | sprintf(dataInputsKVP,"%s",curs->name); |
---|
| 886 | else{ |
---|
| 887 | char *temp=zStrdup(dataInputsKVP); |
---|
| 888 | if(type==0) |
---|
| 889 | sprintf(dataInputsKVP,"%s;%s=",temp,curs->name); |
---|
| 890 | else |
---|
| 891 | sprintf(dataInputsKVP,"%s;%s",temp,curs->name); |
---|
| 892 | } |
---|
| 893 | map* icurs=curs->content; |
---|
| 894 | if(type==0){ |
---|
| 895 | char *temp=zStrdup(dataInputsKVP); |
---|
| 896 | if(getMap(curs->content,"xlink:href")!=NULL) |
---|
| 897 | sprintf(dataInputsKVP,"%sReference",temp); |
---|
| 898 | else{ |
---|
| 899 | if(hasLength!=NULL){ |
---|
| 900 | for(int j=0;j<atoi(hasLength->value);j++){ |
---|
| 901 | map* tmp0=getMapArray(curs->content,"value",j); |
---|
| 902 | if(j==0) |
---|
| 903 | free(temp); |
---|
| 904 | temp=zStrdup(dataInputsKVP); |
---|
| 905 | if(j==0) |
---|
| 906 | sprintf(dataInputsKVP,"%s%s",temp,tmp0->value); |
---|
| 907 | else |
---|
| 908 | sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value); |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | else |
---|
| 912 | sprintf(dataInputsKVP,"%s%s",temp,icurs->value); |
---|
| 913 | } |
---|
| 914 | free(temp); |
---|
| 915 | } |
---|
| 916 | while(icurs!=NULL){ |
---|
| 917 | if(strncasecmp(icurs->name,"value",5)!=0 && |
---|
| 918 | strncasecmp(icurs->name,"mimeType_",9)!=0 && |
---|
| 919 | strncasecmp(icurs->name,"dataType_",9)!=0 && |
---|
| 920 | strncasecmp(icurs->name,"size",4)!=0 && |
---|
| 921 | strncasecmp(icurs->name,"length",4)!=0 && |
---|
| 922 | strncasecmp(icurs->name,"isArray",7)!=0 && |
---|
| 923 | strcasecmp(icurs->name,"Reference")!=0 && |
---|
| 924 | strcasecmp(icurs->name,"minOccurs")!=0 && |
---|
| 925 | strcasecmp(icurs->name,"maxOccurs")!=0 && |
---|
| 926 | strncasecmp(icurs->name,"fmimeType",9)!=0 && |
---|
| 927 | strcasecmp(icurs->name,"inRequest")!=0){ |
---|
| 928 | char *itemp=zStrdup(dataInputsKVP); |
---|
| 929 | if(strcasecmp(icurs->name,"xlink:href")!=0) |
---|
| 930 | sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value); |
---|
| 931 | else |
---|
| 932 | sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value)); |
---|
| 933 | free(itemp); |
---|
| 934 | } |
---|
| 935 | icurs=icurs->next; |
---|
| 936 | } |
---|
| 937 | } |
---|
| 938 | curs=curs->next; |
---|
| 939 | i++; |
---|
| 940 | } |
---|
| 941 | return dataInputsKVP; |
---|
| 942 | } |
---|
| 943 | #endif |
---|
| 944 | |
---|
[1] | 945 | #ifdef __cplusplus |
---|
| 946 | } |
---|
| 947 | #endif |
---|
| 948 | |
---|
| 949 | #endif |
---|