Index: /branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/Makefile.in	(revision 880)
@@ -129,5 +129,5 @@
 zcfg2yaml: zcfg2yaml.c service.h lex.sr.o service_conf.tab.o service_conf.y main_conf_read.tab.o lex.cr.o response_print.o server_internal.o service_internal.o ${MS_FILE} ${YAML_FILE}
 	g++ -g -O2 ${JSCFLAGS} ${RUBYCFLAGS} ${XML2CFLAGS} ${CFLAGS} -c zcfg2yaml.c  -fno-common -DPIC -o zcfg2yaml.o
-	g++  ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o ulinet.o service_callback.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o  ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}
+	g++  ${XML2CFLAGS} ${CFLAGS} zcfg2yaml.o caching.o ulinet.o service_callback.o server_internal.o service_internal.o ${MS_FILE} response_print.o lex.cr.o lex.sr.o service_conf.tab.o main_conf_read.tab.o  ${YAML_FILE} -o zcfg2yaml -L. ${LDFLAGS}
 
 install: zoo_loader.cgi
Index: /branches/prototype-v0/zoo-project/zoo-kernel/caching.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/caching.c	(revision 880)
@@ -67,16 +67,18 @@
  */
 char* getMd5f(char* file){
-  EVP_MD_CTX md5ctx;
+  EVP_MD_CTX *md5ctx=EVP_MD_CTX_create();
   char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char));
   unsigned char result[EVP_MAX_MD_SIZE];
   unsigned int len;
   int bytes;
-  unsigned char data[1024];
+  int dlen=65536;
+  unsigned char data[dlen+1];
   FILE *inFile = fopen (file, "rb");
