Index: branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 860)
@@ -272,6 +272,6 @@
     
     if(i>0){
+      sprintf(cname,"cache_file_%d",i);
       tmp1=getMap(content->content,cname);
-      sprintf(cname,"cache_file_%d",i);
       sprintf(vname,"value_%d",i);
       sprintf(sname,"size_%d",i);
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 860)
@@ -2465,5 +2465,7 @@
   else
     exceptionCode="501 Internal Server Error";
-
+  tmp=getMapFromMaps(m,"lenv","status_code");
+  if(tmp!=NULL)
+    exceptionCode=tmp->value;
   if(m!=NULL){
     map *tmpSid=getMapFromMaps(m,"lenv","sid");
@@ -2605,5 +2607,4 @@
 void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
 		    map* request_inputs1,int cpid,maps* m,int res){
-		
 #ifdef DEBUG
   dumpMaps(request_inputs);
@@ -2659,5 +2660,4 @@
     }
   }
- 		 
   if(res==SERVICE_FAILED){
     map *lenv;
@@ -2718,5 +2718,5 @@
       toto=getMap(tmpI->content,"asReference");
 #ifdef USE_MS
-      restartNoMS:
+    restartNoMS:
       map* geodatatype=getMap(tmpI->content,"geodatatype");
       
@@ -2778,4 +2778,13 @@
 
 	    toto=getMap(tmpI->content,"value");
+	    if(toto==NULL){
+	      char tmpMsg[1024];
+	      sprintf(tmpMsg,_("No value found for the requested output %s."),tmpI->name);
+	      errorException(m,tmpMsg,"InternalError",NULL);
+	      fclose(ofile);
+	      free(file_name);
+	      free(file_path);
+	      return;
+	    }
 	    if(strcasecmp(format,"BoundingBoxData")!=0){
 	      map* size=getMap(tmpI->content,"size");
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 860)
@@ -865,4 +865,18 @@
   else
     addToMap(m,tmp,value);
+}
+
+/**
+ * Add a key and an integer value to an existing map array.
+ *
+ * @param m the map to add the KVP
+ * @param n the key to add
+ * @param index the index of the MapArray 
+ * @param v the corresponding value to add
+ */
+void addIntToMapArray(map* m,const char* n,int index,const int v){
+  char svalue[10];
+  sprintf(svalue,"%d",v);
+  setMapArray(m,n,index,svalue);
 }
 
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 860)
@@ -81,8 +81,11 @@
  */
 #define zWrite write
+#include "unistd.h"
 /**
  * The crossplatform sleep alias
  */
