MySQL 9.1.0
Source Code Documentation
keyring_metadata_query_service_impl_template.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
26
27#include <cstring>
28#include <functional>
29#include <memory>
30
31#include <my_dbug.h>
32#include <mysql/components/services/log_builtins.h> /* LogComponentErr */
33#include <mysqld_error.h>
34
36
38
39/**
40 Returns status of the keyring component
41
42 @param [in] callbacks Component specific callbacks
43
44 @returns Status of keyring
45 @retval true Initialized
46 @retval false Not initialized
47*/
49 Component_callbacks &callbacks) {
50 return callbacks.keyring_initialized();
51}
52
53/**
54 Initialize metadata iterator
55
56 @param [out] it Metadata iterator handle
57 @param [in] callbacks Component callback handle
58
59 @returns Status of iterator initialization
60 @retval false Success
61 @retval true Failure. Check error state.
62*/
63bool keyring_metadata_query_init_template(std::unique_ptr<config_vector> &it,
64 Component_callbacks &callbacks) {
65 try {
66 return callbacks.create_config(it);
67 } catch (...) {
68 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "init",
69 "keyring_component_metadata_query");
70 return true;
71 }
72}
73
74/**
75 Deinitialize metadata iterator
76
77 @param [in, out] it Metadata iterator handle
78
79 @returns Status of iterator deinitialization
80 @retval false Success
81 @retval true Failure. Check error state.
82*/
84 std::unique_ptr<config_vector> &it) {
85 try {
86 it.reset(nullptr);
87 return false;
88 } catch (...) {
89 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "deinit",
90 "keyring_component_metadata_query");
91 return true;
92 }
93}
94
95/**
96 Check validity of iterator
97
98 @param [in] it Metadata iterator handle
99
100 @returns Validity of the the iterator
101 @retval true Iterator valid
102 @retval false Iterator invalid
103*/
105 std::unique_ptr<config_vector> &it) {
106 try {
107 return (it != nullptr) && !it->empty();
108 } catch (...) {
109 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "is_valid",
110 "keyring_component_metadata_query");
111 return false;
112 }
113}
114
115/**
116 Move iterator forward
117
118 @param [in, out] it Metadata iterator handle
119
120 @returns Status of operation
121 @retval false Success
122 @retval true Failure.
123*/
124bool keyring_metadata_query_next_template(std::unique_ptr<config_vector> &it) {
125 try {
126 if (it->empty()) {
127 return true;
128 }
129 it->erase(it->begin());
130 return false;
131 } catch (...) {
132 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "next",
133 "keyring_component_metadata_query");
134 return true;
135 }
136}
137
138/**
139 Get length information about metadata key and value
140
141 @param [in] it Metadata iterator handle
142 @param [out] key_buffer_length Length of the key buffer
143 @param [out] value_buffer_length Length of the value buffer
144
145 @returns Get length information about key and value
146 @retval false Success check out parameters
147 @retval true Error
148*/
150 std::unique_ptr<config_vector> &it, size_t *key_buffer_length,
151 size_t *value_buffer_length) {
152 try {
153 if (it->empty()) {
154 return true;
155 }
156
157 if (key_buffer_length == nullptr || value_buffer_length == nullptr) {
158 assert(false);
159 return true;
160 }
161
162 auto key_value = (*it)[0];
163
164 // Account for null termination
165 *key_buffer_length = key_value.first.length() + 1;
166 *value_buffer_length = key_value.second.length() + 1;
167
168 return false;
169 } catch (...) {
170 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get_length",
171 "keyring_component_metadata_query");
172 return true;
173 }
174}
175
176/**
177 Get name and value of metadata at current position
178
179 @param [out] key_buffer Output buffer for key
180 @param [in] key_buffer_length Length of key buffer
181 @param [out] value_buffer Output buffer for value
182 @param [in] value_buffer_length Length of value buffer
183 @param [in] it Metadata iterator handle
184
185 @returns Status of fetch operation
186 @retval false Success
187 @retval true Failure. Check error state.
188*/
190 size_t key_buffer_length,
191 char *value_buffer,
192 size_t value_buffer_length,
193 std::unique_ptr<config_vector> &it) {
194 try {
195 if (it->empty()) {
196 return true;
197 }
198
199 auto key_value = (*it)[0];
200
201 if (key_value.first.length() >= key_buffer_length) {
202 assert(false);
203 return true;
204 }
205
206 if (key_value.second.length() >= value_buffer_length) {
207 assert(false);
208 return true;
209 }
210
211 memcpy(key_buffer, key_value.first.c_str(), key_value.first.length());
212 key_buffer[key_value.first.length()] = '\0';
213 memcpy(value_buffer, key_value.second.c_str(), key_value.second.length());
214 value_buffer[key_value.second.length()] = '\0';
215
216 return false;
217 } catch (...) {
218 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get",
219 "keyring_component_metadata_query");
220 return true;
221 }
222}
223
224} // namespace keyring_common::service_implementation
225#endif // !KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
bool create_config(std::unique_ptr< config_vector > &metadata)
Create configuration vector.
Definition: component_callbacks.cc:32
bool keyring_initialized()
Keyring component status.
Definition: component_callbacks.cc:28
@ ERROR_LEVEL
Definition: my_loglevel.h:43
Definition: keyring_encryption_service_impl_template.h:56
bool keyring_metadata_query_init_template(std::unique_ptr< config_vector > &it, Component_callbacks &callbacks)
Initialize metadata iterator.
Definition: keyring_metadata_query_service_impl_template.h:63
bool keyring_metadata_query_get_template(char *key_buffer, size_t key_buffer_length, char *value_buffer, size_t value_buffer_length, std::unique_ptr< config_vector > &it)
Get name and value of metadata at current position.
Definition: keyring_metadata_query_service_impl_template.h:189
bool keyring_metadata_query_get_length_template(std::unique_ptr< config_vector > &it, size_t *key_buffer_length, size_t *value_buffer_length)
Get length information about metadata key and value.
Definition: keyring_metadata_query_service_impl_template.h:149
bool keyring_metadata_query_keyring_initialized_template(Component_callbacks &callbacks)
Returns status of the keyring component.
Definition: keyring_metadata_query_service_impl_template.h:48
bool keyring_metadata_query_next_template(std::unique_ptr< config_vector > &it)
Move iterator forward.
Definition: keyring_metadata_query_service_impl_template.h:124
bool keyring_metadata_query_deinit_template(std::unique_ptr< config_vector > &it)
Deinitialize metadata iterator.
Definition: keyring_metadata_query_service_impl_template.h:83
bool keyring_metadata_query_is_valid_template(std::unique_ptr< config_vector > &it)
Check validity of iterator.
Definition: keyring_metadata_query_service_impl_template.h:104