commit d89fb52186f83ab277cc3609c6d46d3b35794876
Author: Martin Szulecki <[email protected]>
Date:   Sat Jul 18 12:34:21 2009 +0200

    Retrieve extended information from iPhone/iPod Touch devices in HAL callout

 tools/Makefile.am     |   45 +++++++++++++++++--------
 tools/hal-callout.c   |   41 +++++++++++++++++++---
 tools/ipod-lockdown.c |   87 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 153 insertions(+), 20 deletions(-)
---
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 2d985e0..efc4591 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,39 +1,56 @@
 if HAVE_SGUTILS
-
 bin_PROGRAMS=ipod-read-sysinfo-extended
-
 ipod_read_sysinfo_extended_SOURCES =   \
        read-sysinfoextended-sgutils.c  \
        ipod-scsi.c
 ipod_read_sysinfo_extended_CFLAGS=$(LIBGPOD_CFLAGS) $(SGUTILS_CFLAGS) 
-I$(top_srcdir)/src
 ipod_read_sysinfo_extended_LDADD=$(LIBGPOD_LIBS) $(SGUTILS_LIBS) 
$(top_builddir)/src/libgpod.la
+endif
 
 if HAVE_HAL
 haldir = $(HALCALLOUTSDIR)
 hal_PROGRAMS = libgpod-callout
-noinst_PROGRAMS=ipod-time-sync
-
 libgpod_callout_SOURCES =                                      \
        hal-callout.c                                           \
        $(top_srcdir)/src/itdb_sysinfo_extended_parser.c        \
-       $(top_srcdir)/src/itdb_plist.c                          \
-       ipod-scsi.c
-libgpod_callout_CFLAGS=$(LIBGPOD_CFLAGS) $(HAL_CFLAGS) $(SGUTILS_CFLAGS) 
-I$(top_srcdir)/src
-#libgpod_callout_LDADD=$(LIBGPOD_LIBS) $(HAL_LIBS) $(SGUTILS_LIBS) 
-libgpod_callout_LDADD=$(top_builddir)/src/libgpod.la $(LIBGPOD_LIBS) 
$(HAL_LIBS) $(SGUTILS_LIBS) 
+       $(top_srcdir)/src/itdb_plist.c
 
-ipod_time_sync_SOURCES =       \
-       ipod-time-sync.c        \
-       ipod-scsi.c
-ipod_time_sync_CFLAGS=$(SGUTILS_CFLAGS) $(LIBGPOD_CFLAGS) 
-ipod_time_sync_LDADD=$(SGUTILS_LIBS) $(LIBGPOD_LIBS) 
+libgpod_callout_CFLAGS =                                               \
+       $(LIBGPOD_CFLAGS)                                       \
+       $(HAL_CFLAGS)                                           \
+       -I$(top_srcdir)/src
+
+#libgpod_callout_LDADD=$(LIBGPOD_LIBS) $(HAL_LIBS) $(SGUTILS_LIBS) 
+libgpod_callout_LDADD =                                                \
+       $(top_builddir)/src/libgpod.la                          \
+       $(LIBGPOD_LIBS)                                         \
+       $(HAL_LIBS)
 
 fdidir = $(HALFDIDIR)/policy/20thirdparty
 fdi_DATA = 20-libgpod-sysinfo-extended.fdi
 
 EXTRA_DIST = $(fdi_DATA)
 
+if HAVE_LIBIPHONE
+libgpod_callout_SOURCES += ipod-lockdown.c
+libgpod_callout_CFLAGS += $(LIBIPHONE_CFLAGS)
+libgpod_callout_LDADD += $(LIBIPHONE_LIBS)
+endif
+
+if HAVE_SGUTILS
+libgpod_callout_SOURCES += ipod-scsi.c
+libgpod_callout_CFLAGS += $(SGUTILS_CFLAGS)
+libgpod_callout_LDADD += $(SGUTILS_LIBS)
 endif
 
 endif
 
+if HAVE_SGUTILS
+noinst_PROGRAMS=ipod-time-sync
+ipod_time_sync_SOURCES =       \
+       ipod-time-sync.c        \
+       ipod-scsi.c
+ipod_time_sync_CFLAGS=$(SGUTILS_CFLAGS) $(LIBGPOD_CFLAGS) 
+ipod_time_sync_LDADD=$(SGUTILS_LIBS) $(LIBGPOD_LIBS) 
+endif
+
diff --git a/tools/hal-callout.c b/tools/hal-callout.c
index 77d8cee..2ad9f02 100644
--- a/tools/hal-callout.c
+++ b/tools/hal-callout.c
@@ -41,7 +41,12 @@
 #include <sys/mount.h>
 #include <itdb.h>
 #include <itdb_device.h>
