E-MailRelay
gfilterfactory.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 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 <string>
29#include <utility>
30#include <memory>
31#include <cstddef> // std::nullptr_t
32
33namespace GFilters
34{
35 class FilterFactory ;
36}
37
38//| \class GFilters::FilterFactory
39/// A FilterFactory implementation. It holds a GSmtp::FileStore reference
40/// so that it can instantiate filters that operate messages stored as
41/// files.
42///
44{
45public:
46 explicit FilterFactory( GStore::FileStore & ) ;
47 ///< Constructor. The FileStore reference is retained and passed
48 ///< to new filter objects so that they can derive the paths of
49 ///< the content and envelope files that they process.
50
51 static Spec parse( const std::string & spec , const G::Path & base_dir = {} ,
52 const G::Path & app_dir = {} , G::StringArray * warnings_p = nullptr ) ;
53 ///< Parses and validates the filter specification string returning
54 ///< the type and value in a Spec tuple, eg. ("file","/usr/bin/foo")
55 ///< or ("net","127.0.0.1:99").
56 ///<
57 ///< The specification string can be a comma-separated list with
58 ///< the component parts checked separately and the returned Spec
59 ///< is like ("chain","file:foo,net:bar").
60 ///<
61 ///< Any relative file paths are made absolute using the given
62 ///< base directory, if given. (This is normally from
63 ///< G::Process::cwd() called at startup).
64 ///<
65 ///< Any "@app" sub-strings in file paths are substituted with
66 ///< the given application directory, if given.
67 ///<
68 ///< Returns 'first' empty if a fatal parsing error, with the
69 ///< reason in 'second'.
70 ///<
71 ///< Returns warnings by reference for non-fatal errors, such
72 ///< as missing files.
73
74protected: // overrides
75 std::unique_ptr<GSmtp::Filter> newFilter( GNet::ExceptionSink ,
76 GSmtp::Filter::Type , const GSmtp::Filter::Config & ,
77 const Spec & ) override ;
78
79private:
80 static void checkNumber( Spec & ) ;
81 static void checkNet( Spec & ) ;
82 static void checkRange( Spec & ) ;
83 static void checkFile( Spec & , G::StringArray * ) ;
84 static void fixFile( Spec & , const G::Path & , const G::Path & ) ;
85
86private:
87 GStore::FileStore & m_file_store ;
88} ;
89
90#endif
A FilterFactory implementation.
static Spec parse(const std::string &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,...
std::unique_ptr< GSmtp::Filter > newFilter(GNet::ExceptionSink, GSmtp::Filter::Type, const GSmtp::Filter::Config &, const Spec &) override
Returns a Filter on the heap.
FilterFactory(GStore::FileStore &)
Constructor.
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
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:73
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