Index: trunk/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 620)
+++ trunk/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 621)
@@ -54,4 +54,5 @@
 
 #include "service_internal.h"
+#include "request_parser.h"
 
 #ifdef USE_PYTHON
@@ -179,90 +180,4 @@
 }
 
-/**
- * Create (or append to) an array valued maps value = "["",""]"
- *
- * @param m the conf maps containing the main.cfg settings
- * @param mo the map to update
- * @param mi the map to append
- * @param elem the elements containing default definitions
- * @return 0 on success, -1 on failure
- */
-int
-appendMapsToMaps (maps * m, maps * mo, maps * mi, elements * elem)
-{
-  maps *tmpMaps = getMaps (mo, mi->name);
-  map *tmap = getMapType (tmpMaps->content);
-  elements *el = getElements (elem, mi->name);
-  int hasEl = 1;
-  if (el == NULL)
-    hasEl = -1;
-  if (tmap == NULL)
-    {
-      if (hasEl > 0)
-        tmap = getMapType (el->defaults->content);
-    }
-
-  map *testMap = NULL;
-  if (hasEl > 0)
-    {
-      testMap = getMap (el->content, "maxOccurs");
-    }
-  else
-    {
-      testMap = createMap ("maxOccurs", "unbounded");
-    }
-
-  if (testMap != NULL)
-    {
-      if (strncasecmp (testMap->value, "unbounded", 9) != 0
-          && atoi (testMap->value) > 1)
-        {
-	  addMapsArrayToMaps (&mo, mi, tmap->name);
-	  map* nb=getMapFromMaps(mo,mi->name,"length");
-          if (nb!=NULL && atoi(nb->value)>atoi(testMap->value))
-            {
-              char emsg[1024];
-              sprintf (emsg,
-                       _("The maximum allowed occurrences for <%s> (%i) was exceeded."),
-                       mi->name, atoi (testMap->value));
-              errorException (m, emsg, "InternalError", NULL);
-              return -1;
-            }
-        }
-      else
-        {
-          if (strncasecmp (testMap->value, "unbounded", 9) == 0)
-            {
-              if (hasEl < 0)
-                {
-                  freeMap (&testMap);
-                  free (testMap);
-                }
-              if (addMapsArrayToMaps (&mo, mi, tmap->name) < 0)
-                {
-                  char emsg[1024];
-                  map *tmpMap = getMap (mi->content, "length");
-                  sprintf (emsg,
-                           _
-                           ("ZOO-Kernel was unable to load your data for %s position %s."),
-                           mi->name, tmpMap->value);
-                  errorException (m, emsg, "InternalError", NULL);
-                  return -1;
-                }
-            }
-          else
-            {
-              char emsg[1024];
-              sprintf (emsg,
-                       _
-                       ("The maximum allowed occurrences for <%s> is one."),
-                       mi->name);
-              errorException (m, emsg, "InternalError", NULL);
-              return -1;
-            }
-        }
-    }
-  return 0;
-}
 
 /**
@@ -495,22 +410,4 @@
   (void) closedir (dirp);
   return 1;
-}
-
-/**
- * Apply XPath Expression on XML document.
- *
- * @param doc the XML Document
- * @param search the XPath expression
- * @return xmlXPathObjectPtr containing the resulting nodes set
- */
-xmlXPathObjectPtr
-extractFromDoc (xmlDocPtr doc, const char *search)
-{
-  xmlXPathContextPtr xpathCtx;
-  xmlXPathObjectPtr xpathObj;
-  xpathCtx = xmlXPathNewContext (doc);
-  xpathObj = xmlXPathEvalExpression (BAD_CAST search, xpathCtx);
-  xmlXPathFreeContext (xpathCtx);
-  return xpathObj;
 }
 
@@ -1722,1527 +1619,16 @@
   maps *request_input_real_format = NULL;
   maps *tmpmaps = request_input_real_format;
