The Battle for Wesnoth  1.17.0-dev
validation.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Iris Morelle <shadowm2006@gmail.com>
4  Copyright (C) 2003 - 2008 by David White <dave@whitevine.net>
5  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY.
13 
14  See the COPYING file for more details.
15 */
16 
17 #pragma once
18 
19 #include <vector>
20 #include <string>
21 
22 class config;
23 
24 /**
25  * Default port number for the addon server.
26  *
27  * @note This might not be the best place to declare the variable, but it's
28  * one of the few files shared by the server and the game.
29  */
30 extern const unsigned short default_campaignd_port;
31 
32 enum class ADDON_CHECK_STATUS : unsigned int
33 {
34  //
35  // General errors
36  //
37  SUCCESS = 0x0, /**< No error */
38  UNAUTHORIZED = 0x1, /**< Authentication failed */
39  DENIED = 0x2, /**< Upload denied */
40  UNEXPECTED_DELTA = 0xD, /**< Delta for a non-existent add-on */
41  //
42  // Structure errors
43  //
44  EMPTY_PACK = 0x100, /**< Empty pack */
45  BAD_DELTA = 0x101, /**< Bad delta pack */
46  BAD_NAME = 0x102, /**< Bad add-on name */
47  NAME_HAS_MARKUP = 0x104, /**< Markup in add-on name */
48  ILLEGAL_FILENAME = 0x10A, /**< Bad filename */
49  FILENAME_CASE_CONFLICT = 0x10B, /**< Filename case conflict */
50  INVALID_UTF8_NAME = 0x1FF, /**< Invalid UTF-8 sequence in add-on name */
51  //
52  // .pbl errors
53  //
54  NO_TITLE = 0x200, /**< No title specified */
55  NO_AUTHOR = 0x201, /**< No author specified */
56  NO_VERSION = 0x202, /**< No version specified */
57  NO_DESCRIPTION = 0x203, /**< No description specified */
58  NO_EMAIL = 0x204, /**< No email specified */
59  NO_PASSPHRASE = 0x205, /**< No passphrase specified */
60  TITLE_HAS_MARKUP = 0x206, /**< Markup in add-on title */
61  BAD_TYPE = 0x207, /**< Bad add-on type */
62  VERSION_NOT_INCREMENTED = 0x208, /**< Version number is not an increment */
63  INVALID_UTF8_ATTRIBUTE = 0x2FF, /**< Invalid UTF-8 sequence in add-on metadata */
64  BAD_FEEDBACK_TOPIC_ID = 0x209, /**< The provided topic ID for the addon's feedback forum thread is invalid */
65  FEEDBACK_TOPIC_ID_NOT_FOUND = 0x2A0, /**< The provided topic ID for the addon's feedback forum thread wasn't found in the forum database */
66  //
67  // Server errors
68  //
69  SERVER_UNSPECIFIED = 0xF000, /**< Unspecified server error */
70  SERVER_READ_ONLY = 0xF001, /**< Server read-only mode on */
71  SERVER_ADDONS_LIST = 0xF002, /**< Corrupted server add-ons list */
72  SERVER_DELTA_NO_VERSIONS = 0xF003, /**< No versions to deltify against */
73 };
74 
75 std::string addon_check_status_desc(unsigned int code);
76 
78 {
79  return addon_check_status_desc(static_cast<unsigned int>(code));
80 }
81 
82 std::string translated_addon_check_status(unsigned int code);
83 
85 {
86  return translated_addon_check_status(static_cast<unsigned int>(code));
87 }
88 
89 /**
90  * Values used for add-on classification; UI-only
91  * at the moment, in the future it could be used for
92  * directory allocation too, removing the need for
93  * the ADDON_GROUP constants (TODO).
94  *
95  * @note If you change the order or content of these, you'll also need
96  * to update the @a addon_type_strings table found in validation.cpp.
97  */
98 enum ADDON_TYPE {
99  ADDON_UNKNOWN, /**< a.k.a. anything. */
100  ADDON_CORE, /**< Total Conversion Core. */
101  ADDON_SP_CAMPAIGN, /**< Single-player campaign. */
102  ADDON_SP_SCENARIO, /**< Single-player scenario. */
103  ADDON_SP_MP_CAMPAIGN, /**< Hybrid campaign. */
104  ADDON_MP_CAMPAIGN, /**< Multiplayer campaign. */
105  ADDON_MP_SCENARIO, /**< Multiplayer scenario. */
106  ADDON_MP_MAPS, /**< Multiplayer plain (no WML) map pack. */
107  ADDON_MP_ERA, /**< Multiplayer era. */
108  ADDON_MP_FACTION, /**< Multiplayer faction. */
109  // NOTE: following two still require proper engine support
110  ADDON_MOD, /**< Modification of the game. */
111  //ADDON_GUI, // GUI add-ons/themes.
112  ADDON_MEDIA, /**< Miscellaneous content/media (unit packs, terrain packs, music packs, etc.). */
113  ADDON_OTHER, /**< an add-on that fits in no other category */
115 };
116 
117 ADDON_TYPE get_addon_type(const std::string& str);
119 
120 /** Checks whether an add-on id/name is legal or not. */
121 bool addon_name_legal(const std::string& name);
122 /** Checks whether an add-on file name is legal or not. */
123 bool addon_filename_legal(const std::string& name);
124 
125 /**
126  * Scans an add-on archive for illegal names.
127  *
128  * @param dir The WML container for the root [dir] node where the search
129  * should begin.
130  * @param badlist If provided and not null, any illegal names encountered will
131  * be added to this list. This also makes the archive scan more
132  * thorough instead of returning on the first illegal name
133  * encountered.
134  *
135  * @returns True if no illegal names were found.
136  */
137 bool check_names_legal(const config& dir, std::vector<std::string>* badlist = nullptr);
138 /**
139  * Scans an add-on archive for case-conflicts.
140  *
141  * Case conflicts may cause trouble on case-insensitive filesystems.
142  *
143  * @param dir The WML container for the root [dir] node where the search
144  * should begin.
145  * @param badlist If provided and not null, any case conflicts encountered will
146  * be added to this list. This also makes the archive scan more
147  * thorough instead of returning on the first conflict
148  * encountered.
149  *
150  * @returns True if no conflicts were found.
151  */
152 bool check_case_insensitive_duplicates(const config& dir, std::vector<std::string>* badlist = nullptr);
153 
154 std::string encode_binary(const std::string& str);
155 std::string unencode_binary(const std::string& str);
156 bool needs_escaping(char c);
157 
158 std::string file_hash(const config& file);
159 bool comp_file_hash(const config& file_a, const config& file_b);
160 void write_hashlist(config& hashlist, const config& data);
161 bool contains_hashlist(const config& from, const config& to);
162 void make_updatepack(config& pack, const config& from, const config& to);
bool check_case_insensitive_duplicates(const config &dir, std::vector< std::string > *badlist=nullptr)
Scans an add-on archive for case-conflicts.
Definition: validation.cpp:176
Modification of the game.
Definition: validation.hpp:110
Single-player scenario.
Definition: validation.hpp:102
ADDON_TYPE get_addon_type(const std::string &str)
Definition: validation.cpp:180
No version specified.
ADDON_TYPE
Values used for add-on classification; UI-only at the moment, in the future it could be used for dire...
Definition: validation.hpp:98
Invalid UTF-8 sequence in add-on name.
an add-on that fits in no other category
Definition: validation.hpp:113
Total Conversion Core.
Definition: validation.hpp:100
bool contains_hashlist(const config &from, const config &to)
Definition: validation.cpp:288
std::string file_hash(const config &file)
Definition: validation.cpp:258
bool addon_name_legal(const std::string &name)
Checks whether an add-on id/name is legal or not.
Definition: validation.cpp:57
bool needs_escaping(char c)
Definition: validation.cpp:206
No versions to deltify against.
const unsigned short default_campaignd_port
Default port number for the addon server.
Definition: validation.cpp:27
Delta for a non-existent add-on.
void write_hashlist(config &hashlist, const config &data)
Definition: validation.cpp:272
Multiplayer faction.
Definition: validation.hpp:108
std::string encode_binary(const std::string &str)
Definition: validation.cpp:218
void make_updatepack(config &pack, const config &from, const config &to)
&from, &to are the top directories of their structures; addlist/removelist tag is treated as [dir] ...
Definition: validation.cpp:370
No description specified.
bool check_names_legal(const config &dir, std::vector< std::string > *badlist=nullptr)
Scans an add-on archive for illegal names.
Definition: validation.cpp:167
std::string addon_check_status_desc(unsigned int code)
Definition: validation.cpp:378
Invalid UTF-8 sequence in add-on metadata.
No email specified.
Authentication failed.
std::string get_addon_type_string(ADDON_TYPE type)
Definition: validation.cpp:196
Server read-only mode on.
Miscellaneous content/media (unit packs, terrain packs, music packs, etc.).
Definition: validation.hpp:112
bool comp_file_hash(const config &file_a, const config &file_b)
Definition: validation.cpp:267
Multiplayer scenario.
Definition: validation.hpp:105
The provided topic ID for the addon&#39;s feedback forum thread wasn&#39;t found in the forum database...
Unspecified server error.
Multiplayer era.
Definition: validation.hpp:107
std::string translated_addon_check_status(unsigned int code)
Definition: validation.cpp:528
Markup in add-on title.
Multiplayer plain (no WML) map pack.
Definition: validation.hpp:106
No title specified.
Corrupted server add-ons list.
No passphrase specified.
std::string unencode_binary(const std::string &str)
Definition: validation.cpp:236
Hybrid campaign.
Definition: validation.hpp:103
The provided topic ID for the addon&#39;s feedback forum thread is invalid.
No author specified.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
mock_char c
bool addon_filename_legal(const std::string &name)
Checks whether an add-on file name is legal or not.
Definition: validation.cpp:67
Single-player campaign.
Definition: validation.hpp:101
Multiplayer campaign.
Definition: validation.hpp:104
ADDON_CHECK_STATUS
Definition: validation.hpp:32
Version number is not an increment.