E-MailRelay

gnetworkfilter.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 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 gnetworkfilter.h
19///
20
21#ifndef G_NETWORK_FILTER_H
22#define G_NETWORK_FILTER_H
23
24#include "gdef.h"
25#include "gfilter.h"
26#include "gclientptr.h"
27#include "gfilestore.h"
28#include "grequestclient.h"
29#include "geventhandler.h"
30#include "goptional.h"
31#include <utility>
32
33 namespace GFilters
34{
35 class NetworkFilter ;
36}
37
38//| \class GFilters::NetworkFilter
39/// A Filter class that passes the name of a message file to a
40/// remote network server. The response of ok/abandon/fail is
41/// delivered via the base class's doneSignal().
42///
43 class GFilters::NetworkFilter : public GSmtp::Filter , private GNet::ExceptionHandler
44{
45 public:
46 NetworkFilter( GNet::EventState , GStore::FileStore & , Filter::Type ,
47 const Filter::Config & , const std::string & server_location ) ;
48 ///< Constructor.
49
50 ~NetworkFilter() override ;
51 ///< Destructor.
52
53 private: // overrides
54 std::string id() const override ; // GSmtp::Filter
55 bool quiet() const override ; // GSmtp::Filter
56 G::Slot::Signal<int> & doneSignal() noexcept override ; // GSmtp::Filter
57 void start( const GStore::MessageId & ) override ; // GSmtp::Filter
58 void cancel() override ; // GSmtp::Filter
59 Result result() const override ; // GSmtp::Filter
60 std::string response() const override ; // GSmtp::Filter
61 int responseCode() const override ; // GSmtp::Filter
62 std::string reason() const override ; // GSmtp::Filter
63 bool special() const override ; // GSmtp::Filter
64 void onException( GNet::ExceptionSource * , std::exception & , bool ) override ; // GNet::ExceptionHandler
65
66 public:
67 NetworkFilter( const NetworkFilter & ) = delete ;
68 NetworkFilter( NetworkFilter && ) = delete ;
69 NetworkFilter & operator=( const NetworkFilter & ) = delete ;
70 NetworkFilter & operator=( NetworkFilter && ) = delete ;
71
72 private:
73 void clientEvent( const std::string & , const std::string & , const std::string & ) ;
74 void sendResult( const std::string & ) ;
75 void onTimeout() ;
76 std::pair<std::string,int> responsePair() const ;
77
78 private:
79 GNet::EventState m_es ;
80 GStore::FileStore & m_file_store ;
81 GNet::ClientPtr<GSmtp::RequestClient> m_client_ptr ;
82 GNet::Timer<NetworkFilter> m_timer ;
83 G::Slot::Signal<int> m_done_signal ;
84 GNet::Location m_location ;
85 unsigned int m_connection_timeout ;
86 unsigned int m_response_timeout ;
87 std::optional<std::string> m_text ;
88 Result m_result {Result::fail} ;
89} ;
90
91#endif
GFilters::NetworkFilter
A Filter class that passes the name of a message file to a remote network server.
Definition: gnetworkfilter.h:44
GFilters::NetworkFilter::NetworkFilter
NetworkFilter(GNet::EventState, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &server_location)
Constructor.
Definition: gnetworkfilter.cpp:27
GFilters::NetworkFilter::~NetworkFilter
~NetworkFilter() override
Destructor.
Definition: gnetworkfilter.cpp:41
GNet::ClientPtr< GSmtp::RequestClient >
GNet::EventState
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
GNet::ExceptionHandler
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket/future event...
Definition: gexceptionhandler.h:44
GNet::ExceptionSource
A mixin base class that identifies the source of an exception when delivered to GNet::ExceptionHandle...
Definition: gexceptionsource.h:39
GNet::Location
A class that represents the remote target for out-going client connections.
Definition: glocation.h:70
GNet::Timer
A timer class template in which the timeout is delivered to the specified method.
Definition: gtimer.h:141
GSmtp::Filter
An interface for processing a message file through a filter.
Definition: gfilter.h:51
GStore::FileStore
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:56
GStore::MessageId
A somewhat opaque identifer for a GStore::MessageStore message id.
Definition: gmessagestore.h:43
G::optional
A class template like a simplified c++17 std::optional.
Definition: goptional.h:50
gclientptr.h
geventhandler.h
gfilestore.h
gfilter.h
goptional.h
grequestclient.h
GFilters
Message filter classes.
Definition: gcopyfilter.h:31
G::Slot::Signal< int >