]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Allow numeric flags when filling cbdata
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Apr 2021 15:00:53 +0000 (16:00 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 15 Apr 2021 15:00:53 +0000 (16:00 +0100)
src/lua/lua_url.c

index f3d64e225803bd55465a0099ed5242c8e1bf2788..0a0af8331c6b52309192521740df990c4ec537a8 100644 (file)
@@ -924,6 +924,7 @@ lua_url_get_flags (lua_State *L)
                PUSH_FLAG (RSPAMD_URL_FLAG_DISPLAY_URL);
                PUSH_FLAG (RSPAMD_URL_FLAG_IMAGE);
                PUSH_FLAG (RSPAMD_URL_FLAG_CONTENT);
+               PUSH_FLAG (RSPAMD_URL_FLAG_TRUNCATED);
        }
        else {
                return luaL_error (L, "invalid arguments");
@@ -1045,15 +1046,22 @@ lua_url_cbdata_fill (lua_State *L,
 
                                for (lua_pushnil (L); lua_next (L, top); lua_pop (L, 1)) {
                                        int nmask = 0;
-                                       const gchar *fname = lua_tostring (L, -1);
 
 
-                                       if (rspamd_url_flag_from_string (fname, &nmask)) {
-                                               flags_mask |= nmask;
+                                       if (lua_type (L, -1) == LUA_TSTRING) {
+                                               const gchar *fname = lua_tostring (L, -1);
+
+
+                                               if (rspamd_url_flag_from_string (fname, &nmask)) {
+                                                       flags_mask |= nmask;
+                                               }
+                                               else {
+                                                       msg_info ("bad url flag: %s", fname);
+                                                       return FALSE;
+                                               }
                                        }
                                        else {
-                                               msg_info ("bad url flag: %s", fname);
-                                               return FALSE;
+                                               flags_mask |= lua_tointeger (L, -1);
                                        }
                                }
 
@@ -1241,14 +1249,20 @@ lua_url_cbdata_fill_exclude_include (lua_State *L,
 
                for (lua_pushnil(L); lua_next(L, pos); lua_pop (L, 1)) {
                        int nmask = 0;
-                       const gchar *fname = lua_tostring (L, -1);
 
-                       if (rspamd_url_flag_from_string(fname, &nmask)) {
-                               include_flags_mask |= nmask;
+                       if (lua_type (L, -1) == LUA_TSTRING) {
+                               const gchar *fname = lua_tostring (L, -1);
+
+                               if (rspamd_url_flag_from_string(fname, &nmask)) {
+                                       include_flags_mask |= nmask;
+                               }
+                               else {
+                                       msg_info ("bad url include flag: %s", fname);
+                                       return FALSE;
+                               }
                        }
                        else {
-                               msg_info ("bad url include flag: %s", fname);
-                               return FALSE;
+                               include_flags_mask |= lua_tointeger (L, -1);
                        }
                }
        }
@@ -1269,14 +1283,19 @@ lua_url_cbdata_fill_exclude_include (lua_State *L,
                for (lua_pushnil(L); lua_next(L, pos); lua_pop (L, 1)) {
                        int nmask = 0;
 
-                       const gchar *fname = lua_tostring (L, -1);
+                       if (lua_type (L, -1) == LUA_TSTRING) {
+                               const gchar *fname = lua_tostring (L, -1);
 
-                       if (rspamd_url_flag_from_string(fname, &nmask)) {
-                               exclude_flags_mask |= nmask;
+                               if (rspamd_url_flag_from_string(fname, &nmask)) {
+                                       exclude_flags_mask |= nmask;
+                               }
+                               else {
+                                       msg_info ("bad url exclude flag: %s", fname);
+                                       return FALSE;
+                               }
                        }
                        else {
-                               msg_info ("bad url exclude flag: %s", fname);
-                               return FALSE;
+                               exclude_flags_mask |= lua_tointeger (L, -1);
                        }
                }
        }