Index: trunk/zoo-project/zoo-kernel/makefile.vc
===================================================================
--- trunk/zoo-project/zoo-kernel/makefile.vc	(revision 383)
+++ trunk/zoo-project/zoo-kernel/makefile.vc	(revision 384)
@@ -62,5 +62,5 @@
 
 zoo_loader.cgi: zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj dirent.obj
-	link zoo_loader.obj dirent.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj /out:zoo_loader.cgi $(LDFLAGS)
+	link zoo_loader.obj dirent.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj /out:zoo_loader.cgi $(LDFLAGS) $(LDFLAGSCGI)
 
 clean:
Index: trunk/zoo-project/zoo-kernel/nmake.opt
===================================================================
--- trunk/zoo-project/zoo-kernel/nmake.opt	(revision 383)
+++ trunk/zoo-project/zoo-kernel/nmake.opt	(revision 384)
@@ -38,3 +38,4 @@
 CFLAGS=$(CFLAGS1) /nologo /MD /W3 /EHsc /Ox /D_CRT_SECURE_NO_WARNINGS /DWIN32 $(CJFLAGS) -I$(ZOOK_DIR) -I./ $(JAVA_CFLAGS) $(MS_CFLAGS) -I$(TROOT)\..\..\thirds\dirent-win32 -I$(INTL_DIR) -I$(CURL_DIR)\include -I$(XML2_DIR)\include -I$(GDAL_DIR)\port $(JS_CFLAGS) -I$(GDAL_DIR)\ogr -I$(GDAL_DIR)\gcore -I$(GD_DIR) -I$(ICONV_DIR) -I$(TROOT)\..\..\thirds\include -I$(TROOT)\..\..\thirds\cgic206 -I$(PYTHON_CPATH)\include -I$(SSL_DIR)/inc32 -I$(FCGI_DIR)\include $(PY_CFLAGS) -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
 
