gsmtpserver.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_SERVER_H
22 #define G_SMTP_SERVER_H
23 
24 #include "gdef.h"
25 #include "gsmtp.h"
26 #include "gnoncopyable.h"
27 #include "gexecutable.h"
28 #include "gbufferedserverpeer.h"
29 #include "gmultiserver.h"
30 #include "gsmtpclient.h"
31 #include "gverifier.h"
32 #include "gmessagestore.h"
33 #include "gserverprotocol.h"
34 #include "gprotocolmessage.h"
35 #include "gconnectionlookup.h"
36 #include "gexception.h"
37 #include <string>
38 #include <sstream>
39 #include <memory>
40 #include <list>
41 
43 namespace GSmtp
44 {
45  class Server ;
46  class ServerPeer ;
47 }
48 
55 {
56 public:
57  ServerPeer( GNet::Server::PeerInfo , Server & server , std::auto_ptr<ProtocolMessage> pmessage ,
58  const GAuth::Secrets & , const std::string & verifier_address , unsigned int verifier_timeout ,
59  std::auto_ptr<ServerProtocol::Text> ptext , ServerProtocol::Config ) ;
61 
62 protected:
63  virtual void onSendComplete() ;
65 
66  virtual void onDelete( const std::string & reason ) ;
68 
69  virtual bool onReceive( const std::string & line ) ;
71 
72  virtual void onSecure( const std::string & ) ;
74 
75 private:
76  ServerPeer( const ServerPeer & ) ;
77  void operator=( const ServerPeer & ) ;
78  virtual void protocolSend( const std::string & line , bool ) ; // override from private base class
79  static const std::string & crlf() ;
80 
81 private:
82  Server & m_server ;
83  std::auto_ptr<Verifier> m_verifier ;
84  std::auto_ptr<ProtocolMessage> m_pmessage ;
85  std::auto_ptr<ServerProtocol::Text> m_ptext ;
86  ServerProtocol m_protocol ; // order dependency -- last
87 } ;
88 
93 {
94 public:
95  typedef std::list<GNet::Address> AddressList ;
96  G_EXCEPTION( Overflow , "too many interface addresses" ) ;
97 
99  struct Config
100  {
102  unsigned int port ;
103  AddressList interfaces ;
105  std::string ident ;
106  bool anonymous ;
108  std::string processor_address ;
109  unsigned int processor_timeout ;
111  std::string verifier_address ;
112  unsigned int verifier_timeout ;
116  Config( bool , unsigned int , const AddressList & , const std::string & , bool ,
117  const std::string & , unsigned int , const std::string & , unsigned int , bool ) ;
118  } ;
119 
120  Server( MessageStore & store , const GAuth::Secrets & client_secrets , const GAuth::Secrets & server_secrets ,
121  Config server_config , std::string smtp_server_address , unsigned int smtp_connection_timeout ,
122  GSmtp::Client::Config client_config ) ;
135 
136  virtual ~Server() ;
138 
139  void report() const ;
141 
144 
147 
148 private:
149  ProtocolMessage * newProtocolMessage() ;
150  ProtocolMessage * newProtocolMessageStore( std::auto_ptr<Processor> ) ;
151  ProtocolMessage * newProtocolMessageScanner( std::auto_ptr<ProtocolMessage> ) ;
152  ProtocolMessage * newProtocolMessageForward( std::auto_ptr<ProtocolMessage> ) ;
153  ServerProtocol::Text * newProtocolText( bool , GNet::Address , const std::string & ) const ;
154 
155 private:
156  MessageStore & m_store ;
157  std::string m_processor_address ;
158  unsigned int m_processor_timeout ;
159  GSmtp::Client::Config m_client_config ;
160  std::string m_ident ;
161  bool m_allow_remote ;
162  const GAuth::Secrets & m_server_secrets ;
163  std::string m_smtp_server ;
164  unsigned int m_smtp_connection_timeout ;
165  const GAuth::Secrets & m_client_secrets ;
166  std::string m_verifier_address ;
167  unsigned int m_verifier_timeout ;
168  bool m_anonymous ;
169  std::auto_ptr<ServerProtocol::Text> m_protocol_text ;
170  G::Signal2<std::string,std::string> m_event_signal ;
171  std::auto_ptr<GNet::ConnectionLookup> m_connection_lookup ;
172 } ;
173 
174 #endif
virtual ~Server()
Destructor.
An interface used by ServerProtocol to send protocol replies.
GNet::ServerPeer * newPeer(GNet::Server::PeerInfo)
From MultiServer.
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
Represents a connection from an SMTP client.
Definition: gsmtpserver.h:54
AddressList interfaces
Definition: gsmtpserver.h:103
SMTP and message-store classes.
An interface used by ServerProtocol to provide response text strings.
std::list< GNet::Address > AddressList
Definition: gsmtpserver.h:95
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
Server(MessageStore &store, const GAuth::Secrets &client_secrets, const GAuth::Secrets &server_secrets, Config server_config, std::string smtp_server_address, unsigned int smtp_connection_timeout, GSmtp::Client::Config client_config)
Constructor.
Implements the SMTP server-side protocol.
void report() const
Generates helpful diagnostics after construction.
Server * server()
Returns a pointer to the associated server object.
G::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something has happened.
unsigned int verifier_timeout
Definition: gsmtpserver.h:112
A structure containing GSmtp::Server configuration parameters.
Definition: gsmtpserver.h:99
virtual bool onReceive(const std::string &line)
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
virtual void onDelete(const std::string &reason)
Final override from GNet::ServerPeer.
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocolSink.
An SMTP server class.
Definition: gsmtpserver.h:92
unsigned int processor_timeout
Definition: gsmtpserver.h:109
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
std::string processor_address
Definition: gsmtpserver.h:108
A structure containing configuration parameters for ServerProtocol.
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
virtual void onSendComplete()
Final override from GNet::BufferedServerPeer.
An interface used by the ServerProtocol class to assemble and process an incoming message...
Config(bool, unsigned int, const AddressList &, const std::string &, bool, const std::string &, unsigned int, const std::string &, unsigned int, bool)
ServerPeer(GNet::Server::PeerInfo, Server &server, std::auto_ptr< ProtocolMessage > pmessage, const GAuth::Secrets &, const std::string &verifier_address, unsigned int verifier_timeout, std::auto_ptr< ServerProtocol::Text > ptext, ServerProtocol::Config)
Constructor.
Definition: gsmtpserver.cpp:78
std::string verifier_address
Definition: gsmtpserver.h:111
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
A ServerPeer that does line-buffering on input.
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91