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