PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pstunsrvr.h
Go to the documentation of this file.
1 /*
2  * pstunsrvr.h
3  *
4  * STUN server
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 2011 Post Increment.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Tools Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 31270 $
27  * $Author: rjongbloed $
28  * $Date$
29  */
30 
31 #ifndef PTLIB_PSTUNSRVR_H
32 #define PTLIB_PSTUNSRVR_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptlib.h>
39 
40 #if P_STUNSRVR
41 
42 #include <ptclib/pstun.h>
43 
44 
45 class PSTUNServer : public PObject, public PSTUN
46 {
47  PCLASSINFO(PSTUNServer, PObject)
48  public:
49  PSTUNServer();
50 
51  bool Open(WORD port = DefaultPort);
52  bool Open(PUDPSocket * socket1, PUDPSocket * socket2 = NULL);
53 
54  bool IsOpen() const;
55 
56  bool Close();
57 
58  struct SocketInfo {
59  SocketInfo(PUDPSocket * socket = NULL);
60 
61  PUDPSocket * m_socket;
62  PIPSocketAddressAndPort m_socketAddress;
63  PIPSocketAddressAndPort m_alternateAddressAndPort;
64 
65  PUDPSocket * m_alternatePortSocket;
66  PUDPSocket * m_alternateAddressSocket;
67  PUDPSocket * m_alternateAddressAndPortSocket;
68  };
69 
70  virtual bool Read(
71  PSTUNMessage & message,
72  SocketInfo & socketInfo
73  );
74 
75  virtual bool Process();
76 
77  virtual bool OnReceiveMessage(
78  const PSTUNMessage & message,
79  const SocketInfo & socketInfo
80  );
81 
82  virtual bool OnBindingRequest(
83  const PSTUNMessage & request,
84  const SocketInfo & socketInfo
85  );
86 
87  virtual bool OnUnknownRequest(
88  const PSTUNMessage & request,
89  const SocketInfo & socketInfo
90  );
91 
92  protected:
93  void PopulateInfo(PUDPSocket * socket, const PIPSocket::Address & alternateAddress, WORD alternatePort,
94  PUDPSocket * alternatePortSocket, PUDPSocket * alternateAddressSocket, PUDPSocket * alternateAddressAndPortSocket);
95 
96  SocketInfo * CreateAndAddSocket(const PIPSocket::Address & addess, WORD port);
97 
98  typedef std::map<PUDPSocket *, SocketInfo> SocketToSocketInfoMap;
99  SocketToSocketInfoMap m_socketToSocketInfoMap;
100  PSocket::SelectList m_sockets;
101  PSocket::SelectList m_selectList;
102 
103  bool m_autoDelete;
104 };
105 
106 
107 #endif // P_STUNSRVR
108 
109 #endif // PTLIB_PSTUNSRVR_H