Index: trunk/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- trunk/zoo-project/zoo-kernel/request_parser.c	(revision 889)
+++ trunk/zoo-project/zoo-kernel/request_parser.c	(revision 917)
@@ -28,4 +28,5 @@
 #include "response_print.h"
 #include "caching.h"
+#include "cgic.h"
 
 /**
@@ -154,5 +155,5 @@
       addToMap(cursor->content,"base64_value",tmp->value);
       int size=0;
-      char *s=strdup(tmp->value);
+      char *s=zStrdup(tmp->value);
       free(tmp->value);
       tmp->value=base64d(s,strlen(s),&size);
@@ -174,5 +175,5 @@
 	  addToMap(cursor->content,key,tmp->value);
 	  int size=0;
-	  char *s=strdup(tmp->value);
+	  char *s=zStrdup(tmp->value);
 	  free(tmp->value);
 	  tmp->value=base64d(s,strlen(s),&size);
@@ -521,4 +522,5 @@
   int l = 0;
   map* version=getMapFromMaps(*main_conf,"main","rversion");
+  map* memory=getMapFromMaps(*main_conf,"main","memory");
   int vid=getVersionId(version->value);
   for (k=0; k < nodes->nodeNr; k++)
@@ -533,4 +535,5 @@
 	    xmlChar *val = xmlGetProp (cur, BAD_CAST "id");
 	    tmpmaps = createMaps((char *) val);
+	    xmlFree(val);
 	  }
 
@@ -624,10 +627,8 @@
 			    tmpmaps->content =
 			      createMap (refs[l], (char *) val);
-
 			  map *ltmp = getMap (tmpmaps->content, "method");
 			  if (l == 4 )
 			    {
-			      if ((ltmp==NULL || strncasecmp (ltmp->value, "POST",4) != 0)) // 
-			      //if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0))
+			      if ((ltmp==NULL || strncmp (ltmp->value, "POST",4) != 0))
 				{
 				  if (loadRemoteFile
@@ -751,4 +752,5 @@
 				      map *btmp =
 					getMap (tmpmaps->content, "Reference");
+				      addToMap (tmpmaps->content, "Body", tmp);
 				      if (btmp != NULL)
 					{
@@ -759,5 +761,6 @@
 							   xmlStrlen(btmps),
 							   INTERNET_FLAG_NO_CACHE_WRITE,
-							   0);
+							   0,
+							   *main_conf);
 					  addIntToMap (tmpmaps->content, "Order", hInternet->nb);
 					}
@@ -778,4 +781,6 @@
 				  xmlGetProp (cur3, BAD_CAST "href");
 				HINTERNET bInternet, res1, res;
+				maps *tmpConf=createMaps("main");
+				tmpConf->content=createMap("memory","load");
 				bInternet = InternetOpen (
 #ifndef WIN32
@@ -785,9 +790,11 @@
 							  INTERNET_OPEN_TYPE_PRECONFIG,
 							  NULL, NULL, 0);
+#ifndef WIN32
 				if (!CHECK_INET_HANDLE (bInternet))
 				  fprintf (stderr,
 					   "WARNING : bInternet handle failed to initialize");
+#endif
 				bInternet.waitingRequests[0] =
-				  strdup ((char *) val);
+				  zStrdup ((char *) val);
 				res1 =
 				  InternetOpenUrl (&bInternet,
@@ -795,6 +802,9 @@
 						   [0], NULL, 0,
 						   INTERNET_FLAG_NO_CACHE_WRITE,
-						   0);
+						   0,
+						   tmpConf);
 				processDownloads (&bInternet);
+				freeMaps(&tmpConf);
+				free(tmpConf);
 				char *tmp =
 				  (char *)
@@ -816,5 +826,6 @@
 						  &bRead);
 				tmp[bInternet.ihandle[0].nDataLen] = 0;
-				InternetCloseHandle (&bInternet);
+				InternetCloseHandle(&bInternet);
+				addToMap (tmpmaps->content, "Body", tmp);
 				map *btmp =
 				  getMap (tmpmaps->content, "href");
@@ -829,8 +840,10 @@
 						       strlen(tmp),
 						       INTERNET_FLAG_NO_CACHE_WRITE,
-						       0);
+						       0,
+						       *main_conf);
 				    addIntToMap (tmpmaps->content, "Order", hInternet->nb);
 				  }
 				free (tmp);
+				xmlFree (val);
 			      }
 			}
@@ -895,5 +908,4 @@
 		    }
 		  }
-
 
 		  while (cur4 != NULL)
@@ -967,7 +979,6 @@
 
 		      map *test = getMap (tmpmaps->content, "encoding");
-
 		      if (test == NULL)
-			{ 
+			{
 			  if (tmpmaps->content != NULL)
 			    addToMap (tmpmaps->content, "encoding",
@@ -979,13 +990,15 @@
 			}
 
-		      if (getMap(tmpmaps->content,"dataType")==NULL && strcasecmp (test->value, "base64") != 0)
-			{ 
-			  xmlChar *mv = xmlNodeListGetString (doc,
-							      cur4->xmlChildrenNode,
-							      1);
+		      if (getMap(tmpmaps->content,"dataType")==NULL && test!=NULL && strcasecmp (test->value, "base64") != 0)
+			{
+			  xmlChar *mv = NULL;
+			  /*if(cur4!=NULL && cur4->xmlChildrenNode!=NULL)
+			    xmlChar *mv = xmlNodeListGetString (doc,
+								cur4->xmlChildrenNode,
+								1);*/
 			  map *ltmp =
 			    getMap (tmpmaps->content, "mimeType");
