sipxportlib  Version 3.3
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
StunMessage Class Reference

#include <StunMessage.h>

Inheritance diagram for StunMessage:
Inheritance graph
[legend]

Public Member Functions

 StunMessage (StunMessage *pRequest=NULL, bool bLegacyMode=true)
 
virtual ~StunMessage ()
 
virtual void reset ()
 
virtual bool parse (const char *pBuf, size_t nBufLength)
 
virtual bool encode (char *pBuf, size_t nBufLength, size_t &nActualLength)
 
virtual bool encodeBody (char *pBuf, size_t nBufLength, size_t &nBytesUsed)
 
void setMagicId (STUN_MAGIC_ID &rMagicId)
 
void setTransactionId (STUN_TRANSACTION_ID &rTransactionId)
 
void allocTransactionId ()
 
void setType (uint16_t type)
 
void setMappedAddress (const char *szIp, const uint16_t port)
 
void setResponseAddress (const char *szIp, const uint16_t port)
 
void setChangePort (const bool bChange)
 
void setChangeIp (const bool bChange)
 
void setSourceAddress (const char *szIp, const uint16_t port)
 
void setChangedAddress (const char *szIp, const uint16_t port)
 
void setUsername (const char *szUsername)
 
void setPassword (const char *szPassword)
 
void setRealm (const char *szRealm)
 
void setNonce (const char *szNonce)
 
void setError (const uint16_t code, const char *szReason)
 
void addUnknownAttribute (uint16_t attributeId)
 
void setReflectedFrom (const char *szIp, const uint16_t port)
 
void setServer (const char *szServer)
 
void setRequestXorOnly ()
 
void setSendXorOnly ()
 
void setIncludeMessageIntegrity (bool bInclude)
 
void setIncludeFingerPrint (bool bInclude)
 
void setAltServer (const char *szIp, uint16_t port)
 
void getMagicId (STUN_MAGIC_ID *pMagicId)
 
void getTransactionId (STUN_TRANSACTION_ID *pTransactionId)
 
uint16_t getType ()
 
bool getMappedAddress (char *szIp, uint16_t &rPort)
 
bool getResponseAddress (char *szIp, uint16_t &rPort)
 
bool getChangePort ()
 
bool getChangeIp ()
 
bool getSourceAddress (char *szIp, uint16_t &rPort)
 
bool getChangedAddress (char *szIp, uint16_t &rPort)
 
bool getUsername (char *szUsername)
 
bool getPassword (char *szPassword)
 
bool getRealm (char *szRealm)
 
bool getNonce (char *szNonce)
 
bool getMessageIntegrity (char *cMessageIntegrity)
 
bool getError (uint16_t &rCode, char *szReason)
 
bool getUnknownAttributes (uint16_t *pList, size_t nMaxItems, size_t &nActualItems)
 
bool getReflectedFrom (char *szIp, uint16_t &rPort)
 
bool getServer (char *szServer)
 
bool getUnknownParsedAttributes (uint16_t *pList, size_t nMaxItems, size_t &nActualItems)
 
bool getRequestXorOnly ()
 
bool getAltServer (char *szIp, uint16_t &rPort)
 
bool getFingerPrint (bool &bValid)
 
virtual bool validateMessageType (uint16_t type)
 
virtual bool isRequestOrNonErrorResponse ()
 
virtual bool isMessageIntegrityValid (const char *cPassword, size_t nPassword)
 
virtual bool isFingerPrintValid ()
 

Static Public Member Functions

static bool isStunMessage (const char *pBuf, uint16_t nBufLength)
 
static bool isFingerPrintValid (const char *pBuf, uint16_t nBufLength, bool bMissingOk)
 

Protected Member Functions

bool encodeByte (char c, char *&pBuf, size_t &nBytesLeft)
 
bool encodeShort (uint16_t value, char *&pBuf, size_t &nBytesLeft)
 
bool encodeLong (uint32_t value, char *&pBuf, size_t &nBytesLeft)
 
bool encodeRaw (const char *cRaw, size_t length, char *&pBuf, size_t &nBytesLeft)
 
bool encodeHeader (STUN_MESSAGE_HEADER *pHeader, char *&pBuf, size_t &nBytesLeft)
 
bool encodeAttributeHeader (int16_t type, int16_t length, char *&pBuf, size_t &nBytesLeft)
 
bool encodeAttributeAddress (uint16_t type, STUN_ATTRIBUTE_ADDRESS *pAddress, char *&pBuf, size_t &nBytesLeft)
 
