E-MailRelay
gfilterfactory.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 gfilterfactory.h
19///
20
21#ifndef G_FILTER_FACTORY_H
22#define G_FILTER_FACTORY_H
23
24#include "gdef.h"
25#include "gfilterfactorybase.h"
26#include "gfilestore.h"
27#include "gpath.h"
28#include "gstringview.h"
29#include <string>
30#include <utility>
31#include <memory>
32#include <cstddef> // std::nullptr_t
33
34namespace GFilters
35{
36 class FilterFactory ;
37}
38
39//| \class GFilters::FilterFactory
40/// A FilterFactory implementation. It holds a GSmtp::FileStore reference
41/// so that it can instantiate filters that operate on messages stored as
42/// files.
43///
45{
46public:
47 explicit FilterFactory( GStore::FileStore & ) ;
48 ///< Constructor. The FileStore reference is retained and passed
49 ///< to new filter objects so that they can derive the paths of
50 ///< the content and envelope files that they process.
51
52 static Spec parse( std::string_view spec , const G::Path & base_dir = {} ,
53 const G::Path & app_dir = {} , G::StringArray * warnings_p = nullptr ) ;
54 ///< Parses and validates the filter specification string returning
55 ///< the type and value in a Spec tuple, eg. ("file","/usr/bin/foo")
56 ///< or ("net","127.0.0.1:99").
57 ///<
58 ///< The specification string can be a comma-separated list with
59 ///< the component parts checked separately and the returned Spec
60 ///< is like ("chain","file:foo,net:bar").
61 ///<
62 ///< Any relative file paths are made absolute using the given
63 ///< base directory, if given. (This is normally from
64 ///< G::Process::cwd() called at startup).
65 ///<
66 ///< Any "@app" sub-strings in file paths are substituted with
67 ///< the given application directory, if given.
68 ///<
69 ///< Returns 'first' empty if a fatal parsing error, with the
70 ///< reason in 'second'.
71 ///<
72 ///< Returns warnings by reference for non-fatal errors, such
73 ///< as missing files.
74
75public:
76 ~FilterFactory() override = default ;
77 FilterFactory( const FilterFactory & ) = delete ;
78 FilterFactory( FilterFactory && ) = delete ;
79 FilterFactory & operator=( const FilterFactory & ) = delete ;
80 FilterFactory & operator=( FilterFactory && ) = delete ;
81
82protected: // overrides
83 std::unique_ptr<GSmtp::Filter> newFilter( GNet::EventState ,
84 GSmtp::Filter::Type , const GSmtp::Filter::Config & ,
85 const Spec & ) override ;
86
87private:
88 static void checkNumber( Spec & ) ;
89 static void checkNet( Spec & ) ;
90 static void checkRange( Spec & ) ;
91 static void checkFile( Spec & , G::StringArray * ) ;
92 static void fixFile( Spec & , const G::Path & , const G::Path & ) ;
93
94private:
95 GStore::FileStore & m_file_store ;
96} ;
97
98#endif
A FilterFactory implementation.
std::unique_ptr< GSmtp::Filter > newFilter(GNet::EventState, GSmtp::Filter::Type, const GSmtp::Filter::Config &, const Spec &) override
Returns a Filter on the heap.
static Spec parse(std::string_view spec, const G::Path &base_dir={}, const G::Path &app_dir={}, G::StringArray *warnings_p=nullptr)
Parses and validates the filter specification string returning the type and value in a Spec tuple,...
FilterFactory(GStore::FileStore &)
Constructor.
A lightweight object containing an ExceptionHandler pointer, optional ExceptionSource pointer and opt...
Definition: geventstate.h:131
A factory interface for making GSmtp::Filter message processors.
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:56
A Path object represents a file system path.
Definition: gpath.h:82
Message filter classes.
Definition: gcopyfilter.h:31
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30
Filter specification tuple for GSmtp::FilterFactoryBase::newFilter().
Configuration passed to filter constructors.
Definition: gfilter.h:66