Index: branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 877)
@@ -23,13 +23,10 @@
  */
 
+#include <openssl/md5.h>
+#include <openssl/evp.h>
 #include "caching.h"
 #include "service.h"
 #include "service_internal.h"
 #include "response_print.h"
-#include <openssl/md5.h>
-#include <openssl/hmac.h>
-#include <openssl/evp.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
 
 /**
@@ -61,4 +58,39 @@
   return fresult;
 }
+
+/**
+ * Compute md5 of a file
+ * 
+ * @param file the char* 
+ * @return a char* representing the md5 of the url
+ * @warning make sure to free resources returned by this function
+ */
+char* getMd5f(char* file){
+  EVP_MD_CTX md5ctx;
+  char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char));
+  unsigned char result[EVP_MAX_MD_SIZE];
+  unsigned int len;
+  int bytes;
+  unsigned char data[1024];
+  FILE *inFile = fopen (file, "rb");
+  EVP_DigestInit(&md5ctx, EVP_md5());
+  while ((bytes = fread (data, 1, 1024, inFile)) != 0)
+    EVP_DigestUpdate(&md5ctx, data, bytes);
+  EVP_DigestFinal_ex(&md5ctx,result,&len);
+  EVP_MD_CTX_cleanup(&md5ctx);
+  int i;
+  for(i = 0; i < len; i++){
+    if(i>0){
+      char *tmp=zStrdup(fresult);
+      sprintf(fresult,"%s%02x", tmp,result[i]);
+      free(tmp);
+    }
+    else
+      sprintf(fresult,"%02x",result[i]);
+  }
+  fclose (inFile);
+  return fresult;
+}
+
 
 
@@ -145,4 +177,5 @@
   map* tmp=getMapFromMaps(conf,"main","cacheDir");
   char contentr[4096];
+  char* md5fstr=NULL;
   int cred=0;
   if(tmp!=NULL){
@@ -183,5 +216,6 @@
       fclose(fo);
       fclose(fi);
-	
+
+      // Store mimeType
       sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
       fo=fopen(fname,"w+");
@@ -192,4 +226,5 @@
       fclose(fo);
 
+      // Store provenance
       sprintf(fname,"%s/%s.zcp",tmp->value,md5str);
       fo=fopen(fname,"w+");
@@ -199,4 +234,16 @@
 #endif
       fwrite(origin,sizeof(char),strlen(origin),fo);
+      fclose(fo);
+
+      // Store md5
+      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
+      md5fstr=getMd5f(fname);
+      sprintf(fname,"%s/%s.zmd",tmp->value,md5str);
+      fo=fopen(fname,"w+");
+#ifdef DEBUG
+      fprintf(stderr,"MD5: %s\n",md5fstr);
+#endif
+      fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo);
+      free(md5fstr);
       fclose(fo);
 
Index: branches/prototype-v0/zoo-project/zoo-kernel/configure.ac
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 877)
@@ -68,18 +68,20 @@
     [AS_HELP_STRING([--with-json=PATH], [Specifies an alternative location for the json-c library])],
     [JSON_DIR="$withval"], [JSON_DIR="/usr/"])
-JSON_CPPFLAGS="-I$JSON_DIR/include/json-c/"
-JSON_LDFLAGS="-L$JSON_DIR/lib -ljson-c"
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$JSON_CPPFLAGS"
-LIBS_SAVE="$LIBS"
-LIBS="$JSON_LDFLAGS"
-echo $CPPFLAGS
-AC_CHECK_HEADERS([json_object.h],
-			[], [AC_MSG_ERROR([could not find header file json_object.h])])
-AC_CHECK_LIB([json-c], [json_object_new_object],
-			[], [AC_MSG_ERROR([could not find function in json-c library])])
-CPPFLAGS="$CPPFLAGS_SAVE"
-JSON_FILE="service_json.o"
-JSON_ENABLED="-DJSON"
+if test "x$JSON_DIR" != "x"
+then
+	JSON_CPPFLAGS="-I$JSON_DIR/include/json-c/"
+	JSON_LDFLAGS="-L$JSON_DIR/lib -ljson-c"
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$JSON_CPPFLAGS"
+	LIBS_SAVE="$LIBS"
+	LIBS="$JSON_LDFLAGS"
+	AC_CHECK_HEADERS([json_object.h],
+		[], [AC_MSG_ERROR([could not find header file json_object.h])])
+	AC_CHECK_LIB([json-c], [json_object_new_object],
+		[], [AC_MSG_ERROR([could not find function in json-c library])])
+	CPPFLAGS="$CPPFLAGS_SAVE"
+	JSON_FILE="service_json.o"
+	JSON_ENABLED="-DJSON"
+fi
 AC_SUBST([JSON_CPPFLAGS])
 AC_SUBST([JSON_LDFLAGS])
@@ -112,9 +114,10 @@
 #============================================================================
 
-#AC_ARG_WITH([gettext],
-#    [AS_HELP_STRING([--with-gettext=PATH], [Specifies an alternative location for the openssl library])],
-#    [GETTEXT_DIR="$withval"], [GETTEXT_DIR="/usr/"])
-#GETTEXT_CFLAGS="-I$GETTEXT_DIR/include"
-#GETTEXT_LDFLAGS="-L$GETTEXT_DIR/lib -lintl"
+AC_ARG_WITH([gettext],
+    [AS_HELP_STRING([--with-gettext=PATH], [Specifies an alternative location for the openssl library])],
+    [GETTEXT_DIR="$withval"], [GETTEXT_DIR="/usr/"])
+
+GETTEXT_CFLAGS="-I$GETTEXT_DIR/include"
+GETTEXT_LDFLAGS="-L$GETTEXT_DIR/lib -lintl"
 #CFLAGS_SAVE="$CFLAGS"
 #CFLAGS="$GETTEXT_CFLAGS"
@@ -232,4 +235,9 @@
         [HPCWITH="$withval"], [HPCWITH="no"])
 
+
+AC_ARG_WITH([ssh2],
+        [AS_HELP_STRING([--with-ssh2=PATH], [Specifies an alternative location for the ssh2 library])],
+        [SSH2PATH="$withval"], [SSH2PATH="/usr"])
+
 if test "x$HPCWITH" = "xyes"; then
    	HPC_FILES="service_internal_hpc.o sshapi.o"
@@ -237,4 +245,18 @@
 	HPC_CPPFLAGS=""
 	HPC_LDFLAGS=""
