29 const std::string & server ) :
33 m_connection_timeout(config.timeout) ,
34 m_response_timeout(config.timeout)
36 G_DEBUG(
"GVerifiers::NetworkVerifier::ctor: " << server ) ;
42 m_client_ptr.eventSignal().disconnect() ;
43 m_client_ptr.deletedSignal().disconnect() ;
48 m_command = request.command ;
49 if( m_client_ptr.get() ==
nullptr )
51 unsigned int idle_timeout = 0U ;
52 m_client_ptr.reset( std::make_unique<GSmtp::RequestClient>(
55 m_location , m_connection_timeout , m_response_timeout ,
59 G_LOG(
"GVerifiers::NetworkVerifier: verification request: ["
63 args.push_back( request.address ) ;
64 args.push_back( request.from_address ) ;
66 args.push_back( m_config.domain ) ;
68 args.push_back( request.auth_extra ) ;
70 m_to_address = request.address ;
74void GVerifiers::NetworkVerifier::onException(
GNet::ExceptionSource * , std::exception & e ,
bool done )
76 bool was_busy = m_client_ptr.get() && m_client_ptr->busy() ;
77 if( m_client_ptr.get() )
78 m_client_ptr->doOnDelete( e.what() , done ) ;
79 m_client_ptr.reset() ;
83 std::string to_address = m_to_address ;
84 m_to_address.erase() ;
86 doneSignal().emit( m_command , status ) ;
90void GVerifiers::NetworkVerifier::clientEvent(
const std::string & s1 ,
const std::string & s2 ,
const std::string & )
92 G_DEBUG(
"GVerifiers::NetworkVerifier::clientEvent: [" << s1 <<
"] [" << s2 <<
"]" ) ;
95 G_LOG(
"GVerifiers::NetworkVerifier: verification response: [" <<
G::Str::printable(s2) <<
"]" ) ;
100 std::string_view s2_sv( s2 ) ;
102 std::size_t part_count = f.count() ;
103 std::string_view part_0 = f() ;
104 std::string_view part_1 = (++f)() ;
105 std::string_view part_2 = (++f)() ;
108 if( part_count && part_0 ==
"100"_sv )
110 status.is_valid = false ;
111 status.abort = true ;
113 else if( part_count >= 2U && part_0 ==
"1"_sv )
115 std::string address = G::sv_to_string( part_1 ) ;
118 else if( part_count >= 3U && part_0 ==
"0"_sv )
120 std::string mbox = G::sv_to_string( part_1 ) ;
121 std::string full_name = G::sv_to_string( part_2 ) ;
124 else if( part_count >= 2U && ( part_0 ==
"2"_sv || part_0 ==
"3"_sv ) )
126 bool temporary = part_0 ==
"3"_sv ;
127 std::string response = G::sv_to_string( part_1 ) ;
129 if( part_count >= 3U ) reason = G::sv_to_string( part_2 ) ;
131 temporary , response , reason ) ;
134 doneSignal().emit( m_command , status ) ;
140 return m_done_signal ;
143void GVerifiers::NetworkVerifier::cancel()
145 m_to_address.erase() ;
146 m_client_ptr.reset() ;
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & eventSignal() noexcept
A signal that is linked to the contained client's eventSignal().
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
static VerifierStatus local(const std::string &recipient, const std::string &full_name, const std::string &mbox)
Constructor for a valid local mailbox.
static VerifierStatus invalid(const std::string &recipient, bool temporary=false, const std::string &response={}, const std::string &reason={})
Factory function for an invalid address.
static VerifierStatus remote(const std::string &recipient, const std::string &address={})
Constructor for a valid remote mailbox.
~NetworkVerifier() override
Destructor.
NetworkVerifier(GNet::EventState, const GSmtp::Verifier::Config &config, const std::string &server)
Constructor.
std::string displayString() const
Returns a printable string that represents the transport address.
static std::string lower(std::string_view)
Returns a copy of 's' in which all seven-bit upper-case characters have been replaced by lower-case c...
static std::string join(std::string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
static std::string printable(const std::string &in, char escape='\\')
Returns a printable representation of the given input string, using chacter code ranges 0x20 to 0x7e ...
A zero-copy string field iterator where the field separators are short fixed strings.
Slot< Args... > slot(TSink &sink, void(TSink::*method)(Args...))
A factory function for Slot objects.
std::vector< std::string > StringArray
A std::vector of std::strings.
Configuration passed to address verifier constructors.
Verification request passed to various GSmtp::Verifier::verify() overrides.