diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 8994f21f007645d94e56e65ed58973bbf91c7f54..5b4daf329894e44def973da12e44bad6924fcc3b 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -53,9 +53,7 @@ namespace ring { std::mutex IAXVoIPLink::mutexIAX = {}; IAXVoIPLink::IAXVoIPLink(IAXAccount& account) : account_(account), resampler_(new Resampler{44100}) -{ - srand(time(NULL)); // to get random number for RANDOM_PORT -} +{} IAXVoIPLink::~IAXVoIPLink() { diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index c9d01821955678bfb31e0d3df23b28bbaf4d73bd..fdfe7aa34f8ff01eb8c40e639d1c36acac1d6a6f 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -124,6 +124,32 @@ restore_backup(const std::string &path) copy_over(backup_path, path); } +/** + * Set pjsip's log level based on the SIPLOGLEVEL environment variable. + * SIPLOGLEVEL = 0 minimum logging + * SIPLOGLEVEL = 6 maximum logging + */ + +/** Environment variable used to set pjsip's logging level */ +static constexpr const char* SIPLOGLEVEL = "SIPLOGLEVEL"; + +static void +setSipLogLevel() +{ + char* envvar = getenv(SIPLOGLEVEL); + int level = 0; + + if (envvar != nullptr) { + if (not (std::istringstream(envvar) >> level)) + level = 0; + + // From 0 (min) to 6 (max) + level = std::max(0, std::min(level, 6)); + } + + pj_log_set_level(level); +} + void ManagerImpl::loadDefaultAccountMap() { @@ -184,13 +210,18 @@ ManagerImpl::init(const std::string &config_file) throw std::runtime_error(#ret " failed"); \ } while (0) - // Our PJSIP dependency (SIP and ICE) + srand(time(NULL)); // to get random number for RANDOM_PORT + + // Initialize PJSIP (SIP and ICE implementation) TRY(pj_init()); + setSipLogLevel(); TRY(pjlib_util_init()); TRY(pjnath_init()); - #undef TRY + RING_DBG("pjsip version %s for %s initialized", + pj_get_version(), PJ_OS_NAME); + ice_tf_.reset(new IceTransportFactory()); path_ = config_file.empty() ? retrieveConfigPath() : config_file; diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index 81236e3fb2ecf6bc249adbec0696ff097080ba47..c544b930ebd5e9cfc75f787db3751056c10914e4 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -85,9 +85,6 @@ namespace ring { -/** Environment variable used to set pjsip's logging level */ -#define SIPLOGLEVEL "SIPLOGLEVEL" - /**************** EXTERN VARIABLES AND FUNCTIONS (callbacks) **************************/ /** @@ -488,18 +485,8 @@ SIPVoIPLink::SIPVoIPLink() throw VoipLinkException(#ret " failed"); \ } while (0) - srand(time(NULL)); // to get random number for RANDOM_PORT - - TRY(pj_init()); - - TRY(pjlib_util_init()); - - setSipLogLevel(); - TRY(pjnath_init()); - pj_caching_pool_init(cp_, &pj_pool_factory_default_policy, 0); pool_ = pj_pool_create(&cp_->factory, PACKAGE, 4096, 4096, nullptr); - if (!pool_) throw VoipLinkException("UserAgent: Could not initialize memory pool"); @@ -575,8 +562,6 @@ SIPVoIPLink::SIPVoIPLink() static const pj_str_t accepted = CONST_PJ_STR("application/sdp"); pjsip_endpt_add_capability(endpt_, &mod_ua_, PJSIP_H_ACCEPT, nullptr, 1, &accepted); - RING_DBG("pjsip version %s for %s initialized", pj_get_version(), PJ_OS_NAME); - TRY(pjsip_replaces_init_module(endpt_)); #undef TRY @@ -612,8 +597,6 @@ SIPVoIPLink::~SIPVoIPLink() pjsip_endpt_destroy(endpt_); pj_pool_release(pool_); pj_caching_pool_destroy(cp_); - - pj_shutdown(); } std::shared_ptr<SIPAccountBase> @@ -662,24 +645,6 @@ SIPVoIPLink::guessAccount(const std::string& userName, return result; } -void SIPVoIPLink::setSipLogLevel() -{ - char *envvar = getenv(SIPLOGLEVEL); - int level = 0; - - if (envvar != NULL) { - std::string loglevel = envvar; - - if (!(std::istringstream(loglevel) >> level)) level = 0; - - level = level > 6 ? 6 : level; - level = level < 0 ? 0 : level; - } - - // From 0 (min) to 6 (max) - pj_log_set_level(level); -} - // Called from EventThread::run (not main thread) void SIPVoIPLink::handleEvents() diff --git a/daemon/src/sip/sipvoiplink.h b/daemon/src/sip/sipvoiplink.h index 772b1d95a1390d70b1465e77cb293b1e8285ff40..80556d5a8448355c2d4e1df7be52e1a3ae76caf9 100644 --- a/daemon/src/sip/sipvoiplink.h +++ b/daemon/src/sip/sipvoiplink.h @@ -79,13 +79,6 @@ extern decltype(getGlobalInstance<SIPVoIPLink>)& getSIPVoIPLink; class SIPVoIPLink { public: - /** - * Set pjsip's log level based on the SIPLOGLEVEL environment variable. - * SIPLOGLEVEL = 0 minimum logging - * SIPLOGLEVEL = 6 maximum logging - */ - static void setSipLogLevel(); - #ifdef __ANDROID__ static void setSipLogger(); #endif