-#define zSleep sleep
+static int zSleep(const long millisecond){
+  return usleep(millisecond*1000);
+}
 /**
  * The crossplatform gettimeofday alias
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 860)
@@ -142,9 +142,5 @@
 	   ( cStep!=arg->step || (arg->state!=0 && steps[arg->step][0]==false) )
 	   ){
-      struct timespec tv;
-      tv.tv_sec = 0;
-      tv.tv_nsec = (long) 5*1e+9;
-      nanosleep(&tv, &tv);
-      //sleep(1);
+      zSleep(100);
     }
     isOngoing=1;
@@ -307,101 +303,6 @@
       
     case 1: {
-      // Fetching data inputs
-      maps* curs=inputs;
-      dumpMaps(curs);
-      char *keys[10][2]={
-	{
-	  "href",
-	  "ref"
-	},
-	{
-	  "cache_file",
-	  "cachefile"
-	},
-	{
-	  "fmimeType",
-	  "mimetype"
-	},
-	{
-	  "size",
-	  "size"
-	},
-	{
-	  "ref_wms_link",
-	  "ref_wms_link"
-	},
-	{
-	  "ref_wcs_link",
-	  "ref_wcs_link"
-	},
-	{
-	  "ref_wcs_link",
-	  "ref_wcs_link"
-	},
-	{
-	  "ref_wcs_preview_link",
-	  "ref_wcs_preview_link"
-	},
-	{
-	  "geodatatype",
-	  "datatype"
-	},
-	{
-	  "wcs_extent",
-	  "boundingbox"
-	}	
-      };
-      json_object *res1=json_object_new_object();
-      while(curs!=NULL){
-	map* tmpMap=getMap(curs->content,"cache_file");
-	sid=getMap(curs->content,"ref_wms_link");
-	json_object *res2=json_object_new_object();
-	if(tmpMap!=NULL){
-	  if(sid==NULL){
-	    addToMap(curs->content,"generated_file",tmpMap->value);
-	    addToMap(curs->content,"storage",tmpMap->value);
-	  }
-	  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-	  dumpMap(curs->content);
-	  struct stat buf;
-	  char timeStr[ 100 ] = "";
-	  if (stat(tmpMap->value, &buf)==0){
-	    strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime));
-	    json_object *jsStr=json_object_new_string(timeStr);
-	    json_object_object_add(res2,"creation_date",jsStr);
-	  }
-	  tmpMap=getMap(curs->content,"fmimeType");
-	  if(tmpMap!=NULL){
-	    addToMap(curs->content,"mimeType",tmpMap->value);
-	  }
-	  setReferenceUrl(conf,curs);
-	}
-	int i=0;
-	int hasRef=-1;
-	for(;i<10;i++){
-	  sid=getMap(curs->content,keys[i][0]);
-	  if(sid!=NULL){
-	    json_object *jsStr=json_object_new_string(sid->value);
-	    json_object_object_add(res2,keys[i][1],jsStr);
-	    if(i==0){
-	      hasRef=1;
-	      json_object *jsStr1=json_object_new_string(getProvenance(conf,url->value));
-	      json_object_object_add(res2,"dataOrigin",jsStr1);
-	    }
-	  }
-	}
-	if(hasRef<0)
-	  json_object_put(res2);
-	else
-	  json_object_object_add(res1,curs->name,res2);
-	curs=curs->next;
-      }
-      json_object_object_add(res,"inputs",res1);
-      break;
-    }
-      
-    case 2: {
-      // Update the execute request stored on disk at step 1,1 to modify the references used.
-      if(state==0){
+      // Update the execute request stored on disk at step 0,0 to modify the references used.
+      if(state==1){
 	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
 	fflush(stderr);
@@ -424,5 +325,11 @@
 	  //if(bvMap!=NULL && strncasecmp(bvMap->value,"true",4)==0){
 	  if(getMap(curs->content,"href")==NULL && getMap(curs->content,"mimeType")!=NULL){
-	    map* tmpMap=getMap(curs->content,"cache_file");
+	    map* tmpMap=getMap(curs->content,"value");
+	    char tmpStr[100];
+	    sprintf(tmpStr,"%d",strlen(tmpMap->value));
+	    addToMap(curs->content,"size",tmpStr);
+	    tmpMap=getMap(curs->content,"mimeType");
+	    addToMap(curs->content,"fmimeType",tmpMap->value);
+	    tmpMap=getMap(curs->content,"cache_file");
 	    addToMap(curs->content,"generated_file",tmpMap->value);
 	    addToMap(curs->content,"storage",tmpMap->value);
@@ -459,6 +366,8 @@
 	    char *tmpParam=(char*)malloc((strlen(curs->name)+11)*sizeof(char));
 	    char *tmpParam1=(char*)malloc((strlen(filePath->value)+11)*sizeof(char));
-	    sprintf(tmpParam,"string(\"%s\")",curs->name);	    
-	    sprintf(tmpParam1,"string(\"%s\")",filePath->value);	    
+	    addToMap(curs->content,"href",filePath->value);
+	    addToMap(curs->content,"xlink:href",filePath->value);
+	    sprintf(tmpParam,"string(\"%s\")",curs->name);
+	    sprintf(tmpParam1,"string(\"%s\")",filePath->value);
 	    params[0]="attr";
 	    params[1]=tmpParam;
@@ -538,4 +447,120 @@
       }
 
+      // Fetching data inputs
+      maps* curs=inputs;
+      dumpMaps(curs);
+      char *keys[11][2]={
+	{
+	  "xlink:href",
+	  "ref"
+	},
+	{
+	  "cache_file",
+	  "cachefile"
+	},
+	{
+	  "fmimeType",
+	  "mimetype"
+	},
+	{
+	  "size",
+	  "size"
+	},
+	{
+	  "ref_wms_link",
+	  "ref_wms_link"
+	},
+	{
+	  "ref_wfs_link",
+	  "ref_wfs_link"
+	},
+	{
+	  "ref_wcs_link",
+	  "ref_wcs_link"
+	},
+	{
+	  "ref_wcs_link",
+	  "ref_wcs_link"
+	},
+	{
+	  "ref_wcs_preview_link",
+	  "ref_wcs_preview_link"
+	},
+	{
+	  "geodatatype",
+	  "datatype"
+	},
+	{
+	  "wgs84_extent",
+	  "boundingbox"
+	}	
+      };
+      json_object *res1=json_object_new_object();
+      while(curs!=NULL){
+	if(getMap(curs->content,"length")==NULL){
+	  addToMap(curs->content,"length","1");
+	}
+	map* length=getMap(curs->content,"length");
+	int len=atoi(length->value);
+	json_object *res3;
+	int hasRef=-1;
+	for(int ii=0;ii<len;ii++){
+	  map* tmpMap=getMapArray(curs->content,"cache_file",ii);
+	  sid=getMapArray(curs->content,"ref_wms_link",ii);
+	  json_object *res2=json_object_new_object();
+	  if(tmpMap!=NULL){
+	    if(sid==NULL){
+	      setMapArray(curs->content,"generated_file",ii,tmpMap->value);
+	      setMapArray(curs->content,"storage",ii,tmpMap->value);
+	    }
+	    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
+	    dumpMap(curs->content);
+	    struct stat buf;
+	    char timeStr[ 100 ] = "";
+	    if (stat(tmpMap->value, &buf)==0){
+	      strftime(timeStr, 100, "%d-%m-%Y %H:%M:%S", localtime( &buf.st_mtime));
+	      json_object *jsStr=json_object_new_string(timeStr);
+	      json_object_object_add(res2,"creation_date",jsStr);
+	    }
+	    tmpMap=getMapArray(curs->content,"fmimeType",ii);
+	    if(tmpMap!=NULL){
+	      setMapArray(curs->content,"mimeType",ii,tmpMap->value);
+	    }
+	    setReferenceUrl(conf,curs);
+	  }else{	  
+	  }
+	  addIntToMap(curs->content,"published_id",ii+1);
+	  int i=0;
+	  for(;i<11;i++){
+	    sid=getMapArray(curs->content,keys[i][0],ii);
+	    if(sid!=NULL){
+	      json_object *jsStr=json_object_new_string(sid->value);
+	      json_object_object_add(res2,keys[i][1],jsStr);
+	      if(i==0){
+		hasRef=1;
+		json_object *jsStr1=json_object_new_string(getProvenance(conf,sid->value));
+		json_object_object_add(res2,"dataOrigin",jsStr1);
+	      }
+	    }
+	  }
+	  if(len>1){
+	    if(ii==0)
+	      res3=json_object_new_array();
+	    json_object_array_add(res3,res2);
+	  }else
+	    res3=res2;
+	}
+	if(hasRef<0)
+	  json_object_put(res3);
+	else
+	  json_object_object_add(res1,curs->name,res3);
+	addIntToMap(curs->content,"published_id",0);
+	curs=curs->next;
+      }
+      json_object_object_add(res,"inputs",res1);
+      break;
+    }
+      
+    case 2: {
       // Uploading data input to cluster
       maps* in=getMaps(conf,"uploadQueue");
@@ -545,5 +570,5 @@
 	if(length!=NULL){
 	  json_object *res1=json_object_new_object();
-	  json_object *res2=json_object_new_object();
+	  json_object *res3=json_object_new_array();
 	  int limit=atoi(length->value);
 	  int i=0;
@@ -555,11 +580,26 @@
 	    map* tmp2=getMapArray(tmp,"targetPath",i);
 	    if(tmp0!=NULL && tmp1!=NULL && tmp2!=NULL){
+	      json_object *res2=json_object_new_object();
 	      json_object *jsStr=json_object_new_string(tmp1->value);
 	      json_object_object_add(res2,"local_path",jsStr);
 	      jsStr=json_object_new_string(tmp2->value);
 	      json_object_object_add(res2,"target_path",jsStr);
-	      json_object_object_add(res1,tmp0->value,res2);
+	      json_object *res4=json_object_object_get(res1,tmp0->value);
+	      if(json_object_is_type(res4,json_type_null)){
+		json_object_object_add(res1,tmp0->value,res2);
+	      }else{
+		if(json_object_is_type(res4,json_type_object)){
+		  json_object_array_add(res3,res4);
+		}
+		json_object_array_add(res3,res2);
+		if(json_object_is_type(res4,json_type_object)){
+		  json_object_object_del(res1,tmp0->value);
+		  json_object_object_add(res1,tmp0->value,res3);
+		}
+	      }
 	    }
 	  }
+	  if(json_object_array_length(res3)==0)
+	    json_object_put(res3);
 	  json_object_object_add(res,"inputs",res1);
 	}
@@ -616,5 +656,5 @@
 	},
 	{
-	  "wcs_extent",
+	  "wgs84_extent",
 	  "boundingbox"
 	},
@@ -684,5 +724,8 @@
 	      int i0=0;
 	      for(;i0<6;i0++){
-		sid=getMap(specificMaps->content,keys[i0][0]);
+		if(i0==0)
+		  sid=getMap(specificMaps->content,specifics[i][1]);
+		else
+		  sid=getMap(specificMaps->content,keys[i0][0]);
 		if(sid!=NULL){
 		  json_object *jsStr=json_object_new_string(sid->value);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 860)
@@ -649,5 +649,5 @@
 	      fprintf(stderr,"Retry to access the semaphore later ...\n");
 #endif
-	      zSleep(1);
+	      zSleep(1000);
             }
         }
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 860)
@@ -285,4 +285,5 @@
  * @param real_inputs the maps containing the inputs
  * @param real_outputs the maps containing the outputs
+ * @return SERVICE_SUCCEEDED in case of success, -1 or SERVICE_FAILED when failing.
  */
 int zoo_hpc_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
