Index: trunk/zoo-kernel/Makefile.in
===================================================================
--- trunk/zoo-kernel/Makefile.in	(revision 8)
+++ trunk/zoo-kernel/Makefile.in	(revision 9)
@@ -1,5 +1,5 @@
 JAVACFLAGS=@JAVA_CPPFLAGS@
 JAVALDFLAGS=@JAVA_LDFLAGS@
-CFLAGS=-I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
+CFLAGS=-I../thirds/cgic206 -I. -DLINUX_FREE_ISSUE #-DDEBUG #-DDEBUG_SERVICE_CONF
 PHPCFLAGS=@PHP_CPPFLAGS@
 PHPLDFLAGS=@PHP_LDFLAGS@
@@ -69,12 +69,9 @@
 
 zoo_service_loader.o: zoo_service_loader.c service.h
-	g++ -g -O2 -Wall ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${PHPCFLAGS} ${JS_ENABLED} ${PHP_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
+	g++ -g -O2 -Wall ${XML2CFLAGS} ${CFLAGS} ${PYTHONCFLAGS} ${JAVACFLAGS} ${JSCFLAGS} ${PHPCFLAGS} ${JS_ENABLED} ${PHP_ENABLED} ${JAVA_ENABLED} -c zoo_service_loader.c  -fno-common -DPIC -o zoo_service_loader.o
 
 zoo_loader.cgi: zoo_loader.c zoo_service_loader.o  ulinet.o service.h lex.sr.o service_conf.tab.o service_conf.y service_internal_python.o  ulinet.o main_conf_read.tab.o lex.cr.o service_internal.o ${PHP_FILE} ${JAVA_FILE} ${JS_FILE}
 	g++ -g -O2 -Wall ${JSCFLAGS} ${PHPCFLAGS} ${JAVACFLAGS} ${XML2CFLAGS} ${PYTHONCFLAGS} ${CFLAGS} -c zoo_loader.c  -fno-common -DPIC -o zoo_loader.o
-	g++  ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o service_internal_python.o  ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -lcurl -lcgic -lcurl ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi 
-
-service_loader: service.h lex.sr.o service_conf.tab.o service_conf.y service_internal_python.o ulinet.o  service_loader.o main_conf_read.tab.o lex.cr.o service_internal.o
-	g++ ${CFLAGS} lex.sr.o service_conf.tab.o main_conf_read.tab.o lex.cr.o service_internal.o service_internal_python.o ulinet.o service_loader.o -o service_loader -ldl  ${JSLDFLAGS} ${PYTHONLDFLAGS} ${XML2LDFLAGS} -lfl -lcurl  -lssl
+	g++  ${JSCFLAGS} ${GDAL_CFLAGS} ${XML2CFLAGS} ${PHPCFLAGS} ${JAVACFLAGS} ${PYTHONCFLAGS} ${CFLAGS} zoo_loader.o zoo_service_loader.o service_internal.o service_internal_python.o  ${PHP_FILE}  ${JS_FILE} ${JAVA_FILE} ulinet.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o -o zoo_loader.cgi -lcurl -L../thirds/cgic206 -lcgic -lcurl ${GDAL_LIBS} ${XML2LDFLAGS} ${PYTHONLDFLAGS}  ${PHPLDFLAGS} ${JAVALDFLAGS} ${JSLDFLAGS} -lfcgi 
 
 install:
Index: trunk/zoo-kernel/configure.ac
===================================================================
--- trunk/zoo-kernel/configure.ac	(revision 8)
+++ trunk/zoo-kernel/configure.ac	(revision 9)
@@ -298,6 +298,6 @@
 	LIBS="$JAVA_LDFLAGS"
 	# Shouldn't we get java here rather than java5 :) ??
-	AC_CHECK_LIB([javaplugin_jni], [JNI_CreateJavaVM], [], [AC_MSG_ERROR([could not find libjava])], [])
-	AC_CHECK_LIB([jvm], [main], [], [AC_MSG_ERROR([could not find libjava])], [])
+	AC_CHECK_LIB([jvm], [JNI_CreateJavaVM], [], [AC_MSG_ERROR([could not find libjava])], [])
+	#AC_CHECK_LIB([jvm], [main], [], [AC_MSG_ERROR([could not find libjava])], [])
 
 	AC_SUBST([JAVA_CPPFLAGS])
@@ -347,5 +347,4 @@
 	fi
 	
-
 	CPPFLAGS_SAVE="$CPPFLAGS"
         CPPFLAGS="$JS_CPPFLAGS"
@@ -367,5 +366,5 @@
 		JS_ENABLED="-DUSE_JS"
         	JS_FILE="service_internal_js.o"
-		JS_CPPFLAGS="-I$JSHOME/include"
+		JS_CPPFLAGS="-I$JSHOME/include/js"
                 JS_LDFLAGS="-L$JSHOME/lib -ljs -lm"
                 JS_LIB="js"
Index: trunk/zoo-kernel/main_conf_read.l
===================================================================
--- trunk/zoo-kernel/main_conf_read.l	(revision 8)
+++ trunk/zoo-kernel/main_conf_read.l	(revision 9)
@@ -1,5 +1,4 @@
 /* pour pouvoir acceder au numero de ligne dans bison */
 %option yylineno
-
 
 %{
@@ -114,9 +113,9 @@
 {newline}+{whitesp}*			{if (affichetrace==1) printf ("\n\nNEWLINE 1\n") ; return NEWLINE;}
 
-<INITIAL,HORSBALISE>"["{attname}"]"             {if (affichetrace==1) printf ("\n\nANID:%s\n",yytext); crlval.chaine=strdup(yytext);crlval.chaine[strlen(crlval.chaine)-1]=0;crlval.chaine+=1;return ANID; }
+<INITIAL,HORSBALISE>"["{attname}"]"             {if (affichetrace==1) printf ("\n\nANID:%s\n",yytext); crlval.chaine=yytext;crlval.chaine[strlen(crlval.chaine)-1]=0;crlval.chaine+=1;return ANID; }
 
-<INITIAL,HORSBALISE>{attname}             {if (affichetrace==1) printf ("\n\nATT_NAME:%s\n",yytext); crlval.chaine=strdup(yytext); return SPAIR; }
+<INITIAL,HORSBALISE>{attname}             {if (affichetrace==1) printf ("\n\nATT_NAME:%s\n",yytext); crlval.chaine=yytext; return SPAIR; }
 
-<PAIRSTART,HORSBALISE>{attvalue1}             {if (affichetrace==1) printf ("\n\nATT_VALUE:%s\n",yytext);crlval.chaine=strdup(yytext);BEGIN(INITIAL);return EPAIR;}
+<PAIRSTART,HORSBALISE>{attvalue1}             {if (affichetrace==1) printf ("\n\nATT_VALUE:%s\n",yytext);crlval.chaine=yytext;BEGIN(INITIAL);return EPAIR;}
 
 <PAIRSTART,INITIAL,HORSBALISE>{whitesp}*"="{whitesp}*             {BEGIN(PAIRSTART);}
@@ -161,5 +160,5 @@
 
 
-<DANSBALISE>{Name}			{if (affichetrace==1) printf ("\n\nID:%s\n",yytext) ; crlval.s=strdup(yytext);return ID;}
+<DANSBALISE>{Name}			{if (affichetrace==1) printf ("\n\nID:%s\n",yytext) ; crlval.s=yytext;return ID;}
 
 
@@ -175,4 +174,4 @@
 
 
-int yywrap()
+int crwrap()
 {return 1;}
Index: trunk/zoo-kernel/main_conf_read.y
===================================================================
--- trunk/zoo-kernel/main_conf_read.y	(revision 8)
+++ trunk/zoo-kernel/main_conf_read.y	(revision 9)
@@ -5,6 +5,4 @@
 **/
 //======================================================
-
-
 
 #include <string>
@@ -23,9 +21,6 @@
 static char* curr_key;
 static int debug=0;
-//static int data=-1;
 static int previous_data=0;
 static int current_data=0;
-//static char* myFinalObjectAsJSON="{";
-// namespace
 using namespace std;
 
@@ -43,5 +38,5 @@
 
 extern int crlex(void);
-
+extern int crlex_destroy(void);
 
 %}
@@ -128,16 +123,16 @@
  : STag contentetoile ETag	
 {
-	/* les non terminaux rendent les valeurs de leur identifiants de balise */
-	/* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */
-	/* de string */
-	if (strcmp($1,$3) != 0)
-	{
-	   crerror("Opening and ending tag mismatch");
-	   printf("\n  ::details : tag '%s' et '%s' \n",$1,$3);
-	   return 1;
-	   // on retourne different de 0
-	   // sinon yyparse rendra 0
-	   // et dans le main on croira a le fichier xml est valide !
-	}
+  /* les non terminaux rendent les valeurs de leur identifiants de balise */
+  /* en char*, donc on peut comparer ces valeurs avec la fonction C++ strcmp(const char*;const char*) */
+  /* de string */
+  if (strcmp($1,$3) != 0)
+    {
+      crerror("Opening and ending tag mismatch");
+      printf("\n  ::details : tag '%s' et '%s' \n",$1,$3);
+      return 1;
+      // on retourne different de 0
+      // sinon yyparse rendra 0
+      // et dans le main on croira a le fichier xml est valide !
+    }
 }
 // pour neutre
@@ -266,6 +261,7 @@
   if(current_content==NULL) 
     current_content=createMap(curr_key,$1);
-  else 
+  else{ 
     addToMap(current_content,curr_key,$1);
+  }
   if(debug){ 
     printf("EPAIR FOUND !! \n"); 
@@ -279,15 +275,24 @@
 
 processid
- : ANID  {
+: ANID  {
    if(current_maps->name!=NULL){
-     current_maps->content=current_content;
-     current_maps->next=(maps*)malloc(MAP_SIZE);
+     addMapToMap(&current_maps->content,current_content);
+     freeMap(&current_content);
+     free(current_content);
+     current_maps->next=NULL;
+     current_maps->next=(maps*)malloc(MAPS_SIZE);
+     current_maps->next->name=strdup($1);
+     current_maps->next->content=NULL;
+     current_maps->next->next=NULL;
      current_maps=current_maps->next;
-     current_maps->name=strdup($1);
+     current_content=current_maps->content;
+   }
+   else{
+     current_maps->name=(char*)malloc((strlen($1)+1)*sizeof(char));
+     snprintf(current_maps->name,(strlen($1)+1),"%s",$1);
+     current_maps->content=NULL;
+     current_maps->next=NULL;
      current_content=NULL;
    }
-   else{
-     current_maps->name=strdup($1);
-   }
  }
  ;
@@ -310,7 +315,4 @@
 //======================================================
 int conf_read(char* file,maps* my_map){
-  /* mode debug ou pas : */
-  /* 1 = debug , 0 = normal */
-  //yydebug = 1;
   
   crin = fopen(file,"r");
@@ -320,5 +322,4 @@
   }
 
-  //my_map=(maps*)malloc(sizeof(maps*));
   my_maps=my_map;
   my_maps->name=NULL;
@@ -326,19 +327,18 @@
   
   int resultatYYParse = crparse() ;
-
-  if(current_content!=NULL)
-    current_maps->content=current_content;
-	  
-  //dumpMaps(my_maps);
+  if(current_content!=NULL){
+    addMapToMap(&current_maps->content,current_content);
+    current_maps->next=NULL;
+    freeMap(&current_content);
+    free(current_content);
+  }
 
   fclose(crin);
+  crlex_destroy();
+
   return resultatYYParse;
 }
 
 
-void usage(void)
-{
-    printf("usage : $./test1 <fichier_de_configuration_principale>\n") ;	 
-}
 //======================================================
 // FIN //
Index: trunk/zoo-kernel/service.h
===================================================================
--- trunk/zoo-kernel/service.h	(revision 8)
+++ trunk/zoo-kernel/service.h	(revision 9)
@@ -40,4 +40,5 @@
 #define true 1
 #define false -1
+
 #define SERVICE_ACCEPTED 0
 #define SERVICE_STARTED 1
@@ -45,10 +46,13 @@
 #define SERVICE_SUCCEEDED 3
 #define SERVICE_FAILED 4
+
 #define ELEMENTS_SIZE (sizeof(char*)+(((2*sizeof(char*))+sizeof(maps*))*2)+sizeof(char*)+(((2*sizeof(char*))+sizeof(iotype*))*2)+sizeof(elements*))
-#define MAP_SIZE (2*sizeof(char*))+sizeof(map*)
-#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+sizeof(maps*)
-
-
-  static char* mtoupper(char* str){
+#define MAP_SIZE (2*sizeof(char*))+sizeof(NULL)
+#define IOTYPE_SIZE MAP_SIZE+sizeof(NULL)
+#define MAPS_SIZE (2*sizeof(char*))+sizeof(map*)+MAP_SIZE
+#define SERVICE_SIZE (ELEMENTS_SIZE*2)+(MAP_SIZE*2)+sizeof(char*)
+
+
+  /*  static char* mtoupper(char* str){
     char* tmp=strdup(str);
     if(tmp){
@@ -63,16 +67,28 @@
       tmp[0]=0;
     return tmp;
-  }
-
+    }*/
+
+  /**
+   * \struct maps
+   * \brief linked list of map pointer
+   *
+   * Small object to store WPS KVP set.
+   */
   typedef struct maps{
-    char* name;
-    struct map* content;
-    struct maps* next;
+    char* name;          
+    struct map* content; 
+    struct maps* next;   
   } maps;
 
+  /**
+   * \struct map
+   * \brief KVP linked list
+   *
+   * Deal with WPS KVP (name,value).
+   */
   typedef struct map{
-    char* name;
-    char* value;
-    struct map* next;
+    char* name;       /* The key */
+    char* value;      /* The value */
+    struct map* next; /* Next couple */
   } map;
 
@@ -83,5 +99,5 @@
 #endif
 
-  static void* _dumpMap(map* t){
+  static void _dumpMap(map* t){
     if(t!=NULL){
       fprintf(stderr,"[%s] => [%s] \n",t->name,t->value);
@@ -91,8 +107,7 @@
       fflush(stderr);
     }
-    return NULL;
-  }
-
-  static void* dumpMap(map* t){
+  }
+
+  static void dumpMap(map* t){
     map* tmp=t;
     while(tmp!=NULL){
@@ -100,5 +115,4 @@
       tmp=tmp->next;
     }
-    return NULL;
   }
 
@@ -112,5 +126,5 @@
   }
 
-  static map* createMap(char* name,char* value){
+  static map* createMap(const char* name,const char* value){
     map* tmp=(map *)malloc(MAP_SIZE);
     tmp->name=strdup(name);
@@ -130,8 +144,8 @@
   }
     
-  static bool hasKey(map* m,char *key){
+  static bool hasKey(map* m,const char *key){
     map* tmp=m;
     while(tmp!=NULL){
-      if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
+      if(strncasecmp(tmp->name,key,strlen(key))==0)
 	return true;
       tmp=tmp->next;
@@ -143,9 +157,10 @@
   }
 
-  static maps* getMaps(maps* m,char *key){
+  static maps* getMaps(maps* m,const char *key){
     maps* tmp=m;
     while(tmp!=NULL){
-      if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
+      if(strncasecmp(tmp->name,key,strlen(key))==0){
 	return tmp;
+      }
       tmp=tmp->next;
     }
@@ -153,9 +168,10 @@
   }
 
-  static map* getMap(map* m,char *key){
+  static map* getMap(map* m,const char *key){
     map* tmp=m;
     while(tmp!=NULL){
-      if(strcmp(mtoupper(tmp->name),mtoupper(key))==0)
+      if(strncasecmp(tmp->name,key,strlen(key))==0){
 	return tmp;
+      }
       tmp=tmp->next;
     }
@@ -166,13 +182,16 @@
     maps* _tmpm=getMaps(m,key);
     if(_tmpm!=NULL){
-      map* tmpm=getMap(_tmpm->content,mtoupper(subkey));
-      return tmpm;
+      map* _ztmpm=getMap(_tmpm->content,subkey);
+      return _ztmpm;
     }
     else return NULL;
   }
 
-  static void* freeMap(map** mo){
+  static void freeMap(map** mo){
     map* _cursor=*mo;
     if(_cursor!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,"freeMap\n");
+#endif
       free(_cursor->name);
       free(_cursor->value);
@@ -182,7 +201,24 @@
       }
     }
-	return NULL;
-  }
-
+  }
+
+  static void freeMaps(maps** mo){
+    maps* _cursor=*mo;
+    fflush(stderr);
+    if(_cursor && _cursor!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,"freeMaps\n");
+#endif
+      free(_cursor->name);
+      if(_cursor->content!=NULL){
+      	freeMap(&_cursor->content);
+      	free(_cursor->content);
+      }
+      if(_cursor->next!=NULL){
+	freeMaps(&_cursor->next);
+	free(_cursor->next);
+      }
+    }
+  }
 
   typedef struct iotype{
@@ -217,7 +253,5 @@
     elements* tmp=e;
     while(tmp!=NULL){
-      mtoupper(key);
-      mtoupper(tmp->name);
-      if(strcmp(key,tmp->name)==0)
+      if(strncasecmp(key,tmp->name,strlen(key))==0)
 	return true;
       tmp=tmp->next;
@@ -229,7 +263,5 @@
     elements* tmp=m;
     while(tmp!=NULL){
-      mtoupper(tmp->name);
-      mtoupper(key);
-      if(strcmp(tmp->name,key)==0)
+      if(strncasecmp(tmp->name,key,strlen(tmp->name))==0)
 	return tmp;
       tmp=tmp->next;
@@ -239,13 +271,14 @@
 
 
-  static void* freeIOType(iotype** i){
+  static void freeIOType(iotype** i){
     iotype* _cursor=*i;
     if(_cursor!=NULL){
       freeMap(&_cursor->content);
       free(_cursor->content);
-      freeIOType(&_cursor->next);
-      free(_cursor->next);
-    }
-	return NULL;
+      if(_cursor->next!=NULL){
+	freeIOType(&_cursor->next);
+	free(_cursor->next);
+      }
+    }
   }
 
@@ -253,41 +286,25 @@
     elements* tmp=*e;
     if(tmp!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"FREE 1");
-#endif
       free(tmp->name);
       freeMap(&tmp->content);
-#ifdef DEBUG
-      fprintf(stderr,"FREE 2");
-#endif
       free(tmp->content);
       freeMap(&tmp->metadata);
-#ifdef DEBUG
-      fprintf(stderr,"FREE 3");
-#endif
       free(tmp->metadata);
-#ifdef DEBUG
-      fprintf(stderr,"FREE 4");
-#endif
       free(tmp->format);
       freeIOType(&tmp->defaults);
-#ifdef DEBUG
-      fprintf(stderr,"FREE 5");
-#endif
       if(tmp->defaults!=NULL)
 	free(tmp->defaults);
       freeIOType(&tmp->supported);
-#ifdef DEBUG
-      fprintf(stderr,"FREE 6");
-#endif
       if(tmp->supported!=NULL)
 	free(tmp->supported);
-      tmp=tmp->next;
-    }
-  }
-
-  static void* freeService(service** s){
+      freeElements(&tmp->next);
+    }
+  }
+
+  static void freeService(service** s){
     service* tmp=*s;
     if(tmp!=NULL){
+      if(tmp->name!=NULL)
+	free(tmp->name);
       freeMap(&tmp->content);
       if(tmp->content!=NULL)
@@ -305,58 +322,5 @@
   }
 
-  static void* addMapToMap(map** mo,map* mi){
-    map* tmp=mi;
-    map* _cursor=*mo;
-    while(tmp!=NULL){
-      if(_cursor==NULL){
-	*mo=(map*)malloc(MAP_SIZE);
-	*mo=createMap(tmp->name,tmp->value);
-	_cursor=*mo;
-	_cursor->next=NULL;
-      }
-      else{
-	while(_cursor->next!=NULL)
-	  _cursor=_cursor->next;
-	_cursor->next=createMap(tmp->name,tmp->value);
-      }
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-  static void* addMapsToMaps(maps** mo,maps* mi){
-    maps* tmp=mi;
-    maps* _cursor=*mo;
-    while(tmp!=NULL){
-      if(_cursor==NULL){
-	*mo=(maps*)malloc(MAP_SIZE);
-	*mo=mi;
-	_cursor=*mo;
-      }
-      else{
-	while(_cursor->next!=NULL)
-	  _cursor=_cursor->next;
-	_cursor->next=tmp;
-      }
-      tmp=tmp->next;
-    }
-    return NULL;
-  }
-
-  static void* addMapToIotype(iotype** io,map* mi){
-    iotype* tmp=*io;
-    while(tmp!=NULL){
-      fprintf(stderr,">> CURRENT MAP");
-      dumpMap(tmp->content);
-      tmp=tmp->next;
-    }
-    tmp=(iotype*)malloc(ELEMENTS_SIZE);
-    tmp->content=NULL;
-    tmp->next=NULL;
-    addMapToMap(&tmp->content,mi);
-    return NULL;
-  }
-
-  static void* addToMap(map* m,char* n,char* v){
+  static void addToMap(map* m,const char* n,const char* v){
     if(hasKey(m,n)==false){
       map* _cursor=m;
@@ -367,11 +331,115 @@
     else{
       map *tmp=getMap(m,n);
+      if(tmp->value!=NULL)
+      	free(tmp->value);
       tmp->value=strdup(v);
     }
-    return NULL;
-  }
-
-
-  static void* dumpElements(elements* e){
+  }
+
+  static void addMapToMap(map** mo,map* mi){
+    map* tmp=mi;
+    map* _cursor=*mo;
+    if(tmp==NULL){
+      if(_cursor!=NULL){
+	while(_cursor!=NULL)
+	  _cursor=_cursor->next;
+	_cursor=NULL;
+      }else
+	*mo=NULL;
+    }
+    while(tmp!=NULL){
+      if(_cursor==NULL){
+	if(*mo==NULL)
+	  *mo=createMap(tmp->name,tmp->value);
+	else
+	  addToMap(*mo,tmp->name,tmp->value);
+      }
+      else{
+#ifdef DEBUG
+	fprintf(stderr,"_CURSOR\n");
+	dumpMap(_cursor);
+#endif
+	while(_cursor!=NULL)
+	  _cursor=_cursor->next;
+	_cursor=createMap(tmp->name,tmp->value);
+	_cursor->next=NULL;
+      }
+      tmp=tmp->next;
+#ifdef DEBUG
+      fprintf(stderr,"MO\n");
+      dumpMap(*mo);
+#endif
+    }
+  }
+
+  static void addMapToIoType(iotype** io,map* mi){
+    iotype* tmp=*io;
+    while(tmp!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,">> CURRENT MAP");
+      dumpMap(tmp->content);
+#endif
+      tmp=tmp->next;
+    }
+#ifdef DEBUG
+    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+    fflush(stderr);
+#endif
+    tmp=(iotype*)malloc(IOTYPE_SIZE);
+#ifdef DEBUG
+    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+    fflush(stderr);
+#endif
+    tmp->content=NULL;
+#ifdef DEBUG
+    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+    fflush(stderr);
+#endif
+    addMapToMap(&tmp->content,mi);
+#ifdef DEBUG
+    fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+    fflush(stderr);
+#endif
+    dumpMap(tmp->content);
+    tmp->next=NULL;
+  }
+
+
+  static maps* dupMaps(maps** mo){
+    maps* _cursor=*mo;
+    maps* res=NULL;
+    if(_cursor!=NULL){
+      res=(maps*)malloc(MAPS_SIZE);
+      res->name=strdup(_cursor->name);
+      res->content=NULL;
+      res->next=NULL;
+      map* mc=_cursor->content;
+      if(mc!=NULL){
+	addMapToMap(&res->content,mc);
+      }
+      res->next=dupMaps(&_cursor->next);
+    }
+    return res;
+  }
+
+  static void addMapsToMaps(maps** mo,maps* mi){
+    maps* tmp=mi;
+    maps* _cursor=*mo;
+    while(tmp!=NULL){
+      if(_cursor==NULL){
+	*mo=dupMaps(&mi);
+	(*mo)->next=NULL;
+      }
+      else{
+	while(_cursor->next!=NULL)
+	  _cursor=_cursor->next;
+	_cursor->next=dupMaps(&tmp);
+      }
+      tmp=tmp->next;
+    }
+  }
+
+
+  static void dumpElements(elements* e){
     elements* tmp=e;
     while(tmp!=NULL){
@@ -401,14 +469,16 @@
       tmp=tmp->next;
     }
-    return NULL;
-  }
-
+  }
 
   static elements* dupElements(elements* e){
-    if(e!=NULL){
-#ifdef DEBUG
+    elements* cursor=e;
+    elements* tmp=NULL;
+    if(cursor!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
       dumpElements(e);
-#endif
-      elements* tmp=(elements*)malloc(ELEMENTS_SIZE);
+      fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+#endif
+      tmp=(elements*)malloc(ELEMENTS_SIZE);
       tmp->name=strdup(e->name);
       tmp->content=NULL;
@@ -418,45 +488,54 @@
       tmp->format=strdup(e->format);
       if(e->defaults!=NULL){
-	tmp->defaults=(iotype*)malloc(MAP_SIZE);
+	tmp->defaults=(iotype*)malloc(IOTYPE_SIZE);
 	tmp->defaults->content=NULL;
+	addMapToMap(&tmp->defaults->content,e->defaults->content);
 	tmp->defaults->next=NULL;
-	addMapToMap(&tmp->defaults->content,e->defaults->content);
-	while(e->defaults->next!=NULL){
-	  tmp->defaults->next=(iotype*)malloc(MAP_SIZE);
-	  addMapToMap(&tmp->defaults->next->content,e->defaults->content);
-	}
-      }
+#ifdef DEBUG
+	fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+	dumpMap(tmp->defaults->content);
+#endif
+      }else
+	tmp->defaults=NULL;
       if(e->supported!=NULL){
-	tmp->supported=(iotype*)malloc(MAP_SIZE);
+	tmp->supported=(iotype*)malloc(IOTYPE_SIZE);
 	tmp->supported->content=NULL;
 	tmp->supported->next=NULL;
 	addMapToMap(&tmp->supported->content,e->supported->content);
+	iotype *etmp=*(&tmp->supported->next) ;
 	iotype *tmp2=e->supported->next;
 	while(tmp2!=NULL){
-	  tmp->supported->next=(iotype*)malloc(MAP_SIZE);
-	  addMapToMap(&tmp->supported->next->content,tmp2->content);
+	  etmp=(iotype*)malloc(IOTYPE_SIZE);
+	  etmp->content=NULL;
+	  addMapToMap(&etmp->content,tmp2->content);
+	  etmp->next=NULL;
+#ifdef DEBUG
+	  fprintf(stderr,">> %s %i\n",__FILE__,__LINE__);
+	  dumpMap(tmp->defaults->content);
+#endif
 	  tmp2=tmp2->next;
+	  etmp=etmp->next;
 	}
       }
-      tmp->next=NULL;
-      return tmp;
-    }
-    return NULL;
-  }
-
-  static void* addToElements(elements* m,elements* e){
-    elements* _cursor=m;
+      else
+	tmp->supported=NULL;
+      tmp->next=dupElements(cursor->next);
+    }
+    return tmp;
+  }
+
+  static void addToElements(elements** m,elements* e){
+    elements* _cursor=*m;
     elements* tmp=e;
     if(_cursor==NULL){
-      m=dupElements(tmp);
-      return NULL;
-    }
-    while(_cursor->next!=NULL)
-      _cursor=_cursor->next;
-    _cursor->next=dupElements(tmp);
-    return NULL;
-  }
-
-  static void* dumpService(service* s){
+      *m=dupElements(tmp);
+    }else{
+      while(_cursor->next!=NULL)
+	_cursor=_cursor->next;
+      _cursor->next=dupElements(tmp);
+    }
+  }
+
+  static void dumpService(service* s){
     fprintf(stderr,"++++++++++++++++++\nSERVICE [%s]\n++++++++++++++++++\n",s->name);
     if(s->content!=NULL){
@@ -475,8 +554,7 @@
     }
     fprintf(stderr,"++++++++++++++++++\n");
-    return NULL;
-  }
-
-  static void* mapsToCharXXX(maps* m,char*** c){
+  }
+
+  static void mapsToCharXXX(maps* m,char*** c){
     maps* tm=m;
     int i=0;
@@ -506,8 +584,7 @@
     }
     memcpy(c,tmp,10*10*1024);
-	return NULL;
-  }
-
-  static void* charxxxToMaps(char*** c,maps**m){
+  }
+
+  static void charxxxToMaps(char*** c,maps**m){
     maps* trorf=*m;
     int i,j;
@@ -526,10 +603,9 @@
 	  trorf->content=createMap(tmp[i][j],tmp[i][j+1]);
 	else
-	addMapToMap(&trorf->content,createMap(tmp[i][j],tmp[i][j+1]));
+	  addToMap(trorf->content,tmp[i][j],tmp[i][j+1]);
       }
       trorf=trorf->next;
     }
     m=&trorf;
-    return NULL;
   }
 
Index: trunk/zoo-kernel/service_conf.l
===================================================================
--- trunk/zoo-kernel/service_conf.l	(revision 8)
+++ trunk/zoo-kernel/service_conf.l	(revision 9)
@@ -124,5 +124,5 @@
 /*====================================================*/
 attname	[a-zA-Z0-9_\-]+
-attvalue1	[a-zA-Z0-9_\-.:" "\"\'/\\\(\)]+
+attvalue1	[\*\+,;@a-zA-Z0-9_\-::.:" "\"\'/\\\(\)]+
 
 
@@ -159,55 +159,55 @@
 {newline}+{whitesp}*			{  if (affichetrace==1) fprintf (stderr,"\n\nNEWLINE 1\n") ; return NEWLINE;}
 
-<INITIAL,HORSBALISE>"["{attname}"]"             {  if (affichetrace==1){ fprintf (stderr,"\n\nANID:%s\n",yytext); fprintf(stderr,"[ZOO: service_conf.l line 161 srlval.chaine=strdup(%s), srlval.chaine=%s]\n",yytext,srlval.chaine);fflush(stderr);}srlval.chaine=strdup(yytext);srlval.chaine[strlen(srlval.chaine)-1]=0;srlval.chaine+=1;if (affichetrace==1){fprintf(stderr,"[ZOO: service_conf.l line 161 srlval.chaine=strdup(%s) done]\n",yytext);fflush(stderr);} return ANID; }
-
-<INITIAL,HORSBALISE>{attname}             {  if (affichetrace==1){fprintf (stderr,"\n\nATT_NAME:%s\n",yytext); fprintf(stderr,"[ZOO: service_conf.l line 163 srlval.chaine=strdup(%s)]\n",yytext);fflush(stderr);}srlval.chaine=strdup(yytext); if (affichetrace==1){fprintf(stderr,"[ZOO: service_conf.l line 163 srlval.chaine=strdup(%s) done]\n",yytext);fflush(stderr);} return SPAIR; }
-
-<PAIRSTART,HORSBALISE>{attvalue1}             { if (affichetrace==1){ fprintf (stderr,"\n\nATT_VALUE:%s\n",yytext);fprintf(stderr,"[ZOO: service_conf.l line 165 srlval.chaine=strdup(%s)]\n",yytext);fflush(stderr);}srlval.chaine=strdup(yytext);if (affichetrace==1){fprintf(stderr,"[ZOO: service_conf.l line 165 srlval.chaine=strdup(%s)]\n",yytext);fflush(stderr);BEGIN(INITIAL);} return EPAIR;}
+<INITIAL,HORSBALISE>"["{attname}"]"             {  srlval.chaine=yytext;return ANID; }
+
+<INITIAL,HORSBALISE>{attname}             {  srlval.chaine=yytext; return SPAIR; }
+
+<PAIRSTART,HORSBALISE>{attvalue1}             { srlval.chaine=yytext;/*BEGIN(INITIAL);*/ return EPAIR;}
 
 <PAIRSTART,INITIAL,HORSBALISE>{whitesp}*"="{whitesp}*             {  BEGIN(PAIRSTART);}
 
-<PAIRSTART,INITIAL,HORSBALISE,DANSBALISE>{newline}+{whitesp}*             { if (affichetrace==1) fprintf (stderr,"\n\nNEWLINE 2\n") ; BEGIN(INITIAL);  return NEWLINE;}
-
-<INITIAL>"<?"[Xx][Mm][Ll]  {   if (attentionImpossibleDeTrouverXMLDeclapres == 1 || attentionImpossibleDeTrouverPIapres == 1) {/* il y a eut un commentaire ou une balise applicative avant la declaration xml */ fprintf(stderr,"\nerror : a la ligne %d : il y a eut un commentaire ou un PI avant la declaration xml\n",srlineno); exit (10) ; } ; if (affichetrace==1) fprintf (stderr,"\n\nSTARTXMLDECL:%s\n",srtext) ;  return STARTXMLDECL;}
-
-<INITIAL>"version"{egalevolue}\"1.0\"|"version"{egalevolue}\'1.0\'  {  if (affichetrace==1) fprintf (stderr,"\n\nVERSIONDECL:%s\n",srtext) ;return VERSIONDECL;  }
+<PAIRSTART,INITIAL,HORSBALISE,DANSBALISE>{newline}+{whitesp}*             { BEGIN(INITIAL);  return NEWLINE;}
+
+<INITIAL>"<?"[Xx][Mm][Ll]  {   if (attentionImpossibleDeTrouverXMLDeclapres == 1 || attentionImpossibleDeTrouverPIapres == 1) {/* il y a eut un commentaire ou une balise applicative avant la declaration xml */ fprintf(stderr,"\nerror : a la ligne %d : il y a eut un commentaire ou un PI avant la declaration xml\n",srlineno); exit (10) ; } ; return STARTXMLDECL;}
+
+<INITIAL>"version"{egalevolue}\"1.0\"|"version"{egalevolue}\'1.0\'  { return VERSIONDECL;  }
 <INITIAL>"version"{egalevolue}\"[^"]*\"|"version"{egalevolue}\'[^']*\'  {/* erreur de version encoding */ fprintf(stderr,"\nerror : a la ligne %d : la version xml n est pas reconnue : %s\n",srlineno,yytext); exit (9) ; }
 
 
-<INITIAL>"encoding"{egalevolue}\"[Ii][Ss][Oo]"-8859-1"\"|"encoding"{egalevolue}\'[Ii][Ss][Oo]"-8859-1"\'  { if (affichetrace==1) fprintf (stderr,"\n\nENCODINGDECL:%s\n",yytext) ; return ENCODINGDECL;}
+<INITIAL>"encoding"{egalevolue}\"[Ii][Ss][Oo]"-8859-1"\"|"encoding"{egalevolue}\'[Ii][Ss][Oo]"-8859-1"\'  { return ENCODINGDECL;}
 <INITIAL>"encoding"{egalevolue}\"[^"]*\"|"encoding"{egalevolue}\'[^']*\'  {/* erreur de version encoding */ 	fprintf(stderr,"\nerror : a la ligne %d : la version d encodage n est pas reconnue : %s\n",srlineno,yytext); exit (8) ; }
 
 
-<INITIAL>"standalone"{egalevolue}\"yes\"|"standalone"{egalevolue}\'yes\'|"standalone"{egalevolue}\"no\"|"standalone"{egalevolue}\'no\'  { if (affichetrace==1) fprintf (stderr,"\n\nSDDECL:%s\n",yytext) ; return SDDECL;}
+<INITIAL>"standalone"{egalevolue}\"yes\"|"standalone"{egalevolue}\'yes\'|"standalone"{egalevolue}\"no\"|"standalone"{egalevolue}\'no\'  { return SDDECL;}
 
 <INITIAL>"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\'|"standalone"{egalevolue}\"[^"]*\"|"standalone"{egalevolue}\'[^']*\'  { /* erreur de version encoding */ 	fprintf(stderr,"\nerror : a la ligne %d : la version standalone n est pas reconnue : %s\n",srlineno,yytext); exit (7) ; }
 
 
-<INITIAL>"?>"  { if (affichetrace==1) fprintf (stderr,"\n\nENDXMLDECL:%s\n",yytext) ; BEGIN(HORSBALISE); return ENDXMLDECL;}
-
-
-<DANSBALISE,INITIAL,HORSBALISE>{S}   { if (affichetrace==1) fprintf (stderr,"\n\nS:'%s'\n",yytext) ; }
-
-
-<HORSBALISE>"<?"[Xx][Mm][Ll]{S}({S}|{chardata})*"?>"|"<?"[Xx][Mm][Ll]"?>"	{ if (affichetrace==1) fprintf (stderr,"\n\nPIERROR:%s\n",yytext) ; return PIERROR;}
-<INITIAL,HORSBALISE>"<?"([^xX]|([xX][^mM])|([xX][mM][^lL]))({S}|([^?]|("?"[^>])))*"?>"		{ attentionImpossibleDeTrouverPIapres=1 ;  if (affichetrace==1) fprintf (stderr,"\n\nPI:%s\n",yytext) ; return PI;}
-
-
-<INITIAL,HORSBALISE>{newline}*"<"		    { if (affichetrace==1) fprintf (stderr,"\n\nINFCAR:%s\n",yytext) ; BEGIN(DANSBALISE); return INFCAR;}
-
-
-<DANSBALISE>">"			{ if (affichetrace==1) fprintf (stderr,"\n\nSUPCAR:%s\n",yytext) ; BEGIN(HORSBALISE);return SUPCAR;}
-
-
-<DANSBALISE>"/"		{if (affichetrace==1) fprintf (stderr,"\n\nSLASH:%s\n",yytext) ; return SLASH;}
-
-
-<DANSBALISE>{egalevolue}			{if (affichetrace==1) fprintf (stderr,"\n\nEq:'%s'\n",yytext) ; return Eq;}
-
-
-<DANSBALISE>{Name}			{if (affichetrace==1){fprintf (stderr,"\n\nID:%s\n",yytext) ; fprintf(stderr,"[ZOO: service_conf.l line 208 srlval.chaine=strdup(%s)]\n",yytext);fflush(stderr);}srlval.s=strdup(yytext);if (affichetrace==1){fprintf(stderr,"[ZOO: service_conf.l line 208 srlval.chaine=strdup(%s)]\n",yytext);fflush(stderr);}return ID;}
-
-
-<DANSBALISE>{attvalue}		{if (affichetrace==1) fprintf (stderr,"\n\nATTVALUE:%s\n",yytext) ; return ATTVALUE;}
+<INITIAL>"?>"  { BEGIN(HORSBALISE); return ENDXMLDECL;}
+
+
+<DANSBALISE,INITIAL,HORSBALISE>{S}   {  }
+
+
+<HORSBALISE>"<?"[Xx][Mm][Ll]{S}({S}|{chardata})*"?>"|"<?"[Xx][Mm][Ll]"?>"	{ return PIERROR;}
+<INITIAL,HORSBALISE>"<?"([^xX]|([xX][^mM])|([xX][mM][^lL]))({S}|([^?]|("?"[^>])))*"?>"		{ attentionImpossibleDeTrouverPIapres=1 ; return PI;}
+
+
+<INITIAL,HORSBALISE>{newline}*"<"		    { BEGIN(DANSBALISE); return INFCAR;}
+
+
+<DANSBALISE>">"			{ BEGIN(HORSBALISE);return SUPCAR;}
+
+
+<DANSBALISE>"/"		{return SLASH;}
+
+
+<DANSBALISE>{egalevolue}			{return Eq;}
+
+
+<DANSBALISE>{Name}			{srlval.chaine=strdup(yytext);return ID;}
+
+
+<DANSBALISE>{attvalue}		{return ATTVALUE;}
 
 
@@ -215,5 +215,5 @@
 
 
-<INITIAL,DANSBALISE,HORSBALISE>.|\n	{if (affichetrace==1) fprintf(stderr,"error : ligne %d : caractere non reconnu '%s'\n",srlineno,yytext);}
+<INITIAL,DANSBALISE,HORSBALISE>.|\n	{fprintf(stderr,"error : ligne %d : caractere non reconnu '%s'\n",srlineno,yytext);}
 
 %%
Index: trunk/zoo-kernel/service_conf.y
===================================================================
--- trunk/zoo-kernel/service_conf.y	(revision 8)
+++ trunk/zoo-kernel/service_conf.y	(revision 9)
@@ -13,5 +13,5 @@
 #include <ctype.h>
 #include <service.h>
-#include <vector>
+  //#include <vector>
 
 static int tmp_count=1;
@@ -65,6 +65,7 @@
 // srlex
 extern int srlex(void);
-
-vector<char*> lattribute;
+extern int srlex_destroy(void);
+
+//vector<char*> lattribute;
 
 %}
@@ -132,11 +133,11 @@
  : STag contentetoile ETag	
 {
-  if (strcmp($1,$3) != 0)
+  /*if (strcasecmp($1,$3) != 0)
     {
-      //srerror("Opening and ending tag mismatch");
       fprintf(stderr,"Opening and ending tag mismatch\n  ::details : tag '%s' et '%s' \n",$1,$3);
-      lattribute.clear();
+      //lattribute.clear();
       //return 1;
-    }
+      }*/
+  free($3);
 }
 // pour neutre
@@ -159,13 +160,13 @@
   /* parce que cet element est reconnu AVANT la balise fermante */
   /* et APRES l'analyse des eventuelles balises internes ou successeur */
-  lattribute.clear();
-	
+  //lattribute.clear();
+
   if(my_service->content==NULL){
 #ifdef DEBUG_SERVICE_CONF
     fprintf(stderr,"NO CONTENT\n");
 #endif
-    //addMapToMap(&my_service->content,current_content);
-    //freeMap(&current_content);
-    my_service->content=current_content;
+    addMapToMap(&my_service->content,current_content);
+    freeMap(&current_content);
+    free(current_content);
     current_content=NULL;
     my_service->metadata=NULL;
@@ -173,12 +174,9 @@
   }
 
-  if(strcmp($2,"DataInputs")==0){
+  if(strncasecmp($2,"DataInputs",10)==0){
     if(wait_mainmetadata==true){
-      if(my_service->metadata==NULL)
-	my_service->metadata=current_content;
-      else{
-	addMapToMap(&my_service->metadata,current_content);
-	freeMap(&current_content);
-      }
+      addMapToMap(&my_service->metadata,current_content);
+      freeMap(&current_content);
+      free(current_content);
       current_content=NULL;
     }
@@ -208,15 +206,24 @@
   }
   else
-    if(strcmp($2,"DataOutputs")==0){
+    if(strncasecmp($2,"DataOutputs",11)==0){
       if(wait_inputs==true){
 #ifdef DEBUG_SERVICE_CONF
 	fprintf(stderr,"(DATAOUTPUTS) DUP INPUTS current_element\n");
-#endif
-	if(my_service->inputs==NULL)
+	fprintf(stderr,"CURRENT_ELEMENT\n");
+	dumpElements(current_element);
+	fprintf(stderr,"SERVICE INPUTS\n");
+	dumpElements(my_service->inputs);
+	dumpService(my_service);
+#endif
+	if(my_service->inputs==NULL){
 	  my_service->inputs=dupElements(current_element);
+	  my_service->inputs->next=NULL;
+	}
 	else
-	  addToElements(my_service->inputs,current_element);
-#ifdef DEBUG_SERVICE_CONF
+	  addToElements(&my_service->inputs,current_element);
+#ifdef DEBUG_SERVICE_CONF
+	fprintf(stderr,"CURRENT_ELEMENT\n");
 	dumpElements(current_element);
+	fprintf(stderr,"SERVICE INPUTS\n");
 	dumpElements(my_service->inputs);
 	fprintf(stderr,"(DATAOUTPUTS) FREE current_element\n");
@@ -245,5 +252,5 @@
     }
     else
-      if(strcmp($2,"MetaData")==0){
+      if(strncasecmp($2,"MetaData",8)==0){
 	current_data=3;
 	if(current_element!=NULL){
@@ -263,23 +270,27 @@
       }
       else
-	if(strcmp($2,"ComplexData")==0 || strcmp($2,"LiteralData")==0
-	|| strcmp($2,"ComplexOutput")==0 || strcmp($2,"LiteralOutput")==0){
+	if(strncasecmp($2,"ComplexData",11)==0 || strncasecmp($2,"LiteralData",10)==0
+	   || strncasecmp($2,"ComplexOutput",13)==0 || strncasecmp($2,"LiteralOutput",12)==0){
 	  current_data=4;
 	  if(wait_metadata==true){
 	    if(current_content!=NULL){
-	      current_element->metadata=current_content;
+	      addMapToMap(&current_element->metadata,current_content);
 	      current_element->next=NULL;
 	      current_element->format=$2;
 	      current_element->defaults=NULL;
+	      current_element->supported=NULL;
+	      freeMap(&current_content);
+	      free(current_content);
 	    }
-	  }else{ // No MainMetaData
-	    //addMapToMap(&current_element->content,current_content);
-	    //freeMap(&current_content);
-	    //free(current_content);
-	    current_element->content=current_content;
+	  }else{ 
+	    // No MainMetaData
+	    addMapToMap(&current_element->content,current_content);
+	    freeMap(&current_content);
+	    free(current_content);
 	    current_element->metadata=NULL;
 	    current_element->next=NULL;
 	    current_element->format=$2;
 	    current_element->defaults=NULL;
+	    current_element->supported=NULL;
 	  }
 	  current_content=NULL;
@@ -287,10 +298,10 @@
 	}
 	else
-	  if(strcmp($2,"Default")==0){
+	  if(strncasecmp($2,"Default",7)==0){
 	    wait_defaults=true;
 	    current_data=5;
 	  }
 	  else
-	    if(strcmp($2,"Supported")==0){
+	    if(strncasecmp($2,"Supported",9)==0){
 	      wait_supporteds=true;
 	      if(wait_defaults==true){
@@ -304,8 +315,9 @@
   printf("* Identifiant : %s\n",$2);
 #endif
-		
   /* et on renvoie l'identifiant de balise afin de pouvoir le comparer */
   /* avec la balise jumelle fermante ! */
   $$ = $2 ;
+  /*if($2!=NULL)
+    free($2);*/
 }
  ;
@@ -338,13 +350,13 @@
   printf ("attribute : %s\n",$1) ;
 #endif
-  for(int i=0;i < lattribute.size(); i++)
+  /*for(int i=0;i < lattribute.size(); i++)
     {
       if (strcmp($1,lattribute.at(i)) == 0)
 	{
 	  fprintf (stderr,"attributs identiques : %d -- %s , %s",i,lattribute.at(i),$1) ;
-	  //srerror("attribut redondant !:");
 	}
     }
-  lattribute.push_back($1);
+    lattribute.push_back($1);*/
+  free($1);
 }
  ;
@@ -359,5 +371,5 @@
 //======================================================
 EmptyElemTag
- : INFCAR ID Attributeetoile SLASH SUPCAR	{lattribute.clear();/* voir Stag */}
+ : INFCAR ID Attributeetoile SLASH SUPCAR	{/*lattribute.clear();/* voir Stag */}
  ;
 //======================================================
@@ -387,7 +399,10 @@
     current_data=previous_data;
     if(current_element->defaults==NULL){
-      current_element->defaults=(iotype*)malloc(MAP_SIZE);
-    }
-    current_element->defaults->content=current_content;
+      current_element->defaults=(iotype*)malloc(IOTYPE_SIZE);
+      current_element->defaults->content=NULL;
+    }
+    addMapToMap(&current_element->defaults->content,current_content);
+    freeMap(&current_content);
+    free(current_content);
     current_element->defaults->next=NULL;
     wait_defaults=false;
@@ -398,27 +413,42 @@
     current_data=previous_data;
     if(current_element->supported==NULL){
-      current_element->supported=(iotype*)malloc(MAP_SIZE);
-      current_element->supported->content=current_content;
+      //addMapToIoType(&current_element->supported,current_content);
+      current_element->supported=(iotype*)malloc(IOTYPE_SIZE);
+      current_element->supported->content=NULL;
+      addMapToMap(&current_element->supported->content,current_content);
+      freeMap(&current_content);
+      free(current_content);
       current_element->supported->next=NULL;
-      /**
-       * Need to free this ressource (HERE ?)
+      current_content=NULL;
+    }
+    else{
+#ifdef DEBUG
+      // Currently we support only one supported format
+      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
+#endif
+      //addMapToIoType(&current_element->supported,current_content);
+      /*iotype* iotmp=*(&current_element->supported);
+      while(iotmp!=NULL){
+	dumpMap(iotmp->content);
+	iotmp=iotmp->next;
+      }
+      iotmp=(iotype*)malloc(IOTYPE_SIZE);
+      iotmp->content=NULL;
+      addMapToMap(&iotmp->content,current_content);
+      iotmp->next=NULL;
+      dumpElements(current_element);
+      fprintf(stderr,"SECOND SUPPORTED FORMAT MAP START !!!!\n");
+      dumpMap(current_content);
+      fprintf(stderr,"SECOND SUPPORTED FORMAT MAP END !!!!\n");*/
+      freeMap(&current_content);
       free(current_content);
-      */
-    }
-    else{ 
-      /*current_element->supported->next=(iotype*)malloc(sizeof(iotype*));
-      current_element->supported->next->content=NULL;
-      current_element->supported->next->next=NULL;
-      iotype* tmp1=current_element->supported;
-      while(tmp1!=NULL){
-	addMapToMap(&current_element->supported->next->content,current_content);
-	freeMap(&current_content);
-#ifdef DEBUG_SERVICE_CONF
-	fprintf(stderr,"LINE 409");
-#endif
-	free(current_content);
-	current_content=NULL;
-	tmp1=tmp1->next;
-	}*/
+      current_content=NULL;
+      /*freeMap(&iotmp->content);
+      free(&iotmp->content);
+      free(iotype);*/
+#ifdef DEBUG
+      // Currently we support only one supported format
+      fprintf(stderr,"SECOND SUPPORTED FORMAT !!!!\n");
+#endif
     }
     current_content=NULL;
@@ -472,5 +502,5 @@
 //======================================================
 
-pair: PAIR {  if(debug) fprintf(stderr,"PAIR FOUND !!\n"); }
+pair: PAIR {  if(debug) fprintf(stderr,"PAIR FOUND !!\n");if(curr_key!=NULL){free(curr_key);curr_key=NULL;} }
 | EPAIR {
 #ifdef DEBUG_SERVICE_CONF
@@ -495,16 +525,10 @@
     dumpMap(current_content);
     fprintf(stderr,"addToMap(current_content,%s,%s) !! \n",curr_key,$1); 
-    
-#endif
-    //map* tmp1=createMap(curr_key,$1);
+#endif
     addToMap(current_content,curr_key,$1);
-    //freeMap(&tmp1);
-    //free(tmp1);
 #ifdef DEBUG_SERVICE_CONF
     fprintf(stderr,"addToMap(current_content,%s,%s) end !! \n",curr_key,$1); 
 #endif    
   }
-  //free(curr_key);
-  curr_key=NULL;
 #ifdef DEBUG_SERVICE_CONF
   fprintf(stderr,"EPAIR FOUND !! \n"); 
@@ -513,6 +537,10 @@
   fflush(stderr);
 #endif
-  }
-| SPAIR  { curr_key=$1; if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); }
+  if(curr_key!=NULL){
+    free(curr_key);
+    curr_key=NULL;
+  }
+  }
+| SPAIR  { curr_key=strdup($1);/*free($1);*/if(debug) fprintf(stderr,"SPAIR FOUND !!\n"); }
  ;
 
@@ -522,5 +550,11 @@
   if(data==-1){
     data=1;
-    my_service->name=$1;
+    char *cen=strdup($1);
+    my_service->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+    cen[strlen(cen)-1]=0;
+    cen+=1;
+    sprintf(my_service->name,"%s",cen);
+    cen-=1;
+    free(cen);
     my_service->content=NULL;
     my_service->metadata=NULL;
@@ -530,33 +564,19 @@
     if(current_data==1){
       if(my_service->content!=NULL && current_element->name!=NULL){
-	//fprintf(stderr,"ELEMENT (%s)",current_element->name);
 	if(my_service->inputs==NULL){
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"count (%i) (%s)\n",tmp_count%2,$1);
-	  fflush(stderr);
-#endif
-	  //if(tmp_count==1){
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 464)DUP current_element\n");
-	  dumpElements(current_element);
-#endif
 	  my_service->inputs=dupElements(current_element);
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 466)FREE current_element\n");
-#endif
-	  freeElements(&current_element);
-	  current_element=NULL;
+	  my_service->inputs->next=NULL;
 	  tmp_count++;
 	}
 	else{
-	  addToElements(my_service->inputs,current_element);
-#ifdef DEBUG_SERVICE_CONF
-	  fprintf(stderr,"(DATAINPUTS - 6)FREE current_element (after adding to allread existing inputs)");
-#endif
-	  freeElements(&current_element);
+	  addToElements(&my_service->inputs,current_element);
 	}
 #ifdef DEBUG_SERVICE_CONF
+	fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
+	dumpElements(current_element);
+	fprintf(stderr,"(%s %d)FREE current_element (after adding to allread existing inputs)",__FILE__,__LINE__);
 	dumpElements(my_service->inputs);
 #endif
+	freeElements(&current_element);
 	free(current_element);
 	current_element=NULL;
@@ -582,5 +602,11 @@
 	fprintf(stderr,"(DATAINPUTS - 501) SET NAME OF current_element\n");
 #endif
-	current_element->name=strdup($1);
+	char *cen=strdup($1);
+	current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+	cen[strlen(cen)-1]=0;
+	cen+=1;
+	sprintf(current_element->name,"%s",cen);
+	cen-=1;
+	free(cen);
 #ifdef DEBUG_SERVICE_CONF
 	fprintf(stderr,"NAME IN %s (current - %s)\n",$1,current_element->name);
@@ -604,4 +630,5 @@
 	    if(my_service->inputs==NULL){
 	      my_service->inputs=dupElements(current_element);
+	      my_service->inputs->next=NULL;
 	    }
 	    else{
@@ -609,18 +636,15 @@
 	      fprintf(stderr,"LAST NAME IN %s (current - %s)\n",$1,current_element->name);
 #endif
-	      addToElements(my_service->inputs,current_element);
+	      addToElements(&my_service->inputs,current_element);
 	    }
 #ifdef DEBUG_SERVICE_CONF
 	    dumpElements(current_element);
-	    fprintf(stderr,"(DATAOUTPUTS - 531) FREE current_element\n");
+	    fprintf(stderr,"(DATAOUTPUTS) FREE current_element %s %i\n",__FILE__,__LINE__);
 #endif
 	    freeElements(&current_element);
-	    free(&current_element);
-#ifdef DEBUG_SERVICE_CONF
-	    fprintf(stderr,"free OUTPUTS\n");
-#endif
+	    free(current_element);
 	    current_element=NULL;
 #ifdef DEBUG_SERVICE_CONF
-	    fprintf(stderr,"(DATAOUTPUTS - 536) ALLOCATE current_element\n");
+	    fprintf(stderr,"(DATAOUTPUTS) ALLOCATE current_element %s %i\n",__FILE__,__LINE__);
 #endif
 	    current_element=(elements*)malloc(ELEMENTS_SIZE);
@@ -638,5 +662,11 @@
 	    fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n");
 #endif
-	    current_element->name=strdup($1);
+	    char *cen=strdup($1);
+	    current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+	    cen[strlen(cen)-1]=0;
+	    cen+=1;
+	    sprintf(current_element->name,"%s",cen);
+	    cen-=1;
+	    free(cen);
 	    current_element->content=NULL;
 	    current_element->metadata=NULL;
@@ -647,4 +677,5 @@
 	  }
 	  wait_inputs=false;
+	  dumpMap(current_content);
 	  current_content=NULL;
 	}
@@ -655,5 +686,14 @@
 	    fprintf(stderr,"(DATAOUTPUTS - 545) SET NAME OF current_element\n");
 #endif
-	    current_element->name=strdup($1);
+	    char *cen=strdup($1);
+	    current_element->name=(char*)malloc((strlen(cen)-1)*sizeof(char*));
+	    cen[strlen(cen)-1]=0;
+#ifdef DEBUG
+	    fprintf(stderr,"tmp %s\n",cen);
+#endif
+	    cen+=1;
+	    sprintf(current_element->name,"%s",cen);
+	    cen-=1;
+	    free(cen);
 	    current_element->content=NULL;
 	    current_element->metadata=NULL;
@@ -726,8 +766,7 @@
   if (srin==NULL){
     fprintf(stderr,"error : le fichier specifie n'existe pas ou n'est pas accessible en lecture\n") ;
-    return 22;
-  }
-
-  //printf(" ");
+    return -1;
+  }
+
   int resultatYYParse = srparse() ;
   
@@ -738,4 +777,7 @@
 #endif
       my_service->outputs=dupElements(current_element);
+      my_service->outputs->next=NULL;
+      freeElements(&current_element);
+      free(current_element);
       current_element=NULL;
     }
@@ -744,5 +786,5 @@
       fprintf(stderr,"(DATAOUTPUTS - 628) COPY current_element\n");
 #endif
-      addToElements(my_service->outputs,current_element);
+      addToElements(&my_service->outputs,current_element);
     }
 #ifdef DEBUG_SERVICE_CONF
