From: Francesco Chemolli Date: Wed, 29 Aug 2012 09:34:34 +0000 (+0200) Subject: Moved StrList-related functions to StrList.h and .cc X-Git-Tag: sourceformat-review-1~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28204b3b1f09fc8e41e1f557999b307a80fd1c94;p=thirdparty%2Fsquid.git Moved StrList-related functions to StrList.h and .cc --- diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index ffc59fe4b6..62ab41a978 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -38,6 +38,7 @@ #include "HttpHdrCc.h" #include "StatHist.h" #include "Store.h" +#include "StrList.h" #include "protos.h" #if HAVE_MAP diff --git a/src/HttpHdrRange.cc b/src/HttpHdrRange.cc index 6474fd90b2..b8217ab461 100644 --- a/src/HttpHdrRange.cc +++ b/src/HttpHdrRange.cc @@ -38,6 +38,7 @@ #include "HttpHeaderRange.h" #include "client_side_request.h" #include "HttpReply.h" +#include "StrList.h" #include "protos.h" /* diff --git a/src/HttpHdrSc.cc b/src/HttpHdrSc.cc index 057e5330b3..43755ea19b 100644 --- a/src/HttpHdrSc.cc +++ b/src/HttpHdrSc.cc @@ -42,6 +42,7 @@ #include "HttpHeaderStat.h" #include "HttpHeaderTools.h" #include "Store.h" +#include "StrList.h" #include "protos.h" #if HAVE_MAP diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 3d2539d0ee..1191e25480 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -48,6 +48,7 @@ #include "rfc1123.h" #include "StatHist.h" #include "Store.h" +#include "StrList.h" #include "TimeOrTag.h" /* diff --git a/src/HttpHeaderTools.cc b/src/HttpHeaderTools.cc index d16d790ca8..07abdc8930 100644 --- a/src/HttpHeaderTools.cc +++ b/src/HttpHeaderTools.cc @@ -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 * diff --git a/src/HttpReply.cc b/src/HttpReply.cc index f0090e1d21..1520f419b4 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -46,6 +46,7 @@ #include "protos.h" #include "SquidTime.h" #include "Store.h" +#include "StrList.h" /* local constants */ diff --git a/src/Makefile.am b/src/Makefile.am index 9fc7b86757..d89603a628 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 index 0000000000..295c560071 --- /dev/null +++ b/src/StrList.cc @@ -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 index 0000000000..829ae9f1ea --- /dev/null +++ b/src/StrList.h @@ -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_ */ diff --git a/src/adaptation/ServiceGroups.cc b/src/adaptation/ServiceGroups.cc index 55802cb6eb..8e44a33c46 100644 --- a/src/adaptation/ServiceGroups.cc +++ b/src/adaptation/ServiceGroups.cc @@ -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): diff --git a/src/adaptation/icap/Options.cc b/src/adaptation/icap/Options.cc index 60bca9ac08..8eec381d22 100644 --- a/src/adaptation/icap/Options.cc +++ b/src/adaptation/icap/Options.cc @@ -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"), diff --git a/src/auth/digest/auth_digest.cc b/src/auth/digest/auth_digest.cc index d98b804e41..2756b2657b 100644 --- a/src/auth/digest/auth_digest.cc +++ b/src/auth/digest/auth_digest.cc @@ -56,6 +56,7 @@ #include "protos.h" #include "wordlist.h" #include "SquidTime.h" +#include "StrList.h" /* Digest Scheme */ diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index cfccd65821..cc9ed614a8 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -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 diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 9c2192ddbb..12158952a3 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -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" diff --git a/src/http.cc b/src/http.cc index 34b44a1b25..d35c71010a 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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 diff --git a/src/protos.h b/src/protos.h index 110896e733..d3e1e66130 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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); diff --git a/src/store.cc b/src/store.cc index a3fe02fd22..5bccf16093 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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"