The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions
lua.c File Reference

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>
+ Include dependency graph for lua.c:

Go to the source code of this file.

Macros

#define IN_RANGE_FLOAT_SIGNED(_x)
 
#define IN_RANGE_INTEGER_SIGNED(_x)
 
#define IN_RANGE_INTEGER_UNSIGNED(_x)
 
#define LOG_PREFIX   mctx->mi->name
 
#define RLM_LUA_STACK_RESET()   lua_settop(L, _fr_lua_stack_state)
 
#define RLM_LUA_STACK_SET()   int _fr_lua_stack_state = lua_gettop(L)
 

Functions

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)
 

Detailed Description

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)

Definition in file lua.c.

Macro Definition Documentation

◆ 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)
Value:
do { \
} while (0)

◆ IN_RANGE_INTEGER_UNSIGNED

#define IN_RANGE_INTEGER_UNSIGNED (   _x)
Value:
do { \
} while (0)

◆ LOG_PREFIX

#define LOG_PREFIX   mctx->mi->name

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.

Function Documentation

◆ _lua_fr_request_register()

static void _lua_fr_request_register ( lua_State *  L,
request_t request 
)
static

Definition at line 721 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lua_list_iterator()

static int _lua_list_iterator ( lua_State *  L)
static

Definition at line 478 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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
[in]LLua interpreter.
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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lua_pair_iterator()

static int _lua_pair_iterator ( lua_State *  L)
static

Definition at line 420 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lua_pair_iterator_init()

static int _lua_pair_iterator_init ( lua_State *  L)
static

Definition at line 449 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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
[in]LLua interpreter.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 364 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lua_rcode_table_index()

static int _lua_rcode_table_index ( lua_State *  L)
static

Definition at line 835 of file lua.c.

+ Here is the caller graph for this function:

◆ _lua_rcode_table_newindex()

static int _lua_rcode_table_newindex ( UNUSED lua_State *  L)
static

Definition at line 826 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _lua_rcode_table_pairs()

static int _lua_rcode_table_pairs ( lua_State *  L)
static

Definition at line 854 of file lua.c.

+ Here is the caller graph for this function:

◆ 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]mctxmodule instantiation data.
[in]Lthe lua state.
[in]nameof function to check.
Returns
0 on success (function is present and correct), or -1 on failure.

Definition at line 634 of file lua.c.

+ Here is the caller graph for this function:

◆ 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.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_init()

int fr_lua_init ( lua_State **  out,
module_inst_ctx_t const *  mctx 
)

Initialise a new Lua/LuaJIT interpreter.

Creates a new lua_State and verifies all required functions have been loaded correctly.

Parameters
[in]outWhere to write a pointer to the new state.
[in]mctxconfiguration data for the
Returns
0 on success else -1.

Definition at line 893 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_isjit()

bool fr_lua_isjit ( lua_State *  L)

Check whether the Lua interpreter were actually linked to is LuaJIT.

Parameters
LLua interpreter.
Returns
true if were running with LuaJIT else false.

Definition at line 591 of file lua.c.

+ Here is the caller graph for this function:

◆ fr_lua_marshall()

static int fr_lua_marshall ( request_t request,
lua_State *  L,
fr_pair_t const *  vp 
)
static

Convert fr_pair_ts to Lua values.

Pushes a Lua representation of an attribute value onto the stack.

Parameters
[in]requestThe current request.
[in]LLua interpreter.
[in]vpto convert.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 55 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_rcode_register()

static void fr_lua_rcode_register ( lua_State *  L,
char const *  name 
)
static

Definition at line 860 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_run()

unlang_action_t fr_lua_run ( rlm_rcode_t p_result,
module_ctx_t const *  mctx,
request_t request,
char const *  funcname 
)

Definition at line 754 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_unmarshall()

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 
)
static

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]ctxTo allocate new fr_pair_t in.
[out]outWhere to write a pointer to the new fr_pair_t.
[in]instthe current instance.
[in]requestthe current request.
[in]LLua interpreter.
[in]daspecifying the type of attribute to create.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 209 of file lua.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_lua_version()

char const* fr_lua_version ( lua_State *  L)

Definition at line 605 of file lua.c.

+ Here is the caller graph for this function: