summaryrefslogtreecommitdiffstats
path: root/src/property_list_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/property_list_service.c')
-rw-r--r--src/property_list_service.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/property_list_service.c b/src/property_list_service.c
index 15adbc8..025a9bc 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -25,27 +25,28 @@
25#include <string.h> 25#include <string.h>
26 26
27#include "property_list_service.h" 27#include "property_list_service.h"
28#include "idevice.h"
29#include "debug.h" 28#include "debug.h"
30#include "endianness.h" 29#include "endianness.h"
31 30
32/** 31/**
33 * Convert an idevice_error_t value to an property_list_service_error_t value. 32 * Convert a service_error_t value to a property_list_service_error_t value.
34 * Used internally to get correct error codes. 33 * Used internally to get correct error codes.
35 * 34 *
36 * @param err An idevice_error_t error code 35 * @param err A service_error_t error code
37 * 36 *
38 * @return A matching property_list_service_error_t error code, 37 * @return A matching property_list_service_error_t error code,
39 * PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise. 38 * PROPERTY_LIST_SERVICE_E_UNKNOWN_ERROR otherwise.
40 */ 39 */
41static property_list_service_error_t idevice_to_property_list_service_error(idevice_error_t err) 40static property_list_service_error_t service_to_property_list_service_error(service_error_t err)
42{ 41{
43 switch (err) { 42 switch (err) {
44 case IDEVICE_E_SUCCESS: 43 case SERVICE_E_SUCCESS:
45 return PROPERTY_LIST_SERVICE_E_SUCCESS; 44 return PROPERTY_LIST_SERVICE_E_SUCCESS;
46 case IDEVICE_E_INVALID_ARG: 45 case SERVICE_E_INVALID_ARG:
47 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 46 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
48 case IDEVICE_E_SSL_ERROR: 47 case SERVICE_E_MUX_ERROR:
48 return PROPERTY_LIST_SERVICE_E_MUX_ERROR;
49 case SERVICE_E_SSL_ERROR:
49 return PROPERTY_LIST_SERVICE_E_SSL_ERROR; 50 return PROPERTY_LIST_SERVICE_E_SSL_ERROR;
50 default: 51 default:
51 break; 52 break;
@@ -70,19 +71,15 @@ property_list_service_error_t property_list_service_client_new(idevice_t device,
70 if (!device || (service->port == 0) || !client || *client) 71 if (!device || (service->port == 0) || !client || *client)
71 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 72 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
72 73
73 /* Attempt connection */ 74 service_client_t parent = NULL;
74 idevice_connection_t connection = NULL; 75 service_error_t rerr = service_client_new(device, service, &parent);
75 if (idevice_connect(device, service->port, &connection) != IDEVICE_E_SUCCESS) { 76 if (rerr != SERVICE_E_SUCCESS) {
76 return PROPERTY_LIST_SERVICE_E_MUX_ERROR; 77 return service_to_property_list_service_error(rerr);
77 } 78 }
78 79
79 /* create client object */ 80 /* create client object */
80 property_list_service_client_t client_loc = (property_list_service_client_t)malloc(sizeof(struct property_list_service_client_private)); 81 property_list_service_client_t client_loc = (property_list_service_client_t)malloc(sizeof(struct property_list_service_client_private));
81 client_loc->connection = connection; 82 client_loc->parent = parent;
82
83 /* enable SSL if requested */
84 if (service->ssl_enabled == 1)
85 property_list_service_enable_ssl(client_loc);
86 83
87 /* all done, return success */ 84 /* all done, return success */
88 *client = client_loc; 85 *client = client_loc;
@@ -103,7 +100,7 @@ property_list_service_error_t property_list_service_client_free(property_list_se
103 if (!client) 100 if (!client)
104 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 101 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
105 102
106 property_list_service_error_t err = idevice_to_property_list_service_error(idevice_disconnect(client->connection)); 103 property_list_service_error_t err = service_to_property_list_service_error(service_client_free(client->parent));
107 free(client); 104 free(client);
108 return err; 105 return err;
109} 106}
@@ -130,7 +127,7 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
130 uint32_t nlen = 0; 127 uint32_t nlen = 0;
131 int bytes = 0; 128 int bytes = 0;
132 129
133 if (!client || (client && !client->connection) || !plist) { 130 if (!client || (client && !client->parent) || !plist) {
134 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 131 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
135 } 132 }
136 133
@@ -146,9 +143,9 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
146 143
147 nlen = htobe32(length); 144 nlen = htobe32(length);
148 debug_info("sending %d bytes", length); 145 debug_info("sending %d bytes", length);
149 idevice_connection_send(client->connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes); 146 service_send(client->parent, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes);
150 if (bytes == sizeof(nlen)) { 147 if (bytes == sizeof(nlen)) {
151 idevice_connection_send(client->connection, content, length, (uint32_t*)&bytes); 148 service_send(client->parent, content, length, (uint32_t*)&bytes);
152 if (bytes > 0) { 149 if (bytes > 0) {
153 debug_info("sent %d bytes", bytes); 150 debug_info("sent %d bytes", bytes);
154 debug_plist(plist); 151 debug_plist(plist);
@@ -222,11 +219,11 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis
222 uint32_t pktlen = 0; 219 uint32_t pktlen = 0;
223 uint32_t bytes = 0; 220 uint32_t bytes = 0;
224 221
225 if (!client || (client && !client->connection) || !plist) { 222 if (!client || (client && !client->parent) || !plist) {
226 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 223 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
227 } 224 }
228 225
229 idevice_connection_receive_timeout(client->connection, (char*)&pktlen, sizeof(pktlen), &bytes, timeout); 226 service_receive_with_timeout(client->parent, (char*)&pktlen, sizeof(pktlen), &bytes, timeout);
230 debug_info("initial read=%i", bytes); 227 debug_info("initial read=%i", bytes);
231 if (bytes < 4) { 228 if (bytes < 4) {
232 debug_info("initial read failed!"); 229 debug_info("initial read failed!");
@@ -240,7 +237,7 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis
240 content = (char*)malloc(pktlen); 237 content = (char*)malloc(pktlen);
241 238
242 while (curlen < pktlen) { 239 while (curlen < pktlen) {
243 idevice_connection_receive(client->connection, content+curlen, pktlen-curlen, &bytes); 240 service_receive(client->parent, content+curlen, pktlen-curlen, &bytes);
244 if (bytes <= 0) { 241 if (bytes <= 0) {
245 res = PROPERTY_LIST_SERVICE_E_MUX_ERROR; 242 res = PROPERTY_LIST_SERVICE_E_MUX_ERROR;
246 break; 243 break;
@@ -332,9 +329,9 @@ property_list_service_error_t property_list_service_receive_plist(property_list_
332 */ 329 */
333property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client) 330property_list_service_error_t property_list_service_enable_ssl(property_list_service_client_t client)
334{ 331{
335 if (!client || !client->connection) 332 if (!client || !client->parent)
336 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 333 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
337 return idevice_to_property_list_service_error(idevice_connection_enable_ssl(client->connection)); 334 return service_to_property_list_service_error(service_enable_ssl(client->parent));
338} 335}
339 336
340/** 337/**
@@ -349,8 +346,8 @@ property_list_service_error_t property_list_service_enable_ssl(property_list_ser
349 */ 346 */
350property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client) 347property_list_service_error_t property_list_service_disable_ssl(property_list_service_client_t client)
351{ 348{
352 if (!client || !client->connection) 349 if (!client || !client->parent)
353 return PROPERTY_LIST_SERVICE_E_INVALID_ARG; 350 return PROPERTY_LIST_SERVICE_E_INVALID_ARG;
354 return idevice_to_property_list_service_error(idevice_connection_disable_ssl(client->connection)); 351 return service_to_property_list_service_error(service_disable_ssl(client->parent));
355} 352}
356 353