Index: trunk/zoo-project/HISTORY.txt
===================================================================
--- trunk/zoo-project/HISTORY.txt	(revision 653)
+++ trunk/zoo-project/HISTORY.txt	(revision 654)
@@ -1,3 +1,4 @@
 Version 1.5.0-dev
+  * Initial support for WPS 2.0.0 including the Dismiss extension
   * Fix concurrency access to status informations
   * Use simple file rather than shared memory for storing status informations
Index: trunk/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- trunk/zoo-project/zoo-kernel/request_parser.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/request_parser.c	(revision 654)
@@ -496,4 +496,6 @@
   int k = 0;
   int l = 0;
+  map* version=getMapFromMaps(*main_conf,"main","rversion");
+  int vid=getVersionId(version->value);
   for (k=0; k < nodes->nodeNr; k++)
     {
@@ -504,4 +506,12 @@
 	{
 	  // A specific Input node.
+	  if(vid==1){
+	    tmpmaps = (maps *) malloc (MAPS_SIZE);
+	    xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
+	    tmpmaps->name = zStrdup ((char *) val);
+	    tmpmaps->content = NULL;
+	    tmpmaps->next = NULL;
+	  }
+
 	  xmlNodePtr cur2 = cur->children;
 	  while (cur2 != NULL)
@@ -805,4 +815,40 @@
 		{
 		  xmlNodePtr cur4 = cur2->children;
+		  if(vid==1){
+		    // Get every dataEncodingAttributes from a Data node:
+		    // mimeType, encoding, schema
+		    const char *coms[3] =
+		      { "mimeType", "encoding", "schema" };
+		    for (l = 0; l < 3; l++){
+		      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);
+			}
+			xmlFree (val);
+		    }
+		    while (cur4 != NULL){
+		      while(cur4 != NULL && 
+			    cur4->type != XML_CDATA_SECTION_NODE &&
+			    cur4->type != XML_TEXT_NODE)
+			cur4=cur4->next;
+		      if(cur4!=NULL){
+			if(cur4->content!=NULL)
+			  if (tmpmaps->content != NULL)
+			    addToMap (tmpmaps->content, "value",
+				      (char *) cur4->content);
+			  else
+			    tmpmaps->content =
+			      createMap ("value", (char *) cur4->content);
+			cur4=cur4->next;
+		      }
+		    }
+		  }
+
+
 		  while (cur4 != NULL)
 		    {
@@ -897,6 +943,5 @@
 			      while (cur5 != NULL
 				     && cur5->type != XML_ELEMENT_NODE
-				     && cur5->type !=
-				     XML_CDATA_SECTION_NODE)
+				     && cur5->type != XML_CDATA_SECTION_NODE)
 				cur5 = cur5->next;
 			      if (cur5 != NULL
@@ -995,4 +1040,55 @@
 
 /**
+ * Parse outputs from XML nodes and store them in a maps (WPS version 2.0.0).
+ *
+ * @param main_conf the conf maps containing the main.cfg settings
+ * @param request_inputs the map storing KVP raw value 
+ * @param request_output the maps to store the KVP pairs 
+ * @param doc the xmlDocPtr containing the original request
+ * @param cur the xmlNodePtr corresponding to the ResponseDocument or RawDataOutput XML node
+ * @param raw true if the node is RawDataOutput, false in case of ResponseDocument
+ * @return 0 on success, -1 on failure
+ */
+int xmlParseOutputs2(maps** main_conf,map** request_inputs,maps** request_output,xmlDocPtr doc,xmlNodeSet* nodes){
+  int k = 0;
+  int l = 0;
+  for (k=0; k < nodes->nodeNr; k++){
+    maps *tmpmaps = NULL;
+    xmlNodePtr cur = nodes->nodeTab[k];
+    if (cur->type == XML_ELEMENT_NODE){
+      maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
+      xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
+      if(val!=NULL)
+	tmpmaps->name = zStrdup ((char*)val);
+      else
+	tmpmaps->name = zStrdup ("unknownIdentifier");
+      tmpmaps->content = NULL;
+      tmpmaps->next = NULL;
+      const char ress[4][13] =
+	{ "mimeType", "encoding", "schema", "transmission" };
+      for (l = 0; l < 4; l++){
+	val = xmlGetProp (cur, BAD_CAST ress[l]);
+	if (val != NULL && strlen ((char *) val) > 0)
+	  {
+	    if (tmpmaps->content != NULL)
+	      addToMap (tmpmaps->content, ress[l],
+			(char *) val);
+	    else
+	      tmpmaps->content =
+		createMap (ress[l], (char *) val);
+	    if(l==3 && strncasecmp((char*)val,"reference",xmlStrlen(val))==0)
+	      addToMap (tmpmaps->content,"asReference","true");
+	  }
+	xmlFree (val);
+      }
+      if (*request_output == NULL)
+	*request_output = dupMaps(&tmpmaps);
+      else
+	addMapsToMaps(request_output,tmpmaps);
+    }
+  }
+}
+
+/**
  * Parse outputs from XML nodes and store them in a maps.
  *
@@ -1225,4 +1321,8 @@
  */
 int xmlParseRequest(maps** main_conf,const char* post,map** request_inputs,service* s,maps** inputs,maps** outputs,HINTERNET* hInternet){
+
+  map* version=getMapFromMaps(*main_conf,"main","rversion");
+  int vid=getVersionId(version->value);
+
   xmlInitParser ();
   xmlDocPtr doc = xmlParseMemory (post, cgiContentLength);
@@ -1232,7 +1332,7 @@
    */
   xmlXPathObjectPtr tmpsptr =
-    extractFromDoc (doc, "/*/*/*[local-name()='Input']");
+    extractFromDoc (doc, (vid==0?"/*/*/*[local-name()='Input']":"/*/*[local-name()='Input']"));
   xmlNodeSet *tmps = tmpsptr->nodesetval;
-  if(xmlParseInputs(main_conf,s,inputs,doc,tmps,hInternet)<0){
+  if(tmps==NULL || xmlParseInputs(main_conf,s,inputs,doc,tmps,hInternet)<0){
     xmlXPathFreeObject (tmpsptr);
     xmlFreeDoc (doc);
@@ -1242,23 +1342,69 @@
   xmlXPathFreeObject (tmpsptr);
 
-  // Extract ResponseDocument / RawDataOutput from the XML Request 
-  tmpsptr =
-    extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']");
-  bool asRaw = false;
-  tmps = tmpsptr->nodesetval;
-  if (tmps->nodeNr == 0)
-    {
-      xmlXPathFreeObject (tmpsptr);
-      tmpsptr =
-	extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']");
-      tmps = tmpsptr->nodesetval;
-      asRaw = true;
-    }
-  if(tmps->nodeNr != 0){
-    if(xmlParseOutputs(main_conf,request_inputs,outputs,doc,tmps->nodeTab[0],asRaw)<0){
-      xmlXPathFreeObject (tmpsptr);
-      xmlFreeDoc (doc);
-      xmlCleanupParser ();
-      return -1;
+  if(vid==1){
+    tmpsptr =
+      extractFromDoc (doc, "/*[local-name()='Execute']");
+    bool asRaw = false;
+    tmps = tmpsptr->nodesetval;
+    if(tmps->nodeNr > 0){
+      int k = 0;
+      for (k=0; k < tmps->nodeNr; k++){
+	maps *tmpmaps = NULL;
+	xmlNodePtr cur = tmps->nodeTab[k];
+	if (cur->type == XML_ELEMENT_NODE){
+	  xmlChar *val = xmlGetProp (cur, BAD_CAST "mode");
+	  if(val!=NULL)
+	    addToMap(*request_inputs,"mode",(char*)val);
+	  else
+	    addToMap(*request_inputs,"mode","auto");
+	  val = xmlGetProp (cur, BAD_CAST "response");
+	  if(val!=NULL){
+	    addToMap(*request_inputs,"response",(char*)val);
+	    if(strncasecmp((char*)val,"raw",xmlStrlen(val))==0)
+	      addToMap(*request_inputs,"RawDataOutput","");
+	    else
+	      addToMap(*request_inputs,"ResponseDocument","");
+	  }
+	  else{
+	    addToMap(*request_inputs,"response","document");
+	    addToMap(*request_inputs,"ResponseDocument","");
+	  }
+	}
+      }
+    }
+    xmlXPathFreeObject (tmpsptr);
+    tmpsptr =
+      extractFromDoc (doc, "/*/*[local-name()='Output']");
+    tmps = tmpsptr->nodesetval;
+    if(tmps->nodeNr > 0){
+      if(xmlParseOutputs2(main_conf,request_inputs,outputs,doc,tmps)<0){
+	xmlXPathFreeObject (tmpsptr);
+	xmlFreeDoc (doc);
+	xmlCleanupParser ();
+	return -1;
+      }
+    }
+  }
+  else{
+    // Extract ResponseDocument / RawDataOutput from the XML Request 
+    tmpsptr =
+      extractFromDoc (doc, "/*/*/*[local-name()='ResponseDocument']");
+    bool asRaw = false;
+    tmps = tmpsptr->nodesetval;
+    if (tmps->nodeNr == 0)
+      {
+	xmlXPathFreeObject (tmpsptr);
+	tmpsptr =
+	  extractFromDoc (doc, "/*/*/*[local-name()='RawDataOutput']");
+	tmps = tmpsptr->nodesetval;
+	asRaw = true;
+      }
+    if(tmps->nodeNr != 0){
+      if(xmlParseOutputs(main_conf,request_inputs,outputs,doc,tmps->nodeTab[0],asRaw)<0){
+	xmlXPathFreeObject (tmpsptr);
+	xmlFreeDoc (doc);
+	xmlCleanupParser ();
+	return -1;
+      }
     }
   }
Index: trunk/zoo-project/zoo-kernel/response_print.c
===================================================================
--- trunk/zoo-project/zoo-kernel/response_print.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/response_print.c	(revision 654)
@@ -1455,199 +1455,194 @@
 
   doc = xmlNewDoc(BAD_CAST "1.0");
-  map* version=getMap(request,"version");
-  n = printWPSHeader(doc,m,"Execute","ExecuteResponse",(version!=NULL?version->value:"1.0.0"),2);
-  int wpsId=zooXmlAddNs(NULL,"http://www.opengis.net/wps/1.0.0","wps");
+  map* version=getMapFromMaps(m,"main","rversion");
+  int vid=getVersionId(version->value);
+  n = printWPSHeader(doc,m,"Execute",root_nodes[vid][2],(version!=NULL?version->value:"1.0.0"),2);
+  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
   ns=usedNs[wpsId];
-  int owsId=zooXmlAddNs(NULL,"http://www.opengis.net/ows/1.1","ows");
+  int owsId=zooXmlAddNs(NULL,schemas[vid][1],"ows");
   ns_ows=usedNs[owsId];
   int xlinkId=zooXmlAddNs(NULL,"http://www.w3.org/1999/xlink","xlink");
   ns_xlink=usedNs[xlinkId];
-
-  char tmp[256];
-  char url[1024];
+  bool hasStoredExecuteResponse=false;
   char stored_path[1024];
-  memset(tmp,0,256);
-  memset(url,0,1024);
   memset(stored_path,0,1024);
-  maps* tmp_maps=getMaps(m,"main");
-  if(tmp_maps!=NULL){
-    map* tmpm1=getMap(tmp_maps->content,"serverAddress");
-    /**
-     * Check if the ZOO Service GetStatus is available in the local directory.
-     * If yes, then it uses a reference to an URL which the client can access
-     * to get information on the status of a running Service (using the 
-     * percentCompleted attribute). 
-     * Else fallback to the initial method using the xml file to write in ...
-     */
-    char ntmp[1024];
+    
+  if(vid==0){
+    char tmp[256];
+    char url[1024];
+    memset(tmp,0,256);
+    memset(url,0,1024);
+    maps* tmp_maps=getMaps(m,"main");
+    if(tmp_maps!=NULL){
+      map* tmpm1=getMap(tmp_maps->content,"serverAddress");
+      /**
+       * Check if the ZOO Service GetStatus is available in the local directory.
+       * If yes, then it uses a reference to an URL which the client can access
+       * to get information on the status of a running Service (using the 
+       * percentCompleted attribute). 
+       * Else fallback to the initial method using the xml file to write in ...
+       */
+      char ntmp[1024];
 #ifndef WIN32
-    getcwd(ntmp,1024);
+      getcwd(ntmp,1024);
 #else
-    _getcwd(ntmp,1024);
+      _getcwd(ntmp,1024);
 #endif
-    struct stat myFileInfo;
-    int statRes;
-    char file_path[1024];
-    sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
-    statRes=stat(file_path,&myFileInfo);
-    if(statRes==0){
-      char currentSid[128];
-      map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
-      map *tmp_lenv=NULL;
-      tmp_lenv=getMapFromMaps(m,"lenv","usid");
-      if(tmp_lenv==NULL)
-	sprintf(currentSid,"%i",pid);
-      else
-	sprintf(currentSid,"%s",tmp_lenv->value);
-      if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
-	sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
+      struct stat myFileInfo;
+      int statRes;
+      char file_path[1024];
+      sprintf(file_path,"%s/GetStatus.zcfg",ntmp);
+      statRes=stat(file_path,&myFileInfo);
+      if(statRes==0){
+	char currentSid[128];
+	map* tmpm=getMap(tmp_maps->content,"rewriteUrl");
+	map *tmp_lenv=NULL;
+	tmp_lenv=getMapFromMaps(m,"lenv","usid");
+	if(tmp_lenv==NULL)
+	  sprintf(currentSid,"%i",pid);
+	else
+	  sprintf(currentSid,"%s",tmp_lenv->value);
+	if(tmpm==NULL || strcasecmp(tmpm->value,"false")==0){
+	  sprintf(url,"%s?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
+	}else{
+	  if(strlen(tmpm->value)>0)
+	    if(strcasecmp(tmpm->value,"true")!=0)
+	      sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
+	    else
+	      sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
+	  else
+	    sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
+	}
       }else{
-	if(strlen(tmpm->value)>0)
-	  if(strcasecmp(tmpm->value,"true")!=0)
-	    sprintf(url,"%s/%s/GetStatus/%s",tmpm1->value,tmpm->value,currentSid);
-	  else
-	    sprintf(url,"%s/GetStatus/%s",tmpm1->value,currentSid);
-	else
-	  sprintf(url,"%s/?request=Execute&service=WPS&version=1.0.0&Identifier=GetStatus&DataInputs=sid=%s&RawDataOutput=Result",tmpm1->value,currentSid);
-	fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
-      }
-    }else{
+	int lpid;
+	map* tmpm2=getMapFromMaps(m,"lenv","usid");
+	map* tmpm3=getMap(tmp_maps->content,"tmpUrl");
+	if(tmpm1!=NULL && tmpm3!=NULL){
+	  if( strncasecmp( tmpm3->value, "http://", 7) == 0 ||
+	      strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){
+	    sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value);
+	  }else
+	    sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
+	}
+      }
+      if(tmpm1!=NULL){
+	sprintf(tmp,"%s",tmpm1->value);
+      }
       int lpid;
       map* tmpm2=getMapFromMaps(m,"lenv","usid");
-      map* tmpm3=getMap(tmp_maps->content,"tmpUrl");
-      if(tmpm1!=NULL && tmpm3!=NULL){
-	if( strncasecmp( tmpm3->value, "http://", 7) == 0 ||
-	    strncasecmp( tmpm3->value, "https://", 8 ) == 0 ){
-	  sprintf(url,"%s/%s_%s.xml",tmpm3->value,service,tmpm2->value);
-	}else
-	  sprintf(url,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
-      }
-    }
-    if(tmpm1!=NULL){
-      sprintf(tmp,"%s",tmpm1->value);
-    }
-    int lpid;
-    map* tmpm2=getMapFromMaps(m,"lenv","usid");
-    tmpm1=getMapFromMaps(m,"main","TmpPath");
-    sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
-  }
-
-  xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
-  map* test=getMap(request,"storeExecuteResponse");
-  bool hasStoredExecuteResponse=false;
-  if(test!=NULL && strcasecmp(test->value,"true")==0){
-    xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
-    hasStoredExecuteResponse=true;
-  }
-
-  nc = xmlNewNode(ns, BAD_CAST "Process");
-  map* tmp2=getMap(serv->content,"processVersion");
-  if(tmp2!=NULL)
-    xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
+      tmpm1=getMapFromMaps(m,"main","TmpPath");
+      sprintf(stored_path,"%s/%s_%s.xml",tmpm1->value,service,tmpm2->value);
+    }
+
+    xmlNewProp(n,BAD_CAST "serviceInstance",BAD_CAST tmp);
+    map* test=getMap(request,"storeExecuteResponse");
+    if(test!=NULL && strcasecmp(test->value,"true")==0){
+      xmlNewProp(n,BAD_CAST "statusLocation",BAD_CAST url);
+      hasStoredExecuteResponse=true;
+    }
+
+    nc = xmlNewNode(ns, BAD_CAST "Process");
+    map* tmp2=getMap(serv->content,"processVersion");
+    if(tmp2!=NULL)
+      xmlNewNsProp(nc,ns,BAD_CAST "processVersion",BAD_CAST tmp2->value);
   
-  map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
-  printDescription(nc,ns_ows,tmpI->value,serv->content,0);
-
-  xmlAddChild(n,nc);
-
-  nc = xmlNewNode(ns, BAD_CAST "Status");
-  const struct tm *tm;
-  size_t len;
-  time_t now;
-  char *tmp1;
-  map *tmpStatus;
+    map* tmpI=getMapFromMaps(m,"lenv","oIdentifier");
+    printDescription(nc,ns_ows,tmpI->value,serv->content,0);
+
+    xmlAddChild(n,nc);
+
+    nc = xmlNewNode(ns, BAD_CAST "Status");
+    const struct tm *tm;
+    size_t len;
+    time_t now;
+    char *tmp1;
+    map *tmpStatus;
   
-  now = time ( NULL );
-  tm = localtime ( &now );
-
-  tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
-
-  len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
-
-  xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
-
-  char sMsg[2048];
-  switch(status){
-  case SERVICE_SUCCEEDED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
-    sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_STARTED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
-    tmpStatus=getMapFromMaps(m,"lenv","status");
-    xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
-    sprintf(sMsg,_("The ZOO service \"%s\" is currently running. Please reload this document to get the up-to-date status of the service."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_ACCEPTED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
-    sprintf(sMsg,_("The service \"%s\" was accepted by the ZOO kernel and is running as a background task. Please access the URL in the statusLocation attribute provided in this document to get the up-to-date status and results."),serv->name);
-    nc3=xmlNewText(BAD_CAST sMsg);
-    xmlAddChild(nc1,nc3);
-    break;
-  case SERVICE_FAILED:
-    nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
-    map *errorMap;
-    map *te;
-    te=getMapFromMaps(m,"lenv","code");
-    if(te!=NULL)
-      errorMap=createMap("code",te->value);
-    else
-      errorMap=createMap("code","NoApplicableCode");
-    te=getMapFromMaps(m,"lenv","message");
-    if(te!=NULL)
-      addToMap(errorMap,"text",_ss(te->value));
-    else
-      addToMap(errorMap,"text",_("No more information available"));
-    nc3=createExceptionReportNode(m,errorMap,0);
-    freeMap(&errorMap);
-    free(errorMap);
-    xmlAddChild(nc1,nc3);
-    break;
-  default :
-    printf(_("error code not know : %i\n"),status);
-    //exit(1);
-    break;
-  }
-  xmlAddChild(nc,nc1);
-  xmlAddChild(n,nc);
-  free(tmp1);
+    now = time ( NULL );
+    tm = localtime ( &now );
+
+    tmp1 = (char*)malloc((TIME_SIZE+1)*sizeof(char));
+
+    len = strftime ( tmp1, TIME_SIZE, "%Y-%m-%dT%I:%M:%SZ", tm );
+
+    xmlNewProp(nc,BAD_CAST "creationTime",BAD_CAST tmp1);
+
+    char sMsg[2048];
+    switch(status){
+    case SERVICE_SUCCEEDED:
+      nc1 = xmlNewNode(ns, BAD_CAST "ProcessSucceeded");
+      sprintf(sMsg,_("The service \"%s\" ran successfully."),serv->name);
+      nc3=xmlNewText(BAD_CAST sMsg);
+      xmlAddChild(nc1,nc3);
+      break;
+    case SERVICE_STARTED:
+      nc1 = xmlNewNode(ns, BAD_CAST "ProcessStarted");
+      tmpStatus=getMapFromMaps(m,"lenv","status");
+      xmlNewProp(nc1,BAD_CAST "percentCompleted",BAD_CAST tmpStatus->value);
+      sprintf(sMsg,_("The ZOO service \"%s\" is currently running. Please reload this document to get the up-to-date status of the service."),serv->name);
+      nc3=xmlNewText(BAD_CAST sMsg);
+      xmlAddChild(nc1,nc3);
+      break;
+    case SERVICE_ACCEPTED:
+      nc1 = xmlNewNode(ns, BAD_CAST "ProcessAccepted");
+      sprintf(sMsg,_("The service \"%s\" was accepted by the ZOO kernel and is running as a background task. Please access the URL in the statusLocation attribute provided in this document to get the up-to-date status and results."),serv->name);
+      nc3=xmlNewText(BAD_CAST sMsg);
+      xmlAddChild(nc1,nc3);
+      break;
+    case SERVICE_FAILED:
+      nc1 = xmlNewNode(ns, BAD_CAST "ProcessFailed");
+      map *errorMap;
+      map *te;
+      te=getMapFromMaps(m,"lenv","code");
+      if(te!=NULL)
+	errorMap=createMap("code",te->value);
+      else
+	errorMap=createMap("code","NoApplicableCode");
+      te=getMapFromMaps(m,"lenv","message");
+      if(te!=NULL)
+	addToMap(errorMap,"text",_ss(te->value));
+      else
+	addToMap(errorMap,"text",_("No more information available"));
+      nc3=createExceptionReportNode(m,errorMap,0);
+      freeMap(&errorMap);
+      free(errorMap);
+      xmlAddChild(nc1,nc3);
+      break;
+    default :
+      printf(_("error code not know : %i\n"),status);
+      //exit(1);
+      break;
+    }
+    xmlAddChild(nc,nc1);
+    xmlAddChild(n,nc);
+    free(tmp1);
 
 #ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 161\n");
+    fprintf(stderr,"printProcessResponse %d\n",__LINE__);
 #endif
 
-  map* lineage=getMap(request,"lineage");
-  if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
-    nc = xmlNewNode(ns, BAD_CAST "DataInputs");
-    maps* mcursor=inputs;
-    elements* scursor=NULL;
-    while(mcursor!=NULL /*&& scursor!=NULL*/){
-      scursor=getElements(serv->inputs,mcursor->name);
-      printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input");
-      mcursor=mcursor->next;
-    }
-    xmlAddChild(n,nc);
-    
-#ifdef DEBUG
-    fprintf(stderr,"printProcessResponse 1 177\n");
-#endif
-
-    nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
-    mcursor=outputs;
-    scursor=NULL;
-    while(mcursor!=NULL){
-      scursor=getElements(serv->outputs,mcursor->name);
-      printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
-      mcursor=mcursor->next;
-    }
-    xmlAddChild(n,nc);
-  }
-#ifdef DEBUG
-  fprintf(stderr,"printProcessResponse 1 190\n");
-#endif
+    map* lineage=getMap(request,"lineage");
+    if(lineage!=NULL && strcasecmp(lineage->value,"true")==0){
+      nc = xmlNewNode(ns, BAD_CAST "DataInputs");
+      maps* mcursor=inputs;
+      elements* scursor=NULL;
+      while(mcursor!=NULL /*&& scursor!=NULL*/){
+	scursor=getElements(serv->inputs,mcursor->name);
+	printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Input",vid);
+	mcursor=mcursor->next;
+      }
+      xmlAddChild(n,nc);
+
+      nc = xmlNewNode(ns, BAD_CAST "OutputDefinitions");
+      mcursor=outputs;
+      scursor=NULL;
+      while(mcursor!=NULL){
+	scursor=getElements(serv->outputs,mcursor->name);
+	printOutputDefinitions(doc,nc,ns,ns_ows,scursor,mcursor,"Output");
+	mcursor=mcursor->next;
+      }
+      xmlAddChild(n,nc);
+    }
+  }
 
   /**
@@ -1655,5 +1650,7 @@
    */
   if(status==SERVICE_SUCCEEDED){
-    nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
+    if(vid==0){
+      nc = xmlNewNode(ns, BAD_CAST "ProcessOutputs");
+    }
     maps* mcursor=outputs;
     elements* scursor=serv->outputs;
@@ -1665,9 +1662,18 @@
       scursor=getElements(serv->outputs,mcursor->name);
       if(scursor!=NULL){
-	if(testResponse==NULL || tmp0==NULL)
-	  printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
+	if(testResponse==NULL || tmp0==NULL){
+	  if(vid==0)
+	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	  else
+	    printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	}
 	else
-	  if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0)
-	    printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
+
+	  if(tmp0!=NULL && strncmp(tmp0->value,"true",4)==0){
+	    if(vid==0)
+	      printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	    else
+	      printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	  }
       }else
 	/**
@@ -1675,11 +1681,15 @@
 	 * present in the service code
 	 */
-	printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output");
+	if(vid==0)
+	  printIOType(doc,nc,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
+	else
+	  printIOType(doc,n,ns,ns_ows,ns_xlink,scursor,mcursor,"Output",vid);
       mcursor=mcursor->next;
     }
-    xmlAddChild(n,nc);
-  }
-
-  if(hasStoredExecuteResponse==true && status!=SERVICE_STARTED && status!=SERVICE_ACCEPTED){
+    if(vid==0)
+      xmlAddChild(n,nc);
+  }
+  
+  if(vid==0 && hasStoredExecuteResponse==true && status!=SERVICE_STARTED && status!=SERVICE_ACCEPTED){
 #ifndef RELY_ON_DB
     semid lid=acquireLock(m);//,1);
@@ -1822,5 +1832,5 @@
  * @param type the type
  */
-void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type){
+void printIOType(xmlDocPtr doc,xmlNodePtr nc,xmlNsPtr ns_wps,xmlNsPtr ns_ows,xmlNsPtr ns_xlink,elements* e,maps* m,const char* type,int vid){
 
   xmlNodePtr nc1,nc2,nc3;
@@ -1832,36 +1842,42 @@
     tmp=m->content;
 
-  nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
-  if(e!=NULL)
-    nc3=xmlNewText(BAD_CAST e->name);
-  else
-    nc3=xmlNewText(BAD_CAST m->name);
-
-  xmlAddChild(nc2,nc3);
-  xmlAddChild(nc1,nc2);
-  xmlAddChild(nc,nc1);
-  if(e!=NULL)
-    tmp=getMap(e->content,"Title");
-  else
-    tmp=getMap(m->content,"Title");
+  if(vid==0){
+    nc2=xmlNewNode(ns_ows, BAD_CAST "Identifier");
+    if(e!=NULL)
+      nc3=xmlNewText(BAD_CAST e->name);
+    else
+      nc3=xmlNewText(BAD_CAST m->name);
+    
+    xmlAddChild(nc2,nc3);
+    xmlAddChild(nc1,nc2);
   
-  if(tmp!=NULL){
-    nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-    nc3=xmlNewText(BAD_CAST _ss(tmp->value));
-    xmlAddChild(nc2,nc3);  
-    xmlAddChild(nc1,nc2);
-  }
-
-  if(e!=NULL)
-    tmp=getMap(e->content,"Abstract");
-  else
-    tmp=getMap(m->content,"Abstract");
-
-  if(tmp!=NULL){
-    nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
-    nc3=xmlNewText(BAD_CAST _ss(tmp->value));
-    xmlAddChild(nc2,nc3);  
-    xmlAddChild(nc1,nc2);
     xmlAddChild(nc,nc1);
+
+    if(e!=NULL)
+      tmp=getMap(e->content,"Title");
+    else
+      tmp=getMap(m->content,"Title");
+    
+    if(tmp!=NULL){
+      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
+      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
+      xmlAddChild(nc2,nc3);  
+      xmlAddChild(nc1,nc2);
+    }
+
+    if(e!=NULL)
+      tmp=getMap(e->content,"Abstract");
+    else
+      tmp=getMap(m->content,"Abstract");
+
+    if(tmp!=NULL){
+      nc2=xmlNewNode(ns_ows, BAD_CAST tmp->name);
+      nc3=xmlNewText(BAD_CAST _ss(tmp->value));
+      xmlAddChild(nc2,nc3);  
+      xmlAddChild(nc1,nc2);
+      xmlAddChild(nc,nc1);
+    }
+  }else{
+    xmlNewProp(nc1,BAD_CAST "id",BAD_CAST (e!=NULL?e->name:m->name));
   }
 
@@ -2155,14 +2171,18 @@
   }
   n = xmlNewNode(ns, BAD_CAST "ExceptionReport");
+  map* version=getMapFromMaps(m,"main","rversion");
+  int vid=getVersionId(version->value);
   if(use_ns==1){
-    xmlNewNs(n,BAD_CAST "http://www.opengis.net/ows/1.1",BAD_CAST"ows");
+    xmlNewNs(n,BAD_CAST schemas[vid][1],BAD_CAST"ows");
     int xsiId=zooXmlAddNs(n,"http://www.w3.org/2001/XMLSchema-instance","xsi");
     ns_xsi=usedNs[xsiId];
-    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST "http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd");
+    char tmp[1024];
+    sprintf(tmp,"%s %s",schemas[vid][1],schemas[vid][5]);
+    xmlNewNsProp(n,ns_xsi,BAD_CAST "schemaLocation",BAD_CAST tmp);
   }
 
 
   addLangAttr(n,m);
-  xmlNewProp(n,BAD_CAST "version",BAD_CAST "1.1.0");
+  xmlNewProp(n,BAD_CAST "version",BAD_CAST schemas[vid][6]);
   
   int length=1;
@@ -2247,4 +2267,6 @@
   if(toto!=NULL)
     asRaw=1;
+  map* version=getMapFromMaps(m,"main","rversion");
+  int vid=getVersionId(version->value);
   
   maps* tmpSess=getMaps(m,"senv");
@@ -2309,4 +2331,13 @@
   }
 
+  if(res==SERVICE_ACCEPTED && vid==1){
+    map* statusInfo=createMap("Status","Accepted");
+    map *usid=getMapFromMaps(m,"lenv","usid");
+    addToMap(statusInfo,"JobID",usid->value);
+    printStatusInfo(m,statusInfo,"Execute");
+    freeMap(&statusInfo);
+    free(statusInfo);
+    return;
+  }
 
   map *tmp1=getMapFromMaps(m,"main","tmpPath");
@@ -2428,11 +2459,9 @@
       tmpI=tmpI->next;
     }
-    map *r_inputs=getMap(s->content,"serviceProvider");
 #ifdef DEBUG
-    fprintf(stderr,"SERVICE : %s\n",r_inputs->value);
+    fprintf(stderr,"SERVICE : %s\n",s->name);
     dumpMaps(m);
 #endif
     printProcessResponse(m,request_inputs1,cpid,
-		//	 s,r_inputs->value,res,
 			 s, s->name,res,  // replace serviceProvider with serviceName in stored response file name
 			 request_inputs,
@@ -2672,2 +2701,72 @@
 }
 
+/**
+ * Print a StatusInfo XML document.
+ * a statusInfo map should contain the following keys:
+ *  * JobID corresponding to usid key from the lenv section
+ *  * Status the current state (Succeeded,Failed,Accepted,Running)
+ *  * PercentCompleted (optional) the percent completed
+ *  * Message (optional) any messages the service may wish to share
+ *
+ * @param conf the maps containing the settings of the main.cfg file
+ * @param statusInfo the map containing the statusInfo definition
+ * @param req the WPS requests (GetResult, GetStatus or Dismiss)
+ */
+void printStatusInfo(maps* conf,map* statusInfo,char* req){
+  rewind(stdout);
+  xmlNodePtr n,n1;
+  xmlDocPtr doc;
+  xmlNsPtr ns;
+  xmlChar *xmlbuff;
+  int buffersize;
+  char *encoding=getEncoding(conf);
+  map *tmp;
+  int pid=0;
+  printf("Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+
+  map* version=getMapFromMaps(conf,"main","rversion");
+  int vid=getVersionId(version->value);
+
+  doc = xmlNewDoc(BAD_CAST "1.0");
+  n1=printWPSHeader(doc,conf,req,"StatusInfo",version->value,1);
+
+  map* val=getMap(statusInfo,"JobID");
+  int wpsId=zooXmlAddNs(NULL,schemas[vid][2],"wps");
+  ns=usedNs[wpsId];
+  n = xmlNewNode(ns, BAD_CAST "JobID");
+  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
+
+  xmlAddChild(n1,n);
+
+  val=getMap(statusInfo,"Status");
+  n = xmlNewNode(ns, BAD_CAST "Status");
+  xmlAddChild(n,xmlNewText(BAD_CAST val->value));
+
+  xmlAddChild(n1,n);
+
+  if(strncasecmp(val->value,"Failed",6)!=0 &&
+     strncasecmp(val->value,"Succeeded",9)!=0){
+    val=getMap(statusInfo,"PercentCompleted");
+    if(val!=NULL){
+      n = xmlNewNode(ns, BAD_CAST "PercentCompleted");
+      xmlAddChild(n,xmlNewText(BAD_CAST val->value));
+      xmlAddChild(n1,n);
+    }
+
+    val=getMap(statusInfo,"Message");
+    if(val!=NULL){    
+      xmlAddChild(n1,xmlNewComment(BAD_CAST val->value));
+    }
+  }
+  xmlDocSetRootElement(doc, n1);
+
+  xmlDocDumpFormatMemoryEnc(doc, &xmlbuff, &buffersize, encoding, 1);
+  printf("%s",xmlbuff);
+
+  xmlFree(xmlbuff);
+  xmlFreeDoc(doc);
+  xmlCleanupParser();
+  zooXmlCleanupNs();
+  
+}
+
Index: trunk/zoo-project/zoo-kernel/response_print.h
===================================================================
--- trunk/zoo-project/zoo-kernel/response_print.h	(revision 653)
+++ trunk/zoo-project/zoo-kernel/response_print.h	(revision 654)
@@ -134,9 +134,16 @@
 
   /**
+   * Definitions of acceptable final status
+   */
+  static char wpsStatus[2][11]={
+    "Succeeded",
+    "Failed"
+  };
+  /**
    * Definitions of schemas depending on the WPS version
    */
-  static const char* schemas[2][5]={
-    {"1.0.0","http://www.opengis.net/ows/1.1","http://www.opengis.net/wps/1.0.0","http://schemas.opengis.net/wps/1.0.0","%s %s/wps%s_response.xsd"},
-    {"2.0.0","http://www.opengis.net/ows/2.0","http://www.opengis.net/wps/2.0","http://schemas.opengis.net/wps/2.0","%s %s/wps%s.xsd"},
+  static const char* schemas[2][7]={
+    {"1.0.0","http://www.opengis.net/ows/1.1","http://www.opengis.net/wps/1.0.0","http://schemas.opengis.net/wps/1.0.0","%s %s/wps%s_response.xsd","http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd","1.1.0"},
+    {"2.0.0","http://www.opengis.net/ows/2.0","http://www.opengis.net/wps/2.0","http://schemas.opengis.net/wps/2.0","%s %s/wps%s.xsd","http://schemas.opengis.net/ows/2.0/owsExceptionReport.xsd","2.0.2"},
   };
   /**
@@ -152,9 +159,17 @@
   };
   /**
+   * Definitions requests requiring identifier (depending on the WPS version)
+   */
+  static int nbReqIdentifier=2;
+  /**
+   * Definitions requests requiring jobid (only for WPS version 2.0.0)
+   */
+  static int nbReqJob=3;
+  /**
    * Definitions of root node for response depending on the request and the WPS version
    */
-  static const char* root_nodes[2][6]={
-    {"ProcessOfferings","ProcessDescriptions",NULL},
-    {"Contents","ProcessOfferings",NULL}
+  static const char root_nodes[2][4][20]={
+    {"ProcessOfferings","ProcessDescriptions","ExecuteResponse",NULL},
+    {"Contents","ProcessOfferings","Result",NULL}
   };
 
@@ -198,9 +213,10 @@
   void printDocument(maps*,xmlDocPtr,int);
   void printDescription(xmlNodePtr,xmlNsPtr,const char*,map*,int);
-  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
+  void printIOType(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*,int);
   map* parseBoundingBox(const char*);
   void printBoundingBox(xmlNsPtr,xmlNodePtr,map*);
   void printBoundingBoxDocument(maps*,maps*,FILE*);
   void printOutputDefinitions(xmlDocPtr,xmlNodePtr,xmlNsPtr,xmlNsPtr,elements*,maps*,const char*);
+  void printStatusInfo(maps*,map*,char*);
 
   void outputResponse(service*,maps*,maps*,map*,int,maps*,int);
Index: trunk/zoo-project/zoo-kernel/server_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/server_internal.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/server_internal.c	(revision 654)
@@ -24,4 +24,5 @@
 
 #include "server_internal.h"
+#include "service_internal.h"
 #include "response_print.h"
 #include "mimetypes.h"
@@ -785,4 +786,198 @@
 }
 
-
-
+#include <dirent.h>
+#ifndef RELY_ON_DB
+/**
+ * Read the Result file (.res).
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the service identifier (usid key from the [lenv] section)
+ */
+void readFinalRes(maps* conf,char* pid,map* statusInfo){
+  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
+  char* fbkpid =
+    (char *)
+    malloc ((strlen (r_inputs->value) + strlen (pid) + 7) * sizeof (char));
+  sprintf (fbkpid, "%s/%s.res", r_inputs->value, pid);
+  struct stat file_status;
+  int istat = stat (fbkpid, &file_status);
+  if (istat == 0 && file_status.st_size > 0)
+    {
+      maps *res = (maps *) malloc (MAPS_SIZE);
+      conf_read (fbkpid, res);
+      map* status=getMapFromMaps(res,"status","status");
+      addToMap(statusInfo,"Status",status->value);
+      freeMaps(&res);
+      free(res);
+    }
+  else
+    addToMap(statusInfo,"Status","Failed");  
+  free(fbkpid);
+}
+
+/**
+ * Check if a service is running.
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the unique service identifier (usid from the lenv section)
+ * @return 1 in case the service is still running, 0 otherwise
+ */
+int isRunning(maps* conf,char* pid){
+  int res=0;
+  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
+  char* fbkpid =
+    (char *)
+    malloc ((strlen (r_inputs->value) + strlen (pid) + 7) * sizeof (char));
+  sprintf (fbkpid, "%s/%s.pid", r_inputs->value, pid);
+  FILE* f0 = fopen (fbkpid, "r");
+  if(f0!=NULL){
+    fclose(f0);
+    res=1;
+  }
+  free(fbkpid);
+  return res;
+}
+#else
+#include "sqlapi.h"
+#endif
+
+/**
+ * Run GetStatus requests.
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the service identifier (usid key from the [lenv] section)
+ * @param req the request (GetStatus / GetResult)
+ */
+void runGetStatus(maps* conf,char* pid,char* req){
+  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
+  char *sid=getStatusId(conf,pid);
+  if(sid==NULL){
+    errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
+		    "NoSuchJob", pid);
+  }else{
+    map* statusInfo=createMap("JobID",pid);
+    if(isRunning(conf,pid)>0){
+      if(strncasecmp(req,"GetResult",strlen(req))==0){
+	errorException (conf, _("The result for the requested JobID has not yet been generated. "),
+			"ResultNotReady", pid);
+	return;
+      }
+      else
+	if(strncasecmp(req,"GetStatus",strlen(req))==0){
+	  addToMap(statusInfo,"Status","Running");
+	  char* tmpStr=_getStatus(conf,pid);
+	  if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
+	    char *tmpStr1=strdup(tmpStr);
+	    char *tmpStr0=strdup(strstr(tmpStr,"|")+1);
+	    free(tmpStr);
+	    tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
+	    addToMap(statusInfo,"PercentCompleted",tmpStr1);
+	    addToMap(statusInfo,"Message",tmpStr0);
+	    free(tmpStr0);
+	    free(tmpStr1);
+	  }
+	}
+    }
+    else{
+      if(strncasecmp(req,"GetResult",strlen(req))==0){
+	char* result=_getStatusFile(conf,pid);
+	if(result!=NULL){
+	  char *encoding=getEncoding(conf);
+	  fprintf(stdout,"Content-Type: text/xml; charset=%s\r\nStatus: 200 OK\r\n\r\n",encoding);
+	  fprintf(stdout,"%s",result);
+	  fflush(stdout);
+	  freeMap(&statusInfo);
+	  free(statusInfo);
+	  return;
+	}else{
+	  errorException (conf, _("The result for the requested JobID has not yet been generated. "),
+			  "ResultNotReady", pid);
+	  freeMap(&statusInfo);
+	  free(statusInfo);
+	  return;
+	}
+      }else
+	if(strncasecmp(req,"GetStatus",strlen(req))==0){
+	  readFinalRes(conf,pid,statusInfo);
+	  char* tmpStr=_getStatus(conf,pid);
+	  if(tmpStr!=NULL && strncmp(tmpStr,"-1",2)!=0){
+	    char *tmpStr1=strdup(tmpStr);
+	    char *tmpStr0=strdup(strstr(tmpStr,"|")+1);
+	    free(tmpStr);
+	    tmpStr1[strlen(tmpStr1)-strlen(tmpStr0)-1]='\0';
+	    addToMap(statusInfo,"PercentCompleted",tmpStr1);
+	    addToMap(statusInfo,"Message",tmpStr0);
+	    free(tmpStr0);
+	    free(tmpStr1);
+	  }
+	}
+    }
+    printStatusInfo(conf,statusInfo,req);
+    freeMap(&statusInfo);
+    free(statusInfo);
+  }
+  return;
+}
+
+/**
+ * Run Dismiss requests.
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the service identifier (usid key from the [lenv] section)
+ */
+void runDismiss(maps* conf,char* pid){
+  map* r_inputs = getMapFromMaps (conf, "main", "tmpPath");
+  char *sid=getStatusId(conf,pid);
+  if(sid==NULL){
+    errorException (conf, _("The JobID from the request does not match any of the Jobs running on this server"),
+		    "NoSuchJob", pid);
+  }else{
+    // We should send the Dismiss request to the target host if it differs
+    char* fbkpid =
+      (char *)
+      malloc ((strlen (r_inputs->value) + strlen (pid) + 7) * sizeof (char));
+    sprintf (fbkpid, "%s/%s.pid", r_inputs->value, pid);
+    FILE* f0 = fopen (fbkpid, "r");
+    if(f0!=NULL){
+      long flen;
+      char *fcontent;
+      fseek (f0, 0, SEEK_END);
+      flen = ftell (f0);
+      fseek (f0, 0, SEEK_SET);
+      fcontent = (char *) malloc ((flen + 1) * sizeof (char));
+      fread(fcontent,flen,1,f0);
+      fcontent[flen]=0;
+      fclose(f0);
+      kill(atoi(fcontent),SIGKILL);
+      free(fcontent);
+    }
+    free(fbkpid);
+    struct dirent *dp;
+    DIR *dirp = opendir(r_inputs->value);
+    char fileName[1024];
+    int hasFile=-1;
+    if(dirp!=NULL){
+      while ((dp = readdir(dirp)) != NULL){
+#ifdef DEBUG
+	fprintf(stderr,"File : %s searched : %s\n",dp->d_name,tmp);
+#endif
+	if(strstr(dp->d_name,pid)!=0){
+	  sprintf(fileName,"%s/%s",r_inputs->value,dp->d_name);
+	  if(unlink(fileName)!=0){
+	    errorException (conf, _("The job cannot be removed, a file cannot be removed"),
+			    "NoApplicableCode", NULL);
+	    return;
+	  }
+	}
+      }
+    }
+#ifdef RELY_ON_DB
+    removeService(conf,pid);
+#endif
+    map* statusInfo=createMap("JobID",pid);
+    addToMap(statusInfo,"Status","Dismissed");
+    printStatusInfo(conf,statusInfo,"Dismiss");
+    free(statusInfo);
+  }
+  return;
+}
Index: trunk/zoo-project/zoo-kernel/server_internal.h
===================================================================
--- trunk/zoo-project/zoo-kernel/server_internal.h	(revision 653)
+++ trunk/zoo-project/zoo-kernel/server_internal.h	(revision 654)
@@ -52,4 +52,6 @@
   void parseIdentifier(maps*,char*,char*,char*);
   void dumpMapsValuesToFiles(maps**,maps**);
+  void runDismiss(maps*,char*);
+  void runGetStatus(maps*,char*,char*);
 
   int isValidLang(maps*,const char*);
Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 654)
@@ -276,5 +276,5 @@
     FILE* fstatus=fopen(fbkpid,"w");
     if(fstatus!=NULL){
-      fprintf(fstatus,"%s|%s\n",status->value,msg->value);
+      fprintf(fstatus,"%s|%s",status->value,msg->value);
       fflush(fstatus);
       fclose(fstatus);
Index: trunk/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.h	(revision 653)
+++ trunk/zoo-project/zoo-kernel/service_internal.h	(revision 654)
@@ -107,4 +107,5 @@
   char* _getStatusFile(maps*,char*);
   char* getStatus(int);
+  char* getStatusId(maps*,char*);
 
   int updateStatus( maps*,const int,const char*);
Index: trunk/zoo-project/zoo-kernel/sql/schema.sql
===================================================================
--- trunk/zoo-project/zoo-kernel/sql/schema.sql	(revision 654)
+++ trunk/zoo-project/zoo-kernel/sql/schema.sql	(revision 654)
@@ -0,0 +1,69 @@
+--------------------------------------------------------------------------------
+--
+-- PostgreSQL definition of tables required byt the ZOO-Kernel version >= 1.5.0
+-- if the the db-backend option is activated
+--
+-- Copyright (C) 2015 GeoLabs SARL. All rights reserved.
+-- Author: David Saggiorato <david.saggiorato@geolabs.fr>
+--
+-- Permission is hereby granted, free of charge, to any person obtaining a copy
+-- of this software and associated documentation files (the "Software"), to deal
+-- in the Software without restriction, including without limitation the rights
+-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+-- copies of the Software, and to permit persons to whom the Software is
+-- furnished to do so, subject to the following conditions:
+--
+-- The above copyright notice and this permission notice shall be included in
+-- all copies or substantial portions of the Software.
+--
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+-- THE SOFTWARE.
+--
+-------------------------------------------------------------------------------- 
+-- If your database is not using UTF-8 per default then uncomment the following 
+-- SET client_encoding = 'UTF8';
+-------------------------------------------------------------------------------- 
+-- Create a dedicated schema to store all tables
+-- Uncomment the following 2 lines to activate the schema use
+-- CREATE SCHEMA zoo;
+-- SET search_path TO zoo;
+--------------------------------------------------------------------------------
+-- Services table
+-- Used to store informations about services running asynchronously
+create table services (
+       osid TEXT unique,
+       sid TEXT unique,
+       uuid TEXT unique,
+       fstate varchar(25),
+       status TEXT,
+       response TEXT,
+       creation_time timestamp with time zone default now(),
+       end_time timestamp with time zone default NULL,
+       progress int,
+       message TEXT
+);
+--------------------------------------------------------------------------------
+-- Responses table 
+-- Used to store the response provided by a services running asynchronously
+create table responses (
+       uuid text references services(uuid) ON DELETE CASCADE,
+       content text,
+       creation_time timestamp with time zone default now()
+);
+--------------------------------------------------------------------------------
+-- Files table
+-- Used to store the files generated during the service execution
+create table files (
+       uuid TEXT references services(uuid) ON DELETE CASCADE,
+       filename text,
+       nature varchar(10),
+       name varchar(255),
+       creation_time timestamp with time zone default now(),
+       expiration_time timestamp with time zone default now() + interval '48 hours'
+);
+--------------------------------------------------------------------------------
Index: trunk/zoo-project/zoo-kernel/sqlapi.c
===================================================================
--- trunk/zoo-project/zoo-kernel/sqlapi.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/sqlapi.c	(revision 654)
@@ -227,5 +227,5 @@
   map *schema=getMapFromMaps(conf,"database","schema");
   char *sqlQuery=(char*)malloc((strlen(schema->value)+flen+strlen(sid->value)+51+1)*sizeof(char));
-  sprintf(sqlQuery,"UPDATE %s.services set response=$$%s$$ where uuid=$$%s$$;",schema->value,tmps,sid->value);
+  sprintf(sqlQuery,"INSERT INTO %s.responses (content,uuid) VALUES ($$%s$$,$$%s$$);",schema->value,tmps,sid->value);
   execSql(conf,sqlQuery);
   cleanUpResultSet(conf);
@@ -292,6 +292,8 @@
 char* _getStatusFile(maps* conf,char* pid){
   map *schema=getMapFromMaps(conf,"database","schema");
-  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
-  sprintf(sqlQuery,"select response from %s.services where uuid=$$%s$$;",schema->value,pid);
+  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+82+1)*sizeof(char));
+  sprintf(sqlQuery,
+	  "select content from %s.responses where uuid=$$%s$$"
+	  " order by creation_time desc limit 1",schema->value,pid);
   if( zoo_DS == NULL )
     init_sql(conf);
@@ -318,12 +320,19 @@
 
 /**
- * Stop handling status repport.
+ * Delete a service reference from the database.
  *
  * @param conf the map containing the setting of the main.cfg file
- */
-void unhandleStatus(maps* conf){
-  map *sid=getMapFromMaps(conf,"lenv","usid");
-  char *sqlQuery=(char*)malloc((strlen(sid->value)+52+1)*sizeof(char));
-  sprintf(sqlQuery,"UPDATE services set end_time=now() where uuid=$$%s$$;",sid->value);
+ * @param pid the service identifier (usid key from the [lenv] section)
+ */
+void removeService(maps* conf,char* pid){
+  map *schema=getMapFromMaps(conf,"database","schema");
+  char *sqlQuery=(char*)
+    malloc((strlen(pid)+strlen(schema->value)+38+1)
+	   *sizeof(char));
+  if( zoo_DS == NULL )
+    init_sql(conf);
+  sprintf(sqlQuery,
+	  "DELETE FROM %s.services where uuid=$$%s$$;",
+	  schema->value,pid);
   execSql(conf,sqlQuery);
   cleanUpResultSet(conf);
@@ -332,3 +341,125 @@
 }
 
+/**
+ * Stop handling status repport.
+ *
+ * @param conf the map containing the setting of the main.cfg file
+ */
+void unhandleStatus(maps* conf){
+  map *schema=getMapFromMaps(conf,"database","schema");
+  map *sid=getMapFromMaps(conf,"lenv","usid");
+  map *fstate=getMapFromMaps(conf,"lenv","fstate");
+  char *sqlQuery=(char*)malloc((strlen(sid->value)+
+				strlen(schema->value)+
+				(fstate!=NULL?
+				 strlen(fstate->value):
+				 6)
+				+66+1)*sizeof(char));
+  sprintf(sqlQuery,
+	  "UPDATE %s.services set end_time=now(), fstate=$$%s$$"
+	  " where uuid=$$%s$$;",
+	  schema->value,(fstate!=NULL?fstate->value:"Failed"),sid->value);
+  execSql(conf,sqlQuery);
+  cleanUpResultSet(conf);
+  close_sql(conf);
+  end_sql();
+}
+
+/**
+ * Read the sid identifier attached of a service if any
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the service identifier (usid key from the [lenv] section)
+ * @return the sid value
+ */
+char* getStatusId(maps* conf,char* pid){
+  map *schema=getMapFromMaps(conf,"database","schema");
+  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
+  sprintf(sqlQuery,
+	  "select osid from %s.services where uuid=$$%s$$",
+	  schema->value,pid);
+  if( zoo_DS == NULL )
+    init_sql(conf);
+  execSql(conf,sqlQuery);
+  OGRFeature  *poFeature = NULL;
+  const char *tmp1;
+  int hasRes=-1;
+  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
+    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
+      if( poFeature->IsFieldSet( iField ) ){
+	tmp1=zStrdup(poFeature->GetFieldAsString( iField ));
+	hasRes=1;
+	break;
+      }
+    }
+    OGRFeature::DestroyFeature( poFeature );
+  }
+  if(hasRes<0)
+    tmp1=NULL;
+  return (char*)tmp1;
+}
+
+/**
+ * Read the Result file (.res).
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the service identifier (usid key from the [lenv] section)
+ */
+void readFinalRes(maps* conf,char* pid,map* statusInfo){
+  map *schema=getMapFromMaps(conf,"database","schema");
+  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+58+1)*sizeof(char));
+  sprintf(sqlQuery,
+	  "select fstate from %s.services where uuid=$$%s$$",
+	  schema->value,pid);
+  if( zoo_DS == NULL )
+    init_sql(conf);
+  execSql(conf,sqlQuery);
+  OGRFeature  *poFeature = NULL;
+  int hasRes=-1;
+  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
+    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
+      if( poFeature->IsFieldSet( iField ) ){
+	addToMap(statusInfo,"Status",poFeature->GetFieldAsString( iField ));
+	hasRes=1;
+	break;
+      }
+    }
+    OGRFeature::DestroyFeature( poFeature );
+  }
+  if(hasRes<0)
+    addToMap(statusInfo,"Status","Failed");
+  return;
+}
+
+/**
+ * Check if a service is running.
+ *
+ * @param conf the maps containing the setting of the main.cfg file
+ * @param pid the unique service identifier (usid from the lenv section)
+ * @return 1 in case the service is still running, 0 otherwise
+ */
+int isRunning(maps* conf,char* pid){
+  int res=0;
+  map *schema=getMapFromMaps(conf,"database","schema");
+  char *sqlQuery=(char*)malloc((strlen(schema->value)+strlen(pid)+73+1)*sizeof(char));
+  sprintf(sqlQuery,"select count(*) as t from %s.services where uuid=$$%s$$ and end_time is null;",schema->value,pid);
+  if( zoo_DS == NULL )
+    init_sql(conf);
+  execSql(conf,sqlQuery);
+  OGRFeature  *poFeature = NULL;
+  const char *tmp1;
+  while( (poFeature = zoo_ResultSet->GetNextFeature()) != NULL ){
+    for( int iField = 0; iField < poFeature->GetFieldCount(); iField++ ){
+      if( poFeature->IsFieldSet( iField ) && 
+	  atoi(poFeature->GetFieldAsString( iField ))>0 ){
+	res=1;
+	break;
+      }
+    }
+    OGRFeature::DestroyFeature( poFeature );
+  }
+  cleanUpResultSet(conf);
+  return res;
+}
+
 #endif
