summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-09-15 01:13:11 +0200
committerMichael Adam <obnox@samba.org>2009-09-15 02:25:09 +0200
commit93b00446b9b474d561d4f3b25d2215ac7a6ffad4 (patch)
treecefe06c21c2a86876dce8e52568ad05baf91fdbb /src
parent9594b8889ef8bfc241613b03d0dd79de4b5c10ec (diff)
downloadtinyproxy-93b00446b9b474d561d4f3b25d2215ac7a6ffad4.tar.gz
tinyproxy-93b00446b9b474d561d4f3b25d2215ac7a6ffad4.zip
filter: reduce indentation in filter_init by 16 characters by using return.
Michael
Diffstat (limited to 'src')
-rw-r--r--src/filter.c148
1 files changed, 76 insertions, 72 deletions
diff --git a/src/filter.c b/src/filter.c
index 9ec7858..3a955ce 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -54,84 +54,88 @@ void filter_init (void)
char *s;
int cflags;
- if (!fl && !already_init) {
- fd = fopen (config.filter, "r");
- if (fd) {
- p = NULL;
-
- cflags = REG_NEWLINE | REG_NOSUB;
- if (config.filter_extended)
- cflags |= REG_EXTENDED;
- if (!config.filter_casesensitive)
- cflags |= REG_ICASE;
-
- while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
+ if (fl || already_init) {
+ return;
+ }
+
+ fd = fopen (config.filter, "r");
+ if (!fd) {
+ return;
+ }
+
+ p = NULL;
+
+ cflags = REG_NEWLINE | REG_NOSUB;
+ if (config.filter_extended)
+ cflags |= REG_EXTENDED;
+ if (!config.filter_casesensitive)
+ cflags |= REG_ICASE;
+
+ while (fgets (buf, FILTER_BUFFER_LEN, fd)) {
+ /*
+ * Remove any trailing white space and
+ * comments.
+ */
+ s = buf;
+ while (*s) {
+ if (isspace ((unsigned char) *s))
+ break;
+ if (*s == '#') {
/*
- * Remove any trailing white space and
- * comments.
+ * If the '#' char is preceeded by
+ * an escape, it's not a comment
+ * string.
*/
- s = buf;
- while (*s) {
- if (isspace ((unsigned char) *s))
- break;
- if (*s == '#') {
- /*
- * If the '#' char is preceeded by
- * an escape, it's not a comment
- * string.
- */
- if (s == buf
- || *(s - 1) != '\\')
- break;
- }
- ++s;
- }
- *s = '\0';
-
- /* skip leading whitespace */
- s = buf;
- while (*s && isspace ((unsigned char) *s))
- s++;
-
- /* skip blank lines and comments */
- if (*s == '\0')
- continue;
-
- if (!p) /* head of list */
- fl = p =
- (struct filter_list *)
- safecalloc (1,
- sizeof (struct
- filter_list));
- else { /* next entry */
- p->next =
- (struct filter_list *)
- safecalloc (1,
- sizeof (struct
- filter_list));
- p = p->next;
- }
-
- p->pat = safestrdup (s);
- p->cpat =
- (regex_t *) safemalloc (sizeof (regex_t));
- err = regcomp (p->cpat, p->pat, cflags);
- if (err != 0) {
- fprintf (stderr,
- "Bad regex in %s: %s\n",
- config.filter, p->pat);
- exit (EX_DATAERR);
- }
- }
- if (ferror (fd)) {
- perror ("fgets");
- exit (EX_DATAERR);
+ if (s == buf
+ || *(s - 1) != '\\')
+ break;
}
- fclose (fd);
+ ++s;
+ }
+ *s = '\0';
+
+ /* skip leading whitespace */
+ s = buf;
+ while (*s && isspace ((unsigned char) *s))
+ s++;
+
+ /* skip blank lines and comments */
+ if (*s == '\0')
+ continue;
+
+ if (!p) /* head of list */
+ fl = p =
+ (struct filter_list *)
+ safecalloc (1,
+ sizeof (struct
+ filter_list));
+ else { /* next entry */
+ p->next =
+ (struct filter_list *)
+ safecalloc (1,
+ sizeof (struct
+ filter_list));
+ p = p->next;
+ }
- already_init = 1;
+ p->pat = safestrdup (s);
+ p->cpat =
+ (regex_t *) safemalloc (sizeof (regex_t));
+ err = regcomp (p->cpat, p->pat, cflags);
+ if (err != 0) {
+ fprintf (stderr,
+ "Bad regex in %s: %s\n",
+ config.filter, p->pat);
+ exit (EX_DATAERR);
}
}
+ if (ferror (fd)) {
+ perror ("fgets");
+ exit (EX_DATAERR);
+ }
+ fclose (fd);
+
+ already_init = 1;
}
/* unlink the list */