mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-02 13:53:06 +02:00
guri: Move IP-literal parsing out into a separate function
This introduces no functional changes, but will make future changes to the code a little cleaner. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
aa6aa0de42
commit
58fce4b92b
42
glib/guri.c
42
glib/guri.c
@ -442,18 +442,29 @@ _uri_encoder (GString *out,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse the IP-literal construction from RFC 6874 (which extends RFC 3986 to
|
||||||
|
* support IPv6 zone identifiers.
|
||||||
|
*
|
||||||
|
* Rules:
|
||||||
|
*
|
||||||
|
* IP-literal = "[" ( IPv6address / IPvFuture ) "]"
|
||||||
|
*
|
||||||
|
* IP-literal = "[" ( IPv6address / IPv6addrz / IPvFuture ) "]"
|
||||||
|
*
|
||||||
|
* ZoneID = 1*( unreserved / pct-encoded )
|
||||||
|
*
|
||||||
|
* IPv6addrz = IPv6address "%25" ZoneID
|
||||||
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_host (const gchar *start,
|
parse_ip_literal (const gchar *start,
|
||||||
gsize length,
|
gsize length,
|
||||||
GUriFlags flags,
|
GUriFlags flags,
|
||||||
gchar **out,
|
gchar **out,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar *decoded, *host, *pct;
|
gchar *pct;
|
||||||
gchar *addr = NULL;
|
gchar *addr = NULL;
|
||||||
|
|
||||||
if (*start == '[')
|
|
||||||
{
|
|
||||||
if (start[length - 1] != ']')
|
if (start[length - 1] != ']')
|
||||||
{
|
{
|
||||||
bad_ipv6_literal:
|
bad_ipv6_literal:
|
||||||
@ -485,7 +496,28 @@ parse_host (const gchar *start,
|
|||||||
memmove (pct + 1, pct + 3, strlen (pct + 3) + 1);
|
memmove (pct + 1, pct + 3, strlen (pct + 3) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
host = addr;
|
/* Success */
|
||||||
|
if (out != NULL)
|
||||||
|
*out = g_steal_pointer (&addr);
|
||||||
|
g_free (addr);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
parse_host (const gchar *start,
|
||||||
|
gsize length,
|
||||||
|
GUriFlags flags,
|
||||||
|
gchar **out,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
gchar *decoded, *host;
|
||||||
|
gchar *addr = NULL;
|
||||||
|
|
||||||
|
if (*start == '[')
|
||||||
|
{
|
||||||
|
if (!parse_ip_literal (start, length, flags, &host, error))
|
||||||
|
return FALSE;
|
||||||
goto ok;
|
goto ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user