/***************************************************************************/ /* */ /* 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 #include #include #include #include "intl.h" #include "strlib.h" #include "variable.h" #include "proto.h" #ifndef PATH_MAX # define PATH_MAX 512 #endif /* PATH_MAX */ /* -------------------------------------------------- NAME get_local_file_data FUNCTION get the data of local files INPUT local_data ... pointer to stored date OUTPUT the maximum number of local files -------------------------------------------------- */ int get_local_file_data(FileData **local_data) { DIR *dir; struct dirent *ent; struct stat file_stat; struct tm *ftime; char time_temp[10]; char date_temp[10]; int isdir; int file_num=0; int i; dir=opendir("."); while((ent=readdir(dir))!=NULL){ if(strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0){ continue; } lstat(ent->d_name,&file_stat); /* follow symlinks */ if (follow_symlinks[host_number] && (file_stat.st_mode & S_IFLNK)==S_IFLNK){ char realfname[PATH_MAX]; DebugPrint((stderr,"Local symlink is detected: %s\n",ent->d_name)); if(realpath(ent->d_name,realfname)==NULL){ char *temp; fprintf(stderr,_("Cannot expand symbolic link `%s'. Ignore this file.\n"),ent->d_name); temp=str_dup_printf(_("Expanding symbolic link failed: %s"),ent->d_name); log_write(temp); free(temp); continue; } stat(realfname,&file_stat); DebugPrint((stderr,"Realfname is %s\n",realfname)); } isdir = ((file_stat.st_mode & S_IFDIR) == S_IFDIR); ftime=gmtime(&file_stat.st_mtime); if(isdir){ if(is_ignore_dir(ent->d_name,LOCAL)){ DebugPrint((stderr,"Ignore local dir: %s\n",ent->d_name)); continue; } }else{ if(is_ignore_file(ent->d_name,LOCAL)){ DebugPrint((stderr,"Ignore local file: %s\n",ent->d_name)); continue; } } sprintf(date_temp,"%04d%02d%02d",1900+ftime->tm_year,ftime->tm_mon+1,ftime->tm_mday); sprintf(time_temp,"%02d%02d%02d",ftime->tm_hour,ftime->tm_min,ftime->tm_sec); *local_data=str_realloc(*local_data,sizeof(**local_data)*(file_num+1)); (*local_data)[file_num].date=atol(date_temp); (*local_data)[file_num].time=atol(time_temp); (*local_data)[file_num].isdir=isdir; (*local_data)[file_num].name=str_dup(ent->d_name); DebugPrint((stderr,"Local: [%08ld] [%06ld] [%08o] [%d] [%s]\n",(*local_data)[file_num].date,(*local_data)[file_num].time,file_stat.st_mode,(*local_data)[file_num].isdir,(*local_data)[file_num].name)); if(conv_to_lower[host_number]){ for(i=0;i")==0) ? 'd' : '-'; }else{ /* Remote system type is UNIX or MACOS */ dir_flag=str[0]; for(i=0;i<7;i++){ if((ptr=strtok(NULL," "))==NULL){ fprintf(stderr,_("Cannot get the remote directory list correctly.\n")); ftp_disconnect(); exit(1); } if((i==0 && strcmp(ptr,"folder")==0) || (i==1 && strcmp(ptr,"0000/0000")==0) || (i==3 && isupper(*ptr) && islower(*(ptr+1)) && islower(*(ptr+2)) && *(ptr+3)=='\0')){ i++; } } } ptr=ptr+strlen(ptr)+1; if((lnktmp=strstr(ptr," -> "))!=NULL){ /* This file is a symbolic link. */ *lnktmp='\0'; } /* Strip leading spaces from the filename which can occur with an FTP server based on Windows NT */ while (*ptr == ' '){ ptr++; } *file=str_dup(ptr); return(dir_flag); } /* -------------------------------------------------- NAME is_ignore_dir FUNCTION whether ???IgnoreDir or not INPUT dir_name ... name of the directory side ....... LOCAL or REMOTE OUTPUT return 1 if match ???IgnoreDir otherwise return 0 -------------------------------------------------- */ int is_ignore_dir(char *dir_name,LocalOrRemote side) { cfgList *l; char *temp; if((side==LOCAL && ignore_local_dir[host_number]==NULL) || (side==REMOTE && ignore_remote_dir[host_number]==NULL)){ return(0); } temp=str_concat(current_dir[side],dir_name,"/",NULL); if(side==LOCAL){ for(l=ignore_local_dir[host_number];l!=NULL;l=l->next){ if(cmp_file_with_wildcard(temp,l->str)==0){ free(temp); return(1); } } }else if(side==REMOTE){ for(l=ignore_remote_dir[host_number];l!=NULL;l=l->next){ if(cmp_file_with_wildcard(temp,l->str)==0){ free(temp); return(1); } } } free(temp); return(0); } /* -------------------------------------------------- NAME is_ignore_file FUNCTION whether ???IgnoreFile or not INPUT file_name ... file name side ........ LOCAL or REMOTE OUTPUT return 1 if match ???IgnoreFile otherwise return 0 -------------------------------------------------- */ int is_ignore_file(char *file_name,LocalOrRemote side) { cfgList *l; char *temp; if((side==LOCAL && ignore_local_file[host_number]==NULL) || (side==REMOTE && ignore_remote_file[host_number]==NULL)){ return(0); } temp=str_concat(current_dir[side],file_name,NULL); if(side==LOCAL){ for(l=ignore_local_file[host_number];l!=NULL;l=l->next){ if(strchr(l->str,'/')==NULL){ if(cmp_file_with_wildcard(file_name,l->str)==0){ free(temp); return(1); } }else{ if(cmp_file_with_wildcard(temp,l->str)==0){ free(temp); return(1); } } } }else if(side==REMOTE){ for(l=ignore_remote_file[host_number];l!=NULL;l=l->next){ if(strchr(l->str,'/')==NULL){ if(cmp_file_with_wildcard(file_name,l->str)==0){ free(temp); return(1); } }else{ if(cmp_file_with_wildcard(temp,l->str)==0){ free(temp); return(1); } } } } free(temp); return(0); } /* -------------------------------------------------- NAME is_ascii_file FUNCTION whether AsciiFile or not INPUT file_name ... file name OUTPUT return 1 if match AsciiFile otherwise return 0 -------------------------------------------------- */ int is_ascii_file(char *file_name) { cfgList *l; char *temp; if(ascii_file[host_number]==NULL){ return(0); } temp=str_concat(current_dir[LOCAL],file_name,NULL); for(l=ascii_file[host_number];l!=NULL;l=l->next){ if(strchr(l->str,'/')==NULL){ if(cmp_file_with_wildcard(file_name,l->str)==0){ free(temp); return(1); } }else{ if(cmp_file_with_wildcard(temp,l->str)==0){ free(temp); return(1); } } } free(temp); return(0); } /* -------------------------------------------------- NAME is_change_permission_dir FUNCTION whether ChangePermissionDir or not OUTPUT return 1 if match ChangePermissionDir otherwise return 0 -------------------------------------------------- */ int is_change_permission_dir(void) { cfgList *l; if(change_permission_dir[host_number]==NULL){ return(0); } for(l=change_permission_dir[host_number];l!=NULL;l=l->next){ if(cmp_file_with_wildcard(current_dir[LOCAL],l->str)==0){ return(1); } } return(0); } /* -------------------------------------------------- NAME is_preserve_permission_dir FUNCTION whether PreservePermissionDir or not OUTPUT return 1 if match PreservePermissionDir otherwise return 0 -------------------------------------------------- */ int is_preserve_permission_dir(void) { cfgList *l; if(preserve_permission_dir[host_number]==NULL){ return(0); } for(l=preserve_permission_dir[host_number];l!=NULL;l=l->next){ if(cmp_file_with_wildcard(current_dir[LOCAL],l->str)==0){ return(1); } } return(0); } /* -------------------------------------------------- NAME is_keep_remote_dir FUNCTION whether KeepRemoteDir or not OUTPUT return 1 if match KeepRemoteDir otherwise return 0 -------------------------------------------------- */ int is_keep_remote_dir(void) { cfgList *l; if(keep_remote_dir[host_number]==NULL){ return(0); } for(l=keep_remote_dir[host_number];l!=NULL;l=l->next){ if(cmp_file_with_wildcard(current_dir[REMOTE],l->str)==0){ return(1); } } return(0); }