From: Andrey Hristov Date: Mon, 7 Jan 2019 16:45:33 +0000 (+0200) Subject: Simplify the command factory X-Git-Tag: php-7.4.0alpha1~1268 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8975e4dcd7d6ff5758cd97a9125eedf7b5aa6e77;p=php Simplify the command factory Since more than an year it not possible to create commands in the heap but they are allocated on the stack and directly run. In this regard, it doesn't make sense to have all the vararg stuff. Commands made sense to be created and pushed onto a stack then a general executor will run thru the stack and execute/handle the commands. --- diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index c1c79a6449..9822b40537 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -196,7 +196,7 @@ mysqlnd_switch_to_ssl_if_needed(MYSQLND_CONN_DATA * const conn, { const size_t client_capabilities = mysql_flags; - ret = conn->run_command(COM_ENABLE_SSL, conn, client_capabilities, server_capabilities, charset_no); + ret = conn->command->enable_ssl(conn, client_capabilities, server_capabilities, charset_no); } DBG_RETURN(ret); } diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c index 9d303058f1..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) { - const struct st_mysqlnd_protocol_com_set_option_command * const command = (const struct st_mysqlnd_protocol_com_set_option_command *) cmd; - zend_uchar buffer[2]; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * conn = command->context.conn; - const enum_mysqlnd_server_option option = command->context.option; 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; - 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 */ +/* {{{ mysqlnd_command::debug */ static enum_func_status -mysqlnd_com_set_option_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, debug)(MYSQLND_CONN_DATA * const conn) { - 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 */ -static enum_func_status -mysqlnd_com_debug_run(void *cmd) -{ - const struct st_mysqlnd_protocol_no_params_command * const command = (const struct st_mysqlnd_protocol_no_params_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; 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; - 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 */ -static enum_func_status -mysqlnd_com_debug_run_command(va_list args) -{ - 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 */ +/* {{{ mysqlnd_command::init_db */ static enum_func_status -mysqlnd_com_init_db_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, init_db)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING db) { - const struct st_mysqlnd_protocol_com_init_db_command * const command = (const struct st_mysqlnd_protocol_com_init_db_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; - const MYSQLND_CSTRING db = command->context.db; 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; - DBG_ENTER("mysqlnd_com_init_db_run"); + DBG_ENTER("mysqlnd_command::init_db"); - ret = send_command(conn->payload_decoder_factory, COM_INIT_DB, (const 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 */ -static enum_func_status -mysqlnd_com_init_db_run_command(va_list args) -{ - 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 */ +/* {{{ mysqlnd_command::ping */ static enum_func_status -mysqlnd_com_ping_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, ping)(MYSQLND_CONN_DATA * const conn) { - const struct st_mysqlnd_protocol_no_params_command * const command = (const struct st_mysqlnd_protocol_no_params_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; 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; - 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 */ +/* {{{ mysqlnd_command::statistics */ static enum_func_status -mysqlnd_com_ping_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, statistics)(MYSQLND_CONN_DATA * const conn, zend_string ** message) { - 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 */ -static enum_func_status -mysqlnd_com_statistics_run(void *cmd) -{ - const struct st_mysqlnd_protocol_com_statistics_command * const command = (const struct st_mysqlnd_protocol_com_statistics_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; - zend_string **message = command->context.message; const 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_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) -{ - 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) +MYSQLND_METHOD(mysqlnd_command, process_kill)(MYSQLND_CONN_DATA * const conn, const unsigned int process_id, const zend_bool read_response) { - const struct st_mysqlnd_protocol_com_process_kill_command * const command = (const struct st_mysqlnd_protocol_com_process_kill_command *) cmd; - zend_uchar buff[4]; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; - const zend_bool read_response = command->context.read_response; 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; - 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) -{ - const struct st_mysqlnd_protocol_com_refresh_command * const command = (const struct st_mysqlnd_protocol_com_refresh_command *) cmd; - zend_uchar bits[1]; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; 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; - 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) +MYSQLND_METHOD(mysqlnd_command, shutdown)(MYSQLND_CONN_DATA * const conn, const uint8_t level) { - 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 -{ - 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) -{ - const struct st_mysqlnd_protocol_com_shutdown_command * const command = (const struct st_mysqlnd_protocol_com_shutdown_command *) cmd; - zend_uchar bits[1]; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; 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; - 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) -{ - const struct st_mysqlnd_protocol_com_quit_command * const command = (const struct st_mysqlnd_protocol_com_quit_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; const 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_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 */ -static enum_func_status -mysqlnd_com_quit_run_command(va_list args) -{ - 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 */ +/* {{{ mysqlnd_command::query */ static enum_func_status -mysqlnd_com_query_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, query)(MYSQLND_CONN_DATA * const conn, MYSQLND_CSTRING query) { - const struct st_mysqlnd_protocol_com_query_command * const command = (const struct st_mysqlnd_protocol_com_query_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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, (const 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) { - const struct st_mysqlnd_protocol_com_change_user_command * const command = (const struct st_mysqlnd_protocol_com_change_user_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; const 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_change_user_run"); + DBG_ENTER("mysqlnd_command::change_user"); - ret = send_command(conn->payload_decoder_factory, COM_CHANGE_USER, (const 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 */ -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 -{ - struct st_mysqlnd_com_reap_result_context - { - MYSQLND_CONN_DATA * conn; - } context; -}; - - -/* {{{ mysqlnd_com_reap_result_run */ +/* {{{ mysqlnd_command::reap_result */ static enum_func_status -mysqlnd_com_reap_result_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, reap_result)(MYSQLND_CONN_DATA * const conn) { - const struct st_mysqlnd_protocol_com_reap_result_command * const command = (const struct st_mysqlnd_protocol_com_reap_result_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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 */ +/* {{{ mysqlnd_command::stmt_prepare */ static enum_func_status -mysqlnd_com_reap_result_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, stmt_prepare)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING query) { - 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 */ -static enum_func_status -mysqlnd_com_stmt_prepare_run(void *cmd) -{ - const struct st_mysqlnd_protocol_com_stmt_prepare_command * const command = (const struct st_mysqlnd_protocol_com_stmt_prepare_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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, (const 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 */ -static enum_func_status -mysqlnd_com_stmt_prepare_run_command(va_list args) -{ - 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 */ +/* {{{ mysqlnd_command::stmt_execute */ static enum_func_status -mysqlnd_com_stmt_execute_run(void *cmd) +MYSQLND_METHOD(mysqlnd_command, stmt_execute)(MYSQLND_CONN_DATA * conn, const MYSQLND_CSTRING payload) { - const struct st_mysqlnd_protocol_com_stmt_execute_command * const command = (const struct st_mysqlnd_protocol_com_stmt_execute_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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, (const 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) +MYSQLND_METHOD(mysqlnd_command, stmt_fetch)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload) { - 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 -{ - 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) -{ - const struct st_mysqlnd_protocol_com_stmt_fetch_command * const command = (const struct st_mysqlnd_protocol_com_stmt_fetch_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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, (const 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) { - zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */]; - const struct st_mysqlnd_protocol_com_stmt_reset_command * const command = (const struct st_mysqlnd_protocol_com_stmt_reset_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; 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 */]; + enum_func_status ret = FAIL; - 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 */ +/* {{{ mysqlnd_command::stmt_send_long_data */ static enum_func_status -mysqlnd_com_stmt_reset_run_command(va_list args) +MYSQLND_METHOD(mysqlnd_command, stmt_send_long_data)(MYSQLND_CONN_DATA * const conn, const MYSQLND_CSTRING payload) { - 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 */ -static enum_func_status -mysqlnd_com_stmt_send_long_data_run(void *cmd) -{ - const struct st_mysqlnd_protocol_com_stmt_send_long_data_command * const command = (const struct st_mysqlnd_protocol_com_stmt_send_long_data_command *) cmd; - enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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, (const 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); - + /* COM_STMT_SEND_LONG_DATA - doesn't read result, the server doesn't send ACK */ DBG_RETURN(ret); } /* }}} */ -/* {{{ mysqlnd_com_stmt_send_long_data_run_command */ +/* {{{ mysqlnd_command::stmt_close */ 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); - - 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 */ -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 */]; - const struct st_mysqlnd_protocol_com_stmt_close_command * const command = (const struct st_mysqlnd_protocol_com_stmt_close_command *) cmd; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const 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 */ +/* {{{ mysqlnd_command::enable_ssl */ static enum_func_status -mysqlnd_com_stmt_close_run_command(va_list args) +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_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 */ -static enum_func_status -mysqlnd_com_enable_ssl_run(void *cmd) -{ - const struct st_mysqlnd_protocol_com_enable_ssl_command * const command = (const struct st_mysqlnd_protocol_com_enable_ssl_command *) cmd; enum_func_status ret = FAIL; - MYSQLND_CONN_DATA * const conn = command->context.conn; MYSQLND_PACKET_AUTH auth_packet; - const size_t client_capabilities = command->context.client_capabilities; - const 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 */ -static enum_func_status -mysqlnd_com_enable_ssl_run_command(va_list args) -{ - struct st_mysqlnd_protocol_com_enable_ssl_command command; - enum_func_status ret; - - 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); - - ret = mysqlnd_com_enable_ssl_run(&command); - - DBG_RETURN(ret); -} -/* }}} */ - -/************************** 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 */ +/* {{{ mysqlnd_command::handshake */ static enum_func_status -mysqlnd_com_handshake_run(void *cmd) +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) { - const struct st_mysqlnd_protocol_com_handshake_command * const command = (const struct st_mysqlnd_protocol_com_handshake_command *) cmd; - const char * user = command->context.user.s; + const char * const user = username.s; - const char * passwd = command->context.passwd.s; - const size_t passwd_len = command->context.passwd.l; + const char * const passwd = password.s; + const size_t passwd_len = password.l; - const char * db = command->context.database.s; - const size_t db_len = command->context.database.l; + const char * const db = database.s; + const size_t db_len = database.l; - const size_t mysql_flags = command->context.client_flags; + const size_t mysql_flags = 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(const 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 a361361818..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); } @@ -877,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); @@ -901,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); @@ -1046,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); } @@ -1068,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); @@ -1087,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); @@ -1107,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); @@ -1126,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); @@ -1187,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); @@ -1207,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); @@ -1240,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); diff --git a/ext/mysqlnd/mysqlnd_driver.c b/ext/mysqlnd/mysqlnd_driver.c index dc08c649bc..46872d9ecb 100644 --- a/ext/mysqlnd/mysqlnd_driver.c +++ b/ext/mysqlnd/mysqlnd_driver.c @@ -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); } diff --git a/ext/mysqlnd/mysqlnd_ext_plugin.c b/ext/mysqlnd/mysqlnd_ext_plugin.c index f0d4112369..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; } /* }}} */ 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 09ef8fa9a3..d8671b9da0 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; } @@ -686,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."); } @@ -990,7 +990,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); @@ -1189,7 +1189,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); } @@ -1295,7 +1295,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); } @@ -2120,9 +2120,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_structs.h b/ext/mysqlnd/mysqlnd_structs.h index 5ab5798355..ad662a1253 100644 --- a/ext/mysqlnd/mysqlnd_structs.h +++ b/ext/mysqlnd/mysqlnd_structs.h @@ -316,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); @@ -848,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); @@ -936,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 */ diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index fd7dfe515b..bd8078225b 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -618,7 +618,7 @@ 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);