E-MailRelay
gpopserver.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 "gpop.h"
26 #include "gmultiserver.h"
27 #include "gbufferedserverpeer.h"
28 #include "glinebuffer.h"
29 #include "gpopsecrets.h"
30 #include "gpopserverprotocol.h"
31 #include "gexception.h"
32 #include "gstrings.h"
33 #include <string>
34 #include <sstream>
35 #include <memory>
36 #include <list>
37 
38 namespace GPop
39 {
40  class Server ;
41  class ServerPeer ;
42 }
43 
44 /// \class GPop::ServerPeer
45 /// Represents a connection from a POP client. Instances are created
46 /// on the heap by Server (only).
47 /// \see GPop::Server
48 ///
50 {
51 public:
52  G_EXCEPTION( SendError , "network send error" ) ;
53 
55  unique_ptr<ServerProtocol::Text> ptext , ServerProtocol::Config ) ;
56  ///< Constructor.
57 
58  virtual bool protocolSend( const std::string & line , size_t ) override ;
59  ///< Final override from GPop::ServerProtocol::Sender.
60 
61 protected:
62  virtual void onDelete( const std::string & ) override ;
63  ///< Final override from GNet::ServerPeer.
64 
65  virtual bool onReceive( const char * , size_t , size_t ) override ;
66  ///< Final override from GNet::BufferedServerPeer.
67 
68  virtual void onSecure( const std::string & ) override ;
69  ///< Final override from GNet::SocketProtocolSink.
70 
71  virtual void onSendComplete() override ;
72  ///< Final override from GNet::BufferedServerPeer.
73 
74  virtual bool securityEnabled() const override ;
75  ///< Final override from GPop::ServerProtocol::Security.
76 
77  virtual void securityStart() override ;
78  ///< Final override from GPop::ServerProtocol::Security.
79 
80 private:
81  ServerPeer( const ServerPeer & ) ;
82  void operator=( const ServerPeer & ) ;
83  void processLine( const std::string & line ) ;
84 
85 private:
86  Server & m_server ;
87  unique_ptr<ServerProtocol::Text> m_ptext ; // order dependency
88  ServerProtocol m_protocol ; // order dependency -- last
89 } ;
90 
91 /// \class GPop::Server
92 /// A POP server class.
93 ///
95 {
96 public:
97  G_EXCEPTION( Overflow , "too many interface addresses" ) ;
98  struct Config /// A structure containing GPop::Server configuration parameters.
99  {
100  bool allow_remote ;
101  unsigned int port ;
102  G::StringArray addresses ;
103  Config() ;
104  Config( bool , unsigned int , const G::StringArray & addresses ) ;
105  } ;
106 
107  Server( GNet::ExceptionHandler & , Store & store , const Secrets & , Config ) ;
108  ///< Constructor. The 'secrets' reference is kept.
109 
110  virtual ~Server() ;
111  ///< Destructor.
112 
113  void report() const ;
114  ///< Generates helpful diagnostics after construction.
115 
116 private:
117  Server( const Server & ) ; // not implemented
118  void operator=( const Server & ) ; // not implemented
119  unique_ptr<ServerProtocol::Text> newProtocolText( GNet::Address ) const ;
121 
122 private:
123  bool m_allow_remote ;
124  Store & m_store ;
125  const Secrets & m_secrets ;
126 } ;
127 
128 #endif
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:173
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:43
virtual void onSecure(const std::string &) override
Final override from GNet::SocketProtocolSink.
Definition: gpopserver.cpp:82
virtual void onSendComplete() override
Final override from GNet::BufferedServerPeer.
Definition: gpopserver.cpp:65
Implements the POP server-side protocol.
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:54
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
void report() const
Generates helpful diagnostics after construction.
ServerPeer(GNet::Server::PeerInfo, Server &, Store &, const Secrets &, unique_ptr< ServerProtocol::Text > ptext, ServerProtocol::Config)
Constructor.
Definition: gpopserver.cpp:31
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:98
virtual bool onReceive(const char *, size_t, size_t) override
Final override from GNet::BufferedServerPeer.
Definition: gpopserver.cpp:49
An interface used by ServerProtocol to send protocol replies.
A message store.
Definition: gpopstore.h:45
virtual void onDelete(const std::string &) override
Final override from GNet::ServerPeer.
Definition: gpopserver.cpp:43
An interface used by ServerProtocol to enable TLS.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
A POP server class.
Definition: gpopserver.h:94
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:100
Server(GNet::ExceptionHandler &, Store &store, const Secrets &, Config)
Constructor. The 'secrets' reference is kept.
Definition: gpopserver.cpp:89
virtual ~Server()
Destructor.
virtual bool securityEnabled() const override
Final override from GPop::ServerProtocol::Security.
Definition: gpopserver.cpp:70
A structure containing configuration parameters for ServerProtocol. NOT USED.
Represents a connection from a POP client.
Definition: gpopserver.h:49
virtual bool protocolSend(const std::string &line, size_t) override
Final override from GPop::ServerProtocol::Sender.
Definition: gpopserver.cpp:60
A server that listens on more than one interface using a facade pattern to multiple GNet::Server inst...
Definition: gmultiserver.h:94
POP3 classes.
Definition: gpopauth.h:28
A ServerPeer that does line-buffering on input.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:85
virtual void securityStart() override
Final override from GPop::ServerProtocol::Security.
Definition: gpopserver.cpp:77