sipxportlib  Version 3.3
TurnMessage.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2006 Robert J. Andreasen, Jr.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // Copyright (C) 2004-2006 SIPfoundry Inc.
9 // Licensed by SIPfoundry under the LGPL license.
10 //
11 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
12 // Licensed to SIPfoundry under a Contributor Agreement.
13 //
14 // $$
16 
17 #ifndef _TurnMessage_h_
18 #define _TurnMessage_h_
19 
20 // SYSTEM INCLUDES
21 // APPLICATION INCLUDES
22 #include "os/OsIntTypes.h"
23 #include "os/StunMessage.h"
24 
25 // DEFINES
26 
30 #define MSG_TURN_ALLOCATE_REQUEST 0x0003
31 #define MSG_TURN_ALLOCATE_RESPONSE 0x0103
32 #define MSG_TURN_ALLOCATE_ERROR_RESPONSE 0x0113
33 #define MSG_TURN_SEND_REQUEST 0x0004
34 #define MSG_TURN_SEND_RESPONSE 0x0104 // deprecated
35 #define MSG_TURN_SEND_ERROR_RESPONSE 0x0114 // deprecated
36 #define MSG_TURN_DATA_INDICATION 0x0115
37 #define MSG_TURN_ACTIVE_DESTINATION_REQUEST 0x0006
38 #define MSG_TURN_ACTIVE_DESTINATION_RESPONSE 0x0106
39 #define MSG_TURN_ACTIVE_DESTINATION_ERROR_RESPONSE 0x0116
40 #define MSG_TURN_CONNECTION_STATUS_INDICATION 0x0117
41 #define MSG_TURN_CLOSE_BINDING_REQUEST 0x0009
42 #define MSG_TURN_CLOSE_BINDING_RESPONSE 0x0109
43 #define MSG_TURN_CLOSE_BINDING_ERROR_RESPONSE 0x0119
44 
45 
49 #define ATTR_TURN_LIFETIME 0x000D
50 #define ATTR_TURN_MAGIC_COOKIE 0x000F // deprecated
51 #define ATTR_TURN_BANDWIDTH 0x0010
52 #define ATTR_TURN_DESTINATION_ADDRESS 0x0011 // deprecated
53 #define ATTR_TURN_REMOTE_ADDRESS 0x0012 // rename from ATTR_TURN_SOURCE_ADDRESS
54 #define ATTR_TURN_DATA 0x0013
55 #define ATTR_TURN_RELAY_ADDRESS 0x0016
56 #define ATTR_TURN_REQUESTED_PORT 0x0018
57 #define ATTR_TURN_REQUESTED_TRANSPORT 0x0019
58 //#define ATTR_TURN_TIMER_VAL 0x0021
59 #define ATTR_TURN_REQUESTED_IP 0x0022
60 
61 #define ATTR_MAGIC_COOKIE 0x72c64bc6
62 
63 // Error Defines
64 #define TURN_ERROR_NO_BINDING_CODE 437
65 #define TURN_ERROR_NO_BINDING_TEXT "no binding"
66 
67 #define TURN_ERROR_TRANSITIONING_CODE 439
68 #define TURN_ERROR_TRANSITIONING_TEXT "transitioning"
69 
70 #define TURN_ERROR_WRONG_USERNAME_CODE 441
71 #define TURN_ERROR_WRONG_USERNAME_TEXT "wrong username"
72 
73 #define TURN_ERROR_TRANSPORT_PROTOCOL_CODE 442
74 #define TURN_ERROR_TRANSPORT_PROTOCOL_TEXT "bad transport"
75 
76 #define TURN_ERROR_INVALID_IP_CODE 443
77 #define TURN_ERROR_INVALID_IP_TEXT "invalid ip"
78 
79 #define TURN_ERROR_INVALID_PORT_CODE 444
80 #define TURN_ERROR_INVALID_PORT_TEXT "invalid port"
81 
82 #define TURN_ERROR_TCP_ONLY_CODE 445
83 #define TURN_ERROR_TCP_ONLY_TEXT "tcp only"
84 
85 #define TURN_ERROR_CONNECTION_FAILED_CODE 446
86 #define TURN_ERROR_CONNECTION_FAILED_TEXT "connection failed"
87 
88 #define TURN_ERROR_CONNECTION_TIMEOUT_CODE 447
89 #define TURN_ERROR_CONNECTION_TIMEOUT_TEXT "connection timeout"
90 
91 // MACROS
92 // EXTERNAL FUNCTIONS
93 // EXTERNAL VARIABLES
94 // CONSTANTS
95 // STRUCTS
96 // TYPEDEFS
97 typedef enum TURN_TRANSPORT_TYPE
98 {
102 
103 // FORWARD DECLARATIONS
104 
107 class TurnMessage : public StunMessage
108 {
109 /* //////////////////////////// PUBLIC //////////////////////////////////// */
110  public:
111 
112 /* ============================ CREATORS ================================== */
113 
117  TurnMessage(TurnMessage* pRequest = NULL,
118  bool bLegacyMode = true) ;
119 
123  virtual ~TurnMessage();
124 
125 /* ============================ MANIPULATORS ============================== */
126 
127  virtual void reset() ;
128 
129  virtual bool encodeBody(char* pBuf, size_t nBufLength, size_t& nBytesUsed) ;
130 
131  void setLifetime(uint32_t secs) ;
132 
133  void setBandwidth(uint32_t rKBPS) ;
134 
136  void setDestinationAddress(const char* szIp, uint16_t port) ;
137 
138  void setTurnRemoteAddress(const char* szIp, uint16_t port) ;
139 
140  void setData(const char* pData, uint16_t nLength) ;
141 
142  void setRelayAddress(const char* szIp, uint16_t port) ;
143 
144  void setRequestedTransport(TURN_TRANSPORT_TYPE transportType) ;
145 
146  void setRequestedIp(const char* szIp, uint16_t port) ;
147 
148 /* ============================ ACCESSORS ================================= */
149 
150  bool getLifetime(uint32_t& rSecs) ;
151 
152  bool getBandwidth(uint32_t& rKBPS) ;
153 
155  bool getDestinationAddress(char* szIp, uint16_t& rPort) ;
156 
157  bool getTurnRemoteAddress(char* szIp, uint16_t& rPort) ;
158 
159  bool getData(char*& rpData, uint16_t& nLength) ;
160 
161  bool getRelayAddress(char* szIp, uint16_t& rPort) ;
162 
163  bool getRequestedTransport(TURN_TRANSPORT_TYPE& rTransportType) ;
164 
165  bool getRequestedIp(char* szIp, uint16_t& rPort) ;
166 
167 /* ============================ INQUIRY =================================== */
168 
169  virtual bool validateMessageType(uint16_t type) ;
170 
171  static bool isTurnMessage(const char* pBuf,
172  uint16_t nBufLength,
173  bool* pbDataIndication = NULL) ;
174 
175  virtual bool isRequestOrNonErrorResponse() ;
176 
177 /* //////////////////////////// PROTECTED ///////////////////////////////// */
178  protected:
179 
180  virtual bool parseAttribute(STUN_ATTRIBUTE_HEADER* pHeader, char* pBuf) ;
181 
182  bool encodeAttributeLong(uint16_t type,
183  uint32_t value,
184  char*& pBuf,
185  size_t& nBytesLeft) ;
186 
187  bool encodeAttributeRaw(uint16_t type,
188  const char* cBuf,
189  size_t length,
190  char*& pBuf,
191  size_t& nBytesLeft) ;
192 
193 /* //////////////////////////// PRIVATE /////////////////////////////////// */
194  private:
195  uint32_t mLifetime ; // ATTR_TURN_LIFETIME
196  bool mbLifetimeValid ;
197 
198  uint32_t mBandwidth ; // ATTR_TURN_BANDWIDTH
199  bool mbBandwidthValid ;
200 
201  STUN_ATTRIBUTE_ADDRESS mDestinationAddress ; // ATTR_TURN_DESTINATION_ADDRESS
202  bool mbDestinationAddressValid ;
203 
204  STUN_ATTRIBUTE_ADDRESS mTurnRemoteAddress ; // ATTR_TURN_REMOTE_ADDRESS
205  bool mbTurnRemoteAddressValid ;
206 
207  char* mszTurnData ; // ATTR_TURN_DATA
208  size_t mnTurnData ;
209  bool mbTurnDataValid ;
210 
211  STUN_ATTRIBUTE_ADDRESS mRelayAddress ; // ATTR_TURN_RELAY_ADDRESS
212  bool mbRelayAddressValid ;
213 
214  uint32_t mTransport ; // ATTR_TURN_REQUESTED_TRANSPORT
215  bool mbTransportValid ;
216 
217  STUN_ATTRIBUTE_ADDRESS mRequestedIp ; // ATTR_TURN_REQUESTED_IP
218  bool mbRequestedIpValid ;
219 
221  TurnMessage(const TurnMessage& rTurnMessage);
222 
224  TurnMessage& operator=(const TurnMessage& rhs);
225 
226 
227 };
228 
229 /* ============================ INLINE METHODS ============================ */
230 
231 #endif // _TurnMessage_h_
void setBandwidth(uint32_t rKBPS)
Definition: TurnMessage.cpp:200
Definition: TurnMessage.h:100
virtual bool parseAttribute(STUN_ATTRIBUTE_HEADER *pHeader, char *pBuf)
Definition: TurnMessage.cpp:500
bool getRequestedTransport(TURN_TRANSPORT_TYPE &rTransportType)
Definition: TurnMessage.cpp:335
Include this file if you want use C99 integer types with specified width and corresponding set of mac...
bool getLifetime(uint32_t &rSecs)
Definition: TurnMessage.cpp:265
void setRequestedIp(const char *szIp, uint16_t port)
Definition: TurnMessage.cpp:254
virtual void reset()
Definition: TurnMessage.cpp:90
Definition: StunMessage.h:138
virtual bool isRequestOrNonErrorResponse()
Definition: TurnMessage.cpp:465
unsigned short uint16_t
Definition: stdint.h:79
virtual bool validateMessageType(uint16_t type)
Definition: TurnMessage.cpp:361
#define NULL
Definition: UtlDefs.h:29
void setDestinationAddress(const char *szIp, uint16_t port)
Definition: TurnMessage.cpp:206
void setLifetime(uint32_t secs)
Definition: TurnMessage.cpp:193
bool getRequestedIp(char *szIp, uint16_t &rPort)
Definition: TurnMessage.cpp:346
void setData(const char *pData, uint16_t nLength)
Definition: TurnMessage.cpp:222
unsigned int uint32_t
Definition: stdint.h:80
TURN_TRANSPORT_TYPE
Definition: TurnMessage.h:97
bool getTurnRemoteAddress(char *szIp, uint16_t &rPort)
Definition: TurnMessage.cpp:298
bool encodeAttributeRaw(uint16_t type, const char *cBuf, size_t length, char *&pBuf, size_t &nBytesLeft)
Definition: TurnMessage.cpp:586
bool getData(char *&rpData, uint16_t &nLength)
Definition: TurnMessage.cpp:310
void setRelayAddress(const char *szIp, uint16_t port)
Definition: TurnMessage.cpp:236
virtual ~TurnMessage()
Definition: TurnMessage.cpp:80
Definition: TurnMessage.h:99
virtual bool encodeBody(char *pBuf, size_t nBufLength, size_t &nBytesUsed)
Definition: TurnMessage.cpp:119
Definition: StunMessage.h:144
void setRequestedTransport(TURN_TRANSPORT_TYPE transportType)
Definition: TurnMessage.cpp:245
static bool isTurnMessage(const char *pBuf, uint16_t nBufLength, bool *pbDataIndication=NULL)
Definition: TurnMessage.cpp:392
bool getBandwidth(uint32_t &rKBPS)
Definition: TurnMessage.cpp:275
bool getDestinationAddress(char *szIp, uint16_t &rPort)
Definition: TurnMessage.cpp:286
Definition: TurnMessage.h:107
TurnMessage(TurnMessage *pRequest=NULL, bool bLegacyMode=true)
Definition: TurnMessage.cpp:49
bool encodeAttributeLong(uint16_t type, uint32_t value, char *&pBuf, size_t &nBytesLeft)
Definition: TurnMessage.cpp:572
void setTurnRemoteAddress(const char *szIp, uint16_t port)
Definition: TurnMessage.cpp:214
Definition: StunMessage.h:211
bool getRelayAddress(char *szIp, uint16_t &rPort)
Definition: TurnMessage.cpp:322