E-MailRelay
gfilterfactory.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2021 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.cpp
19///
20
21#include "gdef.h"
22#include "gstr.h"
23#include "gfilterfactory.h"
24#include "gnullfilter.h"
25#include "gnetworkfilter.h"
26#include "gexecutablefilter.h"
27#include "gspamfilter.h"
28#include "gexception.h"
29#include "gfactoryparser.h"
30
32 m_file_store(file_store)
33{
34}
35
37 bool server_side , const std::string & identifier , unsigned int timeout )
38{
39 FactoryParser::Result p = FactoryParser::parse( identifier , true ) ;
40 if( p.first.empty() )
41 {
42 return std::make_unique<NullFilter>( es , server_side ) ; // up-cast
43 }
44 else if( p.first == "spam" )
45 {
46 // "spam:" is read-only, not-always-pass
47 // "spam-edit:" is read-write, always-pass
48 bool edit = p.third == 1 ;
49 bool read_only = !edit ;
50 bool always_pass = edit ;
51 return std::make_unique<SpamFilter>( es , m_file_store , p.second , read_only , always_pass , timeout , timeout ) ; // up-cast
52 }
53 else if( p.first == "net" )
54 {
55 return std::make_unique<NetworkFilter>( es , m_file_store , p.second , timeout , timeout ) ; // up-cast
56 }
57 else if( p.first == "exit" )
58 {
59 return std::make_unique<NullFilter>( es , server_side , G::Str::toUInt(p.second) ) ; // up-cast
60 }
61 else
62 {
63 return std::make_unique<ExecutableFilter>( es , m_file_store , server_side , p.second , timeout ) ; // up-cast
64 }
65}
66
A tuple containing an ExceptionHandler interface pointer and a bound 'exception source' pointer.
static Result parse(const std::string &identifier, bool allow_spam)
Parses an identifier like "/usr/bin/foo" or "net:127.0.0.1:99" or "net:/run/spamd....
A concrete implementation of the MessageStore interface dealing in paired flat files.
Definition: gfilestore.h:58
FilterFactoryFileStore(FileStore &)
Constructor.
std::unique_ptr< Filter > newFilter(GNet::ExceptionSink, bool server_side, const std::string &identifier, unsigned int timeout) override
Returns a Filter on the heap.
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
Definition: gstr.cpp:604
Result tuple for GSmtp::FactoryParser::parse().