Wolframe, 0.0.3

connectionEndpoint.hpp
Go to the documentation of this file.
1 /************************************************************************
2 
3  Copyright (C) 2011 - 2014 Project Wolframe.
4  All rights reserved.
5 
6  This file is part of Project Wolframe.
7 
8  Commercial Usage
9  Licensees holding valid Project Wolframe Commercial licenses may
10  use this file in accordance with the Project Wolframe
11  Commercial License Agreement provided with the Software or,
12  alternatively, in accordance with the terms contained
13  in a written agreement between the licensee and Project Wolframe.
14 
15  GNU General Public License Usage
16  Alternatively, you can redistribute this file and/or modify it
17  under the terms of the GNU General Public License as published by
18  the Free Software Foundation, either version 3 of the License, or
19  (at your option) any later version.
20 
21  Wolframe is distributed in the hope that it will be useful,
22  but WITHOUT ANY WARRANTY; without even the implied warranty of
23  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  GNU General Public License for more details.
25 
26  You should have received a copy of the GNU General Public License
27  along with Wolframe. If not, see <http://www.gnu.org/licenses/>.
28 
29  If you have questions regarding the use of this file, please contact
30  Project Wolframe.
31 
32 ************************************************************************/
35 
36 #ifndef _CONNECTION_ENDPOINT_HPP_INCLUDED
37 #define _CONNECTION_ENDPOINT_HPP_INCLUDED
38 
39 #include <string>
40 #include <vector>
41 #include <sstream>
42 #include <ctime>
43 #include <boost/algorithm/string.hpp>
44 #include <boost/shared_ptr.hpp>
45 
46 namespace _Wolframe {
47 namespace net {
48 
51 {
52 public:
54  UDP,
55  TCP,
57  };
58  static const char* connectionTypeName( ConnectionType t)
59  {
60  static const char* ar[] = {"UDP","TCP","SSL"};
61  return ar[t];
62  }
63 
64  enum EndPoint {
67  };
68 
69  ConnectionEndpoint( const std::string& Host, unsigned short Port )
70  : m_host( Host ), m_port( Port ) {}
71 
72  virtual ~ConnectionEndpoint( ) {}
73 
74  const std::string& host() const { return m_host; }
75  unsigned short port() const { return m_port; }
76  virtual ConnectionType type() const = 0;
77  virtual EndPoint endpoint() const = 0;
78 
79  std::string toString() const
80  {
81  std::ostringstream o;
82  o << m_host << ":" << m_port;
83  return o.str();
84  }
85 
86 private:
87  void operator=( const ConnectionEndpoint& ) {}
88 private:
89  std::string m_host;
90  unsigned short m_port;
91 };
92 
95 {
97  {
99  Request=0x2
100  };
102  {
103  static const char* ar[] = {0,"PasswordChange","Request"};
104  return ar[c];
105  }
106 
107  std::vector<std::string> capabilities;
108  std::string socketIdentifier;
109  std::string protocol;
110 
113  :capabilities(0xFFFF){}
118  explicit LocalEndpointConfig( const std::string& socketIdentifier_)
119  :capabilities(0xFFFF),socketIdentifier(socketIdentifier_){}
120 
123  {
124  capabilities.clear();
125  }
127  void setCapability( const std::string& c)
128  {
129  capabilities.push_back( c);
130  }
132  bool hasCapability( const std::string& c) const
133  {
134  std::vector<std::string>::const_iterator ci = capabilities.begin(), ce = capabilities.end();
135  for (; ci != ce; ++ci)
136  {
137  if (boost::algorithm::iequals( *ci, c)) return true;
138  }
139  return false;
140  }
141 };
142 
145 {
146 public:
147  LocalEndpoint( const std::string& Host, unsigned short Port, const LocalEndpointConfig& Config=LocalEndpointConfig())
148  : ConnectionEndpoint( Host, Port ), m_config( Config )
149  {
150  m_creationTime = time( NULL );
151  }
152 
153  virtual ConnectionType type() const = 0;
154  EndPoint endpoint() const { return LOCAL_ENDPOINT; }
155  time_t creationTime() const { return m_creationTime; }
156  const LocalEndpointConfig& config() const { return m_config; }
157 
158 private:
160  time_t m_creationTime;
161 };
162 
163 typedef boost::shared_ptr<LocalEndpoint> LocalEndpointR;
164 
165 
168 {
169 public:
170  LocalTCPendpoint( const std::string& Host, unsigned short Port, const LocalEndpointConfig& Config=LocalEndpointConfig())
171  : LocalEndpoint( Host, Port, Config ) {}
172 
173  ConnectionType type() const { return TCP; }
174 };
175 
176 #ifdef WITH_SSL
177 class LocalSSLendpoint : public LocalEndpoint
179 {
180 public:
181  LocalSSLendpoint( const std::string& Host, unsigned short Port, const LocalEndpointConfig& Config=LocalEndpointConfig())
182  : LocalEndpoint( Host, Port, Config ) {}
183 
184  ConnectionType type() const { return SSL; }
185 };
186 #endif // WITH_SSL
187 
188 
191 {
192 public:
193  RemoteEndpoint( const std::string& Host, unsigned short Port )
194  : ConnectionEndpoint( Host, Port )
195  {
196  m_connectionTime = time( NULL );
197  }
198 
199  virtual ConnectionType type() const = 0;
200  EndPoint endpoint() const { return REMOTE_ENDPOINT; }
201 
202  time_t connectionTime() const { return m_connectionTime; }
203 
204 private:
206 };
207 
208 typedef boost::shared_ptr<RemoteEndpoint> RemoteEndpointR;
209 
210 
213 {
214 public:
215  RemoteTCPendpoint( const std::string& Host, unsigned short Port )
216  : RemoteEndpoint( Host, Port ) {}
217 
218  ConnectionType type() const { return TCP; }
219 };
220 
221 #ifdef WITH_SSL
222 class SSLcertificateInfo;
224 
226 class RemoteSSLendpoint : public RemoteEndpoint
227 {
228 public:
229  RemoteSSLendpoint( const std::string& Host, unsigned short Port )
230  : RemoteEndpoint( Host, Port ), m_SSLinfo( NULL ) {}
231 
232  RemoteSSLendpoint( const std::string& Host, unsigned short Port,
233  const SSLcertificateInfo *SSLinfo )
234  : RemoteEndpoint( Host, Port ), m_SSLinfo( SSLinfo ) {}
235 
236  ConnectionType type() const { return SSL; }
237 
239  const SSLcertificateInfo* SSLcertInfo() const { return m_SSLinfo; }
240 
241 private:
242  const SSLcertificateInfo *m_SSLinfo;
243 };
244 #endif // WITH_SSL
245 
246 }} // namespace _Wolframe::net
247 
248 #endif // _CONNECTION_ENDPOINT_HPP_INCLUDED
std::string protocol
Definition: connectionEndpoint.hpp:109
LocalEndpoint(const std::string &Host, unsigned short Port, const LocalEndpointConfig &Config=LocalEndpointConfig())
Definition: connectionEndpoint.hpp:147
Definition: connectionEndpoint.hpp:55
void setCapability(const std::string &c)
Set a capability for this local endpoint configuration.
Definition: connectionEndpoint.hpp:127
the user is allowed make requests
Definition: connectionEndpoint.hpp:99
unsigned short m_port
Definition: connectionEndpoint.hpp:90
LocalEndpointConfig(const LocalEndpointConfig &o)
Copy constructor.
Definition: connectionEndpoint.hpp:115
time_t m_creationTime
time when object has been constructed
Definition: connectionEndpoint.hpp:160
the user is allowed to change his password
Definition: connectionEndpoint.hpp:98
LocalTCPendpoint(const std::string &Host, unsigned short Port, const LocalEndpointConfig &Config=LocalEndpointConfig())
Definition: connectionEndpoint.hpp:170
time_t m_connectionTime
Definition: connectionEndpoint.hpp:205
Definition: connectionEndpoint.hpp:54
EndPoint endpoint() const
Definition: connectionEndpoint.hpp:200
LocalEndpointConfig()
Default constructor.
Definition: connectionEndpoint.hpp:112
ConnectionType type() const
Definition: connectionEndpoint.hpp:173
virtual ConnectionType type() const =0
LocalEndpointConfig m_config
configuration for authorization checks
Definition: connectionEndpoint.hpp:159
ConnectionEndpoint(const std::string &Host, unsigned short Port)
Definition: connectionEndpoint.hpp:69
Base class for network endpoints.
Definition: connectionEndpoint.hpp:50
Definition: connectionEndpoint.hpp:66
Local connection endpoint configuration for authorization, connection based timeout, etc.
Definition: connectionEndpoint.hpp:94
std::vector< std::string > capabilities
Definition: connectionEndpoint.hpp:107
time_t connectionTime() const
Definition: connectionEndpoint.hpp:202
void operator=(const ConnectionEndpoint &)
Definition: connectionEndpoint.hpp:87
EndPoint
Definition: connectionEndpoint.hpp:64
Definition: connectionEndpoint.hpp:56
virtual EndPoint endpoint() const =0
boost::shared_ptr< LocalEndpoint > LocalEndpointR
Definition: connectionEndpoint.hpp:163
ProtocolCapability
Definition: connectionEndpoint.hpp:96
Remote unencrypted endpoint.
Definition: connectionEndpoint.hpp:212
virtual ConnectionType type() const =0
bool hasCapability(const std::string &c) const
Ask for a capability for this local endpoint configuration.
Definition: connectionEndpoint.hpp:132
time_t creationTime() const
Definition: connectionEndpoint.hpp:155
std::string socketIdentifier
Definition: connectionEndpoint.hpp:108
std::string m_host
Definition: connectionEndpoint.hpp:89
static const char * connectionTypeName(ConnectionType t)
Definition: connectionEndpoint.hpp:58
RemoteEndpoint(const std::string &Host, unsigned short Port)
Definition: connectionEndpoint.hpp:193
virtual ConnectionType type() const =0
LocalEndpointConfig(const std::string &socketIdentifier_)
Constructor.
Definition: connectionEndpoint.hpp:118
const std::string & host() const
Definition: connectionEndpoint.hpp:74
std::string toString() const
Definition: connectionEndpoint.hpp:79
static const char * protocolCapabilityName(ProtocolCapability c)
Definition: connectionEndpoint.hpp:101
Local unencrypted endpoint.
Definition: connectionEndpoint.hpp:167
boost::shared_ptr< RemoteEndpoint > RemoteEndpointR
Definition: connectionEndpoint.hpp:208
Definition: connectionEndpoint.hpp:65
Remote connection endpoint.
Definition: connectionEndpoint.hpp:190
virtual ~ConnectionEndpoint()
Definition: connectionEndpoint.hpp:72
void resetCapabilities()
Reset capabilities.
Definition: connectionEndpoint.hpp:122
ConnectionType
Definition: connectionEndpoint.hpp:53
ConnectionType type() const
Definition: connectionEndpoint.hpp:218
const LocalEndpointConfig & config() const
Definition: connectionEndpoint.hpp:156
EndPoint endpoint() const
Definition: connectionEndpoint.hpp:154
RemoteTCPendpoint(const std::string &Host, unsigned short Port)
Definition: connectionEndpoint.hpp:215
unsigned short port() const
Definition: connectionEndpoint.hpp:75
Local connection endpoints.
Definition: connectionEndpoint.hpp:144