summaryrefslogtreecommitdiffstats
path: root/dev/msyncclient.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-07-14 14:21:53 +0200
committerGravatar Matt Colyer2009-07-18 10:39:42 -0700
commit484ff2166a2de58dd185a05fefea47a3f8165033 (patch)
treea8b6f712399369b60999dcd81c8bdbdd36c8ce8b /dev/msyncclient.c
parent5fa071717799ee2424c41b62360c7122b104fefb (diff)
downloadlibimobiledevice-484ff2166a2de58dd185a05fefea47a3f8165033.tar.gz
libimobiledevice-484ff2166a2de58dd185a05fefea47a3f8165033.tar.bz2
Cleanup mobilesync API and bindings. Move get_all_contacts() into msyncclient.
Diffstat (limited to 'dev/msyncclient.c')
-rw-r--r--dev/msyncclient.c109
1 files changed, 105 insertions, 4 deletions
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");