Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 32051b32 authored by rswindell's avatar rswindell

Add/use new function findstr_list() which opens and returns a string list

suitable for passing to findstr_in_list().
SBBSecho peformance improvement: don't open/read the twitlist.cfg file for
*each* imported message: just read it once during initialization (using the new
findstr_list() function of course).
Reversed course on the findstr()/trashcan() matching logic: significant leading
white-space was not backwards compatible (and was the cause of recent lost
messages in DOVE-Net) - so I decided to go a different route and support
C-style character escape sequences (e.g. \r, \n, \t, \x##, etc.) in findstr
comparison strings, so the new way to represent a leading space character
in a filter file (e.g. twitlist.cfg, name.can) would be: "\ ". So to match (e.g.
filter/disallow) all strings with a leading space: "\ *". "\x20 *" would also
work (0x20 is ASCII for "space").
Now, again, leading white-space in filter files (e.g. text/*.can, twitlist.cfg)
is ignored. <sigh>
parent 7fa88586
......@@ -1100,6 +1100,7 @@ extern "C" {
DLLEXPORT BOOL DLLCALL findstr(const char *insearch, const char *fname);
DLLEXPORT BOOL DLLCALL findstr_in_string(const char* insearchof, char* string);
DLLEXPORT BOOL DLLCALL findstr_in_list(const char* insearchof, str_list_t list);
DLLEXPORT str_list_t DLLCALL findstr_list(const char* fname);
DLLEXPORT BOOL DLLCALL trashcan(scfg_t* cfg, const char *insearch, const char *name);
DLLEXPORT char * DLLCALL trashcan_fname(scfg_t* cfg, const char *name, char* fname, size_t);
DLLEXPORT str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name);
......
......@@ -90,7 +90,7 @@ ulong bundles_unpacked=0;
int cur_smb=0;
FILE *fidologfile=NULL;
bool twit_list;
str_list_t twit_list;
str_list_t bad_areas;
fidoaddr_t sys_faddr = {1,1,1,0}; /* Default system address: 1:1/1.0 */
......@@ -3293,17 +3293,13 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t* hdr, uint user, uint subnum)
long dupechk_hashes=SMB_HASH_SOURCE_DUPE;
fidoaddr_t faddr,origaddr,destaddr;
smb_t* smbfile;
char fname[MAX_PATH+1];
smbmsg_t msg;
time32_t now=time32(NULL);
ulong max_msg_age = (subnum == INVALID_SUB) ? cfg.max_netmail_age : cfg.max_echomail_age;
if(twit_list) {
sprintf(fname,"%stwitlist.cfg",scfg.ctrl_dir);
if(findstr(hdr->from,fname) || findstr(hdr->to,fname)) {
lprintf(LOG_INFO,"Filtering message from %s to %s",hdr->from,hdr->to);
return IMPORT_FILTERED_TWIT;
}
if(findstr_in_list(hdr->from, twit_list) || findstr_in_list(hdr->to, twit_list)) {
lprintf(LOG_INFO,"Filtering message from %s to %s",hdr->from,hdr->to);
return IMPORT_FILTERED_TWIT;
}
memset(&msg,0,sizeof(smbmsg_t));
......@@ -6132,7 +6128,7 @@ int main(int argc, char **argv)
}
SAFEPRINTF(str,"%stwitlist.cfg",scfg.ctrl_dir);
twit_list=fexist(str);
twit_list=findstr_list(str);
if(scfg.total_faddrs)
sys_faddr=scfg.faddr[0];
......
......@@ -290,10 +290,13 @@ BOOL DLLCALL findstr(const char* insearchof, const char* fname)
while(!feof(fp) && !ferror(fp) && !found) {
if(!fgets(str,sizeof(str),fp))
break;
if(ip_addr !=0 && (cidr = parse_cidr(str, &subnet)) != 0)
found = is_cidr_match(str, ip_addr, cidr, subnet);
char* p = str;
SKIP_WHITESPACE(p);
c_unescape_str(p);
if(ip_addr !=0 && (cidr = parse_cidr(p, &subnet)) != 0)
found = is_cidr_match(p, ip_addr, cidr, subnet);
else
found = findstr_in_string(insearchof, str);
found = findstr_in_string(insearchof, p);
}
fclose(fp);
......@@ -318,23 +321,37 @@ char* DLLCALL trashcan_fname(scfg_t* cfg, const char* name, char* fname, size_t
return fname;
}
static char* process_findstr_item(size_t index, char *str, void* cbdata)
{
SKIP_WHITESPACE(str);
return c_unescape_str(str);
}
/****************************************************************************/
str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name)
str_list_t DLLCALL findstr_list(const char* fname)
{
char fname[MAX_PATH+1];
FILE* fp;
str_list_t list;
if((fp=fopen(trashcan_fname(cfg, name, fname, sizeof(fname)),"r"))==NULL)
if((fp=fopen(fname,"r"))==NULL)
return NULL;
list=strListReadFile(fp,NULL,255);
list=strListReadFile(fp, NULL, /* Max line length: */255);
strListModifyEach(list, process_findstr_item, /* cbdata: */NULL);
fclose(fp);
return list;
}
/****************************************************************************/
str_list_t DLLCALL trashcan_list(scfg_t* cfg, const char* name)
{
char fname[MAX_PATH+1];
return findstr_list(trashcan_fname(cfg, name, fname, sizeof(fname)));
}
/****************************************************************************/
/* Returns the printed columns from 'str' accounting for Ctrl-A codes */
/****************************************************************************/
......
......@@ -125,10 +125,7 @@ bool sbbs_t::unpack_qwk(char *packet,uint hubnum)
subject_can=trashcan_list(&cfg,"subject");
SAFEPRINTF(fname,"%stwitlist.cfg",cfg.ctrl_dir);
if((fp=fopen(fname,"r"))!=NULL) {
twit_list=strListReadFile(fp,NULL,128);
fclose(fp);
}
twit_list = findstr_list(fname);
for(l=QWK_BLOCK_LEN;l<size;l+=blocks*QWK_BLOCK_LEN) {
if(terminated) {
......
......@@ -168,10 +168,7 @@ bool sbbs_t::unpack_rep(char* repfile)
subject_can=trashcan_list(&cfg,"subject");
SAFEPRINTF(fname,"%stwitlist.cfg",cfg.ctrl_dir);
if((fp=fopen(fname,"r"))!=NULL) {
twit_list=strListReadFile(fp,NULL,128);
fclose(fp);
}
twit_list = findstr_list(fname);
now=time(NULL);
for(l=QWK_BLOCK_LEN;l<size;l+=blocks*QWK_BLOCK_LEN) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment