MySQL 9.3.0
Source Code Documentation
url_paths.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 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_ENDPOINT_HANDLER_URL_PATHS_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_URL_PATHS_H_
28
29#include <string>
30#include <vector>
31
33#include "http/base/uri.h"
34
35namespace mrs {
36namespace endpoint {
37namespace handler {
38
39const std::string k_path_metadata_catalog = "metadata-catalog";
40const std::string k_path_id_or_query =
41 "(/([0-9]|[a-z]|[A-Z]|[-._~!$&'()*+,;=:@%]| )*/?)?";
42const std::string k_metadata = "_metadata";
43const std::string k_debug = "_debug";
44
45inline std::string regex_path_schema_catalog(
46 const std::string &service_schema_path) {
47 using namespace std::string_literals;
48 return "^"s + service_schema_path + "/"s + k_path_metadata_catalog + "/?$"s;
49}
50
52 std::string obj_name) {
53 using namespace std::string_literals;
54 auto result = uri;
55
56 result.get_path_elements().push_back(k_path_metadata_catalog);
57 if (!obj_name.empty()) {
58 if (obj_name[0] == '/') obj_name.erase(obj_name.begin());
59 }
60 result.get_path_elements().push_back(obj_name);
61 return result.join();
62}
63
65 auto u = uri;
66 u.get_path_elements().push_back(k_path_metadata_catalog);
67 return u.join();
68}
69
71 const std::string &service_schema_path, const std::string &obj_name) {
72 const std::string k_metadata_catalog = "/metadata-catalog";
73 using namespace std::string_literals;
74 return "^"s + service_schema_path + k_metadata_catalog + obj_name + "/?$"s;
75}
76
77inline std::string regex_path_service_debug(const std::string &service_path) {
78 using namespace std::string_literals;
79 return "^"s + service_path + "/"s + k_debug + "/?$"s;
80}
81
82inline std::string regex_path_service_metadata(
83 const std::string &service_path) {
84 using namespace std::string_literals;
85 return "^"s + service_path + "/"s + k_metadata + "/?$"s;
86}
87
88inline std::string regex_path_schema_metadata(
89 const std::string &service_schema_path) {
90 using namespace std::string_literals;
91 return "^"s + service_schema_path + "/"s + k_metadata + "/?$"s;
92}
93
94inline std::string regex_path_object_metadata(
95 const std::string &service_schema_path, const std::string &obj_name) {
96 using namespace std::string_literals;
97 return "^"s + service_schema_path + obj_name + "/"s + k_metadata + "/?$"s;
98}
99
101 const std::string &service_schema_path, const std::string &obj_name) {
102 const std::string k_openapi_catalog = "/open-api-catalog";
103 using namespace std::string_literals;
104 return "^"s + service_schema_path + k_openapi_catalog + obj_name + "/?$"s;
105}
106
108 const std::string &service_schema_path) {
109 const std::string k_openapi_catalog = "/open-api-catalog";
110 using namespace std::string_literals;
111 return "^"s + service_schema_path + k_openapi_catalog + "/?$"s;
112}
113
115 const std::string &service_name, const std::string &schema_name) {
116 const std::string k_openapi_catalog = "/open-api-catalog";
117 using namespace std::string_literals;
118 return "^/"s + service_name + k_openapi_catalog + "/" + schema_name + "/?$"s;
119}
120
122 const std::string &service_path) {
123 const std::string k_openapi_catalog = "/open-api-catalog";
124 using namespace std::string_literals;
125 return "^"s + service_path + k_openapi_catalog + "/?$"s;
126}
127
128inline std::string regex_path_db_object(const std::string &object_path) {
129 using namespace std::string_literals;
130 return "^"s + object_path + k_path_id_or_query + "$"s;
131}
132
133inline std::vector<std::string> regex_path_db_object_with_index(
134 const std::string &object_path, const std::string &service_schema_path,
135 const bool is_index) {
136 using namespace std::string_literals;
137 std::vector<std::string> result{"^"s + object_path + k_path_id_or_query +
138 "$"s};
139
140 if (is_index) {
141 // When the url path is empty, its root path, which
142 // http plugin processes as "", instead "/".
143 if (service_schema_path.empty())
144 result.push_back("^"s + service_schema_path + "$"s);
145 else
146 result.push_back("^"s + service_schema_path + "/$"s);
147 }
148
149 return result;
150}
151
152inline std::vector<std::string> regex_path_file(std::string service_schema_path,
153 const std::string &object_path,
154 bool is_index) {
155 using namespace std::string_literals;
156 std::vector<std::string> result{
157 {"^"s + service_schema_path + object_path + "$"s}};
158
159 if (is_index) {
160 // When the url path is empty, its root path, which
161 // http plugin processes as "", instead "/".
162 if (service_schema_path.empty())
163 result.push_back("^"s + service_schema_path + "$"s);
164 else
165 result.push_back("^"s + service_schema_path + "/$"s);
166 }
167
168 return result;
169}
170
171inline std::string remove_leading_slash_from_path(const std::string &path) {
172 if (path.empty()) return {};
173 if (path[0] == '/') return path.substr(1);
174 return {};
175}
176
177inline std::vector<std::string> regex_path_content_file(
178 const std::string &service_schema_path) {
179 return regex_path_file(service_schema_path, "",
180 helper::ends_with(service_schema_path, "/index.html"));
181}
182
183} // namespace handler
184} // namespace endpoint
185} // namespace mrs
186
187#endif /* ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_URL_PATHS_H_ \
188 */
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4618
static char * path
Definition: mysqldump.cc:150
bool ends_with(const std::string &value, const std::string &sst)
Definition: contains.h:66
Request::Uri Uri
Definition: request.cc:36
std::string regex_path_object_metadata(const std::string &service_schema_path, const std::string &obj_name)
Definition: url_paths.h:94
std::string regex_path_schema_openapi_swagger(const std::string &service_schema_path)
Definition: url_paths.h:107
std::string url_sch_metadata_catalog(const ::http::base::Uri &uri)
Definition: url_paths.h:64
const std::string k_path_id_or_query
Definition: url_paths.h:40
std::string regex_path_schema_catalog(const std::string &service_schema_path)
Definition: url_paths.h:45
std::string regex_path_obj_openapi_swagger(const std::string &service_schema_path, const std::string &obj_name)
Definition: url_paths.h:100
std::vector< std::string > regex_path_content_file(const std::string &service_schema_path)
Definition: url_paths.h:177
std::string regex_path_service_debug(const std::string &service_path)
Definition: url_paths.h:77
std::string regex_path_db_object(const std::string &object_path)
Definition: url_paths.h:128
const std::string k_path_metadata_catalog
Definition: url_paths.h:39
std::string regex_path_service_metadata(const std::string &service_path)
Definition: url_paths.h:82
std::string regex_path_obj_metadata_catalog(const std::string &service_schema_path, const std::string &obj_name)
Definition: url_paths.h:70
std::string url_obj_metadata_catalog(const ::http::base::Uri &uri, std::string obj_name)
Definition: url_paths.h:51
std::vector< std::string > regex_path_db_object_with_index(const std::string &object_path, const std::string &service_schema_path, const bool is_index)
Definition: url_paths.h:133
const std::string k_debug
Definition: url_paths.h:43
std::vector< std::string > regex_path_file(std::string service_schema_path, const std::string &object_path, bool is_index)
Definition: url_paths.h:152
std::string regex_path_schema_metadata(const std::string &service_schema_path)
Definition: url_paths.h:88
const std::string k_metadata
Definition: url_paths.h:42
std::string regex_path_schema_openapi_swagger_alias(const std::string &service_name, const std::string &schema_name)
Definition: url_paths.h:114
std::string remove_leading_slash_from_path(const std::string &path)
Definition: url_paths.h:171
std::string regex_path_service_openapi_swagger(const std::string &service_path)
Definition: url_paths.h:121
Definition: authorize_manager.h:48
struct result result
Definition: result.h:34
Definition: result.h:30