Index: trunk/zoo-project/zoo-services/cgal/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/cgal/Makefile	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/Makefile	(revision 917)
@@ -1,5 +1,5 @@
 ZRPATH=../..
 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
-CFLAGS=-I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG
+CFLAGS= ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} ${CGAL_CFLAGS} -frounding-math -fPIC -DLINUX_FREE_ISSUE #-DDEBUG
 CC=gcc
 
@@ -7,5 +7,5 @@
 	g++ ${CFLAGS} -c ./delaunay.c
 	g++ ${CFLAGS} -c ./voronoi.c
-	g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${MACOS_LD_FLAGS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
+	g++ ${CFLAGS} -shared -o cgi-env/cgal_service.zo ./delaunay.o ./voronoi.o ./cgal_service.o ${GDAL_LIBS} ${CGAL_LDFLAGS} -lCGAL -lgmp ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service -lfcgi
 
 cgal_service.o: cgal_service.c cgal_service.h
Index: trunk/zoo-project/zoo-services/cgal/cgal_service.c
===================================================================
--- trunk/zoo-project/zoo-services/cgal/cgal_service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/cgal_service.c	(revision 917)
@@ -24,17 +24,32 @@
 #include "cgal_service.h"
 
-int parseInput(maps* conf,maps* inputs, std::vector<Point>* points,char* filename){
+int parseInput(maps* conf,maps* inputs, std::vector<Pointz>* points,char* filename){
   map* tmpm=NULL;
-  tmpm=getMapFromMaps(inputs,"InputPoints","value");
-  VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE);
-  VSIFCloseL(ifile);
+  tmpm=getMapFromMaps(inputs,"InputPoints","cache_file");
 #if GDAL_VERSION_MAJOR >= 2
-  GDALDataset *ipoDS =
-    (GDALDataset*) GDALOpenEx( filename,
-			       GDAL_OF_READONLY | GDAL_OF_VECTOR,
-			       NULL, NULL, NULL );
+  GDALDataset *ipoDS;
 #else
-  OGRDataSource* ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
+  OGRDataSource* ipoDS;
 #endif
+  if(tmpm==NULL){
+    tmpm=getMapFromMaps(inputs,"InputPoints","value");
+    VSILFILE *ifile=VSIFileFromMemBuffer(filename,(GByte*)tmpm->value,strlen(tmpm->value),FALSE);
+    VSIFCloseL(ifile);
+#if GDAL_VERSION_MAJOR >= 2
+  ipoDS = (GDALDataset*) GDALOpenEx( filename,
+				     GDAL_OF_READONLY | GDAL_OF_VECTOR,
+				     NULL, NULL, NULL );
+#else
+  ipoDS = OGRSFDriverRegistrar::Open(filename,FALSE);
+#endif
+  }else
+#if GDAL_VERSION_MAJOR >= 2
+    ipoDS = (GDALDataset*) GDALOpenEx( tmpm->value,
+				       GDAL_OF_READONLY | GDAL_OF_VECTOR,
+				       NULL, NULL, NULL );
+#else
+    ipoDS = OGRSFDriverRegistrar::Open(tmpm->value,FALSE);
+#endif
+    
   if( ipoDS == NULL )
     {
@@ -87,5 +102,5 @@
 	  break;
 	if(poFeature->GetGeometryRef() != NULL){
-	  points->push_back(Point(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
+	  points->push_back(Pointz(OGR_G_GetX(poFeature->GetGeometryRef(),0),OGR_G_GetY(poFeature->GetGeometryRef(),0)));
 	}
       }
Index: trunk/zoo-project/zoo-services/cgal/cgal_service.h
===================================================================
--- trunk/zoo-project/zoo-services/cgal/cgal_service.h	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/cgal_service.h	(revision 917)
@@ -38,7 +38,7 @@
 
 typedef CGAL::Exact_predicates_inexact_constructions_kernel            Kernel;
-typedef Kernel::Point_2                                                Point;
+typedef Kernel::Point_2                                                Pointz;
 
-int parseInput(maps*,maps*, std::vector<Point>*,char*);
+int parseInput(maps*,maps*, std::vector<Pointz>*,char*);
 
 #endif
Index: trunk/zoo-project/zoo-services/cgal/cgi-env/Voronoi.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/cgal/cgi-env/Voronoi.zcfg	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/cgi-env/Voronoi.zcfg	(revision 917)
@@ -46,4 +46,10 @@
     </Default>
     <Supported>
+      mimeType = image/png
+      useMapserver = true
+      asReference = true
+      msStyle = STYLE COLOR 125 0 105 OUTLINECOLOR 0 0 0 WIDTH 0.3 OPACITY 65 END
+    </Supported>
+    <Supported>
      mimeType = text/xml
      encoding = base64
Index: trunk/zoo-project/zoo-services/cgal/delaunay.c
===================================================================
--- trunk/zoo-project/zoo-services/cgal/delaunay.c	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/delaunay.c	(revision 917)
@@ -40,5 +40,5 @@
     OGRRegisterAll();
 
-    std::vector<Point> points;
+    std::vector<Pointz> points;
     if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
       return res;
Index: trunk/zoo-project/zoo-services/cgal/voronoi.c
===================================================================
--- trunk/zoo-project/zoo-services/cgal/voronoi.c	(revision 811)
+++ trunk/zoo-project/zoo-services/cgal/voronoi.c	(revision 917)
@@ -24,7 +24,7 @@
 
 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
-#include <CGAL/Triangulation_euclidean_traits_xy_3.h>
+//#include <CGAL/Triangulation_euclidean_traits_2.h>
 #include <CGAL/Delaunay_triangulation_2.h>
-#include <CGAL/Constrained_Delaunay_triangulation_2.h>
+//#include <CGAL/Constrained_Delaunay_triangulation_2.h>
 #include <CGAL/Triangulation_conformer_2.h>
 #include <CGAL/Triangulation_face_base_2.h>
@@ -39,4 +39,5 @@
 
 typedef CGAL::Delaunay_triangulation_2<Kernel>  Triangulation;
+typedef Triangulation::Face_iterator  Face_iterator;
 typedef Triangulation::Edge_iterator  Edge_iterator;
 typedef Triangulation::Vertex_circulator Vertex_circulator;
@@ -45,7 +46,8 @@
 
   int Voronoi(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
+    //#ifdef DEBUG
     fprintf(stderr,"\nService internal print\nStarting\n");
-#endif
+    //#endif
+    //return SERVICE_FAILED;
     maps* cursor=inputs;
     OGRGeometryH geometry,res;
@@ -54,14 +56,22 @@
     tmpm=getMapFromMaps(inputs,"InputPoints","value");
 
+    fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
+    fflush(stderr);
+
     OGRRegisterAll();
 
-    std::vector<Point> points;
-    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED)
-      return res;
+    std::vector<Pointz> points;
+    if(int res=parseInput(conf,inputs,&points,"/vsimem/tmp")!=SERVICE_SUCCEEDED){
+      fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
+      fflush(stderr);
+      return SERVICE_FAILED;
+    }
+    fprintf(stderr," **** %s %d\n",__FILE__,__LINE__);
+    fflush(stderr);
     
     Triangulation T;
     T.insert(points.begin(), points.end());
 
-    OGRRegisterAll();
+    //OGRRegisterAll();
     /* -------------------------------------------------------------------- */
     /*      Try opening the output datasource as an existing, writable      */
@@ -187,10 +197,21 @@
     int ns = 0;
     int nr = 0;
+    int nf = 0;
+    Face_iterator fit =T.faces_begin();
+    FILE* f=fopen("/tmp/toto.log","w+");
+    for ( ; fit !=T.faces_end(); ++fit) {
+      fprintf(stderr," *** %s %d %d %d\n",__FILE__,__LINE__,nf,fit.info());
+      fflush(stderr);
+      
+      nf++;
+    }
+    fclose(f);
     Edge_iterator eit =T.edges_begin();
     for ( ; eit !=T.edges_end(); ++eit) {
       CGAL::Object o = T.dual(eit);
       if (const Kernel::Segment_2 *tmp=CGAL::object_cast<Kernel::Segment_2>(&o)) {
-	const Point p1=tmp->source();
-	const Point p2=tmp->target();
+	const Pointz p1=tmp->source();
+	const Pointz p2=tmp->target();
+	fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
 #ifdef DEBUG
 	fprintf(stderr,"P1 %d %d | P2 %d %d\n",p1.x(),p1.y(),p2.x(),p2.y());
@@ -210,6 +231,6 @@
       }
       else if (const Kernel::Ray_2 *tmp=CGAL::object_cast<Kernel::Ray_2>(&o)) { 
-	const Point p1=tmp->source();
-	const Point p2=tmp->point(2);
+	const Pointz p1=tmp->source();
+	const Pointz p2=tmp->point(2);
 	OGRFeatureH hFeature = OGR_F_Create( OGR_L_GetLayerDefn( poDstLayer ) );
 	OGRGeometryH currLine=OGR_G_CreateGeometry(wkbLineString);
@@ -250,5 +271,5 @@
     fprintf(stderr,"\nService internal print\n===\n");
 #endif
-    OGRCleanupAll();
+    //OGRCleanupAll();
     return SERVICE_SUCCEEDED;
   }
Index: trunk/zoo-project/zoo-services/gdal/dem/cgi-env/Gdal_Dem.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/gdal/dem/cgi-env/Gdal_Dem.zcfg	(revision 811)
+++ trunk/zoo-project/zoo-services/gdal/dem/cgi-env/Gdal_Dem.zcfg	(revision 917)
@@ -44,4 +44,13 @@
     <Default />
    </LiteralData>
+  [co]
+   Title = Creation Option
+   Abstract = string representing options (NAME=VALUE)
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    DataType = string
+    <Default />
+   </LiteralData>
  </DataInputs>
  <DataOutputs>
Index: trunk/zoo-project/zoo-services/gdal/dem/service.c
===================================================================
--- trunk/zoo-project/zoo-services/gdal/dem/service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/gdal/dem/service.c	(revision 917)
@@ -2486,4 +2486,19 @@
       setMapInMaps(outputs,"Result","value",tmpMap->value);
     }
+    
+    tmpMap=getMapFromMaps(inputs,"co","value");
+    if(tmpMap!=NULL){
+      papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value );  
+      map* tmpMap1;
+      maps* tmpMaps=getMaps(inputs,"co");
+      if((tmpMap1=getMapFromMaps(inputs,"co","length"))!=NULL){
+        int i=1;
+        int length=atoi(tmpMap1->value);
+        for(;i<length;i++){
+          tmpMap=getMapArray(tmpMaps->content,"value",i);
+          papszCreateOptions = CSLAddString( papszCreateOptions, tmpMap->value );
+        }
+      } 
+    }    
 
     tmpMap=NULL;
Index: trunk/zoo-project/zoo-services/hello-mono/cgi-env/longProcessMono.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/hello-mono/cgi-env/longProcessMono.zcfg	(revision 811)
+++ trunk/zoo-project/zoo-services/hello-mono/cgi-env/longProcessMono.zcfg	(revision 917)
@@ -1,5 +1,5 @@
 [longProcessMono]
- Title = Create a welcome message string.
- Abstract = Create a welcome string.
+ Title = Demo long process.
+ Abstract = This service doesn't do anything except taking its time, it demonstrates how to use the updateStatus function from your ZOO Service.
  processVersion = 2
  storeSupported = true
@@ -13,22 +13,9 @@
    Title = Input string
    Abstract = The name to display in the welcome message.
-   minOccurs = 1
+   minOccurs = 0
    maxOccurs = 1
    <LiteralData>
     dataType = int
-    <Default>
-    AllowedValues = 101,202,303,404
-    rangeMin = -100
-    rangeMax = 100
-    rangeSpacing = 1
-    rangeClosure = co
-      value = 11
-    </Default>
-    <Supported>
-    	AllowedValues = 405,502,503,504
-    </Supported>
-    <Supported>
-    	AllowedValues = 540,502,603,604
-    </Supported>
+    <Default />
    </LiteralData>
  </DataInputs>
Index: trunk/zoo-project/zoo-services/hello-mono/makefile.vc
===================================================================
--- trunk/zoo-project/zoo-services/hello-mono/makefile.vc	(revision 917)
+++ trunk/zoo-project/zoo-services/hello-mono/makefile.vc	(revision 917)
@@ -0,0 +1,9 @@
+!INCLUDE ../../zoo-kernel/nmake.opt
+	
+all: cgi-env/TestService.dll
+
+cgi-env/TestService.dll: test.cs
+	$(MONO_DIR)\bin\mcs /target:library -r:../../zoo-api/mono/ZMaps.dll -out:cgi-env/TestService.dll test.cs
+
+clean:
+	rm -rf cgi-env/*dll
Index: trunk/zoo-project/zoo-services/hello-r/cgi-env/RVoronoi.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/hello-r/cgi-env/RVoronoi.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/hello-r/cgi-env/RVoronoi.zcfg	(revision 917)
@@ -0,0 +1,56 @@
+[RVoronoi]
+ Title = Voronoi Diagram. 
+ Abstract = Computes the edges of Voronoi diagram for a set of data points.
+ Profile = urn:ogc:wps:1.0.0:voronoi
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = hello.R
+ serviceType = R
+ <DataInputs>
+  [InputPoints]
+   Title = Data points
+   Abstract = The set of data points.
+   minOccurs = 1
+   maxOccurs = 1
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://schemas.opengis.net/gml/3.1.0/base/feature.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://schemas.opengis.net/gml/3.1.0/base/feature.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Voronoi Diagram.
+   Abstract = JSON String / GML Entity of the Voronoi Diagram.
+   <ComplexOutput>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = image/png
+     useMapserver = true
+     msStyle = STYLE COLOR 125 0 105 OUTLINECOLOR 0 0 0 WIDTH 0.3 OPACITY 65 END
+    </Supported>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://schemas.opengis.net/gml/3.1.0/base/feature.xsd
+     useMapserver = true
+    </Supported>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://schemas.opengis.net/gml/3.1.0/base/feature.xsd
+     useMapserver = true
+    </Supported>
+   </ComplexOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/hello-r/cgi-env/failR.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/hello-r/cgi-env/failR.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/hello-r/cgi-env/failR.zcfg	(revision 917)
@@ -0,0 +1,28 @@
+[failR]
+ Title = HelloWorld Service in R
+ Abstract = Output and Hello Wolrd string
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = hello.R
+ serviceType = R
+ <DataInputs>
+  [S]
+   Title = Name
+   Abstract = The name to display in the hello message
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default />
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The resulting string
+   Abstract = The string created by service.
+   <LiteralOutput>
+     dataType = string
+    <Default />
+   </LiteralOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/hello-r/cgi-env/hello.R
===================================================================
--- trunk/zoo-project/zoo-services/hello-r/cgi-env/hello.R	(revision 917)
+++ trunk/zoo-project/zoo-services/hello-r/cgi-env/hello.R	(revision 917)
@@ -0,0 +1,61 @@
+source("minimal.r")
+
+hellor <- function(a,b,c) {
+    # Create a useless graph
+    cars <- c(1,2,3,4,5)
+    filePath <- paste(a[["main"]][["tmpPath"]],paste("cars",zoo[["conf"]][["lenv"]][["usid"]],".png",sep=""),sep="/")
+    png(filePath)
+    plot(cars)
+    quartzFonts(avenir = c("Avenir Book", "Avenir Black", "Avenir Book Oblique", "Avenir Black Oblique"))
+    par(family = 'avenir')
+    title("Hello from R World!")
+    dev.off()
+    # Set the result
+    zoo[["outputs"]][["Result"]][["value"]] <<- paste("Hello",b[["S"]][["value"]],"from the R World! (plot ref:",filePath,")",sep=" ")
+    # Update the main conf settings
+    zoo[["conf"]][["lenv"]][["message"]] <<- "Running from R world!"
+    # Return SERVICE_SUCCEEDEED
+    return(zoo[["SERVICE_SUCCEEDEED"]])
+}
+
+failR <- function(conf,inputs,outputs){
+    zoo[["conf"]][["lenv"]][["message"]] <<- ZOOTranslate("Failed running from R world!")
+    return(zoo[["SERVICE_FAILED"]])
+}
+
+voronoipolygons <- function(x,poly) {
+  require(deldir)
+  if (.hasSlot(x, 'coords')) {
+    crds <- x@coords  
+  } else crds <- x
+  bb = bbox(poly)
+  rw = as.numeric(t(bb))
+  z <- deldir(crds[,1], crds[,2],rw=rw)
+  w <- tile.list(z)
+  polys <- vector(mode='list', length=length(w)) 
+  require(sp)
+  finalCoordinates <- c()
+  for (i in seq(along=polys)) {
+    pcrds <- cbind(w[[i]]$x, w[[i]]$y)
+    pcrds <- rbind(pcrds, pcrds[1,])
+    finalCoordinates[[i]] <- i
+    polys[[i]] <- Polygons(list(Polygon(pcrds)), ID=as.character(i))
+  }
+  SP <- SpatialPolygons(polys)
+  voronoi <- SpatialPolygonsDataFrame(SP, data=data.frame(identifier=finalCoordinates))
+  return(voronoi)
+}
+
+RVoronoi <- function(conf,inputs,outputs){
+    require(rgdal)
+    require(rgeos)
+    message(names(inputs[["InputPoints"]]))
+    message(inputs[["InputPoints"]])
+    myGeoData <- readOGR(inputs[["InputPoints"]][["cache_file"]],layer=ogrListLayers(inputs[["InputPoints"]][["cache_file"]])[1], verbose = FALSE);
+    voronoiData <- voronoipolygons(myGeoData,myGeoData)
+    filePath <- paste(conf[["main"]][["tmpPath"]],paste("RBuffer_",zoo[["conf"]][["lenv"]][["usid"]],".shp",sep=""),sep="/")
+    writeOGR(voronoiData, dsn=filePath, layer="Voronoi", driver="ESRI Shapefile", verbose = FALSE)
+    zoo[["outputs"]][["Result"]][["storage"]] <<- filePath
+    return(zoo[["SERVICE_SUCCEEDEED"]])
+}
+
Index: trunk/zoo-project/zoo-services/hello-r/cgi-env/hellor.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/hello-r/cgi-env/hellor.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/hello-r/cgi-env/hellor.zcfg	(revision 917)
@@ -0,0 +1,28 @@
+[hellor]
+ Title = HelloWorld Service in R
+ Abstract = Output and Hello Wolrd string
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = hello.R
+ serviceType = R
+ <DataInputs>
+  [S]
+   Title = Name
+   Abstract = The name to display in the hello message
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default />
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The resulting string
+   Abstract = The string created by service.
+   <LiteralOutput>
+     dataType = string
+    <Default />
+   </LiteralOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 811)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 917)
@@ -95,4 +95,16 @@
 
 def extractInputs(conf,obj):
+    if obj.keys().count("cache_file"):
+        print >> sys.stderr,obj
+        geometry=[]
+        ds = osgeo.ogr.Open(obj["cache_file"])
+        lyr = ds.GetLayer(0)
+        feat = lyr.GetNextFeature()
+        while feat is not None:
+            geometry+=[feat.Clone()]
+            feat.Destroy()
+            feat = lyr.GetNextFeature()
+        ds.Destroy()
+        return geometry    
     if obj["mimeType"]=="application/json":
         return createLayerFromJson(conf,obj["value"])
Index: trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c
===================================================================
--- trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/ogr/base-vect-ops/service.c	(revision 917)
@@ -473,11 +473,11 @@
 	  {
 
-	    if( EQUAL(
+	    if( 
 #if GDAL_VERSION_MAJOR >=2
-		      poR->GetDriver(iDriver)->GetDescription()
-#else
-		      poR->GetDriver(iDriver)->GetName()
-#endif
-		      ,oDriver1) )
+		EQUAL(poR->GetDriver(iDriver)->GetDescription(),oDriver1)
+#else
+		EQUAL(poR->GetDriver(iDriver)->GetName(),oDriver1)
+#endif
+		)
 	      {
 		poDriver = poR->GetDriver(iDriver);
Index: trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c
===================================================================
--- trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/ogr/ogr2ogr/service.c	(revision 917)
@@ -96,4 +96,5 @@
 #endif
 {
+    char  *pszDialect = NULL;
     const char  *pszFormat = "ESRI Shapefile";
     const char  *pszDataSource = NULL;
@@ -155,5 +156,5 @@
       sprintf(serverAddress,"%s",tmpMap->value);
     }
-    
+
     tmpMap=NULL;
     char tmpurl[1024];
@@ -223,4 +224,9 @@
     if(tmpMap!=NULL && strncasecmp(tmpMap->value,"NULL",4)!=0){
       pszSQLStatement = tmpMap->value;
+    }
+
+    tmpMap=getMapFromMaps(inputs,"dialect","value");
+    if(tmpMap!=NULL){
+      pszDialect=strdup(tmpMap->value);
     }
 
@@ -360,11 +366,5 @@
 	  dfMaxSegmentLength = atof(tmpMap->value);
     }
-
-    /*tmpMap=NULL;
-    tmpMap=getMapFromMaps(inputs,"segmentize","value");
-    if(tmpMap!=NULL){
-	  dfMaxSegmentLength = atof(tmpMap->value);
-    }*/
-
+   
     tmpMap=NULL;
     tmpMap=getMapFromMaps(inputs,"InputDSN","value");
@@ -825,5 +825,5 @@
         
         poResultSet = poDS->ExecuteSQL( pszSQLStatement, poSpatialFilter, 
-                                        NULL );
+                                        pszDialect );
 
         if( poResultSet != NULL )
@@ -841,6 +841,13 @@
             }
             poDS->ReleaseResultSet( poResultSet );
-        }
-    }
+        }else{
+	  setMapInMaps(conf,"lenv","message","There was an error when running yoru SQL query.");
+	  if(pszDialect!=NULL)
+	    free(pszDialect);
+	  return SERVICE_FAILED;
+	}
+    }
+    if(pszDialect!=NULL)
+      free(pszDialect);
 
 /* -------------------------------------------------------------------- */
