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 #include "net/websockets/websocket_extension_parser.h" | 5 #include "net/websockets/websocket_extension_parser.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 WebSocketExtensionParser::WebSocketExtensionParser() {} | 11 WebSocketExtensionParser::WebSocketExtensionParser() {} |
12 | 12 |
13 WebSocketExtensionParser::~WebSocketExtensionParser() {} | 13 WebSocketExtensionParser::~WebSocketExtensionParser() {} |
14 | 14 |
15 void WebSocketExtensionParser::Parse(const char* data, size_t size) { | 15 void WebSocketExtensionParser::Parse(const char* data, size_t size) { |
16 current_ = data; | 16 current_ = data; |
17 end_ = data + size; | 17 end_ = data + size; |
18 has_error_ = false; | 18 has_error_ = false; |
19 extensions_.clear(); | |
19 | 20 |
20 ConsumeExtension(&extension_); | 21 while (true) { |
21 if (has_error_) return; | 22 WebSocketExtension extension; |
22 ConsumeSpaces(); | 23 ConsumeExtension(&extension); |
23 has_error_ = has_error_ || (current_ != end_); | 24 extensions_.push_back(extension); |
25 if (has_error_) { | |
eroman
2015/03/31 21:11:12
Should this be done before the call to extensions_
tyoshino (SeeGerritForStatus)
2015/04/01 04:57:57
Done.
| |
26 extensions_.clear(); | |
27 return; | |
eroman
2015/03/31 21:11:12
I suggest doing a break instead, and leaving the c
tyoshino (SeeGerritForStatus)
2015/04/01 04:57:57
Done.
| |
28 } | |
29 | |
30 ConsumeSpaces(); | |
31 DCHECK(!has_error_); | |
32 | |
33 if (!ConsumeIfMatch(',')) { | |
34 break; | |
35 } | |
36 } | |
37 | |
38 has_error_ = has_error_ || current_ != end_; | |
39 if (has_error_) | |
40 extensions_.clear(); | |
24 } | 41 } |
25 | 42 |
26 void WebSocketExtensionParser::Consume(char c) { | 43 void WebSocketExtensionParser::Consume(char c) { |
27 DCHECK(!has_error_); | 44 DCHECK(!has_error_); |
28 ConsumeSpaces(); | 45 ConsumeSpaces(); |
29 DCHECK(!has_error_); | 46 DCHECK(!has_error_); |
30 if (current_ == end_ || c != current_[0]) { | 47 if (current_ == end_ || c != current_[0]) { |
31 has_error_ = true; | 48 has_error_ = true; |
32 return; | 49 return; |
33 } | 50 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 return (0 <= c && c <= 31) || c == 127; | 166 return (0 <= c && c <= 31) || c == 127; |
150 } | 167 } |
151 | 168 |
152 // static | 169 // static |
153 bool WebSocketExtensionParser::IsSeparator(char c) { | 170 bool WebSocketExtensionParser::IsSeparator(char c) { |
154 const char separators[] = "()<>@,;:\\\"/[]?={} \t"; | 171 const char separators[] = "()<>@,;:\\\"/[]?={} \t"; |
155 return strchr(separators, c) != NULL; | 172 return strchr(separators, c) != NULL; |
156 } | 173 } |
157 | 174 |
158 } // namespace net | 175 } // namespace net |
OLD | NEW |