From: Eric Leblond Date: Thu, 30 Apr 2015 09:08:47 +0000 (+0200) Subject: http-json: introduce JsonHttpAddMetadata function X-Git-Tag: suricata-3.0RC1~122 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bccabe3813627abfe4f7a77272d1b195a8115753;p=thirdparty%2Fsuricata.git http-json: introduce JsonHttpAddMetadata function This function will be usable in other logging components to add the http data to their messages. --- diff --git a/src/output-json-http.c b/src/output-json-http.c index 316419855a..bf926b2adf 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -396,6 +396,28 @@ static int JsonHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl SCReturnInt(TM_ECODE_OK); } +json_t *JsonHttpAddMetadata(const Flow *f) +{ + HtpState *htp_state = (HtpState *)FlowGetAppState(f); + if (htp_state) { + uint64_t tx_id = AppLayerParserGetTransactionLogId(f->alparser); + htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP, htp_state, tx_id); + + if (tx) { + json_t *hjs = json_object(); + if (unlikely(hjs == NULL)) + return NULL; + + JsonHttpLogJSONBasic(hjs, tx); + JsonHttpLogJSONExtended(hjs, tx); + + return hjs; + } + } + + return NULL; +} + static void OutputHttpLogDeinit(OutputCtx *output_ctx) { LogHttpFileCtx *http_ctx = output_ctx->data; diff --git a/src/output-json-http.h b/src/output-json-http.h index ab412d227c..b8fcea15be 100644 --- a/src/output-json-http.h +++ b/src/output-json-http.h @@ -29,6 +29,7 @@ void TmModuleJsonHttpLogRegister (void); #ifdef HAVE_LIBJANSSON void JsonHttpLogJSONBasic(json_t *js, htp_tx_t *tx); void JsonHttpLogJSONExtended(json_t *js, htp_tx_t *tx); +json_t *JsonHttpAddMetadata(const Flow *f); #endif /* HAVE_LIBJANSSON */ #endif /* __OUTPUT_JSON_HTTP_H__ */