Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(533)

Side by Side Diff: net/websockets/websocket_extension_parser.cc

Issue 1047623002: Support parsing a Sec-WebSocket-Extensions header with multiple elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 ConsumeExtension();
22 ConsumeSpaces(); 23 if (has_error_)
23 has_error_ = has_error_ || (current_ != end_); 24 return;
25
26 ConsumeSpaces();
27 DCHECK(!has_error_);
28
29 if (!ConsumeIfMatch(',')) {
30 break;
31 }
32 }
33
34 has_error_ |= current_ != end_;
yhirano 2015/03/30 11:02:03 '|=' is a bitwise operation, so I prefer the origi
tyoshino (SeeGerritForStatus) 2015/03/31 06:17:44 Oops.. Fixed
24 } 35 }
25 36
26 void WebSocketExtensionParser::Consume(char c) { 37 void WebSocketExtensionParser::Consume(char c) {
27 DCHECK(!has_error_); 38 DCHECK(!has_error_);
28 ConsumeSpaces(); 39 ConsumeSpaces();
29 DCHECK(!has_error_); 40 DCHECK(!has_error_);
30 if (current_ == end_ || c != current_[0]) { 41 if (current_ == end_ || c != current_[0]) {
31 has_error_ = true; 42 has_error_ = true;
32 return; 43 return;
33 } 44 }
34 ++current_; 45 ++current_;
35 } 46 }
36 47
37 void WebSocketExtensionParser::ConsumeExtension(WebSocketExtension* extension) { 48 void WebSocketExtensionParser::ConsumeExtension() {
38 DCHECK(!has_error_); 49 DCHECK(!has_error_);
39 base::StringPiece name; 50 base::StringPiece name;
40 ConsumeToken(&name); 51 ConsumeToken(&name);
41 if (has_error_) return; 52 if (has_error_) return;
42 *extension = WebSocketExtension(name.as_string()); 53 extensions_.push_back(WebSocketExtension(name.as_string()));
43 54
44 while (ConsumeIfMatch(';')) { 55 while (ConsumeIfMatch(';')) {
45 WebSocketExtension::Parameter parameter((std::string())); 56 WebSocketExtension::Parameter parameter((std::string()));
46 ConsumeExtensionParameter(&parameter); 57 ConsumeExtensionParameter(&parameter);
47 if (has_error_) return; 58 if (has_error_) return;
48 extension->Add(parameter); 59 extensions_.back().Add(parameter);
49 } 60 }
50 } 61 }
51 62
52 void WebSocketExtensionParser::ConsumeExtensionParameter( 63 void WebSocketExtensionParser::ConsumeExtensionParameter(
53 WebSocketExtension::Parameter* parameter) { 64 WebSocketExtension::Parameter* parameter) {
54 DCHECK(!has_error_); 65 DCHECK(!has_error_);
55 base::StringPiece name, value; 66 base::StringPiece name, value;
56 std::string value_string; 67 std::string value_string;
57 68
58 ConsumeToken(&name); 69 ConsumeToken(&name);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return (0 <= c && c <= 31) || c == 127; 160 return (0 <= c && c <= 31) || c == 127;
150 } 161 }
151 162
152 // static 163 // static
153 bool WebSocketExtensionParser::IsSeparator(char c) { 164 bool WebSocketExtensionParser::IsSeparator(char c) {
154 const char separators[] = "()<>@,;:\\\"/[]?={} \t"; 165 const char separators[] = "()<>@,;:\\\"/[]?={} \t";
155 return strchr(separators, c) != NULL; 166 return strchr(separators, c) != NULL;
156 } 167 }
157 168
158 } // namespace net 169 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698