diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | client/gdaemonvfs.c | 123 | ||||
-rw-r--r-- | client/smburi.c | 17 | ||||
-rw-r--r-- | common/gvfsdaemonprotocol.h | 1 | ||||
-rw-r--r-- | common/gvfsurimapper.c | 16 | ||||
-rw-r--r-- | common/gvfsurimapper.h | 46 | ||||
-rw-r--r-- | daemon/mount.c | 42 |
7 files changed, 233 insertions, 27 deletions
@@ -1,3 +1,18 @@ +2007-10-08 Sebastian Dröge <slomo@circular-chaos.org> + + * client/gdaemonvfs.c: (g_daemon_vfs_finalize), + (g_daemon_vfs_init), (fill_supported_uri_schemes), + (g_daemon_vfs_get_supported_uri_schemes), + (g_daemon_vfs_class_init): + * client/smburi.c: (smb_to_uri_scheme), + (g_vfs_uri_mapper_smb_class_init): + * common/gvfsdaemonprotocol.h: + * common/gvfsurimapper.c: (g_vfs_uri_mapper_to_uri_scheme): + * common/gvfsurimapper.h: + * daemon/mount.c: (list_mount_types), (dbus_message_function): + Implement get_supported_uri_schemes method and add a GVfsUriMapper + method to map a mount spec to an URI scheme. + 2007-10-05 Alexander Larsson <alexl@redhat.com> * daemon/gvfsbackendtrash.c: diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c index 1c590ce8..484be4ed 100644 --- a/client/gdaemonvfs.c +++ b/client/gdaemonvfs.c @@ -35,6 +35,8 @@ struct _GDaemonVfs GHashTable *from_uri_hash; GHashTable *to_uri_hash; + + gchar **supported_uri_schemes; }; struct _GDaemonVfsClass @@ -84,12 +86,15 @@ g_daemon_vfs_finalize (GObject *object) g_hash_table_destroy (vfs->from_uri_hash); g_hash_table_destroy (vfs->to_uri_hash); + g_strfreev (vfs->supported_uri_schemes); + if (vfs->async_bus) { dbus_connection_close (vfs->async_bus); dbus_connection_unref (vfs->async_bus); } - + + /* must chain up */ G_OBJECT_CLASS (g_daemon_vfs_parent_class)->finalize (object); } @@ -156,7 +161,7 @@ g_daemon_vfs_init (GDaemonVfs *vfs) { GType *mappers; guint n_mappers; - const char **schemes, **mount_types; + const char * const *schemes, * const *mount_types; GVfsUriMapper *mapper; int i; @@ -289,6 +294,119 @@ _g_daemon_vfs_get_uri_for_mountspec (GMountSpec *spec, return uri; } +static void +fill_supported_uri_schemes (GDaemonVfs *vfs) +{ + DBusConnection *connection; + DBusMessage *message, *reply; + DBusError error; + DBusMessageIter iter, array_iter; + gint i, count; + GList *l, *list = NULL; + + connection = dbus_bus_get (DBUS_BUS_SESSION, NULL); + + + message = dbus_message_new_method_call (G_VFS_DBUS_DAEMON_NAME, + G_VFS_DBUS_MOUNTTRACKER_PATH, + G_VFS_DBUS_MOUNTTRACKER_INTERFACE, + G_VFS_DBUS_MOUNTTRACKER_OP_LIST_MOUNT_TYPES); + + if (message == NULL) + _g_dbus_oom (); + + dbus_message_set_auto_start (message, TRUE); + + dbus_error_init (&error); + reply = dbus_connection_send_with_reply_and_block (connection, + message, + G_VFS_DBUS_TIMEOUT_MSECS, + &error); + dbus_message_unref (message); + + if (dbus_error_is_set (&error)) + { + dbus_error_free (&error); + dbus_connection_unref (connection); + return; + } + + if (reply == NULL) + _g_dbus_oom (); + + dbus_message_iter_init (reply, &iter); + g_assert (dbus_message_iter_get_element_type (&iter) == DBUS_TYPE_STRING); + + dbus_message_iter_recurse (&iter, &array_iter); + + count = 0; + do + { + gchar *type, *scheme = NULL; + GVfsUriMapper *mapper = NULL; + GMountSpec *spec; + gboolean new = TRUE; + + dbus_message_iter_get_basic (&array_iter, &type); + + spec = g_mount_spec_new (type); + + mapper = g_hash_table_lookup (vfs->to_uri_hash, type); + + if (mapper) + scheme = g_vfs_uri_mapper_to_uri_scheme (mapper, spec); + + if (scheme == NULL) + scheme = g_strdup (type); + + for (l = list; l != NULL; l = l->next) + { + if (strcmp (l->data, scheme) == 0) + { + new = FALSE; + break; + } + } + + if (new) + { + list = g_list_prepend (list, scheme); + count++; + } + else + { + g_free (scheme); + } + + g_mount_spec_unref (spec); + } + while (dbus_message_iter_next (&array_iter)); + + dbus_message_unref (reply); + dbus_connection_unref (connection); + + list = g_list_prepend (list, g_strdup ("file")); + list = g_list_sort (list, (GCompareFunc) strcmp); + + vfs->supported_uri_schemes = g_new0 (gchar *, count + 2); + + for (i = 0, l = list; l != NULL; l = l->next, i++) + vfs->supported_uri_schemes[i] = l->data; + + g_list_free (list); +} + +static const gchar * const * +g_daemon_vfs_get_supported_uri_schemes (GVfs *vfs) +{ + GDaemonVfs *daemon_vfs = G_DAEMON_VFS (vfs); + + if (!daemon_vfs->supported_uri_schemes) + fill_supported_uri_schemes (daemon_vfs); + + return (const gchar * const *) G_DAEMON_VFS (vfs)->supported_uri_schemes; +} + static GMountRef * mount_ref_ref (GMountRef *ref) { @@ -631,6 +749,7 @@ g_daemon_vfs_class_init (GDaemonVfsClass *class) vfs_class->get_priority = g_daemon_vfs_get_priority; vfs_class->get_file_for_path = g_daemon_vfs_get_file_for_path; vfs_class->get_file_for_uri = g_daemon_vfs_get_file_for_uri; + vfs_class->get_supported_uri_schemes = g_daemon_vfs_get_supported_uri_schemes; vfs_class->parse_name = g_daemon_vfs_parse_name; } diff --git a/client/smburi.c b/client/smburi.c index b8633f35..36afcc37 100644 --- a/client/smburi.c +++ b/client/smburi.c @@ -80,7 +80,7 @@ normalize_smb_name (const char *name, gssize len) return g_ascii_strdown (name, len); } -static const char ** +static const char * const * smb_get_handled_schemes (GVfsUriMapper *mapper) { static const char *schemes[] = { @@ -206,7 +206,7 @@ smb_from_uri (GVfsUriMapper *mapper, return spec != NULL; } -static const char ** +static const char * const * smb_get_handled_mount_types (GVfsUriMapper *mapper) { static const char *types[] = { @@ -267,6 +267,18 @@ smb_to_uri (GVfsUriMapper *mapper, return s; } +static gchar * +smb_to_uri_scheme (GVfsUriMapper *mapper, + GMountSpec *spec) +{ + const gchar *type = g_mount_spec_get_type (spec); + if (strcmp ("smb-network", type) == 0 || + strcmp ("smb-server", type) == 0 || + strcmp ("smb-share", type) == 0) + return g_strdup ("smb"); + else + return NULL; +} static void g_vfs_uri_mapper_smb_class_init (GVfsUriMapperSmbClass *class) @@ -281,4 +293,5 @@ g_vfs_uri_mapper_smb_class_init (GVfsUriMapperSmbClass *class) mapper_class->from_uri = smb_from_uri; mapper_class->get_handled_mount_types = smb_get_handled_mount_types; mapper_class->to_uri = smb_to_uri; + mapper_class->to_uri_scheme = smb_to_uri_scheme; } diff --git a/common/gvfsdaemonprotocol.h b/common/gvfsdaemonprotocol.h index 2554ab77..d5caf50e 100644 --- a/common/gvfsdaemonprotocol.h +++ b/common/gvfsdaemonprotocol.h @@ -15,6 +15,7 @@ G_BEGIN_DECLS #define G_VFS_DBUS_MOUNTTRACKER_OP_MOUNT_LOCATION "mountLocation" #define G_VFS_DBUS_MOUNTTRACKER_OP_LIST_MOUNTS "listMounts" #define G_VFS_DBUS_MOUNTTRACKER_OP_REGISTER_MOUNT "registerMount" +#define G_VFS_DBUS_MOUNTTRACKER_OP_LIST_MOUNT_TYPES "listMountTypes" #define G_VFS_DBUS_MOUNTTRACKER_SIGNAL_MOUNTED "mounted" #define G_VFS_DBUS_MOUNTTRACKER_SIGNAL_UNMOUNTED "unmounted" diff --git a/common/gvfsurimapper.c b/common/gvfsurimapper.c index 763470d4..e60c24ae 100644 --- a/common/gvfsurimapper.c +++ b/common/gvfsurimapper.c @@ -15,7 +15,7 @@ g_vfs_uri_mapper_init (GVfsUriMapper *vfs) { } -const char ** +const char * const * g_vfs_uri_mapper_get_handled_schemes (GVfsUriMapper *mapper) { GVfsUriMapperClass *class; @@ -39,7 +39,7 @@ g_vfs_uri_mapper_from_uri (GVfsUriMapper *mapper, return (* class->from_uri) (mapper, uri, spec_out, path_out); } -const char ** +const char * const * g_vfs_uri_mapper_get_handled_mount_types (GVfsUriMapper *mapper) { GVfsUriMapperClass *class; @@ -61,3 +61,15 @@ g_vfs_uri_mapper_to_uri (GVfsUriMapper *mapper, return (* class->to_uri) (mapper, spec, path, allow_utf8); } + +char * +g_vfs_uri_mapper_to_uri_scheme (GVfsUriMapper *mapper, + GMountSpec *spec) +{ + GVfsUriMapperClass *class; + + class = G_VFS_URI_MAPPER_GET_CLASS (mapper); + + return (* class->to_uri_scheme) (mapper, spec); +} + diff --git a/common/gvfsurimapper.h b/common/gvfsurimapper.h index a0d3b404..94c8c6f7 100644 --- a/common/gvfsurimapper.h +++ b/common/gvfsurimapper.h @@ -27,32 +27,36 @@ struct _GVfsUriMapperClass /* Virtual Table */ - const char ** (*get_handled_schemes) (GVfsUriMapper *mapper); - gboolean (*from_uri) (GVfsUriMapper *mapper, - const char *uri, - GMountSpec **spec_out, - char **path_out); + const char * const * (*get_handled_schemes) (GVfsUriMapper *mapper); + gboolean (*from_uri) (GVfsUriMapper *mapper, + const char *uri, + GMountSpec **spec_out, + char **path_out); - const char ** (*get_handled_mount_types) (GVfsUriMapper *mapper); - char * (*to_uri) (GVfsUriMapper *mapper, - GMountSpec *spec, - char *path, - gboolean allow_utf8); + const char * const * (*get_handled_mount_types) (GVfsUriMapper *mapper); + char * (*to_uri) (GVfsUriMapper *mapper, + GMountSpec *spec, + char *path, + gboolean allow_utf8); + char * (*to_uri_scheme) (GVfsUriMapper *mapper, + GMountSpec *spec); }; GType g_vfs_uri_mapper_get_type (void) G_GNUC_CONST; -const char **g_vfs_uri_mapper_get_handled_schemes (GVfsUriMapper *mapper); -gboolean g_vfs_uri_mapper_from_uri (GVfsUriMapper *mapper, - const char *uri, - GMountSpec **spec_out, - char **path_out); - -const char **g_vfs_uri_mapper_get_handled_mount_types (GVfsUriMapper *mapper); -char * g_vfs_uri_mapper_to_uri (GVfsUriMapper *mapper, - GMountSpec *spec, - char *path, - gboolean allow_utf8); +const char * const * g_vfs_uri_mapper_get_handled_schemes (GVfsUriMapper *mapper); +gboolean g_vfs_uri_mapper_from_uri (GVfsUriMapper *mapper, + const char *uri, + GMountSpec **spec_out, + char **path_out); + +const char * const * g_vfs_uri_mapper_get_handled_mount_types (GVfsUriMapper *mapper); +char * g_vfs_uri_mapper_to_uri (GVfsUriMapper *mapper, + GMountSpec *spec, + char *path, + gboolean allow_utf8); +char * g_vfs_uri_mapper_to_uri_scheme (GVfsUriMapper *mapper, + GMountSpec *spec); G_END_DECLS diff --git a/daemon/mount.c b/daemon/mount.c index 4e698ec0..9c29754c 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -820,6 +820,43 @@ mount_location (DBusConnection *connection, } +static void +list_mount_types (DBusConnection *connection, + DBusMessage *message) +{ + VfsMountable *mountable; + DBusMessage *reply; + DBusMessageIter iter, array_iter; + GList *l; + + reply = dbus_message_new_method_return (message); + if (reply == NULL) + _g_dbus_oom (); + + dbus_message_iter_init_append (reply, &iter); + + + if (!dbus_message_iter_open_container (&iter, + DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, + &array_iter)) + _g_dbus_oom (); + + for (l = mountables; l != NULL; l = l->next) + { + mountable = l->data; + if (!dbus_message_iter_append_basic (&array_iter, + DBUS_TYPE_STRING, + &mountable->type)) + _g_dbus_oom (); + } + + if (!dbus_message_iter_close_container (&iter, &array_iter)) + _g_dbus_oom (); + + dbus_connection_send (connection, reply, NULL); +} + static DBusHandlerResult dbus_message_function (DBusConnection *connection, DBusMessage *message, @@ -844,6 +881,10 @@ dbus_message_function (DBusConnection *connection, G_VFS_DBUS_MOUNTTRACKER_INTERFACE, G_VFS_DBUS_MOUNTTRACKER_OP_MOUNT_LOCATION)) mount_location (connection, message); + else if (dbus_message_is_method_call (message, + G_VFS_DBUS_MOUNTTRACKER_INTERFACE, + G_VFS_DBUS_MOUNTTRACKER_OP_LIST_MOUNT_TYPES)) + list_mount_types (connection, message); else res = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; @@ -913,3 +954,4 @@ mount_init (void) dbus_error_free (&error); } } + |