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