Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/Makefile.in	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/Makefile.in	(revision 741)
@@ -38,4 +38,13 @@
 zoo_zcfg.o: zoo_zcfg.c service.h
 	g++ ${GLIB_CPPFLAGS} ${XML2CFLAGS} -c zoo_zcfg.c
+
+logger.o: logger.c
+	gcc -c logger.c
+
+zoo_json.o: zoo_json.c service.h
+	g++ ${JSON_CPPFLAGS} ${XML2CFLAGS} -c zoo_json.c
+
+zoo_amqp.o: zoo_amqp.c
+	g++ ${CFLAGS} -c zoo_amqp.c
 
 request_parser.o: request_parser.c request_parser.h
@@ -94,12 +103,17 @@
 
 zoo_service_loader.o: zoo_service_loader.c service.h
-	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
+	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${JSON_CPPFLAGS} ${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
 
 libzoo_service.${EXT}: version.h service_internal.o service.o sqlapi.o
 	gcc -shared  ${GDAL_CFLAGS} ${DEFAULT_OPTS} -fpic -o libzoo_service.${EXT} ${CFLAGS}  service_internal.o service.o sqlapi.o -lfcgi ${GDAL_LIBS}
 
-zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_loader.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
-	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
-	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
+zoo_loader.cgi: version.h libzoo_service.${EXT} zoo_json.o zoo_amqp.o zoo_loader.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
+	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${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 ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -L. ${LDFLAGS}
+
+zoo_fpm: version.h libzoo_service.${EXT} logger.o zoo_json.o zoo_amqp.o zoo_fpm.c zoo_service_loader.o  ulinet.o zoo_zcfg.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o request_parser.o response_print.o server_internal.o caching.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${RABBITMQ_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
+	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${JSON_CPPFLAGS} ${CFLAGS} -c zoo_fpm.c  -fno-common -DPIC -o zoo_fpm.o
+	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} logger.o zoo_fpm.o zoo_service_loader.o ${RABBITMQ_FILE}  ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} response_print.o server_internal.o caching.o request_parser.o ulinet.o zoo_json.o zoo_zcfg.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_fpm -L. ${LDFLAGS}
+
 
 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ZOOMakefile.opts.in
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 741)
@@ -55,4 +55,11 @@
 RUBY_FILE=@RUBY_FILE@
 
+JSON_LDFLAGS=@JSON_LDFLAGS@
+JSON_CPPFLAGS=@JSON_CPPFLAGS@
+
+RABBITMQ_LDFLAGS=@RABBITMQ_LDFLAGS@
+RABBITMQ_CPPFLAGS=@RABBITMQ_CPPFLAGS@
+RABBITMQ_FILE=@RABBITMQ_FILE@
+
 JS_ENABLED=@JS_ENABLED@
 JSCFLAGS=@JS_CPPFLAGS@
@@ -96,5 +103,5 @@
 SAGA_FILE=@SAGA_FILE@
 
-CFLAGS=@RELY_ON_DB@ @DEB_DEF@ -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
-LDFLAGS=-lzoo_service @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
+CFLAGS= @RELY_ON_DB@ @DEB_DEF@ -fpic ${GLIB_CPPFLAGS} ${YAML_CFLAGS} ${GDAL_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} ${RABBITMQ_CPPFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+LDFLAGS=-lzoo_service @DEFAULT_LIBS@ -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${GLIB_LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS} ${JSON_LDFLAGS} ${RABBITMQ_LDFLAGS} ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto -luuid ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
 
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/caching.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/caching.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/caching.c	(revision 741)
@@ -215,5 +215,5 @@
 	    fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
 	    if(fcontent == NULL){
-	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
 	    }
 	    size_t dwRead;
@@ -233,5 +233,5 @@
 	    tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
 	    if(tmpMap->value==NULL){
-	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
 	    }
 	    memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
@@ -277,5 +277,5 @@
 void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
   hInternet->waitingRequests[hInternet->nb]=strdup(url);
-  hInternet->ihandle[hInternet->nb].header=NULL;
+  //hInternet->ihandle[hInternet->nb].header=NULL;
   if(req)
     InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
@@ -304,5 +304,5 @@
  */
 int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
-  char* fcontent;
+  char* fcontent = NULL;
   char* cached=isInCache(*m,url);
   char *mimeType=NULL;
@@ -338,10 +338,10 @@
     }
 
-  }else{    
+  }else{
     addRequestToQueue(m,hInternet,url,true);
     return 0;
   }
   if(fsize==0){
-    return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
+    return errorException(*m, _("Unable to download the file."), "InternalError",NULL,NULL);
   }
   if(mimeType!=NULL){
@@ -354,7 +354,15 @@
 
   tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
-  if(tmpMap->value==NULL)
-    return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+ 
+ if(tmpMap->value==NULL || fcontent == NULL)
+    return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL,NULL);
   memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
+
+ 
+ 
+ 
+  //if(tmpMap->value==NULL)
+    //return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL,NULL);
+  //memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
 
   char ltmp1[256];
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/configure.ac
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/configure.ac	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/configure.ac	(revision 741)
@@ -58,4 +58,25 @@
 AC_SUBST([RELY_ON_DB])
 
+
+AC_ARG_WITH([rabbitmq],
+    [AS_HELP_STRING([--with-rabbittmq], [asynchronous requests management with rabbitmq  ])],
+    [AMQP="-DAMQP"], [AMQP=""])
+
+if test -z "$AMQP"
+then
+    RABBITMQ_LDFLAGS=""
+    RABBITMQ_CPPFLAGS=""
+    RABBITMQ_FILE=""
+else
+    AC_CHECK_LIB([rabbitmq], [main])
+    RABBITMQ_LDFLAGS=`pkg-config --libs librabbitmq`
+    RABBITMQ_CPPFLAGS="-DAMQP" `pkg-config --cflags librabbitmq`
+    RABBITMQ_FILE="zoo_amqp.o"
+    RELY_ON_DB="-DRELY_ON_DB"
+    AC_SUBST([RELY_ON_DB])
+fi
+AC_SUBST([RABBITMQ_LDFLAGS])
+AC_SUBST([RABBITMQ_CPPFLAGS])
+AC_SUBST([RABBITMQ_FILE])
 
 # ===========================================================================
@@ -418,6 +439,7 @@
 	LIBS_SAVE="$LIBS"
 	LIBS="$PYTHON_LDFLAGS"
-	PY_LIB=`$PYTHONCONFIG --libs | sed -e 's/^.*\(python2\..\)$/\1/'`
-	AC_CHECK_LIB([$PY_LIB], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
+	#PY_LIB=`$PYTHONCONFIG --libs | sed -e 's/^.*\(python2\..\)$/\1/'`
+	#PY_LIB=`$PYTHONCONFIG --libs`
+	#AC_CHECK_LIB([$PY_LIB], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
 	AC_SUBST([PYTHON_CPPFLAGS])
 	AC_SUBST([PYTHON_LDFLAGS])
@@ -598,4 +620,17 @@
 AC_SUBST([JAVA_FILE])
 
+
+# ===========================================================================
+# Detect if json-c is available
+# ===========================================================================
+
+AC_CHECK_LIB([json-c], [main])
+JSON_LDFLAGS=`pkg-config --libs json-c`
+JSON_CPPFLAGS=`pkg-config --cflags json-c`
+
+AC_SUBST([JSON_LDFLAGS])
+AC_SUBST([JSON_CPPFLAGS])
+
+
 # ===========================================================================
 # Detect if ruby is installed
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.c	(revision 741)
@@ -92,5 +92,5 @@
 		       _("The maximum allowed occurrences for <%s> (%i) was exceeded."),
 		       mi->name, atoi (testMap->value));
-	      errorException (m, emsg, "InternalError", NULL);
+	      errorException (m, emsg, "InternalError", NULL,NULL);
 	      return -1;
 	    }
@@ -113,5 +113,5 @@
 			   ("ZOO-Kernel was unable to load your data for %s position %s."),
 			   mi->name, tmpMap->value);
-		  errorException (m, emsg, "InternalError", NULL);
+		  errorException (m, emsg, "InternalError", NULL,NULL);
 		  return -1;
 		}
@@ -124,5 +124,5 @@
 		       ("The maximum allowed occurrences for <%s> is one."),
 		       mi->name);
-	      errorException (m, emsg, "InternalError", NULL);
+	      errorException (m, emsg, "InternalError", NULL,NULL);
 	      return -1;
 	    }
@@ -213,5 +213,5 @@
 	free(cursor_input);
 	return errorException (*main_conf, _("Unable to allocate memory."),
-			       "InternalError", NULL);
+			       "InternalError", NULL,NULL);
       }
     int i = 0;
@@ -224,5 +224,5 @@
 	    free(cursor_input);
 	    return errorException (*main_conf, _("Unable to allocate memory."),
-				   "InternalError", NULL);
+				   "InternalError", NULL,NULL);
 	  }
 	snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
@@ -261,5 +261,5 @@
 		    return errorException (*main_conf,
 					   _("Unable to allocate memory."),
-					   "InternalError", NULL);
+					   "InternalError", NULL,NULL);
 		  }
 		tmpmaps->name = zStrdup (tmpn);
@@ -316,15 +316,14 @@
 				 tmpv1 + 1);
 			free(cursor_input);
-			return errorException (*main_conf, emsg, "InternalError", NULL);
+			return errorException (*main_conf, emsg, "InternalError", NULL,NULL);
 		      }
 		    addToMap (tmpmaps->content, tmpn1, tmpx2);
-		    {
 		      if (loadRemoteFile
 			  (&*main_conf, &tmpmaps->content, hInternet, tmpx2) < 0)
 			{
 			  free(cursor_input);
-			  return errorException (*main_conf, "Unable to fetch any ressource", "InternalError", NULL);
+			  return errorException (*main_conf, "Unable to fetch any ressource", "InternalError", NULL,NULL);
 			}
-		      }
+		      
 		    free (tmpx2);
 		    addIntToMap (tmpmaps->content, "Order", hInternet->nb);
@@ -350,5 +349,5 @@
 			  {
 			    free(cursor_input);
-			    return errorException (*main_conf, "Unable to append maps", "InternalError", NULL);
+			    return errorException (*main_conf, "Unable to append maps", "InternalError", NULL,NULL);
 			  }
 		      }
@@ -402,5 +401,5 @@
 	  free(cursor_output);
 	  return errorException (*main_conf, _("Unable to allocate memory"),
-				 "InternalError", NULL);
+				 "InternalError", NULL,NULL);
 	}
       int i = 0;
@@ -413,5 +412,5 @@
 	      free(cursor_output);
 	      return errorException (*main_conf, _("Unable to allocate memory"),
-				     "InternalError", NULL);
+				     "InternalError", NULL,NULL);
 	    }
 	  snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s",
@@ -440,5 +439,5 @@
 						 _
 						 ("Unable to allocate memory."),
-						 "InternalError", NULL);
+						 "InternalError", NULL,NULL);
 			}
 		      tmp_output->name = zStrdup (tmpc);
@@ -536,5 +535,5 @@
 						 _
 						 ("Unable to allocate memory."),
-						 "InternalError", NULL);
+						 "InternalError", NULL,NULL);
 			}
 		      tmpmaps->name = zStrdup ((char *) val);
@@ -561,5 +560,5 @@
 						 _
 						 ("Unable to allocate memory."),
-						 "InternalError", NULL);
+						 "InternalError", NULL,NULL);
 			}
 		      tmpmaps->name = zStrdup ("missingIndetifier");
@@ -613,5 +612,5 @@
 							     _("Unable to add a request in the queue."),
 							     "InternalError",
-							     NULL);
+							     NULL,NULL);
 				    }
 				  addIntToMap (tmpmaps->content, "Order", hInternet->nb);
@@ -665,5 +664,5 @@
 							     ("Unable to allocate memory."),
 							     "InternalError",
-							     NULL);
+							     NULL,NULL);
 				    }
 				  snprintf (has,
@@ -675,11 +674,12 @@
 			      xmlFree (val);
 			    }
-			  hInternet->ihandle[hInternet->nb].header = NULL;
-			  hInternet->ihandle[hInternet->nb].header =
-			    curl_slist_append (hInternet->ihandle
-					       [hInternet->nb].header,
-					       has);
-			  if (has != NULL)
-			    free (has);
+                if (has != NULL){
+                            hInternet->ihandle[hInternet->nb].header = NULL;
+                            hInternet->ihandle[hInternet->nb].header =
+                              curl_slist_append (hInternet->ihandle
+                                                 [hInternet->nb].header,
+                                                 has);
+                            free (has);
+                }
 			}
 		      else
@@ -781,5 +781,5 @@
 							   ("Unable to allocate memory."),
 							   "InternalError",
-							   NULL);
+							   NULL,NULL);
 				  }
 				size_t bRead;
@@ -951,5 +951,5 @@
 				  xmlDocDumpFormatMemoryEnc (doc1, &mv,
 							     &buffersize,
-							     "utf-8", 1);
+							     "utf-8", 0);
 				  char size[1024];
 				  sprintf (size, "%d", buffersize);
@@ -966,10 +966,7 @@
 				    xmlDocDumpFormatMemoryEnc (doc1, &mv,
 							       &buffersize,
-							       "utf-8", 1);
-				    char size[1024];
-				    sprintf (size, "%d", buffersize);
-				    addToMap (tmpmaps->content, "size",
-					      size);
-				    xmlFreeDoc (doc2);
+							       "utf-8", 0);
+				    addIntToMap(tmpmaps->content, "size",buffersize);
+                    xmlFreeDoc (doc2);
 				    xmlFreeDoc (doc1);
 				  }
@@ -1024,5 +1021,5 @@
 					       _("Unable to append maps to maps."),
 					       "InternalError",
-					       NULL);
+					       NULL,NULL);
 		      }
 		  }
@@ -1113,5 +1110,5 @@
 	    {
 	      return errorException (*main_conf, _("Unable to allocate memory."),
-				     "InternalError", NULL);
+				     "InternalError", NULL,NULL);
 	    }
 	  tmpmaps->name = zStrdup ("unknownIdentifier");
@@ -1205,5 +1202,5 @@
 				     _
 				     ("Unable to allocate memory."),
-				     "InternalError", NULL);
+				     "InternalError", NULL,NULL);
 	    }
 	    tmpmaps->name = zStrdup ("unknownIdentifier");
@@ -1292,5 +1289,5 @@
 				     _
 				     ("Duplicate <Output> elements in WPS Execute request"),
