Commit 2b243e38 authored by rswindell's avatar rswindell
Browse files

Add support for importing data/echostats.ini (Unknown areas only), with

filtering on packet address (e.g. to limit importing to a specific msg network)
- for Ragnarok
parent f2bfb9da
......@@ -89,6 +89,8 @@ enum import_list_type determine_msg_list_type(const char* path)
return IMPORT_LIST_TYPE_QWK_CONTROL_DAT;
if(stricmp(fname, "newsgroup.lst") == 0)
return IMPORT_LIST_TYPE_NEWSGROUPS;
if(stricmp(fname, "echostats.ini") == 0)
return IMPORT_LIST_TYPE_ECHOSTATS;
return IMPORT_LIST_TYPE_BACKBONE_NA;
}
......@@ -371,7 +373,7 @@ int main(int argc, char **argv)
case msgbase:
{
enum import_list_type list_type = determine_msg_list_type(fname);
ported = import_msg_areas(list_type, fp, grpnum, 1, 99999, /* qhub: */NULL, &added);
ported = import_msg_areas(list_type, fp, grpnum, 1, 99999, /* qhub: */NULL, /* pkt_orig: */NULL, &added);
break;
}
case filebase:
......
......@@ -82,7 +82,8 @@ enum import_list_type {
IMPORT_LIST_TYPE_SBBSECHO_AREAS_BBS,
IMPORT_LIST_TYPE_BACKBONE_NA,
IMPORT_LIST_TYPE_BAD_AREAS,
IMPORT_LIST_TYPE_NEWSGROUPS,
IMPORT_LIST_TYPE_ECHOSTATS,
IMPORT_LIST_TYPE_NEWSGROUPS
};
/************/
......@@ -164,7 +165,8 @@ BOOL save_file_cfg(scfg_t*, int);
BOOL save_chat_cfg(scfg_t*, int);
BOOL save_xtrn_cfg(scfg_t*, int);
long import_msg_areas(enum import_list_type, FILE*, unsigned grpnum, int min_confnum, int max_confnum, qhub_t*, long* added);
long import_msg_areas(enum import_list_type, FILE*, unsigned grpnum, int min_confnum, int max_confnum
, qhub_t*, const char* pkt_orig, long* added);
/* Prepare a string to be used as an internal code; Note: use the return value, Luke */
char* prep_code(char *str, const char* prefix);
......
......@@ -98,8 +98,9 @@ static bool new_grp(unsigned new_grpnum)
return true;
}
// Return number of imported (including over-written) subs or negative on error
long import_msg_areas(enum import_list_type type, FILE* stream, unsigned grpnum
, int min_confnum, int max_confnum, qhub_t* qhub
, int min_confnum, int max_confnum, qhub_t* qhub, const char* pkt_orig
, long* added)
{
char str[256];
......@@ -112,189 +113,232 @@ long import_msg_areas(enum import_list_type type, FILE* stream, unsigned grpnum
size_t grpname_len = strlen(cfg.grp[grpnum]->sname);
char duplicate_code[LEN_CODE+1]="";
uint duplicate_codes = 0; // consecutive duplicate codes
long new_sub_misc = 0;
long new_sub_misc;
str_list_t ini = NULL;
str_list_t list = NULL;
uint i = 0;
if(added != NULL)
*added = 0;
if(grpnum >= cfg.total_grps)
return -1;
if(type == IMPORT_LIST_TYPE_QWK_CONTROL_DAT) {
/* Skip/ignore the first 10 lines */
for(int i = 0; i < 10; i++) {
if(!fgets(str,sizeof(str),stream))
break;
}
str[0] = 0;
fgets(str,sizeof(str),stream);
total_qwk_confs = atoi(str) + 1;
// Set the new_sub_misc and perform any necessary preprocessing of the input file
switch(type) {
case IMPORT_LIST_TYPE_SUBS_TXT:
new_sub_misc = 0;
break;
case IMPORT_LIST_TYPE_NEWSGROUPS:
new_sub_misc = SUB_INET;
break;
case IMPORT_LIST_TYPE_QWK_CONTROL_DAT:
new_sub_misc = SUB_QNET;
/* Skip/ignore the first 10 lines */
for(int i = 0; i < 10; i++) {
if(!fgets(str,sizeof(str),stream))
break;
}
str[0] = 0;
fgets(str,sizeof(str),stream);
total_qwk_confs = atoi(str) + 1;
break;
case IMPORT_LIST_TYPE_ECHOSTATS:
new_sub_misc = SUB_FIDO;
ini = iniReadFile(stream);
if(ini == NULL)
return 0;
list = iniGetSectionList(ini, /* prefix: */NULL);
if(list == NULL)
return 0;
break;
default: // EchoLists (e.g. BACKBONE.NA, badareas.lst) and AREAS.BBS
new_sub_misc = SUB_FIDO;
break;
}
while(!feof(stream)) {
if(!fgets(str,sizeof(str),stream)) break;
truncsp(str);
if(!str[0])
continue;
while(1) {
memset(&tmpsub,0,sizeof(tmpsub));
// tmpsub.misc = (SUB_FIDO|SUB_NAME|SUB_TOUSER|SUB_QUOTE|SUB_HYPER);
tmpsub.grp = grpnum;
if(type == IMPORT_LIST_TYPE_SUBS_TXT) {
sprintf(tmpsub.lname,"%.*s",LEN_SLNAME,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.sname,"%.*s",LEN_SSNAME,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.qwkname,"%.*s",10,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
SAFECOPY(tmp_code,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.data_dir,"%.*s",LEN_DIR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.read_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.post_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.op_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.misc=ahtoul(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.tagline,"%.*s",80,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.origline,"%.*s",50,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.post_sem,"%.*s",LEN_DIR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
SAFECOPY(tmpsub.newsgroup,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.faddr=atofaddr(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxmsgs=atol(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxcrcs=atol(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxage=atoi(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.ptridx=atoi(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.mod_arstr,"%.*s",LEN_ARSTR,str);
while(!feof(stream)
&& strcmp(str,"***END-OF-SUB***")) {
if(!fgets(str,128,stream)) break;
truncsp(str);
}
}
else if(type == IMPORT_LIST_TYPE_QWK_CONTROL_DAT) {
if(read_qwk_confs >= total_qwk_confs)
if(type == IMPORT_LIST_TYPE_ECHOSTATS) {
char value[INI_MAX_VALUE_LEN];
char areatag[FIDO_AREATAG_LEN + 1];
if(list[i] == NULL)
break;
read_qwk_confs++;
qwk_confnum = atoi(str);
if(!fgets(str,128,stream)) break;
if (qwk_confnum < min_confnum || qwk_confnum > max_confnum)
continue;
truncsp(str);
char* p=str;
SKIP_WHITESPACE(p);
if(*p == 0)
SAFECOPY(areatag, list[i]);
i++;
if(iniGetBool(ini, areatag, "Known", TRUE))
continue;
if(strlen(p) > grpname_len && strnicmp(p, cfg.grp[grpnum]->sname, grpname_len) == 0)
p += grpname_len;
SKIP_WHITESPACE(p);
SAFECOPY(tmp_code, p);
SAFECOPY(tmpsub.lname, p);
SAFECOPY(tmpsub.sname, p);
SAFECOPY(tmpsub.qwkname, p);
new_sub_misc = SUB_QNET;
}
else if(type == IMPORT_LIST_TYPE_NEWSGROUPS) {
char* p=str;
SKIP_WHITESPACE(p);
if(*p == 0)
if(pkt_orig != NULL && *pkt_orig
&& strcmp(pkt_orig, iniGetString(ini, areatag, "LastReceived.pkt_orig", "", value)) != 0)
continue;
char* tp = p + 1;
FIND_WHITESPACE(tp);
*tp = 0;
tp++;
SKIP_WHITESPACE(tp);
SAFECOPY(tmpsub.newsgroup, p);
if(strlen(p) > grpname_len && strnicmp(p, cfg.grp[grpnum]->sname, grpname_len) == 0)
p += grpname_len;
SKIP_CHAR(p, '.');
SAFECOPY(tmp_code, p);
SAFECOPY(tmpsub.lname, tp);
SAFECOPY(tmpsub.sname, p);
SAFECOPY(tmpsub.qwkname, p);
new_sub_misc = SUB_INET;
}
else {
new_sub_misc = SUB_FIDO;
char* p=str;
SKIP_WHITESPACE(p);
if(!*p || *p==';')
SAFECOPY(tmp_code, areatag); // Copy tag to internal code suffix
SAFECOPY(tmpsub.sname, utos(areatag)); // ... to short name, converting underscores to spaces
if(strlen(areatag) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, areatag);
SAFECOPY(tmpsub.lname, iniGetString(ini, areatag, "Title", "", value));
} else {
if(feof(stream))
break;
if(!fgets(str,sizeof(str),stream)) break;
truncsp(str);
if(!str[0])
continue;
if(type == IMPORT_LIST_TYPE_GENERIC_AREAS_BBS) { /* AREAS.BBS Generic/.MSG */
p=str;
SKIP_WHITESPACE(p); /* Find path */
FIND_WHITESPACE(p); /* Skip path */
SKIP_WHITESPACE(p); /* Find tag */
truncstr(p," \t"); /* Truncate tag */
SAFECOPY(tmp_code,p); /* Copy tag to internal code */
SAFECOPY(tmpsub.lname,utos(p));
SAFECOPY(tmpsub.sname,tmpsub.lname);
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
if(type == IMPORT_LIST_TYPE_SUBS_TXT) {
sprintf(tmpsub.lname,"%.*s",LEN_SLNAME,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.sname,"%.*s",LEN_SSNAME,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.qwkname,"%.*s",10,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
SAFECOPY(tmp_code,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.data_dir,"%.*s",LEN_DIR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.read_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.post_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.op_arstr,"%.*s",LEN_ARSTR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.misc=ahtoul(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.tagline,"%.*s",80,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.origline,"%.*s",50,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.post_sem,"%.*s",LEN_DIR,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
SAFECOPY(tmpsub.newsgroup,str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.faddr=atofaddr(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxmsgs=atol(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxcrcs=atol(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.maxage=atoi(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
tmpsub.ptridx=atoi(str);
if(!fgets(str,128,stream)) break;
truncsp(str);
sprintf(tmpsub.mod_arstr,"%.*s",LEN_ARSTR,str);
while(!feof(stream)
&& strcmp(str,"***END-OF-SUB***")) {
if(!fgets(str,128,stream)) break;
truncsp(str);
}
}
else if(type == IMPORT_LIST_TYPE_SBBSECHO_AREAS_BBS) { /* AREAS.BBS SBBSecho */
p=str;
SKIP_WHITESPACE(p); /* Find internal code */
char* tp=p;
else if(type == IMPORT_LIST_TYPE_QWK_CONTROL_DAT) {
if(read_qwk_confs >= total_qwk_confs)
break;
read_qwk_confs++;
qwk_confnum = atoi(str);
if(!fgets(str,128,stream)) break;
if (qwk_confnum < min_confnum || qwk_confnum > max_confnum)
continue;
truncsp(str);
char* p=str;
SKIP_WHITESPACE(p);
if(*p == 0)
continue;
if(strlen(p) > grpname_len && strnicmp(p, cfg.grp[grpnum]->sname, grpname_len) == 0)
p += grpname_len;
SKIP_WHITESPACE(p);
SAFECOPY(tmp_code, p);
SAFECOPY(tmpsub.lname, p);
SAFECOPY(tmpsub.sname, p);
SAFECOPY(tmpsub.qwkname, p);
}
else if(type == IMPORT_LIST_TYPE_NEWSGROUPS) {
char* p=str;
SKIP_WHITESPACE(p);
if(*p == 0)
continue;
char* tp = p + 1;
FIND_WHITESPACE(tp);
*tp=0; /* Truncate internal code */
SAFECOPY(tmp_code,p); /* Copy internal code suffix */
p=tp+1;
SKIP_WHITESPACE(p); /* Find echo tag */
truncstr(p," \t"); /* Truncate tag */
SAFECOPY(tmpsub.lname,utos(p));
SAFECOPY(tmpsub.sname,tmpsub.lname);
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
*tp = 0;
tp++;
SKIP_WHITESPACE(tp);
SAFECOPY(tmpsub.newsgroup, p);
if(strlen(p) > grpname_len && strnicmp(p, cfg.grp[grpnum]->sname, grpname_len) == 0)
p += grpname_len;
SKIP_CHAR(p, '.');
SAFECOPY(tmp_code, p);
SAFECOPY(tmpsub.lname, tp);
SAFECOPY(tmpsub.sname, p);
SAFECOPY(tmpsub.qwkname, p);
}
else if(type == IMPORT_LIST_TYPE_BACKBONE_NA) { /* BACKBONE.NA */
p=str;
SKIP_WHITESPACE(p); /* Find echo tag */
char* tp=p;
FIND_WHITESPACE(tp); /* Find end of tag */
*tp=0; /* Truncate echo tag */
SAFECOPY(tmp_code,p); /* Copy tag to internal code suffix */
SAFECOPY(tmpsub.sname,utos(p)); /* ... to short name, converting underscores to spaces */
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
p=tp+1;
SKIP_WHITESPACE(p); /* Find description */
SAFECOPY(tmpsub.lname,p); /* Copy description to long name */
else {
char* p=str;
SKIP_WHITESPACE(p);
if(!*p || *p==';')
continue;
if(type == IMPORT_LIST_TYPE_GENERIC_AREAS_BBS) { /* AREAS.BBS Generic/.MSG */
p=str;
SKIP_WHITESPACE(p); /* Find path */
FIND_WHITESPACE(p); /* Skip path */
SKIP_WHITESPACE(p); /* Find tag */
truncstr(p," \t"); /* Truncate tag */
SAFECOPY(tmp_code,p); /* Copy tag to internal code */
SAFECOPY(tmpsub.lname,utos(p));
SAFECOPY(tmpsub.sname,tmpsub.lname);
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
}
else if(type == IMPORT_LIST_TYPE_SBBSECHO_AREAS_BBS) { /* AREAS.BBS SBBSecho */
p=str;
SKIP_WHITESPACE(p); /* Find internal code */
char* tp=p;
FIND_WHITESPACE(tp);
*tp=0; /* Truncate internal code */
SAFECOPY(tmp_code,p); /* Copy internal code suffix */
p=tp+1;
SKIP_WHITESPACE(p); /* Find echo tag */
truncstr(p," \t"); /* Truncate tag */
SAFECOPY(tmpsub.lname,utos(p));
SAFECOPY(tmpsub.sname,tmpsub.lname);
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
}
else if(type == IMPORT_LIST_TYPE_BACKBONE_NA) { /* BACKBONE.NA */
p=str;
SKIP_WHITESPACE(p); /* Find echo tag */
char* tp=p;
FIND_WHITESPACE(tp); /* Find end of tag */
*tp=0; /* Truncate echo tag */
SAFECOPY(tmp_code,p); /* Copy tag to internal code suffix */
SAFECOPY(tmpsub.sname,utos(p)); /* ... to short name, converting underscores to spaces */
if(strlen(p) > sizeof(tmpsub.sname) - 1)
SAFECOPY(tmpsub.newsgroup, p);
p=tp+1;
SKIP_WHITESPACE(p); /* Find description */
SAFECOPY(tmpsub.lname,p); /* Copy description to long name */
}
}
}
SAFECOPY(tmpsub.code_suffix, prep_code(tmp_code,cfg.grp[grpnum]->code_prefix));
truncsp(tmpsub.sname);
truncsp(tmpsub.lname);
......@@ -350,12 +394,16 @@ long import_msg_areas(enum import_list_type type, FILE* stream, unsigned grpnum
attempts++;
}
}
if(attempts >= (36*36*36))
return -2;
if(attempts >= (36*36*36)) {
ported = -2;
break;
}
if(j==cfg.total_subs) {
if(!new_sub(j, grpnum, /* pasted_sub: */NULL, new_sub_misc))
return -3;
if(!new_sub(j, grpnum, /* pasted_sub: */NULL, new_sub_misc)) {
ported = -3;
break;
}
if(added != NULL)
(*added)++;
}
......@@ -377,9 +425,12 @@ long import_msg_areas(enum import_list_type type, FILE* stream, unsigned grpnum
new_qhub_sub(qhub, qhub->subs, cfg.sub[j], qwk_confnum);
ported++;
}
if(ported && cfg.grp[grpnum]->sort)
if(ported > 0 && cfg.grp[grpnum]->sort)
sort_subs(grpnum);
strListFree(&ini);
strListFree(&list);
return ported;
}
......@@ -869,6 +920,7 @@ void msgs_cfg()
strcpy(opt[k++],"areas.bbs SBBSecho Area File");
strcpy(opt[k++],"backbone.na FidoNet EchoList");
strcpy(opt[k++],"badareas.lst SBBSecho Bad Area List");
strcpy(opt[k++],"echostats.ini SBBSecho EchoMail Statistics");
strcpy(opt[k++],"newsgroup.lst USENET Newsgroup List");
opt[k][0]=0;
uifc.helpbuf=
......@@ -891,7 +943,10 @@ void msgs_cfg()
"\n"
"`backbone.na` (also `fidonet.na` and `badareas.lst`)\n"
" FidoNet standard EchoList containing standardized echo `Area Tags`\n"
" and (optional) descriptions.\n"
" and optional `Titles` (descriptions).\n"
"\n"
"`echostats.ini`\n"
" SBBSecho cumulative EchoMail statistics (imports `Unknown Areas` only).\n"
"\n"
"`newsgroup.lst`\n"
" Standard (RFC3977) NNTP `LIST NEWSGROUPS` output format:\n"
......@@ -921,8 +976,11 @@ void msgs_cfg()
case IMPORT_LIST_TYPE_NEWSGROUPS:
SAFECOPY(filename, "newsgroup.lst");
break;
case IMPORT_LIST_TYPE_ECHOSTATS:
SAFEPRINTF(filename, "%sechostats.ini", cfg.data_dir);
break;
default:
sprintf(filename,"%sbadareas.lst", cfg.data_dir);
SAFEPRINTF(filename, "%sbadareas.lst", cfg.data_dir);
k = IMPORT_LIST_TYPE_BACKBONE_NA;
break;
}
......@@ -945,6 +1003,16 @@ void msgs_cfg()
break;
max_confnum = atoi(str);
}
char pkt_orig[25] = "";
if(k == IMPORT_LIST_TYPE_ECHOSTATS) {
uifc.helpbuf = "`Filter Areas by Originating Packet Address:`\n"
"\n"
"Enter the relevant uplink's FidoNet address or ENTER for All origins."
;
if(uifc.input(WIN_MID|WIN_SAV, 0, 0, "Filter Areas by Packet Address"
,pkt_orig, sizeof(pkt_orig)-1, K_EDIT) < 0)
break;
}
uifc.helpbuf = "Enter the path to the Area List file to import";
if(uifc.input(WIN_MID|WIN_SAV,0,0,"Filename"
,filename,sizeof(filename)-1,K_EDIT)<=0)
......@@ -956,7 +1024,7 @@ void msgs_cfg()
}
uifc.pop("Importing Areas...");
long added = 0;
ported = import_msg_areas(k, stream, i, min_confnum, max_confnum, /* qhub: */NULL, &added);
ported = import_msg_areas(k, stream, i, min_confnum, max_confnum, /* qhub: */NULL, pkt_orig, &added);
fclose(stream);
uifc.pop(0);
if(ported < 0)
......
......@@ -1261,7 +1261,7 @@ BOOL import_qwk_conferences(uint qhubnum)
}
uifc.pop("Importing Areas...");
long added = 0;
long ported = import_msg_areas(IMPORT_LIST_TYPE_QWK_CONTROL_DAT, fp, grpnum, min_confnum, max_confnum, cfg.qhub[qhubnum], &added);
long ported = import_msg_areas(IMPORT_LIST_TYPE_QWK_CONTROL_DAT, fp, grpnum, min_confnum, max_confnum, cfg.qhub[qhubnum], /* pkt_orig */NULL, &added);
fclose(fp);
uifc.pop(NULL);
if(ported < 0)
......
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