Lines 1-93
Link Here
|
1 |
--- src/network-injection-lua.c.orig 2009-06-30 22:47:39.000000000 +0600 |
|
|
2 |
+++ src/network-injection-lua.c 2009-11-17 09:39:32.000000000 +0500 |
3 |
@@ -33,17 +33,18 @@ |
4 |
#define TIME_DIFF_US(t2, t1) \ |
5 |
((t2.tv_sec - t1.tv_sec) * 1000000.0 + (t2.tv_usec - t1.tv_usec)) |
6 |
|
7 |
+typedef enum { |
8 |
+ PROXY_QUEUE_ADD_PREPEND, |
9 |
+ PROXY_QUEUE_ADD_APPEND |
10 |
+} proxy_queue_add_t; |
11 |
|
12 |
/** |
13 |
- * proxy.queries:append(id, packet[, { options }]) |
14 |
+ * handle _append() and _prepend() |
15 |
* |
16 |
- * id: opaque numeric id (numeric) |
17 |
- * packet: mysql packet to append (string) FIXME: support table for multiple packets |
18 |
- * options: table of options (table) |
19 |
- * backend_ndx: backend_ndx to send it to (numeric) |
20 |
- * resultset_is_needed: expose the result-set into lua (bool) |
21 |
+ * _append() and _prepend() have the same behaviour, parameters, ... |
22 |
+ * just different in position |
23 |
*/ |
24 |
-static int proxy_queue_append(lua_State *L) { |
25 |
+static int proxy_queue_add(lua_State *L, proxy_queue_add_t type) { |
26 |
GQueue *q = *(GQueue **)luaL_checkself(L); |
27 |
int resp_type = luaL_checkinteger(L, 2); |
28 |
size_t str_len; |
29 |
@@ -68,7 +69,12 @@ |
30 |
} else if (lua_isboolean(L, -1)) { |
31 |
inj->resultset_is_needed = lua_toboolean(L, -1); |
32 |
} else { |
33 |
- luaL_argerror(L, 4, ":append(..., { resultset_is_needed = boolean } ), is %s"); |
34 |
+ switch (type) { |
35 |
+ case PROXY_QUEUE_ADD_APPEND: |
36 |
+ return luaL_argerror(L, 4, ":append(..., { resultset_is_needed = boolean } ), is %s"); |
37 |
+ case PROXY_QUEUE_ADD_PREPEND: |
38 |
+ return luaL_argerror(L, 4, ":prepend(..., { resultset_is_needed = boolean } ), is %s"); |
39 |
+ } |
40 |
} |
41 |
|
42 |
lua_pop(L, 1); |
43 |
@@ -78,25 +84,34 @@ |
44 |
luaL_typerror(L, 4, "table"); |
45 |
break; |
46 |
} |
47 |
- |
48 |
- network_injection_queue_append(q, inj); |
49 |
- |
50 |
- return 0; |
51 |
+ |
52 |
+ switch (type) { |
53 |
+ case PROXY_QUEUE_ADD_APPEND: |
54 |
+ network_injection_queue_append(q, inj); |
55 |
+ return 0; |
56 |
+ case PROXY_QUEUE_ADD_PREPEND: |
57 |
+ network_injection_queue_prepend(q, inj); |
58 |
+ return 0; |
59 |
+ } |
60 |
+ |
61 |
+ g_assert_not_reached(); |
62 |
+} |
63 |
+ |
64 |
+/** |
65 |
+ * proxy.queries:append(id, packet[, { options }]) |
66 |
+ * |
67 |
+ * id: opaque numeric id (numeric) |
68 |
+ * packet: mysql packet to append (string) FIXME: support table for multiple packets |
69 |
+ * options: table of options (table) |
70 |
+ * backend_ndx: backend_ndx to send it to (numeric) |
71 |
+ * resultset_is_needed: expose the result-set into lua (bool) |
72 |
+ */ |
73 |
+static int proxy_queue_append(lua_State *L) { |
74 |
+ return proxy_queue_add(L, PROXY_QUEUE_ADD_APPEND); |
75 |
} |
76 |
|
77 |
static int proxy_queue_prepend(lua_State *L) { |
78 |
- /* we expect 2 parameters */ |
79 |
- GQueue *q = *(GQueue **)luaL_checkself(L); |
80 |
- int resp_type = luaL_checkinteger(L, 2); |
81 |
- size_t str_len; |
82 |
- const char *str = luaL_checklstring(L, 3, &str_len); |
83 |
- |
84 |
- GString *query = g_string_sized_new(str_len); |
85 |
- g_string_append_len(query, str, str_len); |
86 |
- |
87 |
- network_injection_queue_prepend(q, injection_new(resp_type, query)); |
88 |
- |
89 |
- return 0; |
90 |
+ return proxy_queue_add(L, PROXY_QUEUE_ADD_PREPEND); |
91 |
} |
92 |
|
93 |
static int proxy_queue_reset(lua_State *L) { |