]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http-json: introduce JsonHttpAddMetadata function
authorEric Leblond <eric@regit.org>
Thu, 30 Apr 2015 09:08:47 +0000 (11:08 +0200)
committerEric Leblond <eric@regit.org>
Fri, 2 Oct 2015 20:57:58 +0000 (22:57 +0200)
This function will be usable in other logging components to add
the http data to their messages.

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

index 316419855aa192d52975f02dbe5635490c0b6d6e..bf926b2adf94676eca4dba7f41831be0665d714e 100644 (file)
@@ -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;
index ab412d227c94de39c68cf551a1c950274ce38163..b8fcea15be0e3183b385b6c3d8c5c406339bffb9 100644 (file)
@@ -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__ */