The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
validation.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2008 - 2025
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
22class 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 */
30extern const unsigned short default_campaignd_port;
31
32enum 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 USER_DOES_NOT_EXIST = 0x3, /**< Requested forum authentication for a user that doesn't exist on the forums */
41 UNEXPECTED_DELTA = 0xD, /**< Delta for a non-existent add-on */
42 //
43 // Structure errors
44 //
45 EMPTY_PACK = 0x100, /**< Empty pack */
46 BAD_DELTA = 0x101, /**< Bad delta pack */
47 BAD_NAME = 0x102, /**< Bad add-on name */
48 NAME_HAS_MARKUP = 0x104, /**< Markup in add-on name */
49 ILLEGAL_FILENAME = 0x10A, /**< Bad filename */
50 FILENAME_CASE_CONFLICT = 0x10B, /**< Filename case conflict */
51 INVALID_UTF8_NAME = 0x1FF, /**< Invalid UTF-8 sequence in add-on name */
52 //
53 // .pbl errors
54 //
55 NO_TITLE = 0x200, /**< No title specified */
56 NO_AUTHOR = 0x201, /**< No author specified */
57 NO_VERSION = 0x202, /**< No version specified */
58 NO_DESCRIPTION = 0x203, /**< No description specified */
59 NO_EMAIL = 0x204, /**< No email specified */
60 NO_PASSPHRASE = 0x205, /**< No passphrase specified */
61 TITLE_HAS_MARKUP = 0x206, /**< Markup in add-on title */
62 BAD_TYPE = 0x207, /**< Bad add-on type */
63 VERSION_NOT_INCREMENTED = 0x208, /**< Version number is not an increment */
64 INVALID_UTF8_ATTRIBUTE = 0x2FF, /**< Invalid UTF-8 sequence in add-on metadata */
65 BAD_FEEDBACK_TOPIC_ID = 0x209, /**< The provided topic ID for the addon's feedback forum thread is invalid */
66 FEEDBACK_TOPIC_ID_NOT_FOUND = 0x2A0, /**< The provided topic ID for the addon's feedback forum thread wasn't found in the forum database */
67 AUTH_TYPE_MISMATCH = 0x2B0, /**< The addon's forum_auth value does not match its previously set value */
68 ICON_TOO_LARGE = 0x2C0, /**< The add-on's icon is too large (presumably a DataURI) */
69 //
70 // Server errors
71 //
72 SERVER_UNSPECIFIED = 0xF000, /**< Unspecified server error */
73 SERVER_READ_ONLY = 0xF001, /**< Server read-only mode on */
74 SERVER_ADDONS_LIST = 0xF002, /**< Corrupted server add-ons list */
75 SERVER_DELTA_NO_VERSIONS = 0xF003, /**< No versions to deltify against */
76 SERVER_FORUM_AUTH_DISABLED = 0xF004, /**< The remote add-ons server does not support forum authorization */
77};
78
79std::string addon_check_status_desc(unsigned int code);
80
82{
83 return addon_check_status_desc(static_cast<unsigned int>(code));
84}
85
86std::string translated_addon_check_status(unsigned int code);
87
89{
90 return translated_addon_check_status(static_cast<unsigned int>(code));
91}
92
93/**
94 * Values used for add-on classification; UI-only
95 * at the moment, in the future it could be used for
96 * directory allocation too, removing the need for
97 * the ADDON_GROUP constants (TODO).
98 *
99 * @note If you change the order or content of these, you'll also need
100 * to update the @a addon_type_strings table found in validation.cpp.
101 */
103 ADDON_UNKNOWN, /**< a.k.a. anything. */
104 ADDON_CORE, /**< Total Conversion Core. */
105 ADDON_SP_CAMPAIGN, /**< Single-player campaign. */
106 ADDON_SP_SCENARIO, /**< Single-player scenario. */
107 ADDON_SP_MP_CAMPAIGN, /**< Hybrid campaign. */
108 ADDON_MP_CAMPAIGN, /**< Multiplayer campaign. */
109 ADDON_MP_SCENARIO, /**< Multiplayer scenario. */
110 ADDON_MP_MAPS, /**< Multiplayer plain (no WML) map pack. */
111 ADDON_MP_ERA, /**< Multiplayer era. */
112 ADDON_MP_FACTION, /**< Multiplayer faction. */
113 ADDON_MOD, /**< Modification of the game. */
114 ADDON_MEDIA, /**< Miscellaneous content/media (unit packs, terrain packs, music packs, etc.). */
115 ADDON_THEME, /**< GUI2 Themes */
116 ADDON_OTHER, /**< an add-on that fits in no other category */
119
120ADDON_TYPE get_addon_type(const std::string& str);
121std::string get_addon_type_string(ADDON_TYPE type);
122
123/** Checks whether an add-on id/name is legal or not. */
124bool addon_name_legal(const std::string& name);
125/** Checks whether an add-on file name is legal or not. */
126bool addon_filename_legal(const std::string& name);
127/** Checks whether an add-on icon is too large. */
128bool addon_icon_too_large(const std::string& icon);
129constexpr std::size_t max_icon_size = 500'000;
130
131/**
132 * Scans an add-on archive for illegal names.
133 *
134 * @param dir The WML container for the root [dir] node where the search
135 * should begin.
136 * @param badlist If provided and not null, any illegal names encountered will
137 * be added to this list. This also makes the archive scan more
138 * thorough instead of returning on the first illegal name
139 * encountered.
140 *
141 * @returns True if no illegal names were found.
142 */
143bool check_names_legal(const config& dir, std::vector<std::string>* badlist = nullptr);
144/**
145 * Scans an add-on archive for case-conflicts.
146 *
147 * Case conflicts may cause trouble on case-insensitive filesystems.
148 *
149 * @param dir The WML container for the root [dir] node where the search
150 * should begin.
151 * @param badlist If provided and not null, any case conflicts encountered will
152 * be added to this list. This also makes the archive scan more
153 * thorough instead of returning on the first conflict
154 * encountered.
155 *
156 * @returns True if no conflicts were found.
157 */
158bool check_case_insensitive_duplicates(const config& dir, std::vector<std::string>* badlist = nullptr);
159
160std::string encode_binary(const std::string& str);
161std::string unencode_binary(const std::string& str);
162bool needs_escaping(char c);
163
164std::string file_hash(const config& file);
165bool comp_file_hash(const config& file_a, const config& file_b);
166void write_hashlist(config& hashlist, const config& data);
167bool contains_hashlist(const config& from, const config& to);
168void make_updatepack(config& pack, const config& from, const config& to);
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
std::string_view data
Definition picture.cpp:188
bool addon_name_legal(const std::string &name)
Checks whether an add-on id/name is legal or not.
bool addon_icon_too_large(const std::string &icon)
Checks whether an add-on icon is too large.
bool needs_escaping(char c)
std::string file_hash(const config &file)
std::string unencode_binary(const std::string &str)
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]
ADDON_TYPE get_addon_type(const std::string &str)
bool addon_filename_legal(const std::string &name)
Checks whether an add-on file name is legal or not.
void write_hashlist(config &hashlist, const config &data)
bool contains_hashlist(const config &from, const config &to)
bool check_names_legal(const config &dir, std::vector< std::string > *badlist=nullptr)
Scans an add-on archive for illegal names.
const unsigned short default_campaignd_port
Default port number for the addon server.
std::string addon_check_status_desc(unsigned int code)
constexpr std::size_t max_icon_size
std::string translated_addon_check_status(unsigned int code)
bool check_case_insensitive_duplicates(const config &dir, std::vector< std::string > *badlist=nullptr)
Scans an add-on archive for case-conflicts.
ADDON_CHECK_STATUS
@ SERVER_ADDONS_LIST
Corrupted server add-ons list.
@ UNAUTHORIZED
Authentication failed.
@ BAD_FEEDBACK_TOPIC_ID
The provided topic ID for the addon's feedback forum thread is invalid.
@ SERVER_DELTA_NO_VERSIONS
No versions to deltify against.
@ NO_TITLE
No title specified.
@ AUTH_TYPE_MISMATCH
The addon's forum_auth value does not match its previously set value.
@ ILLEGAL_FILENAME
Bad filename.
@ ICON_TOO_LARGE
The add-on's icon is too large (presumably a DataURI)
@ NO_PASSPHRASE
No passphrase specified.
@ UNEXPECTED_DELTA
Delta for a non-existent add-on.
@ VERSION_NOT_INCREMENTED
Version number is not an increment.
@ FILENAME_CASE_CONFLICT
Filename case conflict.
@ TITLE_HAS_MARKUP
Markup in add-on title.
@ BAD_DELTA
Bad delta pack.
@ SERVER_UNSPECIFIED
Unspecified server error.
@ DENIED
Upload denied.
@ BAD_TYPE
Bad add-on type.
@ NO_AUTHOR
No author specified.
@ EMPTY_PACK
Empty pack.
@ NO_DESCRIPTION
No description specified.
@ NO_EMAIL
No email specified.
@ FEEDBACK_TOPIC_ID_NOT_FOUND
The provided topic ID for the addon's feedback forum thread wasn't found in the forum database.
@ INVALID_UTF8_NAME
Invalid UTF-8 sequence in add-on name.
@ USER_DOES_NOT_EXIST
Requested forum authentication for a user that doesn't exist on the forums.
@ INVALID_UTF8_ATTRIBUTE
Invalid UTF-8 sequence in add-on metadata.
@ SUCCESS
No error.
@ BAD_NAME
Bad add-on name.
@ NAME_HAS_MARKUP
Markup in add-on name.
@ SERVER_FORUM_AUTH_DISABLED
The remote add-ons server does not support forum authorization.
@ SERVER_READ_ONLY
Server read-only mode on.
@ NO_VERSION
No version specified.
std::string encode_binary(const std::string &str)
bool comp_file_hash(const config &file_a, const config &file_b)
ADDON_TYPE
Values used for add-on classification; UI-only at the moment, in the future it could be used for dire...
@ ADDON_UNKNOWN
a.k.a.
@ ADDON_THEME
GUI2 Themes.
@ ADDON_SP_SCENARIO
Single-player scenario.
@ ADDON_MP_SCENARIO
Multiplayer scenario.
@ ADDON_MP_CAMPAIGN
Multiplayer campaign.
@ ADDON_MP_FACTION
Multiplayer faction.
@ ADDON_TYPES_COUNT
@ ADDON_MEDIA
Miscellaneous content/media (unit packs, terrain packs, music packs, etc.).
@ ADDON_MP_ERA
Multiplayer era.
@ ADDON_CORE
Total Conversion Core.
@ ADDON_SP_CAMPAIGN
Single-player campaign.
@ ADDON_OTHER
an add-on that fits in no other category
@ ADDON_SP_MP_CAMPAIGN
Hybrid campaign.
@ ADDON_MP_MAPS
Multiplayer plain (no WML) map pack.
@ ADDON_MOD
Modification of the game.
std::string get_addon_type_string(ADDON_TYPE type)
#define c