Changeset 877 for branches/prototype-v0/zoo-project/zoo-kernel/caching.c
- Timestamp:
- Aug 16, 2018, 8:00:56 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/caching.c
r872 r877 23 23 */ 24 24 25 #include <openssl/md5.h> 26 #include <openssl/evp.h> 25 27 #include "caching.h" 26 28 #include "service.h" 27 29 #include "service_internal.h" 28 30 #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 31 35 32 /** … … 61 58 return fresult; 62 59 } 60 61 /** 62 * Compute md5 of a file 63 * 64 * @param file the char* 65 * @return a char* representing the md5 of the url 66 * @warning make sure to free resources returned by this function 67 */ 68 char* getMd5f(char* file){ 69 EVP_MD_CTX md5ctx; 70 char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); 71 unsigned char result[EVP_MAX_MD_SIZE]; 72 unsigned int len; 73 int bytes; 74 unsigned char data[1024]; 75 FILE *inFile = fopen (file, "rb"); 76 EVP_DigestInit(&md5ctx, EVP_md5()); 77 while ((bytes = fread (data, 1, 1024, inFile)) != 0) 78 EVP_DigestUpdate(&md5ctx, data, bytes); 79 EVP_DigestFinal_ex(&md5ctx,result,&len); 80 EVP_MD_CTX_cleanup(&md5ctx); 81 int i; 82 for(i = 0; i < len; i++){ 83 if(i>0){ 84 char *tmp=zStrdup(fresult); 85 sprintf(fresult,"%s%02x", tmp,result[i]); 86 free(tmp); 87 } 88 else 89 sprintf(fresult,"%02x",result[i]); 90 } 91 fclose (inFile); 92 return fresult; 93 } 94 63 95 64 96 … … 145 177 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 146 178 char contentr[4096]; 179 char* md5fstr=NULL; 147 180 int cred=0; 148 181 if(tmp!=NULL){ … … 183 216 fclose(fo); 184 217 fclose(fi); 185 218 219 // Store mimeType 186 220 sprintf(fname,"%s/%s.zcm",tmp->value,md5str); 187 221 fo=fopen(fname,"w+"); … … 192 226 fclose(fo); 193 227 228 // Store provenance 194 229 sprintf(fname,"%s/%s.zcp",tmp->value,md5str); 195 230 fo=fopen(fname,"w+"); … … 199 234 #endif 200 235 fwrite(origin,sizeof(char),strlen(origin),fo); 236 fclose(fo); 237 238 // Store md5 239 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 240 md5fstr=getMd5f(fname); 241 sprintf(fname,"%s/%s.zmd",tmp->value,md5str); 242 fo=fopen(fname,"w+"); 243 #ifdef DEBUG 244 fprintf(stderr,"MD5: %s\n",md5fstr); 245 #endif 246 fwrite(md5fstr,sizeof(char),strlen(md5fstr),fo); 247 free(md5fstr); 201 248 fclose(fo); 202 249
Note: See TracChangeset
for help on using the changeset viewer.