Index: branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in	(revision 822)
@@ -38,9 +38,12 @@
 	gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c ulinet.c
 
+sshapi.o: sshapi.c
+	g++ -fPIC ${CFLAGS} -c sshapi.c
+
 request_parser.o: request_parser.c request_parser.h
 	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c
 
 sqlapi.o: sqlapi.c sqlapi.h
-	g++ -fPIC ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c
+	g++ -fPIC ${METADB_ENABLED} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c
 
 caching.o: caching.c
@@ -59,4 +62,7 @@
 	gcc ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_yaml.c
 
+meta_sql.o: meta_sql.c meta_sql.h service.h
+	g++  ${METADB_ENABLED} ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -c meta_sql.c
+
 service_internal_ms.o: service_internal_ms.c
 	gcc ${JS_ENABLED} ${GDAL_CFLAGS}  ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal_ms.c
@@ -68,4 +74,7 @@
 service_internal_otb.o: service_internal_otb.c service_internal_otb.h service.h
 	g++ ${XML2CFLAGS} ${OTBCFLAGS} ${CFLAGS} -c service_internal_otb.c
+
+service_internal_hpc.o: service_internal_hpc.c service_internal_hpc.h service.h
+	g++  ${XML2CFLAGS} ${HPCCFLAGS} ${CFLAGS} -c service_internal_hpc.c
 
 service_internal_saga.o: service_internal_saga.c service_internal_saga.h service.h
@@ -99,13 +108,13 @@
 	g++ -c ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} service_loader.c
 
-zoo_service_loader.o: zoo_service_loader.c service.h version.h ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE}
-	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED}  -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
+zoo_service_loader.o: zoo_service_loader.c service.h version.h ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE}
+	g++ -g -O2 ${GDAL_CFLAGS} ${XML2CFLAGS} ${CFLAGS} ${MONO_CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${HPC_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} ${MONO_ENABLED} ${METADB_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
 
 libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o
 	gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o ${FCGI_LDFLAGS} ${GDAL_LIBS}
 
-zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
+zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${HPC_FILES} ${METADB_FILE}
 	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
-	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
+	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} ${MONO_FILE} ${HPC_FILES} ${METADB_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
 
 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
Index: branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 822)
@@ -29,4 +29,8 @@
 YAML_FILE=@YAML_FILE@
 YAML_FILE1=@YAML_FILE1@
+
+METADB_ENABLED=@METADB@
+METADB_FILE=@METADB_FILE@
+
 
 GDAL_CFLAGS=@GDAL_CFLAGS@
@@ -67,6 +71,6 @@
 MS_FILE=@MS_FILE@
 
-ZOO_CFLAGS=-I${ZRPATH}/../thirds/cgic206/ -I${ZRPATH}/zoo-kernel/
-ZOO_LDFLAGS=@OPENSSL_LDFLAGS@ -luuid
+ZOO_CFLAGS=@GETTEXT_CFLAGS@ -I${ZRPATH}/../thirds/cgic206/ -I${ZRPATH}/zoo-kernel/
+ZOO_LDFLAGS=@GETTEXT_LDFLAGS@ @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@
 
 JAVACFLAGS=@JAVA_CPPFLAGS@
@@ -86,4 +90,9 @@
 PERL_FILE=@PERL_FILE@
 
+HPCCFLAGS=@SSH2_CPPFLAGS@ @HPC_CPPFLAGS@
+HPCLDFLAGS=@SSH2_LDFLAGS@ @HPC_LDFLAGS@
+HPC_ENABLED=@HPC_ENABLED@
+HPC_FILES=@HPC_FILES@
+
 OTBCFLAGS=@OTB_CPPFLAGS@
 OTBLDFLAGS=@OTB_LDFLAGS@
@@ -101,6 +110,6 @@
 MONO_FILE=@MONO_FILE@
 
-CFLAGS=@RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
-LDFLAGS=-lzoo_service @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS}
+CFLAGS=@SSH2_CPPFLAGS@ @GETTEXT_CFLAGS@ @PROJ_CPPFLAGS@ @RELY_ON_DB@ @DEB_DEF@ -fpic @OPENSSL_CFLAGS@ @UUID_CFLAGS@ ${FCGI_CFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+LDFLAGS=-lzoo_service @SSH2_LDFLAGS@ @PROJ_LDFLAGS@ @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS}  ${FCGI_LDFLAGS} @OPENSSL_LDFLAGS@ @UUID_LDFLAGS@ ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS} ${MONO_LDFLAGS} @GETTEXT_LDFLAGS@
 
 DATAROOTDIR=@datarootdir@/zoo-project
Index: branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 822)
@@ -178,4 +178,6 @@
     char icname[14];
     char xname[16];
+    char bname[8];
+    char hname[11];
     char oname[12];
     if(*index>0)
@@ -192,4 +194,6 @@
       sprintf(icname,"isCached_%d",i);
       sprintf(xname,"Reference_%d",i);
+      sprintf(bname,"body_%d",i);
+      sprintf(hname,"headers_%d",i);
       sprintf(oname,"Order_%d",i);
     }else{
@@ -200,4 +204,6 @@
       sprintf(icname,"isCached");
       sprintf(xname,"Reference");
+      sprintf(bname,"body");
+      sprintf(hname,"headers",i);
       sprintf(oname,"Order");
     }
@@ -255,6 +261,25 @@
 	sprintf(ltmp1,"%d",fsize);
 	map* tmp=getMapFromMaps(*m,"main","cacheDir");
+	char *request=NULL;
 	if(tmp!=NULL){
-	  char* md5str=getMd5(tmp1->value);
+	  map* tmp2;
+	  char* md5str=NULL;
+	  if((tmp2=getMap(content->content,bname))!=NULL){
+	    dumpMap(tmp2);
+	    char *tmpStr=(char*)malloc((strlen(tmp1->value)+strlen(tmp2->value)+1)*sizeof(char));
+	    sprintf(tmpStr,"%s%s",tmp1->value,tmp2->value);
+	    if((tmp2=getMap(content->content,"headers"))!=NULL){
+	      char *tmpStr2=zStrdup(tmpStr);
+	      tmpStr=(char*)malloc((strlen(tmpStr2)+strlen(tmp2->value)+1)*sizeof(char));
+	      sprintf(tmpStr,"%s%s",tmpStr2,tmp2->value);
+	      free(tmpStr2);
+	    }
+	    md5str=getMd5(tmpStr);
+	    request=zStrdup(tmpStr);
+	    free(tmpStr);
+	  }else{
+	    md5str=getMd5(tmp1->value);
+	    request=zStrdup(tmp1->value);
+	  }
 	  char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
 	  sprintf(fname,"%s/%s.zca",tmp->value,md5str);
@@ -264,7 +289,8 @@
 	addToMap((*in)->content,sname,ltmp1);
 	addToMap((*in)->content,mname,mimeType);
-	addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0);
+	addToCache(*m,request,fcontent,mimeType,fsize, NULL, 0);
 	free(fcontent);
 	free(mimeType);
+	free(request);
 	*index++;
 	
Index: branches/prototype-v0/zoo-project/zoo-kernel/configure.ac
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/configure.ac	(revision 822)
@@ -1,3 +1,5 @@
 AC_INIT([ZOO Kernel], [1.7.0], [bugs@zoo-project.org])
+
+AC_CONFIG_MACRO_DIR([macros])
 
 # Checks for programs.
@@ -12,5 +14,4 @@
 AC_CHECK_LIB([dl], [dlopen,dlsym,dlerror,dlclose])
 AC_CHECK_LIB([crypto], [EVP_DigestInit,EVP_md5,EVP_DigestUpdate,BIO_f_base64,BIO_new])
-AC_CHECK_LIB([uuid], [uuid_generate_time])
 
 DEFAULT_LIBS="$LIBS"
@@ -20,5 +21,5 @@
 # Checks for header files.
 AC_FUNC_ALLOCA
-AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.h malloc.h stddef.h stdlib.h string.h unistd.h])
+AC_CHECK_HEADERS([fcntl.h inttypes.h malloc.h stddef.h stdlib.h string.h unistd.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
@@ -38,4 +39,25 @@
 AC_FUNC_REALLOC
 AC_CHECK_FUNCS([dup2 getcwd memset setenv strdup strstr])
+
+#============================================================================
+# Detect if uuid is available
+#============================================================================
+
+AC_ARG_WITH([uuid],
+    [AS_HELP_STRING([--with-uuid=PATH], [Specifies an alternative location for the ossp-uuid library])],
+    [UUID_DIR="$withval"], [UUID_DIR="/usr/"])
+UUID_CFLAGS="-I$UUID_DIR/include"
+UUID_LDFLAGS="-L$UUID_DIR/lib -luuid"
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$UUID_CFLAGS"
+LIBS_SAVE="$LIBS"
+LIBS="$UUID_LDFLAGS"
+AC_CHECK_HEADERS([uuid/uuid.h],
+			[], [AC_MSG_ERROR([could not find header file uuid.h])])
+AC_CHECK_LIB([uuid], [uuid_generate_time],
+			[], [AC_MSG_ERROR([could not find function in uuid library])])
+CPPFLAGS="$CPPFLAGS_SAVE"
+AC_SUBST([UUID_CFLAGS])
+AC_SUBST([UUID_LDFLAGS])
 
 #============================================================================
@@ -56,6 +78,26 @@
 AC_CHECK_LIB(crypto, BIO_f_base64,
 			[], [AC_MSG_ERROR([could not find $i function in openssl library])])
+CPPFLAGS="$CPPFLAGS_SAVE"
 AC_SUBST([OPENSSL_CFLAGS])
 AC_SUBST([OPENSSL_LDFLAGS])
+
+#============================================================================
+# Detect if gettext is available
+#============================================================================
+
+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"
+LIBS_SAVE="$LIBS"
+LIBS="$GETTEXT_LDFLAGS"
+AM_GNU_GETTEXT([external], [], [])
+AC_CHECK_LIB(intl,
+			[dgettext], [] , [AC_MSG_ERROR([could not find $i function in gettext library])])
+AC_SUBST([GETTEXT_CFLAGS])
+AC_SUBST([GETTEXT_LDFLAGS])
 
 #============================================================================
@@ -145,4 +187,58 @@
 AC_SUBST([FCGI_LDFLAGS])
 
+AC_ARG_WITH([metadb],
+        [AS_HELP_STRING([--with-metadb=yes], [Activates the metadata database support])],
+        [WITHMETADB="$withval"], [WITHMETADB=""])
+
+if test "x$WITHMETADB" = "xyes"; then
+   	METADB="-DMETA_DB"
+	METADB_FILE="meta_sql.o sqlapi.o"
+else
+	METADB=""
+	METADB_FILE=""
+fi
+
+AC_SUBST([METADB])
+AC_SUBST([METADB_FILE])
+
+AC_ARG_WITH([hpc],
+        [AS_HELP_STRING([--with-hpc=yes], [Specifies if you need to activate HPC support])],
+        [HPCWITH="$withval"], [HPCWITH="no"])
+
+if test "x$HPCWITH" = "xyes"; then
+   	HPC_FILES="service_internal_hpc.o sshapi.o"
+	HPC_ENABLED="-DUSE_HPC"
+	HPC_CPPFLAGS=""
+	HPC_LDFLAGS=""
+fi
+
+AC_SUBST([HPC_CPPFLAGS])
+AC_SUBST([HPC_LDFLAGS])
+AC_SUBST([HPC_ENABLED])
+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])
+
 # ===========================================================================
 # Detect if libxml2 is installed
