/***************************************************************************/ /* */ /* Fast Webpage Exchanger - an FTP client for updating webpages */ /* Copyright (C) 1999-2000 Yuuki NINOMIYA */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2, or (at your option) */ /* any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the */ /* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */ /* Boston, MA 02111-1307, USA. */ /* */ /***************************************************************************/ #ifdef HAVE_CONFIG_H # include "config.h" #endif #include #include #include #include "intl.h" #include "strlib.h" #include "variable.h" #include "proto.h" static Cache_dir *cache_dir; static int max_cache_dir; /* -------------------------------------------------- NAME load_cache FUNCTION load cache of time stamp OUTPUT none -------------------------------------------------- */ void load_cache(void) { char *temp; FILE *fp; char *read_temp; Cache *cache; int max_cache_file; char *date,*time,*name; int i; cache_dir=NULL; max_cache_file=max_cache_dir=0; is_cache_existent=0; temp=str_concat(getenv("HOME"),"/.weex/weex.cache.",cfgSectionNumberToName(host_number),NULL); if(rebuild_cache){ fprintf(stderr,_("Rebuilding cache file `%s'.\n"),temp); free(temp); return; } fp=fopen(temp,"r"); if(fp==NULL){ fprintf(stderr,_("Cache file `%s' does not exist."),temp); if(!opt_test){ fprintf(stderr,_(" Creating a new one.\n")); }else{ fprintf(stderr,"\n"); } free(temp); return; } for(i=0;(read_temp=str_fgets(fp))!=NULL;i++){ date=strtok(read_temp," "); time=strtok(NULL," "); if(date==NULL || time==NULL){ fprintf(stderr,_("Cache file `%s' is broken at line %d.\n"),temp,i+1); exit(1); } name=time+strlen(time)+1; if(name==NULL || (i==0 && strcmp(date,"00000000")!=0)){ fprintf(stderr,_("Cache file `%s' is broken at line %d.\n"),temp,i+1); exit(1); } if(strcmp(date,"00000000")==0){ /* directory */ cache_dir=str_realloc(cache_dir,(max_cache_dir+1)*sizeof(*cache_dir)); cache_dir[max_cache_dir].name=str_dup(name); cache_dir[max_cache_dir].ptr=NULL; if(max_cache_dir>0){ cache_dir[max_cache_dir-1].max_file=max_cache_file; } max_cache_dir++; max_cache_file=0; }else{ /* file */ cache_dir[max_cache_dir-1].ptr=str_realloc(cache_dir[max_cache_dir-1].ptr,(max_cache_file+1)*sizeof(*cache_dir[max_cache_dir-1].ptr)); cache=cache_dir[max_cache_dir-1].ptr; cache[max_cache_file].name=str_dup(name); cache[max_cache_file].date=atol(date); cache[max_cache_file].time=atol(time); max_cache_file++; } free(read_temp); } if(max_cache_dir>0){ cache_dir[max_cache_dir-1].max_file=max_cache_file; } fclose(fp); free(temp); is_cache_existent=1; } /* -------------------------------------------------- NAME find_cache FUNCTION find the file in the cache INPUT cache_dir_num ... the number of directory in a cache file_name ... file name OUTPUT pointer to cached file data return NULL if not found -------------------------------------------------- */ Cache *find_cache(char *file_name) { int i; int cache_dir_num; Cache *cache; cache_dir_num=find_cache_dir(current_dir[REMOTE]); if(cache_dir_num<0){ /* no such a directory */ return(NULL); } cache=cache_dir[cache_dir_num].ptr; if(cache==NULL){ /* no files in the directory */ return(NULL); } for(i=0;i=0){ free(cache_dir[cache_dir_num].name); cache_dir[cache_dir_num].name=NULL; } } void update_cache_directory(char *dir) { if(find_cache_dir(dir)<0){ cache_dir=str_realloc(cache_dir,sizeof(*cache_dir)*(max_cache_dir+1)); cache_dir[max_cache_dir].name=str_dup(dir); cache_dir[max_cache_dir].max_file=0; cache_dir[max_cache_dir].ptr=NULL; max_cache_dir++; } } int find_cache_dir(char *name) { int i; for(i=0;i