PTLib  Version 2.12.9
 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: 30364 $
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 <ptbuildopts.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 
53  bool IsOpen() const;
54 
55  bool Close();
56 
57  struct SocketInfo {
58  SocketInfo();
59 
60  PUDPSocket * m_socket;
61  PIPSocketAddressAndPort m_socketAddress;
62  PIPSocketAddressAndPort m_alternateAddressAndPort;
63 
64  PUDPSocket * m_alternatePortSocket;
65  PUDPSocket * m_alternateAddressSocket;
66  PUDPSocket * m_alternateAddressAndPortSocket;
67  };
68 
69  virtual bool Read(
70  PSTUNMessage & message,
71  SocketInfo & socketInfo
72  );
73 
74  virtual bool Process(
75  const PSTUNMessage & message,
76  SocketInfo & socketInfo
77  );
78 
79  virtual bool OnBindingRequest(
80  const PSTUNMessage & request,
81  SocketInfo & socketInfo
82  );
83 
84  virtual bool OnUnknownRequest(
85  const PSTUNMessage & request,
86  SocketInfo & socketInfo
87  );
88 
89  bool WriteTo(const PSTUNMessage & message, PUDPSocket & socket, const PIPSocketAddressAndPort & dest);
90 
91  protected:
92  void PopulateInfo(PUDPSocket * socket, const PIPSocket::Address & alternateAddress, WORD alternatePort,
93  PUDPSocket * alternatePortSocket, PUDPSocket * alternateAddressSocket, PUDPSocket * alternateAddressAndPortSocket);
94 
95  SocketInfo * CreateAndAddSocket(const PIPSocket::Address & addess, WORD port);
96 
97  PSocket::SelectList m_sockets;
98  PSocket::SelectList m_selectList;
99  typedef std::map<PUDPSocket *, SocketInfo> SocketToSocketInfoMap;
100  SocketToSocketInfoMap m_socketToSocketInfoMap;
101 
102  bool m_autoDelete;
103 };
104 
105 
106 #endif // P_STUNSRVR
107 
108 #endif // PTLIB_PSTUNSRVR_H