@@ -901,5 +908,6 @@
 
 #ifdef ZOO_SERVICE
-    outputs->content=createMap("value",(char*)pszwebDestData);
+    setMapInMaps(outputs,"OutputedDataSourceName","value",(char*)pszwebDestData);
+    //outputs->content=createMap("value",(char*)pszwebDestData);
 #endif
 
@@ -930,5 +938,5 @@
     fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
 
-    OGRCleanupAll();
+    //OGRCleanupAll();
     fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
 
@@ -939,4 +947,5 @@
     
 #ifdef ZOO_SERVICE
+    //sleep(10);
     return SERVICE_SUCCEEDED;
 #else
Index: trunk/zoo-project/zoo-services/ogr/tindex/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/ogr/tindex/Makefile	(revision 917)
+++ trunk/zoo-project/zoo-services/ogr/tindex/Makefile	(revision 917)
@@ -0,0 +1,14 @@
+ZRPATH=../../..
+include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
+CFLAGS=-DZOO_SERVICE ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+CC=gcc
+
+cgi-env/ogrtindex_service.zo: service.c $(DEP_LIBS)
+	g++ $(CFLAGS) $(CPPFLAGS) -shared -fpic $<  -o $@ ${GDAL_LIBS} -L${ZRPATH}/zoo-kernel/ -lzoo_service -lfcgi -L/usr/local/Cellar/gettext/0.19.8.1/lib/ -lintl
+
+install:
+	install -d ${CGI_DIR}/ogr/
+	install cgi-env/* ${CGI_DIR}/ogr/
+
+clean:
+	rm -f cgi-env/*zo
Index: trunk/zoo-project/zoo-services/ogr/tindex/cgi-env/Ogrtindex.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/ogr/tindex/cgi-env/Ogrtindex.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/ogr/tindex/cgi-env/Ogrtindex.zcfg	(revision 917)
@@ -0,0 +1,67 @@
+[Ogrtindex]
+ Title = Create a tileindex. 
+ Abstract = http://www.gdal.org/ogrtindex.html
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceType = C
+ serviceProvider = ogrtindex_service.zo
+ <MetaData>
+   title = My Demo
+ </MetaData>
+ <DataInputs>
+  [f]
+   Title = Format of the output data
+   Abstract = Select the output format.
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    DataType = string
+    <Default>
+     value = ESRI ShapeFile
+     AllowedValues = KML,geojson,ESRI Shapefile,csv
+    </Default>
+   </LiteralData>
+  [of]
+   Title = Format of the output data
+   Abstract = Select the output format.
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    DataType = string
+    <Default>
+     value = ESRI ShapeFile     
+     AllowedValues = KML,geojson,ESRI Shapefile,csv
+    </Default>
+    <Supported>
+     value = KML
+    </Supported>
+   </LiteralData>
+  [files]
+   Title = The input data source name
+   Abstract = The input data source name to use as source for convertion.
+   minOccurs = 1
+   maxOccurs = 1024
+   <LiteralData>
+    DataType = string
+    <Default />
+   </LiteralData>
+  [OutputName]
+   Title = The output data source name
+   Abstract = The output data name.
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    DataType = string
+    <Default />
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The resulting converted file
+   Abstract = The file name resulting of the convertion
+   <LiteralData>
+    DataType = string
+    <Default />
+   </LiteralData>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/ogr/tindex/service.c
===================================================================
--- trunk/zoo-project/zoo-services/ogr/tindex/service.c	(revision 917)
+++ trunk/zoo-project/zoo-services/ogr/tindex/service.c	(revision 917)
@@ -0,0 +1,1102 @@
+/******************************************************************************
+ *
+ * Project:  OpenGIS Simple Features Reference Implementation
+ * Purpose:  Program to generate a UMN MapServer compatible tile index for a
+ *           set of OGR data sources.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2002, Frank Warmerdam
+ * Copyright (c) 2007-2010, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * 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 "cpl_port.h"
+
+#include <cassert>
+#include <vector>
+
+#include "cpl_conv.h"
+#include "cpl_string.h"
+#include "ogr_api.h"
+#include "ogrsf_frmts.h"
+#include "ogr_p.h"
+#include "gdal_version.h"
+//#include "commonutils.h"
+#if GDAL_VERSION_MAJOR >= 2
+#include "gdal.h"
+#include "gdal_priv.h"
+#endif
+#ifdef ZOO_SERVICE
+#include "service.h"
+#include "service_internal.h"
+#endif
+
+CPL_CVSID("$Id$")
+
+#ifdef ZOO_SERVICE
+extern "C" {
+#endif
+
+typedef enum
+{
+    FORMAT_AUTO,
+    FORMAT_WKT,
+    FORMAT_EPSG,
+    FORMAT_PROJ
+} SrcSRSFormat;
+
+/************************************************************************/
+/*                               Usage()                                */
+/************************************************************************/
+
+static void Usage()
+
+{
+    printf("Usage: ogrtindex [-lnum n]... [-lname name]... [-f output_format]\n"
+           "                 [-write_absolute_path] [-skip_different_projection]\n"
+           "                 [-t_srs target_srs]\n"
+           "                 [-src_srs_name field_name] [-src_srs_format [AUTO|WKT|EPSG|PROJ]\n"
+           "                 [-accept_different_schemas]\n"
+           "                 output_dataset src_dataset...\n");
+    printf("\n");
+    printf("  -lnum n: Add layer number 'n' from each source file\n"
+           "           in the tile index.\n");
+    printf("  -lname name: Add the layer named 'name' from each source file\n"
+           "               in the tile index.\n");
+    printf("  -f output_format: Select an output format name.\n");
+    printf("  -tileindex field_name: The name to use for the dataset name.\n"
+           "                         Defaults to LOCATION.\n");
+    printf("  -write_absolute_path: Filenames are written with absolute paths.\n");
+    printf("  -skip_different_projection: Only layers with same projection ref \n"
+           "        as layers already inserted in the tileindex will be inserted.\n");
+    printf("  -accept_different_schemas: by default ogrtindex checks that all layers inserted\n"
+           "                             into the index have the same attribute schemas. If you\n"
+           "                             specify this option, this test will be disabled. Be aware that\n"
+           "                             resulting index may be incompatible with MapServer!\n");
+    printf(
+           "  - If -t_srs is specified, geometries of input files will be transformed to the desired\n"
+           "    target coordinate reference system.\n"
+           "    Note that using this option generates files that are NOT compatible with MapServer < 7.2.\n"
+           "  - Simple rectangular polygons are generated in the same coordinate reference system\n"
+           "    as the vectors, or in target reference system if the -t_srs option is used.\n");
+    printf("\n");
+    printf("If no -lnum or -lname arguments are given it is assumed that\n"
+           "all layers in source datasets should be added to the tile index\n"
+           "as independent records.\n");
+    exit(1);
+}
+
+/************************************************************************/
+/*                                main()                                */
+/************************************************************************/
+
+#ifdef ZOO_SERVICE
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Ogrtindex(maps*& conf,maps*& inputs,maps*& outputs)
+#else
+  MAIN_START(nArgc, papszArgv)
+#endif
+{
+  FILE* log=fopen("/tmp/error.log","w+");
+  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+  fflush(log);
+  //return SERVICE_FAILED;
+    // Check strict compilation and runtime library version as we use C++ API.
+#ifdef ZOO_SERVICE
+  if( !GDAL_CHECK_VERSION("ogrtindex") )
+      {
+	setMapInMaps(conf,"lenv","message",_("Compilation and runtime library versions differ"));
+	return SERVICE_FAILED;
+      }
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+#else
+    if( !GDAL_CHECK_VERSION(papszArgv[0]) )
+      exit(1);
+#endif
+/* -------------------------------------------------------------------- */
+/*      Register format(s).                                             */
+/* -------------------------------------------------------------------- */
+    OGRRegisterAll();
+
+/* -------------------------------------------------------------------- */
+/*      Processing command line arguments.                              */
+/* -------------------------------------------------------------------- */
+    int nFirstSourceDataset = -1;
+    bool bLayersWildcarded = true;
+    const char *pszFormat = nullptr;
+    const char *pszTileIndexField = "LOCATION";
+    const char *pszOutputName = nullptr;
+    bool write_absolute_path = false;
+    bool skip_different_projection = false;
+    char* current_path = nullptr;
+    bool accept_different_schemas = false;
+    bool bFirstWarningForNonMatchingAttributes = true;
+    const char *pszTargetSRS = "";
+    bool bSetTargetSRS = false;
+    const char* pszSrcSRSName = nullptr;
+    int i_SrcSRSName = -1;
+    bool bSrcSRSFormatSpecified = false;
+    SrcSRSFormat eSrcSRSFormat = FORMAT_AUTO;
+    size_t nMaxFieldSize = 254;
+
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+#ifdef ZOO_SERVICE
+      // f / of
+      map* tmpMap=getMapFromMaps(inputs,"f","value");
+      if(tmpMap==NULL)
+	tmpMap=getMapFromMaps(inputs,"of","value");
+      if(tmpMap!=NULL)
+	pszFormat = zStrdup(tmpMap->value);
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+
+      // write_absolute_path
+      tmpMap=getMapFromMaps(inputs,"write_absolute_path","value");
+      if(tmpMap!=NULL && strncasecmp(tmpMap->value,"true",4)==0)
+	write_absolute_path = true;
+      // skip_different_projection
+      tmpMap=getMapFromMaps(inputs,"skip_different_projection","value");
+      if(tmpMap!=NULL && strncasecmp(tmpMap->value,"true",4)==0)
+	skip_different_projection = true;
+      // accept_different_schemas
+      tmpMap=getMapFromMaps(inputs,"accept_different_schemas","value");
+      if(tmpMap!=NULL && strncasecmp(tmpMap->value,"true",4)==0)
+	accept_different_schemas = true;
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // tileindex
+      tmpMap=getMapFromMaps(inputs,"tileindex","value");
+      if(tmpMap!=NULL)
+	pszTileIndexField = zStrdup(tmpMap->value);
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // lname / lnum
+      tmpMap=getMapFromMaps(inputs,"lname","value");
+      if(tmpMap==NULL)
+	tmpMap=getMapFromMaps(inputs,"lnum","value");
+      if(tmpMap!=NULL)
+	bLayersWildcarded = false;
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      //dumpMaps(inputs);
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // t_srs
+      tmpMap=getMapFromMaps(inputs,"t_srs","value");
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      if(tmpMap!=NULL){
+	pszTargetSRS = zStrdup(tmpMap->value);
+	bSetTargetSRS = true;
+      }
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // src_srs_name
+      //dumpMaps(inputs);
+      tmpMap=getMapFromMaps(inputs,"src_srs_name","value");
+      if(tmpMap!=NULL){
+	pszSrcSRSName = zStrdup(tmpMap->value);
+      }
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // src_srs_format
+      tmpMap=getMapFromMaps(inputs,"src_srs_format","value");
+      if(tmpMap!=NULL){
+	bSrcSRSFormatSpecified = true;
+	const char* pszSRSFormat = zStrdup(tmpMap->value);
+	if( EQUAL(pszSRSFormat, "AUTO") )
+	  eSrcSRSFormat = FORMAT_AUTO;
+	else if( EQUAL(pszSRSFormat, "WKT") )
+	  eSrcSRSFormat = FORMAT_WKT;
+	else if( EQUAL(pszSRSFormat, "EPSG") )
+	  eSrcSRSFormat = FORMAT_EPSG;
+	else if( EQUAL(pszSRSFormat, "PROJ") )
+	  eSrcSRSFormat = FORMAT_PROJ;	
+      }
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      // OutputName
+      tmpMap=getMapFromMaps(inputs,"OutputName","value");
+      if(tmpMap!=NULL){
+	pszOutputName = zStrdup(tmpMap->value);
+      }
+      nFirstSourceDataset = 0;
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+#else      
+    for( int iArg = 1; iArg < nArgc; iArg++ )
+    {
+        if( EQUAL(papszArgv[iArg], "--utility_version") )
+        {
+            printf("%s was compiled against GDAL %s and "
+                   "is running against GDAL %s\n",
+                   papszArgv[0], GDAL_RELEASE_NAME,
+                   GDALVersionInfo("RELEASE_NAME"));
+            return 0;
+        }
+        else if( iArg < nArgc-1 &&
+                 (EQUAL(papszArgv[iArg],"-f") || EQUAL(papszArgv[iArg],"-of")) )
+        {
+            pszFormat = papszArgv[++iArg];
+        }
+        else if( EQUAL(papszArgv[iArg],"-write_absolute_path"))
+        {
+            write_absolute_path = true;
+        }
+        else if( EQUAL(papszArgv[iArg],"-skip_different_projection"))
+        {
+            skip_different_projection = true;
+        }
+        else if( EQUAL(papszArgv[iArg],"-accept_different_schemas"))
+        {
+            accept_different_schemas = true;
+        }
+        else if( iArg < nArgc-1 && EQUAL(papszArgv[iArg],"-tileindex") )
+        {
+            pszTileIndexField = papszArgv[++iArg];
+        }
+        else if( EQUAL(papszArgv[iArg],"-lnum")
+                 || EQUAL(papszArgv[iArg],"-lname") )
+        {
+            iArg++;
+            bLayersWildcarded = false;
+        }
+        else if( iArg < nArgc-1 && strcmp(papszArgv[iArg],"-t_srs") == 0 )
+        {
+            pszTargetSRS = papszArgv[++iArg];
+            bSetTargetSRS = true;
+        }
+        else if( iArg < nArgc-1 &&
+                 strcmp(papszArgv[iArg], "-src_srs_name") == 0 )
+        {
+            pszSrcSRSName = papszArgv[++iArg];
+        }
+        else if( iArg < nArgc-1 &&
+                 strcmp(papszArgv[iArg], "-src_srs_format") == 0 )
+        {
+            bSrcSRSFormatSpecified = true;
+            const char* pszSRSFormat = papszArgv[++iArg];
+            if( EQUAL(pszSRSFormat, "AUTO") )
+                eSrcSRSFormat = FORMAT_AUTO;
+            else if( EQUAL(pszSRSFormat, "WKT") )
+                eSrcSRSFormat = FORMAT_WKT;
+            else if( EQUAL(pszSRSFormat, "EPSG") )
+                eSrcSRSFormat = FORMAT_EPSG;
+            else if( EQUAL(pszSRSFormat, "PROJ") )
+                eSrcSRSFormat = FORMAT_PROJ;
+        }
+        else if( papszArgv[iArg][0] == '-' )
+        {
+            Usage();
+        }
+        else if( pszOutputName == nullptr )
+        {
+            pszOutputName = papszArgv[iArg];
+        }
+        else if( nFirstSourceDataset == -1 )
+        {
+            nFirstSourceDataset = iArg;
+        }
+    }
+#endif
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+    if( pszOutputName == nullptr || nFirstSourceDataset == -1 )
+        Usage();
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+
+    if( bSrcSRSFormatSpecified && pszSrcSRSName == nullptr )
+    {
+        fprintf(log,
+                "-src_srs_name must be specified when -src_srs_format is "
+                "specified.\n");
+        Usage();
+    }
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+
+/* -------------------------------------------------------------------- */
+/*      Create and validate target SRS if given.                        */
+/* -------------------------------------------------------------------- */
+    OGRSpatialReference* poTargetSRS = nullptr;
+    if( bSetTargetSRS )
+    {
+        if( skip_different_projection )
+        {
+            fprintf(log,
+                    "Warning : -skip_different_projection does not apply "
+                    "when -t_srs is requested.\n");
+        }
+        poTargetSRS = new OGRSpatialReference();
+        // coverity[tainted_data]
+        if( poTargetSRS->SetFromUserInput( pszTargetSRS ) != CE_None )
+        {
+            delete poTargetSRS;
+            fprintf(log, "Invalid target SRS `%s'.\n",
+                    pszTargetSRS);
+            exit(1);
+        }
+    }
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+
+/* -------------------------------------------------------------------- */
+/*      Try to open as an existing dataset for update access.           */
+/* -------------------------------------------------------------------- */
+    GDALDataset *poDstDS = reinterpret_cast<GDALDataset*>(
+        OGROpen(pszOutputName, TRUE, nullptr));
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+
+/* -------------------------------------------------------------------- */
+/*      If that failed, find the driver so we can create the tile index.*/
+/* -------------------------------------------------------------------- */
+    OGRLayer *poDstLayer = nullptr;
+    int                      nArgc;
+
+    fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+    fflush(log);
+    if( poDstDS == nullptr )
+    {
+        CPLString osFormat;
+	
+	OGRSFDriverRegistrar     *poR = OGRSFDriverRegistrar::GetRegistrar();
+        GDALDriver              *poDriver = NULL;
+        int                      iDriver;
+	
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+        for( iDriver = 0;
+             iDriver < poR->GetDriverCount() && poDriver == NULL;
+             iDriver++ )
+        {
+            if( EQUAL(poR->GetDriver(iDriver)->GetDescription(),pszFormat) )
+            {
+	      osFormat=pszFormat;
+                poDriver = poR->GetDriver(iDriver);
+            }
+        }
+
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+        if( poDriver == NULL )
+        {
+            fprintf( log, "Unable to find driver `%s'.\n", pszFormat );
+            fprintf( log, "The following drivers are available:\n" );
+
+            for( iDriver = 0; iDriver < poR->GetDriverCount(); iDriver++ )
+            {
+                fprintf( log, "  -> `%s'\n", poR->GetDriver(iDriver)->GetDescription() );
+            }
+#ifdef ZOO_SERVICE
+	    setMapInMaps(conf,"lenv","message",_("Unable to find driver!"));	    
+	    return SERVICE_FAILED;
+#else
+            exit( 1 );
+#endif
+        }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+
+	/*        if( !CPLTestBool( CSLFetchNameValueDef(poDriver->GetMetadata(), GDAL_DCAP_CREATE, "FALSE") ) )
+        {
+            fprintf( log, "%s driver does not support data source creation.\n",
+                    pszFormat );
+#ifdef ZOO_SERVICE
+	    setMapInMaps(conf,"lenv","message",_("This driver does not support data source creation!"));	    
+	    return SERVICE_FAILED;
+#else
+            exit( 1 );
+#endif
+}*/
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+
+/* -------------------------------------------------------------------- */
+/*      Now create it.                                                  */
+/* -------------------------------------------------------------------- */
+
+        poDstDS = reinterpret_cast<GDALDataset*>(
+            GDALCreate(poDriver, pszOutputName, 0, 0, 0, GDT_Unknown, nullptr));
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+        if( poDstDS == nullptr )
+        {
+            fprintf(log, "%s driver failed to create %s\n",
+                    osFormat.c_str(), pszOutputName);
+#ifdef ZOO_SERVICE
+	    setMapInMaps(conf,"lenv","message",_("This driver failed to create!"));
+	    return SERVICE_FAILED;
+#else
+            exit( 1 );
+#endif
+        }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+
+        if( poDstDS->GetLayerCount() == 0 )
+        {
+#ifndef ZOO_SERVICE
+	  if( nFirstSourceDataset < nArgc &&
+	      papszArgv[nFirstSourceDataset][0] == '-' )
+            {
+	      nFirstSourceDataset++;
+	    }
+#else
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+	  map* lengthMap=getMapFromMaps(inputs,"files","length");
+	  maps* tmpMaps=getMaps(inputs,"files");
+	  if(lengthMap!=NULL)
+	    nArgc=atoi(lengthMap->value);
+	  else
+	    nArgc=1;
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+#endif	  
+            OGRSpatialReference* poSrcSpatialRef = nullptr;
+            if( bSetTargetSRS )
+            {
+                // Fetches the SRS from target SRS (if set), or from the SRS of
+                // the first layer and use it when creating the
+                // tileindex layer.
+                poSrcSpatialRef = poTargetSRS->Clone();
+            }
+            else if( nFirstSourceDataset < nArgc )
+            {
+#ifdef ZOO_SERVICE
+	  fprintf(log,"**** %s %d %s \n",__FILE__,__LINE__,nFirstSourceDataset);
+	  fflush(log);
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+	  tmpMap=getMapArray(tmpMaps->content,"value",0);
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+	  //dumpMap(tmpMap);
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+#endif
+	  GDALDataset* poDS =
+	    reinterpret_cast<GDALDataset*>(
+#ifndef ZOO_SERVICE
+                    OGROpen(papszArgv[nFirstSourceDataset], FALSE, nullptr)
+#else
+                    OGROpen(tmpMap->value, FALSE, nullptr)
+#endif
+	    );
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+                if( poDS != nullptr )
+                {
+                    for( int iLayer = 0;
+                         iLayer < poDS->GetLayerCount();
+                         iLayer++ )
+                    {
+                        bool bRequested = bLayersWildcarded;
+                        OGRLayer *poLayer = poDS->GetLayer(iLayer);
+
+                        if( !bRequested )
+                            continue;
+
+                        if( poLayer->GetSpatialRef() )
+                            poSrcSpatialRef = poLayer->GetSpatialRef()->Clone();
+                        break;
+                    }
+                }
+
+                GDALClose(poDS);
+            }
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+
+            poDstLayer = poDstDS->CreateLayer("tileindex", poSrcSpatialRef);
+
+            OGRFieldDefn oLocation(pszTileIndexField, OFTString);
+            oLocation.SetWidth(200);
+            poDstLayer->CreateField(&oLocation);
+
+            if( pszSrcSRSName != nullptr )
+            {
+                OGRFieldDefn oSrcSRSNameField(pszSrcSRSName, OFTString);
+                poDstLayer->CreateField(&oSrcSRSNameField);
+            }
+
+            if( poSrcSpatialRef )
+                poSrcSpatialRef->Release();
+	  fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	  fflush(log);
+        }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+    }
+
+/* -------------------------------------------------------------------- */
+/*      Identify target layer and field.                                */
+/* -------------------------------------------------------------------- */
+
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+    poDstLayer = poDstDS->GetLayer(0);
+    if( poDstLayer == nullptr )
+    {
+        fprintf(log, "Can't find any layer in output tileindex!\n");
+        exit(1);
+    }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+
+    const int iTileIndexField =
+        poDstLayer->GetLayerDefn()->GetFieldIndex(pszTileIndexField);
+    if( iTileIndexField == -1 )
+    {
+        fprintf(log, "Can't find %s field in tile index dataset.\n",
+                pszTileIndexField);
+        exit(1);
+    }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+
+    if( pszSrcSRSName != nullptr )
+        i_SrcSRSName = poDstLayer->GetLayerDefn()->GetFieldIndex(pszSrcSRSName);
+
+    OGRFeatureDefn* poFeatureDefn = nullptr;
+
+    // Load in memory existing file names in SHP.
+    char **existingLayersTab = nullptr;
+    OGRSpatialReference* alreadyExistingSpatialRef = nullptr;
+    bool alreadyExistingSpatialRefValid = false;
+    const int nExistingLayers = static_cast<int>(poDstLayer->GetFeatureCount());
+    if( nExistingLayers )
+    {
+        existingLayersTab = static_cast<char **>(
+            CPLMalloc(nExistingLayers * sizeof(char*)));
+        for( int i = 0; i < nExistingLayers; i++ )
+        {
+            OGRFeature* feature = poDstLayer->GetNextFeature();
+            existingLayersTab[i] =
+                CPLStrdup(feature->GetFieldAsString( iTileIndexField));
+            if( i == 0 )
+            {
+                char* filename = CPLStrdup(existingLayersTab[i]);
+                // j used after for.
+                int j = static_cast<int>(strlen(filename)) - 1;
+                for( ; j >= 0; j-- )
+                {
+                    if( filename[j] == ',' )
+                        break;
+                }
+                GDALDataset *poDS = nullptr;
+                if( j >= 0 )
+                {
+                    const int iLayer = atoi(filename + j + 1);
+                    filename[j] = 0;
+                    poDS = reinterpret_cast<GDALDataset *>(
+                        OGROpen(filename, FALSE, nullptr));
+                    if( poDS != nullptr )
+                    {
+                        OGRLayer *poLayer = poDS->GetLayer(iLayer);
+                        if( poLayer )
+                        {
+                            alreadyExistingSpatialRefValid = true;
+                            alreadyExistingSpatialRef =
+                                poLayer->GetSpatialRef() ?
+                                poLayer->GetSpatialRef()->Clone() : nullptr;
+
+                            if( poFeatureDefn == nullptr )
+                                poFeatureDefn =
+                                    poLayer->GetLayerDefn()->Clone();
+                        }
+                        GDALClose(poDS);
+                    }
+                }
+            }
+        }
+    }
+
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+    if( write_absolute_path )
+    {
+        current_path = CPLGetCurrentDir();
+        if( current_path == nullptr )
+        {
+            fprintf(log,
+                    "This system does not support the CPLGetCurrentDir call. "
+                    "The option -write_absolute_path will have no effect\n");
+            write_absolute_path = false;
+        }
+    }
+	fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+	fflush(log);
+/* ==================================================================== */
+/*      Process each input datasource in turn.                          */
+/* ==================================================================== */
+#ifdef ZOO_SERVICE
+    maps* tmpMaps=getMaps(inputs,"files");
+    nFirstSourceDataset=0;
+#endif
+    for( ; nFirstSourceDataset < nArgc; nFirstSourceDataset++ )
+    {
+#ifndef ZOO_SERVICE
+      if( papszArgv[nFirstSourceDataset][0] == '-' )
+        {
+            nFirstSourceDataset++;
+            continue;
+        }
+#else
+      tmpMap=getMapArray(tmpMaps->content,"value",nFirstSourceDataset);
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+      //dumpMap(tmpMap);
+      fprintf(log,"**** %s %d \n",__FILE__,__LINE__);
+      fflush(log);
+
+#endif
+      char* fileNameToWrite = nullptr;
+      VSIStatBuf sStatBuf;
+      if( write_absolute_path &&
+#ifdef ZOO_SERVICE
+            CPLIsFilenameRelative( tmpMap->value ) &&
+            VSIStat( tmpMap->value, &sStatBuf ) == 0
+#else
+            CPLIsFilenameRelative( papszArgv[nFirstSourceDataset] ) &&
+            VSIStat( papszArgv[nFirstSourceDataset], &sStatBuf ) == 0	    
+#endif
+	    )
+        {
+            fileNameToWrite =
+                CPLStrdup(CPLProjectRelativeFilename(
+						     current_path,
+#ifdef ZOO_SERVICE
+						     tmpMap->value
+#else
+						     papszArgv[nFirstSourceDataset]
+#endif
+						     ));
+        }
+        else
+        {
+#ifdef ZOO_SERVICE
+	  fileNameToWrite = CPLStrdup(tmpMap->value);
+#else
+	  fileNameToWrite = CPLStrdup(papszArgv[nFirstSourceDataset]);
+#endif
+        }
+
+        GDALDataset *poDS = reinterpret_cast<GDALDataset*>(
+							   OGROpen(
+#ifdef ZOO_SERVICE
+								   tmpMap->value
+#else
+								   papszArgv[nFirstSourceDataset]
+#endif		    
+								   ,
+								   FALSE,
+								   nullptr )
+							   );
+
+        if( poDS == nullptr )
+        {
+	  fprintf(log, "Failed to open dataset %s, skipping.\n",
+#ifndef ZOO_SERVICE
+		  papszArgv[nFirstSourceDataset]
+#else
+		  tmpMap->value
+#endif
+		  );
+            CPLFree(fileNameToWrite);
+            continue;
+        }
+
+/* -------------------------------------------------------------------- */
+/*      Check all layers, and see if they match requests.               */
+/* -------------------------------------------------------------------- */
+        for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
+        {
+            bool bRequested = bLayersWildcarded;
+            OGRLayer *poLayer = poDS->GetLayer(iLayer);
+
+#ifndef ZOO_SERVICE
+            for( int iArg = 1; iArg < nArgc && !bRequested; iArg++ )
+            {
+                if( EQUAL(papszArgv[iArg], "-lnum")
+                    && atoi(papszArgv[iArg+1]) == iLayer )
+                    bRequested = true;
+                else if( EQUAL(papszArgv[iArg], "-lname" )
+                         && EQUAL(papszArgv[iArg+1],
+                                  poLayer->GetLayerDefn()->GetName()) )
+                    bRequested = true;
+            }
+#endif
+	    
+            if( !bRequested )
+                continue;
+
+            // Checks that the layer is not already in tileindex.
+            int i = 0;  // Used after for.
+            for( ; i < nExistingLayers; i++ )
+            {
+                // TODO(schwehr): Move this off of the stack.
+                char szLocation[5000] = {};
+                snprintf(szLocation, sizeof(szLocation), "%s,%d",
+                         fileNameToWrite, iLayer);
+                if( EQUAL(szLocation, existingLayersTab[i]) )
+                {
+                    fprintf(log, "Layer %d of %s is already in tileindex. "
+                            "Skipping it.\n",
+                            iLayer, szLocation);
+                    break;
+                }
+            }
+            if( i != nExistingLayers )
+            {
+                continue;
+            }
+
+            OGRSpatialReference* spatialRef = poLayer->GetSpatialRef();
+            // If not set target srs, test that the current file uses same
+            // projection as others.
+            if( !bSetTargetSRS )
+            {
+                if( alreadyExistingSpatialRefValid )
+                {
+                    if( (spatialRef != nullptr &&
+                         alreadyExistingSpatialRef != nullptr &&
+                        spatialRef->IsSame(alreadyExistingSpatialRef) ==
+                          FALSE) ||
+                        ((spatialRef != nullptr) !=
+                        (alreadyExistingSpatialRef != nullptr)) )
+                    {
+                        fprintf(
+                            log,
+                            "Warning : layer %d of %s is not using the same "
+                            "projection system as other files in the "
+                            "tileindex. This may cause problems when using it "
+                            "in MapServer for example.%s\n",
+                            iLayer,
+#ifdef ZOO_SERVICE
+			    tmpMap->value
+#else
+			    papszArgv[nFirstSourceDataset]
+#endif
+			    ,
+                            skip_different_projection ? " Skipping it" : "");
+                        if( skip_different_projection )
+                        {
+                            continue;
+                        }
+                    }
+                }
+                else
+                {
+                    alreadyExistingSpatialRefValid = true;
+                    alreadyExistingSpatialRef =
+                        spatialRef ? spatialRef->Clone() : nullptr;
+                }
+            }
+
+/* -------------------------------------------------------------------- */
+/*      Check if all layers in dataset have the same attributes schema. */
+/* -------------------------------------------------------------------- */
+            if( poFeatureDefn == nullptr )
+            {
+                poFeatureDefn = poLayer->GetLayerDefn()->Clone();
+            }
+            else if( !accept_different_schemas )
+            {
+                OGRFeatureDefn* poFeatureDefnCur = poLayer->GetLayerDefn();
+                assert(nullptr != poFeatureDefnCur);
+
+                const int fieldCount = poFeatureDefnCur->GetFieldCount();
+
+                if( fieldCount != poFeatureDefn->GetFieldCount())
+                {
+                    fprintf( log, "Number of attributes of layer %s of %s "
+                             "does not match ... skipping it.\n",
+                             poLayer->GetLayerDefn()->GetName(),
+#ifdef ZOO_SERVICE
+			     tmpMap->value
+#else		     
+                             papszArgv[nFirstSourceDataset]
+#endif			     
+			     );
+                    if( bFirstWarningForNonMatchingAttributes )
+                    {
+                        fprintf(
+                            log, "Note : you can override this "
+                            "behaviour with -accept_different_schemas option\n"
+                            "but this may result in a tileindex incompatible "
+                            "with MapServer\n");
+                        bFirstWarningForNonMatchingAttributes = false;
+                    }
+                    continue;
+                }
+
+                bool bSkip = false;
+                for( int fn = 0; fn < poFeatureDefnCur->GetFieldCount(); fn++ )
+                {
+                    OGRFieldDefn* poField = poFeatureDefn->GetFieldDefn(fn);
+                    OGRFieldDefn* poFieldCur =
+                        poFeatureDefnCur->GetFieldDefn(fn);
+
+                    // XXX - Should those pointers be checked against NULL?
+                    assert(nullptr != poField);
+                    assert(nullptr != poFieldCur);
+
+                    if( poField->GetType() != poFieldCur->GetType()
+                        || poField->GetWidth() != poFieldCur->GetWidth()
+                        || poField->GetPrecision() != poFieldCur->GetPrecision()
+                        || !EQUAL( poField->GetNameRef(),
+                                   poFieldCur->GetNameRef() ) )
+                    {
+                        fprintf(
+                            log, "Schema of attributes of layer %s of %s "
+                            "does not match. Skipping it.\n",
+                            poLayer->GetLayerDefn()->GetName(),
+#ifdef ZOO_SERVICE
+			    tmpMap->value
+#else		     
+			    papszArgv[nFirstSourceDataset]
+#endif
+				);
+                        if( bFirstWarningForNonMatchingAttributes )
+                        {
+                            fprintf(
+                                log, "Note : you can override this "
+                                "behaviour with -accept_different_schemas "
+                                "option,\nbut this may result in a tileindex "
+                                "incompatible with MapServer\n");
+                            bFirstWarningForNonMatchingAttributes = false;
+                        }
+                        bSkip = true;
+                        break;
+                    }
+                }
+
+                if( bSkip )
+                    continue;
+            }
+
+/* -------------------------------------------------------------------- */
+/*      Get layer extents, and create a corresponding polygon           */
+/*      geometry.                                                       */
+/* -------------------------------------------------------------------- */
+            OGREnvelope sExtents;
+
+            if( poLayer->GetExtent( &sExtents, TRUE ) != OGRERR_NONE )
+            {
+                fprintf(log,
+                        "GetExtent() failed on layer %s of %s, skipping.\n",
+                        poLayer->GetLayerDefn()->GetName(),
+#ifdef ZOO_SERVICE
+			tmpMap->value
+#else		     
+			papszArgv[nFirstSourceDataset]
+#endif
+			);
+                continue;
+            }
+
+            OGRLinearRing oRing;
+            oRing.addPoint(sExtents.MinX, sExtents.MinY);
+            oRing.addPoint(sExtents.MinX, sExtents.MaxY);
+            oRing.addPoint(sExtents.MaxX, sExtents.MaxY);
+            oRing.addPoint(sExtents.MaxX, sExtents.MinY);
+            oRing.addPoint(sExtents.MinX, sExtents.MinY);
+
+            OGRPolygon oRegion;
+            oRegion.addRing(&oRing);
+
+            // If set target srs, do the forward transformation of all points.
+            if( bSetTargetSRS && spatialRef != nullptr )
+            {
+                OGRCoordinateTransformation* poCT = nullptr;
+                if( !spatialRef->IsSame(poTargetSRS) )
+                {
+                    poCT = OGRCreateCoordinateTransformation(spatialRef,
+                                                             poTargetSRS);
+                    if( poCT == nullptr ||
+                        oRegion.transform(poCT) == OGRERR_FAILURE )
+                    {
+                        char* pszSourceWKT = nullptr;
+                        spatialRef->exportToWkt(&pszSourceWKT);
+                        fprintf(
+                            log,
+                            "Warning : unable to transform points from source "
+                            "SRS `%s' to target SRS `%s'\n"
+                            "for file `%s' - file skipped\n",
+                            pszSourceWKT, pszTargetSRS,
+#ifdef ZOO_SERVICE
+			    tmpMap->value
+#else		     
+			    papszArgv[nFirstSourceDataset]
+#endif
+				);
+                        CPLFree(pszSourceWKT);
+                        delete poCT;
+                        continue;
+                    }
+                    delete poCT;
+                }
+            }
+
+/* -------------------------------------------------------------------- */
+/*      Add layer to tileindex.                                         */
+/* -------------------------------------------------------------------- */
+            OGRFeature oTileFeat(poDstLayer->GetLayerDefn());
+
+            // TODO(schwehr): Move this off of the stack.
+            char szLocation[5000] = {};
+            snprintf(szLocation, sizeof(szLocation), "%s,%d",
+                     fileNameToWrite, iLayer);
+            oTileFeat.SetGeometry(&oRegion);
+            oTileFeat.SetField(iTileIndexField, szLocation);
+
+            if( i_SrcSRSName >= 0 && spatialRef != nullptr )
+            {
+                const char* pszAuthorityCode =
+                    spatialRef->GetAuthorityCode(nullptr);
+                const char* pszAuthorityName =
+                    spatialRef->GetAuthorityName(nullptr);
+                char* pszWKT = nullptr;
+                spatialRef->exportToWkt(&pszWKT);
+                if( eSrcSRSFormat == FORMAT_AUTO )
+                {
+                    if( pszAuthorityName != nullptr &&
+                        pszAuthorityCode != nullptr )
+                    {
+                        oTileFeat.SetField(i_SrcSRSName,
+                            CPLSPrintf("%s:%s",
+                                       pszAuthorityName, pszAuthorityCode));
+                    }
+                    else if( nMaxFieldSize == 0 ||
+                            strlen(pszWKT) <= nMaxFieldSize )
+                    {
+                        oTileFeat.SetField(i_SrcSRSName, pszWKT);
+                    }
+                    else
+                    {
+                        char* pszProj4 = nullptr;
+                        if( spatialRef->exportToProj4(&pszProj4) ==
+                              OGRERR_NONE )
+                        {
+                            oTileFeat.SetField(i_SrcSRSName, pszProj4);
+                            CPLFree(pszProj4);
+                        }
+                        else
+                        {
+                            oTileFeat.SetField(i_SrcSRSName, pszWKT);
+                        }
+                    }
+                }
+                else if( eSrcSRSFormat == FORMAT_WKT )
+                {
+                    if( nMaxFieldSize == 0 ||
+                        strlen(pszWKT) <= nMaxFieldSize )
+                    {
+                        oTileFeat.SetField(i_SrcSRSName, pszWKT);
+                    }
+                    else
+                    {
+                        fprintf(
+                            log,
+                            "Cannot write WKT for file %s as it is too long!\n",
+                            fileNameToWrite);
+                    }
+                }
+                else if( eSrcSRSFormat == FORMAT_PROJ )
+                {
+                    char* pszProj4 = nullptr;
+                    if( spatialRef->exportToProj4(&pszProj4) == OGRERR_NONE )
+                    {
+                        oTileFeat.SetField(i_SrcSRSName, pszProj4);
+                        CPLFree(pszProj4);
+                    }
+                }
+                else if( eSrcSRSFormat == FORMAT_EPSG )
+                {
+                    if( pszAuthorityName != nullptr &&
+                        pszAuthorityCode != nullptr )
+                        oTileFeat.SetField(i_SrcSRSName,
+                            CPLSPrintf("%s:%s",
+                                       pszAuthorityName, pszAuthorityCode));
+                }
+                CPLFree(pszWKT);
+            }
+            if( poDstLayer->CreateFeature(&oTileFeat) != OGRERR_NONE )
+            {
+                fprintf(log,
+                        "Failed to create feature on tile index. "
+                        "Terminating.");
+                GDALClose(poDstDS);
+                exit(1);
+            }
+        }
+
+/* -------------------------------------------------------------------- */
+/*      Cleanup this data source.                                       */
+/* -------------------------------------------------------------------- */
+        CPLFree(fileNameToWrite);
+        GDALClose(poDS);
+    }
+
+/* -------------------------------------------------------------------- */
+/*      Close tile index and clear buffers.                             */
+/* -------------------------------------------------------------------- */
+    GDALClose(poDstDS);
+    OGRFeatureDefn::DestroyFeatureDefn(poFeatureDefn);
+
+    if( alreadyExistingSpatialRef != nullptr )
+        alreadyExistingSpatialRef->Release();
+    delete poTargetSRS;
+
+    CPLFree(current_path);
+
+    if( nExistingLayers )
+    {
+        for( int i = 0; i < nExistingLayers; i++ )
+        {
+            CPLFree(existingLayersTab[i]);
+        }
+        CPLFree(existingLayersTab);
+    }
+
+    OGRCleanupAll();
+#ifdef ZOO_SERVICE
+    //setMapInMaps(outputs,"Result","generated_file",pszOutputName);
+    setMapInMaps(outputs,"Result","value",pszOutputName);
+    return  SERVICE_SUCCEEDED;
+#else
+    return 0;
+#endif
+}
+#ifndef ZOO_SERVICE
+MAIN_END
+#endif
+  
+#ifdef ZOO_SERVICE
+}
+#endif
Index: trunk/zoo-project/zoo-services/utils/hpc/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/Makefile	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/Makefile	(revision 917)
@@ -0,0 +1,14 @@
+ZRPATH=../../..
+include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
+CFLAGS=-I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+
+cgi-env/wps_hpc.zo: service.c service2.c
+	g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_hpc.zo service.c service2.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/sshapi.o ${HPCLDFLAGS}
+
+install:
+	install -d ${CGI_DIR}
+	install cgi-env/*.zcfg ${CGI_DIR}/
+	install cgi-env/*.zo ${CGI_DIR}/
+
+clean:
+	rm -f cgi-env/wps_hpc.zo
Index: trunk/zoo-project/zoo-services/utils/hpc/cgi-env/DeleteData.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/cgi-env/DeleteData.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/cgi-env/DeleteData.zcfg	(revision 917)
@@ -0,0 +1,50 @@
+[DeleteData]
+ Title = Delete the data associated with an input or an output
+ Abstract = Delete the data associated with an input or an output
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = wps_hpc.zo
+ serviceType = C
+ <DataInputs>
+  [jobid]
+   Title = the image
+   Abstract = The image to process
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default>
+    </Default>
+   </LiteralData>
+  [filename]
+   Title = the image
+   Abstract = The image to process
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default>
+    </Default>
+   </LiteralData>
+  [ioname]
+   Title = the input / output name
+   Abstract = the input / output name
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default>
+    </Default>
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The resulting string
+   Abstract = The resulting message string.
+   <LiteralOutput>
+    DataType = string
+    <Default>
+    </Default>
+   </LiteralOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC.zcfg	(revision 917)
@@ -0,0 +1,30 @@
+[FinalizeHPC]
+ Title = Start phase 3 of HPC execution
+ Abstract = Unblock the ZOO-Kernel awaiting for a remote job execution 
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = wps_hpc.zo
+ serviceType = C
+ <DataInputs>
+  [JobId]
+   Title = the image
+   Abstract = The image to process
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default>
+    </Default>
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The hello string
+   Abstract = The Hello message string.
+   <LiteralOutput>
+    DataType = string
+    <Default>
+    </Default>
+   </LiteralOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC1.zcfg
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC1.zcfg	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/cgi-env/FinalizeHPC1.zcfg	(revision 917)
@@ -0,0 +1,30 @@
+[FinalizeHPC1]
+ Title = Start phase 3 of HPC execution
+ Abstract = Unblock the ZOO-Kernel awaiting for a remote job execution 
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = wps_hpc.zo
+ serviceType = C
+ <DataInputs>
+  [JobId]
+   Title = the image
+   Abstract = The image to process
+   minOccurs = 1
+   maxOccurs = 1
+   <LiteralData>
+    dataType = string
+    <Default>
+    </Default>
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The resulting string
+   Abstract = The message returned by the service execution as a string.
+   <LiteralOutput>
+    DataType = string
+    <Default>
+    </Default>
+   </LiteralOutput>
+ </DataOutputs>  
Index: trunk/zoo-project/zoo-services/utils/hpc/service.c
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/service.c	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/service.c	(revision 917)
@@ -0,0 +1,363 @@
+/**
+ * Author : Gérald FENOY
+ *
+ * Copyright 2017 GeoLabs SARL. All rights reserved.
+ *
+ * This work was supported by public funds received in the framework of GEOSUD,
+ * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
+ * by the French National Research Agency
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "service.h"
+#include "service_internal.h"
+#include "sshapi.h"
+#include "server_internal.h"
+
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#include <libxslt/xslt.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+
+#include <dirent.h>
+extern "C" {
+
+  /**
+   * FinalizeHPC ZOO Service :
+   * This service is used to inform a ZOO-Kernel waiting for the end of the
+   * execution of a HPC service
+   */
+  ZOO_DLL_EXPORT int FinalizeHPC(maps*& conf,maps*& inputs,maps*& outputs){
+    // Retrieve the jobid corresponding to the identifier generated by SLURM
+    // by reading the file generated when running the SBATCH file
+    map* jobid=getMapFromMaps(inputs,"jobid","value");
+    struct sockaddr_un addr;
+    char buf[100]="3";
+    int fd,rc=NULL;
+    int i=0;
+    map* usid=getMapFromMaps(conf,"lenv","usid");
+    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
+
+    char *flenv =
+      (char *) malloc ((strlen (tmpPath->value) + 
+			strlen (jobid->value) + 12) * sizeof (char));
+    sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, jobid->value);
+    maps* m = (maps *) malloc (MAPS_SIZE);
+    m->child=NULL;
+    m->next=NULL;
+    map* configId=NULL;
+
+    
+    if(conf_read(flenv, m) != 2){
+      configId=getMapFromMaps(m,"lenv","configId");
+      setMapInMaps(conf,"lenv","configId",configId->value);
+    }else{
+      setMapInMaps(conf,"lenv","message",_("Unable to read the lenv section file of the requested jobid"));
+      return SERVICE_FAILED;
+    }
+    
+    SSHCON *test=ssh_connect(conf);
+    /*if(test==NULL){
+      setMapInMaps(conf,"lenv","message",_("Unable to connect using ssh."));
+      return SERVICE_FAILED;
+      }*/
+
+    char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+12)*sizeof(char));
+    sprintf(logPath,"%s/exec_out_%s",tmpPath->value,jobid->value);
+    struct stat f_status;
+    int ts=stat(logPath, &f_status);
+    char* fcontent = NULL;
+    if(ts==0) {
+      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(logPath,"rb");
+      fread(fcontent,f_status.st_size,1,f);
+      int fsize=f_status.st_size;
+      fcontent[fsize]=0;
+      fclose(f);
+    }else{
+      setMapInMaps(conf,"lenv","message",_("No service with this jobid can be found"));
+      return SERVICE_FAILED;
+    }
+    free(logPath);
+    // Run scontrol to check if the service execution ended.
+    // Store all the informations returned by scontrol command as a cfg file to
+    // be parsed back by the ZOO-Kernel waiting for the execution of the remote
+    // service
+    maps* tmpMaps=createMaps("henv");
+    char* command=(char*)malloc((126)*sizeof(char));
+    sprintf(command,"scontrol show jobid | grep -A24 JobId=%s",fcontent);    
+    if(ssh_exec(conf,command,ssh_get_cnt(conf))==0){
+      free(command);
+      setMapInMaps(conf,"lenv","message",_("Failed to run scontrol remotely"));
+      // TODO: check status in db and if available continue in other case return SERVICE_FAILED
+      return SERVICE_FAILED;
+    }else{
+      free(command);
+      logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+11)*sizeof(char));
+      sprintf(logPath,"%s/exec_out_%s",tmpPath->value,usid->value);
+      int ts=stat(logPath, &f_status);
+      if(ts==0) {
+	fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+	FILE* f=fopen(logPath,"rb");
+	fread(fcontent,f_status.st_size,1,f);
+	int fsize=f_status.st_size;
+	fcontent[fsize]=0;
+	fclose(f);
+	free(logPath);
+	char *token, *saveptr;
+	token = strtok_r (fcontent, " ", &saveptr);
+	while (token != NULL)
+	  {
+	    char *token1, *saveptr1;
+	    char *tmpToken=strdup(token);
+	    token1 = strtok_r (tmpToken, "=", &saveptr1);
+	    int isNext=-1;
+	    int hasTwoElements=0;
+	    char *name=NULL;
+	    while (token1 != NULL)
+	      {
+		if(hasTwoElements==0)
+		  name=strdup(token1);
+		if(hasTwoElements<1)
+		  hasTwoElements+=1;
+		else{
+		  char *value=strdup(token1);
+		  if(value[strlen(value)-1]=='\n')
+		    value[strlen(value)-1]=0;
+		  if(strlen(name)>0 && strlen(value)>0){
+		    if(tmpMaps->content==NULL)
+		      tmpMaps->content=createMap(name,value);
+		    else
+		      addToMap(tmpMaps->content,name,value);
+		    free(value);
+		  }
+		  free(name);
+		  hasTwoElements=0;
+		}
+		token1 = strtok_r (NULL, "=", &saveptr1);
+	      }
+	    free(tmpToken);
+	    token = strtok_r (NULL, " ", &saveptr);
+	  }
+      }else{
+	setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
+	return SERVICE_FAILED;
+      }
+    }
+    logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
+    sprintf(logPath,"%s/exec_status_%s",tmpPath->value,jobid->value);
+    dumpMapsToFile(tmpMaps,logPath,0);
+    char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
+    sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,jobid->value);
+    if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+      perror("socket error");
+      setMapInMaps(conf,"lenv","message",_("Socket error"));
+      return SERVICE_FAILED;
+    }
+    memset(&addr, 0, sizeof(addr));
+    addr.sun_family = AF_UNIX;
+    strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
+    if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+      perror("connect error");
+      setMapInMaps(conf,"lenv","message",_("Unable to connect"));
+      return SERVICE_FAILED;
+    }
+    if (write(fd, "3", 1) != rc) {
+      if (rc < 0) {
+	perror("write error");
+	setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
+	close(fd);
+	return SERVICE_FAILED;
+      }
+    }
+    close(fd);
+    setOutputValue(outputs,"Result",(char*)"\"FinalizeHPC run successfully\"",32);
+    unlink(flenv);
+    free(flenv);
+
+    return SERVICE_SUCCEEDED;
+  }
+
+
+  /**
+   * FinalizeHPC1 ZOO Service :
+   * This service is used to inform a ZOO-Kernel waiting for the end of the
+   * execution of a HPC service
+   *
+   * format="AllocCPUS"; for i in $(sacct -e) ; do format="$format,$i"; done; format="$(echo $format | sed "s:AllocCPUS,::")" ; echo $format; sacct --format=$format -p | grep "997f-11e8-9f78-0050569320d2" 
+   *
+   * AllocCPUS,AllocGRES,AllocNodes,AllocTRES,Account,AssocID,AveCPU,AveCPUFreq,AveDiskRead,AveDiskWrite,AvePages,AveRSS,AveVMSize,BlockID,Cluster,Comment,ConsumedEnergy,ConsumedEnergyRaw,CPUTime,CPUTimeRAW,DerivedExitCode,Elapsed,Eligible,End,ExitCode,GID,Group,JobID,JobIDRaw,JobName,Layout,MaxDiskRead,MaxDiskReadNode,MaxDiskReadTask,MaxDiskWrite,MaxDiskWriteNode,MaxDiskWriteTask,MaxPages,MaxPagesNode,MaxPagesTask,MaxRSS,MaxRSSNode,MaxRSSTask,MaxVMSize,MaxVMSizeNode,MaxVMSizeTask,MinCPU,MinCPUNode,MinCPUTask,NCPUS,NNodes,NodeList,NTasks,Priority,Partition,QOS,QOSRAW,ReqCPUFreq,ReqCPUFreqMin,ReqCPUFreqMax,ReqCPUFreqGov,ReqCPUS,ReqGRES,ReqMem,ReqNodes,ReqTRES,Reservation,ReservationId,Reserved,ResvCPU,ResvCPURAW,Start,State,Submit,Suspended,SystemCPU,Timelimit,TotalCPU,UID,User,UserCPU,WCKey,WCKeyID
+   * 28||1|cpu=28,node=1|geosud|258|||||||||cluster||||00:00:56|56|0:0|00:00:02|2018-08-06T15:48:13|2018-08-06T15:48:16|0:0|1019|geosud|883299|883299|ZOO-Project_5bd1c32b-997f-11e8-9f78-0050569320d2_GSDBandMath_6_2_005||||||||||||||||||||28|1|muse044||4294360886|defq|qos_geosud|20|Unknown|Unknown|Unknown|Unknown|1||0n|1|cpu=1,node=1|||00:00:01|00:00:01|1|2018-08-06T15:48:14|COMPLETED|2018-08-06T15:48:13|00:00:00||UNLIMITED|00:00:00|1229|geosudwps|||0|
+   * 
+   */
+  ZOO_DLL_EXPORT int FinalizeHPC1(maps*& conf,maps*& inputs,maps*& outputs){
+    // Retrieve the jobid corresponding to the identifier generated by SLURM
+    // by reading the file generated when running the SBATCH file
+    map* jobid=getMapFromMaps(inputs,"jobid","value");
+    struct sockaddr_un addr;
+    char buf[100]="3";
+    int fd,rc=NULL;
+    int i=0;
+    map* usid=getMapFromMaps(conf,"lenv","usid");
+    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
+
+    char *flenv =
+      (char *) malloc ((strlen (tmpPath->value) + 
+			strlen (jobid->value) + 12) * sizeof (char));
+    sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, jobid->value);
+    maps* m = (maps *) malloc (MAPS_SIZE);
+    m->child=NULL;
+    m->next=NULL;
+    map* configId=NULL;
+
+    
+    if(conf_read(flenv, m) != 2){
+      configId=getMapFromMaps(m,"lenv","configId");
+      setMapInMaps(conf,"lenv","configId",configId->value);
+    }else{
+      setMapInMaps(conf,"lenv","message",_("Unable to read the lenv section file of the requested jobid"));
+      return SERVICE_FAILED;
+    }
+
+    SSHCON *test=ssh_connect(conf);
+    /*if(test==NULL){
+      setMapInMaps(conf,"lenv","message",_("Unable to connect using ssh."));
+      return SERVICE_FAILED;
+      }*/
+
+    char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+12)*sizeof(char));
+    sprintf(logPath,"%s/exec_out_%s",tmpPath->value,jobid->value);
+    struct stat f_status;
+    int ts=stat(logPath, &f_status);
+    char* fcontent = NULL;
+    if(ts==0) {
+      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+      FILE* f=fopen(logPath,"rb");
+      fread(fcontent,f_status.st_size,1,f);
+      int fsize=f_status.st_size;
+      fcontent[fsize]=0;
+      fclose(f);
+    }else{
+      setMapInMaps(conf,"lenv","message",_("No service with this jobid can be found"));
+      return SERVICE_FAILED;
+    }
+    free(logPath);
+    // Run sacct to check if the service execution ended.
+    // Store all the informations returned by scontrol command as a cfg file to
+    // be parsed back by the ZOO-Kernel waiting for the execution of the remote
+    // service
+    maps* tmpMaps=createMaps("henv");
+    
+    map* tmpMap=getMapFromMaps(conf,configId->value,"remote_command_opt");
+    char* command=(char*)malloc((126+strlen(tmpMap->value))*sizeof(char));
+    sprintf(command,"sacct --format=%s -p | grep \"%s\" | sed \"s:||:|None|:g;s:||:|None|:g\"",tmpMap->value,jobid->value);    
+    if(ssh_exec(conf,command,ssh_get_cnt(conf))==0){
+      free(command);
+      setMapInMaps(conf,"lenv","message",_("Failed to run sacct remotely"));
+      // TODO: check status in db and if available continue in other case return SERVICE_FAILED
+      return SERVICE_FAILED;
+    }else{
+      free(command);
+      logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+11)*sizeof(char));
+      sprintf(logPath,"%s/exec_out_%s",tmpPath->value,usid->value);
+      int ts=stat(logPath, &f_status);
+      if(ts==0) {
+	fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
+	FILE* f=fopen(logPath,"rb");
+	fread(fcontent,f_status.st_size,1,f);
+	int fsize=f_status.st_size;
+	fcontent[fsize]=0;
+	fclose(f);
+	free(logPath);
+	char *token, *saveptr;
+	char *token1, *saveptr1;
+	token = strtok_r (tmpMap->value, ",", &saveptr);
+	token1 = strtok_r (fcontent, "|", &saveptr1);
+	while (token != NULL) {
+	  fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,token);
+	  fflush(stderr);
+	  fprintf(stderr,"%s %d %s %s \n",__FILE__,__LINE__,token,token1);
+	  fflush(stderr);
+	  if(token1 != NULL){
+	    if(tmpMaps->content==NULL)
+	      tmpMaps->content=createMap(token,token1);
+	    else
+	      addToMap(tmpMaps->content,token,token1);
+	  }
+	  token = strtok_r (NULL, ",", &saveptr);
+	  token1 = strtok_r (NULL, "|", &saveptr1);
+	}
+      }else{
+	free(logPath);
+	setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
+	return SERVICE_FAILED;
+      }
+    }
+    tmpMap=getMapFromMaps(tmpMaps,"henv","JobId");
+    if(tmpMap!=NULL){
+      char* tmpStr=(char*)malloc((32)*sizeof(char));
+      sprintf(tmpStr,"slurm-%s.out",tmpMap->value);
+      addToMap(tmpMaps->content,"StdErr",tmpStr); 
+      free(tmpStr);
+    }
+    logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
+    sprintf(logPath,"%s/exec_status_%s",tmpPath->value,jobid->value);
+    dumpMapsToFile(tmpMaps,logPath,0);
+    char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
+    sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,jobid->value);
+    if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
+      perror("socket error");
+      setMapInMaps(conf,"lenv","message",_("Socket error"));
+      return SERVICE_FAILED;
+    }
+    memset(&addr, 0, sizeof(addr));
+    addr.sun_family = AF_UNIX;
+    strncpy(addr.sun_path, sname, sizeof(addr.sun_path)-1);
+    if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
+      perror("connect error");
+      setMapInMaps(conf,"lenv","message",_("Unable to connect"));
+      return SERVICE_FAILED;
+    }
+    if (write(fd, "3", 1) != rc) {
+      if (rc < 0) {
+	perror("write error");
+	setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
+	close(fd);
+	return SERVICE_FAILED;
+      }
+    }
+    close(fd);
+    unlink(flenv);
+    free(flenv);
+    setOutputValue(outputs,"Result",(char*)"\"FinalizeHPC run successfully\"",32);
+
+    return SERVICE_SUCCEEDED;
+  }
+  
+}
Index: trunk/zoo-project/zoo-services/utils/hpc/service2.c
===================================================================
--- trunk/zoo-project/zoo-services/utils/hpc/service2.c	(revision 917)
+++ trunk/zoo-project/zoo-services/utils/hpc/service2.c	(revision 917)
@@ -0,0 +1,270 @@
+/**
+ * Author : Gérald FENOY
+ *
+ * Copyright 2017 GeoLabs SARL. All rights reserved.
+ *
+ * This work was supported by public funds received in the framework of GEOSUD,
+ * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
+ * by the French National Research Agency
+ *
+ * This work was supported by public funds received in the framework of GEOSUD,
+ * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
+ * by the French National Research Agency
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+#include "service.h"
+#include "service_internal.h"
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+#include <libxml/xpath.h>
+#include <libxml/xpathInternals.h>
+
+#include <libxslt/xslt.h>
+#include <libxslt/xsltInternals.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+
+#include <dirent.h>
+#include <string.h>
+#include <cerrno>
+
+extern "C" {
+
+  /** 
+   * Retrieve the error message which occured when trying to remove a file
+   * (return values can be EACCES, EBUSY, EFAULT, EIO, EISDIR, ELOOP, 
+   * ENAMETOOLONG, ENOENT, ENOMEM, ENOTDIR, EPERM, EROFS, UNKNOWN).
+   *
+   * @param errn
+   * @result a string corresponding to the error number 
+   */ 
+  char* fetchErrno(int errn){
+   switch(errn){
+    case EACCES:
+	return "EACCES";
+    case EBUSY:
+	return "EBUSY";
+    case EFAULT:
+	return "EFAULT";
+    case EIO:
+	return "EIO";
+    case EISDIR:
+	return "EISDIR";
+    case ELOOP:
+	return "ELOOP";
+    case ENAMETOOLONG:
+	return "ENAMETOOLONG";
+    case ENOENT:
+	return "ENOENT";
+    case ENOMEM:
+	return "ENOMEM";
+    case ENOTDIR:
+	return "ENOTDIR";
+    case EPERM:
+	return "EPERM";
+    case EROFS:
+	return "EROFS";
+    default:
+	return "UNKNOWN";
+   }
+  }
+
+  /**
+   * Try to delete a cache file.
+   * 
+   * @param storage the full path to store the file
+   * @param filename the filename to store
+   * @param ext the extention of the file
+   * @return 0 in case of success
+   */
+  int tryDeleteCacheFile(const char* storage,const char* filename,const char* ext){
+    char *filename_noext=(char*)malloc((strlen(filename)-3)*sizeof(char));
+    snprintf(filename_noext,strlen(filename)-4,"%s",filename);
+    char* filename_full=(char*)malloc((strlen(filename)+1)*sizeof(char));
+    sprintf(filename_full,"%s.%s",filename_noext,ext);
+    char* fullpath=(char*)malloc((strlen(storage)+strlen(filename_full)+2)*sizeof(char));
+    sprintf(fullpath,"%s/%s",storage,filename_full);
+    if(unlink(fullpath)==0){
+      // TODO store the filename_full in the deletedfiles
+      fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,filename_full);
+    }else{
+      fprintf(stderr,"#### DeleteData #### unable to delete %s \n",fullpath);
+    }
+    free(fullpath);
+    free(filename_full);
+    return 0;
+  }  
+
+  /**
+   * Try to delete a data file.
+   * 
+   * @param storage the full path to store the file
+   * @param filename the filename to store
+   * @return 0 in case of success
+   */
+  int tryDeleteDataFile(const char* storage,const char* filename){
+    char* fullpath=NULL;
+    if(filename!=NULL){
+      fullpath=(char*)malloc((strlen(storage)+strlen(filename)+2)*sizeof(char));
+      sprintf(fullpath,"%s/%s",storage,filename);
+    }
+    else
+      fullpath=zStrdup(storage);
+    if(unlink(fullpath)==0){
+      // TODO store the filename_full in the deletedfiles
+      fprintf(stderr,"#### DeleteData #### %s %d %s has been successfully deleted\n",__FILE__,__LINE__,(filename!=NULL && strlen(filename)>0?filename:fullpath));
+    }else{
+      fprintf(stderr,"#### DeleteData #### unable to delete %s %s \n",fullpath,fetchErrno(errno));
+    }
+    free(fullpath);
+    return 0;
+  }  
+  
+  
+  /**
+   * DeleteData ZOO-Service :
+   * This service is used in the ZOO-Project to delete the data file
+   * associated with input or output.
+   */
+  ZOO_DLL_EXPORT int DeleteData(maps*& conf,maps*& inputs,maps*& outputs){
+    map* dataPath=getMapFromMaps(conf,"main","dataPath");
+    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
+    map* cacheDir=getMapFromMaps(conf,"main","cacheDir");
+    map* jobid=getMapFromMaps(inputs,"jobid","value");
+    map* filename=getMapFromMaps(inputs,"filename","value");
+    map* ioname=getMapFromMaps(inputs,"ioname","value");
+    char tmp0[4];
+    sprintf(tmp0,"%c%c%c",filename->value[strlen(filename->value)-3],filename->value[strlen(filename->value)-2],filename->value[strlen(filename->value)-1]);
+    char *cfilename=NULL;
+    if(strcasecmp(tmp0,"zca")==0){
+      cfilename=(char*) malloc((strlen(filename->value)+strlen(cacheDir->value)+2)*sizeof(char));
+      sprintf(cfilename,"%s/%s",cacheDir->value,filename->value);
+    }
+    else{
+      cfilename=(char*) malloc((strlen(filename->value)+strlen(tmpPath->value)+2)*sizeof(char));
+      sprintf(cfilename,"%s/%s",tmpPath->value,filename->value);
+    }
+    zooLock* lck=lockFile(conf,cfilename,'w');
+    char** deletedfiles;
+    if(lck!=NULL){
+      if(strcasecmp(tmp0,"zca")==0){
+	// Read the zcp file to verify if it comes from a shared source
+	char *filename_noext=(char*)malloc((strlen(filename->value)-3)*sizeof(char));
+	snprintf(filename_noext,strlen(filename->value)-4,"%s",filename->value);
+	char* filename_full=(char*)malloc((strlen(filename->value)+1)*sizeof(char));
+	sprintf(filename_full,"%s.zcp",filename_noext);
+	char* fullpath=(char*)malloc((strlen(cacheDir->value)+strlen(filename_full)+2)*sizeof(char));
+	sprintf(fullpath,"%s/%s",cacheDir->value,filename_full);
+	FILE* f0=fopen(fullpath,"rb");
+	char *fcontent=NULL;
+	if(f0!=NULL){
+	  long flen;
+	  fseek (f0, 0, SEEK_END);
+	  flen = ftell (f0);
+	  fseek (f0, 0, SEEK_SET);
+	  fcontent = (char *) malloc ((flen + 1) * sizeof (char));
+	  fread(fcontent,flen,1,f0);
+	  fcontent[flen]=0;
+	  fclose(f0);
+	}
+	if(fcontent!=NULL && strcasecmp(fcontent,"SHARED")!=0){
+	  // Delete associated zcm, zcp and maps files
+	  tryDeleteCacheFile(cacheDir->value,filename->value,"zca");
+	  tryDeleteCacheFile(cacheDir->value,filename->value,"zcm");
+	  tryDeleteCacheFile(cacheDir->value,filename->value,"zcp");
+	  tryDeleteCacheFile(tmpPath->value,filename->value,"maps");
+	  // Delete <input>_<sid>.map
+	  char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
+	  sprintf(datafile,"%s_%s.map",ioname->value,jobid->value);
+	  tryDeleteDataFile(dataPath->value,datafile);
+	  free(datafile);
+	}else{
+	  setMapInMaps(conf,"lenv","message",_ss("The file you try to delete is a shared ressource and cannot be deleted by nature."));
+	  unlockFile(conf,lck);
+	  return SERVICE_FAILED;
+	}
+	setMapInMaps(outputs,"Result","value",_ss("The input data has been correclty removed"));
+      }else{
+	char tmp1[8];
+	snprintf(tmp1,7,"%s",filename->value);
+	if(strcasecmp(tmp1,"output")==0 || strstr(filename->value,".zca")!=NULL || strcasecmp(tmp1,"input_")==0){
+	  tryDeleteDataFile(tmpPath->value,filename->value);
+          char *tmp=zStrdup(filename->value);
+	  tmp[strlen(tmp)-strlen(strrchr(tmp,'.'))]=0;
+	  char *mapsfile=(char*)malloc((strlen(tmp)+6)*sizeof(char));
+	  sprintf(mapsfile,"%s.maps",tmp);
+          char* mapPath=(char*)malloc((strlen(tmpPath->value)+strlen(mapsfile)+2)*sizeof(char));
+          sprintf(mapPath,"%s/%s",tmpPath->value,mapsfile);
+	  FILE* myMapsfile=fopen(mapPath,"r");
+          if(myMapsfile!=NULL){
+	    char *buffer=(char*)malloc(1024*sizeof(char));
+	    while(fgets(buffer, 1024, myMapsfile) != NULL){
+	      buffer[strlen(buffer)-1]=0;
+	      tryDeleteDataFile(buffer,NULL);
+	    }
+	    free(buffer);
+	    fclose(myMapsfile);
+          }
+          tryDeleteDataFile(mapPath,NULL);
+          free(mapPath);
+          free(mapsfile);
+	  // Delete ZOO_DATA_<output>_<sid>.data and <output>_<sid>.map
+	  char* datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
+	  sprintf(datafile,"ZOO_DATA_%s_%s.data",ioname->value,jobid->value);
+	  tryDeleteDataFile(dataPath->value,datafile);
+	  free(datafile);
+	  datafile=(char*)malloc((strlen(jobid->value)+strlen(ioname->value)+19)*sizeof(char));
+	  sprintf(datafile,"%s_%s.map",ioname->value,jobid->value);
+	  tryDeleteDataFile(dataPath->value,datafile);
+	  free(datafile);
+	  char* webServices[3]={"wms","wfs","wcs"};
+	  int i=0;
+	  // Delete ZOO_DATA_<ws>_link_<sid>.data and <ws>_link_<sid>.map
+	  // with <ws> is the corresponding OGC web service (wms,wfs,wcs)
+	  for(i=0;i<3;i++){
+	    datafile=(char*)malloc((strlen(jobid->value)+24)*sizeof(char));
+	    sprintf(datafile,"ZOO_DATA_%s_link_%s.data",webServices[i],jobid->value);
+	    tryDeleteDataFile(dataPath->value,datafile);
+	    free(datafile);
+	    datafile=(char*)malloc((strlen(jobid->value)+14)*sizeof(char));
+	    sprintf(datafile,"%s_link_%s.map",webServices[i],jobid->value);
+	    tryDeleteDataFile(dataPath->value,datafile);
+	    free(datafile);
+	  }
+	  setMapInMaps(outputs,"Result","value",_ss("The output data has been correclty removed"));
+	}else{
+	  setMapInMaps(conf,"lenv","message",_ss("The file you try to delete is nor an input, nor an output."));
+	  unlockFile(conf,lck);
+	  return SERVICE_FAILED;
+	}
+      }
+      unlockFile(conf,lck);
+    }
+    else{
+      setMapInMaps(conf,"lenv","message",_ss("Failed to acquire lock for deletion, please try again later."));
+      return SERVICE_FAILED;
+    }
+    return SERVICE_SUCCEEDED;
+  }
+
+}
Index: trunk/zoo-project/zoo-services/utils/registry/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/utils/registry/Makefile	(revision 811)
+++ trunk/zoo-project/zoo-services/utils/registry/Makefile	(revision 917)
@@ -1,5 +1,5 @@
 ZRPATH=../../..
 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
