[1] | 1 | /** |
---|
| 2 | * Author : Gérald FENOY |
---|
| 3 | * |
---|
[72] | 4 | * Copyright (c) 2009-2011 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 | #include "service_internal.h" |
---|
| 26 | |
---|
[216] | 27 | #ifdef WIN32 |
---|
| 28 | char * |
---|
| 29 | strtok_r (char *s1, const char *s2, char **lasts) |
---|
| 30 | { |
---|
| 31 | char *ret; |
---|
| 32 | if (s1 == NULL) |
---|
| 33 | s1 = *lasts; |
---|
| 34 | while (*s1 && strchr(s2, *s1)) |
---|
| 35 | ++s1; |
---|
| 36 | if (*s1 == '\0') |
---|
| 37 | return NULL; |
---|
| 38 | ret = s1; |
---|
| 39 | while (*s1 && !strchr(s2, *s1)) |
---|
| 40 | ++s1; |
---|
| 41 | if (*s1) |
---|
| 42 | *s1++ = '\0'; |
---|
| 43 | *lasts = s1; |
---|
| 44 | return ret; |
---|
| 45 | } |
---|
| 46 | #endif |
---|
| 47 | |
---|
| 48 | void addLangAttr(xmlNodePtr n,maps *m){ |
---|
[34] | 49 | map *tmpLmap=getMapFromMaps(m,"main","language"); |
---|
| 50 | if(tmpLmap!=NULL) |
---|
| 51 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value); |
---|
| 52 | else |
---|
| 53 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US"); |
---|
| 54 | } |
---|
| 55 | |
---|
[1] | 56 | /* Converts a hex character to its integer value */ |
---|
| 57 | char from_hex(char ch) { |
---|
| 58 | return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /* Converts an integer value to its hex character*/ |
---|
| 62 | char to_hex(char code) { |
---|
| 63 | static char hex[] = "0123456789abcdef"; |
---|
| 64 | return hex[code & 15]; |
---|
| 65 | } |
---|
| 66 | |
---|
[216] | 67 | #ifdef WIN32 |
---|
| 68 | |
---|
| 69 | #include <windows.h> |
---|
| 70 | #include <stdio.h> |
---|
| 71 | #include <conio.h> |
---|
| 72 | #include <tchar.h> |
---|
| 73 | |
---|
| 74 | #define SHMEMSIZE 4096 |
---|
| 75 | |
---|
| 76 | static LPVOID lpvMemG = NULL; // pointer to shared memory |
---|
| 77 | static HANDLE hMapObjectG = NULL; // handle to file mapping |
---|
| 78 | |
---|
| 79 | void updateStatus(maps *conf){ |
---|
| 80 | fprintf(stderr,"OK Final 1 \n"); |
---|
| 81 | fflush(stderr); |
---|
| 82 | LPWSTR lpszTmp; |
---|
| 83 | BOOL fInit; |
---|
| 84 | char *s=NULL; |
---|
| 85 | map *tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
| 86 | fprintf(stderr,"OK Final 11 \n"); |
---|
| 87 | fflush(stderr); |
---|
| 88 | if(hMapObjectG==NULL) |
---|
| 89 | hMapObjectG = CreateFileMapping( |
---|
| 90 | INVALID_HANDLE_VALUE, // use paging file |
---|
| 91 | NULL, // default security attributes |
---|
| 92 | PAGE_READWRITE, // read/write access |
---|
| 93 | 0, // size: high 32-bits |
---|
| 94 | SHMEMSIZE, // size: low 32-bits |
---|
| 95 | TEXT(tmpMap->value)); // name of map object |
---|
| 96 | if (hMapObjectG == NULL){ |
---|
| 97 | fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value); |
---|
| 98 | return ; |
---|
| 99 | } |
---|
| 100 | fprintf(stderr,"OK Final 2 \n"); |
---|
| 101 | fflush(stderr); |
---|
| 102 | fInit = (GetLastError() != ERROR_ALREADY_EXISTS); |
---|
| 103 | if(lpvMemG==NULL) |
---|
| 104 | lpvMemG = MapViewOfFile( |
---|
| 105 | hMapObjectG, // object to map view of |
---|
| 106 | FILE_MAP_WRITE, // read/write access |
---|
| 107 | 0, // high offset: map from |
---|
| 108 | 0, // low offset: beginning |
---|
| 109 | 0); // default: map entire file |
---|
| 110 | if (lpvMemG == NULL){ |
---|
| 111 | fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value); |
---|
| 112 | return ; |
---|
| 113 | } |
---|
| 114 | fprintf(stderr,"OK Final 3 \n"); |
---|
| 115 | fflush(stderr); |
---|
| 116 | if (fInit) |
---|
| 117 | memset(lpvMemG, '\0', SHMEMSIZE); |
---|
| 118 | fprintf(stderr,"OK Final 4 \n"); |
---|
| 119 | fflush(stderr); |
---|
| 120 | tmpMap=getMapFromMaps(conf,"lenv","status"); |
---|
| 121 | lpszTmp = (LPWSTR) lpvMemG; |
---|
| 122 | for(s=tmpMap->value;*s!=NULL;s++) |
---|
| 123 | *lpszTmp++ = *s; |
---|
| 124 | *lpszTmp = '\0'; |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | char* getStatus(int pid){ |
---|
| 128 | LPWSTR lpszBuf=NULL; |
---|
| 129 | LPWSTR lpszTmp=NULL; |
---|
| 130 | LPVOID lpvMem = NULL; |
---|
| 131 | HANDLE hMapObject = NULL; |
---|
| 132 | BOOL fIgnore,fInit; |
---|
| 133 | char tmp[100]; |
---|
| 134 | sprintf(tmp,"%i",pid); |
---|
| 135 | if(hMapObject==NULL) |
---|
| 136 | hMapObject = CreateFileMapping( |
---|
| 137 | INVALID_HANDLE_VALUE, // use paging file |
---|
| 138 | NULL, // default security attributes |
---|
| 139 | PAGE_READWRITE, // read/write access |
---|
| 140 | 0, // size: high 32-bits |
---|
| 141 | 4096, // size: low 32-bits |
---|
| 142 | TEXT(tmp)); // name of map object |
---|
| 143 | if (hMapObject == NULL) |
---|
| 144 | return FALSE; |
---|
| 145 | if((GetLastError() != ERROR_ALREADY_EXISTS)){ |
---|
| 146 | fIgnore = UnmapViewOfFile(lpvMem); |
---|
| 147 | fIgnore = CloseHandle(hMapObject); |
---|
| 148 | return "-1"; |
---|
| 149 | } |
---|
| 150 | fInit=TRUE; |
---|
| 151 | if(lpvMem==NULL) |
---|
| 152 | lpvMem = MapViewOfFile( |
---|
| 153 | hMapObject, // object to map view of |
---|
| 154 | FILE_MAP_READ, // read/write access |
---|
| 155 | 0, // high offset: map from |
---|
| 156 | 0, // low offset: beginning |
---|
| 157 | 0); // default: map entire file |
---|
| 158 | if (lpvMem == NULL) |
---|
| 159 | return "-1"; |
---|
| 160 | lpszTmp = (LPWSTR) lpvMem; |
---|
| 161 | while (*lpszTmp!=NULL) |
---|
| 162 | *lpszBuf++ = *lpszTmp++; |
---|
| 163 | *lpszBuf = '\0'; |
---|
| 164 | fIgnore = UnmapViewOfFile(lpvMem); |
---|
| 165 | fIgnore = CloseHandle(hMapObject); |
---|
| 166 | return (char*)lpszBuf; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void unhandleStatus(maps *conf){ |
---|
| 170 | BOOL fIgnore; |
---|
| 171 | fIgnore = UnmapViewOfFile(lpvMemG); |
---|
| 172 | fIgnore = CloseHandle(hMapObjectG); |
---|
| 173 | } |
---|
| 174 | #else |
---|
[255] | 175 | |
---|
[216] | 176 | void unhandleStatus(maps *conf){ |
---|
[26] | 177 | int shmid,i; |
---|
| 178 | key_t key; |
---|
| 179 | void *shm; |
---|
| 180 | struct shmid_ds shmids; |
---|
| 181 | char *s,*s1; |
---|
| 182 | map *tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
| 183 | if(tmpMap!=NULL){ |
---|
| 184 | key=atoi(tmpMap->value); |
---|
| 185 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
| 186 | #ifdef DEBUG |
---|
| 187 | fprintf(stderr,"shmget failed to update value\n"); |
---|
| 188 | #endif |
---|
| 189 | }else{ |
---|
| 190 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 191 | #ifdef DEBUG |
---|
| 192 | fprintf(stderr,"shmat failed to update value\n"); |
---|
| 193 | #endif |
---|
| 194 | }else{ |
---|
| 195 | shmdt(shm); |
---|
| 196 | shmctl(shmid,IPC_RMID,&shmids); |
---|
| 197 | } |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | } |
---|
| 201 | |
---|
[216] | 202 | void updateStatus(maps *conf){ |
---|
[26] | 203 | int shmid,i; |
---|
| 204 | key_t key; |
---|
| 205 | char *shm,*s,*s1; |
---|
| 206 | map *tmpMap=NULL; |
---|
| 207 | tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
| 208 | if(tmpMap!=NULL){ |
---|
| 209 | key=atoi(tmpMap->value); |
---|
| 210 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
| 211 | #ifdef DEBUG |
---|
[255] | 212 | fprintf(stderr,"shmget failed to create new Shared memory segment\n"); |
---|
[26] | 213 | #endif |
---|
| 214 | }else{ |
---|
| 215 | if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 216 | #ifdef DEBUG |
---|
| 217 | fprintf(stderr,"shmat failed to update value\n"); |
---|
| 218 | #endif |
---|
| 219 | } |
---|
| 220 | else{ |
---|
| 221 | tmpMap=getMapFromMaps(conf,"lenv","status"); |
---|
| 222 | s1=shm; |
---|
[255] | 223 | for(s=tmpMap->value;*s!=NULL && *s!=0;s++){ |
---|
[26] | 224 | *s1++=*s; |
---|
[255] | 225 | } |
---|
| 226 | *s1=NULL; |
---|
[26] | 227 | shmdt((void *)shm); |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | char* getStatus(int pid){ |
---|
| 234 | int shmid,i; |
---|
| 235 | key_t key; |
---|
| 236 | void *shm; |
---|
| 237 | char *s; |
---|
| 238 | key=pid; |
---|
| 239 | if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { |
---|
| 240 | #ifdef DEBUG |
---|
| 241 | fprintf(stderr,"shmget failed in getStatus\n"); |
---|
| 242 | #endif |
---|
| 243 | }else{ |
---|
| 244 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 245 | #ifdef DEBUG |
---|
| 246 | fprintf(stderr,"shmat failed in getStatus\n"); |
---|
| 247 | #endif |
---|
| 248 | }else{ |
---|
| 249 | return (char*)shm; |
---|
| 250 | } |
---|
| 251 | } |
---|
| 252 | return "-1"; |
---|
| 253 | } |
---|
| 254 | |
---|
[216] | 255 | #endif |
---|
[26] | 256 | |
---|
[216] | 257 | #ifdef USE_JS |
---|
| 258 | |
---|
| 259 | JSBool |
---|
[274] | 260 | JSUpdateStatus(JSContext *cx, uintN argc, jsval *argv1) |
---|
[216] | 261 | { |
---|
[274] | 262 | jsval *argv = JS_ARGV(cx,argv1); |
---|
[216] | 263 | JS_MaybeGC(cx); |
---|
| 264 | char *sid; |
---|
| 265 | int istatus=0; |
---|
| 266 | char *status=NULL; |
---|
| 267 | maps *conf; |
---|
| 268 | int i=0; |
---|
| 269 | if(argc>2){ |
---|
| 270 | #ifdef JS_DEBUG |
---|
| 271 | fprintf(stderr,"Number of arguments used to call the function : %i",argc); |
---|
| 272 | #endif |
---|
| 273 | return JS_FALSE; |
---|
| 274 | } |
---|
| 275 | conf=mapsFromJSObject(cx,argv[0]); |
---|
| 276 | if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){ |
---|
| 277 | char tmpStatus[4]; |
---|
| 278 | sprintf(tmpStatus,"%i",istatus); |
---|
| 279 | tmpStatus[3]=0; |
---|
| 280 | status=strdup(tmpStatus); |
---|
| 281 | } |
---|
| 282 | if(getMapFromMaps(conf,"lenv","status")!=NULL){ |
---|
[274] | 283 | fprintf(stderr,"STATUS RETURNED : %s\n",status); |
---|
| 284 | if(status!=NULL){ |
---|
[216] | 285 | setMapInMaps(conf,"lenv","status",status); |
---|
[274] | 286 | free(status); |
---|
| 287 | } |
---|
[216] | 288 | else |
---|
| 289 | setMapInMaps(conf,"lenv","status","15"); |
---|
| 290 | updateStatus(conf); |
---|
| 291 | } |
---|
| 292 | freeMaps(&conf); |
---|
| 293 | free(conf); |
---|
| 294 | JS_MaybeGC(cx); |
---|
| 295 | return JS_TRUE; |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | #endif |
---|
| 299 | |
---|
| 300 | |
---|
| 301 | |
---|
[1] | 302 | /* Returns a url-encoded version of str */ |
---|
| 303 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
| 304 | char *url_encode(char *str) { |
---|
| 305 | char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf; |
---|
| 306 | while (*pstr) { |
---|
| 307 | if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') |
---|
| 308 | *pbuf++ = *pstr; |
---|
| 309 | else if (*pstr == ' ') |
---|
| 310 | *pbuf++ = '+'; |
---|
| 311 | else |
---|
| 312 | *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); |
---|
| 313 | pstr++; |
---|
| 314 | } |
---|
| 315 | *pbuf = '\0'; |
---|
| 316 | return buf; |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | /* Returns a url-decoded version of str */ |
---|
| 320 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
| 321 | char *url_decode(char *str) { |
---|
| 322 | char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf; |
---|
| 323 | while (*pstr) { |
---|
| 324 | if (*pstr == '%') { |
---|
| 325 | if (pstr[1] && pstr[2]) { |
---|
| 326 | *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); |
---|
| 327 | pstr += 2; |
---|
| 328 | } |
---|
| 329 | } else if (*pstr == '+') { |
---|
| 330 | *pbuf++ = ' '; |
---|
| 331 | } else { |
---|
| 332 | *pbuf++ = *pstr; |
---|
| 333 | } |
---|
| 334 | pstr++; |
---|
| 335 | } |
---|
| 336 | *pbuf = '\0'; |
---|
| 337 | return buf; |
---|
| 338 | } |
---|
| 339 | |
---|
[9] | 340 | char *zCapitalize1(char *tmp){ |
---|
| 341 | char *res=strdup(tmp); |
---|
| 342 | if(res[0]>=97 && res[0]<=122) |
---|
| 343 | res[0]-=32; |
---|
| 344 | return res; |
---|
| 345 | } |
---|
[1] | 346 | |
---|
[9] | 347 | char *zCapitalize(char *tmp){ |
---|
| 348 | int i=0; |
---|
| 349 | char *res=strdup(tmp); |
---|
| 350 | for(i=0;i<strlen(res);i++) |
---|
| 351 | if(res[i]>=97 && res[i]<=122) |
---|
| 352 | res[i]-=32; |
---|
| 353 | return res; |
---|
| 354 | } |
---|
[1] | 355 | |
---|
[9] | 356 | |
---|
[114] | 357 | int zooXmlSearchForNs(const char* name){ |
---|
[9] | 358 | int i; |
---|
| 359 | int res=-1; |
---|
| 360 | for(i=0;i<nbNs;i++) |
---|
| 361 | if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){ |
---|
| 362 | res=i; |
---|
| 363 | break; |
---|
[1] | 364 | } |
---|
[9] | 365 | return res; |
---|
| 366 | } |
---|
[1] | 367 | |
---|
[114] | 368 | int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){ |
---|
[1] | 369 | #ifdef DEBUG |
---|
[9] | 370 | fprintf(stderr,"zooXmlAddNs %d \n",nbNs); |
---|
[1] | 371 | #endif |
---|
[9] | 372 | int currId=-1; |
---|
[280] | 373 | int currNode=-1; |
---|
[9] | 374 | if(nbNs==0){ |
---|
| 375 | nbNs++; |
---|
| 376 | currId=0; |
---|
| 377 | nsName[currId]=strdup(name); |
---|
| 378 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
| 379 | }else{ |
---|
| 380 | currId=zooXmlSearchForNs(name); |
---|
| 381 | if(currId<0){ |
---|
| 382 | nbNs++; |
---|
| 383 | currId=nbNs-1; |
---|
| 384 | nsName[currId]=strdup(name); |
---|
| 385 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
[1] | 386 | } |
---|
[9] | 387 | } |
---|
| 388 | return currId; |
---|
| 389 | } |
---|
[1] | 390 | |
---|
[9] | 391 | void zooXmlCleanupNs(){ |
---|
| 392 | int j; |
---|
[1] | 393 | #ifdef DEBUG |
---|
[9] | 394 | fprintf(stderr,"zooXmlCleanup %d\n",nbNs); |
---|
[1] | 395 | #endif |
---|
[9] | 396 | for(j=nbNs-1;j>=0;j--){ |
---|
[1] | 397 | #ifdef DEBUG |
---|
[9] | 398 | fprintf(stderr,"zooXmlCleanup %d\n",j); |
---|
[1] | 399 | #endif |
---|
[9] | 400 | if(j==0) |
---|
| 401 | xmlFreeNs(usedNs[j]); |
---|
| 402 | free(nsName[j]); |
---|
| 403 | nbNs--; |
---|
[1] | 404 | } |
---|
[9] | 405 | nbNs=0; |
---|
[1] | 406 | } |
---|
| 407 | |
---|
[280] | 408 | xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){ |
---|
| 409 | map* soap=getMapFromMaps(conf,"main","isSoap"); |
---|
| 410 | if(soap!=NULL && strcasecmp(soap->value,"true")==0){ |
---|
| 411 | int lNbNs=nbNs; |
---|
| 412 | nsName[lNbNs]=strdup("soap"); |
---|
| 413 | usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); |
---|
| 414 | nbNs++; |
---|
| 415 | xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); |
---|
| 416 | nsName[nbNs]=strdup("soap"); |
---|
| 417 | usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); |
---|
| 418 | nbNs++; |
---|
| 419 | nsName[nbNs]=strdup("xsi"); |
---|
| 420 | usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); |
---|
| 421 | nbNs++; |
---|
| 422 | xmlNsPtr ns_xsi=usedNs[nbNs-1]; |
---|
| 423 | xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope"); |
---|
| 424 | xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body"); |
---|
| 425 | xmlAddChild(nr1,n); |
---|
| 426 | xmlAddChild(nr,nr1); |
---|
| 427 | return nr; |
---|
| 428 | }else |
---|
| 429 | return n; |
---|
| 430 | } |
---|
| 431 | |
---|
[114] | 432 | xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,const char* service,maps* m){ |
---|
[1] | 433 | |
---|
| 434 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
[9] | 435 | xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
[1] | 436 | xmlChar *xmlbuff; |
---|
| 437 | int buffersize; |
---|
| 438 | /** |
---|
| 439 | * Create the document and its temporary root. |
---|
| 440 | */ |
---|
[9] | 441 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 442 | ns=usedNs[wpsId]; |
---|
[1] | 443 | maps* toto1=getMaps(m,"main"); |
---|
| 444 | |
---|
[9] | 445 | n = xmlNewNode(ns, BAD_CAST "Capabilities"); |
---|
| 446 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 447 | ns_ows=usedNs[owsId]; |
---|
[1] | 448 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
[9] | 449 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 450 | ns_xsi=usedNs[xsiId]; |
---|
| 451 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 452 | ns_xlink=usedNs[xlinkId]; |
---|
| 453 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd"); |
---|
[1] | 454 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
[34] | 455 | addLangAttr(n,m); |
---|
[1] | 456 | |
---|
| 457 | if(toto1!=NULL){ |
---|
| 458 | map* tmp=getMap(toto1->content,"version"); |
---|
| 459 | if(tmp!=NULL){ |
---|
| 460 | xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value); |
---|
| 461 | } |
---|
| 462 | else |
---|
| 463 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
| 464 | } |
---|
| 465 | else |
---|
| 466 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
| 467 | |
---|
| 468 | char tmp[256]; |
---|
| 469 | |
---|
| 470 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); |
---|
| 471 | maps* tmp4=getMaps(m,"identification"); |
---|
| 472 | if(tmp4!=NULL){ |
---|
| 473 | map* tmp2=tmp4->content; |
---|
[71] | 474 | char *orderedFields[5]; |
---|
| 475 | orderedFields[0]="Title"; |
---|
| 476 | orderedFields[1]="Abstract"; |
---|
| 477 | orderedFields[2]="Keywords"; |
---|
| 478 | orderedFields[3]="Fees"; |
---|
| 479 | orderedFields[4]="AccessConstraints"; |
---|
| 480 | int oI=0; |
---|
| 481 | for(oI=0;oI<5;oI++) |
---|
| 482 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
| 483 | if(strcasecmp(tmp2->name,"abstract")==0 || |
---|
| 484 | strcasecmp(tmp2->name,"title")==0 || |
---|
| 485 | strcasecmp(tmp2->name,"accessConstraints")==0 || |
---|
| 486 | strcasecmp(tmp2->name,"fees")==0){ |
---|
| 487 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
| 488 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
| 489 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 490 | xmlAddChild(nc,nc1); |
---|
| 491 | } |
---|
| 492 | else |
---|
| 493 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
| 494 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
| 495 | char *toto=tmp2->value; |
---|
| 496 | char buff[256]; |
---|
| 497 | int i=0; |
---|
| 498 | int j=0; |
---|
| 499 | while(toto[i]){ |
---|
| 500 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 501 | buff[j]=toto[i]; |
---|
| 502 | buff[j+1]=0; |
---|
| 503 | j++; |
---|
| 504 | } |
---|
| 505 | else{ |
---|
| 506 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 507 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 508 | xmlAddChild(nc1,nc2); |
---|
| 509 | j=0; |
---|
| 510 | } |
---|
| 511 | i++; |
---|
[1] | 512 | } |
---|
[71] | 513 | if(strlen(buff)>0){ |
---|
[1] | 514 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 515 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 516 | xmlAddChild(nc1,nc2); |
---|
| 517 | } |
---|
[71] | 518 | xmlAddChild(nc,nc1); |
---|
| 519 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); |
---|
| 520 | xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); |
---|
| 521 | xmlAddChild(nc,nc2); |
---|
| 522 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); |
---|
| 523 | xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); |
---|
| 524 | xmlAddChild(nc,nc2); |
---|
[1] | 525 | } |
---|
[71] | 526 | tmp2=tmp2->next; |
---|
| 527 | } |
---|
[1] | 528 | } |
---|
| 529 | else{ |
---|
| 530 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
| 531 | return NULL; |
---|
| 532 | } |
---|
| 533 | xmlAddChild(n,nc); |
---|
| 534 | |
---|
| 535 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); |
---|
| 536 | nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); |
---|
| 537 | nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); |
---|
| 538 | nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); |
---|
| 539 | nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); |
---|
| 540 | tmp4=getMaps(m,"provider"); |
---|
| 541 | if(tmp4!=NULL){ |
---|
| 542 | map* tmp2=tmp4->content; |
---|
[57] | 543 | char *tmpAddress[6]; |
---|
| 544 | tmpAddress[0]="addressDeliveryPoint"; |
---|
| 545 | tmpAddress[1]="addressCity"; |
---|
| 546 | tmpAddress[2]="addressAdministrativeArea"; |
---|
| 547 | tmpAddress[3]="addressPostalCode"; |
---|
| 548 | tmpAddress[4]="addressCountry"; |
---|
| 549 | tmpAddress[5]="addressElectronicMailAddress"; |
---|
| 550 | char *tmpPhone[2]; |
---|
| 551 | tmpPhone[0]="phoneVoice"; |
---|
| 552 | tmpPhone[1]="phoneFacsimile"; |
---|
[71] | 553 | char *orderedFields[12]; |
---|
| 554 | orderedFields[0]="providerName"; |
---|
| 555 | orderedFields[1]="providerSite"; |
---|
| 556 | orderedFields[2]="individualName"; |
---|
| 557 | orderedFields[3]="positionName"; |
---|
| 558 | orderedFields[4]=tmpPhone[0]; |
---|
| 559 | orderedFields[5]=tmpPhone[1]; |
---|
| 560 | orderedFields[6]=tmpAddress[0]; |
---|
| 561 | orderedFields[7]=tmpAddress[1]; |
---|
| 562 | orderedFields[8]=tmpAddress[2]; |
---|
| 563 | orderedFields[9]=tmpAddress[3]; |
---|
| 564 | orderedFields[10]=tmpAddress[4]; |
---|
| 565 | orderedFields[11]=tmpAddress[5]; |
---|
| 566 | int oI=0; |
---|
| 567 | for(oI=0;oI<12;oI++) |
---|
| 568 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
| 569 | if(strcmp(tmp2->name,"keywords")!=0 && |
---|
| 570 | strcmp(tmp2->name,"serverAddress")!=0 && |
---|
| 571 | strcmp(tmp2->name,"lang")!=0){ |
---|
| 572 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
| 573 | if(strcmp(tmp2->name,"ProviderName")==0){ |
---|
[1] | 574 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
[71] | 575 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
[1] | 576 | xmlAddChild(nc,nc1); |
---|
[71] | 577 | } |
---|
| 578 | else{ |
---|
| 579 | if(strcmp(tmp2->name,"ProviderSite")==0){ |
---|
[1] | 580 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
[71] | 581 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); |
---|
| 582 | xmlAddChild(nc,nc1); |
---|
[1] | 583 | } |
---|
[71] | 584 | else |
---|
| 585 | if(strcmp(tmp2->name,"IndividualName")==0 || |
---|
| 586 | strcmp(tmp2->name,"PositionName")==0){ |
---|
| 587 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
| 588 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 589 | xmlAddChild(nc3,nc1); |
---|
| 590 | } |
---|
[1] | 591 | else |
---|
[71] | 592 | if(strncmp(tmp2->name,"Phone",5)==0){ |
---|
[57] | 593 | int j; |
---|
[71] | 594 | for(j=0;j<2;j++) |
---|
| 595 | if(strcasecmp(tmp2->name,tmpPhone[j])==0){ |
---|
[57] | 596 | char *toto=NULL; |
---|
| 597 | char *toto1=tmp2->name; |
---|
[71] | 598 | toto=strstr(toto1,"Phone"); |
---|
| 599 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5); |
---|
[57] | 600 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
[71] | 601 | xmlAddChild(nc5,nc1); |
---|
[57] | 602 | } |
---|
[1] | 603 | } |
---|
[71] | 604 | else |
---|
| 605 | if(strncmp(tmp2->name,"Address",7)==0){ |
---|
| 606 | int j; |
---|
| 607 | for(j=0;j<6;j++) |
---|
| 608 | if(strcasecmp(tmp2->name,tmpAddress[j])==0){ |
---|
| 609 | char *toto=NULL; |
---|
| 610 | char *toto1=tmp2->name; |
---|
| 611 | toto=strstr(toto1,"Address"); |
---|
| 612 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7); |
---|
| 613 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 614 | xmlAddChild(nc6,nc1); |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | } |
---|
[1] | 618 | } |
---|
[71] | 619 | else |
---|
| 620 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
| 621 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
| 622 | char *toto=tmp2->value; |
---|
| 623 | char buff[256]; |
---|
| 624 | int i=0; |
---|
| 625 | int j=0; |
---|
| 626 | while(toto[i]){ |
---|
| 627 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 628 | buff[j]=toto[i]; |
---|
| 629 | buff[j+1]=0; |
---|
| 630 | j++; |
---|
| 631 | } |
---|
| 632 | else{ |
---|
| 633 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 634 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 635 | xmlAddChild(nc1,nc2); |
---|
| 636 | j=0; |
---|
| 637 | } |
---|
| 638 | i++; |
---|
[1] | 639 | } |
---|
[71] | 640 | if(strlen(buff)>0){ |
---|
[1] | 641 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 642 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 643 | xmlAddChild(nc1,nc2); |
---|
| 644 | } |
---|
[71] | 645 | xmlAddChild(nc,nc1); |
---|
[1] | 646 | } |
---|
[71] | 647 | tmp2=tmp2->next; |
---|
| 648 | } |
---|
[1] | 649 | } |
---|
| 650 | else{ |
---|
| 651 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
| 652 | } |
---|
| 653 | xmlAddChild(nc4,nc5); |
---|
| 654 | xmlAddChild(nc4,nc6); |
---|
| 655 | xmlAddChild(nc3,nc4); |
---|
| 656 | xmlAddChild(nc,nc3); |
---|
| 657 | xmlAddChild(n,nc); |
---|
| 658 | |
---|
| 659 | |
---|
| 660 | nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); |
---|
| 661 | char *tmp2[3]; |
---|
[9] | 662 | tmp2[0]=strdup("GetCapabilities"); |
---|
| 663 | tmp2[1]=strdup("DescribeProcess"); |
---|
| 664 | tmp2[2]=strdup("Execute"); |
---|
[1] | 665 | int j=0; |
---|
| 666 | |
---|
| 667 | if(toto1!=NULL){ |
---|
| 668 | map* tmp=getMap(toto1->content,"serverAddress"); |
---|
| 669 | if(tmp!=NULL){ |
---|
| 670 | SERVICE_URL = strdup(tmp->value); |
---|
| 671 | } |
---|
| 672 | else |
---|
[9] | 673 | SERVICE_URL = strdup("not_found"); |
---|
[1] | 674 | } |
---|
| 675 | else |
---|
[9] | 676 | SERVICE_URL = strdup("not_found"); |
---|
[1] | 677 | |
---|
| 678 | for(j=0;j<3;j++){ |
---|
| 679 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); |
---|
| 680 | xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]); |
---|
| 681 | nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); |
---|
| 682 | nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); |
---|
| 683 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); |
---|
| 684 | sprintf(tmp,"%s/%s",SERVICE_URL,service); |
---|
[9] | 685 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
[1] | 686 | xmlAddChild(nc3,nc4); |
---|
| 687 | if(j>0){ |
---|
| 688 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); |
---|
[9] | 689 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
[1] | 690 | xmlAddChild(nc3,nc4); |
---|
| 691 | } |
---|
| 692 | xmlAddChild(nc2,nc3); |
---|
| 693 | xmlAddChild(nc1,nc2); |
---|
| 694 | xmlAddChild(nc,nc1); |
---|
| 695 | } |
---|
[9] | 696 | for(j=2;j>=0;j--) |
---|
| 697 | free(tmp2[j]); |
---|
[1] | 698 | xmlAddChild(n,nc); |
---|
| 699 | |
---|
| 700 | nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); |
---|
| 701 | xmlAddChild(n,nc); |
---|
| 702 | |
---|
| 703 | nc1 = xmlNewNode(ns, BAD_CAST "Languages"); |
---|
| 704 | nc2 = xmlNewNode(ns, BAD_CAST "Default"); |
---|
| 705 | nc3 = xmlNewNode(ns, BAD_CAST "Supported"); |
---|
| 706 | |
---|
| 707 | toto1=getMaps(m,"main"); |
---|
| 708 | if(toto1!=NULL){ |
---|
| 709 | map* tmp1=getMap(toto1->content,"lang"); |
---|
| 710 | char *toto=tmp1->value; |
---|
| 711 | char buff[256]; |
---|
| 712 | int i=0; |
---|
| 713 | int j=0; |
---|
| 714 | int dcount=0; |
---|
| 715 | while(toto[i]){ |
---|
| 716 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 717 | buff[j]=toto[i]; |
---|
| 718 | buff[j+1]=0; |
---|
| 719 | j++; |
---|
| 720 | } |
---|
| 721 | else{ |
---|
| 722 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 723 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 724 | if(dcount==0){ |
---|
| 725 | xmlAddChild(nc2,nc4); |
---|
| 726 | xmlAddChild(nc1,nc2); |
---|
| 727 | dcount++; |
---|
| 728 | } |
---|
| 729 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 730 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 731 | xmlAddChild(nc3,nc4); |
---|
| 732 | j=0; |
---|
| 733 | buff[j]=0; |
---|
| 734 | } |
---|
| 735 | i++; |
---|
| 736 | } |
---|
| 737 | if(strlen(buff)>0){ |
---|
| 738 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 739 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 740 | xmlAddChild(nc3,nc4); |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | xmlAddChild(nc1,nc3); |
---|
| 744 | xmlAddChild(n,nc1); |
---|
| 745 | |
---|
[280] | 746 | xmlNodePtr fn=soapEnvelope(m,n); |
---|
| 747 | xmlDocSetRootElement(doc, fn); |
---|
[9] | 748 | //xmlFreeNs(ns); |
---|
| 749 | free(SERVICE_URL); |
---|
[1] | 750 | return nc; |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ |
---|
[9] | 754 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
[1] | 755 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
[9] | 756 | /** |
---|
| 757 | * Initialize or get existing namspaces |
---|
| 758 | */ |
---|
| 759 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 760 | ns=usedNs[wpsId]; |
---|
| 761 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 762 | ns_ows=usedNs[owsId]; |
---|
| 763 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 764 | ns_xlink=usedNs[xlinkId]; |
---|
[1] | 765 | |
---|
| 766 | int cursor=0; |
---|
| 767 | map* tmp1; |
---|
| 768 | if(serv->content!=NULL){ |
---|
| 769 | nc1 = xmlNewNode(ns, BAD_CAST "Process"); |
---|
| 770 | tmp1=getMap(serv->content,"processVersion"); |
---|
| 771 | if(tmp1!=NULL) |
---|
[9] | 772 | xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
[1] | 773 | printDescription(nc1,ns_ows,serv->name,serv->content); |
---|
| 774 | tmp1=serv->metadata; |
---|
| 775 | while(tmp1!=NULL){ |
---|
| 776 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
[9] | 777 | xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
[1] | 778 | xmlAddChild(nc1,nc2); |
---|
| 779 | tmp1=tmp1->next; |
---|
| 780 | } |
---|
| 781 | xmlAddChild(nc,nc1); |
---|
| 782 | } |
---|
| 783 | } |
---|
| 784 | |
---|
[114] | 785 | xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){ |
---|
[1] | 786 | |
---|
| 787 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 788 | xmlNodePtr n,nr; |
---|
| 789 | xmlChar *xmlbuff; |
---|
| 790 | int buffersize; |
---|
| 791 | |
---|
[9] | 792 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
| 793 | ns=usedNs[wpsId]; |
---|
| 794 | n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions"); |
---|
| 795 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 796 | ns_ows=usedNs[owsId]; |
---|
[1] | 797 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
[9] | 798 | zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 799 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 800 | ns_xsi=usedNs[xsiId]; |
---|
| 801 | |
---|
| 802 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd"); |
---|
[1] | 803 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
| 804 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
[34] | 805 | addLangAttr(n,m); |
---|
[1] | 806 | |
---|
[280] | 807 | xmlNodePtr fn=soapEnvelope(m,n); |
---|
| 808 | xmlDocSetRootElement(doc, fn); |
---|
[1] | 809 | |
---|
| 810 | return n; |
---|
| 811 | } |
---|
| 812 | |
---|
[9] | 813 | void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){ |
---|
[1] | 814 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 815 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
| 816 | |
---|
| 817 | char tmp[256]; |
---|
| 818 | n=nc; |
---|
| 819 | |
---|
[9] | 820 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
| 821 | ns=usedNs[wpsId]; |
---|
| 822 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 823 | ns_ows=usedNs[owsId]; |
---|
| 824 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 825 | ns_xlink=usedNs[xlinkId]; |
---|
[1] | 826 | |
---|
| 827 | nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); |
---|
| 828 | char *tmp4[3]; |
---|
| 829 | tmp4[0]="processVersion"; |
---|
| 830 | tmp4[1]="storeSupported"; |
---|
| 831 | tmp4[2]="statusSupported"; |
---|
| 832 | int j=0; |
---|
| 833 | map* tmp1=NULL; |
---|
| 834 | for(j=0;j<3;j++){ |
---|
[9] | 835 | tmp1=getMap(serv->content,tmp4[j]); |
---|
[1] | 836 | if(tmp1!=NULL){ |
---|
| 837 | if(j==0) |
---|
[9] | 838 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
[1] | 839 | else |
---|
| 840 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value); |
---|
| 841 | } |
---|
| 842 | else{ |
---|
| 843 | if(j>0) |
---|
| 844 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); |
---|
| 845 | } |
---|
| 846 | } |
---|
| 847 | |
---|
[9] | 848 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
[1] | 849 | |
---|
[9] | 850 | tmp1=serv->metadata; |
---|
[1] | 851 | while(tmp1!=NULL){ |
---|
| 852 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
[9] | 853 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
[1] | 854 | xmlAddChild(nc,nc1); |
---|
| 855 | tmp1=tmp1->next; |
---|
| 856 | } |
---|
| 857 | |
---|
[9] | 858 | tmp1=getMap(serv->content,"Profile"); |
---|
[1] | 859 | if(tmp1!=NULL){ |
---|
| 860 | nc1 = xmlNewNode(ns, BAD_CAST "Profile"); |
---|
| 861 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 862 | xmlAddChild(nc,nc1); |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); |
---|
[9] | 866 | elements* e=serv->inputs; |
---|
[76] | 867 | printFullDescription(e,"Input",ns_ows,nc1); |
---|
| 868 | xmlAddChild(nc,nc1); |
---|
[1] | 869 | |
---|
[76] | 870 | nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); |
---|
| 871 | e=serv->outputs; |
---|
| 872 | printFullDescription(e,"Output",ns_ows,nc1); |
---|
| 873 | xmlAddChild(nc,nc1); |
---|
[1] | 874 | |
---|
[76] | 875 | xmlAddChild(n,nc); |
---|
[1] | 876 | |
---|
[76] | 877 | } |
---|
[1] | 878 | |
---|
[114] | 879 | void printFullDescription(elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){ |
---|
[76] | 880 | char *orderedFields[7]; |
---|
| 881 | orderedFields[0]="mimeType"; |
---|
| 882 | orderedFields[1]="encoding"; |
---|
| 883 | orderedFields[2]="schema"; |
---|
| 884 | orderedFields[3]="dataType"; |
---|
| 885 | orderedFields[4]="uom"; |
---|
| 886 | orderedFields[5]="CRS"; |
---|
| 887 | orderedFields[6]="value"; |
---|
| 888 | |
---|
| 889 | xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7; |
---|
| 890 | elements* e=elem; |
---|
| 891 | map* tmp1=NULL; |
---|
[1] | 892 | while(e!=NULL){ |
---|
[76] | 893 | int default1=0; |
---|
| 894 | int isAnyValue=1; |
---|
| 895 | nc2 = xmlNewNode(NULL, BAD_CAST type); |
---|
[1] | 896 | tmp1=getMap(e->content,"minOccurs"); |
---|
| 897 | if(tmp1){ |
---|
| 898 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 899 | } |
---|
| 900 | tmp1=getMap(e->content,"maxOccurs"); |
---|
| 901 | if(tmp1){ |
---|
| 902 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 903 | } |
---|
| 904 | |
---|
| 905 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
| 906 | |
---|
[76] | 907 | if(strncmp(type,"Output",6)==0){ |
---|
| 908 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) |
---|
| 909 | nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput"); |
---|
| 910 | else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
[1] | 911 | nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput"); |
---|
[76] | 912 | else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) |
---|
| 913 | nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxOutput"); |
---|
[1] | 914 | else |
---|
| 915 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
[76] | 916 | }else{ |
---|
[79] | 917 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0){ |
---|
[76] | 918 | nc3 = xmlNewNode(NULL, BAD_CAST "LiteralData"); |
---|
[79] | 919 | } |
---|
[76] | 920 | else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
| 921 | nc3 = xmlNewNode(NULL, BAD_CAST "ComplexData"); |
---|
| 922 | else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) |
---|
| 923 | nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxData"); |
---|
| 924 | else |
---|
| 925 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
| 926 | } |
---|
[1] | 927 | iotype* _tmp=e->defaults; |
---|
| 928 | int datatype=0; |
---|
[79] | 929 | bool hasDefault=false; |
---|
| 930 | bool hasUOM=false; |
---|
[1] | 931 | if(_tmp!=NULL){ |
---|
[79] | 932 | if(strcmp(e->format,"LiteralOutput")==0 || |
---|
| 933 | strcmp(e->format,"LiteralData")==0){ |
---|
[1] | 934 | datatype=1; |
---|
| 935 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
| 936 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
[79] | 937 | } |
---|
| 938 | else if(strcmp(e->format,"BoundingBoxOutput")==0 || |
---|
| 939 | strcmp(e->format,"BoundingBoxData")==0){ |
---|
| 940 | datatype=2; |
---|
| 941 | //nc4 = xmlNewNode(NULL, BAD_CAST "BoundingBoxOutput"); |
---|
| 942 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 943 | } |
---|
| 944 | else{ |
---|
| 945 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 946 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | tmp1=_tmp->content; |
---|
| 950 | int avcnt=0; |
---|
| 951 | int dcnt=0; |
---|
| 952 | int oI=0; |
---|
| 953 | for(oI=0;oI<7;oI++) |
---|
| 954 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
| 955 | //while(tmp1!=NULL){ |
---|
[1] | 956 | #ifdef DEBUG |
---|
[79] | 957 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
[1] | 958 | #endif |
---|
[79] | 959 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
| 960 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
| 961 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 962 | char tmp[1024]; |
---|
| 963 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
| 964 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
| 965 | xmlAddChild(nc3,nc6); |
---|
| 966 | tmp1=tmp1->next; |
---|
| 967 | datatype=1; |
---|
| 968 | continue; |
---|
| 969 | } |
---|
| 970 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
| 971 | strncasecmp(tmp1->name,"DataType",8)!=0 && |
---|
| 972 | strcasecmp(tmp1->name,"extension")!=0 && |
---|
| 973 | strcasecmp(tmp1->name,"value")!=0 && |
---|
| 974 | strncasecmp(tmp1->name,"AllowedValues",13)!=0){ |
---|
| 975 | if(datatype!=1){ |
---|
| 976 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 977 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 978 | free(tmp2); |
---|
| 979 | } |
---|
| 980 | else{ |
---|
| 981 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 982 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 983 | free(tmp2); |
---|
| 984 | } |
---|
| 985 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 986 | xmlAddChild(nc5,nc6); |
---|
| 987 | hasUOM=true; |
---|
| 988 | }else |
---|
| 989 | if(strncmp(type,"Input",5)==0){ |
---|
| 990 | if(strcmp(tmp1->name,"value")==0){ |
---|
| 991 | nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); |
---|
| 992 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 993 | default1=1; |
---|
| 994 | } |
---|
| 995 | if(strncasecmp(tmp1->name,"AllowedValues",13)==0){ |
---|
| 996 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
| 997 | fprintf(stderr,"ALLOWED VALUE %s\n",tmp1->value); |
---|
| 998 | char *token,*saveptr1; |
---|
| 999 | token=strtok_r(tmp1->value,",",&saveptr1); |
---|
| 1000 | while(token!=NULL){ |
---|
| 1001 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
| 1002 | char *tmps=strdup(token); |
---|
| 1003 | tmps[strlen(tmps)]=0; |
---|
| 1004 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); |
---|
| 1005 | fprintf(stderr,"strgin : %s\n",tmps); |
---|
| 1006 | xmlAddChild(nc6,nc7); |
---|
| 1007 | token=strtok_r(NULL,",",&saveptr1); |
---|
| 1008 | } |
---|
| 1009 | xmlAddChild(nc3,nc6); |
---|
| 1010 | isAnyValue=-1; |
---|
| 1011 | } |
---|
| 1012 | hasDefault=true; |
---|
| 1013 | } |
---|
| 1014 | tmp1=tmp1->next; |
---|
| 1015 | if(datatype!=2){ |
---|
| 1016 | if(hasUOM==true){ |
---|
| 1017 | xmlAddChild(nc4,nc5); |
---|
| 1018 | xmlAddChild(nc3,nc4); |
---|
| 1019 | } |
---|
| 1020 | }else{ |
---|
| 1021 | xmlAddChild(nc3,nc5); |
---|
| 1022 | } |
---|
[76] | 1023 | |
---|
[79] | 1024 | if(strncmp(type,"Input",5)==0){ |
---|
| 1025 | if(datatype==1 && isAnyValue==1 && avcnt==0){ |
---|
| 1026 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
| 1027 | hasDefault=true; |
---|
| 1028 | avcnt++; |
---|
| 1029 | } |
---|
| 1030 | if(datatype==1 && default1>0){ |
---|
| 1031 | xmlAddChild(nc3,nc7); |
---|
| 1032 | } |
---|
| 1033 | } |
---|
[1] | 1034 | } |
---|
| 1035 | } |
---|
[280] | 1036 | |
---|
[1] | 1037 | _tmp=e->supported; |
---|
[289] | 1038 | if(_tmp==NULL && (getMap(e->defaults->content,"uom")!=NULL || datatype!=1)) |
---|
[280] | 1039 | _tmp=e->defaults; |
---|
| 1040 | |
---|
[71] | 1041 | int hasSupported=-1; |
---|
[1] | 1042 | while(_tmp!=NULL){ |
---|
[71] | 1043 | if(hasSupported<0){ |
---|
| 1044 | if(datatype==0){ |
---|
| 1045 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 1046 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 1047 | } |
---|
| 1048 | else |
---|
| 1049 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 1050 | hasSupported=0; |
---|
| 1051 | }else |
---|
[76] | 1052 | if(datatype==0) |
---|
| 1053 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
[1] | 1054 | tmp1=_tmp->content; |
---|
[71] | 1055 | int oI=0; |
---|
[76] | 1056 | for(oI=0;oI<6;oI++) |
---|
[71] | 1057 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
[1] | 1058 | #ifdef DEBUG |
---|
[71] | 1059 | printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); |
---|
[1] | 1060 | #endif |
---|
[71] | 1061 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
| 1062 | strcmp(tmp1->name,"DataType")!=0 && |
---|
| 1063 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
[76] | 1064 | if(datatype!=1){ |
---|
[71] | 1065 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 1066 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 1067 | free(tmp2); |
---|
| 1068 | } |
---|
| 1069 | else{ |
---|
| 1070 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 1071 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 1072 | free(tmp2); |
---|
| 1073 | } |
---|
[76] | 1074 | if(datatype==2){ |
---|
| 1075 | char *tmpv,*tmps; |
---|
| 1076 | tmps=strtok_r(tmp1->value,",",&tmpv); |
---|
| 1077 | while(tmps){ |
---|
| 1078 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmps)); |
---|
| 1079 | xmlAddChild(nc5,nc6); |
---|
| 1080 | tmps=strtok_r(NULL,",",&tmpv); |
---|
| 1081 | if(tmps){ |
---|
| 1082 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 1083 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 1084 | free(tmp2); |
---|
| 1085 | } |
---|
| 1086 | } |
---|
| 1087 | } |
---|
| 1088 | else{ |
---|
| 1089 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 1090 | xmlAddChild(nc5,nc6); |
---|
| 1091 | } |
---|
[9] | 1092 | } |
---|
[71] | 1093 | tmp1=tmp1->next; |
---|
[1] | 1094 | } |
---|
[71] | 1095 | if(hasSupported<=0){ |
---|
[76] | 1096 | if(datatype!=2){ |
---|
[71] | 1097 | xmlAddChild(nc4,nc5); |
---|
| 1098 | xmlAddChild(nc3,nc4); |
---|
| 1099 | }else |
---|
[76] | 1100 | xmlAddChild(nc3,nc5); |
---|
[71] | 1101 | hasSupported=1; |
---|
[1] | 1102 | } |
---|
[71] | 1103 | else |
---|
[76] | 1104 | if(datatype!=2){ |
---|
| 1105 | xmlAddChild(nc4,nc5); |
---|
| 1106 | } |
---|
| 1107 | else |
---|
| 1108 | xmlAddChild(nc3,nc5); |
---|
| 1109 | _tmp=_tmp->next; |
---|
[1] | 1110 | } |
---|
| 1111 | xmlAddChild(nc2,nc3); |
---|
| 1112 | |
---|
[79] | 1113 | if(datatype!=2 && hasUOM==true){ |
---|
[76] | 1114 | xmlAddChild(nc3,nc4); |
---|
| 1115 | xmlAddChild(nc2,nc3); |
---|
[79] | 1116 | }else if(datatype!=2){ |
---|
[84] | 1117 | if(hasDefault!=true && strncmp(type,"Input",5)==0) |
---|
[79] | 1118 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
[76] | 1119 | } |
---|
[1] | 1120 | |
---|
| 1121 | xmlAddChild(nc1,nc2); |
---|
| 1122 | |
---|
| 1123 | e=e->next; |
---|
| 1124 | } |
---|
| 1125 | } |
---|
| 1126 | |
---|
[114] | 1127 | void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ |
---|
[280] | 1128 | xmlNsPtr ns,ns1,ns_ows,ns_xlink,ns_xsi; |
---|
[9] | 1129 | xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor; |
---|
| 1130 | xmlDocPtr doc; |
---|
[1] | 1131 | xmlChar *xmlbuff; |
---|
| 1132 | int buffersize; |
---|
[9] | 1133 | time_t time1; |
---|
| 1134 | time(&time1); |
---|
[280] | 1135 | nr=NULL; |
---|
[9] | 1136 | /** |
---|
| 1137 | * Create the document and its temporary root. |
---|
| 1138 | */ |
---|
| 1139 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1140 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 1141 | ns=usedNs[wpsId]; |
---|
[280] | 1142 | |
---|
[9] | 1143 | n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); |
---|
[280] | 1144 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
[9] | 1145 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 1146 | ns_ows=usedNs[owsId]; |
---|
| 1147 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 1148 | ns_xlink=usedNs[xlinkId]; |
---|
| 1149 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 1150 | ns_xsi=usedNs[xsiId]; |
---|
[280] | 1151 | |
---|
[9] | 1152 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd"); |
---|
| 1153 | |
---|
| 1154 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
| 1155 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
[34] | 1156 | addLangAttr(n,m); |
---|
| 1157 | |
---|
[9] | 1158 | char tmp[256]; |
---|
[26] | 1159 | char url[1024]; |
---|
[72] | 1160 | char stored_path[1024]; |
---|
[9] | 1161 | memset(tmp,0,256); |
---|
[72] | 1162 | memset(url,0,1024); |
---|
| 1163 | memset(stored_path,0,1024); |
---|
[9] | 1164 | maps* tmp_maps=getMaps(m,"main"); |
---|
| 1165 | if(tmp_maps!=NULL){ |
---|
[26] | 1166 | map* tmpm1=getMap(tmp_maps->content,"serverAddress"); |
---|
| 1167 | /** |
---|
| 1168 | * Check if the ZOO Service GetStatus is available in the local directory. |
---|
| 1169 | * If yes, then it uses a reference to an URL which the client can access |
---|
| 1170 | * to get information on the status of a running Service (using the |
---|
| 1171 | * percentCompleted attribute). |
---|
| 1172 | * Else fallback to the initial method using the xml file to write in ... |
---|
| 1173 | */ |
---|
| 1174 | char ntmp[1024]; |
---|
| 1175 | #ifndef WIN32 |
---|
| 1176 | getcwd(ntmp,1024); |
---|
| 1177 | #else |
---|
| 1178 | _getcwd(ntmp,1024); |
---|
| 1179 | #endif |
---|
| 1180 | struct stat myFileInfo; |
---|
| 1181 | int statRes; |
---|
| 1182 | char file_path[1024]; |
---|
| 1183 | sprintf(file_path,"%s/GetStatus.zcfg",ntmp); |
---|
| 1184 | statRes=stat(file_path,&myFileInfo); |
---|
| 1185 | if(statRes==0){ |
---|
| 1186 | char currentSid[128]; |
---|
| 1187 | map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); |
---|
| 1188 | map *tmp_lenv=NULL; |
---|
| 1189 | tmp_lenv=getMapFromMaps(m,"lenv","sid"); |
---|
| 1190 | if(tmp_lenv==NULL) |
---|
| 1191 | sprintf(currentSid,"%i",pid); |
---|
| 1192 | else |
---|
| 1193 | sprintf(currentSid,"%s",tmp_lenv->value); |
---|
| 1194 | if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ |
---|
[280] | 1195 | sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
[26] | 1196 | }else{ |
---|
| 1197 | if(strlen(tmpm->value)>0) |
---|
| 1198 | if(strcasecmp(tmpm->value,"true")!=0) |
---|
| 1199 | sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); |
---|
| 1200 | else |
---|
| 1201 | sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); |
---|
| 1202 | else |
---|
[41] | 1203 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
[26] | 1204 | } |
---|
| 1205 | }else{ |
---|
| 1206 | map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); |
---|
| 1207 | if(tmpm1!=NULL && tmpm2!=NULL){ |
---|
| 1208 | sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); |
---|
| 1209 | } |
---|
[9] | 1210 | } |
---|
[26] | 1211 | if(tmpm1!=NULL) |
---|
[280] | 1212 | sprintf(tmp,"%s",tmpm1->value); |
---|
[72] | 1213 | tmpm1=getMapFromMaps(m,"main","TmpPath"); |
---|
| 1214 | sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid); |
---|
[9] | 1215 | } |
---|
| 1216 | |
---|
[72] | 1217 | |
---|
| 1218 | |
---|
[9] | 1219 | xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); |
---|
[72] | 1220 | map* test=getMap(request,"storeExecuteResponse"); |
---|
| 1221 | bool hasStoredExecuteResponse=false; |
---|
| 1222 | if(test!=NULL && strcasecmp(test->value,"true")==0){ |
---|
[9] | 1223 | xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); |
---|
[72] | 1224 | hasStoredExecuteResponse=true; |
---|
[9] | 1225 | } |
---|
| 1226 | |
---|
| 1227 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
| 1228 | map* tmp2=getMap(serv->content,"processVersion"); |
---|
| 1229 | |
---|
| 1230 | if(tmp2!=NULL) |
---|
| 1231 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); |
---|
| 1232 | |
---|
| 1233 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
| 1234 | fflush(stderr); |
---|
| 1235 | |
---|
| 1236 | xmlAddChild(n,nc); |
---|
| 1237 | |
---|
| 1238 | nc = xmlNewNode(ns, BAD_CAST "Status"); |
---|
| 1239 | const struct tm *tm; |
---|
| 1240 | size_t len; |
---|
| 1241 | time_t now; |
---|
| 1242 | char *tmp1; |
---|
[26] | 1243 | map *tmpStatus; |
---|
[9] | 1244 | |
---|
| 1245 | now = time ( NULL ); |
---|
| 1246 | tm = localtime ( &now ); |
---|
| 1247 | |
---|
| 1248 | tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); |
---|
| 1249 | |
---|
| 1250 | len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); |
---|
| 1251 | |
---|
[26] | 1252 | xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); |
---|
| 1253 | |
---|
| 1254 | char sMsg[2048]; |
---|
[9] | 1255 | switch(status){ |
---|
| 1256 | case SERVICE_SUCCEEDED: |
---|
| 1257 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); |
---|
[34] | 1258 | sprintf(sMsg,_("Service \"%s\" run successfully."),serv->name); |
---|
[26] | 1259 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1260 | xmlAddChild(nc1,nc3); |
---|
[9] | 1261 | break; |
---|
| 1262 | case SERVICE_STARTED: |
---|
| 1263 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); |
---|
[26] | 1264 | tmpStatus=getMapFromMaps(m,"lenv","status"); |
---|
| 1265 | xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); |
---|
[34] | 1266 | sprintf(sMsg,_("ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service."),serv->name); |
---|
[26] | 1267 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1268 | xmlAddChild(nc1,nc3); |
---|
[9] | 1269 | break; |
---|
| 1270 | case SERVICE_ACCEPTED: |
---|
| 1271 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); |
---|
[34] | 1272 | sprintf(sMsg,_("Service \"%s\" was accepted by the ZOO Kernel and it run as a background task. Please consult the statusLocation attribtue providen in this document to get the up-to-date document."),serv->name); |
---|
[26] | 1273 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1274 | xmlAddChild(nc1,nc3); |
---|
[9] | 1275 | break; |
---|
| 1276 | case SERVICE_FAILED: |
---|
| 1277 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); |
---|
[26] | 1278 | map *errorMap; |
---|
| 1279 | map *te; |
---|
| 1280 | te=getMapFromMaps(m,"lenv","code"); |
---|
| 1281 | if(te!=NULL) |
---|
| 1282 | errorMap=createMap("code",te->value); |
---|
| 1283 | else |
---|
| 1284 | errorMap=createMap("code","NoApplicableCode"); |
---|
| 1285 | te=getMapFromMaps(m,"lenv","message"); |
---|
| 1286 | if(te!=NULL) |
---|
[57] | 1287 | addToMap(errorMap,"text",_ss(te->value)); |
---|
[26] | 1288 | else |
---|
[34] | 1289 | addToMap(errorMap,"text",_("No more information available")); |
---|
[26] | 1290 | nc3=createExceptionReportNode(m,errorMap,0); |
---|
[59] | 1291 | freeMap(&errorMap); |
---|
| 1292 | free(errorMap); |
---|
[26] | 1293 | xmlAddChild(nc1,nc3); |
---|
[9] | 1294 | break; |
---|
| 1295 | default : |
---|
[34] | 1296 | printf(_("error code not know : %i\n"),status); |
---|
[26] | 1297 | //exit(1); |
---|
[9] | 1298 | break; |
---|
| 1299 | } |
---|
| 1300 | xmlAddChild(nc,nc1); |
---|
| 1301 | xmlAddChild(n,nc); |
---|
| 1302 | free(tmp1); |
---|
| 1303 | |
---|
| 1304 | #ifdef DEBUG |
---|
| 1305 | fprintf(stderr,"printProcessResponse 1 161\n"); |
---|
| 1306 | #endif |
---|
| 1307 | |
---|
| 1308 | map* lineage=getMap(request,"lineage"); |
---|
[87] | 1309 | if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){ |
---|
[9] | 1310 | nc = xmlNewNode(ns, BAD_CAST "DataInputs"); |
---|
| 1311 | int i; |
---|
| 1312 | maps* mcursor=inputs; |
---|
[65] | 1313 | elements* scursor=NULL; |
---|
[9] | 1314 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
[65] | 1315 | scursor=getElements(serv->inputs,mcursor->name); |
---|
[76] | 1316 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input"); |
---|
[9] | 1317 | mcursor=mcursor->next; |
---|
| 1318 | } |
---|
| 1319 | xmlAddChild(n,nc); |
---|
| 1320 | |
---|
| 1321 | #ifdef DEBUG |
---|
| 1322 | fprintf(stderr,"printProcessResponse 1 177\n"); |
---|
| 1323 | #endif |
---|
| 1324 | |
---|
| 1325 | nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); |
---|
| 1326 | mcursor=outputs; |
---|
[65] | 1327 | scursor=NULL; |
---|
| 1328 | while(mcursor!=NULL){ |
---|
| 1329 | scursor=getElements(serv->outputs,mcursor->name); |
---|
[9] | 1330 | printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
| 1331 | mcursor=mcursor->next; |
---|
| 1332 | } |
---|
| 1333 | xmlAddChild(n,nc); |
---|
| 1334 | } |
---|
| 1335 | #ifdef DEBUG |
---|
| 1336 | fprintf(stderr,"printProcessResponse 1 190\n"); |
---|
| 1337 | #endif |
---|
| 1338 | |
---|
| 1339 | /** |
---|
| 1340 | * Display the process output only when requested ! |
---|
| 1341 | */ |
---|
| 1342 | if(status==SERVICE_SUCCEEDED){ |
---|
| 1343 | nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); |
---|
| 1344 | maps* mcursor=outputs; |
---|
| 1345 | elements* scursor=serv->outputs; |
---|
[63] | 1346 | while(mcursor!=NULL){ |
---|
[65] | 1347 | scursor=getElements(serv->outputs,mcursor->name); |
---|
[280] | 1348 | if(scursor!=NULL){ |
---|
| 1349 | printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); |
---|
| 1350 | } |
---|
[9] | 1351 | mcursor=mcursor->next; |
---|
| 1352 | } |
---|
| 1353 | xmlAddChild(n,nc); |
---|
| 1354 | } |
---|
| 1355 | #ifdef DEBUG |
---|
| 1356 | fprintf(stderr,"printProcessResponse 1 202\n"); |
---|
| 1357 | #endif |
---|
[280] | 1358 | nr=soapEnvelope(m,n); |
---|
| 1359 | xmlDocSetRootElement(doc, nr); |
---|
| 1360 | |
---|
[76] | 1361 | if(hasStoredExecuteResponse==true){ |
---|
[72] | 1362 | /* We need to write the ExecuteResponse Document somewhere */ |
---|
| 1363 | FILE* output=fopen(stored_path,"w"); |
---|
| 1364 | xmlChar *xmlbuff; |
---|
| 1365 | int buffersize; |
---|
| 1366 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); |
---|
[216] | 1367 | fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output); |
---|
[72] | 1368 | xmlFree(xmlbuff); |
---|
| 1369 | fclose(output); |
---|
| 1370 | } |
---|
[9] | 1371 | printDocument(m,doc,pid); |
---|
| 1372 | |
---|
| 1373 | xmlCleanupParser(); |
---|
| 1374 | zooXmlCleanupNs(); |
---|
| 1375 | } |
---|
| 1376 | |
---|
| 1377 | |
---|
| 1378 | void printDocument(maps* m, xmlDocPtr doc,int pid){ |
---|
| 1379 | char *encoding=getEncoding(m); |
---|
| 1380 | if(pid==getpid()){ |
---|
| 1381 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1382 | } |
---|
| 1383 | fflush(stdout); |
---|
| 1384 | xmlChar *xmlbuff; |
---|
| 1385 | int buffersize; |
---|
[1] | 1386 | /* |
---|
[9] | 1387 | * Dump the document to a buffer and print it on stdout |
---|
[1] | 1388 | * for demonstration purposes. |
---|
| 1389 | */ |
---|
[9] | 1390 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
[114] | 1391 | printf("%s",xmlbuff); |
---|
[216] | 1392 | fflush(stdout); |
---|
[1] | 1393 | /* |
---|
| 1394 | * Free associated memory. |
---|
| 1395 | */ |
---|
| 1396 | xmlFree(xmlbuff); |
---|
[9] | 1397 | xmlFreeDoc(doc); |
---|
| 1398 | xmlCleanupParser(); |
---|
| 1399 | zooXmlCleanupNs(); |
---|
[1] | 1400 | } |
---|
| 1401 | |
---|
[114] | 1402 | void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){ |
---|
[1] | 1403 | xmlNodePtr nc1; |
---|
| 1404 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
| 1405 | map *tmp=NULL; |
---|
| 1406 | if(e!=NULL && e->defaults!=NULL) |
---|
| 1407 | tmp=e->defaults->content; |
---|
| 1408 | else{ |
---|
| 1409 | /* |
---|
| 1410 | dumpElements(e); |
---|
| 1411 | */ |
---|
| 1412 | return; |
---|
| 1413 | } |
---|
| 1414 | while(tmp!=NULL){ |
---|
[9] | 1415 | if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 |
---|
| 1416 | || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 |
---|
| 1417 | || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 |
---|
| 1418 | || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) |
---|
[1] | 1419 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1420 | tmp=tmp->next; |
---|
| 1421 | } |
---|
| 1422 | tmp=getMap(e->defaults->content,"asReference"); |
---|
| 1423 | if(tmp==NULL) |
---|
| 1424 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
| 1425 | |
---|
| 1426 | tmp=e->content; |
---|
| 1427 | |
---|
| 1428 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
| 1429 | |
---|
| 1430 | xmlAddChild(nc,nc1); |
---|
| 1431 | |
---|
| 1432 | } |
---|
| 1433 | |
---|
[114] | 1434 | void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){ |
---|
[1] | 1435 | xmlNodePtr nc1,nc2,nc3; |
---|
| 1436 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
| 1437 | map *tmp=NULL; |
---|
| 1438 | if(e!=NULL && e->defaults!=NULL) |
---|
| 1439 | tmp=e->defaults->content; |
---|
| 1440 | else{ |
---|
| 1441 | /* |
---|
| 1442 | dumpElements(e); |
---|
| 1443 | */ |
---|
| 1444 | return; |
---|
| 1445 | } |
---|
| 1446 | while(tmp!=NULL){ |
---|
| 1447 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1448 | tmp=tmp->next; |
---|
| 1449 | } |
---|
| 1450 | tmp=getMap(e->defaults->content,"asReference"); |
---|
| 1451 | if(tmp==NULL) |
---|
| 1452 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
| 1453 | |
---|
| 1454 | tmp=e->content; |
---|
| 1455 | |
---|
| 1456 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
| 1457 | |
---|
| 1458 | xmlAddChild(nc,nc1); |
---|
| 1459 | |
---|
| 1460 | } |
---|
| 1461 | |
---|
[114] | 1462 | void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){ |
---|
[1] | 1463 | xmlNodePtr nc1,nc2,nc3; |
---|
| 1464 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
[65] | 1465 | map *tmp=NULL; |
---|
| 1466 | if(e!=NULL) |
---|
| 1467 | tmp=e->content; |
---|
| 1468 | else |
---|
| 1469 | tmp=m->content; |
---|
[26] | 1470 | #ifdef DEBUG |
---|
[1] | 1471 | dumpMap(tmp); |
---|
| 1472 | dumpElements(e); |
---|
[26] | 1473 | #endif |
---|
[1] | 1474 | nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
[65] | 1475 | if(e!=NULL) |
---|
| 1476 | nc3=xmlNewText(BAD_CAST e->name); |
---|
| 1477 | else |
---|
| 1478 | nc3=xmlNewText(BAD_CAST m->name); |
---|
[9] | 1479 | xmlAddChild(nc2,nc3); |
---|
[1] | 1480 | xmlAddChild(nc1,nc2); |
---|
| 1481 | xmlAddChild(nc,nc1); |
---|
[9] | 1482 | // Extract Title required to be first element in the ZCFG file ! |
---|
[65] | 1483 | bool isTitle=true; |
---|
| 1484 | if(e!=NULL) |
---|
| 1485 | tmp=getMap(e->content,"Title"); |
---|
| 1486 | else |
---|
| 1487 | tmp=getMap(m->content,"Title"); |
---|
| 1488 | |
---|
| 1489 | if(tmp!=NULL){ |
---|
[43] | 1490 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
| 1491 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
| 1492 | xmlAddChild(nc2,nc3); |
---|
| 1493 | xmlAddChild(nc1,nc2); |
---|
[65] | 1494 | } |
---|
| 1495 | |
---|
| 1496 | if(e!=NULL) |
---|
| 1497 | tmp=getMap(e->content,"Abstract"); |
---|
| 1498 | else |
---|
| 1499 | tmp=getMap(m->content,"Abstract"); |
---|
| 1500 | if(tmp!=NULL){ |
---|
| 1501 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
| 1502 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
| 1503 | xmlAddChild(nc2,nc3); |
---|
| 1504 | xmlAddChild(nc1,nc2); |
---|
[43] | 1505 | xmlAddChild(nc,nc1); |
---|
| 1506 | } |
---|
[1] | 1507 | |
---|
| 1508 | /** |
---|
| 1509 | * IO type Reference or full Data ? |
---|
| 1510 | */ |
---|
[26] | 1511 | #ifdef DEBUG |
---|
[9] | 1512 | fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); |
---|
[26] | 1513 | #endif |
---|
[9] | 1514 | map *tmpMap=getMap(m->content,"Reference"); |
---|
| 1515 | if(tmpMap==NULL){ |
---|
| 1516 | nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); |
---|
[65] | 1517 | if(e!=NULL){ |
---|
[76] | 1518 | if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0) |
---|
[65] | 1519 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
[9] | 1520 | else |
---|
[76] | 1521 | if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) |
---|
[65] | 1522 | nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); |
---|
[76] | 1523 | else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0) |
---|
| 1524 | nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); |
---|
[65] | 1525 | else |
---|
| 1526 | nc3=xmlNewNode(ns_wps, BAD_CAST e->format); |
---|
| 1527 | } |
---|
| 1528 | else{ |
---|
| 1529 | map* tmpV=getMapFromMaps(m,"format","value"); |
---|
| 1530 | if(tmpV!=NULL) |
---|
| 1531 | nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); |
---|
| 1532 | else |
---|
| 1533 | nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData"); |
---|
[76] | 1534 | } |
---|
[9] | 1535 | tmp=m->content; |
---|
[297] | 1536 | #ifdef USE_MS |
---|
| 1537 | map* testMap=getMap(tmp,"requestedMimeType"); |
---|
| 1538 | #endif |
---|
[9] | 1539 | while(tmp!=NULL){ |
---|
[70] | 1540 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
| 1541 | strcasecmp(tmp->name,"encoding")==0 || |
---|
| 1542 | strcasecmp(tmp->name,"schema")==0 || |
---|
| 1543 | strcasecmp(tmp->name,"datatype")==0 || |
---|
| 1544 | strcasecmp(tmp->name,"uom")==0) |
---|
[297] | 1545 | #ifdef USE_MS |
---|
[299] | 1546 | if(testMap==NULL || (testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)==0)){ |
---|
[297] | 1547 | #endif |
---|
[9] | 1548 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
[297] | 1549 | #ifdef USE_MS |
---|
[299] | 1550 | } |
---|
| 1551 | else |
---|
| 1552 | if(strcasecmp(tmp->name,"mimeType")==0) |
---|
| 1553 | if(testMap!=NULL) |
---|
| 1554 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); |
---|
| 1555 | else |
---|
| 1556 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
[297] | 1557 | #endif |
---|
[9] | 1558 | tmp=tmp->next; |
---|
| 1559 | xmlAddChild(nc2,nc3); |
---|
[1] | 1560 | } |
---|
[76] | 1561 | if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ |
---|
| 1562 | map* bb=getMap(m->content,"value"); |
---|
| 1563 | if(bb!=NULL){ |
---|
| 1564 | map* tmpRes=parseBoundingBox(bb->value); |
---|
| 1565 | printBoundingBox(ns_ows,nc3,tmpRes); |
---|
| 1566 | freeMap(&tmpRes); |
---|
| 1567 | free(tmpRes); |
---|
[9] | 1568 | } |
---|
[76] | 1569 | }else{ |
---|
| 1570 | if(e!=NULL) |
---|
| 1571 | tmp=getMap(e->defaults->content,"mimeType"); |
---|
| 1572 | else |
---|
| 1573 | tmp=NULL; |
---|
[297] | 1574 | #ifdef USE_MS |
---|
| 1575 | /** |
---|
| 1576 | * In case of OGC WebServices output use, as the data was requested |
---|
| 1577 | * with asReference=false we have to download the resulting OWS request |
---|
| 1578 | * stored in the Reference map value. |
---|
| 1579 | */ |
---|
| 1580 | map* testMap=getMap(m->content,"requestedMimeType"); |
---|
| 1581 | if(testMap!=NULL){ |
---|
| 1582 | HINTERNET hInternet; |
---|
| 1583 | hInternet=InternetOpen( |
---|
| 1584 | #ifndef WIN32 |
---|
| 1585 | (LPCTSTR) |
---|
| 1586 | #endif |
---|
| 1587 | "ZooWPSClient\0", |
---|
| 1588 | INTERNET_OPEN_TYPE_PRECONFIG, |
---|
| 1589 | NULL,NULL, 0); |
---|
| 1590 | testMap=getMap(m->content,"Reference"); |
---|
| 1591 | loadRemoteFile(m,m->content,hInternet,testMap->value); |
---|
| 1592 | InternetCloseHandle(hInternet); |
---|
| 1593 | } |
---|
| 1594 | #endif |
---|
[76] | 1595 | map* tmp1=getMap(m->content,"encoding"); |
---|
| 1596 | map* tmp2=getMap(m->content,"mimeType"); |
---|
| 1597 | map* toto=getMap(m->content,"value"); |
---|
| 1598 | if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) |
---|
| 1599 | || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 || |
---|
| 1600 | (strncmp(tmp2->value,"application/",12)==0) && |
---|
[279] | 1601 | strncmp(tmp2->value,"application/json",16)!=0&& |
---|
| 1602 | strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0) |
---|
| 1603 | )) { |
---|
[76] | 1604 | map* rs=getMap(m->content,"size"); |
---|
| 1605 | bool isSized=true; |
---|
| 1606 | if(rs==NULL){ |
---|
| 1607 | char tmp1[1024]; |
---|
| 1608 | sprintf(tmp1,"%d",strlen(toto->value)); |
---|
[280] | 1609 | rs=createMap("size",tmp1); |
---|
[76] | 1610 | isSized=false; |
---|
| 1611 | } |
---|
[94] | 1612 | |
---|
| 1613 | xmlAddChild(nc3,xmlNewText(BAD_CAST base64(toto->value, atoi(rs->value)))); |
---|
[76] | 1614 | if(!isSized){ |
---|
| 1615 | freeMap(&rs); |
---|
| 1616 | free(rs); |
---|
| 1617 | } |
---|
[59] | 1618 | } |
---|
[280] | 1619 | else if(tmp2!=NULL){ |
---|
| 1620 | if(strncmp(tmp2->value,"text/js",7)==0 || |
---|
| 1621 | strncmp(tmp2->value,"application/json",16)==0) |
---|
[76] | 1622 | xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value))); |
---|
[280] | 1623 | else{ |
---|
| 1624 | if(strncmp(tmp2->value,"text/xml",8)==0 || |
---|
[307] | 1625 | strncmp(tmp2->value,"application/vnd.google-earth.kml",32)==0){ |
---|
[280] | 1626 | xmlDocPtr doc = |
---|
| 1627 | xmlParseMemory(BAD_CAST toto->value,strlen(BAD_CAST toto->value)); |
---|
| 1628 | xmlNodePtr ir = xmlDocGetRootElement(doc); |
---|
| 1629 | xmlAddChild(nc3,ir); |
---|
| 1630 | } |
---|
| 1631 | else |
---|
| 1632 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
| 1633 | } |
---|
[76] | 1634 | xmlAddChild(nc2,nc3); |
---|
| 1635 | } |
---|
[9] | 1636 | else |
---|
| 1637 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
| 1638 | } |
---|
[1] | 1639 | } |
---|
[9] | 1640 | else{ |
---|
[297] | 1641 | tmpMap=getMap(m->content,"Reference"); |
---|
[9] | 1642 | nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); |
---|
[76] | 1643 | if(strcasecmp(type,"Output")==0) |
---|
| 1644 | xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
| 1645 | else |
---|
| 1646 | xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
[9] | 1647 | tmp=m->content; |
---|
[297] | 1648 | #ifdef USE_MS |
---|
| 1649 | map* testMap=getMap(tmp,"requestedMimeType"); |
---|
| 1650 | #endif |
---|
[9] | 1651 | while(tmp!=NULL){ |
---|
[70] | 1652 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
| 1653 | strcasecmp(tmp->name,"encoding")==0 || |
---|
| 1654 | strcasecmp(tmp->name,"schema")==0 || |
---|
| 1655 | strcasecmp(tmp->name,"datatype")==0 || |
---|
| 1656 | strcasecmp(tmp->name,"uom")==0) |
---|
[297] | 1657 | #ifdef USE_MS |
---|
| 1658 | if(testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)!=0){ |
---|
| 1659 | if(strcasecmp(tmp->name,"mimeType")==0) |
---|
| 1660 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); |
---|
| 1661 | } |
---|
| 1662 | else |
---|
| 1663 | #endif |
---|
[9] | 1664 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1665 | tmp=tmp->next; |
---|
| 1666 | xmlAddChild(nc2,nc3); |
---|
| 1667 | } |
---|
[1] | 1668 | } |
---|
| 1669 | |
---|
| 1670 | xmlAddChild(nc1,nc2); |
---|
| 1671 | xmlAddChild(nc,nc1); |
---|
| 1672 | |
---|
| 1673 | } |
---|
| 1674 | |
---|
[114] | 1675 | void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){ |
---|
[1] | 1676 | xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
| 1677 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
| 1678 | xmlAddChild(root,nc2); |
---|
| 1679 | map* tmp=amap; |
---|
| 1680 | char *tmp2[2]; |
---|
| 1681 | tmp2[0]="Title"; |
---|
| 1682 | tmp2[1]="Abstract"; |
---|
| 1683 | int j=0; |
---|
| 1684 | for(j=0;j<2;j++){ |
---|
| 1685 | map* tmp1=getMap(tmp,tmp2[j]); |
---|
| 1686 | if(tmp1!=NULL){ |
---|
| 1687 | nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); |
---|
[34] | 1688 | xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); |
---|
[1] | 1689 | xmlAddChild(root,nc2); |
---|
| 1690 | } |
---|
| 1691 | } |
---|
| 1692 | } |
---|
| 1693 | |
---|
[9] | 1694 | char* getEncoding(maps* m){ |
---|
| 1695 | if(m!=NULL){ |
---|
| 1696 | map* tmp=getMap(m->content,"encoding"); |
---|
[1] | 1697 | if(tmp!=NULL){ |
---|
[9] | 1698 | return tmp->value; |
---|
[1] | 1699 | } |
---|
| 1700 | else |
---|
[9] | 1701 | return "UTF-8"; |
---|
[1] | 1702 | } |
---|
| 1703 | else |
---|
[9] | 1704 | return "UTF-8"; |
---|
| 1705 | } |
---|
[1] | 1706 | |
---|
[9] | 1707 | char* getVersion(maps* m){ |
---|
| 1708 | if(m!=NULL){ |
---|
| 1709 | map* tmp=getMap(m->content,"version"); |
---|
[1] | 1710 | if(tmp!=NULL){ |
---|
[9] | 1711 | return tmp->value; |
---|
[1] | 1712 | } |
---|
| 1713 | else |
---|
[9] | 1714 | return "1.0.0"; |
---|
[1] | 1715 | } |
---|
| 1716 | else |
---|
[9] | 1717 | return "1.0.0"; |
---|
| 1718 | } |
---|
[1] | 1719 | |
---|
[9] | 1720 | void printExceptionReportResponse(maps* m,map* s){ |
---|
| 1721 | int buffersize; |
---|
| 1722 | xmlDocPtr doc; |
---|
| 1723 | xmlChar *xmlbuff; |
---|
[34] | 1724 | xmlNodePtr n; |
---|
[1] | 1725 | |
---|
[9] | 1726 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1727 | maps* tmpMap=getMaps(m,"main"); |
---|
| 1728 | char *encoding=getEncoding(tmpMap); |
---|
[32] | 1729 | if(m!=NULL){ |
---|
| 1730 | map *tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
| 1731 | if(tmpSid!=NULL){ |
---|
| 1732 | if( getpid()==atoi(tmpSid->value) ) |
---|
| 1733 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1734 | } |
---|
| 1735 | else |
---|
| 1736 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1737 | }else |
---|
[26] | 1738 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
[34] | 1739 | n=createExceptionReportNode(m,s,1); |
---|
[1] | 1740 | xmlDocSetRootElement(doc, n); |
---|
[9] | 1741 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
| 1742 | printf("%s",xmlbuff); |
---|
| 1743 | fflush(stdout); |
---|
| 1744 | xmlFreeDoc(doc); |
---|
[1] | 1745 | xmlFree(xmlbuff); |
---|
[9] | 1746 | xmlCleanupParser(); |
---|
[57] | 1747 | zooXmlCleanupNs(); |
---|
[1] | 1748 | } |
---|
| 1749 | |
---|
[26] | 1750 | xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ |
---|
| 1751 | |
---|
| 1752 | int buffersize; |
---|
| 1753 | xmlChar *xmlbuff; |
---|
| 1754 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 1755 | xmlNodePtr n,nc,nc1,nc2; |
---|
[1] | 1756 | |
---|
[26] | 1757 | maps* tmpMap=getMaps(m,"main"); |
---|
| 1758 | |
---|
[216] | 1759 | int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
[57] | 1760 | ns=usedNs[nsid]; |
---|
[26] | 1761 | n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); |
---|
| 1762 | |
---|
| 1763 | if(use_ns==1){ |
---|
| 1764 | ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
| 1765 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 1766 | ns_xsi=usedNs[xsiId]; |
---|
| 1767 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 1768 | ns_xlink=usedNs[xlinkId]; |
---|
| 1769 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"); |
---|
| 1770 | } |
---|
[34] | 1771 | addLangAttr(n,m); |
---|
[26] | 1772 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); |
---|
| 1773 | |
---|
| 1774 | nc = xmlNewNode(ns, BAD_CAST "Exception"); |
---|
| 1775 | |
---|
| 1776 | map* tmp=getMap(s,"code"); |
---|
| 1777 | if(tmp!=NULL) |
---|
| 1778 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); |
---|
| 1779 | else |
---|
| 1780 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); |
---|
| 1781 | |
---|
| 1782 | tmp=getMap(s,"text"); |
---|
| 1783 | nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); |
---|
| 1784 | nc2=NULL; |
---|
| 1785 | if(tmp!=NULL){ |
---|
| 1786 | xmlNodeSetContent(nc1, BAD_CAST tmp->value); |
---|
| 1787 | } |
---|
| 1788 | else{ |
---|
[34] | 1789 | xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); |
---|
[26] | 1790 | } |
---|
| 1791 | xmlAddChild(nc,nc1); |
---|
| 1792 | xmlAddChild(n,nc); |
---|
| 1793 | return n; |
---|
| 1794 | } |
---|
| 1795 | |
---|
| 1796 | |
---|
[1] | 1797 | void outputResponse(service* s,maps* request_inputs,maps* request_outputs, |
---|
| 1798 | map* request_inputs1,int cpid,maps* m,int res){ |
---|
| 1799 | #ifdef DEBUG |
---|
| 1800 | dumpMaps(request_inputs); |
---|
| 1801 | dumpMaps(request_outputs); |
---|
| 1802 | fprintf(stderr,"printProcessResponse\n"); |
---|
| 1803 | #endif |
---|
| 1804 | map* toto=getMap(request_inputs1,"RawDataOutput"); |
---|
| 1805 | int asRaw=0; |
---|
| 1806 | if(toto!=NULL) |
---|
| 1807 | asRaw=1; |
---|
[9] | 1808 | |
---|
[92] | 1809 | map *_tmp=getMapFromMaps(m,"lenv","cookie"); |
---|
| 1810 | if(_tmp!=NULL){ |
---|
| 1811 | printf("Set-Cookie: %s\r\n",_tmp->value); |
---|
| 1812 | maps *tmpSess=getMaps(m,"senv"); |
---|
| 1813 | if(tmpSess!=NULL){ |
---|
| 1814 | char session_file_path[1024]; |
---|
| 1815 | map *tmpPath=getMapFromMaps(m,"main","sessPath"); |
---|
| 1816 | if(tmpPath==NULL) |
---|
| 1817 | tmpPath=getMapFromMaps(m,"main","tmpPath"); |
---|
| 1818 | char *tmp1=strtok(_tmp->value,";"); |
---|
| 1819 | if(tmp1!=NULL) |
---|
| 1820 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(tmp1,"=")+1); |
---|
| 1821 | else |
---|
| 1822 | sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,strstr(_tmp->value,"=")+1); |
---|
[254] | 1823 | dumpMapsToFile(tmpSess,session_file_path); |
---|
[92] | 1824 | } |
---|
| 1825 | } |
---|
[1] | 1826 | if(asRaw==0){ |
---|
[9] | 1827 | #ifdef DEBUG |
---|
| 1828 | fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); |
---|
| 1829 | dumpMaps(request_outputs); |
---|
| 1830 | #endif |
---|
[70] | 1831 | maps* tmpI=request_outputs; |
---|
| 1832 | while(tmpI!=NULL){ |
---|
[297] | 1833 | #ifdef USE_MS |
---|
| 1834 | map* testMap=getMap(tmpI->content,"useMapserver"); |
---|
| 1835 | #endif |
---|
[70] | 1836 | toto=getMap(tmpI->content,"asReference"); |
---|
[297] | 1837 | #ifdef USE_MS |
---|
| 1838 | if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL){ |
---|
| 1839 | #else |
---|
[70] | 1840 | if(toto!=NULL && strcasecmp(toto->value,"true")==0){ |
---|
[297] | 1841 | #endif |
---|
[76] | 1842 | elements* in=getElements(s->outputs,tmpI->name); |
---|
| 1843 | char *format=NULL; |
---|
| 1844 | if(in!=NULL){ |
---|
| 1845 | format=strdup(in->format); |
---|
| 1846 | }else |
---|
| 1847 | format=strdup("LiteralData"); |
---|
| 1848 | if(strcasecmp(format,"BoundingBoxData")==0){ |
---|
| 1849 | addToMap(tmpI->content,"extension","xml"); |
---|
| 1850 | addToMap(tmpI->content,"mimeType","text/xml"); |
---|
| 1851 | addToMap(tmpI->content,"encoding","UTF-8"); |
---|
| 1852 | addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); |
---|
| 1853 | } |
---|
| 1854 | map *ext=getMap(tmpI->content,"extension"); |
---|
[70] | 1855 | map *tmp1=getMapFromMaps(m,"main","tmpPath"); |
---|
| 1856 | char *file_name; |
---|
| 1857 | bool hasExt=true; |
---|
[76] | 1858 | if(ext==NULL){ |
---|
[70] | 1859 | // We can fallback to a default list of supported formats using |
---|
| 1860 | // mimeType information if present here. Maybe we can add more formats |
---|
| 1861 | // here. |
---|
| 1862 | // If mimeType was not found, we then set txt as the default extension. |
---|
| 1863 | map* mtype=getMap(tmpI->content,"mimeType"); |
---|
| 1864 | if(mtype!=NULL){ |
---|
| 1865 | if(strcasecmp(mtype->value,"text/xml")==0) |
---|
[76] | 1866 | ext=createMap("extension","xml"); |
---|
[70] | 1867 | else if(strcasecmp(mtype->value,"application/json")==0) |
---|
[76] | 1868 | ext=createMap("extension","js"); |
---|
[306] | 1869 | else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0) |
---|
[279] | 1870 | ext=createMap("extension","kml"); |
---|
[306] | 1871 | else if(strncmp(mtype->value,"image/",6)==0) |
---|
| 1872 | ext=createMap("extension",strstr(mtype->value,"/")+1); |
---|
[70] | 1873 | else |
---|
[76] | 1874 | ext=createMap("extension","txt"); |
---|
[70] | 1875 | } |
---|
[57] | 1876 | else |
---|
[76] | 1877 | ext=createMap("extension","txt"); |
---|
[70] | 1878 | hasExt=false; |
---|
[57] | 1879 | } |
---|
[76] | 1880 | file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char)); |
---|
| 1881 | sprintf(file_name,"%s/%s_%s_%i.%s",tmp1->value,s->name,tmpI->name,cpid+100000,ext->value); |
---|
[70] | 1882 | FILE *ofile=fopen(file_name,"w"); |
---|
| 1883 | if(ofile==NULL) |
---|
| 1884 | fprintf(stderr,"Unable to create file on disk implying segfault ! \n"); |
---|
| 1885 | map *tmp2=getMapFromMaps(m,"main","tmpUrl"); |
---|
| 1886 | map *tmp3=getMapFromMaps(m,"main","serverAddress"); |
---|
| 1887 | char *file_url; |
---|
[76] | 1888 | file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+13)*sizeof(char)); |
---|
| 1889 | sprintf(file_url,"%s/%s/%s_%s_%i.%s",tmp3->value,tmp2->value,s->name,tmpI->name,cpid+100000,ext->value); |
---|
[70] | 1890 | addToMap(tmpI->content,"Reference",file_url); |
---|
| 1891 | if(hasExt!=true){ |
---|
[76] | 1892 | freeMap(&ext); |
---|
| 1893 | free(ext); |
---|
[70] | 1894 | } |
---|
| 1895 | toto=getMap(tmpI->content,"value"); |
---|
[76] | 1896 | if(strcasecmp(format,"BoundingBoxData")!=0){ |
---|
| 1897 | map* size=getMap(tmpI->content,"size"); |
---|
| 1898 | if(size!=NULL && toto!=NULL) |
---|
| 1899 | fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile); |
---|
| 1900 | else |
---|
| 1901 | if(toto!=NULL && toto->value!=NULL) |
---|
| 1902 | fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); |
---|
| 1903 | }else{ |
---|
| 1904 | printBoundingBoxDocument(m,tmpI,ofile); |
---|
| 1905 | } |
---|
| 1906 | free(format); |
---|
[70] | 1907 | fclose(ofile); |
---|
| 1908 | free(file_name); |
---|
[76] | 1909 | free(file_url); |
---|
[52] | 1910 | } |
---|
[297] | 1911 | #ifdef USE_MS |
---|
| 1912 | else{ |
---|
| 1913 | if(testMap!=NULL){ |
---|
| 1914 | setReferenceUrl(m,tmpI); |
---|
| 1915 | } |
---|
| 1916 | } |
---|
| 1917 | #endif |
---|
[70] | 1918 | tmpI=tmpI->next; |
---|
[9] | 1919 | } |
---|
[1] | 1920 | map *r_inputs=getMap(s->content,"serviceProvider"); |
---|
| 1921 | #ifdef DEBUG |
---|
| 1922 | fprintf(stderr,"SERVICE : %s\n",r_inputs->value); |
---|
| 1923 | dumpMaps(m); |
---|
| 1924 | #endif |
---|
[9] | 1925 | printProcessResponse(m,request_inputs1,cpid, |
---|
[26] | 1926 | s,r_inputs->value,res, |
---|
| 1927 | request_inputs, |
---|
| 1928 | request_outputs); |
---|
[1] | 1929 | } |
---|
[26] | 1930 | else |
---|
| 1931 | if(res!=SERVICE_FAILED){ |
---|
| 1932 | /** |
---|
[66] | 1933 | * We get the requested output or fallback to the first one if the |
---|
| 1934 | * requested one is not present in the resulting outputs maps. |
---|
[26] | 1935 | */ |
---|
[66] | 1936 | maps* tmpI=NULL; |
---|
| 1937 | map* tmpIV=getMap(request_inputs1,"RawDataOutput"); |
---|
| 1938 | if(tmpIV!=NULL){ |
---|
| 1939 | tmpI=getMaps(request_outputs,tmpIV->value); |
---|
| 1940 | } |
---|
| 1941 | if(tmpI==NULL) |
---|
| 1942 | tmpI=request_outputs; |
---|
[76] | 1943 | elements* e=getElements(s->outputs,tmpI->name); |
---|
| 1944 | if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ |
---|
| 1945 | printBoundingBoxDocument(m,tmpI,NULL); |
---|
| 1946 | }else{ |
---|
| 1947 | toto=getMap(tmpI->content,"value"); |
---|
| 1948 | if(toto==NULL){ |
---|
| 1949 | char tmpMsg[1024]; |
---|
| 1950 | sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name); |
---|
| 1951 | map * errormap = createMap("text",tmpMsg); |
---|
| 1952 | addToMap(errormap,"code", "InvalidParameterValue"); |
---|
| 1953 | printExceptionReportResponse(m,errormap); |
---|
| 1954 | freeMap(&errormap); |
---|
| 1955 | free(errormap); |
---|
[114] | 1956 | return; |
---|
[76] | 1957 | } |
---|
| 1958 | char mime[1024]; |
---|
| 1959 | map* mi=getMap(tmpI->content,"mimeType"); |
---|
[1] | 1960 | #ifdef DEBUG |
---|
[76] | 1961 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
| 1962 | dumpMaps(request_outputs); |
---|
| 1963 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
[1] | 1964 | #endif |
---|
[76] | 1965 | map* en=getMap(tmpI->content,"encoding"); |
---|
| 1966 | if(mi!=NULL && en!=NULL) |
---|
[26] | 1967 | sprintf(mime, |
---|
[76] | 1968 | "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", |
---|
| 1969 | mi->value,en->value); |
---|
[26] | 1970 | else |
---|
[76] | 1971 | if(mi!=NULL) |
---|
| 1972 | sprintf(mime, |
---|
| 1973 | "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", |
---|
| 1974 | mi->value); |
---|
| 1975 | else |
---|
| 1976 | sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); |
---|
| 1977 | printf("%s",mime); |
---|
| 1978 | if(mi!=NULL && strncmp(mi->value,"image",5)==0){ |
---|
| 1979 | map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); |
---|
| 1980 | fwrite(toto->value,atoi(rs->value),1,stdout); |
---|
| 1981 | } |
---|
| 1982 | else |
---|
| 1983 | printf("%s",toto->value); |
---|
[1] | 1984 | #ifdef DEBUG |
---|
[76] | 1985 | dumpMap(toto); |
---|
[1] | 1986 | #endif |
---|
[76] | 1987 | } |
---|
[26] | 1988 | }else{ |
---|
| 1989 | char tmp[1024]; |
---|
| 1990 | map * errormap; |
---|
| 1991 | map *lenv; |
---|
| 1992 | lenv=getMapFromMaps(m,"lenv","message"); |
---|
| 1993 | if(lenv!=NULL) |
---|
[34] | 1994 | sprintf(tmp,_("Unable to run the Service. The message returned back by the Service was the following : %s"),lenv->value); |
---|
[26] | 1995 | else |
---|
[34] | 1996 | sprintf(tmp,_("Unable to run the Service. No more information was returned back by the Service.")); |
---|
[26] | 1997 | errormap = createMap("text",tmp); |
---|
| 1998 | addToMap(errormap,"code", "InternalError"); |
---|
| 1999 | printExceptionReportResponse(m,errormap); |
---|
| 2000 | freeMap(&errormap); |
---|
| 2001 | free(errormap); |
---|
| 2002 | } |
---|
[1] | 2003 | } |
---|
| 2004 | |
---|
[216] | 2005 | char *base64(const char *input, int length) |
---|
[1] | 2006 | { |
---|
| 2007 | BIO *bmem, *b64; |
---|
| 2008 | BUF_MEM *bptr; |
---|
| 2009 | |
---|
| 2010 | b64 = BIO_new(BIO_f_base64()); |
---|
[94] | 2011 | BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); |
---|
[1] | 2012 | bmem = BIO_new(BIO_s_mem()); |
---|
| 2013 | b64 = BIO_push(b64, bmem); |
---|
| 2014 | BIO_write(b64, input, length); |
---|
| 2015 | BIO_flush(b64); |
---|
| 2016 | BIO_get_mem_ptr(b64, &bptr); |
---|
| 2017 | |
---|
[94] | 2018 | char *buff = (char *)malloc((bptr->length)*sizeof(char)); |
---|
[1] | 2019 | memcpy(buff, bptr->data, bptr->length-1); |
---|
| 2020 | buff[bptr->length-1] = 0; |
---|
| 2021 | |
---|
| 2022 | BIO_free_all(b64); |
---|
| 2023 | |
---|
| 2024 | return buff; |
---|
| 2025 | } |
---|
| 2026 | |
---|
[216] | 2027 | char *base64d(const char *input, int length,int* red) |
---|
[88] | 2028 | { |
---|
| 2029 | BIO *b64, *bmem; |
---|
| 2030 | |
---|
| 2031 | char *buffer = (char *)malloc(length); |
---|
[94] | 2032 | if(buffer){ |
---|
| 2033 | memset(buffer, 0, length); |
---|
| 2034 | b64 = BIO_new(BIO_f_base64()); |
---|
| 2035 | if(b64){ |
---|
[216] | 2036 | bmem = BIO_new_mem_buf((unsigned char*)input,length); |
---|
[94] | 2037 | bmem = BIO_push(b64, bmem); |
---|
| 2038 | *red=BIO_read(bmem, buffer, length); |
---|
| 2039 | buffer[length-1]=0; |
---|
| 2040 | BIO_free_all(bmem); |
---|
| 2041 | } |
---|
| 2042 | } |
---|
[88] | 2043 | return buffer; |
---|
| 2044 | } |
---|
| 2045 | |
---|
| 2046 | void ensureDecodedBase64(maps **in){ |
---|
| 2047 | maps* cursor=*in; |
---|
| 2048 | while(cursor!=NULL){ |
---|
| 2049 | map *tmp=getMap(cursor->content,"encoding"); |
---|
| 2050 | if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ |
---|
| 2051 | tmp=getMap(cursor->content,"value"); |
---|
| 2052 | addToMap(cursor->content,"base64_value",tmp->value); |
---|
[94] | 2053 | int size=0; |
---|
[88] | 2054 | char *s=strdup(tmp->value); |
---|
| 2055 | free(tmp->value); |
---|
| 2056 | tmp->value=base64d(s,strlen(s),&size); |
---|
[94] | 2057 | free(s); |
---|
[88] | 2058 | char sizes[1024]; |
---|
| 2059 | sprintf(sizes,"%d",size); |
---|
| 2060 | addToMap(cursor->content,"size",sizes); |
---|
| 2061 | } |
---|
| 2062 | cursor=cursor->next; |
---|
| 2063 | } |
---|
| 2064 | } |
---|
| 2065 | |
---|
[63] | 2066 | char* addDefaultValues(maps** out,elements* in,maps* m,int type){ |
---|
[1] | 2067 | elements* tmpInputs=in; |
---|
| 2068 | maps* out1=*out; |
---|
[280] | 2069 | if(type==1){ |
---|
| 2070 | while(out1!=NULL){ |
---|
| 2071 | if(getElements(in,out1->name)==NULL) |
---|
| 2072 | return out1->name; |
---|
| 2073 | out1=out1->next; |
---|
| 2074 | } |
---|
| 2075 | out1=*out; |
---|
| 2076 | } |
---|
[1] | 2077 | while(tmpInputs!=NULL){ |
---|
| 2078 | maps *tmpMaps=getMaps(out1,tmpInputs->name); |
---|
| 2079 | if(tmpMaps==NULL){ |
---|
[9] | 2080 | maps* tmpMaps2=(maps*)malloc(MAPS_SIZE); |
---|
[57] | 2081 | tmpMaps2->name=strdup(tmpInputs->name); |
---|
[9] | 2082 | tmpMaps2->content=NULL; |
---|
| 2083 | tmpMaps2->next=NULL; |
---|
[63] | 2084 | |
---|
| 2085 | if(type==0){ |
---|
| 2086 | map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs"); |
---|
| 2087 | if(tmpMapMinO!=NULL) |
---|
| 2088 | if(atoi(tmpMapMinO->value)>=1){ |
---|
| 2089 | freeMaps(&tmpMaps2); |
---|
| 2090 | free(tmpMaps2); |
---|
| 2091 | return tmpInputs->name; |
---|
| 2092 | } |
---|
| 2093 | else{ |
---|
| 2094 | if(tmpMaps2->content==NULL) |
---|
| 2095 | tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value); |
---|
| 2096 | else |
---|
| 2097 | addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value); |
---|
| 2098 | } |
---|
| 2099 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
| 2100 | if(tmpMaxO!=NULL) |
---|
| 2101 | if(tmpMaps2->content==NULL) |
---|
| 2102 | tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); |
---|
| 2103 | else |
---|
| 2104 | addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); |
---|
| 2105 | } |
---|
| 2106 | |
---|
[1] | 2107 | iotype* tmpIoType=tmpInputs->defaults; |
---|
[63] | 2108 | if(tmpIoType!=NULL){ |
---|
| 2109 | map* tmpm=tmpIoType->content; |
---|
| 2110 | while(tmpm!=NULL){ |
---|
| 2111 | if(tmpMaps2->content==NULL) |
---|
| 2112 | tmpMaps2->content=createMap(tmpm->name,tmpm->value); |
---|
| 2113 | else |
---|
| 2114 | addToMap(tmpMaps2->content,tmpm->name,tmpm->value); |
---|
| 2115 | tmpm=tmpm->next; |
---|
| 2116 | } |
---|
[1] | 2117 | } |
---|
[88] | 2118 | addToMap(tmpMaps2->content,"inRequest","false"); |
---|
[93] | 2119 | if(type==0){ |
---|
[57] | 2120 | map *tmpMap=getMap(tmpMaps2->content,"value"); |
---|
| 2121 | if(tmpMap==NULL) |
---|
| 2122 | addToMap(tmpMaps2->content,"value","NULL"); |
---|
| 2123 | } |
---|
[1] | 2124 | if(out1==NULL){ |
---|
[9] | 2125 | *out=dupMaps(&tmpMaps2); |
---|
[63] | 2126 | out1=*out; |
---|
[1] | 2127 | } |
---|
| 2128 | else |
---|
[9] | 2129 | addMapsToMaps(&out1,tmpMaps2); |
---|
[63] | 2130 | freeMap(&tmpMaps2->content); |
---|
| 2131 | free(tmpMaps2->content); |
---|
| 2132 | tmpMaps2->content=NULL; |
---|
[9] | 2133 | freeMaps(&tmpMaps2); |
---|
| 2134 | free(tmpMaps2); |
---|
| 2135 | tmpMaps2=NULL; |
---|
[1] | 2136 | } |
---|
| 2137 | else{ |
---|
[57] | 2138 | iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name, |
---|
| 2139 | tmpMaps->content); |
---|
[63] | 2140 | if(type==0) { |
---|
[76] | 2141 | /** |
---|
| 2142 | * In case of an Input maps, then add the minOccurs and maxOccurs to the |
---|
| 2143 | * content map. |
---|
| 2144 | */ |
---|
[63] | 2145 | map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); |
---|
| 2146 | if(tmpMap1!=NULL){ |
---|
| 2147 | if(tmpMaps->content==NULL) |
---|
| 2148 | tmpMaps->content=createMap("minOccurs",tmpMap1->value); |
---|
| 2149 | else |
---|
| 2150 | addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); |
---|
| 2151 | } |
---|
| 2152 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
| 2153 | if(tmpMaxO!=NULL){ |
---|
| 2154 | if(tmpMaps->content==NULL) |
---|
| 2155 | tmpMaps->content=createMap("maxOccurs",tmpMap1->value); |
---|
| 2156 | else |
---|
| 2157 | addToMap(tmpMaps->content,"maxOccurs",tmpMap1->value); |
---|
| 2158 | } |
---|
[76] | 2159 | /** |
---|
| 2160 | * Parsing BoundingBoxData, fill the following map and then add it to |
---|
| 2161 | * the content map of the Input maps: |
---|
| 2162 | * lowerCorner, upperCorner, srs and dimensions |
---|
| 2163 | * cf. parseBoundingBox |
---|
| 2164 | */ |
---|
| 2165 | if(strcasecmp(tmpInputs->format,"BoundingBoxData")==0){ |
---|
| 2166 | maps* tmpI=getMaps(*out,tmpInputs->name); |
---|
| 2167 | if(tmpI!=NULL){ |
---|
| 2168 | map* tmpV=getMap(tmpI->content,"value"); |
---|
| 2169 | if(tmpV!=NULL){ |
---|
| 2170 | char *tmpVS=strdup(tmpV->value); |
---|
| 2171 | map* tmp=parseBoundingBox(tmpVS); |
---|
| 2172 | free(tmpVS); |
---|
| 2173 | map* tmpC=tmp; |
---|
| 2174 | while(tmpC!=NULL){ |
---|
| 2175 | addToMap(tmpMaps->content,tmpC->name,tmpC->value); |
---|
| 2176 | tmpC=tmpC->next; |
---|
| 2177 | } |
---|
| 2178 | freeMap(&tmp); |
---|
| 2179 | free(tmp); |
---|
| 2180 | } |
---|
| 2181 | } |
---|
| 2182 | } |
---|
[63] | 2183 | } |
---|
| 2184 | |
---|
[57] | 2185 | if(tmpIoType!=NULL){ |
---|
| 2186 | map* tmpContent=tmpIoType->content; |
---|
| 2187 | map* cval=NULL; |
---|
| 2188 | |
---|
| 2189 | while(tmpContent!=NULL){ |
---|
| 2190 | if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){ |
---|
[9] | 2191 | #ifdef DEBUG |
---|
[57] | 2192 | fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value); |
---|
[9] | 2193 | #endif |
---|
[63] | 2194 | if(tmpMaps->content==NULL) |
---|
| 2195 | tmpMaps->content=createMap(tmpContent->name,tmpContent->value); |
---|
| 2196 | else |
---|
| 2197 | addToMap(tmpMaps->content,tmpContent->name,tmpContent->value); |
---|
[57] | 2198 | } |
---|
| 2199 | tmpContent=tmpContent->next; |
---|
[9] | 2200 | } |
---|
[297] | 2201 | #ifdef USE_MS |
---|
| 2202 | /** |
---|
| 2203 | * check for useMapServer presence |
---|
| 2204 | */ |
---|
| 2205 | map* tmpCheck=getMap(tmpIoType->content,"useMapServer"); |
---|
| 2206 | if(tmpCheck!=NULL){ |
---|
| 2207 | // Get the default value |
---|
| 2208 | tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL); |
---|
| 2209 | tmpCheck=getMap(tmpMaps->content,"mimeType"); |
---|
| 2210 | addToMap(tmpMaps->content,"requestedMimeType",tmpCheck->value); |
---|
| 2211 | map* cursor=tmpIoType->content; |
---|
| 2212 | while(cursor!=NULL){ |
---|
| 2213 | addToMap(tmpMaps->content,cursor->name,cursor->value); |
---|
| 2214 | cursor=cursor->next; |
---|
| 2215 | } |
---|
| 2216 | |
---|
| 2217 | cursor=tmpInputs->content; |
---|
| 2218 | while(cursor!=NULL){ |
---|
| 2219 | if(strcasecmp(cursor->name,"Title")==0 || |
---|
| 2220 | strcasecmp(cursor->name,"Abstract")==0) |
---|
| 2221 | addToMap(tmpMaps->content,cursor->name,cursor->value); |
---|
| 2222 | cursor=cursor->next; |
---|
| 2223 | } |
---|
| 2224 | } |
---|
| 2225 | #endif |
---|
[1] | 2226 | } |
---|
[92] | 2227 | if(tmpMaps->content==NULL) |
---|
| 2228 | tmpMaps->content=createMap("inRequest","true"); |
---|
| 2229 | else |
---|
| 2230 | addToMap(tmpMaps->content,"inRequest","true"); |
---|
[280] | 2231 | |
---|
[1] | 2232 | } |
---|
| 2233 | tmpInputs=tmpInputs->next; |
---|
| 2234 | } |
---|
[9] | 2235 | return ""; |
---|
[1] | 2236 | } |
---|
[76] | 2237 | |
---|
| 2238 | /** |
---|
| 2239 | * parseBoundingBox : parse a BoundingBox string |
---|
| 2240 | * |
---|
| 2241 | * OGC 06-121r3 : 10.2 Bounding box |
---|
| 2242 | * |
---|
| 2243 | * value is provided as : lowerCorner,upperCorner,crs,dimension |
---|
| 2244 | * exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84 |
---|
| 2245 | * |
---|
| 2246 | * Need to create a map to store boundingbox informations : |
---|
| 2247 | * - lowerCorner : double,double (minimum within this bounding box) |
---|
| 2248 | * - upperCorner : double,double (maximum within this bounding box) |
---|
| 2249 | * - crs : URI (Reference to definition of the CRS) |
---|
| 2250 | * - dimensions : int |
---|
| 2251 | * |
---|
| 2252 | * Note : support only 2D bounding box. |
---|
| 2253 | */ |
---|
[114] | 2254 | map* parseBoundingBox(const char* value){ |
---|
[76] | 2255 | map *res=NULL; |
---|
| 2256 | if(value!=NULL){ |
---|
| 2257 | char *cv,*cvp; |
---|
[114] | 2258 | cv=strtok_r((char*) value,",",&cvp); |
---|
[76] | 2259 | int cnt=0; |
---|
| 2260 | int icnt=0; |
---|
| 2261 | char *currentValue=NULL; |
---|
| 2262 | while(cv){ |
---|
| 2263 | if(cnt<2) |
---|
| 2264 | if(currentValue!=NULL){ |
---|
| 2265 | char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char)); |
---|
| 2266 | sprintf(finalValue,"%s%s",currentValue,cv); |
---|
| 2267 | switch(cnt){ |
---|
| 2268 | case 0: |
---|
| 2269 | res=createMap("lowerCorner",finalValue); |
---|
| 2270 | break; |
---|
| 2271 | case 1: |
---|
| 2272 | addToMap(res,"upperCorner",finalValue); |
---|
| 2273 | icnt=-1; |
---|
| 2274 | break; |
---|
| 2275 | } |
---|
| 2276 | cnt++; |
---|
| 2277 | free(currentValue); |
---|
| 2278 | currentValue=NULL; |
---|
| 2279 | free(finalValue); |
---|
| 2280 | } |
---|
| 2281 | else{ |
---|
| 2282 | currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char)); |
---|
| 2283 | sprintf(currentValue,"%s ",cv); |
---|
| 2284 | } |
---|
| 2285 | else |
---|
| 2286 | if(cnt==2){ |
---|
| 2287 | addToMap(res,"crs",cv); |
---|
| 2288 | cnt++; |
---|
| 2289 | } |
---|
| 2290 | else |
---|
| 2291 | addToMap(res,"dimensions",cv); |
---|
| 2292 | icnt++; |
---|
| 2293 | cv=strtok_r(NULL,",",&cvp); |
---|
| 2294 | } |
---|
| 2295 | } |
---|
| 2296 | return res; |
---|
| 2297 | } |
---|
| 2298 | |
---|
| 2299 | /** |
---|
| 2300 | * printBoundingBox : fill a BoundingBox node (ows:BoundingBox or |
---|
| 2301 | * wps:BoundingBoxData). Set crs and dimensions attributes, add |
---|
| 2302 | * Lower/UpperCorner nodes to a pre-existing XML node. |
---|
| 2303 | */ |
---|
| 2304 | void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){ |
---|
| 2305 | |
---|
| 2306 | xmlNodePtr bb,lw,uc; |
---|
| 2307 | |
---|
| 2308 | map* tmp=getMap(boundingbox,"value"); |
---|
| 2309 | |
---|
| 2310 | tmp=getMap(boundingbox,"lowerCorner"); |
---|
| 2311 | if(tmp!=NULL){ |
---|
| 2312 | lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner"); |
---|
| 2313 | xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value)); |
---|
| 2314 | } |
---|
| 2315 | |
---|
| 2316 | tmp=getMap(boundingbox,"upperCorner"); |
---|
| 2317 | if(tmp!=NULL){ |
---|
| 2318 | uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner"); |
---|
| 2319 | xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value)); |
---|
| 2320 | } |
---|
| 2321 | |
---|
| 2322 | tmp=getMap(boundingbox,"crs"); |
---|
| 2323 | if(tmp!=NULL) |
---|
| 2324 | xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value); |
---|
| 2325 | |
---|
| 2326 | tmp=getMap(boundingbox,"dimensions"); |
---|
| 2327 | if(tmp!=NULL) |
---|
| 2328 | xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value); |
---|
| 2329 | |
---|
| 2330 | xmlAddChild(n,lw); |
---|
| 2331 | xmlAddChild(n,uc); |
---|
| 2332 | |
---|
| 2333 | } |
---|
| 2334 | |
---|
| 2335 | void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){ |
---|
| 2336 | if(file==NULL) |
---|
| 2337 | rewind(stdout); |
---|
| 2338 | xmlNodePtr n; |
---|
| 2339 | xmlDocPtr doc; |
---|
| 2340 | xmlNsPtr ns_ows,ns_xsi; |
---|
| 2341 | xmlChar *xmlbuff; |
---|
| 2342 | int buffersize; |
---|
| 2343 | char *encoding=getEncoding(m); |
---|
| 2344 | map *tmp; |
---|
| 2345 | if(file==NULL){ |
---|
| 2346 | int pid=0; |
---|
| 2347 | tmp=getMapFromMaps(m,"lenv","sid"); |
---|
| 2348 | if(tmp!=NULL) |
---|
| 2349 | pid=atoi(tmp->value); |
---|
| 2350 | if(pid==getpid()){ |
---|
| 2351 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 2352 | } |
---|
| 2353 | fflush(stdout); |
---|
| 2354 | } |
---|
| 2355 | |
---|
| 2356 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 2357 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 2358 | ns_ows=usedNs[owsId]; |
---|
| 2359 | n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox"); |
---|
[216] | 2360 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
[76] | 2361 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 2362 | ns_xsi=usedNs[xsiId]; |
---|
| 2363 | xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); |
---|
| 2364 | map *tmp1=getMap(boundingbox->content,"value"); |
---|
| 2365 | tmp=parseBoundingBox(tmp1->value); |
---|
| 2366 | printBoundingBox(ns_ows,n,tmp); |
---|
| 2367 | xmlDocSetRootElement(doc, n); |
---|
| 2368 | |
---|
| 2369 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
| 2370 | if(file==NULL) |
---|
[114] | 2371 | printf("%s",xmlbuff); |
---|
[76] | 2372 | else{ |
---|
| 2373 | fprintf(file,"%s",xmlbuff); |
---|
| 2374 | } |
---|
| 2375 | |
---|
| 2376 | if(tmp!=NULL){ |
---|
| 2377 | freeMap(&tmp); |
---|
| 2378 | free(tmp); |
---|
| 2379 | } |
---|
| 2380 | xmlFree(xmlbuff); |
---|
| 2381 | xmlFreeDoc(doc); |
---|
| 2382 | xmlCleanupParser(); |
---|
| 2383 | zooXmlCleanupNs(); |
---|
| 2384 | |
---|
| 2385 | } |
---|
[280] | 2386 | |
---|
[281] | 2387 | |
---|
[291] | 2388 | unsigned char* getMd5(char* url){ |
---|
| 2389 | EVP_MD_CTX md5ctx; |
---|
| 2390 | unsigned char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); |
---|
| 2391 | unsigned char result[EVP_MAX_MD_SIZE]; |
---|
| 2392 | unsigned int len; |
---|
| 2393 | EVP_DigestInit(&md5ctx, EVP_md5()); |
---|
| 2394 | EVP_DigestUpdate(&md5ctx, url, strlen(url)); |
---|
| 2395 | EVP_DigestFinal_ex(&md5ctx,result,&len); |
---|
| 2396 | EVP_MD_CTX_cleanup(&md5ctx); |
---|
| 2397 | int i; |
---|
| 2398 | for(i = 0; i < len; i++){ |
---|
| 2399 | if(i>0){ |
---|
| 2400 | char *tmp=strdup(fresult); |
---|
| 2401 | sprintf(fresult,"%s%02x", tmp,result[i]); |
---|
| 2402 | free(tmp); |
---|
| 2403 | } |
---|
| 2404 | else |
---|
| 2405 | sprintf(fresult,"%02x",result[i]); |
---|
| 2406 | } |
---|
| 2407 | return fresult; |
---|
| 2408 | } |
---|
| 2409 | |
---|
[280] | 2410 | /** |
---|
| 2411 | * Cache a file for a given request |
---|
| 2412 | */ |
---|
| 2413 | void addToCache(maps* conf,char* request,char* content,int length){ |
---|
| 2414 | map* tmp=getMapFromMaps(conf,"main","cacheDir"); |
---|
| 2415 | if(tmp!=NULL){ |
---|
[292] | 2416 | unsigned char* md5str=getMd5(request); |
---|
| 2417 | char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); |
---|
| 2418 | sprintf(fname,"%s/%s.zca",tmp->value,md5str); |
---|
[291] | 2419 | #ifdef DEBUG |
---|
[280] | 2420 | fprintf(stderr,"Cache list : %s\n",fname); |
---|
| 2421 | fflush(stderr); |
---|
[291] | 2422 | #endif |
---|
[293] | 2423 | FILE* fo=fopen(fname,"w+"); |
---|
| 2424 | fwrite(content,sizeof(char),length,fo); |
---|
| 2425 | fclose(fo); |
---|
| 2426 | free(md5str); |
---|
| 2427 | free(fname); |
---|
[280] | 2428 | } |
---|
| 2429 | } |
---|
| 2430 | |
---|
| 2431 | char* isInCache(maps* conf,char* request){ |
---|
[291] | 2432 | map* tmpM=getMapFromMaps(conf,"main","cacheDir"); |
---|
| 2433 | if(tmpM!=NULL){ |
---|
| 2434 | unsigned char* md5str=getMd5(request); |
---|
| 2435 | #ifdef DEBUG |
---|
| 2436 | fprintf(stderr,"MD5STR : (%s)\n\n",md5str); |
---|
| 2437 | #endif |
---|
[292] | 2438 | char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38)); |
---|
| 2439 | sprintf(fname,"%s/%s.zca",tmpM->value,md5str); |
---|
[280] | 2440 | struct stat f_status; |
---|
| 2441 | int s=stat(fname, &f_status); |
---|
[292] | 2442 | if(s==0 && f_status.st_size>0){ |
---|
| 2443 | free(md5str); |
---|
| 2444 | return fname; |
---|
| 2445 | } |
---|
[291] | 2446 | free(md5str); |
---|
| 2447 | free(fname); |
---|
[280] | 2448 | } |
---|
| 2449 | return NULL; |
---|
| 2450 | } |
---|
[281] | 2451 | |
---|
| 2452 | /** |
---|
| 2453 | * loadRemoteFile: |
---|
| 2454 | * Try to load file from cache or download a remote file if not in cache |
---|
| 2455 | */ |
---|
| 2456 | void loadRemoteFile(maps* m,map* content,HINTERNET hInternet,char *url){ |
---|
| 2457 | HINTERNET res; |
---|
| 2458 | char* fcontent; |
---|
| 2459 | char* cached=isInCache(m,url); |
---|
| 2460 | int fsize; |
---|
| 2461 | if(cached!=NULL){ |
---|
| 2462 | struct stat f_status; |
---|
| 2463 | int s=stat(cached, &f_status); |
---|
| 2464 | if(s==0){ |
---|
| 2465 | fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); |
---|
| 2466 | FILE* f=fopen(cached,"r"); |
---|
| 2467 | fread(fcontent,sizeof(char),f_status.st_size,f); |
---|
| 2468 | fsize=f_status.st_size; |
---|
| 2469 | } |
---|
| 2470 | }else{ |
---|
| 2471 | res=InternetOpenUrl(hInternet,url,NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); |
---|
| 2472 | fcontent=(char*)calloc((res.nDataLen+1),sizeof(char)); |
---|
| 2473 | if(fcontent == NULL){ |
---|
| 2474 | return errorException(m, _("Unable to allocate memory."), "InternalError"); |
---|
| 2475 | } |
---|
| 2476 | size_t dwRead; |
---|
| 2477 | InternetReadFile(res, (LPVOID)fcontent, res.nDataLen, &dwRead); |
---|
| 2478 | fcontent[res.nDataLen]=0; |
---|
| 2479 | fsize=res.nDataLen; |
---|
| 2480 | } |
---|
[282] | 2481 | map* tmpMap=getMapOrFill(content,"value",""); |
---|
[281] | 2482 | free(tmpMap->value); |
---|
| 2483 | tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); |
---|
| 2484 | memcpy(tmpMap->value,fcontent,(fsize)*sizeof(char)); |
---|
| 2485 | char ltmp1[256]; |
---|
| 2486 | sprintf(ltmp1,"%d",fsize); |
---|
| 2487 | addToMap(content,"size",ltmp1); |
---|
| 2488 | if(cached==NULL) |
---|
| 2489 | addToCache(m,url,fcontent,fsize); |
---|
| 2490 | free(fcontent); |
---|
[294] | 2491 | free(cached); |
---|
[281] | 2492 | } |
---|
| 2493 | |
---|
[284] | 2494 | int errorException(maps *m, const char *message, const char *errorcode) |
---|
| 2495 | { |
---|
| 2496 | map* errormap = createMap("text", message); |
---|
| 2497 | addToMap(errormap,"code", errorcode); |
---|
| 2498 | printExceptionReportResponse(m,errormap); |
---|
| 2499 | freeMap(&errormap); |
---|
| 2500 | free(errormap); |
---|
| 2501 | return -1; |
---|
| 2502 | } |
---|