]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: minor cleanups for lua
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 30 Jan 2025 12:42:19 +0000 (13:42 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 30 Jan 2025 20:52:08 +0000 (21:52 +0100)
In preparation of libhtp rust

Mainly adding some const

src/util-lua-http.c

index d4d056ad03424ed3ff170103b0d8612eb90662ba..6c3a512df9b8c4aa4d7d71bfcdf2c3983fd39e9f 100644 (file)
@@ -154,13 +154,13 @@ static int HttpGetHeader(lua_State *luastate, int dir)
     if (name == NULL)
         return LuaCallbackError(luastate, "1st argument missing, empty or wrong type");
 
-    const htp_headers_t *headers = htp_tx_request_headers(tx);
-    if (dir == 1)
-        headers = htp_tx_response_headers(tx);
-    if (headers == NULL)
-        return LuaCallbackError(luastate, "tx has no headers");
+    const htp_header_t *h = NULL;
+    if (dir == 0) {
+        h = htp_tx_request_header(tx, name);
+    } else {
+        h = htp_tx_response_header(tx, name);
+    }
 
-    htp_header_t *h = (htp_header_t *)htp_table_get_c(headers, name);
     if (h == NULL || htp_header_value_len(h) == 0)
         return LuaCallbackError(luastate, "header not found");
 
@@ -226,11 +226,11 @@ static int HttpGetHeaders(lua_State *luastate, int dir)
     const htp_headers_t *table = htp_tx_request_headers(tx);
     if (dir == 1)
         table = htp_tx_response_headers(tx);
-    if (htp_tx_request_headers(tx) == NULL)
+    if (table == NULL)
         return LuaCallbackError(luastate, "no headers");
 
     lua_newtable(luastate);
-    htp_header_t *h = NULL;
+    const htp_header_t *h = NULL;
     size_t i = 0;
     size_t no_of_headers = htp_headers_size(table);
     for (; i < no_of_headers; i++) {