From: Boyuan Yang Date: Thu, 3 Aug 2023 16:07:40 -0400 Subject: Port to libplist 2.3.0 --- configure.ac | 2 +- src/conf.c | 9 +++++---- src/utils.c | 45 --------------------------------------------- src/utils.h | 8 -------- 4 files changed, 6 insertions(+), 58 deletions(-) diff --git a/configure.ac b/configure.ac index af0d2cd..3f8493c 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ AC_PROG_LIBTOOL # Checks for libraries. PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.9) -PKG_CHECK_MODULES(libplist, libplist-2.0 >= 2.2.0) +PKG_CHECK_MODULES(libplist, libplist-2.0 >= 2.3.0) PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= 1.3.0, have_limd=yes, have_limd=no) AC_CHECK_LIB(pthread, [pthread_create, pthread_mutex_lock], [AC_SUBST(libpthread_LIBS,[-lpthread])], [AC_MSG_ERROR([libpthread is required to build usbmuxd])]) diff --git a/src/conf.c b/src/conf.c index 609d246..5e682b4 100644 --- a/src/conf.c +++ b/src/conf.c @@ -39,6 +39,7 @@ #include #endif +#include #include "conf.h" #include "utils.h" #include "log.h" @@ -230,7 +231,7 @@ static int internal_set_value(const char *config_file, const char *key, plist_t /* read file into plist */ plist_t config = NULL; - plist_read_from_filename(&config, config_file); + plist_read_from_file(config_file, &config, NULL); if (!config) { config = plist_new_dict(); plist_dict_set_item(config, key, value); @@ -254,7 +255,7 @@ static int internal_set_value(const char *config_file, const char *key, plist_t usbmuxd_log(LL_DEBUG, "Setting key %s in config file %s", key, config_file); } - int res = plist_write_to_filename(config, config_file, PLIST_FORMAT_XML); + int res = plist_write_to_file(config, config_file, PLIST_FORMAT_XML, 0); plist_free(config); @@ -288,7 +289,7 @@ static int internal_get_value(const char* config_file, const char *key, plist_t /* now parse file to get the SystemBUID */ plist_t config = NULL; - if (plist_read_from_filename(&config, config_file)) { + if (plist_read_from_file(config_file, &config, NULL)) { usbmuxd_log(LL_DEBUG, "Reading key %s from config file %s", key, config_file); plist_t n = plist_dict_get_item(config, key); if (n) { @@ -428,7 +429,7 @@ int config_set_device_record(const char *udid, char* record_data, uint64_t recor remove(device_record_file); /* store file */ - if (!plist_write_to_filename(plist, device_record_file, PLIST_FORMAT_XML)) { + if (!plist_write_to_file(plist, device_record_file, PLIST_FORMAT_XML, 0)) { usbmuxd_log(LL_DEBUG, "Could not open '%s' for writing: %s", device_record_file, strerror(errno)); res = -ENOENT; } diff --git a/src/utils.c b/src/utils.c index 206c684..35d3f73 100644 --- a/src/utils.c +++ b/src/utils.c @@ -279,51 +279,6 @@ int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t } } -int plist_read_from_filename(plist_t *plist, const char *filename) -{ - char *buffer = NULL; - uint64_t length; - - if (!filename) - return 0; - - if (!buffer_read_from_filename(filename, &buffer, &length)) { - 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; -} - -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; - - int res = buffer_write_to_filename(filename, buffer, length); - - free(buffer); - - return res; -} - #ifndef HAVE_CLOCK_GETTIME typedef int clockid_t; #define CLOCK_MONOTONIC 1 diff --git a/src/utils.h b/src/utils.h index b5cab3f..4fbd3af 100644 --- a/src/utils.h +++ b/src/utils.h @@ -78,14 +78,6 @@ char *string_concat(const char *str, ...); int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length); int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length); -enum plist_format_t { - PLIST_FORMAT_XML, - PLIST_FORMAT_BINARY -}; - -int plist_read_from_filename(plist_t *plist, const char *filename); -int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format); - uint64_t mstime64(void); void get_tick_count(struct timeval * tv);