E-MailRelay
gpopserver.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 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 "gstringarray.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 , tx("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( G::string_view , 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 ServerPeer & operator=( const ServerPeer & ) = delete ;
71 ServerPeer & 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 , tx("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::ServerPeer::Config net_server_peer_config ;
94 GNet::Server::Config net_server_config ;
95 std::string sasl_server_config ;
96 std::string sasl_server_challenge_domain ;
97
98 Config & set_allow_remote( bool = true ) ;
99 Config & set_port( unsigned int ) ;
100 Config & set_addresses( const G::StringArray & ) ;
101 Config & set_net_server_peer_config( const GNet::ServerPeer::Config & ) ;
102 Config & set_net_server_config( const GNet::Server::Config & ) ;
103 Config & set_sasl_server_config( const std::string & ) ;
104 Config & set_sasl_server_challenge_domain( const std::string & ) ;
105 } ;
106
107 Server( GNet::ExceptionSink , Store & store , const GAuth::SaslServerSecrets & , const Config & ) ;
108 ///< Constructor. The 'secrets' reference is kept.
109
110 ~Server() override ;
111 ///< Destructor.
112
113 void report( const std::string & group = {} ) const ;
114 ///< Generates helpful diagnostics after construction.
115
116private: // overrides
117 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::ExceptionSinkUnbound , GNet::ServerPeerInfo && , GNet::MultiServer::ServerInfo ) override ;
118
119public:
120 Server( const Server & ) = delete ;
121 Server( Server && ) = delete ;
122 Server & operator=( const Server & ) = delete ;
123 Server & operator=( Server && ) = delete ;
124
125private:
126 std::unique_ptr<ServerProtocol::Text> newProtocolText( const GNet::Address & ) const ;
127
128private:
129 Config m_config ;
130 Store & m_store ;
131 const GAuth::SaslServerSecrets & m_secrets ;
132} ;
133
134inline GPop::Server::Config & GPop::Server::Config::set_allow_remote( bool b ) { allow_remote = b ; return *this ; }
135inline GPop::Server::Config & GPop::Server::Config::set_port( unsigned int p ) { port = p ; return *this ; }
136inline GPop::Server::Config & GPop::Server::Config::set_addresses( const G::StringArray & a ) { addresses = a ; return *this ; }
137inline GPop::Server::Config & GPop::Server::Config::set_net_server_peer_config( const GNet::ServerPeer::Config & c ) { net_server_peer_config = c ; return *this ; }
138inline GPop::Server::Config & GPop::Server::Config::set_net_server_config( const GNet::Server::Config & c ) { net_server_config = c ; return *this ; }
139inline GPop::Server::Config & GPop::Server::Config::set_sasl_server_config( const std::string & s ) { sasl_server_config = s ; return *this ; }
140inline GPop::Server::Config & GPop::Server::Config::set_sasl_server_challenge_domain( const std::string & s ) { sasl_server_challenge_domain = s ; return *this ; }
141
142#endif
An interface used by GAuth::SaslServer to obtain authentication secrets.
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:62
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:48
A move-only structure used in GNet::Server::newPeer() and containing the new socket.
Definition: gserver.h:140
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:58
Represents a connection from a POP client.
Definition: gpopserver.h:48
ServerPeer(GNet::ExceptionSinkUnbound, 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
void report(const std::string &group={}) const
Generates helpful diagnostics after construction.
Definition: gpopserver.cpp:100
Server(GNet::ExceptionSink, Store &store, const GAuth::SaslServerSecrets &, const Config &)
Constructor. The 'secrets' reference is kept.
Definition: gpopserver.cpp:87
~Server() override
Destructor.
Definition: gpopserver.cpp:95
A message store.
Definition: gpopstore.h:47
A class like c++17's std::string_view.
Definition: gstringview.h:51
POP3 classes.
Definition: gpop.h:33
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
constexpr const char * tx(const char *p)
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:56
A configuration structure for GNet::ServerPeer.
Definition: gserverpeer.h:63
A configuration structure for GNet::Server.
Definition: gserver.h:56
A structure containing configuration parameters for ServerProtocol.
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:89