-CFLAGS=${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+ZCFLAGS=-I${ZRPATH}/zoo-kernel/ ${CFLAGS} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
 
 YAML_FILES=""
@@ -16,5 +16,5 @@
 
 cgi-env/wps_registry.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_registry.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} -lfcgi -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/server_internal.o ${ZRPATH}/zoo-kernel/lex.cr.o ${ZRPATH}/zoo-kernel/lex.sr.o ${ZRPATH}/zoo-kernel/service_conf.tab.o ${ZRPATH}/zoo-kernel/main_conf_read.tab.o ${ZRPATH}/zoo-kernel/response_print.o ${YAML_FILES} ${MS_FILES} ${MS_LDFLAGS} ${YAML_LDFLAGS}
+	g++ ${ZCFLAGS} -shared -fpic -o cgi-env/wps_registry.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} -lfcgi -L${ZRPATH}/zoo-kernel/ -lzoo_service ${ZRPATH}/zoo-kernel/server_internal.o ${ZRPATH}/zoo-kernel/lex.cr.o ${ZRPATH}/zoo-kernel/lex.sr.o ${ZRPATH}/zoo-kernel/service_conf.tab.o ${ZRPATH}/zoo-kernel/main_conf_read.tab.o ${ZRPATH}/zoo-kernel/response_print.o ${YAML_FILES} ${MS_FILES} ${MS_LDFLAGS} ${YAML_LDFLAGS}
 
 install:
