Index: /trunk/docs/kernel/index.txt
===================================================================
--- /trunk/docs/kernel/index.txt	(revision 633)
+++ /trunk/docs/kernel/index.txt	(revision 634)
@@ -13,3 +13,4 @@
    mapserver
    orfeotoolbox
+   sagagis
 
Index: /trunk/docs/kernel/sagagis.txt
===================================================================
--- /trunk/docs/kernel/sagagis.txt	(revision 634)
+++ /trunk/docs/kernel/sagagis.txt	(revision 634)
@@ -0,0 +1,91 @@
+.. _kernel-sagagis:
+    
+How To Use the SAGA-GIS support
+=============================================
+
+:Authors: Nicolas Bozon, Gérald Fenoy, Jeff McKenna
+:Last Updated: $Date: 2015-02-09 18:33:28 +0100 (Lun, 09 fév 2015) $ 
+
+The key idea of the ZOO `SAGA GIS <http://saga-gis.org/>`_  support implementation is to take advantage of the `SAGA-GIS Modules <http://www.saga-gis.org/saga_module_doc/2.1.4/index.html>`_ by using them directly as ZOO-Services, without any modifications.  
+
+Here is an overview of the installation procedure and the required configuration to activate the SAGA-GIS support in ZOO-Project. 
+
+.. contents:: Table of Contents
+    :depth: 3
+    :backlinks: top
+
+How to make it working ?
+------------------------
+
+Requirements
+**************
+
+   * latest `ZOO-Kernel <http://zoo-project.org/trac/browser/trunk/zoo-project/zoo-kernel>`_ trunk version
+   * SAGA-GIS (`SAGA-GIS 2.1.4 <http://saga-gis.org/>`_ )
+   * libLAS-1.2  (`LibLAS-1.2 <https://github.com/libLAS/libLAS-1.2>`_ )
+
+Installation steps
+********************
+
+Download lastest ZOO-Kernel code from SVN.
+
+.. code-block:: guess
+
+    svn checkout http://svn.zoo-project.org/svn/trunk/zoo-kernel zoo-kernel
+
+Then compile ZOO-Kernel using the needed configuration options as shown bellow:
+
+.. code-block:: guess
+
+     cd zoo-kernel
+     autoconf
+     ./configure  --with-saga=/usr/local/
+     make
+     cp zoo_loader.cgi /usr/lib/cgi-bin
+
+Configuration steps
+*************************
+
+Services configuration file
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Building the `saga2zcfg  <http://zoo-project.org/trac/browser/trunk/thirds/otb2zcfg>`_ utility is required to activate the available SAGA-GIS Modules as WPS Services. This can be done using the following command: 
+
+.. code-block:: guess
+	
+	cd thirds/saga2zcfg
+	 make
+	
+Run the following command to generate all the needed zcfg files for the available SAGA-GIS Modules:
+
+.. code-block:: guess
+	
+	 mkdir zcfgs
+	 cd zcfgs
+	 ../saga2zcfg
+         mkdir /location/to/your/cgi-bin/SAGA
+	 cp *zcfg /location/to/your/cgi-bin/SAGA
+	
+Test the ZOO SAGA support
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Once done, SAGA-GIS Modules should be listed as available WPS Services when runing a GetCapabilities request
+
+.. code-block:: guess 
+
+        http://localhost/cgi-bin/zoo_loader.cgi?request=GetCapabilities&service=WPS 
+
+Each SAGA-GIS Service can then be described individually using the DescribeProcess request, as for example:
+
+.. code-block:: guess
+
+   http://localhost/cgi-bin/zoo_loader.cgi?request=DescribeProcess&service=WPS&version=1.0.0&Identifier=SAGA.garden_fractals.1
+
+And executed according to your needs, as for the following example
+executing SAGA.garden_fractals.1 with no optional parameter
+
+.. code-block:: guess
+
+   http://localhost/cgi-bin/zoo_loader.cgi?request=Execute&service=WPS&version=1.0.0&Identifier=SAGA.garden_fractals.1&DataInputs=&ResponseDocument=RESULT@mimeType=application/json@asReference=true
+
+When executing SAGA-GIS Modules as WPS Services, it is also possible to check its ongoing status, using the usual asynchronous Execute requests and polling the ZOO GetStatus request.
Index: /trunk/docs/services/howtos.txt
===================================================================
--- /trunk/docs/services/howtos.txt	(revision 633)
+++ /trunk/docs/services/howtos.txt	(revision 634)
@@ -19,6 +19,15 @@
 ----------------------
 
-The function of the process for each programming language take three arguments: the main
-configuration, inputs and outputs.
+A ZOO-Service is a couple composed of a ZCFG file and a
+ServiceProvider. This last depend of the programming language but
+should expose at least one function corresponding to the Service. This
+function take three arguments: the main configuration, inputs and
+outputs and return an integer:
+* 3 if the process run sucessfully
+* 4 in case any error occur. In such a case, programmer may add
+detailler message map
+
+Data structures for those arguments depend on the programming
+-UMRlanguage and is detailled below.
 
 .. Note:: The service has to **return 3 if the process run successfully instead it 
Index: /trunk/thirds/saga2zcfg/Makefile
===================================================================
--- /trunk/thirds/saga2zcfg/Makefile	(revision 634)
+++ /trunk/thirds/saga2zcfg/Makefile	(revision 634)
@@ -0,0 +1,14 @@
+ZRPATH=../../zoo-project
+include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
+CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+CC=gcc
+
+WXCXX=`wx-config --cxx`
+WXCFLAGS=`wx-config --cxxflags`
+WXLIBS=`wx-config --libs`
+
+saga2zcfg: saga2zcfg.c
+	${WXCXX} ${SAGA_CFLAGS} ${WXCFLAGS} ${CFLAGS} -fpic -o saga2zcfg ./saga2zcfg.c ${GDAL_LIBS} ${MACOS_LD_FLAGS}  ${WXLIBS} ${SAGA_LDFLAGS}
+
+clean:
+	rm -f saga2zcfg
Index: /trunk/thirds/saga2zcfg/saga2zcfg.c
===================================================================
--- /trunk/thirds/saga2zcfg/saga2zcfg.c	(revision 634)
+++ /trunk/thirds/saga2zcfg/saga2zcfg.c	(revision 634)
@@ -0,0 +1,367 @@
+#include <locale.h>
+
+#include <wx/app.h>
+#include <wx/utils.h>
+
+#include <api_core.h>
+#include <module_library.h>
+
+int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2){
+  return( 1 );
+}
+
+TSG_PFNC_UI_Callback Get_Callback(void){
+  return( &Callback );
+}
+
+const char* cleanAbstract(CSG_String abstract){
+  char* tmp=strdup(abstract.b_str());
+  CSG_String val=CSG_String("")+tmp;
+  if(val.Contains("¸")){
+    val.Replace("¸"," ");
+  }
+  if(val.Contains("\n")){
+    val.Replace("\n","<br/>");
+  }
+  if(val.Contains("<")){
+    val.Replace("<","&lt;");
+  }
+  if(val.Contains(">")){
+    val.Replace(">","&gt;");
+    fprintf(stderr,"%s\n",val.b_str());
+  }
+  free(tmp);
+  fprintf(stderr,"%s\n",val.b_str());
+  return val.b_str();
+}
+
+void printBasicMetadata(FILE* stdout,CSG_Parameter* param,bool out=false,bool range=false,bool min=true,bool tin=false,char* tname=NULL,char* ttitle=NULL){
+  fprintf(stdout," [%s]\n",(CSG_String(param->Get_Identifier())+(range?(min?"_MIN":"_MAX"):(tin?CSG_String("_")+tname:""))).b_str());
+  fprintf(stdout,"  Title = %s\n",(CSG_String(param->Get_Name())+(range?(min?" (min value)":" (max value)"):(tin&&ttitle!=NULL?ttitle:""))).b_str());
+  if(CSG_String(param->Get_Description()).is_Empty())
+    fprintf(stdout,"  Abstract = %s\n",CSG_String(param->Get_Name()).b_str());
+  else{
+    fprintf(stdout,"  Abstract = %s\n",cleanAbstract(CSG_String(param->Get_Description()).BeforeFirst('\n')));
+  }
+  if(!out){
+    if(param->is_Option() || param->is_Optional()){
+      fprintf(stdout,"  minOccurs = 0\n");
+      if(param->is_Option())
+	fprintf(stdout,"  maxOccurs = 1\n");
+      else{
+	if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("_list")))
+	  fprintf(stdout,"  maxOccurs = 1024\n");
+	else
+	  fprintf(stdout,"  maxOccurs = 1\n");
+      }
+    }else{
+      if(param->is_Input())
+	fprintf(stdout,"  minOccurs = 1\n");
+      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("_list")))
+	fprintf(stdout,"  maxOccurs = 1024\n");
+      else
+	fprintf(stdout,"  maxOccurs = 1\n");
+    }
+  }
+  if(range){
+    
+  }
+}
+
+void printGrids(FILE* stdout){
+  fprintf(stdout,"  <ComplexData>\n");
+  fprintf(stdout,"   <Default>\n");
+  fprintf(stdout,"    mimeType = image/tiff\n");
+  fprintf(stdout,"   </Default>\n");
+  fprintf(stdout,"   <Supported>\n");
+  fprintf(stdout,"    mimeType = application/x-ogc-envi\n");
+  fprintf(stdout,"   </Supported>\n");
+  fprintf(stdout,"   <Supported>\n");
+  fprintf(stdout,"    mimeType = application/x-ogc-aaigrid\n");
+  fprintf(stdout,"   </Supported>\n");
+  fprintf(stdout,"  </ComplexData>\n");
+}
+
+void printShapes(FILE* stdout){
+  fprintf(stdout,"  <ComplexData>\n");
+  fprintf(stdout,"   <Default>\n");
+  fprintf(stdout,"    mimeType = text/xml\n");
+  fprintf(stdout,"    encoding = utf-8\n");
+  fprintf(stdout,"   </Default>\n");
+  fprintf(stdout,"   <Supported>\n");
+  fprintf(stdout,"    mimeType = application/vnd.google-earth.kml+xml\n");
+  fprintf(stdout,"   </Supported>\n");
+  fprintf(stdout,"   <Supported>\n");
+  fprintf(stdout,"    mimeType = application/json\n");
+  fprintf(stdout,"   </Supported>\n");
+  fprintf(stdout,"  </ComplexData>\n");
+}
+
+void printTables(FILE* stdout){
+  fprintf(stdout,"  <ComplexData>\n");
+  fprintf(stdout,"   <Default>\n");
+  fprintf(stdout,"    mimeType = text/csv\n");
+  fprintf(stdout,"    encoding = utf-8\n");
+  fprintf(stdout,"   </Default>\n");
+  fprintf(stdout,"   <Supported>\n");
+  fprintf(stdout,"    mimeType = text/csv\n");
+  fprintf(stdout,"    encoding = base64\n");
+  fprintf(stdout,"   </Supported>\n");
+  fprintf(stdout,"  </ComplexData>\n");
+}
+
+void printPoints(FILE* stdout){
+  fprintf(stdout,"  <ComplexData>\n");
+  fprintf(stdout,"   <Default>\n");
+  fprintf(stdout,"    mimeType = application/x-ogc-lasf\n");
+  fprintf(stdout,"    extension = las\n");
+  fprintf(stdout,"   </Default>\n");
+  fprintf(stdout,"  </ComplexData>\n");
+}
+
+int main(int argc, char *argv[]) {
+  if( !wxInitialize() ){
+    fprintf(stderr,"initialisation failed");
+    return -1;
+  }
+  setlocale(LC_NUMERIC, "C");
+  static bool g_bShow_Messages = false;
+  SG_Set_UI_Callback(Get_Callback());
+  int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
+  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){
+    fprintf(stderr,"could not load any tool library");
+    return -2;
+  }
+
+  for(int i=0;i<SG_Get_Module_Library_Manager().Get_Count();i++){
+    
+    CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(i);
+    int lc=library->Get_Count();
+    if(!library->Get_Library_Name().Contains("io_")) {
+
+      for(int j=0;j<lc;j++){
+	CSG_Module * module=library->Get_Module(j);
+	if(module!=NULL && !module->needs_GUI() /*&& !module->is_Interactive()*/ ){
+
+	  mkdir(library->Get_Library_Name().b_str(),0755);
+	  FILE *stdout1=fopen((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str(),"w+");
+	  fprintf(stdout1,"[%d]\n",j);
+	  fprintf(stdout1," Title = %s\n",module->Get_Name().b_str());
+	  if(CSG_String(module->Get_Description()).is_Empty())
+	    fprintf(stdout1," Abstract = %s\n",module->Get_Name().b_str());
+	  else
+	    fprintf(stdout1," Abstract = %s\n",cleanAbstract(module->Get_Description()));
+	  fprintf(stdout1," storeSupported = true\n");
+	  fprintf(stdout1," statusSupported = true\n");
+	  fprintf(stdout1," serviceType = SAGA\n");
+	  fprintf(stdout1," serviceProvider = %s\n",library->Get_Library_Name().b_str());
+	  CSG_Parameters * params=module->Get_Parameters();
+	  int pc=params->Get_Count();
+
+	  fprintf(stdout1," <DataInputs>\n");
+	  for(int k=0;k<pc;k++){
+	    CSG_Parameter * param=params->Get_Parameter(k);
+	  
+	    // Node should be used for defining Complex ComplexData
+	    if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("color"))){
+	      
+	    }
+	    else if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("range"),true)){
+
+	      param->Restore_Default();
+
+	      printBasicMetadata(stdout1,param,false,true,true);
+	      fprintf(stdout1,"  <LiteralData>\n");
+	      fprintf(stdout1,"   dataType = float\n");
+	      CSG_Parameter_Range *range=param->asRange();
+	      fprintf(stdout1,"   <Default>\n");
+	      fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_LoVal());
+	      fprintf(stdout1,"   </Default>\n");
+	      fprintf(stdout1,"  </LiteralData>\n");
+
+	      printBasicMetadata(stdout1,param,false,true,false);
+	      fprintf(stdout1,"  <LiteralData>\n");
+	      fprintf(stdout1,"   dataType = float\n");
+	      fprintf(stdout1,"   <Default>\n");
+	      fprintf(stdout1,"    value = %f\n",((CSG_Parameter_Range*)param->Get_Data())->Get_HiVal());
+	      fprintf(stdout1,"   </Default>\n");
+	      fprintf(stdout1,"  </LiteralData>\n");
+
+	    }
+	    else if(param!=NULL && !param->is_Output() 
+		    && 
+		    !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("parameters"),true)
+		    && 
+		    !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("grid_system"),true)
+		    && 
+		    !CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("node"),true)){
+	    
+	      printBasicMetadata(stdout1,param);
+
+	      if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("file"),true)){
+		if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){
+		  fprintf(stdout1,"  <ComplexData>\n");	       
+		  fprintf(stdout1,"   <Default>\n");
+		  fprintf(stdout1,"    mimeType = text/html\n");
+		  fprintf(stdout1,"    encoding = utf-8\n");
+		  fprintf(stdout1,"   </Default>\n");
+		  fprintf(stdout1,"  <ComplexData>\n");
+		}
+		else{
+		  fprintf(stdout1,"  <ComplexData>\n");	       
+		  fprintf(stdout1,"   <Default>\n");
+		  if(CSG_String(param->Get_Description()).Contains(CSG_String("HTML"))){
+		    fprintf(stdout1,"    mimeType = text/html\n");
+		  }else
+		    if(CSG_String(param->Get_Description()).Contains(CSG_String("SVG"))){
+		      fprintf(stdout1,"    mimeType = image/svg+xml\n");
+		    }else
+		      fprintf(stdout1,"    mimeType = text/plain\n");
+		  if(CSG_String(param->Get_Description()).Contains(CSG_String("ASCII"))){
+		    fprintf(stdout1,"    encoding = ascii\n");
+		  }else
+		    fprintf(stdout1,"    encoding = utf-8\n");
+		  fprintf(stdout1,"   </Default>\n");
+		  fprintf(stdout1,"  </ComplexData>\n");
+		}
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes")) ||
+		 CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin")) ){
+		printShapes(stdout1);
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).Contains("points")){
+		printPoints(stdout1);
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).Contains("grid") ||
+		 CSG_String(param->Get_Type_Identifier()).Contains("data_")){
+		printGrids(stdout1);
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){
+		printTables(stdout1);
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("text"))){
+		fprintf(stdout1,"  <LiteralData>\n");
+		fprintf(stdout1,"   dataType = string\n");
+		fprintf(stdout1,"   <Default>\n");
+		if( !param->Get_Data()->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",param->Get_Data()->Get_Default().b_str());
+		}
+		fprintf(stdout1,"   </Default>\n");
+		fprintf(stdout1,"  </LiteralData>\n");
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true)
+		 || 
+		 CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true)
+		 || 
+		 CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("integer"),true)){
+		fprintf(stdout1,"  <LiteralData>\n");
+		if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("double"),true) || 
+		 CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("degree"),true))
+		  fprintf(stdout1,"   dataType = float\n");
+		else
+		  fprintf(stdout1,"   dataType = integer\n");
+
+		fprintf(stdout1,"   <Default>\n");
+		if( !param->Get_Data()->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",param->Get_Data()->Get_Default().b_str());
+		}
+		if(param->asValue()->has_Minimum() && param->asValue()->has_Maximum()){
+		  fprintf(stdout1,"    rangeMin = %f\n",param->asValue()->Get_Minimum());
+		  fprintf(stdout1,"    rangeMax = %f\n",param->asValue()->Get_Maximum());
+		  fprintf(stdout1,"    rangeClosure = c\n");
+		}
+		fprintf(stdout1,"   </Default>\n");
+		fprintf(stdout1,"  </LiteralData>\n");
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("boolean"),true)){
+		fprintf(stdout1,"  <LiteralData>\n");
+		fprintf(stdout1,"   dataType = bool\n");
+		fprintf(stdout1,"   <Default>\n");
+		if( !param->Get_Data()->Get_Default().is_Empty() ){
+		  fprintf(stdout1,"    value = %s\n",(param->Get_Data()->Get_Default().Contains("0")?"false":"true"));
+		}
+		fprintf(stdout1,"   </Default>\n");
+		fprintf(stdout1,"  </LiteralData>\n");	
+	      }
+	      if(CSG_String(param->Get_Type_Identifier()).is_Same_As(CSG_String("choice"),true)){
+		CSG_Parameter_Choice* choice=param->asChoice();
+		if(choice!=NULL){
+		  fprintf(stdout1,"  <LiteralData>\n");
+		  fprintf(stdout1,"   dataType = string\n");
+		  fprintf(stdout1,"   AllowedValues = ");
+		  int clen=choice->Get_Count();
+		  if(clen>0){
+		    for(int l=0;l<clen;l++){
+		      //fprintf(stdout1,"%d",l);
+		      fprintf(stdout1,"%s",cleanAbstract(CSG_String(choice->Get_Item(l))));
+		      if(l+1<clen)
+			fprintf(stdout1,",");
+		    }
+		    fprintf(stdout1,"\n");
+		  }
+		  fprintf(stdout1,"   <Default>\n");
+		  if( !param->Get_Data()->Get_Default().is_Empty() ){
+		    fprintf(stdout1,"    value = %s\n",cleanAbstract(CSG_String(choice->Get_Item(atoi(param->Get_Data()->Get_Default())))));
+		  }
+		  fprintf(stdout1,"   </Default>\n");
+		  fprintf(stdout1,"  </LiteralData>\n");
+		}
+	      }
+	    }
+	  }
+	  fprintf(stdout1," </DataInputs>\n");
+	  fprintf(stdout1," <DataOutputs>\n");
+
+	  bool hasOutput=false;
+
+	  for(int k=0;k<pc;k++){
+	    CSG_Parameter * param=params->Get_Parameter(k);
+	    if(param!=NULL && param->is_Output()){
+	      hasOutput=true;
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){
+		char* tinOut[5]={
+		  (char*)"POINTS",
+		  (char*)"CENTER",
+		  (char*)"EDGES",
+		  (char*)"TRIANGLES",
+		  (char*)"POLYGONS"
+		};
+		for(int l=0;l<5;l++){
+		  char *ttitle=(char*)malloc((strlen(tinOut[l])+8)*sizeof(char));
+		  sprintf(ttitle,"%s Shapes",tinOut[l]);
+		  printBasicMetadata(stdout1,param,true,false,true,true,tinOut[l],ttitle);
+		  printShapes(stdout1);
+		}
+	      }
+	      else {
+		printBasicMetadata(stdout1,param,true);
+
+		if(CSG_String(param->Get_Type_Identifier()).Contains("points")){
+		  printPoints(stdout1);
+		}
+		if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes"))){
+		  printShapes(stdout1);
+		}
+		if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid")) ||
+		   CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("data_object"))){
+		  printGrids(stdout1);
+		}
+		if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){
+		  printTables(stdout1);
+		}
+
+	      }
+	    }
+	  }
+	  fprintf(stdout1,"</DataOutputs>\n");
+	  fclose(stdout1);
+	  if(!hasOutput)
+	    unlink((library->Get_Library_Name()+"/"+module->Get_ID()+".zcfg").b_str());
+	}
+      }
+    }
+  }
+  wxUninitialize();
+
+  return 0;
+}
Index: /trunk/zoo-project/HISTORY.txt
===================================================================
--- /trunk/zoo-project/HISTORY.txt	(revision 633)
+++ /trunk/zoo-project/HISTORY.txt	(revision 634)
@@ -14,4 +14,7 @@
   * Run validateRequest (download, default settings and decoding)
   after fork if any
