From: Jeff Lucovsky Date: Sat, 6 Jun 2020 18:06:43 +0000 (-0400) Subject: output/eve: Remove unused helper function X-Git-Tag: suricata-6.0.0-beta1~318 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f19ab1013f3d260c23b1a2ca22394f305ae41ad;p=thirdparty%2Fsuricata.git output/eve: Remove unused helper function This commit removes an unused helper function no longer required/used after conversion to JsonBuilder. --- diff --git a/src/output-json-ftp.c b/src/output-json-ftp.c index 3d5029da37..04a908b9ca 100644 --- a/src/output-json-ftp.c +++ b/src/output-json-ftp.c @@ -63,12 +63,10 @@ static void JsonFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb) { /* Preallocate array objects to simplify failure case */ JsonBuilder *js_resplist = NULL; - JsonBuilder *js_respcode_list = NULL; if (!TAILQ_EMPTY(&tx->response_list)) { js_resplist = jb_new_array(); - js_respcode_list = jb_new_array(); - if (unlikely(js_resplist == NULL || js_respcode_list == NULL)) { + if (unlikely(js_resplist == NULL)) { goto fail; } } @@ -85,6 +83,7 @@ static void JsonFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb) int resp_code_cnt = 0; int resp_cnt = 0; FTPString *response; + bool is_cc_array_open = false; TAILQ_FOREACH(response, &tx->response_list, next) { /* handle multiple lines within the response, \r\n delimited */ uint8_t *where = response->str; @@ -96,7 +95,11 @@ static void JsonFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb) if (pos >= 3) { /* Gather the completion code if present */ if (isdigit(where[0]) && isdigit(where[1]) && isdigit(where[2])) { - jb_append_string_from_bytes(js_respcode_list, (const uint8_t *)where, 3); + if (!is_cc_array_open) { + jb_open_array(jb, "completion_code"); + is_cc_array_open = true; + } + jb_append_string_from_bytes(jb, (const uint8_t *)where, 3); resp_code_cnt++; offset = 4; } @@ -112,16 +115,14 @@ static void JsonFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb) } } + if (is_cc_array_open) { + jb_close(jb); + } if (resp_cnt) { jb_close(js_resplist); jb_set_object(jb, "reply", js_resplist); } jb_free(js_resplist); - if (resp_code_cnt) { - jb_close(js_respcode_list); - jb_set_object(jb, "completion_code", js_respcode_list); - } - jb_free(js_respcode_list); } if (tx->dyn_port) { @@ -149,9 +150,6 @@ fail: if (js_resplist) { jb_free(js_resplist); } - if (js_respcode_list) { - jb_free(js_respcode_list); - } } diff --git a/src/output-json.c b/src/output-json.c index dd7467d0e9..c159d3509d 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2018 Open Information Security Foundation +/* Copyright (C) 2007-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 @@ -135,23 +135,6 @@ json_t *SCJsonString(const char *val) /* Default Sensor ID value */ static int64_t sensor_id = -1; /* -1 = not defined */ -/** - * \brief Create a JSON string from a character sequence - * - * \param Pointer to character sequence - * \param Number of characters to use from the sequence - * \retval JSON object for the character sequence - */ -json_t *JsonAddStringN(const char *string, size_t size) -{ - char tmpbuf[size + 1]; - - memcpy(tmpbuf, string, size); - tmpbuf[size] = '\0'; - - return SCJsonString(tmpbuf); -} - void EveFileInfo(JsonBuilder *jb, const File *ff, const bool stored) { size_t filename_size = ff->name_len * 2 + 1; diff --git a/src/output-json.h b/src/output-json.h index 4428aacd9d..d8725695bf 100644 --- a/src/output-json.h +++ b/src/output-json.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2007-2013 Open Information Security Foundation +/* Copyright (C) 2007-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 @@ -119,7 +119,6 @@ typedef struct OutputJsonThreadCtx_ { json_t *SCJsonBool(int val); json_t *SCJsonString(const char *val); -json_t *JsonAddStringN(const char *string, size_t size); void SCJsonDecref(json_t *js); void JsonAddCommonOptions(const OutputJsonCommonSettings *cfg,