admin_enabled.cpp
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 // ===
17 //
18 // admin_enabled.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gsmtp.h"
23 #include "admin.h"
24 #include "legal.h"
25 #include "gssl.h"
26 
28 {
29  return true ;
30 }
31 
32 std::auto_ptr<GSmtp::AdminServer> Main::Admin::newServer( const Configuration & cfg ,
33  GSmtp::MessageStore & store , const GSmtp::Client::Config & client_config ,
34  const GAuth::Secrets & client_secrets , const std::string & version_number )
35 {
36  GNet::Address local_address =
37  cfg.clientInterface().length() ?
38  GNet::Address(cfg.clientInterface(),0U) :
39  GNet::Address(0U) ;
40 
41  G::StringMap extra_commands_map ;
42  extra_commands_map.insert( std::make_pair(std::string("version"),version_number) ) ;
43  extra_commands_map.insert( std::make_pair(std::string("warranty"),
44  Legal::warranty(std::string(),std::string(1U,'\n'))) ) ;
45  extra_commands_map.insert( std::make_pair(std::string("credit"),
46  GSsl::Library::credit(std::string(),std::string(1U,'\n'),std::string())) ) ;
47  extra_commands_map.insert( std::make_pair(std::string("copyright"),Legal::copyright()) ) ;
48 
49  std::auto_ptr<GSmtp::AdminServer> server ;
50  server <<= new GSmtp::AdminServer(
51  store ,
52  client_config ,
53  client_secrets ,
55  cfg.allowRemoteClients() ,
56  local_address ,
57  cfg.serverAddress() ,
58  cfg.connectionTimeout() ,
59  extra_commands_map ,
60  cfg.withTerminate() ) ;
61 
62  return server ;
63 }
64 
65 void Main::Admin::notify( GSmtp::AdminServer & s , const std::string & p1 ,
66  const std::string & p2 , const std::string & p3 )
67 {
68  s.notify( p1 , p2 , p3 ) ;
69 }
70 
72 {
73  s.report() ;
74 }
static AddressList addressList(const Address &)
A trivial convenience fuction that returns the given addresses as a single-element list...
static std::string copyright()
Returns the copyright text.
Definition: legal.cpp:26
A server class which implements the emailrelay administration interface.
Definition: gadminserver.h:112
std::string serverAddress() const
Returns the downstream server's address string.
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.
static std::string warranty(const std::string &prefix, const std::string &eol)
Returns the warranty text.
Definition: legal.cpp:31
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
void report() const
Generates helpful diagnostics.
bool allowRemoteClients() const
Returns true if allowing remote clients to connect.
G::Strings listeningInterfaces(const std::string &protocol=std::string()) const
Returns the listening interface(s).
static bool enabled()
Returns true if newServer() is fully implemented.
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
static std::auto_ptr< GSmtp::AdminServer > newServer(const Configuration &, GSmtp::MessageStore &store, const GSmtp::Client::Config &, const GAuth::Secrets &client_secrets, const std::string &version_number)
A factory function for creating a new GSmtp::AdminServer instance on the heap.
static std::string credit(const std::string &prefix, const std::string &eol, const std::string &final)
Returns a credit string.
unsigned int connectionTimeout() const
Returns the client-side connection timeout value.
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
bool withTerminate() const
Returns true if the admin interface should support the terminate command.
std::string clientInterface() const
Returns the sending interface.
static void report(const GSmtp::AdminServer &server)
Calls report() on the given server.
std::map< std::string, std::string > StringMap
A std::map of std::strings.
Definition: gstrings.h:49
unsigned int adminPort() const
Returns the admin port number.
An interface for returning application configuration information.
Definition: configuration.h:45
static void notify(GSmtp::AdminServer &server, const std::string &, const std::string &, const std::string &)
Calls notify() on the given server.