summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-14 14:21:53 +0200
committerGravatar Martin Szulecki2009-07-14 14:21:53 +0200
commita68a82800f116706354adb97da1ef0cfd3e38a52 (patch)
tree329e14aa6227cbe9bd04adfdbfa6c75866375b1e
parent5d047fd1e514e098308430fb59ba335b8ae3d385 (diff)
downloadlibimobiledevice-a68a82800f116706354adb97da1ef0cfd3e38a52.tar.gz
libimobiledevice-a68a82800f116706354adb97da1ef0cfd3e38a52.tar.bz2
Cleanup mobilesync API and bindings. Move get_all_contacts() into msyncclient.
-rwxr-xr-xdev/msync.py2
-rw-r--r--dev/msyncclient.c109
-rw-r--r--include/Makefile.am6
-rw-r--r--include/libiphone/libiphone.h9
-rw-r--r--src/MobileSync.c125
-rw-r--r--src/MobileSync.h8
-rw-r--r--swig/iphone.i15
7 files changed, 134 insertions, 140 deletions
diff --git a/dev/msync.py b/dev/msync.py
index 17e3121..fe7f1fd 100755
--- a/dev/msync.py
+++ b/dev/msync.py
@@ -12,7 +12,7 @@ def GetMobileSyncClient() :
if not lckd :
print "Failed to start lockdown service.\n"
return None
- msync = lckd.get_mobile_sync_client()
+ msync = lckd.get_mobilesync_client()
if not msync :
print "Failed to start mobilesync service.\n"
return None
diff --git a/dev/msyncclient.c b/dev/msyncclient.c
index e06a5fe..5eb105d 100644
--- a/dev/msyncclient.c
+++ b/dev/msyncclient.c
@@ -26,6 +26,107 @@
#include <libiphone/libiphone.h>
#include <libiphone/lockdown.h>
+#include <libiphone/mobilesync.h>
+
+static iphone_error_t mobilesync_get_all_contacts(mobilesync_client_t client)
+{
+ if (!client)
+ return IPHONE_E_INVALID_ARG;
+
+ iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
+ plist_t array = NULL;
+
+ array = plist_new_array();
+ plist_add_sub_string_el(array, "SDMessageSyncDataClassWithDevice");
+ plist_add_sub_string_el(array, "com.apple.Contacts");
+ plist_add_sub_string_el(array, "---");
+ plist_add_sub_string_el(array, "2009-01-09 18:03:58 +0100");
+ plist_add_sub_uint_el(array, 106);
+ plist_add_sub_string_el(array, "___EmptyParameterString___");
+
+ ret = mobilesync_send(client, array);
+ plist_free(array);
+ array = NULL;
+
+ ret = mobilesync_recv(client, &array);
+
+ plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow");
+
+ if (!rep_node)
+ return ret;
+
+ plist_free(array);
+ array = NULL;
+
+ array = plist_new_array();
+ plist_add_sub_string_el(array, "SDMessageGetAllRecordsFromDevice");
+ plist_add_sub_string_el(array, "com.apple.Contacts");
+
+
+ ret = mobilesync_send(client, array);
+ plist_free(array);
+ array = NULL;
+
+ ret = mobilesync_recv(client, &array);
+
+ plist_t contact_node;
+ plist_t switch_node;
+
+ contact_node = plist_find_node_by_string(array, "com.apple.Contacts");
+ switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges");
+
+ while (NULL == switch_node) {
+
+ plist_free(array);
+ array = NULL;
+
+ array = plist_new_array();
+ plist_add_sub_string_el(array, "SDMessageAcknowledgeChangesFromDevice");
+ plist_add_sub_string_el(array, "com.apple.Contacts");
+
+ ret = mobilesync_send(client, array);
+ plist_free(array);
+ array = NULL;
+
+ ret = mobilesync_recv(client, &array);
+
+ contact_node = plist_find_node_by_string(array, "com.apple.Contacts");
+ switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges");
+ }
+
+ array = plist_new_array();
+ plist_add_sub_string_el(array, "DLMessagePing");
+ plist_add_sub_string_el(array, "Preparing to get changes for device");
+
+ ret = mobilesync_send(client, array);
+ plist_free(array);
+ array = NULL;
+
+ array = plist_new_array();
+ plist_add_sub_string_el(array, "SDMessageProcessChanges");
+ plist_add_sub_string_el(array, "com.apple.Contacts");
+ plist_add_sub_node(array, plist_new_dict());
+ plist_add_sub_bool_el(array, 0);
+ plist_t dict = plist_new_dict();
+ plist_add_sub_node(array, dict);
+ plist_add_sub_key_el(dict, "SyncDeviceLinkEntityNamesKey");
+ plist_t array2 = plist_new_array();
+ plist_add_sub_string_el(array2, "com.apple.contacts.Contact");
+ plist_add_sub_string_el(array2, "com.apple.contacts.Group");
+ plist_add_sub_key_el(dict, "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey");
+ plist_add_sub_bool_el(dict, 0);
+
+ ret = mobilesync_send(client, array);
+ plist_free(array);
+ array = NULL;
+
+ ret = mobilesync_recv(client, &array);
+ plist_free(array);
+ array = NULL;
+
+
+ return ret;
+}
int main(int argc, char *argv[])
{
@@ -50,11 +151,11 @@ int main(int argc, char *argv[])
lockdownd_start_service(client, "com.apple.mobilesync", &port);
if (port) {
- iphone_msync_client_t msync = NULL;
- iphone_msync_new_client(phone, port, &msync);
+ mobilesync_client_t msync = NULL;
+ mobilesync_new_client(phone, port, &msync);
if (msync) {
- iphone_msync_get_all_contacts(msync);
- iphone_msync_free_client(msync);
+ mobilesync_get_all_contacts(msync);
+ mobilesync_free_client(msync);
}
} else {
printf("Start service failure.\n");
diff --git a/include/Makefile.am b/include/Makefile.am
index 98792de..df7b823 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1 +1,5 @@
-nobase_include_HEADERS = libiphone/libiphone.h libiphone/lockdown.h libiphone/afc.h libiphone/notification_proxy.h
+nobase_include_HEADERS = libiphone/libiphone.h \
+ libiphone/lockdown.h \
+ libiphone/afc.h \
+ libiphone/notification_proxy.h \
+ libiphone/mobilesync.h
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h
index 9e983bb..fa26d14 100644
--- a/include/libiphone/libiphone.h
+++ b/include/libiphone/libiphone.h
@@ -57,9 +57,6 @@ typedef int16_t iphone_error_t;
struct iphone_device_int;
typedef struct iphone_device_int *iphone_device_t;
-struct iphone_msync_client_int;
-typedef struct iphone_msync_client_int *iphone_msync_client_t;
-
//debug related functions
#define DBGMASK_ALL 0xFFFF
#define DBGMASK_NONE 0x0000
@@ -76,12 +73,6 @@ iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uu
iphone_error_t iphone_free_device(iphone_device_t device);
uint32_t iphone_get_device_handle(iphone_device_t device);
-iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
- iphone_msync_client_t * client);
-iphone_error_t iphone_msync_free_client(iphone_msync_client_t client);
-iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t *plist);
-iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist);
-
#ifdef __cplusplus
}
#endif
diff --git a/src/MobileSync.c b/src/MobileSync.c
index 7d6e947..b9a1cb0 100644
--- a/src/MobileSync.c
+++ b/src/MobileSync.c
@@ -29,8 +29,8 @@
#define MSYNC_VERSION_INT1 100
#define MSYNC_VERSION_INT2 100
-iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
- iphone_msync_client_t * client)
+iphone_error_t mobilesync_new_client(iphone_device_t device, int dst_port,
+ mobilesync_client_t * client)
{
if (!device || dst_port == 0 || !client || *client)
return IPHONE_E_INVALID_ARG;
@@ -43,14 +43,14 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
return ret;
}
- iphone_msync_client_t client_loc = (iphone_msync_client_t) malloc(sizeof(struct iphone_msync_client_int));
+ mobilesync_client_t client_loc = (mobilesync_client_t) malloc(sizeof(struct mobilesync_client_int));
client_loc->sfd = sfd;
//perform handshake
plist_t array = NULL;
//first receive version
- ret = iphone_msync_recv(client_loc, &array);
+ ret = mobilesync_recv(client_loc, &array);
plist_t msg_node = plist_find_node_by_string(array, "DLMessageVersionExchange");
plist_t ver_1 = plist_get_next_sibling(msg_node);
@@ -77,12 +77,12 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
plist_add_sub_string_el(array, "DLMessageVersionExchange");
plist_add_sub_string_el(array, "DLVersionsOk");
- ret = iphone_msync_send(client_loc, array);
+ ret = mobilesync_send(client_loc, array);
plist_free(array);
array = NULL;
- ret = iphone_msync_recv(client_loc, &array);
+ ret = mobilesync_recv(client_loc, &array);
plist_t rep_node = plist_find_node_by_string(array, "DLMessageDeviceReady");
if (rep_node) {
@@ -96,12 +96,12 @@ iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port,
}
if (IPHONE_E_SUCCESS != ret)
- iphone_msync_free_client(client_loc);
+ mobilesync_free_client(client_loc);
return ret;
}
-static void iphone_msync_stop_session(iphone_msync_client_t client)
+static void mobilesync_disconnect(mobilesync_client_t client)
{
if (!client)
return;
@@ -110,17 +110,17 @@ static void iphone_msync_stop_session(iphone_msync_client_t client)
plist_add_sub_string_el(array, "DLMessageDisconnect");
plist_add_sub_string_el(array, "All done, thanks for the memories");
- iphone_msync_send(client, array);
+ mobilesync_send(client, array);
plist_free(array);
array = NULL;
}
-iphone_error_t iphone_msync_free_client(iphone_msync_client_t client)
+iphone_error_t mobilesync_free_client(mobilesync_client_t client)
{
if (!client)
return IPHONE_E_INVALID_ARG;
- iphone_msync_stop_session(client);
+ mobilesync_disconnect(client);
return usbmuxd_disconnect(client->sfd);
}
@@ -131,7 +131,7 @@ iphone_error_t iphone_msync_free_client(iphone_msync_client_t client)
*
* @return an error code
*/
-iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist)
+iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist)
{
if (!client || !plist || (plist && *plist))
return IPHONE_E_INVALID_ARG;
@@ -177,7 +177,7 @@ iphone_error_t iphone_msync_recv(iphone_msync_client_t client, plist_t * plist)
*
* @return an error code
*/
-iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist)
+iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist)
{
if (!client || !plist)
return IPHONE_E_INVALID_ARG;
@@ -207,102 +207,3 @@ iphone_error_t iphone_msync_send(iphone_msync_client_t client, plist_t plist)
return ret;
}
-iphone_error_t iphone_msync_get_all_contacts(iphone_msync_client_t client)
-{
- if (!client)
- return IPHONE_E_INVALID_ARG;
-
- iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
- plist_t array = NULL;
-
- array = plist_new_array();
- plist_add_sub_string_el(array, "SDMessageSyncDataClassWithDevice");
- plist_add_sub_string_el(array, "com.apple.Contacts");
- plist_add_sub_string_el(array, "---");
- plist_add_sub_string_el(array, "2009-01-09 18:03:58 +0100");
- plist_add_sub_uint_el(array, 106);
- plist_add_sub_string_el(array, "___EmptyParameterString___");
-
- ret = iphone_msync_send(client, array);
- plist_free(array);
- array = NULL;
-
- ret = iphone_msync_recv(client, &array);
-
- plist_t rep_node = plist_find_node_by_string(array, "SDSyncTypeSlow");
-
- if (!rep_node)
- return ret;
-
- plist_free(array);
- array = NULL;
-
- array = plist_new_array();
- plist_add_sub_string_el(array, "SDMessageGetAllRecordsFromDevice");
- plist_add_sub_string_el(array, "com.apple.Contacts");
-
-
- ret = iphone_msync_send(client, array);
- plist_free(array);
- array = NULL;
-
- ret = iphone_msync_recv(client, &array);
-
- plist_t contact_node;
- plist_t switch_node;
-
- contact_node = plist_find_node_by_string(array, "com.apple.Contacts");
- switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges");
-
- while (NULL == switch_node) {
-
- plist_free(array);
- array = NULL;
-
- array = plist_new_array();
- plist_add_sub_string_el(array, "SDMessageAcknowledgeChangesFromDevice");
- plist_add_sub_string_el(array, "com.apple.Contacts");
-
- ret = iphone_msync_send(client, array);
- plist_free(array);
- array = NULL;
-
- ret = iphone_msync_recv(client, &array);
-
- contact_node = plist_find_node_by_string(array, "com.apple.Contacts");
- switch_node = plist_find_node_by_string(array, "SDMessageDeviceReadyToReceiveChanges");
- }
-
- array = plist_new_array();
- plist_add_sub_string_el(array, "DLMessagePing");
- plist_add_sub_string_el(array, "Preparing to get changes for device");
-
- ret = iphone_msync_send(client, array);
- plist_free(array);
- array = NULL;
-
- array = plist_new_array();
- plist_add_sub_string_el(array, "SDMessageProcessChanges");
- plist_add_sub_string_el(array, "com.apple.Contacts");
- plist_add_sub_node(array, plist_new_dict());
- plist_add_sub_bool_el(array, 0);
- plist_t dict = plist_new_dict();
- plist_add_sub_node(array, dict);
- plist_add_sub_key_el(dict, "SyncDeviceLinkEntityNamesKey");
- plist_t array2 = plist_new_array();
- plist_add_sub_string_el(array2, "com.apple.contacts.Contact");
- plist_add_sub_string_el(array2, "com.apple.contacts.Group");
- plist_add_sub_key_el(dict, "SyncDeviceLinkAllRecordsOfPulledEntityTypeSentKey");
- plist_add_sub_bool_el(dict, 0);
-
- ret = iphone_msync_send(client, array);
- plist_free(array);
- array = NULL;
-
- ret = iphone_msync_recv(client, &array);
- plist_free(array);
- array = NULL;
-
-
- return ret;
-}
diff --git a/src/MobileSync.h b/src/MobileSync.h
index 495e702..5279ce0 100644
--- a/src/MobileSync.h
+++ b/src/MobileSync.h
@@ -23,16 +23,12 @@
#include "iphone.h"
#include "utils.h"
+#include "libiphone/mobilesync.h"
#include <plist/plist.h>
-
-
-struct iphone_msync_client_int {
+struct mobilesync_client_int {
int sfd;
};
-
-iphone_error_t iphone_msync_get_all_contacts(iphone_msync_client_t client);
-
#endif
diff --git a/swig/iphone.i b/swig/iphone.i
index 25687f5..53fa8da 100644
--- a/swig/iphone.i
+++ b/swig/iphone.i
@@ -5,6 +5,7 @@
/* Includes the header in the wrapper code */
#include <libiphone/libiphone.h>
#include <libiphone/lockdown.h>
+ #include <libiphone/mobilesync.h>
#include <plist/plist.h>
#include "../src/utils.h"
typedef struct {
@@ -18,7 +19,7 @@
typedef struct {
iPhone* dev;
- iphone_msync_client_t client;
+ mobilesync_client_t client;
} MobileSync;
//now declare funtions to handle creation and deletion of objects
@@ -50,7 +51,7 @@ typedef struct {
typedef struct {
iPhone* dev;
- iphone_msync_client_t client;
+ mobilesync_client_t client;
} MobileSync;
%inline %{
@@ -93,7 +94,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) {
client = (MobileSync*) malloc(sizeof(MobileSync));
client->dev = lckd->dev;
client->client = NULL;
- iphone_msync_new_client ( lckd->dev->dev, port, &(client->client));
+ mobilesync_new_client ( lckd->dev->dev, port, &(client->client));
}
return client;
}
@@ -165,7 +166,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) {
return node;
}
- MobileSync* get_mobile_sync_client() {
+ MobileSync* get_mobilesync_client() {
return my_new_MobileSync($self);
}
};
@@ -176,18 +177,18 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) {
}
~MobileSync() {
- iphone_msync_free_client ( $self->client );
+ mobilesync_free_client ( $self->client );
free($self);
}
void send(PListNode* node) {
- iphone_msync_send($self->client, node->node);
+ mobilesync_send($self->client, node->node);
}
PListNode* receive() {
PListNode* node = (PListNode*)malloc(sizeof(PListNode));
node->node = NULL;
- iphone_msync_recv($self->client, &(node->node));
+ mobilesync_recv($self->client, &(node->node));
return node;
}
};