libmm-glib,simple-connect-properties: cleaner error handling

If processing a key-value pair as a bearer property fails, we need to
know if it failed due to the key being unknown or due to some other
reason (e.g. failure parsing value of a known key).

We'll only try with the Simple.Connect properties if the key is
reported as unknown in the bearer properties.

This will help us better identify errors if e.g. an invalid value is
given to a known key. E.g. "yes" was invalid for allow-roaming here:

    daemon.notice netifd: wan (30476): simple connect=apn=internet,ip-type=ipv4,allow-roaming=yes
    daemon.notice netifd: wan (30476): Error parsing connect string: 'Invalid properties string, unexpected key 'allow-roaming''
This commit is contained in:
Aleksander Morgado
2020-01-06 14:46:36 +01:00
parent 15e8a78a15
commit baa68f5a4a
2 changed files with 17 additions and 5 deletions

View File

@@ -514,8 +514,8 @@ mm_bearer_properties_consume_string (MMBearerProperties *self,
} else {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid properties string, unexpected key '%s'",
MM_CORE_ERROR_UNSUPPORTED,
"Invalid properties string, unsupported key '%s'",
key);
return FALSE;
}

View File

@@ -490,20 +490,32 @@ key_value_foreach (const gchar *key,
const gchar *value,
ParseKeyValueContext *ctx)
{
GError *inner_error = NULL;
/* First, check if we can consume this as bearer properties */
if (mm_bearer_properties_consume_string (ctx->self->priv->bearer_properties,
key, value,
NULL))
&inner_error))
return TRUE;
/* Unknown keys are reported as unsupported. Any other error is right away
* fatal (e.g. an invalid value given to a known bearer property) */
if (!g_error_matches (inner_error, MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED)) {
ctx->error = inner_error;
return FALSE;
}
/* On unsupported errors, try with the Simple.Connect specific properties */
g_clear_error (&inner_error);
if (g_str_equal (key, PROPERTY_PIN))
mm_simple_connect_properties_set_pin (ctx->self, value);
else if (g_str_equal (key, PROPERTY_OPERATOR_ID))
mm_simple_connect_properties_set_operator_id (ctx->self, value);
else {
ctx->error = g_error_new (MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid properties string, unexpected key '%s'",
MM_CORE_ERROR_UNSUPPORTED,
"Invalid properties string, unsupported key '%s'",
key);
}