+#ifdef HAVE_SGUTILS
 extern char *read_sysinfo_extended (const char *device);
+#endif
+#ifdef HAVE_LIBIPHONE
+extern char *read_sysinfo_extended_by_uuid (const char *uuid);
+#endif
 
 struct _ProductionInfo {
        gchar *factory_id;
@@ -750,19 +755,43 @@ static gboolean write_sysinfo_extended (const char 
*mountpoint,
 
 int main (int argc, char **argv)
 {
-        char *ipod_mountpoint;
-        char *xml;
+       char *ipod_mountpoint = NULL;
+       char *xml = NULL;
        SysInfoIpodProperties *props;
-        LibHalContext *ctx; 
-        const char *udi;
+       LibHalContext *ctx; 
+       const char *udi;
+#ifdef HAVE_LIBIPHONE
+       char *caps = NULL;
+#endif
 
        g_type_init ();
 
-        xml = read_sysinfo_extended (g_getenv ("HAL_PROP_BLOCK_DEVICE"));
+#ifdef HAVE_LIBIPHONE
+        caps = (char *)g_getenv ("HAL_PROP_INFO_CAPABILITIES");
+        if (caps == NULL) {
+                return -1;
+        }
+        else
+        {
+                /* iPhone/iPod Touch devices with custom usb protocol */
+                if (strstr (caps, "afc") != NULL) {
+                        xml = read_sysinfo_extended_by_uuid(g_getenv 
("HAL_PROP_USB_SERIAL"));
+                }
+                else /* regular usb mass storage ipod */
+                {
+#endif
+#ifdef HAVE_SGUTILS
+                        xml = read_sysinfo_extended (g_getenv 
("HAL_PROP_BLOCK_DEVICE"));
+#else
+                        return -1;
+#endif
+#ifdef HAVE_LIBIPHONE
+                }
+        }
+#endif
         if (xml == NULL) {
                 return -1;
         }
-
         props = itdb_sysinfo_extended_parse_from_xml (xml, NULL);
 
         ctx = hal_ipod_initialize ();
diff --git a/tools/ipod-lockdown.c b/tools/ipod-lockdown.c
new file mode 100644
index 0000000..6253239
--- /dev/null
+++ b/tools/ipod-lockdown.c
@@ -0,0 +1,87 @@
+/* Copyright (c) 2009, Martin S. <[email protected]>
+ * 
+ * The code contained in this file 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.1 of the License, or (at your option) any later version.
+ *
+ * This file 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 code; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * iTunes and iPod are trademarks of Apple
+ *
+ * This product is not supported/written/published by Apple!
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <glib.h>
+
+#include <libiphone/libiphone.h>
+#include <libiphone/lockdown.h>
+
+extern char *read_sysinfo_extended_by_uuid (const char *uuid);
+
+char *
+read_sysinfo_extended_by_uuid (const char *uuid)
+{
+       lockdownd_client_t client = NULL;
+       iphone_device_t device = NULL;
+       iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+       char *xml = NULL; char *str = NULL;
+       uint32_t xml_length = 0;
+       plist_t value = NULL;
+       plist_t global = NULL;
+       plist_t ptr = NULL;
+
+       ret = iphone_get_device_by_uuid(&device, uuid);
+       if (ret != IPHONE_E_SUCCESS) {
+               printf("No device found with uuid %s, is it plugged in?\n", 
uuid);
+               return NULL;
+       }
+
+       if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(device, &client)) {
+               iphone_device_free(device);
+               return NULL;
+       }
+
+       /* run query and get format plist */
+       lockdownd_get_value(client, NULL, NULL, &global);
+       lockdownd_get_value(client, "com.apple.mobile.iTunes", NULL, &value);
+       
+       /* add some required values manually to emulate old plist format */
+       ptr = plist_get_dict_el_from_key(global, "SerialNumber");
+       plist_add_sub_key_el(value, "SerialNumber");
+       plist_get_string_val(ptr, &str);
+       plist_add_sub_string_el(value, str);
+
+       ptr = plist_get_dict_el_from_key(global, "BuildVersion");
+       plist_add_sub_key_el(value, "BuildID");
+       plist_get_string_val(ptr, &str);
+       plist_add_sub_string_el(value, str);
+
+       plist_to_xml(value, &xml, &xml_length);
+
+       ptr = NULL;
+       if (value)
+               plist_free(value);
+       value = NULL;
+       if (global)
+               plist_free(global);
+       global = NULL;
+
+       lockdownd_client_free(client);
+       iphone_device_free(device);
+
+       return xml;
+}

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
gtkpod-cvs2 mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to