diff --git a/src/phonebook.c b/src/phonebook.c index 546c80f..c20a24f 100644 --- a/src/phonebook.c +++ b/src/phonebook.c @@ -309,11 +309,23 @@ static DBusMessage *generate_export_entries_reply(struct ofono_modem *modem, static gboolean need_merge(const char *text) { - int len = strlen(text); - char c = tolower(text[len-1]); + int len; + char c; + + if (!text) + return FALSE; + + len = strlen(text); + + if (len < 2) + return FALSE; + + c = tolower(text[len-1]); + if ((text[len-2] == '/') && ((c == 'w') || (c == 'h') || (c == 'm') || (c == 'o'))) return TRUE; + return FALSE; } @@ -362,6 +374,11 @@ void ofono_phonebook_entry(struct ofono_modem *modem, int index, { struct phonebook_data *phonebook = modem->phonebook; + /* There's really nothing to do */ + if ((number == NULL || number[0] == '\0') && + (text == NULL || text[0] == '\0')) + return; + /* * We need to collect all the entries that belong to one person, * so that only one vCard will be generated at last. @@ -400,7 +417,12 @@ void ofono_phonebook_entry(struct ofono_modem *modem, int index, } vcard_printf_begin(phonebook->vcards); - vcard_printf_text(phonebook->vcards, text); + + if (text == NULL || text[0] == '\0') + vcard_printf_text(phonebook->vcards, number); + else + vcard_printf_text(phonebook->vcards, text); + vcard_printf_number(phonebook->vcards, number, type, TEL_TYPE_OTHER); vcard_printf_number(phonebook->vcards, adnumber, adtype, TEL_TYPE_OTHER);