Index: trunk/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- trunk/zoo-project/zoo-kernel/Makefile.in	(revision 639)
+++ trunk/zoo-project/zoo-kernel/Makefile.in	(revision 640)
@@ -5,4 +5,7 @@
 version.h:
 	echo "#define ZOO_VERSION \"`svnversion`\"" > version.h
+
+service.o: service.c service.h
+	gcc ${YAML_CFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service.c
 
 main_conf_read.tab.c: main_conf_read.y service.h
@@ -34,8 +37,20 @@
 
 request_parser.o: request_parser.c request_parser.h
-	gcc -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c
+	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c request_parser.c
 
-service_internal.o: service_internal.c service.h mimetypes.h
-	g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
+sqlapi.o: sqlapi.c sqlapi.h
+	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c sqlapi.c
+
+caching.o: caching.c
+	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c caching.c
+
+response_print.o: response_print.c response_print.h
+	g++ -fPIC ${XML2CFLAGS} ${CFLAGS} ${JSCFLAGS} ${JS_ENABLED} -c response_print.c
+
+server_internal.o: server_internal.c server_internal.h service.h mimetypes.h
+	g++ ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c server_internal.c
+
+service_internal.o: service_internal.c service_internal.h service.h
+	gcc ${GDAL_CFLAGS} ${JS_ENABLED} ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} -fPIC -c service_internal.c
 
 service_yaml.o: service_yaml.c service.h
@@ -78,17 +93,25 @@
 	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
 
-zoo_loader.cgi: version.h 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 service_internal.o request_parser.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
+libzoo_service.${EXT}: version.h service_internal.o service.o 
+	gcc -shared ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o -lfcgi
+
+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 sqlapi.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}
 	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 service_internal.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${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} sqlapi.o 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  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${JS_FILE} ${RUBY_FILE}  ${YAML_FILE}
+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}
 	g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${CFLAGS} -c zcfg2yaml.c  -fno-common -DPIC -o zcfg2yaml.o
-	g++  ${JSCFLAGS} ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o service_internal.o ${MS_FILE} ${JS_FILE}  ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o  ${YAML_FILE} -o zcfg2yaml ${LDFLAGS}
+	g++  ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o  ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}
 
 install:
 	install -d ${CGI_DIR}
 	install zoo_loader.cgi ${CGI_DIR}/
-	install main.cfg	${CGI_DIR}/
+	install libzoo_service.${EXT} ${DESTDIR}${INST_LIB}/libzoo_service.${VERSION}.${REVISION}.${EXT}
+	(cd ${DESTDIR}${INST_LIB} ; \
+	 if [ -e "libzoo_service.${EXT}" ]; then rm  libzoo_service.${EXT}; fi ; \
+	 ln -s libzoo_service.${VERSION}.${REVISION}.${EXT} libzoo_service.${EXT})
+	install -d ${DESTDIR}${INST_INCLUDE}/zoo
+	install service.h service_internal.h ${DESTDIR}${INST_INCLUDE}/zoo
 
 clean:
-	rm -f version.h *.o *.zo *.eo *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling service_loader.dSYM 
+	rm -f version.h *.o *.zo *.eo *.tab.c *.tab.h *.sr.c* service_loader lex.* *.lreg *.sibling service_loader.dSYM *${EXT}
Index: trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in
===================================================================
--- trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 639)
+++ trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 640)
@@ -1,2 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+PREFIX=@prefix@
+INST_LIB=@libdir@
+INST_INCLUDE=@includedir@
+VERSION=1.5
+REVISION=0
+EXT=so
+DEFAULT_OPTS=-Wl,-soname,libzoo_service.so.${VERSION}
 OS:=$(shell uname -s)
 ifeq ($(OS),Darwin)
@@ -4,4 +13,6 @@
 	MACOS_LD_NET_FLAGS=-framework SystemConfiguration -framework CoreFoundation
 	MACOS_CFLAGS=-arch $(shell uname -m)
+	EXT=dylib
+	DEFAULT_OPTS=-Wl,-compatibility_version,${VERSION},-current_version,${VERSION},-install_name,${DESTDIR}${INST_LIB}/libzoo_service.${VERSION}.${REVISION}.dylib
 endif
 
@@ -80,4 +91,4 @@
 
 CFLAGS=@DEB_DEF@ -fpic ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
-LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
+LDFLAGS=-lzoo_service -lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
 
Index: trunk/zoo-project/zoo-kernel/configure.ac
===================================================================
--- trunk/zoo-project/zoo-kernel/configure.ac	(revision 639)
+++ trunk/zoo-project/zoo-kernel/configure.ac	(revision 640)
@@ -51,4 +51,310 @@
 AC_SUBST([CGI_DIR])
 
+
+# ===========================================================================
+# Detect if libyaml is available
+# ===========================================================================
+
+AC_ARG_WITH([yaml],
+        [AS_HELP_STRING([--with-yaml=PATH], [specify an alternative location for the yaml library])],
+        [YAMLPATH="$withval"], [YAMLPATH=""])
+
+if test -z "$YAMLPATH"
+then
+	YAML_LDFLAGS=""
+	YAML_CPPFLAGS=""
+	YAML_FILE=""
+	YAML_FILE1=""
+else
+
+	# Extract the linker and include flags
+	YAML_LDFLAGS="-L$YAMLPATH/lib -lyaml"
+	YAML_CPPFLAGS="-I$YAMLPATH/include -DYAML"
+	YAML_FILE="service_yaml.o"
+	YAML_FILE1="zcfg2yaml"
+	
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$YAML_CPPFLAGS"
+	LIBS_SAVE="$LIBS"
+	LIBS="$YAML_LDFLAGS"
+	AC_CHECK_LIB([yaml], [yaml_parser_initialize,yaml_parser_set_input_file,yaml_parser_scan])
+	AC_CHECK_HEADERS([yaml.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to YAML])])
+	LIBS="$LIBS_SAVE"
+fi
+AC_SUBST([YAML_CPPFLAGS])
+AC_SUBST([YAML_LDFLAGS])
+AC_SUBST([YAML_FILE])
+AC_SUBST([YAML_FILE1])
+
+# ===========================================================================
+# Detect if fastcgi is available
+# ===========================================================================
+
+AC_ARG_WITH([fastcgi],
+        [AS_HELP_STRING([--with-fastcgi=PATH], [specify an alternative location for the fastcgi library])],
+        [FCGIPATH="$withval"], [FCGIPATH="/usr"])
+
+# Extract the linker and include flags
+FCGI_LDFLAGS="-L$FCGIPATH/lib"
+FCGI_CPPFLAGS="-I$FCGIPATH/include"
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$FCGI_CPPFLAGS"
+LIBS_SAVE="$LIBS"
+LIBS="$FCGI_LDFLAGS"
+AC_CHECK_LIB([fcgi], [main])
+AC_CHECK_HEADERS([fcgi_stdio.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to fastcgi])])
+LIBS="$LIBS_SAVE"
+AC_SUBST([FCGI_CPPFLAGS])
+AC_SUBST([FCGI_LDFLAGS])
+
+# ===========================================================================
+# Detect if libxml2 is installed
+# ===========================================================================
+
+AC_ARG_WITH([xml2config], 
+	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])], 
+	[XML2CONFIG="$withval"], [XML2CONFIG=""])
+
+if test "x$XML2CONFIG" = "x"; then
+	# XML2CONFIG was not specified, so search within the current path
+	AC_PATH_PROG([XML2CONFIG], [xml2-config])
+
+	# If we couldn't find xml2-config, display a warning
+	if test "x$XML2CONFIG" = "x"; then
+		AC_MSG_ERROR([could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.])
+	fi
+else
+	# XML2CONFIG was specified; display a message to the user
+	if test "x$XML2CONFIG" = "xyes"; then
+		AC_MSG_ERROR([you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])
+	else
+		if test -f $XML2CONFIG; then
+			AC_MSG_RESULT([Using user-specified xml2-config file: $XML2CONFIG])
+		else
+			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
+		fi	
+	fi
+fi
+
+# Extract the linker and include flags 
+XML2_LDFLAGS=`$XML2CONFIG --libs`
+XML2_CPPFLAGS=`$XML2CONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$XML2_CPPFLAGS"
+AC_CHECK_HEADERS([libxml/tree.h libxml/parser.h libxml/xpath.h libxml/xpathInternals.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libxml2])])
+
+# Ensure we can link against libxml2
+LIBS_SAVE="$LIBS"
+LIBS="$XML2_LDFLAGS"
+AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], [])
+
+AC_SUBST([XML2_CPPFLAGS])
+AC_SUBST([XML2_LDFLAGS])
+LIBS="$LIBS_SAVE"
+
+
+# ===========================================================================
+# Detect if libxslt is installed
+# ===========================================================================
+
+AC_ARG_WITH([xsltconfig], 
+	[AS_HELP_STRING([--with-xsltconfig=FILE], [specify an alternative xslt-config file])], 
+	[XSLTCONFIG="$withval"], [XSLTCONFIG=""])
+
+if test "x$XSLTCONFIG" = "x"; then
+	# XSLTCONFIG was not specified, so search within the current path
+	AC_PATH_PROG([XSLTCONFIG], [xslt-config])
+
+	# If we couldn't find xslt-config, display a warning
+	if test "x$XSLTCONFIG" = "x"; then
+		AC_MSG_ERROR([could not find xslt-config from libxslt within the current path. You may need to try re-running configure with a --with-xtltconfig parameter.])
+	fi
+else
+	# XSLTCONFIG was specified; display a message to the user
+	if test "x$XSLTCONFIG" = "xyes"; then
+		AC_MSG_ERROR([you must specify a parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config])
+	else
+		if test -f $XSLTCONFIG; then
+			AC_MSG_RESULT([Using user-specified xslt-config file: $XSLTCONFIG])
+		else
+			AC_MSG_ERROR([the user-specified xslt-config file $XSLTCONFIG does not exist])
+		fi	
+	fi
+fi
+
+# Extract the linker and include flags 
+XSLT_LDFLAGS=`$XSLTCONFIG --libs`
+XSLT_CPPFLAGS=`$XSLTCONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$XSLT_CPPFLAGS"
+AC_CHECK_HEADERS([libxslt/xslt.h libxslt/xsltInternals.h libxslt/transform.h libxslt/xsltutils.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libxlst])])
+
+AC_SUBST([XSLT_CPPFLAGS])
+AC_SUBST([XSLT_LDFLAGS])
+
+#============================================================================
+# Detect if gdal is installed
+#============================================================================
+
+AC_ARG_WITH([gdal-config], 
+	[AS_HELP_STRING([--with-gdal-config=FILE], [specify an alternative gdal-config file])], 
+	[GDAL_CONFIG="$withval"], [GDAL_CONFIG=""])
+if test -z $GDAL_CONFIG;
+then
+	AC_PATH_PROG([GDAL_CONFIG], [gdal-config])
+	if test -z $GDAL_CONFIG; 
+	then
+		AC_MSG_ERROR([could not find gdal-config from libgdal within the current path. You may need to try re-running configure with a --with-gdal-config parameter.])
+	fi
+	
+else
+	if test -f $GDAL_CONFIG; then
+		AC_MSG_RESULT([Using user-specified gdal-config file: $GDAL_CONFIG])
+	else
+		AC_MSG_ERROR([the user-specified gdal-config file $GDAL_CONFIG does not exist])
+	fi
+fi
+
+GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
+GDAL_LIBS="`$GDAL_CONFIG --libs`"
+
+AC_SUBST([GDAL_CFLAGS])
+AC_SUBST([GDAL_LIBS])
+
+# ===========================================================================
+# Detect if proj is installed
+# ===========================================================================
+
+AC_ARG_WITH([proj],
+        [AS_HELP_STRING([--with-proj=PATH], [specify an alternative location for PROJ4 setup])],
+        [PROJPATH="$withval"], [PROJPATH=""])
+
+# Extract the linker and include flags
+PROJ_LDFLAGS="-L$PROJPATH/lib"
+PROJ_CPPFLAGS="-I$PROJPATH/include"
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$PROJ_CPPFLAGS"
+AC_CHECK_HEADERS([proj_api.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to PROJ4])])
+
+AC_SUBST([PROJ_CPPFLAGS])
+AC_SUBST([PROJ_LDFLAGS])
+
+# ===========================================================================
+# Detect if libgeos is installed
+# ===========================================================================
+
+AC_ARG_WITH([geosconfig], 
+	[AS_HELP_STRING([--with-geosconfig=FILE], [specify an alternative geos-config file])], 
+	[GEOSCONFIG="$withval"], [GEOSCONFIG=""])
+
+if test "x$GEOSCONFIG" = "x"; then
+	# GEOSCONFIG was not specified, so search within the current path
+	AC_PATH_PROG([GEOSCONFIG], [geos-config])
+
+	# If we couldn't find geos-config, display a warning
+	if test "x$GEOSCONFIG" = "x"; then
+		AC_MSG_WARN([could not find geos-config from libgeos within the current path. You may need to try re-running configure with a --with-geosconfig parameter.])
+	fi
+else
+	# GEOSCONFIG was specified; display a message to the user
+	if test "x$GEOSCONFIG" = "xyes"; then
+		AC_MSG_WARN([you must specify a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])
+	else
+		if test -f $GEOSCONFIG; then
+			AC_MSG_RESULT([Using user-specified geos-config file: $GEOSCONFIG])
+		else
+			AC_MSG_ERROR([the user-specified geos-config file $GEOSCONFIG does not exist])
+		fi	
+	fi
+fi
+
+GEOS_LDFLAGS=`$GEOSCONFIG --libs`
+GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$GEOS_CPPFLAGS"
+AC_CHECK_HEADERS([geos_c.h],
+		 [], [AC_MSG_WARN([could not find headers include related to libgeos])])
+
+AC_SUBST([GEOS_CPPFLAGS])
+AC_SUBST([GEOS_LDFLAGS])
+
+
+# ===========================================================================
+# Detect if cgal is installed
+# ===========================================================================
+
+AC_ARG_WITH([cgal],
+        [AS_HELP_STRING([--with-cgal=PATH], [specify an alternative location for CGAL setup])],
+        [CGALPATH="$withval"], [CGALPATH="/usr"])
+
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$CGAL_CPPFLAGS"
+AC_CHECK_HEADERS([CGAL/Delaunay_triangulation_2.h],
+         [], [AC_MSG_WARN([could not find headers include related to libCGAL])])
+
+# Extract the linker and include flags
+CGAL_LDFLAGS="-L$CGALPATH/lib"
+CGAL_CPPFLAGS="-I$CGALPATH/include"
+
+
+AC_SUBST([CGAL_CPPFLAGS])
+AC_SUBST([CGAL_LDFLAGS])
+#============================================================================
+# Detect if mapserver is installed
+#============================================================================
+
+AC_ARG_WITH([mapserver], 
+       [AS_HELP_STRING([--with-mapserver=PATH], [specify the path for MapServer compiled source tree])], 
+       [MS_SRC_PATH="$withval"], [MS_SRC_PATH=""])
+
+if test -z $MS_SRC_PATH;
+then
+	MS_CPPFLAGS=""
+	MS_LDFLAGS=""
+else
+       if test "x$MS_SRC_PATH" = "xmacos";
+       then
+               MS_LDFLAGS="/Library/Frameworks/MapServer.framework//Versions/6.0/MapServer -lintl"
+               MS_CPPFLAGS="-DUSE_MS `/Library/Frameworks/MapServer.framework/Programs/mapserver-config --includes` -I/Library/Frameworks/MapServer.framework/Versions/Current/Headers/ -I../mapserver "
+               AC_MSG_WARN([Please make sure that ../mapserver exists and contains MapServer source tree])
+               AC_MSG_RESULT([Using MacOS X Framework for MapServer])
+       else
+               if test -d $MS_SRC_PATH; then
+                       MS_LDFLAGS="-L$MS_SRC_PATH -lmapserver `$MS_SRC_PATH/mapserver-config --libs`"
+                       MS_CPPFLAGS="-DUSE_MS `$MS_SRC_PATH/mapserver-config --includes` `$MS_SRC_PATH/mapserver-config --cflags` -I$MS_SRC_PATH "
+               
+                       AC_MSG_RESULT([Using user-specified MapServer src path: $MS_SRC_PATH])
+               else
+                       AC_MSG_ERROR([the user-specified mapserver-config file $MS_SRC_PATH does not exist])
+               fi
+       fi
+       MS_FILE="service_internal_ms.o"
+fi
+
+MS_CFLAGS="$MS_CPPFLAGS"
+MS_LIBS="$MS_LDFLAGS"
+
+AC_SUBST([MS_CFLAGS])
+AC_SUBST([MS_LIBS])
+AC_SUBST([MS_FILE])
+
 # ===========================================================================
 # Detect if python is installed
@@ -100,4 +406,5 @@
 	AC_SUBST([PYTHON_CPPFLAGS])
 	AC_SUBST([PYTHON_LDFLAGS])
+	LIBS="$LIBS_SAVE"
 fi
 
@@ -151,14 +458,15 @@
 	CPPFLAGS_SAVE="$CPPFLAGS"
         CPPFLAGS="$JS_CPPFLAGS"
-
-	#AC_CHECK_HEADERS([jsapi.h],
-        #                [], [AC_MSG_ERROR([could not find headers include related to libjs])])
-
-	
+	AC_LANG_PUSH([C++])
+	AC_CHECK_HEADERS([jsapi.h],
+                        [], [AC_MSG_ERROR([could not find headers include related to libjs])])
+
+	AC_LANG_POP([C++])
 	LIBS_SAVE="$LIBS"
         LIBS="$JS_LDFLAGS"
 
         AC_CHECK_LIB([$JS_LIB], [JS_CompileFile,JS_CallFunctionName], [], [AC_MSG_ERROR([could not find $JS_LIB])], [])
-			
+	LIBS="$LIBS_SAVE"
+	
         AC_SUBST([JS_CPPFLAGS])
         AC_SUBST([JS_LDFLAGS])
@@ -206,4 +514,5 @@
 	# Shouldn't we get php here rather than php5 :) ??
 	AC_CHECK_LIB([php5], [call_user_function], [], [AC_MSG_ERROR([could not find libphp])], [])
+	LIBS="$LIBS_SAVE"
 	AC_SUBST([PHP_CPPFLAGS])
 	AC_SUBST([PHP_LDFLAGS])
@@ -264,4 +573,5 @@
 		AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [], [AC_MSG_ERROR([could not find libjvm])], [])
 	fi
+	LIBS="$LIBS_SAVE"
 
 	AC_SUBST([JAVA_CPPFLAGS])
@@ -304,4 +614,5 @@
 	LIBS="$RUBY_LDFLAGS"
 	# AC_CHECK_LIB([lruby], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
+	LIBS="$LIBS_SAVE"
 	AC_SUBST([RUBY_CPPFLAGS])
 	AC_SUBST([RUBY_LDFLAGS])
@@ -387,8 +698,15 @@
 	CPPFLAGS="$OTB_CPPFLAGS"
 	LDFLAGS_SAVE="$LDFLAGS"
-	LDFLAGS="$OTB_LDFLAGS"
+	LIBS="$LIBS_SAVE $OTB_LDFLAGS"
 	AC_CHECK_HEADERS([otbWrapperApplication.h otbWrapperInputImageListParameter.h otbWrapperApplicationRegistry.h],
 			[], [AC_MSG_ERROR([could not find header file $i related to OTB])])
 	AC_LANG_POP([C++])
+	AC_LANG(C++)
+	LDFLAGS_SAVE="$LDFLAGS"
+	LDFLAGS="$OTB_LDFLAGS"
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "otbWrapperApplication.h"],[std::vector<std::string> list = otb::Wrapwper::ApplicationRegistry::GetAvailableApplication();]])],
+		[AC_MSG_RESULT([checking for GetAvailableApplication... yes])],[AC_MSG_ERROR([checking for GetAvailableApplication... failed])])
+	LDFLAGS="$LDFLAGS_SAVE"
+			
 fi
 AC_SUBST([OTB_CPPFLAGS])
@@ -435,9 +753,9 @@
 	LIBS_SAVE="$LIBS"
 	LIBS="$SAGA_LDFLAGS"
-	AC_MSG_RESULT(CPPFLAGS are $CPPFLAGS)
 	AC_CHECK_HEADERS([module_library.h],
 			[], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])])
-	LIBS_SAVE="$LIBS"
-	AC_CHECK_LIB([saga_api], [SG_Set_UI_Callback,SG_Get_Module_Library_Manager])
+	AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "module_library.h"],[SG_Get_Module_Library_Manager();]])],
+		[AC_MSG_RESULT([checking for SG_Get_Module_Library_Manager... yes])],[AC_MSG_ERROR([checking for SG_Get_Module_Library_Manager... failed])])
+	LIBS="$LIBS_SAVE"
 	AC_LANG_POP([C++])
 fi
@@ -447,308 +765,4 @@
 AC_SUBST([SAGA_ENABLED])
 
-# ===========================================================================
-# Detect if libyaml is available
-# ===========================================================================
-
-AC_ARG_WITH([yaml],
-        [AS_HELP_STRING([--with-yaml=PATH], [specify an alternative location for the yaml library])],
-        [YAMLPATH="$withval"], [YAMLPATH=""])
-
-if test -z "$YAMLPATH"
-then
-	YAML_LDFLAGS=""
-	YAML_CPPFLAGS=""
-	YAML_FILE=""
-	YAML_FILE1=""
-else
-
-	# Extract the linker and include flags
-	YAML_LDFLAGS="-L$YAMLPATH/lib -lyaml"
-	YAML_CPPFLAGS="-I$YAMLPATH/include -DYAML"
-	YAML_FILE="service_yaml.o"
-	YAML_FILE1="zcfg2yaml"
-	
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$YAML_CPPFLAGS"
-	LIBS_SAVE="$LIBS"
-	LIBS="$YAML_LDFLAGS"
-	AC_CHECK_LIB([yaml], [yaml_parser_initialize,yaml_parser_set_input_file,yaml_parser_scan])
-	AC_CHECK_HEADERS([yaml.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to YAML])])
-	LIBS="$LIBS_SAVE"
-fi
-AC_SUBST([YAML_CPPFLAGS])
-AC_SUBST([YAML_LDFLAGS])
-AC_SUBST([YAML_FILE])
-AC_SUBST([YAML_FILE1])
-
-# ===========================================================================
-# Detect if fastcgi is available
-# ===========================================================================
-
-AC_ARG_WITH([fastcgi],
-        [AS_HELP_STRING([--with-fastcgi=PATH], [specify an alternative location for the fastcgi library])],
-        [FCGIPATH="$withval"], [FCGIPATH="/usr"])
-
-# Extract the linker and include flags
-FCGI_LDFLAGS="-L$FCGIPATH/lib"
-FCGI_CPPFLAGS="-I$FCGIPATH/include"
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$FCGI_CPPFLAGS"
-LIBS_SAVE="$LIBS"
-LIBS="$FCGI_LDFLAGS"
-AC_CHECK_LIB([fcgi], [main])
-AC_CHECK_HEADERS([fcgi_stdio.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to fastcgi])])
-LIBS="$LIBS_SAVE"
-AC_SUBST([FCGI_CPPFLAGS])
-AC_SUBST([FCGI_LDFLAGS])
-
-
-# ===========================================================================
-# Detect if libxml2 is installed
-# ===========================================================================
-
-AC_ARG_WITH([xml2config], 
-	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])], 
-	[XML2CONFIG="$withval"], [XML2CONFIG=""])
-
-if test "x$XML2CONFIG" = "x"; then
-	# XML2CONFIG was not specified, so search within the current path
-	AC_PATH_PROG([XML2CONFIG], [xml2-config])
-
-	# If we couldn't find xml2-config, display a warning
-	if test "x$XML2CONFIG" = "x"; then
-		AC_MSG_ERROR([could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.])
-	fi
-else
-	# XML2CONFIG was specified; display a message to the user
-	if test "x$XML2CONFIG" = "xyes"; then
-		AC_MSG_ERROR([you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])
-	else
-		if test -f $XML2CONFIG; then
-			AC_MSG_RESULT([Using user-specified xml2-config file: $XML2CONFIG])
-		else
-			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
-		fi	
-	fi
-fi
-
-# Extract the linker and include flags 
-XML2_LDFLAGS=`$XML2CONFIG --libs`
-XML2_CPPFLAGS=`$XML2CONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$XML2_CPPFLAGS"
-AC_CHECK_HEADERS([libxml/tree.h libxml/parser.h libxml/xpath.h libxml/xpathInternals.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libxml2])])
-
-# Ensure we can link against libxml2
-LIBS_SAVE="$LIBS"
-LIBS="$XML2_LDFLAGS"
-AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], [])
-
-AC_SUBST([XML2_CPPFLAGS])
-AC_SUBST([XML2_LDFLAGS])
-
-# ===========================================================================
-# Detect if libxslt is installed
-# ===========================================================================
-
-AC_ARG_WITH([xsltconfig], 
-	[AS_HELP_STRING([--with-xsltconfig=FILE], [specify an alternative xslt-config file])], 
-	[XSLTCONFIG="$withval"], [XSLTCONFIG=""])
-
-if test "x$XSLTCONFIG" = "x"; then
-	# XSLTCONFIG was not specified, so search within the current path
-	AC_PATH_PROG([XSLTCONFIG], [xslt-config])
-
-	# If we couldn't find xslt-config, display a warning
-	if test "x$XSLTCONFIG" = "x"; then
-		AC_MSG_ERROR([could not find xslt-config from libxslt within the current path. You may need to try re-running configure with a --with-xtltconfig parameter.])
-	fi
-else
-	# XSLTCONFIG was specified; display a message to the user
-	if test "x$XSLTCONFIG" = "xyes"; then
-		AC_MSG_ERROR([you must specify a parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config])
-	else
-		if test -f $XSLTCONFIG; then
-			AC_MSG_RESULT([Using user-specified xslt-config file: $XSLTCONFIG])
-		else
-			AC_MSG_ERROR([the user-specified xslt-config file $XSLTCONFIG does not exist])
-		fi	
-	fi
-fi
-
-# Extract the linker and include flags 
-XSLT_LDFLAGS=`$XSLTCONFIG --libs`
-XSLT_CPPFLAGS=`$XSLTCONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$XSLT_CPPFLAGS"
-AC_CHECK_HEADERS([libxslt/xslt.h libxslt/xsltInternals.h libxslt/transform.h libxslt/xsltutils.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libxlst])])
-
-AC_SUBST([XSLT_CPPFLAGS])
-AC_SUBST([XSLT_LDFLAGS])
-
-#============================================================================
-# Detect if gdal is installed
-#============================================================================
-
-AC_ARG_WITH([gdal-config], 
-	[AS_HELP_STRING([--with-gdal-config=FILE], [specify an alternative gdal-config file])], 
-	[GDAL_CONFIG="$withval"], [GDAL_CONFIG=""])
-if test -z $GDAL_CONFIG;
-then
-	AC_PATH_PROG([GDAL_CONFIG], [gdal-config])
-	if test -z $GDAL_CONFIG; 
-	then
-		AC_MSG_ERROR([could not find gdal-config from libgdal within the current path. You may need to try re-running configure with a --with-gdal-config parameter.])
-	fi
-	
-else
-	if test -f $GDAL_CONFIG; then
-		AC_MSG_RESULT([Using user-specified gdal-config file: $GDAL_CONFIG])
-	else
-		AC_MSG_ERROR([the user-specified gdal-config file $GDAL_CONFIG does not exist])
-	fi
-fi
-
-GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
-GDAL_LIBS="`$GDAL_CONFIG --libs`"
-
-AC_SUBST([GDAL_CFLAGS])
-AC_SUBST([GDAL_LIBS])
-
-# ===========================================================================
-# Detect if proj is installed
-# ===========================================================================
-
-AC_ARG_WITH([proj],
-        [AS_HELP_STRING([--with-proj=PATH], [specify an alternative location for PROJ4 setup])],
-        [PROJPATH="$withval"], [PROJPATH=""])
-
-# Extract the linker and include flags
-PROJ_LDFLAGS="-L$PROJPATH/lib"
-PROJ_CPPFLAGS="-I$PROJPATH/include"
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$PROJ_CPPFLAGS"
-AC_CHECK_HEADERS([proj_api.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to PROJ4])])
-
-AC_SUBST([PROJ_CPPFLAGS])
-AC_SUBST([PROJ_LDFLAGS])
-
-# ===========================================================================
-# Detect if libgeos is installed
-# ===========================================================================
-
-AC_ARG_WITH([geosconfig], 
-	[AS_HELP_STRING([--with-geosconfig=FILE], [specify an alternative geos-config file])], 
-	[GEOSCONFIG="$withval"], [GEOSCONFIG=""])
-
-if test "x$GEOSCONFIG" = "x"; then
-	# GEOSCONFIG was not specified, so search within the current path
-	AC_PATH_PROG([GEOSCONFIG], [geos-config])
-
-	# If we couldn't find geos-config, display a warning
-	if test "x$GEOSCONFIG" = "x"; then
-		AC_MSG_WARN([could not find geos-config from libgeos within the current path. You may need to try re-running configure with a --with-geosconfig parameter.])
-	fi
-else
-	# GEOSCONFIG was specified; display a message to the user
-	if test "x$GEOSCONFIG" = "xyes"; then
-		AC_MSG_WARN([you must specify a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])
-	else
-		if test -f $GEOSCONFIG; then
-			AC_MSG_RESULT([Using user-specified geos-config file: $GEOSCONFIG])
-		else
-			AC_MSG_ERROR([the user-specified geos-config file $GEOSCONFIG does not exist])
-		fi	
-	fi
-fi
-
-GEOS_LDFLAGS=`$GEOSCONFIG --libs`
-GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$GEOS_CPPFLAGS"
-AC_CHECK_HEADERS([geos_c.h],
-		 [], [AC_MSG_WARN([could not find headers include related to libgeos])])
-
-AC_SUBST([GEOS_CPPFLAGS])
-AC_SUBST([GEOS_LDFLAGS])
-
-
-# ===========================================================================
-# Detect if cgal is installed
-# ===========================================================================
-
-AC_ARG_WITH([cgal],
-        [AS_HELP_STRING([--with-cgal=PATH], [specify an alternative location for CGAL setup])],
-        [CGALPATH="$withval"], [CGALPATH="/usr"])
-
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$CGAL_CPPFLAGS"
-AC_CHECK_HEADERS([CGAL/Delaunay_triangulation_2.h],
-         [], [AC_MSG_WARN([could not find headers include related to libCGAL])])
-
-# Extract the linker and include flags
-CGAL_LDFLAGS="-L$CGALPATH/lib"
-CGAL_CPPFLAGS="-I$CGALPATH/include"
-
-
-AC_SUBST([CGAL_CPPFLAGS])
-AC_SUBST([CGAL_LDFLAGS])
-#============================================================================
-# Detect if mapserver is installed
-#============================================================================
-
-AC_ARG_WITH([mapserver], 
-       [AS_HELP_STRING([--with-mapserver=PATH], [specify the path for MapServer compiled source tree])], 
-       [MS_SRC_PATH="$withval"], [MS_SRC_PATH=""])
-
-if test -z $MS_SRC_PATH;
-then
-	MS_CPPFLAGS=""
-	MS_LDFLAGS=""
-else
-       if test "x$MS_SRC_PATH" = "xmacos";
-       then
-               MS_LDFLAGS="/Library/Frameworks/MapServer.framework//Versions/6.0/MapServer -lintl"
-               MS_CPPFLAGS="-DUSE_MS `/Library/Frameworks/MapServer.framework/Programs/mapserver-config --includes` -I/Library/Frameworks/MapServer.framework/Versions/Current/Headers/ -I../mapserver "
-               AC_MSG_WARN([Please make sure that ../mapserver exists and contains MapServer source tree])
-               AC_MSG_RESULT([Using MacOS X Framework for MapServer])
-       else
-               if test -d $MS_SRC_PATH; then
-                       MS_LDFLAGS="-L$MS_SRC_PATH -lmapserver `$MS_SRC_PATH/mapserver-config --libs`"
-                       MS_CPPFLAGS="-DUSE_MS `$MS_SRC_PATH/mapserver-config --includes` `$MS_SRC_PATH/mapserver-config --cflags` -I$MS_SRC_PATH "
-               
-                       AC_MSG_RESULT([Using user-specified MapServer src path: $MS_SRC_PATH])
-               else
-                       AC_MSG_ERROR([the user-specified mapserver-config file $MS_SRC_PATH does not exist])
-               fi
-       fi
-       MS_FILE="service_internal_ms.o"
-fi
-
-MS_CFLAGS="$MS_CPPFLAGS"
-MS_LIBS="$MS_LDFLAGS"
-
-AC_SUBST([MS_CFLAGS])
-AC_SUBST([MS_LIBS])
-AC_SUBST([MS_FILE])
-
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([ZOOMakefile.opts])
Index: trunk/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- trunk/zoo-project/zoo-kernel/request_parser.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/request_parser.c	(revision 640)
@@ -25,4 +25,7 @@
 #include "request_parser.h"
 #include "service_internal.h"
