//初始化
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_init) {
network_mysqld_con_lua_t*st = con->plugin_con_state;
st=network_mysqld_con_lua_new();
con->plugin_con_state =st;
con->state =CON_STATE_CONNECT_SERVER;returnNETWORK_SOCKET_SUCCESS;
}//连接backend, 就是准备些随机挑战数, 用于连接real mysql 用
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_connect_server) {
con->state =CON_STATE_SEND_HANDSHAKE;
}//读取client发来的验证信息
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_auth) {
con->state =CON_STATE_SEND_AUTH_RESULT;
}
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query) {
network_injection_queue_reset(st->injected.queries);
sqls=sql_parse(con, tokens);for (i = 0; i < sqls->len; ++i) {
inj= injection_new(id, sqls->pdata[i]);
inj->resultset_is_needed =TRUE;
g_queue_push_tail(st->injected.queries, inj);
}
inj= g_queue_peek_head(st->injected.queries);
network_mysqld_queue_reset(send_sock);
network_mysqld_queue_append(send_sock, send_sock->send_queue, S(inj->query));
con->state =CON_STATE_SEND_QUERY;
}
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_read_query_result) {if (0 != st->injected.queries->length) {//在读取server返回数据时, 弹出st->injected.queries的头元素
inj = g_queue_pop_head(st->injected.queries);
con->state =CON_STATE_READ_QUERY;
}
}//如果st->injected.queries队列中无数据, 设置状态为CON_STATE_READ_QUERY, 读取client 的新sql//否则, 继续向server发送队列中的sql
NETWORK_MYSQLD_PLUGIN_PROTO(proxy_send_query_result) {if (st->injected.queries->length == 0) {
con->state =CON_STATE_READ_QUERY;returnNETWORK_SOCKET_SUCCESS;
}//发送给client后, 将st->injected.queries的头元素 放到send_queue中
inj = g_queue_peek_head(st->injected.queries);
network_mysqld_queue_reset(send_sock);
network_mysqld_queue_append(send_sock, send_sock->send_queue, S(inj->query));
con->state =CON_STATE_SEND_QUERY;returnNETWORK_SOCKET_SUCCESS;
}