[libsoup] soup-address: fix proxy enumerator implementation



commit 8c5ae3c24c95381b52530ac76a80598bb750c1ef
Author: Dan Winship <danw gnome org>
Date:   Thu Apr 18 10:30:32 2013 -0400

    soup-address: fix proxy enumerator implementation
    
    When creating a GProxyAddressEnumerator, the destination URI passed to
    it must include the port number, or the proxy may end up trying to
    connect to port 0. libsoup was omitting the port number when it was
    the default for the protocol.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=698163

 libsoup/soup-address.c      |  3 ++-
 libsoup/soup-misc-private.h |  2 ++
 libsoup/soup-uri.c          | 39 +++++++++++++++++++++++----------------
 3 files changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/libsoup/soup-address.c b/libsoup/soup-address.c
index e1696fb..286be8c 100644
--- a/libsoup/soup-address.c
+++ b/libsoup/soup-address.c
@@ -14,6 +14,7 @@
 #include "soup-address.h"
 #include "soup.h"
 #include "soup-marshal.h"
+#include "soup-misc-private.h"
 
 /**
  * SECTION:soup-address
@@ -1209,7 +1210,7 @@ soup_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
        soup_uri_set_host (uri, priv->name ? priv->name : soup_address_get_physical (addr));
        soup_uri_set_port (uri, priv->port);
        soup_uri_set_path (uri, "");
-       uri_string = soup_uri_to_string (uri, FALSE);
+       uri_string = soup_uri_to_string_internal (uri, FALSE, TRUE);
 
        proxy_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
                                   "connectable", connectable,
diff --git a/libsoup/soup-misc-private.h b/libsoup/soup-misc-private.h
index cd83618..d03bc77 100644
--- a/libsoup/soup-misc-private.h
+++ b/libsoup/soup-misc-private.h
@@ -10,6 +10,8 @@
 #include "soup-socket.h"
 
 char *uri_decoded_copy (const char *str, int length, int *decoded_length);
+char *soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
+                                  gboolean force_port);
 
 guint soup_socket_handshake_sync  (SoupSocket         *sock,
                                   GCancellable       *cancellable);
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 723e361..26ec24a 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -489,21 +489,9 @@ soup_uri_new (const char *uri_string)
 }
 
 
-/**
- * soup_uri_to_string:
- * @uri: a #SoupURI
- * @just_path_and_query: if %TRUE, output just the path and query portions
- *
- * Returns a string representing @uri.
- *
- * If @just_path_and_query is %TRUE, this concatenates the path and query
- * together. That is, it constructs the string that would be needed in
- * the Request-Line of an HTTP request for @uri.
- *
- * Return value: a string representing @uri, which the caller must free.
- **/
 char *
-soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
+soup_uri_to_string_internal (SoupURI *uri, gboolean just_path_and_query,
+                            gboolean force_port)
 {
        GString *str;
        char *return_result;
@@ -511,7 +499,7 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
        g_return_val_if_fail (uri != NULL, NULL);
        g_warn_if_fail (SOUP_URI_IS_VALID (uri));
 
-       str = g_string_sized_new (20);
+       str = g_string_sized_new (40);
 
        if (uri->scheme && !just_path_and_query)
                g_string_append_printf (str, "%s:", uri->scheme);
@@ -527,7 +515,7 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
                        g_string_append_c (str, ']');
                } else
                        append_uri_encoded (str, uri->host, ":/");
-               if (uri->port && uri->port != soup_scheme_default_port (uri->scheme))
+               if (uri->port && (force_port || uri->port != soup_scheme_default_port (uri->scheme)))
                        g_string_append_printf (str, ":%u", uri->port);
                if (!uri->path && (uri->query || uri->fragment))
                        g_string_append_c (str, '/');
@@ -558,6 +546,25 @@ soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
 }
 
 /**
+ * soup_uri_to_string:
+ * @uri: a #SoupURI
+ * @just_path_and_query: if %TRUE, output just the path and query portions
+ *
+ * Returns a string representing @uri.
+ *
+ * If @just_path_and_query is %TRUE, this concatenates the path and query
+ * together. That is, it constructs the string that would be needed in
+ * the Request-Line of an HTTP request for @uri.
+ *
+ * Return value: a string representing @uri, which the caller must free.
+ **/
+char *
+soup_uri_to_string (SoupURI *uri, gboolean just_path_and_query)
+{
+       return soup_uri_to_string_internal (uri, just_path_and_query, FALSE);
+}
+
+/**
  * soup_uri_copy:
  * @uri: a #SoupURI
  *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]