+  * Add SAGA-GIS support for modules as a service
+  * Add saga2zcfg utility to generate zcfg for SAGA-GIS modules
+  * Add SAGA-GIS Observer to have ongoing status updates
 
 Version 1.4.0
Index: /trunk/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- /trunk/zoo-project/zoo-kernel/Makefile.in	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/Makefile.in	(revision 634)
@@ -48,6 +48,9 @@
 	g++ ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c service_internal_python.c
 
-service_internal_otb.o: service_internal_otb.c service.h
+service_internal_otb.o: service_internal_otb.c service_internal_otb.h service.h
 	g++ ${XML2CFLAGS} ${OTBCFLAGS} ${CFLAGS} -c service_internal_otb.c
+
+service_internal_saga.o: service_internal_saga.c service_internal_saga.h service.h
+	g++ ${XML2CFLAGS} ${SAGA_CFLAGS} ${CFLAGS} -c service_internal_saga.c
 
 otbZooWatcher.o: otbZooWatcher.cxx otbZooWatcher.h  service.h
@@ -73,9 +76,9 @@
 
 zoo_service_loader.o: zoo_service_loader.c service.h
-	g++ -g -O2 ${XML2CFLAGS} ${CFLAGS} ${OTBCFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PERLCFLAGS} ${PHPCFLAGS} ${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} ${SAGA_ENABLED} ${OTB_ENABLED} ${PYTHON_ENABLED} ${JS_ENABLED} ${PHP_ENABLED} ${PERL_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
 
-zoo_loader.cgi: version.h zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o request_parser.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE}
+zoo_loader.cgi: version.h zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o request_parser.o ${MS_FILE} ${PYTHON_FILE} ${PHP_FILE} ${JAVA_FILE} ${JS_FILE} ${PERL_FILE} ${RUBY_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE}
 	g++ -g -O2 ${JSCFLAGS} ${PHPCFLAGS}  ${PERLCFLAGS} ${RUBYCFLAGS}  ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
