Index: trunk/zoo-project/zoo-kernel/service_internal.c
===================================================================
--- trunk/zoo-project/zoo-kernel/service_internal.c	(revision 542)
+++ trunk/zoo-project/zoo-kernel/service_internal.c	(revision 550)
@@ -2432,5 +2432,6 @@
   nc1 = xmlNewNode(ns, BAD_CAST "ExceptionText");
   if(tmp!=NULL){
-    xmlNodeSetContent(nc1, BAD_CAST tmp->value);
+    xmlNodePtr txt=xmlNewText(BAD_CAST tmp->value);
+    xmlAddChild(nc1,txt);
   }
   else{
@@ -2442,4 +2443,40 @@
 }
 
+/************************************************************************/
+/*                          readGeneratedFile()                         */
+/************************************************************************/
+
+/**
+ * Read a file generated by a service.
+ * 
+ * @param m the conf maps
+ * @param content the output item
+ * @param filename the file to read
+ */
+void readGeneratedFile(maps* m,map* content,char* filename){
+  FILE * file=fopen(filename,"rb");
+  fseek(file, 0, SEEK_END);
+  long count = ftell(file);
+  rewind(file);
+  struct stat file_status; 
+  stat(filename, &file_status);
+  if(file==NULL){
+    fprintf(stderr,"Failed to open file %s for reading purpose.\n",filename);
+    setMapInMaps(m,"lenv","message","Unable to read produced file. Please try again later");
+    return ;
+  }
+  map* tmpMap1=getMap(content,"value");
+  if(tmpMap1==NULL){
+    addToMap(content,"value","");
+    tmpMap1=getMap(content,"value");
+  }
+  free(tmpMap1->value);
+  tmpMap1->value=(char*) malloc((count+1)*sizeof(char));  
+  fread(tmpMap1->value,1,count*sizeof(char),file);
+  fclose(file);
+  char rsize[100];
+  sprintf(rsize,"%d",count*sizeof(char));
+  addToMap(tmpMap1,"size",rsize);
+}
 
 void outputResponse(service* s,maps* request_inputs,maps* request_outputs,
@@ -2503,4 +2540,27 @@
   }
   
