From 6256cf1636fa5a5b8abb50f10a6aafe1d2f3b80a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 1 Jul 2016 10:34:16 +0200 Subject: [PATCH] Moved and renamed some vcard methods for python wrapper Cherry pick c8ae29742aee37727658df310f3be603d216c499 from master --- coreapi/carddav.c | 2 +- coreapi/friend.c | 2 +- coreapi/friendlist.c | 4 ++-- coreapi/private.h | 5 ----- coreapi/vcard.cc | 26 ++++++++++++++++---------- coreapi/vcard.h | 38 ++++++++++++++++++++++++++++++++++---- coreapi/vcard_stubs.c | 11 ++++++----- tester/vcard_tester.c | 20 ++++++++++---------- 8 files changed, 70 insertions(+), 38 deletions(-) diff --git a/coreapi/carddav.c b/coreapi/carddav.c index d63b20861..63b22c6bd 100644 --- a/coreapi/carddav.c +++ b/coreapi/carddav.c @@ -115,7 +115,7 @@ static void linphone_carddav_vcards_pulled(LinphoneCardDavContext *cdc, bctbx_li while (vCards) { LinphoneCardDavResponse *vCard = (LinphoneCardDavResponse *)vCards->data; if (vCard) { - LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer(cdc->friend_list->lc->vcard_context, vCard->vcard); + LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(cdc->friend_list->lc->vcard_context, vCard->vcard); LinphoneFriend *lf = NULL; bctbx_list_t *local_friend = NULL; diff --git a/coreapi/friend.c b/coreapi/friend.c index af6b511d8..896e4cab5 100644 --- a/coreapi/friend.c +++ b/coreapi/friend.c @@ -1256,7 +1256,7 @@ static int create_friend(void *data, int argc, char **argv, char **colName) { LinphoneVcard *vcard = NULL; unsigned int storage_id = (unsigned int)atoi(argv[0]); - vcard = linphone_vcard_new_from_vcard4_buffer(context, argv[6]); + vcard = linphone_vcard_context_get_vcard_from_buffer(context, argv[6]); if (vcard) { linphone_vcard_set_etag(vcard, argv[7]); linphone_vcard_set_url(vcard, argv[8]); diff --git a/coreapi/friendlist.c b/coreapi/friendlist.c index 18f5c970a..fb36aec67 100644 --- a/coreapi/friendlist.c +++ b/coreapi/friendlist.c @@ -781,7 +781,7 @@ int linphone_friend_list_import_friends_from_vcard4_file(LinphoneFriendList *lis return -1; } - vcards = linphone_vcard_list_from_vcard4_file(list->lc->vcard_context, vcard_file); + vcards = linphone_vcard_context_get_vcard_list_from_file(list->lc->vcard_context, vcard_file); vcards_iterator = vcards; if (!vcards) { ms_error("Failed to parse the file %s", vcard_file); @@ -821,7 +821,7 @@ int linphone_friend_list_import_friends_from_vcard4_buffer(LinphoneFriendList *l return -1; } - vcards = linphone_vcard_list_from_vcard4_buffer(list->lc->vcard_context, vcard_buffer); + vcards = linphone_vcard_context_get_vcard_list_from_buffer(list->lc->vcard_context, vcard_buffer); vcards_iterator = vcards; if (!vcards) { ms_error("Failed to parse the buffer"); diff --git a/coreapi/private.h b/coreapi/private.h index af1930480..094737be1 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1555,11 +1555,6 @@ char *linphone_presence_model_to_xml(LinphonePresenceModel *model) ; void linphone_call_check_ice_session(LinphoneCall *call, IceRole role, bool_t is_reinvite); -LinphoneVcardContext* linphone_vcard_context_new(void); -void linphone_vcard_context_destroy(LinphoneVcardContext *context); -void* linphone_vcard_context_get_user_data(LinphoneVcardContext *context); -void linphone_vcard_context_set_user_data(LinphoneVcardContext *context, void *data); - #ifdef __cplusplus } #endif diff --git a/coreapi/vcard.cc b/coreapi/vcard.cc index 388422915..f944ad07c 100644 --- a/coreapi/vcard.cc +++ b/coreapi/vcard.cc @@ -53,7 +53,7 @@ void linphone_vcard_context_destroy(LinphoneVcardContext *context) { } } -void* linphone_vcard_context_get_user_data(LinphoneVcardContext *context) { +void* linphone_vcard_context_get_user_data(const LinphoneVcardContext *context) { return context ? context->user_data : NULL; } @@ -82,11 +82,13 @@ void linphone_vcard_free(LinphoneVcard *vCard) { ms_free(vCard); } -bctbx_list_t* linphone_vcard_list_from_vcard4_file(LinphoneVcardContext *context, const char *filename) { +bctbx_list_t* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *filename) { bctbx_list_t *result = NULL; if (context && filename) { - belcard::BelCardParser *parser = context->parser; - shared_ptr belCards = parser->parseFile(filename); + if (!context->parser) { + context->parser = new belcard::BelCardParser(); + } + shared_ptr belCards = context->parser->parseFile(filename); if (belCards) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { shared_ptr belCard = (*it); @@ -98,11 +100,13 @@ bctbx_list_t* linphone_vcard_list_from_vcard4_file(LinphoneVcardContext *context return result; } -bctbx_list_t* linphone_vcard_list_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer) { +bctbx_list_t* linphone_vcard_context_get_vcard_list_from_buffer(LinphoneVcardContext *context, const char *buffer) { bctbx_list_t *result = NULL; if (context && buffer) { - belcard::BelCardParser *parser = context->parser; - shared_ptr belCards = parser->parse(buffer); + if (!context->parser) { + context->parser = new belcard::BelCardParser(); + } + shared_ptr belCards = context->parser->parse(buffer); if (belCards) { for (auto it = belCards->getCards().begin(); it != belCards->getCards().end(); ++it) { shared_ptr belCard = (*it); @@ -114,11 +118,13 @@ bctbx_list_t* linphone_vcard_list_from_vcard4_buffer(LinphoneVcardContext *conte return result; } -LinphoneVcard* linphone_vcard_new_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer) { +LinphoneVcard* linphone_vcard_context_get_vcard_from_buffer(LinphoneVcardContext *context, const char *buffer) { LinphoneVcard *vCard = NULL; if (context && buffer) { - belcard::BelCardParser *parser = context->parser; - shared_ptr belCard = parser->parseOne(buffer); + if (!context->parser) { + context->parser = new belcard::BelCardParser(); + } + shared_ptr belCard = context->parser->parseOne(buffer); if (belCard) { vCard = linphone_vcard_new_from_belcard(belCard); } else { diff --git a/coreapi/vcard.h b/coreapi/vcard.h index 62674a33d..550fa8d81 100644 --- a/coreapi/vcard.h +++ b/coreapi/vcard.h @@ -37,10 +37,36 @@ extern "C" */ /** - * Linphone vCard context object. + * The LinphoneVcardContext object. */ typedef struct _LinphoneVcardContext LinphoneVcardContext; +/** + * Creates a vCard context to reuse the same BelCardParser object + * @return a new LinphoneVcardContext object + */ +LINPHONE_PUBLIC LinphoneVcardContext* linphone_vcard_context_new(void); + +/** + * Destroys the vCard context + * @param[in] context a LinphoneVcardContext object + */ +LINPHONE_PUBLIC void linphone_vcard_context_destroy(LinphoneVcardContext *context); + +/** + * Gets the user data set in the LinphoneVcardContext + * @param[in] context a LinphoneVcardContext object + * @return the user data pointer + */ +LINPHONE_PUBLIC void* linphone_vcard_context_get_user_data(const LinphoneVcardContext *context); + +/** + * Sets the user data in the LinphoneVcardContext + * @param[in] context a LinphoneVcardContext object + * @param[in] data the user data pointer + */ +LINPHONE_PUBLIC void linphone_vcard_context_set_user_data(LinphoneVcardContext *context, void *data); + /** * The LinphoneVcard object. */ @@ -48,6 +74,7 @@ typedef struct _LinphoneVcard LinphoneVcard; /** * Creates a LinphoneVcard object that has a pointer to an empty vCard + * @return a new LinphoneVcard object */ LINPHONE_PUBLIC LinphoneVcard* linphone_vcard_new(void); @@ -59,24 +86,27 @@ LINPHONE_PUBLIC void linphone_vcard_free(LinphoneVcard *vCard); /** * Uses belcard to parse the content of a file and returns all the vcards it contains as LinphoneVcards, or NULL if it contains none. + * @param[in] context the vCard context to use (speed up the process by not creating a Belcard parser each time) * @param[in] file the path to the file to parse * @return \mslist{LinphoneVcard} */ -LINPHONE_PUBLIC bctbx_list_t* linphone_vcard_list_from_vcard4_file(LinphoneVcardContext *context, const char *file); +LINPHONE_PUBLIC bctbx_list_t* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *file); /** * Uses belcard to parse the content of a buffer and returns all the vcards it contains as LinphoneVcards, or NULL if it contains none. + * @param[in] context the vCard context to use (speed up the process by not creating a Belcard parser each time) * @param[in] buffer the buffer to parse * @return \mslist{LinphoneVcard} */ -LINPHONE_PUBLIC bctbx_list_t* linphone_vcard_list_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer); +LINPHONE_PUBLIC bctbx_list_t* linphone_vcard_context_get_vcard_list_from_buffer(LinphoneVcardContext *context, const char *buffer); /** * Uses belcard to parse the content of a buffer and returns one vCard if possible, or NULL otherwise. + * @param[in] context the vCard context to use (speed up the process by not creating a Belcard parser each time) * @param[in] buffer the buffer to parse * @return a LinphoneVcard if one could be parsed, or NULL otherwise */ -LINPHONE_PUBLIC LinphoneVcard* linphone_vcard_new_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer); +LINPHONE_PUBLIC LinphoneVcard* linphone_vcard_context_get_vcard_from_buffer(LinphoneVcardContext *context, const char *buffer); /** * Returns the vCard4 representation of the LinphoneVcard. diff --git a/coreapi/vcard_stubs.c b/coreapi/vcard_stubs.c index 50a8fc2e9..916cd541a 100644 --- a/coreapi/vcard_stubs.c +++ b/coreapi/vcard_stubs.c @@ -31,8 +31,9 @@ void linphone_vcard_context_destroy(LinphoneVcardContext *context) { } -void* linphone_vcard_context_get_user_data(LinphoneVcardContext *context) { - return NULL; + +void* linphone_vcard_context_get_user_data(const LinphoneVcardContext *context) { + return context ? context->user_data : NULL; } void linphone_vcard_context_set_user_data(LinphoneVcardContext *context, void *data) { @@ -51,15 +52,15 @@ void linphone_vcard_free(LinphoneVcard *vCard) { } -MSList* linphone_vcard_list_from_vcard4_file(LinphoneVcardContext *context, const char *filename) { +MSList* linphone_vcard_context_get_vcard_list_from_file(LinphoneVcardContext *context, const char *filename) { return NULL; } -MSList* linphone_vcard_list_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer) { +MSList* linphone_vcard_context_get_vcard_list_from_buffer(LinphoneVcardContext *context, const char *buffer) { return NULL; } -LinphoneVcard* linphone_vcard_new_from_vcard4_buffer(LinphoneVcardContext *context, const char *buffer) { +LinphoneVcard* linphone_vcard_context_get_vcard_from_buffer(LinphoneVcardContext *context, const char *buffer) { return NULL; } diff --git a/tester/vcard_tester.c b/tester/vcard_tester.c index 28631db1f..790244f19 100644 --- a/tester/vcard_tester.c +++ b/tester/vcard_tester.c @@ -138,7 +138,7 @@ static void linphone_vcard_update_existing_friends_test(void) { static void linphone_vcard_phone_numbers_and_sip_addresses(void) { LinphoneCoreManager* manager = linphone_core_manager_new2("empty_rc", FALSE); - LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nIMPP;TYPE=home:sip:sylvain@sip.linphone.org\r\nTEL;TYPE=work:0952636505\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nIMPP;TYPE=home:sip:sylvain@sip.linphone.org\r\nTEL;TYPE=work:0952636505\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); bctbx_list_t *sip_addresses = linphone_friend_get_addresses(lf); bctbx_list_t *phone_numbers = linphone_friend_get_phone_numbers(lf); @@ -150,7 +150,7 @@ static void linphone_vcard_phone_numbers_and_sip_addresses(void) { if (phone_numbers) bctbx_list_free(phone_numbers); linphone_friend_unref(lf); - lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nTEL;TYPE=work:0952636505\r\nTEL:0476010203\r\nEND:VCARD\r\n"); + lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nTEL;TYPE=work:0952636505\r\nTEL:0476010203\r\nEND:VCARD\r\n"); lf = linphone_friend_new_from_vcard(lvc); sip_addresses = linphone_friend_get_addresses(lf); phone_numbers = linphone_friend_get_phone_numbers(lf); @@ -473,7 +473,7 @@ static void carddav_sync_2(void) { static void carddav_sync_3(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); - LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nFN:Sylvain Berfini\r\nIMPP;TYPE=work:sip:sylvain@sip.linphone.org\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nFN:Sylvain Berfini\r\nIMPP;TYPE=work:sip:sylvain@sip.linphone.org\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); char *friends_db = bc_tester_file("friends.db"); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); @@ -514,7 +514,7 @@ static void carddav_sync_3(void) { static void carddav_sync_4(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); - LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneCardDavContext *c = NULL; @@ -575,7 +575,7 @@ static void carddav_sync_status_changed(LinphoneFriendList *list, LinphoneFriend static void carddav_integration(void) { LinphoneCoreManager *manager = linphone_core_manager_new2("carddav_rc", FALSE); LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); - LinphoneVcard *lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); LinphoneFriend *lf = linphone_friend_new_from_vcard(lvc); LinphoneVcard *lvc2 = NULL; LinphoneFriend *lf2 = NULL; @@ -608,12 +608,12 @@ static void carddav_integration(void) { linphone_friend_unref(lf); lf = NULL; - lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n"); + lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n"); lf = linphone_friend_new_from_vcard(lvc); BC_ASSERT_EQUAL(linphone_friend_list_add_local_friend(lfl, lf), LinphoneFriendListOK, int, "%d"); linphone_friend_unref(lf); - lvc2 = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); + lvc2 = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sberfini@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); linphone_vcard_set_url(lvc2, "/card.php/addressbooks/tester/default/me.vcf"); lf2 = linphone_friend_new_from_vcard(lvc2); linphone_friend_set_ref_key(lf2, refkey); @@ -691,7 +691,7 @@ static void carddav_clean(void) { // This is to ensure the content of the test } bctbx_list_free(friends); - lvc = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sylvain@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); + lvc = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Sylvain Berfini\r\nIMPP:sip:sylvain@sip.linphone.org\r\nUID:1f08dd48-29ac-4097-8e48-8596d7776283\r\nEND:VCARD\r\n"); linphone_vcard_set_url(lvc, "http://dav.linphone.org/card.php/addressbooks/tester/default/me.vcf"); lf = linphone_friend_new_from_vcard(lvc); linphone_friend_list_add_friend(lfl, lf); @@ -739,9 +739,9 @@ static void carddav_server_to_client_and_client_to_sever_sync(void) { LinphoneFriendList *lfl = linphone_core_create_friend_list(manager->lc); LinphoneFriendListCbs *cbs = linphone_friend_list_get_callbacks(lfl); LinphoneCardDAVStats *stats = (LinphoneCardDAVStats *)ms_new0(LinphoneCardDAVStats, 1); - LinphoneVcard *lvc1 = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc1 = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Margaux Clerc\r\nIMPP;TYPE=work:sip:margaux@sip.linphone.org\r\nEND:VCARD\r\n"); LinphoneFriend *lf1 = linphone_friend_new_from_vcard(lvc1); - LinphoneVcard *lvc2 = linphone_vcard_new_from_vcard4_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n"); + LinphoneVcard *lvc2 = linphone_vcard_context_get_vcard_from_buffer(manager->lc->vcard_context, "BEGIN:VCARD\r\nVERSION:4.0\r\nFN:Ghislain Mary\r\nIMPP;TYPE=work:sip:ghislain@sip.linphone.org\r\nEND:VCARD\r\n"); LinphoneFriend *lf2 = linphone_friend_new_from_vcard(lvc2); bctbx_list_t *friends = NULL, *friends_iterator = NULL;