+#include "server_internal.h"
+#include "response_print.h"
+#include "caching.h"
 
 /**
@@ -127,4 +130,54 @@
     }
   return 0;
+}
+
+/**
+ * Make sure that each value encoded in base64 in a maps is decoded.
+ *
+ * @param in the maps containing the values
+ * @see readBase64
+ */
+void ensureDecodedBase64(maps **in){
+  maps* cursor=*in;
+  while(cursor!=NULL){
+    map *tmp=getMap(cursor->content,"encoding");
+    if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
+      tmp=getMap(cursor->content,"value");
+      readBase64(&tmp);
+      addToMap(cursor->content,"base64_value",tmp->value);
+      int size=0;
+      char *s=strdup(tmp->value);
+      free(tmp->value);
+      tmp->value=base64d(s,strlen(s),&size);
+      free(s);
+      char sizes[1024];
+      sprintf(sizes,"%d",size);
+      addToMap(cursor->content,"size",sizes);
+    }
+    map* length=getMap(cursor->content,"length");
+    if(length!=NULL){
+      int len=atoi(length->value);
+      for(int i=1;i<len;i++){
+	tmp=getMapArray(cursor->content,"encoding",i);
+	if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
+	  char key[17];
+	  sprintf(key,"base64_value_%d",i);
+	  tmp=getMapArray(cursor->content,"value",i);
+	  readBase64(&tmp);
+	  addToMap(cursor->content,key,tmp->value);
+	  int size=0;
+	  char *s=strdup(tmp->value);
+	  free(tmp->value);
+	  tmp->value=base64d(s,strlen(s),&size);
+	  free(s);
+	  char sizes[1024];
+	  sprintf(sizes,"%d",size);
+	  sprintf(key,"size_%d",i);
+	  addToMap(cursor->content,key,sizes);
+	}
+      }
+    }
+    cursor=cursor->next;
+  }
 }
 
@@ -1448,2 +1501,118 @@
   return 1;
 }
+
+
+/**
+ * Verify if a parameter value is valid.
+ * 
+ * @param request the request map
+ * @param res the error map potentially generated
+ * @param toCheck the parameter to use
+ * @param avalues the acceptable values (or null if testing only for presence)
+ * @param mandatory verify the presence of the parameter if mandatory > 0 
+ */
+void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){
+  map* lres=*res;
+  map* r_inputs = getMap (request,toCheck);
+  if (r_inputs == NULL){
+    if(mandatory>0){
+      char *replace=_("Mandatory parameter <%s> was not specified");
+      char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char));
+      sprintf(message,replace,toCheck);
+      if(lres==NULL){
+	lres=createMap("code","MissingParameterValue");
+	addToMap(lres,"text",message);
+	addToMap(lres,"locator",toCheck);       
+      }else{
+	int length=1;
+	map* len=getMap(lres,"length");
+	if(len!=NULL){
+	  length=atoi(len->value);
+	}
+	setMapArray(lres,"text",length,message);
+	setMapArray(lres,"locator",length,toCheck);
+	setMapArray(lres,"code",length,"MissingParameter");
+      }
+      free(message);
+    }
+  }else{
+    if(avalues==NULL)
+      return;
+    int nb=0;
+    int hasValidValue=-1;
+    if(strncasecmp(toCheck,"Accept",6)==0){
+      char *tmp=zStrdup(r_inputs->value);
+      char *pToken,*saveptr;
+      pToken=strtok_r(tmp,",",&saveptr);
+      while(pToken!=NULL){
+	while(avalues[nb]!=NULL){
+	  if(strcasecmp(avalues[nb],pToken)==0){
+	    hasValidValue=1;
+	    break;
+	  }
+	  nb++;
+	}
+	pToken=strtok_r(NULL,",",&saveptr);
+      }
+      free(tmp);
+    }else{
+      while(avalues[nb]!=NULL){
+	if(strcasecmp(avalues[nb],r_inputs->value)==0){
+	  hasValidValue=1;
+	  break;
+	}
+	nb++;
+      }
+    }
+    if(hasValidValue<0){
+      char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value.");
+      nb=0;
+      char *vvalues=NULL;
+      char* num=_("is");
+      while(avalues[nb]!=NULL){
+	char *tvalues;
+	if(vvalues==NULL){
+	  vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char));
+	  sprintf(vvalues,"%s",avalues[nb]);
+	}
+	else{
+	  tvalues=zStrdup(vvalues);
+	  vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char));
+	  sprintf(vvalues,"%s, %s",tvalues,avalues[nb]);
+	  free(tvalues);
+	  num=_("are");
+	}
+	nb++;
+      }
+      char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char));
+      sprintf(message,replace,toCheck,vvalues,num);
+      const char *code="VersionNegotiationFailed";
+      code="InvalidParameterValue";
+      const char *locator=toCheck;
+      if( strncasecmp(toCheck,"version",7)==0 ||
+	  strncasecmp(toCheck,"AcceptVersions",14)==0 )
+	code="VersionNegotiationFailed";
+      if( strncasecmp(toCheck,"request",7)==0){
+	code="OperationNotSupported";
+	locator=r_inputs->value;
+      }
+      if(lres==NULL){
+	lres=createMap("code","InvalidParameterValue");
+	addToMap(lres,"text",message);
+	addToMap(lres,"locator",locator);       
+      }else{
+	int length=1;
+	map* len=getMap(lres,"length");
+	if(len!=NULL){
+	  length=atoi(len->value);
+	}
+	setMapArray(lres,"text",length,message);
+	setMapArray(lres,"locator",length,locator);
+	setMapArray(lres,"code",length,"InvalidParameterValue");
+      }
+    }
+  }
+  if(lres!=NULL){
+    *res=lres;
+  }
+}
Index: trunk/zoo-project/zoo-kernel/request_parser.h
===================================================================
--- trunk/zoo-project/zoo-kernel/request_parser.h	(revision 639)
+++ trunk/zoo-project/zoo-kernel/request_parser.h	(revision 640)
@@ -23,6 +23,6 @@
  */
 
-#ifndef SERVICE_PARSER_H
-#define SERVICE_PARSER_H 1
+#ifndef ZOO_REQUEST_PARSER_H
+#define ZOO_REQUEST_PARSER_H 1
 
 #pragma once 
@@ -39,4 +39,5 @@
   xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
   int appendMapsToMaps (maps*, maps*, maps*, elements*);
+  void ensureDecodedBase64(maps**);
   int kvpParseInputs(maps**,service*,map*,maps**,HINTERNET*);
   int kvpParseOutputs(maps**,map *,maps**);
@@ -45,4 +46,5 @@
   int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*);
   int parseRequest(maps**,map**,service*,maps**,maps**,HINTERNET*);
+  void checkValidValue(map*,map**,const char*,const char**,int);
   int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*);
 
Index: trunk/zoo-project/zoo-kernel/service.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service.h	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service.h	(revision 640)
@@ -144,5 +144,5 @@
  * The memory size to create an elements
  */
-#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
+#define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+(2*sizeof(elements*)))
 /**
  * The memory size to create a map
@@ -206,248 +206,5 @@
     struct maps* next; //!< the pointer to the next maps if any or NULL
   } maps;
-
-  /**
-   * Dump a map on stderr
-   *
-   * @param t the map to dump
-   */
-  static void _dumpMap(map* t){
-    if(t!=NULL){
-      fprintf(stderr,"%s: %s\n",t->name,t->value);
-      fflush(stderr);
-	}else{
-      fprintf(stderr,"NULL\n");
-      fflush(stderr);
-    }
-  }
-
-  /**
-   * Dump a map on stderr, see _dumpMap()
-   *
-   * @param t the map to dump
-   */
-  static void dumpMap(map* t){
-    map* tmp=t;
-    while(tmp!=NULL){
-      _dumpMap(tmp);
-      tmp=tmp->next;
-    }
-  }
-
-  /**
-   * Dump a map to a file
-   *
-   * @param t the map to dump to file
-   * @param file the file to store the map
-   */
-  static void dumpMapToFile(map* t,FILE* file){
-    map* tmp=t;
-    while(tmp!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"%s = %s\n",tmp->name,tmp->value);
-#endif
-      fprintf(file,"%s = %s\n",tmp->name,tmp->value);
-      tmp=tmp->next;
-    }
-  }
   
