61 lua_pushnil(luastate);
62 lua_pushstring(luastate,
msg);
69 if (!lua_isstring(luastate, argc))
71 const char *
str = lua_tostring(luastate, argc);
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);
144 static int LuaCallbackRuleIdsPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
146 lua_pushinteger(luastate, s->
id);
147 lua_pushinteger(luastate, s->
rev);
148 lua_pushinteger(luastate, s->
gid);
159 static int LuaCallbackRuleIds(
lua_State *luastate)
168 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
170 return LuaCallbackRuleIdsPushToStackFromSignature(luastate, s);
181 static int LuaCallbackRuleActionPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
183 const char *action =
"";
194 lua_pushstring(luastate, action);
205 static int LuaCallbackRuleAction(
lua_State *luastate)
214 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
216 return LuaCallbackRuleActionPushToStackFromSignature(luastate, s);
227 static int LuaCallbackRuleMsgPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
229 lua_pushstring(luastate, s->
msg);
240 static int LuaCallbackRuleMsg(
lua_State *luastate)
249 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
251 return LuaCallbackRuleMsgPushToStackFromSignature(luastate, s);
262 static int LuaCallbackRuleClassPushToStackFromSignature(
lua_State *luastate,
const Signature *s)
265 lua_pushinteger(luastate, s->
prio);
276 static int LuaCallbackRuleClass(
lua_State *luastate)
285 return LuaCallbackError(luastate,
"internal error: no packet alert or signature");
287 return LuaCallbackRuleClassPushToStackFromSignature(luastate, s);
290 static int LuaCallbackLogPath(
lua_State *luastate)
299 static int LuaCallbackLogDebug(
lua_State *luastate)
303 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
308 static int LuaCallbackLogInfo(
lua_State *luastate)
312 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
315 lua_getstack(luastate, 1, &ar);
316 lua_getinfo(luastate,
"nSl", &ar);
317 const char *funcname = ar.name ? ar.name : ar.what;
322 static int LuaCallbackLogNotice(
lua_State *luastate)
326 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
329 lua_getstack(luastate, 1, &ar);
330 lua_getinfo(luastate,
"nSl", &ar);
331 const char *funcname = ar.name ? ar.name : ar.what;
336 static int LuaCallbackLogWarning(
lua_State *luastate)
340 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
343 lua_getstack(luastate, 1, &ar);
344 lua_getinfo(luastate,
"nSl", &ar);
345 const char *funcname = ar.name ? ar.name : ar.what;
350 static int LuaCallbackLogError(
lua_State *luastate)
354 return LuaCallbackError(luastate,
"1st argument missing, empty or wrong type");
356 lua_getstack(luastate, 1, &ar);
357 lua_getinfo(luastate,
"nSl", &ar);
358 const char *funcname = ar.name ? ar.name : ar.what;
373 static int LuaCallbackFileInfoPushToStackFromFile(
lua_State *luastate,
const File *file)
376 char *sha1ptr = NULL;
377 char *sha256ptr = NULL;
383 for (x = 0; x <
sizeof(file->
md5); x++) {
385 snprintf(one,
sizeof(one),
"%02x", file->
md5[x]);
386 strlcat(md5, one,
sizeof(md5));
393 for (x = 0; x <
sizeof(file->
sha1); x++) {
395 snprintf(one,
sizeof(one),
"%02x", file->
sha1[x]);
396 strlcat(sha1, one,
sizeof(sha1));
399 char sha256[65] =
"";
403 for (x = 0; x <
sizeof(file->
sha256); x++) {
405 snprintf(one,
sizeof(one),
"%02x", file->
sha256[x]);
406 strlcat(sha256, one,
sizeof(sha256));
412 lua_pushinteger(luastate, tx_id);
413 lua_pushlstring(luastate, (
char *)file->
name, file->
name_len);
415 lua_pushstring (luastate,
422 lua_pushstring(luastate, md5ptr);
423 lua_pushstring(luastate, sha1ptr);
424 lua_pushstring(luastate, sha256ptr);
432 static int LuaCallbackFileInfo(
lua_State *luastate)
438 return LuaCallbackFileInfoPushToStackFromFile(luastate, file);
449 static int LuaCallbackFileStatePushToStackFromFile(
lua_State *luastate,
const File *file)
451 const char *state =
"UNKNOWN";
452 switch (file->
state) {
472 lua_pushstring (luastate, state);
481 static int LuaCallbackFileState(
lua_State *luastate)
487 return LuaCallbackFileStatePushToStackFromFile(luastate, file);
501 lua_pushinteger (luastate, (lua_Integer)tid);
502 lua_pushstring (luastate,
tv->
name);
511 static int LuaCallbackThreadInfo(
lua_State *luastate)
517 return LuaCallbackThreadInfoPushToStackFromThreadVars(luastate,
tv);
523 lua_pushcfunction(luastate, LuaCallbackStreamingBuffer);
524 lua_setglobal(luastate,
"SCStreamingBuffer");
526 lua_pushcfunction(luastate, LuaCallbackLogPath);
527 lua_setglobal(luastate,
"SCLogPath");
529 lua_pushcfunction(luastate, LuaCallbackLogDebug);
530 lua_setglobal(luastate,
"SCLogDebug");
531 lua_pushcfunction(luastate, LuaCallbackLogInfo);
532 lua_setglobal(luastate,
"SCLogInfo");
533 lua_pushcfunction(luastate, LuaCallbackLogNotice);
534 lua_setglobal(luastate,
"SCLogNotice");
535 lua_pushcfunction(luastate, LuaCallbackLogWarning);
536 lua_setglobal(luastate,
"SCLogWarning");
537 lua_pushcfunction(luastate, LuaCallbackLogError);
538 lua_setglobal(luastate,
"SCLogError");
541 lua_pushcfunction(luastate, LuaCallbackRuleIds);
542 lua_setglobal(luastate,
"SCRuleIds");
543 lua_pushcfunction(luastate, LuaCallbackRuleAction);
544 lua_setglobal(luastate,
"SCRuleAction");
545 lua_pushcfunction(luastate, LuaCallbackRuleMsg);
546 lua_setglobal(luastate,
"SCRuleMsg");
547 lua_pushcfunction(luastate, LuaCallbackRuleClass);
548 lua_setglobal(luastate,
"SCRuleClass");
550 lua_pushcfunction(luastate, LuaCallbackFileInfo);
551 lua_setglobal(luastate,
"SCFileInfo");
552 lua_pushcfunction(luastate, LuaCallbackFileState);
553 lua_setglobal(luastate,
"SCFileState");
555 lua_pushcfunction(luastate, LuaCallbackThreadInfo);
556 lua_setglobal(luastate,
"SCThreadInfo");
569 return (alproto == flow_alproto);