25 RCSID(
"$Id: 3ed156b6f79b98de009580e053786a0dc09488d9 $")
27 #define LOG_PREFIX fr_lua_mctx->mi->name
29 #include <freeradius-devel/server/base.h>
44 lua_setglobal(
L,
"fr");
60 while ((idx = lua_gettop(
L))) {
61 char const *
msg = lua_tostring(
L, idx);
83 while ((idx = lua_gettop(
L))) {
84 char const *
msg = lua_tostring(
L, idx);
107 while ((idx = lua_gettop(
L))) {
108 char const *
msg = lua_tostring(
L, idx);
130 while ((idx = lua_gettop(
L))) {
131 char const *
msg = lua_tostring(
L, idx);
145 RWDEBUG(
"fr.log.$func() is read-only");
204 char const *search_path;
205 char *lua_str, *ctx = NULL;
215 if (strchr(search_path,
':')) {
216 char *paths, *path, *
file, *p;
218 while ((path =
strsep(&paths,
":")) != NULL) {
219 p = strrchr(path,
'/');
220 if (p && ((p[1] ==
'\0') || (p[1] ==
':'))) *p =
'\0';
222 if (access(
file, F_OK) == 0) {
229 lua_str = talloc_asprintf(NULL,
"\
230 ffi = require(\"ffi\")\
232 void fr_lua_util_jit_log_debug(char const *msg);\
233 void fr_lua_util_jit_log_info(char const *msg);\
234 void fr_lua_util_jit_log_warn(char const *msg);\
235 void fr_lua_util_jit_log_error(char const *msg);\
237 fr_lua = ffi.load(\"%s%clibfreeradius-lua%s\")\
239 _fr_log.debug = function(msg)\
240 fr_lua.fr_lua_util_jit_log_debug(msg)\
242 _fr_log.info = function(msg)\
243 fr_lua.fr_lua_util_jit_log_info(msg)\
245 _fr_log.warn = function(msg)\
246 fr_lua.fr_lua_util_jit_log_warn(msg)\
248 _fr_log.error = function(msg)\
249 fr_lua.fr_lua_util_jit_log_error(msg)\
251 function _ro_log(table) \
252 return setmetatable({}, { \
254 __newindex = function(table, key, value)\
255 _fr_log.warn(\"fr.log.$func() is read-only\")\
257 __metatable = false \
260 fr.log = _ro_log(_fr_log)\
262 ret = luaL_dostring(
L, lua_str);
266 ERROR(
"Failed setting up FFI: %s",
267 lua_gettop(
L) ? lua_tostring(
L, -1) :
"Unknown error");
283 lua_getglobal(
L,
"fr");
284 luaL_checktype(
L, -1, LUA_TTABLE);
291 lua_pushvalue(
L, -1);
292 lua_setfield(
L, -2,
"__index");
295 lua_setfield(
L, -2,
"__newindex");
299 lua_setfield(
L, -2,
"debug");
302 lua_setfield(
L, -2,
"info");
305 lua_setfield(
L, -2,
"warn");
308 lua_setfield(
L, -2,
"error");
311 lua_setmetatable(
L, -2);
312 lua_setfield(
L, -2,
"log");
#define L(_str)
Helper for initialising arrays of string literals.
char const * dl_module_search_path(void)
#define ROPTIONAL(_l_request, _l_global, _fmt,...)
Use different logging functions depending on whether request is NULL or not.
Library function signatures for lua module.
char * strsep(char **stringp, char const *delim)
Temporary structure to hold arguments for module calls.
static int _util_log_newindex(UNUSED lua_State *L)
void fr_lua_util_jit_log_warn(char const *msg)
Emit a warning log message.
module_ctx_t const * fr_lua_util_get_mctx(void)
Get the thread local instance.
int fr_lua_util_jit_log_register(lua_State *L)
Insert cdefs into the lua environment.
void fr_lua_util_set_mctx(module_ctx_t const *mctx)
Set the thread local instance.
void fr_lua_util_set_request(request_t *request)
Set the thread local request.
static int _util_log_debug(lua_State *L)
Lua function to output debug messages.
static _Thread_local module_ctx_t const * fr_lua_mctx
void fr_lua_util_fr_register(lua_State *L)
static int _util_log_info(lua_State *L)
Lua function to output informational messages.
static int _util_log_error(lua_State *L)
Lua function to output error messages.
void fr_lua_util_jit_log_error(char const *msg)
Emit a error log message.
void fr_lua_util_jit_log_debug(char const *msg)
Emit a debug log message.
static int _util_log_warn(lua_State *L)
Lua function to output warning messages.
static _Thread_local request_t * fr_lua_request
request_t * fr_lua_util_get_request(void)
Get the thread local request.
int fr_lua_util_log_register(lua_State *L)
Register utililiary functions in the lua environment.
void fr_lua_util_jit_log_info(char const *msg)
Emit an info log message.
char * talloc_typed_strdup(TALLOC_CTX *ctx, char const *p)
Call talloc_strdup, setting the type on the new chunk correctly.
char * talloc_typed_asprintf(TALLOC_CTX *ctx, char const *fmt,...)
Call talloc vasprintf, setting the type on the new chunk correctly.