]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup of the strtokFile, strwordtok and strwordquote code reschuffling
authorhno <>
Sat, 7 Sep 2002 21:12:55 +0000 (21:12 +0000)
committerhno <>
Sat, 7 Sep 2002 21:12:55 +0000 (21:12 +0000)
src/acl.cc
src/cache_cf.cc
src/protos.h
src/tools.cc

index c329a96bb4f2452b83912d636629970b10896108..e02c51891a61ffb4dca0f777aabeaee4a7c1ab41 100644 (file)
@@ -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)
 {
index 9a01f11b00f4cd9d775f1f7ae83426b3785a0a1a..0039f50148af1f27091ca05bc374f3e7170910db 100644 (file)
@@ -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;
index 56214bab0f9b37be079a878bcd9a933dd780ac89..b7f2d6d9437ca1b45fdc7f91a7f0578afeb7552f 100644 (file)
@@ -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
index a784c8ea03fc6a2f7c0968725d05b438387d099b..5abf44245897942d96d268ddcbd0c76c859f4304 100644 (file)
@@ -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;