Skip to content

Commit

Permalink
[Minor] Restore old port behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Jul 24, 2023
1 parent eef2f3c commit 414dd2d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 21 additions & 2 deletions src/libserver/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
15 changes: 11 additions & 4 deletions src/lua/lua_url.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 414dd2d

Please sign in to comment.