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:
@ -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
|
- 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.
|
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
|
- After the session script is loaded, the newSession function in the Lua
|
||||||
level. After this, the newSession function in the Lua scripts is called.
|
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
|
- `nil closeSession()` - session is closed
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
*
|
*
|
||||||
* The entry points for the Lua script expect the following signatures:
|
* The entry points for the Lua script expect the following signatures:
|
||||||
* * nil createInstance() - global script only
|
* * nil createInstance() - global script only
|
||||||
* * nil newSession()
|
* * nil newSession(string, string)
|
||||||
* * nil closeSession()
|
* * nil closeSession()
|
||||||
* * (nil | bool | string) routeQuery(string)
|
* * (nil | bool | string) routeQuery(string)
|
||||||
* * nil clientReply()
|
* * nil clientReply()
|
||||||
@ -360,8 +360,10 @@ static void * newSession(FILTER *instance, SESSION *session)
|
|||||||
|
|
||||||
/** Call the newSession entry point */
|
/** Call the newSession entry point */
|
||||||
lua_getglobal(my_session->lua_state, "newSession");
|
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'."
|
MXS_WARNING("luafilter: Failed to get global variable 'newSession': '%s'."
|
||||||
" The newSession entry point will not be called.",
|
" The newSession entry point will not be called.",
|
||||||
@ -376,8 +378,10 @@ static void * newSession(FILTER *instance, SESSION *session)
|
|||||||
spinlock_acquire(&my_instance->lock);
|
spinlock_acquire(&my_instance->lock);
|
||||||
|
|
||||||
lua_getglobal(my_instance->global_lua_state, "newSession");
|
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'."
|
MXS_WARNING("luafilter: Failed to get global variable 'newSession': '%s'."
|
||||||
" The newSession entry point will not be called for the global script.",
|
" The newSession entry point will not be called for the global script.",
|
||||||
|
|||||||
Reference in New Issue
Block a user