- 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 } 2926 3555 return NULL; 2927 3556 } 2928 3557 2929 int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){ 2930 if(hInternet->nb>0){ 2931 processDownloads(hInternet); 2932 maps* content=*inputs; 2933 map* tmp1; 2934 int index=0; 2935 while(content!=NULL){ 2936 if((tmp1=getMap(content->content,"href")) || 2937 (tmp1=getMap(content->content,"xlink:href"))){ 2938 if(getMap(content->content,"isCached")==NULL){ 2939 char* fcontent; 2940 char *mimeType=NULL; 2941 int fsize=0; 2942 2943 fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char)); 2944 if(fcontent == NULL){ 2945 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 2946 } 2947 size_t dwRead; 2948 InternetReadFile(hInternet->ihandle[index], 2949 (LPVOID)fcontent, 2950 hInternet->ihandle[index].nDataLen, 2951 &dwRead); 2952 fcontent[hInternet->ihandle[index].nDataLen]=0; 2953 fsize=hInternet->ihandle[index].nDataLen; 2954 mimeType=strdup((char*)hInternet->ihandle[index].mimeType); 2955 2956 map* tmpMap=getMapOrFill(&content->content,"value",""); 2957 free(tmpMap->value); 2958 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 2959 if(tmpMap->value==NULL){ 2960 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 2961 } 2962 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 2963 2964 char ltmp1[256]; 2965 sprintf(ltmp1,"%d",fsize); 2966 addToMap(content->content,"size",ltmp1); 2967 addToCache(*m,tmp1->value,fcontent,mimeType,fsize); 2968 free(fcontent); 2969 free(mimeType); 2970 } 2971 index++; 2972 } 2973 content=content->next; 2974 } 2975 } 3558 int 3559 runHttpRequests (maps ** m, maps ** inputs, HINTERNET * hInternet) 3560 { 3561 if (hInternet->nb > 0) 3562 { 3563 processDownloads (hInternet); 3564 maps *content = *inputs; 3565 map *tmp1; 3566 int index = 0; 3567 while (content != NULL) 3568 { 3569 if ((tmp1 = getMap (content->content, "href")) || 3570 (tmp1 = getMap (content->content, "xlink:href"))) 3571 { 3572 if (getMap (content->content, "isCached") == NULL) 3573 { 3574 char *fcontent; 3575 char *mimeType = NULL; 3576 int fsize = 0; 3577 3578 fcontent = 3579 (char *) malloc ((hInternet->ihandle[index].nDataLen + 1) 3580 * sizeof (char)); 3581 if (fcontent == NULL) 3582 { 3583 return errorException (*m, 3584 _("Unable to allocate memory."), 3585 "InternalError", NULL); 3586 } 3587 size_t dwRead; 3588 InternetReadFile (hInternet->ihandle[index], 3589 (LPVOID) fcontent, 3590 hInternet->ihandle[index].nDataLen, 3591 &dwRead); 3592 fcontent[hInternet->ihandle[index].nDataLen] = 0; 3593 fsize = hInternet->ihandle[index].nDataLen; 3594 mimeType = 3595 strdup ((char *) hInternet->ihandle[index].mimeType); 3596 3597 map *tmpMap = getMapOrFill (&content->content, "value", ""); 3598 free (tmpMap->value); 3599 tmpMap->value = 3600 (char *) malloc ((fsize + 1) * sizeof (char)); 3601 if (tmpMap->value == NULL) 3602 { 3603 return errorException (*m, 3604 _("Unable to allocate memory."), 3605 "InternalError", NULL); 3606 } 3607 memcpy (tmpMap->value, fcontent, 3608 (fsize + 1) * sizeof (char)); 3609 3610 char ltmp1[256]; 3611 sprintf (ltmp1, "%d", fsize); 3612 addToMap (content->content, "size", ltmp1); 3613 addToCache (*m, tmp1->value, fcontent, mimeType, fsize); 3614 free (fcontent); 3615 free (mimeType); 3616 } 3617 index++; 3618 } 3619 content = content->next; 3620 } 3621 } 2976 3622 } 2977 3623 … … 2980 3626 * Try to load file from cache or download a remote file if not in cache 2981 3627 */ 2982 int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){ 2983 char* fcontent; 2984 char* cached=isInCache(*m,url); 2985 char *mimeType=NULL; 2986 int fsize=0; 2987 if(cached!=NULL){ 2988 struct stat f_status; 2989 int s=stat(cached, &f_status); 2990 if(s==0){ 2991 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 2992 FILE* f=fopen(cached,"rb"); 2993 fread(fcontent,f_status.st_size,1,f); 2994 fsize=f_status.st_size; 2995 fcontent[fsize]=0; 2996 fclose(f); 2997 } 2998 cached[strlen(cached)-1]='m'; 2999 s=stat(cached, &f_status); 3000 if(s==0){ 3001 mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 3002 FILE* f=fopen(cached,"rb"); 3003 fread(mimeType,f_status.st_size,1,f); 3004 mimeType[f_status.st_size]=0; 3005 fclose(f); 3006 } 3007 }else{ 3008 hInternet->waitingRequests[hInternet->nb]=strdup(url); 3009 InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0); 3010 return 0; 3011 } 3012 if(fsize==0){ 3013 return errorException(*m, _("Unable to download the file."), "InternalError",NULL); 3014 } 3015 if(mimeType!=NULL){ 3016 addToMap(*content,"fmimeType",mimeType); 3017 } 3018 3019 map* tmpMap=getMapOrFill(content,"value",""); 3020 3021 free(tmpMap->value); 3022 tmpMap->value=(char*)malloc((fsize+1)*sizeof(char)); 3023 if(tmpMap->value==NULL) 3024 return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL); 3025 memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char)); 3026 3628 int 3629 loadRemoteFile (maps ** m, map ** content, HINTERNET * hInternet, char *url) 3630 { 3631 char *fcontent; 3632 char *cached = isInCache (*m, url); 3633 char *mimeType = NULL; 3634 int fsize = 0; 3635 if (cached != NULL) 3636 { 3637 struct stat f_status; 3638 int s = stat (cached, &f_status); 3639 if (s == 0) 3640 { 3641 fcontent = (char *) malloc (sizeof (char) * (f_status.st_size + 1)); 3642 FILE *f = fopen (cached, "rb"); 3643 fread (fcontent, f_status.st_size, 1, f); 3644 fsize = f_status.st_size; 3645 fcontent[fsize] = 0; 3646 fclose (f); 3647 } 3648 cached[strlen (cached) - 1] = 'm'; 3649 s = stat (cached, &f_status); 3650 if (s == 0) 3651 { 3652 mimeType = (char *) malloc (sizeof (char) * (f_status.st_size + 1)); 3653 FILE *f = fopen (cached, "rb"); 3654 fread (mimeType, f_status.st_size, 1, f); 3655 mimeType[f_status.st_size] = 0; 3656 fclose (f); 3657 } 3658 } 3659 else 3660 { 3661 hInternet->waitingRequests[hInternet->nb] = strdup (url); 3662 InternetOpenUrl (hInternet, hInternet->waitingRequests[hInternet->nb], 3663 NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0); 3664 return 0; 3665 } 3666 if (fsize == 0) 3667 { 3668 return errorException (*m, _("Unable to download the file."), 3669 "InternalError", NULL); 3670 } 3671 if (mimeType != NULL) 3672 { 3673 addToMap (*content, "fmimeType", mimeType); 3674 } 3675 3676 map *tmpMap = getMapOrFill (content, "value", ""); 3677 3678 free (tmpMap->value); 3679 tmpMap->value = (char *) malloc ((fsize + 1) * sizeof (char)); 3680 if (tmpMap->value == NULL) 3681 return errorException (*m, _("Unable to allocate memory."), 3682 "InternalError", NULL); 3683 memcpy (tmpMap->value, fcontent, (fsize + 1) * sizeof (char)); 3684 3027 3685 char ltmp1[256]; 3028 sprintf (ltmp1,"%d",fsize);3029 addToMap (*content,"size",ltmp1);3030 if (cached==NULL)3031 addToCache (*m,url,fcontent,mimeType,fsize);3686 sprintf (ltmp1, "%d", fsize); 3687 addToMap (*content, "size", ltmp1); 3688 if (cached == NULL) 3689 addToCache (*m, url, fcontent, mimeType, fsize); 3032 3690 else 3033 addToMap (*content,"isCached","true");3034 free (fcontent);3035 free (mimeType);3036 free (cached);3691 addToMap (*content, "isCached", "true"); 3692 free (fcontent); 3693 free (mimeType); 3694 free (cached); 3037 3695 return 0; 3038 3696 } 3039 3697 3040 int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 3041 { 3042 map* errormap = createMap("text", message); 3043 addToMap(errormap,"code", errorcode); 3044 if(locator!=NULL) 3045 addToMap(errormap,"locator", locator); 3698 int 3699 errorException (maps * m, const char *message, const char *errorcode, 3700 const char *locator) 3701 { 3702 map *errormap = createMap ("text", message); 3703 addToMap (errormap, "code", errorcode); 3704 if (locator != NULL) 3705 addToMap (errormap, "locator", locator); 3046 3706 else 3047 addToMap (errormap,"locator", "NULL");3048 printExceptionReportResponse (m,errormap);3049 freeMap (&errormap);3050 free (errormap);3707 addToMap (errormap, "locator", "NULL"); 3708 printExceptionReportResponse (m, errormap); 3709 freeMap (&errormap); 3710 free (errormap); 3051 3711 return -1; 3052 3712 } 3053 3713 3054 3714 3055 char *readVSIFile(maps* conf,const char* dataSource){ 3056 VSILFILE * fichier=VSIFOpenL(dataSource,"rb"); 3057 VSIStatBufL file_status; 3058 VSIStatL(dataSource, &file_status); 3059 if(fichier==NULL){ 3715 char * 3716 readVSIFile (maps * conf, const char *dataSource) 3717 { 3718 VSILFILE *fichier = VSIFOpenL (dataSource, "rb"); 3719 VSIStatBufL file_status; 3720 VSIStatL (dataSource, &file_status); 3721 if (fichier == NULL) 3722 { 3060 3723 char tmp[1024]; 3061 sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %d.", 3062 dataSource,file_status.st_size); 3063 setMapInMaps(conf,"lenv","message",tmp); 3724 sprintf (tmp, 3725 "Failed to open file %s for reading purpose. File seems empty %d.", 3726 dataSource, file_status.st_size); 3727 setMapInMaps (conf, "lenv", "message", tmp); 3064 3728 return NULL; 3065 3729 } 3066 char *res1=(char *)malloc(file_status.st_size*sizeof(char)); 3067 VSIFReadL(res1,1,file_status.st_size*sizeof(char),fichier); 3068 res1[file_status.st_size-1]=0; 3069 VSIFCloseL(fichier); 3070 VSIUnlink(dataSource); 3071 return res1; 3072 } 3073 3074 void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){ 3730 char *res1 = (char *) malloc (file_status.st_size * sizeof (char)); 3731 VSIFReadL (res1, 1, file_status.st_size * sizeof (char), fichier); 3732 res1[file_status.st_size - 1] = 0; 3733 VSIFCloseL (fichier); 3734 VSIUnlink (dataSource); 3735 return res1; 3736 } 3737 3738 void 3739 parseIdentifier (maps * conf, char *conf_dir, char *identifier, char *buffer) 3740 { 3075 3741 char *saveptr1; 3076 char *tmps1 =strtok_r(identifier,".",&saveptr1);3077 int level =0;3742 char *tmps1 = strtok_r (identifier, ".", &saveptr1); 3743 int level = 0; 3078 3744 char key[25]; 3079 3745 char levels[18]; 3080 while(tmps1!=NULL){ 3081 char *test=zStrdup(tmps1); 3082 char* tmps2=(char*)malloc((strlen(test)+2)*sizeof(char)); 3083 sprintf(key,"sprefix_%d",level); 3084 sprintf(tmps2,"%s.",test); 3085 sprintf(levels,"%d",level); 3086 setMapInMaps(conf,"lenv","level",levels); 3087 setMapInMaps(conf,"lenv",key,tmps2); 3088 free(tmps2); 3089 free(test); 3090 level++; 3091 tmps1=strtok_r(NULL,".",&saveptr1); 3092 } 3093 int i=0; 3094 sprintf(buffer,"%s",conf_dir); 3095 for(i=0;i<level;i++){ 3096 char *tmp0=zStrdup(buffer); 3097 sprintf(key,"sprefix_%d",i); 3098 map* tmp00=getMapFromMaps(conf,"lenv",key); 3099 if(tmp00!=NULL) 3100 sprintf(buffer,"%s/%s",tmp0,tmp00->value); 3101 free(tmp0); 3102 buffer[strlen(buffer)-1]=0; 3103 if(i+1<level){ 3104 map* tmpMap=getMapFromMaps(conf,"lenv","metapath"); 3105 if(tmpMap==NULL || strlen(tmpMap->value)==0){ 3106 char *tmp01=zStrdup(tmp00->value); 3107 tmp01[strlen(tmp01)-1]=0; 3108 setMapInMaps(conf,"lenv","metapath",tmp01); 3109 free(tmp01); 3110 tmp01=NULL; 3111 } 3112 else{ 3113 if(tmp00!=NULL && tmpMap!=NULL){ 3114 char *tmp00s=zStrdup(tmp00->value); 3115 tmp00s[strlen(tmp00s)-1]=0; 3116 char *value=(char*)malloc((strlen(tmp00s)+strlen(tmpMap->value)+2)*sizeof(char)); 3117 sprintf(value,"%s/%s",tmpMap->value,tmp00s); 3118 setMapInMaps(conf,"lenv","metapath",value); 3119 free(value); 3120 free(tmp00s); 3121 value=NULL; 3122 } 3123 } 3124 }else{ 3125 char *tmp01=zStrdup(tmp00->value); 3126 tmp01[strlen(tmp01)-1]=0; 3127 setMapInMaps(conf,"lenv","Identifier",tmp01); 3128 free(tmp01); 3129 } 3130 } 3131 char *tmp0=zStrdup(buffer); 3132 sprintf(buffer,"%s.zcfg",tmp0); 3133 free(tmp0); 3134 } 3135 3136 int updateStatus( maps* conf, const int percentCompleted, const char* message ){ 3746 while (tmps1 != NULL) 3747 { 3748 char *test = zStrdup (tmps1); 3749 char *tmps2 = (char *) malloc ((strlen (test) + 2) * sizeof (char)); 3750 sprintf (key, "sprefix_%d", level); 3751 sprintf (tmps2, "%s.", test); 3752 sprintf (levels, "%d", level); 3753 setMapInMaps (conf, "lenv", "level", levels); 3754 setMapInMaps (conf, "lenv", key, tmps2); 3755 free (tmps2); 3756 free (test); 3757 level++; 3758 tmps1 = strtok_r (NULL, ".", &saveptr1); 3759 } 3760 int i = 0; 3761 sprintf (buffer, "%s", conf_dir); 3762 for (i = 0; i < level; i++) 3763 { 3764 char *tmp0 = zStrdup (buffer); 3765 sprintf (key, "sprefix_%d", i); 3766 map *tmp00 = getMapFromMaps (conf, "lenv", key); 3767 if (tmp00 != NULL) 3768 sprintf (buffer, "%s/%s", tmp0, tmp00->value); 3769 free (tmp0); 3770 buffer[strlen (buffer) - 1] = 0; 3771 if (i + 1 < level) 3772 { 3773 map *tmpMap = getMapFromMaps (conf, "lenv", "metapath"); 3774 if (tmpMap == NULL || strlen (tmpMap->value) == 0) 3775 { 3776 char *tmp01 = zStrdup (tmp00->value); 3777 tmp01[strlen (tmp01) - 1] = 0; 3778 setMapInMaps (conf, "lenv", "metapath", tmp01); 3779 free (tmp01); 3780 tmp01 = NULL; 3781 } 3782 else 3783 { 3784 if (tmp00 != NULL && tmpMap != NULL) 3785 { 3786 char *tmp00s = zStrdup (tmp00->value); 3787 tmp00s[strlen (tmp00s) - 1] = 0; 3788 char *value = 3789 (char *) 3790 malloc ((strlen (tmp00s) + strlen (tmpMap->value) + 3791 2) * sizeof (char)); 3792 sprintf (value, "%s/%s", tmpMap->value, tmp00s); 3793 setMapInMaps (conf, "lenv", "metapath", value); 3794 free (value); 3795 free (tmp00s); 3796 value = NULL; 3797 } 3798 } 3799 } 3800 else 3801 { 3802 char *tmp01 = zStrdup (tmp00->value); 3803 tmp01[strlen (tmp01) - 1] = 0; 3804 setMapInMaps (conf, "lenv", "Identifier", tmp01); 3805 free (tmp01); 3806 } 3807 } 3808 char *tmp0 = zStrdup (buffer); 3809 sprintf (buffer, "%s.zcfg", tmp0); 3810 free (tmp0); 3811 } 3812 3813 int 3814 updateStatus (maps * conf, const int percentCompleted, const char *message) 3815 { 3137 3816 char tmp[4]; 3138 snprintf(tmp,4,"%d",percentCompleted); 3139 setMapInMaps( conf, "lenv", "status", tmp ); 3140 setMapInMaps( conf, "lenv", "message", message); 3141 return _updateStatus( conf ); 3142 } 3143 3144 char* getInputValue( maps* inputs, const char* parameterName, size_t* numberOfBytes){ 3145 map* res=getMapFromMaps(inputs,parameterName,"value"); 3146 if(res!=NULL){ 3147 map* size=getMapFromMaps(inputs,parameterName,"size"); 3148 if(size!=NULL){ 3149 *numberOfBytes=(size_t)atoi(size->value); 3150 return res->value; 3151 }else{ 3152 *numberOfBytes=strlen(res->value); 3153 return res->value; 3154 } 3155 } 3817 snprintf (tmp, 4, "%d", percentCompleted); 3818 setMapInMaps (conf, "lenv", "status", tmp); 3819 setMapInMaps (conf, "lenv", "message", message); 3820 return _updateStatus (conf); 3821 } 3822 3823 char * 3824 getInputValue (maps * inputs, const char *parameterName, 3825 size_t * numberOfBytes) 3826 { 3827 map *res = getMapFromMaps (inputs, parameterName, "value"); 3828 if (res != NULL) 3829 { 3830 map *size = getMapFromMaps (inputs, parameterName, "size"); 3831 if (size != NULL) 3832 { 3833 *numberOfBytes = (size_t) atoi (size->value); 3834 return res->value; 3835 } 3836 else 3837 { 3838 *numberOfBytes = strlen (res->value); 3839 return res->value; 3840 } 3841 } 3156 3842 return NULL; 3157 3843 } 3158 3844 3159 int setOutputValue( maps* outputs, const char* parameterName, char* data, size_t numberOfBytes ){ 3160 if(numberOfBytes==-1){ 3161 setMapInMaps(outputs,parameterName,"value",data); 3162 }else{ 3163 char size[1024]; 3164 map* tmp=getMapFromMaps(outputs,parameterName,"value"); 3165 free(tmp->value); 3166 tmp->value=(char*) malloc((numberOfBytes+1)*sizeof(char)); 3167 memcpy(tmp->value,data,numberOfBytes); 3168 sprintf(size,"%lu",numberOfBytes); 3169 setMapInMaps(outputs,parameterName,"size",size); 3170 } 3845 int 3846 setOutputValue (maps * outputs, const char *parameterName, char *data, 3847 size_t numberOfBytes) 3848 { 3849 if (numberOfBytes == -1) 3850 { 3851 setMapInMaps (outputs, parameterName, "value", data); 3852 } 3853 else 3854 { 3855 char size[1024]; 3856 map *tmp = getMapFromMaps (outputs, parameterName, "value"); 3857 free (tmp->value); 3858 tmp->value = (char *) malloc ((numberOfBytes + 1) * sizeof (char)); 3859 memcpy (tmp->value, data, numberOfBytes); 3860 sprintf (size, "%lu", numberOfBytes); 3861 setMapInMaps (outputs, parameterName, "size", size); 3862 } 3171 3863 return 0; 3172 3864 } -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal_js.c
r505 r531 32 32 33 33 JSBool 34 JSAlert(JSContext *cx, uintN argc, jsval *argv1) 35 { 36 jsval *argv = JS_ARGV(cx,argv1); 37 int i=0; 38 JS_MaybeGC(cx); 39 for(i=0;i<argc;i++){ 40 JSString* jsmsg = JS_ValueToString(cx,argv[i]); 41 char *tmp=JS_EncodeString(cx,jsmsg); 42 fprintf(stderr,"[ZOO-API:JS] %s\n",tmp); 43 free(tmp); 44 } 45 JS_MaybeGC(cx); 46 34 JSAlert (JSContext * cx, uintN argc, jsval * argv1) 35 { 36 jsval *argv = JS_ARGV (cx, argv1); 37 int i = 0; 38 JS_MaybeGC (cx); 39 for (i = 0; i < argc; i++) 40 { 41 JSString *jsmsg = JS_ValueToString (cx, argv[i]); 42 char *tmp = JS_EncodeString (cx, jsmsg); 43 fprintf (stderr, "[ZOO-API:JS] %s\n", tmp); 44 free (tmp); 45 } 46 JS_MaybeGC (cx); 47 47 48 return JS_TRUE; 48 49 } 49 50 50 JSBool 51 JSLoadScripts (JSContext *cx, uintN argc, jsval *argv1)51 JSBool 52 JSLoadScripts (JSContext * cx, uintN argc, jsval * argv1) 52 53 { 53 54 //map* request = JS_GetContextPrivate(cx); 54 55 //map* tmpm1=getMap(request,"metapath"); 55 JS_MaybeGC (cx);56 JS_MaybeGC (cx); 56 57 57 58 char ntmp[1024]; 58 getcwd(ntmp,1024); 59 60 jsval *argv = JS_ARGV(cx,argv1); 61 int i=0; 62 JS_MaybeGC(cx); 63 for(i=0;i<argc;i++){ 64 JSString* jsmsg = JS_ValueToString(cx,argv[i]); 65 char *filename = JSValToChar(cx,&argv[i]); 66 char *api0=(char*)malloc((strlen(ntmp)+strlen(filename)+2)*sizeof(char)); 67 sprintf(api0,"%s/%s",ntmp,filename); 68 #ifdef JS_DEBUG 69 fprintf(stderr,"Trying to load %s\n",api0); 70 fflush(stderr); 71 #endif 72 JSObject *api_script1=loadZooApiFile(cx,JS_GetGlobalObject(cx),api0); 73 free(api0); 74 } 75 JS_MaybeGC(cx); 76 JS_SET_RVAL(cx, argv1, JSVAL_VOID); 77 59 getcwd (ntmp, 1024); 60 61 jsval *argv = JS_ARGV (cx, argv1); 62 int i = 0; 63 JS_MaybeGC (cx); 64 for (i = 0; i < argc; i++) 65 { 66 JSString *jsmsg = JS_ValueToString (cx, argv[i]); 67 char *filename = JSValToChar (cx, &argv[i]); 68 char *api0 = 69 (char *) malloc ((strlen (ntmp) + strlen (filename) + 2) * 70 sizeof (char)); 71 sprintf (api0, "%s/%s", ntmp, filename); 72 #ifdef JS_DEBUG 73 fprintf (stderr, "Trying to load %s\n", api0); 74 fflush (stderr); 75 #endif 76 JSObject *api_script1 = 77 loadZooApiFile (cx, JS_GetGlobalObject (cx), api0); 78 free (api0); 79 } 80 JS_MaybeGC (cx); 81 JS_SET_RVAL (cx, argv1, JSVAL_VOID); 82 78 83 return JS_TRUE; 79 84 } 80 85 81 86 82 int zoo_js_support(maps** main_conf,map* request,service* s, 83 maps **inputs,maps **outputs) 84 { 85 maps* main=*main_conf; 86 maps* _inputs=*inputs; 87 maps* _outputs=*outputs; 87 int 88 zoo_js_support (maps ** main_conf, map * request, service * s, 89 maps ** inputs, maps ** outputs) 90 { 91 maps *main = *main_conf; 92 maps *_inputs = *inputs; 93 maps *_outputs = *outputs; 88 94 89 95 /* The class of the global object. */ 90 JSClass global_class = {96 JSClass global_class = { 91 97 "global", JSCLASS_GLOBAL_FLAGS, 92 98 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, … … 98 104 JSRuntime *rt; 99 105 JSContext *cx; 100 JSObject 106 JSObject *global; 101 107 102 108 /* Create a JS runtime. */ 103 rt = JS_NewRuntime (8L * 1024L * 1024L);109 rt = JS_NewRuntime (8L * 1024L * 1024L); 104 110 if (rt == NULL) 105 111 return 1; 106 112 107 113 /* Create a context. */ 108 cx = JS_NewContext(rt,8192); 109 if (cx == NULL){ 110 return 1; 111 } 112 JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 113 JS_SetVersion(cx, JSVERSION_LATEST); 114 JS_SetErrorReporter(cx, reportError); 114 cx = JS_NewContext (rt, 8192); 115 if (cx == NULL) 116 { 117 return 1; 118 } 119 JS_SetOptions (cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); 120 JS_SetVersion (cx, JSVERSION_LATEST); 121 JS_SetErrorReporter (cx, reportError); 115 122 116 123 /* Create the global object. */ 117 global = JS_NewCompartmentAndGlobalObject (cx, &global_class, NULL);124 global = JS_NewCompartmentAndGlobalObject (cx, &global_class, NULL); 118 125 119 126 /* Populate the global object with the standard globals, 120 127 like Object and Array. */ 121 if (!JS_InitStandardClasses(cx, global)){ 122 return 1; 123 } 128 if (!JS_InitStandardClasses (cx, global)) 129 { 130 return 1; 131 } 124 132 125 133 /* Define specific function and global variable to share with JS runtime 126 134 */ 127 jsval tmp=INT_TO_JSVAL(3); 128 if (!JS_SetProperty(cx, global, "SERVICE_SUCCEEDED", &tmp)) 129 return 1; 130 tmp=INT_TO_JSVAL(4); 131 if (!JS_SetProperty(cx, global, "SERVICE_FAILED", &tmp)) 132 return 1; 133 if (!JS_DefineFunction(cx, global, "ZOORequest", JSRequest, 4, 0)) 134 return 1; 135 if (!JS_DefineFunction(cx, global, "ZOOTranslate", JSTranslate, 4, 0)) 136 return 1; 137 if (!JS_DefineFunction(cx, global, "ZOOUpdateStatus", JSUpdateStatus, 2, 0)) 138 return 1; 139 if (!JS_DefineFunction(cx, global, "alert", JSAlert, 2, 0)) 140 return 1; 141 if (!JS_DefineFunction(cx, global, "importScripts", JSLoadScripts, 1, 0)) 142 return 1; 135 jsval tmp = INT_TO_JSVAL (3); 136 if (!JS_SetProperty (cx, global, "SERVICE_SUCCEEDED", &tmp)) 137 return 1; 138 tmp = INT_TO_JSVAL (4); 139 if (!JS_SetProperty (cx, global, "SERVICE_FAILED", &tmp)) 140 return 1; 141 if (!JS_DefineFunction (cx, global, "ZOORequest", JSRequest, 4, 0)) 142 return 1; 143 if (!JS_DefineFunction (cx, global, "ZOOTranslate", JSTranslate, 4, 0)) 144 return 1; 145 if (!JS_DefineFunction 146 (cx, global, "ZOOUpdateStatus", JSUpdateStatus, 2, 0)) 147 return 1; 148 if (!JS_DefineFunction (cx, global, "alert", JSAlert, 2, 0)) 149 return 1; 150 if (!JS_DefineFunction (cx, global, "importScripts", JSLoadScripts, 1, 0)) 151 return 1; 143 152 144 153 /** 145 154 * Add private context object 146 155 */ 147 void* cxPrivate = request; 148 JS_SetContextPrivate(cx,cxPrivate); 149 150 map* tmpm1=getMap(request,"metapath"); 156 void *cxPrivate = request; 157 JS_SetContextPrivate (cx, cxPrivate); 158 151 159 char ntmp[1024]; 152 getcwd (ntmp,1024);160 getcwd (ntmp, 1024); 153 161 154 162 /** 155 163 * Load the first part of the ZOO-API 156 164 */ 157 char *api0 =(char*)malloc((strlen(ntmp)+17)*sizeof(char));158 sprintf (api0,"%s/ZOO-proj4js.js",ntmp);159 #ifdef JS_DEBUG 160 fprintf (stderr,"Trying to load %s\n",api0);161 #endif 162 JSObject *api_script1 =loadZooApiFile(cx,global,api0);163 free (api0);164 fflush (stderr);165 166 char *api1 =(char*)malloc((strlen(ntmp)+13)*sizeof(char));167 sprintf (api1,"%s/ZOO-api.js",ntmp);168 #ifdef JS_DEBUG 169 fprintf (stderr,"Trying to load %s\n",api1);170 #endif 171 JSObject *api_script2 =loadZooApiFile(cx,global,api1);172 free (api1);173 fflush (stderr);165 char *api0 = (char *) malloc ((strlen (ntmp) + 17) * sizeof (char)); 166 sprintf (api0, "%s/ZOO-proj4js.js", ntmp); 167 #ifdef JS_DEBUG 168 fprintf (stderr, "Trying to load %s\n", api0); 169 #endif 170 JSObject *api_script1 = loadZooApiFile (cx, global, api0); 171 free (api0); 172 fflush (stderr); 173 174 char *api1 = (char *) malloc ((strlen (ntmp) + 13) * sizeof (char)); 175 sprintf (api1, "%s/ZOO-api.js", ntmp); 176 #ifdef JS_DEBUG 177 fprintf (stderr, "Trying to load %s\n", api1); 178 #endif 179 JSObject *api_script2 = loadZooApiFile (cx, global, api1); 180 free (api1); 181 fflush (stderr); 174 182 175 183 /* Your application code here. This may include JSAPI calls 176 184 to create your own custom JS objects and run scripts. */ 177 maps* out=*outputs; 178 int res=SERVICE_FAILED; 179 maps* mc=*main_conf; 180 map* tmpm2=getMap(s->content,"serviceProvider"); 181 182 char *filename=(char*)malloc(strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+3); 183 sprintf(filename,"%s/%s/%s",ntmp,tmpm1->value,tmpm2->value); 184 filename[strlen(tmpm1->value)+strlen(tmpm2->value)+strlen(ntmp)+2]=0; 185 #ifdef JS_DEBUG 186 fprintf(stderr,"FILENAME %s\n",filename); 185 maps *out = *outputs; 186 int res = SERVICE_FAILED; 187 maps *mc = *main_conf; 188 map *tmpm2 = getMap (s->content, "serviceProvider"); 189 char *tmp_path = (char *) malloc ((strlen (s->zcfg) + 1) * sizeof (char *)); 190 sprintf (tmp_path, "%s", s->zcfg); 191 char *dir = dirname (tmp_path); 192 char *filename = 193 (char *) malloc ((strlen (dir) + strlen (tmpm2->value) + 2) * 194 sizeof (char *)); 195 sprintf (filename, "%s/%s", dir, tmpm2->value); 196 free (tmp_path); 197 #ifdef JS_DEBUG 198 fprintf (stderr, "FILENAME %s\n", filename); 187 199 #endif 188 200 struct stat file_status; 189 stat (filename, &file_status);201 stat (filename, &file_status); 190 202 //char *source=(char*)malloc(file_status.st_size); 191 203 uint16 lineno; 192 204 jsval rval; 193 JSBool ok ; 194 JSObject *script = JS_CompileFile(cx, global, filename); 195 if(script!=NULL){ 196 (void)JS_ExecuteScript(cx, global, script, &rval); 197 } 198 else{ 199 char tmp1[1024]; 200 sprintf(tmp1,"Unable to load JavaScript file %s",filename); 201 free(filename); 202 map* err=createMap("text",tmp1); 203 addToMap(err,"code","NoApplicableCode"); 204 printExceptionReportResponse(mc,err); 205 freeMap(&err); 206 free(err); 207 JS_MaybeGC(cx); 208 JS_DestroyContext(cx); 209 JS_DestroyRuntime(rt); 210 JS_ShutDown(); 211 return -1; 212 } 213 205 JSBool ok; 206 JSObject *script = JS_CompileFile (cx, global, filename); 207 if (script != NULL) 208 { 209 (void) JS_ExecuteScript (cx, global, script, &rval); 210 } 211 else 212 { 213 char tmp1[1024]; 214 sprintf (tmp1, "Unable to load JavaScript file %s", filename); 215 free (filename); 216 map *err = createMap ("text", tmp1); 217 addToMap (err, "code", "NoApplicableCode"); 218 printExceptionReportResponse (mc, err); 219 freeMap (&err); 220 free (err); 221 JS_MaybeGC (cx); 222 JS_DestroyContext (cx); 223 JS_DestroyRuntime (rt); 224 JS_ShutDown (); 225 return -1; 226 } 227 214 228 215 229 /* Call a function in obj's scope. */ 216 230 jsval argv[3]; 217 JSObject *jsargv1 =JSObject_FromMaps(cx,*main_conf);218 argv[0] = OBJECT_TO_JSVAL (jsargv1);219 JSObject *jsargv2 =JSObject_FromMaps(cx,*inputs);220 argv[1] = OBJECT_TO_JSVAL (jsargv2);221 JSObject *jsargv3 =JSObject_FromMaps(cx,*outputs);222 argv[2] = OBJECT_TO_JSVAL (jsargv3);223 jsval rval1 =JSVAL_NULL;224 #ifdef JS_DEBUG 225 fprintf (stderr, "object %p\n", (void *) argv[2]);226 #endif 227 228 ok = JS_CallFunctionName (cx, global, s->name, 3, argv, &rval1);229 230 #ifdef JS_DEBUG 231 fprintf (stderr, "object %p\n", (void *) argv[2]);231 JSObject *jsargv1 = JSObject_FromMaps (cx, *main_conf); 232 argv[0] = OBJECT_TO_JSVAL (jsargv1); 233 JSObject *jsargv2 = JSObject_FromMaps (cx, *inputs); 234 argv[1] = OBJECT_TO_JSVAL (jsargv2); 235 JSObject *jsargv3 = JSObject_FromMaps (cx, *outputs); 236 argv[2] = OBJECT_TO_JSVAL (jsargv3); 237 jsval rval1 = JSVAL_NULL; 238 #ifdef JS_DEBUG 239 fprintf (stderr, "object %p\n", (void *) argv[2]); 240 #endif 241 242 ok = JS_CallFunctionName (cx, global, s->name, 3, argv, &rval1); 243 244 #ifdef JS_DEBUG 245 fprintf (stderr, "object %p\n", (void *) argv[2]); 232 246 #endif 233 247 234 248 JSObject *d; 235 if (ok==JS_TRUE && JSVAL_IS_OBJECT(rval1)==JS_TRUE) { 236 #ifdef JS_DEBUG 237 fprintf(stderr,"Function run sucessfully !\n"); 238 #endif 239 /* Should get a number back from the service function call. */ 240 ok = JS_ValueToObject(cx, rval1, &d); 241 }else{ 242 /* Unable to run JS function */ 243 char tmp1[1024]; 244 if(strlen(dbg)==0) 245 sprintf(dbg,"No result was found after the function call"); 246 sprintf(tmp1,"Unable to run %s from the JavaScript file %s : \n %s",s->name,filename,dbg); 247 #ifdef JS_DEBUG 248 fprintf(stderr,"%s",tmp1); 249 #endif 250 map* err=createMap("text",tmp1); 251 addToMap(err,"code","NoApplicableCode"); 252 printExceptionReportResponse(*main_conf,err); 253 freeMap(&err); 254 free(err); 255 free(filename); 256 JS_MaybeGC(cx); 257 JS_DestroyContext(cx); 258 JS_DestroyRuntime(rt); 259 JS_ShutDown(); 260 // Should return -1 here but the unallocation won't work from zoo_service_loader.c line 1847 261 return -1; 262 } 263 264 jsval t=OBJECT_TO_JSVAL(d); 265 if(JS_IsArrayObject(cx,d)){ 266 #ifdef JS_DEBUG 267 fprintf(stderr,"An array was returned !\n"); 268 #endif 269 jsuint len; 270 if((JS_GetArrayLength(cx, d, &len)==JS_FALSE)){ 271 #ifdef JS_DEBUG 272 fprintf(stderr,"outputs array is empty\n"); 273 #endif 274 } 275 jsval tmp1; 276 JSBool hasResult=JS_GetElement(cx,d,0,&tmp1); 277 res=JSVAL_TO_INT(tmp1); 278 #ifdef JS_DEBUG 279 fprintf(stderr," * %d * \n",res); 280 #endif 281 if(res==SERVICE_SUCCEEDED){ 282 jsval tmp2; 283 JSBool hasElement=JS_GetElement(cx,d,1,&tmp2); 284 if(hasElement==JS_TRUE){ 285 freeMaps(outputs); 286 free(*outputs); 287 *outputs=mapsFromJSObject(cx,tmp2); 288 } 289 }else{ 290 jsval tmp3; 291 JSBool hasConf=JS_GetElement(cx,d,1,&tmp3); 292 if(hasConf==JS_TRUE){ 293 freeMaps(main_conf); 294 free(*main_conf); 295 *main_conf=mapsFromJSObject(cx,tmp3); 296 } 297 } 298 299 } 300 else{ 301 #ifdef JS_DEBUG 302 fprintf(stderr,"The service didn't return an array !\n"); 249 if (ok == JS_TRUE && JSVAL_IS_OBJECT (rval1) == JS_TRUE) 250 { 251 #ifdef JS_DEBUG 252 fprintf (stderr, "Function run sucessfully !\n"); 253 #endif 254 /* Should get a number back from the service function call. */ 255 ok = JS_ValueToObject (cx, rval1, &d); 256 } 257 else 258 { 259 /* Unable to run JS function */ 260 char tmp1[1024]; 261 if (strlen (dbg) == 0) 262 sprintf (dbg, "No result was found after the function call"); 263 sprintf (tmp1, "Unable to run %s from the JavaScript file %s : \n %s", 264 s->name, filename, dbg); 265 #ifdef JS_DEBUG 266 fprintf (stderr, "%s", tmp1); 267 #endif 268 map *err = createMap ("text", tmp1); 269 addToMap (err, "code", "NoApplicableCode"); 270 printExceptionReportResponse (*main_conf, err); 271 freeMap (&err); 272 free (err); 273 free (filename); 274 JS_MaybeGC (cx); 275 JS_DestroyContext (cx); 276 JS_DestroyRuntime (rt); 277 JS_ShutDown (); 278 // Should return -1 here but the unallocation won't work from zoo_service_loader.c line 1847 279 return -1; 280 } 281 282 jsval t = OBJECT_TO_JSVAL (d); 283 if (JS_IsArrayObject (cx, d)) 284 { 285 #ifdef JS_DEBUG 286 fprintf (stderr, "An array was returned !\n"); 287 #endif 288 jsuint len; 289 if ((JS_GetArrayLength (cx, d, &len) == JS_FALSE)) 290 { 291 #ifdef JS_DEBUG 292 fprintf (stderr, "outputs array is empty\n"); 293 #endif 294 } 295 jsval tmp1; 296 JSBool hasResult = JS_GetElement (cx, d, 0, &tmp1); 297 res = JSVAL_TO_INT (tmp1); 298 #ifdef JS_DEBUG 299 fprintf (stderr, " * %d * \n", res); 300 #endif 301 if (res == SERVICE_SUCCEEDED) 302 { 303 jsval tmp2; 304 JSBool hasElement = JS_GetElement (cx, d, 1, &tmp2); 305 if (hasElement == JS_TRUE) 306 { 307 freeMaps (outputs); 308 free (*outputs); 309 *outputs = mapsFromJSObject (cx, tmp2); 310 } 311 } 312 else 313 { 314 jsval tmp3; 315 JSBool hasConf = JS_GetElement (cx, d, 1, &tmp3); 316 if (hasConf == JS_TRUE) 317 { 318 freeMaps (main_conf); 319 free (*main_conf); 320 *main_conf = mapsFromJSObject (cx, tmp3); 321 } 322 } 323 324 } 325 else 326 { 327 #ifdef JS_DEBUG 328 fprintf (stderr, "The service didn't return an array !\n"); 303 329 #endif 304 330 /** 305 331 * Extract result 306 332 */ 307 jsval tmp1;308 JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);309 res=JSVAL_TO_INT(tmp1);310 311 #ifdef JS_DEBUG 312 fprintf(stderr," * %d * \n",res);333 jsval tmp1; 334 JSBool hasResult = JS_GetProperty (cx, d, "result", &tmp1); 335 res = JSVAL_TO_INT (tmp1); 336 337 #ifdef JS_DEBUG 338 fprintf (stderr, " * %d * \n", res); 313 339 #endif 314 340 /** 315 341 * Extract outputs when available. 316 342 */ 317 jsval tmp2; 318 JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2); 319 if(!JSVAL_IS_VOID(tmp2) && hasElement==JS_TRUE){ 320 freeMaps(outputs); 321 free(*outputs); 322 *outputs=mapsFromJSObject(cx,tmp2); 323 } 324 JS_MaybeGC(cx); 325 #ifdef JS_DEBUG 326 if(JSVAL_IS_VOID(tmp2)) 327 fprintf(stderr,"No outputs property returned\n"); 328 else{ 329 if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2))) 330 fprintf(stderr,"outputs is an array as expected\n"); 343 jsval tmp2; 344 JSBool hasElement = JS_GetProperty (cx, d, "outputs", &tmp2); 345 if (!JSVAL_IS_VOID (tmp2) && hasElement == JS_TRUE) 346 { 347 freeMaps (outputs); 348 free (*outputs); 349 *outputs = mapsFromJSObject (cx, tmp2); 350 } 351 JS_MaybeGC (cx); 352 #ifdef JS_DEBUG 353 if (JSVAL_IS_VOID (tmp2)) 354 fprintf (stderr, "No outputs property returned\n"); 331 355 else 332 fprintf(stderr,"outputs is not an array as expected\n"); 333 } 334 JS_MaybeGC(cx); 356 { 357 if (JS_IsArrayObject (cx, JSVAL_TO_OBJECT (tmp2))) 358 fprintf (stderr, "outputs is an array as expected\n"); 359 else 360 fprintf (stderr, "outputs is not an array as expected\n"); 361 } 362 JS_MaybeGC (cx); 335 363 #endif 336 364 … … 338 366 * Extract conf when available. 339 367 */ 340 jsval tmp3; 341 JSBool hasConf=JS_GetProperty(cx,d,"conf",&tmp3); 342 if(!JSVAL_IS_VOID(tmp3) && hasConf==JS_TRUE){ 343 freeMaps(main_conf); 344 free(*main_conf); 345 *main_conf=mapsFromJSObject(cx,tmp3); 346 } 347 JS_MaybeGC(cx); 348 349 #ifdef JS_DEBUG 350 dumpMaps(*outputs); 351 #endif 352 } 368 jsval tmp3; 369 JSBool hasConf = JS_GetProperty (cx, d, "conf", &tmp3); 370 if (!JSVAL_IS_VOID (tmp3) && hasConf == JS_TRUE) 371 { 372 freeMaps (main_conf); 373 free (*main_conf); 374 *main_conf = mapsFromJSObject (cx, tmp3); 375 } 376 JS_MaybeGC (cx); 377 378 #ifdef JS_DEBUG 379 dumpMaps (*outputs); 380 #endif 381 } 353 382 /* Cleanup. */ 354 JS_MaybeGC (cx);355 JS_DestroyContext (cx);356 JS_DestroyRuntime (rt);357 JS_ShutDown ();358 free (filename);359 #ifdef JS_DEBUG 360 fprintf (stderr,"Returned value %d\n",res);383 JS_MaybeGC (cx); 384 JS_DestroyContext (cx); 385 JS_DestroyRuntime (rt); 386 JS_ShutDown (); 387 free (filename); 388 #ifdef JS_DEBUG 389 fprintf (stderr, "Returned value %d\n", res); 361 390 #endif 362 391 return res; 363 392 } 364 393 365 JSObject * loadZooApiFile(JSContext *cx,JSObject *global, char* filename){ 394 JSObject * 395 loadZooApiFile (JSContext * cx, JSObject * global, char *filename) 396 { 366 397 struct stat api_status; 367 int s=stat(filename, &api_status); 368 if(s==0){ 369 jsval rval; 370 JSBool ok ; 371 JSObject *script = JS_CompileFile(cx, JS_GetGlobalObject(cx), filename); 372 if(script!=NULL){ 373 (void)JS_ExecuteScript(cx, JS_GetGlobalObject(cx), script, &rval); 374 #ifdef JS_DEBUG 375 fprintf(stderr,"**************\n%s correctly loaded\n**************\n",filename); 376 #endif 377 return script; 378 } 379 #ifdef JS_DEBUG 380 else 381 fprintf(stderr,"\n**************\nUnable to run %s\n**************\n",filename); 382 #endif 383 } 398 int s = stat (filename, &api_status); 399 if (s == 0) 400 { 401 jsval rval; 402 JSBool ok; 403 JSObject *script = 404 JS_CompileFile (cx, JS_GetGlobalObject (cx), filename); 405 if (script != NULL) 406 { 407 (void) JS_ExecuteScript (cx, JS_GetGlobalObject (cx), script, 408 &rval); 409 #ifdef JS_DEBUG 410 fprintf (stderr, 411 "**************\n%s correctly loaded\n**************\n", 412 filename); 413 #endif 414 return script; 415 } 416 #ifdef JS_DEBUG 417 else 418 fprintf (stderr, 419 "\n**************\nUnable to run %s\n**************\n", 420 filename); 421 #endif 422 } 384 423 #ifdef JS_DEBUG 385 424 else 386 fprintf(stderr,"\n**************\nUnable to load %s\n**************\n",filename); 425 fprintf (stderr, "\n**************\nUnable to load %s\n**************\n", 426 filename); 387 427 #endif 388 428 return NULL; 389 429 } 390 430 391 JSObject* JSObject_FromMaps(JSContext *cx,maps* t){ 392 393 JSObject* res=JS_NewObject(cx, NULL, NULL, NULL); 431 JSObject * 432 JSObject_FromMaps (JSContext * cx, maps * t) 433 { 434 435 JSObject *res = JS_NewObject (cx, NULL, NULL, NULL); 394 436 //JSObject *res = JS_NewArrayObject(cx, 0, NULL); 395 if(res==NULL) 396 fprintf(stderr,"Array Object is NULL!\n"); 397 maps* tmp=t; 398 while(tmp!=NULL){ 399 jsuint len; 400 JSObject* res1=JS_NewObject(cx, NULL, NULL, NULL); 401 JSObject *pval=JSObject_FromMap(cx,tmp->content); 402 jsval pvalj=OBJECT_TO_JSVAL(pval); 403 JS_SetProperty(cx, res, tmp->name, &pvalj); 404 #ifdef JS_DEBUG 405 fprintf(stderr,"Length of the Array %d, element : %s added \n",len,tmp->name); 406 #endif 407 tmp=tmp->next; 408 } 437 if (res == NULL) 438 fprintf (stderr, "Array Object is NULL!\n"); 439 maps *tmp = t; 440 while (tmp != NULL) 441 { 442 jsuint len; 443 JSObject *res1 = JS_NewObject (cx, NULL, NULL, NULL); 444 JSObject *pval = JSObject_FromMap (cx, tmp->content); 445 jsval pvalj = OBJECT_TO_JSVAL (pval); 446 JS_SetProperty (cx, res, tmp->name, &pvalj); 447 #ifdef JS_DEBUG 448 fprintf (stderr, "Length of the Array %d, element : %s added \n", len, 449 tmp->name); 450 #endif 451 tmp = tmp->next; 452 } 409 453 return res; 410 454 } 411 455 412 JSObject* JSObject_FromMap(JSContext *cx,map* t){ 413 JSObject* res=JS_NewObject(cx, NULL, NULL, NULL); 414 jsval resf = OBJECT_TO_JSVAL(res); 415 map* tmpm=t; 416 map* isArray=getMap(t,"isArray"); 417 map* isBinary=getMap(t,"size"); 418 map* tmap=getMapType(t); 419 #ifdef JS_DEBUG 420 if(tmap==NULL) 421 fprintf(stderr,"tmap is null !\n"); 456 JSObject * 457 JSObject_FromMap (JSContext * cx, map * t) 458 { 459 JSObject *res = JS_NewObject (cx, NULL, NULL, NULL); 460 jsval resf = OBJECT_TO_JSVAL (res); 461 map *tmpm = t; 462 map *isArray = getMap (t, "isArray"); 463 map *isBinary = getMap (t, "size"); 464 map *tmap = getMapType (t); 465 #ifdef JS_DEBUG 466 if (tmap == NULL) 467 fprintf (stderr, "tmap is null !\n"); 422 468 else 423 fprintf(stderr,"tmap is not null ! (%s = %s)\n",tmap->name,tmap->value); 424 #endif 425 while(tmpm!=NULL){ 426 jsval jsstr; 427 if((isArray==NULL && isBinary!=NULL && strncasecmp(tmpm->name,"value",5)==0)) 428 jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,atoi(isBinary->value))); 429 else 430 jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,strlen(tmpm->value))); 431 JS_SetProperty(cx, res, tmpm->name,&jsstr); 432 #ifdef JS_DEBUG 433 fprintf(stderr,"[JS] %s => %s\n",tmpm->name,tmpm->value); 434 #endif 435 tmpm=tmpm->next; 436 } 437 if(isArray!=NULL){ 438 map* len=getMap(t,"length"); 439 int cnt=atoi(len->value); 440 JSObject* values=JS_NewArrayObject( cx, cnt, NULL ); 441 JSObject* mvalues=JS_NewArrayObject( cx, cnt, NULL ); 442 map *tmpm1,*tmpm2; 443 int i=0; 444 for(i=0;i<cnt;i++){ 445 tmpm1=getMapArray(t,"value",i); 446 tmpm2=getMapArray(t,tmap->name,i); 447 if(tmpm1!=NULL){ 448 jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm1->value,strlen(tmpm1->value))); 449 JS_SetElement( cx, values, i, &jsstr ); 450 } 451 if(tmpm2!=NULL){ 452 jsval jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm2->value,strlen(tmpm2->value))); 453 JS_SetElement( cx, mvalues, i, &jsstr ); 454 } 455 } 456 jsval jvalues=OBJECT_TO_JSVAL(values); 457 jsval jmvalues=OBJECT_TO_JSVAL(mvalues); 458 JS_SetProperty(cx, res,"value",&jvalues); 459 JS_SetProperty(cx, res,tmap->name,&jmvalues); 460 } 469 fprintf (stderr, "tmap is not null ! (%s = %s)\n", tmap->name, 470 tmap->value); 471 #endif 472 while (tmpm != NULL) 473 { 474 jsval jsstr; 475 if ((isArray == NULL && isBinary != NULL 476 && strncasecmp (tmpm->name, "value", 5) == 0)) 477 jsstr = 478 STRING_TO_JSVAL (JS_NewStringCopyN 479 (cx, tmpm->value, atoi (isBinary->value))); 480 else 481 jsstr = 482 STRING_TO_JSVAL (JS_NewStringCopyN 483 (cx, tmpm->value, strlen (tmpm->value))); 484 JS_SetProperty (cx, res, tmpm->name, &jsstr); 485 #ifdef JS_DEBUG 486 fprintf (stderr, "[JS] %s => %s\n", tmpm->name, tmpm->value); 487 #endif 488 tmpm = tmpm->next; 489 } 490 if (isArray != NULL) 491 { 492 map *len = getMap (t, "length"); 493 int cnt = atoi (len->value); 494 JSObject *values = JS_NewArrayObject (cx, cnt, NULL); 495 JSObject *mvalues = JS_NewArrayObject (cx, cnt, NULL); 496 map *tmpm1, *tmpm2; 497 int i = 0; 498 for (i = 0; i < cnt; i++) 499 { 500 tmpm1 = getMapArray (t, "value", i); 501 tmpm2 = getMapArray (t, tmap->name, i); 502 if (tmpm1 != NULL) 503 { 504 jsval jsstr = 505 STRING_TO_JSVAL (JS_NewStringCopyN 506 (cx, tmpm1->value, strlen (tmpm1->value))); 507 JS_SetElement (cx, values, i, &jsstr); 508 } 509 if (tmpm2 != NULL) 510 { 511 jsval jsstr = 512 STRING_TO_JSVAL (JS_NewStringCopyN 513 (cx, tmpm2->value, strlen (tmpm2->value))); 514 JS_SetElement (cx, mvalues, i, &jsstr); 515 } 516 } 517 jsval jvalues = OBJECT_TO_JSVAL (values); 518 jsval jmvalues = OBJECT_TO_JSVAL (mvalues); 519 JS_SetProperty (cx, res, "value", &jvalues); 520 JS_SetProperty (cx, res, tmap->name, &jmvalues); 521 } 461 522 return res; 462 523 } 463 524 464 maps* mapsFromJSObject(JSContext *cx,jsval t){ 465 maps *res=NULL; 466 maps *tres=NULL; 467 jsint oi=0; 468 JSObject* tt=JSVAL_TO_OBJECT(t); 469 if(JS_IsArrayObject(cx,tt)){ 470 #ifdef JS_DEBUG 471 fprintf(stderr,"Is finally an array !\n"); 472 #endif 473 } 474 else{ 475 #ifdef JS_DEBUG 476 fprintf(stderr,"Is not an array !\n"); 477 #endif 478 JSIdArray *idp=JS_Enumerate(cx,tt); 479 if(idp!=NULL) { 525 maps * 526 mapsFromJSObject (JSContext * cx, jsval t) 527 { 528 maps *res = NULL; 529 maps *tres = NULL; 530 jsint oi = 0; 531 JSObject *tt = JSVAL_TO_OBJECT (t); 532 if (JS_IsArrayObject (cx, tt)) 533 { 534 #ifdef JS_DEBUG 535 fprintf (stderr, "Is finally an array !\n"); 536 #endif 537 } 538 else 539 { 540 #ifdef JS_DEBUG 541 fprintf (stderr, "Is not an array !\n"); 542 #endif 543 JSIdArray *idp = JS_Enumerate (cx, tt); 544 if (idp != NULL) 545 { 546 int index; 547 jsdouble argNum; 548 #ifdef JS_DEBUG 549 fprintf (stderr, "Properties length : %d \n", idp->length); 550 #endif 551 552 for (index = 0, argNum = idp->length; index < argNum; index++) 553 { 554 jsval id = idp->vector[index]; 555 jsval vp; 556 JSString *str; 557 JS_IdToValue (cx, id, &vp); 558 char *c, *tmp; 559 JSString *jsmsg; 560 size_t len1; 561 jsmsg = JS_ValueToString (cx, vp); 562 len1 = JS_GetStringLength (jsmsg); 563 564 tmp = JS_EncodeString (cx, jsmsg); 565 tres = (maps *) malloc (MAPS_SIZE); 566 tres->name = zStrdup (tmp); 567 tres->content = NULL; 568 tres->next = NULL; 569 570 jsval nvp = JSVAL_NULL; 571 if ((JS_GetProperty (cx, tt, tmp, &nvp) == JS_FALSE)) 572 { 573 #ifdef JS_DEBUG 574 fprintf (stderr, 575 "Enumerate id : %d => %s => No more value\n", oi, 576 tmp); 577 #endif 578 } 579 free (tmp); 580 JSObject *nvp1 = JSVAL_TO_OBJECT (JSVAL_NULL); 581 JS_ValueToObject (cx, nvp, &nvp1); 582 jsval nvp1j = OBJECT_TO_JSVAL (nvp1); 583 if (JSVAL_IS_OBJECT (nvp1j)) 584 { 585 tres->content = mapFromJSObject (cx, nvp1j); 586 } 587 588 if (res == NULL) 589 res = dupMaps (&tres); 590 else 591 addMapsToMaps (&res, tres); 592 freeMaps (&tres); 593 free (tres); 594 tres = NULL; 595 596 } 597 JS_DestroyIdArray (cx, idp); 598 } 599 } 600 601 jsuint len; 602 JSBool hasLen = JS_GetArrayLength (cx, tt, &len); 603 #ifdef JS_DEBUG 604 if (hasLen == JS_FALSE) 605 { 606 fprintf (stderr, "outputs array is empty\n"); 607 } 608 fprintf (stderr, "outputs array length : %d\n", len); 609 #endif 610 for (oi = 0; oi < len; oi++) 611 { 612 #ifdef JS_DEBUG 613 fprintf (stderr, "outputs array length : %d step %d \n", len, oi); 614 #endif 615 jsval tmp1; 616 JSBool hasElement = JS_GetElement (cx, tt, oi, &tmp1); 617 JSObject *otmp1 = JSVAL_TO_OBJECT (tmp1); 618 JSIdArray *idp = JS_Enumerate (cx, otmp1); 619 if (idp != NULL) 620 { 621 int index; 622 jsdouble argNum; 623 #ifdef JS_DEBUG 624 fprintf (stderr, "Properties length : %d \n", idp->length); 625 #endif 626 tres = (maps *) malloc (MAPS_SIZE); 627 tres->name = NULL; 628 tres->content = NULL; 629 tres->next = NULL; 630 631 for (index = 0, argNum = idp->length; index < argNum; index++) 632 { 633 jsval id = idp->vector[index]; 634 jsval vp; 635 JSString *str; 636 JS_IdToValue (cx, id, &vp); 637 char *c, *tmp; 638 JSString *jsmsg; 639 size_t len1; 640 jsmsg = JS_ValueToString (cx, vp); 641 len1 = JS_GetStringLength (jsmsg); 642 tmp = JS_EncodeString (cx, jsmsg); 643 #ifdef JS_DEBUG 644 fprintf (stderr, "Enumerate id : %d => %s\n", oi, tmp); 645 #endif 646 jsval nvp = JSVAL_NULL; 647 if ((JS_GetProperty (cx, JSVAL_TO_OBJECT (tmp1), tmp, &nvp) == 648 JS_FALSE)) 649 { 650 #ifdef JS_DEBUG 651 fprintf (stderr, 652 "Enumerate id : %d => %s => No more value\n", oi, 653 tmp); 654 #endif 655 } 656 free (tmp); 657 if (JSVAL_IS_OBJECT (nvp)) 658 { 659 #ifdef JS_DEBUG 660 fprintf (stderr, "JSVAL NVP IS OBJECT\n"); 661 #endif 662 } 663 664 JSObject *nvp1 = JSVAL_TO_OBJECT (JSVAL_NULL); 665 JS_ValueToObject (cx, nvp, &nvp1); 666 jsval nvp1j = OBJECT_TO_JSVAL (nvp1); 667 if (JSVAL_IS_OBJECT (nvp1j)) 668 { 669 JSString *jsmsg1; 670 char *tmp1, *tmp2; 671 JSObject *nvp2 = JSVAL_TO_OBJECT (JSVAL_NULL); 672 jsmsg1 = JS_ValueToString (cx, nvp1j); 673 len1 = JS_GetStringLength (jsmsg1); 674 tmp1 = JS_EncodeString (cx, jsmsg1); 675 tmp2 = JS_EncodeString (cx, jsmsg); 676 #ifdef JS_DEBUG 677 fprintf (stderr, "JSVAL NVP1J IS OBJECT %s = %s\n", 678 JS_EncodeString (cx, jsmsg), tmp1); 679 #endif 680 if (strcasecmp (tmp1, "[object Object]") == 0) 681 { 682 tres->name = zStrdup (tmp2); 683 tres->content = mapFromJSObject (cx, nvp1j); 684 } 685 else if (strcasecmp (tmp2, "name") == 0) 686 { 687 tres->name = zStrdup (tmp1); 688 } 689 else 690 { 691 if (tres->content == NULL) 692 tres->content = createMap (tmp2, tmp1); 693 else 694 addToMap (tres->content, tmp2, tmp1); 695 } 696 free (tmp1); 697 free (tmp2); 698 } 699 #ifdef JS_DEBUG 700 else 701 fprintf (stderr, "JSVAL NVP1J IS NOT OBJECT !!\n"); 702 #endif 703 } 704 #ifdef JS_DEBUG 705 dumpMaps (tres); 706 #endif 707 if (res == NULL) 708 res = dupMaps (&tres); 709 else 710 addMapsToMaps (&res, tres); 711 freeMaps (&tres); 712 free (tres); 713 tres = NULL; 714 JS_DestroyIdArray (cx, idp); 715 } 716 } 717 #ifdef JS_DEBUG 718 dumpMaps (res); 719 #endif 720 return res; 721 } 722 723 map * 724 mapFromJSObject (JSContext * cx, jsval t) 725 { 726 map *res = NULL; 727 JSIdArray *idp = JS_Enumerate (cx, JSVAL_TO_OBJECT (t)); 728 #ifdef JS_DEBUG 729 fprintf (stderr, "Properties %p\n", (void *) t); 730 #endif 731 if (idp != NULL) 732 { 480 733 int index; 481 734 jsdouble argNum; 482 735 #ifdef JS_DEBUG 483 fprintf(stderr,"Properties length : %d \n",idp->length); 484 #endif 485 486 for (index=0,argNum=idp->length;index<argNum;index++) { 487 jsval id = idp->vector[index]; 488 jsval vp; 489 JSString* str; 490 JS_IdToValue(cx,id,&vp); 491 char *c, *tmp; 492 JSString *jsmsg; 493 size_t len1; 494 jsmsg = JS_ValueToString(cx,vp); 495 len1 = JS_GetStringLength(jsmsg); 496 497 tmp=JS_EncodeString(cx,jsmsg); 498 tres=(maps*)malloc(MAPS_SIZE); 499 tres->name=zStrdup(tmp); 500 tres->content=NULL; 501 tres->next=NULL; 502 503 jsval nvp=JSVAL_NULL; 504 if((JS_GetProperty(cx, tt, tmp, &nvp)==JS_FALSE)){ 505 #ifdef JS_DEBUG 506 fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,tmp); 507 #endif 508 } 509 free(tmp); 510 JSObject *nvp1=JSVAL_TO_OBJECT(JSVAL_NULL); 511 JS_ValueToObject(cx,nvp,&nvp1); 512 jsval nvp1j=OBJECT_TO_JSVAL(nvp1); 513 if(JSVAL_IS_OBJECT(nvp1j)){ 514 tres->content=mapFromJSObject(cx,nvp1j); 515 } 516 517 if(res==NULL) 518 res=dupMaps(&tres); 519 else 520 addMapsToMaps(&res,tres); 521 freeMaps(&tres); 522 free(tres); 523 tres=NULL; 524 525 } 526 JS_DestroyIdArray(cx,idp); 527 } 528 } 529 530 jsuint len; 531 JSBool hasLen=JS_GetArrayLength(cx, tt, &len); 532 #ifdef JS_DEBUG 533 if(hasLen==JS_FALSE){ 534 fprintf(stderr,"outputs array is empty\n"); 535 } 536 fprintf(stderr,"outputs array length : %d\n",len); 537 #endif 538 for(oi=0;oi < len;oi++){ 539 #ifdef JS_DEBUG 540 fprintf(stderr,"outputs array length : %d step %d \n",len,oi); 541 #endif 542 jsval tmp1; 543 JSBool hasElement=JS_GetElement(cx,tt,oi,&tmp1); 544 JSObject *otmp1=JSVAL_TO_OBJECT(tmp1); 545 JSIdArray *idp=JS_Enumerate(cx,otmp1); 546 if(idp!=NULL) { 547 int index; 548 jsdouble argNum; 549 #ifdef JS_DEBUG 550 fprintf(stderr,"Properties length : %d \n",idp->length); 551 #endif 552 tres=(maps*)malloc(MAPS_SIZE); 553 tres->name=NULL; 554 tres->content=NULL; 555 tres->next=NULL; 556 557 for (index=0,argNum=idp->length;index<argNum;index++) { 558 jsval id = idp->vector[index]; 559 jsval vp; 560 JSString* str; 561 JS_IdToValue(cx,id,&vp); 562 char *c, *tmp; 563 JSString *jsmsg; 564 size_t len1; 565 jsmsg = JS_ValueToString(cx,vp); 566 len1 = JS_GetStringLength(jsmsg); 567 tmp=JS_EncodeString(cx,jsmsg); 568 #ifdef JS_DEBUG 569 fprintf(stderr,"Enumerate id : %d => %s\n",oi,tmp); 570 #endif 571 jsval nvp=JSVAL_NULL; 572 if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), tmp, &nvp)==JS_FALSE)){ 573 #ifdef JS_DEBUG 574 fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,tmp); 575 #endif 576 } 577 free(tmp); 578 if(JSVAL_IS_OBJECT(nvp)){ 579 #ifdef JS_DEBUG 580 fprintf(stderr,"JSVAL NVP IS OBJECT\n"); 581 #endif 582 } 583 584 JSObject *nvp1=JSVAL_TO_OBJECT(JSVAL_NULL); 585 JS_ValueToObject(cx,nvp,&nvp1); 586 jsval nvp1j=OBJECT_TO_JSVAL(nvp1); 587 if(JSVAL_IS_OBJECT(nvp1j)){ 588 JSString *jsmsg1; 589 char *tmp1, *tmp2; 590 JSObject *nvp2=JSVAL_TO_OBJECT(JSVAL_NULL); 591 jsmsg1 = JS_ValueToString(cx,nvp1j); 592 len1 = JS_GetStringLength(jsmsg1); 593 tmp1=JS_EncodeString(cx,jsmsg1); 594 tmp2=JS_EncodeString(cx,jsmsg); 595 #ifdef JS_DEBUG 596 fprintf(stderr,"JSVAL NVP1J IS OBJECT %s = %s\n",JS_EncodeString(cx,jsmsg),tmp1); 597 #endif 598 if(strcasecmp(tmp1,"[object Object]")==0){ 599 tres->name=zStrdup(tmp2); 600 tres->content=mapFromJSObject(cx,nvp1j); 601 } 602 else 603 if(strcasecmp(tmp2,"name")==0){ 604 tres->name=zStrdup(tmp1); 605 } 606 else{ 607 if(tres->content==NULL) 608 tres->content=createMap(tmp2,tmp1); 609 else 610 addToMap(tres->content,tmp2,tmp1); 611 } 612 free(tmp1); 613 free(tmp2); 614 } 615 #ifdef JS_DEBUG 616 else 617 fprintf(stderr,"JSVAL NVP1J IS NOT OBJECT !!\n"); 618 #endif 619 } 620 #ifdef JS_DEBUG 621 dumpMaps(tres); 622 #endif 623 if(res==NULL) 624 res=dupMaps(&tres); 625 else 626 addMapsToMaps(&res,tres); 627 freeMaps(&tres); 628 free(tres); 629 tres=NULL; 630 JS_DestroyIdArray(cx,idp); 631 } 632 } 633 #ifdef JS_DEBUG 634 dumpMaps(res); 736 fprintf (stderr, "Properties length : %d \n", idp->length); 737 #endif 738 for (index = 0, argNum = idp->length; index < argNum; index++) 739 { 740 jsval id = idp->vector[index]; 741 jsval vp; 742 JSString *str; 743 JS_IdToValue (cx, id, &vp); 744 char *c, *tmp, *tmp1; 745 JSString *jsmsg, *jsmsg1; 746 size_t len, len1; 747 jsmsg = JS_ValueToString (cx, vp); 748 len = JS_GetStringLength (jsmsg); 749 jsval nvp; 750 tmp = JS_EncodeString (cx, jsmsg); 751 JS_GetProperty (cx, JSVAL_TO_OBJECT (t), tmp, &nvp); 752 jsmsg1 = JS_ValueToString (cx, nvp); 753 len1 = JS_GetStringLength (jsmsg1); 754 tmp1 = JS_EncodeString (cx, jsmsg1); 755 #ifdef JS_DEBUG 756 fprintf (stderr, "Enumerate id : %d [ %s => %s ]\n", index, tmp, 757 tmp1); 758 #endif 759 if (res != NULL) 760 { 761 #ifdef JS_DEBUG 762 fprintf (stderr, "%s - %s\n", tmp, tmp1); 763 #endif 764 addToMap (res, tmp, tmp1); 765 } 766 else 767 { 768 res = createMap (tmp, tmp1); 769 res->next = NULL; 770 } 771 free (tmp); 772 free (tmp1); 773 #ifdef JS_DEBUG 774 dumpMap (res); 775 #endif 776 } 777 JS_DestroyIdArray (cx, idp); 778 } 779 #ifdef JS_DEBUG 780 dumpMap (res); 635 781 #endif 636 782 return res; 637 783 } 638 784 639 map* mapFromJSObject(JSContext *cx,jsval t){640 map *res=NULL;641 JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));642 #ifdef JS_DEBUG643 fprintf(stderr,"Properties %p\n",(void*)t);644 #endif645 if(idp!=NULL) {646 int index;647 jsdouble argNum;648 #ifdef JS_DEBUG649 fprintf(stderr,"Properties length : %d \n",idp->length);650 #endif651 for (index=0,argNum=idp->length;index<argNum;index++) {652 jsval id = idp->vector[index];653 jsval vp;654 JSString* str;655 JS_IdToValue(cx,id,&vp);656 char *c, *tmp, *tmp1;657 JSString *jsmsg,*jsmsg1;658 size_t len,len1;659 jsmsg = JS_ValueToString(cx,vp);660 len = JS_GetStringLength(jsmsg);661 jsval nvp;662 tmp=JS_EncodeString(cx,jsmsg);663 JS_GetProperty(cx, JSVAL_TO_OBJECT(t), tmp, &nvp);664 jsmsg1 = JS_ValueToString(cx,nvp);665 len1 = JS_GetStringLength(jsmsg1);666 tmp1=JS_EncodeString(cx,jsmsg1);667 #ifdef JS_DEBUG668 fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,tmp,tmp1);669 #endif670 if(res!=NULL){671 #ifdef JS_DEBUG672 fprintf(stderr,"%s - %s\n",tmp,tmp1);673 #endif674 addToMap(res,tmp,tmp1);675 }676 else{677 res=createMap(tmp,tmp1);678 res->next=NULL;679 }680 free(tmp);681 free(tmp1);682 #ifdef JS_DEBUG683 dumpMap(res);684 #endif685 }686 JS_DestroyIdArray(cx,idp);687 }688 #ifdef JS_DEBUG689 dumpMap(res);690 #endif691 return res;692 }693 694 785 /* The error reporter callback. */ 695 void reportError(JSContext *cx, const char *message, JSErrorReport *report) 696 { 697 sprintf(dbg,"%s:%u:%s\n", 698 report->filename ? report->filename : "<no filename>", 699 (unsigned int) report->lineno, 700 message); 701 #ifdef JS_DEBUG 702 fprintf(stderr,"%s",dbg); 703 #endif 704 fflush(stderr); 705 } 706 707 char* JSValToChar(JSContext* context, jsval* arg) { 786 void 787 reportError (JSContext * cx, const char *message, JSErrorReport * report) 788 { 789 sprintf (dbg, "%s:%u:%s\n", 790 report->filename ? report->filename : "<no filename>", 791 (unsigned int) report->lineno, message); 792 #ifdef JS_DEBUG 793 fprintf (stderr, "%s", dbg); 794 #endif 795 fflush (stderr); 796 } 797 798 char * 799 JSValToChar (JSContext * context, jsval * arg) 800 { 708 801 char *c; 709 802 char *tmp; … … 711 804 size_t len; 712 805 int i; 713 if(!JSVAL_IS_STRING(*arg)) { 714 return NULL; 715 } 716 jsmsg = JS_ValueToString(context,*arg); 717 len = JS_GetStringLength(jsmsg); 718 tmp = JS_EncodeString(context,jsmsg); 719 c = (char*)malloc((len+1)*sizeof(char)); 806 if (!JSVAL_IS_STRING (*arg)) 807 { 808 return NULL; 809 } 810 jsmsg = JS_ValueToString (context, *arg); 811 len = JS_GetStringLength (jsmsg); 812 tmp = JS_EncodeString (context, jsmsg); 813 c = (char *) malloc ((len + 1) * sizeof (char)); 720 814 c[len] = '\0'; 721 815 #ifdef ULINET_DEBUG 722 fprintf(stderr,"%d \n",len); 723 #endif 724 for(i = 0;i < len;i++) { 725 c[i] = tmp[i]; 726 c[i+1] = 0; 727 } 816 fprintf (stderr, "%d \n", len); 817 #endif 818 for (i = 0; i < len; i++) 819 { 820 c[i] = tmp[i]; 821 c[i + 1] = 0; 822 } 728 823 #ifdef ULINET_DEBUG 729 fprintf (stderr,"%s \n",c);824 fprintf (stderr, "%s \n", c); 730 825 #endif 731 826 return c; 732 827 } 733 828 734 HINTERNET setHeader(HINTERNET* handle,JSContext *cx,JSObject *header){ 735 jsuint length=0; 736 jsint i=0; 829 HINTERNET 830 setHeader (HINTERNET * handle, JSContext * cx, JSObject * header) 831 { 832 jsuint length = 0; 833 jsint i = 0; 737 834 char *tmp1; 738 835 #ifdef ULINET_DEBUG 739 fprintf(stderr,"setHeader\n"); 740 #endif 741 if(JS_IsArrayObject(cx,header)){ 836 fprintf (stderr, "setHeader\n"); 837 #endif 838 if (JS_IsArrayObject (cx, header)) 839 { 742 840 #ifdef ULINET_DEBUG 743 fprintf(stderr,"header is an array\n");744 #endif 745 JS_GetArrayLength(cx,header,&length);841 fprintf (stderr, "header is an array\n"); 842 #endif 843 JS_GetArrayLength (cx, header, &length); 746 844 #ifdef ULINET_DEBUG 747 fprintf(stderr,"header is an array of %d elements\n",length); 748 #endif 749 handle->ihandle[handle->nb].header=NULL; 750 for(i=0;i<length;i++){ 751 jsval tmp; 752 JS_GetElement(cx,header,i,&tmp); 753 tmp1=JSValToChar(cx,&tmp); 845 fprintf (stderr, "header is an array of %d elements\n", length); 846 #endif 847 handle->ihandle[handle->nb].header = NULL; 848 for (i = 0; i < length; i++) 849 { 850 jsval tmp; 851 JS_GetElement (cx, header, i, &tmp); 852 tmp1 = JSValToChar (cx, &tmp); 754 853 #ifdef ULINET_DEBUG 755 curl_easy_setopt(handle->ihandle[handle->nb].handle,CURLOPT_VERBOSE,1); 756 fprintf(stderr,"Element of array n° %d, value : %s\n",i,tmp1); 757 #endif 758 handle->ihandle[handle->nb].header=curl_slist_append(handle->ihandle[handle->nb].header, tmp1); 759 free(tmp1); 760 } 761 } 762 else{ 763 fprintf(stderr,"not an array !!!!!!!\n"); 764 } 854 curl_easy_setopt (handle->ihandle[handle->nb].handle, 855 CURLOPT_VERBOSE, 1); 856 fprintf (stderr, "Element of array n° %d, value : %s\n", i, tmp1); 857 #endif 858 handle->ihandle[handle->nb].header = 859 curl_slist_append (handle->ihandle[handle->nb].header, tmp1); 860 free (tmp1); 861 } 862 } 863 else 864 { 865 fprintf (stderr, "not an array !!!!!!!\n"); 866 } 765 867 return *handle; 766 868 } 767 869 768 870 JSBool 769 JSTranslate(JSContext *cx, uintN argc, jsval *argv1) 770 { 771 jsval *argv = JS_ARGV(cx,argv1); 772 char *str=JSValToChar(cx,&argv[0]); 773 char *tmpValue=_ss(str); 774 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue)))); 775 JS_MaybeGC(cx); 871 JSTranslate (JSContext * cx, uintN argc, jsval * argv1) 872 { 873 jsval *argv = JS_ARGV (cx, argv1); 874 char *str = JSValToChar (cx, &argv[0]); 875 char *tmpValue = _ss (str); 876 JS_SET_RVAL (cx, argv1, 877 STRING_TO_JSVAL (JS_NewStringCopyN 878 (cx, tmpValue, strlen (tmpValue)))); 879 JS_MaybeGC (cx); 776 880 return JS_TRUE; 777 881 } 778 882 779 883 JSBool 780 JSRequest (JSContext *cx, uintN argc, jsval *argv1)781 { 782 jsval *argv = JS_ARGV (cx,argv1);884 JSRequest (JSContext * cx, uintN argc, jsval * argv1) 885 { 886 jsval *argv = JS_ARGV (cx, argv1); 783 887 HINTERNET hInternet; 784 888 HINTERNET res; … … 787 891 char *url; 788 892 char *method; 789 char *tmpValue;893 char *tmpValue; 790 894 size_t dwRead; 791 int i=0; 792 JS_MaybeGC(cx); 793 hInternet=InternetOpen("ZooWPSClient\0", 794 INTERNET_OPEN_TYPE_PRECONFIG, 795 NULL,NULL, 0); 796 if(!CHECK_INET_HANDLE(hInternet)) 895 int i = 0; 896 JS_MaybeGC (cx); 897 hInternet = InternetOpen ("ZooWPSClient\0", 898 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 899 if (!CHECK_INET_HANDLE (hInternet)) 797 900 return JS_FALSE; 798 if(argc>=2){ 799 method=JSValToChar(cx,&argv[0]); 800 url=JSValToChar(cx,&argv[1]); 801 } 802 else{ 803 method=zStrdup("GET"); 804 url=JSValToChar(cx,argv); 805 } 806 hInternet.waitingRequests[hInternet.nb]=strdup(url); 807 if(argc==4){ 808 char *body; 809 body=JSValToChar(cx,&argv[2]); 810 header=JSVAL_TO_OBJECT(argv[3]); 901 if (argc >= 2) 902 { 903 method = JSValToChar (cx, &argv[0]); 904 url = JSValToChar (cx, &argv[1]); 905 } 906 else 907 { 908 method = zStrdup ("GET"); 909 url = JSValToChar (cx, argv); 910 } 911 hInternet.waitingRequests[hInternet.nb] = strdup (url); 912 if (argc == 4) 913 { 914 char *body; 915 body = JSValToChar (cx, &argv[2]); 916 header = JSVAL_TO_OBJECT (argv[3]); 811 917 #ifdef ULINET_DEBUG 812 fprintf(stderr,"URL (%s) \nBODY (%s)\n",url,body);813 #endif 814 if(JS_IsArrayObject(cx,header))815 setHeader(&hInternet,cx,header);918 fprintf (stderr, "URL (%s) \nBODY (%s)\n", url, body); 919 #endif 920 if (JS_IsArrayObject (cx, header)) 921 setHeader (&hInternet, cx, header); 816 922 #ifdef ULINET_DEBUG 817 fprintf(stderr,"BODY (%s)\n",body); 818 #endif 819 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body), 820 INTERNET_FLAG_NO_CACHE_WRITE,0); 821 processDownloads(&hInternet); 822 free(body); 823 }else{ 824 if(argc==3){ 825 char *body=JSValToChar(cx,&argv[2]); 826 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],body,strlen(body), 827 INTERNET_FLAG_NO_CACHE_WRITE,0); 828 processDownloads(&hInternet); 829 free(body); 830 }else{ 831 InternetOpenUrl(&hInternet,hInternet.waitingRequests[hInternet.nb],NULL,0, 832 INTERNET_FLAG_NO_CACHE_WRITE,0); 833 processDownloads(&hInternet); 834 } 835 } 836 tmpValue=(char*)malloc((hInternet.ihandle[0].nDataLen+1)*sizeof(char)); 837 InternetReadFile(hInternet.ihandle[0],(LPVOID)tmpValue,hInternet.ihandle[0].nDataLen,&dwRead); 923 fprintf (stderr, "BODY (%s)\n", body); 924 #endif 925 InternetOpenUrl (&hInternet, hInternet.waitingRequests[hInternet.nb], 926 body, strlen (body), INTERNET_FLAG_NO_CACHE_WRITE, 0); 927 processDownloads (&hInternet); 928 free (body); 929 } 930 else 931 { 932 if (argc == 3) 933 { 934 char *body = JSValToChar (cx, &argv[2]); 935 InternetOpenUrl (&hInternet, 936 hInternet.waitingRequests[hInternet.nb], body, 937 strlen (body), INTERNET_FLAG_NO_CACHE_WRITE, 0); 938 processDownloads (&hInternet); 939 free (body); 940 } 941 else 942 { 943 InternetOpenUrl (&hInternet, 944 hInternet.waitingRequests[hInternet.nb], NULL, 0, 945 INTERNET_FLAG_NO_CACHE_WRITE, 0); 946 processDownloads (&hInternet); 947 } 948 } 949 tmpValue = 950 (char *) malloc ((hInternet.ihandle[0].nDataLen + 1) * sizeof (char)); 951 InternetReadFile (hInternet.ihandle[0], (LPVOID) tmpValue, 952 hInternet.ihandle[0].nDataLen, &dwRead); 838 953 #ifdef ULINET_DEBUG 839 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue); 840 #endif 841 if(dwRead==0){ 842 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,"Unable to access the file.",strlen("Unable to access the file.")))); 843 return JS_TRUE; 844 } 954 fprintf (stderr, "content downloaded (%d) (%s) \n", dwRead, tmpValue); 955 #endif 956 if (dwRead == 0) 957 { 958 JS_SET_RVAL (cx, argv1, 959 STRING_TO_JSVAL (JS_NewStringCopyN 960 (cx, "Unable to access the file.", 961 strlen ("Unable to access the file.")))); 962 return JS_TRUE; 963 } 845 964 846 965 #ifdef ULINET_DEBUG 847 fprintf(stderr,"content downloaded (%d) (%s) \n",dwRead,tmpValue); 848 #endif 849 JS_SET_RVAL(cx, argv1,STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpValue,strlen(tmpValue)))); 850 free(url); 851 if(argc>=2) 852 free(method); 853 InternetCloseHandle(&hInternet); 854 JS_MaybeGC(cx); 966 fprintf (stderr, "content downloaded (%d) (%s) \n", dwRead, tmpValue); 967 #endif 968 JS_SET_RVAL (cx, argv1, 969 STRING_TO_JSVAL (JS_NewStringCopyN 970 (cx, tmpValue, strlen (tmpValue)))); 971 free (url); 972 if (argc >= 2) 973 free (method); 974 InternetCloseHandle (&hInternet); 975 JS_MaybeGC (cx); 855 976 return JS_TRUE; 856 977 } -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_internal_python.c
r505 r531 25 25 #include "service_internal_python.h" 26 26 27 struct module_state { 28 PyObject *error; 27 struct module_state 28 { 29 PyObject *error; 29 30 }; 30 31 … … 43 44 #endif 44 45 45 static PyObject *ZooError;46 static PyObject *ZooError; 46 47 47 48 PyMethodDef zooMethods[] = { 48 {"_", PythonTranslate, METH_VARARGS, "Translate a string using the zoo-services textdomain."}, 49 {"update_status", PythonUpdateStatus, METH_VARARGS, "Update status percentage of a running process."}, 50 {NULL, NULL, 0, NULL} /* tempt not the blade, all fear the sentinel */ 49 {"_", PythonTranslate, METH_VARARGS, 50 "Translate a string using the zoo-services textdomain."}, 51 {"update_status", PythonUpdateStatus, METH_VARARGS, 52 "Update status percentage of a running process."}, 53 {NULL, NULL, 0, NULL} /* tempt not the blade, all fear the sentinel */ 51 54 }; 52 55 53 56 #if PY_MAJOR_VERSION >= 3 54 57 55 static int myextension_traverse(PyObject *m, visitproc visit, void *arg) { 56 Py_VISIT(GETSTATE(m)->error); 58 static int 59 myextension_traverse (PyObject * m, visitproc visit, void *arg) 60 { 61 Py_VISIT (GETSTATE (m)->error); 57 62 return 0; 58 63 } 59 64 60 static int myextension_clear(PyObject *m) { 61 Py_CLEAR(GETSTATE(m)->error); 65 static int 66 myextension_clear (PyObject * m) 67 { 68 Py_CLEAR (GETSTATE (m)->error); 62 69 return 0; 63 70 } … … 67 74 "zoo", 68 75 NULL, 69 sizeof (struct module_state),76 sizeof (struct module_state), 70 77 zooMethods, 71 78 NULL, … … 76 83 #endif 77 84 78 PyMODINIT_FUNC init_zoo(){ 79 PyObject *tmp,*d; 80 PyObject *module = 81 #if PY_MAJOR_VERSION >= 3 82 PyModule_Create(&moduledef); 83 #else 84 Py_InitModule("zoo", zooMethods); 85 #endif 86 if (module == NULL){ 87 #if PY_MAJOR_VERSION >= 3 88 return NULL; 89 #else 90 return; 91 #endif 92 } 93 94 struct module_state *st = GETSTATE(module); 95 96 d = PyModule_GetDict(module); 97 tmp = PyInt_FromLong(3); 98 PyDict_SetItemString(d, "SERVICE_SUCCEEDED", tmp); 99 Py_DECREF(tmp); 100 101 tmp = PyInt_FromLong(4); 102 PyDict_SetItemString(d, "SERVICE_FAILED", tmp); 103 Py_DECREF(tmp); 104 105 tmp = PyString_FromString(ZOO_VERSION); 106 PyDict_SetItemString(d, "VERSION", tmp); 107 Py_DECREF(tmp); 108 109 ZooError = PyErr_NewException((char*)"zoo.error", NULL, NULL); 110 Py_INCREF(ZooError); 111 PyModule_AddObject(module, "error", ZooError); 85 PyMODINIT_FUNC 86 init_zoo () 87 { 88 PyObject *tmp, *d; 89 PyObject *module = 90 #if PY_MAJOR_VERSION >= 3 91 PyModule_Create (&moduledef); 92 #else 93 Py_InitModule ("zoo", zooMethods); 94 #endif 95 if (module == NULL) 96 { 97 #if PY_MAJOR_VERSION >= 3 98 return NULL; 99 #else 100 return; 101 #endif 102 } 103 104 struct module_state *st = GETSTATE (module); 105 106 d = PyModule_GetDict (module); 107 tmp = PyInt_FromLong (3); 108 PyDict_SetItemString (d, "SERVICE_SUCCEEDED", tmp); 109 Py_DECREF (tmp); 110 111 tmp = PyInt_FromLong (4); 112 PyDict_SetItemString (d, "SERVICE_FAILED", tmp); 113 Py_DECREF (tmp); 114 115 tmp = PyString_FromString (ZOO_VERSION); 116 PyDict_SetItemString (d, "VERSION", tmp); 117 Py_DECREF (tmp); 118 119 ZooError = PyErr_NewException ((char *) "zoo.error", NULL, NULL); 120 Py_INCREF (ZooError); 121 PyModule_AddObject (module, "error", ZooError); 112 122 #if PY_MAJOR_VERSION >= 3 113 123 return module; … … 115 125 } 116 126 117 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){ 127 int 128 zoo_python_support (maps ** main_conf, map * request, service * s, 129 maps ** real_inputs, maps ** real_outputs) 130 { 118 131 char *pythonpath; 119 132 char *python_path; 120 maps* m=*main_conf; 121 maps* inputs=*real_inputs; 122 maps* outputs=*real_outputs; 123 map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd"); 124 char *ntmp=tmp0->value; 125 map* tmp=NULL; 126 int hasToClean=0; 127 tmp=getMapFromMaps(*main_conf,"env","PYTHONPATH"); 128 #ifdef DEBUG 129 fprintf(stderr,"PYTHON SUPPORT \n"); 130 #endif 131 if(tmp!=NULL){ 132 #ifdef DEBUG 133 fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value)); 134 #endif 135 python_path=(char*)malloc((strlen(tmp->value))*sizeof(char)); 136 sprintf(python_path,"%s",tmp->value); 137 hasToClean=1; 138 } 139 else{ 140 python_path=(char*)"."; 141 } 142 tmp=NULL; 143 tmp=getMap(request,"metapath"); 144 if(tmp!=NULL && strcmp(tmp->value,"")!=0){ 145 pythonpath=(char*)malloc((4+strlen(python_path)+strlen(ntmp)+strlen(tmp->value))*sizeof(char)); 133 maps *m = *main_conf; 134 maps *inputs = *real_inputs; 135 maps *outputs = *real_outputs; 136 map *tmp0 = getMapFromMaps (*main_conf, "lenv", "cwd"); 137 char *python_package = 138 (char *) malloc ((strlen (s->identifier) - strlen (s->name) + 1) * 139 sizeof (char)); 140 python_package[0] = '\0'; 141 python_package = 142 strncat (python_package, s->identifier, 143 strlen (s->identifier) - strlen (s->name) - 1); 144 python_package[strlen (s->identifier) - strlen (s->name)] = '\0'; 145 char *ntmp = tmp0->value; 146 map *tmp = NULL; 147 int hasToClean = 0; 148 tmp = getMapFromMaps (*main_conf, "env", "PYTHONPATH"); 149 #ifdef DEBUG 150 fprintf (stderr, "PYTHON SUPPORT \n"); 151 #endif 152 if (tmp != NULL) 153 { 154 #ifdef DEBUG 155 fprintf (stderr, "PYTHON SUPPORT (%i)\n", strlen (tmp->value)); 156 #endif 157 python_path = (char *) malloc ((strlen (tmp->value)) * sizeof (char)); 158 sprintf (python_path, "%s", tmp->value); 159 hasToClean = 1; 160 } 161 else 162 { 163 python_path = (char *) "."; 164 } 165 pythonpath = 166 (char *) malloc ((2 + strlen (python_path) + strlen (ntmp)) * 167 sizeof (char)); 146 168 #ifdef WIN32 147 sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path); 148 #else 149 sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path); 150 #endif 151 } 152 else{ 153 pythonpath=(char*)malloc((2+strlen(python_path)+strlen(ntmp))*sizeof(char)); 154 #ifdef WIN32 155 sprintf(pythonpath,"%s;%s",ntmp,python_path); 156 #else 157 sprintf(pythonpath,"%s:%s",ntmp,python_path); 158 #endif 159 } 160 #ifdef DEBUG 161 fprintf(stderr,"PYTHONPATH=%s\n",pythonpath); 169 sprintf (pythonpath, "%s;%s", ntmp, python_path); 170 #else 171 sprintf (pythonpath, "%s:%s", ntmp, python_path); 172 #endif 173 174 #ifdef DEBUG 175 fprintf (stderr, "PYTHONPATH=%s\n", pythonpath); 162 176 #endif 163 177 #ifndef WIN32 164 setenv ("PYTHONPATH",pythonpath,1);165 #else 166 SetEnvironmentVariable ("PYTHONPATH",pythonpath);167 char * toto=(char*)malloc((strlen(pythonpath)+12)*sizeof(char));168 sprintf (toto,"PYTHONPATH=%s",pythonpath);169 putenv (toto);170 free (toto);171 #endif 172 if (hasToClean>0)173 free (python_path);174 free (pythonpath);178 setenv ("PYTHONPATH", pythonpath, 1); 179 #else 180 SetEnvironmentVariable ("PYTHONPATH", pythonpath); 181 char *toto = (char *) malloc ((strlen (pythonpath) + 12) * sizeof (char)); 182 sprintf (toto, "PYTHONPATH=%s", pythonpath); 183 putenv (toto); 184 free (toto); 185 #endif 186 if (hasToClean > 0) 187 free (python_path); 188 free (pythonpath); 175 189 176 190 PyThreadState *mainstate; 177 191 #if PY_MAJOR_VERSION >= 3 178 PyImport_AppendInittab ("zoo", init_zoo);179 #else 180 PyEval_InitThreads ();181 #endif 182 Py_Initialize ();183 #if PY_MAJOR_VERSION >= 3 184 PyEval_InitThreads ();185 PyImport_ImportModule ("zoo");186 #else 187 init_zoo ();188 #endif 189 mainstate = PyThreadState_Swap (NULL);190 PyEval_ReleaseLock ();192 PyImport_AppendInittab ("zoo", init_zoo); 193 #else 194 PyEval_InitThreads (); 195 #endif 196 Py_Initialize (); 197 #if PY_MAJOR_VERSION >= 3 198 PyEval_InitThreads (); 199 PyImport_ImportModule ("zoo"); 200 #else 201 init_zoo (); 202 #endif 203 mainstate = PyThreadState_Swap (NULL); 204 PyEval_ReleaseLock (); 191 205 PyGILState_STATE gstate; 192 gstate = PyGILState_Ensure ();206 gstate = PyGILState_Ensure (); 193 207 PyObject *pName, *pModule, *pFunc; 194 tmp=getMap(s->content,"serviceProvider"); 195 map* mp=getMap(request,"metapath"); 196 if(tmp!=NULL){ 197 if(mp!=NULL && strlen(mp->value)>0){ 198 char *mps=zStrdup(mp->value); 199 int i,len=strlen(mps); 200 int j=0; 201 for(i=0;i<len;i++){ 202 if(mps[i]=='/'){ 203 mps[i]='.'; 204 } 205 } 206 char *mn=(char*)malloc((strlen(mps)+strlen(tmp->value)+2)*sizeof(char)); 207 sprintf(mn,"%s.%s",mps,tmp->value); 208 pName = PyString_FromString(mn); 209 free(mn); 210 free(mps); 211 } 212 else{ 213 pName = PyString_FromString(tmp->value); 214 fprintf(stderr,"%s %d",tmp->value,__LINE__); 215 } 216 } 217 else{ 218 map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file."); 219 addToMap(err,"code","NoApplicableCode"); 220 printExceptionReportResponse(m,err); 221 exit(-1); 222 } 223 pModule = PyImport_Import(pName); 224 int res=SERVICE_FAILED; 225 if (pModule != NULL) { 226 pFunc=PyObject_GetAttrString(pModule,s->name); 227 if (pFunc && PyCallable_Check(pFunc)){ 228 PyObject *pValue; 229 PyDictObject* arg1=PyDict_FromMaps(m); 230 PyDictObject* arg2=PyDict_FromMaps(inputs); 231 PyDictObject* arg3=PyDict_FromMaps(outputs); 232 PyObject *pArgs=PyTuple_New(3); 233 if (!pArgs) 234 return -1; 235 PyTuple_SetItem(pArgs, 0, (PyObject *)arg1); 236 PyTuple_SetItem(pArgs, 1, (PyObject *)arg2); 237 PyTuple_SetItem(pArgs, 2, (PyObject *)arg3); 238 pValue = PyObject_CallObject(pFunc, pArgs); 239 if (pValue != NULL) { 240 res=PyInt_AsLong(pValue); 241 freeMaps(real_outputs); 242 free(*real_outputs); 243 freeMaps(main_conf); 244 free(*main_conf); 245 *main_conf=mapsFromPyDict(arg1); 246 *real_outputs=mapsFromPyDict(arg3); 247 #ifdef DEBUG 248 fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue)); 249 dumpMaps(inputs); 250 dumpMaps(*real_outputs); 251 #endif 252 }else{ 253 PyObject *ptype,*pvalue, *ptraceback; 254 PyErr_Fetch(&ptype, &pvalue, &ptraceback); 255 PyObject *trace=PyObject_Str(pvalue); 256 char pbt[10240]; 257 if(PyString_Check(trace)) 258 sprintf(pbt,"TRACE : %s",PyString_AsString(trace)); 259 else 260 fprintf(stderr,"EMPTY TRACE ?"); 261 trace=NULL; 262 trace=PyObject_Str(ptype); 263 if(PyString_Check(trace)){ 264 char *tpbt=zStrdup(pbt); 265 sprintf(pbt,"%s\n%s",tpbt,PyString_AsString(trace)); 266 free(tpbt); 267 } 268 else 269 fprintf(stderr,"EMPTY TRACE ?"); 270 271 char *tpbt=zStrdup(pbt); 272 pName = PyString_FromString("traceback"); 273 pModule = PyImport_Import(pName); 274 pArgs = PyTuple_New(1); 275 PyTuple_SetItem(pArgs, 0, ptraceback); 276 pFunc = PyObject_GetAttrString(pModule,"format_tb"); 277 pValue = PyObject_CallObject(pFunc, pArgs); 278 trace=NULL; 279 trace=PyObject_Str(pValue); 280 if(PyString_Check(trace)) 281 sprintf(pbt,"%s\nUnable to run your python process properly. Please check the following messages : %s",tpbt,PyString_AsString(trace)); 282 else 283 sprintf(pbt,"%s \n Unable to run your python process properly. Unable to provide any futher informations.",tpbt); 284 free(tpbt); 285 map* err=createMap("text",pbt); 286 addToMap(err,"code","NoApplicableCode"); 287 printExceptionReportResponse(m,err); 288 res=-1; 289 } 290 } 291 else{ 208 tmp = getMap (s->content, "serviceProvider"); 209 if (tmp != NULL) 210 { 211 char *module_name = 212 (char *) malloc (strlen (python_package) + strlen (tmp->value) + 2); 213 sprintf (module_name, "%s.%s", python_package, tmp->value); 214 pName = PyString_FromString (module_name); 215 free (python_package); 216 free (module_name); 217 fprintf (stderr, "%s %d", tmp->value, __LINE__); 218 } 219 else 220 { 221 map *err = createMap ("text", 222 "Unable to parse serviceProvider please check your zcfg file."); 223 addToMap (err, "code", "NoApplicableCode"); 224 printExceptionReportResponse (m, err); 225 exit (-1); 226 } 227 pModule = PyImport_Import (pName); 228 int res = SERVICE_FAILED; 229 if (pModule != NULL) 230 { 231 pFunc = PyObject_GetAttrString (pModule, s->name); 232 if (pFunc && PyCallable_Check (pFunc)) 233 { 234 PyObject *pValue; 235 PyDictObject *arg1 = PyDict_FromMaps (m); 236 PyDictObject *arg2 = PyDict_FromMaps (inputs); 237 PyDictObject *arg3 = PyDict_FromMaps (outputs); 238 PyObject *pArgs = PyTuple_New (3); 239 if (!pArgs) 240 return -1; 241 PyTuple_SetItem (pArgs, 0, (PyObject *) arg1); 242 PyTuple_SetItem (pArgs, 1, (PyObject *) arg2); 243 PyTuple_SetItem (pArgs, 2, (PyObject *) arg3); 244 pValue = PyObject_CallObject (pFunc, pArgs); 245 if (pValue != NULL) 246 { 247 res = PyInt_AsLong (pValue); 248 freeMaps (real_outputs); 249 free (*real_outputs); 250 freeMaps (main_conf); 251 free (*main_conf); 252 *main_conf = mapsFromPyDict (arg1); 253 *real_outputs = mapsFromPyDict (arg3); 254 #ifdef DEBUG 255 fprintf (stderr, "Result of call: %i\n", PyInt_AsLong (pValue)); 256 dumpMaps (inputs); 257 dumpMaps (*real_outputs); 258 #endif 259 } 260 else 261 { 262 PyObject *ptype, *pvalue, *ptraceback; 263 PyErr_Fetch (&ptype, &pvalue, &ptraceback); 264 PyObject *trace = PyObject_Str (pvalue); 265 char pbt[10240]; 266 if (PyString_Check (trace)) 267 sprintf (pbt, "TRACE : %s", PyString_AsString (trace)); 268 else 269 fprintf (stderr, "EMPTY TRACE ?"); 270 trace = NULL; 271 trace = PyObject_Str (ptype); 272 if (PyString_Check (trace)) 273 { 274 char *tpbt = zStrdup (pbt); 275 sprintf (pbt, "%s\n%s", tpbt, PyString_AsString (trace)); 276 free (tpbt); 277 } 278 else 279 fprintf (stderr, "EMPTY TRACE ?"); 280 281 char *tpbt = zStrdup (pbt); 282 pName = PyString_FromString ("traceback"); 283 pModule = PyImport_Import (pName); 284 pArgs = PyTuple_New (1); 285 PyTuple_SetItem (pArgs, 0, ptraceback); 286 pFunc = PyObject_GetAttrString (pModule, "format_tb"); 287 pValue = PyObject_CallObject (pFunc, pArgs); 288 trace = NULL; 289 trace = PyObject_Str (pValue); 290 if (PyString_Check (trace)) 291 sprintf (pbt, 292 "%s\nUnable to run your python process properly. Please check the following messages : %s", 293 tpbt, PyString_AsString (trace)); 294 else 295 sprintf (pbt, 296 "%s \n Unable to run your python process properly. Unable to provide any futher informations.", 297 tpbt); 298 free (tpbt); 299 map *err = createMap ("text", pbt); 300 addToMap (err, "code", "NoApplicableCode"); 301 printExceptionReportResponse (m, err); 302 res = -1; 303 } 304 } 305 else 306 { 307 char tmpS[1024]; 308 sprintf (tmpS, "Cannot find the %s function in the %s file.\n", 309 s->name, tmp->value); 310 map *tmps = createMap ("text", tmpS); 311 printExceptionReportResponse (m, tmps); 312 res = -1; 313 } 314 } 315 else 316 { 292 317 char tmpS[1024]; 293 sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value); 294 map* tmps=createMap("text",tmpS); 295 printExceptionReportResponse(m,tmps); 296 res=-1; 297 } 298 } else{ 299 char tmpS[1024]; 300 sprintf(tmpS, "Python module %s cannot be loaded.\n", tmp->value); 301 map* tmps=createMap("text",tmpS); 302 printExceptionReportResponse(m,tmps); 303 if (PyErr_Occurred()) 304 PyErr_Print(); 305 PyErr_Clear(); 306 res=-1; 307 } 318 sprintf (tmpS, "Python module %s cannot be loaded.\n", tmp->value); 319 map *tmps = createMap ("text", tmpS); 320 printExceptionReportResponse (m, tmps); 321 if (PyErr_Occurred ()) 322 PyErr_Print (); 323 PyErr_Clear (); 324 res = -1; 325 } 308 326 #if PY_MAJOR_VERSION < 3 309 PyGILState_Release (gstate);310 PyEval_AcquireLock ();311 #endif 312 PyThreadState_Swap (mainstate);313 Py_Finalize ();327 PyGILState_Release (gstate); 328 PyEval_AcquireLock (); 329 #endif 330 PyThreadState_Swap (mainstate); 331 Py_Finalize (); 314 332 return res; 315 333 } 316 334 317 PyDictObject* PyDict_FromMaps(maps* t){ 318 PyObject* res=PyDict_New( ); 319 maps* tmp=t; 320 while(tmp!=NULL){ 321 PyObject* value=(PyObject*)PyDict_FromMap(tmp->content); 322 PyObject* name=PyString_FromString(tmp->name); 323 if(PyDict_SetItem(res,name,value)<0){ 324 fprintf(stderr,"Unable to set map value ..."); 335 PyDictObject * 336 PyDict_FromMaps (maps * t) 337 { 338 PyObject *res = PyDict_New (); 339 maps *tmp = t; 340 while (tmp != NULL) 341 { 342 PyObject *value = (PyObject *) PyDict_FromMap (tmp->content); 343 PyObject *name = PyString_FromString (tmp->name); 344 if (PyDict_SetItem (res, name, value) < 0) 345 { 346 fprintf (stderr, "Unable to set map value ..."); 347 return NULL; 348 } 349 Py_DECREF (name); 350 tmp = tmp->next; 351 } 352 return (PyDictObject *) res; 353 } 354 355 PyDictObject * 356 PyDict_FromMap (map * t) 357 { 358 PyObject *res = PyDict_New (); 359 map *tmp = t; 360 int hasSize = 0; 361 map *isArray = getMap (tmp, "isArray"); 362 map *size = getMap (tmp, "size"); 363 map *tmap = getMapType (tmp); 364 while (tmp != NULL) 365 { 366 PyObject *name = PyString_FromString (tmp->name); 367 if (strcasecmp (tmp->name, "value") == 0) 368 { 369 if (isArray != NULL) 370 { 371 map *len = getMap (tmp, "length"); 372 int cnt = atoi (len->value); 373 PyObject *value = PyList_New (cnt); 374 PyObject *mvalue = PyList_New (cnt); 375 PyObject *svalue = PyList_New (cnt); 376 377 for (int i = 0; i < cnt; i++) 378 { 379 380 map *vMap = getMapArray (tmp, "value", i); 381 map *sMap = getMapArray (tmp, "size", i); 382 383 if (vMap != NULL) 384 { 385 386 PyObject *lvalue; 387 PyObject *lsvalue; 388 if (sMap == NULL) 389 { 390 lvalue = PyString_FromString (vMap->value); 391 lsvalue = Py_None; 392 } 393 else 394 { 395 lvalue = 396 PyString_FromStringAndSize (vMap->value, 397 atoi (sMap->value)); 398 lsvalue = PyString_FromString (sMap->value); 399 hasSize = 1; 400 } 401 402 if (PyList_SetItem (value, i, lvalue) < 0) 403 { 404 fprintf (stderr, "Unable to set key value pair..."); 405 return NULL; 406 } 407 if (PyList_SetItem (svalue, i, lsvalue) < 0) 408 { 409 fprintf (stderr, "Unable to set key value pair..."); 410 return NULL; 411 } 412 } 413 414 map *mMap = getMapArray (tmp, tmap->name, i); 415 PyObject *lmvalue; 416 if (mMap != NULL) 417 { 418 lmvalue = PyString_FromString (mMap->value); 419 } 420 else 421 lmvalue = Py_None; 422 423 if (PyList_SetItem (mvalue, i, lmvalue) < 0) 424 { 425 fprintf (stderr, "Unable to set key value pair..."); 426 return NULL; 427 } 428 429 } 430 431 if (PyDict_SetItem (res, name, value) < 0) 432 { 433 fprintf (stderr, "Unable to set key value pair..."); 434 return NULL; 435 } 436 if (PyDict_SetItem 437 (res, PyString_FromString (tmap->name), mvalue) < 0) 438 { 439 fprintf (stderr, "Unable to set key value pair..."); 440 return NULL; 441 } 442 if (hasSize > 0) 443 if (PyDict_SetItem (res, PyString_FromString ("size"), svalue) 444 < 0) 445 { 446 fprintf (stderr, "Unable to set key value pair..."); 447 return NULL; 448 } 449 } 450 else if (size != NULL) 451 { 452 PyObject *value = 453 PyString_FromStringAndSize (tmp->value, atoi (size->value)); 454 if (PyDict_SetItem (res, name, value) < 0) 455 { 456 Py_DECREF (value); 457 fprintf (stderr, "Unable to set key value pair..."); 458 return NULL; 459 } 460 Py_DECREF (value); 461 } 462 else 463 { 464 PyObject *value = PyString_FromString (tmp->value); 465 if (PyDict_SetItem (res, name, value) < 0) 466 { 467 Py_DECREF (value); 468 fprintf (stderr, "Unable to set key value pair..."); 469 return NULL; 470 } 471 Py_DECREF (value); 472 } 473 } 474 else 475 { 476 if (PyDict_GetItem (res, name) == NULL) 477 { 478 PyObject *value = PyString_FromString (tmp->value); 479 if (PyDict_SetItem (res, name, value) < 0) 480 { 481 Py_DECREF (value); 482 fprintf (stderr, "Unable to set key value pair..."); 483 return NULL; 484 } 485 Py_DECREF (value); 486 } 487 } 488 Py_DECREF (name); 489 tmp = tmp->next; 490 } 491 return (PyDictObject *) res; 492 } 493 494 maps * 495 mapsFromPyDict (PyDictObject * t) 496 { 497 maps *res = NULL; 498 maps *cursor = res; 499 PyObject *list = PyDict_Keys ((PyObject *) t); 500 int nb = PyList_Size (list); 501 int i; 502 for (i = 0; i < nb; i++) 503 { 504 #ifdef DEBUG 505 fprintf (stderr, ">> parsing maps %d\n", i); 506 #endif 507 PyObject *key = PyList_GetItem (list, i); 508 PyObject *value = PyDict_GetItem ((PyObject *) t, key); 509 #ifdef DEBUG 510 fprintf (stderr, ">> DEBUG VALUES : %s => %s\n", 511 PyString_AsString (key), PyString_AsString (value)); 512 #endif 513 cursor = (maps *) malloc (MAPS_SIZE); 514 cursor->name = PyString_AsString (key); 515 cursor->content = mapFromPyDict ((PyDictObject *) value); 516 #ifdef DEBUG 517 dumpMap (cursor->content); 518 #endif 519 cursor->next = NULL; 520 if (res == NULL) 521 res = dupMaps (&cursor); 522 else 523 addMapsToMaps (&res, cursor); 524 freeMap (&cursor->content); 525 free (cursor->content); 526 free (cursor); 527 Py_DECREF (key); 528 #ifdef DEBUG 529 dumpMaps (res); 530 fprintf (stderr, ">> parsed maps %d\n", i); 531 #endif 532 } 533 Py_DECREF (list); 534 return res; 535 } 536 537 map * 538 mapFromPyDict (PyDictObject * t) 539 { 540 map *res = NULL; 541 PyObject *list = PyDict_Keys ((PyObject *) t); 542 int nb = PyList_Size (list); 543 int i; 544 for (i = 0; i < nb; i++) 545 { 546 PyObject *key = PyList_GetItem (list, i); 547 PyObject *value = PyDict_GetItem ((PyObject *) t, key); 548 #ifdef DEBUG 549 fprintf (stderr, ">> DEBUG VALUES : %s => %s\n", 550 PyString_AsString (key), PyString_AsString (value)); 551 #endif 552 553 if (strcmp (PyString_AsString (key), "value") == 0) 554 { 555 char *buffer = NULL; 556 Py_ssize_t size; 557 #if PY_MAJOR_VERSION >= 3 558 buffer = _PyUnicode_AsStringAndSize (value, &size); 559 #else 560 PyString_AsStringAndSize (value, &buffer, &size); 561 #endif 562 if (res != NULL) 563 { 564 addToMap (res, PyString_AsString (key), ""); 565 } 566 else 567 { 568 res = createMap (PyString_AsString (key), ""); 569 } 570 map *tmpR = getMap (res, "value"); 571 free (tmpR->value); 572 tmpR->value = (char *) malloc ((size + 1) * sizeof (char)); 573 memmove (tmpR->value, buffer, size * sizeof (char)); 574 tmpR->value[size] = 0; 575 char sin[1024]; 576 sprintf (sin, "%ld", size); 577 addToMap (res, "size", sin); 578 } 579 else 580 { 581 char *lkey = PyString_AsString (key); 582 char *lvalue = PyString_AsString (value); 583 if (res != NULL) 584 { 585 if (PyString_Size (value) > 0) 586 addToMap (res, lkey, lvalue); 587 } 588 else 589 { 590 if (PyString_Size (value) > 0) 591 res = createMap (lkey, lvalue); 592 } 593 } 594 } 595 Py_DECREF (list); 596 return res; 597 } 598 599 PyObject * 600 PythonTranslate (PyObject * self, PyObject * args) 601 { 602 char *str; 603 if (!PyArg_ParseTuple (args, "s", &str)) 604 { 605 #ifdef DEBUG 606 fprintf (stderr, "Incorrect arguments to update status function"); 607 #endif 325 608 return NULL; 326 609 } 327 Py_DECREF(name); 328 tmp=tmp->next; 329 } 330 return (PyDictObject*) res; 331 } 332 333 PyDictObject* PyDict_FromMap(map* t){ 334 PyObject* res=PyDict_New( ); 335 map* tmp=t; 336 int hasSize=0; 337 map* isArray=getMap(tmp,"isArray"); 338 map* size=getMap(tmp,"size"); 339 map* tmap=getMapType(tmp); 340 while(tmp!=NULL){ 341 PyObject* name=PyString_FromString(tmp->name); 342 if(strcasecmp(tmp->name,"value")==0) { 343 if(isArray!=NULL){ 344 map* len=getMap(tmp,"length"); 345 int cnt=atoi(len->value); 346 PyObject* value=PyList_New(cnt); 347 PyObject* mvalue=PyList_New(cnt); 348 PyObject* svalue=PyList_New(cnt); 349 350 for(int i=0;i<cnt;i++){ 351 352 map* vMap=getMapArray(tmp,"value",i); 353 map* sMap=getMapArray(tmp,"size",i); 354 355 if(vMap!=NULL){ 356 357 PyObject* lvalue; 358 PyObject* lsvalue; 359 if(sMap==NULL){ 360 lvalue=PyString_FromString(vMap->value); 361 lsvalue=Py_None; 362 } 363 else{ 364 lvalue=PyString_FromStringAndSize(vMap->value,atoi(sMap->value)); 365 lsvalue=PyString_FromString(sMap->value); 366 hasSize=1; 367 } 368 369 if(PyList_SetItem(value,i,lvalue)<0){ 370 fprintf(stderr,"Unable to set key value pair..."); 371 return NULL; 372 } 373 if(PyList_SetItem(svalue,i,lsvalue)<0){ 374 fprintf(stderr,"Unable to set key value pair..."); 375 return NULL; 376 } 377 } 378 379 map* mMap=getMapArray(tmp,tmap->name,i); 380 PyObject* lmvalue; 381 if(mMap!=NULL){ 382 lmvalue=PyString_FromString(mMap->value); 383 }else 384 lmvalue=Py_None; 385 386 if(PyList_SetItem(mvalue,i,lmvalue)<0){ 387 fprintf(stderr,"Unable to set key value pair..."); 388 return NULL; 389 } 390 391 } 392 393 if(PyDict_SetItem(res,name,value)<0){ 394 fprintf(stderr,"Unable to set key value pair..."); 395 return NULL; 396 } 397 if(PyDict_SetItem(res,PyString_FromString(tmap->name),mvalue)<0){ 398 fprintf(stderr,"Unable to set key value pair..."); 399 return NULL; 400 } 401 if(hasSize>0) 402 if(PyDict_SetItem(res,PyString_FromString("size"),svalue)<0){ 403 fprintf(stderr,"Unable to set key value pair..."); 404 return NULL; 405 } 406 } 407 else if(size!=NULL){ 408 PyObject* value=PyString_FromStringAndSize(tmp->value,atoi(size->value)); 409 if(PyDict_SetItem(res,name,value)<0){ 410 Py_DECREF(value); 411 fprintf(stderr,"Unable to set key value pair..."); 412 return NULL; 413 } 414 Py_DECREF(value); 415 } 416 else{ 417 PyObject* value=PyString_FromString(tmp->value); 418 if(PyDict_SetItem(res,name,value)<0){ 419 Py_DECREF(value); 420 fprintf(stderr,"Unable to set key value pair..."); 421 return NULL; 422 } 423 Py_DECREF(value); 424 } 425 } 426 else{ 427 if(PyDict_GetItem(res,name)==NULL){ 428 PyObject* value=PyString_FromString(tmp->value); 429 if(PyDict_SetItem(res,name,value)<0){ 430 Py_DECREF(value); 431 fprintf(stderr,"Unable to set key value pair..."); 432 return NULL; 433 } 434 Py_DECREF(value); 435 } 436 } 437 Py_DECREF(name); 438 tmp=tmp->next; 439 } 440 return (PyDictObject*) res; 441 } 442 443 maps* mapsFromPyDict(PyDictObject* t){ 444 maps* res=NULL; 445 maps* cursor=res; 446 PyObject* list=PyDict_Keys((PyObject*)t); 447 int nb=PyList_Size(list); 448 int i; 449 for(i=0;i<nb;i++){ 450 #ifdef DEBUG 451 fprintf(stderr,">> parsing maps %d\n",i); 452 #endif 453 PyObject* key=PyList_GetItem(list,i); 454 PyObject* value=PyDict_GetItem((PyObject*)t,key); 455 #ifdef DEBUG 456 fprintf(stderr,">> DEBUG VALUES : %s => %s\n", 457 PyString_AsString(key),PyString_AsString(value)); 458 #endif 459 cursor=(maps*)malloc(MAPS_SIZE); 460 cursor->name=PyString_AsString(key); 461 cursor->content=mapFromPyDict((PyDictObject*)value); 462 #ifdef DEBUG 463 dumpMap(cursor->content); 464 #endif 465 cursor->next=NULL; 466 if(res==NULL) 467 res=dupMaps(&cursor); 468 else 469 addMapsToMaps(&res,cursor); 470 freeMap(&cursor->content); 471 free(cursor->content); 472 free(cursor); 473 Py_DECREF(key); 474 #ifdef DEBUG 475 dumpMaps(res); 476 fprintf(stderr,">> parsed maps %d\n",i); 477 #endif 478 } 479 Py_DECREF(list); 480 return res; 481 } 482 483 map* mapFromPyDict(PyDictObject* t){ 484 map* res=NULL; 485 PyObject* list=PyDict_Keys((PyObject*)t); 486 int nb=PyList_Size(list); 487 int i; 488 for(i=0;i<nb;i++){ 489 PyObject* key=PyList_GetItem(list,i); 490 PyObject* value=PyDict_GetItem((PyObject*)t,key); 491 #ifdef DEBUG 492 fprintf(stderr,">> DEBUG VALUES : %s => %s\n", 493 PyString_AsString(key),PyString_AsString(value)); 494 #endif 495 496 if(strcmp(PyString_AsString(key),"value")==0){ 497 char *buffer=NULL; 498 Py_ssize_t size; 499 #if PY_MAJOR_VERSION >= 3 500 buffer=_PyUnicode_AsStringAndSize(value,&size); 501 #else 502 PyString_AsStringAndSize(value,&buffer,&size); 503 #endif 504 if(res!=NULL){ 505 addToMap(res,PyString_AsString(key),""); 506 }else{ 507 res=createMap(PyString_AsString(key),""); 508 } 509 map* tmpR=getMap(res,"value"); 510 free(tmpR->value); 511 tmpR->value=(char*)malloc((size+1)*sizeof(char)); 512 memmove(tmpR->value,buffer,size*sizeof(char)); 513 tmpR->value[size]=0; 514 char sin[1024]; 515 sprintf(sin,"%ld",size); 516 addToMap(res,"size",sin); 517 }else{ 518 char* lkey=PyString_AsString(key); 519 char* lvalue=PyString_AsString(value); 520 if(res!=NULL){ 521 if(PyString_Size(value)>0) 522 addToMap(res,lkey,lvalue); 523 } 524 else{ 525 if(PyString_Size(value)>0) 526 res=createMap(lkey,lvalue); 527 } 528 } 529 } 530 Py_DECREF(list); 531 return res; 532 } 533 534 PyObject* 535 PythonTranslate(PyObject* self, PyObject* args) 536 { 537 char *str; 538 if (!PyArg_ParseTuple(args, "s", &str)){ 539 #ifdef DEBUG 540 fprintf(stderr,"Incorrect arguments to update status function"); 541 #endif 542 return NULL; 543 } 544 return PyString_FromString(_ss(str)); 545 } 546 547 PyObject* 548 PythonUpdateStatus(PyObject* self, PyObject* args) 549 { 550 maps* conf; 551 PyObject* confdict; 610 return PyString_FromString (_ss (str)); 611 } 612 613 PyObject * 614 PythonUpdateStatus (PyObject * self, PyObject * args) 615 { 616 maps *conf; 617 PyObject *confdict; 552 618 int istatus; 553 char* status; 554 if (!PyArg_ParseTuple(args, "O!i", &PyDict_Type, &confdict, &istatus)){ 555 #ifdef DEBUG 556 fprintf(stderr,"Incorrect arguments to update status function"); 557 #endif 558 return NULL; 559 } 560 if (istatus < 0 || istatus > 100){ 561 PyErr_SetString(ZooError, "Status must be a percentage."); 562 return NULL; 563 }else{ 564 char tmpStatus[4]; 565 snprintf(tmpStatus, 4, "%i", istatus); 566 status = zStrdup(tmpStatus); 567 } 619 char *status; 620 if (!PyArg_ParseTuple (args, "O!i", &PyDict_Type, &confdict, &istatus)) 621 { 622 #ifdef DEBUG 623 fprintf (stderr, "Incorrect arguments to update status function"); 624 #endif 625 return NULL; 626 } 627 if (istatus < 0 || istatus > 100) 628 { 629 PyErr_SetString (ZooError, "Status must be a percentage."); 630 return NULL; 631 } 632 else 633 { 634 char tmpStatus[4]; 635 snprintf (tmpStatus, 4, "%i", istatus); 636 status = zStrdup (tmpStatus); 637 } 568 638 /* now update the map */ 569 639 { 570 PyObject* lenv = PyMapping_GetItemString(confdict, (char *)"lenv"); 571 if (lenv && PyMapping_Check(lenv)){ 572 PyObject* valobj = PyString_FromString(status); 573 PyMapping_SetItemString(lenv, (char *)"status", valobj); 574 Py_DECREF(valobj); 575 } 576 Py_DECREF(lenv); 640 PyObject *lenv = PyMapping_GetItemString (confdict, (char *) "lenv"); 641 if (lenv && PyMapping_Check (lenv)) 642 { 643 PyObject *valobj = PyString_FromString (status); 644 PyMapping_SetItemString (lenv, (char *) "status", valobj); 645 Py_DECREF (valobj); 646 } 647 Py_DECREF (lenv); 577 648 } 578 conf = mapsFromPyDict((PyDictObject*)confdict); 579 if (getMapFromMaps(conf,"lenv","status") != NULL){ 580 if(status!=NULL){ 581 setMapInMaps(conf,"lenv","status",status); 582 free(status); 583 } 584 else 585 setMapInMaps(conf,"lenv","status","15"); 586 _updateStatus(conf); 587 } 588 freeMaps(&conf); 589 free(conf); 649 conf = mapsFromPyDict ((PyDictObject *) confdict); 650 if (getMapFromMaps (conf, "lenv", "status") != NULL) 651 { 652 if (status != NULL) 653 { 654 setMapInMaps (conf, "lenv", "status", status); 655 free (status); 656 } 657 else 658 setMapInMaps (conf, "lenv", "status", "15"); 659 _updateStatus (conf); 660 } 661 freeMaps (&conf); 662 free (conf); 590 663 Py_RETURN_NONE; 591 664 } -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/service_zcfg.c
r512 r531 124 124 { 125 125 GList *l; 126 int i = 0; 126 127 for (l = serviceCfgList; l; l = l->next) 127 128 { 129 #ifdef DEBUG 130 fprintf (stderr, "%d ### %s ###\n", i, 131 ((service *) (l->data))->identifier); 132 i++; 133 #endif 128 134 if (strcasecmp (identifier, ((service *) (l->data))->identifier) == 0) 129 135 return (service *) l->data; -
branches/PublicaMundi_David-devel/zoo-project/zoo-kernel/zoo_service_loader.c
r524 r531 38 38 #include <libxml/xpathInternals.h> 39 39 #include "service_zcfg.h" 40 #include <libgen.h> 40 41 } 41 42 #include "ulinet.h" … … 211 212 } 212 213 214 /** 213 215 int 214 216 recursReaddirF (maps * m, xmlNodePtr n, char *conf_dir, char *prefix, … … 334 336 return 1; 335 337 } 336 338 **/ 337 339 xmlXPathObjectPtr 338 340 extractFromDoc (xmlDocPtr doc, const char *search) … … 408 410 */ 409 411 map *r_inputs = NULL; 410 #ifndef WIN32411 getcwd (ntmp, 1024);412 #else413 _getcwd (ntmp, 1024);414 #endif415 412 r_inputs = getMap (s1->content, "serviceType"); 416 413 #ifdef DEBUG … … 421 418 && strncasecmp (r_inputs->value, "C", 1) == 0) 422 419 { 423 r_inputs = getMap (request_inputs, "metapath"); 424 if (r_inputs != NULL) 425 sprintf (tmps1, "%s/%s", ntmp, r_inputs->value); 426 else 427 sprintf (tmps1, "%s/", ntmp); 428 char *altPath = zStrdup (tmps1); 420 char *tmp_path = 421 (char *) malloc ((strlen (s1->zcfg) + 1) * sizeof (char *)); 422 sprintf (tmp_path, "%s", s1->zcfg); 423 char *dir = dirname (tmp_path); 429 424 r_inputs = getMap (s1->content, "ServiceProvider"); 430 sprintf (tmps1, "%s/%s", altPath, r_inputs->value);431 free ( altPath);425 sprintf (tmps1, "%s/%s", dir, r_inputs->value); 426 free (tmp_path); 432 427 #ifdef DEBUG 433 428 fprintf (stderr, "Trying to load %s\n", tmps1); … … 1264 1259 sprintf (tmpMsg, 1265 1260 _ 1266 ("The value for <i ndetifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."),1261 ("The value for <identifier> seems to be wrong (%s). Please, ensure that the process exist using the GetCapabilities request."), 1267 1262 r_inputs->value); 1268 1263 errorException (m, tmpMsg, "InvalidParameterValue", "identifier"); 1269 1264 free (tmpMsg); 1270 free (s1);1265 //free (s1); 1271 1266 freeMaps (&m); 1272 1267 free (m); … … 1460 1455 InternetCloseHandle (&hInternet); 1461 1456 //freeService (&s1); 1462 free (s1);1457 //free (s1); 1463 1458 return 0; 1464 1459 } … … 1624 1619 InternetCloseHandle (&hInternet); 1625 1620 //freeService (&s1); 1626 free (s1);1621 //free (s1); 1627 1622 return 0; 1628 1623 } … … 1646 1641 InternetCloseHandle (&hInternet); 1647 1642 //freeService (&s1); 1648 free (s1);1643 //free (s1); 1649 1644 return 0; 1650 1645 } … … 1681 1676 InternetCloseHandle (&hInternet); 1682 1677 //freeService (&s1); 1683 free (s1);1678 //free (s1); 1684 1679 return 0; 1685 1680 } … … 1749 1744 { 1750 1745 xmlChar *val = xmlNodeListGetString (doc, 1751 cur2-> 1752 xmlChildrenNode, 1746 cur2->xmlChildrenNode, 1753 1747 1); 1754 1748 if (tmpmaps == NULL) … … 1779 1773 { 1780 1774 xmlChar *val = xmlNodeListGetString (doc, 1781 cur2-> 1782 xmlChildrenNode, 1775 cur2->xmlChildrenNode, 1783 1776 1); 1784 1777 if (tmpmaps == NULL) … … 1866 1859 InternetCloseHandle (&hInternet); 1867 1860 //freeService (&s1); 1868 free (s1);1861 //free (s1); 1869 1862 return 0; 1870 1863 } … … 2216 2209 { 2217 2210 xmlChar *mv = xmlNodeListGetString (doc, 2218 cur4->xmlChildrenNode, 2211 cur4-> 2212 xmlChildrenNode, 2219 2213 1); 2220 2214 map *ltmp = getMap (tmpmaps->content, … … 2262 2256 { 2263 2257 xmlChar *tmp = xmlNodeListGetRawString (doc, 2264 cur4->xmlChildrenNode, 2258 cur4-> 2259 xmlChildrenNode, 2265 2260 0); 2266 2261 addToMap (tmpmaps->content, … … 2331 2326 InternetCloseHandle (&hInternet); 2332 2327 //freeService (&s1); 2333 free (s1);2328 //free (s1); 2334 2329 return 0; 2335 2330 } … … 2429 2424 { 2430 2425 xmlChar *val = xmlNodeListGetString (NULL, 2431 cur2-> 2432 xmlChildrenNode, 2426 cur2->xmlChildrenNode, 2433 2427 1); 2434 2428 free (tmpmaps->name); … … 2517 2511 { 2518 2512 xmlChar *val = xmlNodeListGetString (doc, 2519 cur1-> 2520 xmlChildrenNode, 2513 cur1->xmlChildrenNode, 2521 2514 1); 2522 2515 if (tmpmaps == NULL) … … 2578 2571 { 2579 2572 xmlChar *val = xmlNodeListGetString (doc, 2580 cur1-> 2581 xmlChildrenNode, 2573 cur1->xmlChildrenNode, 2582 2574 1); 2583 2575 if (tmpmaps == NULL) … … 2655 2647 { 2656 2648 xmlChar *val = xmlNodeListGetString (doc, 2657 cur2->xmlChildrenNode, 2649 cur2-> 2650 xmlChildrenNode, 2658 2651 1); 2659 2652 if (tmpmaps == NULL) … … 2695 2688 { 2696 2689 xmlChar *val = xmlNodeListGetString (doc, 2697 cur2->xmlChildrenNode, 2690 cur2-> 2691 xmlChildrenNode, 2698 2692 1); 2699 2693 if (tmpmaps == NULL) … … 2797 2791 printExceptionReportResponse (m, tmpe); 2798 2792 //freeService (&s1); 2799 free (s1);2793 //free (s1); 2800 2794 freeMap (&tmpe); 2801 2795 free (tmpe); … … 3027 3021 "InvalidParameterValue", "storeExecuteResponse"); 3028 3022 //freeService (&s1); 3029 free (s1);3023 //free (s1); 3030 3024 freeMaps (&m); 3031 3025 free (m); … … 3349 3343 3350 3344 //freeService (&s1); 3351 free (s1);3345 //free (s1); 3352 3346 freeMaps (&m); 3353 3347 free (m);
Note: See TracChangeset
for help on using the changeset viewer.