@@ -391,12 +392,17 @@
   }
 
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  invokeCallback(m,inputs,NULL,2,0);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  dumpMaps(inputs);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
+  invokeCallback(m,inputs,NULL,1,1);
   if(getMapFromMaps(m,"lenv","mapError")!=NULL){
     invokeCallback(m,inputs,NULL,7,0);
     return -1;
   }
+  invokeCallback(m,inputs,NULL,2,0);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+  dumpMaps(inputs);
+#endif
 
   // Upload data on HPC
@@ -404,12 +410,20 @@
     errorException (m, _("Unable to lock the file for upload!"),
 		    "InternalError", NULL);
-    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
     invokeCallback(m,inputs,NULL,7,0);
-    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+    fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
     return -1;
   }
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
   invokeCallback(m,inputs,NULL,2,1);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
 
   // Add the filename to generate for every output to parameters
@@ -417,5 +431,7 @@
   // TODO: fix appendOutputParameters
   //appendOutputParameters(input,parameters,&parameters_cnt,s,uuid,targetPathMap);
+#ifdef HPC_DEBUG
   dumpMaps(input);
+#endif
   while(input!=NULL){
     // TODO: parse all outputs including inner outputs if required.
@@ -509,9 +525,13 @@
   sprintf(scriptPath,"%s/zoo_%s_%s.sh",tmpPath->value,s->name,uuid->value);
   setMapInMaps(*main_conf,"lenv","local_script",scriptPath);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   invokeCallback(m,inputs,NULL,3,0);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   FILE* scriptFile=fopen(scriptPath,"w+");
   map* headerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_header");
@@ -562,7 +582,7 @@
       free(fcontent);
     }else
-      fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY (no body found) *** ###\n\n");
+      fprintf(scriptFile,"\n### *** Default ZOO-Service BODY (no body found) *** ###\n\n");
   }else
-    fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service BODY *** ###\n\n");
+    fprintf(scriptFile,"\n### *** Default ZOO-Service BODY *** ###\n\n");
 
   map* sp=getMap(s->content,"serviceProvider");
@@ -583,12 +603,20 @@
   fflush(scriptFile);
   fclose(scriptFile);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
   invokeCallback(m,inputs,NULL,3,1);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
 
   // Upload the SBATCH File to the remote host
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
   invokeCallback(m,inputs,NULL,4,0);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#ifdef HPC_DEBUG
+  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
+#endif
   targetPathMap=getMapFromMaps(*main_conf,configurationId,"remote_work_path");
   if(targetPathMap==NULL){
@@ -597,9 +625,13 @@
     errorException (m, _("There is no remote_work_path defined in your section!"),
 		    "InternalError", NULL);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     invokeCallback(m,NULL,NULL,7,0);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     return SERVICE_FAILED;
   }
@@ -609,7 +641,13 @@
   setMapInMaps(*main_conf,"lenv","remote_script",targetPath);
   SSHCON *test=ssh_connect(*main_conf);
-  ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf));
+  int copy0=ssh_copy(*main_conf,scriptPath,targetPath,ssh_get_cnt(*main_conf));
   unlink(scriptPath);
   free(scriptPath);
+  if(copy0!=true){
+    setMapInMaps(m,"lenv","message",_("Unable to upload the script"));
+    invokeCallback(m,NULL,NULL,7,0);
+    errorException(m,_("Unable to upload the script"),"NoApplicableCode",NULL);
+    return -1;
+  }
   // Execute the SBATCH script remotely
   addReadLocks(main_conf);
@@ -617,5 +655,5 @@
   char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char));
   sprintf(command,"sbatch %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value);
-  if(ssh_exec(*main_conf,command,ssh_get_cnt(m))==0){
+  if(ssh_exec(*main_conf,command,ssh_get_cnt(m))<=0){
     // The sbatch command has failed!
     // Download the error log file from the HPC server
@@ -645,49 +683,46 @@
     }else
       setMapInMaps(*main_conf,"lenv","message",_("Unable to fetch the remote error log file"));
-    tmpPath=getMapFromMaps(*main_conf,"lenv","message");
+    tmpPath=getMapFromMaps(m,"lenv","message");
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     invokeCallback(m,NULL,NULL,7,0);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
-    sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s: %s", s->name, tmpPath->value);
+#endif
+    sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s using %s: %s", s->name, configurationId, tmpPath->value);
     errorException(m,tmpS,"NoApplicableCode",NULL);
     free(command);
     free(targetPath);
     ssh_close(*main_conf);
+    removeReadLocks(main_conf);
     sleep(1);
     return -1;
   }
   free(targetPath);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   invokeCallback(m,NULL,NULL,4,1);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   free(command);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
 
   struct sockaddr_un addr;
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   memset(&addr, 0, sizeof(addr));
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   addr.sun_family = AF_UNIX;
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+20));
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
@@ -696,40 +731,56 @@
     errorException (m, _("Unable to bind socket!"),
 		    "InternalError", NULL);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     invokeCallback(m,NULL,NULL,7,0);
+    removeReadLocks(main_conf);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
-    sleep(120);
+#endif
     return -1;
   }
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   if (listen(fd, 5) == -1) {
     setMapInMaps(*main_conf,"lenv","message",_("Listen error"));
     errorException (m, _("Listen error"),
 		    "InternalError", NULL);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     invokeCallback(m,NULL,NULL,7,0);
+    removeReadLocks(main_conf);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     return -1;
   }
-  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-  fflush(stderr);
   if ( (cl = accept(fd, NULL, NULL)) == -1) {
     setMapInMaps(*main_conf,"lenv","message",_("Accept error"));
     errorException (m, _("Accept error"),
 		    "InternalError", NULL);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     invokeCallback(m,NULL,NULL,7,0);
+    removeReadLocks(main_conf);
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     return -1;
   }else{
+#ifdef HPC_DEBUG
     fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
     fflush(stderr);
+#endif
     int hasPassed=-1;
     char buf[11];
@@ -741,9 +792,14 @@
 	errorException (m, _("Read closed"),
 			"InternalError", NULL);
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
 	invokeCallback(m,NULL,NULL,7,0);
+	removeReadLocks(main_conf);
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
 	return -1;
       }else{
@@ -752,34 +808,55 @@
 	  errorException (m, _("Read error"),
 			  "InternalError", NULL);
+#ifdef HPC_DEBUG
 	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	  fflush(stderr);
+#endif
 	  invokeCallback(m,NULL,NULL,7,0);
+	  removeReadLocks(main_conf);
+#ifdef HPC_DEBUG
 	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	  fflush(stderr);
+#endif
 	  return -1;
 	}
       }
       hasPassed=1;
