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 
52 {
53 public:
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 ;
104  bool m_notifying ;
105  G::StringMap m_extra_commands ;
106  bool m_with_terminate ;
107 } ;
108 
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 
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:
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
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:112
SMTP and message-store classes.
virtual void onDelete(const std::string &)
Final override from GNet::ServerPeer.
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.
void unregister(AdminServerPeer *)
Called from the AdminServerPeer destructor.
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
void report() const
Generates helpful diagnostics.
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.
virtual bool onReceive(const std::string &)
Final override from GNet::BufferedServerPeer.
A class which allows SMTP messages (envelope+content) to be stored and retrieved. ...
Definition: gmessagestore.h:45
A simple interface to a store of secrets as used in authentication.
Definition: gsecrets.h:44
const GAuth::Secrets & secrets() const
Returns a reference to the secrets object, as passed in to the constructor.
MessageStore & store()
Returns a reference to the message store, as passed in to the constructor.
virtual ~AdminServerPeer()
Destructor.
void notify(const std::string &s0, const std::string &s1, const std::string &s2)
Called when something happens.
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
A derivation of ServerPeer for the administration interface.
Definition: gadminserver.h:51
virtual GNet::ServerPeer * newPeer(GNet::Server::PeerInfo)
Final override from GNet::MultiServer.
virtual void onSendComplete()
Final override from GNet::BufferedServerPeer.
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:49
A class which does line buffering.
Definition: glinebuffer.h:52
AdminServerPeer(GNet::Server::PeerInfo, AdminServer &, const GNet::Address &local, const std::string &remote, const G::StringMap &extra_commands, bool with_terminate)
Constructor.
std::list< Address > AddressList
Definition: gmultiserver.h:105
virtual ~AdminServer()
Destructor.
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
GSmtp::Client::Config clientConfig() const
Returns the client configuration.
A ServerPeer that does line-buffering on input.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91
unsigned int connectionTimeout() const
Returns the connection timeout, as passed in to the constructor.
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocolSink.
An iterator class for GSmtp::MessageStore.
Definition: gmessagestore.h:62