Code cleanups for nodelist processing
This commit is contained in:
parent
19ad88a5db
commit
962fe209c6
@ -481,8 +481,6 @@ typedef struct _nlusr {
|
|||||||
#define NL_HOLD 0x02 /* Node is Hold */
|
#define NL_HOLD 0x02 /* Node is Hold */
|
||||||
#define NL_PVT 0x04 /* Private node */
|
#define NL_PVT 0x04 /* Private node */
|
||||||
#define NL_DUMMY 0x08 /* Dummy entry */
|
#define NL_DUMMY 0x08 /* Dummy entry */
|
||||||
#define NL_ISDN 0x10 /* ISDN Only node */
|
|
||||||
#define NL_TCPIP 0x20 /* TCP/IP Only node */
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
|
@ -99,16 +99,12 @@ int nlinfo(faddr *addr)
|
|||||||
* Show P flags
|
* Show P flags
|
||||||
*/
|
*/
|
||||||
printf("P Flag :");
|
printf("P Flag :");
|
||||||
if (nlent->pflag & 0x01)
|
if (nlent->pflag & NL_DOWN)
|
||||||
printf(" Down");
|
printf(" Down");
|
||||||
if (nlent->pflag & 0x02)
|
if (nlent->pflag & NL_HOLD)
|
||||||
printf(" Hold");
|
printf(" Hold");
|
||||||
if (nlent->pflag & 0x04)
|
if (nlent->pflag & NL_PVT)
|
||||||
printf(" Pvt");
|
printf(" Pvt");
|
||||||
if (nlent->pflag & 0x10)
|
|
||||||
printf(" ISDN");
|
|
||||||
if (nlent->pflag & 0x20)
|
|
||||||
printf(" TCP/IP");
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
if (nlent->t1) {
|
if (nlent->t1) {
|
||||||
printf("System open : ");
|
printf("System open : ");
|
||||||
|
204
mbfido/mbindex.c
204
mbfido/mbindex.c
@ -48,6 +48,9 @@ long total = 0, entries = 0;
|
|||||||
int filenr = 0;
|
int filenr = 0;
|
||||||
unsigned short regio;
|
unsigned short regio;
|
||||||
nl_list *nll = NULL;
|
nl_list *nll = NULL;
|
||||||
|
static char *k, *v;
|
||||||
|
static int linecnt = 0;
|
||||||
|
static char *nlpath = NULL;
|
||||||
|
|
||||||
|
|
||||||
extern int do_quiet; /* Quiet flag */
|
extern int do_quiet; /* Quiet flag */
|
||||||
@ -56,6 +59,83 @@ time_t t_start; /* Start time */
|
|||||||
time_t t_end; /* End time */
|
time_t t_end; /* End time */
|
||||||
|
|
||||||
|
|
||||||
|
static int getmdm(char**);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Table to parse the ~/etc/nodelist.conf file
|
||||||
|
*/
|
||||||
|
static struct _keytab {
|
||||||
|
char *key;
|
||||||
|
int (*prc)(char **);
|
||||||
|
char** dest;
|
||||||
|
} keytab[] = {
|
||||||
|
{(char *)"isdn", getmdm, (char **)&nl_isdn},
|
||||||
|
{(char *)"tcpip", getmdm, (char **)&nl_tcpip},
|
||||||
|
{NULL, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a keyword, string, unsigned long, unsigned long
|
||||||
|
*/
|
||||||
|
static int getmdm(char **dest)
|
||||||
|
{
|
||||||
|
char *p, *q;
|
||||||
|
unsigned long tmp1, tmp2;
|
||||||
|
nodelist_modem **tmpm;
|
||||||
|
|
||||||
|
for (p = v; *p && !isspace(*p); p++);
|
||||||
|
if (*p)
|
||||||
|
*p++ = '\0';
|
||||||
|
while (*p && isspace(*p))
|
||||||
|
p++;
|
||||||
|
if (*p == '\0') {
|
||||||
|
WriteError("%s(%s): less then two tokens", nlpath, linecnt);
|
||||||
|
return MBERR_INIT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (q = p; *q && !isspace(*q); q++);
|
||||||
|
if (*q)
|
||||||
|
*q++ = '\0';
|
||||||
|
while (*q && isspace(*q))
|
||||||
|
q++;
|
||||||
|
if (*q == '\0') {
|
||||||
|
WriteError("%s(%s): less then three tokens", nlpath, linecnt);
|
||||||
|
return MBERR_INIT_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmpm = (nodelist_modem**)dest; *tmpm; tmpm=&((*tmpm)->next));
|
||||||
|
(*tmpm) = (nodelist_modem *) xmalloc(sizeof(nodelist_modem));
|
||||||
|
(*tmpm)->next = NULL;
|
||||||
|
(*tmpm)->name = xstrcpy(v);
|
||||||
|
tmp1 = strtoul(p, NULL, 0);
|
||||||
|
tmp2 = strtoul(q, NULL, 0);
|
||||||
|
(*tmpm)->mask = tmp1;
|
||||||
|
(*tmpm)->value = tmp2;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void tidy_nl_modem(nodelist_modem **);
|
||||||
|
void tidy_nl_modem(nodelist_modem **fap)
|
||||||
|
{
|
||||||
|
nodelist_modem *tmp, *old;
|
||||||
|
|
||||||
|
for (tmp = *fap; tmp; tmp = old) {
|
||||||
|
old = tmp->next;
|
||||||
|
if (tmp->name)
|
||||||
|
free(tmp->name);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
*fap = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we don't know what to type
|
* If we don't know what to type
|
||||||
@ -304,18 +384,18 @@ int comp_node(nl_list **fap1, nl_list **fap2)
|
|||||||
|
|
||||||
int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short no)
|
int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short no)
|
||||||
{
|
{
|
||||||
int num, i, rc = 0, lineno, boss = FALSE, bossvalid = FALSE;
|
int num, i, lineno, boss = FALSE, bossvalid = FALSE;
|
||||||
unsigned short upnet, upnode;
|
unsigned short upnet, upnode;
|
||||||
char buf[MAXNLLINELEN], *p, *q;
|
char buf[MAXNLLINELEN], *p, *q;
|
||||||
faddr *tmpa;
|
faddr *tmpa;
|
||||||
FILE *nl;
|
FILE *nl;
|
||||||
struct _nlidx ndx;
|
struct _nlidx ndx;
|
||||||
struct _nlusr udx;
|
struct _nlusr udx;
|
||||||
|
nodelist_modem **tmpm;
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
if ((nl = fopen(fullpath(nlname), "r")) == NULL) {
|
if ((nl = fopen(fullpath(nlname), "r")) == NULL) {
|
||||||
WriteError("$Can't open %s", fullpath(nlname));
|
WriteError("$Can't open %s", fullpath(nlname));
|
||||||
return 102;
|
return MBERR_INIT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Syslog('+', "Compiling \"%s\" (%d)", nlname, filenr);
|
Syslog('+', "Compiling \"%s\" (%d)", nlname, filenr);
|
||||||
@ -375,8 +455,19 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
|
|||||||
|
|
||||||
if ((p = strchr(buf, ',')))
|
if ((p = strchr(buf, ',')))
|
||||||
*p++ = '\0';
|
*p++ = '\0';
|
||||||
|
else {
|
||||||
|
/*
|
||||||
|
* Extra check for valid datalines, there should be at least one comma.
|
||||||
|
*/
|
||||||
|
WriteError("%s(%u): invalid dataline", nlname,lineno);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ((q = strchr(p, ',')))
|
if ((q = strchr(p, ',')))
|
||||||
*q++ = '\0';
|
*q++ = '\0';
|
||||||
|
else {
|
||||||
|
WriteError("%s(%u): invalid dataline", nlname,lineno);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ndx.type = NL_NONE;
|
ndx.type = NL_NONE;
|
||||||
ndx.pflag = 0;
|
ndx.pflag = 0;
|
||||||
@ -386,7 +477,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
|
|||||||
ndx.type = NL_POINT;
|
ndx.type = NL_POINT;
|
||||||
else
|
else
|
||||||
ndx.type = NL_NODE;
|
ndx.type = NL_NODE;
|
||||||
} else
|
} else {
|
||||||
if (strcasecmp(buf,"Boss") == 0) {
|
if (strcasecmp(buf,"Boss") == 0) {
|
||||||
ndx.type = NL_POINT;
|
ndx.type = NL_POINT;
|
||||||
bossvalid = FALSE;
|
bossvalid = FALSE;
|
||||||
@ -436,6 +527,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
|
|||||||
bossvalid = TRUE;
|
bossvalid = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ndx.type == NL_NONE) {
|
if (ndx.type == NL_NONE) {
|
||||||
for (q = buf; *q; q++)
|
for (q = buf; *q; q++)
|
||||||
@ -539,19 +631,11 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
|
|||||||
q = p;
|
q = p;
|
||||||
}
|
}
|
||||||
if ((strlen(p) == 3) && (!strcmp(p, "300")) && (q != NULL)) {
|
if ((strlen(p) == 3) && (!strcmp(p, "300")) && (q != NULL)) {
|
||||||
if ((strstr(q, (char *)"X75")) ||
|
for (tmpm = &nl_isdn; *tmpm; tmpm=&((*tmpm)->next))
|
||||||
(strstr(q, (char *)"V110L")) ||
|
if (strstr(q, (*tmpm)->name))
|
||||||
(strstr(q, (char *)"V110H")) ||
|
|
||||||
(strstr(q, (char *)"V120L")) ||
|
|
||||||
(strstr(q, (char *)"V120H")) ||
|
|
||||||
(strstr(q, (char *)"ISDN")))
|
|
||||||
ndx.pflag |= NL_ISDN;
|
ndx.pflag |= NL_ISDN;
|
||||||
if ((strstr(q, (char *)"IFC")) ||
|
for (tmpm = &nl_tcpip; *tmpm; tmpm=&((*tmpm)->next))
|
||||||
(strstr(q, (char *)"IBN")) ||
|
if (strstr(q, (*tmpm)->name))
|
||||||
(strstr(q, (char *)"ITN")) ||
|
|
||||||
(strstr(q, (char *)"IVM")) ||
|
|
||||||
(strstr(q, (char *)"IFT")) ||
|
|
||||||
(strstr(q, (char *)"IP")))
|
|
||||||
ndx.pflag |= NL_TCPIP;
|
ndx.pflag |= NL_TCPIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,7 +665,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -767,9 +851,9 @@ int makelist(char *base, unsigned short zo, unsigned short ne, unsigned short no
|
|||||||
int nodebld(void)
|
int nodebld(void)
|
||||||
{
|
{
|
||||||
int rc = 0, i;
|
int rc = 0, i;
|
||||||
char *im, *fm, *um, *old, *new;
|
char *im, *fm, *um, *old, *new, *p, buf[256];
|
||||||
struct _nlfil fdx;
|
struct _nlfil fdx;
|
||||||
FILE *fp;
|
FILE *fp, *dbf;
|
||||||
nl_list *tmp;
|
nl_list *tmp;
|
||||||
|
|
||||||
memset(&fdx, 0, sizeof(fdx));
|
memset(&fdx, 0, sizeof(fdx));
|
||||||
@ -779,13 +863,13 @@ int nodebld(void)
|
|||||||
|
|
||||||
if ((ifp = fopen(im, "w+")) == NULL) {
|
if ((ifp = fopen(im, "w+")) == NULL) {
|
||||||
WriteError("$Can't create %s",MBSE_SS(im));
|
WriteError("$Can't create %s",MBSE_SS(im));
|
||||||
return 101;
|
return MBERR_GENERAL;
|
||||||
}
|
}
|
||||||
if ((ufp = fopen(um, "w+")) == NULL) {
|
if ((ufp = fopen(um, "w+")) == NULL) {
|
||||||
WriteError("$Can't create %s", MBSE_SS(um));
|
WriteError("$Can't create %s", MBSE_SS(um));
|
||||||
fclose(ifp);
|
fclose(ifp);
|
||||||
unlink(im);
|
unlink(im);
|
||||||
return 101;
|
return MBERR_GENERAL;
|
||||||
}
|
}
|
||||||
if ((ffp = fopen(fm, "w+")) == NULL) {
|
if ((ffp = fopen(fm, "w+")) == NULL) {
|
||||||
WriteError("$Can't create %s", MBSE_SS(fm));
|
WriteError("$Can't create %s", MBSE_SS(fm));
|
||||||
@ -793,16 +877,79 @@ int nodebld(void)
|
|||||||
unlink(im);
|
unlink(im);
|
||||||
fclose(ufp);
|
fclose(ufp);
|
||||||
unlink(um);
|
unlink(um);
|
||||||
return 101;
|
return MBERR_GENERAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!do_quiet) {
|
if (!do_quiet) {
|
||||||
colour(3, 0);
|
colour(CYAN, BLACK);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nl_isdn = NULL;
|
||||||
|
nl_tcpip = NULL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read and parse ~/etc/nodelist.conf
|
||||||
|
*/
|
||||||
|
nlpath = calloc(PATH_MAX, sizeof(char));
|
||||||
|
sprintf(nlpath, "%s/etc/nodelist.conf", getenv("MBSE_ROOT"));
|
||||||
|
if ((dbf = fopen(nlpath, "r")) == NULL) {
|
||||||
|
WriteError("$Can't open %s", nlpath);
|
||||||
|
fclose(ifp);
|
||||||
|
unlink(im);
|
||||||
|
fclose(ufp);
|
||||||
|
unlink(um);
|
||||||
|
fclose(ffp);
|
||||||
|
unlink(fm);
|
||||||
|
free(nlpath);
|
||||||
|
return MBERR_GENERAL;
|
||||||
|
} else {
|
||||||
|
while (fgets(buf, sizeof(buf) -1, dbf)) {
|
||||||
|
linecnt++;
|
||||||
|
if (*(p = buf + strlen(buf) -1) != '\n') {
|
||||||
|
WriteError("%s(%d): \"%s\" - line too long", nlpath, linecnt, buf);
|
||||||
|
rc = MBERR_GENERAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*p-- = '\0';
|
||||||
|
while ((p >= buf) && isspace(*p))
|
||||||
|
*p-- = '\0';
|
||||||
|
k = buf;
|
||||||
|
while (*k && isspace(*k))
|
||||||
|
k++;
|
||||||
|
p = k;
|
||||||
|
while (*p && !isspace(*p))
|
||||||
|
p++;
|
||||||
|
*p++='\0';
|
||||||
|
v = p;
|
||||||
|
while (*v && isspace(*v))
|
||||||
|
v++;
|
||||||
|
|
||||||
|
if ((*k == '\0') || (*k == '#')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = 0; keytab[i].key; i++)
|
||||||
|
if (strcasecmp(k,keytab[i].key) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// if (keytab[i].key != NULL) {
|
||||||
|
// WriteError("%s(%d): %s %s - unknown keyword", nlpath, linecnt, MBSE_SS(k), MBSE_SS(v));
|
||||||
|
// rc = MBERR_GENERAL;
|
||||||
|
// break;
|
||||||
|
// } else
|
||||||
|
if ((keytab[i].prc(keytab[i].dest))) {
|
||||||
|
rc = MBERR_GENERAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(dbf);
|
||||||
|
}
|
||||||
|
free(nlpath);
|
||||||
|
|
||||||
|
if (rc == 0) {
|
||||||
if ((fp = fopen(fidonet_fil, "r")) == 0)
|
if ((fp = fopen(fidonet_fil, "r")) == 0)
|
||||||
rc = 102;
|
rc = MBERR_GENERAL;
|
||||||
else {
|
else {
|
||||||
fread(&fidonethdr, sizeof(fidonethdr), 1, fp);
|
fread(&fidonethdr, sizeof(fidonethdr), 1, fp);
|
||||||
|
|
||||||
@ -814,10 +961,8 @@ int nodebld(void)
|
|||||||
|
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if (fidonet.seclist[i].zone) {
|
if (fidonet.seclist[i].zone) {
|
||||||
rc = makelist(fidonet.seclist[i].nodelist,
|
rc = makelist(fidonet.seclist[i].nodelist, fidonet.seclist[i].zone,
|
||||||
fidonet.seclist[i].zone,
|
fidonet.seclist[i].net, fidonet.seclist[i].node);
|
||||||
fidonet.seclist[i].net,
|
|
||||||
fidonet.seclist[i].node);
|
|
||||||
if (rc)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -829,6 +974,7 @@ int nodebld(void)
|
|||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fclose(ufp);
|
fclose(ufp);
|
||||||
fclose(ffp);
|
fclose(ffp);
|
||||||
@ -882,6 +1028,8 @@ int nodebld(void)
|
|||||||
free(fm);
|
free(fm);
|
||||||
free(um);
|
free(um);
|
||||||
tidy_nllist(&nll);
|
tidy_nllist(&nll);
|
||||||
|
tidy_nl_modem(&nl_isdn);
|
||||||
|
tidy_nl_modem(&nl_tcpip);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef _MBINDEX_H
|
#ifndef _MBINDEX_H
|
||||||
#define _MBINDEX_H
|
#define _MBINDEX_H
|
||||||
|
|
||||||
|
/* $Id$ */
|
||||||
|
|
||||||
typedef struct _fd_list {
|
typedef struct _fd_list {
|
||||||
struct _fd_list *next;
|
struct _fd_list *next;
|
||||||
@ -9,6 +10,18 @@ typedef struct _fd_list {
|
|||||||
} fd_list;
|
} fd_list;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct _nodelist_modem {
|
||||||
|
struct _nodelist_modem *next;
|
||||||
|
char *name;
|
||||||
|
unsigned long mask;
|
||||||
|
unsigned long value;
|
||||||
|
} nodelist_modem;
|
||||||
|
|
||||||
|
|
||||||
|
nodelist_modem *nl_isdn;
|
||||||
|
nodelist_modem *nl_tcpip;
|
||||||
|
|
||||||
|
|
||||||
int lockindex(void);
|
int lockindex(void);
|
||||||
void ulockindex(void);
|
void ulockindex(void);
|
||||||
void Help(void);
|
void Help(void);
|
||||||
|
Reference in New Issue
Block a user