OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ | 5 #ifndef NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ |
6 #define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ | 6 #define NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "net/base/net_export.h" | 12 #include "net/base/net_export.h" |
13 #include "net/websockets/websocket_extension.h" | 13 #include "net/websockets/websocket_extension.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 | 16 |
17 class NET_EXPORT_PRIVATE WebSocketExtensionParser { | 17 class NET_EXPORT_PRIVATE WebSocketExtensionParser { |
18 public: | 18 public: |
19 WebSocketExtensionParser(); | 19 WebSocketExtensionParser(); |
20 ~WebSocketExtensionParser(); | 20 ~WebSocketExtensionParser(); |
21 | 21 |
22 // Parses the given string as a Sec-WebSocket-Extensions header value. | 22 // Parses the given string as a Sec-WebSocket-Extensions header value. |
23 // | 23 // |
24 // There must be no newline characters in the input. LWS-concatenation must | 24 // There must be no newline characters in the input. LWS-concatenation must |
25 // have already been done before calling this method. | 25 // have already been done before calling this method. |
26 void Parse(const char* data, size_t size); | 26 // |
27 void Parse(const std::string& data) { | 27 // Returns true if the method was successful (no syntax error was found). |
28 Parse(data.data(), data.size()); | 28 bool Parse(const char* data, size_t size); |
29 bool Parse(const std::string& data) { | |
30 return Parse(data.data(), data.size()); | |
29 } | 31 } |
30 | 32 |
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. | 33 // Returns the result of the last Parse() method call. |
34 const std::vector<WebSocketExtension>& extensions() const { | 34 const std::vector<WebSocketExtension>& extensions() const { |
35 return extensions_; | 35 return extensions_; |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 // TODO(tyoshino): Make the following methods return success/fail. | 39 // TODO(tyoshino): Make the following methods return success/fail. |
eroman
2015/04/06 19:07:52
You can now remove this TODO
tyoshino (SeeGerritForStatus)
2015/04/13 14:11:59
Done.
| |
40 void Consume(char c); | 40 bool Consume(char c); |
eroman
2015/04/06 19:07:52
Something else you may consider is to add WARN_UNU
tyoshino (SeeGerritForStatus)
2015/04/13 14:11:59
Done.
| |
41 void ConsumeExtension(WebSocketExtension* extension); | 41 bool ConsumeExtension(WebSocketExtension* extension); |
42 void ConsumeExtensionParameter(WebSocketExtension::Parameter* parameter); | 42 bool ConsumeExtensionParameter(WebSocketExtension::Parameter* parameter); |
43 void ConsumeToken(base::StringPiece* token); | 43 bool ConsumeToken(base::StringPiece* token); |
44 void ConsumeQuotedToken(std::string* token); | 44 bool ConsumeQuotedToken(std::string* token); |
45 void ConsumeSpaces(); | 45 void ConsumeSpaces(); |
46 bool Lookahead(char c); | 46 bool Lookahead(char c); |
47 bool ConsumeIfMatch(char c); | 47 bool ConsumeIfMatch(char c); |
48 size_t UnconsumedBytes() const { return end_ - current_; } | 48 size_t UnconsumedBytes() const { return end_ - current_; } |
49 | 49 |
50 static bool IsControl(char c); | 50 static bool IsControl(char c); |
51 static bool IsSeparator(char c); | 51 static bool IsSeparator(char c); |
52 | 52 |
53 // The current position in the input string. | 53 // The current position in the input string. |
54 const char* current_; | 54 const char* current_; |
55 // The pointer of the end of the input string. | 55 // The pointer of the end of the input string. |
56 const char* end_; | 56 const char* end_; |
57 bool has_error_; | |
58 std::vector<WebSocketExtension> extensions_; | 57 std::vector<WebSocketExtension> extensions_; |
59 | 58 |
60 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser); | 59 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser); |
61 }; | 60 }; |
62 | 61 |
63 } // namespace net | 62 } // namespace net |
64 | 63 |
65 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ | 64 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ |
OLD | NEW |