-      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      fflush(stderr);
       res=atoi(buf);
-      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      fflush(stderr);
       unlink(sname);
-      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      fflush(stderr);
       free(sname);
-      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      fflush(stderr);
       removeReadLocks(main_conf);
-      fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-      fflush(stderr);
   
       if(res==3){
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
 	invokeCallback(m,NULL,outputs,5,0);
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
+
+	// Read informations provided by FinalizeHPC as a configuration file
+	// then, remove the file.
+	map* jobid=getMapFromMaps(*main_conf,"lenv","usid");
+	map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
+	char *filePath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
+	sprintf(filePath,"%s/exec_status_%s",tmpPath->value,jobid->value);
+	maps* m = (maps *) malloc (MAPS_SIZE);
+	m->child=NULL;
+	m->next=NULL;
+	int saved_stdout = dup (fileno (stdout));
+	dup2 (fileno (stderr), fileno (stdout));
+	conf_read(filePath,m);
+	fflush(stdout);
+	dup2 (saved_stdout, fileno (stdout));
+	close(saved_stdout);
+	unlink(filePath);
+	free(filePath);
+	addMapsToMaps(main_conf,m);
+	freeMaps(&m);
+	free(m);
+
 	input=*real_outputs;
 	while(input!=NULL){
@@ -797,5 +874,5 @@
 		char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
 		sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
-		setMapInMaps(*main_conf,"lenv","message",tmpStr);
+		setMapInMaps(m,"lenv","message",tmpStr);
 		free(tmpStr);
 		invokeCallback(m,NULL,NULL,7,0);
@@ -804,6 +881,4 @@
 	    }	    
 	  }else{
-	    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-	    fflush(stderr);
 	    map* generatedFile=getMap(input->content,"generated_file");
 	    if(generatedFile!=NULL){
@@ -834,8 +909,10 @@
 		  sprintf(serviceName,"wcs_link");
 		  setMapInMaps(output->child,serviceName,"msOgc","WCS");
+		  setMapInMaps(output->child,serviceName,"requestedMimeType","image/tiff");
 		}
 		else{
 		  sprintf(serviceName,"wfs_link");
 		  setMapInMaps(output->child,serviceName,"msOgc","WFS");
+		  setMapInMaps(output->child,serviceName,"requestedMimeType","text/xml");
 		}
 		setMapInMaps(output->child,serviceName,"storage",targetPath);
@@ -844,9 +921,31 @@
 		setMapInMaps(output->child,serviceName,"asReference","true");
 	      }else{
-                char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
-                sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
-                setMapInMaps(*main_conf,"lenv","message",tmpStr);
-                free(tmpStr);
-                invokeCallback(m,NULL,NULL,7,0);
+		map* hpcStdErr=getMapFromMaps(*main_conf,"henv","StdErr");
+		if(hpcStdErr!=NULL && ssh_fetch(*main_conf,targetPath,hpcStdErr->value,ssh_get_cnt(m))==0){
+		  struct stat f_status;
+		  int ts=stat(targetPath, &f_status);
+		  if(ts==0) {
+		    char* fcontent = NULL;
+		    fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+		    FILE* f=fopen(targetPath,"rb");
+		    fread(fcontent,f_status.st_size,1,f);
+		    int fsize=f_status.st_size;
+		    fcontent[fsize]=0;
+		    fclose(f);
+		    setMapInMaps(*main_conf,"lenv","message",fcontent);
+		    free(fcontent);
+		  }else{
+		    char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
+		    sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
+		    setMapInMaps(*main_conf,"lenv","message",tmpStr);
+		    free(tmpStr);
+		  }
+		}else{
+		  char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char));
+		  sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename);
+		  setMapInMaps(*main_conf,"lenv","message",tmpStr);
+		  free(tmpStr);
+		}
+                invokeCallback(*main_conf,NULL,NULL,7,0);
                 return SERVICE_FAILED;
 	      }
@@ -857,24 +956,4 @@
 	}
 
-	// Read informations provided by FinalizeHPC as a configuration file
-	// then, remove the file.
-	map* jobid=getMapFromMaps(*main_conf,"lenv","usid");
-	map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
-	char *filePath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
-	sprintf(filePath,"%s/exec_status_%s",tmpPath->value,jobid->value);
-	maps* m = (maps *) malloc (MAPS_SIZE);
-	m->child=NULL;
-	m->next=NULL;
-	int saved_stdout = dup (fileno (stdout));
-	dup2 (fileno (stderr), fileno (stdout));
-	conf_read(filePath,m);
-	fflush(stdout);
-	dup2 (saved_stdout, fileno (stdout));
-	close(saved_stdout);
-	unlink(filePath);
-	free(filePath);
-	addMapsToMaps(main_conf,m);
-	freeMaps(&m);
-	free(m);
       }else{
 	// Try to access remotely to the log file and return a more relevant error message
@@ -882,9 +961,13 @@
 	errorException (m, _("HPC Execution failed!"),
 			"InternalError", NULL);
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
 	invokeCallback(m,NULL,NULL,7,0);
+#ifdef HPC_DEBUG
 	fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
 	fflush(stderr);
+#endif
       }
       //free(buf);
@@ -895,18 +978,25 @@
       errorException (m, _("Unable to parse the value returned by remote execution"),
 		      "InternalError", NULL);
+#ifdef HPC_DEBUG
       fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
       fflush(stderr);
+#endif
       invokeCallback(m,NULL,NULL,7,0);
+#ifdef HPC_DEBUG
       fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
       fflush(stderr);
-      sleep(120);
+#endif
       return SERVICE_FAILED;
     }
   }
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   ssh_close(*main_conf);
+#ifdef HPC_DEBUG
   fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
   fflush(stderr);
+#endif
   return res;
 }
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 860)
@@ -76,4 +76,16 @@
 
 /**
+ * Return the current publish_id value
+ * @param elem and maps pointer on which the search occur
+ * @return the integer value of the publish_id field, if any, 0 otherwise
+ */ 
+int getPublishedId(maps* elem){
+  map* myIndex=getMap(elem->content,"published_id");
+  if(myIndex!=NULL){
+    return atoi(myIndex->value);
+  }
+  return 0;
+}
+/**
  * Add width and height keys to an output maps containing the maximum width
  * and height for displaying the full data extent.
@@ -87,4 +99,5 @@
  */
 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){
+  int imyIndex=getPublishedId(output);
   double maxWidth=640;
   double maxHeight=480;
@@ -118,6 +131,6 @@
 #endif
   if(output!=NULL){
-    addToMap(output->content,"width",sWidth);
-    addToMap(output->content,"height",sHeight);
+    setMapArray(output->content,"width",imyIndex,sWidth);
+    setMapArray(output->content,"height",imyIndex,sHeight);
   }
 }
