mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-22 15:19:16 +02:00
gio: remove _g_uri_parse_authority()
It is now unused and redundant with GUri. Fixes: #2156 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
aa0b09ebef
commit
dd0fae1303
@ -518,252 +518,6 @@ g_network_address_parse (const gchar *host_and_port,
|
|||||||
return connectable;
|
return connectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allowed characters outside alphanumeric for unreserved. */
|
|
||||||
#define G_URI_OTHER_UNRESERVED "-._~"
|
|
||||||
|
|
||||||
/* This or something equivalent will eventually go into glib/guri.h */
|
|
||||||
gboolean
|
|
||||||
_g_uri_parse_authority (const char *uri,
|
|
||||||
char **host,
|
|
||||||
guint16 *port,
|
|
||||||
char **userinfo,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
char *ascii_uri, *tmp_str;
|
|
||||||
const char *start, *p, *at, *delim;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
g_return_val_if_fail (uri != NULL, FALSE);
|
|
||||||
|
|
||||||
if (host)
|
|
||||||
*host = NULL;
|
|
||||||
|
|
||||||
if (port)
|
|
||||||
*port = 0;
|
|
||||||
|
|
||||||
if (userinfo)
|
|
||||||
*userinfo = NULL;
|
|
||||||
|
|
||||||
/* Catch broken URIs early by trying to convert to ASCII. */
|
|
||||||
ascii_uri = g_hostname_to_ascii (uri);
|
|
||||||
if (!ascii_uri)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
/* From RFC 3986 Decodes:
|
|
||||||
* URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
|
|
||||||
* hier-part = "//" authority path-abempty
|
|
||||||
* path-abempty = *( "/" segment )
|
|
||||||
* authority = [ userinfo "@" ] host [ ":" port ]
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Check we have a valid scheme */
|
|
||||||
tmp_str = g_uri_parse_scheme (ascii_uri);
|
|
||||||
|
|
||||||
if (tmp_str == NULL)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
g_free (tmp_str);
|
|
||||||
|
|
||||||
/* Decode hier-part:
|
|
||||||
* hier-part = "//" authority path-abempty
|
|
||||||
*/
|
|
||||||
p = ascii_uri;
|
|
||||||
start = strstr (p, "//");
|
|
||||||
|
|
||||||
if (start == NULL)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
start += 2;
|
|
||||||
|
|
||||||
/* check if the @ sign is part of the authority before attempting to
|
|
||||||
* decode the userinfo */
|
|
||||||
delim = strpbrk (start, "/?#[]");
|
|
||||||
at = strchr (start, '@');
|
|
||||||
if (at && delim && at > delim)
|
|
||||||
at = NULL;
|
|
||||||
|
|
||||||
if (at != NULL)
|
|
||||||
{
|
|
||||||
/* Decode userinfo:
|
|
||||||
* userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
|
|
||||||
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
||||||
* pct-encoded = "%" HEXDIG HEXDIG
|
|
||||||
*/
|
|
||||||
p = start;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *p++;
|
|
||||||
|
|
||||||
if (c == '@')
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* pct-encoded */
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
if (!(g_ascii_isxdigit (p[0]) ||
|
|
||||||
g_ascii_isxdigit (p[1])))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
p++;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unreserved / sub-delims / : */
|
|
||||||
if (!(g_ascii_isalnum (c) ||
|
|
||||||
strchr (G_URI_OTHER_UNRESERVED, c) ||
|
|
||||||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
|
|
||||||
c == ':'))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userinfo)
|
|
||||||
*userinfo = g_strndup (start, p - start - 1);
|
|
||||||
|
|
||||||
start = p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
p = start;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* decode host:
|
|
||||||
* host = IP-literal / IPv4address / reg-name
|
|
||||||
* reg-name = *( unreserved / pct-encoded / sub-delims )
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* If IPv6 or IPvFuture */
|
|
||||||
if (*p == '[')
|
|
||||||
{
|
|
||||||
gboolean has_scope_id = FALSE, has_bad_scope_id = FALSE;
|
|
||||||
|
|
||||||
start++;
|
|
||||||
p++;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *p++;
|
|
||||||
|
|
||||||
if (c == ']')
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (c == '%' && !has_scope_id)
|
|
||||||
{
|
|
||||||
has_scope_id = TRUE;
|
|
||||||
if (p[0] != '2' || p[1] != '5')
|
|
||||||
has_bad_scope_id = TRUE;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unreserved / sub-delims */
|
|
||||||
if (!(g_ascii_isalnum (c) ||
|
|
||||||
strchr (G_URI_OTHER_UNRESERVED, c) ||
|
|
||||||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
|
|
||||||
c == ':' ||
|
|
||||||
c == '.'))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host)
|
|
||||||
{
|
|
||||||
if (has_bad_scope_id)
|
|
||||||
*host = g_strndup (start, p - start - 1);
|
|
||||||
else
|
|
||||||
*host = g_uri_unescape_segment (start, p - 1, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
c = *p++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *p++;
|
|
||||||
|
|
||||||
if (c == ':' ||
|
|
||||||
c == '/' ||
|
|
||||||
c == '?' ||
|
|
||||||
c == '#' ||
|
|
||||||
c == '\0')
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* pct-encoded */
|
|
||||||
if (c == '%')
|
|
||||||
{
|
|
||||||
if (!(g_ascii_isxdigit (p[0]) ||
|
|
||||||
g_ascii_isxdigit (p[1])))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
p++;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unreserved / sub-delims */
|
|
||||||
if (!(g_ascii_isalnum (c) ||
|
|
||||||
strchr (G_URI_OTHER_UNRESERVED, c) ||
|
|
||||||
strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c)))
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host)
|
|
||||||
*host = g_uri_unescape_segment (start, p - 1, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == ':')
|
|
||||||
{
|
|
||||||
/* Decode port:
|
|
||||||
* port = *DIGIT
|
|
||||||
*/
|
|
||||||
guint tmp = 0;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
c = *p++;
|
|
||||||
|
|
||||||
if (c == '/' ||
|
|
||||||
c == '?' ||
|
|
||||||
c == '#' ||
|
|
||||||
c == '\0')
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (!g_ascii_isdigit (c))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
tmp = (tmp * 10) + (c - '0');
|
|
||||||
|
|
||||||
if (tmp > 65535)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (port)
|
|
||||||
*port = (guint16) tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (ascii_uri);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
error:
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
|
|
||||||
"Invalid URI ‘%s’", uri);
|
|
||||||
|
|
||||||
if (host && *host)
|
|
||||||
{
|
|
||||||
g_free (*host);
|
|
||||||
*host = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userinfo && *userinfo)
|
|
||||||
{
|
|
||||||
g_free (*userinfo);
|
|
||||||
*userinfo = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (ascii_uri);
|
|
||||||
|
|
||||||
return 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
|
||||||
|
@ -23,12 +23,6 @@
|
|||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
gboolean _g_uri_parse_authority (const char *uri,
|
|
||||||
char **host,
|
|
||||||
guint16 *port,
|
|
||||||
char **userinfo,
|
|
||||||
GError **error);
|
|
||||||
|
|
||||||
guint64 g_resolver_get_serial (GResolver *resolver);
|
guint64 g_resolver_get_serial (GResolver *resolver);
|
||||||
|
|
||||||
gint g_socket (gint domain,
|
gint g_socket (gint domain,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user