| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 const StunAddressAttribute* GetAddress(int type) const; | 152 const StunAddressAttribute* GetAddress(int type) const; |
| 153 const StunUInt32Attribute* GetUInt32(int type) const; | 153 const StunUInt32Attribute* GetUInt32(int type) const; |
| 154 const StunUInt64Attribute* GetUInt64(int type) const; | 154 const StunUInt64Attribute* GetUInt64(int type) const; |
| 155 const StunByteStringAttribute* GetByteString(int type) const; | 155 const StunByteStringAttribute* GetByteString(int type) const; |
| 156 | 156 |
| 157 // Gets these specific attribute values. | 157 // Gets these specific attribute values. |
| 158 const StunErrorCodeAttribute* GetErrorCode() const; | 158 const StunErrorCodeAttribute* GetErrorCode() const; |
| 159 const StunUInt16ListAttribute* GetUnknownAttributes() const; | 159 const StunUInt16ListAttribute* GetUnknownAttributes() const; |
| 160 | 160 |
| 161 // Takes ownership of the specified attribute and adds it to the message. | 161 // Takes ownership of the specified attribute and adds it to the message. |
| 162 // TODO(zstein): Take a unique_ptr instead of a raw pointer. | 162 void AddAttribute(std::unique_ptr<StunAttribute> attr); |
| 163 void AddAttribute(StunAttribute* attr); | |
| 164 | 163 |
| 165 // Validates that a raw STUN message has a correct MESSAGE-INTEGRITY value. | 164 // Validates that a raw STUN message has a correct MESSAGE-INTEGRITY value. |
| 166 // This can't currently be done on a StunMessage, since it is affected by | 165 // This can't currently be done on a StunMessage, since it is affected by |
| 167 // padding data (which we discard when reading a StunMessage). | 166 // padding data (which we discard when reading a StunMessage). |
| 168 static bool ValidateMessageIntegrity(const char* data, size_t size, | 167 static bool ValidateMessageIntegrity(const char* data, size_t size, |
| 169 const std::string& password); | 168 const std::string& password); |
| 170 // Adds a MESSAGE-INTEGRITY attribute that is valid for the current message. | 169 // Adds a MESSAGE-INTEGRITY attribute that is valid for the current message. |
| 171 bool AddMessageIntegrity(const std::string& password); | 170 bool AddMessageIntegrity(const std::string& password); |
| 172 bool AddMessageIntegrity(const char* key, size_t keylen); | 171 bool AddMessageIntegrity(const char* key, size_t keylen); |
| 173 | 172 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // value is true if successful. | 225 // value is true if successful. |
| 227 virtual bool Write(rtc::ByteBufferWriter* buf) const = 0; | 226 virtual bool Write(rtc::ByteBufferWriter* buf) const = 0; |
| 228 | 227 |
| 229 // Creates an attribute object with the given type and smallest length. | 228 // Creates an attribute object with the given type and smallest length. |
| 230 static StunAttribute* Create(StunAttributeValueType value_type, | 229 static StunAttribute* Create(StunAttributeValueType value_type, |
| 231 uint16_t type, | 230 uint16_t type, |
| 232 uint16_t length, | 231 uint16_t length, |
| 233 StunMessage* owner); | 232 StunMessage* owner); |
| 234 // TODO: Allow these create functions to take parameters, to reduce | 233 // TODO: Allow these create functions to take parameters, to reduce |
| 235 // the amount of work callers need to do to initialize attributes. | 234 // the amount of work callers need to do to initialize attributes. |
| 236 static StunAddressAttribute* CreateAddress(uint16_t type); | 235 static std::unique_ptr<StunAddressAttribute> CreateAddress(uint16_t type); |
| 237 static StunXorAddressAttribute* CreateXorAddress(uint16_t type); | 236 static std::unique_ptr<StunXorAddressAttribute> CreateXorAddress( |
| 238 static StunUInt32Attribute* CreateUInt32(uint16_t type); | 237 uint16_t type); |
| 239 static StunUInt64Attribute* CreateUInt64(uint16_t type); | 238 static std::unique_ptr<StunUInt32Attribute> CreateUInt32(uint16_t type); |
| 240 static StunByteStringAttribute* CreateByteString(uint16_t type); | 239 static std::unique_ptr<StunUInt64Attribute> CreateUInt64(uint16_t type); |
| 241 static StunErrorCodeAttribute* CreateErrorCode(); | 240 static std::unique_ptr<StunByteStringAttribute> CreateByteString( |
| 242 static StunUInt16ListAttribute* CreateUnknownAttributes(); | 241 uint16_t type); |
| 242 static std::unique_ptr<StunErrorCodeAttribute> CreateErrorCode(); |
| 243 static std::unique_ptr<StunUInt16ListAttribute> CreateUnknownAttributes(); |
| 243 | 244 |
| 244 protected: | 245 protected: |
| 245 StunAttribute(uint16_t type, uint16_t length); | 246 StunAttribute(uint16_t type, uint16_t length); |
| 246 void SetLength(uint16_t length) { length_ = length; } | 247 void SetLength(uint16_t length) { length_ = length; } |
| 247 void WritePadding(rtc::ByteBufferWriter* buf) const; | 248 void WritePadding(rtc::ByteBufferWriter* buf) const; |
| 248 void ConsumePadding(rtc::ByteBufferReader* buf) const; | 249 void ConsumePadding(rtc::ByteBufferReader* buf) const; |
| 249 | 250 |
| 250 private: | 251 private: |
| 251 uint16_t type_; | 252 uint16_t type_; |
| 252 uint16_t length_; | 253 uint16_t length_; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 406 |
| 406 private: | 407 private: |
| 407 void SetBytes(char* bytes, size_t length); | 408 void SetBytes(char* bytes, size_t length); |
| 408 | 409 |
| 409 char* bytes_; | 410 char* bytes_; |
| 410 }; | 411 }; |
| 411 | 412 |
| 412 // Implements STUN attributes that record an error code. | 413 // Implements STUN attributes that record an error code. |
| 413 class StunErrorCodeAttribute : public StunAttribute { | 414 class StunErrorCodeAttribute : public StunAttribute { |
| 414 public: | 415 public: |
| 415 static const uint16_t MIN_SIZE = 4; | 416 static const uint16_t MIN_SIZE; |
| 416 StunErrorCodeAttribute(uint16_t type, int code, const std::string& reason); | 417 StunErrorCodeAttribute(uint16_t type, int code, const std::string& reason); |
| 417 StunErrorCodeAttribute(uint16_t type, uint16_t length); | 418 StunErrorCodeAttribute(uint16_t type, uint16_t length); |
| 418 ~StunErrorCodeAttribute(); | 419 ~StunErrorCodeAttribute(); |
| 419 | 420 |
| 420 virtual StunAttributeValueType value_type() const { | 421 virtual StunAttributeValueType value_type() const { |
| 421 return STUN_VALUE_ERROR_CODE; | 422 return STUN_VALUE_ERROR_CODE; |
| 422 } | 423 } |
| 423 | 424 |
| 424 // The combined error and class, e.g. 0x400. | 425 // The combined error and class, e.g. 0x400. |
| 425 int code() const; | 426 int code() const; |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 case STUN_ATTR_ICE_CONTROLLING: return STUN_VALUE_UINT64; | 632 case STUN_ATTR_ICE_CONTROLLING: return STUN_VALUE_UINT64; |
| 632 default: return StunMessage::GetAttributeValueType(type); | 633 default: return StunMessage::GetAttributeValueType(type); |
| 633 } | 634 } |
| 634 } | 635 } |
| 635 virtual StunMessage* CreateNew() const { return new IceMessage(); } | 636 virtual StunMessage* CreateNew() const { return new IceMessage(); } |
| 636 }; | 637 }; |
| 637 | 638 |
| 638 } // namespace cricket | 639 } // namespace cricket |
| 639 | 640 |
| 640 #endif // WEBRTC_P2P_BASE_STUN_H_ | 641 #endif // WEBRTC_P2P_BASE_STUN_H_ |
| OLD | NEW |