Index: trunk/zoo-project/zoo-services/utils/registry/service.c
===================================================================
--- trunk/zoo-project/zoo-services/utils/registry/service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/utils/registry/service.c	(revision 917)
@@ -80,5 +80,5 @@
 				    root_nodes[1][1],"2.0.0",1);
       setMapInMaps(conf,"main","rversion","2.0.0");
-      printDescribeProcessForProcess(zooRegistry,conf,n,inherited);
+      printDescribeProcessForProcess(zooRegistry,conf,doc,n,inherited);
       setMapInMaps(conf,"main","rversion","1.0.0");
 
Index: trunk/zoo-project/zoo-services/utils/status/Makefile
===================================================================
--- trunk/zoo-project/zoo-services/utils/status/Makefile	(revision 811)
+++ trunk/zoo-project/zoo-services/utils/status/Makefile	(revision 917)
@@ -1,8 +1,8 @@
 ZRPATH=../../..
 include ${ZRPATH}/zoo-kernel/ZOOMakefile.opts
-CFLAGS=-I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
+CFLAGS1=${CFLAGS} -I${INST_INCLUDE} ${ZOO_CFLAGS} ${XML2CFLAGS} ${GDAL_CFLAGS} ${PYTHONCFLAGS} -DLINUX_FREE_ISSUE #-DDEBUG
 
 cgi-env/wps_status.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
