The Battle for Wesnoth  1.19.4+dev
Enumerations | Functions | Variables
validation.hpp File Reference
#include <vector>
#include <string>
Include dependency graph for validation.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  ADDON_CHECK_STATUS : unsigned int {
  SUCCESS = 0x0 , UNAUTHORIZED = 0x1 , DENIED = 0x2 , USER_DOES_NOT_EXIST = 0x3 ,
  UNEXPECTED_DELTA = 0xD , EMPTY_PACK = 0x100 , BAD_DELTA = 0x101 , BAD_NAME = 0x102 ,
  NAME_HAS_MARKUP = 0x104 , ILLEGAL_FILENAME = 0x10A , FILENAME_CASE_CONFLICT = 0x10B , INVALID_UTF8_NAME = 0x1FF ,
  NO_TITLE = 0x200 , NO_AUTHOR = 0x201 , NO_VERSION = 0x202 , NO_DESCRIPTION = 0x203 ,
  NO_EMAIL = 0x204 , NO_PASSPHRASE = 0x205 , TITLE_HAS_MARKUP = 0x206 , BAD_TYPE = 0x207 ,
  VERSION_NOT_INCREMENTED = 0x208 , INVALID_UTF8_ATTRIBUTE = 0x2FF , BAD_FEEDBACK_TOPIC_ID = 0x209 , FEEDBACK_TOPIC_ID_NOT_FOUND = 0x2A0 ,
  AUTH_TYPE_MISMATCH = 0x2B0 , SERVER_UNSPECIFIED = 0xF000 , SERVER_READ_ONLY = 0xF001 , SERVER_ADDONS_LIST = 0xF002 ,
  SERVER_DELTA_NO_VERSIONS = 0xF003 , SERVER_FORUM_AUTH_DISABLED = 0xF004
}
 
enum  ADDON_TYPE {
  ADDON_UNKNOWN , ADDON_CORE , ADDON_SP_CAMPAIGN , ADDON_SP_SCENARIO ,
  ADDON_SP_MP_CAMPAIGN , ADDON_MP_CAMPAIGN , ADDON_MP_SCENARIO , ADDON_MP_MAPS ,
  ADDON_MP_ERA , ADDON_MP_FACTION , ADDON_MOD , ADDON_MEDIA ,
  ADDON_OTHER , ADDON_TYPES_COUNT
}
 Values used for add-on classification; UI-only at the moment, in the future it could be used for directory allocation too, removing the need for the ADDON_GROUP constants (TODO). More...
 

Functions

std::string addon_check_status_desc (unsigned int code)
 
std::string addon_check_status_desc (ADDON_CHECK_STATUS code)
 
std::string translated_addon_check_status (unsigned int code)
 
std::string translated_addon_check_status (ADDON_CHECK_STATUS code)
 
ADDON_TYPE get_addon_type (const std::string &str)
 
std::string get_addon_type_string (ADDON_TYPE type)
 
bool addon_name_legal (const std::string &name)
 Checks whether an add-on id/name is legal or not. More...
 
bool addon_filename_legal (const std::string &name)
 Checks whether an add-on file name is legal or not. More...
 
bool check_names_legal (const config &dir, std::vector< std::string > *badlist=nullptr)
 Scans an add-on archive for illegal names. More...
 
bool check_case_insensitive_duplicates (const config &dir, std::vector< std::string > *badlist=nullptr)
 Scans an add-on archive for case-conflicts. More...
 
std::string encode_binary (const std::string &str)
 
std::string unencode_binary (const std::string &str)
 
bool needs_escaping (char c)
 
std::string file_hash (const config &file)
 
bool comp_file_hash (const config &file_a, const config &file_b)
 
void write_hashlist (config &hashlist, const config &data)
 
bool contains_hashlist (const config &from, const config &to)
 
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] More...
 

Variables

const unsigned short default_campaignd_port
 Default port number for the addon server. More...
 

Enumeration Type Documentation

◆ ADDON_CHECK_STATUS

enum ADDON_CHECK_STATUS : unsigned int
strong
Enumerator
SUCCESS 

No error.

