Ignore:
Timestamp:
Nov 21, 2017, 10:24:14 AM (6 years ago)
Author:
djay
Message:

HPC support update. Add inputs for create options in Gdal_Dem.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/caching.c

    r839 r854  
    6464
    6565/**
     66 * Create a URL by appending every request header listed in the security
     67 * section.This imply that the URL will contain any authentication
     68 * informations that should be fowarded to the server from which de input
     69 * was download.
     70 * @param conf the main configuration maps
     71 * @param request the URL to transform.
     72 * @return a char* that contain the original URL plus potential header (only for
     73 * hosts that are not shared).
     74 * @warning Be sure to free the memory returned by this function.
     75 */
     76char* getFilenameForRequest(maps* conf, const char* request){
     77  map* passThrough=getMapFromMaps(conf,"security","attributes");
     78  map* targetHosts=getMapFromMaps(conf,"security","hosts");
     79  char* passedHeader[10];
     80  int cnt=0;
     81  char *res=zStrdup(request);
     82  char *toAppend=NULL;
     83  if(passThrough!=NULL && targetHosts!=NULL){
     84    char *tmp=zStrdup(passThrough->value);
     85    char *token, *saveptr;
     86    token = strtok_r (tmp, ",", &saveptr);
     87    int i;
     88    if((strstr(targetHosts->value,"*")!=NULL || isProtectedHost(targetHosts->value,request)==1) && strncasecmp(getProvenance(conf,request),"SHARED",6)!=0){
     89      while (token != NULL){
     90        int length=strlen(token)+6;
     91        char* tmp1=(char*)malloc(length*sizeof(char));
     92        map* tmpMap;
     93        snprintf(tmp1,6,"HTTP_");
     94        int j;
     95        for(j=0;token[j]!='\0';j++){
     96          if(token[j]!='-')
     97            tmp1[5+j]=toupper(token[j]);
     98          else
     99            tmp1[5+j]='_';
     100          tmp1[5+j+1]='\0';
     101        }
     102        tmpMap = getMapFromMaps(conf,"renv",tmp1);
     103        if(tmpMap!=NULL){
     104          if(toAppend==NULL){
     105            toAppend=(char*)malloc((strlen(tmpMap->value)+1)*sizeof(char));
     106            sprintf(toAppend,"%s",tmpMap->value);
     107          }else{
     108            char *tmp3=zStrdup(toAppend);
     109            toAppend=(char*)realloc(toAppend,(strlen(tmpMap->value)+strlen(tmp3)+2)*sizeof(char));
     110            sprintf(toAppend,"%s,%s",tmp3,tmpMap->value);
     111            free(tmp3);
     112          }
     113        }
     114        free(tmp1);
     115        cnt+=1;
     116        token = strtok_r (NULL, ",", &saveptr);
     117      }
     118    }
     119    free(tmp);
     120  }
     121  if(toAppend!=NULL){
     122    char *tmp3=zStrdup(res);
     123    res=(char*)realloc(res,(strlen(tmp3)+strlen(toAppend)+1)*sizeof(char));
     124    sprintf(res,"%s%s",tmp3,toAppend);
     125    free(tmp3);
     126    free(toAppend);
     127  }
     128  return res;
     129}
     130
     131/**
    66132 * Cache a file for a given request.
    67133 * For each cached file, the are two files stored, a .zca and a .zcm containing
     
    80146  map* tmp=getMapFromMaps(conf,"main","cacheDir");
    81147  if(tmp!=NULL){
    82     char* md5str=getMd5(request);
     148    char* myRequest=getFilenameForRequest(conf,request);
     149    char* md5str=getMd5(myRequest);
     150    free(myRequest);
    83151    char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
    84152    sprintf(fname,"%s/%s.zca",tmp->value,md5str);
     153    zooLock* lck=lockFile(conf,fname,'w');
     154    if(lck!=NULL){
    85155#ifdef DEBUG
    86     fprintf(stderr,"Cache list : %s\n",fname);
    87     fflush(stderr);
     156      fprintf(stderr,"Cache list : %s\n",fname);
     157      fflush(stderr);
    88158#endif
    89     FILE* fo=fopen(fname,"w+");
    90     if(fo==NULL){
     159      FILE* fo=fopen(fname,"w+");
     160      if(fo==NULL){
    91161#ifdef DEBUG
    92       fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
     162        fprintf (stderr, "Failed to open %s for writing: %s\n",fname, strerror(errno));
    93163#endif
    94       filepath = NULL; 
    95       return;
    96     }
    97     fwrite(content,sizeof(char),length,fo);
    98     fclose(fo);
     164        filepath = NULL;
     165        unlockFile(conf,lck);
     166        return;
     167      }
     168      fwrite(content,sizeof(char),length,fo);
     169      unlockFile(conf,lck);
     170      fclose(fo);
    99171       
    100         if (filepath != NULL) {
    101                 strncpy(filepath, fname, max_path);
    102         }       
    103 
    104     sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
    105     fo=fopen(fname,"w+");
     172      if (filepath != NULL) {
     173        strncpy(filepath, fname, max_path);
     174      }
     175
     176      sprintf(fname,"%s/%s.zcm",tmp->value,md5str);
     177      fo=fopen(fname,"w+");
    106178#ifdef DEBUG
    107     fprintf(stderr,"MIMETYPE: %s\n",mimeType);
     179      fprintf(stderr,"MIMETYPE: %s\n",mimeType);
    108180#endif
    109     fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
    110     fclose(fo);
    111 
    112     free(md5str);
    113     free(fname);
     181      fwrite(mimeType,sizeof(char),strlen(mimeType),fo);
     182      fclose(fo);
     183
     184      sprintf(fname,"%s/%s.zcp",tmp->value,md5str);
     185      fo=fopen(fname,"w+");
     186      char* origin=getProvenance(conf,request);
     187#ifdef DEBUG
     188      fprintf(stderr,"ORIGIN: %s\n",mimeType);
     189#endif
     190      fwrite(origin,sizeof(char),strlen(origin),fo);
     191      fclose(fo);
     192
     193      free(md5str);
     194      free(fname);
     195    }
    114196  }
    115197  else {
    116           filepath = NULL;
     198    filepath = NULL;
    117199  }       
    118200}
     
    129211  map* tmpM=getMapFromMaps(conf,"main","cacheDir");
    130212  if(tmpM!=NULL){
    131     char* md5str=getMd5(request);
     213    char* myRequest=getFilenameForRequest(conf,request);
     214    char* md5str=getMd5(myRequest);
     215    free(myRequest);
    132216#ifdef DEBUG
    133217    fprintf(stderr,"MD5STR : (%s)\n\n",md5str);
     
    206290      sprintf(xname,"Reference");
    207291      sprintf(bname,"body");
    208       sprintf(hname,"headers",i);
     292      sprintf(hname,"headers");
    209293      sprintf(oname,"Order");
    210294    }
     
    280364            free(tmpStr);
    281365          }else{
    282             md5str=getMd5(tmp1->value);
     366            char *myRequest=getFilenameForRequest(*m,tmp1->value);
     367            md5str=getMd5(myRequest);
    283368            request=zStrdup(tmp1->value);
     369            free(myRequest);
    284370          }
    285371          char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
     
    387473
    388474  if(cached!=NULL){
    389 
    390475    struct stat f_status;
    391476    int s=stat(cached, &f_status);
    392477    if(s==0){
     478      zooLock* lck=lockFile(*m,cached,'r');
     479      if(lck==NULL)
     480        return -1;
    393481      fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    394482      FILE* f=fopen(cached,"rb");
     
    398486      fclose(f);
    399487      addToMap(*content,"cache_file",cached);
     488      unlockFile(*m,lck);
    400489    }
    401490    cached[strlen(cached)-1]='m';
    402491    s=stat(cached, &f_status);
    403492    if(s==0){
     493      zooLock* lck=lockFile(*m,cached,'r');
     494      if(lck==NULL)
     495        return -1;
    404496      mimeType=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    405497      FILE* f=fopen(cached,"rb");
     
    407499      mimeType[f_status.st_size]=0;
    408500      fclose(f);
    409     }
    410 
     501      unlockFile(*m,lck);
     502    }
    411503  }else{   
    412504    addRequestToQueue(m,hInternet,url,true);
     
    439531    if(tmp!=NULL){
    440532      map *c=getMap((*content),"xlink:href");
    441       char* md5str=getMd5(c->value);
     533      char *myRequest=getFilenameForRequest(*m,c->value);
     534      char* md5str=getMd5(myRequest);
     535      free(myRequest);
    442536      char* fname=(char*)malloc(sizeof(char)*(strlen(tmp->value)+strlen(md5str)+6));
    443537      sprintf(fname,"%s/%s.zca",tmp->value,md5str);
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