@@ -131,5 +144,4 @@
  */
 void setReferenceUrl(maps* m,maps* tmpI){
-  outputMapfile(m,tmpI);
   map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
   if(msUrl==NULL){
@@ -138,14 +150,19 @@
     exit(-1);
   }
+  int imyIndex=getPublishedId(tmpI);
+  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
+    return;
+  outputMapfile(m,tmpI);
   int finalProto=-1;
   map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
   map *dataPath=getMapFromMaps(m,"main","dataPath");
   map *sid=getMapFromMaps(m,"lenv","usid");
-  map* format=getMap(tmpI->content,"mimeType");
-  map* rformat=getMap(tmpI->content,"requestedMimeType");
-  map* width=getMap(tmpI->content,"width");
-  map* height=getMap(tmpI->content,"height");
-  map* protoMap=getMap(tmpI->content,"msOgc");
-  map* versionMap=getMap(tmpI->content,"msOgcVersion");
+  map* format=getMapArray(tmpI->content,"mimeType",imyIndex);
+  map* rformat=getMapArray(tmpI->content,"requestedMimeType",imyIndex);
+  map* width=getMapArray(tmpI->content,"width",imyIndex);
+  map* height=getMapArray(tmpI->content,"height",imyIndex);
+  map* protoMap=getMapArray(tmpI->content,"msOgc",imyIndex);
+  map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex);
+  map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex);
   char options[4][5][25]={
     {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
@@ -154,16 +171,18 @@
     {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
   };
-  map* datatype=getMap(tmpI->content,"geodatatype");
   if(datatype==NULL || strncmp(datatype->value,"other",5)==0){
-    setMapInMaps(m,"lenv","mapError","true");
-    setMapInMaps(m,"lenv","locator",tmpI->name);
-    setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
-    if(getMapFromMaps(m,"lenv","state")==NULL)
-      errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
+    map* minNb=getMap(tmpI->content,"minoccurs");
+    if(minNb==NULL || atoi(minNb->value)>=1){
+      setMapInMaps(m,"lenv","mapError","true");
+      setMapInMaps(m,"lenv","locator",tmpI->name);
+      setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
+      if(getMapFromMaps(m,"lenv","state")==NULL)
+	errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
+    }
     return;
   }
   int proto=0;
   if(rformat==NULL){
-    rformat=getMap(tmpI->content,"mimeType");
+    rformat=getMapArray(tmpI->content,"mimeType",imyIndex);
   }
   if(strncasecmp(rformat->value,"text/xml",8)==0)
@@ -172,12 +191,20 @@
      strncasecmp(rformat->value,"image/geotiff",10)==0)
     proto=2;
+  int hasFormat=-1;
   if(protoMap!=NULL){
-    if(strncasecmp(protoMap->value,"WMS",3)==0)
+    hasFormat=1;
+    if(strncasecmp(protoMap->value,"WMS",3)==0){
       proto=0;
+      rformat=createMap("value","image/png");
+    }
     else{
-      if(strncasecmp(protoMap->value,"WFS",3)==0)
+      if(strncasecmp(protoMap->value,"WFS",3)==0){
 	proto=1;
-      else 
+	rformat=createMap("value","text/xml");
+      }
+      else {
 	proto=2;
+	rformat=createMap("value","image/tiff");
+      }
     }
   }
@@ -190,6 +217,7 @@
   }
 
