/* URL methods */
LUA_FUNCTION_DEF (url, get_length);
LUA_FUNCTION_DEF (url, get_host);
+LUA_FUNCTION_DEF (url, get_port);
LUA_FUNCTION_DEF (url, get_user);
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_tld);
LUA_FUNCTION_DEF (url, to_table);
static const struct luaL_reg urllib_m[] = {
LUA_INTERFACE_DEF (url, get_length),
LUA_INTERFACE_DEF (url, get_host),
+ LUA_INTERFACE_DEF (url, get_port),
LUA_INTERFACE_DEF (url, get_user),
LUA_INTERFACE_DEF (url, get_path),
+ LUA_INTERFACE_DEF (url, get_query),
+ LUA_INTERFACE_DEF (url, get_fragment),
LUA_INTERFACE_DEF (url, get_text),
LUA_INTERFACE_DEF (url, get_tld),
LUA_INTERFACE_DEF (url, to_table),
return 1;
}
+/***
+ * @method url:get_port()
+ * Get port of the url
+ * @return {number} url port
+ */
+static gint
+lua_url_get_port (lua_State *L)
+{
+ struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+ if (url != NULL) {
+ lua_pushnumber (L, url->url->port);
+ }
+ else {
+ lua_pushnil (L);
+ }
+ return 1;
+}
+
/***
* @method url:get_user()
* Get user part of the url (e.g. username in email)
return 1;
}
+/***
+ * @method url:get_query()
+ * Get query of the url
+ * @return {string} query part of URL
+ */
+static gint
+lua_url_get_query (lua_State *L)
+{
+ struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+ if (url != NULL && url->url->querylen > 0) {
+ lua_pushlstring (L, url->url->query, url->url->querylen);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
+/***
+ * @method url:get_fragment()
+ * Get fragment of the url
+ * @return {string} fragment part of URL
+ */
+static gint
+lua_url_get_fragment (lua_State *L)
+{
+ struct rspamd_lua_url *url = lua_check_url (L, 1);
+
+ if (url != NULL && url->url->fragmentlen > 0) {
+ lua_pushlstring (L, url->url->fragment, url->url->fragmentlen);
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
/***
* @method url:get_text()
* Get full content of the url
lua_settable (L, -3);
}
+ if (u->port != 0) {
+ lua_pushstring (L, "port");
+ lua_pushnumber (L, u->port);
+ lua_settable (L, -3);
+ }
+
if (u->tldlen > 0) {
lua_pushstring (L, "tld");
lua_pushlstring (L, u->tld, u->tldlen);
lua_settable (L, -3);
}
+ if (u->querylen > 0) {
+ lua_pushstring (L, "query");
+ lua_pushlstring (L, u->query, u->querylen);
+ lua_settable (L, -3);
+ }
+
+ if (u->fragmentlen > 0) {
+ lua_pushstring (L, "fragment");
+ lua_pushlstring (L, u->fragment, u->fragmentlen);
+ lua_settable (L, -3);
+ }
+
+
lua_pushstring (L, "protocol");
switch (u->protocol) {