]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Moved StrList-related functions to StrList.h and .cc
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 29 Aug 2012 09:34:34 +0000 (11:34 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 29 Aug 2012 09:34:34 +0000 (11:34 +0200)
17 files changed:
src/HttpHdrCc.cc
src/HttpHdrRange.cc
src/HttpHdrSc.cc
src/HttpHeader.cc
src/HttpHeaderTools.cc
src/HttpReply.cc
src/Makefile.am
src/StrList.cc [new file with mode: 0644]
src/StrList.h [new file with mode: 0644]
src/adaptation/ServiceGroups.cc
src/adaptation/icap/Options.cc
src/auth/digest/auth_digest.cc
src/client_side_reply.cc
src/client_side_request.cc
src/http.cc
src/protos.h
src/store.cc

index ffc59fe4b6976d2c1b5888064f8f35d9074f1961..62ab41a97822332d3bbbf305dfd6dd5036074c8f 100644 (file)
@@ -38,6 +38,7 @@
 #include "HttpHdrCc.h"
 #include "StatHist.h"
 #include "Store.h"
+#include "StrList.h"
 #include "protos.h"
 
 #if HAVE_MAP
index 6474fd90b25e6ce211684652170ff6636a8fec22..b8217ab461866c045b0f8448bf45efbc86b52f92 100644 (file)
@@ -38,6 +38,7 @@
 #include "HttpHeaderRange.h"
 #include "client_side_request.h"
 #include "HttpReply.h"
+#include "StrList.h"
 #include "protos.h"
 
 /*
index 057e5330b3a970738c3350dc3e62d73358e6ad6b..43755ea19b2df4473787355f29d21bd00c78e89b 100644 (file)
@@ -42,6 +42,7 @@
 #include "HttpHeaderStat.h"
 #include "HttpHeaderTools.h"
 #include "Store.h"
+#include "StrList.h"
 #include "protos.h"
 
 #if HAVE_MAP
index 3d2539d0ee2d2ea3233420f265a10a9ed7ba3a08..1191e254808f808634ca55a2608b7513994bdb37 100644 (file)
@@ -48,6 +48,7 @@
 #include "rfc1123.h"
 #include "StatHist.h"
 #include "Store.h"
+#include "StrList.h"
 #include "TimeOrTag.h"
 
 /*
index d16d790ca8f81367420b3cb63b6e138076b0414e..07abdc89300a867b48ab69dc6c56d5092929e2af 100644 (file)
@@ -47,6 +47,7 @@
 #include "MemBuf.h"
 #include "protos.h"
 #include "Store.h"
+#include "StrList.h"
 
 #if USE_SSL
 #include "ssl/support.h"
@@ -181,123 +182,7 @@ httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive)
     return res;
 }
 
-/** returns true iff "m" is a member of the list */
-int
-strListIsMember(const String * list, const char *m, char del)
-{
-    const char *pos = NULL;
-    const char *item;
-    int ilen = 0;
-    int mlen;
-    assert(list && m);
-    mlen = strlen(m);
-
-    while (strListGetItem(list, del, &item, &ilen, &pos)) {
-        if (mlen == ilen && !strncasecmp(item, m, ilen))
-            return 1;
-    }
-
-    return 0;
-}
-
-/** returns true iff "s" is a substring of a member of the list */
-int
-strListIsSubstr(const String * list, const char *s, char del)
-{
-    assert(list && del);
-    return (list->find(s) != String::npos);
-
-    /** \note
-     * Note: the original code with a loop is broken because it uses strstr()
-     * instead of strnstr(). If 's' contains a 'del', strListIsSubstr() may
-     * return true when it should not. If 's' does not contain a 'del', the
-     * implementaion is equavalent to strstr()! Thus, we replace the loop with
-     * strstr() above until strnstr() is available.
-     */
-}
-
-/** appends an item to the list */
-void
-strListAdd(String * str, const char *item, char del)
-{
-    assert(str && item);
-
-    if (str->size()) {
-        char buf[3];
-        buf[0] = del;
-        buf[1] = ' ';
-        buf[2] = '\0';
-        str->append(buf, 2);
-    }
-
-    str->append(item, strlen(item));
-}
 
-/**
- * iterates through a 0-terminated string of items separated by 'del's.
- * white space around 'del' is considered to be a part of 'del'
- * like strtok, but preserves the source, and can iterate several strings at once
- *
- * returns true if next item is found.
- * init pos with NULL to start iteration.
- */
-int
-strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos)
-{
-    size_t len;
-    /* ',' is always enabled as field delimiter as this is required for
-     * processing merged header values properly, even if Cookie normally
-     * uses ';' as delimiter.
-     */
-    static char delim[3][8] = {
-        "\"?,",
-        "\"\\",
-        " ?,\t\r\n"
-    };
-    int quoted = 0;
-    assert(str && item && pos);
-
-    delim[0][1] = del;
-    delim[2][1] = del;
-
-    if (!*pos) {
-        *pos = str->termedBuf();
-
-        if (!*pos)
-            return 0;
-    }
-
-    /* skip leading whitespace and delimiters */
-    *pos += strspn(*pos, delim[2]);
-
-    *item = *pos;              /* remember item's start */
-
-    /* find next delimiter */
-    do {
-        *pos += strcspn(*pos, delim[quoted]);
-        if (**pos == '"') {
-            quoted = !quoted;
-            *pos += 1;
-        } else if (quoted && **pos == '\\') {
-            *pos += 1;
-            if (**pos)
-                *pos += 1;
-        } else {
-            break;             /* Delimiter found, marking the end of this value */
-        }
-    } while (**pos);
-
-    len = *pos - *item;                /* *pos points to del or '\0' */
-
-    /* rtrim */
-    while (len > 0 && xisspace((*item)[len - 1]))
-        --len;
-
-    if (ilen)
-        *ilen = len;
-
-    return len > 0;
-}
 
 /** handy to printf prefixes of potentially very long buffers */
 const char *
