Commit d2506c61 authored by Ghislain MARY's avatar Ghislain MARY

Add methods to get resources in platform helpers.

parent 623e8f50
Pipeline #631 canceled with stage
in 0 seconds
......@@ -1148,29 +1148,24 @@ static void build_sound_devices_table(LinphoneCore *lc){
if (old!=NULL) ms_free((void *)old);
}
static char *get_default_local_ring(LinphoneCore * lc) {
LinphoneFactory *factory = linphone_factory_get();
static string get_default_local_ring(LinphoneCore * lc) {
if (linphone_core_file_format_supported(lc, "mkv")) {
return bctbx_strdup_printf("%s/%s", linphone_factory_get_ring_resources_dir(factory), LOCAL_RING_MKV);
return static_cast<PlatformHelpers *>(lc->platform_helper)->getRingResource(LOCAL_RING_MKV);
}
return bctbx_strdup_printf("%s/%s", linphone_factory_get_ring_resources_dir(factory), LOCAL_RING_WAV);
return static_cast<PlatformHelpers *>(lc->platform_helper)->getRingResource(LOCAL_RING_WAV);
}
static char *get_default_onhold_music(LinphoneCore * lc) {
LinphoneFactory *factory = linphone_factory_get();
static string get_default_onhold_music(LinphoneCore * lc) {
if (linphone_core_file_format_supported(lc, "mkv")) {
return bctbx_strdup_printf("%s/%s", linphone_factory_get_sound_resources_dir(factory), HOLD_MUSIC_MKV);
return static_cast<PlatformHelpers *>(lc->platform_helper)->getSoundResource(HOLD_MUSIC_MKV);
}
return bctbx_strdup_printf("%s/%s", linphone_factory_get_sound_resources_dir(factory), HOLD_MUSIC_WAV);
return static_cast<PlatformHelpers *>(lc->platform_helper)->getSoundResource(HOLD_MUSIC_WAV);
}
static void sound_config_read(LinphoneCore *lc)
{
static void sound_config_read(LinphoneCore *lc) {
int tmp;
char *default_remote_ring;
const char *tmpbuf;
const char *devid;
LinphoneFactory *factory = linphone_factory_get();
#ifdef __linux
/*alsadev let the user use custom alsa device within linphone*/
......@@ -1230,23 +1225,19 @@ static void sound_config_read(LinphoneCore *lc)
ms_warning("'%s' ring file does not exist", tmpbuf);
}
} else {
char *default_local_ring = get_default_local_ring(lc);
linphone_core_set_ring(lc, default_local_ring);
bctbx_free(default_local_ring);
linphone_core_set_ring(lc, get_default_local_ring(lc).c_str());
}
default_remote_ring = bctbx_strdup_printf("%s/%s", linphone_factory_get_sound_resources_dir(factory), REMOTE_RING_WAV);
tmpbuf = default_remote_ring;
tmpbuf = lp_config_get_string(lc->config, "sound", "remote_ring", tmpbuf);
string defaultRemoteRing = static_cast<PlatformHelpers *>(lc->platform_helper)->getSoundResource(REMOTE_RING_WAV);
tmpbuf = lp_config_get_string(lc->config, "sound", "remote_ring", defaultRemoteRing.c_str());
if (bctbx_file_exist(tmpbuf) == -1){
tmpbuf = default_remote_ring;
tmpbuf = defaultRemoteRing.c_str();
}
if (strstr(tmpbuf, ".wav") == NULL) {
/* It currently uses old sound files, so replace them */
tmpbuf = default_remote_ring;
tmpbuf = defaultRemoteRing.c_str();
}
linphone_core_set_ringback(lc, tmpbuf);
bctbx_free(default_remote_ring);
tmpbuf = lp_config_get_string(lc->config, "sound", "hold_music", NULL);
if (tmpbuf) {
......@@ -1256,9 +1247,7 @@ static void sound_config_read(LinphoneCore *lc)
ms_warning("'%s' on-hold music file does not exist", tmpbuf);
}
} else {
char *default_onhold_music = get_default_onhold_music(lc);
linphone_core_set_play_file(lc, default_onhold_music);
bctbx_free(default_onhold_music);
linphone_core_set_play_file(lc, get_default_onhold_music(lc).c_str());
}
lc->sound_conf.latency=0;
......@@ -1313,26 +1302,24 @@ static int _linphone_core_tls_postcheck_callback(void *data, const bctbx_x509_ce
}
static void certificates_config_read(LinphoneCore *lc) {
LinphoneFactory *factory = linphone_factory_get();
const char *data_dir = linphone_factory_get_data_resources_dir(factory);
char *root_ca_path = bctbx_strdup_printf("%s/rootca.pem", data_dir);
const char *rootca = lp_config_get_string(lc->config,"sip","root_ca", NULL);
string rootCaPath = static_cast<PlatformHelpers *>(lc->platform_helper)->getDataResource("rootca.pem");
const char *rootca = lp_config_get_string(lc->config, "sip", "root_ca", nullptr);
// If rootca is not existing anymore, we try data_resources_dir/rootca.pem else default from belle-sip
if (rootca == NULL || ((bctbx_file_exist(rootca) != 0 && !bctbx_directory_exists(rootca)))) {
//Check root_ca_path
if ((bctbx_file_exist(root_ca_path) == 0) || bctbx_directory_exists(root_ca_path))
rootca = root_ca_path;
if (!rootca || ((bctbx_file_exist(rootca) != 0) && !bctbx_directory_exists(rootca))) {
// Check root_ca_path
if ((bctbx_file_exist(rootCaPath.c_str()) == 0) || bctbx_directory_exists(rootCaPath.c_str()))
rootca = rootCaPath.c_str();
else
rootca = NULL;
rootca = nullptr;
}
if (rootca)
linphone_core_set_root_ca(lc,rootca);
/*else use default value from belle-sip*/
linphone_core_verify_server_certificates(lc, !!lp_config_get_int(lc->config,"sip","verify_server_certs",TRUE));
linphone_core_verify_server_cn(lc, !!lp_config_get_int(lc->config,"sip","verify_server_cn",TRUE));
bctbx_free(root_ca_path);
linphone_core_set_root_ca(lc, rootca);
// else use default value from belle-sip
linphone_core_verify_server_certificates(lc, !!lp_config_get_int(lc->config, "sip", "verify_server_certs", TRUE));
linphone_core_verify_server_cn(lc, !!lp_config_get_int(lc->config, "sip", "verify_server_cn", TRUE));
lc->sal->setTlsPostcheckCallback(_linphone_core_tls_postcheck_callback, lc);
}
......
......@@ -46,53 +46,59 @@ public:
IosPlatformHelpers (LinphoneCore *lc, void *system_context);
~IosPlatformHelpers () = default;
void setDnsServers () override {}
void acquireWifiLock () override {}
void releaseWifiLock () override {}
void acquireMcastLock () override {}
void releaseMcastLock () override {}
void acquireCpuLock () override;
void releaseCpuLock () override;
string getDataPath () override { return ""; }
string getConfigPath () override { return ""; }
void setVideoWindow (void *windowId) override {}
string getConfigPath () const override { return ""; }
string getDataPath () const override { return ""; }
string getDataResource (const string &filename) const override;
string getImageResource (const string &filename) const override;
string getRingResource (const string &filename) const override;
string getSoundResource (const string &filename) const override;
void setVideoPreviewWindow (void *windowId) override {}
void setNetworkReachable (bool reachable) override {}
void setVideoWindow (void *windowId) override {}
bool isNetworkReachable () override { return false; }
void onLinphoneCoreReady (bool monitoringEnabled) override {}
void onWifiOnlyEnabled (bool enabled) override {}
void setDnsServers () override {}
void setHttpProxy (string host, int port) override {}
void setNetworkReachable (bool reachable) override {}
void onLinphoneCoreReady (bool monitoringEnabled) override {}
private:
void bgTaskTimeout ();
static void sBgTaskTimeout (void *data);
static string getResourceDirPath (CFStringRef framework, CFStringRef resource);
static string getResourcePath (CFStringRef framework, CFStringRef resource);
static string getResourceDirPath (const string &framework, const string &resource);
static string getResourcePath (const string &framework, const string &resource);
long int mCpuLockTaskId;
int mCpuLockCount;
static const string Framework;
};
// =============================================================================
const string IosPlatformHelpers::Framework = "org.linphone.linphone";
IosPlatformHelpers::IosPlatformHelpers (LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) {
mCpuLockCount = 0;
mCpuLockTaskId = 0;
string rootCaPath = getResourcePath(CFSTR("org.linphone.linphone"), CFSTR("rootca.pem"));
if (!rootCaPath.empty())
linphone_core_set_root_ca(lc, rootCaPath.c_str());
else
lError() << "IosPlatformHelpers did not find rootca.pem resource";
string cpimPath = getResourceDirPath(CFSTR("org.linphone.linphone"), CFSTR("cpim_grammar"));
string cpimPath = getResourceDirPath(Framework, "cpim_grammar");
if (!cpimPath.empty())
belr::GrammarLoader::get().addPath(cpimPath);
else
lError() << "IosPlatformHelpers did not find cpim grammar resource directory...";
#ifdef VCARD_ENABLED
string vcardPath = getResourceDirPath(CFSTR("org.linphone.belcard"), CFSTR("vcard_grammar"));
string vcardPath = getResourceDirPath("org.linphone.belcard", "vcard_grammar");
if (!vcardPath.empty())
belr::GrammarLoader::get().addPath(vcardPath);
else
......@@ -141,23 +147,45 @@ void IosPlatformHelpers::releaseCpuLock () {
mCpuLockTaskId = 0;
}
string IosPlatformHelpers::getResourceDirPath (CFStringRef framework, CFStringRef resource) {
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(framework);
CFURLRef resourceUrl = CFBundleCopyResourceURL(bundle, resource, nullptr, nullptr);
// -----------------------------------------------------------------------------
string IosPlatformHelpers::getDataResource (const string &filename) const {
return getResourcePath(Framework, filename);
}
string IosPlatformHelpers::getImageResource (const string &filename) const {
return getResourcePath(Framework, filename);
}
string IosPlatformHelpers::getRingResource (const string &filename) const {
return getResourcePath(Framework, filename);
}
string IosPlatformHelpers::getSoundResource (const string &filename) const {
return getResourcePath(Framework, filename);
}
// -----------------------------------------------------------------------------
string IosPlatformHelpers::getResourceDirPath (const string &framework, const string &resource) {
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
CFStringRef cfFramework = CFStringCreateWithCString(nullptr, framework.c_str(), encodingMethod);
CFStringRef cfResource = CFStringCreateWithCString(nullptr, resource.c_str(), encodingMethod);
CFBundleRef bundle = CFBundleGetBundleWithIdentifier(cfFramework);
CFURLRef resourceUrl = CFBundleCopyResourceURL(bundle, cfResource, nullptr, nullptr);
CFURLRef resourceUrlDirectory = CFURLCreateCopyDeletingLastPathComponent(nullptr, resourceUrl);
CFStringRef resourcePath = CFURLCopyFileSystemPath(resourceUrlDirectory, kCFURLPOSIXPathStyle);
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
string path(CFStringGetCStringPtr(resourcePath, encodingMethod));
CFRelease(resourceUrl);
CFRelease(resourcePath);
CFRelease(resourceUrlDirectory);
CFRelease(resourceUrl);
CFRelease(cfResource);
CFRelease(cfFramework);
return path;
}
string IosPlatformHelpers::getResourcePath (CFStringRef framework, CFStringRef resource) {
CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
string resourceFile(CFStringGetCStringPtr(resource, encodingMethod));
return getResourceDirPath(framework, resource) + "/" + resourceFile;
string IosPlatformHelpers::getResourcePath (const string &framework, const string &resource) {
return getResourceDirPath(framework, resource) + "/" + resource;
}
// -----------------------------------------------------------------------------
......
......@@ -39,7 +39,6 @@ GenericPlatformHelpers::~GenericPlatformHelpers () {
}
}
void GenericPlatformHelpers::setDnsServers () {}
void GenericPlatformHelpers::acquireWifiLock () {}
......@@ -53,26 +52,64 @@ void GenericPlatformHelpers::acquireCpuLock () {}
void GenericPlatformHelpers::releaseCpuLock () {}
string GenericPlatformHelpers::getDataPath () {
string GenericPlatformHelpers::getConfigPath () const {
return "";
}
string GenericPlatformHelpers::getConfigPath () {
string GenericPlatformHelpers::getDataPath () const {
return "";
}
string GenericPlatformHelpers::getDataResource (const string &filename) const {
return getFilePath(
linphone_factory_get_data_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getImageResource (const string &filename) const {
return getFilePath(
linphone_factory_get_image_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getRingResource (const string &filename) const {
return getFilePath(
linphone_factory_get_ring_resources_dir(linphone_factory_get()),
filename
);
}
string GenericPlatformHelpers::getSoundResource (const string &filename) const {
return getFilePath(
linphone_factory_get_sound_resources_dir(linphone_factory_get()),
filename
);
}
void GenericPlatformHelpers::setVideoPreviewWindow (void *windowId) {}
void GenericPlatformHelpers::setVideoWindow (void *windowId) {}
bool GenericPlatformHelpers::isNetworkReachable () {
return mNetworkReachable;
}
void GenericPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void GenericPlatformHelpers::setDnsServers () {}
void GenericPlatformHelpers::setHttpProxy (string host, int port) {}
void GenericPlatformHelpers::setNetworkReachable (bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable);
}
bool GenericPlatformHelpers::isNetworkReachable () {
return mNetworkReachable;
}
void GenericPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {
if (!monitoringEnabled) return;
......@@ -89,9 +126,6 @@ void GenericPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {
}
}
void GenericPlatformHelpers::onWifiOnlyEnabled (bool enabled) {}
void GenericPlatformHelpers::setHttpProxy (string host, int port) {}
int GenericPlatformHelpers::monitorTimerExpired (void *data, unsigned int revents) {
GenericPlatformHelpers *helper = static_cast<GenericPlatformHelpers *>(data);
......
......@@ -21,6 +21,7 @@
#define _L_PLATFORM_HELPERS_H_
#include <string>
#include <sstream>
#include "linphone/utils/general.h"
......@@ -40,29 +41,43 @@ class PlatformHelpers {
public:
virtual ~PlatformHelpers () = default;
LinphoneCore *getCore() { return mCore; }
LinphoneCore *getCore() const { return mCore; }
// This method shall retrieve DNS server list from the platform and assign it to the core.
virtual void setDnsServers () = 0;
virtual void acquireWifiLock () = 0;
virtual void releaseWifiLock () = 0;
virtual void acquireMcastLock () = 0;
virtual void releaseMcastLock () = 0;
virtual void acquireCpuLock () = 0;
virtual void releaseCpuLock () = 0;
virtual std::string getDataPath () = 0;
virtual std::string getConfigPath () = 0;
virtual void setVideoWindow (void *windowId) = 0;
virtual std::string getConfigPath () const = 0;
virtual std::string getDataPath () const = 0;
virtual std::string getDataResource (const std::string &filename) const = 0;
virtual std::string getImageResource (const std::string &filename) const = 0;
virtual std::string getRingResource (const std::string &filename) const = 0;
virtual std::string getSoundResource (const std::string &filename) const = 0;
virtual void setVideoPreviewWindow (void *windowId) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual void setVideoWindow (void *windowId) = 0;
// This method shall retrieve DNS server list from the platform and assign it to the core.
virtual bool isNetworkReachable () = 0;
virtual void onLinphoneCoreReady (bool monitoringEnabled) = 0;
virtual void onWifiOnlyEnabled (bool enabled) = 0;
virtual void setDnsServers () = 0;
virtual void setHttpProxy (std::string host, int port) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual void onLinphoneCoreReady (bool monitoringEnabled) = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
inline std::string getFilePath (const std::string &directory, const std::string &filename) const {
std::ostringstream oss;
oss << directory << "/" << filename;
return oss.str();
}
LinphoneCore *mCore;
};
......@@ -71,22 +86,30 @@ public:
explicit GenericPlatformHelpers (LinphoneCore *lc);
~GenericPlatformHelpers ();
void setDnsServers () override;
void acquireWifiLock () override;
void releaseWifiLock () override;
void acquireMcastLock () override;
void releaseMcastLock () override;
void acquireCpuLock () override;
void releaseCpuLock () override;
std::string getDataPath () override;
std::string getConfigPath () override;
void setVideoWindow (void *windowId) override;
std::string getConfigPath () const override;
std::string getDataPath () const override;
std::string getDataResource (const std::string &filename) const override;
std::string getImageResource (const std::string &filename) const override;
std::string getRingResource (const std::string &filename) const override;
std::string getSoundResource (const std::string &filename) const override;
void setVideoPreviewWindow (void *windowId) override;
void setNetworkReachable (bool reachable) override;
void setVideoWindow (void *windowId) override;
bool isNetworkReachable () override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onWifiOnlyEnabled (bool enabled) override;
void setDnsServers () override;
void setHttpProxy (std::string host, int port) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
private:
static int monitorTimerExpired (void *data, unsigned int revents);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment