]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Restore old port behaviour
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Jul 2023 09:37:22 +0000 (10:37 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 24 Jul 2023 09:37:22 +0000 (10:37 +0100)
config.h.in
src/libserver/url.h
src/lua/lua_url.c

index b70308331ab4160c79e021b8824b846d77f05e3f..412dd53e432d512991e7797c1ba8949b059d572d 100644 (file)
 # define RSPAMD_ALIGNED(x) __declspec(align(x))
 # define RSPAMD_OPTIMIZE(x)
 # define RSPAMD_ALWAYS_INLINE
+# define RSPAMD_PURE_FUNCTION
 #elif defined(__GNUC__)
 # define RSPAMD_ALIGNED(x) __attribute__((aligned(x)))
 # define RSPAMD_ALWAYS_INLINE __attribute__((always_inline))
+# define RSPAMD_PURE_FUNCTION __attribute__((pure))
 #ifndef __clang__
 # define RSPAMD_OPTIMIZE(x) __attribute__((__optimize__ (x)))
 #else
 # define RSPAMD_OPTIMIZE(x)
 #endif
 #else
+/* Unknown compiler */
 # define RSPAMD_ALIGNED(x)
 # define RSPAMD_OPTIMIZE(x)
 # define RSPAMD_ALWAYS_INLINE
+# define RSPAMD_PURE_FUNCTION
 #endif
 #endif
 
index 9c5b7be280b495274e319edf04cbecb7389f8d04..7a005efd85d2b378e7a7242f27aff85ab7eef859 100644 (file)
@@ -361,9 +361,14 @@ int rspamd_url_cmp(const struct rspamd_url *u1, const struct rspamd_url *u2);
  */
 int rspamd_url_cmp_qsort(const void *u1, const void *u2);
 
-static inline uint16_t rspamd_url_get_port(struct rspamd_url *u)
+/**
+ * Returns a port for some url
+ * @param u
+ * @return
+ */
+static RSPAMD_PURE_FUNCTION inline uint16_t rspamd_url_get_port(struct rspamd_url *u)
 {
-       if (u->flags & RSPAMD_URL_FLAG_HAS_PORT && u->ext) {
+       if ((u->flags & RSPAMD_URL_FLAG_HAS_PORT) && u->ext) {
                return u->ext->port;
        }
        else {
@@ -377,6 +382,20 @@ static inline uint16_t rspamd_url_get_port(struct rspamd_url *u)
        }
 }
 
+/**
+ * Returns a port for some url if it is set
+ * @param u
+ * @return
+ */
+static RSPAMD_PURE_FUNCTION inline uint16_t rspamd_url_get_port_if_special(struct rspamd_url *u)
+{
+       if ((u->flags & RSPAMD_URL_FLAG_HAS_PORT) && u->ext) {
+               return u->ext->port;
+       }
+
+       return 0;
+}
+
 /**
  * Normalize unicode input and set out url flags as appropriate
  * @param pool
index a46f4e2769f32e33c1852e9c1496ad039fe40c6b..809bd36d34f389cb861a103ea21b7e865869fe05 100644 (file)
@@ -186,7 +186,12 @@ lua_url_get_port (lua_State *L)
        struct rspamd_lua_url *url = lua_check_url (L, 1);
 
        if (url != NULL) {
-               lua_pushinteger (L, rspamd_url_get_port(url->url));
+               if (rspamd_url_get_port_if_special(url->url) == 0) {
+                       lua_pushnil (L);
+               }
+               else {
+                       lua_pushinteger (L, rspamd_url_get_port_if_special(url->url));
+               }
        }
        else {
                lua_pushnil (L);
@@ -679,9 +684,11 @@ lua_url_to_table (lua_State *L)
                        lua_settable (L, -3);
                }
 
-               lua_pushstring (L, "port");
-               lua_pushinteger (L, rspamd_url_get_port(u));
-               lua_settable (L, -3);
+               if (rspamd_url_get_port_if_special(u) != 0) {
+                       lua_pushstring (L, "port");
+                       lua_pushinteger (L, rspamd_url_get_port_if_special(u));
+                       lua_settable (L, -3);
+               }
 
                if (u->tldlen > 0) {
                        lua_pushstring (L, "tld");