{
/* 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;
}
}
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;
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;
}
}
}
+ 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) {
if (js_resplist) {
jb_free(js_resplist);
}
- if (js_respcode_list) {
- jb_free(js_respcode_list);
- }
}
-/* 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
/* 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;
-/* 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
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,