summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2010-01-26 02:18:36 +0100
committerGravatar Martin Szulecki2010-01-26 02:18:36 +0100
commit135a69205083b8b499147eb8f34baf586e76bb49 (patch)
treee9fa13ca2662961af57095d38fe4231faba09fa4 /src
parent57c883b7fe84d513c836270f681a9bf5a907de3e (diff)
parentb369efa426307bb6e9828c755ccc50c4f213c2e8 (diff)
downloadlibimobiledevice-135a69205083b8b499147eb8f34baf586e76bb49.tar.gz
libimobiledevice-135a69205083b8b499147eb8f34baf586e76bb49.tar.bz2
Merge branch 'mobilebackup' into martin
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/device_link_service.c20
-rw-r--r--src/device_link_service.h1
-rw-r--r--src/mobilebackup.c131
-rw-r--r--src/mobilebackup.h31
-rw-r--r--src/mobilesync.c18
6 files changed, 185 insertions, 19 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index f68f579..93cfbaf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,4 +15,5 @@ libiphone_la_SOURCES = iphone.c iphone.h \
15 notification_proxy.c notification_proxy.h\ 15 notification_proxy.c notification_proxy.h\
16 installation_proxy.c installation_proxy.h\ 16 installation_proxy.c installation_proxy.h\
17 sbservices.c sbservices.h\ 17 sbservices.c sbservices.h\
18 mobilesync.c mobilesync.h 18 mobilesync.c mobilesync.h\
19 mobilebackup.c mobilebackup.h
diff --git a/src/device_link_service.c b/src/device_link_service.c
index b7d9ee8..9998fd0 100644
--- a/src/device_link_service.c
+++ b/src/device_link_service.c
@@ -253,6 +253,26 @@ device_link_service_error_t device_link_service_disconnect(device_link_service_c
253 return err; 253 return err;
254} 254}
255 255
256device_link_service_error_t device_link_service_process_message(device_link_service_client_t client, plist_t message)
257{
258 if (!client || !message)
259 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
260
261 if (plist_get_node_type(message) != PLIST_DICT)
262 return DEVICE_LINK_SERVICE_E_INVALID_ARG;
263
264 plist_t array = plist_new_array();
265 plist_array_append_item(array, plist_new_string("DLMessageProcessMessage"));
266 plist_array_append_item(array, message);
267
268 device_link_service_error_t err = DEVICE_LINK_SERVICE_E_SUCCESS;
269 if (property_list_service_send_binary_plist(client->parent, array) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
270 err = DEVICE_LINK_SERVICE_E_MUX_ERROR;
271 }
272 plist_free(array);
273 return err;
274}
275
256/** 276/**
257 * Generic device link service send function. 277 * Generic device link service send function.
258 * 278 *
diff --git a/src/device_link_service.h b/src/device_link_service.h
index e14d897..8345d57 100644
--- a/src/device_link_service.h
+++ b/src/device_link_service.h
@@ -44,6 +44,7 @@ typedef int16_t device_link_service_error_t;
44device_link_service_error_t device_link_service_client_new(iphone_device_t device, uint16_t port, device_link_service_client_t *client); 44device_link_service_error_t device_link_service_client_new(iphone_device_t device, uint16_t port, device_link_service_client_t *client);
45device_link_service_error_t device_link_service_client_free(device_link_service_client_t client); 45device_link_service_error_t device_link_service_client_free(device_link_service_client_t client);
46device_link_service_error_t device_link_service_version_exchange(device_link_service_client_t client, uint64_t version_major, uint64_t version_minor); 46device_link_service_error_t device_link_service_version_exchange(device_link_service_client_t client, uint64_t version_major, uint64_t version_minor);
47device_link_service_error_t device_link_service_process_message(device_link_service_client_t client, plist_t message);
47device_link_service_error_t device_link_service_disconnect(device_link_service_client_t client); 48device_link_service_error_t device_link_service_disconnect(device_link_service_client_t client);
48device_link_service_error_t device_link_service_send(device_link_service_client_t client, plist_t plist); 49device_link_service_error_t device_link_service_send(device_link_service_client_t client, plist_t plist);
49device_link_service_error_t device_link_service_receive(device_link_service_client_t client, plist_t *plist); 50device_link_service_error_t device_link_service_receive(device_link_service_client_t client, plist_t *plist);
diff --git a/src/mobilebackup.c b/src/mobilebackup.c
new file mode 100644
index 0000000..5b81c7f
--- /dev/null
+++ b/src/mobilebackup.c
@@ -0,0 +1,131 @@
1/*
2 * mobilebackup.c
3 * Contains functions for the built-in MobileBackup client.
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <plist/plist.h>
23#include <string.h>
24#include <stdlib.h>
25#include <arpa/inet.h>
26
27#include "mobilebackup.h"
28#include "device_link_service.h"
29#include "debug.h"
30
31#define MBACKUP_VERSION_INT1 100
32#define MBACKUP_VERSION_INT2 0
33
34/**
35 * Convert an device_link_service_error_t value to an mobilebackup_error_t value.
36 * Used internally to get correct error codes when using device_link_service stuff.
37 *
38 * @param err An device_link_service_error_t error code
39 *
40 * @return A matching mobilebackup_error_t error code,
41 * MOBILEBACKUP_E_UNKNOWN_ERROR otherwise.
42 */
43static mobilebackup_error_t mobilebackup_error(device_link_service_error_t err)
44{
45 switch (err) {
46 case DEVICE_LINK_SERVICE_E_SUCCESS:
47 return MOBILEBACKUP_E_SUCCESS;
48 case DEVICE_LINK_SERVICE_E_INVALID_ARG:
49 return MOBILEBACKUP_E_INVALID_ARG;
50 case DEVICE_LINK_SERVICE_E_PLIST_ERROR:
51 return MOBILEBACKUP_E_PLIST_ERROR;
52 case DEVICE_LINK_SERVICE_E_MUX_ERROR:
53 return MOBILEBACKUP_E_MUX_ERROR;
54 case DEVICE_LINK_SERVICE_E_BAD_VERSION:
55 return MOBILEBACKUP_E_BAD_VERSION;
56 default:
57 break;
58 }
59 return MOBILEBACKUP_E_UNKNOWN_ERROR;
60}
61
62mobilebackup_error_t mobilebackup_client_new(iphone_device_t device, uint16_t port,
63 mobilebackup_client_t * client)
64{
65 if (!device || port == 0 || !client || *client)
66 return MOBILEBACKUP_E_INVALID_ARG;
67
68 device_link_service_client_t dlclient = NULL;
69 mobilebackup_error_t ret = mobilebackup_error(device_link_service_client_new(device, port, &dlclient));
70 if (ret != MOBILEBACKUP_E_SUCCESS) {
71 return ret;
72 }
73
74 mobilebackup_client_t client_loc = (mobilebackup_client_t) malloc(sizeof(struct mobilebackup_client_int));
75 client_loc->parent = dlclient;
76
77 /* perform handshake */
78 ret = mobilebackup_error(device_link_service_version_exchange(dlclient, MBACKUP_VERSION_INT1, MBACKUP_VERSION_INT2));
79 if (ret != MOBILEBACKUP_E_SUCCESS) {
80 debug_info("version exchange failed, error %d", ret);
81 mobilebackup_client_free(client_loc);
82 return ret;
83 }
84
85 *client = client_loc;
86
87 return ret;
88}
89
90mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client)
91{
92 if (!client)
93 return MOBILEBACKUP_E_INVALID_ARG;
94 device_link_service_disconnect(client->parent);
95 mobilebackup_error_t err = mobilebackup_error(device_link_service_client_free(client->parent));
96 free(client);
97 return err;
98}
99
100/** Polls the iPhone for MobileBackup data.
101 *
102 * @param client The MobileBackup client
103 * @param plist A pointer to the location where the plist should be stored
104 *
105 * @return an error code
106 */
107mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t * plist)
108{
109 if (!client)
110 return MOBILEBACKUP_E_INVALID_ARG;
111 mobilebackup_error_t ret = mobilebackup_error(device_link_service_receive(client->parent, plist));
112 return ret;
113}
114
115/** Sends MobileBackup data to the iPhone
116 *
117 * @note This function is low-level and should only be used if you need to send
118 * a new type of message.
119 *
120 * @param client The MobileBackup client
121 * @param plist The location of the plist to send
122 *
123 * @return an error code
124 */
125mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist)
126{
127 if (!client || !plist)
128 return MOBILEBACKUP_E_INVALID_ARG;
129 return mobilebackup_error(device_link_service_send(client->parent, plist));
130}
131
diff --git a/src/mobilebackup.h b/src/mobilebackup.h
new file mode 100644
index 0000000..04ebc45
--- /dev/null
+++ b/src/mobilebackup.h
@@ -0,0 +1,31 @@
1 /*
2 * mobilebackup.h
3 * Definitions for the mobilebackup service
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21#ifndef MOBILEBACKUP_H
22#define MOBILEBACKUP_H
23
24#include "libiphone/mobilebackup.h"
25#include "device_link_service.h"
26
27struct mobilebackup_client_int {
28 device_link_service_client_t parent;
29};
30
31#endif
diff --git a/src/mobilesync.c b/src/mobilesync.c
index 3492673..15614b5 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -109,16 +109,6 @@ mobilesync_error_t mobilesync_receive(mobilesync_client_t client, plist_t * plis
109 if (!client) 109 if (!client)
110 return MOBILESYNC_E_INVALID_ARG; 110 return MOBILESYNC_E_INVALID_ARG;
111 mobilesync_error_t ret = mobilesync_error(device_link_service_receive(client->parent, plist)); 111 mobilesync_error_t ret = mobilesync_error(device_link_service_receive(client->parent, plist));
112#ifndef STRIP_DEBUG_CODE
113 if (ret != MOBILESYNC_E_SUCCESS) {
114 return ret;
115 }
116 char *XMLContent = NULL;
117 uint32_t length = 0;
118 plist_to_xml(*plist, &XMLContent, &length);
119 debug_info("plist size: %i\nbuffer :\n%s", length, XMLContent);
120 free(XMLContent);
121#endif
122 return ret; 112 return ret;
123} 113}
124 114
@@ -136,13 +126,5 @@ mobilesync_error_t mobilesync_send(mobilesync_client_t client, plist_t plist)
136{ 126{
137 if (!client || !plist) 127 if (!client || !plist)
138 return MOBILESYNC_E_INVALID_ARG; 128 return MOBILESYNC_E_INVALID_ARG;
139
140#ifndef STRIP_DEBUG_CODE
141 char *XMLContent = NULL;
142 uint32_t length = 0;
143 plist_to_xml(plist, &XMLContent, &length);
144 debug_info("plist size: %i\nbuffer :\n%s", length, XMLContent);
145 free(XMLContent);
146#endif
147 return mobilesync_error(device_link_service_send(client->parent, plist)); 129 return mobilesync_error(device_link_service_send(client->parent, plist));
148} 130}