41 explicit AnonymousText(
const std::string & = std::string() ) ;
42 virtual std::string greeting()
const ;
43 virtual std::string hello(
const std::string & peer_name )
const ;
44 virtual std::string received(
const std::string & smtp_peer_name ,
bool ,
bool )
const ;
45 std::string m_thishost ;
49 AnonymousText::AnonymousText(
const std::string & thishost ) :
52 if( m_thishost.empty() )
56 std::string AnonymousText::greeting()
const
61 std::string AnonymousText::hello(
const std::string & )
const
63 return m_thishost +
" says hello" ;
66 std::string AnonymousText::received(
const std::string & smtp_peer_name ,
bool authenticated ,
bool secure )
const
68 return std::string() ;
75 unique_ptr<ServerProtocol::Text> ptext ) :
78 m_verifier(
VerifierFactory::newVerifier(*this,server_config.verifier_address,server_config.verifier_timeout,server_config.verifier_compatibility)) ,
79 m_pmessage(server.newProtocolMessage(*this)) ,
80 m_ptext(ptext.release()) ,
81 m_line_buffer(
GNet::LineBufferConfig::smtp()) ,
82 m_protocol(*this,*this,*m_verifier.get(),*m_pmessage.get(),server_secrets,*m_ptext.get(),
83 peer_info.m_address,server_config.protocol_config)
85 G_LOG_S(
"GSmtp::ServerPeer: smtp connection from " << peer_info.m_address.
displayString() ) ;
91 G_LOG_S(
"GSmtp::ServerPeer: smtp connection closed: " << reason << (reason.empty()?
"":
": ")
92 << peerAddress().second.displayString() ) ;
94 m_server.eventSignal().emit(
"done" , reason ) ;
108 bool operator()(
const char * p ,
size_t n ,
size_t e )
110 return m_protocol.
apply( p , n , e ) ;
117 G_ASSERT( line_size != 0U ) ;
if( line_size == 0U ) return ;
118 Adaptor a( m_protocol ) ;
119 m_line_buffer.apply( line_data , line_size , a ) ;
124 m_protocol.secure( certificate ) ;
127 void GSmtp::ServerPeer::protocolSend(
const std::string & line ,
bool go_secure )
129 if( !send( line , 0U ) )
136 void GSmtp::ServerPeer::protocolShutdown()
138 socket().shutdown() ;
146 GNet::MultiServer( eh ,
GNet::MultiServer::addressList(server_config.interfaces,server_config.port) ) ,
148 m_server_config(server_config) ,
149 m_client_config(client_config) ,
150 m_server_secrets(server_secrets) ,
151 m_forward_to(forward_to) ,
152 m_client_secrets(client_secrets)
164 return m_event_signal ;
169 serverReport(
"smtp" ) ;
179 G_WARNING(
"GSmtp::Server: configured to reject non-local smtp connection: " << reason ) ;
183 return new ServerPeer( peer_info , *
this ,
184 m_server_secrets , m_server_config ,
185 unique_ptr<ServerProtocol::Text>(newProtocolText(m_server_config.anonymous,peer_info.m_address)) ) ;
187 catch( std::exception & e )
189 G_WARNING(
"GSmtp::Server: exception from new connection: " << e.what() ) ;
194 unique_ptr<GSmtp::ServerProtocol::Text> GSmtp::Server::newProtocolText(
bool anonymous ,
const GNet::Address & peer_address )
const
197 return unique_ptr<ServerProtocol::Text>(
new AnonymousText ) ;
199 return unique_ptr<ServerProtocol::Text>(
new ServerProtocolText( m_server_config.ident ,
GNet::Local::canonicalName() , peer_address ) ) ;
202 unique_ptr<GSmtp::Filter> GSmtp::Server::newFilter( ServerPeer & server_peer )
204 return FilterFactory::newFilter( server_peer ,
true , m_server_config.filter_address , m_server_config.filter_timeout ) ;
207 unique_ptr<GSmtp::ProtocolMessage> GSmtp::Server::newProtocolMessageStore( unique_ptr<Filter> filter )
209 return unique_ptr<ProtocolMessage>(
new ProtocolMessageStore( m_store , unique_ptr<Filter>(filter.release()) ) ) ;
212 unique_ptr<GSmtp::ProtocolMessage> GSmtp::Server::newProtocolMessageForward( unique_ptr<ProtocolMessage> pm )
215 return unique_ptr<ProtocolMessage>(
new ProtocolMessageForward( m_store , unique_ptr<ProtocolMessage>(pm.release()) ,
216 m_client_config , m_client_secrets , m_forward_to ) ) ;
221 const bool do_forward = ! m_forward_to.empty() ;
223 newProtocolMessageForward( newProtocolMessageStore(newFilter(server_peer)) ) :
224 newProtocolMessageStore( newFilter(server_peer) ) ;
229 GSmtp::Server::Config::Config(
bool allow_remote_ ,
unsigned int port_ ,
const AddressList & interfaces_ ,
230 const std::string & ident_ ,
bool anonymous_ ,
231 const std::string & filter_address_ ,
232 unsigned int filter_timeout_ ,
233 const std::string & verifier_address_ ,
234 unsigned int verifier_timeout_ ,
235 bool verifier_compatibility_ ,
237 allow_remote(allow_remote_) ,
239 interfaces(interfaces_) ,
241 anonymous(anonymous_) ,
242 filter_address(filter_address_) ,
243 filter_timeout(filter_timeout_) ,
244 verifier_address(verifier_address_) ,
245 verifier_timeout(verifier_timeout_) ,
246 verifier_compatibility(verifier_compatibility_) ,
247 protocol_config(protocol_config_)
virtual ~Server()
Destructor.
An abstract base class for the GNet::Server's connection to a remote client.
ServerPeer(GNet::Server::PeerInfo peer_info, Server &server, const GAuth::Secrets &server_secrets, const Server::Config &server_config, unique_ptr< ServerProtocol::Text > ptext)
Constructor.
unique_ptr< ProtocolMessage > newProtocolMessage(ServerPeer &)
Called by GSmtp::ServerPeer to construct a ProtocolMessage.
static std::string canonicalName()
Returns the canonical network name assiciated with hostname().
Handles a connection from a remote SMTP client.
An interface used by ServerProtocol to provide response text strings.
virtual void onSecure(const std::string &) override
Override from GNet::SocketProtocolSink.
The GNet::Address class encapsulates a TCP/UDP transport address.
virtual void onDelete(const std::string &reason) override
Override from GNet::ServerPeer.
Implements the SMTP server-side protocol.
Server(GNet::ExceptionHandler &eh, MessageStore &store, const GAuth::Secrets &client_secrets, const GAuth::Secrets &server_secrets, Config server_config, std::string forward_to, GSmtp::Client::Config client_config)
Constructor.
void report() const
Generates helpful diagnostics after construction.
virtual void onData(const char *, size_t) override
Override from GNet::SocketProtocolSink.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events...
void init()
Starts the protocol. Use only once after construction.
A structure containing GSmtp::Server configuration parameters.
A class which allows SMTP messages to be stored and retrieved.
A simple interface for a store of secrets used in authentication.
static unique_ptr< Filter > newFilter(GNet::ExceptionHandler &, bool server_side, const std::string &identifier, unsigned int timeout)
Returns a Filter on the heap.
A structure used in GNet::MultiServer::newPeer().
static bool isLocal(const Address &, std::string &reason)
Returns true if the given address appears to be associated with the local host, or a helpful error me...
A structure containing GSmtp::Client configuration parameters.
A factory for addresss verifiers.
A structure containing configuration parameters for ServerProtocol.
G::Slot::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something has happened.
bool apply(const char *line_data, size_t line_size, size_t eolsize)
Called on receipt of a line of text from the remote client Returns true.
virtual void onSendComplete() override
Override from GNet::ServerPeer.
A structure used in GNet::Server::newPeer().
std::string displayString() const
Returns a string which represents the transport address for debugging and diagnostics purposes...