From 552be2a6394ee6c13ca31954f65f11c38b1dad6d Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 23 Aug 2017 09:21:14 +0200 Subject: [PATCH] small rework of trace level management. --- coreapi/bellesip_sal/sal_impl.c | 52 +++++++++----------------- coreapi/help/examples/C/CMakeLists.txt | 2 +- coreapi/linphonecore.c | 18 ++++----- daemon/CMakeLists.txt | 2 +- include/linphone/core.h | 8 ++++ include/sal/sal.h | 2 + tester/accountmanager.c | 2 +- tester/liblinphone_tester.c | 3 +- tester/register_tester.c | 5 +++ tester/tester.c | 2 +- tools/CMakeLists.txt | 4 +- 11 files changed, 48 insertions(+), 52 deletions(-) diff --git a/coreapi/bellesip_sal/sal_impl.c b/coreapi/bellesip_sal/sal_impl.c index c6803481b..4aa2c1fb8 100644 --- a/coreapi/bellesip_sal/sal_impl.c +++ b/coreapi/bellesip_sal/sal_impl.c @@ -59,31 +59,6 @@ void sal_op_set_privacy_from_message(SalOp* op,belle_sip_message_t* msg) { } static void set_tls_properties(Sal *ctx); -void _belle_sip_log(const char *domain, belle_sip_log_level lev, const char *fmt, va_list args) { - OrtpLogLevel ortp_level; - switch(lev) { - case BELLE_SIP_LOG_FATAL: - ortp_level=ORTP_FATAL; - break; - case BELLE_SIP_LOG_ERROR: - ortp_level=ORTP_ERROR; - break; - case BELLE_SIP_LOG_WARNING: - ortp_level=ORTP_WARNING; - break; - case BELLE_SIP_LOG_MESSAGE: - ortp_level=ORTP_MESSAGE; - break; - case BELLE_SIP_LOG_DEBUG: - default: - ortp_level=ORTP_DEBUG; - break; - } - if (ortp_log_level_enabled("belle-sip", ortp_level)){ - ortp_logv("belle-sip", ortp_level,fmt,args); - } -} - void sal_enable_log(){ sal_set_log_level(ORTP_MESSAGE); } @@ -93,24 +68,31 @@ void sal_disable_log() { } void sal_set_log_level(OrtpLogLevel level) { - belle_sip_log_level belle_sip_level; + belle_sip_log_level belle_sip_level = BELLE_SIP_LOG_MESSAGE; if ((level&ORTP_FATAL) != 0) { belle_sip_level = BELLE_SIP_LOG_FATAL; - } else if ((level&ORTP_ERROR) != 0) { + } + if ((level&ORTP_ERROR) != 0) { belle_sip_level = BELLE_SIP_LOG_ERROR; - } else if ((level&ORTP_WARNING) != 0) { + } + if ((level&ORTP_WARNING) != 0) { belle_sip_level = BELLE_SIP_LOG_WARNING; - } else if ((level&ORTP_MESSAGE) != 0) { - belle_sip_level = BELLE_SIP_LOG_MESSAGE; - } else if (((level&ORTP_DEBUG) != 0) || ((level&ORTP_TRACE) != 0)) { - belle_sip_level = BELLE_SIP_LOG_DEBUG; - } else { - //well, this should never occurs but... + } + if ((level&ORTP_MESSAGE) != 0) { belle_sip_level = BELLE_SIP_LOG_MESSAGE; } + if (((level&ORTP_DEBUG) != 0) || ((level&ORTP_TRACE) != 0)) { + belle_sip_level = BELLE_SIP_LOG_DEBUG; + } + belle_sip_set_log_level(belle_sip_level); } +static BctbxLogFunc _belle_sip_log_handler = bctbx_logv_out; +void sal_set_log_handler(BctbxLogFunc log_handler) { + _belle_sip_log_handler = log_handler; + belle_sip_set_log_handler(log_handler); +} void sal_add_pending_auth(Sal *sal, SalOp *op){ if (bctbx_list_find(sal->pending_auths,op)==NULL){ sal->pending_auths=bctbx_list_append(sal->pending_auths,op); @@ -505,7 +487,7 @@ Sal * sal_init(MSFactory *factory){ sal->auto_contacts=TRUE; sal->factory = factory; /*first create the stack, which initializes the belle-sip object's pool for this thread*/ - belle_sip_set_log_handler(_belle_sip_log); + belle_sip_set_log_handler(_belle_sip_log_handler); //printf by default sal->stack = belle_sip_stack_new(NULL); sal->user_agent=belle_sip_header_user_agent_new(); diff --git a/coreapi/help/examples/C/CMakeLists.txt b/coreapi/help/examples/C/CMakeLists.txt index af59a648a..84a5b38d5 100644 --- a/coreapi/help/examples/C/CMakeLists.txt +++ b/coreapi/help/examples/C/CMakeLists.txt @@ -29,7 +29,7 @@ if (ENABLE_TOOLS) string(REPLACE ".c" "" EXECUTABLE_NAME ${EXECUTABLE}) bc_apply_compile_flags(${EXECUTABLE} STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(${EXECUTABLE_NAME} ${USE_BUNDLE} ${EXECUTABLE}) - target_link_libraries(${EXECUTABLE_NAME} ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES}) + target_link_libraries(${EXECUTABLE_NAME} ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") if (NOT IOS) install(TARGETS ${EXECUTABLE_NAME} diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 28972673c..bf99af464 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -468,7 +468,9 @@ void linphone_core_set_log_handler(OrtpLogFunc logfunc) { void linphone_core_set_log_file(FILE *file) { if (file == NULL) file = stdout; - ortp_set_log_file(file); + bctbx_set_log_file(file); /*gather everythings*/ + sal_set_log_handler(NULL); /*disable default log handler*/ + ortp_set_log_handler(NULL); /*disable default log handler*/ } void linphone_core_set_log_level(OrtpLogLevel loglevel) { @@ -497,15 +499,13 @@ void linphone_core_set_log_level(OrtpLogLevel loglevel) { } void linphone_core_set_log_level_mask(unsigned int loglevel) { - ortp_set_log_level_mask(NULL, loglevel); - bctbx_set_log_level_mask(NULL, loglevel); - if (loglevel == 0) { - sal_disable_log(); - } else { - sal_enable_log(); - } + //we only have 2 domain for now ortp and belle-sip + bctbx_set_log_level_mask(ORTP_LOG_DOMAIN, loglevel); + sal_set_log_level((OrtpLogLevel)loglevel); +} +unsigned int linphone_core_get_log_level_mask(void) { + return bctbx_get_log_level_mask(ORTP_LOG_DOMAIN); } - static int _open_log_collection_file_with_idx(int idx) { struct stat statbuf; char *log_filename; diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index 1975363c2..61178d119 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt @@ -119,7 +119,7 @@ target_link_libraries(linphone-daemon ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER set_target_properties(linphone-daemon PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") add_executable(linphone-daemon-pipetest ${DAEMON_PIPETEST_SOURCE_FILES}) -target_link_libraries(linphone-daemon-pipetest ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES}) +target_link_libraries(linphone-daemon-pipetest ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(linphone-daemon-pipetest PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(INSTALL_TARGETS linphone-daemon linphone-daemon-pipetest) diff --git a/include/linphone/core.h b/include/linphone/core.h index 6fc0bb029..01483b3c9 100644 --- a/include/linphone/core.h +++ b/include/linphone/core.h @@ -803,6 +803,14 @@ LINPHONE_PUBLIC void linphone_core_set_log_level(OrtpLogLevel loglevel); */ LINPHONE_PUBLIC void linphone_core_set_log_level_mask(unsigned int loglevel); +/** + * Get defined log level mask. + * + * @return The loglevel parameter is a bitmask parameter. Therefore to enable only warning and error + * messages, use ORTP_WARNING | ORTP_ERROR. To disable logs, simply set loglevel to 0. + */ +LINPHONE_PUBLIC unsigned int linphone_core_get_log_level_mask(void); + /** * Enable logs in supplied FILE*. * @param file a C FILE* where to fprintf logs. If null stdout is used. diff --git a/include/sal/sal.h b/include/sal/sal.h index f41c09336..1cabcb5fa 100644 --- a/include/sal/sal.h +++ b/include/sal/sal.h @@ -148,6 +148,8 @@ const char *sal_address_get_header(const SalAddress *addr, const char *name); LINPHONE_PUBLIC Sal * sal_init(MSFactory *factory); LINPHONE_PUBLIC void sal_uninit(Sal* sal); + +void sal_set_log_handler(BctbxLogFunc log_handler); void sal_set_user_pointer(Sal *sal, void *user_data); void *sal_get_user_pointer(const Sal *sal); diff --git a/tester/accountmanager.c b/tester/accountmanager.c index 385717ed2..26ebd3f75 100644 --- a/tester/accountmanager.c +++ b/tester/accountmanager.c @@ -259,7 +259,7 @@ static LinphoneAddress *account_manager_check_account(AccountManager *m, Linphon void linphone_core_manager_check_accounts(LinphoneCoreManager *m){ const bctbx_list_t *it; AccountManager *am=account_manager_get(); - int logmask = ortp_get_log_level_mask(NULL); + int logmask = linphone_core_get_log_level_mask(); if (!liblinphonetester_show_account_manager_logs) linphone_core_set_log_level_mask(ORTP_ERROR|ORTP_FATAL); for(it=linphone_core_get_proxy_config_list(m->lc);it!=NULL;it=it->next){ diff --git a/tester/liblinphone_tester.c b/tester/liblinphone_tester.c index 3626150a4..4857b5855 100644 --- a/tester/liblinphone_tester.c +++ b/tester/liblinphone_tester.c @@ -195,8 +195,7 @@ int liblinphone_tester_set_log_file(const char *filename) { return -1; } ms_message("Redirecting traces to file [%s]", filename); - bctbx_set_log_file(log_file); - ortp_set_log_file(log_file); + linphone_core_set_log_file(log_file); return 0; } diff --git a/tester/register_tester.c b/tester/register_tester.c index 6989c8b1c..c8f899b2e 100644 --- a/tester/register_tester.c +++ b/tester/register_tester.c @@ -684,6 +684,11 @@ static void proxy_transport_change(void){ linphone_core_manager_destroy(lcm); } +/* + * On ios, some firewal require to disable flow label (livebox with default firewall level). + * sudo sysctl net.inet6.ip6.auto_flowlabel=0 + * It might be possible to found a sockopt for such purpose. + */ static void proxy_transport_change_with_wrong_port(void) { LinphoneCoreManager* lcm = create_lcm(); stats* counters = &lcm->stat; diff --git a/tester/tester.c b/tester/tester.c index 9e4f2c10e..996c99f81 100644 --- a/tester/tester.c +++ b/tester/tester.c @@ -461,7 +461,7 @@ void linphone_core_manager_stop(LinphoneCoreManager *mgr){ } void linphone_core_manager_uninit(LinphoneCoreManager *mgr) { - int old_log_level = ortp_get_log_level_mask(NULL); + int old_log_level = linphone_core_get_log_level_mask(); linphone_core_set_log_level(ORTP_ERROR); if (mgr->phone_alias) { ms_free(mgr->phone_alias); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index f26b5491f..fdc797c02 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -33,7 +33,7 @@ endif() set(LP_AUTO_ANSWER_SOURCE_FILES auto_answer.c) bc_apply_compile_flags(LP_AUTO_ANSWER_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(lp-auto-answer ${USE_BUNDLE} ${LP_AUTO_ANSWER_SOURCE_FILES}) -target_link_libraries(lp-auto-answer ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_LIBRARIES}) +target_link_libraries(lp-auto-answer ${LINPHONE_LIBS_FOR_TOOLS} ${MEDIASTREAMER2_LIBRARIES} ${ORTP_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(lp-auto-answer PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(LP_SENDMSG_SOURCE_FILES lpsendmsg.c) @@ -57,7 +57,7 @@ set_target_properties(xml2lpc_test PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") set(LP_TEST_ECC_SOURCE_FILES test_ecc.c) bc_apply_compile_flags(LP_TEST_ECC_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_C) add_executable(lp-test-ecc ${USE_BUNDLE} ${LP_TEST_ECC_SOURCE_FILES}) -target_link_libraries(lp-test-ecc ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${MEDIASTREAMER2_LIBRARIES}) +target_link_libraries(lp-test-ecc ${LINPHONE_LIBS_FOR_TOOLS} ${ORTP_LIBRARIES} ${MEDIASTREAMER2_LIBRARIES} ${BCTOOLBOX_CORE_LIBRARIES}) set_target_properties(lp-test-ecc PROPERTIES LINK_FLAGS "${LINPHONE_LDFLAGS}") if (NOT IOS)