]> granicus.if.org Git - neomutt/commitdiff
refactor mutt_conn_new()
authorRichard Russon <rich@flatcap.org>
Fri, 28 Sep 2018 18:48:37 +0000 (19:48 +0100)
committerRichard Russon <rich@flatcap.org>
Fri, 28 Sep 2018 22:51:56 +0000 (23:51 +0100)
mutt_socket.c
mutt_socket.h

index 94882e018ca1e782e02ca677843f6734f7224a71..24e99664a1ead2995bbb9bf66e9581edc7b4098c 100644 (file)
 #include "hook.h"
 #include "mutt_account.h"
 
+struct Connection *mutt_conn_new(const struct ConnAccount *account)
+{
+  enum ConnectionType conn_type;
+
+  if (Tunnel && *Tunnel)
+    conn_type = MUTT_CONNECTION_TUNNEL;
+  else if (account->flags & MUTT_ACCT_SSL)
+    conn_type = MUTT_CONNECTION_SSL;
+  else
+    conn_type = MUTT_CONNECTION_SIMPLE;
+
+  struct Connection *conn = mutt_socket_new(conn_type);
+  if (conn)
+  {
+    memcpy(&conn->account, account, sizeof(struct ConnAccount));
+  }
+  else
+  {
+    if (conn_type == MUTT_CONNECTION_SSL)
+    {
+#ifndef USE_SSL
+      /* that's probably why it failed */
+      mutt_error(_("SSL is unavailable, cannot connect to %s"), account->host);
+#endif
+    }
+  }
+  return conn;
+}
+
 /**
  * mutt_conn_find - Find a connection from a list
  * @param start   First connection to try
@@ -51,7 +80,6 @@
 struct Connection *mutt_conn_find(const struct Connection *start,
                                   const struct ConnAccount *account)
 {
-  enum ConnectionType conn_type;
   struct Url url;
   char hook[LONG_STRING];
 
@@ -70,28 +98,5 @@ struct Connection *mutt_conn_find(const struct Connection *start,
     conn = TAILQ_NEXT(conn, entries);
   }
 
-  if (Tunnel && *Tunnel)
-    conn_type = MUTT_CONNECTION_TUNNEL;
-  else if (account->flags & MUTT_ACCT_SSL)
-    conn_type = MUTT_CONNECTION_SSL;
-  else
-    conn_type = MUTT_CONNECTION_SIMPLE;
-
-  conn = mutt_socket_new(conn_type);
-  if (conn)
-  {
-    memcpy(&conn->account, account, sizeof(struct ConnAccount));
-  }
-  else
-  {
-    if (conn_type == MUTT_CONNECTION_SSL)
-    {
-#ifndef USE_SSL
-      /* that's probably why it failed */
-      mutt_error(_("SSL is unavailable, cannot connect to %s"), account->host);
-#endif
-    }
-  }
-
-  return conn;
+  return mutt_conn_new(account);
 }
index 78175e35fc6c951e50fa3f38e9eac93fb860f560..3f95014dfd9667a2813555dbec2a1230cf35f934 100644 (file)
@@ -32,6 +32,7 @@ struct Connection;
 #define MUTT_SOCK_LOG_FULL 4
 
 struct Connection *mutt_conn_find(const struct Connection *start, const struct ConnAccount *account);
+struct Connection *mutt_conn_new(const struct ConnAccount *account);
 
 #define mutt_socket_readln(A, B, C)  mutt_socket_readln_d(A, B, C, MUTT_SOCK_LOG_CMD)
 #define mutt_socket_send(conn, buffer)           mutt_socket_send_d(conn, buffer, MUTT_SOCK_LOG_CMD)