Index: trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service.h	(revision 457)
+++ trunk/zoo-project/zoo-kernel/service.h	(revision 458)
@@ -254,52 +254,4 @@
   }
 
-  static char* getMapsAsKVP(maps* m,int length,int type){
-    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
-    maps* curs=m;
-    int i=0;
-    while(curs!=NULL){
-      map *inRequest=getMap(curs->content,"inRequest");
-      if(strncasecmp(inRequest->value,"true",4)==0){
-	if(i==0)
-	  if(type==0)
-	    sprintf(dataInputsKVP,"%s=",curs->name);
-	  else
-	    sprintf(dataInputsKVP,"%s",curs->name);
-	else{
-	  char *temp=zStrdup(dataInputsKVP);
-	  if(type==0)
-	    sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
-	  else
-	    sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
-	  free(temp);
-	}
-	map* icurs=curs->content;
-	if(type==0){
-	  char *temp=zStrdup(dataInputsKVP);
-	  if(getMap(m->content,"xlink:href")!=NULL)
-	    sprintf(dataInputsKVP,"%sReference",temp);
-	  else
-	    sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
-	  free(temp);
-	}
-	while(icurs!=NULL){
-	  if(strcasecmp(icurs->name,"value")!=0 &&
-	     strcasecmp(icurs->name,"Reference")!=0 &&
-	     strcasecmp(icurs->name,"minOccurs")!=0 &&
-	     strcasecmp(icurs->name,"maxOccurs")!=0 &&
-	     strcasecmp(icurs->name,"inRequest")!=0){
-	    char *itemp=zStrdup(dataInputsKVP);
-	    sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
-	    free(itemp);
-	  }
-	  icurs=icurs->next;
-	}
-      }
-      curs=curs->next;
-      i++;
-    }
-    return dataInputsKVP;
-  }
-
 
   static void freeMap(map** mo){
@@ -909,4 +861,86 @@
   }
 
+#ifdef WIN32
+  extern char *url_encode(char *);
+
+  static char* getMapsAsKVP(maps* m,int length,int type){
+    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
+    char *dataInputsKVPi=NULL;
+    maps* curs=m;
+    int i=0;
+    while(curs!=NULL){
+      map *inRequest=getMap(curs->content,"inRequest");
+      map *hasLength=getMap(curs->content,"length");
+      if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
+	 inRequest==NULL){
+	if(i==0)
+	  if(type==0){
+	    sprintf(dataInputsKVP,"%s=",curs->name);
+	    if(hasLength!=NULL){
+	      dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
+	      sprintf(dataInputsKVPi,"%s=",curs->name);
+	    }
+	  }
+	  else
+	    sprintf(dataInputsKVP,"%s",curs->name);
+	else{
+	  char *temp=zStrdup(dataInputsKVP);
+	  if(type==0)
+	    sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
+	  else
+	    sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
+	}
+	map* icurs=curs->content;
+	if(type==0){
+	  char *temp=zStrdup(dataInputsKVP);
+	  if(getMap(curs->content,"xlink:href")!=NULL)
+	    sprintf(dataInputsKVP,"%sReference",temp);
+	  else{
+	    if(hasLength!=NULL){
+	      for(int j=0;j<atoi(hasLength->value);j++){
+		map* tmp0=getMapArray(curs->content,"value",j);
+		if(j==0)
+		  free(temp);
+		temp=zStrdup(dataInputsKVP);
+		if(j==0)
+		  sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
+		else
+		  sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
+	      }
+	    }
+	    else
+	      sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
+	  }
+	  free(temp);
+	}
+	while(icurs!=NULL){
+	  if(strncasecmp(icurs->name,"value",5)!=0 &&
+	     strncasecmp(icurs->name,"mimeType_",9)!=0 &&
+	     strncasecmp(icurs->name,"dataType_",9)!=0 &&
+	     strncasecmp(icurs->name,"size",4)!=0 &&
+	     strncasecmp(icurs->name,"length",4)!=0 &&
+	     strncasecmp(icurs->name,"isArray",7)!=0 &&
+	     strcasecmp(icurs->name,"Reference")!=0 &&
+	     strcasecmp(icurs->name,"minOccurs")!=0 &&
+	     strcasecmp(icurs->name,"maxOccurs")!=0 &&
+	     strncasecmp(icurs->name,"fmimeType",9)!=0 &&
+	     strcasecmp(icurs->name,"inRequest")!=0){
+	    char *itemp=zStrdup(dataInputsKVP);
+	    if(strcasecmp(icurs->name,"xlink:href")!=0)
+	      sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
+	    else
+	      sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
+	    free(itemp);
+	  }
+	  icurs=icurs->next;
+	}
+      }
+      curs=curs->next;
+      i++;
+    }
+    return dataInputsKVP;
+  }
+#endif
+
 #ifdef __cplusplus
 }
Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 457)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 458)
@@ -287,5 +287,4 @@
   }
   if(getMapFromMaps(conf,"lenv","status")!=NULL){
-    fprintf(stderr,"STATUS RETURNED : %s\n",status);
     if(status!=NULL){
       setMapInMaps(conf,"lenv","status",status);
@@ -1641,4 +1640,5 @@
 			    (strncmp(tmp2->value,"application/",12)==0) &&
 			    strncmp(tmp2->value,"application/json",16)!=0&&
+			    strncmp(tmp2->value,"application/x-javascript",24)!=0&&
 			    strncmp(tmp2->value,"application/vnd.google-earth.kml",32)!=0)
 	     )) {
@@ -2004,9 +2004,10 @@
 	map *tmp3=getMapFromMaps(m,"main","serverAddress");
 	char *file_url;
-	if(strncasecmp(tmp2->value,"http://",7)==0){
-	  file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name))*sizeof(char));
+	if(strncasecmp(tmp2->value,"http://",7)==0 ||
+	   strncasecmp(tmp2->value,"https://",8)==0){
+	  file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
 	  sprintf(file_url,"%s/%s",tmp2->value,file_name);
 	}else{
-	  file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name))*sizeof(char));
+	  file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
 	  sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
 	}
