From: Philippe Antoine Date: Fri, 24 Jan 2025 16:16:07 +0000 (+0100) Subject: http: aliases for htp opaque htp_headers_t X-Git-Tag: suricata-8.0.0-beta1~508 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42ed59aa21ac74b5c67f66d4617d77d9c4d3c81e;p=thirdparty%2Fsuricata.git http: aliases for htp opaque htp_headers_t In preparation of libhtp rust --- diff --git a/src/app-layer-htp-libhtp.h b/src/app-layer-htp-libhtp.h index 726b5e0e07..fe94bb01b2 100644 --- a/src/app-layer-htp-libhtp.h +++ b/src/app-layer-htp-libhtp.h @@ -132,6 +132,12 @@ #define htp_header_value_ptr(h) bstr_ptr(h->value) #define htp_header_value(h) h->value +// Functions introduced to handle opaque htp_headers_t: +#define htp_headers_size(headers) htp_table_size(headers) +#define htp_headers_get_index(headers, index) htp_table_get_index(headers, index, NULL) +#define htp_tx_request_headers_size(tx) htp_table_size(tx->request_headers) +#define htp_tx_request_header_index(tx, i) htp_table_get_index(tx->request_headers, i, NULL); + bstr *SCHTPGenerateNormalizedUri(htp_tx_t *tx, htp_uri_t *uri, bool uri_include_all); #endif /* SURICATA_APP_LAYER_HTP_LIBHTP__H */ diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 5b514cb450..1299f607ec 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -2942,7 +2942,7 @@ static int HTPParserTest01(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(strcmp(bstr_util_strdup_to_c(htp_header_value(h)), "Victor/1.0")); @@ -2986,7 +2986,7 @@ static int HTPParserTest01b(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(strcmp(bstr_util_strdup_to_c(htp_header_value(h)), "Victor/1.0")); @@ -3041,7 +3041,7 @@ static int HTPParserTest01c(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(strcmp(bstr_util_strdup_to_c(htp_header_value(h)), "Victor/1.0")); @@ -3097,7 +3097,7 @@ static int HTPParserTest01a(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(strcmp(bstr_util_strdup_to_c(htp_header_value(h)), "Victor/1.0")); @@ -3139,7 +3139,7 @@ static int HTPParserTest02(void) htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NOT_NULL(h); FAIL_IF_NULL(htp_tx_request_method(tx)); @@ -3193,7 +3193,7 @@ static int HTPParserTest03(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NOT_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_UNKNOWN); FAIL_IF(htp_tx_request_protocol_number(tx) != HTP_PROTOCOL_V1_0); @@ -3234,7 +3234,7 @@ static int HTPParserTest04(void) htp_tx_t *tx = HTPStateGetTx(htp_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NOT_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_UNKNOWN); @@ -3308,7 +3308,7 @@ static int HTPParserTest05(void) FAIL_IF_NOT(htp_tx_request_method_number(tx) == HTP_METHOD_POST); FAIL_IF_NOT(htp_tx_request_protocol_number(tx) == HTP_PROTOCOL_V1_0); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF_NOT(htp_tx_response_status_number(tx) == 200); @@ -3399,7 +3399,7 @@ static int HTPParserTest06(void) FAIL_IF(htp_tx_response_status_number(tx) != 200); FAIL_IF(htp_tx_request_protocol_number(tx) != HTP_PROTOCOL_V1_1); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); AppLayerParserThreadCtxFree(alp_tctx); @@ -3638,7 +3638,7 @@ static int HTPParserTest10(void) FAIL_IF_NULL(htp_state); htp_tx_t *tx = HTPStateGetTx(htp_state, 0); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); char *name = bstr_util_strdup_to_c(htp_header_name(h)); @@ -3816,7 +3816,7 @@ static int HTPParserTest13(void) htp_state = f->alstate; FAIL_IF_NULL(htp_state); htp_tx_t *tx = HTPStateGetTx(htp_state, 0); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); char *name = bstr_util_strdup_to_c(htp_header_name(h)); @@ -5389,7 +5389,7 @@ static int HTPParserTest20(void) FAIL_IF_NULL(http_state); htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_GET); @@ -5448,7 +5448,7 @@ static int HTPParserTest21(void) FAIL_IF_NULL(http_state); htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_GET); @@ -5502,7 +5502,7 @@ static int HTPParserTest22(void) FAIL_IF_NULL(http_state); htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_GET); @@ -5556,7 +5556,7 @@ static int HTPParserTest23(void) FAIL_IF_NULL(http_state); htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_GET); @@ -5610,7 +5610,7 @@ static int HTPParserTest24(void) FAIL_IF_NULL(http_state); htp_tx_t *tx = HTPStateGetTx(http_state, 0); FAIL_IF_NULL(tx); - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(tx), 0, NULL); + htp_header_t *h = htp_tx_request_header_index(tx, 0); FAIL_IF_NULL(h); FAIL_IF(htp_tx_request_method_number(tx) != HTP_METHOD_GET); diff --git a/src/app-layer-http2.c b/src/app-layer-http2.c index f214d2210d..bababc099c 100644 --- a/src/app-layer-http2.c +++ b/src/app-layer-http2.c @@ -90,9 +90,9 @@ void HTTP2MimicHttp1Request(void *alstate_orig, void *h2s) rs_http2_tx_set_uri(h2s, bstr_ptr(htp_tx_request_uri(h1tx)), (uint32_t)bstr_len(htp_tx_request_uri(h1tx))); } - size_t nbheaders = htp_table_size(htp_tx_request_headers(h1tx)); + size_t nbheaders = htp_tx_request_headers_size(h1tx); for (size_t i = 0; i < nbheaders; i++) { - htp_header_t *h = htp_table_get_index(htp_tx_request_headers(h1tx), i, NULL); + const htp_header_t *h = htp_tx_request_header_index(h1tx, i); rs_http2_tx_add_header(h2s, htp_header_name_ptr(h), (uint32_t)htp_header_name_len(h), htp_header_value_ptr(h), (uint32_t)htp_header_value_len(h)); } diff --git a/src/detect-http-header-names.c b/src/detect-http-header-names.c index 84f3fe5e7e..eb941434c7 100644 --- a/src/detect-http-header-names.c +++ b/src/detect-http-header-names.c @@ -103,9 +103,9 @@ static uint8_t *GetBufferForTX( /* fill the buffer. \r\nName1\r\nName2\r\n\r\n */ size_t i = 0; - size_t no_of_headers = htp_table_size(headers); + size_t no_of_headers = htp_headers_size(headers); for (; i < no_of_headers; i++) { - htp_header_t *h = htp_table_get_index(headers, i, NULL); + htp_header_t *h = htp_headers_get_index(headers, i); size_t size = htp_header_name_len(h) + 2; // for \r\n if (i == 0) size += 2; diff --git a/src/detect-http-header.c b/src/detect-http-header.c index 81fde351be..f031a3790f 100644 --- a/src/detect-http-header.c +++ b/src/detect-http-header.c @@ -95,9 +95,9 @@ static uint8_t *GetBufferForTX( return NULL; size_t i = 0; - size_t no_of_headers = htp_table_size(headers); + size_t no_of_headers = htp_headers_size(headers); for (; i < no_of_headers; i++) { - htp_header_t *h = htp_table_get_index(headers, i, NULL); + htp_header_t *h = htp_headers_get_index(headers, i); size_t size1 = htp_header_name_len(h); size_t size2 = htp_header_value_len(h); @@ -558,7 +558,7 @@ static InspectionBuffer *GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, } else { headers = htp_tx_response_headers(tx); } - size_t no_of_headers = htp_table_size(headers); + size_t no_of_headers = htp_headers_size(headers); if (local_id == 0) { // We initialize a big buffer on first item // Then, we will just use parts of it @@ -575,7 +575,7 @@ static InspectionBuffer *GetHttp1HeaderData(DetectEngineThreadCtx *det_ctx, hdr_td->cap = no_of_headers; } for (size_t i = 0; i < no_of_headers; i++) { - htp_header_t *h = htp_table_get_index(headers, i, NULL); + htp_header_t *h = htp_headers_get_index(headers, i); size_t size1 = htp_header_name_len(h); size_t size2 = htp_header_value_len(h); size_t size = size1 + size2 + 2; diff --git a/src/detect-http-start.c b/src/detect-http-start.c index d1f7708a15..098b866eb0 100644 --- a/src/detect-http-start.c +++ b/src/detect-http-start.c @@ -115,9 +115,9 @@ static uint8_t *GetBufferForTX( buf->buffer[buf->len++] = '\n'; size_t i = 0; - size_t no_of_headers = htp_table_size(headers); + size_t no_of_headers = htp_headers_size(headers); for (; i < no_of_headers; i++) { - htp_header_t *h = htp_table_get_index(headers, i, NULL); + htp_header_t *h = htp_headers_get_index(headers, i); size_t size1 = htp_header_name_len(h); size_t size2 = htp_header_value_len(h); size_t size = size1 + size2 + 4; diff --git a/src/output-json-http.c b/src/output-json-http.c index c8e3723aec..38cf2e494d 100644 --- a/src/output-json-http.c +++ b/src/output-json-http.c @@ -317,13 +317,13 @@ static void EveHttpLogJSONHeaders( : htp_tx_response_headers(tx); char name[MAX_SIZE_HEADER_NAME] = {0}; char value[MAX_SIZE_HEADER_VALUE] = {0}; - size_t n = htp_table_size(headers); + size_t n = htp_headers_size(headers); JsonBuilderMark mark = { 0, 0, 0 }; jb_get_mark(js, &mark); 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_table_get_index(headers, i, NULL); + 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++) { diff --git a/src/util-lua-http.c b/src/util-lua-http.c index a8924c42fb..fc5622ddd3 100644 --- a/src/util-lua-http.c +++ b/src/util-lua-http.c @@ -232,9 +232,9 @@ static int HttpGetHeaders(lua_State *luastate, int dir) lua_newtable(luastate); htp_header_t *h = NULL; size_t i = 0; - size_t no_of_headers = htp_table_size(table); + size_t no_of_headers = htp_headers_size(table); for (; i < no_of_headers; i++) { - h = htp_table_get_index(table, i, NULL); + h = htp_headers_get_index(table, i); LuaPushStringBuffer(luastate, htp_header_name_ptr(h), htp_header_name_len(h)); LuaPushStringBuffer(luastate, htp_header_value_ptr(h), htp_header_value_len(h)); lua_settable(luastate, -3);