-				     "InternalError", NULL);
+				     "InternalError", NULL,NULL);
 	    }
 	    else {
@@ -1320,5 +1317,5 @@
  * @return 0 on success, -1 on failure
  */
-int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){
+int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet,struct cgi_env *cgi){
 
   map* version=getMapFromMaps(*main_conf,"main","rversion");
@@ -1326,5 +1323,5 @@
 
   xmlInitParser ();
-  xmlDocPtr doc = xmlParseMemory (post, cgiContentLength);
+  xmlDocPtr doc = xmlParseMemory (post, cgi->cgiContentLength);
 
   /**
@@ -1428,5 +1425,5 @@
  * @see kvpParseOutputs,kvpParseInputs,xmlParseRequest
  */
-int parseRequest(maps** main_conf,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){
+int parseRequest(maps** main_conf,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet,struct cgi_env *cgi){
   map *postRequest = NULL;
   postRequest = getMap (*request_inputs, "xrequest");
@@ -1443,5 +1440,5 @@
     {
       //Parse XML request
-      if(xmlParseRequest(main_conf,postRequest->value,request_inputs,s,inputs,outputs,hInternet)<0){
+      if(xmlParseRequest(main_conf,postRequest->value,request_inputs,s,inputs,outputs,hInternet,cgi)<0){
 	return -1;
       }
@@ -1465,9 +1462,13 @@
  * @see runHttpRequests
  */
-int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet){
-
+int validateRequest(maps** main_conf,service* s,map* original_request, maps** request_inputs,maps** request_outputs,HINTERNET* hInternet,struct cgi_env * cgi){
+  fprintf(stderr,"STEP 1 VALIDATE \n");
+  
   runHttpRequests (main_conf, request_inputs, hInternet);
+fprintf(stderr,"STEP 2 VALIDATE \n");
+  
   InternetCloseHandle (hInternet);
-
+  fprintf(stderr,"STEP 3 VALIDATE \n");
+                
   map* errI=NULL;
   char *dfv = addDefaultValues (request_inputs, s->inputs, *main_conf, 0,&errI);
@@ -1491,5 +1492,5 @@
               addToMap (tmpe, "locator", ptr->name);
               addToMap (tmpe, "text", tmps);
-              printExceptionReportResponse (*main_conf, tmpe);
+              printExceptionReportResponse (*main_conf, tmpe,NULL);
               freeMap (&tmpe);
               free (tmpe);
@@ -1499,8 +1500,11 @@
       ptr = ptr->next;
     }
-
+fprintf(stderr,"STEP 4 VALIDATE \n");
+  dumpMaps(*request_outputs);
   map* errO=NULL;
   char *dfv1 =
     addDefaultValues (request_outputs, s->outputs, *main_conf, 1,&errO);
+    fprintf(stderr,"STEP 4 - 1 VALIDATE \n");
+  
   if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
     {
@@ -1526,4 +1530,6 @@
 	  }
 	}
+    fprintf(stderr,"STEP 4 - 2 VALIDATE \n");
+  
       if (strcmp (dfv1, "") != 0)
         {
@@ -1553,5 +1559,7 @@
 	  }
 	}
-      printExceptionReportResponse (*main_conf, tmpe);
+    fprintf(stderr,"STEP 4 - 3 VALIDATE \n");
+  
+      printExceptionReportResponse (*main_conf, tmpe,NULL);
       if(errI!=NULL){
 	freeMap(&errI);
@@ -1567,4 +1575,6 @@
     }
   maps *tmpReqI = *request_inputs;
+  fprintf(stderr,"STEP 5 VALIDATE \n");
+  
   while (tmpReqI != NULL)
     {
@@ -1572,5 +1582,5 @@
       if (getMap (tmpReqI->content, "isFile") != NULL)
         {
-          if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) ==
+          if (cgiFormFileName (tmpReqI->name, name, sizeof (name),&cgi) ==
               cgiFormSuccess)
             {
@@ -1586,8 +1596,8 @@
               int got, t;
               map *path = getMapFromMaps (*main_conf, "main", "tmpPath");
-              cgiFormFileSize (tmpReqI->name, &size);
+              cgiFormFileSize (tmpReqI->name, &size,&cgi);
               cgiFormFileContentType (tmpReqI->name, contentType,
-                                      sizeof (contentType));
-              if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess)
+                                      sizeof (contentType),&cgi);
+              if (cgiFormFileOpen (tmpReqI->name, &file,&cgi) == cgiFormSuccess)
                 {
                   t = -1;
@@ -1643,5 +1653,6 @@
       tmpReqI = tmpReqI->next;
     }
-
+fprintf(stderr,"STEP FINAL VALIDATE \n");
+  
   ensureDecodedBase64 (request_inputs);
   return 1;
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.h	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/request_parser.h	(revision 741)
@@ -44,8 +44,8 @@
   int xmlParseInputs(maps**,service*,maps**,xmlDocPtr,xmlNodeSet*,HINTERNET*);
   int xmlParseOutputs(maps**,map**,maps**,xmlDocPtr,xmlNodePtr,bool);
-  int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*);
-  int parseRequest(maps**,map**,service*,maps**,maps**,HINTERNET*);
+  int xmlParseRequest(maps**,const char*,map**,service*,maps**,maps**,HINTERNET*,struct cgi_env *);
+  int parseRequest(maps**,map**,service*,maps**,maps**,HINTERNET*,struct cgi_env *);
   void checkValidValue(map*,map**,const char*,const char**,int);
-  int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*);
+  int validateRequest(maps**,service*,map*,maps**,maps**,HINTERNET*,struct cgi_env *);
 
 #ifdef __cplusplus
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.c	(revision 741)
@@ -93,10 +93,10 @@
  * @param m the map containing the headers informations
  */
-void printHeaders(maps* m){
+void printHeaders(maps* m,FCGX_Stream *out){
   maps *_tmp=getMaps(m,"headers");
   if(_tmp!=NULL){
     map* _tmp1=_tmp->content;
     while(_tmp1!=NULL){
-      printf("%s: %s\r\n",_tmp1->name,_tmp1->value);
+      FCGX_FPrintF(out,"%s: %s\r\n", _tmp1->name, _tmp1->value);
       _tmp1=_tmp1->next;
     }
@@ -1445,5 +1445,5 @@
  * @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){
+void printProcessResponse(maps* m,map* request, int pid,service* serv,const char* service,int status,maps* inputs,maps* outputs,FCGX_Stream * out){
   xmlNsPtr ns,ns_ows,ns_xlink;
   xmlNodePtr nr,n,nc,nc1=NULL,nc3;
@@ -1540,5 +1540,4 @@
       hasStoredExecuteResponse=true;
     }
-
     nc = xmlNewNode(ns, BAD_CAST "Process");
     map* tmp2=getMap(serv->content,"processVersion");
@@ -1548,5 +1547,4 @@
     map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
     printDescription(nc,ns_ows,tmpI->value,serv->content,0);
-
     xmlAddChild(n,nc);
 
@@ -1695,5 +1693,5 @@
     if(lid<0){
       /* If the lock failed */
-      errorException(m,_("Lock failed."),"InternalError",NULL);
+      errorException(m,_("Lock failed."),"InternalError",NULL,out);
       xmlFreeDoc(doc);
       xmlCleanupParser();
@@ -1710,5 +1708,5 @@
 	sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the ExecuteResponse."),stored_path);
 
-	errorException(m,tmpMsg,"InternalError",NULL);
+	errorException(m,tmpMsg,"InternalError",NULL,out);
 	xmlFreeDoc(doc);
 	xmlCleanupParser();
@@ -1738,5 +1736,5 @@
 #endif
   }
-  printDocument(m,doc,pid);
+  printDocument(m,doc,pid,out);
 
   xmlCleanupParser();
@@ -1751,11 +1749,10 @@
  * @param pid the process identifier linked to a service
  */
-void printDocument(maps* m, xmlDocPtr doc,int pid){
+void printDocument(maps* m, xmlDocPtr doc,int pid,FCGX_Stream * out){
   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);
+    printHeaders(m,out);
+    FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+  }
   xmlChar *xmlbuff;
   int buffersize;
@@ -1765,6 +1762,8 @@
    */
   xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  printf("%s",xmlbuff);
-  fflush(stdout);
+  if (out != NULL){
+    FCGX_FPrintF(out,(char *)xmlbuff);
+    FCGX_FFlush(out);
+  }
   /*
    * Free associated memory.
@@ -2099,5 +2098,5 @@
  * @param s the map containing the text,code,locator keys
  */
-void printExceptionReportResponse(maps* m,map* s){
+void printExceptionReportResponse(maps* m,map* s,FCGX_Stream * out){
   if(getMapFromMaps(m,"lenv","hasPrinted")!=NULL)
     return;
@@ -2135,20 +2134,21 @@
     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);
-      }
+	printHeaders(m,out);
+    FCGX_FPrintF(out,"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);
+      printHeaders(m,out);
+      FCGX_FPrintF(out,"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);
-  }
+    FCGX_FPrintF(out,"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);
+  FCGX_FPrintF(out,"%s",xmlbuff);
+  FCGX_FFlush(out);
+
   xmlFreeDoc(doc);
   xmlFree(xmlbuff);
@@ -2161,5 +2161,5 @@
 /**
  * Create an OWS ExceptionReport Node.
- * 
+ * FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: %s\r\n\r\n",encoding, exceptionCode);
  * @param m the conf maps
  * @param s the map containing the text,code,locator keys
@@ -2241,5 +2241,5 @@
  * @param locator the potential locator
  */
-int errorException(maps *m, const char *message, const char *errorcode, const char *locator) 
+int errorException(maps *m, const char *message, const char *errorcode, const char *locator,FCGX_Stream * out) 
 {
   map* errormap = createMap("text", message);
@@ -2249,5 +2249,5 @@
   else
     addToMap(errormap,"locator", "NULL");
-  printExceptionReportResponse(m,errormap);
+  printExceptionReportResponse(m,errormap,out);
   freeMap(&errormap);
   free(errormap);
@@ -2267,5 +2267,5 @@
  */
 void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
-		    map* request_inputs1,int cpid,maps* m,int res){
+		    map* request_inputs1,int cpid,maps* m,int res,FCGX_Stream * out){
 #ifdef DEBUG
   dumpMaps(request_inputs);
@@ -2278,13 +2278,12 @@
     asRaw=1;
   map* version=getMapFromMaps(m,"main","rversion");
-  int vid=getVersionId(version->value);
-  
-  maps* tmpSess=getMaps(m,"senv");
+   int vid=getVersionId(version->value);
+   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");
+      FCGX_FPrintF(out,"Set-Cookie: %s; HttpOnly\r\n",_tmp->value);
+      FCGX_FPrintF(out,"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,";");
@@ -2314,5 +2313,5 @@
       char tmpMsg[1024];
       sprintf(tmpMsg,_("Unable to create the file \"%s\" for storing the session maps."),session_file_path);
-      errorException(m,tmpMsg,"InternalError",NULL);
+      errorException(m,tmpMsg,"InternalError",NULL,out);
 
       return;
@@ -2323,5 +2322,4 @@
     }
   }
-  
   if(res==SERVICE_FAILED){
     map *lenv;
@@ -2336,19 +2334,17 @@
       sprintf(tmp0,"%s",_("Unable to run the Service. No more information was returned back by the Service."));
     }
-    errorException(m,tmp0,"InternalError",NULL);
+    errorException(m,tmp0,"InternalError",NULL,out);
     free(tmp0);
     return;
   }
-
   if(res==SERVICE_ACCEPTED && vid==1){
     map* statusInfo=createMap("Status","Accepted");
     map *usid=getMapFromMaps(m,"lenv","usid");
     addToMap(statusInfo,"JobID",usid->value);
-    printStatusInfo(m,statusInfo,"Execute");
+    printStatusInfo(m,statusInfo,"Execute",out);
     freeMap(&statusInfo);
     free(statusInfo);
     return;
   }
-
   map *tmp1=getMapFromMaps(m,"main","tmpPath");
   if(asRaw==0){
@@ -2411,5 +2407,4 @@
 	      getFileExtension(mtype != NULL ? mtype->value : NULL, file_ext, 32);
 	    }
-		
 	    file_name=(char*)malloc((strlen(s->name)+strlen(usid->value)+strlen(file_ext)+strlen(tmpI->name)+45)*sizeof(char));
 	    sprintf(file_name,"%s_%s_%s_%d.%s",s->name,tmpI->name,usid->value,itn,file_ext);
@@ -2422,5 +2417,5 @@
 	      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);
+	      errorException(m,tmpMsg,"InternalError",NULL,out);
 	      free(file_name);
 	      free(file_path);
@@ -2428,5 +2423,4 @@
 	    }
 	    free(file_path);
-
 	    toto=getMap(tmpI->content,"value");
 	    if(strcasecmp(format,"BoundingBoxData")!=0){
@@ -2438,10 +2432,10 @@
 		  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
 	    }else{
-	      printBoundingBoxDocument(m,tmpI,ofile);
+	      printBoundingBoxDocument(m,tmpI,ofile,out);
 	    }
 	    fclose(ofile);
 
 	  }
-	  map *tmp2=getMapFromMaps(m,"main","tmpUrl");
+      map *tmp2=getMapFromMaps(m,"main","tmpUrl");
 	  map *tmp3=getMapFromMaps(m,"main","serverAddress");
 	  char *file_url;
@@ -2473,8 +2467,10 @@
     dumpMaps(m);
 #endif
+
     printProcessResponse(m,request_inputs1,cpid,
 			 s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
 			 request_inputs,
-			 request_outputs);
+			 request_outputs,out);
+
   }
   else{
@@ -2492,5 +2488,5 @@
     elements* e=getElements(s->outputs,tmpI->name);
     if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
-      printBoundingBoxDocument(m,tmpI,NULL);
+      printBoundingBoxDocument(m,tmpI,NULL,out);
     }else{
       map *gfile=getMap(tmpI->content,"generated_file");
@@ -2506,14 +2502,14 @@
 	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");
+	errorException(m,tmpMsg,"InvalidParameterValue","RawDataOutput",out);
 	return;
       }
       map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
       if(fname!=NULL)
-	printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
+      FCGX_FPrintF(out,"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);
+      FCGX_FPrintF(out,"Content-Length: %s\r\n",rs->value);
+      printHeaders(m,out);
       char mime[1024];
       map* mi=getMap(tmpI->content,"mimeType");
@@ -2524,20 +2520,21 @@
 #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);
+      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");
+      }
+      FCGX_FPrintF(out,"%s",mime);
+      if(rs!=NULL){
+        FCGX_PutStr(toto->value,atoi(rs->value),out);
+      }
+      else {
+        FCGX_PutStr(toto->value,strlen (toto->value),out);
+      }
+    FCGX_FFlush(out);
 #ifdef DEBUG
       dumpMap(toto);
@@ -2659,7 +2656,5 @@
  * @see parseBoundingBox, printBoundingBox
  */
-void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file){
-  if(file==NULL)
-    rewind(stdout);
+void printBoundingBoxDocument(maps* m,maps* boundingbox,FILE* file,FCGX_Stream * out){
   xmlNodePtr n;
   xmlDocPtr doc;
@@ -2675,7 +2670,8 @@
       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);
+      
+      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+    }
+    FCGX_FFlush(out);
   }
 
@@ -2695,5 +2691,5 @@
   xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
   if(file==NULL)
