E-MailRelay

gpopserver.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gpopserver.h
19///
20
21#ifndef G_POP_SERVER_H
22#define G_POP_SERVER_H
23
24#include "gdef.h"
25#include "gmultiserver.h"
26#include "glinebuffer.h"
27#include "gpopserverprotocol.h"
28#include "gsecrets.h"
29#include "gexception.h"
30#include "gstrings.h"
31#include <string>
32#include <sstream>
33#include <memory>
34#include <list>
35
36 namespace GPop
37{
38 class Server ;
39 class ServerPeer ;
40}
41
42//| \class GPop::ServerPeer
43/// Represents a connection from a POP client. Instances are created
44/// on the heap by GPop::Server.
45/// \see GPop::Server
46///
47 class GPop::ServerPeer : public GNet::ServerPeer , private ServerProtocol::Sender , private ServerProtocol::Security
48{
49 public:
50 G_EXCEPTION( SendError , "network send error" ) ;
51
52 ServerPeer( GNet::ExceptionSinkUnbound , const GNet::ServerPeerInfo & , Store & ,
53 const GAuth::SaslServerSecrets & , const std::string & sasl_server_config ,
54 std::unique_ptr<ServerProtocol::Text> ptext , const ServerProtocol::Config & ) ;
55 ///< Constructor.
56
57 private: // overrides
58 bool protocolSend( const std::string & line , std::size_t ) override ; // Override from GPop::ServerProtocol::Sender.
59 void onDelete( const std::string & ) override ; // Override from GNet::ServerPeer.
60 bool onReceive( const char * , std::size_t , std::size_t , std::size_t , char ) override ; // Override from GNet::ServerPeer.
61 void onSecure( const std::string & , const std::string & , const std::string & ) override ; // Override from GNet::SocketProtocolSink.
62 void onSendComplete() override ; // Override from GNet::ServerPeer.
63 bool securityEnabled() const override ; // Override from GPop::ServerProtocol::Security.
64 void securityStart() override ; // Override from GPop::ServerProtocol::Security.
65
66 public:
67 ~ServerPeer() override = default ;
68 ServerPeer( const ServerPeer & ) = delete ;
69 ServerPeer( ServerPeer && ) = delete ;
70 void operator=( const ServerPeer & ) = delete ;
71 void operator=( ServerPeer && ) = delete ;
72
73 private:
74 void processLine( const std::string & line ) ;
75
76 private:
77 std::unique_ptr<ServerProtocol::Text> m_ptext ; // order dependency
78 ServerProtocol m_protocol ; // order dependency -- last
79} ;
80
81//| \class GPop::Server
82/// A POP server class.
83///
84 class GPop::Server : public GNet::MultiServer
85{
86 public:
87 G_EXCEPTION( Overflow , "too many interface addresses" ) ;
88 struct Config /// A structure containing GPop::Server configuration parameters.
89 {
90 bool allow_remote{false} ;
91 unsigned int port{110} ;
92 G::StringArray addresses ;
93 GNet::ServerPeerConfig server_peer_config ;
94 GNet::ServerConfig server_config ;
95 std::string sasl_server_config ;
96
97 Config() ;
98 Config( bool , unsigned int port , const G::StringArray & addresses ,
99 const GNet::ServerPeerConfig & , const GNet::ServerConfig & ,
100 const std::string & sasl_server_config ) ;
101 Config & set_allow_remote( bool = true ) ;
102 Config & set_port( unsigned int ) ;
103 Config & set_addresses( const G::StringArray & ) ;
104 Config & set_server_peer_config( const GNet::ServerPeerConfig & ) ;
105 Config & set_server_config( const GNet::ServerConfig & ) ;
106 Config & set_sasl_server_config( const std::string & ) ;
107 } ;
108
109 Server( GNet::ExceptionSink , Store & store , const GAuth::SaslServerSecrets & , const Config & ) ;
110 ///< Constructor. The 'secrets' reference is kept.
111
112 ~Server() override ;
113 ///< Destructor.
114
115 void report() const ;
116 ///< Generates helpful diagnostics after construction.
117
118 private: // overrides
119 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::ExceptionSinkUnbound , GNet::ServerPeerInfo , GNet::MultiServer::ServerInfo ) override ;
120
121 public:
122 Server( const Server & ) = delete ;
123 Server( Server && ) = delete ;
124 void operator=( const Server & ) = delete ;
125 void operator=( Server && ) = delete ;
126
127 private:
128 std::unique_ptr<ServerProtocol::Text> newProtocolText( const GNet::Address & ) const ;
129
130 private:
131 Config m_config ;
132 Store & m_store ;
133 const GAuth::SaslServerSecrets & m_secrets ;
134} ;
135
136 inline GPop::Server::Config & GPop::Server::Config::set_allow_remote( bool b ) { allow_remote = b ; return *this ; }
137 inline GPop::Server::Config & GPop::Server::Config::set_port( unsigned int p ) { port = p ; return *this ; }
138 inline GPop::Server::Config & GPop::Server::Config::set_addresses( const G::StringArray & a ) { addresses = a ; return *this ; }
139 inline GPop::Server::Config & GPop::Server::Config::set_server_peer_config( const GNet::ServerPeerConfig & c ) { server_peer_config = c ; return *this ; }
140 inline GPop::Server::Config & GPop::Server::Config::set_server_config( const GNet::ServerConfig & c ) { server_config = c ; return *this ; }
141 inline GPop::Server::Config & GPop::Server::Config::set_sasl_server_config( const std::string & s ) { sasl_server_config = s ; return *this ; }
142
143#endif
GAuth::SaslServerSecrets
An interface used by GAuth::SaslServer to obtain authentication secrets.
Definition: gsaslserversecrets.h:40
GNet::Address
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:53
GNet::ExceptionSinkUnbound
A potential ExceptionSink that is realised by bind()ing an exception source pointer.
Definition: gexceptionsink.h:154
GNet::ExceptionSink
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
Definition: gexceptionsink.h:100
GNet::MultiServer
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
Definition: gmultiserver.h:45
GNet::ServerPeerConfig
A structure that GNet::Server uses to configure its ServerPeer objects.
Definition: gserverpeer.h:51
GNet::ServerPeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:142
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:68
GPop::ServerPeer
Represents a connection from a POP client.
Definition: gpopserver.h:48
GPop::ServerPeer::ServerPeer
ServerPeer(GNet::ExceptionSinkUnbound, const GNet::ServerPeerInfo &, Store &, const GAuth::SaslServerSecrets &, const std::string &sasl_server_config, std::unique_ptr< ServerProtocol::Text > ptext, const ServerProtocol::Config &)
Constructor.
Definition: gpopserver.cpp:28
GPop::ServerProtocol::Security
An interface used by ServerProtocol to enable TLS.
Definition: gpopserverprotocol.h:75
GPop::ServerProtocol::Sender
An interface used by ServerProtocol to send protocol replies.
Definition: gpopserverprotocol.h:53
GPop::ServerProtocol
Implements the POP server-side protocol.
Definition: gpopserverprotocol.h:48
GPop::Server
A POP server class.
Definition: gpopserver.h:85
GPop::Server::Server
Server(GNet::ExceptionSink, Store &store, const GAuth::SaslServerSecrets &, const Config &)
Constructor. The 'secrets' reference is kept.
Definition: gpopserver.cpp:86
GPop::Server::~Server
~Server() override
Destructor.
Definition: gpopserver.cpp:94
GPop::Server::report
void report() const
Generates helpful diagnostics after construction.
Definition: gpopserver.cpp:99
GPop::Store
A message store.
Definition: gpopstore.h:45
gexception.h
glinebuffer.h
gmultiserver.h
gpopserverprotocol.h
gsecrets.h
gstrings.h
GPop
POP3 classes.
Definition: gpopserver.h:37
G::StringArray
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31
GNet::MultiServer::ServerInfo
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:52
GNet::ServerConfig
A configuration structure for GNet::Server.
Definition: gserver.h:50
GPop::ServerProtocol::Config
A structure containing configuration parameters for ServerProtocol, currently empty.
Definition: gpopserverprotocol.h:70
GPop::Server::Config
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:89