The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
lua.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License, version 2 if the
4  * License as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software
13  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
14  */
15 
16 /**
17  * $Id: f61ffb1e706c2ae9060d546c63d9cb63667d3541 $
18  *
19  * @file lua.h
20  * @brief Library function signatures for lua module.
21  */
22 RCSIDH(lua_h, "$Id: f61ffb1e706c2ae9060d546c63d9cb63667d3541 $")
23 
24 /*
25  * If were using luajit, luajit.h will define a few more constants and
26  * then include lua.h. Lua 5.1 and LuaJIT 2.0 are API compatible.
27  */
28 #ifdef HAVE_LUAJIT_H
29 # include <luajit.h>
30 #else
31 # include <lua.h>
32 #endif
33 #include <lauxlib.h>
34 #include <freeradius-devel/server/base.h>
35 
36 /*
37  * Define a structure for our module configuration.
38  *
39  * These variables do not need to be in a structure, but it's
40  * a lot cleaner to do so, and a pointer to the structure can
41  * be used as the instance handle.
42  */
43 typedef struct {
44  lua_State *interpreter; //!< Interpreter used for single threaded mode, and environment tests.
45  bool threads; //!< Whether to create new interpreters on a per-instance/per-thread
46  //!< basis, or use a single mutex protected interpreter.
47 
48  bool jit; //!< Whether the linked interpreter is Lua 5.1 or LuaJIT.
49  const char *module; //!< Full path to lua script to load and execute.
50 
51  const char *func_instantiate; //!< Name of function to run on instantiation.
52  const char *func_detach; //!< Name of function to run on detach.
53 
54  const char *func_authorize; //!< Name of function to run on authorization.
55  const char *func_authenticate; //!< Name of function to run on authentication.
56  const char *func_preacct; //!< Name of function to run on preacct.
57  const char *func_accounting; //!< Name of function to run on accounting.
58  const char *func_post_auth; //!< Name of function to run after authentication.
59  const char *func_xlat; //!< Name of function to be called for string expansions.
60 } rlm_lua_t;
61 
62 typedef struct {
63  lua_State *interpreter; //!< Thread specific interpreter.
65 
66 /* lua.c */
67 int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx);
68 unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname);
69 bool fr_lua_isjit(lua_State *L);
70 char const *fr_lua_version(lua_State *L);
71 
72 /* util.c */
73 void fr_lua_util_jit_log_debug(char const *msg);
74 void fr_lua_util_jit_log_info(char const *msg);
75 void fr_lua_util_jit_log_warn(char const *msg);
76 void fr_lua_util_jit_log_error(char const *msg);
77 
78 int fr_lua_util_jit_log_register(lua_State *L);
79 int fr_lua_util_log_register(lua_State *L);
80 void fr_lua_util_set_mctx(module_ctx_t const *mctx);
82 void fr_lua_util_set_request(request_t *request);
84 void fr_lua_util_fr_register(lua_State *L);
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition: action.h:35
log_entry msg
Definition: acutest.h:794
#define L(_str)
Helper for initialising arrays of string literals.
Definition: build.h:207
#define RCSIDH(h, id)
Definition: build.h:445
Library function signatures for lua module.
void fr_lua_util_jit_log_warn(char const *msg)
Emit a warning log message.
Definition: util.c:176
const char * func_post_auth
Name of function to run after authentication.
Definition: lua.h:58
unlang_action_t fr_lua_run(rlm_rcode_t *p_result, module_ctx_t const *mctx, request_t *request, char const *funcname)
Definition: lua.c:754
module_ctx_t const * fr_lua_util_get_mctx(void)
Get the thread local instance.
Definition: util.c:330
bool threads
Whether to create new interpreters on a per-instance/per-thread basis, or use a single mutex protecte...
Definition: lua.h:45
const char * func_preacct
Name of function to run on preacct.
Definition: lua.h:56
int fr_lua_util_jit_log_register(lua_State *L)
Insert cdefs into the lua environment.
Definition: util.c:202
void fr_lua_util_set_mctx(module_ctx_t const *mctx)
Set the thread local instance.
Definition: util.c:321
void fr_lua_util_set_request(request_t *request)
Set the thread local request.
Definition: util.c:339
void fr_lua_util_fr_register(lua_State *L)
Definition: util.c:40
char const * fr_lua_version(lua_State *L)
Definition: lua.c:605
const char * func_authorize
Name of function to run on authorization.
Definition: lua.h:54
void fr_lua_util_jit_log_error(char const *msg)
Emit a error log message.
Definition: util.c:187
const char * func_xlat
Name of function to be called for string expansions.
Definition: lua.h:59
const char * module
Full path to lua script to load and execute.
Definition: lua.h:49
void fr_lua_util_jit_log_debug(char const *msg)
Emit a debug log message.
Definition: util.c:154
lua_State * interpreter
Interpreter used for single threaded mode, and environment tests.
Definition: lua.h:44
bool fr_lua_isjit(lua_State *L)
Check whether the Lua interpreter were actually linked to is LuaJIT.
Definition: lua.c:591
const char * func_authenticate
Name of function to run on authentication.
Definition: lua.h:55
request_t * fr_lua_util_get_request(void)
Get the thread local request.
Definition: util.c:348
int fr_lua_util_log_register(lua_State *L)
Register utililiary functions in the lua environment.
Definition: util.c:280
void fr_lua_util_jit_log_info(char const *msg)
Emit an info log message.
Definition: util.c:165
bool jit
Whether the linked interpreter is Lua 5.1 or LuaJIT.
Definition: lua.h:48
int fr_lua_init(lua_State **out, module_inst_ctx_t const *mctx)
Initialise a new Lua/LuaJIT interpreter.
Definition: lua.c:893
const char * func_instantiate
Name of function to run on instantiation.
Definition: lua.h:51
const char * func_accounting
Name of function to run on accounting.
Definition: lua.h:57
lua_State * interpreter
Thread specific interpreter.
Definition: lua.h:63
const char * func_detach
Name of function to run on detach.
Definition: lua.h:52
Definition: lua.h:43
Temporary structure to hold arguments for module calls.
Definition: module_ctx.h:41
Temporary structure to hold arguments for instantiation calls.
Definition: module_ctx.h:51
rlm_rcode_t
Return codes indicating the result of the module call.
Definition: rcode.h:40
static size_t char ** out
Definition: value.h:984