diff options
| author | 2014-08-06 03:12:12 +0200 | |
|---|---|---|
| committer | 2014-08-06 03:12:12 +0200 | |
| commit | 2344ec753ea58f93f1a8b889cc564d72bf084964 (patch) | |
| tree | 5a9a9c055c7dd21ca91395a2b4563cd6a7621ffe /tools/idevicebackup.c | |
| parent | 99d83b9017fb46eaeb9d7682fe263fced31c39a3 (diff) | |
| download | libimobiledevice-2344ec753ea58f93f1a8b889cc564d72bf084964.tar.gz libimobiledevice-2344ec753ea58f93f1a8b889cc564d72bf084964.tar.bz2 | |
idevicebackup2/idevicebackup: Remove code duplication and use common code for reading/writing plist files
Diffstat (limited to 'tools/idevicebackup.c')
| -rw-r--r-- | tools/idevicebackup.c | 89 |
1 files changed, 1 insertions, 88 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c index e30540e..c126869 100644 --- a/tools/idevicebackup.c +++ b/tools/idevicebackup.c | |||
| @@ -43,6 +43,7 @@ | |||
| 43 | #include <libimobiledevice/mobilebackup.h> | 43 | #include <libimobiledevice/mobilebackup.h> |
| 44 | #include <libimobiledevice/notification_proxy.h> | 44 | #include <libimobiledevice/notification_proxy.h> |
| 45 | #include <libimobiledevice/afc.h> | 45 | #include <libimobiledevice/afc.h> |
| 46 | #include "common/utils.h" | ||
| 46 | 47 | ||
| 47 | #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" | 48 | #define MOBILEBACKUP_SERVICE_NAME "com.apple.mobilebackup" |
| 48 | #define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" | 49 | #define NP_SERVICE_NAME "com.apple.mobile.notification_proxy" |
| @@ -67,11 +68,6 @@ enum cmd_mode { | |||
| 67 | CMD_LEAVE | 68 | CMD_LEAVE |
| 68 | }; | 69 | }; |
| 69 | 70 | ||
| 70 | enum plist_format_t { | ||
| 71 | PLIST_FORMAT_XML, | ||
| 72 | PLIST_FORMAT_BINARY | ||
| 73 | }; | ||
| 74 | |||
| 75 | enum device_link_file_status_t { | 71 | enum device_link_file_status_t { |
| 76 | DEVICE_LINK_FILE_STATUS_NONE = 0, | 72 | DEVICE_LINK_FILE_STATUS_NONE = 0, |
| 77 | DEVICE_LINK_FILE_STATUS_HUNK, | 73 | DEVICE_LINK_FILE_STATUS_HUNK, |
| @@ -353,89 +349,6 @@ static void mobilebackup_info_update_last_backup_date(plist_t info_plist) | |||
| 353 | node = NULL; | 349 | node = NULL; |
| 354 | } | 350 | } |
| 355 | 351 | ||
| 356 | static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) | ||
| 357 | { | ||
| 358 | FILE *f; | ||
| 359 | uint64_t size; | ||
| 360 | |||
| 361 | *length = 0; | ||
| 362 | |||
| 363 | f = fopen(filename, "rb"); | ||
| 364 | if (!f) { | ||
| 365 | return; | ||
| 366 | } | ||
| 367 | |||
| 368 | fseek(f, 0, SEEK_END); | ||
| 369 | size = ftell(f); | ||
| 370 | rewind(f); | ||
| 371 | |||
| 372 | if (size == 0) { | ||
| 373 | return; | ||
| 374 | } | ||
| 375 | |||
| 376 | *buffer = (char*)malloc(sizeof(char)*size); | ||
| 377 | fread(*buffer, sizeof(char), size, f); | ||
| 378 | fclose(f); | ||
| 379 | |||
| 380 | *length = size; | ||
| 381 | } | ||
| 382 | |||
| 383 | static void buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length) | ||
| 384 | { | ||
| 385 | FILE *f; | ||
| 386 | |||
| 387 | f = fopen(filename, "ab"); | ||
| 388 | fwrite(buffer, sizeof(char), length, f); | ||
| 389 | fclose(f); | ||
| 390 | } | ||
| 391 | |||
| 392 | static int plist_read_from_filename(plist_t *plist, const char *filename) | ||
| 393 | { | ||
| 394 | char *buffer = NULL; | ||
| 395 | uint64_t length; | ||
| 396 | |||
| 397 | if (!filename) | ||
| 398 | return 0; | ||
| 399 | |||
| 400 | buffer_read_from_filename(filename, &buffer, &length); | ||
| 401 | |||
| 402 | if (!buffer) { | ||
| 403 | return 0; | ||
| 404 | } | ||
| 405 | |||
| 406 | if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) { | ||
| 407 | plist_from_bin(buffer, length, plist); | ||
| 408 | } else { | ||
| 409 | plist_from_xml(buffer, length, plist); | ||
| 410 | } | ||
| 411 | |||
| 412 | free(buffer); | ||
| 413 | |||
| 414 | return 1; | ||
| 415 | } | ||
| 416 | |||
| 417 | static int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format) | ||
| 418 | { | ||
| 419 | char *buffer = NULL; | ||
| 420 | uint32_t length; | ||
| 421 | |||
| 422 | if (!plist || !filename) | ||
| 423 | return 0; | ||
| 424 | |||
| 425 | if (format == PLIST_FORMAT_XML) | ||
| 426 | plist_to_xml(plist, &buffer, &length); | ||
| 427 | else if (format == PLIST_FORMAT_BINARY) | ||
| 428 | plist_to_bin(plist, &buffer, &length); | ||
| 429 | else | ||
| 430 | return 0; | ||
| 431 | |||
| 432 | buffer_write_to_filename(filename, buffer, length); | ||
| 433 | |||
| 434 | free(buffer); | ||
| 435 | |||
| 436 | return 1; | ||
| 437 | } | ||
| 438 | |||
| 439 | static int plist_strcmp(plist_t node, const char *str) | 352 | static int plist_strcmp(plist_t node, const char *str) |
| 440 | { | 353 | { |
| 441 | char *buffer = NULL; | 354 | char *buffer = NULL; |
