STUN module (rfc5389)

StringAttribute

Implements a STUN/TURN attribute that holds an arbitrary byte string.

StringAttribute

#include <icy/stun/attributes.h>

Inherits: Attribute

Implements a STUN/TURN attribute that holds an arbitrary byte string. Used for Username, Password, Realm, Nonce, Software, Data, and similar attributes.

Public Methods

ReturnNameDescription
StringAttribute#### Parameters
StringAttributeCopy constructor; duplicates stored bytes.
std::unique_ptr< Attribute >clone virtualReturns a deep copy of this attribute.
const char *bytes const inline#### Returns
voidsetBytesReplaces the stored bytes with a copy of the given buffer and updates the attribute's reported size.
std::stringasString const#### Returns
voidcopyBytesCopies a null-terminated string into the attribute, using strlen to determine the length.
voidcopyBytesCopies an arbitrary block of memory into the attribute.
uint8_tgetByte constReturns a single byte from the stored buffer.
voidsetByteOverwrites a single byte in the stored buffer.
voidread virtualReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite virtual constWrites the body (not the type or size) to the given buffer.

StringAttribute

StringAttribute(uint16_t type, uint16_t size)

Parameters

  • type Wire type code for the concrete attribute.

  • size Initial body length in bytes (0 for variable-length attributes).


StringAttribute

StringAttribute(const StringAttribute & r)

Copy constructor; duplicates stored bytes.


clone

virtual

virtual std::unique_ptr< Attribute > clone()

Returns a deep copy of this attribute.


bytes

const inline

inline const char * bytes() const

Returns

Pointer to the raw byte buffer.


setBytes

void setBytes(const char * bytes, size_t size)

Replaces the stored bytes with a copy of the given buffer and updates the attribute's reported size.

Parameters

  • bytes Source data pointer.

  • size Number of bytes to copy.


asString

const

std::string asString() const

Returns

The stored bytes as a std::string.


copyBytes

void copyBytes(const char * bytes)

Copies a null-terminated string into the attribute, using strlen to determine the length.

Parameters

  • bytes Null-terminated source string.

copyBytes

void copyBytes(const void * bytes, size_t size)

Copies an arbitrary block of memory into the attribute.

Parameters

  • bytes Source data pointer.

  • size Number of bytes to copy.


getByte

const

uint8_t getByte(int index) const

Returns a single byte from the stored buffer.

Parameters

  • index Zero-based byte offset.

Returns

The byte value at index.


setByte

void setByte(int index, uint8_t value)

Overwrites a single byte in the stored buffer.

Parameters

  • index Zero-based byte offset.

  • value New value to write.


read

virtual

virtual void read(BitReader & reader)

Reads the body (not the type or size) for this type of attribute from the given buffer.

Parameters

  • reader Source bit reader positioned at the attribute body.

write

virtual const

virtual void write(BitWriter & writer) const

Writes the body (not the type or size) to the given buffer.

Parameters

  • writer Destination bit writer.

Private Attributes

ReturnNameDescription
std::vector< char >_bytes

_bytes

std::vector< char > _bytes