Skip to content

Commit 4bb784c

Browse files
committed
MNDR:
- make MYSQLND_ERROR_INFO a class
1 parent fb1b5ab commit 4bb784c

13 files changed

+396
-349
lines changed

ext/mysqlnd/mysqlnd.c

+138-112
Large diffs are not rendered by default.

ext/mysqlnd/mysqlnd_auth.c

+28-28
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
6060
auth_resp_packet = conn->payload_decoder_factory->m.get_auth_response_packet(conn->payload_decoder_factory, FALSE);
6161

6262
if (!auth_resp_packet) {
63-
SET_OOM_ERROR(*conn->error_info);
63+
SET_OOM_ERROR(conn->error_info);
6464
goto end;
6565
}
6666

6767
if (use_full_blown_auth_packet != TRUE) {
6868
change_auth_resp_packet = conn->payload_decoder_factory->m.get_change_auth_response_packet(conn->payload_decoder_factory, FALSE);
6969
if (!change_auth_resp_packet) {
70-
SET_OOM_ERROR(*conn->error_info);
70+
SET_OOM_ERROR(conn->error_info);
7171
goto end;
7272
}
7373

7474
change_auth_resp_packet->auth_data = auth_plugin_data;
7575
change_auth_resp_packet->auth_data_len = auth_plugin_data_len;
7676

77-
if (!PACKET_WRITE(change_auth_resp_packet, conn)) {
77+
if (!PACKET_WRITE(change_auth_resp_packet)) {
7878
CONN_SET_STATE(conn, CONN_QUIT_SENT);
79-
SET_CLIENT_ERROR(*conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
79+
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
8080
goto end;
8181
}
8282
} else {
@@ -103,20 +103,20 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
103103
auth_packet->connect_attr = conn->options->connect_attr;
104104
}
105105

106-
if (!PACKET_WRITE(auth_packet, conn)) {
106+
if (!PACKET_WRITE(auth_packet)) {
107107
goto end;
108108
}
109109
}
110110
if (use_full_blown_auth_packet == TRUE) {
111111
conn->charset = mysqlnd_find_charset_nr(auth_packet->charset_no);
112112
}
113113

114-
if (FAIL == PACKET_READ(auth_resp_packet, conn) || auth_resp_packet->response_code >= 0xFE) {
114+
if (FAIL == PACKET_READ(auth_resp_packet) || auth_resp_packet->response_code >= 0xFE) {
115115
if (auth_resp_packet->response_code == 0xFE) {
116116
/* old authentication with new server !*/
117117
if (!auth_resp_packet->new_auth_protocol) {
118118
DBG_ERR(mysqlnd_old_passwd);
119-
SET_CLIENT_ERROR(*conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
119+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
120120
} else {
121121
*switch_to_auth_protocol = mnd_pestrndup(auth_resp_packet->new_auth_protocol, auth_resp_packet->new_auth_protocol_len, FALSE);
122122
*switch_to_auth_protocol_len = auth_resp_packet->new_auth_protocol_len;
@@ -134,7 +134,7 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn,
134134
strlcpy(conn->error_info->sqlstate, auth_resp_packet->sqlstate, sizeof(conn->error_info->sqlstate));
135135
DBG_ERR_FMT("ERROR:%u [SQLSTATE:%s] %s", auth_resp_packet->error_no, auth_resp_packet->sqlstate, auth_resp_packet->error);
136136
}
137-
SET_CLIENT_ERROR(*conn->error_info, auth_resp_packet->error_no, UNKNOWN_SQLSTATE, auth_resp_packet->error);
137+
SET_CLIENT_ERROR(conn->error_info, auth_resp_packet->error_no, UNKNOWN_SQLSTATE, auth_resp_packet->error);
138138
}
139139
goto end;
140140
}
@@ -181,30 +181,30 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
181181
chg_user_resp = conn->payload_decoder_factory->m.get_change_user_response_packet(conn->payload_decoder_factory, FALSE);
182182

183183
if (!chg_user_resp) {
184-
SET_OOM_ERROR(*conn->error_info);
184+
SET_OOM_ERROR(conn->error_info);
185185
goto end;
186186
}
187187

188188
if (use_full_blown_auth_packet != TRUE) {
189189
change_auth_resp_packet = conn->payload_decoder_factory->m.get_change_auth_response_packet(conn->payload_decoder_factory, FALSE);
190190
if (!change_auth_resp_packet) {
191-
SET_OOM_ERROR(*conn->error_info);
191+
SET_OOM_ERROR(conn->error_info);
192192
goto end;
193193
}
194194

195195
change_auth_resp_packet->auth_data = auth_plugin_data;
196196
change_auth_resp_packet->auth_data_len = auth_plugin_data_len;
197197

198-
if (!PACKET_WRITE(change_auth_resp_packet, conn)) {
198+
if (!PACKET_WRITE(change_auth_resp_packet)) {
199199
CONN_SET_STATE(conn, CONN_QUIT_SENT);
200-
SET_CLIENT_ERROR(*conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
200+
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
201201
goto end;
202202
}
203203
} else {
204204
auth_packet = conn->payload_decoder_factory->m.get_auth_packet(conn->payload_decoder_factory, FALSE);
205205

206206
if (!auth_packet) {
207-
SET_OOM_ERROR(*conn->error_info);
207+
SET_OOM_ERROR(conn->error_info);
208208
goto end;
209209
}
210210

@@ -223,21 +223,21 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
223223
auth_packet->charset_no = conn->charset->nr;
224224
}
225225

226-
if (!PACKET_WRITE(auth_packet, conn)) {
226+
if (!PACKET_WRITE(auth_packet)) {
227227
CONN_SET_STATE(conn, CONN_QUIT_SENT);
228-
SET_CLIENT_ERROR(*conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
228+
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
229229
goto end;
230230
}
231231
}
232232

233-
ret = PACKET_READ(chg_user_resp, conn);
234-
COPY_CLIENT_ERROR(*conn->error_info, chg_user_resp->error_info);
233+
ret = PACKET_READ(chg_user_resp);
234+
COPY_CLIENT_ERROR(conn->error_info, chg_user_resp->error_info);
235235

236236
if (0xFE == chg_user_resp->response_code) {
237237
ret = FAIL;
238238
if (!chg_user_resp->new_auth_protocol) {
239239
DBG_ERR(mysqlnd_old_passwd);
240-
SET_CLIENT_ERROR(*conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
240+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
241241
} else {
242242
*switch_to_auth_protocol = mnd_pestrndup(chg_user_resp->new_auth_protocol, chg_user_resp->new_auth_protocol_len, FALSE);
243243
*switch_to_auth_protocol_len = chg_user_resp->new_auth_protocol_len;
@@ -262,11 +262,11 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
262262
if (conn->m->get_server_version(conn) > 50113L &&conn->m->get_server_version(conn) < 50118L) {
263263
MYSQLND_PACKET_OK * redundant_error_packet = conn->payload_decoder_factory->m.get_ok_packet(conn->payload_decoder_factory, FALSE);
264264
if (redundant_error_packet) {
265-
PACKET_READ(redundant_error_packet, conn);
265+
PACKET_READ(redundant_error_packet);
266266
PACKET_FREE(redundant_error_packet);
267267
DBG_INF_FMT("Server is %u, buggy, sends two ERR messages", conn->m->get_server_version(conn));
268268
} else {
269-
SET_OOM_ERROR(*conn->error_info);
269+
SET_OOM_ERROR(conn->error_info);
270270
}
271271
}
272272
}
@@ -297,7 +297,7 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn,
297297
} else if (ret == FAIL && chg_user_resp->server_asked_323_auth == TRUE) {
298298
/* old authentication with new server !*/
299299
DBG_ERR(mysqlnd_old_passwd);
300-
SET_CLIENT_ERROR(*conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
300+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, mysqlnd_old_passwd);
301301
}
302302
end:
303303
PACKET_FREE(change_auth_resp_packet);
@@ -371,7 +371,7 @@ mysqlnd_native_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
371371
/* 5.5.x reports 21 as scramble length because it needs to show the length of the data before the plugin name */
372372
if (auth_plugin_data_len < SCRAMBLE_LENGTH) {
373373
/* mysql_native_password only works with SCRAMBLE_LENGTH scramble */
374-
SET_CLIENT_ERROR(*conn->error_info, CR_MALFORMED_PACKET, UNKNOWN_SQLSTATE, "The server sent wrong length for scramble");
374+
SET_CLIENT_ERROR(conn->error_info, CR_MALFORMED_PACKET, UNKNOWN_SQLSTATE, "The server sent wrong length for scramble");
375375
DBG_ERR_FMT("The server sent wrong length for scramble %u. Expected %u", auth_plugin_data_len, SCRAMBLE_LENGTH);
376376
DBG_RETURN(NULL);
377377
}
@@ -501,23 +501,23 @@ mysqlnd_sha256_get_rsa_key(MYSQLND_CONN_DATA * conn,
501501
DBG_INF("requesting the public key from the server");
502502
pk_req_packet = conn->payload_decoder_factory->m.get_sha256_pk_request_packet(conn->payload_decoder_factory, FALSE);
503503
if (!pk_req_packet) {
504-
SET_OOM_ERROR(*conn->error_info);
504+
SET_OOM_ERROR(conn->error_info);
505505
break;
506506
}
507507
pk_resp_packet = conn->payload_decoder_factory->m.get_sha256_pk_request_response_packet(conn->payload_decoder_factory, FALSE);
508508
if (!pk_resp_packet) {
509-
SET_OOM_ERROR(*conn->error_info);
509+
SET_OOM_ERROR(conn->error_info);
510510
PACKET_FREE(pk_req_packet);
511511
break;
512512
}
513513

514-
if (! PACKET_WRITE(pk_req_packet, conn)) {
514+
if (! PACKET_WRITE(pk_req_packet)) {
515515
DBG_ERR_FMT("Error while sending public key request packet");
516516
php_error(E_WARNING, "Error while sending public key request packet. PID=%d", getpid());
517517
CONN_SET_STATE(conn, CONN_QUIT_SENT);
518518
break;
519519
}
520-
if (FAIL == PACKET_READ(pk_resp_packet, conn) || NULL == pk_resp_packet->public_key) {
520+
if (FAIL == PACKET_READ(pk_resp_packet) || NULL == pk_resp_packet->public_key) {
521521
DBG_ERR_FMT("Error while receiving public key");
522522
php_error(E_WARNING, "Error while receiving public key. PID=%d", getpid());
523523
CONN_SET_STATE(conn, CONN_QUIT_SENT);
@@ -537,7 +537,7 @@ mysqlnd_sha256_get_rsa_key(MYSQLND_CONN_DATA * conn,
537537
DBG_INF_FMT("ret=%p", ret);
538538
DBG_RETURN(ret);
539539

540-
SET_CLIENT_ERROR(*conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE,
540+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE,
541541
"sha256_server_public_key is not set for the connection or as mysqlnd.sha256_server_public_key");
542542
DBG_ERR("server_public_key is not set");
543543
DBG_RETURN(NULL);
@@ -605,7 +605,7 @@ mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self
605605
*/
606606
if ((size_t) server_public_key_len - 41 <= passwd_len) {
607607
/* password message is to long */
608-
SET_CLIENT_ERROR(*conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
608+
SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long");
609609
DBG_ERR("password is too long");
610610
DBG_RETURN(NULL);
611611
}

ext/mysqlnd/mysqlnd_driver.c

+13-32
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,6 @@ PHPAPI void mysqlnd_library_init(void)
9393
/* }}} */
9494

9595

96-
97-
/* {{{ mysqlnd_error_list_pdtor */
98-
static void
99-
mysqlnd_error_list_pdtor(void * pDest)
100-
{
101-
MYSQLND_ERROR_LIST_ELEMENT * element = (MYSQLND_ERROR_LIST_ELEMENT *) pDest;
102-
103-
DBG_ENTER("mysqlnd_error_list_pdtor");
104-
if (element->error) {
105-
mnd_pefree(element->error, TRUE);
106-
}
107-
DBG_VOID_RETURN;
108-
}
109-
/* }}} */
110-
111-
11296
/* {{{ mysqlnd_object_factory::get_connection */
11397
static MYSQLND *
11498
MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_factory_methods * factory, zend_bool persistent)
@@ -133,7 +117,12 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_
133117
new_object->m = mysqlnd_conn_get_methods();
134118
data = new_object->data;
135119

136-
data->error_info = &(data->error_info_impl);
120+
if (FAIL == mysqlnd_error_info_init(&data->error_info_impl, persistent)) {
121+
new_object->m->dtor(new_object);
122+
DBG_RETURN(NULL);
123+
}
124+
data->error_info = &data->error_info_impl;
125+
137126
data->options = &(data->options_impl);
138127

139128
mysqlnd_upsert_status_init(&data->upsert_status_impl);
@@ -146,13 +135,6 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(struct st_mysqlnd_object_
146135
CONN_SET_STATE(data, CONN_ALLOCED);
147136
data->m->get_reference(data);
148137

149-
data->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), persistent);
150-
if (!data->error_info->error_list) {
151-
new_object->m->dtor(new_object);
152-
DBG_RETURN(NULL);
153-
}
154-
zend_llist_init(data->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t)mysqlnd_error_list_pdtor, persistent);
155-
156138
mysqlnd_stats_init(&data->stats, STAT_LAST, persistent);
157139

158140
data->net = mysqlnd_net_init(persistent, data->stats, data->error_info);
@@ -220,7 +202,12 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA
220202
break;
221203
}
222204
stmt->persistent = persistent;
223-
stmt->error_info = &(stmt->error_info_impl);
205+
206+
if (FAIL == mysqlnd_error_info_init(&stmt->error_info_impl, persistent)) {
207+
break;
208+
}
209+
stmt->error_info = &stmt->error_info_impl;
210+
224211
mysqlnd_upsert_status_init(&stmt->upsert_status_impl);
225212
stmt->upsert_status = &(stmt->upsert_status_impl);
226213
stmt->state = MYSQLND_STMT_INITTED;
@@ -231,12 +218,6 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA
231218
}
232219

233220
stmt->prefetch_rows = MYSQLND_DEFAULT_PREFETCH_ROWS;
234-
stmt->error_info->error_list = mnd_pecalloc(1, sizeof(zend_llist), ret->persistent);
235-
if (!stmt->error_info->error_list) {
236-
break;
237-
}
238-
239-
zend_llist_init(stmt->error_info->error_list, sizeof(MYSQLND_ERROR_LIST_ELEMENT), (llist_dtor_func_t) mysqlnd_error_list_pdtor, persistent);
240221

241222
/*
242223
Mark that we reference the connection, thus it won't be
@@ -248,7 +229,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA
248229
DBG_RETURN(ret);
249230
} while (0);
250231

251-
SET_OOM_ERROR(*conn->error_info);
232+
SET_OOM_ERROR(conn->error_info);
252233
if (ret) {
253234
ret->m->dtor(ret, TRUE);
254235
ret = NULL;

ext/mysqlnd/mysqlnd_loaddata.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * filename, zen
176176
*is_warning = TRUE;
177177
/* error occurred */
178178
tmp_error_no = infile.local_infile_error(info, tmp_buf, sizeof(tmp_buf));
179-
SET_CLIENT_ERROR(*conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
179+
SET_CLIENT_ERROR(conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
180180
/* write empty packet to server */
181181
ret = net->data->m.send_ex(net, empty_packet, 0, conn->stats, conn->error_info);
182182
goto infile_error;
@@ -186,14 +186,14 @@ mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * filename, zen
186186
while ((bufsize = infile.local_infile_read (info, buf + MYSQLND_HEADER_SIZE, buflen - MYSQLND_HEADER_SIZE)) > 0) {
187187
if ((ret = net->data->m.send_ex(net, buf, bufsize, conn->stats, conn->error_info)) == 0) {
188188
DBG_ERR_FMT("Error during read : %d %s %s", CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
189-
SET_CLIENT_ERROR(*conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
189+
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
190190
goto infile_error;
191191
}
192192
}
193193

194194
/* send empty packet for eof */
195195
if ((ret = net->data->m.send_ex(net, empty_packet, 0, conn->stats, conn->error_info)) == 0) {
196-
SET_CLIENT_ERROR(*conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
196+
SET_CLIENT_ERROR(conn->error_info, CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
197197
goto infile_error;
198198
}
199199

@@ -204,7 +204,7 @@ mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * filename, zen
204204
*is_warning = TRUE;
205205
DBG_ERR_FMT("Bufsize < 0, warning, %d %s %s", CR_SERVER_LOST, UNKNOWN_SQLSTATE, lost_conn);
206206
tmp_error_no = infile.local_infile_error(info, tmp_buf, sizeof(tmp_buf));
207-
SET_CLIENT_ERROR(*conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
207+
SET_CLIENT_ERROR(conn->error_info, tmp_error_no, UNKNOWN_SQLSTATE, tmp_buf);
208208
goto infile_error;
209209
}
210210

ext/mysqlnd/mysqlnd_net.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ MYSQLND_METHOD(mysqlnd_net, open_pipe)(MYSQLND_NET * const net, const char * con
148148
streams_options |= IGNORE_URL;
149149
net_stream = php_stream_open_wrapper((char*) scheme + sizeof("pipe://") - 1, "r+", streams_options, NULL);
150150
if (!net_stream) {
151-
SET_CLIENT_ERROR(*error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "Unknown errror while connecting");
151+
SET_CLIENT_ERROR(error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "Unknown errror while connecting");
152152
DBG_RETURN(NULL);
153153
}
154154
/*
@@ -211,7 +211,7 @@ MYSQLND_METHOD(mysqlnd_net, open_tcp_or_unix)(MYSQLND_NET * const net, const cha
211211
mnd_sprintf_free(hashed_details);
212212
}
213213
errcode = CR_CONNECTION_ERROR;
214-
SET_CLIENT_ERROR(*error_info,
214+
SET_CLIENT_ERROR(error_info,
215215
CR_CONNECTION_ERROR,
216216
UNKNOWN_SQLSTATE,
217217
errstr? ZSTR_VAL(errstr):"Unknown error while connecting");
@@ -310,7 +310,7 @@ MYSQLND_METHOD(mysqlnd_net, get_open_stream)(MYSQLND_NET * const net, const char
310310
}
311311

312312
if (!ret) {
313-
SET_CLIENT_ERROR(*error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "No handler for this scheme");
313+
SET_CLIENT_ERROR(error_info, CR_CONNECTION_ERROR, UNKNOWN_SQLSTATE, "No handler for this scheme");
314314
}
315315

316316
DBG_RETURN(ret);
@@ -484,7 +484,7 @@ MYSQLND_METHOD(mysqlnd_net, send_ex)(MYSQLND_NET * const net, zend_uchar * const
484484
/* Even for zero size payload we have to send a packet */
485485
if (!bytes_sent) {
486486
DBG_ERR_FMT("Can't %u send bytes", count);
487-
SET_CLIENT_ERROR(*error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
487+
SET_CLIENT_ERROR(error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
488488
}
489489
DBG_RETURN(bytes_sent);
490490
}

0 commit comments

Comments
 (0)