<commit_before>#include <config.h>
#include <string.h>
#include <dbus/dbus.h>
#include "gdaemonvfs.h"
#include "gvfsuriutils.h"
#include "gdaemonfile.h"
#include <gio/glocalvfs.h>
#include <gvfsdaemonprotocol.h>
#include <gmodule.h>
#include "gvfsdaemondbus.h"
#include "gdbusutils.h"
#include "gmountspec.h"
#include "gvfsmapuri.h"

static void g_daemon_vfs_class_init     (GDaemonVfsClass *class);
static void g_daemon_vfs_vfs_iface_init (GVfsIface       *iface);
static void g_daemon_vfs_finalize       (GObject         *object);

struct _GDaemonVfs
{
  GObject parent;

  DBusConnection *bus;
  
  GVfs *wrapped_vfs;
  GList *mount_cache;

  GHashTable *from_uri_hash;
  GHashTable *to_uri_hash;
};

static GDaemonVfs *the_vfs = NULL;
G_LOCK_DEFINE_STATIC(mount_cache);

G_DEFINE_TYPE_WITH_CODE (GDaemonVfs, g_daemon_vfs, G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (G_TYPE_VFS,
						g_daemon_vfs_vfs_iface_init))
 
static void
g_daemon_vfs_class_init (GDaemonVfsClass *class)
{
  GObjectClass *object_class;
  
  object_class = (GObjectClass *) class;

  object_class->finalize = g_daemon_vfs_finalize;
}

static void
g_daemon_vfs_finalize (GObject *object)
{
  GDaemonVfs *vfs;

  vfs = G_DAEMON_VFS (object);

  g_hash_table_destroy (vfs->from_uri_hash);
  g_hash_table_destroy (vfs->to_uri_hash);
  
  /* must chain up */
  G_OBJECT_CLASS (g_daemon_vfs_parent_class)->finalize (object);
}

static void
get_mountspec_from_uri (GDaemonVfs *vfs,
			GDecodedUri *uri,
			GMountSpec **spec_out,
			char **path_out)
{
  GMountSpec *spec;
  char *path;
  g_mountspec_from_uri_func func;
  
  /* TODO: Share MountSpec objects between files (its refcounted) */

  spec = NULL;
  
  if (strcmp (uri->scheme, "test") == 0)
    {
      spec = g_mount_spec_new ("test");
      path = g_strdup (uri->path);
    }
  else
    {
      func = g_hash_table_lookup (vfs->from_uri_hash, uri->scheme);
      if (func)
	func (uri, &spec, &path);
    }
  
  if (spec == NULL)
    {
      spec = g_mount_spec_new (uri->scheme);
      path = g_strdup (uri->path);
    }

  *spec_out = spec;
  *path_out = path;
}

static void
load_vfs_module (GDaemonVfs *vfs,<commit_msg>Reuse GMountSpec:s between different GDaemonFiles<commit_after>#include <config.h>
#include <string.h>
#include <dbus/dbus.h>
#include "gdaemonvfs.h"
#include "gvfsuriutils.h"
#include "gdaemonfile.h"
#include <gio/glocalvfs.h>
#include <gvfsdaemonprotocol.h>
#include <gmodule.h>
#include "gvfsdaemondbus.h"
#include "gdbusutils.h"
#include "gmountspec.h"
#include "gvfsmapuri.h"

static void g_daemon_vfs_class_init     (GDaemonVfsClass *class);
static void g_daemon_vfs_vfs_iface_init (GVfsIface       *iface);
static void g_daemon_vfs_finalize       (GObject         *object);

struct _GDaemonVfs
{
  GObject parent;

  DBusConnection *bus;
  
  GVfs *wrapped_vfs;
  GList *mount_cache;

  GHashTable *from_uri_hash;
  GHashTable *to_uri_hash;
};

static GDaemonVfs *the_vfs = NULL;
G_LOCK_DEFINE_STATIC(mount_cache);

G_DEFINE_TYPE_WITH_CODE (GDaemonVfs, g_daemon_vfs, G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (G_TYPE_VFS,
						g_daemon_vfs_vfs_iface_init))
 
static void
g_daemon_vfs_class_init (GDaemonVfsClass *class)
{
  GObjectClass *object_class;
  
  object_class = (GObjectClass *) class;

  object_class->finalize = g_daemon_vfs_finalize;
}

static void
g_daemon_vfs_finalize (GObject *object)
{
  GDaemonVfs *vfs;

  vfs = G_DAEMON_VFS (object);

  g_hash_table_destroy (vfs->from_uri_hash);
  g_hash_table_destroy (vfs->to_uri_hash);
  
  /* must chain up */
  G_OBJECT_CLASS (g_daemon_vfs_parent_class)->finalize (object);
}

static void
get_mountspec_from_uri (GDaemonVfs *vfs,
			GDecodedUri *uri,
			GMountSpec **spec_out,
			char **path_out)
{
  GMountSpec *spec;
  char *path;
  g_mountspec_from_uri_func func;
  
  spec = NULL;
  
  if (strcmp (uri->scheme, "test") == 0)
    {
      spec = g_mount_spec_new ("test");
      path = g_strdup (uri->path);
    }
  else
    {
      func = g_hash_table_lookup (vfs->from_uri_hash, uri->scheme);
      if (func)
	func (uri, &spec, &path);
    }
  
  if (spec == NULL)
    {
      spec = g_mount_spec_new (uri->scheme);
      path = g_strdup (uri->path);
    }

  *spec_out = g_mount_spec_get_unique_for (spec);
  g_mount_spec_unref (spec);
  *path_out = path;
}

static void
load_vfs_module (GDaemonVfs *vfs,
{'fraction_non_alphanumeric': 0.1125491102380402, 'fraction_numerical': 0.00046221400508435407, 'mean_word_length': 4.246060606060606, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7277098', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1801, 'n_words': 330}