diff --git a/libmobile_zte.c b/libmobile_zte.c index 7c7e938c252c341b9655cc6e0de54feb5946bbb1..826cdf5a6557f9c3ff8c103e68543393d9a5f507 100644 --- a/libmobile_zte.c +++ b/libmobile_zte.c @@ -347,18 +347,25 @@ fail: static struct json_object *parse_apn_profiles(struct json_object *apn_profiles) { struct json_object *parsed_profiles = json_object_new_object(); + const char *apn_string; int apn_counter = 0; char *field_names[13] = {"profile_name", "apn_name", "mode", "wan_dial", "ppp_auth_mode", "ppp_username", "ppp_passwd", "pdp", "pdpd_select", "pdp_addr", "dns_mode", "prefer_dns_manual", "standby_dns_manual"}; + int i; + struct json_object *apn_profile; + char *field_val; + char name[1024] = {0}; json_object_object_foreach(apn_profiles, key, val) { - const char *apn_string = json_object_get_string(val); - int i = 0; - struct json_object *apn_profile = json_object_new_object(); - char *field_val; - char name[1024] = {0}; - - if (strlen(apn_string) <= 0) - goto finished; + apn_string = json_object_get_string(val); + i = 0; + apn_profile = json_object_new_object(); + name[0] = 0; + + if (strlen(apn_string) <= 0) { + json_object_put(apn_profile); + break; + } + while ((field_val = lexer(&apn_string, "($)")) != NULL) { json_object_object_add(apn_profile, field_names[i], json_object_new_string(field_val)); i++; @@ -371,7 +378,6 @@ static struct json_object *parse_apn_profiles(struct json_object *apn_profiles) apn_counter++; } -finished: json_object_put(apn_profiles); return parsed_profiles; }