diff --git a/libmobile_zte.c b/libmobile_zte.c index 91436894edfde81440fc850d59b437c9c5c7dbe7..8164394942b0857a447e5680dd18e18e72dec849 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)