diff options
43 files changed, 413 insertions, 319 deletions
diff --git a/src/controller.c b/src/controller.c index 8df2dc248..c9cda1d62 100644 --- a/src/controller.c +++ b/src/controller.c @@ -1559,7 +1559,7 @@ rspamd_controller_handle_lua_history(lua_State *L, 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); + rspamd_lua_setclass(L, rspamd_csession_classname, -1); lua_pushinteger(L, from); lua_pushinteger(L, to); lua_pushboolean(L, reset); @@ -1921,7 +1921,7 @@ rspamd_controller_handle_lua(struct rspamd_http_connection_entry *conn_ent, *ptask = task; pconn = lua_newuserdata(L, sizeof(*pconn)); - rspamd_lua_setclass(L, "rspamd{csession}", -1); + rspamd_lua_setclass(L, rspamd_csession_classname, -1); *pconn = conn_ent; if (lua_pcall(L, 2, 0, 0) != 0) { @@ -3547,7 +3547,7 @@ rspamd_controller_handle_lua_plugin(struct rspamd_http_connection_entry *conn_en /* Connection */ pconn = lua_newuserdata(L, sizeof(*pconn)); - rspamd_lua_setclass(L, "rspamd{csession}", -1); + rspamd_lua_setclass(L, rspamd_csession_classname, -1); *pconn = conn_ent; /* Query arguments */ @@ -3821,14 +3821,14 @@ static const struct luaL_reg lua_csessionlib_m[] = { static void luaopen_controller(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{csession}", lua_csessionlib_m); + rspamd_lua_new_class(L, rspamd_csession_classname, lua_csessionlib_m); lua_pop(L, 1); } struct rspamd_http_connection_entry * lua_check_controller_entry(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{csession}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_csession_classname); luaL_argcheck(L, ud != NULL, pos, "'csession' expected"); return ud ? *((struct rspamd_http_connection_entry **) ud) : NULL; } @@ -3843,7 +3843,7 @@ lua_csession_get_ev_base(lua_State *L) if (c) { s = c->ud; pbase = lua_newuserdata(L, sizeof(struct ev_loop *)); - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); *pbase = s->ctx->event_loop; } else { @@ -3863,7 +3863,7 @@ lua_csession_get_cfg(lua_State *L) if (c) { s = c->ud; pcfg = lua_newuserdata(L, sizeof(gpointer)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = s->ctx->cfg; } else { diff --git a/src/fuzzy_storage.c b/src/fuzzy_storage.c index b4d2b802b..59a4b815b 100644 --- a/src/fuzzy_storage.c +++ b/src/fuzzy_storage.c @@ -2551,7 +2551,7 @@ static int lua_fuzzy_add_pre_handler(lua_State *L) { struct rspamd_worker *wrk, **pwrk = (struct rspamd_worker **) - rspamd_lua_check_udata(L, 1, "rspamd{worker}"); + rspamd_lua_check_udata(L, 1, rspamd_worker_classname); struct rspamd_fuzzy_storage_ctx *ctx; if (!pwrk) { @@ -2582,7 +2582,7 @@ static int lua_fuzzy_add_post_handler(lua_State *L) { struct rspamd_worker *wrk, **pwrk = (struct rspamd_worker **) - rspamd_lua_check_udata(L, 1, "rspamd{worker}"); + rspamd_lua_check_udata(L, 1, rspamd_worker_classname); struct rspamd_fuzzy_storage_ctx *ctx; if (!pwrk) { @@ -2613,7 +2613,7 @@ static int lua_fuzzy_add_blacklist_handler(lua_State *L) { struct rspamd_worker *wrk, **pwrk = (struct rspamd_worker **) - rspamd_lua_check_udata(L, 1, "rspamd{worker}"); + rspamd_lua_check_udata(L, 1, rspamd_worker_classname); struct rspamd_fuzzy_storage_ctx *ctx; if (!pwrk) { @@ -3458,17 +3458,17 @@ start_fuzzy(struct rspamd_worker *worker) .name = "add_fuzzy_pre_handler", .func = lua_fuzzy_add_pre_handler, }; - rspamd_lua_add_metamethod(ctx->cfg->lua_state, "rspamd{worker}", &fuzzy_lua_reg); + rspamd_lua_add_metamethod(ctx->cfg->lua_state, rspamd_worker_classname, &fuzzy_lua_reg); fuzzy_lua_reg = (luaL_Reg){ .name = "add_fuzzy_post_handler", .func = lua_fuzzy_add_post_handler, }; - rspamd_lua_add_metamethod(ctx->cfg->lua_state, "rspamd{worker}", &fuzzy_lua_reg); + rspamd_lua_add_metamethod(ctx->cfg->lua_state, rspamd_worker_classname, &fuzzy_lua_reg); fuzzy_lua_reg = (luaL_Reg){ .name = "add_fuzzy_blacklist_handler", .func = lua_fuzzy_add_blacklist_handler, }; - rspamd_lua_add_metamethod(ctx->cfg->lua_state, "rspamd{worker}", &fuzzy_lua_reg); + rspamd_lua_add_metamethod(ctx->cfg->lua_state, rspamd_worker_classname, &fuzzy_lua_reg); rspamd_lua_run_postloads(ctx->cfg->lua_state, ctx->cfg, ctx->event_loop, worker); diff --git a/src/libmime/message.c b/src/libmime/message.c index 84870a8b0..4fb118e60 100644 --- a/src/libmime/message.c +++ b/src/libmime/message.c @@ -991,7 +991,7 @@ rspamd_message_from_data(struct rspamd_task *task, const guchar *start, struct rspamd_task **ptask; pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); *pmime = part; ptask = lua_newuserdata(L, sizeof(struct rspamd_task *)); rspamd_lua_setclass(L, rspamd_task_classname, -1); @@ -1444,7 +1444,7 @@ void rspamd_message_process(struct rspamd_task *task) gint err_idx = lua_gettop(L); lua_pushvalue(L, magic_func_pos); pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); *pmime = part; ptask = lua_newuserdata(L, sizeof(struct rspamd_task *)); rspamd_lua_setclass(L, rspamd_task_classname, -1); @@ -1516,7 +1516,7 @@ void rspamd_message_process(struct rspamd_task *task) gint err_idx = lua_gettop(L); lua_pushvalue(L, content_func_pos); pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); *pmime = part; ptask = lua_newuserdata(L, sizeof(struct rspamd_task *)); rspamd_lua_setclass(L, rspamd_task_classname, -1); diff --git a/src/libserver/cfg_rcl.cxx b/src/libserver/cfg_rcl.cxx index 3ac7560a8..39360110f 100644 --- a/src/libserver/cfg_rcl.cxx +++ b/src/libserver/cfg_rcl.cxx @@ -3762,7 +3762,7 @@ rspamd_config_read(struct rspamd_config *cfg, void *pcfg = lua_newuserdata(RSPAMD_LUA_CFG_STATE(cfg), sizeof(void *)); memcpy(pcfg, &cfg, sizeof(void *)); - rspamd_lua_setclass(RSPAMD_LUA_CFG_STATE(cfg), "rspamd{config}", -1); + rspamd_lua_setclass(RSPAMD_LUA_CFG_STATE(cfg), rspamd_config_classname, -1); if (lua_pcall(RSPAMD_LUA_CFG_STATE(cfg), 1, 0, err_idx) != 0) { msg_err_config("cannot call lua init_debug_logging script: %s", diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index cd5cc4e30..80121c9cd 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -482,7 +482,7 @@ rspamd_maybe_add_lua_dynsym(struct rspamd_config *cfg, if (lua_type(L, -1) == LUA_TFUNCTION) { pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); lua_pushstring(L, sym); lua_pushnumber(L, score); @@ -530,7 +530,7 @@ rspamd_maybe_add_lua_dynact(struct rspamd_config *cfg, if (lua_type(L, -1) == LUA_TFUNCTION) { pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); lua_pushstring(L, action); lua_pushnumber(L, score); diff --git a/src/libserver/symcache/symcache_impl.cxx b/src/libserver/symcache/symcache_impl.cxx index 93675ac16..63ac4a58e 100644 --- a/src/libserver/symcache/symcache_impl.cxx +++ b/src/libserver/symcache/symcache_impl.cxx @@ -1052,7 +1052,7 @@ auto symcache::periodic_resort(struct ev_loop *ev_loop, double cur_time, double lua_rawgeti(L, LUA_REGISTRYINDEX, peak_cb); pbase = (struct ev_loop **) lua_newuserdata(L, sizeof(*pbase)); *pbase = ev_loop; - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); lua_pushlstring(L, item->symbol.c_str(), item->symbol.size()); lua_pushnumber(L, item->st->avg_frequency); lua_pushnumber(L, ::sqrt(item->st->stddev_frequency)); diff --git a/src/libstat/backends/redis_backend.cxx b/src/libstat/backends/redis_backend.cxx index 9cc0b123d..630c895a2 100644 --- a/src/libstat/backends/redis_backend.cxx +++ b/src/libstat/backends/redis_backend.cxx @@ -547,7 +547,7 @@ rspamd_redis_init(struct rspamd_stat_ctx *ctx, if (ctx->event_loop) { auto **pev_base = (struct ev_loop **) lua_newuserdata(L, sizeof(struct ev_loop *)); *pev_base = ctx->event_loop; - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); } else { lua_pushnil(L); diff --git a/src/libstat/classifiers/lua_classifier.c b/src/libstat/classifiers/lua_classifier.c index 09b35c6a9..30b2a0abd 100644 --- a/src/libstat/classifiers/lua_classifier.c +++ b/src/libstat/classifiers/lua_classifier.c @@ -148,7 +148,7 @@ lua_classifier_classify(struct rspamd_classifier *cl, rspamd_lua_setclass(L, rspamd_task_classname, -1); pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cl->cfg; - rspamd_lua_setclass(L, "rspamd{classifier}", -1); + rspamd_lua_setclass(L, rspamd_classifier_classname, -1); lua_createtable(L, tokens->len, 0); @@ -203,7 +203,7 @@ lua_classifier_learn_spam(struct rspamd_classifier *cl, rspamd_lua_setclass(L, rspamd_task_classname, -1); pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cl->cfg; - rspamd_lua_setclass(L, "rspamd{classifier}", -1); + rspamd_lua_setclass(L, rspamd_classifier_classname, -1); lua_createtable(L, tokens->len, 0); diff --git a/src/libstat/stat_config.c b/src/libstat/stat_config.c index 274804461..0e1ae5432 100644 --- a/src/libstat/stat_config.c +++ b/src/libstat/stat_config.c @@ -214,7 +214,7 @@ void rspamd_stat_init(struct rspamd_config *cfg, struct ev_loop *ev_base) pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); if ((ret = lua_pcall(L, 1, 1, err_idx)) != 0) { msg_err_config("call to gen_stat_tokens lua " diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c index 76a5795bb..6831cdabe 100644 --- a/src/lua/lua_cdb.c +++ b/src/lua/lua_cdb.c @@ -104,7 +104,7 @@ static const struct luaL_reg cdblib_f[] = { static struct cdb * lua_check_cdb(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cdb}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cdb_classname); luaL_argcheck(L, ud != NULL, pos, "'cdb' expected"); return ud ? *((struct cdb **) ud) : NULL; @@ -113,7 +113,7 @@ lua_check_cdb(lua_State *L, int pos) static struct cdb_make * lua_check_cdb_builder(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cdb_builder}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cdb_builder_classname); luaL_argcheck(L, ud != NULL, pos, "'cdb_builder' expected"); return ud ? ((struct cdb_make *) ud) : NULL; @@ -135,14 +135,14 @@ lua_cdb_get_input(lua_State *L, int pos, gsize *olen) return numbuf; } case LUA_TUSERDATA: { - void *p = rspamd_lua_check_udata_maybe(L, pos, "rspamd{text}"); + void *p = rspamd_lua_check_udata_maybe(L, pos, rspamd_text_classname); if (p) { struct rspamd_lua_text *t = (struct rspamd_lua_text *) p; *olen = t->len; return t->start; } - p = rspamd_lua_check_udata_maybe(L, pos, "rspamd{int64}"); + p = rspamd_lua_check_udata_maybe(L, pos, rspamd_int64_classname); if (p) { static char numbuf[sizeof(gint64)]; @@ -210,7 +210,7 @@ lua_cdb_create(lua_State *L) cdb_add_timer(cdb, ev_base, CDB_REFRESH_TIME); } pcdb = lua_newuserdata(L, sizeof(struct cdb *)); - rspamd_lua_setclass(L, "rspamd{cdb}", -1); + rspamd_lua_setclass(L, rspamd_cdb_classname, -1); *pcdb = cdb; } } @@ -301,7 +301,7 @@ lua_cdb_build(lua_State *L) struct cdb_make *cdbm = lua_newuserdata(L, sizeof(struct cdb_make)); g_assert(cdb_make_start(cdbm, fd) == 0); - rspamd_lua_setclass(L, "rspamd{cdb_builder}", -1); + rspamd_lua_setclass(L, rspamd_cdb_builder_classname, -1); return 1; } @@ -383,9 +383,9 @@ lua_load_cdb(lua_State *L) void luaopen_cdb(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{cdb}", cdblib_m); + rspamd_lua_new_class(L, rspamd_cdb_classname, cdblib_m); lua_pop(L, 1); - rspamd_lua_new_class(L, "rspamd{cdb_builder}", cdbbuilderlib_m); + rspamd_lua_new_class(L, rspamd_cdb_builder_classname, cdbbuilderlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cdb", lua_load_cdb); } diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c index 39580a60d..eb50f1950 100644 --- a/src/lua/lua_classifier.c +++ b/src/lua/lua_classifier.c @@ -48,7 +48,7 @@ static struct rspamd_statfile_config *lua_check_statfile(lua_State *L); static struct rspamd_classifier_config * lua_check_classifier(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{classifier}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_classifier_classname); luaL_argcheck(L, ud != NULL, 1, "'classifier' expected"); return ud ? *((struct rspamd_classifier_config **) ud) : NULL; } @@ -69,7 +69,7 @@ lua_classifier_get_statfiles(lua_State *L) while (cur) { st = cur->data; pst = lua_newuserdata(L, sizeof(struct rspamd_statfile_config *)); - rspamd_lua_setclass(L, "rspamd{statfile}", -1); + rspamd_lua_setclass(L, rspamd_statfile_classname, -1); *pst = st; lua_rawseti(L, -2, i++); @@ -127,7 +127,7 @@ lua_classifier_get_statfile_by_label(lua_State *L) pst = lua_newuserdata(L, sizeof(struct rspamd_statfile_config *)); - rspamd_lua_setclass(L, "rspamd{statfile}", -1); + rspamd_lua_setclass(L, rspamd_statfile_classname, -1); *pst = st; lua_rawseti(L, -2, i++); cur = g_list_next(cur); @@ -209,7 +209,7 @@ lua_statfile_get_param(lua_State *L) static struct rspamd_statfile_config * lua_check_statfile(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{statfile}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_statfile_classname); luaL_argcheck(L, ud != NULL, 1, "'statfile' expected"); return ud ? *((struct rspamd_statfile_config **) ud) : NULL; } @@ -219,12 +219,12 @@ lua_check_statfile(lua_State *L) void luaopen_classifier(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{classifier}", classifierlib_m); + rspamd_lua_new_class(L, rspamd_classifier_classname, classifierlib_m); lua_pop(L, 1); /* remove metatable from stack */ } void luaopen_statfile(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{statfile}", statfilelib_m); + rspamd_lua_new_class(L, rspamd_statfile_classname, statfilelib_m); lua_pop(L, 1); /* remove metatable from stack */ } diff --git a/src/lua/lua_classnames.c b/src/lua/lua_classnames.c index 5992da891..5d67e2c19 100644 --- a/src/lua/lua_classnames.c +++ b/src/lua/lua_classnames.c @@ -16,4 +16,51 @@ #include "lua_classnames.h" +const char *rspamd_archive_classname = "rspamd{archive}"; +const char *rspamd_cdb_builder_classname = "rspamd{cdb_builder}"; +const char *rspamd_cdb_classname = "rspamd{cdb}"; +const char *rspamd_classifier_classname = "rspamd{classifier}"; +const char *rspamd_config_classname = "rspamd{config}"; +const char *rspamd_cryptobox_hash_classname = "rspamd{cryptobox_hash}"; +const char *rspamd_cryptobox_keypair_classname = "rspamd{cryptobox_keypair}"; +const char *rspamd_cryptobox_pubkey_classname = "rspamd{cryptobox_pubkey}"; +const char *rspamd_cryptobox_secretbox_classname = "rspamd{cryptobox_secretbox}"; +const char *rspamd_cryptobox_signature_classname = "rspamd{cryptobox_signature}"; +const char *rspamd_csession_classname = "rspamd{csession}"; +const char *rspamd_ev_base_classname = "rspamd{ev_base}"; +const char *rspamd_expr_classname = "rspamd{expr}"; +const char *rspamd_html_tag_classname = "rspamd{html_tag}"; +const char *rspamd_html_classname = "rspamd{html}"; +const char *rspamd_image_classname = "rspamd{image}"; +const char *rspamd_int64_classname = "rspamd{int64}"; +const char *rspamd_ip_classname = "rspamd{ip}"; +const char *rspamd_kann_node_classname = "rspamd{kann_node}"; +const char *rspamd_kann_classname = "rspamd{kann}"; +const char *rspamd_map_classname = "rspamd{map}"; +const char *rspamd_mempool_classname = "rspamd{mempool}"; +const char *rspamd_mimepart_classname = "rspamd{mimepart}"; +const char *rspamd_monitored_classname = "rspamd{monitored}"; +const char *rspamd_redis_classname = "rspamd{redis}"; +const char *rspamd_regexp_classname = "rspamd{regexp}"; +const char *rspamd_resolver_classname = "rspamd{resolver}"; +const char *rspamd_rsa_privkey_classname = "rspamd{rsa_privkey}"; +const char *rspamd_rsa_pubkey_classname = "rspamd{rsa_pubkey}"; +const char *rspamd_rsa_signature_classname = "rspamd{rsa_signature}"; +const char *rspamd_session_classname = "rspamd{session}"; +const char *rspamd_spf_record_classname = "rspamd{spf_record}"; +const char *rspamd_sqlite3_stmt_classname = "rspamd{sqlite3_stmt}"; +const char *rspamd_sqlite3_classname = "rspamd{sqlite3}"; +const char *rspamd_statfile_classname = "rspamd{statfile}"; const char *rspamd_task_classname = "rspamd{task}"; +const char *rspamd_tcp_sync_classname = "rspamd{tcp_sync}"; +const char *rspamd_tcp_classname = "rspamd{tcp}"; +const char *rspamd_tensor_classname = "rspamd{tensor}"; +const char *rspamd_textpart_classname = "rspamd{textpart}"; +const char *rspamd_text_classname = "rspamd{text}"; +const char *rspamd_trie_classname = "rspamd{trie}"; +const char *rspamd_upstream_list_classname = "rspamd{upstream_list}"; +const char *rspamd_upstream_classname = "rspamd{upstream}"; +const char *rspamd_url_classname = "rspamd{url}"; +const char *rspamd_worker_classname = "rspamd{worker}"; +const char *rspamd_zstd_compress_classname = "rspamd{zstd_compress}"; +const char *rspamd_zstd_decompress_classname = "rspamd{zstd_decompress}"; diff --git a/src/lua/lua_classnames.h b/src/lua/lua_classnames.h index 5f765d9a5..9af339a4a 100644 --- a/src/lua/lua_classnames.h +++ b/src/lua/lua_classnames.h @@ -22,6 +22,53 @@ * Here are static definitions of all classes used in Rspamd Lua API */ +extern const char *rspamd_archive_classname; +extern const char *rspamd_cdb_builder_classname; +extern const char *rspamd_cdb_classname; +extern const char *rspamd_classifier_classname; +extern const char *rspamd_config_classname; +extern const char *rspamd_cryptobox_hash_classname; +extern const char *rspamd_cryptobox_keypair_classname; +extern const char *rspamd_cryptobox_pubkey_classname; +extern const char *rspamd_cryptobox_secretbox_classname; +extern const char *rspamd_cryptobox_signature_classname; +extern const char *rspamd_csession_classname; +extern const char *rspamd_ev_base_classname; +extern const char *rspamd_expr_classname; +extern const char *rspamd_html_tag_classname; +extern const char *rspamd_html_classname; +extern const char *rspamd_image_classname; +extern const char *rspamd_int64_classname; +extern const char *rspamd_ip_classname; +extern const char *rspamd_kann_node_classname; +extern const char *rspamd_kann_classname; +extern const char *rspamd_map_classname; +extern const char *rspamd_mempool_classname; +extern const char *rspamd_mimepart_classname; +extern const char *rspamd_monitored_classname; +extern const char *rspamd_redis_classname; +extern const char *rspamd_regexp_classname; +extern const char *rspamd_resolver_classname; +extern const char *rspamd_rsa_privkey_classname; +extern const char *rspamd_rsa_pubkey_classname; +extern const char *rspamd_rsa_signature_classname; +extern const char *rspamd_session_classname; +extern const char *rspamd_spf_record_classname; +extern const char *rspamd_sqlite3_stmt_classname; +extern const char *rspamd_sqlite3_classname; +extern const char *rspamd_statfile_classname; extern const char *rspamd_task_classname; +extern const char *rspamd_tcp_sync_classname; +extern const char *rspamd_tcp_classname; +extern const char *rspamd_tensor_classname; +extern const char *rspamd_textpart_classname; +extern const char *rspamd_text_classname; +extern const char *rspamd_trie_classname; +extern const char *rspamd_upstream_list_classname; +extern const char *rspamd_upstream_classname; +extern const char *rspamd_url_classname; +extern const char *rspamd_worker_classname; +extern const char *rspamd_zstd_compress_classname; +extern const char *rspamd_zstd_decompress_classname; #endif//RSPAMD_LUA_CLASSNAMES_H diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 9bf9514f6..ef13d4119 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -855,7 +855,7 @@ void rspamd_lua_set_globals(struct rspamd_config *cfg, lua_State *L) if (cfg != NULL) { pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; lua_setglobal(L, "rspamd_config"); } @@ -987,7 +987,7 @@ rspamd_lua_init(bool wipe_mem) lua_settop(L, 0); #endif - rspamd_lua_new_class(L, "rspamd{session}", NULL); + rspamd_lua_new_class(L, rspamd_session_classname, NULL); lua_pop(L, 1); rspamd_lua_add_preload(L, "lpeg", luaopen_lpeg); @@ -1122,7 +1122,7 @@ rspamd_init_lua_filters(struct rspamd_config *cfg, bool force_load, bool strict) gint err_idx, i; pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; lua_setglobal(L, "rspamd_config"); @@ -2084,7 +2084,7 @@ rspamd_lua_check_udata_maybe(lua_State *L, gint pos, const gchar *classname) struct rspamd_async_session * lua_check_session(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{session}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_session_classname); luaL_argcheck(L, ud != NULL, pos, "'session' expected"); return ud ? *((struct rspamd_async_session **) ud) : NULL; } @@ -2092,7 +2092,7 @@ lua_check_session(lua_State *L, gint pos) struct ev_loop * lua_check_ev_base(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{ev_base}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_ev_base_classname); luaL_argcheck(L, ud != NULL, pos, "'event_base' expected"); return ud ? *((struct ev_loop **) ud) : NULL; } @@ -2117,15 +2117,15 @@ void rspamd_lua_run_postloads(lua_State *L, struct rspamd_config *cfg, lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); pev_base = lua_newuserdata(L, sizeof(*pev_base)); *pev_base = ev_base; - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); pw = lua_newuserdata(L, sizeof(*pw)); *pw = w; - rspamd_lua_setclass(L, "rspamd{worker}", -1); + rspamd_lua_setclass(L, rspamd_worker_classname, -1); lua_thread_call(thread, 3); } @@ -2145,7 +2145,7 @@ void rspamd_lua_run_config_post_init(lua_State *L, struct rspamd_config *cfg) lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); if (lua_pcall(L, 1, 0, err_idx) != 0) { msg_err_config("cannot run config post init script: %s; priority = %d", @@ -2170,7 +2170,7 @@ void rspamd_lua_run_config_unload(lua_State *L, struct rspamd_config *cfg) lua_rawgeti(L, LUA_REGISTRYINDEX, sc->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); *pcfg = cfg; - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); if (lua_pcall(L, 1, 0, err_idx) != 0) { msg_err_config("cannot run config post init script: %s", @@ -2365,7 +2365,7 @@ rspamd_lua_try_load_redis(lua_State *L, const ucl_object_t *obj, /* Function arguments */ ucl_object_push_lua(L, obj, false); pcfg = lua_newuserdata(L, sizeof(*pcfg)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; lua_pushboolean(L, false); /* no_fallback */ diff --git a/src/lua/lua_compress.c b/src/lua/lua_compress.c index 77c82c557..39776ccf6 100644 --- a/src/lua/lua_compress.c +++ b/src/lua/lua_compress.c @@ -69,7 +69,7 @@ static const struct luaL_reg zstd_decompress_lib_m[] = { static ZSTD_CStream * lua_check_zstd_compress_ctx(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{zstd_compress}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_compress_classname); luaL_argcheck(L, ud != NULL, pos, "'zstd_compress' expected"); return ud ? *(ZSTD_CStream **) ud : NULL; } @@ -77,7 +77,7 @@ lua_check_zstd_compress_ctx(lua_State *L, gint pos) static ZSTD_DStream * lua_check_zstd_decompress_ctx(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{zstd_decompress}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_zstd_decompress_classname); luaL_argcheck(L, ud != NULL, pos, "'zstd_decompress' expected"); return ud ? *(ZSTD_DStream **) ud : NULL; } @@ -119,7 +119,7 @@ gint lua_compress_zstd_compress(lua_State *L) res = lua_newuserdata(L, sizeof(*res)); res->start = g_malloc(sz); res->flags = RSPAMD_TEXT_FLAG_OWN; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); r = ZSTD_compress((void *) res->start, sz, t->start, t->len, comp_level); if (ZSTD_isError(r)) { @@ -194,7 +194,7 @@ gint lua_compress_zstd_decompress(lua_State *L) res = lua_newuserdata(L, sizeof(*res)); res->start = out; res->flags = RSPAMD_TEXT_FLAG_OWN; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); res->len = zout.pos; return 2; @@ -254,7 +254,7 @@ gint lua_compress_zlib_decompress(lua_State *L, bool is_gzip) res = lua_newuserdata(L, sizeof(*res)); res->start = g_malloc(sz); res->flags = RSPAMD_TEXT_FLAG_OWN; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); p = (guchar *) res->start; remain = sz; @@ -351,7 +351,7 @@ gint lua_compress_zlib_compress(lua_State *L) res = lua_newuserdata(L, sizeof(*res)); res->start = g_malloc(sz); res->flags = RSPAMD_TEXT_FLAG_OWN; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); p = (guchar *) res->start; remain = sz; @@ -417,7 +417,7 @@ lua_zstd_compress_ctx(lua_State *L) } *pctx = ctx; - rspamd_lua_setclass(L, "rspamd{zstd_compress}", -1); + rspamd_lua_setclass(L, rspamd_zstd_compress_classname, -1); return 1; } @@ -535,7 +535,7 @@ lua_zstd_decompress_ctx(lua_State *L) } *pctx = ctx; - rspamd_lua_setclass(L, "rspamd{zstd_decompress}", -1); + rspamd_lua_setclass(L, rspamd_zstd_decompress_classname, -1); return 1; } @@ -614,8 +614,8 @@ lua_load_zstd(lua_State *L) void luaopen_compress(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{zstd_compress}", zstd_compress_lib_m); - rspamd_lua_new_class(L, "rspamd{zstd_decompress}", zstd_decompress_lib_m); + rspamd_lua_new_class(L, rspamd_zstd_compress_classname, zstd_compress_lib_m); + rspamd_lua_new_class(L, rspamd_zstd_decompress_classname, zstd_decompress_lib_m); lua_pop(L, 2); rspamd_lua_add_preload(L, "rspamd_zstd", lua_load_zstd); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 5e3eacd29..ad8a6d0bf 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -947,7 +947,7 @@ static const guint64 rspamd_lua_callback_magic = 0x32c118af1e3263c7ULL; struct rspamd_config * lua_check_config(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{config}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_config_classname); luaL_argcheck(L, ud != NULL, pos, "'config' expected"); return ud ? *((struct rspamd_config **) ud) : NULL; } @@ -955,7 +955,7 @@ lua_check_config(lua_State *L, gint pos) static struct rspamd_monitored * lua_check_monitored(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{monitored}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_monitored_classname); luaL_argcheck(L, ud != NULL, pos, "'monitored' expected"); return ud ? *((struct rspamd_monitored **) ud) : NULL; } @@ -1002,7 +1002,7 @@ lua_config_get_mempool(lua_State *L) if (cfg != NULL) { ppool = lua_newuserdata(L, sizeof(rspamd_mempool_t *)); - rspamd_lua_setclass(L, "rspamd{mempool}", -1); + rspamd_lua_setclass(L, rspamd_mempool_classname, -1); *ppool = cfg->cfg_pool; } else { @@ -1020,7 +1020,7 @@ lua_config_get_resolver(lua_State *L) if (cfg != NULL && cfg->dns_resolver) { pres = lua_newuserdata(L, sizeof(*pres)); - rspamd_lua_setclass(L, "rspamd{resolver}", -1); + rspamd_lua_setclass(L, rspamd_resolver_classname, -1); *pres = cfg->dns_resolver; } else { @@ -1160,7 +1160,7 @@ lua_config_get_classifier(lua_State *L) if (pclc) { pclc = lua_newuserdata(L, sizeof(struct rspamd_classifier_config *)); - rspamd_lua_setclass(L, "rspamd{classifier}", -1); + rspamd_lua_setclass(L, rspamd_classifier_classname, -1); *pclc = clc; return 1; } @@ -3361,11 +3361,11 @@ lua_periodic_callback(struct ev_loop *loop, ev_timer *w, int revents) lua_rawgeti(L, LUA_REGISTRYINDEX, periodic->cbref); pcfg = lua_newuserdata(L, sizeof(*pcfg)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); cfg = periodic->cfg; *pcfg = cfg; pev_base = lua_newuserdata(L, sizeof(*pev_base)); - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); *pev_base = periodic->event_loop; lua_pushnumber(L, ev_now(periodic->event_loop)); @@ -3532,7 +3532,7 @@ lua_config_get_symbols_cksum(lua_State *L) pres = lua_newuserdata(L, sizeof(res)); *pres = res; - rspamd_lua_setclass(L, "rspamd{int64}", -1); + rspamd_lua_setclass(L, rspamd_int64_classname, -1); return 1; } @@ -4094,7 +4094,7 @@ lua_config_register_monitored(lua_State *L) if (m) { pm = lua_newuserdata(L, sizeof(*pm)); *pm = m; - rspamd_lua_setclass(L, "rspamd{monitored}", -1); + rspamd_lua_setclass(L, rspamd_monitored_classname, -1); } else { lua_pushnil(L); @@ -4591,7 +4591,7 @@ lua_config_register_re_selector(lua_State *L) lua_pushvalue(L, -2); pcfg = lua_newuserdata(L, sizeof(*pcfg)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; lua_pushstring(L, selector_str); lua_pushstring(L, delimiter); @@ -4749,11 +4749,11 @@ lua_monitored_latency(lua_State *L) void luaopen_config(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{config}", configlib_m); + rspamd_lua_new_class(L, rspamd_config_classname, configlib_m); lua_pop(L, 1); - rspamd_lua_new_class(L, "rspamd{monitored}", monitoredlib_m); + rspamd_lua_new_class(L, rspamd_monitored_classname, monitoredlib_m); lua_pop(L, 1); } diff --git a/src/lua/lua_cryptobox.c b/src/lua/lua_cryptobox.c index 70c6f0ad4..5e81229ac 100644 --- a/src/lua/lua_cryptobox.c +++ b/src/lua/lua_cryptobox.c @@ -210,7 +210,7 @@ struct rspamd_lua_cryptobox_secretbox { static struct rspamd_cryptobox_pubkey * lua_check_cryptobox_pubkey(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cryptobox_pubkey}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cryptobox_pubkey_classname); luaL_argcheck(L, ud != NULL, 1, "'cryptobox_pubkey' expected"); return ud ? *((struct rspamd_cryptobox_pubkey **) ud) : NULL; @@ -219,7 +219,7 @@ lua_check_cryptobox_pubkey(lua_State *L, int pos) static struct rspamd_cryptobox_keypair * lua_check_cryptobox_keypair(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cryptobox_keypair}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cryptobox_keypair_classname); luaL_argcheck(L, ud != NULL, 1, "'cryptobox_keypair' expected"); return ud ? *((struct rspamd_cryptobox_keypair **) ud) : NULL; @@ -228,7 +228,7 @@ lua_check_cryptobox_keypair(lua_State *L, int pos) static rspamd_fstring_t * lua_check_cryptobox_sign(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cryptobox_signature}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cryptobox_signature_classname); luaL_argcheck(L, ud != NULL, 1, "'cryptobox_signature' expected"); return ud ? *((rspamd_fstring_t **) ud) : NULL; @@ -237,7 +237,7 @@ lua_check_cryptobox_sign(lua_State *L, int pos) struct rspamd_lua_cryptobox_hash * lua_check_cryptobox_hash(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cryptobox_hash}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cryptobox_hash_classname); luaL_argcheck(L, ud != NULL, 1, "'cryptobox_hash' expected"); return ud ? *((struct rspamd_lua_cryptobox_hash **) ud) : NULL; @@ -246,7 +246,7 @@ lua_check_cryptobox_hash(lua_State *L, int pos) static struct rspamd_lua_cryptobox_secretbox * lua_check_cryptobox_secretbox(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{cryptobox_secretbox}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_cryptobox_secretbox_classname); luaL_argcheck(L, ud != NULL, 1, "'cryptobox_secretbox' expected"); return ud ? *((struct rspamd_lua_cryptobox_secretbox **) ud) : NULL; @@ -315,7 +315,7 @@ lua_cryptobox_pubkey_load(lua_State *L) else { munmap(map, len); ppkey = lua_newuserdata(L, sizeof(void *)); - rspamd_lua_setclass(L, "rspamd{cryptobox_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_pubkey_classname, -1); *ppkey = pkey; } } @@ -379,7 +379,7 @@ lua_cryptobox_pubkey_create(lua_State *L) } else { ppkey = lua_newuserdata(L, sizeof(void *)); - rspamd_lua_setclass(L, "rspamd{cryptobox_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_pubkey_classname, -1); *ppkey = pkey; } } @@ -443,7 +443,7 @@ lua_cryptobox_keypair_load(lua_State *L) else { pkp = lua_newuserdata(L, sizeof(gpointer)); *pkp = kp; - rspamd_lua_setclass(L, "rspamd{cryptobox_keypair}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_keypair_classname, -1); ucl_object_unref(obj); } } @@ -465,7 +465,7 @@ lua_cryptobox_keypair_load(lua_State *L) else { pkp = lua_newuserdata(L, sizeof(gpointer)); *pkp = kp; - rspamd_lua_setclass(L, "rspamd{cryptobox_keypair}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_keypair_classname, -1); ucl_object_unref(obj); } } @@ -520,7 +520,7 @@ lua_cryptobox_keypair_create(lua_State *L) pkp = lua_newuserdata(L, sizeof(gpointer)); *pkp = kp; - rspamd_lua_setclass(L, "rspamd{cryptobox_keypair}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_keypair_classname, -1); return 1; } @@ -644,7 +644,7 @@ lua_cryptobox_keypair_get_pk(lua_State *L) ppk = lua_newuserdata(L, sizeof(*ppk)); *ppk = pk; - rspamd_lua_setclass(L, "rspamd{cryptobox_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_pubkey_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -705,7 +705,7 @@ lua_cryptobox_signature_load(lua_State *L) if (st.st_size > 0) { sig = rspamd_fstring_new_init(data, st.st_size); psig = lua_newuserdata(L, sizeof(rspamd_fstring_t *)); - rspamd_lua_setclass(L, "rspamd{cryptobox_signature}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_signature_classname, -1); *psig = sig; } else { @@ -824,7 +824,7 @@ lua_cryptobox_signature_create(lua_State *L) if (dlen == rspamd_cryptobox_signature_bytes(RSPAMD_CRYPTOBOX_MODE_25519)) { sig = rspamd_fstring_new_init(data, dlen); psig = lua_newuserdata(L, sizeof(rspamd_fstring_t *)); - rspamd_lua_setclass(L, "rspamd{cryptobox_signature}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_signature_classname, -1); *psig = sig; } } @@ -1209,7 +1209,7 @@ lua_cryptobox_hash_create(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); return 1; } @@ -1261,7 +1261,7 @@ lua_cryptobox_hash_create_specific(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); return 1; } @@ -1308,7 +1308,7 @@ lua_cryptobox_hash_create_keyed(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -1364,7 +1364,7 @@ lua_cryptobox_hash_create_specific_keyed(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -1427,7 +1427,7 @@ lua_cryptobox_hash_update(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; REF_RETAIN(h); - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); return 1; } @@ -1492,7 +1492,7 @@ lua_cryptobox_hash_reset(lua_State *L) ph = lua_newuserdata(L, sizeof(void *)); *ph = h; REF_RETAIN(h); - rspamd_lua_setclass(L, "rspamd{cryptobox_hash}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_hash_classname, -1); return 1; } @@ -1906,7 +1906,7 @@ lua_cryptobox_sign_memory(lua_State *L) sig->len = siglen; psig = lua_newuserdata(L, sizeof(void *)); *psig = sig; - rspamd_lua_setclass(L, "rspamd{cryptobox_signature}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_signature_classname, -1); return 1; } @@ -1953,7 +1953,7 @@ lua_cryptobox_sign_file(lua_State *L) sig->len = siglen; psig = lua_newuserdata(L, sizeof(void *)); *psig = sig; - rspamd_lua_setclass(L, "rspamd{cryptobox_signature}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_signature_classname, -1); munmap(data, len); } @@ -1981,10 +1981,10 @@ lua_cryptobox_encrypt_memory(lua_State *L) bool owned_pk = false; if (lua_type(L, 1) == LUA_TUSERDATA) { - if (rspamd_lua_check_udata_maybe(L, 1, "rspamd{cryptobox_keypair}")) { + if (rspamd_lua_check_udata_maybe(L, 1, rspamd_cryptobox_keypair_classname)) { kp = lua_check_cryptobox_keypair(L, 1); } - else if (rspamd_lua_check_udata_maybe(L, 1, "rspamd{cryptobox_pubkey}")) { + else if (rspamd_lua_check_udata_maybe(L, 1, rspamd_cryptobox_pubkey_classname)) { pk = lua_check_cryptobox_pubkey(L, 1); } } @@ -2046,7 +2046,7 @@ lua_cryptobox_encrypt_memory(lua_State *L) res->flags = RSPAMD_TEXT_FLAG_OWN; res->start = out; res->len = outlen; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); if (owned_pk) { rspamd_pubkey_unref(pk); @@ -2084,10 +2084,10 @@ lua_cryptobox_encrypt_file(lua_State *L) bool own_pk = false; if (lua_type(L, 1) == LUA_TUSERDATA) { - if (rspamd_lua_check_udata_maybe(L, 1, "rspamd{cryptobox_keypair}")) { + if (rspamd_lua_check_udata_maybe(L, 1, rspamd_cryptobox_keypair_classname)) { kp = lua_check_cryptobox_keypair(L, 1); } - else if (rspamd_lua_check_udata_maybe(L, 1, "rspamd{cryptobox_pubkey}")) { + else if (rspamd_lua_check_udata_maybe(L, 1, rspamd_cryptobox_pubkey_classname)) { pk = lua_check_cryptobox_pubkey(L, 1); } } @@ -2140,7 +2140,7 @@ lua_cryptobox_encrypt_file(lua_State *L) res->flags = RSPAMD_TEXT_FLAG_OWN; res->start = out; res->len = outlen; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); munmap(data, len); if (own_pk) { rspamd_pubkey_unref(pk); @@ -2208,7 +2208,7 @@ lua_cryptobox_decrypt_memory(lua_State *L) res->flags = RSPAMD_TEXT_FLAG_OWN; res->start = out; res->len = outlen; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); } return 2; @@ -2256,7 +2256,7 @@ lua_cryptobox_decrypt_file(lua_State *L) res->flags = RSPAMD_TEXT_FLAG_OWN; res->start = out; res->len = outlen; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); } munmap(data, len); @@ -2619,7 +2619,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) b64_data = rspamd_encode_base64(data, len, -1, &b64_len); priv_out = lua_newuserdata(L, sizeof(*priv_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); priv_out->start = b64_data; priv_out->len = b64_len; priv_out->flags = RSPAMD_TEXT_FLAG_OWN | RSPAMD_TEXT_FLAG_WIPE; @@ -2642,7 +2642,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) b64_data = rspamd_encode_base64(data, len, -1, &b64_len); pub_out = lua_newuserdata(L, sizeof(*pub_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); pub_out->start = b64_data; pub_out->len = b64_len; pub_out->flags = RSPAMD_TEXT_FLAG_OWN; @@ -2666,7 +2666,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) -1, &b64_len); priv_out = lua_newuserdata(L, sizeof(*priv_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); priv_out->start = b64_data; priv_out->len = b64_len; priv_out->flags = RSPAMD_TEXT_FLAG_OWN | RSPAMD_TEXT_FLAG_WIPE; @@ -2677,7 +2677,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) -1, &b64_len); pub_out = lua_newuserdata(L, sizeof(*pub_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); pub_out->start = b64_data; pub_out->len = b64_len; pub_out->flags = RSPAMD_TEXT_FLAG_OWN; @@ -2699,7 +2699,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) -1, &b64_len); priv_out = lua_newuserdata(L, sizeof(*priv_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); priv_out->start = b64_data; priv_out->len = b64_len; priv_out->flags = RSPAMD_TEXT_FLAG_OWN | RSPAMD_TEXT_FLAG_WIPE; @@ -2710,7 +2710,7 @@ lua_cryptobox_gen_dkim_keypair(lua_State *L) -1, &b64_len); pub_out = lua_newuserdata(L, sizeof(*pub_out)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); pub_out->start = b64_data; pub_out->len = b64_len; pub_out->flags = RSPAMD_TEXT_FLAG_OWN; @@ -2774,7 +2774,7 @@ lua_cryptobox_secretbox_create(lua_State *L) crypto_generichash(sbox->sk, sizeof(sbox->sk), in, inlen, NULL, 0); psbox = lua_newuserdata(L, sizeof(*psbox)); *psbox = sbox; - rspamd_lua_setclass(L, "rspamd{cryptobox_secretbox}", -1); + rspamd_lua_setclass(L, rspamd_cryptobox_secretbox_classname, -1); return 1; } @@ -3037,23 +3037,23 @@ lua_load_cryptobox(lua_State *L) void luaopen_cryptobox(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{cryptobox_pubkey}", cryptoboxpubkeylib_m); + rspamd_lua_new_class(L, rspamd_cryptobox_pubkey_classname, cryptoboxpubkeylib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cryptobox_pubkey", lua_load_pubkey); - rspamd_lua_new_class(L, "rspamd{cryptobox_keypair}", cryptoboxkeypairlib_m); + rspamd_lua_new_class(L, rspamd_cryptobox_keypair_classname, cryptoboxkeypairlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cryptobox_keypair", lua_load_keypair); - rspamd_lua_new_class(L, "rspamd{cryptobox_signature}", cryptoboxsignlib_m); + rspamd_lua_new_class(L, rspamd_cryptobox_signature_classname, cryptoboxsignlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cryptobox_signature", lua_load_signature); - rspamd_lua_new_class(L, "rspamd{cryptobox_hash}", cryptoboxhashlib_m); + rspamd_lua_new_class(L, rspamd_cryptobox_hash_classname, cryptoboxhashlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cryptobox_hash", lua_load_hash); - rspamd_lua_new_class(L, "rspamd{cryptobox_secretbox}", + rspamd_lua_new_class(L, rspamd_cryptobox_secretbox_classname, cryptoboxsecretboxlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_cryptobox_secretbox", diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c index b022e1370..6c2d4f672 100644 --- a/src/lua/lua_dns_resolver.c +++ b/src/lua/lua_dns_resolver.c @@ -73,7 +73,7 @@ static const struct luaL_reg dns_resolverlib_m[] = { struct rspamd_dns_resolver * lua_check_dns_resolver(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{resolver}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_resolver_classname); luaL_argcheck(L, ud != NULL, pos, "'resolver' expected"); return ud ? *((struct rspamd_dns_resolver **) ud) : NULL; } @@ -133,7 +133,7 @@ lua_dns_resolver_callback(struct rdns_reply *reply, gpointer arg) lua_rawgeti(L, LUA_REGISTRYINDEX, cd->cbref); presolver = lua_newuserdata(L, sizeof(gpointer)); - rspamd_lua_setclass(L, "rspamd{resolver}", -1); + rspamd_lua_setclass(L, rspamd_resolver_classname, -1); *presolver = cd->resolver; lua_pushstring(L, cd->to_resolve); @@ -304,10 +304,10 @@ lua_dns_resolver_init(lua_State *L) struct ev_loop *base, **pbase; /* Check args */ - pbase = rspamd_lua_check_udata(L, 1, "rspamd{ev_base}"); + pbase = rspamd_lua_check_udata(L, 1, rspamd_ev_base_classname); luaL_argcheck(L, pbase != NULL, 1, "'ev_base' expected"); base = pbase ? *(pbase) : NULL; - pcfg = rspamd_lua_check_udata(L, 2, "rspamd{config}"); + pcfg = rspamd_lua_check_udata(L, 2, rspamd_config_classname); luaL_argcheck(L, pcfg != NULL, 2, "'config' expected"); cfg = pcfg ? *(pcfg) : NULL; @@ -315,7 +315,7 @@ lua_dns_resolver_init(lua_State *L) resolver = rspamd_dns_resolver_init(NULL, base, cfg); if (resolver) { presolver = lua_newuserdata(L, sizeof(gpointer)); - rspamd_lua_setclass(L, "rspamd{resolver}", -1); + rspamd_lua_setclass(L, rspamd_resolver_classname, -1); *presolver = resolver; } else { @@ -692,7 +692,7 @@ lua_dns_resolver_idna_convert_utf8(lua_State *L) guint conv_len = 0; const gchar *hname = luaL_checklstring(L, 2, &hlen); gchar *converted; - rspamd_mempool_t *pool = rspamd_lua_check_udata_maybe(L, 3, "rspamd{mempool}"); + rspamd_mempool_t *pool = rspamd_lua_check_udata_maybe(L, 3, rspamd_mempool_classname); if (dns_resolver && hname) { @@ -735,7 +735,7 @@ lua_load_dns_resolver(lua_State *L) void luaopen_dns_resolver(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{resolver}", dns_resolverlib_m); + rspamd_lua_new_class(L, rspamd_resolver_classname, dns_resolverlib_m); { LUA_ENUM(L, DNS_A, RDNS_REQUEST_A); LUA_ENUM(L, DNS_PTR, RDNS_REQUEST_PTR); diff --git a/src/lua/lua_expression.c b/src/lua/lua_expression.c index 1ac6f864c..b3c725376 100644 --- a/src/lua/lua_expression.c +++ b/src/lua/lua_expression.c @@ -123,7 +123,7 @@ lua_expr_quark(void) struct lua_expression * rspamd_lua_expression(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{expr}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_expr_classname); luaL_argcheck(L, ud != NULL, pos, "'expr' expected"); return ud ? *((struct lua_expression **) ud) : NULL; } @@ -429,7 +429,7 @@ lua_expr_create(lua_State *L) rspamd_mempool_add_destructor(pool, lua_expr_dtor, e); pe = lua_newuserdata(L, sizeof(struct lua_expression *)); - rspamd_lua_setclass(L, "rspamd{expr}", -1); + rspamd_lua_setclass(L, rspamd_expr_classname, -1); *pe = e; lua_pushnil(L); } @@ -506,7 +506,7 @@ lua_load_expression(lua_State *L) void luaopen_expression(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{expr}", exprlib_m); + rspamd_lua_new_class(L, rspamd_expr_classname, exprlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_expression", lua_load_expression); } diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx index 661333700..67dbe9738 100644 --- a/src/lua/lua_html.cxx +++ b/src/lua/lua_html.cxx @@ -194,7 +194,7 @@ static const struct luaL_reg taglib_m[] = { static struct rspamd::html::html_content * lua_check_html(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{html}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_classname); luaL_argcheck(L, ud != NULL, pos, "'html' expected"); return ud ? *((struct rspamd::html::html_content **) ud) : NULL; } @@ -207,7 +207,7 @@ struct lua_html_tag { static struct lua_html_tag * lua_check_html_tag(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{html_tag}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_html_tag_classname); luaL_argcheck(L, ud != NULL, pos, "'html_tag' expected"); return ud ? ((struct lua_html_tag *) ud) : NULL; } @@ -286,7 +286,7 @@ lua_html_push_image(lua_State *L, const struct html_image *img) t->len = strlen(img->src); t->flags = 0; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); } else { lua_pushstring(L, img->src); @@ -299,7 +299,7 @@ lua_html_push_image(lua_State *L, const struct html_image *img) lua_pushstring(L, "url"); purl = static_cast<rspamd_url **>(lua_newuserdata(L, sizeof(gpointer))); *purl = img->url; - rspamd_lua_setclass(L, "rspamd{url}", -1); + rspamd_lua_setclass(L, rspamd_url_classname, -1); lua_settable(L, -3); } @@ -308,7 +308,7 @@ lua_html_push_image(lua_State *L, const struct html_image *img) ltag = static_cast<lua_html_tag *>(lua_newuserdata(L, sizeof(struct lua_html_tag))); ltag->tag = static_cast<rspamd::html::html_tag *>(img->tag); ltag->html = NULL; - rspamd_lua_setclass(L, "rspamd{html_tag}", -1); + rspamd_lua_setclass(L, rspamd_html_tag_classname, -1); lua_settable(L, -3); } @@ -456,7 +456,7 @@ lua_html_foreach_tag(lua_State *L) ltag->tag = tag; ltag->html = hc; auto ct = ltag->tag->get_content(hc); - rspamd_lua_setclass(L, "rspamd{html_tag}", -1); + rspamd_lua_setclass(L, rspamd_html_tag_classname, -1); lua_pushinteger(L, ct.size()); /* Leaf flag */ @@ -544,7 +544,7 @@ lua_html_tag_get_parent(lua_State *L) ptag = static_cast<lua_html_tag *>(lua_newuserdata(L, sizeof(*ptag))); ptag->tag = static_cast<rspamd::html::html_tag *>(parent); ptag->html = ltag->html; - rspamd_lua_setclass(L, "rspamd{html_tag}", -1); + rspamd_lua_setclass(L, rspamd_html_tag_classname, -1); } else { lua_pushnil(L); @@ -608,7 +608,7 @@ lua_html_tag_get_content(lua_State *L) auto ct = ltag->tag->get_content(ltag->html); if (ct.size() > 0) { t = static_cast<rspamd_lua_text *>(lua_newuserdata(L, sizeof(*t))); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = ct.data(); t->len = ct.size(); t->flags = 0; @@ -667,7 +667,7 @@ lua_html_tag_get_extra(lua_State *L) /* For A that's URL */ auto *lua_url = static_cast<rspamd_lua_url *>(lua_newuserdata(L, sizeof(rspamd_lua_url))); lua_url->url = std::get<struct rspamd_url *>(ltag->tag->extra); - rspamd_lua_setclass(L, "rspamd{url}", -1); + rspamd_lua_setclass(L, rspamd_url_classname, -1); } else { /* Unknown extra ? */ @@ -731,8 +731,8 @@ lua_html_tag_get_attribute(lua_State *L) void luaopen_html(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{html}", htmllib_m); + rspamd_lua_new_class(L, rspamd_html_classname, htmllib_m); lua_pop(L, 1); - rspamd_lua_new_class(L, "rspamd{html_tag}", taglib_m); + rspamd_lua_new_class(L, rspamd_html_tag_classname, taglib_m); lua_pop(L, 1); } diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index 713082ac5..4c0596885 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -278,7 +278,7 @@ lua_http_finish_handler(struct rspamd_http_connection *conn, struct rspamd_lua_text *t; t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = body; t->len = body_len; t->flags = 0; @@ -363,7 +363,7 @@ lua_http_resume_handler(struct rspamd_http_connection *conn, struct rspamd_lua_text *t; t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = body; t->len = body_len; t->flags = 0; @@ -653,21 +653,21 @@ lua_http_request(lua_State *L) lua_pushvalue(L, 2); cbref = luaL_ref(L, LUA_REGISTRYINDEX); - if (lua_gettop(L) >= 3 && rspamd_lua_check_udata_maybe(L, 3, "rspamd{ev_base}")) { + if (lua_gettop(L) >= 3 && rspamd_lua_check_udata_maybe(L, 3, rspamd_ev_base_classname)) { ev_base = *(struct ev_loop **) lua_touserdata(L, 3); } else { ev_base = NULL; } - if (lua_gettop(L) >= 4 && rspamd_lua_check_udata_maybe(L, 4, "rspamd{resolver}")) { + if (lua_gettop(L) >= 4 && rspamd_lua_check_udata_maybe(L, 4, rspamd_resolver_classname)) { resolver = *(struct rspamd_dns_resolver **) lua_touserdata(L, 4); } else { resolver = lua_http_global_resolver(ev_base); } - if (lua_gettop(L) >= 5 && rspamd_lua_check_udata_maybe(L, 5, "rspamd{session}")) { + if (lua_gettop(L) >= 5 && rspamd_lua_check_udata_maybe(L, 5, rspamd_session_classname)) { session = *(struct rspamd_async_session **) lua_touserdata(L, 5); } else { @@ -722,7 +722,7 @@ lua_http_request(lua_State *L) if (task == NULL) { lua_pushstring(L, "ev_base"); lua_gettable(L, 1); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{ev_base}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_ev_base_classname)) { ev_base = *(struct ev_loop **) lua_touserdata(L, -1); } else { @@ -733,7 +733,7 @@ lua_http_request(lua_State *L) lua_pushstring(L, "session"); lua_gettable(L, 1); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{session}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_session_classname)) { session = *(struct rspamd_async_session **) lua_touserdata(L, -1); } else { @@ -743,7 +743,7 @@ lua_http_request(lua_State *L) lua_pushstring(L, "config"); lua_gettable(L, 1); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{config}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_config_classname)) { cfg = *(struct rspamd_config **) lua_touserdata(L, -1); } else { @@ -755,7 +755,7 @@ lua_http_request(lua_State *L) lua_pushstring(L, "resolver"); lua_gettable(L, 1); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{resolver}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_resolver_classname)) { resolver = *(struct rspamd_dns_resolver **) lua_touserdata(L, -1); } else { diff --git a/src/lua/lua_ip.c b/src/lua/lua_ip.c index ac24dc52b..6c0dcb069 100644 --- a/src/lua/lua_ip.c +++ b/src/lua/lua_ip.c @@ -212,7 +212,7 @@ lua_ip_new(lua_State *L, struct rspamd_lua_ip *old) } pip = lua_newuserdata(L, sizeof(struct rspamd_lua_ip *)); - rspamd_lua_setclass(L, "rspamd{ip}", -1); + rspamd_lua_setclass(L, rspamd_ip_classname, -1); *pip = ip; @@ -222,7 +222,7 @@ lua_ip_new(lua_State *L, struct rspamd_lua_ip *old) struct rspamd_lua_ip * lua_check_ip(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{ip}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_ip_classname); luaL_argcheck(L, ud != NULL, pos, "'ip' expected"); return ud ? *((struct rspamd_lua_ip **) ud) : NULL; @@ -588,7 +588,7 @@ void rspamd_lua_ip_push(lua_State *L, rspamd_inet_addr_t *addr) ip = g_malloc0(sizeof(struct rspamd_lua_ip)); ip->addr = rspamd_inet_address_copy(addr, NULL); pip = lua_newuserdata(L, sizeof(struct rspamd_lua_ip *)); - rspamd_lua_setclass(L, "rspamd{ip}", -1); + rspamd_lua_setclass(L, rspamd_ip_classname, -1); *pip = ip; } else { @@ -610,7 +610,7 @@ void rspamd_lua_ip_push_fromstring(lua_State *L, const gchar *ip_str) ip_str, strlen(ip_str), RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) { pip = lua_newuserdata(L, sizeof(struct rspamd_lua_ip *)); - rspamd_lua_setclass(L, "rspamd{ip}", -1); + rspamd_lua_setclass(L, rspamd_ip_classname, -1); *pip = ip; } else { @@ -631,7 +631,7 @@ lua_load_ip(lua_State *L) void luaopen_ip(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{ip}", iplib_m); + rspamd_lua_new_class(L, rspamd_ip_classname, iplib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_ip", lua_load_ip); } diff --git a/src/lua/lua_kann.c b/src/lua/lua_kann.c index e42fbfbc5..9e033b40e 100644 --- a/src/lua/lua_kann.c +++ b/src/lua/lua_kann.c @@ -23,8 +23,8 @@ * `rspamd_kann` is a Lua interface to kann library */ -#define KANN_NODE_CLASS "rspamd{kann_node}" -#define KANN_NETWORK_CLASS "rspamd{kann}" +#define KANN_NODE_CLASS rspamd_kann_node_classname +#define KANN_NETWORK_CLASS rspamd_kann_classname /* Simple macros to define behaviour */ #define KANN_LAYER_DEF(name) static int lua_kann_layer_##name(lua_State *L) @@ -928,7 +928,7 @@ lua_kann_save(lua_State *L) fclose(f); t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->flags = RSPAMD_TEXT_FLAG_OWN; t->start = (const gchar *) buf; t->len = buflen; diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index b9969b86b..9a0dacf46 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -664,7 +664,7 @@ lua_logger_get_id(lua_State *L, gint pos, GError **err) EINVAL, "invalid rspamd{task}"); } } - else if (strcmp(clsname, "rspamd{mempool}") == 0) { + else if (strcmp(clsname, rspamd_mempool_classname) == 0) { rspamd_mempool_t *pool; pool = rspamd_lua_check_mempool(L, pos); @@ -677,7 +677,7 @@ lua_logger_get_id(lua_State *L, gint pos, GError **err) EINVAL, "invalid rspamd{mempool}"); } } - else if (strcmp(clsname, "rspamd{config}") == 0) { + else if (strcmp(clsname, rspamd_config_classname) == 0) { struct rspamd_config *cfg; cfg = lua_check_config(L, pos); @@ -692,7 +692,7 @@ lua_logger_get_id(lua_State *L, gint pos, GError **err) EINVAL, "invalid rspamd{config}"); } } - else if (strcmp(clsname, "rspamd{map}") == 0) { + else if (strcmp(clsname, rspamd_map_classname) == 0) { struct rspamd_lua_map *map; map = lua_check_map(L, pos); diff --git a/src/lua/lua_map.c b/src/lua/lua_map.c index 54cfb4b00..cf4275038 100644 --- a/src/lua/lua_map.c +++ b/src/lua/lua_map.c @@ -183,7 +183,7 @@ struct lua_map_callback_data { struct rspamd_lua_map * lua_check_map(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{map}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_map_classname); luaL_argcheck(L, ud != NULL, pos, "'map' expected"); return ud ? *((struct rspamd_lua_map **) ud) : NULL; } @@ -219,7 +219,7 @@ gint lua_config_add_radix_map(lua_State *L) m->lua_map = map; pmap = lua_newuserdata(L, sizeof(void *)); *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -277,7 +277,7 @@ gint lua_config_radix_from_config(lua_State *L) map->map = m; m->lua_map = map; *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { msg_warn_config("Couldnt find config option [%s][%s]", mname, @@ -339,7 +339,7 @@ gint lua_config_radix_from_ucl(lua_State *L) map->map = m; m->lua_map = map; *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -378,7 +378,7 @@ gint lua_config_add_hash_map(lua_State *L) m->lua_map = map; pmap = lua_newuserdata(L, sizeof(void *)); *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -418,7 +418,7 @@ gint lua_config_add_kv_map(lua_State *L) m->lua_map = map; pmap = lua_newuserdata(L, sizeof(void *)); *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -507,7 +507,7 @@ lua_map_fin(struct map_cb_data *data, void **target) struct rspamd_lua_text *t; t = lua_newuserdata(cbdata->L, sizeof(*t)); - rspamd_lua_setclass(cbdata->L, "rspamd{text}", -1); + rspamd_lua_setclass(cbdata->L, rspamd_text_classname, -1); t->flags = 0; t->len = cbdata->data->len; t->start = cbdata->data->str; @@ -515,7 +515,7 @@ lua_map_fin(struct map_cb_data *data, void **target) pmap = lua_newuserdata(cbdata->L, sizeof(void *)); *pmap = cbdata->lua_map; - rspamd_lua_setclass(cbdata->L, "rspamd{map}", -1); + rspamd_lua_setclass(cbdata->L, rspamd_map_classname, -1); gint ret = lua_pcall(cbdata->L, 2, 0, err_idx); @@ -781,7 +781,7 @@ gint lua_config_add_map(lua_State *L) map->map = m; pmap = lua_newuserdata(L, sizeof(void *)); *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -833,7 +833,7 @@ gint lua_config_get_maps(lua_State *L) pmap = lua_newuserdata(L, sizeof(*pmap)); *pmap = map; - rspamd_lua_setclass(L, "rspamd{map}", -1); + rspamd_lua_setclass(L, rspamd_map_classname, -1); lua_rawseti(L, -2, i); cur = g_list_next(cur); @@ -897,7 +897,7 @@ lua_map_get_key(lua_State *L) } } else if (lua_type(L, 2) == LUA_TUSERDATA) { - ud = rspamd_lua_check_udata(L, 2, "rspamd{ip}"); + ud = rspamd_lua_check_udata(L, 2, rspamd_ip_classname); if (ud != NULL) { addr = *((struct rspamd_lua_ip **) ud); @@ -1415,7 +1415,7 @@ lua_map_on_load(lua_State *L) void luaopen_map(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{map}", maplib_m); + rspamd_lua_new_class(L, rspamd_map_classname, maplib_m); lua_pop(L, 1); } diff --git a/src/lua/lua_mempool.c b/src/lua/lua_mempool.c index 4897d1542..bb855710f 100644 --- a/src/lua/lua_mempool.c +++ b/src/lua/lua_mempool.c @@ -149,7 +149,7 @@ struct lua_mempool_udata { struct memory_pool_s * rspamd_lua_check_mempool(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{mempool}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_mempool_classname); luaL_argcheck(L, ud != NULL, pos, "'mempool' expected"); return ud ? *((struct memory_pool_s **) ud) : NULL; } @@ -165,7 +165,7 @@ lua_mempool_create(lua_State *L) if (mempool) { pmempool = lua_newuserdata(L, sizeof(struct memory_pool_s *)); - rspamd_lua_setclass(L, "rspamd{mempool}", -1); + rspamd_lua_setclass(L, rspamd_mempool_classname, -1); *pmempool = mempool; } else { @@ -606,7 +606,7 @@ lua_load_mempool(lua_State *L) void luaopen_mempool(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{mempool}", mempoollib_m); + rspamd_lua_new_class(L, rspamd_mempool_classname, mempoollib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_mempool", lua_load_mempool); } diff --git a/src/lua/lua_mimepart.c b/src/lua/lua_mimepart.c index 5d4b8b74d..6c38a1275 100644 --- a/src/lua/lua_mimepart.c +++ b/src/lua/lua_mimepart.c @@ -609,7 +609,7 @@ static const struct luaL_reg mimepartlib_m[] = { static struct rspamd_mime_text_part * lua_check_textpart(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{textpart}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_textpart_classname); luaL_argcheck(L, ud != NULL, 1, "'textpart' expected"); return ud ? *((struct rspamd_mime_text_part **) ud) : NULL; } @@ -617,7 +617,7 @@ lua_check_textpart(lua_State *L) static struct rspamd_mime_part * lua_check_mimepart(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{mimepart}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_mimepart_classname); luaL_argcheck(L, ud != NULL, 1, "'mimepart' expected"); return ud ? *((struct rspamd_mime_part **) ud) : NULL; } @@ -759,7 +759,7 @@ lua_textpart_get_content(lua_State *L) } t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = start; t->len = len; @@ -781,7 +781,7 @@ lua_textpart_get_raw_content(lua_State *L) } t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = part->raw.begin; t->len = part->raw.len; t->flags = 0; @@ -1095,7 +1095,7 @@ lua_textpart_get_html(lua_State *L) } else { phc = lua_newuserdata(L, sizeof(*phc)); - rspamd_lua_setclass(L, "rspamd{html}", -1); + rspamd_lua_setclass(L, rspamd_html_classname, -1); *phc = part->html; } @@ -1328,7 +1328,7 @@ lua_textpart_get_mimepart(lua_State *L) if (part != NULL) { if (part->mime_part != NULL) { pmime = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); *pmime = part->mime_part; return 1; @@ -1410,7 +1410,7 @@ lua_mimepart_get_content(lua_State *L) } t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = part->parsed_data.begin; t->len = part->parsed_data.len; t->flags = 0; @@ -1435,7 +1435,7 @@ lua_mimepart_get_raw_content(lua_State *L) } t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = part->raw_data.begin; t->len = part->raw_data.len; t->flags = 0; @@ -1733,7 +1733,7 @@ lua_mimepart_get_raw_headers(lua_State *L) if (part) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = part->raw_headers_str; t->len = part->raw_headers_len; t->flags = 0; @@ -1932,7 +1932,7 @@ lua_mimepart_get_image(lua_State *L) else { pimg = lua_newuserdata(L, sizeof(*pimg)); *pimg = part->specific.img; - rspamd_lua_setclass(L, "rspamd{image}", -1); + rspamd_lua_setclass(L, rspamd_image_classname, -1); } return 1; @@ -1955,7 +1955,7 @@ lua_mimepart_get_archive(lua_State *L) else { parch = lua_newuserdata(L, sizeof(*parch)); *parch = part->specific.arch; - rspamd_lua_setclass(L, "rspamd{archive}", -1); + rspamd_lua_setclass(L, rspamd_archive_classname, -1); } return 1; @@ -1983,7 +1983,7 @@ lua_mimepart_get_children(lua_State *L) { pcur = lua_newuserdata(L, sizeof(*pcur)); *pcur = cur; - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); lua_rawseti(L, -2, i + 1); } } @@ -2005,7 +2005,7 @@ lua_mimepart_get_parent(lua_State *L) if (part->parent_part) { pparent = lua_newuserdata(L, sizeof(*pparent)); *pparent = part->parent_part; - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); } else { lua_pushnil(L); @@ -2032,7 +2032,7 @@ lua_mimepart_get_text(lua_State *L) else { ppart = lua_newuserdata(L, sizeof(*ppart)); *ppart = part->specific.txt; - rspamd_lua_setclass(L, "rspamd{textpart}", -1); + rspamd_lua_setclass(L, rspamd_textpart_classname, -1); } return 1; @@ -2106,7 +2106,7 @@ lua_mimepart_headers_foreach(lua_State *L) lua_gettable(L, 3); if (lua_isuserdata(L, -1)) { - RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, -1, "rspamd{regexp}", + RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, -1, rspamd_regexp_classname, struct rspamd_lua_regexp, re); } @@ -2273,7 +2273,7 @@ lua_mimepart_set_specific(lua_State *L) part->specific.lua_specific.type = RSPAMD_LUA_PART_STRING; break; case LUA_TUSERDATA: - if (rspamd_lua_check_udata_maybe(L, 2, "rspamd{text}")) { + if (rspamd_lua_check_udata_maybe(L, 2, rspamd_text_classname)) { part->specific.lua_specific.type = RSPAMD_LUA_PART_TEXT; } else { @@ -2293,12 +2293,12 @@ lua_mimepart_set_specific(lua_State *L) void luaopen_textpart(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{textpart}", textpartlib_m); + rspamd_lua_new_class(L, rspamd_textpart_classname, textpartlib_m); lua_pop(L, 1); } void luaopen_mimepart(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{mimepart}", mimepartlib_m); + rspamd_lua_new_class(L, rspamd_mimepart_classname, mimepartlib_m); lua_pop(L, 1); } diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c index 1ad3b3d17..761aa5f94 100644 --- a/src/lua/lua_redis.c +++ b/src/lua/lua_redis.c @@ -159,7 +159,7 @@ struct lua_redis_result { static struct lua_redis_ctx * lua_check_redis(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{redis}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_redis_classname); luaL_argcheck(L, ud != NULL, pos, "'redis' expected"); return ud ? *((struct lua_redis_ctx **) ud) : NULL; } @@ -350,7 +350,7 @@ lua_redis_push_reply(lua_State *L, const redisReply *r, gboolean text_data) case REDIS_REPLY_STATUS: if (text_data) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->flags = 0; t->start = r->str; t->len = r->len; @@ -1206,7 +1206,7 @@ lua_redis_make_request(lua_State *L) if (ret) { pctx = lua_newuserdata(L, sizeof(ctx)); *pctx = ctx; - rspamd_lua_setclass(L, "rspamd{redis}", -1); + rspamd_lua_setclass(L, rspamd_redis_classname, -1); } else { lua_pushnil(L); @@ -1402,7 +1402,7 @@ lua_redis_connect(lua_State *L) lua_pushboolean(L, TRUE); pctx = lua_newuserdata(L, sizeof(ctx)); *pctx = ctx; - rspamd_lua_setclass(L, "rspamd{redis}", -1); + rspamd_lua_setclass(L, rspamd_redis_classname, -1); return 2; } @@ -1438,7 +1438,7 @@ lua_redis_connect_sync(lua_State *L) lua_pushboolean(L, TRUE); pctx = lua_newuserdata(L, sizeof(ctx)); *pctx = ctx; - rspamd_lua_setclass(L, "rspamd{redis}", -1); + rspamd_lua_setclass(L, rspamd_redis_classname, -1); } else { lua_pushboolean(L, FALSE); @@ -1649,7 +1649,7 @@ lua_redis_null_mt(lua_State *L) */ void luaopen_redis(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{redis}", redislib_m); + rspamd_lua_new_class(L, rspamd_redis_classname, redislib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_redis", lua_load_redis); diff --git a/src/lua/lua_regexp.c b/src/lua/lua_regexp.c index 7e638cade..3623b7dd2 100644 --- a/src/lua/lua_regexp.c +++ b/src/lua/lua_regexp.c @@ -73,7 +73,7 @@ rspamd_mempool_t *regexp_static_pool = NULL; struct rspamd_lua_regexp * lua_check_regexp(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{regexp}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_regexp_classname); luaL_argcheck(L, ud != NULL, pos, "'regexp' expected"); return ud ? *((struct rspamd_lua_regexp **) ud) : NULL; @@ -119,7 +119,7 @@ lua_regexp_create(lua_State *L) new->re_pattern = g_strdup(string); new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } } @@ -178,7 +178,7 @@ lua_regexp_import_glob(lua_State *L) new->re_pattern = escaped; new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } } @@ -237,7 +237,7 @@ lua_regexp_import_plain(lua_State *L) new->re_pattern = escaped; new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } } @@ -278,7 +278,7 @@ lua_regexp_get_cached(lua_State *L) new->re_pattern = g_strdup(string); new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } else { @@ -331,7 +331,7 @@ lua_regexp_create_cached(lua_State *L) new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } else { @@ -349,7 +349,7 @@ lua_regexp_create_cached(lua_State *L) new->re_pattern = g_strdup(string); new->module = rspamd_lua_get_module_name(L); pnew = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pnew = new; } } @@ -740,7 +740,7 @@ lua_regexp_split(lua_State *L) } else { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = old_start; t->len = start - old_start; t->flags = 0; @@ -765,7 +765,7 @@ lua_regexp_split(lua_State *L) } else { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = end; t->len = (data + len) - end; t->flags = 0; @@ -845,7 +845,7 @@ void luaopen_regexp(lua_State *L) "regexp_lua_pool", 0); } - rspamd_lua_new_class(L, "rspamd{regexp}", regexplib_m); + rspamd_lua_new_class(L, rspamd_regexp_classname, regexplib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_regexp", lua_load_regexp); } diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c index ae5acc8a8..c2ea39fa5 100644 --- a/src/lua/lua_rsa.c +++ b/src/lua/lua_rsa.c @@ -94,7 +94,7 @@ static const struct luaL_reg rsasignlib_m[] = { static RSA * lua_check_rsa_pubkey(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{rsa_pubkey}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_rsa_pubkey_classname); luaL_argcheck(L, ud != NULL, 1, "'rsa_pubkey' expected"); return ud ? *((RSA **) ud) : NULL; @@ -103,7 +103,7 @@ lua_check_rsa_pubkey(lua_State *L, int pos) static RSA * lua_check_rsa_privkey(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{rsa_privkey}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_rsa_privkey_classname); luaL_argcheck(L, ud != NULL, 1, "'rsa_privkey' expected"); return ud ? *((RSA **) ud) : NULL; @@ -112,7 +112,7 @@ lua_check_rsa_privkey(lua_State *L, int pos) static rspamd_fstring_t * lua_check_rsa_sign(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{rsa_signature}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_rsa_signature_classname); luaL_argcheck(L, ud != NULL, 1, "'rsa_signature' expected"); return ud ? *((rspamd_fstring_t **) ud) : NULL; @@ -142,7 +142,7 @@ lua_rsa_pubkey_load(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_pubkey_classname, -1); *prsa = rsa; } fclose(f); @@ -238,7 +238,7 @@ lua_rsa_pubkey_create(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_pubkey_classname, -1); *prsa = rsa; } BIO_free(bp); @@ -313,7 +313,7 @@ lua_rsa_privkey_load_file(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = rsa; } fclose(f); @@ -358,7 +358,7 @@ lua_rsa_privkey_load_pem(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = rsa; } @@ -405,7 +405,7 @@ lua_rsa_privkey_load_raw(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = rsa; } @@ -464,7 +464,7 @@ lua_rsa_privkey_load_base64(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = rsa; } @@ -504,7 +504,7 @@ lua_rsa_privkey_create(lua_State *L) } else { prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = rsa; } BIO_free(bp); @@ -554,7 +554,7 @@ lua_rsa_signature_load(lua_State *L) else { sig = rspamd_fstring_new_init(data, st.st_size); psig = lua_newuserdata(L, sizeof(rspamd_fstring_t *)); - rspamd_lua_setclass(L, "rspamd{rsa_signature}", -1); + rspamd_lua_setclass(L, rspamd_rsa_signature_classname, -1); *psig = sig; munmap(data, st.st_size); } @@ -629,7 +629,7 @@ lua_rsa_signature_create(lua_State *L) if (data != NULL) { sig = rspamd_fstring_new_init(data, dlen); psig = lua_newuserdata(L, sizeof(rspamd_fstring_t *)); - rspamd_lua_setclass(L, "rspamd{rsa_signature}", -1); + rspamd_lua_setclass(L, rspamd_rsa_signature_classname, -1); *psig = sig; } @@ -768,7 +768,7 @@ lua_rsa_sign_memory(lua_State *L) else { signature->len = siglen; psig = lua_newuserdata(L, sizeof(rspamd_fstring_t *)); - rspamd_lua_setclass(L, "rspamd{rsa_signature}", -1); + rspamd_lua_setclass(L, rspamd_rsa_signature_classname, -1); *psig = signature; } } @@ -797,12 +797,12 @@ lua_rsa_keypair(lua_State *L) priv_rsa = RSAPrivateKey_dup(rsa); prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_privkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_privkey_classname, -1); *prsa = priv_rsa; pub_rsa = RSAPublicKey_dup(rsa); prsa = lua_newuserdata(L, sizeof(RSA *)); - rspamd_lua_setclass(L, "rspamd{rsa_pubkey}", -1); + rspamd_lua_setclass(L, rspamd_rsa_pubkey_classname, -1); *prsa = pub_rsa; RSA_free(rsa); @@ -849,15 +849,15 @@ lua_load_rsa(lua_State *L) void luaopen_rsa(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{rsa_pubkey}", rsapubkeylib_m); + rspamd_lua_new_class(L, rspamd_rsa_pubkey_classname, rsapubkeylib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_rsa_pubkey", lua_load_pubkey); - rspamd_lua_new_class(L, "rspamd{rsa_privkey}", rsaprivkeylib_m); + rspamd_lua_new_class(L, rspamd_rsa_privkey_classname, rsaprivkeylib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_rsa_privkey", lua_load_privkey); - rspamd_lua_new_class(L, "rspamd{rsa_signature}", rsasignlib_m); + rspamd_lua_new_class(L, rspamd_rsa_signature_classname, rsasignlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_rsa_signature", lua_load_signature); diff --git a/src/lua/lua_spf.c b/src/lua/lua_spf.c index a67a267fa..caea3e3b9 100644 --- a/src/lua/lua_spf.c +++ b/src/lua/lua_spf.c @@ -22,7 +22,7 @@ #include "libserver/spf.h" #include "libutil/ref.h" -#define SPF_RECORD_CLASS "rspamd{spf_record}" +#define SPF_RECORD_CLASS rspamd_spf_record_classname LUA_FUNCTION_DEF(spf, resolve); LUA_FUNCTION_DEF(spf, config); diff --git a/src/lua/lua_sqlite3.c b/src/lua/lua_sqlite3.c index be7a9aeea..dde39bd2e 100644 --- a/src/lua/lua_sqlite3.c +++ b/src/lua/lua_sqlite3.c @@ -64,7 +64,7 @@ static void lua_sqlite3_push_row(lua_State *L, sqlite3_stmt *stmt); static sqlite3 * lua_check_sqlite3(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{sqlite3}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_classname); luaL_argcheck(L, ud != NULL, pos, "'sqlite3' expected"); return ud ? *((sqlite3 **) ud) : NULL; } @@ -72,7 +72,7 @@ lua_check_sqlite3(lua_State *L, gint pos) static sqlite3_stmt * lua_check_sqlite3_stmt(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{sqlite3_stmt}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_sqlite3_stmt_classname); luaL_argcheck(L, ud != NULL, pos, "'sqlite3_stmt' expected"); return ud ? *((sqlite3_stmt **) ud) : NULL; } @@ -110,7 +110,7 @@ lua_sqlite3_open(lua_State *L) pdb = lua_newuserdata(L, sizeof(db)); *pdb = db; - rspamd_lua_setclass(L, "rspamd{sqlite3}", -1); + rspamd_lua_setclass(L, rspamd_sqlite3_classname, -1); return 1; } @@ -317,7 +317,7 @@ lua_sqlite3_rows(lua_State *L) /* Create C closure */ pstmt = lua_newuserdata(L, sizeof(stmt)); *pstmt = stmt; - rspamd_lua_setclass(L, "rspamd{sqlite3_stmt}", -1); + rspamd_lua_setclass(L, rspamd_sqlite3_stmt_classname, -1); lua_pushcclosure(L, lua_sqlite3_next_row, 1); } @@ -369,10 +369,10 @@ lua_load_sqlite3(lua_State *L) */ void luaopen_sqlite3(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{sqlite3}", sqlitelib_m); + rspamd_lua_new_class(L, rspamd_sqlite3_classname, sqlitelib_m); lua_pop(L, 1); - rspamd_lua_new_class(L, "rspamd{sqlite3_stmt}", sqlitestmtlib_m); + rspamd_lua_new_class(L, rspamd_sqlite3_stmt_classname, sqlitestmtlib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_sqlite3", lua_load_sqlite3); diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c index 79cf9c55e..cada9f952 100644 --- a/src/lua/lua_task.c +++ b/src/lua/lua_task.c @@ -1398,7 +1398,7 @@ lua_check_task_maybe(lua_State *L, gint pos) static struct rspamd_image * lua_check_image(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{image}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_image_classname); luaL_argcheck(L, ud != NULL, 1, "'image' expected"); return ud ? *((struct rspamd_image **) ud) : NULL; } @@ -1406,7 +1406,7 @@ lua_check_image(lua_State *L) static struct rspamd_archive * lua_check_archive(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{archive}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_archive_classname); luaL_argcheck(L, ud != NULL, 1, "'archive' expected"); return ud ? *((struct rspamd_archive **) ud) : NULL; } @@ -1505,7 +1505,7 @@ lua_task_get_cfg(lua_State *L) if (task) { pcfg = lua_newuserdata(L, sizeof(gpointer)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = task->cfg; } else { @@ -1520,7 +1520,7 @@ lua_task_set_cfg(lua_State *L) { LUA_TRACE_POINT; struct rspamd_task *task = lua_check_task(L, 1); - void *ud = rspamd_lua_check_udata(L, 2, "rspamd{config}"); + void *ud = rspamd_lua_check_udata(L, 2, rspamd_config_classname); if (task) { luaL_argcheck(L, ud != NULL, 1, "'config' expected"); @@ -1555,7 +1555,7 @@ lua_task_get_message(lua_State *L) if (task) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->flags = 0; t->start = task->msg.begin; t->len = task->msg.len; @@ -1719,7 +1719,7 @@ lua_task_load_from_file(lua_State *L) if (lua_type(L, 2) == LUA_TUSERDATA) { gpointer p; - p = rspamd_lua_check_udata_maybe(L, 2, "rspamd{config}"); + p = rspamd_lua_check_udata_maybe(L, 2, rspamd_config_classname); if (p) { cfg = *(struct rspamd_config **) p; @@ -1810,7 +1810,7 @@ lua_task_load_from_string(lua_State *L) if (lua_type(L, 2) == LUA_TUSERDATA) { gpointer p; - p = rspamd_lua_check_udata_maybe(L, 2, "rspamd{config}"); + p = rspamd_lua_check_udata_maybe(L, 2, rspamd_config_classname); if (p) { cfg = *(struct rspamd_config **) p; @@ -1847,7 +1847,7 @@ lua_task_create(lua_State *L) if (lua_type(L, 1) == LUA_TUSERDATA) { gpointer p; - p = rspamd_lua_check_udata_maybe(L, 1, "rspamd{config}"); + p = rspamd_lua_check_udata_maybe(L, 1, rspamd_config_classname); if (p) { cfg = *(struct rspamd_config **) p; @@ -1856,7 +1856,7 @@ lua_task_create(lua_State *L) if (lua_type(L, 2) == LUA_TUSERDATA) { gpointer p; - p = rspamd_lua_check_udata_maybe(L, 2, "rspamd{ev_base}"); + p = rspamd_lua_check_udata_maybe(L, 2, rspamd_ev_base_classname); if (p) { ev_base = *(struct ev_loop **) p; @@ -1882,7 +1882,7 @@ lua_task_get_mempool(lua_State *L) if (task != NULL) { ppool = lua_newuserdata(L, sizeof(rspamd_mempool_t *)); - rspamd_lua_setclass(L, "rspamd{mempool}", -1); + rspamd_lua_setclass(L, rspamd_mempool_classname, -1); *ppool = task->task_pool; } else { @@ -1901,7 +1901,7 @@ lua_task_get_session(lua_State *L) if (task != NULL) { psession = lua_newuserdata(L, sizeof(void *)); - rspamd_lua_setclass(L, "rspamd{session}", -1); + rspamd_lua_setclass(L, rspamd_session_classname, -1); *psession = task->s; } else { @@ -1935,7 +1935,7 @@ lua_task_get_ev_base(lua_State *L) if (task != NULL) { pbase = lua_newuserdata(L, sizeof(struct ev_loop *)); - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); *pbase = task->event_loop; } else { @@ -1954,7 +1954,7 @@ lua_task_get_worker(lua_State *L) if (task != NULL) { if (task->worker) { pworker = lua_newuserdata(L, sizeof(struct rspamd_worker *)); - rspamd_lua_setclass(L, "rspamd{worker}", -1); + rspamd_lua_setclass(L, rspamd_worker_classname, -1); *pworker = task->worker; } else { @@ -2636,7 +2636,7 @@ lua_task_inject_url(lua_State *L) if (lua_isuserdata(L, 3)) { /* We also have a mime part there */ mpart = *((struct rspamd_mime_part **) rspamd_lua_check_udata_maybe(L, - 3, "rspamd{mimepart}")); + 3, rspamd_mimepart_classname)); } if (task && task->message && url && url->url) { @@ -2663,7 +2663,7 @@ lua_task_get_content(lua_State *L) if (task) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->len = task->msg.len; t->start = task->msg.begin; t->flags = 0; @@ -2802,7 +2802,7 @@ lua_task_get_text_parts(lua_State *L) { ppart = lua_newuserdata(L, sizeof(struct rspamd_mime_text_part *)); *ppart = part; - rspamd_lua_setclass(L, "rspamd{textpart}", -1); + rspamd_lua_setclass(L, rspamd_textpart_classname, -1); /* Make it array */ lua_rawseti(L, -2, i + 1); } @@ -2837,7 +2837,7 @@ lua_task_get_parts(lua_State *L) { ppart = lua_newuserdata(L, sizeof(struct rspamd_mime_part *)); *ppart = part; - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); /* Make it array */ lua_rawseti(L, -2, i + 1); } @@ -2869,7 +2869,7 @@ lua_task_get_request_header(lua_State *L) if (hdr) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = hdr->begin; t->len = hdr->len; t->flags = 0; @@ -3181,7 +3181,7 @@ lua_task_get_raw_headers(lua_State *L) if (task && task->message) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = MESSAGE_FIELD(task, raw_headers_content).begin; t->len = MESSAGE_FIELD(task, raw_headers_content).len; t->flags = 0; @@ -3272,7 +3272,7 @@ lua_task_get_resolver(lua_State *L) if (task != NULL && task->resolver != NULL) { presolver = lua_newuserdata(L, sizeof(void *)); - rspamd_lua_setclass(L, "rspamd{resolver}", -1); + rspamd_lua_setclass(L, rspamd_resolver_classname, -1); *presolver = task->resolver; } else { @@ -4472,7 +4472,7 @@ lua_task_get_images(lua_State *L) { if (part->part_type == RSPAMD_MIME_PART_IMAGE) { pimg = lua_newuserdata(L, sizeof(struct rspamd_image *)); - rspamd_lua_setclass(L, "rspamd{image}", -1); + rspamd_lua_setclass(L, rspamd_image_classname, -1); *pimg = part->specific.img; lua_rawseti(L, -2, ++nelt); } @@ -4510,7 +4510,7 @@ lua_task_get_archives(lua_State *L) { if (part->part_type == RSPAMD_MIME_PART_ARCHIVE) { parch = lua_newuserdata(L, sizeof(struct rspamd_archive *)); - rspamd_lua_setclass(L, "rspamd{archive}", -1); + rspamd_lua_setclass(L, rspamd_archive_classname, -1); *parch = part->specific.arch; lua_rawseti(L, -2, ++nelt); } @@ -6685,7 +6685,7 @@ lua_task_headers_foreach(lua_State *L) lua_gettable(L, 3); if (lua_isuserdata(L, -1)) { - RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, -1, "rspamd{regexp}", + RSPAMD_LUA_CHECK_UDATA_PTR_OR_RETURN(L, -1, rspamd_regexp_classname, struct rspamd_lua_regexp, re); } @@ -7265,7 +7265,7 @@ lua_load_task(lua_State *L) static void luaopen_archive(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{archive}", archivelib_m); + rspamd_lua_new_class(L, rspamd_archive_classname, archivelib_m); lua_pop(L, 1); } @@ -7281,7 +7281,7 @@ void luaopen_task(lua_State *L) void luaopen_image(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{image}", imagelib_m); + rspamd_lua_new_class(L, rspamd_image_classname, imagelib_m); lua_pop(L, 1); } diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 45faa7964..7040e9f43 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -484,7 +484,7 @@ lua_tcp_fin(gpointer arg) static struct lua_tcp_cbdata * lua_check_tcp(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{tcp}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_classname); luaL_argcheck(L, ud != NULL, pos, "'tcp' expected"); return ud ? *((struct lua_tcp_cbdata **) ud) : NULL; } @@ -589,7 +589,7 @@ lua_tcp_push_error(struct lua_tcp_cbdata *cbd, gboolean is_fatal, /* Connection */ pcbd = lua_newuserdata(L, sizeof(*pcbd)); *pcbd = cbd; - rspamd_lua_setclass(L, "rspamd{tcp}", -1); + rspamd_lua_setclass(L, rspamd_tcp_classname, -1); TCP_RETAIN(cbd); if (cbd->item) { @@ -676,7 +676,7 @@ lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) if (hdl->type == LUA_WANT_READ) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = (const gchar *) str; t->len = len; t->flags = 0; @@ -688,7 +688,7 @@ lua_tcp_push_data(struct lua_tcp_cbdata *cbd, const guint8 *str, gsize len) /* Connection */ pcbd = lua_newuserdata(L, sizeof(*pcbd)); *pcbd = cbd; - rspamd_lua_setclass(L, "rspamd{tcp}", -1); + rspamd_lua_setclass(L, rspamd_tcp_classname, -1); TCP_RETAIN(cbd); @@ -792,7 +792,7 @@ lua_tcp_connect_helper(struct lua_tcp_cbdata *cbd) lua_thread_pool_set_running_entry(cbd->cfg->lua_thread_pool, cbd->thread); pcbd = lua_newuserdata(L, sizeof(*pcbd)); *pcbd = cbd; - rspamd_lua_setclass(L, "rspamd{tcp_sync}", -1); + rspamd_lua_setclass(L, rspamd_tcp_sync_classname, -1); msg_debug_tcp("tcp connected"); lua_tcp_shift_handler(cbd); @@ -1145,7 +1145,7 @@ lua_tcp_handler(int fd, short what, gpointer ud) pcbd = lua_newuserdata(L, sizeof(*pcbd)); *pcbd = cbd; TCP_RETAIN(cbd); - rspamd_lua_setclass(L, "rspamd{tcp}", -1); + rspamd_lua_setclass(L, rspamd_tcp_classname, -1); if (cbd->item) { rspamd_symcache_set_cur_item(cbd->task, cbd->item); @@ -1588,7 +1588,7 @@ lua_tcp_request(lua_State *L) if (task == NULL) { lua_pushstring(L, "ev_base"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{ev_base}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_ev_base_classname)) { event_loop = *(struct ev_loop **) lua_touserdata(L, -1); } else { @@ -1600,7 +1600,7 @@ lua_tcp_request(lua_State *L) lua_pushstring(L, "session"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{session}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_session_classname)) { session = *(struct rspamd_async_session **) lua_touserdata(L, -1); } else { @@ -1610,7 +1610,7 @@ lua_tcp_request(lua_State *L) lua_pushstring(L, "config"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{config}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_config_classname)) { cfg = *(struct rspamd_config **) lua_touserdata(L, -1); } else { @@ -1620,7 +1620,7 @@ lua_tcp_request(lua_State *L) lua_pushstring(L, "resolver"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{resolver}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_resolver_classname)) { resolver = *(struct rspamd_dns_resolver **) lua_touserdata(L, -1); } else { @@ -2318,7 +2318,7 @@ lua_tcp_shift_callback(lua_State *L) static struct lua_tcp_cbdata * lua_check_sync_tcp(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{tcp_sync}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_tcp_sync_classname); luaL_argcheck(L, ud != NULL, pos, "'tcp' expected"); return ud ? *((struct lua_tcp_cbdata **) ud) : NULL; } @@ -2560,7 +2560,7 @@ lua_load_tcp(lua_State *L) void luaopen_tcp(lua_State *L) { rspamd_lua_add_preload(L, "rspamd_tcp", lua_load_tcp); - rspamd_lua_new_class(L, "rspamd{tcp}", tcp_libm); - rspamd_lua_new_class(L, "rspamd{tcp_sync}", tcp_sync_libm); + rspamd_lua_new_class(L, rspamd_tcp_classname, tcp_libm); + rspamd_lua_new_class(L, rspamd_tcp_sync_classname, tcp_sync_libm); lua_pop(L, 1); } diff --git a/src/lua/lua_text.c b/src/lua/lua_text.c index 26a5c08e0..d05eee268 100644 --- a/src/lua/lua_text.c +++ b/src/lua/lua_text.c @@ -270,7 +270,7 @@ static const struct luaL_reg textlib_m[] = { struct rspamd_lua_text * lua_check_text(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{text}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname); luaL_argcheck(L, ud != NULL, pos, "'text' expected"); return ud ? (struct rspamd_lua_text *) ud : NULL; } @@ -281,7 +281,7 @@ lua_check_text_or_string(lua_State *L, gint pos) gint pos_type = lua_type(L, pos); if (pos_type == LUA_TUSERDATA) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{text}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_text_classname); luaL_argcheck(L, ud != NULL, pos, "'text' expected"); return ud ? (struct rspamd_lua_text *) ud : NULL; } @@ -341,7 +341,7 @@ lua_new_text(lua_State *L, const gchar *start, gsize len, gboolean own) } t->len = len; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); return t; } @@ -376,7 +376,7 @@ lua_new_text_task(lua_State *L, struct rspamd_task *task, } t->len = len; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); return t; } @@ -572,7 +572,7 @@ lua_text_fromtable(lua_State *L) t->start = dest; t->len = textlen; t->flags = RSPAMD_TEXT_FLAG_OWN; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); lua_pushvalue(L, 1); lua_text_tbl_append(L, delim, dlen, &dest, 0); @@ -792,7 +792,7 @@ rspamd_lua_text_push_line(lua_State *L, struct rspamd_lua_text *ntext; ntext = lua_newuserdata(L, sizeof(*ntext)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); ntext->start = start; ntext->len = len; ntext->flags = 0; /* Not own as it must be owned by a top object */ @@ -907,7 +907,7 @@ rspamd_lua_text_regexp_split(lua_State *L) } else { new_t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); new_t->start = old_start; new_t->len = start - old_start; new_t->flags = 0; @@ -943,7 +943,7 @@ rspamd_lua_text_regexp_split(lua_State *L) } else { new_t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); new_t->start = end; new_t->len = (t->start + t->len) - end; new_t->flags = 0; @@ -1013,7 +1013,7 @@ lua_text_split(lua_State *L) if (own_re) { struct rspamd_lua_regexp **pre; pre = lua_newuserdata(L, sizeof(struct rspamd_lua_regexp *)); - rspamd_lua_setclass(L, "rspamd{regexp}", -1); + rspamd_lua_setclass(L, rspamd_regexp_classname, -1); *pre = re; } else { @@ -1378,7 +1378,7 @@ lua_text_base64(lua_State *L) out->start = rspamd_encode_base64_common(t->start, t->len, line_len, &sz_len, fold, how); out->len = sz_len; - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); } else { return luaL_error(L, "invalid arguments"); @@ -1480,7 +1480,7 @@ lua_text_exclude_chars(lua_State *L) dest = g_malloc(t->len); nt = lua_newuserdata(L, sizeof(*nt)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); nt->len = t->len; nt->flags = RSPAMD_TEXT_FLAG_OWN; memcpy(dest, t->start, t->len); @@ -1592,7 +1592,7 @@ lua_text_oneline(lua_State *L) dest = g_malloc(t->len); nt = lua_newuserdata(L, sizeof(*nt)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); nt->len = t->len; nt->flags = RSPAMD_TEXT_FLAG_OWN; memcpy(dest, t->start, t->len); @@ -1779,7 +1779,7 @@ lua_load_text(lua_State *L) void luaopen_text(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{text}", textlib_m); + rspamd_lua_new_class(L, rspamd_text_classname, textlib_m); lua_pushstring(L, "cookie"); lua_pushnumber(L, rspamd_lua_text_cookie); lua_settable(L, -3); diff --git a/src/lua/lua_trie.c b/src/lua/lua_trie.c index 3b0b55e97..b92832928 100644 --- a/src/lua/lua_trie.c +++ b/src/lua/lua_trie.c @@ -62,7 +62,7 @@ static const struct luaL_reg trielib_f[] = { static struct rspamd_multipattern * lua_check_trie(lua_State *L, gint idx) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{trie}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_trie_classname); luaL_argcheck(L, ud != NULL, 1, "'trie' expected"); return ud ? *((struct rspamd_multipattern **) ud) : NULL; @@ -150,7 +150,7 @@ lua_trie_create(lua_State *L) } else { ptrie = lua_newuserdata(L, sizeof(void *)); - rspamd_lua_setclass(L, "rspamd{trie}", -1); + rspamd_lua_setclass(L, rspamd_trie_classname, -1); *ptrie = trie; } } @@ -494,7 +494,7 @@ lua_load_trie(lua_State *L) void luaopen_trie(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{trie}", trielib_m); + rspamd_lua_new_class(L, rspamd_trie_classname, trielib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_trie", lua_load_trie); } diff --git a/src/lua/lua_udp.c b/src/lua/lua_udp.c index c79e35a8c..d20475933 100644 --- a/src/lua/lua_udp.c +++ b/src/lua/lua_udp.c @@ -424,7 +424,7 @@ lua_udp_sendto(lua_State *L) if (task == NULL) { lua_pushstring(L, "ev_base"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{ev_base}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_ev_base_classname)) { ev_base = *(struct ev_loop **) lua_touserdata(L, -1); } else { @@ -434,7 +434,7 @@ lua_udp_sendto(lua_State *L) lua_pushstring(L, "session"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{session}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_session_classname)) { session = *(struct rspamd_async_session **) lua_touserdata(L, -1); } else { @@ -444,7 +444,7 @@ lua_udp_sendto(lua_State *L) lua_pushstring(L, "pool"); lua_gettable(L, -2); - if (rspamd_lua_check_udata_maybe(L, -1, "rspamd{mempool}")) { + if (rspamd_lua_check_udata_maybe(L, -1, rspamd_mempool_classname)) { pool = *(rspamd_mempool_t **) lua_touserdata(L, -1); } else { diff --git a/src/lua/lua_upstream.c b/src/lua/lua_upstream.c index 583ee6a6e..69d9f39c4 100644 --- a/src/lua/lua_upstream.c +++ b/src/lua/lua_upstream.c @@ -95,7 +95,7 @@ static const struct luaL_reg upstream_m[] = { struct rspamd_lua_upstream * lua_check_upstream(lua_State *L, int pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{upstream}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_upstream_classname); luaL_argcheck(L, ud != NULL, 1, "'upstream' expected"); return ud ? (struct rspamd_lua_upstream *) ud : NULL; @@ -232,7 +232,7 @@ lua_upstream_destroy(lua_State *L) static struct upstream_list * lua_check_upstream_list(lua_State *L) { - void *ud = rspamd_lua_check_udata(L, 1, "rspamd{upstream_list}"); + void *ud = rspamd_lua_check_udata(L, 1, rspamd_upstream_list_classname); luaL_argcheck(L, ud != NULL, 1, "'upstream_list' expected"); return ud ? *((struct upstream_list **) ud) : NULL; @@ -249,7 +249,7 @@ lua_push_upstream(lua_State *L, gint up_idx, struct upstream *up) lua_ups = lua_newuserdata(L, sizeof(*lua_ups)); lua_ups->up = up; - rspamd_lua_setclass(L, "rspamd{upstream}", -1); + rspamd_lua_setclass(L, rspamd_upstream_classname, -1); /* Store parent in the upstream to prevent gc */ lua_pushvalue(L, up_idx); lua_ups->upref = luaL_ref(L, LUA_REGISTRYINDEX); @@ -295,7 +295,7 @@ lua_upstream_list_create(lua_State *L) if (rspamd_upstreams_parse_line(new, def, default_port, NULL)) { pnew = lua_newuserdata(L, sizeof(struct upstream_list *)); - rspamd_lua_setclass(L, "rspamd{upstream_list}", -1); + rspamd_lua_setclass(L, rspamd_upstream_list_classname, -1); *pnew = new; } else { @@ -306,7 +306,7 @@ lua_upstream_list_create(lua_State *L) else if (lua_type(L, top) == LUA_TTABLE) { new = rspamd_upstreams_create(cfg ? cfg->ups_ctx : NULL); pnew = lua_newuserdata(L, sizeof(struct upstream_list *)); - rspamd_lua_setclass(L, "rspamd{upstream_list}", -1); + rspamd_lua_setclass(L, rspamd_upstream_list_classname, -1); *pnew = new; lua_pushvalue(L, top); @@ -563,7 +563,7 @@ lua_upstream_watch_func(struct upstream *up, struct rspamd_lua_upstream *lua_ups = lua_newuserdata(L, sizeof(*lua_ups)); lua_ups->up = up; - rspamd_lua_setclass(L, "rspamd{upstream}", -1); + rspamd_lua_setclass(L, rspamd_upstream_classname, -1); /* Store parent in the upstream to prevent gc */ lua_rawgeti(L, LUA_REGISTRYINDEX, cdata->parent_cbref); lua_ups->upref = luaL_ref(L, LUA_REGISTRYINDEX); @@ -663,10 +663,10 @@ lua_load_upstream_list(lua_State *L) void luaopen_upstream(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{upstream_list}", upstream_list_m); + rspamd_lua_new_class(L, rspamd_upstream_list_classname, upstream_list_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_upstream_list", lua_load_upstream_list); - rspamd_lua_new_class(L, "rspamd{upstream}", upstream_m); + rspamd_lua_new_class(L, rspamd_upstream_classname, upstream_m); lua_pop(L, 1); } diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index c09eedea6..f84f64a2c 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -119,7 +119,7 @@ static const struct luaL_reg urllib_f[] = { struct rspamd_lua_url * lua_check_url(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{url}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_url_classname); luaL_argcheck(L, ud != NULL, pos, "'url' expected"); return ud ? ((struct rspamd_lua_url *) ud) : NULL; } @@ -132,7 +132,7 @@ lua_url_single_inserter(struct rspamd_url *url, gsize start_offset, struct rspamd_lua_url *lua_url; lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url)); - rspamd_lua_setclass(L, "rspamd{url}", -1); + rspamd_lua_setclass(L, rspamd_url_classname, -1); lua_url->url = url; return TRUE; @@ -572,7 +572,7 @@ lua_url_get_phished(lua_State *L) if (url->url->flags & (RSPAMD_URL_FLAG_PHISHED | RSPAMD_URL_FLAG_REDIRECTED)) { purl = lua_newuserdata(L, sizeof(struct rspamd_lua_url)); - rspamd_lua_setclass(L, "rspamd{url}", -1); + rspamd_lua_setclass(L, rspamd_url_classname, -1); purl->url = url->url->ext->linked_url; return 1; @@ -928,7 +928,7 @@ lua_url_table_inserter(struct rspamd_url *url, gsize start_offset, n = rspamd_lua_table_size(L, -1); lua_url = lua_newuserdata(L, sizeof(struct rspamd_lua_url)); - rspamd_lua_setclass(L, "rspamd{url}", -1); + rspamd_lua_setclass(L, rspamd_url_classname, -1); lua_url->url = url; lua_rawseti(L, -2, n + 1); @@ -1353,7 +1353,7 @@ lua_url_cbdata_fill(lua_State *L, cbd->flags_mask = flags_mask; /* This needs to be removed from the stack */ - rspamd_lua_class_metatable(L, "rspamd{url}"); + rspamd_lua_class_metatable(L, rspamd_url_classname); cbd->metatable_pos = lua_gettop(L); (void) lua_checkstack(L, cbd->metatable_pos + 4); @@ -1470,7 +1470,7 @@ lua_url_cbdata_fill_exclude_include(lua_State *L, cbd->flags_exclude_mask = exclude_flags_mask; /* This needs to be removed from the stack */ - rspamd_lua_class_metatable(L, "rspamd{url}"); + rspamd_lua_class_metatable(L, rspamd_url_classname); cbd->metatable_pos = lua_gettop(L); (void) lua_checkstack(L, cbd->metatable_pos + 4); @@ -1562,7 +1562,7 @@ lua_load_url(lua_State *L) void luaopen_url(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{url}", urllib_m); + rspamd_lua_new_class(L, rspamd_url_classname, urllib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_url", lua_load_url); diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 152c02d1e..d1d64b79c 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -763,7 +763,7 @@ static const struct luaL_reg ev_baselib_m[] = { static gint64 lua_check_int64(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{int64}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_int64_classname); luaL_argcheck(L, ud != NULL, pos, "'int64' expected"); return ud ? *((gint64 *) ud) : 0LL; } @@ -776,7 +776,7 @@ lua_util_create_event_base(lua_State *L) struct ev_loop **pev_base; pev_base = lua_newuserdata(L, sizeof(struct ev_loop *)); - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); *pev_base = ev_loop_new(EVFLAG_SIGNALFD | EVBACKEND_ALL); return 1; @@ -802,7 +802,7 @@ lua_util_load_rspamd_config(lua_State *L) else { rspamd_config_post_load(cfg, 0); pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; } } @@ -898,7 +898,7 @@ lua_util_config_from_ucl(lua_State *L) rspamd_config_post_load(cfg, int_options); pcfg = lua_newuserdata(L, sizeof(struct rspamd_config *)); - rspamd_lua_setclass(L, "rspamd{config}", -1); + rspamd_lua_setclass(L, rspamd_config_classname, -1); *pcfg = cfg; } @@ -1085,7 +1085,7 @@ lua_util_encode_qp(lua_State *L) if (out != NULL) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = out; t->len = outlen; /* Need destruction */ @@ -1125,7 +1125,7 @@ lua_util_decode_qp(lua_State *L) } else { out = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); out->start = g_malloc(inlen + 1); out->flags = RSPAMD_TEXT_FLAG_OWN; outlen = rspamd_decode_qp_buf(s, inlen, (gchar *) out->start, inlen + 1); @@ -1167,7 +1167,7 @@ lua_util_decode_base64(lua_State *L) if (s != NULL) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->len = (inlen / 4) * 3 + 3; t->start = g_malloc(t->len); @@ -1222,7 +1222,7 @@ lua_util_encode_base32(lua_State *L) if (out != NULL) { t = lua_newuserdata(L, sizeof(*t)); outlen = strlen(out); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = out; t->len = outlen; /* Need destruction */ @@ -1272,7 +1272,7 @@ lua_util_decode_base32(lua_State *L) if (decoded) { t = lua_newuserdata(L, sizeof(*t)); - rspamd_lua_setclass(L, "rspamd{text}", -1); + rspamd_lua_setclass(L, rspamd_text_classname, -1); t->start = (const gchar *) decoded; t->len = outlen; t->flags = RSPAMD_TEXT_FLAG_OWN; @@ -2077,7 +2077,7 @@ lua_util_caseless_hash(lua_State *L) h = rspamd_icase_hash(t->start, t->len, seed); r = lua_newuserdata(L, sizeof(*r)); *r = h; - rspamd_lua_setclass(L, "rspamd{int64}", -1); + rspamd_lua_setclass(L, rspamd_int64_classname, -1); return 1; } @@ -3468,9 +3468,9 @@ lua_load_int64(lua_State *L) void luaopen_util(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{ev_base}", ev_baselib_m); + rspamd_lua_new_class(L, rspamd_ev_base_classname, ev_baselib_m); lua_pop(L, 1); - rspamd_lua_new_class(L, "rspamd{int64}", int64lib_m); + rspamd_lua_new_class(L, rspamd_int64_classname, int64lib_m); lua_pop(L, 1); rspamd_lua_add_preload(L, "rspamd_util", lua_load_util); rspamd_lua_add_preload(L, "rspamd_int64", lua_load_int64); @@ -3530,7 +3530,7 @@ lua_int64_fromstring(lua_State *L) } gint64 *i64_p = lua_newuserdata(L, sizeof(gint64)); - rspamd_lua_setclass(L, "rspamd{int64}", -1); + rspamd_lua_setclass(L, rspamd_int64_classname, -1); memcpy(i64_p, &u64, sizeof(u64)); if (neg) { diff --git a/src/lua/lua_worker.c b/src/lua/lua_worker.c index 025b97ba1..9bf2a2469 100644 --- a/src/lua/lua_worker.c +++ b/src/lua/lua_worker.c @@ -63,7 +63,7 @@ const luaL_reg worker_reg[] = { static struct rspamd_worker * lua_check_worker(lua_State *L, gint pos) { - void *ud = rspamd_lua_check_udata(L, pos, "rspamd{worker}"); + void *ud = rspamd_lua_check_udata(L, pos, rspamd_worker_classname); luaL_argcheck(L, ud != NULL, pos, "'worker' expected"); return ud ? *((struct rspamd_worker **) ud) : NULL; } @@ -309,7 +309,7 @@ lua_worker_control_handler(struct rspamd_main *rspamd_main, err_idx = lua_gettop(L); lua_rawgeti(L, LUA_REGISTRYINDEX, cbd->cbref); psession = lua_newuserdata(L, sizeof(*psession)); - rspamd_lua_setclass(L, "rspamd{session}", -1); + rspamd_lua_setclass(L, rspamd_session_classname, -1); *psession = session; /* Command name */ @@ -879,5 +879,5 @@ lua_worker_spawn_process(lua_State *L) void luaopen_worker(lua_State *L) { - rspamd_lua_new_class(L, "rspamd{worker}", worker_reg); + rspamd_lua_new_class(L, rspamd_worker_classname, worker_reg); } diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 581c1c12d..62ddef504 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -1570,7 +1570,7 @@ fuzzy_rule_check_mimepart(struct rspamd_task *task, ppart = lua_newuserdata(L, sizeof(*ppart)); *ppart = part; - rspamd_lua_setclass(L, "rspamd{mimepart}", -1); + rspamd_lua_setclass(L, rspamd_mimepart_classname, -1); lua_pushnumber(L, rule->lua_id); diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 0e38dc326..0b7a65006 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -336,17 +336,17 @@ rspamadm_add_lua_globals(struct rspamd_dns_resolver *resolver) NULL, (event_finalizer_t) NULL, NULL); psession = lua_newuserdata(L, sizeof(struct rspamd_async_session *)); - rspamd_lua_setclass(L, "rspamd{session}", -1); + rspamd_lua_setclass(L, rspamd_session_classname, -1); *psession = rspamadm_session; lua_setglobal(L, "rspamadm_session"); pev_base = lua_newuserdata(L, sizeof(struct ev_loop *)); - rspamd_lua_setclass(L, "rspamd{ev_base}", -1); + rspamd_lua_setclass(L, rspamd_ev_base_classname, -1); *pev_base = rspamd_main->event_loop; lua_setglobal(L, "rspamadm_ev_base"); presolver = lua_newuserdata(L, sizeof(struct rspamd_dns_resolver *)); - rspamd_lua_setclass(L, "rspamd{resolver}", -1); + rspamd_lua_setclass(L, rspamd_resolver_classname, -1); *presolver = resolver; lua_setglobal(L, "rspamadm_dns_resolver"); } |