UNAUTHORIZED 

Authentication failed.

DENIED 

Upload denied.

USER_DOES_NOT_EXIST 

Requested forum authentication for a user that doesn't exist on the forums.

UNEXPECTED_DELTA 

Delta for a non-existent add-on.

EMPTY_PACK 

Empty pack.

BAD_DELTA 

Bad delta pack.

BAD_NAME 

Bad add-on name.

NAME_HAS_MARKUP 

Markup in add-on name.

ILLEGAL_FILENAME 

Bad filename.

FILENAME_CASE_CONFLICT 

Filename case conflict.

INVALID_UTF8_NAME 

Invalid UTF-8 sequence in add-on name.

NO_TITLE 

No title specified.

NO_AUTHOR 

No author specified.

NO_VERSION 

No version specified.

NO_DESCRIPTION 

No description specified.

NO_EMAIL 

No email specified.

NO_PASSPHRASE 

No passphrase specified.

TITLE_HAS_MARKUP 

Markup in add-on title.

BAD_TYPE 

Bad add-on type.

VERSION_NOT_INCREMENTED 

Version number is not an increment.

INVALID_UTF8_ATTRIBUTE 

Invalid UTF-8 sequence in add-on metadata.

BAD_FEEDBACK_TOPIC_ID 

The provided topic ID for the addon's feedback forum thread is invalid.

FEEDBACK_TOPIC_ID_NOT_FOUND 

The provided topic ID for the addon's feedback forum thread wasn't found in the forum database.

AUTH_TYPE_MISMATCH 

The addon's forum_auth value does not match its previously set value.

SERVER_UNSPECIFIED 

Unspecified server error.

SERVER_READ_ONLY 

Server read-only mode on.

SERVER_ADDONS_LIST 

Corrupted server add-ons list.

SERVER_DELTA_NO_VERSIONS 

No versions to deltify against.

SERVER_FORUM_AUTH_DISABLED 

The remote add-ons server does not support forum authorization.

Definition at line 32 of file validation.hpp.

◆ ADDON_TYPE

enum ADDON_TYPE

Values used for add-on classification; UI-only at the moment, in the future it could be used for directory allocation too, removing the need for the ADDON_GROUP constants (TODO).

Note
If you change the order or content of these, you'll also need to update the addon_type_strings table found in validation.cpp.
Enumerator
ADDON_UNKNOWN 

a.k.a.

anything.

ADDON_CORE 

Total Conversion Core.

ADDON_SP_CAMPAIGN 

Single-player campaign.

ADDON_SP_SCENARIO 

Single-player scenario.

ADDON_SP_MP_CAMPAIGN 

Hybrid campaign.

ADDON_MP_CAMPAIGN 

Multiplayer campaign.

ADDON_MP_SCENARIO 

Multiplayer scenario.

ADDON_MP_MAPS 

Multiplayer plain (no WML) map pack.

ADDON_MP_ERA 

Multiplayer era.

ADDON_MP_FACTION 

Multiplayer faction.

ADDON_MOD 

Modification of the game.

ADDON_MEDIA 

Miscellaneous content/media (unit packs, terrain packs, music packs, etc.).

ADDON_OTHER 

an add-on that fits in no other category

ADDON_TYPES_COUNT 

Definition at line 101 of file validation.hpp.

Function Documentation

◆ addon_check_status_desc() [1/2]

std::string addon_check_status_desc ( ADDON_CHECK_STATUS  code)
inline

Definition at line 80 of file validation.hpp.

References addon_check_status_desc().

◆ addon_check_status_desc() [2/2]

std::string addon_check_status_desc ( unsigned int  code)

◆ addon_filename_legal()

bool addon_filename_legal ( const std::string &  name)

Checks whether an add-on file name is legal or not.

Definition at line 67 of file validation.cpp.

References filesystem::is_legal_user_file_name().

Referenced by BOOST_AUTO_TEST_CASE(), editor::context_manager::change_addon_id(), and editor::initialize_addon().

◆ addon_name_legal()

bool addon_name_legal ( const std::string &  name)

Checks whether an add-on id/name is legal or not.

