summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/load_file.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ipfilter/lib/load_file.c')
-rw-r--r--contrib/ipfilter/lib/load_file.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/contrib/ipfilter/lib/load_file.c b/contrib/ipfilter/lib/load_file.c
index 9bb3899..a1d1f70 100644
--- a/contrib/ipfilter/lib/load_file.c
+++ b/contrib/ipfilter/lib/load_file.c
@@ -1,12 +1,13 @@
/*
- * Copyright (C) 2006 by Darren Reed.
+ * Copyright (C) 2012 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
- * $Id: load_file.c,v 1.1.2.1 2006/08/25 21:13:04 darrenr Exp $
+ * $Id: load_file.c,v 1.6.2.2 2012/07/22 08:04:24 darren_r Exp $
*/
#include "ipf.h"
+#include <ctype.h>
alist_t *
load_file(char *filename)
@@ -20,13 +21,13 @@ load_file(char *filename)
if (fp == NULL) {
fprintf(stderr, "load_file cannot open '%s'\n", filename);
return NULL;
- }
+ }
a = NULL;
rtop = NULL;
rbot = NULL;
- linenum = 0;
-
+ linenum = 0;
+
while (fgets(line, sizeof(line) - 1, fp)) {
line[sizeof(line) - 1] = '\0';
linenum++;
@@ -35,17 +36,23 @@ load_file(char *filename)
*/
s = strchr(line, '\n');
if (s == NULL) {
- fprintf(stderr, "%d:%s: line too long\n", linenum, filename);
+ fprintf(stderr, "%d:%s: line too long\n",
+ linenum, filename);
fclose(fp);
alist_free(rtop);
return NULL;
}
- *s = '\0';
+ /*
+ * Remove trailing spaces
+ */
+ for (; ISSPACE(*s); s--)
+ *s = '\0';
+
s = strchr(line, '\r');
if (s != NULL)
*s = '\0';
- for (t = line; isspace(*t); t++)
+ for (t = line; ISSPACE(*t); t++)
;
if (*t == '!') {
not = 1;
@@ -56,21 +63,22 @@ load_file(char *filename)
/*
* Remove comment markers
*/
- for (s = t; *s; s++) {
- if (*s == '#')
- *s = '\0';
+ s = strchr(t, '#');
+ if (s != NULL) {
+ *s = '\0';
+ if (s == t)
+ continue;
}
- if (!*t)
- continue;
+
/*
* Trim off tailing white spaces
*/
s = strlen(t) + t - 1;
- while (isspace(*s))
+ while (ISSPACE(*s))
*s-- = '\0';
- if (isdigit(*t)) {
- a = alist_new(4, t);
+ a = alist_new(AF_UNSPEC, t);
+ if (a != NULL) {
a->al_not = not;
if (rbot != NULL)
rbot->al_next = a;
@@ -78,8 +86,8 @@ load_file(char *filename)
rtop = a;
rbot = a;
} else {
- fprintf(stderr, "%s: unrecognised content line %d\n",
- filename, linenum);
+ fprintf(stderr, "%s:%d unrecognised content :%s\n",
+ filename, linenum, t);
}
}
fclose(fp);
OpenPOWER on IntegriCloud