TURN Server  1.5
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
turn::StunMsg Class Reference

#include <TurnMsgLib.h>

Inheritance diagram for turn::StunMsg:
turn::StunMsgChannel turn::StunMsgIndication turn::StunMsgRequest turn::StunMsgResponse

List of all members.

Public Member Functions

 StunMsg ()
 StunMsg (u08bits *buffer, size_t total_sz, size_t sz, bool constructed)
virtual ~StunMsg ()
void construct ()
bool isValid ()
u08bits * getRawBuffer ()
size_t getSize () const
void setSize (size_t sz) throw (WrongStunBufferFormatException)
bool isCommand () const
int addAttr (StunAttr &attr) throw (WrongStunAttrFormatException, WrongStunBufferFormatException)
virtual stun_tid getTid () const throw (WrongStunBufferFormatException)
virtual void setTid (stun_tid &tid) throw (WrongStunBufferFormatException)
void addFingerprint () throw (WrongStunBufferFormatException)
bool checkMessageIntegrity (std::string &uname, std::string &realm, std::string &upwd) const throw (WrongStunBufferFormatException)
void addMessageIntegrity (std::string &uname, std::string &realm, std::string &upwd, std::string &nonce) throw (WrongStunBufferFormatException)

Static Public Member Functions

static bool isCommand (u08bits *buffer, size_t sz)
static bool isIndication (u08bits *buffer, size_t sz)
static bool isRequest (u08bits *buffer, size_t sz)
static bool isSuccessResponse (u08bits *buffer, size_t sz)
static bool isErrorResponse (u08bits *buffer, size_t sz, int &err_code, u08bits *err_msg, size_t err_msg_size)
static bool isChallengeResponse (const u08bits *buf, size_t sz, int &err_code, u08bits *err_msg, size_t err_msg_size, u08bits *realm, u08bits *nonce)
static bool isChannel (u08bits *buffer, size_t sz)
static bool isFingerprintPresent (u08bits *buffer, size_t sz)
static bool checkFingerprint (u08bits *buffer, size_t sz)

Protected Member Functions

virtual void constructBuffer ()=0
virtual bool check ()=0

Protected Attributes

u08bits * _buffer
bool _deallocate
size_t _allocated_sz
size_t _sz
bool _constructed

Detailed Description

Generic "STUN Message" class, base class for all messages

Definition at line 565 of file TurnMsgLib.h.


Constructor & Destructor Documentation

turn::StunMsg::StunMsg ( ) [inline]

Empty constructor

Definition at line 570 of file TurnMsgLib.h.

                  {
                _allocated_sz = 0xFFFF;
                _buffer = (u08bits*)turn_malloc(_allocated_sz);
                _deallocate = true;
                _sz = 0;
                _constructed = 0;
        }
turn::StunMsg::StunMsg ( u08bits *  buffer,
size_t  total_sz,
size_t  sz,
bool  constructed 
) [inline]

Construct message over raw buffer. Parameter "construct" is true if the buffer is initialized.

Definition at line 582 of file TurnMsgLib.h.

                                                                               :
                _buffer(buffer), _deallocate(false), _allocated_sz(total_sz),
                _sz(sz), _constructed(constructed) {}
virtual turn::StunMsg::~StunMsg ( ) [inline, virtual]

Destructor

Definition at line 589 of file TurnMsgLib.h.

                           {
                if(_deallocate && _buffer) {
                        turn_free(_buffer, _allocated_sz);
                }
        }

Member Function Documentation

Add attribute to the message

Definition at line 702 of file TurnMsgLib.h.

                                                                                                        {
                return attr.addToMsg(*this);
        }

Add fingerprint to the message

Definition at line 729 of file TurnMsgLib.h.

                                                                    {
                if(!_constructed || !isCommand())
                        throw WrongStunBufferFormatException();
                stun_attr_add_fingerprint_str(_buffer,&_sz);
        }
void turn::StunMsg::addMessageIntegrity ( std::string &  uname,
std::string &  realm,
std::string &  upwd,
std::string &  nonce 
) throw (WrongStunBufferFormatException) [inline]

Adds message integrity data to the message.

Definition at line 749 of file TurnMsgLib.h.

                                                      {

                if(!_constructed || !isCommand())
                        throw WrongStunBufferFormatException();

                stun_attr_add_integrity_by_user_str(_buffer, &_sz,
                        (u08bits *)uname.c_str(), (u08bits *)realm.c_str(), (u08bits *)upwd.c_str(), (u08bits *)nonce.c_str());
        }
virtual bool turn::StunMsg::check ( ) [protected, pure virtual]
static bool turn::StunMsg::checkFingerprint ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Check the fingerprint

Definition at line 695 of file TurnMsgLib.h.

                                                                 {
                return stun_is_command_message_full_check_str(buffer, sz, 1);
        }
bool turn::StunMsg::checkMessageIntegrity ( std::string &  uname,
std::string &  realm,
std::string &  upwd 
) const throw (WrongStunBufferFormatException) [inline]

Check message integrity, in secure communications.

Definition at line 738 of file TurnMsgLib.h.

                                                      {
                if(!_constructed || !isCommand())
                        throw WrongStunBufferFormatException();
                return (0 == stun_check_message_integrity_str(_buffer, _sz,
                                (u08bits *)uname.c_str(), (u08bits *)realm.c_str(), (u08bits *)upwd.c_str()));
        }
