E-MailRelay
Classes | Public Types | Public Member Functions | List of all members
GSmtp::ServerProtocol Class Reference

Implements the SMTP server-side protocol. More...

#include <gsmtpserverprotocol.h>

+ Inheritance diagram for GSmtp::ServerProtocol:
+ Collaboration diagram for GSmtp::ServerProtocol:

Classes

struct  Config
 A configuration structure for GSmtp::ServerProtocol. More...
 
class  Text
 An interface used by GSmtp::ServerProtocol to provide response text strings. More...
 

Public Types

using ApplyArgsTuple = std::tuple< const char *, std::size_t, std::size_t, std::size_t, char, bool >
 

Public Member Functions

 ServerProtocol (ServerSender &, Verifier &, ProtocolMessage &, const GAuth::SaslServerSecrets &secrets, Text &text, const GNet::Address &peer_address, const Config &config, bool enabled)
 Constructor. More...
 
void setSender (ServerSender &)
 Sets the ServerSender interface, overriding the constructor parameter. More...
 
void init ()
 Starts the protocol. More...
 
 ~ServerProtocol () override
 Destructor. More...
 
bool inDataState () const
 Returns true if currently in a data-transfer state meaning that the next apply() does not need to contain a complete line of text. More...
 
bool inBusyState () const
 Returns true if in a state where the protocol is waiting for an asynchronous filter of address-verifier to complete. More...
 
bool apply (const ApplyArgsTuple &)
 Called on receipt of a complete line of text from the client, or possibly a line fragment iff this object is currently inDataState(). More...
 
void secure (const std::string &certificate, const std::string &protocol, const std::string &cipher)
 To be called when the transport protocol successfully goes into secure mode. More...
 
G::Slot::SignalchangeSignal () noexcept
 A signal that is emitted at the end of apply() or whenever the protocol state might have changed by some other mechanism (eg. More...
 
 ServerProtocol (const ServerProtocol &)=delete
 
 ServerProtocol (ServerProtocol &&)=delete
 
ServerProtocoloperator= (const ServerProtocol &)=delete
 
ServerProtocoloperator= (ServerProtocol &&)=delete
 

Detailed Description

Implements the SMTP server-side protocol.

Uses the ProtocolMessage class as its down-stream interface, used for assembling and processing the incoming email messages.

Uses the ServerSender as its "sideways" interface to talk back to the client.

RFC-2920 PIPELINING suggests that reponses are batched while the protocol is working through a batch of incoming requests. Therefore pipelined requests should be apply()ed one by one with a parameter to indicate last-in-batch.

The return value from apply() will indicate whether a request has been fully processed. If the request is not immediately fully processed then the batch iteration must be paused until a response is emitted via protocolSend(). The GSmtp::ServerBufferIn class can help with this.

Some commands (DATA, NOOP, QUIT etc) should only appear at the end of a batch of pipelined requests and the responses to these commands should force any accumulated response batch to be flushed. (See also RFC-2920 3.2 (2) (5) (6) and RFC-3030 (chunking) 4.2.) If the caller implements response batching then the 'flush' parameter on the protocolSend() callback can be used to flush the batch.

Note that RCPT-TO commands are typically in the middle of a pipelined batch and might be processed asynchronously, but they do not cause the response batch to be flushed.

Definition at line 79 of file gsmtpserverprotocol.h.

Member Typedef Documentation

◆ ApplyArgsTuple

using GSmtp::ServerProtocol::ApplyArgsTuple = std::tuple<const char *,std::size_t,std::size_t,std::size_t,char,bool>

Definition at line 84 of file gsmtpserverprotocol.h.

Constructor & Destructor Documentation

◆ ServerProtocol()

GSmtp::ServerProtocol::ServerProtocol ( ServerSender sender,
Verifier verifier,
ProtocolMessage pm,
const GAuth::SaslServerSecrets secrets,
Text text,
const GNet::Address peer_address,
const Config config,
bool  enabled 
)

Constructor.

The ServerSender interface is used to send protocol responses back to the client.

The Verifier interface is used to verify recipient addresses. See GSmtp::Verifier.

The ProtocolMessage interface is used to assemble and process an incoming message.

The Text interface is used to get informational text for returning to the client.

Definition at line 48 of file gsmtpserverprotocol.cpp.

◆ ~ServerProtocol()

GSmtp::ServerProtocol::~ServerProtocol ( )
override

Destructor.

Definition at line 124 of file gsmtpserverprotocol.cpp.

Member Function Documentation

◆ apply()

bool GSmtp::ServerProtocol::apply ( const ApplyArgsTuple &  args)

Called on receipt of a complete line of text from the client, or possibly a line fragment iff this object is currently inDataState().

Throws an error if inBusyState().

Returns false if the protocol is now inBusyState(); the caller should stop apply()ing any more data until the next ServerSender::protocolSend() callback.

Throws Done at the end of the protocol.

To allow for RFC-2920 PIPELINING the 'more' field should be set if there is another line that is ready to be apply()d. This defines an input batch and allows the ServerSender::protocolSend() callback to ask that the associated responses also get batched up on output.

Definition at line 253 of file gsmtpserverprotocol.cpp.

◆ changeSignal()

G::Slot::Signal & GSmtp::ServerProtocol::changeSignal ( )
noexcept

A signal that is emitted at the end of apply() or whenever the protocol state might have changed by some other mechanism (eg.

GSmtp::Verifier).

Definition at line 130 of file gsmtpserverprotocol.cpp.

◆ inBusyState()

bool GSmtp::ServerProtocol::inBusyState ( ) const

Returns true if in a state where the protocol is waiting for an asynchronous filter of address-verifier to complete.

A call to apply() will throw an exception when in this state.

Definition at line 135 of file gsmtpserverprotocol.cpp.

◆ inDataState()

bool GSmtp::ServerProtocol::inDataState ( ) const

Returns true if currently in a data-transfer state meaning that the next apply() does not need to contain a complete line of text.

This is typically used to enable the GNet::LineBuffer 'fragments' option.

Definition at line 186 of file gsmtpserverprotocol.cpp.

◆ init()

void GSmtp::ServerProtocol::init ( )

Starts the protocol.

Use only once after construction. The implementation uses the ServerSender interface to either send the plaintext SMTP greeting or start the TLS handshake.

Definition at line 202 of file gsmtpserverprotocol.cpp.

◆ secure()

void GSmtp::ServerProtocol::secure ( const std::string &  certificate,
const std::string &  protocol,
const std::string &  cipher 
)

To be called when the transport protocol successfully goes into secure mode.

See ServerSender::protocolSend().

Definition at line 217 of file gsmtpserverprotocol.cpp.

◆ setSender()

void GSmtp::ServerProtocol::setSender ( ServerSender sender)

Sets the ServerSender interface, overriding the constructor parameter.

Definition at line 195 of file gsmtpserverprotocol.cpp.


The documentation for this class was generated from the following files: