MySQL 8.2.0
Source Code Documentation
keyring_metadata_query.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2023, 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 also distributed 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 included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef KEYRING_METADATA_QUERY_SERVICE_INCLUDED
24#define KEYRING_METADATA_QUERY_SERVICE_INCLUDED
25
27
29
30/**
31 @ingroup group_keyring_component_services_inventory
32
33 Keyring component status provides a way to check
34 whether keyring is active or not.
35
36 @code
37 my_service<SERVICE_TYPE(keyring_component_status)> component_status(
38 "keyring_component_status", m_reg_srv);
39 if (!component_status.is_valid()) {
40 return false;
41 }
42 return component_status->keyring_initialized();
43 @endcode
44*/
45
46BEGIN_SERVICE_DEFINITION(keyring_component_status)
47
48/**
49 Returns status of the keyring component
50
51 returns true if keyring initialized, false otherwise.
52*/
54
55END_SERVICE_DEFINITION(keyring_component_status)
56
57/**
58 @ingroup group_keyring_component_services_inventory
59
60 Keyring component metadata query service provides APIs
61 to obtain component specific metadata in string format.
62 Metadata would be in (key, value) pair.
63
64 Implementor can decide what metadata should be exposed
65 through these APIs.
66
67 One of the primary consumer of this metadata is
68 Performance schema table keyring_component_status.
69
70 @code
71 bool print_component_status() {
72 bool next_status = false;
73 my_h_keyring_component_metadata_iterator iterator = nullptr;
74 my_service<SERVICE_TYPE(keyring_component_metadata_query)>
75 metadata_query_service("keyring_component_metadata_query",
76 m_reg_srv);
77 if (!metadata_query_service.valid()) {
78 return false;
79 }
80
81 if (metadata_query_service->init(&iterator) == true) {
82 return false;
83 }
84
85 bool ok = true;
86 for (; metadata_query_service->is_valid(iterator) && next_status;
87 next_status = metadata_query_service->next(iterator)) {
88 size_t key_buffer_length = 0;
89 size_t value_buffer_length = 0;
90 if (metadata_query_service->get_length(iterator, &key_buffer_length,
91 &value_buffer_length) == true) {
92 ok = false;
93 break;
94 }
95
96 std::unique_ptr<char[]> key_buffer(new char[key_buffer_length]);
97 std::unique_ptr<char[]> value_buffer(new char[value_buffer_length]);
98
99 if (key_buffer.get() == nullptr || value_buffer.get() == nullptr) break;
100
101 memset(key_buffer.get(), 0, key_buffer_length);
102 memset(value_buffer.get(), 0, value_buffer_length);
103
104 if (metadata_query_service->get(
105 iterator, key_buffer.get(), key_buffer_length, value_buffer.get(),
106 value_buffer_length) == true) {
107 ok = false;
108 break;
109 }
110
111 std::cout << "Metadata key: " << key_buffer.get()
112 << ". Metadata value: " << value_buffer.get.get() << std::endl;
113 }
114
115 if (metadata_query_service->deinit(iterator) {
116 return false;
117 }
118
119 return ok;
120 }
121 @endcode
122*/
123
124BEGIN_SERVICE_DEFINITION(keyring_component_metadata_query)
125
126/**
127 Initialize metadata iterator. deinit should be called for clean-up.
128
129 @param [out] metadata_iterator Metadata iterator handle
130
131 @returns Status of iterator initialization
132 @retval false Success
133 @retval true Failure
134*/
136 metadata_iterator));
137
138/**
139 Deinitialize metadata iterator
140
141 @param [in, out] metadata_iterator Metadata iterator handle
142
143 @returns Status of iterator deinitialization
144 @retval false Success
145 @retval true Failure
146*/
149
150/**
151 Check validity of iterator
152
153 @param [in] metadata_iterator Metadata iterator handle
154
155 @returns Validity of the the iterator
156 @retval true Iterator valid
157 @retval false Iterator invalid
158*/
161
162/**
163 Move iterator forward
164
165 @param [in, out] metadata_iterator Metadata iterator handle
166
167 @returns Status of operation
168 @retval false Success
169 @retval true Failure. Either iterator already reached end position
170 or some other error was encountered.
171*/
174
175/**
176 Get length information about metadata key and value
177
178 @param [in] metadata_iterator Metadata iterator handle
179 @param [out] key_buffer_length Length of the key buffer
180 @param [out] value_buffer_length Length of the value buffer
181
182 @returns Get length information about key and value
183 @retval false Success
184 @retval true Failure
185*/
186DECLARE_BOOL_METHOD(get_length,
188 size_t *key_buffer_length, size_t *value_buffer_length));
189
190/**
191 Get name and value of metadata at current position
192
193 @param [in] metadata_iterator Metadata iterator handle
194 @param [out] key_buffer Output buffer for key. Byte string.
195 @param [in] key_buffer_length Length of key buffer
196 @param [out] value_buffer Output buffer for value. Byte string.
197 @param [in] value_buffer_length Length of value buffer
198
199 @returns Status of fetch operation
200 @retval false Success
201 @retval true Failure
202*/
205 char *key_buffer, size_t key_buffer_len,
206 char *value_buffer, size_t value_buffer_len));
207
208END_SERVICE_DEFINITION(keyring_component_metadata_query)
209
210#endif // !KEYRING_METADATA_INCLUDED
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:579
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:570
struct my_h_keyring_component_metadata_iterator_imp * my_h_keyring_component_metadata_iterator
Definition: keyring_metadata_query.h:28
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:94
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_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:90
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:85
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:128
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
std::atomic< bool > is_initialized(false)