-  map* extent=getMap(tmpI->content,options[proto][4]);
-  map* crs=getMap(tmpI->content,"crs");
+
+  map* extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
+  map* crs=getMapArray(tmpI->content,"crs",imyIndex);
   int hasCRS=1;
   if(crs==NULL){
@@ -203,14 +231,41 @@
   sprintf(layers,options[proto][3],tmpI->name);
 
-  char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
+  if(format==NULL || width==NULL || height==NULL || extent==NULL){
+    char tmpStr[1024];
+    sprintf(tmpStr,_("Unable to create the mapfile for %s because of missing values."),tmpI->name);
+    errorException (m, tmpStr,
+		    "InternalError", NULL);
+    exit(-1);
+    return;
+  }
+
+  if(proto==0){
+    hasFormat=1;
+    rformat=createMap("mimeType","image/png");
+  }else{
+    if(proto==1){
+      rformat=createMap("mimeType","text/xml");
+      hasFormat=1;
+    }
+    else
+      if(proto==2){
+        rformat=createMap("mimeType","image/tiff");
+	hasFormat=1;
+	finalProto=1;
+      }
+  }
   
+  char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(rformat->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
+
+
   if(proto>0){
     if(proto==2)
       finalProto=1;
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -223,18 +278,21 @@
 	    );
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
-      addToMap(tmpI->content,"ref_wcs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     }
     else{
-      addToMap(tmpI->content,"ref_wfs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     }
     proto=0;
+    freeMap(&rformat);
+    free(rformat);
     rformat=createMap("mimeType","image/png");
   }
   else{
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -248,19 +306,23 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wms_link",webService_url);
+    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
       proto=2;
+      freeMap(&rformat);
+      free(rformat);
       rformat=createMap("mimeType","image/tiff");
     }
     else{
       proto=1;
+      freeMap(&rformat);
+      free(rformat);
       rformat=createMap("mimeType","text/xml");
     }
   }
-  addToMap(tmpI->content,"Reference",webService_url);
+  setMapArray(tmpI->content,"Reference",imyIndex,webService_url);
   memset(layers,0,128);
   sprintf(layers,options[proto][3],tmpI->name);
   protoVersion=options[proto][1];
-  extent=getMap(tmpI->content,options[proto][4]);
+  extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
   memset(webService_url,0,strlen(webService_url));
   if(proto>0){
@@ -268,8 +330,9 @@
       finalProto=1;
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -282,15 +345,16 @@
 	    );
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
-      addToMap(tmpI->content,"ref_wcs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     }
     else{
-      addToMap(tmpI->content,"ref_wfs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     }
   }else{
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -304,5 +368,5 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wms_link",webService_url);
+    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
   }
   if(finalProto>0){
@@ -311,11 +375,15 @@
     sprintf(layers,options[proto][3],tmpI->name);
     protoVersion=options[proto][1];
-    extent=getMap(tmpI->content,options[proto][4]);
+    extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
     memset(webService_url,0,strlen(webService_url));
+    freeMap(&rformat);
+    free(rformat);
+    rformat=createMap("value","image/tiff");
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -327,5 +395,5 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wcs_preview_link",webService_url);
+    setMapArray(tmpI->content,"ref_wcs_preview_link",imyIndex,webService_url);
   }
   if(hasCRS==0){
@@ -352,4 +420,5 @@
   OGRSpatialReferenceH  hSRS;
   map* msSrs=NULL;
+  int imyIndex=getPublishedId(output);
   hSRS = OSRNewSpatialReference(NULL);
   if( pszProjection!=NULL && strlen(pszProjection)>1){
@@ -375,8 +444,8 @@
 	if(output!=NULL){
 	  if(OSRIsGeographic(hSRS)==TRUE)
-	    addToMap(output->content,"crs_isGeographic","true");
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	  else
-	    addToMap(output->content,"crs_isGeographic","false");
-	  addToMap(output->content,"crs",tmpSrs);
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
+	  setMapArray(output->content,"crs",imyIndex,tmpSrs);
 	}
       }
@@ -391,7 +460,7 @@
 	  if(output!=NULL){ 
 	    if(OSRIsGeographic(hSRS)==TRUE)
-	      addToMap(output->content,"crs_isGeographic","true");
+	      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	    else
-	      addToMap(output->content,"crs_isGeographic","false");
+	      setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
 	  }
 	  free(proj4Str);
@@ -401,10 +470,10 @@
 	  msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
 	  if(output!=NULL){
-	    addToMap(output->content,"crs_isGeographic","true");
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	  }
 	}
 	if(output!=NULL){
-	  addToMap(output->content,"crs","EPSG:4326");
-	  addToMap(output->content,"real_extent","true");
+	  setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
+	  setMapArray(output->content,"real_extent",imyIndex,"true");
 	}
 	msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
@@ -415,5 +484,5 @@
   else{
     if(output!=NULL){
-      msSrs=getMap(output->content,"msSrs");
+      msSrs=getMapArray(output->content,"msSrs",imyIndex);
     }
     if(msSrs!=NULL){
@@ -431,6 +500,6 @@
     }
     if(output!=NULL){
-      addToMap(output->content,"crs",msSrs->value);
-      addToMap(output->content,"crs_isGeographic","true");
+      setMapArray(output->content,"crs",imyIndex,msSrs->value);
+      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
     }
   }
@@ -454,4 +523,5 @@
 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
 		 double minX,double minY,double maxX,double maxY){
+  int imyIndex=getPublishedId(output);
   msMapSetExtent(m,minX,minY,maxX,maxY);
 #ifdef DEBUGMS
@@ -466,32 +536,40 @@
   
   if(output!=NULL){
-    map* test=getMap(output->content,"real_extent");
+    map* test=getMapArray(output->content,"real_extent",imyIndex);
+    pointObj min, max;
+    projectionObj tempSrs;
+    min.x = m->extent.minx;
+    min.y = m->extent.miny;
+    max.x = m->extent.maxx;
+    max.y = m->extent.maxy;
+    char tmpSrsStr[1024];
+    msInitProjection(&tempSrs);
+    msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
+
+    msProjectPoint(&(myLayer->projection),&tempSrs,&min);
+    msProjectPoint(&myLayer->projection,&tempSrs,&max);
+  
     if(test!=NULL){
-      pointObj min, max;
-      projectionObj tempSrs;
-      min.x = m->extent.minx;
-      min.y = m->extent.miny;
-      max.x = m->extent.maxx;
-      max.y = m->extent.maxy;
-      char tmpSrsStr[1024];
-      msInitProjection(&tempSrs);
-      msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
-
-      msProjectPoint(&(m->projection),&tempSrs,&min);
-      msProjectPoint(&m->projection,&tempSrs,&max);
-      
       sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
-      map* isGeo=getMap(output->content,"crs_isGeographic");
+      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
 #ifdef DEBUGMS
       fprintf(stderr,"isGeo = %s\n",isGeo->value);
 #endif
-      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
+      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0){
+	sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
+	setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
         sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
-      addToMap(output->content,"wms_extent",tmpExtent);
+      }else{
+	sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
+	setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
+      }
+      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent);
       sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
-      addToMap(output->content,"wcs_extent",tmpExtent);
+      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
     }else{
+      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
+      setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
       sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
-      map* isGeo=getMap(output->content,"crs_isGeographic");
+      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
       if(isGeo!=NULL){
 #ifdef DEBUGMS
@@ -501,7 +579,7 @@
 	  sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
       }
-      addToMap(output->content,"wms_extent",tmpExtent); 
+      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 
       sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);
-      addToMap(output->content,"wcs_extent",tmpExtent);
+      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
     }
   }
@@ -518,6 +596,6 @@
  */
 int tryOgr(maps* conf,maps* output,mapObj* m){
-
-  map* tmpMap=getMap(output->content,"storage");
+  int imyIndex=getPublishedId(output);
+  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
   char *pszDataSource=tmpMap->value;
 
@@ -643,6 +721,4 @@
 #endif
     setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
-    //OGR_DS_Destroy(poDS);
-    //OGRCleanupAll();
 #ifdef DEBUGMS
     fprintf(stderr,"Unable to access the DataSource, exit! \n"); 
@@ -651,5 +727,5 @@
   }
 
-  addToMap(output->content,"geodatatype","vector");
+  setMapArray(output->content,"geodatatype",imyIndex,"vector");
   int iLayer = 0;
   for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){
@@ -687,5 +763,5 @@
     msConnectLayer(myLayer,MS_OGR,pszDataSource);
 
-    addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1));
+    addIntToMapArray(output->content,"nb_features",imyIndex,OGR_L_GetFeatureCount(poLayer,1));
 
     /**
@@ -739,6 +815,6 @@
     }
     else{
-      addToMap(output->content,"crs","EPSG:4326");
-      addToMap(output->content,"crs_isGeographic","true");
+      setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
+      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
       msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
       msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
@@ -752,5 +828,5 @@
       memset(&extent,0,1024);
       sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
-      addToMap(output->content,"boundingbox",extent);
+      setMapArray(output->content,"boundingbox",imyIndex,extent);
     }
   
@@ -771,5 +847,5 @@
     msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all");
     msInsertHashTable(&(myLayer->metadata), "ows_name", output->name);
-    map* tmpMap=getMap(output->content,"title");
+    map* tmpMap=getMapArray(output->content,"title",imyIndex);
     if(tmpMap!=NULL)
       msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value);
@@ -839,5 +915,6 @@
  */
 int tryGdal(maps* conf,maps* output,mapObj* m){
-  map* tmpMap=getMap(output->content,"storage");
+  int imyIndex=getPublishedId(output);
+  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
   char *pszFilename=tmpMap->value;
   GDALDatasetH hDataset;
@@ -855,5 +932,5 @@
     fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
 #endif
-    addToMap(output->content,"geodatatype","other");
+    setMapArray(output->content,"geodatatype",imyIndex,"other");
     setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
     GDALDestroyDriverManager();
@@ -864,5 +941,5 @@
 #endif
 
-  addToMap(output->content,"geodatatype","raster");
+  setMapArray(output->content,"geodatatype",imyIndex,"raster");
   /**
    * Add a new layer set name, data
@@ -886,9 +963,9 @@
 
   char *title=output->name;
-  tmpMap=getMap(output->content,"title");
+  tmpMap=getMapArray(output->content,"title",imyIndex);
   if(tmpMap!=NULL)
     title=tmpMap->value;
   char *abstract=output->name;
-  tmpMap=getMap(output->content,"abstract");
+  tmpMap=getMapArray(output->content,"abstract",imyIndex);
   if(tmpMap!=NULL)
     abstract=tmpMap->value;
@@ -905,5 +982,5 @@
   m->width=GDALGetRasterXSize( hDataset );
   m->height=GDALGetRasterYSize( hDataset );
-  addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
+  addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
   
   /**
@@ -947,14 +1024,14 @@
       memset(&extent,0,1024);
       sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY);
-      addToMap(output->content,"boundingbox",extent);
+      setMapArray(output->content,"boundingbox",imyIndex,extent);
     }
   }else{
     int scale=1;
     if(m->width>2048){
-      addIntToMap(output->content,"width",2048);
+      addIntToMapArray(output->content,"width",imyIndex,2048);
       scale=2048/m->width;
     }else
-      addIntToMap(output->content,"width",m->width);
-    addIntToMap(output->content,"height",m->height*scale);
+      addIntToMapArray(output->content,"width",imyIndex,m->width);
+    addIntToMapArray(output->content,"height",imyIndex,m->height*scale);
   }
 
@@ -1130,5 +1207,6 @@
    * First store the value on disk
    */
-  map* mime=getMap(outputs->content,"mimeType");
+  int imyIndex=getPublishedId(outputs);
+  map* mime=getMapArray(outputs->content,"mimeType",imyIndex);
   char *ext="data";
   if(mime!=NULL)
@@ -1136,17 +1214,17 @@
       ext="json";
 
-  map* storage=getMap(outputs->content,"storage");
+  map* storage=getMapArray(outputs->content,"storage",imyIndex);
   if(storage==NULL){
     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);
+    sprintf(pszDataSource,"%s/ZOO_DATA_%d_%s_%s.%s",tmpMap->value,imyIndex,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 *gfile=getMap(outputs->content,"generated_file");
+    map *gfile=getMapArray(outputs->content,"generated_file",imyIndex);
     if(gfile!=NULL){
       readGeneratedFile(conf,outputs->content,gfile->value);	    
     }
-    map* sizeMap=getMap(outputs->content,"size");
-    map* vData=getMap(outputs->content,"value");
+    map* sizeMap=getMapArray(outputs->content,"size",imyIndex);
+    map* vData=getMapArray(outputs->content,"value",imyIndex);
     if(sizeMap!=NULL){
       zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
@@ -1156,5 +1234,5 @@
     }
     close(f);
-    addToMap(outputs->content,"storage",pszDataSource);
+    setMapArray(outputs->content,"storage",imyIndex,pszDataSource);
     free(pszDataSource);
   }
@@ -1327,6 +1405,6 @@
   map* sid=getMapFromMaps(conf,"lenv","usid");
   char *mapPath=
-    (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);
+    (char*)malloc((14+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
+  sprintf(mapPath,"%s/%s_%d_%s.map",tmp1->value,outputs->name,imyIndex,sid->value);
   msSaveMap(myMap,mapPath);
   free(mapPath);
Index: branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 860)
@@ -121,10 +121,10 @@
 int _init_sql(maps* conf,const char* key){
   char* sqlInitString=_createInitString(conf,key);
+#ifdef SQL_DEBUG
   fprintf(stderr,"Try to connect to: %s %s !\n",key,sqlInitString);
   fflush(stderr);  
+#endif
   if(strncmp(sqlInitString,"-1",2)==0)
     return -1;
-  fprintf(stderr,"Try to connect to: %s !\n",key);
-  fflush(stderr);  
   OGRSFDriver *poDriver = NULL;
   OGRRegisterAll();
@@ -165,5 +165,5 @@
 #endif
   if( zoo_DS[zoo_ds_nb] == NULL ){
-#ifdef DEBUG
+#ifdef SQL_DEBUG
     fprintf(stderr,"sqlInitString: %s FAILED !\n",sqlInitString);
     fflush(stderr);
@@ -174,10 +174,8 @@
     return -2;
   }
-#ifdef DEBUG
+#ifdef SQL_DEBUG
   fprintf(stderr,"sqlInitString: %s SUCEED !\n",sqlInitString);
   fflush(stderr);
 #endif
-  fprintf(stderr,"sqlInitString: %s SUCEED %d !\n",sqlInitString,zoo_ds_nb);
-  fflush(stderr);  
   free(sqlInitString);
   zoo_ds_nb++;
@@ -234,5 +232,5 @@
     return NULL;
   OGRLayer *res=NULL;
-#ifdef DEBUG
+#ifdef SQL_DEBUG
   fprintf(stderr,"************************* %s %s %d\n\n",sqlQuery,__FILE__,__LINE__);
   fflush(stderr);
@@ -381,5 +379,11 @@
   char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(msg->value)+strlen(p->value)+strlen(sid->value)+64+1)*sizeof(char));
   sprintf(sqlQuery,"UPDATE %s.services set status=$$%s$$,message=$$%s$$ where uuid=$$%s$$;",schema->value,p->value,msg->value,sid->value);
-  if(zoo_ds_nb==0){
+  if( zoo_ds_nb==
+#ifdef META_DB
+      1
+#else
+      0
+#endif     
+     ){
     init_sql(conf);
     zoo_ds_nb++;
Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 860)
@@ -283,5 +283,7 @@
     }
   }while(!sftp_handle);
