E-MailRelay

gexecutablefilter.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 gexecutablefilter.h
19///
20
21#ifndef G_EXECUTABLE_FILTER_H
22#define G_EXECUTABLE_FILTER_H
23
24#include "gdef.h"
25#include "gpath.h"
26#include "gfilter.h"
27#include "gfilestore.h"
28#include "geventhandler.h"
29#include "gfutureevent.h"
30#include "gtimer.h"
31#include "gtask.h"
32#include <utility>
33#include <tuple>
34
35 namespace GFilters
36{
37 class ExecutableFilter ;
38}
39
40//| \class GFilters::ExecutableFilter
41/// A Filter class that runs an external helper program.
42///
43 class GFilters::ExecutableFilter : public GSmtp::Filter, private GNet::TaskCallback
44{
45 public:
46 ExecutableFilter( GNet::EventState , GStore::FileStore & , Filter::Type ,
47 const Filter::Config & , const std::string & path ) ;
48 ///< Constructor.
49
50 ~ExecutableFilter() 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 onTaskDone( int , const std::string & ) override ; // GNet::TaskCallback
65
66public:
67 ExecutableFilter( const ExecutableFilter & ) = delete ;
68 ExecutableFilter( ExecutableFilter && ) = delete ;
69 ExecutableFilter & operator=( const ExecutableFilter & ) = delete ;
70 ExecutableFilter & operator=( ExecutableFilter && ) = delete ;
71
72private:
73 static std::tuple<std::string,int,std::string> parseOutput( std::string , const std::string & ) ;
74 void onTimeout() ;
75 std::string prefix() const ;
76
77private:
78 GStore::FileStore & m_file_store ;
79 G::Slot::Signal<int> m_done_signal ;
80 Filter::Type m_filter_type ;
81 Exit m_exit ;
82 G::Path m_path ;
83 unsigned int m_timeout ;
84 GNet::Timer<ExecutableFilter> m_timer ;
85 std::string m_response ;
86 int m_response_code {0} ;
87 std::string m_reason ;
88 GNet::Task m_task ;
89} ;
90
91#endif
GFilters::ExecutableFilter
A Filter class that runs an external helper program.
Definition: gexecutablefilter.h:44
GFilters::ExecutableFilter::ExecutableFilter
ExecutableFilter(GNet::EventState, GStore::FileStore &, Filter::Type, const Filter::Config &, const std::string &path)
Constructor.
Definition: gexecutablefilter.cpp:32
GFilters::ExecutableFilter::~ExecutableFilter
~ExecutableFilter() override
Destructor.
GNet::EventState
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
GNet::TaskCallback
An abstract interface for callbacks from GNet::Task.
Definition: gtask.h:114
GNet::Task
A class for running an exectuable in a separate process with an asychronous completion callback.
Definition: gtask.h:46
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
geventhandler.h
gfilestore.h
gfilter.h
gfutureevent.h
gpath.h
gtask.h
gtimer.h
GFilters
Message filter classes.
Definition: gcopyfilter.h:31
GNet
Network classes.
Definition: gdef.h:1243
GStore
Message store classes.
Definition: genvelope.cpp:30
G
Low-level classes.
Definition: garg.h:36
std
STL namespace.
GSmtp::Filter::Exit
Interprets an executable filter's exit code.
Definition: gfilter.h:126
G::Slot::Signal< int >