| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_handshake.h" | 5 #include "net/websockets/websocket_handshake.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/md5.h" | 11 #include "base/md5.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" |
| 16 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
| 17 #include "net/http/http_util.h" | 18 #include "net/http/http_util.h" |
| 18 | 19 |
| 19 namespace net { | 20 namespace net { |
| 20 | 21 |
| 21 const int WebSocketHandshake::kWebSocketPort = 80; | 22 const int WebSocketHandshake::kWebSocketPort = 80; |
| 22 const int WebSocketHandshake::kSecureWebSocketPort = 443; | 23 const int WebSocketHandshake::kSecureWebSocketPort = 443; |
| 23 | 24 |
| 24 WebSocketHandshake::WebSocketHandshake( | 25 WebSocketHandshake::WebSocketHandshake( |
| 25 const GURL& url, | 26 const GURL& url, |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 rand_ = rand; | 274 rand_ = rand; |
| 274 } | 275 } |
| 275 | 276 |
| 276 void WebSocketHandshake::Parameter::GenerateSecWebSocketKey( | 277 void WebSocketHandshake::Parameter::GenerateSecWebSocketKey( |
| 277 uint32* number, std::string* key) { | 278 uint32* number, std::string* key) { |
| 278 uint32 space = rand_(1, 12); | 279 uint32 space = rand_(1, 12); |
| 279 uint32 max = 4294967295U / space; | 280 uint32 max = 4294967295U / space; |
| 280 *number = rand_(0, max); | 281 *number = rand_(0, max); |
| 281 uint32 product = *number * space; | 282 uint32 product = *number * space; |
| 282 | 283 |
| 283 std::string s = StringPrintf("%u", product); | 284 std::string s = base::StringPrintf("%u", product); |
| 284 int n = rand_(1, 12); | 285 int n = rand_(1, 12); |
| 285 for (int i = 0; i < n; i++) { | 286 for (int i = 0; i < n; i++) { |
| 286 int pos = rand_(0, s.length()); | 287 int pos = rand_(0, s.length()); |
| 287 int chpos = rand_(0, sizeof(randomCharacterInSecWebSocketKey) - 1); | 288 int chpos = rand_(0, sizeof(randomCharacterInSecWebSocketKey) - 1); |
| 288 s = s.substr(0, pos).append(1, randomCharacterInSecWebSocketKey[chpos]) + | 289 s = s.substr(0, pos).append(1, randomCharacterInSecWebSocketKey[chpos]) + |
| 289 s.substr(pos); | 290 s.substr(pos); |
| 290 } | 291 } |
| 291 for (uint32 i = 0; i < space; i++) { | 292 for (uint32 i = 0; i < space; i++) { |
| 292 int pos = rand_(1, s.length() - 1); | 293 int pos = rand_(1, s.length() - 1); |
| 293 s = s.substr(0, pos) + " " + s.substr(pos); | 294 s = s.substr(0, pos) + " " + s.substr(pos); |
| 294 } | 295 } |
| 295 *key = s; | 296 *key = s; |
| 296 } | 297 } |
| 297 | 298 |
| 298 void WebSocketHandshake::Parameter::GenerateKey3() { | 299 void WebSocketHandshake::Parameter::GenerateKey3() { |
| 299 key_3_.clear(); | 300 key_3_.clear(); |
| 300 for (int i = 0; i < 8; i++) { | 301 for (int i = 0; i < 8; i++) { |
| 301 key_3_.append(1, rand_(0, 255)); | 302 key_3_.append(1, rand_(0, 255)); |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 | 305 |
| 305 } // namespace net | 306 } // namespace net |
| OLD | NEW |