@@ -750,9 +792,11 @@
 #endif
     freeElements(&current_element);
+    free(current_element);
+    current_element=NULL;
   }
   if(current_element!=NULL){
     freeElements(&current_element);
     fprintf(stderr,"LINE 709");
-    //free(current_element);
+    free(current_element);
     current_element=NULL;
   }
@@ -760,5 +804,5 @@
     freeMap(&current_content);
     fprintf(stderr,"LINE 715");
-    //free(current_content);
+    free(current_content);
     current_content=NULL;
   }
@@ -769,4 +813,5 @@
   *service=my_service;
 
+  srlex_destroy();
   return resultatYYParse;
 }
Index: trunk/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-kernel/service_internal.c	(revision 8)
+++ trunk/zoo-kernel/service_internal.c	(revision 9)
@@ -74,359 +74,75 @@
 }
 
-
-void printProcessResponse1(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){
-  if(getpid()==pid)
-    printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");  
+char *zCapitalize1(char *tmp){
+        char *res=strdup(tmp);
+        if(res[0]>=97 && res[0]<=122)
+                res[0]-=32;
+        return res;
+}
+
+char *zCapitalize(char *tmp){
+  int i=0;
+  char *res=strdup(tmp);
+  for(i=0;i<strlen(res);i++)
+    if(res[i]>=97 && res[i]<=122)
+      res[i]-=32;
+  return res;
+}
+
+
+int zooXmlSearchForNs(char* name){
+  int i;
+  int res=-1;
+  for(i=0;i<nbNs;i++)
+    if(strncasecmp(name,nsName[i],strlen(nsName[i]))==0){
+      res=i;
+      break;
+    }
+  return res;
+}
+
+int zooXmlAddNs(xmlNodePtr nr,char* url,char* name){
+#ifdef DEBUG
+  fprintf(stderr,"zooXmlAddNs %d \n",nbNs);
+#endif
+  int currId=-1;
+  if(nbNs==0){
+    nbNs++;
+    currId=0;
+    nsName[currId]=strdup(name);
+    usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
+  }else{
+    currId=zooXmlSearchForNs(name);
+    if(currId<0){
+      nbNs++;
+      currId=nbNs-1;
+      nsName[currId]=strdup(name);
+      usedNs[currId]=xmlNewNs(nr,BAD_CAST url,BAD_CAST name);
+    }
+  }
+  return currId;
+}
+
+void zooXmlCleanupNs(){
+  int j;
+#ifdef DEBUG
+  fprintf(stderr,"zooXmlCleanup %d\n",nbNs);
+#endif
+  for(j=nbNs-1;j>=0;j--){
+#ifdef DEBUG
+    fprintf(stderr,"zooXmlCleanup %d\n",j);
+#endif
+    if(j==0)
+      xmlFreeNs(usedNs[j]);
+    free(nsName[j]);
+    nbNs--;
+  }
+  nbNs=0;
+}
+
+xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){
+
   xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
-  xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  int buffersize;
-  time_t time1;  
-  time(&time1);
-  /**
-   * Create the document and its temporary root.
-   */
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  pseudor = xmlNewNode(ns, BAD_CAST "root");
-  ns_ows=xmlNewNs(pseudor,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
-  maps* tmp_maps=getMaps(m,"main");
-  if(tmp_maps!=NULL){
-    map* tmp=getMap(tmp_maps->content,"encoding");
-    if(tmp!=NULL){
-      doc->encoding = xmlCharStrdup(tmp->value);
-    }
-    else
-      doc->encoding = xmlCharStrdup("UTF-8");
-  }
-  
-  n = xmlNewNode(ns, BAD_CAST "ExecuteResponse");  
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");
-  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
-  char tmp[256];
-  char url[256];
-  memset(tmp,0,256);
-  memset(url,0,256);
-  if(tmp_maps!=NULL){
-    map* tmpm=getMap(tmp_maps->content,"serverAddress");
-    map* tmpm1=getMap(tmp_maps->content,"tmpUrl");
-    if(tmpm!=NULL && tmpm1!=NULL){
-      sprintf(url,"%s/%s/%s_%i.xml",tmpm->value,tmpm1->value,service,pid);
-    }
-	if(tmpm1!=NULL)
-      sprintf(tmp,"%s/",tmpm->value);
-  }
-
-  xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
-  if(status!=SERVICE_SUCCEEDED){
-    xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
-  }
-
-  nc = xmlNewNode(ns, BAD_CAST "Process");
-  map* tmp2=getMap(serv->content,"processVersion");
-
-  if(tmp2!=NULL)
-    xmlNewProp(nc,BAD_CAST "wps:processVersion",BAD_CAST tmp2->value);
-  
-  printDescription(nc,ns_ows,serv->name,serv->content);
-  fflush(stderr);
-
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns, BAD_CAST "Status");
-  const struct tm *tm;
-  size_t len;
-  time_t now;
-  char *tmp1;
-  
-  now = time ( NULL );
-  tm = localtime ( &now );
-
-  tmp1 = new char[TIME_SIZE];
-
-  len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
-
-  switch(status){
-  case SERVICE_SUCCEEDED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
-    break;
-  case SERVICE_STARTED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
-    xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST "NEED_SERVICE_ACCESS"); 
-    break;
-  case SERVICE_ACCEPTED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
-    break;
-  case SERVICE_FAILED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
-    break;
-  default :
-    printf("error code not know : %i\n",status);
-    exit(1);
-    break;
-  }
-  xmlAddChild(nc,nc1);
-  xmlAddChild(n,nc);
-
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 161\n");
-#endif
-
-  map* lineage=getMap(request,"lineage");
-  if(lineage!=NULL){
-    nc = xmlNewNode(ns, BAD_CAST "DataInputs");
-    int i;
-    maps* mcursor=inputs;
-    elements* scursor=serv->inputs;
-    while(mcursor!=NULL && scursor!=NULL){
-      printIOType1(doc,nc,ns,ns_ows,scursor,mcursor,"Input");
-      mcursor=mcursor->next;
-      scursor=scursor->next;
-    }
-    xmlAddChild(n,nc);
-    
-#ifdef DEBUG
-    fprintf(stderr,"printProcessResponse 1 177\n");
-#endif
-
-    nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
-    mcursor=outputs;
-    scursor=serv->outputs;
-    while(mcursor!=NULL /*&& scursor!=NULL*/){
-      printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-      mcursor=mcursor->next;
-      //scursor=scursor->next;
-    }
-    xmlAddChild(n,nc);
-  }
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 190\n");
-#endif
-
-  /**
-   * Display the process output only when requested !
-   */
-  if(status==SERVICE_SUCCEEDED){
-    nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
-    maps* mcursor=outputs;
-    elements* scursor=serv->outputs;
-    while(mcursor!=NULL/* && scursor!=NULL*/){
-      //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata"));
-      printIOType1(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-      mcursor=mcursor->next;
-      //scursor=scursor->next;
-    }
-    xmlAddChild(n,nc);
-  }
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 202\n");
-#endif
-
-  xmlAddChild(nr,n);
-  xmlDocSetRootElement(doc, n);
-
-  /*
-   * Dump the document to a buffer and print it
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  xmlFree(nr);
-  xmlFreeDoc(doc);
-
-}
-
-
-void printProcessResponse(maps* m,int pid,service* serv,char* service,int status,map* inputs,map* outputs){
-  
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
-  xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  int buffersize;
-  time_t time1;  
-  time(&time1);
-  /**
-   * Create the document and its temporary root.
-   */
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  pseudor = xmlNewNode(ns, BAD_CAST "root");
-  ns_ows=xmlNewNs(pseudor,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
-  maps* tmp_maps=getMaps(m,"main");
-  if(tmp_maps!=NULL){
-    map* tmp=getMap(tmp_maps->content,"encoding");
-    if(tmp!=NULL){
-      doc->encoding = xmlCharStrdup(tmp->value);
-    }
-    else
-      doc->encoding = xmlCharStrdup("UTF-8");
-  }
-  
-  n = xmlNewNode(ns, BAD_CAST "ExecuteResponse");  
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");
-  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
-  char tmp[256];
-  char url[256];
-  memset(tmp,0,256);
-  memset(url,0,256);
-  if(tmp_maps!=NULL){
-    map* tmpm=getMap(tmp_maps->content,"serverAddress");
-    if(tmpm!=NULL){
-      sprintf(url,"%s/temp/%s_%i.xml",tmpm->value,service,pid);
-      sprintf(tmp,"%s/%s",tmpm->value,service);
-    }
-  }
-
-  //sprintf(tmp,"%s/%s",SERVICE_URL,service);
-  xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
-  //memset(tmp,0,256);
-  
-  
-  if(status!=SERVICE_SUCCEEDED){
-    xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
-  }
-
-
-  nc = xmlNewNode(ns, BAD_CAST "Process");
-  map* tmp2=getMap(serv->content,"processVersion");
-
-  if(tmp2!=NULL)
-    xmlNewProp(nc,BAD_CAST "wps:processVersion",BAD_CAST tmp2->value);
-  
-  printDescription(nc,ns_ows,serv->name,serv->content);
-  fflush(stderr);
-
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns, BAD_CAST "Status");
-  const struct tm *tm;
-  size_t len;
-  time_t now;
-  char *tmp1;
-  
-  now = time ( NULL );
-  tm = localtime ( &now );
-
-  tmp1 = new char[TIME_SIZE];
-
-  len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
-
-  switch(status){
-  case SERVICE_SUCCEEDED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
-    break;
-  case SERVICE_STARTED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
-    xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST "NEED_SERVICE_ACCESS"); 
-    break;
-  case SERVICE_ACCEPTED:
-    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
-    break;
-  case SERVICE_FAILED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
-    break;
-  default :
-    printf("error code not know : %i\n",status);
-    exit(1);
-    break;
-  }
-  xmlAddChild(nc,nc1);
-  xmlAddChild(n,nc);
-
-  fprintf(stderr,"printProcessResponse 1\n");
-
-  nc = xmlNewNode(ns, BAD_CAST "DataInputs");
-  int i;
-  map* mcursor=inputs;
-  elements* scursor=serv->inputs;
-  while(mcursor!=NULL && scursor!=NULL){
-    //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for input format from metadata"));
-    printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Input");
-    mcursor=mcursor->next;
-    scursor=scursor->next;
-  }
-  xmlAddChild(n,nc);
-
-  fprintf(stderr,"printProcessResponse 1\n");
-
-  nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
-  mcursor=outputs;
-  scursor=serv->outputs;
-  //dumpMap(mcursor);
-  while(mcursor!=NULL && scursor!=NULL){
-    //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata"));
-    printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-    mcursor=mcursor->next;
-    scursor=scursor->next;
-  }
-  xmlAddChild(n,nc);
-
-  fprintf(stderr,"printProcessResponse 1\n");
-  
-  nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
-  mcursor=outputs;
-  scursor=serv->outputs;
-  while(mcursor!=NULL && scursor!=NULL){
-    //xmlAddChild(nc,xmlNewComment(BAD_CAST "Here we need to check for output format from metadata"));
-    printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-    mcursor=mcursor->next;
-    scursor=scursor->next;
-  }
-  xmlAddChild(n,nc);
-  fprintf(stderr,"printProcessResponse 1\n");
-
-  xmlAddChild(nr,n);
-  xmlDocSetRootElement(doc, n);
-
-  /*
-   * Dump the document to a buffer and print it
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  xmlFreeDoc(doc);
-
-}
-
-
-void printGetCapabilitiesResponse(service** serv,int sc,char* service,maps* m){
-
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-  xmlDocPtr doc;
+  xmlNodePtr n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
   xmlChar *xmlbuff;
   int buffersize;
@@ -434,26 +150,17 @@
    * Create the document and its temporary root.
    */
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
+  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
+  ns=usedNs[wpsId];
   maps* toto1=getMaps(m,"main");
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"encoding");
-    if(tmp!=NULL){
-      doc->encoding = xmlCharStrdup(tmp->value);
-    }
-    else
-      doc->encoding = xmlCharStrdup("UTF-8");
-  }
-  else
-    doc->encoding = xmlCharStrdup ("UTF-8");
-
-  n = xmlNewNode(ns, BAD_CAST "Capabilities");  
-  ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
+
+  n = xmlNewNode(ns, BAD_CAST "Capabilities");
+  int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
+  ns_ows=usedNs[owsId];
   xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd");
+  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
+  ns_xsi=usedNs[xsiId];
+  int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
+  ns_xlink=usedNs[xlinkId];
+  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd"); 
   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
   
