From 710c7b821fcb919dfaa816f45a8b342acee622f4 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 2 Mar 2018 12:15:11 +0100 Subject: [PATCH] output/json: update callers to use explicit directions --- src/detect-engine-profile.c | 2 +- src/output-json-alert.c | 4 ++-- src/output-json-dnp3.c | 4 ++-- src/output-json-dns.c | 11 +++++------ src/output-json-drop.c | 5 +++-- src/output-json-file.c | 2 +- src/output-json-http.c | 2 +- src/output-json-metadata.c | 2 +- src/output-json-nfs.c | 5 ++--- src/output-json-smtp.c | 2 +- src/output-json-ssh.c | 2 +- src/output-json-template.c | 2 +- src/output-json-tftp.c | 2 +- src/output-json-tls.c | 2 +- 14 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/detect-engine-profile.c b/src/detect-engine-profile.c index fc43c3fd01..3b1d5cd782 100644 --- a/src/detect-engine-profile.c +++ b/src/detect-engine-profile.c @@ -60,7 +60,7 @@ SCMutex g_rule_dump_write_m = SCMUTEX_INITIALIZER; void RulesDumpMatchArray(const DetectEngineThreadCtx *det_ctx, const SigGroupHead *sgh, const Packet *p) { - json_t *js = CreateJSONHeader(p, 0, "inspectedrules"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "inspectedrules"); if (js == NULL) return; json_t *ir = json_object(); diff --git a/src/output-json-alert.c b/src/output-json-alert.c index b494823dec..59d818bc45 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -389,7 +389,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) if (p->alerts.cnt == 0 && !(p->flags & PKT_HAS_TAG)) return TM_ECODE_OK; - json_t *js = CreateJSONHeader(p, 0, "alert"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "alert"); if (unlikely(js == NULL)) return TM_ECODE_OK; @@ -589,7 +589,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags & LOG_JSON_TAGGED_PACKETS)) { MemBufferReset(aft->json_buffer); - json_t *packetjs = CreateJSONHeader(p, 0, "packet"); + json_t *packetjs = CreateJSONHeader(p, LOG_DIR_PACKET, "packet"); if (unlikely(packetjs != NULL)) { AlertJsonPacket(p, packetjs); OutputJSONBuffer(packetjs, aft->file_ctx, &aft->json_buffer); diff --git a/src/output-json-dnp3.c b/src/output-json-dnp3.c index a405dcc890..0f2fdd3cde 100644 --- a/src/output-json-dnp3.c +++ b/src/output-json-dnp3.c @@ -312,7 +312,7 @@ static int JsonDNP3LoggerToServer(ThreadVars *tv, void *thread_data, MemBufferReset(buffer); if (tx->has_request && tx->request_done) { - json_t *js = CreateJSONHeader(p, 1, "dnp3"); + json_t *js = CreateJSONHeader(p, LOG_DIR_FLOW, "dnp3"); if (unlikely(js == NULL)) { return TM_ECODE_OK; } @@ -341,7 +341,7 @@ static int JsonDNP3LoggerToClient(ThreadVars *tv, void *thread_data, MemBufferReset(buffer); if (tx->has_response && tx->response_done) { - json_t *js = CreateJSONHeader(p, 1, "dnp3"); + json_t *js = CreateJSONHeader(p, LOG_DIR_FLOW, "dnp3"); if (unlikely(js == NULL)) { return TM_ECODE_OK; } diff --git a/src/output-json-dns.c b/src/output-json-dns.c index 58d34b64e7..8920b1b288 100644 --- a/src/output-json-dns.c +++ b/src/output-json-dns.c @@ -663,7 +663,7 @@ static int JsonDnsLoggerToServer(ThreadVars *tv, void *thread_data, #ifdef HAVE_RUST for (uint16_t i = 0; i < 0xffff; i++) { - js = CreateJSONHeader(p, 1, "dns"); + js = CreateJSONHeader(p, LOG_DIR_PACKET, "dns"); if (unlikely(js == NULL)) { return TM_ECODE_OK; } @@ -684,7 +684,7 @@ static int JsonDnsLoggerToServer(ThreadVars *tv, void *thread_data, DNSTransaction *tx = txptr; DNSQueryEntry *query = NULL; TAILQ_FOREACH(query, &tx->query_list, next) { - js = CreateJSONHeader(p, 1, "dns"); + js = CreateJSONHeader(p, LOG_DIR_PACKET, "dns"); if (unlikely(js == NULL)) return TM_ECODE_OK; if (dnslog_ctx->include_metadata) { @@ -707,13 +707,14 @@ static int JsonDnsLoggerToClient(ThreadVars *tv, void *thread_data, LogDnsLogThread *td = (LogDnsLogThread *)thread_data; LogDnsFileCtx *dnslog_ctx = td->dnslog_ctx; - json_t *js; if (unlikely(dnslog_ctx->flags & LOG_ANSWERS) == 0) { return TM_ECODE_OK; } - js = CreateJSONHeader(p, 0, "dns"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "dns"); + if (unlikely(js == NULL)) + return TM_ECODE_OK; if (dnslog_ctx->include_metadata) { JsonAddMetadata(p, f, js); @@ -747,8 +748,6 @@ static int JsonDnsLoggerToClient(ThreadVars *tv, void *thread_data, } #else DNSTransaction *tx = txptr; - if (unlikely(js == NULL)) - return TM_ECODE_OK; LogAnswers(td, js, tx, tx_id); #endif diff --git a/src/output-json-drop.c b/src/output-json-drop.c index a84c9d6efc..653e82f50f 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -88,8 +88,8 @@ static int g_droplog_flows_start = 1; static int DropLogJSON (JsonDropLogThread *aft, const Packet *p) { JsonDropOutputCtx *drop_ctx = aft->drop_ctx; - uint16_t proto = 0; - json_t *js = CreateJSONHeader(p, 0, "drop"); + + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "drop"); if (unlikely(js == NULL)) return TM_ECODE_OK; @@ -106,6 +106,7 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p) /* reset */ MemBufferReset(aft->buffer); + uint16_t proto = 0; if (PKT_IS_IPV4(p)) { json_object_set_new(djs, "len", json_integer(IPV4_GET_IPLEN(p))); json_object_set_new(djs, "tos", json_integer(IPV4_GET_IPTOS(p))); diff --git a/src/output-json-file.c b/src/output-json-file.c index f00471adf8..8c9ff61792 100644 --- a/src/output-json-file.c +++ b/src/output-json-file.c @@ -81,7 +81,7 @@ typedef struct JsonFileLogThread_ { json_t *JsonBuildFileInfoRecord(const Packet *p, const File *ff, const bool stored) { - json_t *js = CreateJSONHeader(p, 0, "fileinfo"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "fileinfo"); json_t *hjs = NULL; if (unlikely(js == NULL)) return NULL; diff --git a/src/output-json-http.c b/src/output-json-http.c index ac8a9f34c9..7110e6b44e 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -452,7 +452,7 @@ static int JsonHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl htp_tx_t *tx = txptr; JsonHttpLogThread *jhl = (JsonHttpLogThread *)thread_data; - json_t *js = CreateJSONHeaderWithTxId(p, 1, "http", tx_id); + json_t *js = CreateJSONHeaderWithTxId(p, LOG_DIR_FLOW, "http", tx_id); if (unlikely(js == NULL)) return TM_ECODE_OK; diff --git a/src/output-json-metadata.c b/src/output-json-metadata.c index 370609b178..de918d3ea1 100644 --- a/src/output-json-metadata.c +++ b/src/output-json-metadata.c @@ -82,7 +82,7 @@ typedef struct JsonMetadataLogThread_ { static int MetadataJson(ThreadVars *tv, JsonMetadataLogThread *aft, const Packet *p) { - json_t *js = CreateJSONHeader(p, 0, "metadata"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "metadata"); if (unlikely(js == NULL)) return TM_ECODE_OK; diff --git a/src/output-json-nfs.c b/src/output-json-nfs.c index df614dc472..ba9f97abfa 100644 --- a/src/output-json-nfs.c +++ b/src/output-json-nfs.c @@ -94,12 +94,11 @@ static int JsonNFSLogger(ThreadVars *tv, void *thread_data, { NFSTransaction *nfstx = tx; LogNFSLogThread *thread = thread_data; - json_t *js, *nfsjs; if (rs_nfs_tx_logging_is_filtered(nfstx)) return TM_ECODE_OK; - js = CreateJSONHeader(p, 0, "nfs"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "nfs"); if (unlikely(js == NULL)) { return TM_ECODE_FAILED; } @@ -114,7 +113,7 @@ static int JsonNFSLogger(ThreadVars *tv, void *thread_data, } json_object_set_new(js, "rpc", rpcjs); - nfsjs = rs_nfs_log_json_response(state, tx); + json_t *nfsjs = rs_nfs_log_json_response(state, tx); if (unlikely(nfsjs == NULL)) { goto error; } diff --git a/src/output-json-smtp.c b/src/output-json-smtp.c index 264420b874..eb7cd283de 100644 --- a/src/output-json-smtp.c +++ b/src/output-json-smtp.c @@ -88,7 +88,7 @@ static int JsonSmtpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl SCEnter(); JsonEmailLogThread *jhl = (JsonEmailLogThread *)thread_data; - json_t *js = CreateJSONHeaderWithTxId(p, 1, "smtp", tx_id); + json_t *js = CreateJSONHeaderWithTxId(p, LOG_DIR_FLOW, "smtp", tx_id); if (unlikely(js == NULL)) return TM_ECODE_OK; diff --git a/src/output-json-ssh.c b/src/output-json-ssh.c index 2bbe4acd97..20b0191517 100644 --- a/src/output-json-ssh.c +++ b/src/output-json-ssh.c @@ -106,7 +106,7 @@ static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p, ssh_state->srv_hdr.software_version == NULL) return 0; - json_t *js = CreateJSONHeader(p, 1, "ssh"); + json_t *js = CreateJSONHeader(p, LOG_DIR_FLOW, "ssh"); if (unlikely(js == NULL)) return 0; diff --git a/src/output-json-template.c b/src/output-json-template.c index f59ec2baf4..38bb6b756a 100644 --- a/src/output-json-template.c +++ b/src/output-json-template.c @@ -74,7 +74,7 @@ static int JsonTemplateLogger(ThreadVars *tv, void *thread_data, SCLogNotice("Logging template transaction %"PRIu64".", templatetx->tx_id); - json_t *js = CreateJSONHeader(p, 0, "template"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "template"); if (unlikely(js == NULL)) { return TM_ECODE_FAILED; } diff --git a/src/output-json-tftp.c b/src/output-json-tftp.c index 6953917c11..ed6b73c35e 100644 --- a/src/output-json-tftp.c +++ b/src/output-json-tftp.c @@ -71,7 +71,7 @@ static int JsonTFTPLogger(ThreadVars *tv, void *thread_data, { LogTFTPLogThread *thread = thread_data; - json_t *js = CreateJSONHeader(p, 0, "tftp"); + json_t *js = CreateJSONHeader(p, LOG_DIR_PACKET, "tftp"); if (unlikely(js == NULL)) { return TM_ECODE_FAILED; } diff --git a/src/output-json-tls.c b/src/output-json-tls.c index 95a5f1f3dc..5c424c0d58 100644 --- a/src/output-json-tls.c +++ b/src/output-json-tls.c @@ -357,7 +357,7 @@ static int JsonTlsLogger(ThreadVars *tv, void *thread_data, const Packet *p, return 0; } - json_t *js = CreateJSONHeader(p, 1, "tls"); + json_t *js = CreateJSONHeader(p, LOG_DIR_FLOW, "tls"); if (unlikely(js == NULL)) { return 0; } -- 2.47.2