[gvfs/wip/goa: 7/8] Add GVfsBackendGoogle



commit 85446f7debd2b760ce65309f6b65916594ec1085
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Oct 22 13:53:23 2014 +0200

    Add GVfsBackendGoogle
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739008

 client/Makefile.am         |    1 +
 client/gdaemonvfs.c        |    2 +
 client/googleuri.c         |  170 ++++++++++++++++++++++++++++++++++++++++++++
 configure.ac               |   23 ++++++
 daemon/Makefile.am         |   20 +++++
 daemon/google.mount.in     |    4 +
 daemon/gvfsbackendgoogle.c |  110 ++++++++++++++++++++++++++++
 daemon/gvfsbackendgoogle.h |   62 ++++++++++++++++
 8 files changed, 392 insertions(+), 0 deletions(-)
---
diff --git a/client/Makefile.am b/client/Makefile.am
index 8c7b76a..c9aa1f6 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -22,6 +22,7 @@ gvfsclientinclude_HEADERS = \
 
 URI_PARSER_SOURCES = \
        smburi.c \
+       googleuri.c \
        httpuri.c \
        afpuri.c \
        $(NULL)
diff --git a/client/gdaemonvfs.c b/client/gdaemonvfs.c
index 9ab806b..002c992 100644
--- a/client/gdaemonvfs.c
+++ b/client/gdaemonvfs.c
@@ -1504,6 +1504,7 @@ g_daemon_vfs_class_init (GDaemonVfsClass *class)
 /* Module API */
 
 void g_vfs_uri_mapper_smb_register (GIOModule *module);
+void g_vfs_uri_mapper_google_register (GIOModule *module);
 void g_vfs_uri_mapper_http_register (GIOModule *module);
 void g_vfs_uri_mapper_afp_register (GIOModule *module);
 
@@ -1539,6 +1540,7 @@ g_io_module_load (GIOModule *module)
   
   g_vfs_uri_mapper_register (module);
   g_vfs_uri_mapper_smb_register (module);
+  g_vfs_uri_mapper_google_register (module);
   g_vfs_uri_mapper_http_register (module);
   g_vfs_uri_mapper_afp_register (module);
 }
