mirror of
https://github.com/bol-van/zapret.git
synced 2025-01-27 10:30:35 +05:00
tpws,nfqws: track file size in addition to mod time
This commit is contained in:
parent
02c76a4fb6
commit
aba1fdeb04
@ -367,7 +367,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
|
||||
DLOG_PERROR("write to auto hostlist:");
|
||||
return;
|
||||
}
|
||||
dp->hostlist_auto->mod_time = file_mod_time(dp->hostlist_auto->filename);
|
||||
if (!file_mod_signature(dp->hostlist_auto->filename, &dp->hostlist_auto->mod_sig))
|
||||
DLOG_PERROR("file_mod_signature");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -300,6 +300,14 @@ time_t file_mod_time(const char *filename)
|
||||
struct stat st;
|
||||
return stat(filename,&st)==-1 ? 0 : st.st_mtime;
|
||||
}
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename,&st)==-1) return false;
|
||||
ms->mod_time=st.st_mtime;
|
||||
ms->size=st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pf_in_range(uint16_t port, const port_filter *pf)
|
||||
{
|
||||
|
@ -60,6 +60,14 @@ void fill_pattern(uint8_t *buf,size_t bufsize,const void *pattern,size_t patsize
|
||||
|
||||
int fprint_localtime(FILE *F);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
time_t mod_time;
|
||||
off_t size;
|
||||
} file_mod_sig;
|
||||
#define FILE_MOD_COMPARE(ms1,ms2) (((ms1)->mod_time==(ms2)->mod_time) && ((ms1)->size==(ms2)->size))
|
||||
#define FILE_MOD_RESET(ms) memset(ms,0,sizeof(file_mod_sig))
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms);
|
||||
time_t file_mod_time(const char *filename);
|
||||
|
||||
typedef struct
|
||||
|
@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
if (!AppendHostList(&hfile->hostlist, hfile->filename))
|
||||
{
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
if (!AppendIpset(&hfile->ipset, hfile->filename))
|
||||
{
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
entry->hostlist = NULL;
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -206,7 +206,7 @@ void hostlist_files_reset_modtime(struct hostlist_files_head *list)
|
||||
struct hostlist_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
hfile->mod_time=0;
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct hostlist_item *hostlist_collection_add(struct hostlist_collection_head *head, struct hostlist_file *hfile)
|
||||
@ -390,7 +390,7 @@ struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *fi
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
memset(&entry->ipset,0,sizeof(entry->ipset));
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -427,7 +427,7 @@ void ipset_files_reset_modtime(struct ipset_files_head *list)
|
||||
struct ipset_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
hfile->mod_time=0;
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
|
||||
|
@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
|
||||
|
||||
struct hostlist_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
strpool *hostlist;
|
||||
LIST_ENTRY(hostlist_file) next;
|
||||
};
|
||||
@ -112,7 +112,7 @@ void ipsetPrint(ipset *ipset);
|
||||
|
||||
struct ipset_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
ipset ipset;
|
||||
LIST_ENTRY(ipset_file) next;
|
||||
};
|
||||
|
@ -314,6 +314,14 @@ time_t file_mod_time(const char *filename)
|
||||
struct stat st;
|
||||
return stat(filename, &st) == -1 ? 0 : st.st_mtime;
|
||||
}
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename,&st)==-1) return false;
|
||||
ms->mod_time=st.st_mtime;
|
||||
ms->size=st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pf_in_range(uint16_t port, const port_filter *pf)
|
||||
{
|
||||
|
@ -62,6 +62,14 @@ static inline void phton16(uint8_t *p, uint16_t v) {
|
||||
|
||||
int fprint_localtime(FILE *F);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
time_t mod_time;
|
||||
off_t size;
|
||||
} file_mod_sig;
|
||||
#define FILE_MOD_COMPARE(ms1,ms2) (((ms1)->mod_time==(ms2)->mod_time) && ((ms1)->size==(ms2)->size))
|
||||
#define FILE_MOD_RESET(ms) memset(ms,0,sizeof(file_mod_sig))
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms);
|
||||
time_t file_mod_time(const char *filename);
|
||||
|
||||
typedef struct
|
||||
|
@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
if (!AppendHostList(&hfile->hostlist, hfile->filename))
|
||||
{
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
if (!AppendIpset(&hfile->ipset, hfile->filename))
|
||||
{
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
entry->hostlist = NULL;
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -206,7 +206,7 @@ void hostlist_files_reset_modtime(struct hostlist_files_head *list)
|
||||
struct hostlist_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
hfile->mod_time=0;
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct hostlist_item *hostlist_collection_add(struct hostlist_collection_head *head, struct hostlist_file *hfile)
|
||||
@ -390,7 +390,7 @@ struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *fi
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
memset(&entry->ipset,0,sizeof(entry->ipset));
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -427,7 +427,7 @@ void ipset_files_reset_modtime(struct ipset_files_head *list)
|
||||
struct ipset_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
hfile->mod_time=0;
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
|
||||
|
@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
|
||||
|
||||
struct hostlist_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
strpool *hostlist;
|
||||
LIST_ENTRY(hostlist_file) next;
|
||||
};
|
||||
@ -112,7 +112,7 @@ void ipsetPrint(ipset *ipset);
|
||||
|
||||
struct ipset_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
ipset ipset;
|
||||
LIST_ENTRY(ipset_file) next;
|
||||
};
|
||||
|
@ -443,7 +443,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
|
||||
DLOG_PERROR("write to auto hostlist:");
|
||||
return;
|
||||
}
|
||||
dp->hostlist_auto->mod_time = file_mod_time(dp->hostlist_auto->filename);
|
||||
if (!file_mod_signature(dp->hostlist_auto->filename, &dp->hostlist_auto->mod_sig))
|
||||
DLOG_PERROR("file_mod_signature");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user