The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | 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.

Data Structures

struct  fr_lua_pair_s
 

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)
 

Typedefs

typedef struct fr_lua_pair_s fr_lua_pair_t
 

Functions

static void _lua_fr_request_register (lua_State *L, request_t *request)
 
static int _lua_list_iterator (lua_State *L)
 Iterate over attributes in a list.
 
static int _lua_list_iterator_init (lua_State *L)
 Initialise a new structural iterator.
 
static int _lua_pair_accessor (lua_State *L)
 Get an attribute or an instance of an attribute.
 
static void _lua_pair_init (lua_State *L, fr_pair_t *vp, fr_dict_attr_t const *da, unsigned int idx, fr_lua_pair_t *parent)
 Initialise a table representing a pair.
 
static int _lua_pair_iterator (lua_State *L)
 Iterate over instances of a leaf attribute.
 
static int _lua_pair_iterator_init (lua_State *L)
 Initiate an iterator to return all the values of a given attribute.
 
static int _lua_pair_setter (lua_State *L)
 Set an instance of an attribute.
 
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)
 
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.
 
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.
 
int fr_lua_init (lua_State **out, module_inst_ctx_t const *mctx)
 Initialise a new Lua/LuaJIT interpreter.
 
bool fr_lua_isjit (lua_State *L)
 Check whether the Lua interpreter were actually linked to is LuaJIT.
 
static int fr_lua_marshall (request_t *request, lua_State *L, fr_pair_t const *vp)
 Convert fr_pair_ts to Lua values.
 
static int fr_lua_pair_parent_build (request_t *request, fr_lua_pair_t *pair_data)
 Build parent structural pairs needed when a leaf node is set.
 
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_value_box_t *out_vb, request_t *request, lua_State *L, fr_dict_attr_t const *da)
 Use Lua values to populate a fr_value_box_t.
 
char const * fr_lua_version (lua_State *L)
 

Detailed Description

Library functions for the lua module.

Id
512484de8948670daf8972da4476ce30b25aab4c
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.


Data Structure Documentation

◆ fr_lua_pair_s

struct fr_lua_pair_s

Definition at line 44 of file lua.c.

+ Collaboration diagram for fr_lua_pair_s:
Data Fields
fr_dict_attr_t const * da
unsigned int idx
fr_lua_pair_t * parent
fr_pair_t * vp

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.

Typedef Documentation

◆ fr_lua_pair_t

typedef struct fr_lua_pair_s fr_lua_pair_t

Definition at line 43 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 830 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

Iterate over attributes in a list.

Each call returns with two values on the Lua stack

  • the name of the next attribute
  • the value of the next attribute, or an array of child attribute names

or, nil is pushed to the stack when there are no more attributes in the list.

Definition at line 481 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 structural iterator.

Definition at line 524 of file lua.c.

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

◆ _lua_pair_accessor()

static int _lua_pair_accessor ( lua_State *  L)
static

Get an attribute or an instance of an attribute.

When called with a numeric index, it is the instance of the attribute which is being requested. Otherwise, the index is an attribute name.

Note
Should only be present in the Lua environment as a closure.
Takes one upvalue - the fr_lua_pair_t representing either this attribute in the case it is an index being requested, or the parent in the case an attribute is being requested.
Is called as an __index metamethod, so takes the table (can be ignored) and the field (integer index for instance or string for attribute)
Parameters
[in]LLua interpreter.
Returns
  • -1 on failure.
  • 0 (no results) on success.
  • 1 on success with:
    • the fr_pair_t value on the stack for leaf values.
    • a lua table for structural items.

Definition at line 567 of file lua.c.

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

◆ _lua_pair_init()

static void _lua_pair_init ( lua_State *  L,
fr_pair_t vp,
fr_dict_attr_t const *  da,
unsigned int  idx,
fr_lua_pair_t parent 
)
static

Initialise a table representing a pair.

After calling this function, a new table will be on the lua stack which represents the pair.

The pair may not exist - e.g. when setting a new nested attribute, parent pairs may not have been created yet. In that case, this holds the da and index of the instance which will be created when the leaf is assigned a value.

Parameters
[in]Lthe lua state
[in]vpthe actual pair instance being represented, if it already exists
[in]dadictionary attribute for this pair
[in]idxindex of the attribute instance (starting at 1)
[in]parentlua userdata for the parent of this attribute.

Definition at line 794 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

Iterate over instances of a leaf attribute.

Each call returns with the value of the next instance of the attribute on the Lua stack, or nil, when there are no more instances.

Definition at line 425 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

Initiate an iterator to return all the values of a given attribute.

Definition at line 451 of file lua.c.

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

◆ _lua_pair_setter()

static int _lua_pair_setter ( 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_lua_pair_t representing this pair as 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 state.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 349 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 935 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 926 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 954 of file lua.c.

+ Here is the caller graph for this function:

◆ fr_lua_check_func()

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.

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 693 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 738 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 993 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 650 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 65 of file lua.c.

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

◆ fr_lua_pair_parent_build()

static int fr_lua_pair_parent_build ( request_t request,
fr_lua_pair_t pair_data 
)
static

Build parent structural pairs needed when a leaf node is set.

Definition at line 319 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 960 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 854 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_value_box_t out_vb,
request_t request,
lua_State *  L,
fr_dict_attr_t const *  da 
)
static

Use Lua values to populate a fr_value_box_t.

Convert Lua values to fr_value_box_t. How the Lua value is converted is dependent on the type of the box.

Parameters
[in]ctxTo allocate new fr_pair_t in.
[out]out_vbValue box to populate.
[in]requestthe current request.
[in]LLua interpreter.
[in]daspecifying the type of attribute the box represent.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 218 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 664 of file lua.c.

+ Here is the caller graph for this function: