MySQL 8.0.39
Source Code Documentation
keyring_keys_metadata_iterator.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_FORWARD_ITERATOR_INCLUDED
25#define KEYRING_FORWARD_ITERATOR_INCLUDED
26
28
30
31/**
32 @ingroup group_keyring_component_services_inventory
33
34 Keyring keys metadata iterator service provides APIs to create and use
35 iterator to access metadata associated with all keys stored in keyring.
36
37 @code
38 bool print_keys_metadata() {
39 char data_id[KEYRING_ITEM_BUFFER_SIZE] = "\0";
40 char auth_id[KEYRING_ITEM_BUFFER_SIZE] = "\0";
41 my_h_keyring_keys_metadata_iterator forward_iterator = nullptr;
42 my_service<SERVICE_TYPE(keyring_keys_metadata_iterator)>
43 keys_metadata_iterator("keyring_keys_metadata_iterator", m_reg_srv);
44 if (!keys_metadata_iterator.is_valid()) {
45 return true;
46 }
47
48 if (keys_metadata_iterator->init(&forward_iterator) == true) {
49 return true;
50 }
51
52 bool ok = false;
53 bool move_next = false;
54 for (; keys_metadata_iterator->is_valid(forward_iterator) && move_next;
55 move_next = !keys_metadata_iterator->next(forward_iterator)) {
56 if (keys_metadata_iterator->get(
57 forward_iterator, data_id, KEYRING_ITEM_BUFFER_SIZE, auth_id,
58 KEYRING_ITEM_BUFFER_SIZE) == true) {
59 ok = true;
60 break;
61 }
62 std::cout << "Key name: " << data_id << ". User name: " << auth_id << "."
63 << std::endl;
64 memset(data_id, 0, KEYRING_ITEM_BUFFER_SIZE);
65 memset(auth_id, 0, KEYRING_ITEM_BUFFER_SIZE);
66 }
67
68 if (keys_metadata_iterator->deinit(forward_iterator)) {
69 return true;
70 }
71 return ok;
72 }
73 @endcode
74*/
75
76BEGIN_SERVICE_DEFINITION(keyring_keys_metadata_iterator)
77
78/**
79 Forward iterator initialization.
80
81 This function allocates required memory for forward_iterator and initializes
82 it. Caller should use deinit() to perform clean-up.
83
84 An iterator may become invalid if content of keyring is changed.
85
86 @param [out] forward_iterator metadata iterator
87
88 @returns Status of the operation
89 @retval false Success
90 @retval true Failure
91*/
92
95
96/**
97 Iterator deinitialization
98
99 @note forward_iterator should not be used after call to deinit
100
101 @param [in, out] forward_iterator metadata iterator
102
103 @returns Status of the operation
104 @retval false Success
105 @retval true Failure
106*/
107
110
111/**
112 Check validity of the iterator
113
114 @param [in] forward_iterator metadata iterator
115
116 @returns Validty of the iterator
117 @retval true Success
118 @retval false Failure
119*/
122
123/**
124 Move iterator forward.
125
126 @param [in,out] forward_iterator metadata iterator
127
128 @returns Status of the operation
129 @retval false Success - indicates that iterator is pointing to next entry
130 @retval true Failure - Failure in moving iterator forward or next was
131 called after iterator reached the end.
132*/
133
136
137/**
138 Fetch length metadata for current key pointed by iterator
139
140 @param [in] forward_iterator forward_iterator metadata iterator
141 @param [out] data_id_length Length of data_id buffer
142 @param [out] auth_id_length Length of auth_id buffer
143
144 @returns Status of the operation
145 @retval false Success
146 @retval true Failure
147*/
148DECLARE_BOOL_METHOD(get_length,
149 (my_h_keyring_keys_metadata_iterator forward_iterator,
150 size_t *data_id_length, size_t *auth_id_length));
151/**
152 Fetch metadata for current key pointed by iterator
153
154 Out buffers should be big enough to accommodate data + null terminating
155 character
156
157 @param [in] forward_iterator forward_iterator metadata iterator
158 @param [out] data_id ID information of current data. Byte string.
159 @param [in] data_id_length Length of data_id buffer
160 @param [out] auth_id Owner of the key. Byte string.
161 @param [in] auth_id_length Length of auth_id buffer
162
163 @returns Status of the operation
164 @retval false Success
165 @retval true Failure
166*/
168 char *data_id, size_t data_id_length, char *auth_id,
169 size_t auth_id_length));
170
171END_SERVICE_DEFINITION(keyring_keys_metadata_iterator)
172
173#endif // !KEYRING_FORWARD_ITERATOR_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_keys_metadata_iterator_imp * my_h_keyring_keys_metadata_iterator
Definition: keyring_keys_metadata_iterator.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
void get(PSI_field *, PSI_longlong *) noexcept
Definition: pfs_plugin_column_bigint_v1_all_empty.cc:32
#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