~jan-kneschke/mysql-proxy/packet-tracking-assertions

« back to all changes in this revision

Viewing changes to src/network-mysqld-lua.h

  • Committer: Kay Roepke
  • Author(s): Jan Kneschke
  • Date: 2008-01-23 22:00:28 UTC
  • Revision ID: kay@mysql.com-20080123220028-hq2xqb69apa75fnx
first round on mysql-shell based on the proxy code

this is mostly a verification if the proxy-code is flexible enough to handle 
all three scenarios of: client, server and forwarding (proxy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $%BEGINLICENSE%$
2
 
 Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
3
 
 
4
 
 This program is free software; you can redistribute it and/or
5
 
 modify it under the terms of the GNU General Public License as
6
 
 published by the Free Software Foundation; version 2 of the
7
 
 License.
8
 
 
9
 
 This program is distributed in the hope that it will be useful,
10
 
 but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
 
 GNU General Public License for more details.
13
 
 
14
 
 You should have received a copy of the GNU General Public License
15
 
 along with this program; if not, write to the Free Software
16
 
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17
 
 02110-1301  USA
18
 
 
19
 
 $%ENDLICENSE%$ */
20
 
#ifndef __NETWORK_MYSQLD_LUA__
21
 
#define __NETWORK_MYSQLD_LUA__
22
 
 
23
 
#include <lua.h>
24
 
 
25
 
#include "network-backend.h" /* query-status */
26
 
#include "network-injection.h" /* query-status */
27
 
 
28
 
#include "network-exports.h"
29
 
 
30
 
typedef enum {
31
 
        PROXY_NO_DECISION,
32
 
        PROXY_SEND_QUERY,
33
 
        PROXY_SEND_RESULT,
34
 
        PROXY_SEND_INJECTION,
35
 
        PROXY_IGNORE_RESULT       /** for read_query_result */
36
 
} network_mysqld_lua_stmt_ret;
37
 
 
38
 
typedef enum {
39
 
        REGISTER_CALLBACK_SUCCESS,
40
 
        REGISTER_CALLBACK_LOAD_FAILED,
41
 
        REGISTER_CALLBACK_EXECUTE_FAILED
42
 
} network_mysqld_register_callback_ret;
43
 
 
44
 
NETWORK_API int network_mysqld_con_getmetatable(lua_State *L);
45
 
NETWORK_API void network_mysqld_lua_init_global_fenv(lua_State *L);
46
 
 
47
 
NETWORK_API void network_mysqld_lua_setup_global(lua_State *L, chassis_private *g);
48
 
 
49
 
/**
50
 
 * Encapsulates injected queries information passed back from the a Lua callback function.
51
 
 * 
52
 
 * @todo Simplify this structure, it should be folded into network_mysqld_con_lua_t.
53
 
 */
54
 
struct network_mysqld_con_lua_injection {
55
 
        network_injection_queue *queries;       /**< An ordered list of queries we want to have executed. */
56
 
        int sent_resultset;                                     /**< Flag to make sure we send only one result back to the client. */
57
 
};
58
 
/**
59
 
 * Contains extra connection state used for Lua-based plugins.
60
 
 */
61
 
typedef struct {
62
 
        struct network_mysqld_con_lua_injection injected;       /**< A list of queries to send to the backend.*/
63
 
 
64
 
        lua_State *L;                  /**< The Lua interpreter state of the current connection. */
65
 
        int L_ref;                     /**< The reference into the lua_scope's registry (a global structure in the Lua interpreter) */
66
 
 
67
 
        network_backend_t *backend;
68
 
        int backend_ndx;               /**< [lua] index into the backend-array */
69
 
 
70
 
        gboolean connection_close;     /**< [lua] set by the lua code to close a connection */
71
 
 
72
 
        struct timeval interval;       /**< The interval to be used for evt_timer, currently unused. */
73
 
        struct event evt_timer;        /**< The event structure used to implement the timer callback, currently unused. */
74
 
 
75
 
        gboolean is_reconnecting;      /**< if true, critical messages concerning failed connect() calls are suppressed, as they are expected errors */
76
 
} network_mysqld_con_lua_t;
77
 
 
78
 
NETWORK_API network_mysqld_con_lua_t *network_mysqld_con_lua_new();
79
 
NETWORK_API void network_mysqld_con_lua_free(network_mysqld_con_lua_t *st);
80
 
 
81
 
/** be sure to include network-mysqld.h */
82
 
NETWORK_API network_mysqld_register_callback_ret network_mysqld_con_lua_register_callback(network_mysqld_con *con, const char *lua_script);
83
 
NETWORK_API int network_mysqld_con_lua_handle_proxy_response(network_mysqld_con *con, const char *lua_script);
84
 
 
85
 
#endif