commit 414dd2d: [Minor] Restore old port behaviour
Vsevolod Stakhov
vsevolod at rspamd.com
Mon Jul 24 10:00:03 UTC 2023
Author: Vsevolod Stakhov
Date: 2023-07-24 10:37:22 +0100
URL: https://github.com/rspamd/rspamd/commit/414dd2d5b4eff49643617759db0eca0dd61ca39a
[Minor] Restore old port behaviour
---
config.h.in | 4 ++++
src/libserver/url.h | 23 +++++++++++++++++++++--
src/lua/lua_url.c | 15 +++++++++++----
3 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/config.h.in b/config.h.in
index b70308331..412dd53e4 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 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 {
@@ -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 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");
More information about the Commits
mailing list