summaryrefslogtreecommitdiffstats
path: root/tools/idevicebackup2.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-08-06 03:12:12 +0200
committerGravatar Nikias Bassen2014-08-06 03:12:12 +0200
commit2344ec753ea58f93f1a8b889cc564d72bf084964 (patch)
tree5a9a9c055c7dd21ca91395a2b4563cd6a7621ffe /tools/idevicebackup2.c
parent99d83b9017fb46eaeb9d7682fe263fced31c39a3 (diff)
downloadlibimobiledevice-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/idevicebackup2.c')
-rw-r--r--tools/idevicebackup2.c93
1 files changed, 1 insertions, 92 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index 35d3ccb..2da4971 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -36,6 +36,7 @@
#include <libimobiledevice/mobilebackup2.h>
#include <libimobiledevice/notification_proxy.h>
#include <libimobiledevice/afc.h>
+#include "common/utils.h"
#include <endianness.h>
@@ -73,11 +74,6 @@ enum cmd_mode {
CMD_CLOUD
};
-enum plist_format_t {
- PLIST_FORMAT_XML,
- PLIST_FORMAT_BINARY
-};
-
enum cmd_flags {
CMD_FLAG_RESTORE_SYSTEM_FILES = (1 << 1),
CMD_FLAG_RESTORE_REBOOT = (1 << 2),
@@ -357,93 +353,6 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, lockdownd_c
return ret;
}
-static void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length)
-{
- FILE *f;
- uint64_t size;
-
- *length = 0;
-
- f = fopen(filename, "rb");
- if (!f) {
- return;
- }
-
- fseek(f, 0, SEEK_END);
- size = ftell(f);
- rewind(f);
-
- if (size == 0) {
- return;
- }
-
- *buffer = (char*)malloc(sizeof(char)*size);
- fread(*buffer, sizeof(char), size, f);
- fclose(f);
-
- *length = size;
-}
-
-static void buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length)
-{
- FILE *f;
-
- f = fopen(filename, "ab");
- if (!f)
- f = fopen(filename, "wb");
- if (f) {
- fwrite(buffer, sizeof(char), length, f);
- fclose(f);
- }
-}
-
-static int plist_read_from_filename(plist_t *plist, const char *filename)
-{
- char *buffer = NULL;
- uint64_t length;
-
- if (!filename)
- return 0;
-
- buffer_read_from_filename(filename, &buffer, &length);
-
- if (!buffer) {
- return 0;
- }
-
- if ((length > 8) && (memcmp(buffer, "bplist00", 8) == 0)) {
- plist_from_bin(buffer, length, plist);
- } else {
- plist_from_xml(buffer, length, plist);
- }
-
- free(buffer);
-
- return 1;
-}
-
-static int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format)
-{
- char *buffer = NULL;
- uint32_t length;
-
- if (!plist || !filename)
- return 0;
-
- if (format == PLIST_FORMAT_XML)
- plist_to_xml(plist, &buffer, &length);
- else if (format == PLIST_FORMAT_BINARY)
- plist_to_bin(plist, &buffer, &length);
- else
- return 0;
-
- buffer_write_to_filename(filename, buffer, length);
-
- free(buffer);
-
- return 1;
-}
-
static int mb2_status_check_snapshot_state(const char *path, const char *udid, const char *matches)
{
int ret = -1;