diff options
Diffstat (limited to 'ext/mysqlnd')
-rw-r--r-- | ext/mysqlnd/mysqlnd.h | 2 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_auth.c | 349 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_auth.h | 65 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_charset.c | 66 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_charset.h | 12 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_commands.c | 936 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_commands.h | 2 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_connection.c | 53 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_driver.c | 22 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_enum_n_def.h | 1 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_ext_plugin.c | 9 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_ext_plugin.h | 12 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_priv.h | 1 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_ps.c | 151 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_result.c | 22 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_structs.h | 101 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_wireprotocol.c | 152 | ||||
-rw-r--r-- | ext/mysqlnd/mysqlnd_wireprotocol.h | 10 |
18 files changed, 809 insertions, 1157 deletions
diff --git a/ext/mysqlnd/mysqlnd.h b/ext/mysqlnd/mysqlnd.h index 7cc7cc96e6..021e7a1155 100644 --- a/ext/mysqlnd/mysqlnd.h +++ b/ext/mysqlnd/mysqlnd.h @@ -78,7 +78,7 @@ PHPAPI void mysqlnd_plugin_apply_with_argument(apply_func_arg_t apply_func, void PHPAPI void mysqlnd_minfo_print_hash(zval *values); #define mysqlnd_thread_safe() TRUE -PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(unsigned int charsetno); +PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(const unsigned int charsetno); PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const charsetname); diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index e56ea20380..9822b40537 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -36,7 +36,7 @@ static const char * const mysqlnd_old_passwd = "mysqlnd cannot connect to MySQL /* {{{ mysqlnd_run_authentication */ enum_func_status mysqlnd_run_authentication( - MYSQLND_CONN_DATA * conn, + MYSQLND_CONN_DATA * const conn, const char * const user, const char * const passwd, const size_t passwd_len, @@ -44,11 +44,11 @@ mysqlnd_run_authentication( const size_t db_len, const MYSQLND_STRING auth_plugin_data, const char * const auth_protocol, - unsigned int charset_no, + const unsigned int charset_no, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags, - zend_bool silent, - zend_bool is_change_user + const zend_ulong mysql_flags, + const zend_bool silent, + const zend_bool is_change_user ) { enum_func_status ret = FAIL; @@ -89,6 +89,7 @@ mysqlnd_run_authentication( } } + { zend_uchar * switch_to_auth_protocol_data = NULL; size_t switch_to_auth_protocol_data_len = 0; @@ -113,10 +114,11 @@ mysqlnd_run_authentication( DBG_INF_FMT("salt(%d)=[%.*s]", plugin_data_len, plugin_data_len, plugin_data); /* The data should be allocated with malloc() */ if (auth_plugin) { - scrambled_data = - auth_plugin->methods.get_auth_data(NULL, &scrambled_data_len, conn, user, passwd, passwd_len, - plugin_data, plugin_data_len, session_options, - conn->protocol_frame_codec->data, mysql_flags); + scrambled_data = auth_plugin->methods.get_auth_data( + NULL, &scrambled_data_len, conn, user, passwd, + passwd_len, plugin_data, plugin_data_len, + session_options, conn->protocol_frame_codec->data, + mysql_flags); } if (conn->error_info->error_no) { @@ -127,6 +129,7 @@ mysqlnd_run_authentication( charset_no, first_call, requested_protocol, + auth_plugin, plugin_data, plugin_data_len, scrambled_data, scrambled_data_len, &switch_to_auth_protocol, &switch_to_auth_protocol_len, &switch_to_auth_protocol_data, &switch_to_auth_protocol_data_len @@ -177,23 +180,23 @@ end: /* {{{ mysqlnd_switch_to_ssl_if_needed */ static enum_func_status -mysqlnd_switch_to_ssl_if_needed(MYSQLND_CONN_DATA * conn, +mysqlnd_switch_to_ssl_if_needed(MYSQLND_CONN_DATA * const conn, unsigned int charset_no, - size_t server_capabilities, + const size_t server_capabilities, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags) + const zend_ulong mysql_flags) { enum_func_status ret = FAIL; const MYSQLND_CHARSET * charset; DBG_ENTER("mysqlnd_switch_to_ssl_if_needed"); if (session_options->charset_name && (charset = mysqlnd_find_charset_name(session_options->charset_name))) { - charset_no = charset->nr; + charset_no = charset->nr; } { - size_t client_capabilities = mysql_flags; - ret = conn->run_command(COM_ENABLE_SSL, conn, client_capabilities, server_capabilities, charset_no); + const size_t client_capabilities = mysql_flags; + ret = conn->command->enable_ssl(conn, client_capabilities, server_capabilities, charset_no); } DBG_RETURN(ret); } @@ -203,18 +206,18 @@ mysqlnd_switch_to_ssl_if_needed(MYSQLND_CONN_DATA * conn, /* {{{ mysqlnd_connect_run_authentication */ enum_func_status mysqlnd_connect_run_authentication( - MYSQLND_CONN_DATA * conn, + MYSQLND_CONN_DATA * const conn, const char * const user, const char * const passwd, const char * const db, - size_t db_len, - size_t passwd_len, - MYSQLND_STRING authentication_plugin_data, + const size_t db_len, + const size_t passwd_len, + const MYSQLND_STRING authentication_plugin_data, const char * const authentication_protocol, const unsigned int charset_no, - size_t server_capabilities, + const size_t server_capabilities, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags + const zend_ulong mysql_flags ) { enum_func_status ret = FAIL; @@ -240,16 +243,19 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn, const char * const db, const size_t db_len, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags, - unsigned int server_charset_no, - zend_bool use_full_blown_auth_packet, + const zend_ulong mysql_flags, + const unsigned int server_charset_no, + const zend_bool use_full_blown_auth_packet, const char * const auth_protocol, + struct st_mysqlnd_authentication_plugin * auth_plugin, + const zend_uchar * const orig_auth_plugin_data, + const size_t orig_auth_plugin_data_len, const zend_uchar * const auth_plugin_data, const size_t auth_plugin_data_len, char ** switch_to_auth_protocol, - size_t * switch_to_auth_protocol_len, + size_t * const switch_to_auth_protocol_len, zend_uchar ** switch_to_auth_protocol_data, - size_t * switch_to_auth_protocol_data_len + size_t * const switch_to_auth_protocol_data_len ) { enum_func_status ret = FAIL; @@ -313,6 +319,11 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn, PACKET_FREE(&auth_packet); } + if (auth_plugin && auth_plugin->methods.handle_server_response) { + auth_plugin->methods.handle_server_response(auth_plugin, conn, + orig_auth_plugin_data, orig_auth_plugin_data_len, passwd, passwd_len); + } + if (FAIL == PACKET_READ(conn, &auth_resp_packet) || auth_resp_packet.response_code >= 0xFE) { if (auth_resp_packet.response_code == 0xFE) { /* old authentication with new server !*/ @@ -360,14 +371,14 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn, const char * const db, const size_t db_len, const zend_bool silent, - zend_bool use_full_blown_auth_packet, + const zend_bool use_full_blown_auth_packet, const char * const auth_protocol, - zend_uchar * auth_plugin_data, - size_t auth_plugin_data_len, + const zend_uchar * const auth_plugin_data, + const size_t auth_plugin_data_len, char ** switch_to_auth_protocol, - size_t * switch_to_auth_protocol_len, + size_t * const switch_to_auth_protocol_len, zend_uchar ** switch_to_auth_protocol_data, - size_t * switch_to_auth_protocol_data_len + size_t * const switch_to_auth_protocol_data_len ) { enum_func_status ret = FAIL; @@ -548,10 +559,10 @@ static zend_uchar * mysqlnd_native_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self, size_t * auth_data_len, MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd, - const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len, + const size_t passwd_len, zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, const MYSQLND_SESSION_OPTIONS * const session_options, const MYSQLND_PFC_DATA * const pfc_data, - zend_ulong mysql_flags + const zend_ulong mysql_flags ) { zend_uchar * ret = NULL; @@ -596,7 +607,8 @@ static struct st_mysqlnd_authentication_plugin mysqlnd_native_auth_plugin = } }, {/* methods */ - mysqlnd_native_auth_get_auth_data + mysqlnd_native_auth_get_auth_data, + NULL } }; @@ -608,10 +620,10 @@ static zend_uchar * mysqlnd_pam_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self, size_t * auth_data_len, MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd, - const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len, + const size_t passwd_len, zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, const MYSQLND_SESSION_OPTIONS * const session_options, const MYSQLND_PFC_DATA * const pfc_data, - zend_ulong mysql_flags + const zend_ulong mysql_flags ) { zend_uchar * ret = NULL; @@ -645,7 +657,8 @@ static struct st_mysqlnd_authentication_plugin mysqlnd_pam_authentication_plugin } }, {/* methods */ - mysqlnd_pam_auth_get_auth_data + mysqlnd_pam_auth_get_auth_data, + NULL } }; @@ -749,10 +762,10 @@ static zend_uchar * mysqlnd_sha256_auth_get_auth_data(struct st_mysqlnd_authentication_plugin * self, size_t * auth_data_len, MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd, - const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len, + const size_t passwd_len, zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, const MYSQLND_SESSION_OPTIONS * const session_options, const MYSQLND_PFC_DATA * const pfc_data, - zend_ulong mysql_flags + const zend_ulong mysql_flags ) { RSA * server_public_key; @@ -820,11 +833,266 @@ static struct st_mysqlnd_authentication_plugin mysqlnd_sha256_authentication_plu } }, {/* methods */ - mysqlnd_sha256_auth_get_auth_data + mysqlnd_sha256_auth_get_auth_data, + NULL } }; #endif +/*************************************** CACHING SHA2 Password *******************************/ +#ifdef MYSQLND_HAVE_SSL + +#undef L64 + +#include "ext/hash/php_hash.h" +#include "ext/hash/php_hash_sha.h" + +#define SHA256_LENGTH 32 + +/* {{{ php_mysqlnd_scramble_sha2 */ +void php_mysqlnd_scramble_sha2(zend_uchar * const buffer, const zend_uchar * const scramble, const zend_uchar * const password, const size_t password_len) +{ + PHP_SHA256_CTX context; + zend_uchar sha1[SHA256_LENGTH]; + zend_uchar sha2[SHA256_LENGTH]; + + /* Phase 1: hash password */ + PHP_SHA256Init(&context); + PHP_SHA256Update(&context, password, password_len); + PHP_SHA256Final(sha1, &context); + + /* Phase 2: hash sha1 */ + PHP_SHA256Init(&context); + PHP_SHA256Update(&context, (zend_uchar*)sha1, SHA256_LENGTH); + PHP_SHA256Final(sha2, &context); + + /* Phase 3: hash scramble + sha2 */ + PHP_SHA256Init(&context); + PHP_SHA256Update(&context, (zend_uchar*)sha2, SHA256_LENGTH); + PHP_SHA256Update(&context, scramble, SCRAMBLE_LENGTH); + PHP_SHA256Final(buffer, &context); + + /* let's crypt buffer now */ + php_mysqlnd_crypt(buffer, (const zend_uchar *)sha1, (const zend_uchar *)buffer, SHA256_LENGTH); +} +/* }}} */ + + +/* {{{ mysqlnd_native_auth_get_auth_data */ +static zend_uchar * +mysqlnd_caching_sha2_get_auth_data(struct st_mysqlnd_authentication_plugin * self, + size_t * auth_data_len, + MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd, + const size_t passwd_len, zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, + const MYSQLND_SESSION_OPTIONS * const session_options, + const MYSQLND_PFC_DATA * const pfc_data, + const zend_ulong mysql_flags + ) +{ + zend_uchar * ret = NULL; + DBG_ENTER("mysqlnd_caching_sha2_get_auth_data"); + DBG_INF_FMT("salt(%d)=[%.*s]", auth_plugin_data_len, auth_plugin_data_len, auth_plugin_data); + *auth_data_len = 0; + + DBG_INF("First auth step: send hashed password"); + /* copy scrambled pass*/ + if (passwd && passwd_len) { + ret = malloc(SHA256_LENGTH + 1); + *auth_data_len = SHA256_LENGTH; + php_mysqlnd_scramble_sha2((zend_uchar*)ret, auth_plugin_data, (zend_uchar*)passwd, passwd_len); + ret[SHA256_LENGTH] = '\0'; + DBG_INF_FMT("hash(%d)=[%.*s]", *auth_data_len, *auth_data_len, ret); + } + + DBG_RETURN(ret); +} +/* }}} */ + +static RSA * +mysqlnd_caching_sha2_get_key(MYSQLND_CONN_DATA *conn) +{ + RSA * ret = NULL; + const MYSQLND_PFC_DATA * const pfc_data = conn->protocol_frame_codec->data; + const char * fname = (pfc_data->sha256_server_public_key && pfc_data->sha256_server_public_key[0] != '\0')? + pfc_data->sha256_server_public_key: + MYSQLND_G(sha256_server_public_key); + php_stream * stream; + DBG_ENTER("mysqlnd_cached_sha2_get_key"); + DBG_INF_FMT("options_s256_pk=[%s] MYSQLND_G(sha256_server_public_key)=[%s]", + pfc_data->sha256_server_public_key? pfc_data->sha256_server_public_key:"n/a", + MYSQLND_G(sha256_server_public_key)? MYSQLND_G(sha256_server_public_key):"n/a"); + if (!fname || fname[0] == '\0') { + MYSQLND_PACKET_CACHED_SHA2_RESULT req_packet; + MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE pk_resp_packet; + + do { + DBG_INF("requesting the public key from the server"); + conn->payload_decoder_factory->m.init_cached_sha2_result_packet(&req_packet); + conn->payload_decoder_factory->m.init_sha256_pk_request_response_packet(&pk_resp_packet); + req_packet.request = 1; + + if (! PACKET_WRITE(conn, &req_packet)) { + DBG_ERR_FMT("Error while sending public key request packet"); + php_error(E_WARNING, "Error while sending public key request packet. PID=%d", getpid()); + SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT); + break; + } + if (FAIL == PACKET_READ(conn, &pk_resp_packet) || NULL == pk_resp_packet.public_key) { + DBG_ERR_FMT("Error while receiving public key"); + php_error(E_WARNING, "Error while receiving public key. PID=%d", getpid()); + SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT); + break; + } + DBG_INF_FMT("Public key(%d):\n%s", pk_resp_packet.public_key_len, pk_resp_packet.public_key); + /* now extract the public key */ + { + BIO * bio = BIO_new_mem_buf(pk_resp_packet.public_key, pk_resp_packet.public_key_len); + ret = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL); + BIO_free(bio); + } + } while (0); + PACKET_FREE(&req_packet); + PACKET_FREE(&pk_resp_packet); + + DBG_INF_FMT("ret=%p", ret); + DBG_RETURN(ret); + + SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, + "caching_sha2_server_public_key is not set for the connection or as mysqlnd.sha256_server_public_key"); + DBG_ERR("server_public_key is not set"); + DBG_RETURN(NULL); + } else { + zend_string * key_str; + DBG_INF_FMT("Key in a file. [%s]", fname); + stream = php_stream_open_wrapper((char *) fname, "rb", REPORT_ERRORS, NULL); + + if (stream) { + if ((key_str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0)) != NULL) { + BIO * bio = BIO_new_mem_buf(ZSTR_VAL(key_str), ZSTR_LEN(key_str)); + ret = PEM_read_bio_RSA_PUBKEY(bio, NULL, NULL, NULL); + BIO_free(bio); + DBG_INF("Successfully loaded"); + DBG_INF_FMT("Public key:%*.s", ZSTR_LEN(key_str), ZSTR_VAL(key_str)); + zend_string_release(key_str); + } + php_stream_close(stream); + } + } + DBG_RETURN(ret); + +} + + +/* {{{ mysqlnd_caching_sha2_get_key */ +static size_t +mysqlnd_caching_sha2_get_and_use_key(MYSQLND_CONN_DATA *conn, + const zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, + unsigned char **crypted, + const char * const passwd, + const size_t passwd_len) +{ + static RSA *server_public_key; + server_public_key = mysqlnd_caching_sha2_get_key(conn); + + DBG_ENTER("mysqlnd_caching_sha2_get_and_use_key("); + + if (server_public_key) { + int server_public_key_len; + char xor_str[passwd_len + 1]; + memcpy(xor_str, passwd, passwd_len); + xor_str[passwd_len] = '\0'; + mysqlnd_xor_string(xor_str, passwd_len, (char *) auth_plugin_data, auth_plugin_data_len); + + server_public_key_len = RSA_size(server_public_key); + /* + Because RSA_PKCS1_OAEP_PADDING is used there is a restriction on the passwd_len. + RSA_PKCS1_OAEP_PADDING is recommended for new applications. See more here: + http://www.openssl.org/docs/crypto/RSA_public_encrypt.html + */ + if ((size_t) server_public_key_len - 41 <= passwd_len) { + /* password message is to long */ + SET_CLIENT_ERROR(conn->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "password is too long"); + DBG_ERR("password is too long"); + DBG_RETURN(0); + } + + *crypted = emalloc(server_public_key_len); + RSA_public_encrypt(passwd_len + 1, (zend_uchar *) xor_str, *crypted, server_public_key, RSA_PKCS1_OAEP_PADDING); + DBG_RETURN(server_public_key_len); + } + DBG_RETURN(0); +} +/* }}} */ + +/* {{{ mysqlnd_native_auth_get_auth_data */ +static void +mysqlnd_caching_sha2_handle_server_response(struct st_mysqlnd_authentication_plugin *self, + MYSQLND_CONN_DATA * conn, + const zend_uchar * auth_plugin_data, const size_t auth_plugin_data_len, + const char * const passwd, + const size_t passwd_len) +{ + DBG_ENTER("mysqlnd_caching_sha2_handle_server_response"); + MYSQLND_PACKET_CACHED_SHA2_RESULT result_packet; + conn->payload_decoder_factory->m.init_cached_sha2_result_packet(&result_packet); + + if (FAIL == PACKET_READ(conn, &result_packet)) { + DBG_VOID_RETURN; + } + + switch (result_packet.response_code) { + case 3: + DBG_INF("fast path succeeded"); + DBG_VOID_RETURN; + case 4: + if (conn->vio->data->ssl || conn->unix_socket.s) { + DBG_INF("fast path failed, doing full auth via SSL"); + result_packet.password = (zend_uchar *)passwd; + result_packet.password_len = passwd_len + 1; + PACKET_WRITE(conn, &result_packet); + } else { + DBG_INF("fast path failed, doing full auth without SSL"); + result_packet.password_len = mysqlnd_caching_sha2_get_and_use_key(conn, auth_plugin_data, auth_plugin_data_len, &result_packet.password, passwd, passwd_len); + PACKET_WRITE(conn, &result_packet); + efree(result_packet.password); + } + DBG_VOID_RETURN; + case 2: + // The server tried to send a key, which we didn't expect + // fall-through + default: + php_error_docref(NULL, E_WARNING, "Unexpected server respose while doing caching_sha2 auth: %i", result_packet.response_code); + } + + DBG_VOID_RETURN; +} +/* }}} */ + +static struct st_mysqlnd_authentication_plugin mysqlnd_caching_sha2_auth_plugin = +{ + { + MYSQLND_PLUGIN_API_VERSION, + "auth_plugin_caching_sha2_password", + MYSQLND_VERSION_ID, + PHP_MYSQLND_VERSION, + "PHP License 3.01", + "Johannes Schlüter <johannes.schlueter@php.net>", + { + NULL, /* no statistics , will be filled later if there are some */ + NULL, /* no statistics */ + }, + { + NULL /* plugin shutdown */ + } + }, + {/* methods */ + mysqlnd_caching_sha2_get_auth_data, + mysqlnd_caching_sha2_handle_server_response + } +}; +#endif + + /* {{{ mysqlnd_register_builtin_authentication_plugins */ void mysqlnd_register_builtin_authentication_plugins(void) @@ -832,6 +1100,7 @@ mysqlnd_register_builtin_authentication_plugins(void) mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_native_auth_plugin); mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_pam_authentication_plugin); #ifdef MYSQLND_HAVE_SSL + mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_caching_sha2_auth_plugin); mysqlnd_plugin_register_ex((struct st_mysqlnd_plugin_header *) &mysqlnd_sha256_authentication_plugin); #endif } diff --git a/ext/mysqlnd/mysqlnd_auth.h b/ext/mysqlnd/mysqlnd_auth.h index 8fc369abca..6c115d9e05 100644 --- a/ext/mysqlnd/mysqlnd_auth.h +++ b/ext/mysqlnd/mysqlnd_auth.h @@ -27,36 +27,19 @@ mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn, const char * const db, const size_t db_len, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags, - unsigned int server_charset_no, - zend_bool use_full_blown_auth_packet, + const zend_ulong mysql_flags, + const unsigned int server_charset_no, + const zend_bool use_full_blown_auth_packet, const char * const auth_protocol, + struct st_mysqlnd_authentication_plugin * auth_plugin, + const zend_uchar * const orig_auth_plugin_data, + const size_t orig_auth_plugin_data_len, const zend_uchar * const auth_plugin_data, const size_t auth_plugin_data_len, char ** switch_to_auth_protocol, - size_t * switch_to_auth_protocol_len, + size_t * const switch_to_auth_protocol_len, zend_uchar ** switch_to_auth_protocol_data, - size_t * switch_to_auth_protocol_data_len - ); - -enum_func_status -mysqlnd_auth_handshake(MYSQLND_CONN_DATA * conn, - const char * const user, - const char * const passwd, - const size_t passwd_len, - const char * const db, - const size_t db_len, - const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags, - unsigned int server_charset_no, - zend_bool use_full_blown_auth_packet, - const char * const auth_protocol, - const zend_uchar * const auth_plugin_data, - const size_t auth_plugin_data_len, - char ** switch_to_auth_protocol, - size_t * switch_to_auth_protocol_len, - zend_uchar ** switch_to_auth_protocol_data, - size_t * switch_to_auth_protocol_data_len + size_t * const switch_to_auth_protocol_data_len ); enum_func_status @@ -68,36 +51,36 @@ mysqlnd_auth_change_user(MYSQLND_CONN_DATA * const conn, const char * const db, const size_t db_len, const zend_bool silent, - zend_bool use_full_blown_auth_packet, + const zend_bool use_full_blown_auth_packet, const char * const auth_protocol, - zend_uchar * auth_plugin_data, - size_t auth_plugin_data_len, + const zend_uchar * auth_plugin_data, + const size_t auth_plugin_data_len, char ** switch_to_auth_protocol, - size_t * switch_to_auth_protocol_len, + size_t * const switch_to_auth_protocol_len, zend_uchar ** switch_to_auth_protocol_data, - size_t * switch_to_auth_protocol_data_len + size_t * const switch_to_auth_protocol_data_len ); enum_func_status mysqlnd_connect_run_authentication( - MYSQLND_CONN_DATA * conn, + MYSQLND_CONN_DATA * const conn, const char * const user, const char * const passwd, const char * const db, - size_t db_len, - size_t passwd_len, - MYSQLND_STRING authentication_plugin_data, + const size_t db_len, + const size_t passwd_len, + const MYSQLND_STRING authentication_plugin_data, const char * const authentication_protocol, const unsigned int charset_no, - size_t server_capabilities, + const size_t server_capabilities, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags + const zend_ulong mysql_flags ); enum_func_status mysqlnd_run_authentication( - MYSQLND_CONN_DATA * conn, + MYSQLND_CONN_DATA * const conn, const char * const user, const char * const passwd, const size_t passwd_len, @@ -105,11 +88,11 @@ mysqlnd_run_authentication( const size_t db_len, const MYSQLND_STRING auth_plugin_data, const char * const auth_protocol, - unsigned int charset_no, + const unsigned int charset_no, const MYSQLND_SESSION_OPTIONS * const session_options, - zend_ulong mysql_flags, - zend_bool silent, - zend_bool is_change_user + const zend_ulong mysql_flags, + const zend_bool silent, + const zend_bool is_change_user ); PHPAPI void php_mysqlnd_scramble(zend_uchar * const buffer, const zend_uchar * const scramble, const zend_uchar * const pass, const size_t pass_len); diff --git a/ext/mysqlnd/mysqlnd_charset.c b/ext/mysqlnd/mysqlnd_charset.c index 04dcd82295..ce9708ce4c 100644 --- a/ext/mysqlnd/mysqlnd_charset.c +++ b/ext/mysqlnd/mysqlnd_charset.c @@ -25,7 +25,7 @@ #include "mysqlnd_charset.h" /* {{{ utf8 functions */ -static unsigned int check_mb_utf8mb3_sequence(const char *start, const char *end) +static unsigned int check_mb_utf8mb3_sequence(const char * const start, const char * const end) { zend_uchar c; @@ -64,7 +64,7 @@ static unsigned int check_mb_utf8mb3_sequence(const char *start, const char *end } -static unsigned int check_mb_utf8_sequence(const char *start, const char *end) +static unsigned int check_mb_utf8_sequence(const char * const start, const char * const end) { zend_uchar c; @@ -136,20 +136,20 @@ static unsigned int check_mb_utf8_sequence(const char *start, const char *end) return 0; } -static unsigned int check_mb_utf8mb3_valid(const char *start, const char *end) +static unsigned int check_mb_utf8mb3_valid(const char * const start, const char * const end) { unsigned int len = check_mb_utf8mb3_sequence(start, end); return (len > 1)? len:0; } -static unsigned int check_mb_utf8_valid(const char *start, const char *end) +static unsigned int check_mb_utf8_valid(const char * const start, const char * const end) { unsigned int len = check_mb_utf8_sequence(start, end); return (len > 1)? len:0; } -static unsigned int mysqlnd_mbcharlen_utf8mb3(unsigned int utf8) +static unsigned int mysqlnd_mbcharlen_utf8mb3(const unsigned int utf8) { if (utf8 < 0x80) { return 1; /* single byte character */ @@ -167,7 +167,7 @@ static unsigned int mysqlnd_mbcharlen_utf8mb3(unsigned int utf8) } -static unsigned int mysqlnd_mbcharlen_utf8(unsigned int utf8) +static unsigned int mysqlnd_mbcharlen_utf8(const unsigned int utf8) { if (utf8 < 0x80) { return 1; /* single byte character */ @@ -196,13 +196,13 @@ static unsigned int mysqlnd_mbcharlen_utf8(unsigned int utf8) #define isbig5code(c,d) (isbig5head(c) && isbig5tail(d)) -static unsigned int check_mb_big5(const char *start, const char *end) +static unsigned int check_mb_big5(const char * const start, const char * const end) { return (valid_big5head(*(start)) && (end - start) > 1 && valid_big5tail(*(start + 1)) ? 2 : 0); } -static unsigned int mysqlnd_mbcharlen_big5(unsigned int big5) +static unsigned int mysqlnd_mbcharlen_big5(const unsigned int big5) { return (valid_big5head(big5)) ? 2 : 1; } @@ -214,14 +214,14 @@ static unsigned int mysqlnd_mbcharlen_big5(unsigned int big5) #define valid_cp932tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && c <= 0xFC)) -static unsigned int check_mb_cp932(const char *start, const char *end) +static unsigned int check_mb_cp932(const char * const start, const char * const end) { return (valid_cp932head((zend_uchar)start[0]) && (end - start > 1) && valid_cp932tail((zend_uchar)start[1])) ? 2 : 0; } -static unsigned int mysqlnd_mbcharlen_cp932(unsigned int cp932) +static unsigned int mysqlnd_mbcharlen_cp932(const unsigned int cp932) { return (valid_cp932head((zend_uchar)cp932)) ? 2 : 1; } @@ -231,7 +231,7 @@ static unsigned int mysqlnd_mbcharlen_cp932(unsigned int cp932) /* {{{ euckr functions */ #define valid_euckr(c) ((0xA1 <= (zend_uchar)(c) && (zend_uchar)(c) <= 0xFE)) -static unsigned int check_mb_euckr(const char *start, const char *end) +static unsigned int check_mb_euckr(const char * const start, const char * const end) { if (end - start <= 1) { return 0; /* invalid length */ @@ -246,7 +246,7 @@ static unsigned int check_mb_euckr(const char *start, const char *end) } -static unsigned int mysqlnd_mbcharlen_euckr(unsigned int kr) +static unsigned int mysqlnd_mbcharlen_euckr(const unsigned int kr) { return (valid_euckr(kr)) ? 2 : 1; } @@ -259,7 +259,7 @@ static unsigned int mysqlnd_mbcharlen_euckr(unsigned int kr) #define valid_eucjpms_ss2(c) (((c) & 0xFF) == 0x8E) #define valid_eucjpms_ss3(c) (((c) & 0xFF) == 0x8F) -static unsigned int check_mb_eucjpms(const char *start, const char *end) +static unsigned int check_mb_eucjpms(const char * const start, const char * const end) { if (*((zend_uchar *)start) < 0x80) { return 0; /* invalid eucjpms character */ @@ -278,7 +278,7 @@ static unsigned int check_mb_eucjpms(const char *start, const char *end) } -static unsigned int mysqlnd_mbcharlen_eucjpms(unsigned int jpms) +static unsigned int mysqlnd_mbcharlen_eucjpms(const unsigned int jpms) { if (valid_eucjpms(jpms) || valid_eucjpms_ss2(jpms)) { return 2; @@ -296,14 +296,14 @@ static unsigned int mysqlnd_mbcharlen_eucjpms(unsigned int jpms) #define valid_gb2312_tail(c) (0xA1 <= (zend_uchar)(c) && (zend_uchar)(c) <= 0xFE) -static unsigned int check_mb_gb2312(const char *start, const char *end) +static unsigned int check_mb_gb2312(const char * const start, const char * const end) { return (valid_gb2312_head((unsigned int)start[0]) && end - start > 1 && valid_gb2312_tail((unsigned int)start[1])) ? 2 : 0; } -static unsigned int mysqlnd_mbcharlen_gb2312(unsigned int gb) +static unsigned int mysqlnd_mbcharlen_gb2312(const unsigned int gb) { return (valid_gb2312_head(gb)) ? 2 : 1; } @@ -314,12 +314,12 @@ static unsigned int mysqlnd_mbcharlen_gb2312(unsigned int gb) #define valid_gbk_head(c) (0x81<=(zend_uchar)(c) && (zend_uchar)(c)<=0xFE) #define valid_gbk_tail(c) ((0x40<=(zend_uchar)(c) && (zend_uchar)(c)<=0x7E) || (0x80<=(zend_uchar)(c) && (zend_uchar)(c)<=0xFE)) -static unsigned int check_mb_gbk(const char *start, const char *end) +static unsigned int check_mb_gbk(const char * const start, const char * const end) { return (valid_gbk_head(start[0]) && (end) - (start) > 1 && valid_gbk_tail(start[1])) ? 2 : 0; } -static unsigned int mysqlnd_mbcharlen_gbk(unsigned int gbk) +static unsigned int mysqlnd_mbcharlen_gbk(const unsigned int gbk) { return (valid_gbk_head(gbk) ? 2 : 1); } @@ -331,13 +331,13 @@ static unsigned int mysqlnd_mbcharlen_gbk(unsigned int gbk) #define valid_sjis_tail(c) ((0x40 <= (c) && (c) <= 0x7E) || (0x80 <= (c) && (c) <= 0xFC)) -static unsigned int check_mb_sjis(const char *start, const char *end) +static unsigned int check_mb_sjis(const char * const start, const char * const end) { return (valid_sjis_head((zend_uchar)start[0]) && (end - start) > 1 && valid_sjis_tail((zend_uchar)start[1])) ? 2 : 0; } -static unsigned int mysqlnd_mbcharlen_sjis(unsigned int sjis) +static unsigned int mysqlnd_mbcharlen_sjis(const unsigned int sjis) { return (valid_sjis_head((zend_uchar)sjis)) ? 2 : 1; } @@ -345,12 +345,12 @@ static unsigned int mysqlnd_mbcharlen_sjis(unsigned int sjis) /* {{{ ucs2 functions */ -static unsigned int check_mb_ucs2(const char *start __attribute((unused)), const char *end __attribute((unused))) +static unsigned int check_mb_ucs2(const char * const start __attribute((unused)), const char * const end __attribute((unused))) { return 2; /* always 2 */ } -static unsigned int mysqlnd_mbcharlen_ucs2(unsigned int ucs2 __attribute((unused))) +static unsigned int mysqlnd_mbcharlen_ucs2(const unsigned int ucs2 __attribute((unused))) { return 2; /* always 2 */ } @@ -363,7 +363,7 @@ static unsigned int mysqlnd_mbcharlen_ucs2(unsigned int ucs2 __attribute((unused #define valid_ujis_ss2(c) (((c)&0xFF) == 0x8E) #define valid_ujis_ss3(c) (((c)&0xFF) == 0x8F) -static unsigned int check_mb_ujis(const char *start, const char *end) +static unsigned int check_mb_ujis(const char * const start, const char * const end) { if (*(zend_uchar*)start < 0x80) { return 0; /* invalid ujis character */ @@ -381,7 +381,7 @@ static unsigned int check_mb_ujis(const char *start, const char *end) } -static unsigned int mysqlnd_mbcharlen_ujis(unsigned int ujis) +static unsigned int mysqlnd_mbcharlen_ujis(const unsigned int ujis) { return (valid_ujis(ujis)? 2: valid_ujis_ss2(ujis)? 2: valid_ujis_ss3(ujis)? 3: 1); } @@ -393,7 +393,7 @@ static unsigned int mysqlnd_mbcharlen_ujis(unsigned int ujis) #define UTF16_HIGH_HEAD(x) ((((zend_uchar) (x)) & 0xFC) == 0xD8) #define UTF16_LOW_HEAD(x) ((((zend_uchar) (x)) & 0xFC) == 0xDC) -static unsigned int check_mb_utf16(const char *start, const char *end) +static unsigned int check_mb_utf16(const char * const start, const char * const end) { if (start + 2 > end) { return 0; @@ -410,7 +410,7 @@ static unsigned int check_mb_utf16(const char *start, const char *end) } -static uint32_t mysqlnd_mbcharlen_utf16(unsigned int utf16) +static uint32_t mysqlnd_mbcharlen_utf16(const unsigned int utf16) { return UTF16_HIGH_HEAD(utf16) ? 4 : 2; } @@ -418,13 +418,13 @@ static uint32_t mysqlnd_mbcharlen_utf16(unsigned int utf16) /* {{{ utf32 functions */ -static unsigned int check_mb_utf32(const char *start __attribute((unused)), const char *end __attribute((unused))) +static unsigned int check_mb_utf32(const char * const start __attribute((unused)), const char * const end __attribute((unused))) { return 4; } -static unsigned int mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) +static unsigned int mysqlnd_mbcharlen_utf32(const unsigned int utf32 __attribute((unused))) { return 4; } @@ -437,7 +437,7 @@ static unsigned int mysqlnd_mbcharlen_utf32(unsigned int utf32 __attribute((unus #define is_gb18030_even_4(c) (0x30 <= (zend_uchar) (c) && (zend_uchar) (c) <= 0x39) -static unsigned int mysqlnd_mbcharlen_gb18030(unsigned int c) +static unsigned int mysqlnd_mbcharlen_gb18030(const unsigned int c) { if (c <= 0xFF) { return !is_gb18030_odd(c); @@ -740,7 +740,7 @@ const MYSQLND_CHARSET mysqlnd_charsets[] = /* {{{ mysqlnd_find_charset_nr */ -PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(unsigned int charsetnr) +PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_nr(const unsigned int charsetnr) { const MYSQLND_CHARSET * c = mysqlnd_charsets; @@ -773,8 +773,8 @@ PHPAPI const MYSQLND_CHARSET * mysqlnd_find_charset_name(const char * const name /* {{{ mysqlnd_cset_escape_quotes */ -PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char *newstr, - const char * escapestr, size_t escapestr_len) +PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, char * newstr, + const char * escapestr, const size_t escapestr_len) { const char *newstr_s = newstr; const char *newstr_e = newstr + 2 * escapestr_len; @@ -828,7 +828,7 @@ PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const cset, /* {{{ mysqlnd_cset_escape_slashes */ PHPAPI zend_ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char *newstr, - const char * escapestr, size_t escapestr_len) + const char * escapestr, const size_t escapestr_len) { const char *newstr_s = newstr; const char *newstr_e = newstr + 2 * escapestr_len; diff --git a/ext/mysqlnd/mysqlnd_charset.h b/ext/mysqlnd/mysqlnd_charset.h index 9a6e07a066..96dc95df9d 100644 --- a/ext/mysqlnd/mysqlnd_charset.h +++ b/ext/mysqlnd/mysqlnd_charset.h @@ -21,11 +21,11 @@ #ifndef MYSQLND_CHARSET_H #define MYSQLND_CHARSET_H -PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char *newstr, - const char *escapestr, size_t escapestr_len); +PHPAPI zend_ulong mysqlnd_cset_escape_quotes(const MYSQLND_CHARSET * const charset, char * newstr, + const char * escapestr, const size_t escapestr_len); -PHPAPI zend_ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char *newstr, - const char *escapestr, size_t escapestr_len); +PHPAPI zend_ulong mysqlnd_cset_escape_slashes(const MYSQLND_CHARSET * const cset, char * newstr, + const char * escapestr, const size_t escapestr_len); struct st_mysqlnd_plugin_charsets { @@ -34,8 +34,8 @@ struct st_mysqlnd_plugin_charsets { const MYSQLND_CHARSET * (*const find_charset_by_nr)(unsigned int charsetnr); const MYSQLND_CHARSET * (*const find_charset_by_name)(const char * const name); - zend_ulong (*const escape_quotes)(const MYSQLND_CHARSET * const cset, char * newstr, const char * escapestr, size_t escapestr_len); - zend_ulong (*const escape_slashes)(const MYSQLND_CHARSET * const cset, char * newstr, const char * escapestr, size_t escapestr_len); + zend_ulong (*const escape_quotes)(const MYSQLND_CHARSET * const cset, char * newstr, const char * escapestr, const size_t escapestr_len); + zend_ulong (*const escape_slashes)(const MYSQLND_CHARSET * const cset, char * newstr, const char * escapestr, const size_t escapestr_len); } methods; }; diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c index 21b95a8f57..c292810b4f 100644 --- a/ext/mysqlnd/mysqlnd_commands.c +++ b/ext/mysqlnd/mysqlnd_commands.c @@ -23,43 +23,19 @@ #include "mysqlnd_priv.h" #include "mysqlnd_auth.h" #include "mysqlnd_wireprotocol.h" -#include "mysqlnd_statistics.h" #include "mysqlnd_debug.h" -struct st_mysqlnd_protocol_no_params_command -{ - struct st_mysqlnd_protocol_no_params_command_context - { - MYSQLND_CONN_DATA * conn; - } context; -}; - - -/************************** COM_SET_OPTION ******************************************/ -struct st_mysqlnd_protocol_com_set_option_command -{ - struct st_mysqlnd_com_set_option_context - { - MYSQLND_CONN_DATA * conn; - enum_mysqlnd_server_option option; - } context; -}; - - -/* {{{ mysqlnd_com_set_option_run */ +/* {{{ mysqlnd_command::set_option */ static enum_func_status -mysqlnd_com_set_option_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, set_option)(MYSQLND_CONN_DATA * const conn, const enum_mysqlnd_server_option option) { - struct st_mysqlnd_protocol_com_set_option_command * command = (struct st_mysqlnd_protocol_com_set_option_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; zend_uchar buffer[2]; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - enum_mysqlnd_server_option option = command->context.option; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_set_option_run"); + DBG_ENTER("mysqlnd_command::set_option"); int2store(buffer, (unsigned int) option); ret = send_command(conn->payload_decoder_factory, COM_SET_OPTION, buffer, sizeof(buffer), FALSE, @@ -78,36 +54,15 @@ mysqlnd_com_set_option_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_set_option_run_command */ -static enum_func_status -mysqlnd_com_set_option_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_set_option_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_set_option_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.option = va_arg(args, enum_mysqlnd_server_option); - - ret = mysqlnd_com_set_option_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_DEBUG ******************************************/ -/* {{{ mysqlnd_com_debug_run */ +/* {{{ mysqlnd_command::debug */ static enum_func_status -mysqlnd_com_debug_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, debug)(MYSQLND_CONN_DATA * const conn) { - struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_debug_run"); + DBG_ENTER("mysqlnd_command::debug"); ret = send_command(conn->payload_decoder_factory, COM_DEBUG, NULL, 0, FALSE, &conn->state, @@ -126,48 +81,17 @@ mysqlnd_com_debug_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_debug_run_command */ +/* {{{ mysqlnd_command::init_db */ static enum_func_status -mysqlnd_com_debug_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, init_db)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING db) { - struct st_mysqlnd_protocol_no_params_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_debug_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - - ret = mysqlnd_com_debug_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_INIT_DB ******************************************/ -struct st_mysqlnd_protocol_com_init_db_command -{ - struct st_mysqlnd_com_init_db_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING db; - } context; -}; - - -/* {{{ mysqlnd_com_init_db_run */ -static enum_func_status -mysqlnd_com_init_db_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_init_db_command * command = (struct st_mysqlnd_protocol_com_init_db_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - const MYSQLND_CSTRING db = command->context.db; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_init_db_run"); + DBG_ENTER("mysqlnd_command::init_db"); - ret = send_command(conn->payload_decoder_factory, COM_INIT_DB, (zend_uchar*) command->context.db.s, command->context.db.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_INIT_DB, (const zend_uchar*) db.s, db.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, @@ -202,36 +126,15 @@ mysqlnd_com_init_db_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_init_db_run_command */ +/* {{{ mysqlnd_command::ping */ static enum_func_status -mysqlnd_com_init_db_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, ping)(MYSQLND_CONN_DATA * const conn) { - struct st_mysqlnd_protocol_com_init_db_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_init_db_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.db = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_init_db_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_PING ******************************************/ -/* {{{ mysqlnd_com_ping_run */ -static enum_func_status -mysqlnd_com_ping_run(void *cmd) -{ - struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_ping_run"); + DBG_ENTER("mysqlnd_command::ping"); ret = send_command(conn->payload_decoder_factory, COM_PING, NULL, 0, TRUE, &conn->state, @@ -255,45 +158,14 @@ mysqlnd_com_ping_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_ping_run_command */ -static enum_func_status -mysqlnd_com_ping_run_command(va_list args) -{ - struct st_mysqlnd_protocol_no_params_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_ping_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - - ret = mysqlnd_com_ping_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STATISTICS ******************************************/ -struct st_mysqlnd_protocol_com_statistics_command -{ - struct st_mysqlnd_com_statistics_context - { - MYSQLND_CONN_DATA * conn; - zend_string ** message; - } context; -}; - - -/* {{{ mysqlnd_com_statistics_run */ +/* {{{ mysqlnd_command::statistics */ static enum_func_status -mysqlnd_com_statistics_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, statistics)(MYSQLND_CONN_DATA * const conn, zend_string ** message) { - struct st_mysqlnd_protocol_com_statistics_command * command = (struct st_mysqlnd_protocol_com_statistics_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - zend_string **message = command->context.message; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - DBG_ENTER("mysqlnd_com_statistics_run"); + DBG_ENTER("mysqlnd_command::statistics"); ret = send_command(conn->payload_decoder_factory, COM_STATISTICS, NULL, 0, FALSE, &conn->state, @@ -320,49 +192,17 @@ mysqlnd_com_statistics_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_statistics_run_command */ +/* {{{ mysqlnd_command::process_kill */ static enum_func_status -mysqlnd_com_statistics_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, process_kill)(MYSQLND_CONN_DATA * const conn, const unsigned int process_id, const zend_bool read_response) { - struct st_mysqlnd_protocol_com_statistics_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_statistics_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.message = va_arg(args, zend_string **); - - ret = mysqlnd_com_statistics_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - -/************************** COM_PROCESS_KILL ******************************************/ -struct st_mysqlnd_protocol_com_process_kill_command -{ - struct st_mysqlnd_com_process_kill_context - { - MYSQLND_CONN_DATA * conn; - unsigned int process_id; - zend_bool read_response; - } context; -}; - - -/* {{{ mysqlnd_com_process_kill_run */ -enum_func_status -mysqlnd_com_process_kill_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_process_kill_command * command = (struct st_mysqlnd_protocol_com_process_kill_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; zend_uchar buff[4]; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - zend_bool read_response = command->context.read_response; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_process_kill_run"); - int4store(buff, command->context.process_id); + DBG_ENTER("mysqlnd_command::process_kill"); + int4store(buff, process_id); ret = send_command(conn->payload_decoder_factory, COM_PROCESS_KILL, buff, 4, FALSE, &conn->state, @@ -392,48 +232,17 @@ mysqlnd_com_process_kill_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_process_kill_run_command */ +/* {{{ mysqlnd_command::refresh */ static enum_func_status -mysqlnd_com_process_kill_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, refresh)(MYSQLND_CONN_DATA * const conn, const uint8_t options) { - struct st_mysqlnd_protocol_com_process_kill_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_process_kill_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.process_id = va_arg(args, unsigned int); - command.context.read_response = va_arg(args, unsigned int)? TRUE:FALSE; - - ret = mysqlnd_com_process_kill_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - -/************************** COM_REFRESH ******************************************/ -struct st_mysqlnd_protocol_com_refresh_command -{ - struct st_mysqlnd_com_refresh_context - { - MYSQLND_CONN_DATA * conn; - uint8_t options; - } context; -}; - - -/* {{{ mysqlnd_com_refresh_run */ -enum_func_status -mysqlnd_com_refresh_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_refresh_command * command = (struct st_mysqlnd_protocol_com_refresh_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; zend_uchar bits[1]; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_refresh_run"); - int1store(bits, command->context.options); + DBG_ENTER("mysqlnd_command::refresh"); + int1store(bits, options); ret = send_command(conn->payload_decoder_factory, COM_REFRESH, bits, 1, FALSE, &conn->state, @@ -452,48 +261,17 @@ mysqlnd_com_refresh_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_refresh_run_command */ +/* {{{ mysqlnd_command::shutdown */ static enum_func_status -mysqlnd_com_refresh_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_refresh_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_refresh_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.options = va_arg(args, unsigned int); - - ret = mysqlnd_com_refresh_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_SHUTDOWN ******************************************/ -struct st_mysqlnd_protocol_com_shutdown_command +MYSQLND_METHOD(mysqlnd_command, shutdown)(MYSQLND_CONN_DATA * const conn, const uint8_t level) { - struct st_mysqlnd_com_shutdown_context - { - MYSQLND_CONN_DATA * conn; - uint8_t level; - } context; -}; - - -/* {{{ mysqlnd_com_shutdown_run */ -enum_func_status -mysqlnd_com_shutdown_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_shutdown_command * command = (struct st_mysqlnd_protocol_com_shutdown_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; zend_uchar bits[1]; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_shutdown_run"); - int1store(bits, command->context.level); + DBG_ENTER("mysqlnd_command::shutdown"); + int1store(bits, level); ret = send_command(conn->payload_decoder_factory, COM_SHUTDOWN, bits, 1, FALSE, &conn->state, @@ -512,44 +290,14 @@ mysqlnd_com_shutdown_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_shutdown_run_command */ +/* {{{ mysqlnd_command::quit */ static enum_func_status -mysqlnd_com_shutdown_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, quit)(MYSQLND_CONN_DATA * const conn) { - struct st_mysqlnd_protocol_com_shutdown_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_shutdown_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.level = va_arg(args, unsigned int); - - ret = mysqlnd_com_shutdown_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_QUIT ******************************************/ -struct st_mysqlnd_protocol_com_quit_command -{ - struct st_mysqlnd_com_quit_context - { - MYSQLND_CONN_DATA * conn; - } context; -}; - - -/* {{{ mysqlnd_com_quit_run */ -enum_func_status -mysqlnd_com_quit_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_quit_command * command = (struct st_mysqlnd_protocol_com_quit_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - DBG_ENTER("mysqlnd_com_quit_run"); + DBG_ENTER("mysqlnd_command::quit"); ret = send_command(conn->payload_decoder_factory, COM_QUIT, NULL, 0, TRUE, &conn->state, @@ -564,45 +312,16 @@ mysqlnd_com_quit_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_quit_run_command */ +/* {{{ mysqlnd_command::query */ static enum_func_status -mysqlnd_com_quit_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, query)(MYSQLND_CONN_DATA * const conn, MYSQLND_CSTRING query) { - struct st_mysqlnd_protocol_com_quit_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_quit_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - - ret = mysqlnd_com_quit_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - -/************************** COM_QUERY ******************************************/ -struct st_mysqlnd_protocol_com_query_command -{ - struct st_mysqlnd_com_query_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING query; - } context; -}; - - -/* {{{ mysqlnd_com_query_run */ -static enum_func_status -mysqlnd_com_query_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_query_command * command = (struct st_mysqlnd_protocol_com_query_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_query_run"); + DBG_ENTER("mysqlnd_command::query"); - ret = send_command(conn->payload_decoder_factory, COM_QUERY, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_QUERY, (const zend_uchar*) query.s, query.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, @@ -619,47 +338,16 @@ mysqlnd_com_query_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_query_run_command */ -static enum_func_status -mysqlnd_com_query_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_query_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_query_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.query = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_query_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - -/************************** COM_CHANGE_USER ******************************************/ -struct st_mysqlnd_protocol_com_change_user_command -{ - struct st_mysqlnd_com_change_user_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING payload; - zend_bool silent; - } context; -}; - - -/* {{{ mysqlnd_com_change_user_run */ +/* {{{ mysqlnd_command::change_user */ static enum_func_status -mysqlnd_com_change_user_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, change_user)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload, const zend_bool silent) { - struct st_mysqlnd_protocol_com_change_user_command * command = (struct st_mysqlnd_protocol_com_change_user_command *) cmd; + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - DBG_ENTER("mysqlnd_com_change_user_run"); + DBG_ENTER("mysqlnd_command::change_user"); - ret = send_command(conn->payload_decoder_factory, COM_CHANGE_USER, (zend_uchar*) command->context.payload.s, command->context.payload.l, command->context.silent, + ret = send_command(conn->payload_decoder_factory, COM_CHANGE_USER, (const zend_uchar*) payload.s, payload.l, silent, &conn->state, conn->error_info, conn->upsert_status, @@ -672,45 +360,14 @@ mysqlnd_com_change_user_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_change_user_run_command */ +/* {{{ mysqlnd_command::reap_result */ static enum_func_status -mysqlnd_com_change_user_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_change_user_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_change_user_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.payload = va_arg(args, MYSQLND_CSTRING); - command.context.silent = va_arg(args, unsigned int); - - ret = mysqlnd_com_change_user_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_REAP_RESULT ******************************************/ -struct st_mysqlnd_protocol_com_reap_result_command +MYSQLND_METHOD(mysqlnd_command, reap_result)(MYSQLND_CONN_DATA * const conn) { - struct st_mysqlnd_com_reap_result_context - { - MYSQLND_CONN_DATA * conn; - } context; -}; - - -/* {{{ mysqlnd_com_reap_result_run */ -static enum_func_status -mysqlnd_com_reap_result_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_reap_result_command * command = (struct st_mysqlnd_protocol_com_reap_result_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; const enum_mysqlnd_connection_state state = GET_CONNECTION_STATE(&conn->state); + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_reap_result_run"); + DBG_ENTER("mysqlnd_command::reap_result"); if (state <= CONN_READY || state == CONN_QUIT_SENT) { php_error_docref(NULL, E_WARNING, "Connection not opened, clear or has been closed"); DBG_ERR_FMT("Connection not opened, clear or has been closed. State=%u", state); @@ -723,46 +380,16 @@ mysqlnd_com_reap_result_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_reap_result_run_command */ -static enum_func_status -mysqlnd_com_reap_result_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_reap_result_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_reap_result_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - - ret = mysqlnd_com_reap_result_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STMT_PREPARE ******************************************/ -struct st_mysqlnd_protocol_com_stmt_prepare_command -{ - struct st_mysqlnd_com_stmt_prepare_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING query; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_prepare_run */ +/* {{{ mysqlnd_command::stmt_prepare */ static enum_func_status -mysqlnd_com_stmt_prepare_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, stmt_prepare)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING query) { - struct st_mysqlnd_protocol_com_stmt_prepare_command * command = (struct st_mysqlnd_protocol_com_stmt_prepare_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_stmt_prepare_run"); + DBG_ENTER("mysqlnd_command::stmt_prepare"); - ret = send_command(conn->payload_decoder_factory, COM_STMT_PREPARE, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_STMT_PREPARE, (const zend_uchar*) query.s, query.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, @@ -775,47 +402,16 @@ mysqlnd_com_stmt_prepare_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_stmt_prepare_run_command */ +/* {{{ mysqlnd_command::stmt_execute */ static enum_func_status -mysqlnd_com_stmt_prepare_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, stmt_execute)(MYSQLND_CONN_DATA * conn, const MYSQLND_CSTRING payload) { - struct st_mysqlnd_protocol_com_stmt_prepare_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_prepare_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.query = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_stmt_prepare_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STMT_EXECUTE ******************************************/ -struct st_mysqlnd_protocol_com_stmt_execute_command -{ - struct st_mysqlnd_com_stmt_execute_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING payload; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_execute_run */ -static enum_func_status -mysqlnd_com_stmt_execute_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_stmt_execute_command * command = (struct st_mysqlnd_protocol_com_stmt_execute_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_stmt_execute_run"); + DBG_ENTER("mysqlnd_command::stmt_execute"); - ret = send_command(conn->payload_decoder_factory, COM_STMT_EXECUTE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_STMT_EXECUTE, payload.s, payload.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, @@ -828,47 +424,16 @@ mysqlnd_com_stmt_execute_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_stmt_execute_run_command */ +/* {{{ mysqlnd_command::stmt_fetch */ static enum_func_status -mysqlnd_com_stmt_execute_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_stmt_execute_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_execute_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.payload = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_stmt_execute_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STMT_FETCH ******************************************/ -struct st_mysqlnd_protocol_com_stmt_fetch_command +MYSQLND_METHOD(mysqlnd_command, stmt_fetch)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload) { - struct st_mysqlnd_com_stmt_fetch_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING payload; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_fetch_run */ -static enum_func_status -mysqlnd_com_stmt_fetch_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_stmt_fetch_command * command = (struct st_mysqlnd_protocol_com_stmt_fetch_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_stmt_fetch_run"); + DBG_ENTER("mysqlnd_command::stmt_fetch"); - ret = send_command(conn->payload_decoder_factory, COM_STMT_FETCH, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_STMT_FETCH, (const zend_uchar*) payload.s, payload.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, @@ -881,49 +446,18 @@ mysqlnd_com_stmt_fetch_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_stmt_fetch_run_command */ -static enum_func_status -mysqlnd_com_stmt_fetch_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_stmt_fetch_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_fetch_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.payload = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_stmt_fetch_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STMT_RESET ******************************************/ -struct st_mysqlnd_protocol_com_stmt_reset_command -{ - struct st_mysqlnd_com_stmt_reset_context - { - MYSQLND_CONN_DATA * conn; - zend_ulong stmt_id; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_reset_run */ +/* {{{ mysqlnd_command::stmt_reset */ static enum_func_status -mysqlnd_com_stmt_reset_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, stmt_reset)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id) { + const func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + const func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */]; - struct st_mysqlnd_protocol_com_stmt_reset_command * command = (struct st_mysqlnd_protocol_com_stmt_reset_command *) cmd; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response; - DBG_ENTER("mysqlnd_com_stmt_reset_run"); + DBG_ENTER("mysqlnd_command::stmt_reset"); - int4store(cmd_buf, command->context.stmt_id); + int4store(cmd_buf, stmt_id); ret = send_command(conn->payload_decoder_factory, COM_STMT_RESET, cmd_buf, sizeof(cmd_buf), FALSE, &conn->state, conn->error_info, @@ -941,101 +475,39 @@ mysqlnd_com_stmt_reset_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_stmt_reset_run_command */ -static enum_func_status -mysqlnd_com_stmt_reset_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_stmt_reset_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_reset_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.stmt_id = va_arg(args, size_t); - - ret = mysqlnd_com_stmt_reset_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - -/************************** COM_STMT_SEND_LONG_DATA ******************************************/ -struct st_mysqlnd_protocol_com_stmt_send_long_data_command -{ - struct st_mysqlnd_com_stmt_send_long_data_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING payload; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_send_long_data_run */ +/* {{{ mysqlnd_command::stmt_send_long_data */ static enum_func_status -mysqlnd_com_stmt_send_long_data_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, stmt_send_long_data)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload) { - struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command = (struct st_mysqlnd_protocol_com_stmt_send_long_data_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; + enum_func_status ret = FAIL; - DBG_ENTER("mysqlnd_com_stmt_send_long_data_run"); + DBG_ENTER("mysqlnd_command::stmt_send_long_data"); - ret = send_command(conn->payload_decoder_factory, COM_STMT_SEND_LONG_DATA, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE, + ret = send_command(conn->payload_decoder_factory, COM_STMT_SEND_LONG_DATA, (const zend_uchar*) payload.s, payload.l, FALSE, &conn->state, conn->error_info, conn->upsert_status, conn->stats, conn->m->send_close, conn); - - DBG_RETURN(ret); -} -/* }}} */ - - -/* {{{ mysqlnd_com_stmt_send_long_data_run_command */ -static enum_func_status -mysqlnd_com_stmt_send_long_data_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_stmt_send_long_data_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_send_long_data_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.payload = va_arg(args, MYSQLND_CSTRING); - - ret = mysqlnd_com_stmt_send_long_data_run(&command); - + /* COM_STMT_SEND_LONG_DATA - doesn't read result, the server doesn't send ACK */ DBG_RETURN(ret); } /* }}} */ -/************************** COM_STMT_CLOSE ******************************************/ -struct st_mysqlnd_protocol_com_stmt_close_command -{ - struct st_mysqlnd_com_stmt_close_context - { - MYSQLND_CONN_DATA * conn; - zend_ulong stmt_id; - } context; -}; - - -/* {{{ mysqlnd_com_stmt_close_run */ +/* {{{ mysqlnd_command::stmt_close */ static enum_func_status -mysqlnd_com_stmt_close_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, stmt_close)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id) { + func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */]; - struct st_mysqlnd_protocol_com_stmt_close_command * command = (struct st_mysqlnd_protocol_com_stmt_close_command *) cmd; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command; - DBG_ENTER("mysqlnd_com_stmt_close_run"); + DBG_ENTER("mysqlnd_command::stmt_close"); - int4store(cmd_buf, command->context.stmt_id); + int4store(cmd_buf, stmt_id); ret = send_command(conn->payload_decoder_factory, COM_STMT_CLOSE, cmd_buf, sizeof(cmd_buf), FALSE, &conn->state, conn->error_info, @@ -1049,50 +521,15 @@ mysqlnd_com_stmt_close_run(void *cmd) /* }}} */ -/* {{{ mysqlnd_com_stmt_close_run_command */ -static enum_func_status -mysqlnd_com_stmt_close_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_stmt_close_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_stmt_close_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.stmt_id = va_arg(args, size_t); - - ret = mysqlnd_com_stmt_close_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - - -/************************** COM_ENABLE_SSL ******************************************/ -struct st_mysqlnd_protocol_com_enable_ssl_command -{ - struct st_mysqlnd_com_enable_ssl_context - { - MYSQLND_CONN_DATA * conn; - size_t client_capabilities; - size_t server_capabilities; - unsigned int charset_no; - } context; -}; - - -/* {{{ mysqlnd_com_enable_ssl_run */ +/* {{{ mysqlnd_command::enable_ssl */ static enum_func_status -mysqlnd_com_enable_ssl_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, enable_ssl)(MYSQLND_CONN_DATA * const conn, const size_t client_capabilities, const size_t server_capabilities, const unsigned int charset_no) { - struct st_mysqlnd_protocol_com_enable_ssl_command * command = (struct st_mysqlnd_protocol_com_enable_ssl_command *) cmd; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; MYSQLND_PACKET_AUTH auth_packet; - size_t client_capabilities = command->context.client_capabilities; - size_t server_capabilities = command->context.server_capabilities; - DBG_ENTER("mysqlnd_com_enable_ssl_run"); + DBG_ENTER("mysqlnd_command::enable_ssl"); + DBG_INF_FMT("client_capability_flags=%lu", client_capabilities); DBG_INF_FMT("CLIENT_LONG_PASSWORD= %d", client_capabilities & CLIENT_LONG_PASSWORD? 1:0); DBG_INF_FMT("CLIENT_FOUND_ROWS= %d", client_capabilities & CLIENT_FOUND_ROWS? 1:0); @@ -1123,7 +560,7 @@ mysqlnd_com_enable_ssl_run(void *cmd) auth_packet.client_flags = client_capabilities; auth_packet.max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE; - auth_packet.charset_no = command->context.charset_no; + auth_packet.charset_no = charset_no; #ifdef MYSQLND_SSL_SUPPORTED if (client_capabilities & CLIENT_SSL) { @@ -1169,58 +606,24 @@ close_conn: /* }}} */ -/* {{{ mysqlnd_com_enable_ssl_run_command */ +/* {{{ mysqlnd_command::handshake */ static enum_func_status -mysqlnd_com_enable_ssl_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, handshake)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING username, const MYSQLND_CSTRING password, const MYSQLND_CSTRING database, const size_t client_flags) { - struct st_mysqlnd_protocol_com_enable_ssl_command command; - enum_func_status ret; + const char * const user = username.s; - DBG_ENTER("mysqlnd_com_enable_ssl_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.client_capabilities = va_arg(args, size_t); - command.context.server_capabilities = va_arg(args, size_t); - command.context.charset_no = va_arg(args, unsigned int); + const char * const passwd = password.s; + const size_t passwd_len = password.l; - ret = mysqlnd_com_enable_ssl_run(&command); + const char * const db = database.s; + const size_t db_len = database.l; - DBG_RETURN(ret); -} -/* }}} */ + const size_t mysql_flags = client_flags; -/************************** COM_READ_HANDSHAKE ******************************************/ -struct st_mysqlnd_protocol_com_handshake_command -{ - struct st_mysqlnd_com_handshake_context - { - MYSQLND_CONN_DATA * conn; - MYSQLND_CSTRING user; - MYSQLND_CSTRING passwd; - MYSQLND_CSTRING database; - size_t client_flags; - } context; -}; - - -/* {{{ mysqlnd_com_handshake_run */ -static enum_func_status -mysqlnd_com_handshake_run(void *cmd) -{ - struct st_mysqlnd_protocol_com_handshake_command * command = (struct st_mysqlnd_protocol_com_handshake_command *) cmd; - const char * user = command->context.user.s; - - const char * passwd = command->context.passwd.s; - size_t passwd_len = command->context.passwd.l; - - const char * db = command->context.database.s; - size_t db_len = command->context.database.l; - - size_t mysql_flags = command->context.client_flags; - - MYSQLND_CONN_DATA * conn = command->context.conn; MYSQLND_PACKET_GREET greet_packet; - DBG_ENTER("mysqlnd_conn_data::connect_handshake"); + DBG_ENTER("mysqlnd_command::handshake"); + DBG_INF_FMT("stream=%p", conn->vio->data->m.get_stream(conn->vio)); DBG_INF_FMT("[user=%s] [db=%s:%d] [flags=%llu]", user, db, db_len, mysql_flags); @@ -1279,107 +682,28 @@ err: /* }}} */ -/* {{{ mysqlnd_com_handshake_run_command */ -static enum_func_status -mysqlnd_com_handshake_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_handshake_command command; - enum_func_status ret; - - DBG_ENTER("mysqlnd_com_handshake_run_command"); - command.context.conn = va_arg(args, MYSQLND_CONN_DATA *); - command.context.user = *va_arg(args, const MYSQLND_CSTRING *); - command.context.passwd = *va_arg(args, const MYSQLND_CSTRING *); - command.context.database = *va_arg(args, const MYSQLND_CSTRING *); - command.context.client_flags = va_arg(args, size_t); - - ret = mysqlnd_com_handshake_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - - - -/* {{{ _mysqlnd_run_command */ -static enum_func_status -_mysqlnd_run_command(enum php_mysqlnd_server_command command, ...) -{ - enum_func_status ret = FAIL; - va_list args; - DBG_ENTER("_mysqlnd_run_command"); - - va_start(args, command); - switch (command) { - case COM_SET_OPTION: - ret = mysqlnd_com_set_option_run_command(args); - break; - case COM_DEBUG: - ret = mysqlnd_com_debug_run_command(args); - break; - case COM_INIT_DB: - ret = mysqlnd_com_init_db_run_command(args); - break; - case COM_PING: - ret = mysqlnd_com_ping_run_command(args); - break; - case COM_STATISTICS: - ret = mysqlnd_com_statistics_run_command(args); - break; - case COM_PROCESS_KILL: - ret = mysqlnd_com_process_kill_run_command(args); - break; - case COM_REFRESH: - ret = mysqlnd_com_refresh_run_command(args); - break; - case COM_SHUTDOWN: - ret = mysqlnd_com_shutdown_run_command(args); - break; - case COM_QUIT: - ret = mysqlnd_com_quit_run_command(args); - break; - case COM_QUERY: - ret = mysqlnd_com_query_run_command(args); - break; - case COM_REAP_RESULT: - ret = mysqlnd_com_reap_result_run_command(args); - break; - case COM_CHANGE_USER: - ret = mysqlnd_com_change_user_run_command(args); - break; - case COM_STMT_PREPARE: - ret = mysqlnd_com_stmt_prepare_run_command(args); - break; - case COM_STMT_EXECUTE: - ret = mysqlnd_com_stmt_execute_run_command(args); - break; - case COM_STMT_FETCH: - ret = mysqlnd_com_stmt_fetch_run_command(args); - break; - case COM_STMT_RESET: - ret = mysqlnd_com_stmt_reset_run_command(args); - break; - case COM_STMT_SEND_LONG_DATA: - ret = mysqlnd_com_stmt_send_long_data_run_command(args); - break; - case COM_STMT_CLOSE: - ret = mysqlnd_com_stmt_close_run_command(args); - break; - case COM_ENABLE_SSL: - ret = mysqlnd_com_enable_ssl_run_command(args); - break; - case COM_HANDSHAKE: - ret = mysqlnd_com_handshake_run_command(args); - break; - default: - break; - } - va_end(args); - DBG_RETURN(ret); -} -/* }}} */ - -func_mysqlnd__run_command mysqlnd_run_command = _mysqlnd_run_command; +MYSQLND_CLASS_METHODS_START(mysqlnd_command) + MYSQLND_METHOD(mysqlnd_command, set_option), + MYSQLND_METHOD(mysqlnd_command, debug), + MYSQLND_METHOD(mysqlnd_command, init_db), + MYSQLND_METHOD(mysqlnd_command, ping), + MYSQLND_METHOD(mysqlnd_command, statistics), + MYSQLND_METHOD(mysqlnd_command, process_kill), + MYSQLND_METHOD(mysqlnd_command, refresh), + MYSQLND_METHOD(mysqlnd_command, shutdown), + MYSQLND_METHOD(mysqlnd_command, quit), + MYSQLND_METHOD(mysqlnd_command, query), + MYSQLND_METHOD(mysqlnd_command, change_user), + MYSQLND_METHOD(mysqlnd_command, reap_result), + MYSQLND_METHOD(mysqlnd_command, stmt_prepare), + MYSQLND_METHOD(mysqlnd_command, stmt_execute), + MYSQLND_METHOD(mysqlnd_command, stmt_fetch), + MYSQLND_METHOD(mysqlnd_command, stmt_reset), + MYSQLND_METHOD(mysqlnd_command, stmt_send_long_data), + MYSQLND_METHOD(mysqlnd_command, stmt_close), + MYSQLND_METHOD(mysqlnd_command, enable_ssl), + MYSQLND_METHOD(mysqlnd_command, handshake), +MYSQLND_CLASS_METHODS_END; /* * Local variables: diff --git a/ext/mysqlnd/mysqlnd_commands.h b/ext/mysqlnd/mysqlnd_commands.h index 86b4ccebb4..a9041f76e1 100644 --- a/ext/mysqlnd/mysqlnd_commands.h +++ b/ext/mysqlnd/mysqlnd_commands.h @@ -20,7 +20,7 @@ #ifndef MYSQLND_COMMANDS_H #define MYSQLND_COMMANDS_H -extern func_mysqlnd__run_command mysqlnd_run_command; +//extern func_mysqlnd__run_command mysqlnd_run_command; #endif /* MYSQLND_COMMANDS_H */ diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 9f8e1fb5b9..0a4461c2eb 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -379,7 +379,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_server_option)(MYSQLND_CONN_DATA * const c enum_func_status ret = FAIL; DBG_ENTER("mysqlnd_conn_data::set_server_option"); if (PASS == conn->m->local_tx_start(conn, this_func)) { - ret = conn->run_command(COM_SET_OPTION, conn, option); + ret = conn->command->set_option(conn, option); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -531,7 +531,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect_handshake)(MYSQLND_CONN_DATA * conn, { size_t client_flags = mysql_flags; - ret = conn->run_command(COM_HANDSHAKE, conn, username, password, database, client_flags); + ret = conn->command->handshake(conn, *username, *password, *database, client_flags); } DBG_RETURN(ret); } @@ -666,9 +666,13 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn, { const MYSQLND_CSTRING scheme = { transport.s, transport.l }; + /* This will be overwritten below with a copy, but we can use it during authentication */ + conn->unix_socket.s = (char *)socket_or_pipe.s; if (FAIL == conn->m->connect_handshake(conn, &scheme, &username, &password, &database, mysql_flags)) { + conn->unix_socket.s = NULL; goto err; } + conn->unix_socket.s = NULL; } { @@ -873,7 +877,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, send_query)(MYSQLND_CONN_DATA * conn, const ch { const MYSQLND_CSTRING query_string = {query, query_len}; - ret = conn->run_command(COM_QUERY, conn, query_string); + ret = conn->command->query(conn, query_string); if (type == MYSQLND_SEND_QUERY_EXPLICIT) { conn->m->local_tx_end(conn, this_func, ret); @@ -897,7 +901,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, reap_query)(MYSQLND_CONN_DATA * conn, enum_mys DBG_INF_FMT("conn->server_status=%u", UPSERT_STATUS_GET_SERVER_STATUS(conn->upsert_status)); if (type == MYSQLND_REAP_RESULT_IMPLICIT || PASS == conn->m->local_tx_start(conn, this_func)) { - ret = conn->run_command(COM_REAP_RESULT, conn); + ret = conn->command->reap_result(conn); if (type == MYSQLND_REAP_RESULT_EXPLICIT) { conn->m->local_tx_end(conn, this_func, ret); @@ -1042,7 +1046,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, dump_debug_info)(MYSQLND_CONN_DATA * const con DBG_ENTER("mysqlnd_conn_data::dump_debug_info"); DBG_INF_FMT("conn=%llu", conn->thread_id); if (PASS == conn->m->local_tx_start(conn, this_func)) { - ret = conn->run_command(COM_DEBUG, conn); + ret = conn->command->debug(conn); conn->m->local_tx_end(conn, this_func, ret); } @@ -1064,7 +1068,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, select_db)(MYSQLND_CONN_DATA * const conn, con if (PASS == conn->m->local_tx_start(conn, this_func)) { const MYSQLND_CSTRING database = {db, db_len}; - ret = conn->run_command(COM_INIT_DB, conn, database); + ret = conn->command->init_db(conn, database); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -1083,7 +1087,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, ping)(MYSQLND_CONN_DATA * const conn) DBG_INF_FMT("conn=%llu", conn->thread_id); if (PASS == conn->m->local_tx_start(conn, this_func)) { - ret = conn->run_command(COM_PING, conn); + ret = conn->command->ping(conn); conn->m->local_tx_end(conn, this_func, ret); } DBG_INF_FMT("ret=%u", ret); @@ -1103,7 +1107,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, statistic)(MYSQLND_CONN_DATA * conn, zend_stri DBG_INF_FMT("conn=%llu", conn->thread_id); if (PASS == conn->m->local_tx_start(conn, this_func)) { - ret = conn->run_command(COM_STATISTICS, conn, message); + ret = conn->command->statistics(conn, message); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -1122,11 +1126,11 @@ MYSQLND_METHOD(mysqlnd_conn_data, kill)(MYSQLND_CONN_DATA * conn, unsigned int p DBG_INF_FMT("conn=%llu pid=%u", conn->thread_id, pid); if (PASS == conn->m->local_tx_start(conn, this_func)) { - unsigned int process_id = pid; + const unsigned int process_id = pid; /* 'unsigned char' is promoted to 'int' when passed through '...' */ - unsigned int read_response = (pid != conn->thread_id); + const unsigned int read_response = (pid != conn->thread_id); - ret = conn->run_command(COM_PROCESS_KILL, conn, process_id, read_response); + ret = conn->command->process_kill(conn, process_id, read_response); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -1183,9 +1187,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, refresh)(MYSQLND_CONN_DATA * const conn, uint8 DBG_INF_FMT("conn=%llu options=%lu", conn->thread_id, options); if (PASS == conn->m->local_tx_start(conn, this_func)) { - unsigned int options_param = (unsigned int) options; - - ret = conn->run_command(COM_REFRESH, conn, options_param); + ret = conn->command->refresh(conn, options); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -1203,9 +1205,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, shutdown)(MYSQLND_CONN_DATA * const conn, uint DBG_INF_FMT("conn=%llu level=%lu", conn->thread_id, level); if (PASS == conn->m->local_tx_start(conn, this_func)) { - unsigned int level_param = (unsigned int) level; - - ret = conn->run_command(COM_SHUTDOWN, conn, level_param); + ret = conn->command->shutdown(conn, level); conn->m->local_tx_end(conn, this_func, ret); } DBG_RETURN(ret); @@ -1236,7 +1236,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, send_close)(MYSQLND_CONN_DATA * const conn) case CONN_READY: DBG_INF("Connection clean, sending COM_QUIT"); if (net_stream) { - ret = conn->run_command(COM_QUIT, conn); + ret = conn->command->quit(conn); vio->data->m.close_stream(vio, conn->stats, conn->error_info); } SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT); @@ -1574,7 +1574,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, change_user)(MYSQLND_CONN_DATA * const conn, DBG_ENTER("mysqlnd_conn_data::change_user"); DBG_INF_FMT("conn=%llu user=%s passwd=%s db=%s silent=%u", - conn->thread_id, user?user:"", passwd?"***":"null", db?db:"", (silent == TRUE)?1:0 ); + conn->thread_id, user?user:"", passwd?"***":"null", db?db:"", silent == TRUE); if (PASS != conn->m->local_tx_start(conn, this_func)) { goto end; @@ -1810,10 +1810,17 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA * cons DBG_INF_FMT("Adding [%s][%s]", key, value); { zval attrz; - zend_string *str = zend_string_init(key, strlen(key), 1); - GC_MAKE_PERSISTENT_LOCAL(str); - ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), conn->persistent)); - GC_MAKE_PERSISTENT_LOCAL(Z_COUNTED(attrz)); + zend_string *str; + + if (conn->persistent) { + str = zend_string_init(key, strlen(key), 1); + GC_MAKE_PERSISTENT_LOCAL(str); + ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 1)); + GC_MAKE_PERSISTENT_LOCAL(Z_COUNTED(attrz)); + } else { + str = zend_string_init(key, strlen(key), 0); + ZVAL_NEW_STR(&attrz, zend_string_init(value, strlen(value), 0)); + } zend_hash_update(conn->options->connect_attr, str, &attrz); zend_string_release_ex(str, 1); } diff --git a/ext/mysqlnd/mysqlnd_driver.c b/ext/mysqlnd/mysqlnd_driver.c index b61720fe7c..46872d9ecb 100644 --- a/ext/mysqlnd/mysqlnd_driver.c +++ b/ext/mysqlnd/mysqlnd_driver.c @@ -98,8 +98,8 @@ PHPAPI void mysqlnd_library_init(void) static MYSQLND * MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) *factory, const zend_bool persistent) { - size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *); - size_t alloc_size_ret_data = sizeof(MYSQLND_CONN_DATA) + mysqlnd_plugin_count() * sizeof(void *); + const size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *); + const size_t alloc_size_ret_data = sizeof(MYSQLND_CONN_DATA) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND * new_object; MYSQLND_CONN_DATA * data; @@ -143,9 +143,9 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(MYSQLND_CLASS_METHODS_TYP data->protocol_frame_codec = mysqlnd_pfc_init(persistent, factory, data->stats, data->error_info); data->vio = mysqlnd_vio_init(persistent, factory, data->stats, data->error_info); data->payload_decoder_factory = mysqlnd_protocol_payload_decoder_factory_init(data, persistent); - data->run_command = mysqlnd_command_factory_get(); + data->command = mysqlnd_command_get_methods(); - if (!data->protocol_frame_codec || !data->vio || !data->payload_decoder_factory || !data->run_command) { + if (!data->protocol_frame_codec || !data->vio || !data->payload_decoder_factory || !data->command) { new_object->m->dtor(new_object); DBG_RETURN(NULL); } @@ -159,7 +159,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_connection)(MYSQLND_CLASS_METHODS_TYP static MYSQLND * MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object)(MYSQLND * to_be_cloned) { - size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *); + const size_t alloc_size_ret = sizeof(MYSQLND) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND * new_object; DBG_ENTER("mysqlnd_driver::clone_connection_object"); @@ -188,7 +188,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, clone_connection_object)(MYSQLND * to_be_ static MYSQLND_STMT * MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA * const conn) { - size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *); + const size_t alloc_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND_STMT * ret = mnd_ecalloc(1, alloc_size); MYSQLND_STMT_DATA * stmt = NULL; @@ -245,8 +245,8 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_prepared_statement)(MYSQLND_CONN_DATA static MYSQLND_PFC * MYSQLND_METHOD(mysqlnd_object_factory, get_pfc)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info) { - size_t pfc_alloc_size = ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_PFC) + mysqlnd_plugin_count() * sizeof(void *)); - size_t pfc_data_alloc_size = sizeof(MYSQLND_PFC_DATA) + mysqlnd_plugin_count() * sizeof(void *); + const size_t pfc_alloc_size = ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_PFC) + mysqlnd_plugin_count() * sizeof(void *)); + const size_t pfc_data_alloc_size = sizeof(MYSQLND_PFC_DATA) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND_PFC * pfc = mnd_pecalloc(1, pfc_alloc_size + pfc_data_alloc_size, persistent); DBG_ENTER("mysqlnd_object_factory::get_pfc"); @@ -270,8 +270,8 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_pfc)(const zend_bool persistent, MYSQ static MYSQLND_VIO * MYSQLND_METHOD(mysqlnd_object_factory, get_vio)(const zend_bool persistent, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info) { - size_t vio_alloc_size = ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_VIO) + mysqlnd_plugin_count() * sizeof(void *)); - size_t vio_data_alloc_size = sizeof(MYSQLND_VIO_DATA) + mysqlnd_plugin_count() * sizeof(void *); + const size_t vio_alloc_size = ZEND_MM_ALIGNED_SIZE(sizeof(MYSQLND_VIO) + mysqlnd_plugin_count() * sizeof(void *)); + const size_t vio_data_alloc_size = sizeof(MYSQLND_VIO_DATA) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND_VIO * vio = mnd_pecalloc(1, vio_alloc_size + vio_data_alloc_size, persistent); DBG_ENTER("mysqlnd_object_factory::get_vio"); @@ -295,7 +295,7 @@ MYSQLND_METHOD(mysqlnd_object_factory, get_vio)(const zend_bool persistent, MYSQ static MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * MYSQLND_METHOD(mysqlnd_object_factory, get_protocol_payload_decoder_factory)(MYSQLND_CONN_DATA * conn, const zend_bool persistent) { - size_t alloc_size = sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + mysqlnd_plugin_count() * sizeof(void *); + const size_t alloc_size = sizeof(MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY) + mysqlnd_plugin_count() * sizeof(void *); MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY *ret = mnd_pecalloc(1, alloc_size, persistent); DBG_ENTER("mysqlnd_object_factory::get_protocol_payload_decoder_factory"); diff --git a/ext/mysqlnd/mysqlnd_enum_n_def.h b/ext/mysqlnd/mysqlnd_enum_n_def.h index 7630a0a988..21b84ce71f 100644 --- a/ext/mysqlnd/mysqlnd_enum_n_def.h +++ b/ext/mysqlnd/mysqlnd_enum_n_def.h @@ -631,6 +631,7 @@ enum mysqlnd_packet_type PROT_CHG_USER_RESP_PACKET, PROT_SHA256_PK_REQUEST_PACKET, PROT_SHA256_PK_REQUEST_RESPONSE_PACKET, + PROT_CACHED_SHA2_RESULT_PACKET, PROT_LAST /* should always be last */ }; diff --git a/ext/mysqlnd/mysqlnd_ext_plugin.c b/ext/mysqlnd/mysqlnd_ext_plugin.c index b17c80f190..9bcb12f341 100644 --- a/ext/mysqlnd/mysqlnd_ext_plugin.c +++ b/ext/mysqlnd/mysqlnd_ext_plugin.c @@ -362,19 +362,19 @@ _mysqlnd_vio_set_methods(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_vio) * methods) /* {{{ mysqlnd_command_factory_get */ -static func_mysqlnd__run_command +static MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * _mysqlnd_command_factory_get() { - return mysqlnd_run_command; + return &MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command); } /* }}} */ /* {{{ mysqlnd_command_factory_set */ static void -_mysqlnd_command_factory_set(func_mysqlnd__run_command run_command) +_mysqlnd_command_factory_set(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * methods) { - mysqlnd_run_command = run_command; + MYSQLND_CLASS_METHOD_TABLE_NAME(mysqlnd_command) = *methods; } /* }}} */ @@ -449,6 +449,7 @@ struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters = }, }; + /* * Local variables: * tab-width: 4 diff --git a/ext/mysqlnd/mysqlnd_ext_plugin.h b/ext/mysqlnd/mysqlnd_ext_plugin.h index 008e147198..cbd0982982 100644 --- a/ext/mysqlnd/mysqlnd_ext_plugin.h +++ b/ext/mysqlnd/mysqlnd_ext_plugin.h @@ -117,11 +117,11 @@ struct st_mysqlnd_plugin_methods_xetters void (*set)(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_error_info) * methods); } error_info; - struct st_mnd_command_factory_xetters + struct st_mnd_command_xetters { - func_mysqlnd__run_command (*get)(); - void (*set)(func_mysqlnd__run_command factory); - } command_factory; + MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * (*get)(); + void (*set)(MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * methods); + } command; }; PHPAPI extern struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xetters; @@ -157,8 +157,8 @@ PHPAPI extern struct st_mysqlnd_plugin_methods_xetters mysqlnd_plugin_methods_xe #define mysqlnd_vio_get_methods() mysqlnd_plugin_methods_xetters.vio.get() #define mysqlnd_vio_set_methods(m) mysqlnd_plugin_methods_xetters.vio.set((m)) -#define mysqlnd_command_factory_get() mysqlnd_plugin_methods_xetters.command_factory.get() -#define mysqlnd_command_factory_set(m) mysqlnd_plugin_methods_xetters.command_factory.set((m)) +#define mysqlnd_command_get_methods() mysqlnd_plugin_methods_xetters.command.get() +#define mysqlnd_command_set_methods(m) mysqlnd_plugin_methods_xetters.command.set((m)) #define mysqlnd_error_info_get_methods() mysqlnd_plugin_methods_xetters.error_info.get() #define mysqlnd_error_info_set_methods(m) mysqlnd_plugin_methods_xetters.error_info.set((m)) diff --git a/ext/mysqlnd/mysqlnd_priv.h b/ext/mysqlnd/mysqlnd_priv.h index 013f51b8a0..36113d3da9 100644 --- a/ext/mysqlnd/mysqlnd_priv.h +++ b/ext/mysqlnd/mysqlnd_priv.h @@ -30,6 +30,7 @@ PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_protocol_packet_fr PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_vio); PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_upsert_status); PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_error_info); +PHPAPI extern MYSQLND_CLASS_METHOD_TABLE_NAME_FORWARD(mysqlnd_command); enum_func_status mysqlnd_handle_local_infile(MYSQLND_CONN_DATA * conn, const char * const filename, zend_bool * is_warning); #endif /* MYSQLND_PRIV_H */ diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c index f3fab43f0c..703c1f050a 100644 --- a/ext/mysqlnd/mysqlnd_ps.c +++ b/ext/mysqlnd/mysqlnd_ps.c @@ -409,7 +409,7 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const enum_func_status ret = FAIL; const MYSQLND_CSTRING query_string = {query, query_len}; - ret = conn->run_command(COM_STMT_PREPARE, conn, query_string); + ret = conn->command->stmt_prepare(conn, query_string); if (FAIL == ret) { goto fail; } @@ -641,39 +641,6 @@ MYSQLND_METHOD(mysqlnd_stmt, send_execute)(MYSQLND_STMT * const s, const enum_my UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status); if (stmt->result && stmt->state >= MYSQLND_STMT_PREPARED && stmt->field_count) { - /* - We don need to copy the data from the buffers which we will clean. - Because it has already been copied. See - #ifndef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - */ -#ifdef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - if (stmt->result_bind && - stmt->result_zvals_separated_once == TRUE && - stmt->state >= MYSQLND_STMT_USER_FETCHING) - { - /* - We need to copy the data from the buffers which we will clean. - The bound variables point to them only if the user has started - to fetch data (MYSQLND_STMT_USER_FETCHING). - We need to check 'result_zvals_separated_once' or we will leak - in the following scenario - prepare("select 1 from dual"); - execute(); - fetch(); <-- no binding, but that's not a problem - bind_result(); - execute(); <-- here we will leak because we separate without need - */ - unsigned int i; - for (i = 0; i < stmt->field_count; i++) { - if (stmt->result_bind[i].bound == TRUE) { - zval *result = &stmt->result_bind[i].zv; - ZVAL_DEREF(result); - Z_TRY_ADDREF_P(result); - } - } - } -#endif - s->m->flush(s); /* @@ -719,7 +686,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_execute)(MYSQLND_STMT * const s, const enum_my if (ret == PASS) { const MYSQLND_CSTRING payload = {(const char*) request, request_len}; - ret = conn->run_command(COM_STMT_EXECUTE, conn, payload); + ret = conn->command->stmt_execute(conn, payload); } else { SET_CLIENT_ERROR(stmt->error_info, CR_UNKNOWN_ERROR, UNKNOWN_SQLSTATE, "Couldn't generate the request. Possibly OOM."); } @@ -794,32 +761,11 @@ mysqlnd_stmt_fetch_row_buffered(MYSQLND_RES * result, void * param, const unsign } for (i = 0; i < result->field_count; i++) { - zval *result = &stmt->result_bind[i].zv; - - ZVAL_DEREF(result); - /* Clean what we copied last time */ -#ifndef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - zval_ptr_dtor(result); -#endif /* copy the type */ + zval *resultzv = &stmt->result_bind[i].zv; if (stmt->result_bind[i].bound == TRUE) { DBG_INF_FMT("i=%u type=%u", i, Z_TYPE(current_row[i])); - if (Z_TYPE(current_row[i]) != IS_NULL) { - /* - Copy the value. - Pre-condition is that the zvals in the result_bind buffer - have been ZVAL_NULL()-ed or to another simple type - (int, double, bool but not string). Because of the reference - counting the user can't delete the strings the variables point to. - */ - - ZVAL_COPY_VALUE(result, ¤t_row[i]); -#ifndef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - Z_TRY_ADDREF_P(result); -#endif - } else { - ZVAL_NULL(result); - } + ZEND_TRY_ASSIGN_COPY_EX(resultzv, ¤t_row[i], 0); } } } @@ -899,28 +845,17 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES * result, void * param, const unsi } for (i = 0; i < field_count; i++) { + zval *resultzv = &stmt->result_bind[i].zv; if (stmt->result_bind[i].bound == TRUE) { zval *data = &result->unbuf->last_row_data[i]; - zval *result = &stmt->result_bind[i].zv; - - ZVAL_DEREF(result); - /* - stmt->result_bind[i].zv has been already destructed - in result->unbuf->m.free_last_data() - */ -#ifndef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - zval_ptr_dtor(result); -#endif - if (!Z_ISNULL_P(data)) { - if ((Z_TYPE_P(data) == IS_STRING) && (meta->fields[i].max_length < (zend_ulong) Z_STRLEN_P(data))){ - meta->fields[i].max_length = Z_STRLEN_P(data); - } - ZVAL_COPY_VALUE(result, data); - /* copied data, thus also the ownership. Thus null data */ - ZVAL_NULL(data); - } else { - ZVAL_NULL(result); + + if (Z_TYPE_P(data) == IS_STRING && (meta->fields[i].max_length < (zend_ulong) Z_STRLEN_P(data))){ + meta->fields[i].max_length = Z_STRLEN_P(data); } + + ZEND_TRY_ASSIGN_VALUE_EX(resultzv, data, 0); + /* copied data, thus also the ownership. Thus null data */ + ZVAL_NULL(data); } } MYSQLND_INC_CONN_STATISTIC(conn->stats, STAT_ROWS_FETCHED_FROM_CLIENT_PS_UNBUF); @@ -1049,7 +984,7 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, const unsigned { const MYSQLND_CSTRING payload = {(const char*) buf, sizeof(buf)}; - ret = conn->run_command(COM_STMT_FETCH, conn, payload); + ret = conn->command->stmt_fetch(conn, payload); if (ret == FAIL) { COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); DBG_RETURN(FAIL); @@ -1084,33 +1019,22 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES * result, void * param, const unsigned /* If no result bind, do nothing. We consumed the data */ for (i = 0; i < field_count; i++) { + zval *resultzv = &stmt->result_bind[i].zv; if (stmt->result_bind[i].bound == TRUE) { zval *data = &result->unbuf->last_row_data[i]; - zval *result = &stmt->result_bind[i].zv; - - ZVAL_DEREF(result); - /* - stmt->result_bind[i].zv has been already destructed - in result->unbuf->m.free_last_data() - */ -#ifndef WE_DONT_COPY_IN_BUFFERED_AND_UNBUFFERED_BECAUSEOF_IS_REF - zval_ptr_dtor(result); -#endif + DBG_INF_FMT("i=%u bound_var=%p type=%u refc=%u", i, &stmt->result_bind[i].zv, Z_TYPE_P(data), Z_REFCOUNTED(stmt->result_bind[i].zv)? Z_REFCOUNT(stmt->result_bind[i].zv) : 0); - if (!Z_ISNULL_P(data)) { - if ((Z_TYPE_P(data) == IS_STRING) && - (meta->fields[i].max_length < (zend_ulong) Z_STRLEN_P(data))) { - meta->fields[i].max_length = Z_STRLEN_P(data); - } - ZVAL_COPY_VALUE(result, data); - /* copied data, thus also the ownership. Thus null data */ - ZVAL_NULL(data); - } else { - ZVAL_NULL(result); + if (Z_TYPE_P(data) == IS_STRING && + (meta->fields[i].max_length < (zend_ulong) Z_STRLEN_P(data))) { + meta->fields[i].max_length = Z_STRLEN_P(data); } + + ZEND_TRY_ASSIGN_VALUE_EX(resultzv, data, 0); + /* copied data, thus also the ownership. Thus null data */ + ZVAL_NULL(data); } } } else { @@ -1188,28 +1112,6 @@ MYSQLND_METHOD(mysqlnd_stmt, fetch)(MYSQLND_STMT * const s, zend_bool * const fe SET_EMPTY_ERROR(stmt->error_info); SET_EMPTY_ERROR(conn->error_info); - DBG_INF_FMT("result_bind=%p separated_once=%u", &stmt->result_bind, stmt->result_zvals_separated_once); - /* - The user might have not bound any variables for result. - Do the binding once she does it. - */ - if (stmt->result_bind && !stmt->result_zvals_separated_once) { - unsigned int i; - /* - mysqlnd_stmt_store_result() has been called free the bind - variables to prevent leaking of their previous content. - */ - for (i = 0; i < stmt->result->field_count; i++) { - if (stmt->result_bind[i].bound == TRUE) { - zval *result = &stmt->result_bind[i].zv; - ZVAL_DEREF(result); - zval_ptr_dtor(result); - ZVAL_NULL(result); - } - } - stmt->result_zvals_separated_once = TRUE; - } - ret = stmt->result->m.fetch_row(stmt->result, (void*)s, 0, fetched_anything); DBG_RETURN(ret); } @@ -1257,7 +1159,7 @@ MYSQLND_METHOD(mysqlnd_stmt, reset)(MYSQLND_STMT * const s) if (GET_CONNECTION_STATE(&conn->state) == CONN_READY) { size_t stmt_id = stmt->stmt_id; - ret = stmt->conn->run_command(COM_STMT_RESET, stmt->conn, stmt_id); + ret = stmt->conn->command->stmt_reset(stmt->conn, stmt_id); if (ret == FAIL) { COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); } @@ -1363,7 +1265,7 @@ MYSQLND_METHOD(mysqlnd_stmt, send_long_data)(MYSQLND_STMT * const s, unsigned in { const MYSQLND_CSTRING payload = {(const char *) cmd_buf, packet_len}; - ret = conn->run_command(COM_STMT_SEND_LONG_DATA, conn, payload); + ret = conn->command->stmt_send_long_data(conn, payload); if (ret == FAIL) { COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); } @@ -1605,7 +1507,6 @@ MYSQLND_METHOD(mysqlnd_stmt, bind_result)(MYSQLND_STMT * const s, } mysqlnd_stmt_separate_result_bind(s); - stmt->result_zvals_separated_once = FALSE; stmt->result_bind = result_bind; for (i = 0; i < stmt->field_count; i++) { /* Prevent from freeing */ @@ -2188,9 +2089,9 @@ MYSQLND_METHOD_PRIVATE(mysqlnd_stmt, close_on_server)(MYSQLND_STMT * const s, ze if (GET_CONNECTION_STATE(&conn->state) == CONN_READY) { enum_func_status ret = FAIL; - size_t stmt_id = stmt->stmt_id; + const size_t stmt_id = stmt->stmt_id; - ret = conn->run_command(COM_STMT_CLOSE, conn, stmt_id); + ret = conn->command->stmt_close(conn, stmt_id); if (ret == FAIL) { COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); DBG_RETURN(FAIL); diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c index 201e314f7d..74fd2d1840 100644 --- a/ext/mysqlnd/mysqlnd_result.c +++ b/ext/mysqlnd/mysqlnd_result.c @@ -89,7 +89,7 @@ static enum_func_status MYSQLND_METHOD(mysqlnd_result_buffered_c, initialize_result_set_rest)(MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta, MYSQLND_STATS * stats, - zend_bool int_and_float_native) + const zend_bool int_and_float_native) { unsigned int i; enum_func_status ret = PASS; @@ -568,9 +568,9 @@ mysqlnd_query_read_result_set_header(MYSQLND_CONN_DATA * conn, MYSQLND_STMT * s) completeness. */ static const size_t * -MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(MYSQLND_RES_BUFFERED * const result) +MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(const MYSQLND_RES_BUFFERED * const result) { - const MYSQLND_RES_BUFFERED_ZVAL * set = (MYSQLND_RES_BUFFERED_ZVAL *) result; + const MYSQLND_RES_BUFFERED_ZVAL * const set = (const MYSQLND_RES_BUFFERED_ZVAL *) result; /* If: - unbuffered result @@ -600,9 +600,9 @@ MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_lengths)(MYSQLND_RES_BUFFERED completeness. */ static const size_t * -MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(MYSQLND_RES_BUFFERED * const result) +MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(const MYSQLND_RES_BUFFERED * const result) { - const MYSQLND_RES_BUFFERED_C * set = (MYSQLND_RES_BUFFERED_C *) result; + const MYSQLND_RES_BUFFERED_C * const set = (const MYSQLND_RES_BUFFERED_C *) result; DBG_ENTER("mysqlnd_result_buffered_c::fetch_lengths"); if (set->current_row > set->row_count || set->current_row == 0) { @@ -617,7 +617,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered_c, fetch_lengths)(MYSQLND_RES_BUFFERED * /* {{{ mysqlnd_result_unbuffered::fetch_lengths */ static const size_t * -MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(MYSQLND_RES_UNBUFFERED * const result) +MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(const MYSQLND_RES_UNBUFFERED * const result) { /* simulate output of libmysql */ return (result->last_row_data || result->eof_reached)? result->lengths : NULL; @@ -627,7 +627,7 @@ MYSQLND_METHOD(mysqlnd_result_unbuffered, fetch_lengths)(MYSQLND_RES_UNBUFFERED /* {{{ mysqlnd_res::fetch_lengths */ static const size_t * -MYSQLND_METHOD(mysqlnd_res, fetch_lengths)(MYSQLND_RES * const result) +MYSQLND_METHOD(mysqlnd_res, fetch_lengths)(const MYSQLND_RES * const result) { const size_t * ret; DBG_ENTER("mysqlnd_res::fetch_lengths"); @@ -948,12 +948,12 @@ oom: /* {{{ mysqlnd_result_buffered::fetch_row_c */ static enum_func_status -MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * fetched_anything) +MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void * param, unsigned int flags, zend_bool * const fetched_anything) { enum_func_status ret = FAIL; MYSQLND_ROW_C * row = (MYSQLND_ROW_C *) param; const MYSQLND_RES_METADATA * const meta = result->meta; - unsigned int field_count = meta->field_count; + const unsigned int field_count = meta->field_count; MYSQLND_CONN_DATA * const conn = result->conn; DBG_ENTER("mysqlnd_result_buffered::fetch_row_c"); @@ -1041,7 +1041,7 @@ MYSQLND_METHOD(mysqlnd_result_buffered, fetch_row_c)(MYSQLND_RES * result, void /* {{{ mysqlnd_result_buffered_zval::fetch_row */ static enum_func_status -MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_row)(MYSQLND_RES * result, void * param, const unsigned int flags, zend_bool * fetched_anything) +MYSQLND_METHOD(mysqlnd_result_buffered_zval, fetch_row)(MYSQLND_RES * result, void * param, const unsigned int flags, zend_bool * const fetched_anything) { enum_func_status ret = FAIL; zval * row = (zval *) param; @@ -1811,7 +1811,7 @@ MYSQLND_METHOD(mysqlnd_res, fetch_all)(MYSQLND_RES * result, const unsigned int /* {{{ mysqlnd_res::fetch_field_data */ static void -MYSQLND_METHOD(mysqlnd_res, fetch_field_data)(MYSQLND_RES * result, unsigned int offset, zval *return_value) +MYSQLND_METHOD(mysqlnd_res, fetch_field_data)(MYSQLND_RES * result, const unsigned int offset, zval *return_value) { zval row; zval *entry; diff --git a/ext/mysqlnd/mysqlnd_structs.h b/ext/mysqlnd/mysqlnd_structs.h index a7c892b48d..a5c1359853 100644 --- a/ext/mysqlnd/mysqlnd_structs.h +++ b/ext/mysqlnd/mysqlnd_structs.h @@ -174,6 +174,12 @@ typedef struct st_mysqlnd_infile_info } MYSQLND_INFILE_INFO; +typedef int (*func_mysqlnd_local_infile__init)(void ** ptr, const char * const filename); +typedef int (*func_mysqlnd_local_infile__read)(void * ptr, zend_uchar * buf, unsigned int buf_len); +typedef int (*func_mysqlnd_local_infile__error)(void * ptr, char * error_msg, unsigned int error_msg_len); +typedef void (*func_mysqlnd_local_infile__end)(void * ptr); + + /* character set information */ typedef struct st_mysqlnd_charset { @@ -183,20 +189,21 @@ typedef struct st_mysqlnd_charset unsigned int char_minlen; unsigned int char_maxlen; const char *comment; - unsigned int (*mb_charlen)(unsigned int c); - unsigned int (*mb_valid)(const char *start, const char *end); + unsigned int (*mb_charlen)(const unsigned int c); + unsigned int (*mb_valid)(const char * const start, const char * const end); } MYSQLND_CHARSET; /* local infile handler */ typedef struct st_mysqlnd_infile { - int (*local_infile_init)(void **ptr, const char * const filename); - int (*local_infile_read)(void *ptr, zend_uchar * buf, unsigned int buf_len); - int (*local_infile_error)(void *ptr, char * error_msg, unsigned int error_msg_len); - void (*local_infile_end)(void *ptr); + func_mysqlnd_local_infile__init local_infile_init; + func_mysqlnd_local_infile__read local_infile_read; + func_mysqlnd_local_infile__error local_infile_error; + func_mysqlnd_local_infile__end local_infile_end; } MYSQLND_INFILE; + typedef struct st_mysqlnd_session_options { ulong flags; @@ -309,6 +316,54 @@ struct st_mysqlnd_stats }; +typedef enum_func_status (*func_mysqlnd_execute_com_set_option)(MYSQLND_CONN_DATA * const conn, const enum_mysqlnd_server_option option); +typedef enum_func_status (*func_mysqlnd_execute_com_debug)(MYSQLND_CONN_DATA * const conn); +typedef enum_func_status (*func_mysqlnd_execute_com_init_db)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING db); +typedef enum_func_status (*func_mysqlnd_execute_com_ping)(MYSQLND_CONN_DATA * const conn); +typedef enum_func_status (*func_mysqlnd_execute_com_statistics)(MYSQLND_CONN_DATA * const conn, zend_string ** message); +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); +typedef enum_func_status (*func_mysqlnd_execute_com_refresh)(MYSQLND_CONN_DATA * const conn, const uint8_t options); +typedef enum_func_status (*func_mysqlnd_execute_com_shutdown)(MYSQLND_CONN_DATA * const conn, const uint8_t level); +typedef enum_func_status (*func_mysqlnd_execute_com_quit)(MYSQLND_CONN_DATA * const conn); +typedef enum_func_status (*func_mysqlnd_execute_com_query)(MYSQLND_CONN_DATA * const conn, MYSQLND_CSTRING query); +typedef enum_func_status (*func_mysqlnd_execute_com_change_user)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload, const zend_bool silent); +typedef enum_func_status (*func_mysqlnd_execute_com_reap_result)(MYSQLND_CONN_DATA * const conn); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_prepare)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING query); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_execute)(MYSQLND_CONN_DATA * conn, const MYSQLND_CSTRING payload); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_fetch)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_reset)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_send_long_data)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload); +typedef enum_func_status (*func_mysqlnd_execute_com_stmt_close)(MYSQLND_CONN_DATA * const conn, const zend_ulong stmt_id); +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); +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); + + +MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) +{ + func_mysqlnd_execute_com_set_option set_option; + func_mysqlnd_execute_com_debug debug; + func_mysqlnd_execute_com_init_db init_db; + func_mysqlnd_execute_com_ping ping; + func_mysqlnd_execute_com_statistics statistics; + func_mysqlnd_execute_com_process_kill process_kill; + func_mysqlnd_execute_com_refresh refresh; + func_mysqlnd_execute_com_shutdown shutdown; + func_mysqlnd_execute_com_quit quit; + func_mysqlnd_execute_com_query query; + func_mysqlnd_execute_com_change_user change_user; + func_mysqlnd_execute_com_reap_result reap_result; + func_mysqlnd_execute_com_stmt_prepare stmt_prepare; + func_mysqlnd_execute_com_stmt_execute stmt_execute; + func_mysqlnd_execute_com_stmt_fetch stmt_fetch; + func_mysqlnd_execute_com_stmt_reset stmt_reset; + func_mysqlnd_execute_com_stmt_send_long_data stmt_send_long_data; + func_mysqlnd_execute_com_stmt_close stmt_close; + func_mysqlnd_execute_com_enable_ssl enable_ssl; + func_mysqlnd_execute_com_handshake handshake; +}; + + + typedef enum_func_status (*func_mysqlnd_vio__init)(MYSQLND_VIO * const vio, MYSQLND_STATS * const stats, MYSQLND_ERROR_INFO * const error_info); typedef void (*func_mysqlnd_vio__dtor)(MYSQLND_VIO * const vio, MYSQLND_STATS * const conn_stats, MYSQLND_ERROR_INFO * const error_info); @@ -584,8 +639,8 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn) /* for decoding - binary or text protocol */ typedef enum_func_status (*func_mysqlnd_res__row_decoder)(MYSQLND_ROW_BUFFER * row_buffer, zval * fields, - unsigned int field_count, const MYSQLND_FIELD * fields_metadata, - zend_bool as_int_or_float, MYSQLND_STATS * stats); + const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata, + const zend_bool as_int_or_float, MYSQLND_STATS * const stats); typedef MYSQLND_RES * (*func_mysqlnd_res__use_result)(MYSQLND_RES * const result, const zend_bool ps_protocol); @@ -593,7 +648,7 @@ typedef MYSQLND_RES * (*func_mysqlnd_res__store_result)(MYSQLND_RES * result, M 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); typedef MYSQLND_ROW_C (*func_mysqlnd_res__fetch_row_c)(MYSQLND_RES *result); typedef void (*func_mysqlnd_res__fetch_all)(MYSQLND_RES *result, const unsigned int flags, zval *return_value ZEND_FILE_LINE_DC); -typedef void (*func_mysqlnd_res__fetch_field_data)(MYSQLND_RES *result, unsigned int offset, zval *return_value); +typedef void (*func_mysqlnd_res__fetch_field_data)(MYSQLND_RES *result, const unsigned int offset, zval *return_value); typedef uint64_t (*func_mysqlnd_res__num_rows)(const MYSQLND_RES * const result); typedef unsigned int (*func_mysqlnd_res__num_fields)(const MYSQLND_RES * const result); typedef enum_func_status (*func_mysqlnd_res__skip_result)(MYSQLND_RES * const result); @@ -605,7 +660,7 @@ typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_field_direct)(MYSQLND_RES typedef const MYSQLND_FIELD *(*func_mysqlnd_res__fetch_fields)(MYSQLND_RES * const result); typedef enum_func_status (*func_mysqlnd_res__read_result_metadata)(MYSQLND_RES * result, MYSQLND_CONN_DATA * conn); -typedef const size_t * (*func_mysqlnd_res__fetch_lengths)(MYSQLND_RES * const result); +typedef const size_t * (*func_mysqlnd_res__fetch_lengths)(const MYSQLND_RES * const result); 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); typedef void (*func_mysqlnd_res__free_result_buffers)(MYSQLND_RES * result); /* private */ @@ -656,7 +711,7 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_res) typedef uint64_t (*func_mysqlnd_result_unbuffered__num_rows)(const MYSQLND_RES_UNBUFFERED * const result); -typedef const size_t * (*func_mysqlnd_result_unbuffered__fetch_lengths)(MYSQLND_RES_UNBUFFERED * const result); +typedef const size_t * (*func_mysqlnd_result_unbuffered__fetch_lengths)(const MYSQLND_RES_UNBUFFERED * const result); typedef void (*func_mysqlnd_result_unbuffered__free_last_data)(MYSQLND_RES_UNBUFFERED * result, MYSQLND_STATS * const global_stats); typedef void (*func_mysqlnd_result_unbuffered__free_result)(MYSQLND_RES_UNBUFFERED * const result, MYSQLND_STATS * const global_stats); @@ -672,8 +727,8 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_result_unbuffered) typedef uint64_t (*func_mysqlnd_result_buffered__num_rows)(const MYSQLND_RES_BUFFERED * const result); typedef enum_func_status (*func_mysqlnd_result_buffered__initialize_result_set_rest)(MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta, - MYSQLND_STATS * stats, zend_bool int_and_float_native); -typedef const size_t * (*func_mysqlnd_result_buffered__fetch_lengths)(MYSQLND_RES_BUFFERED * const result); + MYSQLND_STATS * stats, const zend_bool int_and_float_native); +typedef const size_t * (*func_mysqlnd_result_buffered__fetch_lengths)(const MYSQLND_RES_BUFFERED * const result); typedef enum_func_status (*func_mysqlnd_result_buffered__data_seek)(MYSQLND_RES_BUFFERED * const result, const uint64_t row); typedef void (*func_mysqlnd_result_buffered__free_result)(MYSQLND_RES_BUFFERED * const result); @@ -841,10 +896,6 @@ struct st_mysqlnd_vio -typedef enum_func_status (*func_mysqlnd__run_command)(enum php_mysqlnd_server_command command, ...); - - - typedef struct st_mysqlnd_connection_state MYSQLND_CONNECTION_STATE; typedef enum mysqlnd_connection_state (*func_mysqlnd_connection_state__get)(const MYSQLND_CONNECTION_STATE * const state_struct); typedef void (*func_mysqlnd_connection_state__set)(MYSQLND_CONNECTION_STATE * const state_struct, const enum mysqlnd_connection_state state); @@ -929,8 +980,7 @@ struct st_mysqlnd_connection_data zend_bool in_async_err_cb; MYSQLND_CLASS_METHODS_TYPE(mysqlnd_object_factory) object_factory; - func_mysqlnd__run_command run_command; - + MYSQLND_CLASS_METHODS_TYPE(mysqlnd_command) * command; MYSQLND_CLASS_METHODS_TYPE(mysqlnd_conn_data) * m; /* persistent connection */ @@ -963,6 +1013,7 @@ struct st_mysqlnd_packet_chg_user_resp; struct st_mysqlnd_packet_auth_pam; struct st_mysqlnd_packet_sha256_pk_request; struct st_mysqlnd_packet_sha256_pk_request_response; +struct st_mysqlnd_packet_cached_sha2_result; typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_greet_packet)(struct st_mysqlnd_packet_greet *packet); typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_auth_packet)(struct st_mysqlnd_packet_auth *packet); @@ -979,6 +1030,7 @@ typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_prepare_respo typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet)(struct st_mysqlnd_packet_chg_user_resp *packet); typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet)(struct st_mysqlnd_packet_sha256_pk_request *packet); typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet)(struct st_mysqlnd_packet_sha256_pk_request_response *packet); +typedef void (*func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet)(struct st_mysqlnd_packet_cached_sha2_result *packet); typedef enum_func_status (*func_mysqlnd_protocol_payload_decoder_factory__send_command)( MYSQLND_PROTOCOL_PAYLOAD_DECODER_FACTORY * payload_decoder_factory, @@ -1034,6 +1086,7 @@ MYSQLND_CLASS_METHODS_TYPE(mysqlnd_protocol_payload_decoder_factory) func_mysqlnd_protocol_payload_decoder_factory__init_change_user_response_packet init_change_user_response_packet; func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_packet init_sha256_pk_request_packet; func_mysqlnd_protocol_payload_decoder_factory__init_sha256_pk_request_response_packet init_sha256_pk_request_response_packet; + func_mysqlnd_protocol_payload_decoder_factory__init_cached_sha2_result_packet init_cached_sha2_result_packet; func_mysqlnd_protocol_payload_decoder_factory__send_command send_command; func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response; @@ -1256,7 +1309,6 @@ struct st_mysqlnd_stmt_data unsigned char send_types_to_server; MYSQLND_PARAM_BIND *param_bind; MYSQLND_RESULT_BIND *result_bind; - zend_bool result_zvals_separated_once; MYSQLND_UPSERT_STATUS * upsert_status; MYSQLND_UPSERT_STATUS upsert_status_impl; @@ -1328,14 +1380,21 @@ typedef zend_uchar * (*func_auth_plugin__get_auth_data)(struct st_mysqlnd_authen MYSQLND_CONN_DATA * conn, const char * const user, const char * const passwd, const size_t passwd_len, zend_uchar * auth_plugin_data, size_t auth_plugin_data_len, const MYSQLND_SESSION_OPTIONS * const session_options, - const MYSQLND_PFC_DATA * const pfc_data, zend_ulong mysql_flags + const MYSQLND_PFC_DATA * const pfc_data, const zend_ulong mysql_flags ); +typedef void (*func_auth_plugin__handle_server_response)(struct st_mysqlnd_authentication_plugin * self, + MYSQLND_CONN_DATA * conn, + const zend_uchar * auth_plugin_data, size_t auth_plugin_data_len, + const char * const passwd, + const size_t passwd_len); + struct st_mysqlnd_authentication_plugin { struct st_mysqlnd_plugin_header plugin_header; struct { func_auth_plugin__get_auth_data get_auth_data; + func_auth_plugin__handle_server_response handle_server_response; } methods; }; diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index 15b64d9f6d..a6c0ac949b 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -287,7 +287,8 @@ mysqlnd_read_packet_header_and_body(MYSQLND_PACKET_HEADER * packet_header, MYSQLND_STATS * stats, MYSQLND_ERROR_INFO * error_info, MYSQLND_CONNECTION_STATE * connection_state, - zend_uchar * buf, size_t buf_size, const char * const packet_type_as_text, + zend_uchar * const buf, const size_t buf_size, + const char * const packet_type_as_text, enum mysqlnd_packet_type packet_type) { DBG_ENTER("mysqlnd_read_packet_header_and_body"); @@ -618,10 +619,14 @@ size_t php_mysqlnd_auth_write(MYSQLND_CONN_DATA * conn, void * _packet) const MYSQLND_CSTRING payload = {(char*) buffer + MYSQLND_HEADER_SIZE, p - (buffer + MYSQLND_HEADER_SIZE)}; const unsigned int silent = packet->silent; - ret = conn->run_command(COM_CHANGE_USER, conn, payload, silent); + ret = conn->command->change_user(conn, payload, silent); DBG_RETURN(ret == PASS? (p - buffer - MYSQLND_HEADER_SIZE) : 0); } else { - size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info); + /* + The auth handshake packet has no command in it. Thus we can't go over conn->command directly. + Well, we can have a command->no_command(conn, payload) + */ + const size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info); if (!sent) { SET_CONNECTION_STATE(connection_state, CONN_QUIT_SENT); } @@ -766,7 +771,7 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - zend_uchar * buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len); + zend_uchar * const buffer = pfc->cmd_buffer.length >= packet->auth_data_len? pfc->cmd_buffer.buffer : mnd_emalloc(packet->auth_data_len); zend_uchar * p = buffer + MYSQLND_HEADER_SIZE; /* start after the header */ DBG_ENTER("php_mysqlnd_change_auth_response_write"); @@ -777,7 +782,11 @@ php_mysqlnd_change_auth_response_write(MYSQLND_CONN_DATA * conn, void * _packet) } { - size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info); + /* + The auth handshake packet has no command in it. Thus we can't go over conn->command directly. + Well, we can have a command->no_command(conn, payload) + */ + const size_t sent = pfc->data->m.send(pfc, vio, buffer, p - buffer - MYSQLND_HEADER_SIZE, stats, error_info); if (buffer != pfc->cmd_buffer.buffer) { mnd_efree(buffer); } @@ -803,8 +812,8 @@ php_mysqlnd_ok_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; zend_uchar local_buf[OK_BUFFER_SIZE]; - size_t buf_len = pfc->cmd_buffer.buffer? pfc->cmd_buffer.length : OK_BUFFER_SIZE; - zend_uchar * buf = pfc->cmd_buffer.buffer? (zend_uchar *) pfc->cmd_buffer.buffer : local_buf; + const size_t buf_len = pfc->cmd_buffer.buffer? pfc->cmd_buffer.length : OK_BUFFER_SIZE; + zend_uchar * const buf = pfc->cmd_buffer.buffer? (zend_uchar *) pfc->cmd_buffer.buffer : local_buf; const zend_uchar * p = buf; const zend_uchar * const begin = buf; zend_ulong net_len; @@ -897,8 +906,8 @@ php_mysqlnd_eof_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - size_t buf_len = pfc->cmd_buffer.length; - zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer; + const size_t buf_len = pfc->cmd_buffer.length; + zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer; const zend_uchar * p = buf; const zend_uchar * const begin = buf; @@ -965,7 +974,7 @@ size_t php_mysqlnd_cmd_write(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - unsigned int error_reporting = EG(error_reporting); + const unsigned int error_reporting = EG(error_reporting); size_t sent = 0; DBG_ENTER("php_mysqlnd_cmd_write"); @@ -1034,8 +1043,8 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; enum_func_status ret = PASS; - size_t buf_len = pfc->cmd_buffer.length; - zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer; + const size_t buf_len = pfc->cmd_buffer.length; + zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer; const zend_uchar * p = buf; const zend_uchar * const begin = buf; size_t len; @@ -1175,8 +1184,9 @@ php_mysqlnd_rset_field_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - size_t buf_len = pfc->cmd_buffer.length, total_len = 0; - zend_uchar * buf = (zend_uchar *) pfc->cmd_buffer.buffer; + const size_t buf_len = pfc->cmd_buffer.length; + size_t total_len = 0; + zend_uchar * const buf = (zend_uchar *) pfc->cmd_buffer.buffer; const zend_uchar * p = buf; const zend_uchar * const begin = buf; char *root_ptr; @@ -1353,7 +1363,7 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc, MYSQLND_ERROR_INFO * error_info, MYSQLND_MEMORY_POOL * pool, MYSQLND_ROW_BUFFER * buffer, - size_t * data_size) + size_t * const data_size) { enum_func_status ret = PASS; MYSQLND_PACKET_HEADER header; @@ -1433,8 +1443,8 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc, /* {{{ php_mysqlnd_rowp_read_binary_protocol */ enum_func_status php_mysqlnd_rowp_read_binary_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fields, - unsigned int field_count, const MYSQLND_FIELD * fields_metadata, - zend_bool as_int_or_float, MYSQLND_STATS * stats) + const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata, + const zend_bool as_int_or_float, MYSQLND_STATS * const stats) { unsigned int i; const zend_uchar * p = row_buffer->ptr; @@ -1530,7 +1540,7 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval * unsigned int i; zval *current_field, *end_field, *start_field; zend_uchar * p = row_buffer->ptr; - size_t data_size = row_buffer->size; + const size_t data_size = row_buffer->size; const zend_uchar * const packet_end = (zend_uchar*) p + data_size; DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_aux"); @@ -1677,8 +1687,8 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval * /* {{{ php_mysqlnd_rowp_read_text_protocol_zval */ enum_func_status php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_ROW_BUFFER * row_buffer, zval * fields, - unsigned int field_count, const MYSQLND_FIELD * fields_metadata, - zend_bool as_int_or_float, MYSQLND_STATS * stats) + const unsigned int field_count, const MYSQLND_FIELD * fields_metadata, + const zend_bool as_int_or_float, MYSQLND_STATS * stats) { enum_func_status ret; DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_zval"); @@ -1691,8 +1701,8 @@ php_mysqlnd_rowp_read_text_protocol_zval(MYSQLND_ROW_BUFFER * row_buffer, zval * /* {{{ php_mysqlnd_rowp_read_text_protocol_c */ enum_func_status php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_ROW_BUFFER * row_buffer, zval * fields, - unsigned int field_count, const MYSQLND_FIELD * fields_metadata, - zend_bool as_int_or_float, MYSQLND_STATS * stats) + const unsigned int field_count, const MYSQLND_FIELD * const fields_metadata, + const zend_bool as_int_or_float, MYSQLND_STATS * const stats) { enum_func_status ret; DBG_ENTER("php_mysqlnd_rowp_read_text_protocol_c"); @@ -1836,7 +1846,7 @@ php_mysqlnd_stats_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_VIO * vio = conn->vio; MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; - size_t buf_len = pfc->cmd_buffer.length; + const size_t buf_len = pfc->cmd_buffer.length; zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer; DBG_ENTER("php_mysqlnd_stats_read"); @@ -1883,7 +1893,7 @@ php_mysqlnd_prepare_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; /* In case of an error, we should have place to put it */ - size_t buf_len = pfc->cmd_buffer.length; + const size_t buf_len = pfc->cmd_buffer.length; zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer; zend_uchar *p = buf; const zend_uchar * const begin = buf; @@ -1966,7 +1976,7 @@ php_mysqlnd_chg_user_read(MYSQLND_CONN_DATA * conn, void * _packet) MYSQLND_STATS * stats = conn->stats; MYSQLND_CONNECTION_STATE * connection_state = &conn->state; /* There could be an error message */ - size_t buf_len = pfc->cmd_buffer.length; + const size_t buf_len = pfc->cmd_buffer.length; zend_uchar *buf = (zend_uchar *) pfc->cmd_buffer.buffer; zend_uchar *p = buf; const zend_uchar * const begin = buf; @@ -2123,6 +2133,75 @@ php_mysqlnd_sha256_pk_request_response_free_mem(void * _packet) } /* }}} */ +static +size_t php_mysqlnd_cached_sha2_result_write(MYSQLND_CONN_DATA * conn, void * _packet) +{ + MYSQLND_PACKET_CACHED_SHA2_RESULT * packet= (MYSQLND_PACKET_CACHED_SHA2_RESULT *) _packet; + MYSQLND_ERROR_INFO * error_info = conn->error_info; + MYSQLND_PFC * pfc = conn->protocol_frame_codec; + MYSQLND_VIO * vio = conn->vio; + MYSQLND_STATS * stats = conn->stats; +#if HAVE_COMPILER_C99_VLA + zend_uchar buffer[MYSQLND_HEADER_SIZE + packet->password_len + 1]; +#else + ALLOCA_FLAG(use_heap) + zend_uchar *buffer = do_alloca(MYSQLND_HEADER_SIZE + packet->password_len + 1, use_heap); +#endif + size_t sent; + + DBG_ENTER("php_mysqlnd_cached_sha2_result_write"); + + if (packet->request == 1) { + int1store(buffer + MYSQLND_HEADER_SIZE, '\2'); + sent = pfc->data->m.send(pfc, vio, buffer, 1, stats, error_info); + } else { + memcpy(buffer + MYSQLND_HEADER_SIZE, packet->password, packet->password_len); + sent = pfc->data->m.send(pfc, vio, buffer, packet->password_len, stats, error_info); + } + +#if !HAVE_COMPILER_C99_VLA + free_alloca(buffer, use_heap); +#endif + + DBG_RETURN(sent); +} + +static enum_func_status +php_mysqlnd_cached_sha2_result_read(MYSQLND_CONN_DATA * conn, void * _packet) +{ + MYSQLND_PACKET_CACHED_SHA2_RESULT * packet= (MYSQLND_PACKET_CACHED_SHA2_RESULT *) _packet; + MYSQLND_ERROR_INFO * error_info = conn->error_info; + MYSQLND_PFC * pfc = conn->protocol_frame_codec; + MYSQLND_VIO * vio = conn->vio; + MYSQLND_STATS * stats = conn->stats; + MYSQLND_CONNECTION_STATE * connection_state = &conn->state; + zend_uchar buf[SHA256_PK_REQUEST_RESP_BUFFER_SIZE]; + zend_uchar *p = buf; + const zend_uchar * const begin = buf; + + DBG_ENTER("php_mysqlnd_cached_sha2_result_read"); + if (FAIL == mysqlnd_read_packet_header_and_body(&(packet->header), pfc, vio, stats, error_info, connection_state, buf, sizeof(buf), "PROT_CACHED_SHA2_RESULT_PACKET", PROT_CACHED_SHA2_RESULT_PACKET)) { + DBG_RETURN(FAIL); + } + BAIL_IF_NO_MORE_DATA; + + p++; + packet->response_code = uint1korr(p); + BAIL_IF_NO_MORE_DATA; + + p++; + packet->result = uint1korr(p); + BAIL_IF_NO_MORE_DATA; + + DBG_RETURN(PASS); + +premature_end: + DBG_ERR_FMT("OK packet %d bytes shorter than expected", p - begin - packet->header.size); + php_error_docref(NULL, E_WARNING, "SHA256_PK_REQUEST_RESPONSE packet "MYSQLND_SZ_T_SPEC" bytes shorter than expected", + p - begin - packet->header.size); + DBG_RETURN(FAIL); +} + /* {{{ packet_methods */ static mysqlnd_packet_methods packet_methods[PROT_LAST] = @@ -2201,9 +2280,14 @@ mysqlnd_packet_methods packet_methods[PROT_LAST] = php_mysqlnd_sha256_pk_request_response_read, NULL, /* write */ php_mysqlnd_sha256_pk_request_response_free_mem, - } /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */ + }, /* PROT_SHA256_PK_REQUEST_RESPONSE_PACKET */ + { + php_mysqlnd_cached_sha2_result_read, + php_mysqlnd_cached_sha2_result_write, + NULL + } /* PROT_CACHED_SHA2_RESULT_PACKET */ }; -/* }}} */ +/* }}} */ /* {{{ mysqlnd_protocol::init_greet_packet */ @@ -2385,6 +2469,17 @@ MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_response_packet)(struct } /* }}} */ +/* {{{ mysqlnd_protocol::init_cached_sha2_result_packet */ +static void +MYSQLND_METHOD(mysqlnd_protocol, init_cached_sha2_result_packet)(struct st_mysqlnd_packet_cached_sha2_result *packet) +{ + DBG_ENTER("mysqlnd_protocol::init_cached_sha2_result_packet"); + memset(packet, 0, sizeof(*packet)); + packet->header.m = &packet_methods[PROT_CACHED_SHA2_RESULT_PACKET]; + DBG_VOID_RETURN; +} +/* }}} */ + /* {{{ mysqlnd_protocol::send_command */ static enum_func_status @@ -2395,7 +2490,7 @@ MYSQLND_METHOD(mysqlnd_protocol, send_command)( const zend_bool silent, struct st_mysqlnd_connection_state * connection_state, - MYSQLND_ERROR_INFO * error_info, + MYSQLND_ERROR_INFO * error_info, MYSQLND_UPSERT_STATUS * upsert_status, MYSQLND_STATS * stats, func_mysqlnd_conn_data__send_close send_close, @@ -2603,6 +2698,7 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_protocol_payload_decoder_factory) MYSQLND_METHOD(mysqlnd_protocol, init_change_user_response_packet), MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_packet), MYSQLND_METHOD(mysqlnd_protocol, init_sha256_pk_request_response_packet), + MYSQLND_METHOD(mysqlnd_protocol, init_cached_sha2_result_packet), MYSQLND_METHOD(mysqlnd_protocol, send_command), MYSQLND_METHOD(mysqlnd_protocol, send_command_handle_response), diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.h b/ext/mysqlnd/mysqlnd_wireprotocol.h index 6e531b0e54..7dfb256eec 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.h +++ b/ext/mysqlnd/mysqlnd_wireprotocol.h @@ -281,6 +281,16 @@ typedef struct st_mysqlnd_packet_sha256_pk_request_response { size_t public_key_len; } MYSQLND_PACKET_SHA256_PK_REQUEST_RESPONSE; +typedef struct st_mysqlnd_packet_cached_sha2_result { + MYSQLND_PACKET_HEADER header; + uint8_t response_code; + uint8_t result; + uint8_t request; + zend_uchar * password; + size_t password_len; +} MYSQLND_PACKET_CACHED_SHA2_RESULT; + + zend_ulong php_mysqlnd_net_field_length(const zend_uchar **packet); zend_uchar * php_mysqlnd_net_store_length(zend_uchar *packet, const uint64_t length); |