61 lua_pushnil(luastate);
62 lua_pushstring(luastate, msg);
69 if (!lua_isstring(luastate, idx))
71 const char *
str = lua_tostring(luastate, idx);
81 lua_pushstring(luastate, key);
82 lua_pushnumber(luastate, value);
83 lua_settable(luastate, -3);
92 lua_pushstring(luastate, key);
93 lua_pushstring(luastate, value ? value :
"(null)");
94 lua_settable(luastate, -3);
99 lua_pushstring(luastate, key);
101 lua_settable(luastate, -3);
115 lua_pushlstring (luastate, (
const char *)b->
data, b->
data_len);
127 static int LuaCallbackStreamingBuffer(
lua_State *luastate)
133 return LuaCallbackStreamingBufferPushToStack(luastate, b);
136 static int LuaCallbackLogPath(
lua_State *luastate)
145 static int LuaCallbackLogDebug(
lua_State *luastate)
149 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
154 static int LuaCallbackLogInfo(
lua_State *luastate)
158 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
161 lua_getstack(luastate, 1, &ar);
162 lua_getinfo(luastate,
"nSl", &ar);
163 const char *funcname = ar.name ? ar.name : ar.what;
164 SCLogInfoRaw(ar.short_src, funcname, ar.currentline,
"%s", msg);
168 static int LuaCallbackLogNotice(
lua_State *luastate)
172 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
175 lua_getstack(luastate, 1, &ar);
176 lua_getinfo(luastate,
"nSl", &ar);
177 const char *funcname = ar.name ? ar.name : ar.what;
178 SCLogNoticeRaw(ar.short_src, funcname, ar.currentline,
"%s", msg);
182 static int LuaCallbackLogWarning(
lua_State *luastate)
186 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
189 lua_getstack(luastate, 1, &ar);
190 lua_getinfo(luastate,
"nSl", &ar);
191 const char *funcname = ar.name ? ar.name : ar.what;
196 static int LuaCallbackLogError(
lua_State *luastate)
200 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
202 lua_getstack(luastate, 1, &ar);
203 lua_getinfo(luastate,
"nSl", &ar);
204 const char *funcname = ar.name ? ar.name : ar.what;
205 SCLogErrorRaw(ar.short_src, funcname, ar.currentline,
"%s", msg);
219 static int LuaCallbackFileInfoPushToStackFromFile(
lua_State *luastate,
const File *file)
222 char *sha1ptr = NULL;
223 char *sha256ptr = NULL;
229 for (x = 0; x <
sizeof(file->
md5); x++) {
231 snprintf(one,
sizeof(one),
"%02x", file->
md5[x]);
232 strlcat(md5, one,
sizeof(md5));
239 for (x = 0; x <
sizeof(file->
sha1); x++) {
241 snprintf(one,
sizeof(one),
"%02x", file->
sha1[x]);
242 strlcat(sha1, one,
sizeof(sha1));
245 char sha256[65] =
"";
249 for (x = 0; x <
sizeof(file->
sha256); x++) {
251 snprintf(one,
sizeof(one),
"%02x", file->
sha256[x]);
252 strlcat(sha256, one,
sizeof(sha256));
258 lua_pushinteger(luastate, tx_id);
259 lua_pushlstring(luastate, (
char *)file->
name, file->
name_len);
261 lua_pushstring (luastate,
268 lua_pushstring(luastate, md5ptr);
269 lua_pushstring(luastate, sha1ptr);
270 lua_pushstring(luastate, sha256ptr);
278 static int LuaCallbackFileInfo(
lua_State *luastate)
284 return LuaCallbackFileInfoPushToStackFromFile(luastate, file);
295 static int LuaCallbackFileStatePushToStackFromFile(
lua_State *luastate,
const File *file)
297 const char *state =
"UNKNOWN";
298 switch (file->
state) {
318 lua_pushstring (luastate, state);
327 static int LuaCallbackFileState(
lua_State *luastate)
333 return LuaCallbackFileStatePushToStackFromFile(luastate, file);
347 lua_pushinteger (luastate, (lua_Integer)tid);
348 lua_pushstring (luastate,
tv->
name);
357 static int LuaCallbackThreadInfo(
lua_State *luastate)
363 return LuaCallbackThreadInfoPushToStackFromThreadVars(luastate,
tv);
369 lua_pushcfunction(luastate, LuaCallbackStreamingBuffer);
370 lua_setglobal(luastate,
"SCStreamingBuffer");
372 lua_pushcfunction(luastate, LuaCallbackLogPath);
373 lua_setglobal(luastate,
"SCLogPath");
375 lua_pushcfunction(luastate, LuaCallbackLogDebug);
376 lua_setglobal(luastate,
"SCLogDebug");
377 lua_pushcfunction(luastate, LuaCallbackLogInfo);
378 lua_setglobal(luastate,
"SCLogInfo");
379 lua_pushcfunction(luastate, LuaCallbackLogNotice);
380 lua_setglobal(luastate,
"SCLogNotice");
381 lua_pushcfunction(luastate, LuaCallbackLogWarning);
382 lua_setglobal(luastate,
"SCLogWarning");
383 lua_pushcfunction(luastate, LuaCallbackLogError);
384 lua_setglobal(luastate,
"SCLogError");
386 lua_pushcfunction(luastate, LuaCallbackFileInfo);
387 lua_setglobal(luastate,
"SCFileInfo");
388 lua_pushcfunction(luastate, LuaCallbackFileState);
389 lua_setglobal(luastate,
"SCFileState");
391 lua_pushcfunction(luastate, LuaCallbackThreadInfo);
392 lua_setglobal(luastate,
"SCThreadInfo");
405 return (alproto == flow_alproto);