commit 3d8e13b: [Rework] Html: Fix Lua bindings
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Jun 2 19:56:09 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-06-02 20:54:47 +0100
URL: https://github.com/rspamd/rspamd/commit/3d8e13bdef3067a96026a57489c4d83edbce2d25 (HEAD -> master)
[Rework] Html: Fix Lua bindings
---
src/lua/lua_html.cxx | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/src/lua/lua_html.cxx b/src/lua/lua_html.cxx
index 4dd59083c..91df192a9 100644
--- a/src/lua/lua_html.cxx
+++ b/src/lua/lua_html.cxx
@@ -190,7 +190,7 @@ lua_check_html (lua_State * L, gint pos)
}
struct lua_html_tag {
- struct html_content *html;
+ rspamd::html::html_content *html;
rspamd::html::html_tag *tag;
};
@@ -339,7 +339,7 @@ lua_html_get_images (lua_State *L)
}
static void
-lua_html_push_block (lua_State *L, struct html_block *bl)
+lua_html_push_block (lua_State *L, const struct html_block *bl)
{
LUA_TRACE_POINT;
struct rspamd_lua_text *t;
@@ -405,18 +405,15 @@ lua_html_get_blocks (lua_State *L)
{
LUA_TRACE_POINT;
auto *hc = lua_check_html (L, 1);
- struct html_block *bl;
-
- guint i;
+ guint i = 1;
if (hc != NULL) {
if (hc->blocks.size() > 0) {
lua_createtable (L, hc->blocks.size(), 0);
- for (i = 0; i < hc->blocks->len; i ++) {
- bl = static_cast<decltype(bl)>(g_ptr_array_index (hc->blocks, i));
+ for (const auto *bl : hc->blocks) {
lua_html_push_block (L, bl);
- lua_rawseti (L, -2, i + 1);
+ lua_rawseti (L, -2, i++);
}
}
else {
@@ -432,7 +429,7 @@ lua_html_get_blocks (lua_State *L)
struct lua_html_traverse_ud {
lua_State *L;
- struct html_content *html;
+ rspamd::html::html_content *html;
gint cbref;
robin_hood::unordered_flat_set<int> tags;
gboolean any;
@@ -484,7 +481,7 @@ static gint
lua_html_foreach_tag (lua_State *L)
{
LUA_TRACE_POINT;
- struct html_content *hc = lua_check_html (L, 1);
+ auto *hc = lua_check_html (L, 1);
struct lua_html_traverse_ud ud;
const gchar *tagname;
gint id;
@@ -651,10 +648,10 @@ lua_html_tag_get_content (lua_State *L)
if (ltag) {
if (ltag->html && ltag->tag->content_length &&
- ltag->html->parsed->len >= ltag->tag->content_offset + ltag->tag->content_length) {
+ ltag->html->parsed.size() >= ltag->tag->content_offset + ltag->tag->content_length) {
t = static_cast<rspamd_lua_text *>(lua_newuserdata(L, sizeof(*t)));
rspamd_lua_setclass (L, "rspamd{text}", -1);
- t->start = reinterpret_cast<const char *>(ltag->html->parsed->data) +
+ t->start = reinterpret_cast<const char *>(ltag->html->parsed.data()) +
ltag->tag->content_offset;
t->len = ltag->tag->content_length;
t->flags = 0;
More information about the Commits
mailing list