-			  if (mv == NULL
-			      ||
+			  if (/*mv == NULL
+			      ||*/
 			      (xmlStrcasecmp
 			       (cur4->name, BAD_CAST "ComplexData") == 0
@@ -1025,4 +1038,5 @@
 					   buffersize);
 			    }else{
+
 			    if(xmlStrcasecmp
 			       (cur4->name, BAD_CAST "BoundingBoxData") == 0){
@@ -1039,11 +1053,27 @@
 			      xmlNodePtr cur5 = cur4->children;
 			      while (cur5 != NULL
+				     && cur5->type != XML_ELEMENT_NODE
+				     && cur5->type != XML_TEXT_NODE
 				     && cur5->type != XML_CDATA_SECTION_NODE)
 				cur5 = cur5->next;
 			      if (cur5 != NULL
-				  && cur5->type == XML_CDATA_SECTION_NODE){
-				if(mv!=NULL)
-				  xmlFree(mv);
-				mv=xmlStrdup(cur5->content);
+				  && cur5->type != XML_CDATA_SECTION_NODE
+				  && cur5->type != XML_TEXT_NODE)
+				{
+				  xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0");
+				  int buffersize;
+				  xmlDocSetRootElement (doc1, cur5);
+				  xmlDocDumpFormatMemoryEnc (doc1, &mv,
+							     &buffersize,
+							     "utf-8", 0);
+				  addIntToMap (tmpmaps->content, "size",
+					       buffersize);
+				}
+			      else if (cur5 != NULL)/*
+				     && cur5->type == XML_CDATA_SECTION_NODE)*/{
+				xmlFree(mv);
+				if(cur5->content!=NULL){
+				  mv=xmlStrdup(cur5->content);
+				}
 			      }
 			    }
@@ -1088,4 +1118,8 @@
 		cur2 = cur2->next;
 	      }
+	    }
+	  if(memory!=NULL && strncasecmp(memory->value,"load",4)!=0)
+	    if(getMap(tmpmaps->content,"to_load")==NULL){
+	      addToMap(tmpmaps->content,"to_load","false");
 	    }
 	  {
@@ -1123,6 +1157,7 @@
 		  }
 	      }
-	    else
+	    else{
 	      addMapsToMaps (request_output, tmpmaps);
+	    }
 	  }
 	  freeMaps (&tmpmaps);
@@ -1198,4 +1233,5 @@
       const char ress[4][13] =
 	{ "mimeType", "encoding", "schema", "transmission" };
