| 1 |
/* Copyright (c) 2021, 2026, Oracle and/or its affiliates. |
| 2 |
|
| 3 |
This program is free software; you can redistribute it and/or modify |
| 4 |
it under the terms of the GNU General Public License, version 2.0, |
| 5 |
as published by the Free Software Foundation. |
| 6 |
|
| 7 |
This program is designed to work with certain software (including |
| 8 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 9 |
as designated in a particular file or component or in included license |
| 10 |
documentation. The authors of MySQL hereby grant you an additional |
| 11 |
permission to link the program and your derivative works with the |
| 12 |
separately licensed software that they have either included with |
| 13 |
the program or referenced in the documentation. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License, version 2.0, for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program; if not, write to the Free Software |
| 22 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 |
|
| 24 |
#include <components/keyrings/keyring_file/keyring_file.h> |
| 25 |
|
| 26 |
#include <components/keyrings/common/component_helpers/include/keyring_metadata_query_service_definition.h> |
| 27 |
#include <components/keyrings/common/component_helpers/include/keyring_metadata_query_service_impl_template.h> |
| 28 |
|
| 29 |
using keyring_file::g_component_callbacks; |
| 30 |
namespace keyring_common { |
| 31 |
|
| 32 |
using service_implementation::config_vector; |
| 33 |
using service_implementation::keyring_metadata_query_deinit_template; |
| 34 |
using service_implementation::keyring_metadata_query_get_length_template; |
| 35 |
using service_implementation::keyring_metadata_query_get_template; |
| 36 |
using service_implementation::keyring_metadata_query_init_template; |
| 37 |
using service_implementation::keyring_metadata_query_is_valid_template; |
| 38 |
using service_implementation:: |
| 39 |
keyring_metadata_query_keyring_initialized_template; |
| 40 |
using service_implementation::keyring_metadata_query_next_template; |
| 41 |
|
| 42 |
namespace service_definition { |
| 43 |
|
| 44 |
DEFINE_BOOL_METHOD(Keyring_metadata_query_service_impl::is_initialized, ()) { |
| 45 |
return keyring_metadata_query_keyring_initialized_template( |
| 46 |
*g_component_callbacks); |
| 47 |
} |
| 48 |
|
| 49 |
DEFINE_BOOL_METHOD(Keyring_metadata_query_service_impl::init, |
| 50 |
(my_h_keyring_component_metadata_iterator * |
| 51 |
metadata_iterator)) { |
| 52 |
*metadata_iterator = nullptr; |
| 53 |
std::unique_ptr<config_vector> it; |
| 54 |
bool retval = |
| 55 |
keyring_metadata_query_init_template(it, *g_component_callbacks); |
| 56 |
if (retval == false) |
| 57 |
*metadata_iterator = |
| 58 |
reinterpret_cast<my_h_keyring_component_metadata_iterator>( |
| 59 |
it.release()); |
| 60 |
return retval; |
| 61 |
} |
| 62 |
|
| 63 |
DEFINE_BOOL_METHOD( |
| 64 |
Keyring_metadata_query_service_impl::deinit, |
| 65 |
(my_h_keyring_component_metadata_iterator metadata_iterator)) { |
| 66 |
std::unique_ptr<config_vector> it; |
| 67 |
it.reset(reinterpret_cast<config_vector *>(metadata_iterator)); |
| 68 |
return keyring_metadata_query_deinit_template(it); |
| 69 |
} |
| 70 |
|
| 71 |
DEFINE_BOOL_METHOD( |
| 72 |
Keyring_metadata_query_service_impl::is_valid, |
| 73 |
(my_h_keyring_component_metadata_iterator metadata_iterator)) { |
| 74 |
std::unique_ptr<config_vector> it; |
| 75 |
it.reset(reinterpret_cast<config_vector *>(metadata_iterator)); |
| 76 |
bool retval = keyring_metadata_query_is_valid_template(it); |
| 77 |
(void)it.release(); |
| 78 |
return retval; |
| 79 |
} |
| 80 |
|
| 81 |
DEFINE_BOOL_METHOD( |
| 82 |
Keyring_metadata_query_service_impl::next, |
| 83 |
(my_h_keyring_component_metadata_iterator metadata_iterator)) { |
| 84 |
std::unique_ptr<config_vector> it; |
| 85 |
it.reset(reinterpret_cast<config_vector *>(metadata_iterator)); |
| 86 |
bool retval = keyring_metadata_query_next_template(it); |
| 87 |
(void)it.release(); |
| 88 |
return retval; |
| 89 |
} |
| 90 |
|
| 91 |
DEFINE_BOOL_METHOD(Keyring_metadata_query_service_impl::get_length, |
| 92 |
(my_h_keyring_component_metadata_iterator metadata_iterator, |
| 93 |
size_t *key_buffer_length, size_t *value_buffer_length)) { |
| 94 |
std::unique_ptr<config_vector> it; |
| 95 |
it.reset(reinterpret_cast<config_vector *>(metadata_iterator)); |
| 96 |
bool retval = keyring_metadata_query_get_length_template( |
| 97 |
it, key_buffer_length, value_buffer_length); |
| 98 |
(void)it.release(); |
| 99 |
return retval; |
| 100 |
} |
| 101 |
|
| 102 |
DEFINE_BOOL_METHOD(Keyring_metadata_query_service_impl::get, |
| 103 |
(my_h_keyring_component_metadata_iterator metadata_iterator, |
| 104 |
char *key_buffer, size_t key_buffer_len, char *value_buffer, |
| 105 |
size_t value_buffer_len)) { |
| 106 |
std::unique_ptr<config_vector> it; |
| 107 |
it.reset(reinterpret_cast<config_vector *>(metadata_iterator)); |
| 108 |
bool retval = keyring_metadata_query_get_template( |
| 109 |
key_buffer, key_buffer_len, value_buffer, value_buffer_len, it); |
| 110 |
(void)it.release(); |
| 111 |
return retval; |
| 112 |
} |
| 113 |
|
| 114 |
} // namespace service_definition |
| 115 |
} // namespace keyring_common |