diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-08-14 15:36:44 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2018-09-12 17:14:36 +0000 |
commit | 6e84f3d45934e4f1e334c4bfd0d9a43d88889039 (patch) | |
tree | 31acc1e5dec441b3cda6fd35a4739bf5a942dff6 /src/mm-modem-helpers.c | |
parent | 47ed19d5be68f139d4fbb00c997cd2805488ace7 (diff) |
iface-modem-location: validate SUPL server address
Devices will expect SUPL server given as either IP:PORT or FQDN:PORT,
so just avoid saying we require a 'URL' because it's not true.
We will use a new helper method to parse and validate user-provided
SUPL server address.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index c2586712..f7ee0f62 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -4372,3 +4372,61 @@ out: g_assert (retries >= 0); return retries; } + +/*****************************************************************************/ + +gboolean +mm_parse_supl_address (const gchar *supl, + gchar **out_fqdn, + guint32 *out_ip, + guint16 *out_port, + GError **error) +{ + gboolean valid = FALSE; + gchar **split; + guint port; + guint32 ip; + + split = g_strsplit (supl, ":", -1); + if (g_strv_length (split) != 2) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Invalid SUPL address format: expected FQDN:PORT or IP:PORT"); + goto out; + } + + if (!mm_get_uint_from_str (split[1], &port)) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Invalid SUPL port number specified: not a number: %s", split[1]); + goto out; + } + + if (port == 0 || port > G_MAXUINT16) { + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS, + "Invalid SUPL port number specified: out of range: %u", port); + goto out; + } + + /* Port is valid */ + if (out_port) + *out_port = (guint16) port; + + /* Try to parse first item as IP */ + if (inet_pton (AF_INET, split[0], &ip) <= 0) { + /* Otherwise, assume it's a domain name */ + if (out_fqdn) + *out_fqdn = g_strdup (split[0]); + if (out_ip) + *out_ip = 0; + } else { + if (out_ip) + *out_ip = ip; + if (out_fqdn) + *out_fqdn = NULL; + } + + valid = TRUE; + +out: + g_strfreev (split); + return valid; +} |