summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/Makefile.am5
-rw-r--r--common/gvfsmonitorimpl.c203
-rw-r--r--common/gvfsmonitorimpl.h46
-rw-r--r--monitor/proxy/gproxyvolumemonitor.c110
4 files changed, 266 insertions, 98 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index cfc1c230..0577d677 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -23,6 +23,7 @@ libgvfscommon_la_SOURCES = \
gmountspec.c gmountspec.h \
gmountoperationdbus.c gmountoperationdbus.h \
gmountsource.c gmountsource.h \
+ gvfsmonitorimpl.c gvfsmonitorimpl.h \
gmounttracker.c gmounttracker.h \
gvfsdaemonprotocol.c gvfsdaemonprotocol.h \
gvfsicon.h gvfsicon.c \
@@ -30,6 +31,10 @@ libgvfscommon_la_SOURCES = \
$(dbus_built_sources) \
$(NULL)
+libgvfscommon_la_CFLAGS = \
+ -DREMOTE_VOLUME_MONITORS_DIR=\"$(datadir)/gvfs/remote-volume-monitors\" \
+ $(NULL)
+
# needed by cygwin (see bug #564003)
libgvfscommon_la_LDFLAGS = -no-undefined -avoid-version
diff --git a/common/gvfsmonitorimpl.c b/common/gvfsmonitorimpl.c
new file mode 100644
index 00000000..79a5ff78
--- /dev/null
+++ b/common/gvfsmonitorimpl.c
@@ -0,0 +1,203 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
+
+#include <config.h>
+
+#include <gvfsmonitorimpl.h>
+#include <gio/gio.h>
+#include <gvfsdbus.h>
+
+static GVfsMonitorImplementation *
+g_vfs_monitor_implementation_new (void)
+{
+ return g_new0 (GVfsMonitorImplementation, 1);
+}
+
+void
+g_vfs_monitor_implementation_free (GVfsMonitorImplementation *impl)
+{
+ g_free (impl->type_name);
+ g_free (impl->dbus_name);
+ g_free (impl);
+}
+
+GVfsMonitorImplementation *
+g_vfs_monitor_implementation_from_dbus (GVariant *value)
+{
+ GVfsMonitorImplementation *impl;
+ const gchar *key;
+ const gchar *mount_prefix;
+ GVariantIter *iter;
+ GVariant *v;
+
+ impl = g_vfs_monitor_implementation_new ();
+
+ g_variant_get (value, "(ssbia{sv})",
+ &impl->type_name,
+ &impl->dbus_name,
+ &impl->is_native,
+ &impl->native_priority,
+ &iter);
+
+ g_variant_iter_free (iter);
+
+ return impl;
+}
+
+GVariant *
+g_vfs_monitor_implementation_to_dbus (GVfsMonitorImplementation *impl)
+{
+ GVariantBuilder builder;
+ GVariant *v;
+
+ g_assert (impl->type_name != NULL);
+ g_assert (impl->dbus_name != NULL);
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+
+ v = g_variant_new ("(ssbia{sv})",
+ impl->type_name,
+ impl->dbus_name,
+ impl->is_native,
+ impl->native_priority,
+ &builder);
+ g_variant_builder_clear (&builder);
+
+ return v;
+}
+
+GList *
+g_vfs_list_monitor_implementations (void)
+{
+ GList *res = NULL;
+ GDir *dir;
+ GError *error;
+ const char *monitors_dir;
+
+ monitors_dir = g_getenv ("GVFS_MONITOR_DIR");
+ if (monitors_dir == NULL || *monitors_dir == 0)
+ monitors_dir = REMOTE_VOLUME_MONITORS_DIR;
+
+ error = NULL;
+ dir = g_dir_open (monitors_dir, 0, &error);
+ if (dir == NULL)
+ {
+ g_warning ("cannot open directory %s: %s", monitors_dir, error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ const char *name;
+
+ while ((name = g_dir_read_name (dir)) != NULL)
+ {
+ GVfsMonitorImplementation *impl;
+ GKeyFile *key_file;
+ char *type_name;
+ char *path;
+ char *dbus_name;
+ gboolean is_native;
+ int native_priority;
+
+ type_name = NULL;
+ key_file = NULL;
+ dbus_name = NULL;
+ path = NULL;
+
+ if (!g_str_has_suffix (name, ".monitor"))
+ goto cont;
+
+ path = g_build_filename (monitors_dir, name, NULL);
+
+ key_file = g_key_file_new ();
+ error = NULL;
+ if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error))
+ {
+ g_warning ("error loading key-value file %s: %s", path, error->message);
+ g_error_free (error);
+ goto cont;
+ }
+
+ type_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "Name", &error);
+ if (error != NULL)
+ {
+ g_warning ("error extracting Name key from %s: %s", path, error->message);
+ g_error_free (error);
+ goto cont;
+ }
+
+ dbus_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "DBusName", &error);
+ if (error != NULL)
+ {
+ g_warning ("error extracting DBusName key from %s: %s", path, error->message);
+ g_error_free (error);
+ goto cont;
+ }
+
+ is_native = g_key_file_get_boolean (key_file, "RemoteVolumeMonitor", "IsNative", &error);
+ if (error != NULL)
+ {
+ g_warning ("error extracting IsNative key from %s: %s", path, error->message);
+ g_error_free (error);
+ goto cont;
+ }
+
+ if (is_native)
+ {
+ native_priority = g_key_file_get_integer (key_file, "RemoteVolumeMonitor", "NativePriority", &error);
+ if (error != NULL)
+ {
+ g_warning ("error extracting NativePriority key from %s: %s", path, error->message);
+ g_error_free (error);
+ goto cont;
+ }
+ }
+ else
+ {
+ native_priority = 0;
+ }
+
+
+ impl = g_vfs_monitor_implementation_new ();
+ impl->type_name = type_name;
+ type_name = NULL; /* Transfer ownership */
+ impl->dbus_name = dbus_name;
+ dbus_name = NULL; /* Transfer ownership */
+ impl->is_native = is_native;
+ impl->native_priority = native_priority;
+
+ res = g_list_prepend (res, impl);
+
+ cont:
+
+ g_free (type_name);
+ g_free (dbus_name);
+ g_free (path);
+ if (key_file != NULL)
+ g_key_file_free (key_file);
+ }
+ g_dir_close (dir);
+ }
+
+ return res;
+}
+
diff --git a/common/gvfsmonitorimpl.h b/common/gvfsmonitorimpl.h
new file mode 100644
index 00000000..cafa9852
--- /dev/null
+++ b/common/gvfsmonitorimpl.h
@@ -0,0 +1,46 @@
+/* GIO - GLib Input, Output and Streaming Library
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
+
+#ifndef __G_LIST_MONITORS_H__
+#define __G_LIST_MONITORS_H__
+
+#include <glib-object.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+ char *type_name;
+ char *dbus_name;
+ gboolean is_native;
+ gint32 native_priority;
+} GVfsMonitorImplementation;
+
+void g_vfs_monitor_implementation_free (GVfsMonitorImplementation *impl);
+GVfsMonitorImplementation *g_vfs_monitor_implementation_from_dbus (GVariant *value);
+GVariant * g_vfs_monitor_implementation_to_dbus (GVfsMonitorImplementation *impl);
+
+GList *g_vfs_list_monitor_implementations (void);
+
+G_END_DECLS
+
+#endif /* __G_LIST_MONITORS_H__ */
diff --git a/monitor/proxy/gproxyvolumemonitor.c b/monitor/proxy/gproxyvolumemonitor.c
index 7f05b398..ee8818c9 100644
--- a/monitor/proxy/gproxyvolumemonitor.c
+++ b/monitor/proxy/gproxyvolumemonitor.c
@@ -42,6 +42,7 @@
#include "gproxydrive.h"
#include "gproxymountoperation.h"
#include "gvfsvolumemonitordbus.h"
+#include "gvfsmonitorimpl.h"
G_LOCK_DEFINE_STATIC(proxy_vm);
@@ -1428,9 +1429,7 @@ g_proxy_volume_monitor_unload_cleanup (void)
void
g_proxy_volume_monitor_register (GIOModule *module)
{
- GDir *dir;
- GError *error;
- const char *monitors_dir;
+ GList *impls, *l;
/* first register the abstract base type... */
g_proxy_volume_monitor_register_type (G_TYPE_MODULE (module));
@@ -1446,102 +1445,17 @@ g_proxy_volume_monitor_register (GIOModule *module)
* - and if so the priority
*/
- monitors_dir = g_getenv ("GVFS_MONITOR_DIR");
- if (monitors_dir == NULL || *monitors_dir == 0)
- monitors_dir = REMOTE_VOLUME_MONITORS_DIR;
-
- error = NULL;
- dir = g_dir_open (monitors_dir, 0, &error);
- if (dir == NULL)
- {
- g_warning ("cannot open directory %s: %s", monitors_dir, error->message);
- g_error_free (error);
- }
- else
+ impls = g_vfs_list_monitor_implementations ();
+ for (l = impls; l != NULL; l = l->next)
{
- const char *name;
+ GVfsMonitorImplementation *impl = l->data;
- while ((name = g_dir_read_name (dir)) != NULL)
- {
- GKeyFile *key_file;
- char *type_name;
- char *path;
- char *dbus_name;
- gboolean is_native;
- int native_priority;
-
- type_name = NULL;
- key_file = NULL;
- dbus_name = NULL;
- path = NULL;
-
- if (!g_str_has_suffix (name, ".monitor"))
- goto cont;
-
- path = g_build_filename (monitors_dir, name, NULL);
-
- key_file = g_key_file_new ();
- error = NULL;
- if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, &error))
- {
- g_warning ("error loading key-value file %s: %s", path, error->message);
- g_error_free (error);
- goto cont;
- }
-
- type_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "Name", &error);
- if (error != NULL)
- {
- g_warning ("error extracting Name key from %s: %s", path, error->message);
- g_error_free (error);
- goto cont;
- }
-
- dbus_name = g_key_file_get_string (key_file, "RemoteVolumeMonitor", "DBusName", &error);
- if (error != NULL)
- {
- g_warning ("error extracting DBusName key from %s: %s", path, error->message);
- g_error_free (error);
- goto cont;
- }
-
- is_native = g_key_file_get_boolean (key_file, "RemoteVolumeMonitor", "IsNative", &error);
- if (error != NULL)
- {
- g_warning ("error extracting IsNative key from %s: %s", path, error->message);
- g_error_free (error);
- goto cont;
- }
-
- if (is_native)
- {
- native_priority = g_key_file_get_integer (key_file, "RemoteVolumeMonitor", "NativePriority", &error);
- if (error != NULL)
- {
- g_warning ("error extracting NativePriority key from %s: %s", path, error->message);
- g_error_free (error);
- goto cont;
- }
- }
- else
- {
- native_priority = 0;
- }
-
- register_volume_monitor (G_TYPE_MODULE (module),
- type_name,
- dbus_name,
- is_native,
- native_priority);
-
- cont:
-
- g_free (type_name);
- g_free (dbus_name);
- g_free (path);
- if (key_file != NULL)
- g_key_file_free (key_file);
- }
- g_dir_close (dir);
+ register_volume_monitor (G_TYPE_MODULE (module),
+ impl->type_name,
+ impl->dbus_name,
+ impl->is_native,
+ impl->native_priority);
}
+
+ g_list_free_full (impls, (GDestroyNotify)g_vfs_monitor_implementation_free);
}