aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/smtp/camel-smtp-transport.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2004-09-24 10:50:45 +0800
committerMichael Zucci <zucchi@src.gnome.org>2004-09-24 10:50:45 +0800
commit2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1 (patch)
tree47094ce1777a4c6fe98bfc81e70a07a6f9f5414a /camel/providers/smtp/camel-smtp-transport.c
parent6883c5737127983d776b7071c258ae74c9bfb4c1 (diff)
downloadgsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar.gz
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar.bz2
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar.lz
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar.xz
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.tar.zst
gsoc2013-evolution-2223bc36fa7b6b16ff7ea83e39e64e9375e3ebc1.zip
** See bug #47821.
2004-09-13 Not Zed <NotZed@Ximian.com> ** See bug #47821. * camel-service.c: removed the old hostent based hostname interfaces. * camel-sasl-kerberos4.c (krb4_challenge): new hostname interfaces. * camel-sasl-gssapi.c (gssapi_challenge): new hostname interfaces. * camel-sasl-digest-md5.c (digest_md5_challenge): use new hostname interfaces. (generate_response): just take hostname directly, not hostent. * camel-mime-utils.c (camel_header_msgid_generate): use new hostname interfaces. * providers/smtp/camel-smtp-transport.c (connect_to_server): fixed to use new addrinfo apis. * providers/pop3/camel-pop3-store.c (connect_to_server): fixed to use new addrinfo apis. * camel-tcp-stream-ssl.c (stream_connect): try all addresses supplied. * camel-tcp-stream.c (camel_tcp_stream_get_remote_address) (camel_tcp_stream_get_local_address): return a sockaddr now, and also the address length. Fixed all implementations and callers. (camel_tcp_stream_connect): use addrinfo rather than hostent for host AND port info. Fixed all implementations and callers. svn path=/trunk/; revision=27352
Diffstat (limited to 'camel/providers/smtp/camel-smtp-transport.c')
-rw-r--r--camel/providers/smtp/camel-smtp-transport.c94
1 files changed, 33 insertions, 61 deletions
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index 53a2d2cb68..c3a9e9ed15 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -237,53 +237,60 @@ connect_to_server (CamelService *service, int try_starttls, CamelException *ex)
CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service);
CamelStream *tcp_stream;
char *respbuf = NULL;
- struct hostent *h;
- int port, ret;
+ int ret;
+ struct addrinfo *ai, hints = { 0 };
+ char *serv;
if (!CAMEL_SERVICE_CLASS (parent_class)->connect (service, ex))
return FALSE;
- h = camel_service_gethost (service, ex);
- if (!h)
- return FALSE;
-
/* set some smtp transport defaults */
transport->flags &= CAMEL_SMTP_TRANSPORT_USE_SSL; /* reset all but ssl flags */
transport->authtypes = NULL;
-
- port = service->url->port ? service->url->port : SMTP_PORT;
+
+ if (service->url->port) {
+ serv = g_alloca(16);
+ sprintf(serv, "%d", service->url->port);
+ } else
+ serv = "smtp";
if (transport->flags & CAMEL_SMTP_TRANSPORT_USE_SSL) {
#ifdef HAVE_SSL
if (try_starttls) {
tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS);
} else {
- port = service->url->port ? service->url->port : 465;
+ if (service->url->port == 0)
+ serv = "smtps";
tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS);
}
#else
- if (!try_starttls)
- port = service->url->port ? service->url->port : 465;
+ if (!try_starttls && service->url->port == 0)
+ serv = "smtps";
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s (port %d): %s"),
- service->url->host, port,
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
_("SSL unavailable"));
-
- camel_free_host (h);
-
+
return FALSE;
#endif /* HAVE_SSL */
} else {
tcp_stream = camel_tcp_stream_raw_new ();
}
+
+ hints.ai_socktype = SOCK_STREAM;
+ ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
+ if (ai == NULL) {
+ camel_object_unref(tcp_stream);
+ return FALSE;
+ }
- ret = camel_tcp_stream_connect (CAMEL_TCP_STREAM (tcp_stream), h, port);
- camel_free_host (h);
+ ret = camel_tcp_stream_connect(CAMEL_TCP_STREAM(tcp_stream), ai);
+ camel_freeaddrinfo(ai);
if (ret == -1) {
camel_exception_setv (ex, errno == EINTR ? CAMEL_EXCEPTION_USER_CANCEL : CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s (port %d): %s"),
- service->url->host, port,
+ _("Could not connect to %s (port %s): %s"),
+ service->url->host, serv,
g_strerror (errno));
camel_object_unref (tcp_stream);
@@ -294,7 +301,7 @@ connect_to_server (CamelService *service, int try_starttls, CamelException *ex)
transport->connected = TRUE;
/* get the localaddr - needed later by smtp_helo */
- transport->localaddr = camel_tcp_stream_get_local_address (CAMEL_TCP_STREAM (tcp_stream));
+ transport->localaddr = camel_tcp_stream_get_local_address (CAMEL_TCP_STREAM (tcp_stream), &transport->localaddrlen);
transport->ostream = tcp_stream;
transport->istream = camel_stream_buffer_new (tcp_stream, CAMEL_STREAM_BUFFER_READ);
@@ -580,7 +587,7 @@ smtp_disconnect (CamelService *service, gboolean clean, CamelException *ex)
transport->ostream = NULL;
}
- camel_tcp_address_free (transport->localaddr);
+ g_free(transport->localaddr);
transport->localaddr = NULL;
transport->connected = FALSE;
@@ -865,10 +872,7 @@ smtp_helo (CamelSmtpTransport *transport, CamelException *ex)
{
/* say hello to the server */
char *name = NULL, *cmdbuf = NULL, *respbuf = NULL;
- struct hostent *host;
- CamelException err;
const char *token;
- int af;
/* these are flags that we set, so unset them in case we
are being called a second time (ie, after a STARTTLS) */
@@ -883,42 +887,10 @@ smtp_helo (CamelSmtpTransport *transport, CamelException *ex)
}
camel_operation_start_transient (NULL, _("SMTP Greeting"));
-
- /* get the local host name */
- camel_exception_init (&err);
-#ifdef ENABLE_IPv6
- af = transport->localaddr->family == CAMEL_TCP_ADDRESS_IPv6 ? AF_INET6 : AF_INET;
-#else
- af = AF_INET;
-#endif
- host = camel_gethostbyaddr ((char *) &transport->localaddr->address,
- transport->localaddr->length, af, &err);
-
- camel_exception_clear (&err);
-
- if (host && host->h_name && *host->h_name) {
- name = g_strdup (host->h_name);
- } else {
-#ifdef ENABLE_IPv6
- char ip[MAXHOSTNAMELEN + 1];
- const char *proto;
-
- proto = transport->localaddr->family == CAMEL_TCP_ADDRESS_IPv6 ? "IPv6:" : "";
- name = g_strdup_printf ("[%s%s]", proto, inet_ntop (af, transport->localaddr->address, ip, MAXHOSTNAMELEN));
-#else
- /* We *could* use inet_ntoa() here, but it's probably
- not worth it since we would have to worry about
- some systems not having inet_ntoa() */
- name = g_strdup_printf ("[%d.%d.%d.%d]",
- transport->localaddr->address[0],
- transport->localaddr->address[1],
- transport->localaddr->address[2],
- transport->localaddr->address[3]);
-#endif
- }
-
- if (host)
- camel_free_host (host);
+
+ /* this can't really fail with the flags we're using, it should fallback to numerical */
+ if (camel_getnameinfo(transport->localaddr, transport->localaddrlen, &name, NULL, 0, NULL) != 0)
+ name = g_strdup("localhost.localdomain");
/* hiya server! how are you today? */
if (transport->flags & CAMEL_SMTP_TRANSPORT_IS_ESMTP)