Added checks for null values in vcard.cc and added new methods to manipulate sip addresses in vcard from friend

This commit is contained in:
Sylvain Berfini 2015-12-16 10:51:17 +01:00
parent f6edea6eec
commit 0a59544a44
3 changed files with 65 additions and 10 deletions

View file

@ -199,10 +199,12 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char
}
int linphone_friend_set_address(LinphoneFriend *lf, const LinphoneAddress *addr){
LinphoneAddress *fr=linphone_address_clone(addr);
LinphoneAddress *fr = linphone_address_clone(addr);
linphone_address_clean(fr);
if (lf->uri!=NULL) linphone_address_destroy(lf->uri);
lf->uri=fr;
if (lf->uri != NULL) linphone_address_destroy(lf->uri);
lf->uri = fr;
return 0;
}
@ -211,17 +213,19 @@ int linphone_friend_set_name(LinphoneFriend *lf, const char *name){
LinphoneVCard *vcard = NULL;
if (fr == NULL){
ms_error("linphone_friend_set_sip_addr() must be called before linphone_friend_set_name().");
ms_error("linphone_friend_set_address() must be called before linphone_friend_set_name().");
return -1;
}
linphone_address_set_display_name(fr,name);
linphone_address_set_display_name(fr, name);
vcard = linphone_friend_get_vcard(lf);
if (!vcard) {
linphone_friend_create_vcard(lf, name);
} else {
vcard = linphone_friend_get_vcard(lf);
}
if (vcard) {
linphone_vcard_set_full_name(vcard, name);
linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr));
}
return 0;
@ -771,10 +775,10 @@ bool_t linphone_friend_create_vcard(LinphoneFriend *fr, const char *name) {
} else {
const char *displayName = linphone_address_get_display_name(addr);
if (!displayName) {
ms_error("Friend's URI doesn't have a display name");
return FALSE;
fullName = linphone_address_get_username(addr);
} else {
fullName = displayName;
}
fullName = displayName;
}
if (!fullName) {

View file

@ -32,6 +32,8 @@ extern "C" LinphoneVCard* linphone_vcard_new(void) {
}
extern "C" void linphone_vcard_free(LinphoneVCard *vCard) {
if (!vCard) return;
vCard->belCard.reset();
ms_free(vCard);
}
@ -84,28 +86,63 @@ extern "C" LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buff
}
extern "C" const char * linphone_vcard_as_vcard4_string(LinphoneVCard *vCard) {
if (!vCard) return NULL;
return vCard->belCard->toFoldedString().c_str();
}
extern "C" void linphone_vcard_set_full_name(LinphoneVCard *vCard, const char *name) {
if (!vCard || !name) return;
shared_ptr<belcard::BelCardFullName> fn = belcard::BelCardGeneric::create<belcard::BelCardFullName>();
fn->setValue(name);
vCard->belCard->setFullName(fn);
}
extern "C" const char* linphone_vcard_get_full_name(const LinphoneVCard *vCard) {
if (!vCard) return NULL;
const char *result = vCard->belCard->getFullName() ? vCard->belCard->getFullName()->getValue().c_str() : NULL;
return result;
}
extern "C" void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard || !sip_address) return;
shared_ptr<belcard::BelCardImpp> impp = belcard::BelCardGeneric::create<belcard::BelCardImpp>();
impp->setValue(sip_address);
vCard->belCard->addImpp(impp);
}
extern "C" void linphone_vcard_remove_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard) return;
for (auto it = vCard->belCard->getImpp().begin(); it != vCard->belCard->getImpp().end(); ++it) {
const char *value = (*it)->getValue().c_str();
if (strcmp(value, sip_address) == 0) {
vCard->belCard->removeImpp(*it);
break;
}
}
}
extern "C" void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard, const char *sip_address) {
if (!vCard || !sip_address) return;
if (vCard->belCard->getImpp().size() > 0) {
const shared_ptr<belcard::BelCardImpp> impp = vCard->belCard->getImpp().front();
impp->setValue(sip_address);
} else {
shared_ptr<belcard::BelCardImpp> impp = belcard::BelCardGeneric::create<belcard::BelCardImpp>();
impp->setValue(sip_address);
vCard->belCard->addImpp(impp);
}
}
extern "C" MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard) {
MSList *result = NULL;
if (!vCard) return NULL;
for (auto it = vCard->belCard->getImpp().begin(); it != vCard->belCard->getImpp().end(); ++it) {
const char *value = (*it)->getValue().c_str();
if (strncmp(value, "sip:", 4) == 0) {

View file

@ -98,6 +98,20 @@ LINPHONE_PUBLIC const char* linphone_vcard_get_full_name(const LinphoneVCard *vC
*/
LINPHONE_PUBLIC void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char *sip_address);
/**
* Removes a SIP address in the vCard (if it exists), using the IMPP property
* @param[in] vCard the LinphoneVCard
* @param[in] sip_address the SIP address to remove
*/
LINPHONE_PUBLIC void linphone_vcard_remove_sip_address(LinphoneVCard *vCard, const char *sip_address);
/**
* Edits the preferred SIP address in the vCard (or the first one), using the IMPP property
* @param[in] vCard the LinphoneVCard
* @param[in] sip_address the new SIP address
*/
LINPHONE_PUBLIC void linphone_vcard_edit_main_sip_address(LinphoneVCard *vCard, const char *sip_address);
/**
* Returns the list of SIP addresses (as const char *) in the vCard (all the IMPP attributes that has an URI value starting by "sip:") or NULL
* @param[in] vCard the LinphoneVCard