Commit 0a59544a authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Added checks for null values in vcard.cc and added new methods to manipulate...

Added checks for null values in vcard.cc and added new methods to manipulate sip addresses in vcard from friend
parent f6edea6e
...@@ -199,10 +199,12 @@ void linphone_core_interpret_friend_uri(LinphoneCore *lc, const char *uri, char ...@@ -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){ 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); linphone_address_clean(fr);
if (lf->uri!=NULL) linphone_address_destroy(lf->uri); if (lf->uri != NULL) linphone_address_destroy(lf->uri);
lf->uri=fr; lf->uri = fr;
return 0; return 0;
} }
...@@ -211,17 +213,19 @@ int linphone_friend_set_name(LinphoneFriend *lf, const char *name){ ...@@ -211,17 +213,19 @@ int linphone_friend_set_name(LinphoneFriend *lf, const char *name){
LinphoneVCard *vcard = NULL; LinphoneVCard *vcard = NULL;
if (fr == 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; return -1;
} }
linphone_address_set_display_name(fr,name); linphone_address_set_display_name(fr, name);
vcard = linphone_friend_get_vcard(lf); vcard = linphone_friend_get_vcard(lf);
if (!vcard) { if (!vcard) {
linphone_friend_create_vcard(lf, name); linphone_friend_create_vcard(lf, name);
} else { vcard = linphone_friend_get_vcard(lf);
}
if (vcard) {
linphone_vcard_set_full_name(vcard, name); linphone_vcard_set_full_name(vcard, name);
linphone_vcard_edit_main_sip_address(vcard, linphone_address_as_string_uri_only(fr));
} }
return 0; return 0;
...@@ -771,10 +775,10 @@ bool_t linphone_friend_create_vcard(LinphoneFriend *fr, const char *name) { ...@@ -771,10 +775,10 @@ bool_t linphone_friend_create_vcard(LinphoneFriend *fr, const char *name) {
} else { } else {
const char *displayName = linphone_address_get_display_name(addr); const char *displayName = linphone_address_get_display_name(addr);
if (!displayName) { if (!displayName) {
ms_error("Friend's URI doesn't have a display name"); fullName = linphone_address_get_username(addr);
return FALSE; } else {
fullName = displayName;
} }
fullName = displayName;
} }
if (!fullName) { if (!fullName) {
......
...@@ -32,6 +32,8 @@ extern "C" LinphoneVCard* linphone_vcard_new(void) { ...@@ -32,6 +32,8 @@ extern "C" LinphoneVCard* linphone_vcard_new(void) {
} }
extern "C" void linphone_vcard_free(LinphoneVCard *vCard) { extern "C" void linphone_vcard_free(LinphoneVCard *vCard) {
if (!vCard) return;
vCard->belCard.reset(); vCard->belCard.reset();
ms_free(vCard); ms_free(vCard);
} }
...@@ -84,28 +86,63 @@ extern "C" LinphoneVCard* linphone_vcard_new_from_vcard4_buffer(const char *buff ...@@ -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) { extern "C" const char * linphone_vcard_as_vcard4_string(LinphoneVCard *vCard) {
if (!vCard) return NULL;
return vCard->belCard->toFoldedString().c_str(); return vCard->belCard->toFoldedString().c_str();
} }
extern "C" void linphone_vcard_set_full_name(LinphoneVCard *vCard, const char *name) { 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>(); shared_ptr<belcard::BelCardFullName> fn = belcard::BelCardGeneric::create<belcard::BelCardFullName>();
fn->setValue(name); fn->setValue(name);
vCard->belCard->setFullName(fn); vCard->belCard->setFullName(fn);
} }
extern "C" const char* linphone_vcard_get_full_name(const LinphoneVCard *vCard) { 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; const char *result = vCard->belCard->getFullName() ? vCard->belCard->getFullName()->getValue().c_str() : NULL;
return result; return result;
} }
extern "C" void linphone_vcard_add_sip_address(LinphoneVCard *vCard, const char *sip_address) { 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>(); shared_ptr<belcard::BelCardImpp> impp = belcard::BelCardGeneric::create<belcard::BelCardImpp>();
impp->setValue(sip_address); impp->setValue(sip_address);
vCard->belCard->addImpp(impp); 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) { extern "C" MSList* linphone_vcard_get_sip_addresses(const LinphoneVCard *vCard) {
MSList *result = NULL; MSList *result = NULL;
if (!vCard) return NULL;
for (auto it = vCard->belCard->getImpp().begin(); it != vCard->belCard->getImpp().end(); ++it) { for (auto it = vCard->belCard->getImpp().begin(); it != vCard->belCard->getImpp().end(); ++it) {
const char *value = (*it)->getValue().c_str(); const char *value = (*it)->getValue().c_str();
if (strncmp(value, "sip:", 4) == 0) { if (strncmp(value, "sip:", 4) == 0) {
......
...@@ -98,6 +98,20 @@ LINPHONE_PUBLIC const char* linphone_vcard_get_full_name(const LinphoneVCard *vC ...@@ -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); 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 * 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 * @param[in] vCard the LinphoneVCard
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment