E-MailRelay
gmxlookup.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2023 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// ===
17///
18/// \file gmxlookup.h
19///
20
21#ifndef G_MX_LOOKUP_H
22#define G_MX_LOOKUP_H
23
24#include "gdef.h"
25#include "gmessagestore.h"
26#include "gaddress.h"
27#include "gsocket.h"
28#include "geventhandler.h"
29#include "gdatetime.h"
30#include "gtimer.h"
31#include "gslot.h"
32#include <string>
33#include <vector>
34
35namespace GFilters
36{
37 class MxLookup ;
38}
39
40//| \class GFilters::MxLookup
41/// A DNS MX lookup client.
42///
43/// Each nameserver is queried in turn with a 'ns_timeout' interval.
44/// After the final nameserver has been queried there is a
45/// 'restart_timeout' before the sequence starts again. There is no
46/// overall timeout.
47///
49{
50public:
51 struct Config /// A configuration structure for GFilters::MxLookup
52 {
53 Config() ;
54 G::TimeInterval ns_timeout {1U,0} ;
55 G::TimeInterval restart_timeout {15U,0} ;
56 } ;
57
58 static bool enabled() ;
59 ///< Returns true if implemented.
60
61 explicit MxLookup( GNet::ExceptionSink , Config = {} ) ;
62 ///< Constructor.
63
64 explicit MxLookup( GNet::ExceptionSink , Config , const std::vector<GNet::Address> & ns ) ;
65 ///< Constructor taking a list of nameservers.
66 /// \see GNet::nameservers()
67
68 void start( const GStore::MessageId & , const std::string & question_domain , unsigned int port ) ;
69 ///< Starts the lookup.
70
72 ///< Returns a reference to the completion signal. The signal
73 ///< parameters are (1) the original message id, (2) the answer
74 ///< port-25 transport address (if successful), and (3) the
75 ///< error reason (if not).
76
77 void cancel() ;
78 ///< Cancels the lookup so the doneSignal() is not emitted.
79
80private: // overrides
81 void readEvent() override ;
82
83private:
84 void startTimer() ;
85 void onTimeout() ;
86 void sendMxQuestion( std::size_t , const std::string & ) ;
87 void sendHostQuestion( std::size_t , const std::string & ) ;
88 void fail( const std::string & ) ;
89 void succeed( const std::string & ) ;
90 void dropReadHandlers() ;
91 GNet::DatagramSocket & socket( std::size_t ) ;
92 void process( const char * , std::size_t ) ;
93 void disable( std::size_t , const std::string & ) ;
94
95private:
96 GNet::ExceptionSink m_es ;
97 Config m_config ;
98 GStore::MessageId m_message_id ;
99 std::string m_question ;
100 unsigned int m_port {0U} ;
101 std::string m_error ;
102 std::size_t m_ns_index ;
103 std::size_t m_ns_failures ;
104 std::vector<GNet::Address> m_nameservers ;
105 GNet::Timer<MxLookup> m_timer ;
106 std::unique_ptr<GNet::DatagramSocket> m_socket4 ;
107 std::unique_ptr<GNet::DatagramSocket> m_socket6 ;
109} ;
110
111#endif
A DNS MX lookup client.
Definition: gmxlookup.h:49
MxLookup(GNet::ExceptionSink, Config={})
Constructor.
Definition: gmxlookup.cpp:49
G::Slot::Signal< GStore::MessageId, std::string, std::string > & doneSignal() noexcept
Returns a reference to the completion signal.
Definition: gmxlookup.cpp:306
static bool enabled()
Returns true if implemented.
Definition: gmxlookup.cpp:43
void start(const GStore::MessageId &, const std::string &question_domain, unsigned int port)
Starts the lookup.
Definition: gmxlookup.cpp:90
void cancel()
Cancels the lookup so the doneSignal() is not emitted.
Definition: gmxlookup.cpp:249
A base class for classes that have a file descriptor and handle asynchronous events from the event lo...
Definition: geventhandler.h:48
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:141
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
An interval between two G::SystemTime values or two G::TimerTime values.
Definition: gdatetime.h:299
Message filter classes.
Definition: gcopyfilter.h:31
Network classes.
Definition: gdef.h:1144
Message store classes.
Definition: genvelope.cpp:30
STL namespace.
A configuration structure for GFilters::MxLookup.
Definition: gmxlookup.h:52