- fixes for Android build mostly

This commit is contained in:
Dmytro Bogovych 2023-05-22 11:01:44 +03:00
parent 65e27eec0b
commit 7653fcf138
6 changed files with 114 additions and 40 deletions

View File

@ -629,18 +629,16 @@ void AgentImpl::processAddRootCert(JsonCpp::Value& request, JsonCpp::Value& answ
std::string pem = request["cert"].asString(); std::string pem = request["cert"].asString();
std::string::size_type pb = 0, pe = 0; 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); if (pb != std::string::npos && pe != std::string::npos && pe > pb) {
pb != std::string::npos && pe != std::string::npos; std::string cert = pem.substr(pb, pe - pb + EndCertificate.size());
pb = pem.find(BeginCertificate, pb + BeginCertificate.size()), pe = pem.find(EndCertificate, pe + EndCertificate.size())) addRootCert(ByteBuffer(cert.c_str(), cert.size()));
{
// Get single certificate
std::string cert = pem.substr(pb, pe + EndCertificate.size());
//int size = cert.size();
addRootCert(ByteBuffer(cert.c_str(), cert.size()));
// Delete processed part pb = ++pe;
pem.erase(0, pe + EndCertificate.size()); }
} }
answer["status"] = Status_Ok; answer["status"] = Status_Ok;

View File

@ -8,18 +8,31 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set (AUDIOLIB_SOURCES set (AUDIOLIB_SOURCES
Audio_Resampler.cpp Audio_Resampler.cpp
Audio_Resampler.h
Audio_Quality.cpp Audio_Quality.cpp
Audio_Quality.h
Audio_Mixer.cpp Audio_Mixer.cpp
Audio_Mixer.h
Audio_Interface.cpp Audio_Interface.cpp
Audio_Interface.h
Audio_Helper.cpp Audio_Helper.cpp
Audio_Helper.h
Audio_DataWindow.cpp Audio_DataWindow.cpp
Audio_DataWindow.h
Audio_DevicePair.cpp Audio_DevicePair.cpp
Audio_DevicePair.h
Audio_Player.cpp Audio_Player.cpp
Audio_Player.h
Audio_Null.cpp Audio_Null.cpp
Audio_Null.h
Audio_CoreAudio.cpp Audio_CoreAudio.cpp
Audio_CoreAudio.h
Audio_DirectSound.cpp Audio_DirectSound.cpp
Audio_Android.cpp Audio_DirectSound.h
Audio_AndroidOboe.cpp
Audio_AndroidOboe.h
Audio_WavFile.cpp Audio_WavFile.cpp
Audio_WavFile.h
) )
add_library(audio_lib ${AUDIOLIB_SOURCES}) add_library(audio_lib ${AUDIOLIB_SOURCES})

View File

