diff options
| author | 2009-11-10 23:31:49 +0100 | |
|---|---|---|
| committer | 2009-11-11 07:33:08 -0800 | |
| commit | eaf80002c6e82c6b7a376bb61c9884ec3cf750b4 (patch) | |
| tree | fc273d59ad7e5db3db2aba1006bebc6d8e0ac28d /src/lockdown.c | |
| parent | fdf94756f8f6a9fc9d218725f429d64fd91d7679 (diff) | |
| download | libimobiledevice-eaf80002c6e82c6b7a376bb61c9884ec3cf750b4.tar.gz libimobiledevice-eaf80002c6e82c6b7a376bb61c9884ec3cf750b4.tar.bz2 | |
Finish migration to latest plist API.
[#77 state:resolved]
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 75 |
1 files changed, 22 insertions, 53 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 6f9c922..80a89dc 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -60,11 +60,7 @@ static int lockdown_check_result(plist_t dict, const char *query_match) | |||
| 60 | { | 60 | { |
| 61 | int ret = -1; | 61 | int ret = -1; |
| 62 | 62 | ||
| 63 | plist_t query_key = plist_find_node_by_key(dict, "Request"); | 63 | plist_t query_node = plist_dict_get_item(dict, "Request"); |
| 64 | if (!query_key) { | ||
| 65 | return ret; | ||
| 66 | } | ||
| 67 | plist_t query_node = plist_get_next_sibling(query_key); | ||
| 68 | if (!query_node) { | 64 | if (!query_node) { |
| 69 | return ret; | 65 | return ret; |
| 70 | } | 66 | } |
| @@ -83,40 +79,30 @@ static int lockdown_check_result(plist_t dict, const char *query_match) | |||
| 83 | free(query_value); | 79 | free(query_value); |
| 84 | } | 80 | } |
| 85 | 81 | ||
| 86 | plist_t result_node = plist_get_next_sibling(query_node); | 82 | plist_t result_node = plist_dict_get_item(dict, "Result"); |
| 87 | if (!result_node) { | 83 | if (!result_node) { |
| 88 | return ret; | 84 | return ret; |
| 89 | } | 85 | } |
| 90 | 86 | ||
| 91 | plist_t value_node = plist_get_next_sibling(result_node); | ||
| 92 | if (!value_node) { | ||
| 93 | return ret; | ||
| 94 | } | ||
| 95 | |||
| 96 | plist_type result_type = plist_get_node_type(result_node); | 87 | plist_type result_type = plist_get_node_type(result_node); |
| 97 | plist_type value_type = plist_get_node_type(value_node); | ||
| 98 | 88 | ||
| 99 | if (result_type == PLIST_KEY && value_type == PLIST_STRING) { | 89 | if (result_type == PLIST_STRING) { |
| 100 | 90 | ||
| 101 | char *result_value = NULL; | 91 | char *result_value = NULL; |
| 102 | char *value_value = NULL; | ||
| 103 | 92 | ||
| 104 | plist_get_key_val(result_node, &result_value); | 93 | plist_get_string_val(result_node, &result_value); |
| 105 | plist_get_string_val(value_node, &value_value); | ||
| 106 | 94 | ||
| 107 | if (result_value && value_value && !strcmp(result_value, "Result")) { | 95 | if (result_value) { |
| 108 | if (!strcmp(value_value, "Success")) { | 96 | if (!strcmp(result_value, "Success")) { |
| 109 | ret = RESULT_SUCCESS; | 97 | ret = RESULT_SUCCESS; |
| 110 | } else if (!strcmp(value_value, "Failure")) { | 98 | } else if (!strcmp(result_value, "Failure")) { |
| 111 | ret = RESULT_FAILURE; | 99 | ret = RESULT_FAILURE; |
| 112 | } else { | 100 | } else { |
| 113 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, value_value); | 101 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: ERROR: unknown result value '%s'\n", __func__, result_value); |
| 114 | } | 102 | } |
| 115 | } | 103 | } |
| 116 | if (result_value) | 104 | if (result_value) |
| 117 | free(result_value); | 105 | free(result_value); |
| 118 | if (value_value) | ||
| 119 | free(value_value); | ||
| 120 | } | 106 | } |
| 121 | return ret; | 107 | return ret; |
| 122 | } | 108 | } |
| @@ -437,20 +423,11 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom | |||
| 437 | return ret; | 423 | return ret; |
| 438 | } | 424 | } |
| 439 | 425 | ||
| 440 | plist_t value_key_node = plist_find_node_by_key(dict, "Value"); | 426 | plist_t value_node = plist_dict_get_item(dict, "Value"); |
| 441 | plist_t value_value_node = plist_get_next_sibling(value_key_node); | ||
| 442 | |||
| 443 | plist_type value_key_type = plist_get_node_type(value_key_node); | ||
| 444 | 427 | ||
| 445 | if (value_key_type == PLIST_KEY) { | 428 | if (value_node) { |
| 446 | char *result_key = NULL; | 429 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__); |
| 447 | plist_get_key_val(value_key_node, &result_key); | 430 | *value = plist_copy(value_node); |
| 448 | |||
| 449 | if (!strcmp(result_key, "Value")) { | ||
| 450 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__); | ||
| 451 | *value = plist_copy(value_value_node); | ||
| 452 | } | ||
| 453 | free(result_key); | ||
| 454 | } | 431 | } |
| 455 | 432 | ||
| 456 | plist_free(dict); | 433 | plist_free(dict); |
| @@ -1024,7 +1001,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c | |||
| 1024 | return LOCKDOWN_E_PLIST_ERROR; | 1001 | return LOCKDOWN_E_PLIST_ERROR; |
| 1025 | 1002 | ||
| 1026 | if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { | 1003 | if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { |
| 1027 | plist_t error_node = plist_get_dict_el_from_key(dict, "Error"); | 1004 | plist_t error_node = plist_dict_get_item(dict, "Error"); |
| 1028 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { | 1005 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { |
| 1029 | char *error = NULL; | 1006 | char *error = NULL; |
| 1030 | plist_get_string_val(error_node, &error); | 1007 | plist_get_string_val(error_node, &error); |
| @@ -1108,18 +1085,17 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c | |||
| 1108 | } | 1085 | } |
| 1109 | } | 1086 | } |
| 1110 | /* store session id */ | 1087 | /* store session id */ |
| 1111 | plist_t session_node = plist_find_node_by_key(dict, "SessionID"); | 1088 | plist_t session_node = plist_dict_get_item(dict, "SessionID"); |
| 1112 | if (session_node) { | 1089 | if (session_node) { |
| 1113 | 1090 | ||
| 1114 | plist_t session_node_val = plist_get_next_sibling(session_node); | 1091 | plist_type session_node_type = plist_get_node_type(session_node); |
| 1115 | plist_type session_node_val_type = plist_get_node_type(session_node_val); | ||
| 1116 | 1092 | ||
| 1117 | if (session_node_val_type == PLIST_STRING) { | 1093 | if (session_node_type == PLIST_STRING) { |
| 1118 | 1094 | ||
| 1119 | char *session_id = NULL; | 1095 | char *session_id = NULL; |
| 1120 | plist_get_string_val(session_node_val, &session_id); | 1096 | plist_get_string_val(session_node, &session_id); |
| 1121 | 1097 | ||
| 1122 | if (session_node_val_type == PLIST_STRING && session_id) { | 1098 | if (session_node_type == PLIST_STRING && session_id) { |
| 1123 | /* we need to store the session ID for StopSession */ | 1099 | /* we need to store the session ID for StopSession */ |
| 1124 | strcpy(client->session_id, session_id); | 1100 | strcpy(client->session_id, session_id); |
| 1125 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); | 1101 | log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id); |
| @@ -1260,23 +1236,16 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char | |||
| 1260 | 1236 | ||
| 1261 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | 1237 | ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 1262 | if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { | 1238 | if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { |
| 1263 | plist_t port_key_node = plist_find_node_by_key(dict, "Port"); | 1239 | plist_t port_value_node = plist_dict_get_item(dict, "Port"); |
| 1264 | plist_t port_value_node = plist_get_next_sibling(port_key_node); | ||
| 1265 | 1240 | ||
| 1266 | if ((plist_get_node_type(port_key_node) == PLIST_KEY) | 1241 | if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) { |
| 1267 | && (plist_get_node_type(port_value_node) == PLIST_UINT)) { | ||
| 1268 | char *port_key = NULL; | ||
| 1269 | uint64_t port_value = 0; | 1242 | uint64_t port_value = 0; |
| 1270 | |||
| 1271 | plist_get_key_val(port_key_node, &port_key); | ||
| 1272 | plist_get_uint_val(port_value_node, &port_value); | 1243 | plist_get_uint_val(port_value_node, &port_value); |
| 1273 | if (port_key && !strcmp(port_key, "Port")) { | 1244 | |
| 1245 | if (port_value) { | ||
| 1274 | port_loc = port_value; | 1246 | port_loc = port_value; |
| 1275 | ret = LOCKDOWN_E_SUCCESS; | 1247 | ret = LOCKDOWN_E_SUCCESS; |
| 1276 | } | 1248 | } |
| 1277 | if (port_key) | ||
| 1278 | free(port_key); | ||
| 1279 | |||
| 1280 | if (port && ret == LOCKDOWN_E_SUCCESS) | 1249 | if (port && ret == LOCKDOWN_E_SUCCESS) |
| 1281 | *port = port_loc; | 1250 | *port = port_loc; |
| 1282 | } | 1251 | } |
