summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/src/main.c b/src/main.c
index 78c62f7..85405dd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -29,17 +29,15 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
-#include "plist.h"
-#include "lockdown.h"
-#include "AFC.h"
-#include "userpref.h"
+
+#include <libiphone/libiphone.h>
int debug = 1;
int main(int argc, char *argv[]) {
int bytes = 0, port = 0, i = 0;
- lockdownd_client *control = NULL;
- iPhone *phone = get_iPhone();
+ iphone_lckd_client_t control = NULL;
+ iphone_device_t phone = NULL;
if (argc > 1 && !strcasecmp(argv[1], "--debug")){
debug = 1;
@@ -47,13 +45,13 @@ int main(int argc, char *argv[]) {
debug = 0;
}
- if (!phone) {
+ if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
printf("No iPhone found, is it plugged in?\n");
return -1;
}
- if (!lockdownd_init(phone, &control)){
- free_iPhone(phone);
+ if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)){
+ iphone_free_device(phone);
return -1;
}
@@ -63,21 +61,22 @@ int main(int argc, char *argv[]) {
free(uid);
}
- port = lockdownd_start_service(control, "com.apple.afc");
+ port = iphone_lckd_start_service(control, "com.apple.afc");
if (port) {
- AFClient *afc = afc_connect(phone, 3432, port);
+ iphone_afc_client_t afc = NULL;
+ iphone_afc_new_client(phone, 3432, port, &afc);
if (afc) {
char **dirs;
- dirs = afc_get_dir_list(afc, "/eafaedf");
- if (!dirs) dirs = afc_get_dir_list(afc, "/");
+ dirs = iphone_afc_get_dir_list(afc, "/eafaedf");
+ if (!dirs) dirs = iphone_afc_get_dir_list(afc, "/");
printf("Directory time.\n");
for (i = 0; dirs[i]; i++) {
printf("/%s\n", dirs[i]);
}
g_strfreev(dirs);
- dirs = afc_get_devinfo(afc);
+ dirs = iphone_afc_get_devinfo(afc);
if (dirs) {
for (i = 0; dirs[i]; i+=2) {
printf("%s: %s\n", dirs[i], dirs[i+1]);
@@ -85,64 +84,63 @@ int main(int argc, char *argv[]) {
}
g_strfreev(dirs);
- AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ);
- if (my_file) {
- printf("A file size: %i\n", my_file->size);
- char *file_data = (char*)malloc(sizeof(char) * my_file->size);
- bytes = afc_read_file(afc, my_file, file_data, my_file->size);
+ iphone_afc_file_t my_file = NULL;
+ struct stat stbuf;
+ iphone_afc_get_file_attr ( afc, "/iTunesOnTheGoPlaylist.plist", &stbuf );
+ if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ, &my_file) && my_file) {
+ printf("A file size: %i\n", stbuf.st_size);
+ char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size);
+ bytes = iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size);
if (bytes >= 0) {
printf("The file's data:\n");
fwrite(file_data, 1, bytes, stdout);
}
printf("\nClosing my file.\n");
- afc_close_file(afc, my_file);
- free(my_file);
+ iphone_afc_close_file(afc, my_file);
free(file_data);
} else printf("couldn't open a file\n");
- my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE);
+ iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE, &my_file);
if (my_file) {
char *outdatafile = strdup("this is a bitchin text file\n");
- bytes = afc_write_file(afc, my_file, outdatafile, strlen(outdatafile));
+ bytes = iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile));
free(outdatafile);
if (bytes > 0) printf("Wrote a surprise. ;)\n");
else printf("I wanted to write a surprise, but... :(\n");
- afc_close_file(afc, my_file);
- free(my_file);
+ iphone_afc_close_file(afc, my_file);
}
printf("Deleting a file...\n");
- bytes = afc_delete_file(afc, "/delme");
+ bytes = iphone_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 = afc_rename_file(afc, "/renme", "/renme2");
+ bytes = iphone_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");
- my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ);
- bytes = afc_seek_file(afc, my_file, 5);
+ iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ, &my_file);
+ bytes = iphone_afc_seek_file(afc, my_file, 5);
if (bytes) printf("WARN: SEEK DID NOT WORK\n");
char *threeletterword = (char*)malloc(sizeof(char) * 5);
- bytes = afc_read_file(afc, my_file, threeletterword, 3);
+ bytes = iphone_afc_read_file(afc, my_file, threeletterword, 3);
threeletterword[3] = '\0';
if (bytes > 0) printf("Result: %s\n", threeletterword);
else printf("Couldn't read!\n");
free(threeletterword);
- afc_close_file(afc, my_file);
- free(my_file);
+ iphone_afc_close_file(afc, my_file);
}
- afc_disconnect(afc);
+ iphone_afc_free_client(afc);
} else {
printf("Start service failure.\n");
}
printf("All done.\n");
- lockdownd_close(control);
- free_iPhone(phone);
+ iphone_lckd_free_client(control);
+ iphone_free_device(phone);
return 0;
}