static gint lua_html_tag_get_extra (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1); struct html_image *img; struct rspamd_url **purl; if (tag) { if (tag->extra) { if (tag->id == Tag_A || tag->id == Tag_IFRAME) { /* For A that's URL */ purl = lua_newuserdata (L, sizeof (gpointer)); *purl = tag->extra; rspamd_lua_setclass (L, "rspamd{url}", -1); } else if (tag->id == Tag_IMG) { img = tag->extra; lua_html_push_image (L, img); } else { /* Unknown extra ? */ lua_pushnil (L); } } else { lua_pushnil (L); } } else { lua_error (L); } return 1; }
static gint lua_html_tag_get_content_length (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1); if (tag) { lua_pushnumber (L, tag->content_length); } else { return luaL_error (L, "invalid arguments"); } return 1; }
static gint lua_html_tag_get_parent (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1), **ptag; GNode *node; if (tag != NULL) { node = tag->parent; if (node && node->data) { ptag = lua_newuserdata (L, sizeof (gpointer)); *ptag = node->data; rspamd_lua_setclass (L, "rspamd{html_tag}", -1); } } else { return luaL_error (L, "invalid arguments"); } return 1; }
static gint lua_html_tag_get_type (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1); const gchar *tagname; if (tag != NULL) { tagname = rspamd_html_tag_by_id (tag->id); if (tagname) { lua_pushstring (L, tagname); } else { lua_pushnil (L); } } else { return luaL_error (L, "invalid arguments"); } return 1; }
static gint lua_html_tag_get_content (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1); struct rspamd_lua_text *t; if (tag) { if (tag->content && tag->content_length) { t = lua_newuserdata (L, sizeof (*t)); rspamd_lua_setclass (L, "rspamd{text}", -1); t->start = tag->content; t->len = tag->content_length; t->own = FALSE; } else { lua_pushnil (L); } } else { return luaL_error (L, "invalid arguments"); } return 1; }
static gint lua_html_tag_get_flags (lua_State *L) { struct html_tag *tag = lua_check_html_tag (L, 1); gint i = 1; if (tag) { /* Push flags */ lua_createtable (L, 4, 0); if (tag->flags & FL_CLOSING) { lua_pushstring (L, "closing"); lua_rawseti (L, -2, i++); } if (tag->flags & FL_CLOSED) { lua_pushstring (L, "closed"); lua_rawseti (L, -2, i++); } if (tag->flags & FL_BROKEN) { lua_pushstring (L, "broken"); lua_rawseti (L, -2, i++); } if (tag->flags & FL_XML) { lua_pushstring (L, "xml"); lua_rawseti (L, -2, i++); } if (tag->flags & RSPAMD_HTML_FLAG_UNBALANCED) { lua_pushstring (L, "unbalanced"); lua_rawseti (L, -2, i++); } } else { return luaL_error (L, "invalid arguments"); } return 1; }