]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StrList.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 66 HTTP Header Tools */
12 #include "SquidString.h"
15 /** appends an item to the list */
17 strListAdd(String
* str
, const char *item
, char del
)
27 str
->append(item
, strlen(item
));
30 /** returns true iff "m" is a member of the list */
32 strListIsMember(const String
* list
, const char *m
, char del
)
34 const char *pos
= NULL
;
41 while (strListGetItem(list
, del
, &item
, &ilen
, &pos
)) {
42 if (mlen
== ilen
&& !strncasecmp(item
, m
, ilen
))
48 /** returns true iff "s" is a substring of a member of the list */
50 strListIsSubstr(const String
* list
, const char *s
, char del
)
53 return (list
->find(s
) != String::npos
);
56 * Note: the original code with a loop is broken because it uses strstr()
57 * instead of strnstr(). If 's' contains a 'del', strListIsSubstr() may
58 * return true when it should not. If 's' does not contain a 'del', the
59 * implementaion is equavalent to strstr()! Thus, we replace the loop with
60 * strstr() above until strnstr() is available.
65 * iterates through a 0-terminated string of items separated by 'del's.
66 * white space around 'del' is considered to be a part of 'del'
67 * like strtok, but preserves the source, and can iterate several strings at once
69 * returns true if next item is found.
70 * init pos with NULL to start iteration.
73 strListGetItem(const String
* str
, char del
, const char **item
, int *ilen
, const char **pos
)
76 /* ',' is always enabled as field delimiter as this is required for
77 * processing merged header values properly, even if Cookie normally
78 * uses ';' as delimiter.
80 static char delim
[3][8] = {
86 assert(str
&& item
&& pos
);
92 *pos
= str
->termedBuf();
98 /* skip leading whitespace and delimiters */
99 *pos
+= strspn(*pos
, delim
[2]);
101 *item
= *pos
; /* remember item's start */
103 /* find next delimiter */
105 *pos
+= strcspn(*pos
, delim
[quoted
]);
109 } else if (quoted
&& **pos
== '\\') {
114 break; /* Delimiter found, marking the end of this value */
118 len
= *pos
- *item
; /* *pos points to del or '\0' */
121 while (len
> 0 && xisspace((*item
)[len
- 1]))