Commit e047dcf8 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Improved vcard import/export code a bit

parent 1ff3d2d1
...@@ -40,6 +40,12 @@ LinphoneVcard* linphone_vcard_new(void) { ...@@ -40,6 +40,12 @@ LinphoneVcard* linphone_vcard_new(void) {
return vCard; return vCard;
} }
static LinphoneVcard* linphone_vcard_new_from_belcard(shared_ptr<belcard::BelCard> belcard) {
LinphoneVcard* vCard = (LinphoneVcard*) ms_new0(LinphoneVcard, 1);
vCard->belCard = belcard;
return vCard;
}
void linphone_vcard_free(LinphoneVcard *vCard) { void linphone_vcard_free(LinphoneVcard *vCard) {
if (!vCard) return; if (!vCard) return;
...@@ -49,14 +55,13 @@ void linphone_vcard_free(LinphoneVcard *vCard) { ...@@ -49,14 +55,13 @@ void linphone_vcard_free(LinphoneVcard *vCard) {
MSList* linphone_vcard_list_from_vcard4_file(const char *filename) { MSList* linphone_vcard_list_from_vcard4_file(const char *filename) {
MSList *result = NULL; MSList *result = NULL;
if (filename && ortp_file_exist(filename) == 0) { if (filename) {
belcard::BelCardParser parser = belcard::BelCardParser::getInstance(); belcard::BelCardParser parser = belcard::BelCardParser::getInstance();
shared_ptr<belcard::BelCardList> belCards = parser.parseFile(filename); shared_ptr<belcard::BelCardList> belCards = parser.parseFile(filename);
if (belCards) { if (belCards) {
for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) {
shared_ptr<belcard::BelCard> belcard = (*it); shared_ptr<belcard::BelCard> belCard = (*it);
LinphoneVcard *vCard = linphone_vcard_new(); LinphoneVcard *vCard = linphone_vcard_new_from_belcard(belCard);
vCard->belCard = belcard;
result = ms_list_append(result, vCard); result = ms_list_append(result, vCard);
} }
} }
...@@ -72,8 +77,7 @@ MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) { ...@@ -72,8 +77,7 @@ MSList* linphone_vcard_list_from_vcard4_buffer(const char *buffer) {
if (belCards) { if (belCards) {
for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) {
shared_ptr<belcard::BelCard> belCard = (*it); shared_ptr<belcard::BelCard> belCard = (*it);
LinphoneVcard *vCard = linphone_vcard_new(); LinphoneVcard *vCard = linphone_vcard_new_from_belcard(belCard);
vCard->belCard = belCard;
result = ms_list_append(result, vCard); result = ms_list_append(result, vCard);
} }
} }
...@@ -87,8 +91,7 @@ LinphoneVcard* linphone_vcard_new_from_vcard4_buffer(const char *buffer) { ...@@ -87,8 +91,7 @@ LinphoneVcard* linphone_vcard_new_from_vcard4_buffer(const char *buffer) {
belcard::BelCardParser parser = belcard::BelCardParser::getInstance(); belcard::BelCardParser parser = belcard::BelCardParser::getInstance();
shared_ptr<belcard::BelCard> belCard = parser.parseOne(buffer); shared_ptr<belcard::BelCard> belCard = parser.parseOne(buffer);
if (belCard) { if (belCard) {
vCard = linphone_vcard_new(); vCard = linphone_vcard_new_from_belcard(belCard);
vCard->belCard = belCard;
} else { } else {
ms_error("Couldn't parse buffer %s", buffer); ms_error("Couldn't parse buffer %s", buffer);
} }
......
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