Skip to content

Commit

Permalink
screen-cast: Move out helper checking variant dict key existance
Browse files Browse the repository at this point in the history
  • Loading branch information
jadahl committed Jul 11, 2023
1 parent 53cce9b commit cbce8c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
26 changes: 1 addition & 25 deletions src/screen-cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,6 @@ static XdpOptionKey screen_cast_select_sources_options[] = {
{ "persist_mode", G_VARIANT_TYPE_UINT32, validate_persist_mode },
};

static gboolean
variant_contains_key (GVariant *dictionary,
const char *key)
{
GVariantIter iter;

g_variant_iter_init (&iter, dictionary);
while (TRUE)
{
g_autoptr(GVariant) entry = NULL;
g_autoptr(GVariant) entry_key = NULL;

entry = g_variant_iter_next_value (&iter);
if (!entry)
break;

entry_key = g_variant_get_child_value (entry, 0);
if (g_strcmp0 (g_variant_get_string (entry_key, NULL), key) == 0)
return TRUE;
}

return FALSE;
}

static gboolean
replace_screen_cast_restore_token_with_data (Session *session,
GVariant **in_out_options,
Expand All @@ -475,7 +451,7 @@ replace_screen_cast_restore_token_with_data (Session *session,
if (is_remote_desktop_session (session))
{
if (persist_mode != PERSIST_MODE_NONE ||
variant_contains_key (options, "restore_token"))
xdp_variant_contains_key (options, "restore_token"))
{
g_set_error (error,
XDG_DESKTOP_PORTAL_ERROR,
Expand Down
24 changes: 24 additions & 0 deletions src/xdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2430,3 +2430,27 @@ xdp_validate_serialized_icon (GVariant *v,

return TRUE;
}

gboolean
xdp_variant_contains_key (GVariant *dictionary,
const char *key)
{
GVariantIter iter;

g_variant_iter_init (&iter, dictionary);
while (TRUE)
{
g_autoptr(GVariant) entry = NULL;
g_autoptr(GVariant) entry_key = NULL;

entry = g_variant_iter_next_value (&iter);
if (!entry)
break;

entry_key = g_variant_get_child_value (entry, 0);
if (g_strcmp0 (g_variant_get_string (entry_key, NULL), key) == 0)
return TRUE;
}

return FALSE;
}
2 changes: 2 additions & 0 deletions src/xdp-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ XdpAppInfo *xdp_invocation_lookup_app_info_sync (GDBusMethodInvocation *invocati
void xdp_connection_track_name_owners (GDBusConnection *connection,
XdpPeerDiedCallback peer_died_cb);

gboolean xdp_variant_contains_key (GVariant *dictionary,
const char *key);

typedef struct {
const char *key;
Expand Down

0 comments on commit cbce8c6

Please sign in to comment.