diff options
| author | 2013-12-05 14:39:23 +0100 | |
|---|---|---|
| committer | 2013-12-05 14:39:23 +0100 | |
| commit | fe514ef73302973b0df37a999f75b2a461bfa828 (patch) | |
| tree | a15246e9ab4ec3d1c86125406c516cf474a11cf0 /src | |
| parent | 53dac4877ed998c6dcc037b1bc72d236dd7e956a (diff) | |
| download | ideviceinstaller-fe514ef73302973b0df37a999f75b2a461bfa828.tar.gz ideviceinstaller-fe514ef73302973b0df37a999f75b2a461bfa828.tar.bz2 | |
Swap "-u" and "-U" arguments and print deprecation warning if still used
All other tools around the libimobiledevice stack use a lower case
"-u" argument to specify a target UDID. This change swaps the "--uninstall"
and "--udid" argument short form to provide consistency while allowing
the use in the old way as a fallback.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ideviceinstaller.c | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c index 04aa858..0e64e9d 100644 --- a/src/ideviceinstaller.c +++ b/src/ideviceinstaller.c | |||
| @@ -271,6 +271,31 @@ static void idevice_wait_for_operation_to_complete() | |||
| 271 | idevice_event_unsubscribe(); | 271 | idevice_event_unsubscribe(); |
| 272 | } | 272 | } |
| 273 | 273 | ||
| 274 | static int str_is_udid(const char* str) | ||
| 275 | { | ||
| 276 | const char allowed[] = "0123456789abcdefABCDEF"; | ||
| 277 | |||
| 278 | /* handle NULL case */ | ||
| 279 | if (str == NULL) | ||
| 280 | return -1; | ||
| 281 | |||
| 282 | int length = strlen(str); | ||
| 283 | |||
| 284 | /* verify length */ | ||
| 285 | if (length != 40) | ||
| 286 | return -1; | ||
| 287 | |||
| 288 | /* check for invalid characters */ | ||
| 289 | while(length--) { | ||
| 290 | /* invalid character in udid? */ | ||
| 291 | if (strchr(allowed, str[length]) == NULL) { | ||
| 292 | return -1; | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | return 0; | ||
| 297 | } | ||
| 298 | |||
| 274 | static void print_usage(int argc, char **argv) | 299 | static void print_usage(int argc, char **argv) |
| 275 | { | 300 | { |
| 276 | char *name = NULL; | 301 | char *name = NULL; |
| @@ -279,7 +304,7 @@ static void print_usage(int argc, char **argv) | |||
| 279 | printf("Usage: %s OPTIONS\n", (name ? name + 1 : argv[0])); | 304 | printf("Usage: %s OPTIONS\n", (name ? name + 1 : argv[0])); |
| 280 | printf("Manage apps on an iDevice.\n\n"); | 305 | printf("Manage apps on an iDevice.\n\n"); |
| 281 | printf | 306 | printf |
| 282 | (" -U, --udid UDID\tTarget specific device by its 40-digit device UDID.\n" | 307 | (" -u, --udid UDID\tTarget specific device by its 40-digit device UDID.\n" |
| 283 | " -l, --list-apps\tList apps, possible options:\n" | 308 | " -l, --list-apps\tList apps, possible options:\n" |
| 284 | " -o list_user\t- list user apps only (this is the default)\n" | 309 | " -o list_user\t- list user apps only (this is the default)\n" |
| 285 | " -o list_system\t- list system apps only\n" | 310 | " -o list_system\t- list system apps only\n" |
| @@ -287,7 +312,7 @@ static void print_usage(int argc, char **argv) | |||
| 287 | " -o xml\t\t- print full output as xml plist\n" | 312 | " -o xml\t\t- print full output as xml plist\n" |
| 288 | " -i, --install ARCHIVE\tInstall app from package file specified by ARCHIVE.\n" | 313 | " -i, --install ARCHIVE\tInstall app from package file specified by ARCHIVE.\n" |
| 289 | " \tARCHIVE can also be a .ipcc file for carrier bundles.\n" | 314 | " \tARCHIVE can also be a .ipcc file for carrier bundles.\n" |
| 290 | " -u, --uninstall APPID\tUninstall app specified by APPID.\n" | 315 | " -U, --uninstall APPID\tUninstall app specified by APPID.\n" |
| 291 | " -g, --upgrade ARCHIVE\tUpgrade app from package file specified by ARCHIVE.\n" | 316 | " -g, --upgrade ARCHIVE\tUpgrade app from package file specified by ARCHIVE.\n" |
| 292 | " -L, --list-archives\tList archived applications, possible options:\n" | 317 | " -L, --list-archives\tList archived applications, possible options:\n" |
| 293 | " -o xml\t\t- print full output as xml plist\n" | 318 | " -o xml\t\t- print full output as xml plist\n" |
| @@ -308,10 +333,10 @@ static void parse_opts(int argc, char **argv) | |||
| 308 | { | 333 | { |
| 309 | static struct option longopts[] = { | 334 | static struct option longopts[] = { |
| 310 | {"help", 0, NULL, 'h'}, | 335 | {"help", 0, NULL, 'h'}, |
| 311 | {"udid", 1, NULL, 'U'}, | 336 | {"udid", 1, NULL, 'u'}, |
| 312 | {"list-apps", 0, NULL, 'l'}, | 337 | {"list-apps", 0, NULL, 'l'}, |
| 313 | {"install", 1, NULL, 'i'}, | 338 | {"install", 1, NULL, 'i'}, |
| 314 | {"uninstall", 1, NULL, 'u'}, | 339 | {"uninstall", 1, NULL, 'U'}, |
| 315 | {"upgrade", 1, NULL, 'g'}, | 340 | {"upgrade", 1, NULL, 'g'}, |
| 316 | {"list-archives", 0, NULL, 'L'}, | 341 | {"list-archives", 0, NULL, 'L'}, |
| 317 | {"archive", 1, NULL, 'a'}, | 342 | {"archive", 1, NULL, 'a'}, |
| @@ -353,14 +378,20 @@ static void parse_opts(int argc, char **argv) | |||
| 353 | case 'h': | 378 | case 'h': |
| 354 | print_usage(argc, argv); | 379 | print_usage(argc, argv); |
| 355 | exit(0); | 380 | exit(0); |
| 356 | case 'U': | 381 | case 'u': |
| 357 | if (strlen(optarg) != 40) { | 382 | if (str_is_udid(optarg) == 0) { |
| 358 | printf("%s: invalid UDID specified (length != 40)\n", | 383 | udid = strdup(optarg); |
| 359 | argv[0]); | 384 | break; |
| 385 | } | ||
| 386 | if (strchr(optarg, '.') != NULL) { | ||
| 387 | fprintf(stderr, "WARNING: Using \"-u\" for \"--uninstall\" is deprecated. Please use \"-U\" instead.\n"); | ||
| 388 | cmd = CMD_UNINSTALL; | ||
| 389 | appid = strdup(optarg); | ||
| 390 | } else { | ||
| 391 | printf("ERROR: Invalid UDID specified\n"); | ||
| 360 | print_usage(argc, argv); | 392 | print_usage(argc, argv); |
| 361 | exit(2); | 393 | exit(2); |
| 362 | } | 394 | } |
| 363 | udid = strdup(optarg); | ||
| 364 | break; | 395 | break; |
| 365 | case 'l': | 396 | case 'l': |
| 366 | cmd = CMD_LIST_APPS; | 397 | cmd = CMD_LIST_APPS; |
| @@ -369,6 +400,12 @@ static void parse_opts(int argc, char **argv) | |||
| 369 | cmd = CMD_INSTALL; | 400 | cmd = CMD_INSTALL; |
| 370 | appid = strdup(optarg); | 401 | appid = strdup(optarg); |
| 371 | break; | 402 | break; |
| 403 | case 'U': | ||
| 404 | if (str_is_udid(optarg) == 0) { | ||
| 405 | fprintf(stderr, "WARNING: Using \"-U\" for \"--udid\" is deprecated. Please use \"-u\" instead.\n"); | ||
| 406 | udid = strdup(optarg); | ||
| 407 | break; | ||
| 408 | } | ||
| 372 | cmd = CMD_UNINSTALL; | 409 | cmd = CMD_UNINSTALL; |
| 373 | appid = strdup(optarg); | 410 | appid = strdup(optarg); |
| 374 | break; | 411 | break; |
