From: Vsevolod Stakhov Date: Mon, 24 Jul 2023 09:37:22 +0000 (+0100) Subject: [Minor] Restore old port behaviour X-Git-Tag: 3.6~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=414dd2d5b4eff49643617759db0eca0dd61ca39a;p=thirdparty%2Frspamd.git [Minor] Restore old port behaviour --- diff --git a/config.h.in b/config.h.in index b70308331a..412dd53e43 100644 --- a/config.h.in +++ b/config.h.in @@ -294,18 +294,22 @@ # 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 diff --git a/src/libserver/url.h b/src/libserver/url.h index 9c5b7be280..7a005efd85 100644 --- a/src/libserver/url.h +++ b/src/libserver/url.h @@ -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 diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index a46f4e2769..809bd36d34 100644 --- a/src/lua/lua_url.c +++ b/src/lua/lua_url.c @@ -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");