Index: trunk/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 457)
+++ trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 458)
@@ -923,20 +923,19 @@
     if(strncasecmp(mime->value,"application/json",16)==0)
       ext="json";
-  
+
   map* tmpMap=getMapFromMaps(conf,"main","dataPath");
   map* sidMap=getMapFromMaps(conf,"lenv","usid");
   char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
-  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext);
-  int f=open(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+  sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext); 
+  int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
   map* sizeMap=getMap(outputs->content,"size");
   map* vData=getMap(outputs->content,"value");
   if(sizeMap!=NULL){
-    write(f,vData->value,atoi(sizeMap->value)*sizeof(char));
+    zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
   }
   else{
-    write(f,vData->value,strlen(vData->value)*sizeof(char));
+    zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
   }
   close(f);
-  //exit(-1);
   addToMap(outputs->content,"storage",pszDataSource);
 
@@ -1090,5 +1089,5 @@
   map* sid=getMapFromMaps(conf,"lenv","usid");
   char *mapPath=
-    (char*)malloc((16+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
+    (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
   sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
   msSaveMap(myMap,mapPath);
Index: trunk/zoo-project/zoo-kernel/service_internal_python.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_python.c	(revision 457)
+++ trunk/zoo-project/zoo-kernel/service_internal_python.c	(revision 458)
@@ -544,5 +544,4 @@
   conf = mapsFromPyDict((PyDictObject*)confdict);
   if (getMapFromMaps(conf,"lenv","status") != NULL){
-    fprintf(stderr,"STATUS RETURNED : %s\n",status);
     if(status!=NULL){
       setMapInMaps(conf,"lenv","status",status);
Index: trunk/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 457)
+++ trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 458)
@@ -114,5 +114,5 @@
 	 if(strQuery==NULL || strlen(strQuery)==0)
 	   tmpMap=createMap("request",res);
-       }
+            }
     }else{
       char *buffer=new char[cgiContentLength+1];
@@ -177,4 +177,19 @@
   }
 
