]> source.dussan.org Git - rspamd.git/commitdiff
Fix some more old upstreams code.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Oct 2014 01:38:22 +0000 (01:38 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Oct 2014 01:38:22 +0000 (01:38 +0000)
src/libmime/smtp_proto.c
src/libmime/smtp_utils.c
src/libmime/smtp_utils.h
src/libutil/upstream.c
src/libutil/upstream.h
src/smtp.h

index c9220f84ab171d206b1f7a15156ff9fade4f21fb..c716b7480fdda3add1f5a57230d2e0fe85265117 100644 (file)
@@ -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);
 }
 
index 0940871dd0b4595bd55491b049dab3d69d666c69..b29a9d717cf8c3434a3048e25783a3678a0a6c0a 100644 (file)
@@ -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;
-}
index bb17d142e4edd1962911fb58ee7691403688d39e..f72831b6b6f353724247bac76192048eee2457e2 100644 (file)
@@ -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_ */
index ca3c4a947fbd1506ba6fe9d13c779a268c8a4979..0ed103111b7ad9efa91510e27b1eb14d85faa68a 100644 (file)
@@ -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)
index 7adad8d22604bd17077c74ac5b5b3a55b2dbf42d..cc4462878ac9832eacdd849ec8dd3a06fbabb765 100644 (file)
@@ -69,6 +69,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
index aa1651b1244fb5e5aeaf15ecac9e47dd6d7d7e65..d6713eeb209b79816a263b5d37a9f9638f297a31 100644 (file)
@@ -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;