+    if(res==SERVICE_FAILED){
+      map * errormap;
+      map *lenv;
+      lenv=getMapFromMaps(m,"lenv","message");
+      char *tmp0;
+      if(lenv!=NULL){
+	tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char));
+	sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
+      }
+      else{
+	tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
+	sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service."));
+      }
+      errormap = createMap("text",tmp0);
+      free(tmp0);
+      addToMap(errormap,"code", "InternalError");
+      dumpMap(errormap);
+      printExceptionReportResponse(m,errormap);
+      freeMap(&errormap);
+      free(errormap);
+      return;
+    }
+
 
   if(asRaw==0){
@@ -2521,92 +2581,108 @@
 #endif
 	{
-	elements* in=getElements(s->outputs,tmpI->name);
-	char *format=NULL;
-	if(in!=NULL){
-	  format=strdup(in->format);
-	}else
-	  format=strdup("LiteralData");
-	if(strcasecmp(format,"BoundingBoxData")==0){
-	  addToMap(tmpI->content,"extension","xml");
-	  addToMap(tmpI->content,"mimeType","text/xml");
-	  addToMap(tmpI->content,"encoding","UTF-8");
-	  addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
-	}
-	map *ext=getMap(tmpI->content,"extension");
-	map *tmp1=getMapFromMaps(m,"main","tmpPath");
-	char *file_name,*file_path;
-	bool hasExt=true;
-	if(ext==NULL){
-	  // We can fallback to a default list of supported formats using
-	  // mimeType information if present here. Maybe we can add more formats
-	  // here.
-	  // If mimeType was not found, we then set txt as the default extension
-	  map* mtype=getMap(tmpI->content,"mimeType");
-	  if(mtype!=NULL){
-	    if(strcasecmp(mtype->value,"text/xml")==0)
-	      ext=createMap("extension","xml");
-	    else if(strcasecmp(mtype->value,"application/json")==0)
-	      ext=createMap("extension","js");
-	    else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0)
-	      ext=createMap("extension","kml");
-	    else if(strncmp(mtype->value,"image/",6)==0)
-	      ext=createMap("extension",strstr(mtype->value,"/")+1);
-	    else
-	      ext=createMap("extension","txt");
+	  elements* in=getElements(s->outputs,tmpI->name);
+	  char *format=NULL;
+	  if(in!=NULL){
+	    format=strdup(in->format);
+	  }else
+	    format=strdup("LiteralData");
+	  if(strcasecmp(format,"BoundingBoxData")==0){
+	    addToMap(tmpI->content,"extension","xml");
+	    addToMap(tmpI->content,"mimeType","text/xml");
+	    addToMap(tmpI->content,"encoding","UTF-8");
+	    addToMap(tmpI->content,"schema","http://schemas.opengis.net/ows/1.1.0/owsCommon.xsd");
 	  }
-	  else
-	    ext=createMap("extension","txt");
-	  hasExt=false;
-	}
-	file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char));
-	int cpid0=cpid+time(NULL);
-	sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value);
-	file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
-	sprintf(file_path,"%s/%s",tmp1->value,file_name);
-	FILE *ofile=fopen(file_path,"wb");
-	if(ofile==NULL){
-	  char tmpMsg[1024];
-	  sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name);
-	  map * errormap = createMap("text",tmpMsg);
-	  addToMap(errormap,"code", "InternalError");
-	  printExceptionReportResponse(m,errormap);
-	  freeMap(&errormap);
-	  free(errormap);
+
+	  map *tmp1=getMapFromMaps(m,"main","tmpPath");
+
+	  map *gfile=getMap(tmpI->content,"generated_file");
+	  char *file_name;
+	  if(gfile!=NULL){
+	    readGeneratedFile(m,tmpI->content,gfile->value);	    
+	    file_name=(char*)malloc((strlen(gfile->value)+strlen(tmp1->value)+1)*sizeof(char));
+	    for(int i=0;i<strlen(gfile->value);i++)
+	      file_name[i]=gfile->value[i+strlen(tmp1->value)];
+	  }
+	  else{
+	    map *ext=getMap(tmpI->content,"extension");
+	    char *file_path;
+	    bool hasExt=true;
+	    if(ext==NULL){
+	      // We can fallback to a default list of supported formats using
+	      // mimeType information if present here. Maybe we can add more formats
+	      // here.
+	      // If mimeType was not found, we then set txt as the default extension
+	      map* mtype=getMap(tmpI->content,"mimeType");
+	      if(mtype!=NULL) {
+		if(strncasecmp(mtype->value,"text/xml",8)==0)
+		  ext=createMap("extension","xml");
+		else if(strncasecmp(mtype->value,"application/zip",15)==0)
+		  ext=createMap("extension","zip");
+		else if(strncasecmp(mtype->value,"application/json",16)==0)
+		  ext=createMap("extension","js");
+		else if(strncmp(mtype->value,"application/vnd.google-earth.kml",32)==0)
+		  ext=createMap("extension","kml");
+		else if(strncmp(mtype->value,"image/",6)==0)
+		  ext=createMap("extension",strstr(mtype->value,"/")+1);
+		else
+		  ext=createMap("extension","txt");
+	      }
+	      else
+		ext=createMap("extension","txt");
+	      hasExt=false;
+	    }
+	    file_name=(char*)malloc((strlen(s->name)+strlen(ext->value)+strlen(tmpI->name)+1024)*sizeof(char));
+	    int cpid0=cpid+time(NULL);
+	    sprintf(file_name,"%s_%s_%i.%s",s->name,tmpI->name,cpid0,ext->value);
+	    file_path=(char*)malloc((strlen(tmp1->value)+strlen(file_name)+2)*sizeof(char));
+	    sprintf(file_path,"%s/%s",tmp1->value,file_name);
+	    FILE *ofile=fopen(file_path,"wb");
+	    if(ofile==NULL){
+	      char tmpMsg[1024];
+	      sprintf(tmpMsg,_("Unable to create the file : \"%s\" for storing the %s final result."),file_name,tmpI->name);
+	      map * errormap = createMap("text",tmpMsg);
+	      addToMap(errormap,"code", "InternalError");
+	      printExceptionReportResponse(m,errormap);
+	      freeMap(&errormap);
+	      free(errormap);
+	      free(file_name);
+	      free(file_path);
+	      return;
+	    }
+	    free(file_path);
+	    if(!hasExt){
+	      freeMap(&ext);
+	      free(ext);
+	    }
+	    toto=getMap(tmpI->content,"value");
+	    if(strcasecmp(format,"BoundingBoxData")!=0){
+	      map* size=getMap(tmpI->content,"size");
+	      if(size!=NULL && toto!=NULL)
+		fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile);
+	      else
+		if(toto!=NULL && toto->value!=NULL)
+		  fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
+	    }else{
+	      printBoundingBoxDocument(m,tmpI,ofile);
+	    }
+	    fclose(ofile);
+
+	  }
+	  map *tmp2=getMapFromMaps(m,"main","tmpUrl");
+	  map *tmp3=getMapFromMaps(m,"main","serverAddress");
+	  char *file_url;
+	  if(strncasecmp(tmp2->value,"http://",7)==0 ||
+	     strncasecmp(tmp2->value,"https://",8)==0){
+	    file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
+	    sprintf(file_url,"%s/%s",tmp2->value,file_name);
+	  }else{
+	    file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
+	    sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
+	  }
+	  addToMap(tmpI->content,"Reference",file_url);
+	  free(format);
 	  free(file_name);
