1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 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   |          Ulf Wendel <uw@php.net>                                     |
17   +----------------------------------------------------------------------+
18 */
19 
20 #ifndef MYSQLND_STRUCTS_H
21 #define MYSQLND_STRUCTS_H
22 
23 #include "zend_smart_str_public.h"
24 
25 #define MYSQLND_TYPEDEFED_METHODS
26 
27 #define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
28 #define MYSQLND_CLASS_METHODS_TYPE(class) struct st_##class##_methods
29 #define MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) MYSQLND_CLASS_METHODS_TYPE(class) MYSQLND_CLASS_METHOD_TABLE_NAME(class)
30 
31 #define MYSQLND_CLASS_METHODS_START(class)	MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(class) = {
32 #define MYSQLND_CLASS_METHODS_END			}
33 
34 #define MYSQLND_CLASS_METHODS_INSTANCE_NAME(class)		mysqlnd_##class##_methods_ptr
35 #define MYSQLND_CLASS_METHODS_INSTANCE_DECLARE(class)	extern const MYSQLND_CLASS_METHODS_TYPE(class) * MYSQLND_CLASS_METHODS_INSTANCE_NAME(class)
36 #define MYSQLND_CLASS_METHODS_INSTANCE_DEFINE(class)	const MYSQLND_CLASS_METHODS_TYPE(class) * MYSQLND_CLASS_METHODS_INSTANCE_NAME(class) = & MYSQLND_CLASS_METHOD_TABLE_NAME(class)
37 
38 typedef struct st_mysqlnd_string
39 {
40 	char	*s;
41 	size_t	l;
42 } MYSQLND_STRING;
43 
44 typedef struct st_mysqlnd_const_string
45 {
46 	const char *s;
47 	size_t	l;
48 } MYSQLND_CSTRING;
49 
50 
51 typedef struct st_mysqlnd_memory_pool MYSQLND_MEMORY_POOL;
52 
53 struct st_mysqlnd_memory_pool
54 {
55 	zend_arena		*arena;
56 	void			*last;
57 	void            *checkpoint;
58 
59 	void*	(*get_chunk)(MYSQLND_MEMORY_POOL * pool, size_t size);
60 	void*	(*resize_chunk)(MYSQLND_MEMORY_POOL * pool, void * ptr, size_t old_size, size_t size);
61 	void	(*free_chunk)(MYSQLND_MEMORY_POOL * pool, void * ptr);
62 };
63 
64 
65 typedef struct st_mysqlnd_row_buffer MYSQLND_ROW_BUFFER;
66 
67 struct st_mysqlnd_row_buffer
68 {
69 	void			*ptr;
70 	size_t			size;
71 };
72 
73 
74 typedef struct st_mysqlnd_cmd_buffer
75 {
76 	zend_uchar		*buffer;
77 	size_t			length;
78 } MYSQLND_CMD_BUFFER;
79 
80 
81 typedef struct st_mysqlnd_field
82 {
83 	zend_string *sname;			/* Name of column */
84 	zend_bool    is_numeric;
85 	zend_ulong	 num_key;
86 	const char  *name;          /* Name of column in C string */
87 	const char  *org_name;		/* Original column name, if an alias */
88 	const char  *table;			/* Table of column if column was a field */
89 	const char  *org_table;		/* Org table name, if table was an alias */
90 	const char  *db;			/* Database for table */
91 	const char  *catalog;		/* Catalog for table */
92 	char  *def;                 /* Default value */
93 	zend_ulong length;		/* Width of column (create length) */
94 	zend_ulong max_length;	/* Max width for selected set */
95 	unsigned int name_length;
96 	unsigned int org_name_length;
97 	unsigned int table_length;
98 	unsigned int org_table_length;
99 	unsigned int db_length;
100 	unsigned int catalog_length;
101 	unsigned int def_length;
102 	unsigned int flags;			/* Diverse flags */
103 	unsigned int decimals;		/* Number of decimals in field */
104 	unsigned int charsetnr;		/* Character set */
105 	enum mysqlnd_field_types type;	/* Type of field. See mysql_com.h for types */
106 	char *root;
107 	size_t root_len;
108 } MYSQLND_FIELD;
109 
110 
111 typedef struct st_mysqlnd_upsert_status MYSQLND_UPSERT_STATUS;
112 typedef void (*func_mysqlnd_upsert_status__reset)(MYSQLND_UPSERT_STATUS * const upsert_status);
113 typedef void (*func_mysqlnd_upsert_status__set_affected_rows_to_error)(MYSQLND_UPSERT_STATUS * const upsert_status);
114 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_upsert_status)115 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_upsert_status)
116 {
117 	func_mysqlnd_upsert_status__reset reset;
118 	func_mysqlnd_upsert_status__set_affected_rows_to_error set_affected_rows_to_error;
119 };
120 
121 struct st_mysqlnd_upsert_status
122 {
123 	unsigned int	warning_count;
124 	unsigned int	server_status;
125 	uint64_t		affected_rows;
126 	uint64_t		last_insert_id;
127 
128 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_upsert_status) *m;
129 };
130 
131 #define SET_EMPTY_ERROR(info)							(info)->m->reset((info))
132 #define SET_CLIENT_ERROR(info, err_no, sqlstate, error)	(err_no)? (info)->m->set_client_error((info), (err_no), (sqlstate), (error)) : (info)->m->reset((info))
133 #define SET_OOM_ERROR(info) 							SET_CLIENT_ERROR((info), CR_OUT_OF_MEMORY, UNKNOWN_SQLSTATE, mysqlnd_out_of_memory)
134 #define COPY_CLIENT_ERROR(dest, source)					SET_CLIENT_ERROR((dest), (source).error_no, (source).sqlstate, (source).error)
135 
136 
137 typedef struct st_mysqlnd_error_info MYSQLND_ERROR_INFO;
138 typedef void (*func_mysqlnd_error_info__reset)(MYSQLND_ERROR_INFO * const info);
139 typedef void (*func_mysqlnd_error_info__set_client_error)(MYSQLND_ERROR_INFO * const info, const unsigned int err_no, const char * const sqlstate, const char * const error);
140 
141 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info)142 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info)
143 {
144 	func_mysqlnd_error_info__reset reset;
145 	func_mysqlnd_error_info__set_client_error set_client_error;
146 };
147 
148 struct st_mysqlnd_error_info
149 {
150 	char error[MYSQLND_ERRMSG_SIZE+1];
151 	char sqlstate[MYSQLND_SQLSTATE_LENGTH + 1];
152 	unsigned int error_no;
153 	zend_llist error_list;
154 
155 	zend_bool persistent;
156 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) *m;
157 };
158 
159 
160 typedef struct st_mysqlnd_error_list_element
161 {
162 	char * error;
163 	char sqlstate[MYSQLND_SQLSTATE_LENGTH + 1];
164 	unsigned int error_no;
165 } MYSQLND_ERROR_LIST_ELEMENT;
166 
167 
168 typedef struct st_mysqlnd_infile_info
169 {
170 	php_stream	*fd;
171 	int			error_no;
172 	char		error_msg[MYSQLND_ERRMSG_SIZE + 1];
173 	const char	*filename;
174 } MYSQLND_INFILE_INFO;
175 
176 
177 typedef int (*func_mysqlnd_local_infile__init)(void ** ptr, const char * const filename);
178 typedef int (*func_mysqlnd_local_infile__read)(void * ptr, zend_uchar * buf, unsigned int buf_len);
179 typedef int (*func_mysqlnd_local_infile__error)(void * ptr, char * error_msg, unsigned int error_msg_len);
180 typedef void (*func_mysqlnd_local_infile__end)(void * ptr);
181 
182 
183 /* character set information */
184 typedef struct st_mysqlnd_charset
185 {
186 	unsigned int	nr;
187 	const char		*name;
188 	const char		*collation;
189 	unsigned int	char_minlen;
190 	unsigned int	char_maxlen;
191 	const char		*comment;
192 	unsigned int 	(*mb_charlen)(const unsigned int c);
193 	unsigned int 	(*mb_valid)(const char * const start, const char * const end);
194 } MYSQLND_CHARSET;
195 
196 
197 /* local infile handler */
198 typedef struct st_mysqlnd_infile
199 {
200 	func_mysqlnd_local_infile__init		local_infile_init;
201 	func_mysqlnd_local_infile__read		local_infile_read;
202 	func_mysqlnd_local_infile__error	local_infile_error;
203 	func_mysqlnd_local_infile__end		local_infile_end;
204 } MYSQLND_INFILE;
205 
206 
207 typedef struct st_mysqlnd_session_options
208 {
209 	unsigned int		flags;
210 
211 	/* init commands - we need to send them to server directly after connect */
212 	unsigned int	num_commands;
213 	char			**init_commands;
214 
215 	/* configuration file information */
216 	char 		*cfg_file;
217 	char		*cfg_section;
218 
219 	char		*auth_protocol;
220 	/*
221 	  We need to keep these because otherwise st_mysqlnd_conn will be changed.
222 	  The ABI will be broken and the methods structure will be somewhere else
223 	  in the memory which can crash external code. Feel free to reuse these.
224 	*/
225 	HashTable	* connect_attr;
226 	char		* unused1;
227 	char		* unused2;
228 	char		* unused3;
229 
230 	enum_mysqlnd_session_protocol_type protocol;
231 
232 	char 		*charset_name;
233 	/* maximum allowed packet size for communication */
234 	unsigned int		max_allowed_packet;
235 
236 #ifdef MYSQLND_STRING_TO_INT_CONVERSION
237 	zend_bool	int_and_float_native;
238 #endif
239 } MYSQLND_SESSION_OPTIONS;
240 
241 
242 typedef struct st_mysqlnd_vio_options
243 {
244 	/* timeouts */
245 	unsigned int timeout_connect;
246 	unsigned int timeout_read;
247 	unsigned int timeout_write;
248 
249 	size_t		net_read_buffer_size;
250 
251 	/* SSL information */
252 	char		*ssl_key;
253 	char		*ssl_cert;
254 	char		*ssl_ca;
255 	char		*ssl_capath;
256 	char		*ssl_cipher;
257 	char		*ssl_passphrase;
258 	enum mysqlnd_ssl_peer {
259 		MYSQLND_SSL_PEER_DEFAULT = 0,
260 		MYSQLND_SSL_PEER_VERIFY = 1,
261 		MYSQLND_SSL_PEER_DONT_VERIFY = 2,
262 
263 #define MYSQLND_SSL_PEER_DEFAULT_ACTION  MYSQLND_SSL_PEER_VERIFY
264 	} ssl_verify_peer;
265 } MYSQLND_VIO_OPTIONS;
266 
267 
268 
269 typedef struct st_mysqlnd_connection MYSQLND;
270 typedef struct st_mysqlnd_connection_data MYSQLND_CONN_DATA;
271 typedef struct st_mysqlnd_protocol_frame_codec		MYSQLND_PFC;
272 typedef struct st_mysqlnd_protocol_frame_codec_data	MYSQLND_PFC_DATA;
273 typedef struct st_mysqlnd_vio		MYSQLND_VIO;
274 typedef struct st_mysqlnd_vio_data	MYSQLND_VIO_DATA;
275 typedef struct st_mysqlnd_protocol_payload_decoder_factory	MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY;
276 typedef struct st_mysqlnd_res	MYSQLND_RES;
277 typedef char** 					MYSQLND_ROW_C;		/* return data as array of strings */
278 typedef struct st_mysqlnd_stmt_data	MYSQLND_STMT_DATA;
279 typedef struct st_mysqlnd_stmt	MYSQLND_STMT;
280 typedef unsigned int			MYSQLND_FIELD_OFFSET;
281 
282 typedef struct st_mysqlnd_param_bind MYSQLND_PARAM_BIND;
283 
284 typedef struct st_mysqlnd_result_bind MYSQLND_RESULT_BIND;
285 
286 typedef struct st_mysqlnd_result_metadata MYSQLND_RES_METADATA;
287 typedef struct st_mysqlnd_buffered_result_parent MYSQLND_RES_BUFFERED;
288 typedef struct st_mysqlnd_buffered_result_zval MYSQLND_RES_BUFFERED_ZVAL;
289 typedef struct st_mysqlnd_buffered_result_c MYSQLND_RES_BUFFERED_C;
290 typedef struct st_mysqlnd_unbuffered_result MYSQLND_RES_UNBUFFERED;
291 
292 typedef struct st_mysqlnd_debug MYSQLND_DEBUG;
293 
294 
295 typedef MYSQLND_RES* (*mysqlnd_stmt_use_or_store_func)(MYSQLND_STMT * const);
296 typedef enum_func_status  (*mysqlnd_fetch_row_func)(MYSQLND_RES *result,
297 													void * param,
298 													const unsigned int flags,
299 													zend_bool * fetched_anything
300 													);
301 
302 
303 typedef struct st_mysqlnd_stats MYSQLND_STATS;
304 
305 typedef void (*mysqlnd_stat_trigger)(MYSQLND_STATS * stats, enum_mysqlnd_collected_stats stat, int64_t change);
306 
307 struct st_mysqlnd_stats
308 {
309 	uint64_t				*values;
310 	mysqlnd_stat_trigger	*triggers;
311 	size_t					count;
312 	zend_bool				in_trigger;
313 #ifdef ZTS
314 	MUTEX_T	LOCK_access;
315 #endif
316 };
317 
318 
319 typedef enum_func_status (*func_mysqlnd_execute_com_set_option)(MYSQLND_CONN_DATA * const conn, const enum_mysqlnd_server_option option);
320 typedef enum_func_status (*func_mysqlnd_execute_com_debug)(MYSQLND_CONN_DATA * const conn);
321 typedef enum_func_status (*func_mysqlnd_execute_com_init_db)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING db);
322 typedef enum_func_status (*func_mysqlnd_execute_com_ping)(MYSQLND_CONN_DATA * const conn);
323 typedef enum_func_status (*func_mysqlnd_execute_com_statistics)(MYSQLND_CONN_DATA * const conn, zend_string ** message);
324 typedef enum_func_status (*func_mysqlnd_execute_com_process_kill)(MYSQLND_CONN_DATA * const conn, const unsigned int process_id, const zend_bool read_response);
325 typedef enum_func_status (*func_mysqlnd_execute_com_refresh)(MYSQLND_CONN_DATA * const conn, const uint8_t options);
326 typedef enum_func_status (*func_mysqlnd_execute_com_shutdown)(MYSQLND_CONN_DATA * const conn, const uint8_t level);
327 typedef enum_func_status (*func_mysqlnd_execute_com_quit)(MYSQLND_CONN_DATA * const conn);
328 typedef enum_func_status (*func_mysqlnd_execute_com_query)(MYSQLND_CONN_DATA * const conn, MYSQLND_CSTRING query);
329 typedef enum_func_status (*func_mysqlnd_execute_com_change_user)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload, const zend_bool silent);
330 typedef enum_func_status (*func_mysqlnd_execute_com_reap_result)(MYSQLND_CONN_DATA * const conn);
331 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_prepare)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING query);
332 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_execute)(MYSQLND_CONN_DATA * conn, const MYSQLND_CSTRING payload);
333 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_fetch)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload);
334 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_reset)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id);
335 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_send_long_data)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload);
336 typedef enum_func_status (*func_mysqlnd_execute_com_stmt_close)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id);
337 typedef enum_func_status (*func_mysqlnd_execute_com_enable_ssl)(MYSQLND_CONN_DATA * const conn, const size_t client_capabilities, const size_t server_capabilities, const unsigned int charset_no);
338 typedef enum_func_status (*func_mysqlnd_execute_com_handshake)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING username, const MYSQLND_CSTRING password, const MYSQLND_CSTRING database, const size_t client_flags);
339 
340 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command)341 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command)
342 {
343 	func_mysqlnd_execute_com_set_option set_option;
344 	func_mysqlnd_execute_com_debug debug;
345 	func_mysqlnd_execute_com_init_db init_db;
346 	func_mysqlnd_execute_com_ping ping;
347 	func_mysqlnd_execute_com_statistics statistics;
348 	func_mysqlnd_execute_com_process_kill process_kill;
349 	func_mysqlnd_execute_com_refresh refresh;
350 	func_mysqlnd_execute_com_shutdown shutdown;
351 	func_mysqlnd_execute_com_quit quit;
352 	func_mysqlnd_execute_com_query query;
353 	func_mysqlnd_execute_com_change_user change_user;
354 	func_mysqlnd_execute_com_reap_result reap_result;
355 	func_mysqlnd_execute_com_stmt_prepare stmt_prepare;
356 	func_mysqlnd_execute_com_stmt_execute stmt_execute;
357 	func_mysqlnd_execute_com_stmt_fetch stmt_fetch;
358 	func_mysqlnd_execute_com_stmt_reset stmt_reset;
359 	func_mysqlnd_execute_com_stmt_send_long_data stmt_send_long_data;
360 	func_mysqlnd_execute_com_stmt_close stmt_close;
361 	func_mysqlnd_execute_com_enable_ssl enable_ssl;
362 	func_mysqlnd_execute_com_handshake handshake;
363 };
364 
365 
366 
367 typedef enum_func_status	(*func_mysqlnd_vio__init)(MYSQLND_VIO * const vio, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info);
368 typedef void				(*func_mysqlnd_vio__dtor)(MYSQLND_VIO * const vio, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
369 
370 typedef enum_func_status	(*func_mysqlnd_vio__connect)(MYSQLND_VIO * const vio, const MYSQLND_CSTRING scheme, const zend_bool persistent, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
371 
372 typedef void				(*func_mysqlnd_vio__close_stream)(MYSQLND_VIO * const vio, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
373 typedef php_stream *		(*func_mysqlnd_vio__open_stream)(MYSQLND_VIO * const vio, const MYSQLND_CSTRING scheme, const zend_bool persistent, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
374 typedef php_stream *		(*func_mysqlnd_vio__get_stream)(const MYSQLND_VIO * const vio);
375 typedef enum_func_status	(*func_mysqlnd_vio__set_stream)(MYSQLND_VIO * const vio, php_stream * vio_stream);
376 typedef zend_bool			(*func_mysqlnd_vio__has_valid_stream)(const MYSQLND_VIO * const vio);
377 typedef func_mysqlnd_vio__open_stream (*func_mysqlnd_vio__get_open_stream)(MYSQLND_VIO * const vio, const MYSQLND_CSTRING scheme, MYSQLND_ERROR_INFO * const error_info);
378 
379 typedef enum_func_status	(*func_mysqlnd_vio__set_client_option)(MYSQLND_VIO * const vio, enum_mysqlnd_client_option option, const char * const value);
380 typedef void				(*func_mysqlnd_vio__post_connect_set_opt)(MYSQLND_VIO * const vio, const MYSQLND_CSTRING scheme, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
381 
382 typedef enum_func_status	(*func_mysqlnd_vio__enable_ssl)(MYSQLND_VIO * const vio);
383 typedef enum_func_status	(*func_mysqlnd_vio__disable_ssl)(MYSQLND_VIO * const vio);
384 typedef enum_func_status	(*func_mysqlnd_vio__network_read)(MYSQLND_VIO * const vio, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info);
385 typedef ssize_t				(*func_mysqlnd_vio__network_write)(MYSQLND_VIO * const vio, const zend_uchar * const buf, const size_t count, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info);
386 
387 typedef size_t				(*func_mysqlnd_vio__consume_uneaten_data)(MYSQLND_VIO * const vio, enum php_mysqlnd_server_command cmd);
388 
389 typedef void				(*func_mysqlnd_vio__free_contents)(MYSQLND_VIO * vio);
390 
391 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio)392 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio)
393 {
394 	func_mysqlnd_vio__init init;
395 	func_mysqlnd_vio__dtor dtor;
396 	func_mysqlnd_vio__connect connect;
397 
398 	func_mysqlnd_vio__close_stream close_stream;
399 	func_mysqlnd_vio__open_stream open_pipe;
400 	func_mysqlnd_vio__open_stream open_tcp_or_unix;
401 
402 	func_mysqlnd_vio__get_stream get_stream;
403 	func_mysqlnd_vio__set_stream set_stream;
404 	func_mysqlnd_vio__has_valid_stream has_valid_stream;
405 	func_mysqlnd_vio__get_open_stream get_open_stream;
406 
407 	func_mysqlnd_vio__set_client_option set_client_option;
408 	func_mysqlnd_vio__post_connect_set_opt post_connect_set_opt;
409 
410 	func_mysqlnd_vio__enable_ssl enable_ssl;
411 	func_mysqlnd_vio__disable_ssl disable_ssl;
412 
413 	func_mysqlnd_vio__network_read network_read;
414 	func_mysqlnd_vio__network_write network_write;
415 
416 	func_mysqlnd_vio__consume_uneaten_data consume_uneaten_data;
417 
418 	func_mysqlnd_vio__free_contents free_contents;
419 };
420 
421 
422 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory);
423 
424 typedef MYSQLND * (*func_mysqlnd_object_factory__get_connection)(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) * factory, const zend_bool persistent);
425 typedef MYSQLND * (*func_mysqlnd_object_factory__clone_connection_object)(MYSQLND * conn);
426 typedef MYSQLND_STMT * (*func_mysqlnd_object_factory__get_prepared_statement)(MYSQLND_CONN_DATA * conn);
427 typedef MYSQLND_PFC * (*func_mysqlnd_object_factory__get_pfc)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info);
428 typedef MYSQLND_VIO * (*func_mysqlnd_object_factory__get_vio)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info);
429 typedef MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * (*func_mysqlnd_object_factory__get_protocol_payload_decoder_factory)(MYSQLND_CONN_DATA * conn, const zend_bool persistent);
430 
431 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory)432 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory)
433 {
434 	func_mysqlnd_object_factory__get_connection get_connection;
435 	func_mysqlnd_object_factory__clone_connection_object clone_connection_object;
436 	func_mysqlnd_object_factory__get_prepared_statement get_prepared_statement;
437 	func_mysqlnd_object_factory__get_pfc get_protocol_frame_codec;
438 	func_mysqlnd_object_factory__get_vio get_vio;
439 	func_mysqlnd_object_factory__get_protocol_payload_decoder_factory get_protocol_payload_decoder_factory;
440 };
441 
442 
443 typedef enum_func_status	(*func_mysqlnd_conn_data__connect)(MYSQLND_CONN_DATA * conn, MYSQLND_CSTRING hostname, MYSQLND_CSTRING username, MYSQLND_CSTRING password, MYSQLND_CSTRING database, unsigned int port, MYSQLND_CSTRING socket_or_pipe, unsigned int mysql_flags);
444 typedef zend_ulong			(*func_mysqlnd_conn_data__escape_string)(MYSQLND_CONN_DATA * const conn, char *newstr, const char *escapestr, size_t escapestr_len);
445 typedef enum_func_status	(*func_mysqlnd_conn_data__set_charset)(MYSQLND_CONN_DATA * const conn, const char * const charset);
446 typedef enum_func_status	(*func_mysqlnd_conn_data__query)(MYSQLND_CONN_DATA * conn, const char * const query, const size_t query_len);
447 typedef enum_func_status	(*func_mysqlnd_conn_data__send_query)(MYSQLND_CONN_DATA * conn, const char * const query, const size_t query_len, enum_mysqlnd_send_query_type type, zval *read_cb, zval *err_cb);
448 typedef enum_func_status	(*func_mysqlnd_conn_data__reap_query)(MYSQLND_CONN_DATA * conn, enum_mysqlnd_reap_result_type type);
449 typedef MYSQLND_RES *		(*func_mysqlnd_conn_data__use_result)(MYSQLND_CONN_DATA * const conn, const unsigned int flags);
450 typedef MYSQLND_RES *		(*func_mysqlnd_conn_data__store_result)(MYSQLND_CONN_DATA * const conn, const unsigned int flags);
451 typedef enum_func_status	(*func_mysqlnd_conn_data__next_result)(MYSQLND_CONN_DATA * const conn);
452 typedef zend_bool			(*func_mysqlnd_conn_data__more_results)(const MYSQLND_CONN_DATA * const conn);
453 
454 typedef MYSQLND_STMT *		(*func_mysqlnd_conn_data__stmt_init)(MYSQLND_CONN_DATA * const conn);
455 
456 typedef enum_func_status	(*func_mysqlnd_conn_data__shutdown_server)(MYSQLND_CONN_DATA * const conn, uint8_t level);
457 typedef enum_func_status	(*func_mysqlnd_conn_data__refresh_server)(MYSQLND_CONN_DATA * const conn, uint8_t options);
458 
459 typedef enum_func_status	(*func_mysqlnd_conn_data__ping)(MYSQLND_CONN_DATA * const conn);
460 typedef enum_func_status	(*func_mysqlnd_conn_data__kill_connection)(MYSQLND_CONN_DATA * conn, unsigned int pid);
461 typedef enum_func_status	(*func_mysqlnd_conn_data__select_db)(MYSQLND_CONN_DATA * const conn, const char * const db, const size_t db_len);
462 typedef enum_func_status	(*func_mysqlnd_conn_data__server_dump_debug_information)(MYSQLND_CONN_DATA * const conn);
463 typedef enum_func_status	(*func_mysqlnd_conn_data__change_user)(MYSQLND_CONN_DATA * const conn, const char * user, const char * passwd, const char * db, zend_bool silent, size_t passwd_len);
464 
465 typedef unsigned int		(*func_mysqlnd_conn_data__get_error_no)(const MYSQLND_CONN_DATA * const conn);
466 typedef const char *		(*func_mysqlnd_conn_data__get_error_str)(const MYSQLND_CONN_DATA * const conn);
467 typedef const char *		(*func_mysqlnd_conn_data__get_sqlstate)(const MYSQLND_CONN_DATA * const conn);
468 typedef uint64_t			(*func_mysqlnd_conn_data__get_thread_id)(const MYSQLND_CONN_DATA * const conn);
469 typedef void				(*func_mysqlnd_conn_data__get_statistics)(const MYSQLND_CONN_DATA * const conn, zval *return_value ZEND_FILE_LINE_DC);
470 
471 typedef zend_ulong			(*func_mysqlnd_conn_data__get_server_version)(const MYSQLND_CONN_DATA * const conn);
472 typedef const char *		(*func_mysqlnd_conn_data__get_server_information)(const MYSQLND_CONN_DATA * const conn);
473 typedef enum_func_status	(*func_mysqlnd_conn_data__get_server_statistics)(MYSQLND_CONN_DATA * conn, zend_string **message);
474 typedef const char *		(*func_mysqlnd_conn_data__get_host_information)(const MYSQLND_CONN_DATA * const conn);
475 typedef unsigned int		(*func_mysqlnd_conn_data__get_protocol_information)(const MYSQLND_CONN_DATA * const conn);
476 typedef const char *		(*func_mysqlnd_conn_data__get_last_message)(const MYSQLND_CONN_DATA * const conn);
477 typedef const char *		(*func_mysqlnd_conn_data__charset_name)(const MYSQLND_CONN_DATA * const conn);
478 typedef MYSQLND_RES *		(*func_mysqlnd_conn_data__list_method)(MYSQLND_CONN_DATA * conn, const char * const query, const char * const achtung_wild, const char * const par1);
479 
480 typedef uint64_t			(*func_mysqlnd_conn_data__get_last_insert_id)(const MYSQLND_CONN_DATA * const conn);
481 typedef uint64_t			(*func_mysqlnd_conn_data__get_affected_rows)(const MYSQLND_CONN_DATA * const conn);
482 typedef unsigned int		(*func_mysqlnd_conn_data__get_warning_count)(const MYSQLND_CONN_DATA * const conn);
483 
484 typedef unsigned int		(*func_mysqlnd_conn_data__get_field_count)(const MYSQLND_CONN_DATA * const conn);
485 
486 typedef unsigned int		(*func_mysqlnd_conn_data__get_server_status)(const MYSQLND_CONN_DATA * const conn);
487 typedef enum_func_status	(*func_mysqlnd_conn_data__set_server_option)(MYSQLND_CONN_DATA * const conn, enum_mysqlnd_server_option option);
488 typedef enum_func_status	(*func_mysqlnd_conn_data__set_client_option)(MYSQLND_CONN_DATA * const conn, enum_mysqlnd_client_option option, const char * const value);
489 typedef void				(*func_mysqlnd_conn_data__free_contents)(MYSQLND_CONN_DATA * conn);/* private */
490 typedef void				(*func_mysqlnd_conn_data__free_options)(MYSQLND_CONN_DATA * conn);	/* private */
491 typedef void				(*func_mysqlnd_conn_data__dtor)(MYSQLND_CONN_DATA * conn);	/* private */
492 
493 typedef enum_func_status	(*func_mysqlnd_conn_data__query_read_result_set_header)(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * stmt);
494 
495 typedef MYSQLND_CONN_DATA *	(*func_mysqlnd_conn_data__get_reference)(MYSQLND_CONN_DATA * const conn);
496 typedef enum_func_status	(*func_mysqlnd_conn_data__free_reference)(MYSQLND_CONN_DATA * const conn);
497 
498 typedef enum_func_status	(*func_mysqlnd_conn_data__send_command_do_request)(MYSQLND_CONN_DATA * const conn, const enum php_mysqlnd_server_command command, const zend_uchar * const arg, const size_t arg_len, const zend_bool silent, const zend_bool ignore_upsert_status);
499 typedef enum_func_status	(*func_mysqlnd_conn_data__send_command_handle_response)(MYSQLND_CONN_DATA * const conn, const enum mysqlnd_packet_type ok_packet, const zend_bool silent, const enum php_mysqlnd_server_command command, const zend_bool ignore_upsert_status);
500 
501 typedef enum_func_status	(*func_mysqlnd_conn_data__restart_psession)(MYSQLND_CONN_DATA * conn);
502 typedef enum_func_status	(*func_mysqlnd_conn_data__end_psession)(MYSQLND_CONN_DATA * conn);
503 typedef enum_func_status	(*func_mysqlnd_conn_data__send_close)(MYSQLND_CONN_DATA * conn);
504 
505 typedef enum_func_status    (*func_mysqlnd_conn_data__ssl_set)(MYSQLND_CONN_DATA * const conn, const char * key, const char * const cert, const char * const ca, const char * const capath, const char * const cipher);
506 
507 typedef MYSQLND_RES * 		(*func_mysqlnd_conn_data__result_init)(unsigned int field_count);
508 
509 typedef enum_func_status	(*func_mysqlnd_conn_data__set_autocommit)(MYSQLND_CONN_DATA * conn, unsigned int mode);
510 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_commit)(MYSQLND_CONN_DATA * conn);
511 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_rollback)(MYSQLND_CONN_DATA * conn);
512 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_begin)(MYSQLND_CONN_DATA * conn, const unsigned int mode, const char * const name);
513 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_commit_or_rollback)(MYSQLND_CONN_DATA * conn, const zend_bool commit, const unsigned int flags, const char * const name);
514 typedef void				(*func_mysqlnd_conn_data__tx_cor_options_to_string)(const MYSQLND_CONN_DATA * const conn, smart_str * tmp_str, const unsigned int mode);
515 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_savepoint)(MYSQLND_CONN_DATA * conn, const char * const name);
516 typedef enum_func_status	(*func_mysqlnd_conn_data__tx_savepoint_release)(MYSQLND_CONN_DATA * conn, const char * const name);
517 
518 typedef enum_func_status	(*func_mysqlnd_conn_data__local_tx_start)(MYSQLND_CONN_DATA * conn, const size_t this_func);
519 typedef enum_func_status	(*func_mysqlnd_conn_data__local_tx_end)(MYSQLND_CONN_DATA * conn, const size_t this_func, const enum_func_status status);
520 typedef enum_func_status	(*func_mysqlnd_conn_data__execute_init_commands)(MYSQLND_CONN_DATA * conn);
521 typedef unsigned int		(*func_mysqlnd_conn_data__get_updated_connect_flags)(MYSQLND_CONN_DATA * conn, unsigned int mysql_flags);
522 typedef enum_func_status	(*func_mysqlnd_conn_data__connect_handshake)(MYSQLND_CONN_DATA * conn, const MYSQLND_CSTRING * const scheme, const MYSQLND_CSTRING * const username, const MYSQLND_CSTRING * const password, const MYSQLND_CSTRING * const database, const unsigned int mysql_flags);
523 typedef struct st_mysqlnd_authentication_plugin * (*func_mysqlnd_conn_data__fetch_auth_plugin_by_name)(const char * const requested_protocol);
524 
525 typedef enum_func_status	(*func_mysqlnd_conn_data__set_client_option_2d)(MYSQLND_CONN_DATA * const conn, const enum_mysqlnd_client_option option, const char * const key, const char * const value);
526 
527 
528 typedef size_t				(*func_mysqlnd_conn_data__negotiate_client_api_capabilities)(MYSQLND_CONN_DATA * const conn, const size_t flags);
529 typedef size_t				(*func_mysqlnd_conn_data__get_client_api_capabilities)(const MYSQLND_CONN_DATA * const conn);
530 
531 typedef MYSQLND_STRING		(*func_mysqlnd_conn_data__get_scheme)(MYSQLND_CONN_DATA * conn, MYSQLND_CSTRING hostname, MYSQLND_CSTRING *socket_or_pipe, unsigned int port, zend_bool * unix_socket, zend_bool * named_pipe);
532 
533 
534 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data)535 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data)
536 {
537 	func_mysqlnd_conn_data__connect connect;
538 	func_mysqlnd_conn_data__escape_string escape_string;
539 	func_mysqlnd_conn_data__set_charset set_charset;
540 	func_mysqlnd_conn_data__query query;
541 	func_mysqlnd_conn_data__send_query send_query;
542 	func_mysqlnd_conn_data__reap_query reap_query;
543 	func_mysqlnd_conn_data__use_result use_result;
544 	func_mysqlnd_conn_data__store_result store_result;
545 	func_mysqlnd_conn_data__next_result next_result;
546 	func_mysqlnd_conn_data__more_results more_results;
547 
548 	func_mysqlnd_conn_data__stmt_init stmt_init;
549 
550 	func_mysqlnd_conn_data__shutdown_server shutdown_server;
551 	func_mysqlnd_conn_data__refresh_server refresh_server;
552 
553 	func_mysqlnd_conn_data__ping ping;
554 	func_mysqlnd_conn_data__kill_connection kill_connection;
555 	func_mysqlnd_conn_data__select_db select_db;
556 	func_mysqlnd_conn_data__server_dump_debug_information server_dump_debug_information;
557 	func_mysqlnd_conn_data__change_user change_user;
558 
559 	func_mysqlnd_conn_data__get_error_no get_error_no;
560 	func_mysqlnd_conn_data__get_error_str get_error_str;
561 	func_mysqlnd_conn_data__get_sqlstate get_sqlstate;
562 	func_mysqlnd_conn_data__get_thread_id get_thread_id;
563 	func_mysqlnd_conn_data__get_statistics get_statistics;
564 
565 	func_mysqlnd_conn_data__get_server_version get_server_version;
566 	func_mysqlnd_conn_data__get_server_information get_server_information;
567 	func_mysqlnd_conn_data__get_server_statistics get_server_statistics;
568 	func_mysqlnd_conn_data__get_host_information get_host_information;
569 	func_mysqlnd_conn_data__get_protocol_information get_protocol_information;
570 	func_mysqlnd_conn_data__get_last_message get_last_message;
571 	func_mysqlnd_conn_data__charset_name charset_name;
572 	func_mysqlnd_conn_data__list_method list_method;
573 
574 	func_mysqlnd_conn_data__get_last_insert_id get_last_insert_id;
575 	func_mysqlnd_conn_data__get_affected_rows get_affected_rows;
576 	func_mysqlnd_conn_data__get_warning_count get_warning_count;
577 
578 	func_mysqlnd_conn_data__get_field_count get_field_count;
579 
580 	func_mysqlnd_conn_data__get_server_status get_server_status;
581 
582 	func_mysqlnd_conn_data__set_server_option set_server_option;
583 	func_mysqlnd_conn_data__set_client_option set_client_option;
584 	func_mysqlnd_conn_data__free_contents free_contents;
585 	func_mysqlnd_conn_data__free_options free_options;
586 	func_mysqlnd_conn_data__dtor dtor;
587 
588 	func_mysqlnd_conn_data__query_read_result_set_header query_read_result_set_header;
589 
590 	func_mysqlnd_conn_data__get_reference get_reference;
591 	func_mysqlnd_conn_data__free_reference free_reference;
592 
593 	func_mysqlnd_conn_data__restart_psession restart_psession;
594 	func_mysqlnd_conn_data__end_psession end_psession;
595 	func_mysqlnd_conn_data__send_close send_close;
596 
597 	func_mysqlnd_conn_data__ssl_set ssl_set;
598 
599 	func_mysqlnd_conn_data__result_init result_init;
600 	func_mysqlnd_conn_data__set_autocommit set_autocommit;
601 	func_mysqlnd_conn_data__tx_commit tx_commit;
602 	func_mysqlnd_conn_data__tx_rollback tx_rollback;
603 	func_mysqlnd_conn_data__tx_begin tx_begin;
604 	func_mysqlnd_conn_data__tx_commit_or_rollback tx_commit_or_rollback;
605 	func_mysqlnd_conn_data__tx_cor_options_to_string tx_cor_options_to_string;
606 	func_mysqlnd_conn_data__tx_savepoint tx_savepoint;
607 	func_mysqlnd_conn_data__tx_savepoint_release tx_savepoint_release;
608 
609 	func_mysqlnd_conn_data__local_tx_start local_tx_start;
610 	func_mysqlnd_conn_data__local_tx_end local_tx_end;
611 
612 	func_mysqlnd_conn_data__execute_init_commands execute_init_commands;
613 	func_mysqlnd_conn_data__get_updated_connect_flags get_updated_connect_flags;
614 	func_mysqlnd_conn_data__connect_handshake connect_handshake;
615 	func_mysqlnd_conn_data__fetch_auth_plugin_by_name fetch_auth_plugin_by_name;
616 
617 	func_mysqlnd_conn_data__set_client_option_2d set_client_option_2d;
618 
619 	func_mysqlnd_conn_data__negotiate_client_api_capabilities negotiate_client_api_capabilities;
620 	func_mysqlnd_conn_data__get_client_api_capabilities get_client_api_capabilities;
621 
622 	func_mysqlnd_conn_data__get_scheme get_scheme;
623 };
624 
625 
626 typedef enum_func_status	(*func_mysqlnd_data__connect)(MYSQLND * conn, const MYSQLND_CSTRING hostname, const MYSQLND_CSTRING username, const MYSQLND_CSTRING password, const MYSQLND_CSTRING database, unsigned int port, const MYSQLND_CSTRING socket_or_pipe, unsigned int mysql_flags);
627 typedef MYSQLND *			(*func_mysqlnd_conn__clone_object)(MYSQLND * const conn);
628 typedef void				(*func_mysqlnd_conn__dtor)(MYSQLND * conn);
629 typedef enum_func_status	(*func_mysqlnd_conn__close)(MYSQLND * conn, const enum_connection_close_type close_type);
630 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)631 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn)
632 {
633 	func_mysqlnd_data__connect connect;
634 	func_mysqlnd_conn__clone_object clone_object;
635 	func_mysqlnd_conn__dtor dtor;
636 	func_mysqlnd_conn__close close;
637 };
638 
639 
640 	/* for decoding - binary or text protocol */
641 typedef enum_func_status	(*func_mysqlnd_res__row_decoder)(MYSQLND_ROW_BUFFER * row_buffer, zval * fields,
642 															 const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata,
643 															 const zend_bool as_int_or_float, MYSQLND_STATS * const stats);
644 
645 
646 typedef MYSQLND_RES *		(*func_mysqlnd_res__use_result)(MYSQLND_RES * const result, const zend_bool ps_protocol);
647 typedef MYSQLND_RES *		(*func_mysqlnd_res__store_result)(MYSQLND_RES * result, MYSQLND_CONN_DATA * const conn, const unsigned int flags);
648 typedef void 				(*func_mysqlnd_res__fetch_into)(MYSQLND_RES *result, const unsigned int flags, zval *return_value, enum_mysqlnd_extension ext ZEND_FILE_LINE_DC);
649 typedef MYSQLND_ROW_C 		(*func_mysqlnd_res__fetch_row_c)(MYSQLND_RES *result);
650 typedef void 				(*func_mysqlnd_res__fetch_all)(MYSQLND_RES *result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC);
651 typedef void 				(*func_mysqlnd_res__fetch_field_data)(MYSQLND_RES *result, const unsigned int offset, zval *return_value);
652 typedef uint64_t			(*func_mysqlnd_res__num_rows)(const MYSQLND_RES * const result);
653 typedef unsigned int		(*func_mysqlnd_res__num_fields)(const MYSQLND_RES * const result);
654 typedef enum_func_status	(*func_mysqlnd_res__skip_result)(MYSQLND_RES * const result);
655 typedef enum_func_status	(*func_mysqlnd_res__seek_data)(MYSQLND_RES * const result, const uint64_t row);
656 typedef MYSQLND_FIELD_OFFSET (*func_mysqlnd_res__seek_field)(MYSQLND_RES * const result, const MYSQLND_FIELD_OFFSET field_offset);
657 typedef MYSQLND_FIELD_OFFSET (*func_mysqlnd_res__field_tell)(const MYSQLND_RES * const result);
658 typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_field)(MYSQLND_RES * const result);
659 typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_field_direct)(MYSQLND_RES * const result, const MYSQLND_FIELD_OFFSET fieldnr);
660 typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_fields)(MYSQLND_RES * const result);
661 
662 typedef enum_func_status	(*func_mysqlnd_res__read_result_metadata)(MYSQLND_RES * result, MYSQLND_CONN_DATA * conn);
663 typedef const size_t *		(*func_mysqlnd_res__fetch_lengths)(const MYSQLND_RES * const result);
664 typedef enum_func_status	(*func_mysqlnd_res__store_result_fetch_data)(MYSQLND_CONN_DATA * const conn, MYSQLND_RES * result, MYSQLND_RES_METADATA * meta, MYSQLND_ROW_BUFFER ** row_buffers, zend_bool binary_protocol);
665 
666 typedef void				(*func_mysqlnd_res__free_result_buffers)(MYSQLND_RES * result);	/* private */
667 typedef enum_func_status	(*func_mysqlnd_res__free_result)(MYSQLND_RES * result, const zend_bool implicit);
668 typedef void				(*func_mysqlnd_res__free_result_internal)(MYSQLND_RES *result);
669 typedef void				(*func_mysqlnd_res__free_result_contents)(MYSQLND_RES *result);
670 typedef void				(*func_mysqlnd_res__free_buffered_data)(MYSQLND_RES *result);
671 typedef void				(*func_mysqlnd_res__unbuffered_free_last_data)(MYSQLND_RES *result);
672 
673 
674 typedef MYSQLND_RES_METADATA * (*func_mysqlnd_res__result_meta_init)(MYSQLND_RES *result, unsigned int field_count);
675 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)676 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res)
677 {
678 	mysqlnd_fetch_row_func	fetch_row;
679 
680 	func_mysqlnd_res__use_result use_result;
681 	func_mysqlnd_res__store_result store_result;
682 	func_mysqlnd_res__fetch_into fetch_into;
683 	func_mysqlnd_res__fetch_row_c fetch_row_c;
684 	func_mysqlnd_res__fetch_all fetch_all;
685 	func_mysqlnd_res__fetch_field_data fetch_field_data;
686 	func_mysqlnd_res__num_rows num_rows;
687 	func_mysqlnd_res__num_fields num_fields;
688 	func_mysqlnd_res__skip_result skip_result;
689 	func_mysqlnd_res__seek_data seek_data;
690 	func_mysqlnd_res__seek_field seek_field;
691 	func_mysqlnd_res__field_tell field_tell;
692 	func_mysqlnd_res__fetch_field fetch_field;
693 	func_mysqlnd_res__fetch_field_direct fetch_field_direct;
694 	func_mysqlnd_res__fetch_fields fetch_fields;
695 	func_mysqlnd_res__read_result_metadata read_result_metadata;
696 	func_mysqlnd_res__fetch_lengths fetch_lengths;
697 	func_mysqlnd_res__store_result_fetch_data store_result_fetch_data;
698 	func_mysqlnd_res__free_result_buffers free_result_buffers;
699 	func_mysqlnd_res__free_result free_result;
700 	func_mysqlnd_res__free_result_internal free_result_internal;
701 	func_mysqlnd_res__free_result_contents free_result_contents;
702 
703 	func_mysqlnd_res__result_meta_init result_meta_init;
704 
705 	void * unused1;
706 	void * unused2;
707 	void * unused3;
708 	void * unused4;
709 	void * unused5;
710 };
711 
712 
713 typedef uint64_t		(*func_mysqlnd_result_unbuffered__num_rows)(const MYSQLND_RES_UNBUFFERED * const result);
714 typedef const size_t *	(*func_mysqlnd_result_unbuffered__fetch_lengths)(const MYSQLND_RES_UNBUFFERED * const result);
715 typedef void			(*func_mysqlnd_result_unbuffered__free_last_data)(MYSQLND_RES_UNBUFFERED * result, MYSQLND_STATS * const global_stats);
716 typedef void			(*func_mysqlnd_result_unbuffered__free_result)(MYSQLND_RES_UNBUFFERED * const result, MYSQLND_STATS * const global_stats);
717 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered)718 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered)
719 {
720 	mysqlnd_fetch_row_func							fetch_row;
721 	func_mysqlnd_res__row_decoder					row_decoder;
722 	func_mysqlnd_result_unbuffered__num_rows		num_rows;
723 	func_mysqlnd_result_unbuffered__fetch_lengths	fetch_lengths;
724 	func_mysqlnd_result_unbuffered__free_last_data	free_last_data;
725 	func_mysqlnd_result_unbuffered__free_result		free_result;
726 };
727 
728 typedef uint64_t			(*func_mysqlnd_result_buffered__num_rows)(const MYSQLND_RES_BUFFERED * const result);
729 typedef enum_func_status	(*func_mysqlnd_result_buffered__initialize_result_set_rest)(MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta,
730 																						MYSQLND_STATS * stats, const zend_bool int_and_float_native);
731 typedef const size_t *		(*func_mysqlnd_result_buffered__fetch_lengths)(const MYSQLND_RES_BUFFERED * const result);
732 typedef enum_func_status	(*func_mysqlnd_result_buffered__data_seek)(MYSQLND_RES_BUFFERED * const result, const uint64_t row);
733 typedef void				(*func_mysqlnd_result_buffered__free_result)(MYSQLND_RES_BUFFERED * const result);
734 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered)735 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered)
736 {
737 	mysqlnd_fetch_row_func						fetch_row;
738 	func_mysqlnd_res__row_decoder				row_decoder;
739 	func_mysqlnd_result_buffered__num_rows		num_rows;
740 	func_mysqlnd_result_buffered__fetch_lengths	fetch_lengths;
741 	func_mysqlnd_result_buffered__data_seek		data_seek;
742 	func_mysqlnd_result_buffered__initialize_result_set_rest initialize_result_set_rest;
743 	func_mysqlnd_result_buffered__free_result	free_result;
744 };
745 
746 
747 typedef const MYSQLND_FIELD *	(*func_mysqlnd_res_meta__fetch_field)(MYSQLND_RES_METADATA * const meta);
748 typedef const MYSQLND_FIELD *	(*func_mysqlnd_res_meta__fetch_field_direct)(const MYSQLND_RES_METADATA * const meta, const MYSQLND_FIELD_OFFSET fieldnr);
749 typedef const MYSQLND_FIELD *	(*func_mysqlnd_res_meta__fetch_fields)(MYSQLND_RES_METADATA * const meta);
750 typedef MYSQLND_FIELD_OFFSET	(*func_mysqlnd_res_meta__field_tell)(const MYSQLND_RES_METADATA * const meta);
751 typedef MYSQLND_FIELD_OFFSET	(*func_mysqlnd_res_meta__field_seek)(MYSQLND_RES_METADATA * const meta, const MYSQLND_FIELD_OFFSET field_offset);
752 typedef enum_func_status		(*func_mysqlnd_res_meta__read_metadata)(MYSQLND_RES_METADATA * const meta, MYSQLND_CONN_DATA * conn, MYSQLND_RES * result);
753 typedef MYSQLND_RES_METADATA *	(*func_mysqlnd_res_meta__clone_metadata)(MYSQLND_RES *result, const MYSQLND_RES_METADATA * const meta);
754 typedef void					(*func_mysqlnd_res_meta__free_metadata)(MYSQLND_RES_METADATA * meta);
755 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res_meta)756 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res_meta)
757 {
758 	func_mysqlnd_res_meta__fetch_field fetch_field;
759 	func_mysqlnd_res_meta__fetch_field_direct fetch_field_direct;
760 	func_mysqlnd_res_meta__fetch_fields fetch_fields;
761 	func_mysqlnd_res_meta__field_tell field_tell;
762 	func_mysqlnd_res_meta__field_seek field_seek;
763 	func_mysqlnd_res_meta__read_metadata read_metadata;
764 	func_mysqlnd_res_meta__clone_metadata clone_metadata;
765 	func_mysqlnd_res_meta__free_metadata free_metadata;
766 };
767 
768 
769 typedef enum_func_status	(*func_mysqlnd_stmt__prepare)(MYSQLND_STMT * const stmt, const char * const query, const size_t query_len);
770 typedef enum_func_status	(*func_mysqlnd_stmt__send_execute)(MYSQLND_STMT * const s, const enum_mysqlnd_send_execute_type type, zval * read_cb, zval * err_cb);
771 typedef enum_func_status	(*func_mysqlnd_stmt__execute)(MYSQLND_STMT * const stmt);
772 typedef MYSQLND_RES *		(*func_mysqlnd_stmt__use_result)(MYSQLND_STMT * const stmt);
773 typedef MYSQLND_RES *		(*func_mysqlnd_stmt__store_result)(MYSQLND_STMT * const stmt);
774 typedef MYSQLND_RES *		(*func_mysqlnd_stmt__get_result)(MYSQLND_STMT * const stmt);
775 typedef zend_bool			(*func_mysqlnd_stmt__more_results)(const MYSQLND_STMT * const stmt);
776 typedef enum_func_status	(*func_mysqlnd_stmt__next_result)(MYSQLND_STMT * const stmt);
777 typedef enum_func_status	(*func_mysqlnd_stmt__free_result)(MYSQLND_STMT * const stmt);
778 typedef enum_func_status	(*func_mysqlnd_stmt__seek_data)(const MYSQLND_STMT * const stmt, uint64_t row);
779 typedef enum_func_status	(*func_mysqlnd_stmt__reset)(MYSQLND_STMT * const stmt);
780 typedef enum_func_status	(*func_mysqlnd_stmt__close_on_server)(MYSQLND_STMT * const stmt, zend_bool implicit); /* private */
781 typedef enum_func_status	(*func_mysqlnd_stmt__dtor)(MYSQLND_STMT * const stmt, zend_bool implicit); /* use this for mysqlnd_stmt_close */
782 typedef enum_func_status	(*func_mysqlnd_stmt__fetch)(MYSQLND_STMT * const stmt, zend_bool * const fetched_anything);
783 typedef enum_func_status	(*func_mysqlnd_stmt__bind_parameters)(MYSQLND_STMT * const stmt, MYSQLND_PARAM_BIND * const param_bind);
784 typedef enum_func_status	(*func_mysqlnd_stmt__bind_one_parameter)(MYSQLND_STMT * const stmt, unsigned int param_no, zval * const zv, zend_uchar	type);
785 typedef enum_func_status	(*func_mysqlnd_stmt__refresh_bind_param)(MYSQLND_STMT * const stmt);
786 typedef enum_func_status	(*func_mysqlnd_stmt__bind_result)(MYSQLND_STMT * const stmt, MYSQLND_RESULT_BIND * const result_bind);
787 typedef enum_func_status	(*func_mysqlnd_stmt__bind_one_result)(MYSQLND_STMT * const stmt, unsigned int param_no);
788 typedef enum_func_status	(*func_mysqlnd_stmt__send_long_data)(MYSQLND_STMT * const stmt, unsigned int param_num, const char * const data, zend_ulong length);
789 typedef MYSQLND_RES *		(*func_mysqlnd_stmt__get_parameter_metadata)(MYSQLND_STMT * const stmt);
790 typedef MYSQLND_RES *		(*func_mysqlnd_stmt__get_result_metadata)(MYSQLND_STMT * const stmt);
791 typedef uint64_t			(*func_mysqlnd_stmt__get_last_insert_id)(const MYSQLND_STMT * const stmt);
792 typedef uint64_t			(*func_mysqlnd_stmt__get_affected_rows)(const MYSQLND_STMT * const stmt);
793 typedef uint64_t			(*func_mysqlnd_stmt__get_num_rows)(const MYSQLND_STMT * const stmt);
794 typedef unsigned int		(*func_mysqlnd_stmt__get_param_count)(const MYSQLND_STMT * const stmt);
795 typedef unsigned int		(*func_mysqlnd_stmt__get_field_count)(const MYSQLND_STMT * const stmt);
796 typedef unsigned int		(*func_mysqlnd_stmt__get_warning_count)(const MYSQLND_STMT * const stmt);
797 typedef unsigned int		(*func_mysqlnd_stmt__get_error_no)(const MYSQLND_STMT * const stmt);
798 typedef const char *		(*func_mysqlnd_stmt__get_error_str)(const MYSQLND_STMT * const stmt);
799 typedef const char *		(*func_mysqlnd_stmt__get_sqlstate)(const MYSQLND_STMT * const stmt);
800 typedef enum_func_status	(*func_mysqlnd_stmt__get_attribute)(const MYSQLND_STMT * const stmt, enum mysqlnd_stmt_attr attr_type, void * const value);
801 typedef enum_func_status	(*func_mysqlnd_stmt__set_attribute)(MYSQLND_STMT * const stmt, enum mysqlnd_stmt_attr attr_type, const void * const value);
802 typedef MYSQLND_PARAM_BIND *(*func_mysqlnd_stmt__alloc_param_bind)(MYSQLND_STMT * const stmt);
803 typedef MYSQLND_RESULT_BIND*(*func_mysqlnd_stmt__alloc_result_bind)(MYSQLND_STMT * const stmt);
804 typedef	void 				(*func_mysqlnd_stmt__free_parameter_bind)(MYSQLND_STMT * const stmt, MYSQLND_PARAM_BIND *);
805 typedef	void 				(*func_mysqlnd_stmt__free_result_bind)(MYSQLND_STMT * const stmt, MYSQLND_RESULT_BIND *);
806 typedef unsigned int		(*func_mysqlnd_stmt__server_status)(const MYSQLND_STMT * const stmt);
807 typedef enum_func_status 	(*func_mysqlnd_stmt__generate_execute_request)(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer);
808 typedef enum_func_status	(*func_mysqlnd_stmt__parse_execute_response)(MYSQLND_STMT * const s, enum_mysqlnd_parse_exec_response_type type);
809 typedef void 				(*func_mysqlnd_stmt__free_stmt_content)(MYSQLND_STMT * const s);
810 typedef enum_func_status	(*func_mysqlnd_stmt__flush)(MYSQLND_STMT * const stmt);
811 typedef void 				(*func_mysqlnd_stmt__free_stmt_result)(MYSQLND_STMT * const s);
812 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt)813 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt)
814 {
815 	func_mysqlnd_stmt__prepare prepare;
816 	func_mysqlnd_stmt__send_execute send_execute;
817 	func_mysqlnd_stmt__execute execute;
818 	func_mysqlnd_stmt__use_result use_result;
819 	func_mysqlnd_stmt__store_result store_result;
820 	func_mysqlnd_stmt__get_result get_result;
821 	func_mysqlnd_stmt__more_results more_results;
822 	func_mysqlnd_stmt__next_result next_result;
823 	func_mysqlnd_stmt__free_result free_result;
824 	func_mysqlnd_stmt__seek_data seek_data;
825 	func_mysqlnd_stmt__reset reset;
826 	func_mysqlnd_stmt__close_on_server close_on_server;
827 	func_mysqlnd_stmt__dtor dtor;
828 	func_mysqlnd_stmt__fetch fetch;
829 
830 	func_mysqlnd_stmt__bind_parameters bind_parameters;
831 	func_mysqlnd_stmt__bind_one_parameter bind_one_parameter;
832 	func_mysqlnd_stmt__refresh_bind_param refresh_bind_param;
833 	func_mysqlnd_stmt__bind_result bind_result;
834 	func_mysqlnd_stmt__bind_one_result bind_one_result;
835 	func_mysqlnd_stmt__send_long_data send_long_data;
836 	func_mysqlnd_stmt__get_parameter_metadata get_parameter_metadata;
837 	func_mysqlnd_stmt__get_result_metadata get_result_metadata;
838 
839 	func_mysqlnd_stmt__get_last_insert_id get_last_insert_id;
840 	func_mysqlnd_stmt__get_affected_rows get_affected_rows;
841 	func_mysqlnd_stmt__get_num_rows get_num_rows;
842 
843 	func_mysqlnd_stmt__get_param_count get_param_count;
844 	func_mysqlnd_stmt__get_field_count get_field_count;
845 	func_mysqlnd_stmt__get_warning_count get_warning_count;
846 
847 	func_mysqlnd_stmt__get_error_no get_error_no;
848 	func_mysqlnd_stmt__get_error_str get_error_str;
849 	func_mysqlnd_stmt__get_sqlstate get_sqlstate;
850 
851 	func_mysqlnd_stmt__get_attribute get_attribute;
852 	func_mysqlnd_stmt__set_attribute set_attribute;
853 
854 	func_mysqlnd_stmt__alloc_param_bind alloc_parameter_bind;
855 	func_mysqlnd_stmt__alloc_result_bind alloc_result_bind;
856 
857 	func_mysqlnd_stmt__free_parameter_bind free_parameter_bind;
858 	func_mysqlnd_stmt__free_result_bind free_result_bind;
859 
860 	func_mysqlnd_stmt__server_status get_server_status;
861 
862 	func_mysqlnd_stmt__generate_execute_request generate_execute_request;
863 	func_mysqlnd_stmt__parse_execute_response parse_execute_response;
864 
865 	func_mysqlnd_stmt__free_stmt_content free_stmt_content;
866 
867 	func_mysqlnd_stmt__flush flush;
868 
869 	func_mysqlnd_stmt__free_stmt_result free_stmt_result;
870 };
871 
872 
873 struct st_mysqlnd_vio_data
874 {
875 	php_stream			*stream;
876 	zend_bool			ssl;
877 	MYSQLND_VIO_OPTIONS	options;
878 #ifdef MYSQLND_DO_WIRE_CHECK_BEFORE_COMMAND
879 	zend_uchar			last_command;
880 #else
881 	zend_uchar			unused_pad1;
882 #endif
883 
884 	zend_bool			persistent;
885 
886 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) m;
887 };
888 
889 
890 struct st_mysqlnd_vio
891 {
892 	struct st_mysqlnd_vio_data * data;
893 
894 	zend_bool persistent;
895 };
896 
897 
898 
899 typedef struct st_mysqlnd_connection_state MYSQLND_CONNECTION_STATE;
900 typedef enum mysqlnd_connection_state (*func_mysqlnd_connection_state__get)(const MYSQLND_CONNECTION_STATE * const state_struct);
901 typedef void (*func_mysqlnd_connection_state__set)(MYSQLND_CONNECTION_STATE * const state_struct, const enum mysqlnd_connection_state state);
902 
903 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_connection_state)904 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_connection_state)
905 {
906 	func_mysqlnd_connection_state__get get;
907 	func_mysqlnd_connection_state__set set;
908 };
909 
910 struct st_mysqlnd_connection_state
911 {
912 	enum mysqlnd_connection_state state;
913 
914 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_connection_state) *m;
915 };
916 
917 struct st_mysqlnd_connection_data
918 {
919 /* Operation related */
920 	MYSQLND_PFC		* protocol_frame_codec;
921 	MYSQLND_VIO		* vio;
922 	MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * payload_decoder_factory;
923 
924 /* Information related */
925 	MYSQLND_STRING	hostname;
926 	MYSQLND_STRING	unix_socket;
927 	MYSQLND_STRING	username;
928 	MYSQLND_STRING	password;
929 	MYSQLND_STRING	scheme;
930 	uint64_t		thread_id;
931 	char			*server_version;
932 	char			*host_info;
933 	MYSQLND_STRING	authentication_plugin_data;
934 	const MYSQLND_CHARSET *charset;
935 	const MYSQLND_CHARSET *greet_charset;
936 	MYSQLND_STRING	connect_or_select_db;
937 	MYSQLND_INFILE	infile;
938 	unsigned int	protocol_version;
939 	unsigned int	port;
940 	zend_ulong		server_capabilities;
941 
942 	/* For UPSERT queries */
943 	MYSQLND_UPSERT_STATUS * upsert_status;
944 	MYSQLND_UPSERT_STATUS upsert_status_impl;
945 	MYSQLND_STRING last_message;
946 
947 	/* If error packet, we use these */
948 	MYSQLND_ERROR_INFO	* error_info;
949 	MYSQLND_ERROR_INFO	error_info_impl;
950 
951 	MYSQLND_CONNECTION_STATE	state;
952 	enum_mysqlnd_query_type		last_query_type;
953 	/* Temporary storage between query and (use|store)_result() call */
954 	MYSQLND_RES						*current_result;
955 
956 	/*
957 	  How many result sets reference this connection.
958 	  It won't be freed until this number reaches 0.
959 	  The last one, please close the door! :-)
960 	  The result set objects can determine by inspecting
961 	  'quit_sent' whether the connection is still valid.
962 	*/
963 	unsigned int	refcount;
964 
965 	/* Temporal storage for mysql_query */
966 	unsigned int	field_count;
967 
968 	/* options */
969 	MYSQLND_SESSION_OPTIONS	* options;
970 	MYSQLND_SESSION_OPTIONS	options_impl;
971 
972 	/* stats */
973 	MYSQLND_STATS	* stats;
974 
975 	size_t			client_api_capabilities;
976 
977 	zval			async_read_cb;
978 	zval			async_err_cb;
979 	zend_bool		in_async_read_cb;
980 	zend_bool		in_async_err_cb;
981 
982 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) object_factory;
983 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * command;
984 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) * m;
985 
986 	/* persistent connection */
987 	zend_bool		persistent;
988 };
989 
990 
991 struct st_mysqlnd_connection
992 {
993 	MYSQLND_CONN_DATA * data;
994 	zend_bool persistent;
995 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) * m;
996 };
997 
998 
999 
1000 struct st_mysqlnd_packet_greet;
1001 struct st_mysqlnd_packet_auth;
1002 struct st_mysqlnd_packet_auth_response;
1003 struct st_mysqlnd_packet_change_auth_response;
1004 struct st_mysqlnd_packet_ok;
1005 struct st_mysqlnd_packet_command;
1006 struct st_mysqlnd_packet_eof;
1007 struct st_mysqlnd_packet_rset_header;
1008 struct st_mysqlnd_packet_res_field;
1009 struct st_mysqlnd_packet_row;
1010 struct st_mysqlnd_packet_stats;
1011 struct st_mysqlnd_packet_prepare_response;
1012 struct st_mysqlnd_packet_chg_user_resp;
1013 struct st_mysqlnd_packet_auth_pam;
1014 struct st_mysqlnd_packet_sha256_pk_request;
1015 struct st_mysqlnd_packet_sha256_pk_request_response;
1016 struct st_mysqlnd_packet_cached_sha2_result;
1017 
1018 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_greet_packet)(struct st_mysqlnd_packet_greet *packet);
1019 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_auth_packet)(struct st_mysqlnd_packet_auth *packet);
1020 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_auth_response_packet)(struct st_mysqlnd_packet_auth_response *packet);
1021 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_change_auth_response_packet)(struct st_mysqlnd_packet_change_auth_response *packet);
1022 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_ok_packet)(struct st_mysqlnd_packet_ok *packet);
1023 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_command_packet)(struct st_mysqlnd_packet_command *packet);
1024 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_eof_packet)(struct st_mysqlnd_packet_eof *packet);
1025 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_rset_header_packet)(struct st_mysqlnd_packet_rset_header *packet);
1026 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_result_field_packet)(struct st_mysqlnd_packet_res_field *packet);
1027 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_row_packet)(struct st_mysqlnd_packet_row *packet);
1028 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_stats_packet)(struct st_mysqlnd_packet_stats *packet);
1029 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_prepare_response_packet)(struct st_mysqlnd_packet_prepare_response *packet);
1030 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet)(struct st_mysqlnd_packet_chg_user_resp *packet);
1031 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet)(struct st_mysqlnd_packet_sha256_pk_request *packet);
1032 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet)(struct st_mysqlnd_packet_sha256_pk_request_response *packet);
1033 typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet)(struct st_mysqlnd_packet_cached_sha2_result *packet);
1034 
1035 typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command)(
1036 			MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * payload_decoder_factory,
1037 			const enum php_mysqlnd_server_command command,
1038 			const zend_uchar * const arg, const size_t arg_len,
1039 			const zend_bool silent,
1040 
1041 			MYSQLND_CONNECTION_STATE * connection_state,
1042 			MYSQLND_ERROR_INFO	* error_info,
1043 			MYSQLND_UPSERT_STATUS * upsert_status,
1044 			MYSQLND_STATS * stats,
1045 			func_mysqlnd_conn_data__send_close send_close,
1046 			void * send_close_ctx);
1047 
1048 typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_OK)(
1049 			MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const payload_decoder_factory,
1050 			MYSQLND_ERROR_INFO * const error_info,
1051 			MYSQLND_UPSERT_STATUS * const upsert_status,
1052 			const zend_bool ignore_upsert_status,  /* actually used only by LOAD DATA. COM_QUERY and COM_EXECUTE handle the responses themselves */
1053 			MYSQLND_STRING * const last_message);
1054 
1055 typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_EOF)(
1056 			MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * const payload_decoder_factory,
1057 			MYSQLND_ERROR_INFO * const error_info,
1058 			MYSQLND_UPSERT_STATUS * const upsert_status);
1059 
1060 typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response)(
1061 			MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * payload_decoder_factory,
1062 			const enum mysqlnd_packet_type ok_packet,
1063 			const zend_bool silent,
1064 			const enum php_mysqlnd_server_command command,
1065 			const zend_bool ignore_upsert_status, /* actually used only by LOAD DATA. COM_QUERY and COM_EXECUTE handle the responses themselves */
1066 
1067 			MYSQLND_ERROR_INFO	* error_info,
1068 			MYSQLND_UPSERT_STATUS * upsert_status,
1069 			MYSQLND_STRING * last_message);
1070 
1071 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)1072 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory)
1073 {
1074 	func_mysqlnd_protocol_payload_decoder_factory__init_greet_packet init_greet_packet;
1075 	func_mysqlnd_protocol_payload_decoder_factory__init_auth_packet init_auth_packet;
1076 	func_mysqlnd_protocol_payload_decoder_factory__init_auth_response_packet init_auth_response_packet;
1077 	func_mysqlnd_protocol_payload_decoder_factory__init_change_auth_response_packet init_change_auth_response_packet;
1078 	func_mysqlnd_protocol_payload_decoder_factory__init_ok_packet init_ok_packet;
1079 	func_mysqlnd_protocol_payload_decoder_factory__init_command_packet init_command_packet;
1080 	func_mysqlnd_protocol_payload_decoder_factory__init_eof_packet init_eof_packet;
1081 	func_mysqlnd_protocol_payload_decoder_factory__init_rset_header_packet init_rset_header_packet;
1082 	func_mysqlnd_protocol_payload_decoder_factory__init_result_field_packet init_result_field_packet;
1083 	func_mysqlnd_protocol_payload_decoder_factory__init_row_packet init_row_packet;
1084 	func_mysqlnd_protocol_payload_decoder_factory__init_stats_packet init_stats_packet;
1085 	func_mysqlnd_protocol_payload_decoder_factory__init_prepare_response_packet init_prepare_response_packet;
1086 	func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet init_change_user_response_packet;
1087 	func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet init_sha256_pk_request_packet;
1088 	func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet init_sha256_pk_request_response_packet;
1089 	func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet init_cached_sha2_result_packet;
1090 
1091 	func_mysqlnd_protocol_payload_decoder_factory__send_command send_command;
1092 	func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response;
1093 	func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_OK send_command_handle_OK;
1094 	func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_EOF send_command_handle_EOF;
1095 };
1096 
1097 struct st_mysqlnd_protocol_payload_decoder_factory
1098 {
1099 	MYSQLND_CONN_DATA * conn;
1100 	zend_bool persistent;
1101 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) m;
1102 };
1103 
1104 
1105 typedef struct st_mysqlnd_read_buffer {
1106 	zend_uchar 	* data;
1107 	size_t 		offset;
1108 	size_t 		size;
1109 	size_t		len;
1110 	zend_bool	(*is_empty)(const struct st_mysqlnd_read_buffer *);
1111 	void		(*read)(struct st_mysqlnd_read_buffer *, size_t count, zend_uchar * dest);
1112 	size_t		(*bytes_left)(const struct st_mysqlnd_read_buffer *);
1113 	void		(*free_buffer)(struct st_mysqlnd_read_buffer **);
1114 } MYSQLND_READ_BUFFER;
1115 
1116 
1117 
1118 typedef enum_func_status	(*func_mysqlnd_pfc__init)(MYSQLND_PFC * const pfc, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info);
1119 typedef void				(*func_mysqlnd_pfc__dtor)(MYSQLND_PFC * const pfc, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
1120 typedef enum_func_status	(*func_mysqlnd_pfc__reset)(MYSQLND_PFC * const pfc, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
1121 typedef enum_func_status	(*func_mysqlnd_pfc__set_client_option)(MYSQLND_PFC * const pfc, enum_mysqlnd_client_option option, const char * const value);
1122 typedef enum_func_status	(*func_mysqlnd_pfc__decode)(zend_uchar * uncompressed_data, const size_t uncompressed_data_len, const zend_uchar * const compressed_data, const size_t compressed_data_len);
1123 typedef enum_func_status	(*func_mysqlnd_pfc__encode)(zend_uchar * compress_buffer, size_t * compress_buffer_len, const zend_uchar * const uncompressed_data, const size_t uncompressed_data_len);
1124 typedef size_t				(*func_mysqlnd_pfc__send)(MYSQLND_PFC * const pfc, MYSQLND_VIO * const vio, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
1125 typedef enum_func_status	(*func_mysqlnd_pfc__receive)(MYSQLND_PFC * const pfc, MYSQLND_VIO * const vio, zend_uchar * const buffer, const size_t count, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info);
1126 typedef enum_func_status	(*func_mysqlnd_pfc__read_compressed_packet_from_stream_and_fill_read_buffer)(MYSQLND_PFC * pfc, MYSQLND_VIO * const vio, size_t net_payload_size, MYSQLND_STATS * conn_stats, MYSQLND_ERROR_INFO * error_info);
1127 typedef void				(*func_mysqlnd_pfc__free_contents)(MYSQLND_PFC * pfc);
1128 
MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec)1129 MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec)
1130 {
1131 	func_mysqlnd_pfc__init init;
1132 	func_mysqlnd_pfc__dtor dtor;
1133 	func_mysqlnd_pfc__reset reset;
1134 	func_mysqlnd_pfc__set_client_option set_client_option;
1135 
1136 	func_mysqlnd_pfc__decode decode;
1137 	func_mysqlnd_pfc__encode encode;
1138 
1139 	func_mysqlnd_pfc__send send;
1140 	func_mysqlnd_pfc__receive receive;
1141 
1142 	func_mysqlnd_pfc__read_compressed_packet_from_stream_and_fill_read_buffer read_compressed_packet_from_stream_and_fill_read_buffer;
1143 
1144 	func_mysqlnd_pfc__free_contents free_contents;
1145 };
1146 
1147 
1148 struct st_mysqlnd_protocol_frame_codec_data
1149 {
1150 	php_stream		*stream;
1151 	zend_bool		compressed;
1152 	zend_bool		ssl;
1153 	uint64_t		flags;
1154 	char *			sha256_server_public_key;
1155 
1156 #ifdef MYSQLND_COMPRESSION_ENABLED
1157 	MYSQLND_READ_BUFFER	* uncompressed_data;
1158 #else
1159 	void * 				unused_pad1;
1160 #endif
1161 
1162 	/* sequence for simple checking of correct packets */
1163 	zend_uchar		packet_no;
1164 	zend_uchar		compressed_envelope_packet_no;
1165 
1166 	zend_bool		persistent;
1167 
1168 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_packet_frame_codec) m;
1169 };
1170 
1171 
1172 struct st_mysqlnd_protocol_frame_codec
1173 {
1174 	MYSQLND_CMD_BUFFER	cmd_buffer;
1175 
1176 	struct st_mysqlnd_protocol_frame_codec_data * data;
1177 
1178 	zend_bool 		persistent;
1179 };
1180 
1181 
1182 struct st_mysqlnd_result_metadata
1183 {
1184 	MYSQLND_FIELD					*fields;
1185 
1186 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res_meta) * m;
1187 
1188 	unsigned int					current_field;
1189 	unsigned int					field_count;
1190 };
1191 
1192 
1193 #define def_mysqlnd_buffered_result_parent 			\
1194 	MYSQLND_ROW_BUFFER	*row_buffers;				\
1195 	uint64_t			row_count;					\
1196 	uint64_t			initialized_rows;			\
1197 													\
1198 	/*  Column lengths of current row - both buffered and unbuffered. For buffered results it duplicates the data found in **data */ \
1199 	size_t				*lengths;					\
1200 													\
1201 	MYSQLND_MEMORY_POOL	*result_set_memory_pool;	\
1202 													\
1203 	unsigned int		references;					\
1204 													\
1205 	MYSQLND_ERROR_INFO	error_info;					\
1206 													\
1207 	unsigned int		field_count;				\
1208 	zend_bool			ps;							\
1209 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_buffered) m;	\
1210 	enum mysqlnd_buffered_type type;				\
1211 	void				* unused1;					\
1212 	void				* unused2;					\
1213 	void				* unused3
1214 
1215 
1216 struct st_mysqlnd_buffered_result_parent
1217 {
1218 	def_mysqlnd_buffered_result_parent;
1219 };
1220 
1221 
1222 struct st_mysqlnd_buffered_result_zval
1223 {
1224 	def_mysqlnd_buffered_result_parent;
1225 
1226 	zval	*data;
1227 	zval	*data_cursor;
1228 };
1229 
1230 
1231 struct st_mysqlnd_buffered_result_c
1232 {
1233 	def_mysqlnd_buffered_result_parent;
1234 
1235 	zend_uchar	*initialized; /* every row is a single bit */
1236 	uint64_t	current_row;
1237 };
1238 
1239 
1240 struct st_mysqlnd_unbuffered_result
1241 {
1242 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) m;
1243 	uint64_t			row_count;
1244 
1245 	/* For unbuffered (both normal and PS) */
1246 	zval				*last_row_data;
1247 	MYSQLND_ROW_BUFFER	 last_row_buffer;
1248 
1249 	/*
1250 	  Column lengths of current row - both buffered and unbuffered.
1251 	  For buffered results it duplicates the data found in **data
1252 	*/
1253 	size_t				*lengths;
1254 
1255 	MYSQLND_MEMORY_POOL	*result_set_memory_pool;
1256 
1257 	struct st_mysqlnd_packet_row *row_packet;
1258 
1259 	unsigned int		field_count;
1260 
1261 	zend_bool			eof_reached;
1262 
1263 	zend_bool			ps;
1264 };
1265 
1266 
1267 struct st_mysqlnd_res
1268 {
1269 	MYSQLND_CONN_DATA		*conn;
1270 	enum_mysqlnd_res_type	type;
1271 	unsigned int			field_count;
1272 
1273 	/* For metadata functions */
1274 	MYSQLND_RES_METADATA	*meta;
1275 
1276 	/* To be used with store_result() - both normal and PS */
1277 	MYSQLND_RES_BUFFERED	*stored_data;
1278 	MYSQLND_RES_UNBUFFERED	*unbuf;
1279 
1280 	MYSQLND_MEMORY_POOL		*memory_pool;
1281 
1282 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) m;
1283 };
1284 
1285 
1286 struct st_mysqlnd_param_bind
1287 {
1288 	zval		zv;
1289 	zend_uchar	type;
1290 	enum_param_bind_flags	flags;
1291 };
1292 
1293 struct st_mysqlnd_result_bind
1294 {
1295 	zval		zv;
1296 	zend_bool	bound;
1297 };
1298 
1299 
1300 struct st_mysqlnd_stmt_data
1301 {
1302 	MYSQLND_CONN_DATA			*conn;
1303 	zend_ulong					stmt_id;
1304 	zend_ulong					flags;/* cursor is set here */
1305 	enum_mysqlnd_stmt_state		state;
1306 	MYSQLND_RES					*result;
1307 	unsigned int				field_count;
1308 	unsigned int				param_count;
1309 	unsigned char				send_types_to_server;
1310 	MYSQLND_PARAM_BIND			*param_bind;
1311 	MYSQLND_RESULT_BIND			*result_bind;
1312 
1313 	MYSQLND_UPSERT_STATUS * 	upsert_status;
1314 	MYSQLND_UPSERT_STATUS 		upsert_status_impl;
1315 
1316 	MYSQLND_ERROR_INFO *		error_info;
1317 	MYSQLND_ERROR_INFO			error_info_impl;
1318 
1319 	zend_bool					update_max_length;
1320 	zend_ulong					prefetch_rows;
1321 
1322 	zend_bool					cursor_exists;
1323 	mysqlnd_stmt_use_or_store_func default_rset_handler;
1324 
1325 	zval						execute_read_cb;
1326 	zval						execute_err_cb;
1327 	zend_bool					in_execute_read_cb;
1328 	zend_bool					in_execute_err_cb;
1329 
1330 	MYSQLND_CMD_BUFFER			execute_cmd_buffer;
1331 	unsigned int				execute_count;/* count how many times the stmt was executed */
1332 };
1333 
1334 
1335 struct st_mysqlnd_stmt
1336 {
1337 	MYSQLND_STMT_DATA * data;
1338 	MYSQLND_CLASS_METHODS_TYPE(mysqlnd_stmt) * m;
1339 };
1340 
1341 
1342 struct st_mysqlnd_plugin_header
1343 {
1344 	unsigned int	plugin_api_version;
1345 	const char *	plugin_name;
1346 	zend_ulong	plugin_version;
1347 	const char *	plugin_string_version;
1348 	const char *	plugin_license;
1349 	const char *	plugin_author;
1350 	struct
1351 	{
1352 		MYSQLND_STATS *			values;
1353 		const MYSQLND_STRING *	names;
1354 	} plugin_stats;
1355 
1356 	struct
1357 	{
1358 		enum_func_status (*plugin_shutdown)(void * plugin);
1359 	} m;
1360 };
1361 
1362 
1363 struct st_mysqlnd_plugin_core
1364 {
1365 	struct st_mysqlnd_plugin_header plugin_header;
1366 };
1367 
1368 
1369 struct st_mysqlnd_typeii_plugin_example
1370 {
1371 	struct st_mysqlnd_plugin_header plugin_header;
1372 	void * methods;
1373 	unsigned int counter;
1374 };
1375 
1376 struct st_mysqlnd_authentication_plugin;
1377 
1378 typedef zend_uchar * (*func_auth_plugin__get_auth_data)(struct st_mysqlnd_authentication_plugin * self,
1379 														size_t * auth_data_len,
1380 														MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd,
1381 														const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len,
1382 														const MYSQLND_SESSION_OPTIONS * const session_options,
1383 														const MYSQLND_PFC_DATA * const pfc_data, const zend_ulong mysql_flags
1384 														);
1385 
1386 typedef enum_func_status (*func_auth_plugin__handle_server_response)(struct st_mysqlnd_authentication_plugin * self,
1387 		MYSQLND_CONN_DATA * conn,
1388 		const zend_uchar * auth_plugin_data, size_t auth_plugin_data_len,
1389 		const char * const passwd,
1390 		const size_t passwd_len,
1391 		char **new_auth_protocol, size_t *new_auth_protocol_len,
1392 		zend_uchar **new_auth_protocol_data, size_t *new_auth_protocol_data_len
1393 		);
1394 
1395 struct st_mysqlnd_authentication_plugin
1396 {
1397 	struct st_mysqlnd_plugin_header plugin_header;
1398 	struct {
1399 		func_auth_plugin__get_auth_data get_auth_data;
1400 		func_auth_plugin__handle_server_response handle_server_response;
1401 	} methods;
1402 };
1403 
1404 #endif /* MYSQLND_STRUCTS_H */
1405