-	g++  ${JSCFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}
+	g++  ${JSCFLAGS} ${SAGA_CFLAGS} ${OTBCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${PERLCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o ${MS_FILE} ${PYTHON_FILE}  ${PERL_FILE} ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ${YAML_FILE} ${OTB_FILE} ${SAGA_FILE} request_parser.o ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi ${LDFLAGS}
 
 zcfg2yaml: zcfg2yaml.c  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${MS_FILE} ${JS_FILE} ${RUBY_FILE}  ${YAML_FILE}
Index: /trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in
===================================================================
--- /trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/ZOOMakefile.opts.in	(revision 634)
@@ -74,5 +74,10 @@
 OTB_FILE=@OTB_FILE@
 
+SAGA_CFLAGS=@SAGA_CPPFLAGS@
+SAGA_LDFLAGS=@SAGA_LDFLAGS@
+SAGA_ENABLED=@SAGA_ENABLED@
+SAGA_FILE=@SAGA_FILE@
+
 CFLAGS=@DEB_DEF@ -fpic ${YAML_CFLAGS} ${MACOS_CFLAGS} ${MS_CFLAGS} -I../../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
-LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS}
+LDFLAGS=-lcurl -L../../thirds/cgic206 -lcgic ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS} ${PERLLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi -lcrypto ${MS_LDFLAGS} ${MACOS_LD_FLAGS} ${MACOS_LD_NET_FLAGS} ${YAML_LDFLAGS} ${OTBLDFLAGS} ${SAGA_LDFLAGS}
 
Index: /trunk/zoo-project/zoo-kernel/configure.ac
===================================================================
--- /trunk/zoo-project/zoo-kernel/configure.ac	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/configure.ac	(revision 634)
@@ -46,404 +46,8 @@
 AC_SUBST([DEB_DEF])
 
-
-
-
 AC_ARG_WITH([cgi-dir],
     [AS_HELP_STRING([--with-cgi-dir=PATH], [specify an alternative cgi directory path ( default: /usr/lib/cgi-bin) ])],
     [CGI_DIR="$withval"], [CGI_DIR="/usr/lib/cgi-bin"])
 AC_SUBST([CGI_DIR])
-
-#============================================================================
-# Detect if gdal is installed
-#============================================================================
-
-AC_ARG_WITH([gdal-config], 
-	[AS_HELP_STRING([--with-gdal-config=FILE], [specify an alternative gdal-config file])], 
-	[GDAL_CONFIG="$withval"], [GDAL_CONFIG=""])
-if test -z $GDAL_CONFIG;
-then
-	AC_PATH_PROG([GDAL_CONFIG], [gdal-config])
-	if test -z $GDAL_CONFIG; 
-	then
-		AC_MSG_ERROR([could not find gdal-config from libgdal within the current path. You may need to try re-running configure with a --with-gdal-config parameter.])
-	fi
-	
-else
-	if test -f $GDAL_CONFIG; then
-		AC_MSG_RESULT([Using user-specified gdal-config file: $GDAL_CONFIG])
-	else
-		AC_MSG_ERROR([the user-specified gdal-config file $GDAL_CONFIG does not exist])
-	fi
-fi
-
-GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
-GDAL_LIBS="`$GDAL_CONFIG --libs`"
-
-AC_SUBST([GDAL_CFLAGS])
-AC_SUBST([GDAL_LIBS])
-
-# ===========================================================================
-# Detect if otb is available
-# ===========================================================================
-
-AC_ARG_WITH([itk],
-        [AS_HELP_STRING([--with-itk=PATH], [specify an alternative location for the itk library])],
-        [ITKPATH="$withval"], [ITKPATH=""])
-
-AC_ARG_WITH([itk-version],
-        [AS_HELP_STRING([--with-itk-version=VERSION], [specify an alternative version for the itk library])],
-        [ITKVERS="$withval"], [ITKVERS=""])
-
-AC_ARG_WITH([otb],
-        [AS_HELP_STRING([--with-otb=PATH], [specify an alternative location for the otb library])],
-        [OTBPATH="$withval"], [OTBPATH=""])
-
-if test -z "$OTBPATH"
-then
-	OTB_LDFLAGS=""
-	OTB_CPPFLAGS=""
-	OTB_FILE=""
-	OTB_ENABLED=""
-else
-    if test -z "$ITKVERS" 
-    then
-        ITKVERS="4.5"
-    fi
-	OTB_ENABLED="-DUSE_OTB"
-	OTB_LDFLAGS="-L$OTBPATH/lib/otb -lOTBIO -lOTBCommon -lOTBApplicationEngine -L$ITKPATH/lib -lITKBiasCorrection-$ITKVERS -lITKCommon-$ITKVERS -lITKIOImageBase-$ITKVERS -lITKKLMRegionGrowing-$ITKVERS -lITKLabelMap-$ITKVERS -lITKMesh-$ITKVERS -lITKMetaIO-$ITKVERS -lITKOptimizers-$ITKVERS -lITKPath-$ITKVERS -lITKPolynomials-$ITKVERS -lITKQuadEdgeMesh-$ITKVERS -lITKSpatialObjects-$ITKVERS -lITKStatistics-$ITKVERS -lITKVNLInstantiation-$ITKVERS -lITKWatersheds-$ITKVERS -litkNetlibSlatec-$ITKVERS -litksys-$ITKVERS -litkdouble-conversion-$ITKVERS -litkv3p_lsqr-$ITKVERS -litkv3p_netlib-$ITKVERS -litkvcl-$ITKVERS -litkvnl-$ITKVERS -litkvnl_algo-$ITKVERS -litkzlib-$ITKVERS"
-	OTB_CPPFLAGS="-I$OTBPATH/include/otb/ApplicationEngine -I$OTBPATH/include/otb/Common -I$ITKPATH/include/ITK-$ITKVERS -I$OTBPATH/include/otb/Utilities/ITK -I$OTBPATH/include/otb/ -I$OTBPATH/include/otb/IO -I$OTBPATH/include/otb/UtilitiesAdapters/OssimAdapters -I$OTBPATH/include/otb/UtilitiesAdapters/CurlAdapters -I$OTBPATH/include/otb/Utilities/BGL -I$OTBPATH/include/otb/UtilitiesAdapters/ITKPendingPatches -I$OTBPATH/include/otb/Utilities/otbconfigfile $GDAL_CFLAGS"
-	OTB_FILE="otbZooWatcher.o service_internal_otb.o"
-	
-	AC_LANG_PUSH([C++])
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$OTB_CPPFLAGS"
-	LDFLAGS_SAVE="$LDFLAGS"
-	LDFLAGS="$OTB_LDFLAGS"
-	AC_CHECK_HEADERS([otbWrapperApplication.h otbWrapperInputImageListParameter.h otbWrapperApplicationRegistry.h],
-			[], [AC_MSG_ERROR([could not find header file $i related to OTB])])
-	AC_LANG_POP([C++])
-fi
-AC_SUBST([OTB_CPPFLAGS])
-AC_SUBST([OTB_LDFLAGS])
-AC_SUBST([OTB_FILE])
-AC_SUBST([OTB_ENABLED])
-
-# ===========================================================================
-# Detect if libyaml is available
-# ===========================================================================
-
-AC_ARG_WITH([yaml],
-        [AS_HELP_STRING([--with-yaml=PATH], [specify an alternative location for the yaml library])],
-        [YAMLPATH="$withval"], [YAMLPATH=""])
-
-if test -z "$YAMLPATH"
-then
-	YAML_LDFLAGS=""
-	YAML_CPPFLAGS=""
-	YAML_FILE=""
-	YAML_FILE1=""
-else
-
-	# Extract the linker and include flags
-	YAML_LDFLAGS="-L$YAMLPATH/lib -lyaml"
-	YAML_CPPFLAGS="-I$YAMLPATH/include -DYAML"
-	YAML_FILE="service_yaml.o"
-	YAML_FILE1="zcfg2yaml"
-	
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$YAML_CPPFLAGS"
-	LDFLAGS_SAVE="$LDFLAGS"
-	LDFLAGS="YAML_LDFLAGS"
-	AC_CHECK_LIB([yaml], [yaml_parser_initialize,yaml_parser_set_input_file,yaml_parser_scan])
-	AC_CHECK_HEADERS([yaml.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to YAML])])
-
-fi
-AC_SUBST([YAML_CPPFLAGS])
-AC_SUBST([YAML_LDFLAGS])
-AC_SUBST([YAML_FILE])
-AC_SUBST([YAML_FILE1])
-
-# ===========================================================================
-# Detect if fastcgi is available
-# ===========================================================================
-
-AC_ARG_WITH([fastcgi],
-        [AS_HELP_STRING([--with-fastcgi=PATH], [specify an alternative location for the fastcgi library])],
-        [FCGIPATH="$withval"], [FCGIPATH="/usr"])
-
-# Extract the linker and include flags
-FCGI_LDFLAGS="-L$FCGIPATH/lib"
-FCGI_CPPFLAGS="-I$FCGIPATH/include"
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$FCGI_CPPFLAGS"
-LDFLAGS_SAVE="LDFLAGS"
-LDFLAGS="$FCGI_LDFLAGS"
-AC_CHECK_LIB([fcgi], [main])
-AC_CHECK_HEADERS([fcgi_stdio.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to fastcgi])])
-
-AC_SUBST([FCGI_CPPFLAGS])
-AC_SUBST([FCGI_LDFLAGS])
-
-# ===========================================================================
-# Detect if proj is installed
-# ===========================================================================
-
-AC_ARG_WITH([proj],
-        [AS_HELP_STRING([--with-proj=PATH], [specify an alternative location for PROJ4 setup])],
-        [PROJPATH="$withval"], [PROJPATH=""])
-
-# Extract the linker and include flags
-PROJ_LDFLAGS="-L$PROJPATH/lib"
-PROJ_CPPFLAGS="-I$PROJPATH/include"
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$PROJ_CPPFLAGS"
-AC_CHECK_HEADERS([proj_api.h],
-                 [], [AC_MSG_ERROR([could not find headers include related to PROJ4])])
-
-AC_SUBST([PROJ_CPPFLAGS])
-AC_SUBST([PROJ_LDFLAGS])
-
-# ===========================================================================
-# Detect if libxml2 is installed
-# ===========================================================================
-
-AC_ARG_WITH([xml2config], 
-	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])], 
-	[XML2CONFIG="$withval"], [XML2CONFIG=""])
-
-if test "x$XML2CONFIG" = "x"; then
-	# XML2CONFIG was not specified, so search within the current path
-	AC_PATH_PROG([XML2CONFIG], [xml2-config])
-
-	# If we couldn't find xml2-config, display a warning
-	if test "x$XML2CONFIG" = "x"; then
-		AC_MSG_ERROR([could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.])
-	fi
-else
-	# XML2CONFIG was specified; display a message to the user
-	if test "x$XML2CONFIG" = "xyes"; then
-		AC_MSG_ERROR([you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])
-	else
-		if test -f $XML2CONFIG; then
-			AC_MSG_RESULT([Using user-specified xml2-config file: $XML2CONFIG])
-		else
-			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
-		fi	
-	fi
-fi
-
-# Extract the linker and include flags 
-XML2_LDFLAGS=`$XML2CONFIG --libs`
-XML2_CPPFLAGS=`$XML2CONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$XML2_CPPFLAGS"
-AC_CHECK_HEADERS([libxml/tree.h libxml/parser.h libxml/xpath.h libxml/xpathInternals.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libxml2])])
-
-# Ensure we can link against libxml2
-LIBS_SAVE="$LIBS"
-LIBS="$XML2_LDFLAGS"
-AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], [])
-
-AC_SUBST([XML2_CPPFLAGS])
-AC_SUBST([XML2_LDFLAGS])
-
-
-
-# ===========================================================================
-# Detect if libxslt is installed
-# ===========================================================================
-
-AC_ARG_WITH([xsltconfig], 
-	[AS_HELP_STRING([--with-xsltconfig=FILE], [specify an alternative xslt-config file])], 
-	[XSLTCONFIG="$withval"], [XSLTCONFIG=""])
-
-if test "x$XSLTCONFIG" = "x"; then
-	# XSLTCONFIG was not specified, so search within the current path
-	AC_PATH_PROG([XSLTCONFIG], [xslt-config])
-
-	# If we couldn't find xslt-config, display a warning
-	if test "x$XSLTCONFIG" = "x"; then
-		AC_MSG_ERROR([could not find xslt-config from libxslt within the current path. You may need to try re-running configure with a --with-xtltconfig parameter.])
-	fi
-else
-	# XSLTCONFIG was specified; display a message to the user
-	if test "x$XSLTCONFIG" = "xyes"; then
-		AC_MSG_ERROR([you must specify a parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config])
-	else
-		if test -f $XSLTCONFIG; then
-			AC_MSG_RESULT([Using user-specified xslt-config file: $XSLTCONFIG])
-		else
-			AC_MSG_ERROR([the user-specified xslt-config file $XSLTCONFIG does not exist])
-		fi	
-	fi
-fi
-
-# Extract the linker and include flags 
-XSLT_LDFLAGS=`$XSLTCONFIG --libs`
-XSLT_CPPFLAGS=`$XSLTCONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$XSLT_CPPFLAGS"
-AC_CHECK_HEADERS([libxslt/xslt.h libxslt/xsltInternals.h libxslt/transform.h libxslt/xsltutils.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libxlst])])
-
-AC_SUBST([XSLT_CPPFLAGS])
-AC_SUBST([XSLT_LDFLAGS])
-
-
-
-# ===========================================================================
-# Detect if libgeos is installed
-# ===========================================================================
-
-AC_ARG_WITH([geosconfig], 
-	[AS_HELP_STRING([--with-geosconfig=FILE], [specify an alternative geos-config file])], 
-	[GEOSCONFIG="$withval"], [GEOSCONFIG=""])
-
-if test "x$GEOSCONFIG" = "x"; then
-	# GEOSCONFIG was not specified, so search within the current path
-	AC_PATH_PROG([GEOSCONFIG], [geos-config])
-
-	# If we couldn't find geos-config, display a warning
-	if test "x$GEOSCONFIG" = "x"; then
-		AC_MSG_WARN([could not find geos-config from libgeos within the current path. You may need to try re-running configure with a --with-geosconfig parameter.])
-	fi
-else
-	# GEOSCONFIG was specified; display a message to the user
-	if test "x$GEOSCONFIG" = "xyes"; then
-		AC_MSG_WARN([you must specify a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])
-	else
-		if test -f $GEOSCONFIG; then
-			AC_MSG_RESULT([Using user-specified geos-config file: $GEOSCONFIG])
-		else
-			AC_MSG_ERROR([the user-specified geos-config file $GEOSCONFIG does not exist])
-		fi	
-	fi
-fi
-
-GEOS_LDFLAGS=`$GEOSCONFIG --libs`
-GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$GEOS_CPPFLAGS"
-AC_CHECK_HEADERS([geos_c.h],
-		 [], [AC_MSG_WARN([could not find headers include related to libgeos])])
-
-AC_SUBST([GEOS_CPPFLAGS])
-AC_SUBST([GEOS_LDFLAGS])
-
-
-# ===========================================================================
-# Detect if cgal is installed
-# ===========================================================================
-
-AC_ARG_WITH([cgal],
-        [AS_HELP_STRING([--with-cgal=PATH], [specify an alternative location for CGAL setup])],
-        [CGALPATH="$withval"], [CGALPATH="/usr"])
-
-
-# Check headers file
-CPPFLAGS_SAVE="$CPPFLAGS"
-CPPFLAGS="$CGAL_CPPFLAGS"
-AC_CHECK_HEADERS([CGAL/Delaunay_triangulation_2.h],
-         [], [AC_MSG_WARN([could not find headers include related to libgeos])])
-
-# Extract the linker and include flags
-CGAL_LDFLAGS="-L$CGALPATH/lib"
-CGAL_CPPFLAGS="-I$CGALPATH/include"
-
-
-AC_SUBST([CGAL_CPPFLAGS])
-AC_SUBST([CGAL_LDFLAGS])
-#============================================================================
-# Detect if mapserver is installed
-#============================================================================
-
-AC_ARG_WITH([mapserver], 
-       [AS_HELP_STRING([--with-mapserver=PATH], [specify the path for MapServer compiled source tree])], 
-       [MS_SRC_PATH="$withval"], [MS_SRC_PATH=""])
-
-if test -z $MS_SRC_PATH;
-then
-	MS_CPPFLAGS=""
-	MS_LDFLAGS=""
-else
-       if test "x$MS_SRC_PATH" = "xmacos";
-       then
-               MS_LDFLAGS="/Library/Frameworks/MapServer.framework//Versions/6.0/MapServer -lintl"
-               MS_CPPFLAGS="-DUSE_MS `/Library/Frameworks/MapServer.framework/Programs/mapserver-config --includes` -I/Library/Frameworks/MapServer.framework/Versions/Current/Headers/ -I../mapserver "
-               AC_MSG_WARN([Please make sure that ../mapserver exists and contains MapServer source tree])
-               AC_MSG_RESULT([Using MacOS X Framework for MapServer])
-       else
-               if test -d $MS_SRC_PATH; then
-                       MS_LDFLAGS="-L$MS_SRC_PATH -lmapserver `$MS_SRC_PATH/mapserver-config --libs`"
-                       MS_CPPFLAGS="-DUSE_MS `$MS_SRC_PATH/mapserver-config --includes` `$MS_SRC_PATH/mapserver-config --cflags` -I$MS_SRC_PATH "
-               
-                       AC_MSG_RESULT([Using user-specified MapServer src path: $MS_SRC_PATH])
-               else
-                       AC_MSG_ERROR([the user-specified mapserver-config file $MS_SRC_PATH does not exist])
-               fi
-       fi
-       MS_FILE="service_internal_ms.o"
-fi
-
-MS_CFLAGS="$MS_CPPFLAGS"
-MS_LIBS="$MS_LDFLAGS"
-
-AC_SUBST([MS_CFLAGS])
-AC_SUBST([MS_LIBS])
-AC_SUBST([MS_FILE])
-
-# ===========================================================================
-# Detect if ruby is installed
-# ===========================================================================
-AC_ARG_WITH([ruby], 
-	[AS_HELP_STRING([--with-ruby=PATH], [To enable ruby support or specify an alternative directory for ruby installation,  disabled by default])], 
-	[RUBY_PATH="$withval"; RUBY_ENABLED="-DUSE_RUBY"], [RUBY_ENABLED=""])
-
-AC_ARG_WITH([rvers], 
-	[AS_HELP_STRING([--with-rvers=NUM], [To use a specific ruby version])], 
-	[RUBY_VERS="$withval"], [RUBY_VERS=""])
-
-
-if test -z "$RUBY_ENABLED"
-then
-	RUBY_FILE=""
-else
-	RUBY_FILE="service_internal_ruby.o"
-
-	# Extract the linker and include flags 
-	RUBY_LDFLAGS="-lruby"
-	RUBY_CPPFLAGS="-I$RUBY_PATH -I$RUBY_PATH/x86_64-darwin13.0/ -DZRUBY_VERSION=$RUBY_VERS"
-
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$RUBY_CPPFLAGS"
-	AC_CHECK_HEADERS([ruby.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libruby])])
-
-	# Ensure we can link against libphp
-	LIBS_SAVE="$LIBS"
-	LIBS="$RUBY_LDFLAGS"
-	# AC_CHECK_LIB([lruby], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
-	AC_SUBST([RUBY_CPPFLAGS])
-	AC_SUBST([RUBY_LDFLAGS])
-fi
-
-AC_SUBST([RUBY_ENABLED])
-AC_SUBST([RUBY_FILE])
 
 # ===========================================================================
@@ -500,147 +104,4 @@
 AC_SUBST([PYTHON_ENABLED])
 AC_SUBST([PYTHON_FILE])
-
-# ===========================================================================
-# Detect if php is installed
-# ===========================================================================
-
-AC_ARG_WITH([php], 
-	[AS_HELP_STRING([--with-php=PATH], [To enable php support or specify an alternative directory for php installation,  disabled by default])], 
-	[PHP_PATH="$withval"; PHP_ENABLED="-DUSE_PHP"], [PHP_ENABLED=""])
-
-
-if test -z "$PHP_ENABLED"
-then
-	PHP_FILE=""
-else
-	PHPCONFIG="$PHP_PATH/bin/php-config"
-	PHP_FILE="service_internal_php.o"
-	if test  "$PHP_PATH" = "yes"
-	then
-		# PHP was not specified, so search within the current path
-		AC_PATH_PROG([PHPCONFIG], [php-config])
-	else
-		PHPCONFIG="$PHP_PATH/bin/php-config"
-	fi
-
-	# Extract the linker and include flags 
-	PHP_LDFLAGS="-L/`$PHPCONFIG --prefix`/lib -lphp5"
-	PHP_CPPFLAGS=`$PHPCONFIG --includes`
-
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$PHP_CPPFLAGS"
-	AC_CHECK_HEADERS([sapi/embed/php_embed.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libphp])])
-
-	# Ensure we can link against libphp
-	LIBS_SAVE="$LIBS"
-	LIBS="$PHP_LDFLAGS"
-	# Shouldn't we get php here rather than php5 :) ??
-	AC_CHECK_LIB([php5], [call_user_function], [], [AC_MSG_ERROR([could not find libphp])], [])
-	AC_SUBST([PHP_CPPFLAGS])
-	AC_SUBST([PHP_LDFLAGS])
-fi
-
-AC_SUBST([PHP_ENABLED])
-AC_SUBST([PHP_FILE])
-
-# ===========================================================================
-# Detect if perl is installed
-# ===========================================================================
-
-AC_ARG_WITH([perl], 
-	[AS_HELP_STRING([--with-perl=PATH], [To enable perl support or specify an alternative directory for perl installation,  disabled by default])], 
-	[PERL_PATH="$withval"; PERL_ENABLED="-DUSE_PERL"], [PERL_ENABLED=""])
-
-
-if test -z "$PERL_ENABLED"
-then
-	PERL_FILE=""
-else
-	PERL_FILE="service_internal_perl.o"
-	if test  "$PERL_PATH" = "yes"
-	then
-		# Perl was not specified, so search within the current path
-		AC_PATH_PROG([PERLCONFIG], [perl])
-	else
-		PERLCONFIG="$PERL_PATH/bin/perl"
-	fi
-
-	# Extract the linker and include flags 
-	PERL_LDFLAGS=`$PERLCONFIG -MExtUtils::Embed -e ldopts`
-	PERL_CPPFLAGS=`$PERLCONFIG -MExtUtils::Embed -e ccopts`
-
-	# Check headers file
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$PERL_CPPFLAGS"
-	AC_CHECK_HEADERS([EXTERN.h],
-		 [], [AC_MSG_ERROR([could not find headers include related to libperl])])
-
-	AC_SUBST([PERL_CPPFLAGS])
-	AC_SUBST([PERL_LDFLAGS])
-fi
-
-AC_SUBST([PERL_ENABLED])
-AC_SUBST([PERL_FILE])
-
-# ===========================================================================
-# Detect if java is installed
-# ===========================================================================
-
-AC_ARG_WITH([java], 
-	[AS_HELP_STRING([--with-java=PATH], [To enable java support, specify a JDK_HOME,  disabled by default])], 
-	[JDKHOME="$withval"; JAVA_ENABLED="-DUSE_JAVA"], [JAVA_ENABLED=""])
-
-if test -z "$JAVA_ENABLED"
-then
-	JAVA_FILE=""
-else
-	JAVA_FILE="service_internal_java.o"
-	if test "x$JDKHOME" = "x"; 
-	then
-		AC_MSG_ERROR([could not find java installation path within the current path. You may need to try re-running configure with a --with-java parameter.])
-	fi	# JAVA was specified; display a message to the user
-	if test "x$JDKHOME" = "xyes"; 
-	then
-		AC_MSG_ERROR([you must specify a parameter to --with-java, e.g. --with-java=/path/to/java])
-	fi
-
-	# Extract the linker and include flags
-	if test "x$JDKHOME" = "xmacos";
-	then
-		JAVA_LDFLAGS="-framework JavaVM"
-		JAVA_CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/"
-	else
-		if test -d "$JDKHOME/jre/lib/i386";
-		then
-			JAVA_LDFLAGS="-L$JDKHOME/jre/lib/i386/server/ -ljvm -lpthread"
-			JAVA_CPPFLAGS="-I$JDKHOME/include -I$JDKHOME/include/linux"
-		else
-			JAVA_LDFLAGS="-L$JDKHOME/jre/lib/amd64/server/ -ljvm -lpthread"
-			JAVA_CPPFLAGS="-I$JDKHOME/include -I$JDKHOME/include/linux"
-		fi
-	fi
-
-	# Check headers file (second time we check that in fact)
-	CPPFLAGS_SAVE="$CPPFLAGS"
-	CPPFLAGS="$JAVA_CPPFLAGS"
-	AC_CHECK_HEADERS([jni.h],
-			 [], [AC_MSG_ERROR([could not find jni.h file])])
-
-	# Ensure we can link against libjava
-	LIBS_SAVE="$LIBS"
-	LIBS="$JAVA_LDFLAGS"
-	if test "x$JDKHOME" != "xmacos";
-	then
-		AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [], [AC_MSG_ERROR([could not find libjvm])], [])
-	fi
-
-	AC_SUBST([JAVA_CPPFLAGS])
-	AC_SUBST([JAVA_LDFLAGS])
-fi 
-
-AC_SUBST([JAVA_ENABLED])
-AC_SUBST([JAVA_FILE])
 
 # ===========================================================================