Index: trunk/zoo-project/zoo-kernel/sqlapi.h
===================================================================
--- trunk/zoo-project/zoo-kernel/sqlapi.h	(revision 653)
+++ trunk/zoo-project/zoo-kernel/sqlapi.h	(revision 654)
@@ -1,3 +1,3 @@
-/**
+/*
  * Author : David Saggiorato
  *
@@ -39,4 +39,8 @@
   void recordServiceStatus(maps*);
   void recordResponse(maps*,char*);
+  void readFinalRes(maps*,char*,map*);
+  int isRunning(maps*,char*);
+  char* getStatusId(maps*,char*);
+  void removeService(maps*,char*);
 #endif
 
Index: trunk/zoo-project/zoo-kernel/zoo_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/zoo_loader.c	(revision 654)
@@ -339,4 +339,29 @@
 	    free(identifiers);
 	  }
+	}else{
+	  idptr=extractFromDoc(doc,"/*/*[local-name()='JobID']");
+	  if(idptr!=NULL){
+	    xmlNodeSet* id=idptr->nodesetval;
+	    if(id!=NULL){
+	      char* identifiers=NULL;
+	      identifiers=(char*)calloc(cgiContentLength,sizeof(char));
+	      identifiers[0]=0;
+	      for(int k=0;k<id->nodeNr;k++){
+		xmlChar* content=xmlNodeListGetString(doc, id->nodeTab[k]->xmlChildrenNode,1);
+		if(strlen(identifiers)>0){
+		  char *tmp=zStrdup(identifiers);
+		  snprintf(identifiers,strlen(tmp)+xmlStrlen(content)+2,"%s,%s",tmp,content);
+		  free(tmp);
+		}
+		else{
+		  snprintf(identifiers,xmlStrlen(content)+1,"%s",content);
+		}
+		xmlFree(content);
+	      }
+	      xmlXPathFreeObject(idptr);
+	      addToMap(tmpMap,"JobID",identifiers);
+	      free(identifiers);
+	    }
+	}
 	}
       }
Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 653)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 654)
@@ -22,6 +22,4 @@
  * THE SOFTWARE.
  */