-    printf("%s",xmlbuff);
+   FCGX_FPrintF(out,"%s",xmlbuff);
   else{
     fprintf(file,"%s",xmlbuff);
@@ -2723,6 +2719,6 @@
  * @param req the WPS requests (GetResult, GetStatus or Dismiss)
  */
-void printStatusInfo(maps* conf,map* statusInfo,char* req){
-  rewind(stdout);
+void printStatusInfo(maps* conf,map* statusInfo,char* req,FCGX_Stream * out){
+  //rewind(stdout);
   xmlNodePtr n,n1;
   xmlDocPtr doc;
@@ -2733,9 +2729,9 @@
   map *tmp;
   int pid=0;
-  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+  
+  FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
 
   map* version=getMapFromMaps(conf,"main","rversion");
   int vid=getVersionId(version->value);
-
   doc = xmlNewDoc(BAD_CAST "1.0");
   n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
@@ -2772,6 +2768,5 @@
 
   xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
-  printf("%s",xmlbuff);
-
+  FCGX_FPrintF(out,"%s",xmlbuff);
   xmlFree(xmlbuff);
   xmlFreeDoc(doc);
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.h	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/response_print.h	(revision 741)
@@ -25,4 +25,6 @@
 #ifndef ZOO_RESPONSE_PRINT_H
 #define ZOO_RESPONSE_PRINT_H 1
+
+#include <fcgiapp.h>
 
 #pragma once 
@@ -69,5 +71,5 @@
 #include <direct.h>
 #endif
-#include <stdio.h>
+
 #include <time.h>
 #include <ctype.h>
@@ -201,7 +203,7 @@
   void zooXmlCleanupDocs();
   
-  void printExceptionReportResponse(maps*,map*);
+  void printExceptionReportResponse(maps*,map*,FCGX_Stream *);
   xmlNodePtr createExceptionReportNode(maps*,map*,int);
-  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*);
+  void printProcessResponse(maps*,map*,int,service*,const char*,int,maps*,maps*,FCGX_Stream *);
   xmlNodePtr printWPSHeader(xmlDocPtr,maps*,const char*,const char*,const char*,int);
   xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,maps*,const char*);
@@ -209,16 +211,16 @@
   void printDescribeProcessForProcess(maps*,xmlNodePtr,service*);
   void printFullDescription(int,elements*,const char*,xmlNsPtr,xmlNsPtr,xmlNodePtr,int);
-  void printDocument(maps*,xmlDocPtr,int);
+  void printDocument(maps*,xmlDocPtr,int,FCGX_Stream *);
   void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
   void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
   map* parseBoundingBox(const char*);
   void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
-  void printBoundingBoxDocument(maps*,maps*,FILE*);
+  void printBoundingBoxDocument(maps*,maps*,FILE*,FCGX_Stream *);
   void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
-  void printStatusInfo(maps*,map*,char*);
-
-  void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
-
-  int errorException(maps *, const char *, const char *, const char*);
+  void printStatusInfo(maps*,map*,char*,FCGX_Stream *);
+
+  void outputResponse(service*,maps*,maps*,map*,int,maps*,int,FCGX_Stream *);
+
+  int errorException(maps *, const char *, const char *, const char*,FCGX_Stream *);
 
   xmlNodePtr soapEnvelope(maps*,xmlNodePtr);
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.c	(revision 741)
@@ -850,10 +850,10 @@
  * @param req the request (GetStatus / GetResult)
  */
-void runGetStatus(maps* conf,char* pid,char* req){
+void runGetStatus(maps* conf,char* pid,char* req,FCGX_Stream* out){
   map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
   char *sid=getStatusId(conf,pid);
   if(sid==NULL){
     errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
-		    "NoSuchJob", pid);
+		    "NoSuchJob", pid,out);
   }else{
     map* statusInfo=createMap("JobID",pid);
@@ -861,5 +861,5 @@
       if(strncasecmp(req,"GetResult",strlen(req))==0){
 	errorException (conf, _("The result for the requested JobID has not yet been generated. "),
-			"ResultNotReady", pid);
+			"ResultNotReady", pid,out);
 	return;
       }
@@ -885,7 +885,7 @@
 	if(result!=NULL){
 	  char *encoding=getEncoding(conf);
-	  fprintf(stdout,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
-	  fprintf(stdout,"%s",result);
-	  fflush(stdout);
+      FCGX_FPrintF(out,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+      FCGX_FPrintF(out,"%s",result);
+      FCGX_FFlush(out);
 	  freeMap(&statusInfo);
 	  free(statusInfo);
@@ -893,5 +893,5 @@
 	}else{
 	  errorException (conf, _("The result for the requested JobID has not yet been generated. "),
-			  "ResultNotReady", pid);
+			  "ResultNotReady", pid,out);
 	  freeMap(&statusInfo);
 	  free(statusInfo);
@@ -914,5 +914,5 @@
 	}
     }
-    printStatusInfo(conf,statusInfo,req);
+    printStatusInfo(conf,statusInfo,req,out);
     freeMap(&statusInfo);
     free(statusInfo);
@@ -927,10 +927,10 @@
  * @param pid the service identifier (usid key from the [lenv] section)
  */
-void runDismiss(maps* conf,char* pid){
+void runDismiss(maps* conf,char* pid,FCGX_Stream* out){
   map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
   char *sid=getStatusId(conf,pid);
   if(sid==NULL){
     errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
-		    "NoSuchJob", pid);
+		    "NoSuchJob", pid,out);
   }else{
     // We should send the Dismiss request to the target host if it differs
@@ -967,5 +967,5 @@
 	  if(unlink(fileName)!=0){
 	    errorException (conf, _("The job cannot be removed, a file cannot be removed"),
-			    "NoApplicableCode", NULL);
+			    "NoApplicableCode", NULL,out);
 	    return;
 	  }
@@ -978,5 +978,5 @@
     map* statusInfo=createMap("JobID",pid);
     addToMap(statusInfo,"Status","Dismissed");
-    printStatusInfo(conf,statusInfo,"Dismiss");
+    printStatusInfo(conf,statusInfo,"Dismiss",out);
     free(statusInfo);
   }
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.h	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/server_internal.h	(revision 741)
@@ -31,5 +31,5 @@
 #include <openssl/bio.h>
 #include <openssl/buffer.h>
-
+#include <fcgiapp.h>
 extern   int conf_read(const char*,maps*);
 
@@ -52,6 +52,6 @@
   void parseIdentifier(maps*,char*,char*,char*);
   void dumpMapsValuesToFiles(maps**,maps**);
-  void runDismiss(maps*,char*);
-  void runGetStatus(maps*,char*,char*);
+  void runDismiss(maps*,char*,FCGX_Stream*);
+  void runGetStatus(maps*,char*,char*,FCGX_Stream*);
 
   int isValidLang(maps*,const char*);
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.c	(revision 741)
@@ -23,5 +23,4 @@
  */
 
-#include "fcgi_stdio.h"
 #include "service_internal.h"
 #ifdef USE_MS
@@ -293,5 +292,5 @@
 
 #include <windows.h>
-#include <fcgi_stdio.h>
+//#include <fcgi_stdio.h>
 #include <stdio.h>
 #include <conio.h>
@@ -689,5 +688,6 @@
     VSILFILE * fichier=VSIFOpenL(dataSource,"rb");
     VSIStatBuf file_status;
