#include <netdb.h>
#include <sys/socket.h>
-#include <lib-ui/curses.h>
+#include <lib-ui/lib-ui.h>
#include "mutt.h"
#include "globals.h"
/* support for multiple socket connections */
static CONNECTION *Connections = NULL;
-/* forward declarations */
-static int socket_preconnect (void);
-static int socket_connect (int fd, struct sockaddr *sa);
-static CONNECTION *socket_new_conn (void);
-
/* Wrappers */
int mutt_socket_open (CONNECTION * conn)
{
- if (socket_preconnect ())
- return -1;
+ int rc;
+
+ if (m_strlen(Preconnect)) {
+ rc = mutt_system (Preconnect);
+ if (rc) {
+ mutt_perror (_("Preconnect command failed."));
+ mutt_sleep (1);
+ return -1;
+ }
+ }
- return conn->conn_open (conn);
+ return conn->conn_open(conn);
}
int mutt_socket_close (CONNECTION * conn)
CONNECTION *mutt_conn_find (const CONNECTION * start, const ACCOUNT * account)
{
CONNECTION *conn;
- ciss_url_t url;
- char hook[LONG_STRING];
-
- /* account isn't actually modified, since url isn't either */
- mutt_account_tourl ((ACCOUNT *) account, &url);
- url.path = NULL;
- url_ciss_tostring (&url, hook, sizeof (hook), 0);
- mutt_account_hook (hook);
conn = start ? start->next : Connections;
while (conn) {
conn = conn->next;
}
- conn = socket_new_conn ();
- memcpy (&conn->account, account, sizeof (ACCOUNT));
-
- conn->next = Connections;
+ conn = p_new(CONNECTION, 1);
+ conn->fd = -1;
+ conn->account = *account;
+ conn->next = Connections;
Connections = conn;
if (Tunnel && *Tunnel)
mutt_tunnel_socket_setup (conn);
- else if (account->flags & M_ACCT_SSL) {
+ else if (account->has_ssl) {
if (mutt_ssl_socket_setup (conn) < 0) {
mutt_socket_free (conn);
return NULL;
return conn;
}
-static int socket_preconnect (void)
-{
- int rc;
- int save_errno;
-
- if (m_strlen(Preconnect)) {
- rc = mutt_system (Preconnect);
- if (rc) {
- save_errno = errno;
- mutt_perror (_("Preconnect command failed."));
- mutt_sleep (1);
-
- return save_errno;
- }
- }
-
- return 0;
-}
-
/* socket_connect: set up to connect to a socket fd. */
static int socket_connect (int fd, struct sockaddr *sa)
{
return save_errno;
}
-/* socket_new_conn: allocate and initialise a new connection. */
-static CONNECTION *socket_new_conn (void)
-{
- CONNECTION *conn;
-
- conn = p_new(CONNECTION, 1);
- conn->fd = -1;
-
- return conn;
-}
-
int raw_socket_close (CONNECTION * conn)
{
return close (conn->fd);
/* we accept v4 or v6 STREAM sockets */
p_clear(&hints, 1);
- if (option (OPTUSEIPV6))
- hints.ai_family = AF_UNSPEC;
- else
- hints.ai_family = AF_INET;
-
+ hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
snprintf (port, sizeof (port), "%d", conn->account.port);