Code cleanups for nodelist processing

This commit is contained in:
Michiel Broek 2004-07-10 13:26:16 +00:00
parent 19ad88a5db
commit 962fe209c6
4 changed files with 464 additions and 309 deletions

View File

@ -481,8 +481,6 @@ typedef struct _nlusr {
#define NL_HOLD 0x02 /* Node is Hold */
#define NL_PVT 0x04 /* Private node */
#define NL_DUMMY 0x08 /* Dummy entry */
#define NL_ISDN 0x10 /* ISDN Only node */
#define NL_TCPIP 0x20 /* TCP/IP Only node */
/************************************************************************

View File

@ -99,16 +99,12 @@ int nlinfo(faddr *addr)
* Show P flags
*/
printf("P Flag :");
if (nlent->pflag & 0x01)
if (nlent->pflag & NL_DOWN)
printf(" Down");
if (nlent->pflag & 0x02)
if (nlent->pflag & NL_HOLD)
printf(" Hold");
if (nlent->pflag & 0x04)
if (nlent->pflag & NL_PVT)
printf(" Pvt");
if (nlent->pflag & 0x10)
printf(" ISDN");
if (nlent->pflag & 0x20)
printf(" TCP/IP");
printf("\n");
if (nlent->t1) {
printf("System open : ");

View File

@ -48,6 +48,9 @@ long total = 0, entries = 0;
int filenr = 0;
unsigned short regio;
nl_list *nll = NULL;
static char *k, *v;
static int linecnt = 0;
static char *nlpath = NULL;
extern int do_quiet; /* Quiet flag */
@ -56,6 +59,83 @@ time_t t_start; /* Start 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
@ -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 num, i, rc = 0, lineno, boss = FALSE, bossvalid = FALSE;
int num, i, lineno, boss = FALSE, bossvalid = FALSE;
unsigned short upnet, upnode;
char buf[MAXNLLINELEN], *p, *q;
faddr *tmpa;
FILE *nl;
struct _nlidx ndx;
struct _nlusr udx;
nodelist_modem **tmpm;
rc = 0;
if ((nl = fopen(fullpath(nlname), "r")) == NULL) {
WriteError("$Can't open %s", fullpath(nlname));
return 102;
return MBERR_INIT_ERROR;
}
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, ',')))
*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, ',')))
*q++ = '\0';
else {
WriteError("%s(%u): invalid dataline", nlname,lineno);
continue;
}
ndx.type = NL_NONE;
ndx.pflag = 0;
@ -386,7 +477,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
ndx.type = NL_POINT;
else
ndx.type = NL_NODE;
} else
} else {
if (strcasecmp(buf,"Boss") == 0) {
ndx.type = NL_POINT;
bossvalid = FALSE;
@ -436,6 +527,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
bossvalid = TRUE;
}
}
}
if (ndx.type == NL_NONE) {
for (q = buf; *q; q++)
@ -539,19 +631,11 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
q = p;
}
if ((strlen(p) == 3) && (!strcmp(p, "300")) && (q != NULL)) {
if ((strstr(q, (char *)"X75")) ||
(strstr(q, (char *)"V110L")) ||
(strstr(q, (char *)"V110H")) ||
(strstr(q, (char *)"V120L")) ||
(strstr(q, (char *)"V120H")) ||
(strstr(q, (char *)"ISDN")))
for (tmpm = &nl_isdn; *tmpm; tmpm=&((*tmpm)->next))
if (strstr(q, (*tmpm)->name))
ndx.pflag |= NL_ISDN;
if ((strstr(q, (char *)"IFC")) ||
(strstr(q, (char *)"IBN")) ||
(strstr(q, (char *)"ITN")) ||
(strstr(q, (char *)"IVM")) ||
(strstr(q, (char *)"IFT")) ||
(strstr(q, (char *)"IP")))
for (tmpm = &nl_tcpip; *tmpm; tmpm=&((*tmpm)->next))
if (strstr(q, (*tmpm)->name))
ndx.pflag |= NL_TCPIP;
}
@ -581,7 +665,7 @@ int compile(char *nlname, unsigned short zo, unsigned short ne, unsigned short n
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 rc = 0, i;
char *im, *fm, *um, *old, *new;
char *im, *fm, *um, *old, *new, *p, buf[256];
struct _nlfil fdx;
FILE *fp;
FILE *fp, *dbf;
nl_list *tmp;
memset(&fdx, 0, sizeof(fdx));
@ -779,13 +863,13 @@ int nodebld(void)
if ((ifp = fopen(im, "w+")) == NULL) {
WriteError("$Can't create %s",MBSE_SS(im));
return 101;
return MBERR_GENERAL;
}
if ((ufp = fopen(um, "w+")) == NULL) {
WriteError("$Can't create %s", MBSE_SS(um));
fclose(ifp);
unlink(im);
return 101;
return MBERR_GENERAL;
}
if ((ffp = fopen(fm, "w+")) == NULL) {
WriteError("$Can't create %s", MBSE_SS(fm));
@ -793,16 +877,79 @@ int nodebld(void)
unlink(im);
fclose(ufp);
unlink(um);
return 101;
return MBERR_GENERAL;
}
if (!do_quiet) {
colour(3, 0);
colour(CYAN, BLACK);
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)
rc = 102;
rc = MBERR_GENERAL;
else {
fread(&fidonethdr, sizeof(fidonethdr), 1, fp);
@ -814,10 +961,8 @@ int nodebld(void)
for (i = 0; i < 6; i++) {
if (fidonet.seclist[i].zone) {
rc = makelist(fidonet.seclist[i].nodelist,
fidonet.seclist[i].zone,
fidonet.seclist[i].net,
fidonet.seclist[i].node);
rc = makelist(fidonet.seclist[i].nodelist, fidonet.seclist[i].zone,
fidonet.seclist[i].net, fidonet.seclist[i].node);
if (rc)
break;
}
@ -829,6 +974,7 @@ int nodebld(void)
fclose(fp);
}
}
fclose(ufp);
fclose(ffp);
@ -882,6 +1028,8 @@ int nodebld(void)
free(fm);
free(um);
tidy_nllist(&nll);
tidy_nl_modem(&nl_isdn);
tidy_nl_modem(&nl_tcpip);
return rc;
}

View File

@ -1,6 +1,7 @@
#ifndef _MBINDEX_H
#define _MBINDEX_H
/* $Id$ */
typedef struct _fd_list {
struct _fd_list *next;
@ -9,6 +10,18 @@ typedef struct _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);
void ulockindex(void);
void Help(void);