-
-
 
 extern "C" int yylex ();
@@ -1111,40 +1109,40 @@
 
   if(strlen(cgiServerName)>0)
-  {
-    char tmpUrl[1024];
+    {
+      char tmpUrl[1024];
 	
-	if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?		
-		if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
-			sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
-		}
-		else {
-			sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
-		}
+      if ( getenv("HTTPS") != NULL && strncmp(getenv("HTTPS"), "on", 2) == 0 ) { // Knut: check if non-empty instead of "on"?		
+	if ( strncmp(cgiServerPort, "443", 3) == 0 ) { 
+	  sprintf(tmpUrl, "https://%s%s", cgiServerName, cgiScriptName);
 	}
 	else {
-		if ( strncmp(cgiServerPort, "80", 2) == 0 ) { 
-			sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
-		}
-		else {
-			sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
-		}
+	  sprintf(tmpUrl, "https://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
 	}
-#ifdef DEBUG
-    fprintf(stderr,"*** %s ***\n",tmpUrl);
-#endif
-    setMapInMaps(m,"main","serverAddress",tmpUrl);
-  }
-
-  /**
-   * Check for minimum inputs
-   */
+      }
+      else {
+	if ( strncmp(cgiServerPort, "80", 2) == 0 ) { 
+	  sprintf(tmpUrl, "http://%s%s", cgiServerName, cgiScriptName);
+	}
+	else {
+	  sprintf(tmpUrl, "http://%s:%s%s", cgiServerName, cgiServerPort, cgiScriptName);
+	}
+      }
+#ifdef DEBUG
+      fprintf(stderr,"*** %s ***\n",tmpUrl);
+#endif
+      setMapInMaps(m,"main","serverAddress",tmpUrl);
+    }
+
+  //Check for minimum inputs
+  map* version=getMap(request_inputs,"version");
+  if(version==NULL)
+    version=getMapFromMaps(m,"main","version");
+  setMapInMaps(m,"main","rversion",version->value);
+  int vid=getVersionId(version->value);
+  if(vid<0)
+    vid=0;
   map* err=NULL;
