diff options
author | Jeffrey Stedfast <fejj@novell.com> | 2004-09-28 01:41:16 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2004-09-28 01:41:16 +0800 |
commit | e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa (patch) | |
tree | 652e325cf8c7c28bb03682bb9021ad79f0834986 /camel/providers/pop3 | |
parent | c3a9a32b59ef4fb590e8a2232177630891b46b71 (diff) | |
download | gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar.gz gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar.bz2 gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar.lz gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar.xz gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.tar.zst gsoc2013-evolution-e5e0149bb66b663bba92c0eb8dd7dfbe6e33d9fa.zip |
Instead of doing a host-lookup ourselves, get it passed in to us as an
2004-09-22 Jeffrey Stedfast <fejj@novell.com>
* providers/imap/camel-imap-store.c (connect_to_server): Instead
of doing a host-lookup ourselves, get it passed in to us as an
argument. Also simplified a bit (try_starttls is no longer an
option).
(connect_to_server_wrapper): Simplified (we no longer have
fallback cases for SSL stuff). Also, perform host lookup here.
* providers/imap4/camel-imap4-store.c: Same changes as above.
* providers/pop3/camel-pop3-store.c: Same.
* providers/smtp/camel-smtp-transport.c: Same. Other changes
include making the code consistant with the other providers.
* providers/nntp/camel-nntp-store.c: Same as pop/imap.
svn path=/trunk/; revision=27398
Diffstat (limited to 'camel/providers/pop3')
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.c | 161 |
1 files changed, 59 insertions, 102 deletions
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c index 6870aa1456..1c7b9d025d 100644 --- a/camel/providers/pop3/camel-pop3-store.c +++ b/camel/providers/pop3/camel-pop3-store.c @@ -135,16 +135,16 @@ finalize (CamelObject *object) } enum { - USE_SSL_NEVER, - USE_SSL_ALWAYS, - USE_SSL_WHEN_POSSIBLE + MODE_CLEAR, + MODE_SSL, + MODE_TLS, }; #define SSL_PORT_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_SSL2 | CAMEL_TCP_STREAM_SSL_ENABLE_SSL3) #define STARTTLS_FLAGS (CAMEL_TCP_STREAM_SSL_ENABLE_TLS) static gboolean -connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelException *ex) +connect_to_server (CamelService *service, struct addrinfo *ai, int ssl_mode, CamelException *ex) { CamelPOP3Store *store = CAMEL_POP3_STORE (service); CamelStream *tcp_stream; @@ -152,56 +152,34 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelE guint32 flags = 0; int clean_quit; int ret; - struct addrinfo *ai, hints = { 0 }; - char *serv; - - if (service->url->port) { - serv = g_alloca(16); - sprintf(serv, "%d", service->url->port); - } else - serv = "pop3"; - - if (ssl_mode != USE_SSL_NEVER) { + + if (ssl_mode != MODE_CLEAR) { #ifdef HAVE_SSL - if (try_starttls) { - tcp_stream = camel_tcp_stream_ssl_new_raw (service->session, service->url->host, STARTTLS_FLAGS); + if (ssl_mode == MODE_TLS) { + tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, STARTTLS_FLAGS); } else { - if (service->url->port == 0) - serv = "pop3s"; tcp_stream = camel_tcp_stream_ssl_new (service->session, service->url->host, SSL_PORT_FLAGS); } #else - if (!try_starttls && service->url->port == 0) - serv = "pop3s"; - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - _("Could not connect to %s (port %s): %s"), - service->url->host, serv, - _("SSL unavailable")); + _("Could not connect to %s: %s"), + service->url->host, _("SSL unavailable")); 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), ai); - camel_freeaddrinfo(ai); - if (ret == -1) { + if ((ret = camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai)) == -1) { if (errno == EINTR) camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Connection cancelled")); else camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - _("Could not connect to POP server %s (port %s): %s"), - service->url->host, serv, g_strerror (errno)); + _("Could not connect to %s: %s"), + service->url->host, + g_strerror (errno)); camel_object_unref (tcp_stream); @@ -219,41 +197,24 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelE if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Failed to read a valid greeting from POP server %s (port %s)"), - service->url->host, serv); + _("Failed to read a valid greeting from POP server %s"), + service->url->host); + return FALSE; } -#ifdef HAVE_SSL - if (store->engine) { - if (ssl_mode == USE_SSL_WHEN_POSSIBLE) { - if (store->engine->capa & CAMEL_POP3_CAP_STLS) - goto starttls; - } else if (ssl_mode == USE_SSL_ALWAYS) { - if (try_starttls) { - if (store->engine->capa & CAMEL_POP3_CAP_STLS) { - /* attempt to toggle STARTTLS mode */ - goto starttls; - } else { - /* server doesn't support STARTTLS, abort */ - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Failed to connect to POP server %s in secure mode: %s"), - service->url->host, _("SSL/TLS extension not supported.")); - /* we have the possibility of quitting cleanly here */ - clean_quit = TRUE; - goto stls_exception; - } - } - } + if (ssl_mode != MODE_TLS) { + camel_object_unref (tcp_stream); + return TRUE; } -#endif /* HAVE_SSL */ - - camel_object_unref (tcp_stream); - return store->engine != NULL; + if (!(store->engine->capa & CAMEL_POP3_CAP_STLS)) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Failed to connect to POP server %s in secure mode: %s"), + service->url->host, _("STLS not supported")); + goto stls_exception; + } -#ifdef HAVE_SSL - starttls: /* as soon as we send a STLS command, all hope is lost of a clean QUIT if problems arise */ clean_quit = FALSE; @@ -303,59 +264,55 @@ connect_to_server (CamelService *service, int ssl_mode, int try_starttls, CamelE store->engine = NULL; return FALSE; -#endif /* HAVE_SSL */ } static struct { char *value; + char *serv; int mode; } ssl_options[] = { - { "", USE_SSL_ALWAYS }, - { "always", USE_SSL_ALWAYS }, - { "when-possible", USE_SSL_WHEN_POSSIBLE }, - { "never", USE_SSL_NEVER }, - { NULL, USE_SSL_NEVER }, + { "", "pop3s", MODE_SSL }, /* really old (1.x) */ + { "always", "pop3s", MODE_SSL }, + { "when-possible", "pop3", MODE_TLS }, + { "never", "pop3", MODE_CLEAR }, + { NULL, "pop3", MODE_CLEAR }, }; static gboolean connect_to_server_wrapper (CamelService *service, CamelException *ex) { -#ifdef HAVE_SSL - const char *use_ssl; - int i, ssl_mode; + struct addrinfo hints, *ai; + const char *ssl_mode; + int mode, ret, i; + char *serv; - use_ssl = camel_url_get_param (service->url, "use_ssl"); - if (use_ssl) { + if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) { for (i = 0; ssl_options[i].value; i++) - if (!strcmp (ssl_options[i].value, use_ssl)) + if (!strcmp (ssl_options[i].value, ssl_mode)) break; - ssl_mode = ssl_options[i].mode; - } else - ssl_mode = USE_SSL_NEVER; - - if (ssl_mode == USE_SSL_ALWAYS) { - /* First try the ssl port */ - if (!connect_to_server (service, ssl_mode, FALSE, ex)) { - if (camel_exception_get_id (ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE) { - /* The ssl port seems to be unavailable, lets try STARTTLS */ - camel_exception_clear (ex); - return connect_to_server (service, ssl_mode, TRUE, ex); - } else { - return FALSE; - } - } - - return TRUE; - } else if (ssl_mode == USE_SSL_WHEN_POSSIBLE) { - /* If the server supports STARTTLS, use it */ - return connect_to_server (service, ssl_mode, TRUE, ex); + mode = ssl_options[i].mode; + serv = ssl_options[i].serv; } else { - /* User doesn't care about SSL */ - return connect_to_server (service, ssl_mode, FALSE, ex); + mode = MODE_CLEAR; + serv = "pop3"; } -#else - return connect_to_server (service, USE_SSL_NEVER, FALSE, ex); -#endif + + if (service->url->port) { + serv = g_alloca (16); + sprintf (serv, "%d", service->url->port); + } + + memset (&hints, 0, sizeof (hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_family = PF_UNSPEC; + if (!(ai = camel_getaddrinfo (service->url->host, serv, &hints, ex))) + return FALSE; + + ret = connect_to_server (service, ai, mode, ex); + + camel_freeaddrinfo (ai); + + return ret; } extern CamelServiceAuthType camel_pop3_password_authtype; |