The Battle for Wesnoth  1.13.4+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 - 2016 by Ignacio Riquelme Morelle <[email protected]>
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 #ifndef CAMPAIGN_SERVER_BLACKLIST_HPP_INCLUDED
16 #define CAMPAIGN_SERVER_BLACKLIST_HPP_INCLUDED
17 
18 #include "config.hpp"
19 
20 #include <boost/noncopyable.hpp>
21 
22 namespace campaignd
23 {
24 
25 /**
26  * Add-on blacklist table.
27  *
28  * A path to a blacklist WML file may be provided in the campaignd
29  * configuration. The file's contents are used to maintain a blacklist to
30  * check certain add-on metadata fields against it every time a new or
31  * existing add-on is uploaded ([upload] request).
32  *
33  * Blacklist entries are glob patterns accepting the '*' and '?' wildcards for
34  * matching any number of characters and a single character, respectively. The
35  * lists are expected to be comma-delimited.
36  *
37  * ip = (net address masks)
38  * email = (email address patterns)
39  * name = (add-on id/dirname patterns)
40  * title = (add-on title patterns)
41  * author = (add-on author patterns)
42  * description = (add-on description patterns)
43  */
44 class blacklist : private boost::noncopyable
45 {
46 public:
47  typedef std::string glob;
48  typedef std::vector<glob> globlist;
49 
50  blacklist();
51  explicit blacklist(const config& cfg);
52 
53  void clear();
54 
55  /**
56  * Initializes the blacklist from WML.
57  *
58  * @param cfg WML node object with the contents of the [blacklist] tag.
59  */
60  void read(const config& cfg);
61 
62  /**
63  * Writes the blacklist to a WML node.
64  *
65  * @param cfg WML node object to write to. Any existing contents are
66  * erased by this method.
67  */
68  void write(config& cfg) const;
69 
70  /**
71  * Whether an add-on described by these fields is blacklisted.
72  *
73  * Empty parameters are ignored.
74  */
75  bool is_blacklisted(const std::string& name,
76  const std::string& title,
77  const std::string& description,
78  const std::string& author,
79  const std::string& ip,
80  const std::string& email) const;
81 
82 private:
83  globlist names_;
84  globlist titles_;
85  globlist descriptions_;
86 
87  globlist authors_;
88  globlist ips_;
89  globlist emails_;
90 
91  void parse_str_to_globlist(const std::string& str, globlist& glist);
92 
93  bool is_in_globlist(const std::string& str, const globlist& glist) const;
94 
95  bool is_in_ip_masklist(const std::string& ip, const globlist& mlist) const;
96  bool ip_matches(const std::string& ip, const glob& ip_mask) const;
97 };
98 
99 }
100 
101 #endif
bool is_in_globlist(const std::string &str, const globlist &glist) const
Definition: blacklist.cpp:92
std::vector< glob > globlist
Definition: blacklist.hpp:48
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:54
Add-on blacklist table.
Definition: blacklist.hpp:44
std::string glob
Definition: blacklist.hpp:47
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
globlist descriptions_
Definition: blacklist.hpp:85
GLuint const GLchar * name
Definition: glew.h:1782
void read(const config &cfg)
Initializes the blacklist from WML.
Definition: blacklist.cpp:59
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool ip_matches(const std::string &ip, const glob &ip_mask) const
Definition: blacklist.cpp:126