#include <icy/stun/message.h>STUN/TURN protocol message with method, class, transaction ID, and attributes.
| Return | Name | Description |
|---|---|---|
Message | Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID. | |
Message | Constructs a message with explicit class and method. | |
Message | Deep-copy constructor; clones all attributes. | |
Message | Move constructor. | |
Message & | operator= | Deep-copy assignment; clones all attributes from that. |
Message & | operator= | Move assignment. |
std::unique_ptr< IPacket > | clone virtual const | #### Returns |
void | setClass | Sets the message class field. |
void | setMethod | Sets the message method field. |
void | setTransactionID | Sets the 12-byte transaction ID. |
ClassType | classType const | #### Returns |
MethodType | methodType const | #### Returns |
const TransactionID & | transactionID const inline | #### Returns |
size_t | size virtual const inline | #### Returns |
std::string | methodString const | #### Returns |
std::string | classString const | #### Returns |
std::string | errorString const | Maps a numeric error code to its canonical string description. |
T & | add inline | Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration. |
void | add | Appends an attribute to the message, taking ownership via unique_ptr. |
Attribute * | get const | Returns the Nth attribute of the given type, or nullptr if not found. |
T * | get const inline | Type-safe attribute accessor using the concrete attribute's TypeID. |
ssize_t | read virtual | Parses a STUN/TURN packet from the given buffer. |
void | write virtual const | Serialises this message into a STUN/TURN wire-format packet. |
std::string | toString const | #### Returns |
void | print virtual const | Writes the same representation as toString() to the given stream. |
const char * | className virtual const inline | Returns the class name of this packet type for logging and diagnostics. |
Message()Constructs a default message (Request class, Undefined method) with a randomly generated 12-byte transaction ID.
Message(ClassType clss, MethodType meth)Constructs a message with explicit class and method.
clss Message class (Request, Indication, SuccessResponse, or ErrorResponse).
meth Message method (Binding, Allocate, Refresh, etc.).
Message(const Message & that)Deep-copy constructor; clones all attributes.
Message(Message && that) noexceptMove constructor.
Message & operator=(const Message & that)Deep-copy assignment; clones all attributes from that.
Message & operator=(Message && that) noexceptMove assignment.
virtual const
virtual std::unique_ptr< IPacket > clone() constA heap-allocated deep copy of this message.
void setClass(ClassType type)Sets the message class field.
type One of Request, Indication, SuccessResponse, ErrorResponse.void setMethod(MethodType type)Sets the message method field.
type One of the MethodType enumerators.void setTransactionID(const std::string & id)Sets the 12-byte transaction ID.
id Must be exactly kTransactionIdLength (12) bytes.const
ClassType classType() constThe message class.
const
MethodType methodType() constThe message method.
const inline
inline const TransactionID & transactionID() constReference to the 12-byte transaction ID string.
virtual const inline
virtual inline size_t size() constTotal body size in bytes (sum of padded attribute headers and bodies).
const
std::string methodString() constHuman-readable method name (e.g. "BINDING", "ALLOCATE").
const
std::string classString() constHuman-readable class name (e.g. "Request", "SuccessResponse").
const
std::string errorString(uint16_t errorCode) constMaps a numeric error code to its canonical string description.
errorCode One of the ErrorCodes enumerators.Human-readable error string, or "UnknownError" if not recognised.
inline
template<typename T> inline T & add()Constructs an attribute of type T in-place and appends it to the message. Returns a reference to the new attribute for further configuration.
T Concrete attribute type (e.g. stun::Lifetime, stun::XorMappedAddress).Reference to the newly added attribute.
void add(std::unique_ptr< Attribute > attr)Appends an attribute to the message, taking ownership via unique_ptr.
attr Attribute to add.const
Attribute * get(Attribute::Type type, int index) constReturns the Nth attribute of the given type, or nullptr if not found.
type Attribute type code to search for.
index Zero-based occurrence index (0 = first match).
Raw pointer to the attribute (owned by this message), or nullptr.
const inline
template<typename T> inline T * get(int index) constType-safe attribute accessor using the concrete attribute's TypeID.
T Concrete attribute type (must define TypeID).index Zero-based occurrence index.Pointer to T, or nullptr if the attribute is absent.
virtual
virtual ssize_t read(const ConstBuffer & buf)Parses a STUN/TURN packet from the given buffer.
buf Buffer containing at least one complete STUN message.Number of bytes consumed, or 0 on parse failure.
virtual const
virtual void write(Buffer & buf) constSerialises this message into a STUN/TURN wire-format packet.
buf Destination buffer; data is appended.const
std::string toString() constA concise string representation for logging (method, transaction ID, attribute types).
virtual const
virtual void print(std::ostream & os) constWrites the same representation as toString() to the given stream.
os Output stream.virtual const inline
virtual inline const char * className() constReturns the class name of this packet type for logging and diagnostics.
| Return | Name | Description |
|---|---|---|
uint16_t | _class | |
uint16_t | _method | |
uint16_t | _size | Set by read(); write() uses computeBodySize() instead. |
TransactionID | _transactionID | |
std::vector< std::unique_ptr< Attribute > > | _attrs |
uint16_t _classuint16_t _methoduint16_t _sizeSet by read(); write() uses computeBodySize() instead.
TransactionID _transactionIDstd::vector< std::unique_ptr< Attribute > > _attrs| Name | Description |
|---|---|
MethodType | |
ClassType | |
ErrorCodes |
enum MethodType| Value | Description |
|---|---|
Undefined | default error type |
Binding | STUN. |
Allocate | TURN. |
Refresh | |
SendIndication | (only indication semantics defined) |
DataIndication | (only indication semantics defined) |
CreatePermission | (only request/response semantics defined) |
ChannelBind | (only request/response semantics defined) |
Connect | TURN TCP RFC 6062. |
ConnectionBind | |
ConnectionAttempt |
enum ClassType| Value | Description |
|---|---|
Request | |
Indication | |
SuccessResponse | |
ErrorResponse |
enum ErrorCodes| Value | Description |
|---|---|
TryAlternate | |
BadRequest | |
NotAuthorized | |
Forbidden | |
UnknownAttribute | |
StaleCredentials | |
IntegrityCheckFailure | |
MissingUsername | |
UseTLS | |
AllocationMismatch | |
StaleNonce | |
WrongCredentials | |
UnsupportedTransport | |
AllocationQuotaReached | |
RoleConflict | |
ServerError | |
InsufficientCapacity | |
GlobalFailure | |
ConnectionAlreadyExists | TURN TCP. |
ConnectionTimeoutOrFailure |
| Return | Name | Description |
|---|---|---|
uint16_t | computeBodySize const | Computes the wire body size from the current attribute list. |
const
uint16_t computeBodySize() constComputes the wire body size from the current attribute list.