| 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 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 msg.SetType(STUN_BINDING_REQUEST); | 878 msg.SetType(STUN_BINDING_REQUEST); |
| 879 msg.SetTransactionID( | 879 msg.SetTransactionID( |
| 880 std::string(reinterpret_cast<const char*>(kTestTransactionId1), | 880 std::string(reinterpret_cast<const char*>(kTestTransactionId1), |
| 881 kStunTransactionIdLength)); | 881 kStunTransactionIdLength)); |
| 882 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); | 882 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); |
| 883 | 883 |
| 884 StunAddressAttribute* addr = | 884 StunAddressAttribute* addr = |
| 885 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); | 885 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); |
| 886 rtc::SocketAddress test_addr(test_ip, kTestMessagePort2); | 886 rtc::SocketAddress test_addr(test_ip, kTestMessagePort2); |
| 887 addr->SetAddress(test_addr); | 887 addr->SetAddress(test_addr); |
| 888 EXPECT_TRUE(msg.AddAttribute(addr)); | 888 msg.AddAttribute(addr); |
| 889 | 889 |
| 890 CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20)); | 890 CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20)); |
| 891 | 891 |
| 892 rtc::ByteBufferWriter out; | 892 rtc::ByteBufferWriter out; |
| 893 EXPECT_TRUE(msg.Write(&out)); | 893 EXPECT_TRUE(msg.Write(&out)); |
| 894 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv6MappedAddress)); | 894 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv6MappedAddress)); |
| 895 int len1 = static_cast<int>(out.Length()); | 895 int len1 = static_cast<int>(out.Length()); |
| 896 rtc::ByteBufferReader read_buf(out); | 896 rtc::ByteBufferReader read_buf(out); |
| 897 std::string bytes; | 897 std::string bytes; |
| 898 read_buf.ReadString(&bytes, len1); | 898 read_buf.ReadString(&bytes, len1); |
| 899 ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv6MappedAddress, len1)); | 899 ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv6MappedAddress, len1)); |
| 900 } | 900 } |
| 901 | 901 |
| 902 TEST_F(StunTest, WriteMessageWithIPv4AddressAttribute) { | 902 TEST_F(StunTest, WriteMessageWithIPv4AddressAttribute) { |
| 903 StunMessage msg; | 903 StunMessage msg; |
| 904 size_t size = sizeof(kStunMessageWithIPv4MappedAddress); | 904 size_t size = sizeof(kStunMessageWithIPv4MappedAddress); |
| 905 | 905 |
| 906 rtc::IPAddress test_ip(kIPv4TestAddress1); | 906 rtc::IPAddress test_ip(kIPv4TestAddress1); |
| 907 | 907 |
| 908 msg.SetType(STUN_BINDING_RESPONSE); | 908 msg.SetType(STUN_BINDING_RESPONSE); |
| 909 msg.SetTransactionID( | 909 msg.SetTransactionID( |
| 910 std::string(reinterpret_cast<const char*>(kTestTransactionId1), | 910 std::string(reinterpret_cast<const char*>(kTestTransactionId1), |
| 911 kStunTransactionIdLength)); | 911 kStunTransactionIdLength)); |
| 912 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); | 912 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); |
| 913 | 913 |
| 914 StunAddressAttribute* addr = | 914 StunAddressAttribute* addr = |
| 915 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); | 915 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); |
| 916 rtc::SocketAddress test_addr(test_ip, kTestMessagePort4); | 916 rtc::SocketAddress test_addr(test_ip, kTestMessagePort4); |
| 917 addr->SetAddress(test_addr); | 917 addr->SetAddress(test_addr); |
| 918 EXPECT_TRUE(msg.AddAttribute(addr)); | 918 msg.AddAttribute(addr); |
| 919 | 919 |
| 920 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); | 920 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); |
| 921 | 921 |
| 922 rtc::ByteBufferWriter out; | 922 rtc::ByteBufferWriter out; |
| 923 EXPECT_TRUE(msg.Write(&out)); | 923 EXPECT_TRUE(msg.Write(&out)); |
| 924 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv4MappedAddress)); | 924 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv4MappedAddress)); |
| 925 int len1 = static_cast<int>(out.Length()); | 925 int len1 = static_cast<int>(out.Length()); |
| 926 rtc::ByteBufferReader read_buf(out); | 926 rtc::ByteBufferReader read_buf(out); |
| 927 std::string bytes; | 927 std::string bytes; |
| 928 read_buf.ReadString(&bytes, len1); | 928 read_buf.ReadString(&bytes, len1); |
| 929 ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv4MappedAddress, len1)); | 929 ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv4MappedAddress, len1)); |
| 930 } | 930 } |
| 931 | 931 |
| 932 TEST_F(StunTest, WriteMessageWithIPv6XorAddressAttribute) { | 932 TEST_F(StunTest, WriteMessageWithIPv6XorAddressAttribute) { |
| 933 StunMessage msg; | 933 StunMessage msg; |
| 934 size_t size = sizeof(kStunMessageWithIPv6XorMappedAddress); | 934 size_t size = sizeof(kStunMessageWithIPv6XorMappedAddress); |
| 935 | 935 |
| 936 rtc::IPAddress test_ip(kIPv6TestAddress1); | 936 rtc::IPAddress test_ip(kIPv6TestAddress1); |
| 937 | 937 |
| 938 msg.SetType(STUN_BINDING_RESPONSE); | 938 msg.SetType(STUN_BINDING_RESPONSE); |
| 939 msg.SetTransactionID( | 939 msg.SetTransactionID( |
| 940 std::string(reinterpret_cast<const char*>(kTestTransactionId2), | 940 std::string(reinterpret_cast<const char*>(kTestTransactionId2), |
| 941 kStunTransactionIdLength)); | 941 kStunTransactionIdLength)); |
| 942 CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength); | 942 CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength); |
| 943 | 943 |
| 944 StunAddressAttribute* addr = | 944 StunAddressAttribute* addr = |
| 945 StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); | 945 StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); |
| 946 rtc::SocketAddress test_addr(test_ip, kTestMessagePort1); | 946 rtc::SocketAddress test_addr(test_ip, kTestMessagePort1); |
| 947 addr->SetAddress(test_addr); | 947 addr->SetAddress(test_addr); |
| 948 EXPECT_TRUE(msg.AddAttribute(addr)); | 948 msg.AddAttribute(addr); |
| 949 | 949 |
| 950 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); | 950 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); |
| 951 | 951 |
| 952 rtc::ByteBufferWriter out; | 952 rtc::ByteBufferWriter out; |
| 953 EXPECT_TRUE(msg.Write(&out)); | 953 EXPECT_TRUE(msg.Write(&out)); |
| 954 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv6XorMappedAddress)); | 954 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv6XorMappedAddress)); |
| 955 int len1 = static_cast<int>(out.Length()); | 955 int len1 = static_cast<int>(out.Length()); |
| 956 rtc::ByteBufferReader read_buf(out); | 956 rtc::ByteBufferReader read_buf(out); |
| 957 std::string bytes; | 957 std::string bytes; |
| 958 read_buf.ReadString(&bytes, len1); | 958 read_buf.ReadString(&bytes, len1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 969 msg.SetType(STUN_BINDING_RESPONSE); | 969 msg.SetType(STUN_BINDING_RESPONSE); |
| 970 msg.SetTransactionID( | 970 msg.SetTransactionID( |
| 971 std::string(reinterpret_cast<const char*>(kTestTransactionId1), | 971 std::string(reinterpret_cast<const char*>(kTestTransactionId1), |
| 972 kStunTransactionIdLength)); | 972 kStunTransactionIdLength)); |
| 973 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); | 973 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); |
| 974 | 974 |
| 975 StunAddressAttribute* addr = | 975 StunAddressAttribute* addr = |
| 976 StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); | 976 StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS); |
| 977 rtc::SocketAddress test_addr(test_ip, kTestMessagePort3); | 977 rtc::SocketAddress test_addr(test_ip, kTestMessagePort3); |
| 978 addr->SetAddress(test_addr); | 978 addr->SetAddress(test_addr); |
| 979 EXPECT_TRUE(msg.AddAttribute(addr)); | 979 msg.AddAttribute(addr); |
| 980 | 980 |
| 981 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); | 981 CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20)); |
| 982 | 982 |
| 983 rtc::ByteBufferWriter out; | 983 rtc::ByteBufferWriter out; |
| 984 EXPECT_TRUE(msg.Write(&out)); | 984 EXPECT_TRUE(msg.Write(&out)); |
| 985 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv4XorMappedAddress)); | 985 ASSERT_EQ(out.Length(), sizeof(kStunMessageWithIPv4XorMappedAddress)); |
| 986 int len1 = static_cast<int>(out.Length()); | 986 int len1 = static_cast<int>(out.Length()); |
| 987 rtc::ByteBufferReader read_buf(out); | 987 rtc::ByteBufferReader read_buf(out); |
| 988 std::string bytes; | 988 std::string bytes; |
| 989 read_buf.ReadString(&bytes, len1); | 989 read_buf.ReadString(&bytes, len1); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 size_t size = sizeof(kStunMessageWithErrorAttribute); | 1069 size_t size = sizeof(kStunMessageWithErrorAttribute); |
| 1070 | 1070 |
| 1071 msg.SetType(STUN_BINDING_ERROR_RESPONSE); | 1071 msg.SetType(STUN_BINDING_ERROR_RESPONSE); |
| 1072 msg.SetTransactionID( | 1072 msg.SetTransactionID( |
| 1073 std::string(reinterpret_cast<const char*>(kTestTransactionId1), | 1073 std::string(reinterpret_cast<const char*>(kTestTransactionId1), |
| 1074 kStunTransactionIdLength)); | 1074 kStunTransactionIdLength)); |
| 1075 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); | 1075 CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength); |
| 1076 StunErrorCodeAttribute* errorcode = StunAttribute::CreateErrorCode(); | 1076 StunErrorCodeAttribute* errorcode = StunAttribute::CreateErrorCode(); |
| 1077 errorcode->SetCode(kTestErrorCode); | 1077 errorcode->SetCode(kTestErrorCode); |
| 1078 errorcode->SetReason(kTestErrorReason); | 1078 errorcode->SetReason(kTestErrorReason); |
| 1079 EXPECT_TRUE(msg.AddAttribute(errorcode)); | 1079 msg.AddAttribute(errorcode); |
| 1080 CheckStunHeader(msg, STUN_BINDING_ERROR_RESPONSE, (size - 20)); | 1080 CheckStunHeader(msg, STUN_BINDING_ERROR_RESPONSE, (size - 20)); |
| 1081 | 1081 |
| 1082 rtc::ByteBufferWriter out; | 1082 rtc::ByteBufferWriter out; |
| 1083 EXPECT_TRUE(msg.Write(&out)); | 1083 EXPECT_TRUE(msg.Write(&out)); |
| 1084 ASSERT_EQ(size, out.Length()); | 1084 ASSERT_EQ(size, out.Length()); |
| 1085 // No padding. | 1085 // No padding. |
| 1086 ASSERT_EQ(0, memcmp(out.Data(), kStunMessageWithErrorAttribute, size)); | 1086 ASSERT_EQ(0, memcmp(out.Data(), kStunMessageWithErrorAttribute, size)); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 TEST_F(StunTest, WriteMessageWithAUInt16ListAttribute) { | 1089 TEST_F(StunTest, WriteMessageWithAUInt16ListAttribute) { |
| 1090 StunMessage msg; | 1090 StunMessage msg; |
| 1091 size_t size = sizeof(kStunMessageWithUInt16ListAttribute); | 1091 size_t size = sizeof(kStunMessageWithUInt16ListAttribute); |
| 1092 | 1092 |
| 1093 msg.SetType(STUN_BINDING_REQUEST); | 1093 msg.SetType(STUN_BINDING_REQUEST); |
| 1094 msg.SetTransactionID( | 1094 msg.SetTransactionID( |
| 1095 std::string(reinterpret_cast<const char*>(kTestTransactionId2), | 1095 std::string(reinterpret_cast<const char*>(kTestTransactionId2), |
| 1096 kStunTransactionIdLength)); | 1096 kStunTransactionIdLength)); |
| 1097 CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength); | 1097 CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength); |
| 1098 StunUInt16ListAttribute* list = StunAttribute::CreateUnknownAttributes(); | 1098 StunUInt16ListAttribute* list = StunAttribute::CreateUnknownAttributes(); |
| 1099 list->AddType(0x1U); | 1099 list->AddType(0x1U); |
| 1100 list->AddType(0x1000U); | 1100 list->AddType(0x1000U); |
| 1101 list->AddType(0xAB0CU); | 1101 list->AddType(0xAB0CU); |
| 1102 EXPECT_TRUE(msg.AddAttribute(list)); | 1102 msg.AddAttribute(list); |
| 1103 CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20)); | 1103 CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20)); |
| 1104 | 1104 |
| 1105 rtc::ByteBufferWriter out; | 1105 rtc::ByteBufferWriter out; |
| 1106 EXPECT_TRUE(msg.Write(&out)); | 1106 EXPECT_TRUE(msg.Write(&out)); |
| 1107 ASSERT_EQ(size, out.Length()); | 1107 ASSERT_EQ(size, out.Length()); |
| 1108 // Check everything up to the padding. | 1108 // Check everything up to the padding. |
| 1109 ASSERT_EQ(0, | 1109 ASSERT_EQ(0, |
| 1110 memcmp(out.Data(), kStunMessageWithUInt16ListAttribute, size - 2)); | 1110 memcmp(out.Data(), kStunMessageWithUInt16ListAttribute, size - 2)); |
| 1111 } | 1111 } |
| 1112 | 1112 |
| 1113 TEST_F(StunTest, WriteMessageWithOriginAttribute) { | 1113 TEST_F(StunTest, WriteMessageWithOriginAttribute) { |
| 1114 StunMessage msg; | 1114 StunMessage msg; |
| 1115 size_t size = sizeof(kStunMessageWithOriginAttribute); | 1115 size_t size = sizeof(kStunMessageWithOriginAttribute); |
| 1116 | 1116 |
| 1117 msg.SetType(STUN_BINDING_REQUEST); | 1117 msg.SetType(STUN_BINDING_REQUEST); |
| 1118 msg.SetTransactionID( | 1118 msg.SetTransactionID( |
| 1119 std::string(reinterpret_cast<const char*>(kTestTransactionId1), | 1119 std::string(reinterpret_cast<const char*>(kTestTransactionId1), |
| 1120 kStunTransactionIdLength)); | 1120 kStunTransactionIdLength)); |
| 1121 StunByteStringAttribute* origin = | 1121 StunByteStringAttribute* origin = |
| 1122 new StunByteStringAttribute(STUN_ATTR_ORIGIN, kTestOrigin); | 1122 new StunByteStringAttribute(STUN_ATTR_ORIGIN, kTestOrigin); |
| 1123 EXPECT_TRUE(msg.AddAttribute(origin)); | 1123 msg.AddAttribute(origin); |
| 1124 | 1124 |
| 1125 rtc::ByteBufferWriter out; | 1125 rtc::ByteBufferWriter out; |
| 1126 EXPECT_TRUE(msg.Write(&out)); | 1126 EXPECT_TRUE(msg.Write(&out)); |
| 1127 ASSERT_EQ(size, out.Length()); | 1127 ASSERT_EQ(size, out.Length()); |
| 1128 // Check everything up to the padding | 1128 // Check everything up to the padding |
| 1129 ASSERT_EQ(0, memcmp(out.Data(), kStunMessageWithOriginAttribute, size - 2)); | 1129 ASSERT_EQ(0, memcmp(out.Data(), kStunMessageWithOriginAttribute, size - 2)); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 // Test that we fail to read messages with invalid lengths. | 1132 // Test that we fail to read messages with invalid lengths. |
| 1133 void CheckFailureToRead(const unsigned char* testcase, size_t length) { | 1133 void CheckFailureToRead(const unsigned char* testcase, size_t length) { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 const StunAddressAttribute* addr = msg.GetAddress(STUN_ATTR_MAPPED_ADDRESS); | 1386 const StunAddressAttribute* addr = msg.GetAddress(STUN_ATTR_MAPPED_ADDRESS); |
| 1387 ASSERT_TRUE(addr != NULL); | 1387 ASSERT_TRUE(addr != NULL); |
| 1388 EXPECT_EQ(1, addr->family()); | 1388 EXPECT_EQ(1, addr->family()); |
| 1389 EXPECT_EQ(13, addr->port()); | 1389 EXPECT_EQ(13, addr->port()); |
| 1390 EXPECT_EQ(legacy_ip, addr->ipaddr()); | 1390 EXPECT_EQ(legacy_ip, addr->ipaddr()); |
| 1391 | 1391 |
| 1392 StunAddressAttribute* addr2 = | 1392 StunAddressAttribute* addr2 = |
| 1393 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); | 1393 StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS); |
| 1394 addr2->SetPort(13); | 1394 addr2->SetPort(13); |
| 1395 addr2->SetIP(legacy_ip); | 1395 addr2->SetIP(legacy_ip); |
| 1396 EXPECT_TRUE(msg2.AddAttribute(addr2)); | 1396 msg2.AddAttribute(addr2); |
| 1397 | 1397 |
| 1398 const StunByteStringAttribute* bytes = msg.GetByteString(STUN_ATTR_USERNAME); | 1398 const StunByteStringAttribute* bytes = msg.GetByteString(STUN_ATTR_USERNAME); |
| 1399 ASSERT_TRUE(bytes != NULL); | 1399 ASSERT_TRUE(bytes != NULL); |
| 1400 EXPECT_EQ(12U, bytes->length()); | 1400 EXPECT_EQ(12U, bytes->length()); |
| 1401 EXPECT_EQ("abcdefghijkl", bytes->GetString()); | 1401 EXPECT_EQ("abcdefghijkl", bytes->GetString()); |
| 1402 | 1402 |
| 1403 StunByteStringAttribute* bytes2 = | 1403 StunByteStringAttribute* bytes2 = |
| 1404 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); | 1404 StunAttribute::CreateByteString(STUN_ATTR_USERNAME); |
| 1405 bytes2->CopyBytes("abcdefghijkl"); | 1405 bytes2->CopyBytes("abcdefghijkl"); |
| 1406 EXPECT_TRUE(msg2.AddAttribute(bytes2)); | 1406 msg2.AddAttribute(bytes2); |
| 1407 | 1407 |
| 1408 const StunUInt32Attribute* uval = msg.GetUInt32(STUN_ATTR_LIFETIME); | 1408 const StunUInt32Attribute* uval = msg.GetUInt32(STUN_ATTR_LIFETIME); |
| 1409 ASSERT_TRUE(uval != NULL); | 1409 ASSERT_TRUE(uval != NULL); |
| 1410 EXPECT_EQ(11U, uval->value()); | 1410 EXPECT_EQ(11U, uval->value()); |
| 1411 | 1411 |
| 1412 StunUInt32Attribute* uval2 = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME); | 1412 StunUInt32Attribute* uval2 = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME); |
| 1413 uval2->SetValue(11); | 1413 uval2->SetValue(11); |
| 1414 EXPECT_TRUE(msg2.AddAttribute(uval2)); | 1414 msg2.AddAttribute(uval2); |
| 1415 | 1415 |
| 1416 bytes = msg.GetByteString(STUN_ATTR_MAGIC_COOKIE); | 1416 bytes = msg.GetByteString(STUN_ATTR_MAGIC_COOKIE); |
| 1417 ASSERT_TRUE(bytes != NULL); | 1417 ASSERT_TRUE(bytes != NULL); |
| 1418 EXPECT_EQ(4U, bytes->length()); | 1418 EXPECT_EQ(4U, bytes->length()); |
| 1419 EXPECT_EQ(0, | 1419 EXPECT_EQ(0, |
| 1420 memcmp(bytes->bytes(), | 1420 memcmp(bytes->bytes(), |
| 1421 TURN_MAGIC_COOKIE_VALUE, | 1421 TURN_MAGIC_COOKIE_VALUE, |
| 1422 sizeof(TURN_MAGIC_COOKIE_VALUE))); | 1422 sizeof(TURN_MAGIC_COOKIE_VALUE))); |
| 1423 | 1423 |
| 1424 bytes2 = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); | 1424 bytes2 = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE); |
| 1425 bytes2->CopyBytes(reinterpret_cast<const char*>(TURN_MAGIC_COOKIE_VALUE), | 1425 bytes2->CopyBytes(reinterpret_cast<const char*>(TURN_MAGIC_COOKIE_VALUE), |
| 1426 sizeof(TURN_MAGIC_COOKIE_VALUE)); | 1426 sizeof(TURN_MAGIC_COOKIE_VALUE)); |
| 1427 EXPECT_TRUE(msg2.AddAttribute(bytes2)); | 1427 msg2.AddAttribute(bytes2); |
| 1428 | 1428 |
| 1429 uval = msg.GetUInt32(STUN_ATTR_BANDWIDTH); | 1429 uval = msg.GetUInt32(STUN_ATTR_BANDWIDTH); |
| 1430 ASSERT_TRUE(uval != NULL); | 1430 ASSERT_TRUE(uval != NULL); |
| 1431 EXPECT_EQ(6U, uval->value()); | 1431 EXPECT_EQ(6U, uval->value()); |
| 1432 | 1432 |
| 1433 uval2 = StunAttribute::CreateUInt32(STUN_ATTR_BANDWIDTH); | 1433 uval2 = StunAttribute::CreateUInt32(STUN_ATTR_BANDWIDTH); |
| 1434 uval2->SetValue(6); | 1434 uval2->SetValue(6); |
| 1435 EXPECT_TRUE(msg2.AddAttribute(uval2)); | 1435 msg2.AddAttribute(uval2); |
| 1436 | 1436 |
| 1437 addr = msg.GetAddress(STUN_ATTR_DESTINATION_ADDRESS); | 1437 addr = msg.GetAddress(STUN_ATTR_DESTINATION_ADDRESS); |
| 1438 ASSERT_TRUE(addr != NULL); | 1438 ASSERT_TRUE(addr != NULL); |
| 1439 EXPECT_EQ(1, addr->family()); | 1439 EXPECT_EQ(1, addr->family()); |
| 1440 EXPECT_EQ(13, addr->port()); | 1440 EXPECT_EQ(13, addr->port()); |
| 1441 EXPECT_EQ(legacy_ip, addr->ipaddr()); | 1441 EXPECT_EQ(legacy_ip, addr->ipaddr()); |
| 1442 | 1442 |
| 1443 addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); | 1443 addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS); |
| 1444 addr2->SetPort(13); | 1444 addr2->SetPort(13); |
| 1445 addr2->SetIP(legacy_ip); | 1445 addr2->SetIP(legacy_ip); |
| 1446 EXPECT_TRUE(msg2.AddAttribute(addr2)); | 1446 msg2.AddAttribute(addr2); |
| 1447 | 1447 |
| 1448 addr = msg.GetAddress(STUN_ATTR_SOURCE_ADDRESS2); | 1448 addr = msg.GetAddress(STUN_ATTR_SOURCE_ADDRESS2); |
| 1449 ASSERT_TRUE(addr != NULL); | 1449 ASSERT_TRUE(addr != NULL); |
| 1450 EXPECT_EQ(1, addr->family()); | 1450 EXPECT_EQ(1, addr->family()); |
| 1451 EXPECT_EQ(13, addr->port()); | 1451 EXPECT_EQ(13, addr->port()); |
| 1452 EXPECT_EQ(legacy_ip, addr->ipaddr()); | 1452 EXPECT_EQ(legacy_ip, addr->ipaddr()); |
| 1453 | 1453 |
| 1454 addr2 = StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2); | 1454 addr2 = StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2); |
| 1455 addr2->SetPort(13); | 1455 addr2->SetPort(13); |
| 1456 addr2->SetIP(legacy_ip); | 1456 addr2->SetIP(legacy_ip); |
| 1457 EXPECT_TRUE(msg2.AddAttribute(addr2)); | 1457 msg2.AddAttribute(addr2); |
| 1458 | 1458 |
| 1459 bytes = msg.GetByteString(STUN_ATTR_DATA); | 1459 bytes = msg.GetByteString(STUN_ATTR_DATA); |
| 1460 ASSERT_TRUE(bytes != NULL); | 1460 ASSERT_TRUE(bytes != NULL); |
| 1461 EXPECT_EQ(7U, bytes->length()); | 1461 EXPECT_EQ(7U, bytes->length()); |
| 1462 EXPECT_EQ("abcdefg", bytes->GetString()); | 1462 EXPECT_EQ("abcdefg", bytes->GetString()); |
| 1463 | 1463 |
| 1464 bytes2 = StunAttribute::CreateByteString(STUN_ATTR_DATA); | 1464 bytes2 = StunAttribute::CreateByteString(STUN_ATTR_DATA); |
| 1465 bytes2->CopyBytes("abcdefg"); | 1465 bytes2->CopyBytes("abcdefg"); |
| 1466 EXPECT_TRUE(msg2.AddAttribute(bytes2)); | 1466 msg2.AddAttribute(bytes2); |
| 1467 | 1467 |
| 1468 rtc::ByteBufferWriter out; | 1468 rtc::ByteBufferWriter out; |
| 1469 EXPECT_TRUE(msg.Write(&out)); | 1469 EXPECT_TRUE(msg.Write(&out)); |
| 1470 EXPECT_EQ(size, out.Length()); | 1470 EXPECT_EQ(size, out.Length()); |
| 1471 size_t len1 = out.Length(); | 1471 size_t len1 = out.Length(); |
| 1472 rtc::ByteBufferReader read_buf(out); | 1472 rtc::ByteBufferReader read_buf(out); |
| 1473 std::string outstring; | 1473 std::string outstring; |
| 1474 read_buf.ReadString(&outstring, len1); | 1474 read_buf.ReadString(&outstring, len1); |
| 1475 EXPECT_EQ(0, memcmp(outstring.c_str(), input, len1)); | 1475 EXPECT_EQ(0, memcmp(outstring.c_str(), input, len1)); |
| 1476 | 1476 |
| 1477 rtc::ByteBufferWriter out2; | 1477 rtc::ByteBufferWriter out2; |
| 1478 EXPECT_TRUE(msg2.Write(&out2)); | 1478 EXPECT_TRUE(msg2.Write(&out2)); |
| 1479 EXPECT_EQ(size, out2.Length()); | 1479 EXPECT_EQ(size, out2.Length()); |
| 1480 size_t len2 = out2.Length(); | 1480 size_t len2 = out2.Length(); |
| 1481 rtc::ByteBufferReader read_buf2(out2); | 1481 rtc::ByteBufferReader read_buf2(out2); |
| 1482 std::string outstring2; | 1482 std::string outstring2; |
| 1483 read_buf2.ReadString(&outstring2, len2); | 1483 read_buf2.ReadString(&outstring2, len2); |
| 1484 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2)); | 1484 EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2)); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 } // namespace cricket | 1487 } // namespace cricket |
| OLD | NEW |