Add username and network address to newSession

The luafilter now provides the username and the network address of the
client for the newSession entry point.
This commit is contained in:
Markus Mäkelä
2016-12-22 11:56:45 +02:00
parent 47ac20adea
commit 5664321df0
2 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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.",