]>
Commit | Line | Data |
---|---|---|
f29718b0 | 1 | /* |
5b74111a | 2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors |
f29718b0 AJ |
3 | * |
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. | |
7 | */ | |
8 | ||
9 | #ifndef SQUID_SRC_HTTP_ONE_TOKENIZER_H | |
10 | #define SQUID_SRC_HTTP_ONE_TOKENIZER_H | |
11 | ||
12 | #include "parser/Tokenizer.h" | |
13 | ||
14 | namespace Http { | |
15 | namespace One { | |
16 | ||
17 | /** | |
18 | * Lexical processor extended to tokenize HTTP/1.x syntax. | |
19 | * | |
20 | * \see ::Parser::Tokenizer for more detail | |
21 | */ | |
22 | class Tokenizer : public ::Parser::Tokenizer | |
23 | { | |
24 | public: | |
57438e03 | 25 | Tokenizer(SBuf &s) : ::Parser::Tokenizer(s), savedStats_(0) {} |
f29718b0 AJ |
26 | |
27 | /** | |
28 | * Attempt to parse a quoted-string lexical construct. | |
29 | * | |
30 | * Governed by: | |
31 | * - RFC 1945 section 2.1 | |
32 | * " | |
33 | * A string of text is parsed as a single word if it is quoted using | |
34 | * double-quote marks. | |
35 | * | |
36 | * quoted-string = ( <"> *(qdtext) <"> ) | |
37 | * | |
38 | * qdtext = <any CHAR except <"> and CTLs, | |
39 | * but including LWS> | |
40 | * | |
41 | * Single-character quoting using the backslash ("\") character is not | |
42 | * permitted in HTTP/1.0. | |
43 | * " | |
44 | * | |
45 | * - RFC 7230 section 3.2.6 | |
46 | * " | |
47 | * A string of text is parsed as a single value if it is quoted using | |
48 | * double-quote marks. | |
49 | * | |
50 | * quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE | |
51 | * qdtext = HTAB / SP /%x21 / %x23-5B / %x5D-7E / obs-text | |
52 | * obs-text = %x80-FF | |
53 | * " | |
54 | * | |
55 | * \param escaped HTTP/1.0 does not permit \-escaped characters | |
56 | */ | |
57 | bool quotedString(SBuf &value, const bool http1p0 = false); | |
58 | ||
59 | /** | |
60 | * Attempt to parse a (token / quoted-string ) lexical construct. | |
61 | */ | |
62 | bool quotedStringOrToken(SBuf &value, const bool http1p0 = false); | |
63 | ||
64 | private: | |
65 | /// parse the internal component of a quote-string, and terminal DQUOTE | |
66 | bool qdText(SBuf &value, const bool http1p0); | |
67 | ||
68 | void checkpoint() { savedCheckpoint_ = buf(); savedStats_ = parsedSize(); } | |
69 | void restoreLastCheckpoint() { undoParse(savedCheckpoint_, savedStats_); } | |
70 | ||
71 | SBuf savedCheckpoint_; | |
72 | SBuf::size_type savedStats_; | |
73 | }; | |
74 | ||
75 | } // namespace One | |
76 | } // namespace Http | |
77 | ||
78 | #endif /* SQUID_SRC_HTTP_ONE_TOKENIZER_H */ | |
79 |