@@ -476,315 +183,9 @@
     map* tmp2=tmp4->content;
     while(tmp2!=NULL){
-      if(strcmp(tmp2->name,"keywords")!=0 &&
-	 strcmp(tmp2->name,"serverAddress")!=0 &&
-	 strcmp(tmp2->name,"lang")!=0 &&
-	 strcmp(tmp2->name,"encoding")!=0 &&
-	 strcmp(tmp2->name,"version")!=0){
-	tmp2->name[0]=toupper(tmp2->name[0]);
-	nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	xmlAddChild(nc,nc1);
-      }
-      else
-	if(strcmp(tmp2->name,"keywords")==0){
-	  nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
-	  char *toto=tmp2->value;
-	  char buff[256];
-	  int i=0;
-	  int j=0;
-	  while(toto[i]){
-	    if(toto[i]!=',' && toto[i]!=0){
-	      buff[j]=toto[i];
-	      buff[j+1]=0;
-	      j++;
-	    }
-	    else{
-	      nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	      xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	      xmlAddChild(nc1,nc2);
-	      j=0;
-	    }
-	    i++;
-	  }
-	  if(strlen(buff)>0){
-	    nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	    xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	    xmlAddChild(nc1,nc2);
-	  }
-	  xmlAddChild(nc,nc1);
-	}
-      tmp2=tmp2->next;
-    }
-  }
-  else{
-    fprintf(stderr,"TMP4 NOT FOUND !!");
-    //dumpMaps(tmp4);
-    return;
-  }
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceProvider");
-  nc3 = xmlNewNode(ns_ows, BAD_CAST "ServiceContact");
-  nc4 = xmlNewNode(ns_ows, BAD_CAST "ContactInfo");
-  nc5 = xmlNewNode(ns_ows, BAD_CAST "Phone");
-  nc6 = xmlNewNode(ns_ows, BAD_CAST "Address");
-  tmp4=getMaps(m,"provider");
-  if(tmp4!=NULL){
-    map* tmp2=tmp4->content;
-    while(tmp2!=NULL){
-      if(strcmp(tmp2->name,"keywords")!=0 &&
-	 strcmp(tmp2->name,"serverAddress")!=0 &&
-	 strcmp(tmp2->name,"lang")!=0){
-	tmp2->name[0]=toupper(tmp2->name[0]);
-	if(strcmp(tmp2->name,"ProviderName")==0 || 
-	   strcmp(tmp2->name,"ProviderSite")==0){
-	  nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	  xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	  xmlAddChild(nc,nc1);
-	}
-	else{
-	  if(strcmp(tmp2->name,"IndividualName")==0 || 
-	     strcmp(tmp2->name,"PositionName")==0){
-	    nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	    xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	    xmlAddChild(nc3,nc1);
-	  } 
-	  else 
-	    if(strncmp(tmp2->name,"Phone",5)==0){
-	      char *toto=NULL;
-	      char *toto1=tmp2->name;
-	      toto=strstr(toto1,"Phone");
-	      nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+5);
-	      xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-	      xmlAddChild(nc5,nc1);
-	    }
-	    else 
-	      if(strncmp(tmp2->name,"Address",7)==0){
-		char *toto=NULL;
-		char *toto1=tmp2->name;
-		toto=strstr(toto1,"Address");
-		nc1 = xmlNewNode(ns_ows, BAD_CAST toto1+7);
-		xmlAddChild(nc1,xmlNewText(BAD_CAST tmp2->value));
-		xmlAddChild(nc6,nc1);
-	      }
-	}
-      }
-      else
-	if(strcmp(tmp2->name,"keywords")==0){
-	  nc1 = xmlNewNode(ns_ows, BAD_CAST "Keywords");
-	  char *toto=tmp2->value;
-	  char buff[256];
-	  int i=0;
-	  int j=0;
-	  while(toto[i]){
-	    if(toto[i]!=',' && toto[i]!=0){
-	      buff[j]=toto[i];
-	      buff[j+1]=0;
-	      j++;
-	    }
-	    else{
-	      nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	      xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	      xmlAddChild(nc1,nc2);
-	      j=0;
-	    }
-	    i++;
-	  }
-	  if(strlen(buff)>0){
-	    nc2 = xmlNewNode(ns_ows, BAD_CAST "Keyword");
-	    xmlAddChild(nc2,xmlNewText(BAD_CAST buff));	      
-	    xmlAddChild(nc1,nc2);
-	  }
-	  xmlAddChild(nc,nc1);
-	}
-      tmp2=tmp2->next;
-    }
-  }
-  else{
-    fprintf(stderr,"TMP4 NOT FOUND !!");
-    //dumpMaps(tmp4);
-  }
-  xmlAddChild(nc4,nc5);
-  xmlAddChild(nc4,nc6);
-  xmlAddChild(nc3,nc4);
-  xmlAddChild(nc,nc3);
-  xmlAddChild(n,nc);
-
-
-  nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata");
-  char *tmp2[3];
-  tmp2[0]="GetCapabilities";
-  tmp2[1]="DescribeProcess";
-  tmp2[2]="Execute";
-  int j=0;
-
-
-  for(j=0;j<3;j++){
-    nc1 = xmlNewNode(ns_ows, BAD_CAST "Operation");
-    xmlNewProp(nc1,BAD_CAST "name",BAD_CAST tmp2[j]);
-    nc2 = xmlNewNode(ns_ows, BAD_CAST "DCP");
-    nc3 = xmlNewNode(ns_ows, BAD_CAST "HTTP");
-    nc4 = xmlNewNode(ns_ows, BAD_CAST "Get");
-    sprintf(tmp,"%s/%s",SERVICE_URL,service);
-    xmlNewProp(nc4,BAD_CAST "xlink:href",BAD_CAST tmp);
-    xmlAddChild(nc3,nc4);
-    if(j>0){
-      nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
-      xmlNewProp(nc4,BAD_CAST "xlink:href",BAD_CAST tmp);
-      xmlAddChild(nc3,nc4);
-    }
-    xmlAddChild(nc2,nc3);
-    xmlAddChild(nc1,nc2);    
-    xmlAddChild(nc,nc1);    
-  }
-  xmlAddChild(n,nc);
-
-
-  nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings");
-  /**
-   * Need to loop over various operations
-   */
-  int cursor=0;
-  map* tmp1;
-  for(cursor=0;cursor<sc;cursor++){
-    //dumpService(serv[cursor]);
-    if(serv[cursor]->content!=NULL){
-      nc1 = xmlNewNode(ns, BAD_CAST "Process");
-      tmp1=getMap(serv[cursor]->content,"processVersion");
-      if(tmp1!=NULL)
-	xmlNewProp(nc1,BAD_CAST "wps:processVersion",BAD_CAST tmp1->value);
-      
-      printDescription(nc1,ns_ows,serv[cursor]->name,serv[cursor]->content);
-      tmp1=serv[cursor]->metadata;
-      while(tmp1!=NULL){
-	nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-	xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-	xmlAddChild(nc1,nc2);
-	tmp1=tmp1->next;
-      }
-      xmlAddChild(nc,nc1);
-      xmlAddChild(n,nc);
-    }
-  }
-
-
-  nc1 = xmlNewNode(ns, BAD_CAST "Languages");
-  nc2 = xmlNewNode(ns, BAD_CAST "Default");
-  nc3 = xmlNewNode(ns, BAD_CAST "Supported");
-  
-  toto1=getMaps(m,"main");
-  if(toto1!=NULL){
-    tmp1=getMap(toto1->content,"lang");
-    char *toto=tmp1->value;
-    char buff[256];
-    int i=0;
-    int j=0;
-    int dcount=0;
-    while(toto[i]){
-      if(toto[i]!=',' && toto[i]!=0){
-	buff[j]=toto[i];
-	buff[j+1]=0;
-	j++;
-      }
-      else{
-	nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
-	if(dcount==0){
-	  xmlAddChild(nc2,nc4);
-	  xmlAddChild(nc1,nc2);
-	  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST buff);
-	  dcount++;
-	}
-	nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-	xmlAddChild(nc4,xmlNewText(BAD_CAST buff));
-	xmlAddChild(nc3,nc4);
-	j=0;
-	buff[j]=0;
-      }
-      i++;
-    }
-    if(strlen(buff)>0){
-      nc4 = xmlNewNode(ns_ows, BAD_CAST "Language");
-      xmlAddChild(nc4,xmlNewText(BAD_CAST buff));	      
-      xmlAddChild(nc3,nc4);
-    }
-  }
-  xmlAddChild(nc1,nc3);
-  xmlAddChild(n,nc1);
-  
-  xmlDocSetRootElement(doc, n);
-    
-  /*
-   * Dump the document to a buffer and print it
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  //xmlFreeDoc(doc);
-
-}
-
-xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr doc,char* service,maps* m){
-
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-  //xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  int buffersize;
-  /**
-   * Create the document and its temporary root.
-   */
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
-  maps* toto1=getMaps(m,"main");
-  //doc = xmlNewDoc(BAD_CAST "1.0");
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"encoding");
-    if(tmp!=NULL){
-      doc->encoding = xmlCharStrdup(tmp->value);
-    }
-    else
-      doc->encoding = xmlCharStrdup("UTF-8");
-  }
-  else
-    doc->encoding = xmlCharStrdup ("UTF-8");
-
-  n = xmlNewNode(ns, BAD_CAST "Capabilities");  
-  ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd");
-  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
-  
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"version");
-    if(tmp!=NULL){
-      xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value);
-    }
-    else
-      xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  }
-  else
-    xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-
-  char tmp[256];
-  
-  nc = xmlNewNode(ns_ows, BAD_CAST "ServiceIdentification");
-  maps* tmp4=getMaps(m,"identification");
-  if(tmp4!=NULL){
-    map* tmp2=tmp4->content;
-    while(tmp2!=NULL){
-      if(strcmp(tmp2->name,"keywords")!=0 &&
-	 strcmp(tmp2->name,"serverAddress")!=0 &&
-	 strcmp(tmp2->name,"lang")!=0 &&
-	 strcmp(tmp2->name,"encoding")!=0 &&
-	 strcmp(tmp2->name,"version")!=0){
+      if(strncasecmp(tmp2->name,"keywords",8)!=0 &&
+	 strncasecmp(tmp2->name,"serverAddress",13)!=0 &&
+	 strncasecmp(tmp2->name,"lang",4)!=0 &&
+	 strncasecmp(tmp2->name,"encoding",8)!=0 &&
+	 strncasecmp(tmp2->name,"version",7)!=0){
 	tmp2->name[0]=toupper(tmp2->name[0]);
 	nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
@@ -857,5 +258,5 @@
 	  if(strcmp(tmp2->name,"ProviderSite")==0){
 	    nc1 = xmlNewNode(ns_ows, BAD_CAST tmp2->name);
-	    xmlNewProp(nc1,BAD_CAST "xlink:href",BAD_CAST tmp2->value);
+	    xmlNewNsProp(nc1,ns_xlink,BAD_CAST "href",BAD_CAST tmp2->value);
 	    xmlAddChild(nc,nc1);
 	  } 
@@ -931,7 +332,7 @@
   nc = xmlNewNode(ns_ows, BAD_CAST "OperationsMetadata");
   char *tmp2[3];
-  tmp2[0]="GetCapabilities";
-  tmp2[1]="DescribeProcess";
-  tmp2[2]="Execute";
+  tmp2[0]=strdup("GetCapabilities");
+  tmp2[1]=strdup("DescribeProcess");
+  tmp2[2]=strdup("Execute");
   int j=0;
 
@@ -942,8 +343,8 @@
     }
     else
-      SERVICE_URL = "not_found";
+      SERVICE_URL = strdup("not_found");
   }
   else
-    SERVICE_URL = "not_found";
+    SERVICE_URL = strdup("not_found");
 
   for(j=0;j<3;j++){
@@ -954,9 +355,9 @@
     nc4 = xmlNewNode(ns_ows, BAD_CAST "Get");
     sprintf(tmp,"%s/%s",SERVICE_URL,service);
-    xmlNewProp(nc4,BAD_CAST "xlink:href",BAD_CAST tmp);
+    xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
     xmlAddChild(nc3,nc4);
     if(j>0){
       nc4 = xmlNewNode(ns_ows, BAD_CAST "Post");
-      xmlNewProp(nc4,BAD_CAST "xlink:href",BAD_CAST tmp);
+      xmlNewNsProp(nc4,ns_xlink,BAD_CAST "href",BAD_CAST tmp);
       xmlAddChild(nc3,nc4);
     }
@@ -965,10 +366,10 @@
     xmlAddChild(nc,nc1);    
   }
+  for(j=2;j>=0;j--)
+    free(tmp2[j]);
   xmlAddChild(n,nc);
 
   nc = xmlNewNode(ns, BAD_CAST "ProcessOfferings");
   xmlAddChild(n,nc);
-
-
 
   nc1 = xmlNewNode(ns, BAD_CAST "Languages");
@@ -1017,16 +418,21 @@
   
   xmlDocSetRootElement(doc, n);
-
+  //xmlFreeNs(ns);
+  free(SERVICE_URL);
   return nc;
 }
 
 void printGetCapabilitiesForProcess(maps* m,xmlNodePtr nc,service* serv){
-
-  xmlNsPtr ns,ns_ows;
+  xmlNsPtr ns,ns_ows,ns_xlink;
   xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  ns_ows=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/ows/1.1.0",BAD_CAST "ows");
+  /**
+   * Initialize or get existing namspaces
+   */
+  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
+  ns=usedNs[wpsId];
+  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
+  ns_ows=usedNs[owsId];
+  int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
+  ns_xlink=usedNs[xlinkId];
 
   int cursor=0;
@@ -1036,13 +442,10 @@
     tmp1=getMap(serv->content,"processVersion");
     if(tmp1!=NULL)
-      xmlNewProp(nc1,BAD_CAST "wps:processVersion",BAD_CAST tmp1->value);
-    
+      xmlNewNsProp(nc1,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value);
     printDescription(nc1,ns_ows,serv->name,serv->content);
     tmp1=serv->metadata;
     while(tmp1!=NULL){
       nc2 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-      char toto[1024];
-      sprintf(toto,"xlink:%s",tmp1->name);
-      xmlNewProp(nc2,BAD_CAST toto,BAD_CAST tmp1->value);
+      xmlNewNsProp(nc2,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
       xmlAddChild(nc1,nc2);
       tmp1=tmp1->next;
@@ -1050,70 +453,47 @@
     xmlAddChild(nc,nc1);
   }
-  
-}
-
-void printDocument(xmlDocPtr doc){
-  rewind(stdout);
-  printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-  fflush(stdout);
+}
+
+xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){
+
+  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
+  xmlNodePtr n,nr;
   xmlChar *xmlbuff;
   int buffersize;
-  /*
-   * Dump the document to a buffer and print it on stdout
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  xmlFreeDoc(doc);
-}
-
-void printGetCapabilitiesDocument(xmlDocPtr doc){
-  printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-  xmlChar *xmlbuff;
-  int buffersize;
-  /*
-   * Dump the document to a buffer and print it on stdout
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-
-}
+
+  int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
+  ns=usedNs[wpsId];
+  n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");
+  int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
+  ns_ows=usedNs[owsId];
+  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
+  zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
+  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
+  ns_xsi=usedNs[xsiId];
   
-
-void printDescribeProcessResponse(service* serv,char* service){
-
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-  xmlDocPtr doc;
-  xmlChar *xmlbuff;
-  int buffersize;
-  /**
-   * Create the document and its temporary root.
-   */
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://schemas.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
-  doc = xmlNewDoc(BAD_CAST "1.0");
-  doc->encoding = xmlCharStrdup ("UTF-8");
-
-  n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");  
-  ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd");
+  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd");
   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
   xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
+  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
+
+  xmlDocSetRootElement(doc, n);
+
+  return n;
+}
+
+void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service* serv,int sc){
+  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
+  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
+
   char tmp[256];
+  n=nc;
   
+  int wpsId=zooXmlAddNs(NULL,"http://schemas.opengis.net/wps/1.0.0","wps");
+  ns=usedNs[wpsId];
+  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
+  ns_ows=usedNs[owsId];
+  int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
+  ns_xlink=usedNs[xlinkId];
+
   nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
   char *tmp4[3];
@@ -1127,5 +507,5 @@
     if(tmp1!=NULL){
       if(j==0)
-	xmlNewProp(nc,BAD_CAST "wps:processVersion",BAD_CAST tmp1->value);      
+	xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp1->value);      
       else
 	xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value);      
@@ -1142,5 +522,5 @@
   while(tmp1!=NULL){
     nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-    xmlNewProp(nc1,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
+    xmlNewNsProp(nc1,ns_xlink,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
     xmlAddChild(nc,nc1);
     tmp1=tmp1->next;
@@ -1173,5 +553,7 @@
     nc3 = xmlNewNode(NULL, BAD_CAST e->format);
     iotype* _tmp=e->defaults;
+    int datatype=0;
     if(_tmp!=NULL){
+      int isAnyValue=1;
       if(strcmp(e->format,"LiteralData")!=0){
 	nc4 = xmlNewNode(NULL, BAD_CAST "Default");
@@ -1181,323 +563,38 @@
 	nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
 	nc5 = xmlNewNode(NULL, BAD_CAST "Default");
+	datatype=1;
       }
       tmp1=_tmp->content;
+      int default1=0;
+      xmlNodePtr nc7;
       while(tmp1!=NULL){
 #ifdef DEBUG
 	printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
 #endif
-	if(strcmp(tmp1->name,"DataType")==0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	if(strncasecmp(tmp1->name,"DataType",8)==0){
+	  nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType");
 	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	  char tmp[1024];
 	  sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
-	  xmlNewProp(nc6,BAD_CAST "ows:reference",BAD_CAST tmp);
+	  xmlNewNsProp(nc6,ns_ows,BAD_CAST "reference",BAD_CAST tmp);
 	  xmlAddChild(nc3,nc6);
 	  tmp1=tmp1->next;
 	  continue;
 	}
-	if(strcmp(tmp1->name,"asReference")!=0 && 
-	   strcmp(tmp1->name,"DataType")!=0 && 
-	   strcmp(tmp1->name,"value")!=0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	  xmlAddChild(nc5,nc6);
-	}
-	else{
-	  if(strcmp(tmp1->name,"value")==0){
-	    nc6 = xmlNewNode(NULL, BAD_CAST "DefaultValue");
-	    xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	    xmlAddChild(nc3,nc6);
+	if(strcasecmp(tmp1->name,"asReference")!=0 && 
+	   strcasecmp(tmp1->name,"DataType")!=0 && 
+	   strncasecmp(tmp1->name,"AllowedValues",13)!=0 &&
+	   strcasecmp(tmp1->name,"value")!=0 &&
+	   strcasecmp(tmp1->name,"extension")!=0){
+	  if(datatype==0){
+	    char *tmp2=zCapitalize1(tmp1->name);
+	    nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
+	    free(tmp2);
 	  }
-	}
-	tmp1=tmp1->next;
-      }
-      xmlAddChild(nc4,nc5);
-      xmlAddChild(nc3,nc4);
-    }
-    xmlAddChild(nc2,nc3);
-    
-    _tmp=e->supported;
-    if(_tmp!=NULL){
-      if(strcmp(e->format,"LiteralData")!=0){
-	nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      }
-      else{
-	nc5 = xmlNewNode(NULL, BAD_CAST "Supported");
-	
-      }
-      tmp1=_tmp->content;
-      while(tmp1!=NULL){
-	/*if(strcmp(e->format,"LiteralData")==0)
-	  xmlAddChild(nc5,nc6);*/
-	nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	xmlAddChild(nc5,nc6);
-	tmp1=tmp1->next;
-      }
-      xmlAddChild(nc4,nc5);
-      if(strcmp(e->format,"LiteralData")!=0){
-	xmlAddChild(nc3,nc4);
-      }
-    }
-    if(strcmp(e->format,"LiteralData")!=0){
-      xmlAddChild(nc2,nc3);
-    }
-    xmlAddChild(nc1,nc2);
-    
-    
-    e=e->next;
-  }
-  xmlAddChild(nc,nc1);
-
-  nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
-  
-  e=serv->outputs;
-  while(e!=NULL){
-    nc2 = xmlNewNode(NULL, BAD_CAST "Output");
-    tmp1=getMap(e->content,"minOccurs");
-    if(tmp1){
-      xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-    }
-    tmp1=getMap(e->content,"maxOccurs");
-    if(tmp1){
-      xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-    }
-
-    printDescription(nc2,ns_ows,e->name,e->content);
-
-    nc3 = xmlNewNode(ns, BAD_CAST e->format);
-    fprintf(stderr,"LITERALDATA ? %s",e->format);
-    iotype* _tmp=e->defaults;
-    if(_tmp!=NULL){
-      if(strcmp(e->format,"LiteralData")!=0 &&
-	 strcmp(e->format,"LiteralOutput")!=0){
-	nc4 = xmlNewNode(NULL, BAD_CAST "Default");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      }   
-      else{
-	nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Default");
-      }
-
-      /*nc4 = xmlNewNode(NULL, BAD_CAST "Default");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      */
-      tmp1=_tmp->content;
-      while(tmp1!=NULL){
-#ifdef DEBUG
-	printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
-	fprintf(stderr,"DEBUG DATATYPE !!\n");
-	dumpMap(tmp1);
-#endif
-	if(strcmp(tmp1->name,"DataType")==0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	  char tmp[1024];
-	  sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
-	  xmlNewProp(nc6,BAD_CAST "ows:reference",BAD_CAST tmp);
-	  xmlAddChild(nc5,nc6);
-	  tmp1=tmp1->next;
-	  continue;
-	}
-	if(strcmp(tmp1->name,"asReference")!=0 && strcmp(tmp1->name,"DataType")!=0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	  xmlAddChild(nc5,nc6);
-	}
-	tmp1=tmp1->next;
-      }
-      xmlAddChild(nc4,nc5);
-      xmlAddChild(nc3,nc4);	    
-    }
-    _tmp=e->supported;
-    while(_tmp!=NULL){
-      nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
-      nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      tmp1=_tmp->content;
-      while(tmp1!=NULL){
-#ifdef DEBUG
-	printf("DATATYPE SUPPORTED ? %s\n",tmp1->name);
-#endif
-	if(strcmp(tmp1->name,"asReference")!=0 && strcmp(tmp1->name,"DataType")!=0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	  xmlAddChild(nc5,nc6);
-	}
-	tmp1=tmp1->next;
-      }
-      _tmp=_tmp->next;
-      xmlAddChild(nc4,nc5);
-      xmlAddChild(nc3,nc4);
-    }
-    xmlAddChild(nc2,nc3);
-
-    xmlAddChild(nc3,nc4);
-      
-    
-    xmlAddChild(nc2,nc3);
-    
-    xmlAddChild(nc1,nc2);
-    
-    e=e->next;
-  }
-  xmlAddChild(nc,nc1);
-
-  xmlAddChild(n,nc);
-
-  xmlDocSetRootElement(doc, n);
-    
-  /*
-   * Dump the document to a buffer and print it
-   * for demonstration purposes.
-   */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
-  
-  /*
-   * Free associated memory.
-   */
-  xmlFree(xmlbuff);
-  //xmlFreeDoc(doc);
-
-}
-
-xmlNodePtr printDescribeProcessHeader(xmlDocPtr doc,char* service,maps* m){
-
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  //xmlDocPtr doc;
-  xmlNodePtr n,nr;
-  xmlChar *xmlbuff;
-  int buffersize;
-  /**
-   * Create the document and its temporary root.
-   */
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://schemas.opengis.net/wps/1.0.0",BAD_CAST "wps");
-
-  /*doc = xmlNewDoc(BAD_CAST "1.0");
-    doc->encoding = xmlCharStrdup ("UTF-8");*/
-
-  n = xmlNewNode(ns, BAD_CAST "ProcessDescriptions");  
-  ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsDescribeProcess_response.xsd");
-  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
-
-  xmlDocSetRootElement(doc, n);
-
-  return n;
-}
-
-void printDescribeProcessForProcess(maps* m,xmlNodePtr nc,service** serv,int sc){
-  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
-  xmlNodePtr nr,n,nc1,nc2,nc3,nc4,nc5,nc6,pseudor;
-
-  char tmp[256];
-  n=nc;
-  nr = xmlNewNode(ns, BAD_CAST "root");
-  
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
-  ns_ows=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/ows/1.1.0",BAD_CAST "ows");
-
-  nc = xmlNewNode(NULL, BAD_CAST "ProcessDescription");
-  char *tmp4[3];
-  tmp4[0]="processVersion";
-  tmp4[1]="storeSupported";
-  tmp4[2]="statusSupported";
-  int j=0;
-  map* tmp1=NULL;
-  for(j=0;j<3;j++){
-    tmp1=getMap(serv[0]->content,tmp4[j]);
-    if(tmp1!=NULL){
-      if(j==0)
-	xmlNewProp(nc,BAD_CAST "wps:processVersion",BAD_CAST tmp1->value);      
-      else
-	xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST tmp1->value);      
-    }
-    else{
-      if(j>0)
-	xmlNewProp(nc,BAD_CAST tmp4[j],BAD_CAST "false");      
-    }
-  }
-  
-  printDescription(nc,ns_ows,serv[0]->name,serv[0]->content);
-
-  tmp1=serv[0]->metadata;
-  while(tmp1!=NULL){
-    nc1 = xmlNewNode(ns_ows, BAD_CAST "Metadata");
-    char toto[1024];
-    sprintf(toto,"xlink:%s",tmp1->name);
-    xmlNewProp(nc1,BAD_CAST toto,BAD_CAST tmp1->value);
-    xmlAddChild(nc,nc1);
-    tmp1=tmp1->next;
-  }
-
-  tmp1=getMap(serv[0]->content,"Profile");
-  if(tmp1!=NULL){
-    nc1 = xmlNewNode(ns, BAD_CAST "Profile");
-    xmlAddChild(nc1,xmlNewText(BAD_CAST tmp1->value));
-    xmlAddChild(nc,nc1);
-  }
-
-  nc1 = xmlNewNode(NULL, BAD_CAST "DataInputs");
-  
-  elements* e=serv[0]->inputs;
-  while(e!=NULL){
-    nc2 = xmlNewNode(NULL, BAD_CAST "Input");
-    tmp1=getMap(e->content,"minOccurs");
-    if(tmp1){
-      xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-    }
-    tmp1=getMap(e->content,"maxOccurs");
-    if(tmp1){
-      xmlNewProp(nc2,BAD_CAST tmp1->name,BAD_CAST tmp1->value);
-    }
-
-    printDescription(nc2,ns_ows,e->name,e->content);
-
-
-    nc3 = xmlNewNode(NULL, BAD_CAST e->format);
-    iotype* _tmp=e->defaults;
-    int datatype=0;
-    if(_tmp!=NULL){
-      if(strcmp(e->format,"LiteralData")!=0){
-	nc4 = xmlNewNode(NULL, BAD_CAST "Default");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
-      }
-      else{
-	nc4 = xmlNewNode(NULL, BAD_CAST "UOMs");
-	nc5 = xmlNewNode(NULL, BAD_CAST "Default");
-	datatype=1;
-      }
-      tmp1=_tmp->content;
-      int default1=0;
-      xmlNodePtr nc7;
-      while(tmp1!=NULL){
-#ifdef DEBUG
-	printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
-#endif
-	if(strcmp(tmp1->name,"DataType")==0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
-	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
-	  char tmp[1024];
-	  sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
-	  xmlNewProp(nc6,BAD_CAST "ows:reference",BAD_CAST tmp);
-	  xmlAddChild(nc3,nc6);
-	  tmp1=tmp1->next;
-	  continue;
-	}
-	if(strcmp(tmp1->name,"asReference")!=0 && 
-	   strcmp(tmp1->name,"DataType")!=0 && 
-	   strcmp(tmp1->name,"value")!=0){
-	  if(datatype==0)
-	  nc6 = xmlNewNode(NULL, BAD_CAST tmp1->name);
-	  else
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	  else{
+	    char *tmp2=zCapitalize(tmp1->name);
+	    nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
+	    free(tmp2);
+	  }
 	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	  xmlAddChild(nc5,nc6);
@@ -1509,4 +606,20 @@
 	    default1=1;
 	  }
+	  if(strncasecmp(tmp1->name,"AllowedValues",13)==0){
+	    nc6 = xmlNewNode(ns_ows, BAD_CAST "AllowedValues");
+	    char *token,*saveptr1;
+	    token=strtok_r(tmp1->value,",",&saveptr1);
+	    while(token!=NULL){
+	   	nc7 = xmlNewNode(ns_ows, BAD_CAST "Value");
+		char *tmps=strdup(token);
+		tmps[strlen(tmps)]=0;
+		xmlAddChild(nc7,xmlNewText(BAD_CAST tmps));
+		fprintf(stderr,"strgin : %s\n",tmps);
+		xmlAddChild(nc6,nc7);
+		token=strtok_r(NULL,",",&saveptr1);
+	    }
+	    xmlAddChild(nc3,nc6);
+	    isAnyValue=-1;
+	  }
 	}
 	tmp1=tmp1->next;
@@ -1514,14 +627,16 @@
       xmlAddChild(nc4,nc5);
       xmlAddChild(nc3,nc4);
-      if(datatype==1){
-		xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
-		if(default1>0)
-	    xmlAddChild(nc3,nc7);
-      }
+      if(datatype==1 && isAnyValue==1){
+	xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
+	if(default1>0)
+	  xmlAddChild(nc3,nc7);
+      }
+      if(datatype==1 && default1>0)
+      	xmlAddChild(nc3,nc7);
     }
     xmlAddChild(nc2,nc3);
     
     _tmp=e->supported;
-    if(_tmp!=NULL){
+    while(_tmp!=NULL){
       if(datatype==0){
 	nc4 = xmlNewNode(NULL, BAD_CAST "Supported");
@@ -1535,8 +650,14 @@
 	/*if(strcmp(e->format,"LiteralData")==0)
 	  xmlAddChild(nc5,nc6);*/
-	if(datatype==0)
-	nc6 = xmlNewNode(NULL, BAD_CAST tmp1->name);
-	else
-	nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	if(datatype==0){
+	  char *tmp2=zCapitalize1(tmp1->name);
+	  nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
+	  free(tmp2);
+	}
+	else{
+	  char *tmp2=zCapitalize(tmp1->name);	  
+	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
+	  free(tmp2);
+	}
 	xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	xmlAddChild(nc5,nc6);
@@ -1549,10 +670,11 @@
       	xmlAddChild(nc4,nc5);
 	//xmlAddChild(nc3,xmlNewNode(ns_ows, BAD_CAST "AnyValue"));
-	}
-    }
-    if(strcmp(e->format,"LiteralData")!=0){
-      xmlAddChild(nc2,nc3);
-    }
-    xmlAddChild(nc1,nc2);
+      }
+      _tmp=_tmp->next;
+      if(strcmp(e->format,"LiteralData")!=0){
+	xmlAddChild(nc2,nc3);
+      }
+      xmlAddChild(nc1,nc2);
+    }
     
     
@@ -1563,5 +685,5 @@
   nc1 = xmlNewNode(NULL, BAD_CAST "ProcessOutputs");
   
-  e=serv[0]->outputs;
+  e=serv->outputs;
   while(e!=NULL){
     nc2 = xmlNewNode(NULL, BAD_CAST "Output");
@@ -1577,8 +699,8 @@
     printDescription(nc2,ns_ows,e->name,e->content);
 
-    if(strcmp(mtoupper(e->format),"LITERALDATA")==0)
+    if(strncasecmp(e->format,"LITERALDATA",strlen(e->format))==0)
       nc3 = xmlNewNode(NULL, BAD_CAST "LiteralOutput");
     else
-      if(strcmp(mtoupper(e->format),"COMPLEXDATA")==0)
+      if(strncasecmp(e->format,"COMPLEXDATA",strlen(e->format))==0)
 	nc3 = xmlNewNode(NULL, BAD_CAST "ComplexOutput");
       else
@@ -1594,6 +716,6 @@
      }
       else{
-      nc4 = xmlNewNode(NULL, BAD_CAST "Default");
-      nc5 = xmlNewNode(NULL, BAD_CAST "Format");
+	nc4 = xmlNewNode(NULL, BAD_CAST "Default");
+	nc5 = xmlNewNode(NULL, BAD_CAST "Format");
       }
       tmp1=_tmp->content;
@@ -1602,10 +724,10 @@
 	printf("DATATYPE DEFAULT ? %s\n",tmp1->name);
 #endif
-	if(strcmp(tmp1->name,"DataType")==0){
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	if(strncasecmp(tmp1->name,"DataType",8)==0){
+	  nc6 = xmlNewNode(ns_ows, BAD_CAST "DataType");
 	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	  char tmp[1024];
 	  sprintf(tmp,"http://www.w3.org/TR/xmlschema-2/#%s",tmp1->value);
-	  xmlNewProp(nc6,BAD_CAST "ows:reference",BAD_CAST tmp);
+	  xmlNewNsProp(nc6,ns_xlink,BAD_CAST "reference",BAD_CAST tmp);
 	  xmlAddChild(nc3,nc6);
 	  tmp1=tmp1->next;
@@ -1613,9 +735,17 @@
 	  continue;
 	}
-	if(strcmp(tmp1->name,"asReference")!=0 && strcmp(tmp1->name,"DataType")!=0){
-	  if(datatype==0)
-	  nc6 = xmlNewNode(NULL, BAD_CAST tmp1->name);
-	  else
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	if(strcmp(tmp1->name,"asReference")!=0 &&
+	   strncasecmp(tmp1->name,"DataType",8)!=0 &&
+	   strcasecmp(tmp1->name,"extension")!=0){
+	  if(datatype==0){
+	    char *tmp2=zCapitalize1(tmp1->name);
+	    nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
+	    free(tmp2);
+	  }
+	  else{
+	    char *tmp2=zCapitalize(tmp1->name);
+	    nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
+	    free(tmp2);
+	  }
 	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	  xmlAddChild(nc5,nc6);
@@ -1639,9 +769,17 @@
 	printf("DATATYPE SUPPORTED ? %s\n",tmp1->name);
 #endif
-	if(strcmp(tmp1->name,"asReference")!=0 && strcmp(tmp1->name,"DataType")!=0){
-	  if(datatype==0)
-	  nc6 = xmlNewNode(NULL, BAD_CAST tmp1->name);
-	  else
-	  nc6 = xmlNewNode(ns_ows, BAD_CAST tmp1->name);
+	if(strcmp(tmp1->name,"asReference")!=0 && 
+	   strcmp(tmp1->name,"DataType")!=0 &&
+	   strcasecmp(tmp1->name,"extension")!=0){
+	  if(datatype==0){
+	    char *tmp2=zCapitalize1(tmp1->name);
+	    nc6 = xmlNewNode(NULL, BAD_CAST tmp2);
+	    free(tmp2);
+	  }
+	  else{
+	    char *tmp2=zCapitalize(tmp1->name);
+	    nc6 = xmlNewNode(ns_ows, BAD_CAST tmp2);
+	    free(tmp2);
+	  }
 	  xmlAddChild(nc6,xmlNewText(BAD_CAST tmp1->value));
 	  xmlAddChild(nc5,nc6);
@@ -1673,22 +811,187 @@
 }
 
-void printDescribeProcessDocument(xmlDocPtr doc){
+void printProcessResponse(maps* m,map* request, int pid,service* serv,char* service,int status,maps* inputs,maps* outputs){
+  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
+  xmlNodePtr nr,n,nc,nc1,nc2,nc3,pseudor;
+  xmlDocPtr doc;
+  xmlChar *xmlbuff;
+  int buffersize;
+  time_t time1;  
+  time(&time1);
+  /**
+   * Create the document and its temporary root.
+   */
+  doc = xmlNewDoc(BAD_CAST "1.0");
+  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
+  ns=usedNs[wpsId];
+  
+  n = xmlNewNode(ns, BAD_CAST "ExecuteResponse");
+  int owsId=zooXmlAddNs(n,"http://www.opengis.net/ows/1.1","ows");
+  ns_ows=usedNs[owsId];
+  int xlinkId=zooXmlAddNs(n,"http://www.w3.org/1999/xlink","xlink");
+  ns_xlink=usedNs[xlinkId];
+  int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
+  ns_xsi=usedNs[xsiId];
+  xmlNewNs(n,BAD_CAST "http://www.opengis.net/wps/1.0.0",BAD_CAST "wps");
+
+  xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsExecute_response.xsd");
+  
+  xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
+  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
+  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
+  char tmp[256];
+  char url[256];
+  memset(tmp,0,256);
+  memset(url,0,256);
+  maps* tmp_maps=getMaps(m,"main");
+  if(tmp_maps!=NULL){
+    map* tmpm=getMap(tmp_maps->content,"serverAddress");
+    map* tmpm1=getMap(tmp_maps->content,"tmpUrl");
+    if(tmpm!=NULL && tmpm1!=NULL){
+      sprintf(url,"%s/%s/%s_%i.xml",tmpm->value,tmpm1->value,service,pid);
+    }
+    if(tmpm!=NULL)
+      sprintf(tmp,"%s/",tmpm->value);
+  }
+
+  xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
+  if(status!=SERVICE_SUCCEEDED){
+    xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
+  }
+
+  nc = xmlNewNode(ns, BAD_CAST "Process");
+  map* tmp2=getMap(serv->content,"processVersion");
+
+  if(tmp2!=NULL)
+    xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
+  
+  printDescription(nc,ns_ows,serv->name,serv->content);
+  fflush(stderr);
+
+  xmlAddChild(n,nc);
+
+  nc = xmlNewNode(ns, BAD_CAST "Status");
+  const struct tm *tm;
+  size_t len;
+  time_t now;
+  char *tmp1;
+  
+  now = time ( NULL );
+  tm = localtime ( &now );
+
+  tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
+
+  len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
+
+  switch(status){
+  case SERVICE_SUCCEEDED:
+    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
+    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
+    break;
+  case SERVICE_STARTED:
+    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
+    nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
+    xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST "NEED_SERVICE_ACCESS"); 
+    break;
+  case SERVICE_ACCEPTED:
+    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
+    nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
+    break;
+  case SERVICE_FAILED:
+    nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
+    break;
+  default :
+    printf("error code not know : %i\n",status);
+    exit(1);
+    break;
+  }
+  xmlAddChild(nc,nc1);
+  xmlAddChild(n,nc);
+  free(tmp1);
+
+#ifdef DEBUG
+  fprintf(stderr,"printProcessResponse 1 161\n");
+#endif
+
+  map* lineage=getMap(request,"lineage");
+  if(lineage!=NULL){
+    nc = xmlNewNode(ns, BAD_CAST "DataInputs");
+    int i;
+    maps* mcursor=inputs;
+    elements* scursor=serv->inputs;
+    while(mcursor!=NULL /*&& scursor!=NULL*/){
+      printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Input");
+      mcursor=mcursor->next;
+      //scursor=scursor->next;
+    }
+    xmlAddChild(n,nc);
+    
+#ifdef DEBUG
+    fprintf(stderr,"printProcessResponse 1 177\n");
+#endif
+
+    nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
+    mcursor=outputs;
+    scursor=serv->outputs;
+    while(mcursor!=NULL /*&& scursor!=NULL*/){
+      printOutputDefinitions1(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
+      mcursor=mcursor->next;
+      //scursor=scursor->next;
+    }
+    xmlAddChild(n,nc);
+  }
+#ifdef DEBUG
+  fprintf(stderr,"printProcessResponse 1 190\n");
+#endif
+
+  /**
+   * Display the process output only when requested !
+   */
+  if(status==SERVICE_SUCCEEDED){
+    nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
+    maps* mcursor=outputs;
+    elements* scursor=serv->outputs;
+    while(mcursor!=NULL && scursor!=NULL){
+      printIOType(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
+      mcursor=mcursor->next;
+      scursor=scursor->next;
+    }
+    xmlAddChild(n,nc);
+  }
+#ifdef DEBUG
+  fprintf(stderr,"printProcessResponse 1 202\n");
+#endif
+  xmlDocSetRootElement(doc, n);
+  printDocument(m,doc,pid);
+
+  xmlCleanupParser();
+  zooXmlCleanupNs();
+}
+
+
+void printDocument(maps* m, xmlDocPtr doc,int pid){
+  rewind(stdout);
+  char *encoding=getEncoding(m);
+  if(pid==getpid()){
+    printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+  }
+  fflush(stdout);
   xmlChar *xmlbuff;
   int buffersize;
   /*
-   * Dump the document to a buffer and print it
+   * Dump the document to a buffer and print it on stdout
    * for demonstration purposes.
    */
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
   printf((char *) xmlbuff);
-  
+  //fflush(stdout);
   /*
    * Free associated memory.
    */
   xmlFree(xmlbuff);
-  //xmlFreeDoc(doc);
-
-}
-//printGetCapabilitiesHeader
+  xmlFreeDoc(doc);
+  xmlCleanupParser();
+  zooXmlCleanupNs();
+}
 
 void printOutputDefinitions1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
@@ -1705,8 +1008,8 @@
   }
   while(tmp!=NULL){
-    if(strcmp(mtoupper(tmp->name),"MIMETYPE")==0
-       || strcmp(mtoupper(tmp->name),"ENCODING")==0
-       || strcmp(mtoupper(tmp->name),"SCHEMA")==0
-       || strcmp(mtoupper(tmp->name),"UOM")==0)
+    if(strncasecmp(tmp->name,"MIMETYPE",strlen(tmp->name))==0
+       || strncasecmp(tmp->name,"ENCODING",strlen(tmp->name))==0
+       || strncasecmp(tmp->name,"SCHEMA",strlen(tmp->name))==0
+       || strncasecmp(tmp->name,"UOM",strlen(tmp->name))==0)
     xmlNewProp(nc1,BAD_CAST tmp->name,BAD_CAST tmp->value);
     tmp=tmp->next;
@@ -1752,18 +1055,27 @@
 }
 
-void printIOType1(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
+void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,maps* m,char* type){
   xmlNodePtr nc1,nc2,nc3;
   nc1=xmlNewNode(ns_wps, BAD_CAST type);
   map *tmp=e->content;
-#ifdef DEBUG
+  //#ifdef DEBUG
   dumpMap(tmp);
   dumpElements(e);
-#endif
+  //#endif
   nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
-  xmlAddChild(nc2,xmlNewText(BAD_CAST m->name));
+  nc3=xmlNewText(BAD_CAST e->name);
+  xmlAddChild(nc2,nc3);
   xmlAddChild(nc1,nc2);
   xmlAddChild(nc,nc1);
+  // Extract Title required to be first element in the ZCFG file !
   nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-  xmlAddChild(nc2,xmlNewText(BAD_CAST tmp->value));
+  nc3=xmlNewText(BAD_CAST tmp->value);
+  xmlAddChild(nc2,nc3);  
+  xmlAddChild(nc1,nc2);
+  // Extract Abstract required to be second element in the ZCFG file !
+  tmp=tmp->next;
+  nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
+  nc3=xmlNewText(BAD_CAST tmp->value);
+  xmlAddChild(nc2,nc3);  
   xmlAddChild(nc1,nc2);
   xmlAddChild(nc,nc1);
@@ -1773,90 +1085,67 @@
    * IO type Reference or full Data ?
    */
-#ifdef DEBUG
-  fprintf(stderr,"FORMAT %s %s\n",e->format,mtoupper(e->format));
-#endif
-  nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
-  if(strcmp(mtoupper(e->format),"LITERALOUTPUT")==0)
-    nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
-  else
-    if(strcmp(mtoupper(e->format),"COMPLEXOUTPUT")==0)
-      nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
+  //#ifdef DEBUG
+  fprintf(stderr,"FORMAT %s %s\n",e->format,e->format);
+  //#endif
+  map *tmpMap=getMap(m->content,"Reference");
+  if(tmpMap==NULL){
+    nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
+    if(strncasecmp(e->format,"LITERALOUTPUT",strlen(e->format))==0)
+      nc3=xmlNewNode(ns_wps, BAD_CAST "LiteralData");
     else
-      nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
-  tmp=m->content;
-  while(tmp!=NULL){
-    if(strcmp(tmp->name,"value")!=0)
-      xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
-    tmp=tmp->next;
-    xmlAddChild(nc2,nc3);
-  }
-  tmp=getMap(e->defaults->content,"mimeType");
-  map* tmp1=getMap(m->content,"encoding");
-  map* tmp2=getMap(m->content,"mimeType");
-  map* toto=getMap(m->content,"value");
-  if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0)
-     || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0
-			|| strncmp(tmp2->value,"application/",6)==0)) ){
-    map* rs=getMap(m->content,"size");
-    if(rs==NULL){
-      char tmp1[1024];
-      sprintf(tmp1,"%d",strlen(toto->value));
-      rs=createMap("z",tmp1);
-    }
-    xmlAddChild(nc3,xmlNewText(BAD_CAST base64((const unsigned char*)toto->value,atoi(rs->value))));
-  }
-  else if(tmp!=NULL){
-    if(strcmp(tmp->value,"text/js")==0)
-      xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value)));
+      if(strncasecmp(e->format,"COMPLEXOUTPUT",strlen(e->format))==0)
+	nc3=xmlNewNode(ns_wps, BAD_CAST "ComplexData");
+      else
+	nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
+    tmp=m->content;
+    while(tmp!=NULL){
+      if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0)
+	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+      tmp=tmp->next;
+      xmlAddChild(nc2,nc3);
+    }
+    tmp=getMap(e->defaults->content,"mimeType");
+    map* tmp1=getMap(m->content,"encoding");
+    map* tmp2=getMap(m->content,"mimeType");
+    map* toto=getMap(m->content,"value");
+    if((tmp1!=NULL && strncmp(tmp1->value,"base64",6)==0)
+       || (tmp2!=NULL && (strncmp(tmp2->value,"image/",6)==0
+			  || strncmp(tmp2->value,"application/",6)==0)) ){
+      map* rs=getMap(m->content,"size");
+      if(rs==NULL){
+	char tmp1[1024];
+	sprintf(tmp1,"%d",strlen(toto->value));
+	rs=createMap("z",tmp1);
+      }
+      xmlAddChild(nc3,xmlNewText(BAD_CAST base64((const unsigned char*)toto->value,atoi(rs->value))));
+    }
+    else if(tmp!=NULL){
+      if(strcmp(tmp->value,"text/js")==0)
+	xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST toto->value,strlen(toto->value)));
+      else
+	xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
+      xmlAddChild(nc2,nc3);
+    }
     else
       xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
-    xmlAddChild(nc2,nc3);
-  }
-  else
-    xmlAddChild(nc3,xmlNewText(BAD_CAST toto->value));
-
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-
-}
-
-void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,elements* e,map* m,char* type){
-  xmlNodePtr nc1,nc2,nc3;
-  nc1=xmlNewNode(ns_wps, BAD_CAST type);
-  map *tmp=e->content;
-  nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
-  xmlAddChild(nc2,xmlNewText(BAD_CAST m->name));
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-  nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-  xmlAddChild(nc2,xmlNewText(BAD_CAST tmp->value));
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-  tmp=tmp->next;
-
-  /**
-   * IO type Reference or full Data ?
-   */
-#ifdef DEBUG
-  printf("FORMAT %s\n",e->format);
-#endif
-  nc2=xmlNewNode(ns_wps, BAD_CAST "Data");
-  nc3=xmlNewNode(ns_wps, BAD_CAST e->format);
-  tmp=e->defaults->content;
-  while(tmp!=NULL){
-    xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
-    tmp=tmp->next;
-    xmlAddChild(nc2,nc3);
-  }
-  tmp=getMap(e->defaults->content,"mimeType");
-  if(tmp!=NULL){
-    if(strcmp(tmp->value,"text/js")==0)
-      xmlAddChild(nc3,xmlNewCDataBlock(doc,BAD_CAST m->value,strlen(m->value)));
-    else
-      xmlAddChild(nc3,xmlNewText(BAD_CAST m->value));
-    xmlAddChild(nc2,nc3);
-  }
-  else
-    xmlAddChild(nc3,xmlNewText(BAD_CAST m->value));
+  }
+  else{
+    nc3=nc2=xmlNewNode(ns_wps, BAD_CAST "Reference");
+    xmlNewProp(nc3,BAD_CAST "href",BAD_CAST tmpMap->value);
+    tmp=m->content;
+    while(tmp!=NULL){
+      if(strncasecmp(tmp->name,"value",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"reference",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"extension",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"abstract",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"status",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"storeExecuteResponse",strlen(tmp->name))!=0 &&
+	 strncasecmp(tmp->name,"asReference",strlen(tmp->name))!=0)
+	xmlNewProp(nc3,BAD_CAST tmp->name,BAD_CAST tmp->value);
+      tmp=tmp->next;
+      xmlAddChild(nc2,nc3);
+    }
+  }
 
   xmlAddChild(nc1,nc2);
