- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
54 class GSmtp::ServerPeer : public GNet::BufferedServerPeer , private GSmtp::ServerProtocol::Sender
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
92 class GSmtp::Server : public GNet::MultiServer
93 {
94 public:
95 typedef std::list<GNet::Address> AddressList ;
96 G_EXCEPTION( Overflow , "too many interface addresses" ) ;
97
99 struct Config
100 {
101 bool allow_remote ;
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 ;
114 bool use_connection_lookup ;
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
142 GNet::ServerPeer * newPeer( GNet::Server::PeerInfo ) ;
144
145 G::Signal2<std::string,std::string> & eventSignal() ;
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
GSmtp::Server::~Server
virtual ~Server()
Destructor.
Definition: gsmtpserver.cpp:156
GSmtp::ServerProtocol::Sender
An interface used by ServerProtocol to send protocol replies.
Definition: gserverprotocol.h:63
GSmtp::Server::newPeer
GNet::ServerPeer * newPeer(GNet::Server::PeerInfo)
From MultiServer.
Definition: gsmtpserver.cpp:172
GNet::ServerPeer
An abstract base class for the GNet::Server's connection to a remote client.
Definition: gserver.h:191
G::Signal2< std::string, std::string >
GSmtp::ServerPeer
Represents a connection from an SMTP client.
Definition: gsmtpserver.h:54
GSmtp::Server::Config::interfaces
AddressList interfaces
Definition: gsmtpserver.h:103
GSmtp
SMTP and message-store classes.
GSmtp::ServerProtocol::Text
An interface used by ServerProtocol to provide response text strings.
Definition: gserverprotocol.h:70
GSmtp::Server::AddressList
std::list< GNet::Address > AddressList
Definition: gsmtpserver.h:95
gprotocolmessage.h
GNet::Address
The Address class encapsulates an IP transport address.
Definition: gaddress.h:48
GSmtp::Server::Server
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.
Definition: gsmtpserver.cpp:136
GSmtp::Server::Config::allow_remote
bool allow_remote
Definition: gsmtpserver.h:101
GSmtp::ServerProtocol
Implements the SMTP server-side protocol.
Definition: gserverprotocol.h:58
GSmtp::Server::report
void report() const
Generates helpful diagnostics after construction.
Definition: gsmtpserver.cpp:167
GNet::ServerPeer::server
Server * server()
Returns a pointer to the associated server object.
gexecutable.h
GSmtp::Server::Config::ident
std::string ident
Definition: gsmtpserver.h:105
GSmtp::Server::Config::anonymous
bool anonymous
Definition: gsmtpserver.h:106
gmultiserver.h
gverifier.h
GSmtp::Server::eventSignal
G::Signal2< std::string, std::string > & eventSignal()
Returns a signal that indicates that something has happened.
Definition: gsmtpserver.cpp:162
GSmtp::Server::Config::verifier_timeout
unsigned int verifier_timeout
Definition: gsmtpserver.h:112
gserverprotocol.h
GSmtp::Server::Config
A structure containing GSmtp::Server configuration parameters.
Definition: gsmtpserver.h:99
GSmtp::ServerPeer::onReceive
virtual bool onReceive(const std::string &line)
Final override from GNet::BufferedServerPeer.
Definition: gsmtpserver.cpp:115
gbufferedserverpeer.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
GSmtp::ServerPeer::onDelete
virtual void onDelete(const std::string &reason)
Final override from GNet::ServerPeer.
Definition: gsmtpserver.cpp:102
GSmtp::ServerPeer::onSecure
virtual void onSecure(const std::string &)
Final override from GNet::SocketProtocolSink.
Definition: gsmtpserver.cpp:122
GSmtp::Server::Config::port
unsigned int port
Definition: gsmtpserver.h:102
GSmtp::Server
An SMTP server class.
Definition: gsmtpserver.h:92
gconnectionlookup.h
gmessagestore.h
GSmtp::Server::Config::processor_timeout
unsigned int processor_timeout
Definition: gsmtpserver.h:109
GSmtp::Client::Config
A structure containing GSmtp::Client configuration parameters.
Definition: gsmtpclient.h:61
GSmtp::Server::Config::processor_address
std::string processor_address
Definition: gsmtpserver.h:108
gexception.h
GSmtp::ServerProtocol::Config
A structure containing configuration parameters for ServerProtocol.
Definition: gserverprotocol.h:79
gnoncopyable.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
GSmtp::ServerPeer::onSendComplete
virtual void onSendComplete()
Final override from GNet::BufferedServerPeer.
Definition: gsmtpserver.cpp:110
GSmtp::ProtocolMessage
An interface used by the ServerProtocol class to assemble and process an incoming message...
Definition: gprotocolmessage.h:64
GSmtp::Server::Config::Config
Config(bool, unsigned int, const AddressList &, const std::string &, bool, const std::string &, unsigned int, const std::string &, unsigned int, bool)
Definition: gsmtpserver.cpp:238
GSmtp::ServerPeer::ServerPeer
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
GSmtp::Server::Config::use_connection_lookup
bool use_connection_lookup
Definition: gsmtpserver.h:114
gsmtp.h
gsmtpclient.h
GSmtp::Server::Config::verifier_address
std::string verifier_address
Definition: gsmtpserver.h:111
GNet::MultiServer
A server that listens on more than one interface using a facade pattern to multiple Server instances...
Definition: gmultiserver.h:102
GNet::BufferedServerPeer
A ServerPeer that does line-buffering on input.
Definition: gbufferedserverpeer.h:41
GNet::Server::PeerInfo
A structure used in GNet::Server::newPeer().
Definition: gserver.h:91