Definition at line 57 of file validation.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), addons_client::upload_addon(), and campaignd::server::validate_addon().

◆ check_case_insensitive_duplicates()

bool check_case_insensitive_duplicates ( const config dir,
std::vector< std::string > *  badlist = nullptr 
)

Scans an add-on archive for case-conflicts.

Case conflicts may cause trouble on case-insensitive filesystems.

Parameters
dirThe WML container for the root [dir] node where the search should begin.
badlistIf provided and not null, any case conflicts encountered will be added to this list. This also makes the archive scan more thorough instead of returning on the first conflict encountered.
Returns
True if no conflicts were found.

Definition at line 176 of file validation.cpp.

Referenced by addons_client::install_addon(), and addons_client::upload_addon().

◆ check_names_legal()

bool check_names_legal ( const config dir,
std::vector< std::string > *  badlist = nullptr 
)

Scans an add-on archive for illegal names.

Parameters
dirThe WML container for the root [dir] node where the search should begin.
badlistIf provided and not null, any illegal names encountered will be added to this list. This also makes the archive scan more thorough instead of returning on the first illegal name encountered.
Returns
True if no illegal names were found.

Definition at line 167 of file validation.cpp.

Referenced by addons_client::install_addon(), and addons_client::upload_addon().

◆ comp_file_hash()

bool comp_file_hash ( const config file_a,
const config file_b 
)

Definition at line 268 of file validation.cpp.

References file_hash().

Referenced by contains_hashlist(), and write_difference().

◆ contains_hashlist()

bool contains_hashlist ( const config from,
const config to 
)

Definition at line 289 of file validation.cpp.

References config::child_range(), comp_file_hash(), d, f, and config::find_child().

Referenced by addons_client::upload_addon().

◆ encode_binary()

std::string encode_binary ( const std::string &  str)

Definition at line 219 of file validation.cpp.

References n, and needs_escaping().

Referenced by archive_file(), and BOOST_AUTO_TEST_CASE().

◆ file_hash()

std::string file_hash ( const config file)

Definition at line 259 of file validation.cpp.

References file_hash_raw().

Referenced by comp_file_hash(), and write_difference().

◆ get_addon_type()

ADDON_TYPE get_addon_type ( const std::string &  str)

Definition at line 181 of file validation.cpp.

References ADDON_TYPES_COUNT, and ADDON_UNKNOWN.

Referenced by addon_info::read(), and campaignd::server::validate_addon().

◆ get_addon_type_string()

std::string get_addon_type_string ( ADDON_TYPE  type)

Definition at line 197 of file validation.cpp.

References ADDON_TYPES_COUNT.

Referenced by addon_info::write(), and addon_info::write_minimal().

◆ make_updatepack()

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]

Does it worth it to archive and write the pack on the fly using config_writer? TODO: clientside verification?

Definition at line 371 of file validation.cpp.

References config::add_child(), and write_difference().

Referenced by campaignd::server::handle_upload(), and addons_client::upload_addon().

◆ needs_escaping()

bool needs_escaping ( char  c)

Definition at line 207 of file validation.cpp.

References c.

Referenced by encode_binary().

◆ translated_addon_check_status() [1/2]

std::string translated_addon_check_status ( ADDON_CHECK_STATUS  code)
inline

Definition at line 87 of file validation.hpp.

References translated_addon_check_status().

◆ translated_addon_check_status() [2/2]

std::string translated_addon_check_status ( unsigned int  code)

◆ unencode_binary()

std::string unencode_binary ( const std::string &  str)

Definition at line 237 of file validation.cpp.

References c, and n.

Referenced by BOOST_AUTO_TEST_CASE(), and unarchive_file().

◆ write_hashlist()

void write_hashlist ( config hashlist,
const config data 
)

Variable Documentation

◆ default_campaignd_port

const unsigned short default_campaignd_port
extern

Default port number for the addon server.

Note
This might not be the best place to declare the variable, but it's one of the few files shared by the server and the game.

Definition at line 27 of file validation.cpp.

Referenced by addons_client::addons_client(), and campaignd::server::load_config().