summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cython/Makefile.am10
-rw-r--r--cython/afc.pxi3
-rw-r--r--cython/imobiledevice.pxd7
-rw-r--r--cython/imobiledevice.pyx35
-rw-r--r--cython/installation_proxy.pxi2
-rw-r--r--cython/property_list_client.pxi12
-rw-r--r--cython/sbservices.pxi30
-rw-r--r--m4/ac_pkg_cython.m456
-rw-r--r--m4/cython_python.m47
9 files changed, 130 insertions, 32 deletions
diff --git a/cython/Makefile.am b/cython/Makefile.am
index 228ec0c..b1dea79 100644
--- a/cython/Makefile.am
+++ b/cython/Makefile.am
@@ -1,7 +1,7 @@
1AM_CPPFLAGS = -I$(top_srcdir)/include 1AM_CPPFLAGS = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusbmuxd_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) 4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6if HAVE_CYTHON 6if HAVE_CYTHON
7 7
@@ -30,9 +30,9 @@ EXTRA_DIST = imobiledevice.pyx imobiledevice.pxd $(PXIINCLUDES)
30imobiledevicedir = $(pyexecdir) 30imobiledevicedir = $(pyexecdir)
31imobiledevice_LTLIBRARIES = imobiledevice.la 31imobiledevice_LTLIBRARIES = imobiledevice.la
32imobiledevice_la_SOURCES = imobiledevice.pyx 32imobiledevice_la_SOURCES = imobiledevice.pyx
33imobiledevice_la_CFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/src $(PYTHON_CPPFLAGS) $(libglib2_CFLAGS) $(libgthread2_CFLAGS) 33imobiledevice_la_CFLAGS = -I../include -I../src $(PYTHON_CPPFLAGS) $(AM_CFLAGS)
34imobiledevice_la_LDFLAGS = -module -avoid-version $(PYTHON_LDFLAGS) $(libglib2_LIBS) $(libgthread2_LIBS) 34imobiledevice_la_LDFLAGS = -module -avoid-version -L$(libdir) $(PYTHON_LDFLAGS) $(AM_LDFLAGS)
35imobiledevice_la_LIBADD = $(top_builddir)/src/libimobiledevice.la 35imobiledevice_la_LIBADD = ../src/libimobiledevice.la
36 36
37imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES) 37imobiledevice.c: imobiledevice.pyx $(PXDINCLUDES) $(PXIINCLUDES)
38 38
diff --git a/cython/afc.pxi b/cython/afc.pxi
index ac9c927..1e2617a 100644
--- a/cython/afc.pxi
+++ b/cython/afc.pxi
@@ -66,9 +66,6 @@ cdef extern from "libimobiledevice/afc.h":
66 afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, char *target, char *linkname) 66 afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, char *target, char *linkname)
67 afc_error_t afc_set_file_time(afc_client_t client, char *path, uint64_t mtime) 67 afc_error_t afc_set_file_time(afc_client_t client, char *path, uint64_t mtime)
68 68
69cdef extern from *:
70 void free(void *ptr)
71
72cdef class AfcError(BaseError): 69cdef class AfcError(BaseError):
73 def __init__(self, *args, **kwargs): 70 def __init__(self, *args, **kwargs):
74 self._lookup_table = { 71 self._lookup_table = {
diff --git a/cython/imobiledevice.pxd b/cython/imobiledevice.pxd
index 8efd669..6bf75af 100644
--- a/cython/imobiledevice.pxd
+++ b/cython/imobiledevice.pxd
@@ -54,10 +54,5 @@ cdef extern from "libimobiledevice/lockdown.h":
54 54
55cdef class LockdownClient(Base): 55cdef class LockdownClient(Base):
56 cdef lockdownd_client_t _c_client 56 cdef lockdownd_client_t _c_client
57 cpdef int start_service(self, service) 57 cpdef int start_service(self, bytes service)
58 cpdef goodbye(self) 58 cpdef goodbye(self)
59
60cpdef set_debug_level(int level)
61cpdef event_subscribe(object callback)
62cpdef event_unsubscribe()
63cpdef get_device_list()
diff --git a/cython/imobiledevice.pyx b/cython/imobiledevice.pyx
index dc0fb88..b57db04 100644
--- a/cython/imobiledevice.pyx
+++ b/cython/imobiledevice.pyx
@@ -67,27 +67,40 @@ cdef class iDeviceError(BaseError):
67 } 67 }
68 BaseError.__init__(self, *args, **kwargs) 68 BaseError.__init__(self, *args, **kwargs)
69 69
70cpdef set_debug_level(int level): 70def set_debug_level(int level):
71 idevice_set_debug_level(level) 71 idevice_set_debug_level(level)
72 72
73cdef class iDeviceEvent: 73cdef class iDeviceEvent:
74 def __init__(self, *args, **kwargs): 74 def __init__(self, *args, **kwargs):
75 raise TypeError("iDeviceEvent cannot be instantiated") 75 raise TypeError("iDeviceEvent cannot be instantiated")
76 76
77cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data): 77 def __str__(self):
78 return 'iDeviceEvent: %s (%s)' % (self.event == IDEVICE_DEVICE_ADD and 'Add' or 'Remove', self.uuid)
79
80 property event:
81 def __get__(self):
82 return self._c_event.event
83 property uuid:
84 def __get__(self):
85 return self._c_event.uuid
86 property conn_type:
87 def __get__(self):
88 return self._c_event.conn_type
89
90cdef void idevice_event_cb(const_idevice_event_t c_event, void *user_data) with gil:
78 cdef iDeviceEvent event = iDeviceEvent.__new__(iDeviceEvent) 91 cdef iDeviceEvent event = iDeviceEvent.__new__(iDeviceEvent)
79 event._c_event = c_event 92 event._c_event = c_event
80 (<object>user_data)(event) 93 (<object>user_data)(event)
81 94
82cpdef event_subscribe(object callback): 95def event_subscribe(object callback):
83 cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback)) 96 cdef iDeviceError err = iDeviceError(idevice_event_subscribe(idevice_event_cb, <void*>callback))
84 if err: raise err 97 if err: raise err
85 98
86cpdef event_unsubscribe(): 99def event_unsubscribe():
87 cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe()) 100 cdef iDeviceError err = iDeviceError(idevice_event_unsubscribe())
88 if err: raise err 101 if err: raise err
89 102
90cpdef get_device_list(): 103def get_device_list():
91 cdef: 104 cdef:
92 char** devices 105 char** devices
93 int count 106 int count
@@ -214,10 +227,14 @@ cdef class LockdownError(BaseError):
214 BaseError.__init__(self, *args, **kwargs) 227 BaseError.__init__(self, *args, **kwargs)
215 228
216cdef class LockdownClient(Base): 229cdef class LockdownClient(Base):
217 def __cinit__(self, iDevice device not None, char *label=NULL, *args, **kwargs): 230 def __cinit__(self, iDevice device not None, bytes label="", *args, **kwargs):
218 cdef: 231 cdef:
219 iDevice dev = device 232 iDevice dev = device
220 lockdownd_error_t err = lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), label) 233 lockdownd_error_t err
234 char* c_label = NULL
235 if label:
236 c_label = label
237 err = lockdownd_client_new_with_handshake(dev._c_dev, &(self._c_client), c_label)
221 self.handle_error(err) 238 self.handle_error(err)
222 239
223 def __dealloc__(self): 240 def __dealloc__(self):
@@ -229,7 +246,7 @@ cdef class LockdownClient(Base):
229 cdef inline BaseError _error(self, int16_t ret): 246 cdef inline BaseError _error(self, int16_t ret):
230 return LockdownError(ret) 247 return LockdownError(ret)
231 248
232 cpdef int start_service(self, service): 249 cpdef int start_service(self, bytes service):
233 cdef: 250 cdef:
234 uint16_t port 251 uint16_t port
235 lockdownd_error_t err 252 lockdownd_error_t err
@@ -242,6 +259,8 @@ cdef class LockdownClient(Base):
242 259
243cdef extern from *: 260cdef extern from *:
244 ctypedef char* const_char_ptr "const char*" 261 ctypedef char* const_char_ptr "const char*"
262 void free(void *ptr)
263 void plist_free(plist.plist_t node)
245 264
246include "property_list_client.pxi" 265include "property_list_client.pxi"
247include "mobilesync.pxi" 266include "mobilesync.pxi"
diff --git a/cython/installation_proxy.pxi b/cython/installation_proxy.pxi
index 22e7e38..a8083d3 100644
--- a/cython/installation_proxy.pxi
+++ b/cython/installation_proxy.pxi
@@ -26,7 +26,7 @@ cdef extern from "libimobiledevice/installation_proxy.h":
26 instproxy_error_t instproxy_restore(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) 26 instproxy_error_t instproxy_restore(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)
27 instproxy_error_t instproxy_remove_archive(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data) 27 instproxy_error_t instproxy_remove_archive(instproxy_client_t client, char *appid, plist.plist_t client_options, instproxy_status_cb_t status_cb, void *user_data)
28 28
29cdef void instproxy_notify_cb(const_char_ptr operation, plist.plist_t status, void *py_callback): 29cdef void instproxy_notify_cb(const_char_ptr operation, plist.plist_t status, void *py_callback) with gil:
30 (<object>py_callback)(operation, plist.plist_t_to_node(status, False)) 30 (<object>py_callback)(operation, plist.plist_t_to_node(status, False))
31 31
32cdef class InstallationProxyError(BaseError): 32cdef class InstallationProxyError(BaseError):
diff --git a/cython/property_list_client.pxi b/cython/property_list_client.pxi
index 874f2b5..2f9ce76 100644
--- a/cython/property_list_client.pxi
+++ b/cython/property_list_client.pxi
@@ -4,8 +4,16 @@ cdef class PropertyListClient(Base):
4 self.handle_error(self._send(n._c_node)) 4 self.handle_error(self._send(n._c_node))
5 5
6 cpdef object receive(self): 6 cpdef object receive(self):
7 cdef plist.plist_t c_node = NULL 7 cdef:
8 self.handle_error(self._receive(&c_node)) 8 plist.plist_t c_node = NULL
9 int16_t err
10 err = self._receive(&c_node)
11 try:
12 self.handle_error(err)
13 except BaseError, e:
14 if c_node != NULL:
15 plist_free(c_node)
16 raise
9 17
10 return plist.plist_t_to_node(c_node) 18 return plist.plist_t_to_node(c_node)
11 19
diff --git a/cython/sbservices.pxi b/cython/sbservices.pxi
index f458bec..6eece0a 100644
--- a/cython/sbservices.pxi
+++ b/cython/sbservices.pxi
@@ -29,14 +29,16 @@ cdef class SpringboardServicesClient(Base):
29 cdef sbservices_client_t _c_client 29 cdef sbservices_client_t _c_client
30 30
31 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs): 31 def __cinit__(self, iDevice device not None, LockdownClient lockdown=None, *args, **kwargs):
32 cdef iDevice dev = device 32 cdef:
33 cdef LockdownClient lckd 33 iDevice dev = device
34 LockdownClient lckd
34 if lockdown is None: 35 if lockdown is None:
35 lckd = LockdownClient(dev) 36 lckd = LockdownClient(dev)
36 else: 37 else:
37 lckd = lockdown 38 lckd = lockdown
38 port = lockdown.start_service("com.apple.springboardservices") 39 port = lckd.start_service("com.apple.springboardservices")
39 self.handle_error(sbservices_client_new(dev._c_dev, port, &(self._c_client))) 40 err = SpringboardServicesError(sbservices_client_new(dev._c_dev, port, &(self._c_client)))
41 if err: raise err
40 42
41 def __dealloc__(self): 43 def __dealloc__(self):
42 if self._c_client is not NULL: 44 if self._c_client is not NULL:
@@ -51,7 +53,14 @@ cdef class SpringboardServicesClient(Base):
51 cdef: 53 cdef:
52 plist.plist_t c_node = NULL 54 plist.plist_t c_node = NULL
53 plist.Node node 55 plist.Node node
54 self.handle_error(sbservices_get_icon_state(self._c_client, &c_node)) 56 sbservices_error_t err
57 err = sbservices_get_icon_state(self._c_client, &c_node)
58 try:
59 self.handle_error(err)
60 except BaseError, e:
61 if c_node != NULL:
62 plist_free(c_node)
63 raise
55 node = plist.plist_t_to_node(c_node) 64 node = plist.plist_t_to_node(c_node)
56 return node 65 return node
57 def __set__(self, plist.Node newstate not None): 66 def __set__(self, plist.Node newstate not None):
@@ -63,6 +72,13 @@ cdef class SpringboardServicesClient(Base):
63 bytes result 72 bytes result
64 char* pngdata = NULL 73 char* pngdata = NULL
65 uint64_t pngsize 74 uint64_t pngsize
66 self.handle_error(sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)) 75 sbservices_error_t err
67 result = pngdata[:pngsize] 76 err = sbservices_get_icon_pngdata(self._c_client, bundleId, &pngdata, &pngsize)
77 try:
78 self.handle_error(err)
79 except BaseError, e:
80 raise
81 finally:
82 result = pngdata[:pngsize]
83 free(pngdata)
68 return result 84 return result
diff --git a/m4/ac_pkg_cython.m4 b/m4/ac_pkg_cython.m4
new file mode 100644
index 0000000..aeae6a0
--- /dev/null
+++ b/m4/ac_pkg_cython.m4
@@ -0,0 +1,56 @@
1
2AC_DEFUN([AC_PROG_CYTHON],[
3 AC_PATH_PROG([CYTHON],[cython])
4 if test -z "$CYTHON" ; then
5 AC_MSG_WARN([cannot find 'cython' program. You should look at http://www.cython.org] or install your distribution specific cython package.)
6 CYTHON=false
7 elif test -n "$1" ; then
8 AC_MSG_CHECKING([for Cython version])
9 [cython_version=`$CYTHON --version 2>&1 | grep 'Cython version' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
10 AC_MSG_RESULT([$cython_version])
11 if test -n "$cython_version" ; then
12 # Calculate the required version number components
13 [required=$1]
14 [required_major=`echo $required | sed 's/[^0-9].*//'`]
15 if test -z "$required_major" ; then
16 [required_major=0]
17 fi
18 [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
19 [required_minor=`echo $required | sed 's/[^0-9].*//'`]
20 if test -z "$required_minor" ; then
21 [required_minor=0]
22 fi
23 [required=`echo $required | sed 's/[0-9]*[^0-9]//'`]
24 [required_patch=`echo $required | sed 's/[^0-9].*//'`]
25 if test -z "$required_patch" ; then
26 [required_patch=0]
27 fi
28 # Calculate the available version number components
29 [available=$cython_version]
30 [available_major=`echo $available | sed 's/[^0-9].*//'`]
31 if test -z "$available_major" ; then
32 [available_major=0]
33 fi
34 [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
35 [available_minor=`echo $available | sed 's/[^0-9].*//'`]
36 if test -z "$available_minor" ; then
37 [available_minor=0]
38 fi
39 [available=`echo $available | sed 's/[0-9]*[^0-9]//'`]
40 [available_patch=`echo $available | sed 's/[^0-9].*//'`]
41 if test -z "$available_patch" ; then
42 [available_patch=0]
43 fi
44 if test $available_major -ne $required_major \
45 -o $available_minor -ne $required_minor \
46 -o $available_patch -lt $required_patch ; then
47 AC_MSG_WARN([Cython version >= $1 is required. You have $cython_version. You should look at http://www.cython.org])
48 CYTHON=false
49 fi
50 else
51 AC_MSG_WARN([cannot determine Cython version])
52 CYTHON=false
53 fi
54 fi
55 AC_SUBST([CYTHON_LIB])
56])
diff --git a/m4/cython_python.m4 b/m4/cython_python.m4
new file mode 100644
index 0000000..ba730d5
--- /dev/null
+++ b/m4/cython_python.m4
@@ -0,0 +1,7 @@
1AC_DEFUN([CYTHON_PYTHON],[
2 AC_REQUIRE([AC_PROG_CYTHON])
3 AC_REQUIRE([AC_PYTHON_DEVEL])
4 test "x$1" != "xno" || cython_shadow=" -noproxy"
5 AC_SUBST([CYTHON_PYTHON_OPT],[-python$cython_shadow])
6 AC_SUBST([CYTHON_PYTHON_CPPFLAGS],[$PYTHON_CPPFLAGS])
7])