diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-24 10:37:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-07-24 10:37:22 +0100 |
commit | 414dd2d5b4eff49643617759db0eca0dd61ca39a (patch) | |
tree | 542a287c07eb57d25f3540bb3f096f795c0cd409 /src | |
parent | eef2f3cac7c975af050efaf4cf1acafcb9b501e3 (diff) | |
download | rspamd-414dd2d5b4eff49643617759db0eca0dd61ca39a.tar.gz rspamd-414dd2d5b4eff49643617759db0eca0dd61ca39a.zip |
[Minor] Restore old port behaviour
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/url.h | 23 | ||||
-rw-r--r-- | src/lua/lua_url.c | 15 |
2 files changed, 32 insertions, 6 deletions
diff --git a/src/libserver/url.h b/src/libserver/url.h index 9c5b7be28..7a005efd8 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 { @@ -378,6 +383,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 * @param input diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c index a46f4e276..809bd36d3 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"); |