From c0299e1868312e623c9b2ec6646cc7d1a5fe0f69 Mon Sep 17 00:00:00 2001 From: Robert James Kaes Date: Mon, 15 Aug 2005 03:54:31 +0000 Subject: * [Indent] Ran Source Through indent I re-indented the source code using indent with the following options: indent -kr -bad -bap -nut -i8 -l80 -psl -sob -ss -ncs There are now _no_ tabs in the source files, and all indentation is eight spaces. Lines are 80 characters long, and the procedure type is on it's own line. Read the indent manual for more information about what each option means. --- src/filter.c | 282 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 143 insertions(+), 139 deletions(-) (limited to 'src/filter.c') diff --git a/src/filter.c b/src/filter.c index 161cc66..4f25c74 100644 --- a/src/filter.c +++ b/src/filter.c @@ -1,4 +1,4 @@ -/* $Id: filter.c,v 1.21 2005-07-12 17:39:43 rjkaes Exp $ +/* $Id: filter.c,v 1.22 2005-08-15 03:54:31 rjkaes Exp $ * * Copyright (c) 1999 George Talusan (gstalusan@uwaterloo.ca) * Copyright (c) 2002 James E. Flemer (jflemer@acm.jhu.edu) @@ -30,9 +30,9 @@ static int err; struct filter_list { - struct filter_list *next; - char *pat; - regex_t *cpat; + struct filter_list *next; + char *pat; + regex_t *cpat; }; static struct filter_list *fl = NULL; @@ -45,158 +45,162 @@ static filter_policy_t default_policy = FILTER_DEFAULT_ALLOW; void filter_init(void) { - FILE *fd; - struct filter_list *p; - char buf[FILTER_BUFFER_LEN]; - 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)) { - /* - * Remove any trailing white space and - * comments. - */ - 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 = - safecalloc(1, - sizeof(struct - filter_list)); - else { /* next entry */ - p->next = - safecalloc(1, - sizeof(struct - filter_list)); - p = p->next; - } - - p->pat = safestrdup(s); - p->cpat = safemalloc(sizeof(regex_t)); - if ((err = regcomp(p->cpat, p->pat, cflags)) != 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; - } - } + FILE *fd; + struct filter_list *p; + char buf[FILTER_BUFFER_LEN]; + 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)) { + /* + * Remove any trailing white space and + * comments. + */ + 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 = + safecalloc(1, + sizeof(struct + filter_list)); + else { /* next entry */ + p->next = + safecalloc(1, + sizeof(struct + filter_list)); + p = p->next; + } + + p->pat = safestrdup(s); + p->cpat = safemalloc(sizeof(regex_t)); + if ((err = + regcomp(p->cpat, p->pat, cflags)) != 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 */ void filter_destroy(void) { - struct filter_list *p, *q; - - if (already_init) { - for (p = q = fl; p; p = q) { - regfree(p->cpat); - safefree(p->cpat); - safefree(p->pat); - q = p->next; - safefree(p); - } - fl = NULL; - already_init = 0; - } + struct filter_list *p, *q; + + if (already_init) { + for (p = q = fl; p; p = q) { + regfree(p->cpat); + safefree(p->cpat); + safefree(p->pat); + q = p->next; + safefree(p); + } + fl = NULL; + already_init = 0; + } } /* Return 0 to allow, non-zero to block */ int filter_domain(const char *host) { - struct filter_list *p; - int result; - - if (!fl || !already_init) - goto COMMON_EXIT; - - for (p = fl; p; p = p->next) { - result = regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0); - - if (result == 0) { - if (default_policy == FILTER_DEFAULT_ALLOW) - return 1; - else - return 0; - } - } - - COMMON_EXIT: - if (default_policy == FILTER_DEFAULT_ALLOW) - return 0; - else - return 1; + struct filter_list *p; + int result; + + if (!fl || !already_init) + goto COMMON_EXIT; + + for (p = fl; p; p = p->next) { + result = + regexec(p->cpat, host, (size_t) 0, (regmatch_t *) 0, 0); + + if (result == 0) { + if (default_policy == FILTER_DEFAULT_ALLOW) + return 1; + else + return 0; + } + } + + COMMON_EXIT: + if (default_policy == FILTER_DEFAULT_ALLOW) + return 0; + else + return 1; } /* returns 0 to allow, non-zero to block */ int filter_url(const char *url) { - struct filter_list *p; - int result; - - if (!fl || !already_init) - goto COMMON_EXIT; - - for (p = fl; p; p = p->next) { - result = regexec(p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0); - - if (result == 0) { - if (default_policy == FILTER_DEFAULT_ALLOW) - return 1; - else - return 0; - } - } - - COMMON_EXIT: - if (default_policy == FILTER_DEFAULT_ALLOW) - return 0; - else - return 1; + struct filter_list *p; + int result; + + if (!fl || !already_init) + goto COMMON_EXIT; + + for (p = fl; p; p = p->next) { + result = regexec(p->cpat, url, (size_t) 0, (regmatch_t *) 0, 0); + + if (result == 0) { + if (default_policy == FILTER_DEFAULT_ALLOW) + return 1; + else + return 0; + } + } + + COMMON_EXIT: + if (default_policy == FILTER_DEFAULT_ALLOW) + return 0; + else + return 1; } /* @@ -205,5 +209,5 @@ filter_url(const char *url) void filter_set_default_policy(filter_policy_t policy) { - default_policy = policy; + default_policy = policy; } -- cgit v1.2.3