run.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_MAIN_RUN_H
22 #define G_MAIN_RUN_H
23 
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "configuration.h"
27 #include "commandline.h"
28 #include "output.h"
29 #include "geventloop.h"
30 #include "gtimer.h"
31 #include "gclientptr.h"
32 #include "glogoutput.h"
33 #include "gdaemon.h"
34 #include "gpidfile.h"
35 #include "gslot.h"
36 #include "garg.h"
37 #include "gsecrets.h"
38 #include "gmessagestore.h"
39 #include "gfilestore.h"
40 #include "gsmtpclient.h"
41 #include "gsmtpserver.h"
42 #include "gadminserver.h"
43 #include "gpopserver.h"
44 #include "gpopstore.h"
45 #include "gpopsecrets.h"
46 #include <iostream>
47 #include <exception>
48 #include <memory>
49 
51 namespace Main
52 {
53  class Run ;
54 }
55 
71 class Main::Run : private GNet::EventHandler
72 {
73 public:
74  Run( Output & output , const G::Arg & arg , const std::string & switch_spec ) ;
76 
77  virtual ~Run() ;
79 
80  bool hidden() const ;
82 
83  bool prepare() ;
87 
88  bool prepareError() const ;
90 
91  void run() ;
94 
95  const Configuration & config() const ;
97 
98  static std::string versionNumber() ;
100 
103 
104  virtual void onException( std::exception & ) ;
106 
107 private:
108  Run( const Run & ) ; // not implemented
109  void operator=( const Run & ) ; // not implemented
110  void runCore() ;
111  void doForwardingOnStartup( GSmtp::MessageStore & , const GAuth::Secrets & , GNet::EventLoop & ) ;
112  void doServing( const GAuth::Secrets & , GSmtp::MessageStore & , const GAuth::Secrets & ,
113  GPop::Store & , const GPop::Secrets & , G::PidFile & , GNet::EventLoop & ) ;
114  void closeFiles() ;
115  void closeMoreFiles() ;
116  std::string smtpIdent() const ;
117  void recordPid() ;
118  const CommandLine & cl() const ;
119  void forwardingClientDone( std::string , bool ) ; // Client::doneSignal()
120  void pollingClientDone( std::string , bool ) ; // Client::doneSignal()
121  void clientEvent( std::string , std::string ) ; // Client::eventSignal()
122  void serverEvent( std::string , std::string ) ; // Server::eventSignal()
123  void raiseStoreEvent( bool ) ;
124  void raiseNetworkEvent( std::string , std::string ) ;
125  void emit( const std::string & , const std::string & , const std::string & ) ;
126  void onPollTimeout() ;
127  void onForwardingTimeout() ;
128  void doForwarding( const std::string & ) ;
129  std::string doForwardingCore() ;
130  void checkPorts() const ;
131  static void checkPort( bool , const std::string & , unsigned int ) ;
132  GSmtp::Client::Config clientConfig() const ;
133  GSmtp::Server::Config serverConfig() const ;
134  static GNet::Address clientBindAddress( const std::string & ) ;
135  GPop::Server::Config popConfig() const ;
136  void checkScripts() const ;
137  void checkVerifierScript( const std::string & ) const ;
138  void checkProcessorScript( const std::string & ) const ;
139  std::string versionString() const ;
140  static std::string capabilities() ;
141 
142 private:
143  Output & m_output ;
144  std::string m_switch_spec ;
145  std::auto_ptr<G::LogOutput> m_log_output ;
146  std::auto_ptr<CommandLine> m_cl ;
147  std::auto_ptr<Configuration> m_cfg ;
148  G::Arg m_arg ;
150  std::auto_ptr<GSmtp::FileStore> m_store ; // order dependency -- early
151  std::auto_ptr<GAuth::Secrets> m_client_secrets ;
152  std::auto_ptr<GPop::Secrets> m_pop_secrets ;
153  std::auto_ptr<GSmtp::AdminServer> m_admin_server ;
154  std::auto_ptr<GSmtp::Server> m_smtp_server ;
155  std::auto_ptr<GNet::Timer<Run> > m_poll_timer ;
156  std::auto_ptr<GNet::Timer<Run> > m_forwarding_timer ;
157  GNet::ResolverInfo m_client_resolver_info ;
158  GNet::ClientPtr<GSmtp::Client> m_client ; // order dependency -- late
159  bool m_prepare_error ;
160 } ;
161 
162 #endif
Application-level classes.
bool prepare()
Prepares to run() typically by parsing the commandline.
Definition: run.cpp:150
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:44
void run()
Runs the application.
Definition: run.cpp:247
Run(Output &output, const G::Arg &arg, const std::string &switch_spec)
Constructor. Tries not to throw.
Definition: run.cpp:72
const Configuration & config() const
Returns a configuration object.
Definition: run.cpp:119
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:51
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
bool hidden() const
Returns true if the program should run in hidden mode.
Definition: run.cpp:145
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:101
A message store.
Definition: gpopstore.h:46
An abstract interface for generating output on a command-line or a GUI.
Definition: output.h:38
A structure containing GSmtp::Server configuration parameters.
Definition: gsmtpserver.h:99
virtual ~Run()
Destructor.
Definition: run.cpp:83
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
bool prepareError() const
Returns true if prepare() failed.
Definition: run.cpp:114
A class which deals with the command-line interface to the process, both input and output...
Definition: commandline.h:44
A base class for classes that handle asynchronous socket events.
Definition: geventhandler.h:54
A top-level class for the process.
Definition: run.h:71
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
virtual void onException(std::exception &)
Final override from GNet::EventHandler.
Definition: run.cpp:510
static std::string versionNumber()
Returns the application version number string.
Definition: run.cpp:67
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
Definition: garg.h:46
A class for creating pid files.
Definition: gpidfile.h:56
G::Signal3< std::string, std::string, std::string > & signal()
Provides a signal which is activated when something changes.
Definition: run.cpp:654
An interface for returning application configuration information.
Definition: configuration.h:45