+	# Extract the linker and include flags
+	SSH2_LDFLAGS="-L$SSH2PATH/lib -lssh2"
+	SSH2_CPPFLAGS="-I$SSH2PATH/include"
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$SSH2_CPPFLAGS"
+	LIBS_SAVE="$LIBS"
+	LIBS="$SSH2_LDFLAGS"
+	
+	AC_CHECK_HEADERS([libssh2.h],
+                 [], [AC_MSG_ERROR([could not find headers related to libssh2])])
+	AC_CHECK_LIB([ssh2], [libssh2_session_init])
+
+	LIBS="$LIBS_SAVE"
 fi
 
@@ -244,24 +266,4 @@
 AC_SUBST([HPC_FILES])
 
-AC_ARG_WITH([ssh2],
-        [AS_HELP_STRING([--with-ssh2=PATH], [Specifies an alternative location for the ssh2 library])],
-        [SSH2PATH="$withval"], [SSH2PATH="/usr"])
-
-# Extract the linker and include flags
-SSH2_LDFLAGS="-L$SSH2PATH/lib -lssh2"
-SSH2_CPPFLAGS="-I$SSH2PATH/include"
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$SSH2_CPPFLAGS"
-LIBS_SAVE="$LIBS"
-LIBS="$SSH2_LDFLAGS"
-echo $CPPFLAGS
-echo $LIBS
-
-AC_CHECK_HEADERS([libssh2.h],
-                 [], [AC_MSG_ERROR([could not find headers related to libssh2])])
-AC_CHECK_LIB([ssh2], [libssh2_session_init])
-
-LIBS="$LIBS_SAVE"
 AC_SUBST([SSH2_CPPFLAGS])
 AC_SUBST([SSH2_LDFLAGS])
@@ -805,5 +807,5 @@
 
 	AC_LANG([C++])
-	echo $JAVA_CPPFLAGS
+	#echo $JAVA_CPPFLAGS
 	# Check headers file (second time we check that in fact)
 	CPPFLAGS_SAVE="$CPPFLAGS"
@@ -855,5 +857,5 @@
 
 	AC_LANG([C++])
-	echo $JAVA_CPPFLAGS
+	#echo $JAVA_CPPFLAGS
 	# Check headers file (second time we check that in fact)
 	CPPFLAGS_SAVE="$CFLAGS"
Index: branches/prototype-v0/zoo-project/zoo-kernel/makefile.vc
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/makefile.vc	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/makefile.vc	(revision 877)
@@ -50,4 +50,7 @@
 	$(CPP) $(CFLAGS) /c caching.c
 
+service_json.obj: service_json.c service_json.h
+	$(CPP) $(CFLAGS) /c service_json.c
+
 request_parser.obj: request_parser.c request_parser.h
 	$(CPP) $(CFLAGS) /c request_parser.c
@@ -89,4 +92,7 @@
 	$(CPP) /c $(CFLAGS) $(PHP_CFLAGS) service_internal_php.c
     
+service_callback.obj: service_callback.c service_callback.h service.h
+	$(CPP) /c $(CFLAGS) service_callback.c
+    
 service_internal_php7.obj: service_internal_php7.c service_internal_php.h service.h
 	$(CPP) /c $(CFLAGS) $(PHP_CFLAGS) service_internal_php7.c    
@@ -95,6 +101,6 @@
 	link /dll /out:$(LIBZOO_SERVICE) ./service.obj ./service_internal.obj ./sqlapi.obj $(LDFLAGS) /FORCE:MULTIPLE
 
-$(PROGRAMNAME): version.h $(LIBZOO_SERVICE) zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj request_parser.obj response_print.obj server_internal.obj caching.obj
-	link zoo_loader.obj request_parser.obj response_print.obj server_internal.obj caching.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj ./libzoo_service.lib /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI) 
+$(PROGRAMNAME): version.h $(LIBZOO_SERVICE) zoo_loader.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj request_parser.obj response_print.obj server_internal.obj caching.obj service_json.obj service_callback.obj
+	link zoo_loader.obj request_parser.obj response_print.obj server_internal.obj caching.obj service_json.obj service_callback.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) $(PHP_FILE) ulinet.obj main_conf_read.tab.obj lex.cr.obj service_conf.tab.obj lex.sr.obj  zoo_service_loader.obj ./libzoo_service.lib /out:$(PROGRAMNAME) $(LDFLAGS) $(LDFLAGSCGI) ..\..\thirds\sdk\release-1800-x64/lib/json-c.lib ..\..\thirds\sdk\release-1800-x64/lib/pthread_dll.lib ..\..\thirds\sdk\release-1800-x64/lib/libxslt.lib
 
 zcfg2yaml: version.h zcfg2yaml.obj zoo_service_loader.obj service_internal.obj $(PY_FILE) $(JAVA_FILE) $(MS_FILE) $(JS_FILE) $(RUBY_FILE) ulinet.obj lex.cr.obj lex.sr.obj service_conf.tab.obj main_conf_read.tab.obj
@@ -105,3 +111,3 @@
 
 embed-manifest: zoo_loader.cgi
-	mt.exe -manifest zoo_loader.cgi.manifest -outputresource:zoo_loader.cgi;1
+	mt.exe -manifest zoo_loader.cgi.manifest -outputresource:zoo_loader.cgi;
Index: branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 877)
@@ -521,4 +521,5 @@
   int l = 0;
   map* version=getMapFromMaps(*main_conf,"main","rversion");
+  map* memory=getMapFromMaps(*main_conf,"main","memory");
   int vid=getVersionId(version->value);
   for (k=0; k < nodes->nodeNr; k++)
@@ -788,7 +789,9 @@
 							  INTERNET_OPEN_TYPE_PRECONFIG,
 							  NULL, NULL, 0);
+#ifndef WIN32
 				if (!CHECK_INET_HANDLE (bInternet))
 				  fprintf (stderr,
 					   "WARNING : bInternet handle failed to initialize");
+#endif
 				bInternet.waitingRequests[0] =
 				  strdup ((char *) val);
@@ -1109,4 +1112,8 @@
 	      }
 	    }
+	  if(memory!=NULL && strncasecmp(memory->value,"load",4)!=0)
+	    if(getMap(tmpmaps->content,"to_load")==NULL){
+	      addToMap(tmpmaps->content,"to_load","false");
+	    }
 	  {
 	    map* test=getMap(tmpmaps->content,"value");
@@ -1189,4 +1196,5 @@
     }
   }
+  return 0;
 }
 
@@ -1970,8 +1978,11 @@
 	  addToMap(res->content,name,token1);
 	free(name);
+	name=NULL;
 	i=0;
       }
       token1 = strtok_r (NULL, "=", &saveptr1);
     }
+    if(name!=NULL)
+      free(name);
     token = strtok_r (NULL, "; ", &saveptr);
   }
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 877)
@@ -693,5 +693,5 @@
     tmp1=serv->metadata;
 
