The Battle for Wesnoth  1.17.0-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  ADDON_CHECK_STATUS : unsigned int {
  ADDON_CHECK_STATUS::SUCCESS = 0x0, ADDON_CHECK_STATUS::UNAUTHORIZED = 0x1, ADDON_CHECK_STATUS::DENIED = 0x2, ADDON_CHECK_STATUS::UNEXPECTED_DELTA = 0xD,
  ADDON_CHECK_STATUS::EMPTY_PACK = 0x100, ADDON_CHECK_STATUS::BAD_DELTA = 0x101, ADDON_CHECK_STATUS::BAD_NAME = 0x102, ADDON_CHECK_STATUS::NAME_HAS_MARKUP = 0x104,
  ADDON_CHECK_STATUS::ILLEGAL_FILENAME = 0x10A, ADDON_CHECK_STATUS::FILENAME_CASE_CONFLICT = 0x10B, ADDON_CHECK_STATUS::INVALID_UTF8_NAME = 0x1FF, ADDON_CHECK_STATUS::NO_TITLE = 0x200,
  ADDON_CHECK_STATUS::NO_AUTHOR = 0x201, ADDON_CHECK_STATUS::NO_VERSION = 0x202, ADDON_CHECK_STATUS::NO_DESCRIPTION = 0x203, ADDON_CHECK_STATUS::NO_EMAIL = 0x204,
  ADDON_CHECK_STATUS::NO_PASSPHRASE = 0x205, ADDON_CHECK_STATUS::TITLE_HAS_MARKUP = 0x206, ADDON_CHECK_STATUS::BAD_TYPE = 0x207, ADDON_CHECK_STATUS::VERSION_NOT_INCREMENTED = 0x208,
  ADDON_CHECK_STATUS::INVALID_UTF8_ATTRIBUTE = 0x2FF, ADDON_CHECK_STATUS::BAD_FEEDBACK_TOPIC_ID = 0x209, ADDON_CHECK_STATUS::FEEDBACK_TOPIC_ID_NOT_FOUND = 0x2A0, ADDON_CHECK_STATUS::SERVER_UNSPECIFIED = 0xF000,
  ADDON_CHECK_STATUS::SERVER_READ_ONLY = 0xF001, ADDON_CHECK_STATUS::SERVER_ADDONS_LIST = 0xF002, ADDON_CHECK_STATUS::SERVER_DELTA_NO_VERSIONS = 0xF003
}
 
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.

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.

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.

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 98 of file validation.hpp.

Function Documentation

◆ addon_check_status_desc() [1/2]

std::string addon_check_status_desc ( unsigned int  code)

◆ addon_check_status_desc() [2/2]

std::string addon_check_status_desc ( ADDON_CHECK_STATUS  code)
inline

Definition at line 77 of file validation.hpp.

References addon_check_status_desc(), and translated_addon_check_status().

◆ addon_filename_legal()

bool addon_filename_legal ( const std::string &  name)

◆ 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 267 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 
)

◆ encode_binary()

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

Definition at line 218 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 258 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 180 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 196 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 370 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 206 of file validation.cpp.

Referenced by encode_binary().

◆ translated_addon_check_status() [1/2]

std::string translated_addon_check_status ( unsigned int  code)

◆ translated_addon_check_status() [2/2]

std::string translated_addon_check_status ( ADDON_CHECK_STATUS  code)
inline

Definition at line 84 of file validation.hpp.

References translated_addon_check_status().

◆ unencode_binary()

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

Definition at line 236 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

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().