From fbea2b4159580c5f9225b84be00d1330b3f01088 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Tue, 9 Jul 2013 10:19:14 +0300 Subject: [PATCH] http: add support TCP transport Required for the new EWS autodiscover http://Autodiscover ... URL. --- src/core/sipe-http-request.c | 3 ++- src/core/sipe-http-request.h | 1 + src/core/sipe-http-transport.c | 10 +++++++--- src/core/sipe-http-transport.h | 4 +++- src/core/sipe-http.c | 24 +++++++++++++++++++----- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/core/sipe-http-request.c b/src/core/sipe-http-request.c index 0df05927..be7ee35a 100644 --- a/src/core/sipe-http-request.c +++ b/src/core/sipe-http-request.c @@ -153,7 +153,8 @@ static void sipe_http_request_enqueue(struct sipe_core_private *sipe_private, req->path = g_strdup(parsed_uri->path); req->connection = conn_public = sipe_http_transport_new(sipe_private, parsed_uri->host, - parsed_uri->port); + parsed_uri->port, + parsed_uri->tls); if (!sipe_http_request_pending(conn_public)) req->flags |= SIPE_HTTP_REQUEST_FLAG_FIRST; diff --git a/src/core/sipe-http-request.h b/src/core/sipe-http-request.h index 9af42d70..435a7ccf 100644 --- a/src/core/sipe-http-request.h +++ b/src/core/sipe-http-request.h @@ -42,6 +42,7 @@ struct sipe_http_parsed_uri { gchar *host; gchar *path; guint port; + gboolean tls; }; /** diff --git a/src/core/sipe-http-transport.c b/src/core/sipe-http-transport.c index d08d4979..87fee7d1 100644 --- a/src/core/sipe-http-transport.c +++ b/src/core/sipe-http-transport.c @@ -61,6 +61,7 @@ struct sipe_http_connection { gchar *host_port; time_t timeout; /* in seconds from epoch */ + gboolean use_tls; }; struct sipe_http { @@ -399,7 +400,8 @@ static void sipe_http_transport_input(struct sipe_transport_connection *connecti if (next) sipe_http_transport_new(conn->public.sipe_private, conn->public.host, - conn->public.port); + conn->public.port, + conn->use_tls); } else if (next) { /* trigger sending of next pending request */ @@ -422,7 +424,8 @@ static void sipe_http_transport_error(struct sipe_transport_connection *connecti struct sipe_http_connection_public *sipe_http_transport_new(struct sipe_core_private *sipe_private, const gchar *host_in, - const guint32 port) + const guint32 port, + gboolean use_tls) { struct sipe_http *http; struct sipe_http_connection *conn = NULL; @@ -459,6 +462,7 @@ struct sipe_http_connection_public *sipe_http_transport_new(struct sipe_core_pri conn->public.port = port; conn->host_port = host_port; + conn->use_tls = use_tls; g_hash_table_insert(http->connections, host_port, @@ -468,7 +472,7 @@ struct sipe_http_connection_public *sipe_http_transport_new(struct sipe_core_pri if (!conn->connection) { sipe_connect_setup setup = { - SIPE_TRANSPORT_TLS, /* TBD: we only support TLS for now */ + use_tls ? SIPE_TRANSPORT_TLS : SIPE_TRANSPORT_TCP, host, port, conn, diff --git a/src/core/sipe-http-transport.h b/src/core/sipe-http-transport.h index fd0bfcf8..06b5a814 100644 --- a/src/core/sipe-http-transport.h +++ b/src/core/sipe-http-transport.h @@ -64,12 +64,14 @@ gboolean sipe_http_shutting_down(struct sipe_core_private *sipe_private); * @param sipe_private SIPE core private data * @param host name of the host to connect to * @param port port number to connect to + * @param use_tls use TLS if @c TRUE, otherwise TCP * * @return HTTP connection public data */ struct sipe_http_connection_public *sipe_http_transport_new(struct sipe_core_private *sipe_private, const gchar *host, - guint32 port); + guint32 port, + gboolean use_tls); /** * Send HTTP request diff --git a/src/core/sipe-http.c b/src/core/sipe-http.c index 16913db6..cf697544 100644 --- a/src/core/sipe-http.c +++ b/src/core/sipe-http.c @@ -48,12 +48,20 @@ void sipe_http_parsed_uri_free(struct sipe_http_parsed_uri *parsed_uri) struct sipe_http_parsed_uri *sipe_http_parse_uri(const gchar *uri) { struct sipe_http_parsed_uri *parsed_uri = NULL; + guint offset = 0; + gboolean tls = FALSE; // SIPE_DEBUG_INFO("sipe_http_parse_uri: '%s'", uri); - /* Currently only HTTPS is supported */ if (g_str_has_prefix(uri, "https://")) { - gchar **hostport_path = g_strsplit(uri + 8, "/", 2); + offset = 8; + tls = TRUE; + } else if (g_str_has_prefix(uri, "http://")) { + offset = 7; + } + + if (offset) { + gchar **hostport_path = g_strsplit(uri + offset, "/", 2); if (hostport_path && hostport_path[0] && hostport_path[1]) { gchar **host_port = g_strsplit(hostport_path[0], ":", 2); @@ -66,14 +74,20 @@ struct sipe_http_parsed_uri *sipe_http_parse_uri(const gchar *uri) parsed_uri = g_new0(struct sipe_http_parsed_uri, 1); parsed_uri->host = g_strdup(host_port[0]); parsed_uri->path = g_strdup(hostport_path[1]); + parsed_uri->tls = tls; if (host_port[1]) parsed_uri->port = g_ascii_strtoull(host_port[1], NULL, 10); - if (parsed_uri->port == 0) - /* default port for https */ - parsed_uri->port = 443; + if (parsed_uri->port == 0) { + if (tls) + /* default port for https */ + parsed_uri->port = 443; + else + /* default port for http */ + parsed_uri->port = 80; + } SIPE_DEBUG_INFO("sipe_http_parse_uri: host '%s' port %d path '%s'", parsed_uri->host, parsed_uri->port, parsed_uri->path); -- 2.11.4.GIT