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 | http://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_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
87 /* {{{ _mysqlnd_plugin__get_plugin_result_buffered_data */
88 static void **
mysqlnd_plugin__get_plugin_result_buffered_data_zval(const MYSQLND_RES_BUFFERED_ZVAL * result,const unsigned int plugin_id)89 mysqlnd_plugin__get_plugin_result_buffered_data_zval(const MYSQLND_RES_BUFFERED_ZVAL * result, const unsigned int plugin_id)
90 {
91 DBG_ENTER("_mysqlnd_plugin__get_plugin_result_data");
92 DBG_INF_FMT("plugin_id=%u", plugin_id);
93 if (!result || plugin_id >= mysqlnd_plugin_count()) {
94 return NULL;
95 }
96 DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_BUFFERED_ZVAL) + plugin_id * sizeof(void *)));
97 }
98 /* }}} */
99
100 /* {{{ mysqlnd_plugin__get_plugin_result_buffered_data */
101 static void **
mysqlnd_plugin__get_plugin_result_buffered_data_c(const MYSQLND_RES_BUFFERED_C * result,const unsigned int plugin_id)102 mysqlnd_plugin__get_plugin_result_buffered_data_c(const MYSQLND_RES_BUFFERED_C * result, const unsigned int plugin_id)
103 {
104 DBG_ENTER("mysqlnd_plugin__get_plugin_result_data");
105 DBG_INF_FMT("plugin_id=%u", plugin_id);
106 if (!result || plugin_id >= mysqlnd_plugin_count()) {
107 return NULL;
108 }
109 DBG_RETURN((void *)((char *)result + sizeof(MYSQLND_RES_BUFFERED_C) + plugin_id * sizeof(void *)));
110 }
111 /* }}} */
112
113
114 /* {{{ mysqlnd_plugin__get_plugin_protocol_data */
115 static void **
mysqlnd_plugin__get_plugin_protocol_data(const MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory,const unsigned int plugin_id)116 mysqlnd_plugin__get_plugin_protocol_data(const MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * factory, const unsigned int plugin_id)
117 {
118 DBG_ENTER("mysqlnd_plugin__get_plugin_protocol_data");
119 DBG_INF_FMT("plugin_id=%u", plugin_id);
120 if (!factory || plugin_id >= mysqlnd_plugin_count()) {
121 return NULL;
122 }
123 DBG_RETURN((void *)((char *)factory + sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + plugin_id * sizeof(void *)));
124 }
125 /* }}} */
126
127
128 /* {{{ mysqlnd_plugin__get_plugin_stmt_data */
129 static void **
mysqlnd_plugin__get_plugin_stmt_data(const MYSQLND_STMT * stmt,const unsigned int plugin_id)130 mysqlnd_plugin__get_plugin_stmt_data(const MYSQLND_STMT * stmt, const unsigned int plugin_id)
131 {
132 DBG_ENTER("mysqlnd_plugin__get_plugin_stmt_data");
133 DBG_INF_FMT("plugin_id=%u", plugin_id);
134 if (!stmt || plugin_id >= mysqlnd_plugin_count()) {
135 return NULL;
136 }
137 DBG_RETURN((void *)((char *)stmt + sizeof(MYSQLND_STMT) + plugin_id * sizeof(void *)));
138 }
139 /* }}} */
140
141
142 /* {{{ mysqlnd_plugin__get_plugin_pfc_data */
143 static void **
mysqlnd_plugin__get_plugin_pfc_data(const MYSQLND_PFC * pfc,const unsigned int plugin_id)144 mysqlnd_plugin__get_plugin_pfc_data(const MYSQLND_PFC * pfc, const unsigned int plugin_id)
145 {
146 DBG_ENTER("mysqlnd_plugin__get_plugin_pfc_data");
147 DBG_INF_FMT("plugin_id=%u", plugin_id);
148 if (!pfc || plugin_id >= mysqlnd_plugin_count()) {
149 return NULL;
150 }
151 DBG_RETURN((void *)((char *)pfc + sizeof(MYSQLND_PFC) + plugin_id * sizeof(void *)));
152 }
153 /* }}} */
154
155
156 /* {{{ _mysqlnd_plugin__get_plugin_vio_data */
157 static void **
mysqlnd_plugin__get_plugin_vio_data(const MYSQLND_VIO * vio,const unsigned int plugin_id)158 mysqlnd_plugin__get_plugin_vio_data(const MYSQLND_VIO * vio, const unsigned int plugin_id)
159 {
160 DBG_ENTER("_mysqlnd_plugin__get_plugin_vio_data");
161 DBG_INF_FMT("plugin_id=%u", plugin_id);
162 if (!vio || plugin_id >= mysqlnd_plugin_count()) {
163 return NULL;
164 }
165 DBG_RETURN((void *)((char *)vio + sizeof(MYSQLND_VIO) + plugin_id * sizeof(void *)));
166 }
167 /* }}} */
168
169 struct st_mysqlnd_plugin__plugin_area_getters mysqlnd_plugin_area_getters =
170 {
171 mysqlnd_plugin__get_plugin_connection_data,
172 mysqlnd_plugin__get_plugin_connection_data_data,
173 mysqlnd_plugin__get_plugin_result_data,
174 mysqlnd_plugin__get_plugin_result_unbuffered_data,
175 mysqlnd_plugin__get_plugin_result_buffered_data_zval,
176 mysqlnd_plugin__get_plugin_result_buffered_data_c,
177 mysqlnd_plugin__get_plugin_stmt_data,
178 mysqlnd_plugin__get_plugin_protocol_data,
179 mysqlnd_plugin__get_plugin_pfc_data,
180 mysqlnd_plugin__get_plugin_vio_data,
181 };
182
183
184
185 /* {{{ _mysqlnd_object_factory_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory)186 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *
187 _mysqlnd_object_factory_get_methods()
188 {
189 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory);
190 }
191 /* }}} */
192
193 /* {{{ mysqlnd_conn_set_methods */
194 static void
_mysqlnd_object_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_object_factory)* methods)195 _mysqlnd_object_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *methods)
196 {
197 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_object_factory) = *methods;
198 }
199 /* }}} */
200
201
202 /* {{{ _mysqlnd_conn_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)203 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) *
204 _mysqlnd_conn_get_methods()
205 {
206 return mysqlnd_conn_methods;
207 }
208 /* }}} */
209
210 /* {{{ _mysqlnd_conn_set_methods */
211 static void
_mysqlnd_conn_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_conn)* methods)212 _mysqlnd_conn_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) *methods)
213 {
214 mysqlnd_conn_methods = methods;
215 }
216 /* }}} */
217
218
219 /* {{{ _mysqlnd_conn_data_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data)220 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) *
221 _mysqlnd_conn_data_get_methods()
222 {
223 return mysqlnd_conn_data_methods;
224 }
225 /* }}} */
226
227 /* {{{ _mysqlnd_conn_data_set_methods */
228 static void
_mysqlnd_conn_data_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_conn_data)* methods)229 _mysqlnd_conn_data_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) * methods)
230 {
231 mysqlnd_conn_data_methods = methods;
232 }
233 /* }}} */
234
235
236 /* {{{ _mysqlnd_result_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)237 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) *
238 _mysqlnd_result_get_methods()
239 {
240 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res);
241 }
242 /* }}} */
243
244
245 /* {{{ _mysqlnd_result_set_methods */
246 static void
_mysqlnd_result_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_res)* methods)247 _mysqlnd_result_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) * methods)
248 {
249 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_res) = *methods;
250 }
251 /* }}} */
252
253
254 /* {{{ _mysqlnd_result_unbuffered_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered)255 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) *
256 _mysqlnd_result_unbuffered_get_methods()
257 {
258 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered);
259 }
260 /* }}} */
261
262
263 /* {{{ _mysqlnd_result_unbuffered_set_methods */
264 static void
_mysqlnd_result_unbuffered_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_result_unbuffered)* methods)265 _mysqlnd_result_unbuffered_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) * methods)
266 {
267 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_unbuffered) = *methods;
268 }
269 /* }}} */
270
271
272 /* {{{ _mysqlnd_result_buffered_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered)273 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered) *
274 _mysqlnd_result_buffered_get_methods()
275 {
276 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered);
277 }
278 /* }}} */
279
280
281 /* {{{ _mysqlnd_result_buffered_set_methods */
282 static void
_mysqlnd_result_buffered_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_result_buffered)* methods)283 _mysqlnd_result_buffered_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered) * methods)
284 {
285 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_result_buffered) = *methods;
286 }
287 /* }}} */
288
289
290 /* {{{ _mysqlnd_stmt_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt)291 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt) *
292 _mysqlnd_stmt_get_methods()
293 {
294 return mysqlnd_stmt_methods;
295 }
296 /* }}} */
297
298
299 /* {{{ _mysqlnd_stmt_set_methods */
300 static void
_mysqlnd_stmt_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_stmt)* methods)301 _mysqlnd_stmt_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt) *methods)
302 {
303 mysqlnd_stmt_methods = methods;
304 }
305 /* }}} */
306
307
308 /* {{{ _mysqlnd_protocol_payload_decoder_factory_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)309 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) *
310 _mysqlnd_protocol_payload_decoder_factory_get_methods()
311 {
312 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory);
313 }
314 /* }}} */
315
316
317 /* {{{ _mysqlnd_protocol_payload_decoder_factory_set_methods */
318 static void
_mysqlnd_protocol_payload_decoder_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_protocol_payload_decoder_factory)* methods)319 _mysqlnd_protocol_payload_decoder_factory_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) * methods)
320 {
321 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_payload_decoder_factory) = *methods;
322 }
323 /* }}} */
324
325
326 /* {{{ _mysqlnd_pfc_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec)327 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec) *
328 _mysqlnd_pfc_get_methods()
329 {
330 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_frame_codec);
331 }
332 /* }}} */
333
334
335 /* {{{ _mysqlnd_pfc_set_methods */
336 static void
_mysqlnd_pfc_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_protocol_packet_frame_codec)* methods)337 _mysqlnd_pfc_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec) * methods)
338 {
339 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_protocol_packet_frame_codec) = *methods;
340 }
341 /* }}} */
342
343
344 /* {{{ _mysqlnd_vio_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio)345 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) *
346 _mysqlnd_vio_get_methods()
347 {
348 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_vio);
349 }
350 /* }}} */
351
352
353 /* {{{ _mysqlnd_vio_set_methods */
354 static void
_mysqlnd_vio_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_vio)* methods)355 _mysqlnd_vio_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) * methods)
356 {
357 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_vio) = *methods;
358 }
359 /* }}} */
360
361
362 /* {{{ mysqlnd_command_factory_get */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command)363 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) *
364 _mysqlnd_command_factory_get()
365 {
366 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command);
367 }
368 /* }}} */
369
370
371 /* {{{ mysqlnd_command_factory_set */
372 static void
_mysqlnd_command_factory_set(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_command)* methods)373 _mysqlnd_command_factory_set(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * methods)
374 {
375 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command) = *methods;
376 }
377 /* }}} */
378
379
380 /* {{{ _mysqlnd_error_info_get_methods */
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info)381 static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *
382 _mysqlnd_error_info_get_methods()
383 {
384 return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_error_info);
385 }
386 /* }}} */
387
388
389 /* {{{ _mysqlnd_error_info_set_methods */
390 static void
_mysqlnd_error_info_set_methods(MYSQLND_CLASS_METHODS_TYPE (mysqlnd_error_info)* methods)391 _mysqlnd_error_info_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *methods)
392 {
393 MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_error_info) = *methods;
394 }
395 /* }}} */
396
397
398 struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters =
399 {
400 {
401 _mysqlnd_object_factory_get_methods,
402 _mysqlnd_object_factory_set_methods
403 },
404 {
405 _mysqlnd_conn_get_methods,
406 _mysqlnd_conn_set_methods,
407 },
408 {
409 _mysqlnd_conn_data_get_methods,
410 _mysqlnd_conn_data_set_methods,
411 },
412 {
413 _mysqlnd_result_get_methods,
414 _mysqlnd_result_set_methods,
415 },
416 {
417 _mysqlnd_result_unbuffered_get_methods,
418 _mysqlnd_result_unbuffered_set_methods,
419 },
420 {
421 _mysqlnd_result_buffered_get_methods,
422 _mysqlnd_result_buffered_set_methods,
423 },
424 {
425 _mysqlnd_stmt_get_methods,
426 _mysqlnd_stmt_set_methods,
427 },
428 {
429 _mysqlnd_protocol_payload_decoder_factory_get_methods,
430 _mysqlnd_protocol_payload_decoder_factory_set_methods,
431 },
432 {
433 _mysqlnd_pfc_get_methods,
434 _mysqlnd_pfc_set_methods,
435 },
436 {
437 _mysqlnd_vio_get_methods,
438 _mysqlnd_vio_set_methods,
439 },
440 {
441 _mysqlnd_error_info_get_methods,
442 _mysqlnd_error_info_set_methods,
443 },
444 {
445 _mysqlnd_command_factory_get,
446 _mysqlnd_command_factory_set,
447 },
448 };
449