+      xmlFree (val);
       for (l = 0; l < 4; l++){
 	val = xmlGetProp (cur, BAD_CAST ress[l]);
@@ -1217,9 +1253,11 @@
 	while (ccur != NULL){
 	  if(ccur->type == XML_ELEMENT_NODE){
-	    char *xpathExpr=(char*)malloc(65+strlen(tmpmaps->name));
-	    sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name);
+	    char *xpathExpr=(char*)malloc(66+strlen(tmpmaps->name));
+	    sprintf(xpathExpr,"/*/*[local-name()='Output' and @id='%s']/*[local-name()='Output']",tmpmaps->name);	    
 	    xmlXPathObjectPtr tmpsptr = extractFromDoc (doc, xpathExpr);
 	    xmlNodeSet* cnodes = tmpsptr->nodesetval;
 	    xmlParseOutputs2(main_conf,request_inputs,&tmpmaps->child,doc,cnodes);
+	    xmlXPathFreeObject (tmpsptr);
+	    free(xpathExpr);
 	    break;
 	  }
@@ -1470,6 +1508,5 @@
 
   xmlInitParser ();
-  //xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER);
-  xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER | XML_PARSE_HUGE); // 
+  xmlDocPtr doc = xmlReadMemory (post, cgiContentLength, "input_request.xml", NULL, XML_PARSE_RECOVER);
 
   /**
@@ -1503,4 +1540,5 @@
 	  else
 	    addToMap(*request_inputs,"mode","auto");
+	  xmlFree(val);
 	  val = xmlGetProp (cur, BAD_CAST "response");
 	  if(val!=NULL){
@@ -1515,4 +1553,5 @@
 	    addToMap(*request_inputs,"ResponseDocument","");
 	  }
+	  xmlFree(val);
 	}
       }
@@ -1768,5 +1807,5 @@
 #endif
                   targetFile =
-                    open (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
+                    zOpen (storageNameOnServer, O_RDWR | O_CREAT | O_TRUNC,
                           S_IRWXU | S_IRGRP | S_IROTH);
                   if (targetFile < 0)
@@ -1788,5 +1827,5 @@
                   addToMap (tmpReqI->content, "lref", storageNameOnServer);
                   cgiFormFileClose (file);
-                  close (targetFile);
+                  zClose (targetFile);
 		  free(fileNameOnServer);
 		  free(storageNameOnServer);
@@ -1820,5 +1859,5 @@
   if (r_inputs == NULL){
     if(mandatory>0){
-      const char *replace=_("Mandatory parameter <%s> was not specified");
+      char *replace=_("Mandatory parameter <%s> was not specified");
       char *message=(char*)malloc((strlen(replace)+strlen(toCheck)+1)*sizeof(char));
       sprintf(message,replace,toCheck);
@@ -1869,8 +1908,8 @@
     }
     if(hasValidValue<0){
-      const char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value.");
+      char *replace=_("The value <%s> was not recognized, %s %s the only acceptable value.");
       nb=0;
       char *vvalues=NULL;
-      const char* num=_("is");
+      char* num=_("is");
       while(avalues[nb]!=NULL){
 	char *tvalues;
@@ -1920,2 +1959,43 @@
   }
 }
+
+/**
+ * Parse cookie contained in request headers.
+ *
+ * @param conf the conf maps containinfg the main.cfg
+ * @param cookie the 
+ */
+void parseCookie(maps** conf,const char* cookie){
+  char* tcook=zStrdup(cookie);
+  char *token, *saveptr;
+  token = strtok_r (tcook, "; ", &saveptr);
+  maps* res=createMaps("cookies");
+  while (token != NULL){
+    char *token1, *saveptr1, *name;
+    int i=0;
+    token1 = strtok_r (token, "=", &saveptr1);
+    while (token1 != NULL){
+      if(i==0){
+	name=zStrdup(token1);
+	i++;
+      }
+      else{
+	if(res->content==NULL)
+	  res->content=createMap(name,token1);
+	else
+	  addToMap(res->content,name,token1);
+	free(name);
+	name=NULL;
+	i=0;
+      }
+      token1 = strtok_r (NULL, "=", &saveptr1);
+    }
+    if(name!=NULL)
+      free(name);
+    token = strtok_r (NULL, "; ", &saveptr);
+  }
+  addMapsToMaps(conf,res);
+  freeMaps(&res);
+  free(res);
+  free(tcook);
+}
