E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gadminserver.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 gadminserver.h
19 ///
20
21 #ifndef G_SMTP_ADMIN_H
22 #define G_SMTP_ADMIN_H
23
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "gmultiserver.h"
27 #include "gstr.h"
28 #include "gstrings.h"
29 #include "glinebuffer.h"
30 #include "gserverprotocol.h"
31 #include "gclientptr.h"
32 #include "gsmtpclient.h"
33 #include "gbufferedserverpeer.h"
34 #include <string>
35 #include <list>
36 #include <sstream>
37 #include <utility>
38
39 namespace GSmtp
40 {
41 class AdminServerPeer ;
42 class AdminServer ;
43 }
44
45 /// \class GSmtp::AdminServerPeer
46 /// A derivation of ServerPeer for the administration interface.
47 /// \see GSmtp::AdminServer
48 ///
49 class GSmtp::AdminServerPeer : public GNet::BufferedServerPeer
50 {
51 public:
52 AdminServerPeer( GNet::Server::PeerInfo , AdminServer & , const std::string & remote ,
53 const G::StringMap & info_commands , const G::StringMap & config_commands ,
54 bool with_terminate ) ;
55 ///< Constructor.
56
57 virtual ~AdminServerPeer() ;
58 ///< Destructor.
59
60 void notify( const std::string & s0 , const std::string & s1 , const std::string & s2 ) ;
61 ///< Called when something happens.
62
63 protected:
64 virtual void onSendComplete() override ;
65 ///< Override from GNet::BufferedServerPeer.
66
67 virtual bool onReceive( const char * , size_t , size_t ) override ;
68 ///< Override from GNet::BufferedServerPeer.
69
70 virtual void onDelete( const std::string & ) override ;
71 ///< Override from GNet::ServerPeer.
72
73 virtual void onSecure( const std::string & ) override ;
74 ///< Override from GNet::SocketProtocolSink.
75
76 private:
77 AdminServerPeer( const AdminServerPeer & ) ;
78 void operator=( const AdminServerPeer & ) ;
79 void clientDone( std::string ) ;
80 static bool is( const std::string & , const std::string & ) ;
81 static std::pair<bool,std::string> find( const std::string & line , const G::StringMap & map ) ;
82 static std::string argument( const std::string & ) ;
83 void flush() ;
84 void help() ;
85 void status() ;
86 MessageStore::Iterator spooled() ;
87 MessageStore::Iterator failures() ;
88 void sendList( MessageStore::Iterator ) ;
89 void sendLine( std::string , bool = true ) ;
90 void warranty() ;
91 void version() ;
92 void copyright() ;
93 std::string eol() const ;
94 void unfailAll() ;
95 void send_( const std::string & ) ;
96
97 private:
98 AdminServer & m_server ;
99 std::string m_prompt ;
100 bool m_blocked ;
101 std::string m_remote_address ;
102 GNet::ClientPtr<GSmtp::Client> m_client ;
103 bool m_notifying ;
104 G::StringMap m_info_commands ;
105 G::StringMap m_config_commands ;
106 bool m_with_terminate ;
107 } ;
108
109 /// \class GSmtp::AdminServer
110 /// A server class which implements the emailrelay administration interface.
111 ///
112 class GSmtp::AdminServer : public GNet::MultiServer
113 {
114 public:
115 AdminServer( GNet::ExceptionHandler & , MessageStore & store ,
116 const GSmtp::Client::Config & client_config , const GAuth::Secrets & client_secrets ,
117 const GNet::MultiServer::AddressList & listening_addresses , bool allow_remote ,
118 const std::string & remote_address , unsigned int connection_timeout ,
119 const G::StringMap & info_commands , const G::StringMap & config_commands ,
120 bool with_terminate ) ;
121 ///< Constructor.
122
123 virtual ~AdminServer() ;
124 ///< Destructor.
125
126 void report() const ;
127 ///< Generates helpful diagnostics.
128
129 MessageStore & store() ;
130 ///< Returns a reference to the message store, as
131 ///< passed in to the constructor.
132
133 const GAuth::Secrets & secrets() const ;
134 ///< Returns a reference to the secrets object, as
135 ///< passed in to the constructor. Note that this is
136 ///< a "client-side" secrets file, used to authenticate
137 ///< ourselves with a remote server.
138
139 GSmtp::Client::Config clientConfig() const ;
140 ///< Returns the client configuration.
141
142 unsigned int connectionTimeout() const ;
143 ///< Returns the connection timeout, as passed in to the
144 ///< constructor.
145
146 void notify( const std::string & s0 , const std::string & s1 , const std::string & s2 ) ;
147 ///< Called when something happens which the admin
148 ///< user might be interested in.
149
150 void unregister( AdminServerPeer * ) ;
151 ///< Called from the AdminServerPeer destructor.
152
153 protected:
154 virtual GNet::ServerPeer * newPeer( GNet::Server::PeerInfo , GNet::MultiServer::ServerInfo ) g__final override ;
155 ///< Override from GNet::MultiServer.
156
157 private:
158 AdminServer( const AdminServer & ) ; // not implemented
159 void operator=( const AdminServer & ) ; // not implemented
160
161 private:
162 typedef std::list<AdminServerPeer*> PeerList ;
163 PeerList m_peers ;
164 MessageStore & m_store ;
165 GSmtp::Client::Config m_client_config ;
166 const GAuth::Secrets & m_secrets ;
167 bool m_allow_remote ;
168 std::string m_remote_address ;
169 unsigned int m_connection_timeout ;
170 G::StringMap m_info_commands ;
171 G::StringMap m_config_commands ;
172 bool m_with_terminate ;
173 } ;
174
175 #endif
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:173
GSmtp::AdminServer
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:112
gstrings.h
GSmtp
SMTP and message-store classes.
Definition: gadminserver.h:39
GSmtp::AdminServerPeer::onSendComplete
virtual void onSendComplete() override
Override from GNet::BufferedServerPeer.
Definition: gadminserver.cpp:256
GSmtp::AdminServer::notify
void notify(const std::string &s0, const std::string &s1, const std::string &s2)
Called when something happens which the admin user might be interested in.
Definition: gadminserver.cpp:365
GSmtp::AdminServer::unregister
void unregister(AdminServerPeer *)
Called from the AdminServerPeer destructor.
Definition: gadminserver.cpp:374
GSmtp::AdminServer::AdminServer
AdminServer(GNet::ExceptionHandler &, MessageStore &store, const GSmtp::Client::Config &client_config, const GAuth::Secrets &client_secrets, const GNet::MultiServer::AddressList &listening_addresses, bool allow_remote, const std::string &remote_address, unsigned int connection_timeout, const G::StringMap &info_commands, const G::StringMap &config_commands, bool with_terminate)
Constructor.
Definition: gadminserver.cpp:312
GSmtp::AdminServer::report
void report() const
Generates helpful diagnostics.
Definition: gadminserver.cpp:360
GSmtp::AdminServerPeer::onDelete
virtual void onDelete(const std::string &) override
Override from GNet::ServerPeer.
Definition: gadminserver.cpp:72
gmultiserver.h
GNet::ExceptionHandler
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
Definition: gexceptionhandler.h:44
glinebuffer.h
gserverprotocol.h
gbufferedserverpeer.h
GSmtp::AdminServerPeer::AdminServerPeer
AdminServerPeer(GNet::Server::PeerInfo, AdminServer &, const std::string &remote, const G::StringMap &info_commands, const G::StringMap &config_commands, bool with_terminate)
Constructor.
Definition: gadminserver.cpp:34
gstr.h
GSmtp::MessageStore
A class which allows SMTP messages to be stored and retrieved.
Definition: gmessagestore.h:43
GAuth::Secrets
A simple interface for a store of secrets used in authentication.
Definition: gsecrets.h:40
gclientptr.h
GSmtp::AdminServer::secrets
const GAuth::Secrets & secrets() const
Returns a reference to the secrets object, as passed in to the constructor.
Definition: gadminserver.cpp:387
GNet::MultiServer::ServerInfo
A structure used in GNet::MultiServer::newPeer().
Definition: gmultiserver.h:100
GSmtp::AdminServer::store
MessageStore & store()
Returns a reference to the message store, as passed in to the constructor.
Definition: gadminserver.cpp:382
GSmtp::AdminServerPeer::~AdminServerPeer
virtual ~AdminServerPeer()
Destructor.
Definition: gadminserver.cpp:53
GSmtp::AdminServerPeer::notify
void notify(const std::string &s0, const std::string &s1, const std::string &s2)
Called when something happens.
Definition: gadminserver.cpp:237
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:55
GSmtp::AdminServerPeer
A derivation of ServerPeer for the administration interface.
Definition: gadminserver.h:49
GSmtp::AdminServerPeer::onReceive
virtual bool onReceive(const char *, size_t, size_t) override
Override from GNet::BufferedServerPeer.
Definition: gadminserver.cpp:82
G::StringMap
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:34
GNet::ClientPtr
A smart pointer class for GNet::HeapClient that keeps track of when the contained instance deletes it...
Definition: gclientptr.h:33
GSmtp::AdminServerPeer::onSecure
virtual void onSecure(const std::string &) override
Override from GNet::SocketProtocolSink.
Definition: gadminserver.cpp:78
gsmtp.h
GSmtp::AdminServer::~AdminServer
virtual ~AdminServer()
Destructor.
Definition: gadminserver.cpp:331
gsmtpclient.h
GSmtp::AdminServer::newPeer
virtual GNet::ServerPeer * newPeer(GNet::Server::PeerInfo, GNet::MultiServer::ServerInfo) g__final override
Override from GNet::MultiServer.
Definition: gadminserver.cpp:337
GNet::MultiServer
A server that listens on more than one interface using a facade pattern to multiple GNet::Server inst...
Definition: gmultiserver.h:94
GSmtp::AdminServer::clientConfig
GSmtp::Client::Config clientConfig() const
Returns the client configuration.
Definition: gadminserver.cpp:397
GNet::BufferedServerPeer
A ServerPeer that does line-buffering on input.
Definition: gbufferedserverpeer.h:39
GNet::Server::PeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:85
GSmtp::AdminServer::connectionTimeout
unsigned int connectionTimeout() const
Returns the connection timeout, as passed in to the constructor.
Definition: gadminserver.cpp:392
GSmtp::MessageStore::Iterator
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:55