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:
@@ -514,8 +514,8 @@ mm_bearer_properties_consume_string (MMBearerProperties *self,
|
|||||||
} else {
|
} else {
|
||||||
g_set_error (error,
|
g_set_error (error,
|
||||||
MM_CORE_ERROR,
|
MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_INVALID_ARGS,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"Invalid properties string, unexpected key '%s'",
|
"Invalid properties string, unsupported key '%s'",
|
||||||
key);
|
key);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@@ -490,20 +490,32 @@ key_value_foreach (const gchar *key,
|
|||||||
const gchar *value,
|
const gchar *value,
|
||||||
ParseKeyValueContext *ctx)
|
ParseKeyValueContext *ctx)
|
||||||
{
|
{
|
||||||
|
GError *inner_error = NULL;
|
||||||
|
|
||||||
/* First, check if we can consume this as bearer properties */
|
/* First, check if we can consume this as bearer properties */
|
||||||
if (mm_bearer_properties_consume_string (ctx->self->priv->bearer_properties,
|
if (mm_bearer_properties_consume_string (ctx->self->priv->bearer_properties,
|
||||||
key, value,
|
key, value,
|
||||||
NULL))
|
&inner_error))
|
||||||
return TRUE;
|
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))
|
if (g_str_equal (key, PROPERTY_PIN))
|
||||||
mm_simple_connect_properties_set_pin (ctx->self, value);
|
mm_simple_connect_properties_set_pin (ctx->self, value);
|
||||||
else if (g_str_equal (key, PROPERTY_OPERATOR_ID))
|
else if (g_str_equal (key, PROPERTY_OPERATOR_ID))
|
||||||
mm_simple_connect_properties_set_operator_id (ctx->self, value);
|
mm_simple_connect_properties_set_operator_id (ctx->self, value);
|
||||||
else {
|
else {
|
||||||
ctx->error = g_error_new (MM_CORE_ERROR,
|
ctx->error = g_error_new (MM_CORE_ERROR,
|
||||||
MM_CORE_ERROR_INVALID_ARGS,
|
MM_CORE_ERROR_UNSUPPORTED,
|
||||||
"Invalid properties string, unexpected key '%s'",
|
"Invalid properties string, unsupported key '%s'",
|
||||||
key);
|
key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user