#include <TurnMsgLib.h>
Public Member Functions | |
StunAttr () | |
StunAttr (const StunAttrIterator &iter) throw (WrongStunAttrFormatException, EndOfStunMsgException) | |
virtual | ~StunAttr () |
const u08bits * | getRawValue (size_t &sz) const |
void | setRawValue (u08bits *value, size_t sz) throw (WrongStunAttrFormatException) |
u16bits | getType () const |
void | setType (u16bits at) |
template<class T > | |
int | addToMsg (T &msg) throw (WrongStunAttrFormatException, WrongStunBufferFormatException) |
Protected Member Functions | |
virtual int | addToBuffer (u08bits *buffer, size_t &sz) throw (WrongStunAttrFormatException, WrongStunBufferFormatException) |
Static Protected Member Functions | |
static stun_attr_ref | getSar (const StunAttrIterator &iter) |
Root class of all STUN attributes. Can be also used for a generic attribute object.
Definition at line 189 of file TurnMsgLib.h.
turn::StunAttr::StunAttr | ( | ) | [inline] |
Empty constructor
Definition at line 194 of file TurnMsgLib.h.
: _attr_type(0), _value(0), _sz(0) {}
turn::StunAttr::StunAttr | ( | const StunAttrIterator & | iter | ) | throw (WrongStunAttrFormatException, EndOfStunMsgException) [inline] |
Constructs attribute from iterator
Definition at line 199 of file TurnMsgLib.h.
{ if(iter.eof()) { throw EndOfStunMsgException(); } size_t sz = 0; const u08bits *ptr = iter.getRawBuffer(sz); if(sz>=0xFFFF) throw WrongStunAttrFormatException(); int at = iter.getType(); if(at<0) throw WrongStunAttrFormatException(); _attr_type = (u16bits)at; _sz = sz; _value=(u08bits*)turn_malloc(_sz); if(ptr) ns_bcopy(ptr,_value,_sz); }
virtual turn::StunAttr::~StunAttr | ( | ) | [inline, virtual] |
virtual int turn::StunAttr::addToBuffer | ( | u08bits * | buffer, |
size_t & | sz | ||
) | throw (WrongStunAttrFormatException, WrongStunBufferFormatException) [inline, protected, virtual] |
Virtual function member to add attribute to a raw buffer
Reimplemented in turn::StunAttrPadding, turn::StunAttrResponsePort, turn::StunAttrChangeRequest, turn::StunAttrAddr, turn::StunAttrReservationToken, turn::StunAttrEvenPort, and turn::StunAttrChannelNumber.
Definition at line 284 of file TurnMsgLib.h.
{ if(buffer) { if(!_value) throw WrongStunAttrFormatException(); if(stun_attr_add_str(buffer, &sz, _attr_type, _value, _sz)<0) { throw WrongStunBufferFormatException(); } return 0; } throw WrongStunBufferFormatException(); }
int turn::StunAttr::addToMsg | ( | T & | msg | ) | throw (WrongStunAttrFormatException, WrongStunBufferFormatException) [inline] |
Add attribute to a message
Definition at line 265 of file TurnMsgLib.h.
{ if(!_attr_type) throw WrongStunAttrFormatException(); u08bits *buffer = msg.getRawBuffer(); if(buffer) { size_t sz = msg.getSize(); if(addToBuffer(buffer, sz)<0) { throw WrongStunBufferFormatException(); } msg.setSize(sz); return 0; } throw WrongStunBufferFormatException(); }
const u08bits* turn::StunAttr::getRawValue | ( | size_t & | sz | ) | const [inline] |
Return raw data representation of the attribute
Definition at line 228 of file TurnMsgLib.h.
{
sz=_sz;
return _value;
}
static stun_attr_ref turn::StunAttr::getSar | ( | const StunAttrIterator & | iter | ) | [inline, static, protected] |
u16bits turn::StunAttr::getType | ( | ) | const [inline] |
void turn::StunAttr::setRawValue | ( | u08bits * | value, |
size_t | sz | ||
) | throw (WrongStunAttrFormatException) [inline] |
Set raw data value
Definition at line 236 of file TurnMsgLib.h.
{ if(sz>0xFFFF) throw WrongStunAttrFormatException(); if(_value) turn_free(_value,_sz); _sz = sz; _value=(u08bits*)turn_malloc(_sz); if(value) ns_bcopy(value,_value,_sz); }
void turn::StunAttr::setType | ( | u16bits | at | ) | [inline] |