bool encodeXorAttributeAddress (uint16_t type, STUN_ATTRIBUTE_ADDRESS *pAddress, char *&pBuf, size_t &nBytesLeft)
 
bool encodeString (uint16_t type, const char *szString, char *&pBuf, size_t &nBytesLeft)
 
bool encodeAttributeError (STUN_ATTRIBUTE_ERROR *pError, char *&pBuf, size_t &nBytesLeft)
 
bool encodeAttributesUnknown (STUN_ATTRIBUTE_UNKNOWN *pAttributes, char *&pBuf, size_t &nBytesLeft)
 
virtual bool parseAttribute (STUN_ATTRIBUTE_HEADER *pHeader, char *pBuf)
 
bool parseAddressAttribute (char *pBuf, size_t nLength, STUN_ATTRIBUTE_ADDRESS *pAddress)
 
bool parseXorAddressAttribute (char *pBuf, size_t nLength, STUN_ATTRIBUTE_ADDRESS *pAddress)
 
bool parseShortAttribute (char *pBuf, size_t nLength, uint16_t *pShort)
 
bool parseLongAttribute (char *pBuf, size_t nLength, uint32_t *pLong)
 
bool parseStringAttribute (char *pBuf, size_t nLength, char *pString)
 
bool parseRawAttribute (char *pBuf, size_t nLength, char *pDest, size_t nDest)
 
bool parseErrorAttribute (char *pBuf, size_t nLength, STUN_ATTRIBUTE_ERROR *pError)
 
bool parseUnknownAttribute (char *pBuf, size_t nLength, STUN_ATTRIBUTE_UNKNOWN *pAttributes)
 

Static Protected Member Functions

static void calculateHmacSha1 (const char *pDataIn, size_t nDataIn, const char *pKey, size_t nKey, char results[20])
 

Detailed Description

A StunMessage includes all of the parse and encoding for a STUN message as defined by draft-ietf-behave-rfc3489bis-04.txt:

All data is stored internally in host byte order

                    Error
                                Error

Attribute Request Response Response Indication


MAPPED-ADDRESS - C - - USERNAME O - - O PASSWORD - C - - MESSAGE-INTEGRITY O O O O ERROR-CODE - - M - ALTERNATE-SERVER - - C - REALM C - C - NONCE C - C - UNKNOWN-ATTRIBUTES - - C - XOR-MAPPED-ADDRESS - C - - SERVER - O O O REFRESH-INTERVAL - O - - FINGERPRINT M M M M

               Shared   Shared    Shared
               Secret   Secret    Secret

Attribute Request Response Error Response


USERNAME O M - PASSWORD - M - MESSAGE-INTEGRITY O O O ERROR-CODE - - M ALTERNATE-SERVER - - C UNKNOWN-ATTRIBUTES - - C SERVER - O O REALM C - C NONCE C - C

Constructor & Destructor Documentation

StunMessage ( StunMessage pRequest = NULL,
bool  bLegacyMode = true 
)

Default constructor, if a msg is passed, the magic/transaction id is copied – otherwise a new magic/transaction id is generated.

~StunMessage ( )
virtual

Destructor

Member Function Documentation

void reset ( void  )
virtual

Reimplemented in TurnMessage.

bool parse ( const char *  pBuf,
size_t  nBufLength 
)
virtual
bool encode ( char *  pBuf,
size_t  nBufLength,
size_t &  nActualLength 
)
virtual
bool encodeBody ( char *  pBuf,
size_t  nBufLength,
size_t &  nBytesUsed 
)
virtual

Reimplemented in TurnMessage.

