1
module("proxy.auto-config", package.seeall)
3
local tokenizer = require("proxy.tokenizer")
5
local function parse_value(fld, token)
9
if token.token_name == "TK_INTEGER" then
10
return (token.text ~= "0")
12
print("(auto-config) expected a number, got " .. token.token_name)
14
elseif t == "number" then
15
if token.token_name == "TK_INTEGER" then
16
return tonumber(token.text)
18
print("(auto-config) expected a number, got " .. token.token_name)
21
print("(auto-config) type: " .. t .. " isn't handled yet" )
28
-- handle script-options first
29
if cmd.type ~= proxy.COM_QUERY then return nil end
30
if cmd.query:sub(1, 3):upper() ~= "SET" then return nil end
32
local tokens = assert(tokenizer.tokenize(cmd.query))
33
local norm_query = tokenizer.normalize(tokens)
35
-- looks like a SET query
36
if tokens[1].token_name ~= "TK_SQL_SET" then return end
37
if tokens[2].token_name ~= "TK_LITERAL" or tokens[2].text:upper() ~= "GLOBAL" then return end
41
if tokens[3].token_name == "TK_LITERAL" and proxy.global.config[tokens[3].text] ~= nil then
42
if tokens[4].token_name == "TK_DOT" then
43
-- SET GLOBAL <scope>.<key> = <value>
44
if tokens[5].token_name == "TK_LITERAL" and proxy.global.config[tokens[3].text][tokens[5].text] ~= nil then
45
if tokens[6].token_name == "TK_EQ" then
46
-- next one is the value
47
local r = parse_value(proxy.global.config[tokens[3].text][tokens[5].text], tokens[7])
50
proxy.global.config[tokens[3].text][tokens[5].text] = r
59
if not is_ok then return end
62
type = proxy.MYSQLD_PACKET_OK
65
return proxy.PROXY_SEND_RESULT