*/
void imap_logout_all(void)
{
- struct Connection *conn = NULL;
- struct Connection *tmp = NULL;
-
- conn = mutt_socket_head();
-
- while (conn)
+ struct ConnectionList *head = mutt_socket_head();
+ struct Connection *np, *tmp;
+ TAILQ_FOREACH_SAFE(np, head, entries, tmp)
{
- tmp = conn->next;
-
- if (conn->account.type == MUTT_ACCT_TYPE_IMAP && conn->fd >= 0)
+ if (np->account.type == MUTT_ACCT_TYPE_IMAP && np->fd >= 0)
{
- mutt_message(_("Closing connection to %s..."), conn->account.host);
- imap_logout((struct ImapData **) (void *) &conn->data);
+ TAILQ_REMOVE(head, np, entries);
+ mutt_message(_("Closing connection to %s..."), np->account.host);
+ imap_logout((struct ImapData **) (void *) &np->data);
mutt_clear_error();
- mutt_socket_free(conn);
+ mutt_socket_free(np);
}
-
- conn = tmp;
}
}
}
}
- for (conn = mutt_socket_head(); conn; conn = conn->next)
+ TAILQ_FOREACH(conn, mutt_socket_head(), entries)
{
struct Url url;
char urlstr[LONG_STRING];
struct ImapData *idata = NULL;
time_t now = time(NULL);
- for (conn = mutt_socket_head(); conn; conn = conn->next)
+ TAILQ_FOREACH(conn, mutt_socket_head(), entries)
{
if (conn->account.type == MUTT_ACCT_TYPE_IMAP)
{
#endif
/* support for multiple socket connections */
-static struct Connection *Connections = NULL;
+static struct ConnectionList Connections = TAILQ_HEAD_INITIALIZER(Connections);
static int socket_preconnect(void)
{
return i + 1;
}
-struct Connection *mutt_socket_head(void)
+struct ConnectionList *mutt_socket_head(void)
{
- return Connections;
+ return &Connections;
}
/**
*/
void mutt_socket_free(struct Connection *conn)
{
- struct Connection *iter = NULL;
- struct Connection *tmp = NULL;
-
- iter = Connections;
-
- /* head is special case, doesn't need prev updated */
- if (iter == conn)
- {
- Connections = iter->next;
- FREE(&iter);
- return;
- }
-
- while (iter->next)
+ struct Connection *np = NULL;
+ TAILQ_FOREACH(np, &Connections, entries)
{
- if (iter->next == conn)
+ if (np == conn)
{
- tmp = iter->next;
- iter->next = tmp->next;
- FREE(&tmp);
+ TAILQ_REMOVE(&Connections, np, entries);
+ FREE(&np);
return;
}
- iter = iter->next;
}
}
url_tostring(&url, hook, sizeof(hook), 0);
mutt_account_hook(hook);
- conn = start ? start->next : Connections;
+ conn = start ? TAILQ_NEXT(start, entries) : TAILQ_FIRST(&Connections);
while (conn)
{
if (mutt_account_match(account, &(conn->account)))
return conn;
- conn = conn->next;
+ conn = TAILQ_NEXT(conn, entries);
}
conn = socket_new_conn();
memcpy(&conn->account, account, sizeof(struct Account));
- conn->next = Connections;
- Connections = conn;
+ TAILQ_INSERT_HEAD(&Connections, conn, entries);
if (Tunnel && *Tunnel)
mutt_tunnel_socket_setup(conn);
#include <stddef.h>
#include "account.h"
+#include "list.h"
#include "lib/lib.h"
/* logging levels */
#define MUTT_SOCK_LOG_HDR 3
#define MUTT_SOCK_LOG_FULL 4
+/**
+ * struct ConnectionList - A list of connections
+ */
+TAILQ_HEAD(ConnectionList, Connection);
+
/**
* struct Connection - An open network connection (socket)
*/
int fd;
int available;
- struct Connection *next;
+ TAILQ_ENTRY(Connection) entries;
void *sockdata;
int (*conn_read)(struct Connection *conn, char *buf, size_t len);
int mutt_socket_write_d(struct Connection *conn, const char *buf, int len, int dbg);
/* stupid hack for imap_logout_all */
-struct Connection *mutt_socket_head(void);
+struct ConnectionList *mutt_socket_head(void);
void mutt_socket_free(struct Connection *conn);
struct Connection *mutt_conn_find(const struct Connection *start, const struct Account *account);