@@ -400,4 +496,5 @@
 AC_SUBST([MS_LIBS])
 AC_SUBST([MS_FILE])
+AC_SUBST([MS_VERSION])
 
 # ===========================================================================
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.c	(revision 822)
@@ -646,5 +646,5 @@
 void printGetCapabilitiesForProcess(registry *reg, maps* m,xmlNodePtr nc,service* serv){
   xmlNsPtr ns,ns_ows,ns_xml,ns_xlink;
-  xmlNodePtr n=NULL,nc1,nc2;
+  xmlNodePtr n=NULL,nc1,nc2,nc3;
   map* version=getMapFromMaps(m,"main","rversion");
   int vid=getVersionId(version->value);
@@ -667,4 +667,5 @@
       limit=7;
     }
+    nc3=NULL;
     for(;i<limit;i+=2){
       if(capabilities[vid][i]==NULL)
@@ -690,13 +691,32 @@
     printDescription(nc1,ns_ows,serv->name,serv->content,vid);
     tmp1=serv->metadata;
-    while(tmp1!=NULL){
+
+    addMetadata(tmp1,nc1,ns_ows,ns_xlink);
+
+    /*while(tmp1!=NULL){
       nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-      xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-      xmlAddChild(nc1,nc2);
+      if(strcmp(tmp1->name,"title")==0 ||
+	 strcmp(tmp1->name,"href")==0 ||
+	 strcmp(tmp1->name,"role")==0 ||
+	 strcmp(tmp1->name,"link_type")==0){
+	xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
+	xmlAddChild(nc1,nc2);
+      }else{
+	if(nc3==NULL)
+	  nc3 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
+	xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Name");
+	xmlAddChild(nc4,xmlNewText(BAD_CAST tmp1->name));
+	xmlNodePtr nc5 = xmlNewNode(ns_ows, BAD_CAST "Value");
+	xmlAddChild(nc5,xmlNewText(BAD_CAST tmp1->value));
+	xmlAddChild(nc3,nc4);
+	xmlAddChild(nc3,nc5);
+      }
       tmp1=tmp1->next;
-    }
-
+      }*/
+    if(nc3!=NULL)
+      xmlAddChild(nc1,nc3);
     xmlAddChild(nc,nc1);
   }
+
 }
 
@@ -734,4 +754,78 @@
     }
   }
+}
+
+int addMetadata(map* meta,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink){
+    int hasTitle=-1;
+    int hasValue=-1;
+    xmlNodePtr nc1;
+    map* oMeta=meta;
+    int isAdditionalParameters=-1;
+    //if(count(oMeta)>=2){
+    int level=0;
+    map* test=getMap(meta,"title");
+    if(test!=NULL)
+      level+=1;
+    test=getMap(meta,"href");
+    if(test!=NULL)
+      level+=1;
+    test=getMap(meta,"role");
+    if(test!=NULL)
+      level+=1;
+    if(count(oMeta)>level+1)
+      isAdditionalParameters=1;
+    //}
+    char *ctitle=NULL;
+    while(meta!=NULL){
+      if(hasTitle<0)
+	if(isAdditionalParameters<0)
+	  nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
+	else
+	  if(hasValue<0)
+	    nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+      if(strncasecmp(meta->name,"title",5)==0 ||
+	 strcasecmp(meta->name,"href")==0 ||
+	 strcasecmp(meta->name,"role")==0 ){
+	int index=5;
+	if(strncasecmp(meta->name,"title",5)==0){
+	  index=6;
+	  hasTitle=1;
+	  if(ctitle!=NULL && strcasecmp(meta->value,ctitle)!=0){
+	      xmlAddChild(nc,nc1);
+	      nc1 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameters");
+	      free(ctitle);
+	      ctitle=NULL;
+	  }
+	  if(ctitle==NULL){
+	    char *tmp=(char*)malloc((strlen(meta->name)+1)*sizeof(char));
+	    snprintf(tmp,index,"%s",meta->name);
+	    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp,BAD_CAST meta->value);
+	    free(tmp);
+	  }	  
+	  if(ctitle!=NULL)
+	    free(ctitle);
+	  ctitle=zStrdup(meta->value);
+	}
+      }else{
+	xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "AdditionalParameter");
+	xmlNodePtr nc3 = xmlNewNode(ns_ows, BAD_CAST "Name");
+	xmlAddChild(nc3,xmlNewText(BAD_CAST meta->name));
+	xmlNodePtr nc4 = xmlNewNode(ns_ows, BAD_CAST "Value");
+	xmlAddChild(nc4,xmlNewText(BAD_CAST meta->value));
+	xmlAddChild(nc2,nc3);
+	xmlAddChild(nc2,nc4);
+	xmlAddChild(nc1,nc2);
+	hasTitle=-1;
+      }
+      meta=meta->next;
+      if(hasTitle<0){
+	if(isAdditionalParameters)
+	  xmlAddChild(nc,nc1);
+	hasValue=1;
+      }
+    }
+    if(oMeta!=NULL && hasValue<0 && nc1!=NULL){
+      xmlAddChild(nc,nc1);
+    }
 }
 
@@ -843,7 +937,8 @@
     tmp1=serv->metadata;
     while(tmp1!=NULL){
-      nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
+      addMetadata(tmp1,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);
+      xmlAddChild(nc,nc1);*/
       tmp1=tmp1->next;
     }
@@ -855,4 +950,6 @@
     }
   }else{
+    tmp1=serv->metadata;
+    addMetadata(tmp1,nc,ns_ows,ns_xlink);
     addInheritedMetadata(nc,ns_ows,ns_xlink,reg,m,serv);
   }
@@ -1340,10 +1437,6 @@
 	xmlNsPtr ns_xlink=usedNs[xlinkId];
 
-	while(metadata!=NULL){
-	  nc6=xmlNewNode(ns_ows, BAD_CAST "Metadata");
-	  xmlNewNsProp(nc6,ns_xlink,BAD_CAST metadata->name,BAD_CAST metadata->value);
-	  xmlAddChild(nc2,nc6);
-	  metadata=metadata->next;
-	}
+	dumpMap(metadata);
+	addMetadata(metadata,nc2,ns_ows,ns_xlink);
 
       }
@@ -1982,5 +2075,5 @@
     elements* ecurs=getElements(e,(e!=NULL?e->name:m->name));
     ecurs=ecurs->child;
-    while(curs!=NULL){
+    while(curs!=NULL/* && ecurs!=NULL*/){
       ecurs=getElements(ecurs,(curs->name));
       map* inRequest=getMap(curs->content,"inRequest");
Index: branches/prototype-v0/zoo-project/zoo-kernel/response_print.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 822)
@@ -220,4 +220,5 @@
   void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
   void printStatusInfo(maps*,map*,char*);
+  int addMetadata(map* meta,xmlNodePtr nc,xmlNsPtr ns_ows,xmlNsPtr ns_xlink);
 
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
Index: branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/server_internal.c	(revision 822)
@@ -368,5 +368,4 @@
   FILE * file=fopen(filename,"rb");
   if(file==NULL){
-    fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);
     setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later");
     return ;
@@ -598,4 +597,5 @@
 	  setMapArray(res,"value",nb,out1->name);
 	}
+
 	nb++;
 	result=out1->name;
@@ -701,5 +701,5 @@
       }
     }
-    else { 
+    else /*toto*/{ 
       iotype* tmpIoType=NULL;
       if(tmpMaps->content!=NULL){
@@ -834,5 +834,5 @@
 	addToMap(tmpMaps->content,"inRequest","true");
       elements* tmpElements=getElements(in,tmpMaps->name);
-      if(tmpElements!=NULL && tmpElements->child!=NULL){
+      if(/*tmpMaps->child!=NULL && */tmpElements!=NULL && tmpElements->child!=NULL){
 	char *res=addDefaultValues(&tmpMaps->child,tmpElements->child,m,type,err);
 	if(strlen(res)>0){
@@ -841,5 +841,13 @@
       }
     }
-    tmpInputs=tmpInputs->next;
+    /*if(tmpInputs->child!=NULL){
+      tmpInputss=tmpInputs->next;
+      tmpInputs=tmpInputs->child;
+      if(tmpMaps!=NULL){
+	out1=tmpMaps->child;
+	out1s=tmpMaps;
+      }
+      }else*/
+      tmpInputs=tmpInputs->next;
   }
   if(tmpInputss!=NULL){
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.c	(revision 822)
@@ -98,6 +98,9 @@
     fprintf(stderr," * CONTENT [%s] \n",tmp->name);
     dumpMap(tmp->content);
-    fprintf(stderr," * CHILD [%s] \n",tmp->name);
-    dumpMaps(tmp->child);
+    if(tmp->child!=NULL){
+      fprintf(stderr," * CHILD [%s] \n",tmp->name);
+      dumpMaps(tmp->child);
+      fprintf(stderr," * /CHILD [%s] \n",tmp->name);
+    }
     tmp=tmp->next;
   }
@@ -121,7 +124,7 @@
     fflush(file);
     tmp=tmp->next;
-    cnt++;
     if(limit>=0 && cnt==limit)
       tmp=NULL;
+    cnt++;
   }
   fflush(file);
@@ -403,14 +406,16 @@
       free(tmp->child);
     }
-    freeIOType(&tmp->defaults);
-    if(tmp->defaults!=NULL)
+    if(tmp->defaults!=NULL){
+      freeIOType(&tmp->defaults);
       free(tmp->defaults);
-    freeIOType(&tmp->supported);
+    }
     if(tmp->supported!=NULL){
+      freeIOType(&tmp->supported);
       free(tmp->supported);
     }
-    freeElements(&tmp->next);
-    if(tmp->next!=NULL)
+    if(tmp->next!=NULL){
+      freeElements(&tmp->next);
       free(tmp->next);
+    }
   }
 }