-  /**
-   * Dump a maps on stderr, see dumpMap().
-   *
-   * @param m the map to dump
-   */
-  static void dumpMaps(maps* m){
-    maps* tmp=m;
-    while(tmp!=NULL){
-      fprintf(stderr,"MAP => [%s] \n",tmp->name);
-      dumpMap(tmp->content);
-      tmp=tmp->next;
-    }
-  }
-
-  /**
-   * Dump a maps to a file, see dumpMapToFile().
-   *
-   * @param m the map to dump
-   * @param file_path the full path to the file name to store the map
-   */
-  static void dumpMapsToFile(maps* m,char* file_path){
-    FILE* file=fopen(file_path,"w");
-    maps* tmp=m;
-    if(tmp!=NULL){
-      fprintf(file,"[%s]\n",tmp->name);
-      dumpMapToFile(tmp->content,file);
-      fflush(file);
-    }
-    fclose(file);
-  }
-  
-  /**
-   * Create a new map
-   *
-   * @param name the key to add to the map
-   * @param value the corresponding value to add to the map
-   * @return the allocated map
-   */
-  static map* createMap(const char* name,const char* value){
-    map* tmp=(map *)malloc(MAP_SIZE);
-    tmp->name=zStrdup(name);
-    tmp->value=zStrdup(value);
-    tmp->next=NULL;
-    return tmp;
-  }
-
-  /**
-   * Count number of map in a map
-   *
-   * @param m the maps to count
-   * @return number of map in a map
-   */
-  static int count(map* m){
-    map* tmp=m;
-    int c=0;
-    while(tmp!=NULL){
-      c++;
-      tmp=tmp->next;
-    }
-    return c;
-  }
-    
-  /**
-   * Verify if a key exist in a map
-   *
-   * @param m the map to search for the key
-   * @param key the key to search in the map
-   * @return true if the key wwas found, false in other case
-   */
-  static bool hasKey(map* m,const char *key){
-    map* tmp=m;
-    while(tmp!=NULL){
-      if(strcasecmp(tmp->name,key)==0)
-	return true;
-      tmp=tmp->next;
-    }
-#ifdef DEBUG_MAP
-    fprintf(stderr,"NOT FOUND \n");
-#endif
-    return false;
-  }
-
-  /**
-   * Access a specific maps
-   *
-   * @param m the maps to search for the key
-   * @param key the key to search in the maps
-   * @return a pointer on the maps found or NULL if not found
-   */
-  static maps* getMaps(maps* m,const char *key){
-    maps* tmp=m;
-    while(tmp!=NULL){
-      if(strcasecmp(tmp->name,key)==0){
-	return tmp;
-      }
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-  /**
-   * Access a specific map
-   *
-   * @param m the map to search for the key
-   * @param key the key to search in the map
-   * @return a pointer on the map found or NULL if not found
-   */
-  static map* getMap(map* m,const char *key){
-    map* tmp=m;
-    while(tmp!=NULL){
-      if(strcasecmp(tmp->name,key)==0){
-	return tmp;
-      }
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-
-  /**
-   * Access the last map
-   *
-   * @param m the map to search for the lastest map
-   * @return a pointer on the lastest map found or NULL if not found
-   */
-  static map* getLastMap(map* m){
-    map* tmp=m;
-    while(tmp!=NULL){
-      if(tmp->next==NULL){
-	return tmp;
-      }
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-  /**
-   * Access a specific map from a maps
-   *
-   * @param m the maps to search for the key
-   * @param key the key to search in the maps
-   * @param subkey the key to search in the map (found for the key, if any)
-   * @return a pointer on the map found or NULL if not found
-   */
-  static map* getMapFromMaps(maps* m,const char* key,const char* subkey){
-    maps* _tmpm=getMaps(m,key);
-    if(_tmpm!=NULL){
-      map* _ztmpm=getMap(_tmpm->content,subkey);
-      return _ztmpm;
-    }
-    else return NULL;
-  }
-
-  /**
-   * Free allocated memory of a map.
-   * Require to call free on mo after calling this function.
-   *
-   * @param mo the map to free
-   */
-  static void freeMap(map** mo){
-    map* _cursor=*mo;
-    if(_cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"freeMap\n");
-#endif
-      free(_cursor->name);
-      free(_cursor->value);
-      if(_cursor->next!=NULL){
-	freeMap(&_cursor->next);
-	free(_cursor->next);
-      }
-    }
-  }
-
-  /**
-   * Free allocated memory of a maps.
-   * Require to call free on mo after calling this function.
-   *
-   * @param mo the maps to free
-   */
-  static void freeMaps(maps** mo){
-    maps* _cursor=*mo;
-    if(_cursor && _cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"freeMaps\n");
-#endif
-      free(_cursor->name);
-      if(_cursor->content!=NULL){
-      	freeMap(&_cursor->content);
-      	free(_cursor->content);
-      }
-      if(_cursor->next!=NULL){
-	freeMaps(&_cursor->next);
-	free(_cursor->next);
-      }
-    }
-  }
-
   /**
    * Not named linked list
@@ -472,4 +229,5 @@
     struct iotype* defaults; //!< the default iotype 
     struct iotype* supported; //!< the supported iotype 
+    struct elements* child; //!< the pointer to the children element if any (or NULL)
     struct elements* next; //!< the pointer to the next element if any (or NULL)
   } elements;
@@ -503,1243 +261,63 @@
   } registry;
 
-  /**
-   * Verify if an elements contains a name equal to the given key.
-   *
-   * @param e the elements to search for the key
-   * @param key the elements name to search
-   * @return true if the elements contains the name, false in other cases.
-   */ 
-  static bool hasElement(elements* e,const char* key){
-    elements* tmp=e;
-    while(tmp!=NULL){
-      if(strcasecmp(key,tmp->name)==0)
-	return true;
-      tmp=tmp->next;
-    }
-    return false;
-  }
-
-  /**
-   * Access a specific elements named key.
-   *
-   * @param m the elements to search
-   * @param key the elements name to search
-   * @return a pointer to the specific element if found, NULL in other case.
-   */ 
-  static elements* getElements(elements* m,char *key){
-    elements* tmp=m;
-    while(tmp!=NULL){
-      if(strcasecmp(tmp->name,key)==0)
-	return tmp;
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-  /**
-   * Free allocated memory of an iotype.
-   * Require to call free on i after calling this function.
-   *
-   * @param i the iotype to free
-   */
-  static void freeIOType(iotype** i){
-    iotype* _cursor=*i;
-    if(_cursor!=NULL){
-      if(_cursor->next!=NULL){
-	freeIOType(&_cursor->next);
-	free(_cursor->next);
-      }
-      freeMap(&_cursor->content);
-      free(_cursor->content);
-    }
-  }
-
-  /**
-   * Free allocated memory of an elements.
-   * Require to call free on e after calling this function.
-   *
-   * @param e the iotype to free
-   */
-  static void freeElements(elements** e){
-    elements* tmp=*e;
-    if(tmp!=NULL){
-      if(tmp->name!=NULL)
-	free(tmp->name);
-      freeMap(&tmp->content);
-      if(tmp->content!=NULL)
-	free(tmp->content);
-      freeMap(&tmp->metadata);
-      if(tmp->metadata!=NULL)
-	free(tmp->metadata);
-      if(tmp->format!=NULL)
-	free(tmp->format);
-      freeIOType(&tmp->defaults);
-      if(tmp->defaults!=NULL)
-	free(tmp->defaults);
-      freeIOType(&tmp->supported);
-      if(tmp->supported!=NULL){
-	free(tmp->supported);
-      }
-      freeElements(&tmp->next);
-      if(tmp->next!=NULL)
-	free(tmp->next);
-    }
-  }
-
-  /**
-   * Free allocated memory of a service.
-   * Require to call free on e after calling this function.
-   *
-   * @param s the service to free
-   */
-  static void freeService(service** s){
-    service* tmp=*s;
-    if(tmp!=NULL){
-      if(tmp->name!=NULL)
-	free(tmp->name);
-      freeMap(&tmp->content);
-      if(tmp->content!=NULL)
-	free(tmp->content);
-      freeMap(&tmp->metadata);
-      if(tmp->metadata!=NULL)
-	free(tmp->metadata);
-      freeElements(&tmp->inputs);
-      if(tmp->inputs!=NULL)
-	free(tmp->inputs);
-      freeElements(&tmp->outputs);
-      if(tmp->outputs!=NULL)
-	free(tmp->outputs);
-    }
-  }
-
-  /**
-   * Add key value pair to an existing map.
-   *
-   * @param m the map to add the KVP
-   * @param n the key to add
-   * @param v the corresponding value to add
-   */
-  static void addToMap(map* m,const char* n,const char* v){
-    if(hasKey(m,n)==false){
-      map* _cursor=m;
-      while(_cursor->next!=NULL){
-	_cursor=_cursor->next;
-      }
-      _cursor->next=createMap(n,v);
-    }
-    else{
-      map *tmp=getMap(m,n);
-      if(tmp->value!=NULL)
-	free(tmp->value);
-      tmp->value=zStrdup(v);
-    }
-  }
-
-  /**
-   * Add a key and an integer value to an existing map.
-   *
-   * @param m the map to add the KVP
-   * @param n the key to add
-   * @param v the corresponding value to add
-   */
-  static void addIntToMap(map* m,const char* n,const int v){
-    char svalue[10];
-    sprintf(svalue,"%d",v);
-    if(hasKey(m,n)==false){
-      map* _cursor=m;
-      while(_cursor->next!=NULL){
-	_cursor=_cursor->next;
-      }
-      _cursor->next=createMap(n,svalue);
-    }
-    else{
-      map *tmp=getMap(m,n);
-      if(tmp->value!=NULL)
-	free(tmp->value);
-      tmp->value=zStrdup(svalue);
-    }
-  }
-
-  /**
-   * Add a key and a binary value to an existing map.
-   *
-   * @param m the map to add the KVP
-   * @param n the key to add
-   * @param v the corresponding value to add
-   * @param size the size of the given value
-   */
-  static void addToMapWithSize(map* m,const char* n,const char* v,int size){
-    if(hasKey(m,n)==false){
-      map* _cursor=m;
-      if(_cursor!=NULL){
-	addToMap(m,n,"");
-      }else{
-	m=createMap(n,"");
-      }
-    }
-    char sname[10]="size";
-    if(strlen(n)>5)
-      sprintf(sname,"size_%s",n+6);
-    map *tmp=getMap(m,n);
-    if(tmp->value!=NULL)
-      free(tmp->value);
-    tmp->value=(char*)malloc((size+1)*sizeof(char));
-    memmove(tmp->value,v,size*sizeof(char));
-    tmp->value[size]=0;
-    char sin[128];
-    sprintf(sin,"%d",size);
-    addToMap(m,sname,sin);
-  }
-
-  /**
-   * Add a map at the end of another map.
-   *
-   * @param mo the map to add mi
-   * @param mi the map to add to mo
-   */
-  static void addMapToMap(map** mo,map* mi){
-    map* tmp=mi;
-    map* _cursor=*mo;
-    while(tmp!=NULL){
-      if(_cursor==NULL){
-	*mo=createMap(tmp->name,tmp->value);
-	(*mo)->next=NULL;
-      }
-      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){
-	  _cursor->next=createMap(tmp->name,tmp->value);
-	}
-	else{
-	  addToMap(*mo,tmp->name,tmp->value);
-	}
-      }
-      _cursor=*mo;
-      tmp=tmp->next;
-#ifdef DEBUG
-      fprintf(stderr,"MO\n");
-      dumpMap(*mo);
-#endif
-    }
-  }
-
-  /**
-   * Add a map to iotype.
-   *
-   * @param io the iotype to add the map
-   * @param mi the map to add to io
-   */
-  static void addMapToIoType(iotype** io,map* mi){
-    iotype* tmp=*io;
-    while(tmp->next!=NULL){
-      tmp=tmp->next;
-    }
-    tmp->next=(iotype*)malloc(IOTYPE_SIZE);
-    tmp->next->content=NULL;
-    addMapToMap(&tmp->next->content,mi);
-    tmp->next->next=NULL;
-  }
-
-  /**
-   * Access a specific map or set its value.
-   *
-   * @param m the map to search for the key
-   * @param key the key to search/add in the map
-   * @param value the value to add if the key does not exist
-   * @return a pointer on the map found or NULL if not found
-   */
-  static map* getMapOrFill(map** m,const char *key,const char* value){
-    map* tmp=*m;
-    map* tmpMap=getMap(tmp,key);
-    if(tmpMap==NULL){
-      if(tmp!=NULL){
-	addToMap((*m),key,value);
-      }
-      else
-	(*m)=createMap(key,value);
-      tmpMap=getMap(*m,key);
-    }
-    return tmpMap;
-  }
-
-  /**
-   * Verify if a map is contained in another map.
-   *
-   * @param m the map to search for i
-   * @param i the map to search in m
-   * @return true if i was found in m, false in other case
-   */
-  static bool contains(map* m,map* i){
-    while(i!=NULL){      
-      if(strcasecmp(i->name,"value")!=0 &&
-	 strcasecmp(i->name,"xlink:href")!=0 &&
-	 strcasecmp(i->name,"useMapServer")!=0 &&
-	 strcasecmp(i->name,"asReference")!=0){
-	map *tmp;
-	if(hasKey(m,i->name) && (tmp=getMap(m,i->name))!=NULL && 
-	   strcasecmp(i->value,tmp->value)!=0)
-	  return false;
-      }
-      i=i->next;
-    }
-    return true;
-  }
-
-  /**
-   * Access a specific iotype from an elements.
-   *
-   * @param e the elements to search for the name
-   * @param name the name to search in the elements e
-   * @param values the map to verify it was contained in the defaults or 
-   *  supported content of the elements e
-   * @return a pointer on the iotype found or NULL if not found
-   */
-  static iotype* getIoTypeFromElement(elements* e,char *name, map* values){
-    elements* cursor=e;
-    while(cursor!=NULL){
-      if(strcasecmp(cursor->name,name)==0){
-	if(contains(cursor->defaults->content,values)==true)
-	  return cursor->defaults;
-	else{
-	  iotype* tmp=cursor->supported;
-	  while(tmp!=NULL){
-	    if(contains(tmp->content,values)==true)
-	      return tmp;	    
-	    tmp=tmp->next;
-	  }
-	}
-      }
-      cursor=cursor->next;
-    }
-    return NULL;
-  }
-
-  /**
-   * Load binary values from a map (in) and add them to another map (out)
-   *
-   * @param out the map to add binaries values
-   * @param in the map containing the binary values to add ti out
-   * @param pos index of the binary in an array (in case of "MapArray")
-   */
-  static void loadMapBinary(map** out,map* in,int pos){
-    map* size=getMap(in,"size");
-    map *lout=*out;
-    if(size!=NULL && pos>0){
-      char tmp[11];
-      sprintf(tmp,"size_%d",pos);
-      size=getMap(in,tmp);
-      sprintf(tmp,"value_%d",pos);
-      map* tmpVin=getMap(in,tmp);
-      map* tmpVout=getMap(lout,tmp);
-      free(tmpVout->value);
-      tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
-      memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
-      tmpVout->value[atoi(size->value)]=0;
-    }else{
-      if(size!=NULL){
-	map* tmpVin=getMap(in,"value");
-	map* tmpVout=getMap(lout,"value");
-	free(tmpVout->value);
-	tmpVout->value=(char*)malloc((atoi(size->value)+1)*sizeof(char));
-	memmove(tmpVout->value,tmpVin->value,atoi(size->value)*sizeof(char));
-	tmpVout->value[atoi(size->value)]=0;
-      }
-    }
-  }
+
+  void _dumpMap(map*);
+  void dumpMap(map*);
+  void dumpMapToFile(map*,FILE*);
+  void dumpMaps(maps* m);
+  void dumpMapsToFile(maps*,char*);
+  map* createMap(const char*,const char*);
+  int count(map*);
+  bool hasKey(map*,const char*);
+  maps* getMaps(maps*,const char*);
+  map* getMap(map*,const char*);
+  map* getLastMap(map*);
+  map* getMapFromMaps(maps*,const char*,const char*);
+  void freeMap(map**);
+  void freeMaps(maps** mo);
   
-  /**
-   * Load binary values from a map (in) and add them to another map (out).
-   * This function will take care of MapArray.
-   * @see loadMapBinary
-   *
-   * @param out the map to add binaries values
-   * @param in the map containing the binary values to add ti out
-   */
-  static void loadMapBinaries(map** out,map* in){
-    map* size=getMap(in,"size");
-    map* length=getMap(in,"length");
-    if(length!=NULL){
-      int len=atoi(length->value);
-      int i=0;
-      for(i=0;i<len;i++){
-	loadMapBinary(out,in,i);
-      }
-    }
-    else
-      if(size!=NULL)
-	loadMapBinary(out,in,-1);
-  }
-
-  /**
-   * Duplicate a Maps
-   * 
-   * @param mo the maps to clone
-   * @return the allocated maps containing a copy of the mo maps
-   */
-  static maps* dupMaps(maps** mo){
-    maps* _cursor=*mo;
-    maps* res=NULL;
-    if(_cursor!=NULL){
-      res=(maps*)malloc(MAPS_SIZE);
-      res->name=zStrdup(_cursor->name);
-      res->content=NULL;
-      res->next=NULL;
-      map* mc=_cursor->content;
-      if(mc!=NULL){
-	addMapToMap(&res->content,mc);
-	loadMapBinaries(&res->content,mc);
-      }
-      res->next=dupMaps(&_cursor->next);
-    }
-    return res;
-  }
-
-  /**
-   * Add a maps at the end of another maps.
-   *
-   * @see addMapToMap, dupMaps, getMaps
-   * @param mo the maps to add mi
-   * @param mi the maps to add to mo
-   */
-  static void addMapsToMaps(maps** mo,maps* mi){
-    maps* tmp=mi;
-    maps* _cursor=*mo;
-    while(tmp!=NULL){
-      if(_cursor==NULL){
-	*mo=dupMaps(&mi);
-      }
-      else{
-	while(_cursor->next!=NULL)
-	  _cursor=_cursor->next;
-	maps* tmp1=getMaps(*mo,tmp->name);
-	if(tmp1==NULL)
-	  _cursor->next=dupMaps(&tmp);
-	else
-	  addMapToMap(&tmp1->content,tmp->content);
-	_cursor=*mo;
-      }
-      tmp=tmp->next;
-    }
-  }
-
-  /**
-   * Access a specific map array element
-   *
-   * @param m the map to search for the key
-   * @param key the key to search in the map
-   * @param index of the MapArray 
-   * @return a pointer on the map found or NULL if not found
-   */
-  static map* getMapArray(map* m,const char* key,int index){
-    char tmp[1024];
-    if(index>0)
-      sprintf(tmp,"%s_%d",key,index);
-    else
-      sprintf(tmp,"%s",key);
-#ifdef DEBUG
-    fprintf(stderr,"** KEY %s\n",tmp);
-#endif
-    map* tmpMap=getMap(m,tmp);
-#ifdef DEBUG
-    if(tmpMap!=NULL)
-      dumpMap(tmpMap);
-#endif
-    return tmpMap;
-  }
-
-
-  /**
-   * Add a key value in a MapArray for a specific index
-   *
-   * @param m the map to search for the key
-   * @param key the key to search in the map
-   * @param index the index of the MapArray 
-   * @param value the value to set in the MapArray 
-   * @return a pointer on the map found or NULL if not found
-   */
-  static void setMapArray(map* m,const char* key,int index,const char* value){
-    char tmp[1024];
-    if(index>0){
-      sprintf(tmp,"%s_%d",key,index);
-      map* len=getMap(m,"length");
-      if((len!=NULL && atoi(len->value)<index+1) || len==NULL){
-	char tmp0[5];
-	sprintf(tmp0,"%d",index+1);
-	addToMap(m,"length",tmp0);
-      }
-    }
-    else
-      sprintf(tmp,"%s",key);
-    map* tmpSize=getMapArray(m,"size",index);
-    if(tmpSize!=NULL && strncasecmp(key,"value",5)==0){
-#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));
-      memcpy(ptr->value,value,atoi(tmpSize->value)); 
-    }
-    else
-      addToMap(m,tmp,value);
-  }
-
-  /**
-   * Access the map "type"
-   *
-   * @param mt the map
-   * @return a pointer on the map for mimeType/dataType/CRS if found, NULL in
-   *  other case
-   */
-  static map* getMapType(map* mt){
-    map* tmap=getMap(mt,(char *)"mimeType");
-    if(tmap==NULL){
-      tmap=getMap(mt,"dataType");
-      if(tmap==NULL){
-	tmap=getMap(mt,"CRS");
-      }
-    }
-#ifdef DEBUG
-	dumpMap(tmap);
-#endif
-    return tmap;
-  }
-
-  /**
-   * Add a Maps containing a MapArray to a Maps
-   *
-   * @see getMapType
-   * @param mo the maps
-   * @param mi the maps
-   * @param typ the map "type"
-   * @return 
-   */
-  static int addMapsArrayToMaps(maps** mo,maps* mi,char* typ){
-    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[12]={
-      (char*)"size",
-      (char*)"value",
-      (char*)"uom",
-      (char*)"Reference",
-      (char*)"Order",
-      (char*)"cache_file",
-      (char*)"fmimeType",
-      (char*)"xlink:href",
-      typ,
-      (char*)"schema",
-      (char*)"encoding",
-      (char*)"isCached"
-    };
-    sprintf(tmpLen,"%d",len+1);
-    addToMap(_cursor->content,"length",tmpLen);
-    int i=0;
-    for(i=0;i<12;i++){
-      map* tmpVI=getMap(tmp->content,tmpV[i]);
-      if(tmpVI!=NULL){
-#ifdef DEBUG
-	fprintf(stderr,"%s = %s\n",tmpV[i],tmpVI->value);
-#endif
-	setMapArray(_cursor->content,tmpV[i],len,tmpVI->value);
-      }
-    }
-    
-    addToMap(_cursor->content,"isArray","true");
-    return 0;
-  }
-
-  /**
-   * Set a key value pair to a map contained in a Maps
-   *
-   * @param m the maps
-   * @param key the maps name
-   * @param subkey the map name included in the maps corresponding to key
-   * @param value the corresponding value to add in the map
-   */
-  static void setMapInMaps(maps* m,const char* key,const char* subkey,const char *value){
-    maps* _tmpm=getMaps(m,key);
-    if(_tmpm!=NULL){
-      map* _ztmpm=getMap(_tmpm->content,subkey);
-      if(_ztmpm!=NULL){
-	if(_ztmpm->value!=NULL)
-	  free(_ztmpm->value);
-	_ztmpm->value=zStrdup(value);
-      }else{
-	maps *tmp=(maps*)malloc(MAPS_SIZE);
-	tmp->name=zStrdup(key);
-	tmp->content=createMap(subkey,value);
-	tmp->next=NULL;
-	addMapsToMaps(&_tmpm,tmp);
-	freeMaps(&tmp);
-	free(tmp);
-      }
-    }else{
-      maps *tmp=(maps*)malloc(MAPS_SIZE);
-      tmp->name=zStrdup(key);
-      tmp->content=createMap(subkey,value);
-      tmp->next=NULL;
-      addMapsToMaps(&m,tmp);
-      freeMaps(&tmp);
-      free(tmp);
-    }
-  }
-
-  /**
-   * Dump an elements on stderr
-   *
-   * @param e the elements to dump
-   */
-  static void dumpElements(elements* e){
-    elements* tmp=e;
-    while(tmp!=NULL){
-      fprintf(stderr,"ELEMENT [%s]\n",tmp->name);
-      fprintf(stderr," > CONTENT [%s]\n",tmp->name);
-      dumpMap(tmp->content);
-      fprintf(stderr," > METADATA [%s]\n",tmp->name);
-      dumpMap(tmp->metadata);
-      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);
-	dumpMap(tmpio->content);
-	tmpio=tmpio->next;
-	ioc++;
-      }
-      tmpio=tmp->supported;
-      ioc=0;
-      while(tmpio!=NULL){
-	fprintf(stderr," > SUPPORTED [%s] (%i)\n",tmp->name,ioc);
-	dumpMap(tmpio->content);
-	tmpio=tmpio->next;
-	ioc++;
-      }
-      fprintf(stderr,"------------------\n");
-      tmp=tmp->next;
-    }
-  }
-
-  /**
-   * Dump an elements on stderr using the YAML syntaxe
-   *
-   * @param e the elements to dump
-   */
-  static void dumpElementsAsYAML(elements* e){
-    elements* tmp=e;
-    int i;
-    while(tmp!=NULL){
-      for(i=0;i<2;i++)
-	fprintf(stderr," ");
-      fprintf(stderr,"%s:\n",tmp->name);
-      map* mcurs=tmp->content;
-      while(mcurs!=NULL){
-	for(i=0;i<4;i++)
-	  fprintf(stderr," ");
-	_dumpMap(mcurs);
-	mcurs=mcurs->next;
-      }
-      mcurs=tmp->metadata;
-      if(mcurs!=NULL){
-	for(i=0;i<4;i++)
-	  fprintf(stderr," ");
-	fprintf(stderr,"MetaData:\n");
-	while(mcurs!=NULL){
-	  for(i=0;i<6;i++)
-	    fprintf(stderr," ");
-	  _dumpMap(mcurs);
-	  mcurs=mcurs->next;
-	}
-      }
-      for(i=0;i<4;i++)
-	fprintf(stderr," ");
-      fprintf(stderr,"%s:\n",tmp->format);
-      iotype* tmpio=tmp->defaults;
-      int ioc=0;
-      while(tmpio!=NULL){
-	for(i=0;i<6;i++)
-	  fprintf(stderr," ");
-	fprintf(stderr,"default:\n");
-	mcurs=tmpio->content;
-	while(mcurs!=NULL){
-	  for(i=0;i<8;i++)
-	    fprintf(stderr," ");
-	  if(strcasecmp(mcurs->name,"range")==0){
-	    fprintf(stderr,"range: \"%s\"\n",mcurs->value);
-	  }else
-	    _dumpMap(mcurs);
-	  mcurs=mcurs->next;
-	}
-	tmpio=tmpio->next;
-	ioc++;
-      }
-      tmpio=tmp->supported;
-      ioc=0;
-      while(tmpio!=NULL){
-	for(i=0;i<6;i++)
-	  fprintf(stderr," ");
-	fprintf(stderr,"supported:\n");
-	mcurs=tmpio->content;
-	while(mcurs!=NULL){
-	  for(i=0;i<8;i++)
-	    fprintf(stderr," ");
-	  if(strcasecmp(mcurs->name,"range")==0){
-	    fprintf(stderr,"range: \"%s\"\n",mcurs->value);
-	  }else
-	    _dumpMap(mcurs);
-	  mcurs=mcurs->next;
-	}
-	tmpio=tmpio->next;
-	ioc++;
-      }
-      tmp=tmp->next;
-    }
-  }
-
-  /**
-   * Duplicate an elements
-   * 
-   * @param e the elements to clone
-   * @return the allocated elements containing a copy of the elements e
-   */
-  static elements* dupElements(elements* e){
-    elements* cursor=e;
-    elements* tmp=NULL;
-    if(cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
-      dumpElements(e);
-      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
-#endif
-      tmp=(elements*)malloc(ELEMENTS_SIZE);
-      tmp->name=zStrdup(e->name);
-      tmp->content=NULL;
-      addMapToMap(&tmp->content,e->content);
-      tmp->metadata=NULL;
-      addMapToMap(&tmp->metadata,e->metadata);
-      if(e->format!=NULL)
-	tmp->format=zStrdup(e->format);
-      else
-	tmp->format=NULL;
-      if(e->defaults!=NULL){
-	tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
-	tmp->defaults->content=NULL;
-	addMapToMap(&tmp->defaults->content,e->defaults->content);
-	tmp->defaults->next=NULL;
-#ifdef DEBUG
-	fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
-	dumpMap(tmp->defaults->content);
-#endif
-      }else
-	tmp->defaults=NULL;
-      if(e->supported!=NULL){
-	tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
-	tmp->supported->content=NULL;
-	addMapToMap(&tmp->supported->content,e->supported->content);
-	tmp->supported->next=NULL;
-	iotype *tmp2=e->supported->next;
-	while(tmp2!=NULL){
-	  addMapToIoType(&tmp->supported,tmp2->content);
-#ifdef DEBUG
-	  fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
-	  dumpMap(tmp->defaults->content);
-#endif
-	  tmp2=tmp2->next;
-	}
-      }
-      else
-	tmp->supported=NULL;
-      tmp->next=dupElements(cursor->next);
-    }
-    return tmp;
-  }
-
-  /**
-   * Add an elements to another elements.
-   *
-   * @see dupElements
-   * @param m the elements to add the e
-   * @param e the elements to be added to m
-   */
-  static void addToElements(elements** m,elements* e){
-    elements* tmp=e;
-    if(*m==NULL){
-      *m=dupElements(tmp);
-    }else{
-      addToElements(&(*m)->next,tmp);
-    }
-  }
-  
-  /**
-   * Dump a service on stderr
-   *
-   * @param s the service to dump
-   */
-  static void dumpService(service* s){
-    if(s==NULL)
-      return;
-    fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
-    if(s->content!=NULL){
-      fprintf(stderr,"CONTENT MAP\n");
-      dumpMap(s->content);
-      fprintf(stderr,"CONTENT METADATA\n");
-      dumpMap(s->metadata);
-    }
-    if(s->inputs!=NULL){
-      fprintf(stderr,"INPUT ELEMENTS [%s]\n------------------\n",s->name);
-      dumpElements(s->inputs);
-    }
-    if(s->outputs!=NULL){
-      fprintf(stderr,"OUTPUT ELEMENTS [%s]\n------------------\n",s->name);
-      dumpElements(s->outputs);
-    }
-    fprintf(stderr,"++++++++++++++++++\n");
-  }
-
-  /**
-   * Dump a service on stderr using the YAML syntaxe
-   *
-   * @param s the service to dump
-   */
-  static void dumpServiceAsYAML(service* s){
-    int i;
-    fprintf(stderr,"# %s\n\n",s->name);
-    if(s->content!=NULL){
-      map* mcurs=s->content;
-      dumpMap(mcurs);
-      mcurs=s->metadata;
-      if(mcurs!=NULL){
-	fprintf(stderr,"MetaData:\n");
-	while(mcurs!=NULL){
-	  for(i=0;i<2;i++)
-	    fprintf(stderr," ");
-	  _dumpMap(mcurs);
-	  mcurs=mcurs->next;
-	}
-      }
-    }
-    if(s->inputs!=NULL){
-      fprintf(stderr,"\ninputs:\n");
-      dumpElementsAsYAML(s->inputs);
-    }
-    if(s->outputs!=NULL){
-      fprintf(stderr,"\noutputs:\n");
-      dumpElementsAsYAML(s->outputs);
-    }
-  }
-
-  /**
-   * Duplicate a service
-   * 
-   * @param s the service to clone
-   * @return the allocated service containing a copy of the serfvice s
-   */
-  static service* dupService(service* s){
-    service *res=(service*)malloc(SERVICE_SIZE);
-    res->name=zStrdup(s->name);
-    res->content=NULL;
-    addMapToMap(&res->content,s->content);
-    res->metadata=NULL;
-    addMapToMap(&res->metadata,s->metadata);
-    res->inputs=dupElements(s->inputs);
-    res->outputs=dupElements(s->outputs);
-    return res;
-  }
-
-  /**
-   * Print the registry on stderr.
-   * 
-   * @param r the registry
-   */
-  static void dumpRegistry(registry* r){
-    registry* p=r;
-    while(p!=NULL){
-      fprintf(stderr,"%s \n",p->name);
-      services* s=p->content;
-      s=p->content;
-      while(s!=NULL){
-	dumpService(s->content);
-	s=s->next;
-      }
-      p=p->next;
-    }
-  }
-
-  /**
-   * Add a service to the registry
-   *
-   * @param reg the resgitry to add the service
-   * @param name the registry name to update
-   * @param content the service to add
-   */
-  static bool addServiceToRegistry(registry** reg,char* name,service* content){
-    registry *l=*reg;
-    int isInitial=-1;
-    if(l==NULL){
-      l=(registry*)malloc(REGISTRY_SIZE);
-      isInitial=1;
-    }
-    if(l!=NULL){
-      int hasLevel=-1;
-      while(isInitial<0 && l!=NULL){
-	if(l->name!=NULL && strcasecmp(name,l->name)==0){
-	  hasLevel=1;
-	  break;
-	}
-	l=l->next;
-      }
-      if(hasLevel<0){
-	if(isInitial<0)
-	  l=(registry*)malloc(REGISTRY_SIZE);
-	l->name=zStrdup(name);
-	l->content=NULL;
-	l->next=NULL;
-      }
-      if(l->content==NULL){
-	l->content=(services*)malloc(SERVICES_SIZE);
-	l->content->content=dupService(content);
-	l->content->next=NULL;
-      }
-      else{
-	services* s=l->content;
-	while(s->next!=NULL)
-	  s=s->next;
-	s->next=(services*)malloc(SERVICES_SIZE);
-	s->next->content=dupService(content);
-	s->next->next=NULL;
-      }
-      l->next=NULL;
-      if(isInitial>0)
-	*reg=l;
-      else{
-	registry *r=*reg;
-	while(r->next!=NULL)
-	  r=r->next;
-	r->next=l;
-	r->next->next=NULL;
-      }
-      return true;
-    }
-    else
-      return false;
-  }
-
-  /**
-   * Free memory allocated for the registry
-   *
-   * @param r the registry
-   */
-  static void freeRegistry(registry** r){
-    registry* lr=*r;
-    while(lr!=NULL){
-      services* s=lr->content;
-      free(lr->name);
-      while(s!=NULL){
-	service* s1=s->content;
-	s=s->next;
-	if(s1!=NULL){
-	  freeService(&s1);
-	  free(s1);
-	  s1=NULL;
-	}
-      }
-      lr=lr->next;
-    }    
-  }
-
-  /**
-   * Access a service in the registry
-   *
-   * @param r the registry
-   * @param level the regitry to search ("concept", "generic" or "implementation")
-   * @param sname the service name
-   * @return the service pointer if a corresponding service was found or NULL
-   */
-  static service* getServiceFromRegistry(registry* r,char  *level,char* sname){
-    registry *lr=r;
-    while(lr!=NULL){
-      if(strcasecmp(lr->name,level)==0){
-	services* s=lr->content;
-	while(s!=NULL){
-	  if(s->content!=NULL && strcasecmp(s->content->name,sname)==0)
-	    return s->content;
-	  s=s->next;
-	}
-	break;
-      }
-      lr=lr->next;
-    }
-    return NULL;
-  }
-
-  /**
-   * Apply inheritance to an out map from a reference in map
-   *
-   * @param out the map to update
-   * @param in the reference map (containing inherited properties)
-   */
-  static void inheritMap(map** out,map* in){
-    map* content=in;
-    while(content!=NULL && *out!=NULL){
-      map* cmap=getMap(*out,content->name);
-      if(cmap==NULL)
-	addToMap(*out,content->name,content->value);
-      content=content->next;
-    }
-  }
-
-  /**
-   * Apply inheritance to an out iotype from a reference in iotype
-   * 
-   * @param out the iotype to update
-   * @param in the reference iotype (containing inherited properties)
-   */
-  static void inheritIOType(iotype** out,iotype* in){
-    iotype* io=in;
-    iotype* oio=*out;
-    if(io!=NULL){
-      if(*out==NULL){
-	*out=(iotype*)malloc(IOTYPE_SIZE);
-	(*out)->content=NULL;
-	addMapToMap(&(*out)->content,io->content);
-	(*out)->next=NULL;
-	oio=*out;
-	inheritIOType(&oio->next,io->next);
-      }else{
-	inheritIOType(&oio->next,io->next);
-      }
-    }
-  }
-
-  /**
-   * Apply inheritance to an out elements from a reference in elements
-   * 
-   * @param out the elements to update
-   * @param in the reference elements (containing inherited properties)
-   */
-  static void inheritElements(elements** out,elements* in){
-    elements* content=in;
-    while(content!=NULL && *out!=NULL){
-      elements* cmap=getElements(*out,content->name);
-      if(cmap==NULL)
-	addToElements(out,content);
-      else{
-	inheritMap(&cmap->content,content->content);
-	inheritMap(&cmap->metadata,content->metadata);
-	if(cmap->format==NULL && content->format!=NULL)
-	  cmap->format=zStrdup(content->format);
-	inheritIOType(&cmap->defaults,content->defaults);
-	if(cmap->supported==NULL)
-	  inheritIOType(&cmap->supported,content->supported);
-	else{
-	  iotype* p=content->supported;
-	  while(p!=NULL){
-	    addMapToIoType(&cmap->supported,p->content);
-	    p=p->next;
-	  }
-	}
-      }
-      content=content->next;
-    }
-  }
-
-  /**
-   * Apply inheritance to a service based on a registry
-   * 
-   * @param r the registry storing profiles hierarchy
-   * @param s the service to update depending on its inheritance
-   */
-  static void inheritance(registry *r,service** s){
-    if(r==NULL)
-      return;
-    service* ls=*s;
-    if(ls->content==NULL)
-      return;
-    map* profile=getMap(ls->content,"extend");
-    map* level=getMap(ls->content,"level");
-    if(profile!=NULL&&level!=NULL){
-      service* s1;
-      if(strncasecmp(level->value,"profile",7)==0)
-	s1=getServiceFromRegistry(r,"generic",profile->value);
-      else
-	s1=getServiceFromRegistry(r,level->value,profile->value);
-      
-      inheritMap(&ls->content,s1->content);
-      inheritMap(&ls->metadata,s1->metadata);
-      if(ls->inputs==NULL && s1->inputs!=NULL){
-	ls->inputs=dupElements(s1->inputs);
-      }else{
-	inheritElements(&ls->inputs,s1->inputs);
-      }
-      if(ls->outputs==NULL && s1->outputs!=NULL){
-	ls->outputs=dupElements(s1->outputs);
-      }else
-	inheritElements(&ls->outputs,s1->outputs);
-    }
-  }
-
-  /**
-   * Convert a maps to a char*** (only used for Fortran support)
-   *
-   * @param m the maps to convert
-   * @param c the resulting array
-   */
-  static void mapsToCharXXX(maps* m,char*** c){
-    maps* tm=m;
-    int i=0;
-    int j=0;
-    char tmp[10][30][1024];
-    memset(tmp,0,1024*10*10);
-    while(tm!=NULL){
-      if(i>=10)
-	break;
-      strcpy(tmp[i][j],"name");
-      j++;
-      strcpy(tmp[i][j],tm->name);
-      j++;
-      map* tc=tm->content;
-      while(tc!=NULL){
-	if(j>=30)
-	  break;
-	strcpy(tmp[i][j],tc->name);
-	j++;
-	strcpy(tmp[i][j],tc->value);
-	j++;
-	tc=tc->next;
-      }
-      tm=tm->next;
-      j=0;
-      i++;
-    }
-    memcpy(c,tmp,10*10*1024);
-  }
-
-  /**
-   * Convert a char*** to a maps (only used for Fortran support)
-   *
-   * @param c the array to convert
-   * @param m the resulting maps
-   */
-  static void charxxxToMaps(char*** c,maps**m){
-    maps* trorf=*m;
-    int i,j;
-    char tmp[10][30][1024];
-    memcpy(tmp,c,10*30*1024);
-    for(i=0;i<10;i++){
-      if(strlen(tmp[i][1])==0)
-	break;
-      trorf->name=tmp[i][1];
-      trorf->content=NULL;
-      trorf->next=NULL;
-      for(j=2;j<29;j+=2){
-	if(strlen(tmp[i][j+1])==0)
-	  break;
-	if(trorf->content==NULL)
-	  trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
-	else
-	  addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
-      }
-      trorf=trorf->next;
-    }
-    m=&trorf;
-  }
-
+
+  bool hasElement(elements*,const char*);
+  elements* getElements(elements*,char*);
+  void freeIOType(iotype**);
+  void freeElements(elements**);
+  void freeService(service**);
+  void addToMap(map*,const char*,const char*);
+  void addIntToMap(map*,const char*,const int);
+  void addToMapWithSize(map*,const char*,const char*,int);
+  void addMapToMap(map**,map*);
+  void addMapToIoType(iotype**,map*);
+  map* getMapOrFill(map**,const char*,const char*);
+  bool contains(map*,map*);
+  iotype* getIoTypeFromElement(elements*,char*, map*);
+  void loadMapBinary(map**,map*,int);
+  void loadMapBinaries(map**,map*);
+  maps* dupMaps(maps**);
+  void addMapsToMaps(maps**,maps*);
+  map* getMapArray(map*,const char*,int);
+  void setMapArray(map*,const char*,int,const char*);
+  map* getMapType(map*);
+  int addMapsArrayToMaps(maps**,maps*,char*);
+  void setMapInMaps(maps*,const char*,const char*,const char*);
+  void dumpElements(elements*);
+  void dumpElementsAsYAML(elements*);
+  elements* dupElements(elements*);
+  void addToElements(elements**,elements*);
+  void dumpService(service*);
+  void dumpServiceAsYAML(service*);
+  service* dupService(service*);
+  void dumpRegistry(registry*);
+  bool addServiceToRegistry(registry**,char*,service*);
+  void freeRegistry(registry**);
+  service* getServiceFromRegistry(registry*,char*,char*);
+  void inheritMap(map**,map*);
+  void inheritIOType(iotype**,iotype*);
+  void inheritElements(elements**,elements*);
+  void inheritance(registry*,service**);
+  void mapsToCharXXX(maps*,char***);
+  void charxxxToMaps(char***,maps**);
 #ifdef WIN32
   extern char *url_encode(char *);
-
-  static char* getMapsAsKVP(maps* m,int length,int type){
-    char *dataInputsKVP=(char*) malloc(length*sizeof(char));
-    char *dataInputsKVPi=NULL;
-    maps* curs=m;
-    int i=0;
-    while(curs!=NULL){
-      map *inRequest=getMap(curs->content,"inRequest");
-      map *hasLength=getMap(curs->content,"length");
-      if((inRequest!=NULL && strncasecmp(inRequest->value,"true",4)==0) ||
-	 inRequest==NULL){
-	if(i==0)
-	  if(type==0){
-	    sprintf(dataInputsKVP,"%s=",curs->name);
-	    if(hasLength!=NULL){
-	      dataInputsKVPi=(char*)malloc((strlen(curs->name)+2)*sizeof(char));
-	      sprintf(dataInputsKVPi,"%s=",curs->name);
-	    }
-	  }
-	  else
-	    sprintf(dataInputsKVP,"%s",curs->name);
-	else{
-	  char *temp=zStrdup(dataInputsKVP);
-	  if(type==0)
-	    sprintf(dataInputsKVP,"%s;%s=",temp,curs->name);
-	  else
-	    sprintf(dataInputsKVP,"%s;%s",temp,curs->name);
-	}
-	map* icurs=curs->content;
-	if(type==0){
-	  char *temp=zStrdup(dataInputsKVP);
-	  if(getMap(curs->content,"xlink:href")!=NULL)
-	    sprintf(dataInputsKVP,"%sReference",temp);
-	  else{
-	    if(hasLength!=NULL){
-	      int j;
-	      for(j=0;j<atoi(hasLength->value);j++){
-		map* tmp0=getMapArray(curs->content,"value",j);
-		if(j==0)
-		  free(temp);
-		temp=zStrdup(dataInputsKVP);
-		if(j==0)
-		  sprintf(dataInputsKVP,"%s%s",temp,tmp0->value);
-		else
-		  sprintf(dataInputsKVP,"%s;%s%s",temp,dataInputsKVPi,tmp0->value);
-	      }
-	    }
-	    else
-	      sprintf(dataInputsKVP,"%s%s",temp,icurs->value);
-	  }
-	  free(temp);
-	}
-	while(icurs!=NULL){
-	  if(strncasecmp(icurs->name,"value",5)!=0 &&
-	     strncasecmp(icurs->name,"mimeType_",9)!=0 &&
-	     strncasecmp(icurs->name,"dataType_",9)!=0 &&
-	     strncasecmp(icurs->name,"size",4)!=0 &&
-	     strncasecmp(icurs->name,"length",4)!=0 &&
-	     strncasecmp(icurs->name,"isArray",7)!=0 &&
-	     strcasecmp(icurs->name,"Reference")!=0 &&
-	     strcasecmp(icurs->name,"minOccurs")!=0 &&
-	     strcasecmp(icurs->name,"maxOccurs")!=0 &&
-	     strncasecmp(icurs->name,"fmimeType",9)!=0 &&
-	     strcasecmp(icurs->name,"inRequest")!=0){
-	    char *itemp=zStrdup(dataInputsKVP);
-	    if(strcasecmp(icurs->name,"xlink:href")!=0)
-	      sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,icurs->value);
-	    else
-	      sprintf(dataInputsKVP,"%s@%s=%s",itemp,icurs->name,url_encode(icurs->value));
-	    free(itemp);
-	  }
-	  icurs=icurs->next;
-	}
-      }
-      curs=curs->next;
-      i++;
-    }
-    return dataInputsKVP;
-  }
+  char* getMapsAsKVP(maps*,int,int);
 #endif
 
Index: trunk/zoo-project/zoo-kernel/service_conf.y
===================================================================
--- trunk/zoo-project/zoo-kernel/service_conf.y	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_conf.y	(revision 640)
@@ -174,4 +174,5 @@
       current_element->defaults=NULL;
       current_element->supported=NULL;
+      current_element->child=NULL;
       current_element->next=NULL;
     }
