]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: minor cleanups for output-json-http
authorPhilippe Antoine <pantoine@oisf.net>
Fri, 24 Jan 2025 16:37:29 +0000 (17:37 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 28 Jan 2025 08:32:43 +0000 (09:32 +0100)
In preparation of libhtp rust

Mainly using htp_header_value_ptr and htp_header_value_len
when possible

src/output-json-http.c

index 38cf2e494d4b309d3b34eb4ad24c3d6cdb45a178..1f39cec0a51c31d312d0dc53880e29a710e07ebf 100644 (file)
@@ -220,39 +220,40 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
 
     if (htp_tx_request_headers(tx) != NULL) {
         /* user agent */
-        htp_header_t *h_user_agent = htp_tx_request_header(tx, "user-agent");
+        const htp_header_t *h_user_agent = htp_tx_request_header(tx, "user-agent");
         if (h_user_agent != NULL) {
-            jb_set_string_from_bytes(js, "http_user_agent", bstr_ptr(h_user_agent->value),
-                    (uint32_t)bstr_len(h_user_agent->value));
+            jb_set_string_from_bytes(js, "http_user_agent", htp_header_value_ptr(h_user_agent),
+                    (uint32_t)htp_header_value_len(h_user_agent));
         }
 
         /* x-forwarded-for */
-        htp_header_t *h_x_forwarded_for = htp_tx_request_header(tx, "x-forwarded-for");
+        const htp_header_t *h_x_forwarded_for = htp_tx_request_header(tx, "x-forwarded-for");
         if (h_x_forwarded_for != NULL) {
-            jb_set_string_from_bytes(js, "xff", bstr_ptr(h_x_forwarded_for->value),
-                    (uint32_t)bstr_len(h_x_forwarded_for->value));
+            jb_set_string_from_bytes(js, "xff", htp_header_value_ptr(h_x_forwarded_for),
+                    (uint32_t)htp_header_value_len(h_x_forwarded_for));
         }
     }
 
     /* content-type */
     if (htp_tx_response_headers(tx) != NULL) {
-        htp_header_t *h_content_type = htp_tx_response_header(tx, "content-type");
+        const htp_header_t *h_content_type = htp_tx_response_header(tx, "content-type");
         if (h_content_type != NULL) {
-            const size_t size = bstr_len(h_content_type->value) * 2 + 1;
+            const size_t size = htp_header_value_len(h_content_type) * 2 + 1;
             char string[size];
-            BytesToStringBuffer(bstr_ptr(h_content_type->value), bstr_len(h_content_type->value), string, size);
+            BytesToStringBuffer(htp_header_value_ptr(h_content_type),
+                    htp_header_value_len(h_content_type), string, size);
             char *p = strchr(string, ';');
             if (p != NULL)
                 *p = '\0';
             jb_set_string(js, "http_content_type", string);
         }
-        htp_header_t *h_content_range = htp_tx_response_header(tx, "content-range");
+        const htp_header_t *h_content_range = htp_tx_response_header(tx, "content-range");
         if (h_content_range != NULL) {
             jb_open_object(js, "content_range");
-            jb_set_string_from_bytes(js, "raw", bstr_ptr(h_content_range->value),
-                    (uint32_t)bstr_len(h_content_range->value));
+            jb_set_string_from_bytes(js, "raw", htp_header_value_ptr(h_content_range),
+                    (uint32_t)htp_header_value_len(h_content_range));
             HTTPContentRange crparsed;
-            if (HTPParseContentRange(h_content_range->value, &crparsed) == 0) {
+            if (HTPParseContentRange(htp_header_value(h_content_range), &crparsed) == 0) {
                 if (crparsed.start >= 0)
                     jb_set_uint(js, "start", crparsed.start);
                 if (crparsed.end >= 0)
@@ -268,13 +269,13 @@ static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
 static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
 {
     /* referer */
-    htp_header_t *h_referer = NULL;
+    const htp_header_t *h_referer = NULL;
     if (htp_tx_request_headers(tx) != NULL) {
         h_referer = htp_tx_request_header(tx, "referer");
     }
     if (h_referer != NULL) {
-        jb_set_string_from_bytes(
-                js, "http_refer", bstr_ptr(h_referer->value), (uint32_t)bstr_len(h_referer->value));
+        jb_set_string_from_bytes(js, "http_refer", htp_header_value_ptr(h_referer),
+                (uint32_t)htp_header_value_len(h_referer));
     }
 
     /* method */
@@ -300,10 +301,10 @@ static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
                 (uint32_t)bstr_len(htp_tx_response_status(tx)));
     }
 
-    htp_header_t *h_location = htp_tx_response_header(tx, "location");
+    const htp_header_t *h_location = htp_tx_response_header(tx, "location");
     if (h_location != NULL) {
-        jb_set_string_from_bytes(
-                js, "redirect", bstr_ptr(h_location->value), (uint32_t)bstr_len(h_location->value));
+        jb_set_string_from_bytes(js, "redirect", htp_header_value_ptr(h_location),
+                (uint32_t)htp_header_value_len(h_location));
     }
 
     /* length */
@@ -323,7 +324,7 @@ static void EveHttpLogJSONHeaders(
     bool array_empty = true;
     jb_open_array(js, direction & LOG_HTTP_REQ_HEADERS ? "request_headers" : "response_headers");
     for (size_t i = 0; i < n; i++) {
-        htp_header_t *h = htp_headers_get_index(headers, i);
+        const htp_header_t *h = htp_headers_get_index(headers, i);
         if ((http_ctx->flags & direction) == 0 && http_ctx->fields != 0) {
             bool tolog = false;
             for (HttpField f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++) {