diff --git a/src/engine/agent/Agent_Impl.cpp b/src/engine/agent/Agent_Impl.cpp index 4207c9f6..98e1b474 100644 --- a/src/engine/agent/Agent_Impl.cpp +++ b/src/engine/agent/Agent_Impl.cpp @@ -629,18 +629,16 @@ void AgentImpl::processAddRootCert(JsonCpp::Value& request, JsonCpp::Value& answ std::string pem = request["cert"].asString(); std::string::size_type pb = 0, pe = 0; + while (pb != std::string::npos && pe != std::string::npos) { + pb = pem.find(BeginCertificate, pb); + pe = pem.find(EndCertificate, pe); - for(pb = pem.find(BeginCertificate, pb), pe = pem.find(EndCertificate, pe); - pb != std::string::npos && pe != std::string::npos; - pb = pem.find(BeginCertificate, pb + BeginCertificate.size()), pe = pem.find(EndCertificate, pe + EndCertificate.size())) - { - // Get single certificate - std::string cert = pem.substr(pb, pe + EndCertificate.size()); - //int size = cert.size(); - addRootCert(ByteBuffer(cert.c_str(), cert.size())); + if (pb != std::string::npos && pe != std::string::npos && pe > pb) { + std::string cert = pem.substr(pb, pe - pb + EndCertificate.size()); + addRootCert(ByteBuffer(cert.c_str(), cert.size())); - // Delete processed part - pem.erase(0, pe + EndCertificate.size()); + pb = ++pe; + } } answer["status"] = Status_Ok; diff --git a/src/engine/audio/CMakeLists.txt b/src/engine/audio/CMakeLists.txt index 0f4e6f54..2eb2e050 100644 --- a/src/engine/audio/CMakeLists.txt +++ b/src/engine/audio/CMakeLists.txt @@ -8,18 +8,31 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set (AUDIOLIB_SOURCES Audio_Resampler.cpp + Audio_Resampler.h Audio_Quality.cpp + Audio_Quality.h Audio_Mixer.cpp + Audio_Mixer.h Audio_Interface.cpp + Audio_Interface.h Audio_Helper.cpp + Audio_Helper.h Audio_DataWindow.cpp + Audio_DataWindow.h Audio_DevicePair.cpp + Audio_DevicePair.h Audio_Player.cpp + Audio_Player.h Audio_Null.cpp + Audio_Null.h Audio_CoreAudio.cpp + Audio_CoreAudio.h Audio_DirectSound.cpp - Audio_Android.cpp + Audio_DirectSound.h + Audio_AndroidOboe.cpp + Audio_AndroidOboe.h Audio_WavFile.cpp + Audio_WavFile.h ) add_library(audio_lib ${AUDIOLIB_SOURCES}) diff --git a/src/engine/endpoint/EP_Engine.cpp b/src/engine/endpoint/EP_Engine.cpp index 8ccb3c27..192d7132 100644 --- a/src/engine/endpoint/EP_Engine.cpp +++ b/src/engine/endpoint/EP_Engine.cpp @@ -44,6 +44,60 @@ typedef resip::SdpContents::Session::Medium Medium; typedef resip::SdpContents::Session::MediumContainer MediumContainer; +class TransportLogger: public resip::Transport::SipMessageLoggingHandler +{ +public: + void outboundMessage(const resip::Tuple &source, const resip::Tuple &destination, const resip::SipMessage &msg) override + { + std::ostringstream dest_buffer; dest_buffer << destination; + std::ostringstream msg_buffer; msg_buffer << msg; + std::string msg_text = msg_buffer.str(); +#if defined(TARGET_ANDROID) + if (msg_text.size() > 512) + { + ICELogDebug(<< "Sent to " << dest_buffer.str() << " :"); + msg_text = strx::prefixLines(msg_text, "<---"); + + auto lines = strx::split(msg_text); + for (const auto& l: lines) + ICELogDebug(<< l); + } + else + ICELogDebug(<< "Sent to " << dest_buffer.str() << "\n" << strx::prefixLines(msg_text, "<---")); +#else + ICELogDebug(<< "Sent to " << dest_buffer.str() << "\n" << strx::prefixLines(msg_text, "<---")); +#endif + } + + // Note: retransmissions store already encoded messages, so callback doesn't send SipMessage it sends + // the encoded version of the SipMessage instead. If you need a SipMessage you will need to + // re-parse back into a SipMessage in the callback handler. + void outboundRetransmit(const resip::Tuple &source, const resip::Tuple &destination, const resip::SendData &data) override + {} + + void inboundMessage(const resip::Tuple& source, const resip::Tuple& destination, const resip::SipMessage &msg) override + { + std::ostringstream source_buffer; source_buffer << source; + std::ostringstream msg_buffer; msg_buffer << msg; + std::string msg_text = msg_buffer.str(); +#if defined(TARGET_ANDROID) + if (msg_text.size() > 512) + { + ICELogDebug(<< "Received from " << source_buffer.str() << " :"); + msg_text = strx::prefixLines(msg_text, "--->"); + auto lines = strx::split(msg_text); + for (const auto& l: lines) + ICELogDebug(<< l); + } + else + ICELogDebug(<< "Received from " << source_buffer.str() << "\n" << strx::prefixLines(msg_text, "<---")); +#else + ICELogDebug(<< "Received from " << source_buffer.str() << "\n" << strx::prefixLines(msg_buffer.str(), "--->")); +#endif + } + +}; + //-------------- UserAgent ----------------------- UserAgent::UserAgent() { @@ -93,7 +147,7 @@ void UserAgent::start() } // Initialize resip loggег - resip::Log::initialize(resip::Log::OnlyExternal, resip::Log::Debug, "Client", *this); + resip::Log::initialize(resip::Log::OnlyExternal, resip::Log::Info, "Client", *this); // Build list of nameservers if specified resip::DnsStub::NameserverList nslist; @@ -142,6 +196,8 @@ void UserAgent::start() } } + mStack->setTransportSipMessageLoggingHandler(std::make_shared()); + // Add transports mTransportList.clear(); resip::InternalTransport* t; @@ -262,16 +318,16 @@ void UserAgent::shutdown() { LOCK; - for (auto observerIter: mClientObserverMap) + for (auto& observerIter: mClientObserverMap) observerIter.second->stop(); - for (auto observerIter: mServerObserverMap) + for (auto& observerIter: mServerObserverMap) observerIter.second->stop(); - for (auto sessionIter: mSessionMap) + for (auto& sessionIter: mSessionMap) sessionIter.second->stop(); - for (auto accountIter: mAccountSet) + for (auto& accountIter: mAccountSet) accountIter->stop(); } } @@ -279,24 +335,24 @@ void UserAgent::shutdown() bool UserAgent::active() { LOCK; - return mStack != NULL; + return mStack != nullptr; } void UserAgent::refresh() { LOCK; - for (auto acc: mAccountSet) + for (auto& acc: mAccountSet) acc->refresh(); - for (auto observer: mClientObserverMap) + for (auto& observer: mClientObserverMap) observer.second->refresh(); } void UserAgent::onDumCanBeDeleted() { - delete mDum; mDum = NULL; - delete mStack; mStack = NULL; + delete mDum; mDum = nullptr; + delete mStack; mStack = nullptr; mClientObserverMap.clear(); mServerObserverMap.clear(); @@ -382,15 +438,14 @@ void UserAgent::process() // Find all sessions std::set idSet; - SessionMap::iterator sessionIter; - for (sessionIter = mSessionMap.begin(); sessionIter != mSessionMap.end(); ++sessionIter) + for (auto sessionIter = mSessionMap.begin(); sessionIter != mSessionMap.end(); ++sessionIter) idSet.insert(sessionIter->first); // Now process session one by one checking if current is available yet std::set::iterator resipIter; for (resipIter = idSet.begin(); resipIter != idSet.end(); ++resipIter) { - SessionMap::iterator sessionIter = mSessionMap.find(*resipIter); + auto sessionIter = mSessionMap.find(*resipIter); if (sessionIter == mSessionMap.end()) continue; @@ -432,7 +487,12 @@ void UserAgent::addRootCert(const ByteBuffer& data) { LOCK; resip::Data b(data.data(), data.size()); - mStack->getSecurity()->addRootCertPEM(b); + try { + mStack->getSecurity()->addRootCertPEM(b); + } + catch(...) { + // Ignore silently + } } PAccount UserAgent::createAccount(PVariantMap config) @@ -467,7 +527,7 @@ PSession UserAgent::createSession(PAccount account) return session; } -std::string UserAgent::formatSipAddress(std::string sip) +std::string UserAgent::formatSipAddress(const std::string& sip) { std::string result; if (sip.size()) @@ -483,17 +543,18 @@ std::string UserAgent::formatSipAddress(std::string sip) return result; } -bool UserAgent::isSipAddressValid(std::string sip) +bool UserAgent::isSipAddressValid(const std::string& sip) { bool result = false; try { - if (sip.find('<') == std::string::npos) - sip = "<" + sip; - if (sip.find('>') == std::string::npos) - sip += ">"; + std::string s = sip; + if (s.find('<') == std::string::npos) + s = "<" + s; + if (s.find('>') == std::string::npos) + s += ">"; - resip::Data d(formatSipAddress(sip)); + resip::Data d(formatSipAddress(s)); resip::Uri uri(d); result = uri.isWellFormed(); if (result) @@ -543,7 +604,7 @@ UserAgent::SipAddress UserAgent::parseSipAddress(const std::string& sip) return result; } -bool UserAgent::compareSipAddresses(std::string sip1, std::string sip2) +bool UserAgent::compareSipAddresses(const std::string& sip1, const std::string& sip2) { if (sip1.empty() || sip2.empty()) return false; diff --git a/src/engine/endpoint/EP_Engine.h b/src/engine/endpoint/EP_Engine.h index 39eefe20..ea2c059b 100644 --- a/src/engine/endpoint/EP_Engine.h +++ b/src/engine/endpoint/EP_Engine.h @@ -162,9 +162,9 @@ class UserAgent: public resip::ClientRegistrationHandler, friend class WatcherQueue; public: /* Compares two sip addresses. Returns true if they represent the same entity - user and domain are the same. Otherwise returns false. */ - static bool compareSipAddresses(std::string sip1, std::string sip2); - static std::string formatSipAddress(std::string sip); - static bool isSipAddressValid(std::string sip); + static bool compareSipAddresses(const std::string& sip1, const std::string& sip2); + static std::string formatSipAddress(const std::string& sip); + static bool isSipAddressValid(const std::string& sip); struct SipAddress { bool mValid; diff --git a/src/libs/ice/CMakeLists.txt b/src/libs/ice/CMakeLists.txt index 4e117d56..ab300b7a 100644 --- a/src/libs/ice/CMakeLists.txt +++ b/src/libs/ice/CMakeLists.txt @@ -34,9 +34,10 @@ set (ICE_STACK_SOURCES ICEAddress.cpp ICETime.cpp ICETransactionList.cpp) -if (ANDROID_ABI) - set (ICE_STACK_SOURCES ${ICE_STACK_SOURCES} android-ifaddrs/android-ifaddrs.h android-ifaddrs/android-ifaddrs.c) -endif() + +#if (ANDROID_ABI) +# set (ICE_STACK_SOURCES ${ICE_STACK_SOURCES} android-ifaddrs/android-ifaddrs.h android-ifaddrs/android-ifaddrs.c) +#endif() if (TARGET_MUSL) add_definitions(-DTARGET_MUSL) diff --git a/src/libs/ice/ICENetworkHelper.cpp b/src/libs/ice/ICENetworkHelper.cpp index e740b5a7..3a4a0ac1 100644 --- a/src/libs/ice/ICENetworkHelper.cpp +++ b/src/libs/ice/ICENetworkHelper.cpp @@ -26,7 +26,7 @@ # include # if defined(TARGET_ANDROID) # if __ANDROID_API__ < 24 -# include "android-ifaddrs/android-ifaddrs.h" +# error not supported for ANDROID_API < 24 # else # include # endif @@ -161,6 +161,7 @@ void NetworkHelper::reload(int networkType) fillUwpInterfaceList(AF_INET, networkType, mIPList); fillUwpInterfaceList(AF_INET6, networkType, mIPList); #else + // https://github.com/golang/go/issues/40569 struct ifaddrs* il = NULL; if (getifaddrs(&il)) throw Exception(GETIFADDRS_FAILED, errno);