-    VSIStat(dataSource, &file_status);
+    VSIStatL(dataSource,&file_status);
+    //file_status.st_size = 2500;
     if(fichier==NULL){
       char tmp[1024];
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.h	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/service_internal.h	(revision 741)
@@ -26,4 +26,7 @@
 #define ZOO_SERVICE_INTERNAL_H 1
 
+
+#include <fcgiapp.h>
+
 #pragma once 
 
@@ -37,5 +40,5 @@
 #define TIME_SIZE 40
 
-#include <libintl.h>
+//#include <libintl.h>
 #include <locale.h>
 /**
@@ -65,6 +68,7 @@
 #define ZOO_LOCK_MAX_RETRY 10
 
-#include <sys/stat.h>
-#include <sys/types.h>
+//#include <sys/stat.h>
+//#include <sys/types.h>
+
 #ifndef WIN32
 #include <sys/ipc.h>
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/sqlapi.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/sqlapi.c	(revision 741)
@@ -29,5 +29,5 @@
 
 #include "sqlapi.h"
-#include <fcgi_stdio.h>
+//#include <fcgi_stdio.h>
 #include <stdlib.h>
 
@@ -183,4 +183,5 @@
     sprintf(sqlQuery,"INSERT INTO %s.files (uuid,filename,nature,name) VALUES ('%s','%s','%s',NULL);",schema->value,uusid->value,filename,type);
   execSql(conf,sqlQuery);
+  free(sqlQuery);
   cleanUpResultSet(conf);
 }
@@ -206,4 +207,5 @@
 	  uusid->value,sid->value,osid->value);
   execSql(conf,sqlQuery);
+  free(sqlQuery);
   cleanUpResultSet(conf);
 }
@@ -229,4 +231,6 @@
   sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
   execSql(conf,sqlQuery);
+  free(sqlQuery);
+  free(tmps);
   cleanUpResultSet(conf);
 }
@@ -250,4 +254,5 @@
   execSql(conf,sqlQuery);
   cleanUpResultSet(conf);
+  free(sqlQuery);
   return 0;
 }
@@ -280,4 +285,5 @@
   }
   cleanUpResultSet(conf);
+  free(sqlQuery);
   return (char*)tmp1;
 }
@@ -316,4 +322,5 @@
     tmp1=NULL;
   cleanUpResultSet(conf);
+  free(sqlQuery);
   return (char*)tmp1;
 }
@@ -338,4 +345,5 @@
   cleanUpResultSet(conf);
   close_sql(conf);
+  free(sqlQuery);
   end_sql();
 }
@@ -363,4 +371,5 @@
   cleanUpResultSet(conf);
   close_sql(conf);
+  free(sqlQuery);
   end_sql();
 }
@@ -397,4 +406,5 @@
   if(hasRes<0)
     tmp1=NULL;
+  free(sqlQuery);
   return (char*)tmp1;
 }
@@ -429,4 +439,5 @@
   if(hasRes<0)
     addToMap(statusInfo,"Status","Failed");
+  free(sqlQuery);
   return;
 }
@@ -460,4 +471,5 @@
   }
   cleanUpResultSet(conf);
+  free(sqlQuery);
   return res;
 }
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ulinet.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ulinet.h	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/ulinet.h	(revision 741)
@@ -26,5 +26,5 @@
 #define _ULINET_H
 
-#include "fcgi_stdio.h"
+//#include "fcgi_stdio.h"
 #include <stdlib.h>
 #include <fcntl.h>
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.c	(revision 741)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.c	(revision 741)
@@ -0,0 +1,128 @@
+/**
+ * Author : David Saggiorato
+ *
+ *  Copyright 2008-2009 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <stdint.h>
+#include <amqp_tcp_socket.h>
+#include <amqp.h>
+#include <amqp_framing.h>
+
+
+amqp_connection_state_t conn;
+amqp_socket_t *socket = NULL;
+char * amqp_exchange;
+char * amqp_routingkey;
+char * amqp_hostname;
+int amqp_port;
+char *amqp_user;
+char *amqp_passwd;
+char * amqp_queue;
+
+
+void init_amqp(const char * hostname, int port,const char *user, const char *passwd,const char *exchange, const char * routingkey,const char * queue){
+    amqp_hostname = strdup(hostname);
+    amqp_user = strdup(user);
+    amqp_passwd = strdup(passwd);
+    amqp_exchange = strdup(exchange);
+    amqp_routingkey = strdup(routingkey);
+    amqp_queue = strdup(queue);
+    amqp_port = port;
+}
+
+void init_consumer(){
+    amqp_basic_consume(conn, 1, amqp_cstring_bytes(amqp_queue), amqp_empty_bytes, 0, 0, 0, amqp_empty_table);
+    amqp_get_rpc_reply(conn);
+}
+
+uint64_t consumer_amqp(char **msg){
+    amqp_rpc_reply_t res;
+    amqp_envelope_t envelope;
+    amqp_maybe_release_buffers(conn);
+    res = amqp_consume_message(conn, &envelope, NULL, 0);
+    if (AMQP_RESPONSE_NORMAL != res.reply_type) {
+        return 0;
+    }
+    unsigned char *buf = (unsigned char *) envelope.message.body.bytes;
+    size_t i;
+    char * tmp = (char *) malloc(envelope.message.body.len * sizeof(char*));
+    for (i = 0; i < envelope.message.body.len; i++) {
+        tmp[i] = (char)buf[i];
+    }
+    tmp[envelope.message.body.len]='\0';
+    *msg = tmp;
+    uint64_t r = envelope.delivery_tag;
+    amqp_destroy_envelope(&envelope);
+    return r;
+}
+
+
+int consumer_ack_amqp(uint64_t delivery_tag){
+    return amqp_basic_ack(conn,1,delivery_tag,0);
+}
+
+
+
+int bind_amqp(){
+    conn = amqp_new_connection();
+    socket = amqp_tcp_socket_new(conn);
+    int  status;
+    if (!socket)
+        return -1;
+    status = amqp_socket_open(socket, amqp_hostname, amqp_port);
+    if (status != 0)
+        return status;
+    amqp_rpc_reply_t s = amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, amqp_user, amqp_passwd);
+    if (s.reply_type != AMQP_RESPONSE_NORMAL)
+        return -2;
+    amqp_channel_open(conn, 1);
+    s = amqp_get_rpc_reply(conn);
+    if (s.reply_type != AMQP_RESPONSE_NORMAL)
+        return -3;
+    return 0;
+
+}
+
+int send_msg(const char * msg, const char * content_type){
+    amqp_basic_properties_t props;
+    props._flags = AMQP_BASIC_CONTENT_TYPE_FLAG | AMQP_BASIC_DELIVERY_MODE_FLAG;
+    props.content_type = amqp_cstring_bytes(content_type);
+    props.delivery_mode = 2; /* persistent delivery mode */
+    int ret = amqp_basic_publish(conn,1,amqp_cstring_bytes(amqp_exchange),amqp_cstring_bytes(amqp_routingkey), 0, 0, &props, amqp_cstring_bytes(msg));
+    if (ret < 0)
+        fprintf(stderr, " %s\n", amqp_error_string2(ret));
+    return ret;
+}
+
+int close_amqp(){
+    amqp_channel_close(conn, 1, AMQP_REPLY_SUCCESS);
+    amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
+    amqp_destroy_connection(conn);
+    return 0;
+}
+
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.h	(revision 741)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_amqp.h	(revision 741)
@@ -0,0 +1,40 @@
+/**
+ * Author : David Saggiorato
+ *
+ *  Copyright 2008-2009 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#ifndef ZOO_AMQP_H
+#define ZOO_AMQP 1
+
+#include <stdint.h>
+void init_amqp(const char * hostname, int port,const char *user, const char *passwd, const char *exchange, const char * routingkey, const char * queue);
+
+
+int bind_amqp();
+void init_consumer();
+uint64_t consumer_amqp(char ** m);
+int send_msg(const char * msg, const char * content_type);
+int close_amqp();
+int consumer_ack_amqp(uint64_t delivery_tag);
+
+#endif
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_fpm.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_fpm.c	(revision 741)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_fpm.c	(revision 741)
@@ -0,0 +1,455 @@
+/**
+ * Author : David Saggiorato
+ * 
+ *  Copyright 2008-2015 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#define MALLOC_CHECK_ 0
+#define MALLOC_CHECK 0
+
+/**
+ * Specific includes
+ */
+#ifndef WIN32
+/*
+#include "fcgio.h"
+#include "fcgi_config.h"
+*/
+//#include <stdio.h>
+#include <unistd.h>
+#include <fcgiapp.h>
+#endif
+#include <sys/wait.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "service_internal.h"
+
+extern "C"
+{
+#include <string.h>
+#include "logger.h"
+#include <stdlib.h>
+#include <glib.h>
+#include <sys/stat.h>
+#include <ctype.h>
+
+}
+#include "service.h"
+#include "response_print.h"
+#include "zoo_zcfg.h"
+#include "zoo_json.h"
+#include "zoo_amqp.h"
+//#include "zoo_sql.h"
+#include "server_internal.h"
+#include "request_parser.h"
+#include "logger.h"
+
+void
+loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
+                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err);
+
+
+using namespace std;
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE -1
+#endif
+
+
+int
+main (int argc, char *argv[])
+{
+ int debug_flag = 0;
+ int background_flag = 0;
+ char *file_value = NULL;
+ int index;
+ int c;
+ opterr = 0;
+ while ((c = getopt (argc, argv, "dbhf:")) != -1)
+      switch (c)
+      {
+      case 'd':
+        debug_flag = 1;
+        break;
+      case 'b':
+        background_flag = 1;
+        break;
+      case 'h':
+        fprintf(stderr,"TODO: need to print help\n");
+        fflush(stderr);
+        return 0;
+      case 'f':
+        file_value = optarg;
+        break;
+      case '?':
+        if (optopt == 'f')
+          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+        else if (isprint (optopt))
+          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+        else
+          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
+        return 1;
+      default:
+        abort ();
+      }
+
+  maps *conf;
+  conf = (maps *) malloc (MAPS_SIZE);
+  
+  int ret = conf_read (file_value, conf);
+  if ( ret == 2){
+    //a verifier mais conf_read ne renvoie jamais 0
+    fprintf(stderr,"Erreur lors de la lecture de %s\n",file_value);
+    return 1;
+  }
+
+  char *rootDir;
+  map *m_rootDir = getMapFromMaps (conf, "server", "rootDir");
+  if (m_rootDir == NULL){
+    fprintf(stderr,"Configuration error: rootDir");
+    return 2;
+  }
+  else {
+   rootDir = (char*)malloc((strlen(m_rootDir->value) +1)*sizeof(char*));
+   strncpy(rootDir,m_rootDir->value,strlen(m_rootDir->value));
+   rootDir[strlen(m_rootDir->value)] = '\0';
+   //freeMap(&m_rootDir);
+  }
+
+char *regDir;
+  map *m_regDir = getMapFromMaps (conf, "main", "registry");
+  if (m_regDir == NULL){
+    fprintf(stderr,"Configuration error: regDir");
+    return 2;
+  }
+  else {
+   regDir = (char*)malloc((strlen(m_regDir->value) +1)*sizeof(char*));
+   strncpy(regDir,m_regDir->value,strlen(m_regDir->value));
+   regDir[strlen(m_regDir->value)] = '\0';
+  }
+  
+  int async_worker;
+  map *m_async_worker = getMapFromMaps (conf, "server", "async_worker");  
+  if (m_async_worker == NULL){
+    fprintf(stderr,"Configuration error: async_worker not found");
+    return 2;
+  }
+  else {
+    async_worker = atoi(m_async_worker->value);
+    //freeMap(&m_async_worker);
+    if (async_worker == 0){
+        fprintf(stderr,"Configuration error: req_worker");
+        return 2;
+    }
+  }
+
+  int max_requests;
+  map *m_max_requests = getMapFromMaps (conf, "server", "max_requests");
+  if (m_max_requests == NULL){
+    fprintf(stderr,"Configuration error: max_requests");
+    return 2;
+  }
+  else {
+    max_requests = atoi(m_max_requests->value);
+    //freeMap(&m_max_requests);
+    if (max_requests == 0){
+        fprintf(stderr,"Configuration error: max_requests");
+        return 2;
+    }
+  }
+
+  int id_user;
+  map *m_user = getMapFromMaps (conf, "server", "uid");
+  if (m_user == NULL){
+    fprintf(stderr,"Configuration error: id_user");
+    return 2;
+  }
+  else {
+    id_user = atoi(m_user->value);
+    //freeMap(&m_user);
+    if (id_user == 0){
+        fprintf(stderr,"Configuration error: id_user");
+        return 2;
+    }
+  }
+
+
+  int id_group;
+  map *m_group = getMapFromMaps (conf, "server", "gid");
+  if (m_group == NULL){
+    fprintf(stderr,"Configuration error: gid");
+    return 2;
+  }
+  else {
+    id_group = atoi(m_group->value);
+    //freeMap(&m_group);
+    if (id_group == 0){
+        fprintf(stderr,"Configuration error: id_group");
+        return 2;
+    }
+  }
+
+
+  char * amqp_host;
+  map * m_amqp_host = getMapFromMaps (conf, "rabbitmq", "host");
+  if (m_amqp_host == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] host");
+    return 2;
+  }
+  else {
+    amqp_host = (char *)malloc((strlen(m_amqp_host->value) +1)*sizeof(char*));
+    strncpy(amqp_host,m_amqp_host->value,strlen(m_amqp_host->value));
+    amqp_host[strlen(m_amqp_host->value)] = '\0';
+ }
+
+  int amqp_port;
+  map *m_amqp_port = getMapFromMaps (conf, "rabbitmq", "port");
+  if (m_amqp_port == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] port");
+    return 2;
+  }
+  else {
+    amqp_port = atoi(m_amqp_port->value);
+    if (amqp_port == 0){
+        fprintf(stderr,"Configuration error: [rabbitmq] port");
+        return 2;
+    }
+  }
+
+  char * amqp_user;
+  map * m_amqp_user = getMapFromMaps (conf, "rabbitmq", "user");
+  if (m_amqp_user == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] user");
+    return 2;
+  }
+  else {
+    amqp_user = (char *)malloc((strlen(m_amqp_user->value) +1)*sizeof(char*));
+    strncpy(amqp_user,m_amqp_user->value,strlen(m_amqp_user->value));
+    amqp_user[strlen(m_amqp_user->value)] = '\0';
+ }
+
+  char * amqp_passwd;
+  map * m_amqp_passwd = getMapFromMaps (conf, "rabbitmq", "passwd");
+  if (m_amqp_passwd == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] passwd");
+    return 2;
+  }
+  else {
+    amqp_passwd = (char *)malloc((strlen(m_amqp_passwd->value) +1)*sizeof(char*));
+    strncpy(amqp_passwd,m_amqp_passwd->value,strlen(m_amqp_passwd->value));
+    amqp_passwd[strlen(m_amqp_passwd->value)] = '\0';
+ }
+
+  char * amqp_exchange;
+  map * m_amqp_exchange = getMapFromMaps (conf, "rabbitmq", "exchange");
+  if (m_amqp_exchange == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] exchange");
+    return 2;
+  }
+  else {
+    amqp_exchange = (char *)malloc((strlen(m_amqp_exchange->value) +1)*sizeof(char*));
+    strncpy(amqp_exchange,m_amqp_exchange->value,strlen(m_amqp_exchange->value));
+    amqp_exchange[strlen(m_amqp_exchange->value)] = '\0';
+ }
+
+  char * amqp_routingkey;
+  map * m_amqp_routingkey = getMapFromMaps (conf, "rabbitmq", "routingkey");
+  if (m_amqp_routingkey == NULL){
+    fprintf(stderr,"Configuration error: [amqp] routingkey");
+    return 2;
+  }
+  else {
+    amqp_routingkey = (char *)malloc((strlen(m_amqp_routingkey->value) +1)*sizeof(char*));
+    strncpy(amqp_routingkey,m_amqp_routingkey->value,strlen(m_amqp_routingkey->value));
+    amqp_routingkey[strlen(m_amqp_routingkey->value)] = '\0';
+ }
+
+  char * amqp_queue;
+  map * m_amqp_queue = getMapFromMaps (conf, "rabbitmq", "queue");
+  if (m_amqp_queue == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] queue");
+    return 2;
+  }
+  else {
+    amqp_queue = (char *)malloc((strlen(m_amqp_queue->value) +1)*sizeof(char*));
+    strncpy(amqp_queue,m_amqp_queue->value,strlen(m_amqp_queue->value));
+    amqp_queue[strlen(m_amqp_queue->value)] = '\0';
+ }
+
+
+  /*
+  ret = setgid(id_group);
+  if (ret != 0){
+    fprintf(stderr,"Change gid error\n");
+    return 3;
+  }
+
+  ret = setuid(id_user);
+  if (ret != 0){
+    fprintf(stderr,"Change uid error\n");
+    return 3;
+  }
+*/
+
+
+  init_services_conf (rootDir,regDir);
+  init_amqp(amqp_host,amqp_port,amqp_user, amqp_passwd, amqp_exchange, amqp_routingkey,amqp_queue);
+
+
+
+
+
+  int fork_status = fork();
+  if (fork_status == 0){
+    //child
+    int master_async= getpid();
+    int i;
+    int count_request = 0;
+    for (i = 0; i< async_worker; i++){
+        fork_status = fork();
+        if (fork_status == 0){
+            fprintf(stderr,"child async %d \n",getpid());
+            fflush(stderr);
+            break;
+        }
+    }
+    
+    json_object *msg_obj;
+    json_object *maps_obj;
+    maps * map_c;
+    json_object *req_format_jobj;
+    maps * request_input_real_format;
+    json_object *req_jobj;
+    map * request_inputs;
+    json_object *outputs_jobj;
+    maps * request_output_real_format;
+
+    char *msg;
+    int c;
+    int eres;
+    char * service_identifier;
+    service * s1 = NULL;
+    
+    HINTERNET hInternet;
+    HINTERNET res;
+    hInternet = InternetOpen (
+			    "ZooWPSClient\0",
+			    INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+    
+    while(1){
+        /* mode asynchrone */
+        if( master_async != getpid()){
+            /*traitement des requetes de la queue */
+            bind_amqp();
+            init_consumer();
+            while(1){
+                
+                c = consumer_amqp(&msg);
+                if (c == 0)
+                    break;
+                msg_obj = json_tokener_parse(msg);
+                
+                free(msg);
+                maps_obj = json_object_object_get(msg_obj,"maps");
+
+                map_c = jsontomaps(maps_obj);
+
+                req_format_jobj = json_object_object_get(msg_obj,"request_input_real_format");
+                request_input_real_format = jsontomaps(req_format_jobj);
+
+                req_jobj = json_object_object_get(msg_obj,"request_inputs");
+                request_inputs = jsontomap(req_jobj);
+
+                outputs_jobj = json_object_object_get(msg_obj,"request_output_real_format");
+                request_output_real_format = jsontomaps(outputs_jobj);
+                
+                json_object_put(msg_obj);
+
+                /* traitemement du message */
+                
+                /* Recherche des references */
+                
+                map * m_identifier = getMap (request_inputs, "Identifier");
+                
+                service_identifier = zStrdup (m_identifier->value);
+
+                s1 = search_service (service_identifier);
+                dumpService(s1);
+                free(service_identifier);
+                
+                validateRequest(&map_c,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,NULL);
+                
+                
+                dumpMaps(request_input_real_format);
+
+                loadServiceAndRun(&map_c, s1,request_inputs,&request_input_real_format, &request_output_real_format, &eres,NULL,NULL);
+                /*
+                if (eres == SERVICE_SUCCEEDED) {
+                    outputResponse (s1,request_input_real_format,request_output_real_format,request_inputs, 0, map_c, eres,NULL,NULL);
+                }
+                */
+                    
+                dumpMaps(request_output_real_format);
+                fprintf(stderr,"################################################################\n");
+                dumpMaps(map_c);
+
+                //outputResponse (s1,request_input_real_format,request_output_real_format,request_inputs, 0, map_c, eres,NULL,NULL);
+
+                
+                freeMaps(&map_c);
+                map_c= NULL;
+               
+                freeMaps(&request_input_real_format);
+                request_input_real_format = NULL;
+
+                dumpMap(request_inputs);
+                freeMap(&request_inputs);
+                request_inputs = NULL;
+                
+                //dumpMaps(request_output_real_format);
+                //freeMaps(&request_output_real_format);
+                //request_output_real_format = NULL;
+                consumer_ack_amqp(c);
+                
+
+            }
+            close_amqp();
+            
+        }
+        else {
+            wait(0);
+            fprintf(stderr,"Master async %d\n",getpid());
+            fprintf(stderr,"New async Child\n");
+            fflush(stderr);
+            exit(1);
+            fork();
+        }
+    }
+
+  }
+   while(1);
+  return 0;
+}
+ 
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.c	(revision 741)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.c	(revision 741)
@@ -0,0 +1,111 @@
+/**
+ * Author : David Saggiorato
+ *
+ *  Copyright 2008-2009 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include "service.h"
+#include "service_internal.h"
+#include <json/json.h>
+
+
+
+void maptojson(json_object ** obj,map * m){
+    json_object *jobj = json_object_new_object();
+    map *tmp = m;
+    while(tmp != NULL){
+        json_object_object_add(jobj,tmp->name,json_object_new_string(tmp->value));
+        tmp = tmp->next;
+    }
+    *obj = jobj;
+}
+
+void mapstojson(json_object ** obj,maps * m){
+    json_object *jobj = json_object_new_object();
+    maps *tmp = m;
+    while(tmp!=NULL){
+        json_object *map_obj;
+        maptojson(&map_obj,tmp->content);
+        json_object_object_add(jobj,tmp->name,map_obj);
+        tmp = tmp->next;
+    }
+    *obj = jobj;
+}
+
+
+map* jsontomap(json_object * jobj){
+    map *m = (map *) malloc (MAP_SIZE);
+    int i = 0;
+    json_object_object_foreach(jobj, key, val){
+        if (json_object_is_type(val, json_type_string)){
+            if (i==0){
+                m->name = zStrdup(key);
+                m->value = zStrdup(json_object_get_string(val));
+                m->next = NULL;
+                i = 1;
+            }
+            else {
+                map *tmp=createMap(key,json_object_get_string(val));
+                addMapToMap(&m,tmp);
+                freeMap(&tmp);
+                free(tmp);
+           }
+        }
+        else {
+            fprintf(stderr,"jsontomap not map :%s \n",key);
+            /* Attention ce n'est pas une map */
+            return NULL;
+        }
+     }
+        return m;
+}
+
+maps * jsontomaps(json_object * jobj){
+    maps *mm = (maps *) malloc (MAPS_SIZE); 
+    int i =0;
+    json_object_object_foreach(jobj, key, val){
+        if (i ==0){
+            mm->content = jsontomap(val);
+            mm->name = zStrdup(key);
+            mm->next = NULL;
+            i = 1;
+        }
+        else {
+            maps *maps_tmp;
+            maps_tmp = (maps *) malloc (MAPS_SIZE);
+            maps_tmp->content = jsontomap(val); 
+            maps_tmp->name = zStrdup(key);
+            maps_tmp->next = NULL;
+            addMapsToMaps(&mm,maps_tmp);
+            freeMaps(&maps_tmp);
+            free(maps_tmp);
+            maps_tmp = NULL;
+       }
+    }
+    return mm;
+}
+ 
+
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.h
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.h	(revision 741)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_json.h	(revision 741)
@@ -0,0 +1,40 @@
+/**
+ * Author : David Saggiorato
+ *
+ *  Copyright 2008-2009 GeoLabs SARL. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#ifndef ZOO_JSON_H
+#define ZOO_JSON_H 1
+
+
+#include "service.h"
+#include "service_internal.h"
+#include <json/json.h>
+void maptojson(json_object ** obj,map * m);
+
+void mapstojson(json_object ** obj,maps * m);
+
+map* jsontomap(json_object * jobj);
+maps*  jsontomaps(json_object * jobj);
+
+#endif
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_loader.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_loader.c	(revision 741)
@@ -1,3 +1,3 @@
-/*
+/**
  * Author : Gérald FENOY
  *
@@ -30,14 +30,17 @@
  */
 #ifndef WIN32
