http: aliases for htp opaque htp_headers_t

In preparation of libhtp rust
pull/12492/head
Philippe Antoine 2 years ago committed by Victor Julien
parent 4478c94395
commit 42ed59aa21

@ -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 */

@ -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);

@ -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));
}

@ -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;

@ -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;

@ -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;

@ -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++) {

@ -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);

Loading…
Cancel
Save