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

#include <TurnMsgLib.h>

Inheritance diagram for turn::StunMsgResponse:
turn::StunMsg

List of all members.

Public Member Functions

 StunMsgResponse (u16bits method, stun_tid &tid)
 StunMsgResponse (u16bits method, int error_code, std::string reason, stun_tid &tid)
 StunMsgResponse (u08bits *buffer, size_t total_sz, size_t sz, bool constructed) throw (WrongStunBufferFormatException)
u16bits getMethod () const
void setMethod (u16bits method)
int getError () const
void setError (int err)
std::string getReason () const
void setReason (std::string reason)
void setTid (stun_tid &tid) throw (WrongStunBufferFormatException)
stun_tid getTid () throw (WrongStunBufferFormatException)
bool isChallenge (std::string &realm, std::string &nonce) const
bool isChallenge () const
bool isSuccess () const
void constructBindingResponse (stun_tid &tid, const ioa_addr &reflexive_addr, int error_code, const u08bits *reason)
bool isBindingResponse () const
void constructAllocateResponse (stun_tid &tid, const ioa_addr &relayed_addr, const ioa_addr &reflexive_addr, u32bits lifetime, int error_code, const u08bits *reason, u64bits reservation_token)
void constructChannelBindResponse (stun_tid &tid, int error_code, const u08bits *reason)

Protected Member Functions

virtual void constructBuffer ()
virtual bool check ()

Detailed Description

Class for STUN/TURN responses

Definition at line 854 of file TurnMsgLib.h.


Constructor & Destructor Documentation

turn::StunMsgResponse::StunMsgResponse ( u16bits  method,
stun_tid tid 
) [inline]

Definition at line 856 of file TurnMsgLib.h.

: _method(method), _err(0), _reason(""), _tid(tid) {};
turn::StunMsgResponse::StunMsgResponse ( u16bits  method,
int  error_code,
std::string  reason,
stun_tid tid 
) [inline]

Definition at line 857 of file TurnMsgLib.h.

                                                                                         :
                _method(method), _err(error_code), _reason(reason), _tid(tid) {

        };
turn::StunMsgResponse::StunMsgResponse ( u08bits *  buffer,
size_t  total_sz,
size_t  sz,
bool  constructed 
) throw (WrongStunBufferFormatException) [inline]

Definition at line 861 of file TurnMsgLib.h.

                                                      :
                        StunMsg(buffer,total_sz,sz,constructed),_method(0),_err(0),_reason("") {

                if(constructed) {
                        if(!stun_is_success_response_str(buffer,sz)) {
                                u08bits errtxt[0xFFFF];
                                if(!stun_is_error_response_str(buffer,sz,&_err,errtxt,sizeof(errtxt))) {
                                        throw WrongStunBufferFormatException();
                                }
                                _reason = (char*)errtxt;
                        }
                        _method = stun_get_method_str(buffer,sz);
                        stun_tid_from_message_str(_buffer,_sz,&_tid);
                }
        }

Member Function Documentation

virtual bool turn::StunMsgResponse::check ( ) [inline, protected, virtual]

Implements turn::StunMsg.

Definition at line 1009 of file TurnMsgLib.h.

                             {
                if(!_constructed)
                        return false;
                if(!stun_is_success_response_str(_buffer,_sz)) {
                        u08bits errtxt[0xFFFF];
                        int cerr=0;
                        if(!stun_is_error_response_str(_buffer,_sz,&cerr,errtxt,sizeof(errtxt))) {
                                throw WrongStunBufferFormatException();
                        }
                        if(cerr != _err) {
                                throw WrongStunBufferFormatException();
                        }
                }
                if(_method != stun_get_method_str(_buffer,_sz)) {
                        return false;
                }
                return true;
        }
void turn::StunMsgResponse::constructAllocateResponse ( stun_tid tid,
const ioa_addr &  relayed_addr,
const ioa_addr &  reflexive_addr,
u32bits  lifetime,
int  error_code,
const u08bits *  reason,
u64bits  reservation_token 
) [inline]

Construct allocate response

