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:
Philip Withnall 2020-09-30 17:45:19 +01:00
parent aa6aa0de42
commit 58fce4b92b

View File

@ -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
parse_host (const gchar *start,
parse_ip_literal (const gchar *start,
gsize length,
GUriFlags flags,
gchar **out,
GError **error)
{
gchar *decoded, *host, *pct;
gchar *pct;
gchar *addr = NULL;
if (*start == '[')
{
if (start[length - 1] != ']')
{
bad_ipv6_literal:
@ -485,7 +496,28 @@ parse_host (const gchar *start,
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;
}