diff --git a/client/googleuri.c b/client/googleuri.c
new file mode 100644
index 0000000..9e8b94d
--- /dev/null
+++ b/client/googleuri.c
@@ -0,0 +1,170 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* gvfs - extensions for gio
+ *
+ * Copyright (C) 2014 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: Debarshi Ray <debarshir gnome org>
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include <stdlib.h> /* atoi */
+
+#include <gio/gio.h>
+#include <gvfsurimapper.h>
+#include <gvfsuriutils.h>
+
+typedef struct _GVfsUriMapperGoogle GVfsUriMapperGoogle;
+typedef struct _GVfsUriMapperGoogleClass GVfsUriMapperGoogleClass;
+
+struct _GVfsUriMapperGoogle
+{
+  GVfsUriMapper parent;
+};
+
+struct _GVfsUriMapperGoogleClass
+{
+  GVfsUriMapperClass parent_class;
+};
+
+GType g_vfs_uri_mapper_google_get_type (void);
+void  g_vfs_uri_mapper_google_register (GIOModule *module);
+
+G_DEFINE_DYNAMIC_TYPE (GVfsUriMapperGoogle, g_vfs_uri_mapper_google, G_VFS_TYPE_URI_MAPPER)
+
+static const gchar * const *
+google_get_handled_schemes (GVfsUriMapper *mapper)
+{
+  static const gchar *schemes[] = {
+    "google-drive",
+    NULL
+  };
+  return schemes;
+}
+
+static GMountSpec *
+google_from_uri (GVfsUriMapper  *mapper,
+                 const char     *uri_str,
+                 gchar         **path)
+{
+  GMountSpec *spec = NULL;
+  GDecodedUri *uri = NULL;
+  gchar *identity = NULL;
+
+  uri = g_vfs_decode_uri (uri_str);
+
+  if (uri == NULL)
+    goto out;
+
+  if (g_ascii_strncasecmp (uri->scheme, "google-drive", 12) != 0)
+    goto out;
+
+  spec = g_mount_spec_new ("google-drive");
+  g_mount_spec_set (spec, "uri", uri_str);
+
+  identity = g_strconcat (uri->userinfo, "@", uri->host, NULL);
+  g_mount_spec_set (spec, "goa-identity", identity);
+
+  *path = uri->path;
+  uri->path = NULL;
+
+ out:
+  g_free (identity);
+  g_vfs_decoded_uri_free (uri);
+  return spec;
+}
+
+static GMountSpec *
+google_get_mount_spec_for_path (GVfsUriMapper *mapper,
+                                GMountSpec *spec,
+                                const gchar *old_path,
+                                const gchar *new_path)
+{
+  return NULL;
+}
+
+static const gchar * const *
+google_get_handled_mount_types (GVfsUriMapper *mapper)
+{
+  static const gchar *types[] = {
+    "google-drive",
+    NULL
+  };
+  return types;
+}
+
+static gchar *
+google_to_uri (GVfsUriMapper *mapper,
+               GMountSpec    *spec,
+               const gchar    *path,
+               gboolean       allow_utf8)
+{
+  const gchar *type;
+  gchar *res = NULL;
+
+  type = g_mount_spec_get (spec, "type");
+  if (g_strcmp0 (type, "google-drive") == 0)
+    {
+      const gchar *uri;
+
+      uri = g_mount_spec_get (spec, "uri");
+      res = g_strdup (uri);
+    }
+
+  return res;
+}
+
+static const gchar *
+google_to_uri_scheme (GVfsUriMapper *mapper,
+                      GMountSpec    *spec)
+{
+  const gchar *type;
+
+  type = g_mount_spec_get (spec, "type");
+  return (g_strcmp0 (type, "google-drive") == 0) ? type : NULL;
+}
+
+static void
+g_vfs_uri_mapper_google_class_finalize (GVfsUriMapperGoogleClass *klass)
+{
+}
+
+static void
+g_vfs_uri_mapper_google_class_init (GVfsUriMapperGoogleClass *class)
+{
+  GVfsUriMapperClass *mapper_class = G_VFS_URI_MAPPER_CLASS (class);
+
+  mapper_class->get_handled_schemes = google_get_handled_schemes;
+  mapper_class->from_uri = google_from_uri;
+  mapper_class->get_mount_spec_for_path = google_get_mount_spec_for_path;
+  mapper_class->get_handled_mount_types = google_get_handled_mount_types;
+  mapper_class->to_uri = google_to_uri;
+  mapper_class->to_uri_scheme = google_to_uri_scheme;
+}
+
+static void
+g_vfs_uri_mapper_google_init (GVfsUriMapperGoogle *vfs)
+{
+}
+
+void
+g_vfs_uri_mapper_google_register (GIOModule *module)
+{
+  g_vfs_uri_mapper_google_register_type (G_TYPE_MODULE (module));
+}
diff --git a/configure.ac b/configure.ac
index 1e21fdb..617f7d9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -407,6 +407,28 @@ AC_SUBST(GOA_CFLAGS)
 
 AM_CONDITIONAL(USE_GOA, [test "$msg_goa" = "yes"])
 
+dnl ****************************************************
+dnl *** Check if we should build with Google backend ***
+dnl ****************************************************
+AC_ARG_ENABLE(google, AS_HELP_STRING([--disable-google],[build without Google backend]))
+msg_google=no
+GOOGLE_LIBS=
+GOOGLE_CFLAGS=
+
+if test "x$enable_google" != "xno" ; then
+  PKG_CHECK_EXISTS(goa-1.0 >= 3.15.1 libgdata >= 0.13.1, msg_google=yes)
+
+  if test "x$msg_google" = "xyes"; then
+    PKG_CHECK_MODULES(GOOGLE, goa-1.0 libgdata)
+    AC_DEFINE(HAVE_GOOGLE, 1, [Define to 1 if Google is going to be built])
+  fi
+fi
+
+AC_SUBST(GOOGLE_LIBS)
+AC_SUBST(GOOGLE_CFLAGS)
+
+AM_CONDITIONAL(USE_GOOGLE, [test "$msg_google" = "yes"])
+
 dnl *****************************************************
 dnl *** Check if we should build with obexftp backend ***
 dnl *****************************************************