@@ -707,4 +168,587 @@
 AC_SUBST([JS_FILE])
 
+# ===========================================================================
+# Detect if php is installed
+# ===========================================================================
+
+AC_ARG_WITH([php], 
+	[AS_HELP_STRING([--with-php=PATH], [To enable php support or specify an alternative directory for php installation,  disabled by default])], 
+	[PHP_PATH="$withval"; PHP_ENABLED="-DUSE_PHP"], [PHP_ENABLED=""])
+
+
+if test -z "$PHP_ENABLED"
+then
+	PHP_FILE=""
+else
+	PHPCONFIG="$PHP_PATH/bin/php-config"
+	PHP_FILE="service_internal_php.o"
+	if test  "$PHP_PATH" = "yes"
+	then
+		# PHP was not specified, so search within the current path
+		AC_PATH_PROG([PHPCONFIG], [php-config])
+	else
+		PHPCONFIG="$PHP_PATH/bin/php-config"
+	fi
+
+	# Extract the linker and include flags 
+	PHP_LDFLAGS="-L/`$PHPCONFIG --prefix`/lib -lphp5"
+	PHP_CPPFLAGS=`$PHPCONFIG --includes`
+
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$PHP_CPPFLAGS"
+	AC_CHECK_HEADERS([sapi/embed/php_embed.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libphp])])
+
+	# Ensure we can link against libphp
+	LIBS_SAVE="$LIBS"
+	LIBS="$PHP_LDFLAGS"
+	# Shouldn't we get php here rather than php5 :) ??
+	AC_CHECK_LIB([php5], [call_user_function], [], [AC_MSG_ERROR([could not find libphp])], [])
+	AC_SUBST([PHP_CPPFLAGS])
+	AC_SUBST([PHP_LDFLAGS])
+fi
+
+AC_SUBST([PHP_ENABLED])
+AC_SUBST([PHP_FILE])
+
+# ===========================================================================
+# Detect if java is installed
+# ===========================================================================
+
+AC_ARG_WITH([java], 
+	[AS_HELP_STRING([--with-java=PATH], [To enable java support, specify a JDK_HOME,  disabled by default])], 
+	[JDKHOME="$withval"; JAVA_ENABLED="-DUSE_JAVA"], [JAVA_ENABLED=""])
+
+if test -z "$JAVA_ENABLED"
+then
+	JAVA_FILE=""
+else
+	JAVA_FILE="service_internal_java.o"
+	if test "x$JDKHOME" = "x"; 
+	then
+		AC_MSG_ERROR([could not find java installation path within the current path. You may need to try re-running configure with a --with-java parameter.])
+	fi	# JAVA was specified; display a message to the user
+	if test "x$JDKHOME" = "xyes"; 
+	then
+		AC_MSG_ERROR([you must specify a parameter to --with-java, e.g. --with-java=/path/to/java])
+	fi
+
+	# Extract the linker and include flags
+	if test "x$JDKHOME" = "xmacos";
+	then
+		JAVA_LDFLAGS="-framework JavaVM"
+		JAVA_CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/"
+	else
+		if test -d "$JDKHOME/jre/lib/i386";
+		then
+			JAVA_LDFLAGS="-L$JDKHOME/jre/lib/i386/server/ -ljvm -lpthread"
+			JAVA_CPPFLAGS="-I$JDKHOME/include -I$JDKHOME/include/linux"
+		else
+			JAVA_LDFLAGS="-L$JDKHOME/jre/lib/amd64/server/ -ljvm -lpthread"
+			JAVA_CPPFLAGS="-I$JDKHOME/include -I$JDKHOME/include/linux"
+		fi
+	fi
+
+	# Check headers file (second time we check that in fact)
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$JAVA_CPPFLAGS"
+	AC_CHECK_HEADERS([jni.h],
+			 [], [AC_MSG_ERROR([could not find jni.h file])])
+
+	# Ensure we can link against libjava
+	LIBS_SAVE="$LIBS"
+	LIBS="$JAVA_LDFLAGS"
+	if test "x$JDKHOME" != "xmacos";
+	then
+		AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [], [AC_MSG_ERROR([could not find libjvm])], [])
+	fi
+
+	AC_SUBST([JAVA_CPPFLAGS])
+	AC_SUBST([JAVA_LDFLAGS])
+fi 
+
+AC_SUBST([JAVA_ENABLED])
+AC_SUBST([JAVA_FILE])
+
+# ===========================================================================
+# Detect if ruby is installed
+# ===========================================================================
+AC_ARG_WITH([ruby], 
+	[AS_HELP_STRING([--with-ruby=PATH], [To enable ruby support or specify an alternative directory for ruby installation,  disabled by default])], 
+	[RUBY_PATH="$withval"; RUBY_ENABLED="-DUSE_RUBY"], [RUBY_ENABLED=""])
+
+AC_ARG_WITH([rvers], 
+	[AS_HELP_STRING([--with-rvers=NUM], [To use a specific ruby version])], 
+	[RUBY_VERS="$withval"], [RUBY_VERS=""])
+
+
+if test -z "$RUBY_ENABLED"
+then
+	RUBY_FILE=""
+else
+	RUBY_FILE="service_internal_ruby.o"
+
+	# Extract the linker and include flags 
+	RUBY_LDFLAGS="-lruby"
+	RUBY_CPPFLAGS="-I$RUBY_PATH -I$RUBY_PATH/x86_64-darwin13.0/ -DZRUBY_VERSION=$RUBY_VERS"
+
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$RUBY_CPPFLAGS"
+	AC_CHECK_HEADERS([ruby.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libruby])])
+
+	# Ensure we can link against libphp
+	LIBS_SAVE="$LIBS"
+	LIBS="$RUBY_LDFLAGS"
+	# AC_CHECK_LIB([lruby], [PyObject_CallObject], [], [AC_MSG_ERROR([could not find libpython])], [])
+	AC_SUBST([RUBY_CPPFLAGS])
+	AC_SUBST([RUBY_LDFLAGS])
+fi
+
+AC_SUBST([RUBY_ENABLED])
+AC_SUBST([RUBY_FILE])
+
+# ===========================================================================
+# Detect if perl is installed
+# ===========================================================================
+
+AC_ARG_WITH([perl], 
+	[AS_HELP_STRING([--with-perl=PATH], [To enable perl support or specify an alternative directory for perl installation,  disabled by default])], 
+	[PERL_PATH="$withval"; PERL_ENABLED="-DUSE_PERL"], [PERL_ENABLED=""])
+
+
+if test -z "$PERL_ENABLED"
+then
+	PERL_FILE=""
+else
+	PERL_FILE="service_internal_perl.o"
+	if test  "$PERL_PATH" = "yes"
+	then
+		# Perl was not specified, so search within the current path
+		AC_PATH_PROG([PERLCONFIG], [perl])
+	else
+		PERLCONFIG="$PERL_PATH/bin/perl"
+	fi
+
+	# Extract the linker and include flags 
+	PERL_LDFLAGS=`$PERLCONFIG -MExtUtils::Embed -e ldopts`
+	PERL_CPPFLAGS=`$PERLCONFIG -MExtUtils::Embed -e ccopts`
+
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$PERL_CPPFLAGS"
+	AC_CHECK_HEADERS([EXTERN.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libperl])])
+
+	AC_SUBST([PERL_CPPFLAGS])
+	AC_SUBST([PERL_LDFLAGS])
+fi
+
+AC_SUBST([PERL_ENABLED])
+AC_SUBST([PERL_FILE])
+
+# ===========================================================================
+# Detect if otb is available
+# ===========================================================================
+
+AC_ARG_WITH([itk],
+        [AS_HELP_STRING([--with-itk=PATH], [specify an alternative location for the itk library])],
+        [ITKPATH="$withval"], [ITKPATH=""])
+
+AC_ARG_WITH([itk-version],
+        [AS_HELP_STRING([--with-itk-version=VERSION], [specify an alternative version for the itk library])],
+        [ITKVERS="$withval"], [ITKVERS=""])
+
+AC_ARG_WITH([otb],
+        [AS_HELP_STRING([--with-otb=PATH], [specify an alternative location for the otb library])],
+        [OTBPATH="$withval"], [OTBPATH=""])
+
+if test -z "$OTBPATH"
+then
+	OTB_LDFLAGS=""
+	OTB_CPPFLAGS=""
+	OTB_FILE=""
+	OTB_ENABLED=""
+else
+    if test -z "$ITKVERS" 
+    then
+        ITKVERS="4.5"
+    fi
+	OTB_ENABLED="-DUSE_OTB"
+	OTB_LDFLAGS="-L$OTBPATH/lib/otb -lOTBIO -lOTBCommon -lOTBApplicationEngine -L$ITKPATH/lib -lITKBiasCorrection-$ITKVERS -lITKCommon-$ITKVERS -lITKIOImageBase-$ITKVERS -lITKKLMRegionGrowing-$ITKVERS -lITKLabelMap-$ITKVERS -lITKMesh-$ITKVERS -lITKMetaIO-$ITKVERS -lITKOptimizers-$ITKVERS -lITKPath-$ITKVERS -lITKPolynomials-$ITKVERS -lITKQuadEdgeMesh-$ITKVERS -lITKSpatialObjects-$ITKVERS -lITKStatistics-$ITKVERS -lITKVNLInstantiation-$ITKVERS -lITKWatersheds-$ITKVERS -litkNetlibSlatec-$ITKVERS -litksys-$ITKVERS -litkdouble-conversion-$ITKVERS -litkv3p_lsqr-$ITKVERS -litkv3p_netlib-$ITKVERS -litkvcl-$ITKVERS -litkvnl-$ITKVERS -litkvnl_algo-$ITKVERS -litkzlib-$ITKVERS"
+	OTB_CPPFLAGS="-I$OTBPATH/include/otb/ApplicationEngine -I$OTBPATH/include/otb/Common -I$ITKPATH/include/ITK-$ITKVERS -I$OTBPATH/include/otb/Utilities/ITK -I$OTBPATH/include/otb/ -I$OTBPATH/include/otb/IO -I$OTBPATH/include/otb/UtilitiesAdapters/OssimAdapters -I$OTBPATH/include/otb/UtilitiesAdapters/CurlAdapters -I$OTBPATH/include/otb/Utilities/BGL -I$OTBPATH/include/otb/UtilitiesAdapters/ITKPendingPatches -I$OTBPATH/include/otb/Utilities/otbconfigfile $GDAL_CFLAGS"
+	OTB_FILE="otbZooWatcher.o service_internal_otb.o"
+	
+	AC_LANG_PUSH([C++])
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$OTB_CPPFLAGS"
+	LDFLAGS_SAVE="$LDFLAGS"
+	LDFLAGS="$OTB_LDFLAGS"
+	AC_CHECK_HEADERS([otbWrapperApplication.h otbWrapperInputImageListParameter.h otbWrapperApplicationRegistry.h],
+			[], [AC_MSG_ERROR([could not find header file $i related to OTB])])
+	AC_LANG_POP([C++])
+fi
+AC_SUBST([OTB_CPPFLAGS])
+AC_SUBST([OTB_LDFLAGS])
+AC_SUBST([OTB_FILE])
+AC_SUBST([OTB_ENABLED])
+
+# ===========================================================================
+# Detect if saga-gis is available
+# ===========================================================================
+
+AC_ARG_WITH([wx-config],
+        [AS_HELP_STRING([--with-wx-config=PATH], [specify an alternative path for the wx-config tool])],
+        [WXCFG="$withval"], [WXCFG=""])
+
+AC_ARG_WITH([saga],
+        [AS_HELP_STRING([--with-saga=PATH], [specify an alternative location for the SAGA-GIS library])],
+        [SAGAPATH="$withval"], [SAGAPATH=""])
+
+if test -z "$SAGAPATH"
+then
+	SAGA_LDFLAGS=""
+	SAGA_CPPFLAGS=""
+	SAGA_FILE=""
+	SAGA_ENABLED=""
+else
+	if test -z "$WXCFG" ; then
+	   WXCFG="$(which wx-config)"
+	fi
+	if test "`$WXCFG --list | grep unicode`" == "" ; then
+	   AC_MSG_ERROR(SAGA requires a unicode build of wxGTK)
+	fi
+	WX_ISSUE="-D_WX_WXCRTVARARG_H_"
+	SAGA_DEFS="-D_SAGA_LINUX -D_TYPEDEF_BYTE -D_TYPEDEF_WORD -DMODULE_LIBRARY_PATH=\\\"$SAGAPATH/lib/saga\\\""
+	SAGA_CPPFLAGS=" -fPIC -I$SAGAPATH/include/saga/saga_core/saga_api/ `$WXCFG --unicode=yes --static=no --cxxflags` -D_SAGA_UNICODE $SAGA_DEFS $WX_ISSUE"
+	SAGA_LDFLAGS="-fPIC `$WXCFG --unicode=yes --static=no --libs` -lsaga_api"
+	SAGA_ENABLED="-DUSE_SAGA"
+	SAGA_FILE="service_internal_saga.o"
+	
+	AC_LANG_PUSH([C++])
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$SAGA_CPPFLAGS"
+	LIBS_SAVE="$LIBS"
+	LIBS="$SAGA_LDFLAGS"
+	AC_MSG_RESULT(CPPFLAGS are $CPPFLAGS)
+	AC_CHECK_HEADERS([module_library.h],
+			[], [AC_MSG_ERROR([could not find header file $i related to SAGA-GIS])])
+	LIBS_SAVE="$LIBS"
+	AC_LANG_POP([C++])
+	AC_CHECK_LIB([saga_api], [SG_Set_UI_Callback,SG_Get_Module_Library_Manager])
+fi
+AC_SUBST([SAGA_CPPFLAGS])
+AC_SUBST([SAGA_LDFLAGS])
+AC_SUBST([SAGA_FILE])
+AC_SUBST([SAGA_ENABLED])
+
+# ===========================================================================
+# Detect if libyaml is available
+# ===========================================================================
+
+AC_ARG_WITH([yaml],
+        [AS_HELP_STRING([--with-yaml=PATH], [specify an alternative location for the yaml library])],
+        [YAMLPATH="$withval"], [YAMLPATH=""])
+
+if test -z "$YAMLPATH"
+then
+	YAML_LDFLAGS=""
+	YAML_CPPFLAGS=""
+	YAML_FILE=""
+	YAML_FILE1=""
+else
+
+	# Extract the linker and include flags
+	YAML_LDFLAGS="-L$YAMLPATH/lib -lyaml"
+	YAML_CPPFLAGS="-I$YAMLPATH/include -DYAML"
+	YAML_FILE="service_yaml.o"
+	YAML_FILE1="zcfg2yaml"
+	
+	# Check headers file
+	CPPFLAGS_SAVE="$CPPFLAGS"
+	CPPFLAGS="$YAML_CPPFLAGS"
+	LIBS_SAVE="$LIBS"
+	LIBS="$YAML_LDFLAGS"
+	AC_CHECK_LIB([yaml], [yaml_parser_initialize,yaml_parser_set_input_file,yaml_parser_scan])
+	AC_CHECK_HEADERS([yaml.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to YAML])])
+	LIBS="$LIBS_SAVE"
+fi
+AC_SUBST([YAML_CPPFLAGS])
+AC_SUBST([YAML_LDFLAGS])
+AC_SUBST([YAML_FILE])
+AC_SUBST([YAML_FILE1])
+
+# ===========================================================================
+# Detect if fastcgi is available
+# ===========================================================================
+
+AC_ARG_WITH([fastcgi],
+        [AS_HELP_STRING([--with-fastcgi=PATH], [specify an alternative location for the fastcgi library])],
+        [FCGIPATH="$withval"], [FCGIPATH="/usr"])
+
+# Extract the linker and include flags
+FCGI_LDFLAGS="-L$FCGIPATH/lib"
+FCGI_CPPFLAGS="-I$FCGIPATH/include"
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$FCGI_CPPFLAGS"
+LIBS_SAVE="$LIBS"
+LIBS="$FCGI_LDFLAGS"
+AC_CHECK_LIB([fcgi], [main])
+AC_CHECK_HEADERS([fcgi_stdio.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to fastcgi])])
+LIBS="$LIBS_SAVE"
+AC_SUBST([FCGI_CPPFLAGS])
+AC_SUBST([FCGI_LDFLAGS])
+
+
+# ===========================================================================
+# Detect if libxml2 is installed
+# ===========================================================================
+
+AC_ARG_WITH([xml2config], 
+	[AS_HELP_STRING([--with-xml2config=FILE], [specify an alternative xml2-config file])], 
+	[XML2CONFIG="$withval"], [XML2CONFIG=""])
+
+if test "x$XML2CONFIG" = "x"; then
+	# XML2CONFIG was not specified, so search within the current path
+	AC_PATH_PROG([XML2CONFIG], [xml2-config])
+
+	# If we couldn't find xml2-config, display a warning
+	if test "x$XML2CONFIG" = "x"; then
+		AC_MSG_ERROR([could not find xml2-config from libxml2 within the current path. You may need to try re-running configure with a --with-xml2config parameter.])
+	fi
+else
+	# XML2CONFIG was specified; display a message to the user
+	if test "x$XML2CONFIG" = "xyes"; then
+		AC_MSG_ERROR([you must specify a parameter to --with-xml2config, e.g. --with-xml2config=/path/to/xml2-config])
+	else
+		if test -f $XML2CONFIG; then
+			AC_MSG_RESULT([Using user-specified xml2-config file: $XML2CONFIG])
+		else
+			AC_MSG_ERROR([the user-specified xml2-config file $XML2CONFIG does not exist])
+		fi	
+	fi
+fi
+
+# Extract the linker and include flags 
+XML2_LDFLAGS=`$XML2CONFIG --libs`
+XML2_CPPFLAGS=`$XML2CONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$XML2_CPPFLAGS"
+AC_CHECK_HEADERS([libxml/tree.h libxml/parser.h libxml/xpath.h libxml/xpathInternals.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libxml2])])
+
+# Ensure we can link against libxml2
+LIBS_SAVE="$LIBS"
+LIBS="$XML2_LDFLAGS"
+AC_CHECK_LIB([xml2], [xmlInitParser], [], [AC_MSG_ERROR([could not find libxml2])], [])
+
+AC_SUBST([XML2_CPPFLAGS])
+AC_SUBST([XML2_LDFLAGS])
+
+# ===========================================================================
+# Detect if libxslt is installed
+# ===========================================================================
+
+AC_ARG_WITH([xsltconfig], 
+	[AS_HELP_STRING([--with-xsltconfig=FILE], [specify an alternative xslt-config file])], 
+	[XSLTCONFIG="$withval"], [XSLTCONFIG=""])
+
+if test "x$XSLTCONFIG" = "x"; then
+	# XSLTCONFIG was not specified, so search within the current path
+	AC_PATH_PROG([XSLTCONFIG], [xslt-config])
+
+	# If we couldn't find xslt-config, display a warning
+	if test "x$XSLTCONFIG" = "x"; then
+		AC_MSG_ERROR([could not find xslt-config from libxslt within the current path. You may need to try re-running configure with a --with-xtltconfig parameter.])
+	fi
+else
+	# XSLTCONFIG was specified; display a message to the user
+	if test "x$XSLTCONFIG" = "xyes"; then
+		AC_MSG_ERROR([you must specify a parameter to --with-xsltconfig, e.g. --with-xsltconfig=/path/to/xslt-config])
+	else
+		if test -f $XSLTCONFIG; then
+			AC_MSG_RESULT([Using user-specified xslt-config file: $XSLTCONFIG])
+		else
+			AC_MSG_ERROR([the user-specified xslt-config file $XSLTCONFIG does not exist])
+		fi	
+	fi
+fi
+
+# Extract the linker and include flags 
+XSLT_LDFLAGS=`$XSLTCONFIG --libs`
+XSLT_CPPFLAGS=`$XSLTCONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$XSLT_CPPFLAGS"
+AC_CHECK_HEADERS([libxslt/xslt.h libxslt/xsltInternals.h libxslt/transform.h libxslt/xsltutils.h],
+		 [], [AC_MSG_ERROR([could not find headers include related to libxlst])])
+
+AC_SUBST([XSLT_CPPFLAGS])
+AC_SUBST([XSLT_LDFLAGS])
+
+#============================================================================
+# Detect if gdal is installed
+#============================================================================
+
+AC_ARG_WITH([gdal-config], 
+	[AS_HELP_STRING([--with-gdal-config=FILE], [specify an alternative gdal-config file])], 
+	[GDAL_CONFIG="$withval"], [GDAL_CONFIG=""])
+if test -z $GDAL_CONFIG;
+then
+	AC_PATH_PROG([GDAL_CONFIG], [gdal-config])
+	if test -z $GDAL_CONFIG; 
+	then
+		AC_MSG_ERROR([could not find gdal-config from libgdal within the current path. You may need to try re-running configure with a --with-gdal-config parameter.])
+	fi
+	
+else
+	if test -f $GDAL_CONFIG; then
+		AC_MSG_RESULT([Using user-specified gdal-config file: $GDAL_CONFIG])
+	else
+		AC_MSG_ERROR([the user-specified gdal-config file $GDAL_CONFIG does not exist])
+	fi
+fi
+
+GDAL_CFLAGS="`$GDAL_CONFIG --cflags`"
+GDAL_LIBS="`$GDAL_CONFIG --libs`"
+
+AC_SUBST([GDAL_CFLAGS])
+AC_SUBST([GDAL_LIBS])
+
+# ===========================================================================
+# Detect if proj is installed
+# ===========================================================================
+
+AC_ARG_WITH([proj],
+        [AS_HELP_STRING([--with-proj=PATH], [specify an alternative location for PROJ4 setup])],
+        [PROJPATH="$withval"], [PROJPATH=""])
+
+# Extract the linker and include flags
+PROJ_LDFLAGS="-L$PROJPATH/lib"
+PROJ_CPPFLAGS="-I$PROJPATH/include"
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$PROJ_CPPFLAGS"
+AC_CHECK_HEADERS([proj_api.h],
+                 [], [AC_MSG_ERROR([could not find headers include related to PROJ4])])
+
+AC_SUBST([PROJ_CPPFLAGS])
+AC_SUBST([PROJ_LDFLAGS])
+
+# ===========================================================================
+# Detect if libgeos is installed
+# ===========================================================================
+
+AC_ARG_WITH([geosconfig], 
+	[AS_HELP_STRING([--with-geosconfig=FILE], [specify an alternative geos-config file])], 
+	[GEOSCONFIG="$withval"], [GEOSCONFIG=""])
+
+if test "x$GEOSCONFIG" = "x"; then
+	# GEOSCONFIG was not specified, so search within the current path
+	AC_PATH_PROG([GEOSCONFIG], [geos-config])
+
+	# If we couldn't find geos-config, display a warning
+	if test "x$GEOSCONFIG" = "x"; then
+		AC_MSG_WARN([could not find geos-config from libgeos within the current path. You may need to try re-running configure with a --with-geosconfig parameter.])
+	fi
+else
+	# GEOSCONFIG was specified; display a message to the user
+	if test "x$GEOSCONFIG" = "xyes"; then
+		AC_MSG_WARN([you must specify a parameter to --with-geosconfig, e.g. --with-geosconfig=/path/to/geos-config])
+	else
+		if test -f $GEOSCONFIG; then
+			AC_MSG_RESULT([Using user-specified geos-config file: $GEOSCONFIG])
+		else
+			AC_MSG_ERROR([the user-specified geos-config file $GEOSCONFIG does not exist])
+		fi	
+	fi
+fi
+
+GEOS_LDFLAGS=`$GEOSCONFIG --libs`
+GEOS_CPPFLAGS=`$GEOSCONFIG --cflags`
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$GEOS_CPPFLAGS"
+AC_CHECK_HEADERS([geos_c.h],
+		 [], [AC_MSG_WARN([could not find headers include related to libgeos])])
+
+AC_SUBST([GEOS_CPPFLAGS])
+AC_SUBST([GEOS_LDFLAGS])
+
+
+# ===========================================================================
+# Detect if cgal is installed
+# ===========================================================================
+
+AC_ARG_WITH([cgal],
+        [AS_HELP_STRING([--with-cgal=PATH], [specify an alternative location for CGAL setup])],
+        [CGALPATH="$withval"], [CGALPATH="/usr"])
+
+
+# Check headers file
+CPPFLAGS_SAVE="$CPPFLAGS"
+CPPFLAGS="$CGAL_CPPFLAGS"
+AC_CHECK_HEADERS([CGAL/Delaunay_triangulation_2.h],
+         [], [AC_MSG_WARN([could not find headers include related to libCGAL])])
+
+# Extract the linker and include flags
+CGAL_LDFLAGS="-L$CGALPATH/lib"
+CGAL_CPPFLAGS="-I$CGALPATH/include"
+
+
+AC_SUBST([CGAL_CPPFLAGS])
+AC_SUBST([CGAL_LDFLAGS])
+#============================================================================
+# Detect if mapserver is installed
+#============================================================================
+
+AC_ARG_WITH([mapserver], 
+       [AS_HELP_STRING([--with-mapserver=PATH], [specify the path for MapServer compiled source tree])], 
+       [MS_SRC_PATH="$withval"], [MS_SRC_PATH=""])
+
+if test -z $MS_SRC_PATH;
+then
+	MS_CPPFLAGS=""
+	MS_LDFLAGS=""
+else
+       if test "x$MS_SRC_PATH" = "xmacos";
+       then
+               MS_LDFLAGS="/Library/Frameworks/MapServer.framework//Versions/6.0/MapServer -lintl"
+               MS_CPPFLAGS="-DUSE_MS `/Library/Frameworks/MapServer.framework/Programs/mapserver-config --includes` -I/Library/Frameworks/MapServer.framework/Versions/Current/Headers/ -I../mapserver "
+               AC_MSG_WARN([Please make sure that ../mapserver exists and contains MapServer source tree])
+               AC_MSG_RESULT([Using MacOS X Framework for MapServer])
+       else
+               if test -d $MS_SRC_PATH; then
+                       MS_LDFLAGS="-L$MS_SRC_PATH -lmapserver `$MS_SRC_PATH/mapserver-config --libs`"
+                       MS_CPPFLAGS="-DUSE_MS `$MS_SRC_PATH/mapserver-config --includes` `$MS_SRC_PATH/mapserver-config --cflags` -I$MS_SRC_PATH "
+               
+                       AC_MSG_RESULT([Using user-specified MapServer src path: $MS_SRC_PATH])
+               else
+                       AC_MSG_ERROR([the user-specified mapserver-config file $MS_SRC_PATH does not exist])
+               fi
+       fi
+       MS_FILE="service_internal_ms.o"
+fi
+
+MS_CFLAGS="$MS_CPPFLAGS"
+MS_LIBS="$MS_LDFLAGS"
+
+AC_SUBST([MS_CFLAGS])
+AC_SUBST([MS_LIBS])
+AC_SUBST([MS_FILE])
+
 AC_CONFIG_FILES([Makefile])
 AC_CONFIG_FILES([ZOOMakefile.opts])
