]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/http/one/Tokenizer.cc
2 * Copyright (C) 1996-2017 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.
11 #include "http/one/Tokenizer.h"
14 Http::One::Tokenizer::quotedString(SBuf
&returnedToken
, const bool http1p0
)
21 return qdText(returnedToken
, http1p0
);
25 Http::One::Tokenizer::quotedStringOrToken(SBuf
&returnedToken
, const bool http1p0
)
30 return prefix(returnedToken
, CharacterSet::TCHAR
);
32 return qdText(returnedToken
, http1p0
);
36 Http::One::Tokenizer::qdText(SBuf
&returnedToken
, const bool http1p0
)
38 // the initial DQUOTE has been skipped by the caller
41 * RFC 1945 - defines qdtext:
42 * inclusive of LWS (which includes CR and LF)
43 * exclusive of 0x80-0xFF
44 * includes 0x5C ('\') as just a regular character
46 static const CharacterSet qdtext1p0
= CharacterSet("qdtext (HTTP/1.0)", 0x23, 0x7E) +
47 CharacterSet("", "!") +
48 CharacterSet::CR
+ CharacterSet::LF
+ CharacterSet::HTAB
+ CharacterSet::SP
;
50 * RFC 7230 - defines qdtext:
51 * exclusive of CR and LF
52 * inclusive of 0x80-0xFF
53 * includes 0x5C ('\') but only when part of quoted-pair
55 static const CharacterSet qdtext1p1
= CharacterSet("qdtext (HTTP/1.1)", 0x23, 0x5B) +
56 CharacterSet("", "!") +
57 CharacterSet("", 0x5D, 0x7E) +
58 CharacterSet::HTAB
+ CharacterSet::SP
+
59 CharacterSet::OBSTEXT
;
61 // best we can do is a conditional reference since http1p0 value may change per-client
62 const CharacterSet
&tokenChars
= (http1p0
? qdtext1p0
: qdtext1p1
);
65 SBuf::size_type prefixLen
= buf().findFirstNotOf(tokenChars
);
66 returnedToken
.append(consume(prefixLen
));
68 // HTTP/1.1 allows quoted-pair, HTTP/1.0 does not
69 if (!http1p0
&& skip('\\')) {
70 /* RFC 7230 section 3.2.6
72 * The backslash octet ("\") can be used as a single-octet quoting
73 * mechanism within quoted-string and comment constructs. Recipients
74 * that process the value of a quoted-string MUST handle a quoted-pair
75 * as if it were replaced by the octet following the backslash.
77 * quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
79 static const CharacterSet qPairChars
= CharacterSet::HTAB
+ CharacterSet::SP
+ CharacterSet::VCHAR
+ CharacterSet::OBSTEXT
;
81 if (!prefix(escaped
, qPairChars
, 1)) {
82 returnedToken
.clear();
83 restoreLastCheckpoint();
86 returnedToken
.append(escaped
);
89 } else if (skip('"')) {
94 returnedToken
.clear();
95 restoreLastCheckpoint();
99 // else, we have an error
100 debugs(24, 8, "invalid bytes for set " << tokenChars
.name
);
101 returnedToken
.clear();
102 restoreLastCheckpoint();
106 // found the whole string