示例#1
0
文件: socket.c 项目: darnir/neomutt
/**
 * 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(enum ConnectionType type)
{
  struct Connection *conn = mutt_mem_calloc(1, sizeof(struct Connection));
  conn->fd = -1;

  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;
  }

  return conn;
}
示例#2
0
/* mutt_conn_find: find a connection off the list of connections whose
 *   account matches account. If start is not null, only search for
 *   connections after the given connection (allows higher level socket code
 *   to make more fine-grained searches than account info - eg in IMAP we may
 *   wish to find a connection which is not in IMAP_SELECTED state) */
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) {
                if (mutt_account_match (account, &(conn->account)))
                        return conn;
                conn = conn->next;
        }

        conn = socket_new_conn ();
        memcpy (&conn->account, account, sizeof (ACCOUNT));

        conn->next = Connections;
        Connections = conn;

        if (Tunnel && *Tunnel)
                mutt_tunnel_socket_setup (conn);
        else if (account->flags & M_ACCT_SSL) {
#if defined(USE_SSL)
                if (mutt_ssl_socket_setup (conn) < 0) {
                        mutt_socket_free (conn);
                        return NULL;
                }
#else
                mutt_error _("SSL is unavailable.");
                mutt_sleep (2);
                mutt_socket_free (conn);

                return NULL;
#endif
        }
        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;
}