]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StrList.cc
2 * DEBUG: section 66 HTTP Header Tools
3 * AUTHOR: Alex Rousskov
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "SquidString.h"
37 /** appends an item to the list */
39 strListAdd(String
* str
, const char *item
, char del
)
49 str
->append(item
, strlen(item
));
52 /** returns true iff "m" is a member of the list */
54 strListIsMember(const String
* list
, const char *m
, char del
)
56 const char *pos
= NULL
;
63 while (strListGetItem(list
, del
, &item
, &ilen
, &pos
)) {
64 if (mlen
== ilen
&& !strncasecmp(item
, m
, ilen
))
70 /** returns true iff "s" is a substring of a member of the list */
72 strListIsSubstr(const String
* list
, const char *s
, char del
)
75 return (list
->find(s
) != String::npos
);
78 * Note: the original code with a loop is broken because it uses strstr()
79 * instead of strnstr(). If 's' contains a 'del', strListIsSubstr() may
80 * return true when it should not. If 's' does not contain a 'del', the
81 * implementaion is equavalent to strstr()! Thus, we replace the loop with
82 * strstr() above until strnstr() is available.
87 * iterates through a 0-terminated string of items separated by 'del's.
88 * white space around 'del' is considered to be a part of 'del'
89 * like strtok, but preserves the source, and can iterate several strings at once
91 * returns true if next item is found.
92 * init pos with NULL to start iteration.
95 strListGetItem(const String
* str
, char del
, const char **item
, int *ilen
, const char **pos
)
98 /* ',' is always enabled as field delimiter as this is required for
99 * processing merged header values properly, even if Cookie normally
100 * uses ';' as delimiter.
102 static char delim
[3][8] = {
108 assert(str
&& item
&& pos
);
114 *pos
= str
->termedBuf();
120 /* skip leading whitespace and delimiters */
121 *pos
+= strspn(*pos
, delim
[2]);
123 *item
= *pos
; /* remember item's start */
125 /* find next delimiter */
127 *pos
+= strcspn(*pos
, delim
[quoted
]);
131 } else if (quoted
&& **pos
== '\\') {
136 break; /* Delimiter found, marking the end of this value */
140 len
= *pos
- *item
; /* *pos points to del or '\0' */
143 while (len
> 0 && xisspace((*item
)[len
- 1]))