OLD | NEW |
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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 StunAttributeValueType value_type = GetAttributeValueType(type); | 399 StunAttributeValueType value_type = GetAttributeValueType(type); |
400 return StunAttribute::Create(value_type, type, static_cast<uint16_t>(length), | 400 return StunAttribute::Create(value_type, type, static_cast<uint16_t>(length), |
401 this); | 401 this); |
402 } | 402 } |
403 | 403 |
404 const StunAttribute* StunMessage::GetAttribute(int type) const { | 404 const StunAttribute* StunMessage::GetAttribute(int type) const { |
405 for (size_t i = 0; i < attrs_->size(); ++i) { | 405 for (size_t i = 0; i < attrs_->size(); ++i) { |
406 if ((*attrs_)[i]->type() == type) | 406 if ((*attrs_)[i]->type() == type) |
407 return (*attrs_)[i]; | 407 return (*attrs_)[i]; |
408 } | 408 } |
409 return NULL; | 409 return nullptr; |
410 } | 410 } |
411 | 411 |
412 bool StunMessage::IsValidTransactionId(const std::string& transaction_id) { | 412 bool StunMessage::IsValidTransactionId(const std::string& transaction_id) { |
413 return transaction_id.size() == kStunTransactionIdLength || | 413 return transaction_id.size() == kStunTransactionIdLength || |
414 transaction_id.size() == kStunLegacyTransactionIdLength; | 414 transaction_id.size() == kStunLegacyTransactionIdLength; |
415 } | 415 } |
416 | 416 |
417 // StunAttribute | 417 // StunAttribute |
418 | 418 |
419 StunAttribute::StunAttribute(uint16_t type, uint16_t length) | 419 StunAttribute::StunAttribute(uint16_t type, uint16_t length) |
(...skipping 28 matching lines...) Expand all Loading... |
448 return new StunUInt32Attribute(type); | 448 return new StunUInt32Attribute(type); |
449 case STUN_VALUE_UINT64: | 449 case STUN_VALUE_UINT64: |
450 return new StunUInt64Attribute(type); | 450 return new StunUInt64Attribute(type); |
451 case STUN_VALUE_BYTE_STRING: | 451 case STUN_VALUE_BYTE_STRING: |
452 return new StunByteStringAttribute(type, length); | 452 return new StunByteStringAttribute(type, length); |
453 case STUN_VALUE_ERROR_CODE: | 453 case STUN_VALUE_ERROR_CODE: |
454 return new StunErrorCodeAttribute(type, length); | 454 return new StunErrorCodeAttribute(type, length); |
455 case STUN_VALUE_UINT16_LIST: | 455 case STUN_VALUE_UINT16_LIST: |
456 return new StunUInt16ListAttribute(type, length); | 456 return new StunUInt16ListAttribute(type, length); |
457 default: | 457 default: |
458 return NULL; | 458 return nullptr; |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 StunAddressAttribute* StunAttribute::CreateAddress(uint16_t type) { | 462 StunAddressAttribute* StunAttribute::CreateAddress(uint16_t type) { |
463 return new StunAddressAttribute(type, 0); | 463 return new StunAddressAttribute(type, 0); |
464 } | 464 } |
465 | 465 |
466 StunXorAddressAttribute* StunAttribute::CreateXorAddress(uint16_t type) { | 466 StunXorAddressAttribute* StunAttribute::CreateXorAddress(uint16_t type) { |
467 return new StunXorAddressAttribute(type, 0, NULL); | 467 return new StunXorAddressAttribute(type, 0, nullptr); |
468 } | 468 } |
469 | 469 |
470 StunUInt64Attribute* StunAttribute::CreateUInt64(uint16_t type) { | 470 StunUInt64Attribute* StunAttribute::CreateUInt64(uint16_t type) { |
471 return new StunUInt64Attribute(type); | 471 return new StunUInt64Attribute(type); |
472 } | 472 } |
473 | 473 |
474 StunUInt32Attribute* StunAttribute::CreateUInt32(uint16_t type) { | 474 StunUInt32Attribute* StunAttribute::CreateUInt32(uint16_t type) { |
475 return new StunUInt32Attribute(type); | 475 return new StunUInt32Attribute(type); |
476 } | 476 } |
477 | 477 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 in6_addr v6addr = address_.ipaddr().ipv6_address(); | 555 in6_addr v6addr = address_.ipaddr().ipv6_address(); |
556 buf->WriteBytes(reinterpret_cast<char*>(&v6addr), sizeof(v6addr)); | 556 buf->WriteBytes(reinterpret_cast<char*>(&v6addr), sizeof(v6addr)); |
557 break; | 557 break; |
558 } | 558 } |
559 } | 559 } |
560 return true; | 560 return true; |
561 } | 561 } |
562 | 562 |
563 StunXorAddressAttribute::StunXorAddressAttribute(uint16_t type, | 563 StunXorAddressAttribute::StunXorAddressAttribute(uint16_t type, |
564 const rtc::SocketAddress& addr) | 564 const rtc::SocketAddress& addr) |
565 : StunAddressAttribute(type, addr), owner_(NULL) { | 565 : StunAddressAttribute(type, addr), owner_(nullptr) {} |
566 } | |
567 | 566 |
568 StunXorAddressAttribute::StunXorAddressAttribute(uint16_t type, | 567 StunXorAddressAttribute::StunXorAddressAttribute(uint16_t type, |
569 uint16_t length, | 568 uint16_t length, |
570 StunMessage* owner) | 569 StunMessage* owner) |
571 : StunAddressAttribute(type, length), owner_(owner) { | 570 : StunAddressAttribute(type, length), owner_(owner) { |
572 } | 571 } |
573 | 572 |
574 rtc::IPAddress StunXorAddressAttribute::GetXoredIP() const { | 573 rtc::IPAddress StunXorAddressAttribute::GetXoredIP() const { |
575 if (owner_) { | 574 if (owner_) { |
576 rtc::IPAddress ip = ipaddr(); | 575 rtc::IPAddress ip = ipaddr(); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 return false; | 686 return false; |
688 return true; | 687 return true; |
689 } | 688 } |
690 | 689 |
691 bool StunUInt64Attribute::Write(ByteBufferWriter* buf) const { | 690 bool StunUInt64Attribute::Write(ByteBufferWriter* buf) const { |
692 buf->WriteUInt64(bits_); | 691 buf->WriteUInt64(bits_); |
693 return true; | 692 return true; |
694 } | 693 } |
695 | 694 |
696 StunByteStringAttribute::StunByteStringAttribute(uint16_t type) | 695 StunByteStringAttribute::StunByteStringAttribute(uint16_t type) |
697 : StunAttribute(type, 0), bytes_(NULL) { | 696 : StunAttribute(type, 0), bytes_(nullptr) {} |
698 } | |
699 | 697 |
700 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, | 698 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, |
701 const std::string& str) | 699 const std::string& str) |
702 : StunAttribute(type, 0), bytes_(NULL) { | 700 : StunAttribute(type, 0), bytes_(nullptr) { |
703 CopyBytes(str.c_str(), str.size()); | 701 CopyBytes(str.c_str(), str.size()); |
704 } | 702 } |
705 | 703 |
706 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, | 704 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, |
707 const void* bytes, | 705 const void* bytes, |
708 size_t length) | 706 size_t length) |
709 : StunAttribute(type, 0), bytes_(NULL) { | 707 : StunAttribute(type, 0), bytes_(nullptr) { |
710 CopyBytes(bytes, length); | 708 CopyBytes(bytes, length); |
711 } | 709 } |
712 | 710 |
713 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, uint16_t length) | 711 StunByteStringAttribute::StunByteStringAttribute(uint16_t type, uint16_t length) |
714 : StunAttribute(type, length), bytes_(NULL) { | 712 : StunAttribute(type, length), bytes_(nullptr) {} |
715 } | |
716 | 713 |
717 StunByteStringAttribute::~StunByteStringAttribute() { | 714 StunByteStringAttribute::~StunByteStringAttribute() { |
718 delete [] bytes_; | 715 delete [] bytes_; |
719 } | 716 } |
720 | 717 |
721 void StunByteStringAttribute::CopyBytes(const char* bytes) { | 718 void StunByteStringAttribute::CopyBytes(const char* bytes) { |
722 CopyBytes(bytes, strlen(bytes)); | 719 CopyBytes(bytes, strlen(bytes)); |
723 } | 720 } |
724 | 721 |
725 void StunByteStringAttribute::CopyBytes(const void* bytes, size_t length) { | 722 void StunByteStringAttribute::CopyBytes(const void* bytes, size_t length) { |
726 char* new_bytes = new char[length]; | 723 char* new_bytes = new char[length]; |
727 memcpy(new_bytes, bytes, length); | 724 memcpy(new_bytes, bytes, length); |
728 SetBytes(new_bytes, length); | 725 SetBytes(new_bytes, length); |
729 } | 726 } |
730 | 727 |
731 uint8_t StunByteStringAttribute::GetByte(size_t index) const { | 728 uint8_t StunByteStringAttribute::GetByte(size_t index) const { |
732 RTC_DCHECK(bytes_ != NULL); | 729 RTC_DCHECK(bytes_ != nullptr); |
733 RTC_DCHECK(index < length()); | 730 RTC_DCHECK(index < length()); |
734 return static_cast<uint8_t>(bytes_[index]); | 731 return static_cast<uint8_t>(bytes_[index]); |
735 } | 732 } |
736 | 733 |
737 void StunByteStringAttribute::SetByte(size_t index, uint8_t value) { | 734 void StunByteStringAttribute::SetByte(size_t index, uint8_t value) { |
738 RTC_DCHECK(bytes_ != NULL); | 735 RTC_DCHECK(bytes_ != nullptr); |
739 RTC_DCHECK(index < length()); | 736 RTC_DCHECK(index < length()); |
740 bytes_[index] = value; | 737 bytes_[index] = value; |
741 } | 738 } |
742 | 739 |
743 bool StunByteStringAttribute::Read(ByteBufferReader* buf) { | 740 bool StunByteStringAttribute::Read(ByteBufferReader* buf) { |
744 bytes_ = new char[length()]; | 741 bytes_ = new char[length()]; |
745 if (!buf->ReadBytes(bytes_, length())) { | 742 if (!buf->ReadBytes(bytes_, length())) { |
746 return false; | 743 return false; |
747 } | 744 } |
748 | 745 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 digest, sizeof(digest)); | 909 digest, sizeof(digest)); |
913 if (size == 0) { | 910 if (size == 0) { |
914 return false; | 911 return false; |
915 } | 912 } |
916 | 913 |
917 *hash = std::string(digest, size); | 914 *hash = std::string(digest, size); |
918 return true; | 915 return true; |
919 } | 916 } |
920 | 917 |
921 } // namespace cricket | 918 } // namespace cricket |
OLD | NEW |