-  EVP_DigestInit(&md5ctx, EVP_md5());
-  while ((bytes = fread (data, 1, 1024, inFile)) != 0)
-    EVP_DigestUpdate(&md5ctx, data, bytes);
-  EVP_DigestFinal_ex(&md5ctx,result,&len);
-  EVP_MD_CTX_cleanup(&md5ctx);
+  EVP_DigestInit(md5ctx, EVP_md5());
+  while ((bytes = fread (data, sizeof(unsigned char), dlen, inFile)) != 0)
+    EVP_DigestUpdate(md5ctx, data, bytes);
+  EVP_DigestFinal_ex(md5ctx,result,&len);
+  EVP_MD_CTX_cleanup(md5ctx);
+  EVP_MD_CTX_destroy(md5ctx);
   int i;
   for(i = 0; i < len; i++){
@@ -162,4 +164,22 @@
 
 /**
+ * Store MD5 of the content of a file
+ * @file char* the full path of the file
+ */
+int storeMd5(char* file){
+  char* storage=zStrdup(file);
+  char* md5fstr=getMd5f(file);
+  storage[strlen(storage)-2]='m';
+  storage[strlen(storage)-1]='d';
+  FILE* fo=fopen(storage,"w+");
+  if(fo==NULL)
+    return 1;
+  fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo);
+  free(md5fstr);
+  fclose(fo);
+  return 0;
+}
+
+/**
  * Cache a file for a given request.
  * For each cached file, the are two files stored, a .zca and a .zcm containing
@@ -177,5 +197,4 @@
   map* tmp=getMapFromMaps(conf,"main","cacheDir");
   char contentr[4096];
-  char* md5fstr=NULL;
   int cred=0;
   if(tmp!=NULL){
@@ -184,4 +203,16 @@
     free(myRequest);
     char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
+    // Store md5
+    char* md5fstr=getMd5f(filename);
+    sprintf(fname,"%s/%s.zmd",tmp->value,md5str);
+    FILE* fo=fopen(fname,"w+");
+#ifdef DEBUG
+    fprintf(stderr,"filename: %s\n",filename);
+    fprintf(stderr,"MD5: %s\n",md5fstr);
+#endif
+    fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo);
+    free(md5fstr);
+    fclose(fo);
+    
     sprintf(fname,"%s/%s.zca",tmp->value,md5str);
     zooLock* lck=lockFile(conf,fname,'w');
@@ -192,5 +223,6 @@
 #endif
       FILE* fi=fopen(filename,"rb");
-      FILE* fo=fopen(fname,"w+");
+      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
+      fo=fopen(fname,"w+");
       if(fo==NULL){
 #ifdef DEBUG
@@ -236,19 +268,8 @@
       fclose(fo);
 
-      // Store md5
-      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
-      md5fstr=getMd5f(fname);
-      sprintf(fname,"%s/%s.zmd",tmp->value,md5str);
-      fo=fopen(fname,"w+");
-#ifdef DEBUG
-      fprintf(stderr,"MD5: %s\n",md5fstr);
-#endif
-      fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo);
-      free(md5fstr);
-      fclose(fo);
-
       free(md5str);
-      free(fname);
-    }
+
+    }
+    free(fname);
   }
 }
@@ -342,5 +363,4 @@
     }
     else{
-
       char* myRequest=getFilenameForRequest(conf,request);
       char* md5str=getMd5(myRequest);
@@ -436,5 +456,5 @@
 
       if(getMap(content->content,icname)==NULL) {
-	if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
+	if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
 	  fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char));
 	  if(fcontent == NULL){
@@ -456,5 +476,5 @@
 	
 	map* tmpMap=getMapOrFill(&(*in)->content,vname,"");
-	if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
+	if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
 	  free(tmpMap->value);
 	  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
@@ -518,5 +538,5 @@
 	addToMap((*in)->content,sname,ltmp1);
 	addToMap((*in)->content,mname,mimeType);
-	if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
+	if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
 	  addToCache(*m,request,fcontent,mimeType,fsize, NULL, 0);
 	  free(fcontent);
@@ -628,5 +648,5 @@
 	return -1;
       fsize=f_status.st_size;
-      if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
+      if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
 	fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
 	FILE* f=fopen(cached,"rb");
@@ -665,5 +685,5 @@
 
   map* tmpMap=getMapOrFill(content,"value","");
-  if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
+  if(memUse==NULL || strcasecmp(memUse->value,"load")==0){
     free(tmpMap->value);
     tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
@@ -677,5 +697,5 @@
   addToMap(*content,"size",ltmp1);
   if(cached==NULL){
-    if(memUse!=NULL && strcasecmp(memUse->value,"load")==0)
+    if(memUse==NULL || strcasecmp(memUse->value,"load")==0)
       addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0);
     else
Index: /branches/prototype-v0/zoo-project/zoo-kernel/caching.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/caching.h	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/caching.h	(revision 880)
@@ -35,5 +35,7 @@
   void addRequestToQueue(maps**,HINTERNET*,const char*,bool);
   int loadRemoteFile(maps**,map**,HINTERNET*,char*);
-
+  char* getMd5f(char*);
+  int storeMd5(char*);
+  
 #ifdef __cplusplus
 }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/request_parser.c	(revision 880)
@@ -978,5 +978,4 @@
 
 		      map *test = getMap (tmpmaps->content, "encoding");
-		      
 		      if (test == NULL)
 			{
@@ -992,11 +991,13 @@
 		      if (getMap(tmpmaps->content,"dataType")==NULL && test!=NULL && strcasecmp (test->value, "base64") != 0)
 			{
-			  xmlChar *mv = xmlNodeListGetString (doc,
-							      cur4->xmlChildrenNode,
-							      1);
+			  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
-			      ||
+			    getMap (tmpmaps->content, "mimeType");
+			  if (/*mv == NULL
+			      ||*/
 			      (xmlStrcasecmp
 			       (cur4->name, BAD_CAST "ComplexData") == 0
@@ -1036,4 +1037,5 @@
 					   buffersize);
 			    }else{
+
 			    if(xmlStrcasecmp
 			       (cur4->name, BAD_CAST "BoundingBoxData") == 0){
@@ -1051,8 +1053,10 @@
 			      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)
+				  && cur5->type != XML_CDATA_SECTION_NODE
+				  && cur5->type != XML_TEXT_NODE)
 				{
 				  xmlDocPtr doc1 = xmlNewDoc (BAD_CAST "1.0");
@@ -1065,8 +1069,10 @@
 					       buffersize);
 				}
