23#ifndef MANIFEST_INCLUDED
24#define MANIFEST_INCLUDED
34#include <rapidjson/document.h>
35#include <rapidjson/schema.h>
41 " \"title\": \"Manifest validator version 1.0\","
42 " \"description\": \"Expected schema for version 1.0\","
43 " \"type\": \"object\","
45 " \"read_local_manifest\": {"
46 " \"description\": \"Flag to indicate that manifest information is in "
48 " \"type\": \"boolean\""
51 " \"description\": \"The list of components to be loaded at "
53 " \"type\": \"string\""
72 const std::string instance_path,
81 std::string exe_path(executable_path);
82 const std::size_t last_separator = exe_path.find_last_of(
"/\\");
83 std::string executable = exe_path.substr(last_separator + 1);
84 const std::string
path = exe_path.erase(last_separator + 1);
86 const std::size_t
ext = executable.find(
".exe");
87 executable = executable.substr(0,
ext);
89 executable.append(
".my");
90 if (instance_path.length() == 0)
96 if (!file_stream.is_open())
return;
101 ro_ = !out_stream.is_open();
105 auto file_length = file_stream.tellg();
106 if (file_length > 0) {
108 file_stream.seekg(std::ios::beg);
109 const std::unique_ptr<char[]> read_data(
110 new (std::nothrow)
char[file_length]);
111 if (!read_data)
return;
112 if (file_stream.read(read_data.get(), file_length).fail() ==
true)
return;
113 const std::string data(read_data.get(), file_length);
114 if (
data_.Parse(data).HasParseError())
return;
115 if (
schema_.Parse(json_schema).HasParseError())
return;
117 rapidjson::Document document;
118 if (document.Parse(data).HasParseError())
return;
120 const rapidjson::SchemaDocument sd(
schema_);
121 rapidjson::SchemaValidator validator(sd);
122 if (!document.Accept(validator))
return;
143 return get_element<std::string>(
"components", components_string);
160 template <
typename T>
161 bool get_element(
const std::string element_name, T &element_value)
const {
162 if (!
valid_ || !
data_.HasMember(element_name))
return false;
163 element_value =
data_[element_name].Get<T>();
Definition: manifest.h:58
bool ro() const
Definition: manifest.h:132
bool file_present() const
Definition: manifest.h:130
bool components(std::string &components_string) const
Definition: manifest.h:142
Manifest_reader(const std::string executable_path, const std::string instance_path, std::string json_schema=manifest_version_1_0)
Definition: manifest.h:71
bool empty() const
Definition: manifest.h:131
bool get_element(const std::string element_name, T &element_value) const
Get an element value from JSON document.
Definition: manifest.h:161
bool empty_
content
Definition: manifest.h:179
bool read_local_manifest() const
Definition: manifest.h:135
bool ro_
RO flag.
Definition: manifest.h:181
std::string config_file_path_
Configuration file path.
Definition: manifest.h:169
rapidjson::Document data_
Configuration data in JSON.
Definition: manifest.h:173
bool valid_
Validity of configuration data.
Definition: manifest.h:177
~Manifest_reader()=default
std::string manifest_file() const
Definition: manifest.h:133
rapidjson::Document schema_
Schema Document.
Definition: manifest.h:171
bool file_present_
File status.
Definition: manifest.h:175
Define rapidjson::SizeType to be std::size_t.
static void clean_up(bool print_message)
Definition: mysqld.cc:2646
static char * path
Definition: mysqldump.cc:140
constexpr value_type binary
Definition: classic_protocol_constants.h:274
Json_data_extension ext
Definition: backend.cc:50
Definition: manifest.h:37
std::string manifest_version_1_0
Definition: manifest.h:39
Scope_guard< TLambda > create_scope_guard(const TLambda rollback_lambda)
Definition: scope_guard.h:60