-LDFLAGS=$(FCGI_LIBRARY) $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(TROOT)/../../thirds/cgic206/libcgic.lib $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) /machine:i386
+LDFLAGSCGI=$(TROOT)/../../thirds/cgic206/libcgic.lib 
+LDFLAGS=$(FCGI_DIR)/libfcgi/Release/libfcgi.lib $(CURL_LIBRARY) $(PY_LDFLAGS) $(XML2_LIBRARY) $(SSL_DIR)/out32dll/libeay32.lib $(JAVA_LDFLAGS) $(SSL_DIR)/out32dll/ssleay32.lib $(MS_LDFLAGS) $(INTL_DIR)/intl.lib $(XML2_DIR)/win32/bin.msvc/libxml2.lib $(GDAL_DIR)/gdal_i.lib $(CURL_DIR)/lib/libcurl.lib $(JS_LDFLAGS) /machine:i386
Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 383)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 384)
@@ -78,49 +78,39 @@
 
 void updateStatus(maps *conf){
-	fprintf(stderr,"OK Final 1 \n");
-	fflush(stderr);
-	LPWSTR lpszTmp;
-	BOOL fInit;
-	char *s=NULL;
-	map *tmpMap=getMapFromMaps(conf,"lenv","sid");
-	fprintf(stderr,"OK Final 11 \n");
-	fflush(stderr);
-	if(hMapObjectG==NULL)
-	hMapObjectG = CreateFileMapping( 
-		INVALID_HANDLE_VALUE,   // use paging file
-		NULL,                   // default security attributes
-		PAGE_READWRITE,         // read/write access
-		0,                      // size: high 32-bits
-		SHMEMSIZE,              // size: low 32-bits
-		TEXT(tmpMap->value));   // name of map object
-	if (hMapObjectG == NULL){
-		fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value);
-		return ;
-	}
-	fprintf(stderr,"OK Final 2 \n");
-	fflush(stderr);
-	fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
-	if(lpvMemG==NULL)
-	lpvMemG = MapViewOfFile( 
-		hMapObjectG,     // object to map view of
-		FILE_MAP_WRITE, // read/write access
-		0,              // high offset:  map from
-		0,              // low offset:   beginning
-		0);             // default: map entire file
-	if (lpvMemG == NULL){
-		fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value);
-		return ;
-	} 
-	fprintf(stderr,"OK Final 3 \n");
-	fflush(stderr);
-	if (fInit)
-		memset(lpvMemG, '\0', SHMEMSIZE);
-	fprintf(stderr,"OK Final 4 \n");
-	fflush(stderr);
-	tmpMap=getMapFromMaps(conf,"lenv","status");
-	lpszTmp = (LPWSTR) lpvMemG;
-	for(s=tmpMap->value;*s!=NULL;s++)
-		*lpszTmp++ = *s;
-	*lpszTmp = '\0'; 
+  LPWSTR lpszTmp;
+  BOOL fInit;
+  char *s=NULL;
+  map *tmpMap=getMapFromMaps(conf,"lenv","sid");
+  if(hMapObjectG==NULL)
+    hMapObjectG = CreateFileMapping( 
+				    INVALID_HANDLE_VALUE,   // use paging file
+				    NULL,                   // default security attributes
+				    PAGE_READWRITE,         // read/write access
+				    0,                      // size: high 32-bits
+				    SHMEMSIZE,              // size: low 32-bits
+				    TEXT(tmpMap->value));   // name of map object
+  if (hMapObjectG == NULL){
+    fprintf(stderr,"Unable to create share memory segment %s !! \n",tmpMap->value);
+    return ;
+  }
+  fInit = (GetLastError() != ERROR_ALREADY_EXISTS); 
+  if(lpvMemG==NULL)
+    lpvMemG = MapViewOfFile( 
+			    hMapObjectG,     // object to map view of
+			    FILE_MAP_WRITE, // read/write access
+			    0,              // high offset:  map from
+			    0,              // low offset:   beginning
+			    0);             // default: map entire file
+  if (lpvMemG == NULL){
+    fprintf(stderr,"Unable to create or access the shared memory segment %s !! \n",tmpMap->value);
+    return ;
+  } 
+  if (fInit)
+    memset(lpvMemG, '\0', SHMEMSIZE);
+  tmpMap=getMapFromMaps(conf,"lenv","status");
+  lpszTmp = (LPWSTR) lpvMemG;
+  for(s=tmpMap->value;*s!=NULL;s++)
+    *lpszTmp++ = *s;
+  *lpszTmp = '\0'; 
 }
 
@@ -159,10 +149,5 @@
     return "-1"; 
   lpszTmp = (LPWSTR) lpvMem;
-  while (*lpszTmp!=NULL)
-    *lpszBuf++ = *lpszTmp++;
-  *lpszBuf = '\0';
-  fIgnore = UnmapViewOfFile(lpvMem); 
-  fIgnore = CloseHandle(hMapObject);
-  return (char*)lpszBuf;
+  return (char*)lpszTmp;
 }
 
@@ -1391,4 +1376,5 @@
   char *encoding=getEncoding(m);
   if(pid==getpid()){
+    printHeaders(m);
     printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
   }
@@ -1745,5 +1731,4 @@
   xmlNodePtr n;
 
-  printHeaders(m);
   doc = xmlNewDoc(BAD_CAST "1.0");
   maps* tmpMap=getMaps(m,"main");
@@ -1752,9 +1737,13 @@
     map *tmpSid=getMapFromMaps(m,"lenv","sid");
     if(tmpSid!=NULL){
-      if( getpid()==atoi(tmpSid->value) )
+      if( getpid()==atoi(tmpSid->value) ){
+	printHeaders(m);
 	printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
-    }
-    else
+      }
+    }
+    else{
+      printHeaders(m);
       printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+    }
   }else
     printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
@@ -1862,6 +1851,4 @@
   }
   
-  printHeaders(m);
-
   if(asRaw==0){
 #ifdef DEBUG
@@ -2007,5 +1994,5 @@
 	if(rs!=NULL)
 	  printf("Content-Length: %s\r\n",rs->value);
-
+	printHeaders(m);
 	char mime[1024];
 	map* mi=getMap(tmpI->content,"mimeType");
Index: trunk/zoo-project/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 383)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 384)
@@ -103,5 +103,5 @@
   
   /* Create a context. */
