E-MailRelay
gpopserver.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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 "gstringview.h"
31#include "gstringarray.h"
32#include <string>
33#include <sstream>
34#include <memory>
35#include <list>
36
37namespace GPop
38{
39 class Server ;
40 class ServerPeer ;
41}
42
43//| \class GPop::ServerPeer
44/// Represents a connection from a POP client. Instances are created
45/// on the heap by GPop::Server.
46/// \see GPop::Server
47///
49{
50public:
51 G_EXCEPTION( SendError , tx("network send error") )
52
54 const GAuth::SaslServerSecrets & , const std::string & sasl_server_config ,
55 std::unique_ptr<ServerProtocol::Text> ptext , const ServerProtocol::Config & ) ;
56 ///< Constructor.
57
58private: // overrides
59 bool protocolSend( std::string_view , std::size_t ) override ; // GPop::ServerProtocol::Sender
60 void onDelete( const std::string & ) override ; // GNet::ServerPeer
61 bool onReceive( const char * , std::size_t , std::size_t , std::size_t , char ) override ; // GNet::ServerPeer
62 void onSecure( const std::string & , const std::string & , const std::string & ) override ; // GNet::SocketProtocolSink
63 void onSendComplete() override ; // GNet::ServerPeer
64 bool securityEnabled() const override ; // GPop::ServerProtocol::Security
65 void securityStart() override ; // GPop::ServerProtocol::Security
66
67public:
68 ~ServerPeer() override = default ;
69 ServerPeer( const ServerPeer & ) = delete ;
70 ServerPeer( ServerPeer && ) = delete ;
71 ServerPeer & operator=( const ServerPeer & ) = delete ;
72 ServerPeer & operator=( ServerPeer && ) = delete ;
73
74private:
75 void processLine( const std::string & line ) ;
76
77private:
78 std::unique_ptr<ServerProtocol::Text> m_ptext ; // order dependency
79 ServerProtocol m_protocol ; // order dependency -- last
80} ;
81
82//| \class GPop::Server
83/// A POP server class.
84///
86{
87public:
88 G_EXCEPTION( Overflow , tx("too many interface addresses") )
89 struct Config /// A structure containing GPop::Server configuration parameters.
90 {
91 bool allow_remote {false} ;
92 unsigned int port {110} ;
93 G::StringArray addresses ;
94 GNet::ServerPeer::Config net_server_peer_config ;
95 GNet::Server::Config net_server_config ;
96 ServerProtocol::Config protocol_config ;
97 std::string sasl_server_config ;
98
99 Config & set_allow_remote( bool = true ) noexcept ;
100 Config & set_port( unsigned int ) noexcept ;
101 Config & set_addresses( const G::StringArray & ) ;
102 Config & set_net_server_peer_config( const GNet::ServerPeer::Config & ) ;
103 Config & set_net_server_config( const GNet::Server::Config & ) ;
104 Config & set_protocol_config( const ServerProtocol::Config & ) ;
105 Config & set_sasl_server_config( const std::string & ) ;
106 } ;
107
108 Server( GNet::EventState , Store & store , const GAuth::SaslServerSecrets & , const Config & ) ;
109 ///< Constructor. The 'secrets' reference is kept.
110
111 ~Server() override ;
112 ///< Destructor.
113
114 void report( const std::string & group = {} ) const ;
115 ///< Generates helpful diagnostics after construction.
116
117private: // overrides
118 std::unique_ptr<GNet::ServerPeer> newPeer( GNet::EventStateUnbound , GNet::ServerPeerInfo && , GNet::MultiServer::ServerInfo ) override ;
119
120public:
121 Server( const Server & ) = delete ;
122 Server( Server && ) = delete ;
123 Server & operator=( const Server & ) = delete ;
124 Server & operator=( Server && ) = delete ;
125
126private:
127 std::unique_ptr<ServerProtocol::Text> newProtocolText( const GNet::Address & ) const ;
128
129private:
130 Config m_config ;
131 Store & m_store ;
132 const GAuth::SaslServerSecrets & m_secrets ;
133} ;
134
135inline GPop::Server::Config & GPop::Server::Config::set_allow_remote( bool b ) noexcept { allow_remote = b ; return *this ; }
136inline GPop::Server::Config & GPop::Server::Config::set_port( unsigned int p ) noexcept { port = p ; return *this ; }
137inline GPop::Server::Config & GPop::Server::Config::set_addresses( const G::StringArray & a ) { addresses = a ; return *this ; }
138inline GPop::Server::Config & GPop::Server::Config::set_net_server_peer_config( const GNet::ServerPeer::Config & c ) { net_server_peer_config = c ; return *this ; }
139inline GPop::Server::Config & GPop::Server::Config::set_net_server_config( const GNet::Server::Config & c ) { net_server_config = c ; return *this ; }
140inline GPop::Server::Config & GPop::Server::Config::set_protocol_config( const ServerProtocol::Config & c ) { protocol_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:63
The EventStateUnbound class is used as a device to force factory methods to plumb-in an ExceptionSour...
Definition: geventstate.h:231
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
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:142
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserverpeer.h:59
Represents a connection from a POP client.
Definition: gpopserver.h:49
ServerPeer(GNet::EventStateUnbound, 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:86
void report(const std::string &group={}) const
Generates helpful diagnostics after construction.
Definition: gpopserver.cpp:100
~Server() override
Destructor.
Definition: gpopserver.cpp:95
Server(GNet::EventState, Store &store, const GAuth::SaslServerSecrets &, const Config &)
Constructor. The 'secrets' reference is kept.
Definition: gpopserver.cpp:87
A message store.
Definition: gpopstore.h:47
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) noexcept
A briefer alternative to G::gettext_noop().
Definition: ggettext.h:84
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:55
A configuration structure for GNet::ServerPeer.
Definition: gserverpeer.h:64
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:90