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 const std::size_t last_separator = exe_path.find_last_of(
"/\\");
84 std::string executable = exe_path.substr(last_separator + 1);
85 const std::string
path = exe_path.erase(last_separator + 1);
87 const 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 const std::unique_ptr<char[]> read_data(
111 new (std::nothrow)
char[file_length]);
112 if (!read_data)
return;
113 if (file_stream.read(read_data.get(), file_length).fail() ==
true)
return;
114 const std::string data(read_data.get(), file_length);
115 if (
data_.Parse(data).HasParseError())
return;
116 if (
schema_.Parse(json_schema).HasParseError())
return;
118 rapidjson::Document document;
119 if (document.Parse(data).HasParseError())
return;
121 const rapidjson::SchemaDocument sd(
schema_);
122 rapidjson::SchemaValidator validator(sd);
123 if (!document.Accept(validator))
return;
144 return get_element<std::string>(
"components", components_string);
161 template <
typename T>
162 bool get_element(
const std::string element_name, T &element_value)
const {
163 if (!
valid_ || !
data_.HasMember(element_name))
return false;
164 element_value =
data_[element_name].Get<T>();
Definition: manifest.h:59
bool ro() const
Definition: manifest.h:133
bool file_present() const
Definition: manifest.h:131
bool components(std::string &components_string) const
Definition: manifest.h:143
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:132
bool get_element(const std::string element_name, T &element_value) const
Get an element value from JSON document.
Definition: manifest.h:162
bool empty_
content
Definition: manifest.h:180
bool read_local_manifest() const
Definition: manifest.h:136
bool ro_
RO flag.
Definition: manifest.h:182
std::string config_file_path_
Configuration file path.
Definition: manifest.h:170
rapidjson::Document data_
Configuration data in JSON.
Definition: manifest.h:174
bool valid_
Validity of configuration data.
Definition: manifest.h:178
~Manifest_reader()=default
std::string manifest_file() const
Definition: manifest.h:134
rapidjson::Document schema_
Schema Document.
Definition: manifest.h:172
bool file_present_
File status.
Definition: manifest.h:176
Define rapidjson::SizeType to be std::uint64_t.
static void clean_up(bool print_message)
Definition: mysqld.cc:2703
static char * path
Definition: mysqldump.cc:149
constexpr value_type binary
Definition: classic_protocol_constants.h:275
Json_data_extension ext
Definition: backend.cc:52
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