Roll src/third_party/skia 7b05ff1:dab1f60
[chromium-blink-merge.git] / net / websockets / websocket_extension_parser.h
blob007040de291408aa411fa24eb172a7db6c6246e7
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>
9 #include <vector>
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"
16 namespace net {
18 class NET_EXPORT_PRIVATE WebSocketExtensionParser {
19 public:
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 {
36 return extensions_;
39 private:
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);
46 void ConsumeSpaces();
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.
55 const char* current_;
56 // The pointer of the end of the input string.
57 const char* end_;
58 std::vector<WebSocketExtension> extensions_;
60 DISALLOW_COPY_AND_ASSIGN(WebSocketExtensionParser);
63 } // namespace net
65 #endif // NET_WEBSOCKETS_WEBSOCKET_EXTENSION_PARSER_H_