MySQL 9.1.0
Source Code Documentation
keyring_metadata_query.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_INCLUDED
25#define KEYRING_METADATA_QUERY_SERVICE_INCLUDED
26
28
30
31/**
32 @ingroup group_keyring_component_services_inventory
33
34 Keyring component status provides a way to check
35 whether keyring is active or not.
36
37 @code
38 my_service<SERVICE_TYPE(keyring_component_status)> component_status(
39 "keyring_component_status", m_reg_srv);
40 if (!component_status.is_valid()) {
41 return false;
42 }
43 return component_status->keyring_initialized();
44 @endcode
45*/
46
47BEGIN_SERVICE_DEFINITION(keyring_component_status)
48
49/**
50 Returns status of the keyring component
51
52 returns true if keyring initialized, false otherwise.
53*/
55
56END_SERVICE_DEFINITION(keyring_component_status)
57
58/**
59 @ingroup group_keyring_component_services_inventory
60
61 Keyring component metadata query service provides APIs
62 to obtain component specific metadata in string format.
63 Metadata would be in (key, value) pair.
64
65 Implementor can decide what metadata should be exposed
66 through these APIs.
67
68 One of the primary consumer of this metadata is
69 Performance schema table keyring_component_status.
70
71 @code
72 bool print_component_status() {
73 bool next_status = false;
74 my_h_keyring_component_metadata_iterator iterator = nullptr;
75 my_service<SERVICE_TYPE(keyring_component_metadata_query)>
76 metadata_query_service("keyring_component_metadata_query",
77 m_reg_srv);
78 if (!metadata_query_service.valid()) {
79 return false;
80 }
81
82 if (metadata_query_service->init(&iterator) == true) {
83 return false;
84 }
85
86 bool ok = true;
87 for (; metadata_query_service->is_valid(iterator) && next_status;
88 next_status = metadata_query_service->next(iterator)) {
89 size_t key_buffer_length = 0;
90 size_t value_buffer_length = 0;
91 if (metadata_query_service->get_length(iterator, &key_buffer_length,
92 &value_buffer_length) == true) {
93 ok = false;
94 break;
95 }
96
97 std::unique_ptr<char[]> key_buffer(new char[key_buffer_length]);
98 std::unique_ptr<char[]> value_buffer(new char[value_buffer_length]);
99
100 if (key_buffer.get() == nullptr || value_buffer.get() == nullptr) break;
101
102 memset(key_buffer.get(), 0, key_buffer_length);
103 memset(value_buffer.get(), 0, value_buffer_length);
104
105 if (metadata_query_service->get(
106 iterator, key_buffer.get(), key_buffer_length, value_buffer.get(),
107 value_buffer_length) == true) {
108 ok = false;
109 break;
110 }
111
112 std::cout << "Metadata key: " << key_buffer.get()
113 << ". Metadata value: " << value_buffer.get.get() << std::endl;
114 }
115
116 if (metadata_query_service->deinit(iterator) {
117 return false;
118 }
119
120 return ok;
121 }
122 @endcode
123*/
124
125BEGIN_SERVICE_DEFINITION(keyring_component_metadata_query)
126
127/**
128 Initialize metadata iterator. deinit should be called for clean-up.
129
130 @param [out] metadata_iterator Metadata iterator handle
131
132 @returns Status of iterator initialization
133 @retval false Success
134 @retval true Failure
135*/
137 metadata_iterator));
138
139/**
140 Deinitialize metadata iterator
141
142 @param [in, out] metadata_iterator Metadata iterator handle
143
144 @returns Status of iterator deinitialization
145 @retval false Success
146 @retval true Failure
147*/
150
151/**
152 Check validity of iterator
153
154 @param [in] metadata_iterator Metadata iterator handle
155
156 @returns Validity of the the iterator
157 @retval true Iterator valid
158 @retval false Iterator invalid
159*/
162
163/**
164 Move iterator forward
165
166 @param [in, out] metadata_iterator Metadata iterator handle
167
168 @returns Status of operation
169 @retval false Success
170 @retval true Failure. Either iterator already reached end position
171 or some other error was encountered.
172*/
175
176/**
177 Get length information about metadata key and value
178
179 @param [in] metadata_iterator Metadata iterator handle
180 @param [out] key_buffer_length Length of the key buffer
181 @param [out] value_buffer_length Length of the value buffer
182
183 @returns Get length information about key and value
184 @retval false Success
185 @retval true Failure
186*/
187DECLARE_BOOL_METHOD(get_length,
189 size_t *key_buffer_length, size_t *value_buffer_length));
190
191/**
192 Get name and value of metadata at current position
193
194 @param [in] metadata_iterator Metadata iterator handle
195 @param [out] key_buffer Output buffer for key. Byte string.
196 @param [in] key_buffer_length Length of key buffer
197 @param [out] value_buffer Output buffer for value. Byte string.
198 @param [in] value_buffer_length Length of value buffer
199
200 @returns Status of fetch operation
201 @retval false Success
202 @retval true Failure
203*/
206 char *key_buffer, size_t key_buffer_len,
207 char *value_buffer, size_t value_buffer_len));
208
209END_SERVICE_DEFINITION(keyring_component_metadata_query)
210
211#endif // !KEYRING_METADATA_INCLUDED
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:580
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
struct my_h_keyring_component_metadata_iterator_imp * my_h_keyring_component_metadata_iterator
Definition: keyring_metadata_query.h:29
bool is_valid(const dd::Spatial_reference_system *srs, const Geometry *g, const char *func_name, bool *is_valid) noexcept
Decides if a geometry is valid.
Definition: is_valid.cc:95
static mysql_service_status_t get(THD **thd) noexcept
Definition: mysql_current_thread_reader_all_empty.cc:31
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:129
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112
std::atomic< bool > is_initialized(false)