index f0090e1d211c39dcb9643c570a11ffb5a4f6c9db..1520f419b421d81234cbb2c70d32c2238735994c 100644 (file)
@@ -46,6 +46,7 @@
 #include "protos.h"
 #include "SquidTime.h"
 #include "Store.h"
+#include "StrList.h"
 
 /* local constants */
 
index 9fc7b86757102e38664b720135f6d154fa737a49..d89603a6287a87298975d074c0df26e6a199b4ff 100644 (file)
@@ -452,6 +452,8 @@ squid_SOURCES = \
        StatHist.h \
        StatHist.cc \
        String.cc \
+       StrList.h \
+       StrList.cc \
        stmem.cc \
        stmem.h \
        store.cc \
@@ -1118,6 +1120,8 @@ tests_testHttpReply_SOURCES=\
        SquidString.h \
        SquidTime.h \
        String.cc \
+       StrList.h \
+       StrList.cc \
        log/access_log.h \
        tests/stub_access_log.cc \
        cache_cf.h \
@@ -1203,6 +1207,8 @@ tests_testACLMaxUserIP_SOURCES= \
        StatCounters.cc \
        StatCounters.h \
        StatHist.h \
+       StrList.h \
+       StrList.cc \
        tests/stub_StatHist.cc \
        stmem.cc \
        String.cc \
@@ -1439,6 +1445,8 @@ tests_testCacheManager_SOURCES = \
        StatCounters.h \
        StatCounters.cc \
        StatHist.h \
+       StrList.h \
+       StrList.cc \
        tests/stub_StatHist.cc \
        stmem.cc \
        store.cc \
@@ -1596,6 +1604,8 @@ tests_testDiskIO_SOURCES = \
        store_swapmeta.cc \
        store.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        log/access_log.h \
        tests/stub_access_log.cc \
@@ -1800,6 +1810,8 @@ tests_testEvent_SOURCES = \
        refresh.cc \
        RemovalPolicy.cc \
        Server.cc \
+  StrList.h \
+  StrList.cc \
        $(SNMP_SOURCE) \
        SquidMath.cc \
        SquidMath.h \
@@ -2050,6 +2062,8 @@ tests_testEventLoop_SOURCES = \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        tests/testEventLoop.cc \
        tests/testEventLoop.h \
@@ -2262,6 +2276,8 @@ tests_test_http_range_SOURCES = \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        tests/test_http_range.cc \
        tests/stub_ipc_Forwarder.cc \
@@ -2516,6 +2532,8 @@ tests_testHttpRequest_SOURCES = \
        StoreMetaURL.cc \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
+  StrList.h \
+  StrList.cc \
        event.cc \
        tools.h \
        tools.cc \
@@ -2640,6 +2658,8 @@ tests_testStore_SOURCES= \
        store_key_md5.h \
        store_key_md5.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        tests/CapturingStoreEntry.h \
        log/access_log.h \
@@ -2881,6 +2901,8 @@ tests_testUfs_SOURCES = \
        StatCounters.cc \
        StatHist.h \
        StatHist.cc \
+  StrList.h \
+  StrList.cc \
        HttpHdrRange.cc \
        ETag.cc \
        tests/stub_errorpage.cc \
