Probably broke Win7 Tests (dbg)(6). http://build.chromium.org/p/chromium.win/builders...
[chromium-blink-merge.git] / net / websockets / websocket_extension_parser.h
blobef7fe0366575c696f039008d4989246f6b5b43a2
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_
8 #include <string>
10 #include "base/strings/string_piece.h"
11 #include "net/base/net_export.h"
12 #include "net/websockets/websocket_extension.h"
14 namespace net {
16 class NET_EXPORT_PRIVATE WebSocketExtensionParser {
17 public:
18 WebSocketExtensionParser();
19 ~WebSocketExtensionParser();
21 // Parses the given string as a WebSocket extension header value.
22 // This parser assumes some preprocesses are made.
23 // - The parser parses single extension at a time. This means that
24 // the parser parses |extension| in RFC6455 9.1, not |extension-list|.
25 // - There is no newline characters in the input. LWS-concatenation must
26 // have already been done.
27 void Parse(const char* data, size_t size);
28 void Parse(const std::string& data) {
29 Parse(data.data(), data.size());
32 bool has_error() const { return has_error_; }
33 const WebSocketExtension& extension() const { return extension_; }
35 private:
36 void Consume(char c);
37 void ConsumeExtension(WebSocketExtension* extension);
38 void ConsumeExtensionParameter(WebSocketExtension::Parameter* parameter);
39 void ConsumeToken(base::StringPiece* token);
40 void ConsumeQuotedToken(std::string* token);
41 void ConsumeSpaces();
42 bool Lookahead(char c);
43 bool ConsumeIfMatch(char c);
44 size_t UnconsumedBytes() const { return end_ - current_; }
46 static bool IsControl(char c);
47 static bool IsSeparator(char c);
49 const char* current_;
50 const char* end_;
51 bool has_error_;
52 WebSocketExtension extension_;
54 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser);
57 } // namespace net
59 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_