21 #ifndef G_SMTP_SERVER_PROTOCOL_H
22 #define G_SMTP_SERVER_PROTOCOL_H
42 class ServerProtocol ;
43 class ServerProtocolText ;
61 G_EXCEPTION( ProtocolDone ,
"smtp protocol done" ) ;
64 public:
virtual void protocolSend(
const std::string & s ,
bool go_secure ) = 0 ;
73 public:
virtual ~
Sender() ;
74 private:
void operator=(
const Sender & ) ;
78 public:
virtual std::string greeting()
const = 0 ;
79 public:
virtual std::string hello(
const std::string & smtp_peer_name )
const = 0 ;
80 public:
virtual std::string received(
const std::string & smtp_peer_name ,
bool a ,
bool s )
const = 0 ;
81 public:
virtual ~
Text() ;
82 private:
void operator=(
const Text & ) ;
87 unsigned int filter_timeout ;
89 bool authentication_requires_encryption ;
90 bool mail_requires_encryption ;
91 bool disconnect_on_max_size ;
92 bool advertise_tls_if_possible ;
93 Config(
bool with_vrfy ,
unsigned int filter_timeout ,
size_t max_size ,
94 bool authentication_requires_encryption ,
95 bool mail_requires_encryption ,
96 bool advertise_tls_if_possible ) ;
127 bool apply(
const char * line_data ,
size_t line_size ,
size_t eolsize ) ;
132 void secure(
const std::string & certificate ) ;
186 typedef std::pair<const char *,size_t> EventData ;
192 void send( std::string ,
bool =
false ) ;
193 Event commandEvent(
const std::string & )
const ;
194 std::string commandWord(
const std::string & line )
const ;
195 std::string commandLine(
const std::string & line )
const ;
196 static const std::string & crlf() ;
197 bool authenticationRequiresEncryption()
const ;
199 void badClientEvent() ;
200 void processDone(
bool ,
unsigned long , std::string , std::string ) ;
201 void prepareDone(
bool ,
bool , std::string ) ;
202 bool isEndOfText(
const char * ,
size_t )
const ;
203 bool isEscaped(
const char * ,
size_t )
const ;
204 void doNoop( EventData ,
bool & ) ;
205 void doIgnore( EventData ,
bool & ) ;
206 void doNothing( EventData ,
bool & ) ;
207 void doDiscarded( EventData ,
bool & ) ;
208 void doDiscard( EventData ,
bool & ) ;
209 void doHelp( EventData ,
bool & ) ;
210 void doExpn( EventData ,
bool & ) ;
211 void doQuit( EventData ,
bool & ) ;
212 void doEhlo( EventData ,
bool & ) ;
213 void doHelo( EventData ,
bool & ) ;
214 void doAuth( EventData ,
bool & ) ;
215 void doAuthData( EventData ,
bool & ) ;
216 void doMail( EventData ,
bool & ) ;
217 void doRcpt( EventData ,
bool & ) ;
218 void doUnknown( EventData ,
bool & ) ;
219 void doRset( EventData ,
bool & ) ;
220 void doData( EventData ,
bool & ) ;
221 void doContent( EventData ,
bool & ) ;
222 void doComplete( EventData ,
bool & ) ;
223 void doEot( EventData ,
bool & ) ;
224 void doVrfy( EventData ,
bool & ) ;
225 void doVrfyReply( EventData ,
bool & ) ;
226 void doVrfyToReply( EventData ,
bool & ) ;
227 void doNoRecipients( EventData ,
bool & ) ;
228 void doStartTls( EventData ,
bool & ) ;
229 void doSecure( EventData ,
bool & ) ;
230 void verifyDone( std::string , VerifierStatus status ) ;
231 void sendBadFrom( std::string ) ;
232 void sendTooBig(
bool disconnecting =
false ) ;
233 void sendChallenge(
const std::string & ) ;
234 void sendBadTo(
const std::string & ,
bool ) ;
235 void sendOutOfSequence(
const std::string & ) ;
236 void sendGreeting(
const std::string & ) ;
238 void sendUnrecognised(
const std::string & ) ;
239 void sendNotImplemented() ;
240 void sendHeloReply() ;
241 void sendEhloReply() ;
242 void sendRsetReply() ;
243 void sendMailReply() ;
244 void sendRcptReply() ;
245 void sendDataReply() ;
246 void sendCompletionReply(
bool ok ,
const std::string & ) ;
247 void sendAuthRequired() ;
248 void sendEncryptionRequired() ;
249 void sendNoRecipients() ;
250 void sendMissingParameter() ;
251 void sendVerified(
const std::string & ) ;
252 void sendNotVerified(
const std::string & ,
bool ) ;
253 void sendWillAccept(
const std::string & ) ;
254 void sendAuthDone(
bool ok ) ;
256 std::pair<std::string,std::string> parseAddress(
const std::string & )
const ;
257 std::pair<std::string,std::string> parseMailFrom(
const std::string & )
const ;
258 std::string parseMailParameter(
const std::string & ,
const std::string & )
const ;
259 size_t parseMailSize(
const std::string & )
const ;
260 std::string parseMailAuth(
const std::string & )
const ;
261 std::pair<std::string,std::string> parseRcptTo(
const std::string & )
const ;
262 std::string parseRcptParameter(
const std::string & )
const ;
263 std::string parsePeerName(
const std::string & )
const ;
264 void verify(
const std::string & ,
const std::string & ) ;
268 Verifier & m_verifier ;
270 ProtocolMessage & m_message ;
271 unique_ptr<GAuth::SaslServer> m_sasl ;
274 bool m_with_starttls ;
277 std::string m_certificate ;
278 unsigned int m_bad_client_count ;
279 unsigned int m_bad_client_limit ;
280 std::string m_session_peer_name ;
281 bool m_session_authenticated ;
282 std::string m_buffer ;
296 virtual std::string
greeting()
const override ;
299 virtual std::string
hello(
const std::string & smtp_peer_name_from_helo )
const override ;
302 virtual std::string
received(
const std::string & smtp_peer_name_from_helo ,
303 bool authenticated ,
bool secure )
const override ;
306 static std::string
receivedLine(
const std::string & smtp_peer_name_from_helo ,
307 const std::string & peer_address ,
const std::string & thishost ,
308 bool authenticated ,
bool secure ) ;
312 std::string m_code_ident ;
313 std::string m_thishost ;
void secure(const std::string &certificate)
To be called when the transport protocol goes into secure mode.
An interface used by ServerProtocol to send protocol replies.
ServerProtocolText(const std::string &code_ident, const std::string &thishost, const GNet::Address &peer_address)
Constructor.
SMTP and message-store classes.
An interface used by ServerProtocol to provide response text strings.
The GNet::Address class encapsulates a TCP/UDP transport address.
virtual void protocolSend(const std::string &s, bool go_secure)=0
Called when the protocol class wants to send data down the socket.
Implements the SMTP server-side protocol.
virtual std::string received(const std::string &smtp_peer_name_from_helo, bool authenticated, bool secure) const override
Override from GSmtp::ServerProtocol::Text.
An asynchronous interface that verifies recipient 'to' addresses.
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 simple interface for a store of secrets used in authentication.
virtual ~ServerProtocol()
Destructor.
virtual std::string hello(const std::string &smtp_peer_name_from_helo) const override
Override from GSmtp::ServerProtocol::Text.
static std::string receivedLine(const std::string &smtp_peer_name_from_helo, const std::string &peer_address, const std::string &thishost, bool authenticated, bool secure)
Returns a standard "Received:" line.
A default implementation for the ServerProtocol::Text interface.
A structure containing configuration parameters for ServerProtocol.
An interface used by the ServerProtocol class to assemble and process an incoming message...
virtual std::string greeting() const override
Override from GSmtp::ServerProtocol::Text.
An interface used by GNet::TimerList to keep track of pending timeouts and to deliver timeout events...
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 onTimeout() override
Override from GNet::TimerBase.
virtual void protocolShutdown()=0
Called on receipt of a quit command after the quit response has been sent allowing the socket to be s...
ServerProtocol(GNet::ExceptionHandler &, Sender &, Verifier &, ProtocolMessage &, const GAuth::Secrets &secrets, Text &text, GNet::Address peer_address, Config config)
Constructor.