@@ -1884,49 +1173,55 @@
 }
 
+char* getEncoding(maps* m){
+  if(m!=NULL){
+    map* tmp=getMap(m->content,"encoding");
+    if(tmp!=NULL){
+      return tmp->value;
+    }
+    else
+      return "UTF-8";
+  }
+  else
+    return "UTF-8";  
+}
+
+char* getVersion(maps* m){
+  if(m!=NULL){
+    map* tmp=getMap(m->content,"version");
+    if(tmp!=NULL){
+      return tmp->value;
+    }
+    else
+      return "1.0.0";
+  }
+  else
+    return "1.0.0";
+}
+
 void printExceptionReportResponse(maps* m,map* s){
   
-  printf("Content-Type: text/xml; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");  
   int buffersize;
   xmlDocPtr doc;
   xmlChar *xmlbuff;
-  xmlNsPtr ns=NULL;
-  xmlNodePtr nr = xmlNewNode(ns, BAD_CAST "root");
-  ns=xmlNewNs(nr,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-
-  maps* toto1=getMaps(m,"main");
+  xmlNsPtr ns,ns_ows,ns_xlink,ns_xsi;
+  xmlNodePtr n,nc,nc1,nc2;
+
   doc = xmlNewDoc(BAD_CAST "1.0");
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"encoding");
-  //map* tmp=getMapFromMaps(m,"main","encoding");
-    if(tmp!=NULL){
-      doc->encoding = xmlCharStrdup(tmp->value);
-    }
-    else
-      doc->encoding = xmlCharStrdup("UTF-8");
-  }
-  else
-    doc->encoding = xmlCharStrdup ("UTF-8");
-
-  xmlNodePtr n = xmlNewNode(ns, BAD_CAST "ExceptionReport");  
-  xmlNsPtr ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
-  xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
-  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");
-  xmlNewProp(n,BAD_CAST "xml:lan",BAD_CAST "en");
+  maps* tmpMap=getMaps(m,"main");
+  char *encoding=getEncoding(tmpMap);
+  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+
+  ns=xmlNewNs(NULL,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
+  n = xmlNewNode(ns, BAD_CAST "ExceptionReport");  
+  ns_ows=xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST "ows");
+  ns_xlink=xmlNewNs(n,BAD_CAST "http://www.w3.org/1999/xlink",BAD_CAST "xlink");
+  ns_xsi=xmlNewNs(n,BAD_CAST "http://www.w3.org/2001/XMLSchema-instance",BAD_CAST "xsi");
+  xmlNewProp(n,BAD_CAST "xsi:schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1/owsExceptionReport.xsd");
+  xmlNewProp(n,BAD_CAST "xml:lang",BAD_CAST "en");
   xmlNewProp(n,BAD_CAST "service",BAD_CAST "WPS");
 
-  if(toto1!=NULL){
-    map* tmp=getMap(toto1->content,"version");
-    if(tmp!=NULL){
-      xmlNewProp(n,BAD_CAST "version",BAD_CAST tmp->value);
-    }
-    else
-      xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-  }
-  else
-    xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.0.0");
-
-
-  xmlNodePtr nc = xmlNewNode(ns, BAD_CAST "Exception");  
+  xmlNewProp(n,BAD_CAST "version",BAD_CAST getVersion(tmpMap));
+
+  nc = xmlNewNode(ns, BAD_CAST "Exception");  
 
   map* tmp=getMap(s,"code");
@@ -1937,25 +1232,23 @@
 
   tmp=getMap(s,"text");
-  xmlNodePtr nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
+  nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
+  nc2=NULL;
   if(tmp!=NULL){
-    xmlAddChild(nc1,xmlNewText(BAD_CAST tmp->value));
-  }
-  else
-    xmlAddChild(nc1,xmlNewText(BAD_CAST "No debug message available"));
-  
+    xmlNodeSetContent(nc1, BAD_CAST tmp->value);
+  }
+  else{
+    xmlNodeSetContent(nc1, BAD_CAST "No debug message available");
+  }
   xmlAddChild(nc,nc1);
   xmlAddChild(n,nc);
   xmlDocSetRootElement(doc, n);
 
-  xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-  printf((char *) xmlbuff);
+  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
+  printf("%s",xmlbuff);
+  fflush(stdout);
+  xmlFreeDoc(doc);
   xmlFree(xmlbuff);
-  xmlFree(ns_ows);
-  xmlFree(nr);
-  xmlFree(nc1);
-  xmlFree(nc);
-  xmlFree(n);
-  xmlFree(ns);
-  xmlFree(doc);
+  xmlFreeNs(ns);
+  xmlCleanupParser();
 }
 
@@ -1972,6 +1265,29 @@
   if(toto!=NULL)
     asRaw=1;
-   
+  
   if(asRaw==0){
+#ifdef DEBUG
+    fprintf(stderr,"REQUEST_OUTPUTS FINAL\n");
+    dumpMaps(request_outputs);
+#endif
+    toto=getMap(request_outputs->content,"asReference");
+    if(toto!=NULL && strcasecmp(toto->value,"true")==0){
+      toto=getMap(request_outputs->content,"extension");
+      map *tmp1=getMapFromMaps(m,"main","tmpPath");
+      char *file_name=(char*)malloc((strlen(tmp1->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char));
+      sprintf(file_name,"%s/%s_%i.%s",tmp1->value,s->name,cpid+100000,toto->value);
+      FILE *ofile=fopen(file_name,"w");
+      map *tmp2=getMapFromMaps(m,"main","tmpUrl");
+      map *tmp3=getMapFromMaps(m,"main","serverAddress");
+      char *file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(s->name)+strlen(toto->value)+13)*sizeof(char));
+      sprintf(file_url,"%s/%s/%s_%i.%s",tmp3->value,tmp2->value,s->name,cpid+100000,toto->value);
+      addToMap(request_outputs->content,"Reference",file_url);
+      toto=getMap(request_outputs->content,"value");
+      if(toto!=NULL)
+	fwrite(toto->value,sizeof(char),strlen(toto->value),ofile);
+      fclose(ofile);
+      free(file_name);
+      free(file_url);
+    }
     map *r_inputs=getMap(s->content,"serviceProvider");
 #ifdef DEBUG
@@ -1979,5 +1295,5 @@
     dumpMaps(m);
 #endif
-    printProcessResponse1(m,request_inputs1,cpid,
+    printProcessResponse(m,request_inputs1,cpid,
 			  s,r_inputs->value,res,
 			  request_inputs,
@@ -2007,14 +1323,12 @@
       else
 	sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-    printf(mime);
-    toto=getMapFromMaps(request_outputs,
-			request_outputs->name,"value");
+    printf("%s",mime);
+    toto=getMap(request_outputs->content,"value");
     if(mi!=NULL && strncmp(mi->value,"image",5)==0){
-      map* rs=getMapFromMaps(request_outputs,
-			     request_outputs->name,"size");
+      map* rs=getMapFromMaps(request_outputs,request_outputs->name,"size");
       fwrite(toto->value,atoi(rs->value),1,stdout);
     }
     else
-      printf(toto->value);
+      printf("%s",toto->value);
 #ifdef DEBUG
     dumpMap(toto);
@@ -2045,5 +1359,5 @@
 }
 
-void addDefaultValues(maps** out,elements* in,maps* m,char* type){
+char* addDefaultValues(maps** out,elements* in,maps* m,char* type){
   elements* tmpInputs=in;
   maps* out1=*out;
@@ -2052,46 +1366,44 @@
     if(tmpMaps==NULL){
       map* tmpMap1=getMap(tmpInputs->content,"minOccurs");
-      if(strcmp(type,"inputs")==0)
+      if(strncmp(type,"inputs",6)==0)
 	if(tmpMap1!=NULL && atoi(tmpMap1->value)>=1){
-	  char tmps[1024];
-	  sprintf(tmps,"The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file.",tmpInputs->name);
-	  map* tmpe=createMap("text",tmps);
-	  addToMap(tmpe,"code","MissingParameterValue");
-	  printExceptionReportResponse(m,tmpe);
-	  exit(1);
+	  return tmpInputs->name;
 	}
-      tmpMaps=(maps*)malloc(MAPS_SIZE);
-      tmpMaps->name=strdup((char*)tmpInputs->name);
-      tmpMaps->content=NULL;
+      maps* tmpMaps2=(maps*)malloc(MAPS_SIZE);
+      tmpMaps2->name=strdup((char*)tmpInputs->name);
+      tmpMaps2->content=NULL;
+      tmpMaps2->next=NULL;
       iotype* tmpIoType=tmpInputs->defaults;
       while(tmpIoType!=NULL){
-	tmpMaps->content=tmpIoType->content;
-	tmpMaps->content->next;
+	addMapToMap(&tmpMaps2->content,tmpIoType->content);
 	tmpIoType=tmpIoType->next;
       }
-      map *tmpMap=getMap(tmpMaps->content,"value");
+      map *tmpMap=getMap(tmpMaps2->content,"value");
       if(tmpMap==NULL)
-	addToMap(tmpMaps->content,"value","NULL");
-      tmpMaps->next=NULL;
-      dumpMaps(tmpMaps);
+	addToMap(tmpMaps2->content,"value","NULL");
       if(out1==NULL){
-	out1=(maps*)malloc(MAPS_SIZE);
-	out1->name=tmpMaps->name;
-	out1->content=tmpMaps->content;
-	out1->next=NULL;
-	*out=out1;
+	*out=dupMaps(&tmpMaps2);
       }
       else
-	addMapsToMaps(&out1,tmpMaps);
+	addMapsToMaps(&out1,tmpMaps2);
+      freeMaps(&tmpMaps2);
+      free(tmpMaps2);
+      tmpMaps2=NULL;
     }
     else{
       map* tmpContent=tmpInputs->defaults->content;
+      
+      map* cval=NULL;
+      
       while(tmpContent!=NULL){
-	map* tmpIn=getMap(out1->content,tmpContent->name);
-	if(tmpIn==NULL)
-	  if(out1->content==NULL)
-	    out1->content=createMap(tmpContent->name,tmpContent->value);
+	if((cval=getMap(tmpMaps->content,tmpContent->name))==NULL){
+#ifdef DEBUG
+	  fprintf(stderr,"addDefaultValues %s => %s\n",tmpContent->name,tmpContent->value);
+#endif
+	  if(tmpMaps->content==NULL)
+	    tmpMaps->content=createMap(tmpContent->name,tmpContent->value);
 	  else
-	    addToMap(out1->content,tmpContent->name,tmpContent->value);
+	    addToMap(tmpMaps->content,tmpContent->name,tmpContent->value);
+	}
 	tmpContent=tmpContent->next;
       }
@@ -2099,3 +1411,4 @@
     tmpInputs=tmpInputs->next;
   }
-}
+  return "";
+}
Index: trunk/zoo-kernel/service_internal.h
===================================================================
--- trunk/zoo-kernel/service_internal.h	(revision 8)
+++ trunk/zoo-kernel/service_internal.h	(revision 9)
@@ -53,25 +53,27 @@
 #include <libxml/parser.h>
   static char* SERVICE_URL;
+  static xmlNsPtr usedNs[5];
+  static char* nsName[5];
+  static int nbNs=0;
+
 
   void URLDecode(char *);
   char *url_encode(char *);
+  char* getEncoding(maps*);
+
+  int zooXmlSearchForNs(char*);
+  int zooXmlAddNs(xmlNodePtr,char*,char*);
+  void zooXmlCleanupNs();
   
   void printExceptionReportResponse(maps*,map*);
-  void printProcessResponse1(maps*,map*,int,service*,char*,int,maps*,maps*);
-  void printProcessResponse(maps*,int,service*,char*,int,map*,map*);
-  void printGetCapabilitiesResponse(service**,int,char*,maps*);
+  void printProcessResponse(maps*,map*,int,service*,char*,int,maps*,maps*);
   xmlNodePtr printGetCapabilitiesHeader(xmlDocPtr,char*,maps*);
   void printGetCapabilitiesForProcess(maps*,xmlNodePtr,service*);
-  void printGetCapabilitiesDocument(xmlDocPtr);
-  void printDescribeProcessResponse(service*,char*);
   xmlNodePtr printDescribeProcessHeader(xmlDocPtr,char*,maps*);
-  void printDescribeProcessForProcess(maps*,xmlNodePtr,service**,int);
-  void printDescribeProcessDocument(xmlDocPtr);
-  void printDocument(xmlDocPtr);
+  void printDescribeProcessForProcess(maps*,xmlNodePtr,service*,int);
+  void printDocument(maps*,xmlDocPtr,int);
   void printDescription(xmlNodePtr,xmlNsPtr,char*,map*);
-  void printIOType1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,char*);
-  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,map*,char*);
+  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,char*);
   void printOutputDefinitions1(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,char*);
-  void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,map*,char*);
   
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
@@ -79,5 +81,8 @@
   char *base64(const unsigned char*,int);
 
-  void addDefaultValues(maps**,elements*,maps*,char*);
+  char* addDefaultValues(maps**,elements*,maps*,char*);
+
+  /*defined in zoo_loader.c*/ 
+  int errorException(maps *m, const char *message, const char *errorcode);
 
 #ifdef __cplusplus
Index: trunk/zoo-kernel/service_internal_java.c
===================================================================
--- trunk/zoo-kernel/service_internal_java.c	(revision 8)
+++ trunk/zoo-kernel/service_internal_java.c	(revision 9)
@@ -86,4 +86,6 @@
     addToMap(err,"code","NoApplicableCode");
     printExceptionReportResponse(m,err);
+    freeMap(&err);
+    free(err);
     (*jvm)->DestroyJavaVM(jvm);
     return 1;
@@ -148,6 +150,8 @@
 	addToMap(err,"code","NoApplicableCode");
 	printExceptionReportResponse(m,err);
+	freeMap(&err);
+	free(err);
 	(*jvm)->DestroyJavaVM(jvm);
-	return 1;
+	return -1;
       }
     }
@@ -155,16 +159,20 @@
       char tmpS[1024];
       sprintf(tmpS, "Cannot find function %s \n", s->name);
-      map* tmps=createMap("text",tmpS);
-      printExceptionReportResponse(m,tmps);
+      map* err=createMap("text",tmpS);
+      printExceptionReportResponse(m,err);
+      freeMap(&err);
+      free(err);
       (*jvm)->DestroyJavaVM(jvm);
-      exit(-1);
+      return -1;
     }
   }else{
     char tmpS[1024];
     sprintf(tmpS, "Cannot find function %s \n", tmp->value);
-    map* tmps=createMap("text",tmpS);
-    printExceptionReportResponse(m,tmps);
-    if (PyErr_Occurred())
-      PyErr_Print();
+    map* err=createMap("text",tmpS);
+    printExceptionReportResponse(m,err);
+    freeMap(&err);
+    free(err);
+    (*jvm)->DestroyJavaVM(jvm);
+    return -1;
   }
   (*jvm)->DestroyJavaVM(jvm);
@@ -312,8 +320,11 @@
     cmap->next=NULL;
     if(final_res==NULL){
-      final_res=cmap;
+      final_res=dupMaps(&cmap);
     }else
-      addMapsToMaps(final_res,cmap);
+      addMapsToMaps(&final_res,cmap);
     final_res->next=NULL;
+    freeMaps(&cmap);
+    free(cmap);
+    cmap=NULL;
     res=NULL;
   }
Index: trunk/zoo-kernel/service_internal_js.c
===================================================================
--- trunk/zoo-kernel/service_internal_js.c	(revision 8)
+++ trunk/zoo-kernel/service_internal_js.c	(revision 9)
@@ -30,4 +30,8 @@
 		   maps **inputs,maps **outputs)
 {
+  maps* main=*main_conf;
+  maps* _inputs=*inputs;
+  maps* _outputs=*outputs;
+
   /* The class of the global object. */
   JSClass global_class = {
@@ -47,7 +51,7 @@
   if (rt == NULL)
     return 1;
-
+  
   /* Create a context. */
-  cx = JS_NewContext(rt, 8192);
+  cx = JS_NewContext(rt,8192);
   if (cx == NULL){
     return 1;
@@ -78,5 +82,5 @@
   map* tmpm1=getMap(request,"metapath");
   map* tmpm2=getMap(s->content,"serviceProvider");
-  char *filename[strlen(tmpm1->value)+strlen(tmpm2->value)+6];
+  char filename[strlen(tmpm1->value)+strlen(tmpm2->value)+6];
   char ntmp[1024];
   getcwd(ntmp,1024);
@@ -87,8 +91,8 @@
   uint16 lineno;
   jsval rval;
-  FILE *jsfile=fopen(filename,"rb");
+  FILE *jsfile=fopen(filename,"r");
   JSBool ok ;
-  JSScript *script = JS_CompileFileHandle(cx, global, filename, jsfile);
-  if(script){
+  JSScript *script = JS_CompileFileHandle(cx, global, filename,jsfile);
+  if(script!=NULL){
     (void)JS_ExecuteScript(cx, global, script, &rval);
   }
@@ -102,12 +106,16 @@
     JS_DestroyRuntime(rt);
     JS_ShutDown();
+    fclose(jsfile);
     exit(-1);
   }
   /* Call a function in obj's scope. */
   jsval argv[3];
-  argv[0] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*main_conf));
-  argv[1] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*inputs));
-  argv[2] = OBJECT_TO_JSVAL(JSObject_FromMaps(cx,*outputs));
-  jsval rval1;
+  JSObject *jsargv1=JSObject_FromMaps(cx,*main_conf);
+  argv[0] = OBJECT_TO_JSVAL(jsargv1);
+  JSObject *jsargv2=JSObject_FromMaps(cx,*inputs);
+  argv[1] = OBJECT_TO_JSVAL(jsargv2);
+  JSObject *jsargv3=JSObject_FromMaps(cx,*outputs);
+  argv[2] = OBJECT_TO_JSVAL(jsargv3);
+  jsval rval1=JSVAL_NULL;
 #ifdef JS_DEBUG
   fprintf(stderr, "object %p\n", (void *) argv[2]);
@@ -121,5 +129,5 @@
 
   JSObject *d;
