enum connection_type connection_type_from_properties(GVariant *properties) { enum connection_type type = CONNECTION_TYPE_UNKNOWN; GVariantDict *dict = g_variant_dict_new(properties); GVariant *type_v = g_variant_dict_lookup_value(dict, "Type", NULL); if(type_v) { const gchar *type_s; type_s = g_variant_get_string(type_v, NULL); type = connection_type_from_string(type_s); g_variant_unref(type_v); } g_variant_dict_unref(dict); return type; }
static void parse_configuration (Setting *setting) { GVariantDict *dict = NULL; GVariant *value = NULL; LoomSetting *loom_setting = LOOM_SETTING (setting); dict = g_variant_dict_new (setting->configuration); value = g_variant_dict_lookup_value (dict, "address", G_VARIANT_TYPE_STRING); loom_setting_set_address (loom_setting, g_variant_get_string (value, NULL)); if (g_variant_dict_contains (dict, "router")) { value = g_variant_dict_lookup_value (dict, "router", G_VARIANT_TYPE_STRING); loom_setting_set_router (loom_setting, g_variant_get_string (value, NULL)); } if (g_variant_dict_contains (dict, "nameservers")) { value = g_variant_dict_lookup_value (dict, "nameservers", G_VARIANT_TYPE_STRING_ARRAY); gchar **strv = g_variant_dup_strv (value, NULL); loom_setting_set_name_servers (loom_setting, (const gchar **)strv); g_strfreev (strv); } if (g_variant_dict_contains (dict, "domain")) { value = g_variant_dict_lookup_value (dict, "domains", G_VARIANT_TYPE_STRING); loom_setting_set_domain (loom_setting, g_variant_get_string (value, NULL)); } if (g_variant_dict_contains (dict, "searches")) { value = g_variant_dict_lookup_value (dict, "searches", G_VARIANT_TYPE_STRING_ARRAY); gchar **strv = g_variant_dup_strv (value, NULL); loom_setting_set_searches (loom_setting, (const gchar **)strv); g_strfreev (strv); } g_variant_dict_unref (dict); }
static gboolean validate_configuration (GVariant *configuration, GError **error) { GVariantDict *dict = NULL; GVariant *value = NULL; dict = g_variant_dict_new (configuration); if (g_variant_dict_contains (dict, "address")) { value = g_variant_dict_lookup_value (dict, "address", G_VARIANT_TYPE_STRING); if (value == NULL) { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'address' entry must be a string")); return FALSE; } if (!validate_address ("address", g_variant_get_string (value, NULL), TRUE, error)) { g_variant_dict_unref (dict); return FALSE; } } else { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'address' entry is required")); return FALSE; } if (g_variant_dict_contains (dict, "router")) { value = g_variant_dict_lookup_value (dict, "router", G_VARIANT_TYPE_STRING); if (value == NULL) { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'router' entry must be a string")); return FALSE; } if (!validate_address ("router", g_variant_get_string (value, NULL), FALSE, error)) { g_variant_dict_unref (dict); return FALSE; } } if (g_variant_dict_contains (dict, "nameservers")) { value = g_variant_dict_lookup_value (dict, "nameservers", G_VARIANT_TYPE_STRING_ARRAY); if (value == NULL) { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'nameservers' entry must be a string array")); return FALSE; } gsize len; gs_strfreev gchar **nameservers = g_variant_dup_strv (value, &len); for (gsize i = 0; i < len; i++) { if (!validate_address ("nameservers", nameservers[i], FALSE, error)) { g_variant_dict_unref (dict); return FALSE; } } } if (g_variant_dict_contains (dict, "domain")) { value = g_variant_dict_lookup_value (dict, "domain", G_VARIANT_TYPE_STRING); if (value == NULL) { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'domain' entry must be a string")); return FALSE; } if (!validate_domainname ("domain", g_variant_get_string (value, NULL), error)) { g_variant_dict_unref (dict); return FALSE; } } if (g_variant_dict_contains (dict, "searches")) { value = g_variant_dict_lookup_value (dict, "searches", G_VARIANT_TYPE_STRING_ARRAY); if (value == NULL) { g_variant_dict_unref (dict); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'searches' entry must be a string array")); return FALSE; } gsize len; gs_strfreev gchar **searches = g_variant_dup_strv (value, &len); for (gsize i = 0; i < len; i++) { if (!validate_domainname ("searches", searches[i], error)) { g_variant_dict_unref (dict); return FALSE; } } } g_variant_dict_unref (dict); return TRUE; }