Browse Source

[Minor] Store raw urls

tags/1.7.0
Vsevolod Stakhov 6 years ago
parent
commit
809d57ec6a
5 changed files with 32 additions and 1 deletions
  1. 4
    1
      src/libserver/url.c
  2. 2
    0
      src/libserver/url.h
  3. 1
    0
      src/libutil/http.c
  4. 3
    0
      src/lua/lua_http.c
  5. 22
    0
      src/lua/lua_url.c

+ 4
- 1
src/libserver/url.c View File

@@ -1592,7 +1592,10 @@ rspamd_url_parse (struct rspamd_url *uri, gchar *uristring, gsize len,
uri->flags |= RSPAMD_URL_FLAG_OBSCURED;
}

uri->string = p;
uri->raw = p;
uri->rawlen = len;
uri->string = rspamd_mempool_alloc (pool, len + 1);
rspamd_strlcpy (uri->string, p, len + 1);
uri->urllen = len;

/* Now decode url symbols */

+ 2
- 0
src/libserver/url.h View File

@@ -25,6 +25,7 @@ struct rspamd_url_tag {
};

struct rspamd_url {
gchar *raw;
gchar *string;
gint protocol;
guint port;
@@ -48,6 +49,7 @@ struct rspamd_url {
guint surbllen;
guint tldlen;
guint urllen;
guint rawlen;

enum rspamd_url_flags flags;
guint count;

+ 1
- 0
src/libutil/http.c View File

@@ -2385,6 +2385,7 @@ rspamd_http_message_from_url (const gchar *url)

urllen = strlen (url);
memset (&pu, 0, sizeof (pu));

if (http_parser_parse_url (url, urllen, FALSE, &pu) != 0) {
msg_warn ("cannot parse URL: %s", url);
return NULL;

+ 3
- 0
src/lua/lua_http.c View File

@@ -366,13 +366,16 @@ lua_http_request (lua_State *L)
if (lua_gettop (L) >= 2) {
/* url, callback and event_base format */
url = luaL_checkstring (L, 1);

if (url == NULL || lua_type (L, 2) != LUA_TFUNCTION) {
msg_err ("http request has bad params");
lua_pushboolean (L, FALSE);
return 1;
}

lua_pushvalue (L, 2);
cbref = luaL_ref (L, LUA_REGISTRYINDEX);

if (lua_gettop (L) >= 3 && rspamd_lua_check_udata_maybe (L, 3, "rspamd{ev_base}")) {
ev_base = *(struct event_base **)lua_touserdata (L, 3);
}

+ 22
- 0
src/lua/lua_url.c View File

@@ -47,6 +47,7 @@ LUA_FUNCTION_DEF (url, get_path);
LUA_FUNCTION_DEF (url, get_query);
LUA_FUNCTION_DEF (url, get_fragment);
LUA_FUNCTION_DEF (url, get_text);
LUA_FUNCTION_DEF (url, get_raw);
LUA_FUNCTION_DEF (url, get_tld);
LUA_FUNCTION_DEF (url, to_table);
LUA_FUNCTION_DEF (url, is_phished);
@@ -73,6 +74,7 @@ static const struct luaL_reg urllib_m[] = {
LUA_INTERFACE_DEF (url, get_fragment),
LUA_INTERFACE_DEF (url, get_text),
LUA_INTERFACE_DEF (url, get_tld),
LUA_INTERFACE_DEF (url, get_raw),
LUA_INTERFACE_DEF (url, to_table),
LUA_INTERFACE_DEF (url, is_phished),
LUA_INTERFACE_DEF (url, is_redirected),
@@ -262,6 +264,26 @@ lua_url_get_text (lua_State *L)
return 1;
}

/***
* @method url:get_raw()
* Get full content of the url as it was parsed (e.g. with urldecode)
* @return {string} url string
*/
static gint
lua_url_get_raw (lua_State *L)
{
struct rspamd_lua_url *url = lua_check_url (L, 1);

if (url != NULL) {
lua_pushlstring (L, url->url->raw, url->url->rawlen);
}
else {
lua_pushnil (L);
}

return 1;
}

/***
* @method url:is_phished()
* Check whether URL is treated as phished

Loading…
Cancel
Save