-  const char *vvr[]={
-    "GetCapabilities",
-    "DescribeProcess",
-    "Execute",
-    NULL
-  };
-  checkValidValue(request_inputs,&err,"request",(const char**)vvr,1);
+  const char **vvr=(const char**)requests[vid];
+  checkValidValue(request_inputs,&err,"request",vvr,1);
   const char *vvs[]={
     "WPS",
@@ -1174,7 +1172,25 @@
   r_inputs = getMap (request_inputs, "Request");
   REQUEST = zStrdup (r_inputs->value);
+  int reqId=-1;
   if (strncasecmp (REQUEST, "GetCapabilities", 15) != 0){
     checkValidValue(request_inputs,&err,"version",(const char**)vvv,1);
-    checkValidValue(request_inputs,&err,"identifier",NULL,1);
+    int j=0;
+    for(j=0;j<nbSupportedRequests;j++){
+      if(requests[vid][j]!=NULL && requests[vid][j+1]!=NULL){
+	if(j<nbReqIdentifier && strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
+	  checkValidValue(request_inputs,&err,"identifier",NULL,1);
+	  reqId=j+1;
+	  break;
+	}
+	else
+	  if(j>=nbReqIdentifier && j<nbReqIdentifier+nbReqJob && 
+	     strncasecmp(REQUEST,requests[vid][j+1],strlen(REQUEST))==0){
+	    checkValidValue(request_inputs,&err,"jobid",NULL,1);
+	    reqId=j+1;
+	    break;
+	  }
+      }else
+	break;
+    }
   }else{
     checkValidValue(request_inputs,&err,"AcceptVersions",(const char**)vvv,-1);
@@ -1187,8 +1203,4 @@
     }
   }
