1--[[
2Copyright (c) 2019, Vsevolod Stakhov <vsevolod@highsecure.ru>
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15]]--
16
17--[[[
18-- @module lua_ffi
19-- This module contains ffi interfaces (requires luajit or lua-ffi)
20--]]
21
22local ffi
23
24local exports = {}
25
26if type(jit) == 'table' then
27  ffi = require "ffi"
28  local NULL = ffi.new 'void*'
29
30  exports.is_null = function(o)
31    return o ~= NULL
32  end
33else
34  local ret,result_or_err = pcall(require, 'ffi')
35
36  if not ret then
37    return {}
38  end
39
40  ffi = result_or_err
41  -- Lua ffi
42  local NULL = ffi.NULL or ffi.C.NULL
43  exports.is_null = function(o)
44    return o ~= NULL
45  end
46end
47
48pcall(ffi.load, "rspamd-server", true)
49exports.common = require "lua_ffi/common"
50exports.dkim = require "lua_ffi/dkim"
51exports.spf = require "lua_ffi/spf"
52exports.linalg = require "lua_ffi/linalg"
53
54for k,v in pairs(ffi) do
55  -- Preserve all stuff to use lua_ffi as ffi itself
56  exports[k] = v
57end
58
59return exports