From: Vsevolod Stakhov Date: Mon, 18 May 2020 15:56:25 +0000 (+0100) Subject: [Minor] Allow to specify flags mode when getting urls X-Git-Tag: 2.6~414 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8c9a5fc40ae7275e9101ecfe65bef6d150260af1;p=thirdparty%2Frspamd.git [Minor] Allow to specify flags mode when getting urls --- diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index b491462923..29f75995bb 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -933,8 +933,18 @@ lua_tree_url_callback (gpointer key, gpointer value, gpointer ud) struct rspamd_url *url = (struct rspamd_url *)value; struct lua_tree_cb_data *cb = ud; - if ((url->protocol & cb->protocols_mask) == url->protocol && - (url->flags == (url->flags & cb->flags_mask))) { + if ((url->protocol & cb->protocols_mask) == url->protocol) { + + if (cb->flags_mode == url_flags_mode_include_any) { + if (url->flags != (url->flags & cb->flags_mask)) { + return; + } + } + else { + if ((url->flags & cb->flags_mask) != cb->flags_mask) { + return; + } + } if (cb->skip_prob > 0) { gdouble coin = rspamd_random_double_fast_seed (cb->xoroshiro_state); @@ -966,6 +976,9 @@ lua_url_cbdata_fill (lua_State *L, guint flags_mask = default_flags; gboolean seen_flags = FALSE, seen_protocols = FALSE; + memset (cbd, 0, sizeof (*cbd)); + cbd->flags_mode = url_flags_mode_include_any; + if (pos_arg_type == LUA_TBOOLEAN) { protocols_mask = default_protocols; if (lua_toboolean (L, 2)) { @@ -980,6 +993,21 @@ lua_url_cbdata_fill (lua_State *L, if (lua_istable (L, -1)) { gint top = lua_gettop (L); + lua_getfield (L, pos, "flags_mode"); + if (lua_isstring (L, -1)) { + const gchar *mode_str = lua_tostring (L, -1); + + if (strcmp (mode_str, "explicit") == 0) { + cbd->flags_mode = url_flags_mode_include_explicit; + /* + * Ignore default flags in this mode and include + * merely flags specified by a caller + */ + flags_mask = 0; + } + } + lua_pop (L, 1); + for (lua_pushnil (L); lua_next (L, top); lua_pop (L, 1)) { int nmask = 0; const gchar *fname = lua_tostring (L, -1); @@ -993,6 +1021,7 @@ lua_url_cbdata_fill (lua_State *L, return FALSE; } } + seen_flags = TRUE; } else { @@ -1136,8 +1165,6 @@ lua_url_cbdata_fill (lua_State *L, } } - memset (cbd, 0, sizeof (*cbd)); - cbd->i = 1; cbd->L = L; cbd->max_urls = max_urls; diff --git a/src/lua/lua_url.h b/src/lua/lua_url.h index 0ea2186d86..c074a579a2 100644 --- a/src/lua/lua_url.h +++ b/src/lua/lua_url.h @@ -28,6 +28,10 @@ struct lua_tree_cb_data { int metatable_pos; guint flags_mask; guint protocols_mask; + enum { + url_flags_mode_include_any, + url_flags_mode_include_explicit, + } flags_mode; gsize max_urls; gdouble skip_prob; guint64 xoroshiro_state[4];