cur->active_idx = i;
}
- rspamd_upstream_resolve_addrs (ls, up);
+ if (up->ctx) {
+ rspamd_upstream_resolve_addrs (ls, up);
- REF_RETAIN (up);
- evtimer_set (&up->ev, rspamd_upstream_revive_cb, up);
- if (up->ctx->ev_base != NULL && up->ctx->configured) {
- event_base_set (up->ctx->ev_base, &up->ev);
- }
+ REF_RETAIN (up);
+ evtimer_set (&up->ev, rspamd_upstream_revive_cb, up);
+ if (up->ctx->ev_base != NULL && up->ctx->configured) {
+ event_base_set (up->ctx->ev_base, &up->ev);
+ }
- ntim = rspamd_time_jitter (up->ctx->revive_time, up->ctx->revive_jitter);
- double_to_tv (ntim, &tv);
- event_add (&up->ev, &tv);
+ ntim = rspamd_time_jitter (up->ctx->revive_time,
+ up->ctx->revive_jitter);
+ double_to_tv (ntim, &tv);
+ event_add (&up->ev, &tv);
+ }
RSPAMD_UPSTREAM_UNLOCK (ls->lock);
}
gdouble sec_last, sec_cur;
struct upstream_addr_elt *addr_elt;
- if (up->active_idx != -1) {
+ if (up->ctx && up->active_idx != -1) {
sec_cur = rspamd_get_ticks (FALSE);
RSPAMD_UPSTREAM_LOCK (up->lock);
case RSPAMD_UPSTREAM_PARSE_DEFAULT:
ret = rspamd_parse_host_port_priority (str, &addrs,
&up->weight,
- &up->name, def_port, ups->ctx->pool);
+ &up->name, def_port, ups->ctx ? ups->ctx->pool : NULL);
break;
case RSPAMD_UPSTREAM_PARSE_NAMESERVER:
addrs = g_ptr_array_sized_new (1);
ret = rspamd_parse_inet_address (&addr, str, strlen (str));
- up->name = rspamd_mempool_strdup (ups->ctx->pool, str);
+
+ if (ups->ctx) {
+ up->name = rspamd_mempool_strdup (ups->ctx->pool, str);
+ }
+ else {
+ up->name = g_strdup (str);
+ }
if (ret) {
if (rspamd_inet_address_get_port (addr) == 0) {
}
g_ptr_array_add (addrs, addr);
- rspamd_mempool_add_destructor (ups->ctx->pool,
- (rspamd_mempool_destruct_t)rspamd_inet_address_free,
- addr);
- rspamd_mempool_add_destructor (ups->ctx->pool,
- (rspamd_mempool_destruct_t)rspamd_ptr_array_free_hard,
- addrs);
+
+ if (ups->ctx) {
+ rspamd_mempool_add_destructor (ups->ctx->pool,
+ (rspamd_mempool_destruct_t) rspamd_inet_address_free,
+ addr);
+ rspamd_mempool_add_destructor (ups->ctx->pool,
+ (rspamd_mempool_destruct_t) rspamd_ptr_array_free_hard,
+ addrs);
+ }
}
else {
g_ptr_array_free (addrs, TRUE);
REF_INIT_RETAIN (up, rspamd_upstream_dtor);
up->lock = rspamd_mutex_new ();
up->ctx = ups->ctx;
- REF_RETAIN (ups->ctx);
- g_queue_push_tail (ups->ctx->upstreams, up);
- up->ctx_pos = g_queue_peek_tail_link (ups->ctx->upstreams);
+
+ if (up->ctx) {
+ REF_RETAIN (ups->ctx);
+ g_queue_push_tail (ups->ctx->upstreams, up);
+ up->ctx_pos = g_queue_peek_tail_link (ups->ctx->upstreams);
+ }
+
g_ptr_array_sort (up->addrs.addr, rspamd_upstream_addr_sort_func);
rspamd_upstream_set_active (ups, up);
lua_upstream_list_create (lua_State *L)
{
struct upstream_list *new = NULL, **pnew;
- struct rspamd_config *cfg = lua_check_config (L, 1);
+ struct rspamd_config *cfg = NULL;
const gchar *def;
guint default_port = 0;
+ gint top;
- def = luaL_checkstring (L, 2);
- if (def && cfg) {
- if (lua_gettop (L) >= 3) {
- default_port = luaL_checknumber (L, 3);
+
+ if (lua_type (L, 1) == LUA_TUSERDATA) {
+ cfg = lua_check_config (L, 1);
+ top = 2;
+ }
+ else {
+ top = 1;
+ }
+
+ def = luaL_checkstring (L, top);
+ if (def) {
+ if (lua_gettop (L) >= top + 1) {
+ default_port = luaL_checknumber (L, top + 1);
}
- new = rspamd_upstreams_create (cfg->ups_ctx);
+ new = rspamd_upstreams_create (cfg ? cfg->ups_ctx : NULL);
if (rspamd_upstreams_parse_line (new, def, default_port, NULL)) {
pnew = lua_newuserdata (L, sizeof (struct upstream_list *));