+#ifdef WIN32
+  map *tmpReq=getMap(tmpMap,"rfile");
+  if(tmpReq!=NULL){
+    FILE *lf=fopen(tmpReq->value,"r");
+    fseek(lf,0,SEEK_END);
+    long flen=ftell(lf);
+    fseek(lf,0,SEEK_SET);
+    char *buffer=(char*)malloc((flen+1)*sizeof(char));
+    fread(buffer,flen,1,lf);
+    fclose(lf);
+    addToMap(tmpMap,"request",buffer);
+    free(buffer);
+    cgiContentLength=flen+9;
+  }
+#endif
   /**
    * In case that the POST method was used, then check if params came in XML
@@ -183,5 +198,9 @@
    */
   if(strncasecmp(cgiRequestMethod,"post",4)==0 || 
-     (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0)){
+     (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0) 
+#ifdef WIN32
+     ||tmpReq!=NULL
+#endif
+     ){
     /**
      * First include the MetaPath and the ServiceProvider default parameters
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 457)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 458)
@@ -478,8 +478,9 @@
   map *tmpPath=getMapFromMaps(m,"lenv","cwd");
 
+  map *tmpReq=getMap(request_inputs,"xrequest");
   if(r_inputs2!=NULL){
     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,dataOutputsKVP,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,"\"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);
@@ -492,5 +493,5 @@
   }
   char *tmp1=zStrdup(tmp);
-  sprintf(tmp,"zoo_loader.cgi %s \"%s\"",tmp1,sid->value);
+  sprintf(tmp,"\"zoo_loader.cgi\" %s \"%s\"",tmp1,sid->value);
   
   free(dataInputsKVP);
@@ -504,5 +505,5 @@
   sprintf(clen,"%d",strlen(tmpq));
   SetEnvironmentVariable("CONTENT_LENGTH",TEXT(clen));
-
+  
   if( !CreateProcess( NULL,             // No module name (use command line)
 		      TEXT(tmp),        // Command line
@@ -517,5 +518,4 @@
       ) 
     { 
-      //printf("CreateProcess failed (%d).\n",GetLastError() );
 #ifdef DEBUG
       fprintf( stderr, "CreateProcess failed (%d).\n", GetLastError() );
@@ -523,5 +523,4 @@
       return ;
     }else{
-    //printf("CreateProcess successfull (%d).\n",GetLastError() );
 #ifdef DEBUG
     fprintf( stderr, "CreateProcess successfull (%d).\n\n\n\n", GetLastError() );
@@ -530,5 +529,4 @@
   CloseHandle( pi.hProcess );
   CloseHandle( pi.hThread );
-  //printf("CreateProcess finished !\n");
 #ifdef DEBUG
   fprintf(stderr,"CreateProcess finished !\n");
@@ -600,5 +598,5 @@
   map* fstdem=getMapFromMaps(m,"main","logPath");
   if(fstdem!=NULL)
-	fstde = freopen(fstdem->value, "a+", stderr) ;
+    fstde = freopen(fstdem->value, "a+", stderr) ;
 
   r_inputs=getMap(request_inputs,"language");
@@ -2247,5 +2245,4 @@
     setMapInMaps(m,"lenv","sid",test1->value);
     status=getMap(request_inputs,"status");
-    printf("cgiSid %s\n",cgiSid);
   }
 #endif
@@ -2274,8 +2271,5 @@
       pid=0;
       cpid=atoi(cgiSid);
-      printf("cgiSid %s\n",cgiSid);
-    }
-    //printf("pid cpid %d %d\n",pid,cpid);
-    //fflush(stderr);
+    }
 #endif
     if (pid > 0) {
@@ -2304,7 +2298,9 @@
       fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
 #endif
-      freopen(flog,"w+",stderr);
+      freopen(flog, "w+", stderr);
       f0=freopen(fbkp , "w+", stdout);
+#ifndef WIN32
       fclose(stdin);
+#endif
       free(flog);
       /**
@@ -2359,5 +2355,5 @@
 #endif
 
-  if(((int)getpid())!=cpid){
+  if(((int)getpid())!=cpid || cgiSid!=NULL){
     fclose(stdout);
     fclose(stderr);
@@ -2376,5 +2372,5 @@
     char *tmps1=(char*)malloc((flen+1)*sizeof(char));
     fread(tmps1,flen,1,f2);
-    fwrite(tmps1,1,flen+1,f3);
+    fwrite(tmps1,1,flen,f3);
     fclose(f2);
     fclose(f3);
