projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix small bug from julien
[apps/madmutt.git]
/
mutt_socket.c
diff --git
a/mutt_socket.c
b/mutt_socket.c
index
90ae621
..
e5fc1a3
100644
(file)
--- a/
mutt_socket.c
+++ b/
mutt_socket.c
@@
-13,16
+13,22
@@
# include "config.h"
#endif
# include "config.h"
#endif
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+#include <lib-lib/macros.h>
+
#include "mutt.h"
#include "globals.h"
#include "mutt_socket.h"
#include "mutt_tunnel.h"
#include "mutt.h"
#include "globals.h"
#include "mutt_socket.h"
#include "mutt_tunnel.h"
-#if defined(USE_SSL) || defined(USE_GNUTLS)
|| defined(USE_NSS)
+#if defined(USE_SSL) || defined(USE_GNUTLS)
# include "mutt_ssl.h"
#endif
#include "mutt_idna.h"
# include "mutt_ssl.h"
#endif
#include "mutt_idna.h"
+#include "lib/debug.h"
+
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
@@
-39,7
+45,7
@@
static CONNECTION *Connections = NULL;
/* forward declarations */
static int socket_preconnect (void);
static int socket_connect (int fd, struct sockaddr *sa);
/* forward declarations */
static int socket_preconnect (void);
static int socket_connect (int fd, struct sockaddr *sa);
-static CONNECTION *socket_new_conn ();
+static CONNECTION *socket_new_conn (
void
);
/* Wrappers */
int mutt_socket_open (CONNECTION * conn)
/* Wrappers */
int mutt_socket_open (CONNECTION * conn)
@@
-55,9
+61,7
@@
int mutt_socket_close (CONNECTION * conn)
int rc = -1;
if (conn->fd < 0)
int rc = -1;
if (conn->fd < 0)
- dprint (1,
- (debugfile,
- "mutt_socket_close: Attempt to close closed connection.\n"));
+ debug_print (1, ("Attempt to close closed connection.\n"));
else
rc = conn->conn_close (conn);
else
rc = conn->conn_close (conn);
@@
-72,9
+76,7
@@
int mutt_socket_read (CONNECTION * conn, char *buf, size_t len)
int rc;
if (conn->fd < 0) {
int rc;
if (conn->fd < 0) {
- dprint (1,
- (debugfile,
- "mutt_socket_read: attempt to read from closed connection\n"));
+ debug_print (1, ("attempt to read from closed connection\n"));
return -1;
}
return -1;
}
@@
-95,28
+97,23
@@
int mutt_socket_write_d (CONNECTION * conn, const char *buf, int dbg)
int rc;
int len;
int rc;
int len;
- d
print (dbg, (debugfile,
"> %s", buf));
+ d
ebug_print (dbg, (
"> %s", buf));
if (conn->fd < 0) {
if (conn->fd < 0) {
- dprint (1,
- (debugfile,
- "mutt_socket_write: attempt to write to closed connection\n"));
+ debug_print (1, ("attempt to write to closed connection\n"));
return -1;
}
return -1;
}
- len = m
utt_strlen
(buf);
+ len = m
_strlen
(buf);
if ((rc = conn->conn_write (conn, buf, len)) < 0) {
if ((rc = conn->conn_write (conn, buf, len)) < 0) {
- dprint (1, (debugfile,
- "mutt_socket_write: error writing, closing socket\n"));
+ debug_print (1, ("error writing, closing socket\n"));
mutt_socket_close (conn);
return -1;
}
if (rc < len) {
mutt_socket_close (conn);
return -1;
}
if (rc < len) {
- dprint (1, (debugfile,
- "mutt_socket_write: ERROR: wrote %d of %d bytes!\n", rc,
- len));
+ debug_print (1, ("ERROR: wrote %d of %d bytes!\n", rc, len));
}
return rc;
}
return rc;
@@
-130,9
+127,7
@@
int mutt_socket_readchar (CONNECTION * conn, char *c)
conn->available =
conn->conn_read (conn, conn->inbuf, sizeof (conn->inbuf));
else {
conn->available =
conn->conn_read (conn, conn->inbuf, sizeof (conn->inbuf));
else {
- dprint (1,
- (debugfile,
- "mutt_socket_readchar: attempt to read from closed connection.\n"));
+ debug_print (1, ("attempt to read from closed connection.\n"));
return -1;
}
conn->bufpos = 0;
return -1;
}
conn->bufpos = 0;
@@
-173,9
+168,9
@@
int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION * conn,
else
buf[i] = '\0';
else
buf[i] = '\0';
- d
print (dbg, (debugfile,
"< %s\n", buf));
+ d
ebug_print (dbg, (
"< %s\n", buf));
- /* number of bytes read, not m
utt_strlen
*/
+ /* number of bytes read, not m
_strlen
*/
return i + 1;
}
return i + 1;
}
@@
-195,7
+190,7
@@
void mutt_socket_free (CONNECTION * conn)
/* head is special case, doesn't need prev updated */
if (iter == conn) {
Connections = iter->next;
/* head is special case, doesn't need prev updated */
if (iter == conn) {
Connections = iter->next;
-
FREE
(&iter);
+
p_delete
(&iter);
return;
}
return;
}
@@
-203,7
+198,7
@@
void mutt_socket_free (CONNECTION * conn)
if (iter->next == conn) {
tmp = iter->next;
iter->next = tmp->next;
if (iter->next == conn) {
tmp = iter->next;
iter->next = tmp->next;
-
FREE
(&tmp);
+
p_delete
(&tmp);
return;
}
iter = iter->next;
return;
}
iter = iter->next;
@@
-243,12
+238,8
@@
CONNECTION *mutt_conn_find (const CONNECTION * start, const ACCOUNT * account)
if (Tunnel && *Tunnel)
mutt_tunnel_socket_setup (conn);
else if (account->flags & M_ACCT_SSL) {
if (Tunnel && *Tunnel)
mutt_tunnel_socket_setup (conn);
else if (account->flags & M_ACCT_SSL) {
-#ifdef USE_SSL
- ssl_socket_setup (conn);
-#elif USE_NSS
- mutt_nss_socket_setup (conn);
-#elif USE_GNUTLS
- if (mutt_gnutls_socket_setup (conn) < 0) {
+#if defined (USE_SSL) || defined (USE_GNUTLS)
+ if (mutt_ssl_socket_setup (conn) < 0) {
mutt_socket_free (conn);
return NULL;
}
mutt_socket_free (conn);
return NULL;
}
@@
-276,10
+267,10
@@
static int socket_preconnect (void)
int rc;
int save_errno;
int rc;
int save_errno;
- if (m
utt_strlen
(Preconnect)) {
- d
print (2, (debugfile,
"Executing preconnect: %s\n", Preconnect));
+ if (m
_strlen
(Preconnect)) {
+ d
ebug_print (2, (
"Executing preconnect: %s\n", Preconnect));
rc = mutt_system (Preconnect);
rc = mutt_system (Preconnect);
- d
print (2, (debugfile,
"Preconnect result: %d\n", rc));
+ d
ebug_print (2, (
"Preconnect result: %d\n", rc));
if (rc) {
save_errno = errno;
mutt_perror (_("Preconnect command failed."));
if (rc) {
save_errno = errno;
mutt_perror (_("Preconnect command failed."));
@@
-305,7
+296,7
@@
static int socket_connect (int fd, struct sockaddr *sa)
sa_size = sizeof (struct sockaddr_in6);
#endif
else {
sa_size = sizeof (struct sockaddr_in6);
#endif
else {
- d
print (1, (debugfile,
"Unknown address family!\n"));
+ d
ebug_print (1, (
"Unknown address family!\n"));
return -1;
}
return -1;
}
@@
-318,7
+309,7
@@
static int socket_connect (int fd, struct sockaddr *sa)
if (connect (fd, sa, sa_size) < 0) {
save_errno = errno;
if (connect (fd, sa, sa_size) < 0) {
save_errno = errno;
- d
print (2, (debugfile,
"Connection failed. errno: %d...\n", errno));
+ d
ebug_print (2, (
"Connection failed. errno: %d...\n", errno));
SigInt = 0; /* reset in case we caught SIGINTR while in connect() */
}
SigInt = 0; /* reset in case we caught SIGINTR while in connect() */
}
@@
-330,11
+321,11
@@
static int socket_connect (int fd, struct sockaddr *sa)
}
/* socket_new_conn: allocate and initialise a new connection. */
}
/* socket_new_conn: allocate and initialise a new connection. */
-static CONNECTION *socket_new_conn ()
+static CONNECTION *socket_new_conn (
void
)
{
CONNECTION *conn;
{
CONNECTION *conn;
- conn =
(CONNECTION *) safe_calloc (1, sizeof (CONNECTION)
);
+ conn =
p_new(CONNECTION, 1
);
conn->fd = -1;
return conn;
conn->fd = -1;
return conn;
@@
-388,7
+379,7
@@
int raw_socket_open (CONNECTION * conn)
struct addrinfo *cur;
/* we accept v4 or v6 STREAM sockets */
struct addrinfo *cur;
/* we accept v4 or v6 STREAM sockets */
-
memset (&hints, 0, sizeof (hints)
);
+
p_clear(&hints, 1
);
if (option (OPTUSEIPV6))
hints.ai_family = AF_UNSPEC;
if (option (OPTUSEIPV6))
hints.ai_family = AF_UNSPEC;
@@
-414,11
+405,12
@@
int raw_socket_open (CONNECTION * conn)
rc = getaddrinfo (host_idna, port, &hints, &res);
# ifdef HAVE_LIBIDN
rc = getaddrinfo (host_idna, port, &hints, &res);
# ifdef HAVE_LIBIDN
-
FREE
(&host_idna);
+
p_delete
(&host_idna);
# endif
if (rc) {
mutt_error (_("Could not find the host \"%s\""), conn->account.host);
# endif
if (rc) {
mutt_error (_("Could not find the host \"%s\""), conn->account.host);
+ mutt_sleep (2);
return -1;
}
return -1;
}
@@
-447,7
+439,7
@@
int raw_socket_open (CONNECTION * conn)
struct hostent *he;
int i;
struct hostent *he;
int i;
-
memset (&sin, 0, sizeof (sin)
);
+
p_clear(&sin, 1
);
sin.sin_port = htons (conn->account.port);
sin.sin_family = AF_INET;
sin.sin_port = htons (conn->account.port);
sin.sin_family = AF_INET;
@@
-464,7
+456,7
@@
int raw_socket_open (CONNECTION * conn)
if ((he = gethostbyname (host_idna)) == NULL) {
# ifdef HAVE_LIBIDN
if ((he = gethostbyname (host_idna)) == NULL) {
# ifdef HAVE_LIBIDN
-
FREE
(&host_idna);
+
p_delete
(&host_idna);
# endif
mutt_error (_("Could not find the host \"%s\""), conn->account.host);
# endif
mutt_error (_("Could not find the host \"%s\""), conn->account.host);
@@
-472,7
+464,7
@@
int raw_socket_open (CONNECTION * conn)
}
# ifdef HAVE_LIBIDN
}
# ifdef HAVE_LIBIDN
-
FREE
(&host_idna);
+
p_delete
(&host_idna);
# endif
mutt_message (_("Connecting to %s..."), conn->account.host);
# endif
mutt_message (_("Connecting to %s..."), conn->account.host);
@@
-484,6
+476,7
@@
int raw_socket_open (CONNECTION * conn)
if (fd >= 0) {
if ((rc = socket_connect (fd, (struct sockaddr *) &sin)) == 0) {
if (fd >= 0) {
if ((rc = socket_connect (fd, (struct sockaddr *) &sin)) == 0) {
+ fcntl (fd, F_SETFD, FD_CLOEXEC);
conn->fd = fd;
break;
}
conn->fd = fd;
break;
}