From fc98cf91a8a4e8d6b39ea1ec1ac87c428dd47859 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Tue, 16 Jun 2009 16:31:32 -0500 Subject: [PATCH] Use library functions appropriately Instead of using custom parsing, use the existing library functionality in result iter open_list, next_range and close_list --- drivers/atmodem/phonebook.c | 42 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/drivers/atmodem/phonebook.c b/drivers/atmodem/phonebook.c index 6bf6f3ec..471e597e 100644 --- a/drivers/atmodem/phonebook.c +++ b/drivers/atmodem/phonebook.c @@ -180,9 +180,8 @@ static void at_list_indices_cb(gboolean ok, GAtResult *result, ofono_phonebook_export_entries_t cb = cbd->cb; struct ofono_error error; GAtResultIter iter; - const char *indices; - int index_min = 0, index_max = 0; - int i = 0, integer_index = 0; + int index_min; + int index_max; decode_at_error(&error, g_at_result_final_response(result)); if (!ok) { @@ -191,31 +190,30 @@ static void at_list_indices_cb(gboolean ok, GAtResult *result, } g_at_result_iter_init(&iter, result); - if (!g_at_result_iter_next(&iter, "+CPBR:")) { - DECLARE_FAILURE(e); - cb(&e, 0, NULL, cbd->data); - return; - } + if (!g_at_result_iter_next(&iter, "+CPBR:")) + goto fail; + + if (!g_at_result_iter_open_list(&iter)) + goto fail; - indices = g_at_result_iter_raw_line(&iter); /* retrieve index_min and index_max from indices * which seems like "(1-150),32,16" */ - while (indices[i] != ')') { - if (indices[i] == '(') - integer_index = 1; - else if (indices[i] == '-') - integer_index = 2; - if ((indices[i] >= '0') && (indices[i] <= '9')) { - if (integer_index == 1) - index_min = index_min*10 + (indices[i] - '0'); - else if (integer_index == 2) - index_max = index_max*10 + (indices[i] - '0'); - } - i++; - } + if (!g_at_result_iter_next_range(&iter, &index_min, &index_max)) + goto fail; + + if (!g_at_result_iter_close_list(&iter)) + goto fail; at_read_entries(modem, index_min, index_max, cb, modem); + + return; + +fail: + { + DECLARE_FAILURE(e); + cb(&e, cbd->data); + } } static void at_list_indices(struct ofono_modem *modem,