1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_
11 #include "base/compiler_specific.h"
12 #include "base/strings/string_piece.h"
13 #include "net/base/net_export.h"
14 #include "net/websockets/websocket_extension.h"
18 class NET_EXPORT_PRIVATE WebSocketExtensionParser
{
20 WebSocketExtensionParser();
21 ~WebSocketExtensionParser();
23 // Parses the given string as a Sec-WebSocket-Extensions header value.
25 // There must be no newline characters in the input. LWS-concatenation must
26 // have already been done before calling this method.
28 // Returns true if the method was successful (no syntax error was found).
29 bool Parse(const char* data
, size_t size
);
30 bool Parse(const std::string
& data
) {
31 return Parse(data
.data(), data
.size());
34 // Returns the result of the last Parse() method call.
35 const std::vector
<WebSocketExtension
>& extensions() const {
40 WARN_UNUSED_RESULT
bool Consume(char c
);
41 WARN_UNUSED_RESULT
bool ConsumeExtension(WebSocketExtension
* extension
);
42 WARN_UNUSED_RESULT
bool ConsumeExtensionParameter(
43 WebSocketExtension::Parameter
* parameter
);
44 WARN_UNUSED_RESULT
bool ConsumeToken(base::StringPiece
* token
);
45 WARN_UNUSED_RESULT
bool ConsumeQuotedToken(std::string
* token
);
47 WARN_UNUSED_RESULT
bool Lookahead(char c
);
48 WARN_UNUSED_RESULT
bool ConsumeIfMatch(char c
);
49 size_t UnconsumedBytes() const { return end_
- current_
; }
51 static bool IsControl(char c
);
52 static bool IsSeparator(char c
);
54 // The current position in the input string.
56 // The pointer of the end of the input string.
58 std::vector
<WebSocketExtension
> extensions_
;
60 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser
);
65 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_