Index: /trunk/zoo-project/zoo-kernel/service_conf.l
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_conf.l	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/service_conf.l	(revision 634)
@@ -35,5 +35,4 @@
 %}
 
-
 S		[ \t\r\n]+
 
@@ -47,5 +46,5 @@
 
 attname	[a-zA-Z0-9._\-]+
-attvalue1	[#°²θé\^\*\+,;?!~`Ãº@a-zA-Z0-9%_\-:\:.:" "\"\'/\\\(\)\t\|\$\&>\[\]]+
+attvalue1	[\x80-\xbf\xc2-\xdf\xe0-\xef\xf0-\xf4#°²θé\^\*\+\,\;?!~`Ãº@a-zA-Z0-9%_\-:\:.:" "\"\'/\\\(\)\t\|\$\&>\[\]]+
 
 attvalue		\"[^"]*\"|\'[^']*\'\(\)
Index: /trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/service_internal.c	(revision 634)
@@ -2249,19 +2249,19 @@
     if(e!=NULL){
       if(strncasecmp(e->format,"LiteralOutput",strlen(e->format))==0)
-         nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
+	nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
       else
         if(strncasecmp(e->format,"ComplexOutput",strlen(e->format))==0)
-		   nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
-	  else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
-	    nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
-	  else
-	    nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
+	  nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
+	else if(strncasecmp(e->format,"BoundingBoxOutput",strlen(e->format))==0)
+	  nc3=xmlNewNode(ns_wps, BAD_CAST "BoundingBoxData");
+	else
+	  nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
     }
     else {
       map* tmpV=getMapFromMaps(m,"format","value");
       if(tmpV!=NULL)
-	    nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
+	nc3=xmlNewNode(ns_wps, BAD_CAST tmpV->value);
       else
-	    nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
+	nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     } 
     tmp=m->content;
@@ -2269,10 +2269,10 @@
     while(tmp!=NULL){
       if(strcasecmp(tmp->name,"mimeType")==0 ||
-	     strcasecmp(tmp->name,"encoding")==0 ||
-	     strcasecmp(tmp->name,"schema")==0 ||
-	     strcasecmp(tmp->name,"datatype")==0 ||
-	     strcasecmp(tmp->name,"uom")==0) {
-
-	    xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+	 strcasecmp(tmp->name,"encoding")==0 ||
+	 strcasecmp(tmp->name,"schema")==0 ||
+	 strcasecmp(tmp->name,"datatype")==0 ||
+	 strcasecmp(tmp->name,"uom")==0) {
+
+	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
       }
       tmp=tmp->next;
@@ -2282,98 +2282,97 @@
       map* bb=getMap(m->content,"value");
       if(bb!=NULL) {
-	    map* tmpRes=parseBoundingBox(bb->value);
-	    printBoundingBox(ns_ows,nc3,tmpRes);
-	    freeMap(&tmpRes);
-	    free(tmpRes);
-      }
-    }
-	else {
+	map* tmpRes=parseBoundingBox(bb->value);
+	printBoundingBox(ns_ows,nc3,tmpRes);
+	freeMap(&tmpRes);
+	free(tmpRes);
+      }
+    }
+    else {
       if(e!=NULL)
-	    tmp=getMap(e->defaults->content,"mimeType");
+	tmp=getMap(e->defaults->content,"mimeType");
       else
-	    tmp=NULL;
+	tmp=NULL;
 	
-        map* tmp1=getMap(m->content,"encoding");
-        map* tmp2=getMap(m->content,"mimeType");
-        map* tmp3=getMap(m->content,"value");
-        int hasValue=1;
-        if(tmp3==NULL){
-	      tmp3=createMap("value","");
-	      hasValue=-1;
-        }
-
-       if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )  // if encoding is base64
-	        || 	                                                     // or if 
-	        ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL //  mime type is not text 
-	                            &&                                   //  nor 
-							    strstr(tmp2->value,"xml") == NULL  //  xml
-								&&                                          // nor
-								strstr(tmp2->value,"javascript") == NULL  // javascript
-								&&
-								strstr(tmp2->value,"json") == NULL
-								&&
-								strstr(tmp2->value,"ecmascript") == NULL
-								&&
-								// include for backwards compatibility,
-								// although correct mime type is ...kml+xml:
-								strstr(tmp2->value,"google-earth.kml") == NULL								
-							  )
-	        )
-		  ) { 	                                                   // then	
-	      map* rs=getMap(m->content,"size");                       // obtain size
-	      bool isSized=true;
-	      if(rs==NULL){
-	        char tmp1[1024];
-	        sprintf(tmp1,"%ld",strlen(tmp3->value));
-	        rs=createMap("size",tmp1);
-	        isSized=false;
-	      }
-
-	    xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
+      map* tmp1=getMap(m->content,"encoding");
+      map* tmp2=getMap(m->content,"mimeType");
+      map* tmp3=getMap(m->content,"value");
+      int hasValue=1;
+      if(tmp3==NULL){
+	tmp3=createMap("value","");
+	hasValue=-1;
+      }
+
+      if( ( tmp1 != NULL && strncmp(tmp1->value,"base64",6) == 0 )     // if encoding is base64
+	  || 	                                                       // or if 
+	  ( tmp2 != NULL && ( strstr(tmp2->value,"text") == NULL       //  mime type is not text 
+			      &&                                       //  nor 
+			      strstr(tmp2->value,"xml") == NULL        //  xml
+			      &&                                       // nor
+			      strstr(tmp2->value,"javascript") == NULL // javascript
+			      &&
+			      strstr(tmp2->value,"json") == NULL
+			      &&
+			      strstr(tmp2->value,"ecmascript") == NULL
+			      &&
+			      // include for backwards compatibility,
+			      // although correct mime type is ...kml+xml:
+			      strstr(tmp2->value,"google-earth.kml") == NULL							)
+	    )
+	  ) { 	                                                 // then	
+	map* rs=getMap(m->content,"size");                       // obtain size
+	bool isSized=true;
+	if(rs==NULL){
+	  char tmp1[1024];
+	  sprintf(tmp1,"%ld",strlen(tmp3->value));
+	  rs=createMap("size",tmp1);
+	  isSized=false;
+	}
+	 
+	xmlAddChild(nc3,xmlNewText(BAD_CAST base64(tmp3->value, atoi(rs->value))));  // base 64 encode in XML
 		
-	    if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
-	       xmlAttrPtr ap = xmlHasProp(nc3, BAD_CAST "encoding");
-	       if (ap != NULL) {
-	          xmlRemoveProp(ap);
-	       }			
-	       xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64");
-		}
+	if(tmp1==NULL || (tmp1!=NULL && strncmp(tmp1->value,"base64",6)!=0)) {
+	  xmlAttrPtr ap = xmlHasProp(nc3, BAD_CAST "encoding");
+	  if (ap != NULL) {
+	    xmlRemoveProp(ap);
+	  }			
+	  xmlNewProp(nc3,BAD_CAST "encoding",BAD_CAST "base64");
+	}
 		
- 	    if(!isSized){
-	      freeMap(&rs);
-	      free(rs);
-	    }
+	if(!isSized){
+	  freeMap(&rs);
+	  free(rs);
+	}
       }
       else if (tmp2!=NULL) {                                 // else (text-based format) 
-	    if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block 
-	       strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader) 
-	       strstr(tmp2->value, "ecmascript") != NULL
-		  ) {
-	       xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
-		}   
-	    else {                                                     // else
-	       if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
-			   // include for backwards compatibility,
-			   // although correct mime type is ...kml+xml:		   
-	           strstr(tmp2->value, "google-earth.kml") != NULL
-			  ) { 
+	if(strstr(tmp2->value, "javascript") != NULL ||      //    if javascript put code in CDATA block 
+	   strstr(tmp2->value, "json") != NULL ||            //    (will not be parsed by XML reader) 
+	   strstr(tmp2->value, "ecmascript") != NULL
+	   ) {
+	  xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST tmp3->value,strlen(tmp3->value)));
+	}   
+	else {                                                     // else
+	  if (strstr(tmp2->value, "xml") != NULL ||                 // if XML-based format
+	      // include for backwards compatibility,
+	      // although correct mime type is ...kml+xml:		   
+	      strstr(tmp2->value, "google-earth.kml") != NULL
+	      ) { 
 			  
-	          int li=zooXmlAddDoc(tmp3->value);
-	          xmlDocPtr doc = iDocs[li];
-	          xmlNodePtr ir = xmlDocGetRootElement(doc);
-	          xmlAddChild(nc3,ir);
-	       }
-	       else                                                     // else	
-	          xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));    //   add text node
-	    }
-	    xmlAddChild(nc2,nc3);
+	    int li=zooXmlAddDoc(tmp3->value);
+	    xmlDocPtr doc = iDocs[li];
+	    xmlNodePtr ir = xmlDocGetRootElement(doc);
+	    xmlAddChild(nc3,ir);
+	  }
+	  else                                                     // else	
+	    xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));    //   add text node
+	}
+	xmlAddChild(nc2,nc3);
       }
       else {
-	    xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));
+	xmlAddChild(nc3,xmlNewText(BAD_CAST tmp3->value));
       }
 	  
       if(hasValue<0) {
-	    freeMap(&tmp3);
-	    free(tmp3);
+	freeMap(&tmp3);
+	free(tmp3);
       }
     }
