Fix clang style warnings in p2p/base/stun.h
Bug: webrtc:163 Change-Id: Ief9c59f80f36d3339fd40bed9f33e8c6eeef4f90 Reviewed-on: https://webrtc-review.googlesource.com/15781 Commit-Queue: Taylor Brandstetter <deadbeef@webrtc.org> Reviewed-by: Taylor Brandstetter <deadbeef@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20434}
This commit is contained in:
parent
74e72c8c9b
commit
ca7d54e16a
115
p2p/base/stun.cc
115
p2p/base/stun.cc
@ -52,6 +52,8 @@ StunMessage::StunMessage()
|
||||
RTC_DCHECK(IsValidTransactionId(transaction_id_));
|
||||
}
|
||||
|
||||
StunMessage::~StunMessage() = default;
|
||||
|
||||
bool StunMessage::IsLegacy() const {
|
||||
if (transaction_id_.size() == kStunLegacyTransactionIdLength)
|
||||
return true;
|
||||
@ -287,7 +289,7 @@ bool StunMessage::AddFingerprint() {
|
||||
// it can't fail.
|
||||
auto fingerprint_attr_ptr =
|
||||
rtc::MakeUnique<StunUInt32Attribute>(STUN_ATTR_FINGERPRINT, 0);
|
||||
auto fingerprint_attr = fingerprint_attr_ptr.get();
|
||||
auto* fingerprint_attr = fingerprint_attr_ptr.get();
|
||||
AddAttribute(std::move(fingerprint_attr_ptr));
|
||||
|
||||
// Calculate the CRC-32 for the message and insert it.
|
||||
@ -386,6 +388,10 @@ bool StunMessage::Write(ByteBufferWriter* buf) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
StunMessage* StunMessage::CreateNew() const {
|
||||
return new StunMessage();
|
||||
}
|
||||
|
||||
StunAttributeValueType StunMessage::GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_MAPPED_ADDRESS: return STUN_VALUE_ADDRESS;
|
||||
@ -524,6 +530,10 @@ StunAddressAttribute::StunAddressAttribute(uint16_t type, uint16_t length)
|
||||
: StunAttribute(type, length) {
|
||||
}
|
||||
|
||||
StunAttributeValueType StunAddressAttribute::value_type() const {
|
||||
return STUN_VALUE_ADDRESS;
|
||||
}
|
||||
|
||||
bool StunAddressAttribute::Read(ByteBufferReader* buf) {
|
||||
uint8_t dummy;
|
||||
if (!buf->ReadUInt8(&dummy))
|
||||
@ -597,6 +607,14 @@ StunXorAddressAttribute::StunXorAddressAttribute(uint16_t type,
|
||||
: StunAddressAttribute(type, length), owner_(owner) {
|
||||
}
|
||||
|
||||
StunAttributeValueType StunXorAddressAttribute::value_type() const {
|
||||
return STUN_VALUE_XOR_ADDRESS;
|
||||
}
|
||||
|
||||
void StunXorAddressAttribute::SetOwner(StunMessage* owner) {
|
||||
owner_ = owner;
|
||||
}
|
||||
|
||||
rtc::IPAddress StunXorAddressAttribute::GetXoredIP() const {
|
||||
if (owner_) {
|
||||
rtc::IPAddress ip = ipaddr();
|
||||
@ -678,6 +696,10 @@ StunUInt32Attribute::StunUInt32Attribute(uint16_t type)
|
||||
: StunAttribute(type, SIZE), bits_(0) {
|
||||
}
|
||||
|
||||
StunAttributeValueType StunUInt32Attribute::value_type() const {
|
||||
return STUN_VALUE_UINT32;
|
||||
}
|
||||
|
||||
bool StunUInt32Attribute::GetBit(size_t index) const {
|
||||
RTC_DCHECK(index < 32);
|
||||
return static_cast<bool>((bits_ >> index) & 0x1);
|
||||
@ -708,6 +730,10 @@ StunUInt64Attribute::StunUInt64Attribute(uint16_t type)
|
||||
: StunAttribute(type, SIZE), bits_(0) {
|
||||
}
|
||||
|
||||
StunAttributeValueType StunUInt64Attribute::value_type() const {
|
||||
return STUN_VALUE_UINT64;
|
||||
}
|
||||
|
||||
bool StunUInt64Attribute::Read(ByteBufferReader* buf) {
|
||||
if (length() != SIZE || !buf->ReadUInt64(&bits_))
|
||||
return false;
|
||||
@ -744,6 +770,10 @@ StunByteStringAttribute::~StunByteStringAttribute() {
|
||||
delete [] bytes_;
|
||||
}
|
||||
|
||||
StunAttributeValueType StunByteStringAttribute::value_type() const {
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
}
|
||||
|
||||
void StunByteStringAttribute::CopyBytes(const char* bytes) {
|
||||
CopyBytes(bytes, strlen(bytes));
|
||||
}
|
||||
@ -805,6 +835,10 @@ StunErrorCodeAttribute::StunErrorCodeAttribute(uint16_t type, uint16_t length)
|
||||
StunErrorCodeAttribute::~StunErrorCodeAttribute() {
|
||||
}
|
||||
|
||||
StunAttributeValueType StunErrorCodeAttribute::value_type() const {
|
||||
return STUN_VALUE_ERROR_CODE;
|
||||
}
|
||||
|
||||
int StunErrorCodeAttribute::code() const {
|
||||
return class_ * 100 + number_;
|
||||
}
|
||||
@ -853,6 +887,10 @@ StunUInt16ListAttribute::~StunUInt16ListAttribute() {
|
||||
delete attr_types_;
|
||||
}
|
||||
|
||||
StunAttributeValueType StunUInt16ListAttribute::value_type() const {
|
||||
return STUN_VALUE_UINT16_LIST;
|
||||
}
|
||||
|
||||
size_t StunUInt16ListAttribute::Size() const {
|
||||
return attr_types_->size();
|
||||
}
|
||||
@ -946,4 +984,79 @@ bool ComputeStunCredentialHash(const std::string& username,
|
||||
return true;
|
||||
}
|
||||
|
||||
StunAttributeValueType RelayMessage::GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_LIFETIME:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_MAGIC_COOKIE:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_BANDWIDTH:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_DESTINATION_ADDRESS:
|
||||
return STUN_VALUE_ADDRESS;
|
||||
case STUN_ATTR_SOURCE_ADDRESS2:
|
||||
return STUN_VALUE_ADDRESS;
|
||||
case STUN_ATTR_DATA:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_OPTIONS:
|
||||
return STUN_VALUE_UINT32;
|
||||
default:
|
||||
return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
|
||||
StunMessage* RelayMessage::CreateNew() const {
|
||||
return new RelayMessage();
|
||||
}
|
||||
|
||||
StunAttributeValueType TurnMessage::GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_CHANNEL_NUMBER:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_TURN_LIFETIME:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_XOR_PEER_ADDRESS:
|
||||
return STUN_VALUE_XOR_ADDRESS;
|
||||
case STUN_ATTR_DATA:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_XOR_RELAYED_ADDRESS:
|
||||
return STUN_VALUE_XOR_ADDRESS;
|
||||
case STUN_ATTR_EVEN_PORT:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_REQUESTED_TRANSPORT:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_DONT_FRAGMENT:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_RESERVATION_TOKEN:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
default:
|
||||
return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
|
||||
StunMessage* TurnMessage::CreateNew() const {
|
||||
return new TurnMessage();
|
||||
}
|
||||
|
||||
StunAttributeValueType IceMessage::GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_PRIORITY:
|
||||
case STUN_ATTR_NETWORK_INFO:
|
||||
case STUN_ATTR_NOMINATION:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_USE_CANDIDATE:
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_ICE_CONTROLLED:
|
||||
return STUN_VALUE_UINT64;
|
||||
case STUN_ATTR_ICE_CONTROLLING:
|
||||
return STUN_VALUE_UINT64;
|
||||
default:
|
||||
return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
|
||||
StunMessage* IceMessage::CreateNew() const {
|
||||
return new IceMessage();
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
117
p2p/base/stun.h
117
p2p/base/stun.h
@ -132,7 +132,7 @@ class StunUInt16ListAttribute;
|
||||
class StunMessage {
|
||||
public:
|
||||
StunMessage();
|
||||
virtual ~StunMessage() = default;
|
||||
virtual ~StunMessage();
|
||||
|
||||
int type() const { return type_; }
|
||||
size_t length() const { return length_; }
|
||||
@ -188,7 +188,7 @@ class StunMessage {
|
||||
bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
|
||||
// Creates an empty message. Overridable by derived classes.
|
||||
virtual StunMessage* CreateNew() const { return new StunMessage(); }
|
||||
virtual StunMessage* CreateNew() const;
|
||||
|
||||
protected:
|
||||
// Verifies that the given attribute is allowed for this message.
|
||||
@ -265,9 +265,7 @@ class StunAddressAttribute : public StunAttribute {
|
||||
StunAddressAttribute(uint16_t type, const rtc::SocketAddress& addr);
|
||||
StunAddressAttribute(uint16_t type, uint16_t length);
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_ADDRESS;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
StunAddressFamily family() const {
|
||||
switch (address_.ipaddr().family()) {
|
||||
@ -293,8 +291,8 @@ class StunAddressAttribute : public StunAttribute {
|
||||
}
|
||||
void SetPort(uint16_t port) { address_.SetPort(port); }
|
||||
|
||||
virtual bool Read(rtc::ByteBufferReader* buf);
|
||||
virtual bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
void EnsureAddressLength() {
|
||||
@ -324,14 +322,10 @@ class StunXorAddressAttribute : public StunAddressAttribute {
|
||||
StunXorAddressAttribute(uint16_t type, const rtc::SocketAddress& addr);
|
||||
StunXorAddressAttribute(uint16_t type, uint16_t length, StunMessage* owner);
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_XOR_ADDRESS;
|
||||
}
|
||||
virtual void SetOwner(StunMessage* owner) {
|
||||
owner_ = owner;
|
||||
}
|
||||
virtual bool Read(rtc::ByteBufferReader* buf);
|
||||
virtual bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
StunAttributeValueType value_type() const override;
|
||||
void SetOwner(StunMessage* owner) override;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
rtc::IPAddress GetXoredIP() const;
|
||||
@ -345,9 +339,7 @@ class StunUInt32Attribute : public StunAttribute {
|
||||
StunUInt32Attribute(uint16_t type, uint32_t value);
|
||||
explicit StunUInt32Attribute(uint16_t type);
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_UINT32;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
uint32_t value() const { return bits_; }
|
||||
void SetValue(uint32_t bits) { bits_ = bits; }
|
||||
@ -355,8 +347,8 @@ class StunUInt32Attribute : public StunAttribute {
|
||||
bool GetBit(size_t index) const;
|
||||
void SetBit(size_t index, bool value);
|
||||
|
||||
virtual bool Read(rtc::ByteBufferReader* buf);
|
||||
virtual bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
uint32_t bits_;
|
||||
@ -368,15 +360,13 @@ class StunUInt64Attribute : public StunAttribute {
|
||||
StunUInt64Attribute(uint16_t type, uint64_t value);
|
||||
explicit StunUInt64Attribute(uint16_t type);
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_UINT64;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
uint64_t value() const { return bits_; }
|
||||
void SetValue(uint64_t bits) { bits_ = bits; }
|
||||
|
||||
virtual bool Read(rtc::ByteBufferReader* buf);
|
||||
virtual bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
uint64_t bits_;
|
||||
@ -389,11 +379,9 @@ class StunByteStringAttribute : public StunAttribute {
|
||||
StunByteStringAttribute(uint16_t type, const std::string& str);
|
||||
StunByteStringAttribute(uint16_t type, const void* bytes, size_t length);
|
||||
StunByteStringAttribute(uint16_t type, uint16_t length);
|
||||
~StunByteStringAttribute();
|
||||
~StunByteStringAttribute() override;
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_BYTE_STRING;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
const char* bytes() const { return bytes_; }
|
||||
std::string GetString() const { return std::string(bytes_, length()); }
|
||||
@ -404,8 +392,8 @@ class StunByteStringAttribute : public StunAttribute {
|
||||
uint8_t GetByte(size_t index) const;
|
||||
void SetByte(size_t index, uint8_t value);
|
||||
|
||||
virtual bool Read(rtc::ByteBufferReader* buf);
|
||||
virtual bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
void SetBytes(char* bytes, size_t length);
|
||||
@ -419,11 +407,9 @@ class StunErrorCodeAttribute : public StunAttribute {
|
||||
static const uint16_t MIN_SIZE;
|
||||
StunErrorCodeAttribute(uint16_t type, int code, const std::string& reason);
|
||||
StunErrorCodeAttribute(uint16_t type, uint16_t length);
|
||||
~StunErrorCodeAttribute();
|
||||
~StunErrorCodeAttribute() override;
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_ERROR_CODE;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
// The combined error and class, e.g. 0x400.
|
||||
int code() const;
|
||||
@ -437,8 +423,8 @@ class StunErrorCodeAttribute : public StunAttribute {
|
||||
void SetNumber(uint8_t number) { number_ = number; }
|
||||
void SetReason(const std::string& reason);
|
||||
|
||||
bool Read(rtc::ByteBufferReader* buf);
|
||||
bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
uint8_t class_;
|
||||
@ -450,19 +436,17 @@ class StunErrorCodeAttribute : public StunAttribute {
|
||||
class StunUInt16ListAttribute : public StunAttribute {
|
||||
public:
|
||||
StunUInt16ListAttribute(uint16_t type, uint16_t length);
|
||||
~StunUInt16ListAttribute();
|
||||
~StunUInt16ListAttribute() override;
|
||||
|
||||
virtual StunAttributeValueType value_type() const {
|
||||
return STUN_VALUE_UINT16_LIST;
|
||||
}
|
||||
StunAttributeValueType value_type() const override;
|
||||
|
||||
size_t Size() const;
|
||||
uint16_t GetType(int index) const;
|
||||
void SetType(int index, uint16_t value);
|
||||
void AddType(uint16_t value);
|
||||
|
||||
bool Read(rtc::ByteBufferReader* buf);
|
||||
bool Write(rtc::ByteBufferWriter* buf) const;
|
||||
bool Read(rtc::ByteBufferReader* buf) override;
|
||||
bool Write(rtc::ByteBufferWriter* buf) const override;
|
||||
|
||||
private:
|
||||
std::vector<uint16_t>* attr_types_;
|
||||
@ -524,19 +508,8 @@ enum RelayAttributeType {
|
||||
// A "GTURN" STUN message.
|
||||
class RelayMessage : public StunMessage {
|
||||
protected:
|
||||
virtual StunAttributeValueType GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_LIFETIME: return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_MAGIC_COOKIE: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_BANDWIDTH: return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_DESTINATION_ADDRESS: return STUN_VALUE_ADDRESS;
|
||||
case STUN_ATTR_SOURCE_ADDRESS2: return STUN_VALUE_ADDRESS;
|
||||
case STUN_ATTR_DATA: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_OPTIONS: return STUN_VALUE_UINT32;
|
||||
default: return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
virtual StunMessage* CreateNew() const { return new RelayMessage(); }
|
||||
StunAttributeValueType GetAttributeValueType(int type) const override;
|
||||
StunMessage* CreateNew() const override;
|
||||
};
|
||||
|
||||
// Defined in TURN RFC 5766.
|
||||
@ -586,21 +559,8 @@ extern const char STUN_ERROR_REASON_WRONG_CREDENTIALS[];
|
||||
extern const char STUN_ERROR_REASON_UNSUPPORTED_PROTOCOL[];
|
||||
class TurnMessage : public StunMessage {
|
||||
protected:
|
||||
virtual StunAttributeValueType GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_CHANNEL_NUMBER: return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_TURN_LIFETIME: return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_XOR_PEER_ADDRESS: return STUN_VALUE_XOR_ADDRESS;
|
||||
case STUN_ATTR_DATA: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_XOR_RELAYED_ADDRESS: return STUN_VALUE_XOR_ADDRESS;
|
||||
case STUN_ATTR_EVEN_PORT: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_REQUESTED_TRANSPORT: return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_DONT_FRAGMENT: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_RESERVATION_TOKEN: return STUN_VALUE_BYTE_STRING;
|
||||
default: return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
virtual StunMessage* CreateNew() const { return new TurnMessage(); }
|
||||
StunAttributeValueType GetAttributeValueType(int type) const override;
|
||||
StunMessage* CreateNew() const override;
|
||||
};
|
||||
|
||||
// RFC 5245 ICE STUN attributes.
|
||||
@ -624,19 +584,8 @@ extern const char STUN_ERROR_REASON_ROLE_CONFLICT[];
|
||||
// A RFC 5245 ICE STUN message.
|
||||
class IceMessage : public StunMessage {
|
||||
protected:
|
||||
virtual StunAttributeValueType GetAttributeValueType(int type) const {
|
||||
switch (type) {
|
||||
case STUN_ATTR_PRIORITY:
|
||||
case STUN_ATTR_NETWORK_INFO:
|
||||
case STUN_ATTR_NOMINATION:
|
||||
return STUN_VALUE_UINT32;
|
||||
case STUN_ATTR_USE_CANDIDATE: return STUN_VALUE_BYTE_STRING;
|
||||
case STUN_ATTR_ICE_CONTROLLED: return STUN_VALUE_UINT64;
|
||||
case STUN_ATTR_ICE_CONTROLLING: return STUN_VALUE_UINT64;
|
||||
default: return StunMessage::GetAttributeValueType(type);
|
||||
}
|
||||
}
|
||||
virtual StunMessage* CreateNew() const { return new IceMessage(); }
|
||||
StunAttributeValueType GetAttributeValueType(int type) const override;
|
||||
StunMessage* CreateNew() const override;
|
||||
};
|
||||
|
||||
} // namespace cricket
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user