+#ifdef SSH_DEBUG
   fprintf(stderr, "libssh2_sftp_open() is done, get file information\n");
+#endif
   do {
   rc = libssh2_sftp_stat_ex(sessions[cnt]->sftp_session, targetPath, strlen(targetPath),
@@ -295,8 +297,10 @@
   else
     {
+#ifdef SSH_DEBUG
       fprintf(stderr, "Stat Data: RetCode=%d\n", rc);
       fprintf(stderr, "Stat Data: Size=%llu\n", attrs.filesize);
       fprintf(stderr, "Stat Data: Perm=%lx\n",  attrs.permissions);
       fprintf(stderr, "Stat Data: mtime=%lu\n",  attrs.mtime);
+#endif
       if(rc==0)
 	break;
@@ -348,4 +352,6 @@
       return false;
     }
+    if(!sessions[cnt]->sftp_session)
+      zSleep(10);
   } while (!sessions[cnt]->sftp_session);
 
@@ -363,4 +369,6 @@
       return false;
     }
+    if(!sftp_handle)
+      zSleep(10);
   } while (!sftp_handle);
   start = time(NULL);
@@ -432,4 +440,6 @@
       return -1;
     }
+    if(!sessions[cnt]->sftp_session)
+      zSleep(10);
   } while (!sessions[cnt]->sftp_session);
   do {
@@ -482,5 +492,5 @@
       return -1;
     }
- 
+    
   } while (1);
   duration = (int)(time(NULL)-start);
