xref: /PHP-7.0/ext/mysqlnd/mysqlnd_priv.h (revision 478f119a)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2006-2017 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   |          Georg Richter <georg@php.net>                               |
18   +----------------------------------------------------------------------+
19 */
20 
21 #ifndef MYSQLND_PRIV_H
22 #define MYSQLND_PRIV_H
23 
24 #ifdef ZTS
25 #include "TSRM.h"
26 #endif
27 
28 #define MYSQLND_STR_W_LEN(str)  str, (sizeof(str) - 1)
29 
30 #define MYSQLND_DEBUG_DUMP_TIME				1
31 #define MYSQLND_DEBUG_DUMP_TRACE			2
32 #define MYSQLND_DEBUG_DUMP_PID				4
33 #define MYSQLND_DEBUG_DUMP_LINE				8
34 #define MYSQLND_DEBUG_DUMP_FILE				16
35 #define MYSQLND_DEBUG_DUMP_LEVEL			32
36 #define MYSQLND_DEBUG_APPEND				64
37 #define MYSQLND_DEBUG_FLUSH					128
38 #define MYSQLND_DEBUG_TRACE_MEMORY_CALLS	256
39 #define MYSQLND_DEBUG_PROFILE_CALLS			512
40 
41 
42 /* Client Error codes */
43 #define CR_UNKNOWN_ERROR		2000
44 #define CR_CONNECTION_ERROR		2002
45 #define CR_SERVER_GONE_ERROR	2006
46 #define CR_OUT_OF_MEMORY		2008
47 #define CR_SERVER_LOST			2013
48 #define CR_COMMANDS_OUT_OF_SYNC	2014
49 #define CR_CANT_FIND_CHARSET	2019
50 #define CR_MALFORMED_PACKET		2027
51 #define CR_NOT_IMPLEMENTED		2054
52 #define CR_NO_PREPARE_STMT		2030
53 #define CR_PARAMS_NOT_BOUND		2031
54 #define CR_INVALID_PARAMETER_NO	2034
55 #define CR_INVALID_BUFFER_USE	2035
56 
57 #define MYSQLND_EE_FILENOTFOUND	 7890
58 
59 #define UNKNOWN_SQLSTATE		"HY000"
60 
61 #define MAX_CHARSET_LEN			32
62 
63 
64 #define SET_ERROR_AFF_ROWS(s)	(s)->upsert_status->affected_rows = (uint64_t) ~0
65 
66 /* Error handling */
67 #define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
68 	{\
69 		if ((buf)) { \
70 			mnd_pefree((buf), (persistent)); \
71 		} \
72 		if ((message)) { \
73 			(buf) = mnd_pestrndup((message), (len), (persistent)); \
74 		} else { \
75 			(buf) = NULL; \
76 		} \
77 		(buf_len) = (len); \
78 	}
79 
80 #define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
81 	{\
82 		if ((buf)) { \
83 			mnd_pefree((buf), (persistent)); \
84 			(buf) = NULL; \
85 		} \
86 		(buf_len) = 0; \
87 	}
88 
89 
90 #define SET_EMPTY_ERROR(error_info) \
91 	{ \
92 		(error_info).error_no = 0; \
93 		(error_info).error[0] = '\0'; \
94 		strlcpy((error_info).sqlstate, "00000", sizeof((error_info).sqlstate)); \
95 		if ((error_info).error_list) { \
96 			zend_llist_clean((error_info).error_list); \
97 		} \
98 	}
99 
100 
101 #define SET_CLIENT_ERROR(error_info, a, b, c) \
102 { \
103 	if (0 == (a)) { \
104 		SET_EMPTY_ERROR((error_info)); \
105 	} else { \
106 		(error_info).error_no = (a); \
107 		strlcpy((error_info).sqlstate, (b), sizeof((error_info).sqlstate)); \
108 		strlcpy((error_info).error, (c), sizeof((error_info).error)); \
109 		if ((error_info).error_list) {\
110 			MYSQLND_ERROR_LIST_ELEMENT error_for_the_list = {0}; \
111 																	\
112 			error_for_the_list.error_no = (a); \
113 			strlcpy(error_for_the_list.sqlstate, (b), sizeof(error_for_the_list.sqlstate)); \
114 			error_for_the_list.error = mnd_pestrdup((c), TRUE); \
115 			if (error_for_the_list.error) { \
116 				DBG_INF_FMT("adding error [%s] to the list", error_for_the_list.error); \
117 				zend_llist_add_element((error_info).error_list, &error_for_the_list); \
118 			} \
119 		} \
120 	} \
121 }
122 
123 
124 #define COPY_CLIENT_ERROR(error_info_to, error_info_from) \
125 	{ \
126 		SET_CLIENT_ERROR((error_info_to), (error_info_from).error_no, (error_info_from).sqlstate, (error_info_from).error); \
127 	}
128 
129 
130 #define SET_OOM_ERROR(error_info) SET_CLIENT_ERROR((error_info), CR_OUT_OF_MEMORY, UNKNOWN_SQLSTATE, mysqlnd_out_of_memory)
131 
132 
133 #define SET_STMT_ERROR(stmt, a, b, c)	SET_CLIENT_ERROR(*(stmt)->error_info, a, b, c)
134 
135 #define CONN_GET_STATE(c)		(c)->m->get_state((c))
136 #define CONN_SET_STATE(c, s)	(c)->m->set_state((c), (s))
137 
138 /* PS stuff */
139 typedef void (*ps_field_fetch_func)(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row);
140 struct st_mysqlnd_perm_bind {
141 	ps_field_fetch_func func;
142 	/* should be signed int */
143 	int					pack_len;
144 	unsigned int		php_type;
145 	zend_bool			is_possibly_blob;
146 	zend_bool			can_ret_as_str_in_uni;
147 };
148 
149 extern struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
150 
151 enum_func_status mysqlnd_stmt_fetch_row_buffered(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything);
152 enum_func_status mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything);
153 
154 
155 PHPAPI extern const char * const mysqlnd_old_passwd;
156 PHPAPI extern const char * const mysqlnd_out_of_sync;
157 PHPAPI extern const char * const mysqlnd_server_gone;
158 PHPAPI extern const char * const mysqlnd_out_of_memory;
159 
160 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_object_factory);
161 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn);
162 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_conn_data);
163 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_res);
164 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_result_unbuffered);
165 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_result_buffered);
166 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_protocol);
167 PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_net);
168 
169 enum_func_status mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * filename, zend_bool * is_warning);
170 
171 
172 
173 void _mysqlnd_init_ps_subsystem();/* This one is private, mysqlnd_library_init() will call it */
174 void _mysqlnd_init_ps_fetch_subsystem();
175 
176 void ps_fetch_from_1_to_8_bytes(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row, unsigned int byte_count);
177 
178 void mysqlnd_plugin_subsystem_init(void);
179 void mysqlnd_plugin_subsystem_end(void);
180 
181 void mysqlnd_register_builtin_authentication_plugins(void);
182 
183 void mysqlnd_example_plugin_register(void);
184 
185 struct st_mysqlnd_packet_greet;
186 struct st_mysqlnd_authentication_plugin;
187 
188 enum_func_status
189 mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
190 						const char * const user,
191 						const char * const passwd,
192 						const size_t passwd_len,
193 						const char * const db,
194 						const size_t db_len,
195 						const MYSQLND_OPTIONS * const options,
196 						zend_ulong mysql_flags,
197 						unsigned int server_charset_no,
198 						zend_bool use_full_blown_auth_packet,
199 						const char * const auth_protocol,
200 						const zend_uchar * const auth_plugin_data,
201 						const size_t auth_plugin_data_len,
202 						char ** switch_to_auth_protocol,
203 						size_t * switch_to_auth_protocol_len,
204 						zend_uchar ** switch_to_auth_protocol_data,
205 						size_t * switch_to_auth_protocol_data_len
206 						);
207 
208 enum_func_status
209 mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
210 								const char * const user,
211 								const size_t user_len,
212 								const char * const passwd,
213 								const size_t passwd_len,
214 								const char * const db,
215 								const size_t db_len,
216 								const zend_bool silent,
217 								zend_bool use_full_blown_auth_packet,
218 								const char * const auth_protocol,
219 								zend_uchar * auth_plugin_data,
220 								size_t auth_plugin_data_len,
221 								char ** switch_to_auth_protocol,
222 								size_t * switch_to_auth_protocol_len,
223 								zend_uchar ** switch_to_auth_protocol_data,
224 								size_t * switch_to_auth_protocol_data_len
225 								);
226 
227 #endif	/* MYSQLND_PRIV_H */
228 
229 
230 /*
231  * Local variables:
232  * tab-width: 4
233  * c-basic-offset: 4
234  * End:
235  * vim600: noet sw=4 ts=4 fdm=marker
236  * vim<600: noet sw=4 ts=4
237  */
238