+/*
 #include "fcgio.h"
-#include "fcgi_config.h" 
-#include "fcgi_stdio.h"
-#endif
+#include "fcgi_config.h"
+*/
+//#include <stdio.h>
+#include <unistd.h>
+#include <fcgiapp.h>
+#endif
+#include <sys/wait.h>
+#include <pthread.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include "service_internal.h"
-#include "response_print.h"
-#include "zoo_zcfg.h"
-
 #ifdef WIN32
 #include "windows.h"
@@ -45,5 +48,6 @@
 #endif
 
-extern "C" {
+extern "C"
+{
 #include "cgic.h"
 #include <libxml/tree.h>
@@ -52,10 +56,26 @@
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
+
+#include <string.h>
+
+#include <stdlib.h>
+#include <glib.h>
+#include <sys/stat.h>
+#include <ctype.h>
+
 }
-
-#include "service_internal.h"
+#include "response_print.h"
+#include "zoo_zcfg.h"
+#include "zoo_json.h"
+#include "zoo_amqp.h"
+//#include "zoo_sql.h"
+#include "server_internal.h"
 #include "request_parser.h"
-
-int runRequest(map**);
+void
+loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
+                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err);
+
+xmlXPathObjectPtr extractFromDoc (xmlDocPtr, const char *);
+int runRequest (map **,struct cgi_env **,FCGX_Request *);
 
 using namespace std;
@@ -68,147 +88,172 @@
 #endif
 
-/**
- * Main entry point for cgic.
- * @return 0 on sucess.
- */
-int cgiMain(){
-  /**
-   * We'll use cgiOut as the default output (stdout) to produce plain text 
-   * response.
-   */
-  dup2(fileno(cgiOut),fileno(stdout));
+
+static void PrintEnv(FCGX_Stream *out, char *label, char **envp)
+{
+    FCGX_FPrintF(out, "%s:<br>\n<pre>\n", label);
+    for( ; *envp != NULL; envp++) {
+        FCGX_FPrintF(out, "%s\n", *envp);
+    }
+    FCGX_FPrintF(out, "</pre><p>\n");
+}
+
+#define PATH_SOCKET "/tmp/zoo.sock"
+#define THREAD_COUNT 50
+static int counts[THREAD_COUNT];
+
+
+int process(FCGX_Request *request){
+
+      int pid = getpid();
+      struct cgi_env *cgi;
+      cgi = (struct cgi_env*)malloc(sizeof(struct cgi_env));
+      cgiMain_init (NULL, NULL,&cgi,request);
+      char *strQuery = NULL;
+      if (cgi->cgiQueryString != NULL)
+        strQuery = zStrdup (cgi->cgiQueryString);
+      map *tmpMap = NULL;
+
+      if (strncmp (cgi->cgiContentType, "text/xml", 8) == 0 ||
+          strncasecmp (cgi->cgiRequestMethod, "post", 4) == 0)
+        {
+          if (cgi->cgiContentLength == 0)
+            {
+              char *post_data = NULL;
+              int i = 0;
+              int ch = FCGX_GetChar(request->in);
+              while (ch != -1){
+                {
+                  i++;
+                  if (post_data == NULL)
+                    {
+                    post_data=(char*)malloc(sizeof(char));
+                    post_data[i-1] = (char) ch;
+                    }
+                  else
+                    {
+                    post_data=(char*)realloc(post_data,i*sizeof(char));
+                    post_data[i-1] = (char) ch;
+                    }
+                  ch = FCGX_GetChar(request->in);
+                  if (ch == -1 ){
+                    post_data=(char*)realloc(post_data,(i + 1)*sizeof(char));
+                    post_data[i] = '\0';
+                    }
+                }
+                cgi->cgiContentLength = i;
+              if (post_data == NULL && (strQuery == NULL || strlen (strQuery) == 0))
+                {
+                  return errorException (NULL,
+                                         "ZOO-Kernel failed to process your request cause the request was emtpty.",
+                                         "InternalError", NULL,request->out);
+                }
+              else
+                {
+                  if (strQuery == NULL || strlen (strQuery) == 0)
+                    tmpMap = createMap ("request", post_data);
+                }
+              if (post_data != NULL)
+                free (post_data);
+                }
+            }
+          else
+            {
+              char *post_data = new char[cgi->cgiContentLength + 1];
+              int r = FCGX_GetStr(post_data,cgi->cgiContentLength,request->in);
+              if ( r > 0)
+                {
+                  post_data[r] = '\0';
+                  cgi->cgiContentLength = r;
+                  tmpMap = createMap ("request", post_data);
+                }
+              else
+                {
+                  post_data[0] = '\0';
+                  char **array, **arrayStep;
+                  if (cgiFormEntries (&array,&cgi) != cgiFormSuccess)
+                    {
+                      return 1;
+                    }
+                  arrayStep = array;
+                  while (*arrayStep)
+                    {
+                      char *ivalue = new char[cgi->cgiContentLength];
+                      cgiFormStringNoNewlines (*arrayStep, ivalue,
+                                               cgi->cgiContentLength,&cgi);
+                      char *tmpValueFinal =
+                        (char *)
+                        malloc ((strlen (*arrayStep) + strlen (ivalue) +
+                                 1) * sizeof (char));
+                      sprintf (tmpValueFinal, "%s=%s", *arrayStep, ivalue);
+                      if (strlen (post_data) == 0)
+                        {
+                          sprintf (post_data, "%s", tmpValueFinal);
+                        }
+                      else
+                        {
+                          char *tmp = zStrdup (post_data);
+                          sprintf (post_data, "%s&%s", tmp, tmpValueFinal);
+                          free (tmp);
+                        }
+                      free (tmpValueFinal);
 #ifdef DEBUG
-  fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-  fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
-  fflush(cgiOut);
-  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 
-  fprintf (stderr, "RequestMethod: (%s) %d %d\n", cgiRequestMethod,strncasecmp(cgiRequestMethod,"post",4),strncmp(cgiContentType,"text/xml",8)==0 || strncasecmp(cgiRequestMethod,"post",4)==0); 
-  fprintf (stderr, "Request: %s\n", cgiQueryString);
-  fprintf (stderr, "ContentType: %s\n", cgiContentType);
-  fprintf (stderr, "ContentLength: %d\n", cgiContentLength);
-  fflush(stderr);
-#endif
-
-
-  init_services_conf ("/var/www/zoo-wps/cgi-bin","/var/www/zoo-wps/registry/");
-
-
-  char *strQuery=NULL;
-  if(cgiQueryString!=NULL)
-    strQuery=zStrdup(cgiQueryString);
-  map* tmpMap=NULL;
-
-  if(strncmp(cgiContentType,"text/xml",8)==0 || 
-     strncasecmp(cgiRequestMethod,"post",4)==0){
-    if(cgiContentLength==0){
-       char *buffer=new char[2];
-       char *res=NULL;
-       int r=0;
-       while((r=fread(buffer,sizeof(char),1,cgiIn))){
-	 buffer[1]=0;
-	 if(res==NULL){
-	   res=(char*)malloc(2*sizeof(char));
-	   sprintf(res,"%s",buffer);
-	 }
-	 else{
-	   res=(char*)realloc(res,(cgiContentLength+2)*sizeof(char));
-	   memcpy(res + cgiContentLength, buffer, sizeof(char));
-	   res[cgiContentLength+1]=0;
-	 }
-	 cgiContentLength+=r;
-       }
-       delete[] buffer;
-       if(res!=NULL && (strQuery==NULL || strlen(strQuery)==0))
-	 tmpMap=createMap("request",res);
-       if(res!=NULL)
-	 free(res);
-    }else{
-      char *buffer=new char[cgiContentLength+1];
-      if(fread(buffer,sizeof(char),cgiContentLength,cgiIn)>0){
-	buffer[cgiContentLength]=0;
-	tmpMap=createMap("request",buffer);
-      }else{
-	buffer[0]=0;
-	char **array, **arrayStep;
-	if (cgiFormEntries(&array) != cgiFormSuccess) {
-	  return 1;
-	}
-	arrayStep = array;
-	while (*arrayStep) {
-	  char *ivalue=new char[cgiContentLength];
-	  cgiFormStringNoNewlines(*arrayStep, ivalue, cgiContentLength);
-	  char* tmpValueFinal=(char*) malloc((strlen(*arrayStep)+strlen(ivalue)+2)*sizeof(char));	
-	  sprintf(tmpValueFinal,"%s=%s",*arrayStep,ivalue);
-
-	  if(strlen(buffer)==0){		
-	    sprintf(buffer,"%s",tmpValueFinal);
-	  }else{		
-	    char *tmp=zStrdup(buffer);
-	    sprintf(buffer,"%s&%s",tmp,tmpValueFinal);
-	    free(tmp);
-	  }	  
-	  free(tmpValueFinal);
+                      fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep,
+                               ivalue);
+#endif
+                      delete[]ivalue;
+                      arrayStep++;
+                    }
+                  if (tmpMap != NULL)
+                    addToMap (tmpMap, "request", post_data);
+                  else
+                    tmpMap = createMap ("request", post_data);
+                }
+              delete[]post_data;
+            }
+        }
+      else
+        {
 #ifdef DEBUG
-	  fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,ivalue);
-#endif
-	  delete[]ivalue;
-	  arrayStep++;
-	}	
-	if(tmpMap!=NULL)
-	  addToMap(tmpMap,"request",buffer);
-	else
-	  tmpMap=createMap("request",buffer);
-      }
-      delete[]buffer;
-    }	
-  }
-  else{
+          dumpMap (tmpMap);
+#endif
+       
+       char **array, **arrayStep;
+          if (cgiFormEntries (&array,&cgi) != cgiFormSuccess)
+            {
+              return 1;
+            }
+          arrayStep = array;
+          while (*arrayStep)
+            {
+              char *value = new char[cgi->cgiContentLength];
+              cgiFormStringNoNewlines (*arrayStep, value, cgi->cgiContentLength,&cgi);
 #ifdef DEBUG
-    dumpMap(tmpMap);
-#endif
-    char **array, **arrayStep;
-    if (cgiFormEntries(&array) != cgiFormSuccess) {
-      return 1;
-    }
-    arrayStep = array;
-    while (*arrayStep) {
-      char *value=new char[cgiContentLength];
-      cgiFormStringNoNewlines(*arrayStep, value, cgiContentLength);
-#ifdef DEBUG
-      fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
-#endif
+              fprintf (stderr, "(( \n %s \n %s \n ))", *arrayStep, value);
+#endif
+              if (tmpMap != NULL)
+                addToMap (tmpMap, *arrayStep, value);
+              else
+                tmpMap = createMap (*arrayStep, value);
+              arrayStep++;
+              delete[]value;
+            }
+          cgiStringArrayFree (array);
+        }
+
 #ifdef WIN32
-      char* tmp = url_decode(value); 
-      if(tmpMap!=NULL)		
-        addToMap(tmpMap,*arrayStep,tmp);
-      else		
-        tmpMap=createMap(*arrayStep,tmp);
-      free(tmp);
-#else
-      if(tmpMap!=NULL)
-        addToMap(tmpMap,*arrayStep,value);
-      else
-        tmpMap=createMap(*arrayStep,value);
-#endif	
-      arrayStep++;
-      delete[]value;
-    }
-    cgiStringArrayFree(array);
-  }
-
-#ifdef WIN32
-  map *tmpReq=getMap(tmpMap,"rfile");
-  if(tmpReq!=NULL){
-    FILE *lf=fopen(tmpReq->value,"r");
-    fseek(lf,0,SEEK_END);
-    long flen=ftell(lf);
-    fseek(lf,0,SEEK_SET);
-    char *buffer=(char*)malloc((flen+1)*sizeof(char));
-    fread(buffer,flen,1,lf);
-    fclose(lf);
-    addToMap(tmpMap,"request",buffer);
-    free(buffer);
-    cgiContentLength=flen+9;
-  }
+      map *tmpReq = getMap (tmpMap, "rfile");
+      if (tmpReq != NULL)
+        {
+          FILE *lf = fopen (tmpReq->value, "r");
+          fseek (lf, 0, SEEK_END);
+          long flen = ftell (lf);
+          fseek (lf, 0, SEEK_SET);
+          char *buffer = (char *) malloc ((flen + 1) * sizeof (char));
+          fread (buffer, flen, 1, lf);
+          fclose (lf);
+          addToMap (tmpMap, "request", buffer);
+          free (buffer);
+          cgiContentLength = flen + 9;
+        }
 #endif
   /**
@@ -217,207 +262,678 @@
    * one.
    */