-	  free(file_path);
-	  return;
-	}
-	free(file_path);
-	map *tmp2=getMapFromMaps(m,"main","tmpUrl");
-	map *tmp3=getMapFromMaps(m,"main","serverAddress");
-	char *file_url;
-	if(strncasecmp(tmp2->value,"http://",7)==0 ||
-	   strncasecmp(tmp2->value,"https://",8)==0){
-	  file_url=(char*)malloc((strlen(tmp2->value)+strlen(file_name)+2)*sizeof(char));
-	  sprintf(file_url,"%s/%s",tmp2->value,file_name);
-	}else{
-	  file_url=(char*)malloc((strlen(tmp3->value)+strlen(tmp2->value)+strlen(file_name)+3)*sizeof(char));
-	  sprintf(file_url,"%s/%s/%s",tmp3->value,tmp2->value,file_name);
-	}
-	addToMap(tmpI->content,"Reference",file_url);
-	if(!hasExt){
-	  freeMap(&ext);
-	  free(ext);
-	}
-	toto=getMap(tmpI->content,"value");
-	if(strcasecmp(format,"BoundingBoxData")!=0){
-	  map* size=getMap(tmpI->content,"size");
-	  if(size!=NULL && toto!=NULL)
-	    fwrite(toto->value,1,atoi(size->value)*sizeof(char),ofile);
-	  else
-	    if(toto!=NULL && toto->value!=NULL)
-	      fwrite(toto->value,1,strlen(toto->value)*sizeof(char),ofile);
-	}else{
-	  printBoundingBoxDocument(m,tmpI,ofile);
-	}
-	free(format);
-	fclose(ofile);
-	free(file_name);
-	free(file_url);	
+	  free(file_url);	
+	  
 	}
 #ifdef USE_MS
@@ -2628,22 +2704,31 @@
 			 request_inputs,
 			 request_outputs);
