Library functions for the lua module.
More...
#include <freeradius-devel/server/base.h>
#include <freeradius-devel/util/debug.h>
#include "config.h"
#include "lua.h"
#include <float.h>
#include <lauxlib.h>
#include <lualib.h>
Go to the source code of this file.
|
static void | _lua_fr_request_register (lua_State *L, request_t *request) |
|
static int | _lua_list_iterator (lua_State *L) |
|
static int | _lua_list_iterator_init (lua_State *L) |
| Initialise a new top level list iterator. More...
|
|
static int | _lua_pair_accessor_init (lua_State *L) |
| Initialise and return a new accessor table. More...
|
|
static int | _lua_pair_get (lua_State *L) |
| Get an instance of an attribute. More...
|
|
static int | _lua_pair_iterator (lua_State *L) |
|
static int | _lua_pair_iterator_init (lua_State *L) |
|
static int | _lua_pair_set (lua_State *L) |
| Set an instance of an attribute. More...
|
|
static int | _lua_rcode_table_index (lua_State *L) |
|
static int | _lua_rcode_table_newindex (UNUSED lua_State *L) |
|
static int | _lua_rcode_table_pairs (lua_State *L) |
|
static int | fr_lua_check_func (module_inst_ctx_t const *mctx, lua_State *L, char const *name) |
| Check if a given function was loaded into an index in the global table. More...
|
|
static int | fr_lua_get_field (lua_State *L, request_t *request, char const *field) |
| Resolve a path string to a field value in Lua. More...
|
|
int | fr_lua_init (lua_State **out, module_inst_ctx_t const *mctx) |
| Initialise a new Lua/LuaJIT interpreter. More...
|
|
bool | fr_lua_isjit (lua_State *L) |
| Check whether the Lua interpreter were actually linked to is LuaJIT. More...
|
|
static int | fr_lua_marshall (request_t *request, lua_State *L, fr_pair_t const *vp) |
| Convert fr_pair_ts to Lua values. More...
|
|
static void | fr_lua_rcode_register (lua_State *L, char const *name) |
|
unlang_action_t | fr_lua_run (rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname) |
|
static int | fr_lua_unmarshall (TALLOC_CTX *ctx, fr_pair_t **out, UNUSED rlm_lua_t const *inst, request_t *request, lua_State *L, fr_dict_attr_t const *da) |
| Convert Lua values to fr_pair_ts. More...
|
|
char const * | fr_lua_version (lua_State *L) |
|
Library functions for the lua module.
- Id
- 40c93863c0c8d0913633f4b1d04ab1f3a1c0881d
- Author
- Arran Cudbard-Bell (a.cud.nosp@m.bard.nosp@m.b@fre.nosp@m.erad.nosp@m.ius.o.nosp@m.rg)
-
Artur Malinowski (artur.nosp@m.@wow.nosp@m..com)
- Copyright
- 2015 The FreeRADIUS Server Project.
Definition in file lua.c.
◆ IN_RANGE_FLOAT_SIGNED
#define IN_RANGE_FLOAT_SIGNED |
( |
|
_x | ) |
|
Value: do { \
if ((((double)(_x)) < DBL_MIN) || (((double)(_x)) > DBL_MAX)) { \
REDEBUG("Value (%f) cannot be represented as Lua number. Must be between %f-%f", \
(double)(_x), DBL_MIN, DBL_MAX); \
return -1; \
} \
} while (0)
◆ IN_RANGE_INTEGER_SIGNED
#define IN_RANGE_INTEGER_SIGNED |
( |
|
_x | ) |
|
◆ IN_RANGE_INTEGER_UNSIGNED
#define IN_RANGE_INTEGER_UNSIGNED |
( |
|
_x | ) |
|
◆ LOG_PREFIX
Definition at line 28 of file lua.c.
◆ RLM_LUA_STACK_RESET
#define RLM_LUA_STACK_RESET |
( |
| ) |
lua_settop(L, _fr_lua_stack_state) |
Definition at line 41 of file lua.c.
◆ RLM_LUA_STACK_SET
#define RLM_LUA_STACK_SET |
( |
| ) |
int _fr_lua_stack_state = lua_gettop(L) |
Definition at line 40 of file lua.c.
◆ _lua_fr_request_register()
static void _lua_fr_request_register |
( |
lua_State * |
L, |
|
|
request_t * |
request |
|
) |
| |
|
static |
◆ _lua_list_iterator()
static int _lua_list_iterator |
( |
lua_State * |
L | ) |
|
|
static |
◆ _lua_list_iterator_init()
static int _lua_list_iterator_init |
( |
lua_State * |
L | ) |
|
|
static |
Initialise a new top level list iterator.
Definition at line 512 of file lua.c.
◆ _lua_pair_accessor_init()
static int _lua_pair_accessor_init |
( |
lua_State * |
L | ) |
|
|
static |
Initialise and return a new accessor table.
Definition at line 534 of file lua.c.
◆ _lua_pair_get()
static int _lua_pair_get |
( |
lua_State * |
L | ) |
|
|
static |
Get an instance of an attribute.
- Note
- Should only be present in the Lua environment as a closure.
-
Takes one upvalue - the fr_dict_attr_t to search for as light user data.
-
Is called as an __index metamethod, so takes the table (can be ignored) and the field (an integer index value)
- Parameters
-
- Returns
- 0 (no results) on success.
- 1 on success with the fr_pair_t value on the stack.
Definition at line 323 of file lua.c.
◆ _lua_pair_iterator()
static int _lua_pair_iterator |
( |
lua_State * |
L | ) |
|
|
static |
◆ _lua_pair_iterator_init()
static int _lua_pair_iterator_init |
( |
lua_State * |
L | ) |
|
|
static |
◆ _lua_pair_set()
static int _lua_pair_set |
( |
lua_State * |
L | ) |
|
|
static |
Set an instance of an attribute.
- Note
- Should only be present in the Lua environment as a closure.
-
Takes one upvalue - the fr_dict_attr_t to search for as light user data.
-
Is called as an __newindex metamethod, so takes the table (can be ignored), the field (an integer index value) and the new value.
- Parameters
-
- Returns
- 0 on success.
- -1 on failure.
Definition at line 364 of file lua.c.
◆ _lua_rcode_table_index()
static int _lua_rcode_table_index |
( |
lua_State * |
L | ) |
|
|
static |
◆ _lua_rcode_table_newindex()
static int _lua_rcode_table_newindex |
( |
UNUSED lua_State * |
L | ) |
|
|
static |
◆ _lua_rcode_table_pairs()
static int _lua_rcode_table_pairs |
( |
lua_State * |
L | ) |
|
|
static |
◆ fr_lua_check_func()
static int fr_lua_check_func |
( |
module_inst_ctx_t const * |
mctx, |
|
|
lua_State * |
L, |
|
|
char const * |
name |
|
) |
| |
|
static |
Check if a given function was loaded into an index in the global table.
Also check what was loaded there is a function and that it accepts the correct arguments.
- Parameters
-
[in] | mctx | module instantiation data. |
[in] | L | the lua state. |
[in] | name | of function to check. |
- Returns
- 0 on success (function is present and correct), or -1 on failure.
Definition at line 634 of file lua.c.
◆ fr_lua_get_field()
static int fr_lua_get_field |
( |
lua_State * |
L, |
|
|
request_t * |
request, |
|
|
char const * |
field |
|
) |
| |
|
static |
Resolve a path string to a field value in Lua.
Parses a string in the format
obj0[.obj1][.objN]
, adding all tables it traverses to the stack.
All paths are assumed to start at a global, so the first field will be looked up in the global table.
Definition at line 679 of file lua.c.
◆ fr_lua_init()
Initialise a new Lua/LuaJIT interpreter.
Creates a new lua_State and verifies all required functions have been loaded correctly.
- Parameters
-
[in] | out | Where to write a pointer to the new state. |
[in] | mctx | configuration data for the |
- Returns
- 0 on success else -1.
Definition at line 893 of file lua.c.
◆ fr_lua_isjit()
bool fr_lua_isjit |
( |
lua_State * |
L | ) |
|
Check whether the Lua interpreter were actually linked to is LuaJIT.
- Parameters
-
- Returns
- true if were running with LuaJIT else false.
Definition at line 591 of file lua.c.
◆ fr_lua_marshall()
Convert fr_pair_ts to Lua values.
Pushes a Lua representation of an attribute value onto the stack.
- Parameters
-
[in] | request | The current request. |
[in] | L | Lua interpreter. |
[in] | vp | to convert. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 55 of file lua.c.
◆ fr_lua_rcode_register()
static void fr_lua_rcode_register |
( |
lua_State * |
L, |
|
|
char const * |
name |
|
) |
| |
|
static |
◆ fr_lua_run()
◆ fr_lua_unmarshall()
Convert Lua values to fr_pair_ts.
Convert Lua values back to fr_pair_ts. How the Lua value is converted is dependent on the type of the DA.
- Parameters
-
[in] | ctx | To allocate new fr_pair_t in. |
[out] | out | Where to write a pointer to the new fr_pair_t. |
[in] | inst | the current instance. |
[in] | request | the current request. |
[in] | L | Lua interpreter. |
[in] | da | specifying the type of attribute to create. |
- Returns
- 0 on success.
- -1 on failure.
Definition at line 209 of file lua.c.
◆ fr_lua_version()
char const* fr_lua_version |
( |
lua_State * |
L | ) |
|