]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Some reshuffling of code to where it belongs
authorhno <>
Sat, 7 Sep 2002 20:55:24 +0000 (20:55 +0000)
committerhno <>
Sat, 7 Sep 2002 20:55:24 +0000 (20:55 +0000)
strtokFile from acl.c to cache_cf.c

strwordtok/strwordquote from external_acl.c to tools.c

prototypes for the same.

src/cache_cf.cc
src/external_acl.cc
src/protos.h
src/tools.cc

index d9e122f4a531f125dc313172e375e8408253f715..3636aec80159740a52e49ec11cb0121e938a47a5 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.411 2002/09/01 15:16:33 hno Exp $
+ * $Id: cache_cf.cc,v 1.412 2002/09/07 14:55:24 hno Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -75,7 +75,6 @@ static int parseTimeUnits(const char *unit);
 static void parseTimeLine(time_t * tptr, const char *units);
 static void parse_ushort(u_short * var);
 static void parse_string(char **);
-void parse_wordlist(wordlist **);
 static void default_all(void);
 static void defaults_if_none(void);
 static int parse_line(char *);
@@ -2465,3 +2464,54 @@ requirePathnameExists(const char *name, const char *path)
     if (stat(path, &sb) < 0)
        fatalf("%s: %s", path, xstrerror());
 }
+
+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;
+    }
+}
+
index d26a4601487bcfedd6e0606667c51e3251863c5c..2af23e6dcf43cf5644870368846498b5bc8fd775 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: external_acl.cc,v 1.12 2002/09/07 14:39:52 hno Exp $
+ * $Id: external_acl.cc,v 1.13 2002/09/07 14:55:24 hno Exp $
  *
  * DEBUG: section 82    External ACL
  * AUTHOR: Henrik Nordstrom, MARA Systems AB
@@ -57,9 +57,6 @@ static void external_acl_cache_delete(external_acl * def, external_acl_entry * e
 static int external_acl_entry_expired(external_acl * def, external_acl_entry * entry);
 static void external_acl_cache_touch(external_acl * def, external_acl_entry * entry);
 
-extern char *strtokFile(void);
-static void strwordquote(MemBuf * mb, const char *str);
-
 /*******************************************************************
  * external_acl cache entry
  * Used opaqueue in the interface
@@ -654,73 +651,6 @@ free_externalAclState(void *data)
     cbdataReferenceDone(state->def);
 }
 
-/* FIXME: This should be moved to tools.c */
-static char *
-strwordtok(char *buf, char **t)
-{
-    unsigned char *word = NULL;
-    unsigned char *p = (unsigned char *) buf;
-    unsigned char *d;
-    unsigned char ch;
-    int quoted = 0;
-    if (!p)
-       p = (unsigned char *) *t;
-    if (!p)
-       goto error;
-    while (*p && isspace(*p))
-       p++;
-    if (!*p)
-       goto error;
-    word = d = p;
-    while ((ch = *p)) {
-       switch (ch) {
-       case '\\':
-           p++;
-           *d++ = ch = *p;
-           if (ch)
-               p++;
-           break;
-       case '"':
-           quoted = !quoted;
-           p++;
-       default:
-           if (!quoted && isspace(*p)) {
-               p++;
-               goto done;
-           }
-           *d++ = *p++;
-           break;
-       }
-    }
-  done:
-    *d++ = '\0';
-  error:
-    *t = (char *) p;
-    return (char *) word;
-}
-
-static void
-strwordquote(MemBuf * mb, const char *str)
-{
-    int quoted = 0;
-    if (strchr(str, ' ')) {
-       quoted = 1;
-       memBufAppend(mb, "\"", 1);
-    }
-    while (*str) {
-       int l = strcspn(str, "\"\\");
-       memBufAppend(mb, str, l);
-       str += l;
-       while (*str == '"' || *str == '\\') {
-           memBufAppend(mb, "\\", 1);
-           memBufAppend(mb, str, 1);
-           str++;
-       }
-    }
-    if (quoted)
-       memBufAppend(mb, "\"", 1);
-}
-
 /*
  * The helper program receives queries on stdin, one
  * per line, and must return the result on on stdout as
index 89226c8c27811c1a4277c41f0191476c6aeb735c..56214bab0f9b37be079a878bcd9a933dd780ac89 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.442 2002/07/20 12:30:04 hno Exp $
+ * $Id: protos.h,v 1.443 2002/09/07 14:55:24 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -1159,6 +1159,9 @@ extern int isPowTen(int);
 extern void parseEtcHosts(void);
 extern int getMyPort(void);
 
+static void strwordquote(MemBuf * mb, const char *str);
+void strwordquote(MemBuf * mb, const char *str);
+
 #if USE_HTCP
 extern void htcpInit(void);
 extern void htcpQuery(StoreEntry * e, request_t * req, peer * p);
@@ -1334,5 +1337,6 @@ typedef void EAH(void *data, void *result);
 extern void externalAclLookup(aclCheck_t * ch, void *acl_data, EAH * handler, void *data);
 extern void externalAclInit(void);
 extern void externalAclShutdown(void);
+extern char *strtokFile(void);
 
 #endif /* SQUID_PROTOS_H */
index 244577029f9ceae229e20854d9324350db0a8e24..a784c8ea03fc6a2f7c0968725d05b438387d099b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tools.cc,v 1.221 2002/09/01 15:16:35 hno Exp $
+ * $Id: tools.cc,v 1.222 2002/09/07 14:55:24 hno Exp $
  *
  * DEBUG: section 21    Misc Functions
  * AUTHOR: Harvest Derived
@@ -1008,3 +1008,76 @@ getMyPort(void)
     fatal("No port defined");
     return 0;                  /* NOT REACHED */
 }
+
+/*
+ * Similar to strtok, but has some rudimentary knowledge
+ * of quoting
+ */
+static char *
+strwordtok(char *buf, char **t)
+{
+    unsigned char *word = NULL;
+    unsigned char *p = (unsigned char *) buf;
+    unsigned char *d;
+    unsigned char ch;
+    int quoted = 0;
+    if (!p)
+       p = (unsigned char *) *t;
+    if (!p)
+       goto error;
+    while (*p && isspace(*p))
+       p++;
+    if (!*p)
+       goto error;
+    word = d = p;
+    while ((ch = *p)) {
+       switch (ch) {
+       case '\\':
+           p++;
+           *d++ = ch = *p;
+           if (ch)
+               p++;
+           break;
+       case '"':
+           quoted = !quoted;
+           p++;
+       default:
+           if (!quoted && isspace(*p)) {
+               p++;
+               goto done;
+           }
+           *d++ = *p++;
+           break;
+       }
+    }
+  done:
+    *d++ = '\0';
+  error:
+    *t = (char *) p;
+    return (char *) word;
+}
+
+/*
+ * Inverse of strwordtok. Quotes a word if needed
+ */
+static void
+strwordquote(MemBuf * mb, const char *str)
+{
+    int quoted = 0;
+    if (strchr(str, ' ')) {
+       quoted = 1;
+       memBufAppend(mb, "\"", 1);
+    }
+    while (*str) {
+       int l = strcspn(str, "\"\\");
+       memBufAppend(mb, str, l);
+       str += l;
+       while (*str == '"' || *str == '\\') {
+           memBufAppend(mb, "\\", 1);
+           memBufAppend(mb, str, 1);
+           str++;
+       }
+    }
+    if (quoted)
+       memBufAppend(mb, "\"", 1);
+}