63 static char g_waldo[PATH_MAX] =
"";
65 static int g_waldo_init = 0;
66 static int g_waldo_deinit = 0;
76 memset(op, 0x00,
sizeof(*op));
95 SCLogDebug(
"OutputRegisterFiledataLogger happy");
103 const uint8_t *data, uint32_t data_len, uint8_t
flags, uint8_t dir)
109 while (logger && store) {
119 logger = logger->
next;
130 const bool file_close,
const bool file_trunc,
const uint8_t dir)
134 for (ff = ffc->
head; ff != NULL; ff = ff->
next) {
135 uint8_t file_flags = call_flags;
138 FilemagicGlobalLookup(ff);
155 (file_trunc || file_close)) {
186 const uint8_t *data = NULL;
187 uint32_t data_len = 0;
193 const int file_logged = CallLoggers(tv, store, p, ff, data, data_len, file_flags, dir);
220 if (f == NULL || f->
alstate == NULL) {
249 static void LogFiledataLogLoadWaldo(
const char *path)
254 FILE *fp = fopen(path,
"r");
256 SCLogInfo(
"couldn't open waldo: %s", strerror(errno));
260 if (fgets(line, (
int)
sizeof(line), fp) != NULL) {
261 if (sscanf(line,
"%10u", &
id) == 1) {
276 static void LogFiledataLogStoreWaldo(
const char *path)
284 FILE *fp = fopen(path,
"w");
286 SCLogInfo(
"couldn't open waldo: %s", strerror(errno));
290 snprintf(line,
sizeof(line),
"%u\n",
SC_ATOMIC_GET(g_file_store_id));
291 if (fwrite(line, strlen(line), 1, fp) != 1) {
300 static TmEcode OutputFiledataLogThreadInit(
ThreadVars *tv,
const void *initdata,
void **data)
305 memset(td, 0x00,
sizeof(*td));
309 SCLogDebug(
"OutputFiledataLogThreadInit happy (*data %p)", *data);
318 memset(ts, 0x00,
sizeof(*ts));
323 if (td->
store == NULL) {
327 while (tmp->
next != NULL)
336 logger = logger->
next;
340 if (g_waldo_init == 0) {
348 if (!(strcmp(output->
val,
"file") == 0 || strcmp(output->
val,
"file-store") == 0))
354 SCLogDebug(
"file-store failed, lets try 'file'");
369 const char *s_default_log_dir = NULL;
372 const char *waldo = node->
val;
374 if (waldo != NULL && strlen(waldo) > 0) {
376 snprintf(g_waldo,
sizeof(g_waldo),
"%s", waldo);
378 snprintf(g_waldo,
sizeof(g_waldo),
"%s/%s", s_default_log_dir, waldo);
382 LogFiledataLogLoadWaldo(g_waldo);
397 while (logger && store) {
405 logger = logger->
next;
409 if (g_waldo_deinit == 0) {
410 if (strlen(g_waldo) > 0) {
412 LogFiledataLogStoreWaldo(g_waldo);
428 while (logger && store) {
433 logger = logger->
next;
441 OutputFiledataLogThreadDeinit, OutputFiledataLogExitPrintStats,
452 logger = next_logger;
#define OUTPUT_FILEDATA_FLAG_CLOSE
void OutputFiledataLoggerRegister(void)
#define PACKET_PROFILING_LOGGER_START(p, id)
#define TAILQ_FOREACH(var, head, field)
int OutputRegisterFiledataLogger(LoggerId id, const char *name, FiledataLogger LogFunc, OutputCtx *output_ctx, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats)
int StreamingBufferGetDataAtOffset(const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t offset)
void(* ThreadExitPrintStatsFunc)(ThreadVars *, void *)
uint64_t FileDataSize(const File *file)
get the size of the file data
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
OutputLoggerThreadStore * store
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
struct OutputFiledataLogger_ OutputFiledataLogger
ThreadDeinitFunc ThreadDeinit
struct OutputFiledataLogger_ * next
void OutputFiledataShutdown(void)
TmEcode(* ThreadDeinitFunc)(ThreadVars *, void *)
#define SC_ATOMIC_INIT(name)
Initialize the previously declared atomic variable and it's lock.
#define SCMutexUnlock(mut)
#define SCMUTEX_INITIALIZER
struct OutputLoggerThreadStore_ * next
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
void OutputRegisterRootLogger(ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats, OutputLogFunc LogFunc)
SC_ATOMIC_DECLARE(unsigned int, g_file_store_id)
#define FLOW_PKT_TOSERVER
#define PKT_PSEUDO_STREAM_END
int PathIsAbsolute(const char *path)
Check if a path is absolute.
ThreadExitPrintStatsFunc ThreadExitPrintStats
int(* FiledataLogger)(ThreadVars *, void *thread_data, const Packet *, File *, const uint8_t *, uint32_t, uint8_t, uint8_t dir)
const char * ConfigGetLogDirectory()
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
#define SC_ATOMIC_CAS(name, cmpval, newval)
atomic Compare and Switch
struct OutputLoggerThreadStore_ OutputLoggerThreadStore
struct OutputLoggerThreadData_ OutputLoggerThreadData
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
ThreadInitFunc ThreadInit
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
Per thread variable structure.
int StreamTcpReassembleDepthReached(Packet *p)
check if stream in pkt direction has depth reached
TmEcode(* ThreadInitFunc)(ThreadVars *, const void *, void **)
#define FLOW_PKT_TOCLIENT
AppProto alproto
application level protocol
#define PACKET_PROFILING_LOGGER_END(p, id)
FileContainer * AppLayerParserGetFiles(uint8_t ipproto, AppProto alproto, void *alstate, uint8_t direction)
#define OUTPUT_FILEDATA_FLAG_OPEN
int FileCloseFilePtr(File *ff, const uint8_t *data, uint32_t data_len, uint16_t flags)
#define DEBUG_VALIDATE_BUG_ON(exp)