- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
101 G::Signal3<std::string,std::string,std::string> & signal() ;
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 ;
149 G::Signal3<std::string,std::string,std::string> m_signal ;
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
Main
Application-level classes.
Main::Run::prepare
bool prepare()
Prepares to run() typically by parsing the commandline.
Definition: run.cpp:150
GPop::Secrets
A simple interface to a store of secrets as used in authentication.
Definition: gpopsecrets.h:44
Main::Run::run
void run()
Runs the application.
Definition: run.cpp:247
gadminserver.h
output.h
gsmtpserver.h
Main::Run::Run
Run(Output &output, const G::Arg &arg, const std::string &switch_spec)
Constructor. Tries not to throw.
Definition: run.cpp:72
Main::Run::config
const Configuration & config() const
Returns a configuration object.
Definition: run.cpp:119
GNet::EventLoop
An abstract base class for a singleton that keeps track of open sockets and their associated handlers...
Definition: geventloop.h:51
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
Main::Run::hidden
bool hidden() const
Returns true if the program should run in hidden mode.
Definition: run.cpp:145
GNet::ResolverInfo
A class that holds a host/service name pair and optionally the results of a name-to-address lookup...
Definition: gresolverinfo.h:48
gslot.h
geventloop.h
GPop::Server::Config
A structure containing GPop::Server configuration parameters.
Definition: gpopserver.h:101
gpopstore.h
glogoutput.h
GPop::Store
A message store.
Definition: gpopstore.h:46
Main::Output
An abstract interface for generating output on a command-line or a GUI.
Definition: output.h:38
garg.h
GSmtp::Server::Config
A structure containing GSmtp::Server configuration parameters.
Definition: gsmtpserver.h:99
gpidfile.h
configuration.h
Main::Run::~Run
virtual ~Run()
Destructor.
Definition: run.cpp:83
gsecrets.h
gfilestore.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
gtimer.h
gclientptr.h
commandline.h
Main::Run::prepareError
bool prepareError() const
Returns true if prepare() failed.
Definition: run.cpp:114
gpopsecrets.h
Main::CommandLine
A class which deals with the command-line interface to the process, both input and output...
Definition: commandline.h:44
gmessagestore.h
GNet::EventHandler
A base class for classes that handle asynchronous socket events.
Definition: geventhandler.h:54
Main::Run
A top-level class for the process.
Definition: run.h:71
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
Main::Run::onException
virtual void onException(std::exception &)
Final override from GNet::EventHandler.
Definition: run.cpp:510
G::Signal3< std::string, std::string, std::string >
Main::Run::versionNumber
static std::string versionNumber()
Returns the application version number string.
Definition: run.cpp:67
gdaemon.h
GNet::ClientPtr< GSmtp::Client >
G::Arg
A class which holds a represention of the argc/argv command line array, and supports simple command-l...
Definition: garg.h:46
gsmtp.h
gsmtpclient.h
gpopserver.h
G::PidFile
A class for creating pid files.
Definition: gpidfile.h:56
Main::Run::signal
G::Signal3< std::string, std::string, std::string > & signal()
Provides a signal which is activated when something changes.
Definition: run.cpp:654
Main::Configuration
An interface for returning application configuration information.
Definition: configuration.h:45