-    }
-    else{
-      if(res==SERVICE_FAILED){
-	map * errormap;
-	map *lenv;
-	lenv=getMapFromMaps(m,"lenv","message");
-	char *tmp0;
-	if(lenv!=NULL){
-	  tmp0=(char*)malloc((strlen(lenv->value)+strlen(_("Unable to run the Service. The message returned back by the Service was the following: "))+1)*sizeof(char));
-	  sprintf(tmp0,_("Unable to run the Service. The message returned back by the Service was the following: %s"),lenv->value);
-	}
-	else{
-	  tmp0=(char*)malloc((strlen(_("Unable to run the Service. No more information was returned back by the Service."))+1)*sizeof(char));
-	  sprintf(tmp0,_("Unable to run the Service. No more information was returned back by the Service."));
-	}
-	errormap = createMap("text",tmp0);
-	free(tmp0);
-	addToMap(errormap,"code", "InternalError");
+  }
+  else{
+    /**
+     * We get the requested output or fallback to the first one if the 
+     * requested one is not present in the resulting outputs maps.
+     */
+    maps* tmpI=NULL;
+    map* tmpIV=getMap(request_inputs1,"RawDataOutput");
+    if(tmpIV!=NULL){
+      tmpI=getMaps(request_outputs,tmpIV->value);
+    }
+    if(tmpI==NULL)
+      tmpI=request_outputs;
+    elements* e=getElements(s->outputs,tmpI->name);
+    if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
+      printBoundingBoxDocument(m,tmpI,NULL);
+    }else{
+      map *gfile=getMap(tmpI->content,"generated_file");
+      if(gfile!=NULL){
+	readGeneratedFile(m,tmpI->content,gfile->value);
+      }
+      toto=getMap(tmpI->content,"value");
+      if(toto==NULL){
+	char tmpMsg[1024];
+	sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name);
+	map * errormap = createMap("text",tmpMsg);
+	addToMap(errormap,"code", "InvalidParameterValue");
 	printExceptionReportResponse(m,errormap);
 	freeMap(&errormap);
@@ -2651,66 +2736,40 @@
 	return;
       }
-      /**
-       * We get the requested output or fallback to the first one if the 
-       * requested one is not present in the resulting outputs maps.
-       */
-      maps* tmpI=NULL;
-      map* tmpIV=getMap(request_inputs1,"RawDataOutput");
-      if(tmpIV!=NULL){
-	tmpI=getMaps(request_outputs,tmpIV->value);
-      }
-      if(tmpI==NULL)
-	tmpI=request_outputs;
-      elements* e=getElements(s->outputs,tmpI->name);
-      if(e!=NULL && strcasecmp(e->format,"BoundingBoxData")==0){
-	printBoundingBoxDocument(m,tmpI,NULL);
-      }else{
-	toto=getMap(tmpI->content,"value");
-	if(toto==NULL){
-	  char tmpMsg[1024];
-	  sprintf(tmpMsg,_("Wrong RawDataOutput parameter, unable to fetch any result for the name your provided : \"%s\"."),tmpI->name);
-	  map * errormap = createMap("text",tmpMsg);
-	  addToMap(errormap,"code", "InvalidParameterValue");
-	  printExceptionReportResponse(m,errormap);
-	  freeMap(&errormap);
-	  free(errormap);
-	  return;
-	}
-	map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
-	if(fname!=NULL)
-	  printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
-	map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
-	if(rs!=NULL)
-	  printf("Content-Length: %s\r\n",rs->value);
-	printHeaders(m);
-	char mime[1024];
-	map* mi=getMap(tmpI->content,"mimeType");
-#ifdef DEBUG
-	fprintf(stderr,"SERVICE OUTPUTS\n");
-	dumpMaps(request_outputs);
-	fprintf(stderr,"SERVICE OUTPUTS\n");
-#endif
-	map* en=getMap(tmpI->content,"encoding");
-	if(mi!=NULL && en!=NULL)
+      map* fname=getMapFromMaps(tmpI,tmpI->name,"filename");
+      if(fname!=NULL)
+	printf("Content-Disposition: attachment; filename=\"%s\"\r\n",fname->value);
+      map* rs=getMapFromMaps(tmpI,tmpI->name,"size");
+      if(rs!=NULL)
+	printf("Content-Length: %s\r\n",rs->value);
+      printHeaders(m);
+      char mime[1024];
+      map* mi=getMap(tmpI->content,"mimeType");
+#ifdef DEBUG
+      fprintf(stderr,"SERVICE OUTPUTS\n");
+      dumpMaps(request_outputs);
+      fprintf(stderr,"SERVICE OUTPUTS\n");
+#endif
+      map* en=getMap(tmpI->content,"encoding");
+      if(mi!=NULL && en!=NULL)
+	sprintf(mime,
+		"Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
+		mi->value,en->value);
+      else
+	if(mi!=NULL)
 	  sprintf(mime,
-		  "Content-Type: %s; charset=%s\r\nStatus: 200 OK\r\n\r\n",
-		  mi->value,en->value);
+		  "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
+		  mi->value);
 	else
-	  if(mi!=NULL)
-	    sprintf(mime,
-		    "Content-Type: %s; charset=UTF-8\r\nStatus: 200 OK\r\n\r\n",
-		    mi->value);
-	  else
-	    sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
-	printf("%s",mime);
-	if(rs!=NULL)
-	  fwrite(toto->value,1,atoi(rs->value),stdout);
-	else
-	  fwrite(toto->value,1,strlen(toto->value),stdout);
-#ifdef DEBUG
-	dumpMap(toto);
-#endif
-      }
-    }
+	  sprintf(mime,"Content-Type: text/plain; charset=utf-8\r\nStatus: 200 OK\r\n\r\n");
+      printf("%s",mime);
+      if(rs!=NULL)
+	fwrite(toto->value,1,atoi(rs->value),stdout);
+      else
+	fwrite(toto->value,1,strlen(toto->value),stdout);
+#ifdef DEBUG
+      dumpMap(toto);
+#endif
+    }
+  }
 }
 