-    addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink);
+    addMetadata(tmp1,doc,nc1,ns_ows,ns_xlink,vid);
     tmp1=serv->additional_parameters;
     int fromDb=-1;
@@ -750,6 +750,7 @@
  * @param ns_ows the OWS namespace
  * @param ns_xlink the xlink namespace
- */
-void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
+ * @param vid the version of WPS to use (0 for 1.0.0 and 1 for 2.0)
+ */
+void addMetadata(map* meta,xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,int vid){
     int hasTitle=-1;
     int hasValue=-1;
@@ -757,5 +758,4 @@
     map* oMeta=meta;
     int isAdditionalParameters=-1;
-    //if(count(oMeta)>=2){
     int level=0;
     map* test=getMap(meta,"title");
@@ -770,5 +770,4 @@
     if(count(oMeta)>level+1)
       isAdditionalParameters=1;
-    //}
     char *ctitle=NULL;
     while(meta!=NULL){
@@ -815,7 +814,12 @@
       meta=meta->next;
       if(hasTitle<0){
-	if(isAdditionalParameters)
-	  xmlAddChild(nc,nc1);
 	hasValue=1;
+	if(isAdditionalParameters){
+	  if(vid==0){
+	    meta=NULL;
+	    break;
+	  }else
+	    xmlAddChild(nc,nc1);
+	}
       }
     }
@@ -1049,8 +1053,5 @@
     tmp1=serv->metadata;
     while(tmp1!=NULL){
-      addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
-      /*nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-      xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-      xmlAddChild(nc,nc1);*/
+      addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid);
       tmp1=tmp1->next;
     }
@@ -1063,8 +1064,9 @@
   }else{
     tmp1=serv->metadata;
-    addMetadata(tmp1,doc,nc,ns_ows,ns_xlink);
+    addMetadata(tmp1,doc,nc,ns_ows,ns_xlink,vid);
     addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
     tmp1=serv->additional_parameters;
-    addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb);
+    if(vid!=0)
+      addAdditionalParameters(tmp1,doc,nc,ns_ows,ns_xlink,fromDb);
   }
 
@@ -1126,4 +1128,5 @@
     int isAnyValue=1;
     nc2 = xmlNewNode(NULL, BAD_CAST type);
+    // Extract min/max Occurence information
     if(strstr(type,"Input")!=NULL){
       tmp1=getMap(e->content,"minOccurs");
@@ -1168,5 +1171,5 @@
       //Build the (Literal/Complex/BoundingBox)Data node
       if(strncmp(type,"Output",6)==0){
-	if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
+	if(strncasecmp(e->format,"LITERAL",7)==0)
 	  nc3 = xmlNewNode(ns1, BAD_CAST "LiteralOutput");
 	else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
@@ -1214,5 +1217,13 @@
 		strcmp(e->format,"BoundingBoxData")==0){
 	  datatype=2;
-	  nc5 = xmlNewNode(NULL, BAD_CAST "Default");
+	  if(vid==0)
+	    nc5 = xmlNewNode(NULL, BAD_CAST "Default");
+	  else{
+	    xmlNodePtr nc6 = xmlNewNode(ns1, BAD_CAST "Format");
+	    xmlNewProp(nc6,BAD_CAST "mimeType",BAD_CAST "text/xml");
+	    xmlNewProp(nc6,BAD_CAST "default",BAD_CAST "true");
+	    xmlAddChild(nc3,nc6);
+	    nc5 = xmlNewNode(NULL, BAD_CAST "SupportedCRS");
+	  }
 	}
 	else{
@@ -1424,7 +1435,13 @@
 		 strncasecmp(tmp1->name,"range",5)!=0){
 		if(datatype!=1){
-		  char *tmp2=zCapitalize1(tmp1->name);
-		  nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
-		  free(tmp2);
+		  if(datatype==2 && vid==1){
+		    nc9 = xmlNewNode(ns, BAD_CAST "SupportedCRS");
+		    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
+		  }
+		  else{
+		    char *tmp2=zCapitalize1(tmp1->name);
+		    nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
+		    free(tmp2);
+		  }
 		}
 		else{
@@ -1435,6 +1452,10 @@
 		xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
 		if(vid==0 || oI>=3){
-		  if(vid==0 || oI!=4)
-		    xmlAddChild(nc5,nc9);
+		  if(vid==0 || oI!=4){
+		    if(datatype==2 && vid==1)
+		      xmlAddChild(nc3,nc9);
+		    else
+		      xmlAddChild(nc5,nc9);
+		  }
 		  if(oI==4 && vid==1){
 		    xmlNewProp(nc9,BAD_CAST "default",BAD_CAST "true");
@@ -1447,6 +1468,5 @@
 		  hasUOM1=true;
 		hasUOM=true;
-	      }else 	  
-		tmp1=tmp1->next;
+	      }
 	    }
 	}
@@ -1463,17 +1483,22 @@
 	  }else{
 	    if(hasUOM1==false && vid==0){
-	      xmlFreeNode(nc5);
+	      if(nc5!=NULL)
+		xmlFreeNode(nc5);
 	      if(datatype==1){
 		xmlFreeNode(nc4);
 	      }
 	    }
-	    else
+	    else{
 	      xmlAddChild(nc3,nc5);
+	    }
 	  }
 	}else{
-	  xmlAddChild(nc3,nc5);
+	  if(vid==0)
+	    xmlAddChild(nc3,nc5);
+	  else
+	    xmlFreeNode(nc5);
 	}
       
-	if(datatype!=1 && default1<0){
+	if(datatype==0 && default1<0){
 	  xmlFreeNode(nc5);
 	  if(datatype!=2){
@@ -1530,20 +1555,6 @@
 	      nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
 	      free(tmp2);
-	      //xmlNewProp(nc9, BAD_CAST "default", BAD_CAST "true");
 	      xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
 	      xmlAddChild(nc5,nc9);
-	      /*struct iotype * _ltmp=e->supported;
-		while(_ltmp!=NULL){
-		tmp1=getMap(_ltmp->content,"uom");
-		if(tmp1!=NULL){
-		char *tmp2=zCapitalize(tmp1->name);
-		nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
-		free(tmp2);
-		xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
-		xmlAddChild(nc5,nc9);
-		}
-		_ltmp=_ltmp->next;
-		}*/
-	    
 	    }
 	  }
@@ -1560,12 +1571,12 @@
 	xmlNsPtr ns_xlink=usedNs[xlinkId];
 
-	//dumpMap(metadata);
-	addMetadata(metadata,doc,nc2,ns_ows,ns_xlink);
-	addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb);
+	addMetadata(metadata,doc,nc2,ns_ows,ns_xlink,vid);
+	if(vid!=0)
+	  addAdditionalParameters(e->additional_parameters,doc,nc2,ns_ows,ns_xlink,fromDb);
 
       }
 
       _tmp=e->supported;
