output-lua: add SCLogPath callback

Add a lua callback for getting Suricata's log path, so that lua scripts
can easily get the logging directory Suricata uses.

Update the Setup logic to register callbacks before the scripts 'setup'
is called.

Example:

    name = "fast_lua.log"
    function setup (args)
        filename = SCLogPath() .. "/" .. name
        file = assert(io.open(filename, "a"))
    end
pull/1112/head
Victor Julien 12 years ago
parent 31eea0f143
commit 1e836be3d8

@ -232,11 +232,22 @@ static int LuaCallbackTuple(lua_State *luastate)
return LuaCallbackTuplePushToStackFromPacket(luastate, p);
}
static int LuaCallbackLogPath(lua_State *luastate)
{
const char *ld = ConfigGetLogDirectory();
if (ld == NULL)
return LuaCallbackError(luastate, "internal error: no log dir");
return LuaReturnStringBuffer(luastate, (const uint8_t *)ld, strlen(ld));
}
int LogLuaRegisterFunctions(lua_State *luastate)
{
/* registration of the callbacks */
lua_pushcfunction(luastate, LuaCallbackTuple);
lua_setglobal(luastate, "SCPacketTuple");
lua_pushcfunction(luastate, LuaCallbackLogPath);
lua_setglobal(luastate, "SCLogPath");
return 0;
}

@ -433,17 +433,17 @@ static lua_State *LuaScriptSetup(const char *filename)
lua_getglobal(luastate, "setup");
if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1));
goto error;
}
/* register functions common to all */
LogLuaRegisterFunctions(luastate);
/* unconditionally register http function. They will only work
* if the tx is registered in the state at runtime though. */
LogLuaRegisterHttpFunctions(luastate);
if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError(SC_ERR_LUAJIT_ERROR, "couldn't run script 'setup' function: %s", lua_tostring(luastate, -1));
goto error;
}
SCLogDebug("lua_State %p is set up", luastate);
return luastate;
error:

Loading…
Cancel
Save