summaryrefslogtreecommitdiffstats
path: root/tools/idevicepair.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2022-04-30 13:31:20 +0200
committerGravatar Nikias Bassen2022-04-30 13:31:20 +0200
commit6cb13f9e6d3939930aecf91d8e23d1896a3b92e5 (patch)
tree371e4676ac914d9eef6bb4cfc0b5b6dc6f27da4f /tools/idevicepair.c
parent3b5cad28fabb236e05b8fff82fab5098127aa2bb (diff)
downloadlibimobiledevice-6cb13f9e6d3939930aecf91d8e23d1896a3b92e5.tar.gz
libimobiledevice-6cb13f9e6d3939930aecf91d8e23d1896a3b92e5.tar.bz2
tools: Use getopt for option parsing in all tools
Diffstat (limited to 'tools/idevicepair.c')
-rw-r--r--tools/idevicepair.c92
1 files changed, 50 insertions, 42 deletions
diff --git a/tools/idevicepair.c b/tools/idevicepair.c
index f42f498..dda02ec 100644
--- a/tools/idevicepair.c
+++ b/tools/idevicepair.c
@@ -144,42 +144,50 @@ static void print_error_message(lockdownd_error_t err)
144 } 144 }
145} 145}
146 146
147static void print_usage(int argc, char **argv) 147static void print_usage(int argc, char **argv, int is_error)
148{ 148{
149 char *name = NULL; 149 char *name = strrchr(argv[0], '/');
150 150 fprintf(is_error ? stderr : stdout, "Usage: %s [OPTIONS] COMMAND\n", (name ? name + 1: argv[0]));
151 name = strrchr(argv[0], '/'); 151 fprintf(is_error ? stderr : stdout,
152 printf("Usage: %s [OPTIONS] COMMAND\n", (name ? name + 1: argv[0])); 152 "\n"
153 printf("\n"); 153 "Manage host pairings with devices and usbmuxd.\n"
154 printf("Manage host pairings with devices and usbmuxd.\n"); 154 "\n"
155 printf("\n"); 155 "Where COMMAND is one of:\n"
156 printf("Where COMMAND is one of:\n"); 156 " systembuid print the system buid of the usbmuxd host\n"
157 printf(" systembuid print the system buid of the usbmuxd host\n"); 157 " hostid print the host id for target device\n"
158 printf(" hostid print the host id for target device\n"); 158 " pair pair device with this host\n"
159 printf(" pair pair device with this host\n"); 159 " validate validate if device is paired with this host\n"
160 printf(" validate validate if device is paired with this host\n"); 160 " unpair unpair device with this host\n"
161 printf(" unpair unpair device with this host\n"); 161 " list list devices paired with this host\n"
162 printf(" list list devices paired with this host\n"); 162 "\n"
163 printf("\n"); 163 "The following OPTIONS are accepted:\n"
164 printf("The following OPTIONS are accepted:\n"); 164 " -u, --udid UDID target specific device by UDID\n"
165 printf(" -u, --udid UDID target specific device by UDID\n"); 165 );
166#ifdef HAVE_WIRELESS_PAIRING 166#ifdef HAVE_WIRELESS_PAIRING
167 printf(" -w, --wireless perform wireless pairing (see NOTE)\n"); 167 fprintf(is_error ? stderr : stdout,
168 printf(" -n, --network connect to network device (see NOTE)\n"); 168 " -w, --wireless perform wireless pairing (see NOTE)\n"
169 " -n, --network connect to network device (see NOTE)\n"
170 );
169#endif 171#endif
170 printf(" -d, --debug enable communication debugging\n"); 172 fprintf(is_error ? stderr : stdout,
171 printf(" -h, --help prints usage information\n"); 173 " -d, --debug enable communication debugging\n"
172 printf(" -v, --version prints version information\n"); 174 " -h, --help prints usage information\n"
175 " -v, --version prints version information\n"
176 );
173#ifdef HAVE_WIRELESS_PAIRING 177#ifdef HAVE_WIRELESS_PAIRING
174 printf("\n"); 178 fprintf(is_error ? stderr : stdout,
175 printf("NOTE: Pairing over network (wireless pairing) is only supported by Apple TV\n"); 179 "\n"
176 printf("devices. To perform a wireless pairing, you need to use the -w command line\n"); 180 "NOTE: Pairing over network (wireless pairing) is only supported by Apple TV\n"
177 printf("switch. Make sure to put the device into pairing mode first by opening\n"); 181 "devices. To perform a wireless pairing, you need to use the -w command line\n"
178 printf("Settings > Remotes and Devices > Remote App and Devices.\n"); 182 "switch. Make sure to put the device into pairing mode first by opening\n"
183 "Settings > Remotes and Devices > Remote App and Devices.\n"
184 );
179#endif 185#endif
180 printf("\n"); 186 fprintf(is_error ? stderr : stdout,
181 printf("Homepage: <" PACKAGE_URL ">\n"); 187 "\n"
182 printf("Bug Reports: <" PACKAGE_BUGREPORT ">\n"); 188 "Homepage: <" PACKAGE_URL ">\n"
189 "Bug Reports: <" PACKAGE_BUGREPORT ">\n"
190 );
183} 191}
184 192
185int main(int argc, char **argv) 193int main(int argc, char **argv)
@@ -223,12 +231,12 @@ int main(int argc, char **argv)
223 while ((c = getopt_long(argc, argv, SHORT_OPTIONS, longopts, NULL)) != -1) { 231 while ((c = getopt_long(argc, argv, SHORT_OPTIONS, longopts, NULL)) != -1) {
224 switch (c) { 232 switch (c) {
225 case 'h': 233 case 'h':
226 print_usage(argc, argv); 234 print_usage(argc, argv, 0);
227 exit(EXIT_SUCCESS); 235 exit(EXIT_SUCCESS);
228 case 'u': 236 case 'u':
229 if (!*optarg) { 237 if (!*optarg) {
230 fprintf(stderr, "ERROR: UDID must not be empty!\n"); 238 fprintf(stderr, "ERROR: UDID must not be empty!\n");
231 print_usage(argc, argv); 239 print_usage(argc, argv, 1);
232 result = EXIT_FAILURE; 240 result = EXIT_FAILURE;
233 goto leave; 241 goto leave;
234 } 242 }
@@ -280,7 +288,7 @@ int main(int argc, char **argv)
280 result = EXIT_SUCCESS; 288 result = EXIT_SUCCESS;
281 goto leave; 289 goto leave;
282 default: 290 default:
283 print_usage(argc, argv); 291 print_usage(argc, argv, 1);
284 result = EXIT_FAILURE; 292 result = EXIT_FAILURE;
285 goto leave; 293 goto leave;
286 } 294 }
@@ -291,15 +299,15 @@ int main(int argc, char **argv)
291#endif 299#endif
292 300
293 if ((argc - optind) < 1) { 301 if ((argc - optind) < 1) {
294 printf("ERROR: You need to specify a COMMAND!\n"); 302 fprintf(stderr, "ERROR: You need to specify a COMMAND!\n");
295 print_usage(argc, argv); 303 print_usage(argc, argv, 1);
296 result = EXIT_FAILURE; 304 result = EXIT_FAILURE;
297 goto leave; 305 goto leave;
298 } 306 }
299 307
300 if (wireless_pairing && use_network) { 308 if (wireless_pairing && use_network) {
301 printf("ERROR: You cannot use -w and -n together.\n"); 309 fprintf(stderr, "ERROR: You cannot use -w and -n together.\n");
302 print_usage(argc, argv); 310 print_usage(argc, argv, 1);
303 result = EXIT_FAILURE; 311 result = EXIT_FAILURE;
304 goto leave; 312 goto leave;
305 } 313 }
@@ -319,16 +327,16 @@ int main(int argc, char **argv)
319 } else if (!strcmp(cmd, "systembuid")) { 327 } else if (!strcmp(cmd, "systembuid")) {
320 op = OP_SYSTEMBUID; 328 op = OP_SYSTEMBUID;
321 } else { 329 } else {
322 printf("ERROR: Invalid command '%s' specified\n", cmd); 330 fprintf(stderr, "ERROR: Invalid command '%s' specified\n", cmd);
323 print_usage(argc, argv); 331 print_usage(argc, argv, 1);
324 result = EXIT_FAILURE; 332 result = EXIT_FAILURE;
325 goto leave; 333 goto leave;
326 } 334 }
327 335
328 if (wireless_pairing) { 336 if (wireless_pairing) {
329 if (op == OP_VALIDATE || op == OP_UNPAIR) { 337 if (op == OP_VALIDATE || op == OP_UNPAIR) {
330 printf("ERROR: Command '%s' is not supported with -w\n", cmd); 338 fprintf(stderr, "ERROR: Command '%s' is not supported with -w\n", cmd);
331 print_usage(argc, argv); 339 print_usage(argc, argv, 1);
332 result = EXIT_FAILURE; 340 result = EXIT_FAILURE;
333 goto leave; 341 goto leave;
334 } 342 }