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