| 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/compiler_specific.h" |
| 11 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 13 #include "net/websockets/websocket_extension.h" | 14 #include "net/websockets/websocket_extension.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 | 17 |
| 17 class NET_EXPORT_PRIVATE WebSocketExtensionParser { | 18 class NET_EXPORT_PRIVATE WebSocketExtensionParser { |
| 18 public: | 19 public: |
| 19 WebSocketExtensionParser(); | 20 WebSocketExtensionParser(); |
| 20 ~WebSocketExtensionParser(); | 21 ~WebSocketExtensionParser(); |
| 21 | 22 |
| 22 // Parses the given string as a Sec-WebSocket-Extensions header value. | 23 // Parses the given string as a Sec-WebSocket-Extensions header value. |
| 23 // | 24 // |
| 24 // There must be no newline characters in the input. LWS-concatenation must | 25 // There must be no newline characters in the input. LWS-concatenation must |
| 25 // have already been done before calling this method. | 26 // have already been done before calling this method. |
| 26 void Parse(const char* data, size_t size); | 27 // |
| 27 void Parse(const std::string& data) { | 28 // Returns true if the method was successful (no syntax error was found). |
| 28 Parse(data.data(), data.size()); | 29 bool Parse(const char* data, size_t size); |
| 30 bool Parse(const std::string& data) { |
| 31 return Parse(data.data(), data.size()); |
| 29 } | 32 } |
| 30 | 33 |
| 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 // Returns the result of the last Parse() method call. |
| 34 const std::vector<WebSocketExtension>& extensions() const { | 35 const std::vector<WebSocketExtension>& extensions() const { |
| 35 return extensions_; | 36 return extensions_; |
| 36 } | 37 } |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 // TODO(tyoshino): Make the following methods return success/fail. | 40 WARN_UNUSED_RESULT bool Consume(char c); |
| 40 void Consume(char c); | 41 WARN_UNUSED_RESULT bool ConsumeExtension(WebSocketExtension* extension); |
| 41 void ConsumeExtension(WebSocketExtension* extension); | 42 WARN_UNUSED_RESULT bool ConsumeExtensionParameter( |
| 42 void ConsumeExtensionParameter(WebSocketExtension::Parameter* parameter); | 43 WebSocketExtension::Parameter* parameter); |
| 43 void ConsumeToken(base::StringPiece* token); | 44 WARN_UNUSED_RESULT bool ConsumeToken(base::StringPiece* token); |
| 44 void ConsumeQuotedToken(std::string* token); | 45 WARN_UNUSED_RESULT bool ConsumeQuotedToken(std::string* token); |
| 45 void ConsumeSpaces(); | 46 void ConsumeSpaces(); |
| 46 bool Lookahead(char c); | 47 WARN_UNUSED_RESULT bool Lookahead(char c); |
| 47 bool ConsumeIfMatch(char c); | 48 WARN_UNUSED_RESULT bool ConsumeIfMatch(char c); |
| 48 size_t UnconsumedBytes() const { return end_ - current_; } | 49 size_t UnconsumedBytes() const { return end_ - current_; } |
| 49 | 50 |
| 50 static bool IsControl(char c); | 51 static bool IsControl(char c); |
| 51 static bool IsSeparator(char c); | 52 static bool IsSeparator(char c); |
| 52 | 53 |
| 53 // The current position in the input string. | 54 // The current position in the input string. |
| 54 const char* current_; | 55 const char* current_; |
| 55 // The pointer of the end of the input string. | 56 // The pointer of the end of the input string. |
| 56 const char* end_; | 57 const char* end_; |
| 57 bool has_error_; | |
| 58 std::vector<WebSocketExtension> extensions_; | 58 std::vector<WebSocketExtension> extensions_; |
| 59 | 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser); | 60 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 } // namespace net | 63 } // namespace net |
| 64 | 64 |
| 65 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ | 65 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_ |
| OLD | NEW |