MySQL 9.3.0
Source Code Documentation
parse_file_sharing_options.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2023, 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_JSON_PARSE_FILE_SHARING_OPTIONS_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_JSON_PARSE_FILE_SHARING_OPTIONS_H_
28
29#include <map>
30#include <string>
31#include <vector>
32
33#include "mysqlrouter/base64.h"
34
37
38namespace mrs {
39namespace json {
40
42 public:
43 std::map<std::string, std::string> default_static_content_;
44 std::map<std::string, std::string> default_redirects_;
45 std::optional<std::vector<std::string>> directory_index_directive_;
46};
47
49 : public helper::json::RapidReaderHandlerToStruct<FileSharing> {
50 private:
51 template <typename T>
52 std::string to_string(const T &v) {
53 return std::to_string(v);
54 }
55 std::string to_string(const std::string &str) {
56 try {
57 return from_base64(str);
58 } catch (...) {
59 }
60 return str;
61 }
62
63 template <typename T>
64 std::string from_base64(const T &str) {
65 return to_string(str);
66 }
67
68 std::string from_base64(const std::string &str) {
70 }
71
72 template <typename Container>
73 void push_key_value(Container *c, const std::string &,
74 const std::string &value) {
75 c->push_back(value);
76 }
77
78 void push_key_value(std::map<std::string, std::string> *c,
79 const std::string &key, const std::string &value) {
80 (*c)[key] = value;
81 }
82
83 public:
84 template <typename ValueType, typename Container>
85 bool push_value_when_matches(const std::string &starts,
86 const std::string &key, const ValueType &vt,
87 Container *push_to) {
88 if (helper::starts_with(key, starts)) {
89 push_key_value(push_to, key.substr(starts.length()), to_string(vt));
90 return true;
91 }
92 return false;
93 }
94
95 template <typename ValueType>
96 void handle_array_value(const std::string &key, const ValueType &vt) {
97 static const std::string kHttpContent = "directoryIndexDirective.";
98 if (!result_.directory_index_directive_.has_value()) {
99 result_.directory_index_directive_ = std::vector<std::string>{};
100 }
101 push_value_when_matches(kHttpContent, key, vt,
102 &result_.directory_index_directive_.value());
103 }
104
105 template <typename ValueType>
106 void handle_object_value(const std::string &key, const ValueType &vt) {
107 static const std::string kHttpContent = "defaultStaticContent.";
108 static const std::string kHttpRedirects = "defaultRedirects.";
109 using std::to_string;
110
111 if (push_value_when_matches(kHttpContent, key, vt,
112 &result_.default_static_content_))
113 return;
114
115 push_value_when_matches(kHttpRedirects, key, vt,
116 &result_.default_redirects_);
117 }
118
119 template <typename ValueType>
120 void handle_value(const ValueType &vt) {
121 const auto &key = get_current_key();
122 if (is_object_path()) {
124 } else if (is_array_value()) {
126 }
127 }
128
129 bool String(const Ch *v, rapidjson::SizeType v_len, bool) override {
130 handle_value(std::string{v, v_len});
131 return true;
132 }
133
134 bool RawNumber(const Ch *v, rapidjson::SizeType v_len, bool) override {
135 handle_value(std::string{v, v_len});
136 return true;
137 }
138
139 bool Bool(bool v) override {
140 handle_value(v);
141 return true;
142 }
143};
144
145} // namespace json
146} // namespace mrs
147
148#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_JSON_PARSE_FILE_SHARING_OPTIONS_H_
static std::vector< uint8_t > decode(const std::string &encoded)
decode a base64 encoded string to binary.
Definition: base64.h:563
This class is a adapter for Reader from RapidJson.
Definition: rapid_json_to_struct.h:51
bool is_array_value()
Definition: rapid_json_to_struct.h:191
typename Parent::Ch Ch
Definition: rapid_json_to_struct.h:60
bool is_object_path()
Definition: rapid_json_to_struct.h:190
FileSharing result_
Definition: rapid_json_to_struct.h:188
std::string get_current_key() const
Definition: rapid_json_to_struct.h:194
Definition: parse_file_sharing_options.h:41
std::optional< std::vector< std::string > > directory_index_directive_
Definition: parse_file_sharing_options.h:45
std::map< std::string, std::string > default_static_content_
Definition: parse_file_sharing_options.h:43
std::map< std::string, std::string > default_redirects_
Definition: parse_file_sharing_options.h:44
Definition: parse_file_sharing_options.h:49
void handle_value(const ValueType &vt)
Definition: parse_file_sharing_options.h:120
bool String(const Ch *v, rapidjson::SizeType v_len, bool) override
Definition: parse_file_sharing_options.h:129
bool RawNumber(const Ch *v, rapidjson::SizeType v_len, bool) override
enabled via kParseNumbersAsStringsFlag, string is not null-terminated (use length)
Definition: parse_file_sharing_options.h:134
std::string to_string(const std::string &str)
Definition: parse_file_sharing_options.h:55
std::string from_base64(const T &str)
Definition: parse_file_sharing_options.h:64
void push_key_value(std::map< std::string, std::string > *c, const std::string &key, const std::string &value)
Definition: parse_file_sharing_options.h:78
bool Bool(bool v) override
Definition: parse_file_sharing_options.h:139
void handle_object_value(const std::string &key, const ValueType &vt)
Definition: parse_file_sharing_options.h:106
void handle_array_value(const std::string &key, const ValueType &vt)
Definition: parse_file_sharing_options.h:96
bool push_value_when_matches(const std::string &starts, const std::string &key, const ValueType &vt, Container *push_to)
Definition: parse_file_sharing_options.h:85
std::string to_string(const T &v)
Definition: parse_file_sharing_options.h:52
void push_key_value(Container *c, const std::string &, const std::string &value)
Definition: parse_file_sharing_options.h:73
std::string from_base64(const std::string &str)
Definition: parse_file_sharing_options.h:68
#define T
Definition: jit_executor_value.cc:373
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
std::string as_string(const Container &c)
Definition: generic.h:44
bool starts_with(const String1 &value, const String2 &search_for)
Definition: contains.h:92
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
Definition: authorize_manager.h:48
typedef::std::uint64_t SizeType
Definition: my_rapidjson_size_t.h:39
required string key
Definition: replication_asynchronous_connection_failover.proto:60