aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 01:38:22 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2014-10-29 01:38:22 +0000
commitdb1fd009599ba9c60f569b2ce5a99c373ad9f478 (patch)
treef439f05bce1a533104c673dada54747033b017ea
parentabb6a8e41b9d5a9eb671222bfc77814eb0731212 (diff)
downloadrspamd-db1fd009599ba9c60f569b2ce5a99c373ad9f478.tar.gz
rspamd-db1fd009599ba9c60f569b2ce5a99c373ad9f478.zip
Fix some more old upstreams code.
-rw-r--r--src/libmime/smtp_proto.c4
-rw-r--r--src/libmime/smtp_utils.c84
-rw-r--r--src/libmime/smtp_utils.h14
-rw-r--r--src/libutil/upstream.c6
-rw-r--r--src/libutil/upstream.h7
-rw-r--r--src/smtp.h4
6 files changed, 24 insertions, 95 deletions
diff --git a/src/libmime/smtp_proto.c b/src/libmime/smtp_proto.c
index c9220f84a..c716b7480 100644
--- a/src/libmime/smtp_proto.c
+++ b/src/libmime/smtp_proto.c
@@ -742,7 +742,7 @@ smtp_upstream_err_socket (GError *err, void *arg)
struct smtp_session *session = arg;
msg_info ("abnormally closing connection with upstream %s, error: %s",
- session->upstream->name,
+ rspamd_upstream_name (session->upstream),
err->message);
session->error = SMTP_ERROR_UPSTREAM;
session->state = SMTP_STATE_CRITICAL_ERROR;
@@ -756,7 +756,7 @@ smtp_upstream_err_socket (GError *err, void *arg)
FALSE, TRUE)) {
return;
}
- upstream_fail (&session->upstream->up, session->session_time);
+ rspamd_upstream_fail (session->upstream);
destroy_session (session->s);
}
diff --git a/src/libmime/smtp_utils.c b/src/libmime/smtp_utils.c
index 0940871dd..b29a9d717 100644
--- a/src/libmime/smtp_utils.c
+++ b/src/libmime/smtp_utils.c
@@ -60,17 +60,11 @@ free_smtp_session (gpointer arg)
gboolean
create_smtp_upstream_connection (struct smtp_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),
- session->session_time,
- 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;
@@ -79,15 +73,11 @@ create_smtp_upstream_connection (struct smtp_session *session)
session->upstream = selected;
/* Now try to create socket */
- session->upstream_sock = make_universal_socket (selected->addr,
- 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, session->session_time);
+ msg_err ("cannot make a connection to %s", rspamd_upstream_name (selected));
+ rspamd_upstream_fail (selected);
return FALSE;
}
/* Create a dispatcher for upstream connection */
@@ -380,63 +370,3 @@ err:
destroy_session (session->s);
return FALSE;
}
-
-gboolean
-parse_upstreams_line (rspamd_mempool_t *pool,
- struct smtp_upstream *upstreams,
- const gchar *line,
- gsize *count)
-{
- gchar **strv, *p, *t, *tt, *err_str;
- guint32 num, i;
- struct smtp_upstream *cur;
- gchar resolved_path[PATH_MAX];
-
- strv = g_strsplit_set (line, ",; ", -1);
- num = g_strv_length (strv);
-
- if (num >= MAX_SMTP_UPSTREAMS) {
- msg_err ("cannot define %d upstreams %d is max", num,
- MAX_SMTP_UPSTREAMS);
- return FALSE;
- }
- *count = 0;
-
- for (i = 0; i < num; i++) {
- p = strv[i];
- cur = &upstreams[*count];
- if ((t = strrchr (p, ':')) != NULL && (tt = strchr (p, ':')) != t) {
- /* Assume that after last `:' we have weigth */
- *t = '\0';
- t++;
- errno = 0;
- cur->up.priority = strtoul (t, &err_str, 10);
- if (errno != 0 || (err_str && *err_str != '\0')) {
- msg_err ("cannot convert weight: %s, %s", t, strerror (errno));
- g_strfreev (strv);
- return FALSE;
- }
- }
- if (*p == '/') {
- cur->is_unix = TRUE;
- if (realpath (p, resolved_path) == NULL) {
- msg_err ("cannot resolve path: %s", resolved_path);
- g_strfreev (strv);
- return FALSE;
- }
- cur->name = rspamd_mempool_strdup (pool, resolved_path);
- (*count)++;
- }
- else {
- if (!rspamd_parse_host_port (pool, p, &cur->addr, &cur->port)) {
- g_strfreev (strv);
- return FALSE;
- }
- cur->name = rspamd_mempool_strdup (pool, p);
- (*count)++;
- }
- }
-
- g_strfreev (strv);
- return TRUE;
-}
diff --git a/src/libmime/smtp_utils.h b/src/libmime/smtp_utils.h
index bb17d142e..f72831b6b 100644
--- a/src/libmime/smtp_utils.h
+++ b/src/libmime/smtp_utils.h
@@ -9,8 +9,6 @@
*/
struct smtp_upstream {
- struct upstream up;
-
const gchar *name;
gchar *addr;
guint16 port;
@@ -49,16 +47,4 @@ gboolean write_smtp_reply (struct smtp_session *session);
*/
void free_smtp_session (gpointer arg);
-/**
- * Parse upstreams line
- * @param upstreams pointer to the array of upstreams (must be at least MAX_SMTP_UPSTREAMS size)
- * @param line description line
- * @param count targeted count
- * @return
- */
-gboolean parse_upstreams_line (rspamd_mempool_t *pool,
- struct smtp_upstream *upstreams,
- const gchar *line,
- gsize *count);
-
#endif /* SMTP_UTILS_H_ */
diff --git a/src/libutil/upstream.c b/src/libutil/upstream.c
index ca3c4a947..0ed103111 100644
--- a/src/libutil/upstream.c
+++ b/src/libutil/upstream.c
@@ -296,6 +296,12 @@ rspamd_upstream_addr (struct upstream *up)
return &up->addrs.addr[up->addrs.cur++ % up->addrs.count];
}
+const gchar*
+rspamd_upstream_name (struct upstream *up)
+{
+ return up->name;
+}
+
gboolean
rspamd_upstreams_add_upstream (struct upstream_list *ups,
const gchar *str, guint16 def_port, void *data)
diff --git a/src/libutil/upstream.h b/src/libutil/upstream.h
index 7adad8d22..cc4462878 100644
--- a/src/libutil/upstream.h
+++ b/src/libutil/upstream.h
@@ -70,6 +70,13 @@ gboolean rspamd_upstreams_add_upstream (struct upstream_list *ups,
rspamd_inet_addr_t* rspamd_upstream_addr (struct upstream *up);
/**
+ * Returns the symbolic name of the upstream
+ * @param up
+ * @return
+ */
+const gchar* rspamd_upstream_name (struct upstream *up);
+
+/**
* Get new upstream from the list
* @param ups upstream list
* @param type type of rotation algorithm, for `RSPAMD_UPSTREAM_HASHED` it is required to specify `key` and `keylen` as arguments
diff --git a/src/smtp.h b/src/smtp.h
index aa1651b12..d6713eeb2 100644
--- a/src/smtp.h
+++ b/src/smtp.h
@@ -21,7 +21,7 @@ enum rspamd_smtp_stage {
};
struct smtp_worker_ctx {
- struct smtp_upstream upstreams[MAX_SMTP_UPSTREAMS];
+ struct upstream_list *upstreams;
gsize upstream_num;
gchar *upstreams_str;
@@ -96,7 +96,7 @@ struct smtp_session {
rspamd_io_dispatcher_t *dispatcher;
rspamd_io_dispatcher_t *upstream_dispatcher;
- struct smtp_upstream *upstream;
+ struct upstream *upstream;
struct event *delay_timer;