@@ -3006,6 +3028,8 @@ tests_testRock_SOURCES = \
        store_swapmeta.cc \
        store_swapout.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        tests/testRock.cc \
        tests/testMain.cc \
@@ -3519,6 +3543,8 @@ tests_testURL_SOURCES = \
        StoreMetaVary.cc \
        StoreSwapLogData.cc \
        String.cc \
+  StrList.h \
+  StrList.cc \
        SwapDir.cc \
        MemStore.cc \
        tests/stub_debug.cc \
diff --git a/src/StrList.cc b/src/StrList.cc
new file mode 100644 (file)
index 0000000..295c560
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * DEBUG: section 66    HTTP Header Tools
+ * AUTHOR: Alex Rousskov
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#include "squid.h"
+#include "SquidString.h"
+#include "StrList.h"
+
+/** appends an item to the list */
+void
+strListAdd(String * str, const char *item, char del)
+{
+    assert(str && item);
+    if (str->size()) {
+        char buf[3];
+        buf[0] = del;
+        buf[1] = ' ';
+        buf[2] = '\0';
+        str->append(buf, 2);
+    }
+    str->append(item, strlen(item));
+}
+
+/** returns true iff "m" is a member of the list */
+int
+strListIsMember(const String * list, const char *m, char del)
+{
+    const char *pos = NULL;
+    const char *item;
+    int ilen = 0;
+    int mlen;
+
+    assert(list && m);
+    mlen = strlen(m);
+    while (strListGetItem(list, del, &item, &ilen, &pos)) {
+        if (mlen == ilen && !strncasecmp(item, m, ilen))
+            return 1;
+    }
+    return 0;
+}
+
+/** returns true iff "s" is a substring of a member of the list */
+int
+strListIsSubstr(const String * list, const char *s, char del)
+{
+    assert(list && del);
+    return (list->find(s) != String::npos);
+
+    /** \note
+     * Note: the original code with a loop is broken because it uses strstr()
+     * instead of strnstr(). If 's' contains a 'del', strListIsSubstr() may
+     * return true when it should not. If 's' does not contain a 'del', the
+     * implementaion is equavalent to strstr()! Thus, we replace the loop with
+     * strstr() above until strnstr() is available.
+     */
+}
+
+/**
+ * iterates through a 0-terminated string of items separated by 'del's.
+ * white space around 'del' is considered to be a part of 'del'
+ * like strtok, but preserves the source, and can iterate several strings at once
+ *
+ * returns true if next item is found.
+ * init pos with NULL to start iteration.
+ */
+int
+strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos)
+{
+    size_t len;
+    /* ',' is always enabled as field delimiter as this is required for
+     * processing merged header values properly, even if Cookie normally
+     * uses ';' as delimiter.
+     */
+    static char delim[3][8] = {
+        "\"?,",
+        "\"\\",
+        " ?,\t\r\n"
+    };
+    int quoted = 0;
+    assert(str && item && pos);
+
+    delim[0][1] = del;
+    delim[2][1] = del;
+
+    if (!*pos) {
+        *pos = str->termedBuf();
+
+        if (!*pos)
+            return 0;
+    }
+
+    /* skip leading whitespace and delimiters */
+    *pos += strspn(*pos, delim[2]);
+
+    *item = *pos;       /* remember item's start */
+
+    /* find next delimiter */
+    do {
+        *pos += strcspn(*pos, delim[quoted]);
+        if (**pos == '"') {
+            quoted = !quoted;
+            *pos += 1;
+        } else if (quoted && **pos == '\\') {
+            *pos += 1;
+            if (**pos)
+                *pos += 1;
+        } else {
+            break;      /* Delimiter found, marking the end of this value */
+        }
+    } while (**pos);
+
+    len = *pos - *item;     /* *pos points to del or '\0' */
+
+    /* rtrim */
+    while (len > 0 && xisspace((*item)[len - 1]))
+        --len;
+
+    if (ilen)
+        *ilen = len;
+
+    return len > 0;
+}
+
diff --git a/src/StrList.h b/src/StrList.h
new file mode 100644 (file)
index 0000000..829ae9f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * DEBUG: section 66    HTTP Header Tools
+ * AUTHOR: Alex Rousskov
+ *
+ * SQUID Web Proxy Cache          http://www.squid-cache.org/
+ * ----------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from
+ *  the Internet community; see the CONTRIBUTORS file for full
+ *  details.   Many organizations have provided support for Squid's
+ *  development; see the SPONSORS file for full details.  Squid is
+ *  Copyrighted (C) 2001 by the Regents of the University of
+ *  California; see the COPYRIGHT file for full details.  Squid
+ *  incorporates software developed and/or copyrighted by other
+ *  sources; see the CREDITS file for full details.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ *
+ */
+
+#ifndef SQUID_STRLIST_H_
+#define SQUID_STRLIST_H_
+
+class String;
+
+extern void strListAdd(String * str, const char *item, char del);
+extern int strListIsMember(const String * str, const char *item, char del);
+extern int strListIsSubstr(const String * list, const char *s, char del);
+extern int strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos);
+
+#endif /* SQUID_STRLIST_H_ */
index 55802cb6eb1ff8fe602a1202ccad5183174adffe..8e44a33c46476e7543b6ed47a5f4a691161a747f 100644 (file)
@@ -8,6 +8,7 @@
 #include "ConfigParser.h"
 #include "Debug.h"
 #include "protos.h"