@ -44,6 +44,60 @@
typedef resip::SdpContents::Session::Medium Medium; typedef resip::SdpContents::Session::Medium Medium;
typedef resip::SdpContents::Session::MediumContainer MediumContainer; 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::UserAgent() UserAgent::UserAgent()
{ {
@ -93,7 +147,7 @@ void UserAgent::start()
} }
// Initialize resip loggег // 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 // Build list of nameservers if specified
resip::DnsStub::NameserverList nslist; resip::DnsStub::NameserverList nslist;
@ -142,6 +196,8 @@ void UserAgent::start()
} }
} }
mStack->setTransportSipMessageLoggingHandler(std::make_shared<TransportLogger>());
// Add transports // Add transports
mTransportList.clear(); mTransportList.clear();
resip::InternalTransport* t; resip::InternalTransport* t;
@ -262,16 +318,16 @@ void UserAgent::shutdown()
{ {
LOCK; LOCK;
for (auto observerIter: mClientObserverMap) for (auto& observerIter: mClientObserverMap)
observerIter.second->stop(); observerIter.second->stop();
for (auto observerIter: mServerObserverMap) for (auto& observerIter: mServerObserverMap)
observerIter.second->stop(); observerIter.second->stop();
for (auto sessionIter: mSessionMap) for (auto& sessionIter: mSessionMap)
sessionIter.second->stop(); sessionIter.second->stop();
for (auto accountIter: mAccountSet) for (auto& accountIter: mAccountSet)
accountIter->stop(); accountIter->stop();
} }
} }
@ -279,24 +335,24 @@ void UserAgent::shutdown()
bool UserAgent::active() bool UserAgent::active()
{ {
LOCK; LOCK;
return mStack != NULL; return mStack != nullptr;
} }
void UserAgent::refresh() void UserAgent::refresh()
{ {
LOCK; LOCK;
for (auto acc: mAccountSet) for (auto& acc: mAccountSet)
acc->refresh(); acc->refresh();
for (auto observer: mClientObserverMap) for (auto& observer: mClientObserverMap)
observer.second->refresh(); observer.second->refresh();
} }
void UserAgent::onDumCanBeDeleted() void UserAgent::onDumCanBeDeleted()
{ {
delete mDum; mDum = NULL; delete mDum; mDum = nullptr;
delete mStack; mStack = NULL; delete mStack; mStack = nullptr;
mClientObserverMap.clear(); mClientObserverMap.clear();
mServerObserverMap.clear(); mServerObserverMap.clear();
@ -382,15 +438,14 @@ void UserAgent::process()
// Find all sessions // Find all sessions
std::set<int> idSet; std::set<int> idSet;
SessionMap::iterator sessionIter; for (auto sessionIter = mSessionMap.begin(); sessionIter != mSessionMap.end(); ++sessionIter)
for (sessionIter = mSessionMap.begin(); sessionIter != mSessionMap.end(); ++sessionIter)
idSet.insert(sessionIter->first); idSet.insert(sessionIter->first);
// Now process session one by one checking if current is available yet // Now process session one by one checking if current is available yet
std::set<int>::iterator resipIter; std::set<int>::iterator resipIter;
for (resipIter = idSet.begin(); resipIter != idSet.end(); ++resipIter) for (resipIter = idSet.begin(); resipIter != idSet.end(); ++resipIter)
{ {
SessionMap::iterator sessionIter = mSessionMap.find(*resipIter); auto sessionIter = mSessionMap.find(*resipIter);
if (sessionIter == mSessionMap.end()) if (sessionIter == mSessionMap.end())
continue; continue;
@ -432,7 +487,12 @@ void UserAgent::addRootCert(const ByteBuffer& data)
{ {
LOCK; LOCK;
resip::Data b(data.data(), data.size()); resip::Data b(data.data(), data.size());
mStack->getSecurity()->addRootCertPEM(b); try {
mStack->getSecurity()->addRootCertPEM(b);
}
catch(...) {
// Ignore silently
}
} }
PAccount UserAgent::createAccount(PVariantMap config) PAccount UserAgent::createAccount(PVariantMap config)
@ -467,7 +527,7 @@ PSession UserAgent::createSession(PAccount account)
return session; return session;
} }
std::string UserAgent::formatSipAddress(std::string sip) std::string UserAgent::formatSipAddress(const std::string& sip)
{ {
std::string result; std::string result;
if (sip.size()) if (sip.size())
@ -483,17 +543,18 @@ std::string UserAgent::formatSipAddress(std::string sip)
return result; return result;
} }
bool UserAgent::isSipAddressValid(std::string sip) bool UserAgent::isSipAddressValid(const std::string& sip)
{ {
bool result = false; bool result = false;
try try
{ {
if (sip.find('<') == std::string::npos) std::string s = sip;
sip = "<" + sip; if (s.find('<') == std::string::npos)
if (sip.find('>') == std::string::npos) s = "<" + s;
sip += ">"; if (s.find('>') == std::string::npos)
s += ">";
resip::Data d(formatSipAddress(sip)); resip::Data d(formatSipAddress(s));
resip::Uri uri(d); resip::Uri uri(d);
result = uri.isWellFormed(); result = uri.isWellFormed();
if (result) if (result)
@ -543,7 +604,7 @@ UserAgent::SipAddress UserAgent::parseSipAddress(const std::string& sip)
return result; 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()) if (sip1.empty() || sip2.empty())
return false; return false;

View File

@ -162,9 +162,9 @@ class UserAgent: public resip::ClientRegistrationHandler,
friend class WatcherQueue; friend class WatcherQueue;
public: public:
/* Compares two sip addresses. Returns true if they represent the same entity - user and domain are the same. Otherwise returns false. */ /* 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 bool compareSipAddresses(const std::string& sip1, const std::string& sip2);
static std::string formatSipAddress(std::string sip); static std::string formatSipAddress(const std::string& sip);
static bool isSipAddressValid(std::string sip); static bool isSipAddressValid(const std::string& sip);
struct SipAddress struct SipAddress
{ {
bool mValid; bool mValid;

View File

@ -34,9 +34,10 @@ set (ICE_STACK_SOURCES ICEAddress.cpp
ICETime.cpp ICETime.cpp
ICETransactionList.cpp) ICETransactionList.cpp)
if (ANDROID_ABI)
set (ICE_STACK_SOURCES ${ICE_STACK_SOURCES} android-ifaddrs/android-ifaddrs.h android-ifaddrs/android-ifaddrs.c) #if (ANDROID_ABI)
endif() # set (ICE_STACK_SOURCES ${ICE_STACK_SOURCES} android-ifaddrs/android-ifaddrs.h android-ifaddrs/android-ifaddrs.c)
#endif()
if (TARGET_MUSL) if (TARGET_MUSL)
add_definitions(-DTARGET_MUSL) add_definitions(-DTARGET_MUSL)

View File

@ -26,7 +26,7 @@
# include <linux/in6.h> # include <linux/in6.h>
# if defined(TARGET_ANDROID) # if defined(TARGET_ANDROID)
# if __ANDROID_API__ < 24 # if __ANDROID_API__ < 24
# include "android-ifaddrs/android-ifaddrs.h" # error not supported for ANDROID_API < 24
# else # else
# include <ifaddrs.h> # include <ifaddrs.h>
# endif # endif
@ -161,6 +161,7 @@ void NetworkHelper::reload(int networkType)
fillUwpInterfaceList(AF_INET, networkType, mIPList); fillUwpInterfaceList(AF_INET, networkType, mIPList);
fillUwpInterfaceList(AF_INET6, networkType, mIPList); fillUwpInterfaceList(AF_INET6, networkType, mIPList);
#else #else
// https://github.com/golang/go/issues/40569
struct ifaddrs* il = NULL; struct ifaddrs* il = NULL;
if (getifaddrs(&il)) if (getifaddrs(&il))
throw Exception(GETIFADDRS_FAILED, errno); throw Exception(GETIFADDRS_FAILED, errno);