<commit_before>#include <config.h>

#include "openuri.h"

#include <libportal/portal.h>
#include "src/xdp-utils.h"
#include "src/xdp-impl-dbus.h"

extern XdpImplLockdown *lockdown;
extern XdpImplPermissionStore *permission_store;

extern char outdir[];

static int got_info = 0;

static void
set_openuri_permissions (const char *type,
                         const char *handler,
                         guint count,
                         guint threshold)
{
  g_autoptr(GError) error = NULL;
  g_autofree char *count_s = g_strdup_printf ("%u", count);
  g_autofree char *threshold_s = g_strdup_printf ("%u", threshold);
  const char *permissions[4];

  permissions[0] = handler;
  permissions[1] = count_s;
  permissions[2] = threshold_s;
  permissions[3] = NULL;

  xdp_impl_permission_store_call_set_permission_sync (permission_store,
                                                      "desktop-used-apps",
                                                      TRUE,
                                                      type,
                                                      "",
                                                      permissions,
                                                      NULL,
                                                      &error);
  g_assert_no_error (error);
}

static void
unset_openuri_permissions (const char *type)
{
  xdp_impl_permission_store_call_delete_sync (permission_store,
                                              "desktop-used-apps",
                                              type,
                                              NULL,
                                              NULL);
  /* Ignore the error here, since this fails if the table doesn't exist */
}

static void
open_uri_cb (GObject *obj,
             GAsyncResult *result,
             gpointer data)
{
  XdpPortal *portal = XDP_PORTAL (obj);
  g_autoptr(GError) error = NULL;
  GKeyFile *keyfile = data;
  gboolean ret;
  int response;
  int domain;
  int code;

  response = g_key_file_get_integer (keyfile, "result", "response", NULL);
  domain = g_key_file_get_integer (keyfile, "result", "error_domain", NULL);
  code = g_key_file_get_integer (keyfile, "result", "error_code", NULL);

  ret = xdp_portal_open_uri_finish (portal, result, &error);
  if (response == 0)<commit_msg>Adapt tests<commit_after>#include <config.h>

#include "openuri.h"

#include <libportal/portal.h>
#include "src/xdp-utils.h"
#include "src/xdp-impl-dbus.h"

extern XdpImplLockdown *lockdown;
extern XdpImplPermissionStore *permission_store;

extern char outdir[];

static int got_info = 0;

static void
set_openuri_permissions (const char *type,
                         const char *handler,
                         guint count,
                         guint threshold)
{
  g_autoptr(GError) error = NULL;
  g_autofree char *count_s = g_strdup_printf ("%u", count);
  g_autofree char *threshold_s = g_strdup_printf ("%u", threshold);
  const char *permissions[4];

  permissions[0] = handler;
  permissions[1] = count_s;
  permissions[2] = threshold_s;
  permissions[3] = NULL;

  xdp_impl_permission_store_call_set_permission_sync (permission_store,
                                                      "desktop-used-apps",
                                                      TRUE,
                                                      type,
                                                      "",
                                                      permissions,
                                                      NULL,
                                                      &error);
  g_assert_no_error (error);
}

static void
unset_openuri_permissions (const char *type)
{
  GVariantBuilder data_builder;

  xdp_impl_permission_store_call_delete_sync (permission_store,
                                              "desktop-used-apps",
                                              type,
                                              NULL,
                                              NULL);

  /* turn on paranoid mode to ensure we get a backend call */
  g_variant_builder_init (&data_builder, G_VARIANT_TYPE_VARDICT);
  g_variant_builder_add (&data_builder, "{sv}", "always-ask", g_variant_new_boolean (TRUE));
  xdp_impl_permission_store_call_set_value_sync (permission_store,
                                                 "desktop-used-apps",
                                                 TRUE,
                                                 type,
                                                 g_variant_new_variant (g_variant_builder_end (&data_builder)),
                                                 NULL,
                                                 NULL);
  /* Ignore the error here, since this fails if the table doesn't exist */
}

static void
open_uri_cb (GObject *obj,
             GAsyncResult *result,
             gpointer data)
{
  XdpPortal *portal = XDP_PORTAL (obj);
  g_autoptr(GError) error = NULL;
  GKeyFile *keyfile = data;
  gboolean ret;
  int response;
  int domain;
  int code;

  response = g_key_file_get_integer (keyfile, "result", "response", NULL);
  domain = g_key_file_get_integer (keyfile, "result", "error_domain", NULL);
  code = g_key_file_get_integer (keyfile, "result", "error_code", NULL);

  ret = xdp_portal_open_uri_finish (portal, result, &error);
  if (response == 0)
{'fraction_non_alphanumeric': 0.08186046511627906, 'fraction_numerical': 0.0026046511627906975, 'mean_word_length': 1.4762782128051588, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1597524', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1385, 'n_words': 330}