-  cx = JS_NewContext(rt,81920);
+  cx = JS_NewContext(rt,8192);
   if (cx == NULL){
     return 1;
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 383)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 384)
@@ -431,4 +431,5 @@
 }
 
+
 #ifdef WIN32
 /**
@@ -449,9 +450,16 @@
   char *dataInputsKVP=getMapsAsKVP(inputs,cgiContentLength,0);
   char *dataOutputsKVP=getMapsAsKVP(outputs,cgiContentLength,1);
+#ifdef DEBUG
   fprintf(stderr,"DATAINPUTSKVP %s\n",dataInputsKVP);
   fprintf(stderr,"DATAOUTPUTSKVP %s\n",dataOutputsKVP);
+#endif
   map *sid=getMapFromMaps(m,"lenv","sid");
   map* r_inputs=getMapFromMaps(m,"main","tmpPath");
-  map* r_inputs1=getMap(s1->content,"ServiceProvider");
+  map* r_inputs1=getMap(request_inputs,"metapath");
+  int hasIn=-1;
+  if(r_inputs1==NULL){
+    r_inputs1=createMap("metapath","");
+    hasIn=1;
+  }
   map* r_inputs2=getMap(s1->content,"ResponseDocument");
   if(r_inputs2==NULL)
@@ -460,18 +468,25 @@
 
   if(r_inputs2!=NULL){
-    sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,r_inputs2->name,r_inputs2->value,sid->value);
-	sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP);
+    sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,r_inputs2->value,sid->value);
+    sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&%s=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,r_inputs2->name,dataOutputsKVP);
   }
   else{
-    sprintf(tmp,"\"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",req->value,id->value,dataInputsKVP,sid->value);
-    sprintf(tmpq,"request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",req->value,id->value,dataInputsKVP,sid->value);
-  }
-
+    sprintf(tmp,"\"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s&cgiSid=%s\"",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value);
+    sprintf(tmpq,"metapath=%s&request=%s&service=WPS&version=1.0.0&Identifier=%s&DataInputs=%s",r_inputs1->value,req->value,id->value,dataInputsKVP,sid->value);
+  }
+  
+  if(hasIn>0){
+    freeMap(&r_inputs1);
+    free(r_inputs1);
+  }
   char *tmp1=strdup(tmp);
   sprintf(tmp,"zoo_loader.cgi %s \"%s\"",tmp1,sid->value);
-
+  
   free(dataInputsKVP);
   free(dataOutputsKVP);
+  //printf("REQUEST IS : %s \n",tmp);
+#ifdef DEBUG
   fprintf(stderr,"REQUEST IS : %s \n",tmp);
+#endif
   SetEnvironmentVariable("CGISID",TEXT(sid->value));
   SetEnvironmentVariable("QUERY_STRING",TEXT(tmpq));
@@ -492,12 +507,21 @@
       ) 
     { 
+      //printf("CreateProcess failed (%d).\n",GetLastError() );
+#ifdef DEBUG
       fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() );
+#endif
       return ;
     }else{
+    //printf("CreateProcess successfull (%d).\n",GetLastError() );
+#ifdef DEBUG
     fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() );
+#endif
   }
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );
+  //printf("CreateProcess finished !\n");
+#ifdef DEBUG
   fprintf(stderr,"CreateProcess finished !\n");
+#endif
 }
 #endif
@@ -1701,6 +1725,5 @@
 	}
 	/**
-	 * Get every attribute from a LiteralData node
-	 * storeExecuteResponse, lineage, status
+	 * Get every attribute: storeExecuteResponse, lineage, status
 	 */
 	const char *ress[3]={"storeExecuteResponse","lineage","status"};
@@ -1742,6 +1765,8 @@
 	      tmpmaps->next=NULL;
 	    }
-	    else
-	      tmpmaps->name=strdup((char*)val);;
+	    else{
+	      //free(tmpmaps->name);
+	      tmpmaps->name=strdup((char*)val);
+	    }
 	    xmlFree(val);
 	  }
