Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 652)
+++ 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);