Definition at line 979 of file TurnMsgLib.h.

                                                                      {

                stun_set_allocate_response_str(_buffer, &_sz, &tid,
                                                   &relayed_addr,
                                                   &reflexive_addr,
                                                   lifetime, error_code, reason,
                                                   reservation_token);
        }
void turn::StunMsgResponse::constructBindingResponse ( stun_tid tid,
const ioa_addr &  reflexive_addr,
int  error_code,
const u08bits *  reason 
) [inline]

Construct binding response

Definition at line 963 of file TurnMsgLib.h.

                                                       {

                stun_set_binding_response_str(_buffer, &_sz, &tid,
                                        &reflexive_addr, error_code,
                                        reason);
        }
virtual void turn::StunMsgResponse::constructBuffer ( ) [inline, protected, virtual]

Implements turn::StunMsg.

Definition at line 1000 of file TurnMsgLib.h.

                                       {
                if(_err) {
                        stun_init_error_response_str(_method, _buffer, &_sz, _err, (u08bits*)_reason.c_str(), &_tid);
                } else {
                        stun_init_success_response_str(_method, _buffer, &_sz, &_tid);
                }
                _constructed = true;
        }
void turn::StunMsgResponse::constructChannelBindResponse ( stun_tid tid,
int  error_code,
const u08bits *  reason 
) [inline]

Construct channel bind response

Definition at line 995 of file TurnMsgLib.h.

                                                                                                {
                stun_set_channel_bind_response_str(_buffer, &_sz, &tid, error_code, reason);
        }
int turn::StunMsgResponse::getError ( ) const [inline]

Get error code

Definition at line 889 of file TurnMsgLib.h.

                             {
                return _err;
        }
u16bits turn::StunMsgResponse::getMethod ( ) const [inline]

Definition at line 878 of file TurnMsgLib.h.

                                  {
                return _method;
        }
std::string turn::StunMsgResponse::getReason ( ) const [inline]

Get error message

Definition at line 903 of file TurnMsgLib.h.

                                    {
                return _reason;
        }

Get transaction ID

Definition at line 924 of file TurnMsgLib.h.

                                                                {
                return _tid;
        }

Definition at line 972 of file TurnMsgLib.h.

bool turn::StunMsgResponse::isChallenge ( std::string &  realm,
std::string &  nonce 
) const [inline]

Check if this is a challenge response, and return realm and nonce

Definition at line 931 of file TurnMsgLib.h.

                                                                   {
                bool ret = false;
                if(_constructed) {
                        int err_code;
                        u08bits err_msg[1025];
                        size_t err_msg_size=sizeof(err_msg);
                        u08bits srealm[0xFFFF];
                        u08bits snonce[0xFFFF];
                        ret = stun_is_challenge_response_str(_buffer, _sz, &err_code, err_msg, err_msg_size, srealm, snonce);
                        if(ret) {
                                realm = (char*)srealm;
                                nonce = (char*)snonce;
                        }
                }
                return ret;
        }
bool turn::StunMsgResponse::isChallenge ( ) const [inline]

Definition at line 948 of file TurnMsgLib.h.

                                 {
                std::string realm, nonce;
                return isChallenge(realm, nonce);
        }
bool turn::StunMsgResponse::isSuccess ( ) const [inline]

Check if this is a success response

Definition at line 956 of file TurnMsgLib.h.

                               {
                return (_err == 0);
        }
void turn::StunMsgResponse::setError ( int  err) [inline]

Set error code

Definition at line 896 of file TurnMsgLib.h.

                               {
                _err = err;
        }
void turn::StunMsgResponse::setMethod ( u16bits  method) [inline]

Definition at line 882 of file TurnMsgLib.h.

                                       {
                _method = method;
        }
void turn::StunMsgResponse::setReason ( std::string  reason) [inline]

Set error message

Definition at line 910 of file TurnMsgLib.h.

                                         {
                _reason = reason;
        }
void turn::StunMsgResponse::setTid ( stun_tid tid) throw (WrongStunBufferFormatException) [inline, virtual]

Set transaction ID

Reimplemented from turn::StunMsg.

Definition at line 917 of file TurnMsgLib.h.

                                                                         {
                _tid = tid;
        }

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