From 03f2baebe9aac44ed6a512f0f3374a944602917d Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 7 Apr 2022 00:20:48 +0200 Subject: tss/restore: Improve code readability with plist helpers and removal of unneeded comments --- src/common.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 4dbabc0..89cd86d 100644 --- a/src/common.c +++ b/src/common.c @@ -645,3 +645,53 @@ uint8_t _plist_dict_get_bool(plist_t dict, const char *key) } return bval; } + +int _plist_dict_copy_uint(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key) +{ + if (plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key) == NULL) { + return -1; + } + uint64_t u64val = _plist_dict_get_uint(source_dict, (alt_source_key) ? alt_source_key : key); + plist_dict_set_item(target_dict, key, plist_new_uint(u64val)); + return 0; +} + +int _plist_dict_copy_bool(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key) +{ + if (plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key) == NULL) { + return -1; + } + uint64_t bval = _plist_dict_get_bool(source_dict, (alt_source_key) ? alt_source_key : key); + plist_dict_set_item(target_dict, key, plist_new_bool(bval)); + return 0; +} + +int _plist_dict_copy_data(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key) +{ + plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key); + if (!PLIST_IS_DATA(node)) { + return -1; + } + plist_dict_set_item(target_dict, key, plist_copy(node)); + return 0; +} + +int _plist_dict_copy_string(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key) +{ + plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key); + if (!PLIST_IS_STRING(node)) { + return -1; + } + plist_dict_set_item(target_dict, key, plist_copy(node)); + return 0; +} + +int _plist_dict_copy_item(plist_t target_dict, plist_t source_dict, const char *key, const char *alt_source_key) +{ + plist_t node = plist_dict_get_item(source_dict, (alt_source_key) ? alt_source_key : key); + if (!node) { + return -1; + } + plist_dict_set_item(target_dict, key, plist_copy(node)); + return 0; +} -- cgit v1.1-32-gdbae