#include "globals.h"
#include "options.h"
#include "protos.h"
-#ifdef USE_SSL
-#include "ssl.h"
-#endif
#include "socket.h"
+#include "ssl.h"
+#include "tunnel.h"
/* support for multiple socket connections */
static struct ConnectionList Connections = TAILQ_HEAD_INITIALIZER(Connections);
/**
* mutt_socket_new - allocate and initialise a new connection
+ * @param type Type of the new Connection
* @retval ptr New Connection
*/
-struct Connection *mutt_socket_new(void)
+struct Connection *mutt_socket_new(enum ConnectionType type)
{
struct Connection *conn = mutt_mem_calloc(1, sizeof(struct Connection));
conn->fd = -1;
- TAILQ_INSERT_HEAD(&Connections, conn, entries);
+ if (type == MUTT_CONNECTION_TUNNEL)
+ {
+ mutt_tunnel_socket_setup(conn);
+ }
+ else if (type == MUTT_CONNECTION_SSL)
+ {
+ int ret = mutt_ssl_socket_setup(conn);
+
+ if (ret < 0)
+ FREE(&conn);
+ }
+ else
+ {
+ conn->conn_read = raw_socket_read;
+ conn->conn_write = raw_socket_write;
+ conn->conn_open = raw_socket_open;
+ conn->conn_close = raw_socket_close;
+ conn->conn_poll = raw_socket_poll;
+ }
+
+ if (conn)
+ TAILQ_INSERT_HEAD(&Connections, conn, entries);
return conn;
}
#include "mutt/queue.h"
+enum ConnectionType
+{
+ MUTT_CONNECTION_SIMPLE,
+ MUTT_CONNECTION_TUNNEL,
+ MUTT_CONNECTION_SSL,
+};
+
struct Connection;
/**
/* stupid hack for imap_logout_all */
struct ConnectionList *mutt_socket_head(void);
-struct Connection *mutt_socket_new(void);
+struct Connection *mutt_socket_new(enum ConnectionType type);
void mutt_socket_free(struct Connection *conn);
int mutt_socket_open(struct Connection *conn);
*/
struct Connection *mutt_conn_find(const struct Connection *start, const struct Account *account)
{
+ enum ConnectionType conn_type;
struct Url url;
char hook[LONG_STRING];
conn = TAILQ_NEXT(conn, entries);
}
- conn = mutt_socket_new();
- memcpy(&conn->account, account, sizeof(struct Account));
-
if (Tunnel && *Tunnel)
- mutt_tunnel_socket_setup(conn);
+ 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 Account));
+ }
+ else
{
- if (mutt_ssl_socket_setup(conn) < 0)
+ 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
- mutt_socket_free(conn);
-
- return NULL;
}
}
- else
- {
- conn->conn_read = raw_socket_read;
- conn->conn_write = raw_socket_write;
- conn->conn_open = raw_socket_open;
- conn->conn_close = raw_socket_close;
- conn->conn_poll = raw_socket_poll;
- }
return conn;
}