@@ -2387,16 +2386,16 @@
       xmlNewNsProp(nc3,ns_xlink,BAD_CAST "href",BAD_CAST tmpMap->value);
     
-	tmp=m->content;
+    tmp=m->content;
     while(tmp!=NULL) {
       if(strcasecmp(tmp->name,"mimeType")==0 ||
-	     strcasecmp(tmp->name,"encoding")==0 ||
-	     strcasecmp(tmp->name,"schema")==0 ||
-	     strcasecmp(tmp->name,"datatype")==0 ||
-	     strcasecmp(tmp->name,"uom")==0){
-
-	    if(strcasecmp(tmp->name,"datatype")==0)
-	      xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
-	    else
-	      xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+	 strcasecmp(tmp->name,"encoding")==0 ||
+	 strcasecmp(tmp->name,"schema")==0 ||
+	 strcasecmp(tmp->name,"datatype")==0 ||
+	 strcasecmp(tmp->name,"uom")==0){
+
+	if(strcasecmp(tmp->name,"datatype")==0)
+	  xmlNewProp(nc3,BAD_CAST "mimeType",BAD_CAST "text/plain");
+	else
+	  xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
       }
       tmp=tmp->next;
@@ -2660,7 +2659,8 @@
   free(tmpMap1->value);
   tmpMap1->value=(char*) malloc((count+1)*sizeof(char));  
-  fread(tmpMap1->value,count,sizeof(char),file);
+  fread(tmpMap1->value,1,count,file);
+  tmpMap1->value[count]=0;
   fclose(file);
-  char rsize[100];
+  char rsize[1000];
   sprintf(rsize,"%ld",count);
   addToMap(content,"size",rsize);
@@ -2833,5 +2833,5 @@
 	      map* size=getMap(tmpI->content,"size");
 	      if(size!=NULL && toto!=NULL)
-		fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile);
+		fwrite(toto->value,1,(atoi(size->value))*sizeof(char),ofile);
 	      else
 		if(toto!=NULL && toto->value!=NULL)
@@ -3044,5 +3044,5 @@
   bmem = BIO_new(BIO_s_mem());
   b64 = BIO_push(b64, bmem);
-  BIO_write(b64, input, length+1);
+  BIO_write(b64, input, length);
   BIO_flush(b64);
   BIO_get_mem_ptr(b64, &bptr);
@@ -3050,5 +3050,5 @@
   char *buff = (char *)malloc((bptr->length+1)*sizeof(char));
   memcpy(buff, bptr->data, bptr->length);
-  buff[bptr->length-1] = 0;
+  buff[bptr->length] = 0;
 
   BIO_free_all(b64);