-  map *postRequest = NULL;
-  postRequest = getMap (request_inputs, "xrequest");
-  if (postRequest == NULLMAP)
-    {
-    /**
-     * Parsing outputs provided as KVP
-     */
-      r_inputs = NULL;
-#ifdef DEBUG
-      fprintf (stderr, "OUTPUT Parsing ... \n");
-#endif
-      r_inputs = getMap (request_inputs, "ResponseDocument");
-      if (r_inputs == NULL)
-        r_inputs = getMap (request_inputs, "RawDataOutput");
-
-#ifdef DEBUG
-      fprintf (stderr, "OUTPUT Parsing ... \n");
-#endif
-      if (r_inputs != NULL)
-        {
-#ifdef DEBUG
-          fprintf (stderr, "OUTPUT Parsing start now ... \n");
-#endif
-          char cursor_output[10240];
-          char *cotmp = zStrdup (r_inputs->value);
-          snprintf (cursor_output, 10240, "%s", cotmp);
-          free (cotmp);
-          j = 0;
-
-      /**
-       * Put each Output into the outputs_as_text array
-       */
-          char *pToken;
-          maps *tmp_output = NULL;
-#ifdef DEBUG
-          fprintf (stderr, "OUTPUT [%s]\n", cursor_output);
-#endif
-          pToken = strtok (cursor_output, ";");
-          char **outputs_as_text = (char **) malloc (128 * sizeof (char *));
-          if (outputs_as_text == NULL)
-            {
-              return errorException (m, _("Unable to allocate memory"),
-                                     "InternalError", NULL);
-            }
-          i = 0;
-          while (pToken != NULL)
-            {
-#ifdef DEBUG
-              fprintf (stderr, "***%s***\n", pToken);
-              fflush (stderr);
-              fprintf (stderr, "***%s***\n", pToken);
-#endif
-              outputs_as_text[i] =
-                (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
-              if (outputs_as_text[i] == NULL)
-                {
-                  return errorException (m, _("Unable to allocate memory"),
-                                         "InternalError", NULL);
-                }
-              snprintf (outputs_as_text[i], strlen (pToken) + 1, "%s",
-                        pToken);
-              pToken = strtok (NULL, ";");
-              i++;
-            }
-          for (j = 0; j < i; j++)
-            {
-              char *tmp = zStrdup (outputs_as_text[j]);
-              free (outputs_as_text[j]);
-              char *tmpc;
-              tmpc = strtok (tmp, "@");
-              int k = 0;
-              while (tmpc != NULL)
-                {
-                  if (k == 0)
-                    {
-                      if (tmp_output == NULL)
-                        {
-                          tmp_output = (maps *) malloc (MAPS_SIZE);
-                          if (tmp_output == NULL)
-                            {
-                              return errorException (m,
-                                                     _
-                                                     ("Unable to allocate memory."),
-                                                     "InternalError", NULL);
-                            }
-                          tmp_output->name = zStrdup (tmpc);
-                          tmp_output->content = NULL;
-                          tmp_output->next = NULL;
-                        }
-                    }
-                  else
-                    {
-                      char *tmpv = strstr (tmpc, "=");
-                      char tmpn[256];
-                      memset (tmpn, 0, 256);
-                      strncpy (tmpn, tmpc,
-                               (strlen (tmpc) -
-                                strlen (tmpv)) * sizeof (char));
-                      tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
-#ifdef DEBUG
-                      fprintf (stderr, "OUTPUT DEF [%s]=[%s]\n", tmpn,
-                               tmpv + 1);
-#endif
-                      if (tmp_output->content == NULL)
-                        {
-                          tmp_output->content = createMap (tmpn, tmpv + 1);
-                          tmp_output->content->next = NULL;
-                        }
-                      else
-                        addToMap (tmp_output->content, tmpn, tmpv + 1);
-                    }
-                  k++;
-#ifdef DEBUG
-                  fprintf (stderr, "***%s***\n", tmpc);
-#endif
-                  tmpc = strtok (NULL, "@");
-                }
-              if (request_output_real_format == NULL)
-                request_output_real_format = dupMaps (&tmp_output);
-              else
-                addMapsToMaps (&request_output_real_format, tmp_output);
-              freeMaps (&tmp_output);
-              free (tmp_output);
-              tmp_output = NULL;
-#ifdef DEBUG
-              dumpMaps (tmp_output);
-              fflush (stderr);
-#endif
-              free (tmp);
-            }
-          free (outputs_as_text);
-        }
-
-
-    /**
-     * Parsing inputs provided as KVP
-     */
-      r_inputs = getMap (request_inputs, "DataInputs");
-#ifdef DEBUG
-      fprintf (stderr, "DATA INPUTS [%s]\n", r_inputs->value);
-#endif
-      char cursor_input[40960];
-      if (r_inputs != NULL){
-        snprintf (cursor_input, 40960, "%s", r_inputs->value);
-	j = 0;
-
-	/**
-	 * Put each DataInputs into the inputs_as_text array
-	 */
-	char *tmp1 = zStrdup (cursor_input);
-	char *pToken;
-	pToken = strtok (cursor_input, ";");
-	if (pToken != NULL && strncasecmp (pToken, tmp1, strlen (tmp1)) == 0)
-	  {
-	    char *tmp2 = url_decode (tmp1);
-	    snprintf (cursor_input, (strlen (tmp2) + 1) * sizeof (char), "%s",
-		      tmp2);
-	    free (tmp2);
-	    pToken = strtok (cursor_input, ";");
-	  }
-	free (tmp1);
-	
-	char **inputs_as_text = (char **) malloc (100 * sizeof (char *));
-	if (inputs_as_text == NULL)
-	  {
-	    return errorException (m, _("Unable to allocate memory."),
-				   "InternalError", NULL);
-	  }
-	i = 0;
-	while (pToken != NULL)
-	  {
-#ifdef DEBUG
-	    fprintf (stderr, "***%s***\n", pToken);
-	    fflush (stderr);
-	    fprintf (stderr, "***%s***\n", pToken);
-#endif
-	    inputs_as_text[i] =
-	      (char *) malloc ((strlen (pToken) + 1) * sizeof (char));
-	    if (inputs_as_text[i] == NULL)
-	      {
-		return errorException (m, _("Unable to allocate memory."),
-				       "InternalError", NULL);
-	      }
-	    snprintf (inputs_as_text[i], strlen (pToken) + 1, "%s", pToken);
-	    pToken = strtok (NULL, ";");
-	    i++;
-	  }
-	
-	for (j = 0; j < i; j++)
-	  {
-	    char *tmp = zStrdup (inputs_as_text[j]);
-	    free (inputs_as_text[j]);
-	    char *tmpc;
-	    tmpc = strtok (tmp, "@");
-	    while (tmpc != NULL)
-	      {
-#ifdef DEBUG
-		fprintf (stderr, "***\n***%s***\n", tmpc);
-#endif
-		char *tmpv = strstr (tmpc, "=");
-		char tmpn[256];
-		memset (tmpn, 0, 256);
-		if (tmpv != NULL)
-		  {
-		    strncpy (tmpn, tmpc,
-			     (strlen (tmpc) - strlen (tmpv)) * sizeof (char));
-		    tmpn[strlen (tmpc) - strlen (tmpv)] = 0;
-		  }
-		else
-		  {
-		    strncpy (tmpn, tmpc, strlen (tmpc) * sizeof (char));
-		    tmpn[strlen (tmpc)] = 0;
-		  }
-#ifdef DEBUG
-		fprintf (stderr, "***\n*** %s = %s ***\n", tmpn, tmpv + 1);
-#endif
-		if (tmpmaps == NULL)
-		  {
-		    tmpmaps = (maps *) malloc (MAPS_SIZE);
-		    if (tmpmaps == NULL)
-		      {
-			return errorException (m,
-					       _("Unable to allocate memory."),
-					       "InternalError", NULL);
-		      }
-		    tmpmaps->name = zStrdup (tmpn);
-		    if (tmpv != NULL)
-		      {
-			char *tmpvf = url_decode (tmpv + 1);
-			tmpmaps->content = createMap ("value", tmpvf);
-			free (tmpvf);
-		      }
-		    else
-		      tmpmaps->content = createMap ("value", "Reference");
-		    tmpmaps->next = NULL;
-		  }
-		tmpc = strtok (NULL, "@");
-		while (tmpc != NULL)
-		  {
-#ifdef DEBUG
-		    fprintf (stderr, "*** KVP NON URL-ENCODED \n***%s***\n",
-			     tmpc);
-#endif
-		    char *tmpv1 = strstr (tmpc, "=");
-#ifdef DEBUG
-		    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
-			     tmpv1 + 1);
-#endif
-		    char tmpn1[1024];
-		    memset (tmpn1, 0, 1024);
-		    if (tmpv1 != NULL)
-		      {
-			strncpy (tmpn1, tmpc, strlen (tmpc) - strlen (tmpv1));
-			tmpn1[strlen (tmpc) - strlen (tmpv1)] = 0;
-			addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
-		      }
-		    else
-		      {
-			strncpy (tmpn1, tmpc, strlen (tmpc));
-			tmpn1[strlen (tmpc)] = 0;
-			map *lmap = getLastMap (tmpmaps->content);
-			char *tmpValue =
-			  (char *) malloc ((strlen (tmpv) + strlen (tmpc) + 1) *
-					   sizeof (char));
-			sprintf (tmpValue, "%s@%s", tmpv + 1, tmpc);
-			free (lmap->value);
-			lmap->value = zStrdup (tmpValue);
-			free (tmpValue);
-			tmpc = strtok (NULL, "@");
-			continue;
-		      }
-#ifdef DEBUG
-		    fprintf (stderr, "*** NAME NON URL-ENCODED \n***%s***\n",
-			     tmpn1);
-		    fprintf (stderr, "*** VALUE NON URL-ENCODED \n***%s***\n",
-			     tmpv1 + 1);
-#endif
-		    if (strcmp (tmpn1, "xlink:href") != 0)
-		      addToMap (tmpmaps->content, tmpn1, tmpv1 + 1);
-		    else if (tmpv1 != NULL)
-		      {
-			char *tmpx2 = url_decode (tmpv1 + 1);
-			if (strncasecmp (tmpx2, "http://", 7) != 0 &&
-			    strncasecmp (tmpx2, "ftp://", 6) != 0 &&
-			    strncasecmp (tmpx2, "https://", 8) != 0)
-			  {
-			    char emsg[1024];
-			    sprintf (emsg,
-				     _
-				     ("Unable to find a valid protocol to download the remote file %s"),
-				     tmpv1 + 1);
-			    errorException (m, emsg, "InternalError", NULL);
-			    freeMaps (&m);
-			    free (m);
-			    free (REQUEST);
-			    free (SERVICE_URL);
-			    InternetCloseHandle (&hInternet);
-			    freeService (&s1);
-			    free (s1);
-			    return 0;
-			  }
-#ifdef DEBUG
-			fprintf (stderr,
-				 "REQUIRE TO DOWNLOAD A FILE FROM A SERVER : url(%s)\n",
-				 tmpv1 + 1);
-#endif
-			addToMap (tmpmaps->content, tmpn1, tmpx2);
-#ifndef WIN32
-			if (CHECK_INET_HANDLE (hInternet))
-#endif
-			  {
-			    if (loadRemoteFile
-				(&m, &tmpmaps->content, &hInternet, tmpx2) < 0)
-			      {
-				freeMaps (&m);
-				free (m);
-				free (REQUEST);
-				free (SERVICE_URL);
-				InternetCloseHandle (&hInternet);
-				freeService (&s1);
-				free (s1);
-				return 0;
-			      }
-			  }
-			free (tmpx2);
-			addToMap (tmpmaps->content, "Reference", tmpv1 + 1);
-		      }
-		    tmpc = strtok (NULL, "@");
-		  }
-#ifdef DEBUG
-		dumpMaps (tmpmaps);
-		fflush (stderr);
-#endif
-		if (request_input_real_format == NULL)
-		  request_input_real_format = dupMaps (&tmpmaps);
-		else
-		  {
-		    maps *testPresence =
-		      getMaps (request_input_real_format, tmpmaps->name);
-		    if (testPresence != NULL)
-		      {
-			elements *elem =
-			  getElements (s1->inputs, tmpmaps->name);
-			if (elem != NULL)
-			  {
-			    if (appendMapsToMaps
-				(m, request_input_real_format, tmpmaps,
-				 elem) < 0)
-			      {
-				freeMaps (&m);
-				free (m);
-				free (REQUEST);
-				free (SERVICE_URL);
-				InternetCloseHandle (&hInternet);
-				freeService (&s1);
-				free (s1);
-				return 0;
-			      }
-			  }
-		      }
-		    else
-		      addMapsToMaps (&request_input_real_format, tmpmaps);
-		  }
-		freeMaps (&tmpmaps);
-		free (tmpmaps);
-		tmpmaps = NULL;
-		free (tmp);
-	      }
-	  }
-	free (inputs_as_text);
-      }
-    }
-  else
-    {
-    /**
-     * Parse XML request
-     */
-      xmlInitParser ();
-#ifdef DEBUG
-      fflush (stderr);
-      fprintf (stderr, "BEFORE %s\n", postRequest->value);
-      fflush (stderr);
-#endif
-      xmlDocPtr doc = xmlParseMemory (postRequest->value, cgiContentLength);
-#ifdef DEBUG
-      fprintf (stderr, "AFTER\n");
-      fflush (stderr);
-#endif
-
-    /**
-     * Parse every Input in DataInputs node.
-     */
-      xmlXPathObjectPtr tmpsptr =
-        extractFromDoc (doc, "/*/*/*[local-name()='Input']");
-      xmlNodeSet *tmps = tmpsptr->nodesetval;
-#ifdef DEBUG
-      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
-#endif
-      for (int k = 0; k < tmps->nodeNr; k++)
-        {
-          maps *tmpmaps = NULL;
-          xmlNodePtr cur = tmps->nodeTab[k];
-          if (tmps->nodeTab[k]->type == XML_ELEMENT_NODE)
-            {
-        /**
-	 * A specific Input node.
-	 */
-#ifdef DEBUG
-              fprintf (stderr, "= element 0 node \"%s\"\n", cur->name);
-#endif
-              xmlNodePtr cur2 = cur->children;
-              while (cur2 != NULL)
-                {
-                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
-                    cur2 = cur2->next;
-                  if (cur2 == NULL)
-                    break;
-          /**
-	   * Indentifier
-	   */
-                  if (xmlStrncasecmp
-                      (cur2->name, BAD_CAST "Identifier",
-                       xmlStrlen (cur2->name)) == 0)
-                    {
-                      xmlChar *val =
-                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
-                      if (tmpmaps == NULL)
-                        {
-                          tmpmaps = (maps *) malloc (MAPS_SIZE);
-                          if (tmpmaps == NULL)
-                            {
-                              return errorException (m,
-                                                     _
-                                                     ("Unable to allocate memory."),
-                                                     "InternalError", NULL);
-                            }
-                          tmpmaps->name = zStrdup ((char *) val);
-                          tmpmaps->content = NULL;
-                          tmpmaps->next = NULL;
-                        }
-                      xmlFree (val);
-                    }
-          /**
-	   * Title, Asbtract
-	   */
-                  if (xmlStrncasecmp
-                      (cur2->name, BAD_CAST "Title",
-                       xmlStrlen (cur2->name)) == 0
-                      || xmlStrncasecmp (cur2->name, BAD_CAST "Abstract",
-                                         xmlStrlen (cur2->name)) == 0)
-                    {
-                      xmlChar *val =
-                        xmlNodeListGetString (doc, cur2->xmlChildrenNode, 1);
-                      if (tmpmaps == NULL)
-                        {
-                          tmpmaps = (maps *) malloc (MAPS_SIZE);
-                          if (tmpmaps == NULL)
-                            {
-                              return errorException (m,
-                                                     _
-                                                     ("Unable to allocate memory."),
-                                                     "InternalError", NULL);
-                            }
-                          tmpmaps->name = zStrdup ("missingIndetifier");
-                          tmpmaps->content =
-                            createMap ((char *) cur2->name, (char *) val);
-                          tmpmaps->next = NULL;
-                        }
-                      else
-                        {
-                          if (tmpmaps->content != NULL)
-                            addToMap (tmpmaps->content,
-                                      (char *) cur2->name, (char *) val);
-                          else
-                            tmpmaps->content =
-                              createMap ((char *) cur2->name, (char *) val);
-                        }
-#ifdef DEBUG
-                      dumpMaps (tmpmaps);
-#endif
-                      xmlFree (val);
-                    }
-          /**
-	   * InputDataFormChoice (Reference or Data ?) 
-	   */
-                  if (xmlStrcasecmp (cur2->name, BAD_CAST "Reference") == 0)
-                    {
-            /**
-	     * Get every attribute from a Reference node
-	     * mimeType, encoding, schema, href, method
-	     * Header and Body gesture should be added here
-	     */
-#ifdef DEBUG
-                      fprintf (stderr, "REFERENCE\n");
-#endif
-                      const char *refs[5] =
-                        { "mimeType", "encoding", "schema", "method",
-                        "href"
-                      };
-                      for (int l = 0; l < 5; l++)
-                        {
-#ifdef DEBUG
-                          fprintf (stderr, "*** %s ***", refs[l]);
-#endif
-                          xmlChar *val = xmlGetProp (cur2, BAD_CAST refs[l]);
-                          if (val != NULL && xmlStrlen (val) > 0)
-                            {
-                              if (tmpmaps->content != NULL)
-                                addToMap (tmpmaps->content, refs[l],
-                                          (char *) val);
-                              else
-                                tmpmaps->content =
-                                  createMap (refs[l], (char *) val);
-                              map *ltmp = getMap (tmpmaps->content, "method");
-                              if (l == 4)
-                                {
-                                  if (!
-                                      (ltmp != NULL
-                                       && strncmp (ltmp->value, "POST",
-                                                   4) == 0)
-                                      && CHECK_INET_HANDLE (hInternet))
-                                    {
-                                      if (loadRemoteFile
-                                          (&m, &tmpmaps->content, &hInternet,
-                                           (char *) val) != 0)
-                                        {
-                                          freeMaps (&m);
-                                          free (m);
-                                          free (REQUEST);
-                                          free (SERVICE_URL);
-                                          InternetCloseHandle (&hInternet);
-                                          freeService (&s1);
-                                          free (s1);
-                                          return 0;
-                                        }
-                                    }
-                                }
-                            }
-#ifdef DEBUG
-                          fprintf (stderr, "%s\n", val);
-#endif
-                          xmlFree (val);
-                        }
-#ifdef POST_DEBUG
-                      fprintf (stderr,
-                               "Parse Header and Body from Reference \n");
-#endif
-                      xmlNodePtr cur3 = cur2->children;
-                      /*      HINTERNET hInternetP;
-                         hInternetP=InternetOpen(
-                         #ifndef WIN32
-                         (LPCTSTR)
-                         #endif
-                         "ZooWPSClient\0",
-                         INTERNET_OPEN_TYPE_PRECONFIG,
-                         NULL,NULL, 0); */
-                      //hInternet.ihandle[hInternet.nb].header=NULL;
-                      while (cur3 != NULL)
-                        {
-                          while (cur3 != NULL
-                                 && cur3->type != XML_ELEMENT_NODE)
-                            cur3 = cur3->next;
-                          if (cur3 == NULL)
-                            break;
-                          if (xmlStrcasecmp (cur3->name, BAD_CAST "Header") ==
-                              0)
-                            {
-                              const char *ha[2];
-                              ha[0] = "key";
-                              ha[1] = "value";
-                              int hai;
-                              char *has;
-                              char *key;
-                              for (hai = 0; hai < 2; hai++)
-                                {
-                                  xmlChar *val =
-                                    xmlGetProp (cur3, BAD_CAST ha[hai]);
-#ifdef POST_DEBUG
-                                  fprintf (stderr, "%s = %s\n", ha[hai],
-                                           (char *) val);
-#endif
-                                  if (hai == 0)
-                                    {
-                                      key = zStrdup ((char *) val);
-                                    }
-                                  else
-                                    {
-                                      has =
-                                        (char *)
-                                        malloc ((4 + xmlStrlen (val) +
-                                                 strlen (key)) *
-                                                sizeof (char));
-                                      if (has == NULL)
-                                        {
-                                          return errorException (m,
-                                                                 _
-                                                                 ("Unable to allocate memory."),
-                                                                 "InternalError",
-                                                                 NULL);
-                                        }
-                                      snprintf (has,
-                                                (3 + xmlStrlen (val) +
-                                                 strlen (key)), "%s: %s", key,
-                                                (char *) val);
-                                      free (key);
-#ifdef POST_DEBUG
-                                      fprintf (stderr, "%s\n", has);
-#endif
-                                    }
-                                  xmlFree (val);
-                                }
-                              hInternet.ihandle[hInternet.nb].header =
-                                curl_slist_append (hInternet.ihandle
-                                                   [hInternet.nb].header,
-                                                   has);
-                              if (has != NULL)
-                                free (has);
-                            }
-                          else
-                            {
-#ifdef POST_DEBUG
-                              fprintf (stderr,
-                                       "Try to fetch the body part of the request ...\n");
-#endif
-                              if (xmlStrcasecmp (cur3->name, BAD_CAST "Body")
-                                  == 0)
-                                {
-#ifdef POST_DEBUG
-                                  fprintf (stderr, "Body part found !!!\n",
-                                           (char *) cur3->content);
-#endif
-                                  char *tmp =
-                                    (char *) malloc (cgiContentLength +
-                                                     1 * sizeof (char));
-                                  memset (tmp, 0, cgiContentLength);
-                                  xmlNodePtr cur4 = cur3->children;
-                                  while (cur4 != NULL)
-                                    {
-                                      while (cur4->type != XML_ELEMENT_NODE)
-                                        cur4 = cur4->next;
-                                      xmlDocPtr bdoc =
-                                        xmlNewDoc (BAD_CAST "1.0");
-                                      bdoc->encoding =
-                                        xmlCharStrdup ("UTF-8");
-                                      xmlDocSetRootElement (bdoc, cur4);
-                                      xmlChar *btmps;
-                                      int bsize;
-                                      xmlDocDumpMemory (bdoc, &btmps, &bsize);
-#ifdef POST_DEBUG
-                                      fprintf (stderr,
-                                               "Body part found !!! %s %s\n",
-                                               tmp, (char *) btmps);
-#endif
-                                      if (btmps != NULL)
-                                        sprintf (tmp, "%s", (char *) btmps);
-                                      xmlFree (btmps);
-                                      cur4 = cur4->next;
-                                      xmlFreeDoc (bdoc);
-                                    }
-                                  map *btmp =
-                                    getMap (tmpmaps->content, "href");
-                                  if (btmp != NULL)
-                                    {
-#ifdef POST_DEBUG
-                                      fprintf (stderr, "%s %s\n", btmp->value,
-                                               tmp);
-                                      curl_easy_setopt (hInternet.handle,
-                                                        CURLOPT_VERBOSE, 1);
-#endif
-                                      hInternet.
-                                        waitingRequests[hInternet.nb] =
-                                        strdup (tmp);
-                                      InternetOpenUrl (&hInternet,
-                                                       btmp->value,
-                                                       hInternet.waitingRequests
-                                                       [hInternet.nb],
-                                                       strlen
-                                                       (hInternet.waitingRequests
-                                                        [hInternet.nb]),
-                                                       INTERNET_FLAG_NO_CACHE_WRITE,
-                                                       0);
-                                    }
-                                  free (tmp);
-                                }
-                              else
-                                if (xmlStrcasecmp
-                                    (cur3->name,
-                                     BAD_CAST "BodyReference") == 0)
-                                {
-                                  xmlChar *val =
-                                    xmlGetProp (cur3, BAD_CAST "href");
-                                  HINTERNET bInternet, res1;
-                                  bInternet = InternetOpen (
-#ifndef WIN32
-                                                             (LPCTSTR)
-#endif
-                                                             "ZooWPSClient\0",
-                                                             INTERNET_OPEN_TYPE_PRECONFIG,
-                                                             NULL, NULL, 0);
-                                  if (!CHECK_INET_HANDLE (hInternet))
-                                    fprintf (stderr,
-                                             "WARNING : hInternet handle failed to initialize");
-#ifdef POST_DEBUG
-                                  curl_easy_setopt (bInternet.handle,
-                                                    CURLOPT_VERBOSE, 1);
-#endif
-                                  bInternet.waitingRequests[0] =
-                                    strdup ((char *) val);
-                                  res1 =
-                                    InternetOpenUrl (&bInternet,
-                                                     bInternet.waitingRequests
-                                                     [0], NULL, 0,
-                                                     INTERNET_FLAG_NO_CACHE_WRITE,
-                                                     0);
-                                  processDownloads (&bInternet);
-                                  char *tmp =
-                                    (char *)
-                                    malloc ((bInternet.ihandle[0].nDataLen +
-                                             1) * sizeof (char));
-                                  if (tmp == NULL)
-                                    {
-                                      return errorException (m,
-                                                             _
-                                                             ("Unable to allocate memory."),
-                                                             "InternalError",
-                                                             NULL);
-                                    }
-                                  size_t bRead;
-                                  InternetReadFile (bInternet.ihandle[0],
-                                                    (LPVOID) tmp,
-                                                    bInternet.
-                                                    ihandle[0].nDataLen,
-                                                    &bRead);
-                                  tmp[bInternet.ihandle[0].nDataLen] = 0;
-                                  InternetCloseHandle (&bInternet);
-                                  map *btmp =
-                                    getMap (tmpmaps->content, "href");
-                                  if (btmp != NULL)
-                                    {
-#ifdef POST_DEBUG
-                                      fprintf (stderr, "%s %s\n", btmp->value,
-                                               tmp);
-#endif
-                                      hInternet.
-                                        waitingRequests[hInternet.nb] =
-                                        strdup (tmp);
-                                      res =
-                                        InternetOpenUrl (&hInternet,
-                                                         btmp->value,
-                                                         hInternet.waitingRequests
-                                                         [hInternet.nb],
-                                                         strlen
-                                                         (hInternet.waitingRequests
-                                                          [hInternet.nb]),
-                                                         INTERNET_FLAG_NO_CACHE_WRITE,
-                                                         0);
-                                    }
-                                  free (tmp);
-                                }
-                            }
-                          cur3 = cur3->next;
-                        }
-#ifdef POST_DEBUG
-                      fprintf (stderr,
-                               "Header and Body was parsed from Reference \n");
-#endif
-#ifdef DEBUG
-                      dumpMap (tmpmaps->content);
-                      fprintf (stderr, "= element 2 node \"%s\" = (%s)\n",
-                               cur2->name, cur2->content);
-#endif
-                    }
-                  else if (xmlStrcasecmp (cur2->name, BAD_CAST "Data") == 0)
-                    {
-#ifdef DEBUG
-                      fprintf (stderr, "DATA\n");
-#endif
-                      xmlNodePtr cur4 = cur2->children;
-                      while (cur4 != NULL)
-                        {
-                          while (cur4 != NULL
-                                 && cur4->type != XML_ELEMENT_NODE)
-                            cur4 = cur4->next;
-                          if (cur4 == NULL)
-                            break;
-                          if (xmlStrcasecmp
-                              (cur4->name, BAD_CAST "LiteralData") == 0)
-                            {
-                /**
-		 * Get every attribute from a LiteralData node
-		 * dataType , uom
-		 */
-                              char *list[2];
-                              list[0] = zStrdup ("dataType");
-                              list[1] = zStrdup ("uom");
-                              for (int l = 0; l < 2; l++)
-                                {
-#ifdef DEBUG
-                                  fprintf (stderr, "*** LiteralData %s ***",
-                                           list[l]);
-#endif
-                                  xmlChar *val =
-                                    xmlGetProp (cur4, BAD_CAST list[l]);
-                                  if (val != NULL
-                                      && strlen ((char *) val) > 0)
-                                    {
-                                      if (tmpmaps->content != NULL)
-                                        addToMap (tmpmaps->content, list[l],
-                                                  (char *) val);
-                                      else
-                                        tmpmaps->content =
-                                          createMap (list[l], (char *) val);
-#ifdef DEBUG
-                                      fprintf (stderr, "%s\n", val);
-#endif
-                                    }
-                                  xmlFree (val);
-                                  free (list[l]);
-                                }
-                            }
-                          else
-                            if (xmlStrcasecmp
-                                (cur4->name, BAD_CAST "ComplexData") == 0)
-                            {
-                /**
-		 * Get every attribute from a Reference node
-		 * mimeType, encoding, schema
-		 */
-                              const char *coms[3] =
-                                { "mimeType", "encoding", "schema" };
-                              for (int l = 0; l < 3; l++)
-                                {
-#ifdef DEBUG
-                                  fprintf (stderr, "*** ComplexData %s ***\n",
-                                           coms[l]);
-#endif
-                                  xmlChar *val =
-                                    xmlGetProp (cur4, BAD_CAST coms[l]);
-                                  if (val != NULL
-                                      && strlen ((char *) val) > 0)
-                                    {
-                                      if (tmpmaps->content != NULL)
-                                        addToMap (tmpmaps->content, coms[l],
-                                                  (char *) val);
-                                      else
-                                        tmpmaps->content =
-                                          createMap (coms[l], (char *) val);
-#ifdef DEBUG
-                                      fprintf (stderr, "%s\n", val);
-#endif
-                                    }
-                                  xmlFree (val);
-                                }
-                            }
-
-                          map *test = getMap (tmpmaps->content, "encoding");
-
-                          if (test == NULL)
-                            { 
-                              if (tmpmaps->content != NULL)
-                                addToMap (tmpmaps->content, "encoding",
-                                          "utf-8");
-                              else
-                                tmpmaps->content =
-                                  createMap ("encoding", "utf-8");
-                              test = getMap (tmpmaps->content, "encoding");
-                            }
-
-                          if (strcasecmp (test->value, "base64") != 0)
-                            { 
-                              xmlChar *mv = xmlNodeListGetString (doc,
-                                                                  cur4->
-                                                                  xmlChildrenNode,
-                                                                  1);
-                              map *ltmp =
-                                getMap (tmpmaps->content, "mimeType");
-                              if (mv == NULL
-                                  ||
-                                  (xmlStrcasecmp
-                                   (cur4->name, BAD_CAST "ComplexData") == 0
-                                   && (ltmp == NULL
-                                       || strncasecmp (ltmp->value,
-                                                       "text/xml", 8) == 0)))
-                                {
-                                  xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0");
-                                  int buffersize;
-                                  xmlNodePtr cur5 = cur4->children;
-                                  while (cur5 != NULL
-                                         && cur5->type != XML_ELEMENT_NODE
-                                         && cur5->type !=
-                                         XML_CDATA_SECTION_NODE)
-                                    cur5 = cur5->next;
-                                  if (cur5 != NULL
-                                      && cur5->type != XML_CDATA_SECTION_NODE)
-                                    {
-                                      xmlDocSetRootElement (doc1, cur5);
-                                      xmlDocDumpFormatMemoryEnc (doc1, &mv,
-                                                                 &buffersize,
-                                                                 "utf-8", 1);
-                                      char size[1024];
-                                      sprintf (size, "%d", buffersize);
-                                      addToMap (tmpmaps->content, "size",
-                                                size);
-                                      xmlFreeDoc (doc1);
-                                    }
-				  else
-				    {
-				      if (cur5 != NULL
-					  && cur5->type == XML_CDATA_SECTION_NODE){
-					xmlDocPtr doc2 = xmlParseMemory((const char*)cur5->content,xmlStrlen(cur5->content));
-					xmlDocSetRootElement (doc1,xmlDocGetRootElement(doc2));
-					xmlDocDumpFormatMemoryEnc (doc1, &mv,
-								   &buffersize,
-								   "utf-8", 1);
-					char size[1024];
-					sprintf (size, "%d", buffersize);
-					addToMap (tmpmaps->content, "size",
-						  size);
-					xmlFreeDoc (doc2);
-					xmlFreeDoc (doc1);
-				      }
-				    }
-                                }else{
-				xmlNodePtr cur5 = cur4->children;
-				while (cur5 != NULL
-				       && cur5->type != XML_CDATA_SECTION_NODE)
-				  cur5 = cur5->next;
-				if (cur5 != NULL
-				    && cur5->type == XML_CDATA_SECTION_NODE){
-				  xmlFree(mv);
-				  mv=xmlStrdup(cur5->content);
-				}
-			      }
-                              if (mv != NULL)
-                                {
-                                  addToMap (tmpmaps->content, "value",
-                                            (char *) mv);
-                                  xmlFree (mv);
-                                }
-                            }
-                          else
-                            {
-                              xmlChar *tmp = xmlNodeListGetRawString (doc,
-                                                                      cur4->xmlChildrenNode,
-                                                                      0);
-                              addToMap (tmpmaps->content, "value",
-                                        (char *) tmp);
-                              map *tmpv = getMap (tmpmaps->content, "value");
-                              char *res = NULL;
-                              char *curs = tmpv->value;
-                              for (int i = 0; i <= strlen (tmpv->value) / 64;
-                                   i++)
-                                {
-                                  if (res == NULL)
-                                    res =
-                                      (char *) malloc (67 * sizeof (char));
-                                  else
-                                    res =
-                                      (char *) realloc (res,
-                                                        (((i + 1) * 65) +
-                                                         i) * sizeof (char));
-                                  int csize = i * 65;
-                                  strncpy (res + csize, curs, 64);
-                                  if (i == xmlStrlen (tmp) / 64)
-                                    strcat (res, "\n\0");
-                                  else
-                                    {
-                                      strncpy (res + (((i + 1) * 64) + i),
-                                               "\n\0", 2);
-                                      curs += 64;
-                                    }
-                                }
-                              free (tmpv->value);
-                              tmpv->value = zStrdup (res);
-                              free (res);
-                              xmlFree (tmp);
-                            }
-                          cur4 = cur4->next;
-                        }
-                    }
-#ifdef DEBUG
-                  fprintf (stderr, "cur2 next \n");
-                  fflush (stderr);
-#endif
-                  cur2 = cur2->next;
-                }
-#ifdef DEBUG
-              fprintf (stderr, "ADD MAPS TO REQUEST MAPS !\n");
-              fflush (stderr);
-#endif
-
-              {
-                maps *testPresence =
-                  getMaps (request_input_real_format, tmpmaps->name);
-                if (testPresence != NULL)
-                  {
-                    elements *elem = getElements (s1->inputs, tmpmaps->name);
-                    if (elem != NULL)
-                      {
-                        if (appendMapsToMaps
-                            (m, request_input_real_format, tmpmaps, elem) < 0)
-                          {
-                            freeMaps (&m);
-                            free (m);
-                            free (REQUEST);
-                            free (SERVICE_URL);
-                            InternetCloseHandle (&hInternet);
-                            freeService (&s1);
-                            free (s1);
-                            return 0;
-                          }
-                      }
-                  }
-                else
-                  addMapsToMaps (&request_input_real_format, tmpmaps);
-              }
-
-#ifdef DEBUG
-              fprintf (stderr, "******TMPMAPS*****\n");
-              dumpMaps (tmpmaps);
-              fprintf (stderr, "******REQUESTMAPS*****\n");
-              dumpMaps (request_input_real_format);
-#endif
-              freeMaps (&tmpmaps);
-              free (tmpmaps);
-              tmpmaps = NULL;
-            }
-#ifdef DEBUG
-          dumpMaps (tmpmaps);
-#endif
-        }
-#ifdef DEBUG
-      fprintf (stderr, "Search for response document node\n");
-#endif
-      xmlXPathFreeObject (tmpsptr);
-
-      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;
-        }
-#ifdef DEBUG
-      fprintf (stderr, "*****%d*****\n", tmps->nodeNr);
-#endif
-      if (asRaw == true)
-        {
-          addToMap (request_inputs, "RawDataOutput", "");
-          xmlNodePtr cur0 = tmps->nodeTab[0];
-          if (cur0->type == XML_ELEMENT_NODE)
-            {
-
-              maps *tmpmaps = (maps *) malloc (MAPS_SIZE);
-              if (tmpmaps == NULL)
-                {
-                  return errorException (m, _("Unable to allocate memory."),
-                                         "InternalError", NULL);
-                }
-              tmpmaps->name = zStrdup ("unknownIdentifier");
-              tmpmaps->content = NULL;
-              tmpmaps->next = NULL;
-
-        /**
-	 * Get every attribute from a RawDataOutput node
-	 * mimeType, encoding, schema, uom
-	 */
-              const char *outs[4] =
-                { "mimeType", "encoding", "schema", "uom" };
-              for (int l = 0; l < 4; l++)
-                {
-#ifdef DEBUG
-                  fprintf (stderr, "*** %s ***\t", outs[l]);
-#endif
-                  xmlChar *val = xmlGetProp (cur0, BAD_CAST outs[l]);
-                  if (val != NULL)
-                    {
-                      if (strlen ((char *) val) > 0)
-                        {
-                          if (tmpmaps->content != NULL)
-                            addToMap (tmpmaps->content, outs[l],
-                                      (char *) val);
-                          else
-                            tmpmaps->content =
-                              createMap (outs[l], (char *) val);
-                        }
-                      xmlFree (val);
-                    }
-                }
-              xmlNodePtr cur2 = cur0->children;
-              while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
-                cur2 = cur2->next;
-              while (cur2 != NULL)
-                {
-                  if (xmlStrncasecmp
-                      (cur2->name, BAD_CAST "Identifier",
-                       xmlStrlen (cur2->name)) == 0)
-                    {
-                      xmlChar *val =
-                        xmlNodeListGetString (NULL, cur2->xmlChildrenNode, 1);
-                      free (tmpmaps->name);
-                      tmpmaps->name = zStrdup ((char *) val);
-                      xmlFree (val);
-                    }
-                  cur2 = cur2->next;
-                  while (cur2 != NULL && cur2->type != XML_ELEMENT_NODE)
-                    cur2 = cur2->next;
-                }
-              if (request_output_real_format == NULL)
-                request_output_real_format = dupMaps (&tmpmaps);
-              else
-                addMapsToMaps (&request_output_real_format, tmpmaps);
-              if (tmpmaps != NULL)
-                {
-                  freeMaps (&tmpmaps);
-                  free (tmpmaps);
-                  tmpmaps = NULL;
-                }
-            }
-        }
-      else
-	  {
-		addToMap (request_inputs, "ResponseDocument", "");
-			
-		xmlNodePtr cur = tmps->nodeTab[0]; // only one ResponseDocument node
-		if (cur->type == XML_ELEMENT_NODE) {
-		/**
-		 * Get every attribute: storeExecuteResponse, lineage, status
-		 */
-			//map* attributes = NULL;
-			const char *ress[3] =
-			  { "storeExecuteResponse", "lineage", "status" };
-			xmlChar *val;
-			for (int l = 0; l < 3; l++)
-			{
-	#ifdef DEBUG
-				fprintf (stderr, "*** %s ***\t", ress[l]);
-	#endif
-				val = xmlGetProp (cur, BAD_CAST ress[l]);
-				if (val != NULL && strlen ((char *) val) > 0)
-				{
-				/*
-					if (attributes == NULL) {
-						attributes = createMap (ress[l], (char *) val);
-					}
-					else {
-						addToMap (attributes, ress[l], (char *) val);
-					}
-				*/		
-					addToMap (request_inputs, ress[l], (char *) val);
-				  }
-	#ifdef DEBUG
-				fprintf (stderr, "%s\n", val);
-	#endif
-				xmlFree (val);
-			}
-			
-			xmlNodePtr cur1 = cur->children;		
-			while (cur1 != NULL) // iterate over Output nodes
-			{
-				if (cur1->type != XML_ELEMENT_NODE || 
-					xmlStrncasecmp(cur1->name, BAD_CAST "Output", 
-								   xmlStrlen (cur1->name)) != 0) {
-					cur1 = cur1->next;
-					continue;
-				}
-				
-				maps *tmpmaps = (maps *) malloc (MAPS_SIZE); // one per Output node
-				if (tmpmaps == NULL) {
-					return errorException (m,
-										   _
-										   ("Unable to allocate memory."),
-										   "InternalError", NULL);
-				}
-				tmpmaps->name = zStrdup ("unknownIdentifier");
-				tmpmaps->content = NULL;
-				tmpmaps->next = NULL;
-				
-				xmlNodePtr elems = cur1->children;
-				
-				while (elems != NULL) {
-				
-					/**
-					 * Identifier
-					 */		
-					if (xmlStrncasecmp
-						(elems->name, BAD_CAST "Identifier",
-						 xmlStrlen (elems->name)) == 0)
-					{			
-						xmlChar *val =
-						  xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
-						
-						free(tmpmaps->name);
-						tmpmaps->name = zStrdup ((char *) val);  
-						if (tmpmaps->content == NULL) {
-							tmpmaps->content = createMap("Identifier", zStrdup ((char *) val));
-						}
-						else {
-							addToMap(tmpmaps->content, "Identifier", zStrdup ((char *) val));
-						}
-					  
-						map* tt = getMap (request_inputs, "ResponseDocument");				  
-						if (strlen(tt->value) == 0) {
-						  addToMap (request_inputs, "ResponseDocument",
-									(char *) val);							
-						}	
-						else {
-							char* tmp = (char*) malloc((strlen(tt->value) + 1 
-												+ strlen((char*) val) + 1) * sizeof(char));
-							sprintf (tmp, "%s;%s", tt->value, (char *) val);
-							free(tt->value);
-							tt->value = tmp;	
-						}	
-						xmlFree (val);
-					}				
-					/**
-					 * Title, Abstract
-					 */
-					else if (xmlStrncasecmp(elems->name, BAD_CAST "Title",
-											xmlStrlen (elems->name)) == 0
-						  || xmlStrncasecmp(elems->name, BAD_CAST "Abstract",
-										 xmlStrlen (elems->name)) == 0)
-					{
-						xmlChar *val =
-							xmlNodeListGetString (doc, elems->xmlChildrenNode, 1);
-							
-						if (tmpmaps->content == NULL) {
-							tmpmaps->content = createMap((char*) elems->name, zStrdup ((char *) val));
-						}
-						else {
-							addToMap(tmpmaps->content, (char*) elems->name, zStrdup ((char *) val));
-						}
-						xmlFree (val);
-					}
-					elems = elems->next;
-				}
-				
-				/**
-				 * Get every attribute from an Output node:
-				 * mimeType, encoding, schema, uom, asReference
-				 */
-				const char *outs[5] =
-					  { "mimeType", "encoding", "schema", "uom", "asReference" };
-					  
-				for (int l = 0; l < 5; l++) {
-	#ifdef DEBUG
-					fprintf (stderr, "*** %s ***\t", outs[l]);
-	#endif
-					xmlChar *val = xmlGetProp (cur1, BAD_CAST outs[l]);				
-					if (val != NULL && xmlStrlen(val) > 0) {
-						if (tmpmaps->content != NULL) {
-							addToMap (tmpmaps->content, outs[l], (char *) val);
-						}			  
-						else {
-							tmpmaps->content = createMap (outs[l], (char *) val);
-						}	
-					}
-	#ifdef DEBUG
-					fprintf (stderr, "%s\n", val);
-	#endif
-					xmlFree (val);
-				}
-				
-				if (request_output_real_format == NULL) {
-					request_output_real_format = tmpmaps;
-				}	
-				else if (getMaps(request_output_real_format, tmpmaps->name) != NULL) {
-					return errorException (m,
-										   _
-										   ("Duplicate <Output> elements in WPS Execute request"),
-										   "InternalError", NULL);
-				}
-				else {
-					maps* mptr = request_output_real_format;
-					while (mptr->next != NULL) {
-						mptr = mptr->next;
-					}
-					mptr->next = tmpmaps;	
-				}					
-				cur1 = cur1->next;
-			}			 
-		}
-	  } 
-      xmlXPathFreeObject (tmpsptr);
-      xmlFreeDoc (doc);
-      xmlCleanupParser ();
-    }
-
-  runHttpRequests (&m, &request_input_real_format, &hInternet);
-
-  //  if(CHECK_INET_HANDLE(hInternet))
-  InternetCloseHandle (&hInternet);
-
-#ifdef DEBUG
-  fprintf (stderr, "\n%d\n", __LINE__);
-  fflush (stderr);
-  dumpMaps (request_input_real_format);
-  dumpMaps (request_output_real_format);
-  dumpMap (request_inputs);
-  fprintf (stderr, "\n%d\n", __LINE__);
-  fflush (stderr);
-#endif
-
-  /**
-   * Ensure that each requested arguments are present in the request
-   * DataInputs and ResponseDocument / RawDataOutput
-   */
-  map* errI=NULL;
-#ifdef DEBUG  
-  dumpMaps(request_input_real_format);
-#endif  
-  char *dfv = addDefaultValues (&request_input_real_format, s1->inputs, m, 0,&errI);
-#ifdef DEBUG  
-  dumpMaps(request_input_real_format);
-#endif  
-  maps *ptr = request_input_real_format;
-  while (ptr != NULL)
-    {
-      map *tmp0 = getMap (ptr->content, "size");
-      map *tmp1 = getMap (ptr->content, "maximumMegabytes");
-      if (tmp1 != NULL && tmp0 != NULL)
-        {
-          float i = atof (tmp0->value) / 1048576.0;
-          if (i >= atoi (tmp1->value))
-            {
-              char tmps[1024];
-              map *tmpe = createMap ("code", "FileSizeExceeded");
-              snprintf (tmps, 1024,
-                        _
-                        ("The <%s> parameter has a size limit (%s MB) defined in the ZOO ServicesProvider configuration file, but the reference you provided exceeds this limit (%f MB)."),
-                        ptr->name, tmp1->value, i);
-              addToMap (tmpe, "locator", ptr->name);
-              addToMap (tmpe, "text", tmps);
-              printExceptionReportResponse (m, tmpe);
-              freeService (&s1);
-              free (s1);
-              freeMap (&tmpe);
-              free (tmpe);
-              freeMaps (&m);
-              free (m);
-              free (REQUEST);
-              free (SERVICE_URL);
-              freeMaps (&request_input_real_format);
-              free (request_input_real_format);
-              freeMaps (&request_output_real_format);
-              free (request_output_real_format);
-              freeMaps (&tmpmaps);
-              free (tmpmaps);
-              return 1;
-            }
-        }
-      ptr = ptr->next;
-    }
-
-  map* errO=NULL;
-  char *dfv1 =
-    addDefaultValues (&request_output_real_format, s1->outputs, m, 1,&errO);
-  if (strcmp (dfv1, "") != 0 || strcmp (dfv, "") != 0)
-    {
-      char tmps[1024];
-      map *tmpe = NULL;
-      if (strcmp (dfv, "") != 0)
-        {
-	  tmpe = createMap ("code", "MissingParameterValue");
-	  int nb=0;
-	  int length=1;
-	  map* len=getMap(errI,"length");
-	  if(len!=NULL)
-	    length=atoi(len->value);
-	  for(nb=0;nb<length;nb++){
-	    map* errp=getMapArray(errI,"value",nb);
-	    snprintf (tmps, 1024,
-		      _
-		      ("The <%s> argument was not specified in DataInputs but is required according to the ZOO ServicesProvider configuration file."),
-		      errp->value);
-	    setMapArray (tmpe, "locator", nb , errp->value);
-	    setMapArray (tmpe, "text", nb , tmps);
-	    setMapArray (tmpe, "code", nb , "MissingParameterValue");
-	  }
-	}
-      if (strcmp (dfv1, "") != 0)
-        {
-	  int ilength=0;
-	  if(tmpe==NULL)
-	    tmpe = createMap ("code", "InvalidParameterValue");
-	  else{
-	    map* len=getMap(tmpe,"length");
-	    if(len!=NULL)
-	      ilength=atoi(len->value);
-	  }
-	  int nb=0;
-	  int length=1;
-	  map* len=getMap(errO,"length");
-	  if(len!=NULL)
-	    length=atoi(len->value);
-	  for(nb=0;nb<length;nb++){
-	    map* errp=getMapArray(errO,"value",nb);
-	    snprintf (tmps, 1024,
-		      _
-		      ("The <%s> argument specified as %s identifier was not recognized (not defined in the ZOO Configuration File)."),
-		      errp->value,
-		      ((getMap(request_inputs,"RawDataOutput")!=NULL)?"RawDataOutput":"ResponseDocument"));
-	    setMapArray (tmpe, "locator", nb+ilength , errp->value);
-	    setMapArray (tmpe, "text", nb+ilength , tmps);
-	    setMapArray (tmpe, "code", nb+ilength , "InvalidParameterValue");
-	  }
-	}
-      printExceptionReportResponse (m, tmpe);
-      freeService (&s1);
-      free (s1);
-      freeMap (&tmpe);
-      free (tmpe);
-      freeMaps (&m);
-      free (m);
-      free (REQUEST);
-      free (SERVICE_URL);
-      freeMaps (&request_input_real_format);
-      free (request_input_real_format);
-      freeMaps (&request_output_real_format);
-      free (request_output_real_format);
-      freeMaps (&tmpmaps);
-      free (tmpmaps);
-      if(errI!=NULL){
-	freeMap(&errI);
-	free(errI);
-      }
-      if(errO!=NULL){
-	freeMap(&errO);
-	free(errO);
-      }
-      return 1;
-    }
-  maps *tmpReqI = request_input_real_format;
-  while (tmpReqI != NULL)
-    {
-      char name[1024];
-      if (getMap (tmpReqI->content, "isFile") != NULL)
-        {
-          if (cgiFormFileName (tmpReqI->name, name, sizeof (name)) ==
-              cgiFormSuccess)
-            {
-              int BufferLen = 1024;
-              cgiFilePtr file;
-              int targetFile;
-              char storageNameOnServer[2048];
-              char fileNameOnServer[64];
-              char contentType[1024];
-              char buffer[1024];
-              char *tmpStr = NULL;
-              int size;
-              int got, t;
-              map *path = getMapFromMaps (m, "main", "tmpPath");
-              cgiFormFileSize (tmpReqI->name, &size);
-              cgiFormFileContentType (tmpReqI->name, contentType,
-                                      sizeof (contentType));
-              if (cgiFormFileOpen (tmpReqI->name, &file) == cgiFormSuccess)
-                {
-                  t = -1;
-                  while (1)
-                    {
-                      tmpStr = strstr (name + t + 1, "\\");
-                      if (NULL == tmpStr)
-                        tmpStr = strstr (name + t + 1, "/");
-                      if (NULL != tmpStr)
-                        t = (int) (tmpStr - name);
-                      else
-                        break;
-                    }
-                  strcpy (fileNameOnServer, name + t + 1);
-
-                  sprintf (storageNameOnServer, "%s/%s", path->value,
-                           fileNameOnServer);
-#ifdef DEBUG
-                  fprintf (stderr, "Name on server %s\n",
-                           storageNameOnServer);
-                  fprintf (stderr, "fileNameOnServer: %s\n",
-                           fileNameOnServer);
-#endif
-                  targetFile =
-                    open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
-                          S_IRWXU | S_IRGRP | S_IROTH);
-                  if (targetFile < 0)
-                    {
-#ifdef DEBUG
-                      fprintf (stderr, "could not create the new file,%s\n",
-                               fileNameOnServer);
-#endif
-                    }
-                  else
-                    {
-                      while (cgiFormFileRead (file, buffer, BufferLen, &got)
-                             == cgiFormSuccess)
-                        {
-                          if (got > 0)
-                            write (targetFile, buffer, got);
-                        }
-                    }
-                  addToMap (tmpReqI->content, "lref", storageNameOnServer);
-                  cgiFormFileClose (file);
-                  close (targetFile);
-#ifdef DEBUG
-                  fprintf (stderr, "File \"%s\" has been uploaded",
-                           fileNameOnServer);
-#endif
-                }
-            }
-        }
-      tmpReqI = tmpReqI->next;
-    }
-
-  ensureDecodedBase64 (&request_input_real_format);
-
-#ifdef DEBUG
-  fprintf (stderr, "REQUEST_INPUTS\n");
-  dumpMaps (request_input_real_format);
-  fprintf (stderr, "REQUEST_OUTPUTS\n");
-  dumpMaps (request_output_real_format);
-#endif
+
+
+  if(parseRequest(&m,&request_inputs,s1,&request_input_real_format,&request_output_real_format,&hInternet)<0){
+    freeMaps (&m);
+    free (m);
+    free (REQUEST);
+    free (SERVICE_URL);
+    InternetCloseHandle (&hInternet);
+    freeService (&s1);
+    free (s1);
+    return 0;
+  }
 
   maps *curs = getMaps (m, "env");