-  if(strncasecmp(cgiRequestMethod,"post",4)==0 || 
-     (count(tmpMap)==1 && strncmp(tmpMap->value,"<",1)==0) 
+      if (strncasecmp (cgi->cgiRequestMethod, "post", 4) == 0 ||
+          (count (tmpMap) == 1 && strncmp (tmpMap->value, "<", 1) == 0)
 #ifdef WIN32
-     ||tmpReq!=NULL
-#endif
-     ){
+          || tmpReq != NULL
+#endif
+        )
+        {
     /**
      * Store the original XML request in xrequest map
      */
-    map* t1=getMap(tmpMap,"request");
-    if(t1!=NULL && strncasecmp(t1->value,"<",1)==0) {
-      addToMap(tmpMap,"xrequest",t1->value);
-      xmlInitParser();
-      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
+          map *t1 = getMap (tmpMap, "request");
+          if (t1 != NULL && strncasecmp (t1->value, "<", 1) == 0)
+            {
+              addToMap (tmpMap, "xrequest", t1->value);
+              xmlInitParser ();
+              xmlDocPtr doc = xmlParseMemory (t1->value, cgi->cgiContentLength);
+              {
+                xmlXPathObjectPtr reqptr = extractFromDoc (doc,
+                                                           "/*[local-name()='Envelope']/*[local-name()='Body']/*");
+                if (reqptr != NULL)
+                  {
+                    xmlNodeSet *req = reqptr->nodesetval;
+                    if (req != NULL && req->nodeNr == 1)
+                      {
+                        addToMap (tmpMap, "soap", "true");
+                        for (int k = 0; k < req->nodeNr; k++)
+                          {
+                            //xmlNsPtr ns=xmlNewNs(req->nodeTab[k],BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
+                            xmlDocSetRootElement (doc, req->nodeTab[k]);
+                            xmlChar *xmlbuff;
+                            int buffersize;
+                            xmlDocDumpFormatMemoryEnc (doc, &xmlbuff,
+                                                       &buffersize, "utf-8",
+                                                       1);
+                            addToMap (tmpMap, "xrequest", (char *) xmlbuff);
+                            xmlFree (xmlbuff);
+                          }
+                      }
+                    xmlXPathFreeObject (reqptr);
+                  }
+              }
+
+              xmlNodePtr cur = xmlDocGetRootElement (doc);
+              char *tval;
+              tval = NULL;
+              tval = (char *) xmlGetProp (cur, BAD_CAST "service");
+              if (tval != NULL)
+                {
+                  addToMap (tmpMap, "service", tval);
+                  xmlFree (tval);
+                }
+              tval = NULL;
+              tval = (char *) xmlGetProp (cur, BAD_CAST "language");
+              if (tval != NULL)
+                {
+                  addToMap (tmpMap, "language", tval);
+                  xmlFree (tval);
+                }
+              const char *requests[3] =
+                { "GetCapabilities", "DescribeProcess", "Execute" };
+              for (int j = 0; j < 3; j++)
+                {
+                  char tt[128];
+                  sprintf (tt, "/*[local-name()='%s']", requests[j]);
+                  xmlXPathObjectPtr reqptr = extractFromDoc (doc, tt);
+                  if (reqptr != NULL)
+                    {
+                      xmlNodeSet *req = reqptr->nodesetval;
+#ifdef DEBUG
+                      fprintf (stderr, "%i", req->nodeNr);
+#endif
+                      if (req != NULL && req->nodeNr == 1)
+                        {
+                          if (t1->value != NULL)
+                            free (t1->value);
+                          t1->value = zStrdup (requests[j]);
+                          j = 2;
+                        }
+                      xmlXPathFreeObject (reqptr);
+                    }
+                }
+              if (strncasecmp (t1->value, "GetCapabilities", 15) == 0)
+                {
+                  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);
+                  xmlXPathFreeObject (versptr);
+                  xmlFree (content);
+                }
+              else
+                {
+                  tval = NULL;
+                  tval = (char *) xmlGetProp (cur, BAD_CAST "version");
+                  if (tval != NULL)
+                    {
+                      addToMap (tmpMap, "version", tval);
+                      xmlFree (tval);
+                    }
+                  tval = (char *) xmlGetProp (cur, BAD_CAST "language");
+                  if (tval != NULL)
+                    {
+                      addToMap (tmpMap, "language", tval);
+                      xmlFree (tval);
+                    }
+                  xmlXPathObjectPtr idptr =
+                    extractFromDoc (doc, "/*/*[local-name()='Identifier']");
+                  if (idptr != NULL)
+                    {
+                      xmlNodeSet *id = idptr->nodesetval;
+                      if (id != NULL)
+                        {
+                          char *identifiers = NULL;
+                          identifiers =
+                            (char *) calloc (cgi->cgiContentLength, sizeof (char));
+                          identifiers[0] = 0;
+                          for (int k = 0; k < id->nodeNr; k++)
+                            {
+                              xmlChar *content = xmlNodeListGetString (doc,
+                                                                       id->nodeTab
+                                                                       [k]->
+                                                                       xmlChildrenNode,
+                                                                       1);
+                              if (strlen (identifiers) > 0)
+                                {
+                                  char *tmp = zStrdup (identifiers);
+                                  snprintf (identifiers,
+                                            strlen (tmp) +
+                                            xmlStrlen (content) + 2, "%s,%s",
+                                            tmp, content);
+                                  free (tmp);
+                                }
+                              else
+                                {
+                                  snprintf (identifiers,
+                                            xmlStrlen (content) + 1, "%s",
+                                            content);
+                                }
+                              xmlFree (content);
+                            }
+                          xmlXPathFreeObject (idptr);
+                          addToMap (tmpMap, "Identifier", identifiers);
+                          free (identifiers);
+                        }
+                    }
+                }
+              xmlFreeDoc (doc);
+              xmlCleanupParser ();
+            }
+          else
+            {
+              freeMap (&tmpMap);
+              free (tmpMap);
+              tmpMap = createMap ("not_valid", "true");
+            }
+
+          char *token, *saveptr;
+          token = strtok_r (cgi->cgiQueryString, "&", &saveptr);
+          while (token != NULL)
+            {
+              char *token1, *saveptr1;
+              char *name = NULL;
+              char *value = NULL;
+              token1 = strtok_r (token, "=", &saveptr1);
+              while (token1 != NULL)
+                {
+                  if (name == NULL)
+                    name = zStrdup (token1);
+                  else
+                    value = zStrdup (token1);
+                  token1 = strtok_r (NULL, "=", &saveptr1);
+                }
+              addToMap (tmpMap, name, value);
+              free (name);
+              free (value);
+              name = NULL;
+              value = NULL;
+              token = strtok_r (NULL, "&", &saveptr);
+            }
+
+        }
+
+      if (strncasecmp (cgi->cgiContentType, "multipart/form-data", 19) == 0)
+        {
+          map *tmp = getMap (tmpMap, "dataInputs");
+          if (tmp != NULL)
+            {
+              addToMap (tmpMap, "dataInputs",
+                        strstr (strQuery, "dataInputs=") + 11);
+            }
+        }
+
+      if (strQuery != NULL)
+        free (strQuery);
+/*
+      json_object *obj;
+      maptojson(&obj,tmpMap);
+      fprintf(stderr,"%s\n",json_object_to_json_string(obj));
+      fflush(stderr);
+  */    
+      runRequest (&tmpMap,&cgi,request);
+
+  /** 
+   * Required but can't be made after executing a process using POST requests.
+   */
+      if ( /*strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && */ tmpMap != NULL)
+        {
+          freeMap (&tmpMap);
+          free (tmpMap);
+        }
+        // a verifier fait planter
+      cgiFreeResources (&cgi);
+
+      FCGX_Finish_r(request);
+      return 0;
+}
+
+
+
+int
+main (int argc, char *argv[])
+{
+ int debug_flag = 0;
+ int background_flag = 0;
+ char *file_value = NULL;
+ int index;
+ int c;
+ opterr = 0;
+ while ((c = getopt (argc, argv, "dbhf:")) != -1)
+      switch (c)
       {
-	xmlXPathObjectPtr reqptr=extractFromDoc(doc,"/*[local-name()='Envelope']/*[local-name()='Body']/*");
-	if(reqptr!=NULL){
-	  xmlNodeSet* req=reqptr->nodesetval;
-	  if(req!=NULL && req->nodeNr==1){
-	    addToMap(tmpMap,"soap","true");
-	    for(int k=0;k < req->nodeNr;k++){
-	      xmlDocSetRootElement(doc, req->nodeTab[k]);
-	      xmlChar *xmlbuff;
-	      int buffersize;
-	      xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, "utf-8", 1);
-	      addToMap(tmpMap,"xrequest",(char*)xmlbuff);
-	      xmlFree(xmlbuff);
-	    }
-	  }
-	  xmlXPathFreeObject(reqptr);
-	}
+      case 'd':
+        debug_flag = 1;
+        break;
+      case 'b':
+        background_flag = 1;
+        break;
+      case 'h':
+        fprintf(stderr,"TODO: need to print help\n");
+        fflush(stderr);
+        return 0;
+      case 'f':
+        file_value = optarg;
+        break;
+      case '?':
+        if (optopt == 'f')
+          fprintf (stderr, "Option -%c requires an argument.\n", optopt);
+        else if (isprint (optopt))
+          fprintf (stderr, "Unknown option `-%c'.\n", optopt);
+        else
+          fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt);
+        return 1;
+      default:
+        abort ();
       }
 
-      xmlNodePtr cur = xmlDocGetRootElement(doc);
-      char *tval;
-      tval=NULL;
-      tval = (char*) xmlGetProp(cur,BAD_CAST "service");
-      if(tval!=NULL){
-	addToMap(tmpMap,"service",tval);
-	xmlFree(tval);
-      }
-      tval=NULL;
-      tval = (char*) xmlGetProp(cur,BAD_CAST "language");
-      if(tval!=NULL){
-	addToMap(tmpMap,"language",tval);
-	xmlFree(tval);
-      }
-      const char* requests[3]={"GetCapabilities","DescribeProcess","Execute"};
-      for(int j=0;j<3;j++){
-	char tt[128];
-	sprintf(tt,"/*[local-name()='%s']",requests[j]);
-	xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
-	if(reqptr!=NULL){
-	  xmlNodeSet* req=reqptr->nodesetval;
-#ifdef DEBUG
-	  fprintf(stderr,"%i",req->nodeNr);
-#endif
-	  if(req!=NULL && req->nodeNr==1){
-	    if(t1->value!=NULL)
-	      free(t1->value);
-	    t1->value=zStrdup(requests[j]);
-	    j=2;
-	  }
-	  xmlXPathFreeObject(reqptr);
-	}
-      }
-      if(strncasecmp(t1->value,"GetCapabilities",15)==0){
-	xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
-	xmlNodeSet* vers=versptr->nodesetval;
-	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);
-	  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);
-	    }
-	}
-	xmlXPathFreeObject(versptr);
-      }else{
-	tval=NULL;
-	tval = (char*) xmlGetProp(cur,BAD_CAST "version");
-	if(tval!=NULL){
-	  addToMap(tmpMap,"version",tval);
-	  xmlFree(tval);
-	}
-	tval = (char*) xmlGetProp(cur,BAD_CAST "language");
-	if(tval!=NULL){
-	  addToMap(tmpMap,"language",tval);
-	  xmlFree(tval);
-	}
-	xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
-	if(idptr!=NULL){
-	  xmlNodeSet* id=idptr->nodesetval;
-	  if(id!=NULL){
-	    char* identifiers=NULL;
-	    identifiers=(char*)calloc(cgiContentLength,sizeof(char));
-	    identifiers[0]=0;
-	    for(int k=0;k<id->nodeNr;k++){
-	      xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
-	      if(strlen(identifiers)>0){
-		char *tmp=zStrdup(identifiers);
-		snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
-		free(tmp);
-	      }
-	      else{
-		snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
-	      }
-	      xmlFree(content);
-	    }
-	    xmlXPathFreeObject(idptr);
-	    addToMap(tmpMap,"Identifier",identifiers);
-	    free(identifiers);
-	  }
-	}else{
-	  idptr=extractFromDoc(doc,"/*/*[local-name()='JobID']");
-	  if(idptr!=NULL){
-	    xmlNodeSet* id=idptr->nodesetval;
-	    if(id!=NULL){
-	      char* identifiers=NULL;
-	      identifiers=(char*)calloc(cgiContentLength,sizeof(char));
-	      identifiers[0]=0;
-	      for(int k=0;k<id->nodeNr;k++){
-		xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
-		if(strlen(identifiers)>0){
-		  char *tmp=zStrdup(identifiers);
-		  snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
-		  free(tmp);
-		}
-		else{
-		  snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
-		}
-		xmlFree(content);
-	      }
-	      xmlXPathFreeObject(idptr);
-	      addToMap(tmpMap,"JobID",identifiers);
-	      free(identifiers);
-	    }
-	}
-	}
-      }
-      xmlFreeDoc(doc);
-      xmlCleanupParser();
-    }else{
-      freeMap(&tmpMap);
-      free(tmpMap);
-      tmpMap=createMap("not_valid","true");
-    }
-
-    char *token,*saveptr;
-    token=strtok_r(cgiQueryString,"&",&saveptr);
-    while(token!=NULL){
-      char *token1,*saveptr1;
-      char *name=NULL;
-      char *value=NULL;
-      token1=strtok_r(token,"=",&saveptr1);
-      while(token1!=NULL){
-        if(name==NULL)
-          name=zStrdup(token1);
-        else
-          value=zStrdup(token1);
-        token1=strtok_r(NULL,"=",&saveptr1);
-      }	  
-      //addToMap(tmpMap,name,value);
-	  /* knut: strtok(_r) ignores delimiter bytes at start and end of string; 
-	   * it will return non-empty string or NULL, e.g. "metapath=" yields value=NULL.
-	   * This modification sets value="" instead of NULL.
-	   */
-	  addToMap(tmpMap,name, value != NULL ? value : "");
-
-      free(name);
-      free(value);
-      name=NULL;
-      value=NULL;
-      token=strtok_r(NULL,"&",&saveptr);
-    }
-    
-  }
-
-  if(strncasecmp(cgiContentType,"multipart/form-data",19)==0){
-    map* tmp=getMap(tmpMap,"dataInputs");
-    if(tmp!=NULL){
-      addToMap(tmpMap,"dataInputs",strstr(strQuery,"dataInputs=")+11);
-    }
-  }
-
-  if(strQuery!=NULL)
-    free(strQuery);
-
+
+  maps *conf;
+  conf = (maps *) malloc (MAPS_SIZE);
   
