Changeset 292 for trunk/zoo-kernel
- Timestamp:
- Aug 3, 2011, 3:33:48 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-kernel/service_internal.c
r291 r292 2327 2327 map* tmp=getMapFromMaps(conf,"main","cacheDir"); 2328 2328 if(tmp!=NULL){ 2329 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+6)); 2330 sprintf(fname,"%s/list",tmp->value); 2329 unsigned char* md5str=getMd5(request); 2330 char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6)); 2331 sprintf(fname,"%s/%s.zca",tmp->value,md5str); 2331 2332 #ifdef DEBUG 2332 2333 fprintf(stderr,"Cache list : %s\n",fname); … … 2335 2336 struct stat f_status; 2336 2337 int s=stat(fname, &f_status); 2337 /** 2338 * If the file does not exist, create it 2339 */ 2340 if(s<0){ 2341 FILE* f=fopen(fname,"w+"); 2342 if(f) 2343 fclose(f); 2344 s=stat(fname, &f_status); 2345 } 2346 if(f_status.st_size>=0){ 2347 FILE* f=fopen(fname,"a+"); 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 2353 fprintf(stderr,"Cache file : %s\n",foname); 2354 fflush(stderr); 2355 #endif 2356 FILE* fo=fopen(fonames,"w+"); 2357 char *fcontent=(char*)malloc(sizeof(char)*(strlen(foname)+strlen(request)+3)); 2358 unsigned char* md5str=getMd5(request); 2359 sprintf(fcontent,"%s|%s\n",md5str,foname); 2338 if(f_status.st_size>0){ 2339 FILE* fo=fopen(fname,"w+"); 2340 fwrite(content,sizeof(char),length,fo); 2360 2341 free(md5str); 2361 free(foname); 2362 free(fonames); 2363 fwrite(fcontent,sizeof(char),strlen(fcontent),f); 2364 fwrite(content,sizeof(char),length,fo); 2365 fclose(f); 2342 free(fname); 2366 2343 fclose(fo); 2367 2344 } … … 2376 2353 fprintf(stderr,"MD5STR : (%s)\n\n",md5str); 2377 2354 #endif 2378 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+ 6));2379 sprintf(fname,"%s/ list",tmpM->value);2355 char* fname=(char*)malloc(sizeof(char)*(strlen(tmpM->value)+38)); 2356 sprintf(fname,"%s/%s.zca",tmpM->value,md5str); 2380 2357 struct stat f_status; 2381 2358 int s=stat(fname, &f_status); 2382 if(s==0){ 2383 char* fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 2384 FILE* f=fopen(fname,"r"); 2385 fread(fcontent,sizeof(char),f_status.st_size,f); 2386 char *tmp,*svt; 2387 tmp=strtok_r(fcontent,"\n",&svt); 2388 int lin=0; 2389 while(tmp!=NULL){ 2390 char *tmp1,*svt1; 2391 tmp1=strtok_r(tmp,"|",&svt1); 2392 int hv=-1; 2393 while(tmp1!=NULL){ 2394 fprintf(stderr,"%s %s\n",tmp1,request); 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) 2407 hv=1; 2408 tmp1=strtok_r(NULL,"|",&svt1); 2409 } 2410 lin++; 2411 tmp = strtok_r(NULL,"\n",&svt); 2412 } 2413 fclose(f); 2414 free(fcontent); 2415 } 2359 if(s==0 && f_status.st_size>0){ 2360 free(md5str); 2361 free(fname); 2362 return fname; 2363 } 2416 2364 free(md5str); 2417 2365 free(fname);
Note: See TracChangeset
for help on using the changeset viewer.