mysqlnd_commands.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP Version 7 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 2006-2018 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 3.01 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available through the world-wide-web at the following url: |
  10. | http://www.php.net/license/3_01.txt |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Andrey Hristov <andrey@php.net> |
  16. | Ulf Wendel <uw@php.net> |
  17. +----------------------------------------------------------------------+
  18. */
  19. #include "php.h"
  20. #include "mysqlnd.h"
  21. #include "mysqlnd_connection.h"
  22. #include "mysqlnd_priv.h"
  23. #include "mysqlnd_auth.h"
  24. #include "mysqlnd_wireprotocol.h"
  25. #include "mysqlnd_statistics.h"
  26. #include "mysqlnd_debug.h"
  27. struct st_mysqlnd_protocol_no_params_command
  28. {
  29. struct st_mysqlnd_protocol_no_params_command_context
  30. {
  31. MYSQLND_CONN_DATA * conn;
  32. } context;
  33. };
  34. /************************** COM_SET_OPTION ******************************************/
  35. struct st_mysqlnd_protocol_com_set_option_command
  36. {
  37. struct st_mysqlnd_com_set_option_context
  38. {
  39. MYSQLND_CONN_DATA * conn;
  40. enum_mysqlnd_server_option option;
  41. } context;
  42. };
  43. /* {{{ mysqlnd_com_set_option_run */
  44. static enum_func_status
  45. mysqlnd_com_set_option_run(void *cmd)
  46. {
  47. struct st_mysqlnd_protocol_com_set_option_command * command = (struct st_mysqlnd_protocol_com_set_option_command *) cmd;
  48. zend_uchar buffer[2];
  49. enum_func_status ret = FAIL;
  50. MYSQLND_CONN_DATA * conn = command->context.conn;
  51. enum_mysqlnd_server_option option = command->context.option;
  52. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  53. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  54. DBG_ENTER("mysqlnd_com_set_option_run");
  55. int2store(buffer, (unsigned int) option);
  56. ret = send_command(conn->payload_decoder_factory, COM_SET_OPTION, buffer, sizeof(buffer), FALSE,
  57. &conn->state,
  58. conn->error_info,
  59. conn->upsert_status,
  60. conn->stats,
  61. conn->m->send_close,
  62. conn);
  63. if (PASS == ret) {
  64. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_SET_OPTION, TRUE,
  65. conn->error_info, conn->upsert_status, &conn->last_message);
  66. }
  67. DBG_RETURN(ret);
  68. }
  69. /* }}} */
  70. /* {{{ mysqlnd_com_set_option_run_command */
  71. static enum_func_status
  72. mysqlnd_com_set_option_run_command(va_list args)
  73. {
  74. struct st_mysqlnd_protocol_com_set_option_command command;
  75. enum_func_status ret;
  76. DBG_ENTER("mysqlnd_com_set_option_run_command");
  77. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  78. command.context.option = va_arg(args, enum_mysqlnd_server_option);
  79. ret = mysqlnd_com_set_option_run(&command);
  80. DBG_RETURN(ret);
  81. }
  82. /* }}} */
  83. /************************** COM_DEBUG ******************************************/
  84. /* {{{ mysqlnd_com_debug_run */
  85. static enum_func_status
  86. mysqlnd_com_debug_run(void *cmd)
  87. {
  88. struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
  89. enum_func_status ret = FAIL;
  90. MYSQLND_CONN_DATA * conn = command->context.conn;
  91. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  92. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  93. DBG_ENTER("mysqlnd_com_debug_run");
  94. ret = send_command(conn->payload_decoder_factory, COM_DEBUG, NULL, 0, FALSE,
  95. &conn->state,
  96. conn->error_info,
  97. conn->upsert_status,
  98. conn->stats,
  99. conn->m->send_close,
  100. conn);
  101. if (PASS == ret) {
  102. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_EOF_PACKET, FALSE, COM_DEBUG, TRUE,
  103. conn->error_info, conn->upsert_status, &conn->last_message);
  104. }
  105. DBG_RETURN(ret);
  106. }
  107. /* }}} */
  108. /* {{{ mysqlnd_com_debug_run_command */
  109. static enum_func_status
  110. mysqlnd_com_debug_run_command(va_list args)
  111. {
  112. struct st_mysqlnd_protocol_no_params_command command;
  113. enum_func_status ret;
  114. DBG_ENTER("mysqlnd_com_debug_run_command");
  115. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  116. ret = mysqlnd_com_debug_run(&command);
  117. DBG_RETURN(ret);
  118. }
  119. /* }}} */
  120. /************************** COM_INIT_DB ******************************************/
  121. struct st_mysqlnd_protocol_com_init_db_command
  122. {
  123. struct st_mysqlnd_com_init_db_context
  124. {
  125. MYSQLND_CONN_DATA * conn;
  126. MYSQLND_CSTRING db;
  127. } context;
  128. };
  129. /* {{{ mysqlnd_com_init_db_run */
  130. static enum_func_status
  131. mysqlnd_com_init_db_run(void *cmd)
  132. {
  133. struct st_mysqlnd_protocol_com_init_db_command * command = (struct st_mysqlnd_protocol_com_init_db_command *) cmd;
  134. enum_func_status ret = FAIL;
  135. MYSQLND_CONN_DATA * conn = command->context.conn;
  136. const MYSQLND_CSTRING db = command->context.db;
  137. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  138. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  139. DBG_ENTER("mysqlnd_com_init_db_run");
  140. ret = send_command(conn->payload_decoder_factory, COM_INIT_DB, (zend_uchar*) command->context.db.s, command->context.db.l, FALSE,
  141. &conn->state,
  142. conn->error_info,
  143. conn->upsert_status,
  144. conn->stats,
  145. conn->m->send_close,
  146. conn);
  147. if (PASS == ret) {
  148. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_INIT_DB, TRUE,
  149. conn->error_info, conn->upsert_status, &conn->last_message);
  150. }
  151. /*
  152. The server sends 0 but libmysql doesn't read it and has established
  153. a protocol of giving back -1. Thus we have to follow it :(
  154. */
  155. UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
  156. if (ret == PASS) {
  157. if (conn->connect_or_select_db.s) {
  158. mnd_pefree(conn->connect_or_select_db.s, conn->persistent);
  159. }
  160. conn->connect_or_select_db.s = mnd_pestrndup(db.s, db.l, conn->persistent);
  161. conn->connect_or_select_db.l = db.l;
  162. if (!conn->connect_or_select_db.s) {
  163. /* OOM */
  164. SET_OOM_ERROR(conn->error_info);
  165. ret = FAIL;
  166. }
  167. }
  168. DBG_RETURN(ret);
  169. }
  170. /* }}} */
  171. /* {{{ mysqlnd_com_init_db_run_command */
  172. static enum_func_status
  173. mysqlnd_com_init_db_run_command(va_list args)
  174. {
  175. struct st_mysqlnd_protocol_com_init_db_command command;
  176. enum_func_status ret;
  177. DBG_ENTER("mysqlnd_com_init_db_run_command");
  178. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  179. command.context.db = va_arg(args, MYSQLND_CSTRING);
  180. ret = mysqlnd_com_init_db_run(&command);
  181. DBG_RETURN(ret);
  182. }
  183. /* }}} */
  184. /************************** COM_PING ******************************************/
  185. /* {{{ mysqlnd_com_ping_run */
  186. static enum_func_status
  187. mysqlnd_com_ping_run(void *cmd)
  188. {
  189. struct st_mysqlnd_protocol_no_params_command * command = (struct st_mysqlnd_protocol_no_params_command *) cmd;
  190. enum_func_status ret = FAIL;
  191. MYSQLND_CONN_DATA * conn = command->context.conn;
  192. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  193. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  194. DBG_ENTER("mysqlnd_com_ping_run");
  195. ret = send_command(conn->payload_decoder_factory, COM_PING, NULL, 0, TRUE,
  196. &conn->state,
  197. conn->error_info,
  198. conn->upsert_status,
  199. conn->stats,
  200. conn->m->send_close,
  201. conn);
  202. if (PASS == ret) {
  203. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, TRUE, COM_PING, TRUE,
  204. conn->error_info, conn->upsert_status, &conn->last_message);
  205. }
  206. /*
  207. The server sends 0 but libmysql doesn't read it and has established
  208. a protocol of giving back -1. Thus we have to follow it :(
  209. */
  210. UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
  211. DBG_RETURN(ret);
  212. }
  213. /* }}} */
  214. /* {{{ mysqlnd_com_ping_run_command */
  215. static enum_func_status
  216. mysqlnd_com_ping_run_command(va_list args)
  217. {
  218. struct st_mysqlnd_protocol_no_params_command command;
  219. enum_func_status ret;
  220. DBG_ENTER("mysqlnd_com_ping_run_command");
  221. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  222. ret = mysqlnd_com_ping_run(&command);
  223. DBG_RETURN(ret);
  224. }
  225. /* }}} */
  226. /************************** COM_STATISTICS ******************************************/
  227. struct st_mysqlnd_protocol_com_statistics_command
  228. {
  229. struct st_mysqlnd_com_statistics_context
  230. {
  231. MYSQLND_CONN_DATA * conn;
  232. zend_string ** message;
  233. } context;
  234. };
  235. /* {{{ mysqlnd_com_statistics_run */
  236. static enum_func_status
  237. mysqlnd_com_statistics_run(void *cmd)
  238. {
  239. struct st_mysqlnd_protocol_com_statistics_command * command = (struct st_mysqlnd_protocol_com_statistics_command *) cmd;
  240. enum_func_status ret = FAIL;
  241. MYSQLND_CONN_DATA * conn = command->context.conn;
  242. zend_string **message = command->context.message;
  243. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  244. DBG_ENTER("mysqlnd_com_statistics_run");
  245. ret = send_command(conn->payload_decoder_factory, COM_STATISTICS, NULL, 0, FALSE,
  246. &conn->state,
  247. conn->error_info,
  248. conn->upsert_status,
  249. conn->stats,
  250. conn->m->send_close,
  251. conn);
  252. if (PASS == ret) {
  253. MYSQLND_PACKET_STATS stats_header;
  254. conn->payload_decoder_factory->m.init_stats_packet(&stats_header);
  255. if (PASS == (ret = PACKET_READ(conn, &stats_header))) {
  256. /* will be freed by Zend, thus don't use the mnd_ allocator */
  257. *message = zend_string_init(stats_header.message.s, stats_header.message.l, 0);
  258. DBG_INF(ZSTR_VAL(*message));
  259. }
  260. PACKET_FREE(&stats_header);
  261. }
  262. DBG_RETURN(ret);
  263. }
  264. /* }}} */
  265. /* {{{ mysqlnd_com_statistics_run_command */
  266. static enum_func_status
  267. mysqlnd_com_statistics_run_command(va_list args)
  268. {
  269. struct st_mysqlnd_protocol_com_statistics_command command;
  270. enum_func_status ret;
  271. DBG_ENTER("mysqlnd_com_statistics_run_command");
  272. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  273. command.context.message = va_arg(args, zend_string **);
  274. ret = mysqlnd_com_statistics_run(&command);
  275. DBG_RETURN(ret);
  276. }
  277. /* }}} */
  278. /************************** COM_PROCESS_KILL ******************************************/
  279. struct st_mysqlnd_protocol_com_process_kill_command
  280. {
  281. struct st_mysqlnd_com_process_kill_context
  282. {
  283. MYSQLND_CONN_DATA * conn;
  284. unsigned int process_id;
  285. zend_bool read_response;
  286. } context;
  287. };
  288. /* {{{ mysqlnd_com_process_kill_run */
  289. enum_func_status
  290. mysqlnd_com_process_kill_run(void *cmd)
  291. {
  292. struct st_mysqlnd_protocol_com_process_kill_command * command = (struct st_mysqlnd_protocol_com_process_kill_command *) cmd;
  293. zend_uchar buff[4];
  294. enum_func_status ret = FAIL;
  295. MYSQLND_CONN_DATA * conn = command->context.conn;
  296. zend_bool read_response = command->context.read_response;
  297. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  298. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  299. DBG_ENTER("mysqlnd_com_process_kill_run");
  300. int4store(buff, command->context.process_id);
  301. ret = send_command(conn->payload_decoder_factory, COM_PROCESS_KILL, buff, 4, FALSE,
  302. &conn->state,
  303. conn->error_info,
  304. conn->upsert_status,
  305. conn->stats,
  306. conn->m->send_close,
  307. conn);
  308. if (PASS == ret && read_response) {
  309. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_PROCESS_KILL, TRUE,
  310. conn->error_info, conn->upsert_status, &conn->last_message);
  311. }
  312. if (read_response) {
  313. /*
  314. The server sends 0 but libmysql doesn't read it and has established
  315. a protocol of giving back -1. Thus we have to follow it :(
  316. */
  317. UPSERT_STATUS_SET_AFFECTED_ROWS_TO_ERROR(conn->upsert_status);
  318. } else if (PASS == ret) {
  319. SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
  320. conn->m->send_close(conn);
  321. }
  322. DBG_RETURN(ret);
  323. }
  324. /* }}} */
  325. /* {{{ mysqlnd_com_process_kill_run_command */
  326. static enum_func_status
  327. mysqlnd_com_process_kill_run_command(va_list args)
  328. {
  329. struct st_mysqlnd_protocol_com_process_kill_command command;
  330. enum_func_status ret;
  331. DBG_ENTER("mysqlnd_com_process_kill_run_command");
  332. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  333. command.context.process_id = va_arg(args, unsigned int);
  334. command.context.read_response = va_arg(args, unsigned int)? TRUE:FALSE;
  335. ret = mysqlnd_com_process_kill_run(&command);
  336. DBG_RETURN(ret);
  337. }
  338. /* }}} */
  339. /************************** COM_REFRESH ******************************************/
  340. struct st_mysqlnd_protocol_com_refresh_command
  341. {
  342. struct st_mysqlnd_com_refresh_context
  343. {
  344. MYSQLND_CONN_DATA * conn;
  345. uint8_t options;
  346. } context;
  347. };
  348. /* {{{ mysqlnd_com_refresh_run */
  349. enum_func_status
  350. mysqlnd_com_refresh_run(void *cmd)
  351. {
  352. struct st_mysqlnd_protocol_com_refresh_command * command = (struct st_mysqlnd_protocol_com_refresh_command *) cmd;
  353. zend_uchar bits[1];
  354. enum_func_status ret = FAIL;
  355. MYSQLND_CONN_DATA * conn = command->context.conn;
  356. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  357. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  358. DBG_ENTER("mysqlnd_com_refresh_run");
  359. int1store(bits, command->context.options);
  360. ret = send_command(conn->payload_decoder_factory, COM_REFRESH, bits, 1, FALSE,
  361. &conn->state,
  362. conn->error_info,
  363. conn->upsert_status,
  364. conn->stats,
  365. conn->m->send_close,
  366. conn);
  367. if (PASS == ret) {
  368. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_REFRESH, TRUE,
  369. conn->error_info, conn->upsert_status, &conn->last_message);
  370. }
  371. DBG_RETURN(ret);
  372. }
  373. /* }}} */
  374. /* {{{ mysqlnd_com_refresh_run_command */
  375. static enum_func_status
  376. mysqlnd_com_refresh_run_command(va_list args)
  377. {
  378. struct st_mysqlnd_protocol_com_refresh_command command;
  379. enum_func_status ret;
  380. DBG_ENTER("mysqlnd_com_refresh_run_command");
  381. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  382. command.context.options = va_arg(args, unsigned int);
  383. ret = mysqlnd_com_refresh_run(&command);
  384. DBG_RETURN(ret);
  385. }
  386. /* }}} */
  387. /************************** COM_SHUTDOWN ******************************************/
  388. struct st_mysqlnd_protocol_com_shutdown_command
  389. {
  390. struct st_mysqlnd_com_shutdown_context
  391. {
  392. MYSQLND_CONN_DATA * conn;
  393. uint8_t level;
  394. } context;
  395. };
  396. /* {{{ mysqlnd_com_shutdown_run */
  397. enum_func_status
  398. mysqlnd_com_shutdown_run(void *cmd)
  399. {
  400. struct st_mysqlnd_protocol_com_shutdown_command * command = (struct st_mysqlnd_protocol_com_shutdown_command *) cmd;
  401. zend_uchar bits[1];
  402. enum_func_status ret = FAIL;
  403. MYSQLND_CONN_DATA * conn = command->context.conn;
  404. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  405. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  406. DBG_ENTER("mysqlnd_com_shutdown_run");
  407. int1store(bits, command->context.level);
  408. ret = send_command(conn->payload_decoder_factory, COM_SHUTDOWN, bits, 1, FALSE,
  409. &conn->state,
  410. conn->error_info,
  411. conn->upsert_status,
  412. conn->stats,
  413. conn->m->send_close,
  414. conn);
  415. if (PASS == ret) {
  416. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_SHUTDOWN, TRUE,
  417. conn->error_info, conn->upsert_status, &conn->last_message);
  418. }
  419. DBG_RETURN(ret);
  420. }
  421. /* }}} */
  422. /* {{{ mysqlnd_com_shutdown_run_command */
  423. static enum_func_status
  424. mysqlnd_com_shutdown_run_command(va_list args)
  425. {
  426. struct st_mysqlnd_protocol_com_shutdown_command command;
  427. enum_func_status ret;
  428. DBG_ENTER("mysqlnd_com_shutdown_run_command");
  429. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  430. command.context.level = va_arg(args, unsigned int);
  431. ret = mysqlnd_com_shutdown_run(&command);
  432. DBG_RETURN(ret);
  433. }
  434. /* }}} */
  435. /************************** COM_QUIT ******************************************/
  436. struct st_mysqlnd_protocol_com_quit_command
  437. {
  438. struct st_mysqlnd_com_quit_context
  439. {
  440. MYSQLND_CONN_DATA * conn;
  441. } context;
  442. };
  443. /* {{{ mysqlnd_com_quit_run */
  444. enum_func_status
  445. mysqlnd_com_quit_run(void *cmd)
  446. {
  447. struct st_mysqlnd_protocol_com_quit_command * command = (struct st_mysqlnd_protocol_com_quit_command *) cmd;
  448. enum_func_status ret = FAIL;
  449. MYSQLND_CONN_DATA * conn = command->context.conn;
  450. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  451. DBG_ENTER("mysqlnd_com_quit_run");
  452. ret = send_command(conn->payload_decoder_factory, COM_QUIT, NULL, 0, TRUE,
  453. &conn->state,
  454. conn->error_info,
  455. conn->upsert_status,
  456. conn->stats,
  457. conn->m->send_close,
  458. conn);
  459. DBG_RETURN(ret);
  460. }
  461. /* }}} */
  462. /* {{{ mysqlnd_com_quit_run_command */
  463. static enum_func_status
  464. mysqlnd_com_quit_run_command(va_list args)
  465. {
  466. struct st_mysqlnd_protocol_com_quit_command command;
  467. enum_func_status ret;
  468. DBG_ENTER("mysqlnd_com_quit_run_command");
  469. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  470. ret = mysqlnd_com_quit_run(&command);
  471. DBG_RETURN(ret);
  472. }
  473. /* }}} */
  474. /************************** COM_QUERY ******************************************/
  475. struct st_mysqlnd_protocol_com_query_command
  476. {
  477. struct st_mysqlnd_com_query_context
  478. {
  479. MYSQLND_CONN_DATA * conn;
  480. MYSQLND_CSTRING query;
  481. } context;
  482. };
  483. /* {{{ mysqlnd_com_query_run */
  484. static enum_func_status
  485. mysqlnd_com_query_run(void *cmd)
  486. {
  487. struct st_mysqlnd_protocol_com_query_command * command = (struct st_mysqlnd_protocol_com_query_command *) cmd;
  488. enum_func_status ret = FAIL;
  489. MYSQLND_CONN_DATA * conn = command->context.conn;
  490. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  491. DBG_ENTER("mysqlnd_com_query_run");
  492. ret = send_command(conn->payload_decoder_factory, COM_QUERY, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE,
  493. &conn->state,
  494. conn->error_info,
  495. conn->upsert_status,
  496. conn->stats,
  497. conn->m->send_close,
  498. conn);
  499. if (PASS == ret) {
  500. SET_CONNECTION_STATE(&conn->state, CONN_QUERY_SENT);
  501. }
  502. DBG_RETURN(ret);
  503. }
  504. /* }}} */
  505. /* {{{ mysqlnd_com_query_run_command */
  506. static enum_func_status
  507. mysqlnd_com_query_run_command(va_list args)
  508. {
  509. struct st_mysqlnd_protocol_com_query_command command;
  510. enum_func_status ret;
  511. DBG_ENTER("mysqlnd_com_query_run_command");
  512. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  513. command.context.query = va_arg(args, MYSQLND_CSTRING);
  514. ret = mysqlnd_com_query_run(&command);
  515. DBG_RETURN(ret);
  516. }
  517. /* }}} */
  518. /************************** COM_CHANGE_USER ******************************************/
  519. struct st_mysqlnd_protocol_com_change_user_command
  520. {
  521. struct st_mysqlnd_com_change_user_context
  522. {
  523. MYSQLND_CONN_DATA * conn;
  524. MYSQLND_CSTRING payload;
  525. zend_bool silent;
  526. } context;
  527. };
  528. /* {{{ mysqlnd_com_change_user_run */
  529. static enum_func_status
  530. mysqlnd_com_change_user_run(void *cmd)
  531. {
  532. struct st_mysqlnd_protocol_com_change_user_command * command = (struct st_mysqlnd_protocol_com_change_user_command *) cmd;
  533. enum_func_status ret = FAIL;
  534. MYSQLND_CONN_DATA * conn = command->context.conn;
  535. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  536. DBG_ENTER("mysqlnd_com_change_user_run");
  537. ret = send_command(conn->payload_decoder_factory, COM_CHANGE_USER, (zend_uchar*) command->context.payload.s, command->context.payload.l, command->context.silent,
  538. &conn->state,
  539. conn->error_info,
  540. conn->upsert_status,
  541. conn->stats,
  542. conn->m->send_close,
  543. conn);
  544. DBG_RETURN(ret);
  545. }
  546. /* }}} */
  547. /* {{{ mysqlnd_com_change_user_run_command */
  548. static enum_func_status
  549. mysqlnd_com_change_user_run_command(va_list args)
  550. {
  551. struct st_mysqlnd_protocol_com_change_user_command command;
  552. enum_func_status ret;
  553. DBG_ENTER("mysqlnd_com_change_user_run_command");
  554. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  555. command.context.payload = va_arg(args, MYSQLND_CSTRING);
  556. command.context.silent = va_arg(args, unsigned int);
  557. ret = mysqlnd_com_change_user_run(&command);
  558. DBG_RETURN(ret);
  559. }
  560. /* }}} */
  561. /************************** COM_REAP_RESULT ******************************************/
  562. struct st_mysqlnd_protocol_com_reap_result_command
  563. {
  564. struct st_mysqlnd_com_reap_result_context
  565. {
  566. MYSQLND_CONN_DATA * conn;
  567. } context;
  568. };
  569. /* {{{ mysqlnd_com_reap_result_run */
  570. static enum_func_status
  571. mysqlnd_com_reap_result_run(void *cmd)
  572. {
  573. struct st_mysqlnd_protocol_com_reap_result_command * command = (struct st_mysqlnd_protocol_com_reap_result_command *) cmd;
  574. enum_func_status ret = FAIL;
  575. MYSQLND_CONN_DATA * conn = command->context.conn;
  576. const enum_mysqlnd_connection_state state = GET_CONNECTION_STATE(&conn->state);
  577. DBG_ENTER("mysqlnd_com_reap_result_run");
  578. if (state <= CONN_READY || state == CONN_QUIT_SENT) {
  579. php_error_docref(NULL, E_WARNING, "Connection not opened, clear or has been closed");
  580. DBG_ERR_FMT("Connection not opened, clear or has been closed. State=%u", state);
  581. DBG_RETURN(ret);
  582. }
  583. ret = conn->m->query_read_result_set_header(conn, NULL);
  584. DBG_RETURN(ret);
  585. }
  586. /* }}} */
  587. /* {{{ mysqlnd_com_reap_result_run_command */
  588. static enum_func_status
  589. mysqlnd_com_reap_result_run_command(va_list args)
  590. {
  591. struct st_mysqlnd_protocol_com_reap_result_command command;
  592. enum_func_status ret;
  593. DBG_ENTER("mysqlnd_com_reap_result_run_command");
  594. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  595. ret = mysqlnd_com_reap_result_run(&command);
  596. DBG_RETURN(ret);
  597. }
  598. /* }}} */
  599. /************************** COM_STMT_PREPARE ******************************************/
  600. struct st_mysqlnd_protocol_com_stmt_prepare_command
  601. {
  602. struct st_mysqlnd_com_stmt_prepare_context
  603. {
  604. MYSQLND_CONN_DATA * conn;
  605. MYSQLND_CSTRING query;
  606. } context;
  607. };
  608. /* {{{ mysqlnd_com_stmt_prepare_run */
  609. static enum_func_status
  610. mysqlnd_com_stmt_prepare_run(void *cmd)
  611. {
  612. struct st_mysqlnd_protocol_com_stmt_prepare_command * command = (struct st_mysqlnd_protocol_com_stmt_prepare_command *) cmd;
  613. enum_func_status ret = FAIL;
  614. MYSQLND_CONN_DATA * conn = command->context.conn;
  615. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  616. DBG_ENTER("mysqlnd_com_stmt_prepare_run");
  617. ret = send_command(conn->payload_decoder_factory, COM_STMT_PREPARE, (zend_uchar*) command->context.query.s, command->context.query.l, FALSE,
  618. &conn->state,
  619. conn->error_info,
  620. conn->upsert_status,
  621. conn->stats,
  622. conn->m->send_close,
  623. conn);
  624. DBG_RETURN(ret);
  625. }
  626. /* }}} */
  627. /* {{{ mysqlnd_com_stmt_prepare_run_command */
  628. static enum_func_status
  629. mysqlnd_com_stmt_prepare_run_command(va_list args)
  630. {
  631. struct st_mysqlnd_protocol_com_stmt_prepare_command command;
  632. enum_func_status ret;
  633. DBG_ENTER("mysqlnd_com_stmt_prepare_run_command");
  634. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  635. command.context.query = va_arg(args, MYSQLND_CSTRING);
  636. ret = mysqlnd_com_stmt_prepare_run(&command);
  637. DBG_RETURN(ret);
  638. }
  639. /* }}} */
  640. /************************** COM_STMT_EXECUTE ******************************************/
  641. struct st_mysqlnd_protocol_com_stmt_execute_command
  642. {
  643. struct st_mysqlnd_com_stmt_execute_context
  644. {
  645. MYSQLND_CONN_DATA * conn;
  646. MYSQLND_CSTRING payload;
  647. } context;
  648. };
  649. /* {{{ mysqlnd_com_stmt_execute_run */
  650. static enum_func_status
  651. mysqlnd_com_stmt_execute_run(void *cmd)
  652. {
  653. struct st_mysqlnd_protocol_com_stmt_execute_command * command = (struct st_mysqlnd_protocol_com_stmt_execute_command *) cmd;
  654. enum_func_status ret = FAIL;
  655. MYSQLND_CONN_DATA * conn = command->context.conn;
  656. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  657. DBG_ENTER("mysqlnd_com_stmt_execute_run");
  658. ret = send_command(conn->payload_decoder_factory, COM_STMT_EXECUTE, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE,
  659. &conn->state,
  660. conn->error_info,
  661. conn->upsert_status,
  662. conn->stats,
  663. conn->m->send_close,
  664. conn);
  665. DBG_RETURN(ret);
  666. }
  667. /* }}} */
  668. /* {{{ mysqlnd_com_stmt_execute_run_command */
  669. static enum_func_status
  670. mysqlnd_com_stmt_execute_run_command(va_list args)
  671. {
  672. struct st_mysqlnd_protocol_com_stmt_execute_command command;
  673. enum_func_status ret;
  674. DBG_ENTER("mysqlnd_com_stmt_execute_run_command");
  675. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  676. command.context.payload = va_arg(args, MYSQLND_CSTRING);
  677. ret = mysqlnd_com_stmt_execute_run(&command);
  678. DBG_RETURN(ret);
  679. }
  680. /* }}} */
  681. /************************** COM_STMT_FETCH ******************************************/
  682. struct st_mysqlnd_protocol_com_stmt_fetch_command
  683. {
  684. struct st_mysqlnd_com_stmt_fetch_context
  685. {
  686. MYSQLND_CONN_DATA * conn;
  687. MYSQLND_CSTRING payload;
  688. } context;
  689. };
  690. /* {{{ mysqlnd_com_stmt_fetch_run */
  691. static enum_func_status
  692. mysqlnd_com_stmt_fetch_run(void *cmd)
  693. {
  694. struct st_mysqlnd_protocol_com_stmt_fetch_command * command = (struct st_mysqlnd_protocol_com_stmt_fetch_command *) cmd;
  695. enum_func_status ret = FAIL;
  696. MYSQLND_CONN_DATA * conn = command->context.conn;
  697. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  698. DBG_ENTER("mysqlnd_com_stmt_fetch_run");
  699. ret = send_command(conn->payload_decoder_factory, COM_STMT_FETCH, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE,
  700. &conn->state,
  701. conn->error_info,
  702. conn->upsert_status,
  703. conn->stats,
  704. conn->m->send_close,
  705. conn);
  706. DBG_RETURN(ret);
  707. }
  708. /* }}} */
  709. /* {{{ mysqlnd_com_stmt_fetch_run_command */
  710. static enum_func_status
  711. mysqlnd_com_stmt_fetch_run_command(va_list args)
  712. {
  713. struct st_mysqlnd_protocol_com_stmt_fetch_command command;
  714. enum_func_status ret;
  715. DBG_ENTER("mysqlnd_com_stmt_fetch_run_command");
  716. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  717. command.context.payload = va_arg(args, MYSQLND_CSTRING);
  718. ret = mysqlnd_com_stmt_fetch_run(&command);
  719. DBG_RETURN(ret);
  720. }
  721. /* }}} */
  722. /************************** COM_STMT_RESET ******************************************/
  723. struct st_mysqlnd_protocol_com_stmt_reset_command
  724. {
  725. struct st_mysqlnd_com_stmt_reset_context
  726. {
  727. MYSQLND_CONN_DATA * conn;
  728. zend_ulong stmt_id;
  729. } context;
  730. };
  731. /* {{{ mysqlnd_com_stmt_reset_run */
  732. static enum_func_status
  733. mysqlnd_com_stmt_reset_run(void *cmd)
  734. {
  735. zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */];
  736. struct st_mysqlnd_protocol_com_stmt_reset_command * command = (struct st_mysqlnd_protocol_com_stmt_reset_command *) cmd;
  737. enum_func_status ret = FAIL;
  738. MYSQLND_CONN_DATA * conn = command->context.conn;
  739. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  740. func_mysqlnd_protocol_payload_decoder_factory__send_command_handle_response send_command_handle_response = conn->payload_decoder_factory->m.send_command_handle_response;
  741. DBG_ENTER("mysqlnd_com_stmt_reset_run");
  742. int4store(cmd_buf, command->context.stmt_id);
  743. ret = send_command(conn->payload_decoder_factory, COM_STMT_RESET, cmd_buf, sizeof(cmd_buf), FALSE,
  744. &conn->state,
  745. conn->error_info,
  746. conn->upsert_status,
  747. conn->stats,
  748. conn->m->send_close,
  749. conn);
  750. if (PASS == ret) {
  751. ret = send_command_handle_response(conn->payload_decoder_factory, PROT_OK_PACKET, FALSE, COM_STMT_RESET, TRUE,
  752. conn->error_info, conn->upsert_status, &conn->last_message);
  753. }
  754. DBG_RETURN(ret);
  755. }
  756. /* }}} */
  757. /* {{{ mysqlnd_com_stmt_reset_run_command */
  758. static enum_func_status
  759. mysqlnd_com_stmt_reset_run_command(va_list args)
  760. {
  761. struct st_mysqlnd_protocol_com_stmt_reset_command command;
  762. enum_func_status ret;
  763. DBG_ENTER("mysqlnd_com_stmt_reset_run_command");
  764. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  765. command.context.stmt_id = va_arg(args, size_t);
  766. ret = mysqlnd_com_stmt_reset_run(&command);
  767. DBG_RETURN(ret);
  768. }
  769. /* }}} */
  770. /************************** COM_STMT_SEND_LONG_DATA ******************************************/
  771. struct st_mysqlnd_protocol_com_stmt_send_long_data_command
  772. {
  773. struct st_mysqlnd_com_stmt_send_long_data_context
  774. {
  775. MYSQLND_CONN_DATA * conn;
  776. MYSQLND_CSTRING payload;
  777. } context;
  778. };
  779. /* {{{ mysqlnd_com_stmt_send_long_data_run */
  780. static enum_func_status
  781. mysqlnd_com_stmt_send_long_data_run(void *cmd)
  782. {
  783. struct st_mysqlnd_protocol_com_stmt_send_long_data_command * command = (struct st_mysqlnd_protocol_com_stmt_send_long_data_command *) cmd;
  784. enum_func_status ret = FAIL;
  785. MYSQLND_CONN_DATA * conn = command->context.conn;
  786. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  787. DBG_ENTER("mysqlnd_com_stmt_send_long_data_run");
  788. ret = send_command(conn->payload_decoder_factory, COM_STMT_SEND_LONG_DATA, (zend_uchar*) command->context.payload.s, command->context.payload.l, FALSE,
  789. &conn->state,
  790. conn->error_info,
  791. conn->upsert_status,
  792. conn->stats,
  793. conn->m->send_close,
  794. conn);
  795. DBG_RETURN(ret);
  796. }
  797. /* }}} */
  798. /* {{{ mysqlnd_com_stmt_send_long_data_run_command */
  799. static enum_func_status
  800. mysqlnd_com_stmt_send_long_data_run_command(va_list args)
  801. {
  802. struct st_mysqlnd_protocol_com_stmt_send_long_data_command command;
  803. enum_func_status ret;
  804. DBG_ENTER("mysqlnd_com_stmt_send_long_data_run_command");
  805. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  806. command.context.payload = va_arg(args, MYSQLND_CSTRING);
  807. ret = mysqlnd_com_stmt_send_long_data_run(&command);
  808. DBG_RETURN(ret);
  809. }
  810. /* }}} */
  811. /************************** COM_STMT_CLOSE ******************************************/
  812. struct st_mysqlnd_protocol_com_stmt_close_command
  813. {
  814. struct st_mysqlnd_com_stmt_close_context
  815. {
  816. MYSQLND_CONN_DATA * conn;
  817. zend_ulong stmt_id;
  818. } context;
  819. };
  820. /* {{{ mysqlnd_com_stmt_close_run */
  821. static enum_func_status
  822. mysqlnd_com_stmt_close_run(void *cmd)
  823. {
  824. zend_uchar cmd_buf[MYSQLND_STMT_ID_LENGTH /* statement id */];
  825. struct st_mysqlnd_protocol_com_stmt_close_command * command = (struct st_mysqlnd_protocol_com_stmt_close_command *) cmd;
  826. enum_func_status ret = FAIL;
  827. MYSQLND_CONN_DATA * conn = command->context.conn;
  828. func_mysqlnd_protocol_payload_decoder_factory__send_command send_command = conn->payload_decoder_factory->m.send_command;
  829. DBG_ENTER("mysqlnd_com_stmt_close_run");
  830. int4store(cmd_buf, command->context.stmt_id);
  831. ret = send_command(conn->payload_decoder_factory, COM_STMT_CLOSE, cmd_buf, sizeof(cmd_buf), FALSE,
  832. &conn->state,
  833. conn->error_info,
  834. conn->upsert_status,
  835. conn->stats,
  836. conn->m->send_close,
  837. conn);
  838. DBG_RETURN(ret);
  839. }
  840. /* }}} */
  841. /* {{{ mysqlnd_com_stmt_close_run_command */
  842. static enum_func_status
  843. mysqlnd_com_stmt_close_run_command(va_list args)
  844. {
  845. struct st_mysqlnd_protocol_com_stmt_close_command command;
  846. enum_func_status ret;
  847. DBG_ENTER("mysqlnd_com_stmt_close_run_command");
  848. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  849. command.context.stmt_id = va_arg(args, size_t);
  850. ret = mysqlnd_com_stmt_close_run(&command);
  851. DBG_RETURN(ret);
  852. }
  853. /* }}} */
  854. /************************** COM_ENABLE_SSL ******************************************/
  855. struct st_mysqlnd_protocol_com_enable_ssl_command
  856. {
  857. struct st_mysqlnd_com_enable_ssl_context
  858. {
  859. MYSQLND_CONN_DATA * conn;
  860. size_t client_capabilities;
  861. size_t server_capabilities;
  862. unsigned int charset_no;
  863. } context;
  864. };
  865. /* {{{ mysqlnd_com_enable_ssl_run */
  866. static enum_func_status
  867. mysqlnd_com_enable_ssl_run(void *cmd)
  868. {
  869. struct st_mysqlnd_protocol_com_enable_ssl_command * command = (struct st_mysqlnd_protocol_com_enable_ssl_command *) cmd;
  870. enum_func_status ret = FAIL;
  871. MYSQLND_CONN_DATA * conn = command->context.conn;
  872. MYSQLND_PACKET_AUTH auth_packet;
  873. size_t client_capabilities = command->context.client_capabilities;
  874. size_t server_capabilities = command->context.server_capabilities;
  875. DBG_ENTER("mysqlnd_com_enable_ssl_run");
  876. DBG_INF_FMT("client_capability_flags=%lu", client_capabilities);
  877. DBG_INF_FMT("CLIENT_LONG_PASSWORD= %d", client_capabilities & CLIENT_LONG_PASSWORD? 1:0);
  878. DBG_INF_FMT("CLIENT_FOUND_ROWS= %d", client_capabilities & CLIENT_FOUND_ROWS? 1:0);
  879. DBG_INF_FMT("CLIENT_LONG_FLAG= %d", client_capabilities & CLIENT_LONG_FLAG? 1:0);
  880. DBG_INF_FMT("CLIENT_NO_SCHEMA= %d", client_capabilities & CLIENT_NO_SCHEMA? 1:0);
  881. DBG_INF_FMT("CLIENT_COMPRESS= %d", client_capabilities & CLIENT_COMPRESS? 1:0);
  882. DBG_INF_FMT("CLIENT_ODBC= %d", client_capabilities & CLIENT_ODBC? 1:0);
  883. DBG_INF_FMT("CLIENT_LOCAL_FILES= %d", client_capabilities & CLIENT_LOCAL_FILES? 1:0);
  884. DBG_INF_FMT("CLIENT_IGNORE_SPACE= %d", client_capabilities & CLIENT_IGNORE_SPACE? 1:0);
  885. DBG_INF_FMT("CLIENT_PROTOCOL_41= %d", client_capabilities & CLIENT_PROTOCOL_41? 1:0);
  886. DBG_INF_FMT("CLIENT_INTERACTIVE= %d", client_capabilities & CLIENT_INTERACTIVE? 1:0);
  887. DBG_INF_FMT("CLIENT_SSL= %d", client_capabilities & CLIENT_SSL? 1:0);
  888. DBG_INF_FMT("CLIENT_IGNORE_SIGPIPE= %d", client_capabilities & CLIENT_IGNORE_SIGPIPE? 1:0);
  889. DBG_INF_FMT("CLIENT_TRANSACTIONS= %d", client_capabilities & CLIENT_TRANSACTIONS? 1:0);
  890. DBG_INF_FMT("CLIENT_RESERVED= %d", client_capabilities & CLIENT_RESERVED? 1:0);
  891. DBG_INF_FMT("CLIENT_SECURE_CONNECTION=%d", client_capabilities & CLIENT_SECURE_CONNECTION? 1:0);
  892. DBG_INF_FMT("CLIENT_MULTI_STATEMENTS=%d", client_capabilities & CLIENT_MULTI_STATEMENTS? 1:0);
  893. DBG_INF_FMT("CLIENT_MULTI_RESULTS= %d", client_capabilities & CLIENT_MULTI_RESULTS? 1:0);
  894. DBG_INF_FMT("CLIENT_PS_MULTI_RESULTS=%d", client_capabilities & CLIENT_PS_MULTI_RESULTS? 1:0);
  895. DBG_INF_FMT("CLIENT_CONNECT_ATTRS= %d", client_capabilities & CLIENT_PLUGIN_AUTH? 1:0);
  896. DBG_INF_FMT("CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA= %d", client_capabilities & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA? 1:0);
  897. DBG_INF_FMT("CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS= %d", client_capabilities & CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS? 1:0);
  898. DBG_INF_FMT("CLIENT_SESSION_TRACK= %d", client_capabilities & CLIENT_SESSION_TRACK? 1:0);
  899. DBG_INF_FMT("CLIENT_SSL_VERIFY_SERVER_CERT= %d", client_capabilities & CLIENT_SSL_VERIFY_SERVER_CERT? 1:0);
  900. DBG_INF_FMT("CLIENT_REMEMBER_OPTIONS= %d", client_capabilities & CLIENT_REMEMBER_OPTIONS? 1:0);
  901. conn->payload_decoder_factory->m.init_auth_packet(&auth_packet);
  902. auth_packet.client_flags = client_capabilities;
  903. auth_packet.max_packet_size = MYSQLND_ASSEMBLED_PACKET_MAX_SIZE;
  904. auth_packet.charset_no = command->context.charset_no;
  905. #ifdef MYSQLND_SSL_SUPPORTED
  906. if (client_capabilities & CLIENT_SSL) {
  907. const zend_bool server_has_ssl = (server_capabilities & CLIENT_SSL)? TRUE:FALSE;
  908. if (server_has_ssl == FALSE) {
  909. goto close_conn;
  910. } else {
  911. enum mysqlnd_ssl_peer verify = client_capabilities & CLIENT_SSL_VERIFY_SERVER_CERT?
  912. MYSQLND_SSL_PEER_VERIFY:
  913. (client_capabilities & CLIENT_SSL_DONT_VERIFY_SERVER_CERT?
  914. MYSQLND_SSL_PEER_DONT_VERIFY:
  915. MYSQLND_SSL_PEER_DEFAULT);
  916. DBG_INF("Switching to SSL");
  917. if (!PACKET_WRITE(conn, &auth_packet)) {
  918. goto close_conn;
  919. }
  920. conn->vio->data->m.set_client_option(conn->vio, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (const char *) &verify);
  921. if (FAIL == conn->vio->data->m.enable_ssl(conn->vio)) {
  922. goto end;
  923. }
  924. }
  925. }
  926. #else
  927. auth_packet.client_flags &= ~CLIENT_SSL;
  928. if (!PACKET_WRITE(conn, &auth_packet)) {
  929. goto close_conn;
  930. }
  931. #endif
  932. ret = PASS;
  933. end:
  934. PACKET_FREE(&auth_packet);
  935. DBG_RETURN(ret);
  936. close_conn:
  937. SET_CONNECTION_STATE(&conn->state, CONN_QUIT_SENT);
  938. conn->m->send_close(conn);
  939. SET_CLIENT_ERROR(conn->error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
  940. PACKET_FREE(&auth_packet);
  941. DBG_RETURN(ret);
  942. }
  943. /* }}} */
  944. /* {{{ mysqlnd_com_enable_ssl_run_command */
  945. static enum_func_status
  946. mysqlnd_com_enable_ssl_run_command(va_list args)
  947. {
  948. struct st_mysqlnd_protocol_com_enable_ssl_command command;
  949. enum_func_status ret;
  950. DBG_ENTER("mysqlnd_com_enable_ssl_run_command");
  951. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  952. command.context.client_capabilities = va_arg(args, size_t);
  953. command.context.server_capabilities = va_arg(args, size_t);
  954. command.context.charset_no = va_arg(args, unsigned int);
  955. ret = mysqlnd_com_enable_ssl_run(&command);
  956. DBG_RETURN(ret);
  957. }
  958. /* }}} */
  959. /************************** COM_READ_HANDSHAKE ******************************************/
  960. struct st_mysqlnd_protocol_com_handshake_command
  961. {
  962. struct st_mysqlnd_com_handshake_context
  963. {
  964. MYSQLND_CONN_DATA * conn;
  965. MYSQLND_CSTRING user;
  966. MYSQLND_CSTRING passwd;
  967. MYSQLND_CSTRING database;
  968. size_t client_flags;
  969. } context;
  970. };
  971. /* {{{ mysqlnd_com_handshake_run */
  972. static enum_func_status
  973. mysqlnd_com_handshake_run(void *cmd)
  974. {
  975. struct st_mysqlnd_protocol_com_handshake_command * command = (struct st_mysqlnd_protocol_com_handshake_command *) cmd;
  976. const char * user = command->context.user.s;
  977. const char * passwd = command->context.passwd.s;
  978. size_t passwd_len = command->context.passwd.l;
  979. const char * db = command->context.database.s;
  980. size_t db_len = command->context.database.l;
  981. size_t mysql_flags = command->context.client_flags;
  982. MYSQLND_CONN_DATA * conn = command->context.conn;
  983. MYSQLND_PACKET_GREET greet_packet;
  984. DBG_ENTER("mysqlnd_conn_data::connect_handshake");
  985. DBG_INF_FMT("stream=%p", conn->vio->data->m.get_stream(conn->vio));
  986. DBG_INF_FMT("[user=%s] [db=%s:%d] [flags=%llu]", user, db, db_len, mysql_flags);
  987. conn->payload_decoder_factory->m.init_greet_packet(&greet_packet);
  988. if (FAIL == PACKET_READ(conn, &greet_packet)) {
  989. DBG_ERR("Error while reading greeting packet");
  990. php_error_docref(NULL, E_WARNING, "Error while reading greeting packet. PID=%d", getpid());
  991. goto err;
  992. } else if (greet_packet.error_no) {
  993. DBG_ERR_FMT("errorno=%u error=%s", greet_packet.error_no, greet_packet.error);
  994. SET_CLIENT_ERROR(conn->error_info, greet_packet.error_no, greet_packet.sqlstate, greet_packet.error);
  995. goto err;
  996. } else if (greet_packet.pre41) {
  997. DBG_ERR_FMT("Connecting to 3.22, 3.23 & 4.0 is not supported. Server is %-.32s", greet_packet.server_version);
  998. php_error_docref(NULL, E_WARNING, "Connecting to 3.22, 3.23 & 4.0 "
  999. " is not supported. Server is %-.32s", greet_packet.server_version);
  1000. SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE,
  1001. "Connecting to 3.22, 3.23 & 4.0 servers is not supported");
  1002. goto err;
  1003. }
  1004. conn->thread_id = greet_packet.thread_id;
  1005. conn->protocol_version = greet_packet.protocol_version;
  1006. conn->server_version = mnd_pestrdup(greet_packet.server_version, conn->persistent);
  1007. conn->greet_charset = mysqlnd_find_charset_nr(greet_packet.charset_no);
  1008. if (!conn->greet_charset) {
  1009. php_error_docref(NULL, E_WARNING,
  1010. "Server sent charset (%d) unknown to the client. Please, report to the developers", greet_packet.charset_no);
  1011. SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE,
  1012. "Server sent charset unknown to the client. Please, report to the developers");
  1013. goto err;
  1014. }
  1015. conn->server_capabilities = greet_packet.server_capabilities;
  1016. if (FAIL == mysqlnd_connect_run_authentication(conn, user, passwd, db, db_len, (size_t) passwd_len,
  1017. greet_packet.authentication_plugin_data, greet_packet.auth_protocol,
  1018. greet_packet.charset_no, greet_packet.server_capabilities,
  1019. conn->options, mysql_flags))
  1020. {
  1021. goto err;
  1022. }
  1023. UPSERT_STATUS_RESET(conn->upsert_status);
  1024. UPSERT_STATUS_SET_SERVER_STATUS(conn->upsert_status, greet_packet.server_status);
  1025. PACKET_FREE(&greet_packet);
  1026. DBG_RETURN(PASS);
  1027. err:
  1028. conn->server_capabilities = 0;
  1029. PACKET_FREE(&greet_packet);
  1030. DBG_RETURN(FAIL);
  1031. }
  1032. /* }}} */
  1033. /* {{{ mysqlnd_com_handshake_run_command */
  1034. static enum_func_status
  1035. mysqlnd_com_handshake_run_command(va_list args)
  1036. {
  1037. struct st_mysqlnd_protocol_com_handshake_command command;
  1038. enum_func_status ret;
  1039. DBG_ENTER("mysqlnd_com_handshake_run_command");
  1040. command.context.conn = va_arg(args, MYSQLND_CONN_DATA *);
  1041. command.context.user = *va_arg(args, const MYSQLND_CSTRING *);
  1042. command.context.passwd = *va_arg(args, const MYSQLND_CSTRING *);
  1043. command.context.database = *va_arg(args, const MYSQLND_CSTRING *);
  1044. command.context.client_flags = va_arg(args, size_t);
  1045. ret = mysqlnd_com_handshake_run(&command);
  1046. DBG_RETURN(ret);
  1047. }
  1048. /* }}} */
  1049. /* {{{ _mysqlnd_run_command */
  1050. static enum_func_status
  1051. _mysqlnd_run_command(enum php_mysqlnd_server_command command, ...)
  1052. {
  1053. enum_func_status ret = FAIL;
  1054. va_list args;
  1055. DBG_ENTER("_mysqlnd_run_command");
  1056. va_start(args, command);
  1057. switch (command) {
  1058. case COM_SET_OPTION:
  1059. ret = mysqlnd_com_set_option_run_command(args);
  1060. break;
  1061. case COM_DEBUG:
  1062. ret = mysqlnd_com_debug_run_command(args);
  1063. break;
  1064. case COM_INIT_DB:
  1065. ret = mysqlnd_com_init_db_run_command(args);
  1066. break;
  1067. case COM_PING:
  1068. ret = mysqlnd_com_ping_run_command(args);
  1069. break;
  1070. case COM_STATISTICS:
  1071. ret = mysqlnd_com_statistics_run_command(args);
  1072. break;
  1073. case COM_PROCESS_KILL:
  1074. ret = mysqlnd_com_process_kill_run_command(args);
  1075. break;
  1076. case COM_REFRESH:
  1077. ret = mysqlnd_com_refresh_run_command(args);
  1078. break;
  1079. case COM_SHUTDOWN:
  1080. ret = mysqlnd_com_shutdown_run_command(args);
  1081. break;
  1082. case COM_QUIT:
  1083. ret = mysqlnd_com_quit_run_command(args);
  1084. break;
  1085. case COM_QUERY:
  1086. ret = mysqlnd_com_query_run_command(args);
  1087. break;
  1088. case COM_REAP_RESULT:
  1089. ret = mysqlnd_com_reap_result_run_command(args);
  1090. break;
  1091. case COM_CHANGE_USER:
  1092. ret = mysqlnd_com_change_user_run_command(args);
  1093. break;
  1094. case COM_STMT_PREPARE:
  1095. ret = mysqlnd_com_stmt_prepare_run_command(args);
  1096. break;
  1097. case COM_STMT_EXECUTE:
  1098. ret = mysqlnd_com_stmt_execute_run_command(args);
  1099. break;
  1100. case COM_STMT_FETCH:
  1101. ret = mysqlnd_com_stmt_fetch_run_command(args);
  1102. break;
  1103. case COM_STMT_RESET:
  1104. ret = mysqlnd_com_stmt_reset_run_command(args);
  1105. break;
  1106. case COM_STMT_SEND_LONG_DATA:
  1107. ret = mysqlnd_com_stmt_send_long_data_run_command(args);
  1108. break;
  1109. case COM_STMT_CLOSE:
  1110. ret = mysqlnd_com_stmt_close_run_command(args);
  1111. break;
  1112. case COM_ENABLE_SSL:
  1113. ret = mysqlnd_com_enable_ssl_run_command(args);
  1114. break;
  1115. case COM_HANDSHAKE:
  1116. ret = mysqlnd_com_handshake_run_command(args);
  1117. break;
  1118. default:
  1119. break;
  1120. }
  1121. va_end(args);
  1122. DBG_RETURN(ret);
  1123. }
  1124. /* }}} */
  1125. func_mysqlnd__run_command mysqlnd_run_command = _mysqlnd_run_command;
  1126. /*
  1127. * Local variables:
  1128. * tab-width: 4
  1129. * c-basic-offset: 4
  1130. * End:
  1131. * vim600: noet sw=4 ts=4 fdm=marker
  1132. * vim<600: noet sw=4 ts=4
  1133. */