+#include "StrList.h"
 #include "wordlist.h"
 
 Adaptation::ServiceGroup::ServiceGroup(const String &aKind, bool allSame):
index 60bca9ac0860c0f495281dce2259080409e2c016..8eec381d2282162cfbb9b50ccb3295e13145e898 100644 (file)
@@ -5,6 +5,7 @@
 #include "HttpReply.h"
 #include "protos.h"
 #include "SquidTime.h"
+#include "StrList.h"
 #include "wordlist.h"
 
 Adaptation::Icap::Options::Options(): error("unconfigured"),
index d98b804e4195cf21ed05a3b50e3a764392d681e1..2756b2657b9fc7681fb7958c52cd57958f8022b3 100644 (file)
@@ -56,6 +56,7 @@
 #include "protos.h"
 #include "wordlist.h"
 #include "SquidTime.h"
+#include "StrList.h"
 
 /* Digest Scheme */
 
index cfccd658215d6186bc5b95fc13910e66a68455d3..cc9ed614a859fc54a53611bd2e1340e739a7de10 100644 (file)
@@ -59,6 +59,7 @@
 #include "SquidTime.h"
 #include "Store.h"
 #include "StoreClient.h"
+#include "StrList.h"
 #include "tools.h"
 #include "URL.h"
 #if USE_AUTH
index 9c2192ddbba8d0f8bafaeaa3279d3ffd3d7c0e01..12158952a329d6cc021db90eb2231c352d506d75 100644 (file)
@@ -72,6 +72,7 @@
 #include "protos.h"
 #include "SquidTime.h"
 #include "Store.h"
+#include "StrList.h"
 #include "tools.h"
 #include "URL.h"
 #include "wordlist.h"
index 34b44a1b258f05464aec32b9b043d88162568662..d35c71010ae364e4cc68c52c311715284055e88d 100644 (file)
@@ -70,6 +70,7 @@
 #include "SquidTime.h"
 #include "StatCounters.h"
 #include "Store.h"
+#include "StrList.h"
 #include "tools.h"
 #include "URL.h"
 
@@ -1586,7 +1587,7 @@ httpFixupAuthentication(HttpRequest * request, const HttpHeader * hdr_in, HttpHe
     }
     // if no external user credentials are available to fake authentication with PASS acts like PASSTHRU
     if (strcmp(request->peer_login, "PASS") == 0)
-        continue;
+        return;
 
     /* Kerberos login to peer */
 #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI
index 110896e733a143e5b90bfe2ba27356f4c97cd02a..d3e1e66130b08c1782cc2f0caafabd2b6b38f8de 100644 (file)
@@ -55,11 +55,6 @@ class FwdState;
 class HttpRequest;
 class HttpReply;
 
-/* TODO: move to StrList.h */
-SQUIDCEXTERN void strListAdd(String * str, const char *item, char del);
-SQUIDCEXTERN int strListIsMember(const String * str, const char *item, char del);
-SQUIDCEXTERN int strListIsSubstr(const String * list, const char *s, char del);
-SQUIDCEXTERN int strListGetItem(const String * str, char del, const char **item, int *ilen, const char **pos);
 
 extern const char *getStringPrefix(const char *str, const char *end);
 
index a3fe02fd22f44b88128958972eb4ed0297ffdb40..5bccf16093697ee3255b8ab25b79ba45a94a1e8d 100644 (file)
@@ -58,6 +58,7 @@
 #include "store_key_md5.h"
 #include "StoreIOState.h"
 #include "StoreMeta.h"
+#include "StrList.h"
 #include "store_key_md5.h"
 #include "SwapDir.h"
 #include "swap_log_op.h"