@@ -3220,46 +3279,98 @@
     int index=0;
     while(content!=NULL){
-      if((tmp1=getMap(content->content,"href")) || 
-	 (tmp1=getMap(content->content,"xlink:href"))){
-	if(getMap(content->content,"isCached")==NULL){
-	  char* fcontent;
-	  char *mimeType=NULL;
-	  int fsize=0;
-
-	  fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
-	  if(fcontent == NULL){
-	    return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+      
+      map* length=getMap(content->content,"length");
+      int shouldClean=-1;
+      if(length==NULL){
+	length=createMap("length","1");
+	shouldClean=1;
+      }
+      for(int i=0;i<atoi(length->value);i++){
+	
+	char* fcontent;
+	char *mimeType=NULL;
+	int fsize=0;
+	char cname[15];
+	char vname[11];
+	char vname1[11];
+	char sname[9];
+	char icname[14];
+	char xname[16];
+	if(index>0)
+	  sprintf(vname1,"value_%d",index);
+	else
+	  sprintf(vname1,"value");
+
+	if(i>0){
+	  tmp1=getMap(content->content,cname);
+	  sprintf(cname,"cache_file_%d",i);
+	  sprintf(vname,"value_%d",i);
+	  sprintf(sname,"size_%d",i);
+	  sprintf(icname,"isCached_%d",i);
+	  sprintf(xname,"Reference_%d",i);
+	}else{
+	  sprintf(cname,"cache_file");
+	  sprintf(vname,"value");
+	  sprintf(icname,"isCached");
+	  sprintf(sname,"size");
+	  sprintf(xname,"Reference");
+	}
+
+	map* tmap=getMapFromMaps(*m,"orequests",vname1);
+	if((tmp1=getMap(content->content,xname))!=NULL && strcasecmp(tmap->value,tmp1->value)==0 ){
+	  if(getMap(content->content,icname)==NULL){
+	    
+	    fcontent=(char*)malloc((hInternet->ihandle[index].nDataLen+1)*sizeof(char));
+	    if(fcontent == NULL){
+	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+	    }
+	    size_t dwRead;
+	    InternetReadFile(hInternet->ihandle[index], 
+			     (LPVOID)fcontent, 
+			     hInternet->ihandle[index].nDataLen, 
+			     &dwRead);
+	    fcontent[hInternet->ihandle[index].nDataLen]=0;
+	    fsize=hInternet->ihandle[index].nDataLen;
+	    if(hInternet->ihandle[index].mimeType==NULL)
+	      mimeType=strdup("none");
+	    else
+	      mimeType=strdup((char*)hInternet->ihandle[index].mimeType);
+	    
+	    map* tmpMap=getMapOrFill(&content->content,vname,"");
+	    free(tmpMap->value);
+	    tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
+	    if(tmpMap->value==NULL){
+	      return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
+	    }
+	    memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
+	    
+	    char ltmp1[256];
+	    sprintf(ltmp1,"%d",fsize);
+	    map* tmp=getMapFromMaps(*m,"main","cacheDir");
+	    if(tmp!=NULL){
+	      char* md5str=getMd5(tmp1->value);
+	      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
+	      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
+	      addToMap(content->content,cname,fname);
+	      free(fname);
+	    }
+	    addToMap(content->content,sname,ltmp1);
+	    addToCache(*m,tmp1->value,fcontent,mimeType,fsize);
+	    free(fcontent);
+	    free(mimeType);
+	    dumpMaps(content);
+	    index++;
+
 	  }
-	  size_t dwRead;
-	  InternetReadFile(hInternet->ihandle[index], 
-			   (LPVOID)fcontent, 
-			   hInternet->ihandle[index].nDataLen, 
-			   &dwRead);
-	  fcontent[hInternet->ihandle[index].nDataLen]=0;
-	  fsize=hInternet->ihandle[index].nDataLen;
-	  if(hInternet->ihandle[index].mimeType==NULL)
-	    mimeType=strdup("none");
-	  else
-	    mimeType=strdup((char*)hInternet->ihandle[index].mimeType);
-	  
-	  map* tmpMap=getMapOrFill(&content->content,"value","");
-	  free(tmpMap->value);
-	  tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
-	  if(tmpMap->value==NULL){
-	    return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
-	  }
-	  memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
-	  
-	  char ltmp1[256];
-	  sprintf(ltmp1,"%d",fsize);
-	  addToMap(content->content,"size",ltmp1);
-	  addToCache(*m,tmp1->value,fcontent,mimeType,fsize);
-	  free(fcontent);
-	  free(mimeType);
 	}
-	index++;
-      }
+      }
+      if(shouldClean>0){
+	freeMap(&length);
+	free(length);
+      }
+      
       content=content->next;
     }
+    
   }
 }