-      if(_tmp==NULL && datatype!=1)
+      if(_tmp==NULL && datatype==0)
 	_tmp=e->defaults;
 
@@ -1613,7 +1624,12 @@
 	       strcasecmp(tmp1->name,"extension")!=0){
 	      if(datatype!=1){
-		char *tmp2=zCapitalize1(tmp1->name);
-		nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
-		free(tmp2);
+		if(datatype==2 && vid==1){
+		  nc6 = xmlNewNode(ns, BAD_CAST "SupportedCRS");
+		}
+		else{
+		  char *tmp2=zCapitalize1(tmp1->name);
+		  nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
+		  free(tmp2);
+		}
 	      }
 	      else{
@@ -1639,6 +1655,10 @@
 	      }
 	      if(vid==0 || oI>=3){
-		if(vid==0 || oI!=4)
-		  xmlAddChild(nc5,nc6);
+		if(vid==0 || oI!=4){
+		  if(datatype==2 && vid==1)
+		    xmlAddChild(nc3,nc6);
+		  else
+		    xmlAddChild(nc5,nc6);
+		}
 		else{
 		  xmlFreeNode(nc6);
@@ -1658,9 +1678,10 @@
 	    }
 	    else{
-	      xmlAddChild(nc3,nc5);
+	      if(datatype!=2)
+		xmlAddChild(nc3,nc5);
 	    }
 
 	  }else{
-	    if(datatype!=1)
+	    if(datatype==2 && vid==0)
 	      xmlAddChild(nc3,nc5);
 	  }
@@ -1678,5 +1699,5 @@
 	  }
 	  else
-	    if(datatype!=1){
+	    if(datatype==0){
 	      xmlFreeNode(nc4);
 	      xmlAddChild(nc3,nc5);
@@ -1713,27 +1734,27 @@
       xmlAddChild(nc2,nc3);
     }else{
-      if(e->child!=NULL){
-	if(e->child!=NULL && vid!=0){
-	  printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL);
-	}
+      if(e->child!=NULL && vid!=0){
+	printFullDescription(doc,in,e->child,type,ns,ns_ows,nc2,vid,fromDb,NULL);
       }
     }
     if(e->child!=NULL && vid==0){
-      xmlFreeNode(nc3);
       elements* children=dupElements(e->child);
       elements* cursor=children;
       while(cursor!=NULL){
-	char* tmp=strdup(cursor->name);
-	free(cursor->name);
-	cursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char));
-	sprintf(cursor->name,"%s.%s",e->name,tmp);
+	elements* ccursor=cursor;
+	char* tmp=strdup(ccursor->name);
+	free(ccursor->name);
+	ccursor->name=(char*)malloc((strlen(tmp)+strlen(e->name)+2)*sizeof(char));
+	sprintf(ccursor->name,"%s.%s",e->name,tmp);
 	cursor=cursor->next;
       }
-      printFullDescription(doc,in,children,type,ns,ns_ows,nc2,vid,fromDb,serviceType);
-      xmlAddChild(nc1,nc2);
+      printFullDescription(doc,in,children,type,ns,ns_ows,nc1,vid,fromDb,serviceType);
       freeElements(&children);
       free(children);
-    }else
-      xmlAddChild(nc1,nc2);
+    }else{
+      if(nc2!=NULL){
+	xmlAddChild(nc1,nc2);
+      }
+    }
     e=e->next;
   }
@@ -1966,4 +1987,5 @@
       nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
     }
+    //dumpMaps(outputs);
     maps* mcursor=outputs;
     elements* scursor=serv->outputs;
@@ -1977,10 +1999,9 @@
 	if(testResponse==NULL || tmp0==NULL){
 	  if(vid==0)
-	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	      printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
 	  else
-	    printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	      printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
 	}
 	else
-
 	  if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
 	    if(vid==0)
@@ -2058,4 +2079,5 @@
 #endif
   }
+
   printDocument(m,doc,pid);
 
@@ -2699,4 +2721,13 @@
     return;
   }
+
+  if(res!=SERVICE_SUCCEEDED){
+    printProcessResponse(m,request_inputs1,cpid,
+                         s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
+                         request_inputs,
+                         request_outputs);
+    return;
+  }
+    
 	
   map *tmp1=getMapFromMaps(m,"main","tmpPath");
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 877)
@@ -221,5 +221,5 @@
   void printStatusInfo(maps*,map*,char*);
   void addAdditionalParameters(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
-  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr);
+  void addMetadata(map*,xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,int);
 
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 877)
@@ -539,4 +539,7 @@
  */
 map* addToMapWithSize(map* m,const char* n,const char* v,int size){
+  char sin[128];
+  char sname[10]="size";
+  map *tmp;
   if(hasKey(m,n)==false){
     map* _cursor=m;
@@ -547,8 +550,7 @@
     }
   }
-  char sname[10]="size";
   if(strlen(n)>5)
     sprintf(sname,"size_%s",n+6);
-  map *tmp=getMap(m,n);
+  tmp=getMap(m,n);
   if(tmp->value!=NULL)
     free(tmp->value);
@@ -557,5 +559,4 @@
     memmove(tmp->value,v,size*sizeof(char));
   tmp->value[size]=0;
-  char sin[128];
   sprintf(sin,"%d",size);
   addToMap(m,sname,sin);
@@ -578,12 +579,8 @@
     }
     else{
-#ifdef DEBUG
-      fprintf(stderr,"_CURSOR\n");
-      dumpMap(_cursor);
-#endif
-      while(_cursor->next!=NULL)
-	_cursor=_cursor->next;
       map* tmp1=getMap(*mo,tmp->name);
       if(tmp1==NULL){
+	while(_cursor->next!=NULL)
+	  _cursor=_cursor->next;
 	_cursor->next=createMap(tmp->name,tmp->value);
       }
@@ -594,8 +591,4 @@
     _cursor=*mo;
     tmp=tmp->next;
-#ifdef DEBUG
-    fprintf(stderr,"MO\n");
-    dumpMap(*mo);
-#endif
   }
 }
@@ -711,4 +704,5 @@
   map* size=getMap(in,"size");
   map *lout=*out;