@@ -3490,4 +1876,20 @@
   if (status == NULLMAP)
     {
+      if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
+	freeService (&s1);
+	free (s1);
+	freeMaps (&m);
+	free (m);
+	free (REQUEST);
+	free (SERVICE_URL);
+	freeMaps (&request_input_real_format);
+	free (request_input_real_format);
+	freeMaps (&request_output_real_format);
+	free (request_output_real_format);
+	freeMaps (&tmpmaps);
+	free (tmpmaps);
+	return -1;
+      }
+
       loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
                          &request_output_real_format, &eres);
@@ -3530,8 +1932,8 @@
       else if (pid == 0)
         {
-      /**
-       * son : have to close the stdout, stdin and stderr to let the parent
-       * process answer to http client.
-       */
+	  /**
+	   * son : have to close the stdout, stdin and stderr to let the parent
+	   * process answer to http client.
+	   */
 #ifndef WIN32
           zSleep (1);
@@ -3586,4 +1988,22 @@
 #endif
           free (flog);
+	  if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
+	    freeService (&s1);
+	    free (s1);
+	    freeMaps (&m);
+	    free (m);
+	    free (REQUEST);
+	    free (SERVICE_URL);
+	    freeMaps (&request_input_real_format);
+	    free (request_input_real_format);
+	    freeMaps (&request_output_real_format);
+	    free (request_output_real_format);
+	    freeMaps (&tmpmaps);
+	    free (tmpmaps);
+	    fflush (stdout);
+	    unlockShm (lid);
+	    fflush (stderr);
+	    return -1;
+	  }
       /**
        * set status to SERVICE_STARTED and flush stdout to ensure full 
