12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391 |
- /*
- +----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
- | Copyright (c) 2006-2018 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 3.01 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_01.txt |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andrey Hristov <andrey@php.net> |
- | Ulf Wendel <uw@php.net> |
- +----------------------------------------------------------------------+
- */
- #include "php.h"
- #include "mysqlnd.h"
- #include "mysqlnd_connection.h"
- #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 */
- static enum_func_status
- mysqlnd_com_set_option_run(void *cmd)
- {
- struct st_mysqlnd_protocol_com_set_option_command * command = (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;
- 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");
- int2store(buffer, (unsigned int) option);
- ret = send_command(conn->payload_decoder_factory, COM_SET_OPTION, buffer, sizeof(buffer), FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_SET_OPTION, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_debug_run(void *cmd)
- {
- struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_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_debug_run");
- ret = send_command(conn->payload_decoder_factory, COM_DEBUG, NULL, 0, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_DEBUG, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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;
- 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");
- ret = send_command(conn->payload_decoder_factory, COM_INIT_DB, (zend_uchar*) command->context.db.s, command->context.db.l, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_INIT_DB, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- /*
- The server sends 0 but libmysql doesn't read it and has established
- a protocol of giving back -1. Thus we have to follow it :(
- */
- UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
- if (ret == PASS) {
- if (conn->connect_or_select_db.s) {
- mnd_pefree(conn->connect_or_select_db.s, conn->persistent);
- }
- conn->connect_or_select_db.s = mnd_pestrndup(db.s, db.l, conn->persistent);
- conn->connect_or_select_db.l = db.l;
- if (!conn->connect_or_select_db.s) {
- /* OOM */
- SET_OOM_ERROR(conn->error_info);
- ret = FAIL;
- }
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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;
- 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");
- ret = send_command(conn->payload_decoder_factory, COM_PING, NULL, 0, TRUE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, TRUE, COM_PING, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- /*
- The server sends 0 but libmysql doesn't read it and has established
- a protocol of giving back -1. Thus we have to follow it :(
- */
- UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_statistics_run(void *cmd)
- {
- struct st_mysqlnd_protocol_com_statistics_command * command = (struct st_mysqlnd_protocol_com_statistics_command *) cmd;
- 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");
- ret = send_command(conn->payload_decoder_factory, COM_STATISTICS, NULL, 0, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- MYSQLND_PACKET_STATS stats_header;
- conn->payload_decoder_factory->m.init_stats_packet(&stats_header);
- if (PASS == (ret = PACKET_READ(conn, &stats_header))) {
- /* will be freed by Zend, thus don't use the mnd_ allocator */
- *message = zend_string_init(stats_header.message.s, stats_header.message.l, 0);
- DBG_INF(ZSTR_VAL(*message));
- }
- PACKET_FREE(&stats_header);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ mysqlnd_com_statistics_run_command */
- 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)
- {
- struct st_mysqlnd_protocol_com_process_kill_command * command = (struct st_mysqlnd_protocol_com_process_kill_command *) cmd;
- 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);
- ret = send_command(conn->payload_decoder_factory, COM_PROCESS_KILL, buff, 4, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret && read_response) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_PROCESS_KILL, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- if (read_response) {
- /*
- The server sends 0 but libmysql doesn't read it and has established
- a protocol of giving back -1. Thus we have to follow it :(
- */
- UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
- } else if (PASS == ret) {
- SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
- conn->m->send_close(conn);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ mysqlnd_com_process_kill_run_command */
- static enum_func_status
- mysqlnd_com_process_kill_run_command(va_list args)
- {
- 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;
- 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);
- ret = send_command(conn->payload_decoder_factory, COM_REFRESH, bits, 1, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_REFRESH, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ mysqlnd_com_refresh_run_command */
- 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
- {
- 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;
- 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);
- ret = send_command(conn->payload_decoder_factory, COM_SHUTDOWN, bits, 1, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_SHUTDOWN, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ mysqlnd_com_shutdown_run_command */
- static enum_func_status
- mysqlnd_com_shutdown_run_command(va_list args)
- {
- 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;
- 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");
- ret = send_command(conn->payload_decoder_factory, COM_QUIT, NULL, 0, TRUE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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;
- DBG_ENTER("mysqlnd_com_query_run");
- ret = send_command(conn->payload_decoder_factory, COM_QUERY, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- SET_CONNECTION_STATE(&conn->state, CONN_QUERY_SENT);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_change_user_run(void *cmd)
- {
- struct st_mysqlnd_protocol_com_change_user_command * command = (struct st_mysqlnd_protocol_com_change_user_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_change_user_run");
- ret = send_command(conn->payload_decoder_factory, COM_CHANGE_USER, (zend_uchar*) command->context.payload.s, command->context.payload.l, command->context.silent,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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);
- DBG_ENTER("mysqlnd_com_reap_result_run");
- 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);
- DBG_RETURN(ret);
- }
- ret = conn->m->query_read_result_set_header(conn, NULL);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_stmt_prepare_run(void *cmd)
- {
- 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;
- DBG_ENTER("mysqlnd_com_stmt_prepare_run");
- ret = send_command(conn->payload_decoder_factory, COM_STMT_PREPARE, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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;
- DBG_ENTER("mysqlnd_com_stmt_execute_run");
- ret = send_command(conn->payload_decoder_factory, COM_STMT_EXECUTE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ mysqlnd_com_stmt_execute_run_command */
- 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
- {
- 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;
- DBG_ENTER("mysqlnd_com_stmt_fetch_run");
- ret = send_command(conn->payload_decoder_factory, COM_STMT_FETCH, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_stmt_reset_run(void *cmd)
- {
- 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");
- int4store(cmd_buf, command->context.stmt_id);
- ret = send_command(conn->payload_decoder_factory, COM_STMT_RESET, cmd_buf, sizeof(cmd_buf), FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- if (PASS == ret) {
- ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_STMT_RESET, TRUE,
- conn->error_info, conn->upsert_status, &conn->last_message);
- }
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_stmt_send_long_data_run(void *cmd)
- {
- 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;
- DBG_ENTER("mysqlnd_com_stmt_send_long_data_run");
- ret = send_command(conn->payload_decoder_factory, COM_STMT_SEND_LONG_DATA, (zend_uchar*) command->context.payload.s, command->context.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);
- 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)
- {
- 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");
- int4store(cmd_buf, command->context.stmt_id);
- ret = send_command(conn->payload_decoder_factory, COM_STMT_CLOSE, cmd_buf, sizeof(cmd_buf), FALSE,
- &conn->state,
- conn->error_info,
- conn->upsert_status,
- conn->stats,
- conn->m->send_close,
- conn);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- static enum_func_status
- mysqlnd_com_enable_ssl_run(void *cmd)
- {
- 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_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);
- DBG_INF_FMT("CLIENT_LONG_FLAG= %d", client_capabilities & CLIENT_LONG_FLAG? 1:0);
- DBG_INF_FMT("CLIENT_NO_SCHEMA= %d", client_capabilities & CLIENT_NO_SCHEMA? 1:0);
- DBG_INF_FMT("CLIENT_COMPRESS= %d", client_capabilities & CLIENT_COMPRESS? 1:0);
- DBG_INF_FMT("CLIENT_ODBC= %d", client_capabilities & CLIENT_ODBC? 1:0);
- DBG_INF_FMT("CLIENT_LOCAL_FILES= %d", client_capabilities & CLIENT_LOCAL_FILES? 1:0);
- DBG_INF_FMT("CLIENT_IGNORE_SPACE= %d", client_capabilities & CLIENT_IGNORE_SPACE? 1:0);
- DBG_INF_FMT("CLIENT_PROTOCOL_41= %d", client_capabilities & CLIENT_PROTOCOL_41? 1:0);
- DBG_INF_FMT("CLIENT_INTERACTIVE= %d", client_capabilities & CLIENT_INTERACTIVE? 1:0);
- DBG_INF_FMT("CLIENT_SSL= %d", client_capabilities & CLIENT_SSL? 1:0);
- DBG_INF_FMT("CLIENT_IGNORE_SIGPIPE= %d", client_capabilities & CLIENT_IGNORE_SIGPIPE? 1:0);
- DBG_INF_FMT("CLIENT_TRANSACTIONS= %d", client_capabilities & CLIENT_TRANSACTIONS? 1:0);
- DBG_INF_FMT("CLIENT_RESERVED= %d", client_capabilities & CLIENT_RESERVED? 1:0);
- DBG_INF_FMT("CLIENT_SECURE_CONNECTION=%d", client_capabilities & CLIENT_SECURE_CONNECTION? 1:0);
- DBG_INF_FMT("CLIENT_MULTI_STATEMENTS=%d", client_capabilities & CLIENT_MULTI_STATEMENTS? 1:0);
- DBG_INF_FMT("CLIENT_MULTI_RESULTS= %d", client_capabilities & CLIENT_MULTI_RESULTS? 1:0);
- DBG_INF_FMT("CLIENT_PS_MULTI_RESULTS=%d", client_capabilities & CLIENT_PS_MULTI_RESULTS? 1:0);
- DBG_INF_FMT("CLIENT_CONNECT_ATTRS= %d", client_capabilities & CLIENT_PLUGIN_AUTH? 1:0);
- DBG_INF_FMT("CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA= %d", client_capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA? 1:0);
- DBG_INF_FMT("CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS= %d", client_capabilities & CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS? 1:0);
- DBG_INF_FMT("CLIENT_SESSION_TRACK= %d", client_capabilities & CLIENT_SESSION_TRACK? 1:0);
- DBG_INF_FMT("CLIENT_SSL_VERIFY_SERVER_CERT= %d", client_capabilities & CLIENT_SSL_VERIFY_SERVER_CERT? 1:0);
- DBG_INF_FMT("CLIENT_REMEMBER_OPTIONS= %d", client_capabilities & CLIENT_REMEMBER_OPTIONS? 1:0);
- conn->payload_decoder_factory->m.init_auth_packet(&auth_packet);
- auth_packet.client_flags = client_capabilities;
- auth_packet.max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE;
- auth_packet.charset_no = command->context.charset_no;
- #ifdef MYSQLND_SSL_SUPPORTED
- if (client_capabilities & CLIENT_SSL) {
- const zend_bool server_has_ssl = (server_capabilities & CLIENT_SSL)? TRUE:FALSE;
- if (server_has_ssl == FALSE) {
- goto close_conn;
- } else {
- enum mysqlnd_ssl_peer verify = client_capabilities & CLIENT_SSL_VERIFY_SERVER_CERT?
- MYSQLND_SSL_PEER_VERIFY:
- (client_capabilities & CLIENT_SSL_DONT_VERIFY_SERVER_CERT?
- MYSQLND_SSL_PEER_DONT_VERIFY:
- MYSQLND_SSL_PEER_DEFAULT);
- DBG_INF("Switching to SSL");
- if (!PACKET_WRITE(conn, &auth_packet)) {
- goto close_conn;
- }
- conn->vio->data->m.set_client_option(conn->vio, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *) &verify);
- if (FAIL == conn->vio->data->m.enable_ssl(conn->vio)) {
- goto end;
- }
- }
- }
- #else
- auth_packet.client_flags &= ~CLIENT_SSL;
- if (!PACKET_WRITE(conn, &auth_packet)) {
- goto close_conn;
- }
- #endif
- ret = PASS;
- end:
- PACKET_FREE(&auth_packet);
- DBG_RETURN(ret);
- close_conn:
- SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
- conn->m->send_close(conn);
- SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
- PACKET_FREE(&auth_packet);
- DBG_RETURN(ret);
- }
- /* }}} */
- /* {{{ 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 */
- 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_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);
- conn->payload_decoder_factory->m.init_greet_packet(&greet_packet);
- if (FAIL == PACKET_READ(conn, &greet_packet)) {
- DBG_ERR("Error while reading greeting packet");
- php_error_docref(NULL, E_WARNING, "Error while reading greeting packet. PID=%d", getpid());
- goto err;
- } else if (greet_packet.error_no) {
- DBG_ERR_FMT("errorno=%u error=%s", greet_packet.error_no, greet_packet.error);
- SET_CLIENT_ERROR(conn->error_info, greet_packet.error_no, greet_packet.sqlstate, greet_packet.error);
- goto err;
- } else if (greet_packet.pre41) {
- DBG_ERR_FMT("Connecting to 3.22, 3.23 & 4.0 is not supported. Server is %-.32s", greet_packet.server_version);
- php_error_docref(NULL, E_WARNING, "Connecting to 3.22, 3.23 & 4.0 "
- " is not supported. Server is %-.32s", greet_packet.server_version);
- SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE,
- "Connecting to 3.22, 3.23 & 4.0 servers is not supported");
- goto err;
- }
- conn->thread_id = greet_packet.thread_id;
- conn->protocol_version = greet_packet.protocol_version;
- conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent);
- conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
- if (!conn->greet_charset) {
- php_error_docref(NULL, E_WARNING,
- "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no);
- SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE,
- "Server sent charset unknown to the client. Please, report to the developers");
- goto err;
- }
- conn->server_capabilities = greet_packet.server_capabilities;
- if (FAIL == mysqlnd_connect_run_authentication(conn, user, passwd, db, db_len, (size_t) passwd_len,
- greet_packet.authentication_plugin_data, greet_packet.auth_protocol,
- greet_packet.charset_no, greet_packet.server_capabilities,
- conn->options, mysql_flags))
- {
- goto err;
- }
- UPSERT_STATUS_RESET(conn->upsert_status);
- UPSERT_STATUS_SET_SERVER_STATUS(conn->upsert_status, greet_packet.server_status);
- PACKET_FREE(&greet_packet);
- DBG_RETURN(PASS);
- err:
- conn->server_capabilities = 0;
- PACKET_FREE(&greet_packet);
- DBG_RETURN(FAIL);
- }
- /* }}} */
- /* {{{ 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;
- /*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
|