diff options
author | Alexander Larsson <alexl@redhat.com> | 2015-01-25 21:37:31 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2015-01-26 13:27:28 +0100 |
commit | 623d6fd8e9912ccc0003fad97578d24f5a5e773a (patch) | |
tree | 8d1fe4f09ed2064a15cbe0f17a140fc055110254 /common | |
parent | be1191f1b2f3972441b2e8947d9a2ac71160a375 (diff) | |
download | gvfs-623d6fd8e9912ccc0003fad97578d24f5a5e773a.tar.gz |
Move proxy monitor implementation listing to common
Also add some to/from_dbus helpers.
This is in preparation for moving the reading of the monitor
files to the gvfs daemon, which is needed for the sandboxed
case where the monitor files are not necessarily the same as
the host installed ones.
Diffstat (limited to 'common')
-rw-r--r-- | common/Makefile.am | 5 | ||||
-rw-r--r-- | common/gvfsmonitorimpl.c | 203 | ||||
-rw-r--r-- | common/gvfsmonitorimpl.h | 46 |
3 files changed, 254 insertions, 0 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__ */ |