The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
blacklist.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2017 by Ignacio Riquelme Morelle <shadowm2006@gmail.com>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "config.hpp"
18 
19 namespace campaignd
20 {
21 
22 /**
23  * Add-on blacklist table.
24  *
25  * A path to a blacklist WML file may be provided in the campaignd
26  * configuration. The file's contents are used to maintain a blacklist to
27  * check certain add-on metadata fields against it every time a new or
28  * existing add-on is uploaded ([upload] request).
29  *
30  * Blacklist entries are glob patterns accepting the '*' and '?' wildcards for
31  * matching any number of characters and a single character, respectively. The
32  * lists are expected to be comma-delimited.
33  *
34  * ip = (net address masks)
35  * email = (email address patterns)
36  * name = (add-on id/dirname patterns)
37  * title = (add-on title patterns)
38  * author = (add-on author patterns)
39  * description = (add-on description patterns)
40  */
41 class blacklist
42 {
43 public:
44  typedef std::vector<std::string> globlist;
45 
46  blacklist(const blacklist&) = delete;
47  blacklist& operator=(const blacklist&) = delete;
48 
49  blacklist();
50  explicit blacklist(const config& cfg);
51 
52  void clear();
53 
54  /**
55  * Initializes the blacklist from WML.
56  *
57  * @param cfg WML node object with the contents of the [blacklist] tag.
58  */
59  void read(const config& cfg);
60 
61  /**
62  * Writes the blacklist to a WML node.
63  *
64  * @param cfg WML node object to write to. Any existing contents are
65  * erased by this method.
66  */
67  void write(config& cfg) const;
68 
69  /**
70  * Whether an add-on described by these fields is blacklisted.
71  *
72  * Empty parameters are ignored.
73  */
74  bool is_blacklisted(const std::string& name,
75  const std::string& title,
76  const std::string& description,
77  const std::string& author,
78  const std::string& ip,
79  const std::string& email) const;
80 
81 private:
82  globlist names_;
83  globlist titles_;
84  globlist descriptions_;
85 
86  globlist authors_;
87  globlist ips_;
88  globlist emails_;
89 
90  void parse_str_to_globlist(const std::string& str, globlist& glist);
91 
92  bool is_in_globlist(const std::string& str, const globlist& glist) const;
93 
94  bool is_in_ip_masklist(const std::string& ip, const globlist& mlist) const;
95  bool ip_matches(const std::string& ip, const std::string& ip_mask) const;
96 };
97 
98 }
bool ip_matches(const std::string &ip, const std::string &ip_mask) const
Definition: blacklist.cpp:126
std::vector< char_t > string
bool is_in_globlist(const std::string &str, const globlist &glist) const
Definition: blacklist.cpp:92
Definitions for the interface to Wesnoth Markup Language (WML).
void write(config &cfg) const
Writes the blacklist to a WML node.
std::pair< unsigned int, unsigned int > ip_mask
Definition: ban.hpp:52
blacklist & operator=(const blacklist &)=delete
Add-on blacklist table.
Definition: blacklist.hpp:41
bool is_in_ip_masklist(const std::string &ip, const globlist &mlist) const
Definition: blacklist.cpp:110
bool is_blacklisted(const std::string &name, const std::string &title, const std::string &description, const std::string &author, const std::string &ip, const std::string &email) const
Whether an add-on described by these fields is blacklisted.
Definition: blacklist.cpp:75
void parse_str_to_globlist(const std::string &str, globlist &glist)
Definition: blacklist.cpp:70
std::vector< std::string > globlist
Definition: blacklist.hpp:44
globlist descriptions_
Definition: blacklist.hpp:84
void read(const config &cfg)
Initializes the blacklist from WML.
Definition: blacklist.cpp:59
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93