@@ -1764,9 +1789,7 @@
 	    else{
 	      if(tmpmaps->content!=NULL)
-		addToMap(tmpmaps->content,
-			 (char*)cur1->name,(char*)val);
+		addToMap(tmpmaps->content,(char*)cur1->name,(char*)val);
 	      else
-		tmpmaps->content=
-		  createMap((char*)cur1->name,(char*)val);
+		tmpmaps->content=createMap((char*)cur1->name,(char*)val);
 	    }
 	    xmlFree(val);
@@ -1795,4 +1818,6 @@
 	    }
 	    xmlNodePtr cur2=cur1->children;
+	    while(cur2!=NULL && cur2->type != XML_ELEMENT_NODE)
+	      cur2=cur2->next;
 	    while(cur2){
 	      /**
@@ -2125,12 +2150,14 @@
   if(test1!=NULL){
     cgiSid=test1->value;
-  }
-  if(cgiSid!=NULL){
     addToMap(request_inputs,"storeExecuteResponse","true");
     addToMap(request_inputs,"status","true");
+    setMapInMaps(m,"lenv","sid",test1->value);
     status=getMap(request_inputs,"status");
-    //fprintf(stderr,"cgiSID : %s",cgiSid);
-  }
-#endif
+    printf("cgiSid %s\n",cgiSid);
+  }
+#endif
+  int hrstd=-1;
+  char *fbkp,*fbkp1;
+  FILE *f0,*f1;
   if(status!=NULL)
     if(strcasecmp(status->value,"false")==0)
@@ -2149,5 +2176,4 @@
 #else
     if(cgiSid==NULL){
-      addToMap(request_inputs,"cgSid",cgiSid);
       createProcess(m,request_inputs,s1,NULL,cpid,request_input_real_format,request_output_real_format);
       pid = cpid;
@@ -2155,6 +2181,8 @@
       pid=0;
       cpid=atoi(cgiSid);
-    }
-    fflush(stderr);
+      printf("cgiSid %s\n",cgiSid);
+    }
+    //printf("pid cpid %d %d\n",pid,cpid);
+    //fflush(stderr);
 #endif
     if (pid > 0) {
@@ -2174,7 +2202,7 @@
       r_inputs=getMapFromMaps(m,"main","tmpPath");
       map* r_inputs1=getMap(s1->content,"ServiceProvider");
-      char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char));
+      fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
       sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid);
-      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+100)*sizeof(char));
+      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
       sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid);
 #ifdef DEBUG
@@ -2184,7 +2212,6 @@
 #endif
       freopen(flog,"w+",stderr);
-      freopen(fbkp , "w+", stdout);
+      f0=freopen(fbkp , "w+", stdout);
       fclose(stdin);
-      free(fbkp);
       free(flog);
       /**
@@ -2194,5 +2221,4 @@
        * this way the data will be updated at the end of the process run.
        */
-      updateStatus(m);
       printProcessResponse(m,request_inputs,cpid,
 			   s1,r_inputs1->value,SERVICE_STARTED,
@@ -2202,8 +2228,10 @@
       fflush(stdout);
       rewind(stdout);
-#endif
-
+#else
+#endif
+      fbkp1=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+1024)*sizeof(char));
+      sprintf(fbkp1,"%s/%s_final_%d.xml",r_inputs->value,r_inputs1->value,cpid);
+      f1=freopen(fbkp1 , "w+", stdout);
       loadServiceAndRun(&m,s1,request_inputs,&request_input_real_format,&request_output_real_format,&eres);
-
     } else {
       /**
@@ -2242,4 +2270,21 @@
     fclose(stderr);
     unhandleStatus(m);
+    /**
+     * Dump back the final file fbkp1 to fbkp
+     */
+    fclose(f0);
+    fclose(f1);
+    FILE* f2=fopen(fbkp1,"rb");
+    FILE* f3=fopen(fbkp,"wb+");
+    free(fbkp);
+    free(fbkp1);
+    fseek(f2,0,SEEK_END);
+    long flen=ftell(f2);
+    fseek(f2,0,SEEK_SET);
+    char *tmps1=(char*)malloc((flen+1)*sizeof(char));
+    fread(tmps1,flen,1,f2);
+    fwrite(tmps1,1,flen,f3);
+    fclose(f2);
+    fclose(f3);
   }
 