void turn::StunMsg::construct ( ) [inline]

Initialize buffer

Definition at line 598 of file TurnMsgLib.h.

virtual void turn::StunMsg::constructBuffer ( ) [protected, pure virtual]
u08bits* turn::StunMsg::getRawBuffer ( ) [inline]

get raw buffer

Definition at line 612 of file TurnMsgLib.h.

                                {
                return _buffer;
        }
size_t turn::StunMsg::getSize ( ) const [inline]

Get message size in the buffer (message can be mnuch smaller than the whole buffer)

Definition at line 619 of file TurnMsgLib.h.

                               {
                return _sz;
        }
virtual stun_tid turn::StunMsg::getTid ( ) const throw (WrongStunBufferFormatException) [inline, virtual]

Get transaction ID

Definition at line 709 of file TurnMsgLib.h.

                                                                              {
                if(!_constructed || !isCommand())
                        throw WrongStunBufferFormatException();
                stun_tid tid;
                stun_tid_from_message_str(_buffer,_sz,&tid);
                return tid;
        }
static bool turn::StunMsg::isChallengeResponse ( const u08bits *  buf,
size_t  sz,
int &  err_code,
u08bits *  err_msg,
size_t  err_msg_size,
u08bits *  realm,
u08bits *  nonce 
) [inline, static]

Check if the raw buffer is a challenge response (the one with 401 error and realm and nonce values).

Definition at line 666 of file TurnMsgLib.h.

                                                                        {
                return stun_is_challenge_response_str(buf, sz, &err_code, err_msg, err_msg_size, realm, nonce);
        }
static bool turn::StunMsg::isChannel ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Check if the message is a channel message

Definition at line 675 of file TurnMsgLib.h.

                                                          {
                return is_channel_msg_str(buffer, sz);
        }
static bool turn::StunMsg::isCommand ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Check if the raw buffer is a TURN "command" (request, response or indication).

Definition at line 635 of file TurnMsgLib.h.

                                                          {
                return stun_is_command_message_str(buffer, sz);
        }
bool turn::StunMsg::isCommand ( ) const [inline]

Check if the current message object is a "command" (request, response, or indication).

Definition at line 642 of file TurnMsgLib.h.

static bool turn::StunMsg::isErrorResponse ( u08bits *  buffer,
size_t  sz,
int &  err_code,
u08bits *  err_msg,
size_t  err_msg_size 
) [inline, static]

Definition at line 658 of file TurnMsgLib.h.

                                                                                              {
                return stun_is_error_response_str(buffer, sz, &err_code, err_msg, err_msg_size);
        }
static bool turn::StunMsg::isFingerprintPresent ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Check if the fingerprint is present.

Definition at line 682 of file TurnMsgLib.h.

                                                                     {
                if(!stun_is_command_message_str(buffer,sz))
                        return false;
                stun_attr_ref sar = stun_attr_get_first_by_type_str(buffer, sz, STUN_ATTRIBUTE_FINGERPRINT);
                if(!sar)
                        return false;

                return true;
        }
static bool turn::StunMsg::isIndication ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Definition at line 646 of file TurnMsgLib.h.

                                                             {
                return stun_is_indication_str(buffer, sz);
        }
static bool turn::StunMsg::isRequest ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Definition at line 650 of file TurnMsgLib.h.

                                                          {
                return stun_is_request_str(buffer, sz);
        }
static bool turn::StunMsg::isSuccessResponse ( u08bits *  buffer,
size_t  sz 
) [inline, static]

Definition at line 654 of file TurnMsgLib.h.

                                                                  {
                return stun_is_success_response_str(buffer, sz);
        }
bool turn::StunMsg::isValid ( ) [inline]

Checks if the message is properly constructed

Definition at line 605 of file TurnMsgLib.h.

                       {
                return check();
        }
void turn::StunMsg::setSize ( size_t  sz) throw (WrongStunBufferFormatException) [inline]

Set message size

Definition at line 626 of file TurnMsgLib.h.

                                                                      {
                if(sz>_allocated_sz)
                        throw WrongStunBufferFormatException();
                _sz = sz;
        }
virtual void turn::StunMsg::setTid ( stun_tid tid) throw (WrongStunBufferFormatException) [inline, virtual]

Set transaction ID

Reimplemented in turn::StunMsgResponse.

Definition at line 720 of file TurnMsgLib.h.

                                                                                 {
                if(!_constructed || !isCommand())
                        throw WrongStunBufferFormatException();
                stun_tid_message_cpy(_buffer, &tid);
        }

Member Data Documentation

size_t turn::StunMsg::_allocated_sz [protected]

Definition at line 765 of file TurnMsgLib.h.

u08bits* turn::StunMsg::_buffer [protected]

Definition at line 763 of file TurnMsgLib.h.

bool turn::StunMsg::_constructed [protected]

Definition at line 767 of file TurnMsgLib.h.

bool turn::StunMsg::_deallocate [protected]

Definition at line 764 of file TurnMsgLib.h.

size_t turn::StunMsg::_sz [protected]

Definition at line 766 of file TurnMsgLib.h.


The documentation for this class was generated from the following file: