]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
smtp-json: introduce function to output smtp data
authorEric Leblond <eric@regit.org>
Thu, 30 Apr 2015 11:28:49 +0000 (13:28 +0200)
committerEric Leblond <eric@regit.org>
Fri, 2 Oct 2015 20:57:58 +0000 (22:57 +0200)
src/output-json-smtp.c
src/output-json-smtp.h

index 9ebebca7e4a82518134a868b7dd3d11fb3d71246..255209571c4a4dc152582d14dbe7226866f751b4 100644 (file)
@@ -54,7 +54,7 @@
 #ifdef HAVE_LIBJANSSON
 #include <jansson.h>
 
-static json_t *JsonSmtpDataLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, void *state, void *vtx, uint64_t tx_id)
+static json_t *JsonSmtpDataLogger(const Flow *f, void *state, void *vtx, uint64_t tx_id)
 {
     json_t *sjs = json_object();
     SMTPTransaction *tx = vtx;
@@ -97,7 +97,7 @@ static int JsonSmtpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl
     /* reset */
     MemBufferReset(buffer);
 
-    sjs = JsonSmtpDataLogger(tv, thread_data, p, f, state, tx, tx_id);
+    sjs = JsonSmtpDataLogger(f, state, tx, tx_id);
     if (sjs) {
         json_object_set_new(js, "smtp", sjs);
     }
@@ -117,6 +117,21 @@ static int JsonSmtpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl
 
 }
 
+json_t *JsonSMTPAddMetadata(const Flow *f)
+{
+    SMTPState *smtp_state = (SMTPState *)FlowGetAppState(f);
+    if (smtp_state) {
+        uint64_t tx_id = AppLayerParserGetTransactionLogId(f->alparser);
+        SMTPTransaction *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_SMTP, smtp_state, tx_id);
+
+        if (tx) {
+            return JsonSmtpDataLogger(f, smtp_state, tx, tx_id);
+        }
+    }
+
+    return NULL;
+}
+
 static void OutputSmtpLogDeInitCtx(OutputCtx *output_ctx)
 {
     OutputJsonEmailCtx *email_ctx = output_ctx->data;
index d38187c706b83e25973c03d67d79fa5921f08788..5b3233abca9fd1af92e7a030241ab5a24788a64d 100644 (file)
@@ -25,5 +25,8 @@
 #define __OUTPUT_JSON_SMTP_H__
 
 void TmModuleJsonSmtpLogRegister (void);
+#ifdef HAVE_LIBJANSSON
+json_t *JsonSMTPAddMetadata(const Flow *f);
+#endif
 
 #endif /* __OUTPUT_JSON_SMTP_H__ */