[gvfs] AFC: Add ability to mount the house-arrest service



commit 073715e62f7618a78f1ca07663cd734bbd545fa6
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Nov 12 19:42:41 2010 +0000

    AFC: Add ability to mount the house-arrest service
    
    https://bugzilla.gnome.org/show_bug.cgi?id=636133

 monitor/afc/afcvolume.c              |   47 +++++++++++++++++++++++++++++----
 monitor/afc/afcvolume.h              |    5 +++-
 monitor/afc/afcvolumemonitor.c       |   14 ++++++++-
 monitor/afc/afcvolumemonitordaemon.c |    9 ++++++-
 po/POTFILES.in                       |    1 +
 5 files changed, 66 insertions(+), 10 deletions(-)
---
diff --git a/monitor/afc/afcvolume.c b/monitor/afc/afcvolume.c
index 0784716..3669b27 100644
--- a/monitor/afc/afcvolume.c
+++ b/monitor/afc/afcvolume.c
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <glib.h>
 #include <gio/gio.h>
+#include <glib/gi18n.h>
 
 #include <libimobiledevice/libimobiledevice.h>
 #include <libimobiledevice/lockdown.h>
@@ -20,6 +21,7 @@ struct _GVfsAfcVolume {
   GVolumeMonitor *monitor;
 
   char *uuid;
+  char *service;
 
   char *name;
   char *icon;
@@ -39,6 +41,7 @@ g_vfs_afc_volume_finalize (GObject *object)
   self = G_VFS_AFC_VOLUME(object);
 
   g_free (self->uuid);
+  g_free (self->service);
 
   g_free (self->name);
   g_free (self->icon);
@@ -86,17 +89,43 @@ _g_vfs_afc_volume_update_metadata (GVfsAfcVolume *self)
   if (err != IDEVICE_E_SUCCESS)
     return 0;
 
-  if (lockdownd_client_new (dev, &lockdown_cli, "gvfs-afc-volume-monitor") != LOCKDOWN_E_SUCCESS)
+  if (self->service != NULL)
     {
-      idevice_free (dev);
-      return 0;
+      guint16 port;
+
+      if (lockdownd_client_new_with_handshake (dev, &lockdown_cli, "gvfs-afc-volume-monitor") != LOCKDOWN_E_SUCCESS)
+        {
+          idevice_free (dev);
+          return 0;
+        }
+      if (lockdownd_start_service(lockdown_cli, "com.apple.mobile.house_arrest", &port) != LOCKDOWN_E_SUCCESS)
+        {
+          idevice_free (dev);
+          return 0;
+        }
+    }
+  else
+    {
+      if (lockdownd_client_new (dev, &lockdown_cli, "gvfs-afc-volume-monitor") != LOCKDOWN_E_SUCCESS)
+        {
+          idevice_free (dev);
+          return 0;
+        }
     }
 
   /* try to use pretty device name */
   if (lockdownd_get_device_name (lockdown_cli, &display_name) == LOCKDOWN_E_SUCCESS)
     {
       g_free (self->name);
-      self->name = display_name;
+      if (g_strcmp0 (self->service, HOUSE_ARREST_SERVICE_PORT) == 0)
+        {
+          /* translators:
+           * This is "Documents on foo" where foo is the device name, eg.:
+           * Documents on Alan Smithee's iPhone */
+          self->name = g_strdup_printf (_("Documents on %s"), display_name);
+        }
+      else
+        self->name = display_name;
     }
 
   value = NULL;
@@ -127,7 +156,8 @@ _g_vfs_afc_volume_update_metadata (GVfsAfcVolume *self)
 
 GVfsAfcVolume *
 g_vfs_afc_volume_new (GVolumeMonitor *monitor,
-                      const char     *uuid)
+                      const char     *uuid,
+                      const char     *service)
 {
   GVfsAfcVolume *self;
   GFile *root;
@@ -136,8 +166,13 @@ g_vfs_afc_volume_new (GVolumeMonitor *monitor,
   self = G_VFS_AFC_VOLUME(g_object_new (G_VFS_TYPE_AFC_VOLUME, NULL));
   self->monitor = monitor;
   self->uuid = g_strdup (uuid);
+  self->service = g_strdup (service);
+
+  if (service == NULL)
+    uri = g_strdup_printf ("afc://%s", self->uuid);
+  else
+    uri = g_strdup_printf ("afc://%s:%s", self->uuid, service);
 
-  uri = g_strdup_printf ("afc://%s", self->uuid);
   root = g_file_new_for_uri (uri);
   g_free (uri);
 
diff --git a/monitor/afc/afcvolume.h b/monitor/afc/afcvolume.h
index de24cd5..ba0aa3b 100644
--- a/monitor/afc/afcvolume.h
+++ b/monitor/afc/afcvolume.h
@@ -21,6 +21,8 @@ G_BEGIN_DECLS
 #define G_VFS_IS_AFC_VOLUME_CLASS(k) ((G_TYPE_CHECK_CLASS_TYPE((k), G_VFS_TYPE_AFC_VOLUME))
 #define G_VFS_AFC_VOLUME_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), G_VFS_TYPE_AFC_VOLUME, GVfsAfcVolumeClass))
 
+#define HOUSE_ARREST_SERVICE_PORT "3"
+
 typedef struct _GVfsAfcVolume GVfsAfcVolume;
 typedef struct _GVfsAfcVolumeClass GVfsAfcVolumeClass;
 
@@ -31,7 +33,8 @@ struct _GVfsAfcVolumeClass {
 GType g_vfs_afc_volume_get_type (void) G_GNUC_CONST;
 
 GVfsAfcVolume *g_vfs_afc_volume_new (GVolumeMonitor *monitor,
-                                     const char     *uuid);
+                                     const char     *uuid,
+                                     const char     *service);
 
 gboolean g_vfs_afc_volume_has_uuid (GVfsAfcVolume *volume, const char *uuid);
 
diff --git a/monitor/afc/afcvolumemonitor.c b/monitor/afc/afcvolumemonitor.c
index d10e862..dfc3fa5 100644
--- a/monitor/afc/afcvolumemonitor.c
+++ b/monitor/afc/afcvolumemonitor.c
@@ -29,7 +29,15 @@ g_vfs_afc_monitor_create_volume (GVfsAfcVolumeMonitor *self,
 
   g_print ("creating volume for device uuid '%s'\n", uuid);
 
-  volume = g_vfs_afc_volume_new (G_VOLUME_MONITOR (self), uuid);
+  volume = g_vfs_afc_volume_new (G_VOLUME_MONITOR (self), uuid, NULL);
+  if (volume != NULL)
+    {
+      self->volumes = g_list_prepend (self->volumes, volume);
+      g_signal_emit_by_name (self, "volume-added", volume);
+    }
+
+  /* The house arrest service */
+  volume = g_vfs_afc_volume_new (G_VOLUME_MONITOR (self), uuid, HOUSE_ARREST_SERVICE_PORT);
   if (volume != NULL)
     {
       self->volumes = g_list_prepend (self->volumes, volume);
@@ -60,12 +68,14 @@ g_vfs_afc_monitor_remove_volume (GVfsAfcVolumeMonitor *self,
   GVfsAfcVolume *volume = NULL;
 
   volume = find_volume_by_uuid (self, uuid);
-  if (volume != NULL)
+  while (volume != NULL)
     {
       g_print ("removing volume for device uuid '%s'\n", uuid);
       self->volumes = g_list_remove (self->volumes, volume);
       g_signal_emit_by_name (self, "volume-removed", volume);
       g_object_unref (volume);
+
+      volume = find_volume_by_uuid (self, uuid);
     }
 }
 
diff --git a/monitor/afc/afcvolumemonitordaemon.c b/monitor/afc/afcvolumemonitordaemon.c
index 9c24a34..474a608 100644
--- a/monitor/afc/afcvolumemonitordaemon.c
+++ b/monitor/afc/afcvolumemonitordaemon.c
@@ -8,9 +8,10 @@
 #include <config.h>
 
 #include <glib.h>
-#include <glib/gi18n-lib.h>
+#include <glib/gi18n.h>
 #include <gmodule.h>
 #include <gio/gio.h>
+#include <locale.h>
 
 #include <gvfsproxyvolumemonitordaemon.h>
 
@@ -19,6 +20,12 @@
 int
 main (int argc, char *argv[])
 {
+  setlocale (LC_ALL, "");
+
+  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
   g_vfs_proxy_volume_monitor_daemon_init ();
   return g_vfs_proxy_volume_monitor_daemon_main (argc,
                                                  argv,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1bad2c5..3ece998 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -78,6 +78,7 @@ daemon/gvfsjobwrite.c
 daemon/main.c
 daemon/mount.c
 metadata/meta-daemon.c
+monitor/afc/afcvolume.c
 monitor/gdu/gdu-volume-monitor-daemon.c
 monitor/gdu/ggdudrive.c
 monitor/gdu/ggdumount.c



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