mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-15 20:18:05 +02:00
Fix IPv6 parsing in _g_uri_parse_authority, add _g_uri_from_authority
Fixes connections to IPv6 address literals. https://bugzilla.gnome.org/show_bug.cgi?id=629259
This commit is contained in:
parent
f8cb2a60b9
commit
59383c8bea
@ -526,6 +526,8 @@ _g_uri_parse_authority (const char *uri,
|
|||||||
/* If IPv6 or IPvFuture */
|
/* If IPv6 or IPvFuture */
|
||||||
if (*p == '[')
|
if (*p == '[')
|
||||||
{
|
{
|
||||||
|
start++;
|
||||||
|
p++;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
c = *p++;
|
c = *p++;
|
||||||
@ -625,6 +627,46 @@ error:
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
_g_uri_from_authority (const gchar *protocol,
|
||||||
|
const gchar *host,
|
||||||
|
guint port,
|
||||||
|
const gchar *userinfo)
|
||||||
|
{
|
||||||
|
GString *uri;
|
||||||
|
|
||||||
|
uri = g_string_new (protocol);
|
||||||
|
g_string_append (uri, "://");
|
||||||
|
|
||||||
|
if (userinfo)
|
||||||
|
{
|
||||||
|
g_string_append_uri_escaped (uri, userinfo, G_URI_RESERVED_CHARS_ALLOWED_IN_USERINFO, FALSE);
|
||||||
|
g_string_append_c (uri, '@');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_hostname_is_non_ascii (host))
|
||||||
|
{
|
||||||
|
gchar *ace_encoded = g_hostname_to_ascii (host);
|
||||||
|
|
||||||
|
if (!ace_encoded)
|
||||||
|
{
|
||||||
|
g_string_free (uri, TRUE);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
g_string_append (uri, ace_encoded);
|
||||||
|
g_free (ace_encoded);
|
||||||
|
}
|
||||||
|
else if (strchr (host, ':'))
|
||||||
|
g_string_append_printf (uri, "[%s]", host);
|
||||||
|
else
|
||||||
|
g_string_append (uri, host);
|
||||||
|
|
||||||
|
if (port != 0)
|
||||||
|
g_string_append_printf (uri, ":%u", port);
|
||||||
|
|
||||||
|
return g_string_free (uri, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_network_address_parse_uri:
|
* g_network_address_parse_uri:
|
||||||
* @uri: the hostname and optionally a port
|
* @uri: the hostname and optionally a port
|
||||||
@ -920,9 +962,10 @@ g_network_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
|
|||||||
GSocketAddressEnumerator *proxy_enum;
|
GSocketAddressEnumerator *proxy_enum;
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
|
|
||||||
uri = g_strdup_printf ("%s://%s:%u",
|
uri = _g_uri_from_authority (self->priv->scheme ? self->priv->scheme : "none",
|
||||||
self->priv->scheme ? self->priv->scheme : "none",
|
self->priv->hostname,
|
||||||
self->priv->hostname, self->priv->port);
|
self->priv->port,
|
||||||
|
NULL);
|
||||||
|
|
||||||
proxy_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
|
proxy_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
|
||||||
"connectable", connectable,
|
"connectable", connectable,
|
||||||
|
@ -124,6 +124,10 @@ gboolean _g_uri_parse_authority (const char *uri,
|
|||||||
char **host,
|
char **host,
|
||||||
guint16 *port,
|
guint16 *port,
|
||||||
char **userinfo);
|
char **userinfo);
|
||||||
|
gchar * _g_uri_from_authority (const gchar *protocol,
|
||||||
|
const gchar *host,
|
||||||
|
guint port,
|
||||||
|
const gchar *userinfo);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "ginetsocketaddress.h"
|
#include "ginetsocketaddress.h"
|
||||||
#include "gioerror.h"
|
#include "gioerror.h"
|
||||||
#include "gnetworkaddress.h"
|
#include "gnetworkaddress.h"
|
||||||
|
#include "gnetworkingprivate.h"
|
||||||
#include "gresolver.h"
|
#include "gresolver.h"
|
||||||
#include "gsimpleasyncresult.h"
|
#include "gsimpleasyncresult.h"
|
||||||
#include "gsocketaddressenumerator.h"
|
#include "gsocketaddressenumerator.h"
|
||||||
@ -438,10 +439,10 @@ g_network_service_address_enumerator_next (GSocketAddressEnumerator *enumerator
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
uri = g_strdup_printf ("%s://%s:%u",
|
uri = _g_uri_from_authority (g_network_service_get_scheme (srv_enum->srv),
|
||||||
g_network_service_get_scheme (srv_enum->srv),
|
hostname,
|
||||||
hostname,
|
g_srv_target_get_port (target),
|
||||||
g_srv_target_get_port (target));
|
NULL);
|
||||||
g_free (hostname);
|
g_free (hostname);
|
||||||
|
|
||||||
addr = g_network_address_parse_uri (uri,
|
addr = g_network_address_parse_uri (uri,
|
||||||
|
@ -372,7 +372,7 @@ g_socket_address_connectable_proxy_enumerate (GSocketConnectable *connectable)
|
|||||||
g_object_get (connectable, "address", &addr, "port", &port, NULL);
|
g_object_get (connectable, "address", &addr, "port", &port, NULL);
|
||||||
|
|
||||||
ip = g_inet_address_to_string (addr);
|
ip = g_inet_address_to_string (addr);
|
||||||
uri = g_strdup_printf ("none://%s:%u", ip, port);
|
uri = _g_uri_from_authority ("none", ip, port, NULL);
|
||||||
|
|
||||||
addr_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
|
addr_enum = g_object_new (G_TYPE_PROXY_ADDRESS_ENUMERATOR,
|
||||||
"connectable", connectable,
|
"connectable", connectable,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user