Changeset 291
- Timestamp:
- Aug 3, 2011, 3:17:10 PM (13 years ago)
- Location:
- trunk/zoo-kernel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/service_internal.c
r289 r291 2299 2299 2300 2300 2301 unsigned char* getMd5(char* url){ 2302 EVP_MD_CTX md5ctx; 2303 unsigned char* fresult=(char*)malloc((EVP_MAX_MD_SIZE+1)*sizeof(char)); 2304 unsigned char result[EVP_MAX_MD_SIZE]; 2305 unsigned int len; 2306 EVP_DigestInit(&md5ctx, EVP_md5()); 2307 EVP_DigestUpdate(&md5ctx, url, strlen(url)); 2308 EVP_DigestFinal_ex(&md5ctx,result,&len); 2309 EVP_MD_CTX_cleanup(&md5ctx); 2310 int i; 2311 for(i = 0; i < len; i++){ 2312 if(i>0){ 2313 char *tmp=strdup(fresult); 2314 sprintf(fresult,"%s%02x", tmp,result[i]); 2315 free(tmp); 2316 } 2317 else 2318 sprintf(fresult,"%02x",result[i]); 2319 } 2320 return fresult; 2321 } 2322 2301 2323 /** 2302 2324 * Cache a file for a given request … … 2307 2329 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+6)); 2308 2330 sprintf(fname,"%s/list",tmp->value); 2331 #ifdef DEBUG 2309 2332 fprintf(stderr,"Cache list : %s\n",fname); 2310 2333 fflush(stderr); 2334 #endif 2311 2335 struct stat f_status; 2312 2336 int s=stat(fname, &f_status); … … 2322 2346 if(f_status.st_size>=0){ 2323 2347 FILE* f=fopen(fname,"a+"); 2324 char* foname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+64)); 2325 sprintf(foname,"%s/%d.zca",tmp->value,f_status.st_size); 2348 char* foname=(char*)malloc(sizeof(char)*65); 2349 char* fonames=(char*)malloc(sizeof(char)*(strlen(tmp->value)+70)); 2350 sprintf(foname,"%d",f_status.st_size); 2351 sprintf(fonames,"%s/%s.zca",tmp->value,foname); 2352 #ifdef DEBUG 2326 2353 fprintf(stderr,"Cache file : %s\n",foname); 2327 2354 fflush(stderr); 2328 FILE* fo=fopen(foname,"w+"); 2355 #endif 2356 FILE* fo=fopen(fonames,"w+"); 2329 2357 char *fcontent=(char*)malloc(sizeof(char)*(strlen(foname)+strlen(request)+3)); 2330 sprintf(fcontent,"%s|%s\n",request,foname); 2331 2358 unsigned char* md5str=getMd5(request); 2359 sprintf(fcontent,"%s|%s\n",md5str,foname); 2360 free(md5str); 2361 free(foname); 2362 free(fonames); 2332 2363 fwrite(fcontent,sizeof(char),strlen(fcontent),f); 2333 2364 fwrite(content,sizeof(char),length,fo); … … 2339 2370 2340 2371 char* isInCache(maps* conf,char* request){ 2341 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 2342 if(tmp!=NULL){ 2343 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+6)); 2344 sprintf(fname,"%s/list",tmp->value); 2372 map* tmpM=getMapFromMaps(conf,"main","cacheDir"); 2373 if(tmpM!=NULL){ 2374 unsigned char* md5str=getMd5(request); 2375 #ifdef DEBUG 2376 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 2377 #endif 2378 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+6)); 2379 sprintf(fname,"%s/list",tmpM->value); 2345 2380 struct stat f_status; 2346 2381 int s=stat(fname, &f_status); … … 2358 2393 while(tmp1!=NULL){ 2359 2394 fprintf(stderr,"%s %s\n",tmp1,request); 2360 if(hv>0) 2361 return tmp1; 2362 if(strcasecmp(tmp1,request)==0) 2395 if(hv>0){ 2396 char* foname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+68)); 2397 sprintf(foname,"%s/%s.zca",tmpM->value,tmp1); 2398 free(md5str); 2399 free(fname); 2400 free(fcontent); 2401 #ifdef DEBUG 2402 fprintf(stderr,"Cache file : %s\n",foname); 2403 #endif 2404 return foname; 2405 } 2406 if(strcasecmp(tmp1,md5str)==0) 2363 2407 hv=1; 2364 2408 tmp1=strtok_r(NULL,"|",&svt1); … … 2368 2412 } 2369 2413 fclose(f); 2370 } 2414 free(fcontent); 2415 } 2416 free(md5str); 2417 free(fname); 2371 2418 } 2372 2419 return NULL; -
trunk/zoo-kernel/service_internal.h
r284 r291 53 53 #include "service.h" 54 54 #include <openssl/sha.h> 55 #include <openssl/md5.h> 55 56 #include <openssl/hmac.h> 56 57 #include <openssl/evp.h>
Note: See TracChangeset
for help on using the changeset viewer.