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