-  if (ok==JS_TRUE) {
+  if (ok==JS_TRUE && JSVAL_IS_OBJECT(rval1)==JS_TRUE) {
 #ifdef JS_DEBUG
     fprintf(stderr,"Function run sucessfully !\n");
@@ -127,35 +135,30 @@
     /* Should get a number back from the service function call. */
     ok = JS_ValueToObject(cx, rval1, &d);
-    if (ok==JS_TRUE) {
-#ifdef JS_DEBUG
-      fprintf(stderr,"Function run sucessfully !\n");
-#endif
-      /*char tmpres[10];
-      sprintf(tmpres,"%p",(void *)d);
-      res=atoi(tmpres);*/
-    }
   }else{
     /* Unable to run JS function */
     char tmp1[1024];
-    //sprintf(tmp1,"Unable to run %s from the JavScript file %s",s->name,filename);
+    if(strlen(dbg)==0)
+      sprintf(dbg,"No result was found after the function call");
     sprintf(tmp1,"Unable to run %s from the JavScript file %s : \n %s",s->name,filename,dbg);
     fprintf(stderr,"%s",tmp1);
     map* err=createMap("text",tmp1);
-    addMapToMap(err,createMap("code","NoApplicableCode"));
+    addToMap(err,"code","NoApplicableCode");
     printExceptionReportResponse(*main_conf,err);
+    freeMap(&err);
+    free(err);
     JS_DestroyContext(cx);
     JS_DestroyRuntime(rt);
     JS_ShutDown();
+    // Should return -1 here but the unallocation won't work from zoo_service_loader.c line 1847
     exit(-1);
   }
 
   jsval t=OBJECT_TO_JSVAL(d);
-  //JSVAL_TO_OBJECT(t);
-  if(JS_IsArrayObject(cx,t)){
+  if(JS_IsArrayObject(cx,d)){
 #ifdef JS_DEBUG
     fprintf(stderr,"An array was returned !\n");
 #endif
-    jsdouble len;
-    if((JS_GetArrayLength(cx, t, &len)==JS_FALSE)){
+    jsint len;
+    if((JS_GetArrayLength(cx, d, &len)==JS_FALSE)){
 #ifdef JS_DEBUG
       fprintf(stderr,"outputs array is empty\n");
@@ -163,5 +166,5 @@
     }
     jsval tmp1;
-    JSBool hasResult=JS_GetElement(cx,t,0,&tmp1);
+    JSBool hasResult=JS_GetElement(cx,d,0,&tmp1);
     res=JSVAL_TO_INT(tmp1);
 #ifdef JS_DEBUG
@@ -169,50 +172,44 @@
 #endif
     jsval tmp2;
-    JSBool hasElement=JS_GetElement(cx,t,1,&tmp2);
-    out=mapsFromJSObject(cx,tmp2);
-    *outputs=out;
+    JSBool hasElement=JS_GetElement(cx,d,1,&tmp2);
+    if(hasElement==JS_TRUE){
+      *outputs=mapsFromJSObject(cx,tmp2);
+    }
   }
   else{
-    //#ifdef JS_DEBUG
-    fprintf(stderr,"The service didn't return an array !\n");
-    //#endif
+#ifdef JS_DEBUG
+    fprintf(stderr,"The serice didn't return an array !\n");
+#endif
     jsval tmp1;
-    JSBool hasResult=JS_GetProperty(cx,t,"result",&tmp1);
+    JSBool hasResult=JS_GetProperty(cx,d,"result",&tmp1);
     res=JSVAL_TO_INT(tmp1);
 
-    //#ifdef JS_DEBUG
+#ifdef JS_DEBUG
     fprintf(stderr," * %d * \n",res);
-    //#endif
+#endif
     jsval tmp2;
-    JSBool hasElement=JS_GetProperty(cx,t,"outputs",&tmp2);
+    JSBool hasElement=JS_GetProperty(cx,d,"outputs",&tmp2);
     if(!hasElement)
       fprintf(stderr,"No outputs property returned\n");
-    if(JS_IsArrayObject(cx,tmp2))
+    if(JS_IsArrayObject(cx,JSVAL_TO_OBJECT(tmp2)))
       fprintf(stderr,"outputs is array an as expected\n");
     else
       fprintf(stderr,"outputs is not an array as expected\n");
-    out=mapsFromJSObject(cx,tmp2);
+    *outputs=mapsFromJSObject(cx,tmp2);
 #ifdef JS_DEBUG
     dumpMaps(out);
 #endif
-    *outputs=out;
-  }
-
-  *inputs=mapsFromJSObject(cx,argv[1]);
-  *main_conf=mapsFromJSObject(cx,argv[0]);
-
-  
-  //}
-  //else
-  // ERROR 
-  //;
+  }
 
   /* Cleanup. */
-  JS_MaybeGC(cx);
+  // The JS_MaybeGC call imply segmentation fault
+  //JS_MaybeGC(cx);
   JS_DestroyScript(cx, script);
-  JS_DestroyContext(cx);
+  // If we use the DestroyContext as requested to release memory then we get 
+  // issue getting back the main configuration maps after coming back to the 
+  // runRequest function ...
+  //JS_DestroyContext(cx);
   JS_DestroyRuntime(rt);
   JS_ShutDown();
-  fflush(stderr);
 #ifdef JS_DEBUG
   fprintf(stderr,"Returned value %d\n",res);
@@ -223,4 +220,6 @@
 JSObject* JSObject_FromMaps(JSContext *cx,maps* t){
   JSObject *res = JS_NewArrayObject(cx, 0, NULL);
+  if(res==NULL)
+    fprintf(stderr,"Array Object is NULL!\n");
   maps* tmp=t;
   while(tmp!=NULL){
@@ -247,5 +246,5 @@
   while(tmpm!=NULL){
     jsval jsstr = STRING_TO_JSVAL(JS_NewString(cx,tmpm->value,strlen(tmpm->value)));
-    JS_SetProperty(cx, resf, tmpm->name,&jsstr);
+    JS_SetProperty(cx, res, tmpm->name,&jsstr);
 #ifdef JS_DEBUG
     fprintf(stderr,"%s => %s\n",tmpm->name,tmpm->value);
@@ -259,38 +258,32 @@
   maps *res=NULL;
   maps *tres=NULL;
-  JSVAL_TO_OBJECT(t);
+  jsint oi=0;
+  JSObject* tt=JSVAL_TO_OBJECT(t);
 #ifdef JS_DEBUG
   fprintf(stderr,"Is finally an array ?\n");
-#endif
-  if(JS_IsArrayObject(cx,t)){
-#ifdef JS_DEBUG
+  if(JS_IsArrayObject(cx,tt)){
     fprintf(stderr,"Is finally an array !\n");
-#endif
-  }
-#ifdef JS_DEBUG
+  }
   else
     fprintf(stderr,"Is not an array !\n");
 #endif
-  jsdouble len;
-  if((JS_GetArrayLength(cx, t, &len)==JS_FALSE)){
+  jsint len;
+  JSBool hasLen=JS_GetArrayLength(cx, tt, &len);
+  if(hasLen==JS_FALSE){
 #ifdef JS_DEBUG
     fprintf(stderr,"outputs array is empty\n");
 #endif
   }
-  int i=0;
-  char tmp[10];
-  sprintf(tmp,"%d",len);
-  int clen=atoi(tmp);
 #ifdef JS_DEBUG
   fprintf(stderr,"outputs array length : %d\n",len);
 #endif
-  for(i=0;i<len;i++){
-#ifdef JS_DEBUG
-    fprintf(stderr,"outputs array length : %d step %d\n",len,i);
+  for(oi=0;oi < len;oi++){
+#ifdef JS_DEBUG
+    fprintf(stderr,"outputs array length : %d step %d \n",len,oi);
 #endif
     jsval tmp1;
-    JSBool hasElement=JS_GetElement(cx,t,i,&tmp1);
-    JSVAL_TO_OBJECT(tmp1);
-    JSIdArray *idp=JS_Enumerate(cx,tmp1);
+    JSBool hasElement=JS_GetElement(cx,tt,oi,&tmp1);
+    JSObject *otmp1=JSVAL_TO_OBJECT(tmp1);
+    JSIdArray *idp=JS_Enumerate(cx,otmp1);
     if(idp!=NULL) {
       int index;
@@ -300,5 +293,5 @@
 #endif
       for (index=0,argNum=idp->length;index<argNum;index++) { 
-	jsid* id = idp->vector[index];
+	jsval id = idp->vector[index];
 	jsval vp;
 	JSString* str; 
@@ -310,10 +303,10 @@
 	len1 = JS_GetStringLength(jsmsg);
 #ifdef JS_DEBUG
-	fprintf(stderr,"Enumerate id : %d => %s\n",i,JS_GetStringBytes(jsmsg));
-#endif
-	jsval nvp;
-	if((JS_GetProperty(cx, tmp1, JS_GetStringBytes(jsmsg), &nvp)==JS_FALSE))
-#ifdef JS_DEBUG
-	fprintf(stderr,"Enumerate id : %d => %s => No more value\n",i,JS_GetStringBytes(jsmsg));
+	fprintf(stderr,"Enumerate id : %d => %s\n",oi,JS_GetStringBytes(jsmsg));
+#endif
+	jsval nvp=JSVAL_NULL;
+	if((JS_GetProperty(cx, JSVAL_TO_OBJECT(tmp1), JS_GetStringBytes(jsmsg), &nvp)==JS_FALSE))
+#ifdef JS_DEBUG
+	fprintf(stderr,"Enumerate id : %d => %s => No more value\n",oi,JS_GetStringBytes(jsmsg));
 #endif
 	if(JSVAL_IS_OBJECT(nvp)){
@@ -333,5 +326,5 @@
 	  fprintf(stderr,"JSVAL NVP1J IS OBJECT\n");
 #endif
-	  tres=(maps*)malloc(sizeof(maps*));
+	  tres=(maps*)malloc(MAPS_SIZE);
 	  tres->name=strdup(JS_GetStringBytes(jsmsg));
 	  tres->content=mapFromJSObject(cx,nvp1j);
@@ -341,7 +334,10 @@
 #endif
 	  if(res==NULL)
-	    res=tres;
+	    res=dupMaps(&tres);
 	  else
 	    addMapsToMaps(&res,tres);
+	  freeMaps(&tres);
+	  free(tres);
+	  tres=NULL;
 #ifdef JS_DEBUG
 	  dumpMaps(res);
@@ -363,5 +359,5 @@
 map* mapFromJSObject(JSContext *cx,jsval t){
   map *res=NULL;
-  JSIdArray *idp=JS_Enumerate(cx,t);
+  JSIdArray *idp=JS_Enumerate(cx,JSVAL_TO_OBJECT(t));
 #ifdef JS_DEBUG
   fprintf(stderr,"Properties %p\n",(void*)t);
@@ -374,5 +370,5 @@
 #endif
     for (index=0,argNum=idp->length;index<argNum;index++) { 
-      jsid* id = idp->vector[index];
+      jsval id = idp->vector[index];
       jsval vp;
       JSString* str; 
@@ -384,5 +380,5 @@
       len = JS_GetStringLength(jsmsg);
       jsval nvp;
-      JS_GetProperty(cx, t, JS_GetStringBytes(jsmsg), &nvp);
+      JS_GetProperty(cx, JSVAL_TO_OBJECT(t), JS_GetStringBytes(jsmsg), &nvp);
       jsmsg1 = JS_ValueToString(cx,nvp);
       len1 = JS_GetStringLength(jsmsg1);
@@ -390,8 +386,13 @@
       fprintf(stderr,"Enumerate id : %d [ %s => %s ]\n",index,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
 #endif
-      if(res!=NULL)
-	addMapToMap(&res,createMap(JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1)));
-      else
+      if(res!=NULL){
+	fprintf(stderr,"%s - %s\n",JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
+	addToMap(res,JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
+      }
+      else{
 	res=createMap(JS_GetStringBytes(jsmsg),JS_GetStringBytes(jsmsg1));
+	res->next=NULL;
+      }
+      dumpMap(res);
     }
   }
@@ -401,5 +402,4 @@
   return res;
 }
-
 
 /* The error reporter callback. */
Index: trunk/zoo-kernel/service_internal_python.c
===================================================================
--- trunk/zoo-kernel/service_internal_python.c	(revision 8)
+++ trunk/zoo-kernel/service_internal_python.c	(revision 9)
@@ -25,115 +25,4 @@
 #include "service_internal_python.h"
 
-int python_support(maps* m,service* s,int argc,char** argv,map *inputs,map *outputs){
-  Py_Initialize();
-  PyObject *pName, *pModule, *pFunc;
-  pName = PyString_FromString(argv[2]);
-  pModule = PyImport_Import(pName);
-  int i;
-  if (pModule != NULL) {
-    pFunc=PyObject_GetAttrString(pModule,argv[4]);
-    if (pFunc && PyCallable_Check(pFunc)){
-      PyDictObject* arg1=PyDict_FromMap(inputs);
-      PyDictObject* arg2=PyDict_FromMap(outputs);
-      PyObject *pArgs=PyTuple_New(2);
-      PyObject *pValue;
-      PyTuple_SetItem(pArgs, 0, (PyObject *)arg1);
-      PyTuple_SetItem(pArgs, 1, (PyObject *)arg2);
-      pValue = PyString_FromString(argv[argc-1]);
-#ifdef DEBUG
-      fprintf(stderr,"Function successfully loaded\n");
-#endif	
-      /**
-       * Need to check if we need to fork to load a status enabled 
-       */
-      if(strcmp(PyString_AsString(pValue),"bg")!=0){
-#ifdef DEBUG
-	fprintf(stderr,"RUN IN NORMAL MODE \n");
-#endif
-	pValue = PyObject_CallObject(pFunc, pArgs);
-	if (pValue != NULL) {
-	  inputs=mapFromPyDict(arg1);
-	  outputs=mapFromPyDict(arg2);
-#ifdef DEBUG
-	  fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue));
-	  dumpMap(inputs);
-	  dumpMap(outputs);
-#ifndef WIN32
-	  fprintf(stderr,"printProcessResponse(%i,\"%s\",%i,inputs,outputs);",getpid(),argv[1],PyInt_AsLong(pValue));
-#endif
-#endif
-	  printProcessResponse(m,getpid(),s,argv[2],PyInt_AsLong(pValue),inputs,outputs);
-	}
-      }
-      else{
-	pid_t pid;
-#ifdef WIN32
-	pid = 0;
-#else
-	pid = fork ();
-#endif
-	if (pid > 0) {
-	  /* dady */
-	  printProcessResponse(m,pid,s,argv[2],SERVICE_STARTED,inputs,outputs);
-	}else if (pid == 0) {
-	  /* son */
-#ifdef DEBUG
-	  fprintf(stderr,"RUN IN BACKGROUND MODE \n");
-#endif
-	  char tmp1[256];
-	  sprintf(tmp1,"service/temp/%s_%d.xml",argv[2],getpid());
-#ifndef WIN32
-	  stdout =
-#endif
-		  freopen(tmp1 , "w+" , stdout);
-	  printProcessResponse(m,getpid(),s,argv[2],SERVICE_STARTED,inputs,outputs);
-	  fflush(stdout);
-	  pValue = PyObject_CallObject(pFunc, pArgs);
-	  if (pValue != NULL) {
-	    rewind(stdout);
-	    inputs=mapFromPyDict(arg1);
-	    outputs=mapFromPyDict(arg2);
-#ifdef DEBUG
-	    fprintf(stderr,"Result of call: %ld\n", PyInt_AsLong(pValue));
-	    dumpMap(inputs);
-	    dumpMap(outputs);
-	    fprintf(stderr,"printProcessResponse(%i,%s,%i,inputs,outputs);",s,getpid(),argv[2],PyInt_AsLong(pValue));
-#endif
-//	    sleep(6);
-	    printProcessResponse(m,getpid(),s,argv[2],PyInt_AsLong(pValue),inputs,outputs);
-	  }
-	  exit(1);
-	} else {
-	  /* error */
-	}
-      }
-      Py_DECREF(pArgs);
-      Py_DECREF(pValue);
-#ifdef DEBUG
-      fprintf(stderr,"Function ran successfully\n");
-#endif	
-    }
-    else{
-      char tmpS[1024];
-      sprintf(tmpS, "Cannot find function %s \n", argv[4]);
-      map* tmps=createMap("text",tmpS);
-      printExceptionReportResponse(m,tmps);
-      //fprintf(stderr, "Cannot find function %s \n", argv[2]);
-      exit(-1);
-    }
-  }else{
-    char tmpS[1024];
-    sprintf(tmpS, "Cannot find function %s \n", argv[4]);
-    map* tmps=createMap("text",tmpS);
-    printExceptionReportResponse(m,tmps);
-    //fprintf(stderr, "Cannot find function %s \n", argv[4]);
-    if (PyErr_Occurred())
-      PyErr_Print();
-
-  }
-  Py_Finalize();
-  return 2;
-}
-
 int zoo_python_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
   maps* m=*main_conf;
@@ -144,12 +33,14 @@
   map* tmp=NULL;
   tmp=getMapFromMaps(*main_conf,"env","PYTHONPATH");
-  char *python_path=NULL;
+  char *python_path;
+  fprintf(stderr,"PYTHON SUPPORT \n");
+  fflush(stderr);
   if(tmp!=NULL){
-	  python_path=(char*)malloc((1+strlen(tmp->value))*sizeof(char));
-	  sprintf(python_path,"%s",tmp->value);
+    fprintf(stderr,"PYTHON SUPPORT (%i)\n",strlen(tmp->value));
+    python_path=(char*)malloc((strlen(tmp->value))*sizeof(char));
+    sprintf(python_path,"%s",tmp->value);
   }
   else{
-	python_path=(char*)malloc(2*sizeof(char));
-	python_path=".";
+    python_path=strdup(".");
   }
   tmp=NULL;
@@ -158,7 +49,7 @@
   if(tmp!=NULL && strcmp(tmp->value,"")!=0)
 #ifdef WIN32
-	  sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path);
+    sprintf(pythonpath,"%s/%s/;%s",ntmp,tmp->value,python_path);
 #else
-	  sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path);
+  sprintf(pythonpath,"%s/%s/:%s",ntmp,tmp->value,python_path);
 #endif
   else
@@ -166,9 +57,9 @@
     sprintf(pythonpath,"%s;%s",ntmp,python_path);
 #else
-    sprintf(pythonpath,"%s:%s",ntmp,python_path);
-#endif
-#ifdef DEBUG
-  fprintf(stderr,"PYTHONPATH=%s\n",pythonpath);
-#endif
+  sprintf(pythonpath,"%s:%s",ntmp,python_path);
+#endif
+  //#ifdef DEBUG
+    fprintf(stderr,"PYTHONPATH=%s\n",pythonpath);
+  //#endif
 #ifndef WIN32
   setenv("PYTHONPATH",pythonpath,1);
@@ -178,10 +69,16 @@
   free(python_path);
   free(pythonpath);
-  //
+
   Py_Initialize();
   PyObject *pName, *pModule, *pFunc;
   tmp=getMap(s->content,"serviceProvider");
-  //if(tmp!=NULL)
-  pName = PyString_FromString(tmp->value);
+  if(tmp!=NULL)
+    pName = PyString_FromString(tmp->value);
+  else{
+    map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
+    addToMap(err,"code","NoApplicableCode");
+    printExceptionReportResponse(m,err);
+    exit(-1);
+  }
   pModule = PyImport_Import(pName);
   int i;
@@ -202,28 +99,27 @@
 #ifdef DEBUG
       fprintf(stderr,"RUN IN NORMAL MODE \n");
-      //fflush(stderr);
+      fflush(stderr);
 #endif
       pValue = PyObject_CallObject(pFunc, pArgs);
       if (pValue != NULL) {
 	res=PyInt_AsLong(pValue);
-	/*inputs=mapsFromPyDict(arg2);
-	dumpMaps(inputs);*/
-	outputs=mapsFromPyDict(arg3);
-	*real_outputs=outputs;
-
+	freeMaps(real_outputs);
+	free(*real_outputs);
+	//*real_inputs=mapsFromPyDict(arg2);
+	//createMapsFromPyDict(real_outputs,arg3);
+	*real_outputs=mapsFromPyDict(arg3);
 #ifdef DEBUG
 	fprintf(stderr,"Result of call: %i\n", PyInt_AsLong(pValue));
 	dumpMaps(inputs);
 	dumpMaps(outputs);
-	fprintf(stderr,"printProcessResponse(%i,\"%s\",%i,inputs,outputs);",
-		getpid(),tmp->value,PyInt_AsLong(pValue));
-	dumpMaps(outputs);
-#endif
+#endif
+	Py_DECREF(arg1);
+	Py_DECREF(arg2);
+	Py_DECREF(arg3);
+      	Py_DECREF(pArgs);
 	Py_DECREF(pValue);
 	Py_XDECREF(pFunc);
-      	Py_DECREF(pArgs);
 	Py_DECREF(pModule);
-      }else{
-	  
+      }else{	  
 	PyObject *ptype,*pvalue, *ptraceback;
 	PyErr_Fetch(&ptype, &pvalue, &ptraceback);
@@ -268,5 +164,4 @@
       map* tmps=createMap("text",tmpS);
       printExceptionReportResponse(m,tmps);
-      //fprintf(stderr, "Cannot find function %s \n", argv[2]);
       Py_XDECREF(pFunc);
       Py_DECREF(pModule);
@@ -275,13 +170,15 @@
   } else{
     char tmpS[1024];
-    sprintf(tmpS, "Cannot find function %s \n", tmp->value);
+    sprintf(tmpS, "Python module %s cannot be loaded.\n", tmp->value);
     map* tmps=createMap("text",tmpS);
     printExceptionReportResponse(m,tmps);
-    //fprintf(stderr, "Cannot find function %s \n", argv[4]);
     if (PyErr_Occurred())
       PyErr_Print();
     exit(-1);
   } 
+#ifndef DEBUG
+  // Failed when DEBUG is defined
   Py_Finalize();
+#endif
   return res;
 }
@@ -329,8 +226,8 @@
 	    PyString_AsString(key),PyString_AsString(value));
 #endif
-    if(cursor!=NULL){
+    while(cursor!=NULL){
       cursor=cursor->next;
     }
-    cursor=(maps*)malloc(sizeof(maps*));
+    cursor=(maps*)malloc(MAPS_SIZE);
     cursor->name=PyString_AsString(key);
 #ifdef DEBUG
Index: trunk/zoo-kernel/service_internal_python.h
===================================================================
--- trunk/zoo-kernel/service_internal_python.h	(revision 8)
+++ trunk/zoo-kernel/service_internal_python.h	(revision 9)
@@ -40,7 +40,7 @@
 
 maps* mapsFromPyDict(PyDictObject* t);
+void createMapsFromPyDict(maps**,PyDictObject*);
 map* mapFromPyDict(PyDictObject* t);
 
-int python_support(maps*,service*,int,char**,map *,map *);
 int zoo_python_support(maps**,map*,service*,maps**,maps**);
 
Index: trunk/zoo-kernel/ulinet.c
===================================================================
--- trunk/zoo-kernel/ulinet.c	(revision 8)
+++ trunk/zoo-kernel/ulinet.c	(revision 9)
@@ -215,4 +215,5 @@
   if(handle.handle)
     curl_easy_cleanup(handle.handle);
+  curl_global_cleanup();
 }
 
@@ -233,5 +234,5 @@
       break;
     default:
-      sprintf(filename,"/tmp/HTCcache%d",(int)time(NULL));
+      sprintf(filename,"/tmp/ZOO_Cache%d",(int)time(NULL));
       printf("file=%s",filename);
 #ifdef MSG_LAF_VERBOSE
Index: trunk/zoo-kernel/zoo_loader.c
===================================================================
--- trunk/zoo-kernel/zoo_loader.c	(revision 8)
+++ trunk/zoo-kernel/zoo_loader.c	(revision 9)
@@ -23,4 +23,7 @@
  */
 
+#define MALLOC_CHECK_ 0
+#define MALLOC_CHECK 0
+
 /**
  * Specific includes
@@ -31,10 +34,8 @@
 #include <sys/types.h>
 #include <unistd.h>
+#include "service_internal.h"
+
 extern "C" {
 #include "cgic.h"
-}
-
-#include "service_internal.h"
-extern "C" {
 #include <libxml/tree.h>
 #include <libxml/xmlmemory.h>
@@ -44,7 +45,26 @@
 }
 
+xmlXPathObjectPtr extractFromDoc(xmlDocPtr,char*);
+int runRequest(map*);
+
+using namespace std;
+
+/* ************************************************************************* */
+
+int errorException(maps *m, const char *message, const char *errorcode) 
+{
+  map * errormap = createMap("text", message);
+  addToMap(errormap,"code", errorcode);
+  printExceptionReportResponse(m,errormap);
+  freeMap(&errormap);
+  free(errormap);
+  return -1;
+}
+
+/* ************************************************************************* */
+
 #ifndef STRTOK_R
 char *
-strtok_r(char *s1, const char *s2, char **lasts)
+strtok_r (char *s1, const char *s2, char **lasts)
 {
   char *ret;
@@ -52,12 +72,12 @@
   if (s1 == NULL)
     s1 = *lasts;
-  while(*s1 && strchr(s2, *s1))
+  while (*s1 && strchr(s2, *s1))
     ++s1;
-  if(*s1 == '\0')
+  if (*s1 == '\0')
     return NULL;
   ret = s1;
-  while(*s1 && !strchr(s2, *s1))
+  while (*s1 && !strchr(s2, *s1))
     ++s1;
-  if(*s1)
+  if (*s1)
     *s1++ = '\0';
   *lasts = s1;
@@ -67,69 +87,6 @@
 #endif
 
-xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
-int runRequest(map*);
-
-using namespace std;
-
-char* strtoupper(char* str)
-{
-  int leng=strlen(str);
-  for(int i=0; i<leng; i++)
-    if (97<=str[i]&&str[i]<=122)//a-z
-      str[i]-=32;
-  return str;
-}
-
-char* strtolower(char* str)
-{
-  int leng=strlen(str);
-  for(int i=0; i<leng; i++)
-    if (65<=str[i]&&str[i]<=90)//A-Z
-      str[i]+=32;
-  return str;
-}
-
-char* remplace(char* delim,char* rep,char* source){
-  if(strcmp(source,"")==0){
-#ifdef DEBUG
-    //char *tmp="RETURN NULL !\n";
-    //printf((void*)tmp);
-#endif
-    return "NULL";
-  }
-
-  char *_token; 
-  char *origin=strdup(source);
-  char result[1024]="";
-  _token = strtok(source, delim);
-#ifdef DEBUG
-  fprintf(stderr,"\nREPLACE TOKEN (%s == %s => %d)\n ",_token,origin,strcmp(_token,origin));
-#endif
-  if(strcmp(_token,origin)!=0)
-    while(_token!=NULL){
-      sprintf(result,"%s%s%s",result,_token,rep);
-      _token = strtok (NULL, delim);
-      if(_token==NULL)
-	result[strlen(result)-strlen(rep)]=0;
-#ifdef DEBUG
-      fprintf(stderr,"\n\nRESULT(%s)\n\n",result);
-#endif
-    }
-  else
-    return origin;
-  
-  return strdup(result);
-}
-
-
-char *colors[] = {
-  "red", "green", "blue"
-};
-
-#define colorsTotal 3
-#define TRUE -1
+#define TRUE 1
 #define FALSE -1
-static bool started=FALSE;
-static bool isStarted=FALSE;
 
 int cgiMain(){
@@ -140,12 +97,11 @@
   dup2(fileno(cgiOut),fileno(stdout));
 #ifdef DEBUG
-    fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-    fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
-    fflush(cgiOut);
+  fprintf(cgiOut,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
+  fprintf(cgiOut,"Welcome on ZOO verbose debuging mode \r\n\r\n");
+  fflush(cgiOut);
 #endif
   
   /**
    * Read the main configuration file
-   */
   if(!isStarted){
     maps* m;
@@ -159,22 +115,25 @@
     isStarted=TRUE;
   }
-
-#ifdef DEBUG
-  char textb[23];
-  sprintf(textb,"\n%s\n%s\n",cgiRemoteAddr,cgiRequestMethod);
-  fprintf(stderr,"****%s\n%s\n***",textb,cgiQueryString);
-#endif
-
-  map* tmp=NULL;
+   */
+
+#ifdef DEBUG
+  fprintf (stderr, "Addr:%s\n", cgiRemoteAddr); 
+  fprintf (stderr, "RequestMethod:%s\n", cgiRequestMethod); 
+  fprintf (stderr, "Request: %s\n", cgiQueryString);
+#endif
+
+  map* tmpMap=NULL;
     
   if(strncmp(cgiContentType,"text/xml",8)==0){
-    char *buffer=new char[cgiContentLength];
+    char *buffer=new char[cgiContentLength+1];
     if(fread(buffer,1,cgiContentLength,cgiIn)){
       buffer[cgiContentLength]=0;
-      tmp=createMap("request",buffer);
+      tmpMap=createMap("request",buffer);
     }else{
       /* Here we have to return an error message ... */
+      fprintf(stderr, "Unable to read cgi content in zoo_loader.c line %i\n", __LINE__);      
       return 1; 
     }
+    delete[]buffer;
   }
   else{
@@ -190,9 +149,10 @@
       fprintf(stderr,"(( \n %s \n %s \n ))",*arrayStep,value);
 #endif
-      if(tmp!=NULL)
-	addToMap(tmp,*arrayStep,value);
+      if(tmpMap!=NULL)
+	addToMap(tmpMap,*arrayStep,value);
       else
-	tmp=createMap(*arrayStep,value);
+	tmpMap=createMap(*arrayStep,value);
       arrayStep++;
+      delete[]value;
     }
     cgiStringArrayFree(array);
@@ -201,46 +161,23 @@
   /**
    * In case that the POST method was used, then check if params came in XML
-   * format (attribute request should be the once).
-   */
-  if(strcmp(cgiRequestMethod,mtoupper("post"))==0 && count(tmp)==1){
+   * format else try to use the attribute "request" which should be the only 
+   * one.
+   */
+  if(strncasecmp(cgiRequestMethod,"post",4)==0 || count(tmpMap)==1){
     /**
      * First include the MetaPath and the ServiceProvider default parameters
      * (which should be always available in GET params so in cgiQueryString)
      */
-    char *saveptr1, *saveptr2;
-    char *str1, *str2, *token, *subtoken;
+    //char *saveptr1, *saveptr2;
+    char *str1/*, str2, *token, *subtoken*/;
     str1=cgiQueryString;
-    token=strtok_r(str1,"&",&saveptr1);
-    while(token!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"%s",token);
-#endif
-      str2=token;
-      subtoken=strtok_r(str2,"=",&saveptr2);
-#ifdef DEBUG
-      fprintf(stderr,"%s\n",subtoken);
-#endif
-      char* tmp_name;
-      if(subtoken!=NULL){
-	tmp_name=subtoken;
-#ifdef DEBUG
-	fprintf(stderr,"%s",subtoken);
-#endif
-	subtoken=strtok_r(NULL,"=",&saveptr2);
-	if(subtoken!=NULL)
-	  addToMap(tmp,tmp_name,subtoken);
-	else
-	  addToMap(tmp,tmp_name,"");
-      }
-      token=strtok_r(NULL,"&",&saveptr1);
-    }
     /**
      * Store the original XML request in xrequest map
      */
-    map* t1=getMap(tmp,"request");
+    map* t1=getMap(tmpMap,"request");
     if(t1!=NULL){
-      addToMap(tmp,"xrequest",t1->value);
+      addToMap(tmpMap,"xrequest",t1->value);
       xmlInitParser();
-      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);      
+      xmlDocPtr doc = xmlParseMemory(t1->value,cgiContentLength);
       xmlNodePtr cur = xmlDocGetRootElement(doc);
       char *tval;
@@ -248,9 +185,9 @@
       tval = (char*) xmlGetProp(cur,BAD_CAST "service");
       if(tval!=NULL)
-	addToMap(tmp,"service",tval);
+	addToMap(tmpMap,"service",tval);
       tval=NULL;
       tval = (char*) xmlGetProp(cur,BAD_CAST "language");
       if(tval!=NULL)
-	addToMap(tmp,"language",tval);
+	addToMap(tmpMap,"language",tval);
       
       char* requests[3];
@@ -261,19 +198,25 @@
 	char tt[35];
 	sprintf(tt,"/*[local-name()='%s']",requests[j]);
-	xmlNodeSet* req=extractFromDoc(doc,tt);
-#ifdef DEBUG
-	fprintf(stderr,"%i",req->nodeNr);
-#endif
-	if(req->nodeNr==1){
-	  t1->value=requests[j];
-	  j=2;
+	xmlXPathObjectPtr reqptr=extractFromDoc(doc,tt);
+	if(reqptr!=NULL){
+	  xmlNodeSet* req=reqptr->nodesetval;
+#ifdef DEBUG
+	  fprintf(stderr,"%i",req->nodeNr);
+#endif
+	  if(req!=NULL && req->nodeNr==1){
+	    t1->value=requests[j];
+	    j=2;
+	  }
+	  xmlXPathFreeObject(reqptr);
 	}
-	xmlFree(req);
+	//xmlFree(req);
       }
-      if(strcmp(mtoupper(t1->value),mtoupper("GetCapabilities"))==0){	
-	xmlNodeSet* vers=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
+      if(strncasecmp(t1->value,"GetCapabilities",15)==0){
+	xmlXPathObjectPtr versptr=extractFromDoc(doc,"/*/*/*[local-name()='Version']");
+	xmlNodeSet* vers=versptr->nodesetval;
 	xmlChar* content=xmlNodeListGetString(doc, vers->nodeTab[0]->xmlChildrenNode,1);
-	addToMap(tmp,"version",(char*)content);
-	xmlFree(vers);
+	addToMap(tmpMap,"version",(char*)content);
+	xmlXPathFreeObject(versptr);
+	//xmlFree(vers);
 	xmlFree(content);
       }else{
@@ -281,36 +224,50 @@
 	tval = (char*) xmlGetProp(cur,BAD_CAST "version");
 	if(tval!=NULL)
-	  addToMap(tmp,"version",tval);
+	  addToMap(tmpMap,"version",tval);
 	xmlFree(tval);
 	tval = (char*) xmlGetProp(cur,BAD_CAST "language");
 	if(tval!=NULL)
-	  addToMap(tmp,"language",tval);
-	xmlNodeSet* id=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
-	char* identifiers=NULL;
-	identifiers=(char*)malloc(cgiContentLength);
-	identifiers[0]=0;
-	for(int k=0;k<id->nodeNr;k++){
-	  xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
-	  if(strlen(identifiers)>0){
-	    sprintf(identifiers,"%s,%s",identifiers,content);
-	    identifiers[strlen(identifiers)]=0;
+	  addToMap(tmpMap,"language",tval);
+	xmlXPathObjectPtr idptr=extractFromDoc(doc,"/*/*[local-name()='Identifier']");
+	if(idptr!=NULL){
+	  xmlNodeSet* id=idptr->nodesetval;
+	  if(id!=NULL){
+	    char* identifiers=NULL;
+	    identifiers=(char*)calloc(cgiContentLength,sizeof(char));
+	    identifiers[0]=0;
+	    for(int k=0;k<id->nodeNr;k++){
+	      xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
+	      if(strlen(identifiers)>0){
+		char *tmp=strdup(identifiers);
+		snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
+		free(tmp);
+	      }
+	      else{
+		snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
+	      }
+	      xmlFree(content);
+	    }
+	    xmlXPathFreeObject(idptr);
+	    addToMap(tmpMap,"Identifier",identifiers);
+	    free(identifiers);
 	  }
-	  else{
-	    sprintf(identifiers,"%s",content);
-	    identifiers[strlen(identifiers)]=0;
-	  }
-	  xmlFree(content);
 	}
-	xmlFree(id);
-	addToMap(tmp,"Identifier",identifiers);
+	//xmlFree(id);
       }
-      //xmlCleanupParser();
       xmlFree(tval);
-    }
-  }
-  //dumpMap(tmp);
-  runRequest(tmp);
-  //dumpMap(tmp);
-
+      xmlFreeDoc(doc);
+      xmlCleanupParser();
+    }
+  }
+
+  runRequest(tmpMap);
+
+  /** 
+   * Required but can't be made after executing a process using POST requests.
+   */
+  if(strncasecmp(cgiRequestMethod,"post",4)!=0 && count(tmpMap)!=1 && tmpMap!=NULL){
+    freeMap(&tmpMap);
+    free(tmpMap);
+  }
   return 0;
 
Index: trunk/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-kernel/zoo_service_loader.c	(revision 8)
+++ trunk/zoo-kernel/zoo_service_loader.c	(revision 9)
@@ -27,4 +27,6 @@
 extern "C" int yylex();
 extern "C" int crlex();
+
+
 extern "C" {
 #include <libxml/tree.h>
@@ -71,19 +73,54 @@
 #include <stdarg.h>
 
-xmlNodeSet* extractFromDoc(xmlDocPtr doc,char* search){
+xmlXPathObjectPtr extractFromDoc(xmlDocPtr doc,char* search){
   xmlXPathContextPtr xpathCtx;
   xmlXPathObjectPtr xpathObj;
   xpathCtx = xmlXPathNewContext(doc);
   xpathObj = xmlXPathEvalExpression(BAD_CAST search,xpathCtx);
-  xmlXPathFreeContext(xpathCtx); 
-  return xpathObj->nodesetval;
+  xmlXPathFreeContext(xpathCtx);
+  return xpathObj;
 }
 
-void sigint_handler(int sig){
+void sig_handler(int sig){
+  char tmp[100];
+  char *ssig;
+  switch(sig){
+  case SIGSEGV:
+    ssig="SIGSEGV";
+    break;
+  case SIGTERM:
+    ssig="SIGTERM";
+    break;
+  case SIGINT:
+    ssig="SIGINT";
+    break;
+  case SIGILL:
+    ssig="SIGILL";
+    break;
+  case SIGFPE:
+    ssig="SIGFPE";
+    break;
+  case SIGABRT:
+    ssig="SIGABRT";
+    break;
+  default:
+    ssig="UNKNOWN";
+    break;
+  }
+  sprintf(tmp,"ZOO Kernel failed to process your request receiving signal %d = %s",sig,ssig);
+  errorException(NULL, tmp, "InternalError");
   fprintf(stderr,"Not this time!\n");
+  exit(0);
 }
 
 int runRequest(map* request_inputs)
 {
+
+  (void) signal(SIGSEGV,sig_handler);
+  (void) signal(SIGTERM,sig_handler);
+  (void) signal(SIGINT,sig_handler);
+  (void) signal(SIGILL,sig_handler);
+  (void) signal(SIGFPE,sig_handler);
+  (void) signal(SIGABRT,sig_handler);
 
   map* r_inputs=NULL,*tmps=NULL;
@@ -95,5 +132,8 @@
    * Parsing service specfic configuration file
    */
-  m=(maps*)malloc(MAPS_SIZE);
+  m=(maps*)calloc(1,MAPS_SIZE);
+  if(m == NULL){
+    return errorException(m, "Unable to allocate memory.", "InternalError");
+  }
   char ntmp[1024];
 #ifndef WIN32
@@ -102,63 +142,74 @@
   _getcwd(ntmp,1024);
 #endif
-  char conf_file[1024];
-  sprintf(conf_file,"%s/main.cfg",ntmp);  
+  r_inputs=getMap(request_inputs,"metapath");
+  if(r_inputs==NULL){
+    if(request_inputs==NULL)
+      request_inputs=createMap("metapath","");
+    else
+      addToMap(request_inputs,"metapath","");
+#ifdef DEBUG
+    fprintf(stderr,"ADD METAPATH\n");
+    dumpMap(request_inputs);
+#endif
+    r_inputs=getMap(request_inputs,"metapath");
+  }
+  char conf_file[10240];
+  snprintf(conf_file,10240,"%s/%s/main.cfg",ntmp,r_inputs->value);
   conf_read(conf_file,m);
-  
+#ifdef DEBUG
+  fprintf(stderr, "***** BEGIN MAPS\n"); 
+  dumpMaps(m);
+  fprintf(stderr, "***** END MAPS\n");
+#endif
+
   /**
    * Check for minimum inputs
    */
   r_inputs=getMap(request_inputs,"Request");
-  if(r_inputs==NULLMAP){ 
-  tmps=createMap("text","Parameter <request> was not specified");
-    addToMap(tmps,"code","MissingParameterValue");
-    printExceptionReportResponse(m,tmps);
+  if(request_inputs==NULL || r_inputs==NULL){ 
+    errorException(m, "Parameter <request> was not specified","MissingParameterValue");
+    freeMaps(&m);
+    free(m);
+    freeMap(&request_inputs);
+    free(request_inputs);
     return 1;
   }
-  else
+  else{
     REQUEST=strdup(r_inputs->value);
-  r_inputs=NULL;
-  r_inputs=getMap(request_inputs,"Service");
-  if(r_inputs==NULLMAP){ 
-    tmps=createMap("text","Parameter <service> was not specified");
-    addToMap(tmps,"code","MissingParameterValue");
-    printExceptionReportResponse(m,tmps);
-    return 1;
-  }
-  if(strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0){
-    r_inputs=getMap(request_inputs,"Version");
-    if(r_inputs==NULL){ 
-      tmps=createMap("text","Parameter <version> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);
+    if(strncasecmp(r_inputs->value,"GetCapabilities",15)!=0
+       && strncasecmp(r_inputs->value,"DescribeProcess",15)!=0
+       && strncasecmp(r_inputs->value,"Execute",7)!=0){ 
+      errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
+      freeMaps(&m);
+      free(m);
+      freeMap(&request_inputs);
+      free(request_inputs);
+      free(REQUEST);
       return 1;
     }
   }
-
-  /**
-   * Need to print std exception message here
-   */
-  char SP[1024];
-  if ((argc < 5 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")!=0) || (argc < 4 && strcmp(mtoupper(REQUEST),"GETCAPABILITIES")==0)){
-    r_inputs=getMap(request_inputs,"ServiceProvider");
-    if(r_inputs==NULLMAP){
-      tmps=createMap("text","Parameter <serviceprovider> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);    
+  r_inputs=NULL;
+  r_inputs=getMap(request_inputs,"Service");
+  if(r_inputs==NULLMAP){
+    errorException(m, "Parameter <service> was not specified","MissingParameterValue");
+    freeMaps(&m);
+    free(m);
+    free(REQUEST);
+    return 1;
+  }
+  if(strncasecmp(REQUEST,"GetCapabilities",15)!=0){
+    r_inputs=getMap(request_inputs,"Version");
+    if(r_inputs==NULL){ 
+      errorException(m, "Parameter <version> was not specified","MissingParameterValue");
+      freeMaps(&m);
+      free(m);
+      free(REQUEST);
       return 1;
     }
-    else
-      sprintf(SP,"%s",r_inputs->value);
-    r_inputs=getMap(request_inputs,"MetaPath");
-    if(r_inputs==NULLMAP){
-      tmps=createMap("text","Parameter <metapath> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);    
-      return 1;
-    }
-    tmps=createMap("text","Parameter <unknown> was not specified");
-    addToMap(tmps,"code","MissingParameterValue");
-    printExceptionReportResponse(m,tmps);    
-    return 1;
+  }
+
+  r_inputs=getMap(request_inputs,"serviceprovider");
+  if(r_inputs==NULL){
+    addToMap(request_inputs,"serviceprovider","");
   }
 
@@ -182,25 +233,30 @@
   char tmps1[1024];
 
-  if(strcmp(mtoupper(REQUEST),mtoupper("GetCapabilities"))==0){
+  r_inputs=NULL;
+  r_inputs=getMap(request_inputs,"metapath");
+  if(r_inputs!=NULL)
+    snprintf(conf_dir,1024,"%s/%s",ntmp,r_inputs->value);
+  else
+    snprintf(conf_dir,1024,"%s",ntmp);
+
+  if(strncasecmp(REQUEST,"GetCapabilities",15)==0){
     int i=0;
     struct dirent *dp;
-    r_inputs=NULL;
-    r_inputs=getMap(request_inputs,"metapath");
 #ifdef DEBUG
     dumpMap(r_inputs);
 #endif
-    sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
-	DIR *dirp = opendir(conf_dir);
+    DIR *dirp = opendir(conf_dir);
     if(dirp==NULL){
-      tmps=createMap("text","The specified path doesn't exist.");
-      addToMap(tmps,"code","InvalidParameterValue");
-      printExceptionReportResponse(m,tmps);    
-      return -1;
+      return errorException(m, "The specified path doesn't exist.","InvalidParameterValue");
     }
     xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
-    doc->encoding = xmlCharStrdup ("UTF-8");
     r_inputs=NULL;
     r_inputs=getMap(request_inputs,"ServiceProvider");
-    xmlNodePtr n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
+    xmlNodePtr n;
+    //dumpMap(request_inputs);
+    if(r_inputs!=NULL)
+      n = printGetCapabilitiesHeader(doc,r_inputs->value,m);
+    else
+      n = printGetCapabilitiesHeader(doc,"",m);
     /**
      * Strange, here we need to close stdout to ensure that no uneeded 
@@ -211,8 +267,10 @@
     while ((dp = readdir(dirp)) != NULL)
       if(strstr(dp->d_name,".zcfg")!=0){
-	sprintf(tmps1,"%s/%s",conf_dir,dp->d_name);
-	char *tmps=tmps1;
-	s1=(service*)malloc(sizeof(service*));
-	s[0]=(service*)malloc(sizeof(service*));
+	memset(tmps1,0,1024);
+	snprintf(tmps1,1024,"%s/%s",conf_dir,dp->d_name);
+	s1=(service*)calloc(1,SERVICE_SIZE);
+	if(s1 == NULL){ 
+	  return errorException(m, "Unable to allocate memory.","InternalError");
+	}
 #ifdef DEBUG
 	fprintf(stderr,"#################\n%s\n#################\n",tmps1);
@@ -224,8 +282,7 @@
 	fflush(stderr);
 #endif
-	s[0]=s1;
 	printGetCapabilitiesForProcess(m,n,s1);
-	//freeService(&s1);
-	//s1=NULL;
+	freeService(&s1);
+	free(s1);
 	scount++;
       }
@@ -233,8 +290,10 @@
     fflush(stdout);
     dup2(saved_stdout,fileno(stdout));
-    
-    printDocument(doc);
+    printDocument(m,doc,getpid());
+    freeMaps(&m);
+    free(m);
+    free(REQUEST);
+    free(SERVICE_URL);
     fflush(stdout);
-    xmlFree(n);
     return 0;
   }
@@ -243,34 +302,35 @@
     if(r_inputs==NULL 
        || strlen(r_inputs->name)==0 || strlen(r_inputs->value)==0){ 
-      if(r_inputs!=NULL && strlen(r_inputs->value)==0)
-	tmps=createMap("text","Mandatory value for <identifier> was not specified");
-      else
-	tmps=createMap("text","Mandatory <identifier> was not specified");
-      addToMap(tmps,"code","MissingParameterValue");
-      printExceptionReportResponse(m,tmps);
-      return 1;
+      errorException(m, "Mandatory <identifier> was not specified","MissingParameterValue");
+      freeMaps(&m);
+      free(m);
+      free(REQUEST);
+      free(SERVICE_URL);
+      return 0;
     }
 
-    r_inputs=getMap(request_inputs,"metapath");
-    sprintf(conf_dir,"%s/%s",ntmp,r_inputs->value);
     struct dirent *dp;
     DIR *dirp = opendir(conf_dir);
     if(dirp==NULL){
-      tmps=createMap("text","The specified metapath path doesn't exist.");
-      addToMap(tmps,"code","InvalidParameterValue");
-      printExceptionReportResponse(m,tmps);    
-      return -1;
+      errorException(m, "The specified path path doesn't exist.","InvalidParameterValue");
+      freeMaps(&m);
+      free(m);
+      free(REQUEST);
+      free(SERVICE_URL);
+      return 0;
     }
-    if(strcmp(mtoupper(REQUEST),"DESCRIBEPROCESS")==0){
+    if(strncasecmp(REQUEST,"DescribeProcess",15)==0){
       /**
        * Loop over Identifier list
        */
       xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
-      doc->encoding = xmlCharStrdup ("UTF-8");
       r_inputs=NULL;
       r_inputs=getMap(request_inputs,"ServiceProvider");
+
       xmlNodePtr n;
       if(r_inputs!=NULL)
 	n = printDescribeProcessHeader(doc,r_inputs->value,m);
+      else
+	n = printDescribeProcessHeader(doc,"",m);
 
       r_inputs=getMap(request_inputs,"Identifier");
@@ -286,5 +346,5 @@
       while(tmps){
 	memset(buff,0,256);
-	sprintf(buff,"%s.zcfg",tmps);
+	snprintf(buff,256,"%s.zcfg",tmps);
 	memset(buff1,0,1024);
 #ifdef DEBUG
@@ -294,16 +354,20 @@
 	  if(strcmp(dp->d_name,buff)==0){
 	    memset(buff1,0,1024);
-	    sprintf(buff1,"%s/%s",conf_dir,dp->d_name);
-	    s1=(service*)malloc(sizeof(service*));
-	    s[scount]=(service*)malloc(sizeof(service*));
-#ifdef DEBUG
-	    fprintf(stderr,"#################\n%s\n#################\n",tmps1);
+	    snprintf(buff1,1024,"%s/%s",conf_dir,dp->d_name);
+	    //s1=(service*)malloc(sizeof(service*));
+	    s1=(service*)calloc(1,SERVICE_SIZE);
+	    if(s1 == NULL){
+	      return errorException(m, "Unable to allocate memory.","InternalError");
+	    }
+#ifdef DEBUG
+	    fprintf(stderr,"#################\n%s\n#################\n",buff1);
 #endif
 	    t=getServiceFromFile(buff1,&s1);
-	    /*dumpService(s1);
-	      fflush(stdout);
-	      fflush(stderr);*/
-	    s[0]=s1;
-	    printDescribeProcessForProcess(m,n,s,1);
+#ifdef DEBUG
+	    dumpService(s1);
+#endif
+	    printDescribeProcessForProcess(m,n,s1,1);
+	    freeService(&s1);
+	    free(s1);
 	    scount++;
 	  }
@@ -311,38 +375,47 @@
 	tmps=strtok(NULL,",");
       }
-      (void)closedir(dirp);
+      closedir(dirp);
       fflush(stdout);
       dup2(saved_stdout,fileno(stdout));
-
-      printDocument(doc);
+      printDocument(m,doc,getpid());
+      freeMaps(&m);
+      free(m);
+      free(REQUEST);
+      free(SERVICE_URL);
       fflush(stdout);
       //xmlFree(n);
 #ifndef LINUX_FREE_ISSUE
-      free(s1);
+      if(s1)
+	free(s1);
 #endif
       return 0;
     }
     else
-      if(strcmp(mtoupper(REQUEST),"EXECUTE")!=0){
-	tmps=createMap("text","Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.");
-	addToMap(tmps,"code","InvalidParameterValue");
-	printExceptionReportResponse(m,tmps);
+      if(strncasecmp(REQUEST,"Execute",strlen(REQUEST))!=0){
+	errorException(m, "Unenderstood <request> value. Please check that it was set to GetCapabilities, DescribeProcess or Execute.", "InvalidParameterValue");
 #ifdef DEBUG
 	fprintf(stderr,"No request found %s",REQUEST);
 #endif	
+	closedir(dirp);
 	free(s);
 	return 0;
       }
+    closedir(dirp);
   }
   
   s1=NULL;
-  s1=(service*)malloc(sizeof(service*));
-  s[0]=(service*)malloc(sizeof(service*));
+  s1=(service*)calloc(1,SERVICE_SIZE);
+  if(s1 == NULL){
+    return errorException(m, "Unable to allocate memory.","InternalError");
+  }
   r_inputs=getMap(request_inputs,"MetaPath");
-  sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
+  if(r_inputs!=NULL)
+    snprintf(tmps1,1024,"%s/%s",ntmp,r_inputs->value);
+  else
+    snprintf(tmps1,1024,"%s/",ntmp);
   r_inputs=getMap(request_inputs,"Identifier");
-
-  sprintf(tmps1,"%s/%s.zcfg",strdup(tmps1),r_inputs->value);
-
+  char *ttmp=strdup(tmps1);
+  snprintf(tmps1,1024,"%s/%s.zcfg",ttmp,r_inputs->value);
+  free(ttmp);
 #ifdef DEBUG
   fprintf(stderr,"Trying to load %s\n", tmps1);
@@ -354,10 +427,8 @@
   dup2(saved_stdout,fileno(stdout));
   if(t==22){
-    tmps=createMap("text","The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.");
-    addToMap(tmps,"code","InvalidParameterValue");
-    printExceptionReportResponse(m,tmps);
+    errorException(m, "The value for <indetifier> seems to be wrong. Please, ensure that the process exsits using the GetCapabilities request.", "InvalidParameterValue");
     exit(0);
   }
-  s[0]=s1;
+  //s[0]=s1;
 
 #ifdef DEBUG
@@ -399,16 +470,18 @@
 #endif
     r_inputs=getMap(request_inputs,"ResponseDocument");	
-    if(r_inputs==NULLMAP)
-      r_inputs=getMap(request_inputs,"RawDataOutput");
-#ifdef DEBUG
+    if(r_inputs==NULL) r_inputs=getMap(request_inputs,"RawDataOutput");
+    
+    //#ifdef DEBUG
     fprintf(stderr,"OUTPUT Parsing ... \n");
-#endif
-    if(r_inputs!=NULLMAP){
-#ifdef DEBUG
+    //#endif
+    if(r_inputs!=NULL){
+      //#ifdef DEBUG
       fprintf(stderr,"OUTPUT Parsing start now ... \n");
-#endif
+      //#endif
       char current_output_as_string[10240];
       char cursor_output[10240];
-      sprintf(cursor_output,"%s",strdup(r_inputs->value));
+      char *cotmp=strdup(r_inputs->value);
+      snprintf(cursor_output,10240,"%s",cotmp);
+      free(cotmp);
       j=0;
       map* request_kvp_outputs=NULL;
@@ -423,5 +496,8 @@
 #endif
       pToken=strtok(cursor_output,";");
-      char** outputs_as_text=(char**)malloc(128*sizeof(char*));
+      char** outputs_as_text=(char**)calloc(128,sizeof(char*));
+      if(outputs_as_text == NULL) {
+	return errorException(m, "Unable to allocate memory", "InternalError");
+      }
       i=0;
       while(pToken!=NULL){
@@ -431,6 +507,9 @@
 	fprintf(stderr,"***%s***\n",pToken);
 #endif
-	outputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
-	sprintf(outputs_as_text[i],"%s",pToken);
+	outputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char));
+	if(outputs_as_text[i] == NULL) {
+	  return errorException(m, "Unable to allocate memory", "InternalError");
+	}
+	snprintf(outputs_as_text[i],strlen(pToken)+1,"%s",pToken);
 	pToken = strtok(NULL,";");
 	i++;
@@ -438,4 +517,5 @@
       for(j=0;j<i;j++){
 	char *tmp=strdup(outputs_as_text[j]);
+	free(outputs_as_text[j]);
 	char *tmpc;
 	tmpc=strtok(tmp,"@");
@@ -444,5 +524,8 @@
 	  if(k==0){
 	    if(tmp_output==NULL){
-	      tmp_output=(maps*)malloc(MAPS_SIZE);
+	      tmp_output=(maps*)calloc(1,MAPS_SIZE);
+	      if(tmp_output == NULL){
+		return errorException(m, "Unable to allocate memory.", "InternalError");
+	      }
 	      tmp_output->name=strdup(tmpc);
 	      tmp_output->content=NULL;
@@ -473,13 +556,18 @@
 	}
 	if(request_output_real_format==NULL)
-	  request_output_real_format=tmp_output;
+	  request_output_real_format=dupMaps(&tmp_output);
 	else
 	  addMapsToMaps(&request_output_real_format,tmp_output);
+	freeMaps(&tmp_output);
+	free(tmp_output);
+	tmp_output=NULL;
 #ifdef DEBUG
 	dumpMaps(tmp_output);
 	fflush(stderr);
 #endif
-	tmp_output=tmp_output->next;
+	//tmp_output=tmp_output->next;
+	free(tmp);
       }
+      free(outputs_as_text);
     }
 
@@ -494,5 +582,14 @@
     char current_input_as_string[40960];
     char cursor_input[40960];
-    sprintf(cursor_input,"%s",strdup(r_inputs->value));
+    if(r_inputs!=NULL)
+      snprintf(cursor_input,40960,"%s",r_inputs->value);
+    else{
+      errorException(m, "Parameter <DataInputs> was not specified","MissingParameterValue");
+      freeMaps(&m);
+      free(m);
+      free(REQUEST);
+      free(SERVICE_URL);
+      return 0;
+    }
     j=0;
     map* request_kvp_inputs=NULL;
@@ -503,5 +600,8 @@
     char * pToken;
     pToken=strtok(cursor_input,";");
-    char** inputs_as_text=(char**)malloc(100*sizeof(char*));
+    char** inputs_as_text=(char**)calloc(100,sizeof(char*));
+    if(inputs_as_text == NULL){
+      return errorException(m, "Unable to allocate memory.", "InternalError");
+    }
     i=0;
     while(pToken!=NULL){
@@ -513,6 +613,9 @@
       fprintf(stderr,"***%s***\n",pToken);
 #endif
-      inputs_as_text[i]=(char*)malloc(strlen(pToken)*sizeof(char));
-      sprintf(inputs_as_text[i],"%s",pToken);
+      inputs_as_text[i]=(char*)calloc(strlen(pToken)+1,sizeof(char));
+      snprintf(inputs_as_text[i],strlen(pToken)+1,"%s",pToken);
+      if(inputs_as_text[i] == NULL){
+	return errorException(m, "Unable to allocate memory.", "InternalError");
+      }
       pToken = strtok(NULL,";");
       i++;
@@ -521,4 +624,5 @@
     for(j=0;j<i;j++){
       char *tmp=strdup(inputs_as_text[j]);
+      free(inputs_as_text[j]);
       char *tmpc;
       tmpc=strtok(tmp,"@");
@@ -537,5 +641,8 @@
 #endif
 	if(tmpmaps==NULL){
-	  tmpmaps=(maps*)malloc(MAPS_SIZE);
+	  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	  if(tmpmaps == NULL){
+	    return errorException(m, "Unable to allocate memory.", "InternalError");
+	  }
 	  tmpmaps->name=strdup(tmpn);
 	  tmpmaps->content=createMap("value",tmpv+1);
@@ -566,37 +673,52 @@
 #endif
 #ifndef WIN32
-		if(CHECK_INET_HANDLE(hInternet))
-#endif
-		{
-	      res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
-					    INTERNET_FLAG_NO_CACHE_WRITE,0);
-#ifdef DEBUG
-	      fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
-		      tmpv1+1,res.nDataAlloc,res.nDataLen);
-#endif
-	      char* tmpContent=(char*)malloc((res.nDataLen+1)*sizeof(char));
-	      size_t dwRead;
-	      InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
-	      map* tmpMap=getMap(tmpmaps->content,"value");
-	      if(tmpMap!=NULL)
-		tmpMap->value=tmpContent;
-	    }
+	    if(CHECK_INET_HANDLE(hInternet))
+#endif
+	      {
+		res=InternetOpenUrl(hInternet,tmpv1+1,NULL,0,
+				    INTERNET_FLAG_NO_CACHE_WRITE,0);
+#ifdef DEBUG
+		fprintf(stderr,"(%s) content-length : %d,,res.nDataAlloc %d \n",
+			tmpv1+1,res.nDataAlloc,res.nDataLen);
+#endif
+		char* tmpContent=(char*)calloc((res.nDataLen+1),sizeof(char));
+		if(tmpContent == NULL){
+		  return errorException(m, "Unable to allocate memory.", "InternalError");
+		}
+		size_t dwRead;
+		InternetReadFile(res, (LPVOID)tmpContent,res.nDataLen, &dwRead);
+		map* tmpMap=getMap(tmpmaps->content,"value");
+		if(tmpMap!=NULL)
+		  tmpMap->value=strdup(tmpContent);
+		free(tmpContent);
+	      }
 	    addToMap(tmpmaps->content,tmpn1,tmpv1+1);
 	  }
 	  tmpc=strtok(NULL,"@");
 	}
+#ifdef DEBUG
+	dumpMaps(tmpmaps);
+	fflush(stderr);
+#endif
 	if(request_input_real_format==NULL)
-	  request_input_real_format=tmpmaps;
+	  request_input_real_format=dupMaps(&tmpmaps);
 	else
 	  addMapsToMaps(&request_input_real_format,tmpmaps);
-#ifdef DEBUG
-	dumpMaps(tmpmaps);
-	fflush(stderr);
-#endif
-	tmpmaps=tmpmaps->next;
+	/*freeMap(&tmpmaps->content);
+	free(tmpmaps->content);
+	tmpmaps->content=NULL;*/
+	freeMaps(&tmpmaps);
+	free(tmpmaps);
+	  //}
+	tmpmaps=NULL;
+	free(tmp);
       }
     }
-  } 
+    free(inputs_as_text);
+  }
   else {
+    /**
+     * Parse XML request
+     */ 
     xmlInitParser();
 #ifdef DEBUG
@@ -616,6 +738,6 @@
      */
     maps* tempMaps=NULL;
-    xmlNodeSet* tmps=extractFromDoc(doc,
-				    "/*/*/*[local-name()='Input']");
+    xmlXPathObjectPtr tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='Input']");
+    xmlNodeSet* tmps=tmpsptr->nodesetval;
 #ifdef DEBUG
     fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
@@ -631,168 +753,222 @@
 	fprintf(stderr, "= element 0 node \"%s\"\n", cur->name);
 #endif
-	xmlNodePtr cur1=cur->children;
-	while(cur1){
-#ifdef DEBUG
-	  fprintf(stderr, "= element 1 node \"%s\" = (%s)\n", 
-		  cur1->name,xmlNodeListGetString(doc,cur1,1));
-#endif
-	  xmlNodePtr cur2=cur1/*->next*/;
-	  while(cur2){
+	xmlNodePtr cur2=cur->children;
+	while(cur2){
+	  while(cur2->type!=XML_ELEMENT_NODE)
+	    cur2=cur2->next;
+	  /**
+	   * Indentifier
+	   */
+	  if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
+	    xmlChar *val= xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
+	    if(tmpmaps==NULL){
+	      tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	      if(tmpmaps == NULL){
+		return errorException(m, "Unable to allocate memory.", "InternalError");
+	      }
+	      tmpmaps->name=strdup((char*)val);
+	      tmpmaps->content=NULL;
+	      tmpmaps->next=NULL;
+	    }
+	    xmlFree(val);
+	  }
+	  /**
+	   * Title, Asbtract
+	   */
+	  if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
+	     xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
+	    xmlChar *val=
+	      xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
+	    if(tmpmaps==NULL){
+	      tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	      if(tmpmaps == NULL){
+		return errorException(m, "Unable to allocate memory.", "InternalError");
+	      }
+	      tmpmaps->name="missingIndetifier";
+	      tmpmaps->content=createMap((char*)cur2->name,(char*)val);
+	      tmpmaps->next=NULL;
+	    }
+	    else{
+	      if(tmpmaps->content!=NULL)
+		addToMap(tmpmaps->content,
+			 (char*)cur2->name,(char*)val);
+	      else
+		tmpmaps->content=
+		  createMap((char*)cur2->name,(char*)val);
+	    }
+#ifdef DEBUG
+	    dumpMaps(tmpmaps);
+#endif
+	    xmlFree(val);
+	  }
+	  /**
+	   * InputDataFormChoice (Reference or Data ?) 
+	   */
+	  if(xmlStrcasecmp(cur2->name,BAD_CAST "Reference")==0){
 	    /**
-	     * Indentifier
+	     * Get every attribute from a Reference node
+	     * mimeType, encoding, schema, href, method
+	     * Header and Body gesture should be added here
 	     */
-	    if(strcmp(mtoupper((char*)cur2->name),
-		      mtoupper("Identifier"))==0){
-	      xmlChar *val=
-		xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
-	      if(tmpmaps==NULL){
-		tmpmaps=(maps*)malloc(MAPS_SIZE);
-		tmpmaps->name=strdup((char*)val);
-		tmpmaps->content=NULL;
-		tmpmaps->next=NULL;
+#ifdef DEBUG
+	    fprintf(stderr,"REFERENCE\n");
+#endif
+	    map* referenceMap=NULL;
+	    char *refs[5];
+	    refs[0]="mimeType";
+	    refs[1]="encoding";
+	    refs[2]="schema";
+	    refs[3]="method";
+	    refs[4]="href";
+	    char*url;
+	    for(int l=0;l<5;l++){
+#ifdef DEBUG
+	      fprintf(stderr,"*** %s ***",refs[l]);
+#endif
+	      xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]);
+	      if(val!=NULL && xmlStrlen(val)>0){
+		if(tmpmaps->content!=NULL)
+		  addToMap(tmpmaps->content,refs[l],(char*)val);
+		else
+		  tmpmaps->content=createMap(refs[l],(char*)val);
+		map* ltmp=getMap(tmpmaps->content,"method");
+		if(l==4){
+		  if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
+		     && CHECK_INET_HANDLE(hInternet)){
+		    res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
+					INTERNET_FLAG_NO_CACHE_WRITE,0);
+		    char* tmpContent=
+		      (char*)calloc((res.nDataLen+1),sizeof(char));
+		    if(tmpContent == NULL){
+		      return errorException(m, "Unable to allocate memory.", "InternalError");
+		    }
+		    size_t dwRead;
+		    InternetReadFile(res, (LPVOID)tmpContent,
+				     res.nDataLen, &dwRead);
+		    tmpContent[res.nDataLen]=0;
+		    addToMap(tmpmaps->content,"value",tmpContent);
+		  }
+		}
 	      }
+#ifdef DEBUG
+	      fprintf(stderr,"%s\n",val);
+#endif
 	      xmlFree(val);
 	    }
-	    /**
-	     * Title, Asbtract
-	     */
-	    if(strcmp(mtoupper((char*)cur2->name),
-		      mtoupper("Title"))==0 ||
-	       strcmp(mtoupper((char*)cur2->name),
-		      mtoupper("Abstract"))==0){
-	      xmlChar *val=
-		xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
-	      if(tmpmaps==NULL){
-		tmpmaps=(maps*)malloc(MAPS_SIZE);
-		tmpmaps->name="missingIndetifier";
-		tmpmaps->content=createMap((char*)cur2->name,(char*)val);
-		tmpmaps->next=NULL;
+#ifdef POST_DEBUG
+	    fprintf(stderr,"Parse Header and Body from Reference \n");
+#endif
+	    xmlNodePtr cur3=cur2->children;
+	    hInternet.header=NULL;
+	    while(cur3){
+	      if(xmlStrcasecmp(cur3->name,BAD_CAST "Header")==0 ){
+		xmlNodePtr cur4=cur3;
+		char *tmp=new char[cgiContentLength];
+		char *ha[2];
+		ha[0]="key";
+		ha[1]="value";
+		int hai;
+		char *has;
+		char *key;
+		for(hai=0;hai<2;hai++){
+		  xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]);
+#ifdef POST_DEBUG
+		  fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
+#endif
+		  if(hai==0){
+		    key=(char*)calloc((1+strlen((char*)val)),sizeof(char));
+		    snprintf(key,1+strlen((char*)val),"%s",(char*)val);
+		  }else{
+		    has=(char*)calloc((3+strlen((char*)val)+strlen(key)),sizeof(char));
+		    if(has == NULL){
+		      return errorException(m, "Unable to allocate memory.", "InternalError");
+		    }
+		    snprintf(has,(3+strlen((char*)val)+strlen(key)),"%s: %s",key,(char*)val);
+#ifdef POST_DEBUG
+		    fprintf(stderr,"%s\n",has);
+#endif
+		  }
+		}
+		hInternet.header=curl_slist_append(hInternet.header, has);
+		//free(has);
 	      }
 	      else{
-		if(tmpmaps->content!=NULL)
-		  addToMap(tmpmaps->content,
-			   (char*)cur2->name,(char*)val);
+#ifdef POST_DEBUG
+		fprintf(stderr,"Try to fetch the body part of the request ...\n");
+#endif
+		if(xmlStrcasecmp(cur3->name,BAD_CAST "Body")==0 ){
+#ifdef POST_DEBUG
+		  fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
+#endif
+		  char *tmp=new char[cgiContentLength];
+		  memset(tmp,0,cgiContentLength);
+		  xmlNodePtr cur4=cur3->children;
+		  while(cur4!=NULL){
+		    xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
+		    bdoc->encoding = xmlCharStrdup ("UTF-8");
+		    xmlDocSetRootElement(bdoc,cur4);
+		    xmlChar* btmps;
+		    int bsize;
+		    xmlDocDumpMemory(bdoc,&btmps,&bsize);
+#ifdef POST_DEBUG
+		    fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps);
+#endif
+		    if(btmps!=NULL)
+		      sprintf(tmp,"%s",(char*)btmps);
+		    xmlFreeDoc(bdoc);
+		    cur4=cur4->next;
+		  }
+		  map *btmp=getMap(tmpmaps->content,"href");
+		  if(btmp!=NULL){
+#ifdef POST_DEBUG
+		    fprintf(stderr,"%s %s\n",btmp->value,tmp);
+		    curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
+#endif
+		    res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
+					INTERNET_FLAG_NO_CACHE_WRITE,0);
+		    char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
+		    if(tmpContent == NULL){
+		      return errorException(m, "Unable to allocate memory.", "InternalError");
+		    }
+		    size_t dwRead;
+		    InternetReadFile(res, (LPVOID)tmpContent,
+				     res.nDataLen, &dwRead);
+		    tmpContent[res.nDataLen]=0;
+		    if(hInternet.header!=NULL)
+		      curl_slist_free_all(hInternet.header);
+		    addToMap(tmpmaps->content,"value",tmpContent);
+#ifdef POST_DEBUG
+		    fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
+#endif
+		  }
+		}
 		else
-		  tmpmaps->content=
-		    createMap((char*)cur2->name,(char*)val);
-	      }
-#ifdef DEBUG
-	      dumpMaps(tmpmaps);
-#endif
-	      xmlFree(val);
-	    }
-	    /**
-	     * InputDataFormChoice (Reference or Data ?) 
-	     */
-	    if(strcmp(mtoupper((char*)cur2->name),
-		      mtoupper("Reference"))==0){
-	      /**
-	       * Get every attribute from a Reference node
-	       * mimeType, encoding, schema, href, method
-	       * Header and Body gesture should be added here
-	       */
-#ifdef DEBUG
-	      fprintf(stderr,"REFERENCE\n");
-#endif
-	      map* referenceMap=NULL;
-	      char *refs[5];
-	      refs[0]="mimeType";
-	      refs[1]="encoding";
-	      refs[2]="schema";
-	      refs[3]="method";
-	      refs[4]="href";
-	      char*url;
-	      for(int l=0;l<5;l++){
-#ifdef DEBUG
-		fprintf(stderr,"*** %s ***\t",refs[l]);
-#endif
-		xmlChar *val=xmlGetProp(cur2,BAD_CAST refs[l]);
-		if(val!=NULL && strlen((char*)val)>0){
-		  if(tmpmaps->content!=NULL)
-		    addToMap(tmpmaps->content,refs[l],(char*)val);
-		  else
-		    tmpmaps->content=createMap(refs[l],(char*)val);
-		  map* ltmp=getMap(tmpmaps->content,"method");
-		  if(l==4){
-		    if(!(ltmp!=NULL && strcmp(ltmp->value,"POST")==0)
-		       && CHECK_INET_HANDLE(hInternet)){
-			res=InternetOpenUrl(hInternet,(char*)val,NULL,0,
-					    INTERNET_FLAG_NO_CACHE_WRITE,0);
-			char* tmpContent=
-			  (char*)malloc((res.nDataLen+1)*sizeof(char));
-			size_t dwRead;
-			InternetReadFile(res, (LPVOID)tmpContent,
-					 res.nDataLen, &dwRead);
-			tmpContent[res.nDataLen]=0;
-			addToMap(tmpmaps->content,"value",tmpContent);
+		  if(xmlStrcasecmp(cur3->name,BAD_CAST "BodyReference")==0 ){
+		    xmlChar *val=xmlGetProp(cur3,BAD_CAST "href");
+		    HINTERNET bInternet,res1;
+		    bInternet=InternetOpen(
+#ifndef WIN32
+					   (LPCTSTR)
+#endif
+					   "ZooWPSClient\0",
+					   INTERNET_OPEN_TYPE_PRECONFIG,
+					   NULL,NULL, 0);
+		    if(!CHECK_INET_HANDLE(bInternet))
+		      fprintf(stderr,"WARNING : hInternet handle failed to initialize");
+#ifdef POST_DEBUG
+		    curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
+#endif
+		    res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
+					 INTERNET_FLAG_NO_CACHE_WRITE,0);
+		    char* tmp=
+		      (char*)calloc((res1.nDataLen+1),sizeof(char));
+		    if(tmp == NULL){
+		      return errorException(m, "Unable to allocate memory.", "InternalError");
 		    }
-		  }
-		  
-		}
-#ifdef DEBUG
-		fprintf(stderr,"%s\n",val);
-#endif
-		xmlFree(val);
-	      }
-#ifdef POST_DEBUG
-	      fprintf(stderr,"Parse Header and Body from Reference \n");
-#endif
-	      xmlNodePtr cur3=cur2->children;
-	      hInternet.header=NULL;
-	      while(cur3){
-		if(strcmp(mtoupper((char*)cur3->name), mtoupper("Header"))==0 ){
-		  xmlNodePtr cur4=cur3;
-		  char *tmp=new char[cgiContentLength];
-		  char *ha[2];
-		  ha[0]="key";
-		  ha[1]="value";
-		  int hai;
-		  char *has;
-		  char *key;
-		  for(hai=0;hai<2;hai++){
-		    xmlChar *val=xmlGetProp(cur3,BAD_CAST ha[hai]);
-#ifdef POST_DEBUG
-		    fprintf(stderr,"%s = %s\n",ha[hai],(char*)val);
-#endif
-		    if(hai==0){
-		      key=(char*)malloc((1+strlen((char*)val))*sizeof(char));
-		      sprintf(key,"%s",(char*)val);
-		    }else{
-		      has=(char*)malloc((3+strlen((char*)val)+strlen(key))*sizeof(char));
-		      sprintf(has,"%s: %s",key,(char*)val);
-#ifdef POST_DEBUG
-		      fprintf(stderr,"%s\n",has);
-#endif
-		    }
-		  }
-		  hInternet.header=curl_slist_append(hInternet.header, has);
-		  //free(has);
-		}
-		else{
-#ifdef POST_DEBUG
-		  fprintf(stderr,"Try to fetch the body part of the request ...\n");
-#endif
-		  if(strcmp(mtoupper((char*)cur3->name),mtoupper("Body"))==0 ){
-#ifdef POST_DEBUG
-		    fprintf(stderr,"Body part found !!!\n",(char*)cur3->content);
-#endif
-		    char *tmp=new char[cgiContentLength];
-		    memset(tmp,cgiContentLength,0);
-		    xmlNodePtr cur4=cur3->children;
-		    while(cur4!=NULL){
-		      xmlDocPtr bdoc = xmlNewDoc(BAD_CAST "1.0");
-		      bdoc->encoding = xmlCharStrdup ("UTF-8");
-		      xmlDocSetRootElement(bdoc,cur4);
-		      xmlChar* btmps;
-		      int bsize;
-		      xmlDocDumpMemory(bdoc,&btmps,&bsize);
-#ifdef POST_DEBUG
-		      fprintf(stderr,"Body part found !!! %s %s\n",tmp,(char*)btmps);
-#endif
-		      if(btmps!=NULL)
-			sprintf(tmp,"%s",(char*)btmps);
-		      xmlFreeDoc(bdoc);
-		      cur4=cur4->next;
-		    }
+		    size_t bRead;
+		    InternetReadFile(res1, (LPVOID)tmp,
+				     res1.nDataLen, &bRead);
+		    tmp[res1.nDataLen]=0;
+		    InternetCloseHandle(bInternet);
 		    map *btmp=getMap(tmpmaps->content,"href");
 		    if(btmp!=NULL){
@@ -801,8 +977,11 @@
 		      curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
 #endif
-		      res=InternetOpenUrl(hInternet,btmp->value,tmp,strlen(tmp),
+		      res=InternetOpenUrl(hInternet,btmp->value,tmp,
+					  strlen(tmp),
 					  INTERNET_FLAG_NO_CACHE_WRITE,0);
-		      char* tmpContent=
-			(char*)malloc((res.nDataLen+1)*sizeof(char));
+		      char* tmpContent = (char*)calloc((res.nDataLen+1),sizeof(char));
+		      if(tmpContent == NULL){
+			return errorException(m, "Unable to allocate memory.", "InternalError");
+		      }
 		      size_t dwRead;
 		      InternetReadFile(res, (LPVOID)tmpContent,
@@ -817,187 +996,102 @@
 		    }
 		  }
-		  else
-		    if(strcmp(mtoupper((char*)cur3->name),mtoupper("BodyReference"))==0 ){
-		      xmlChar *val=xmlGetProp(cur3,BAD_CAST "href");
-		      HINTERNET bInternet,res1;
-		      bInternet=InternetOpen(
-#ifndef WIN32
-				  (LPCTSTR)
-#endif
-				  "ZooWPSClient\0",
-					     INTERNET_OPEN_TYPE_PRECONFIG,
-					     NULL,NULL, 0);
-		      if(!CHECK_INET_HANDLE(bInternet))
-			fprintf(stderr,"WARNING : hInternet handle failed to initialize");
+	      }
+	      cur3=cur3->next;
+	    }
 #ifdef POST_DEBUG
-		      curl_easy_setopt(bInternet.handle, CURLOPT_VERBOSE, 1);
-#endif
-		      res1=InternetOpenUrl(bInternet,(char*)val,NULL,0,
-					   INTERNET_FLAG_NO_CACHE_WRITE,0);
-		      char* tmp=
-			(char*)malloc((res1.nDataLen+1)*sizeof(char));
-		      size_t bRead;
-		      InternetReadFile(res1, (LPVOID)tmp,
-				       res1.nDataLen, &bRead);
-		      tmp[res1.nDataLen]=0;
-		      InternetCloseHandle(bInternet);
-		      map *btmp=getMap(tmpmaps->content,"href");
-		      if(btmp!=NULL){
-#ifdef POST_DEBUG
-			fprintf(stderr,"%s %s\n",btmp->value,tmp);
-			curl_easy_setopt(hInternet.handle, CURLOPT_VERBOSE, 1);
-#endif
-			res=InternetOpenUrl(hInternet,btmp->value,tmp,
-					    strlen(tmp),
-					    INTERNET_FLAG_NO_CACHE_WRITE,0);
-			char* tmpContent=
-			  (char*)malloc((res.nDataLen+1)*sizeof(char));
-			size_t dwRead;
-			InternetReadFile(res, (LPVOID)tmpContent,
-					 res.nDataLen, &dwRead);
-			tmpContent[res.nDataLen]=0;
-			if(hInternet.header!=NULL)
-			  curl_slist_free_all(hInternet.header);
-			addToMap(tmpmaps->content,"value",tmpContent);
-#ifdef POST_DEBUG
-			fprintf(stderr,"DL CONTENT : (%s)\n",tmpContent);
-#endif
-		      }
-		    }
-		}
-		cur3=cur3->next;
-	      }
-#ifdef POST_DEBUG
-	      fprintf(stderr,"Header and Body was parsed from Reference \n");
-#endif
-#ifdef DEBUG
-	      dumpMap(tmpmaps->content);
-	      fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", 
-		      cur2->name,cur2->content);
-#endif
-	    }
-	    else if(strcmp(mtoupper((char*)cur2->name),
-			   mtoupper("Data"))==0){
-#ifdef DEBUG
-	      fprintf(stderr,"DATA\n");
-#endif
-	      xmlNodePtr cur4=cur2->children;
-	      while(cur4){
-		if(strcmp(mtoupper((char*)cur4->name),
-			  mtoupper("LiteralData"))==0){
-		  /**
-		   * Get every attribute from a LiteralData node
-		   * dataType , uom
-		   */
-		  char *lits[2];
-		  lits[0]="dataType";
-		  lits[1]="uom";
-		  for(int l=0;l<2;l++){
-#ifdef DEBUG
-		    fprintf(stderr,"*** %s ***\t",lits[l]);
-#endif
-		    xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]);
-		    if(val!=NULL && strlen((char*)val)>0){
-		      if(tmpmaps->content!=NULL)
-			addToMap(tmpmaps->content,lits[l],(char*)val);
-		      else
-			tmpmaps->content=createMap(lits[l],(char*)val);
-		    }
-#ifdef DEBUG
-		    fprintf(stderr,"%s\n",val);
-#endif
-		    xmlFree(val);
-		  }
-		  xmlChar* mv=xmlNodeListGetString(doc,
-						   cur4->xmlChildrenNode,1);
-		  if(tmpmaps->content!=NULL)
-		    addToMap(tmpmaps->content,
-			     "value",
-			     (char*)mv);
-		  else
-		    tmpmaps->content=
-		      createMap("value",
-				(char*)mv);
-		  xmlFree(mv);
-		}
-		else if(strcmp(mtoupper((char*)cur4->name),
-			       mtoupper("ComplexData"))==0){
-		  /**
-		   * Get every attribute from a Reference node
-		   * mimeType, encoding, schema
-		   */
-		  char *coms[2];
-		  coms[0]="mimeType";
-		  coms[1]="encoding";
-		  coms[2]="schema";
-		  for(int l=0;l<2;l++){
-#ifdef DEBUG
-		    fprintf(stderr,"*** %s ***\t",coms[l]);
-#endif
-		    xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
-		    if(val!=NULL && strlen((char*)val)>0){
-		      if(tmpmaps->content!=NULL)
-			addToMap(tmpmaps->content,coms[l],(char*)val);
-		      else
-			tmpmaps->content=createMap(coms[l],(char*)val);
-		    }
-#ifdef DEBUG
-		    fprintf(stderr,"%s\n",val);
-#endif
-		    xmlFree(val);
-		  }
-		  xmlChar* mv=xmlNodeListGetString(doc,
-						   cur4->xmlChildrenNode,1);
-		  if(tmpmaps->content!=NULL)
-		    addToMap(tmpmaps->content,
-			     "value",
-			     (char*)mv);
-		  else
-		    tmpmaps->content=
-		      createMap("value",
-				(char*)mv);
-		  xmlFree(mv);
-		}
-		cur4=cur4->next;
-	      }
-	    }
+	    fprintf(stderr,"Header and Body was parsed from Reference \n");
+#endif
 #ifdef DEBUG
 	    dumpMap(tmpmaps->content);
 	    fprintf(stderr, "= element 2 node \"%s\" = (%s)\n", 
-		    cur2->name,cur2->content);	
-#endif
-	    xmlNodePtr cur3=cur->children;
-	    while(cur3){
-#ifdef DEBUG
-	      fprintf(stderr, "= element 3 node \"%s\" = (%s)\n",cur3->name,
-		      xmlNodeListGetString(doc,cur3->xmlChildrenNode,1));
-#endif
-	      if(strcmp(mtoupper((char*)cur3->name),
-			mtoupper("Title"))==0){
-#ifdef DEBUG
-		fprintf(stderr, "= element 3 node \"%s\" = (%s)\n", 
-			cur3->name,xmlNodeListGetString(doc,cur3,1));
-#endif
+		    cur2->name,cur2->content);
+#endif
+	  }
+	  else if(xmlStrcasecmp(cur2->name,BAD_CAST "Data")==0){
+#ifdef DEBUG
+	    fprintf(stderr,"DATA\n");
+#endif
+	    xmlNodePtr cur4=cur2->children;
+	    while(cur4){
+	      while(cur4->type!=XML_ELEMENT_NODE)
+		cur4=cur4->next;
+
+	      if(xmlStrcasecmp(cur4->name, BAD_CAST "LiteralData")==0){
+		/**
+		 * Get every attribute from a LiteralData node
+		 * dataType , uom
+		 */
+		char *lits[2];
+		lits[0]="dataType";
+		lits[1]="uom";
+		for(int l=0;l<2;l++){
+#ifdef DEBUG
+		  fprintf(stderr,"*** LiteralData %s ***",lits[l]);
+#endif
+		  xmlChar *val=xmlGetProp(cur4,BAD_CAST lits[l]);
+		  if(val!=NULL && strlen((char*)val)>0){
+		    if(tmpmaps->content!=NULL)
+		      addToMap(tmpmaps->content,lits[l],(char*)val);
+		    else
+		      tmpmaps->content=createMap(lits[l],(char*)val);
+		  }
+#ifdef DEBUG
+		  fprintf(stderr,"%s\n",val);
+#endif
+		  xmlFree(val);
+		}
 	      }
-	      cur3=cur3->children;
+	      else if(xmlStrcasecmp(cur4->name, BAD_CAST "ComplexData")==0){
+		/**
+		 * Get every attribute from a Reference node
+		 * mimeType, encoding, schema
+		 */
+		char *coms[3];
+		coms[0]="mimeType";
+		coms[1]="encoding";
+		coms[2]="schema";
+		for(int l=0;l<3;l++){
+#ifdef DEBUG
+		  fprintf(stderr,"*** ComplexData %s ***",coms[l]);
+#endif
+		  xmlChar *val=xmlGetProp(cur4,BAD_CAST coms[l]);
+		  if(val!=NULL && strlen((char*)val)>0){
+		    if(tmpmaps->content!=NULL)
+		      addToMap(tmpmaps->content,coms[l],(char*)val);
+		    else
+		      tmpmaps->content=createMap(coms[l],(char*)val);
+		  }
+#ifdef DEBUG
+		  fprintf(stderr,"%s\n",val);
+#endif
+		  xmlFree(val);
+		}
+	      }
+	      xmlChar* mv=xmlNodeListGetString(doc,cur4->xmlChildrenNode,1);
+	      addToMap(tmpmaps->content,"value",(char*)mv);
+	      xmlFree(mv);
+	      cur4=cur4->next;
 	    }
-	    cur2=cur2->next;
 	  }
-	  cur1=cur1->children;
+#ifdef DEBUG
+	  fprintf(stderr,"cur2 next \n");
+	  fflush(stderr);
+#endif
+	  cur2=cur2->next;
 	}
-	if(request_input_real_format==NULL)
-	  request_input_real_format=tmpmaps;
-	else
-	  addMapsToMaps(&request_input_real_format,tmpmaps);
-#ifdef DEBUG
+#ifdef DEBUG
+	fprintf(stderr,"ADD MAPS TO REQUEST MAPS !\n");
+	fflush(stderr);
+#endif
+	addMapsToMaps(&request_input_real_format,tmpmaps);
+	
+#ifdef DEBUG
+	fprintf(stderr,"******TMPMAPS*****\n");
 	dumpMaps(tmpmaps);
-#endif
-	fflush(stderr);
+	fprintf(stderr,"******REQUESTMAPS*****\n");
+	dumpMaps(request_input_real_format);
+#endif
 	tmpmaps=tmpmaps->next;
 	      
-      } else {
-#ifdef DEBUG
-	fprintf(stderr, "= node \"%s\": type %d\n", cur->name, cur->type);
-#endif
       }
 #ifdef DEBUG
@@ -1005,7 +1099,11 @@
 #endif
     }
-    
-    xmlFree(tmps);
-    tmps=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
+#ifdef DEBUG
+    fprintf(stderr,"Search for response document node\n");
+#endif
+    xmlXPathFreeObject(tmpsptr);
+    //xmlFree(tmps);
+    tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='ResponseDocument']");
+    tmps=tmpsptr->nodesetval;
 #ifdef DEBUG
     fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
@@ -1021,5 +1119,8 @@
 	 */
 	if(tmpmaps==NULL){
-	  tmpmaps=(maps*)malloc(MAPS_SIZE);
+	  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	  if(tmpmaps == NULL){
+	    return errorException(m, "Unable to allocate memory.", "InternalError");
+	  }
 	  tmpmaps->name="unknownIdentifier";
 	  tmpmaps->next=NULL;
@@ -1053,6 +1154,5 @@
 	xmlNodePtr cur1=cur->children;
 	while(cur1){
-	  if(strcmp(mtoupper((char*)cur1->name),
-		    mtoupper("Output"))==0){
+	  if(xmlStrncasecmp(cur1->name,BAD_CAST "Output",xmlStrlen(cur1->name))==0){
 	    /**
 	     * Get every attribute from a Output node
@@ -1087,10 +1187,12 @@
 	       * Indentifier
 	       */
-	      if(strcmp(mtoupper((char*)cur2->name),
-			mtoupper("Identifier"))==0){
+	      if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
 		xmlChar *val=
 		  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 		if(tmpmaps==NULL){
-		  tmpmaps=(maps*)malloc(MAPS_SIZE);
+		  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+		  if(tmpmaps == NULL){
+		    return errorException(m, "Unable to allocate memory.", "InternalError");
+		  }
 		  tmpmaps->name=strdup((char*)val);
 		  tmpmaps->content=NULL;
@@ -1104,12 +1206,13 @@
 	       * Title, Asbtract
 	       */
-	      if(strcmp(mtoupper((char*)cur2->name),
-			mtoupper("Title"))==0 ||
-		 strcmp(mtoupper((char*)cur2->name),
-			mtoupper("Abstract"))==0){
+	      if(xmlStrncasecmp(cur2->name,BAD_CAST "Title",xmlStrlen(cur2->name))==0 ||
+		 xmlStrncasecmp(cur2->name,BAD_CAST "Abstract",xmlStrlen(cur2->name))==0){
 		xmlChar *val=
 		  xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 		if(tmpmaps==NULL){
-		  tmpmaps=(maps*)malloc(MAPS_SIZE);
+		  tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+		  if(tmpmaps == NULL){
+		    return errorException(m, "Unable to allocate memory.", "InternalError");
+		  }
 		  tmpmaps->name="missingIndetifier";
 		  tmpmaps->content=createMap((char*)cur2->name,(char*)val);
@@ -1141,7 +1244,8 @@
 #endif
     }
-
-    xmlFree(tmps);
-    tmps=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']");
+    xmlXPathFreeObject(tmpsptr);
+    //xmlFree(tmps);
+    tmpsptr=extractFromDoc(doc,"/*/*/*[local-name()='RawDataOutput']");
+    tmps=tmpsptr->nodesetval;
 #ifdef DEBUG
     fprintf(stderr,"*****%d*****\n",tmps->nodeNr);
@@ -1167,5 +1271,8 @@
 	if(val!=NULL && strlen((char*)val)>0){
 	  if(tmpmaps==NULL){
-	    tmpmaps=(maps*)malloc(MAPS_SIZE);
+	    tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	    if(tmpmaps == NULL){
+	      return errorException(m, "Unable to allocate memory.", "InternalError");
+	    }
 	    tmpmaps->name="unknownIdentifier";
 	    tmpmaps->content=createMap(outs[l],(char*)val);
@@ -1186,10 +1293,12 @@
 	 * Indentifier
 	 */
-	if(strcmp(mtoupper((char*)cur2->name),
-		  mtoupper("Identifier"))==0){
+	if(xmlStrncasecmp(cur2->name,BAD_CAST "Identifier",xmlStrlen(cur2->name))==0){
 	  val=
 	    xmlNodeListGetString(doc,cur2->xmlChildrenNode,1);
 	  if(tmpmaps==NULL){
-	    tmpmaps=(maps*)malloc(MAPS_SIZE);
+	    tmpmaps=(maps*)calloc(1,MAPS_SIZE);
+	    if(tmpmaps == NULL){
+	      return errorException(m, "Unable to allocate memory.", "InternalError");
+	    }
 	    tmpmaps->name=strdup((char*)val);
 	    tmpmaps->content=NULL;
@@ -1210,11 +1319,11 @@
 #endif
     }
-    
-    xmlFree(tmps);
+    xmlXPathFreeObject(tmpsptr);
+    //xmlFree(tmps);
     xmlCleanupParser();
   }
 
-  if(CHECK_INET_HANDLE(hInternet))
-    InternetCloseHandle(hInternet);
+  //if(CHECK_INET_HANDLE(hInternet))
+  InternetCloseHandle(hInternet);
 
 #ifdef DEBUG
@@ -1222,5 +1331,5 @@
   dumpMaps(request_input_real_format);
   dumpMaps(request_output_real_format);
-  dumpElements();
+  dumpMap(request_inputs);
 #endif
 
@@ -1228,17 +1337,33 @@
    * Ensure that each requested arguments are present in the request
    * DataInputs and ResponseDocument / RawDataOutput
-   */
-  addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs");
+   */  
+  char *dfv=addDefaultValues(&request_input_real_format,s1->inputs,m,"inputs");
+  if(strcmp(dfv,"")!=0){
+    char tmps[1024];
+    snprintf(tmps,1024,"The <%s> argument was not specified in DataInputs but defined as requested in ZOO ServicesProvider configuration file, please correct your query or the ZOO Configuration file.",dfv);
+    map* tmpe=createMap("text",tmps);
+    addToMap(tmpe,"code","MissingParameterValue");
+    printExceptionReportResponse(m,tmpe);
+    freeMap(&tmpe);
+    free(tmpe);
+    freeMaps(&m);
+    free(m);
+    free(REQUEST);
+    freeMaps(&request_input_real_format);
+    free(request_input_real_format);
+    freeMaps(&request_output_real_format);
+    free(request_output_real_format);
+    freeMaps(&tmpmaps);
+    free(tmpmaps);
+    return 1;
+  }
   addDefaultValues(&request_output_real_format,s1->outputs,m,"outputs");
 
-  const struct tm *tm;
-  size_t len;
-  time_t now;
-  char *sDate;
-  
-  now = time ( NULL );
-  tm = localtime ( &now );
-
-  sDate = new char[TIME_SIZE];
+#ifdef DEBUG
+  fprintf(stderr,"REQUEST_INPUTS\n");
+  dumpMaps(request_input_real_format);
+  fprintf(stderr,"REQUEST_OUTPUTS\n");
+  dumpMaps(request_output_real_format);
+#endif
 
   maps* curs=getMaps(m,"env");
@@ -1280,6 +1405,4 @@
   }
   
-  len = strftime ( sDate, TIME_SIZE, "%d-%B-%YT%I:%M:%SZ", tm );
-
 #ifdef DEBUG
   dumpMap(request_inputs);
@@ -1297,4 +1420,7 @@
 #endif
 
+  if(r_inputs!=NULL)
+    if(strcasecmp(r_inputs->value,"false")==0)
+      r_inputs=NULL;
   if(r_inputs==NULLMAP){
     /**
@@ -1307,29 +1433,31 @@
     fflush(stderr);
 #endif
-
-	if(strncmp(mtoupper(r_inputs->value),"C",1)==0){
+    if(strncasecmp(r_inputs->value,"C",1)==0){
       r_inputs=getMap(request_inputs,"metapath");
-      sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
-	  char *altPath=strdup(tmps1);
+      if(r_inputs!=NULL)
+	sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
+      else
+	sprintf(tmps1,"%s/",ntmp);
+      char *altPath=strdup(tmps1);
       r_inputs=getMap(s1->content,"ServiceProvider");
       sprintf(tmps1,"%s/%s",altPath,r_inputs->value);
-	  free(altPath);
+      free(altPath);
 #ifdef DEBUG
       fprintf(stderr,"Trying to load %s\n",tmps1);
 #endif
 #ifdef WIN32
-	  HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
+      HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
 #else
       void* so = dlopen(tmps1, RTLD_LAZY);
 #endif
+#ifdef DEBUG
 #ifdef WIN32
       DWORD errstr;
-	  errstr = GetLastError();
-#ifdef DEBUG
-	  fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr);
-#endif
+      errstr = GetLastError();
+      fprintf(stderr,"%s loaded (%d) \n",tmps1,errstr);
 #else
       char *errstr;
-	  errstr = dlerror();
+      errstr = dlerror();
+#endif
 #endif
 
@@ -1342,8 +1470,8 @@
 #ifdef DEBUG
 	dumpMap(r_inputs);
-	fprintf(stderr,"%s %s",r_inputs->value,mtoupper(r_inputs->value));
+	fprintf(stderr,"%s\n",r_inputs->value);
 	fflush(stderr);
 #endif
-	if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){
+	if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
 #ifdef WIN32
 	  //Strange return value needed here !
@@ -1352,5 +1480,5 @@
 	  r_inputs=getMap(request_inputs,"Identifier");
 	  char fname[1024];
-	  sprintf(fname,"%s",r_inputs->value);
+	  sprintf(fname,"%s_",r_inputs->value);
 #ifdef DEBUG
 	  fprintf(stderr,"Try to load function %s\n",fname);
@@ -1371,4 +1499,5 @@
 	  fprintf(stderr,"Function loaded %s\n",errstr);
 #endif	
+
 	  char main_conf[10][30][1024];
 	  char inputs[10][30][1024];
@@ -1390,7 +1519,7 @@
 	  charxxxToMaps((char***)&outputs[0],&request_output_real_format);
 	}else{
+#ifdef DEBUG
 #ifdef WIN32
 	  errstr = GetLastError();
-#ifdef DEBUG
 	  fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr);
 #endif
@@ -1404,9 +1533,6 @@
 	  execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 
 #ifdef DEBUG
-	  /*if(!execute)*/
 	  errstr = GetLastError();
 	  fprintf(stderr,"Function %s failed to load because of %d\n",r_inputs->value,errstr);
-	  /*else
-	  fprintf(stderr,"Function %s loaded\n",r_inputs->value);*/
 #endif
 #else
@@ -1433,5 +1559,4 @@
 #endif
 	}
-
 	dlclose(so);
       } else {
@@ -1440,4 +1565,9 @@
 	 */
 	char tmps[1024];
+#ifdef WIN32
+	DWORD errstr = GetLastError();
+#else
+	char* errstr = dlerror();
+#endif
 	sprintf(tmps,"C Library can't be loaded %s \n",errstr);
 	map* tmps1=createMap("text",tmps);
@@ -1447,36 +1577,36 @@
     }
     else{
-	if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){
-		eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
-      	}
-	else
-
-	#ifdef USE_JAVA
-	if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){
+      if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
+	eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
+      }
+      else
+	
+#ifdef USE_JAVA
+	if(strncasecmp(r_inputs->value,"JAVA",4)==0){
 	  eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	}
 	else
-	#endif
-
-	#ifdef USE_PHP
-	  if(strcmp(mtoupper(r_inputs->value),"PHP")==0){
+#endif
+
+#ifdef USE_PHP
+	  if(strncasecmp(r_inputs->value,"PHP",3)==0){
 	    eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	  }
-	else
-	#endif
-	
-	#ifdef USE_JS
-	    if(strcmp(mtoupper(r_inputs->value),"JS")==0){
+	  else
+#endif
+	  
+#ifdef USE_JS
+	    if(strncasecmp(r_inputs->value,"JS",2)==0){
 	      eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	    }
 	    else
-         #endif
-		{
-	      char tmpv[1024];
-	      sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
-	      map* tmps=createMap("text",tmpv);
-	      printExceptionReportResponse(m,tmps);
-	      return(-1);
-	    }
+#endif
+	      {
+		char tmpv[1024];
+		sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
+		map* tmps=createMap("text",tmpv);
+		printExceptionReportResponse(m,tmps);
+		return(-1);
+	      }
     }
   }
@@ -1487,8 +1617,9 @@
     fprintf(stderr,"\nPID : %d\n",cpid);
 #endif
+
 #ifndef WIN32
-	pid = fork ();
+    pid = fork ();
 #else
-	pid = 0;
+    pid = 0;
 #endif
     if (pid > 0) {
@@ -1506,23 +1637,21 @@
        * process answer to http client.
        */
-      char tmp1[256];
       r_inputs=getMapFromMaps(m,"main","tmpPath");
-      sprintf(tmp1,"%s",r_inputs->value);
-      r_inputs=getMap(s1->content,"ServiceProvider");
-      sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value);
-      sprintf(tmp1,"%s_%d.xml",strdup(tmp1),cpid);
+      map* r_inputs1=getMap(s1->content,"ServiceProvider");
+      char* fbkp=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+16)*sizeof(char));
+      sprintf(fbkp,"%s/%s_%d.xml",r_inputs->value,r_inputs1->value,cpid);
+      char* flog=(char*)malloc((strlen(r_inputs->value)+strlen(r_inputs1->value)+22)*sizeof(char));
+      sprintf(flog,"%s/%s_%d_error.log",r_inputs->value,r_inputs1->value,cpid);
+      fprintf(stderr,"File to use as backup %s\n",fbkp);
 #ifdef DEBUG
       fprintf(stderr,"RUN IN BACKGROUND MODE \n");
       fprintf(stderr,"son pid continue (origin %d) %d ...\n",cpid,getpid());
-      fprintf(stderr,"\nFILE TO STORE DATA %s\n",tmp1);
-#endif
-      freopen(tmp1 , "w+", stdout);
+      fprintf(stderr,"\nFILE TO STORE DATA %s\n",r_inputs->value);
+#endif
+      freopen(fbkp , "w+", stdout);
       fclose(stdin);
-      r_inputs=getMapFromMaps(m,"main","tmpPath");
-      sprintf(tmp1,"%s",r_inputs->value);
-      r_inputs=getMap(s1->content,"ServiceProvider");
-      sprintf(tmp1,"%s/%s",strdup(tmp1),r_inputs->value);
-      sprintf(tmp1,"%s_%d_error.log",strdup(tmp1),cpid);
-      freopen(tmp1,"w+",stderr);
+      freopen(flog,"w+",stderr);
+      free(fbkp);
+      free(flog);
       /**
        * set status to SERVICE_STARTED and flush stdout to ensure full 
@@ -1531,6 +1660,6 @@
        * this way the data will be updated at the end of the process run.
        */
-      printProcessResponse1(m,request_inputs,cpid,
-			    s[0],r_inputs->value,SERVICE_STARTED,
+      printProcessResponse(m,request_inputs,cpid,
+			    s1,r_inputs->value,SERVICE_STARTED,
 			    request_input_real_format,
 			    request_output_real_format);
@@ -1546,9 +1675,16 @@
 #endif
 
-      if(strncmp(mtoupper(r_inputs->value),"C",1)==0){
+      if(strncasecmp(r_inputs->value,"C",1)==0){
+
 	r_inputs=getMap(request_inputs,"metapath");
-	sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
-	r_inputs=getMap(s1->content,"ServiceProvider");
-	sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value);
+	if(r_inputs!=NULL){
+	  sprintf(tmps1,"%s/%s",ntmp,r_inputs->value);
+	  r_inputs=getMap(s1->content,"ServiceProvider");
+	  if(r_inputs!=NULL)
+	    sprintf(tmps1,"%s/%s",strdup(tmps1),r_inputs->value);
+	}else{
+	  sprintf(tmps1,"%s/",ntmp);
+	}
+	  
   
 #ifdef DEBUG
@@ -1556,14 +1692,14 @@
 #endif
 #ifdef WIN32
-	  HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
+	HINSTANCE so = LoadLibraryEx(tmps1,NULL,LOAD_WITH_ALTERED_SEARCH_PATH);
 #else
-      void* so = dlopen(tmps1, RTLD_LAZY);
+	void* so = dlopen(tmps1, RTLD_LAZY);
 #endif
 #ifdef WIN32
-	  DWORD errstr;
-	  errstr = GetLastError();
+	DWORD errstr;
+	errstr = GetLastError();
 #else
-	  char *errstr;
-	  errstr = dlerror();
+	char *errstr;
+	errstr = dlerror();
 #endif
 	if( so != NULL ) {
@@ -1572,5 +1708,5 @@
 	  fprintf(stderr,"r_inputs->value = %s\n",r_inputs->value);
 #endif
-	  if(strcmp(mtoupper(r_inputs->value),"C-FORTRAN")==0){
+	  if(strncasecmp(r_inputs->value,"C-FORTRAN",9)==0){
 	    r_inputs=getMap(request_inputs,"Identifier");
 #ifdef DEBUG
@@ -1584,13 +1720,13 @@
 #endif
 #ifdef WIN32
-	  execute_t execute=(execute_t)GetProcAddress(so,fname); 
+	    execute_t execute=(execute_t)GetProcAddress(so,fname); 
 #else
-	  execute_t execute=(execute_t)dlsym(so,fname);
+	    execute_t execute=(execute_t)dlsym(so,fname);
 #endif
 #ifdef DEBUG
 #ifdef WIN32
-	  errstr = GetLastError();
+	    errstr = GetLastError();
 #else
-	  errstr = dlerror();
+	    errstr = dlerror();
 #endif
 #endif	
@@ -1622,13 +1758,13 @@
 #endif
 #ifdef WIN32
-	  execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 
+	    execute_t execute=(execute_t)GetProcAddress(so,r_inputs->value); 
 #else
-	  execute_t execute=(execute_t)dlsym(so,r_inputs->value);
+	    execute_t execute=(execute_t)dlsym(so,r_inputs->value);
 #endif
 #ifdef DEBUG
 #ifdef WIN32
-	  errstr = GetLastError();
+	    errstr = GetLastError();
 #else
-	  errstr = dlerror();
+	    errstr = dlerror();
 #endif
 	    fprintf(stderr,"Function loaded %s\n",errstr);
@@ -1638,6 +1774,6 @@
 	     */
 	    eres=execute(&m,&request_input_real_format,&request_output_real_format);
-	    dlclose(so);
 	  }
+	  dlclose(so);
 	} else {
 	  /**
@@ -1648,39 +1784,41 @@
 	  map* tmps=createMap("text",tmps1);
 	  printExceptionReportResponse(m,tmps);
+	  freeMap(&tmps);
+	  free(tmps);
 	  exit(1);
 	}
       } else{
-	if(strcmp(mtoupper(r_inputs->value),"PYTHON")==0){
+	if(strncasecmp(r_inputs->value,"PYTHON",6)==0){
 	  eres=zoo_python_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	}
 	else
 
-	#ifdef USE_JAVA
-	  if(strcmp(mtoupper(r_inputs->value),"JAVA")==0){
+#ifdef USE_JAVA
+	  if(strncasecmp(r_inputs->value,"JAVA",4)==0){
 	    eres=zoo_java_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	  }
 	  else
-	#endif
-	
-	#ifdef USE_PHP
-	    if(strcmp(mtoupper(r_inputs->value),"PHP")==0){
+#endif
+	    
+#ifdef USE_PHP
+	    if(strncasecmp(r_inputs->value,"PHP",3)==0){
 	      eres=zoo_php_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	    }
 	    else
-	#endif
-
-	#ifdef USE_JS
-	    if(strcmp(mtoupper(r_inputs->value),"JS")==0){
+#endif
+	      
+#ifdef USE_JS
+	      if(strncasecmp(r_inputs->value,"JS",2)==0){
 		eres=zoo_js_support(&m,request_inputs,s1,&request_input_real_format,&request_output_real_format);
 	      }
-	    else
-	#endif
-	{
-	      char tmpv[1024];
-	      sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
-	      map* tmps=createMap("text",tmpv);
-	      printExceptionReportResponse(m,tmps);
-	      return -1;
-	    }
+	      else
+#endif
+		{
+		  char tmpv[1024];
+		  sprintf(tmpv,"Programming Language (%s) set in ZCFG file is not currently supported by ZOO Kernel.\n",r_inputs->value);
+		  map* tmps=createMap("text",tmpv);
+		  printExceptionReportResponse(m,tmps);
+		  return -1;
+		}
       }
   
@@ -1697,9 +1835,32 @@
 #ifdef DEBUG
   dumpMaps(request_output_real_format);
-#endif
-  outputResponse(s1,request_input_real_format,
-		 request_output_real_format,request_inputs,
-		 cpid,m,eres);
-
+  fprintf(stderr,"Function loaded and returned %d\n",eres);
+  fflush(stderr);
+#endif
+  if(eres!=-1)
+    outputResponse(s1,request_input_real_format,
+		   request_output_real_format,request_inputs,
+		   cpid,m,eres);
+
+  //if(getpid()==cpid){
+  freeService(&s1);
+  free(s1);
+  freeMaps(&m);
+  free(m);
+  freeMaps(&tmpmaps);
+  free(tmpmaps);
+  
+  freeMaps(&request_input_real_format);
+  free(request_input_real_format);
+  
+  //freeMap(&request_inputs);
+  //free(request_inputs);
+    
+  /* The following is requested but get issue using with Python support :/ */
+  freeMaps(&request_output_real_format);
+  free(request_output_real_format);
+  
+  free(REQUEST);
+  free(SERVICE_URL);
 #ifdef DEBUG
   fprintf(stderr,"Processed response \n");
@@ -1707,4 +1868,5 @@
   fflush(stderr);
 #endif
+    //}
 
   return 0;
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BoundaryPy.zcfg	(revision 9)
@@ -0,0 +1,57 @@
+[BoundaryPy]
+ Title = Compute boundary.
+ Abstract = A new geometry object is created and returned containing the boundary of the geometry on which the method is invoked. 
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to conpute boundary
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The geometry created
+   Abstract = The geometry containing the boundary of the geometry on which the method is invoked.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/BufferPy.zcfg	(revision 9)
@@ -0,0 +1,69 @@
+[BufferPy]
+ Title = Create a buffer around a polygon. 
+ Abstract = Create a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature. 
+ Profile = urn:ogc:wps:1.0.0:buffer
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to be buffered
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Default>
+    <Supported>
+     mimeType = aplication/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+  [BufferDistance]
+   Title = Buffer Distance
+   Abstract = Distance to be used to calculate buffer.
+   minOccurs = 0
+   maxOccurs = 1
+   <LiteralData>
+    DataType = float
+    <Default>
+     uom = meters
+     value = 1
+    </Default>
+    <Supported>
+     uom = feet
+    </Supported>
+   </LiteralData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Buffered Polygon
+   Abstract = GML stream describing the buffered polygon feature.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/CentroidPy.zcfg	(revision 9)
@@ -0,0 +1,54 @@
+[CentroidPy]
+ Title = Get the centroid of a polygon. 
+ Abstract = Compute the geometry centroid.
+ Profile = urn:ogc:wps:1.0.0:centroid
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to get the centroid
+   Abstract = The centroid which is not necessarily within the geometry.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The Centroid
+   Abstract = JSON String / GML Entity of the centroid
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/point.xsd
+     asReference = true	
+    </Supported>
+   </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ConvexHullPy.zcfg	(revision 9)
@@ -0,0 +1,51 @@
+[ConvexHullPy]
+ Title = Compute convex hull.
+ Abstract = A new geometry object is created and returned containing the convex hull of the geometry on which the method is invoked.
+ processVersion = 1
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData lang="en">
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputPolygon]
+   Title = Polygon to compute convexhull
+   Abstract = URI to a set of GML that describes the polygon.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+   title = Mon test
+   </MetaData>
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The convex hull of the geometry
+   Abstract = The convex hull of the geometry
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = application/json
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataOutputs> 
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/DifferencePy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[DifferencePy]
+ Title = Compute difference. . 
+ Abstract = Generates a new geometry which is the region of this geometry with the region of the other geometry removed.
+ Profile = urn:ogc:wps:1.0.0:difference
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The difference between two geometries
+   Abstract = The difference between the two geometries.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/IntersectionPy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[IntersectionPy]
+ Title = Compute intersection. 
+ Abstract = Generates a new geometry which is the region of intersection of the two geometries operated on.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = Intersection of the two geometries
+   Abstract = A new geometry representing the intersection or NULL if there is no intersection or an error occurs.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/SymDifferencePy.zcfg	(revision 9)
@@ -0,0 +1,75 @@
+[SymDifferencePy]
+ Title = Compute symmetric difference. 
+ Abstract = Generates a new geometry which is the symmetric difference of this geometry and the other geometry.
+ Profile = urn:ogc:wps:1.0.0:symmetricdifference
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = text/xml
+     encoding = base64
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The symmetric difference between two geometries
+   Abstract = The symmetric difference between the two geometries.
+   <MetaData lang="en">
+    Title = Symmetric Difference  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/UnionPy.zcfg	(revision 9)
@@ -0,0 +1,73 @@
+[UnionPy]
+ Title = Compute union. 
+ Abstract = Generates a new geometry which is the region of union of the two geometries operated on.
+ Profile = urn:ogc:wps:1.0.0:union
+ processVersion = 2
+ storeSupported = true
+ statusSupported = true
+ serviceProvider = ogr_sp
+ serviceType = Python
+ <MetaData>
+   title = Demo
+ </MetaData>
+ <DataInputs>
+  [InputEntity1]
+   Title = the first geometry 
+   Abstract = the first geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+  [InputEntity2]
+   Title = the other geometry
+   Abstract = the other geometry to compare against.
+   minOccurs = 1
+   maxOccurs = 1
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+   <ComplexData>
+    <Default>
+     mimeType = text/xml
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     encoding = UTF-8
+    </Default>
+    <Supported>
+     mimeType = application/json
+     encoding = UTF-8
+    </Supported>
+   </ComplexData>
+ </DataInputs>
+ <DataOutputs>
+  [Result]
+   Title = The union of two geometries
+   Abstract = The geometry representing the union of the two geometries.
+   <MetaData lang="en">
+    title = Mon test  
+   </MetaData>   
+    <ComplexData>
+     <Default>
+       mimeType = application/json
+       encoding = UTF-8
+       extension = js
+     </Default>
+     <Supported>
+      mimeType = text/xml
+      schema = http://fooa/gml/3.1.0/polygon.xsd
+      encoding = UTF-8
+      extension = xml
+     </Supported>
+    </ComplexData>
+ </DataOutputs>  
Index: trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 9)
+++ trunk/zoo-services/ogr/base-vect-ops-py/cgi-env/ogr_sp.py	(revision 9)
@@ -0,0 +1,95 @@
+import osgeo.ogr
+import libxml2
+
+def createGeometryFromWFS(my_wfs_response):
+    doc=libxml2.parseMemory(my_wfs_response,len(my_wfs_response))
+    ctxt = doc.xpathNewContext()
+    res=ctxt.xpathEval("/*/*/*/*/*[local-name()='Polygon' or local-name()='MultiPolygon']")
+    for node in res:
+        geometry_as_string=node.serialize()
+        geometry=osgeo.ogr.CreateGeometryFromGML(geometry_as_string)
+	return geometry
+    return geometry
+
+def extractInputs(obj):
+    if obj["mimeType"]=="application/json":
+	return osgeo.ogr.CreateGeometryFromJson(obj["value"])
+    else:
+	try:
+        	return createGeometryFromWFS(obj["value"])
+	except:
+		return osgeo.ogr.CreateGeometryFromJson(obj["value"])
+    return null
+    
+def outputResult(obj,geom):
+    if obj["mimeType"]=="application/json":
+        obj["value"]=geom.ExportToJson()
+        obj["mimeType"]="text/plain"
+    else:
+        obj["value"]=geom.ExportToGML()
+
+def BoundaryPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    rgeom=geometry.GetBoundary()
+    if outputs["Result"]["mimeType"]=="application/json":
+        outputs["Result"]["value"]=rgeom.ExportToJson()
+        outputs["Result"]["mimeType"]="text/plain"
+    else:
+        outputs["Result"]["value"]=rgeom.ExportToGML()
+    return 3
+
+def CentroidPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    if geometry.GetGeometryType()!=3:
+        geometry=geometry.ConvexHull()
+    rgeom=geometry.Centroid()
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def ConvexHullPy(conf,inputs,outputs):
+    geometry=extractInputs(inputs["InputPolygon"])
+    rgeom=geometry.ConvexHull()
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def BufferPy(conf,inputs,outputs):
+    geometry=createGeometryFromWFS(inputs["InputPolygon"]["value"])
+    try:
+        bdist=int(inputs["BufferDistance"]["value"])
+    except:
+        bdist=10
+    rgeom=geometry.Buffer(bdist)
+    if outputs["Result"]["mimeType"]=="application/json":
+        outputs["Result"]["value"]=rgeom.ExportToJson()
+        outputs["Result"]["mimeType"]="text/plain"
+    else:
+        outputs["Result"]["value"]=rgeom.ExportToGML()
+    return 3
+
+def UnionPy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Union(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def IntersectionPy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Intersection(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def DifferencePy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.Difference(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
+
+def SymDifferencePy(conf,inputs,outputs):
+    geometry1=extractInputs(inputs["InputEntity1"])
+    geometry2=extractInputs(inputs["InputEntity2"])
+    rgeom=geometry1.SymmetricDifference(geometry2)
+    outputResult(outputs["Result"],rgeom)
+    return 3
Index: trunk/zoo-services/ogr/base-vect-ops/Makefile
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/Makefile	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/Makefile	(revision 9)
@@ -1,7 +1,7 @@
-CFLAGS=-I../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags`  `gdal-config --cflags`   -DLINUX_FREE_ISSUE #-DDEBUG
+CFLAGS=-I../../../zoo-kernel/ -I./ `xml2-config --cflags` `python-config --cflags`  `gdal-config --cflags`   -DLINUX_FREE_ISSUE #-DDEBUG
 CC=gcc
 
 cgi-env/service.zo: service.c
-	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c `gdal-config --libs`
+	g++ ${CFLAGS} -shared -fpic -o cgi-env/ogr_service.zo ./service.c ../../../zoo-kernel/service_internal.o `gdal-config --libs`
 
 clean:
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Boundary.zcfg	(revision 9)
@@ -8,19 +8,20 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to be buffered
+   Title = Polygon to compute boundary
    Abstract = URI to a set of GML that describes the polygon.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/js
+     mimeType = text/xml
      encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
     </Default>
     <Supported>
@@ -30,41 +31,30 @@
     </Supported>
    </ComplexData>
-  [BufferDistance]
-   Title = Buffer Distance
-   Abstract = Distance to be used to calculate buffer.
-   minOccurs = 0
-   maxOccurs = 1
-   <LiteralData>
-    DataType = float
-    <Default>
-     uom = meters
-    </Default>
-    <Supported>
-     uom = feet
-    </Supported>
-   </LiteralData>
  </DataInputs>
  <DataOutputs>
-  [Boundary]
+  [Result]
    Title = The geometry created
    Abstract = The geometry containing the boundary of the geometry on which the method is invoked.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/xml
+     mimeType = application/json
      encoding = UTF-8
-     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = js
      asReference = true	
     </Default>
     <Supported>
      mimeType = text/xml
+     encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
+    </Supported>
+    <Supported>
+     mimeType = text/xml
      encoding = base64
      schema = http://fooa/gml/3.1.0/polygon.xsd
-    </Supported>
-    <Supported>
-     mimeType = text/js
-     encoding = UTF-8
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Buffer.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -49,15 +49,15 @@
  </DataInputs>
  <DataOutputs>
-  [BufferedPolygon]
+  [Result]
    Title = Buffered Polygon
    Abstract = GML stream describing the buffered polygon feature.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/xml
+     mimeType = application/json
      encoding = UTF-8
-     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = js
      asReference = true	
     </Default>
@@ -66,8 +66,11 @@
      encoding = base64
      schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
     </Supported>
     <Supported>
-     mimeType = application/json
+     mimeType = text/xml
      encoding = UTF-8
+     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Centroid.zcfg	(revision 9)
@@ -1,5 +1,5 @@
 [Centroid]
  Title = Get the centroid of a polygon. 
- Abstract = Create a buffer around a single polygon. Accepts the polygon as GML and provides GML output for the buffered feature. 
+ Abstract = Compute the geometry centroid.
  Profile = urn:ogc:wps:1.0.0:centroid
  processVersion = 2
@@ -9,14 +9,14 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to be buffered
-   Abstract = URI to a set of GML that describes the polygon.
+   Title = Polygon to get the centroid
+   Abstract = The centroid which is not necessarily within the geometry.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -34,25 +34,22 @@
  </DataInputs>
  <DataOutputs>
-  [Centroid]
+  [Result]
    Title = The Centroid
    Abstract = JSON String / GML Entity of the centroid
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
-     mimeType = text/js
+     mimeType = application/json
      encoding = UTF-8
+     extension = js
+     asReference = true	
     </Default>
-    <Supported>
-     mimeType = text/xml
-     encoding = base64
-     schema = http://fooa/gml/3.1.0/point.xsd
-    </Supported>
     <Supported>
      mimeType = text/xml
      encoding = UTF-8
      schema = http://fooa/gml/3.1.0/point.xsd
-     asReference = true	
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/ConvexHull.zcfg	(revision 9)
@@ -8,14 +8,14 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
   [InputPolygon]
-   Title = Polygon to compute are
+   Title = Polygon to compute convexhull
    Abstract = URI to a set of GML that describes the polygon.
    minOccurs = 1
    maxOccurs = 1
    <MetaData lang="en">
-   Test1 = Mon test
+   title = Mon test
    </MetaData>
    <ComplexData>
@@ -37,16 +37,18 @@
    Abstract = The convex hull of the geometry
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
     <Default>
+     mimeType = application/json
+     encoding = UTF-8
+     extension = js
+     asReference = true	
+    </Default>
+    <Supported>
      mimeType = text/xml
      encoding = UTF-8
      schema = http://fooa/gml/3.1.0/polygon.xsd
-    </Default>
-    <Supported>
-     mimeType = text/xml
-     encoding = base64
-     schema = http://fooa/gml/3.1.0/polygon.xsd
+     extension = xml
     </Supported>
    </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Difference.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The difference between two geometries
+   Abstract = The difference between the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Distance.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -58,5 +58,5 @@
    Abstract = The shortest distance between the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <LiteralData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/GetArea.zcfg	(revision 9)
@@ -8,5 +8,5 @@
  serviceType = C
  <MetaData lang="en">
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -17,5 +17,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-   Test1 = Mon test
+   title = Mon test
    </MetaData>
    <ComplexData>
@@ -37,5 +37,5 @@
    Abstract = The Computed Area Value
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
    <LiteralData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Intersection.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = Intersection of geometries
+   Abstract = A new geometry representing the intersection or NULL if there is no intersection or an error occurs.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/SymDifference.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The resulting geometry
+   Abstract = The symmetric difference of two geometries
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/cgi-env/Union.zcfg	(revision 9)
@@ -9,5 +9,5 @@
  serviceType = C
  <MetaData>
-   Test = Demo
+   title = Demo
  </MetaData>
  <DataInputs>
@@ -18,5 +18,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -38,5 +38,5 @@
    maxOccurs = 1
    <MetaData lang="en">
-    Test = Mon test  
+    title = Mon test  
    </MetaData>   
    <ComplexData>
@@ -54,9 +54,9 @@
  </DataInputs>
  <DataOutputs>
-  [Distance]
-   Title = The distance between two geometries
-   Abstract = The shortest distance between the two geometries.
+  [Result]
+   Title = The union of two geometries
+   Abstract = The geometry representing the union of the two geometries.
    <MetaData lang="en">
-    Test1 = Mon test  
+    title = Mon test  
    </MetaData>   
     <ComplexData>
@@ -64,4 +64,5 @@
        mimeType = application/json
        encoding = UTF-8
+       extension = js
      </Default>
      <Supported>
@@ -69,4 +70,5 @@
       schema = http://fooa/gml/3.1.0/polygon.xsd
       encoding = UTF-8
+      extension = xml
      </Supported>
     </ComplexData>
Index: trunk/zoo-services/ogr/base-vect-ops/service.c
===================================================================
--- trunk/zoo-services/ogr/base-vect-ops/service.c	(revision 8)
+++ trunk/zoo-services/ogr/base-vect-ops/service.c	(revision 9)
@@ -23,6 +23,8 @@
  */
 
-#include "cpl_minixml.h"
+#include "cpl_conv.h"
 #include "ogr_api.h"
+#include "ogr_geometry.h"
+#include "geos_c.h"
 #include "service.h"
 
@@ -39,5 +41,4 @@
 #include <openssl/buffer.h>
 
-  xmlNodeSet* extractFromDoc(xmlDocPtr,char*);
   void printExceptionReportResponse(maps*,map*);
   char *base64(const unsigned char *input, int length);
@@ -71,9 +72,12 @@
     }
     xmlDocDumpFormatMemory(ndoc, &xmlbuff, &buffersize, 1);
-    char *tmp=strdup(strstr((char*)xmlbuff,"?>")+2);
+    char *tmp=(char*)calloc((xmlStrlen(xmlStrstr(xmlbuff,BAD_CAST "?>"))-1),sizeof(char));
+    sprintf(tmp,"%s",xmlStrstr(xmlbuff,BAD_CAST "?>")+2);
+    //strdup(strstr((char*)xmlbuff,"?>")+2);
     xmlXPathFreeObject(xpathObj);
-    xmlXPathFreeContext(xpathCtx); 
+    xmlXPathFreeContext(xpathCtx);
     xmlFree(xmlbuff);
     xmlFreeDoc(doc);
+    xmlFreeDoc(ndoc);
     xmlCleanupParser();
 #ifdef DEBUG
@@ -81,12 +85,301 @@
 #endif
     OGRGeometryH res=OGR_G_CreateFromGML(tmp);
+    free(tmp);
     if(res==NULL){
-    	map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
-	addToMap(tmp,"code","NoApplicableCode");
-	printExceptionReportResponse(conf,tmp);
-	exit(0);
+      map* tmp=createMap("text","Unable to call OGR_G_CreatFromGML");
+      addToMap(tmp,"code","NoApplicableCode");
+      printExceptionReportResponse(conf,tmp);
+      exit(0);
     }
     else
-    	return OGR_G_CreateFromGML(tmp);
+      return res;//OGR_G_CreateFromGML(tmp);
+  }
+
+  int Simplify(maps*& conf,maps*& inputs,maps*& outputs){
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    double tolerance;
+    map* tmp0=getMapFromMaps(cursor,"Tolerance","value");
+    if(tmp0==NULL){
+      tolerance=atof("2.0");
+    }
+    else
+      tolerance=atof(tmp0->value);
+    fprintf(stderr,"Tolerance for Simplify %f",tolerance);
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp)
+      return SERVICE_FAILED;
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
+    if(tmp1!=NULL){
+      if(strncmp(tmp1->value,"text/js",7)==0 ||
+	 strncmp(tmp1->value,"application/json",7)==0)
+        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
+      else
+        geometry=createGeometryFromGML(conf,tmp->value);
+    }
+    else
+      geometry=createGeometryFromGML(conf,tmp->value);
+    GEOSGeometry* ggeometry=((OGRGeometry *) geometry)->exportToGEOS();
+    GEOSGeometry* gres=GEOSTopologyPreserveSimplify(ggeometry,tolerance);
+    res=OGRGeometryFactory::createFromGEOS(gres);
+    if(tmp1!=NULL){
+      if(strncmp(tmp1->value,"text/js",7)==0 ||
+	 strncmp(tmp1->value,"application/json",16)==0){
+        outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
+	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
+	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+      }
+      else{
+        outputs->content=createMap("value",OGR_G_ExportToGML(res));
+	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
+	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+	addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
+      }
+    }else{
+      outputs->content=createMap("value",OGR_G_ExportToJson(res));
+      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
+      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+    }
+    outputs->next=NULL;
+    //GEOSFree(ggeometry);
+    //GEOSFree(gres);
+    OGR_G_DestroyGeometry(res);
+    OGR_G_DestroyGeometry(geometry);
+    return SERVICE_SUCCEEDED;
+  }
+
+
+  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
+#ifdef DEBUG
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+#ifdef DEBUG
+    dumpMaps(cursor);
+#endif
+    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+    if(!tmp)
+      return SERVICE_FAILED;
+    fprintf(stderr,"Service internal print \n");
+    dumpMaps(inputs);
+    fprintf(stderr,"/Service internal print \n");
+    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+    fprintf(stderr,"Service internal print \n");
+    dumpMap(tmp1);
+    fprintf(stderr,"/Service internal print \n");
+    if(tmp1!=NULL){
+      if(strncmp(tmp1->value,"text/js",7)==0 ||
+	 strncmp(tmp1->value,"application/json",7)==0)
+        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
+      else
+        geometry=createGeometryFromGML(conf,tmp->value);
+    }
+    else
+      geometry=createGeometryFromGML(conf,tmp->value);
+    res=(*myFunc)(geometry);
+    fprintf(stderr,"Service internal print \n");
+    dumpMaps(outputs);
+    fprintf(stderr,"/Service internal print \n");
+    map *tmp_2=getMapFromMaps(outputs,"Result","mimeType");
+    fprintf(stderr,"Service internal print \n");
+    dumpMap(tmp_2);
+    fprintf(stderr,"/Service internal print \n");
+    if(tmp_2!=NULL){
+      if(strncmp(tmp_2->value,"text/js",7)==0 ||
+	 strncmp(tmp_2->value,"application/json",16)==0){
+	char *tres=OGR_G_ExportToJson(res);
+        addToMap(outputs->content,"value",tres);
+	free(tres);
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+      }
+      else{
+	char *tres=OGR_G_ExportToGML(res);
+        addToMap(outputs->content,"value",tres);
+	free(tres);
+      }
+    }else{
+      char *tres=OGR_G_ExportToJson(res);
+      addToMap(outputs->content,"value",tres);
+      free(tres);
+      addToMap(outputs->content,"mimeType","text/plain");
+      addToMap(outputs->content,"encoding","UTF-8");
+    }
+    outputs->next=NULL;
+#ifdef DEBUG
+    dumpMaps(outputs);
+    fprintf(stderr,"\nService internal print\n===\n");
+#endif
+    OGR_G_DestroyGeometry(res);
+    OGR_G_DestroyGeometry(geometry);
+    //CPLFree(res);
+    //CPLFree(geometry);
+    fprintf(stderr,"Service internal print \n");
+    dumpMaps(outputs);
+    fprintf(stderr,"/Service internal print \n");
+    return SERVICE_SUCCEEDED;
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
+   OGRGeometryH geometry,res;
+   map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+   if(tmp==NULL)
+     return SERVICE_FAILED;
+   map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+   if(strncmp(tmp1->value,"application/json",16)==0)
+     geometry=OGR_G_CreateGeometryFromJson(tmp->value);
+   else
+     geometry=createGeometryFromGML(conf,tmp->value);
+   int bufferDistance=1;
+   tmp=getMapFromMaps(inputs,"BufferDistance","value");
+   if(tmp!=NULL)
+		bufferDistance=atoi(tmp->value);
+   res=OGR_G_Buffer(geometry,bufferDistance,30);
+   tmp1=getMapFromMaps(outputs,"Result","mimeType");
+   if(strncmp(tmp1->value,"application/json",16)==0){
+		addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+		addToMap(outputs->content,"mimeType","text/plain");
+   }
+   else{
+		addToMap(outputs->content,"value",OGR_G_ExportToGML(res));
+   }
+   outputs->next=NULL;
+   OGR_G_DestroyGeometry(geometry);
+   OGR_G_DestroyGeometry(res);
+   return SERVICE_SUCCEEDED;
+}
+
+/*  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
+#ifdef DEBUG
+    fprintf(stderr,"\nService internal print\n");
+#endif
+    maps* cursor=inputs;
+    OGRGeometryH geometry,res;
+    int bufferDistance;    
+    if(cursor!=NULL){
+#ifdef DEBUG
+      fprintf(stderr,"\nService internal print\n");
+      dumpMaps(cursor);
+      fprintf(stderr,"\nService internal print\n");
+      dumpMaps(inputs);
+      fprintf(stderr,"\nService internal print\n");
+#endif
+      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
+      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
+      if(tmp1!=NULL){
+        if(strncmp(tmp1->value,"application/json",16)==0 ||
+	   strncmp(tmp1->value,"text/js",7)==0)
+      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
+	else
+	  geometry=createGeometryFromGML(conf,tmp->value);
+      }
+      else
+      	geometry=createGeometryFromGML(conf,tmp->value);
+    }
+    if(cursor!=NULL){
+      map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
+      if(tmp==NULL){
+	bufferDistance=10;
+      }
+      else
+	bufferDistance=atoi(tmp->value);
+#ifdef DEBUG
+      fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
+#endif
+    }
+#ifdef DEBUG
+    dumpMaps(outputs);
+#endif
+    map* tmp=getMapFromMaps(outputs,"Result","mimeType");
+    res=OGR_G_Buffer(geometry,bufferDistance,30);
+#ifdef DEBUG
+    dumpMap(tmp);
+#endif
+    if(tmp!=NULL){
+#ifdef DEBUG
+      dumpMap(tmp);
+#endif
+      if(strncmp(tmp->value,"application/json",16)==0){
+	addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+      }
+      else if(strcmp(tmp->value,"text/xml")==0){
+	xmlInitParser();
+	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
+	xmlChar *xmlbuff;
+	int buffersize;
+	char *buff=OGR_G_ExportToGML(res);
+	addToMap(outputs->content,"value",buff);
+	map* tmp1=getMapFromMaps(outputs,"Result","encoding");
+	if(tmp1!=NULL)
+	  addToMap(outputs->content,"encoding",tmp1->value);
+	else
+	  addToMap(outputs->content,"encoding","UTF-8");
+	xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
+	xmlFree(xmlbuff);
+	xmlFreeDoc(doc);
+	xmlCleanupParser();
+      }
+      else{
+	addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+	addToMap(outputs->content,"mimeType","text/plain");
+	addToMap(outputs->content,"encoding","UTF-8");
+	outputs->next=NULL;
+      }
+      outputs->next=NULL;
+    }
+    else{
+      addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+      addToMap(outputs->content,"mimeType","text/plain");
+      addToMap(outputs->content,"encoding","UTF-8");
+      outputs->next=NULL;
+    }
+    outputs->next=NULL;
+#ifdef DEBUG
+    dumpMaps(outputs);
+    fprintf(stderr,"\nService internal print\n===\n");
+#endif
+    OGR_G_DestroyGeometry(geometry);
+    OGR_G_DestroyGeometry(res);
+    return SERVICE_SUCCEEDED;
+  }
+*/
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&OGR_G_GetBoundary);
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
+  }
+
+
+  OGRGeometryH MY_OGR_G_Centroid(OGRGeometryH hTarget){
+    OGRGeometryH res;
+    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
+    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(hTarget);
+    if(gtype!=wkbPolygon){
+      hTarget=OGR_G_ConvexHull(hTarget);
+    }
+    int c=OGR_G_Centroid(hTarget,res);
+    return res;
+  }
+
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
+  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
+    return applyOne(conf,inputs,outputs,&MY_OGR_G_Centroid);
   }
 
@@ -130,15 +423,14 @@
     }
     res=(*myFunc)(geometry1,geometry2);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    char tmpres[100];
-    sprintf(tmpres,"%d",res);
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
+    addToMap(outputs->content,"value",OGR_G_ExportToJson(res));
+    addToMap(outputs->content,"mimeType","text/plain");
+    addToMap(outputs->content,"encoding","UTF-8");
     outputs->next=NULL;
+    OGR_G_DestroyGeometry(geometry1);
+    OGR_G_DestroyGeometry(geometry2);
+    OGR_G_DestroyGeometry(res);
     return SERVICE_SUCCEEDED;
   }
-
+  
 #ifdef WIN32
   __declspec(dllexport)
@@ -162,366 +454,9 @@
   }
 
-  int applyOne(maps*& conf,maps*& inputs,maps*& outputs,OGRGeometryH (*myFunc)(OGRGeometryH)){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;
-#ifdef DEBUG
-    dumpMaps(cursor);
-#endif
-    map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-    if(!tmp)
-      return SERVICE_FAILED;
-    map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeTime");
-    if(tmp1!=NULL){
-      if(strncmp(tmp1->value,"text/js",7)==0)
-        geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-      else
-        geometry=createGeometryFromGML(conf,tmp->value);
-      }
-    else
-      geometry=createGeometryFromGML(conf,tmp->value);
-    res=(*myFunc)(geometry);
-    /**
-     * Here we should check what is the requested output.
-     * Let's use JSON per default.
-     */
-    //outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    if(tmp1!=NULL){
-      if(strncmp(tmp1->value,"text/js",7)==0){
-        outputs->content=createMap("value",OGR_G_ExportToJson(tmp->value));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else{
-        outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
-      }
-    }else{
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int ConvexHull(maps*& conf,maps*& inputs,maps*& outputs){
-    return applyOne(conf,inputs,outputs,&OGR_G_ConvexHull);
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Boundary(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\nStarting\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;
-    xmlInitParser();
-    
-    if(cursor!=NULL){
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"text/js",7)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }
-    res=OGR_G_GetBoundary(geometry);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Boundary";
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    /*
-    outputs->content=createMap("value",OGR_G_ExportToGML(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    addMapToMap(&outputs->content,createMap("schema","http://fooa/gml/3.1.0/polygon.xsd"));
-    */
-    outputs->next=NULL;
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    xmlCleanupParser();
-    return SERVICE_SUCCEEDED;
-    }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Centroid(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res=NULL;
-    int bufferDistance;    
-    if(cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(cursor);
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(inputs);
-      fprintf(stderr,"\nService internal print\n");
-#endif
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }else{
-    /**
-     * Print WPSExceptionError message here !!
-     */
-    }
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    res=OGR_G_CreateGeometryFromJson("{\"type\": \"Point\", \"coordinates\": [0,0] }");
-    OGRwkbGeometryType gtype=OGR_G_GetGeometryType(geometry);
-    if(gtype!=wkbPolygon){
-    	fprintf(stderr,"\n\nGeometry Type is not Polygon, let us use the ConvexHull !\n\n");
-    	geometry=OGR_G_ConvexHull(OGR_G_Clone(geometry));
-    }else{
-    	fprintf(stderr,"\n\nGeometry Type is Polygon, thanks !\n\n");
-    }
-    int c=OGR_G_Centroid(geometry,res);
-#ifdef DEBUG
-    fprintf(stderr,"\n\nC VALUE : %d\n\n",c);
-#endif
-    map* tmp=getMapFromMaps(outputs,"Result","mimeType");
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    if(tmp!=NULL){
-#ifdef DEBUG
-      dumpMap(tmp);
-#endif
-      if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
-	outputs->content=createMap("value",OGR_G_ExportToJson(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else if(strncmp(mtoupper(tmp->value),mtoupper("text/xml"),8)==0){
-	/*xmlInitParser();
-	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
-	xmlChar *xmlbuff;
-	int buffersize;*/
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	map* tmp1=getMapFromMaps(outputs,"Result","encoding");
-	if(tmp1!=NULL)
-	  addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
-	else
-	  addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	/*xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	xmlFree(xmlbuff);
-	xmlFreeDoc(doc);
-	xmlCleanupParser();
-	*/
-      }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="Result";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-    }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="Result";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
-#ifdef WIN32
-  __declspec(dllexport)
-#endif
-  int Buffer(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print\n");
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry,res;
-    int bufferDistance;    
-    if(cursor!=NULL){
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(cursor);
-      fprintf(stderr,"\nService internal print\n");
-      dumpMaps(inputs);
-      fprintf(stderr,"\nService internal print\n");
-#endif
-      map* tmp=getMapFromMaps(inputs,"InputPolygon","value");
-      map* tmp1=getMapFromMaps(inputs,"InputPolygon","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry=createGeometryFromGML(conf,tmp->value);
-    }
-    if(cursor!=NULL){
-      map* tmp=getMapFromMaps(cursor,"BufferDistance","value");
-      if(tmp==NULL){
-	bufferDistance=10;
-      }
-      else
-	bufferDistance=atoi(tmp->value);
-#ifdef DEBUG
-      fprintf(stderr,"\nService internal print (BufferDistance value: %i)\n",bufferDistance);
-#endif
-    }
-#ifdef DEBUG
-    dumpMaps(outputs);
-#endif
-    map* tmp=getMapFromMaps(outputs,"BufferedPolygon","mimeType");
-    res=OGR_G_Buffer(geometry,bufferDistance,30);
-#ifdef DEBUG
-    dumpMap(tmp);
-#endif
-    if(tmp!=NULL){
-#ifdef DEBUG
-      dumpMap(tmp);
-#endif
-      if(strncmp(mtoupper(tmp->value),mtoupper("application/json"),16)==0){
-	outputs->content=createMap("value",OGR_G_ExportToJson(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-	addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      }
-      else if(strcmp(mtoupper(tmp->value),mtoupper("text/xml"))==0){
-	xmlInitParser();
-	xmlDocPtr doc = xmlParseMemory(tmp->value,strlen(tmp->value));
-	xmlChar *xmlbuff;
-	int buffersize;
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	addMapToMap(&outputs->content,createMap("mimeType","text/xml"));
-	map* tmp1=getMapFromMaps(outputs,"BufferedPolygon","encoding");
-	if(tmp1!=NULL)
-	  addMapToMap(&outputs->content,createMap("encoding",tmp1->value));
-	else
-	  addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-	xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1);
-	outputs->content=createMap("value",OGR_G_ExportToGML(res));
-	xmlFree(xmlbuff);
-	xmlFreeDoc(doc);
-	xmlCleanupParser();
-      }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="BufferedPolygon";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-    }
-    else{
-      outputs=(maps*)malloc(sizeof(maps*));
-      outputs->name="BufferedPolygon";
-      outputs->content=createMap("value",OGR_G_ExportToJson(res));
-      addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-      addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-      outputs->next=NULL;
-    }
-    outputs->next=NULL;
-#ifdef DEBUG
-    dumpMaps(outputs);
-    fprintf(stderr,"\nService internal print\n===\n");
-#endif
-    return SERVICE_SUCCEEDED;
-  }
-
 #ifdef WIN32
   __declspec(dllexport)
 #endif
   int Union(maps*& conf,maps*& inputs,maps*& outputs){
-#ifdef DEBUG
-    fprintf(stderr,"\nService internal print1\n");
-    fflush(stderr);
-#endif
-    maps* cursor=inputs;
-    OGRGeometryH geometry1,geometry2;
-    OGRGeometryH res;
-    {
-      map* tmp=getMapFromMaps(inputs,"InputEntity1","value");
-      map* tmp1=getMapFromMaps(inputs,"InputEntity1","mimeType");
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry1=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry1=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry1=createGeometryFromGML(conf,tmp->value);
-    }
-    {
-      map* tmp=getMapFromMaps(inputs,"InputEntity2","value");
-      map* tmp1=getMapFromMaps(inputs,"InputEntity2","mimeType");
-#ifdef DEBUG
-      fprintf(stderr,"MY MAP\n");
-      dumpMap(tmp1);
-      fprintf(stderr,"MY MAP\n");
-#endif
-      if(tmp1!=NULL){
-        if(strncmp(tmp1->value,"application/json",16)==0)
-      	  geometry2=OGR_G_CreateGeometryFromJson(tmp->value);
-	else
-	  geometry2=createGeometryFromGML(conf,tmp->value);
-      }
-      else
-      	geometry2=createGeometryFromGML(conf,tmp->value);
-    }
-    res=OGR_G_Union(geometry1,geometry2);
-    outputs=(maps*)malloc(sizeof(maps*));
-    outputs->name="Result";
-    char tmpres[100];
-    sprintf(tmpres,"%d",res);
-    outputs->content=createMap("value",OGR_G_ExportToJson(res));
-    addMapToMap(&outputs->content,createMap("mimeType","text/plain"));
-    addMapToMap(&outputs->content,createMap("encoding","UTF-8"));
-    outputs->next=NULL;
-    return SERVICE_SUCCEEDED;
+    return applyTwo(conf,inputs,outputs,&OGR_G_Union);
   }
 
@@ -589,4 +524,7 @@
   }
 
+#ifdef WIN32
+  __declspec(dllexport)
+#endif
   int GetArea(maps*& conf,maps*& inputs,maps*& outputs){
     fprintf(stderr,"GETAREA \n");
