From 73bf010d1bc22c0ae896c0f08084e77c6e0680e9 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Wed, 10 Jan 2018 16:36:31 +0100 Subject: [PATCH] Use LinphoneCoreCbs instead of LinphoneVTable in testers. --- coreapi/linphonecore.c | 27 ++++++------- coreapi/tester_utils.h | 1 - include/linphone/core.h | 6 ++- tester/accountmanager.c | 22 ++--------- tester/call_single_tester.c | 75 ++++++++++++++++------------------- tester/call_video_tester.c | 24 ++++++------ tester/liblinphone_tester.h | 10 ++--- tester/message_tester.c | 7 ++-- tester/tester.c | 78 ++++++++++++++++++------------------- 9 files changed, 113 insertions(+), 137 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index ad7b151ab..d7540b8ae 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2366,22 +2366,12 @@ LinphoneCore *linphone_core_new_with_config(const LinphoneCoreVTable *vtable, st return _linphone_core_new_with_config_and_start(vtable, config, userdata, TRUE); } -LinphoneCore *_linphone_core_new ( - const LinphoneCoreVTable *vtable, - const char *config_path, - const char *factory_config_path, - void * userdata, - bool_t automatically_start -) { - LinphoneConfig *config = lp_config_new_with_factory(config_path, factory_config_path); - LinphoneCore *lc = _linphone_core_new_with_config_and_start(vtable, config, userdata, automatically_start); - linphone_config_unref(config); - return lc; -} - LinphoneCore *linphone_core_new(const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void * userdata) { - return _linphone_core_new(vtable, config_path, factory_config_path, userdata, TRUE); + LinphoneConfig *config = lp_config_new_with_factory(config_path, factory_config_path); + LinphoneCore *lc = _linphone_core_new_with_config_and_start(vtable, config, userdata, TRUE); + linphone_config_unref(config); + return lc; } LinphoneCore *linphone_core_ref(LinphoneCore *lc) { @@ -6703,8 +6693,13 @@ int linphone_core_get_video_dscp(const LinphoneCore *lc){ } void linphone_core_set_chat_database_path (LinphoneCore *lc, const char *path) { - if (!linphone_core_conference_server_enabled(lc)) - L_GET_PRIVATE(lc->cppPtr)->mainDb->import(LinphonePrivate::MainDb::Sqlite3, path); + if (!linphone_core_conference_server_enabled(lc)) { + auto &mainDb = L_GET_PRIVATE(lc->cppPtr)->mainDb; + if (mainDb) + mainDb->import(LinphonePrivate::MainDb::Sqlite3, path); + else + ms_warning("linphone_core_set_chat_database_path() needs to be called once linphone_core_start() has been called"); + } } const char *linphone_core_get_chat_database_path (const LinphoneCore *) { diff --git a/coreapi/tester_utils.h b/coreapi/tester_utils.h index 4fd79a951..f6d836b5f 100644 --- a/coreapi/tester_utils.h +++ b/coreapi/tester_utils.h @@ -45,7 +45,6 @@ typedef enum _LinphoneProxyConfigAddressComparisonResult{ extern "C" { #endif -LINPHONE_PUBLIC LinphoneCore *_linphone_core_new (const LinphoneCoreVTable *vtable, const char *config_path, const char *factory_config_path, void * userdata, bool_t automatically_start); LINPHONE_PUBLIC LinphoneVcardContext *linphone_core_get_vcard_context(const LinphoneCore *lc); LINPHONE_PUBLIC bool_t linphone_core_rtcp_enabled(const LinphoneCore *lc); LINPHONE_PUBLIC void linphone_core_get_local_ip(LinphoneCore *lc, int af, const char *dest, char *result); diff --git a/include/linphone/core.h b/include/linphone/core.h index 469e1e3eb..d2efdce47 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -4942,15 +4942,17 @@ void linphone_core_set_linphone_specs (LinphoneCore *core, const char *specs); * Set the chat database path. * @param lc the linphone core * @param path the database path + * @deprecated 2018-01-10: Use only for migration purposes */ -LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path); +LINPHONE_DEPRECATED LINPHONE_PUBLIC void linphone_core_set_chat_database_path(LinphoneCore *lc, const char *path); /** * Get path to the database file used for storing chat messages. * @param lc the linphone core * @return file path or NULL if not exist + * @deprecated 2018-01-10 **/ -LINPHONE_PUBLIC const char *linphone_core_get_chat_database_path(const LinphoneCore *lc); +LINPHONE_DEPRECATED LINPHONE_PUBLIC const char *linphone_core_get_chat_database_path(const LinphoneCore *lc); /** * Create a client-side group chat room. When calling this function the chat room is only created diff --git a/tester/accountmanager.c b/tester/accountmanager.c index 70e7e63a4..51f8694f0 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -131,17 +131,7 @@ static void account_created_on_server_cb(LinphoneCore *lc, LinphoneProxyConfig * } } -// TEMPORARY CODE: remove function below when flexisip is updated, this is not needed anymore! -// The new flexisip now answer "200 Test account created" when creating a test account, and do not -// challenge authentication anymore! so this code is not used for newer version -static void account_created_auth_requested_cb(LinphoneCore *lc, const char *username, const char *realm, const char *domain){ - Account *account=(Account*)linphone_core_get_user_data(lc); - account->created=1; -} -// TEMPORARY CODE: remove line above when flexisip is updated, this is not needed anymore! - void account_create_on_server(Account *account, const LinphoneProxyConfig *refcfg, const char* phone_alias){ - LinphoneCoreVTable vtable={0}; LinphoneCore *lc; LinphoneAddress *tmp_identity=linphone_address_clone(account->modified_identity); LinphoneProxyConfig *cfg; @@ -149,13 +139,11 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf char *tmp; LinphoneAddress *server_addr; LinphoneSipTransports tr; - char *chatdb; + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); - vtable.registration_state_changed=account_created_on_server_cb; - // TEMPORARY CODE: remove line below when flexisip is updated, this is not needed anymore! - vtable.auth_info_requested=account_created_auth_requested_cb; - lc=configure_lc_from(&vtable,bc_tester_get_resource_dir_prefix(),NULL,account); - chatdb = ms_strdup(linphone_core_get_chat_database_path(lc)); + linphone_core_cbs_set_registration_state_changed(cbs, account_created_on_server_cb); + lc = configure_lc_from(cbs, bc_tester_get_resource_dir_prefix(), NULL, account); + linphone_core_cbs_unref(cbs); tr.udp_port=LC_SIP_TRANSPORT_RANDOM; tr.tcp_port=LC_SIP_TRANSPORT_RANDOM; tr.tls_port=LC_SIP_TRANSPORT_RANDOM; @@ -211,8 +199,6 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf ms_error("Account creation could not clean the registration context."); } linphone_core_unref(lc); - unlink(chatdb); - ms_free(chatdb); } static LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyConfig *cfg, LinphoneCoreManager *cm){ diff --git a/tester/call_single_tester.c b/tester/call_single_tester.c index b0ce5d7c8..3fdea92b1 100644 --- a/tester/call_single_tester.c +++ b/tester/call_single_tester.c @@ -1826,7 +1826,7 @@ static void call_with_custom_sdp_attributes(void) { const LinphoneCallParams *marie_remote_params; const LinphoneCallParams *pauline_remote_params; const char *value; - LinphoneCoreVTable *vtable; + LinphoneCoreCbs *cbs; pauline_params = linphone_core_create_call_params(pauline->lc, NULL); linphone_call_params_add_custom_sdp_attribute(pauline_params, "weather", "bad"); @@ -1849,9 +1849,9 @@ static void call_with_custom_sdp_attributes(void) { BC_ASSERT_PTR_NOT_NULL(value); if (value) BC_ASSERT_STRING_EQUAL(value, "almost"); - vtable = linphone_core_v_table_new(); - vtable->call_state_changed = call_with_custom_sdp_attributes_cb; - linphone_core_add_listener(marie->lc, vtable); + cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_with_custom_sdp_attributes_cb); + linphone_core_add_callbacks(marie->lc, cbs); pauline_params = linphone_core_create_call_params(pauline->lc, call_pauline); linphone_call_params_clear_custom_sdp_attributes(pauline_params); linphone_call_params_clear_custom_sdp_media_attributes(pauline_params, LinphoneStreamTypeAudio); @@ -1868,6 +1868,7 @@ static void call_with_custom_sdp_attributes(void) { end_call(pauline, marie); + linphone_core_cbs_unref(cbs); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); } @@ -1915,9 +1916,7 @@ static void call_caller_with_custom_header_or_sdp_attributes(void) { LinphoneCoreManager *caller_mgr = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); LinphoneCall *call_caller = NULL, *call_callee = NULL; LinphoneCallParams *caller_params; // *callee_params ; - - LinphoneCoreVTable *vtable; - + LinphoneCoreCbs *cbs; LinphoneCallTestParams caller_test_params = {0}; LinphoneCallTestParams callee_test_params = {0}; @@ -1941,11 +1940,11 @@ static void call_caller_with_custom_header_or_sdp_attributes(void) { setup_sdp_handling(&caller_test_params, caller_mgr); setup_sdp_handling(&callee_test_params, callee_mgr); - // Assign dedicated callback to vtable for caller and callee - vtable = linphone_core_v_table_new(); - vtable->call_state_changed = call_with_custom_header_or_sdp_cb; - linphone_core_add_listener(callee_mgr->lc, vtable); - linphone_core_add_listener(caller_mgr->lc, vtable); + // Assign dedicated callback for caller and callee + cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_with_custom_header_or_sdp_cb); + linphone_core_add_callbacks(callee_mgr->lc, cbs); + linphone_core_add_callbacks(caller_mgr->lc, cbs); //Caller initates the call with INVITE // caller params not null @@ -1971,8 +1970,6 @@ static void call_caller_with_custom_header_or_sdp_attributes(void) { BC_ASSERT_EQUAL(caller_mgr->stat.number_of_LinphoneCallOutgoingProgress,initial_caller.number_of_LinphoneCallOutgoingProgress+1, int, "%d"); - - LinphoneCallParams *default_params=linphone_core_create_call_params(callee_mgr->lc,call_callee); ms_message("Created default call params with video=%i", linphone_call_params_video_enabled(default_params)); linphone_core_accept_call_with_params(callee_mgr->lc,call_callee,default_params); @@ -1998,6 +1995,7 @@ static void call_caller_with_custom_header_or_sdp_attributes(void) { end_call(caller_mgr, callee_mgr); + linphone_core_cbs_unref(cbs); linphone_core_manager_destroy(callee_mgr); linphone_core_manager_destroy(caller_mgr); } @@ -2037,20 +2035,16 @@ static void call_callee_with_custom_header_or_sdp_attributes(void) { LinphoneCoreManager *caller_mgr = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); LinphoneCall *call_caller = NULL, *call_callee = NULL; LinphoneCallParams *callee_params, *caller_params ; - - LinphoneCoreVTable *vtable; + LinphoneCoreCbs *cbs; const char *value; LinphoneCallTestParams caller_test_params = {0}; LinphoneCallTestParams callee_test_params = {0}; - stats initial_caller=caller_mgr->stat; stats initial_callee=callee_mgr->stat; bool_t did_receive_call; const LinphoneCallParams *caller_remote_params; caller_params = linphone_core_create_call_params(caller_mgr->lc, NULL); - - callee_test_params.base = NULL; caller_test_params.base = NULL; @@ -2061,11 +2055,11 @@ static void call_callee_with_custom_header_or_sdp_attributes(void) { setup_sdp_handling(&caller_test_params, caller_mgr); setup_sdp_handling(&callee_test_params, callee_mgr); - // Assign dedicated callback to vtable for caller and callee - vtable = linphone_core_v_table_new(); - vtable->call_state_changed = call_callee_with_custom_header_or_sdp_cb; - linphone_core_add_listener(callee_mgr->lc, vtable); - linphone_core_add_listener(caller_mgr->lc, vtable); + // Assign dedicated callback for caller and callee + cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_callee_with_custom_header_or_sdp_cb); + linphone_core_add_callbacks(callee_mgr->lc, cbs); + linphone_core_add_callbacks(caller_mgr->lc, cbs); //Caller initates the call with INVITE // caller params not null @@ -2124,6 +2118,7 @@ static void call_callee_with_custom_header_or_sdp_attributes(void) { linphone_call_params_unref(caller_params); end_call(caller_mgr, callee_mgr); + linphone_core_cbs_unref(cbs); linphone_core_manager_destroy(callee_mgr); linphone_core_manager_destroy(caller_mgr); } @@ -3575,7 +3570,6 @@ static void call_rejected_because_wrong_credentials_with_params(const char* user linphone_core_set_user_agent(marie->lc,user_agent,NULL); } if (!enable_auth_req_cb) { - // ((VTableReference*)(marie->lc->vtable_refs->data))->cbs->vtable->auth_info_requested=NULL; LinphoneCoreCbs *cbs = linphone_core_get_first_callbacks(marie->lc); linphone_core_cbs_set_auth_info_requested(cbs, NULL); linphone_core_add_auth_info(marie->lc,wrong_auth_info); @@ -4204,15 +4198,16 @@ static void call_with_transport_change_base(bool_t succesfull_call) { LinphoneSipTransports sip_tr; LinphoneCoreManager* marie; LinphoneCoreManager* pauline; - LinphoneCoreVTable * v_table; - v_table = linphone_core_v_table_new(); - v_table->call_state_changed=call_state_changed_2; + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_state_changed_2); marie = linphone_core_manager_new("marie_rc"); pauline = linphone_core_manager_new(transport_supported(LinphoneTransportTls) ? "pauline_rc" : "pauline_tcp_rc"); - linphone_core_add_listener(marie->lc,v_table); - v_table = linphone_core_v_table_new(); - v_table->call_state_changed=call_state_changed_3; - linphone_core_add_listener(marie->lc,v_table); + linphone_core_add_callbacks(marie->lc, cbs); + linphone_core_cbs_unref(cbs); + cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_state_changed_3); + linphone_core_add_callbacks(marie->lc, cbs); + linphone_core_cbs_unref(cbs); sip_tr.udp_port = 0; sip_tr.tcp_port = 45875; @@ -4734,7 +4729,7 @@ static void custom_rtp_modifier(bool_t pauseResumeTest, bool_t recordTest) { LinphoneCall* call_marie = NULL; const rtp_stats_t * stats; bool_t call_ok; - LinphoneCoreVTable * v_table; + LinphoneCoreCbs *cbs; RtpTransportModifier *rtptm_marie = NULL; RtpTransportModifier *rtptm_pauline = NULL; RtpTransportModifierData *data_marie = NULL; @@ -4746,14 +4741,12 @@ static void custom_rtp_modifier(bool_t pauseResumeTest, bool_t recordTest) { double similar = 1; // The factor of similarity between the played file and the one recorded const double threshold = 0.85; // Minimum similarity value to consider the record file equal to the one sent - // We create a new vtable to listen only to the call state changes, in order to plug our RTP Transport Modifier when the call will be established - v_table = linphone_core_v_table_new(); - v_table->call_state_changed = call_state_changed_4; - linphone_core_add_listener(pauline->lc,v_table); - v_table = linphone_core_v_table_new(); - v_table->call_state_changed = call_state_changed_4; - linphone_core_add_listener(marie->lc,v_table); - + // We create a new LinphoneCoreCbs to listen only to the call state changes, in order to plug our RTP Transport Modifier when the call will be established + cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_state_changed_4); + linphone_core_add_callbacks(pauline->lc, cbs); + linphone_core_add_callbacks(marie->lc, cbs); + linphone_core_cbs_unref(cbs); if (recordTest) { // When we do the record test, we need a file player to play the content of a sound file /*make sure the record file doesn't already exists, otherwise this test will append new samples to it*/ diff --git a/tester/call_video_tester.c b/tester/call_video_tester.c index 7987d9ecf..cf55ad1f1 100644 --- a/tester/call_video_tester.c +++ b/tester/call_video_tester.c @@ -41,8 +41,8 @@ static void call_paused_resumed_with_video_base(bool_t sdp_200_ack bctbx_list_t *lcs = NULL; LinphoneVideoPolicy vpol; bool_t call_ok; - LinphoneCoreVTable *vtable = linphone_core_v_table_new(); - vtable->call_state_changed = call_paused_resumed_with_video_base_call_cb; + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_paused_resumed_with_video_base_call_cb); lcs = bctbx_list_append(lcs, pauline->lc); lcs = bctbx_list_append(lcs, marie->lc); @@ -114,7 +114,7 @@ static void call_paused_resumed_with_video_base(bool_t sdp_200_ack linphone_call_params_set_audio_direction(params,LinphoneMediaDirectionSendRecv); linphone_call_params_set_video_direction(params,LinphoneMediaDirectionSendRecv); if (with_call_accept) { - linphone_core_add_listener(marie->lc, vtable); + linphone_core_add_callbacks(marie->lc, cbs); } linphone_call_update(call_pauline,params); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneCallStreamsRunning,4)); @@ -137,6 +137,7 @@ static void call_paused_resumed_with_video_base(bool_t sdp_200_ack end_call(marie, pauline); end: + linphone_core_cbs_unref(cbs); linphone_core_manager_destroy(marie); linphone_core_manager_destroy(pauline); bctbx_list_free(lcs); @@ -163,7 +164,7 @@ static void zrtp_video_call(void) { } static void call_state_changed_callback_to_accept_video(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *message){ - LinphoneCoreVTable *vtable; + LinphoneCoreCbs *cbs; if (state == LinphoneCallUpdatedByRemote){ LinphoneCallParams *params = linphone_core_create_call_params(lc, call); linphone_call_params_enable_video(params, TRUE); @@ -171,9 +172,8 @@ static void call_state_changed_callback_to_accept_video(LinphoneCore *lc, Linpho linphone_call_params_unref(params); } ms_message("video acceptance listener about to be dropped"); - vtable = belle_sip_object_data_get(BELLE_SIP_OBJECT(call), - "call_state_changed_callback_to_accept_video"); - linphone_core_remove_listener(lc, vtable); + cbs = belle_sip_object_data_get(BELLE_SIP_OBJECT(call), "call_state_changed_callback_to_accept_video"); + linphone_core_remove_callbacks(lc, cbs); belle_sip_object_data_set(BELLE_SIP_OBJECT(call), "call_state_changed_callback_to_accept_video", NULL, NULL); } @@ -192,11 +192,11 @@ static LinphoneCall* _request_video(LinphoneCoreManager* caller,LinphoneCoreMana } if (accept_with_params) { - LinphoneCoreVTable *vtable = linphone_core_v_table_new(); - vtable->call_state_changed = call_state_changed_callback_to_accept_video; - linphone_core_add_listener(caller->lc, vtable); - belle_sip_object_data_set(BELLE_SIP_OBJECT(linphone_core_get_current_call(caller->lc)), "call_state_changed_callback_to_accept_video", - vtable, (void (*)(void*))linphone_core_v_table_destroy); + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_call_state_changed(cbs, call_state_changed_callback_to_accept_video); + linphone_core_add_callbacks(caller->lc, cbs); + belle_sip_object_data_set(BELLE_SIP_OBJECT(linphone_core_get_current_call(caller->lc)), + "call_state_changed_callback_to_accept_video", cbs, (void (*)(void*))linphone_core_cbs_unref); } linphone_core_enable_video_capture(callee->lc, TRUE); linphone_core_enable_video_display(callee->lc, TRUE); diff --git a/tester/liblinphone_tester.h b/tester/liblinphone_tester.h index f2b8009e4..c38e3d433 100644 --- a/tester/liblinphone_tester.h +++ b/tester/liblinphone_tester.h @@ -291,14 +291,14 @@ typedef struct _stats { typedef struct _LinphoneCoreManager { - LinphoneCoreVTable v_table; - LinphoneCore* lc; + LinphoneCoreCbs *cbs; + LinphoneCore *lc; stats stat; - LinphoneAddress* identity; + LinphoneAddress *identity; LinphoneEvent *lev; bool_t decline_subscribe; int number_of_bcunit_error_at_creation; - char* phone_alias; + char *phone_alias; char *rc_path; } LinphoneCoreManager; @@ -394,7 +394,7 @@ bool_t liblinphone_tester_clock_elapsed(const MSTimeSpec *start, int value_ms); void linphone_core_manager_check_accounts(LinphoneCoreManager *m); void account_manager_destroy(void); LinphoneAddress *account_manager_get_identity_with_modified_identity(const LinphoneAddress *modified_identity); -LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data); +LinphoneCore *configure_lc_from(LinphoneCoreCbs *cbs, const char *path, const char *file, void *user_data); void linphone_call_iframe_decoded_cb(LinphoneCall *call,void * user_data); void call_paused_resumed_base(bool_t multicast,bool_t with_losses); diff --git a/tester/message_tester.c b/tester/message_tester.c index 5929d8893..0730a7014 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -339,13 +339,14 @@ static void text_message_with_credential_from_auth_cb_auth_info_requested(Linpho static void text_message_with_credential_from_auth_callback(void) { LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); - LinphoneCoreVTable* vtable = linphone_core_v_table_new(); + LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get()); /*to force cb to be called*/ text_message_with_credential_from_auth_cb_auth_info=linphone_auth_info_clone((LinphoneAuthInfo*)(linphone_core_get_auth_info_list(pauline->lc)->data)); linphone_core_clear_all_auth_info(pauline->lc); - vtable->auth_info_requested=text_message_with_credential_from_auth_cb_auth_info_requested; - linphone_core_add_listener(pauline->lc, vtable); + linphone_core_cbs_set_auth_info_requested(cbs, text_message_with_credential_from_auth_cb_auth_info_requested); + linphone_core_add_callbacks(pauline->lc, cbs); + linphone_core_cbs_unref(cbs); text_message_base(marie, pauline); diff --git a/tester/tester.c b/tester/tester.c index f325acc93..8b4f503b1 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -125,28 +125,27 @@ void reset_counters( stats* counters) { memset(counters,0,sizeof(stats)); } -LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, const char* file, void* user_data) { - LinphoneCore* lc; - LpConfig* config = NULL; +LinphoneCore *configure_lc_from(LinphoneCoreCbs *cbs, const char *path, const char *file, void *user_data) { + LinphoneCore *lc; + LinphoneConfig *config = NULL; char *filepath = NULL; char *ringpath = NULL; char *ringbackpath = NULL; char *rootcapath = NULL; char *dnsuserhostspath = NULL; char *nowebcampath = NULL; - char *chatdb = NULL; - if (path==NULL) path="."; + if (!path) + path = "."; if (file){ - filepath = ms_strdup_printf("%s/%s", path, file); - if (ortp_file_exist(filepath) != 0) { + filepath = bctbx_strdup_printf("%s/%s", path, file); + if (bctbx_file_exist(filepath) != 0) { ms_fatal("Could not find file %s in path %s, did you configured resources directory correctly?", file, path); } - config = lp_config_new_with_factory(NULL,filepath); + config = lp_config_new_with_factory(NULL, filepath); } - // setup dynamic-path assets ringpath = ms_strdup_printf("%s/sounds/oldphone.wav",path); ringbackpath = ms_strdup_printf("%s/sounds/ringback.wav", path); @@ -154,20 +153,20 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, c rootcapath = ms_strdup_printf("%s/certificates/cn/cafile.pem", path); dnsuserhostspath = userhostsfile[0]=='/' ? ms_strdup(userhostsfile) : ms_strdup_printf("%s/%s", path, userhostsfile); - if (config) { lp_config_set_string(config, "sound", "remote_ring", ringbackpath); lp_config_set_string(config, "sound", "local_ring" , ringpath); lp_config_set_string(config, "sip", "root_ca" , rootcapath); lc = linphone_factory_create_core_with_config_3(linphone_factory_get(), config, NULL); } else { - lc = _linphone_core_new(v_table,NULL,(filepath!=NULL&&filepath[0]!='\0') ? filepath : NULL, user_data, FALSE); - + lc = linphone_factory_create_core_3(linphone_factory_get(), NULL, (filepath && (filepath[0] != '\0')) ? filepath : NULL, NULL); linphone_core_set_ring(lc, ringpath); linphone_core_set_ringback(lc, ringbackpath); linphone_core_set_root_ca(lc,rootcapath); } - chatdb = ms_strdup_printf("%s/messages-%p.db",bc_tester_get_writable_dir_prefix(),lc); + linphone_core_set_user_data(lc, user_data); + if (cbs) + linphone_core_add_callbacks(lc, cbs); linphone_core_enable_ipv6(lc, liblinphonetester_ipv6); linphone_core_set_sip_transport_timeout(lc, liblinphonetester_transport_timeout); @@ -178,19 +177,17 @@ LinphoneCore* configure_lc_from(LinphoneCoreVTable* v_table, const char* path, c linphone_core_set_static_picture(lc,nowebcampath); #endif - linphone_core_set_chat_database_path(lc, chatdb); - ms_free(ringpath); ms_free(ringbackpath); ms_free(nowebcampath); ms_free(rootcapath); ms_free(dnsuserhostspath); - remove(chatdb); - ms_free(chatdb); - if( filepath ) ms_free(filepath); + if (filepath) + bctbx_free(filepath); - if( config ) lp_config_unref(config); + if (config) + linphone_config_unref(config); return lc; } @@ -294,7 +291,7 @@ void linphone_core_manager_configure (LinphoneCoreManager *mgr) { LinphoneImNotifPolicy *im_notif_policy; char *hellopath = bc_tester_res("sounds/hello8000.wav"); - mgr->lc=configure_lc_from(&mgr->v_table, bc_tester_get_resource_dir_prefix(), mgr->rc_path, mgr); + mgr->lc = configure_lc_from(mgr->cbs, bc_tester_get_resource_dir_prefix(), mgr->rc_path, mgr); linphone_core_manager_check_accounts(mgr); im_notif_policy = linphone_core_get_im_notif_policy(mgr->lc); if (im_notif_policy != NULL) { @@ -354,25 +351,26 @@ void linphone_core_manager_configure (LinphoneCoreManager *mgr) { #endif void linphone_core_manager_init(LinphoneCoreManager *mgr, const char* rc_file, const char* phone_alias) { mgr->number_of_bcunit_error_at_creation = bc_get_number_of_failures(); - mgr->v_table.registration_state_changed=registration_state_changed; - mgr->v_table.auth_info_requested=auth_info_requested; - mgr->v_table.call_state_changed=call_state_changed; - mgr->v_table.text_received=text_message_received; - mgr->v_table.message_received=message_received; - mgr->v_table.is_composing_received=is_composing_received; - mgr->v_table.new_subscription_requested=new_subscription_requested; - mgr->v_table.notify_presence_received=notify_presence_received; - mgr->v_table.notify_presence_received_for_uri_or_tel=notify_presence_received_for_uri_or_tel; - mgr->v_table.transfer_state_changed=linphone_transfer_state_changed; - mgr->v_table.info_received=info_message_received; - mgr->v_table.subscription_state_changed=linphone_subscription_state_change; - mgr->v_table.notify_received=linphone_notify_received; - mgr->v_table.publish_state_changed=linphone_publish_state_changed; - mgr->v_table.configuring_status=linphone_configuration_status; - mgr->v_table.call_encryption_changed=linphone_call_encryption_changed; - mgr->v_table.network_reachable=network_reachable; - mgr->v_table.dtmf_received=dtmf_received; - mgr->v_table.call_stats_updated=call_stats_updated; + mgr->cbs = linphone_factory_create_core_cbs(linphone_factory_get()); + linphone_core_cbs_set_registration_state_changed(mgr->cbs, registration_state_changed); + linphone_core_cbs_set_auth_info_requested(mgr->cbs, auth_info_requested); + linphone_core_cbs_set_call_state_changed(mgr->cbs, call_state_changed); + //mgr->v_table.text_received=text_message_received; + linphone_core_cbs_set_message_received(mgr->cbs, message_received); + linphone_core_cbs_set_is_composing_received(mgr->cbs, is_composing_received); + linphone_core_cbs_set_new_subscription_requested(mgr->cbs, new_subscription_requested); + linphone_core_cbs_set_notify_presence_received(mgr->cbs, notify_presence_received); + linphone_core_cbs_set_notify_presence_received_for_uri_or_tel(mgr->cbs, notify_presence_received_for_uri_or_tel); + linphone_core_cbs_set_transfer_state_changed(mgr->cbs, linphone_transfer_state_changed); + linphone_core_cbs_set_info_received(mgr->cbs, info_message_received); + linphone_core_cbs_set_subscription_state_changed(mgr->cbs, linphone_subscription_state_change); + linphone_core_cbs_set_notify_received(mgr->cbs, linphone_notify_received); + linphone_core_cbs_set_publish_state_changed(mgr->cbs, linphone_publish_state_changed); + linphone_core_cbs_set_configuring_status(mgr->cbs, linphone_configuration_status); + linphone_core_cbs_set_call_encryption_changed(mgr->cbs, linphone_call_encryption_changed); + linphone_core_cbs_set_network_reachable(mgr->cbs, network_reachable); + linphone_core_cbs_set_dtmf_received(mgr->cbs, dtmf_received); + linphone_core_cbs_set_call_stats_updated(mgr->cbs, call_stats_updated); mgr->phone_alias = phone_alias ? ms_strdup(phone_alias) : NULL; @@ -493,6 +491,8 @@ void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { } if (mgr->rc_path) bctbx_free(mgr->rc_path); + if (mgr->cbs) + linphone_core_cbs_unref(mgr->cbs); manager_count--; linphone_core_set_log_level(old_log_level);