From 4105af17e9f2df5405afa6a74a02a304ed6bacff Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 6 Jul 2009 19:38:00 +0200 Subject: API cleanup for AFC --- dev/afccheck.c | 21 ++++++++-------- dev/main.c | 47 ++++++++++++++++++----------------- include/Makefile.am | 2 +- include/libiphone/afc.h | 54 ++++++++++++++++++++++++++++++++++++++++ include/libiphone/libiphone.h | 40 ------------------------------ src/AFC.c | 57 +++++++++++++++++++++++-------------------- src/AFC.h | 5 +--- 7 files changed, 121 insertions(+), 105 deletions(-) create mode 100644 include/libiphone/afc.h diff --git a/dev/afccheck.c b/dev/afccheck.c index 965981b..b107437 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -25,13 +25,14 @@ #include #include +#include #define BUFFER_SIZE 20000 #define NB_THREADS 10 typedef struct { - iphone_afc_client_t afc; + afc_client_t afc; int id; } param; @@ -53,18 +54,18 @@ void check_afc(gpointer data) uint64_t file = 0; char path[50]; sprintf(path, "/Buf%i", ((param *) data)->id); - iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); - iphone_afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); - iphone_afc_close_file(((param *) data)->afc, file); + afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RW, &file); + afc_write_file(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); + afc_close_file(((param *) data)->afc, file); file = 0; if (bytes != buffersize) printf("Write operation failed\n"); //now read it bytes = 0; - iphone_afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); - iphone_afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); - iphone_afc_close_file(((param *) data)->afc, file); + afc_open_file(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); + afc_read_file(((param *) data)->afc, file, (char *) buf2, buffersize, &bytes); + afc_close_file(((param *) data)->afc, file); if (bytes != buffersize) printf("Read operation failed\n"); @@ -77,7 +78,7 @@ void check_afc(gpointer data) } //cleanup - iphone_afc_delete_file(((param *) data)->afc, path); + afc_delete_file(((param *) data)->afc, path); g_thread_exit(0); } @@ -87,7 +88,7 @@ int main(int argc, char *argv[]) iphone_device_t phone = NULL; GError *err; int port = 0; - iphone_afc_client_t afc = NULL; + afc_client_t afc = NULL; if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { printf("No iPhone found, is it plugged in?\n"); @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) return 1; } - iphone_afc_new_client(phone, port, &afc); + afc_new_client(phone, port, &afc); //makes sure thread environment is available if (!g_thread_supported()) diff --git a/dev/main.c b/dev/main.c index c8c9dfa..fe340ff 100644 --- a/dev/main.c +++ b/dev/main.c @@ -25,6 +25,7 @@ #include #include +#include #include "../src/utils.h" void notifier(const char *notification) @@ -97,8 +98,8 @@ int main(int argc, char *argv[]) iphone_lckd_start_service(control, "com.apple.afc", &port); if (port) { - iphone_afc_client_t afc = NULL; - iphone_afc_new_client(phone, port, &afc); + afc_client_t afc = NULL; + afc_new_client(phone, port, &afc); if (afc) { iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { @@ -120,18 +121,18 @@ int main(int argc, char *argv[]) perform_notification(phone, control, NP_SYNC_WILL_START); - iphone_afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); + afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); - iphone_afc_lock_file(afc, lockfile, 2 | 4); + afc_lock_file(afc, lockfile, 2 | 4); perform_notification(phone, control, NP_SYNC_DID_START); } char **dirs = NULL; - iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); + afc_get_dir_list(afc, "/eafaedf", &dirs); if (!dirs) - iphone_afc_get_dir_list(afc, "/", &dirs); + afc_get_dir_list(afc, "/", &dirs); printf("Directory time.\n"); for (i = 0; dirs[i]; i++) { printf("/%s\n", dirs[i]); @@ -140,7 +141,7 @@ int main(int argc, char *argv[]) g_strfreev(dirs); dirs = NULL; - iphone_afc_get_devinfo(afc, &dirs); + afc_get_devinfo(afc, &dirs); if (dirs) { for (i = 0; dirs[i]; i += 2) { printf("%s: %s\n", dirs[i], dirs[i + 1]); @@ -151,7 +152,7 @@ int main(int argc, char *argv[]) uint64_t my_file = 0; char **info = NULL; uint64_t fsize = 0; - if (IPHONE_E_SUCCESS == iphone_afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { + if (IPHONE_E_SUCCESS == afc_get_file_info(afc, "/readme.libiphone.fx", &info) && info) { for (i = 0; info[i]; i += 2) { printf("%s: %s\n", info[i], info[i+1]); if (!strcmp(info[i], "st_size")) { @@ -161,58 +162,58 @@ int main(int argc, char *argv[]) } if (IPHONE_E_SUCCESS == - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { printf("A file size: %i\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); - iphone_afc_read_file(afc, my_file, file_data, fsize, &bytes); + afc_read_file(afc, my_file, file_data, fsize, &bytes); if (bytes >= 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } printf("\nClosing my file.\n"); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); free(file_data); } else printf("couldn't open a file\n"); - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_WR, &my_file); if (my_file) { char *outdatafile = strdup("this is a bitchin text file\n"); - iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); + afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); free(outdatafile); if (bytes > 0) printf("Wrote a surprise. ;)\n"); else printf("I wanted to write a surprise, but... :(\n"); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); } printf("Deleting a file...\n"); - bytes = iphone_afc_delete_file(afc, "/delme"); + bytes = afc_delete_file(afc, "/delme"); if (bytes) printf("Success.\n"); else printf("Failure. (expected unless you have a /delme file on your phone)\n"); printf("Renaming a file...\n"); - bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); + bytes = afc_rename_file(afc, "/renme", "/renme2"); if (bytes > 0) printf("Success.\n"); else printf("Failure. (expected unless you have a /renme file on your phone)\n"); printf("Seek & read\n"); - iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); - if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5, SEEK_CUR)) + afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file); + if (IPHONE_E_SUCCESS != afc_seek_file(afc, my_file, 5, SEEK_CUR)) printf("WARN: SEEK DID NOT WORK\n"); char *threeletterword = (char *) malloc(sizeof(char) * 5); - iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); + afc_read_file(afc, my_file, threeletterword, 3, &bytes); threeletterword[3] = '\0'; if (bytes > 0) printf("Result: %s\n", threeletterword); else printf("Couldn't read!\n"); free(threeletterword); - iphone_afc_close_file(afc, my_file); + afc_close_file(afc, my_file); } if (gnp && lockfile) { @@ -245,10 +246,10 @@ int main(int argc, char *argv[]) //perform_notification(phone, control, NP_SYNC_DID_FINISH); printf("XXX unlocking file\n"); - iphone_afc_lock_file(afc, lockfile, 8 | 4); + afc_lock_file(afc, lockfile, 8 | 4); printf("XXX closing file\n"); - iphone_afc_close_file(afc, lockfile); + afc_close_file(afc, lockfile); } if (gnp) { @@ -256,7 +257,7 @@ int main(int argc, char *argv[]) gnp = NULL; } - iphone_afc_free_client(afc); + afc_free_client(afc); } else { printf("Start service failure.\n"); } diff --git a/include/Makefile.am b/include/Makefile.am index a5f8766..4c17261 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h new file mode 100644 index 0000000..2a0bbad --- /dev/null +++ b/include/libiphone/afc.h @@ -0,0 +1,54 @@ +#ifndef AFC_H +#define AFC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef enum { + AFC_FOPEN_RDONLY = 0x00000001, // r O_RDONLY + AFC_FOPEN_RW = 0x00000002, // r+ O_RDWR | O_CREAT + AFC_FOPEN_WRONLY = 0x00000003, // w O_WRONLY | O_CREAT | O_TRUNC + AFC_FOPEN_WR = 0x00000004, // w+ O_RDWR | O_CREAT | O_TRUNC + AFC_FOPEN_APPEND = 0x00000005, // a O_WRONLY | O_APPEND | O_CREAT + AFC_FOPEN_RDAPPEND = 0x00000006 // a+ O_RDWR | O_APPEND | O_CREAT +} afc_file_mode_t; + +typedef enum { + AFC_HARDLINK = 1, + AFC_SYMLINK = 2 +} afc_link_type_t; + +struct afc_client_int; +typedef struct afc_client_int *afc_client_t; + +//afc related functions +iphone_error_t afc_new_client ( iphone_device_t device, int dst_port, afc_client_t *client ); +iphone_error_t afc_free_client ( afc_client_t client ); +int afc_get_afcerror ( afc_client_t client ); +int afc_get_errno ( afc_client_t client ); + +iphone_error_t afc_get_devinfo ( afc_client_t client, char ***infos ); +iphone_error_t afc_get_dir_list ( afc_client_t client, const char *dir, char ***list); + +iphone_error_t afc_get_file_info ( afc_client_t client, const char *filename, char ***infolist ); +iphone_error_t afc_open_file ( afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle ); +iphone_error_t afc_close_file ( afc_client_t client, uint64_t handle); +iphone_error_t afc_lock_file ( afc_client_t client, uint64_t handle, int operation); +iphone_error_t afc_read_file ( afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); +iphone_error_t afc_write_file ( afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); +iphone_error_t afc_seek_file ( afc_client_t client, uint64_t handle, int64_t offset, int whence); +iphone_error_t afc_truncate_file ( afc_client_t client, uint64_t handle, uint64_t newsize); +iphone_error_t afc_delete_file ( afc_client_t client, const char *path); +iphone_error_t afc_rename_file ( afc_client_t client, const char *from, const char *to); +iphone_error_t afc_mkdir ( afc_client_t client, const char *dir); +iphone_error_t afc_truncate ( afc_client_t client, const char *path, off_t newsize); +iphone_error_t afc_make_link ( afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 463efa7..3f5d86c 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -54,29 +54,12 @@ extern "C" { typedef int16_t iphone_error_t; -typedef enum { - AFC_FOPEN_RDONLY = 0x00000001, // r O_RDONLY - AFC_FOPEN_RW = 0x00000002, // r+ O_RDWR | O_CREAT - AFC_FOPEN_WRONLY = 0x00000003, // w O_WRONLY | O_CREAT | O_TRUNC - AFC_FOPEN_WR = 0x00000004, // w+ O_RDWR | O_CREAT | O_TRUNC - AFC_FOPEN_APPEND = 0x00000005, // a O_WRONLY | O_APPEND | O_CREAT - AFC_FOPEN_RDAPPEND = 0x00000006 // a+ O_RDWR | O_APPEND | O_CREAT -} iphone_afc_file_mode_t; - -typedef enum { - IPHONE_AFC_HARDLINK = 1, - IPHONE_AFC_SYMLINK = 2 -} iphone_afc_link_type_t; - struct iphone_device_int; typedef struct iphone_device_int *iphone_device_t; struct iphone_lckd_client_int; typedef struct iphone_lckd_client_int *iphone_lckd_client_t; -struct iphone_afc_client_int; -typedef struct iphone_afc_client_int *iphone_afc_client_t; - struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; @@ -111,29 +94,6 @@ iphone_error_t iphone_lckd_recv ( iphone_lckd_client_t client, plist_t* plist); iphone_error_t iphone_lckd_send ( iphone_lckd_client_t client, plist_t plist); -//afc related functions -iphone_error_t iphone_afc_new_client ( iphone_device_t device, int dst_port, iphone_afc_client_t *client ); -iphone_error_t iphone_afc_free_client ( iphone_afc_client_t client ); -int iphone_afc_get_afcerror ( iphone_afc_client_t client ); -int iphone_afc_get_errno ( iphone_afc_client_t client ); - -iphone_error_t iphone_afc_get_devinfo ( iphone_afc_client_t client, char ***infos ); -iphone_error_t iphone_afc_get_dir_list ( iphone_afc_client_t client, const char *dir, char ***list); - -iphone_error_t iphone_afc_get_file_info ( iphone_afc_client_t client, const char *filename, char ***infolist ); -iphone_error_t iphone_afc_open_file ( iphone_afc_client_t client, const char *filename, iphone_afc_file_mode_t file_mode, uint64_t *handle ); -iphone_error_t iphone_afc_close_file ( iphone_afc_client_t client, uint64_t handle); -iphone_error_t iphone_afc_lock_file ( iphone_afc_client_t client, uint64_t handle, int operation); -iphone_error_t iphone_afc_read_file ( iphone_afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); -iphone_error_t iphone_afc_write_file ( iphone_afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); -iphone_error_t iphone_afc_seek_file ( iphone_afc_client_t client, uint64_t handle, int64_t offset, int whence); -iphone_error_t iphone_afc_truncate_file ( iphone_afc_client_t client, uint64_t handle, uint64_t newsize); -iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path); -iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); -iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); -iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize); -iphone_error_t iphone_afc_make_link ( iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname); - iphone_error_t iphone_msync_new_client(iphone_device_t device, int dst_port, iphone_msync_client_t * client); diff --git a/src/AFC.c b/src/AFC.c index 960d640..e666c45 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -24,8 +24,11 @@ #include #include #include "AFC.h" +#include "iphone.h" #include "utils.h" +#include + // This is the maximum size an AFC data packet can be const int MAXIMUM_PACKET_SIZE = (2 << 15); @@ -34,7 +37,7 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15); * * @param client The AFC client connection to lock */ -static void afc_lock(iphone_afc_client_t client) +static void afc_lock(afc_client_t client) { log_debug_msg("Locked\n"); /*while (client->lock) { @@ -48,7 +51,7 @@ static void afc_lock(iphone_afc_client_t client) * * @param client The AFC */ -static void afc_unlock(iphone_afc_client_t client) +static void afc_unlock(afc_client_t client) { // just to be pretty log_debug_msg("Unlocked\n"); //client->lock = 0; @@ -63,7 +66,7 @@ static void afc_unlock(iphone_afc_client_t client) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphone_afc_client_t * client) +iphone_error_t afc_new_client(iphone_device_t device, int dst_port, afc_client_t * client) { //makes sure thread environment is available if (!g_thread_supported()) @@ -78,7 +81,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon return IPHONE_E_UNKNOWN_ERROR; // ret; } - iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); + afc_client_t client_loc = (afc_client_t) malloc(sizeof(struct afc_client_int)); client_loc->sfd = sfd; // Allocate a packet @@ -105,7 +108,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int dst_port, iphon * * @param client The client to disconnect. */ -iphone_error_t iphone_afc_free_client(iphone_afc_client_t client) +iphone_error_t afc_free_client(afc_client_t client) { if (!client || client->sfd < 0 || !client->afc_packet) return IPHONE_E_INVALID_ARG; @@ -127,7 +130,7 @@ iphone_error_t iphone_afc_free_client(iphone_afc_client_t client) * * @return AFC error code or -1 on error. */ -int iphone_afc_get_afcerror(iphone_afc_client_t client) +int afc_get_afcerror(afc_client_t client) { int res = -1; if (client) { @@ -140,13 +143,13 @@ int iphone_afc_get_afcerror(iphone_afc_client_t client) /** * Tries to convert the AFC error value into a meaningful errno value. - * Internally used by iphone_afc_get_errno. + * Internally used by afc_get_errno. * * @param afcerror AFC error value to convert * * @return errno value or -1 if the errno could not be determined. * - * @see iphone_afc_get_errno + * @see afc_get_errno */ static int afcerror_to_errno(int afcerror) { @@ -189,7 +192,7 @@ static int afcerror_to_errno(int afcerror) * * @return errno value or -1 on error. */ -int iphone_afc_get_errno(iphone_afc_client_t client) +int afc_get_errno(afc_client_t client) { int res = -1; if (client) { @@ -213,7 +216,7 @@ int iphone_afc_get_errno(iphone_afc_client_t client) * reason is that if you set them to different values, it indicates * you want to send the data as two packets. */ -static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uint64_t length) +static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t length) { int bytes = 0, offset = 0; char *buffer; @@ -294,7 +297,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, uin * received raised a non-trivial error condition (i.e. non-zero with * AFC_ERROR operation) */ -static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) +static int receive_AFC_data(afc_client_t client, char **dump_here) { AFCPacket header; int bytes = 0; @@ -468,7 +471,7 @@ static char **make_strings_list(char *tokens, int true_length) * @return A char ** list of files in that directory, terminated by an empty * string for now or NULL if there was an error. */ -iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *dir, char ***list) +iphone_error_t afc_get_dir_list(afc_client_t client, const char *dir, char ***list) { int bytes = 0; char *data = NULL, **list_loc = NULL; @@ -514,7 +517,7 @@ iphone_error_t iphone_afc_get_dir_list(iphone_afc_client_t client, const char *d * @return A char ** list of parameters as given by AFC or NULL if there was an * error. */ -iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos) +iphone_error_t afc_get_devinfo(afc_client_t client, char ***infos) { int bytes = 0; char *data = NULL, **list = NULL; @@ -556,7 +559,7 @@ iphone_error_t iphone_afc_get_devinfo(iphone_afc_client_t client, char ***infos) * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *path) +iphone_error_t afc_delete_file(afc_client_t client, const char *path) { char *response = NULL; int bytes; @@ -596,7 +599,7 @@ iphone_error_t iphone_afc_delete_file(iphone_afc_client_t client, const char *pa * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *from, const char *to) +iphone_error_t afc_rename_file(afc_client_t client, const char *from, const char *to) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); @@ -640,7 +643,7 @@ iphone_error_t iphone_afc_rename_file(iphone_afc_client_t client, const char *fr * @return IPHONE_E_SUCCESS if everythong went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir) +iphone_error_t afc_mkdir(afc_client_t client, const char *dir) { int bytes = 0; char *response = NULL; @@ -682,7 +685,7 @@ iphone_error_t iphone_afc_mkdir(iphone_afc_client_t client, const char *dir) * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error value * when something went wrong. */ -iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char *path, char ***infolist) +iphone_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) { char *received = NULL; int length; @@ -726,8 +729,8 @@ iphone_error_t iphone_afc_get_file_info(iphone_afc_client_t client, const char * * @return IPHONE_E_SUCCESS on success or an IPHONE_E_* error on failure. */ iphone_error_t -iphone_afc_open_file(iphone_afc_client_t client, const char *filename, - iphone_afc_file_mode_t file_mode, uint64_t *handle) +afc_open_file(afc_client_t client, const char *filename, + afc_file_mode_t file_mode, uint64_t *handle) { uint32_t ag = 0; int bytes = 0, length = 0; @@ -786,7 +789,7 @@ iphone_afc_open_file(iphone_afc_client_t client, const char *filename, * @return The number of bytes read if successful. If there was an error -1. */ iphone_error_t -iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) +afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) { char *input = NULL; int current_count = 0, bytes_loc = 0; @@ -857,7 +860,7 @@ iphone_afc_read_file(iphone_afc_client_t client, uint64_t handle, char *data, in * none were written... */ iphone_error_t -iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle, +afc_write_file(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t * bytes) { char *acknowledgement = NULL; @@ -946,7 +949,7 @@ iphone_afc_write_file(iphone_afc_client_t client, uint64_t handle, * @param client The client to close the file with. * @param handle File handle of a previously opened file. */ -iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle) +iphone_error_t afc_close_file(afc_client_t client, uint64_t handle) { if (!client || (handle == 0)) return IPHONE_E_INVALID_ARG; @@ -997,7 +1000,7 @@ iphone_error_t iphone_afc_close_file(iphone_afc_client_t client, uint64_t handle * @param handle File handle of a previously opened file. * @operation the lock or unlock operation to perform. */ -iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle, int operation) +iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, int operation) { if (!client || (handle == 0)) return IPHONE_E_INVALID_ARG; @@ -1046,7 +1049,7 @@ iphone_error_t iphone_afc_lock_file(iphone_afc_client_t client, uint64_t handle, * * @return IPHONE_E_SUCCESS on success, IPHONE_E_NOT_ENOUGH_DATA on failure. */ -iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle, int64_t offset, int whence) +iphone_error_t afc_seek_file(afc_client_t client, uint64_t handle, int64_t offset, int whence) { char *buffer = (char *) malloc(sizeof(char) * 24); uint32_t zero = 0; @@ -1093,7 +1096,7 @@ iphone_error_t iphone_afc_seek_file(iphone_afc_client_t client, uint64_t handle, * @note This function is more akin to ftruncate than truncate, and truncate * calls would have to open the file before calling this, sadly. */ -iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t handle, uint64_t newsize) +iphone_error_t afc_truncate_file(afc_client_t client, uint64_t handle, uint64_t newsize) { char *buffer = (char *) malloc(sizeof(char) * 16); int bytes = 0; @@ -1135,7 +1138,7 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, uint64_t han * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) +iphone_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); @@ -1181,7 +1184,7 @@ iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. */ -iphone_error_t iphone_afc_make_link(iphone_afc_client_t client, iphone_afc_link_type_t linktype, const char *target, const char *linkname) +iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const char *target, const char *linkname) { char *response = NULL; char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); diff --git a/src/AFC.h b/src/AFC.h index a9c33c3..5d337e5 100644 --- a/src/AFC.h +++ b/src/AFC.h @@ -19,9 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libiphone/libiphone.h" -#include "iphone.h" - #include #include #include @@ -46,7 +43,7 @@ typedef struct __AFCToken { char *token; } AFCToken; -struct iphone_afc_client_int { +struct afc_client_int { int sfd; AFCPacket *afc_packet; int file_handle; -- cgit v1.1-32-gdbae From ab8e29dafc0577203e6867329b1d3ff9095a4fb2 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 6 Jul 2009 19:46:35 +0200 Subject: API cleanup for NotificationProxy --- dev/main.c | 40 ++++++++--------------------- include/Makefile.am | 2 +- include/libiphone/libiphone.h | 33 ------------------------ include/libiphone/notification_proxy.h | 46 ++++++++++++++++++++++++++++++++++ src/NotificationProxy.c | 39 ++++++++++++++-------------- src/NotificationProxy.h | 7 +++--- 6 files changed, 80 insertions(+), 87 deletions(-) create mode 100644 include/libiphone/notification_proxy.h diff --git a/dev/main.c b/dev/main.c index fe340ff..d39baa7 100644 --- a/dev/main.c +++ b/dev/main.c @@ -26,6 +26,7 @@ #include #include +#include #include "../src/utils.h" void notifier(const char *notification) @@ -38,16 +39,16 @@ void notifier(const char *notification) void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) { int nport = 0; - iphone_np_client_t np; + np_client_t np; iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); - iphone_np_new_client(phone, nport, &np); + np_new_client(phone, nport, &np); if (np) { printf("::::::::: PostNotification %s\n", notification); - iphone_np_post_notification(np, notification); - iphone_np_free_client(np); + np_post_notification(np, notification); + np_free_client(np); } } else { printf("::::::::::::::: np was NOT started ::::::::::::\n"); @@ -61,7 +62,7 @@ int main(int argc, char *argv[]) iphone_lckd_client_t control = NULL; iphone_device_t phone = NULL; uint64_t lockfile = 0; - iphone_np_client_t gnp = NULL; + np_client_t gnp = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) { iphone_set_debug(1); @@ -104,7 +105,7 @@ int main(int argc, char *argv[]) iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); - iphone_np_new_client(phone, npp, &gnp); + np_new_client(phone, npp, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } @@ -115,8 +116,8 @@ int main(int argc, char *argv[]) NP_SYNC_RESUME_REQUEST, NULL }; - iphone_np_observe_notifications(gnp, nspec); - iphone_np_set_notify_callback(gnp, notifier); + np_observe_notifications(gnp, nspec); + np_set_notify_callback(gnp, notifier); } perform_notification(phone, control, NP_SYNC_WILL_START); @@ -219,28 +220,7 @@ int main(int argc, char *argv[]) if (gnp && lockfile) { char *noti; - /* - noti = NULL; - iphone_np_get_notification(gnp, ¬i); - if (noti) { - printf("------> received notification '%s'\n", noti); - free(noti); - }*/ - printf("XXX sleeping\n"); - /*for (i = 0; i < 5; i++) { - noti = NULL; - printf("--- getting notification\n"); - iphone_np_get_notification(gnp, ¬i); - if (noti) { - printf("------> received notification '%s'\n", noti); - free(noti); - } else { - printf("---- no notification\n"); - } - sleep(1); - } - */ sleep(5); //perform_notification(phone, control, NP_SYNC_DID_FINISH); @@ -253,7 +233,7 @@ int main(int argc, char *argv[]) } if (gnp) { - iphone_np_free_client(gnp); + np_free_client(gnp); gnp = NULL; } diff --git a/include/Makefile.am b/include/Makefile.am index 4c17261..d8ae1e4 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 3f5d86c..456f000 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -63,9 +63,6 @@ typedef struct iphone_lckd_client_int *iphone_lckd_client_t; struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; -struct iphone_np_client_int; -typedef struct iphone_np_client_int *iphone_np_client_t; - //debug related functions #define DBGMASK_ALL 0xFFFF #define DBGMASK_NONE 0x0000 @@ -102,36 +99,6 @@ 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); -// NotificationProxy related -// notifications for use with post_notification (client --> device) -#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" -#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" -#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" - -// notifications for use with observe_notification (device --> client) -#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" -#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" -#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" -#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed" -#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed" -#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation" -#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" -#define NP_APP_INSTALLED "com.apple.mobile.application_installed" -#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" - -iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ); -iphone_error_t iphone_np_free_client ( iphone_np_client_t client ); - -iphone_error_t iphone_np_post_notification ( iphone_np_client_t client, const char *notification ); - -iphone_error_t iphone_np_observe_notification ( iphone_np_client_t client, const char *notification ); -iphone_error_t iphone_np_observe_notifications ( iphone_np_client_t client, const char **notification_spec ); -iphone_error_t iphone_np_get_notification ( iphone_np_client_t client, char **notification ); - -typedef void (*iphone_np_notify_cb_t) ( const char *notification ); - -iphone_error_t iphone_np_set_notify_callback ( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ); - #ifdef __cplusplus } #endif diff --git a/include/libiphone/notification_proxy.h b/include/libiphone/notification_proxy.h new file mode 100644 index 0000000..9412b4f --- /dev/null +++ b/include/libiphone/notification_proxy.h @@ -0,0 +1,46 @@ +#ifndef NOTIFICATION_PROXY_H +#define NOTIFICATION_PROXY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct np_client_int; +typedef struct np_client_int *np_client_t; + +// NotificationProxy related +// notifications for use with post_notification (client --> device) +#define NP_SYNC_WILL_START "com.apple.itunes-mobdev.syncWillStart" +#define NP_SYNC_DID_START "com.apple.itunes-mobdev.syncDidStart" +#define NP_SYNC_DID_FINISH "com.apple.itunes-mobdev.syncDidFinish" + +// notifications for use with observe_notification (device --> client) +#define NP_SYNC_CANCEL_REQUEST "com.apple.itunes-client.syncCancelRequest" +#define NP_SYNC_SUSPEND_REQUEST "com.apple.itunes-client.syncSuspendRequest" +#define NP_SYNC_RESUME_REQUEST "com.apple.itunes-client.syncResumeRequest" +#define NP_PHONE_NUMBER_CHANGED "com.apple.mobile.lockdown.phone_number_changed" +#define NP_DEVICE_NAME_CHANGED "com.apple.mobile.lockdown.device_name_changed" +#define NP_ATTEMPTACTIVATION "com.apple.springboard.attemptactivation" +#define NP_DS_DOMAIN_CHANGED "com.apple.mobile.data_sync.domain_changed" +#define NP_APP_INSTALLED "com.apple.mobile.application_installed" +#define NP_APP_UNINSTALLED "com.apple.mobile.application_uninstalled" + +iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ); +iphone_error_t np_free_client ( np_client_t client ); + +iphone_error_t np_post_notification ( np_client_t client, const char *notification ); + +iphone_error_t np_observe_notification ( np_client_t client, const char *notification ); +iphone_error_t np_observe_notifications ( np_client_t client, const char **notification_spec ); + +typedef void (*np_notify_cb_t) ( const char *notification ); + +iphone_error_t np_set_notify_callback ( np_client_t client, np_notify_cb_t notify_cb ); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c index 6fc048c..374420c 100644 --- a/src/NotificationProxy.c +++ b/src/NotificationProxy.c @@ -25,18 +25,19 @@ #include #include #include "NotificationProxy.h" +#include "iphone.h" #include "utils.h" struct np_thread { - iphone_np_client_t client; - iphone_np_notify_cb_t cbfunc; + np_client_t client; + np_notify_cb_t cbfunc; }; /** Locks an NP client, done for thread safety stuff. * * @param client The NP */ -static void np_lock(iphone_np_client_t client) +static void np_lock(np_client_t client) { log_debug_msg("NP: Locked\n"); g_mutex_lock(client->mutex); @@ -46,7 +47,7 @@ static void np_lock(iphone_np_client_t client) * * @param client The NP */ -static void np_unlock(iphone_np_client_t client) +static void np_unlock(np_client_t client) { log_debug_msg("NP: Unlocked\n"); g_mutex_unlock(client->mutex); @@ -61,7 +62,7 @@ static void np_unlock(iphone_np_client_t client) * * @return IPHONE_E_SUCCESS or an error code. */ -static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) +static iphone_error_t np_plist_send(np_client_t client, plist_t dict) { char *XML_content = NULL; uint32_t length = 0; @@ -108,7 +109,7 @@ static iphone_error_t np_plist_send(iphone_np_client_t client, plist_t dict) * * @return A handle to the newly-connected client or NULL upon error. */ -iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, iphone_np_client_t *client ) +iphone_error_t np_new_client ( iphone_device_t device, int dst_port, np_client_t *client ) { //makes sure thread environment is available if (!g_thread_supported()) @@ -123,7 +124,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho return IPHONE_E_UNKNOWN_ERROR; //ret; } - iphone_np_client_t client_loc = (iphone_np_client_t) malloc(sizeof(struct iphone_np_client_int)); + np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int)); client_loc->sfd = sfd; client_loc->mutex = g_mutex_new(); @@ -138,7 +139,7 @@ iphone_error_t iphone_np_new_client ( iphone_device_t device, int dst_port, ipho * * @param client The client to disconnect. */ -iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) +iphone_error_t np_free_client ( np_client_t client ) { if (!client) return IPHONE_E_INVALID_ARG; @@ -166,7 +167,7 @@ iphone_error_t iphone_np_free_client ( iphone_np_client_t client ) * @param client The client to send to * @param notification The notification message to send */ -iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const char *notification ) +iphone_error_t np_post_notification( np_client_t client, const char *notification ) { if (!client || !notification) { return IPHONE_E_INVALID_ARG; @@ -202,7 +203,7 @@ iphone_error_t iphone_np_post_notification( iphone_np_client_t client, const cha * @param client The client to send to * @param notification The notifications that should be observed. */ -iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const char *notification ) +iphone_error_t np_observe_notification( np_client_t client, const char *notification ) { if (!client || !notification) { return IPHONE_E_INVALID_ARG; @@ -245,7 +246,7 @@ iphone_error_t iphone_np_observe_notification( iphone_np_client_t client, const * terminating NULL entry. However this parameter can be NULL; in this case, * the default set of notifications will be used. */ -iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const char **notification_spec ) +iphone_error_t np_observe_notifications( np_client_t client, const char **notification_spec ) { int i = 0; iphone_error_t res = IPHONE_E_UNKNOWN_ERROR; @@ -260,7 +261,7 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const } while (notifications[i]) { - res = iphone_np_observe_notification(client, notifications[i]); + res = np_observe_notification(client, notifications[i]); if (res != IPHONE_E_SUCCESS) { break; } @@ -281,10 +282,10 @@ iphone_error_t iphone_np_observe_notifications( iphone_np_client_t client, const * IPHONE_E_TIMEOUT if nothing has been received, * or an error value if an error occured. * - * @note You probably want to check out iphone_np_set_notify_callback - * @see iphone_np_set_notify_callback + * @note You probably want to check out np_set_notify_callback + * @see np_set_notify_callback */ -iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **notification ) +static iphone_error_t np_get_notification( np_client_t client, char **notification ) { uint32_t bytes = 0; iphone_error_t res; @@ -382,7 +383,7 @@ iphone_error_t iphone_np_get_notification( iphone_np_client_t client, char **not /** * Internally used thread function. */ -gpointer iphone_np_notifier( gpointer arg ) +gpointer np_notifier( gpointer arg ) { char *notification = NULL; struct np_thread *npt = (struct np_thread*)arg; @@ -391,7 +392,7 @@ gpointer iphone_np_notifier( gpointer arg ) log_debug_msg("%s: starting callback.\n", __func__); while (npt->client->sfd >= 0) { - iphone_np_get_notification(npt->client, ¬ification); + np_get_notification(npt->client, ¬ification); if (notification) { npt->cbfunc(notification); free(notification); @@ -419,7 +420,7 @@ gpointer iphone_np_notifier( gpointer arg ) * @return IPHONE_E_SUCCESS when the callback was successfully registered, * or an error value when an error occured. */ -iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_np_notify_cb_t notify_cb ) +iphone_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb ) { if (!client) { return IPHONE_E_INVALID_ARG; @@ -442,7 +443,7 @@ iphone_error_t iphone_np_set_notify_callback( iphone_np_client_t client, iphone_ npt->client = client; npt->cbfunc = notify_cb; - client->notifier = g_thread_create(iphone_np_notifier, npt, TRUE, NULL); + client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); if (client->notifier) { res = IPHONE_E_SUCCESS; } diff --git a/src/NotificationProxy.h b/src/NotificationProxy.h index afae98a..a10cde4 100644 --- a/src/NotificationProxy.h +++ b/src/NotificationProxy.h @@ -18,12 +18,11 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "libiphone/libiphone.h" -#include "iphone.h" +#include "libiphone/notification_proxy.h" #include -struct iphone_np_client_int { +struct np_client_int { int sfd; GMutex *mutex; GThread *notifier; @@ -42,4 +41,4 @@ static const char *np_default_notifications[10] = { NULL }; -gpointer iphone_np_notifier( gpointer arg ); +gpointer np_notifier( gpointer arg ); -- cgit v1.1-32-gdbae From b8ce722ffaeab22e141e18907c46bbed4659d857 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 7 Jul 2009 21:02:00 +0200 Subject: Cleanup lockdown request API and fix docs, tools, bindings and exports --- dev/afccheck.c | 15 +- dev/iphone_id.c | 9 +- dev/iphoneinfo.c | 17 +- dev/lckdclient.c | 29 +- dev/main.c | 35 +- dev/msyncclient.c | 12 +- dev/syslog_relay.c | 9 +- include/Makefile.am | 2 +- include/libiphone/libiphone.h | 27 +- include/libiphone/lockdown.h | 51 +++ src/lockdown.c | 778 ++++++++++++++++++++---------------------- src/lockdown.h | 24 +- swig/iphone.i | 17 +- 13 files changed, 501 insertions(+), 524 deletions(-) create mode 100644 include/libiphone/lockdown.h diff --git a/dev/afccheck.c b/dev/afccheck.c index b107437..9174e32 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -25,6 +25,7 @@ #include #include +#include #include #define BUFFER_SIZE 20000 @@ -40,10 +41,10 @@ typedef struct { void check_afc(gpointer data) { //prepare a buffer - int buffersize = BUFFER_SIZE * sizeof(int); + unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); int *buf = (int *) malloc(buffersize); int *buf2 = (int *) malloc(buffersize); - int bytes = 0; + unsigned int bytes = 0; //fill buffer int i = 0; for (i = 0; i < BUFFER_SIZE; i++) { @@ -84,7 +85,7 @@ void check_afc(gpointer data) int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; GError *err; int port = 0; @@ -95,13 +96,13 @@ int main(int argc, char *argv[]) return 1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return 1; } - if (IPHONE_E_SUCCESS == iphone_lckd_start_service(control, "com.apple.afc", &port) && !port) { - iphone_lckd_free_client(control); + if (IPHONE_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { + lockdownd_free_client(client); iphone_free_device(phone); fprintf(stderr, "Something went wrong when starting AFC."); return 1; @@ -128,7 +129,7 @@ int main(int argc, char *argv[]) } - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/iphone_id.c b/dev/iphone_id.c index c191608..15081f0 100644 --- a/dev/iphone_id.c +++ b/dev/iphone_id.c @@ -3,6 +3,7 @@ #include #include #include +#include #include static void usage() @@ -18,7 +19,7 @@ static void usage() int main(int argc, char **argv) { iphone_device_t phone = NULL; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; usbmuxd_scan_result *dev_list; char *devname = NULL; int ret = 0; @@ -67,18 +68,18 @@ int main(int argc, char **argv) return -2; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); fprintf(stderr, "ERROR: Connecting to device failed!\n"); return -2; } - if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) { + if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(client, &devname)) || !devname) { fprintf(stderr, "ERROR: Could not get device name!\n"); ret = -2; } - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); if (ret == 0) { diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 18ee055..7c823e6 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -25,6 +25,7 @@ #include #include +#include #define FORMAT_KEY_VALUE 1 #define FORMAT_XML 2 @@ -45,13 +46,13 @@ static const char *domains[] = { int is_domain_known(char *domain); void print_usage(int argc, char **argv); -void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format); +void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format); void plist_node_to_string(plist_t *node); void plist_children_to_string(plist_t *node); int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; @@ -128,17 +129,17 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } /* run query and output information */ - print_lckd_request_result(control, domain, "GetValue", key, format); + print_lckd_request_result(client, domain, "GetValue", key, format); if (domain != NULL) free(domain); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; @@ -248,7 +249,7 @@ void plist_children_to_string(plist_t *node) } } -void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, const char *request, const char *key, int format) { +void print_lckd_request_result(lockdownd_client_t client, const char *domain, const char *request, const char *key, int format) { char *xml_doc = NULL; char *s = NULL; uint32_t xml_length = 0; @@ -266,11 +267,11 @@ void print_lckd_request_result(iphone_lckd_client_t control, const char *domain, plist_add_sub_key_el(node, "Request"); plist_add_sub_string_el(node, request); - ret = iphone_lckd_send(control, node); + ret = lockdownd_send(client, node); if (ret == IPHONE_E_SUCCESS) { plist_free(node); node = NULL; - ret = iphone_lckd_recv(control, &node); + ret = lockdownd_recv(client, &node); if (ret == IPHONE_E_SUCCESS) { /* seek to value node */ for ( diff --git a/dev/lckdclient.c b/dev/lckdclient.c index c96f052..e197002 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -27,12 +27,11 @@ #include #include - +#include int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_set_debug(1); @@ -42,13 +41,13 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { printf("DeviceUniqueID : %s\n", uid); free(uid); } @@ -74,17 +73,25 @@ int main(int argc, char *argv[]) if (!strcmp(*args, "quit")) loop = FALSE; - if (!strcmp(*args, "get") && len == 3) { - char *value = NULL; - if (IPHONE_E_SUCCESS == lockdownd_generic_get_value(control, *(args + 1), *(args + 2), &value)) - printf("Success : value = %s\n", value); + if (!strcmp(*args, "get") && len >= 2) { + plist_t *value = NULL; + if (IPHONE_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) + { + char *xml = NULL; + uint32_t length; + plist_to_xml(value, &xml, &length); + printf("Success : value = %s\n", xml); + + free(xml); + free(value); + } else printf("Error\n"); } if (!strcmp(*args, "start") && len == 2) { int port = 0; - iphone_lckd_start_service(control, *(args + 1), &port); + lockdownd_start_service(client, *(args + 1), &port); printf("%i\n", port); } } @@ -94,7 +101,7 @@ int main(int argc, char *argv[]) cmd = NULL; } clear_history(); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/main.c b/dev/main.c index d39baa7..cf7dbaa 100644 --- a/dev/main.c +++ b/dev/main.c @@ -23,25 +23,27 @@ #include #include #include +#include #include +#include #include #include #include "../src/utils.h" -void notifier(const char *notification) +static void notifier(const char *notification) { printf("---------------------------------------------------------\n"); printf("------> Notification received: %s\n", notification); printf("---------------------------------------------------------\n"); } -void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, const char *notification) +static void perform_notification(iphone_device_t phone, lockdownd_client_t client, const char *notification) { int nport = 0; np_client_t np; - iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); + lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); np_new_client(phone, nport, &np); @@ -57,9 +59,10 @@ void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, c int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; + unsigned int bytes = 0; + int port = 0, i = 0; int npp; - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; uint64_t lockfile = 0; np_client_t gnp = NULL; @@ -77,32 +80,32 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); printf("Exiting.\n"); return -1; } char *uid = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid)) { printf("DeviceUniqueID : %s\n", uid); free(uid); } char *nnn = NULL; - if (IPHONE_E_SUCCESS == lockdownd_get_device_name(control, &nnn)) { + if (IPHONE_E_SUCCESS == lockdownd_get_device_name(client, &nnn)) { printf("DeviceName : %s\n", nnn); free(nnn); } - iphone_lckd_start_service(control, "com.apple.afc", &port); + lockdownd_start_service(client, "com.apple.afc", &port); if (port) { afc_client_t afc = NULL; afc_new_client(phone, port, &afc); if (afc) { - iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); + lockdownd_start_service(client, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); np_new_client(phone, npp, &gnp); @@ -120,14 +123,14 @@ int main(int argc, char *argv[]) np_set_notify_callback(gnp, notifier); } - perform_notification(phone, control, NP_SYNC_WILL_START); + perform_notification(phone, client, NP_SYNC_WILL_START); afc_open_file(afc, "/com.apple.itunes.lock_sync", AFC_FOPEN_RW, &lockfile); if (lockfile) { printf("locking file\n"); afc_lock_file(afc, lockfile, 2 | 4); - perform_notification(phone, control, NP_SYNC_DID_START); + perform_notification(phone, client, NP_SYNC_DID_START); } char **dirs = NULL; @@ -164,10 +167,10 @@ int main(int argc, char *argv[]) if (IPHONE_E_SUCCESS == afc_open_file(afc, "/readme.libiphone.fx", AFC_FOPEN_RDONLY, &my_file) && my_file) { - printf("A file size: %i\n", fsize); + printf("A file size: %llu\n", fsize); char *file_data = (char *) malloc(sizeof(char) * fsize); afc_read_file(afc, my_file, file_data, fsize, &bytes); - if (bytes >= 0) { + if (bytes > 0) { printf("The file's data:\n"); fwrite(file_data, 1, bytes, stdout); } @@ -218,8 +221,6 @@ int main(int argc, char *argv[]) } if (gnp && lockfile) { - char *noti; - printf("XXX sleeping\n"); sleep(5); @@ -244,7 +245,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/msyncclient.c b/dev/msyncclient.c index e3bb0c2..e06a5fe 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -25,12 +25,12 @@ #include #include - +#include int main(int argc, char *argv[]) { - int bytes = 0, port = 0, i = 0; - iphone_lckd_client_t control = NULL; + int port = 0; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; if (argc > 1 && !strcasecmp(argv[1], "--debug")) @@ -42,12 +42,12 @@ int main(int argc, char *argv[]) return -1; } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } - iphone_lckd_start_service(control, "com.apple.mobilesync", &port); + lockdownd_start_service(client, "com.apple.mobilesync", &port); if (port) { iphone_msync_client_t msync = NULL; @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) printf("All done.\n"); - iphone_lckd_free_client(control); + lockdownd_free_client(client); iphone_free_device(phone); return 0; diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 6698653..a93e85b 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -27,6 +27,7 @@ #include #include +#include #include static int quit_flag = 0; @@ -44,7 +45,7 @@ static void clean_exit(int sig) int main(int argc, char *argv[]) { - iphone_lckd_client_t control = NULL; + lockdownd_client_t client = NULL; iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; @@ -99,15 +100,15 @@ int main(int argc, char *argv[]) } } - if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + if (IPHONE_E_SUCCESS != lockdownd_new_client(phone, &client)) { iphone_free_device(phone); return -1; } /* start syslog_relay service and retrieve port */ - ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); + ret = lockdownd_start_service(client, "com.apple.syslog_relay", &port); if ((ret == IPHONE_E_SUCCESS) && port) { - iphone_lckd_free_client(control); + lockdownd_free_client(client); /* connect to socket relay messages */ diff --git a/include/Makefile.am b/include/Makefile.am index d8ae1e4..98792de 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1 +1 @@ -nobase_include_HEADERS = libiphone/libiphone.h libiphone/afc.h libiphone/notification_proxy.h +nobase_include_HEADERS = libiphone/libiphone.h libiphone/lockdown.h libiphone/afc.h libiphone/notification_proxy.h diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 456f000..9e983bb 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_lckd_client_int; -typedef struct iphone_lckd_client_int *iphone_lckd_client_t; - struct iphone_msync_client_int; typedef struct iphone_msync_client_int *iphone_msync_client_t; @@ -74,29 +71,15 @@ void iphone_set_debug_mask(uint16_t mask); void iphone_set_debug(int level); //device related functions -iphone_error_t iphone_get_device ( iphone_device_t *device ); -iphone_error_t iphone_get_device_by_uuid ( iphone_device_t *device, const char *uuid ); -iphone_error_t iphone_free_device ( iphone_device_t device ); - -uint32_t iphone_get_device_handle ( iphone_device_t device ); - -//lockdownd related functions -iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); -iphone_error_t lockdownd_get_device_name ( iphone_lckd_client_t client, char **device_name ); -iphone_error_t iphone_lckd_new_client ( iphone_device_t device, iphone_lckd_client_t *client ); -iphone_error_t iphone_lckd_free_client( iphone_lckd_client_t client ); - -iphone_error_t iphone_lckd_start_service ( iphone_lckd_client_t client, const char *service, int *port ); -iphone_error_t iphone_lckd_recv ( iphone_lckd_client_t client, plist_t* plist); -iphone_error_t iphone_lckd_send ( iphone_lckd_client_t client, plist_t plist); - - +iphone_error_t iphone_get_device(iphone_device_t *device); +iphone_error_t iphone_get_device_by_uuid(iphone_device_t *device, const char *uuid); +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_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 diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h new file mode 100644 index 0000000..805c90b --- /dev/null +++ b/include/libiphone/lockdown.h @@ -0,0 +1,51 @@ +/* + * lockdownd.h + * + * Copyright (c) 2009 Martin S. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef LOCKDOWN_H +#define LOCKDOWN_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +struct lockdownd_client_int; +typedef struct lockdownd_client_int *lockdownd_client_t; + +//lockdownd related functions +iphone_error_t lockdownd_new_client (iphone_device_t device, lockdownd_client_t *client); +iphone_error_t lockdownd_free_client(lockdownd_client_t client); +iphone_error_t lockdownd_query_type(lockdownd_client_t client); +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node); +iphone_error_t lockdownd_start_service (lockdownd_client_t client, const char *service, int *port); +iphone_error_t lockdownd_stop_session(lockdownd_client_t client); +iphone_error_t lockdownd_send (lockdownd_client_t client, plist_t plist); +iphone_error_t lockdownd_recv (lockdownd_client_t client, plist_t *plist); +iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id); +iphone_error_t lockdownd_get_device_uid (lockdownd_client_t control, char **uid); +iphone_error_t lockdownd_get_device_name (lockdownd_client_t client, char **device_name); +iphone_error_t lockdownd_goodbye(lockdownd_client_t client); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/lockdown.c b/src/lockdown.c index a950ceb..7e1f1a8 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -33,6 +33,8 @@ #include +#define RESULT_SUCCESS 0 +#define RESULT_FAILURE 1 const ASN1_ARRAY_TYPE pkcs1_asn1_tab[] = { {"PKCS1", 536872976, 0}, @@ -43,28 +45,80 @@ const ASN1_ARRAY_TYPE pkcs1_asn1_tab[] = { {0, 0, 0} }; -/** Creates a lockdownd client for the give iPhone. +/** + * Internally used function for checking the result from lockdown's answer + * plist to a previously sent request. * - * @param phone The iPhone to create a lockdownd client for + * @param dict The plist to evaluate. + * @param query_match Name of the request to match. * - * @return The lockdownd client. + * @return RESULT_SUCCESS when the result is 'Success', + * RESULT_FAILURE when the result is 'Failure', + * or a negative value if an error occured during evaluation. */ -iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone) +static int lockdown_check_result(plist_t dict, const char *query_match) { - if (!phone) - return NULL; + int ret = -1; - int sfd = usbmuxd_connect(phone->handle, 0xf27e); - if (sfd < 0) { - log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, phone->handle); - return NULL; + plist_t query_key = plist_find_node_by_key(dict, "Request"); + if (!query_key) { + return ret; + } + plist_t query_node = plist_get_next_sibling(query_key); + if (!query_node) { + return ret; + } + if (plist_get_node_type(query_node) != PLIST_STRING) { + return ret; + } else { + char *query_value = NULL; + plist_get_string_val(query_node, &query_value); + if (!query_value) { + return ret; + } + if (strcmp(query_value, query_match) != 0) { + free(query_value); + return ret; + } + free(query_value); + } + + plist_t result_node = plist_get_next_sibling(query_node); + if (!result_node) { + return ret; } - iphone_lckd_client_t control = (iphone_lckd_client_t) malloc(sizeof(struct iphone_lckd_client_int)); - control->sfd = sfd; - control->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); - control->in_SSL = 0; - return control; + plist_t value_node = plist_get_next_sibling(result_node); + if (!value_node) { + return ret; + } + + plist_type result_type = plist_get_node_type(result_node); + plist_type value_type = plist_get_node_type(value_node); + + if (result_type == PLIST_KEY && value_type == PLIST_STRING) { + + char *result_value = NULL; + char *value_value = NULL; + + plist_get_key_val(result_node, &result_value); + plist_get_string_val(value_node, &value_value); + + if (result_value && value_value && !strcmp(result_value, "Result")) { + if (!strcmp(value_value, "Success")) { + ret = RESULT_SUCCESS; + } else if (!strcmp(value_value, "Failure")) { + ret = RESULT_FAILURE; + } else { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value); + } + } + if (result_value) + free(result_value); + if (value_value) + free(value_value); + } + return ret; } /** @@ -73,10 +127,10 @@ iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone) * * @param control The lockdown client */ -static void iphone_lckd_stop_session(iphone_lckd_client_t control) +iphone_error_t lockdownd_stop_session(lockdownd_client_t client) { - if (!control) - return; //IPHONE_E_INVALID_ARG; + if (!client) + return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -84,48 +138,31 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "StopSession"); plist_add_sub_key_el(dict, "SessionID"); - plist_add_sub_string_el(dict, control->session_id); + plist_add_sub_string_el(dict, client->session_id); log_dbg_msg(DBGMASK_LOCKDOWND, "iphone_lckd_stop_session() called\n"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) { log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); - return; // IPHONE_E_PLIST_ERROR; + return IPHONE_E_PLIST_ERROR; } - plist_t query_node = plist_find_node_by_string(dict, "StopSession"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + ret = IPHONE_E_UNKNOWN_ERROR; + if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; - return; // ret; + return ret; } /** @@ -135,16 +172,17 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) * * @param client The lockdown client */ -static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) +static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) { if (!client) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_SSL_session(): invalid argument!\n"); - return; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_ssl_session(): invalid argument!\n"); + return IPHONE_E_INVALID_ARG; } + iphone_error_t ret = IPHONE_E_SUCCESS; if (client->in_SSL) { log_dbg_msg(DBGMASK_LOCKDOWND, "Stopping SSL Session\n"); - iphone_lckd_stop_session(client); + ret = lockdownd_stop_session(client); log_dbg_msg(DBGMASK_LOCKDOWND, "Sending SSL close notify\n"); gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); } @@ -154,27 +192,26 @@ static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) } client->in_SSL = 0; - return; + return ret; } /** Closes the lockdownd client and does the necessary housekeeping. * - * @param control The lockdown client + * @param client The lockdown client */ -iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client) +iphone_error_t lockdownd_free_client(lockdownd_client_t client) { if (!client) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - iphone_lckd_stop_SSL_session(client); + lockdownd_stop_ssl_session(client); if (client->sfd > 0) { - lockdownd_close(client); + lockdownd_goodbye(client); // IMO, read of final "sessionUpcall connection closed" packet // should come here instead of in iphone_free_device - ret = usbmuxd_disconnect(client->sfd); } @@ -185,12 +222,11 @@ iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client) /** Polls the iPhone for lockdownd data. * * @param control The lockdownd client - * @param dump_data The pointer to the location of the buffer in which to store - * the received data + * @param plist The plist to store the received data * - * @return The number of bytes received + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) +iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist) { if (!client || !plist || (plist && *plist)) return IPHONE_E_INVALID_ARG; @@ -265,7 +301,7 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist) * * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) +iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) { if (!client || !plist) return IPHONE_E_INVALID_ARG; @@ -278,7 +314,6 @@ iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) plist_to_xml(plist, &XMLContent, &length); log_dbg_msg(DBGMASK_LOCKDOWND, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); - real_query = (char *) malloc(sizeof(char) * (length + 4)); length = htonl(length); memcpy(real_query, &length, sizeof(length)); @@ -310,15 +345,13 @@ iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist) /** Initiates the handshake for the lockdown session. Part of the lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @param control The lockdownd client + * @param client The lockdownd client * - * @return 1 on success and 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_hello(iphone_lckd_client_t control) +iphone_error_t lockdownd_query_type(lockdownd_client_t client) { - if (!control) + if (!client) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -327,72 +360,60 @@ iphone_error_t lockdownd_hello(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "QueryType"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_hello() called\n"); - ret = iphone_lckd_send(control, dict); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type() called\n"); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (IPHONE_E_SUCCESS != ret) return ret; - plist_t query_node = plist_find_node_by_string(dict, "QueryType"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_hello(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + ret = IPHONE_E_UNKNOWN_ERROR; + if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type(): success\n"); + ret = IPHONE_E_SUCCESS; } - plist_free(dict); dict = NULL; return ret; } -/** Generic function to handle simple (key, value) requests. +/** Retrieves a preferences plist using an optional domain and/or key name. * - * @param control an initialized lockdownd client. - * @param key the key to request - * @param value a pointer to the requested value + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to request or NULL to query for all keys + * @param value_node a plist node representing the result value node * - * @return IPHONE_E_SUCCESS on success. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, const char *req_string, - gnutls_datum_t * value) +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node) { - if (!control || !req_key || !value || value->data) + if (!client) return IPHONE_E_INVALID_ARG; plist_t dict = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - /* Setup DevicePublicKey request plist */ + /* setup request plist */ dict = plist_new_dict(); - plist_add_sub_key_el(dict, req_key); - plist_add_sub_string_el(dict, req_string); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "GetValue"); - /* send to iPhone */ - ret = iphone_lckd_send(control, dict); + /* send to device */ + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; @@ -400,71 +421,38 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const c if (ret != IPHONE_E_SUCCESS) return ret; - /* Now get iPhone's answer */ - ret = iphone_lckd_recv(control, &dict); - + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); if (ret != IPHONE_E_SUCCESS) return ret; - plist_t query_node = plist_find_node_by_string(dict, "GetValue"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - - char *result_key = NULL; - char *result_value = NULL; - ret = IPHONE_E_DICT_ERROR; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_generic_get_value(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_key); - free(result_value); + if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): success\n"); + ret = IPHONE_E_SUCCESS; } if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); return ret; } - plist_t value_key_node = plist_find_node_by_key(dict, "Value");//plist_get_next_sibling(result_value_node); + plist_t value_key_node = plist_find_node_by_key(dict, "Value"); plist_t value_value_node = plist_get_next_sibling(value_key_node); plist_type value_key_type = plist_get_node_type(value_key_node); if (value_key_type == PLIST_KEY) { - char *result_key = NULL; plist_get_key_val(value_key_node, &result_key); if (!strcmp(result_key, "Value")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_generic_get_value(): success\n"); - - plist_type value_value_type = plist_get_node_type(value_value_node); - if (PLIST_STRING == value_value_type) { - char *value_value = NULL; - plist_get_string_val(value_value_node, &value_value); - - value->data = (unsigned char*)value_value; - value->size = strlen(value_value); - ret = IPHONE_E_SUCCESS; - } - - if (PLIST_DATA == value_value_type) { - char *value_value = NULL; - uint64_t size = 0; - plist_get_data_val(value_value_node, &value_value, &size); - - value->data = (unsigned char*)value_value; - value->size = size; - ret = IPHONE_E_SUCCESS; - } + char *buf = NULL; + uint32_t length; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); + + /* FIXME: libplist does not offer cloning of nodes, use serialization */ + plist_to_bin(value_value_node, &buf, &length); + plist_from_bin(buf, length, value_node); + free(buf); } free(result_key); } @@ -473,69 +461,109 @@ iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const c return ret; } -/** Askes for the device's unique id. Part of the lockdownd handshake. - * - * @note You most likely want lockdownd_init unless you are doing something special. +/** Asks for the device's unique id. Part of the lockdownd handshake. * - * @return 1 on success and 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid) +iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) { - gnutls_datum_t temp = { NULL, 0 }; - iphone_error_t ret = lockdownd_generic_get_value(control, "Key", "UniqueDeviceID", &temp); - *uid = (char*)temp.data; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_string_val(value, uid); + + plist_free(value); + value = NULL; return ret; } /** Askes for the device's public key. Part of the lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @return IPHONE_E_SUCCESS on succes or an error value < 0 on failure. + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key) +iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) { - return lockdownd_generic_get_value(control, "Key", "DevicePublicKey", public_key); + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + char *value_value = NULL; + uint64_t size = 0; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_data_val(value, &value_value, &size); + public_key->data = (unsigned char*)value_value; + public_key->size = size; + + plist_free(value); + value = NULL; + + return ret; } /** Askes for the device's name. * - * @return IPHONE_E_SUCCESS on succes or an error value < 0 on failure. + * @param client The pointer to the location of the new lockdownd_client + * + * + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_device_name(iphone_lckd_client_t control, char **device_name) +iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) { - gnutls_datum_t temp = { NULL, 0 }; - iphone_error_t res = lockdownd_generic_get_value(control, "Key", "DeviceName", &temp); - log_debug_msg("%s: %s\n", __func__, temp.data); - *device_name = (char*)temp.data; - return res; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + plist_t value = NULL; + value = plist_new_dict(); + + ret = lockdownd_get_value(client, NULL, "DeviceName", &value); + if (ret != IPHONE_E_SUCCESS) { + return ret; + } + plist_get_string_val(value, device_name); + log_debug_msg("%s: %s\n", __func__, device_name); + + plist_free(value); + value = NULL; + + return ret; } -/** Completes the entire lockdownd handshake. +/** Creates a lockdownd client for the give iPhone * - * @param phone The iPhone - * @param lockdownd_client The pointer to the location of the lockdownd_client + * @param phone The iPhone to create a lockdownd client for + * @param client The pointer to the location of the new lockdownd_client * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client_t * client) +iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *client) { if (!device || !client || (client && *client)) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_SUCCESS; char *host_id = NULL; - iphone_lckd_client_t client_loc = new_lockdownd_client(device); - if (!client_loc) { - log_debug_msg("FATAL: lockdownd client could not be created!\n"); + int sfd = usbmuxd_connect(device->handle, 0xf27e); + if (sfd < 0) { + log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, device->handle); return IPHONE_E_UNKNOWN_ERROR; } - if (IPHONE_E_SUCCESS != lockdownd_hello(client_loc)) { - log_debug_msg("Hello failed in the lockdownd client.\n"); + + lockdownd_client_t client_loc = (lockdownd_client_t) malloc(sizeof(struct lockdownd_client_int)); + client_loc->sfd = sfd; + client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); + client_loc->in_SSL = 0; + + if (IPHONE_E_SUCCESS != lockdownd_query_type(client_loc)) { + log_debug_msg("QueryType failed in the lockdownd client.\n"); ret = IPHONE_E_NOT_ENOUGH_DATA; } - char *uid = NULL; ret = lockdownd_get_device_uid(client_loc, &uid); if (IPHONE_E_SUCCESS != ret) { @@ -549,7 +577,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client } if (IPHONE_E_SUCCESS == ret && !is_device_known(uid)) - ret = lockdownd_pair_device(client_loc, uid, host_id); + ret = lockdownd_pair(client_loc, uid, host_id); if (uid) { free(uid); @@ -557,7 +585,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client } if (IPHONE_E_SUCCESS == ret) { - ret = lockdownd_start_SSL_session(client_loc, host_id); + ret = lockdownd_start_ssl_session(client_loc, host_id); if (IPHONE_E_SUCCESS != ret) { ret = IPHONE_E_SSL_ERROR; log_debug_msg("SSL Session opening failed.\n"); @@ -578,11 +606,9 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client /** Generates the appropriate keys and pairs the device. It's part of the * lockdownd handshake. * - * @note You most likely want lockdownd_init unless you are doing something special. - * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id) +iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id) { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t dict = NULL; @@ -593,7 +619,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch gnutls_datum_t root_cert = { NULL, 0 }; gnutls_datum_t public_key = { NULL, 0 }; - ret = lockdownd_get_device_public_key(control, &public_key); + ret = lockdownd_get_device_public_key(client, &public_key); if (ret != IPHONE_E_SUCCESS) { log_debug_msg("Device refused to send public key.\n"); return ret; @@ -623,7 +649,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch plist_add_sub_string_el(dict, "Pair"); /* send to iPhone */ - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; @@ -631,43 +657,24 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch return ret; /* Now get iPhone's answer */ - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (ret != IPHONE_E_SUCCESS) return ret; - plist_t query_node = plist_find_node_by_string(dict, "Pair"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - - char *result_key = NULL; - char *result_value = NULL; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - ret = IPHONE_E_SUCCESS; - } - - free(result_key); - free(result_value); + if (lockdown_check_result(dict, "Pair") == RESULT_SUCCESS) { + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; /* store public key in config if pairing succeeded */ if (ret == IPHONE_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair_device: pair success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair success\n"); store_device_public_key(uid, public_key); ret = IPHONE_E_SUCCESS; } else { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair_device: pair failure\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair failure\n"); ret = IPHONE_E_PAIRING_FAILED; } free(public_key.data); @@ -678,12 +685,14 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch * Performs the Goodbye Request to tell the device the communication * session is now closed. * - * @param control The lockdown client + * @param client The lockdown client + * + * @return an error code (IPHONE_E_SUCCESS on success) */ -void lockdownd_close(iphone_lckd_client_t control) +iphone_error_t lockdownd_goodbye(lockdownd_client_t client) { - if (!control) - return; //IPHONE_E_INVALID_ARG; + if (!client) + return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; @@ -691,49 +700,32 @@ void lockdownd_close(iphone_lckd_client_t control) plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "Goodbye"); - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close() called\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye() called\n"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close(): IPHONE_E_PLIST_ERROR\n"); - return; // IPHONE_E_PLIST_ERROR; + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): IPHONE_E_PLIST_ERROR\n"); + return IPHONE_E_PLIST_ERROR; } - plist_t query_node = plist_find_node_by_string(dict, "Goodbye"); - plist_t result_node = plist_get_next_sibling(query_node); - plist_t value_node = plist_get_next_sibling(result_node); - - plist_type result_type = plist_get_node_type(result_node); - plist_type value_type = plist_get_node_type(value_node); - - if (result_type == PLIST_KEY && value_type == PLIST_STRING) { - char *result_value = NULL; - char *value_value = NULL; - - plist_get_key_val(result_node, &result_value); - plist_get_string_val(value_node, &value_value); - - if (!strcmp(result_value, "Result") && !strcmp(value_value, "Success")) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_close(): success\n"); - ret = IPHONE_E_SUCCESS; - } - free(result_value); - free(value_value); + if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): success\n"); + ret = IPHONE_E_SUCCESS; } plist_free(dict); dict = NULL; - return; // ret; + return ret; } /** Generates the device certificate from the public key as well as the host * and root certificates. * - * @return IPHONE_E_SUCCESS on success. + * @return an error code (IPHONE_E_SUCCESS on success) */ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) @@ -798,7 +790,7 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t gnutls_x509_privkey_init(&root_privkey); gnutls_x509_privkey_init(&host_privkey); - ret = get_keys_and_certs( root_privkey, root_cert, host_privkey, host_cert); + ret = get_keys_and_certs(root_privkey, root_cert, host_privkey, host_cert); if (IPHONE_E_SUCCESS == ret) { @@ -853,18 +845,18 @@ iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t /** Starts SSL communication with lockdownd after the iPhone has been paired. * - * @param control The lockdownd client + * @param client The lockdownd client * @param HostID The HostID used with this phone * - * @return 1 on success and 0 on failure + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID) +iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID) { plist_t dict = NULL; uint32_t return_me = 0; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; - control->session_id[0] = '\0'; + client->session_id[0] = '\0'; /* Setup DevicePublicKey request plist */ dict = plist_new_dict(); @@ -873,137 +865,101 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c plist_add_sub_key_el(dict, "Request"); plist_add_sub_string_el(dict, "StartSession"); - ret = iphone_lckd_send(control, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (ret != IPHONE_E_SUCCESS) return ret; - ret = iphone_lckd_recv(control, &dict); + ret = lockdownd_recv(client, &dict); if (!dict) return IPHONE_E_PLIST_ERROR; - plist_t request_node = plist_get_dict_el_from_key(dict, "Request"); - plist_t result_node = plist_get_dict_el_from_key(dict, "Result"); - - if (request_node && PLIST_STRING == plist_get_node_type(request_node) && - result_node && PLIST_STRING == plist_get_node_type(result_node)){ - - char *request = NULL; - char *result = NULL; - - plist_get_string_val(request_node, &request); - plist_get_string_val(result_node, &result); - - if (!strcmp(request, "StartSession")) { - if (!strcmp(result, "Failure")) { - - plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); - if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { - - char *error = NULL; - plist_get_string_val(error_node, &error); - - if (!strcmp(error, "InvalidHostID")) { - //hostid is not know. Pair and try again - char *uid = NULL; - char* host_id = get_host_id(); - if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(control, &uid) ) { - if (IPHONE_E_SUCCESS == lockdownd_pair_device(control, uid, host_id) ) { - - //start session again - plist_free(dict); - dict = plist_new_dict(); - plist_add_sub_key_el(dict, "HostID"); - plist_add_sub_string_el(dict, HostID); - plist_add_sub_key_el(dict, "Request"); - plist_add_sub_string_el(dict, "StartSession"); - - ret = iphone_lckd_send(control, dict); - plist_free(dict); - dict = NULL; - - ret = iphone_lckd_recv(control, &dict); - } - } - free(uid); - free(host_id); + if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { + plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); + if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { + char *error = NULL; + plist_get_string_val(error_node, &error); + + if (!strcmp(error, "InvalidHostID")) { + //hostid is unknown. Pair and try again + char *uid = NULL; + char* host_id = get_host_id(); + if (IPHONE_E_SUCCESS == lockdownd_get_device_uid(client, &uid) ) { + if (IPHONE_E_SUCCESS == lockdownd_pair(client, uid, host_id) ) { + //start session again + plist_free(dict); + dict = plist_new_dict(); + plist_add_sub_key_el(dict, "HostID"); + plist_add_sub_string_el(dict, HostID); + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "StartSession"); + + ret = lockdownd_send(client, dict); + plist_free(dict); + dict = NULL; + + ret = lockdownd_recv(client, &dict); } - free(error); } + free(uid); + free(host_id); } + free(error); } - free(request); - free(result); } - plist_t query_node = plist_find_node_by_string(dict, "StartSession"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - char *result_key = NULL; - char *result_value = NULL; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - ret = IPHONE_E_SSL_ERROR; - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success")) { - // Set up GnuTLS... - //gnutls_anon_client_credentials_t anoncred; - gnutls_certificate_credentials_t xcred; - - log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); - errno = 0; - gnutls_global_init(); - //gnutls_anon_allocate_client_credentials(&anoncred); - gnutls_certificate_allocate_credentials(&xcred); - gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM); - gnutls_init(control->ssl_session, GNUTLS_CLIENT); - { - int protocol_priority[16] = { GNUTLS_SSL3, 0 }; - int kx_priority[16] = { GNUTLS_KX_ANON_DH, GNUTLS_KX_RSA, 0 }; - int cipher_priority[16] = { GNUTLS_CIPHER_AES_128_CBC, GNUTLS_CIPHER_AES_256_CBC, 0 }; - int mac_priority[16] = { GNUTLS_MAC_SHA1, GNUTLS_MAC_MD5, 0 }; - int comp_priority[16] = { GNUTLS_COMP_NULL, 0 }; - - gnutls_cipher_set_priority(*control->ssl_session, cipher_priority); - gnutls_compression_set_priority(*control->ssl_session, comp_priority); - gnutls_kx_set_priority(*control->ssl_session, kx_priority); - gnutls_protocol_set_priority(*control->ssl_session, protocol_priority); - gnutls_mac_set_priority(*control->ssl_session, mac_priority); + ret = IPHONE_E_SSL_ERROR; + if (lockdown_check_result(dict, "StartSession") == RESULT_SUCCESS) { + // Set up GnuTLS... + //gnutls_anon_client_credentials_t anoncred; + gnutls_certificate_credentials_t xcred; - } - gnutls_credentials_set(*control->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. - - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); - gnutls_transport_set_ptr(*control->ssl_session, (gnutls_transport_ptr_t) control); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); - gnutls_transport_set_push_function(*control->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); - gnutls_transport_set_pull_function(*control->ssl_session, (gnutls_pull_func) & lockdownd_securead); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); - - if (errno) - log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); - return_me = gnutls_handshake(*control->ssl_session); - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); - - if (return_me != GNUTLS_E_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); - gnutls_perror(return_me); - log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); - return IPHONE_E_SSL_ERROR; - } else { - control->in_SSL = 1; - ret = IPHONE_E_SUCCESS; - } + log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); + errno = 0; + gnutls_global_init(); + //gnutls_anon_allocate_client_credentials(&anoncred); + gnutls_certificate_allocate_credentials(&xcred); + gnutls_certificate_set_x509_trust_file(xcred, "hostcert.pem", GNUTLS_X509_FMT_PEM); + gnutls_init(client->ssl_session, GNUTLS_CLIENT); + { + int protocol_priority[16] = { GNUTLS_SSL3, 0 }; + int kx_priority[16] = { GNUTLS_KX_ANON_DH, GNUTLS_KX_RSA, 0 }; + int cipher_priority[16] = { GNUTLS_CIPHER_AES_128_CBC, GNUTLS_CIPHER_AES_256_CBC, 0 }; + int mac_priority[16] = { GNUTLS_MAC_SHA1, GNUTLS_MAC_MD5, 0 }; + int comp_priority[16] = { GNUTLS_COMP_NULL, 0 }; + + gnutls_cipher_set_priority(*client->ssl_session, cipher_priority); + gnutls_compression_set_priority(*client->ssl_session, comp_priority); + gnutls_kx_set_priority(*client->ssl_session, kx_priority); + gnutls_protocol_set_priority(*client->ssl_session, protocol_priority); + gnutls_mac_set_priority(*client->ssl_session, mac_priority); + } + gnutls_credentials_set(*client->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. + + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); + gnutls_transport_set_ptr(*client->ssl_session, (gnutls_transport_ptr_t) client); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); + gnutls_transport_set_push_function(*client->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); + gnutls_transport_set_pull_function(*client->ssl_session, (gnutls_pull_func) & lockdownd_securead); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); + + if (errno) + log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); + return_me = gnutls_handshake(*client->ssl_session); + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); + + if (return_me != GNUTLS_E_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); + gnutls_perror(return_me); + log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); + return IPHONE_E_SSL_ERROR; + } else { + client->in_SSL = 1; + ret = IPHONE_E_SUCCESS; } } //store session id @@ -1020,10 +976,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c if (session_node_val_type == PLIST_STRING && session_id) { // we need to store the session ID for StopSession - strcpy(control->session_id, session_id); - log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", control->session_id); + strcpy(client->session_id, session_id); + log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", client->session_id); } - free(session_id); + if (session_id) + free(session_id); } } else log_dbg_msg(DBGMASK_LOCKDOWND, "Failed to get SessionID!\n"); @@ -1048,11 +1005,11 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length) { uint32_t bytes = 0; - iphone_lckd_client_t control; - control = (iphone_lckd_client_t) transport; + lockdownd_client_t client; + client = (lockdownd_client_t) transport; log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n"); log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length); - usbmuxd_send(control->sfd, buffer, length, &bytes); + usbmuxd_send(client->sfd, buffer, length, &bytes); log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes); dump_debug_buffer("sslpacketwrite.out", buffer, length); @@ -1073,8 +1030,8 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ size_t tbytes = 0; int this_len = length; iphone_error_t res; - iphone_lckd_client_t control; - control = (iphone_lckd_client_t) transport; + lockdownd_client_t client; + client = (lockdownd_client_t) transport; char *recv_buffer; log_debug_msg("lockdownd_securead() called\nlength = %zi\n", length); @@ -1085,8 +1042,8 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ // repeat until we have the full data or an error occurs. do { - if ((res = usbmuxd_recv(control->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { - log_debug_msg("%s: ERROR: iphone_mux_recv returned %d\n", __func__, res); + if ((res = usbmuxd_recv(client->sfd, recv_buffer, this_len, (uint32_t*)&bytes)) != IPHONE_E_SUCCESS) { + log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); return res; } log_debug_msg("post-read\nwe got %i bytes\n", bytes); @@ -1105,6 +1062,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ this_len = length - tbytes; log_debug_msg("re-read\ntrying to read missing %i bytes\n", this_len); } while (tbytes < length); + if (recv_buffer) { free(recv_buffer); } @@ -1114,13 +1072,13 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_ /** Command to start the desired service * - * @param control The lockdownd client + * @param client The lockdownd client * @param service The name of the service to start * @param port The port number the service was started on - * @return an error code + * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char *service, int *port) +iphone_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, int *port) { if (!client || !service || !port) return IPHONE_E_INVALID_ARG; @@ -1128,7 +1086,7 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char char *host_id = get_host_id(); if (!host_id) return IPHONE_E_INVALID_CONF; - if (!client->in_SSL && !lockdownd_start_SSL_session(client, host_id)) + if (!client->in_SSL && !lockdownd_start_ssl_session(client, host_id)) return IPHONE_E_SSL_ERROR; plist_t dict = NULL; @@ -1145,14 +1103,14 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char plist_add_sub_string_el(dict, service); /* send to iPhone */ - ret = iphone_lckd_send(client, dict); + ret = lockdownd_send(client, dict); plist_free(dict); dict = NULL; if (IPHONE_E_SUCCESS != ret) return ret; - ret = iphone_lckd_recv(client, &dict); + ret = lockdownd_recv(client, &dict); if (IPHONE_E_SUCCESS != ret) return ret; @@ -1161,47 +1119,33 @@ iphone_error_t iphone_lckd_start_service(iphone_lckd_client_t client, const char return IPHONE_E_PLIST_ERROR; ret = IPHONE_E_UNKNOWN_ERROR; - - plist_t query_node = plist_find_node_by_string(dict, "StartService"); - plist_t result_key_node = plist_get_next_sibling(query_node); - plist_t result_value_node = plist_get_next_sibling(result_key_node); - - plist_t port_key_node = plist_find_node_by_key(dict, "Port"); - plist_t port_value_node = plist_get_next_sibling(port_key_node); - - plist_type result_key_type = plist_get_node_type(result_key_node); - plist_type result_value_type = plist_get_node_type(result_value_node); - plist_type port_key_type = plist_get_node_type(port_key_node); - plist_type port_value_type = plist_get_node_type(port_value_node); - - if (result_key_type == PLIST_KEY && result_value_type == PLIST_STRING) { - char *result_key = NULL; - char *result_value = NULL; - char *port_key = NULL; - uint64_t port_value = 0; - - plist_get_key_val(result_key_node, &result_key); - plist_get_string_val(result_value_node, &result_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Failure")) { - ret = IPHONE_E_START_SERVICE_FAILED; - } else { - if (port_key_type == PLIST_KEY && port_value_type == PLIST_UINT) { - plist_get_key_val(port_key_node, &port_key); - plist_get_uint_val(port_value_node, &port_value); - - if (!strcmp(result_key, "Result") && !strcmp(result_value, "Success") && !strcmp(port_key, "Port")) { - port_loc = port_value; - ret = IPHONE_E_SUCCESS; - } - - if (port && ret == IPHONE_E_SUCCESS) - *port = port_loc; + if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { + plist_t port_key_node = plist_find_node_by_key(dict, "Port"); + plist_t port_value_node = plist_get_next_sibling(port_key_node); + + if ((plist_get_node_type(port_key_node) == PLIST_KEY) + && (plist_get_node_type(port_value_node) == PLIST_UINT)) { + char *port_key = NULL; + uint64_t port_value = 0; + + plist_get_key_val(port_key_node, &port_key); + plist_get_uint_val(port_value_node, &port_value); + if (port_key && !strcmp(port_key, "Port")) { + port_loc = port_value; + ret = IPHONE_E_SUCCESS; } + if (port_key) + free(port_key); + + if (port && ret == IPHONE_E_SUCCESS) + *port = port_loc; } } + else + ret = IPHONE_E_START_SERVICE_FAILED; plist_free(dict); dict = NULL; return ret; } + diff --git a/src/lockdown.h b/src/lockdown.h index 1f9d84c..185d27a 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -1,5 +1,5 @@ /* - * lockdown.h + * lockdownd.h * Defines lockdown stuff, like the client struct. * * Copyright (c) 2008 Zach C. All Rights Reserved. @@ -24,36 +24,22 @@ #include #include -#include +#include "libiphone/lockdown.h" - - - -struct iphone_lckd_client_int { +struct lockdownd_client_int { int sfd; gnutls_session_t *ssl_session; int in_SSL; char session_id[40]; }; -iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); -iphone_error_t lockdownd_hello(iphone_lckd_client_t control); - -iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, const char *req_string, - gnutls_datum_t * value); - -iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key); - +iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); iphone_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * device_cert, gnutls_datum_t * host_cert, gnutls_datum_t * root_cert); -iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, char *host_id); -void lockdownd_close(iphone_lckd_client_t control); // SSL functions - -iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const char *HostID); +iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char *HostID); ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_t length); ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size_t length); - #endif diff --git a/swig/iphone.i b/swig/iphone.i index 0a337ad..25687f5 100644 --- a/swig/iphone.i +++ b/swig/iphone.i @@ -4,15 +4,16 @@ %{ /* Includes the header in the wrapper code */ #include + #include #include -#include "../src/utils.h" + #include "../src/utils.h" typedef struct { iphone_device_t dev; } iPhone; typedef struct { iPhone* dev; - iphone_lckd_client_t client; + lockdownd_client_t client; } Lockdownd; typedef struct { @@ -44,7 +45,7 @@ typedef struct { typedef struct { iPhone* dev; - iphone_lckd_client_t client; + lockdownd_client_t client; } Lockdownd; typedef struct { @@ -68,7 +69,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); client->dev = phone; client->client = NULL; - if (IPHONE_E_SUCCESS == iphone_lckd_new_client ( phone->dev , &(client->client))) { + if (IPHONE_E_SUCCESS == lockdownd_new_client ( phone->dev , &(client->client))) { return client; } else { @@ -79,7 +80,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) { void my_delete_Lockdownd(Lockdownd* lckd) { if (lckd) { - iphone_lckd_free_client ( lckd->client ); + lockdownd_free_client ( lckd->client ); free(lckd); } } @@ -88,7 +89,7 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { if (!lckd || !lckd->dev) return NULL; MobileSync* client = NULL; int port = 0; - if (IPHONE_E_SUCCESS == iphone_lckd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { + if (IPHONE_E_SUCCESS == lockdownd_start_service ( lckd->client, "com.apple.mobilesync", &port )) { client = (MobileSync*) malloc(sizeof(MobileSync)); client->dev = lckd->dev; client->client = NULL; @@ -154,13 +155,13 @@ MobileSync* my_new_MobileSync(Lockdownd* lckd) { } void send(PListNode* node) { - iphone_lckd_send($self->client, node->node); + lockdownd_send($self->client, node->node); } PListNode* receive() { PListNode* node = (PListNode*)malloc(sizeof(PListNode)); node->node = NULL; - iphone_lckd_recv($self->client, &(node->node)); + lockdownd_recv($self->client, &(node->node)); return node; } -- cgit v1.1-32-gdbae From 5fa071717799ee2424c41b62360c7122b104fefb Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 10 Jul 2009 19:01:09 +0200 Subject: Use new plist_copy instead of serialization workaround in lockdownd_et_value() --- dev/lckdclient.c | 7 ++++--- src/lockdown.c | 12 +----------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/dev/lckdclient.c b/dev/lckdclient.c index e197002..e7ad962 100644 --- a/dev/lckdclient.c +++ b/dev/lckdclient.c @@ -74,19 +74,20 @@ int main(int argc, char *argv[]) loop = FALSE; if (!strcmp(*args, "get") && len >= 2) { - plist_t *value = NULL; + plist_t value = NULL; if (IPHONE_E_SUCCESS == lockdownd_get_value(client, len == 3 ? *(args + 1):NULL, len == 3 ? *(args + 2):*(args + 1), &value)) { char *xml = NULL; uint32_t length; plist_to_xml(value, &xml, &length); printf("Success : value = %s\n", xml); - free(xml); - free(value); } else printf("Error\n"); + + if (value) + plist_free(value); } if (!strcmp(*args, "start") && len == 2) { diff --git a/src/lockdown.c b/src/lockdown.c index 7e1f1a8..24283cb 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -445,14 +445,8 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain plist_get_key_val(value_key_node, &result_key); if (!strcmp(result_key, "Value")) { - char *buf = NULL; - uint32_t length; log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); - - /* FIXME: libplist does not offer cloning of nodes, use serialization */ - plist_to_bin(value_value_node, &buf, &length); - plist_from_bin(buf, length, value_node); - free(buf); + *value_node = plist_copy(value_value_node); } free(result_key); } @@ -469,7 +463,6 @@ iphone_error_t lockdownd_get_device_uid(lockdownd_client_t client, char **uid) { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t value = NULL; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "UniqueDeviceID", &value); if (ret != IPHONE_E_SUCCESS) { @@ -492,7 +485,6 @@ iphone_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls plist_t value = NULL; char *value_value = NULL; uint64_t size = 0; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "DevicePublicKey", &value); if (ret != IPHONE_E_SUCCESS) { @@ -519,14 +511,12 @@ iphone_error_t lockdownd_get_device_name(lockdownd_client_t client, char **devic { iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; plist_t value = NULL; - value = plist_new_dict(); ret = lockdownd_get_value(client, NULL, "DeviceName", &value); if (ret != IPHONE_E_SUCCESS) { return ret; } plist_get_string_val(value, device_name); - log_debug_msg("%s: %s\n", __func__, device_name); plist_free(value); value = NULL; -- cgit v1.1-32-gdbae From 484ff2166a2de58dd185a05fefea47a3f8165033 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Tue, 14 Jul 2009 14:21:53 +0200 Subject: Cleanup mobilesync API and bindings. Move get_all_contacts() into msyncclient. --- dev/msync.py | 2 +- dev/msyncclient.c | 109 ++++++++++++++++++++++++++++++++++-- include/Makefile.am | 6 +- include/libiphone/libiphone.h | 9 --- src/MobileSync.c | 125 +++++------------------------------------- src/MobileSync.h | 8 +-- swig/iphone.i | 15 ++--- 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 #include +#include + +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 - - -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 #include + #include #include #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; } }; -- cgit v1.1-32-gdbae From 0be7debdc3b08e07b7f8bc2e32fed6aed587e09d Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Wed, 15 Jul 2009 16:16:40 +0200 Subject: Implement lockdown set_value, remove_value and enter_recovery request API [#46 state:resolved] Signed-off-by: Matt Colyer --- include/libiphone/lockdown.h | 5 +- src/lockdown.c | 163 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 163 insertions(+), 5 deletions(-) diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h index 805c90b..20ccf77 100644 --- a/include/libiphone/lockdown.h +++ b/include/libiphone/lockdown.h @@ -34,7 +34,9 @@ typedef struct lockdownd_client_int *lockdownd_client_t; iphone_error_t lockdownd_new_client (iphone_device_t device, lockdownd_client_t *client); iphone_error_t lockdownd_free_client(lockdownd_client_t client); iphone_error_t lockdownd_query_type(lockdownd_client_t client); -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node); +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); +iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); +iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); iphone_error_t lockdownd_start_service (lockdownd_client_t client, const char *service, int *port); iphone_error_t lockdownd_stop_session(lockdownd_client_t client); iphone_error_t lockdownd_send (lockdownd_client_t client, plist_t plist); @@ -42,6 +44,7 @@ iphone_error_t lockdownd_recv (lockdownd_client_t client, plist_t *plist); iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_id); iphone_error_t lockdownd_get_device_uid (lockdownd_client_t control, char **uid); iphone_error_t lockdownd_get_device_name (lockdownd_client_t client, char **device_name); +iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client); iphone_error_t lockdownd_goodbye(lockdownd_client_t client); #ifdef __cplusplus diff --git a/src/lockdown.c b/src/lockdown.c index 24283cb..1a434aa 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -387,11 +387,11 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client) * @param client an initialized lockdownd client. * @param domain the domain to query on or NULL for global domain * @param key the key name to request or NULL to query for all keys - * @param value_node a plist node representing the result value node + * @param value a plist node representing the result value node * * @return an error code (IPHONE_E_SUCCESS on success) */ -iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value_node) +iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) { if (!client) return IPHONE_E_INVALID_ARG; @@ -427,7 +427,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain return ret; if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { - log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): success\n"); + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); ret = IPHONE_E_SUCCESS; } if (ret != IPHONE_E_SUCCESS) { @@ -446,7 +446,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain if (!strcmp(result_key, "Value")) { log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); - *value_node = plist_copy(value_value_node); + *value = plist_copy(value_value_node); } free(result_key); } @@ -455,6 +455,126 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain return ret; } +/** Sets a preferences value using a plist and optional domain and/or key name. + * + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to set the value or NULL to set a value dict plist + * @param value a plist node of any node type representing the value to set + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) +{ + if (!client || !value) + return IPHONE_E_INVALID_ARG; + + plist_t dict = NULL; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + /* setup request plist */ + dict = plist_new_dict(); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "SetValue"); + + plist_add_sub_key_el(dict, "Value"); + plist_add_sub_node(dict, value); + + /* send to device */ + ret = lockdownd_send(client, dict); + + plist_free(dict); + dict = NULL; + + if (ret != IPHONE_E_SUCCESS) + return ret; + + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); + if (ret != IPHONE_E_SUCCESS) + return ret; + + if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + + if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); + return ret; + } + + plist_free(dict); + return ret; +} + +/** Removes a preference node on the device by domain and/or key name + * + * @note: Use with caution as this could remove vital information on the device + * + * @param client an initialized lockdownd client. + * @param domain the domain to query on or NULL for global domain + * @param key the key name to remove or NULL remove all keys for the current domain + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) +{ + if (!client) + return IPHONE_E_INVALID_ARG; + + plist_t dict = NULL; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + /* setup request plist */ + dict = plist_new_dict(); + if (domain) { + plist_add_sub_key_el(dict, "Domain"); + plist_add_sub_string_el(dict, domain); + } + if (key) { + plist_add_sub_key_el(dict, "Key"); + plist_add_sub_string_el(dict, key); + } + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "RemoveValue"); + + /* send to device */ + ret = lockdownd_send(client, dict); + + plist_free(dict); + dict = NULL; + + if (ret != IPHONE_E_SUCCESS) + return ret; + + /* Now get device's answer */ + ret = lockdownd_recv(client, &dict); + if (ret != IPHONE_E_SUCCESS) + return ret; + + if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + + if (ret != IPHONE_E_SUCCESS) { + plist_free(dict); + return ret; + } + + plist_free(dict); + return ret; +} + /** Asks for the device's unique id. Part of the lockdownd handshake. * * @return an error code (IPHONE_E_SUCCESS on success) @@ -671,6 +791,41 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i return ret; } +/** + * Tells the device to immediately enter recovery mode. + * + * @param client The lockdown client + * + * @return an error code (IPHONE_E_SUCCESS on success) + */ +iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client) +{ + if (!client) + return IPHONE_E_INVALID_ARG; + + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + plist_t dict = plist_new_dict(); + plist_add_sub_key_el(dict, "Request"); + plist_add_sub_string_el(dict, "EnterRecovery"); + + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Telling device to enter recovery mode\n", __func__); + + ret = lockdownd_send(client, dict); + plist_free(dict); + dict = NULL; + + ret = lockdownd_recv(client, &dict); + + if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { + log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__); + ret = IPHONE_E_SUCCESS; + } + plist_free(dict); + dict = NULL; + return ret; +} + /** * Performs the Goodbye Request to tell the device the communication * session is now closed. -- cgit v1.1-32-gdbae