@@ -223,4 +224,5 @@
 	current_element->defaults=NULL;
 	current_element->supported=NULL;
+	current_element->child=NULL;
 	current_element->next=NULL;
       }
Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 640)
@@ -23,10 +23,6 @@
  */
 
+#include "fcgi_stdio.h"
 #include "service_internal.h"
-#ifdef USE_MS
-#include "service_internal_ms.h"
-#else
-#include "cpl_vsi.h"
-#endif
 
 #ifndef TRUE
@@ -37,86 +33,5 @@
 #endif
 
-#ifndef WIN32
-#include <dlfcn.h>
-#endif
-
 #define ERROR_MSG_MAX_LENGTH 1024
-
-#include "mimetypes.h"
-
-/**
- * Verify if a given language is listed in the lang list defined in the [main] 
- * section of the main.cfg file.
- * 
- * @param conf the map containing the settings from the main.cfg file
- * @param str the specific language
- * @return 1 if the specific language is listed, -1 in other case.
- */
-int isValidLang(maps* conf,const char *str){
-  map *tmpMap=getMapFromMaps(conf,"main","lang");
-  char *tmp=zStrdup(tmpMap->value);
-  char *pToken=strtok(tmp,",");
-  int res=-1;
-  while(pToken!=NULL){
-    if(strcasecmp(str,pToken)==0){
-      res=1;
-      break;
-    }
-    pToken = strtok(NULL,",");
-  }
-  free(tmp);
-  return res;
-}
-
-/**
- * Print the HTTP headers based on a map.
- * 
- * @param m the map containing the headers informations
- */
-void printHeaders(maps* m){
-  maps *_tmp=getMaps(m,"headers");
-  if(_tmp!=NULL){
-    map* _tmp1=_tmp->content;
-    while(_tmp1!=NULL){
-      printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
-      _tmp1=_tmp1->next;
-    }
-  }
-}
-
-/**
- * Add a land attribute to a XML node
- *
- * @param n the XML node to add the attribute
- * @param m the map containing the language key to add as xml:lang
- */
-void addLangAttr(xmlNodePtr n,maps *m){
-  map *tmpLmap=getMapFromMaps(m,"main","language");
-  if(tmpLmap!=NULL)
-    xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST tmpLmap->value);
-  else
-    xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en-US");
-}
-
-/**
- * Converts a hex character to its integer value 
- *
- * @param ch the char to convert
- * @return the converted char 
- */
-char from_hex(char ch) {
-  return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
-}
-
-/**
- * Converts an integer value to its hec character 
- *
- * @param code the char to convert
- * @return the converted char 
- */
-char to_hex(char code) {
-  static char hex[] = "0123456789abcdef";
-  return hex[code & 15];
-}
 
 /**
@@ -649,3396 +564,4 @@
 #endif
 
-
-/**
- * URLEncode an url
- *
- * @param str the url to encode
- * @return a url-encoded version of str
- * @warning be sure to free() the returned string after use
- */
-char *url_encode(char *str) {
-  char *pstr = str, *buf = (char*) malloc(strlen(str) * 3 + 1), *pbuf = buf;
-  while (*pstr) {
-    if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') 
-      *pbuf++ = *pstr;
-    else if (*pstr == ' ') 
-      *pbuf++ = '+';
-    else 
-      *pbuf++ = '%', *pbuf++ = to_hex(*pstr >> 4), *pbuf++ = to_hex(*pstr & 15);
-    pstr++;
-  }
-  *pbuf = '\0';
-  return buf;
-}
-
-/**
- * Decode an URLEncoded url
- *
- * @param str the URLEncoded url to decode
- * @return a url-decoded version of str
- * @warning be sure to free() the returned string after use
- */
-char *url_decode(char *str) {
-  char *pstr = str, *buf = (char*) malloc(strlen(str) + 1), *pbuf = buf;
-  while (*pstr) {
-    if (*pstr == '%') {
-      if (pstr[1] && pstr[2]) {
-        *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
-        pstr += 2;
-      }
-    } else if (*pstr == '+') { 
-      *pbuf++ = ' ';
-    } else {
-      *pbuf++ = *pstr;
-    }
-    pstr++;
-  }
-  *pbuf = '\0';
-  return buf;
-}
-
-/**
- * Replace the first letter by its upper case version in a new char array
- *
- * @param tmp the char*
- * @return a new char* with first letter in upper case
- * @warning be sure to free() the returned string after use
- */
-char *zCapitalize1(char *tmp){
-  char *res=zStrdup(tmp);
-  if(res[0]>=97 && res[0]<=122)
-    res[0]-=32;
-  return res;
-}
-
-/**
- * Replace all letters by their upper case version in a new char array
- *
- * @param tmp the char*
- * @return a new char* with first letter in upper case
- * @warning be sure to free() the returned string after use
- */
-char *zCapitalize(char *tmp){
-  int i=0;
-  char *res=zStrdup(tmp);
-  for(i=0;i<strlen(res);i++)
-    if(res[i]>=97 && res[i]<=122)
-      res[i]-=32;
-  return res;
-}
-
-/**
- * Search for an existing XML namespace in usedNS.
- * 
- * @param name the name of the XML namespace to search
- * @return the index of the XML namespace found or -1 if not found.
- */
-int zooXmlSearchForNs(const char* name){
-  int i;
-  int res=-1;
-  for(i=0;i<nbNs;i++)
-    if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){
-      res=i;
-      break;
-    }
-  return res;
-}
-
-/**
- * Add an XML namespace to the usedNS if it was not already used.
- * 
- * @param nr the xmlNodePtr to attach the XML namspace (can be NULL)
- * @param url the url of the XML namespace to add
- * @param name the name of the XML namespace to add
- * @return the index of the XML namespace added.
- */
-int zooXmlAddNs(xmlNodePtr nr,const char* url,const char* name){
-#ifdef DEBUG
-  fprintf(stderr,"zooXmlAddNs %d %s \n",nbNs,name);
-#endif
-  int currId=-1;
-  if(nbNs==0){
-    nbNs++;
-    currId=0;
-    nsName[currId]=strdup(name);
-    usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
-  }else{
-    currId=zooXmlSearchForNs(name);
-    if(currId<0){
-      nbNs++;
-      currId=nbNs-1;
-      nsName[currId]=strdup(name);
-      usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
-    }
-  }
-  return currId;
-}
-
-/**
- * Free allocated memory to store used XML namespace.
- */
-void zooXmlCleanupNs(){
-  int j;
-#ifdef DEBUG
-  fprintf(stderr,"zooXmlCleanup %d\n",nbNs);
-#endif
-  for(j=nbNs-1;j>=0;j--){
-#ifdef DEBUG
-    fprintf(stderr,"zooXmlCleanup %d\n",j);
-#endif
-    if(j==0)
-      xmlFreeNs(usedNs[j]);
-    free(nsName[j]);
-    nbNs--;
-  }
-  nbNs=0;
-}
-
-/**
- * Add a XML document to the iDocs.
- * 
- * @param value the string containing the XML document
- * @return the index of the XML document added.
- */
-int zooXmlAddDoc(const char* value){
-  int currId=0;
-  nbDocs++;
-  currId=nbDocs-1;
-  iDocs[currId]=xmlParseMemory(value,strlen(value));
-  return currId;
-}
-
-/**
- * Free allocated memort to store XML documents
- */
-void zooXmlCleanupDocs(){
-  int j;
-  for(j=nbDocs-1;j>=0;j--){
-    xmlFreeDoc(iDocs[j]);
-  }
-  nbDocs=0;
-}
-
-/**
- * Generate a SOAP Envelope node when required (if the isSoap key of the [main]
- * section is set to true).
- * 
- * @param conf the conf maps containing the main.cfg settings
- * @param n the node used as children of the generated soap:Envelope
- * @return the generated soap:Envelope (if isSoap=true) or the input node n 
- *  (when isSoap=false)
- */
-xmlNodePtr soapEnvelope(maps* conf,xmlNodePtr n){
-  map* soap=getMapFromMaps(conf,"main","isSoap");
-  if(soap!=NULL && strcasecmp(soap->value,"true")==0){
-    int lNbNs=nbNs;
-    nsName[lNbNs]=strdup("soap");
-    usedNs[lNbNs]=xmlNewNs(NULL,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
-    nbNs++;
-    xmlNodePtr nr = xmlNewNode(usedNs[lNbNs], BAD_CAST "Envelope");
-    nsName[nbNs]=strdup("soap");
-    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2003/05/soap-envelope",BAD_CAST "soap");
-    nbNs++;
-    nsName[nbNs]=strdup("xsi");
-    usedNs[nbNs]=xmlNewNs(nr,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-    nbNs++;
-    xmlNsPtr ns_xsi=usedNs[nbNs-1];
-    xmlNewNsProp(nr,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.w3.org/2003/05/soap-envelope http://www.w3.org/2003/05/soap-envelope");
-    xmlNodePtr nr1 = xmlNewNode(usedNs[lNbNs], BAD_CAST "Body");
-    xmlAddChild(nr1,n);
-    xmlAddChild(nr,nr1);
-    return nr;
-  }else
-    return n;
-}
-
-/**
- * Generate a WPS header.
- * 
- * @param doc the document to add the header
- * @param m the conf maps containing the main.cfg settings
- * @param req the request type (GetCapabilities,DescribeProcess,Execute)
- * @param rname the root node name
- * @return the generated wps:rname xmlNodePtr (can be wps: Capabilities, 
- *  wps:ProcessDescriptions,wps:ExecuteResponse)
- */
-xmlNodePtr printWPSHeader(xmlDocPtr doc,maps* m,const char* req,const char* rname){
-
-  xmlNsPtr ns,ns_xsi;
-  xmlNodePtr n;
-
-  int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
-  ns=usedNs[wpsId];
-  n = xmlNewNode(ns, BAD_CAST rname);
-  zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
-  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
-  ns_xsi=usedNs[xsiId];
-  
-  char *tmp=(char*) malloc((86+strlen(req)+1)*sizeof(char));
-  sprintf(tmp,"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wps%s_response.xsd",req);
-  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
-  free(tmp);
-  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  addLangAttr(n,m);
-  xmlNodePtr fn=soapEnvelope(m,n);
-  xmlDocSetRootElement(doc, fn);
-  return n;
-}
-
-/**
- * Generate a Capabilities header.
- * 
- * @param doc the document to add the header
- * @param m the conf maps containing the main.cfg settings
- * @return the generated wps:ProcessOfferings xmlNodePtr 
- */
-xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,maps* m){
-
-  xmlNsPtr ns,ns_ows,ns_xlink;
-  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6;
-  n = printWPSHeader(doc,m,"GetCapabilities","Capabilities");
-  maps* toto1=getMaps(m,"main");
-  char tmp[256];
-
-  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
-  ns=usedNs[wpsId];
-  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
-  ns_xlink=usedNs[xlinkId];
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
-
-  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification");
-  maps* tmp4=getMaps(m,"identification");
-  if(tmp4!=NULL){
-    map* tmp2=tmp4->content;
-    const char *orderedFields[5];
-    orderedFields[0]="Title";
-    orderedFields[1]="Abstract";
-    orderedFields[2]="Keywords";
-    orderedFields[3]="Fees";
-    orderedFields[4]="AccessConstraints";
-    int oI=0;
-    for(oI=0;oI<5;oI++)
-      if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){
-	if(strcasecmp(tmp2->name,"abstract")==0 ||
-	   strcasecmp(tmp2->name,"title")==0 ||
-	   strcasecmp(tmp2->name,"accessConstraints")==0 ||
-	   strcasecmp(tmp2->name,"fees")==0){
-	  tmp2->name[0]=toupper(tmp2->name[0]);
-	  nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	  xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	  xmlAddChild(nc,nc1);
-	}
-	else
-	  if(strcmp(tmp2->name,"keywords")==0){
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
-	    char *toto=tmp2->value;
-	    char buff[256];
-	    int i=0;
-	    int j=0;
-	    while(toto[i]){
-	      if(toto[i]!=',' && toto[i]!=0){
-		buff[j]=toto[i];
-		buff[j+1]=0;
-		j++;
-	      }
-	      else{
-		nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-		xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-		xmlAddChild(nc1,nc2);
-		j=0;
-	      }
-	      i++;
-	    }
-	    if(strlen(buff)>0){
-	      nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	      xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	      xmlAddChild(nc1,nc2);
-	    }
-	    xmlAddChild(nc,nc1);
-	    nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceType");
-	    xmlAddChild(nc2,xmlNewText(BAD_CAST "WPS"));
-	    xmlAddChild(nc,nc2);
-	    nc2 = xmlNewNode(ns_ows, BAD_CAST "ServiceTypeVersion");
-	    xmlAddChild(nc2,xmlNewText(BAD_CAST "1.0.0"));
-	    xmlAddChild(nc,nc2);
-	  }
-	tmp2=tmp2->next;
-      }
-  }
-  else{
-    fprintf(stderr,"TMP4 NOT FOUND !!");
-    return NULL;
-  }
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider");
-  nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact");
-  nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo");
-  nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone");
-  nc6 = xmlNewNode(ns_ows, BAD_CAST "Address");
-  tmp4=getMaps(m,"provider");
-  if(tmp4!=NULL){
-    map* tmp2=tmp4->content;
-    const char *tmpAddress[6];
-    tmpAddress[0]="addressDeliveryPoint";
-    tmpAddress[1]="addressCity";
-    tmpAddress[2]="addressAdministrativeArea";
-    tmpAddress[3]="addressPostalCode";
-    tmpAddress[4]="addressCountry";
-    tmpAddress[5]="addressElectronicMailAddress";
-    const char *tmpPhone[2];
-    tmpPhone[0]="phoneVoice";
-    tmpPhone[1]="phoneFacsimile";
-    const char *orderedFields[12];
-    orderedFields[0]="providerName";
-    orderedFields[1]="providerSite";
-    orderedFields[2]="individualName";
-    orderedFields[3]="positionName";
-    orderedFields[4]=tmpPhone[0];
-    orderedFields[5]=tmpPhone[1];
-    orderedFields[6]=tmpAddress[0];
-    orderedFields[7]=tmpAddress[1];
-    orderedFields[8]=tmpAddress[2];
-    orderedFields[9]=tmpAddress[3];
-    orderedFields[10]=tmpAddress[4];
-    orderedFields[11]=tmpAddress[5];
-    int oI=0;
-    for(oI=0;oI<12;oI++)
-      if((tmp2=getMap(tmp4->content,orderedFields[oI]))!=NULL){
-	if(strcmp(tmp2->name,"keywords")!=0 &&
-	   strcmp(tmp2->name,"serverAddress")!=0 &&
-	   strcmp(tmp2->name,"lang")!=0){
-	  tmp2->name[0]=toupper(tmp2->name[0]);
-	  if(strcmp(tmp2->name,"ProviderName")==0){
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	    xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	    xmlAddChild(nc,nc1);
-	  }
-	  else{
-	    if(strcmp(tmp2->name,"ProviderSite")==0){
-	      nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	      xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value);
-	      xmlAddChild(nc,nc1);
-	    } 
-	    else  
-	      if(strcmp(tmp2->name,"IndividualName")==0 || 
-		 strcmp(tmp2->name,"PositionName")==0){
-		nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-		xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-		xmlAddChild(nc3,nc1);
-	      } 
-	      else 
-		if(strncmp(tmp2->name,"Phone",5)==0){
-		  int j;
-		  for(j=0;j<2;j++)
-		    if(strcasecmp(tmp2->name,tmpPhone[j])==0){
-		      char *tmp4=tmp2->name;
-		      nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+5);
-		      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-		      xmlAddChild(nc5,nc1);
-		    }
-		}
-		else 
-		  if(strncmp(tmp2->name,"Address",7)==0){
-		    int j;
-		    for(j=0;j<6;j++)
-		      if(strcasecmp(tmp2->name,tmpAddress[j])==0){
-			char *tmp4=tmp2->name;
-			nc1 = xmlNewNode(ns_ows, BAD_CAST tmp4+7);
-			xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-			xmlAddChild(nc6,nc1);
-		      }
-		  }
-	  }
-	}
-	else
-	  if(strcmp(tmp2->name,"keywords")==0){
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
-	    char *toto=tmp2->value;
-	    char buff[256];
-	    int i=0;
-	    int j=0;
-	    while(toto[i]){
-	      if(toto[i]!=',' && toto[i]!=0){
-		buff[j]=toto[i];
-		buff[j+1]=0;
-		j++;
-	      }
-	      else{
-		nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-		xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-		xmlAddChild(nc1,nc2);
-		j=0;
-	      }
-	      i++;
-	    }
-	    if(strlen(buff)>0){
-	      nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	      xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	      xmlAddChild(nc1,nc2);
-	    }
-	    xmlAddChild(nc,nc1);
-	  }
-	tmp2=tmp2->next;
-      }
-  }
-  else{
-    fprintf(stderr,"TMP4 NOT FOUND !!");
-  }
-  xmlAddChild(nc4,nc5);
-  xmlAddChild(nc4,nc6);
-  xmlAddChild(nc3,nc4);
-  xmlAddChild(nc,nc3);
-  xmlAddChild(n,nc);
-
-
-  nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata");
-  char *tmp2[3];
-  tmp2[0]=strdup("GetCapabilities");
-  tmp2[1]=strdup("DescribeProcess");
-  tmp2[2]=strdup("Execute");
-  int j=0;
-
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"serverAddress");
-    if(tmp!=NULL){
-      SERVICE_URL = strdup(tmp->value);
-    }
-    else
-      SERVICE_URL = strdup("not_defined");
-  }
-  else
-    SERVICE_URL = strdup("not_defined");
-
-  for(j=0;j<3;j++){
-    nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation");
-    xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]);
-    nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP");
-    nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP");
-    nc4 = xmlNewNode(ns_ows, BAD_CAST "Get");
-    sprintf(tmp,"%s",SERVICE_URL);
-    xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
-    xmlAddChild(nc3,nc4);
-    nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
-    xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
-    xmlAddChild(nc3,nc4);
-    xmlAddChild(nc2,nc3);
-    xmlAddChild(nc1,nc2);    
-    xmlAddChild(nc,nc1);    
-  }
-  for(j=2;j>=0;j--)
-    free(tmp2[j]);
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings");
-  xmlAddChild(n,nc);
-
-  nc1 = xmlNewNode(ns, BAD_CAST "Languages");
-  nc2 = xmlNewNode(ns, BAD_CAST "Default");
-  nc3 = xmlNewNode(ns, BAD_CAST "Supported");
-  
-  toto1=getMaps(m,"main");
-  if(toto1!=NULL){
-    map* tmp1=getMap(toto1->content,"lang");
-    char *toto=tmp1->value;
-    char buff[256];
-    int i=0;
-    int j=0;
-    int dcount=0;
-    while(toto[i]){
-      if(toto[i]!=',' && toto[i]!=0){
-	buff[j]=toto[i];
-	buff[j+1]=0;
-	j++;
-      }
-      else{
-	nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
-	if(dcount==0){
-	  xmlAddChild(nc2,nc4);
-	  xmlAddChild(nc1,nc2);
-	  dcount++;
-	}
-	nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
-	xmlAddChild(nc3,nc4);
-	j=0;
-	buff[j]=0;
-      }
-      i++;
-    }
-    if(strlen(buff)>0){
-      nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-      xmlAddChild(nc4,xmlNewText(BAD_CAST buff));	      
-      xmlAddChild(nc3,nc4);
-    }
-  }
-  xmlAddChild(nc1,nc3);
-  xmlAddChild(n,nc1);
-  
-  free(SERVICE_URL);
-  return nc;
-}
-
-/**
- * Add prefix to the service name.
- * 
- * @param conf the conf maps containing the main.cfg settings
- * @param level the map containing the level information
- * @param serv the service structure created from the zcfg file
- */
-void addPrefix(maps* conf,map* level,service* serv){
-  if(level!=NULL){
-    char key[25];
-    char* prefix=NULL;
-    int clevel=atoi(level->value);
-    int cl=0;
-    for(cl=0;cl<clevel;cl++){
-      sprintf(key,"sprefix_%d",cl);
-      map* tmp2=getMapFromMaps(conf,"lenv",key);
-      if(tmp2!=NULL){
-	if(prefix==NULL)
-	  prefix=zStrdup(tmp2->value);
-	else{
-	  int plen=strlen(prefix);
-	  prefix=(char*)realloc(prefix,(plen+strlen(tmp2->value)+2)*sizeof(char));
-	  memcpy(prefix+plen,tmp2->value,strlen(tmp2->value)*sizeof(char));
-	  prefix[plen+strlen(tmp2->value)]=0;
-	}
-      }
-    }
-    if(prefix!=NULL){
-      char* tmp0=strdup(serv->name);
-      free(serv->name);
-      serv->name=(char*)malloc((strlen(prefix)+strlen(tmp0)+1)*sizeof(char));
-      sprintf(serv->name,"%s%s",prefix,tmp0);
-      free(tmp0);
-      free(prefix);
-      prefix=NULL;
-    }
-  }
-}
-
-/**
- * Generate a wps:Process node for a servie and add it to a given node.
- * 
- * @param m the conf maps containing the main.cfg settings
- * @param registry the profile registry if any
- * @param nc the XML node to add the Process node
- * @param serv the service structure created from the zcfg file
- * @return the generated wps:ProcessOfferings xmlNodePtr 
- */
-void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
-  xmlNsPtr ns,ns_ows,ns_xlink;
-  xmlNodePtr n=NULL,nc1,nc2;
-  /**
-   * Initialize or get existing namspaces
-   */
-  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
-  ns=usedNs[wpsId];
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
-  int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
-  ns_xlink=usedNs[xlinkId];
-
-  map* tmp1;
-  if(serv->content!=NULL){
-    nc1 = xmlNewNode(ns, BAD_CAST "Process");
-    tmp1=getMap(serv->content,"processVersion");
-    if(tmp1!=NULL)
-      xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value);
-    else
-      xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST "1");
-    map* tmp3=getMapFromMaps(m,"lenv","level");
-    addPrefix(m,tmp3,serv);
-    printDescription(nc1,ns_ows,serv->name,serv->content);
-    tmp1=serv->metadata;
-    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);
-      tmp1=tmp1->next;
-    }
-    xmlAddChild(nc,nc1);
-  }
-}
-
-/**
- * Generate a ProcessDescription node for a servie and add it to a given node.
- * 
- * @param m the conf maps containing the main.cfg settings
- * @param nc the XML node to add the Process node
- * @param serv the servive structure created from the zcfg file
- * @return the generated wps:ProcessOfferings xmlNodePtr 
- */
-void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv){
-  xmlNsPtr ns,ns_ows,ns_xlink;
-  xmlNodePtr n,nc1;
-
-  n=nc;
-  
-  int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
-  ns=usedNs[wpsId];
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
-  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
-  ns_xlink=usedNs[xlinkId];
-
-  nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
-  const char *tmp4[3];
-  tmp4[0]="processVersion";
-  tmp4[1]="storeSupported";
-  tmp4[2]="statusSupported";
-  int j=0;
-  map* tmp1=NULL;
-  for(j=0;j<3;j++){
-    tmp1=getMap(serv->content,tmp4[j]);
-    if(tmp1!=NULL){
-      if(j==0)
-	xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value);      
-      else
-	xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value);      
-    }
-    else{
-      if(j>0)
-	xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "true");
-      else
-	xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST "1");
-    }
-  }
-  
-  tmp1=getMapFromMaps(m,"lenv","level");
-  addPrefix(m,tmp1,serv);
-  printDescription(nc,ns_ows,serv->name,serv->content);
-
-  tmp1=serv->metadata;
-  while(tmp1!=NULL){
-    nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-    xmlAddChild(nc,nc1);
-    tmp1=tmp1->next;
-  }
-
-  tmp1=getMap(serv->content,"Profile");
-  if(tmp1!=NULL){
-    nc1 = xmlNewNode(ns, BAD_CAST "Profile");
-    xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value));
-    xmlAddChild(nc,nc1);
-  }
-
-  if(serv->inputs!=NULL){
-    nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
-    elements* e=serv->inputs;
-    printFullDescription(1,e,"Input",ns_ows,nc1);
-    xmlAddChild(nc,nc1);
-  }
-
-  nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
-  elements* e=serv->outputs;
-  printFullDescription(0,e,"Output",ns_ows,nc1);
-  xmlAddChild(nc,nc1);
-
-  xmlAddChild(n,nc);
-
-}
-
-/**
- * Generate the required XML tree for the detailled metadata informations of 
- * inputs or outputs
- *
- * @param in 1 in case of inputs, 0 for outputs
- * @param elem the elements structure containing the metadata informations
- * @param type the name ("Input" or "Output") of the XML node to create
- * @param ns_ows the ows XML namespace
- * @param nc1 the XML node to use to add the created tree
- */
-void printFullDescription(int in,elements *elem,const char* type,xmlNsPtr ns_ows,xmlNodePtr nc1){
-  const char *orderedFields[13];
-  orderedFields[0]="mimeType";
-  orderedFields[1]="encoding";
-  orderedFields[2]="schema";
-  orderedFields[3]="dataType";
-  orderedFields[4]="uom";
-  orderedFields[5]="CRS";
-  orderedFields[6]="value";
-  orderedFields[7]="AllowedValues";
-  orderedFields[8]="range";
-  orderedFields[9]="rangeMin";
-  orderedFields[10]="rangeMax";
-  orderedFields[11]="rangeClosure";
-  orderedFields[12]="rangeSpace";
-
-  xmlNodePtr nc2,nc3,nc4,nc5,nc6,nc7,nc8,nc9;
-  elements* e=elem;
-
-  map* tmp1=NULL;
-  while(e!=NULL){
-    int default1=0;
-    int isAnyValue=1;
-    nc2 = xmlNewNode(NULL, BAD_CAST type);
-    if(strncmp(type,"Input",5)==0){
-      tmp1=getMap(e->content,"minOccurs");
-      if(tmp1!=NULL){
-	xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-      }else
-	xmlNewProp(nc2,BAD_CAST "minOccurs",BAD_CAST "0");
-      tmp1=getMap(e->content,"maxOccurs");
-      if(tmp1!=NULL){
-	if(strcasecmp(tmp1->value,"unbounded")!=0)
-	  xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-	else
-	  xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1000");
-      }else
-	xmlNewProp(nc2,BAD_CAST "maxOccurs",BAD_CAST "1");
-      if((tmp1=getMap(e->content,"maximumMegabytes"))!=NULL){
-	xmlNewProp(nc2,BAD_CAST "maximumMegabytes",BAD_CAST tmp1->value);
-      }
-    }
-
-    printDescription(nc2,ns_ows,e->name,e->content);
-
-    /**
-     * Build the (Literal/Complex/BoundingBox)Data node
-     */
-    if(strncmp(type,"Output",6)==0){
-      if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
-	nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput");
-      else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
-	nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput");
-      else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
-	nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxOutput");
-      else
-	nc3 = xmlNewNode(NULL, BAD_CAST e->format);
-    }else{
-      if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0){
-	nc3 = xmlNewNode(NULL, BAD_CAST "LiteralData");
-      }
-      else if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
-	nc3 = xmlNewNode(NULL, BAD_CAST "ComplexData");
-      else if(strncasecmp(e->format,"BOUNDINGBOXDATA",strlen(e->format))==0)
-	nc3 = xmlNewNode(NULL, BAD_CAST "BoundingBoxData");
-      else
-	nc3 = xmlNewNode(NULL, BAD_CAST e->format);
-    }
-
-    iotype* _tmp0=NULL;
-    iotype* _tmp=e->defaults;
-    int datatype=0;
-    bool hasUOM=false;
-    bool hasUOM1=false;
-    if(_tmp!=NULL){
-      if(strcmp(e->format,"LiteralOutput")==0 ||
-	 strcmp(e->format,"LiteralData")==0){
-     	datatype=1;
-	nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Default");
-      }
-      else if(strcmp(e->format,"BoundingBoxOutput")==0 ||
-	      strcmp(e->format,"BoundingBoxData")==0){
-	datatype=2;
-	nc5 = xmlNewNode(NULL, BAD_CAST "Default");
-      }
-      else{
-	nc4 = xmlNewNode(NULL, BAD_CAST "Default");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      }
-      
-      tmp1=_tmp->content;
-
-      if((tmp1=getMap(_tmp->content,"DataType"))!=NULL){
-	nc8 = xmlNewNode(ns_ows, BAD_CAST "DataType");
-	xmlAddChild(nc8,xmlNewText(BAD_CAST tmp1->value));
-	char tmp[1024];
-	sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
-	xmlNewNsProp(nc8,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
-	xmlAddChild(nc3,nc8);
-	datatype=1;
-      }
-
-      if(strncmp(type,"Input",5)==0){
-
-	if((tmp1=getMap(_tmp->content,"AllowedValues"))!=NULL){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
-	  char *token,*saveptr1;
-	  token=strtok_r(tmp1->value,",",&saveptr1);
-	  while(token!=NULL){
-	    nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	    char *tmps=strdup(token);
-	    tmps[strlen(tmps)]=0;
-	    xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
-	    free(tmps);
-	    xmlAddChild(nc6,nc7);
-	    token=strtok_r(NULL,",",&saveptr1);
-	  }
-	  if(getMap(_tmp->content,"range")!=NULL ||
-	     getMap(_tmp->content,"rangeMin")!=NULL ||
-	     getMap(_tmp->content,"rangeMax")!=NULL ||
-	     getMap(_tmp->content,"rangeClosure")!=NULL )
-	    goto doRange;
-	  xmlAddChild(nc3,nc6);
-	  isAnyValue=-1;
-	}
-
-        tmp1=getMap(_tmp->content,"range");
-	if(tmp1==NULL)
-	  tmp1=getMap(_tmp->content,"rangeMin");
-	if(tmp1==NULL)
-	  tmp1=getMap(_tmp->content,"rangeMax");
-	
-	if(tmp1!=NULL && isAnyValue==1){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
-	doRange:
-	  
-	  /**
-	   * Range: Table 46 OGC Web Services Common Standard
-	   */
-	  nc8 = xmlNewNode(ns_ows, BAD_CAST "Range");
-	  
-	  map* tmp0=getMap(tmp1,"range");
-	  if(tmp0!=NULL){
-	    char* pToken;
-	    char* orig=zStrdup(tmp0->value);
-	    /**
-	     * RangeClosure: Table 47 OGC Web Services Common Standard
-	     */
-	    const char *tmp="closed";
-	    if(orig[0]=='[' && orig[strlen(orig)-1]=='[')
-	      tmp="closed-open";
-	    else
-	      if(orig[0]==']' && orig[strlen(orig)-1]==']')
-		tmp="open-closed";
-	      else
-		if(orig[0]==']' && orig[strlen(orig)-1]=='[')
-		  tmp="open";
-	    xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
-	    pToken=strtok(orig,",");
-	    int nci0=0;
-	    while(pToken!=NULL){
-	      char *tmpStr=(char*) malloc((strlen(pToken))*sizeof(char));
-	      if(nci0==0){
-		nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
-		strncpy( tmpStr, pToken+1, strlen(pToken)-1 );
-		tmpStr[strlen(pToken)-1] = '\0';
-	      }else{
-		nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
-		const char* bkt;
-		if ( ( bkt = strchr(pToken, '[') ) != NULL || ( bkt = strchr(pToken, ']') ) != NULL ){
-		  strncpy( tmpStr, pToken, bkt - pToken );
-		  tmpStr[bkt - pToken] = '\0';
-		}
-	      }
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST tmpStr));
-	      free(tmpStr);
-	      xmlAddChild(nc8,nc7);
-	      nci0++;
-	      pToken = strtok(NULL,",");
-	    }		    
-	    if(getMap(tmp1,"rangeSpacing")==NULL){
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST "1"));
-	      xmlAddChild(nc8,nc7);
-	    }
-	    free(orig);
-	  }else{
-	    
-	    tmp0=getMap(tmp1,"rangeMin");
-	    if(tmp0!=NULL){
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
-	      xmlAddChild(nc8,nc7);
-	    }else{
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "MinimumValue");
-	      xmlAddChild(nc8,nc7);
-	    }
-	    tmp0=getMap(tmp1,"rangeMax");
-	    if(tmp0!=NULL){
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
-	      xmlAddChild(nc8,nc7);
-	    }else{
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "MaximumValue");
-	      xmlAddChild(nc8,nc7);
-	    }
-	    tmp0=getMap(tmp1,"rangeSpacing");
-	    if(tmp0!=NULL){
-	      nc7 = xmlNewNode(ns_ows, BAD_CAST "Spacing");
-	      xmlAddChild(nc7,xmlNewText(BAD_CAST tmp0->value));
-	      xmlAddChild(nc8,nc7);
-	    }
-	    tmp0=getMap(tmp1,"rangeClosure");
-	    if(tmp0!=NULL){
-	      const char *tmp="closed";
-	      if(strcasecmp(tmp0->value,"co")==0)
-		tmp="closed-open";
-	      else
-		if(strcasecmp(tmp0->value,"oc")==0)
-		  tmp="open-closed";
-		else
-		  if(strcasecmp(tmp0->value,"o")==0)
-		    tmp="open";
-	      xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST tmp);
-	    }else
-	      xmlNewNsProp(nc8,ns_ows,BAD_CAST "rangeClosure",BAD_CAST "closed");
-	  }
-	  if(_tmp0==NULL){
-	    xmlAddChild(nc6,nc8);
-	    _tmp0=e->supported;
-	    if(_tmp0!=NULL &&
-	       (getMap(_tmp0->content,"range")!=NULL ||
-		getMap(_tmp0->content,"rangeMin")!=NULL ||
-		getMap(_tmp0->content,"rangeMax")!=NULL ||
-		getMap(_tmp0->content,"rangeClosure")!=NULL )){
-	      tmp1=_tmp0->content;
-	      goto doRange;
-	    }
-	  }else{
-	    _tmp0=_tmp0->next;
-	    if(_tmp0!=NULL){
-	      xmlAddChild(nc6,nc8);
-	      if(getMap(_tmp0->content,"range")!=NULL ||
-		 getMap(_tmp0->content,"rangeMin")!=NULL ||
-		 getMap(_tmp0->content,"rangeMax")!=NULL ||
-		 getMap(_tmp0->content,"rangeClosure")!=NULL ){
-		tmp1=_tmp0->content;
-		goto doRange;
-	      }
-	    }
-	  }
-	  xmlAddChild(nc6,nc8);
-	  xmlAddChild(nc3,nc6);
-	  isAnyValue=-1;
-	}
-	
-      }
-      
-      int oI=0;
-      for(oI=0;oI<13;oI++)
-	if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
-#ifdef DEBUG
-	  printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
-#endif
-	  if(strcmp(tmp1->name,"asReference")!=0 &&
-	     strncasecmp(tmp1->name,"DataType",8)!=0 &&
-	     strcasecmp(tmp1->name,"extension")!=0 &&
-	     strcasecmp(tmp1->name,"value")!=0 &&
-	     strcasecmp(tmp1->name,"AllowedValues")!=0 &&
-	     strncasecmp(tmp1->name,"range",5)!=0){
-	    if(datatype!=1){
-	      char *tmp2=zCapitalize1(tmp1->name);
-	      nc9 = xmlNewNode(NULL, BAD_CAST tmp2);
-	      free(tmp2);
-	    }
-	    else{
-	      char *tmp2=zCapitalize(tmp1->name);
-	      nc9 = xmlNewNode(ns_ows, BAD_CAST tmp2);
-	      free(tmp2);
-	    }
-	    xmlAddChild(nc9,xmlNewText(BAD_CAST tmp1->value));
-	    xmlAddChild(nc5,nc9);
-	    if(strcasecmp(tmp1->name,"uom")==0)
-	      hasUOM1=true;
-	    hasUOM=true;
-	  }else 
-	  
-	    tmp1=tmp1->next;
-	}
-    
-    
-      if(datatype!=2){
-	if(hasUOM==true){
-	  xmlAddChild(nc4,nc5);
-	  xmlAddChild(nc3,nc4);
-	}else{
-	  if(hasUOM1==false){
-	    xmlFreeNode(nc5);
-	    if(datatype==1)
-	      xmlFreeNode(nc4);
-	  }
-	}
-      }else{
-	xmlAddChild(nc3,nc5);
-      }
-      
-      if(datatype!=1 && default1<0){
-	xmlFreeNode(nc5);
-	if(datatype!=2)
-	  xmlFreeNode(nc4);
-      }
-
-      map* metadata=e->metadata;
-      xmlNodePtr n=NULL;
-      int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
-      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;
-      }
-
-    }
-
-    _tmp=e->supported;
-    if(_tmp==NULL && datatype!=1)
-      _tmp=e->defaults;
-
-    int hasSupported=-1;
-
-    while(_tmp!=NULL){
-      if(hasSupported<0){
-	if(datatype==0){
-	  nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
-	  nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-	}
-	else
-	  nc5 = xmlNewNode(NULL, BAD_CAST "Supported");
-	hasSupported=0;
-      }else
-	if(datatype==0)
-	  nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      tmp1=_tmp->content;
-      int oI=0;
-      for(oI=0;oI<6;oI++)
-	if((tmp1=getMap(_tmp->content,orderedFields[oI]))!=NULL){
-#ifdef DEBUG
-	  printf("DATATYPE SUPPORTED ? %s\n",tmp1->name);
-#endif
-	  if(strcmp(tmp1->name,"asReference")!=0 && 
-	     strcmp(tmp1->name,"value")!=0 && 
-	     strcmp(tmp1->name,"DataType")!=0 &&
-	     strcasecmp(tmp1->name,"extension")!=0){
-	    if(datatype!=1){
-	      char *tmp2=zCapitalize1(tmp1->name);
-	      nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
-	      free(tmp2);
-	    }
-	    else{
-	      char *tmp2=zCapitalize(tmp1->name);
-	      nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
-	      free(tmp2);
-	    }
-	    if(datatype==2){
-	      char *tmpv,*tmps;
-	      tmps=strtok_r(tmp1->value,",",&tmpv);
-	      while(tmps){
-		xmlAddChild(nc6,xmlNewText(BAD_CAST tmps));
-		tmps=strtok_r(NULL,",",&tmpv);
-		if(tmps){
-		  char *tmp2=zCapitalize1(tmp1->name);
-		  nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
-		  free(tmp2);
-		}
-	      }
-	    }
-	    else{
-	      xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	    }
-	    xmlAddChild(nc5,nc6);
-	  }
-	  tmp1=tmp1->next;
-	}
-      if(hasSupported<=0){
-	if(datatype==0){
-	  xmlAddChild(nc4,nc5);
-	  xmlAddChild(nc3,nc4);
-	}else{
-	  if(datatype!=1)
-	    xmlAddChild(nc3,nc5);
-	}
-	hasSupported=1;
-      }
-      else
-	if(datatype==0){
-	  xmlAddChild(nc4,nc5);
-	  xmlAddChild(nc3,nc4);
-	}
-	else
-	  if(datatype!=1)
-	    xmlAddChild(nc3,nc5);
-
-      _tmp=_tmp->next;
-    }
-
-    if(hasSupported==0){
-      if(datatype==0)
-	xmlFreeNode(nc4);
-      xmlFreeNode(nc5);
-    }
-
-    _tmp=e->defaults;
-    if(datatype==1 && hasUOM1==true){
-      xmlAddChild(nc4,nc5);
-      xmlAddChild(nc3,nc4);
-    }
-
-    if(in>0 && datatype==1 &&
-       getMap(_tmp->content,"AllowedValues")==NULL &&
-       getMap(_tmp->content,"range")==NULL &&
-       getMap(_tmp->content,"rangeMin")==NULL &&
-       getMap(_tmp->content,"rangeMax")==NULL &&
-       getMap(_tmp->content,"rangeClosure")==NULL ){
-      tmp1=getMap(_tmp->content,"dataType");
-      if(tmp1!=NULL && strcasecmp(tmp1->value,"boolean")==0){
-	nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
-	nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	xmlAddChild(nc7,xmlNewText(BAD_CAST "true"));
-	xmlAddChild(nc6,nc7);
-	nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
-	xmlAddChild(nc7,xmlNewText(BAD_CAST "false"));
-	xmlAddChild(nc6,nc7);
-	xmlAddChild(nc3,nc6);
-      }
-      else
-	xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
-    }
-    
-    if(_tmp!=NULL && (tmp1=getMap(_tmp->content,"value"))!=NULL){
-      nc7 = xmlNewNode(NULL, BAD_CAST "DefaultValue");
-      xmlAddChild(nc7,xmlNewText(BAD_CAST tmp1->value));
-      xmlAddChild(nc3,nc7);
-    }
-    
-    xmlAddChild(nc2,nc3);
-    
-    xmlAddChild(nc1,nc2);
-    
-    e=e->next;
-  }
-}
-
-/**
- * Generate a wps:Execute XML document.
- * 
- * @param m the conf maps containing the main.cfg settings
- * @param request the map representing the HTTP request
- * @param pid the process identifier linked to a service
- * @param serv the serv structure created from the zcfg file
- * @param service the service name
- * @param status the status returned by the service
- * @param inputs the inputs provided
- * @param outputs the outputs generated by the service
- */
-void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs){
-  xmlNsPtr ns,ns_ows,ns_xlink;
-  xmlNodePtr nr,n,nc,nc1=NULL,nc3;
-  xmlDocPtr doc;
-  time_t time1;  
-  time(&time1);
-  nr=NULL;
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  n = printWPSHeader(doc,m,"Execute","ExecuteResponse");
-  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
-  ns=usedNs[wpsId];
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
-  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
-  ns_xlink=usedNs[xlinkId];
-
-  char tmp[256];
-  char url[1024];
-  char stored_path[1024];
-  memset(tmp,0,256);
-  memset(url,0,1024);
-  memset(stored_path,0,1024);
-  maps* tmp_maps=getMaps(m,"main");
-  if(tmp_maps!=NULL){
-    map* tmpm1=getMap(tmp_maps->content,"serverAddress");
-    /**
-     * Check if the ZOO Service GetStatus is available in the local directory.
-     * If yes, then it uses a reference to an URL which the client can access
-     * to get information on the status of a running Service (using the 
-     * percentCompleted attribute). 
-     * Else fallback to the initial method using the xml file to write in ...
-     */
-    char ntmp[1024];
-#ifndef WIN32
-    getcwd(ntmp,1024);
-#else
-    _getcwd(ntmp,1024);
-#endif
-    struct stat myFileInfo;
-    int statRes;
-    char file_path[1024];
-    sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
-    statRes=stat(file_path,&myFileInfo);
-    if(statRes==0){
-      char currentSid[128];
-      map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
-      map *tmp_lenv=NULL;
-      tmp_lenv=getMapFromMaps(m,"lenv","usid");
-      if(tmp_lenv==NULL)
-	sprintf(currentSid,"%i",pid);
-      else
-	sprintf(currentSid,"%s",tmp_lenv->value);
-      if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
-	sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
-      }else{
-	if(strlen(tmpm->value)>0)
-	  if(strcasecmp(tmpm->value,"true")!=0)
-	    sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
-	  else
-	    sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
-	else
-	  sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
-      }
-    }else{
-      int lpid;
-      map* tmpm2=getMapFromMaps(m,"lenv","usid");
-      lpid=atoi(tmpm2->value);
-      tmpm2=getMap(tmp_maps->content,"tmpUrl");
-      if(tmpm1!=NULL && tmpm2!=NULL){
-	if( strncasecmp( tmpm2->value, "http://", 7) == 0 ||
-	    strncasecmp( tmpm2->value, "https://", 8 ) == 0 ){
-	  sprintf(url,"%s/%s_%i.xml",tmpm2->value,service,lpid);
-	}else
-	  sprintf(url,"%s/%s/%s_%i.xml",tmpm1->value,tmpm2->value,service,lpid);
-      }
-    }
-    if(tmpm1!=NULL)
-      sprintf(tmp,"%s",tmpm1->value);
-    int lpid;
-    tmpm1=getMapFromMaps(m,"lenv","usid");
-    lpid=atoi(tmpm1->value);
-    tmpm1=getMapFromMaps(m,"main","TmpPath");
-    sprintf(stored_path,"%s/%s_%i.xml",tmpm1->value,service,lpid);
-  }
-
-
-
-  xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
-  map* test=getMap(request,"storeExecuteResponse");
-  bool hasStoredExecuteResponse=false;
-  if(test!=NULL && strcasecmp(test->value,"true")==0){
-    xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
-    hasStoredExecuteResponse=true;
-  }
-
-  nc = xmlNewNode(ns, BAD_CAST "Process");
-  map* tmp2=getMap(serv->content,"processVersion");
-  if(tmp2!=NULL)
-    xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
-  
-  map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
-  printDescription(nc,ns_ows,tmpI->value,serv->content);
-
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns, BAD_CAST "Status");
-  const struct tm *tm;
-  size_t len;
-  time_t now;
-  char *tmp1;
-  map *tmpStatus;
-  
-  now = time ( NULL );
-  tm = localtime ( &now );
-
-  tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
-
-  len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
-
-  xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-
-  char sMsg[2048];
-  switch(status){
-  case SERVICE_SUCCEEDED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
-    sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_STARTED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
-    tmpStatus=getMapFromMaps(m,"lenv","status");
-    xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
-    sprintf(sMsg,_("The ZOO service \"%s\" is currently running. Please reload this document to get the up-to-date status of the service."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_ACCEPTED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
-    sprintf(sMsg,_("The service \"%s\" was accepted by the ZOO kernel and is running as a background task. Please access the URL in the statusLocation attribute provided in this document to get the up-to-date status and results."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_FAILED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
-    map *errorMap;
-    map *te;
-    te=getMapFromMaps(m,"lenv","code");
-    if(te!=NULL)
-      errorMap=createMap("code",te->value);
-    else
-      errorMap=createMap("code","NoApplicableCode");
-    te=getMapFromMaps(m,"lenv","message");
-    if(te!=NULL)
-      addToMap(errorMap,"text",_ss(te->value));
-    else
-      addToMap(errorMap,"text",_("No more information available"));
-    nc3=createExceptionReportNode(m,errorMap,0);
-    freeMap(&errorMap);
-    free(errorMap);
-    xmlAddChild(nc1,nc3);
-    break;
-  default :
-    printf(_("error code not know : %i\n"),status);
-    //exit(1);
-    break;
-  }
-  xmlAddChild(nc,nc1);
-  xmlAddChild(n,nc);
-  free(tmp1);
-
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 161\n");
-#endif
-
-  map* lineage=getMap(request,"lineage");
-  if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
-    nc = xmlNewNode(ns, BAD_CAST "DataInputs");
-    maps* mcursor=inputs;
-    elements* scursor=NULL;
-    while(mcursor!=NULL /*&& scursor!=NULL*/){
-      scursor=getElements(serv->inputs,mcursor->name);
-      printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input");
-      mcursor=mcursor->next;
-    }
-    xmlAddChild(n,nc);
-    
-#ifdef DEBUG
-    fprintf(stderr,"printProcessResponse 1 177\n");
-#endif
-
-    nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
-    mcursor=outputs;
-    scursor=NULL;
-    while(mcursor!=NULL){
-      scursor=getElements(serv->outputs,mcursor->name);
-      printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-      mcursor=mcursor->next;
-    }
-    xmlAddChild(n,nc);
-  }
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 190\n");
-#endif
-
-  /**
-   * Display the process output only when requested !
-   */
-  if(status==SERVICE_SUCCEEDED){
-    nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
-    maps* mcursor=outputs;
-    elements* scursor=serv->outputs;
-    map* testResponse=getMap(request,"RawDataOutput");
-    if(testResponse==NULL)
-      testResponse=getMap(request,"ResponseDocument");
-    while(mcursor!=NULL){
-      map* tmp0=getMap(mcursor->content,"inRequest");
-      scursor=getElements(serv->outputs,mcursor->name);
-      if(scursor!=NULL){
-	if(testResponse==NULL || tmp0==NULL)
-	  printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
-	else
-	  if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0)
-	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
-      }else
-	/**
-	 * In case there was no definition found in the ZCFG file but 
-	 * present in the service code
-	 */
-	printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
-      mcursor=mcursor->next;
-    }
-    xmlAddChild(n,nc);
-  }
-
-  if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED){
-    semid lid=getShmLockId(m,1);
-    if(lid<0){
-      /* If the lock failed */
-      errorException(m,_("Lock failed."),"InternalError",NULL);
-      xmlFreeDoc(doc);
-      xmlCleanupParser();
-      zooXmlCleanupNs();
-      return;
-    }
-    else{
-#ifdef DEBUG
-      fprintf(stderr,"LOCK %s %d !\n",__FILE__,__LINE__);
-#endif
-      lockShm(lid);
-      /* We need to write the ExecuteResponse Document somewhere */
-      FILE* output=fopen(stored_path,"w");
-      if(output==NULL){
-	/* If the file cannot be created return an ExceptionReport */
-	char tmpMsg[1024];
-	sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
-
-	errorException(m,tmpMsg,"InternalError",NULL);
-	xmlFreeDoc(doc);
-	xmlCleanupParser();
-	zooXmlCleanupNs();
-	unlockShm(lid);
-	return;
-      }
-      xmlChar *xmlbuff;
-      int buffersize;
-      xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "UTF-8", 1);
-      fwrite(xmlbuff,1,xmlStrlen(xmlbuff)*sizeof(char),output);
-      xmlFree(xmlbuff);
-      fclose(output);
-#ifdef DEBUG
-      fprintf(stderr,"UNLOCK %s %d !\n",__FILE__,__LINE__);
-#endif
-      unlockShm(lid);
-      map* test1=getMap(request,"status");
-      if(test1==NULL || strcasecmp(test1->value,"true")!=0){
-	removeShmLock(m,1);
-      }
-    }
-  }
-  printDocument(m,doc,pid);
-
-  xmlCleanupParser();
-  zooXmlCleanupNs();
-}
-
-/**
- * Print a XML document.
- * 
- * @param m the conf maps containing the main.cfg settings
- * @param doc the XML document
- * @param pid the process identifier linked to a service
- */
-void printDocument(maps* m, xmlDocPtr doc,int pid){
-  char *encoding=getEncoding(m);
-  if(pid==getpid()){
-    printHeaders(m);
-    printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
-  }
-  fflush(stdout);
-  xmlChar *xmlbuff;
-  int buffersize;
-  /*
-   * Dump the document to a buffer and print it on stdout
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  printf("%s",xmlbuff);
-  fflush(stdout);
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  xmlFreeDoc(doc);
-  xmlCleanupParser();
-  zooXmlCleanupNs();
-}
-
-/**
- * Print a XML document.
- * 
- * @param doc the XML document (unused)
- * @param nc the XML node to add the output definition
- * @param ns_wps the wps XML namespace
- * @param ns_ows the ows XML namespace
- * @param e the output elements 
- * @param m the conf maps containing the main.cfg settings
- * @param type the type (unused)
- */
-void printOutputDefinitions(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,const char* type){
-  xmlNodePtr nc1;
-  nc1=xmlNewNode(ns_wps, BAD_CAST type);
-  map *tmp=NULL;  
-  if(e!=NULL && e->defaults!=NULL)
-    tmp=e->defaults->content;
-  else{
-    /*
-    dumpElements(e);
-    */
-    return;
-  }
-  while(tmp!=NULL){
-    if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0
-       || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0
-       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
-       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
-    xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
-    tmp=tmp->next;
-  }
-  tmp=getMap(e->defaults->content,"asReference");
-  if(tmp==NULL)
-    xmlNewProp(nc1,BAD_CAST "asReference",BAD_CAST "false");
-
-  tmp=e->content;
-
-  printDescription(nc1,ns_ows,m->name,e->content);
-
-  xmlAddChild(nc,nc1);
-
-}
-
-/**
- * Generate XML nodes describing inputs or outputs metadata.
- * 
- * @param doc the XML document 
- * @param nc the XML node to add the definition
- * @param ns_wps the wps namespace
- * @param ns_ows the ows namespace
- * @param ns_xlink the xlink namespace
- * @param e the output elements 
- * @param m the conf maps containing the main.cfg settings
- * @param type the type
- */
-void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){
-
-  xmlNodePtr nc1,nc2,nc3;
-  nc1=xmlNewNode(ns_wps, BAD_CAST type);
-  map *tmp=NULL;
-  if(e!=NULL)
-    tmp=e->content;
-  else
-    tmp=m->content;
-
-  nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
-  if(e!=NULL)
-    nc3=xmlNewText(BAD_CAST e->name);
-  else
-    nc3=xmlNewText(BAD_CAST m->name);
-
-  xmlAddChild(nc2,nc3);
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-  if(e!=NULL)
-    tmp=getMap(e->content,"Title");
-  else
-    tmp=getMap(m->content,"Title");
-  
-  if(tmp!=NULL){
-    nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-    nc3=xmlNewText(BAD_CAST _ss(tmp->value));
-    xmlAddChild(nc2,nc3);  
-    xmlAddChild(nc1,nc2);
-  }
-
-  if(e!=NULL)
-    tmp=getMap(e->content,"Abstract");
-  else
-    tmp=getMap(m->content,"Abstract");
-
-  if(tmp!=NULL){
-    nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-    nc3=xmlNewText(BAD_CAST _ss(tmp->value));
-    xmlAddChild(nc2,nc3);  
-    xmlAddChild(nc1,nc2);
-    xmlAddChild(nc,nc1);
-  }
-
-  /**
-   * IO type Reference or full Data ?
-   */
-  map *tmpMap=getMap(m->content,"Reference");
-  if(tmpMap==NULL){
-    nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
-    if(e!=NULL){
-      if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
-	nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
-      else
-        if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
-	  nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
-	else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
-	  nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
-	else
-	  nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
-    }
-    else {
-      map* tmpV=getMapFromMaps(m,"format","value");
-      if(tmpV!=NULL)
-	nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
-      else
-	nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
-    } 
-    tmp=m->content;
-
-    while(tmp!=NULL){
-      if(strcasecmp(tmp->name,"mimeType")==0 ||
-	 strcasecmp(tmp->name,"encoding")==0 ||
-	 strcasecmp(tmp->name,"schema")==0 ||
-	 strcasecmp(tmp->name,"datatype")==0 ||
-	 strcasecmp(tmp->name,"uom")==0) {
-
-	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
-      }
-      tmp=tmp->next;
-      xmlAddChild(nc2,nc3);
-    }
-    if(e!=NULL && e->format!=NULL && strcasecmp(e->format,"BoundingBoxData")==0) {
-      map* bb=getMap(m->content,"value");
-      if(bb!=NULL) {
-	map* tmpRes=parseBoundingBox(bb->value);
-	printBoundingBox(ns_ows,nc3,tmpRes);
-	freeMap(&tmpRes);
-	free(tmpRes);
-      }
-    }
-    else {
-      if(e!=NULL)
-	tmp=getMap(e->defaults->content,"mimeType");
-      else
-	tmp=NULL;
-	
-      map* tmp1=getMap(m->content,"encoding");
-      map* tmp2=getMap(m->content,"mimeType");
-      map* tmp3=getMap(m->content,"value");
-      int hasValue=1;
-      if(tmp3==NULL){
-	tmp3=createMap("value","");
-	hasValue=-1;
-      }
-
-      if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
-	  || 	                                                       // or if 
-	  ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text 
-			      &&                                       //  nor 
-			      strstr(tmp2->value,"xml") == NULL        //  xml
-			      &&                                       // nor
-			      strstr(tmp2->value,"javascript") == NULL // javascript
-			      &&
-			      strstr(tmp2->value,"json") == NULL
-			      &&
-			      strstr(tmp2->value,"ecmascript") == NULL
-			      &&
-			      // include for backwards compatibility,
-			      // although correct mime type is ...kml+xml:
-			      strstr(tmp2->value,"google-earth.kml") == NULL							)
-	    )
-	  ) { 	                                                 // then	
-	map* rs=getMap(m->content,"size");                       // obtain size
-	bool isSized=true;
-	if(rs==NULL){
-	  char tmp1[1024];
-	  sprintf(tmp1,"%ld",strlen(tmp3->value));
-	  rs=createMap("size",tmp1);
-	  isSized=false;
-	}
-	 
-	xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
-		
-	if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
-	  xmlAttrPtr ap = xmlHasProp(nc3, BAD_CAST "encoding");
-	  if (ap != NULL) {
-	    xmlRemoveProp(ap);
-	  }			
-	  xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64");
-	}
-		
-	if(!isSized){
-	  freeMap(&rs);
-	  free(rs);
-	}
-      }
-      else if (tmp2!=NULL) {                                 // else (text-based format) 
-	if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block 
-	   strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader) 
-	   strstr(tmp2->value, "ecmascript") != NULL
-	   ) {
-	  xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
-	}   
-	else {                                                     // else
-	  if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
-	      // include for backwards compatibility,
-	      // although correct mime type is ...kml+xml:		   
-	      strstr(tmp2->value, "google-earth.kml") != NULL
-	      ) { 
-			  
-	    int li=zooXmlAddDoc(tmp3->value);
-	    xmlDocPtr doc = iDocs[li];
-	    xmlNodePtr ir = xmlDocGetRootElement(doc);
-	    xmlAddChild(nc3,ir);
-	  }
-	  else                                                     // else	
-	    xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));    //   add text node
-	}
-	xmlAddChild(nc2,nc3);
-      }
-      else {
-	xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));
-      }
-	  
-      if(hasValue<0) {
-	freeMap(&tmp3);
-	free(tmp3);
-      }
-    }
-  }
-  else { // Reference
-    tmpMap=getMap(m->content,"Reference");
-    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
-    if(strcasecmp(type,"Output")==0)
-      xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
-    else
-      xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
-    
-    tmp=m->content;
-    while(tmp!=NULL) {
-      if(strcasecmp(tmp->name,"mimeType")==0 ||
-	 strcasecmp(tmp->name,"encoding")==0 ||
-	 strcasecmp(tmp->name,"schema")==0 ||
-	 strcasecmp(tmp->name,"datatype")==0 ||
-	 strcasecmp(tmp->name,"uom")==0){
-
-	if(strcasecmp(tmp->name,"datatype")==0)
-	  xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
-	else
-	  xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
-      }
-      tmp=tmp->next;
-      xmlAddChild(nc2,nc3);
-    }
-  }
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-}
-
-/**
- * Create XML node with basic ows metadata informations (Identifier,Title,Abstract)
- *
- * @param root the root XML node to add the description
- * @param ns_ows the ows XML namespace
- * @param identifier the identifier to use
- * @param amap the map containing the ows metadata informations 
- */
-void printDescription(xmlNodePtr root,xmlNsPtr ns_ows,const char* identifier,map* amap){
-  xmlNodePtr nc2 = xmlNewNode(ns_ows, BAD_CAST "Identifier");
-  
-  xmlAddChild(nc2,xmlNewText(BAD_CAST identifier));
-  xmlAddChild(root,nc2);
-  map* tmp=amap;
-  const char *tmp2[2];
-  tmp2[0]="Title";
-  tmp2[1]="Abstract";
-  int j=0;
-  for(j=0;j<2;j++){
-    map* tmp1=getMap(tmp,tmp2[j]);
-    if(tmp1!=NULL){
-      nc2 = xmlNewNode(ns_ows, BAD_CAST tmp2[j]);
-      xmlAddChild(nc2,xmlNewText(BAD_CAST _ss(tmp1->value)));
-      xmlAddChild(root,nc2);
-    }
-  }
-}
-
-/**
- * Access the value of the encoding key in a maps
- *
- * @param m the maps to search for the encoding key
- * @return the value of the encoding key in a maps if encoding key exists,
- *  "UTF-8" in other case.
- */
-char* getEncoding(maps* m){
-  if(m!=NULL){
-    map* tmp=getMap(m->content,"encoding");
-    if(tmp!=NULL){
-      return tmp->value;
-    }
-    else
-      return (char*)"UTF-8";
-  }
-  else
-    return (char*)"UTF-8";  
-}
-
-/**
- * Access the value of the version key in a maps
- *
- * @param m the maps to search for the version key
- * @return the value of the version key in a maps if encoding key exists,
- *  "1.0.0" in other case.
- */
-char* getVersion(maps* m){
-  if(m!=NULL){
-    map* tmp=getMap(m->content,"version");
-    if(tmp!=NULL){
-      return tmp->value;
-    }
-    else
-      return (char*)"1.0.0";
-  }
-  else
-    return (char*)"1.0.0";
-}
-
-/**
- * Print an OWS ExceptionReport Document and HTTP headers (when required) 
- * depending on the code.
- * Set hasPrinted value to true in the [lenv] section.
- * 
- * @param m the maps containing the settings of the main.cfg file
- * @param s the map containing the text,code,locator keys
- */
-void printExceptionReportResponse(maps* m,map* s){
-  if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
-    return;
-  int buffersize;
-  xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  xmlNodePtr n;
-
-  zooXmlCleanupNs();
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  maps* tmpMap=getMaps(m,"main");
-  char *encoding=getEncoding(tmpMap);
-  const char *exceptionCode;
-  
-  map* tmp=getMap(s,"code");
-  if(tmp!=NULL){
-    if(strcmp(tmp->value,"OperationNotSupported")==0 ||
-       strcmp(tmp->value,"NoApplicableCode")==0)
-      exceptionCode="501 Not Implemented";
-    else
-      if(strcmp(tmp->value,"MissingParameterValue")==0 ||
-	 strcmp(tmp->value,"InvalidUpdateSequence")==0 ||
-	 strcmp(tmp->value,"OptionNotSupported")==0 ||
-	 strcmp(tmp->value,"VersionNegotiationFailed")==0 ||
-	 strcmp(tmp->value,"InvalidParameterValue")==0)
-	exceptionCode="400 Bad request";
-      else
-	exceptionCode="501 Internal Server Error";
-  }
-  else
-    exceptionCode="501 Internal Server Error";
-
-  if(m!=NULL){
-    map *tmpSid=getMapFromMaps(m,"lenv","sid");
-    if(tmpSid!=NULL){
-      if( getpid()==atoi(tmpSid->value) ){
-	printHeaders(m);
-	printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
-      }
-    }
-    else{
-      printHeaders(m);
-      printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
-    }
-  }else{
-    printf("Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding,exceptionCode);
-  }
-  n=createExceptionReportNode(m,s,1);
-  xmlDocSetRootElement(doc, n);
-  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  printf("%s",xmlbuff);
-  fflush(stdout);
-  xmlFreeDoc(doc);
-  xmlFree(xmlbuff);
-  xmlCleanupParser();
-  zooXmlCleanupNs();
-  if(m!=NULL)
-    setMapInMaps(m,"lenv","hasPrinted","true");
-}
-
-/**
- * Create an OWS ExceptionReport Node.
- * 
- * @param m the conf maps
- * @param s the map containing the text,code,locator keys
- * @param use_ns (0/1) choose if you want to generate an ExceptionReport or 
- *  ows:ExceptionReport node respectively
- * @return the ExceptionReport/ows:ExceptionReport node
- */
-xmlNodePtr createExceptionReportNode(maps* m,map* s,int use_ns){
-  
-  xmlNsPtr ns,ns_xsi;
-  xmlNodePtr n,nc,nc1;
-
-  int nsid=zooXmlAddNs(NULL,"http://www.opengis.net/ows","ows");
-  ns=usedNs[nsid];
-  if(use_ns==0){
-    ns=NULL;
-  }
-  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
-  if(use_ns==1){
-    xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST"ows");
-    int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
-    ns_xsi=usedNs[xsiId];
-    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");
-  }
-
-
-  addLangAttr(n,m);
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0");
-  
-  int length=1;
-  int cnt=0;
-  map* len=getMap(s,"length");
-  if(len!=NULL)
-    length=atoi(len->value);
-  for(cnt=0;cnt<length;cnt++){
-    nc = xmlNewNode(ns, BAD_CAST "Exception");
-    
-    map* tmp=getMapArray(s,"code",cnt);
-    if(tmp==NULL)
-      tmp=getMap(s,"code");
-    if(tmp!=NULL)
-      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST tmp->value);
-    else
-      xmlNewProp(nc,BAD_CAST "exceptionCode",BAD_CAST "NoApplicableCode");
-    
-    tmp=getMapArray(s,"locator",cnt);
-    if(tmp==NULL)
-      tmp=getMap(s,"locator");
-    if(tmp!=NULL && strcasecmp(tmp->value,"NULL")!=0)
-      xmlNewProp(nc,BAD_CAST "locator",BAD_CAST tmp->value);
-
-    tmp=getMapArray(s,"text",cnt);
-    nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
-    if(tmp!=NULL){
-      xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
-      xmlAddChild(nc1,txt);
-    }
-    else{
-      xmlNodeSetContent(nc1, BAD_CAST _("No debug message available"));
-    }
-    xmlAddChild(nc,nc1);
-    xmlAddChild(n,nc);
-  }
-  return n;
-}
-
-/**
- * Print an OWS ExceptionReport.
- * 
- * @param m the conf maps
- * @param message the error message 
- * @param errorcode the error code
- * @param locator the potential locator
- */
-int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 
-{
-  map* errormap = createMap("text", message);
-  addToMap(errormap,"code", errorcode);
-  if(locator!=NULL)
-    addToMap(errormap,"locator", locator);
-  else
-    addToMap(errormap,"locator", "NULL");
-  printExceptionReportResponse(m,errormap);
-  freeMap(&errormap);
-  free(errormap);
-  return -1;
-}
-
-/**
- * Read a file generated by a service.
- * 
- * @param m the conf maps
- * @param content the output item
- * @param filename the file to read
- */
-void readGeneratedFile(maps* m,map* content,char* filename){
-  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 ;
-  }
-  fseek(file, 0, SEEK_END);
-  long count = ftell(file);
-  rewind(file);
-  struct stat file_status; 
-  stat(filename, &file_status);
-  map* tmpMap1=getMap(content,"value");
-  if(tmpMap1==NULL){
-    addToMap(content,"value","");
-    tmpMap1=getMap(content,"value");
-  }
-  free(tmpMap1->value);
-  tmpMap1->value=(char*) malloc((count+1)*sizeof(char));  
-  fread(tmpMap1->value,1,count,file);
-  tmpMap1->value[count]=0;
-  fclose(file);
-  char rsize[1000];
-  sprintf(rsize,"%ld",count);
-  addToMap(content,"size",rsize);
-}
-
-/**
- * Generate the output response (RawDataOutput or ResponseDocument)
- *
- * @param s the service structure containing the metadata informations
- * @param request_inputs the inputs provided to the service for execution
- * @param request_outputs the outputs updated by the service execution
- * @param request_inputs1 the map containing the HTTP request
- * @param cpid the process identifier attached to a service execution
- * @param m the conf maps containing the main.cfg settings
- * @param res the value returned by the service execution
- */
-void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
-		    map* request_inputs1,int cpid,maps* m,int res){
-#ifdef DEBUG
-  dumpMaps(request_inputs);
-  dumpMaps(request_outputs);
-  fprintf(stderr,"printProcessResponse\n");
-#endif
-  map* toto=getMap(request_inputs1,"RawDataOutput");
-  int asRaw=0;
-  if(toto!=NULL)
-    asRaw=1;
-  
-  maps* tmpSess=getMaps(m,"senv");
-  if(tmpSess!=NULL){
-    map *_tmp=getMapFromMaps(m,"lenv","cookie");
-    char* sessId=NULL;
-    if(_tmp!=NULL){
-      printf("Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
-      printf("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"\r\n");
-      char session_file_path[100];
-      char *tmp1=strtok(_tmp->value,";");
-      if(tmp1!=NULL)
-	sprintf(session_file_path,"%s",strstr(tmp1,"=")+1);
-      else
-	sprintf(session_file_path,"%s",strstr(_tmp->value,"=")+1);
-      sessId=strdup(session_file_path);
-    }else{
-      maps* t=getMaps(m,"senv");
-      map*p=t->content;
-      while(p!=NULL){
-	if(strstr(p->name,"ID")!=NULL){
-	  sessId=strdup(p->value);
-	  break;
-	}
-	p=p->next;
-      }
-    }
-    char session_file_path[1024];
-    map *tmpPath=getMapFromMaps(m,"main","sessPath");
-    if(tmpPath==NULL)
-      tmpPath=getMapFromMaps(m,"main","tmpPath");
-    sprintf(session_file_path,"%s/sess_%s.cfg",tmpPath->value,sessId);
-    FILE* teste=fopen(session_file_path,"w");
-    if(teste==NULL){
-      char tmpMsg[1024];
-      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
-      errorException(m,tmpMsg,"InternalError",NULL);
-
-      return;
-    }
-    else{
-      fclose(teste);
-      dumpMapsToFile(tmpSess,session_file_path);
-    }
-  }
-  
-  if(res==SERVICE_FAILED){
-    map *lenv;
-    lenv=getMapFromMaps(m,"lenv","message");
-    char *tmp0;
-    if(lenv!=NULL){
-      tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char));
-      sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
-    }
-    else{
-      tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
-      sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
-    }
-    errorException(m,tmp0,"InternalError",NULL);
-    free(tmp0);
-    return;
-  }
-
-
-  map *tmp1=getMapFromMaps(m,"main","tmpPath");
-  if(asRaw==0){
-#ifdef DEBUG
-    fprintf(stderr,"REQUEST_OUTPUTS FINAL\n");
-    dumpMaps(request_outputs);
-#endif
-    maps* tmpI=request_outputs;
-
-    while(tmpI!=NULL){
-#ifdef USE_MS
-      map* testMap=getMap(tmpI->content,"useMapserver");	
-#endif
-      map *gfile=getMap(tmpI->content,"generated_file");
-      char *file_name;
-      if(gfile!=NULL){
-	gfile=getMap(tmpI->content,"expected_generated_file");
-	if(gfile==NULL){
-	  gfile=getMap(tmpI->content,"generated_file");
-	}
-	readGeneratedFile(m,tmpI->content,gfile->value);	    
-	file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char));
-	for(int i=0;i<strlen(gfile->value);i++)
-	  file_name[i]=gfile->value[i+strlen(tmp1->value)];
-      }
-
-      toto=getMap(tmpI->content,"asReference");
-#ifdef USE_MS
-      if(toto!=NULL && strcasecmp(toto->value,"true")==0 && testMap==NULL)
-#else
-      if(toto!=NULL && strcasecmp(toto->value,"true")==0)
-#endif
-	{
-	  elements* in=getElements(s->outputs,tmpI->name);
-	  char *format=NULL;
-	  if(in!=NULL){
-	    format=strdup(in->format);
-	  }else
-	    format=strdup("LiteralData");
-	  if(strcasecmp(format,"BoundingBoxData")==0){
-	    addToMap(tmpI->content,"extension","xml");
-	    addToMap(tmpI->content,"mimeType","text/xml");
-	    addToMap(tmpI->content,"encoding","UTF-8");
-	    addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
-	  }
-
-	  if(gfile==NULL){
-	    map *ext=getMap(tmpI->content,"extension");
-	    char *file_path;
-	    char file_ext[32];
-
-	    if( ext != NULL && ext->value != NULL) {
-	      strncpy(file_ext, ext->value, 32);
-	    }
-	    else {
-	      // Obtain default file extension (see mimetypes.h).	      
-	      // If the MIME type is not recognized, txt is used as the default extension
-	      map* mtype=getMap(tmpI->content,"mimeType");
-	      getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
-	    }
-		
-	    file_name=(char*)malloc((strlen(s->name)+strlen(file_ext)+strlen(tmpI->name)+1024)*sizeof(char));
-	    int cpid0=cpid+time(NULL);	    
-	    sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,file_ext);
-	    file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
-	    sprintf(file_path,"%s/%s",tmp1->value,file_name);
-    
-		FILE *ofile=fopen(file_path,"wb");
-	    if(ofile==NULL){
-	      char tmpMsg[1024];
-	      sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the %s final result."),file_name,tmpI->name);
-	      errorException(m,tmpMsg,"InternalError",NULL);
-	      free(file_name);
-	      free(file_path);
-	      return;
-	    }
-	    free(file_path);
-
-	    toto=getMap(tmpI->content,"value");
-	    if(strcasecmp(format,"BoundingBoxData")!=0){
-	      map* size=getMap(tmpI->content,"size");
-	      if(size!=NULL && toto!=NULL)
-		fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
-	      else
-		if(toto!=NULL && toto->value!=NULL)
-		  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
-	    }else{
-	      printBoundingBoxDocument(m,tmpI,ofile);
-	    }
-	    fclose(ofile);
-
-	  }
-	  map *tmp2=getMapFromMaps(m,"main","tmpUrl");
-	  map *tmp3=getMapFromMaps(m,"main","serverAddress");
-	  char *file_url;
-	  if(strncasecmp(tmp2->value,"http://",7)==0 ||
-	     strncasecmp(tmp2->value,"https://",8)==0){
-	    file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
-	    sprintf(file_url,"%s/%s",tmp2->value,file_name);
-	  }else{
-	    file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
-	    sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
-	  }
-	  addToMap(tmpI->content,"Reference",file_url);
-	  free(format);
-	  free(file_name);
-	  free(file_url);	
-	  
-	}
-#ifdef USE_MS
-      else{
-	if(testMap!=NULL){
-	  setReferenceUrl(m,tmpI);
-	}
-      }
-#endif
-      tmpI=tmpI->next;
-    }
-    map *r_inputs=getMap(s->content,"serviceProvider");
-#ifdef DEBUG
-    fprintf(stderr,"SERVICE : %s\n",r_inputs->value);
-    dumpMaps(m);
-#endif
-    printProcessResponse(m,request_inputs1,cpid,
-		//	 s,r_inputs->value,res,
-			 s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
-			 request_inputs,
-			 request_outputs);
-  }
-  else{
-    /**
-     * We get the requested output or fallback to the first one if the 
-     * requested one is not present in the resulting outputs maps.
-     */
-    maps* tmpI=NULL;
-    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
-    if(tmpIV!=NULL){
-      tmpI=getMaps(request_outputs,tmpIV->value);
-    }
-    if(tmpI==NULL)
-      tmpI=request_outputs;
-    elements* e=getElements(s->outputs,tmpI->name);
-    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
-      printBoundingBoxDocument(m,tmpI,NULL);
-    }else{
-      map *gfile=getMap(tmpI->content,"generated_file");
-      if(gfile!=NULL){
-	gfile=getMap(tmpI->content,"expected_generated_file");
-	if(gfile==NULL){
-	  gfile=getMap(tmpI->content,"generated_file");
-	}
-	readGeneratedFile(m,tmpI->content,gfile->value);
-      }
-      toto=getMap(tmpI->content,"value");
-      if(toto==NULL){
-	char tmpMsg[1024];
-	sprintf(tmpMsg,_("Wrong RawDataOutput parameter: unable to fetch any result for the given parameter name: \"%s\"."),tmpI->name);
-	errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput");
-	return;
-      }
-      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
-      if(fname!=NULL)
-	printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
-      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
-      if(rs!=NULL)
-	printf("Content-Length: %s\r\n",rs->value);
-      printHeaders(m);
-      char mime[1024];
-      map* mi=getMap(tmpI->content,"mimeType");
-#ifdef DEBUG
-      fprintf(stderr,"SERVICE OUTPUTS\n");
-      dumpMaps(request_outputs);
-      fprintf(stderr,"SERVICE OUTPUTS\n");
-#endif
-      map* en=getMap(tmpI->content,"encoding");
-      if(mi!=NULL && en!=NULL)
-	sprintf(mime,
-		"Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
-		mi->value,en->value);
-      else
-	if(mi!=NULL)
-	  sprintf(mime,
-		  "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
-		  mi->value);
-	else
-	  sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-      printf("%s",mime);
-      if(rs!=NULL)
-	fwrite(toto->value,1,atoi(rs->value),stdout);
-      else
-	fwrite(toto->value,1,strlen(toto->value),stdout);
-#ifdef DEBUG
-      dumpMap(toto);
-#endif
-    }
-  }
-}
-
-/**
- * Write a file from value and length
- *
- * @param fname the file name
- * @param val the value
- * @param length the value length
- */
-int writeFile(char* fname,char* val,int length){
-  FILE* of=fopen(fname,"wb");
-  if(of==NULL){
-    return -1;
-  }
-  size_t ret=fwrite(val,sizeof(char),length,of);
-  if(ret<length){
-    fprintf(stderr,"Write error occured!\n");
-    fclose(of);
-    return -1;
-  }
-  fclose(of);
-  return 1;
-}
-
-/**
- * Dump all values in a maps as files
- *
- * @param main_conf the maps containing the settings of the main.cfg file
- * @param in the maps containing values to dump as files
- */
-void dumpMapsValuesToFiles(maps** main_conf,maps** in){
-  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
-  map* tmpSid=getMapFromMaps(*main_conf,"lenv","sid");
-  maps* inputs=*in;
-  int length=0;
-  while(inputs!=NULL){
-    if(getMap(inputs->content,"mimeType")!=NULL &&
-       getMap(inputs->content,"cache_file")==NULL){
-      map* cMap=inputs->content;
-      if(getMap(cMap,"length")!=NULL){
-	map* tmpLength=getMap(cMap,"length");
-	int len=atoi(tmpLength->value);
-	int k=0;
-	for(k=0;k<len;k++){
-	  map* cMimeType=getMapArray(cMap,"mimeType",k);
-	  map* cValue=getMapArray(cMap,"value",k);
-	  map* cSize=getMapArray(cMap,"size",k);
-	  char file_ext[32];
-	  getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
-	  char* val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
-	  sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,k,file_ext);
-	  length=0;
-	  if(cSize!=NULL){
-	    length=atoi(cSize->value);
-	  }
-	  writeFile(val,cValue->value,length);
-	  setMapArray(cMap,"cache_file",k,val);
-	  free(val);
-	}
-      }else{
-	int length=0;
-	map* cMimeType=getMap(cMap,"mimeType");
-	map* cValue=getMap(cMap,"value");
-	map* cSize=getMap(cMap,"size");
-	char file_ext[32];
-	getFileExtension(cMimeType != NULL ? cMimeType->value : NULL, file_ext, 32);
-	char *val=(char*)malloc((strlen(tmpPath->value)+strlen(inputs->name)+strlen(tmpSid->value)+strlen(file_ext)+16)*sizeof(char));
-	sprintf(val,"%s/Input_%s_%s_%d.%s",tmpPath->value,inputs->name,tmpSid->value,0,file_ext);
-	if(cSize!=NULL){
-	  length=atoi(cSize->value);
-	}
-	writeFile(val,cValue->value,length);
-	addToMap(cMap,"cache_file",val);
-	free(val);
-      }
-    }
-    inputs=inputs->next;
-  }
-}
-
-/**
- * Base64 encoding of a char*
- *
- * @param input the value to encode
- * @param length the value length
- * @return the buffer containing the base64 value
- * @warning make sure to free the returned value
- */
-char *base64(const char *input, int length)
-{
-  BIO *bmem, *b64;
-  BUF_MEM *bptr;
-
-  b64 = BIO_new(BIO_f_base64());
-  BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
-  bmem = BIO_new(BIO_s_mem());
-  b64 = BIO_push(b64, bmem);
-  BIO_write(b64, input, length);
-  BIO_flush(b64);
-  BIO_get_mem_ptr(b64, &bptr);
-
-  char *buff = (char *)malloc((bptr->length+1)*sizeof(char));
-  memcpy(buff, bptr->data, bptr->length);
-  buff[bptr->length] = 0;
-
-  BIO_free_all(b64);
-
-  return buff;
-}
-
-/**
- * Base64 decoding of a char*
- *
- * @param input the value to decode
- * @param length the value length
- * @param red the value length
- * @return the buffer containing the base64 value 
- * @warning make sure to free the returned value
- */
-char *base64d(const char *input, int length,int* red)
-{
-  BIO *b64, *bmem;
-
-  char *buffer = (char *)malloc(length);
-  if(buffer){
-    memset(buffer, 0, length);
-    b64 = BIO_new(BIO_f_base64());
-    if(b64){
-      bmem = BIO_new_mem_buf((unsigned char*)input,length);
-      bmem = BIO_push(b64, bmem);
-      *red=BIO_read(bmem, buffer, length);
-      buffer[length-1]=0;
-      BIO_free_all(bmem);
-    }
-  }
-  return buffer;
-}
-
-/**
- * Read Base64 value and split it value by lines of 64 char.
- *
- * @param in the map containing the value to split
- */
-void readBase64(map **in){
-  char *res = NULL;
-  char *curs = (*in)->value;
-  int i = 0;
-  for (i = 0; i <= strlen ((*in)->value) / 64;
-       i++)
-    {
-      if (res == NULL)
-	res =
-	  (char *) malloc (65 * sizeof (char));
-      else
-	res =
-	  (char *) realloc (res,
-			    (((i + 1) * 65) +
-			     i) * sizeof (char));
-      int csize = i * 65;
-      strncpy (res + csize, curs, 64);
-      if (i == strlen ((*in)->value) / 64)
-	strcat (res, "\n\0");
-      else
-	{
-	  strncpy (res + (((i + 1) * 64) + i),
-		   "\n\0", 2);
-	  curs += 64;
-	}
-    }
-  free ((*in)->value);
-  (*in)->value = zStrdup (res);
-  free (res);
-}
-
-/**
- * Make sure that each value encoded in base64 in a maps is decoded.
- *
- * @param in the maps containing the values
- * @see readBase64
- */
-void ensureDecodedBase64(maps **in){
-  maps* cursor=*in;
-  while(cursor!=NULL){
-    map *tmp=getMap(cursor->content,"encoding");
-    if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
-      tmp=getMap(cursor->content,"value");
-      readBase64(&tmp);
-      addToMap(cursor->content,"base64_value",tmp->value);
-      int size=0;
-      char *s=strdup(tmp->value);
-      free(tmp->value);
-      tmp->value=base64d(s,strlen(s),&size);
-      free(s);
-      char sizes[1024];
-      sprintf(sizes,"%d",size);
-      addToMap(cursor->content,"size",sizes);
-    }
-    map* length=getMap(cursor->content,"length");
-    if(length!=NULL){
-      int len=atoi(length->value);
-      for(int i=1;i<len;i++){
-	tmp=getMapArray(cursor->content,"encoding",i);
-	if(tmp!=NULL && strncasecmp(tmp->value,"base64",6)==0){
-	  char key[17];
-	  sprintf(key,"base64_value_%d",i);
-	  tmp=getMapArray(cursor->content,"value",i);
-	  readBase64(&tmp);
-	  addToMap(cursor->content,key,tmp->value);
-	  int size=0;
-	  char *s=strdup(tmp->value);
-	  free(tmp->value);
-	  tmp->value=base64d(s,strlen(s),&size);
-	  free(s);
-	  char sizes[1024];
-	  sprintf(sizes,"%d",size);
-	  sprintf(key,"size_%d",i);
-	  addToMap(cursor->content,key,sizes);
-	}
-      }
-    }
-    cursor=cursor->next;
-  }
-}
-
-/**
- * Add the default values defined in the zcfg to a maps.
- *
- * @param out the maps containing the inputs or outputs given in the initial
- *  HTTP request
- * @param in the description of all inputs or outputs available for a service
- * @param m the maps containing the settings of the main.cfg file
- * @param type 0 for inputs and 1 for outputs
- * @param err the map to store potential missing mandatory input parameters or
- *  wrong output names depending on the type.
- * @return "" if no error was detected, the name of last input or output causing
- *  an error.
- */
-char* addDefaultValues(maps** out,elements* in,maps* m,int type,map** err){
-  map *res=*err;
-  elements* tmpInputs=in;
-  maps* out1=*out;
-  char *result=NULL;
-  int nb=0;
-  if(type==1){
-    while(out1!=NULL){
-      if(getElements(in,out1->name)==NULL){
-	if(res==NULL){
-	  res=createMap("value",out1->name);
-	}else{
-	  setMapArray(res,"value",nb,out1->name);
-	}
-	nb++;
-	result=out1->name;
-      }
-      out1=out1->next;
-    }
-    if(res!=NULL){
-      *err=res;
-      return result;
-    }
-    out1=*out;
-  }
-  while(tmpInputs!=NULL){
-    maps *tmpMaps=getMaps(out1,tmpInputs->name);
-    if(tmpMaps==NULL){
-      maps* tmpMaps2=(maps*)malloc(MAPS_SIZE);
-      tmpMaps2->name=strdup(tmpInputs->name);
-      tmpMaps2->content=NULL;
-      tmpMaps2->next=NULL;
-      
-      if(type==0){
-	map* tmpMapMinO=getMap(tmpInputs->content,"minOccurs");
-	if(tmpMapMinO!=NULL){
-	  if(atoi(tmpMapMinO->value)>=1){
-	    freeMaps(&tmpMaps2);
-	    free(tmpMaps2);
-	    if(res==NULL){
-	      res=createMap("value",tmpInputs->name);
-	    }else{
-	      setMapArray(res,"value",nb,tmpInputs->name);
-	    }
-	    nb++;
-	    result=tmpInputs->name;
-	  }
-	  else{
-	    if(tmpMaps2->content==NULL)
-	      tmpMaps2->content=createMap("minOccurs",tmpMapMinO->value);
-	    else
-	      addToMap(tmpMaps2->content,"minOccurs",tmpMapMinO->value);
-	  }
-	}
-	if(res==NULL){
-	  map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
-	  if(tmpMaxO!=NULL){
-	    if(tmpMaps2->content==NULL)
-	      tmpMaps2->content=createMap("maxOccurs",tmpMaxO->value);
-	    else
-	      addToMap(tmpMaps2->content,"maxOccurs",tmpMaxO->value);
-	  }
-	  map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
-	  if(tmpMaxMB!=NULL){
-	    if(tmpMaps2->content==NULL)
-	      tmpMaps2->content=createMap("maximumMegabytes",tmpMaxMB->value);
-	    else
-	      addToMap(tmpMaps2->content,"maximumMegabytes",tmpMaxMB->value);
-	  }
-	}
-      }
-
-      if(res==NULL){
-	iotype* tmpIoType=tmpInputs->defaults;
-	if(tmpIoType!=NULL){
-	  map* tmpm=tmpIoType->content;
-	  while(tmpm!=NULL){
-	    if(tmpMaps2->content==NULL)
-	      tmpMaps2->content=createMap(tmpm->name,tmpm->value);
-	    else
-	      addToMap(tmpMaps2->content,tmpm->name,tmpm->value);
-	    tmpm=tmpm->next;
-	  }
-	}
-	addToMap(tmpMaps2->content,"inRequest","false");
-	if(type==0){
-	  map *tmpMap=getMap(tmpMaps2->content,"value");
-	  if(tmpMap==NULL)
-	    addToMap(tmpMaps2->content,"value","NULL");
-	}
-	if(out1==NULL){
-	  *out=dupMaps(&tmpMaps2);
-	  out1=*out;
-	}
-	else
-	  addMapsToMaps(&out1,tmpMaps2);
-	freeMap(&tmpMaps2->content);
-	free(tmpMaps2->content);
-	tmpMaps2->content=NULL;
-	freeMaps(&tmpMaps2);
-	free(tmpMaps2);
-	tmpMaps2=NULL;
-      }
-    }
-    else{
-      iotype* tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,
-					     tmpMaps->content);
-      if(type==0) {
-	/**
-	 * In case of an Input maps, then add the minOccurs and maxOccurs to the
-	 * content map.
-	 */
-	map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
-	if(tmpMap1!=NULL){
-	  if(tmpMaps->content==NULL)
-	    tmpMaps->content=createMap("minOccurs",tmpMap1->value);
-	  else
-	    addToMap(tmpMaps->content,"minOccurs",tmpMap1->value);
-	}
-	map* tmpMaxO=getMap(tmpInputs->content,"maxOccurs");
-	if(tmpMaxO!=NULL){
-	  if(tmpMaps->content==NULL)
-	    tmpMaps->content=createMap("maxOccurs",tmpMaxO->value);
-	  else
-	    addToMap(tmpMaps->content,"maxOccurs",tmpMaxO->value);
-	}
-	map* tmpMaxMB=getMap(tmpInputs->content,"maximumMegabytes");
-	if(tmpMaxMB!=NULL){
-	  if(tmpMaps->content==NULL)
-	    tmpMaps->content=createMap("maximumMegabytes",tmpMaxMB->value);
-	  else
-	    addToMap(tmpMaps->content,"maximumMegabytes",tmpMaxMB->value);
-	}
-	/**
-	 * Parsing BoundingBoxData, fill the following map and then add it to
-	 * the content map of the Input maps: 
-	 * lowerCorner, upperCorner, srs and dimensions
-	 * cf. parseBoundingBox
-	 */
-	if(tmpInputs->format!=NULL && strcasecmp(tmpInputs->format,"BoundingBoxData")==0){
-	  maps* tmpI=getMaps(*out,tmpInputs->name);
-	  if(tmpI!=NULL){
-	    map* tmpV=getMap(tmpI->content,"value");
-	    if(tmpV!=NULL){
-	      char *tmpVS=strdup(tmpV->value);
-	      map* tmp=parseBoundingBox(tmpVS);
-	      free(tmpVS);
-	      map* tmpC=tmp;
-	      while(tmpC!=NULL){
-		addToMap(tmpMaps->content,tmpC->name,tmpC->value);
-		tmpC=tmpC->next;
-	      }
-	      freeMap(&tmp);
-	      free(tmp);
-	    }
-	  }
-	}
-      }
-
-      if(tmpIoType!=NULL){
-	map* tmpContent=tmpIoType->content;
-	map* cval=NULL;
-	int hasPassed=-1;
-	while(tmpContent!=NULL){
-	  if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){
-#ifdef DEBUG
-	    fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value);
-#endif
-	    if(tmpMaps->content==NULL)
-	      tmpMaps->content=createMap(tmpContent->name,tmpContent->value);
-	    else
-	      addToMap(tmpMaps->content,tmpContent->name,tmpContent->value);
-	    
-	    if(hasPassed<0 && type==0 && getMap(tmpMaps->content,"isArray")!=NULL){
-	      map* length=getMap(tmpMaps->content,"length");
-	      int i;
-	      char *tcn=strdup(tmpContent->name);
-	      for(i=1;i<atoi(length->value);i++){
-#ifdef DEBUG
-		dumpMap(tmpMaps->content);
-		fprintf(stderr,"addDefaultValues %s_%d => %s\n",tcn,i,tmpContent->value);
-#endif
-		int len=strlen((char*) tcn);
-		char *tmp1=(char *)malloc((len+10)*sizeof(char));
-		sprintf(tmp1,"%s_%d",tcn,i);
-#ifdef DEBUG
-		fprintf(stderr,"addDefaultValues %s => %s\n",tmp1,tmpContent->value);
-#endif
-		addToMap(tmpMaps->content,tmp1,tmpContent->value);
-		free(tmp1);
-		hasPassed=1;
-	      }
-	      free(tcn);
-	    }
-	  }
-	  tmpContent=tmpContent->next;
-	}
-#ifdef USE_MS
-	/**
-	 * check for useMapServer presence
-	 */
-	map* tmpCheck=getMap(tmpIoType->content,"useMapServer");
-	if(tmpCheck!=NULL){
-	  // Get the default value
-	  tmpIoType=getIoTypeFromElement(tmpInputs,tmpInputs->name,NULL);
-	  tmpCheck=getMap(tmpMaps->content,"mimeType");
-	  addToMap(tmpMaps->content,"requestedMimeType",tmpCheck->value);
-	  map* cursor=tmpIoType->content;
-	  while(cursor!=NULL){
-	    addToMap(tmpMaps->content,cursor->name,cursor->value);
-	    cursor=cursor->next;
-	  }
-	  
-	  cursor=tmpInputs->content;
-	  while(cursor!=NULL){
-	    if(strcasecmp(cursor->name,"Title")==0 ||
-	       strcasecmp(cursor->name,"Abstract")==0)
-	      addToMap(tmpMaps->content,cursor->name,cursor->value);
-           cursor=cursor->next;
-	  }
-	}
-#endif
-      }
-      if(tmpMaps->content==NULL)
-	tmpMaps->content=createMap("inRequest","true");
-      else
-	addToMap(tmpMaps->content,"inRequest","true");
-
-    }
-    tmpInputs=tmpInputs->next;
-  }
-  if(res!=NULL){
-    *err=res;
-    return result;
-  }
-  return "";
-}
-
-/**
- * Parse a BoundingBox string
- *
- * [OGC 06-121r3](http://portal.opengeospatial.org/files/?artifact_id=20040):
- *  10.2 Bounding box
- * 
- *
- * Value is provided as : lowerCorner,upperCorner,crs,dimension
- * Exemple : 189000,834000,285000,962000,urn:ogc:def:crs:OGC:1.3:CRS84
- *
- * A map to store boundingbox informations should contain:
- *  - lowerCorner : double,double (minimum within this bounding box)
- *  - upperCorner : double,double (maximum within this bounding box)
- *  - crs : URI (Reference to definition of the CRS)
- *  - dimensions : int 
- * 
- * Note : support only 2D bounding box.
- *
- * @param value the char* containing the KVP bouding box
- * @return a map containing all the bounding box keys
- */
-map* parseBoundingBox(const char* value){
-  map *res=NULL;
-  if(value!=NULL){
-    char *cv,*cvp;
-    cv=strtok_r((char*) value,",",&cvp);
-    int cnt=0;
-    int icnt=0;
-    char *currentValue=NULL;
-    while(cv){
-      if(cnt<2)
-	if(currentValue!=NULL){
-	  char *finalValue=(char*)malloc((strlen(currentValue)+strlen(cv)+1)*sizeof(char));
-	  sprintf(finalValue,"%s%s",currentValue,cv);
-	  switch(cnt){
-	  case 0:
-	    res=createMap("lowerCorner",finalValue);
-	    break;
-	  case 1:
-	    addToMap(res,"upperCorner",finalValue);
-	    icnt=-1;
-	    break;
-	  }
-	  cnt++;
-	  free(currentValue);
-	  currentValue=NULL;
-	  free(finalValue);
-	}
-	else{
-	  currentValue=(char*)malloc((strlen(cv)+2)*sizeof(char));
-	  sprintf(currentValue,"%s ",cv);
-	}
-      else
-	if(cnt==2){
-	  addToMap(res,"crs",cv);
-	  cnt++;
-	}
-	else
-	  addToMap(res,"dimensions",cv);
-      icnt++;
-      cv=strtok_r(NULL,",",&cvp);
-    }
-  }
-  return res;
-}
-
-/**
- * Create required XML nodes for boundingbox and update the current XML node
- *
- * @param ns_ows the ows XML namespace
- * @param n the XML node to update
- * @param boundingbox the map containing the boundingbox definition
- */
-void printBoundingBox(xmlNsPtr ns_ows,xmlNodePtr n,map* boundingbox){
-
-  xmlNodePtr lw=NULL,uc=NULL;
-
-  map* tmp=getMap(boundingbox,"value");
-
-  tmp=getMap(boundingbox,"lowerCorner");
-  if(tmp!=NULL){
-    lw=xmlNewNode(ns_ows,BAD_CAST "LowerCorner");
-    xmlAddChild(lw,xmlNewText(BAD_CAST tmp->value));
-  }
-
-  tmp=getMap(boundingbox,"upperCorner");
-  if(tmp!=NULL){
-    uc=xmlNewNode(ns_ows,BAD_CAST "UpperCorner");
-    xmlAddChild(uc,xmlNewText(BAD_CAST tmp->value));
-  }
-
-  tmp=getMap(boundingbox,"crs");
-  if(tmp!=NULL)
-    xmlNewProp(n,BAD_CAST "crs",BAD_CAST tmp->value);
-
-  tmp=getMap(boundingbox,"dimensions");
-  if(tmp!=NULL)
-    xmlNewProp(n,BAD_CAST "dimensions",BAD_CAST tmp->value);
-
-  xmlAddChild(n,lw);
-  xmlAddChild(n,uc);
-
-}
-
-/**
- * Print an ows:BoundingBox XML document
- *
- * @param m the maps containing the settings of the main.cfg file
- * @param boundingbox the maps containing the boundingbox definition
- * @param file the file to print the BoundingBox (if NULL then print on stdout)
- * @see parseBoundingBox, printBoundingBox
- */
-void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
-  if(file==NULL)
-    rewind(stdout);
-  xmlNodePtr n;
-  xmlDocPtr doc;
-  xmlNsPtr ns_ows,ns_xsi;
-  xmlChar *xmlbuff;
-  int buffersize;
-  char *encoding=getEncoding(m);
-  map *tmp;
-  if(file==NULL){
-    int pid=0;
-    tmp=getMapFromMaps(m,"lenv","sid");
-    if(tmp!=NULL)
-      pid=atoi(tmp->value);
-    if(pid==getpid()){
-      printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
-    }
-    fflush(stdout);
-  }
-
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
-  ns_ows=usedNs[owsId];
-  n = xmlNewNode(ns_ows, BAD_CAST "BoundingBox");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
-  ns_xsi=usedNs[xsiId];
-  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
-  map *tmp1=getMap(boundingbox->content,"value");
-  tmp=parseBoundingBox(tmp1->value);
-  printBoundingBox(ns_ows,n,tmp);
-  xmlDocSetRootElement(doc, n);
-
-  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  if(file==NULL)
-    printf("%s",xmlbuff);
-  else{
-    fprintf(file,"%s",xmlbuff);
-  }
-
-  if(tmp!=NULL){
-    freeMap(&tmp);
-    free(tmp);
-  }
-  xmlFree(xmlbuff);
-  xmlFreeDoc(doc);
-  xmlCleanupParser();
-  zooXmlCleanupNs();
-  
-}
-
-/**
- * Compute md5
- * 
- * @param url the char* 
- * @return a char* representing the md5 of the url
- * @warning make sure to free ressources returned by this function
- */
-char* getMd5(char* url){
-  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;
-  EVP_DigestInit(&md5ctx, EVP_md5());
-  EVP_DigestUpdate(&md5ctx, url, strlen(url));
-  EVP_DigestFinal_ex(&md5ctx,result,&len);
-  EVP_MD_CTX_cleanup(&md5ctx);
-  int i;
-  for(i = 0; i < len; i++){
-    if(i>0){
-      char *tmp=strdup(fresult);
-      sprintf(fresult,"%s%02x", tmp,result[i]);
-      free(tmp);
-    }
-    else
-      sprintf(fresult,"%02x",result[i]);
-  }
-  return fresult;
-}
-
-/**
- * Cache a file for a given request.
- * For each cached file, the are two files stored, a .zca and a .zcm containing
- * the downloaded content and the mimeType respectively. 
- *
- * @param conf the maps containing the settings of the main.cfg file
- * @param request the url used too fetch the content
- * @param content the downloaded content
- * @param mimeType the content mimeType 
- * @param length the content size
- * @param filepath a buffer for storing the path of the cached file; may be NULL
- * @param max_path the size of the allocated filepath buffer  
- */
-void addToCache(maps* conf,char* request,char* content,char* mimeType,int length, 
-                char* filepath, size_t max_path){
-  map* tmp=getMapFromMaps(conf,"main","cacheDir");
-  if(tmp!=NULL){
-    char* md5str=getMd5(request);
-    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
-    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
-#ifdef DEBUG
-    fprintf(stderr,"Cache list : %s\n",fname);
-    fflush(stderr);
-#endif
-    FILE* fo=fopen(fname,"w+");
-    if(fo==NULL){
-#ifdef DEBUG
-      fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
-#endif
-      filepath = NULL;	
-      return;
-    }
-    fwrite(content,sizeof(char),length,fo);
-    fclose(fo);
-	
-	if (filepath != NULL) {
-		strncpy(filepath, fname, max_path);
-	}	
-
-    sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
-    fo=fopen(fname,"w+");
-#ifdef DEBUG
-    fprintf(stderr,"MIMETYPE: %s\n",mimeType);
-#endif
-    fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
-    fclose(fo);
-
-    free(md5str);
-    free(fname);
-  }
-  else {
-	  filepath = NULL;
-  }	  
-}
-
-/**
- * Verify if a url is available in the cache
- *
- * @param conf the maps containing the settings of the main.cfg file
- * @param request the url
- * @return the full name of the cached file if any, NULL in other case
- * @warning make sure to free ressources returned by this function (if not NULL)
- */
-char* isInCache(maps* conf,char* request){
-  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
-  if(tmpM!=NULL){
-    char* md5str=getMd5(request);
-#ifdef DEBUG
-    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
-#endif
-    char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6));
-    sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
-    struct stat f_status;
-    int s=stat(fname, &f_status);
-    if(s==0 && f_status.st_size>0){
-      free(md5str);
-      return fname;
-    }
-    free(md5str);
-    free(fname);
-  }
-  return NULL;
-}
-
-/**
- * Effectively run all the HTTP requests in the queue
- *
- * @param m the maps containing the settings of the main.cfg file
- * @param inputs the maps containing the inputs (defined in the requests+added
- *  per default based on the zcfg file)
- * @param hInternet the HINTERNET pointer
- * @return 0 on success
- */
-int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet){
-  if(hInternet->nb>0){
-    processDownloads(hInternet);
-    maps* content=*inputs;
-    map* tmp1;
-    int index=0;
-    char sindex[5];
-    while(content!=NULL){
-      
-      map* length=getMap(content->content,"length");
-      int shouldClean=-1;
-      if(length==NULL){
-	length=createMap("length","1");
-	shouldClean=1;
-      }
-      for(int i=0;i<atoi(length->value);i++){
-	char* fcontent;
-	char *mimeType=NULL;
-	int fsize=0;
-	char cname[15];
-	char vname[11];
-	char vname1[11];
-	char sname[9];
-	char mname[15];
-	char icname[14];
-	char xname[16];
-	char oname[12];
-	if(index>0)
-	  sprintf(vname1,"value_%d",index);
-	else
-	  sprintf(vname1,"value");
-
-	if(i>0){
-	  tmp1=getMap(content->content,cname);
-	  sprintf(cname,"cache_file_%d",i);
-	  sprintf(vname,"value_%d",i);
-	  sprintf(sname,"size_%d",i);
-	  sprintf(mname,"mimeType_%d",i);
-	  sprintf(icname,"isCached_%d",i);
-	  sprintf(xname,"Reference_%d",i);
-	  sprintf(oname,"Order_%d",i);
-	}else{
-	  sprintf(cname,"cache_file");
-	  sprintf(vname,"value");
-	  sprintf(sname,"size");
-	  sprintf(mname,"mimeType");
-	  sprintf(icname,"isCached");
-	  sprintf(xname,"Reference");
-	  sprintf(oname,"Order");
-	}
-
-	map* tmap=getMap(content->content,oname);
-	sprintf(sindex,"%d",index+1);
-	if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
-
-	  if(getMap(content->content,icname)==NULL){
-	    
-	    fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
-	    if(fcontent == NULL){
-	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
-	    }
-	    size_t dwRead;
-	    InternetReadFile(hInternet->ihandle[index], 
-			     (LPVOID)fcontent, 
-			     hInternet->ihandle[index].nDataLen, 
-			     &dwRead);
-	    fcontent[hInternet->ihandle[index].nDataLen]=0;
-	    fsize=hInternet->ihandle[index].nDataLen;
-	    if(hInternet->ihandle[index].mimeType==NULL)
-	      mimeType=strdup("none");
-	    else
-	      mimeType=strdup(hInternet->ihandle[index].mimeType);	      
-	    
-	    map* tmpMap=getMapOrFill(&content->content,vname,"");
-	    free(tmpMap->value);
-	    tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
-	    if(tmpMap->value==NULL){
-	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
-	    }
-	    memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
-	    
-	    char ltmp1[256];
-	    sprintf(ltmp1,"%d",fsize);
-	    map* tmp=getMapFromMaps(*m,"main","cacheDir");
-	    if(tmp!=NULL){
-	      char* md5str=getMd5(tmp1->value);
-	      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
-	      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
-	      addToMap(content->content,cname,fname);
-	      free(fname);
-	    }
-	    addToMap(content->content,sname,ltmp1);
-	    addToMap(content->content,mname,mimeType);
-	    addToCache(*m,tmp1->value,fcontent,mimeType,fsize, NULL, 0);
-	    free(fcontent);
-	    free(mimeType);
-	    index++;
-
-	  }
-	}
-      }
-      if(shouldClean>0){
-	freeMap(&length);
-	free(length);
-      }
-      
-      content=content->next;
-    }
-    
-  }
-  return 0;
-}
-
-/**
- * Add a request in the download queue
- *
- * @param m the maps containing the settings of the main.cfg file
- * @param url the url to add to the queue
- */
-void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
-  hInternet->waitingRequests[hInternet->nb]=strdup(url);
-  hInternet->ihandle[hInternet->nb].header=NULL;
-  if(req)
-    InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
-  maps *oreq=getMaps(*m,"orequests");
-  if(oreq==NULL){
-    oreq=(maps*)malloc(MAPS_SIZE);
-    oreq->name=zStrdup("orequests");
-    oreq->content=createMap("value",url);
-    oreq->next=NULL;
-    addMapsToMaps(m,oreq);
-    freeMaps(&oreq);
-    free(oreq);
-  }else{
-    setMapArray(oreq->content,"value",hInternet->nb-1,url);
-  }
-}
-
-/**
- * Try to load file from cache or download a remote file if not in cache
- *
- * @param m the maps containing the settings of the main.cfg file
- * @param content the map to update
- * @param hInternet the HINTERNET pointer
- * @param url the url to fetch
- * @return 0
- */
-int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
-  char* fcontent;
-  char* cached=isInCache(*m,url);
-  char *mimeType=NULL;
-  int fsize=0;
-
-  map* t=getMap(*content,"xlink:href");
-  if(t==NULL){
-    t=getMap((*content),"href");
-    addToMap(*content,"xlink:href",url);
-  }
-
-  if(cached!=NULL){
-
-    struct stat f_status;
-    int s=stat(cached, &f_status);
-    if(s==0){
-      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
-      FILE* f=fopen(cached,"rb");
-      fread(fcontent,f_status.st_size,1,f);
-      fsize=f_status.st_size;
-      fcontent[fsize]=0;
-      fclose(f);
-      addToMap(*content,"cache_file",cached);
-    }
-    cached[strlen(cached)-1]='m';
-    s=stat(cached, &f_status);
-    if(s==0){
-      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
-      FILE* f=fopen(cached,"rb");
-      fread(mimeType,f_status.st_size,1,f);
-      mimeType[f_status.st_size]=0;
-      fclose(f);
-    }
-
-  }else{    
-    addRequestToQueue(m,hInternet,url,true);
-    return 0;
-  }
-  if(fsize==0){
-    return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
-  }
-  if(mimeType!=NULL){
-    addToMap(*content,"fmimeType",mimeType);
-  }
-
-  map* tmpMap=getMapOrFill(content,"value","");
-    
-  free(tmpMap->value);
-
-  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
-  if(tmpMap->value==NULL)
-    return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
-  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
-
-  char ltmp1[256];
-  sprintf(ltmp1,"%d",fsize);
-  addToMap(*content,"size",ltmp1);
-  if(cached==NULL){
-    addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0);
-  }
-  else{
-    addToMap(*content,"isCached","true");
-    map* tmp=getMapFromMaps(*m,"main","cacheDir");
-    if(tmp!=NULL){
-      map *c=getMap((*content),"xlink:href");
-      char* md5str=getMd5(c->value);
-      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
-      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
-      addToMap(*content,"cache_file",fname);
-      free(fname);
-    }
-  }
-  free(fcontent);
-  free(mimeType);
-  free(cached);
-  return 0;
-}
-
-/**
- * Read a file using the GDAL VSI API 
- *
- * @param conf the maps containing the settings of the main.cfg file
- * @param dataSource the datasource name to read
- * @warning make sure to free ressources returned by this function
- */
-char *readVSIFile(maps* conf,const char* dataSource){
-    VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
-    VSIStatBufL file_status;
-    VSIStatL(dataSource, &file_status);
-    if(fichier==NULL){
-      char tmp[1024];
-      sprintf(tmp,"Failed to open file %s for reading purpose. File seems empty %lld.",
-	      dataSource,file_status.st_size);
-      setMapInMaps(conf,"lenv","message",tmp);
-      return NULL;
-    }
-    char *res1=(char *)malloc(file_status.st_size*sizeof(char));
-    VSIFReadL(res1,1,file_status.st_size*sizeof(char),fichier);
-    res1[file_status.st_size-1]=0;
-    VSIFCloseL(fichier);
-    VSIUnlink(dataSource);
-    return res1;
-}
-
-/**
- * Extract the service identifier from the full service identifier
- * ie: 
- *  - Full service name: OTB.BandMath
- *  - Service name: BandMath
- *
- * @param conf the maps containing the settings of the main.cfg file
- * @param conf_dir the full path to the ZOO-Kernel directory
- * @param identifier the full service name (potentialy including a prefix, ie:
- *  Prefix.MyService)
- * @param buffer the resulting service identifier (without any prefix)
- */
-void parseIdentifier(maps* conf,char* conf_dir,char *identifier,char* buffer){
-  setMapInMaps(conf,"lenv","oIdentifier",identifier);
-  char *lid=zStrdup(identifier);
-  char *saveptr1;
-  char *tmps1=strtok_r(lid,".",&saveptr1);
-  int level=0;
-  char key[25];
-  char levels[18];
-  while(tmps1!=NULL){
-    char *test=zStrdup(tmps1);
-    char* tmps2=(char*)malloc((strlen(test)+2)*sizeof(char));
-    sprintf(key,"sprefix_%d",level);
-    sprintf(tmps2,"%s.",test);
-    sprintf(levels,"%d",level);
-    setMapInMaps(conf,"lenv","level",levels);
-    setMapInMaps(conf,"lenv",key,tmps2);
-    free(tmps2);
-    free(test);
-    level++;
-    tmps1=strtok_r(NULL,".",&saveptr1);
-  }
-  int i=0;
-  sprintf(buffer,"%s",conf_dir);
-  for(i=0;i<level;i++){
-    char *tmp0=zStrdup(buffer);
-    sprintf(key,"sprefix_%d",i);
-    map* tmp00=getMapFromMaps(conf,"lenv",key);
-    if(tmp00!=NULL)
-      sprintf(buffer,"%s/%s",tmp0,tmp00->value);
-    free(tmp0);
-    buffer[strlen(buffer)-1]=0;
-    if(i+1<level){ 
-      #ifdef IGNORE_METAPATH
-        map* tmpMap = createMap("metapath", "");
-      #else  
-        map* tmpMap=getMapFromMaps(conf,"lenv","metapath");
-      #endif	  
-      if(tmpMap==NULL || strlen(tmpMap->value)==0){
-	char *tmp01=zStrdup(tmp00->value);
-	tmp01[strlen(tmp01)-1]=0;
-	setMapInMaps(conf,"lenv","metapath",tmp01);
-	free(tmp01);
-	tmp01=NULL;
-      }
-      else{
-	if(tmp00!=NULL && tmpMap!=NULL){
-	  char *tmp00s=zStrdup(tmp00->value);
-	  tmp00s[strlen(tmp00s)-1]=0;
-	  char *value=(char*)malloc((strlen(tmp00s)+strlen(tmpMap->value)+2)*sizeof(char));
-	  sprintf(value,"%s/%s",tmpMap->value,tmp00s);
-	  setMapInMaps(conf,"lenv","metapath",value);
-	  free(value);
-	  free(tmp00s);
-	  value=NULL;
-	}
-      }
-    }else{
-      char *tmp01=zStrdup(tmp00->value);
-      tmp01[strlen(tmp01)-1]=0;
-      setMapInMaps(conf,"lenv","Identifier",tmp01);
-      free(tmp01);
-    }
-  }
-  char *tmp0=zStrdup(buffer);
-  sprintf(buffer,"%s.zcfg",tmp0);
-  free(tmp0);
-  free(lid);
-}
-
 /**
  * Update the status of an ongoing service 
@@ -4111,131 +634,2 @@
 }
 
-/**
- * Verify if a parameter value is valid.
- * 
- * @param request the request map
- * @param res the error map potentially generated
- * @param toCheck the parameter to use
- * @param avalues the acceptable values (or null if testing only for presence)
- * @param mandatory verify the presence of the parameter if mandatory > 0 
- */
-void checkValidValue(map* request,map** res,const char* toCheck,const char** avalues,int mandatory){
-  map* lres=*res;
-  map* r_inputs = getMap (request,toCheck);
-  if (r_inputs == NULL){
-    if(mandatory>0){
-      char *replace=_("Mandatory parameter <%s> was not specified");
-      char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char));
-      sprintf(message,replace,toCheck);
-      if(lres==NULL){
-	lres=createMap("code","MissingParameterValue");
-	addToMap(lres,"text",message);
-	addToMap(lres,"locator",toCheck);       
-      }else{
-	int length=1;
-	map* len=getMap(lres,"length");
-	if(len!=NULL){
-	  length=atoi(len->value);
-	}
-	setMapArray(lres,"text",length,message);
-	setMapArray(lres,"locator",length,toCheck);
-	setMapArray(lres,"code",length,"MissingParameter");
-      }
-      free(message);
-    }
-  }else{
-    if(avalues==NULL)
-      return;
-    int nb=0;
-    int hasValidValue=-1;
-    while(avalues[nb]!=NULL){
-      if(strcasecmp(avalues[nb],r_inputs->value)==0){
-	hasValidValue=1;
-	break;
-      }
-      nb++;
-    }
-    if(hasValidValue<0){
-      char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value.");
-      nb=0;
-      char *vvalues=NULL;
-      char* num=_("is");
-      while(avalues[nb]!=NULL){
-	char *tvalues;
-	if(vvalues==NULL){
-	  vvalues=(char*)malloc((strlen(avalues[nb])+3)*sizeof(char));
-	  sprintf(vvalues,"%s",avalues[nb]);
-	}
-	else{
-	  tvalues=zStrdup(vvalues);
-	  vvalues=(char*)realloc(vvalues,(strlen(tvalues)+strlen(avalues[nb])+3)*sizeof(char));
-	  sprintf(vvalues,"%s, %s",tvalues,avalues[nb]);
-	  free(tvalues);
-	  num=_("are");
-	}
-	nb++;
-      }
-      char *message=(char*)malloc((strlen(replace)+strlen(num)+strlen(vvalues)+strlen(toCheck)+1)*sizeof(char));
-      sprintf(message,replace,toCheck,vvalues,num);
-      if(lres==NULL){
-	lres=createMap("code","InvalidParameterValue");
-	addToMap(lres,"text",message);
-	addToMap(lres,"locator",toCheck);       
-      }else{
-	int length=1;
-	map* len=getMap(lres,"length");
-	if(len!=NULL){
-	  length=atoi(len->value);
-	}
-	setMapArray(lres,"text",length,message);
-	setMapArray(lres,"locator",length,toCheck);
-	setMapArray(lres,"code",length,"InvalidParameterValue");
-      }
-    }
-  }
-  if(lres!=NULL){
-    *res=lres;
-  }
-}
-
-/**
- * Access the last error message returned by the OS when trying to dynamically
- * load a shared library.
- *
- * @return the last error message
- * @warning The character string returned from getLastErrorMessage resides
- * in a static buffer. The application should not write to this
- * buffer or attempt to free() it.
- */ 
-char* getLastErrorMessage() {                                              
-#ifdef WIN32
-  LPVOID lpMsgBuf;
-  DWORD errCode = GetLastError();
-  static char msg[ERROR_MSG_MAX_LENGTH];
-  size_t i;
-  
-  DWORD length = FormatMessage(
-			       FORMAT_MESSAGE_ALLOCATE_BUFFER | 
-			       FORMAT_MESSAGE_FROM_SYSTEM |
-			       FORMAT_MESSAGE_IGNORE_INSERTS,
-			       NULL,
-			       errCode,
-			       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-			       (LPTSTR) &lpMsgBuf,
-			       0, NULL );	
-  
-#ifdef UNICODE		
-  wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
-	      (wchar_t*) lpMsgBuf, _TRUNCATE );
-#else
-  strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
-	    (char *) lpMsgBuf );		
-#endif	
-  LocalFree(lpMsgBuf);
-  
-  return msg;
-#else
-  return dlerror();
-#endif
-}
-
Index: trunk/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.h	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal.h	(revision 640)
@@ -74,84 +74,32 @@
 #include <time.h>
 #include <ctype.h>
