};
struct smtp_proxy_ctx {
- struct smtp_upstream upstreams[MAX_SMTP_UPSTREAMS];
- size_t upstream_num;
+ struct upstream_list *upstreams;
gchar *upstreams_str;
rspamd_mempool_t *pool;
rspamd_proxy_t *proxy;
- struct smtp_upstream *upstream;
+ struct upstream *upstream;
struct event *delay_timer;
struct event upstream_ev;
else if (r == -1) {
/* Proxy sent 500 error */
msg_info ("connection with %s got smtp error for greeting",
- session->upstream->name);
+ rspamd_upstream_name (session->upstream));
destroy_session (session->s);
}
}
else {
msg_info ("connection with %s got read error: %s",
- session->upstream->name,
+ rspamd_upstream_name (session->upstream),
strerror (errno));
destroy_session (session->s);
}
else if (r == -1) {
/* Proxy sent 500 error */
msg_info ("connection with %s got smtp error for xclient",
- session->upstream->name);
+ rspamd_upstream_name (session->upstream));
destroy_session (session->s);
}
}
}
else {
msg_info ("connection with %s got read event at improper state: %d",
- session->upstream->name,
+ rspamd_upstream_name (session->upstream),
session->state);
destroy_session (session->s);
}
}
else {
msg_info ("connection with %s got write error: %s",
- session->upstream->name,
+ rspamd_upstream_name (session->upstream),
strerror (errno));
destroy_session (session->s);
}
else {
msg_info (
"connection with %s got write event at improper state: %d",
- session->upstream->name,
+ rspamd_upstream_name (session->upstream),
session->state);
destroy_session (session->s);
}
}
else {
/* Timeout */
- msg_info ("connection with %s timed out", session->upstream->name);
+ msg_info ("connection with %s timed out",
+ rspamd_upstream_name (session->upstream));
destroy_session (session->s);
}
}
static gboolean
create_smtp_proxy_upstream_connection (struct smtp_proxy_session *session)
{
- struct smtp_upstream *selected;
+ struct upstream *selected;
/* Try to select upstream */
- selected = (struct smtp_upstream *)get_upstream_round_robin (
- session->ctx->upstreams,
- session->ctx->upstream_num,
- sizeof (struct smtp_upstream),
- time (NULL),
- DEFAULT_UPSTREAM_ERROR_TIME,
- DEFAULT_UPSTREAM_DEAD_TIME,
- DEFAULT_UPSTREAM_MAXERRORS);
+ selected = rspamd_upstream_get (session->ctx->upstreams,
+ RSPAMD_UPSTREAM_ROUND_ROBIN);
if (selected == NULL) {
msg_err ("no upstreams suitable found");
return FALSE;
session->upstream = selected;
/* Now try to create socket */
- session->upstream_sock = make_universal_socket (selected->name,
- selected->port,
- SOCK_STREAM,
- TRUE,
- FALSE,
- FALSE);
+ session->upstream_sock = rspamd_inet_address_connect (
+ rspamd_upstream_addr (selected), SOCK_STREAM, TRUE);
if (session->upstream_sock == -1) {
- msg_err ("cannot make a connection to %s", selected->name);
- upstream_fail (&selected->up, time (NULL));
+ msg_err ("cannot make a connection to %s",
+ rspamd_upstream_name (session->upstream));
+ rspamd_upstream_fail (selected);
return FALSE;
}
/* Create a proxy for upstream connection */
/* Init upstreams */
if ((value = ctx->upstreams_str) != NULL) {
- if (!parse_upstreams_line (ctx->pool, ctx->upstreams, value,
- &ctx->upstream_num)) {
+ if (!rspamd_upstreams_parse_line (ctx->upstreams, value, 25, NULL)) {
+ msg_err ("cannot parse any valid upstream");
return FALSE;
}
}