blob: 88bf653f674d6dd028d019e5e37ba486a02df141 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <filtercontainer.h>
#include <exceptions.h>
#include <matcher.h>
#include <utils.h>
#include <config.h>
namespace newsbeuter {
filtercontainer::~filtercontainer() { }
void filtercontainer::handle_action(const std::string& action, const std::vector<std::string>& params) {
/*
* filtercontainer does nothing but to save (filter name, filter expression) tuples.
* These tuples are used for enabling the user to predefine filter expressions and
* then select them from a list by their name.
*/
if (action == "define-filter") {
if (params.size() < 2)
throw confighandlerexception(AHS_TOO_FEW_PARAMS);
matcher m;
if (!m.parse(params[1]))
throw confighandlerexception(utils::strprintf(_("couldn't parse filter expression `%s': %s"), params[1].c_str(), m.get_parse_error().c_str()));
filters.push_back(filter_name_expr_pair(params[0],params[1]));
} else
throw confighandlerexception(AHS_INVALID_COMMAND);
}
void filtercontainer::dump_config(std::vector<std::string>& config_output) {
for (std::vector<filter_name_expr_pair>::iterator it=filters.begin();it!=filters.end();it++) {
config_output.push_back(utils::strprintf("define-filter %s %s", utils::quote(it->first).c_str(), utils::quote(it->second).c_str()));
}
}
}
|