diff options
Diffstat (limited to 'dev/afccheck.c')
| -rw-r--r-- | dev/afccheck.c | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c deleted file mode 100644 index b4d8910..0000000 --- a/dev/afccheck.c +++ /dev/null | |||
| @@ -1,146 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * afccheck.c | ||
| 3 | * creates threads and check communication through AFC is done rigth | ||
| 4 | * | ||
| 5 | * Copyright (c) 2008 Jonathan Beck All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdlib.h> | ||
| 23 | #include <stdio.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <glib.h> | ||
| 26 | |||
| 27 | #include <libimobiledevice/libimobiledevice.h> | ||
| 28 | #include <libimobiledevice/lockdown.h> | ||
| 29 | #include <libimobiledevice/afc.h> | ||
| 30 | |||
| 31 | #define BUFFER_SIZE 20000 | ||
| 32 | #define NB_THREADS 10 | ||
| 33 | |||
| 34 | |||
| 35 | typedef struct { | ||
| 36 | afc_client_t afc; | ||
| 37 | int id; | ||
| 38 | } param; | ||
| 39 | |||
| 40 | |||
| 41 | static void check_afc(gpointer data) | ||
| 42 | { | ||
| 43 | //prepare a buffer | ||
| 44 | unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); | ||
| 45 | int *buf = (int *) malloc(buffersize); | ||
| 46 | int *buf2 = (int *) malloc(buffersize); | ||
| 47 | unsigned int bytes = 0; | ||
| 48 | uint64_t position = 0; | ||
| 49 | |||
| 50 | //fill buffer | ||
| 51 | int i = 0; | ||
| 52 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 53 | buf[i] = ((param *) data)->id * i; | ||
| 54 | } | ||
| 55 | |||
| 56 | //now writes buffer on device | ||
| 57 | uint64_t file = 0; | ||
| 58 | char path[50]; | ||
| 59 | sprintf(path, "/Buf%i", ((param *) data)->id); | ||
| 60 | afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RW, &file); | ||
| 61 | afc_file_write(((param *) data)->afc, file, (char *) buf, buffersize, &bytes); | ||
| 62 | afc_file_close(((param *) data)->afc, file); | ||
| 63 | file = 0; | ||
| 64 | if (bytes != buffersize) | ||
| 65 | printf("Write operation failed\n"); | ||
| 66 | |||
| 67 | //now read it | ||
| 68 | bytes = 0; | ||
| 69 | afc_file_open(((param *) data)->afc, path, AFC_FOPEN_RDONLY, &file); | ||
| 70 | afc_file_read(((param *) data)->afc, file, (char *) buf2, buffersize/2, &bytes); | ||
| 71 | afc_file_read(((param *) data)->afc, file, (char *) buf2 + (buffersize/2), buffersize/2, &bytes); | ||
| 72 | if(AFC_E_SUCCESS != afc_file_tell(((param *) data)->afc, file, &position)) | ||
| 73 | printf("Tell operation failed\n"); | ||
| 74 | afc_file_close(((param *) data)->afc, file); | ||
| 75 | if (position != buffersize) | ||
| 76 | printf("Read operation failed\n"); | ||
| 77 | |||
| 78 | //compare buffers | ||
| 79 | for (i = 0; i < BUFFER_SIZE; i++) { | ||
| 80 | if (buf[i] != buf2[i]) { | ||
| 81 | printf("Buffers are differents, stream corrupted\n"); | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | //cleanup | ||
| 87 | afc_remove_path(((param *) data)->afc, path); | ||
| 88 | g_thread_exit(0); | ||
| 89 | } | ||
| 90 | |||
| 91 | int main(int argc, char *argv[]) | ||
| 92 | { | ||
| 93 | lockdownd_client_t client = NULL; | ||
| 94 | idevice_t phone = NULL; | ||
| 95 | GError *err; | ||
| 96 | uint16_t port = 0; | ||
| 97 | afc_client_t afc = NULL; | ||
| 98 | |||
| 99 | if (argc > 1 && !strcasecmp(argv[1], "--debug")) { | ||
| 100 | idevice_set_debug_level(1); | ||
| 101 | } else { | ||
| 102 | idevice_set_debug_level(0); | ||
| 103 | } | ||
| 104 | |||
| 105 | if (IDEVICE_E_SUCCESS != idevice_new(&phone, NULL)) { | ||
| 106 | printf("No device found, is it plugged in?\n"); | ||
| 107 | return 1; | ||
| 108 | } | ||
| 109 | |||
| 110 | if (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(phone, &client, "afccheck")) { | ||
| 111 | idevice_free(phone); | ||
| 112 | return 1; | ||
| 113 | } | ||
| 114 | |||
| 115 | if (LOCKDOWN_E_SUCCESS == lockdownd_start_service(client, "com.apple.afc", &port) && !port) { | ||
| 116 | lockdownd_client_free(client); | ||
| 117 | idevice_free(phone); | ||
| 118 | fprintf(stderr, "Something went wrong when starting AFC."); | ||
| 119 | return 1; | ||
| 120 | } | ||
| 121 | |||
| 122 | afc_client_new(phone, port, &afc); | ||
| 123 | |||
| 124 | //makes sure thread environment is available | ||
| 125 | if (!g_thread_supported()) | ||
| 126 | g_thread_init(NULL); | ||
| 127 | |||
| 128 | GThread *threads[NB_THREADS]; | ||
| 129 | param data[NB_THREADS]; | ||
| 130 | |||
| 131 | int i = 0; | ||
| 132 | for (i = 0; i < NB_THREADS; i++) { | ||
| 133 | data[i].afc = afc; | ||
| 134 | data[i].id = i + 1; | ||
| 135 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | ||
| 136 | } | ||
| 137 | |||
| 138 | for (i = 0; i < NB_THREADS; i++) { | ||
| 139 | g_thread_join(threads[i]); | ||
| 140 | } | ||
| 141 | |||
| 142 | lockdownd_client_free(client); | ||
| 143 | idevice_free(phone); | ||
| 144 | |||
| 145 | return 0; | ||
| 146 | } | ||
