Changeset 531
- Timestamp:
- Nov 5, 2014, 4:58:11 PM (10 years ago)
- Location:
- branches/PublicaMundi_David-devel/zoo-project/zoo-kernel
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal.c
r505 r531 37 37 #endif 38 38 39 int isValidLang(maps* conf,const char *str){ 40 map *tmpMap=getMapFromMaps(conf,"main","lang"); 41 char *tmp=zStrdup(tmpMap->value); 42 char *pToken=strtok(tmp,","); 43 int res=-1; 44 while(pToken!=NULL){ 45 if(strcasecmp(str,pToken)==0){ 46 res=1; 47 break; 48 } 49 pToken = strtok(NULL,","); 50 } 51 free(tmp); 39 int 40 isValidLang (maps * conf, const char *str) 41 { 42 map *tmpMap = getMapFromMaps (conf, "main", "lang"); 43 char *tmp = zStrdup (tmpMap->value); 44 char *pToken = strtok (tmp, ","); 45 int res = -1; 46 while (pToken != NULL) 47 { 48 if (strcasecmp (str, pToken) == 0) 49 { 50 res = 1; 51 break; 52 } 53 pToken = strtok (NULL, ","); 54 } 55 free (tmp); 52 56 return res; 53 57 } 54 58 55 void printHeaders(maps* m){ 56 maps *_tmp=getMaps(m,"headers"); 57 if(_tmp!=NULL){ 58 map* _tmp1=_tmp->content; 59 while(_tmp1!=NULL){ 60 printf("%s: %s\r\n",_tmp1->name,_tmp1->value); 61 _tmp1=_tmp1->next; 62 } 63 } 64 } 65 66 void addLangAttr(xmlNodePtr n,maps *m){ 67 map *tmpLmap=getMapFromMaps(m,"main","language"); 68 if(tmpLmap!=NULL) 69 xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value); 59 void 60 printHeaders (maps * m) 61 { 62 maps *_tmp = getMaps (m, "headers"); 63 if (_tmp != NULL) 64 { 65 map *_tmp1 = _tmp->content; 66 while (_tmp1 != NULL) 67 { 68 printf ("%s: %s\r\n", _tmp1->name, _tmp1->value); 69 _tmp1 = _tmp1->next; 70 } 71 } 72 } 73 74 void 75 addLangAttr (xmlNodePtr n, maps * m) 76 { 77 map *tmpLmap = getMapFromMaps (m, "main", "language"); 78 if (tmpLmap != NULL) 79 xmlNewProp (n, BAD_CAST "xml:lang", BAD_CAST tmpLmap->value); 70 80 else 71 xmlNewProp (n,BAD_CAST "xml:lang",BAD_CAST "en-US");81 xmlNewProp (n, BAD_CAST "xml:lang", BAD_CAST "en-US"); 72 82 } 73 83 74 84 /* Converts a hex character to its integer value */ 75 char from_hex(char ch) { 76 return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; 85 char 86 from_hex (char ch) 87 { 88 return isdigit (ch) ? ch - '0' : tolower (ch) - 'a' + 10; 77 89 } 78 90 79 91 /* Converts an integer value to its hex character*/ 80 char to_hex(char code) { 92 char 93 to_hex (char code) 94 { 81 95 static char hex[] = "0123456789abcdef"; 82 96 return hex[code & 15]; … … 93 107 #define SHMEMSIZE 4096 94 108 95 static LPVOID lpvMemG = NULL; // pointer to shared memory 96 static HANDLE hMapObjectG = NULL; // handle to file mapping 97 98 int _updateStatus(maps *conf){ 109 static LPVOID lpvMemG = NULL; // pointer to shared memory 110 static HANDLE hMapObjectG = NULL; // handle to file mapping 111 112 int 113 _updateStatus (maps * conf) 114 { 99 115 LPWSTR lpszTmp; 100 116 BOOL fInit; 101 char *final_string =NULL;102 char *s =NULL;117 char *final_string = NULL; 118 char *s = NULL; 103 119 map *tmpMap1; 104 map *tmpMap=getMapFromMaps(conf,"lenv","sid"); 105 if(hMapObjectG==NULL) 106 hMapObjectG = CreateFileMapping( 107 INVALID_HANDLE_VALUE, // use paging file 108 NULL, // default security attributes 109 PAGE_READWRITE, // read/write access 110 0, // size: high 32-bits 111 SHMEMSIZE, // size: low 32-bits 112 TEXT(tmpMap->value)); // name of map object 113 if (hMapObjectG == NULL){ 114 fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value); 115 return -2; 116 } 117 fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 118 if(lpvMemG==NULL) 119 lpvMemG = MapViewOfFile( 120 hMapObjectG, // object to map view of 121 FILE_MAP_WRITE, // read/write access 122 0, // high offset: map from 123 0, // low offset: beginning 124 0); // default: map entire file 125 if (lpvMemG == NULL){ 126 fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value); 127 return -1; 128 } 129 memset(lpvMemG, '\0', SHMEMSIZE); 130 tmpMap=getMapFromMaps(conf,"lenv","status"); 131 tmpMap1=NULL; 132 tmpMap1=getMapFromMaps(conf,"lenv","message"); 120 map *tmpMap = getMapFromMaps (conf, "lenv", "sid"); 121 if (hMapObjectG == NULL) 122 hMapObjectG = CreateFileMapping (INVALID_HANDLE_VALUE, // use paging file 123 NULL, // default security attributes 124 PAGE_READWRITE, // read/write access 125 0, // size: high 32-bits 126 SHMEMSIZE, // size: low 32-bits 127 TEXT (tmpMap->value)); // name of map object 128 if (hMapObjectG == NULL) 129 { 130 fprintf (stderr, "Unable to create share memory segment %s !! \n", 131 tmpMap->value); 132 return -2; 133 } 134 fInit = (GetLastError () != ERROR_ALREADY_EXISTS); 135 if (lpvMemG == NULL) 136 lpvMemG = MapViewOfFile (hMapObjectG, // object to map view of 137 FILE_MAP_WRITE, // read/write access 138 0, // high offset: map from 139 0, // low offset: beginning 140 0); // default: map entire file 141 if (lpvMemG == NULL) 142 { 143 fprintf (stderr, 144 "Unable to create or access the shared memory segment %s !! \n", 145 tmpMap->value); 146 return -1; 147 } 148 memset (lpvMemG, '\0', SHMEMSIZE); 149 tmpMap = getMapFromMaps (conf, "lenv", "status"); 150 tmpMap1 = NULL; 151 tmpMap1 = getMapFromMaps (conf, "lenv", "message"); 133 152 lpszTmp = (LPWSTR) lpvMemG; 134 final_string=(char*)malloc((strlen(tmpMap1->value)+strlen(tmpMap->value)+2)*sizeof(char)); 135 sprintf(final_string,"%s|%s",tmpMap->value,tmpMap1->value); 136 for(s=final_string;*s!='\0';*s++){ 137 *lpszTmp++ = *s; 138 } 153 final_string = 154 (char *) malloc ((strlen (tmpMap1->value) + strlen (tmpMap->value) + 2) * 155 sizeof (char)); 156 sprintf (final_string, "%s|%s", tmpMap->value, tmpMap1->value); 157 for (s = final_string; *s != '\0'; *s++) 158 { 159 *lpszTmp++ = *s; 160 } 139 161 *lpszTmp++ = '\0'; 140 free (final_string);162 free (final_string); 141 163 return 0; 142 164 } 143 165 144 char* getStatus(int pid){ 145 char *lpszBuf=(char*) malloc(SHMEMSIZE*sizeof(char)); 146 int i=0; 147 LPWSTR lpszTmp=NULL; 166 char * 167 getStatus (int pid) 168 { 169 char *lpszBuf = (char *) malloc (SHMEMSIZE * sizeof (char)); 170 int i = 0; 171 LPWSTR lpszTmp = NULL; 148 172 LPVOID lpvMem = NULL; 149 173 HANDLE hMapObject = NULL; 150 BOOL fIgnore, fInit;174 BOOL fIgnore, fInit; 151 175 char tmp[100]; 152 sprintf(tmp,"%i",pid); 153 if(hMapObject==NULL) 154 hMapObject = CreateFileMapping( 155 INVALID_HANDLE_VALUE, // use paging file 156 NULL, // default security attributes 157 PAGE_READWRITE, // read/write access 158 0, // size: high 32-bits 159 4096, // size: low 32-bits 160 TEXT(tmp)); // name of map object 161 if (hMapObject == NULL) 176 sprintf (tmp, "%i", pid); 177 if (hMapObject == NULL) 178 hMapObject = CreateFileMapping (INVALID_HANDLE_VALUE, // use paging file 179 NULL, // default security attributes 180 PAGE_READWRITE, // read/write access 181 0, // size: high 32-bits 182 4096, // size: low 32-bits 183 TEXT (tmp)); // name of map object 184 if (hMapObject == NULL) 162 185 return FALSE; 163 if((GetLastError() != ERROR_ALREADY_EXISTS)){ 164 fIgnore = UnmapViewOfFile(lpvMem); 165 fIgnore = CloseHandle(hMapObject); 186 if ((GetLastError () != ERROR_ALREADY_EXISTS)) 187 { 188 fIgnore = UnmapViewOfFile (lpvMem); 189 fIgnore = CloseHandle (hMapObject); 190 return "-1"; 191 } 192 fInit = TRUE; 193 if (lpvMem == NULL) 194 lpvMem = MapViewOfFile (hMapObject, // object to map view of 195 FILE_MAP_READ, // read/write access 196 0, // high offset: map from 197 0, // low offset: beginning 198 0); // default: map entire file 199 if (lpvMem == NULL) 166 200 return "-1"; 167 }168 fInit=TRUE;169 if(lpvMem==NULL)170 lpvMem = MapViewOfFile(171 hMapObject, // object to map view of172 FILE_MAP_READ, // read/write access173 0, // high offset: map from174 0, // low offset: beginning175 0); // default: map entire file176 if (lpvMem == NULL)177 return "-1";178 201 lpszTmp = (LPWSTR) lpvMem; 179 while (*lpszTmp){ 180 lpszBuf[i] = (char)*lpszTmp; 181 *lpszTmp++; 182 lpszBuf[i+1] = '\0'; 183 i++; 184 } 202 while (*lpszTmp) 203 { 204 lpszBuf[i] = (char) *lpszTmp; 205 *lpszTmp++; 206 lpszBuf[i + 1] = '\0'; 207 i++; 208 } 185 209 #ifdef DEBUG 186 fprintf(stderr,"READING STRING S %s\n",lpszBuf); 187 #endif 188 return (char*)lpszBuf; 189 } 190 191 void unhandleStatus(maps *conf){ 210 fprintf (stderr, "READING STRING S %s\n", lpszBuf); 211 #endif 212 return (char *) lpszBuf; 213 } 214 215 void 216 unhandleStatus (maps * conf) 217 { 192 218 BOOL fIgnore; 193 fIgnore = UnmapViewOfFile (lpvMemG);194 fIgnore = CloseHandle (hMapObjectG);219 fIgnore = UnmapViewOfFile (lpvMemG); 220 fIgnore = CloseHandle (hMapObjectG); 195 221 } 196 222 #else 197 223 198 void unhandleStatus(maps *conf){ 224 void 225 unhandleStatus (maps * conf) 226 { 199 227 int shmid; 200 228 key_t key; 201 229 void *shm; 202 230 struct shmid_ds shmids; 203 map *tmpMap=getMapFromMaps(conf,"lenv","sid"); 204 if(tmpMap!=NULL){ 205 key=atoi(tmpMap->value); 206 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 231 map *tmpMap = getMapFromMaps (conf, "lenv", "sid"); 232 if (tmpMap != NULL) 233 { 234 key = atoi (tmpMap->value); 235 if ((shmid = shmget (key, SHMSZ, IPC_CREAT | 0666)) < 0) 236 { 207 237 #ifdef DEBUG 208 fprintf(stderr,"shmget failed to update value\n"); 209 #endif 210 }else{ 211 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 238 fprintf (stderr, "shmget failed to update value\n"); 239 #endif 240 } 241 else 242 { 243 if ((shm = shmat (shmid, NULL, 0)) == (char *) -1) 244 { 212 245 #ifdef DEBUG 213 fprintf(stderr,"shmat failed to update value\n"); 214 #endif 215 }else{ 216 shmdt(shm); 217 shmctl(shmid,IPC_RMID,&shmids); 218 } 219 } 220 } 221 } 222 223 int _updateStatus(maps *conf){ 246 fprintf (stderr, "shmat failed to update value\n"); 247 #endif 248 } 249 else 250 { 251 shmdt (shm); 252 shmctl (shmid, IPC_RMID, &shmids); 253 } 254 } 255 } 256 } 257 258 int 259 _updateStatus (maps * conf) 260 { 224 261 int shmid; 225 262 key_t key; 226 char *shm,*s,*s1; 227 map *tmpMap=NULL; 228 tmpMap=getMapFromMaps(conf,"lenv","sid"); 229 if(tmpMap!=NULL){ 230 key=atoi(tmpMap->value); 231 if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) { 263 char *shm, *s, *s1; 264 map *tmpMap = NULL; 265 tmpMap = getMapFromMaps (conf, "lenv", "sid"); 266 if (tmpMap != NULL) 267 { 268 key = atoi (tmpMap->value); 269 if ((shmid = shmget (key, SHMSZ, IPC_CREAT | 0666)) < 0) 270 { 232 271 #ifdef DEBUG 233 fprintf(stderr,"shmget failed to create new Shared memory segment\n"); 234 #endif 235 return -2; 236 }else{ 237 if ((shm = (char*) shmat(shmid, NULL, 0)) == (char *) -1) { 272 fprintf (stderr, 273 "shmget failed to create new Shared memory segment\n"); 274 #endif 275 return -2; 276 } 277 else 278 { 279 if ((shm = (char *) shmat (shmid, NULL, 0)) == (char *) -1) 280 { 238 281 #ifdef DEBUG 239 fprintf(stderr,"shmat failed to update value\n"); 240 #endif 241 return -1; 242 } 243 else{ 244 tmpMap=getMapFromMaps(conf,"lenv","status"); 245 s1=shm; 246 for(s=tmpMap->value;*s!=NULL && *s!=0;s++){ 247 *s1++=*s; 248 } 249 *s1++='|'; 250 tmpMap=getMapFromMaps(conf,"lenv","message"); 251 if(tmpMap!=NULL) 252 for(s=tmpMap->value;*s!=NULL && *s!=0;s++){ 253 *s1++=*s; 254 } 255 *s1=NULL; 256 shmdt((void *)shm); 257 } 258 } 259 } 282 fprintf (stderr, "shmat failed to update value\n"); 283 #endif 284 return -1; 285 } 286 else 287 { 288 tmpMap = getMapFromMaps (conf, "lenv", "status"); 289 s1 = shm; 290 for (s = tmpMap->value; *s != NULL && *s != 0; s++) 291 { 292 *s1++ = *s; 293 } 294 *s1++ = '|'; 295 tmpMap = getMapFromMaps (conf, "lenv", "message"); 296 if (tmpMap != NULL) 297 for (s = tmpMap->value; *s != NULL && *s != 0; s++) 298 { 299 *s1++ = *s; 300 } 301 *s1 = NULL; 302 shmdt ((void *) shm); 303 } 304 } 305 } 260 306 return 0; 261 307 } 262 308 263 char* getStatus(int pid){ 309 char * 310 getStatus (int pid) 311 { 264 312 int shmid; 265 313 key_t key; 266 314 void *shm; 267 key=pid; 268 if ((shmid = shmget(key, SHMSZ, 0666)) < 0) { 315 key = pid; 316 if ((shmid = shmget (key, SHMSZ, 0666)) < 0) 317 { 269 318 #ifdef DEBUG 270 fprintf(stderr,"shmget failed in getStatus\n"); 271 #endif 272 }else{ 273 if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) { 319 fprintf (stderr, "shmget failed in getStatus\n"); 320 #endif 321 } 322 else 323 { 324 if ((shm = shmat (shmid, NULL, 0)) == (char *) -1) 325 { 274 326 #ifdef DEBUG 275 fprintf(stderr,"shmat failed in getStatus\n"); 276 #endif 277 }else{ 278 return (char*)shm; 279 } 280 } 281 return (char*)"-1"; 327 fprintf (stderr, "shmat failed in getStatus\n"); 328 #endif 329 } 330 else 331 { 332 return (char *) shm; 333 } 334 } 335 return (char *) "-1"; 282 336 } 283 337 … … 287 341 288 342 JSBool 289 JSUpdateStatus (JSContext *cx, uintN argc, jsval *argv1)290 { 291 jsval *argv = JS_ARGV (cx,argv1);292 JS_MaybeGC (cx);293 int istatus =0;294 char *status =NULL;343 JSUpdateStatus (JSContext * cx, uintN argc, jsval * argv1) 344 { 345 jsval *argv = JS_ARGV (cx, argv1); 346 JS_MaybeGC (cx); 347 int istatus = 0; 348 char *status = NULL; 295 349 maps *conf; 296 if(argc>2){ 350 if (argc > 2) 351 { 297 352 #ifdef JS_DEBUG 298 fprintf(stderr,"Number of arguments used to call the function : %i",argc); 299 #endif 300 return JS_FALSE; 301 } 302 conf=mapsFromJSObject(cx,argv[0]); 303 if(JS_ValueToInt32(cx,argv[1],&istatus)==JS_TRUE){ 304 char tmpStatus[4]; 305 sprintf(tmpStatus,"%i",istatus); 306 tmpStatus[3]=0; 307 status=strdup(tmpStatus); 308 } 309 if(getMapFromMaps(conf,"lenv","status")!=NULL){ 310 if(status!=NULL){ 311 setMapInMaps(conf,"lenv","status",status); 312 free(status); 313 } 314 else 315 setMapInMaps(conf,"lenv","status","15"); 316 _updateStatus(conf); 317 } 318 freeMaps(&conf); 319 free(conf); 320 JS_MaybeGC(cx); 353 fprintf (stderr, "Number of arguments used to call the function : %i", 354 argc); 355 #endif 356 return JS_FALSE; 357 } 358 conf = mapsFromJSObject (cx, argv[0]); 359 if (JS_ValueToInt32 (cx, argv[1], &istatus) == JS_TRUE) 360 { 361 char tmpStatus[4]; 362 sprintf (tmpStatus, "%i", istatus); 363 tmpStatus[3] = 0; 364 status = strdup (tmpStatus); 365 } 366 if (getMapFromMaps (conf, "lenv", "status") != NULL) 367 { 368 if (status != NULL) 369 { 370 setMapInMaps (conf, "lenv", "status", status); 371 free (status); 372 } 373 else 374 setMapInMaps (conf, "lenv", "status", "15"); 375 _updateStatus (conf); 376 } 377 freeMaps (&conf); 378 free (conf); 379 JS_MaybeGC (cx); 321 380 return JS_TRUE; 322 381 } … … 328 387 /* Returns a url-encoded version of str */ 329 388 /* IMPORTANT: be sure to free() the returned string after use */ 330 char *url_encode(char *str) { 331 char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf; 332 while (*pstr) { 333 if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') 334 *pbuf++ = *pstr; 335 else if (*pstr == ' ') 336 *pbuf++ = '+'; 337 else 338 *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15); 339 pstr++; 340 } 389 char * 390 url_encode (char *str) 391 { 392 char *pstr = str, *buf = (char *) malloc (strlen (str) * 3 + 1), *pbuf = 393 buf; 394 while (*pstr) 395 { 396 if (isalnum (*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' 397 || *pstr == '~') 398 *pbuf++ = *pstr; 399 else if (*pstr == ' ') 400 *pbuf++ = '+'; 401 else 402 *pbuf++ = '%', *pbuf++ = to_hex (*pstr >> 4), *pbuf++ = 403 to_hex (*pstr & 15); 404 pstr++; 405 } 341 406 *pbuf = '\0'; 342 407 return buf; … … 345 410 /* Returns a url-decoded version of str */ 346 411 /* IMPORTANT: be sure to free() the returned string after use */ 347 char *url_decode(char *str) { 348 char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf; 349 while (*pstr) { 350 if (*pstr == '%') { 351 if (pstr[1] && pstr[2]) { 352 *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]); 353 pstr += 2; 354 } 355 } else if (*pstr == '+') { 356 *pbuf++ = ' '; 357 } else { 358 *pbuf++ = *pstr; 359 } 360 pstr++; 361 } 412 char * 413 url_decode (char *str) 414 { 415 char *pstr = str, *buf = (char *) malloc (strlen (str) + 1), *pbuf = buf; 416 while (*pstr) 417 { 418 if (*pstr == '%') 419 { 420 if (pstr[1] && pstr[2]) 421 { 422 *pbuf++ = from_hex (pstr[1]) << 4 | from_hex (pstr[2]); 423 pstr += 2; 424 } 425 } 426 else if (*pstr == '+') 427 { 428 *pbuf++ = ' '; 429 } 430 else 431 { 432 *pbuf++ = *pstr; 433 } 434 pstr++; 435 } 362 436 *pbuf = '\0'; 363 437 return buf; 364 438 } 365 439 366 char *zCapitalize1(char *tmp){ 367 char *res=strdup(tmp); 368 if(res[0]>=97 && res[0]<=122) 369 res[0]-=32; 370 return res; 371 } 372 373 char *zCapitalize(char *tmp){ 374 int i=0; 375 char *res=strdup(tmp); 376 for(i=0;i<strlen(res);i++) 377 if(res[i]>=97 && res[i]<=122) 378 res[i]-=32; 440 char * 441 zCapitalize1 (char *tmp) 442 { 443 char *res = strdup (tmp); 444 if (res[0] >= 97 && res[0] <= 122) 445 res[0] -= 32; 379 446 return res; 380 447 } 381 448 382 383 int zooXmlSearchForNs(const char* name){ 449 char * 450 zCapitalize (char *tmp) 451 { 452 int i = 0; 453 char *res = strdup (tmp); 454 for (i = 0; i < strlen (res); i++) 455 if (res[i] >= 97 && res[i] <= 122) 456 res[i] -= 32; 457 return res; 458 } 459 460 461 int 462 zooXmlSearchForNs (const char *name) 463 { 384 464 int i; 385 int res=-1; 386 for(i=0;i<nbNs;i++) 387 if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){ 388 res=i; 389 break; 390 } 465 int res = -1; 466 for (i = 0; i < nbNs; i++) 467 if (strncasecmp (name, nsName[i], strlen (nsName[i])) == 0) 468 { 469 res = i; 470 break; 471 } 391 472 return res; 392 473 } 393 474 394 int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){ 475 int 476 zooXmlAddNs (xmlNodePtr nr, const char *url, const char *name) 477 { 395 478 #ifdef DEBUG 396 fprintf(stderr,"zooXmlAddNs %d %s \n",nbNs,name); 397 #endif 398 int currId=-1; 399 if(nbNs==0){ 400 nbNs++; 401 currId=0; 402 nsName[currId]=strdup(name); 403 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 404 }else{ 405 currId=zooXmlSearchForNs(name); 406 if(currId<0){ 479 fprintf (stderr, "zooXmlAddNs %d %s \n", nbNs, name); 480 #endif 481 int currId = -1; 482 if (nbNs == 0) 483 { 407 484 nbNs++; 408 currId=nbNs-1; 409 nsName[currId]=strdup(name); 410 usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name); 411 } 412 } 485 currId = 0; 486 nsName[currId] = strdup (name); 487 usedNs[currId] = xmlNewNs (nr, BAD_CAST url, BAD_CAST name); 488 } 489 else 490 { 491 currId = zooXmlSearchForNs (name); 492 if (currId < 0) 493 { 494 nbNs++; 495 currId = nbNs - 1; 496 nsName[currId] = strdup (name); 497 usedNs[currId] = xmlNewNs (nr, BAD_CAST url, BAD_CAST name); 498 } 499 } 413 500 return currId; 414 501 } 415 502 416 void zooXmlCleanupNs(){ 503 void 504 zooXmlCleanupNs () 505 { 417 506 int j; 418 507 #ifdef DEBUG 419 fprintf(stderr,"zooXmlCleanup %d\n",nbNs); 420 #endif 421 for(j=nbNs-1;j>=0;j--){ 508 fprintf (stderr, "zooXmlCleanup %d\n", nbNs); 509 #endif 510 for (j = nbNs - 1; j >= 0; j--) 511 { 422 512 #ifdef DEBUG 423 fprintf(stderr,"zooXmlCleanup %d\n",j); 424 #endif 425 if(j==0) 426 xmlFreeNs(usedNs[j]); 427 free(nsName[j]); 428 nbNs--; 429 } 430 nbNs=0; 431 } 432 433 434 int zooXmlAddDoc(const char* value){ 435 int currId=0; 513 fprintf (stderr, "zooXmlCleanup %d\n", j); 514 #endif 515 if (j == 0) 516 xmlFreeNs (usedNs[j]); 517 free (nsName[j]); 518 nbNs--; 519 } 520 nbNs = 0; 521 } 522 523 524 int 525 zooXmlAddDoc (const char *value) 526 { 527 int currId = 0; 436 528 nbDocs++; 437 currId =nbDocs-1;438 iDocs[currId] =xmlParseMemory(value,strlen(value));529 currId = nbDocs - 1; 530 iDocs[currId] = xmlParseMemory (value, strlen (value)); 439 531 return currId; 440 532 } 441 533 442 void zooXmlCleanupDocs(){ 534 void 535 zooXmlCleanupDocs () 536 { 443 537 int j; 444 for(j=nbDocs-1;j>=0;j--){ 445 xmlFreeDoc(iDocs[j]); 446 } 447 nbDocs=0; 448 } 449 450 451 xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){ 452 map* soap=getMapFromMaps(conf,"main","isSoap"); 453 if(soap!=NULL && strcasecmp(soap->value,"true")==0){ 454 int lNbNs=nbNs; 455 nsName[lNbNs]=strdup("soap"); 456 usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 457 nbNs++; 458 xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope"); 459 nsName[nbNs]=strdup("soap"); 460 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap"); 461 nbNs++; 462 nsName[nbNs]=strdup("xsi"); 463 usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi"); 464 nbNs++; 465 xmlNsPtr ns_xsi=usedNs[nbNs-1]; 466 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"); 467 xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body"); 468 xmlAddChild(nr1,n); 469 xmlAddChild(nr,nr1); 470 return nr; 471 }else 538 for (j = nbDocs - 1; j >= 0; j--) 539 { 540 xmlFreeDoc (iDocs[j]); 541 } 542 nbDocs = 0; 543 } 544 545 546 xmlNodePtr 547 soapEnvelope (maps * conf, xmlNodePtr n) 548 { 549 map *soap = getMapFromMaps (conf, "main", "isSoap"); 550 if (soap != NULL && strcasecmp (soap->value, "true") == 0) 551 { 552 int lNbNs = nbNs; 553 nsName[lNbNs] = strdup ("soap"); 554 usedNs[lNbNs] = 555 xmlNewNs (NULL, BAD_CAST "http://www.w3.org/2003/05/soap-envelope", 556 BAD_CAST "soap"); 557 nbNs++; 558 xmlNodePtr nr = xmlNewNode (usedNs[lNbNs], BAD_CAST "Envelope"); 559 nsName[nbNs] = strdup ("soap"); 560 usedNs[nbNs] = 561 xmlNewNs (nr, BAD_CAST "http://www.w3.org/2003/05/soap-envelope", 562 BAD_CAST "soap"); 563 nbNs++; 564 nsName[nbNs] = strdup ("xsi"); 565 usedNs[nbNs] = 566 xmlNewNs (nr, BAD_CAST "http://www.w3.org/2001/XMLSchema-instance", 567 BAD_CAST "xsi"); 568 nbNs++; 569 xmlNsPtr ns_xsi = usedNs[nbNs - 1]; 570 xmlNewNsProp (nr, ns_xsi, BAD_CAST "schemaLocation", 571 BAD_CAST 572 "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope"); 573 xmlNodePtr nr1 = xmlNewNode (usedNs[lNbNs], BAD_CAST "Body"); 574 xmlAddChild (nr1, n); 575 xmlAddChild (nr, nr1); 576 return nr; 577 } 578 else 472 579 return n; 473 580 } 474 581 475 xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,const char* service,maps* m){ 476 477 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; 478 xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6; 582 xmlNodePtr 583 printGetCapabilitiesHeader (xmlDocPtr doc, const char *service, maps * m) 584 { 585 586 xmlNsPtr ns, ns_ows, ns_xlink, ns_xsi; 587 xmlNodePtr n, nc, nc1, nc2, nc3, nc4, nc5, nc6; 479 588 /** 480 589 * Create the document and its temporary root. 481 590 */ 482 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 483 ns=usedNs[wpsId]; 484 maps* toto1=getMaps(m,"main"); 485 486 n = xmlNewNode(ns, BAD_CAST "Capabilities"); 487 int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 488 ns_ows=usedNs[owsId]; 489 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 490 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 491 ns_xsi=usedNs[xsiId]; 492 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 493 ns_xlink=usedNs[xlinkId]; 494 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"); 495 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 496 addLangAttr(n,m); 497 498 if(toto1!=NULL){ 499 map* tmp=getMap(toto1->content,"version"); 500 if(tmp!=NULL){ 501 xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value); 502 } 503 else 504 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 505 } 591 int wpsId = zooXmlAddNs (NULL, "http://www.opengis.net/wps/1.0.0", "wps"); 592 ns = usedNs[wpsId]; 593 maps *toto1 = getMaps (m, "main"); 594 595 n = xmlNewNode (ns, BAD_CAST "Capabilities"); 596 int owsId = zooXmlAddNs (n, "http://www.opengis.net/ows/1.1", "ows"); 597 ns_ows = usedNs[owsId]; 598 xmlNewNs (n, BAD_CAST "http://www.opengis.net/wps/1.0.0", BAD_CAST "wps"); 599 int xsiId = 600 zooXmlAddNs (n, "http://www.w3.org/2001/XMLSchema-instance", "xsi"); 601 ns_xsi = usedNs[xsiId]; 602 int xlinkId = zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink"); 603 ns_xlink = usedNs[xlinkId]; 604 xmlNewNsProp (n, ns_xsi, BAD_CAST "schemaLocation", 605 BAD_CAST 606 "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd"); 607 xmlNewProp (n, BAD_CAST "service", BAD_CAST "WPS"); 608 addLangAttr (n, m); 609 610 if (toto1 != NULL) 611 { 612 map *tmp = getMap (toto1->content, "version"); 613 if (tmp != NULL) 614 { 615 xmlNewProp (n, BAD_CAST "version", BAD_CAST tmp->value); 616 } 617 else 618 xmlNewProp (n, BAD_CAST "version", BAD_CAST "1.0.0"); 619 } 506 620 else 507 xmlNewProp (n,BAD_CAST "version",BAD_CAST "1.0.0");621 xmlNewProp (n, BAD_CAST "version", BAD_CAST "1.0.0"); 508 622 509 623 char tmp[256]; 510 511 nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification"); 512 maps* tmp4=getMaps(m,"identification"); 513 if(tmp4!=NULL){ 514 map* tmp2=tmp4->content; 515 const char *orderedFields[5]; 516 orderedFields[0]="Title"; 517 orderedFields[1]="Abstract"; 518 orderedFields[2]="Keywords"; 519 orderedFields[3]="Fees"; 520 orderedFields[4]="AccessConstraints"; 521 int oI=0; 522 for(oI=0;oI<5;oI++) 523 if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ 524 if(strcasecmp(tmp2->name,"abstract")==0 || 525 strcasecmp(tmp2->name,"title")==0 || 526 strcasecmp(tmp2->name,"accessConstraints")==0 || 527 strcasecmp(tmp2->name,"fees")==0){ 528 tmp2->name[0]=toupper(tmp2->name[0]); 529 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); 530 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); 531 xmlAddChild(nc,nc1); 532 } 533 else 534 if(strcmp(tmp2->name,"keywords")==0){ 535 nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); 536 char *toto=tmp2->value; 537 char buff[256]; 538 int i=0; 539 int j=0; 540 while(toto[i]){ 541 if(toto[i]!=',' && toto[i]!=0){ 542 buff[j]=toto[i]; 543 buff[j+1]=0; 544 j++; 545 } 546 else{ 547 nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); 548 xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); 549 xmlAddChild(nc1,nc2); 550 j=0; 551 } 552 i++; 553 } 554 if(strlen(buff)>0){ 555 nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); 556 xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); 557 xmlAddChild(nc1,nc2); 558 } 559 xmlAddChild(nc,nc1); 560 nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType"); 561 xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS")); 562 xmlAddChild(nc,nc2); 563 nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion"); 564 xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0")); 565 xmlAddChild(nc,nc2); 566 } 567 tmp2=tmp2->next; 568 } 569 } 570 else{ 571 fprintf(stderr,"TMP4 NOT FOUND !!"); 572 return NULL; 573 } 574 xmlAddChild(n,nc); 575 576 nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider"); 577 nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact"); 578 nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo"); 579 nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone"); 580 nc6 = xmlNewNode(ns_ows, BAD_CAST "Address"); 581 tmp4=getMaps(m,"provider"); 582 if(tmp4!=NULL){ 583 map* tmp2=tmp4->content; 584 const char *tmpAddress[6]; 585 tmpAddress[0]="addressDeliveryPoint"; 586 tmpAddress[1]="addressCity"; 587 tmpAddress[2]="addressAdministrativeArea"; 588 tmpAddress[3]="addressPostalCode"; 589 tmpAddress[4]="addressCountry"; 590 tmpAddress[5]="addressElectronicMailAddress"; 591 const char *tmpPhone[2]; 592 tmpPhone[0]="phoneVoice"; 593 tmpPhone[1]="phoneFacsimile"; 594 const char *orderedFields[12]; 595 orderedFields[0]="providerName"; 596 orderedFields[1]="providerSite"; 597 orderedFields[2]="individualName"; 598 orderedFields[3]="positionName"; 599 orderedFields[4]=tmpPhone[0]; 600 orderedFields[5]=tmpPhone[1]; 601 orderedFields[6]=tmpAddress[0]; 602 orderedFields[7]=tmpAddress[1]; 603 orderedFields[8]=tmpAddress[2]; 604 orderedFields[9]=tmpAddress[3]; 605 orderedFields[10]=tmpAddress[4]; 606 orderedFields[11]=tmpAddress[5]; 607 int oI=0; 608 for(oI=0;oI<12;oI++) 609 if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){ 610 if(strcmp(tmp2->name,"keywords")!=0 && 611 strcmp(tmp2->name,"serverAddress")!=0 && 612 strcmp(tmp2->name,"lang")!=0){ 613 tmp2->name[0]=toupper(tmp2->name[0]); 614 if(strcmp(tmp2->name,"ProviderName")==0){ 615 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); 616 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); 617 xmlAddChild(nc,nc1); 618 } 619 else{ 620 if(strcmp(tmp2->name,"ProviderSite")==0){ 621 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); 622 xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value); 623 xmlAddChild(nc,nc1); 624 } 625 else 626 if(strcmp(tmp2->name,"IndividualName")==0 || 627 strcmp(tmp2->name,"PositionName")==0){ 628 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name); 629 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); 630 xmlAddChild(nc3,nc1); 631 } 632 else 633 if(strncmp(tmp2->name,"Phone",5)==0){ 634 int j; 635 for(j=0;j<2;j++) 636 if(strcasecmp(tmp2->name,tmpPhone[j])==0){ 637 char *tmp4=tmp2->name; 638 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+5); 639 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); 640 xmlAddChild(nc5,nc1); 641 } 642 } 643 else 644 if(strncmp(tmp2->name,"Address",7)==0){ 645 int j; 646 for(j=0;j<6;j++) 647 if(strcasecmp(tmp2->name,tmpAddress[j])==0){ 648 char *tmp4=tmp2->name; 649 nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+7); 650 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value)); 651 xmlAddChild(nc6,nc1); 652 } 653 } 654 } 655 } 656 else 657 if(strcmp(tmp2->name,"keywords")==0){ 658 nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords"); 659 char *toto=tmp2->value; 660 char buff[256]; 661 int i=0; 662 int j=0; 663 while(toto[i]){ 664 if(toto[i]!=',' && toto[i]!=0){ 665 buff[j]=toto[i]; 666 buff[j+1]=0; 667 j++; 668 } 669 else{ 670 nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); 671 xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); 672 xmlAddChild(nc1,nc2); 673 j=0; 674 } 675 i++; 676 } 677 if(strlen(buff)>0){ 678 nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword"); 679 xmlAddChild(nc2,xmlNewText(BAD_CAST buff)); 680 xmlAddChild(nc1,nc2); 681 } 682 xmlAddChild(nc,nc1); 683 } 684 tmp2=tmp2->next; 685 } 686 } 687 else{ 688 fprintf(stderr,"TMP4 NOT FOUND !!"); 689 } 690 xmlAddChild(nc4,nc5); 691 xmlAddChild(nc4,nc6); 692 xmlAddChild(nc3,nc4); 693 xmlAddChild(nc,nc3); 694 xmlAddChild(n,nc); 695 696 697 nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata"); 624 625 nc = xmlNewNode (ns_ows, BAD_CAST "ServiceIdentification"); 626 maps *tmp4 = getMaps (m, "identification"); 627 if (tmp4 != NULL) 628 { 629 map *tmp2 = tmp4->content; 630 const char *orderedFields[5]; 631 orderedFields[0] = "Title"; 632 orderedFields[1] = "Abstract"; 633 orderedFields[2] = "Keywords"; 634 orderedFields[3] = "Fees"; 635 orderedFields[4] = "AccessConstraints"; 636 int oI = 0; 637 for (oI = 0; oI < 5; oI++) 638 if ((tmp2 = getMap (tmp4->content, orderedFields[oI])) != NULL) 639 { 640 if (strcasecmp (tmp2->name, "abstract") == 0 || 641 strcasecmp (tmp2->name, "title") == 0 || 642 strcasecmp (tmp2->name, "accessConstraints") == 0 || 643 strcasecmp (tmp2->name, "fees") == 0) 644 { 645 tmp2->name[0] = toupper (tmp2->name[0]); 646 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp2->name); 647 xmlAddChild (nc1, xmlNewText (BAD_CAST tmp2->value)); 648 xmlAddChild (nc, nc1); 649 } 650 else if (strcmp (tmp2->name, "keywords") == 0) 651 { 652 nc1 = xmlNewNode (ns_ows, BAD_CAST "Keywords"); 653 char *toto = tmp2->value; 654 char buff[256]; 655 int i = 0; 656 int j = 0; 657 while (toto[i]) 658 { 659 if (toto[i] != ',' && toto[i] != 0) 660 { 661 buff[j] = toto[i]; 662 buff[j + 1] = 0; 663 j++; 664 } 665 else 666 { 667 nc2 = xmlNewNode (ns_ows, BAD_CAST "Keyword"); 668 xmlAddChild (nc2, xmlNewText (BAD_CAST buff)); 669 xmlAddChild (nc1, nc2); 670 j = 0; 671 } 672 i++; 673 } 674 if (strlen (buff) > 0) 675 { 676 nc2 = xmlNewNode (ns_ows, BAD_CAST "Keyword"); 677 xmlAddChild (nc2, xmlNewText (BAD_CAST buff)); 678 xmlAddChild (nc1, nc2); 679 } 680 xmlAddChild (nc, nc1); 681 nc2 = xmlNewNode (ns_ows, BAD_CAST "ServiceType"); 682 xmlAddChild (nc2, xmlNewText (BAD_CAST "WPS")); 683 xmlAddChild (nc, nc2); 684 nc2 = xmlNewNode (ns_ows, BAD_CAST "ServiceTypeVersion"); 685 xmlAddChild (nc2, xmlNewText (BAD_CAST "1.0.0")); 686 xmlAddChild (nc, nc2); 687 } 688 tmp2 = tmp2->next; 689 } 690 } 691 else 692 { 693 fprintf (stderr, "TMP4 NOT FOUND !!"); 694 return NULL; 695 } 696 xmlAddChild (n, nc); 697 698 nc = xmlNewNode (ns_ows, BAD_CAST "ServiceProvider"); 699 nc3 = xmlNewNode (ns_ows, BAD_CAST "ServiceContact"); 700 nc4 = xmlNewNode (ns_ows, BAD_CAST "ContactInfo"); 701 nc5 = xmlNewNode (ns_ows, BAD_CAST "Phone"); 702 nc6 = xmlNewNode (ns_ows, BAD_CAST "Address"); 703 tmp4 = getMaps (m, "provider"); 704 if (tmp4 != NULL) 705 { 706 map *tmp2 = tmp4->content; 707 const char *tmpAddress[6]; 708 tmpAddress[0] = "addressDeliveryPoint"; 709 tmpAddress[1] = "addressCity"; 710 tmpAddress[2] = "addressAdministrativeArea"; 711 tmpAddress[3] = "addressPostalCode"; 712 tmpAddress[4] = "addressCountry"; 713 tmpAddress[5] = "addressElectronicMailAddress"; 714 const char *tmpPhone[2]; 715 tmpPhone[0] = "phoneVoice"; 716 tmpPhone[1] = "phoneFacsimile"; 717 const char *orderedFields[12]; 718 orderedFields[0] = "providerName"; 719 orderedFields[1] = "providerSite"; 720 orderedFields[2] = "individualName"; 721 orderedFields[3] = "positionName"; 722 orderedFields[4] = tmpPhone[0]; 723 orderedFields[5] = tmpPhone[1]; 724 orderedFields[6] = tmpAddress[0]; 725 orderedFields[7] = tmpAddress[1]; 726 orderedFields[8] = tmpAddress[2]; 727 orderedFields[9] = tmpAddress[3]; 728 orderedFields[10] = tmpAddress[4]; 729 orderedFields[11] = tmpAddress[5]; 730 int oI = 0; 731 for (oI = 0; oI < 12; oI++) 732 if ((tmp2 = getMap (tmp4->content, orderedFields[oI])) != NULL) 733 { 734 if (strcmp (tmp2->name, "keywords") != 0 && 735 strcmp (tmp2->name, "serverAddress") != 0 && 736 strcmp (tmp2->name, "lang") != 0) 737 { 738 tmp2->name[0] = toupper (tmp2->name[0]); 739 if (strcmp (tmp2->name, "ProviderName") == 0) 740 { 741 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp2->name); 742 xmlAddChild (nc1, xmlNewText (BAD_CAST tmp2->value)); 743 xmlAddChild (nc, nc1); 744 } 745 else 746 { 747 if (strcmp (tmp2->name, "ProviderSite") == 0) 748 { 749 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp2->name); 750 xmlNewNsProp (nc1, ns_xlink, BAD_CAST "href", 751 BAD_CAST tmp2->value); 752 xmlAddChild (nc, nc1); 753 } 754 else 755 if (strcmp (tmp2->name, "IndividualName") == 0 || 756 strcmp (tmp2->name, "PositionName") == 0) 757 { 758 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp2->name); 759 xmlAddChild (nc1, xmlNewText (BAD_CAST tmp2->value)); 760 xmlAddChild (nc3, nc1); 761 } 762 else if (strncmp (tmp2->name, "Phone", 5) == 0) 763 { 764 int j; 765 for (j = 0; j < 2; j++) 766 if (strcasecmp (tmp2->name, tmpPhone[j]) == 0) 767 { 768 char *tmp4 = tmp2->name; 769 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp4 + 5); 770 xmlAddChild (nc1, 771 xmlNewText (BAD_CAST tmp2->value)); 772 xmlAddChild (nc5, nc1); 773 } 774 } 775 else if (strncmp (tmp2->name, "Address", 7) == 0) 776 { 777 int j; 778 for (j = 0; j < 6; j++) 779 if (strcasecmp (tmp2->name, tmpAddress[j]) == 0) 780 { 781 char *tmp4 = tmp2->name; 782 nc1 = xmlNewNode (ns_ows, BAD_CAST tmp4 + 7); 783 xmlAddChild (nc1, 784 xmlNewText (BAD_CAST tmp2->value)); 785 xmlAddChild (nc6, nc1); 786 } 787 } 788 } 789 } 790 else if (strcmp (tmp2->name, "keywords") == 0) 791 { 792 nc1 = xmlNewNode (ns_ows, BAD_CAST "Keywords"); 793 char *toto = tmp2->value; 794 char buff[256]; 795 int i = 0; 796 int j = 0; 797 while (toto[i]) 798 { 799 if (toto[i] != ',' && toto[i] != 0) 800 { 801 buff[j] = toto[i]; 802 buff[j + 1] = 0; 803 j++; 804 } 805 else 806 { 807 nc2 = xmlNewNode (ns_ows, BAD_CAST "Keyword"); 808 xmlAddChild (nc2, xmlNewText (BAD_CAST buff)); 809 xmlAddChild (nc1, nc2); 810 j = 0; 811 } 812 i++; 813 } 814 if (strlen (buff) > 0) 815 { 816 nc2 = xmlNewNode (ns_ows, BAD_CAST "Keyword"); 817 xmlAddChild (nc2, xmlNewText (BAD_CAST buff)); 818 xmlAddChild (nc1, nc2); 819 } 820 xmlAddChild (nc, nc1); 821 } 822 tmp2 = tmp2->next; 823 } 824 } 825 else 826 { 827 fprintf (stderr, "TMP4 NOT FOUND !!"); 828 } 829 xmlAddChild (nc4, nc5); 830 xmlAddChild (nc4, nc6); 831 xmlAddChild (nc3, nc4); 832 xmlAddChild (nc, nc3); 833 xmlAddChild (n, nc); 834 835 836 nc = xmlNewNode (ns_ows, BAD_CAST "OperationsMetadata"); 698 837 char *tmp2[3]; 699 tmp2[0]=strdup("GetCapabilities"); 700 tmp2[1]=strdup("DescribeProcess"); 701 tmp2[2]=strdup("Execute"); 702 int j=0; 703 704 if(toto1!=NULL){ 705 map* tmp=getMap(toto1->content,"serverAddress"); 706 if(tmp!=NULL){ 707 SERVICE_URL = strdup(tmp->value); 708 } 709 else 710 SERVICE_URL = strdup("not_found"); 711 } 838 tmp2[0] = strdup ("GetCapabilities"); 839 tmp2[1] = strdup ("DescribeProcess"); 840 tmp2[2] = strdup ("Execute"); 841 int j = 0; 842 843 if (toto1 != NULL) 844 { 845 map *tmp = getMap (toto1->content, "serverAddress"); 846 if (tmp != NULL) 847 { 848 SERVICE_URL = strdup (tmp->value); 849 } 850 else 851 SERVICE_URL = strdup ("not_found"); 852 } 712 853 else 713 SERVICE_URL = strdup("not_found"); 714 715 for(j=0;j<3;j++){ 716 nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation"); 717 xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]); 718 nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP"); 719 nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP"); 720 nc4 = xmlNewNode(ns_ows, BAD_CAST "Get"); 721 sprintf(tmp,"%s/%s",SERVICE_URL,service); 722 xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); 723 xmlAddChild(nc3,nc4); 724 if(j>0){ 725 nc4 = xmlNewNode(ns_ows, BAD_CAST "Post"); 726 xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp); 727 xmlAddChild(nc3,nc4); 728 } 729 xmlAddChild(nc2,nc3); 730 xmlAddChild(nc1,nc2); 731 xmlAddChild(nc,nc1); 732 } 733 for(j=2;j>=0;j--) 734 free(tmp2[j]); 735 xmlAddChild(n,nc); 736 737 nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings"); 738 xmlAddChild(n,nc); 739 740 nc1 = xmlNewNode(ns, BAD_CAST "Languages"); 741 nc2 = xmlNewNode(ns, BAD_CAST "Default"); 742 nc3 = xmlNewNode(ns, BAD_CAST "Supported"); 743 744 toto1=getMaps(m,"main"); 745 if(toto1!=NULL){ 746 map* tmp1=getMap(toto1->content,"lang"); 747 char *toto=tmp1->value; 748 char buff[256]; 749 int i=0; 750 int j=0; 751 int dcount=0; 752 while(toto[i]){ 753 if(toto[i]!=',' && toto[i]!=0){ 754 buff[j]=toto[i]; 755 buff[j+1]=0; 756 j++; 757 } 758 else{ 759 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 760 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 761 if(dcount==0){ 762 xmlAddChild(nc2,nc4); 763 xmlAddChild(nc1,nc2); 764 dcount++; 765 } 766 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 767 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 768 xmlAddChild(nc3,nc4); 769 j=0; 770 buff[j]=0; 771 } 772 i++; 773 } 774 if(strlen(buff)>0){ 775 nc4 = xmlNewNode(ns_ows, BAD_CAST "Language"); 776 xmlAddChild(nc4,xmlNewText(BAD_CAST buff)); 777 xmlAddChild(nc3,nc4); 778 } 779 } 780 xmlAddChild(nc1,nc3); 781 xmlAddChild(n,nc1); 782 783 xmlNodePtr fn=soapEnvelope(m,n); 784 xmlDocSetRootElement(doc, fn); 854 SERVICE_URL = strdup ("not_found"); 855 856 for (j = 0; j < 3; j++) 857 { 858 nc1 = xmlNewNode (ns_ows, BAD_CAST "Operation"); 859 xmlNewProp (nc1, BAD_CAST "name", BAD_CAST tmp2[j]); 860 nc2 = xmlNewNode (ns_ows, BAD_CAST "DCP"); 861 nc3 = xmlNewNode (ns_ows, BAD_CAST "HTTP"); 862 nc4 = xmlNewNode (ns_ows, BAD_CAST "Get"); 863 sprintf (tmp, "%s/%s", SERVICE_URL, service); 864 xmlNewNsProp (nc4, ns_xlink, BAD_CAST "href", BAD_CAST tmp); 865 xmlAddChild (nc3, nc4); 866 if (j > 0) 867 { 868 nc4 = xmlNewNode (ns_ows, BAD_CAST "Post"); 869 xmlNewNsProp (nc4, ns_xlink, BAD_CAST "href", BAD_CAST tmp); 870 xmlAddChild (nc3, nc4); 871 } 872 xmlAddChild (nc2, nc3); 873 xmlAddChild (nc1, nc2); 874 xmlAddChild (nc, nc1); 875 } 876 for (j = 2; j >= 0; j--) 877 free (tmp2[j]); 878 xmlAddChild (n, nc); 879 880 nc = xmlNewNode (ns, BAD_CAST "ProcessOfferings"); 881 xmlAddChild (n, nc); 882 883 nc1 = xmlNewNode (ns, BAD_CAST "Languages"); 884 nc2 = xmlNewNode (ns, BAD_CAST "Default"); 885 nc3 = xmlNewNode (ns, BAD_CAST "Supported"); 886 887 toto1 = getMaps (m, "main"); 888 if (toto1 != NULL) 889 { 890 map *tmp1 = getMap (toto1->content, "lang"); 891 char *toto = tmp1->value; 892 char buff[256]; 893 int i = 0; 894 int j = 0; 895 int dcount = 0; 896 while (toto[i]) 897 { 898 if (toto[i] != ',' && toto[i] != 0) 899 { 900 buff[j] = toto[i]; 901 buff[j + 1] = 0; 902 j++; 903 } 904 else 905 { 906 nc4 = xmlNewNode (ns_ows, BAD_CAST "Language"); 907 xmlAddChild (nc4, xmlNewText (BAD_CAST buff)); 908 if (dcount == 0) 909 { 910 xmlAddChild (nc2, nc4); 911 xmlAddChild (nc1, nc2); 912 dcount++; 913 } 914 nc4 = xmlNewNode (ns_ows, BAD_CAST "Language"); 915 xmlAddChild (nc4, xmlNewText (BAD_CAST buff)); 916 xmlAddChild (nc3, nc4); 917 j = 0; 918 buff[j] = 0; 919 } 920 i++; 921 } 922 if (strlen (buff) > 0) 923 { 924 nc4 = xmlNewNode (ns_ows, BAD_CAST "Language"); 925 xmlAddChild (nc4, xmlNewText (BAD_CAST buff)); 926 xmlAddChild (nc3, nc4); 927 } 928 } 929 xmlAddChild (nc1, nc3); 930 xmlAddChild (n, nc1); 931 932 xmlNodePtr fn = soapEnvelope (m, n); 933 xmlDocSetRootElement (doc, fn); 785 934 //xmlFreeNs(ns); 786 free (SERVICE_URL);935 free (SERVICE_URL); 787 936 return nc; 788 937 } 789 938 790 void addPrefix(maps* conf,map* level,service* serv){ 791 if(level!=NULL){ 792 char key[25]; 793 char* prefix=NULL; 794 int clevel=atoi(level->value); 795 int cl=0; 796 for(cl=0;cl<clevel;cl++){ 797 sprintf(key,"sprefix_%d",cl); 798 map* tmp2=getMapFromMaps(conf,"lenv",key); 799 if(tmp2!=NULL){ 800 if(prefix==NULL) 801 prefix=zStrdup(tmp2->value); 802 else{ 803 int plen=strlen(prefix); 804 prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char)); 805 memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char)); 806 prefix[plen+strlen(tmp2->value)]=0; 807 } 808 } 809 } 810 if(prefix!=NULL){ 811 char* tmp0=strdup(serv->name); 812 free(serv->name); 813 serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char)); 814 sprintf(serv->name,"%s%s",prefix,tmp0); 815 free(tmp0); 816 free(prefix); 817 prefix=NULL; 818 } 819 } 820 } 821 822 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){ 823 xmlNsPtr ns,ns_ows,ns_xlink; 824 xmlNodePtr n=NULL,nc1,nc2; 939 void 940 addPrefix (maps * conf, map * level, service * serv) 941 { 942 if (level != NULL) 943 { 944 char key[25]; 945 char *prefix = NULL; 946 int clevel = atoi (level->value); 947 int cl = 0; 948 for (cl = 0; cl < clevel; cl++) 949 { 950 sprintf (key, "sprefix_%d", cl); 951 map *tmp2 = getMapFromMaps (conf, "lenv", key); 952 if (tmp2 != NULL) 953 { 954 if (prefix == NULL) 955 prefix = zStrdup (tmp2->value); 956 else 957 { 958 int plen = strlen (prefix); 959 prefix = 960 (char *) realloc (prefix, 961 (plen + strlen (tmp2->value) + 962 2) * sizeof (char)); 963 memcpy (prefix + plen, tmp2->value, 964 strlen (tmp2->value) * sizeof (char)); 965 prefix[plen + strlen (tmp2->value)] = 0; 966 } 967 } 968 } 969 if (prefix != NULL) 970 { 971 char *tmp0 = strdup (serv->name); 972 free (serv->name); 973 serv->name = 974 (char *) malloc ((strlen (prefix) + strlen (tmp0) + 1) * 975 sizeof (char)); 976 sprintf (serv->name, "%s%s", prefix, tmp0); 977 free (tmp0); 978 free (prefix); 979 prefix = NULL; 980 } 981 } 982 } 983 984 void 985 printGetCapabilitiesForProcess (maps * m, xmlNodePtr nc, service * serv) 986 { 987 xmlNsPtr ns, ns_ows, ns_xlink; 988 xmlNodePtr n = NULL, nc1, nc2; 825 989 /** 826 990 * Initialize or get existing namspaces 827 991 */ 828 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 829 ns=usedNs[wpsId]; 830 int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 831 ns_ows=usedNs[owsId]; 832 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 833 ns_xlink=usedNs[xlinkId]; 834 835 map* tmp1; 836 if(serv->content!=NULL){ 837 nc1 = xmlNewNode(ns, BAD_CAST "Process"); 838 tmp1=getMap(serv->content,"processVersion"); 839 if(tmp1!=NULL) 840 xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); 841 map* tmp3=getMapFromMaps(m,"lenv","level"); 842 addPrefix(m,tmp3,serv); 843 printDescription(nc1,ns_ows,serv->name,serv->content); 844 tmp1=serv->metadata; 845 while(tmp1!=NULL){ 846 nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 847 xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 848 xmlAddChild(nc1,nc2); 849 tmp1=tmp1->next; 850 } 851 xmlAddChild(nc,nc1); 852 } 853 } 854 855 xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,const char* service,maps* m){ 856 857 xmlNsPtr ns,ns_xsi; 992 int wpsId = zooXmlAddNs (NULL, "http://www.opengis.net/wps/1.0.0", "wps"); 993 ns = usedNs[wpsId]; 994 int owsId = zooXmlAddNs (NULL, "http://www.opengis.net/ows/1.1", "ows"); 995 ns_ows = usedNs[owsId]; 996 int xlinkId = zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink"); 997 ns_xlink = usedNs[xlinkId]; 998 999 map *tmp1; 1000 if (serv->content != NULL) 1001 { 1002 nc1 = xmlNewNode (ns, BAD_CAST "Process"); 1003 tmp1 = getMap (serv->content, "processVersion"); 1004 if (tmp1 != NULL) 1005 xmlNewNsProp (nc1, ns, BAD_CAST "processVersion", 1006 BAD_CAST tmp1->value); 1007 map *tmp3 = getMapFromMaps (m, "lenv", "level"); 1008 addPrefix (m, tmp3, serv); 1009 printDescription (nc1, ns_ows, serv->name, serv->content); 1010 tmp1 = serv->metadata; 1011 while (tmp1 != NULL) 1012 { 1013 nc2 = xmlNewNode (ns_ows, BAD_CAST "Metadata"); 1014 xmlNewNsProp (nc2, ns_xlink, BAD_CAST tmp1->name, 1015 BAD_CAST tmp1->value); 1016 xmlAddChild (nc1, nc2); 1017 tmp1 = tmp1->next; 1018 } 1019 xmlAddChild (nc, nc1); 1020 } 1021 } 1022 1023 xmlNodePtr 1024 printDescribeProcessHeader (xmlDocPtr doc, const char *service, maps * m) 1025 { 1026 1027 xmlNsPtr ns, ns_xsi; 858 1028 xmlNodePtr n; 859 1029 860 int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); 861 ns=usedNs[wpsId]; 862 n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions"); 863 zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 864 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 865 zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 866 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 867 ns_xsi=usedNs[xsiId]; 868 869 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"); 870 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 871 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 872 addLangAttr(n,m); 873 874 xmlNodePtr fn=soapEnvelope(m,n); 875 xmlDocSetRootElement(doc, fn); 1030 int wpsId = 1031 zooXmlAddNs (NULL, "http://schemas.opengis.net/wps/1.0.0", "wps"); 1032 ns = usedNs[wpsId]; 1033 n = xmlNewNode (ns, BAD_CAST "ProcessDescriptions"); 1034 zooXmlAddNs (n, "http://www.opengis.net/ows/1.1", "ows"); 1035 xmlNewNs (n, BAD_CAST "http://www.opengis.net/wps/1.0.0", BAD_CAST "wps"); 1036 zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink"); 1037 int xsiId = 1038 zooXmlAddNs (n, "http://www.w3.org/2001/XMLSchema-instance", "xsi"); 1039 ns_xsi = usedNs[xsiId]; 1040 1041 xmlNewNsProp (n, ns_xsi, BAD_CAST "schemaLocation", 1042 BAD_CAST 1043 "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd"); 1044 xmlNewProp (n, BAD_CAST "service", BAD_CAST "WPS"); 1045 xmlNewProp (n, BAD_CAST "version", BAD_CAST "1.0.0"); 1046 addLangAttr (n, m); 1047 1048 xmlNodePtr fn = soapEnvelope (m, n); 1049 xmlDocSetRootElement (doc, fn); 876 1050 877 1051 return n; 878 1052 } 879 1053 880 void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){ 881 xmlNsPtr ns,ns_ows,ns_xlink; 882 xmlNodePtr n,nc1; 883 884 n=nc; 885 886 int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps"); 887 ns=usedNs[wpsId]; 888 int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 889 ns_ows=usedNs[owsId]; 890 int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink"); 891 ns_xlink=usedNs[xlinkId]; 892 893 nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription"); 1054 void 1055 printDescribeProcessForProcess (maps * m, xmlNodePtr nc, service * serv) 1056 { 1057 xmlNsPtr ns, ns_ows, ns_xlink; 1058 xmlNodePtr n, nc1; 1059 1060 n = nc; 1061 1062 int wpsId = 1063 zooXmlAddNs (NULL, "http://schemas.opengis.net/wps/1.0.0", "wps"); 1064 ns = usedNs[wpsId]; 1065 int owsId = zooXmlAddNs (NULL, "http://www.opengis.net/ows/1.1", "ows"); 1066 ns_ows = usedNs[owsId]; 1067 int xlinkId = zooXmlAddNs (NULL, "http://www.w3.org/1999/xlink", "xlink"); 1068 ns_xlink = usedNs[xlinkId]; 1069 1070 nc = xmlNewNode (NULL, BAD_CAST "ProcessDescription"); 894 1071 const char *tmp4[3]; 895 tmp4[0]="processVersion"; 896 tmp4[1]="storeSupported"; 897 tmp4[2]="statusSupported"; 898 int j=0; 899 map* tmp1=NULL; 900 for(j=0;j<3;j++){ 901 tmp1=getMap(serv->content,tmp4[j]); 902 if(tmp1!=NULL){ 903 if(j==0) 904 xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value); 1072 tmp4[0] = "processVersion"; 1073 tmp4[1] = "storeSupported"; 1074 tmp4[2] = "statusSupported"; 1075 int j = 0; 1076 map *tmp1 = NULL; 1077 for (j = 0; j < 3; j++) 1078 { 1079 tmp1 = getMap (serv->content, tmp4[j]); 1080 if (tmp1 != NULL) 1081 { 1082 if (j == 0) 1083 xmlNewNsProp (nc, ns, BAD_CAST "processVersion", 1084 BAD_CAST tmp1->value); 1085 else 1086 xmlNewProp (nc, BAD_CAST tmp4[j], BAD_CAST tmp1->value); 1087 } 905 1088 else 906 xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value); 907 } 908 else{ 909 if(j>0) 910 xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false"); 911 } 912 } 913 914 tmp1=getMapFromMaps(m,"lenv","level"); 915 addPrefix(m,tmp1,serv); 916 printDescription(nc,ns_ows,serv->name,serv->content); 917 918 tmp1=serv->metadata; 919 while(tmp1!=NULL){ 920 nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata"); 921 xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 922 xmlAddChild(nc,nc1); 923 tmp1=tmp1->next; 924 } 925 926 tmp1=getMap(serv->content,"Profile"); 927 if(tmp1!=NULL){ 928 nc1 = xmlNewNode(ns, BAD_CAST "Profile"); 929 xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value)); 930 xmlAddChild(nc,nc1); 931 } 932 933 if(serv->inputs!=NULL){ 934 nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs"); 935 elements* e=serv->inputs; 936 printFullDescription(1,e,"Input",ns_ows,nc1); 937 xmlAddChild(nc,nc1); 938 } 939 940 nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs"); 941 elements* e=serv->outputs; 942 printFullDescription(0,e,"Output",ns_ows,nc1); 943 xmlAddChild(nc,nc1); 944 945 xmlAddChild(n,nc); 946 947 } 948 949 void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){ 1089 { 1090 if (j > 0) 1091 xmlNewProp (nc, BAD_CAST tmp4[j], BAD_CAST "false"); 1092 } 1093 } 1094 1095 tmp1 = getMapFromMaps (m, "lenv", "level"); 1096 addPrefix (m, tmp1, serv); 1097 printDescription (nc, ns_ows, serv->identifier, serv->content); 1098 1099 tmp1 = serv->metadata; 1100 while (tmp1 != NULL) 1101 { 1102 nc1 = xmlNewNode (ns_ows, BAD_CAST "Metadata"); 1103 xmlNewNsProp (nc1, ns_xlink, BAD_CAST tmp1->name, BAD_CAST tmp1->value); 1104 xmlAddChild (nc, nc1); 1105 tmp1 = tmp1->next; 1106 } 1107 1108 tmp1 = getMap (serv->content, "Profile"); 1109 if (tmp1 != NULL) 1110 { 1111 nc1 = xmlNewNode (ns, BAD_CAST "Profile"); 1112 xmlAddChild (nc1, xmlNewText (BAD_CAST tmp1->value)); 1113 xmlAddChild (nc, nc1); 1114 } 1115 1116 if (serv->inputs != NULL) 1117 { 1118 nc1 = xmlNewNode (NULL, BAD_CAST "DataInputs"); 1119 elements *e = serv->inputs; 1120 printFullDescription (1, e, "Input", ns_ows, nc1); 1121 xmlAddChild (nc, nc1); 1122 } 1123 1124 nc1 = xmlNewNode (NULL, BAD_CAST "ProcessOutputs"); 1125 elements *e = serv->outputs; 1126 printFullDescription (0, e, "Output", ns_ows, nc1); 1127 xmlAddChild (nc, nc1); 1128 1129 xmlAddChild (n, nc); 1130 1131 } 1132 1133 void 1134 printFullDescription (int in, elements * elem, const char *type, 1135 xmlNsPtr ns_ows, xmlNodePtr nc1) 1136 { 950 1137 const char *orderedFields[13]; 951 orderedFields[0]="mimeType"; 952 orderedFields[1]="encoding"; 953 orderedFields[2]="schema"; 954 orderedFields[3]="dataType"; 955 orderedFields[4]="uom"; 956 orderedFields[5]="CRS"; 957 orderedFields[6]="value"; 958 orderedFields[7]="AllowedValues"; 959 orderedFields[8]="range"; 960 orderedFields[9]="rangeMin"; 961 orderedFields[10]="rangeMax"; 962 orderedFields[11]="rangeClosure"; 963 orderedFields[12]="rangeSpace"; 964 965 xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7,nc8,nc9; 966 elements* e=elem; 967 968 map* tmp1=NULL; 969 while(e!=NULL){ 970 int default1=0; 971 int isAnyValue=1; 972 nc2 = xmlNewNode(NULL, BAD_CAST type); 973 if(strncmp(type,"Input",5)==0){ 974 tmp1=getMap(e->content,"minOccurs"); 975 if(tmp1!=NULL){ 976 xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 977 }else 978 xmlNewProp(nc2,BAD_CAST "minOccurs",BAD_CAST "0"); 979 tmp1=getMap(e->content,"maxOccurs"); 980 if(tmp1!=NULL){ 981 if(strcasecmp(tmp1->value,"unbounded")!=0) 982 xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value); 983 else 984 xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1000"); 985 }else 986 xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1"); 987 if((tmp1=getMap(e->content,"maximumMegabytes"))!=NULL){ 988 xmlNewProp(nc2,BAD_CAST "maximumMegabytes",BAD_CAST tmp1->value); 989 } 990 } 991 992 printDescription(nc2,ns_ows,e->name,e->content); 1138 orderedFields[0] = "mimeType"; 1139 orderedFields[1] = "encoding"; 1140 orderedFields[2] = "schema"; 1141 orderedFields[3] = "dataType"; 1142 orderedFields[4] = "uom"; 1143 orderedFields[5] = "CRS"; 1144 orderedFields[6] = "value"; 1145 orderedFields[7] = "AllowedValues"; 1146 orderedFields[8] = "range"; 1147 orderedFields[9] = "rangeMin"; 1148 orderedFields[10] = "rangeMax"; 1149 orderedFields[11] = "rangeClosure"; 1150 orderedFields[12] = "rangeSpace"; 1151 1152 xmlNodePtr nc2, nc3, nc4, nc5, nc6, nc7, nc8, nc9; 1153 elements *e = elem; 1154 1155 map *tmp1 = NULL; 1156 while (e != NULL) 1157 { 1158 int default1 = 0; 1159 int isAnyValue = 1; 1160 nc2 = xmlNewNode (NULL, BAD_CAST type); 1161 if (strncmp (type, "Input", 5) == 0) 1162 { 1163 tmp1 = getMap (e->content, "minOccurs"); 1164 if (tmp1 != NULL) 1165 { 1166 xmlNewProp (nc2, BAD_CAST tmp1->name, BAD_CAST tmp1->value); 1167 } 1168 else 1169 xmlNewProp (nc2, BAD_CAST "minOccurs", BAD_CAST "0"); 1170 tmp1 = getMap (e->content, "maxOccurs"); 1171 if (tmp1 != NULL) 1172 { 1173 if (strcasecmp (tmp1->value, "unbounded") != 0) 1174 xmlNewProp (nc2, BAD_CAST tmp1->name, BAD_CAST tmp1->value); 1175 else 1176 xmlNewProp (nc2, BAD_CAST "maxOccurs", BAD_CAST "1000"); 1177 } 1178 else 1179 xmlNewProp (nc2, BAD_CAST "maxOccurs", BAD_CAST "1"); 1180 if ((tmp1 = getMap (e->content, "maximumMegabytes")) != NULL) 1181 { 1182 xmlNewProp (nc2, BAD_CAST "maximumMegabytes", 1183 BAD_CAST tmp1->value); 1184 } 1185 } 1186 1187 printDescription (nc2, ns_ows, e->name, e->content); 993 1188 994 1189 /** 995 1190 * Build the (Literal/Complex/BoundingBox)Data node 996 1191 */ 997 if(strncmp(type,"Output",6)==0){ 998 if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0) 999 nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput"); 1000 else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) 1001 nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput"); 1002 else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) 1003 nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxOutput"); 1192 if (strncmp (type, "Output", 6) == 0) 1193 { 1194 if (strncasecmp (e->format, "LITERALDATA", strlen (e->format)) == 0) 1195 nc3 = xmlNewNode (NULL, BAD_CAST "LiteralOutput"); 1196 else if (strncasecmp (e->format, "COMPLEXDATA", strlen (e->format)) 1197 == 0) 1198 nc3 = xmlNewNode (NULL, BAD_CAST "ComplexOutput"); 1199 else 1200 if (strncasecmp (e->format, "BOUNDINGBOXDATA", strlen (e->format)) 1201 == 0) 1202 nc3 = xmlNewNode (NULL, BAD_CAST "BoundingBoxOutput"); 1203 else 1204 nc3 = xmlNewNode (NULL, BAD_CAST e->format); 1205 } 1004 1206 else 1005 nc3 = xmlNewNode(NULL, BAD_CAST e->format); 1006 }else{ 1007 if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0){ 1008 nc3 = xmlNewNode(NULL, BAD_CAST "LiteralData"); 1009 } 1010 else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0) 1011 nc3 = xmlNewNode(NULL, BAD_CAST "ComplexData"); 1012 else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0) 1013 nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxData"); 1014 else 1015 nc3 = xmlNewNode(NULL, BAD_CAST e->format); 1016 } 1017 1018 iotype* _tmp0=NULL; 1019 iotype* _tmp=e->defaults; 1020 int datatype=0; 1021 bool hasUOM=false; 1022 bool hasUOM1=false; 1023 if(_tmp!=NULL){ 1024 if(strcmp(e->format,"LiteralOutput")==0 || 1025 strcmp(e->format,"LiteralData")==0){ 1026 datatype=1; 1027 nc4 = xmlNewNode(NULL, BAD_CAST "UOMs"); 1028 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1029 } 1030 else if(strcmp(e->format,"BoundingBoxOutput")==0 || 1031 strcmp(e->format,"BoundingBoxData")==0){ 1032 datatype=2; 1033 nc5 = xmlNewNode(NULL, BAD_CAST "Default"); 1034 } 1035 else{ 1036 nc4 = xmlNewNode(NULL, BAD_CAST "Default"); 1037 nc5 = xmlNewNode(NULL, BAD_CAST "Format"); 1038 } 1039 1040 tmp1=_tmp->content; 1041 1042 if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){ 1043 nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType"); 1044 xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value)); 1045 char tmp[1024]; 1046 sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value); 1047 xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp); 1048 xmlAddChild(nc3,nc8); 1049 datatype=1; 1050 } 1051 1052 if(strncmp(type,"Input",5)==0){ 1053 1054 if((tmp1=getMap(_tmp->content,"AllowedValues"))!=NULL){ 1055 nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); 1056 char *token,*saveptr1; 1057 token=strtok_r(tmp1->value,",",&saveptr1); 1058 while(token!=NULL){ 1059 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1060 char *tmps=strdup(token); 1061 tmps[strlen(tmps)]=0; 1062 xmlAddChild(nc7,xmlNewText(BAD_CAST tmps)); 1063 free(tmps); 1064 xmlAddChild(nc6,nc7); 1065 token=strtok_r(NULL,",",&saveptr1); 1066 } 1067 if(getMap(_tmp->content,"range")!=NULL || 1068 getMap(_tmp->content,"rangeMin")!=NULL || 1069 getMap(_tmp->content,"rangeMax")!=NULL || 1070 getMap(_tmp->content,"rangeClosure")!=NULL ) 1071 goto doRange; 1072 xmlAddChild(nc3,nc6); 1073 isAnyValue=-1; 1074 } 1075 1076 tmp1=getMap(_tmp->content,"range"); 1077 if(tmp1==NULL) 1078 tmp1=getMap(_tmp->content,"rangeMin"); 1079 if(tmp1==NULL) 1080 tmp1=getMap(_tmp->content,"rangeMax"); 1081 1082 if(tmp1!=NULL && isAnyValue==1){ 1083 nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); 1084 doRange: 1085 1086 /** 1207 { 1208 if (strncasecmp (e->format, "LITERALDATA", strlen (e->format)) == 0) 1209 { 1210 nc3 = xmlNewNode (NULL, BAD_CAST "LiteralData"); 1211 } 1212 else if (strncasecmp (e->format, "COMPLEXDATA", strlen (e->format)) 1213 == 0) 1214 nc3 = xmlNewNode (NULL, BAD_CAST "ComplexData"); 1215 else 1216 if (strncasecmp (e->format, "BOUNDINGBOXDATA", strlen (e->format)) 1217 == 0) 1218 nc3 = xmlNewNode (NULL, BAD_CAST "BoundingBoxData"); 1219 else 1220 nc3 = xmlNewNode (NULL, BAD_CAST e->format); 1221 } 1222 1223 iotype *_tmp0 = NULL; 1224 iotype *_tmp = e->defaults; 1225 int datatype = 0; 1226 bool hasUOM = false; 1227 bool hasUOM1 = false; 1228 if (_tmp != NULL) 1229 { 1230 if (strcmp (e->format, "LiteralOutput") == 0 || 1231 strcmp (e->format, "LiteralData") == 0) 1232 { 1233 datatype = 1; 1234 nc4 = xmlNewNode (NULL, BAD_CAST "UOMs"); 1235 nc5 = xmlNewNode (NULL, BAD_CAST "Default"); 1236 } 1237 else if (strcmp (e->format, "BoundingBoxOutput") == 0 || 1238 strcmp (e->format, "BoundingBoxData") == 0) 1239 { 1240 datatype = 2; 1241 nc5 = xmlNewNode (NULL, BAD_CAST "Default"); 1242 } 1243 else 1244 { 1245 nc4 = xmlNewNode (NULL, BAD_CAST "Default"); 1246 nc5 = xmlNewNode (NULL, BAD_CAST "Format"); 1247 } 1248 1249 tmp1 = _tmp->content; 1250 1251 if ((tmp1 = getMap (_tmp->content, "DataType")) != NULL) 1252 { 1253 nc8 = xmlNewNode (ns_ows, BAD_CAST "DataType"); 1254 xmlAddChild (nc8, xmlNewText (BAD_CAST tmp1->value)); 1255 char tmp[1024]; 1256 sprintf (tmp, "http://www.w3.org/TR/xmlschema-2/#%s", 1257 tmp1->value); 1258 xmlNewNsProp (nc8, ns_ows, BAD_CAST "reference", BAD_CAST tmp); 1259 xmlAddChild (nc3, nc8); 1260 datatype = 1; 1261 } 1262 1263 if (strncmp (type, "Input", 5) == 0) 1264 { 1265 1266 if ((tmp1 = getMap (_tmp->content, "AllowedValues")) != NULL) 1267 { 1268 nc6 = xmlNewNode (ns_ows, BAD_CAST "AllowedValues"); 1269 char *token, *saveptr1; 1270 token = strtok_r (tmp1->value, ",", &saveptr1); 1271 while (token != NULL) 1272 { 1273 nc7 = xmlNewNode (ns_ows, BAD_CAST "Value"); 1274 char *tmps = strdup (token); 1275 tmps[strlen (tmps)] = 0; 1276 xmlAddChild (nc7, xmlNewText (BAD_CAST tmps)); 1277 free (tmps); 1278 xmlAddChild (nc6, nc7); 1279 token = strtok_r (NULL, ",", &saveptr1); 1280 } 1281 if (getMap (_tmp->content, "range") != NULL || 1282 getMap (_tmp->content, "rangeMin") != NULL || 1283 getMap (_tmp->content, "rangeMax") != NULL || 1284 getMap (_tmp->content, "rangeClosure") != NULL) 1285 goto doRange; 1286 xmlAddChild (nc3, nc6); 1287 isAnyValue = -1; 1288 } 1289 1290 tmp1 = getMap (_tmp->content, "range"); 1291 if (tmp1 == NULL) 1292 tmp1 = getMap (_tmp->content, "rangeMin"); 1293 if (tmp1 == NULL) 1294 tmp1 = getMap (_tmp->content, "rangeMax"); 1295 1296 if (tmp1 != NULL && isAnyValue == 1) 1297 { 1298 nc6 = xmlNewNode (ns_ows, BAD_CAST "AllowedValues"); 1299 doRange: 1300 1301 /** 1087 1302 * Range: Table 46 OGC Web Services Common Standard 1088 1303 */ 1089 nc8 = xmlNewNode(ns_ows, BAD_CAST "Range"); 1090 1091 map* tmp0=getMap(tmp1,"range"); 1092 if(tmp0!=NULL){ 1093 char* pToken; 1094 char* orig=zStrdup(tmp0->value); 1095 /** 1304 nc8 = xmlNewNode (ns_ows, BAD_CAST "Range"); 1305 1306 map *tmp0 = getMap (tmp1, "range"); 1307 if (tmp0 != NULL) 1308 { 1309 char *pToken; 1310 char *orig = zStrdup (tmp0->value); 1311 /** 1096 1312 * RangeClosure: Table 47 OGC Web Services Common Standard 1097 1313 */ 1098 const char *tmp="closed"; 1099 if(orig[0]=='[' && orig[strlen(orig)-1]=='[') 1100 tmp="closed-open"; 1101 else 1102 if(orig[0]==']' && orig[strlen(orig)-1]==']') 1103 tmp="open-closed"; 1104 else 1105 if(orig[0]==']' && orig[strlen(orig)-1]=='[') 1106 tmp="open"; 1107 xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp); 1108 pToken=strtok(orig,","); 1109 int nci0=0; 1110 while(pToken!=NULL){ 1111 char *tmpStr=(char*) malloc((strlen(pToken))*sizeof(char)); 1112 if(nci0==0){ 1113 nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); 1114 int nci=1; 1115 for(nci=1;nci<strlen(pToken);nci++){ 1116 tmpStr[nci-1]=pToken[nci]; 1117 } 1118 }else{ 1119 nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); 1120 int nci=0; 1121 for(nci=0;nci<strlen(pToken)-1;nci++){ 1122 tmpStr[nci]=pToken[nci]; 1123 } 1124 } 1125 xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr)); 1126 free(tmpStr); 1127 xmlAddChild(nc8,nc7); 1128 nci0++; 1129 pToken = strtok(NULL,","); 1130 } 1131 if(getMap(tmp1,"rangeSpacing")==NULL){ 1132 nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing"); 1133 xmlAddChild(nc7,xmlNewText(BAD_CAST "1")); 1134 xmlAddChild(nc8,nc7); 1135 } 1136 free(orig); 1137 }else{ 1138 1139 tmp0=getMap(tmp1,"rangeMin"); 1140 if(tmp0!=NULL){ 1141 nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); 1142 xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); 1143 xmlAddChild(nc8,nc7); 1144 }else{ 1145 nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue"); 1146 xmlAddChild(nc8,nc7); 1147 } 1148 tmp0=getMap(tmp1,"rangeMax"); 1149 if(tmp0!=NULL){ 1150 nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); 1151 xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); 1152 xmlAddChild(nc8,nc7); 1153 }else{ 1154 nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue"); 1155 xmlAddChild(nc8,nc7); 1156 } 1157 tmp0=getMap(tmp1,"rangeSpacing"); 1158 if(tmp0!=NULL){ 1159 nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing"); 1160 xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value)); 1161 xmlAddChild(nc8,nc7); 1162 } 1163 tmp0=getMap(tmp1,"rangeClosure"); 1164 if(tmp0!=NULL){ 1165 const char *tmp="closed"; 1166 if(strcasecmp(tmp0->value,"co")==0) 1167 tmp="closed-open"; 1168 else 1169 if(strcasecmp(tmp0->value,"oc")==0) 1170 tmp="open-closed"; 1171 else 1172 if(strcasecmp(tmp0->value,"o")==0) 1173 tmp="open"; 1174 xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp); 1175 }else 1176 xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST "closed"); 1177 } 1178 if(_tmp0==NULL){ 1179 xmlAddChild(nc6,nc8); 1180 _tmp0=e->supported; 1181 if(getMap(_tmp0->content,"range")!=NULL || 1182 getMap(_tmp0->content,"rangeMin")!=NULL || 1183 getMap(_tmp0->content,"rangeMax")!=NULL || 1184 getMap(_tmp0->content,"rangeClosure")!=NULL ){ 1185 tmp1=_tmp0->content; 1186 goto doRange; 1187 } 1188 }else{ 1189 _tmp0=_tmp0->next; 1190 if(_tmp0!=NULL){ 1191 xmlAddChild(nc6,nc8); 1192 if(getMap(_tmp0->content,"range")!=NULL || 1193 getMap(_tmp0->content,"rangeMin")!=NULL || 1194 getMap(_tmp0->content,"rangeMax")!=NULL || 1195 getMap(_tmp0->content,"rangeClosure")!=NULL ){ 1196 tmp1=_tmp0->content; 1197 goto doRange; 1198 } 1199 } 1200 } 1201 xmlAddChild(nc6,nc8); 1202 xmlAddChild(nc3,nc6); 1203 isAnyValue=-1; 1204 } 1205 1206 } 1207 1208 1209 int oI=0; 1210 for(oI=0;oI<13;oI++) 1211 if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ 1314 const char *tmp = "closed"; 1315 if (orig[0] == '[' && orig[strlen (orig) - 1] == '[') 1316 tmp = "closed-open"; 1317 else 1318 if (orig[0] == ']' && orig[strlen (orig) - 1] == ']') 1319 tmp = "open-closed"; 1320 else 1321 if (orig[0] == ']' && orig[strlen (orig) - 1] == '[') 1322 tmp = "open"; 1323 xmlNewNsProp (nc8, ns_ows, BAD_CAST "rangeClosure", 1324 BAD_CAST tmp); 1325 pToken = strtok (orig, ","); 1326 int nci0 = 0; 1327 while (pToken != NULL) 1328 { 1329 char *tmpStr = 1330 (char *) malloc ((strlen (pToken)) * 1331 sizeof (char)); 1332 if (nci0 == 0) 1333 { 1334 nc7 = 1335 xmlNewNode (ns_ows, BAD_CAST "MinimumValue"); 1336 int nci = 1; 1337 for (nci = 1; nci < strlen (pToken); nci++) 1338 { 1339 tmpStr[nci - 1] = pToken[nci]; 1340 } 1341 } 1342 else 1343 { 1344 nc7 = 1345 xmlNewNode (ns_ows, BAD_CAST "MaximumValue"); 1346 int nci = 0; 1347 for (nci = 0; nci < strlen (pToken) - 1; nci++) 1348 { 1349 tmpStr[nci] = pToken[nci]; 1350 } 1351 } 1352 xmlAddChild (nc7, xmlNewText (BAD_CAST tmpStr)); 1353 free (tmpStr); 1354 xmlAddChild (nc8, nc7); 1355 nci0++; 1356 pToken = strtok (NULL, ","); 1357 } 1358 if (getMap (tmp1, "rangeSpacing") == NULL) 1359 { 1360 nc7 = xmlNewNode (ns_ows, BAD_CAST "Spacing"); 1361 xmlAddChild (nc7, xmlNewText (BAD_CAST "1")); 1362 xmlAddChild (nc8, nc7); 1363 } 1364 free (orig); 1365 } 1366 else 1367 { 1368 1369 tmp0 = getMap (tmp1, "rangeMin"); 1370 if (tmp0 != NULL) 1371 { 1372 nc7 = xmlNewNode (ns_ows, BAD_CAST "MinimumValue"); 1373 xmlAddChild (nc7, 1374 xmlNewText (BAD_CAST tmp0->value)); 1375 xmlAddChild (nc8, nc7); 1376 } 1377 else 1378 { 1379 nc7 = xmlNewNode (ns_ows, BAD_CAST "MinimumValue"); 1380 xmlAddChild (nc8, nc7); 1381 } 1382 tmp0 = getMap (tmp1, "rangeMax"); 1383 if (tmp0 != NULL) 1384 { 1385 nc7 = xmlNewNode (ns_ows, BAD_CAST "MaximumValue"); 1386 xmlAddChild (nc7, 1387 xmlNewText (BAD_CAST tmp0->value)); 1388 xmlAddChild (nc8, nc7); 1389 } 1390 else 1391 { 1392 nc7 = xmlNewNode (ns_ows, BAD_CAST "MaximumValue"); 1393 xmlAddChild (nc8, nc7); 1394 } 1395 tmp0 = getMap (tmp1, "rangeSpacing"); 1396 if (tmp0 != NULL) 1397 { 1398 nc7 = xmlNewNode (ns_ows, BAD_CAST "Spacing"); 1399 xmlAddChild (nc7, 1400 xmlNewText (BAD_CAST tmp0->value)); 1401 xmlAddChild (nc8, nc7); 1402 } 1403 tmp0 = getMap (tmp1, "rangeClosure"); 1404 if (tmp0 != NULL) 1405 { 1406 const char *tmp = "closed"; 1407 if (strcasecmp (tmp0->value, "co") == 0) 1408 tmp = "closed-open"; 1409 else if (strcasecmp (tmp0->value, "oc") == 0) 1410 tmp = "open-closed"; 1411 else if (strcasecmp (tmp0->value, "o") == 0) 1412 tmp = "open"; 1413 xmlNewNsProp (nc8, ns_ows, BAD_CAST "rangeClosure", 1414 BAD_CAST tmp); 1415 } 1416 else 1417 xmlNewNsProp (nc8, ns_ows, BAD_CAST "rangeClosure", 1418 BAD_CAST "closed"); 1419 } 1420 if (_tmp0 == NULL) 1421 { 1422 xmlAddChild (nc6, nc8); 1423 _tmp0 = e->supported; 1424 if (getMap (_tmp0->content, "range") != NULL || 1425 getMap (_tmp0->content, "rangeMin") != NULL || 1426 getMap (_tmp0->content, "rangeMax") != NULL || 1427 getMap (_tmp0->content, "rangeClosure") != NULL) 1428 { 1429 tmp1 = _tmp0->content; 1430 goto doRange; 1431 } 1432 } 1433 else 1434 { 1435 _tmp0 = _tmp0->next; 1436 if (_tmp0 != NULL) 1437 { 1438 xmlAddChild (nc6, nc8); 1439 if (getMap (_tmp0->content, "range") != NULL || 1440 getMap (_tmp0->content, "rangeMin") != NULL || 1441 getMap (_tmp0->content, "rangeMax") != NULL || 1442 getMap (_tmp0->content, "rangeClosure") != NULL) 1443 { 1444 tmp1 = _tmp0->content; 1445 goto doRange; 1446 } 1447 } 1448 } 1449 xmlAddChild (nc6, nc8); 1450 xmlAddChild (nc3, nc6); 1451 isAnyValue = -1; 1452 } 1453 1454 } 1455 1456 1457 int oI = 0; 1458 for (oI = 0; oI < 13; oI++) 1459 if ((tmp1 = getMap (_tmp->content, orderedFields[oI])) != NULL) 1460 { 1212 1461 #ifdef DEBUG 1213 printf("DATATYPE DEFAULT ? %s\n",tmp1->name); 1214 #endif 1215 if(strcmp(tmp1->name,"asReference")!=0 && 1216 strncasecmp(tmp1->name,"DataType",8)!=0 && 1217 strcasecmp(tmp1->name,"extension")!=0 && 1218 strcasecmp(tmp1->name,"value")!=0 && 1219 strcasecmp(tmp1->name,"AllowedValues")!=0 && 1220 strncasecmp(tmp1->name,"range",5)!=0){ 1221 if(datatype!=1){ 1222 char *tmp2=zCapitalize1(tmp1->name); 1223 nc9 = xmlNewNode(NULL, BAD_CAST tmp2); 1224 free(tmp2); 1225 } 1226 else{ 1227 char *tmp2=zCapitalize(tmp1->name); 1228 nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2); 1229 free(tmp2); 1230 } 1231 xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value)); 1232 xmlAddChild(nc5,nc9); 1233 if(strcasecmp(tmp1->name,"uom")==0) 1234 hasUOM1=true; 1235 hasUOM=true; 1236 }else 1237 1238 tmp1=tmp1->next; 1239 } 1240 1241 1242 if(datatype!=2){ 1243 if(hasUOM==true){ 1244 xmlAddChild(nc4,nc5); 1245 xmlAddChild(nc3,nc4); 1246 }else{ 1247 if(hasUOM1==false){ 1248 xmlFreeNode(nc5); 1249 if(datatype==1) 1250 xmlFreeNode(nc4); 1251 } 1252 } 1253 }else{ 1254 xmlAddChild(nc3,nc5); 1255 } 1256 1257 if(datatype!=1 && default1<0){ 1258 xmlFreeNode(nc5); 1259 if(datatype!=2) 1260 xmlFreeNode(nc4); 1261 } 1262 1263 map* metadata=e->metadata; 1264 xmlNodePtr n=NULL; 1265 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 1266 xmlNsPtr ns_xlink=usedNs[xlinkId]; 1267 1268 while(metadata!=NULL){ 1269 nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata"); 1270 xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value); 1271 xmlAddChild(nc2,nc6); 1272 metadata=metadata->next; 1273 } 1274 1275 } 1276 1277 _tmp=e->supported; 1278 if(_tmp==NULL && datatype!=1) 1279 _tmp=e->defaults; 1280 1281 int hasSupported=-1; 1282 1283 while(_tmp!=NULL){ 1284 if(hasSupported<0){ 1285 if(datatype==0){ 1286 nc4 = xmlNewNode(NULL, BAD_CAST "Supported"); 1287 nc5 = xmlNewNode(NULL, BAD_CAST "Format"); 1288 } 1289 else 1290 nc5 = xmlNewNode(NULL, BAD_CAST "Supported"); 1291 hasSupported=0; 1292 }else 1293 if(datatype==0) 1294 nc5 = xmlNewNode(NULL, BAD_CAST "Format"); 1295 tmp1=_tmp->content; 1296 int oI=0; 1297 for(oI=0;oI<6;oI++) 1298 if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){ 1462 printf ("DATATYPE DEFAULT ? %s\n", tmp1->name); 1463 #endif 1464 if (strcmp (tmp1->name, "asReference") != 0 && 1465 strncasecmp (tmp1->name, "DataType", 8) != 0 && 1466 strcasecmp (tmp1->name, "extension") != 0 && 1467 strcasecmp (tmp1->name, "value") != 0 && 1468 strcasecmp (tmp1->name, "AllowedValues") != 0 && 1469 strncasecmp (tmp1->name, "range", 5) != 0) 1470 { 1471 if (datatype != 1) 1472 { 1473 char *tmp2 = zCapitalize1 (tmp1->name); 1474 nc9 = xmlNewNode (NULL, BAD_CAST tmp2); 1475 free (tmp2); 1476 } 1477 else 1478 { 1479 char *tmp2 = zCapitalize (tmp1->name); 1480 nc9 = xmlNewNode (ns_ows, BAD_CAST tmp2); 1481 free (tmp2); 1482 } 1483 xmlAddChild (nc9, xmlNewText (BAD_CAST tmp1->value)); 1484 xmlAddChild (nc5, nc9); 1485 if (strcasecmp (tmp1->name, "uom") == 0) 1486 hasUOM1 = true; 1487 hasUOM = true; 1488 } 1489 else 1490 1491 tmp1 = tmp1->next; 1492 } 1493 1494 1495 if (datatype != 2) 1496 { 1497 if (hasUOM == true) 1498 { 1499 xmlAddChild (nc4, nc5); 1500 xmlAddChild (nc3, nc4); 1501 } 1502 else 1503 { 1504 if (hasUOM1 == false) 1505 { 1506 xmlFreeNode (nc5); 1507 if (datatype == 1) 1508 xmlFreeNode (nc4); 1509 } 1510 } 1511 } 1512 else 1513 { 1514 xmlAddChild (nc3, nc5); 1515 } 1516 1517 if (datatype != 1 && default1 < 0) 1518 { 1519 xmlFreeNode (nc5); 1520 if (datatype != 2) 1521 xmlFreeNode (nc4); 1522 } 1523 1524 map *metadata = e->metadata; 1525 xmlNodePtr n = NULL; 1526 int xlinkId = 1527 zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink"); 1528 xmlNsPtr ns_xlink = usedNs[xlinkId]; 1529 1530 while (metadata != NULL) 1531 { 1532 nc6 = xmlNewNode (ns_ows, BAD_CAST "Metadata"); 1533 xmlNewNsProp (nc6, ns_xlink, BAD_CAST metadata->name, 1534 BAD_CAST metadata->value); 1535 xmlAddChild (nc2, nc6); 1536 metadata = metadata->next; 1537 } 1538 1539 } 1540 1541 _tmp = e->supported; 1542 if (_tmp == NULL && datatype != 1) 1543 _tmp = e->defaults; 1544 1545 int hasSupported = -1; 1546 1547 while (_tmp != NULL) 1548 { 1549 if (hasSupported < 0) 1550 { 1551 if (datatype == 0) 1552 { 1553 nc4 = xmlNewNode (NULL, BAD_CAST "Supported"); 1554 nc5 = xmlNewNode (NULL, BAD_CAST "Format"); 1555 } 1556 else 1557 nc5 = xmlNewNode (NULL, BAD_CAST "Supported"); 1558 hasSupported = 0; 1559 } 1560 else if (datatype == 0) 1561 nc5 = xmlNewNode (NULL, BAD_CAST "Format"); 1562 tmp1 = _tmp->content; 1563 int oI = 0; 1564 for (oI = 0; oI < 6; oI++) 1565 if ((tmp1 = getMap (_tmp->content, orderedFields[oI])) != NULL) 1566 { 1299 1567 #ifdef DEBUG 1300 printf("DATATYPE SUPPORTED ? %s\n",tmp1->name); 1301 #endif 1302 if(strcmp(tmp1->name,"asReference")!=0 && 1303 strcmp(tmp1->name,"value")!=0 && 1304 strcmp(tmp1->name,"DataType")!=0 && 1305 strcasecmp(tmp1->name,"extension")!=0){ 1306 if(datatype!=1){ 1307 char *tmp2=zCapitalize1(tmp1->name); 1308 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1309 free(tmp2); 1310 } 1311 else{ 1312 char *tmp2=zCapitalize(tmp1->name); 1313 nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2); 1314 free(tmp2); 1315 } 1316 if(datatype==2){ 1317 char *tmpv,*tmps; 1318 tmps=strtok_r(tmp1->value,",",&tmpv); 1319 while(tmps){ 1320 xmlAddChild(nc6,xmlNewText(BAD_CAST tmps)); 1321 tmps=strtok_r(NULL,",",&tmpv); 1322 if(tmps){ 1323 char *tmp2=zCapitalize1(tmp1->name); 1324 nc6 = xmlNewNode(NULL, BAD_CAST tmp2); 1325 free(tmp2); 1326 } 1327 } 1328 } 1329 else{ 1330 xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value)); 1331 } 1332 xmlAddChild(nc5,nc6); 1333 } 1334 tmp1=tmp1->next; 1335 } 1336 if(hasSupported<=0){ 1337 if(datatype==0){ 1338 xmlAddChild(nc4,nc5); 1339 xmlAddChild(nc3,nc4); 1340 }else{ 1341 if(datatype!=1) 1342 xmlAddChild(nc3,nc5); 1343 } 1344 hasSupported=1; 1345 } 1346 else 1347 if(datatype==0){ 1348 xmlAddChild(nc4,nc5); 1349 xmlAddChild(nc3,nc4); 1350 } 1351 else 1352 if(datatype!=1) 1353 xmlAddChild(nc3,nc5); 1354 1355 _tmp=_tmp->next; 1356 } 1357 1358 if(hasSupported==0){ 1359 if(datatype==0) 1360 xmlFreeNode(nc4); 1361 xmlFreeNode(nc5); 1362 } 1363 1364 _tmp=e->defaults; 1365 if(datatype==1 && hasUOM1==true){ 1366 xmlAddChild(nc4,nc5); 1367 xmlAddChild(nc3,nc4); 1368 } 1369 1370 if(in>0 && datatype==1 && 1371 getMap(_tmp->content,"AllowedValues")==NULL && 1372 getMap(_tmp->content,"range")==NULL && 1373 getMap(_tmp->content,"rangeMin")==NULL && 1374 getMap(_tmp->content,"rangeMax")==NULL && 1375 getMap(_tmp->content,"rangeClosure")==NULL ){ 1376 tmp1=getMap(_tmp->content,"dataType"); 1377 if(tmp1!=NULL) 1378 if(strcasecmp(tmp1->value,"boolean")==0){ 1379 nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues"); 1380 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1381 xmlAddChild(nc7,xmlNewText(BAD_CAST "true")); 1382 xmlAddChild(nc6,nc7); 1383 nc7 = xmlNewNode(ns_ows, BAD_CAST "Value"); 1384 xmlAddChild(nc7,xmlNewText(BAD_CAST "false")); 1385 xmlAddChild(nc6,nc7); 1386 xmlAddChild(nc3,nc6); 1387 } 1388 xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue")); 1389 } 1390 1391 if((tmp1=getMap(_tmp->content,"value"))!=NULL){ 1392 nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue"); 1393 xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value)); 1394 xmlAddChild(nc3,nc7); 1395 } 1396 1397 xmlAddChild(nc2,nc3); 1398 1399 xmlAddChild(nc1,nc2); 1400 1401 e=e->next; 1402 } 1403 } 1404 1405 void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){ 1406 xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi; 1407 xmlNodePtr nr,n,nc,nc1=NULL,nc3; 1568 printf ("DATATYPE SUPPORTED ? %s\n", tmp1->name); 1569 #endif 1570 if (strcmp (tmp1->name, "asReference") != 0 && 1571 strcmp (tmp1->name, "value") != 0 && 1572 strcmp (tmp1->name, "DataType") != 0 && 1573 strcasecmp (tmp1->name, "extension") != 0) 1574 { 1575 if (datatype != 1) 1576 { 1577 char *tmp2 = zCapitalize1 (tmp1->name); 1578 nc6 = xmlNewNode (NULL, BAD_CAST tmp2); 1579 free (tmp2); 1580 } 1581 else 1582 { 1583 char *tmp2 = zCapitalize (tmp1->name); 1584 nc6 = xmlNewNode (ns_ows, BAD_CAST tmp2); 1585 free (tmp2); 1586 } 1587 if (datatype == 2) 1588 { 1589 char *tmpv, *tmps; 1590 tmps = strtok_r (tmp1->value, ",", &tmpv); 1591 while (tmps) 1592 { 1593 xmlAddChild (nc6, xmlNewText (BAD_CAST tmps)); 1594 tmps = strtok_r (NULL, ",", &tmpv); 1595 if (tmps) 1596 { 1597 char *tmp2 = zCapitalize1 (tmp1->name); 1598 nc6 = xmlNewNode (NULL, BAD_CAST tmp2); 1599 free (tmp2); 1600 } 1601 } 1602 } 1603 else 1604 { 1605 xmlAddChild (nc6, xmlNewText (BAD_CAST tmp1->value)); 1606 } 1607 xmlAddChild (nc5, nc6); 1608 } 1609 tmp1 = tmp1->next; 1610 } 1611 if (hasSupported <= 0) 1612 { 1613 if (datatype == 0) 1614 { 1615 xmlAddChild (nc4, nc5); 1616 xmlAddChild (nc3, nc4); 1617 } 1618 else 1619 { 1620 if (datatype != 1) 1621 xmlAddChild (nc3, nc5); 1622 } 1623 hasSupported = 1; 1624 } 1625 else if (datatype == 0) 1626 { 1627 xmlAddChild (nc4, nc5); 1628 xmlAddChild (nc3, nc4); 1629 } 1630 else if (datatype != 1) 1631 xmlAddChild (nc3, nc5); 1632 1633 _tmp = _tmp->next; 1634 } 1635 1636 if (hasSupported == 0) 1637 { 1638 if (datatype == 0) 1639 xmlFreeNode (nc4); 1640 xmlFreeNode (nc5); 1641 } 1642 1643 _tmp = e->defaults; 1644 if (datatype == 1 && hasUOM1 == true) 1645 { 1646 xmlAddChild (nc4, nc5); 1647 xmlAddChild (nc3, nc4); 1648 } 1649 1650 if (in > 0 && datatype == 1 && 1651 getMap (_tmp->content, "AllowedValues") == NULL && 1652 getMap (_tmp->content, "range") == NULL && 1653 getMap (_tmp->content, "rangeMin") == NULL && 1654 getMap (_tmp->content, "rangeMax") == NULL && 1655 getMap (_tmp->content, "rangeClosure") == NULL) 1656 { 1657 tmp1 = getMap (_tmp->content, "dataType"); 1658 if (tmp1 != NULL) 1659 if (strcasecmp (tmp1->value, "boolean") == 0) 1660 { 1661 nc6 = xmlNewNode (ns_ows, BAD_CAST "AllowedValues"); 1662 nc7 = xmlNewNode (ns_ows, BAD_CAST "Value"); 1663 xmlAddChild (nc7, xmlNewText (BAD_CAST "true")); 1664 xmlAddChild (nc6, nc7); 1665 nc7 = xmlNewNode (ns_ows, BAD_CAST "Value"); 1666 xmlAddChild (nc7, xmlNewText (BAD_CAST "false")); 1667 xmlAddChild (nc6, nc7); 1668 xmlAddChild (nc3, nc6); 1669 } 1670 xmlAddChild (nc3, xmlNewNode (ns_ows, BAD_CAST "AnyValue")); 1671 } 1672 1673 if ((tmp1 = getMap (_tmp->content, "value")) != NULL) 1674 { 1675 nc7 = xmlNewNode (NULL, BAD_CAST "DefaultValue"); 1676 xmlAddChild (nc7, xmlNewText (BAD_CAST tmp1->value)); 1677 xmlAddChild (nc3, nc7); 1678 } 1679 1680 xmlAddChild (nc2, nc3); 1681 1682 xmlAddChild (nc1, nc2); 1683 1684 e = e->next; 1685 } 1686 } 1687 1688 void 1689 printProcessResponse (maps * m, map * request, int pid, service * serv, 1690 const char *service, int status, maps * inputs, 1691 maps * outputs) 1692 { 1693 xmlNsPtr ns, ns_ows, ns_xlink, ns_xsi; 1694 xmlNodePtr nr, n, nc, nc1 = NULL, nc3; 1408 1695 xmlDocPtr doc; 1409 time_t time1; 1410 time (&time1);1411 nr =NULL;1696 time_t time1; 1697 time (&time1); 1698 nr = NULL; 1412 1699 /** 1413 1700 * Create the document and its temporary root. 1414 1701 */ 1415 doc = xmlNewDoc(BAD_CAST "1.0"); 1416 int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps"); 1417 ns=usedNs[wpsId]; 1418 1419 n = xmlNewNode(ns, BAD_CAST "ExecuteResponse"); 1420 xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps"); 1421 int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows"); 1422 ns_ows=usedNs[owsId]; 1423 int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink"); 1424 ns_xlink=usedNs[xlinkId]; 1425 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 1426 ns_xsi=usedNs[xsiId]; 1427 1428 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"); 1429 1430 xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS"); 1431 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0"); 1432 addLangAttr(n,m); 1702 doc = xmlNewDoc (BAD_CAST "1.0"); 1703 int wpsId = zooXmlAddNs (NULL, "http://www.opengis.net/wps/1.0.0", "wps"); 1704 ns = usedNs[wpsId]; 1705 1706 n = xmlNewNode (ns, BAD_CAST "ExecuteResponse"); 1707 xmlNewNs (n, BAD_CAST "http://www.opengis.net/wps/1.0.0", BAD_CAST "wps"); 1708 int owsId = zooXmlAddNs (n, "http://www.opengis.net/ows/1.1", "ows"); 1709 ns_ows = usedNs[owsId]; 1710 int xlinkId = zooXmlAddNs (n, "http://www.w3.org/1999/xlink", "xlink"); 1711 ns_xlink = usedNs[xlinkId]; 1712 int xsiId = 1713 zooXmlAddNs (n, "http://www.w3.org/2001/XMLSchema-instance", "xsi"); 1714 ns_xsi = usedNs[xsiId]; 1715 1716 xmlNewNsProp (n, ns_xsi, BAD_CAST "schemaLocation", 1717 BAD_CAST 1718 "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd"); 1719 1720 xmlNewProp (n, BAD_CAST "service", BAD_CAST "WPS"); 1721 xmlNewProp (n, BAD_CAST "version", BAD_CAST "1.0.0"); 1722 addLangAttr (n, m); 1433 1723 1434 1724 char tmp[256]; 1435 1725 char url[1024]; 1436 1726 char stored_path[1024]; 1437 memset(tmp,0,256); 1438 memset(url,0,1024); 1439 memset(stored_path,0,1024); 1440 maps* tmp_maps=getMaps(m,"main"); 1441 if(tmp_maps!=NULL){ 1442 map* tmpm1=getMap(tmp_maps->content,"serverAddress"); 1727 memset (tmp, 0, 256); 1728 memset (url, 0, 1024); 1729 memset (stored_path, 0, 1024); 1730 maps *tmp_maps = getMaps (m, "main"); 1731 if (tmp_maps != NULL) 1732 { 1733 map *tmpm1 = getMap (tmp_maps->content, "serverAddress"); 1443 1734 /** 1444 1735 * Check if the ZOO Service GetStatus is available in the local directory. … … 1448 1739 * Else fallback to the initial method using the xml file to write in ... 1449 1740 */ 1450 char ntmp[1024];1741 char ntmp[1024]; 1451 1742 #ifndef WIN32 1452 getcwd(ntmp,1024);1743 getcwd (ntmp, 1024); 1453 1744 #else 1454 _getcwd(ntmp,1024); 1455 #endif 1456 struct stat myFileInfo; 1457 int statRes; 1458 char file_path[1024]; 1459 sprintf(file_path,"%s/GetStatus.zcfg",ntmp); 1460 statRes=stat(file_path,&myFileInfo); 1461 if(statRes==0){ 1462 char currentSid[128]; 1463 map* tmpm=getMap(tmp_maps->content,"rewriteUrl"); 1464 map *tmp_lenv=NULL; 1465 tmp_lenv=getMapFromMaps(m,"lenv","sid"); 1466 if(tmp_lenv==NULL) 1467 sprintf(currentSid,"%i",pid); 1745 _getcwd (ntmp, 1024); 1746 #endif 1747 struct stat myFileInfo; 1748 int statRes; 1749 char file_path[1024]; 1750 sprintf (file_path, "%s/GetStatus.zcfg", ntmp); 1751 statRes = stat (file_path, &myFileInfo); 1752 if (statRes == 0) 1753 { 1754 char currentSid[128]; 1755 map *tmpm = getMap (tmp_maps->content, "rewriteUrl"); 1756 map *tmp_lenv = NULL; 1757 tmp_lenv = getMapFromMaps (m, "lenv", "sid"); 1758 if (tmp_lenv == NULL) 1759 sprintf (currentSid, "%i", pid); 1760 else 1761 sprintf (currentSid, "%s", tmp_lenv->value); 1762 if (tmpm == NULL || strcasecmp (tmpm->value, "false") == 0) 1763 { 1764 sprintf (url, 1765 "%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result", 1766 tmpm1->value, currentSid); 1767 } 1768 else 1769 { 1770 if (strlen (tmpm->value) > 0) 1771 if (strcasecmp (tmpm->value, "true") != 0) 1772 sprintf (url, "%s/%s/GetStatus/%s", tmpm1->value, 1773 tmpm->value, currentSid); 1774 else 1775 sprintf (url, "%s/GetStatus/%s", tmpm1->value, currentSid); 1776 else 1777 sprintf (url, 1778 "%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result", 1779 tmpm1->value, currentSid); 1780 } 1781 } 1468 1782 else 1469 sprintf(currentSid,"%s",tmp_lenv->value); 1470 if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){ 1471 sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); 1472 }else{ 1473 if(strlen(tmpm->value)>0) 1474 if(strcasecmp(tmpm->value,"true")!=0) 1475 sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid); 1476 else 1477 sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid); 1478 else 1479 sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid); 1480 } 1481 }else{ 1482 map* tmpm2=getMap(tmp_maps->content,"tmpUrl"); 1483 if(tmpm1!=NULL && tmpm2!=NULL){ 1484 if( strncasecmp( tmpm2->value, "http://", 7) == 0 || 1485 strncasecmp( tmpm2->value, "https://", 8 ) == 0 ){ 1486 sprintf(url,"%s/%s_%i.xml",tmpm2->value,service,pid); 1487 }else 1488 sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,pid); 1489 } 1490 } 1491 if(tmpm1!=NULL) 1492 sprintf(tmp,"%s",tmpm1->value); 1493 tmpm1=getMapFromMaps(m,"main","TmpPath"); 1494 sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,pid); 1495 } 1496 1497 1498 1499 xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp); 1500 map* test=getMap(request,"storeExecuteResponse"); 1501 bool hasStoredExecuteResponse=false; 1502 if(test!=NULL && strcasecmp(test->value,"true")==0){ 1503 xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url); 1504 hasStoredExecuteResponse=true; 1505 } 1506 1507 nc = xmlNewNode(ns, BAD_CAST "Process"); 1508 map* tmp2=getMap(serv->content,"processVersion"); 1509 if(tmp2!=NULL) 1510 xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value); 1511 1512 printDescription(nc,ns_ows,serv->name,serv->content); 1513 1514 xmlAddChild(n,nc); 1515 1516 nc = xmlNewNode(ns, BAD_CAST "Status"); 1783 { 1784 map *tmpm2 = getMap (tmp_maps->content, "tmpUrl"); 1785 if (tmpm1 != NULL && tmpm2 != NULL) 1786 { 1787 if (strncasecmp (tmpm2->value, "http://", 7) == 0 || 1788 strncasecmp (tmpm2->value, "https://", 8) == 0) 1789 { 1790 sprintf (url, "%s/%s_%i.xml", tmpm2->value, service, pid); 1791 } 1792 else 1793 sprintf (url, "%s/%s/%s_%i.xml", tmpm1->value, tmpm2->value, 1794 service, pid); 1795 } 1796 } 1797 if (tmpm1 != NULL) 1798 sprintf (tmp, "%s", tmpm1->value); 1799 tmpm1 = getMapFromMaps (m, "main", "TmpPath"); 1800 sprintf (stored_path, "%s/%s_%i.xml", tmpm1->value, service, pid); 1801 } 1802 1803 1804 1805 xmlNewProp (n, BAD_CAST "serviceInstance", BAD_CAST tmp); 1806 map *test = getMap (request, "storeExecuteResponse"); 1807 bool hasStoredExecuteResponse = false; 1808 if (test != NULL && strcasecmp (test->value, "true") == 0) 1809 { 1810 xmlNewProp (n, BAD_CAST "statusLocation", BAD_CAST url); 1811 hasStoredExecuteResponse = true; 1812 } 1813 1814 nc = xmlNewNode (ns, BAD_CAST "Process"); 1815 map *tmp2 = getMap (serv->content, "processVersion"); 1816 if (tmp2 != NULL) 1817 xmlNewNsProp (nc, ns, BAD_CAST "processVersion", BAD_CAST tmp2->value); 1818 1819 printDescription (nc, ns_ows, serv->name, serv->content); 1820 1821 xmlAddChild (n, nc); 1822 1823 nc = xmlNewNode (ns, BAD_CAST "Status"); 1517 1824 const struct tm *tm; 1518 1825 size_t len; … … 1520 1827 char *tmp1; 1521 1828 map *tmpStatus; 1522 1523 now = time ( NULL);1524 tm = localtime ( &now);1525 1526 tmp1 = (char *)malloc((TIME_SIZE+1)*sizeof(char));1527 1528 len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm);1529 1530 xmlNewProp (nc,BAD_CAST "creationTime",BAD_CAST tmp1);1829 1830 now = time (NULL); 1831 tm = localtime (&now); 1832 1833 tmp1 = (char *) malloc ((TIME_SIZE + 1) * sizeof (char)); 1834 1835 len = strftime (tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm); 1836 1837 xmlNewProp (nc, BAD_CAST "creationTime", BAD_CAST tmp1); 1531 1838 1532 1839 char sMsg[2048]; 1533 switch(status){ 1534 case SERVICE_SUCCEEDED: 1535 nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded"); 1536 sprintf(sMsg,_("Service \"%s\" run successfully."),serv->name); 1537 nc3=xmlNewText(BAD_CAST sMsg); 1538 xmlAddChild(nc1,nc3); 1539 break; 1540 case SERVICE_STARTED: 1541 nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted"); 1542 tmpStatus=getMapFromMaps(m,"lenv","status"); 1543 xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value); 1544 sprintf(sMsg,_("ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service."),serv->name); 1545 nc3=xmlNewText(BAD_CAST sMsg); 1546 xmlAddChild(nc1,nc3); 1547 break; 1548 case SERVICE_ACCEPTED: 1549 nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted"); 1550 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); 1551 nc3=xmlNewText(BAD_CAST sMsg); 1552 xmlAddChild(nc1,nc3); 1553 break; 1554 case SERVICE_FAILED: 1555 nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed"); 1556 map *errorMap; 1557 map *te; 1558 te=getMapFromMaps(m,"lenv","code"); 1559 if(te!=NULL) 1560 errorMap=createMap("code",te->value); 1561 else 1562 errorMap=createMap("code","NoApplicableCode"); 1563 te=getMapFromMaps(m,"lenv","message"); 1564 if(te!=NULL) 1565 addToMap(errorMap,"text",_ss(te->value)); 1566 else 1567 addToMap(errorMap,"text",_("No more information available")); 1568 nc3=createExceptionReportNode(m,errorMap,0); 1569 freeMap(&errorMap); 1570 free(errorMap); 1571 xmlAddChild(nc1,nc3); 1572 break; 1573 default : 1574 printf(_("error code not know : %i\n"),status); 1575 //exit(1); 1576 break; 1577 } 1578 xmlAddChild(nc,nc1); 1579 xmlAddChild(n,nc); 1580 free(tmp1); 1840 switch (status) 1841 { 1842 case SERVICE_SUCCEEDED: 1843 nc1 = xmlNewNode (ns, BAD_CAST "ProcessSucceeded"); 1844 sprintf (sMsg, _("Service \"%s\" run successfully."), serv->name); 1845 nc3 = xmlNewText (BAD_CAST sMsg); 1846 xmlAddChild (nc1, nc3); 1847 break; 1848 case SERVICE_STARTED: 1849 nc1 = xmlNewNode (ns, BAD_CAST "ProcessStarted"); 1850 tmpStatus = getMapFromMaps (m, "lenv", "status"); 1851 xmlNewProp (nc1, BAD_CAST "percentCompleted", 1852 BAD_CAST tmpStatus->value); 1853 sprintf (sMsg, 1854 _ 1855 ("ZOO Service \"%s\" is currently running. Please, reload this document to get the up-to-date status of the Service."), 1856 serv->name); 1857 nc3 = xmlNewText (BAD_CAST sMsg); 1858 xmlAddChild (nc1, nc3); 1859 break; 1860 case SERVICE_ACCEPTED: 1861 nc1 = xmlNewNode (ns, BAD_CAST "ProcessAccepted"); 1862 sprintf (sMsg, 1863 _ 1864 ("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."), 1865 serv->name); 1866 nc3 = xmlNewText (BAD_CAST sMsg); 1867 xmlAddChild (nc1, nc3); 1868 break; 1869 case SERVICE_FAILED: 1870 nc1 = xmlNewNode (ns, BAD_CAST "ProcessFailed"); 1871 map *errorMap; 1872 map *te; 1873 te = getMapFromMaps (m, "lenv", "code"); 1874 if (te != NULL) 1875 errorMap = createMap ("code", te->value); 1876 else 1877 errorMap = createMap ("code", "NoApplicableCode"); 1878 te = getMapFromMaps (m, "lenv", "message"); 1879 if (te != NULL) 1880 addToMap (errorMap, "text", _ss (te->value)); 1881 else 1882 addToMap (errorMap, "text", _("No more information available")); 1883 nc3 = createExceptionReportNode (m, errorMap, 0); 1884 freeMap (&errorMap); 1885 free (errorMap); 1886 xmlAddChild (nc1, nc3); 1887 break; 1888 default: 1889 printf (_("error code not know : %i\n"), status); 1890 //exit(1); 1891 break; 1892 } 1893 xmlAddChild (nc, nc1); 1894 xmlAddChild (n, nc); 1895 free (tmp1); 1581 1896 1582 1897 #ifdef DEBUG 1583 fprintf(stderr,"printProcessResponse 1 161\n"); 1584 #endif 1585 1586 map* lineage=getMap(request,"lineage"); 1587 if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){ 1588 nc = xmlNewNode(ns, BAD_CAST "DataInputs"); 1589 maps* mcursor=inputs; 1590 elements* scursor=NULL; 1591 while(mcursor!=NULL /*&& scursor!=NULL*/){ 1592 scursor=getElements(serv->inputs,mcursor->name); 1593 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input"); 1594 mcursor=mcursor->next; 1595 } 1596 xmlAddChild(n,nc); 1597 1898 fprintf (stderr, "printProcessResponse 1 161\n"); 1899 #endif 1900 1901 map *lineage = getMap (request, "lineage"); 1902 if (lineage != NULL && strcasecmp (lineage->value, "true") == 0) 1903 { 1904 nc = xmlNewNode (ns, BAD_CAST "DataInputs"); 1905 maps *mcursor = inputs; 1906 elements *scursor = NULL; 1907 while (mcursor != NULL /*&& scursor!=NULL */ ) 1908 { 1909 scursor = getElements (serv->inputs, mcursor->name); 1910 printIOType (doc, nc, ns, ns_ows, ns_xlink, scursor, mcursor, 1911 "Input"); 1912 mcursor = mcursor->next; 1913 } 1914 xmlAddChild (n, nc); 1915 1598 1916 #ifdef DEBUG 1599 fprintf(stderr,"printProcessResponse 1 177\n"); 1600 #endif 1601 1602 nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions"); 1603 mcursor=outputs; 1604 scursor=NULL; 1605 while(mcursor!=NULL){ 1606 scursor=getElements(serv->outputs,mcursor->name); 1607 printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output"); 1608 mcursor=mcursor->next; 1609 } 1610 xmlAddChild(n,nc); 1611 } 1917 fprintf (stderr, "printProcessResponse 1 177\n"); 1918 #endif 1919 1920 nc = xmlNewNode (ns, BAD_CAST "OutputDefinitions"); 1921 mcursor = outputs; 1922 scursor = NULL; 1923 while (mcursor != NULL) 1924 { 1925 scursor = getElements (serv->outputs, mcursor->name); 1926 printOutputDefinitions1 (doc, nc, ns, ns_ows, scursor, mcursor, 1927 "Output"); 1928 mcursor = mcursor->next; 1929 } 1930 xmlAddChild (n, nc); 1931 } 1612 1932 #ifdef DEBUG 1613 fprintf (stderr,"printProcessResponse 1 190\n");1933 fprintf (stderr, "printProcessResponse 1 190\n"); 1614 1934 #endif 1615 1935 … … 1617 1937 * Display the process output only when requested ! 1618 1938 */ 1619 if(status==SERVICE_SUCCEEDED){ 1620 nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs"); 1621 maps* mcursor=outputs; 1622 elements* scursor=serv->outputs; 1623 map* testResponse=getMap(request,"RawDataOutput"); 1624 if(testResponse==NULL) 1625 testResponse=getMap(request,"ResponseDocument"); 1626 while(mcursor!=NULL){ 1627 map* tmp0=getMap(mcursor->content,"inRequest"); 1628 scursor=getElements(serv->outputs,mcursor->name); 1629 if(scursor!=NULL){ 1630 if(testResponse==NULL || tmp0==NULL) 1631 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); 1632 else 1633 if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0) 1634 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); 1635 }else 1636 /** 1939 if (status == SERVICE_SUCCEEDED) 1940 { 1941 nc = xmlNewNode (ns, BAD_CAST "ProcessOutputs"); 1942 maps *mcursor = outputs; 1943 elements *scursor = serv->outputs; 1944 map *testResponse = getMap (request, "RawDataOutput"); 1945 if (testResponse == NULL) 1946 testResponse = getMap (request, "ResponseDocument"); 1947 while (mcursor != NULL) 1948 { 1949 map *tmp0 = getMap (mcursor->content, "inRequest"); 1950 scursor = getElements (serv->outputs, mcursor->name); 1951 if (scursor != NULL) 1952 { 1953 if (testResponse == NULL || tmp0 == NULL) 1954 printIOType (doc, nc, ns, ns_ows, ns_xlink, scursor, mcursor, 1955 "Output"); 1956 else if (tmp0 != NULL && strncmp (tmp0->value, "true", 4) == 0) 1957 printIOType (doc, nc, ns, ns_ows, ns_xlink, scursor, mcursor, 1958 "Output"); 1959 } 1960 else 1961 /** 1637 1962 * In case there was no definition found in the ZCFG file but 1638 1963 * present in the service code 1639 1964 */ 1640 printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output"); 1641 mcursor=mcursor->next; 1642 } 1643 xmlAddChild(n,nc); 1644 } 1965 printIOType (doc, nc, ns, ns_ows, ns_xlink, scursor, mcursor, 1966 "Output"); 1967 mcursor = mcursor->next; 1968 } 1969 xmlAddChild (n, nc); 1970 } 1645 1971 1646 1972 #ifdef DEBUG 1647 fprintf(stderr,"printProcessResponse 1 202\n"); 1648 #endif 1649 nr=soapEnvelope(m,n); 1650 xmlDocSetRootElement(doc, nr); 1651 1652 if(hasStoredExecuteResponse==true){ 1653 /* We need to write the ExecuteResponse Document somewhere */ 1654 FILE* output=fopen(stored_path,"w"); 1655 if(output==NULL){ 1656 /* If the file cannot be created return an ExceptionReport */ 1657 char tmpMsg[1024]; 1658 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the ExecuteResponse."),stored_path); 1659 map * errormap = createMap("text",tmpMsg); 1660 addToMap(errormap,"code", "InternalError"); 1661 printExceptionReportResponse(m,errormap); 1662 freeMap(&errormap); 1663 free(errormap); 1664 xmlFreeDoc(doc); 1665 xmlCleanupParser(); 1666 zooXmlCleanupNs(); 1667 return; 1668 } 1669 xmlChar *xmlbuff; 1670 int buffersize; 1671 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1); 1672 fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output); 1673 xmlFree(xmlbuff); 1674 fclose(output); 1675 } 1676 printDocument(m,doc,pid); 1677 1678 xmlCleanupParser(); 1679 zooXmlCleanupNs(); 1680 } 1681 1682 1683 void printDocument(maps* m, xmlDocPtr doc,int pid){ 1684 char *encoding=getEncoding(m); 1685 if(pid==getpid()){ 1686 printHeaders(m); 1687 printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); 1688 } 1689 fflush(stdout); 1973 fprintf (stderr, "printProcessResponse 1 202\n"); 1974 #endif 1975 nr = soapEnvelope (m, n); 1976 xmlDocSetRootElement (doc, nr); 1977 1978 if (hasStoredExecuteResponse == true) 1979 { 1980 /* We need to write the ExecuteResponse Document somewhere */ 1981 FILE *output = fopen (stored_path, "w"); 1982 if (output == NULL) 1983 { 1984 /* If the file cannot be created return an ExceptionReport */ 1985 char tmpMsg[1024]; 1986 sprintf (tmpMsg, 1987 _ 1988 ("Unable to create the file : \"%s\" for storing the ExecuteResponse."), 1989 stored_path); 1990 map *errormap = createMap ("text", tmpMsg); 1991 addToMap (errormap, "code", "InternalError"); 1992 printExceptionReportResponse (m, errormap); 1993 freeMap (&errormap); 1994 free (errormap); 1995 xmlFreeDoc (doc); 1996 xmlCleanupParser (); 1997 zooXmlCleanupNs (); 1998 return; 1999 } 2000 xmlChar *xmlbuff; 2001 int buffersize; 2002 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, "UTF-8", 1); 2003 fwrite (xmlbuff, 1, xmlStrlen (xmlbuff) * sizeof (char), output); 2004 xmlFree (xmlbuff); 2005 fclose (output); 2006 } 2007 printDocument (m, doc, pid); 2008 2009 xmlCleanupParser (); 2010 zooXmlCleanupNs (); 2011 } 2012 2013 2014 void 2015 printDocument (maps * m, xmlDocPtr doc, int pid) 2016 { 2017 char *encoding = getEncoding (m); 2018 if (pid == getpid ()) 2019 { 2020 printHeaders (m); 2021 printf ("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n", 2022 encoding); 2023 } 2024 fflush (stdout); 1690 2025 xmlChar *xmlbuff; 1691 2026 int buffersize; … … 1694 2029 * for demonstration purposes. 1695 2030 */ 1696 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1);1697 printf ("%s",xmlbuff);1698 fflush (stdout);2031 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1); 2032 printf ("%s", xmlbuff); 2033 fflush (stdout); 1699 2034 /* 1700 2035 * Free associated memory. 1701 2036 */ 1702 xmlFree(xmlbuff); 1703 xmlFreeDoc(doc); 1704 xmlCleanupParser(); 1705 zooXmlCleanupNs(); 1706 } 1707 1708 void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){ 2037 xmlFree (xmlbuff); 2038 xmlFreeDoc (doc); 2039 xmlCleanupParser (); 2040 zooXmlCleanupNs (); 2041 } 2042 2043 void 2044 printOutputDefinitions1 (xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_wps, 2045 xmlNsPtr ns_ows, elements * e, maps * m, 2046 const char *type) 2047 { 1709 2048 xmlNodePtr nc1; 1710 nc1=xmlNewNode(ns_wps, BAD_CAST type); 1711 map *tmp=NULL; 1712 if(e!=NULL && e->defaults!=NULL) 1713 tmp=e->defaults->content; 1714 else{ 1715 /* 1716 dumpElements(e); 1717 */ 1718 return; 1719 } 1720 while(tmp!=NULL){ 1721 if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0 1722 || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0 1723 || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0 1724 || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0) 1725 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); 1726 tmp=tmp->next; 1727 } 1728 tmp=getMap(e->defaults->content,"asReference"); 1729 if(tmp==NULL) 1730 xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); 1731 1732 tmp=e->content; 1733 1734 printDescription(nc1,ns_ows,m->name,e->content); 1735 1736 xmlAddChild(nc,nc1); 1737 1738 } 1739 1740 void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,const char* type){ 2049 nc1 = xmlNewNode (ns_wps, BAD_CAST type); 2050 map *tmp = NULL; 2051 if (e != NULL && e->defaults != NULL) 2052 tmp = e->defaults->content; 2053 else 2054 { 2055 /* 2056 dumpElements(e); 2057 */ 2058 return; 2059 } 2060 while (tmp != NULL) 2061 { 2062 if (strncasecmp (tmp->name, "MIMETYPE", strlen (tmp->name)) == 0 2063 || strncasecmp (tmp->name, "ENCODING", strlen (tmp->name)) == 0 2064 || strncasecmp (tmp->name, "SCHEMA", strlen (tmp->name)) == 0 2065 || strncasecmp (tmp->name, "UOM", strlen (tmp->name)) == 0) 2066 xmlNewProp (nc1, BAD_CAST tmp->name, BAD_CAST tmp->value); 2067 tmp = tmp->next; 2068 } 2069 tmp = getMap (e->defaults->content, "asReference"); 2070 if (tmp == NULL) 2071 xmlNewProp (nc1, BAD_CAST "asReference", BAD_CAST "false"); 2072 2073 tmp = e->content; 2074 2075 printDescription (nc1, ns_ows, m->name, e->content); 2076 2077 xmlAddChild (nc, nc1); 2078 2079 } 2080 2081 void 2082 printOutputDefinitions (xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_wps, 2083 xmlNsPtr ns_ows, elements * e, map * m, 2084 const char *type) 2085 { 1741 2086 xmlNodePtr nc1; 1742 nc1=xmlNewNode(ns_wps, BAD_CAST type); 1743 map *tmp=NULL; 1744 if(e!=NULL && e->defaults!=NULL) 1745 tmp=e->defaults->content; 1746 else{ 1747 /* 1748 dumpElements(e); 1749 */ 1750 return; 1751 } 1752 while(tmp!=NULL){ 1753 xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value); 1754 tmp=tmp->next; 1755 } 1756 tmp=getMap(e->defaults->content,"asReference"); 1757 if(tmp==NULL) 1758 xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false"); 1759 1760 tmp=e->content; 1761 1762 printDescription(nc1,ns_ows,m->name,e->content); 1763 1764 xmlAddChild(nc,nc1); 1765 1766 } 1767 1768 void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){ 1769 xmlNodePtr nc1,nc2,nc3; 1770 nc1=xmlNewNode(ns_wps, BAD_CAST type); 1771 map *tmp=NULL; 1772 if(e!=NULL) 1773 tmp=e->content; 2087 nc1 = xmlNewNode (ns_wps, BAD_CAST type); 2088 map *tmp = NULL; 2089 if (e != NULL && e->defaults != NULL) 2090 tmp = e->defaults->content; 1774 2091 else 1775 tmp=m->content; 2092 { 2093 /* 2094 dumpElements(e); 2095 */ 2096 return; 2097 } 2098 while (tmp != NULL) 2099 { 2100 xmlNewProp (nc1, BAD_CAST tmp->name, BAD_CAST tmp->value); 2101 tmp = tmp->next; 2102 } 2103 tmp = getMap (e->defaults->content, "asReference"); 2104 if (tmp == NULL) 2105 xmlNewProp (nc1, BAD_CAST "asReference", BAD_CAST "false"); 2106 2107 tmp = e->content; 2108 2109 printDescription (nc1, ns_ows, m->name, e->content); 2110 2111 xmlAddChild (nc, nc1); 2112 2113 } 2114 2115 void 2116 printIOType (xmlDocPtr doc, xmlNodePtr nc, xmlNsPtr ns_wps, xmlNsPtr ns_ows, 2117 xmlNsPtr ns_xlink, elements * e, maps * m, const char *type) 2118 { 2119 xmlNodePtr nc1, nc2, nc3; 2120 nc1 = xmlNewNode (ns_wps, BAD_CAST type); 2121 map *tmp = NULL; 2122 if (e != NULL) 2123 tmp = e->content; 2124 else 2125 tmp = m->content; 1776 2126 #ifdef DEBUG 1777 dumpMap (tmp);1778 dumpElements (e);1779 #endif 1780 nc2 =xmlNewNode(ns_ows, BAD_CAST "Identifier");1781 if (e!=NULL)1782 nc3 =xmlNewText(BAD_CAST e->name);2127 dumpMap (tmp); 2128 dumpElements (e); 2129 #endif 2130 nc2 = xmlNewNode (ns_ows, BAD_CAST "Identifier"); 2131 if (e != NULL) 2132 nc3 = xmlNewText (BAD_CAST e->name); 1783 2133 else 1784 nc3 =xmlNewText(BAD_CAST m->name);1785 xmlAddChild (nc2,nc3);1786 xmlAddChild (nc1,nc2);1787 xmlAddChild (nc,nc1);1788 if (e!=NULL)1789 tmp =getMap(e->content,"Title");2134 nc3 = xmlNewText (BAD_CAST m->name); 2135 xmlAddChild (nc2, nc3); 2136 xmlAddChild (nc1, nc2); 2137 xmlAddChild (nc, nc1); 2138 if (e != NULL) 2139 tmp = getMap (e->content, "Title"); 1790 2140 else 1791 tmp=getMap(m->content,"Title"); 1792 1793 if(tmp!=NULL){ 1794 nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); 1795 nc3=xmlNewText(BAD_CAST _ss(tmp->value)); 1796 xmlAddChild(nc2,nc3); 1797 xmlAddChild(nc1,nc2); 1798 } 1799 1800 if(e!=NULL) 1801 tmp=getMap(e->content,"Abstract"); 2141 tmp = getMap (m->content, "Title"); 2142 2143 if (tmp != NULL) 2144 { 2145 nc2 = xmlNewNode (ns_ows, BAD_CAST tmp->name); 2146 nc3 = xmlNewText (BAD_CAST _ss (tmp->value)); 2147 xmlAddChild (nc2, nc3); 2148 xmlAddChild (nc1, nc2); 2149 } 2150 2151 if (e != NULL) 2152 tmp = getMap (e->content, "Abstract"); 1802 2153 else 1803 tmp=getMap(m->content,"Abstract"); 1804 if(tmp!=NULL){ 1805 nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name); 1806 nc3=xmlNewText(BAD_CAST _ss(tmp->value)); 1807 xmlAddChild(nc2,nc3); 1808 xmlAddChild(nc1,nc2); 1809 xmlAddChild(nc,nc1); 1810 } 2154 tmp = getMap (m->content, "Abstract"); 2155 if (tmp != NULL) 2156 { 2157 nc2 = xmlNewNode (ns_ows, BAD_CAST tmp->name); 2158 nc3 = xmlNewText (BAD_CAST _ss (tmp->value)); 2159 xmlAddChild (nc2, nc3); 2160 xmlAddChild (nc1, nc2); 2161 xmlAddChild (nc, nc1); 2162 } 1811 2163 1812 2164 /** … … 1814 2166 */ 1815 2167 #ifdef DEBUG 1816 fprintf(stderr,"FORMAT %s %s\n",e->format,e->format); 1817 #endif 1818 map *tmpMap=getMap(m->content,"Reference"); 1819 if(tmpMap==NULL){ 1820 nc2=xmlNewNode(ns_wps, BAD_CAST "Data"); 1821 if(e!=NULL){ 1822 if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0) 1823 nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData"); 2168 fprintf (stderr, "FORMAT %s %s\n", e->format, e->format); 2169 #endif 2170 map *tmpMap = getMap (m->content, "Reference"); 2171 if (tmpMap == NULL) 2172 { 2173 nc2 = xmlNewNode (ns_wps, BAD_CAST "Data"); 2174 if (e != NULL) 2175 { 2176 if (strncasecmp (e->format, "LiteralOutput", strlen (e->format)) == 2177 0) 2178 nc3 = xmlNewNode (ns_wps, BAD_CAST "LiteralData"); 2179 else 2180 if (strncasecmp (e->format, "ComplexOutput", strlen (e->format)) 2181 == 0) 2182 nc3 = xmlNewNode (ns_wps, BAD_CAST "ComplexData"); 2183 else 2184 if (strncasecmp 2185 (e->format, "BoundingBoxOutput", strlen (e->format)) == 0) 2186 nc3 = xmlNewNode (ns_wps, BAD_CAST "BoundingBoxData"); 2187 else 2188 nc3 = xmlNewNode (ns_wps, BAD_CAST e->format); 2189 } 1824 2190 else 1825 if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0) 1826 nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData"); 1827 else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0) 1828 nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData"); 1829 else 1830 nc3=xmlNewNode(ns_wps, BAD_CAST e->format); 1831 } 1832 else{ 1833 map* tmpV=getMapFromMaps(m,"format","value"); 1834 if(tmpV!=NULL) 1835 nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value); 2191 { 2192 map *tmpV = getMapFromMaps (m, "format", "value"); 2193 if (tmpV != NULL) 2194 nc3 = xmlNewNode (ns_wps, BAD_CAST tmpV->value); 2195 else 2196 nc3 = xmlNewNode (ns_wps, BAD_CAST "LitteralData"); 2197 } 2198 tmp = m->content; 2199 #ifdef USE_MS 2200 map *testMap = getMap (tmp, "requestedMimeType"); 2201 #endif 2202 while (tmp != NULL) 2203 { 2204 if (strcasecmp (tmp->name, "mimeType") == 0 || 2205 strcasecmp (tmp->name, "encoding") == 0 || 2206 strcasecmp (tmp->name, "schema") == 0 || 2207 strcasecmp (tmp->name, "datatype") == 0 || 2208 strcasecmp (tmp->name, "uom") == 0) 2209 { 2210 #ifdef USE_MS 2211 if (testMap == NULL 2212 || (testMap != NULL 2213 && strncasecmp (testMap->value, "text/xml", 8) == 0)) 2214 { 2215 #endif 2216 xmlNewProp (nc3, BAD_CAST tmp->name, BAD_CAST tmp->value); 2217 #ifdef USE_MS 2218 } 2219 else if (strcasecmp (tmp->name, "mimeType") == 0) 2220 { 2221 if (testMap != NULL) 2222 xmlNewProp (nc3, BAD_CAST tmp->name, 2223 BAD_CAST testMap->value); 2224 else 2225 xmlNewProp (nc3, BAD_CAST tmp->name, BAD_CAST tmp->value); 2226 } 2227 #endif 2228 } 2229 tmp = tmp->next; 2230 xmlAddChild (nc2, nc3); 2231 } 2232 if (e != NULL && e->format != NULL 2233 && strcasecmp (e->format, "BoundingBoxData") == 0) 2234 { 2235 map *bb = getMap (m->content, "value"); 2236 if (bb != NULL) 2237 { 2238 map *tmpRes = parseBoundingBox (bb->value); 2239 printBoundingBox (ns_ows, nc3, tmpRes); 2240 freeMap (&tmpRes); 2241 free (tmpRes); 2242 } 2243 } 1836 2244 else 1837 nc3=xmlNewNode(ns_wps, BAD_CAST "LitteralData"); 1838 } 1839 tmp=m->content; 1840 #ifdef USE_MS 1841 map* testMap=getMap(tmp,"requestedMimeType"); 1842 #endif 1843 while(tmp!=NULL){ 1844 if(strcasecmp(tmp->name,"mimeType")==0 || 1845 strcasecmp(tmp->name,"encoding")==0 || 1846 strcasecmp(tmp->name,"schema")==0 || 1847 strcasecmp(tmp->name,"datatype")==0 || 1848 strcasecmp(tmp->name,"uom")==0){ 1849 #ifdef USE_MS 1850 if(testMap==NULL || (testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)==0)){ 1851 #endif 1852 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 1853 #ifdef USE_MS 1854 } 1855 else 1856 if(strcasecmp(tmp->name,"mimeType")==0){ 1857 if(testMap!=NULL) 1858 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); 1859 else 1860 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 1861 } 1862 #endif 1863 } 1864 tmp=tmp->next; 1865 xmlAddChild(nc2,nc3); 1866 } 1867 if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ 1868 map* bb=getMap(m->content,"value"); 1869 if(bb!=NULL){ 1870 map* tmpRes=parseBoundingBox(bb->value); 1871 printBoundingBox(ns_ows,nc3,tmpRes); 1872 freeMap(&tmpRes); 1873 free(tmpRes); 1874 } 1875 }else{ 1876 if(e!=NULL) 1877 tmp=getMap(e->defaults->content,"mimeType"); 1878 else 1879 tmp=NULL; 2245 { 2246 if (e != NULL) 2247 tmp = getMap (e->defaults->content, "mimeType"); 2248 else 2249 tmp = NULL; 1880 2250 #ifdef USE_MS 1881 2251 /** … … 1884 2254 * stored in the Reference map value. 1885 2255 */ 1886 map* testMap=getMap(m->content,"requestedMimeType"); 1887 if(testMap!=NULL){ 1888 HINTERNET hInternet; 1889 char* tmpValue; 1890 size_t dwRead; 1891 hInternet=InternetOpen( 2256 map *testMap = getMap (m->content, "requestedMimeType"); 2257 if (testMap != NULL) 2258 { 2259 HINTERNET hInternet; 2260 char *tmpValue; 2261 size_t dwRead; 2262 hInternet = InternetOpen ( 1892 2263 #ifndef WIN32 1893 (LPCTSTR) 1894 #endif 1895 "ZooWPSClient\0", 1896 INTERNET_OPEN_TYPE_PRECONFIG, 1897 NULL,NULL, 0); 1898 testMap=getMap(m->content,"Reference"); 1899 loadRemoteFile(&m,&m->content,&hInternet,testMap->value); 1900 processDownloads(&hInternet); 1901 tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char)); 1902 InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead); 1903 InternetCloseHandle(&hInternet); 1904 } 1905 #endif 1906 map* tmp1=getMap(m->content,"encoding"); 1907 map* tmp2=getMap(m->content,"mimeType"); 1908 map* tmp3=getMap(m->content,"value"); 1909 int hasValue=1; 1910 if(tmp3==NULL){ 1911 tmp3=createMap("value",""); 1912 hasValue=-1; 1913 } 1914 if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0) 1915 || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0 || 1916 (strncmp(tmp2->value,"application/",12)==0 && 1917 strncmp(tmp2->value,"application/json",16)!=0&& 1918 strncmp(tmp2->value,"application/x-javascript",24)!=0&& 1919 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0)) 1920 )) { 1921 map* rs=getMap(m->content,"size"); 1922 bool isSized=true; 1923 if(rs==NULL){ 1924 char tmp1[1024]; 1925 sprintf(tmp1,"%u",strlen(tmp3->value)); 1926 rs=createMap("size",tmp1); 1927 isSized=false; 1928 } 1929 1930 xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value)))); 1931 if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) 1932 xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64"); 1933 if(!isSized){ 1934 freeMap(&rs); 1935 free(rs); 1936 } 1937 } 1938 else if(tmp2!=NULL){ 1939 if(strncmp(tmp2->value,"text/js",7)==0 || 1940 strncmp(tmp2->value,"application/json",16)==0) 1941 xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value))); 1942 else{ 1943 if(strncmp(tmp2->value,"text/xml",8)==0 || 1944 strncmp(tmp2->value,"application/vnd.google-earth.kml",32)==0){ 1945 int li=zooXmlAddDoc(tmp3->value); 1946 xmlDocPtr doc = iDocs[li]; 1947 xmlNodePtr ir = xmlDocGetRootElement(doc); 1948 xmlAddChild(nc3,ir); 1949 } 1950 else 1951 xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value)); 1952 } 1953 xmlAddChild(nc2,nc3); 1954 } 1955 else{ 1956 xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value)); 1957 } 1958 if(hasValue<0){ 1959 freeMap(&tmp3); 1960 free(tmp3); 1961 } 1962 } 1963 } 1964 else{ 1965 tmpMap=getMap(m->content,"Reference"); 1966 nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference"); 1967 if(strcasecmp(type,"Output")==0) 1968 xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value); 1969 else 1970 xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value); 1971 tmp=m->content; 2264 (LPCTSTR) 2265 #endif 2266 "ZooWPSClient\0", 2267 INTERNET_OPEN_TYPE_PRECONFIG, 2268 NULL, NULL, 0); 2269 testMap = getMap (m->content, "Reference"); 2270 loadRemoteFile (&m, &m->content, &hInternet, testMap->value); 2271 processDownloads (&hInternet); 2272 tmpValue = 2273 (char *) malloc ((hInternet.ihandle[0].nDataLen + 1) * 2274 sizeof (char)); 2275 InternetReadFile (hInternet.ihandle[0], (LPVOID) tmpValue, 2276 hInternet.ihandle[0].nDataLen, &dwRead); 2277 InternetCloseHandle (&hInternet); 2278 } 2279 #endif 2280 map *tmp1 = getMap (m->content, "encoding"); 2281 map *tmp2 = getMap (m->content, "mimeType"); 2282 map *tmp3 = getMap (m->content, "value"); 2283 int hasValue = 1; 2284 if (tmp3 == NULL) 2285 { 2286 tmp3 = createMap ("value", ""); 2287 hasValue = -1; 2288 } 2289 if ((tmp1 != NULL && strncmp (tmp1->value, "base64", 6) == 0) 2290 || (tmp2 != NULL && (strncmp (tmp2->value, "image/", 6) == 0 || 2291 (strncmp (tmp2->value, "application/", 12) 2292 == 0 2293 && strncmp (tmp2->value, 2294 "application/json", 16) != 0 2295 && strncmp (tmp2->value, 2296 "application/x-javascript", 2297 24) != 0 2298 && strncmp (tmp2->value, 2299 "application/vnd.google-earth.kml", 2300 32) != 0)))) 2301 { 2302 map *rs = getMap (m->content, "size"); 2303 bool isSized = true; 2304 if (rs == NULL) 2305 { 2306 char tmp1[1024]; 2307 sprintf (tmp1, "%u", strlen (tmp3->value)); 2308 rs = createMap ("size", tmp1); 2309 isSized = false; 2310 } 2311 2312 xmlAddChild (nc3, 2313 xmlNewText (BAD_CAST 2314 base64 (tmp3->value, 2315 atoi (rs->value)))); 2316 if (tmp1 == NULL 2317 || (tmp1 != NULL 2318 && strncmp (tmp1->value, "base64", 6) != 0)) 2319 xmlNewProp (nc3, BAD_CAST "encoding", BAD_CAST "base64"); 2320 if (!isSized) 2321 { 2322 freeMap (&rs); 2323 free (rs); 2324 } 2325 } 2326 else if (tmp2 != NULL) 2327 { 2328 if (strncmp (tmp2->value, "text/js", 7) == 0 || 2329 strncmp (tmp2->value, "application/json", 16) == 0) 2330 xmlAddChild (nc3, 2331 xmlNewCDataBlock (doc, BAD_CAST tmp3->value, 2332 strlen (tmp3->value))); 2333 else 2334 { 2335 if (strncmp (tmp2->value, "text/xml", 8) == 0 || 2336 strncmp (tmp2->value, 2337 "application/vnd.google-earth.kml", 32) == 0) 2338 { 2339 int li = zooXmlAddDoc (tmp3->value); 2340 xmlDocPtr doc = iDocs[li]; 2341 xmlNodePtr ir = xmlDocGetRootElement (doc); 2342 xmlAddChild (nc3, ir); 2343 } 2344 else 2345 xmlAddChild (nc3, xmlNewText (BAD_CAST tmp3->value)); 2346 } 2347 xmlAddChild (nc2, nc3); 2348 } 2349 else 2350 { 2351 xmlAddChild (nc3, xmlNewText (BAD_CAST tmp3->value)); 2352 } 2353 if (hasValue < 0) 2354 { 2355 freeMap (&tmp3); 2356 free (tmp3); 2357 } 2358 } 2359 } 2360 else 2361 { 2362 tmpMap = getMap (m->content, "Reference"); 2363 nc3 = nc2 = xmlNewNode (ns_wps, BAD_CAST "Reference"); 2364 if (strcasecmp (type, "Output") == 0) 2365 xmlNewProp (nc3, BAD_CAST "href", BAD_CAST tmpMap->value); 2366 else 2367 xmlNewNsProp (nc3, ns_xlink, BAD_CAST "href", BAD_CAST tmpMap->value); 2368 tmp = m->content; 1972 2369 #ifdef USE_MS 1973 map* testMap=getMap(tmp,"requestedMimeType"); 1974 #endif 1975 while(tmp!=NULL){ 1976 if(strcasecmp(tmp->name,"mimeType")==0 || 1977 strcasecmp(tmp->name,"encoding")==0 || 1978 strcasecmp(tmp->name,"schema")==0 || 1979 strcasecmp(tmp->name,"datatype")==0 || 1980 strcasecmp(tmp->name,"uom")==0){ 2370 map *testMap = getMap (tmp, "requestedMimeType"); 2371 #endif 2372 while (tmp != NULL) 2373 { 2374 if (strcasecmp (tmp->name, "mimeType") == 0 || 2375 strcasecmp (tmp->name, "encoding") == 0 || 2376 strcasecmp (tmp->name, "schema") == 0 || 2377 strcasecmp (tmp->name, "datatype") == 0 || 2378 strcasecmp (tmp->name, "uom") == 0) 2379 { 1981 2380 #ifdef USE_MS 1982 if(testMap!=NULL && strncasecmp(testMap->value,"text/xml",8)!=0){ 1983 if(strcasecmp(tmp->name,"mimeType")==0) 1984 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST testMap->value); 1985 } 1986 else 1987 #endif 1988 if(strcasecmp(tmp->name,"datatype")==0) 1989 xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain"); 1990 else 1991 xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value); 1992 } 1993 tmp=tmp->next; 1994 xmlAddChild(nc2,nc3); 1995 } 1996 } 1997 xmlAddChild(nc1,nc2); 1998 xmlAddChild(nc,nc1); 1999 2000 } 2001 2002 void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){ 2003 xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier"); 2004 2005 xmlAddChild(nc2,xmlNewText(BAD_CAST identifier)); 2006 xmlAddChild(root,nc2); 2007 map* tmp=amap; 2381 if (testMap != NULL 2382 && strncasecmp (testMap->value, "text/xml", 8) != 0) 2383 { 2384 if (strcasecmp (tmp->name, "mimeType") == 0) 2385 xmlNewProp (nc3, BAD_CAST tmp->name, 2386 BAD_CAST testMap->value); 2387 } 2388 else 2389 #endif 2390 if (strcasecmp (tmp->name, "datatype") == 0) 2391 xmlNewProp (nc3, BAD_CAST "mimeType", BAD_CAST "text/plain"); 2392 else 2393 xmlNewProp (nc3, BAD_CAST tmp->name, BAD_CAST tmp->value); 2394 } 2395 tmp = tmp->next; 2396 xmlAddChild (nc2, nc3); 2397 } 2398 } 2399 xmlAddChild (nc1, nc2); 2400 xmlAddChild (nc, nc1); 2401 2402 } 2403 2404 void 2405 printDescription (xmlNodePtr root, xmlNsPtr ns_ows, const char *identifier, 2406 map * amap) 2407 { 2408 xmlNodePtr nc2 = xmlNewNode (ns_ows, BAD_CAST "Identifier"); 2409 2410 xmlAddChild (nc2, xmlNewText (BAD_CAST identifier)); 2411 xmlAddChild (root, nc2); 2412 map *tmp = amap; 2008 2413 const char *tmp2[2]; 2009 tmp2[0]="Title"; 2010 tmp2[1]="Abstract"; 2011 int j=0; 2012 for(j=0;j<2;j++){ 2013 map* tmp1=getMap(tmp,tmp2[j]); 2014 if(tmp1!=NULL){ 2015 nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]); 2016 xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value))); 2017 xmlAddChild(root,nc2); 2018 } 2019 } 2020 } 2021 2022 char* getEncoding(maps* m){ 2023 if(m!=NULL){ 2024 map* tmp=getMap(m->content,"encoding"); 2025 if(tmp!=NULL){ 2026 return tmp->value; 2027 } 2028 else 2029 return (char*)"UTF-8"; 2030 } 2414 tmp2[0] = "Title"; 2415 tmp2[1] = "Abstract"; 2416 int j = 0; 2417 for (j = 0; j < 2; j++) 2418 { 2419 map *tmp1 = getMap (tmp, tmp2[j]); 2420 if (tmp1 != NULL) 2421 { 2422 nc2 = xmlNewNode (ns_ows, BAD_CAST tmp2[j]); 2423 xmlAddChild (nc2, xmlNewText (BAD_CAST _ss (tmp1->value))); 2424 xmlAddChild (root, nc2); 2425 } 2426 } 2427 } 2428 2429 char * 2430 getEncoding (maps * m) 2431 { 2432 if (m != NULL) 2433 { 2434 map *tmp = getMap (m->content, "encoding"); 2435 if (tmp != NULL) 2436 { 2437 return tmp->value; 2438 } 2439 else 2440 return (char *) "UTF-8"; 2441 } 2031 2442 else 2032 return (char*)"UTF-8"; 2033 } 2034 2035 char* getVersion(maps* m){ 2036 if(m!=NULL){ 2037 map* tmp=getMap(m->content,"version"); 2038 if(tmp!=NULL){ 2039 return tmp->value; 2040 } 2041 else 2042 return (char*)"1.0.0"; 2043 } 2443 return (char *) "UTF-8"; 2444 } 2445 2446 char * 2447 getVersion (maps * m) 2448 { 2449 if (m != NULL) 2450 { 2451 map *tmp = getMap (m->content, "version"); 2452 if (tmp != NULL) 2453 { 2454 return tmp->value; 2455 } 2456 else 2457 return (char *) "1.0.0"; 2458 } 2044 2459 else 2045 return (char*)"1.0.0"; 2046 } 2047 2048 void printExceptionReportResponse(maps* m,map* s){ 2049 if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL) 2460 return (char *) "1.0.0"; 2461 } 2462 2463 void 2464 printExceptionReportResponse (maps * m, map * s) 2465 { 2466 if (getMapFromMaps (m, "lenv", "hasPrinted") != NULL) 2050 2467 return; 2051 2468 int buffersize; … … 2054 2471 xmlNodePtr n; 2055 2472 2056 zooXmlCleanupNs ();2057 doc = xmlNewDoc (BAD_CAST "1.0");2058 maps * tmpMap=getMaps(m,"main");2059 char *encoding =getEncoding(tmpMap);2473 zooXmlCleanupNs (); 2474 doc = xmlNewDoc (BAD_CAST "1.0"); 2475 maps *tmpMap = getMaps (m, "main"); 2476 char *encoding = getEncoding (tmpMap); 2060 2477 const char *exceptionCode; 2061 2062 map* tmp=getMap(s,"code"); 2063 if(tmp!=NULL){ 2064 if(strcmp(tmp->value,"OperationNotSupported")==0) 2065 exceptionCode="501 Not Implemented"; 2066 else 2067 if(strcmp(tmp->value,"MissingParameterValue")==0 || 2068 strcmp(tmp->value,"InvalidUpdateSequence")==0 || 2069 strcmp(tmp->value,"OptionNotSupported")==0 || 2070 strcmp(tmp->value,"VersionNegotiationFailed")==0 || 2071 strcmp(tmp->value,"InvalidParameterValue")==0) 2072 exceptionCode="400 Bad request"; 2478 2479 map *tmp = getMap (s, "code"); 2480 if (tmp != NULL) 2481 { 2482 if (strcmp (tmp->value, "OperationNotSupported") == 0) 2483 exceptionCode = "501 Not Implemented"; 2073 2484 else 2074 if(strcmp(tmp->value,"NoApplicableCode")==0) 2075 exceptionCode="501 Internal Server Error"; 2076 else 2077 exceptionCode="501 Internal Server Error"; 2078 } 2485 if (strcmp (tmp->value, "MissingParameterValue") == 0 || 2486 strcmp (tmp->value, "InvalidUpdateSequence") == 0 || 2487 strcmp (tmp->value, "OptionNotSupported") == 0 || 2488 strcmp (tmp->value, "VersionNegotiationFailed") == 0 || 2489 strcmp (tmp->value, "InvalidParameterValue") == 0) 2490 exceptionCode = "400 Bad request"; 2491 else if (strcmp (tmp->value, "NoApplicableCode") == 0) 2492 exceptionCode = "501 Internal Server Error"; 2493 else 2494 exceptionCode = "501 Internal Server Error"; 2495 } 2079 2496 else 2080 exceptionCode="501 Internal Server Error"; 2081 2082 if(m!=NULL){ 2083 map *tmpSid=getMapFromMaps(m,"lenv","sid"); 2084 if(tmpSid!=NULL){ 2085 if( getpid()==atoi(tmpSid->value) ){ 2086 printHeaders(m); 2087 printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); 2088 } 2089 } 2090 else{ 2091 printHeaders(m); 2092 printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); 2093 } 2094 }else{ 2095 printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode); 2096 } 2097 n=createExceptionReportNode(m,s,1); 2098 xmlDocSetRootElement(doc, n); 2099 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 2100 printf("%s",xmlbuff); 2101 fflush(stdout); 2102 xmlFreeDoc(doc); 2103 xmlFree(xmlbuff); 2104 xmlCleanupParser(); 2105 zooXmlCleanupNs(); 2106 if(m!=NULL) 2107 setMapInMaps(m,"lenv","hasPrinted","true"); 2108 } 2109 2110 xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){ 2111 2112 xmlNsPtr ns,ns_xsi; 2113 xmlNodePtr n,nc,nc1; 2114 2115 int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows"); 2116 ns=usedNs[nsid]; 2117 if(use_ns==1){ 2118 ns=NULL; 2119 } 2120 n = xmlNewNode(ns, BAD_CAST "ExceptionReport"); 2121 if(use_ns==1){ 2122 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",NULL); 2123 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 2124 ns_xsi=usedNs[xsiId]; 2125 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"); 2126 } 2127 2128 2129 addLangAttr(n,m); 2130 xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0"); 2131 2132 nc = xmlNewNode(ns, BAD_CAST "Exception"); 2133 2134 map* tmp=getMap(s,"code"); 2135 if(tmp!=NULL) 2136 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value); 2497 exceptionCode = "501 Internal Server Error"; 2498 2499 if (m != NULL) 2500 { 2501 map *tmpSid = getMapFromMaps (m, "lenv", "sid"); 2502 if (tmpSid != NULL) 2503 { 2504 if (getpid () == atoi (tmpSid->value)) 2505 { 2506 printHeaders (m); 2507 printf 2508 ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n", 2509 encoding, exceptionCode); 2510 } 2511 } 2512 else 2513 { 2514 printHeaders (m); 2515 printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n", 2516 encoding, exceptionCode); 2517 } 2518 } 2137 2519 else 2138 xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode"); 2139 2140 tmp=getMap(s,"locator"); 2141 if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0) 2142 xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value); 2143 2144 2145 tmp=getMap(s,"text"); 2146 nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText"); 2147 if(tmp!=NULL){ 2148 xmlNodeSetContent(nc1, BAD_CAST tmp->value); 2149 } 2150 else{ 2151 xmlNodeSetContent(nc1, BAD_CAST _("No debug message available")); 2152 } 2153 xmlAddChild(nc,nc1); 2154 xmlAddChild(n,nc); 2520 { 2521 printf ("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n", 2522 encoding, exceptionCode); 2523 } 2524 n = createExceptionReportNode (m, s, 1); 2525 xmlDocSetRootElement (doc, n); 2526 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1); 2527 printf ("%s", xmlbuff); 2528 fflush (stdout); 2529 xmlFreeDoc (doc); 2530 xmlFree (xmlbuff); 2531 xmlCleanupParser (); 2532 zooXmlCleanupNs (); 2533 if (m != NULL) 2534 setMapInMaps (m, "lenv", "hasPrinted", "true"); 2535 } 2536 2537 xmlNodePtr 2538 createExceptionReportNode (maps * m, map * s, int use_ns) 2539 { 2540 2541 xmlNsPtr ns, ns_xsi; 2542 xmlNodePtr n, nc, nc1; 2543 2544 int nsid = zooXmlAddNs (NULL, "http://www.opengis.net/ows", "ows"); 2545 ns = usedNs[nsid]; 2546 if (use_ns == 1) 2547 { 2548 ns = NULL; 2549 } 2550 n = xmlNewNode (ns, BAD_CAST "ExceptionReport"); 2551 if (use_ns == 1) 2552 { 2553 xmlNewNs (n, BAD_CAST "http://www.opengis.net/ows/1.1", NULL); 2554 int xsiId = 2555 zooXmlAddNs (n, "http://www.w3.org/2001/XMLSchema-instance", "xsi"); 2556 ns_xsi = usedNs[xsiId]; 2557 xmlNewNsProp (n, ns_xsi, BAD_CAST "schemaLocation", 2558 BAD_CAST 2559 "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"); 2560 } 2561 2562 2563 addLangAttr (n, m); 2564 xmlNewProp (n, BAD_CAST "version", BAD_CAST "1.1.0"); 2565 2566 nc = xmlNewNode (ns, BAD_CAST "Exception"); 2567 2568 map *tmp = getMap (s, "code"); 2569 if (tmp != NULL) 2570 xmlNewProp (nc, BAD_CAST "exceptionCode", BAD_CAST tmp->value); 2571 else 2572 xmlNewProp (nc, BAD_CAST "exceptionCode", BAD_CAST "NoApplicableCode"); 2573 2574 tmp = getMap (s, "locator"); 2575 if (tmp != NULL && strcasecmp (tmp->value, "NULL") != 0) 2576 xmlNewProp (nc, BAD_CAST "locator", BAD_CAST tmp->value); 2577 2578 2579 tmp = getMap (s, "text"); 2580 nc1 = xmlNewNode (ns, BAD_CAST "ExceptionText"); 2581 if (tmp != NULL) 2582 { 2583 xmlNodeSetContent (nc1, BAD_CAST tmp->value); 2584 } 2585 else 2586 { 2587 xmlNodeSetContent (nc1, BAD_CAST _("No debug message available")); 2588 } 2589 xmlAddChild (nc, nc1); 2590 xmlAddChild (n, nc); 2155 2591 return n; 2156 2592 } 2157 2593 2158 2594 2159 void outputResponse(service* s,maps* request_inputs,maps* request_outputs, 2160 map* request_inputs1,int cpid,maps* m,int res){ 2595 void 2596 outputResponse (service * s, maps * request_inputs, maps * request_outputs, 2597 map * request_inputs1, int cpid, maps * m, int res) 2598 { 2161 2599 #ifdef DEBUG 2162 dumpMaps(request_inputs); 2163 dumpMaps(request_outputs); 2164 fprintf(stderr,"printProcessResponse\n"); 2165 #endif 2166 map* toto=getMap(request_inputs1,"RawDataOutput"); 2167 int asRaw=0; 2168 if(toto!=NULL) 2169 asRaw=1; 2170 2171 maps* tmpSess=getMaps(m,"senv"); 2172 if(tmpSess!=NULL){ 2173 map *_tmp=getMapFromMaps(m,"lenv","cookie"); 2174 char* sessId=NULL; 2175 if(_tmp!=NULL){ 2176 printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value); 2177 printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 2178 char session_file_path[100]; 2179 char *tmp1=strtok(_tmp->value,";"); 2180 if(tmp1!=NULL) 2181 sprintf(session_file_path,"%s",strstr(tmp1,"=")+1); 2600 dumpMaps (request_inputs); 2601 dumpMaps (request_outputs); 2602 fprintf (stderr, "printProcessResponse\n"); 2603 #endif 2604 map *toto = getMap (request_inputs1, "RawDataOutput"); 2605 int asRaw = 0; 2606 if (toto != NULL) 2607 asRaw = 1; 2608 2609 maps *tmpSess = getMaps (m, "senv"); 2610 if (tmpSess != NULL) 2611 { 2612 map *_tmp = getMapFromMaps (m, "lenv", "cookie"); 2613 char *sessId = NULL; 2614 if (_tmp != NULL) 2615 { 2616 printf ("Set-Cookie: %s; HttpOnly\r\n", _tmp->value); 2617 printf 2618 ("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n"); 2619 char session_file_path[100]; 2620 char *tmp1 = strtok (_tmp->value, ";"); 2621 if (tmp1 != NULL) 2622 sprintf (session_file_path, "%s", strstr (tmp1, "=") + 1); 2623 else 2624 sprintf (session_file_path, "%s", strstr (_tmp->value, "=") + 1); 2625 sessId = strdup (session_file_path); 2626 } 2182 2627 else 2183 sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1); 2184 sessId=strdup(session_file_path); 2185 }else{ 2186 maps* t=getMaps(m,"senv"); 2187 map*p=t->content; 2188 while(p!=NULL){ 2189 if(strstr(p->name,"ID")!=NULL){ 2190 sessId=strdup(p->value); 2191 break; 2192 } 2193 p=p->next; 2194 } 2195 } 2196 char session_file_path[1024]; 2197 map *tmpPath=getMapFromMaps(m,"main","sessPath"); 2198 if(tmpPath==NULL) 2199 tmpPath=getMapFromMaps(m,"main","tmpPath"); 2200 sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId); 2201 FILE* teste=fopen(session_file_path,"w"); 2202 if(teste==NULL){ 2203 char tmpMsg[1024]; 2204 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the session maps."),session_file_path); 2205 map * errormap = createMap("text",tmpMsg); 2206 addToMap(errormap,"code", "InternalError"); 2207 2208 printExceptionReportResponse(m,errormap); 2209 freeMap(&errormap); 2210 free(errormap); 2211 return; 2212 } 2213 else{ 2214 fclose(teste); 2215 dumpMapsToFile(tmpSess,session_file_path); 2216 } 2217 } 2218 2219 2220 if(asRaw==0){ 2628 { 2629 maps *t = getMaps (m, "senv"); 2630 map *p = t->content; 2631 while (p != NULL) 2632 { 2633 if (strstr (p->name, "ID") != NULL) 2634 { 2635 sessId = strdup (p->value); 2636 break; 2637 } 2638 p = p->next; 2639 } 2640 } 2641 char session_file_path[1024]; 2642 map *tmpPath = getMapFromMaps (m, "main", "sessPath"); 2643 if (tmpPath == NULL) 2644 tmpPath = getMapFromMaps (m, "main", "tmpPath"); 2645 sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value, sessId); 2646 FILE *teste = fopen (session_file_path, "w"); 2647 if (teste == NULL) 2648 { 2649 char tmpMsg[1024]; 2650 sprintf (tmpMsg, 2651 _ 2652 ("Unable to create the file : \"%s\" for storing the session maps."), 2653 session_file_path); 2654 map *errormap = createMap ("text", tmpMsg); 2655 addToMap (errormap, "code", "InternalError"); 2656 2657 printExceptionReportResponse (m, errormap); 2658 freeMap (&errormap); 2659 free (errormap); 2660 return; 2661 } 2662 else 2663 { 2664 fclose (teste); 2665 dumpMapsToFile (tmpSess, session_file_path); 2666 } 2667 } 2668 2669 2670 if (asRaw == 0) 2671 { 2221 2672 #ifdef DEBUG 2222 fprintf(stderr,"REQUEST_OUTPUTS FINAL\n"); 2223 dumpMaps(request_outputs); 2224 #endif 2225 maps* tmpI=request_outputs; 2226 while(tmpI!=NULL){ 2673 fprintf (stderr, "REQUEST_OUTPUTS FINAL\n"); 2674 dumpMaps (request_outputs); 2675 #endif 2676 maps *tmpI = request_outputs; 2677 while (tmpI != NULL) 2678 { 2227 2679 #ifdef USE_MS 2228 map* testMap=getMap(tmpI->content,"useMapserver");2229 #endif 2230 toto=getMap(tmpI->content,"asReference");2680 map *testMap = getMap (tmpI->content, "useMapserver"); 2681 #endif 2682 toto = getMap (tmpI->content, "asReference"); 2231 2683 #ifdef USE_MS 2232 if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL) 2684 if (toto != NULL && strcasecmp (toto->value, "true") == 0 2685 && testMap == NULL) 2233 2686 #else 2234 if(toto!=NULL && strcasecmp(toto->value,"true")==0) 2235 #endif 2236 { 2237 elements* in=getElements(s->outputs,tmpI->name); 2238 char *format=NULL; 2239 if(in!=NULL){ 2240 format=strdup(in->format); 2241 }else 2242 format=strdup("LiteralData"); 2243 if(strcasecmp(format,"BoundingBoxData")==0){ 2244 addToMap(tmpI->content,"extension","xml"); 2245 addToMap(tmpI->content,"mimeType","text/xml"); 2246 addToMap(tmpI->content,"encoding","UTF-8"); 2247 addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2248 } 2249 map *ext=getMap(tmpI->content,"extension"); 2250 map *tmp1=getMapFromMaps(m,"main","tmpPath"); 2251 char *file_name,*file_path; 2252 bool hasExt=true; 2253 if(ext==NULL){ 2254 // We can fallback to a default list of supported formats using 2255 // mimeType information if present here. Maybe we can add more formats 2256 // here. 2257 // If mimeType was not found, we then set txt as the default extension 2258 map* mtype=getMap(tmpI->content,"mimeType"); 2259 if(mtype!=NULL){ 2260 if(strcasecmp(mtype->value,"text/xml")==0) 2261 ext=createMap("extension","xml"); 2262 else if(strcasecmp(mtype->value,"application/json")==0) 2263 ext=createMap("extension","js"); 2264 else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0) 2265 ext=createMap("extension","kml"); 2266 else if(strncmp(mtype->value,"image/",6)==0) 2267 ext=createMap("extension",strstr(mtype->value,"/")+1); 2268 else 2269 ext=createMap("extension","txt"); 2270 } 2271 else 2272 ext=createMap("extension","txt"); 2273 hasExt=false; 2274 } 2275 file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char)); 2276 int cpid0=cpid+time(NULL); 2277 sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value); 2278 file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char)); 2279 sprintf(file_path,"%s/%s",tmp1->value,file_name); 2280 FILE *ofile=fopen(file_path,"wb"); 2281 if(ofile==NULL){ 2282 char tmpMsg[1024]; 2283 sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name); 2284 map * errormap = createMap("text",tmpMsg); 2285 addToMap(errormap,"code", "InternalError"); 2286 printExceptionReportResponse(m,errormap); 2287 freeMap(&errormap); 2288 free(errormap); 2289 free(file_name); 2290 free(file_path); 2291 return; 2292 } 2293 free(file_path); 2294 map *tmp2=getMapFromMaps(m,"main","tmpUrl"); 2295 map *tmp3=getMapFromMaps(m,"main","serverAddress"); 2296 char *file_url; 2297 if(strncasecmp(tmp2->value,"http://",7)==0 || 2298 strncasecmp(tmp2->value,"https://",8)==0){ 2299 file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char)); 2300 sprintf(file_url,"%s/%s",tmp2->value,file_name); 2301 }else{ 2302 file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char)); 2303 sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name); 2304 } 2305 addToMap(tmpI->content,"Reference",file_url); 2306 if(!hasExt){ 2307 freeMap(&ext); 2308 free(ext); 2309 } 2310 toto=getMap(tmpI->content,"value"); 2311 if(strcasecmp(format,"BoundingBoxData")!=0){ 2312 map* size=getMap(tmpI->content,"size"); 2313 if(size!=NULL && toto!=NULL) 2314 fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile); 2315 else 2316 if(toto!=NULL && toto->value!=NULL) 2317 fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile); 2318 }else{ 2319 printBoundingBoxDocument(m,tmpI,ofile); 2320 } 2321 free(format); 2322 fclose(ofile); 2323 free(file_name); 2324 free(file_url); 2325 } 2687 if (toto != NULL && strcasecmp (toto->value, "true") == 0) 2688 #endif 2689 { 2690 elements *in = getElements (s->outputs, tmpI->name); 2691 char *format = NULL; 2692 if (in != NULL) 2693 { 2694 format = strdup (in->format); 2695 } 2696 else 2697 format = strdup ("LiteralData"); 2698 if (strcasecmp (format, "BoundingBoxData") == 0) 2699 { 2700 addToMap (tmpI->content, "extension", "xml"); 2701 addToMap (tmpI->content, "mimeType", "text/xml"); 2702 addToMap (tmpI->content, "encoding", "UTF-8"); 2703 addToMap (tmpI->content, "schema", 2704 "http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 2705 } 2706 map *ext = getMap (tmpI->content, "extension"); 2707 map *tmp1 = getMapFromMaps (m, "main", "tmpPath"); 2708 char *file_name, *file_path; 2709 bool hasExt = true; 2710 if (ext == NULL) 2711 { 2712 // We can fallback to a default list of supported formats using 2713 // mimeType information if present here. Maybe we can add more formats 2714 // here. 2715 // If mimeType was not found, we then set txt as the default extension 2716 map *mtype = getMap (tmpI->content, "mimeType"); 2717 if (mtype != NULL) 2718 { 2719 if (strcasecmp (mtype->value, "text/xml") == 0) 2720 ext = createMap ("extension", "xml"); 2721 else if (strcasecmp (mtype->value, "application/json") 2722 == 0) 2723 ext = createMap ("extension", "js"); 2724 else 2725 if (strncmp 2726 (mtype->value, "application/vnd.google-earth.kml", 2727 32) == 0) 2728 ext = createMap ("extension", "kml"); 2729 else if (strncmp (mtype->value, "image/", 6) == 0) 2730 ext = 2731 createMap ("extension", 2732 strstr (mtype->value, "/") + 1); 2733 else 2734 ext = createMap ("extension", "txt"); 2735 } 2736 else 2737 ext = createMap ("extension", "txt"); 2738 hasExt = false; 2739 } 2740 file_name = 2741 (char *) 2742 malloc ((strlen (s->name) + strlen (ext->value) + 2743 strlen (tmpI->name) + 1024) * sizeof (char)); 2744 int cpid0 = cpid + time (NULL); 2745 sprintf (file_name, "%s_%s_%i.%s", s->name, tmpI->name, cpid0, 2746 ext->value); 2747 file_path = 2748 (char *) 2749 malloc ((strlen (tmp1->value) + strlen (file_name) + 2750 2) * sizeof (char)); 2751 sprintf (file_path, "%s/%s", tmp1->value, file_name); 2752 FILE *ofile = fopen (file_path, "wb"); 2753 if (ofile == NULL) 2754 { 2755 char tmpMsg[1024]; 2756 sprintf (tmpMsg, 2757 _ 2758 ("Unable to create the file : \"%s\" for storing the %s final result."), 2759 file_name, tmpI->name); 2760 map *errormap = createMap ("text", tmpMsg); 2761 addToMap (errormap, "code", "InternalError"); 2762 printExceptionReportResponse (m, errormap); 2763 freeMap (&errormap); 2764 free (errormap); 2765 free (file_name); 2766 free (file_path); 2767 return; 2768 } 2769 free (file_path); 2770 map *tmp2 = getMapFromMaps (m, "main", "tmpUrl"); 2771 map *tmp3 = getMapFromMaps (m, "main", "serverAddress"); 2772 char *file_url; 2773 if (strncasecmp (tmp2->value, "http://", 7) == 0 || 2774 strncasecmp (tmp2->value, "https://", 8) == 0) 2775 { 2776 file_url = 2777 (char *) 2778 malloc ((strlen (tmp2->value) + strlen (file_name) + 2779 2) * sizeof (char)); 2780 sprintf (file_url, "%s/%s", tmp2->value, file_name); 2781 } 2782 else 2783 { 2784 file_url = 2785 (char *) 2786 malloc ((strlen (tmp3->value) + strlen (tmp2->value) + 2787 strlen (file_name) + 3) * sizeof (char)); 2788 sprintf (file_url, "%s/%s/%s", tmp3->value, tmp2->value, 2789 file_name); 2790 } 2791 addToMap (tmpI->content, "Reference", file_url); 2792 if (!hasExt) 2793 { 2794 freeMap (&ext); 2795 free (ext); 2796 } 2797 toto = getMap (tmpI->content, "value"); 2798 if (strcasecmp (format, "BoundingBoxData") != 0) 2799 { 2800 map *size = getMap (tmpI->content, "size"); 2801 if (size != NULL && toto != NULL) 2802 fwrite (toto->value, 1, 2803 atoi (size->value) * sizeof (char), ofile); 2804 else if (toto != NULL && toto->value != NULL) 2805 fwrite (toto->value, 1, 2806 strlen (toto->value) * sizeof (char), ofile); 2807 } 2808 else 2809 { 2810 printBoundingBoxDocument (m, tmpI, ofile); 2811 } 2812 free (format); 2813 fclose (ofile); 2814 free (file_name); 2815 free (file_url); 2816 } 2326 2817 #ifdef USE_MS 2327 else{ 2328 if(testMap!=NULL){ 2329 setReferenceUrl(m,tmpI); 2330 } 2331 } 2332 #endif 2333 tmpI=tmpI->next; 2334 } 2335 map *r_inputs=getMap(s->content,"serviceProvider"); 2818 else 2819 { 2820 if (testMap != NULL) 2821 { 2822 setReferenceUrl (m, tmpI); 2823 } 2824 } 2825 #endif 2826 tmpI = tmpI->next; 2827 } 2828 map *r_inputs = getMap (s->content, "serviceProvider"); 2336 2829 #ifdef DEBUG 2337 fprintf(stderr,"SERVICE : %s\n",r_inputs->value); 2338 dumpMaps(m); 2339 #endif 2340 printProcessResponse(m,request_inputs1,cpid, 2341 s,r_inputs->value,res, 2342 request_inputs, 2343 request_outputs); 2344 } 2345 else{ 2346 if(res==SERVICE_FAILED){ 2347 map * errormap; 2348 map *lenv; 2349 lenv=getMapFromMaps(m,"lenv","message"); 2350 char *tmp0; 2351 if(lenv!=NULL){ 2352 tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char)); 2353 sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value); 2354 } 2355 else{ 2356 tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char)); 2357 sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service.")); 2358 } 2359 errormap = createMap("text",tmp0); 2360 free(tmp0); 2361 addToMap(errormap,"code", "InternalError"); 2362 printExceptionReportResponse(m,errormap); 2363 freeMap(&errormap); 2364 free(errormap); 2365 return; 2366 } 2830 fprintf (stderr, "SERVICE : %s\n", r_inputs->value); 2831 dumpMaps (m); 2832 #endif 2833 printProcessResponse (m, request_inputs1, cpid, 2834 s, r_inputs->value, res, 2835 request_inputs, request_outputs); 2836 } 2837 else 2838 { 2839 if (res == SERVICE_FAILED) 2840 { 2841 map *errormap; 2842 map *lenv; 2843 lenv = getMapFromMaps (m, "lenv", "message"); 2844 char *tmp0; 2845 if (lenv != NULL) 2846 { 2847 tmp0 = 2848 (char *) 2849 malloc ((strlen (lenv->value) + 2850 strlen (_ 2851 ("Unable to run the Service. The message returned back by the Service was the following: ")) 2852 + 1) * sizeof (char)); 2853 sprintf (tmp0, 2854 _ 2855 ("Unable to run the Service. The message returned back by the Service was the following: %s"), 2856 lenv->value); 2857 } 2858 else 2859 { 2860 tmp0 = 2861 (char *) 2862 malloc ((strlen 2863 (_ 2864 ("Unable to run the Service. No more information was returned back by the Service.")) 2865 + 1) * sizeof (char)); 2866 sprintf (tmp0, 2867 _ 2868 ("Unable to run the Service. No more information was returned back by the Service.")); 2869 } 2870 errormap = createMap ("text", tmp0); 2871 free (tmp0); 2872 addToMap (errormap, "code", "InternalError"); 2873 printExceptionReportResponse (m, errormap); 2874 freeMap (&errormap); 2875 free (errormap); 2876 return; 2877 } 2367 2878 /** 2368 2879 * We get the requested output or fallback to the first one if the 2369 2880 * requested one is not present in the resulting outputs maps. 2370 2881 */ 2371 maps* tmpI=NULL; 2372 map* tmpIV=getMap(request_inputs1,"RawDataOutput"); 2373 if(tmpIV!=NULL){ 2374 tmpI=getMaps(request_outputs,tmpIV->value); 2375 } 2376 if(tmpI==NULL) 2377 tmpI=request_outputs; 2378 elements* e=getElements(s->outputs,tmpI->name); 2379 if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){ 2380 printBoundingBoxDocument(m,tmpI,NULL); 2381 }else{ 2382 toto=getMap(tmpI->content,"value"); 2383 if(toto==NULL){ 2384 char tmpMsg[1024]; 2385 sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name); 2386 map * errormap = createMap("text",tmpMsg); 2387 addToMap(errormap,"code", "InvalidParameterValue"); 2388 printExceptionReportResponse(m,errormap); 2389 freeMap(&errormap); 2390 free(errormap); 2391 return; 2392 } 2393 map* fname=getMapFromMaps(tmpI,tmpI->name,"filename"); 2394 if(fname!=NULL) 2395 printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value); 2396 map* rs=getMapFromMaps(tmpI,tmpI->name,"size"); 2397 if(rs!=NULL) 2398 printf("Content-Length: %s\r\n",rs->value); 2399 printHeaders(m); 2400 char mime[1024]; 2401 map* mi=getMap(tmpI->content,"mimeType"); 2882 maps *tmpI = NULL; 2883 map *tmpIV = getMap (request_inputs1, "RawDataOutput"); 2884 if (tmpIV != NULL) 2885 { 2886 tmpI = getMaps (request_outputs, tmpIV->value); 2887 } 2888 if (tmpI == NULL) 2889 tmpI = request_outputs; 2890 elements *e = getElements (s->outputs, tmpI->name); 2891 if (e != NULL && strcasecmp (e->format, "BoundingBoxData") == 0) 2892 { 2893 printBoundingBoxDocument (m, tmpI, NULL); 2894 } 2895 else 2896 { 2897 toto = getMap (tmpI->content, "value"); 2898 if (toto == NULL) 2899 { 2900 char tmpMsg[1024]; 2901 sprintf (tmpMsg, 2902 _ 2903 ("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."), 2904 tmpI->name); 2905 map *errormap = createMap ("text", tmpMsg); 2906 addToMap (errormap, "code", "InvalidParameterValue"); 2907 printExceptionReportResponse (m, errormap); 2908 freeMap (&errormap); 2909 free (errormap); 2910 return; 2911 } 2912 map *fname = getMapFromMaps (tmpI, tmpI->name, "filename"); 2913 if (fname != NULL) 2914 printf ("Content-Disposition: attachment; filename=\"%s\"\r\n", 2915 fname->value); 2916 map *rs = getMapFromMaps (tmpI, tmpI->name, "size"); 2917 if (rs != NULL) 2918 printf ("Content-Length: %s\r\n", rs->value); 2919 printHeaders (m); 2920 char mime[1024]; 2921 map *mi = getMap (tmpI->content, "mimeType"); 2402 2922 #ifdef DEBUG 2403 fprintf(stderr,"SERVICE OUTPUTS\n");2404 dumpMaps(request_outputs);2405 fprintf(stderr,"SERVICE OUTPUTS\n");2406 #endif 2407 map* en=getMap(tmpI->content,"encoding");2408 if(mi!=NULL && en!=NULL)2409 sprintf(mime,2410 2411 mi->value,en->value);2412 else 2413 if(mi!=NULL) 2414 sprintf(mime,2415 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2416 mi->value); 2417 else 2418 sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");2419 printf("%s",mime);2420 if(rs!=NULL)2421 fwrite(toto->value,1,atoi(rs->value),stdout);2422 2423 fwrite(toto->value,1,strlen(toto->value),stdout);2923 fprintf (stderr, "SERVICE OUTPUTS\n"); 2924 dumpMaps (request_outputs); 2925 fprintf (stderr, "SERVICE OUTPUTS\n"); 2926 #endif 2927 map *en = getMap (tmpI->content, "encoding"); 2928 if (mi != NULL && en != NULL) 2929 sprintf (mime, 2930 "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n", 2931 mi->value, en->value); 2932 else if (mi != NULL) 2933 sprintf (mime, 2934 "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n", 2935 mi->value); 2936 else 2937 sprintf (mime, 2938 "Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n"); 2939 printf ("%s", mime); 2940 if (rs != NULL) 2941 fwrite (toto->value, 1, atoi (rs->value), stdout); 2942 else 2943 fwrite (toto->value, 1, strlen (toto->value), stdout); 2424 2944 #ifdef DEBUG 2425 dumpMap(toto); 2426 #endif 2427 } 2428 } 2429 } 2430 2431 char *base64(const char *input, int length) 2945 dumpMap (toto); 2946 #endif 2947 } 2948 } 2949 } 2950 2951 char * 2952 base64 (const char *input, int length) 2432 2953 { 2433 2954 BIO *bmem, *b64; 2434 2955 BUF_MEM *bptr; 2435 2956 2436 b64 = BIO_new (BIO_f_base64());2437 BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);2438 bmem = BIO_new (BIO_s_mem());2439 b64 = BIO_push (b64, bmem);2440 BIO_write (b64, input, length+1);2441 BIO_flush (b64);2442 BIO_get_mem_ptr (b64, &bptr);2443 2444 char *buff = (char *) malloc((bptr->length+1)*sizeof(char));2445 memcpy (buff, bptr->data, bptr->length);2446 buff[bptr->length -1] = 0;2447 2448 BIO_free_all (b64);2957 b64 = BIO_new (BIO_f_base64 ()); 2958 BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL); 2959 bmem = BIO_new (BIO_s_mem ()); 2960 b64 = BIO_push (b64, bmem); 2961 BIO_write (b64, input, length + 1); 2962 BIO_flush (b64); 2963 BIO_get_mem_ptr (b64, &bptr); 2964 2965 char *buff = (char *) malloc ((bptr->length + 1) * sizeof (char)); 2966 memcpy (buff, bptr->data, bptr->length); 2967 buff[bptr->length - 1] = 0; 2968 2969 BIO_free_all (b64); 2449 2970 2450 2971 return buff; 2451 2972 } 2452 2973 2453 char *base64d(const char *input, int length,int* red) 2974 char * 2975 base64d (const char *input, int length, int *red) 2454 2976 { 2455 2977 BIO *b64, *bmem; 2456 2978 2457 char *buffer = (char *)malloc(length); 2458 if(buffer){ 2459 memset(buffer, 0, length); 2460 b64 = BIO_new(BIO_f_base64()); 2461 if(b64){ 2462 bmem = BIO_new_mem_buf((unsigned char*)input,length); 2463 bmem = BIO_push(b64, bmem); 2464 *red=BIO_read(bmem, buffer, length); 2465 buffer[length-1]=0; 2466 BIO_free_all(bmem); 2467 } 2468 } 2979 char *buffer = (char *) malloc (length); 2980 if (buffer) 2981 { 2982 memset (buffer, 0, length); 2983 b64 = BIO_new (BIO_f_base64 ()); 2984 if (b64) 2985 { 2986 bmem = BIO_new_mem_buf ((unsigned char *) input, length); 2987 bmem = BIO_push (b64, bmem); 2988 *red = BIO_read (bmem, buffer, length); 2989 buffer[length - 1] = 0; 2990 BIO_free_all (bmem); 2991 } 2992 } 2469 2993 return buffer; 2470 2994 } 2471 2995 2472 void ensureDecodedBase64(maps **in){ 2473 maps* cursor=*in; 2474 while(cursor!=NULL){ 2475 map *tmp=getMap(cursor->content,"encoding"); 2476 if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){ 2477 tmp=getMap(cursor->content,"value"); 2478 addToMap(cursor->content,"base64_value",tmp->value); 2479 int size=0; 2480 char *s=strdup(tmp->value); 2481 free(tmp->value); 2482 tmp->value=base64d(s,strlen(s),&size); 2483 free(s); 2484 char sizes[1024]; 2485 sprintf(sizes,"%d",size); 2486 addToMap(cursor->content,"size",sizes); 2487 } 2488 cursor=cursor->next; 2489 } 2490 } 2491 2492 char* addDefaultValues(maps** out,elements* in,maps* m,int type){ 2493 elements* tmpInputs=in; 2494 maps* out1=*out; 2495 if(type==1){ 2496 while(out1!=NULL){ 2497 if(getElements(in,out1->name)==NULL) 2498 return out1->name; 2499 out1=out1->next; 2500 } 2501 out1=*out; 2502 } 2503 while(tmpInputs!=NULL){ 2504 maps *tmpMaps=getMaps(out1,tmpInputs->name); 2505 if(tmpMaps==NULL){ 2506 maps* tmpMaps2=(maps*)malloc(MAPS_SIZE); 2507 tmpMaps2->name=strdup(tmpInputs->name); 2508 tmpMaps2->content=NULL; 2509 tmpMaps2->next=NULL; 2510 2511 if(type==0){ 2512 map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs"); 2513 if(tmpMapMinO!=NULL){ 2514 if(atoi(tmpMapMinO->value)>=1){ 2515 freeMaps(&tmpMaps2); 2516 free(tmpMaps2); 2517 return tmpInputs->name; 2518 } 2519 else{ 2520 if(tmpMaps2->content==NULL) 2521 tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value); 2522 else 2523 addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value); 2524 } 2525 } 2526 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 2527 if(tmpMaxO!=NULL){ 2528 if(tmpMaps2->content==NULL) 2529 tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value); 2530 else 2531 addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value); 2532 } 2533 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 2534 if(tmpMaxMB!=NULL){ 2535 if(tmpMaps2->content==NULL) 2536 tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value); 2537 else 2538 addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value); 2539 } 2540 } 2541 2542 iotype* tmpIoType=tmpInputs->defaults; 2543 if(tmpIoType!=NULL){ 2544 map* tmpm=tmpIoType->content; 2545 while(tmpm!=NULL){ 2546 if(tmpMaps2->content==NULL) 2547 tmpMaps2->content=createMap(tmpm->name,tmpm->value); 2548 else 2549 addToMap(tmpMaps2->content,tmpm->name,tmpm->value); 2550 tmpm=tmpm->next; 2551 } 2552 } 2553 addToMap(tmpMaps2->content,"inRequest","false"); 2554 if(type==0){ 2555 map *tmpMap=getMap(tmpMaps2->content,"value"); 2556 if(tmpMap==NULL) 2557 addToMap(tmpMaps2->content,"value","NULL"); 2558 } 2559 if(out1==NULL){ 2560 *out=dupMaps(&tmpMaps2); 2561 out1=*out; 2562 } 2996 void 2997 ensureDecodedBase64 (maps ** in) 2998 { 2999 maps *cursor = *in; 3000 while (cursor != NULL) 3001 { 3002 map *tmp = getMap (cursor->content, "encoding"); 3003 if (tmp != NULL && strncasecmp (tmp->value, "base64", 6) == 0) 3004 { 3005 tmp = getMap (cursor->content, "value"); 3006 addToMap (cursor->content, "base64_value", tmp->value); 3007 int size = 0; 3008 char *s = strdup (tmp->value); 3009 free (tmp->value); 3010 tmp->value = base64d (s, strlen (s), &size); 3011 free (s); 3012 char sizes[1024]; 3013 sprintf (sizes, "%d", size); 3014 addToMap (cursor->content, "size", sizes); 3015 } 3016 cursor = cursor->next; 3017 } 3018 } 3019 3020 char * 3021 addDefaultValues (maps ** out, elements * in, maps * m, int type) 3022 { 3023 elements *tmpInputs = in; 3024 maps *out1 = *out; 3025 if (type == 1) 3026 { 3027 while (out1 != NULL) 3028 { 3029 if (getElements (in, out1->name) == NULL) 3030 return out1->name; 3031 out1 = out1->next; 3032 } 3033 out1 = *out; 3034 } 3035 while (tmpInputs != NULL) 3036 { 3037 maps *tmpMaps = getMaps (out1, tmpInputs->name); 3038 if (tmpMaps == NULL) 3039 { 3040 maps *tmpMaps2 = (maps *) malloc (MAPS_SIZE); 3041 tmpMaps2->name = strdup (tmpInputs->name); 3042 tmpMaps2->content = NULL; 3043 tmpMaps2->next = NULL; 3044 3045 if (type == 0) 3046 { 3047 map *tmpMapMinO = getMap (tmpInputs->content, "minOccurs"); 3048 if (tmpMapMinO != NULL) 3049 { 3050 if (atoi (tmpMapMinO->value) >= 1) 3051 { 3052 freeMaps (&tmpMaps2); 3053 free (tmpMaps2); 3054 return tmpInputs->name; 3055 } 3056 else 3057 { 3058 if (tmpMaps2->content == NULL) 3059 tmpMaps2->content = 3060 createMap ("minOccurs", tmpMapMinO->value); 3061 else 3062 addToMap (tmpMaps2->content, "minOccurs", 3063 tmpMapMinO->value); 3064 } 3065 } 3066 map *tmpMaxO = getMap (tmpInputs->content, "maxOccurs"); 3067 if (tmpMaxO != NULL) 3068 { 3069 if (tmpMaps2->content == NULL) 3070 tmpMaps2->content = 3071 createMap ("maxOccurs", tmpMaxO->value); 3072 else 3073 addToMap (tmpMaps2->content, "maxOccurs", tmpMaxO->value); 3074 } 3075 map *tmpMaxMB = getMap (tmpInputs->content, "maximumMegabytes"); 3076 if (tmpMaxMB != NULL) 3077 { 3078 if (tmpMaps2->content == NULL) 3079 tmpMaps2->content = 3080 createMap ("maximumMegabytes", tmpMaxMB->value); 3081 else 3082 addToMap (tmpMaps2->content, "maximumMegabytes", 3083 tmpMaxMB->value); 3084 } 3085 } 3086 3087 iotype *tmpIoType = tmpInputs->defaults; 3088 if (tmpIoType != NULL) 3089 { 3090 map *tmpm = tmpIoType->content; 3091 while (tmpm != NULL) 3092 { 3093 if (tmpMaps2->content == NULL) 3094 tmpMaps2->content = createMap (tmpm->name, tmpm->value); 3095 else 3096 addToMap (tmpMaps2->content, tmpm->name, tmpm->value); 3097 tmpm = tmpm->next; 3098 } 3099 } 3100 addToMap (tmpMaps2->content, "inRequest", "false"); 3101 if (type == 0) 3102 { 3103 map *tmpMap = getMap (tmpMaps2->content, "value"); 3104 if (tmpMap == NULL) 3105 addToMap (tmpMaps2->content, "value", "NULL"); 3106 } 3107 if (out1 == NULL) 3108 { 3109 *out = dupMaps (&tmpMaps2); 3110 out1 = *out; 3111 } 3112 else 3113 addMapsToMaps (&out1, tmpMaps2); 3114 freeMap (&tmpMaps2->content); 3115 free (tmpMaps2->content); 3116 tmpMaps2->content = NULL; 3117 freeMaps (&tmpMaps2); 3118 free (tmpMaps2); 3119 tmpMaps2 = NULL; 3120 } 2563 3121 else 2564 addMapsToMaps(&out1,tmpMaps2); 2565 freeMap(&tmpMaps2->content); 2566 free(tmpMaps2->content); 2567 tmpMaps2->content=NULL; 2568 freeMaps(&tmpMaps2); 2569 free(tmpMaps2); 2570 tmpMaps2=NULL; 2571 } 2572 else{ 2573 iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name, 2574 tmpMaps->content); 2575 if(type==0) { 2576 /** 3122 { 3123 iotype *tmpIoType = 3124 getIoTypeFromElement (tmpInputs, tmpInputs->name, 3125 tmpMaps->content); 3126 if (type == 0) 3127 { 3128 /** 2577 3129 * In case of an Input maps, then add the minOccurs and maxOccurs to the 2578 3130 * content map. 2579 3131 */ 2580 map* tmpMap1=getMap(tmpInputs->content,"minOccurs"); 2581 if(tmpMap1!=NULL){ 2582 if(tmpMaps->content==NULL) 2583 tmpMaps->content=createMap("minOccurs",tmpMap1->value); 2584 else 2585 addToMap(tmpMaps->content,"minOccurs",tmpMap1->value); 2586 } 2587 map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs"); 2588 if(tmpMaxO!=NULL){ 2589 if(tmpMaps->content==NULL) 2590 tmpMaps->content=createMap("maxOccurs",tmpMaxO->value); 2591 else 2592 addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value); 2593 } 2594 map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes"); 2595 if(tmpMaxMB!=NULL){ 2596 if(tmpMaps->content==NULL) 2597 tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value); 2598 else 2599 addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value); 2600 } 2601 /** 3132 map *tmpMap1 = getMap (tmpInputs->content, "minOccurs"); 3133 if (tmpMap1 != NULL) 3134 { 3135 if (tmpMaps->content == NULL) 3136 tmpMaps->content = 3137 createMap ("minOccurs", tmpMap1->value); 3138 else 3139 addToMap (tmpMaps->content, "minOccurs", tmpMap1->value); 3140 } 3141 map *tmpMaxO = getMap (tmpInputs->content, "maxOccurs"); 3142 if (tmpMaxO != NULL) 3143 { 3144 if (tmpMaps->content == NULL) 3145 tmpMaps->content = 3146 createMap ("maxOccurs", tmpMaxO->value); 3147 else 3148 addToMap (tmpMaps->content, "maxOccurs", tmpMaxO->value); 3149 } 3150 map *tmpMaxMB = getMap (tmpInputs->content, "maximumMegabytes"); 3151 if (tmpMaxMB != NULL) 3152 { 3153 if (tmpMaps->content == NULL) 3154 tmpMaps->content = 3155 createMap ("maximumMegabytes", tmpMaxMB->value); 3156 else 3157 addToMap (tmpMaps->content, "maximumMegabytes", 3158 tmpMaxMB->value); 3159 } 3160 /** 2602 3161 * Parsing BoundingBoxData, fill the following map and then add it to 2603 3162 * the content map of the Input maps: … … 2605 3164 * cf. parseBoundingBox 2606 3165 */ 2607 if(strcasecmp(tmpInputs->format,"BoundingBoxData")==0){ 2608 maps* tmpI=getMaps(*out,tmpInputs->name); 2609 if(tmpI!=NULL){ 2610 map* tmpV=getMap(tmpI->content,"value"); 2611 if(tmpV!=NULL){ 2612 char *tmpVS=strdup(tmpV->value); 2613 map* tmp=parseBoundingBox(tmpVS); 2614 free(tmpVS); 2615 map* tmpC=tmp; 2616 while(tmpC!=NULL){ 2617 addToMap(tmpMaps->content,tmpC->name,tmpC->value); 2618 tmpC=tmpC->next; 2619 } 2620 freeMap(&tmp); 2621 free(tmp); 2622 } 2623 } 2624 } 2625 } 2626 2627 if(tmpIoType!=NULL){ 2628 map* tmpContent=tmpIoType->content; 2629 map* cval=NULL; 2630 int hasPassed=-1; 2631 while(tmpContent!=NULL){ 2632 if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){ 3166 if (strcasecmp (tmpInputs->format, "BoundingBoxData") == 0) 3167 { 3168 maps *tmpI = getMaps (*out, tmpInputs->name); 3169 if (tmpI != NULL) 3170 { 3171 map *tmpV = getMap (tmpI->content, "value"); 3172 if (tmpV != NULL) 3173 { 3174 char *tmpVS = strdup (tmpV->value); 3175 map *tmp = parseBoundingBox (tmpVS); 3176 free (tmpVS); 3177 map *tmpC = tmp; 3178 while (tmpC != NULL) 3179 { 3180 addToMap (tmpMaps->content, tmpC->name, 3181 tmpC->value); 3182 tmpC = tmpC->next; 3183 } 3184 freeMap (&tmp); 3185 free (tmp); 3186 } 3187 } 3188 } 3189 } 3190 3191 if (tmpIoType != NULL) 3192 { 3193 map *tmpContent = tmpIoType->content; 3194 map *cval = NULL; 3195 int hasPassed = -1; 3196 while (tmpContent != NULL) 3197 { 3198 if ((cval = 3199 getMap (tmpMaps->content, tmpContent->name)) == NULL) 3200 { 2633 3201 #ifdef DEBUG 2634 fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value); 2635 #endif 2636 if(tmpMaps->content==NULL) 2637 tmpMaps->content=createMap(tmpContent->name,tmpContent->value); 2638 else 2639 addToMap(tmpMaps->content,tmpContent->name,tmpContent->value); 2640 2641 if(hasPassed<0 && type==0 && getMap(tmpMaps->content,"isArray")!=NULL){ 2642 map* length=getMap(tmpMaps->content,"length"); 2643 int i; 2644 char *tcn=strdup(tmpContent->name); 2645 for(i=1;i<atoi(length->value);i++){ 3202 fprintf (stderr, "addDefaultValues %s => %s\n", 3203 tmpContent->name, tmpContent->value); 3204 #endif 3205 if (tmpMaps->content == NULL) 3206 tmpMaps->content = 3207 createMap (tmpContent->name, tmpContent->value); 3208 else 3209 addToMap (tmpMaps->content, tmpContent->name, 3210 tmpContent->value); 3211 3212 if (hasPassed < 0 && type == 0 3213 && getMap (tmpMaps->content, "isArray") != NULL) 3214 { 3215 map *length = getMap (tmpMaps->content, "length"); 3216 int i; 3217 char *tcn = strdup (tmpContent->name); 3218 for (i = 1; i < atoi (length->value); i++) 3219 { 2646 3220 #ifdef DEBUG 2647 dumpMap(tmpMaps->content); 2648 fprintf(stderr,"addDefaultValues %s_%d => %s\n",tcn,i,tmpContent->value); 2649 #endif 2650 int len=strlen((char*) tcn); 2651 char *tmp1=(char *)malloc((len+10)*sizeof(char)); 2652 sprintf(tmp1,"%s_%d",tcn,i); 3221 dumpMap (tmpMaps->content); 3222 fprintf (stderr, 3223 "addDefaultValues %s_%d => %s\n", tcn, 3224 i, tmpContent->value); 3225 #endif 3226 int len = strlen ((char *) tcn); 3227 char *tmp1 = 3228 (char *) malloc ((len + 10) * sizeof (char)); 3229 sprintf (tmp1, "%s_%d", tcn, i); 2653 3230 #ifdef DEBUG 2654 fprintf(stderr,"addDefaultValues %s => %s\n",tmp1,tmpContent->value); 2655 #endif 2656 addToMap(tmpMaps->content,tmp1,tmpContent->value); 2657 free(tmp1); 2658 hasPassed=1; 2659 } 2660 free(tcn); 2661 } 2662 } 2663 tmpContent=tmpContent->next; 2664 } 3231 fprintf (stderr, "addDefaultValues %s => %s\n", 3232 tmp1, tmpContent->value); 3233 #endif 3234 addToMap (tmpMaps->content, tmp1, 3235 tmpContent->value); 3236 free (tmp1); 3237 hasPassed = 1; 3238 } 3239 free (tcn); 3240 } 3241 } 3242 tmpContent = tmpContent->next; 3243 } 2665 3244 #ifdef USE_MS 2666 3245 /** 2667 3246 * check for useMapServer presence 2668 3247 */ 2669 map* tmpCheck=getMap(tmpIoType->content,"useMapServer"); 2670 if(tmpCheck!=NULL){ 2671 // Get the default value 2672 tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL); 2673 tmpCheck=getMap(tmpMaps->content,"mimeType"); 2674 addToMap(tmpMaps->content,"requestedMimeType",tmpCheck->value); 2675 map* cursor=tmpIoType->content; 2676 while(cursor!=NULL){ 2677 addToMap(tmpMaps->content,cursor->name,cursor->value); 2678 cursor=cursor->next; 2679 } 2680 2681 cursor=tmpInputs->content; 2682 while(cursor!=NULL){ 2683 if(strcasecmp(cursor->name,"Title")==0 || 2684 strcasecmp(cursor->name,"Abstract")==0) 2685 addToMap(tmpMaps->content,cursor->name,cursor->value); 2686 cursor=cursor->next; 2687 } 2688 } 2689 #endif 2690 } 2691 if(tmpMaps->content==NULL) 2692 tmpMaps->content=createMap("inRequest","true"); 2693 else 2694 addToMap(tmpMaps->content,"inRequest","true"); 2695 2696 } 2697 tmpInputs=tmpInputs->next; 2698 } 3248 map *tmpCheck = getMap (tmpIoType->content, "useMapServer"); 3249 if (tmpCheck != NULL) 3250 { 3251 // Get the default value 3252 tmpIoType = 3253 getIoTypeFromElement (tmpInputs, tmpInputs->name, NULL); 3254 tmpCheck = getMap (tmpMaps->content, "mimeType"); 3255 addToMap (tmpMaps->content, "requestedMimeType", 3256 tmpCheck->value); 3257 map *cursor = tmpIoType->content; 3258 while (cursor != NULL) 3259 { 3260 addToMap (tmpMaps->content, cursor->name, 3261 cursor->value); 3262 cursor = cursor->next; 3263 } 3264 3265 cursor = tmpInputs->content; 3266 while (cursor != NULL) 3267 { 3268 if (strcasecmp (cursor->name, "Title") == 0 || 3269 strcasecmp (cursor->name, "Abstract") == 0) 3270 addToMap (tmpMaps->content, cursor->name, 3271 cursor->value); 3272 cursor = cursor->next; 3273 } 3274 } 3275 #endif 3276 } 3277 if (tmpMaps->content == NULL) 3278 tmpMaps->content = createMap ("inRequest", "true"); 3279 else 3280 addToMap (tmpMaps->content, "inRequest", "true"); 3281 3282 } 3283 tmpInputs = tmpInputs->next; 3284 } 2699 3285 return ""; 2700 3286 } … … 2716 3302 * Note : support only 2D bounding box. 2717 3303 */ 2718 map* parseBoundingBox(const char* value){ 2719 map *res=NULL; 2720 if(value!=NULL){ 2721 char *cv,*cvp; 2722 cv=strtok_r((char*) value,",",&cvp); 2723 int cnt=0; 2724 int icnt=0; 2725 char *currentValue=NULL; 2726 while(cv){ 2727 if(cnt<2) 2728 if(currentValue!=NULL){ 2729 char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char)); 2730 sprintf(finalValue,"%s%s",currentValue,cv); 2731 switch(cnt){ 2732 case 0: 2733 res=createMap("lowerCorner",finalValue); 2734 break; 2735 case 1: 2736 addToMap(res,"upperCorner",finalValue); 2737 icnt=-1; 2738 break; 2739 } 2740 cnt++; 2741 free(currentValue); 2742 currentValue=NULL; 2743 free(finalValue); 2744 } 2745 else{ 2746 currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char)); 2747 sprintf(currentValue,"%s ",cv); 2748 } 2749 else 2750 if(cnt==2){ 2751 addToMap(res,"crs",cv); 2752 cnt++; 2753 } 2754 else 2755 addToMap(res,"dimensions",cv); 2756 icnt++; 2757 cv=strtok_r(NULL,",",&cvp); 2758 } 2759 } 3304 map * 3305 parseBoundingBox (const char *value) 3306 { 3307 map *res = NULL; 3308 if (value != NULL) 3309 { 3310 char *cv, *cvp; 3311 cv = strtok_r ((char *) value, ",", &cvp); 3312 int cnt = 0; 3313 int icnt = 0; 3314 char *currentValue = NULL; 3315 while (cv) 3316 { 3317 if (cnt < 2) 3318 if (currentValue != NULL) 3319 { 3320 char *finalValue = 3321 (char *) malloc ((strlen (currentValue) + strlen (cv) + 1) * 3322 sizeof (char)); 3323 sprintf (finalValue, "%s%s", currentValue, cv); 3324 switch (cnt) 3325 { 3326 case 0: 3327 res = createMap ("lowerCorner", finalValue); 3328 break; 3329 case 1: 3330 addToMap (res, "upperCorner", finalValue); 3331 icnt = -1; 3332 break; 3333 } 3334 cnt++; 3335 free (currentValue); 3336 currentValue = NULL; 3337 free (finalValue); 3338 } 3339 else 3340 { 3341 currentValue = 3342 (char *) malloc ((strlen (cv) + 2) * sizeof (char)); 3343 sprintf (currentValue, "%s ", cv); 3344 } 3345 else if (cnt == 2) 3346 { 3347 addToMap (res, "crs", cv); 3348 cnt++; 3349 } 3350 else 3351 addToMap (res, "dimensions", cv); 3352 icnt++; 3353 cv = strtok_r (NULL, ",", &cvp); 3354 } 3355 } 2760 3356 return res; 2761 3357 } … … 2766 3362 * Lower/UpperCorner nodes to a pre-existing XML node. 2767 3363 */ 2768 void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){ 2769 2770 xmlNodePtr lw=NULL,uc=NULL; 2771 2772 map* tmp=getMap(boundingbox,"value"); 2773 2774 tmp=getMap(boundingbox,"lowerCorner"); 2775 if(tmp!=NULL){ 2776 lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner"); 2777 xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value)); 2778 } 2779 2780 tmp=getMap(boundingbox,"upperCorner"); 2781 if(tmp!=NULL){ 2782 uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner"); 2783 xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value)); 2784 } 2785 2786 tmp=getMap(boundingbox,"crs"); 2787 if(tmp!=NULL) 2788 xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value); 2789 2790 tmp=getMap(boundingbox,"dimensions"); 2791 if(tmp!=NULL) 2792 xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value); 2793 2794 xmlAddChild(n,lw); 2795 xmlAddChild(n,uc); 2796 2797 } 2798 2799 void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){ 2800 if(file==NULL) 2801 rewind(stdout); 3364 void 3365 printBoundingBox (xmlNsPtr ns_ows, xmlNodePtr n, map * boundingbox) 3366 { 3367 3368 xmlNodePtr lw = NULL, uc = NULL; 3369 3370 map *tmp = getMap (boundingbox, "value"); 3371 3372 tmp = getMap (boundingbox, "lowerCorner"); 3373 if (tmp != NULL) 3374 { 3375 lw = xmlNewNode (ns_ows, BAD_CAST "LowerCorner"); 3376 xmlAddChild (lw, xmlNewText (BAD_CAST tmp->value)); 3377 } 3378 3379 tmp = getMap (boundingbox, "upperCorner"); 3380 if (tmp != NULL) 3381 { 3382 uc = xmlNewNode (ns_ows, BAD_CAST "UpperCorner"); 3383 xmlAddChild (uc, xmlNewText (BAD_CAST tmp->value)); 3384 } 3385 3386 tmp = getMap (boundingbox, "crs"); 3387 if (tmp != NULL) 3388 xmlNewProp (n, BAD_CAST "crs", BAD_CAST tmp->value); 3389 3390 tmp = getMap (boundingbox, "dimensions"); 3391 if (tmp != NULL) 3392 xmlNewProp (n, BAD_CAST "dimensions", BAD_CAST tmp->value); 3393 3394 xmlAddChild (n, lw); 3395 xmlAddChild (n, uc); 3396 3397 } 3398 3399 void 3400 printBoundingBoxDocument (maps * m, maps * boundingbox, FILE * file) 3401 { 3402 if (file == NULL) 3403 rewind (stdout); 2802 3404 xmlNodePtr n; 2803 3405 xmlDocPtr doc; 2804 xmlNsPtr ns_ows, ns_xsi;3406 xmlNsPtr ns_ows, ns_xsi; 2805 3407 xmlChar *xmlbuff; 2806 3408 int buffersize; 2807 char *encoding =getEncoding(m);3409 char *encoding = getEncoding (m); 2808 3410 map *tmp; 2809 if(file==NULL){ 2810 int pid=0; 2811 tmp=getMapFromMaps(m,"lenv","sid"); 2812 if(tmp!=NULL) 2813 pid=atoi(tmp->value); 2814 if(pid==getpid()){ 2815 printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding); 2816 } 2817 fflush(stdout); 2818 } 2819 2820 doc = xmlNewDoc(BAD_CAST "1.0"); 2821 int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows"); 2822 ns_ows=usedNs[owsId]; 2823 n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox"); 2824 xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows"); 2825 int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi"); 2826 ns_xsi=usedNs[xsiId]; 2827 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"); 2828 map *tmp1=getMap(boundingbox->content,"value"); 2829 tmp=parseBoundingBox(tmp1->value); 2830 printBoundingBox(ns_ows,n,tmp); 2831 xmlDocSetRootElement(doc, n); 2832 2833 xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1); 2834 if(file==NULL) 2835 printf("%s",xmlbuff); 2836 else{ 2837 fprintf(file,"%s",xmlbuff); 2838 } 2839 2840 if(tmp!=NULL){ 2841 freeMap(&tmp); 2842 free(tmp); 2843 } 2844 xmlFree(xmlbuff); 2845 xmlFreeDoc(doc); 2846 xmlCleanupParser(); 2847 zooXmlCleanupNs(); 2848 2849 } 2850 2851 2852 char* getMd5(char* url){ 3411 if (file == NULL) 3412 { 3413 int pid = 0; 3414 tmp = getMapFromMaps (m, "lenv", "sid"); 3415 if (tmp != NULL) 3416 pid = atoi (tmp->value); 3417 if (pid == getpid ()) 3418 { 3419 printf 3420 ("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n", 3421 encoding); 3422 } 3423 fflush (stdout); 3424 } 3425 3426 doc = xmlNewDoc (BAD_CAST "1.0"); 3427 int owsId = zooXmlAddNs (NULL, "http://www.opengis.net/ows/1.1", "ows"); 3428 ns_ows = usedNs[owsId]; 3429 n = xmlNewNode (ns_ows, BAD_CAST "BoundingBox"); 3430 xmlNewNs (n, BAD_CAST "http://www.opengis.net/ows/1.1", BAD_CAST "ows"); 3431 int xsiId = 3432 zooXmlAddNs (n, "http://www.w3.org/2001/XMLSchema-instance", "xsi"); 3433 ns_xsi = usedNs[xsiId]; 3434 xmlNewNsProp (n, ns_xsi, BAD_CAST "schemaLocation", 3435 BAD_CAST 3436 "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd"); 3437 map *tmp1 = getMap (boundingbox->content, "value"); 3438 tmp = parseBoundingBox (tmp1->value); 3439 printBoundingBox (ns_ows, n, tmp); 3440 xmlDocSetRootElement (doc, n); 3441 3442 xmlDocDumpFormatMemoryEnc (doc, &xmlbuff, &buffersize, encoding, 1); 3443 if (file == NULL) 3444 printf ("%s", xmlbuff); 3445 else 3446 { 3447 fprintf (file, "%s", xmlbuff); 3448 } 3449 3450 if (tmp != NULL) 3451 { 3452 freeMap (&tmp); 3453 free (tmp); 3454 } 3455 xmlFree (xmlbuff); 3456 xmlFreeDoc (doc); 3457 xmlCleanupParser (); 3458 zooXmlCleanupNs (); 3459 3460 } 3461 3462 3463 char * 3464 getMd5 (char *url) 3465 { 2853 3466 EVP_MD_CTX md5ctx; 2854 char * fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char));3467 char *fresult = (char *) malloc ((EVP_MAX_MD_SIZE + 1) * sizeof (char)); 2855 3468 unsigned char result[EVP_MAX_MD_SIZE]; 2856 3469 unsigned int len; 2857 EVP_DigestInit (&md5ctx, EVP_md5());2858 EVP_DigestUpdate (&md5ctx, url, strlen(url));2859 EVP_DigestFinal_ex (&md5ctx,result,&len);2860 EVP_MD_CTX_cleanup (&md5ctx);3470 EVP_DigestInit (&md5ctx, EVP_md5 ()); 3471 EVP_DigestUpdate (&md5ctx, url, strlen (url)); 3472 EVP_DigestFinal_ex (&md5ctx, result, &len); 3473 EVP_MD_CTX_cleanup (&md5ctx); 2861 3474 int i; 2862 for(i = 0; i < len; i++){ 2863 if(i>0){ 2864 char *tmp=strdup(fresult); 2865 sprintf(fresult,"%s%02x", tmp,result[i]); 2866 free(tmp); 2867 } 2868 else 2869 sprintf(fresult,"%02x",result[i]); 2870 } 3475 for (i = 0; i < len; i++) 3476 { 3477 if (i > 0) 3478 { 3479 char *tmp = strdup (fresult); 3480 sprintf (fresult, "%s%02x", tmp, result[i]); 3481 free (tmp); 3482 } 3483 else 3484 sprintf (fresult, "%02x", result[i]); 3485 } 2871 3486 return fresult; 2872 3487 } … … 2875 3490 * Cache a file for a given request 2876 3491 */ 2877 void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){ 2878 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 2879 if(tmp!=NULL){ 2880 char* md5str=getMd5(request); 2881 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 2882 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 3492 void 3493 addToCache (maps * conf, char *request, char *content, char *mimeType, 3494 int length) 3495 { 3496 map *tmp = getMapFromMaps (conf, "main", "cacheDir"); 3497 if (tmp != NULL) 3498 { 3499 char *md5str = getMd5 (request); 3500 char *fname = 3501 (char *) malloc (sizeof (char) * 3502 (strlen (tmp->value) + strlen (md5str) + 6)); 3503 sprintf (fname, "%s/%s.zca", tmp->value, md5str); 2883 3504 #ifdef DEBUG 2884 fprintf(stderr,"Cache list : %s\n",fname); 2885 fflush(stderr); 2886 #endif 2887 FILE* fo=fopen(fname,"w+"); 2888 if(fo==NULL){ 2889 fprintf (stderr, "Failed to open %s for writting: %s\n",fname, strerror(errno)); 2890 return; 2891 } 2892 fwrite(content,sizeof(char),length,fo); 2893 fclose(fo); 2894 2895 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 2896 fo=fopen(fname,"w+"); 3505 fprintf (stderr, "Cache list : %s\n", fname); 3506 fflush (stderr); 3507 #endif 3508 FILE *fo = fopen (fname, "w+"); 3509 if (fo == NULL) 3510 { 3511 fprintf (stderr, "Failed to open %s for writting: %s\n", fname, 3512 strerror (errno)); 3513 return; 3514 } 3515 fwrite (content, sizeof (char), length, fo); 3516 fclose (fo); 3517 3518 sprintf (fname, "%s/%s.zcm", tmp->value, md5str); 3519 fo = fopen (fname, "w+"); 2897 3520 #ifdef DEBUG 2898 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 2899 #endif 2900 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 2901 fclose(fo); 2902 2903 free(md5str); 2904 free(fname); 2905 } 2906 } 2907 2908 char* isInCache(maps* conf,char* request){ 2909 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 2910 if(tmpM!=NULL){ 2911 char* md5str=getMd5(request); 3521 fprintf (stderr, "MIMETYPE: %s\n", mimeType); 3522 #endif 3523 fwrite (mimeType, sizeof (char), strlen (mimeType), fo); 3524 fclose (fo); 3525 3526 free (md5str); 3527 free (fname); 3528 } 3529 } 3530 3531 char * 3532 isInCache (maps * conf, char *request) 3533 { 3534 map *tmpM = getMapFromMaps (conf, "main", "cacheDir"); 3535 if (tmpM != NULL) 3536 { 3537 char *md5str = getMd5 (request); 2912 3538 #ifdef DEBUG 2913 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 2914 #endif 2915 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6)); 2916 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 2917 struct stat f_status; 2918 int s=stat(fname, &f_status); 2919 if(s==0 && f_status.st_size>0){ 2920 free(md5str); 2921 return fname; 2922 } 2923 free(md5str); 2924 free(fname); 2925 } 3539 fprintf (stderr, "MD5STR : (%s)\n\n", md5str); 3540 #endif 3541 char *fname = 3542 (char *) malloc (sizeof (char) * 3543 (strlen (tmpM->value) + strlen (md5str) + 6)); 3544 sprintf (fname, "%s/%s.zca", tmpM->value, md5str); 3545 struct stat f_status; 3546 int s = stat (fname, &f_status); 3547 if (s == 0 && f_status.st_size > 0) 3548 { 3549 free (md5str); 3550 return fname; 3551 } 3552 free (md5str); 3553 free (fname); 3554 }