-			      else /*if (cur5 != NULL
+			      else if (cur5 != NULL)/*
 				     && cur5->type == XML_CDATA_SECTION_NODE)*/{
 				xmlFree(mv);
-				mv=xmlStrdup(cur5->content);
+				if(cur5->content!=NULL){
+				  mv=xmlStrdup(cur5->content);
+				}
 			      }
 			    }
@@ -1150,6 +1156,7 @@
 		  }
 	      }
-	    else
+	    else{
 	      addMapsToMaps (request_output, tmpmaps);
+	    }
 	  }
 	  freeMaps (&tmpmaps);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/response_print.h	(revision 880)
@@ -38,5 +38,5 @@
 
 #include <libintl.h>
-#include <locale.h>
+#include <xlocale.h>
 /**
  * ZOO-Kernel internal messages translation function
@@ -80,5 +80,5 @@
 #endif
 #ifndef WIN32
-#include <xlocale.h>
+#include <locale.h>
 #endif
 #include "ulinet.h"
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal.h	(revision 880)
@@ -38,5 +38,5 @@
 
 #include <libintl.h>
-#include <locale.h>
+#include <xlocale.h>
 /**
  * ZOO-Kernel internal messages translation function
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 880)
@@ -34,4 +34,5 @@
 #include "server_internal.h"
 #include "response_print.h"
+#include "caching.h"
 
 /**
@@ -1235,4 +1236,5 @@
   GDALDestroyDriverManager();
   CPLCleanupTLS();
+  storeMd5(pszFilename);
   return 1;
 }
Index: /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/service_internal_r.c	(revision 880)
@@ -110,20 +110,10 @@
   if(tmp!=NULL){
     if(mp!=NULL && strlen(mp->value)>0){
-      char *mps=zStrdup(mp->value);
-      int i,len=strlen(mps);
-      int j=0;
-      for(i=0;i<len;i++){
-	if(mps[i]=='/'){
-	  mps[i]='.';
-	}
-      }
-      char *mn=(char*)malloc((strlen(mps)+strlen(tmp->value)+2)*sizeof(char));
-      sprintf(mn,"%s.%s",mps,tmp->value);
+      char *mn=(char*)malloc((strlen(mp->value)+strlen(tmp->value)+2)*sizeof(char));
+      sprintf(mn,"%s/%s",mp->value,tmp->value);
       pName = mkString(mn);
       free(mn);
-      free(mps);
     }
     else{
-      dumpMap(tmp);
       char *tmpStr=(char*)malloc((strlen(r_path)+strlen(tmp->value)+2)*sizeof(char));
       sprintf(tmpStr,"%s/%s",r_path,tmp->value);
@@ -189,6 +179,4 @@
 	char* finalStr=(char*)malloc((strlen(tmpStr)+strlen(_("Unable to run your R service: "))+2)*sizeof(char));
 	sprintf(finalStr,"%s %s",_("Unable to run your R service: "),tmpStr);
-	fprintf(stderr,"%s %d %s \n",__FILE__,__LINE__,tmpStr);
-	fflush(stderr);
 	errorException(*main_conf,finalStr,"NoApplicableCode",NULL);
 	free(finalStr);
Index: /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/ulinet.h	(revision 880)
@@ -45,4 +45,5 @@
 #include "jsapi.h"
 #endif
+#ifndef __cplusplus
 #ifndef bool
 #define bool int
@@ -51,4 +52,5 @@
 #define true 1
 #define false 0
+#endif
 #endif
 
Index: /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c
===================================================================
--- /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 879)
+++ /branches/prototype-v0/zoo-project/zoo-kernel/zoo_service_loader.c	(revision 880)
@@ -107,6 +107,8 @@
 #endif
 
+#ifdef USE_HPC
 #include "service_json.h"
 #include "service_callback.h"
+#endif
 
 #include <dirent.h>
@@ -2347,5 +2349,5 @@
       }
       map* testMap=getMapFromMaps(m,"main","memory");
-      if(testMap!=NULL && strcasecmp(testMap->value,"load")!=0)
+      if(testMap==NULL || strcasecmp(testMap->value,"load")!=0)
 	dumpMapsValuesToFiles(&m,&request_input_real_format);
       loadServiceAndRun (&m, s1, request_inputs, &request_input_real_format,