+  map *tmpVin,*tmpVout;
   if(size!=NULL && pos>0){
     char tmp[11];
@@ -716,6 +710,6 @@
     size=getMap(in,tmp);
     sprintf(tmp,"value_%d",pos);
-    map* tmpVin=getMap(in,tmp);
-    map* tmpVout=getMap(lout,tmp);
+    tmpVin=getMap(in,tmp);
+    tmpVout=getMap(lout,tmp);
     free(tmpVout->value);
     tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
@@ -724,6 +718,6 @@
   }else{
     if(size!=NULL){
-      map* tmpVin=getMap(in,"value");
-      map* tmpVout=getMap(lout,"value");
+      tmpVin=getMap(in,"value");
+      tmpVout=getMap(lout,"value");
       free(tmpVout->value);
       tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
@@ -745,4 +739,9 @@
   map* size=getMap(in,"size");
   map* length=getMap(in,"length");
+  map* toload=getMap(in,"to_load");
+  if(toload!=NULL && strcasecmp(toload->value,"false")==0){
+    fprintf(stderr,"NO LOAD %s %d \n",__FILE__,__LINE__);
+    return ;
+  }
   if(length!=NULL){
     int len=atoi(length->value);
@@ -767,11 +766,11 @@
   maps* res=NULL;
   if(_cursor!=NULL){
+    map* mc=_cursor->content;
+    maps* mcs=_cursor->child;
     res=createMaps(_cursor->name);
-    map* mc=_cursor->content;
     if(mc!=NULL){
       addMapToMap(&res->content,mc);
       loadMapBinaries(&res->content,mc);
     }
-    maps* mcs=_cursor->child;
     if(mcs!=NULL){
       res->child=dupMaps(&mcs);
@@ -797,7 +796,7 @@
     }
     else{
+      maps* tmp1=getMaps(*mo,tmp->name);
       while(_cursor->next!=NULL)
 	_cursor=_cursor->next;
-      maps* tmp1=getMaps(*mo,tmp->name);
       if(tmp1==NULL){
 	_cursor->next=dupMaps(&tmp);
@@ -830,4 +829,5 @@
 map* getMapArray(map* m,const char* key,int index){
   char tmp[1024];
+  map* tmpMap;
   if(index>0)
     sprintf(tmp,"%s_%d",key,index);
@@ -837,5 +837,5 @@
   fprintf(stderr,"** KEY %s\n",tmp);
 #endif
-  map* tmpMap=getMap(m,tmp);
+  tmpMap=getMap(m,tmp);
 #ifdef DEBUG
   if(tmpMap!=NULL)
@@ -856,7 +856,8 @@
 void setMapArray(map* m,const char* key,int index,const char* value){
   char tmp[1024];
+  map* tmpSize;
   if(index>0){
+    map* len=getMap(m,"length");
     sprintf(tmp,"%s_%d",key,index);
-    map* len=getMap(m,"length");
     if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
       char tmp0[5];
@@ -869,10 +870,10 @@
     addToMap(m,"length","1");
   }
-  map* tmpSize=getMapArray(m,"size",index);
+  tmpSize=getMapArray(m,"size",index);
   if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
+    map* ptr=getMapOrFill(&m,tmp,(char *)"");
 #ifdef DEBUG
     fprintf(stderr,"%s\n",tmpSize->value);
 #endif
-    map* ptr=getMapOrFill(&m,tmp,(char *)"");
     free(ptr->value);
     ptr->value=(char*)malloc((atoi(tmpSize->value)+1)*sizeof(char));
@@ -930,15 +931,6 @@
   maps* tmp=mi;    
   maps* _cursor=getMaps(*mo,tmp->name);
-
-  if(_cursor==NULL)
-    return -1;
-
-  map* tmpLength=getMap(_cursor->content,"length");
   char tmpLen[10];
   int len=1;
-  if(tmpLength!=NULL){
-    len=atoi(tmpLength->value);
-  }
-
   char *tmpV[14]={
     (char*)"size",
@@ -957,7 +949,17 @@
     (char*)"UpperCorner"
   };
+  int i=0;
+  map* tmpLength;
+  
+  if(_cursor==NULL)
+    return -1;
+
+  tmpLength=getMap(_cursor->content,"length");
+  if(tmpLength!=NULL){
+    len=atoi(tmpLength->value);
+  }
+
   sprintf(tmpLen,"%d",len+1);
   addToMap(_cursor->content,"length",tmpLen);
-  int i=0;
   for(i=0;i<14;i++){
     map* tmpVI=getMap(tmp->content,tmpV[i]);
@@ -1071,4 +1073,6 @@
   elements* tmp=e;
   while(tmp!=NULL){
+    iotype* tmpio=tmp->defaults;
+    int ioc=0;
     fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
     fprintf(stderr," > CONTENT [%s]\n",tmp->name);
@@ -1079,6 +1083,4 @@
     dumpMap(tmp->additional_parameters);
     fprintf(stderr," > FORMAT [%s]\n",tmp->format);
-    iotype* tmpio=tmp->defaults;
-    int ioc=0;
     while(tmpio!=NULL){
       fprintf(stderr," > DEFAULTS [%s] (%i)\n",tmp->name,ioc);
@@ -1113,8 +1115,10 @@
   int i;
   while(tmp!=NULL){
+    map* mcurs=tmp->content;
+    int ioc=0;
+    iotype* tmpio;
     for(i=0;i<2+(4*level);i++)
       fprintf(stderr," ");
     fprintf(stderr,"%s:\n",tmp->name);
-    map* mcurs=tmp->content;
     while(mcurs!=NULL){
       for(i=0;i<4+(4*level);i++)
@@ -1144,6 +1148,5 @@
 	dumpElementsAsYAML(tmp->child,level+1);
     }
-    iotype* tmpio=tmp->defaults;
-    int ioc=0;
+    tmpio=tmp->defaults;
     while(tmpio!=NULL){
       for(i=0;i<6+(4*level);i++)
@@ -1225,10 +1228,10 @@
       tmp->defaults=NULL;
     if(cursor->supported!=NULL && cursor->supported->content!=NULL){
+      iotype *tmp2=cursor->supported->next;
       tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
       tmp->supported->content=NULL;
       addMapToMap(&tmp->supported->content,cursor->supported->content);
       tmp->supported->next=NULL;
-      iotype *tmp2=cursor->supported->next;
-      while(tmp2!=NULL){
+            while(tmp2!=NULL){
 	addMapToIoType(&tmp->supported,tmp2->content);
 #ifdef DEBUG
@@ -1373,6 +1376,6 @@
   registry* p=r;
   while(p!=NULL){
+    services* s=p->content;
     fprintf(stderr,"%s \n",p->name);
-    services* s=p->content;
     s=p->content;
     while(s!=NULL){
@@ -1573,11 +1576,12 @@
  */
 void inheritance(registry *r,service** s){
+  service* ls=*s;
+  map *profile,*level;
   if(r==NULL)
     return;
-  service* ls=*s;
-  if(ls->content==NULL)
+  if(ls==NULL || ls->content==NULL)
     return;
-  map* profile=getMap(ls->content,"extend");
-  map* level=getMap(ls->content,"level");
+  profile=getMap(ls->content,"extend");
+  level=getMap(ls->content,"level");
   if(profile!=NULL&&level!=NULL){
     service* s1;
@@ -1614,4 +1618,5 @@
   memset(tmp,0,1024*10*10);
   while(tm!=NULL){
+    map* tc=tm->content;
     if(i>=10)
       break;
@@ -1620,5 +1625,4 @@
     strcpy(tmp[i][j],tm->name);
     j++;
-    map* tc=tm->content;
     while(tc!=NULL){
       if(j>=30)
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 877)
@@ -35,4 +35,5 @@
 
 #ifdef WIN32
+#define strtok_r strtok_s
 #define strncasecmp _strnicmp
 #define strcasecmp _stricmp
@@ -196,4 +197,7 @@
 #ifdef WIN32
 #define NULLMAP ((map*) 0)
+#define bool int
+#define true 1
+#define false 0
 #else
 #define NULLMAP NULL
@@ -295,4 +299,5 @@
   ZOO_DLL_EXPORT void addToMap(map*,const char*,const char*);
   ZOO_DLL_EXPORT void addIntToMap(map*,const char*,const int);
+  ZOO_DLL_EXPORT void addIntToMapArray(map*,const char*,int,const int);
   ZOO_DLL_EXPORT map* addToMapWithSize(map*,const char*,const char*,int);
   ZOO_DLL_EXPORT void addMapToMap(map**,map*);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_callback.c	(revision 877)
@@ -220,5 +220,5 @@
     tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
     len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
-    fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT (%s)\n",pthread_self(),__FILE__,__LINE__,,tmp1);
+    fprintf(stderr,"************************* From thread %d %s %d: RESPONSE CONTENT (%s)\n",pthread_self(),__FILE__,__LINE__,tmp1);
     for(i=0;i<7;i++){
       fprintf(stderr,"%d) %d %d\n",i,steps[i][0],steps[i][1]);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_callback.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_callback.h	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_callback.h	(revision 877)
@@ -36,5 +36,4 @@
 #include <service.h>
 #include <ulinet.h>
-#include <service_json.h>
 
 #ifdef __cplusplus
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c	(revision 877)
@@ -2,5 +2,5 @@
  * Author : Gérald FENOY
  *
- * Copyright (c) 2009-2015 GeoLabs SARL
+ * Copyright (c) 2009-2018 GeoLabs SARL
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -38,4 +38,139 @@
 #endif
 
+#ifdef WIN32
+// cf. https://stackoverflow.com/questions/3168504/lockfileex-read-write-upgrade-downgrade
+// only works for (SEEK_SET, start=0, len=0) file locking.
+__inline int fcntl(int fd, int cmd, ...)
+{
+    va_list a;
+    va_start(a, cmd);
+    switch(cmd)
+    {
+    case F_SETLK:
+        {
+            struct flock *l = va_arg(a, struct flock*);
+            switch(l->l_type)
+            {
+            case F_RDLCK:
+                {
+                    LPOVERLAPPED o = { 0 };
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 1, o)) // read lock
+                    {
+                        unsigned long x = GetLastError();
+                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 1, 1); // write lock
+                }
+                break;
+            case F_WRLCK:
+                {
+                    LPOVERLAPPED o = { 0 };
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
+                    {
+                        unsigned long x = GetLastError();
+                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 0, 1); // read lock
+                }
+                break;
+            case F_UNLCK:
+                {
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 0, 1); // read lock
+                    UnlockFile(h, 0, 0, 1, 1); // write lock
+                }
+                break;
+            default:
+                _set_errno(ENOTSUP);
+                return -1;
+            }
+        }
+        break;
+    case F_SETLKW:
+        {
+            struct flock *l = va_arg(a, struct flock*);
+            switch(l->l_type)
+            {
+            case F_RDLCK:
+                {
+                    LPOVERLAPPED o = { 0 };
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    if(!LockFileEx(h, 0, 0, 0, 1, o)) // read lock
+                    {
+                        unsigned long x = GetLastError();
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 1, 1); // write lock
+                }
+                break;
+            case F_WRLCK:
+                {
+                    LPOVERLAPPED o = { 0 };
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
+                    {
+                        unsigned long x = GetLastError();
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 0, 1); // read lock
+                }
+                break;
+            case F_UNLCK:
+                {
+                    flock *l = va_arg(a, flock*);
+                    HANDLE h = (HANDLE)_get_osfhandle(fd);
+                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
+                    {
+                        _set_errno(ENOTSUP);
+                        return -1;
+                    }
+                    UnlockFile(h, 0, 0, 0, 1); // read lock
+                    UnlockFile(h, 0, 0, 1, 1); // write lock
+                }
+                break;
+            default:
+                _set_errno(ENOTSUP);
+                return -1;
+            }
+        }
+        break;
+    default:
+        _set_errno(ENOTSUP);
+        return -1;
+    }
+
+    return 0;
+}
+#endif
+
 #define ERROR_MSG_MAX_LENGTH 1024
 
@@ -53,9 +188,9 @@
   struct zooLock* myLock=(struct zooLock*)malloc(sizeof(struct flock)+sizeof(FILE*)+sizeof(char*));
   int len=6;
-  char *template="%s.lock";
+  char *myTemplate="%s.lock";
   int res=-1;
  retryLockFile:
   myLock->filename=(char*)malloc((strlen(filename)+len)*sizeof(char));
-  sprintf(myLock->filename,"%s.lock",filename);
+  sprintf(myLock->filename,myTemplate,filename);
   s=stat(myLock->filename, &f_status);
   if(s==0 && mode!='r'){
@@ -64,5 +199,5 @@
       fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",getpid(),myLock->filename,itn);
       fflush(stderr);
-      sleep(5);
+      zSleep(5);
       free(myLock->filename);
       goto retryLockFile;
@@ -105,19 +240,19 @@
       if((res=fcntl(fileno(myLock->lockfile), F_SETLK, &(myLock->lock)))==-1 &&
 	 (errno==EAGAIN || errno==EACCES)){
-	if(cnt >= ZOO_LOCK_MAX_RETRY){
-	  char message[51];	  
-	  sprintf(message,"Unable to get the lock after %d attempts.\n",cnt);
-	  setMapInMaps(conf,"lenv","message",message);
-	  fclose(myLock->lockfile);
-	  free(myLock->filename);
-	  free(myLock);
-	  return NULL;
-	}
-	fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",getpid(),myLock->filename,cnt);
-	fflush(stderr);
-	sleep(1);
-	cnt++;
-      }else
-	break;
+	  if(cnt >= ZOO_LOCK_MAX_RETRY){
+	    char message[51];	  
+	    sprintf(message,"Unable to get the lock after %d attempts.\n",cnt);
+	    setMapInMaps(conf,"lenv","message",message);
+	    fclose(myLock->lockfile);
+	    free(myLock->filename);
+	    free(myLock);
+	    return NULL;
+	  }
+	  fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",getpid(),myLock->filename,cnt);
+	  fflush(stderr);
+	  zSleep(1);
+	  cnt++;
+	}else
+	   break;
     }
     if(res<0){
@@ -163,5 +298,5 @@
 
 #ifndef RELY_ON_DB
-#include <dirent.h>
+#include "dirent.h"
 
 /**
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 877)
@@ -96,4 +96,23 @@
 #endif
 
+#ifdef WIN32
+// fcntl flock definitions
+#define F_SETLK  8   // Non-Blocking set or clear a lock
+#define F_SETLKW 9   // Blocking set or clear a lock
+#define F_GETLK 10
+#define F_RDLCK  1   // read lock
+#define F_WRLCK  2   // write lock
+#define F_UNLCK  3   // remove lock
+struct flock {
+    short l_type;   // F_RDLCK, F_WRLCK, or F_UNLCK
+    short l_whence; // flag to choose starting offset, must be SEEK_SET
+    long  l_start;  // relative offset, in bytes, must be 0
+    long  l_len;    // length, in bytes; 0 means lock to EOF, must be 0
+    short l_pid;    // unused (returned with the unsupported F_GETLK)
+    short l_xxx;    // reserved for future use
+};
+
+#endif
+
 /**
  * The lock structure used by the ZOO-Kernel to ensure atomicity of operations
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 877)
@@ -50,5 +50,5 @@
     return;
   }    
-  if(*s==NULL || (*s)->outputs==NULL){
+  if(*s==NULL || (*s)->outputs==NULL || (*s)->content==NULL){
     return;
   }
@@ -621,4 +621,24 @@
   fprintf(scriptFile,"\n");
   fprintf(scriptFile,"echo \"Job finished at: $(date)\"\n");
+  map* footerMap=getMapFromMaps(*main_conf,configurationId,"jobscript_footer");
+  if(footerMap!=NULL){
+    // Use the footer file if defined in the HPC section of the main.cfg file
+    struct stat f_status;
+    int s=stat(footerMap->value, &f_status);
+    if(s==0){
+      char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(footerMap->value,"rb");
+      fread(fcontent,f_status.st_size,1,f);
+      int fsize=f_status.st_size;
+      fcontent[fsize]=0;
+      fclose(f);
+      char* ffcontent=(char*)malloc((strlen(fcontent)+(3*strlen(uuid->value))+1)*sizeof(char));
+      sprintf(ffcontent,fcontent,uuid->value,uuid->value,uuid->value);
+      fprintf(scriptFile,"%s\n### --- ZOO-Service FOOTER end --- ###\n\n",ffcontent);
+      free(fcontent);
+    }else
+      fprintf(scriptFile,"### *** Default ZOO-Service FOOTER (footer file failed to load) *** ###\n\n");
+  }else
+      fprintf(scriptFile,"### *** Default ZOO-Service FOOTER (no footer found) *** ###\n\n");
   fflush(scriptFile);
   fclose(scriptFile);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_java.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_java.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_java.c	(revision 877)
@@ -208,5 +208,5 @@
 #endif
 #ifdef JAVA7
-  cls_gr = (*env)NewGlobalRef(cls);
+  cls_gr = (*env).NewGlobalRef(cls);
 #else
   cls_gr = (*env)->NewGlobalRef(env, cls);
@@ -215,5 +215,5 @@
   if (cls != NULL) {
 #ifdef JAVA7
-@    (*env).ExceptionClear();
+    (*env).ExceptionClear();
     pmid=(*env).GetStaticMethodID(cls, s->name, "(Ljava/util/HashMap;Ljava/util/HashMap;Ljava/util/HashMap;)I");
 #else
@@ -284,5 +284,5 @@
   }
 #ifdef JAVA7
-      (*jvm).DestroyJavaVM();
+  (*jvm).DestroyJavaVM();
 #else
   (*jvm)->DestroyJavaVM(jvm);
@@ -438,5 +438,5 @@
 	      jbyteArray tmpData=(*env).NewByteArray(atoi(sizeV->value));
 	      (*env).SetByteArrayRegion(tmpData,0,atoi(sizeV->value),(const jbyte *)tmp1->value);
-	      (*env).CallObjectMethod(env,scObject1, put_mid, (*env).NewStringUTF(env,tmp1->name), tmpData);
+	      (*env).CallObjectMethod(scObject1, put_mid, (*env).NewStringUTF(tmp1->name), tmpData);
 #else
 	      jbyteArray tmpData=(*env)->NewByteArray(env,atoi(sizeV->value));
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 877)
@@ -1020,5 +1020,6 @@
     m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));
     outputIndex=msGetOutputFormatIndex(m,"geotiff");
-    m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));    
+    if(outputIndex>=0)
+      m->outputformatlist[outputIndex]->imagemode=((pixel_type==GDT_Byte)?MS_IMAGEMODE_BYTE:((pixel_type==GDT_Int16 || pixel_type==GDT_UInt16)?MS_IMAGEMODE_INT16:((pixel_type!=GDT_Float32)?MS_IMAGEMODE_FLOAT32:MS_IMAGEMODE_BYTE)));
   }
   //
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c	(revision 877)
@@ -379,5 +379,5 @@
   int istatus;
   char* cstatus=NULL;
-  if (!isInteger(status)){
+  if (!isInteger(status) && !isReal(status)){
 #ifdef DEBUG
     fprintf(stderr,"Incorrect arguments to update status function");
@@ -385,5 +385,8 @@
     return R_NilValue;
   }
-  istatus=asInteger(status);
+  if(isInteger(status))
+    istatus=asInteger(status);
+  else
+    istatus=asReal(status);
   if (istatus < 0 || istatus > 100){
     return R_NilValue;
Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 877)
@@ -96,5 +96,4 @@
 
   map* hpc_config=getMapFromMaps(conf,"lenv","configId");
-  
   map* hpc_host=getMapFromMaps(conf,hpc_config->value,"ssh_host");
   map* hpc_port=getMapFromMaps(conf,hpc_config->value,"ssh_port");
@@ -102,5 +101,5 @@
   map* hpc_password=getMapFromMaps(conf,hpc_config->value,"ssh_password");
   map* hpc_public_key=getMapFromMaps(conf,hpc_config->value,"ssh_key");
-
+  
   char ip[100];
   struct hostent *my_hostent;
Index: branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/zoo_loader.c	(revision 877)
@@ -68,4 +68,5 @@
   fprintf(FCGI_stderr,"ZOO-Kernel initialization %s %d ... \n",__FILE__,__LINE__);
   fflush(FCGI_stderr);
+  return 0;
 }
 
Index: branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 873)
+++ branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 877)
@@ -68,4 +68,5 @@
 #ifdef WIN32
 #include "caching.h"
+extern wchar_t**_wenviron;
 #endif
 
@@ -111,5 +112,7 @@
 #include <dirent.h>
 #include <signal.h>
+#ifndef WIN32
 #include <execinfo.h>
+#endif
 #include <unistd.h>
 #ifndef WIN32
@@ -365,5 +368,6 @@
               fflush (stderr);
   #endif
-	      inheritance(r,&s1);
+	      if(s1!=NULL)
+		inheritance(r,&s1);
               func (r, m, doc, n, s1);
               freeService (&s1);
@@ -1449,6 +1453,8 @@
 	    r_inputs = NULL;
 	    r_inputs = getMap (request_inputs, "version");
+#ifdef DEBUG
 	    fprintf(stderr," ** DEBUG %s %d \n",__FILE__,__LINE__);
 	    fflush(stderr);
+#endif
 	    xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
 					  root_nodes[vid][1],(version!=NULL?version->value:"1.0.0"),1);
@@ -1628,9 +1634,4 @@
 			hasVal = 1;
 			setMapInMaps (m, "lenv", "level", "0");
-			/*
-			  #ifdef META_DB
-			  }
-			  #endif
-			*/
 		      }
 		    else
@@ -1726,7 +1727,7 @@
 				  addNestedOutputs(&s1);
 #endif
-				  json_object* jobj=serviceToJson(s1);
+				  /*json_object* jobj=serviceToJson(s1);
 				  const char* jsonStr=json_object_to_json_string_ext(jobj,JSON_C_TO_STRING_PLAIN);
-				  fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);
+				  fprintf(stderr,"*** %s %d %s \n",__FILE__,__LINE__,jsonStr);*/
 
 				  printDescribeProcessForProcess (zooRegistry,m, doc, n, s1);
@@ -1942,8 +1943,12 @@
     dup2 (fileno (stderr), fileno (stdout));
     t = readServiceFile (m, tmps1, &s1, r_inputs->value);
-    inheritance(zooRegistry,&s1);
+    fprintf(stderr,"%d %s %d",t,__FILE__,__LINE__);
+    fflush(stderr);
+    if(t>=0){
+      inheritance(zooRegistry,&s1);
 #ifdef USE_HPC
-    addNestedOutputs(&s1);
-#endif
+      addNestedOutputs(&s1);
+#endif
+    }
     if(zooRegistry!=NULL){
       freeRegistry(&zooRegistry);
@@ -2254,12 +2259,13 @@
 #endif
   int ei = 1;
-  char **orig = 
+  
 #ifdef WIN32
-    GetEnvironmentStrings()
+  LPVOID orig = GetEnvironmentStrings();
+  LPTSTR s = (LPTSTR) orig;
 #else
-    environ
-#endif
-    ;
+  char **orig = environ;
   char *s=*orig;
+#endif
+
   _tmpMaps = createMaps("renv");
   for (; s; ei++) {
@@ -2277,5 +2283,9 @@
       free(tmpName);
     }
+#ifdef WIN32
+    s++;
+#else
     s = *(orig+ei);
+#endif
   }
   if(_tmpMaps->content!=NULL && getMap(_tmpMaps->content,"HTTP_COOKIE")!=NULL){
@@ -2285,4 +2295,5 @@
   freeMaps (&_tmpMaps);
   free (_tmpMaps);
+  
   if(postRequest!=NULL)
     setMapInMaps (m, "renv", "xrequest", postRequest->value);
@@ -2335,4 +2346,7 @@
 	return -1;
       }
+      map* testMap=getMapFromMaps(m,"main","memory");
+      if(testMap!=NULL && strcasecmp(testMap->value,"load")!=0)
+	dumpMapsValuesToFiles(&m,&request_input_real_format);
       loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
                          &request_output_real_format, &eres);
@@ -2379,4 +2393,5 @@
       else if (pid == 0)
 	{
+	  eres = SERVICE_ACCEPTED;
 	  //
 	  // son : have to close the stdout, stdin and stderr to let the parent
@@ -2457,5 +2472,7 @@
 	  recordServiceStatus(m);
 #endif
+#ifdef USE_HPC
 	  invokeCallback(m,NULL,NULL,0,0);
+#endif
 	  if(vid==0){
 	    //
@@ -2499,5 +2516,7 @@
 	  free(flenv);
 
+#ifdef USE_HPC
 	  invokeCallback(m,request_input_real_format,NULL,1,0);
+#endif
 	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
 	    freeService (&s1);
@@ -2514,5 +2533,7 @@
 #else
 	    recordResponse(m,fbkp1);
+#ifdef USE_HPC
 	    invokeCallback(m,NULL,NULL,7,0);
+#endif
 #endif
 	    unlink (fbkpid);
@@ -2539,7 +2560,12 @@
 	  if(getMapFromMaps(m,"lenv","mapError")!=NULL){
 	    setMapInMaps(m,"lenv","message",_("Issue with geographic data"));
+#ifdef USE_HPC
 	    invokeCallback(m,NULL,NULL,7,0);
+#endif
 	    eres=-1;//SERVICE_FAILED;
 	  }else{
+	    map* testMap=getMapFromMaps(m,"main","memory");
+	    if(testMap!=NULL && strcasecmp(testMap->value,"load")!=0)
+	      dumpMapsValuesToFiles(&m,&request_input_real_format);
 	    loadServiceAndRun (&m, s1, request_inputs,
 			       &request_input_real_format,
@@ -2567,5 +2593,5 @@
   rewind(stdout);
 
-  fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres);
+  //fprintf(stderr,"%s %d %d\n",__FILE__,__LINE__,eres);
 
   if (eres != -1)
@@ -2592,6 +2618,7 @@
     {
       if (eres == SERVICE_SUCCEEDED)
+#ifdef USE_HPC
 	invokeCallback(m,NULL,request_output_real_format,5,1);
-
+#endif
       fflush(stderr);
       fflush(stdout);
@@ -2622,5 +2649,7 @@
       recordResponse(m,fbkp1);
       if (eres == SERVICE_SUCCEEDED)
+#ifdef USE_HPC
 	invokeCallback(m,NULL,request_output_real_format,6,0);
+#endif
 #endif
       freeMaps(&bmap);
