/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "utlist.h"
#include "libmime/lang_detection.h"
#include "mempool_vars_internal.h"
+#include "lua/lua_classnames.h"
#include <math.h>
/* 60 seconds for worker's IO */
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
pconn_ent = lua_newuserdata(L, sizeof(*pconn_ent));
*pconn_ent = conn_ent;
rspamd_lua_setclass(L, "rspamd{csession}", -1);
}
ptask = lua_newuserdata(L, sizeof(*ptask));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
pconn = lua_newuserdata(L, sizeof(*pconn));
/* Task */
ptask = lua_newuserdata(L, sizeof(*ptask));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
/* Connection */
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
rspamd_lua_setclass(L, "rspamd{mimepart}", -1);
*pmime = part;
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
if (lua_pcall(L, 2, 2, 0) != 0) {
rspamd_lua_setclass(L, "rspamd{mimepart}", -1);
*pmime = part;
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
if (lua_pcall(L, 2, 2, err_idx) != 0) {
rspamd_lua_setclass(L, "rspamd{mimepart}", -1);
*pmime = part;
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
if (lua_pcall(L, 2, 0, err_idx) != 0) {
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
if (!rspamd_lua_universal_pcall(L, mres->symbol_cbref,
G_STRLOC, 1, "uss", &err,
- "rspamd{task}", task, symbol, mres->name ? mres->name : "default")) {
+ rspamd_task_classname, task, symbol, mres->name ? mres->name : "default")) {
msg_warn_task("cannot call for symbol_cbref for result %s: %e",
mres->name ? mres->name : "default", err);
g_error_free(err);
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "libserver/mempool_vars_internal.h"
#include "contrib/fastutf8/fastutf8.h"
#include "task.h"
+#include "lua/lua_classnames.h"
#include <math.h>
#ifdef SYS_ZSTD
if (lua_isfunction(L, -1)) {
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
/* stack:
* -1: task
* -2: func
#include "lua/lua_common.h"
#include "libstat/stat_api.h"
#include "contrib/uthash/utlist.h"
+#include "lua/lua_classnames.h"
#include "khash.h"
if (!rspamd_lua_universal_pcall(L, lua_cbref,
G_STRLOC, 1, "utii", &err,
- "rspamd{task}", task,
+ rspamd_task_classname, task,
text_pos, start, end)) {
msg_warn_task("cannot call for re_cache_check_lua_condition for re %s: %e",
rspamd_regexp_get_pattern(re), err);
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if ((ret = lua_pcall(L, 1, 1, err_idx)) != 0) {
msg_err_task("call to selector %s "
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "libserver/cfg_file_private.h"
#include "libmime/lang_detection.h"
#include "libmime/scan_result_private.h"
+#include "lua/lua_classnames.h"
#ifdef WITH_JEMALLOC
#include <jemalloc/jemalloc.h>
L = task->cfg->lua_state;
lua_rawgeti(L, LUA_REGISTRYINDEX, GPOINTER_TO_INT(lf->data));
ptask = lua_newuserdata(L, sizeof(*ptask));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
if (lua_pcall(L, 1, 1, 0) != 0) {
lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->cbref_user);
ptask = (struct rspamd_task **) lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_pcall(L, 1, 1, err_idx) != 0) {
msg_err_task("call to user extraction script failed: %s",
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
lua_rawgeti(L, LUA_REGISTRYINDEX, db->cbref_user);
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_pcall(L, 1, 1, err_idx) != 0) {
msg_err_task("call to user extraction script failed: %s",
lua_rawgeti(L, LUA_REGISTRYINDEX, db->cbref_language);
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_pcall(L, 1, 1, err_idx) != 0) {
msg_err_task("call to language extraction script failed: %s",
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->classify_ref);
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
pcfg = lua_newuserdata(L, sizeof(*pcfg));
*pcfg = cl->cfg;
rspamd_lua_setclass(L, "rspamd{classifier}", -1);
lua_rawgeti(L, LUA_REGISTRYINDEX, ctx->learn_ref);
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
pcfg = lua_newuserdata(L, sizeof(*pcfg));
*pcfg = cl->cfg;
rspamd_lua_setclass(L, "rspamd{classifier}", -1);
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
#include "libmime/images.h"
#include "libserver/html/html.h"
#include "lua/lua_common.h"
+#include "lua/lua_classnames.h"
#include "libserver/mempool_vars_internal.h"
#include "utlist.h"
#include <math.h>
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if ((ret = lua_pcall(L, 1, 1, err_idx)) != 0) {
msg_err_task("call to stat_tokens lua "
/* Push task and two booleans: is_spam and is_unlearn */
struct rspamd_task **ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (is_learn) {
lua_pushboolean(L, is_spam);
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_pcall(L, 1, 1, err_idx) != 0) {
msg_err_task("call to autolearn script failed: "
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
/* Push the whole object as well */
ucl_object_push_lua(L, obj, true);
${CMAKE_CURRENT_SOURCE_DIR}/lua_spf.c
${CMAKE_CURRENT_SOURCE_DIR}/lua_tensor.c
${CMAKE_CURRENT_SOURCE_DIR}/lua_parsers.c
- ${CMAKE_CURRENT_SOURCE_DIR}/lua_compress.c)
+ ${CMAKE_CURRENT_SOURCE_DIR}/lua_compress.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/lua_classnames.c)
SET(RSPAMD_LUA ${LUASRC} PARENT_SCOPE)
\ No newline at end of file
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "config.h"
+
/* Lua headers do not have __cplusplus guards... */
#ifdef __cplusplus
extern "C" {
#include "rspamd.h"
#include "ucl.h"
#include "lua_ucl.h"
+#include "lua_classnames.h"
#ifdef __cplusplus
extern "C" {
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
if ((ret = lua_pcall(L, 1, LUA_MULTRET, err_idx)) != 0) {
}
ptask = lua_newuserdata(thread, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(thread, "rspamd{task}", -1);
+ rspamd_lua_setclass(thread, rspamd_task_classname, -1);
*ptask = task;
thread_entry->finish_callback = lua_metric_symbol_callback_return;
lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref);
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
lua_thread_call(thread, 1);
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
clsname = lua_tostring(L, -1);
- if (strcmp(clsname, "rspamd{task}") == 0) {
+ if (strcmp(clsname, rspamd_task_classname) == 0) {
struct rspamd_task *task = lua_check_task(L, pos);
if (task) {
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct rspamd_task *
lua_check_task(lua_State *L, gint pos)
{
- void *ud = rspamd_lua_check_udata(L, pos, "rspamd{task}");
+ void *ud = rspamd_lua_check_udata(L, pos, rspamd_task_classname);
luaL_argcheck(L, ud != NULL, pos, "'task' expected");
return ud ? *((struct rspamd_task **) ud) : NULL;
}
struct rspamd_task *
lua_check_task_maybe(lua_State *L, gint pos)
{
- void *ud = rspamd_lua_check_udata_maybe(L, pos, "rspamd{task}");
+ void *ud = rspamd_lua_check_udata_maybe(L, pos, rspamd_task_classname);
return ud ? *((struct rspamd_task **) ud) : NULL;
}
if (res) {
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
}
else {
if (err) {
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
return 2;
}
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
return 1;
}
void luaopen_task(lua_State *L)
{
- rspamd_lua_new_class(L, "rspamd{task}", tasklib_m);
+ rspamd_lua_new_class(L, rspamd_task_classname, tasklib_m);
lua_pop(L, 1);
rspamd_lua_add_preload(L, "rspamd_task", lua_load_task);
struct rspamd_task **ptask;
ptask = lua_newuserdata(L, sizeof(gpointer));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
}
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
ppart = lua_newuserdata(L, sizeof(*ppart));
*ppart = part;
lua_rawgeti(L, LUA_REGISTRYINDEX, rule->learn_condition_cb);
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_pcall(L, 1, LUA_MULTRET, err_idx) != 0) {
msg_err_task("call to fuzzy learn condition failed: %s",
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
lua_rawgeti(L, LUA_REGISTRYINDEX, lua_data->idx);
/* Now we got function in top of stack */
ptask = lua_newuserdata(L, sizeof(struct rspamd_task *));
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
*ptask = task;
/* Now push all arguments */
/*
- * Copyright 2023 Vsevolod Stakhov
+ * Copyright 2024 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
lua_pushvalue(L, func_idx);
ptask = lua_newuserdata(L, sizeof(*ptask));
*ptask = task;
- rspamd_lua_setclass(L, "rspamd{task}", -1);
+ rspamd_lua_setclass(L, rspamd_task_classname, -1);
if (lua_repl_thread_call(thread, 1, argv[i], lua_thread_str_error_cb) == 0) {