@@ -503,33 +513,19 @@
   int exitcode;
   char *exitsignal=(char *)"none";
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL &&
 	 libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) {
-    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-    fflush(stderr);
-      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
-  }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
+    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+  }
   if( channel == NULL ){
     fprintf(stderr,"Error\n");
     return -1;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) {
-    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-    fflush(stderr);
     waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   if( rc != 0 ) {
     fprintf(stderr,"Error\n");
     return -1;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
 
   map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
@@ -539,6 +535,4 @@
   FILE* logFile=fopen(logPath,"wb");
   free(logPath);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while(true){
     int rc;
@@ -563,16 +557,8 @@
       break;
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   fclose(logFile);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   exitcode = 127;
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN )
     waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   if( rc == 0 ) {
@@ -581,6 +567,4 @@
 				    NULL, NULL, NULL, NULL, NULL);
   }
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   if (exitsignal)
@@ -588,6 +572,4 @@
   else
     fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
-  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-  fflush(stderr);
   
   libssh2_channel_free(channel);
@@ -664,5 +646,5 @@
     }
   }
-#ifdef DEBUG  
+#ifdef SSH_DEBUG  
   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
   fflush(stderr);
@@ -682,5 +664,5 @@
     return false;
   }
-#ifdef DEBUG
+#ifdef SSH_DEBUG
   fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
   fflush(stderr);
@@ -700,5 +682,7 @@
 	getMapArray(queueMaps->content,"targetPath",i)
       };
+#ifdef SSH_DEBUG      
       fprintf(stderr,"*** %s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
+#endif      
       /**/zooLock* lck;
       if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/
Index: branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/ulinet.c	(revision 860)
@@ -316,9 +316,9 @@
   if(passThrough!=NULL && targetHosts!=NULL){
     char *tmp=zStrdup(passThrough->value);
-    char *token, *saveptr;
-    token = strtok_r (tmp, ",", &saveptr);
     int i;
     for(i=0;i<handle->nb;i++){
       if(strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,handle->ihandle[i].url)==1){
+	char *token, *saveptr;
+	token = strtok_r (tmp, ",", &saveptr);
 	while (token != NULL){
 	  int length=strlen(token)+6;
@@ -338,7 +338,7 @@
 	    AddMissingHeaderEntry(&handle->ihandle[i],token,tmpMap->value);
 	  }
-	  free(tmp1);
 	  if(handle->ihandle[i].header!=NULL)
 	    curl_easy_setopt(handle->ihandle[i].handle,CURLOPT_HTTPHEADER,handle->ihandle[i].header);
+	  free(tmp1);
 	  cnt+=1;
 	  token = strtok_r (NULL, ",", &saveptr);
@@ -520,8 +520,5 @@
     if(curl_multi_perform(hInternet->handle, &still_running)==CURLM_OK)
       if(still_running){
-	struct timespec tv;
-	tv.tv_sec = 0;
-	tv.tv_nsec = (long) 100;
-	nanosleep(&tv, &tv);
+	zSleep(10);
       }
   }while(still_running);  
Index: branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 859)
+++ branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 860)
@@ -2201,50 +2201,10 @@
       int hasValidCookie = -1;
       char *tcook = originalCookie = zStrdup (cgiCookie);
-      //fprintf(stderr,">>>>> %s %d %s\n",__FILE__,__LINE__,tcook );
-      char *tmp = NULL;
       map *testing = getMapFromMaps (m, "main", "cookiePrefix");
       parseCookie(&m,originalCookie);
-      if (testing == NULL)
+      map *sessId=getMapFromMaps(m,"cookies",(testing==NULL?"ID":testing->value));
+      if (sessId!=NULL)
         {
-          tmp = zStrdup ("ID=");
-        }
-      else
-        {
-          tmp =
-            (char *) malloc ((strlen (testing->value) + 2) * sizeof (char));
-          sprintf (tmp, "%s=", testing->value);
-        }
-      if (strstr (cgiCookie, ";") != NULL)
-        {
-          char *token, *saveptr;
-          token = strtok_r (tcook, ";", &saveptr);
-          while (token != NULL)
-            {
-              if (strcasestr (token, tmp) != NULL)
-                {
-                  if (tcook != NULL)
-                    free (tcook);
-                  tcook = zStrdup (token);
-                  hasValidCookie = 1;
-                }
-              token = strtok_r (NULL, ";", &saveptr);
-            }
-        }
-      else
-        {
-          if (strstr (cgiCookie, "=") != NULL
-              && strcasestr (cgiCookie, tmp) != NULL)
-            {
-              tcook = zStrdup (cgiCookie);
-              hasValidCookie = 1;
-            }
-          if (tmp != NULL)
-            {
-              free (tmp);
-            }
-        }
-      if (hasValidCookie > 0)
-        {
-          addToMap (_tmpMaps->content, "sessid", strstr (tcook, "=") + 1);
+	  addToMap (_tmpMaps->content, "sessid", sessId->value);
           char session_file_path[1024];
           map *tmpPath = getMapFromMaps (m, "main", "sessPath");
@@ -2254,8 +2214,8 @@
           if (tmp1 != NULL)
             sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
-                     strstr (tmp1, "=") + 1);
+                     sessId->value);
           else
             sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
-                     strstr (cgiCookie, "=") + 1);
+                     sessId->value);
           free (tcook);
           maps *tmpSess = (maps *) malloc (MAPS_SIZE);
@@ -2351,10 +2311,4 @@
   if (status == NULLMAP)
     {
-      /*        hInternet = InternetOpen (
-#ifndef WIN32
-				  (LPCTSTR)
-#endif
-				  "ZooWPSClient\0",
-				  INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);*/
       if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
 	freeService (&s1);
@@ -2378,9 +2332,4 @@
       close_sql(m,0);      
 #endif      
-
-      /*#ifdef RELY_ON_DB
-      //close_sql(m,1);
-      //end_sql();
-      #endif*/
     }
   else
@@ -2433,15 +2382,4 @@
           setMapInMaps (m, "lenv", "async","true");
 	  map* r_inputs1 = createMap("ServiceName", s1->name);
-
-	  /*hInternet = InternetOpen (
-#ifndef WIN32
-				    (LPCTSTR)
-#endif
-				    "ZooWPSClient\0",
-				    INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
-#ifndef WIN32
-	  if (!CHECK_INET_HANDLE (hInternet))
-	    fprintf (stderr, "WARNING : hInternet handle failed to initialize");
-	    #endif*/
 
 	  // Create the filename for the result file (.res)
@@ -2558,5 +2496,5 @@
 	  invokeCallback(m,request_input_real_format,NULL,1,0);
 	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-	  dumpMaps(request_output_real_format);
+	  //dumpMaps(request_output_real_format);
 	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
 	    freeService (&s1);
@@ -2600,8 +2538,4 @@
 	    return -1;
 	  }
-	  dumpMaps(request_output_real_format);
-	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
-	  invokeCallback(m,request_input_real_format,NULL,1,1);
-	  fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
           if(getMapFromMaps(m,"lenv","mapError")!=NULL){
 		setMapInMaps(m,"lenv","message",_("Issue with geographic data"));
@@ -2634,6 +2568,7 @@
   fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
 #endif
-fflush(stdout);
-rewind(stdout);
+  fflush(stdout);
+  rewind(stdout);
+
   if (eres != -1)
     outputResponse (s1, request_input_real_format,
