source: branches/prototype-v0/zoo-project/zoo-kernel/caching.c @ 872

Last change on this file since 872 was 872, checked in by djay, 6 years ago

Fix name of the map red to return extra cookie headers

  • Property svn:keywords set to Id
File size: 19.8 KB
Line 
1/*
2 * Author : Gérald Fenoy
3 *
4 *  Copyright 2008-2015 GeoLabs SARL. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#include "caching.h"
26#include "service.h"
27#include "service_internal.h"
28#include "response_print.h"
29#include <openssl/md5.h>
30#include <openssl/hmac.h>
31#include <openssl/evp.h>
32#include <openssl/bio.h>
33#include <openssl/buffer.h>
34
35/**
36 * Compute md5
37 *
38 * @param url the char*
39 * @return a char* representing the md5 of the url
40 * @warning make sure to free resources returned by this function
41 */
42char* getMd5(char* url){
43  EVP_MD_CTX md5ctx;
44  char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char));
45  unsigned char result[EVP_MAX_MD_SIZE];
46  unsigned int len;
47  EVP_DigestInit(&md5ctx, EVP_md5());
48  EVP_DigestUpdate(&md5ctx, url, strlen(url));
49  EVP_DigestFinal_ex(&md5ctx,result,&len);
50  EVP_MD_CTX_cleanup(&md5ctx);
51  int i;
52  for(i = 0; i < len; i++){
53    if(i>0){
54      char *tmp=strdup(fresult);
55      sprintf(fresult,"%s%02x", tmp,result[i]);
56      free(tmp);
57    }
58    else
59      sprintf(fresult,"%02x",result[i]);
60  }
61  return fresult;
62}
63
64
65/**
66 * Create a URL by appending every request header listed in the security
67 * section.This imply that the URL will contain any authentication
68 * informations that should be fowarded to the server from which de input
69 * was download.
70 * @param conf the main configuration maps
71 * @param request the URL to transform.
72 * @return a char* that contain the original URL plus potential header (only for
73 * hosts that are not shared).
74 * @warning Be sure to free the memory returned by this function.
75 */
76char* getFilenameForRequest(maps* conf, const char* request){
77  map* passThrough=getMapFromMaps(conf,"security","attributes");
78  map* targetHosts=getMapFromMaps(conf,"security","hosts");
79  char* passedHeader[10];
80  int cnt=0;
81  char *res=zStrdup(request);
82  char *toAppend=NULL;
83  if(passThrough!=NULL && targetHosts!=NULL){
84    char *tmp=zStrdup(passThrough->value);
85    char *token, *saveptr;
86    token = strtok_r (tmp, ",", &saveptr);
87    int i;
88    if((strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,request)==1) && strncasecmp(getProvenance(conf,request),"SHARED",6)!=0){
89      while (token != NULL){
90        int length=strlen(token)+6;
91        char* tmp1=(char*)malloc(length*sizeof(char));
92        map* tmpMap;
93        snprintf(tmp1,6,"HTTP_");
94        int j;
95        for(j=0;token[j]!='\0';j++){
96          if(token[j]!='-')
97            tmp1[5+j]=toupper(token[j]);
98          else
99            tmp1[5+j]='_';
100          tmp1[5+j+1]='\0';
101        }
102        tmpMap = getMapFromMaps(conf,"renv",tmp1);
103        if(tmpMap!=NULL){
104          if(toAppend==NULL){
105            toAppend=(char*)malloc((strlen(tmpMap->value)+1)*sizeof(char));
106            sprintf(toAppend,"%s",tmpMap->value);
107          }else{
108            char *tmp3=zStrdup(toAppend);
109            toAppend=(char*)realloc(toAppend,(strlen(tmpMap->value)+strlen(tmp3)+2)*sizeof(char));
110            sprintf(toAppend,"%s,%s",tmp3,tmpMap->value);
111            free(tmp3);
112          }
113        }
114        free(tmp1);
115        cnt+=1;
116        token = strtok_r (NULL, ",", &saveptr);
117      }
118    }
119    free(tmp);
120  }
121  if(toAppend!=NULL){
122    char *tmp3=zStrdup(res);
123    res=(char*)realloc(res,(strlen(tmp3)+strlen(toAppend)+1)*sizeof(char));
124    sprintf(res,"%s%s",tmp3,toAppend);
125    free(tmp3);
126    free(toAppend);
127  }
128  return res;
129}
130
131/**
132 * Cache a file for a given request.
133 * For each cached file, the are two files stored, a .zca and a .zcm containing
134 * the downloaded content and the mimeType respectively.
135 *
136 * @param conf the maps containing the settings of the main.cfg file
137 * @param request the url used too fetch the content
138 * @param content the downloaded content
139 * @param mimeType the content mimeType
140 * @param length the content size
141 * @param filepath a buffer for storing the path of the cached file; may be NULL
142 * @param max_path the size of the allocated filepath buffer 
143 */
144void cacheFile(maps* conf,char* request,char* mimeType,int length,char* filename){
145  map* tmp=getMapFromMaps(conf,"main","cacheDir");
146  char contentr[4096];
147  int cred=0;
148  if(tmp!=NULL){
149    char* myRequest=getFilenameForRequest(conf,request);
150    char* md5str=getMd5(myRequest);
151    free(myRequest);
152    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
153    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
154    zooLock* lck=lockFile(conf,fname,'w');
155    if(lck!=NULL){
156#ifdef DEBUG
157      fprintf(stderr,"Cache list : %s\n",fname);
158      fflush(stderr);
159#endif
160      FILE* fi=fopen(filename,"rb");
161      FILE* fo=fopen(fname,"w+");
162      if(fo==NULL){
163#ifdef DEBUG
164        fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
165#endif
166        unlockFile(conf,lck);
167        return;
168      }
169      if(fi==NULL){
170#ifdef DEBUG
171        fprintf (stderr, "Failed to open %s for reading: %s\n",filename, strerror(errno));
172#endif
173        unlockFile(conf,lck);
174        return;
175      }
176      memset(contentr,0,4096);
177      while((cred=fread(contentr,sizeof(char),4096,fi))>0){
178        fwrite(contentr,sizeof(char),cred,fo);
179        fflush(fo);
180        memset(contentr,0,4096);
181      }
182      unlockFile(conf,lck);
183      fclose(fo);
184      fclose(fi);
185       
186      sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
187      fo=fopen(fname,"w+");
188#ifdef DEBUG
189      fprintf(stderr,"MIMETYPE: %s\n",mimeType);
190#endif
191      fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
192      fclose(fo);
193
194      sprintf(fname,"%s/%s.zcp",tmp->value,md5str);
195      fo=fopen(fname,"w+");
196      char* origin=getProvenance(conf,request);
197#ifdef DEBUG
198      fprintf(stderr,"ORIGIN: %s\n",mimeType);
199#endif
200      fwrite(origin,sizeof(char),strlen(origin),fo);
201      fclose(fo);
202
203      free(md5str);
204      free(fname);
205    }
206  }
207}
208
209/**
210 * Cache a file for a given request.
211 * For each cached file, the are two files stored, a .zca and a .zcm containing
212 * the downloaded content and the mimeType respectively.
213 *
214 * @param conf the maps containing the settings of the main.cfg file
215 * @param request the url used too fetch the content
216 * @param content the downloaded content
217 * @param mimeType the content mimeType
218 * @param length the content size
219 * @param filepath a buffer for storing the path of the cached file; may be NULL
220 * @param max_path the size of the allocated filepath buffer 
221 */
222void addToCache(maps* conf,char* request,char* content,char* mimeType,int length, 
223                char* filepath, size_t max_path){
224  map* tmp=getMapFromMaps(conf,"main","cacheDir");
225  if(tmp!=NULL){
226    char* myRequest=getFilenameForRequest(conf,request);
227    char* md5str=getMd5(myRequest);
228    free(myRequest);
229    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
230    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
231    zooLock* lck=lockFile(conf,fname,'w');
232    if(lck!=NULL){
233#ifdef DEBUG
234      fprintf(stderr,"Cache list : %s\n",fname);
235      fflush(stderr);
236#endif
237      FILE* fo=fopen(fname,"w+");
238      if(fo==NULL){
239#ifdef DEBUG
240        fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
241#endif
242        filepath = NULL;
243        unlockFile(conf,lck);
244        return;
245      }
246      fwrite(content,sizeof(char),length,fo);
247      unlockFile(conf,lck);
248      fclose(fo);
249       
250      if (filepath != NULL) {
251        strncpy(filepath, fname, max_path);
252      }
253
254      sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
255      fo=fopen(fname,"w+");
256#ifdef DEBUG
257      fprintf(stderr,"MIMETYPE: %s\n",mimeType);
258#endif
259      fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
260      fclose(fo);
261
262      sprintf(fname,"%s/%s.zcp",tmp->value,md5str);
263      fo=fopen(fname,"w+");
264      char* origin=getProvenance(conf,request);
265#ifdef DEBUG
266      fprintf(stderr,"ORIGIN: %s\n",mimeType);
267#endif
268      fwrite(origin,sizeof(char),strlen(origin),fo);
269      fclose(fo);
270
271      free(md5str);
272      free(fname);
273    }
274  }
275  else {
276    filepath = NULL;
277  }       
278}
279
280/**
281 * Verify if a url is available in the cache
282 *
283 * @param conf the maps containing the settings of the main.cfg file
284 * @param request the url
285 * @return the full name of the cached file if any, NULL in other case
286 * @warning make sure to free resources returned by this function (if not NULL)
287 */
288char* isInCache(maps* conf,char* request){
289  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
290  if(tmpM!=NULL){
291    if(strncasecmp(request,"file://",7)==0){
292      char* tmpStr=zStrdup(request+7);
293      fprintf(stderr,"**** %s %d %s \n",__FILE__,__LINE__,tmpStr);
294      return tmpStr;
295    }
296    else{
297
298      char* myRequest=getFilenameForRequest(conf,request);
299      char* md5str=getMd5(myRequest);
300      free(myRequest);
301#ifdef DEBUG
302      fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
303#endif
304      char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+strlen(md5str)+6));
305      sprintf(fname,"%s/%s.zca",tmpM->value,md5str);
306      struct stat f_status;
307      int s=stat(fname, &f_status);
308      if(s==0 && f_status.st_size>0){
309        free(md5str);
310        return fname;
311      }
312      free(md5str);
313      free(fname);
314    }
315  }
316  return NULL;
317}
318
319/**
320 * Read the downloaded file for a specific input
321 *
322 * @param m the maps containing the settings of the main.cfg file
323 * @param in the input
324 * @param index the input index
325 * @param hInternet the internet connection
326 * @param error the error map pointer
327 * @return 0 in case of success, -1 in case of failure
328 */
329int readCurrentInput(maps** m,maps** in,int* index,HINTERNET* hInternet,map** error){
330 
331  int shouldClean=-1;
332  map* tmp1;
333  char sindex[5];
334  maps* content=*in;
335  map* length=getMap(content->content,"length");
336  map* memUse=getMapFromMaps(*m,"main","memory");
337  if(length==NULL){
338    length=createMap("length","1");
339    shouldClean=1;
340  }
341  for(int i=0;i<atoi(length->value);i++){
342    char* fcontent;
343    char *mimeType=NULL;
344    int fsize=0;
345    char cname[15];
346    char vname[11];
347    char vname1[11];
348    char sname[9];
349    char mname[15];
350    char icname[14];
351    char xname[16];
352    char bname[8];
353    char hname[11];
354    char oname[12];
355    char ufile[12];   
356    if(*index>0)
357      sprintf(vname1,"value_%d",*index);
358    else
359      sprintf(vname1,"value");
360   
361    if(i>0){
362      sprintf(cname,"cache_file_%d",i);
363      tmp1=getMap(content->content,cname);
364      sprintf(vname,"value_%d",i);
365      sprintf(sname,"size_%d",i);
366      sprintf(mname,"mimeType_%d",i);
367      sprintf(icname,"isCached_%d",i);
368      sprintf(xname,"Reference_%d",i);
369      sprintf(bname,"body_%d",i);
370      sprintf(hname,"headers_%d",i);
371      sprintf(oname,"Order_%d",i);
372      sprintf(ufile,"use_file_%d",i);
373    }else{
374      sprintf(cname,"cache_file");
375      sprintf(vname,"value");
376      sprintf(sname,"size");
377      sprintf(mname,"mimeType");
378      sprintf(icname,"isCached");
379      sprintf(xname,"Reference");
380      sprintf(bname,"body");
381      sprintf(hname,"headers");
382      sprintf(oname,"Order");
383      sprintf(ufile,"use_file");
384    }
385   
386    map* tmap=getMap(content->content,oname);
387    sprintf(sindex,"%d",*index+1);
388    if((tmp1=getMap(content->content,xname))!=NULL && tmap!=NULL && strcasecmp(tmap->value,sindex)==0){
389
390      if(getMap(content->content,icname)==NULL) {
391        if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
392          fcontent=(char*)malloc((hInternet->ihandle[*index].nDataLen+1)*sizeof(char));
393          if(fcontent == NULL){
394            errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
395            return -1;
396          }
397          size_t dwRead;
398          InternetReadFile(hInternet->ihandle[*index], 
399                           (LPVOID)fcontent, 
400                           hInternet->ihandle[*index].nDataLen, 
401                           &dwRead);
402          fcontent[hInternet->ihandle[*index].nDataLen]=0;
403        }
404        fsize=hInternet->ihandle[*index].nDataLen;
405        if(hInternet->ihandle[*index].mimeType==NULL)
406          mimeType=zStrdup("none");
407        else
408          mimeType=zStrdup(hInternet->ihandle[*index].mimeType);             
409       
410        map* tmpMap=getMapOrFill(&(*in)->content,vname,"");
411        if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
412          free(tmpMap->value);
413          tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
414          if(tmpMap->value==NULL){
415            return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
416          }
417          memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
418        }else
419          addToMap((*in)->content,ufile,"true");
420        if(hInternet->ihandle[*index].code!=200){
421          char *error_rep_str=_("Unable to download the file for the input <%s>, response code was : %d.");
422          char *error_msg=(char*)malloc((strlen(error_rep_str)+strlen(content->name)+4)*sizeof(char));
423          sprintf(error_msg,error_rep_str,content->name,hInternet->ihandle[*index].code);
424          if(*error==NULL){
425            *error=createMap("text",error_msg);
426            addToMap(*error,"locator",content->name);
427            addToMap(*error,"code","InvalidParameterValue");
428          }else{
429            int nb=1;
430            map* tmpMap=getMap(*error,"length");
431            if(tmpMap!=NULL)
432              nb=atoi(tmpMap->value);
433            setMapArray(*error,"text",nb,error_msg);
434            setMapArray(*error,"locator",nb,content->name);
435            setMapArray(*error,"code",nb,"InvalidParameterValue");
436          }
437          return -1;
438        }
439       
440        char ltmp1[256];
441        sprintf(ltmp1,"%d",fsize);
442        map* tmp=getMapFromMaps(*m,"main","cacheDir");
443        char *request=NULL;
444        if(tmp!=NULL){
445          map* tmp2;
446          char* md5str=NULL;
447          if((tmp2=getMap(content->content,bname))!=NULL){
448            char *tmpStr=(char*)malloc((strlen(tmp1->value)+strlen(tmp2->value)+1)*sizeof(char));
449            sprintf(tmpStr,"%s%s",tmp1->value,tmp2->value);
450            if((tmp2=getMap(content->content,"headers"))!=NULL){
451              char *tmpStr2=zStrdup(tmpStr);
452              free(tmpStr);
453              tmpStr=(char*)malloc((strlen(tmpStr2)+strlen(tmp2->value)+1)*sizeof(char));
454              sprintf(tmpStr,"%s%s",tmpStr2,tmp2->value);
455              free(tmpStr2);
456            }
457            md5str=getMd5(tmpStr);
458            request=zStrdup(tmpStr);
459            free(tmpStr);
460          }else{
461            char *myRequest=getFilenameForRequest(*m,tmp1->value);
462            md5str=getMd5(myRequest);
463            request=zStrdup(tmp1->value);
464            free(myRequest);
465          }
466          char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
467          sprintf(fname,"%s/%s.zca",tmp->value,md5str);
468          addToMap((*in)->content,cname,fname);
469          free(fname);
470        }
471        addToMap((*in)->content,sname,ltmp1);
472        addToMap((*in)->content,mname,mimeType);
473        if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
474          addToCache(*m,request,fcontent,mimeType,fsize, NULL, 0);
475          free(fcontent);
476        }else{
477          addToMap((*in)->content,ufile,"true");
478          cacheFile(*m,request,mimeType,fsize,hInternet->ihandle[*index].filename);
479        }
480        free(mimeType);
481        free(request);
482        (*index)++;
483      }
484    }
485  }
486  if(shouldClean>0){
487    freeMap(&length);
488    free(length);
489  }
490  return 0;
491}
492
493/**
494 * Effectively run all the HTTP requests in the queue
495 *
496 * @param m the maps containing the settings of the main.cfg file
497 * @param inputs the maps containing the inputs (defined in the requests+added
498 *  per default based on the zcfg file)
499 * @param hInternet the HINTERNET pointer
500 * @param error the error map pointer
501 * @return 0 on success, -1 on failure
502 */
503int runHttpRequests(maps** m,maps** inputs,HINTERNET* hInternet,map** error){
504  int hasAFailure=0;
505  if(hInternet!=NULL && hInternet->nb>0){
506    AddHeaderEntries(hInternet,*m);
507    processDownloads(hInternet);
508    maps* content=*inputs;
509    int index=0;
510    while(content!=NULL){
511      if(content->child!=NULL){
512        maps* cursor=content->child;
513        while(cursor!=NULL){
514          int red=readCurrentInput(m,&cursor,&index,hInternet,error);
515          if(red<0)
516            hasAFailure=red;
517          cursor=cursor->next;
518        }
519      }
520      else{
521        int red=readCurrentInput(m,&content,&index,hInternet,error);
522        if(red<0)
523          hasAFailure=red;
524      }
525      content=content->next;
526    }
527  }
528  return hasAFailure;
529}
530
531/**
532 * Add a request in the download queue
533 *
534 * @param m the maps containing the settings of the main.cfg file
535 * @param url the url to add to the queue
536 */
537void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
538  hInternet->waitingRequests[hInternet->nb]=strdup(url);
539  if(req)
540    InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0,*m);
541  maps *oreq=getMaps(*m,"orequests");
542  if(oreq==NULL){
543    oreq=createMaps("orequests");
544    oreq->content=createMap("value",url);
545    addMapsToMaps(m,oreq);
546    freeMaps(&oreq);
547    free(oreq);
548  }else{
549    setMapArray(oreq->content,"value",hInternet->nb,url);
550  }
551}
552
553/**
554 * Try to load file from cache or download a remote file if not in cache
555 *
556 * @param m the maps containing the settings of the main.cfg file
557 * @param content the map to update
558 * @param hInternet the HINTERNET pointer
559 * @param url the url to fetch
560 * @return 0
561 */
562int loadRemoteFile(maps** m,map** content,HINTERNET* hInternet,char *url){
563  char* fcontent = NULL;
564  char* cached=isInCache(*m,url);
565  char *mimeType=NULL;
566  int fsize=0;
567  map* memUse=getMapFromMaps(*m,"main","memory");
568
569  map* t=getMap(*content,"xlink:href");
570  if(t==NULL){
571    t=getMap((*content),"href");
572    addToMap(*content,"xlink:href",url);
573  }
574
575  if(cached!=NULL){
576    struct stat f_status;
577    int s=stat(cached, &f_status);
578    if(s==0){
579      zooLock* lck=lockFile(*m,cached,'r');
580      if(lck==NULL)
581        return -1;
582      fsize=f_status.st_size;
583      if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
584        fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
585        FILE* f=fopen(cached,"rb");
586        if(f!=NULL){
587          fread(fcontent,f_status.st_size,1,f);
588          fcontent[fsize]=0;
589          fclose(f);
590        }
591      }
592      addToMap(*content,"cache_file",cached);
593      unlockFile(*m,lck);
594    }
595    cached[strlen(cached)-1]='m';
596    s=stat(cached, &f_status);
597    if(s==0){
598      zooLock* lck=lockFile(*m,cached,'r');
599      if(lck==NULL)
600        return -1;
601      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
602      FILE* f=fopen(cached,"rb");
603      fread(mimeType,f_status.st_size,1,f);
604      mimeType[f_status.st_size]=0;
605      fclose(f);
606      unlockFile(*m,lck);
607    }
608  }else{   
609    addRequestToQueue(m,hInternet,url,true);
610    return 0;
611  }
612  if(fsize==0){
613    return errorException(*m, _("Unable to download the file."), "InternalError",NULL);
614  }
615  if(mimeType!=NULL){
616    addToMap(*content,"fmimeType",mimeType);
617  }
618
619  map* tmpMap=getMapOrFill(content,"value","");
620  if(memUse!=NULL && strcasecmp(memUse->value,"load")==0){
621    free(tmpMap->value);
622    tmpMap->value=(char*)malloc((fsize+1)*sizeof(char));
623    if(tmpMap->value==NULL || fcontent == NULL)
624      return errorException(*m, _("Unable to allocate memory"), "InternalError",NULL);
625    memcpy(tmpMap->value,fcontent,(fsize+1)*sizeof(char));
626  }
627 
628  char ltmp1[256];
629  sprintf(ltmp1,"%d",fsize);
630  addToMap(*content,"size",ltmp1);
631  if(cached==NULL){
632    if(memUse!=NULL && strcasecmp(memUse->value,"load")==0)
633      addToCache(*m,url,fcontent,mimeType,fsize, NULL, 0);
634    else
635      cacheFile(*m,url,mimeType,fsize,hInternet->ihandle[hInternet->nb-1].filename);
636  }
637  else{
638    addToMap(*content,"isCached","true");
639    map* tmp=getMapFromMaps(*m,"main","cacheDir");
640    if(tmp!=NULL){
641      map *c=getMap((*content),"xlink:href");
642      if(strncasecmp(c->value,"file://",7)!=0){
643        char *myRequest=getFilenameForRequest(*m,c->value);
644        char* md5str=getMd5(myRequest);
645        free(myRequest);
646        char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
647        sprintf(fname,"%s/%s.zca",tmp->value,md5str);
648        addToMap(*content,"cache_file",fname);
649        free(fname);
650        free(md5str);
651      }
652    }
653  }
654  free(fcontent);
655  free(mimeType);
656  free(cached);
657  return 0;
658}
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png