summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar Matt Colyer2008-09-01 15:04:31 -0700
committerGravatar Matt Colyer2008-09-01 15:04:31 -0700
commit2b05e48cb4a90dfc94ff584124f08e431398bb1a (patch)
treee0c8255e2cd5592a31295ac8ce89d8846feb7043 /src/main.c
parent7ac3d681889a6a8f9987837ace5465f2967cfff9 (diff)
downloadlibimobiledevice-2b05e48cb4a90dfc94ff584124f08e431398bb1a.tar.gz
libimobiledevice-2b05e48cb4a90dfc94ff584124f08e431398bb1a.tar.bz2
Enforce a modified kr style.
Use "make indent" from now on before committing.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c78
1 files changed, 45 insertions, 33 deletions
diff --git a/src/main.c b/src/main.c
index dd6e51b..c38103d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,23 +34,24 @@
34 34
35int debug = 1; 35int debug = 1;
36 36
37int main(int argc, char *argv[]) { 37int main(int argc, char *argv[])
38{
38 int bytes = 0, port = 0, i = 0; 39 int bytes = 0, port = 0, i = 0;
39 iphone_lckd_client_t control = NULL; 40 iphone_lckd_client_t control = NULL;
40 iphone_device_t phone = NULL; 41 iphone_device_t phone = NULL;
41 42
42 if (argc > 1 && !strcasecmp(argv[1], "--debug")){ 43 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
43 debug = 1; 44 debug = 1;
44 } else { 45 } else {
45 debug = 0; 46 debug = 0;
46 } 47 }
47 48
48 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { 49 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
49 printf("No iPhone found, is it plugged in?\n"); 50 printf("No iPhone found, is it plugged in?\n");
50 return -1; 51 return -1;
51 } 52 }
52 53
53 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)){ 54 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
54 iphone_free_device(phone); 55 iphone_free_device(phone);
55 return -1; 56 return -1;
56 } 57 }
@@ -62,34 +63,36 @@ int main(int argc, char *argv[]) {
62 } 63 }
63 64
64 iphone_lckd_start_service(control, "com.apple.afc", &port); 65 iphone_lckd_start_service(control, "com.apple.afc", &port);
65 66
66 if (port) { 67 if (port) {
67 iphone_afc_client_t afc = NULL; 68 iphone_afc_client_t afc = NULL;
68 iphone_afc_new_client(phone, 3432, port, &afc); 69 iphone_afc_new_client(phone, 3432, port, &afc);
69 if (afc) { 70 if (afc) {
70 char **dirs = NULL; 71 char **dirs = NULL;
71 iphone_afc_get_dir_list(afc, "/eafaedf", &dirs); 72 iphone_afc_get_dir_list(afc, "/eafaedf", &dirs);
72 if (!dirs) iphone_afc_get_dir_list(afc, "/", &dirs); 73 if (!dirs)
74 iphone_afc_get_dir_list(afc, "/", &dirs);
73 printf("Directory time.\n"); 75 printf("Directory time.\n");
74 for (i = 0; dirs[i]; i++) { 76 for (i = 0; dirs[i]; i++) {
75 printf("/%s\n", dirs[i]); 77 printf("/%s\n", dirs[i]);
76 } 78 }
77 79
78 g_strfreev(dirs); 80 g_strfreev(dirs);
79 iphone_afc_get_devinfo(afc, &dirs); 81 iphone_afc_get_devinfo(afc, &dirs);
80 if (dirs) { 82 if (dirs) {
81 for (i = 0; dirs[i]; i+=2) { 83 for (i = 0; dirs[i]; i += 2) {
82 printf("%s: %s\n", dirs[i], dirs[i+1]); 84 printf("%s: %s\n", dirs[i], dirs[i + 1]);
83 } 85 }
84 } 86 }
85 g_strfreev(dirs); 87 g_strfreev(dirs);
86 88
87 iphone_afc_file_t my_file = NULL; 89 iphone_afc_file_t my_file = NULL;
88 struct stat stbuf; 90 struct stat stbuf;
89 iphone_afc_get_file_attr ( afc, "/iTunesOnTheGoPlaylist.plist", &stbuf ); 91 iphone_afc_get_file_attr(afc, "/iTunesOnTheGoPlaylist.plist", &stbuf);
90 if (IPHONE_E_SUCCESS == iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) { 92 if (IPHONE_E_SUCCESS ==
93 iphone_afc_open_file(afc, "/iTunesOnTheGoPlaylist.plist", IPHONE_AFC_FILE_READ, &my_file) && my_file) {
91 printf("A file size: %i\n", stbuf.st_size); 94 printf("A file size: %i\n", stbuf.st_size);
92 char *file_data = (char*)malloc(sizeof(char) * stbuf.st_size); 95 char *file_data = (char *) malloc(sizeof(char) * stbuf.st_size);
93 iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes); 96 iphone_afc_read_file(afc, my_file, file_data, stbuf.st_size, &bytes);
94 if (bytes >= 0) { 97 if (bytes >= 0) {
95 printf("The file's data:\n"); 98 printf("The file's data:\n");
@@ -98,49 +101,58 @@ int main(int argc, char *argv[]) {
98 printf("\nClosing my file.\n"); 101 printf("\nClosing my file.\n");
99 iphone_afc_close_file(afc, my_file); 102 iphone_afc_close_file(afc, my_file);
100 free(file_data); 103 free(file_data);
101 } else printf("couldn't open a file\n"); 104 } else
102 105 printf("couldn't open a file\n");
106
103 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_WRITE, &my_file); 107 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_WRITE, &my_file);
104 if (my_file) { 108 if (my_file) {
105 char *outdatafile = strdup("this is a bitchin text file\n"); 109 char *outdatafile = strdup("this is a bitchin text file\n");
106 iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes); 110 iphone_afc_write_file(afc, my_file, outdatafile, strlen(outdatafile), &bytes);
107 free(outdatafile); 111 free(outdatafile);
108 if (bytes > 0) printf("Wrote a surprise. ;)\n"); 112 if (bytes > 0)
109 else printf("I wanted to write a surprise, but... :(\n"); 113 printf("Wrote a surprise. ;)\n");
114 else
115 printf("I wanted to write a surprise, but... :(\n");
110 iphone_afc_close_file(afc, my_file); 116 iphone_afc_close_file(afc, my_file);
111 } 117 }
112 printf("Deleting a file...\n"); 118 printf("Deleting a file...\n");
113 bytes = iphone_afc_delete_file(afc, "/delme"); 119 bytes = iphone_afc_delete_file(afc, "/delme");
114 if (bytes) printf("Success.\n"); 120 if (bytes)
115 else printf("Failure. (expected unless you have a /delme file on your phone)\n"); 121 printf("Success.\n");
116 122 else
123 printf("Failure. (expected unless you have a /delme file on your phone)\n");
124
117 printf("Renaming a file...\n"); 125 printf("Renaming a file...\n");
118 bytes = iphone_afc_rename_file(afc, "/renme", "/renme2"); 126 bytes = iphone_afc_rename_file(afc, "/renme", "/renme2");
119 if (bytes > 0) printf("Success.\n"); 127 if (bytes > 0)
120 else printf("Failure. (expected unless you have a /renme file on your phone)\n"); 128 printf("Success.\n");
121 129 else
130 printf("Failure. (expected unless you have a /renme file on your phone)\n");
131
122 printf("Seek & read\n"); 132 printf("Seek & read\n");
123 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_READ, &my_file); 133 iphone_afc_open_file(afc, "/readme.libiphone.fx", IPHONE_AFC_FILE_READ, &my_file);
124 if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5)) printf("WARN: SEEK DID NOT WORK\n"); 134 if (IPHONE_E_SUCCESS != iphone_afc_seek_file(afc, my_file, 5))
125 char *threeletterword = (char*)malloc(sizeof(char) * 5); 135 printf("WARN: SEEK DID NOT WORK\n");
136 char *threeletterword = (char *) malloc(sizeof(char) * 5);
126 iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes); 137 iphone_afc_read_file(afc, my_file, threeletterword, 3, &bytes);
127 threeletterword[3] = '\0'; 138 threeletterword[3] = '\0';
128 if (bytes > 0) printf("Result: %s\n", threeletterword); 139 if (bytes > 0)
129 else printf("Couldn't read!\n"); 140 printf("Result: %s\n", threeletterword);
141 else
142 printf("Couldn't read!\n");
130 free(threeletterword); 143 free(threeletterword);
131 iphone_afc_close_file(afc, my_file); 144 iphone_afc_close_file(afc, my_file);
132 145
133 } 146 }
134 iphone_afc_free_client(afc); 147 iphone_afc_free_client(afc);
135 } else { 148 } else {
136 printf("Start service failure.\n"); 149 printf("Start service failure.\n");
137 } 150 }
138 151
139 printf("All done.\n"); 152 printf("All done.\n");
140 153
141 iphone_lckd_free_client(control); 154 iphone_lckd_free_client(control);
142 iphone_free_device(phone); 155 iphone_free_device(phone);
143 156
144 return 0; 157 return 0;
145} 158}
146