MySQL 8.0.32
Source Code Documentation
mysql_connection_attributes_iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 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 MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H
24#define MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H
25
28#include <stddef.h>
29
30/**
31 @ingroup group_components_services_inventory
32
33 A service to read the connection attributes from the current session
34 It provides a read-only iterator over the attributes.
35 This is some example code to use the iterator:
36
37 @code
38
39 // at init time. try to reuse the service handles as much as possible
40
41 my_service<SERVICE_TYPE(mysql_current_thread_reader)> thd_reader(
42 "mysql_current_thread_reader", m_reg_srv);
43 my_service<SERVICE_TYPE(mysql_connection_attributes_iterator)> service(
44 "mysql_connection_attributes_iterator", m_reg_srv);
45
46 if (!service.is_valid() || !thd_reader.is_valid) {
47 return; //error
48 }
49
50 ...
51
52 // at parse time
53
54 MYSQL_THD thd;
55 if (thd_reader->get(&thd))
56 return; //error
57
58 my_h_connection_attributes_iterator iterator;
59
60 MYSQL_LEX_CSTRING name;
61 MYSQL_LEX_CSTRING value;
62 const char *charset_string;
63 const CHARSET_INFO *charset = nullptr;
64
65 my_h_connection_attributes_iterator iterator;
66 if (service->init(thd, &iterator)) return; // error
67
68 while (!service->get(thd, &iterator, &name.str, &name.length, &value.str,
69 &value.length, &charset_string)) {
70 // Do something with name and value
71 }
72
73 service->deinit(iterator);
74
75 @endcode
76*/
77
79
80BEGIN_SERVICE_DEFINITION(mysql_connection_attributes_iterator)
81
82/**
83 Initialize an iterator.
84
85 Also position at the first attribute.
86
87 @param thd The session to operate on. Can be NULL to use the
88 current THD.
89 @param[out] iterator Iterator pointer.
90
91 @return
92 @retval false Succeeded.
93 @retval true Failed.
94
95 @sa mysql_connection_attributes_iterator_imp::init
96*/
99
100/**
101 Deinitialize an iterator.
102
103 @param iterator Iterator pointer.
104
105 @return
106 @retval false Succeeded.
107 @retval true Failed.
108
109 @sa mysql_connection_attributes_iterator_imp::deinit
110*/
112
113/**
114 Fetch the current name/value pair from the iterator and move it forward.
115 Note: the attribute's name and value pointers are valid until the THD object
116 is alive.
117
118 @param thd The session to operate on. Can be NULL to use the
119 current THD.
120 @param iterator Iterator pointer.
121 @param[out] name The attribute name.
122 @param[out] name_length The attribute name's length.
123 @param[out] value The attribute value.
124 @param[out] value_length The attribute value's length.
125 @param[out] client_charset The character set, used for encoding the
126 connection attributes pair
127
128 @return
129 @retval false Succeeded.
130 @retval true Failed.
131
132 @sa mysql_connection_attributes_iterator_imp::get
133*/
135 (MYSQL_THD thd,
137 const char **name, size_t *name_length, const char **value,
138 size_t *value_length, const char **client_charset));
139
140END_SERVICE_DEFINITION(mysql_connection_attributes_iterator)
141
142#endif /* MYSQL_CONNECTION_ATTRIBUTES_ITERATOR_H */
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
#define MYSQL_THD
Definition: backup_page_tracker.h:37
const char * my_h_connection_attributes_iterator
A service to read the connection attributes from the current session It provides a read-only iterator...
Definition: mysql_connection_attributes_iterator.h:78
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 DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:111
case opt name
Definition: sslopt-case.h:32