/** * check if the common case works */ void t_network_injection_new() { injection *inj; inj = injection_new(1, g_string_new("123")); g_assert(inj); injection_free(inj); }
/** * a NULL shouldn't cause problems */ void t_network_injection_new_null() { injection *inj; inj = injection_new(1, NULL); g_assert(inj); injection_free(inj); }
static network_mysqld_python_stmt_ret proxy_python_read_query_result(network_mysqld_con *con) { network_socket *send_sock = con->client; network_socket *recv_sock = con->server; injection *inj = NULL; network_mysqld_con_python_t *st = con->plugin_con_state; network_mysqld_python_stmt_ret ret = PROXY_NO_DECISION; GString *packet; /** * check if we want to forward the statement to the client * if not, clean the send-queue */ if (0 == st->injected.queries->length) return PROXY_NO_DECISION; if(!CHECK_FUNC(read_query_result)) return ret; inj = g_queue_pop_head(st->injected.queries); inj->result_queue = con->server->recv_queue->chunks; PyObject * injection_obj = Injection_New(inj); if(!injection_obj){ PyErr_Print(); network_mysqld_con_send_error(con->client, C("PyProxy: Failed to create injection object.")); con->state = CON_STATE_SEND_ERROR; return PROXY_SEND_RESULT; } PyObject *result = PyObject_CallFunctionObjArgs( GET_FUNC(read_query_result), st->proxy, injection_obj, NULL); Py_DECREF(injection_obj); GET_PYTHON_RESULT(read_query_result) if (!con->resultset_is_needed && (PROXY_NO_DECISION != ret)) { g_critical("%s: read_query_result() in %s tries to modify the resultset, " "but hasn't asked to buffer it in proxy.query.append(..., True). " "We ignore the change to the result-set.", G_STRLOC, con->config->python_script); ret = PROXY_NO_DECISION; } switch (ret) { case PROXY_SEND_RESULT: /* we can only replace the result, if we buffer it */ g_assert_cmpint(con->resultset_is_needed, ==, TRUE); while ((packet = g_queue_pop_head(recv_sock->recv_queue->chunks))) g_string_free(packet, TRUE); if (network_mysqld_con_python_handle_proxy_response(con, st->proxy)) if (!st->injected.sent_resultset) network_mysqld_con_send_error(con->client, C("(python) handling" " proxy.response failed, check error-log")); /* fall through */ case PROXY_NO_DECISION: if (!st->injected.sent_resultset) { // make sure we send only one result-set per client-query while ((packet = g_queue_pop_head(recv_sock->recv_queue->chunks))) network_mysqld_queue_append_raw(send_sock, send_sock->send_queue, packet); st->injected.sent_resultset++; break; } g_critical("%s.%d: got asked to send a resultset, but ignoring it as " "we already have sent %d resultset(s). injection-id: %d", __FILE__, __LINE__, st->injected.sent_resultset, inj->id); st->injected.sent_resultset++; /* fall through */ case PROXY_IGNORE_RESULT: /* trash the packets for the injection query */ if (!con->resultset_is_needed) { g_critical("%s: we tried to send more than one resultset to the " "client, but didn't had them buffered. Now the client " "is out of sync may have closed the connection on us. " "Please use proxy.queries.append(..., True) to fix this.", G_STRLOC); break; } while ((packet = g_queue_pop_head(recv_sock->recv_queue->chunks))) g_string_free(packet, TRUE); break; default: /* invalid return code */ g_message("%s.%d: return-code for read_query_result() was neither " "PROXY_SEND_RESULT or PROXY_IGNORE_RESULT, will ignore the result", __FILE__, __LINE__); while ((packet = g_queue_pop_head(send_sock->send_queue->chunks))) g_string_free(packet, TRUE); break; } injection_free(inj); return ret; }