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

Side by Side Diff: webrtc/p2p/base/port.cc

Issue 2685783014: Replace NULL with nullptr in all C++ files. (Closed)
Patch Set: Fixing android. Created 3 years, 10 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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 max_port_(max_port), 178 max_port_(max_port),
179 component_(ICE_CANDIDATE_COMPONENT_DEFAULT), 179 component_(ICE_CANDIDATE_COMPONENT_DEFAULT),
180 generation_(0), 180 generation_(0),
181 ice_username_fragment_(username_fragment), 181 ice_username_fragment_(username_fragment),
182 password_(password), 182 password_(password),
183 timeout_delay_(kPortTimeoutDelay), 183 timeout_delay_(kPortTimeoutDelay),
184 enable_port_packets_(false), 184 enable_port_packets_(false),
185 ice_role_(ICEROLE_UNKNOWN), 185 ice_role_(ICEROLE_UNKNOWN),
186 tiebreaker_(0), 186 tiebreaker_(0),
187 shared_socket_(false) { 187 shared_socket_(false) {
188 RTC_DCHECK(factory_ != NULL); 188 RTC_DCHECK(factory_ != nullptr);
189 Construct(); 189 Construct();
190 } 190 }
191 191
192 void Port::Construct() { 192 void Port::Construct() {
193 // TODO(pthatcher): Remove this old behavior once we're sure no one 193 // TODO(pthatcher): Remove this old behavior once we're sure no one
194 // relies on it. If the username_fragment and password are empty, 194 // relies on it. If the username_fragment and password are empty,
195 // we should just create one. 195 // we should just create one.
196 if (ice_username_fragment_.empty()) { 196 if (ice_username_fragment_.empty()) {
197 RTC_DCHECK(password_.empty()); 197 RTC_DCHECK(password_.empty());
198 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH); 198 ice_username_fragment_ = rtc::CreateRandomString(ICE_UFRAG_LENGTH);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 c.set_username(username_fragment); 233 c.set_username(username_fragment);
234 c.set_password(password); 234 c.set_password(password);
235 } 235 }
236 } 236 }
237 237
238 Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) { 238 Connection* Port::GetConnection(const rtc::SocketAddress& remote_addr) {
239 AddressMap::const_iterator iter = connections_.find(remote_addr); 239 AddressMap::const_iterator iter = connections_.find(remote_addr);
240 if (iter != connections_.end()) 240 if (iter != connections_.end())
241 return iter->second; 241 return iter->second;
242 else 242 else
243 return NULL; 243 return nullptr;
244 } 244 }
245 245
246 void Port::AddAddress(const rtc::SocketAddress& address, 246 void Port::AddAddress(const rtc::SocketAddress& address,
247 const rtc::SocketAddress& base_address, 247 const rtc::SocketAddress& base_address,
248 const rtc::SocketAddress& related_address, 248 const rtc::SocketAddress& related_address,
249 const std::string& protocol, 249 const std::string& protocol,
250 const std::string& relay_protocol, 250 const std::string& relay_protocol,
251 const std::string& tcptype, 251 const std::string& tcptype,
252 const std::string& type, 252 const std::string& type,
253 uint32_t type_preference, 253 uint32_t type_preference,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 349 }
350 350
351 bool Port::GetStunMessage(const char* data, 351 bool Port::GetStunMessage(const char* data,
352 size_t size, 352 size_t size,
353 const rtc::SocketAddress& addr, 353 const rtc::SocketAddress& addr,
354 std::unique_ptr<IceMessage>* out_msg, 354 std::unique_ptr<IceMessage>* out_msg,
355 std::string* out_username) { 355 std::string* out_username) {
356 // NOTE: This could clearly be optimized to avoid allocating any memory. 356 // NOTE: This could clearly be optimized to avoid allocating any memory.
357 // However, at the data rates we'll be looking at on the client side, 357 // However, at the data rates we'll be looking at on the client side,
358 // this probably isn't worth worrying about. 358 // this probably isn't worth worrying about.
359 RTC_DCHECK(out_msg != NULL); 359 RTC_DCHECK(out_msg != nullptr);
360 RTC_DCHECK(out_username != NULL); 360 RTC_DCHECK(out_username != nullptr);
361 out_username->clear(); 361 out_username->clear();
362 362
363 // Don't bother parsing the packet if we can tell it's not STUN. 363 // Don't bother parsing the packet if we can tell it's not STUN.
364 // In ICE mode, all STUN packets will have a valid fingerprint. 364 // In ICE mode, all STUN packets will have a valid fingerprint.
365 if (!StunMessage::ValidateFingerprint(data, size)) { 365 if (!StunMessage::ValidateFingerprint(data, size)) {
366 return false; 366 return false;
367 } 367 }
368 368
369 // Parse the request message. If the packet is not a complete and correct 369 // Parse the request message. If the packet is not a complete and correct
370 // STUN message, then ignore it. 370 // STUN message, then ignore it.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 bool Port::ParseStunUsername(const StunMessage* stun_msg, 462 bool Port::ParseStunUsername(const StunMessage* stun_msg,
463 std::string* local_ufrag, 463 std::string* local_ufrag,
464 std::string* remote_ufrag) const { 464 std::string* remote_ufrag) const {
465 // The packet must include a username that either begins or ends with our 465 // The packet must include a username that either begins or ends with our
466 // fragment. It should begin with our fragment if it is a request and it 466 // fragment. It should begin with our fragment if it is a request and it
467 // should end with our fragment if it is a response. 467 // should end with our fragment if it is a response.
468 local_ufrag->clear(); 468 local_ufrag->clear();
469 remote_ufrag->clear(); 469 remote_ufrag->clear();
470 const StunByteStringAttribute* username_attr = 470 const StunByteStringAttribute* username_attr =
471 stun_msg->GetByteString(STUN_ATTR_USERNAME); 471 stun_msg->GetByteString(STUN_ATTR_USERNAME);
472 if (username_attr == NULL) 472 if (username_attr == nullptr)
473 return false; 473 return false;
474 474
475 // RFRAG:LFRAG 475 // RFRAG:LFRAG
476 const std::string username = username_attr->GetString(); 476 const std::string username = username_attr->GetString();
477 size_t colon_pos = username.find(":"); 477 size_t colon_pos = username.find(":");
478 if (colon_pos == std::string::npos) { 478 if (colon_pos == std::string::npos) {
479 return false; 479 return false;
480 } 480 }
481 481
482 *local_ufrag = username.substr(0, colon_pos); 482 *local_ufrag = username.substr(0, colon_pos);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 stun_username_attr_str->append(username_fragment()); 553 stun_username_attr_str->append(username_fragment());
554 } 554 }
555 555
556 void Port::SendBindingResponse(StunMessage* request, 556 void Port::SendBindingResponse(StunMessage* request,
557 const rtc::SocketAddress& addr) { 557 const rtc::SocketAddress& addr) {
558 RTC_DCHECK(request->type() == STUN_BINDING_REQUEST); 558 RTC_DCHECK(request->type() == STUN_BINDING_REQUEST);
559 559
560 // Retrieve the username from the request. 560 // Retrieve the username from the request.
561 const StunByteStringAttribute* username_attr = 561 const StunByteStringAttribute* username_attr =
562 request->GetByteString(STUN_ATTR_USERNAME); 562 request->GetByteString(STUN_ATTR_USERNAME);
563 RTC_DCHECK(username_attr != NULL); 563 RTC_DCHECK(username_attr != nullptr);
564 if (username_attr == NULL) { 564 if (username_attr == nullptr) {
565 // No valid username, skip the response. 565 // No valid username, skip the response.
566 return; 566 return;
567 } 567 }
568 568
569 // Fill in the response message. 569 // Fill in the response message.
570 StunMessage response; 570 StunMessage response;
571 response.SetType(STUN_BINDING_RESPONSE); 571 response.SetType(STUN_BINDING_RESPONSE);
572 response.SetTransactionID(request->transaction_id()); 572 response.SetTransactionID(request->transaction_id());
573 const StunUInt32Attribute* retransmit_attr = 573 const StunUInt32Attribute* retransmit_attr =
574 request->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); 574 request->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT);
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 RTC_DCHECK(sent < 0); 1588 RTC_DCHECK(sent < 0);
1589 error_ = port_->GetError(); 1589 error_ = port_->GetError();
1590 stats_.sent_discarded_packets++; 1590 stats_.sent_discarded_packets++;
1591 } else { 1591 } else {
1592 send_rate_tracker_.AddSamples(sent); 1592 send_rate_tracker_.AddSamples(sent);
1593 } 1593 }
1594 return sent; 1594 return sent;
1595 } 1595 }
1596 1596
1597 } // namespace cricket 1597 } // namespace cricket
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698