@@ -3274,5 +3385,13 @@
   char *mimeType=NULL;
   int fsize=0;
+
+  map* t=getMap(*content,"xlink:href");
+  if(t==NULL){
+    t=getMap((*content),"href");
+    addToMap(*content,"xlink:href",url);
+  }
+
   if(cached!=NULL){
+
     struct stat f_status;
     int s=stat(cached, &f_status);
@@ -3284,4 +3403,5 @@
       fcontent[fsize]=0;
       fclose(f);
+      addToMap(*content,"cache_file",cached);
     }
     cached[strlen(cached)-1]='m';
@@ -3294,7 +3414,20 @@
       fclose(f);
     }
+
   }else{
     hInternet->waitingRequests[hInternet->nb]=strdup(url);
     InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
+    maps *oreq=getMaps(*m,"orequests");
+    if(oreq==NULL){
+      oreq=(maps*)malloc(MAPS_SIZE);
+      oreq->name=zStrdup("orequests");
+      oreq->content=createMap("value",url);
+      oreq->next=NULL;
+      addMapsToMaps(m,oreq);
+      freeMaps(&oreq);
+      free(oreq);
+    }else{
+      setMapArray(oreq->content,"value",hInternet->nb-1,url);
+    }
     return 0;
   }
@@ -3309,16 +3442,29 @@
     
   free(tmpMap->value);
+
   tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
   if(tmpMap->value==NULL)
     return errorException(*m, _("Unable to allocate memory."), "InternalError",NULL);
   memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
-  
+
   char ltmp1[256];
   sprintf(ltmp1,"%d",fsize);
   addToMap(*content,"size",ltmp1);
-  if(cached==NULL)
+  if(cached==NULL){
     addToCache(*m,url,fcontent,mimeType,fsize);
-  else
+  }
+  else{
     addToMap(*content,"isCached","true");
+
+    map* tmp=getMapFromMaps(*m,"main","cacheDir");
+    if(tmp!=NULL){
+      map *c=getMap((*content),"xlink:href");
+      char* md5str=getMd5(c->value);
+      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
+      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
+      addToMap(*content,"cache_file",fname);
+      free(fname);
+    }
+  }
   free(fcontent);
   free(mimeType);
