aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_ffi
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-08-07 11:41:28 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-08-07 11:41:28 +0100
commit662145d0554de5e769b92dab2d41173a98adcee5 (patch)
treeec28311a0bce6181f248ba7b50304293ad764e44 /lualib/lua_ffi
parentbbd88232db43d18f5e0de5a6502848d4074621c5 (diff)
downloadrspamd-662145d0554de5e769b92dab2d41173a98adcee5.tar.gz
rspamd-662145d0554de5e769b92dab2d41173a98adcee5.zip
[Minor] Reformat all Lua code, no functional changes
Diffstat (limited to 'lualib/lua_ffi')
-rw-r--r--lualib/lua_ffi/common.lua2
-rw-r--r--lualib/lua_ffi/dkim.lua36
-rw-r--r--lualib/lua_ffi/init.lua4
-rw-r--r--lualib/lua_ffi/linalg.lua12
-rw-r--r--lualib/lua_ffi/spf.lua4
5 files changed, 31 insertions, 27 deletions
diff --git a/lualib/lua_ffi/common.lua b/lualib/lua_ffi/common.lua
index 4455c580e..4076cfad4 100644
--- a/lualib/lua_ffi/common.lua
+++ b/lualib/lua_ffi/common.lua
@@ -21,7 +21,7 @@ limitations under the License.
local ffi = require 'ffi'
-ffi.cdef[[
+ffi.cdef [[
struct GString {
char *str;
size_t len;
diff --git a/lualib/lua_ffi/dkim.lua b/lualib/lua_ffi/dkim.lua
index 16d7c11a1..e4592c2d2 100644
--- a/lualib/lua_ffi/dkim.lua
+++ b/lualib/lua_ffi/dkim.lua
@@ -21,7 +21,7 @@ limitations under the License.
local ffi = require 'ffi'
-ffi.cdef[[
+ffi.cdef [[
struct rspamd_dkim_sign_context_s;
struct rspamd_dkim_key_s;
struct rspamd_task;
@@ -69,23 +69,22 @@ local function load_sign_key(what, format)
elseif format == 'raw' then
format = ffi.C.RSPAMD_DKIM_KEY_RAW
else
- return nil,'unknown key format'
+ return nil, 'unknown key format'
end
end
return ffi.C.rspamd_dkim_sign_key_load(what, #what, format, nil)
end
-local default_dkim_headers =
-"(o)from:(o)sender:(o)reply-to:(o)subject:(o)date:(o)message-id:" ..
-"(o)to:(o)cc:(o)mime-version:(o)content-type:(o)content-transfer-encoding:" ..
-"resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" ..
-"(o)in-reply-to:(o)references:list-id:list-owner:list-unsubscribe:" ..
-"list-subscribe:list-post:(o)openpgp:(o)autocrypt"
+local default_dkim_headers = "(o)from:(o)sender:(o)reply-to:(o)subject:(o)date:(o)message-id:" ..
+ "(o)to:(o)cc:(o)mime-version:(o)content-type:(o)content-transfer-encoding:" ..
+ "resent-to:resent-cc:resent-from:resent-sender:resent-message-id:" ..
+ "(o)in-reply-to:(o)references:list-id:list-owner:list-unsubscribe:" ..
+ "list-subscribe:list-post:(o)openpgp:(o)autocrypt"
local function create_sign_context(task, privkey, dkim_headers, sign_type)
if not task or not privkey then
- return nil,'invalid arguments'
+ return nil, 'invalid arguments'
end
if not dkim_headers then
@@ -103,10 +102,9 @@ local function create_sign_context(task, privkey, dkim_headers, sign_type)
elseif sign_type == 'arc-seal' then
sign_type = ffi.C.RSPAMD_DKIM_ARC_SEAL
else
- return nil,'invalid sign type'
+ return nil, 'invalid sign type'
end
-
return ffi.C.rspamd_create_dkim_sign_context(task:topointer(), privkey,
1, 1, dkim_headers, sign_type, nil)
end
@@ -114,17 +112,23 @@ end
local function do_sign(task, sign_context, selector, domain,
expire, len, arc_idx)
if not task or not sign_context or not selector or not domain then
- return nil,'invalid arguments'
+ return nil, 'invalid arguments'
end
- if not expire then expire = 0 end
- if not len then len = 0 end
- if not arc_idx then arc_idx = 0 end
+ if not expire then
+ expire = 0
+ end
+ if not len then
+ len = 0
+ end
+ if not arc_idx then
+ arc_idx = 0
+ end
local gstring = ffi.C.rspamd_dkim_sign(task:topointer(), selector, domain, expire, len, arc_idx, nil, sign_context)
if not gstring then
- return nil,'cannot sign'
+ return nil, 'cannot sign'
end
local ret = ffi.string(gstring.str, gstring.len)
diff --git a/lualib/lua_ffi/init.lua b/lualib/lua_ffi/init.lua
index 6e61462f9..efbbc7ab6 100644
--- a/lualib/lua_ffi/init.lua
+++ b/lualib/lua_ffi/init.lua
@@ -31,7 +31,7 @@ if type(jit) == 'table' then
return o ~= NULL
end
else
- local ret,result_or_err = pcall(require, 'ffi')
+ local ret, result_or_err = pcall(require, 'ffi')
if not ret then
return {}
@@ -51,7 +51,7 @@ exports.dkim = require "lua_ffi/dkim"
exports.spf = require "lua_ffi/spf"
exports.linalg = require "lua_ffi/linalg"
-for k,v in pairs(ffi) do
+for k, v in pairs(ffi) do
-- Preserve all stuff to use lua_ffi as ffi itself
exports[k] = v
end
diff --git a/lualib/lua_ffi/linalg.lua b/lualib/lua_ffi/linalg.lua
index 6a5c53df0..2df488afe 100644
--- a/lualib/lua_ffi/linalg.lua
+++ b/lualib/lua_ffi/linalg.lua
@@ -23,15 +23,15 @@ local ffi = require 'ffi'
local exports = {}
-ffi.cdef[[
+ffi.cdef [[
void kad_sgemm_simple(int trans_A, int trans_B, int M, int N, int K, const float *A, const float *B, float *C);
bool kad_ssyev_simple (int N, float *A, float *output);
]]
local function table_to_ffi(a, m, n)
local a_conv = ffi.new("float[?]", m * n)
- for i=1,m or #a do
- for j=1,n or #a[1] do
+ for i = 1, m or #a do
+ for j = 1, n or #a[1] do
a_conv[(i - 1) * n + (j - 1)] = a[i][j]
end
end
@@ -41,9 +41,9 @@ end
local function ffi_to_table(a, m, n)
local res = {}
- for i=0,m-1 do
+ for i = 0, m - 1 do
res[i + 1] = {}
- for j=0,n-1 do
+ for j = 0, n - 1 do
res[i + 1][j + 1] = a[i * n + j]
end
end
@@ -75,7 +75,7 @@ exports.eigen = function(a, n)
local res = ffi.new("float[?]", n)
if ffi.C.kad_ssyev_simple(n, ffi.cast('float*', a), res) then
- return res,a
+ return res, a
end
return nil
diff --git a/lualib/lua_ffi/spf.lua b/lualib/lua_ffi/spf.lua
index 783870eac..0f982f2f9 100644
--- a/lualib/lua_ffi/spf.lua
+++ b/lualib/lua_ffi/spf.lua
@@ -21,7 +21,7 @@ limitations under the License.
local ffi = require 'ffi'
-ffi.cdef[[
+ffi.cdef [[
enum spf_mech_e {
SPF_FAIL,
SPF_SOFT_FAIL,
@@ -112,7 +112,7 @@ local function spf_resolve(task, cb)
local digstr = ffi.new("char[64]")
ffi.C.rspamd_snprintf(digstr, 64, "0x%xuL", rec.digest)
res.digest = ffi.string(digstr)
- for i = 1,nelts do
+ for i = 1, nelts do
res.addrs[i] = spf_addr_tolua(elts[i - 1])
end