]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
http: use lua lib to access data
authorShivani Bhardwaj <shivanib134@gmail.com>
Wed, 26 Mar 2025 06:00:18 +0000 (11:30 +0530)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Apr 2025 08:17:07 +0000 (10:17 +0200)
tests/lua-output-http-02/http.lua
tests/lua-output-http/http.lua

index a55f9b25e70b706a0cb1e4b8afb7932bcf35b596..38deddf6af0ca9a06e96bb1d224e646fb8de94f6 100644 (file)
@@ -1,6 +1,7 @@
 -- simple fast-log to file lua module
 local flow = require("suricata.flow")
 local packet = require "suricata.packet"
+local http = require("suricata.http")
 
 name = "http_lua.log"
 
@@ -14,23 +15,24 @@ function setup (args)
     filename = SCLogPath() .. "/" .. name
     file = assert(io.open(filename, "a"))
     SCLogInfo("HTTP Log Filename " .. filename)
-    http = 0
+    http_tx = 0
 end
 
 function log(args)
-    http_uri = HttpGetRequestUriRaw()
+    local tx = http.get_tx()
+    http_uri = tx:request_uri_raw()
     if http_uri == nil then
         http_uri = "<unknown>"
     end
     http_uri = string.gsub(http_uri, "%c", ".")
 
-    http_host = HttpGetRequestHost()
+    http_host = tx:request_host()
     if http_host == nil then
         http_host = "<hostname unknown>"
     end
     http_host = string.gsub(http_host, "%c", ".")
 
-    http_ua = HttpGetRequestHeader("User-Agent")
+    http_ua = tx:request_header("User-Agent")
     if http_ua == nil then
         http_ua = "<useragent unknown>"
     end
@@ -46,10 +48,10 @@ function log(args)
            dstip .. ":" .. math.floor(dp) .. "\n")
     file:flush()
 
-    http = http + 1
+    http_tx = http_tx + 1
 end
 
 function deinit (args)
-    SCLogInfo ("HTTP transactions logged: " .. http);
+    SCLogInfo ("HTTP transactions logged: " .. http_tx);
     file:close(file)
 end
index 0f5c0feccb3433cb01458fc42b3988cc208d60c1..1979598df3bba8fa5dbca8bf4fbc00c276ab590f 100644 (file)
@@ -1,6 +1,7 @@
 -- simple fast-log to file lua module
 local packet = require "suricata.packet"
 local flow = require("suricata.flow")
+local http = require("suricata.http")
 
 name = "http_lua.log"
 
@@ -13,24 +14,24 @@ end
 function setup (args)
     filename = SCLogPath() .. "/" .. name
     file = assert(io.open(filename, "a"))
-    SCLogInfo("HTTP Log Filename " .. filename)
-    http = 0
+    http_tx = 0
 end
 
 function log(args)
-    http_uri = HttpGetRequestUriRaw()
+    local tx = http.get_tx()
+    http_uri = tx:request_uri_raw()
     if http_uri == nil then
         http_uri = "<unknown>"
     end
     http_uri = string.gsub(http_uri, "%c", ".")
 
-    http_host = HttpGetRequestHost()
+    http_host = tx:request_host()
     if http_host == nil then
         http_host = "<hostname unknown>"
     end
     http_host = string.gsub(http_host, "%c", ".")
 
-    http_ua = HttpGetRequestHeader("User-Agent")
+    http_ua = tx:request_header("User-Agent")
     if http_ua == nil then
         http_ua = "<useragent unknown>"
     end
@@ -46,10 +47,10 @@ function log(args)
            dstip .. ":" .. math.floor(dp) .. "\n")
     file:flush()
 
-    http = http + 1
+    http_tx = http_tx + 1
 end
 
 function deinit (args)
-    SCLogInfo ("HTTP transactions logged: " .. http);
+    SCLogInfo ("HTTP transactions logged: " .. http_tx);
     file:close(file)
 end