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