-#ifdef WIN32
 #ifndef USE_RUBY
 #include <unistd.h>
-#endif
 #endif
 #ifndef WIN32
 #include <xlocale.h>
 #endif
-#include "ulinet.h"
 
 #include "service.h"
-#include <openssl/sha.h>
-#include <openssl/md5.h>
-#include <openssl/hmac.h>
-#include <openssl/evp.h>
-#include <openssl/bio.h>
-#include <openssl/buffer.h>
 
-extern   int conf_read(const char*,maps*);
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
 
-#ifdef USE_JS
-#ifdef WIN32
-#define XP_WIN 1
-#else
-#define XP_UNIX 0
+#include <CoreServices/CoreServices.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
 #endif
-#include "service_internal_js.h"
-#endif
-
 
 #ifdef __cplusplus
 extern "C" {
 #endif
-#include <libxml/parser.h>
-#include <libxml/xpath.h>
 
-  /**
-   * Maximum number of XML namespaces
-   */
-#define ZOO_NS_MAX 10
-  /**
-   * Maximum number of XML docs
-   */
-#define ZOO_DOC_MAX 20
+  int  setOutputValue( maps*, const char*, char*, size_t);
+  char* getInputValue( maps*,const char*,size_t*);
 
-  /**
-   * Global char* to store the serverAddress value of the mmmmmain section
-   */
-  static char* SERVICE_URL;
-  /**
-   * Array of xmlNsPtr storing all used XML namespace
-   */
-  static xmlNsPtr usedNs[ZOO_NS_MAX];
-  /**
-   * Array storing names of the used XML namespace
-   */
-  static char* nsName[ZOO_NS_MAX];
-  /**
-   * Number of XML namespaces
-   */
-  static int nbNs=0;
-  /**
-   * Array of xmlDocPtr storing XML docs
-   */
-  static xmlDocPtr iDocs[ZOO_DOC_MAX];
-  /**
-   * Number of XML docs
-   */
-  static int nbDocs=0;
-
-  int getServiceFromYAML(maps*,char*,service**,char *name);
-  int readServiceFile(maps*, char*,service**,char *);
-  int isValidLang(maps*,const char*);
-  void addLangAttr(xmlNodePtr,maps*);
-
-  void printHeaders(maps*);
   void unhandleStatus(maps*);
   int _updateStatus(maps*);
   char* _getStatus(maps*,int);
   char* getStatus(int);
+  int updateStatus( maps*,const int,const char*);
   int removeShmLock(maps*, int);
   /**
@@ -170,62 +118,4 @@
 #endif
   
-  void readGeneratedFile(maps*,map*,char*);
-
-  void URLDecode(char *);
-  char *url_encode(char *);
-  char *url_decode(char *);
-  char* getEncoding(maps*);
-
-  int zooXmlSearchForNs(const char*);
-  int zooXmlAddNs(xmlNodePtr,const char*,const char*);
-  void zooXmlCleanupNs();
-
-  int zooXmlAddDoc(xmlNodePtr,const char*,const char*);
-  void zooXmlCleanupDocs();
-  
-  void printExceptionReportResponse(maps*,map*);
-  xmlNodePtr createExceptionReportNode(maps*,map*,int);
-  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
-  xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*);
-  xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*);
-  void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*);
-  void printDescribeProcessForProcess(maps*,xmlNodePtr,service*);
-  void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNodePtr);
-  void printDocument(maps*,xmlDocPtr,int);
-  void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*);
-  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
-  map* parseBoundingBox(const char*);
-  void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
-  void printBoundingBoxDocument(maps*,maps*,FILE*);
-  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
-
-  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
-
-  void dumpMapsValuesToFiles(maps**,maps**);
-
-  char *base64(const char*,int);
-  char *base64d(const char*,int,int*);
-  void ensureDecodedBase64(maps**);
-  void checkValidValue(map*,map**,const char*,const char**,int);
-  char* addDefaultValues(maps**,elements*,maps*,int,map**);
-
-  int errorException(maps *, const char *, const char *, const char*);
-
-  xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
-  int checkForSoapEnvelope(xmlDocPtr);
-  
-  void addToCache(maps*,char*,char*,char*,int,char*,size_t);
-  char* isInCache(maps*,char*);
-  int runHttpRequests(maps**,maps**,HINTERNET*);
-  void addRequestToQueue(maps**,HINTERNET*,const char*,bool);
-  int loadRemoteFile(maps**,map**,HINTERNET*,char*);
-
-  char *readVSIFile(maps*,const char*);
-  void parseIdentifier(maps*,char*,char*,char*);
-  int updateStatus( maps*,const int,const char*);
-  char* getInputValue( maps*,const char*,size_t*);
-  int  setOutputValue( maps*, const char*, char*, size_t);
-  
-  char* getLastErrorMessage();
 #ifdef __cplusplus
 }
Index: trunk/zoo-project/zoo-kernel/service_internal_java.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_java.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_java.c	(revision 640)
@@ -24,4 +24,5 @@
 
 #include "service_internal_java.h"
+#include "response_print.h"
 
 /**
@@ -87,10 +88,10 @@
   int nb=1;
   int nbc0=0;
-  maps* javaXXMap=getMaps(main_conf,"javaxx");
+  maps* javaXXMap=getMaps(*main_conf,"javaxx");
   if(javaXXMap!=NULL){
     nbc0+=count(javaXXMap->content);
   }
   int nbc1=0;
-  maps* javaXMap=getMaps(main_conf,"javax");
+  maps* javaXMap=getMaps(*main_conf,"javax");
   if(javaXMap!=NULL){
     nbc1+=count(javaXMap->content);
@@ -107,6 +108,4 @@
   long result;
   jmethodID pmid;
-  jfieldID fid;
-  jobject jobj;
   jclass cls;
 #ifdef JAVA7
@@ -502,7 +501,6 @@
    * }
    */
-  jclass scHashMap_class,scSetClass,scIteratorClass,scMapEntryClass,scSet_class,scMapClass;
+  jclass scSetClass,scIteratorClass,scMapEntryClass;
   jmethodID entrySet_mid,containsKey_mid,get_mid,iterator_mid,hasNext_mid,next_mid,getKey_mid,getValue_mid;
-  jobject scObject,scObject1;
   if(scHashMapClass==NULL){
 #ifdef DEBUG
Index: trunk/zoo-project/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_js.c	(revision 640)
@@ -23,5 +23,6 @@
  */
 
-#include "service_internal.h"
+#include "service_internal_js.h"
+#include "response_print.h"
 
 #ifndef JSCLASS_GLOBAL_FLAGS
@@ -67,6 +68,4 @@
 JSLoadScripts(JSContext *cx, uintN argc, jsval *argv1)
 {
-  //map* request = JS_GetContextPrivate(cx);
-  //map* tmpm1=getMap(request,"metapath");
   JS_MaybeGC(cx);
 
@@ -78,5 +77,4 @@
   JS_MaybeGC(cx);
   for(i=0;i<argc;i++){
-    JSString* jsmsg = JS_ValueToString(cx,argv[i]);
     char *filename = JSValToChar(cx,&argv[i]);
     char *api0=(char*)malloc((strlen(ntmp)+strlen(filename)+2)*sizeof(char));
@@ -110,7 +108,7 @@
 int zoo_js_support(maps** main_conf,map* request,service* s,maps **inputs,maps **outputs)
 {
-  maps* main=*main_conf;
+  /*maps* main=*main_conf;
   maps* _inputs=*inputs;
-  maps* _outputs=*outputs;
+  maps* _outputs=*outputs;*/
 
   /* The class of the global object. */
@@ -202,7 +200,7 @@
   /* Your application code here. This may include JSAPI calls
      to create your own custom JS objects and run scripts. */
-  maps* out=*outputs;
+  //maps* out=*outputs;
   int res=SERVICE_FAILED;
-  maps* mc=*main_conf;
+  //maps* mc=*main_conf;
   map* tmpm2=getMap(s->content,"serviceProvider");
 
@@ -216,5 +214,5 @@
   stat(filename, &file_status);
   //char *source=(char*)malloc(file_status.st_size);
-  uint16 lineno;
+  //uint16 lineno;
   jsval rval;
   JSBool ok ;
@@ -281,5 +279,5 @@
   }
 
-  jsval t=OBJECT_TO_JSVAL(d);
+  //jsval t=OBJECT_TO_JSVAL(d);
   if(JS_IsArrayObject(cx,d)){
 #ifdef JS_DEBUG
@@ -395,5 +393,4 @@
   if(s==0){
     jsval rval;
-    JSBool ok ;
     JSObject *script = JS_CompileFile(cx, JS_GetGlobalObject(cx), filename);
     if(script!=NULL){
@@ -425,11 +422,8 @@
 JSObject* JSObject_FromMaps(JSContext *cx,maps* t){
   JSObject* res=JS_NewObject(cx, NULL, NULL, NULL);
-  //JSObject *res = JS_NewArrayObject(cx, 0, NULL);
   if(res==NULL)
     fprintf(stderr,"Array Object is NULL!\n");
   maps* tmp=t;
   while(tmp!=NULL){
-    jsuint len;
-    JSObject* res1=JS_NewObject(cx, NULL, NULL, NULL);
     JSObject *pval=JSObject_FromMap(cx,tmp->content);
     jsval pvalj=OBJECT_TO_JSVAL(pval);
@@ -452,5 +446,4 @@
 JSObject* JSObject_FromMap(JSContext *cx,map* t){
   JSObject* res=JS_NewObject(cx, NULL, NULL, NULL);
-  jsval resf =  OBJECT_TO_JSVAL(res);
   map* tmpm=t;
   map* isArray=getMap(t,"isArray");
@@ -463,7 +456,7 @@
     fprintf(stderr,"tmap is not null ! (%s = %s)\n",tmap->name,tmap->value);
 #endif
-  while(tmpm!=NULL){
+  while(isArray==NULL && tmpm!=NULL){
     jsval jsstr;
-    if((isArray==NULL && isBinary!=NULL && strncasecmp(tmpm->name,"value",5)==0))
+    if((isBinary!=NULL && strncasecmp(tmpm->name,"value",5)==0))
       jsstr = STRING_TO_JSVAL(JS_NewStringCopyN(cx,tmpm->value,atoi(isBinary->value)));
     else
@@ -534,7 +527,6 @@
 	jsval id = idp->vector[index];
 	jsval vp;
-	JSString* str; 
 	JS_IdToValue(cx,id,&vp);
-	char *c, *tmp;
+	char *tmp;
 	JSString *jsmsg;
 	size_t len1;
@@ -583,5 +575,5 @@
   fprintf(stderr,"outputs array length : %d\n",len);
 #endif
-  for(oi=0;oi < len;oi++){
+  for(oi=0;hasLen && oi < len;oi++){
 #ifdef JS_DEBUG
     fprintf(stderr,"outputs array length : %d step %d \n",len,oi);
@@ -605,7 +597,6 @@
 	jsval id = idp->vector[index];
 	jsval vp;
-	JSString* str; 
 	JS_IdToValue(cx,id,&vp);
-	char *c, *tmp;
+	char *tmp;
 	JSString *jsmsg;
 	size_t len1;
@@ -706,7 +697,6 @@
       jsval id = idp->vector[index];
       jsval vp;
-      JSString* str; 
       JS_IdToValue(cx,id,&vp);
-      char *c, *tmp, *tmp1;
+      char *tmp, *tmp1;
       JSString *jsmsg,*jsmsg1;
       size_t len,len1;
@@ -877,6 +867,4 @@
   jsval *argv = JS_ARGV(cx,argv1);
   HINTERNET hInternet;
-  HINTERNET res;
-  HINTERNET res1;
   JSObject *header;
   char *url;
@@ -884,5 +872,4 @@
   char* tmpValue;
   size_t dwRead;
-  int i=0;
   JS_MaybeGC(cx);
   hInternet=InternetOpen("ZooWPSClient\0",
Index: trunk/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_ms.c	(revision 640)
@@ -32,4 +32,6 @@
 #endif
 #include "service_internal_ms.h"
+#include "server_internal.h"
+#include "response_print.h"
 
 /**
Index: trunk/zoo-project/zoo-kernel/service_internal_otb.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_otb.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_otb.c	(revision 640)
@@ -28,6 +28,13 @@
 
 #include "service_internal_otb.h"
+#include "response_print.h"
+#include "server_internal.h"
 
 using namespace otb::Wrapper;
+
+/**
+ * Global OTB counter 
+ */
+int otbCounter=0;
 
 /**
@@ -148,5 +155,5 @@
 	  for (unsigned int i = 0; i < appKeyList.size(); i++){
 	    const std::string paramKey(appKeyList[i]);
-	    std::vector<std::string> values;
+	    fprintf(stderr,"%s %d %s !\n",__FILE__,__LINE__,paramKey.c_str());
 	    Parameter::Pointer param = m_Application->GetParameterByKey(paramKey);
 	    ParameterType type = m_Application->GetParameterType(paramKey);
@@ -154,4 +161,5 @@
 	      map* test=getMapFromMaps(inputs,paramKey.c_str(),"cache_file");
 	      if(test==NULL){
+		fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,paramKey.c_str());
 		test=getMapFromMaps(inputs,paramKey.c_str(),"inRequest");
 		map* tmpPath=getMapFromMaps(m,"main","tmpPath");
@@ -160,5 +168,5 @@
 		map* tmpVal=getMapFromMaps(outputs,paramKey.c_str(),"mimeType");
 		maps* tmpMaps=getMaps(outputs,paramKey.c_str());
-		if(test!=NULL && test->value!=NULL && strncasecmp(test->value,"true",4)==0){
+		if(tmpMaps!=NULL && test!=NULL && test->value!=NULL && strncasecmp(test->value,"true",4)==0){
 		  test=getMapFromMaps(inputs,paramKey.c_str(),"value");
 		  if(type == ParameterType_OutputImage){
@@ -187,12 +195,9 @@
 			    ext="jpeg";
 		    }
-		    sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext);
+		    sprintf(tmp,"%s/%s_%d_%s.%s",tmpPath->value,s->name,otbCounter,tmpSid->value,ext);
+		    otbCounter++;
 		    m_Application->SetParameterString(paramKey, tmp);
 		    setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp);
 		    dynamic_cast<OutputImageParameter *> (param.GetPointer())->SetPixelType(outPixType);
-		  }
-		  else{ 
-		    if(test!=NULL && test->value!=NULL)
-		      m_Application->SetParameterString(paramKey, test->value);
 		  }
 		}else{
@@ -212,5 +217,6 @@
 			      ext="kml";
 		      }
-		      sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext);
+		      sprintf(tmp,"%s/%s_%d_%s.%s",tmpPath->value,s->name,otbCounter,tmpSid->value,ext);
+		      otbCounter++;
 		      m_Application->SetParameterString(paramKey, tmp);
 		      setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp);
@@ -234,5 +240,5 @@
 				if(strncasecmp(tmpVal->value,"application/vnd.google-earth.kmz",32)==0){
 				  ext="kmz";
-				  sprintf(tmp,"%s/%s_%sxt.%s",tmpPath->value,s->name,tmpSid->value,ext);
+				  sprintf(tmp,"%s/%s_%d_%sxt.%s",tmpPath->value,s->name,otbCounter,tmpSid->value,ext);
 				  m_Application->SetParameterString(paramKey, tmp);
 				  setMapInMaps(outputs,paramKey.c_str(),"expected_generated_file",tmp);
@@ -240,12 +246,37 @@
 
 		      }
-		      sprintf(tmp,"%s/%s_%s.%s",tmpPath->value,s->name,tmpSid->value,ext);
+		      sprintf(tmp,"%s/%s_%d_%s.%s",tmpPath->value,s->name,otbCounter,tmpSid->value,ext);
+		      otbCounter++;
 		      m_Application->SetParameterString(paramKey, tmp);
 		      setMapInMaps(inputs,paramKey.c_str(),"generated_file",tmp);
 		    }
-
+		    else{
+		      test=getMapFromMaps(inputs,paramKey.c_str(),"value");
+		      if(test!=NULL && type!=ParameterType_ListView){
+			m_Application->SetParameterString(paramKey, test->value);
+		      }
+		      else
+			if(type==ParameterType_ListView){
+			  std::vector<std::string> values;
+			  values.push_back(test->value);
+			  map* tmpLength=getMapFromMaps(inputs,paramKey.c_str(),"length");
+			  if(tmpLength!=NULL){
+			    int len=atoi(tmpLength->value);
+			    for(int k=1;k<len;k++){
+			      char tmp[15];
+			      sprintf(tmp,"cache_file_%d",k);
+			      map* tmpVal=getMapFromMaps(inputs,paramKey.c_str(),tmp);
+			      if(tmpVal!=NULL){
+				values.push_back(tmpVal->value);
+			      }
+			    }
+			  }
+			  dynamic_cast<ListViewParameter *> (param.GetPointer())->SetSelectedItems(values);
+			}
+		    }
 		}
 	      }else{
 		if(type == ParameterType_InputImageList){
+		  std::vector<std::string> values;
 		  values.push_back(test->value);
 		  map* tmpPath=getMapFromMaps(inputs,paramKey.c_str(),"length");
Index: trunk/zoo-project/zoo-kernel/service_internal_otb.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_otb.h	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_otb.h	(revision 640)
@@ -31,8 +31,8 @@
 #include "otbWrapperApplicationRegistry.h"
 #include "otbWrapperInputImageListParameter.h"
+#include "otbWrapperListViewParameter.h"
 #include "otbWrapperAddProcessToWatchEvent.h"
 #include "otbZooWatcher.h"
 #include "service_internal.h"
-#include "mimetypes.h"
 #include "service.h"
 #include "cgic.h"
Index: trunk/zoo-project/zoo-kernel/service_internal_python.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_python.h	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_python.h	(revision 640)
@@ -29,4 +29,5 @@
 
 #include "service_internal.h"
+#include "response_print.h"
 #include <Python.h>
 #include "cgic.h"
Index: trunk/zoo-project/zoo-kernel/service_internal_saga.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 640)
@@ -33,4 +33,5 @@
 #define _ZOO_SAGA
 #include "service_internal_saga.h"
+#include "server_internal.h"
 #include "mimetypes.h"
 
Index: trunk/zoo-project/zoo-kernel/zcfg2yaml.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zcfg2yaml.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/zcfg2yaml.c	(revision 640)
@@ -23,5 +23,6 @@
  */
 
-#include "service_internal.h"
+#include "server_internal.h"
+#include "response_print.h"
 #include "service.h"
 
Index: trunk/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 640)
@@ -37,4 +37,5 @@
 #include <unistd.h>
 #include "service_internal.h"
+#include "response_print.h"
 
 
@@ -216,5 +217,4 @@
    * one.
    */
-
   if(strncasecmp(cgiRequestMethod,"post",4)==0 || 
      (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0) 
@@ -287,8 +287,22 @@
 	xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
 	xmlNodeSet* vers=versptr->nodesetval;
-	xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
-	addToMap(tmpMap,"version",(char*)content);
+	if(vers!=NULL && vers->nodeTab!=NULL && vers->nodeTab[0]!=NULL){
+	  xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
+	  addToMap(tmpMap,"version",(char*)content);
+	  xmlFree(content);
+	}
+	if(cur->ns){
+	  addToMap(tmpMap,"wps_schemas",(char*)cur->ns->href);
+	  xmlFree(tval);
+	  int j=0;
+	  for(j=0;j<2;j++)
+	    if(strncasecmp(schemas[j][2],(char*)cur->ns->href,strlen(schemas[j][2]))==0){
+	      char vers[6];
+	      sprintf(vers,"%d.0.0",j+1);
+	      addToMap(tmpMap,"version",(char*)vers);
+	    }
+	}
+	dumpMap(tmpMap);
 	xmlXPathFreeObject(versptr);
-	xmlFree(content);
       }else{
 	tval=NULL;
@@ -376,4 +390,5 @@
     free(strQuery);
 
+  
   runRequest(&tmpMap);
 
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 639)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 640)
@@ -54,5 +54,8 @@
 
 #include "service_internal.h"
+#include "server_internal.h"
+#include "response_print.h"
 #include "request_parser.h"
+#include "sqlapi.h"
 
 #ifdef USE_PYTHON
@@ -1044,4 +1047,6 @@
   r_inputs = getMap (request_inputs, "language");
   if (r_inputs == NULL)
+    r_inputs = getMap (request_inputs, "AcceptLanguages");
+  if (r_inputs == NULL)
     r_inputs = getMapFromMaps (m, "main", "language");
   if (r_inputs != NULL)
@@ -1141,5 +1146,5 @@
     NULL
   };
-  checkValidValue(request_inputs,&err,"Request",(const char**)vvr,1);
+  checkValidValue(request_inputs,&err,"request",(const char**)vvr,1);
   const char *vvs[]={
     "WPS",
@@ -1161,6 +1166,8 @@
   }
   checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
+
   const char *vvv[]={
     "1.0.0",
+    "2.0.0",
     NULL
   };
@@ -1172,5 +1179,16 @@
   }else{
     checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
+    map* version=getMap(request_inputs,"AcceptVersions");
+    if(version!=NULL){
+      if(strstr(version->value,schemas[1][0])!=NULL)
+	addToMap(request_inputs,"version",schemas[1][0]);
+      else
+	addToMap(request_inputs,"version",version->value);
+    }
   }
+  map* version=getMap(request_inputs,"version");
+  if(version==NULL)
+    version=getMapFromMaps(m,"main","version");
+  setMapInMaps(m,"main","rversion",version->value);
   if(err!=NULL){
     printExceptionReportResponse (m, err);
@@ -1237,5 +1255,6 @@
       r_inputs = NULL;
       //r_inputs = getMap (request_inputs, "ServiceProvider");
-      xmlNodePtr n=printGetCapabilitiesHeader(doc,m);
+      r_inputs = getMap (request_inputs, "version");
+      xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(r_inputs!=NULL?r_inputs->value:"1.0.0"));
       /**
        * Here we need to close stdout to ensure that unsupported chars 
@@ -1299,6 +1318,9 @@
           xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
           r_inputs = NULL;
+	  r_inputs = getMap (request_inputs, "version");
+	  map* version=getMapFromMaps(m,"main","rversion");
+	  int vid=getVersionId(version->value);
 	  xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
-					"ProcessDescriptions");
+					root_nodes[vid][1],(r_inputs!=NULL?r_inputs->value:"1.0.0"),1);
 
           r_inputs = getMap (request_inputs, "Identifier");
@@ -1748,4 +1770,5 @@
    *  - usid : it is an unique identification number 
    *  - sid : it is the process idenfitication number (OS)
+   *  - uusid : it is an universally unique identification number 
    *  - status : value between 0 and 100 to express the  completude of 
    * the operations of the running service 
@@ -1777,4 +1800,7 @@
   sprintf (tmpBuff, "%i", cpid);
   addToMap (_tmpMaps->content, "sid", tmpBuff);
+  char* tmpUuid=get_uuid();
+  addToMap (_tmpMaps->content, "uusid", tmpUuid);
+  free(tmpUuid);
   addToMap (_tmpMaps->content, "status", "0");
   addToMap (_tmpMaps->content, "cwd", ntmp);
