Changeset 291


Ignore:
Timestamp:
Aug 3, 2011, 3:17:10 PM (13 years ago)
Author:
djay
Message:

Update cache to use md5 as described in #51.

Location:
trunk/zoo-kernel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal.c

    r289 r291  
    22992299
    23002300
     2301unsigned 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
    23012323/**
    23022324 * Cache a file for a given request
     
    23072329    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+6));
    23082330    sprintf(fname,"%s/list",tmp->value);
     2331#ifdef DEBUG
    23092332    fprintf(stderr,"Cache list : %s\n",fname);
    23102333    fflush(stderr);
     2334#endif
    23112335    struct stat f_status;
    23122336    int s=stat(fname, &f_status);
     
    23222346    if(f_status.st_size>=0){
    23232347      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
    23262353      fprintf(stderr,"Cache file : %s\n",foname);
    23272354      fflush(stderr);
    2328       FILE* fo=fopen(foname,"w+");
     2355#endif
     2356      FILE* fo=fopen(fonames,"w+");
    23292357      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);     
    23322363      fwrite(fcontent,sizeof(char),strlen(fcontent),f);
    23332364      fwrite(content,sizeof(char),length,fo);
     
    23392370
    23402371char* 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);
    23452380    struct stat f_status;
    23462381    int s=stat(fname, &f_status);
     
    23582393        while(tmp1!=NULL){
    23592394          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)
    23632407            hv=1;
    23642408          tmp1=strtok_r(NULL,"|",&svt1);
     
    23682412      }
    23692413      fclose(f);
    2370     }
     2414      free(fcontent);
     2415    }
     2416    free(md5str);
     2417    free(fname);
    23712418  }
    23722419  return NULL;
  • trunk/zoo-kernel/service_internal.h

    r284 r291  
    5353#include "service.h"
    5454#include <openssl/sha.h>
     55#include <openssl/md5.h>
    5556#include <openssl/hmac.h>
    5657#include <openssl/evp.h>
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

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