diff --git a/Documentation/Filters/Luafilter.md b/Documentation/Filters/Luafilter.md index 3e21662d7..4bb2b2847 100644 --- a/Documentation/Filters/Luafilter.md +++ b/Documentation/Filters/Luafilter.md @@ -38,10 +38,11 @@ The entry points for the Lua script expect the following signatures: - The global script will be loaded in this function and executed once on a global level before calling the createInstance function in the Lua script. - - `nil newSession()` - new session is created + - `nil newSession(string, string)` - new session is created - - This function first loads the session script and executes in on a global - level. After this, the newSession function in the Lua scripts is called. + - After the session script is loaded, the newSession function in the Lua + scripts is called. The first parameter is the username of the client and + the second parameter is the client's network address. - `nil closeSession()` - session is closed diff --git a/server/modules/filter/luafilter/luafilter.c b/server/modules/filter/luafilter/luafilter.c index f6a17d96e..fcf19209a 100644 --- a/server/modules/filter/luafilter/luafilter.c +++ b/server/modules/filter/luafilter/luafilter.c @@ -18,7 +18,7 @@ * * The entry points for the Lua script expect the following signatures: * * nil createInstance() - global script only - * * nil newSession() + * * nil newSession(string, string) * * nil closeSession() * * (nil | bool | string) routeQuery(string) * * nil clientReply() @@ -360,8 +360,10 @@ static void * newSession(FILTER *instance, SESSION *session) /** Call the newSession entry point */ lua_getglobal(my_session->lua_state, "newSession"); + lua_pushstring(my_session->lua_state, session->client_dcb->user); + lua_pushstring(my_session->lua_state, session->client_dcb->remote); - if (lua_pcall(my_session->lua_state, 0, 0, 0)) + if (lua_pcall(my_session->lua_state, 2, 0, 0)) { MXS_WARNING("luafilter: Failed to get global variable 'newSession': '%s'." " The newSession entry point will not be called.", @@ -376,8 +378,10 @@ static void * newSession(FILTER *instance, SESSION *session) spinlock_acquire(&my_instance->lock); lua_getglobal(my_instance->global_lua_state, "newSession"); + lua_pushstring(my_instance->global_lua_state, session->client_dcb->user); + lua_pushstring(my_instance->global_lua_state, session->client_dcb->remote); - if (lua_pcall(my_instance->global_lua_state, 0, 0, 0)) + if (lua_pcall(my_instance->global_lua_state, 2, 0, 0)) { MXS_WARNING("luafilter: Failed to get global variable 'newSession': '%s'." " The newSession entry point will not be called for the global script.",