@@ -938,6 +960,7 @@ echo "
         hotplug backend:              $msg_hotplug_backend
 
        Blu-ray metadata support:     $msg_bluray
+       Google support:               $msg_google
         HTTP/WebDAV support:          $msg_http
         ObexFTP support               $msg_obexftp
        Samba support:                $msg_samba
diff --git a/daemon/Makefile.am b/daemon/Makefile.am
index a6a9ae1..5cb89ae 100644
--- a/daemon/Makefile.am
+++ b/daemon/Makefile.am
@@ -48,6 +48,12 @@ libexec_PROGRAMS=gvfsd gvfsd-sftp gvfsd-trash gvfsd-computer gvfsd-burn gvfsd-lo
 mount_in_files = sftp.mount.in ftp.mount.in trash.mount.in computer.mount.in burn.mount.in 
localtest.mount.in network.mount.in
 mount_DATA =  sftp.mount ftp.mount trash.mount computer.mount burn.mount localtest.mount network.mount
 
+mount_in_files +=google.mount.in
+if USE_GOOGLE
+mount_DATA += google.mount
+libexec_PROGRAMS += gvfsd-google
+endif
+
 mount_in_files +=recent.mount.in
 if USE_GTK
 mount_DATA += recent.mount
@@ -459,6 +465,20 @@ else
 gvfsd_cdda_LDADD = $(libraries) $(CDDA_LIBS) $(HAL_LIBS)
 endif
 
+gvfsd_google_SOURCES = \
+       gvfsbackendgoogle.c gvfsbackendgoogle.h \
+       daemon-main.c daemon-main.h \
+       daemon-main-generic.c
+
+gvfsd_google_CPPFLAGS = \
+       $(flags) \
+       -DBACKEND_HEADER=gvfsbackendgoogle.h \
+       -DDEFAULT_BACKEND_TYPE=google-drive \
+       -DBACKEND_TYPES='"google-drive", G_VFS_TYPE_BACKEND_GOOGLE,' \
+       $(GOOGLE_CFLAGS)
+
+gvfsd_google_LDADD = $(libraries) $(GOOGLE_LIBS)
+
 gvfsd_gphoto2_SOURCES = \
        gvfsbackendgphoto2.c gvfsbackendgphoto2.h \
        daemon-main.c daemon-main.h \
