diff options
Diffstat (limited to 'dev/filerelaytest.c')
| -rw-r--r-- | dev/filerelaytest.c | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/dev/filerelaytest.c b/dev/filerelaytest.c deleted file mode 100644 index 6983f1d..0000000 --- a/dev/filerelaytest.c +++ /dev/null | |||
| @@ -1,151 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * filerelaytest.c | ||
| 3 | * Simple Test program showing the usage of the file_relay interface. | ||
| 4 | * | ||
| 5 | * Copyright (c) 2010 Nikias Bassen 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 | #include <errno.h> | ||
| 22 | #include <stdio.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <string.h> | ||
| 25 | #include <libimobiledevice/libimobiledevice.h> | ||
| 26 | #include <libimobiledevice/lockdown.h> | ||
| 27 | #include <libimobiledevice/file_relay.h> | ||
| 28 | |||
| 29 | int main(int argc, char **argv) | ||
| 30 | { | ||
| 31 | idevice_t dev = NULL; | ||
| 32 | lockdownd_client_t client = NULL; | ||
| 33 | lockdownd_service_descriptor_t service = NULL; | ||
| 34 | file_relay_client_t frc = NULL; | ||
| 35 | file_relay_error_t frc_error = FILE_RELAY_E_SUCCESS; | ||
| 36 | idevice_connection_t dump = NULL; | ||
| 37 | const char **sources; | ||
| 38 | const char *default_sources[] = {"AppleSupport", "Network", "VPN", "WiFi", "UserDatabases", "CrashReporter", "tmp", "SystemConfiguration", NULL}; | ||
| 39 | int i = 0; | ||
| 40 | |||
| 41 | if (idevice_new(&dev, NULL) != IDEVICE_E_SUCCESS) { | ||
| 42 | printf("No device connected?!\n"); | ||
| 43 | goto leave_cleanup; | ||
| 44 | } | ||
| 45 | |||
| 46 | printf("Connecting...\n"); | ||
| 47 | if (lockdownd_client_new_with_handshake(dev, &client, NULL) != LOCKDOWN_E_SUCCESS) { | ||
| 48 | printf("Could not connect to lockdownd!\n"); | ||
| 49 | goto leave_cleanup; | ||
| 50 | } | ||
| 51 | |||
| 52 | if (lockdownd_start_service(client, FILE_RELAY_SERVICE_NAME, &service) != LOCKDOWN_E_SUCCESS) { | ||
| 53 | printf("Could not start file_relay service!\n"); | ||
| 54 | goto leave_cleanup; | ||
| 55 | } | ||
| 56 | |||
| 57 | if (client) { | ||
| 58 | lockdownd_client_free(client); | ||
| 59 | client = NULL; | ||
| 60 | } | ||
| 61 | |||
| 62 | if (file_relay_client_new(dev, service, &frc) != FILE_RELAY_E_SUCCESS) { | ||
| 63 | printf("Could not connect to file_relay service!\n"); | ||
| 64 | goto leave_cleanup; | ||
| 65 | } | ||
| 66 | |||
| 67 | if (service) { | ||
| 68 | lockdownd_service_descriptor_free(service); | ||
| 69 | service = NULL; | ||
| 70 | } | ||
| 71 | |||
| 72 | if (argc > 1) { | ||
| 73 | sources = calloc(1, argc * sizeof(char *)); | ||
| 74 | argc--; | ||
| 75 | argv++; | ||
| 76 | for (i = 0; i < argc; i++) { | ||
| 77 | sources[i] = argv[i]; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | else { | ||
| 81 | sources = default_sources; | ||
| 82 | } | ||
| 83 | |||
| 84 | printf("Requesting "); | ||
| 85 | i = 0; | ||
| 86 | while (sources[i]) { | ||
| 87 | printf(" %s", sources[i]); | ||
| 88 | i++; | ||
| 89 | if (sources[i]) | ||
| 90 | printf(","); | ||
| 91 | } | ||
| 92 | printf("\n"); | ||
| 93 | |||
| 94 | frc_error = file_relay_request_sources(frc, sources, &dump); | ||
| 95 | if (frc_error != FILE_RELAY_E_SUCCESS) { | ||
| 96 | printf("Could not request sources.\n"); | ||
| 97 | switch (frc_error) { | ||
| 98 | case FILE_RELAY_E_INVALID_SOURCE: | ||
| 99 | printf("At least one of the given sources is invalid and was rejected.\n"); | ||
| 100 | break; | ||
| 101 | case FILE_RELAY_E_STAGING_EMPTY: | ||
| 102 | printf("Staging is empty. Perhaps there is no data for the requested sources available.\n"); | ||
| 103 | break; | ||
| 104 | case FILE_RELAY_E_PERMISSION_DENIED: | ||
| 105 | printf("Permission denied by device. Possibly missing a signed preferences profile.\n"); | ||
| 106 | break; | ||
| 107 | default: | ||
| 108 | printf("An unknown error occoured.\n"); | ||
| 109 | break; | ||
| 110 | } | ||
| 111 | goto leave_cleanup; | ||
| 112 | } | ||
| 113 | |||
| 114 | if (!dump) { | ||
| 115 | printf("Did not get connection!\n"); | ||
| 116 | goto leave_cleanup; | ||
| 117 | } | ||
| 118 | |||
| 119 | uint32_t cnt = 0; | ||
| 120 | uint32_t len = 0; | ||
| 121 | char buf[4096]; | ||
| 122 | FILE *f = fopen("dump.cpio.gz", "wb"); | ||
| 123 | if (!f) { | ||
| 124 | fprintf(stderr, "dump.cpio.gz: %s\n", strerror(errno)); | ||
| 125 | return EXIT_FAILURE; | ||
| 126 | } | ||
| 127 | setbuf(stdout, NULL); | ||
| 128 | printf("Receiving "); | ||
| 129 | while (idevice_connection_receive(dump, buf, 4096, &len) == IDEVICE_E_SUCCESS) { | ||
| 130 | fwrite(buf, 1, len, f); | ||
| 131 | cnt += len; | ||
| 132 | printf("."); | ||
| 133 | len = 0; | ||
| 134 | } | ||
| 135 | printf("\n"); | ||
| 136 | fclose(f); | ||
| 137 | printf("Total size received: %d\n", cnt); | ||
| 138 | |||
| 139 | leave_cleanup: | ||
| 140 | if (frc) { | ||
| 141 | file_relay_client_free(frc); | ||
| 142 | } | ||
| 143 | if (client) { | ||
| 144 | lockdownd_client_free(client); | ||
| 145 | } | ||
| 146 | if (dev) { | ||
| 147 | idevice_free(dev); | ||
| 148 | } | ||
| 149 | |||
| 150 | return 0; | ||
| 151 | } | ||
