summaryrefslogtreecommitdiffstats
path: root/src/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/src/common.c b/src/common.c
index a00cc05..f9377ba 100644
--- a/src/common.c
+++ b/src/common.c
@@ -52,6 +52,7 @@
#endif
#include "common.h"
+#include "endianness.h"
#define MAX_PRINT_LEN 64*1024
@@ -551,21 +552,88 @@ void get_user_input(char *buf, int maxlen, int secure)
uint64_t _plist_dict_get_uint(plist_t dict, const char *key)
{
uint64_t uintval = 0;
+ char *strval = NULL;
+ uint64_t strsz = 0;
plist_t node = plist_dict_get_item(dict, key);
if (!node) {
return (uint64_t)-1LL;
}
- plist_get_uint_val(node, &uintval);
+ switch (plist_get_node_type(node)) {
+ case PLIST_UINT:
+ plist_get_uint_val(node, &uintval);
+ break;
+ case PLIST_STRING:
+ plist_get_string_val(node, &strval);
+ if (strval) {
+ uintval = strtoull(strval, NULL, 0);
+ free(strval);
+ }
+ break;
+ case PLIST_DATA:
+ plist_get_data_val(node, &strval, &strsz);
+ if (strval) {
+ if (strsz == 8) {
+ uintval = le64toh(*(uint64_t*)strval);
+ } else if (strsz == 4) {
+ uintval = le32toh(*(uint32_t*)strval);
+ } else if (strsz == 2) {
+ uintval = le16toh(*(uint16_t*)strval);
+ } else if (strsz == 1) {
+ uintval = strval[0];
+ } else {
+ error("%s: ERROR: invalid size %d for data to integer conversion\n", __func__, strsz);
+ }
+ free(strval);
+ }
+ break;
+ default:
+ break;
+ }
return uintval;
}
uint8_t _plist_dict_get_bool(plist_t dict, const char *key)
{
uint8_t bval = 0;
+ uint64_t uintval = 0;
+ char *strval = NULL;
+ uint64_t strsz = 0;
plist_t node = plist_dict_get_item(dict, key);
if (!node) {
return 0;
}
- plist_get_bool_val(node, &bval);
+ switch (plist_get_node_type(node)) {
+ case PLIST_BOOLEAN:
+ plist_get_bool_val(node, &bval);
+ break;
+ case PLIST_UINT:
+ plist_get_uint_val(node, &uintval);
+ bval = (uint8_t)uintval;
+ break;
+ case PLIST_STRING:
+ plist_get_string_val(node, &strval);
+ if (strval) {
+ if (strcmp(strval, "true")) {
+ bval = 1;
+ } else if (strcmp(strval, "false")) {
+ bval = 0;
+ }
+ free(strval);
+ }
+ break;
+ case PLIST_DATA:
+ plist_get_data_val(node, &strval, &strsz);
+ if (strval) {
+ if (strsz == 1) {
+ bval = strval[0];
+ } else {
+ error("%s: ERROR: invalid size %d for data to boolean conversion\n", __func__, strsz);
+ }
+ free(strval);
+ }
+ break;
+ default:
+ break;
+ }
return bval;
}