aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_auth_results.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-08 14:34:58 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2022-01-08 14:34:58 +0000
commit3f14f4a3e583593cb55bdd5604db3d9af8e65da5 (patch)
tree25c923e5c60282064bcc9f934867258178f5afa6 /lualib/lua_auth_results.lua
parent9473ed82b5011b67646c18d9f3fb8da67f01e038 (diff)
downloadrspamd-3f14f4a3e583593cb55bdd5604db3d9af8e65da5.tar.gz
rspamd-3f14f4a3e583593cb55bdd5604db3d9af8e65da5.zip
[Minor] Add authentication results parser function
Diffstat (limited to 'lualib/lua_auth_results.lua')
-rw-r--r--lualib/lua_auth_results.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/lualib/lua_auth_results.lua b/lualib/lua_auth_results.lua
index f7a319f48..7b41e6ff5 100644
--- a/lualib/lua_auth_results.lua
+++ b/lualib/lua_auth_results.lua
@@ -275,4 +275,28 @@ end
exports.gen_auth_results = gen_auth_results
+local aar_elt_grammar
+-- This function parses an ar element to a table of kv pairs that represents different
+-- elements
+local function parse_ar_element(elt)
+
+ if not aar_elt_grammar then
+ -- Generate grammar
+ local lpeg = require "lpeg"
+ local P = lpeg.P
+ local S = lpeg.S
+ local V = lpeg.V
+ local C = lpeg.C
+ local space = S(" ")^0
+ local doublequoted = space * P'"' * ((1 - S'"\r\n\f\\') + (P'\\' * 1))^0 * '"' * space
+ local comment = space * P{ "(" * ((1 - S"()") + V(1))^0 * ")" } * space
+ local name = C((1 - S('=(" '))^1) * space
+ local pair = lpeg.Cg(name * "=" * space * name) * space
+ aar_elt_grammar = lpeg.Cf(lpeg.Ct("") * (pair + comment + doublequoted)^1, rawset)
+ end
+
+ return aar_elt_grammar:match(elt)
+end
+exports.parse_ar_element = parse_ar_element
+
return exports