24#ifndef MANIFEST_INCLUDED
25#define MANIFEST_INCLUDED
35#include <rapidjson/document.h>
36#include <rapidjson/schema.h>
42 " \"title\": \"Manifest validator version 1.0\","
43 " \"description\": \"Expected schema for version 1.0\","
44 " \"type\": \"object\","
46 " \"read_local_manifest\": {"
47 " \"description\": \"Flag to indicate that manifest information is in "
49 " \"type\": \"boolean\""
52 " \"description\": \"The list of components to be loaded at "
54 " \"type\": \"string\""
73 const std::string instance_path,
82 std::string exe_path(executable_path);
83 std::size_t last_separator = exe_path.find_last_of(
"/\\");
84 std::string executable = exe_path.substr(last_separator + 1);
85 std::string
path = exe_path.erase(last_separator + 1);
87 std::size_t
ext = executable.find(
".exe");
88 executable = executable.substr(0,
ext);
90 executable.append(
".my");
91 if (instance_path.length() == 0)
97 if (!file_stream.is_open())
return;
102 ro_ = !out_stream.is_open();
106 auto file_length = file_stream.tellg();
107 if (file_length > 0) {
109 file_stream.seekg(std::ios::beg);
110 std::unique_ptr<char[]> read_data(
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 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 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:59
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:72
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:2600
static char * path
Definition: mysqldump.cc:137
constexpr value_type binary
Definition: classic_protocol_constants.h:275
Json_data_extension ext
Definition: backend.cc:51
Definition: manifest.h:38
std::string manifest_version_1_0
Definition: manifest.h:40
Scope_guard< TLambda > create_scope_guard(const TLambda rollback_lambda)
Create a scope guard object.
Definition: scope_guard.h:113