void setMagicId ( STUN_MAGIC_ID rMagicId)
void setTransactionId ( STUN_TRANSACTION_ID rTransactionId)
void allocTransactionId ( )
void setType ( uint16_t  type)
void setMappedAddress ( const char *  szIp,
const uint16_t  port 
)
void setResponseAddress ( const char *  szIp,
const uint16_t  port 
)
void setChangePort ( const bool  bChange)
void setChangeIp ( const bool  bChange)
void setSourceAddress ( const char *  szIp,
const uint16_t  port 
)
void setChangedAddress ( const char *  szIp,
const uint16_t  port 
)
void setUsername ( const char *  szUsername)
void setPassword ( const char *  szPassword)
void setRealm ( const char *  szRealm)
void setNonce ( const char *  szNonce)
void setError ( const uint16_t  code,
const char *  szReason 
)
void addUnknownAttribute ( uint16_t  attributeId)
void setReflectedFrom ( const char *  szIp,
const uint16_t  port 
)
void setServer ( const char *  szServer)
void setRequestXorOnly ( )
void setSendXorOnly ( )
void setIncludeMessageIntegrity ( bool  bInclude)
void setIncludeFingerPrint ( bool  bInclude)
void setAltServer ( const char *  szIp,
uint16_t  port 
)
void getMagicId ( STUN_MAGIC_ID pMagicId)
void getTransactionId ( STUN_TRANSACTION_ID pTransactionId)
uint16_t getType ( )
bool getMappedAddress ( char *  szIp,
uint16_t rPort 
)
bool getResponseAddress ( char *  szIp,
uint16_t rPort 
)
bool getChangePort ( )
bool getChangeIp ( )
bool getSourceAddress ( char *  szIp,
uint16_t rPort 
)
bool getChangedAddress ( char *  szIp,
uint16_t rPort 
)
bool getUsername ( char *  szUsername)
bool getPassword ( char *  szPassword)
bool getRealm ( char *  szRealm)
bool getNonce ( char *  szNonce)
bool getMessageIntegrity ( char *  cMessageIntegrity)
bool getError ( uint16_t rCode,
char *  szReason 
)
bool getUnknownAttributes ( uint16_t pList,
size_t  nMaxItems,
size_t &  nActualItems 
)
bool getReflectedFrom ( char *  szIp,
uint16_t rPort 
)
bool getServer ( char *  szServer)
bool getUnknownParsedAttributes ( uint16_t pList,
size_t  nMaxItems,
size_t &  nActualItems 
)
bool getRequestXorOnly ( )
bool getAltServer ( char *  szIp,
uint16_t rPort 
)
bool getFingerPrint ( bool &  bValid)
bool validateMessageType ( uint16_t  type)
virtual

Reimplemented in TurnMessage.

bool isStunMessage ( const char *  pBuf,
uint16_t  nBufLength 
)
static
bool isFingerPrintValid ( const char *  pBuf,
uint16_t  nBufLength,
bool  bMissingOk 
)
static
bool isRequestOrNonErrorResponse ( )
virtual

Reimplemented in TurnMessage.

bool isMessageIntegrityValid ( const char *  cPassword,
size_t  nPassword 
)
virtual
bool isFingerPrintValid ( )
virtual
bool encodeByte ( char  c,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeShort ( uint16_t  value,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeLong ( uint32_t  value,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeRaw ( const char *  cRaw,
size_t  length,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeHeader ( STUN_MESSAGE_HEADER pHeader,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeAttributeHeader ( int16_t  type,
int16_t  length,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeAttributeAddress ( uint16_t  type,
STUN_ATTRIBUTE_ADDRESS pAddress,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeXorAttributeAddress ( uint16_t  type,
STUN_ATTRIBUTE_ADDRESS pAddress,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeString ( uint16_t  type,
const char *  szString,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeAttributeError ( STUN_ATTRIBUTE_ERROR pError,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool encodeAttributesUnknown ( STUN_ATTRIBUTE_UNKNOWN pAttributes,
char *&  pBuf,
size_t &  nBytesLeft 
)
protected
bool parseAttribute ( STUN_ATTRIBUTE_HEADER pHeader,
char *  pBuf 
)
protectedvirtual

Reimplemented in TurnMessage.

bool parseAddressAttribute ( char *  pBuf,
size_t  nLength,
STUN_ATTRIBUTE_ADDRESS pAddress 
)
protected
bool parseXorAddressAttribute ( char *  pBuf,
size_t  nLength,
STUN_ATTRIBUTE_ADDRESS pAddress 
)
protected
bool parseShortAttribute ( char *  pBuf,
size_t  nLength,
uint16_t pShort 
)
protected
bool parseLongAttribute ( char *  pBuf,
size_t  nLength,
uint32_t pLong 
)
protected
bool parseStringAttribute ( char *  pBuf,
size_t  nLength,
char *  pString 
)
protected
bool parseRawAttribute ( char *  pBuf,
size_t  nLength,
char *  pDest,
size_t  nDest 
)
protected
bool parseErrorAttribute ( char *  pBuf,
size_t  nLength,
STUN_ATTRIBUTE_ERROR pError 
)
protected
bool parseUnknownAttribute ( char *  pBuf,
size_t  nLength,
STUN_ATTRIBUTE_UNKNOWN pAttributes 
)
protected
void calculateHmacSha1 ( const char *  pDataIn,
size_t  nDataIn,
const char *  pKey,
size_t  nKey,
char  results[20] 
)
staticprotected

zero pads to 64 boundry and results will be 20 bytes long for hmac/sha1