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
36namespace 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///
48{
49public:
50 G_EXCEPTION( SendError , "network send error" ) ;
51
53 const GAuth::SaslServerSecrets & , const std::string & sasl_server_config ,
54 std::unique_ptr<ServerProtocol::Text> ptext , const ServerProtocol::Config & ) ;
55 ///< Constructor.
56
57private: // 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
66public:
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
73private:
74 void processLine( const std::string & line ) ;
75
76private:
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///
85{
86public:
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 ,
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
118private: // overrides
119 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::ExceptionSinkUnbound , GNet::ServerPeerInfo , GNet::MultiServer::ServerInfo ) override ;
120
121public:
122 Server( const Server & ) = delete ;
123 Server( Server && ) = delete ;
124 void operator=( const Server & ) = delete ;
125 void operator=( Server && ) = delete ;
126
127private:
128 std::unique_ptr<ServerProtocol::Text> newProtocolText( const GNet::Address & ) const ;
129
130private:
131 Config m_config ;
132 Store & m_store ;
133 const GAuth::SaslServerSecrets & m_secrets ;
134} ;
135
136inline GPop::Server::Config & GPop::Server::Config::set_allow_remote( bool b ) { allow_remote = b ; return *this ; }
137inline GPop::Server::Config & GPop::Server::Config::set_port( unsigned int p ) { port = p ; return *this ; }
138inline GPop::Server::Config & GPop::Server::Config::set_addresses( const G::StringArray & a ) { addresses = a ; return *this ; }
139inline GPop::Server::Config & GPop::Server::Config::set_server_peer_config( const GNet::ServerPeerConfig & c ) { server_peer_config = c ; return *this ; }
140inline GPop::Server::Config & GPop::Server::Config::set_server_config( const GNet::ServerConfig & c ) { server_config = c ; return *this ; }
141inline GPop::Server::Config & GPop::Server::Config::set_sasl_server_config( const std::string & s ) { sasl_server_config = s ; return *this ; }
142
143#endif
An interface used by GAuth::SaslServer to obtain authentication secrets.
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:53
A potential ExceptionSink that is realised by bind()ing an exception source pointer.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A server that listens on more than one address using a facade pattern to multiple GNet::Server instan...
Definition: gmultiserver.h:45
A structure that GNet::Server uses to configure its ServerPeer objects.
Definition: gserverpeer.h:51
A structure used in GNet::Server::newPeer().
Definition: gserver.h:142
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:68
Represents a connection from a POP client.
Definition: gpopserver.h:48
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
An interface used by ServerProtocol to enable TLS.
An interface used by ServerProtocol to send protocol replies.
Implements the POP server-side protocol.
A POP server class.
Definition: gpopserver.h:85
Server(GNet::ExceptionSink, Store &store, const GAuth::SaslServerSecrets &, const Config &)
Constructor. The 'secrets' reference is kept.
Definition: gpopserver.cpp:86
~Server() override
Destructor.
Definition: gpopserver.cpp:94
void report() const
Generates helpful diagnostics after construction.
Definition: gpopserver.cpp:99
A message store.
Definition: gpopstore.h:45
POP3 classes.
Definition: gpopserver.h:37
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:31
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:52
A configuration structure for GNet::Server.
Definition: gserver.h:50
A structure containing configuration parameters for ServerProtocol, currently empty.
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:89