-  map* version=getMap(request_inputs,"version");
-  if(version==NULL)
-    version=getMapFromMaps(m,"main","version");
-  setMapInMaps(m,"main","rversion",version->value);
   if(err!=NULL){
     printExceptionReportResponse (m, err);
@@ -1293,270 +1305,353 @@
   else
     {
-      r_inputs = getMap (request_inputs, "Identifier");
-
-      struct dirent *dp;
-      DIR *dirp = opendir (conf_dir);
-      if (dirp == NULL)
-        {
-          errorException (m, _("The specified path path does not exist."),
-                          "InvalidParameterValue", conf_dir);
-          freeMaps (&m);
-          free (m);
+      r_inputs = getMap (request_inputs, "JobId");
+      if(reqId>nbReqIdentifier){
+	if (strncasecmp (REQUEST, "GetStatus", strlen(REQUEST)) == 0 ||
+	    strncasecmp (REQUEST, "GetResult", strlen(REQUEST)) == 0){
+	  runGetStatus(m,r_inputs->value,REQUEST);
+	  freeMaps (&m);
+	  free (m);
 	  if(zooRegistry!=NULL){
 	    freeRegistry(&zooRegistry);
 	    free(zooRegistry);
 	  }
-          free (REQUEST);
-          free (SERVICE_URL);
-          return 0;
-        }
-      if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
-        {
-	  /**
-	   * Loop over Identifier list
-	   */
-          xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
-          r_inputs = NULL;
-	  r_inputs = getMap (request_inputs, "version");
-	  map* version=getMapFromMaps(m,"main","rversion");
-	  int vid=getVersionId(version->value);
-	  xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
-					root_nodes[vid][1],(r_inputs!=NULL?r_inputs->value:"1.0.0"),1);
-
-          r_inputs = getMap (request_inputs, "Identifier");
-
-          char *orig = zStrdup (r_inputs->value);
-
-          int saved_stdout = dup (fileno (stdout));
-          dup2 (fileno (stderr), fileno (stdout));
-          if (strcasecmp ("all", orig) == 0)
-            {
-              if (int res =
-                  recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
-                                  printDescribeProcessForProcess) < 0)
-                return res;
-            }
-          else
-            {
-              char *saveptr;
-              char *tmps = strtok_r (orig, ",", &saveptr);
-
-              char buff[256];
-              char buff1[1024];
-              while (tmps != NULL)
-                {
-                  int hasVal = -1;
-                  char *corig = zStrdup (tmps);
-                  if (strstr (corig, ".") != NULL)
-                    {
-
-                      parseIdentifier (m, conf_dir, corig, buff1);
-                      map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
-                      if (tmpMap != NULL)
-                        addToMap (request_inputs, "metapath", tmpMap->value);
-                      map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
-
-                      s1 = (service *) malloc (SERVICE_SIZE);
-                      t = readServiceFile (m, buff1, &s1, tmpMapI->value);
-                      if (t < 0)
-                        {
-                          map *tmp00 = getMapFromMaps (m, "lenv", "message");
-                          char tmp01[1024];
-                          if (tmp00 != NULL)
-                            sprintf (tmp01,
-                                     _
-                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
-                                     tmps, tmp00->value);
-                          else
-                            sprintf (tmp01,
-                                     _
-                                     ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
-                                     tmps);
-                          dup2 (saved_stdout, fileno (stdout));
-                          errorException (m, tmp01, "InvalidParameterValue",
-                                          "identifier");
-                          freeMaps (&m);
-                          free (m);
-			  if(zooRegistry!=NULL){
-			    freeRegistry(&zooRegistry);
-			    free(zooRegistry);
+	  free (REQUEST);
+	  free (SERVICE_URL);
+	  return 0;
+	}
+	else
+	  if (strncasecmp (REQUEST, "Dismiss", strlen(REQUEST)) == 0){
+	    runDismiss(m,r_inputs->value);
+	    freeMaps (&m);
+	    free (m);
+	    if(zooRegistry!=NULL){
+	      freeRegistry(&zooRegistry);
+	      free(zooRegistry);
+	    }
+	    free (REQUEST);
+	    free (SERVICE_URL);
+	    return 0;
+	    
+	  }
+	return 0;
+      }
+      if(reqId<=nbReqIdentifier){
+	r_inputs = getMap (request_inputs, "Identifier");
+
+	struct dirent *dp;
+	DIR *dirp = opendir (conf_dir);
+	if (dirp == NULL)
+	  {
+	    errorException (m, _("The specified path path does not exist."),
+			    "InvalidParameterValue", conf_dir);
+	    freeMaps (&m);
+	    free (m);
+	    if(zooRegistry!=NULL){
+	      freeRegistry(&zooRegistry);
+	      free(zooRegistry);
+	    }
+	    free (REQUEST);
+	    free (SERVICE_URL);
+	    return 0;
+	  }
+	if (strncasecmp (REQUEST, "DescribeProcess", 15) == 0)
+	  {
+	    /**
+	     * Loop over Identifier list
+	     */
+	    xmlDocPtr doc = xmlNewDoc (BAD_CAST "1.0");
+	    r_inputs = NULL;
+	    r_inputs = getMap (request_inputs, "version");
+	    map* version=getMapFromMaps(m,"main","rversion");
+	    int vid=getVersionId(version->value);
+	    xmlNodePtr n = printWPSHeader(doc,m,"DescribeProcess",
+					  root_nodes[vid][1],(r_inputs!=NULL?r_inputs->value:"1.0.0"),1);
+
+	    r_inputs = getMap (request_inputs, "Identifier");
+
+	    char *orig = zStrdup (r_inputs->value);
+
+	    int saved_stdout = dup (fileno (stdout));
+	    dup2 (fileno (stderr), fileno (stdout));
+	    if (strcasecmp ("all", orig) == 0)
+	      {
+		if (int res =
+		    recursReaddirF (m, zooRegistry, n, conf_dir, NULL, saved_stdout, 0,
+				    printDescribeProcessForProcess) < 0)
+		  return res;
+	      }
+	    else
+	      {
+		char *saveptr;
+		char *tmps = strtok_r (orig, ",", &saveptr);
+
+		char buff[256];
+		char buff1[1024];
+		while (tmps != NULL)
+		  {
+		    int hasVal = -1;
+		    char *corig = zStrdup (tmps);
+		    if (strstr (corig, ".") != NULL)
+		      {
+
+			parseIdentifier (m, conf_dir, corig, buff1);
+			map *tmpMap = getMapFromMaps (m, "lenv", "metapath");
+			if (tmpMap != NULL)
+			  addToMap (request_inputs, "metapath", tmpMap->value);
+			map *tmpMapI = getMapFromMaps (m, "lenv", "Identifier");
+
+			s1 = (service *) malloc (SERVICE_SIZE);
+			t = readServiceFile (m, buff1, &s1, tmpMapI->value);
+			if (t < 0)
+			  {
+			    map *tmp00 = getMapFromMaps (m, "lenv", "message");
+			    char tmp01[1024];
+			    if (tmp00 != NULL)
+			      sprintf (tmp01,
+				       _
+				       ("Unable to parse the ZCFG file for the following ZOO-Service: %s. Message: %s"),
+				       tmps, tmp00->value);
+			    else
+			      sprintf (tmp01,
+				       _
+				       ("Unable to parse the ZCFG file for the following ZOO-Service: %s."),
+				       tmps);
+			    dup2 (saved_stdout, fileno (stdout));
+			    errorException (m, tmp01, "InvalidParameterValue",
+					    "identifier");
+			    freeMaps (&m);
+			    free (m);
+			    if(zooRegistry!=NULL){
+			      freeRegistry(&zooRegistry);
+			      free(zooRegistry);
+			    }
+			    free (REQUEST);
+			    free (corig);
+			    free (orig);
+			    free (SERVICE_URL);
+			    free (s1);
+			    closedir (dirp);
+			    xmlFreeDoc (doc);
+			    xmlCleanupParser ();
+			    zooXmlCleanupNs ();
+			    return 1;
 			  }
-                          free (REQUEST);
-                          free (corig);
-                          free (orig);
-                          free (SERVICE_URL);
-                          free (s1);
-                          closedir (dirp);
-                          xmlFreeDoc (doc);
-                          xmlCleanupParser ();
-                          zooXmlCleanupNs ();
-                          return 1;
-                        }
-#ifdef DEBUG
-                      dumpService (s1);
-#endif
-		      inheritance(zooRegistry,&s1);
-                      printDescribeProcessForProcess (m, n, s1);
-                      freeService (&s1);
-                      free (s1);
-                      s1 = NULL;
-                      scount++;
-                      hasVal = 1;
-                      setMapInMaps (m, "lenv", "level", "0");
-                    }
-                  else
-                    {
-                      memset (buff, 0, 256);
-                      snprintf (buff, 256, "%s.zcfg", corig);
-                      memset (buff1, 0, 1024);
-#ifdef DEBUG
-                      printf ("\n#######%s\n########\n", buff);
-#endif
-                      while ((dp = readdir (dirp)) != NULL)
-                        {
-                          if (strcasecmp (dp->d_name, buff) == 0)
-                            {
-                              memset (buff1, 0, 1024);
-                              snprintf (buff1, 1024, "%s/%s", conf_dir,
-                                        dp->d_name);
-                              s1 = (service *) malloc (SERVICE_SIZE);
-                              if (s1 == NULL)
-                                {
-                                  dup2 (saved_stdout, fileno (stdout));
-                                  return errorException (m,
-                                                         _
-                                                         ("Unable to allocate memory."),
-                                                         "InternalError",
-                                                         NULL);
-                                }
-#ifdef DEBUG
-                              printf
-                                ("#################\n(%s) %s\n#################\n",
-                                 r_inputs->value, buff1);
-#endif
-                              char *tmp0 = zStrdup (dp->d_name);
-                              tmp0[strlen (tmp0) - 5] = 0;
-                              t = readServiceFile (m, buff1, &s1, tmp0);
-                              free (tmp0);
-                              if (t < 0)
-                                {
-                                  map *tmp00 =
-                                    getMapFromMaps (m, "lenv", "message");
-                                  char tmp01[1024];
-                                  if (tmp00 != NULL)
-                                    sprintf (tmp01,
-                                             _
-                                             ("Unable to parse the ZCFG file: %s (%s)"),
-                                             dp->d_name, tmp00->value);
-                                  else
-                                    sprintf (tmp01,
-                                             _
-                                             ("Unable to parse the ZCFG file: %s."),
-                                             dp->d_name);
-                                  dup2 (saved_stdout, fileno (stdout));
-                                  errorException (m, tmp01, "InternalError",
-                                                  NULL);
-                                  freeMaps (&m);
-                                  free (m);
-				  if(zooRegistry!=NULL){
-				    freeRegistry(&zooRegistry);
-				    free(zooRegistry);
+#ifdef DEBUG
+			dumpService (s1);
+#endif
+			inheritance(zooRegistry,&s1);
+			printDescribeProcessForProcess (m, n, s1);
+			freeService (&s1);
+			free (s1);
+			s1 = NULL;
+			scount++;
+			hasVal = 1;
+			setMapInMaps (m, "lenv", "level", "0");
+		      }
+		    else
+		      {
+			memset (buff, 0, 256);
+			snprintf (buff, 256, "%s.zcfg", corig);
+			memset (buff1, 0, 1024);
+#ifdef DEBUG
+			printf ("\n#######%s\n########\n", buff);
+#endif
+			while ((dp = readdir (dirp)) != NULL)
+			  {
+			    if (strcasecmp (dp->d_name, buff) == 0)
+			      {
+				memset (buff1, 0, 1024);
+				snprintf (buff1, 1024, "%s/%s", conf_dir,
+					  dp->d_name);
+				s1 = (service *) malloc (SERVICE_SIZE);
+				if (s1 == NULL)
+				  {
+				    dup2 (saved_stdout, fileno (stdout));
+				    return errorException (m,
+							   _
+							   ("Unable to allocate memory."),
+							   "InternalError",
+							   NULL);
 				  }
-                                  free (orig);
-                                  free (REQUEST);
-                                  closedir (dirp);
-                                  xmlFreeDoc (doc);
-                                  xmlCleanupParser ();
-                                  zooXmlCleanupNs ();
-                                  return 1;
-                                }
-#ifdef DEBUG
-                              dumpService (s1);
-#endif
-			      inheritance(zooRegistry,&s1);
-                              printDescribeProcessForProcess (m, n, s1);
-                              freeService (&s1);
-                              free (s1);
-                              s1 = NULL;
-                              scount++;
-                              hasVal = 1;
-                            }
-                        }
-                    }
-                  if (hasVal < 0)
-                    {
-                      map *tmp00 = getMapFromMaps (m, "lenv", "message");
-                      char tmp01[1024];
-                      if (tmp00 != NULL)
-                        sprintf (tmp01,
-                                 _("Unable to parse the ZCFG file: %s (%s)"),
-                                 buff, tmp00->value);
-                      else
-                        sprintf (tmp01,
-                                 _("Unable to parse the ZCFG file: %s."),
-                                 buff);
-                      dup2 (saved_stdout, fileno (stdout));
-                      errorException (m, tmp01, "InvalidParameterValue",
-                                      "Identifier");
-                      freeMaps (&m);
-                      free (m);
-		      if(zooRegistry!=NULL){
-			freeRegistry(&zooRegistry);
-			free(zooRegistry);
+#ifdef DEBUG
+				printf
+				  ("#################\n(%s) %s\n#################\n",
+				   r_inputs->value, buff1);
+#endif
+				char *tmp0 = zStrdup (dp->d_name);
+				tmp0[strlen (tmp0) - 5] = 0;
+				t = readServiceFile (m, buff1, &s1, tmp0);
+				free (tmp0);
+				if (t < 0)
+				  {
+				    map *tmp00 =
+				      getMapFromMaps (m, "lenv", "message");
+				    char tmp01[1024];
+				    if (tmp00 != NULL)
+				      sprintf (tmp01,
+					       _
+					       ("Unable to parse the ZCFG file: %s (%s)"),
+					       dp->d_name, tmp00->value);
+				    else
+				      sprintf (tmp01,
+					       _
+					       ("Unable to parse the ZCFG file: %s."),
+					       dp->d_name);
+				    dup2 (saved_stdout, fileno (stdout));
+				    errorException (m, tmp01, "InternalError",
+						    NULL);
+				    freeMaps (&m);
+				    free (m);
+				    if(zooRegistry!=NULL){
+				      freeRegistry(&zooRegistry);
+				      free(zooRegistry);
+				    }
+				    free (orig);
+				    free (REQUEST);
+				    closedir (dirp);
+				    xmlFreeDoc (doc);
+				    xmlCleanupParser ();
+				    zooXmlCleanupNs ();
+				    return 1;
+				  }
+#ifdef DEBUG
+				dumpService (s1);
+#endif
+				inheritance(zooRegistry,&s1);
+				printDescribeProcessForProcess (m, n, s1);
+				freeService (&s1);
+				free (s1);
+				s1 = NULL;
+				scount++;
+				hasVal = 1;
+			      }
+			  }
 		      }
-                      free (orig);
-                      free (REQUEST);
-                      closedir (dirp);
-                      xmlFreeDoc (doc);
-                      xmlCleanupParser ();
-                      zooXmlCleanupNs ();
-                      return 1;
-                    }
-                  rewinddir (dirp);
-                  tmps = strtok_r (NULL, ",", &saveptr);
-                  if (corig != NULL)
-                    free (corig);
-                }
-            }
-          closedir (dirp);
-          fflush (stdout);
-          dup2 (saved_stdout, fileno (stdout));
-          free (orig);
-          printDocument (m, doc, getpid ());
-          freeMaps (&m);
-          free (m);
-	  if(zooRegistry!=NULL){
-	    freeRegistry(&zooRegistry);
-	    free(zooRegistry);
+		    if (hasVal < 0)
+		      {
+			map *tmp00 = getMapFromMaps (m, "lenv", "message");
+			char tmp01[1024];
+			if (tmp00 != NULL)
+			  sprintf (tmp01,
+				   _("Unable to parse the ZCFG file: %s (%s)"),
+				   buff, tmp00->value);
+			else
+			  sprintf (tmp01,
+				   _("Unable to parse the ZCFG file: %s."),
+				   buff);
+			dup2 (saved_stdout, fileno (stdout));
+			errorException (m, tmp01, "InvalidParameterValue",
+					"Identifier");
+			freeMaps (&m);
+			free (m);
+			if(zooRegistry!=NULL){
+			  freeRegistry(&zooRegistry);
+			  free(zooRegistry);
+			}
+			free (orig);
+			free (REQUEST);
+			closedir (dirp);
+			xmlFreeDoc (doc);
+			xmlCleanupParser ();
+			zooXmlCleanupNs ();
+			return 1;
+		      }
+		    rewinddir (dirp);
+		    tmps = strtok_r (NULL, ",", &saveptr);
+		    if (corig != NULL)
+		      free (corig);
+		  }
+	      }
+	    closedir (dirp);
+	    fflush (stdout);
+	    dup2 (saved_stdout, fileno (stdout));
+	    free (orig);
+	    printDocument (m, doc, getpid ());
+	    freeMaps (&m);
+	    free (m);
+	    if(zooRegistry!=NULL){
+	      freeRegistry(&zooRegistry);
+	      free(zooRegistry);
+	    }
+	    free (REQUEST);
+	    free (SERVICE_URL);
+	    fflush (stdout);
+	    return 0;
 	  }
-          free (REQUEST);
-          free (SERVICE_URL);
-          fflush (stdout);
-          return 0;
-        }
-      else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
-        {
-          errorException (m,
-                          _
-                          ("The <request> value was not recognized. Allowed values are GetCapabilities, DescribeProcess, and Execute."),
-                          "InvalidParameterValue", "request");
-#ifdef DEBUG
-          fprintf (stderr, "No request found %s", REQUEST);
-#endif
-          closedir (dirp);
-          freeMaps (&m);
-          free (m);
-	  if(zooRegistry!=NULL){
-	    freeRegistry(&zooRegistry);
-	    free(zooRegistry);
+	else if (strncasecmp (REQUEST, "Execute", strlen (REQUEST)) != 0)
+	  {
+	    map* version=getMapFromMaps(m,"main","rversion");
+	    int vid=getVersionId(version->value);
+	    int len,j=0;
+	    for(j=0;j<nbSupportedRequests;j++){
+	      if(requests[vid][j]!=NULL)
+		len+=strlen(requests[vid][j])+2;
+	      else{
+		len+=4;
+		break;
+	      }
+	    }
+	    char *tmpStr=(char*)malloc(len*sizeof(char));
+	    int it=0;
+	    for(j=0;j<nbSupportedRequests;j++){
+	      if(requests[vid][j]!=NULL){
+		if(it==0){
+		  sprintf(tmpStr,"%s",requests[vid][j]);
+		  it++;
+		}else{
+		  char *tmpS=zStrdup(tmpStr);
+		  if(j+1<nbSupportedRequests && requests[vid][j+1]==NULL){
+		    sprintf(tmpStr,"%s and %s",tmpS,requests[vid][j]);
+		  }else{
+		    sprintf(tmpStr,"%s, %s",tmpS,requests[vid][j]);
+		  
+		  }
+		  free(tmpS);
+		}
+	      }
+	      else{
+		len+=4;
+		break;
+	      }
+	    }
+	    char* message=(char*)malloc((61+len)*sizeof(char));
+	    sprintf(message,"The <request> value was not recognized. Allowed values are %s.",tmpStr);
+	    errorException (m,_(message),"InvalidParameterValue", "request");
+#ifdef DEBUG
+	    fprintf (stderr, "No request found %s", REQUEST);
+#endif
+	    closedir (dirp);
+	    freeMaps (&m);
+	    free (m);
+	    if(zooRegistry!=NULL){
+	      freeRegistry(&zooRegistry);
+	      free(zooRegistry);
+	    }
+	    free (REQUEST);
+	    free (SERVICE_URL);
+	    fflush (stdout);
+	    return 0;
 	  }
-          free (REQUEST);
-          free (SERVICE_URL);
-          fflush (stdout);
-          return 0;
-        }
-      closedir (dirp);
-    }
-
+	closedir (dirp);
+      }
+    }
+
+  map *postRequest = NULL;
+  postRequest = getMap (request_inputs, "xrequest");
+
+  if(vid==1 && postRequest==NULL){
+    errorException (m,_("Unable to run Execute request using the GET HTTP method"),"InvalidParameterValue", "request");  
+    freeMaps (&m);
+    free (m);
+    if(zooRegistry!=NULL){
+      freeRegistry(&zooRegistry);
+      free(zooRegistry);
+    }
+    free (REQUEST);
+    free (SERVICE_URL);
+    fflush (stdout);
+    return 0;
+  }
+  
   s1 = NULL;
   s1 = (service *) malloc (SERVICE_SIZE);
@@ -1645,8 +1740,8 @@
   hInternet = InternetOpen (
 #ifndef WIN32
-                             (LPCTSTR)
-#endif
-                             "ZooWPSClient\0",
-                             INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+			    (LPCTSTR)
+#endif
+			    "ZooWPSClient\0",
+			    INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
 
 #ifndef WIN32
@@ -1730,36 +1825,82 @@
 #endif
 
-  // Need to check if we need to fork to load a status enabled 
-  r_inputs = NULL;
-  map *store = getMap (request_inputs, "storeExecuteResponse");
   map *status = getMap (request_inputs, "status");
-  /**
-   * 05-007r7 WPS 1.0.0 page 57 :
-   * 'If status="true" and storeExecuteResponse is "false" then the service 
-   * shall raise an exception.'
-   */
-  if (status != NULL && strcmp (status->value, "true") == 0 &&
-      store != NULL && strcmp (store->value, "false") == 0)
-    {
-      errorException (m,
-                      _
-                      ("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
-                      "InvalidParameterValue", "storeExecuteResponse");
-      freeService (&s1);
-      free (s1);
-      freeMaps (&m);
-      free (m);
-
-      freeMaps (&request_input_real_format);
-      free (request_input_real_format);
-
-      freeMaps (&request_output_real_format);
-      free (request_output_real_format);
-
-      free (REQUEST);
-      free (SERVICE_URL);
-      return 1;
-    }
-  r_inputs = getMap (request_inputs, "storeExecuteResponse");
+  if(vid==0){
+    // Need to check if we need to fork to load a status enabled 
+    r_inputs = NULL;
+    map *store = getMap (request_inputs, "storeExecuteResponse");
+    /**
+     * 05-007r7 WPS 1.0.0 page 57 :
+     * 'If status="true" and storeExecuteResponse is "false" then the service 
+     * shall raise an exception.'
+     */
+    if (status != NULL && strcmp (status->value, "true") == 0 &&
+	store != NULL && strcmp (store->value, "false") == 0)
+      {
+	errorException (m,
+			_
+			("The status parameter cannot be set to true if storeExecuteResponse is set to false. Please modify your request parameters."),
+			"InvalidParameterValue", "storeExecuteResponse");
+	freeService (&s1);
+	free (s1);
+	freeMaps (&m);
+	free (m);
+	
+	freeMaps (&request_input_real_format);
+	free (request_input_real_format);
+	
+	freeMaps (&request_output_real_format);
+	free (request_output_real_format);
+
+	free (REQUEST);
+	free (SERVICE_URL);
+	return 1;
+      }
+    r_inputs = getMap (request_inputs, "storeExecuteResponse");
+  }else{
+    // Define status depending on the WPS 2.0.0 mode attribute
+    status = getMap (request_inputs, "mode");
+    map* mode=getMap(s1->content,"mode");
+    if(strcasecmp(status->value,"async")==0){
+      if(mode!=NULL && strcasecmp(mode->value,"async")==0)
+	addToMap(request_inputs,"status","true");
+      else{
+	if(mode!=NULL){
+	  // see ref. http://docs.opengeospatial.org/is/14-065/14-065.html#61
+	  errorException (m,_("The process does not permit the desired execution mode."),"NoSuchMode", mode->value);  
+	  fflush (stdout);
+	  freeMaps (&m);
+	  free (m);
+	  if(zooRegistry!=NULL){
+	    freeRegistry(&zooRegistry);
+	    free(zooRegistry);
+	  }
+	  freeMaps (&request_input_real_format);
+	  free (request_input_real_format);
+	  freeMaps (&request_output_real_format);
+	  free (request_output_real_format);
+	  free (REQUEST);
+	  free (SERVICE_URL);
+	  return 0;
+	}else
+	  addToMap(request_inputs,"status","true");
+      }
+    }
+    else{
+      if(strcasecmp(status->value,"auto")==0){
+	if(mode!=NULL){
+	  if(strcasecmp(mode->value,"async")==0)
+	    addToMap(request_inputs,"status","false");
+	  else
+	    addToMap(request_inputs,"status","true");
+	}
+	else
+	  addToMap(request_inputs,"status","false");
+      }else
+	addToMap(request_inputs,"status","false");
+    }
+    status = getMap (request_inputs, "status");
+  }
+
   int eres = SERVICE_STARTED;
   int cpid = getpid ();
@@ -1808,4 +1949,6 @@
   else
     addToMap (_tmpMaps->content, "soap", "false");
+
+  // Parse the session file and add it to the main maps 
   if (cgiCookie != NULL && strlen (cgiCookie) > 0)
     {
@@ -1883,5 +2026,5 @@
   freeMaps (&_tmpMaps);
   free (_tmpMaps);
-
+  maps* bmap=NULL;
 #ifdef DEBUG
   dumpMap (request_inputs);
@@ -1907,5 +2050,5 @@
     }
 #endif
-  char *fbkp, *fbkpid, *fbkp1, *flog;
+  char *fbkp, *fbkpid, *fbkpres, *fbkp1, *flog;
   FILE *f0, *f1;
   if (status != NULL)
@@ -1958,8 +2101,8 @@
       if (pid > 0)
         {
-      /**
-       * dady :
-       * set status to SERVICE_ACCEPTED
-       */
+	  /**
+	   * dady :
+	   * set status to SERVICE_ACCEPTED
+	   */
 #ifdef DEBUG
           fprintf (stderr, "father pid continue (origin %d) %d ...\n", cpid,
@@ -1975,9 +2118,22 @@
 	   */
 	  map* usid = getMapFromMaps (m, "lenv", "uusid");
-          r_inputs = getMapFromMaps (m, "lenv", "osid");
-          int cpid = atoi (r_inputs->value);
+          map* tmpm = getMapFromMaps (m, "lenv", "osid");
+          int cpid = atoi (tmpm->value);
           r_inputs = getMapFromMaps (m, "main", "tmpPath");
 	  map* r_inputs1 = createMap("ServiceName", s1->name);
 
+	  // Create the filename for the result file (.res)
+          fbkpres =
+            (char *)
+            malloc ((strlen (r_inputs->value) +
+                     strlen (usid->value) + 7) * sizeof (char));
+          sprintf (fbkpres, "%s/%s.res", r_inputs->value, usid->value);
+	  bmap = (maps *) malloc (MAPS_SIZE);
+	  bmap->name=zStrdup("status");
+	  bmap->content=createMap("usid",usid->value);
+	  bmap->next=NULL;
+	  addToMap(bmap->content,"sid",tmpm->value);
+	  addIntToMap(bmap->content,"pid",getpid());
+	  
 	  // Create PID file referencing the OS process identifier
           fbkpid =
@@ -1999,5 +2155,4 @@
 
           FILE* f2 = fopen (fbkp, "w+");
-	  map* tmpm=getMapFromMaps (m, "lenv", "osid");
 	  fprintf(f2,"%s",tmpm->value);
 	  fflush(f2);
@@ -2025,26 +2180,32 @@
           freopen (flog, "w+", stderr);
           fflush (stderr);
-          f0 = freopen (fbkp, "w+", stdout);
-          rewind (stdout);
+	  f0 = freopen (fbkp, "w+", stdout);
+	  rewind (stdout);
 #ifndef WIN32
-          fclose (stdin);
-#endif
-
-	  /**
-	   * set status to SERVICE_STARTED and flush stdout to ensure full 
-	   * content was outputed (the file used to store the ResponseDocument).
-	   * The rewind stdout to restart writing from the bgining of the file,
-	   * this way the data will be updated at the end of the process run.
-	   */
-          printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
-                                SERVICE_STARTED, request_input_real_format,
-                                request_output_real_format);
-          fflush (stdout);
+	  fclose (stdin);
+#endif
+
 #ifdef RELY_ON_DB
 	  init_sql(m);
 	  recordServiceStatus(m);
-	  recordResponse(m,fbkp);
-#endif
+#endif
+	  if(vid==0){
+	    /**
+	     * set status to SERVICE_STARTED and flush stdout to ensure full 
+	     * content was outputed (the file used to store the ResponseDocument).
+	     * The rewind stdout to restart writing from the bgining of the file,
+	     * this way the data will be updated at the end of the process run.
+	     */
+	    printProcessResponse (m, request_inputs, cpid, s1, r_inputs1->value,
+				  SERVICE_STARTED, request_input_real_format,
+				  request_output_real_format);
+	    fflush (stdout);
+#ifdef RELY_ON_DB
+	    recordResponse(m,fbkp);
+#endif
+	  }
+
           fflush (stderr);
+
           fbkp1 =
             (char *)
@@ -2116,5 +2277,5 @@
     {
       fclose (stdout);
-      fclose (stderr);
+      //fclose (stderr);
       /**
        * Dump back the final file fbkp1 to fbkp
@@ -2122,4 +2283,5 @@
       fclose (f0);
       fclose (f1);
+
       FILE *f2 = fopen (fbkp1, "rb");
 #ifndef RELY_ON_DB
@@ -2129,4 +2291,5 @@
       lockShm (lid);
 #endif
+      fclose(f0);
       FILE *f3 = fopen (fbkp, "wb+");
       free (fbkp);
@@ -2140,13 +2303,28 @@
       fclose (f3);
       unlink (fbkpid);
+      switch(eres){
+      default:
+      case SERVICE_FAILED:
+	setMapInMaps(bmap,"status","status",wpsStatus[1]);
+	setMapInMaps(m,"lenv","fstate",wpsStatus[1]);
+	break;
+      case SERVICE_SUCCEEDED:
+	setMapInMaps(bmap,"status","status",wpsStatus[0]);
+	setMapInMaps(m,"lenv","fstate",wpsStatus[0]);
+	break;
+      }
 #ifndef RELY_ON_DB
+      dumpMapsToFile(bmap,fbkpres);
       removeShmLock (m, 1);
 #else
       recordResponse(m,fbkp1);
 #endif
+      freeMaps(&bmap);
+      free(bmap);
       unlink (fbkp1);
       unlink (flog);
       unhandleStatus (m);
       free(fbkpid);
+      free(fbkpres);
       free (flog);
       free (fbkp1);