+	g++ ${CFLAGS1} -shared -fpic -o cgi-env/wps_status.zo ./service.c ${GDAL_LIBS} ${XML2LDFLAGS} ${MACOS_LD_FLAGS} ${ZOO_LDFLAGS} ${MACOS_LD_NET_FLAGS} ${XSLT_LDFLAGS} ${FCGI_LDFLAGS} -L${ZRPATH}/zoo-kernel/ -lzoo_service
 
 install:
Index: trunk/zoo-project/zoo-services/utils/status/service.c
===================================================================
--- trunk/zoo-project/zoo-services/utils/status/service.c	(revision 811)
+++ trunk/zoo-project/zoo-services/utils/status/service.c	(revision 917)
@@ -72,4 +72,7 @@
       return SERVICE_FAILED;
     }
+    map* tmpMap1=getMapFromMaps(conf,"lenv","semaphore");
+    if(tmpMap1!=NULL && strcasecmp(tmpMap1->value,"Created")==0)
+      removeShmLock(conf,1);
     sprintf(xslFileName,"%s/updateStatus.xsl",tmpMmap->value);
     xmlSubstituteEntitiesDefault(1);
@@ -85,7 +88,7 @@
        */
       char *tmpStr=_getStatus(conf,tmpMap->value);
-#ifdef DEBUG
+      //#ifdef DEBUG
       fprintf(stderr,"DEBUG: %s \n",tmpStr);
-#endif
+      //#endif
       if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
 	char *tmpStr1=strdup(tmpStr);
@@ -140,4 +143,6 @@
       char message[10];
       sprintf(message,"Step %d",i);
+      fprintf (stderr, "RUN IN BACKGROUND MODE %s %d \n",__FILE__,__LINE__);
+      fflush(stderr);
       updateStatus(conf,i,message);
 #ifndef WIN32
