]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output/tftp: Convert to JsonBuilder 5133/head
authorJeff Lucovsky <jeff@lucovsky.org>
Thu, 2 Jul 2020 14:01:12 +0000 (10:01 -0400)
committerVictor Julien <victor@inliniac.net>
Mon, 6 Jul 2020 17:06:43 +0000 (19:06 +0200)
This commit converts the TFTP logging mechanisms to JsonBuilder.

rust/src/tftp/log.rs
src/output-json-tftp.c

index 45f68a7102bd1d1c7c49dbe904eed2e78a21481d..b4837036a156f17e6dab45407f5be8104900be06 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017 Open Information Security Foundation
+/* Copyright (C) 2017-2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
 
 // written by ClĂ©ment Galland <clement.galland@epita.fr>
 
-use crate::json::*;
-use crate::tftp::tftp::*;
+use crate::jsonbuilder::{JsonBuilder, JsonError};
+use crate::tftp::tftp::TFTPTransaction;
 
-#[no_mangle]
-pub extern "C" fn rs_tftp_log_json_request(tx: &mut TFTPTransaction) -> *mut JsonT
+fn tftp_log_request(tx: &mut TFTPTransaction,
+                    jb: &mut JsonBuilder)
+                    -> Result<(), JsonError>
 {
-    let js = Json::object();
     match tx.opcode {
-        1 => js.set_string("packet", "read"),
-        2 => js.set_string("packet", "write"),
-        _ => js.set_string("packet", "error")
+        1 => jb.set_string("packet", "read")?,
+        2 => jb.set_string("packet", "write")?,
+        _ => jb.set_string("packet", "error")?
     };
-    js.set_string("file", tx.filename.as_str());
-    js.set_string("mode", tx.mode.as_str());
-    js.unwrap()
+    jb.set_string("file", tx.filename.as_str())?;
+    jb.set_string("mode", tx.mode.as_str())?;
+    Ok(())
+}
+
+#[no_mangle]
+pub extern "C" fn rs_tftp_log_json_request(tx: &mut TFTPTransaction,
+                                           jb: &mut JsonBuilder)
+                                           -> bool
+{
+    tftp_log_request(tx, jb).is_ok()
 }
index dbad0ae4e72f946585e65e145e45aaed9043bdd5..2779f5073a2dda9667b2736ec55d5e6e8a2f8054 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2017 Open Information Security Foundation
+/* Copyright (C) 2020 Open Information Security Foundation
  *
  * You can copy, redistribute or modify this Program under the terms of
  * the GNU General Public License version 2 as published by the Free
@@ -67,27 +67,26 @@ static int JsonTFTPLogger(ThreadVars *tv, void *thread_data,
 {
     LogTFTPLogThread *thread = thread_data;
 
-    json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "tftp", NULL);
-    if (unlikely(js == NULL)) {
+    JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "tftp", NULL);
+    if (unlikely(jb == NULL)) {
         return TM_ECODE_FAILED;
     }
 
-    json_t *tftpjs = rs_tftp_log_json_request(tx);
-    if (unlikely(tftpjs == NULL)) {
+    jb_open_object(jb, "tftp");
+    if (unlikely(!rs_tftp_log_json_request(tx, jb))) {
         goto error;
     }
+    jb_close(jb);
 
-    json_object_set_new(js, "tftp", tftpjs);
-
-    JsonAddCommonOptions(&thread->tftplog_ctx->cfg, p, f, js);
+    EveAddCommonOptions(&thread->tftplog_ctx->cfg, p, f, jb);
     MemBufferReset(thread->buffer);
-    OutputJSONBuffer(js, thread->tftplog_ctx->file_ctx, &thread->buffer);
+    OutputJsonBuilderBuffer(jb, thread->tftplog_ctx->file_ctx, &thread->buffer);
 
-    json_decref(js);
+    jb_free(jb);
     return TM_ECODE_OK;
 
 error:
-    json_decref(js);
+    jb_free(jb);
     return TM_ECODE_FAILED;
 }