Index: /trunk/zoo-project/zoo-kernel/service_internal_saga.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 634)
+++ /trunk/zoo-project/zoo-kernel/service_internal_saga.c	(revision 634)
@@ -0,0 +1,1193 @@
+/*
+ * Author : Gérald FENOY
+ *
+ * Copyright (c) 2015 GeoLabs SARL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <limits.h>
+#include "service_internal_saga.h"
+#include "mimetypes.h"
+
+/**
+ * Observer used to access the ongoing status of a running OTB Application
+ */
+class SagaWatcher
+{
+ public:
+  static int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2);
+  //int Callback(TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2);
+  /** 
+   * Define the message value
+   *
+   * @param conf the maps pointer to copy
+   */
+  static void SetMessage(const char *mess)
+  {
+    FreeMessage();
+    message=zStrdup(mess);
+  }
+  /** 
+   * Free the message value
+   *
+   */
+  static void FreeMessage()
+  {
+    if(message!=NULL)
+      free(message);
+    message=NULL;
+  }
+  /** 
+   * Copy the original conf in the m_conf property
+   *
+   * @param conf the maps pointer to copy
+   */
+  void SetConf(maps **conf)
+  {
+    m_conf=dupMaps(conf);
+  }
+  /**  
+   * Get Configuration maps (m_conf)
+   * @return the m_conf property
+   */
+  const maps& GetConf()
+  {
+    return *m_conf;
+  }
+  /**  
+   * Free Configuration maps (m_Conf)
+   */
+  void FreeConf(){
+    freeMaps(&m_conf);
+    free(m_conf);
+  }
+ private:
+  /** Main conf maps */
+  static maps* m_conf;
+  /** Status */
+  static int status;
+  /** Message */
+  static char* message;
+};
+
+maps* SagaWatcher::m_conf;
+char* SagaWatcher::message=zStrdup("");
+int SagaWatcher::status=1;
+
+/**
+ * The callback function called at any SAGA-GIS module step
+ *
+ * @param id a TSG_UI_Callback_ID as defined in api_core.h (line 1290)
+ * @param param1 
+ * @param param2
+ */
+int
+SagaWatcher::
+Callback(TSG_UI_Callback_ID id, CSG_UI_Parameter &param1, CSG_UI_Parameter &param2)
+{
+
+  int res = 1;
+  switch( id )
+    {
+    default:
+      res = 0;
+      break;
+
+    case CALLBACK_PROCESS_GET_OKAY:
+      break;
+
+    case CALLBACK_PROCESS_SET_OKAY:
+      break;
+
+    case CALLBACK_PROCESS_SET_PROGRESS:
+      {
+	int cPercent= param2.Number != 0.0 ? 1 + (int)(100.0 * param1.Number / param2.Number) : 100 ;
+	if( cPercent != status ){
+	  status=cPercent;
+	}
+      }
+      break;
+
+    case CALLBACK_PROCESS_SET_READY:
+      status=1;
+      break;
+
+    case CALLBACK_PROCESS_SET_TEXT:
+      SetMessage(param1.String.b_str());
+      break;
+
+    case CALLBACK_MESSAGE_ADD:
+      SetMessage(param1.String.b_str());
+      break;
+
+    case CALLBACK_MESSAGE_ADD_ERROR:
+      SetMessage(param1.String.b_str());
+      break;
+
+    case CALLBACK_MESSAGE_ADD_EXECUTION:
+      SetMessage(param1.String.b_str());
+      break;
+
+    case CALLBACK_DLG_MESSAGE:
+      SetMessage((param2.String + ": " + param1.String).b_str());
+      break;
+
+    case CALLBACK_DLG_CONTINUE:
+      break;
+
+    case CALLBACK_DLG_ERROR:
+      break;
+
+    case CALLBACK_DATAOBJECT_ADD:
+      if(SG_Get_Data_Manager().Add((CSG_Data_Object *)param1.Pointer))
+	res = 1 ;
+      else
+	res = 0;
+      break;
+
+    case CALLBACK_DATAOBJECT_UPDATE:
+      break;
+
+    case CALLBACK_DATAOBJECT_SHOW:
+      break;
+
+    case CALLBACK_DATAOBJECT_COLORS_GET:
+      break;
+
+    case CALLBACK_DATAOBJECT_COLORS_SET:
+      break;
+
+    case CALLBACK_DATAOBJECT_PARAMS_GET:
+      break;
+
+    case CALLBACK_DATAOBJECT_PARAMS_SET:
+      break;
+
+    case CALLBACK_DLG_PARAMETERS:
+      break;
+
+    }
+  updateStatus(m_conf,status,message);
+  return( res );
+}
+
+TSG_PFNC_UI_Callback	Get_Callback	(SagaWatcher watcher)
+{
+  return( &(watcher.Callback) );
+}
+
+
+/**
+ * Get the default file extension for SAGA-GIS parameter type.
+ * Extensions are the following:
+ *  - sgrd for grid and data_object
+ *  - shp for shapes and tin
+ *  - csv for tables
+ *  - spc for points
+ *
+ * @param param a SAGA-GIS Parameter
+ */ 
+const char* sagaGetDefaultExt(CSG_Parameter* param){
+  if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid"))
+     || CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("data_object"))){
+    return "sgrd";
+  }
+  else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes")) ||
+	  CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){
+    return "shp";
+  }
+  else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){
+    return "csv";
+  }
+  else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("points"))){
+    return "spc";
+  }
+  return "unknown";
+}
+
+/**
+ * Load a datasource in the SAGA-GIS Data Manager.
+ *
+ * @param param a SAGA-GIS Parameter
+ * @param arg the arguments map passed to a SAGA-GIS module
+ * @return false on failure, true in case of success
+ */
+bool sagaLoadInput(CSG_Parameter* param,map* arg){
+  if(!param->is_Input() || !param->is_Enabled()){
+    return true;
+  }
+  map* carg=getMap(arg,CSG_String(param->Get_Identifier()).b_str());
+  if(carg!=NULL){
+    wxString fileName(carg->value);
+    if(param->is_DataObject()){
+      // In case it there is a single datasource
+      if(!SG_Get_Data_Manager().Find(&fileName) && !SG_Get_Data_Manager().Add(&fileName) && !param->is_Optional() ){
+	return false;
+      }
+      return( param->Set_Value(SG_Get_Data_Manager().Find(&fileName)) );
+    }
+    else
+      if(param->is_DataObject_List()){
+	// In case there are multiple datasources
+	param->asList()->Del_Items();
+	wxString fileNames(fileName);
+	while( fileNames.Length() > 0 ){
+	  fileName = fileNames.BeforeFirst(';').Trim(false);
+	  fileNames = fileNames.AfterFirst (';');	    
+	  if( !SG_Get_Data_Manager().Find(&fileName) ){
+	    SG_Get_Data_Manager().Add(&fileName);
+	  }
+	  param->asList()->Add_Item(SG_Get_Data_Manager().Find(&fileName));
+	}
+      }
+  }
+  return true;
+}
+
+/**
+ * Extract all SAGA-GIS parameters from a parameters list and set its values to
+ * the one defined in the map.
+ *
+ * @parap params the parameters list
+ * @parap argument the argument map containing the value to use
+ * @return true in success, false in other case
+ */
+bool sagaSetParameters(CSG_Parameters *params,map* argument){
+
+  int pc=params->Get_Count();
+  params->Restore_Defaults();
+
+  for(int k=0;k<pc;k++){
+    CSG_Parameter * param=params->Get_Parameter(k);
+    if( param->is_Output() ){
+      map* omap=getMap(argument,CSG_String(param->Get_Identifier()).b_str());
+      if( param->is_DataObject() && param->is_Optional() && !param->asDataObject() && omap!=NULL){
+	param->Set_Value(DATAOBJECT_CREATE);
+      }
+    }
+    else
+      if( param->is_Option() && !param->is_Information() ){
+	map* inmap=getMap(argument,CSG_String(param->Get_Identifier()).b_str());
+	if(inmap!=NULL){
+	    switch( param->Get_Type() ){
+	    case PARAMETER_TYPE_Bool:
+	      if(strncasecmp(inmap->value,"true",4)==0 || strncasecmp(inmap->value,"1",1)==0){
+		param->Set_Value(1);
+	      }else
+		param->Set_Value(0);
+	      break;
+	    case PARAMETER_TYPE_Parameters:
+	      // TODO: nested inputs gesture
+	      break;
+	    case PARAMETER_TYPE_Int:
+	      param->Set_Value((int)strtol(inmap->value,NULL,10));
+	      break;
+	    case PARAMETER_TYPE_Double:
+	    case PARAMETER_TYPE_Degree:
+	      param->Set_Value((double)strtod(inmap->value,NULL));
+	      break;
+	    case PARAMETER_TYPE_String:
+	      param->Set_Value(CSG_String(inmap->value));
+	      break;
+	    case PARAMETER_TYPE_FilePath:
+	      param->Set_Value(CSG_String(inmap->value));
+	      break;
+	    case PARAMETER_TYPE_FixedTable:
+	      {
+		CSG_Table Table(inmap->value);
+		param->asTable()->Assign_Values(&Table);
+	      }
+	      break;
+	    case PARAMETER_TYPE_Choice:
+	      {
+		int val=(int)strtol(inmap->value,(char**)NULL,10);
+		if(val==0 && strncasecmp(inmap->value,"0",1)!=0)
+		  param->Set_Value(CSG_String(inmap->value));
+		else
+		  param->Set_Value(val);
+	      }
+	      break;
+	    default:
+	      break;
+	    }
+	}else{
+	  if(param->Get_Type()==PARAMETER_TYPE_Range){
+	    inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MIN").b_str());
+	    if(inmap!=NULL)
+	      param->asRange()->Set_LoVal(strtod(inmap->value,NULL));
+	    inmap=getMap(argument,(CSG_String(param->Get_Identifier())+"_MAX").b_str());
+	    if(inmap!=NULL)
+	      param->asRange()->Set_HiVal(strtod(inmap->value,NULL));	    
+	  }
+	  if(inmap==NULL){
+	    param->Restore_Default();
+	  }
+	}
+      }
+  }
+
+  for(int k=0;k<pc;k++){
+    CSG_Parameter * param=params->Get_Parameter(k);
+    if( param->is_Input() )
+      if(!sagaLoadInput(param,argument)){
+	fprintf(stderr,"%s %d \n",__FILE__,__LINE__);
+	return false;
+      }
+  }
+  return true;
+}
+
+/**
+ * Save all values outputed by a SAGA-GIS module invocation to files
+ *
+ * @param params the parameters list
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param outputs the maps to set the generated_file for each output
+ */
+bool sagaSaveOutputs(CSG_Parameters *params,maps* main_conf,maps** outputs)
+{
+  for(int j=0; j<params->Get_Count(); j++)
+    {
+      CSG_Parameter *param = params->Get_Parameter(j);
+      maps* cMaps=getMaps(*outputs,CSG_String(param->Get_Identifier()).b_str());
+      // Specific TIN case
+      if(cMaps==NULL && CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin")))
+	cMaps=getMaps(*outputs,(CSG_String(param->Get_Identifier())+"_POINTS").b_str());
+      if(cMaps!=NULL){
+	map* tmpPath=getMapFromMaps(main_conf,"main","tmpPath");
+	map* sid=getMapFromMaps(main_conf,"lenv","usid");
+	const char *file_ext=sagaGetDefaultExt(param);
+
+	if( param->is_Input() )
+	  {
+	    if( param->is_DataObject() )
+	      {
+		CSG_Data_Object *pObject = param->asDataObject();
+		
+		if( pObject && pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) )
+		  {
+		    pObject->Save(pObject->Get_File_Name());
+		    addToMap(cMaps->content,"generated_file",CSG_String(pObject->Get_File_Name()).b_str());
+		  }
+	      }
+	    
+	    else if( param->is_DataObject_List() )
+	      {
+		for(int i=0; i<param->asList()->Get_Count(); i++)
+		  {
+		    CSG_Data_Object	*pObject	= param->asList()->asDataObject(i);
+		    
+		    if( pObject->is_Modified() && SG_File_Exists(pObject->Get_File_Name()) )
+		      {
+			pObject->Save(pObject->Get_File_Name());
+			setMapArray(cMaps->content,"generated_file",i,CSG_String(pObject->Get_File_Name()).b_str());
+		      }
+		  }
+	      }
+	  }
+	else
+	  if( param->is_Output() )
+	    {
+	      char *realFileName=(char*)malloc((strlen(file_ext)+strlen(sid->value)+strlen(cMaps->name)+14)*sizeof(char));
+	      char *fullFileName=(char*)malloc((strlen(file_ext)+strlen(sid->value)+strlen(cMaps->name)+strlen(tmpPath->value)+16)*sizeof(char));
+	      sprintf(realFileName,"Output_%s_%d_%s",cMaps->name,sagaOutputCounter,sid->value);
+	      sprintf(fullFileName,"%s/Output_%s_%d_%s.%s",tmpPath->value,cMaps->name,sagaOutputCounter,sid->value,file_ext);
+	      sagaOutputCounter+=1;
+	      wxString fileName(fullFileName);
+	      addToMap(cMaps->content,"generated_name",realFileName);
+	      free(realFileName);
+	      free(fullFileName);
+
+	      if( param->is_DataObject() )
+		{
+		  if( param->asDataObject() )
+		    {
+		      param->asDataObject()->Save(&fileName);
+		      addToMap(cMaps->content,"generated_file",CSG_String(param->asDataObject()->Get_File_Name()).b_str());
+		    }
+		}
+	    
+	      else if( param->is_DataObject_List() )
+		{
+		  CSG_Strings	fileNames;
+		
+		  while( fileName.Length() > 0 )
+		    {
+		      CSG_String	s(&fileName); s = s.BeforeFirst(';');
+		    
+		      if( s.Length() > 0 )
+			{
+			  fileNames	+= s;
+			  fileName	 = fileName.AfterFirst(';');
+			}
+		      else
+			{
+			  fileNames	+= &fileName;
+			  fileName	.Clear();
+			}
+		    }
+		
+		  int nFileNames = param->asList()->Get_Count() <= fileNames.Get_Count() ? fileNames.Get_Count() : fileNames.Get_Count() - 1;
+		  for(int i=0; i<param->asList()->Get_Count(); i++)
+		    {
+		      fileNames[i].Trim();
+		      if( i < nFileNames )
+			{
+			  param->asList()->asDataObject(i)->Save(fileNames[i]);
+			}
+		      else
+			{
+			  param->asList()->asDataObject(i)->Save(CSG_String::Format(SG_T("%s_%0*d"),
+										    fileNames[fileNames.Get_Count() - 1].c_str(),
+										    SG_Get_Digit_Count(param->asList()->Get_Count()),
+										    1 + i - nFileNames
+										    ));
+			}
+		      setMapArray(cMaps->content,"generated_file",i,
+				  CSG_String(param->asList()->asDataObject(i)->Get_File_Name()).b_str());
+		    }
+		}
+	    }
+      }
+    } 
+  return( true );
+}
+
+/**
+ * Invoke the execution of a SAGA-GIS module.
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param lib_name the SAGA-GIS library name
+ * @param module_name the SAGA-GIS module name
+ * @param arguments the map containing the arguments to pass to the module
+ * @param outputs default to NULL, contains the maps to fill with the result
+ */
+int sagaExecuteCmd(maps** main_conf,const char* lib_name,const char* module_name,map* arguments,maps** outputs=NULL){
+  int res=SERVICE_FAILED;
+
+  CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(lib_name),true);
+  if( library == NULL){
+    char tmp[255];
+    sprintf(tmp,"Counld not load the %s SAGA library",lib_name);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+
+  CSG_Module * module=library->Get_Module(atoi(module_name));
+  if(module == NULL){
+    char tmp[255];
+    sprintf(tmp,"Counld not load the %s module from the %s SAGA library",module_name,lib_name);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+
+  CSG_Parameters * params=module->Get_Parameters();
+  if(!params){
+    char tmp[255];
+    sprintf(tmp,"Counld not find any param for the %s module from the %s SAGA library",module_name,lib_name);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+  
+  sagaSetParameters(params,arguments);
+
+  module->Update_Parameter_States();
+
+  bool retval=false;
+  if(module->On_Before_Execution()){
+    retval=module->Execute();
+    module->On_After_Execution();
+  }
+  
+  if(retval && outputs!=NULL){
+    sagaSaveOutputs(module->Get_Parameters(),*main_conf,outputs);
+    SG_Get_Data_Manager().Delete_Unsaved();
+    return SERVICE_SUCCEEDED;
+  }
+
+  return SERVICE_FAILED;
+
+}
+
+/**
+ * Export a SAGA-GIS Shapes to a file in a specific format (GML,KML,GeoJSON).
+ * saga_cmd io_gdal 4 -FILE my.format -SHAPES my.shp -FORMAT XXX
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param in the output maps to fill with the resulting file
+ */
+int sagaExportOGR(maps** conf, maps** in){
+  map* mtype=getMap((*in)->content,"mimeType");
+  map* gfile=getMap((*in)->content,"generated_file");
+  char* fext=NULL;
+  map* arg=NULL;
+  if(strncasecmp(mtype->value,"text/xml",8)==0){
+    fext=zStrdup("xml");
+  }
+  else if(strncasecmp(mtype->value,"application/json",16)==0){
+    fext=zStrdup("json");
+  }
+  else{
+    fext=zStrdup("kml");
+  }
+  char* tmpName=(char*)malloc((strlen(gfile->value)+2)*sizeof(char));
+  strncpy(tmpName,gfile->value,(strlen(gfile->value)-3)*sizeof(char));
+  strncpy(&tmpName[0]+(strlen(gfile->value)-3),fext,(strlen(fext))*sizeof(char));
+  tmpName[strlen(fext)+(strlen(gfile->value)-3)]=0;
+  arg=createMap("SHAPES",gfile->value);
+  addToMap(arg,"FILE",tmpName);
+  if(strncasecmp(mtype->value,"text/xml",8)==0){
+    addToMap(arg,"FORMAT","GML");
+  }
+  else if(strncasecmp(mtype->value,"application/json",16)==0){
+    addToMap(arg,"FORMAT","GeoJSON");
+  }
+  else{
+    addToMap(arg,"FORMAT","LIBKML");
+  }
+  free(fext);
+  free(gfile->value);
+  gfile->value=zStrdup(tmpName);
+  free(tmpName);
+  
+  sagaExecuteCmd(conf,"io_gdal","4",arg);
+  freeMap(&arg);
+  free(arg);
+}
+
+/**
+ * Export a SAGA-GIS pointcloud to a las file.
+ * saga_cmd io_shapes_las 0 -POINTS my.spc -FILE my.las
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param in the output maps to fill with the resulting file
+ */
+void sagaExportPC(maps** conf, maps** in){
+  map* mtype=getMap((*in)->content,"mimeType");
+  map* gfile=getMap((*in)->content,"generated_file");
+  char* fext="las";
+  map* arg=NULL;
+  char* tmpName=(char*)malloc((strlen(gfile->value)+2)*sizeof(char));
+  strncpy(tmpName,gfile->value,(strlen(gfile->value)-3)*sizeof(char));
+  strncpy(&tmpName[0]+(strlen(gfile->value)-3),fext,(strlen(fext))*sizeof(char));
+  tmpName[strlen(fext)+(strlen(gfile->value)-3)]=0;
+  arg=createMap("POINTS",gfile->value);
+  addToMap(arg,"FILE",tmpName);
+  free(gfile->value);
+  gfile->value=zStrdup(tmpName);
+  sagaExecuteCmd(conf,"io_shapes_las","0",arg);
+  freeMap(&arg);
+  free(arg);
+  free(tmpName);
+}
+
+/**
+ * Export a SAGA-GIS Grid to a file in a specific format (tiff,hdr,aa).
+ * saga_cmd io_gdal 1 -FILE my.format -GRIDS my.sgrd -FORMAT XXX
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param in the output maps to fill with the resulting file
+ */
+int sagaExportGDAL(maps** conf, maps** in/*,CSG_Parameter* param*/){
+  map* mtype=getMap((*in)->content,"extension");
+  map* gfile=getMap((*in)->content,"generated_file");
+  char* fext=NULL;
+  map* arg;
+
+  if(mtype!=NULL)
+    fext=zStrdup(mtype->value);
+  else{
+    fext=zStrdup("tiff");
+  }
+
+  mtype=getMap((*in)->content,"mimeType");
+  if(strncasecmp(mtype->value,"image/tiff",10)==0){
+    arg=createMap("FORMAT","1");
+  }
+  else if(strncasecmp(mtype->value,"application/x-ogc-envi",22)==0){
+    arg=createMap("FORMAT","ENVI .hdr Labelled");
+  }
+  else{
+    arg=createMap("FORMAT","ARC Digitized Raster Graphics");
+  }
+
+  if(gfile!=NULL){
+    char* tmpName=(char*)malloc((strlen(gfile->value)+1)*sizeof(char));
+    strncpy(tmpName,gfile->value,(strlen(gfile->value)-4)*sizeof(char));
+    strncpy(&tmpName[0]+(strlen(gfile->value)-4),fext,(strlen(fext))*sizeof(char));
+    tmpName[strlen(fext)+(strlen(gfile->value)-4)]=0;
+    addToMap(arg,"FILE",tmpName);
+    addToMap(arg,"GRIDS",gfile->value);
+    free(tmpName);
+    free(fext);
+    free(gfile->value);
+    map* tmp=getMap(arg,"FILE");
+    gfile->value=zStrdup(tmp->value);
+    sagaExecuteCmd(conf,"io_gdal","1",arg);
+  }
+  else{
+    // Empty result
+    return true;
+  }
+  freeMap(&arg);
+  free(arg);
+}
+
+/**
+ * Export a SAGA-GIS TIN to a file in a specific format (GML,KML,GeoJSON).
+ * Exporting TIN produce 5 separated files (POINTS, CENTER, EDGES, TRIANGLES 
+ * and POLYGONS). Even if a client can choose which result it want to have,
+ * SAGA-GIS module will be invoked in a way that it will produce in any case
+ * each possible outputs. The selection of a specific output is made in the 
+ * ZOO-Kernel itself and not specifically at this level.
+ * saga_cmd tin_tools 3 -TIN my.shp -POINTS p.shp ...
+ *
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in the output maps to fill with the resulting file
+ * @see sagaExportOGR
+ */
+int sagaExportTIN(maps** conf, maps** in,const char* tname/*,CSG_Parameter* param*/){
+  dumpMaps(*in);
+  map* mtype=getMap((*in)->content,"mimeType");
+  map* gfile=getMap((*in)->content,"generated_file");
+  char* fext="shp";
+  map* arg=createMap("TIN",gfile->value);
+
+  char* tinOut[5]={
+    "POINTS",
+    "CENTER",
+    "EDGES",
+    "TRIANGLES",
+    "POLYGONS"
+  };
+  maps* resouts=NULL;
+
+  int i=0;
+  for(i=0;i<5;i++){
+    char* tmpName=(char*)malloc((strlen(gfile->value)+strlen(tinOut[i])+4)*sizeof(char));
+    strncpy(tmpName,gfile->value,(strlen(gfile->value)-3)*sizeof(char));
+    char *tmpSubName=(char*) malloc((strlen(tinOut[i])+3)*sizeof(char));
+    sprintf(tmpSubName,"_%s.",tinOut[i]);
+    strncpy(&tmpName[0]+(strlen(gfile->value)-4),tmpSubName,(strlen(tmpSubName))*sizeof(char));
+    strncpy(&tmpName[0]+(strlen(gfile->value)+strlen(tmpSubName)-4),fext,(strlen(fext))*sizeof(char));
+    tmpName[strlen(fext)+(strlen(gfile->value)+strlen(tmpSubName)-4)]=0;
+
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup(tinOut[i]);
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+    
+    addToMap(arg,tinOut[i],tmpName);
+    
+    free(tmpName);
+    if(resouts==NULL)
+      resouts=dupMaps(&louts);
+    else
+      addMapsToMaps(&resouts,louts);
+    freeMaps(&louts);
+    free(louts);
+  }
+  
+  sagaExecuteCmd(conf,"tin_tools","3",arg,&resouts);
+
+  for(i=0;i<5;i++){
+    map* generatedFile=getMapFromMaps(resouts,tinOut[i],"generated_file");
+    setMapInMaps(*in,(CSG_String(tname)+"_"+tinOut[i]).b_str(),"generated_file",generatedFile->value);
+    maps* cout=getMaps(*in,(CSG_String(tname)+"_"+tinOut[i]).b_str());
+    sagaExportOGR(conf,&cout);
+  }
+  return true;
+}
+
+/**
+ * Import GDAL Datasource into SAGA-GIS.
+ * saga_cmd io_gdal 0 -TRANSFORM 0 -FILES my.format -GRIDS /tmpPath/MyGridXXX.sgrd
+ * 
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in in the inputs maps
+ */
+int sagaImportGDAL(maps** conf, maps** in){
+  map* l=getMap((*in)->content,"length");
+  bool shouldClean=false;
+  if(l==NULL){
+    l=createMap("length","1");
+    shouldClean=true;
+  }
+  int len=strtol(l->value,NULL,10);
+  int i=0;
+  for(i=0;i<len;i++){
+    map* arg=createMap("TRANSFORM","0");
+    addToMap(arg,"INTERPOL","4");
+    map* v=getMapArray((*in)->content,"cache_file",i);
+    if(v!=NULL)
+      addToMap(arg,"FILES",v->value);
+    addToMap(arg,"GRIDS","");
+
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup("GRIDS");
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+
+    sagaExecuteCmd(conf,"io_gdal","0",arg,&louts);
+
+    map* tmp=getMapFromMaps(louts,"GRIDS","generated_file");
+    setMapArray((*in)->content,"saga_value",i,tmp->value);
+
+    freeMaps(&louts);
+    free(louts);
+    freeMap(&arg);
+    free(arg);
+  }
+  if(shouldClean){
+    freeMap(&l);
+    free(l);
+  }
+}
+
+/**
+ * Import OGR Datasource into SAGA-GIS.
+ * saga_cmd io_gdal 3 -SHAPES my.shp -FILES my.format
+ * 
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in in the inputs maps
+ */
+int sagaImportOGR(maps** conf, maps** in){
+  char *ext;
+  map* arg;
+  map* l=getMap((*in)->content,"length");
+  bool shouldClean=false;
+  if(l==NULL){
+    l=createMap("length","1");
+    shouldClean=true;
+  }
+  int len=strtol(l->value,NULL,10);
+  int i=0;
+  for(i=0;i<len;i++){
+    map* v=getMapArray((*in)->content,"cache_file",i);
+    arg=createMap("SHAPES","");
+    if(v!=NULL)
+      addToMap(arg,"FILES",v->value);
+
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup("SHAPES");
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+
+    sagaExecuteCmd(conf,"io_gdal","3",arg,&louts);
+
+    map* tmp=getMapFromMaps(louts,"SHAPES","generated_file");
+    setMapArray((*in)->content,"saga_value",i,tmp->value);
+
+    freeMaps(&louts);
+    free(louts);
+    freeMap(&arg);
+    free(arg);
+  }
+  if(shouldClean){
+    freeMap(&l);
+    free(l);
+  }
+}
+
+/**
+ * Import TIN into SAGA-GIS. Calling this function suppose that sagaImportOGR
+ * was called first.
+ * saga_cmd tin_tools 2 -SHAPES myShapes.shp -TIN myTin.shp
+ * 
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in in the inputs maps
+ * @see sagaImportOGR
+ */
+bool sagaImportTIN(maps** conf, maps** in){
+  char *ext;
+  map* arg;
+  map* l=getMap((*in)->content,"length");
+  bool shouldClean=false;
+  if(l==NULL){
+    l=createMap("length","1");
+    shouldClean=true;
+  }
+  int len=strtol(l->value,NULL,10);
+  int i=0;
+  for(i=0;i<len;i++){
+    map* v=getMapArray((*in)->content,"saga_value",i);
+    arg=createMap("TIN","");
+    if(v!=NULL)
+      addToMap(arg,"SHAPES",v->value);
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup("TIN");
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+    sagaExecuteCmd(conf,"tin_tools","2",arg,&louts);
+    map* tmp=getMapFromMaps(louts,"TIN","generated_file");
+    v=getMapArray((*in)->content,"saga_value",i);
+    if(tmp!=NULL){
+      if(v!=NULL){
+	free(v->value);
+	v->value=zStrdup(tmp->value);
+      }
+      else
+	setMapArray((*in)->content,"saga_value",i,tmp->value);
+    }
+    freeMaps(&louts);
+    free(louts);
+    freeMap(&arg);
+    free(arg);
+  }
+  if(shouldClean){
+    freeMap(&l);
+    free(l);
+  }
+  return true;
+}
+
+/**
+ * Import table into SAGA-GIS. 
+ * saga_cmd io_table 1 -TABLE myTable -FILENAME myFile -SEPARATOR 2
+ * 
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in in the inputs maps
+ */
+int sagaImportTable(maps** conf, maps** in){
+  char *ext;
+  map* arg;
+  map* l=getMap((*in)->content,"length");
+  bool shouldClean=false;
+  if(l==NULL){
+    l=createMap("length","1");
+    shouldClean=true;
+  }
+  int len=strtol(l->value,NULL,10);
+  int i=0;
+  for(i=0;i<len;i++){
+
+    // Create and fill arg map
+    arg=createMap("SEPARATOR","2");
+    addToMap(arg,"TABLE","");
+    map* v=getMapArray((*in)->content,"cache_file",i);
+    if(v!=NULL)
+      addToMap(arg,"FILENAME",v->value);
+
+    // Create the output maps
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup("TABLE");
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+
+    // Execute the saga command
+    sagaExecuteCmd(conf,"io_table","1",arg,&louts);
+
+    // Fetch result and add it to the original map as saga_value
+    map* tmp=getMapFromMaps(louts,"TABLE","generated_file");
+    setMapArray((*in)->content,"saga_value",i,tmp->value);
+
+    // Cleanup
+    freeMaps(&louts);
+    free(louts);
+    freeMap(&arg);
+    free(arg);
+
+  }
+  // Cleanup if required
+  if(shouldClean){
+    freeMap(&l);
+    free(l);
+  }
+}
+
+/**
+ * Import las file as pointcloud into SAGA-GIS. 
+ * saga_cmd io_shapes_las 1 -POINTS my.spc -FILENAME my.las
+ * 
+ * @param conf the conf maps containing the main.cfg settings
+ * @param in in the inputs maps
+ */
+int sagaImportPC(maps** conf, maps** in){
+  char *ext;
+  map* arg;
+  map* l=getMap((*in)->content,"length");
+  bool shouldClean=false;
+  if(l==NULL){
+    l=createMap("length","1");
+    shouldClean=true;
+  }
+  int len=strtol(l->value,NULL,10);
+  int i=0;
+  for(i=0;i<len;i++){
+
+    // Create and fill arg map
+    arg=createMap("POINTS","");
+    map* v=getMapArray((*in)->content,"cache_file",i);
+    if(v!=NULL)
+      addToMap(arg,"FILES",v->value);
+
+    // Create the output maps
+    maps* louts=(maps*)malloc(MAPS_SIZE);
+    louts->name=zStrdup("POINTS");
+    louts->content=createMap("mimeType","UNKOWN");
+    louts->next=NULL;
+
+    // Execute the saga command
+    sagaExecuteCmd(conf,"io_shapes_las","1",arg,&louts);
+
+    // Fetch result and add it to the original map as saga_value
+    map* tmp=getMapFromMaps(louts,"POINTS","generated_file");
+    setMapArray((*in)->content,"saga_value",i,tmp->value);
+
+    // Cleanup
+    freeMaps(&louts);
+    free(louts);
+    freeMap(&arg);
+    free(arg);
+
+  }
+  // Cleanup if required
+  if(shouldClean){
+    freeMap(&l);
+    free(l);
+  }
+}
+
+/**
+ * Load and invoke a SAGA-GIS module defined in a service metadata definitions.
+ * Load all the input data into SAGA-GIS using io_gdal, io_tables and 
+ * io_shapes_las for SAGA grids/shapes, tables and pointcloud respectively. 
+ * Load and run the module from its library and invoke it using the data 
+ * imported in SAGA-GIS at first stage. After the execution, export the outputs
+ * to files using io_gdal and io_shapes_las for grids/shapes and pointcloud 
+ * respectively.
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param request the map containing the HTTP request
+ * @param s the service structure
+ * @param inputs the maps containing the inputs
+ * @param outputs the maps containing the outputs
+ */
+int zoo_saga_support(maps** main_conf,map* request,service* s,maps** inputs,maps** outputs){
+  int res=SERVICE_FAILED;
+  if( !wxInitialize() ){
+    fprintf(stderr,"initialisation failed");
+    return SERVICE_FAILED;
+  }
+  setlocale(LC_NUMERIC, "C");
+  static bool g_bShow_Messages = false;
+
+  dumpMapsValuesToFiles(main_conf,inputs);
+
+  SagaWatcher watcher=SagaWatcher();
+  watcher.SetConf(main_conf);
+
+  SG_Set_UI_Callback(Get_Callback(watcher));
+
+  int n = SG_Get_Module_Library_Manager().Add_Directory(wxT(MODULE_LIBRARY_PATH),false);
+  if( SG_Get_Module_Library_Manager().Get_Count() <= 0 ){
+    setMapInMaps(*main_conf,"lenv","message","Could not load any SAGA tool library");
+    res=SERVICE_FAILED;
+    return res;
+  }
+
+  map* serviceProvider=getMap(s->content,"serviceProvider");
+
+  // Load the SAGA-GIS library corresponding to the serviceProvider
+  CSG_Module_Library * library=SG_Get_Module_Library_Manager().Get_Library(CSG_String(serviceProvider->value),true);
+  if( library == NULL){
+    char tmp[255];
+    sprintf(tmp,"Counld not load the %s SAGA library",serviceProvider->value);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+  
+  // Load the SAGA-GIS module corresponding to the service name from the library
+  CSG_Module * module=library->Get_Module(atoi(s->name));
+  if(module == NULL){
+    char tmp[255];
+    sprintf(tmp,"Counld not load the %s module from the %s SAGA library",
+	    s->name,serviceProvider->value);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+
+  // Load all the parameters defined for the module
+  CSG_Parameters * params=module->Get_Parameters();
+  int pc=params->Get_Count();
+  if(!params){
+    char tmp[255];
+    sprintf(tmp,"Counld not find any param for the %s module from the %s SAGA library",
+	    s->name,serviceProvider->value);
+    setMapInMaps(*main_conf,"lenv","message",tmp);
+    res=SERVICE_FAILED;
+    return res;
+  }
+
+  // Loop over each inputs to transform raster files to grid when needed, 
+  // import tables, shapes or point clouds
+  for(int k=0;k<pc;k++){
+    CSG_Parameter * param=params->Get_Parameter(k);
+    if(param!=NULL && !param->is_Output()){
+      maps* inmap=getMaps(*inputs,CSG_String(param->Get_Identifier()).b_str());
+      if(inmap!=NULL){
+	map* tmp=getMap(inmap->content,"value");
+	if(tmp==NULL || strncasecmp(tmp->value,"NULL",4)!=0){
+	  if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid"))){
+	    sagaImportGDAL(main_conf,&inmap);
+	  }
+	  else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){
+	    sagaImportOGR(main_conf,&inmap);
+	    sagaImportTIN(main_conf,&inmap);
+	  }
+	  else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes"))){
+	    sagaImportOGR(main_conf,&inmap);
+	  }
+	  else{
+	    if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){
+	      sagaImportTable(main_conf,&inmap);
+	    }
+	    else
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("points"))){
+		sagaImportPC(main_conf,&inmap);
+	      }
+	  }
+	}
+      }
+    }
+  }
+
+  // Create a map conraining arguments to pass to the SAGA-GIS module
+  // Fetch all input value (specifically for data imported into SAGA-GIS)
+  maps* inp=*inputs;
+  int k=0;
+  map* cParams=NULL;
+  while(inp!=NULL){
+    map* len=getMap(inp->content,"length");
+    bool shouldClean=false;
+    if(len==NULL){
+      len=createMap("length","1");
+      shouldClean=true;
+    }
+    int len0=strtol(len->value,NULL,10);
+    int i=0;
+    char *cinput=NULL;
+    int clen=0;
+    for(i=0;i<len0;i++){
+      map* val=getMapArray(inp->content,"saga_value",i);
+      if(val==NULL)
+	val=getMapArray(inp->content,"value",i);
+      if(val!=NULL && strncasecmp(val->value,"NULL",4)!=0){
+	if(cinput==NULL){
+	  cinput=zStrdup(val->value);
+	}
+	else{
+	  cinput=(char*)realloc(cinput,(clen+strlen(val->value)+1)*sizeof(char));
+	  strncpy(&cinput[0]+clen,";",1);
+	  strncpy(&cinput[0]+(clen+1),val->value,strlen(val->value));
+	  clen+=1;
+	}
+	clen+=strlen(val->value);
+	cinput[clen]=0;
+      }
+    }
+    if(cinput!=NULL && strncasecmp(cinput,"NULL",4)!=0){
+      if(cParams==NULL)
+	cParams=createMap(inp->name,cinput);
+      else
+	addToMap(cParams,inp->name,cinput);
+      free(cinput);
+    }
+    inp=inp->next;
+  }
+
+  // Fetch all output and define a resulting filename
+  inp=*outputs;
+  map* tmpPath=getMapFromMaps(*main_conf,"main","tmpPath");
+  map* sid=getMapFromMaps(*main_conf,"lenv","usid");
+  while(inp!=NULL){
+    for(int k=0;k<pc;k++){
+      CSG_Parameter * param=params->Get_Parameter(k);
+      if(CSG_String(param->Get_Identifier()).Cmp(inp->name)==0){
+	const char *file_ext=sagaGetDefaultExt(param);
+	char *fileName=(char*)malloc((strlen(file_ext)+strlen(sid->value)+strlen(inp->name)+strlen(tmpPath->value)+11)*sizeof(char));
+	sprintf(fileName,"%s/Output_%s_%s.%s",tmpPath->value,inp->name,sid->value,file_ext);
+	if(cParams==NULL)
+	  cParams=createMap(inp->name,fileName);
+	else
+	  addToMap(cParams,inp->name,fileName);
+      }
+    }
+    inp=inp->next;
+  }
+
+  sagaSetParameters(params,cParams);
+
+  module->Update_Parameter_States();
+  
+  bool retval=false;
+  if(module->On_Before_Execution()){
+    retval=module->Execute();
+    module->On_After_Execution();
+  }
+
+  sagaSaveOutputs(params,*main_conf,outputs);
+
+  // Loop over each outputs to transform grid to raster file when needed, 
+  // export tables, shapes or point clouds
+  for(int k=0;k<pc;k++){
+    CSG_Parameter * param=params->Get_Parameter(k);
+    if(param!=NULL && param->is_Output()){
+      maps* inmap=getMaps(*outputs,CSG_String(param->Get_Identifier()).b_str());
+      if(inmap!=NULL){
+	if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("grid"))
+	   || CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("data_object"))){
+	  sagaExportGDAL(main_conf,&inmap);
+	}else{
+	  if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("shapes"))){
+	    sagaExportOGR(main_conf,&inmap);
+	  }
+	  else{
+	    if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("table"))){
+	    }
+	    else{
+	      if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){
+		sagaExportTIN(main_conf,&inmap,"TIN");
+	      }
+	      else
+		if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("points"))){
+		  sagaExportPC(main_conf,&inmap);
+	      }
+	    }
+	  }
+	}
+      }
+      else if(CSG_String(param->Get_Type_Identifier()).Contains(CSG_String("tin"))){
+	sagaExportTIN(main_conf,outputs,CSG_String(param->Get_Identifier()).b_str());
+      }
+	      
+    }
+  }
+
+  wxUninitialize();
+
+  return SERVICE_SUCCEEDED;
+}
Index: /trunk/zoo-project/zoo-kernel/service_internal_saga.h
===================================================================
--- /trunk/zoo-project/zoo-kernel/service_internal_saga.h	(revision 634)
+++ /trunk/zoo-project/zoo-kernel/service_internal_saga.h	(revision 634)
@@ -0,0 +1,47 @@
+/*
+ * Author : Gérald FENOY
+ *
+ * Copyright (c) 2015 GeoLabs SARL
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef ZOO_SERVICE_INTERNAL_SAGA_H
+#define ZOO_SERVICE_INTERNAL_SAGA_H 1
+
+#pragma once 
+
+#include <locale.h>
+#define _WX_WXCRTVARARG_H_
+#include <wx/string.h>
+#include <wx/app.h>
+#include <api_core.h>
+#include <data_manager.h>
+#include <module_library.h>
+
+#include "service.h"
+#include "service_internal.h"
+
+/**
+ * Global SAGA-GIS output counter 
+ */
+int sagaOutputCounter=0;
+int zoo_saga_support(maps**,map*,service*,maps**,maps**);
+
+#endif
Index: /trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 633)
+++ /trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 634)
@@ -58,4 +58,8 @@
 #ifdef USE_PYTHON
 #include "service_internal_python.h"
+#endif
+
+#ifdef USE_SAGA
+#include "service_internal_saga.h"
 #endif
 
@@ -695,4 +699,15 @@
     }
   else
+
+#ifdef USE_SAGA
+  if (strncasecmp (r_inputs->value, "SAGA", 6) == 0)
+    {
+      *eres =
+        zoo_saga_support (&m, request_inputs, s1,
+                            &request_input_real_format,
+                            &request_output_real_format);
+    }
+  else
+#endif
 
 #ifdef USE_OTB