diff --git a/daemon/google.mount.in b/daemon/google.mount.in
new file mode 100644
index 0000000..059b228
--- /dev/null
+++ b/daemon/google.mount.in
@@ -0,0 +1,4 @@
+[Mount]
+Type=google-drive
+Exec= libexecdir@/gvfsd-google
+AutoMount=false
diff --git a/daemon/gvfsbackendgoogle.c b/daemon/gvfsbackendgoogle.c
new file mode 100644
index 0000000..e0e9d79
--- /dev/null
+++ b/daemon/gvfsbackendgoogle.c
@@ -0,0 +1,110 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* gvfs - extensions for gio
+ *
+ * Copyright (C) 2014 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: Debarshi Ray <debarshir gnome org>
+ */
+
+#include <config.h>
+
+#include <gdata/gdata.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#include <goa/goa.h>
+
+#include "gvfsbackendgoogle.h"
+
+struct _GVfsBackendGoogle
+{
+  GVfsBackend parent;
+};
+
+struct _GVfsBackendGoogleClass
+{
+  GVfsBackendClass parent_class;
+};
+
+G_DEFINE_TYPE(GVfsBackendGoogle, g_vfs_backend_google, G_VFS_TYPE_BACKEND)
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GoaClient *
+get_goa_client_sync (GError **error)
+{
+  static GoaClient *client = NULL;
+  static GError *_error = NULL;
+  static volatile gsize initialized = 0;
+
+  if (g_once_init_enter (&initialized))
+    {
+      client = goa_client_new_sync (NULL, &_error);
+      g_once_init_leave (&initialized, 1);
+    }
+
+  if (_error != NULL && error != NULL)
+    *error = g_error_copy (_error);
+
+  return client;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+g_vfs_backend_google_mount (GVfsBackend  *_self,
+                            GVfsJobMount *job,
+                            GMountSpec   *mount_spec,
+                            GMountSource *mount_source,
+                            gboolean      is_automount)
+{
+  g_vfs_job_succeeded (G_VFS_JOB (job));
+}
+
+static void
+g_vfs_backend_google_dispose (GObject *_self)
+{
+  GVfsBackendGoogle *self = G_VFS_BACKEND_GOOGLE (_self);
+
+  G_OBJECT_CLASS (g_vfs_backend_google_parent_class)->dispose (_self);
+}
+
+static void
+g_vfs_backend_google_class_init (GVfsBackendGoogleClass * klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GVfsBackendClass *backend_class = G_VFS_BACKEND_CLASS (klass);
+
+  gobject_class->dispose = g_vfs_backend_google_dispose;
+
+  backend_class->try_mount = NULL;
+  backend_class->mount = g_vfs_backend_google_mount;
+}
+
+static void
+g_vfs_backend_google_init (GVfsBackendGoogle *self)
+{
+  g_vfs_backend_set_user_visible (G_VFS_BACKEND (self), FALSE);
+}
+
+GVfsBackend *
+g_vfs_backend_google_new (void)
+{
+  return g_object_new (G_VFS_TYPE_BACKEND_GOOGLE, NULL);
+}
diff --git a/daemon/gvfsbackendgoogle.h b/daemon/gvfsbackendgoogle.h
new file mode 100644
index 0000000..21b209f
--- /dev/null
+++ b/daemon/gvfsbackendgoogle.h
@@ -0,0 +1,62 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* gvfs - extensions for gio
+ *
+ * Copyright (C) 2014 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: Debarshi Ray <debarshir gnome org>
+ */
+
+#ifndef __G_VFS_BACKEND_GOOGLE_H__
+#define __G_VFS_BACKEND_GOOGLE_H__
+
+#include <gvfsbackend.h>
+
+G_BEGIN_DECLS
+
+#define G_VFS_TYPE_BACKEND_GOOGLE (g_vfs_backend_google_get_type())
+
+#define G_VFS_BACKEND_GOOGLE(o) \
+  (G_TYPE_CHECK_INSTANCE_CAST((o), \
+   G_VFS_TYPE_BACKEND_GOOGLE, GVfsBackendGoogle))
+
+#define G_VFS_BACKEND_GOOGLE_CLASS(k) \
+  (G_TYPE_CHECK_CLASS_CAST((k), \
+   G_VFS_TYPE_BACKEND_GOOGLE, GVfsBackendGoogleClass))
+
+#define G_VFS_IS_BACKEND_GOOGLE(o) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((o), \
+   G_VFS_TYPE_BACKEND_GOOGLE))
+
+#define G_VFS_IS_BACKEND_GOOGLE_CLASS(k) \
+  (G_TYPE_CHECK_CLASS_TYPE((k), \
+   G_VFS_TYPE_BACKEND_GOOGLE))
+
+#define G_VFS_BACKEND_GOOGLE_GET_CLASS(o) \
+  (G_TYPE_INSTANCE_GET_CLASS((o), \
+   G_VFS_TYPE_BACKEND_GOOGLE, GVfsBackendGoogleClass))
+
+typedef struct _GVfsBackendGoogle GVfsBackendGoogle;
+typedef struct _GVfsBackendGoogleClass GVfsBackendGoogleClass;
+
+GType g_vfs_backend_google_get_type (void) G_GNUC_CONST;
+
+GVfsBackend *g_vfs_backend_google_new (void);
+
+G_END_DECLS
+
+#endif /* __G_VFS_BACKEND_GOOGLE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]