- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gadminserver.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 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 // ===
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 "gexecutable.h"
28 #include "gstr.h"
29 #include "gstrings.h"
30 #include "glinebuffer.h"
31 #include "gserverprotocol.h"
32 #include "gclientptr.h"
33 #include "gsmtpclient.h"
34 #include "gbufferedserverpeer.h"
35 #include <string>
36 #include <list>
37 #include <sstream>
38 #include <utility>
39
41 namespace GSmtp
42 {
43 class AdminServerPeer ;
44 class AdminServer ;
45 }
46
51 class GSmtp::AdminServerPeer : public GNet::BufferedServerPeer
52 {
53 public:
54 AdminServerPeer( GNet::Server::PeerInfo , AdminServer & , const GNet::Address & local ,
55 const std::string & remote , const G::StringMap & extra_commands , bool with_terminate ) ;
57
58 virtual ~AdminServerPeer() ;
60
61 void notify( const std::string & s0 , const std::string & s1 , const std::string & s2 ) ;
63
64 protected:
65 virtual void onSendComplete() ;
67
68 virtual bool onReceive( const std::string & ) ;
70
71 virtual void onDelete( const std::string & ) ;
73
74 virtual void onSecure( const std::string & ) ;
76
77 private:
78 AdminServerPeer( const AdminServerPeer & ) ;
79 void operator=( const AdminServerPeer & ) ;
80 void clientDone( std::string , bool ) ;
81 static bool is( const std::string & , const std::string & ) ;
82 static std::pair<bool,std::string> find( const std::string & line , const G::StringMap & map ) ;
83 bool flush() ;
84 void help() ;
85 void info() ;
86 MessageStore::Iterator spooled() ;
87 MessageStore::Iterator failures() ;
88 void list( MessageStore::Iterator ) ;
89 void pid() ;
90 void sendLine( std::string ) ;
91 void warranty() ;
92 void version() ;
93 void copyright() ;
94 static const std::string & crlf() ;
95 void prompt() ;
96 void unfailAll() ;
97
98 private:
99 GNet::LineBuffer m_buffer ;
100 AdminServer & m_server ;
101 GNet::Address m_local_address ;
102 std::string m_remote_address ;
103 GNet::ClientPtr<GSmtp::Client> m_client ;
104 bool m_notifying ;
105 G::StringMap m_extra_commands ;
106 bool m_with_terminate ;
107 } ;
108
112 class GSmtp::AdminServer : public GNet::MultiServer
113 {
114 public:
115 AdminServer( MessageStore & store , const GSmtp::Client::Config & client_config ,
116 const GAuth::Secrets & client_secrets , const GNet::MultiServer::AddressList & listening_addresses ,
117 bool allow_remote , const GNet::Address & local_address , const std::string & remote_address ,
118 unsigned int connection_timeout , const G::StringMap & extra_commands , bool with_terminate ) ;
121
122 virtual ~AdminServer() ;
124
125 void report() const ;
127
128 MessageStore & store() ;
131
132 const GAuth::Secrets & secrets() const ;
137
138 GSmtp::Client::Config clientConfig() const ;
140
141 unsigned int connectionTimeout() const ;
144
145 void notify( const std::string & s0 , const std::string & s1 , const std::string & s2 ) ;
148
149 void unregister( AdminServerPeer * ) ;
151
152 protected:
153 virtual GNet::ServerPeer * newPeer( GNet::Server::PeerInfo ) ;
155
156 private:
157 AdminServer( const AdminServer & ) ; // not implemented
158 void operator=( const AdminServer & ) ; // not implemented
159
160 private:
161 typedef std::list<AdminServerPeer*> PeerList ;
162 PeerList m_peers ;
163 MessageStore & m_store ;
164 GSmtp::Client::Config m_client_config ;
165 const GAuth::Secrets & m_secrets ;
166 GNet::Address m_local_address ;
167 bool m_allow_remote ;
168 std::string m_remote_address ;
169 unsigned int m_connection_timeout ;
170 G::StringMap m_extra_commands ;
171 bool m_with_terminate ;
172 } ;
173
174 #endif
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
GSmtp::AdminServer
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:112
gstrings.h
GSmtp
SMTP and message-store classes.
GSmtp::AdminServerPeer::onDelete
virtual void onDelete(const std::string &)
Final override from GNet::ServerPeer.
Definition: gadminserver.cpp:79
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:350
GSmtp::AdminServer::unregister
void unregister(AdminServerPeer *)
Called from the AdminServerPeer destructor.
Definition: gadminserver.cpp:359
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
GSmtp::AdminServer::report
void report() const
Generates helpful diagnostics.
Definition: gadminserver.cpp:345
GSmtp::AdminServer::AdminServer
AdminServer(MessageStore &store, const GSmtp::Client::Config &client_config, const GAuth::Secrets &client_secrets, const GNet::MultiServer::AddressList &listening_addresses, bool allow_remote, const GNet::Address &local_address, const std::string &remote_address, unsigned int connection_timeout, const G::StringMap &extra_commands, bool with_terminate)
Constructor.
Definition: gadminserver.cpp:299
GSmtp::AdminServerPeer::onReceive
virtual bool onReceive(const std::string &)
Final override from GNet::BufferedServerPeer.
Definition: gadminserver.cpp:89
gexecutable.h
gmultiserver.h
glinebuffer.h
gserverprotocol.h
gbufferedserverpeer.h
gstr.h
GSmtp::MessageStore
A class which allows SMTP messages (envelope+content) to be stored and retrieved. ...
Definition: gmessagestore.h:45
GAuth::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
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:372
GSmtp::AdminServer::store
MessageStore & store()
Returns a reference to the message store, as passed in to the constructor.
Definition: gadminserver.cpp:367
GSmtp::AdminServerPeer::~AdminServerPeer
virtual ~AdminServerPeer()
Destructor.
Definition: gadminserver.cpp:54
GSmtp::AdminServerPeer::notify
void notify(const std::string &s0, const std::string &s1, const std::string &s2)
Called when something happens.
Definition: gadminserver.cpp:240
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
GSmtp::AdminServerPeer
A derivation of ServerPeer for the administration interface.
Definition: gadminserver.h:51
GSmtp::AdminServer::newPeer
virtual GNet::ServerPeer * newPeer(GNet::Server::PeerInfo)
Final override from GNet::MultiServer.
Definition: gadminserver.cpp:322
GSmtp::AdminServerPeer::onSendComplete
virtual void onSendComplete()
Final override from GNet::BufferedServerPeer.
Definition: gadminserver.cpp:74
G::StringMap
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:49
GNet::LineBuffer
A class which does line buffering.
Definition: glinebuffer.h:52
GNet::ClientPtr< GSmtp::Client >
GSmtp::AdminServerPeer::AdminServerPeer
AdminServerPeer(GNet::Server::PeerInfo, AdminServer &, const GNet::Address &local, const std::string &remote, const G::StringMap &extra_commands, bool with_terminate)
Constructor.
Definition: gadminserver.cpp:38
GNet::MultiServer::AddressList
std::list< Address > AddressList
Definition: gmultiserver.h:105
gsmtp.h
GSmtp::AdminServer::~AdminServer
virtual ~AdminServer()
Destructor.
Definition: gadminserver.cpp:316
gsmtpclient.h
GNet::MultiServer
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
GSmtp::AdminServer::clientConfig
GSmtp::Client::Config clientConfig() const
Returns the client configuration.
Definition: gadminserver.cpp:382
GNet::BufferedServerPeer
A ServerPeer that does line-buffering on input.
Definition: gbufferedserverpeer.h:41
GNet::Server::PeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91
GSmtp::AdminServer::connectionTimeout
unsigned int connectionTimeout() const
Returns the connection timeout, as passed in to the constructor.
Definition: gadminserver.cpp:377
GSmtp::AdminServerPeer::onSecure
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocolSink.
Definition: gadminserver.cpp:85
GSmtp::MessageStore::Iterator
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:62