]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output/eve: Remove unused helper function
authorJeff Lucovsky <jeff@lucovsky.org>
Sat, 6 Jun 2020 18:06:43 +0000 (14:06 -0400)
committerVictor Julien <victor@inliniac.net>
Sun, 28 Jun 2020 12:16:21 +0000 (14:16 +0200)
This commit removes an unused helper function no longer required/used
after conversion to JsonBuilder.

src/output-json-ftp.c
src/output-json.c
src/output-json.h

index 3d5029da376562ff90753f9277d515504b6df827..04a908b9ca114f5f22a40cefe3a907e77859f21a 100644 (file)
@@ -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);
-    }
 }
 
 
index dd7467d0e9eb9b3d65d6b3cfe404f716bb1dcbfa..c159d3509d232c11e505b6c43e3f870f19351e67 100644 (file)
@@ -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;
index 4428aacd9d4915faf98c8d90cba949be53d68d7b..d8725695bf40dee8295f5d4e6fe1e0f94023c2f1 100644 (file)
@@ -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,