-  runRequest(&tmpMap);
-
-  if(tmpMap!=NULL){
-    freeMap(&tmpMap);
-    free(tmpMap);
-  }
+  int ret = conf_read (file_value, conf);
+  if ( ret == 2){
+    //a verifier mais conf_read ne renvoie jamais 0
+    fprintf(stderr,"Erreur lors de la lecture de %s\n",file_value);
+    return 1;
+  }
+/* 
+ json_object *jobj;
+  mapstojson(&jobj,conf);
+  fprintf (stderr,"The json object created: %s\n",json_object_to_json_string(jobj));
+    freeMaps(&conf);
+ 
+  maps *conf_tmp;
+  jsontomaps(jobj,&conf_tmp);
+  dumpMaps(conf_tmp);
+   return 1;
+*/
+  char *rootDir;
+  map *m_rootDir = getMapFromMaps (conf, "server", "rootDir");
+  if (m_rootDir == NULL){
+    fprintf(stderr,"Configuration error: rootDir");
+    return 2;
+  }
+  else {
+   rootDir = (char*)malloc((strlen(m_rootDir->value) +1)*sizeof(char*));
+   strncpy(rootDir,m_rootDir->value,strlen(m_rootDir->value));
+   rootDir[strlen(m_rootDir->value)] = '\0';
+   //freeMap(&m_rootDir);
+  }
+
+char *regDir;
+  map *m_regDir = getMapFromMaps (conf, "main", "registry");
+  if (m_regDir == NULL){
+    fprintf(stderr,"Configuration error: regDir");
+    return 2;
+  }
+  else {
+   regDir = (char*)malloc((strlen(m_regDir->value) +1)*sizeof(char*));
+   strncpy(regDir,m_regDir->value,strlen(m_regDir->value));
+   regDir[strlen(m_regDir->value)] = '\0';
+  }
+
+
+
+  int req_worker;
+  map *m_req_worker = getMapFromMaps (conf, "server", "req_worker");
+  if (m_req_worker == NULL){
+    fprintf(stderr,"Configuration error: req.worker not found\n");
+    return 2;
+  }
+  else {
+    req_worker=atoi(m_req_worker->value);
+    //freeMap(&m_req_worker);
+    if (req_worker == 0){
+        fprintf(stderr,"Configuration error: req.worker\n");
+        return 2;
+    }
+  }
+  
+  int async_worker;
+  map *m_async_worker = getMapFromMaps (conf, "server", "async_worker");  
+  if (m_async_worker == NULL){
+    fprintf(stderr,"Configuration error: async_worker not found");
+    return 2;
+  }
+  else {
+    async_worker = atoi(m_async_worker->value);
+    //freeMap(&m_async_worker);
+    if (async_worker == 0){
+        fprintf(stderr,"Configuration error: req_worker");
+        return 2;
+    }
+  }
+
+  int max_requests;
+  map *m_max_requests = getMapFromMaps (conf, "server", "max_requests");
+  if (m_max_requests == NULL){
+    fprintf(stderr,"Configuration error: max_requests");
+    return 2;
+  }
+  else {
+    max_requests = atoi(m_max_requests->value);
+    //freeMap(&m_max_requests);
+    if (max_requests == 0){
+        fprintf(stderr,"Configuration error: max_requests");
+        return 2;
+    }
+  }
+
+  map *m_listen = getMapFromMaps (conf, "server", "listen");
+  char *listen;
+  if (m_listen == NULL){
+    fprintf(stderr,"Configuration error: listen not found");
+    return 2;
+  }
+  else {
+    listen = (char *)malloc((strlen(m_listen->value) +1)*sizeof(char*));
+    strncpy(listen,m_listen->value,strlen(m_listen->value));
+    listen[strlen(m_listen->value)] = '\0';
+    //freeMap(&m_listen);
+  }
+  int listen_owner;
+  map *m_listen_owner = getMapFromMaps (conf, "server", "listen_owner");
+  if (m_listen_owner == NULL){
+    fprintf(stderr,"Configuration error: listen_owner");
+    return 2;
+  }
+  else {
+    listen_owner = atoi(m_listen_owner->value);
+    //freeMap(&m_listen_owner);
+    if (listen_owner == 0){
+        fprintf(stderr,"Configuration error: listen_owner");
+        return 2;
+    }
+  }
+
+  int listen_group;
+  map *m_listen_group = getMapFromMaps (conf, "server", "listen_group");
+  if (m_listen_group == NULL){
+    fprintf(stderr,"Configuration error: listen_group");
+    return 2;
+  }
+  else {
+    listen_group = atoi(m_listen_group->value);
+    //freeMap(&m_listen_group);
+    if (listen_group == 0){
+        fprintf(stderr,"Configuration error: listen_group");
+        return 2;
+    }
+  }
+
+  char * listen_mode;
+  map *m_listen_mode = getMapFromMaps (conf, "server", "listen_mode");
+  if (m_listen_mode == NULL){
+    fprintf(stderr,"Configuration error: listen_mode");
+    return 2;
+  }
+  else {
+    listen_mode = (char *)malloc((strlen(m_listen_mode->value) +1)*sizeof(char*));
+    strncpy(listen_mode,m_listen_mode->value,strlen(m_listen_mode->value));
+    listen_mode[strlen(m_listen_mode->value)] = '\0';
+    //freeMap(&m_listen_mode);
+  }
+
+  int listen_queue;
+  map *m_listen_queue = getMapFromMaps (conf, "server", "listen_queue");
+  if (m_listen_queue == NULL){
+    fprintf(stderr,"Configuration error: listen_queue");
+    return 2;
+  }
+  else {
+    listen_queue = atoi(m_listen_queue->value);
+    //freeMap(&m_listen_queue);
+    if (listen_queue == 0){
+        fprintf(stderr,"Configuration error: listen_queue");
+        return 2;
+    }
+  }
+
+  int id_user;
+  map *m_user = getMapFromMaps (conf, "server", "uid");
+  if (m_user == NULL){
+    fprintf(stderr,"Configuration error: id_user");
+    return 2;
+  }
+  else {
+    id_user = atoi(m_user->value);
+    //freeMap(&m_user);
+    if (id_user == 0){
+        fprintf(stderr,"Configuration error: id_user");
+        return 2;
+    }
+  }
+
+
+  int id_group;
+  map *m_group = getMapFromMaps (conf, "server", "gid");
+  if (m_group == NULL){
+    fprintf(stderr,"Configuration error: gid");
+    return 2;
+  }
+  else {
+    id_group = atoi(m_group->value);
+    //freeMap(&m_group);
+    if (id_group == 0){
+        fprintf(stderr,"Configuration error: id_group");
+        return 2;
+    }
+  }
+
+
+  char * amqp_host;
+  map * m_amqp_host = getMapFromMaps (conf, "rabbitmq", "host");
+  if (m_amqp_host == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] host");
+    return 2;
+  }
+  else {
+    amqp_host = (char *)malloc((strlen(m_amqp_host->value) +1)*sizeof(char*));
+    strncpy(amqp_host,m_amqp_host->value,strlen(m_amqp_host->value));
+    amqp_host[strlen(m_amqp_host->value)] = '\0';
+ }
+
+  int amqp_port;
+  map *m_amqp_port = getMapFromMaps (conf, "rabbitmq", "port");
+  if (m_amqp_port == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] port");
+    return 2;
+  }
+  else {
+    amqp_port = atoi(m_amqp_port->value);
+    if (amqp_port == 0){
+        fprintf(stderr,"Configuration error: [rabbitmq] port");
+        return 2;
+    }
+  }
+
+  char * amqp_user;
+  map * m_amqp_user = getMapFromMaps (conf, "rabbitmq", "user");
+  if (m_amqp_user == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] user");
+    return 2;
+  }
+  else {
+    amqp_user = (char *)malloc((strlen(m_amqp_user->value) +1)*sizeof(char*));
+    strncpy(amqp_user,m_amqp_user->value,strlen(m_amqp_user->value));
+    amqp_user[strlen(m_amqp_user->value)] = '\0';
+ }
+
+  char * amqp_passwd;
+  map * m_amqp_passwd = getMapFromMaps (conf, "rabbitmq", "passwd");
+  if (m_amqp_passwd == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] passwd");
+    return 2;
+  }
+  else {
+    amqp_passwd = (char *)malloc((strlen(m_amqp_passwd->value) +1)*sizeof(char*));
+    strncpy(amqp_passwd,m_amqp_passwd->value,strlen(m_amqp_passwd->value));
+    amqp_passwd[strlen(m_amqp_passwd->value)] = '\0';
+ }
+
+  char * amqp_exchange;
+  map * m_amqp_exchange = getMapFromMaps (conf, "rabbitmq", "exchange");
+  if (m_amqp_exchange == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] exchange");
+    return 2;
+  }
+  else {
+    amqp_exchange = (char *)malloc((strlen(m_amqp_exchange->value) +1)*sizeof(char*));
+    strncpy(amqp_exchange,m_amqp_exchange->value,strlen(m_amqp_exchange->value));
+    amqp_exchange[strlen(m_amqp_exchange->value)] = '\0';
+ }
+
+  char * amqp_routingkey;
+  map * m_amqp_routingkey = getMapFromMaps (conf, "rabbitmq", "routingkey");
+  if (m_amqp_routingkey == NULL){
+    fprintf(stderr,"Configuration error: [amqp] routingkey");
+    return 2;
+  }
+  else {
+    amqp_routingkey = (char *)malloc((strlen(m_amqp_routingkey->value) +1)*sizeof(char*));
+    strncpy(amqp_routingkey,m_amqp_routingkey->value,strlen(m_amqp_routingkey->value));
+    amqp_routingkey[strlen(m_amqp_routingkey->value)] = '\0';
+ }
+
+  char * amqp_queue;
+  map * m_amqp_queue = getMapFromMaps (conf, "rabbitmq", "queue");
+  if (m_amqp_queue == NULL){
+    fprintf(stderr,"Configuration error: [rabbitmq] queue");
+    return 2;
+  }
+  else {
+    amqp_queue = (char *)malloc((strlen(m_amqp_queue->value) +1)*sizeof(char*));
+    strncpy(amqp_queue,m_amqp_queue->value,strlen(m_amqp_queue->value));
+    amqp_queue[strlen(m_amqp_queue->value)] = '\0';
+ }
+/*
+  char * status_user;
+  map * m_status_user = getMapFromMaps (conf, "status", "user");
+  if (m_status_user == NULL){
+    fprintf(stderr,"Configuration error: [status] user");
+    return 2;
+  }
+  else {
+    status_user = (char *)malloc((strlen(m_status_user->value) +1)*sizeof(char*));
+    strncpy(status_user,m_status_user->value,strlen(m_status_user->value));
+    status_user[strlen(m_status_user->value)] = '\0';
+  }
+
+
+  char * status_passwd;
+  map * m_status_passwd = getMapFromMaps (conf, "status", "passwd");
+  if (m_status_passwd == NULL){
+    fprintf(stderr,"Configuration error: [status] passwd");
+    return 2;
+  }
+  else {
+    status_passwd = (char *)malloc((strlen(m_status_passwd->value) +1)*sizeof(char*));
+    strncpy(status_passwd,m_status_passwd->value,strlen(m_status_passwd->value));
+    status_passwd[strlen(m_status_passwd->value)] = '\0';
+  }
+
+  char * status_bdd;
+  map * m_status_bdd = getMapFromMaps (conf, "status", "bdd");
+  if (m_status_bdd == NULL){
+    fprintf(stderr,"Configuration error: [status] bdd");
+    return 2;
+  }
+  else {
+    status_bdd = (char *)malloc((strlen(m_status_bdd->value) +1)*sizeof(char*));
+    strncpy(status_bdd,m_status_bdd->value,strlen(m_status_bdd->value));
+    status_bdd[strlen(m_status_bdd->value)] = '\0';
+  }
+
+  char * status_host;
+  map * m_status_host = getMapFromMaps (conf, "status", "host");
+  if (m_status_host == NULL){
+    fprintf(stderr,"Configuration error: [status] host");
+    return 2;
+  }
+  else {
+    status_host = (char *)malloc((strlen(m_status_host->value) +1)*sizeof(char*));
+    strncpy(status_host,m_status_host->value,strlen(m_status_host->value));
+    status_host[strlen(m_status_host->value)] = '\0';
+  }
+
+  int status_port;
+  map *m_status_port = getMapFromMaps (conf, "status", "port");
+  if (m_status_port == NULL){
+    fprintf(stderr,"Configuration error: [status] port");
+    return 2;
+  }
+  else {
+    status_port = atoi(m_status_port->value);
+    if (status_port == 0){
+        fprintf(stderr,"Configuration error: [status] port");
+        return 2;
+    }
+  }
+  */
+  int sock = FCGX_OpenSocket(listen, listen_queue); 
+  init_services_conf (rootDir,regDir);
+  
+  ret = chown(listen, listen_owner, listen_group); 
+  if (ret != 0){
+    fprintf(stderr,"Change owner error on : %s\n",listen);
+    return 3;
+  }
+  /*
+  ret = setgid(id_group);
+  if (ret != 0){
+    fprintf(stderr,"Change gid error\n");
+    return 3;
+  }
+
+  ret = setuid(id_user);
+  if (ret != 0){
+    fprintf(stderr,"Change uid error\n");
+    return 3;
+  }
+*/
+
+#ifdef AMQP
+  init_amqp(amqp_host,amqp_port,amqp_user, amqp_passwd, amqp_exchange, amqp_routingkey,amqp_queue);
+#endif
+
+  int fork_status = fork();
+  if (fork_status == 0){
+    //child
+    int master_sync= getpid();
+    fprintf(stderr,"Master sync%d\n",getpid());
+    FCGX_Init();
+    FCGX_Request request;
+    FCGX_InitRequest(&request, sock, 0);
+    int i;
+    int count_request = 0;
+    for (i = 0; i< req_worker; i++){
+        fork_status = fork();
+        if (fork_status == 0){
+            fprintf(stderr,"child sync %d \n",getpid());
+            fflush(stderr);
+            break;
+        }
+    }
+    while(1){
+        /* mode synchrone */
+        if (master_sync != getpid()){
+            while(FCGX_Accept_r(&request) == 0){
+                process(&request);
+                count_request ++;
+                if (count_request >= max_requests){
+                    fprintf(stderr,"Max request stop process\n");
+                    fflush(stderr);
+                    exit(0);
+                }
+            }
+        }
+        else {
+            wait(0);
+            fprintf(stderr,"Master sync %d\n",getpid());
+            fprintf(stderr,"New sync Child\n");
+            fflush(stderr);
+            fork();
+        }
+    }
+  }
+  while(1);
+  
   return 0;
-
 }
+ 
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 741)
@@ -32,5 +32,5 @@
 #endif
 
-#include "cgic.h"
+//#include "cgic.h"
 
 extern "C"
@@ -45,5 +45,5 @@
 #include "ulinet.h"
 
-#include <libintl.h>
+//#include <libintl.h>
 #include <locale.h>
 #include <string.h>
@@ -56,4 +56,6 @@
 #include "request_parser.h"
 #include "sqlapi.h"
+#include "zoo_amqp.h"
+#include "zoo_json.h"
 
 #ifdef USE_PYTHON
@@ -237,5 +239,5 @@
            ("ZOO Kernel failed to process your request, receiving signal %d = %s"),
            sig, ssig);
-  errorException (NULL, tmp, "InternalError", NULL);
+  errorException (NULL, tmp, "InternalError", NULL,NULL);
 #ifdef DEBUG
   fprintf (stderr, "Not this time!\n");
@@ -256,5 +258,5 @@
 void
 loadServiceAndRun (maps ** myMap, service * s1, map * request_inputs,
-                   maps ** inputs, maps ** ioutputs, int *eres)
+                   maps ** inputs, maps ** ioutputs, int *eres,FCGX_Stream *out, FCGX_Stream *err)
 {
   char tmps1[1024];
@@ -386,5 +388,4 @@
               typedef int (*execute_t) (maps **, maps **, maps **);
 
-              fprintf(stderr,"%s \n",s1->name);
 #ifdef WIN32
               execute_t execute =
@@ -407,5 +408,5 @@
                            ("Error occured while running the %s function: %s"),
                            s1->name, errstr);
-                  errorException (m, tmpMsg, "InternalError", NULL);
+                  errorException (m, tmpMsg, "InternalError", NULL,out);
                   free (tmpMsg);
 #ifdef DEBUG
