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/strings/string_piece.h"
12 #include "net/base/net_export.h"
13 #include "net/websockets/websocket_extension.h"
17 class NET_EXPORT_PRIVATE WebSocketExtensionParser
{
19 WebSocketExtensionParser();
20 ~WebSocketExtensionParser();
22 // Parses the given string as a Sec-WebSocket-Extensions header value.
24 // There must be no newline characters in the input. LWS-concatenation must
25 // have already been done before calling this method.
26 void Parse(const char* data
, size_t size
);
27 void Parse(const std::string
& data
) {
28 Parse(data
.data(), data
.size());
31 // Returns true if the last Parse() method call encountered any syntax error.
32 bool has_error() const { return has_error_
; }
33 // Returns the result of the last Parse() method call.
34 const std::vector
<WebSocketExtension
>& extensions() const {
39 // TODO(tyoshino): Make the following methods return success/fail.
41 void ConsumeExtension(WebSocketExtension
* extension
);
42 void ConsumeExtensionParameter(WebSocketExtension::Parameter
* parameter
);
43 void ConsumeToken(base::StringPiece
* token
);
44 void ConsumeQuotedToken(std::string
* token
);
46 bool Lookahead(char c
);
47 bool ConsumeIfMatch(char c
);
48 size_t UnconsumedBytes() const { return end_
- current_
; }
50 static bool IsControl(char c
);
51 static bool IsSeparator(char c
);
53 // The current position in the input string.
55 // 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_