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