The Battle for Wesnoth  1.19.5+dev
Functions | Variables
validation.cpp File Reference
#include "addon/validation.hpp"
#include "config.hpp"
#include "filesystem.hpp"
#include "gettext.hpp"
#include "hash.hpp"
#include <algorithm>
#include <array>
#include <boost/algorithm/string.hpp>
Include dependency graph for validation.cpp:

Go to the source code of this file.

Functions

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)
 Scans an add-on archive for illegal names. More...
 
bool check_case_insensitive_duplicates (const config &dir, std::vector< std::string > *badlist)
 Scans an add-on archive for case-conflicts. More...
 
ADDON_TYPE get_addon_type (const std::string &str)
 
std::string get_addon_type_string (ADDON_TYPE type)
 
bool needs_escaping (char c)
 
std::string encode_binary (const std::string &str)
 
std::string unencode_binary (const std::string &str)
 
static std::string file_hash_raw (const config &file)
 
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)
 
static bool write_difference (config &pack, const config &from, const config &to, bool with_content)
 Surround with [dir][/dir]. More...
 
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...
 
std::string addon_check_status_desc (unsigned int code)
 
std::string translated_addon_check_status (unsigned int code)
 

Variables

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

Function Documentation

◆ addon_check_status_desc()

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 66 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 56 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 175 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 166 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 
)

Definition at line 288 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 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().

◆ file_hash_raw()

static std::string file_hash_raw ( const config file)
static

Definition at line 253 of file validation.cpp.

References utils::md5::base64_digest().

Referenced by file_hash(), and write_hashlist().

◆ 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.

References c.

Referenced by encode_binary().

◆ translated_addon_check_status()

std::string translated_addon_check_status ( unsigned int  code)

◆ 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_difference()

static bool write_difference ( config pack,
const config from,
const config to,
bool  with_content 
)
static

Surround with [dir][/dir].

Definition at line 321 of file validation.cpp.

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

Referenced by make_updatepack().

◆ write_hashlist()

void write_hashlist ( config hashlist,
const config data 
)

Variable Documentation

◆ default_campaignd_port

const unsigned short default_campaignd_port = 15019

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