Changeset 446 for trunk/zoo-project/zoo-kernel/service_internal.c
- Timestamp:
- Oct 30, 2013, 1:24:11 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-project/zoo-kernel/service_internal.c
r442 r446 2516 2516 * Cache a file for a given request 2517 2517 */ 2518 void addToCache(maps* conf,char* request,char* content, int length){2518 void addToCache(maps* conf,char* request,char* content,char* mimeType,int length){ 2519 2519 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 2520 2520 if(tmp!=NULL){ … … 2529 2529 fwrite(content,sizeof(char),length,fo); 2530 2530 fclose(fo); 2531 2532 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 2533 fo=fopen(fname,"w+"); 2534 #ifdef DEBUG 2535 fprintf(stderr,"MIMETYPE: %s\n",mimeType); 2536 #endif 2537 fwrite(mimeType,sizeof(char),strlen(mimeType),fo); 2538 fclose(fo); 2539 2531 2540 free(md5str); 2532 2541 free(fname); … … 2563 2572 char* fcontent; 2564 2573 char* cached=isInCache(m,url); 2574 char *mimeType=NULL; 2565 2575 int fsize; 2566 2576 int hasF=-1; … … 2574 2584 fsize=f_status.st_size; 2575 2585 fcontent[fsize]=0; 2586 fclose(f); 2587 } 2588 cached[strlen(cached)-1]='m'; 2589 s=stat(cached, &f_status); 2590 if(s==0){ 2591 mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 2592 FILE* f=fopen(cached,"rb"); 2593 int len=fread(mimeType,f_status.st_size,1,f); 2594 mimeType[f_status.st_size]=0; 2595 fclose(f); 2576 2596 } 2577 2597 }else{ … … 2585 2605 fcontent[res.nDataLen]=0; 2586 2606 fsize=res.nDataLen; 2607 mimeType=res.mimeType; 2587 2608 } 2588 2609 if(fsize==0){ 2589 2610 return errorException(m, _("Unable to download the file."), "InternalError"); 2611 } 2612 2613 if(mimeType!=NULL){ 2614 addToMap(content,"fmimeType",mimeType); 2590 2615 } 2591 2616 … … 2603 2628 addToMap(content,"size",ltmp1); 2604 2629 if(cached==NULL) 2605 addToCache(m,url,fcontent, fsize);2630 addToCache(m,url,fcontent,mimeType,fsize); 2606 2631 else{ 2632 free(fcontent); 2633 free(mimeType); 2607 2634 free(cached); 2608 2635 }
Note: See TracChangeset
for help on using the changeset viewer.