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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 attrs_->resize(0); | 333 attrs_->resize(0); |
334 | 334 |
335 size_t rest = buf->Length() - length_; | 335 size_t rest = buf->Length() - length_; |
336 while (buf->Length() > rest) { | 336 while (buf->Length() > rest) { |
337 uint16_t attr_type, attr_length; | 337 uint16_t attr_type, attr_length; |
338 if (!buf->ReadUInt16(&attr_type)) | 338 if (!buf->ReadUInt16(&attr_type)) |
339 return false; | 339 return false; |
340 if (!buf->ReadUInt16(&attr_length)) | 340 if (!buf->ReadUInt16(&attr_length)) |
341 return false; | 341 return false; |
342 | 342 |
343 StunAttribute* attr = CreateAttribute(attr_type, attr_length); | 343 std::unique_ptr<StunAttribute> attr( |
| 344 CreateAttribute(attr_type, attr_length)); |
344 if (!attr) { | 345 if (!attr) { |
345 // Skip any unknown or malformed attributes. | 346 // Skip any unknown or malformed attributes. |
346 if ((attr_length % 4) != 0) { | 347 if ((attr_length % 4) != 0) { |
347 attr_length += (4 - (attr_length % 4)); | 348 attr_length += (4 - (attr_length % 4)); |
348 } | 349 } |
349 if (!buf->Consume(attr_length)) | 350 if (!buf->Consume(attr_length)) |
350 return false; | 351 return false; |
351 } else { | 352 } else { |
352 if (!attr->Read(buf)) | 353 if (!attr->Read(buf)) |
353 return false; | 354 return false; |
354 attrs_->push_back(attr); | 355 // TODO(honghaiz): Change |attrs_| to be a vector of unique_ptrs. |
| 356 attrs_->push_back(attr.release()); |
355 } | 357 } |
356 } | 358 } |
357 | 359 |
358 ASSERT(buf->Length() == rest); | 360 ASSERT(buf->Length() == rest); |
359 return true; | 361 return true; |
360 } | 362 } |
361 | 363 |
362 bool StunMessage::Write(ByteBufferWriter* buf) const { | 364 bool StunMessage::Write(ByteBufferWriter* buf) const { |
363 buf->WriteUInt16(type_); | 365 buf->WriteUInt16(type_); |
364 buf->WriteUInt16(length_); | 366 buf->WriteUInt16(length_); |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 digest, sizeof(digest)); | 914 digest, sizeof(digest)); |
913 if (size == 0) { | 915 if (size == 0) { |
914 return false; | 916 return false; |
915 } | 917 } |
916 | 918 |
917 *hash = std::string(digest, size); | 919 *hash = std::string(digest, size); |
918 return true; | 920 return true; |
919 } | 921 } |
920 | 922 |
921 } // namespace cricket | 923 } // namespace cricket |
OLD | NEW |