summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-08-25 23:25:56 +0200
committerGravatar Jonathan Beck2008-08-31 19:32:27 +0200
commit6ac4ceb4c6ee63c279f4841381a3eb09598f3517 (patch)
tree37de86e9d99a56c2e4ef1e7b5db28bd252cd4a39 /src/main.c
parentc042f7ca2731fa5c8a5aa13789f5901ae5a3af7a (diff)
downloadlibimobiledevice-6ac4ceb4c6ee63c279f4841381a3eb09598f3517.tar.gz
libimobiledevice-6ac4ceb4c6ee63c279f4841381a3eb09598f3517.tar.bz2
migrate main.c
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 @@
29 29
30#include <libxml/parser.h> 30#include <libxml/parser.h>
31#include <libxml/tree.h> 31#include <libxml/tree.h>
32#include "plist.h" 32
33#include "lockdown.h" 33#include <libiphone/libiphone.h>
34#include "AFC.h"
35#include "userpref.h"
36 34
37int debug = 1; 35int debug = 1;
38 36
39int main(int argc, char *argv[]) { 37int main(int argc, char *argv[]) {
40 int bytes = 0, port = 0, i = 0; 38 int bytes = 0, port = 0, i = 0;
41 lockdownd_client *control = NULL; 39 iphone_lckd_client_t control = NULL;
42 iPhone *phone = get_iPhone(); 40 iphone_device_t phone = NULL;
43 41
44 if (argc > 1 && !strcasecmp(argv[1], "--debug")){ 42 if (argc > 1 && !strcasecmp(argv[1], "--debug")){
45 debug = 1; 43 debug = 1;
@@ -47,13 +45,13 @@ int main(int argc, char *argv[]) {
47 debug = 0; 45 debug = 0;
48 } 46 }
49 47
50 if (!phone) { 48 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
51 printf("No iPhone found, is it plugged in?\n"); 49 printf("No iPhone found, is it plugged in?\n");
52 return -1; 50 return -1;
53 } 51 }
54 52
55 if (!lockdownd_init(phone, &control)){ 53 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)){
56 free_iPhone(phone); 54 iphone_free_device(phone);
57 return -1; 55 return -1;
58 } 56 }
59 57
@@ -63,21 +61,22 @@ int main(int argc, char *argv[]) {
63 free(uid); 61 free(uid);
64 } 62 }
65 63
66 port = lockdownd_start_service(control, "com.apple.afc"); 64 port = iphone_lckd_start_service(control, "com.apple.afc");
67 65
68 if (port) { 66 if (port) {
69 AFClient *afc = afc_connect(phone, 3432, port); 67 iphone_afc_client_t afc = NULL;
68 iphone_afc_new_client(phone, 3432, port, &afc);
70 if (afc) { 69 if (afc) {
71 char **dirs; 70 char **dirs;
72 dirs = afc_get_dir_list(afc, "/eafaedf"); 71 dirs = iphone_afc_get_dir_list(afc, "/eafaedf");
73 if (!dirs) dirs = afc_get_dir_list(afc, "/"); 72 if (!dirs) dirs = iphone_afc_get_dir_list(afc, "/");
74 printf("Directory time.\n"); 73 printf("Directory time.\n");
75 for (i = 0; dirs[i]; i++) { 74 for (i = 0; dirs[i]; i++) {
76 printf("/%s\n", dirs[i]); 75 printf("/%s\n", dirs[i]);
77 } 76 }
78 77
79 g_strfreev(dirs); 78 g_strfreev(dirs);
80 dirs = afc_get_devinfo(afc); 79 dirs = iphone_afc_get_devinfo(afc);
81 if (dirs) { 80 if (dirs) {
82 for (i = 0; dirs[i]; i+=2) { 81 for (i = 0; dirs[i]; i+=2) {
83 printf("%s: %s\n", dirs[i], dirs[i+1]); 82 printf("%s: %s\n", dirs[i], dirs[i+1]);
@@ -85,64 +84,63 @@ int main(int argc, char *argv[]) {
85 } 84 }
86 g_strfreev(dirs); 85 g_strfreev(dirs);
87 86
88 AFCFile *my_file = afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ); 87 iphone_afc_file_t my_file = NULL;
89 if (my_file) { 88 struct stat stbuf;
90 printf("A file size: %i\n", my_file->size); 89 iphone_afc_get_file_attr ( afc, "/iTunesOnTheGoPlaylist.plist", &stbuf );
91 char *file_data = (char*)malloc(sizeof(char) * my_file->size); 90 if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", AFC_FILE_READ, &my_file) && my_file) {
92 bytes = afc_read_file(afc, my_file, file_data, my_file->size); 91 printf("A file size: %i\n", stbuf.st_size);
92 char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size);
93 bytes = iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size);
93 if (bytes >= 0) { 94 if (bytes >= 0) {
94 printf("The file's data:\n"); 95 printf("The file's data:\n");
95 fwrite(file_data, 1, bytes, stdout); 96 fwrite(file_data, 1, bytes, stdout);
96 } 97 }
97 printf("\nClosing my file.\n"); 98 printf("\nClosing my file.\n");
98 afc_close_file(afc, my_file); 99 iphone_afc_close_file(afc, my_file);
99 free(my_file);
100 free(file_data); 100 free(file_data);
101 } else printf("couldn't open a file\n"); 101 } else printf("couldn't open a file\n");
102 102
103 my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE); 103 iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_WRITE, &my_file);
104 if (my_file) { 104 if (my_file) {
105 char *outdatafile = strdup("this is a bitchin text file\n"); 105 char *outdatafile = strdup("this is a bitchin text file\n");
106 bytes = afc_write_file(afc, my_file, outdatafile, strlen(outdatafile)); 106 bytes = iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile));
107 free(outdatafile); 107 free(outdatafile);
108 if (bytes > 0) printf("Wrote a surprise. ;)\n"); 108 if (bytes > 0) printf("Wrote a surprise. ;)\n");
109 else printf("I wanted to write a surprise, but... :(\n"); 109 else printf("I wanted to write a surprise, but... :(\n");
110 afc_close_file(afc, my_file); 110 iphone_afc_close_file(afc, my_file);
111 free(my_file);
112 } 111 }
113 printf("Deleting a file...\n"); 112 printf("Deleting a file...\n");
114 bytes = afc_delete_file(afc, "/delme"); 113 bytes = iphone_afc_delete_file(afc, "/delme");
115 if (bytes) printf("Success.\n"); 114 if (bytes) printf("Success.\n");
116 else printf("Failure. (expected unless you have a /delme file on your phone)\n"); 115 else printf("Failure. (expected unless you have a /delme file on your phone)\n");
117 116
118 printf("Renaming a file...\n"); 117 printf("Renaming a file...\n");
119 bytes = afc_rename_file(afc, "/renme", "/renme2"); 118 bytes = iphone_afc_rename_file(afc, "/renme", "/renme2");
120 if (bytes > 0) printf("Success.\n"); 119 if (bytes > 0) printf("Success.\n");
121 else printf("Failure. (expected unless you have a /renme file on your phone)\n"); 120 else printf("Failure. (expected unless you have a /renme file on your phone)\n");
122 121
123 printf("Seek & read\n"); 122 printf("Seek & read\n");
124 my_file = afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ); 123 iphone_afc_open_file(afc, "/readme.libiphone.fx", AFC_FILE_READ, &my_file);
125 bytes = afc_seek_file(afc, my_file, 5); 124 bytes = iphone_afc_seek_file(afc, my_file, 5);
126 if (bytes) printf("WARN: SEEK DID NOT WORK\n"); 125 if (bytes) printf("WARN: SEEK DID NOT WORK\n");
127 char *threeletterword = (char*)malloc(sizeof(char) * 5); 126 char *threeletterword = (char*)malloc(sizeof(char) * 5);
128 bytes = afc_read_file(afc, my_file, threeletterword, 3); 127 bytes = iphone_afc_read_file(afc, my_file, threeletterword, 3);
129 threeletterword[3] = '\0'; 128 threeletterword[3] = '\0';
130 if (bytes > 0) printf("Result: %s\n", threeletterword); 129 if (bytes > 0) printf("Result: %s\n", threeletterword);
131 else printf("Couldn't read!\n"); 130 else printf("Couldn't read!\n");
132 free(threeletterword); 131 free(threeletterword);
133 afc_close_file(afc, my_file); 132 iphone_afc_close_file(afc, my_file);
134 free(my_file);
135 133
136 } 134 }
137 afc_disconnect(afc); 135 iphone_afc_free_client(afc);
138 } else { 136 } else {
139 printf("Start service failure.\n"); 137 printf("Start service failure.\n");
140 } 138 }
141 139
142 printf("All done.\n"); 140 printf("All done.\n");
143 141
144 lockdownd_close(control); 142 iphone_lckd_free_client(control);
145 free_iPhone(phone); 143 iphone_free_device(phone);
146 144
147 return 0; 145 return 0;
148} 146}