@@ -457,5 +458,5 @@
 #endif
           sprintf (tmps, _("Unable to load C Library %s"), errstr);
-	  errorException(m,tmps,"InternalError",NULL);
+	  errorException(m,tmps,"InternalError",NULL,out);
           *eres = -1;
         }
@@ -553,7 +554,8 @@
                ("Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n"),
                r_inputs->value);
-      errorException (m, tmpv, "InternalError", NULL);
+      errorException (m, tmpv, "InternalError", NULL,out);
       *eres = -1;
     }
+   fflush(stderr);
   *myMap = m;
   *ioutputs = request_output_real_format;
@@ -728,7 +730,8 @@
  */
 int
-runRequest (map ** inputs)
+runRequest (map ** inputs,struct cgi_env ** c,FCGX_Request *request)
 {
-
+struct cgi_env *cgi = *c;
+char *cgiSid = cgi->cgiSid; 
 #ifndef USE_GDB
 #ifndef WIN32
@@ -757,5 +760,5 @@
     {
       return errorException (m, _("Unable to allocate memory."),
-                             "InternalError", NULL);
+                             "InternalError", NULL,request->out);
     }
   char ntmp[1024];
@@ -772,5 +775,5 @@
     {
       errorException (NULL, _("Unable to load the main.cfg file."),
-                      "InternalError", NULL);
+                      "InternalError", NULL,request->out);
       free (m);
       return 1;
@@ -819,5 +822,5 @@
                    ("The value %s is not supported for the <language> parameter"),
                    r_inputs->value);
-          errorException (m, tmp, "InvalidParameterValue", "language");
+          errorException (m, tmp, "InvalidParameterValue", "language",request->out);
           freeMaps (&m);
           free (m);
@@ -870,22 +873,22 @@
     setMapInMaps (m, "main", "isSoap", "false");
 
-  if(strlen(cgiServerName)>0)
+  if(strlen(cgi->cgiServerName)>0)
     {
       char tmpUrl[1024];
 	
       if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?		
-	if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
-	  sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
+	if ( strncmp(cgi->cgiServerPort, "443", 3) == 0 ) { 
+	  sprintf(tmpUrl, "https://%s%s", cgi->cgiServerName, cgi->cgiScriptName);
 	}
 	else {
-	  sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
+	  sprintf(tmpUrl, "https://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName);
 	}
       }
       else {
-	if ( strncmp(cgiServerPort, "80", 2) == 0 ) { 
-	  sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
+	if ( strncmp(cgi->cgiServerPort, "80", 2) == 0 ) { 
+	  sprintf(tmpUrl, "http://%s%s", cgi->cgiServerName, cgi->cgiScriptName);
 	}
 	else {
-	  sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
+	  sprintf(tmpUrl, "http://%s:%s%s", cgi->cgiServerName, cgi->cgiServerPort, cgi->cgiScriptName);
 	}
       }
@@ -913,5 +916,5 @@
   if(err!=NULL){
     checkValidValue(request_inputs,&err,"service",(const char**)vvs,1);
-    printExceptionReportResponse (m, err);
+    printExceptionReportResponse (m, err,request->out);
     freeMap(&err);
     free(err);
@@ -969,5 +972,5 @@
   }
   if(err!=NULL){
-    printExceptionReportResponse (m, err);
+    printExceptionReportResponse (m, err,request->out);
     freeMap(&err);
     free(err);
@@ -1024,41 +1027,14 @@
       xmlNodePtr n=printGetCapabilitiesHeader(doc,m,(version!=NULL?version->value:"1.0.0"));
       CapabilitiesAllProcess(m,n);
+      
       /**
        * Here we need to close stdout to ensure that unsupported chars 
        * has been found in the zcfg and then printed on stdout
        */
-      /*
-      int saved_stdout = dup (fileno (stdout));
-      dup2 (fileno (stderr), fileno (stdout));
-      if (int res =		  
-          recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
-                          printGetCapabilitiesForProcess) < 0)
-        {
-          freeMaps (&m);
-          free (m);
-	  if(zooRegistry!=NULL){
-	    freeRegistry(&zooRegistry);
-	    free(zooRegistry);
-	  }
-          free (REQUEST);
-          free (SERVICE_URL);
-          fflush (stdout);
-          return res;
-        }
-      fflush (stdout);
-      dup2 (saved_stdout, fileno (stdout));
-      */
-      printDocument (m, doc, getpid ());
+      printDocument (m, doc, getpid (),request->out);
       freeMaps (&m);
       free (m);
-      /*
-      if(zooRegistry!=NULL){
-	freeRegistry(&zooRegistry);
-	free(zooRegistry);
-      }
-*/
       free (REQUEST);
       free (SERVICE_URL);
-      fflush (stdout);
       return 0;
     }
@@ -1069,5 +1045,5 @@
 	if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
 	    strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
-	  runGetStatus(m,r_inputs->value,REQUEST);
+	  runGetStatus(m,r_inputs->value,REQUEST,request->out);
 	  freeMaps (&m);
 	  free (m);
@@ -1078,5 +1054,5 @@
 	else
 	  if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){
-	    runDismiss(m,r_inputs->value);
+	    runDismiss(m,r_inputs->value,request->out);
 	    freeMaps (&m);
 	    free (m);
@@ -1091,16 +1067,4 @@
 	r_inputs = getMap (request_inputs, "Identifier");
 
-	struct dirent *dp;
-	DIR *dirp = opendir (conf_dir);
-	if (dirp == NULL)
-	  {
-	    errorException (m, _("The specified path path does not exist."),
-			    "InvalidParameterValue", conf_dir);
-	    freeMaps (&m);
-	    free (m);
-	    free (REQUEST);
-	    free (SERVICE_URL);
-	    return 0;
-	  }
 	if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
 	  {
@@ -1119,19 +1083,16 @@
 
         DescribeProcess(m,n,orig);
-	    fflush (stdout);
         int saved_stdout;
-	    dup2 (saved_stdout, fileno (stdout));
 	    free (orig);
-	    printDocument (m, doc, getpid ());
+	    printDocument (m, doc, getpid (),request->out);
 	    freeMaps (&m);
 	    free (m);
 	    free (REQUEST);
 	    free (SERVICE_URL);
-	    fflush (stdout);
 	    return 0;
 	  }
 	else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
 	  {
-	    map* version=getMapFromMaps(m,"main","rversion");
+        map* version=getMapFromMaps(m,"main","rversion");
 	    int vid=getVersionId(version->value);
 	    int len,j=0;
@@ -1169,17 +1130,14 @@
 	    char* message=(char*)malloc((61+len)*sizeof(char));
 	    sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr);
-	    errorException (m,_(message),"InvalidParameterValue", "request");
+	    errorException (m,_(message),"InvalidParameterValue", "request",request->out);
 #ifdef DEBUG
 	    fprintf (stderr, "No request found %s", REQUEST);
 #endif
-	    closedir (dirp);
 	    freeMaps (&m);
 	    free (m);
 	    free (REQUEST);
 	    free (SERVICE_URL);
-	    fflush (stdout);
 	    return 0;
 	  }
-	closedir (dirp);
       }
     }
@@ -1187,19 +1145,18 @@
   map *postRequest = NULL;
   postRequest = getMap (request_inputs, "xrequest");
-
+/*
   if(vid==1 && postRequest==NULL){
-    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request");  
+    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request",request->out);  
     freeMaps (&m);
     free (m);
     free (REQUEST);
     free (SERVICE_URL);
-    fflush (stdout);
     return 0;
   }
-  
+  */
   s1 = NULL;
   r_inputs = getMap (request_inputs, "Identifier");
   s1 = search_service (r_inputs->value);
- int saved_stdout = dup (fileno (stdout));
+ int saved_stdout;// = dup (fileno (stdout));
   
   
@@ -1211,5 +1168,5 @@
                ("The value for <identifier> seems to be wrong (%s). Please specify one of the processes in the list returned by a GetCapabilities request."),
                r_inputs->value);
-      errorException (m, tmpMsg, "InvalidParameterValue", "identifier");
+      errorException (m, tmpMsg, "InvalidParameterValue", "identifier",request->out);
       free (tmpMsg);
       freeMaps (&m);
@@ -1219,5 +1176,7 @@
       return 0;
     }
-  close (saved_stdout);
+  setMapInMaps (m, "lenv", "Identifier", r_inputs->value);
+  setMapInMaps (m, "lenv", "oIdentifier", r_inputs->value);
+
 
 #ifdef DEBUG
@@ -1248,5 +1207,5 @@
 
 
-  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){
+  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
     freeMaps (&m);
     free (m);
@@ -1334,7 +1293,5 @@
 			_
 			("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
-			"InvalidParameterValue", "storeExecuteResponse");
-	//freeService (&s1);
-	free (s1);
+			"InvalidParameterValue", "storeExecuteResponse",request->out);
 	freeMaps (&m);
 	free (m);
@@ -1361,6 +1318,5 @@
 	if(mode!=NULL){
 	  // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61
-	  errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value);  
-	  fflush (stdout);
+	  errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value,request->out);  
 	  freeMaps (&m);
 	  free (m);
@@ -1440,8 +1396,8 @@
 
   // Parse the session file and add it to the main maps 
-  if (cgiCookie != NULL && strlen (cgiCookie) > 0)
+  if (cgi->cgiCookie != NULL && strlen (cgi->cgiCookie) > 0)
     {
       int hasValidCookie = -1;
-      char *tcook = zStrdup (cgiCookie);
+      char *tcook = zStrdup (cgi->cgiCookie);
       char *tmp = NULL;
       map *testing = getMapFromMaps (m, "main", "cookiePrefix");
@@ -1456,8 +1412,8 @@
           sprintf (tmp, "%s=", testing->value);
         }
-      if (strstr (cgiCookie, ";") != NULL)
+      if (strstr (cgi->cgiCookie, ";") != NULL)
         {
           char *token, *saveptr;
-          token = strtok_r (cgiCookie, ";", &saveptr);
+          token = strtok_r (cgi->cgiCookie, ";", &saveptr);
           while (token != NULL)
             {
@@ -1474,8 +1430,8 @@
       else
         {
-          if (strstr (cgiCookie, "=") != NULL
-              && strcasestr (cgiCookie, tmp) != NULL)
+          if (strstr (cgi->cgiCookie, "=") != NULL
+              && strcasestr (cgi->cgiCookie, tmp) != NULL)
             {
-              tcook = zStrdup (cgiCookie);
+              tcook = zStrdup (cgi->cgiCookie);
               hasValidCookie = 1;
             }
@@ -1498,5 +1454,5 @@
           else
             sprintf (session_file_path, "%s/sess_%s.cfg", tmpPath->value,
-                     strstr (cgiCookie, "=") + 1);
+                     strstr (cgi->cgiCookie, "=") + 1);
           free (tcook);
           maps *tmpSess = (maps *) malloc (MAPS_SIZE);
@@ -1539,4 +1495,5 @@
     }
 #endif
+
   char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
   FILE *f0, *f1;
@@ -1546,6 +1503,5 @@
   if (status == NULLMAP)
     {
-      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
-	free (s1);
+      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
 	freeMaps (&m);
 	free (m);
@@ -1560,10 +1516,53 @@
 	return -1;
       }
-
+       fflush(stderr);
       loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
-                         &request_output_real_format, &eres);
-    }
-  else
-    {
+                         &request_output_real_format, &eres,request->out,request->err);
+    }
+  else
+    {
+        
+        eres = SERVICE_ACCEPTED;
+        vid = 1;
+        
+#ifdef AMQP
+
+
+    eres = SERVICE_ACCEPTED;
+    json_object *msg_jobj = json_object_new_object();
+    json_object *maps_obj;
+    mapstojson(&maps_obj,m);
+    json_object_object_add(msg_jobj,"maps",maps_obj);
+
+
+    json_object *req_format_jobj;
+    mapstojson(&req_format_jobj,request_input_real_format);
+    json_object_object_add(msg_jobj,"request_input_real_format",req_format_jobj);
+
+    json_object *req_jobj;
+    maptojson(&req_jobj,request_inputs);
+    json_object_object_add(msg_jobj,"request_inputs",req_jobj);
+
+ 
+    dumpMaps(request_output_real_format);
+    json_object *outputs_jobj;
+    mapstojson(&outputs_jobj,request_output_real_format);
+    json_object_object_add(msg_jobj,"request_output_real_format",outputs_jobj);
+  
+    bind_amqp();
+
+    if ( (send_msg(json_object_to_json_string(msg_jobj),"application/json") != 0) ){     
+        eres = SERVICE_FAILED;
+    }
+    close_amqp();
+    json_object_put(msg_jobj);
+    
+    init_sql(m);
+    recordServiceStatus(m);
+
+
+
+        
+#else
       int pid;
 #ifdef DEBUG
@@ -1687,6 +1686,6 @@
 	    printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
 				  SERVICE_STARTED, request_input_real_format,
-				  request_output_real_format);
-	    fflush (stdout);
+				  request_output_real_format,request->out);
+
 #ifdef RELY_ON_DB
 	    recordResponse(m,fbkp);
@@ -1705,7 +1704,5 @@
           f1 = freopen (fbkp1, "w+", stdout);
 
-	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
-	    //freeService (&s1);
-	    free (s1);
+	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet,cgi)<0){
 	    freeMaps (&m);
 	    free (m);
@@ -1718,12 +1715,12 @@
 	    freeMaps (&tmpmaps);
 	    free (tmpmaps);
-	    fflush (stdout);
 	    fflush (stderr);
 	    unhandleStatus (m);
 	    return -1;
 	  }
+      
           loadServiceAndRun (&m, s1, request_inputs,
                              &request_input_real_format,
-                             &request_output_real_format, &eres);
+                             &request_output_real_format, &eres,request->out,request->err);
 
         }
@@ -1736,7 +1733,13 @@
           eres = -1;
           errorException (m, _("Unable to run the child process properly"),
-                          "InternalError", NULL);
+                          "InternalError", NULL,request->out);
         }
-    }
+
+#endif
+
+    }
+
+
+
 
 #ifdef DEBUG
@@ -1746,7 +1749,8 @@
     outputResponse (s1, request_input_real_format,
                     request_output_real_format, request_inputs,
-                    cpid, m, eres);
-  fflush (stdout);
+                    cpid, m, eres,request->out);
+  //fflush (stdout);
   
+
   /**
    * Ensure that if error occurs when freeing memory, no signal will return
@@ -1819,7 +1823,4 @@
       free (tmps1);
     }
-
-  //freeService (&s1);
-  free (s1);
   freeMaps (&m);
   free (m);
Index: branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_zcfg.c
===================================================================
--- branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_zcfg.c	(revision 678)
+++ branches/PublicaMundi_David_integration_01-devel/zoo-project/zoo-kernel/zoo_zcfg.c	(revision 741)
@@ -269,5 +269,4 @@
 #ifdef DEBUG
       dumpService (s1);
-      fflush (stdout);
       fflush (stderr);
 #endif