@@ -973,5 +978,5 @@
  * @return a pointer to the allocated elements
  */
-elements* createElements(char* name){
+elements* createElements(const char* name){
   elements* res=(elements*)malloc(ELEMENTS_SIZE);
   res->name=zStrdup(name);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service.h	(revision 822)
@@ -281,5 +281,5 @@
 
   ZOO_DLL_EXPORT elements* createEmptyElements();
-  ZOO_DLL_EXPORT elements* createElements(char*);
+  ZOO_DLL_EXPORT elements* createElements(const char*);
   ZOO_DLL_EXPORT void setElementsName(elements**,char*);
   ZOO_DLL_EXPORT bool hasElement(elements*,const char*);
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 822)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c	(revision 822)
@@ -0,0 +1,369 @@
+/*
+ * Author : Gérald FENOY
+ *
+ * Copyright (c) 2015 GeoLabs SARL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * See Ref: http://hg.orfeo-toolbox.org/OTB/ Copyright
+ * Some parts of this code are derived from ITK. See ITKCopyright.txt for 
+ * details.
+ */
+
+#include "service_internal_hpc.h"
+#include "response_print.h"
+#include "server_internal.h"
+#include <sys/un.h>
+
+void appendOutputParameters(maps* input,char** parameters,int* cnt,service* s,map* uuid,map* targetPathMap){
+  while(input!=NULL){
+    if(input->child==NULL){
+      *cnt+=1;
+      if(*cnt==1)
+	parameters=(char**)malloc((*cnt)*sizeof(char*));
+      else
+	parameters=(char**)realloc(parameters,(*cnt)*sizeof(char*));
+      // Name every files that should be produced by the service execution
+      char* targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+10)*sizeof(char));
+      sprintf(targetName,"output_%s_%s_%s",s->name,input->name,uuid->value);
+      // TODO: We should verify if any optional tag for output is required (i.e. -out output.tiff int8)
+      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
+      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+      parameters[*cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
+      sprintf(parameters[*cnt-1],"-%s %s",input->name,targetPath);
+    }else
+      appendOutputParameters(input->child,parameters,cnt,s,uuid,targetPathMap);
+    input=input->next;
+  }
+}
+
+/**
+ * Load and run a HPC Application corresponding to the service.
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param request the map containing the HTTP request
+ * @param s the service structure
+ * @param real_inputs the maps containing the inputs
+ * @param real_outputs the maps containing the outputs
+ */
+int zoo_hpc_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
+  maps* m=*main_conf;
+  maps* inputs=*real_inputs;
+  maps* outputs=*real_outputs;
+  map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd");
+  char *ntmp=tmp0->value;
+  map* tmp=NULL;
+  int res=-1;
+  map* targetPathMap=getMapFromMaps(*main_conf,"HPC","storagePath");
+  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
+  map* uuid=getMapFromMaps(*main_conf,"lenv","usid");
+
+  sleep(5);
+
+  maps* input=*real_inputs;
+  char **parameters=NULL;
+  int parameters_cnt=0;
+  while(input!=NULL){
+    parameters_cnt+=1;
+    if(parameters_cnt==1)
+      parameters=(char**)malloc(parameters_cnt*sizeof(char*));
+    else
+      parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
+    if(getMap(input->content,"mimeType")!=NULL){
+      // Input is ComplexData
+      SSHCON *test=ssh_connect(*main_conf);
+      dumpMaps(getMaps(*main_conf,"lenv"));
+      if(test==NULL){	
+	sleep(3600);
+	return -1;
+      }
+      if(getMap(input->content,"cache_file")==NULL){
+	// Input data has been passed by value
+	// TODO: store data remotely
+	// TODO: publish input through MapServer / use output publication
+	dumpMapsValuesToFiles(main_conf,&input);
+      }
+      if(getMap(input->content,"cache_file")!=NULL){
+	// Input data passed by reference or by value
+	map* tmp=getMap(input->content,"cache_file");
+	char* targetName=strrchr(tmp->value,'/');
+	char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
+	sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+	ssh_copy(*main_conf,tmp->value,targetPath);
+	parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
+	sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
+	free(targetPath);
+      }else{
+	// ???
+	fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
+	fflush(stderr);
+      }
+    }else{
+      // LitteralData and BboxData 
+      if(getMap(input->content,"dataType")!=NULL){
+	// For LitteralData, simply pass the value
+	map* val=getMap(input->content,"value");
+	sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,val->value);
+      }
+      
+    }
+    input=input->next;
+  }
+
+  // Add the filename to generate for every output to the parameters
+  input=*real_outputs;
+  // TODO: fix appendOutputParameters
+  //appendOutputParameters(input,parameters,&parameters_cnt,s,uuid,targetPathMap);
+  while(input!=NULL){
+    // TODO: parse all outputs including inner outputs if required.
+    if(input->child==NULL){
+      parameters_cnt+=1;
+      if(parameters_cnt==1)
+	parameters=(char**)malloc(parameters_cnt*sizeof(char*));
+      else
+	parameters=(char**)realloc(parameters,parameters_cnt*sizeof(char*));
+      // Name every files that should be produced by the service execution
+      char* targetName=(char*)malloc((strlen(s->name)+strlen(input->name)+strlen(uuid->value)+10)*sizeof(char));
+      sprintf(targetName,"output_%s_%s_%s",s->name,input->name,uuid->value);
+      // TODO: We should verify if any optional tag for output is required (i.e. -out output.tiff *int8*)
+      // TODO: Add support for Array values
+      char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
+      sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+      setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
+      parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char));
+      sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath);
+    }
+    input=input->next;
+  }
+  
+  // Produce the SBATCH File locally
+  char *scriptPath=(char*)malloc((strlen(s->name)+strlen(tmpPath->value)+strlen(uuid->value)+9)*sizeof(char));
+  sprintf(scriptPath,"%s/zoo_%s_%s.sh",tmpPath->value,s->name,uuid->value);
+  FILE* scriptFile=fopen(scriptPath,"w+");
+  maps* hpc_opts=getMaps(*main_conf,"sbatch_options");
+  map* hpc_opts_content=hpc_opts->content;
+  map* headerMap=getMapFromMaps(*main_conf,"HPC","header");
+  if(headerMap!=NULL){
+    // Use the header file if defined in the HPC section of the main.cfg file
+    struct stat f_status;
+    int s=stat(headerMap->value, &f_status);
+    if(s==0){
+      char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(headerMap->value,"rb");
+      fread(fcontent,f_status.st_size,1,f);
+      int fsize=f_status.st_size;
+      fcontent[fsize]=0;
+      fclose(f);
+      fprintf(scriptFile,"%s\n### --- ZOO-Service HEADER end --- ###",fcontent);
+      free(fcontent);
+    }else
+      fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER (no header found) *** ###\n\n");
+  }else
+    fprintf(scriptFile,"#!/bin/bash\n\n### *** Default ZOO-Service HEADER *** ###\n\n");
+  
+  while(hpc_opts_content!=NULL){
+    fprintf(scriptFile,"#SBATCH --%s=%s\n",hpc_opts_content->name,hpc_opts_content->value);
+    hpc_opts_content=hpc_opts_content->next;
+  }
+  fprintf(scriptFile,"#SBATCH --job-name=ZOO-Project_%s_%s\n\n",uuid->value,s->name);
+  map* mods=getMap(s->content,"hpcModules");
+  if(mods!=NULL)
+    fprintf(scriptFile,"#SBATCH --export=MODULES=%s\n",mods->value);
+  else
+    fprintf(scriptFile,"#SBATCH --export=MODULES=\n");
+  map* sp=getMap(s->content,"serviceProvider");
+  // Require to produce the command line to be executed
+  fprintf(scriptFile,"\n\necho \"Job started at: $(date)\"\n");
+  fprintf(scriptFile,"echo \"Running service: [%s]\"\n",sp->value);
+  fprintf(scriptFile,"%s ",sp->value);
+  for(int i=0;i<parameters_cnt;i++){
+    fprintf(scriptFile," %s",parameters[i]);
+    //free(parameters[i]);
+  }
+  free(parameters);
+  fprintf(scriptFile,"\n");
+  fprintf(scriptFile,"echo \"Job finished at: $(date)\"\n");
+  
+  fflush(scriptFile);
+  fclose(scriptFile);
+
+  // Upload the SBATCH File to the remote host
+  targetPathMap=getMapFromMaps(*main_conf,"HPC","executePath");
+  if(targetPathMap==NULL){
+    setMapInMaps(*main_conf,"lenv","message",_("There is no executePath defined in you HPC section!"));
+    return SERVICE_FAILED;
+  }
+  char* targetName=strrchr(scriptPath,'/');
+  char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char));
+  sprintf(targetPath,"%s/%s",targetPathMap->value,targetName);
+  SSHCON *test=ssh_connect(*main_conf);
+  ssh_copy(*main_conf,scriptPath,targetPath);
+  
+  // Execute the SBATCH script remotely
+  map* subStr=getMapFromMaps(*main_conf,"HPC","subStr");
+  //char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+37)*sizeof(char));
+  char *command=(char*)malloc((strlen(targetPath)+strlen(targetPathMap->value)+strlen(subStr->value)+strlen(uuid->value)+137)*sizeof(char));
+  //sprintf(command,"ls # %s 2> %s/error_%s.log | sed \"s:%s::g\"",targetPath,targetPathMap->value,uuid->value,subStr->value);
+  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)==0){
+    // The sbatch command has failed!
+    // Download the error log file from the HPC server
+    char tmpS[1024];
+    free(command);
+    command=(char*)malloc((strlen(targetPathMap->value)+strlen(uuid->value)+22)*sizeof(char));
+    sprintf(command,"%s/error_%s.log",targetPathMap->value,uuid->value);
+    targetName=strrchr(command,'/');
+    free(targetPath);
+    targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(targetName)+2)*sizeof(char));
+    sprintf(targetPath,"%s/%s",tmpPath->value,targetName);
+    if(ssh_fetch(*main_conf,targetPath,command)==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
+	setMapInMaps(*main_conf,"lenv","message",_("No message provided"));
+    }else
+      setMapInMaps(*main_conf,"lenv","message",_("Unable to fetch the remote error log file"));
+    tmpPath=getMapFromMaps(*main_conf,"lenv","message");
+    sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s: %s", s->name, tmpPath->value);
+    errorException(m,tmpS,"NoApplicableCode",NULL);
+    free(command);
+    free(targetPath);
+    ssh_close(*main_conf);
+    sleep(120);
+    return -1;
+  }
+
+  struct sockaddr_un addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.sun_family = AF_UNIX;
+  int rc, cl, fd = socket(AF_UNIX, SOCK_STREAM, 0);
+  char buf[100];
+  char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+19));
+  sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,uuid->value);
+  strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
+  if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+    perror("bind error");
+    sleep(120);
+    return -1;
+  }
+  if (listen(fd, 5) == -1) {
+    perror("listen error");
+    sleep(120);
+    return -1;
+  }
+  /*fd_set master, read_fds;
+  int fdmax;
+  FD_ZERO(&master);
+  FD_ZERO(&read_fds);
+  FD_SET(fd, &master);
+  if (select(fd+1, &master, NULL, NULL, NULL) == -1) {
+    perror("select");
+    sleep(120);
+    return -1;
+  }
+  if (FD_ISSET(fd, &master)) {*/
+    if ( (cl = accept(fd, NULL, NULL)) == -1) {
+      perror("accept error");
+      sleep(120);
+      return -1;
+    }else{
+      int hasPassed=-1;
+      /*FD_SET(cl,&read_fds);
+      if (select(cl+1, &read_fds, NULL, NULL, NULL) == -1) {
+	perror("select");
+	sleep(120);
+	return -1;
+	}*/
+      while ( (rc=read(cl,buf,10)) ) {	  
+	if(rc==0){
+	  sleep(120);
+	  return -1;
+	}else{
+	  if(rc<0){
+	    perror("read");
+	    sleep(120);
+	    return -1;
+	  }
+	}
+	hasPassed=1;
+	res=atoi(buf);
+	unlink(sname);
+	if(res==3){
+	  input=*real_outputs;
+	  while(input!=NULL){
+	    // TODO: parse all outputs including inner outputs if required.
+	    if(input->child==NULL){
+	      //map* dataPath=getMapFromMaps(*main_conf,"main","dataPath");
+	      map* generatedFile=getMap(input->content,"generated_file");
+	      if(generatedFile!=NULL){
+		char* filename=strrchr(generatedFile->value,'/');
+		char* targetPath=(char*)malloc((strlen(tmpPath->value)+strlen(filename)+2)*sizeof(char));
+		sprintf(targetPath,"%s/%s",tmpPath->value,filename);
+		test=ssh_connect(*main_conf);
+		if(ssh_fetch(*main_conf,targetPath,generatedFile->value)==0){
+		  setMapInMaps(*real_outputs,input->name,"generated_file",targetPath);
+		}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);
+		  return SERVICE_FAILED;
+		}
+	      }
+	    }/*else{
+	     // Generate the nested outputs based on each input value
+	     if(getMaps(*real_inputs,input->name)!=NULL && getMapFromMaps(*real_inputs,input->name,"mimeType")!=NULL){
+	     // Input was ComplexeData
+	     maps* output=getMaps(*real_outputs,input->name);
+	     map* cache=getMapFromMaps(*real_inputs,input->name,"cache_file");
+	     setMapInMaps(output->child,"download","generated_file",cache->value);
+	     setMapInMaps(output->child,"WCS_LINK","generated_file",cache->value);
+	     setMapInMaps(output->child,"WCS_LINK","useMs","true");
+	     setMapInMaps(output->child,"WMS_LINK","generated_file",cache->value);
+	     setMapInMaps(output->child,"WMS_LINK","useMs","true");
+	     }
+	     }*/
+	    input=input->next;
+	  }
+	}
+      }
+      if(hasPassed<0){
+	perror("Failed to read");
+	setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution"));
+	sleep(120);
+	return SERVICE_FAILED;
+      }
+    }
+    //}
+  ssh_close(*main_conf);
+  //sleep(120);
+  return res;
+}
+
+    
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.h	(revision 822)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.h	(revision 822)
@@ -0,0 +1,41 @@
+/*
+ * Author : Gérald FENOY
+ *
+ * Copyright (c) 2015 GeoLabs SARL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef ZOO_SERVICE_INTERNAL_HPC_H
+#define ZOO_SERVICE_INTERNAL_HPC_H 1
+
+#pragma once 
+
+#include "service_internal.h"
+#include "service.h"
+#include "cgic.h"
+#ifdef WIN32
+#include <windows.h>
+#include <direct.h>
+#endif
+#include "sshapi.h"
+
+int zoo_hpc_support(maps**,map*,service*,maps**,maps**);
+
+#endif
Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 822)
@@ -131,5 +131,15 @@
  */
 void setReferenceUrl(maps* m,maps* tmpI){
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
+  dumpMaps(tmpI);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   outputMapfile(m,tmpI);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
+  dumpMaps(tmpI);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
   if(msUrl==NULL){
@@ -150,5 +160,6 @@
     {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
     {"WFS","1.1.0","GetFeature","typename=%s","wcs_extent"},
-    {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
+    //{"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
+    {"WCS","2.0.0","GetCoverage","coverageid=%s","wcs_extent"}
   };
   int proto=0;
@@ -988,5 +999,9 @@
  */
 void outputMapfile(maps* conf,maps* outputs){
-
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
+  dumpMaps(outputs);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   /**
    * First store the value on disk
@@ -998,4 +1013,6 @@
       ext="json";
 
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   map* tmpMap=getMapFromMaps(conf,"main","dataPath");
   map* sidMap=getMapFromMaps(conf,"lenv","usid");
@@ -1009,4 +1026,6 @@
   map* sizeMap=getMap(outputs->content,"size");
   map* vData=getMap(outputs->content,"value");
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   if(sizeMap!=NULL){
     zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
@@ -1015,7 +1034,13 @@
     zWrite(f,vData->value,(strlen(vData->value)+1)*sizeof(char));
   }
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   close(f);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   addToMap(outputs->content,"storage",pszDataSource);
   free(pszDataSource);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
   /*
@@ -1024,7 +1049,15 @@
   mapObj *myMap=msNewMapObj();
   free(myMap->name);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   myMap->name=zStrdup("ZOO-Project_WXS_Server");
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   msMapSetSize(myMap,2048,2048);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   msMapSetExtent(myMap,-1,-1,1,1);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   
   /*
@@ -1035,4 +1068,6 @@
   tmp1=getMapFromMaps(conf,"main","tmpUrl");
   myMap->web.imageurl=zStrdup(tmp1->value);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
   
   /*
@@ -1045,11 +1080,20 @@
   msAppendOutputFormat(myMap,msCloneOutputFormat(o1));
   msFreeOutputFormat(o1);
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
 #ifdef USE_KML
   outputFormatObj *o2=msCreateDefaultOutputFormat(NULL,"KML","kml");
-  o2->inmapfile=MS_TRUE;  
-  msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
-  msFreeOutputFormat(o2);
-#endif
+  if(!o2){
+    perror("Unable to initialize KML driver");
+    fprintf(stderr,"Unable to initialize KML driver !\n");
+  }else{
+    o2->inmapfile=MS_TRUE;  
+    msAppendOutputFormat(myMap,msCloneOutputFormat(o2));
+    msFreeOutputFormat(o2);
+  }
+#endif
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
   outputFormatObj *o3=msCreateDefaultOutputFormat(NULL,"GDAL/GTiff","tiff");
@@ -1062,4 +1106,6 @@
     msFreeOutputFormat(o3);
   }
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
   outputFormatObj *o4=msCreateDefaultOutputFormat(NULL,"GDAL/AAIGRID","grd");
@@ -1072,4 +1118,6 @@
     msFreeOutputFormat(o4);
   }
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
 #ifdef USE_CAIRO
@@ -1085,4 +1133,6 @@
   }
 #endif
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
   /*
@@ -1091,4 +1141,6 @@
   msLoadProjectionStringEPSG(&myMap->projection,"EPSG:4326");
   myMap->transparent=1;
+  fprintf(stderr,"%s %D \n",__FILE__,__LINE__);
+  fflush(stderr);
 
   /**
Index: branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.c	(revision 822)
@@ -1,5 +1,5 @@
 /*
- * Author : David Saggiorato
- *          Gérald Fenoy
+ * Authors : David Saggiorato
+ *           Gérald Fenoy
  *  Copyright 2015 GeoLabs SARL. All rights reserved.
  *
@@ -23,5 +23,4 @@
  */
 
-#ifdef RELY_ON_DB
 #include "ogr_api.h"
 #include "ogrsf_frmts.h"
@@ -52,24 +51,31 @@
 
 /**
- * Create a GDAL / OGR string for connecting to the db backend
- * (do not support active_schema)
- * 
- * @param conf the maps containing the setting of the main.cfg file
- */
-char* createInitString(maps* conf){
+ * Create a GDAL / OGR string for connecting to a db backend defined in the
+ * key section.
+ * 
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param key the name of the section containing the connection setting
+ * @return the OGR connection string
+ */
+char* _createInitString(maps* conf,const char* key){
   char* res=NULL;
-  char keywords[5][9]={
+  char keywords[6][14]={
     "dbname",
     "host",
     "port",
     "user",
-    "password"
+    "password",
+    "active_schema"    
   };
   int i=0;
-  maps* cconf=getMaps(conf,"database");
+  maps* cconf=getMaps(conf,key);
   int len=0;
-  for(i=0;i<5;i++){
+  for(i=0;i<6;i++){
     map* tmp=getMap(cconf->content,keywords[i]);
+    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+    fflush(stderr);
     if(tmp!=NULL){
+      fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+      fflush(stderr);
       if(res==NULL){
 	res=(char*)malloc((strlen(keywords[i])+strlen(tmp->value)+4)*sizeof(char));
@@ -83,8 +89,14 @@
 	len+=strlen(res1);
 	res[len]=0;
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	fflush(stderr);
 	free(res1);
       }
     }
-  }
+    fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+    fflush(stderr);
+  }
+  fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+  fflush(stderr);
   map* tmp=getMap(cconf->content,"type");
   if(tmp!=NULL){
@@ -98,11 +110,21 @@
 
 /**
- * Connect to the db backend.
+ * Create a GDAL / OGR string for connecting to the db backend
+ * 
+ * @param conf the maps containing the setting of the main.cfg file
+ * @return the OGR connection string
+ */
+char* createInitString(maps* conf){
+  return _createInitString(conf,"database");
+}
+
+/**
+ * Connect to a db backend.
  * 
  * @param conf the maps containing the setting of the main.cfg file
  * @see createInitString
  */
-void init_sql(maps* conf){
-  char* sqlInitString=createInitString(conf);
+void _init_sql(maps* conf,const char* key){
+  char* sqlInitString=_createInitString(conf,key);
   OGRSFDriver *poDriver = NULL;
   OGRRegisterAll();
@@ -129,4 +151,14 @@
 #endif
   free(sqlInitString);
+}
+
+/**
+ * Connect to the db backend.
+ * 
+ * @param conf the maps containing the setting of the main.cfg file
+ * @see createInitString
+ */
+void init_sql(maps* conf){
+  return _init_sql(conf,"database");
 }
 
@@ -158,4 +190,24 @@
 
 /**
+ * Fetch a tuple set by executing a SQL query to the Database Backend.
+ * 
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param sqlQuery the SQL query to run
+ * @return NULL in case of failure or an OGRLayer pointer if the query succeed.
+ */
+OGRLayer *fetchSql(maps* conf,const char* sqlQuery){
+  OGRLayer *res=NULL;
+  res = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
+  return res;
+}
+
+void cleanFetchSql(maps* conf,OGRLayer *objects){
+  if( objects != NULL ){
+    zoo_DS->ReleaseResultSet( objects );
+    objects=NULL;
+  }
+}
+
+/**
  * Execute a SQL query to the SQL Database Backend.
  * 
@@ -165,9 +217,11 @@
  */
 int execSql(maps* conf,const char* sqlQuery){
+  int res=-1;
   zoo_ResultSet = zoo_DS->ExecuteSQL( sqlQuery, NULL, NULL);
   if( zoo_ResultSet != NULL ){
-    return 1;
-  }
-  return -1;
+    res=1;
+  }
+  zoo_DS->ReleaseResultSet( zoo_ResultSet );
+  return res;
 }
 
@@ -260,4 +314,5 @@
 }
 
+#ifdef RELY_ON_DB
 /**
  * Update the current status of the running service.
Index: branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.h	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sqlapi.h	(revision 822)
@@ -25,5 +25,12 @@
 #ifndef ZOO_SQLAPI_H
 #define ZOO_SQLAPI_H 1
-#ifdef RELY_ON_DB
+
+#ifdef META_DB
+#include "ogrsf_frmts.h"
+#if GDAL_VERSION_MAJOR >= 2
+#include <gdal_priv.h>
+#endif
+#endif
+
 #include "service.h"
 #include "service_internal.h"
@@ -32,4 +39,11 @@
 extern "C" {
 #endif
+  
+#ifdef META_DB
+  ZOO_DLL_EXPORT char* _createInitString(maps*,const char*);
+  ZOO_DLL_EXPORT void _init_sql(maps*,const char*);
+  ZOO_DLL_EXPORT OGRLayer *fetchSql(maps*,const char*);
+#endif
+#ifdef RELY_ON_DB
   ZOO_DLL_EXPORT void init_sql(maps*);
   ZOO_DLL_EXPORT void close_sql(maps*);
@@ -42,4 +56,5 @@
   ZOO_DLL_EXPORT char* getStatusId(maps*,char*);
   ZOO_DLL_EXPORT void removeService(maps*,char*);
+#endif
 
 #ifdef __cplusplus
@@ -48,3 +63,2 @@
 
 #endif
-#endif
Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 822)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c	(revision 822)
@@ -0,0 +1,597 @@
+/*
+ *
+ * Author : Gérald FENOY
+ *
+ * Copyright 2017 GeoLabs SARL. All rights reserved.
+ *
+ * This work was supported by public funds received in the framework of GEOSUD,
+ * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed 
+ * by the French National Research Agency
+ *
+ * permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "sshapi.h"
+
+SSHCON *sessions[MAX_PARALLEL_SSH_CON];
+
+/**
+ * Wait until one or more file descriptor has been changed for the socket for a
+ * time defined by timeout
+ * @param socket_fd int defining the sockket file descriptor
+ * @param session an exeisting LIBSSH2_SESSION
+ */ 
+int waitsocket(int socket_fd, LIBSSH2_SESSION *session)
+{
+    struct timeval timeout;
+    int rc;
+    fd_set fd;
+    fd_set *writefd = NULL;
+    fd_set *readfd = NULL;
+    int dir;
+ 
+    timeout.tv_sec = 10;
+    timeout.tv_usec = 0;
+ 
+    FD_ZERO(&fd);
+ 
+    FD_SET(socket_fd, &fd);
+ 
+    /* now make sure we wait in the correct direction */ 
+    dir = libssh2_session_block_directions(session);
+
+ 
+    if(dir & LIBSSH2_SESSION_BLOCK_INBOUND)
+        readfd = &fd;
+ 
+    if(dir & LIBSSH2_SESSION_BLOCK_OUTBOUND)
+        writefd = &fd;
+ 
+    rc = select(socket_fd + 1, readfd, writefd, NULL, &timeout);
+ 
+    return rc;
+}
+
+/**
+ * Connect to a remote host using SSH protocol
+ * @param conf maps The main configuration maps
+ * @return the libssh2 sessions pointer or NULL in case any failure occured. 
+ */
+SSHCON *ssh_connect(maps* conf){
+  unsigned long hostaddr;
+  int i, use_pw = 1;
+  struct sockaddr_in sin;
+  const char *fingerprint;
+  SSHCON *result=(SSHCON*)malloc((2*sizeof(int))+sizeof(LIBSSH2_SESSION*)+sizeof(LIBSSH2_SFTP*));
+  result->sock_id=NULL;
+  result->index=NULL;
+  result->session=NULL;
+  result->sftp_session=NULL;
+  const char *user;
+  const char *password=NULL;
+  const char *public_key;
+  char *private_key;
+  int rc;
+  FILE *local;
+  char mem[1024 * 1000];
+  char error[1024];
+  int port=22;
+
+  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
+  fflush(stderr);
+
+  map* hpc_host=getMapFromMaps(conf,"HPC","host");
+  map* hpc_port=getMapFromMaps(conf,"HPC","port");
+  map* hpc_user=getMapFromMaps(conf,"HPC","user");
+  map* hpc_password=getMapFromMaps(conf,"HPC","password");
+  map* hpc_public_key=getMapFromMaps(conf,"HPC","key");
+
+  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
+  fflush(stderr);
+
+#ifdef WIN32
+  WSADATA wsadata;
+  int err;
+  err = WSAStartup(MAKEWORD(2,0), &wsadata);
+  if (err != 0) {
+    sprintf(error, "WSAStartup failed with error: %d\n", err);
+    setMapInMaps(conf,"lenv","message",error);
+    return NULL;
+  }
+#endif
+
+  // TODO: fetch ip address for the hostname
+  if (hpc_host != NULL) {
+    hostaddr = inet_addr(hpc_host->value);
+  } else {
+    setMapInMaps(conf,"lenv","message","No host parameter found in your main.cfg file!\n");
+    return NULL;
+  }
+
+  // Default port is 22
+  if(hpc_port!=NULL){
+    port=atoi(hpc_port->value);
+  }
+
+  // In case there is no HPC > user the it must failed
+  if (hpc_user != NULL) {
+    user = hpc_user->value;
+  }else{
+    setMapInMaps(conf,"lenv","message","No user parameter found in your main.cfg file!");
+    return NULL;
+  }
+
+  // TODO: in case password is available but there is also the public key
+  // defined, then we can consider this password as the pass phrase.
+  if (hpc_password != NULL) {
+    password = hpc_password->value;
+  }else{
+    use_pw=-1;
+    if (hpc_public_key != NULL) {
+      public_key = hpc_public_key->value;
+      private_key = strdup(hpc_public_key->value);
+      private_key[strlen(public_key)-4]=0;
+    }else{
+      setMapInMaps(conf,"lenv","message","No method found to authenticate!");
+      return NULL;
+    }
+  }
+
+  rc = libssh2_init (0);
+  if (rc != 0) {
+    sprintf (error, "libssh2 initialization failed (%d)\n", rc);
+    setMapInMaps(conf,"lenv","message",error);
+    return NULL;
+  }
+
+  result->sock_id = socket(AF_INET, SOCK_STREAM, 0);
+  sin.sin_family = AF_INET;
+  sin.sin_port = htons(port);
+  sin.sin_addr.s_addr = hostaddr;
+  if (connect(result->sock_id, (struct sockaddr*)(&sin),sizeof(struct sockaddr_in)) != 0) {
+    setMapInMaps(conf,"lenv","message","Failed to connect to remote host!");
+    return NULL;
+  }
+
+  result->session = libssh2_session_init();
+  result->sftp_session = NULL;
+  map* tmp=getMapFromMaps(conf,"lenv","nb_sessions");
+  if(tmp!=NULL){
+    char nb_sessions[10];
+    int nb_sess=atoi(tmp->value);
+    sprintf(nb_sessions,"%d",nb_sess+1);
+    setMapInMaps(conf,"lenv","nb_sessions",nb_sessions);
+    result->index=nb_sess+1;
+    sessions[nb_sess+1]=result;
+  }else{
+    setMapInMaps(conf,"lenv","nb_sessions","0");
+    sessions[0]=result;
+    result->index=0;
+  }
+
+  if (!result->session)
+    return NULL;
+
+  libssh2_session_set_blocking(result->session, 0);
+
+  while ((rc = libssh2_session_handshake(result->session, result->sock_id))
+	 == LIBSSH2_ERROR_EAGAIN);
+
+  if (rc) {
+    sprintf(error, "Failure establishing SSH session: %d\n", rc);
+    setMapInMaps(conf,"lenv","message",error);
+    return NULL;
+  }
+
+  fingerprint = libssh2_hostkey_hash(result->session, LIBSSH2_HOSTKEY_HASH_SHA1);
+  
+  if (use_pw>0) {
+    while ((rc = libssh2_userauth_password(result->session, user, password)) ==
+	   LIBSSH2_ERROR_EAGAIN);
+    if (rc) {
+      setMapInMaps(conf,"lenv","message","Authentication by password failed.");
+      ssh_close(conf);
+      return NULL;
+    }
+  } else {
+    while ((rc = libssh2_userauth_publickey_fromfile(result->session, user,
+						     public_key,
+						     private_key,
+						     password)) ==
+	   LIBSSH2_ERROR_EAGAIN);
+    if (rc) {
+      setMapInMaps(conf,"lenv","message","Authentication by public key failed");
+      ssh_close(conf);
+      return NULL;
+    }
+    free(private_key);
+  }
+
+  return result;
+
+}
+
+/** 
+ * Get the number of opened SSH connections
+ * @param conf maps pointer to the main configuration maps
+ * @return the number of opened SSH connections
+ */
+int ssh_get_cnt(maps* conf){
+  int result=0;
+  map* myMap=getMapFromMaps(conf,"lenv","cnt_session");
+  if(myMap!=NULL){
+    result=atoi(myMap->value);
+  }
+  return result;
+}
+
+/** 
+ * Verify if a file exists on the remote host
+ * @param conf maps pointer to the main configuration maps
+ * @param targetPath const char* defining the path for storing the file on the
+ * remote host
+ * @return true in case of success, false if failure occured
+ */
+size_t ssh_file_exists(maps* conf,const char* targetPath){
+  size_t result=-1;
+  int cnt=ssh_get_cnt(conf);
+  if(cnt>0)
+    cnt-=1;
+  int rc;
+  LIBSSH2_SFTP_ATTRIBUTES attrs;
+  LIBSSH2_SFTP_HANDLE *sftp_handle;
+  do{
+    sftp_handle =
+      libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath, LIBSSH2_FXF_READ,
+			LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
+			LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
+    if (!sftp_handle) {
+      fprintf(stderr, "Unable to open file with SFTP: %d %ld\n",__LINE__,
+	      libssh2_sftp_last_error(sessions[cnt]->sftp_session));
+      return 0;
+    }
+  }while(!sftp_handle);
+  fprintf(stderr, "libssh2_sftp_open() is done, get file information\n");
+  do {
+  rc = libssh2_sftp_stat_ex(sessions[cnt]->sftp_session, targetPath, strlen(targetPath),
+			    LIBSSH2_SFTP_LSTAT, &attrs );
+  if (rc<0 &&
+      (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN))
+    {
+      fprintf(stderr, "error trying to fstat_ex, returned %d\n", rc);
+      break;
+    }
+  else
+    {
+      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);
+      if(rc==0)
+	break;
+      result=attrs.filesize;
+    }
+  } while (true);
+  libssh2_sftp_close(sftp_handle);
+  //libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
+
+  return result;
+}
+
+/** 
+ * Upload a file over an opened SSH connection
+ * @param conf maps pointer to the main configuration maps
+ * @param localPath const char* defining the local path for accessing the file
+ * @param targetPath const char* defining the path for storing the file on the
+ * remote host
+ * @return true in case of success, false if failure occured
+ */
+bool ssh_copy(maps* conf,const char* localPath,const char* targetPath){
+  char mem[1024 * 1000];
+  size_t nread;
+  size_t memuse=0;
+  time_t start;
+  long total = 0;
+  int duration;
+  int cnt=ssh_get_cnt(conf);
+  int rc;
+  LIBSSH2_SFTP_HANDLE *sftp_handle;
+  //map* myMap=getMapFromMaps(conf,"lenv","cnt_session");
+  if(getMapFromMaps(conf,"lenv","cnt_session")!=NULL){
+    char tmp[10];
+    sprintf(tmp,"%d",cnt+1);
+    setMapInMaps(conf,"lenv","cnt_session",tmp);
+  }else
+    setMapInMaps(conf,"lenv","cnt_session","0");
+  FILE *local = fopen(localPath, "rb");
+  if (!local) {
+    fprintf(stderr, "Can't open local file %s\n", localPath);
+    return -1;
+  }
+
+  do {
+    sessions[cnt]->sftp_session = libssh2_sftp_init(sessions[cnt]->session);
+    if (!sessions[cnt]->sftp_session &&
+	(libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN)) {
+      
+      fprintf(stderr, "Unable to init SFTP session\n");
+      return false;
+    }
+  } while (!sessions[cnt]->sftp_session);
+
+  do {
+    sftp_handle =
+      libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath,
+			
+			LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
+			LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|
+			LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);
+
+    if (!sftp_handle &&
+	(libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN)) {
+      
+      fprintf(stderr, "Unable to open file with SFTP\n");
+      return false;
+    }
+  } while (!sftp_handle);
+  start = time(NULL);
+  
+  do {
+    nread = fread(&mem[memuse], 1, sizeof(mem)-memuse, local);
+    if (nread <= 0) {
+      if (memuse > 0)
+	nread = 0;
+      else
+	break;
+    }
+    memuse += nread;
+    total += nread;
+    
+    while ((rc = libssh2_sftp_write(sftp_handle, mem, memuse)) ==
+	   LIBSSH2_ERROR_EAGAIN) {
+      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+    }
+    if(rc < 0)
+      break;
+    
+    if(memuse - rc) {
+      memmove(&mem[0], &mem[rc], memuse - rc);
+      memuse -= rc;
+    }
+    else
+      memuse = 0;
+    
+  } while (rc > 0);
+  
+  duration = (int)(time(NULL)-start);
+  fclose(local);
+  libssh2_sftp_close(sftp_handle);
+
+  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
+  return true;
+}
+
+/** 
+ * Download a file over an opened SSH connection
+ * @param conf maps pointer to the main configuration maps
+ * @param localPath const char* defining the local path for storing the file
+ * @param targetPath const char* defining the path for accessing the file on the
+ * remote host
+ * @return true in case of success, false if failure occured
+ */
+int ssh_fetch(maps* conf,const char* localPath,const char* targetPath){
+  char mem[1024];
+  size_t nread;
+  size_t memuse=0;
+  time_t start;
+  long total = 0;
+  int duration;
+  int cnt=ssh_get_cnt(conf);
+  int rc;
+  LIBSSH2_SFTP_HANDLE *sftp_handle;
+  FILE *local = fopen(localPath, "wb");
+  if (!local) {
+    fprintf(stderr, "Can't open local file %s\n", localPath);
+    return -1;
+  }
+
+  do {
+    sessions[cnt]->sftp_session = libssh2_sftp_init(sessions[cnt]->session);
+    if (!sessions[cnt]->sftp_session &&
+	(libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN)) {
+      
+      fprintf(stderr, "Unable to init SFTP session\n");
+      return false;
+    }
+  } while (!sessions[cnt]->sftp_session);
+    do {
+        sftp_handle = libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath,
+
+                                        LIBSSH2_FXF_READ, 0);
+ 
+        if (!sftp_handle) {
+            if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) {
+
+                fprintf(stderr, "Unable to open file with SFTP\n");
+                return -1;
+            }
+            else {
+                fprintf(stderr, "non-blocking open\n");
+                waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session); 
+            }
+        }
+    } while (!sftp_handle);
+ 
+    int result=1;
+    do {
+        do {
+            rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
+            fprintf(stderr, "libssh2_sftp_read returned %d\n",
+                    rc);
+ 
+            if(rc > 0) {
+                write(2, mem, rc);
+                fwrite(mem, rc, 1, local);
+            }
+        } while (rc > 0);
+ 
+        if(rc != LIBSSH2_ERROR_EAGAIN) {
+	  result=-1;
+	  break;
+        }
+
+	struct timeval timeout;
+	fd_set fd;
+        timeout.tv_sec = 10;
+        timeout.tv_usec = 0;
+ 
+        FD_ZERO(&fd);
+ 
+        FD_SET(sessions[cnt]->sock_id, &fd);
+ 
+        rc = select(sessions[cnt]->sock_id+1, &fd, &fd, NULL, &timeout);
+        if(rc <= 0) {
+	  if(rc==0)
+            fprintf(stderr, "SFTP download timed out: %d\n", rc);
+	  else
+	    fprintf(stderr, "SFTP download error: %d\n", rc);
+	  result=-1;
+	  break;
+        }
+ 
+    } while (1);
+  duration = (int)(time(NULL)-start);
+  fclose(local);
+  libssh2_sftp_close(sftp_handle);
+
+  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
+  return 0;
+}
+
+/** 
+ * Execute a command over an opened SSH connection
+ * @param conf maps pointer to the main configuration maps
+ * @param command const char pointer to the command to be executed
+ * @return bytecount resulting from the execution of the command
+ */
+int ssh_exec(maps* conf,const char* command){
+  int cnt=ssh_get_cnt(conf);
+  LIBSSH2_CHANNEL *channel;
+  int rc;
+  int bytecount = 0;
+  int exitcode;
+  char *exitsignal=(char *)"none";
+  while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL &&
+	 libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) {
+      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+  }
+  if( channel == NULL ){
+    fprintf(stderr,"Error\n");
+    return 1;
+  }
+  while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) {
+    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+  }
+  if( rc != 0 ) {
+    fprintf(stderr,"Error\n");
+    return -1;
+  }
+
+  map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
+  map* uuid=getMapFromMaps(conf,"lenv","usid");
+  char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(uuid->value)+11)*sizeof(char));
+  sprintf(logPath,"%s/exec_out_%s",tmpPath->value,uuid->value);
+  FILE* logFile=fopen(logPath,"wb");
+  while(true){
+    int rc;
+    do {
+      char buffer[0x4000];
+      rc = libssh2_channel_read( channel, buffer, sizeof(buffer) );
+      
+      if( rc > 0 ){
+	int i;
+	bytecount += rc;
+	buffer[rc]=0;
+	fprintf(logFile,"%s",buffer);
+	fflush(logFile);
+      }
+    }
+    while( rc > 0 );
+    
+    if( rc == LIBSSH2_ERROR_EAGAIN ) {
+      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+    }
+    else
+      break;
+  }
+  fclose(logFile);
+  exitcode = 127;
+  while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN )
+    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
+  
+  if( rc == 0 ) {
+    exitcode = libssh2_channel_get_exit_status( channel );
+    libssh2_channel_get_exit_signal(channel, &exitsignal,
+				    NULL, NULL, NULL, NULL, NULL);
+  }
+  
+  if (exitsignal)
+    fprintf(stderr, "\nGot signal: %s\n", exitsignal);
+  else
+    fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
+  
+  libssh2_channel_free(channel);
+
+  return bytecount;
+}
+
+/** 
+ * Close an opened SSH connection
+ * @param conf maps pointer to the main configuration maps
+ * @param con SSHCON pointer to the SSH connection
+ * @return true in case of success, false if failure occured
+ */
+bool ssh_close_session(maps* conf,SSHCON* con){
+  while (libssh2_session_disconnect(con->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi")
+	 == LIBSSH2_ERROR_EAGAIN);
+  libssh2_session_free(con->session);
+#ifdef WIN32
+  closesocket(con->sock_id);
+#else
+  close(con->sock_id);
+#endif
+  return true;
+}
+
+/** 
+ * Close all the opened SSH connections
+ * @param conf maps pointer to the main configuration maps
+ * @return true in case of success, false if failure occured
+ */
+bool ssh_close(maps* conf){
+  int i,nb_sessions;
+  map* tmp=getMapFromMaps(conf,"lenv","nb_sessions");
+  if(tmp!=NULL){
+    nb_sessions=atoi(tmp->value);
+    for(i=0;i<nb_sessions;i++)
+      ssh_close_session(conf,sessions[i]);
+  }
+  libssh2_exit();
+  return true;
+}
Index: branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h	(revision 822)
+++ branches/prototype-v0/zoo-project/zoo-kernel/sshapi.h	(revision 822)
@@ -0,0 +1,97 @@
+/*
+ *
+ * Author : Gérald FENOY
+ *
+ *  Copyright 2017 GeoLabs SARL. All rights reserved.
+ *
+ * This work was supported by public funds received in the framework of GEOSUD,
+ * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed 
+ * by the French National Research Agency
+ *
+ * permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef SSHAPI_H
+#define SSHAPI_H 1
+
+#pragma once 
+
+#include <libssh2.h>
+#include <libssh2_sftp.h>
+ 
+#ifdef HAVE_WINSOCK2_H
+#include <winsock2.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+ 
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <time.h>
+
+#include "service.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_PARALLEL_SSH_CON 128  
+
+  static int nb_sessions;
+
+  typedef struct {
+    int sock_id;
+    int index;
+    LIBSSH2_SESSION *session;
+    LIBSSH2_SFTP *sftp_session;
+  } SSHCON;
+
+  
+  ZOO_DLL_EXPORT SSHCON *ssh_connect(maps*);
+  ZOO_DLL_EXPORT bool ssh_copy(maps*,const char*,const char*);
+  ZOO_DLL_EXPORT int ssh_fetch(maps*,const char*,const char*);
+  ZOO_DLL_EXPORT int ssh_exec(maps*,const char*);
+  ZOO_DLL_EXPORT bool ssh_close_session(maps*,SSHCON*);
+  ZOO_DLL_EXPORT bool ssh_close(maps*);
+  
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 821)
+++ branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 822)
@@ -26,6 +26,17 @@
 extern "C" int crlex ();
 
+#ifdef META_DB
+#include "ogrsf_frmts.h"
+#if GDAL_VERSION_MAJOR >= 2
+#include <gdal_priv.h>
+#endif
+#endif
+
 #ifdef USE_OTB
 #include "service_internal_otb.h"
+#endif
+
+#ifdef USE_HPC
+#include "service_internal_hpc.h"
 #endif
 
@@ -53,4 +64,8 @@
 #ifdef WIN32
 #include "caching.h"
+#endif
+
+#ifdef META_DB
+#include "meta_sql.h"
 #endif
 
@@ -305,5 +320,5 @@
                   return -1;
                 }
-  #ifdef DEBUG
+  #ifndef DEBUG
               fprintf (stderr, "#################\n%s\n#################\n",
                        tmps1);
@@ -330,5 +345,5 @@
               fflush (stderr);
   #endif
-        inheritance(r,&s1);
+	      inheritance(r,&s1);
               func (r, m, n, s1);
               freeService (&s1);
@@ -631,6 +646,17 @@
   else
 
+#ifdef USE_HPC
+  if (strncasecmp (r_inputs->value, "HPC", 3) == 0)
+    {
+      *eres =
+        zoo_hpc_support (&m, request_inputs, s1,
+                            &request_input_real_format,
+                            &request_output_real_format);
+    }
+  else
+#endif
+
 #ifdef USE_SAGA
-  if (strncasecmp (r_inputs->value, "SAGA", 6) == 0)
+  if (strncasecmp (r_inputs->value, "SAGA", 4) == 0)
     {
       *eres =
@@ -643,5 +669,5 @@
 
 #ifdef USE_OTB
-  if (strncasecmp (r_inputs->value, "OTB", 6) == 0)
+  if (strncasecmp (r_inputs->value, "OTB", 3) == 0)
     {
       *eres =
@@ -1304,4 +1330,7 @@
       fflush (stdout);
       dup2 (saved_stdout, fileno (stdout));
+#ifdef META_DB
+      fetchServicesFromDb(zooRegistry,m,n,printGetCapabilitiesForProcess);
+#endif      
       printDocument (m, doc, getpid ());
       freeMaps (&m);
@@ -1412,4 +1441,8 @@
 				    printDescribeProcessForProcess) < 0)
 		  return res;
+#ifdef META_DB
+		fetchServicesFromDb(zooRegistry,m,n,printDescribeProcessForProcess);
+#endif      
+
 	      }
 	    else
@@ -1427,47 +1460,56 @@
 		    if (import != NULL && import->value != NULL) 
 		      {
-			s1 = (service *) malloc (SERVICE_SIZE);
-			t = readServiceFile (m, import->value, &s1, import->name);
+#ifdef META_DB			
+			service* s2=extractServiceFromDb(m,import->name);
+			fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+			fflush(stderr);
+			if(s2==NULL){
+#endif
+			  s1 = (service *) malloc (SERVICE_SIZE);
+			  t = readServiceFile (m, import->value, &s1, import->name);
                 
-			if (t < 0) // failure reading zcfg
-			  {
-			    map *tmp00 = getMapFromMaps (m, "lenv", "message");
-			    char tmp01[1024];
-			    if (tmp00 != NULL)
-			      sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
-			    else
-			      sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
-
-			    dup2 (saved_stdout, fileno (stdout));
-			    errorException (m, tmp01, "InternalError", NULL);
-            
-			    freeMaps (&m);
-			    free (m);
-
-			    if(zooRegistry!=NULL){
-			      freeRegistry(&zooRegistry);
-			      free(zooRegistry);
+			  if (t < 0) // failure reading zcfg
+			    {
+			      map *tmp00 = getMapFromMaps (m, "lenv", "message");
+			      char tmp01[1024];
+			      if (tmp00 != NULL)
+				sprintf (tmp01, _("Unable to parse the ZCFG file: %s (%s)"), import->value, tmp00->value);
+			      else
+				sprintf (tmp01, _("Unable to parse the ZCFG file: %s."), import->value);
+			      
+			      dup2 (saved_stdout, fileno (stdout));
+			      errorException (m, tmp01, "InternalError", NULL);
+			      
+			      freeMaps (&m);
+			      free (m);
+
+			      if(zooRegistry!=NULL){
+				freeRegistry(&zooRegistry);
+				free(zooRegistry);
+			      }
+			      free (orig);
+			      free (REQUEST);
+			      closedir (dirp);
+			      xmlFreeDoc (doc);
+			      xmlCleanupParser ();
+			      zooXmlCleanupNs ();
+                    
+			      return 1;
 			    }
-			    free (orig);
-			    free (REQUEST);
-			    closedir (dirp);
-			    xmlFreeDoc (doc);
-			    xmlCleanupParser ();
-			    zooXmlCleanupNs ();
-                    
-			    return 1;
-			  }
-#ifdef DEBUG
-			dumpService (s1);
-#endif
-
-			inheritance(zooRegistry,&s1);
-			printDescribeProcessForProcess (zooRegistry,m, n, s1);
-			freeService (&s1);
-			free (s1);
-			s1 = NULL;
-			scount++;
-			hasVal = 1;                
-		    }
+#ifdef DEBUG
+			  dumpService (s1);
+#endif
+
+			  inheritance(zooRegistry,&s1);
+			  printDescribeProcessForProcess (zooRegistry,m, n, s1);
+			  freeService (&s1);
+			  free (s1);
+			  s1 = NULL;
+			  scount++;
+			  hasVal = 1;                
+#ifdef META_DB
+			}
+#endif
+		      }
 		    else if (strstr (corig, ".") != NULL)
 		      {
@@ -1479,131 +1521,159 @@
 			map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
 
-			s1 = (service *) malloc (SERVICE_SIZE);
-			t = readServiceFile (m, buff1, &s1, tmpMapI->value);
-			if (t < 0)
-			  {
-			    map *tmp00 = getMapFromMaps (m, "lenv", "message");
-			    char tmp01[1024];
-			    if (tmp00 != NULL)
-			      sprintf (tmp01,
-				       _
-				       ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
-				       tmps, tmp00->value);
-			    else
-			      sprintf (tmp01,
-				       _
-				       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
-				       tmps);
-			    dup2 (saved_stdout, fileno (stdout));
-			    errorException (m, tmp01, "InvalidParameterValue",
-					    "identifier");
-			    freeMaps (&m);
-			    free (m);
-			    if(zooRegistry!=NULL){
-			      freeRegistry(&zooRegistry);
-			      free(zooRegistry);
+#ifdef META_DB
+			service* s2=extractServiceFromDb(m,tmpMapI->name);
+			fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+			fflush(stderr);
+			if(s2==NULL){
+#endif
+			  s1 = (service *) malloc (SERVICE_SIZE);
+			  t = readServiceFile (m, buff1, &s1, tmpMapI->value);
+			  if (t < 0)
+			    {
+			      map *tmp00 = getMapFromMaps (m, "lenv", "message");
+			      char tmp01[1024];
+			      if (tmp00 != NULL)
+				sprintf (tmp01,
+					 _
+					 ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
+					 tmps, tmp00->value);
+			      else
+				sprintf (tmp01,
+					 _
+					 ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
+					 tmps);
+			      dup2 (saved_stdout, fileno (stdout));
+			      errorException (m, tmp01, "InvalidParameterValue",
+					      "identifier");
+			      freeMaps (&m);
+			      free (m);
+			      if(zooRegistry!=NULL){
+				freeRegistry(&zooRegistry);
+				free(zooRegistry);
+			      }
+			      free (REQUEST);
+			      free (corig);
+			      free (orig);
+			      free (SERVICE_URL);
+			      free (s1);
+			      closedir (dirp);
+			      xmlFreeDoc (doc);
+			      xmlCleanupParser ();
+			      zooXmlCleanupNs ();
+			      return 1;
 			    }
-			    free (REQUEST);
-			    free (corig);
-			    free (orig);
-			    free (SERVICE_URL);
-			    free (s1);
-			    closedir (dirp);
-			    xmlFreeDoc (doc);
-			    xmlCleanupParser ();
-			    zooXmlCleanupNs ();
-			    return 1;
-			  }
-#ifdef DEBUG
-			dumpService (s1);
-#endif
-			inheritance(zooRegistry,&s1);
-			printDescribeProcessForProcess (zooRegistry,m, n, s1);
-			freeService (&s1);
-			free (s1);
-			s1 = NULL;
-			scount++;
-			hasVal = 1;
-			setMapInMaps (m, "lenv", "level", "0");
+#ifdef DEBUG
+			  dumpService (s1);
+#endif
+			  inheritance(zooRegistry,&s1);
+			  printDescribeProcessForProcess (zooRegistry,m, n, s1);
+			  freeService (&s1);
+			  free (s1);
+			  s1 = NULL;
+			  scount++;
+			  hasVal = 1;
+			  setMapInMaps (m, "lenv", "level", "0");
+#ifdef META_DB
+			}
+#endif
 		      }
 		    else
 		      {
+			fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+			fflush(stderr);
+#ifdef META_DB
+			_init_sql(m,"metadb");
+			service* s2=extractServiceFromDb(m,corig);
+			if(s2!=NULL){
+			  fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+			  fflush(stderr);
+			  inheritance(zooRegistry,&s2);
+			  printDescribeProcessForProcess (zooRegistry,m, n, s2);
+			  freeService (&s2);
+			  free (s2);
+			  s2 = NULL;
+			  hasVal = 1;
+			}else /*TOTO*/{
+#endif
 			memset (buff, 0, 256);
 			snprintf (buff, 256, "%s.zcfg", corig);
 			memset (buff1, 0, 1024);
 #ifdef DEBUG
-			printf ("\n#######%s\n########\n", buff);
-#endif
-			while ((dp = readdir (dirp)) != NULL)
-			  {
-			    if (strcasecmp (dp->d_name, buff) == 0)
-			      {
-				memset (buff1, 0, 1024);
-				snprintf (buff1, 1024, "%s/%s", conf_dir,
-					  dp->d_name);
-				s1 = (service *) malloc (SERVICE_SIZE);
-				if (s1 == NULL)
-				  {
-				    dup2 (saved_stdout, fileno (stdout));
-				    return errorException (m,
-							   _
-							   ("Unable to allocate memory"),
-							   "InternalError",
-							   NULL);
-				  }
+			  printf ("\n#######%s\n########\n", buff);
+#endif
+			  while ((dp = readdir (dirp)) != NULL)
+			    {
+			      if (strcasecmp (dp->d_name, buff) == 0)
+				{
+				  memset (buff1, 0, 1024);
+				  snprintf (buff1, 1024, "%s/%s", conf_dir,
+					    dp->d_name);
+				  s1 = (service *) malloc (SERVICE_SIZE);
+				  if (s1 == NULL)
+				    {
+				      dup2 (saved_stdout, fileno (stdout));
+				      return errorException (m,
+							     _
+							     ("Unable to allocate memory"),
+							     "InternalError",
+							     NULL);
+				    }
 #ifdef DEBUG_SERVICE_CONF
-				fprintf
-				  (stderr,"#################\n(%s) %s\n#################\n",
-				   r_inputs->value, buff1);
-#endif
-				char *tmp0 = zStrdup (dp->d_name);
-				tmp0[strlen (tmp0) - 5] = 0;
-				t = readServiceFile (m, buff1, &s1, tmp0);
-				free (tmp0);
-				if (t < 0)
-				  {
-				    map *tmp00 =
-				      getMapFromMaps (m, "lenv", "message");
-				    char tmp01[1024];
-				    if (tmp00 != NULL)
-				      sprintf (tmp01,
-					       _
-					       ("Unable to parse the ZCFG file: %s (%s)"),
-					       dp->d_name, tmp00->value);
-				    else
-				      sprintf (tmp01,
-					       _
-					       ("Unable to parse the ZCFG file: %s."),
-					       dp->d_name);
-				    dup2 (saved_stdout, fileno (stdout));
-				    errorException (m, tmp01, "InternalError",
-						    NULL);
-				    freeMaps (&m);
-				    free (m);
-				    if(zooRegistry!=NULL){
-				      freeRegistry(&zooRegistry);
-				      free(zooRegistry);
+				  fprintf
+				    (stderr,"#################\n(%s) %s\n#################\n",
+				     r_inputs->value, buff1);
+#endif
+				  char *tmp0 = zStrdup (dp->d_name);
+				  tmp0[strlen (tmp0) - 5] = 0;
+				  t = readServiceFile (m, buff1, &s1, tmp0);
+				  free (tmp0);
+				  if (t < 0)
+				    {
+				      map *tmp00 =
+					getMapFromMaps (m, "lenv", "message");
+				      char tmp01[1024];
+				      if (tmp00 != NULL)
+					sprintf (tmp01,
+						 _
+						 ("Unable to parse the ZCFG file: %s (%s)"),
+						 dp->d_name, tmp00->value);
+				      else
+					sprintf (tmp01,
+						 _
+						 ("Unable to parse the ZCFG file: %s."),
+						 dp->d_name);
+				      dup2 (saved_stdout, fileno (stdout));
+				      errorException (m, tmp01, "InternalError",
+						      NULL);
+				      freeMaps (&m);
+				      free (m);
+				      if(zooRegistry!=NULL){
+					freeRegistry(&zooRegistry);
+					free(zooRegistry);
+				      }
+				      free (orig);
+				      free (REQUEST);
+				      closedir (dirp);
+				      xmlFreeDoc (doc);
+				      xmlCleanupParser ();
+				      zooXmlCleanupNs ();
+				      return 1;
 				    }
-				    free (orig);
-				    free (REQUEST);
-				    closedir (dirp);
-				    xmlFreeDoc (doc);
-				    xmlCleanupParser ();
-				    zooXmlCleanupNs ();
-				    return 1;
-				  }
-#ifdef DEBUG
-				dumpService (s1);
-#endif
-				inheritance(zooRegistry,&s1);
-				printDescribeProcessForProcess (zooRegistry,m, n, s1);
-				freeService (&s1);
-				free (s1);
-				s1 = NULL;
-				scount++;
-				hasVal = 1;
-			      }
-			  }
-		      }
+#ifdef DEBUG
+				  dumpService (s1);
+#endif
+				  inheritance(zooRegistry,&s1);
+				  printDescribeProcessForProcess (zooRegistry,m, n, s1);
+				  freeService (&s1);
+				  free (s1);
+				  s1 = NULL;
+				  scount++;
+				  hasVal = 1;
+				}
+			    }
+#ifdef META_DB
+			}
+#endif
+		      }		      
 		    if (hasVal < 0)
 		      {
@@ -2365,8 +2435,8 @@
     }
 
-#ifdef DEBUG
+  //#ifdef DEBUG
   dumpMaps (request_output_real_format);
-#endif
-
+  //#endif
+  //sleep(120);
   if (eres != -1)
     outputResponse (s1, request_input_real_format,
