From 0e7bafce108a1720c5de68c6b4f305ec91ac6215 Mon Sep 17 00:00:00 2001 From: Jakob Olsson <jakobols@kth.se> Date: Thu, 5 Jul 2018 13:06:56 +0200 Subject: [PATCH] libmobile_zte: change get_apn_profile_by_name to function based on new array-based profile list --- libmobile_zte.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/libmobile_zte.c b/libmobile_zte.c index 9143689..8164394 100644 --- a/libmobile_zte.c +++ b/libmobile_zte.c @@ -434,27 +434,40 @@ fail: struct json_object *mobile_get_apn_profile_by_name_zte(char *ip_addr, char *name) { - struct json_object *apn_profiles, *apn_profile = NULL; - int idx, counter = 0, rv; + struct json_object *container, *profiles, *profile, *apn_name, *rv = NULL; + int i; - apn_profiles = mobile_get_apn_profiles_zte(ip_addr); - if (!apn_profiles) + container = mobile_get_apn_profiles_zte(ip_addr); + if (!container) goto fail; - json_object_object_foreach(apn_profiles, key, val) { - json_object_object_foreach(val, inner_key, inner_val) { - if (strncmp(name, json_object_get_string(inner_val), 1024) != 0) - continue; + json_object_object_get_ex(container, "profiles", &profiles); + if (!profiles) + goto fail_profiles; - json_object_get(inner_val); - apn_profile = inner_val; - break; - } + for (i = 0; i < json_object_array_length(profiles); i++) { + profile = json_object_array_get_idx(profiles, i); + + json_object_object_get_ex(profile, "profile", &profile); + if (!profile) + continue; + + json_object_object_get_ex(profile, "name", &apn_name); + if (!apn_name) + continue; + + if (strncmp(name, json_object_get_string(apn_name), 1024) != 0) + continue; + + json_object_get(profile); + rv = profile; + break; } - json_object_put(apn_profiles); +fail_profiles: + json_object_put(container); fail: - return apn_profile; + return rv; } struct json_object *mobile_get_remaining_tries_zte(char *ip_addr) -- GitLab