xref: /PHP-8.4/ext/mysqlnd/mysqlnd_ext_plugin.c (revision 071bf465)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Authors: Andrey Hristov <andrey@php.net>                             |
14   |          Johannes Schlüter <johannes@php.net>                        |
15   |          Ulf Wendel <uw@php.net>                                     |
16   +----------------------------------------------------------------------+
17 */
18 
19 #include "php.h"
20 #include "mysqlnd.h"
21 #include "mysqlnd_priv.h"
22 #include "mysqlnd_result.h"
23 #include "mysqlnd_debug.h"
24 #include "mysqlnd_commands.h"
25 #include "mysqlnd_ext_plugin.h"
26 
27 static struct st_mysqlnd_conn_methods * mysqlnd_conn_methods;
28 static struct st_mysqlnd_conn_data_methods * mysqlnd_conn_data_methods;
29 static struct st_mysqlnd_stmt_methods * mysqlnd_stmt_methods;
30 
31 /* {{{ mysqlnd_plugin__get_plugin_connection_data */
32 static void **
mysqlnd_plugin__get_plugin_connection_data(const MYSQLND * conn,const unsigned int plugin_id)33 mysqlnd_plugin__get_plugin_connection_data(const MYSQLND * conn, const unsigned int plugin_id)
34 {
35 	DBG_ENTER("mysqlnd_plugin__get_plugin_connection_data");
36 	DBG_INF_FMT("plugin_id=%u", plugin_id);
37 	if (!conn || plugin_id >= mysqlnd_plugin_count()) {
38 		return NULL;
39 	}
40 	DBG_RETURN((void *)((char *)conn + sizeof(MYSQLND) + plugin_id * sizeof(void *)));
41 }
42 /* }}} */
43 
44 
45 /* {{{ mysqlnd_plugin__get_plugin_connection_data_data */
46 static void **
mysqlnd_plugin__get_plugin_connection_data_data(const MYSQLND_CONN_DATA * conn,const unsigned int plugin_id)47 mysqlnd_plugin__get_plugin_connection_data_data(const MYSQLND_CONN_DATA * conn, const unsigned int plugin_id)
48 {
49 	DBG_ENTER("mysqlnd_plugin__get_plugin_connection_data_data");
50 	DBG_INF_FMT("plugin_id=%u", plugin_id);
51 	if (!conn || plugin_id >= mysqlnd_plugin_count()) {
52 		return NULL;
53 	}
54 	DBG_RETURN((void *)((char *)conn + sizeof(MYSQLND_CONN_DATA) + plugin_id * sizeof(void *)));
55 }
56 /* }}} */
57 
58 
59 /* {{{ mysqlnd_plugin__get_plugin_result_data */
60 static void **
mysqlnd_plugin__get_plugin_result_data(const MYSQLND_RES * result,const unsigned int plugin_id)61 mysqlnd_plugin__get_plugin_result_data(const MYSQLND_RES * result, const unsigned int plugin_id)
62 {
63 	DBG_ENTER("mysqlnd_plugin__get_plugin_result_data");
64 	DBG_INF_FMT("plugin_id=%u", plugin_id);
65 	if (!result || plugin_id >= mysqlnd_plugin_count()) {
66 		return NULL;
67 	}
68 	DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES) + plugin_id * sizeof(void *)));
69 }
70 /* }}} */
71 
72 
73 /* {{{ _mysqlnd_plugin__get_plugin_result_unbuffered_data */
74 static void **
mysqlnd_plugin__get_plugin_result_unbuffered_data(const MYSQLND_RES_UNBUFFERED * result,const unsigned int plugin_id)75 mysqlnd_plugin__get_plugin_result_unbuffered_data(const MYSQLND_RES_UNBUFFERED * result, const unsigned int plugin_id)
76 {
77 	DBG_ENTER("mysqlnd_plugin__get_plugin_result_unbuffered_data");
78 	DBG_INF_FMT("plugin_id=%u", plugin_id);
79 	if (!result || plugin_id >= mysqlnd_plugin_count()) {
80 		return NULL;
81 	}
82 	DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_UNBUFFERED) + plugin_id * sizeof(void *)));
83 }
84 /* }}} */
85 
86 /* {{{ mysqlnd_plugin__get_plugin_result_buffered_data */
87 static void **
mysqlnd_plugin__get_plugin_result_buffered_data(const MYSQLND_RES_BUFFERED * result,const unsigned int plugin_id)88 mysqlnd_plugin__get_plugin_result_buffered_data(const MYSQLND_RES_BUFFERED * result, const unsigned int plugin_id)
89 {
90 	DBG_ENTER("mysqlnd_plugin__get_plugin_result_buffered_data");
91 	DBG_INF_FMT("plugin_id=%u", plugin_id);
92 	if (!result || plugin_id >= mysqlnd_plugin_count()) {
93 		return NULL;
94 	}
95 	DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_BUFFERED) + plugin_id * sizeof(void *)));
96 }
97 /* }}} */
98 
99 
100 /* {{{ mysqlnd_plugin__get_plugin_protocol_data */
101 static void **
mysqlnd_plugin__get_plugin_protocol_data(const MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory,const unsigned int plugin_id)102 mysqlnd_plugin__get_plugin_protocol_data(const MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory, const unsigned int plugin_id)
103 {
104 	DBG_ENTER("mysqlnd_plugin__get_plugin_protocol_data");
105 	DBG_INF_FMT("plugin_id=%u", plugin_id);
106 	if (!factory || plugin_id >= mysqlnd_plugin_count()) {
107 		return NULL;
108 	}
109 	DBG_RETURN((void *)((char *)factory + sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + plugin_id * sizeof(void *)));
110 }
111 /* }}} */
112 
113 
114 /* {{{ mysqlnd_plugin__get_plugin_stmt_data */
115 static void **
mysqlnd_plugin__get_plugin_stmt_data(const MYSQLND_STMT * stmt,const unsigned int plugin_id)116 mysqlnd_plugin__get_plugin_stmt_data(const MYSQLND_STMT * stmt, const unsigned int plugin_id)
117 {
118 	DBG_ENTER("mysqlnd_plugin__get_plugin_stmt_data");
119 	DBG_INF_FMT("plugin_id=%u", plugin_id);
120 	if (!stmt || plugin_id >= mysqlnd_plugin_count()) {
121 		return NULL;
122 	}
123 	DBG_RETURN((void *)((char *)stmt + sizeof(MYSQLND_STMT) + plugin_id * sizeof(void *)));
124 }
125 /* }}} */
126 
127 
128 /* {{{ mysqlnd_plugin__get_plugin_pfc_data */
129 static void **
mysqlnd_plugin__get_plugin_pfc_data(const MYSQLND_PFC * pfc,const unsigned int plugin_id)130 mysqlnd_plugin__get_plugin_pfc_data(const MYSQLND_PFC * pfc, const unsigned int plugin_id)
131 {
132 	DBG_ENTER("mysqlnd_plugin__get_plugin_pfc_data");
133 	DBG_INF_FMT("plugin_id=%u", plugin_id);
134 	if (!pfc || plugin_id >= mysqlnd_plugin_count()) {
135 		return NULL;
136 	}
137 	DBG_RETURN((void *)((char *)pfc + sizeof(MYSQLND_PFC) + plugin_id * sizeof(void *)));
138 }
139 /* }}} */
140 
141 
142 /* {{{ _mysqlnd_plugin__get_plugin_vio_data */
143 static void **
mysqlnd_plugin__get_plugin_vio_data(const MYSQLND_VIO * vio,const unsigned int plugin_id)144 mysqlnd_plugin__get_plugin_vio_data(const MYSQLND_VIO * vio, const unsigned int plugin_id)
145 {
146 	DBG_ENTER("_mysqlnd_plugin__get_plugin_vio_data");
147 	DBG_INF_FMT("plugin_id=%u", plugin_id);
148 	if (!vio || plugin_id >= mysqlnd_plugin_count()) {
149 		return NULL;
150 	}
151 	DBG_RETURN((void *)((char *)vio + sizeof(MYSQLND_VIO) + plugin_id * sizeof(void *)));
152 }
153 /* }}} */
154 
155 struct st_mysqlnd_plugin__plugin_area_getters mysqlnd_plugin_area_getters =
156 {
157 	mysqlnd_plugin__get_plugin_connection_data,
158 	mysqlnd_plugin__get_plugin_connection_data_data,
159 	mysqlnd_plugin__get_plugin_result_data,
160 	mysqlnd_plugin__get_plugin_result_unbuffered_data,
161 	mysqlnd_plugin__get_plugin_result_buffered_data,
162 	mysqlnd_plugin__get_plugin_stmt_data,
163 	mysqlnd_plugin__get_plugin_protocol_data,
164 	mysqlnd_plugin__get_plugin_pfc_data,
165 	mysqlnd_plugin__get_plugin_vio_data,
166 };
167 
168 
169 
170 /* {{{ _mysqlnd_object_factory_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory)171 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *
172 _mysqlnd_object_factory_get_methods(void)
173 {
174 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory);
175 }
176 /* }}} */
177 
178 /* {{{ mysqlnd_conn_set_methods */
179 static void
_mysqlnd_object_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_object_factory)* methods)180 _mysqlnd_object_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *methods)
181 {
182 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory) = *methods;
183 }
184 /* }}} */
185 
186 
187 /* {{{ _mysqlnd_conn_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)188 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) *
189 _mysqlnd_conn_get_methods(void)
190 {
191 	return mysqlnd_conn_methods;
192 }
193 /* }}} */
194 
195 /* {{{ _mysqlnd_conn_set_methods */
196 static void
_mysqlnd_conn_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_conn)* methods)197 _mysqlnd_conn_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) *methods)
198 {
199 	mysqlnd_conn_methods = methods;
200 }
201 /* }}} */
202 
203 
204 /* {{{ _mysqlnd_conn_data_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data)205 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) *
206 _mysqlnd_conn_data_get_methods(void)
207 {
208 	return mysqlnd_conn_data_methods;
209 }
210 /* }}} */
211 
212 /* {{{ _mysqlnd_conn_data_set_methods */
213 static void
_mysqlnd_conn_data_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_conn_data)* methods)214 _mysqlnd_conn_data_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) * methods)
215 {
216 	mysqlnd_conn_data_methods = methods;
217 }
218 /* }}} */
219 
220 
221 /* {{{ _mysqlnd_result_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)222 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) *
223 _mysqlnd_result_get_methods(void)
224 {
225 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res);
226 }
227 /* }}} */
228 
229 
230 /* {{{ _mysqlnd_result_set_methods */
231 static void
_mysqlnd_result_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_res)* methods)232 _mysqlnd_result_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) * methods)
233 {
234 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res) = *methods;
235 }
236 /* }}} */
237 
238 
239 /* {{{ _mysqlnd_result_unbuffered_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered)240 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) *
241 _mysqlnd_result_unbuffered_get_methods(void)
242 {
243 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered);
244 }
245 /* }}} */
246 
247 
248 /* {{{ _mysqlnd_result_unbuffered_set_methods */
249 static void
_mysqlnd_result_unbuffered_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_result_unbuffered)* methods)250 _mysqlnd_result_unbuffered_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) * methods)
251 {
252 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered) = *methods;
253 }
254 /* }}} */
255 
256 
257 /* {{{ _mysqlnd_result_buffered_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered)258 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered) *
259 _mysqlnd_result_buffered_get_methods(void)
260 {
261 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered);
262 }
263 /* }}} */
264 
265 
266 /* {{{ _mysqlnd_result_buffered_set_methods */
267 static void
_mysqlnd_result_buffered_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_result_buffered)* methods)268 _mysqlnd_result_buffered_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered) * methods)
269 {
270 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered) = *methods;
271 }
272 /* }}} */
273 
274 
275 /* {{{ _mysqlnd_stmt_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt)276 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt) *
277 _mysqlnd_stmt_get_methods(void)
278 {
279 	return mysqlnd_stmt_methods;
280 }
281 /* }}} */
282 
283 
284 /* {{{ _mysqlnd_stmt_set_methods */
285 static void
_mysqlnd_stmt_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_stmt)* methods)286 _mysqlnd_stmt_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt) *methods)
287 {
288 	mysqlnd_stmt_methods = methods;
289 }
290 /* }}} */
291 
292 
293 /* {{{ _mysqlnd_protocol_payload_decoder_factory_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)294 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) *
295 _mysqlnd_protocol_payload_decoder_factory_get_methods(void)
296 {
297 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory);
298 }
299 /* }}} */
300 
301 
302 /* {{{ _mysqlnd_protocol_payload_decoder_factory_set_methods */
303 static void
_mysqlnd_protocol_payload_decoder_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_protocol_payload_decoder_factory)* methods)304 _mysqlnd_protocol_payload_decoder_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) * methods)
305 {
306 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory) = *methods;
307 }
308 /* }}} */
309 
310 
311 /* {{{ _mysqlnd_pfc_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec)312 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec) *
313 _mysqlnd_pfc_get_methods(void)
314 {
315 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_frame_codec);
316 }
317 /* }}} */
318 
319 
320 /* {{{ _mysqlnd_pfc_set_methods */
321 static void
_mysqlnd_pfc_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_protocol_packet_frame_codec)* methods)322 _mysqlnd_pfc_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec) * methods)
323 {
324 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_frame_codec) = *methods;
325 }
326 /* }}} */
327 
328 
329 /* {{{ _mysqlnd_vio_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio)330 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) *
331 _mysqlnd_vio_get_methods(void)
332 {
333 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_vio);
334 }
335 /* }}} */
336 
337 
338 /* {{{ _mysqlnd_vio_set_methods */
339 static void
_mysqlnd_vio_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_vio)* methods)340 _mysqlnd_vio_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) * methods)
341 {
342 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_vio) = *methods;
343 }
344 /* }}} */
345 
346 
347 /* {{{ mysqlnd_command_factory_get */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command)348 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) *
349 _mysqlnd_command_factory_get(void)
350 {
351 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command);
352 }
353 /* }}} */
354 
355 
356 /* {{{ mysqlnd_command_factory_set */
357 static void
_mysqlnd_command_factory_set(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_command)* methods)358 _mysqlnd_command_factory_set(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * methods)
359 {
360 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command) = *methods;
361 }
362 /* }}} */
363 
364 
365 /* {{{ _mysqlnd_error_info_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info)366 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *
367 _mysqlnd_error_info_get_methods(void)
368 {
369 	return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_error_info);
370 }
371 /* }}} */
372 
373 
374 /* {{{ _mysqlnd_error_info_set_methods */
375 static void
_mysqlnd_error_info_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_error_info)* methods)376 _mysqlnd_error_info_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *methods)
377 {
378 	MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_error_info) = *methods;
379 }
380 /* }}} */
381 
382 
383 struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters =
384 {
385 	{
386 		_mysqlnd_object_factory_get_methods,
387 		_mysqlnd_object_factory_set_methods
388 	},
389 	{
390 		_mysqlnd_conn_get_methods,
391 		_mysqlnd_conn_set_methods,
392 	},
393 	{
394 		_mysqlnd_conn_data_get_methods,
395 		_mysqlnd_conn_data_set_methods,
396 	},
397 	{
398 		_mysqlnd_result_get_methods,
399 		_mysqlnd_result_set_methods,
400 	},
401 	{
402 		_mysqlnd_result_unbuffered_get_methods,
403 		_mysqlnd_result_unbuffered_set_methods,
404 	},
405 	{
406 		_mysqlnd_result_buffered_get_methods,
407 		_mysqlnd_result_buffered_set_methods,
408 	},
409 	{
410 		_mysqlnd_stmt_get_methods,
411 		_mysqlnd_stmt_set_methods,
412 	},
413 	{
414 		_mysqlnd_protocol_payload_decoder_factory_get_methods,
415 		_mysqlnd_protocol_payload_decoder_factory_set_methods,
416 	},
417 	{
418 		_mysqlnd_pfc_get_methods,
419 		_mysqlnd_pfc_set_methods,
420 	},
421 	{
422 		_mysqlnd_vio_get_methods,
423 		_mysqlnd_vio_set_methods,
424 	},
425 	{
426 		_mysqlnd_error_info_get_methods,
427 		_mysqlnd_error_info_set_methods,
428 	},
429 	{
430 		_mysqlnd_command_factory_get,
431 		_mysqlnd_command_factory_set,
432 	},
433 };
434