[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 | |
---|
[34] | 27 | void *addLangAttr(xmlNodePtr n,maps *m){ |
---|
| 28 | map *tmpLmap=getMapFromMaps(m,"main","language"); |
---|
| 29 | if(tmpLmap!=NULL) |
---|
| 30 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value); |
---|
| 31 | else |
---|
| 32 | xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US"); |
---|
| 33 | } |
---|
| 34 | |
---|
[1] | 35 | /* Converts a hex character to its integer value */ |
---|
| 36 | char from_hex(char ch) { |
---|
| 37 | return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | /* Converts an integer value to its hex character*/ |
---|
| 41 | char to_hex(char code) { |
---|
| 42 | static char hex[] = "0123456789abcdef"; |
---|
| 43 | return hex[code & 15]; |
---|
| 44 | } |
---|
| 45 | |
---|
[26] | 46 | void* unhandleStatus(maps *conf){ |
---|
| 47 | int shmid,i; |
---|
| 48 | key_t key; |
---|
| 49 | void *shm; |
---|
| 50 | struct shmid_ds shmids; |
---|
| 51 | char *s,*s1; |
---|
| 52 | map *tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
| 53 | if(tmpMap!=NULL){ |
---|
| 54 | key=atoi(tmpMap->value); |
---|
| 55 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
| 56 | #ifdef DEBUG |
---|
| 57 | fprintf(stderr,"shmget failed to update value\n"); |
---|
| 58 | #endif |
---|
| 59 | }else{ |
---|
| 60 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 61 | #ifdef DEBUG |
---|
| 62 | fprintf(stderr,"shmat failed to update value\n"); |
---|
| 63 | #endif |
---|
| 64 | }else{ |
---|
| 65 | shmdt(shm); |
---|
| 66 | shmctl(shmid,IPC_RMID,&shmids); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | #ifdef USE_JS |
---|
| 73 | |
---|
| 74 | JSBool |
---|
| 75 | JSUpdateStatus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) |
---|
| 76 | { |
---|
| 77 | JS_MaybeGC(cx); |
---|
| 78 | char *sid; |
---|
| 79 | int istatus=0; |
---|
| 80 | char *status=NULL; |
---|
| 81 | maps *conf; |
---|
| 82 | int i=0; |
---|
| 83 | if(argc>2){ |
---|
| 84 | #ifdef JS_DEBUG |
---|
| 85 | fprintf(stderr,"Number of arguments used to call the function : %i",argc); |
---|
| 86 | #endif |
---|
| 87 | return JS_FALSE; |
---|
| 88 | } |
---|
| 89 | conf=mapsFromJSObject(cx,argv[0]); |
---|
| 90 | if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){ |
---|
| 91 | char tmpStatus[4]; |
---|
| 92 | sprintf(tmpStatus,"%i",istatus); |
---|
| 93 | tmpStatus[3]=0; |
---|
| 94 | status=strdup(tmpStatus); |
---|
| 95 | } |
---|
| 96 | if(getMapFromMaps(conf,"lenv","status")!=NULL){ |
---|
| 97 | if(status!=NULL) |
---|
| 98 | setMapInMaps(conf,"lenv","status",status); |
---|
| 99 | else |
---|
| 100 | setMapInMaps(conf,"lenv","status","15"); |
---|
| 101 | updateStatus(conf); |
---|
| 102 | } |
---|
| 103 | freeMaps(&conf); |
---|
| 104 | free(conf); |
---|
| 105 | JS_MaybeGC(cx); |
---|
| 106 | return JS_TRUE; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | #endif |
---|
| 110 | |
---|
| 111 | void* updateStatus(maps *conf){ |
---|
| 112 | int shmid,i; |
---|
| 113 | key_t key; |
---|
| 114 | char *shm,*s,*s1; |
---|
| 115 | map *tmpMap=NULL; |
---|
| 116 | tmpMap=getMapFromMaps(conf,"lenv","sid"); |
---|
| 117 | if(tmpMap!=NULL){ |
---|
| 118 | key=atoi(tmpMap->value); |
---|
| 119 | if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { |
---|
| 120 | #ifdef DEBUG |
---|
| 121 | fprintf(stderr,"shmget failed to update value\n"); |
---|
| 122 | #endif |
---|
| 123 | }else{ |
---|
| 124 | if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 125 | #ifdef DEBUG |
---|
| 126 | fprintf(stderr,"shmat failed to update value\n"); |
---|
| 127 | #endif |
---|
| 128 | } |
---|
| 129 | else{ |
---|
| 130 | tmpMap=getMapFromMaps(conf,"lenv","status"); |
---|
| 131 | s1=shm; |
---|
| 132 | for(s=tmpMap->value;*s!=NULL;s++) |
---|
| 133 | *s1++=*s; |
---|
| 134 | shmdt((void *)shm); |
---|
| 135 | } |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | char* getStatus(int pid){ |
---|
| 141 | int shmid,i; |
---|
| 142 | key_t key; |
---|
| 143 | void *shm; |
---|
| 144 | char *s; |
---|
| 145 | key=pid; |
---|
| 146 | if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { |
---|
| 147 | #ifdef DEBUG |
---|
| 148 | fprintf(stderr,"shmget failed in getStatus\n"); |
---|
| 149 | #endif |
---|
| 150 | }else{ |
---|
| 151 | if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { |
---|
| 152 | #ifdef DEBUG |
---|
| 153 | fprintf(stderr,"shmat failed in getStatus\n"); |
---|
| 154 | #endif |
---|
| 155 | }else{ |
---|
| 156 | return (char*)shm; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | return "-1"; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
[1] | 163 | /* Returns a url-encoded version of str */ |
---|
| 164 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
| 165 | char *url_encode(char *str) { |
---|
| 166 | char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf; |
---|
| 167 | while (*pstr) { |
---|
| 168 | if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') |
---|
| 169 | *pbuf++ = *pstr; |
---|
| 170 | else if (*pstr == ' ') |
---|
| 171 | *pbuf++ = '+'; |
---|
| 172 | else |
---|
| 173 | *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); |
---|
| 174 | pstr++; |
---|
| 175 | } |
---|
| 176 | *pbuf = '\0'; |
---|
| 177 | return buf; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /* Returns a url-decoded version of str */ |
---|
| 181 | /* IMPORTANT: be sure to free() the returned string after use */ |
---|
| 182 | char *url_decode(char *str) { |
---|
| 183 | char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf; |
---|
| 184 | while (*pstr) { |
---|
| 185 | if (*pstr == '%') { |
---|
| 186 | if (pstr[1] && pstr[2]) { |
---|
| 187 | *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); |
---|
| 188 | pstr += 2; |
---|
| 189 | } |
---|
| 190 | } else if (*pstr == '+') { |
---|
| 191 | *pbuf++ = ' '; |
---|
| 192 | } else { |
---|
| 193 | *pbuf++ = *pstr; |
---|
| 194 | } |
---|
| 195 | pstr++; |
---|
| 196 | } |
---|
| 197 | *pbuf = '\0'; |
---|
| 198 | return buf; |
---|
| 199 | } |
---|
| 200 | |
---|
[9] | 201 | char *zCapitalize1(char *tmp){ |
---|
| 202 | char *res=strdup(tmp); |
---|
| 203 | if(res[0]>=97 && res[0]<=122) |
---|
| 204 | res[0]-=32; |
---|
| 205 | return res; |
---|
| 206 | } |
---|
[1] | 207 | |
---|
[9] | 208 | char *zCapitalize(char *tmp){ |
---|
| 209 | int i=0; |
---|
| 210 | char *res=strdup(tmp); |
---|
| 211 | for(i=0;i<strlen(res);i++) |
---|
| 212 | if(res[i]>=97 && res[i]<=122) |
---|
| 213 | res[i]-=32; |
---|
| 214 | return res; |
---|
| 215 | } |
---|
[1] | 216 | |
---|
[9] | 217 | |
---|
| 218 | int zooXmlSearchForNs(char* name){ |
---|
| 219 | int i; |
---|
| 220 | int res=-1; |
---|
| 221 | for(i=0;i<nbNs;i++) |
---|
| 222 | if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){ |
---|
| 223 | res=i; |
---|
| 224 | break; |
---|
[1] | 225 | } |
---|
[9] | 226 | return res; |
---|
| 227 | } |
---|
[1] | 228 | |
---|
[9] | 229 | int zooXmlAddNs(xmlNodePtr nr,char* url,char* name){ |
---|
[1] | 230 | #ifdef DEBUG |
---|
[9] | 231 | fprintf(stderr,"zooXmlAddNs %d \n",nbNs); |
---|
[1] | 232 | #endif |
---|
[9] | 233 | int currId=-1; |
---|
| 234 | if(nbNs==0){ |
---|
| 235 | nbNs++; |
---|
| 236 | currId=0; |
---|
| 237 | nsName[currId]=strdup(name); |
---|
| 238 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
| 239 | }else{ |
---|
| 240 | currId=zooXmlSearchForNs(name); |
---|
| 241 | if(currId<0){ |
---|
| 242 | nbNs++; |
---|
| 243 | currId=nbNs-1; |
---|
| 244 | nsName[currId]=strdup(name); |
---|
| 245 | usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); |
---|
[1] | 246 | } |
---|
[9] | 247 | } |
---|
| 248 | return currId; |
---|
| 249 | } |
---|
[1] | 250 | |
---|
[9] | 251 | void zooXmlCleanupNs(){ |
---|
| 252 | int j; |
---|
[1] | 253 | #ifdef DEBUG |
---|
[9] | 254 | fprintf(stderr,"zooXmlCleanup %d\n",nbNs); |
---|
[1] | 255 | #endif |
---|
[9] | 256 | for(j=nbNs-1;j>=0;j--){ |
---|
[1] | 257 | #ifdef DEBUG |
---|
[9] | 258 | fprintf(stderr,"zooXmlCleanup %d\n",j); |
---|
[1] | 259 | #endif |
---|
[9] | 260 | if(j==0) |
---|
| 261 | xmlFreeNs(usedNs[j]); |
---|
| 262 | free(nsName[j]); |
---|
| 263 | nbNs--; |
---|
[1] | 264 | } |
---|
[9] | 265 | nbNs=0; |
---|
[1] | 266 | } |
---|
| 267 | |
---|
| 268 | xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){ |
---|
| 269 | |
---|
| 270 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
[9] | 271 | xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
[1] | 272 | xmlChar *xmlbuff; |
---|
| 273 | int buffersize; |
---|
| 274 | /** |
---|
| 275 | * Create the document and its temporary root. |
---|
| 276 | */ |
---|
[9] | 277 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 278 | ns=usedNs[wpsId]; |
---|
[1] | 279 | maps* toto1=getMaps(m,"main"); |
---|
| 280 | |
---|
[9] | 281 | n = xmlNewNode(ns, BAD_CAST "Capabilities"); |
---|
| 282 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 283 | ns_ows=usedNs[owsId]; |
---|
[1] | 284 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
[9] | 285 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 286 | ns_xsi=usedNs[xsiId]; |
---|
| 287 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 288 | ns_xlink=usedNs[xlinkId]; |
---|
| 289 | 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] | 290 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
[34] | 291 | addLangAttr(n,m); |
---|
[1] | 292 | |
---|
| 293 | if(toto1!=NULL){ |
---|
| 294 | map* tmp=getMap(toto1->content,"version"); |
---|
| 295 | if(tmp!=NULL){ |
---|
| 296 | xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value); |
---|
| 297 | } |
---|
| 298 | else |
---|
| 299 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
| 300 | } |
---|
| 301 | else |
---|
| 302 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
| 303 | |
---|
| 304 | char tmp[256]; |
---|
| 305 | |
---|
| 306 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); |
---|
| 307 | maps* tmp4=getMaps(m,"identification"); |
---|
| 308 | if(tmp4!=NULL){ |
---|
| 309 | map* tmp2=tmp4->content; |
---|
[71] | 310 | char *orderedFields[5]; |
---|
| 311 | orderedFields[0]="Title"; |
---|
| 312 | orderedFields[1]="Abstract"; |
---|
| 313 | orderedFields[2]="Keywords"; |
---|
| 314 | orderedFields[3]="Fees"; |
---|
| 315 | orderedFields[4]="AccessConstraints"; |
---|
| 316 | int oI=0; |
---|
| 317 | for(oI=0;oI<5;oI++) |
---|
| 318 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
| 319 | if(strcasecmp(tmp2->name,"abstract")==0 || |
---|
| 320 | strcasecmp(tmp2->name,"title")==0 || |
---|
| 321 | strcasecmp(tmp2->name,"accessConstraints")==0 || |
---|
| 322 | strcasecmp(tmp2->name,"fees")==0){ |
---|
| 323 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
| 324 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
| 325 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 326 | xmlAddChild(nc,nc1); |
---|
| 327 | } |
---|
| 328 | else |
---|
| 329 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
| 330 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
| 331 | char *toto=tmp2->value; |
---|
| 332 | char buff[256]; |
---|
| 333 | int i=0; |
---|
| 334 | int j=0; |
---|
| 335 | while(toto[i]){ |
---|
| 336 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 337 | buff[j]=toto[i]; |
---|
| 338 | buff[j+1]=0; |
---|
| 339 | j++; |
---|
| 340 | } |
---|
| 341 | else{ |
---|
| 342 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 343 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 344 | xmlAddChild(nc1,nc2); |
---|
| 345 | j=0; |
---|
| 346 | } |
---|
| 347 | i++; |
---|
[1] | 348 | } |
---|
[71] | 349 | if(strlen(buff)>0){ |
---|
[1] | 350 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 351 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 352 | xmlAddChild(nc1,nc2); |
---|
| 353 | } |
---|
[71] | 354 | xmlAddChild(nc,nc1); |
---|
| 355 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); |
---|
| 356 | xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); |
---|
| 357 | xmlAddChild(nc,nc2); |
---|
| 358 | nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); |
---|
| 359 | xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); |
---|
| 360 | xmlAddChild(nc,nc2); |
---|
[1] | 361 | } |
---|
[71] | 362 | tmp2=tmp2->next; |
---|
| 363 | } |
---|
[1] | 364 | } |
---|
| 365 | else{ |
---|
| 366 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
| 367 | return NULL; |
---|
| 368 | } |
---|
| 369 | xmlAddChild(n,nc); |
---|
| 370 | |
---|
| 371 | nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); |
---|
| 372 | nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); |
---|
| 373 | nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); |
---|
| 374 | nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); |
---|
| 375 | nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); |
---|
| 376 | tmp4=getMaps(m,"provider"); |
---|
| 377 | if(tmp4!=NULL){ |
---|
| 378 | map* tmp2=tmp4->content; |
---|
[57] | 379 | char *tmpAddress[6]; |
---|
| 380 | tmpAddress[0]="addressDeliveryPoint"; |
---|
| 381 | tmpAddress[1]="addressCity"; |
---|
| 382 | tmpAddress[2]="addressAdministrativeArea"; |
---|
| 383 | tmpAddress[3]="addressPostalCode"; |
---|
| 384 | tmpAddress[4]="addressCountry"; |
---|
| 385 | tmpAddress[5]="addressElectronicMailAddress"; |
---|
| 386 | char *tmpPhone[2]; |
---|
| 387 | tmpPhone[0]="phoneVoice"; |
---|
| 388 | tmpPhone[1]="phoneFacsimile"; |
---|
[71] | 389 | char *orderedFields[12]; |
---|
| 390 | orderedFields[0]="providerName"; |
---|
| 391 | orderedFields[1]="providerSite"; |
---|
| 392 | orderedFields[2]="individualName"; |
---|
| 393 | orderedFields[3]="positionName"; |
---|
| 394 | orderedFields[4]=tmpPhone[0]; |
---|
| 395 | orderedFields[5]=tmpPhone[1]; |
---|
| 396 | orderedFields[6]=tmpAddress[0]; |
---|
| 397 | orderedFields[7]=tmpAddress[1]; |
---|
| 398 | orderedFields[8]=tmpAddress[2]; |
---|
| 399 | orderedFields[9]=tmpAddress[3]; |
---|
| 400 | orderedFields[10]=tmpAddress[4]; |
---|
| 401 | orderedFields[11]=tmpAddress[5]; |
---|
| 402 | int oI=0; |
---|
| 403 | for(oI=0;oI<12;oI++) |
---|
| 404 | if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ |
---|
| 405 | if(strcmp(tmp2->name,"keywords")!=0 && |
---|
| 406 | strcmp(tmp2->name,"serverAddress")!=0 && |
---|
| 407 | strcmp(tmp2->name,"lang")!=0){ |
---|
| 408 | tmp2->name[0]=toupper(tmp2->name[0]); |
---|
| 409 | if(strcmp(tmp2->name,"ProviderName")==0){ |
---|
[1] | 410 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
[71] | 411 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
[1] | 412 | xmlAddChild(nc,nc1); |
---|
[71] | 413 | } |
---|
| 414 | else{ |
---|
| 415 | if(strcmp(tmp2->name,"ProviderSite")==0){ |
---|
[1] | 416 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
[71] | 417 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); |
---|
| 418 | xmlAddChild(nc,nc1); |
---|
[1] | 419 | } |
---|
[71] | 420 | else |
---|
| 421 | if(strcmp(tmp2->name,"IndividualName")==0 || |
---|
| 422 | strcmp(tmp2->name,"PositionName")==0){ |
---|
| 423 | nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); |
---|
| 424 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 425 | xmlAddChild(nc3,nc1); |
---|
| 426 | } |
---|
[1] | 427 | else |
---|
[71] | 428 | if(strncmp(tmp2->name,"Phone",5)==0){ |
---|
[57] | 429 | int j; |
---|
[71] | 430 | for(j=0;j<2;j++) |
---|
| 431 | if(strcasecmp(tmp2->name,tmpPhone[j])==0){ |
---|
[57] | 432 | char *toto=NULL; |
---|
| 433 | char *toto1=tmp2->name; |
---|
[71] | 434 | toto=strstr(toto1,"Phone"); |
---|
| 435 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5); |
---|
[57] | 436 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
[71] | 437 | xmlAddChild(nc5,nc1); |
---|
[57] | 438 | } |
---|
[1] | 439 | } |
---|
[71] | 440 | else |
---|
| 441 | if(strncmp(tmp2->name,"Address",7)==0){ |
---|
| 442 | int j; |
---|
| 443 | for(j=0;j<6;j++) |
---|
| 444 | if(strcasecmp(tmp2->name,tmpAddress[j])==0){ |
---|
| 445 | char *toto=NULL; |
---|
| 446 | char *toto1=tmp2->name; |
---|
| 447 | toto=strstr(toto1,"Address"); |
---|
| 448 | nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7); |
---|
| 449 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); |
---|
| 450 | xmlAddChild(nc6,nc1); |
---|
| 451 | } |
---|
| 452 | } |
---|
| 453 | } |
---|
[1] | 454 | } |
---|
[71] | 455 | else |
---|
| 456 | if(strcmp(tmp2->name,"keywords")==0){ |
---|
| 457 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); |
---|
| 458 | char *toto=tmp2->value; |
---|
| 459 | char buff[256]; |
---|
| 460 | int i=0; |
---|
| 461 | int j=0; |
---|
| 462 | while(toto[i]){ |
---|
| 463 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 464 | buff[j]=toto[i]; |
---|
| 465 | buff[j+1]=0; |
---|
| 466 | j++; |
---|
| 467 | } |
---|
| 468 | else{ |
---|
| 469 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 470 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 471 | xmlAddChild(nc1,nc2); |
---|
| 472 | j=0; |
---|
| 473 | } |
---|
| 474 | i++; |
---|
[1] | 475 | } |
---|
[71] | 476 | if(strlen(buff)>0){ |
---|
[1] | 477 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); |
---|
| 478 | xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); |
---|
| 479 | xmlAddChild(nc1,nc2); |
---|
| 480 | } |
---|
[71] | 481 | xmlAddChild(nc,nc1); |
---|
[1] | 482 | } |
---|
[71] | 483 | tmp2=tmp2->next; |
---|
| 484 | } |
---|
[1] | 485 | } |
---|
| 486 | else{ |
---|
| 487 | fprintf(stderr,"TMP4 NOT FOUND !!"); |
---|
| 488 | } |
---|
| 489 | xmlAddChild(nc4,nc5); |
---|
| 490 | xmlAddChild(nc4,nc6); |
---|
| 491 | xmlAddChild(nc3,nc4); |
---|
| 492 | xmlAddChild(nc,nc3); |
---|
| 493 | xmlAddChild(n,nc); |
---|
| 494 | |
---|
| 495 | |
---|
| 496 | nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); |
---|
| 497 | char *tmp2[3]; |
---|
[9] | 498 | tmp2[0]=strdup("GetCapabilities"); |
---|
| 499 | tmp2[1]=strdup("DescribeProcess"); |
---|
| 500 | tmp2[2]=strdup("Execute"); |
---|
[1] | 501 | int j=0; |
---|
| 502 | |
---|
| 503 | if(toto1!=NULL){ |
---|
| 504 | map* tmp=getMap(toto1->content,"serverAddress"); |
---|
| 505 | if(tmp!=NULL){ |
---|
| 506 | SERVICE_URL = strdup(tmp->value); |
---|
| 507 | } |
---|
| 508 | else |
---|
[9] | 509 | SERVICE_URL = strdup("not_found"); |
---|
[1] | 510 | } |
---|
| 511 | else |
---|
[9] | 512 | SERVICE_URL = strdup("not_found"); |
---|
[1] | 513 | |
---|
| 514 | for(j=0;j<3;j++){ |
---|
| 515 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); |
---|
| 516 | xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]); |
---|
| 517 | nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); |
---|
| 518 | nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); |
---|
| 519 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); |
---|
| 520 | sprintf(tmp,"%s/%s",SERVICE_URL,service); |
---|
[9] | 521 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
[1] | 522 | xmlAddChild(nc3,nc4); |
---|
| 523 | if(j>0){ |
---|
| 524 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); |
---|
[9] | 525 | xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); |
---|
[1] | 526 | xmlAddChild(nc3,nc4); |
---|
| 527 | } |
---|
| 528 | xmlAddChild(nc2,nc3); |
---|
| 529 | xmlAddChild(nc1,nc2); |
---|
| 530 | xmlAddChild(nc,nc1); |
---|
| 531 | } |
---|
[9] | 532 | for(j=2;j>=0;j--) |
---|
| 533 | free(tmp2[j]); |
---|
[1] | 534 | xmlAddChild(n,nc); |
---|
| 535 | |
---|
| 536 | nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); |
---|
| 537 | xmlAddChild(n,nc); |
---|
| 538 | |
---|
| 539 | nc1 = xmlNewNode(ns, BAD_CAST "Languages"); |
---|
| 540 | nc2 = xmlNewNode(ns, BAD_CAST "Default"); |
---|
| 541 | nc3 = xmlNewNode(ns, BAD_CAST "Supported"); |
---|
| 542 | |
---|
| 543 | toto1=getMaps(m,"main"); |
---|
| 544 | if(toto1!=NULL){ |
---|
| 545 | map* tmp1=getMap(toto1->content,"lang"); |
---|
| 546 | char *toto=tmp1->value; |
---|
| 547 | char buff[256]; |
---|
| 548 | int i=0; |
---|
| 549 | int j=0; |
---|
| 550 | int dcount=0; |
---|
| 551 | while(toto[i]){ |
---|
| 552 | if(toto[i]!=',' && toto[i]!=0){ |
---|
| 553 | buff[j]=toto[i]; |
---|
| 554 | buff[j+1]=0; |
---|
| 555 | j++; |
---|
| 556 | } |
---|
| 557 | else{ |
---|
| 558 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 559 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 560 | if(dcount==0){ |
---|
| 561 | xmlAddChild(nc2,nc4); |
---|
| 562 | xmlAddChild(nc1,nc2); |
---|
| 563 | dcount++; |
---|
| 564 | } |
---|
| 565 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 566 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 567 | xmlAddChild(nc3,nc4); |
---|
| 568 | j=0; |
---|
| 569 | buff[j]=0; |
---|
| 570 | } |
---|
| 571 | i++; |
---|
| 572 | } |
---|
| 573 | if(strlen(buff)>0){ |
---|
| 574 | nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); |
---|
| 575 | xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); |
---|
| 576 | xmlAddChild(nc3,nc4); |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | xmlAddChild(nc1,nc3); |
---|
| 580 | xmlAddChild(n,nc1); |
---|
| 581 | |
---|
| 582 | xmlDocSetRootElement(doc, n); |
---|
[9] | 583 | //xmlFreeNs(ns); |
---|
| 584 | free(SERVICE_URL); |
---|
[1] | 585 | return nc; |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ |
---|
[9] | 589 | xmlNsPtr ns,ns_ows,ns_xlink; |
---|
[1] | 590 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
[9] | 591 | /** |
---|
| 592 | * Initialize or get existing namspaces |
---|
| 593 | */ |
---|
| 594 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 595 | ns=usedNs[wpsId]; |
---|
| 596 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 597 | ns_ows=usedNs[owsId]; |
---|
| 598 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 599 | ns_xlink=usedNs[xlinkId]; |
---|
[1] | 600 | |
---|
| 601 | int cursor=0; |
---|
| 602 | map* tmp1; |
---|
| 603 | if(serv->content!=NULL){ |
---|
| 604 | nc1 = xmlNewNode(ns, BAD_CAST "Process"); |
---|
| 605 | tmp1=getMap(serv->content,"processVersion"); |
---|
| 606 | if(tmp1!=NULL) |
---|
[9] | 607 | xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
[1] | 608 | printDescription(nc1,ns_ows,serv->name,serv->content); |
---|
| 609 | tmp1=serv->metadata; |
---|
| 610 | while(tmp1!=NULL){ |
---|
| 611 | nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
[9] | 612 | xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
[1] | 613 | xmlAddChild(nc1,nc2); |
---|
| 614 | tmp1=tmp1->next; |
---|
| 615 | } |
---|
| 616 | xmlAddChild(nc,nc1); |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){ |
---|
| 621 | |
---|
| 622 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 623 | xmlNodePtr n,nr; |
---|
| 624 | xmlChar *xmlbuff; |
---|
| 625 | int buffersize; |
---|
| 626 | |
---|
[9] | 627 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
| 628 | ns=usedNs[wpsId]; |
---|
| 629 | n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions"); |
---|
| 630 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 631 | ns_ows=usedNs[owsId]; |
---|
[1] | 632 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
[9] | 633 | zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 634 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 635 | ns_xsi=usedNs[xsiId]; |
---|
| 636 | |
---|
| 637 | 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] | 638 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
| 639 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
[34] | 640 | addLangAttr(n,m); |
---|
[1] | 641 | |
---|
| 642 | xmlDocSetRootElement(doc, n); |
---|
| 643 | |
---|
| 644 | return n; |
---|
| 645 | } |
---|
| 646 | |
---|
[9] | 647 | void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){ |
---|
[1] | 648 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 649 | xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor; |
---|
| 650 | |
---|
| 651 | char tmp[256]; |
---|
| 652 | n=nc; |
---|
| 653 | |
---|
[9] | 654 | int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); |
---|
| 655 | ns=usedNs[wpsId]; |
---|
| 656 | int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 657 | ns_ows=usedNs[owsId]; |
---|
| 658 | int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 659 | ns_xlink=usedNs[xlinkId]; |
---|
[1] | 660 | |
---|
| 661 | nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); |
---|
| 662 | char *tmp4[3]; |
---|
| 663 | tmp4[0]="processVersion"; |
---|
| 664 | tmp4[1]="storeSupported"; |
---|
| 665 | tmp4[2]="statusSupported"; |
---|
| 666 | int j=0; |
---|
| 667 | map* tmp1=NULL; |
---|
| 668 | for(j=0;j<3;j++){ |
---|
[9] | 669 | tmp1=getMap(serv->content,tmp4[j]); |
---|
[1] | 670 | if(tmp1!=NULL){ |
---|
| 671 | if(j==0) |
---|
[9] | 672 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); |
---|
[1] | 673 | else |
---|
| 674 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value); |
---|
| 675 | } |
---|
| 676 | else{ |
---|
| 677 | if(j>0) |
---|
| 678 | xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); |
---|
| 679 | } |
---|
| 680 | } |
---|
| 681 | |
---|
[9] | 682 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
[1] | 683 | |
---|
[9] | 684 | tmp1=serv->metadata; |
---|
[1] | 685 | while(tmp1!=NULL){ |
---|
| 686 | nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); |
---|
[9] | 687 | xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
[1] | 688 | xmlAddChild(nc,nc1); |
---|
| 689 | tmp1=tmp1->next; |
---|
| 690 | } |
---|
| 691 | |
---|
[9] | 692 | tmp1=getMap(serv->content,"Profile"); |
---|
[1] | 693 | if(tmp1!=NULL){ |
---|
| 694 | nc1 = xmlNewNode(ns, BAD_CAST "Profile"); |
---|
| 695 | xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 696 | xmlAddChild(nc,nc1); |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); |
---|
| 700 | |
---|
[9] | 701 | elements* e=serv->inputs; |
---|
[1] | 702 | while(e!=NULL){ |
---|
| 703 | nc2 = xmlNewNode(NULL, BAD_CAST "Input"); |
---|
| 704 | tmp1=getMap(e->content,"minOccurs"); |
---|
| 705 | if(tmp1){ |
---|
| 706 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 707 | } |
---|
| 708 | tmp1=getMap(e->content,"maxOccurs"); |
---|
| 709 | if(tmp1){ |
---|
| 710 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
| 714 | |
---|
| 715 | |
---|
| 716 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
| 717 | iotype* _tmp=e->defaults; |
---|
| 718 | int datatype=0; |
---|
| 719 | if(_tmp!=NULL){ |
---|
[9] | 720 | int isAnyValue=1; |
---|
[1] | 721 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
| 722 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 723 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 724 | } |
---|
| 725 | else{ |
---|
| 726 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
| 727 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 728 | datatype=1; |
---|
| 729 | } |
---|
| 730 | tmp1=_tmp->content; |
---|
| 731 | int default1=0; |
---|
| 732 | xmlNodePtr nc7; |
---|
[71] | 733 | char *orderedFields[5]; |
---|
| 734 | orderedFields[0]="mimeType"; |
---|
| 735 | orderedFields[1]="encoding"; |
---|
| 736 | orderedFields[2]="schema"; |
---|
| 737 | orderedFields[3]="dataType"; |
---|
| 738 | orderedFields[4]="uom"; |
---|
| 739 | int oI=0; |
---|
| 740 | for(oI=0;oI<5;oI++) |
---|
| 741 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
[1] | 742 | #ifdef DEBUG |
---|
[71] | 743 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
[1] | 744 | #endif |
---|
[71] | 745 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
| 746 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
| 747 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 748 | char tmp[1024]; |
---|
| 749 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
| 750 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
| 751 | xmlAddChild(nc3,nc6); |
---|
| 752 | tmp1=tmp1->next; |
---|
| 753 | continue; |
---|
[9] | 754 | } |
---|
[71] | 755 | if(strcasecmp(tmp1->name,"asReference")!=0 && |
---|
| 756 | strcasecmp(tmp1->name,"DataType")!=0 && |
---|
| 757 | strncasecmp(tmp1->name,"AllowedValues",13)!=0 && |
---|
| 758 | strcasecmp(tmp1->name,"value")!=0 && |
---|
| 759 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
| 760 | if(datatype==0){ |
---|
| 761 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 762 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 763 | free(tmp2); |
---|
| 764 | } |
---|
| 765 | else{ |
---|
| 766 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 767 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 768 | free(tmp2); |
---|
| 769 | } |
---|
| 770 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 771 | xmlAddChild(nc5,nc6); |
---|
| 772 | } |
---|
[9] | 773 | else{ |
---|
[71] | 774 | if(strcmp(tmp1->name,"value")==0){ |
---|
| 775 | nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); |
---|
| 776 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 777 | default1=1; |
---|
| 778 | } |
---|
| 779 | if(strncasecmp(tmp1->name,"AllowedValues",13)==0){ |
---|
| 780 | nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); |
---|
| 781 | char *token,*saveptr1; |
---|
| 782 | token=strtok_r(tmp1->value,",",&saveptr1); |
---|
| 783 | while(token!=NULL){ |
---|
[9] | 784 | nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); |
---|
| 785 | char *tmps=strdup(token); |
---|
| 786 | tmps[strlen(tmps)]=0; |
---|
| 787 | xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); |
---|
| 788 | fprintf(stderr,"strgin : %s\n",tmps); |
---|
| 789 | xmlAddChild(nc6,nc7); |
---|
| 790 | token=strtok_r(NULL,",",&saveptr1); |
---|
[71] | 791 | } |
---|
| 792 | xmlAddChild(nc3,nc6); |
---|
| 793 | isAnyValue=-1; |
---|
[9] | 794 | } |
---|
| 795 | } |
---|
[71] | 796 | tmp1=tmp1->next; |
---|
[1] | 797 | } |
---|
| 798 | xmlAddChild(nc4,nc5); |
---|
| 799 | xmlAddChild(nc3,nc4); |
---|
[9] | 800 | if(datatype==1 && isAnyValue==1){ |
---|
| 801 | xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); |
---|
| 802 | if(default1>0) |
---|
| 803 | xmlAddChild(nc3,nc7); |
---|
[1] | 804 | } |
---|
[9] | 805 | if(datatype==1 && default1>0) |
---|
| 806 | xmlAddChild(nc3,nc7); |
---|
[1] | 807 | } |
---|
| 808 | xmlAddChild(nc2,nc3); |
---|
| 809 | |
---|
| 810 | _tmp=e->supported; |
---|
[71] | 811 | int hasSupported=-1; |
---|
[9] | 812 | while(_tmp!=NULL){ |
---|
[71] | 813 | if(hasSupported<0){ |
---|
| 814 | if(datatype==0){ |
---|
| 815 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 816 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 817 | } |
---|
| 818 | else{ |
---|
| 819 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 820 | } |
---|
| 821 | hasSupported=0; |
---|
| 822 | }else{ |
---|
[1] | 823 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 824 | } |
---|
| 825 | tmp1=_tmp->content; |
---|
[71] | 826 | char *orderedFields[5]; |
---|
| 827 | orderedFields[0]="mimeType"; |
---|
| 828 | orderedFields[1]="encoding"; |
---|
| 829 | orderedFields[2]="schema"; |
---|
| 830 | orderedFields[3]="dataType"; |
---|
| 831 | orderedFields[4]="uom"; |
---|
| 832 | int oI=0; |
---|
| 833 | for(oI=0;oI<5;oI++) |
---|
| 834 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
| 835 | if(datatype==0){ |
---|
| 836 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 837 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 838 | free(tmp2); |
---|
| 839 | } |
---|
| 840 | else{ |
---|
| 841 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 842 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 843 | free(tmp2); |
---|
| 844 | } |
---|
| 845 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 846 | xmlAddChild(nc5,nc6); |
---|
| 847 | tmp1=tmp1->next; |
---|
| 848 | } |
---|
| 849 | if(hasSupported<=0){ |
---|
[9] | 850 | if(datatype==0){ |
---|
[71] | 851 | xmlAddChild(nc4,nc5); |
---|
| 852 | xmlAddChild(nc3,nc4); |
---|
| 853 | }else{ |
---|
| 854 | xmlAddChild(nc4,nc5); |
---|
[9] | 855 | } |
---|
[71] | 856 | hasSupported=1; |
---|
[1] | 857 | }else{ |
---|
[71] | 858 | xmlAddChild(nc4,nc5); |
---|
[9] | 859 | } |
---|
| 860 | _tmp=_tmp->next; |
---|
| 861 | if(strcmp(e->format,"LiteralData")!=0){ |
---|
| 862 | xmlAddChild(nc2,nc3); |
---|
| 863 | } |
---|
[1] | 864 | } |
---|
[64] | 865 | xmlAddChild(nc1,nc2); |
---|
[1] | 866 | |
---|
| 867 | |
---|
| 868 | e=e->next; |
---|
| 869 | } |
---|
| 870 | xmlAddChild(nc,nc1); |
---|
| 871 | |
---|
| 872 | nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); |
---|
| 873 | |
---|
[9] | 874 | e=serv->outputs; |
---|
[1] | 875 | while(e!=NULL){ |
---|
| 876 | nc2 = xmlNewNode(NULL, BAD_CAST "Output"); |
---|
| 877 | tmp1=getMap(e->content,"minOccurs"); |
---|
| 878 | if(tmp1){ |
---|
| 879 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 880 | } |
---|
| 881 | tmp1=getMap(e->content,"maxOccurs"); |
---|
| 882 | if(tmp1){ |
---|
| 883 | xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); |
---|
| 884 | } |
---|
| 885 | |
---|
| 886 | printDescription(nc2,ns_ows,e->name,e->content); |
---|
| 887 | |
---|
[9] | 888 | if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) |
---|
[1] | 889 | nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput"); |
---|
| 890 | else |
---|
[9] | 891 | if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) |
---|
[1] | 892 | nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput"); |
---|
| 893 | else |
---|
| 894 | nc3 = xmlNewNode(NULL, BAD_CAST e->format); |
---|
| 895 | iotype* _tmp=e->defaults; |
---|
| 896 | int datatype=0; |
---|
| 897 | if(_tmp!=NULL){ |
---|
| 898 | if(strcmp(e->format,"LiteralOutput")==0 || |
---|
| 899 | strcmp(e->format,"LiteralData")==0){ |
---|
| 900 | datatype=1; |
---|
| 901 | nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); |
---|
| 902 | nc5 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 903 | } |
---|
| 904 | else{ |
---|
[9] | 905 | nc4 = xmlNewNode(NULL, BAD_CAST "Default"); |
---|
| 906 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
[1] | 907 | } |
---|
| 908 | tmp1=_tmp->content; |
---|
| 909 | while(tmp1!=NULL){ |
---|
| 910 | #ifdef DEBUG |
---|
| 911 | printf("DATATYPE DEFAULT ? %s\n",tmp1->name); |
---|
| 912 | #endif |
---|
[9] | 913 | if(strncasecmp(tmp1->name,"DataType",8)==0){ |
---|
| 914 | nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType"); |
---|
[1] | 915 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 916 | char tmp[1024]; |
---|
| 917 | sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); |
---|
[26] | 918 | xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp); |
---|
[1] | 919 | xmlAddChild(nc3,nc6); |
---|
| 920 | tmp1=tmp1->next; |
---|
| 921 | datatype=1; |
---|
| 922 | continue; |
---|
| 923 | } |
---|
[9] | 924 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
| 925 | strncasecmp(tmp1->name,"DataType",8)!=0 && |
---|
| 926 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
| 927 | if(datatype==0){ |
---|
| 928 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 929 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 930 | free(tmp2); |
---|
| 931 | } |
---|
| 932 | else{ |
---|
| 933 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 934 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 935 | free(tmp2); |
---|
| 936 | } |
---|
[1] | 937 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 938 | xmlAddChild(nc5,nc6); |
---|
| 939 | } |
---|
| 940 | tmp1=tmp1->next; |
---|
| 941 | } |
---|
| 942 | xmlAddChild(nc4,nc5); |
---|
| 943 | xmlAddChild(nc3,nc4); |
---|
| 944 | } |
---|
| 945 | _tmp=e->supported; |
---|
[71] | 946 | int hasSupported=-1; |
---|
[1] | 947 | while(_tmp!=NULL){ |
---|
[71] | 948 | if(hasSupported<0){ |
---|
| 949 | if(datatype==0){ |
---|
| 950 | nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 951 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
| 952 | } |
---|
| 953 | else |
---|
| 954 | nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); |
---|
| 955 | hasSupported=0; |
---|
| 956 | }else |
---|
[64] | 957 | nc5 = xmlNewNode(NULL, BAD_CAST "Format"); |
---|
[1] | 958 | tmp1=_tmp->content; |
---|
[71] | 959 | char *orderedFields[5]; |
---|
| 960 | orderedFields[0]="mimeType"; |
---|
| 961 | orderedFields[1]="encoding"; |
---|
| 962 | orderedFields[2]="schema"; |
---|
| 963 | orderedFields[3]="dataType"; |
---|
| 964 | orderedFields[4]="uom"; |
---|
| 965 | int oI=0; |
---|
| 966 | for(oI=0;oI<5;oI++) |
---|
| 967 | if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ |
---|
[1] | 968 | #ifdef DEBUG |
---|
[71] | 969 | printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); |
---|
[1] | 970 | #endif |
---|
[71] | 971 | if(strcmp(tmp1->name,"asReference")!=0 && |
---|
| 972 | strcmp(tmp1->name,"DataType")!=0 && |
---|
| 973 | strcasecmp(tmp1->name,"extension")!=0){ |
---|
| 974 | if(datatype==0){ |
---|
| 975 | char *tmp2=zCapitalize1(tmp1->name); |
---|
| 976 | nc6 = xmlNewNode(NULL, BAD_CAST tmp2); |
---|
| 977 | free(tmp2); |
---|
| 978 | } |
---|
| 979 | else{ |
---|
| 980 | char *tmp2=zCapitalize(tmp1->name); |
---|
| 981 | nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); |
---|
| 982 | free(tmp2); |
---|
| 983 | } |
---|
| 984 | xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); |
---|
| 985 | xmlAddChild(nc5,nc6); |
---|
[9] | 986 | } |
---|
[71] | 987 | tmp1=tmp1->next; |
---|
[1] | 988 | } |
---|
[71] | 989 | _tmp=_tmp->next; |
---|
| 990 | if(hasSupported<=0){ |
---|
| 991 | if(datatype==0){ |
---|
| 992 | xmlAddChild(nc4,nc5); |
---|
| 993 | xmlAddChild(nc3,nc4); |
---|
| 994 | }else |
---|
| 995 | xmlAddChild(nc4,nc5); |
---|
| 996 | hasSupported=1; |
---|
[1] | 997 | } |
---|
[71] | 998 | else |
---|
| 999 | xmlAddChild(nc4,nc5); |
---|
[1] | 1000 | } |
---|
| 1001 | xmlAddChild(nc2,nc3); |
---|
| 1002 | |
---|
| 1003 | xmlAddChild(nc3,nc4); |
---|
| 1004 | |
---|
| 1005 | |
---|
| 1006 | xmlAddChild(nc2,nc3); |
---|
| 1007 | |
---|
| 1008 | xmlAddChild(nc1,nc2); |
---|
| 1009 | |
---|
| 1010 | e=e->next; |
---|
| 1011 | } |
---|
| 1012 | xmlAddChild(nc,nc1); |
---|
| 1013 | |
---|
| 1014 | xmlAddChild(n,nc); |
---|
| 1015 | |
---|
| 1016 | } |
---|
| 1017 | |
---|
[9] | 1018 | void printProcessResponse(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){ |
---|
| 1019 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 1020 | xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor; |
---|
| 1021 | xmlDocPtr doc; |
---|
[1] | 1022 | xmlChar *xmlbuff; |
---|
| 1023 | int buffersize; |
---|
[9] | 1024 | time_t time1; |
---|
| 1025 | time(&time1); |
---|
| 1026 | /** |
---|
| 1027 | * Create the document and its temporary root. |
---|
| 1028 | */ |
---|
| 1029 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1030 | int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); |
---|
| 1031 | ns=usedNs[wpsId]; |
---|
| 1032 | |
---|
| 1033 | n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); |
---|
| 1034 | int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); |
---|
| 1035 | ns_ows=usedNs[owsId]; |
---|
| 1036 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 1037 | ns_xlink=usedNs[xlinkId]; |
---|
| 1038 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 1039 | ns_xsi=usedNs[xsiId]; |
---|
| 1040 | xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); |
---|
| 1041 | |
---|
| 1042 | 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"); |
---|
| 1043 | |
---|
| 1044 | xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); |
---|
| 1045 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); |
---|
[34] | 1046 | addLangAttr(n,m); |
---|
| 1047 | |
---|
[9] | 1048 | char tmp[256]; |
---|
[26] | 1049 | char url[1024]; |
---|
[72] | 1050 | char stored_path[1024]; |
---|
[9] | 1051 | memset(tmp,0,256); |
---|
[72] | 1052 | memset(url,0,1024); |
---|
| 1053 | memset(stored_path,0,1024); |
---|
[9] | 1054 | maps* tmp_maps=getMaps(m,"main"); |
---|
| 1055 | if(tmp_maps!=NULL){ |
---|
[26] | 1056 | map* tmpm1=getMap(tmp_maps->content,"serverAddress"); |
---|
| 1057 | /** |
---|
| 1058 | * Check if the ZOO Service GetStatus is available in the local directory. |
---|
| 1059 | * If yes, then it uses a reference to an URL which the client can access |
---|
| 1060 | * to get information on the status of a running Service (using the |
---|
| 1061 | * percentCompleted attribute). |
---|
| 1062 | * Else fallback to the initial method using the xml file to write in ... |
---|
| 1063 | */ |
---|
| 1064 | char ntmp[1024]; |
---|
| 1065 | #ifndef WIN32 |
---|
| 1066 | getcwd(ntmp,1024); |
---|
| 1067 | #else |
---|
| 1068 | _getcwd(ntmp,1024); |
---|
| 1069 | #endif |
---|
| 1070 | struct stat myFileInfo; |
---|
| 1071 | int statRes; |
---|
| 1072 | char file_path[1024]; |
---|
| 1073 | sprintf(file_path,"%s/GetStatus.zcfg",ntmp); |
---|
| 1074 | statRes=stat(file_path,&myFileInfo); |
---|
| 1075 | if(statRes==0){ |
---|
| 1076 | char currentSid[128]; |
---|
| 1077 | map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); |
---|
| 1078 | map *tmp_lenv=NULL; |
---|
| 1079 | tmp_lenv=getMapFromMaps(m,"lenv","sid"); |
---|
| 1080 | if(tmp_lenv==NULL) |
---|
| 1081 | sprintf(currentSid,"%i",pid); |
---|
| 1082 | else |
---|
| 1083 | sprintf(currentSid,"%s",tmp_lenv->value); |
---|
| 1084 | if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ |
---|
[41] | 1085 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
[26] | 1086 | }else{ |
---|
| 1087 | if(strlen(tmpm->value)>0) |
---|
| 1088 | if(strcasecmp(tmpm->value,"true")!=0) |
---|
| 1089 | sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); |
---|
| 1090 | else |
---|
| 1091 | sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); |
---|
| 1092 | else |
---|
[41] | 1093 | sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); |
---|
[26] | 1094 | } |
---|
| 1095 | }else{ |
---|
| 1096 | map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); |
---|
| 1097 | if(tmpm1!=NULL && tmpm2!=NULL){ |
---|
| 1098 | sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); |
---|
| 1099 | } |
---|
[9] | 1100 | } |
---|
[26] | 1101 | if(tmpm1!=NULL) |
---|
| 1102 | sprintf(tmp,"%s/",tmpm1->value); |
---|
[72] | 1103 | tmpm1=getMapFromMaps(m,"main","TmpPath"); |
---|
| 1104 | sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid); |
---|
[9] | 1105 | } |
---|
| 1106 | |
---|
[72] | 1107 | |
---|
| 1108 | |
---|
[9] | 1109 | xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); |
---|
[72] | 1110 | map* test=getMap(request,"storeExecuteResponse"); |
---|
| 1111 | bool hasStoredExecuteResponse=false; |
---|
| 1112 | if(test!=NULL && strcasecmp(test->value,"true")==0){ |
---|
[9] | 1113 | xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); |
---|
[72] | 1114 | hasStoredExecuteResponse=true; |
---|
[9] | 1115 | } |
---|
| 1116 | |
---|
| 1117 | nc = xmlNewNode(ns, BAD_CAST "Process"); |
---|
| 1118 | map* tmp2=getMap(serv->content,"processVersion"); |
---|
| 1119 | |
---|
| 1120 | if(tmp2!=NULL) |
---|
| 1121 | xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); |
---|
| 1122 | |
---|
| 1123 | printDescription(nc,ns_ows,serv->name,serv->content); |
---|
| 1124 | fflush(stderr); |
---|
| 1125 | |
---|
| 1126 | xmlAddChild(n,nc); |
---|
| 1127 | |
---|
| 1128 | nc = xmlNewNode(ns, BAD_CAST "Status"); |
---|
| 1129 | const struct tm *tm; |
---|
| 1130 | size_t len; |
---|
| 1131 | time_t now; |
---|
| 1132 | char *tmp1; |
---|
[26] | 1133 | map *tmpStatus; |
---|
[9] | 1134 | |
---|
| 1135 | now = time ( NULL ); |
---|
| 1136 | tm = localtime ( &now ); |
---|
| 1137 | |
---|
| 1138 | tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char)); |
---|
| 1139 | |
---|
| 1140 | len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm ); |
---|
| 1141 | |
---|
[26] | 1142 | xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1); |
---|
| 1143 | |
---|
| 1144 | char sMsg[2048]; |
---|
[9] | 1145 | switch(status){ |
---|
| 1146 | case SERVICE_SUCCEEDED: |
---|
| 1147 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); |
---|
[34] | 1148 | sprintf(sMsg,_("Service \"%s\" run successfully."),serv->name); |
---|
[26] | 1149 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1150 | xmlAddChild(nc1,nc3); |
---|
[9] | 1151 | break; |
---|
| 1152 | case SERVICE_STARTED: |
---|
| 1153 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); |
---|
[26] | 1154 | tmpStatus=getMapFromMaps(m,"lenv","status"); |
---|
| 1155 | xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); |
---|
[34] | 1156 | 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] | 1157 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1158 | xmlAddChild(nc1,nc3); |
---|
[9] | 1159 | break; |
---|
| 1160 | case SERVICE_ACCEPTED: |
---|
| 1161 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); |
---|
[34] | 1162 | 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] | 1163 | nc3=xmlNewText(BAD_CAST sMsg); |
---|
| 1164 | xmlAddChild(nc1,nc3); |
---|
[9] | 1165 | break; |
---|
| 1166 | case SERVICE_FAILED: |
---|
| 1167 | nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); |
---|
[26] | 1168 | map *errorMap; |
---|
| 1169 | map *te; |
---|
| 1170 | te=getMapFromMaps(m,"lenv","code"); |
---|
| 1171 | if(te!=NULL) |
---|
| 1172 | errorMap=createMap("code",te->value); |
---|
| 1173 | else |
---|
| 1174 | errorMap=createMap("code","NoApplicableCode"); |
---|
| 1175 | te=getMapFromMaps(m,"lenv","message"); |
---|
| 1176 | if(te!=NULL) |
---|
[57] | 1177 | addToMap(errorMap,"text",_ss(te->value)); |
---|
[26] | 1178 | else |
---|
[34] | 1179 | addToMap(errorMap,"text",_("No more information available")); |
---|
[26] | 1180 | nc3=createExceptionReportNode(m,errorMap,0); |
---|
[59] | 1181 | freeMap(&errorMap); |
---|
| 1182 | free(errorMap); |
---|
[26] | 1183 | xmlAddChild(nc1,nc3); |
---|
[9] | 1184 | break; |
---|
| 1185 | default : |
---|
[34] | 1186 | printf(_("error code not know : %i\n"),status); |
---|
[26] | 1187 | //exit(1); |
---|
[9] | 1188 | break; |
---|
| 1189 | } |
---|
| 1190 | xmlAddChild(nc,nc1); |
---|
| 1191 | xmlAddChild(n,nc); |
---|
| 1192 | free(tmp1); |
---|
| 1193 | |
---|
| 1194 | #ifdef DEBUG |
---|
| 1195 | fprintf(stderr,"printProcessResponse 1 161\n"); |
---|
| 1196 | #endif |
---|
| 1197 | |
---|
| 1198 | map* lineage=getMap(request,"lineage"); |
---|
| 1199 | if(lineage!=NULL){ |
---|
| 1200 | nc = xmlNewNode(ns, BAD_CAST "DataInputs"); |
---|
| 1201 | int i; |
---|
| 1202 | maps* mcursor=inputs; |
---|
[65] | 1203 | elements* scursor=NULL; |
---|
[9] | 1204 | while(mcursor!=NULL /*&& scursor!=NULL*/){ |
---|
[65] | 1205 | scursor=getElements(serv->inputs,mcursor->name); |
---|
[9] | 1206 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Input"); |
---|
| 1207 | mcursor=mcursor->next; |
---|
| 1208 | } |
---|
| 1209 | xmlAddChild(n,nc); |
---|
| 1210 | |
---|
| 1211 | #ifdef DEBUG |
---|
| 1212 | fprintf(stderr,"printProcessResponse 1 177\n"); |
---|
| 1213 | #endif |
---|
| 1214 | |
---|
| 1215 | nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); |
---|
| 1216 | mcursor=outputs; |
---|
[65] | 1217 | scursor=NULL; |
---|
| 1218 | while(mcursor!=NULL){ |
---|
| 1219 | scursor=getElements(serv->outputs,mcursor->name); |
---|
[9] | 1220 | printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
| 1221 | mcursor=mcursor->next; |
---|
| 1222 | } |
---|
| 1223 | xmlAddChild(n,nc); |
---|
| 1224 | } |
---|
| 1225 | #ifdef DEBUG |
---|
| 1226 | fprintf(stderr,"printProcessResponse 1 190\n"); |
---|
| 1227 | #endif |
---|
| 1228 | |
---|
| 1229 | /** |
---|
| 1230 | * Display the process output only when requested ! |
---|
| 1231 | */ |
---|
| 1232 | if(status==SERVICE_SUCCEEDED){ |
---|
| 1233 | nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); |
---|
| 1234 | maps* mcursor=outputs; |
---|
| 1235 | elements* scursor=serv->outputs; |
---|
[63] | 1236 | while(mcursor!=NULL){ |
---|
[65] | 1237 | scursor=getElements(serv->outputs,mcursor->name); |
---|
[9] | 1238 | printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); |
---|
| 1239 | mcursor=mcursor->next; |
---|
| 1240 | } |
---|
| 1241 | xmlAddChild(n,nc); |
---|
| 1242 | } |
---|
| 1243 | #ifdef DEBUG |
---|
| 1244 | fprintf(stderr,"printProcessResponse 1 202\n"); |
---|
| 1245 | #endif |
---|
| 1246 | xmlDocSetRootElement(doc, n); |
---|
[72] | 1247 | if(hasStoredExecuteResponse){ |
---|
| 1248 | /* We need to write the ExecuteResponse Document somewhere */ |
---|
| 1249 | FILE* output=fopen(stored_path,"w"); |
---|
| 1250 | xmlChar *xmlbuff; |
---|
| 1251 | int buffersize; |
---|
| 1252 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); |
---|
| 1253 | fwrite(xmlbuff,1,strlen(xmlbuff)*sizeof(char),output); |
---|
| 1254 | xmlFree(xmlbuff); |
---|
| 1255 | fclose(output); |
---|
| 1256 | } |
---|
[9] | 1257 | printDocument(m,doc,pid); |
---|
| 1258 | |
---|
| 1259 | xmlCleanupParser(); |
---|
| 1260 | zooXmlCleanupNs(); |
---|
| 1261 | } |
---|
| 1262 | |
---|
| 1263 | |
---|
| 1264 | void printDocument(maps* m, xmlDocPtr doc,int pid){ |
---|
| 1265 | rewind(stdout); |
---|
| 1266 | char *encoding=getEncoding(m); |
---|
| 1267 | if(pid==getpid()){ |
---|
| 1268 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1269 | } |
---|
| 1270 | fflush(stdout); |
---|
| 1271 | xmlChar *xmlbuff; |
---|
| 1272 | int buffersize; |
---|
[1] | 1273 | /* |
---|
[9] | 1274 | * Dump the document to a buffer and print it on stdout |
---|
[1] | 1275 | * for demonstration purposes. |
---|
| 1276 | */ |
---|
[9] | 1277 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
[1] | 1278 | printf((char *) xmlbuff); |
---|
[9] | 1279 | //fflush(stdout); |
---|
[1] | 1280 | /* |
---|
| 1281 | * Free associated memory. |
---|
| 1282 | */ |
---|
| 1283 | xmlFree(xmlbuff); |
---|
[9] | 1284 | xmlFreeDoc(doc); |
---|
| 1285 | xmlCleanupParser(); |
---|
| 1286 | zooXmlCleanupNs(); |
---|
[1] | 1287 | } |
---|
| 1288 | |
---|
| 1289 | void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
| 1290 | xmlNodePtr nc1; |
---|
| 1291 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
| 1292 | map *tmp=NULL; |
---|
| 1293 | if(e!=NULL && e->defaults!=NULL) |
---|
| 1294 | tmp=e->defaults->content; |
---|
| 1295 | else{ |
---|
| 1296 | /* |
---|
| 1297 | dumpElements(e); |
---|
| 1298 | */ |
---|
| 1299 | return; |
---|
| 1300 | } |
---|
| 1301 | while(tmp!=NULL){ |
---|
[9] | 1302 | if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 |
---|
| 1303 | || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 |
---|
| 1304 | || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 |
---|
| 1305 | || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) |
---|
[1] | 1306 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1307 | tmp=tmp->next; |
---|
| 1308 | } |
---|
| 1309 | tmp=getMap(e->defaults->content,"asReference"); |
---|
| 1310 | if(tmp==NULL) |
---|
| 1311 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
| 1312 | |
---|
| 1313 | tmp=e->content; |
---|
| 1314 | |
---|
| 1315 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
| 1316 | |
---|
| 1317 | xmlAddChild(nc,nc1); |
---|
| 1318 | |
---|
| 1319 | } |
---|
| 1320 | |
---|
| 1321 | void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){ |
---|
| 1322 | xmlNodePtr nc1,nc2,nc3; |
---|
| 1323 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
| 1324 | map *tmp=NULL; |
---|
| 1325 | if(e!=NULL && e->defaults!=NULL) |
---|
| 1326 | tmp=e->defaults->content; |
---|
| 1327 | else{ |
---|
| 1328 | /* |
---|
| 1329 | dumpElements(e); |
---|
| 1330 | */ |
---|
| 1331 | return; |
---|
| 1332 | } |
---|
| 1333 | while(tmp!=NULL){ |
---|
| 1334 | xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1335 | tmp=tmp->next; |
---|
| 1336 | } |
---|
| 1337 | tmp=getMap(e->defaults->content,"asReference"); |
---|
| 1338 | if(tmp==NULL) |
---|
| 1339 | xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); |
---|
| 1340 | |
---|
| 1341 | tmp=e->content; |
---|
| 1342 | |
---|
| 1343 | printDescription(nc1,ns_ows,m->name,e->content); |
---|
| 1344 | |
---|
| 1345 | xmlAddChild(nc,nc1); |
---|
| 1346 | |
---|
| 1347 | } |
---|
| 1348 | |
---|
[9] | 1349 | void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){ |
---|
[1] | 1350 | xmlNodePtr nc1,nc2,nc3; |
---|
| 1351 | nc1=xmlNewNode(ns_wps, BAD_CAST type); |
---|
[65] | 1352 | map *tmp=NULL; |
---|
| 1353 | if(e!=NULL) |
---|
| 1354 | tmp=e->content; |
---|
| 1355 | else |
---|
| 1356 | tmp=m->content; |
---|
[26] | 1357 | #ifdef DEBUG |
---|
[1] | 1358 | dumpMap(tmp); |
---|
| 1359 | dumpElements(e); |
---|
[26] | 1360 | #endif |
---|
[1] | 1361 | nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
[65] | 1362 | if(e!=NULL) |
---|
| 1363 | nc3=xmlNewText(BAD_CAST e->name); |
---|
| 1364 | else |
---|
| 1365 | nc3=xmlNewText(BAD_CAST m->name); |
---|
[9] | 1366 | xmlAddChild(nc2,nc3); |
---|
[1] | 1367 | xmlAddChild(nc1,nc2); |
---|
| 1368 | xmlAddChild(nc,nc1); |
---|
[9] | 1369 | // Extract Title required to be first element in the ZCFG file ! |
---|
[65] | 1370 | bool isTitle=true; |
---|
| 1371 | if(e!=NULL) |
---|
| 1372 | tmp=getMap(e->content,"Title"); |
---|
| 1373 | else |
---|
| 1374 | tmp=getMap(m->content,"Title"); |
---|
| 1375 | |
---|
| 1376 | if(tmp!=NULL){ |
---|
[43] | 1377 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
| 1378 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
| 1379 | xmlAddChild(nc2,nc3); |
---|
| 1380 | xmlAddChild(nc1,nc2); |
---|
[65] | 1381 | } |
---|
| 1382 | |
---|
| 1383 | if(e!=NULL) |
---|
| 1384 | tmp=getMap(e->content,"Abstract"); |
---|
| 1385 | else |
---|
| 1386 | tmp=getMap(m->content,"Abstract"); |
---|
| 1387 | if(tmp!=NULL){ |
---|
| 1388 | nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); |
---|
| 1389 | nc3=xmlNewText(BAD_CAST _ss(tmp->value)); |
---|
| 1390 | xmlAddChild(nc2,nc3); |
---|
| 1391 | xmlAddChild(nc1,nc2); |
---|
[43] | 1392 | xmlAddChild(nc,nc1); |
---|
| 1393 | } |
---|
[1] | 1394 | |
---|
| 1395 | /** |
---|
| 1396 | * IO type Reference or full Data ? |
---|
| 1397 | */ |
---|
[26] | 1398 | #ifdef DEBUG |
---|
[9] | 1399 | fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); |
---|
[26] | 1400 | #endif |
---|
[9] | 1401 | map *tmpMap=getMap(m->content,"Reference"); |
---|
| 1402 | if(tmpMap==NULL){ |
---|
| 1403 | nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); |
---|
[65] | 1404 | if(e!=NULL){ |
---|
| 1405 | if(strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0) |
---|
| 1406 | nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); |
---|
[9] | 1407 | else |
---|
[65] | 1408 | if(strncasecmp(e->format,"COMPLEXOUTPUT",strlen(e->format))==0) |
---|
| 1409 | nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); |
---|
| 1410 | else |
---|
| 1411 | nc3=xmlNewNode(ns_wps, BAD_CAST e->format); |
---|
| 1412 | } |
---|
| 1413 | else{ |
---|
| 1414 | map* tmpV=getMapFromMaps(m,"format","value"); |
---|
| 1415 | if(tmpV!=NULL) |
---|
| 1416 | nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); |
---|
| 1417 | else |
---|
| 1418 | nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData"); |
---|
| 1419 | } |
---|
[9] | 1420 | tmp=m->content; |
---|
| 1421 | while(tmp!=NULL){ |
---|
[70] | 1422 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
| 1423 | strcasecmp(tmp->name,"encoding")==0 || |
---|
| 1424 | strcasecmp(tmp->name,"schema")==0 || |
---|
| 1425 | strcasecmp(tmp->name,"datatype")==0 || |
---|
| 1426 | strcasecmp(tmp->name,"uom")==0) |
---|
[9] | 1427 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1428 | tmp=tmp->next; |
---|
| 1429 | xmlAddChild(nc2,nc3); |
---|
[1] | 1430 | } |
---|
[65] | 1431 | if(e!=NULL) |
---|
| 1432 | tmp=getMap(e->defaults->content,"mimeType"); |
---|
| 1433 | else |
---|
| 1434 | tmp=NULL; |
---|
[9] | 1435 | map* tmp1=getMap(m->content,"encoding"); |
---|
| 1436 | map* tmp2=getMap(m->content,"mimeType"); |
---|
| 1437 | map* toto=getMap(m->content,"value"); |
---|
| 1438 | if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) |
---|
| 1439 | || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 |
---|
| 1440 | || strncmp(tmp2->value,"application/",6)==0)) ){ |
---|
| 1441 | map* rs=getMap(m->content,"size"); |
---|
[59] | 1442 | bool isSized=true; |
---|
[9] | 1443 | if(rs==NULL){ |
---|
| 1444 | char tmp1[1024]; |
---|
| 1445 | sprintf(tmp1,"%d",strlen(toto->value)); |
---|
| 1446 | rs=createMap("z",tmp1); |
---|
[59] | 1447 | isSized=false; |
---|
[9] | 1448 | } |
---|
| 1449 | xmlAddChild(nc3,xmlNewText(BAD_CAST base64((const unsigned char*)toto->value,atoi(rs->value)))); |
---|
[59] | 1450 | if(!isSized){ |
---|
| 1451 | freeMap(&rs); |
---|
| 1452 | free(rs); |
---|
| 1453 | } |
---|
[9] | 1454 | } |
---|
| 1455 | else if(tmp!=NULL){ |
---|
[32] | 1456 | if(strncmp(tmp->value,"text/js",4)==0 || |
---|
| 1457 | strncmp(tmp->value,"application/js",14)==0) |
---|
[9] | 1458 | xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value))); |
---|
| 1459 | else |
---|
| 1460 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
| 1461 | xmlAddChild(nc2,nc3); |
---|
| 1462 | } |
---|
[1] | 1463 | else |
---|
| 1464 | xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value)); |
---|
| 1465 | } |
---|
[9] | 1466 | else{ |
---|
| 1467 | nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); |
---|
| 1468 | xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); |
---|
| 1469 | tmp=m->content; |
---|
| 1470 | while(tmp!=NULL){ |
---|
[70] | 1471 | if(strcasecmp(tmp->name,"mimeType")==0 || |
---|
| 1472 | strcasecmp(tmp->name,"encoding")==0 || |
---|
| 1473 | strcasecmp(tmp->name,"schema")==0 || |
---|
| 1474 | strcasecmp(tmp->name,"datatype")==0 || |
---|
| 1475 | strcasecmp(tmp->name,"uom")==0) |
---|
[9] | 1476 | xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); |
---|
| 1477 | tmp=tmp->next; |
---|
| 1478 | xmlAddChild(nc2,nc3); |
---|
| 1479 | } |
---|
[1] | 1480 | } |
---|
| 1481 | |
---|
| 1482 | xmlAddChild(nc1,nc2); |
---|
| 1483 | xmlAddChild(nc,nc1); |
---|
| 1484 | |
---|
| 1485 | } |
---|
| 1486 | |
---|
| 1487 | void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,char* identifier,map* amap){ |
---|
| 1488 | xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); |
---|
| 1489 | xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); |
---|
| 1490 | xmlAddChild(root,nc2); |
---|
| 1491 | map* tmp=amap; |
---|
| 1492 | char *tmp2[2]; |
---|
| 1493 | tmp2[0]="Title"; |
---|
| 1494 | tmp2[1]="Abstract"; |
---|
| 1495 | int j=0; |
---|
| 1496 | for(j=0;j<2;j++){ |
---|
| 1497 | map* tmp1=getMap(tmp,tmp2[j]); |
---|
| 1498 | if(tmp1!=NULL){ |
---|
| 1499 | nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); |
---|
[34] | 1500 | xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); |
---|
[1] | 1501 | xmlAddChild(root,nc2); |
---|
| 1502 | } |
---|
| 1503 | } |
---|
| 1504 | } |
---|
| 1505 | |
---|
[9] | 1506 | char* getEncoding(maps* m){ |
---|
| 1507 | if(m!=NULL){ |
---|
| 1508 | map* tmp=getMap(m->content,"encoding"); |
---|
[1] | 1509 | if(tmp!=NULL){ |
---|
[9] | 1510 | return tmp->value; |
---|
[1] | 1511 | } |
---|
| 1512 | else |
---|
[9] | 1513 | return "UTF-8"; |
---|
[1] | 1514 | } |
---|
| 1515 | else |
---|
[9] | 1516 | return "UTF-8"; |
---|
| 1517 | } |
---|
[1] | 1518 | |
---|
[9] | 1519 | char* getVersion(maps* m){ |
---|
| 1520 | if(m!=NULL){ |
---|
| 1521 | map* tmp=getMap(m->content,"version"); |
---|
[1] | 1522 | if(tmp!=NULL){ |
---|
[9] | 1523 | return tmp->value; |
---|
[1] | 1524 | } |
---|
| 1525 | else |
---|
[9] | 1526 | return "1.0.0"; |
---|
[1] | 1527 | } |
---|
| 1528 | else |
---|
[9] | 1529 | return "1.0.0"; |
---|
| 1530 | } |
---|
[1] | 1531 | |
---|
[9] | 1532 | void printExceptionReportResponse(maps* m,map* s){ |
---|
| 1533 | int buffersize; |
---|
| 1534 | xmlDocPtr doc; |
---|
| 1535 | xmlChar *xmlbuff; |
---|
[34] | 1536 | xmlNodePtr n; |
---|
[1] | 1537 | |
---|
[9] | 1538 | doc = xmlNewDoc(BAD_CAST "1.0"); |
---|
| 1539 | maps* tmpMap=getMaps(m,"main"); |
---|
| 1540 | char *encoding=getEncoding(tmpMap); |
---|
[32] | 1541 | if(m!=NULL){ |
---|
| 1542 | map *tmpSid=getMapFromMaps(m,"lenv","sid"); |
---|
| 1543 | if(tmpSid!=NULL){ |
---|
| 1544 | if( getpid()==atoi(tmpSid->value) ) |
---|
| 1545 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1546 | } |
---|
| 1547 | else |
---|
| 1548 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
| 1549 | }else |
---|
[26] | 1550 | printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); |
---|
[34] | 1551 | n=createExceptionReportNode(m,s,1); |
---|
[1] | 1552 | xmlDocSetRootElement(doc, n); |
---|
[9] | 1553 | xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); |
---|
| 1554 | printf("%s",xmlbuff); |
---|
| 1555 | fflush(stdout); |
---|
| 1556 | xmlFreeDoc(doc); |
---|
[1] | 1557 | xmlFree(xmlbuff); |
---|
[9] | 1558 | xmlCleanupParser(); |
---|
[57] | 1559 | zooXmlCleanupNs(); |
---|
[1] | 1560 | } |
---|
| 1561 | |
---|
[26] | 1562 | xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ |
---|
| 1563 | |
---|
| 1564 | int buffersize; |
---|
| 1565 | xmlChar *xmlbuff; |
---|
| 1566 | xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; |
---|
| 1567 | xmlNodePtr n,nc,nc1,nc2; |
---|
[1] | 1568 | |
---|
[26] | 1569 | maps* tmpMap=getMaps(m,"main"); |
---|
| 1570 | |
---|
[57] | 1571 | int nsid=zooXmlAddNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
| 1572 | ns=usedNs[nsid]; |
---|
[26] | 1573 | n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); |
---|
| 1574 | |
---|
| 1575 | if(use_ns==1){ |
---|
| 1576 | ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); |
---|
| 1577 | int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); |
---|
| 1578 | ns_xsi=usedNs[xsiId]; |
---|
| 1579 | int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); |
---|
| 1580 | ns_xlink=usedNs[xlinkId]; |
---|
| 1581 | 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"); |
---|
| 1582 | } |
---|
[34] | 1583 | addLangAttr(n,m); |
---|
[26] | 1584 | xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); |
---|
| 1585 | |
---|
| 1586 | nc = xmlNewNode(ns, BAD_CAST "Exception"); |
---|
| 1587 | |
---|
| 1588 | map* tmp=getMap(s,"code"); |
---|
| 1589 | if(tmp!=NULL) |
---|
| 1590 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); |
---|
| 1591 | else |
---|
| 1592 | xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); |
---|
| 1593 | |
---|
| 1594 | tmp=getMap(s,"text"); |
---|
| 1595 | nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); |
---|
| 1596 | nc2=NULL; |
---|
| 1597 | if(tmp!=NULL){ |
---|
| 1598 | xmlNodeSetContent(nc1, BAD_CAST tmp->value); |
---|
| 1599 | } |
---|
| 1600 | else{ |
---|
[34] | 1601 | xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); |
---|
[26] | 1602 | } |
---|
| 1603 | xmlAddChild(nc,nc1); |
---|
| 1604 | xmlAddChild(n,nc); |
---|
| 1605 | return n; |
---|
| 1606 | } |
---|
| 1607 | |
---|
| 1608 | |
---|
[1] | 1609 | void outputResponse(service* s,maps* request_inputs,maps* request_outputs, |
---|
| 1610 | map* request_inputs1,int cpid,maps* m,int res){ |
---|
| 1611 | #ifdef DEBUG |
---|
| 1612 | dumpMaps(request_inputs); |
---|
| 1613 | dumpMaps(request_outputs); |
---|
| 1614 | fprintf(stderr,"printProcessResponse\n"); |
---|
| 1615 | #endif |
---|
| 1616 | map* toto=getMap(request_inputs1,"RawDataOutput"); |
---|
| 1617 | int asRaw=0; |
---|
| 1618 | if(toto!=NULL) |
---|
| 1619 | asRaw=1; |
---|
[9] | 1620 | |
---|
[1] | 1621 | if(asRaw==0){ |
---|
[9] | 1622 | #ifdef DEBUG |
---|
| 1623 | fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); |
---|
| 1624 | dumpMaps(request_outputs); |
---|
| 1625 | #endif |
---|
[70] | 1626 | maps* tmpI=request_outputs; |
---|
| 1627 | while(tmpI!=NULL){ |
---|
| 1628 | toto=getMap(tmpI->content,"asReference"); |
---|
| 1629 | if(toto!=NULL && strcasecmp(toto->value,"true")==0){ |
---|
| 1630 | |
---|
| 1631 | toto=getMap(tmpI->content,"extension"); |
---|
| 1632 | map *tmp1=getMapFromMaps(m,"main","tmpPath"); |
---|
| 1633 | char *file_name; |
---|
| 1634 | bool hasExt=true; |
---|
| 1635 | if(toto==NULL){ |
---|
| 1636 | dumpMaps(tmpI); |
---|
| 1637 | // We can fallback to a default list of supported formats using |
---|
| 1638 | // mimeType information if present here. Maybe we can add more formats |
---|
| 1639 | // here. |
---|
| 1640 | // If mimeType was not found, we then set txt as the default extension. |
---|
| 1641 | map* mtype=getMap(tmpI->content,"mimeType"); |
---|
| 1642 | if(mtype!=NULL){ |
---|
| 1643 | if(strcasecmp(mtype->value,"text/xml")==0) |
---|
| 1644 | toto=createMap("extension","xml"); |
---|
| 1645 | else if(strcasecmp(mtype->value,"application/json")==0) |
---|
| 1646 | toto=createMap("extension","js"); |
---|
| 1647 | else |
---|
| 1648 | toto=createMap("extension","txt"); |
---|
| 1649 | } |
---|
[57] | 1650 | else |
---|
| 1651 | toto=createMap("extension","txt"); |
---|
[70] | 1652 | hasExt=false; |
---|
[57] | 1653 | } |
---|
[70] | 1654 | file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(toto->value)+strlen(tmpI->name)+13)*sizeof(char)); |
---|
| 1655 | sprintf(file_name,"%s/%s_%s_%i.%s",tmp1->value,s->name,tmpI->name,cpid+100000,toto->value); |
---|
| 1656 | FILE *ofile=fopen(file_name,"w"); |
---|
| 1657 | if(ofile==NULL) |
---|
| 1658 | fprintf(stderr,"Unable to create file on disk implying segfault ! \n"); |
---|
| 1659 | map *tmp2=getMapFromMaps(m,"main","tmpUrl"); |
---|
| 1660 | map *tmp3=getMapFromMaps(m,"main","serverAddress"); |
---|
| 1661 | char *file_url; |
---|
| 1662 | file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(s->name)+strlen(toto->value)+strlen(tmpI->name)+13)*sizeof(char)); |
---|
| 1663 | sprintf(file_url,"%s/%s/%s_%s_%i.%s",tmp3->value,tmp2->value,s->name,tmpI->name,cpid+100000,toto->value); |
---|
| 1664 | addToMap(tmpI->content,"Reference",file_url); |
---|
| 1665 | if(hasExt!=true){ |
---|
| 1666 | freeMap(&toto); |
---|
| 1667 | free(toto); |
---|
| 1668 | } |
---|
| 1669 | toto=getMap(tmpI->content,"value"); |
---|
| 1670 | map* size=getMap(tmpI->content,"size"); |
---|
| 1671 | if(size!=NULL && toto!=NULL) |
---|
| 1672 | fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile); |
---|
[63] | 1673 | else |
---|
[70] | 1674 | if(toto!=NULL && toto->value!=NULL) |
---|
| 1675 | fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); |
---|
| 1676 | fclose(ofile); |
---|
| 1677 | free(file_name); |
---|
| 1678 | free(file_url); |
---|
[52] | 1679 | } |
---|
[70] | 1680 | tmpI=tmpI->next; |
---|
[9] | 1681 | } |
---|
[1] | 1682 | map *r_inputs=getMap(s->content,"serviceProvider"); |
---|
| 1683 | #ifdef DEBUG |
---|
| 1684 | fprintf(stderr,"SERVICE : %s\n",r_inputs->value); |
---|
| 1685 | dumpMaps(m); |
---|
| 1686 | #endif |
---|
[9] | 1687 | printProcessResponse(m,request_inputs1,cpid, |
---|
[26] | 1688 | s,r_inputs->value,res, |
---|
| 1689 | request_inputs, |
---|
| 1690 | request_outputs); |
---|
[1] | 1691 | } |
---|
[26] | 1692 | else |
---|
| 1693 | if(res!=SERVICE_FAILED){ |
---|
| 1694 | /** |
---|
[66] | 1695 | * We get the requested output or fallback to the first one if the |
---|
| 1696 | * requested one is not present in the resulting outputs maps. |
---|
[26] | 1697 | */ |
---|
[66] | 1698 | maps* tmpI=NULL; |
---|
| 1699 | map* tmpIV=getMap(request_inputs1,"RawDataOutput"); |
---|
| 1700 | if(tmpIV!=NULL){ |
---|
| 1701 | tmpI=getMaps(request_outputs,tmpIV->value); |
---|
| 1702 | } |
---|
| 1703 | if(tmpI==NULL) |
---|
| 1704 | tmpI=request_outputs; |
---|
| 1705 | toto=getMap(tmpI->content,"value"); |
---|
[32] | 1706 | if(toto==NULL){ |
---|
[34] | 1707 | map * errormap = createMap("text",_("Unable to fetch any result")); |
---|
[32] | 1708 | addToMap(errormap,"code", "InternalError"); |
---|
| 1709 | printExceptionReportResponse(m,errormap); |
---|
| 1710 | freeMap(&errormap); |
---|
| 1711 | free(errormap); |
---|
| 1712 | } |
---|
[26] | 1713 | char mime[1024]; |
---|
[66] | 1714 | map* mi=getMap(tmpI->content,"mimeType"); |
---|
[1] | 1715 | #ifdef DEBUG |
---|
[26] | 1716 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
| 1717 | dumpMaps(request_outputs); |
---|
| 1718 | fprintf(stderr,"SERVICE OUTPUTS\n"); |
---|
[1] | 1719 | #endif |
---|
[66] | 1720 | map* en=getMap(tmpI->content,"encoding"); |
---|
[26] | 1721 | if(mi!=NULL && en!=NULL) |
---|
[1] | 1722 | sprintf(mime, |
---|
[26] | 1723 | "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", |
---|
| 1724 | mi->value,en->value); |
---|
[1] | 1725 | else |
---|
[26] | 1726 | if(mi!=NULL) |
---|
| 1727 | sprintf(mime, |
---|
| 1728 | "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", |
---|
| 1729 | mi->value); |
---|
| 1730 | else |
---|
| 1731 | sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); |
---|
| 1732 | printf("%s",mime); |
---|
| 1733 | if(mi!=NULL && strncmp(mi->value,"image",5)==0){ |
---|
[66] | 1734 | map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); |
---|
[26] | 1735 | fwrite(toto->value,atoi(rs->value),1,stdout); |
---|
| 1736 | } |
---|
| 1737 | else |
---|
| 1738 | printf("%s",toto->value); |
---|
[1] | 1739 | #ifdef DEBUG |
---|
[26] | 1740 | dumpMap(toto); |
---|
[1] | 1741 | #endif |
---|
[26] | 1742 | }else{ |
---|
| 1743 | char tmp[1024]; |
---|
| 1744 | map * errormap; |
---|
| 1745 | map *lenv; |
---|
| 1746 | lenv=getMapFromMaps(m,"lenv","message"); |
---|
| 1747 | if(lenv!=NULL) |
---|
[34] | 1748 | sprintf(tmp,_("Unable to run the Service. The message returned back by the Service was the following : %s"),lenv->value); |
---|
[26] | 1749 | else |
---|
[34] | 1750 | sprintf(tmp,_("Unable to run the Service. No more information was returned back by the Service.")); |
---|
[26] | 1751 | errormap = createMap("text",tmp); |
---|
| 1752 | addToMap(errormap,"code", "InternalError"); |
---|
| 1753 | printExceptionReportResponse(m,errormap); |
---|
| 1754 | freeMap(&errormap); |
---|
| 1755 | free(errormap); |
---|
| 1756 | } |
---|
[1] | 1757 | } |
---|
| 1758 | |
---|
| 1759 | char *base64(const unsigned char *input, int length) |
---|
| 1760 | { |
---|
| 1761 | BIO *bmem, *b64; |
---|
| 1762 | BUF_MEM *bptr; |
---|
| 1763 | |
---|
| 1764 | b64 = BIO_new(BIO_f_base64()); |
---|
| 1765 | bmem = BIO_new(BIO_s_mem()); |
---|
| 1766 | b64 = BIO_push(b64, bmem); |
---|
| 1767 | BIO_write(b64, input, length); |
---|
| 1768 | BIO_flush(b64); |
---|
| 1769 | BIO_get_mem_ptr(b64, &bptr); |
---|
| 1770 | |
---|
| 1771 | char *buff = (char *)malloc(bptr->length); |
---|
| 1772 | memcpy(buff, bptr->data, bptr->length-1); |
---|
| 1773 | buff[bptr->length-1] = 0; |
---|
| 1774 | |
---|
| 1775 | BIO_free_all(b64); |
---|
| 1776 | |
---|
| 1777 | return buff; |
---|
| 1778 | } |
---|
| 1779 | |
---|
[63] | 1780 | char* addDefaultValues(maps** out,elements* in,maps* m,int type){ |
---|
[1] | 1781 | elements* tmpInputs=in; |
---|
| 1782 | maps* out1=*out; |
---|
| 1783 | while(tmpInputs!=NULL){ |
---|
| 1784 | maps *tmpMaps=getMaps(out1,tmpInputs->name); |
---|
| 1785 | if(tmpMaps==NULL){ |
---|
[9] | 1786 | maps* tmpMaps2=(maps*)malloc(MAPS_SIZE); |
---|
[57] | 1787 | tmpMaps2->name=strdup(tmpInputs->name); |
---|
[9] | 1788 | tmpMaps2->content=NULL; |
---|
| 1789 | tmpMaps2->next=NULL; |
---|
[63] | 1790 | |
---|
| 1791 | if(type==0){ |
---|
| 1792 | map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs"); |
---|
| 1793 | if(tmpMapMinO!=NULL) |
---|
| 1794 | if(atoi(tmpMapMinO->value)>=1){ |
---|
| 1795 | freeMaps(&tmpMaps2); |
---|
| 1796 | free(tmpMaps2); |
---|
| 1797 | return tmpInputs->name; |
---|
| 1798 | } |
---|
| 1799 | else{ |
---|
| 1800 | if(tmpMaps2->content==NULL) |
---|
| 1801 | tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value); |
---|
| 1802 | else |
---|
| 1803 | addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value); |
---|
| 1804 | } |
---|
| 1805 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
| 1806 | if(tmpMaxO!=NULL) |
---|
| 1807 | if(tmpMaps2->content==NULL) |
---|
| 1808 | tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); |
---|
| 1809 | else |
---|
| 1810 | addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); |
---|
| 1811 | } |
---|
| 1812 | |
---|
[1] | 1813 | iotype* tmpIoType=tmpInputs->defaults; |
---|
[63] | 1814 | if(tmpIoType!=NULL){ |
---|
| 1815 | map* tmpm=tmpIoType->content; |
---|
| 1816 | while(tmpm!=NULL){ |
---|
| 1817 | if(tmpMaps2->content==NULL) |
---|
| 1818 | tmpMaps2->content=createMap(tmpm->name,tmpm->value); |
---|
| 1819 | else |
---|
| 1820 | addToMap(tmpMaps2->content,tmpm->name,tmpm->value); |
---|
| 1821 | tmpm=tmpm->next; |
---|
| 1822 | } |
---|
[1] | 1823 | } |
---|
[63] | 1824 | if(type==1){ |
---|
[57] | 1825 | map *tmpMap=getMap(tmpMaps2->content,"value"); |
---|
| 1826 | if(tmpMap==NULL) |
---|
| 1827 | addToMap(tmpMaps2->content,"value","NULL"); |
---|
| 1828 | } |
---|
[1] | 1829 | if(out1==NULL){ |
---|
[9] | 1830 | *out=dupMaps(&tmpMaps2); |
---|
[63] | 1831 | out1=*out; |
---|
[1] | 1832 | } |
---|
| 1833 | else |
---|
[9] | 1834 | addMapsToMaps(&out1,tmpMaps2); |
---|
[63] | 1835 | freeMap(&tmpMaps2->content); |
---|
| 1836 | free(tmpMaps2->content); |
---|
| 1837 | tmpMaps2->content=NULL; |
---|
[9] | 1838 | freeMaps(&tmpMaps2); |
---|
| 1839 | free(tmpMaps2); |
---|
| 1840 | tmpMaps2=NULL; |
---|
[1] | 1841 | } |
---|
| 1842 | else{ |
---|
[57] | 1843 | iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name, |
---|
| 1844 | tmpMaps->content); |
---|
[63] | 1845 | |
---|
| 1846 | if(type==0) { |
---|
| 1847 | map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); |
---|
| 1848 | if(tmpMap1!=NULL){ |
---|
| 1849 | if(tmpMaps->content==NULL) |
---|
| 1850 | tmpMaps->content=createMap("minOccurs",tmpMap1->value); |
---|
| 1851 | else |
---|
| 1852 | addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); |
---|
| 1853 | } |
---|
| 1854 | map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); |
---|
| 1855 | if(tmpMaxO!=NULL){ |
---|
| 1856 | if(tmpMaps->content==NULL) |
---|
| 1857 | tmpMaps->content=createMap("maxOccurs",tmpMap1->value); |
---|
| 1858 | else |
---|
| 1859 | addToMap(tmpMaps->content,"maxOccurs",tmpMap1->value); |
---|
| 1860 | } |
---|
| 1861 | } |
---|
| 1862 | |
---|
[57] | 1863 | if(tmpIoType!=NULL){ |
---|
| 1864 | map* tmpContent=tmpIoType->content; |
---|
| 1865 | map* cval=NULL; |
---|
| 1866 | |
---|
| 1867 | while(tmpContent!=NULL){ |
---|
| 1868 | if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){ |
---|
[9] | 1869 | #ifdef DEBUG |
---|
[57] | 1870 | fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value); |
---|
[9] | 1871 | #endif |
---|
[63] | 1872 | if(tmpMaps->content==NULL) |
---|
| 1873 | tmpMaps->content=createMap(tmpContent->name,tmpContent->value); |
---|
| 1874 | else |
---|
| 1875 | addToMap(tmpMaps->content,tmpContent->name,tmpContent->value); |
---|
[57] | 1876 | } |
---|
| 1877 | tmpContent=tmpContent->next; |
---|
[9] | 1878 | } |
---|
[1] | 1879 | } |
---|
| 1880 | } |
---|
| 1881 | tmpInputs=tmpInputs->next; |
---|
| 1882 | } |
---|
[9] | 1883 | return ""; |
---|
[1] | 1884 | } |
---|