return up->name;
}
+gint
+rspamd_upstream_port (struct upstream *up)
+{
+ struct upstream_addr_elt *elt;
+
+ elt = g_ptr_array_index (up->addrs.addr, up->addrs.cur);
+ return rspamd_inet_address_get_port (elt->addr);
+}
+
gboolean
rspamd_upstreams_add_upstream (struct upstream_list *ups, const gchar *str,
guint16 def_port, enum rspamd_upstream_parse_type parse_type,
LUA_FUNCTION_DEF (upstream, fail);
LUA_FUNCTION_DEF (upstream, get_addr);
LUA_FUNCTION_DEF (upstream, get_name);
+LUA_FUNCTION_DEF (upstream, get_port);
LUA_FUNCTION_DEF (upstream, destroy);
static const struct luaL_reg upstream_m[] = {
LUA_INTERFACE_DEF (upstream, ok),
LUA_INTERFACE_DEF (upstream, fail),
LUA_INTERFACE_DEF (upstream, get_addr),
+ LUA_INTERFACE_DEF (upstream, get_port),
LUA_INTERFACE_DEF (upstream, get_name),
{"__tostring", rspamd_lua_class_tostring},
{"__gc", lua_upstream_destroy},
return 1;
}
+/***
+ * @method upstream:get_port()
+ * Get port of upstream
+ * @return {int} port of the upstream
+ */
+static gint
+lua_upstream_get_port (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_lua_upstream *up = lua_check_upstream (L);
+
+ if (up) {
+ lua_pushinteger (L, rspamd_upstream_port (up->up));
+ }
+ else {
+ lua_pushnil (L);
+ }
+
+ return 1;
+}
+
/***
* @method upstream:fail()
* Indicate upstream failure. After certain amount of failures during specified time frame, an upstream is marked as down and does not participate in rotations.