MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / client_mpvio_read_packet

Function client_mpvio_read_packet

sql-common/client.c:2791–2841  ·  view source on GitHub ↗

vio->read_packet() callback method for client authentication plugins This function is called by a client authentication plugin, when it wants to read data from the server. */

Source from the content-addressed store, hash-verified

2789 to read data from the server.
2790*/
2791static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf)
2792{
2793 MCPVIO_EXT *mpvio= (MCPVIO_EXT*)mpv;
2794 MYSQL *mysql= mpvio->mysql;
2795 ulong pkt_len;
2796
2797 /* there are cached data left, feed it to a plugin */
2798 if (mpvio->cached_server_reply.pkt)
2799 {
2800 *buf= mpvio->cached_server_reply.pkt;
2801 mpvio->cached_server_reply.pkt= 0;
2802 mpvio->packets_read++;
2803 return mpvio->cached_server_reply.pkt_len;
2804 }
2805
2806 if (mpvio->packets_read == 0)
2807 {
2808 /*
2809 the server handshake packet came from the wrong plugin,
2810 or it's mysql_change_user(). Either way, there is no data
2811 for a plugin to read. send a dummy packet to the server
2812 to initiate a dialog.
2813 */
2814 if (client_mpvio_write_packet(mpv, 0, 0))
2815 return (int)packet_error;
2816 }
2817
2818 /* otherwise read the data */
2819 pkt_len= (*mysql->methods->read_change_user_result)(mysql);
2820 mpvio->last_read_packet_len= pkt_len;
2821 *buf= mysql->net.read_pos;
2822
2823 /* was it a request to change plugins ? */
2824 if (**buf == 254)
2825 return (int)packet_error; /* if yes, this plugin shan't continue */
2826
2827 /*
2828 the server sends \1\255 or \1\254 instead of just \255 or \254 -
2829 for us to not confuse it with an error or "change plugin" packets.
2830 We remove this escaping \1 here.
2831
2832 See also server_mpvio_write_packet() where the escaping is done.
2833 */
2834 if (pkt_len && **buf == 1)
2835 {
2836 (*buf)++;
2837 pkt_len--;
2838 }
2839 mpvio->packets_read++;
2840 return pkt_len;
2841}
2842
2843/**
2844 vio->write_packet() callback method for client authentication plugins

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected