From: hno <> Date: Sat, 7 Sep 2002 21:12:55 +0000 (+0000) Subject: Cleanup of the strtokFile, strwordtok and strwordquote code reschuffling X-Git-Tag: SQUID_3_0_PRE1~775 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=42419a951ea74fa992a8546e805f217326b32f3e;p=thirdparty%2Fsquid.git Cleanup of the strtokFile, strwordtok and strwordquote code reschuffling --- diff --git a/src/acl.cc b/src/acl.cc index c329a96bb4..e02c51891a 100644 --- a/src/acl.cc +++ b/src/acl.cc @@ -1,6 +1,6 @@ /* - * $Id: acl.cc,v 1.283 2002/09/05 21:09:23 hno Exp $ + * $Id: acl.cc,v 1.284 2002/09/07 15:12:55 hno Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -36,9 +36,6 @@ #include "squid.h" #include "splay.h" -static int aclFromFile = 0; -static FILE *aclFile; - static void aclParseDomainList(void *curlist); static void aclParseUserList(void **current); static void aclParseIpList(void *curlist); @@ -50,7 +47,6 @@ static void aclParseProtoList(void *curlist); static void aclParseMethodList(void *curlist); static void aclParseTimeSpec(void *curlist); static void aclParseIntRange(void *curlist); -extern char *strtokFile(void); static void aclDestroyTimeList(acl_time_data * data); static void aclDestroyIntRange(intrange *); static void aclLookupProxyAuthStart(aclCheck_t * checklist); @@ -107,56 +103,6 @@ static SPLAYWALKEE aclDumpArpListWalkee; #endif static int aclCacheMatchAcl(dlink_list * cache, squid_acl acltype, void *data, char *MatchParam); -char * -strtokFile(void) -{ - char *t, *fn; - LOCAL_ARRAY(char, buf, 256); - - strtok_again: - if (!aclFromFile) { - t = (strtok(NULL, w_space)); - if (!t || *t == '#') { - return NULL; - } else if (*t == '\"' || *t == '\'') { - /* quote found, start reading from file */ - fn = ++t; - while (*t && *t != '\"' && *t != '\'') - t++; - *t = '\0'; - if ((aclFile = fopen(fn, "r")) == NULL) { - debug(28, 0) ("strtokFile: %s not found\n", fn); - return (NULL); - } -#if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) - setmode(fileno(aclFile), O_TEXT); -#endif - aclFromFile = 1; - } else { - return t; - } - } - /* aclFromFile */ - if (fgets(buf, 256, aclFile) == NULL) { - /* stop reading from file */ - fclose(aclFile); - aclFromFile = 0; - goto strtok_again; - } else { - t = buf; - /* skip leading and trailing white space */ - t += strspn(buf, w_space); - t[strcspn(t, w_space)] = '\0'; - /* skip comments */ - if (*t == '#') - goto strtok_again; - /* skip blank lines */ - if (!*t) - goto strtok_again; - return t; - } -} - static squid_acl aclStrToType(const char *s) { diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 9a01f11b00..0039f50148 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.413 2002/09/07 15:02:24 hno Exp $ + * $Id: cache_cf.cc,v 1.414 2002/09/07 15:12:56 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -2469,11 +2469,14 @@ requirePathnameExists(const char *name, const char *path) char * strtokFile(void) { + static int fromFile = 0; + static FILE *wordFile = NULL; + char *t, *fn; LOCAL_ARRAY(char, buf, 256); strtok_again: - if (!aclFromFile) { + if (!fromFile) { t = (strtok(NULL, w_space)); if (!t || *t == '#') { return NULL; @@ -2483,23 +2486,24 @@ strtokFile(void) while (*t && *t != '\"' && *t != '\'') t++; *t = '\0'; - if ((aclFile = fopen(fn, "r")) == NULL) { + if ((wordFile = fopen(fn, "r")) == NULL) { debug(28, 0) ("strtokFile: %s not found\n", fn); return (NULL); } #if defined(_SQUID_MSWIN_) || defined(_SQUID_CYGWIN_) - setmode(fileno(aclFile), O_TEXT); + setmode(fileno(wordFile), O_TEXT); #endif - aclFromFile = 1; + fromFile = 1; } else { return t; } } - /* aclFromFile */ - if (fgets(buf, 256, aclFile) == NULL) { + /* fromFile */ + if (fgets(buf, 256, wordFile) == NULL) { /* stop reading from file */ - fclose(aclFile); - aclFromFile = 0; + fclose(wordFile); + wordFile = NULL; + fromFile = 0; goto strtok_again; } else { t = buf; diff --git a/src/protos.h b/src/protos.h index 56214bab0f..b7f2d6d943 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.443 2002/09/07 14:55:24 hno Exp $ + * $Id: protos.h,v 1.444 2002/09/07 15:12:56 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1159,7 +1159,7 @@ extern int isPowTen(int); extern void parseEtcHosts(void); extern int getMyPort(void); -static void strwordquote(MemBuf * mb, const char *str); +char *strwordtok(char *buf, char **t); void strwordquote(MemBuf * mb, const char *str); #if USE_HTCP diff --git a/src/tools.cc b/src/tools.cc index a784c8ea03..5abf442458 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.222 2002/09/07 14:55:24 hno Exp $ + * $Id: tools.cc,v 1.223 2002/09/07 15:12:56 hno Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1013,7 +1013,7 @@ getMyPort(void) * Similar to strtok, but has some rudimentary knowledge * of quoting */ -static char * +char * strwordtok(char *buf, char **t) { unsigned char *word = NULL; @@ -1060,7 +1060,7 @@ strwordtok(char *buf, char **t) /* * Inverse of strwordtok. Quotes a word if needed */ -static void +void strwordquote(MemBuf * mb, const char *str) { int quoted = 0;