Commit d4fb428a authored by rswindell's avatar rswindell
Browse files

Log a warning when a duplicate area is found in the area file (areas.bbs).

Added (new) '-a' option to dump the parsed area file (areas.bbs) to stdout
(useful for debugging area file issues).
Only age-filtered messages can be relayed to downlinks now (not twit-filtered
messages).
parent 92087b81
......@@ -71,6 +71,7 @@ bool opt_export_ftn_echomail= false; /* Export msgs previously imported from Fid
bool opt_update_msgptrs = false;
bool opt_ignore_msgptrs = false;
bool opt_leave_msgptrs = false;
bool opt_dump_area_file = false;
/* statistics */
ulong netmail=0; /* imported */
......@@ -79,7 +80,6 @@ ulong exported_netmail=0;
ulong exported_echomail=0;
ulong packed_netmail=0;
char tmp[256];
int cur_smb=0;
FILE *fidologfile=NULL;
bool twit_list;
......@@ -675,6 +675,7 @@ int create_netmail(const char *to, const smbmsg_t* msg, const char *subject, con
,bool file_attached)
{
FILE *fp;
char tmp[256];
char fname[MAX_PATH+1];
char* from=NULL;
uint i;
......@@ -850,12 +851,30 @@ bool area_is_linked(unsigned area_num, const fidoaddr_t* addr)
return false;
}
uint find_linked_echo(const char* echotag, fidoaddr_t addr)
/* Returns area index */
uint find_area(const char* echotag)
{
unsigned i;
for(i=0; i<cfg.areas; i++)
if(stricmp(cfg.area[i].name, echotag) == 0 && area_is_linked(i, &addr))
return cfg.area[i].sub;
unsigned u;
for(u=0; u < cfg.areas; u++)
if(stricmp(cfg.area[u].name, echotag) == 0)
break;
return u;
}
bool area_is_valid(uint areanum)
{
return areanum < cfg.areas;
}
/* Returns subnum */
uint find_linked_area(const char* echotag, fidoaddr_t addr)
{
unsigned area;
if(area_is_valid(area = find_area(echotag)) && area_is_linked(area, &addr))
return cfg.area[area].sub;
return INVALID_SUB;
}
......@@ -974,10 +993,7 @@ void netmail_arealist(enum arealist_type type, fidoaddr_t addr, const char* to)
tp=p;
FIND_WHITESPACE(tp);
*tp=0;
for(y=0;y<cfg.areas;y++)
if(!stricmp(cfg.area[y].name,p))
break;
if(y>=cfg.areas || !area_is_linked(y,&addr)) {
if(find_linked_area(p, addr) == INVALID_SUB) {
if(strListFind(area_list, p, /* case_sensitive */false) < 0)
strListPush(&area_list, p);
}
......@@ -1276,11 +1292,7 @@ void alter_areas(str_list_t add_area, str_list_t del_area, fidoaddr_t addr, cons
FIND_WHITESPACE(tp);
*tp=0;
if(add_area[0]!=NULL && stricmp(add_area[0],"+ALL")==0) {
SAFECOPY(tmp,p);
for(y=0;y<cfg.areas;y++)
if(stricmp(p, cfg.area[y].name) == 0)
break;
if(y<cfg.areas)
if(area_is_valid(find_area(p)))
continue;
}
for(y=0;add_area[y]!=NULL;y++)
......@@ -1476,7 +1488,7 @@ void areafix_command(char* instr, fidoaddr_t addr, const char* to)
if(strnicmp(instr, "RESCAN ", 7) == 0) {
char* p = instr + 7;
SKIP_WHITESPACE(p);
int subnum = find_linked_echo(p, addr);
int subnum = find_linked_area(p, addr);
if(subnum == INVALID_SUB)
SAFEPRINTF(str, "Echo-tag '%s' not linked or not found.", p);
else {
......@@ -2296,7 +2308,7 @@ ushort matchname(const char *inname)
static username_t *username;
ulong last_user;
int userdat,i;
char str[256],name[LEN_NAME+1],alias[LEN_ALIAS+1];
char str[256],name[LEN_NAME+1],alias[LEN_ALIAS+1],misc[9];
ulong l;
if(!total_users) { /* Load CRCs */
......@@ -2324,13 +2336,13 @@ ushort matchname(const char *inname)
read(userdat,alias,LEN_ALIAS);
read(userdat,name,LEN_NAME);
lseek(userdat,(long)(((long)total_users)*U_LEN)+U_MISC,SEEK_SET);
read(userdat,tmp,8);
read(userdat,misc,8);
for(i=0;i<8;i++)
if(tmp[i]==ETX || tmp[i]=='\r') break;
tmp[i]=0;
if(misc[i]==ETX || misc[i]=='\r') break;
misc[i]=0;
unlock(userdat,(long)((long)(total_users)*U_LEN)+U_ALIAS
,LEN_ALIAS+LEN_NAME);
if(ahtoul(tmp)&DELETED)
if(ahtoul(misc)&DELETED)
continue;
for(i=0;i<LEN_ALIAS;i++)
if(alias[i]==ETX || alias[i]=='\r') break;
......@@ -2519,6 +2531,15 @@ char* getfmsg(FILE* stream, ulong* outlen)
#define MAX_TAILLEN 1024
enum {
IMPORT_FAILURE = -1
,IMPORT_SUCCESS = SMB_SUCCESS
,IMPORT_FILTERED_DUPE = SMB_DUPE_MSG
,IMPORT_FILTERED_TWIT = 2
,IMPORT_FILTERED_EMPTY = 3
,IMPORT_FILTERED_AGE = 4
};
/****************************************************************************/
/* Coverts a FidoNet message into a Synchronet message */
/* Returns 0 on success, 1 dupe, 2 filtered, 3 empty, 4 too-old */
......@@ -2546,7 +2567,7 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t fmsghdr, uint user, uint subnum)
sprintf(fname,"%stwitlist.cfg",scfg.ctrl_dir);
if(findstr(fmsghdr.from,fname) || findstr(fmsghdr.to,fname)) {
lprintf(LOG_INFO,"Filtering message from %s to %s",fmsghdr.from,fmsghdr.to);
return(2);
return IMPORT_FILTERED_TWIT;
}
}
......@@ -2566,7 +2587,7 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t fmsghdr, uint user, uint subnum)
lprintf(LOG_INFO, "Filtering message from %s due to age: %1.1f days"
,fmsghdr.from
,(now - msg.hdr.when_written.time) / (24.0*60.0*60.0));
return 4;
return IMPORT_FILTERED_AGE;
}
origaddr.zone=fmsghdr.origzone; /* only valid if NetMail */
......@@ -2592,14 +2613,14 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t fmsghdr, uint user, uint subnum)
if(fbuf==NULL) {
lprintf(LOG_ERR,"ERROR line %d allocating fbuf",__LINE__);
smb_freemsgmem(&msg);
return(-1);
return IMPORT_FAILURE;
}
length=strlen((char *)fbuf);
if((sbody=(uchar*)malloc((length+1)*2))==NULL) {
lprintf(LOG_ERR,"ERROR line %d allocating %lu bytes for body",__LINE__
,(length+1)*2L);
smb_freemsgmem(&msg);
return(-1);
return IMPORT_FAILURE;
}
for(col=l=esc=done=bodylen=taillen=0,cr=1;l<length;l++) {
......@@ -2801,7 +2822,7 @@ int fmsgtosmsg(char* fbuf, fmsghdr_t fmsghdr, uint user, uint subnum)
lprintf(LOG_INFO,"Empty NetMail - Ignored ");
smb_freemsgmem(&msg);
free(sbody);
return(3);
return IMPORT_FILTERED_EMPTY;
}
if(!origaddr.zone && subnum==INVALID_SUB)
......@@ -3626,7 +3647,7 @@ int import_netmail(const char* path, fmsghdr_t hdr, FILE* fidomsg, const char* i
SAFECOPY(hdr.from,"SBBSecho");
SAFECOPY(hdr.subj,"Areafix Request");
hdr.origzone=hdr.orignet=hdr.orignode=hdr.origpoint=0;
if(fmsgtosmsg(p,hdr,notify,INVALID_SUB)==0) {
if(fmsgtosmsg(p,hdr,notify,INVALID_SUB) == IMPORT_SUCCESS) {
sprintf(str,"\7\1n\1hSBBSecho \1n\1msent you mail\r\n");
putsmsg(&scfg,notify,str);
}
......@@ -3660,15 +3681,15 @@ int import_netmail(const char* path, fmsghdr_t hdr, FILE* fidomsg, const char* i
fmsgbuf=getfmsg(fidomsg,&length);
switch(i=fmsgtosmsg(fmsgbuf,hdr,usernumber,INVALID_SUB)) {
case 0: /* success */
case IMPORT_SUCCESS: /* success */
break;
case 2: /* filtered */
case IMPORT_FILTERED_DUPE: /* filtered */
lprintf(LOG_WARNING,"%s Filtered - Ignored",info);
break;
case 3: /* empty */
case IMPORT_FILTERED_EMPTY: /* empty */
lprintf(LOG_WARNING,"%s Empty - Ignored",info);
break;
case 4: /* too-old */
case IMPORT_FILTERED_AGE: /* too-old */
lprintf(LOG_WARNING,"%s Filtered - Too Old", info);
break;
default:
......@@ -4696,18 +4717,14 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure)
continue;
}
for(i=0;i<cfg.areas;i++) /* Do we carry this area? */
if(stricmp(cfg.area[i].name, areatag) == 0) {
if(cfg.area[i].sub!=INVALID_SUB)
printf("%s ",scfg.sub[cfg.area[i].sub]->code);
else
printf("(Passthru) ");
fmsgbuf=getfmsg(fidomsg,NULL);
gen_psb(&msg_seen,&msg_path,fmsgbuf,pkt_orig.zone); /* was destzone */
break;
}
if(i==cfg.areas) {
if(area_is_valid(i = find_area(areatag))) { /* Do we carry this area? */
if(cfg.area[i].sub!=INVALID_SUB)
printf("%s ",scfg.sub[cfg.area[i].sub]->code);
else
printf("(Passthru) ");
fmsgbuf=getfmsg(fidomsg,NULL);
gen_psb(&msg_seen,&msg_path,fmsgbuf,pkt_orig.zone); /* was destzone */
} else {
printf("(Unknown) ");
if(cfg.badecho>=0) {
i=cfg.badecho;
......@@ -4827,12 +4844,12 @@ void import_packets(const char* inbound, nodecfg_t* inbox, bool secure)
/**********************/
result=fmsgtosmsg(fmsgbuf,hdr,0,cfg.area[i].sub);
if(result==SMB_DUPE_MSG) {
if(result==IMPORT_FILTERED_DUPE) {
lprintf(LOG_NOTICE, "%s Duplicate message from %s (%s) to %s, subject: %s"
,areatag, hdr.from, fmsghdr_srcaddr_str(&hdr), hdr.to, hdr.subj);
cfg.area[i].dupes++;
}
else if(result==SMB_SUCCESS || cfg.relay_filtered_msgs) { /* Not a dupe */
else if(result==IMPORT_SUCCESS || (result==IMPORT_FILTERED_AGE && cfg.relay_filtered_msgs)) { /* Not a dupe */
strip_psb(fmsgbuf);
pkt_to_pkt(fmsgbuf,curarea,NULL,hdr,msg_seen,msg_path);
}
......@@ -4874,6 +4891,8 @@ int main(int argc, char **argv)
char str[1025],path[MAX_PATH+1]
,*p,*tp;
char* sub_code = NULL;
char tmp_code[LEN_EXTCODE+1];
char area_tag[FIDO_AREATAG_LEN+1];
char cmdline[256];
int i,j,fmsg;
size_t f;
......@@ -4902,6 +4921,7 @@ int main(int argc, char **argv)
" * Export echomail previously imported from FTN (-h to enable)\n"
" * Update echomail export pointers without exporting messages (-u to enable)\n"
" * Generate AreaFix netmail reports/notifications for links (-g to enable)\n"
" * Display the parsed area file (e.g. AREAS.BBS) for debugging (-a to enable)\n"
" * Prompt for key-press upon normal exit (-@ to enable)\n"
" * Prompt for key-press upon abnormal exit (-w to enable)\n"
;
......@@ -4984,12 +5004,14 @@ int main(int argc, char **argv)
case 'W':
pause_on_abend=true;
break;
case 'A':
opt_dump_area_file=true;
break;
default:
fprintf(stderr, "Unsupported option: %c\n", argv[i][j]);
case '?':
printf("%s", usage);
bail(0);
case 'A':
case 'B':
case 'D':
case 'F':
......@@ -5125,6 +5147,7 @@ int main(int argc, char **argv)
if(*p==';' || !*p) /* Ignore blank lines or start with ; */
continue;
if((cfg.area=(area_t *)realloc(cfg.area,sizeof(area_t)*(cfg.areas+1)))==NULL) {
printf("\n");
lprintf(LOG_ERR,"ERROR allocating memory for area #%u.",cfg.areas+1);
bail(1);
return -1;
......@@ -5133,27 +5156,34 @@ int main(int argc, char **argv)
cfg.area[cfg.areas].sub=INVALID_SUB; /* Default to passthru */
sprintf(tmp,"%-.*s",LEN_EXTCODE,p);
tp=tmp;
sprintf(tmp_code,"%-.*s",LEN_EXTCODE,p);
tp=tmp_code;
FIND_WHITESPACE(tp);
*tp=0;
for(i=0;i<scfg.total_subs;i++)
if(!stricmp(tmp,scfg.sub[i]->code))
if(!stricmp(tmp_code,scfg.sub[i]->code))
break;
if(i<scfg.total_subs)
cfg.area[cfg.areas].sub=i;
else if(stricmp(tmp,"P")) {
lprintf(LOG_WARNING,"%s: Unrecognized internal code, assumed passthru",tmp);
else if(stricmp(tmp_code,"P")) {
printf("\n");
lprintf(LOG_WARNING,"%s: Unrecognized internal code, assumed passthru",tmp_code);
}
FIND_WHITESPACE(p); /* Skip code */
SKIP_WHITESPACE(p); /* Skip white space */
SAFECOPY(tmp,p); /* Area tag */
truncstr(tmp,"\t ");
strupr(tmp);
if(tmp[0]=='*') /* UNKNOWN-ECHO area */
SAFECOPY(area_tag,p); /* Area tag */
truncstr(area_tag,"\t ");
strupr(area_tag);
if(area_tag[0]=='*') /* UNKNOWN-ECHO area */
cfg.badecho=cfg.areas;
if((cfg.area[cfg.areas].name=strdup(tmp))==NULL) {
if(area_is_valid(find_area(area_tag))) {
printf("\n");
lprintf(LOG_WARNING, "DUPLICATE AREA (%s) in area file (%s), IGNORED!", area_tag, cfg.areafile);
continue;
}
if((cfg.area[cfg.areas].name=strdup(area_tag))==NULL) {
printf("\n");
lprintf(LOG_ERR,"ERROR allocating memory for area #%u tag name."
,cfg.areas+1);
bail(1);
......@@ -5165,12 +5195,14 @@ int main(int argc, char **argv)
while(*p && *p!=';') {
if(!isdigit(*p)) {
printf("\n");
lprintf(LOG_WARNING, "Invalid Area File line, expected link address(es) after echo-tag: '%s'", str);
break;
}
if((cfg.area[cfg.areas].link=(fidoaddr_t *)
realloc(cfg.area[cfg.areas].link
,sizeof(fidoaddr_t)*(cfg.area[cfg.areas].links+1)))==NULL) {
printf("\n");
lprintf(LOG_ERR,"ERROR allocating memory for area #%u links."
,cfg.areas+1);
bail(1);
......@@ -5178,10 +5210,11 @@ int main(int argc, char **argv)
}
fidoaddr_t link = atofaddr(p);
cfg.area[cfg.areas].link[cfg.area[cfg.areas].links] = link;
if(findnodecfg(&cfg, link, /* exact: */false) == NULL)
if(findnodecfg(&cfg, link, /* exact: */false) == NULL) {
printf("\n");
lprintf(LOG_WARNING, "Configuration for %s-linked-node (%s) not found in %s"
,cfg.area[cfg.areas].name, faddrtoa(&link), cfg.cfgfile);
else
} else
cfg.area[cfg.areas].links++;
FIND_WHITESPACE(p); /* Skip address */
SKIP_WHITESPACE(p); /* Skip white space */
......@@ -5192,7 +5225,19 @@ int main(int argc, char **argv)
}
fclose(stream);
printf("\n");
printf("\nRead %u areas from %s\n", cfg.areas, cfg.areafile);
if(opt_dump_area_file) {
printf("Area file dump (%u areas):\n", cfg.areas);
for(unsigned u=0; u < cfg.areas && !terminated; u++) {
printf("%-*s %-*s "
,LEN_EXTCODE, cfg.area[u].sub == INVALID_SUB ? "P" : scfg.sub[cfg.area[u].sub]->code
,FIDO_AREATAG_LEN, cfg.area[u].name);
for(unsigned l=0; l < cfg.area[u].links && !terminated; l++)
printf("%s ", faddrtoa(&cfg.area[u].link[l]));
printf("\n");
}
}
if(opt_gen_notify_list && !terminated) {
lprintf(LOG_DEBUG,"Generating AreaFix Notifications...");
......
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