From: Jeff Lucovsky Date: Thu, 2 Jul 2020 14:01:12 +0000 (-0400) Subject: output/tftp: Convert to JsonBuilder X-Git-Tag: suricata-6.0.0-beta1~280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c5c949cfa05e00a896fe6f61513f1d234cb7d24;p=thirdparty%2Fsuricata.git output/tftp: Convert to JsonBuilder This commit converts the TFTP logging mechanisms to JsonBuilder. --- diff --git a/rust/src/tftp/log.rs b/rust/src/tftp/log.rs index 45f68a7102..b4837036a1 100644 --- a/rust/src/tftp/log.rs +++ b/rust/src/tftp/log.rs @@ -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 @@ -17,19 +17,27 @@ // written by Clément Galland -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() } diff --git a/src/output-json-tftp.c b/src/output-json-tftp.c index dbad0ae4e7..2779f5073a 100644 --- a/src/output-json-tftp.c +++ b/src/output-json-tftp.c @@ -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; }