[evolution-data-server/camel-socks-proxy] Change CamelNNTPStore to use the new API
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/camel-socks-proxy] Change CamelNNTPStore to use the new API
- Date: Mon, 12 Jul 2010 21:09:03 +0000 (UTC)
commit 24d74eb76d74486bb31bcaa584cd11b6f08f11df
Author: Federico Mena Quintero <federico novell com>
Date: Mon Jul 12 15:49:40 2010 -0500
Change CamelNNTPStore to use the new API
Signed-off-by: Federico Mena Quintero <federico novell com>
camel/providers/nntp/camel-nntp-store.c | 60 +++++++++++++------------------
1 files changed, 25 insertions(+), 35 deletions(-)
---
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index e86ac5d..109ad7d 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -57,8 +57,8 @@
#define w(x)
#define dd(x) (camel_debug("nntp")?(x):0)
-#define NNTP_PORT "119"
-#define NNTPS_PORT "563"
+#define NNTP_PORT 119
+#define NNTPS_PORT 563
#define DUMP_EXTENSIONS
@@ -158,7 +158,7 @@ enum {
#endif
static gboolean
-connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, CamelException *ex)
+connect_to_server (CamelService *service, const char *host, const char *serv, gint fallback_port, gint ssl_mode, CamelException *ex)
{
CamelNNTPStore *store = (CamelNNTPStore *) service;
CamelDiscoStore *disco_store = (CamelDiscoStore*) service;
@@ -199,15 +199,21 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
g_free (socks_host);
}
- if (camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, ai) == -1) {
- if (errno == EINTR)
- camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
- _("Connection canceled"));
- else
- camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
- _("Could not connect to %s: %s"),
- service->url->host,
- g_strerror (errno));
+ if (camel_tcp_stream_connect ((CamelTcpStream *) tcp_stream, host, serv, fallback_port, ex) == -1) {
+ gint saved_errno;
+
+ saved_errno = errno;
+
+ if (!camel_exception_is_set (ex)) {
+ if (saved_errno == EINTR)
+ camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
+ _("Connection canceled"));
+ else
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+ _("Could not connect to %s: %s"),
+ host,
+ g_strerror (saved_errno));
+ }
camel_object_unref (tcp_stream);
@@ -278,7 +284,7 @@ connect_to_server (CamelService *service, struct addrinfo *ai, gint ssl_mode, Ca
static struct {
const gchar *value;
const gchar *serv;
- const gchar *port;
+ gint fallback_port;
gint mode;
} ssl_options[] = {
{ "", "nntps", NNTPS_PORT, MODE_SSL }, /* really old (1.x) */
@@ -291,11 +297,10 @@ static struct {
static gboolean
nntp_connect_online (CamelService *service, CamelException *ex)
{
- struct addrinfo hints, *ai;
const gchar *ssl_mode;
- gint mode, ret, i;
+ gint mode, i;
gchar *serv;
- const gchar *port;
+ gint fallback_port;
if ((ssl_mode = camel_url_get_param (service->url, "use_ssl"))) {
for (i = 0; ssl_options[i].value; i++)
@@ -303,35 +308,20 @@ nntp_connect_online (CamelService *service, CamelException *ex)
break;
mode = ssl_options[i].mode;
serv = (gchar *) ssl_options[i].serv;
- port = ssl_options[i].port;
+ fallback_port = ssl_options[i].fallback_port;
} else {
mode = MODE_CLEAR;
serv = (gchar *) "nntp";
- port = NNTP_PORT;
+ fallback_port = NNTP_PORT;
}
if (service->url->port) {
serv = g_alloca (16);
sprintf (serv, "%d", service->url->port);
- port = NULL;
- }
-
- memset (&hints, 0, sizeof (hints));
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_family = PF_UNSPEC;
- ai = camel_getaddrinfo(service->url->host, serv, &hints, ex);
- if (ai == NULL && port != NULL && camel_exception_get_id(ex) != CAMEL_EXCEPTION_USER_CANCEL) {
- camel_exception_clear (ex);
- ai = camel_getaddrinfo(service->url->host, port, &hints, ex);
+ fallback_port = 0;
}
- if (ai == NULL)
- return FALSE;
- ret = connect_to_server (service, ai, mode, ex);
-
- camel_freeaddrinfo (ai);
-
- return ret;
+ return connect_to_server (service, service->url->host, serv, fallback_port, mode, ex);
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]