sipxtacklib  Version 3.3
SipUdpServer.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 SIPfoundry Inc.
3 // Licensed by SIPfoundry under the LGPL license.
4 //
5 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
6 // Licensed to SIPfoundry under a Contributor Agreement.
7 //
8 // $$
10 
11 #ifndef _SipUdpServer_h_
12 #define _SipUdpServer_h_
13 
14 // SYSTEM INCLUDES
15 // APPLICATION INCLUDES
17 #include <os/OsNatKeepaliveListener.h>
18 #include <utl/UtlSList.h>
19 #include <os/OsRWMutex.h>
20 
21 // DEFINES
22 // MACROS
23 // EXTERNAL FUNCTIONS
24 // EXTERNAL VARIABLES
25 // CONSTANTS
26 // STRUCTS
27 // TYPEDEFS
28 // FORWARD DECLARATIONS
29 class SipUserAgent;
30 class OsNatDatagramSocket ;
31 class OsNotification ;
32 class OsTimer;
33 
34 
53 {
54 /* //////////////////////////// PUBLIC //////////////////////////////////// */
55 public:
56 
57 /* ============================ CREATORS ================================== */
58 
59  SipUdpServer(int sipPort = SIP_PORT,
60  SipUserAgent* userAgent = NULL,
61  int udpReadBufferSize = -1,
62  UtlBoolean bUseNextAvailablePort = FALSE,
63  const char* szBoundIp = NULL);
64  //:Default constructor
65 
66 
67  virtual
68  ~SipUdpServer();
69  //:Destructor
70 
71 /* ============================ MANIPULATORS ============================== */
72 
73  int run(void* pArg);
74 
75  void shutdownListener();
76 
77  void enableStun(const char* szStunServer,
78  int iStunPort,
79  const char* szLocalIp,
80  int refreshPeriodInSecs,
81  OsNotification* pNotification) ;
82  //:Enable stun lookups for UDP signaling
83  // Use a NULL szStunServer to disable
84 
85  UtlBoolean sendTo(const SipMessage& message,
86  const char* address,
87  int port,
88  const char* szLocalSipIp = NULL);
89 
90  UtlBoolean addCrLfKeepAlive(const char* szLocalIp,
91  const char* szRemoteIp,
92  const int remotePort,
93  const int keepAliveSecs,
94  OsNatKeepaliveListener* pListener) ;
95 
96  UtlBoolean removeCrLfKeepAlive(const char* szLocalIp,
97  const char* szRemoteIp,
98  const int remotePort) ;
99 
100  UtlBoolean addStunKeepAlive(const char* szLocalIp,
101  const char* szRemoteIp,
102  const int remotePort,
103  const int keepAliveSecs,
104  OsNatKeepaliveListener* pListener) ;
105 
106  UtlBoolean removeStunKeepAlive(const char* szLocalIp,
107  const char* szRemoteIp,
108  const int remotePort) ;
109 
110  UtlBoolean addSipKeepAlive(const char* szLocalIp,
111  const char* szRemoteIp,
112  const int remotePort,
113  const char* szMethod,
114  const int keepAliveSecs,
115  OsNatKeepaliveListener* pListener) ;
116 
117  UtlBoolean removeSipKeepAlive(const char* szLocalIp,
118  const char* szRemoteIp,
119  const int remotePort,
120  const char* szMethod) ;
121 
122  void updateSipKeepAlive(const char* szLocalIp,
123  const char* szMethod,
124  const char* szRemoteIp,
125  const int remotePort,
126  const char* szContactIp,
127  const int contactPort) ;
128 
129 
130  void sendSipKeepAlive(OsTimer* pTimer) ;
131 
132  static void SipKeepAliveCallback(const intptr_t userData,
133  const intptr_t eventData) ;
134 
135 /* ============================ ACCESSORS ================================= */
136 
137  void printStatus();
138 
139  int getServerPort(const char* szLocalIp = NULL) ;
140 
141  UtlBoolean getStunAddress(UtlString* pIpAddress,
142  int* pPort,
143  const char* szLocalIp = NULL) ;
144 
145  UtlBoolean addKeepAliveBinding(void* pBinding) ;
146  UtlBoolean removeKeepAliveBinding(void* pBinding) ;
147 
148  void* findKeepAliveBinding(OsTimer* pTimer) ;
149 
150  void* findKeepAliveBinding(OsSocket* pSocket,
151  const char* szRemoteIp,
152  const int remotePort,
153  const char* szMethod) ;
154 
155 
156 /* ============================ INQUIRY =================================== */
157 
158 
159 /* //////////////////////////// PROTECTED ///////////////////////////////// */
160 protected:
161 
162  OsSocket* buildClientSocket(int hostPort,
163  const char* hostAddress,
164  const char* localIp);
165 
166  OsMutex mMapLock;
167 
168 /* //////////////////////////// PRIVATE /////////////////////////////////// */
169 private:
170 
171  UtlString mStunServer ;
172  int mStunRefreshSecs ;
173  int mStunPort ;
174  UtlSList mSipKeepAliveBindings ;
175  OsRWMutex mKeepAliveMutex ;
176 
177  OsStatus createServerSocket(const char* localIp,
178  int& localPort,
179  const UtlBoolean& bUseNextAvailablePort,
180  int udpReadBufferSize);
181 
182  SipUdpServer(const SipUdpServer& rSipUdpServer);
183  //: disable Copy constructor
184 
185  SipUdpServer& operator=(const SipUdpServer& rhs);
186  //:disable Assignment operator
187 
188 
189 };
190 
191 /* ============================ INLINE METHODS ============================ */
192 
193 #endif // _SipUdpServer_h_
Transaction and Transport manager for SIP stack.
Definition: SipUserAgent.h:157
The SipUdpServer is owner/container of the sockets used for UDP communications.
Definition: SipUdpServer.h:52
UtlBoolean getStunAddress(UtlString *pIpAddress, int *pPort, const char *szLocalIp=NULL)
Definition: SipUdpServer.cpp:881
void printStatus()
Definition: SipUdpServer.cpp:823
UtlBoolean removeKeepAliveBinding(void *pBinding)
Definition: SipUdpServer.cpp:935
UtlBoolean removeStunKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort)
Definition: SipUdpServer.cpp:645
Definition: SipProtocolServerBase.h:40
void updateSipKeepAlive(const char *szLocalIp, const char *szMethod, const char *szRemoteIp, const int remotePort, const char *szContactIp, const int contactPort)
Definition: SipUdpServer.cpp:782
Specialization of HttpMessage to contain and manipulate SIP messages.
Definition: SipMessage.h:343
UtlBoolean addStunKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort, const int keepAliveSecs, OsNatKeepaliveListener *pListener)
Definition: SipUdpServer.cpp:607
void shutdownListener()
Definition: SipUdpServer.cpp:442
UtlBoolean removeSipKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort, const char *szMethod)
Definition: SipUdpServer.cpp:740
#define SIP_PORT
Definition: SipMessage.h:256
void * findKeepAliveBinding(OsTimer *pTimer)
Definition: SipUdpServer.cpp:946
static void SipKeepAliveCallback(const intptr_t userData, const intptr_t eventData)
Definition: SipUdpServer.cpp:1089
SipUdpServer(int sipPort=SIP_PORT, SipUserAgent *userAgent=NULL, int udpReadBufferSize=-1, UtlBoolean bUseNextAvailablePort=FALSE, const char *szBoundIp=NULL)
Definition: SipUdpServer.cpp:179
OsSocket * buildClientSocket(int hostPort, const char *hostAddress, const char *localIp)
Definition: SipUdpServer.cpp:504
UtlBoolean addCrLfKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort, const int keepAliveSecs, OsNatKeepaliveListener *pListener)
Definition: SipUdpServer.cpp:535
UtlBoolean addKeepAliveBinding(void *pBinding)
Definition: SipUdpServer.cpp:918
virtual ~SipUdpServer()
Definition: SipUdpServer.cpp:231
int getServerPort(const char *szLocalIp=NULL)
Definition: SipUdpServer.cpp:852
UtlBoolean addSipKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort, const char *szMethod, const int keepAliveSecs, OsNatKeepaliveListener *pListener)
Definition: SipUdpServer.cpp:679
UtlBoolean sendTo(const SipMessage &message, const char *address, int port, const char *szLocalSipIp=NULL)
Definition: SipUdpServer.cpp:462
void enableStun(const char *szStunServer, int iStunPort, const char *szLocalIp, int refreshPeriodInSecs, OsNotification *pNotification)
Definition: SipUdpServer.cpp:357
int run(void *pArg)
Definition: SipUdpServer.cpp:349
void sendSipKeepAlive(OsTimer *pTimer)
Definition: SipUdpServer.cpp:990
UtlBoolean removeCrLfKeepAlive(const char *szLocalIp, const char *szRemoteIp, const int remotePort)
Definition: SipUdpServer.cpp:573
OsMutex mMapLock
Definition: SipUdpServer.h:166

sipXtackLib home page