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