Commit d2506c61 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

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);
}
......
......@@ -37,23 +37,31 @@ public:
AndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
~AndroidPlatformHelpers ();
void setDnsServers () override;
void acquireWifiLock () override;
void releaseWifiLock () override;
void acquireMcastLock () override;
void releaseMcastLock () override;
void acquireCpuLock () override;
void releaseCpuLock () override;
string getDataPath () override;
string getConfigPath () override;
void setVideoWindow (void *windowId) override;
string getConfigPath () const override;
string getDataPath () const override;
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;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onWifiOnlyEnabled (bool enabled) override;
void setDnsServers () override;
void setNetworkReachable (bool reachable) override;
void setHttpProxy (string host, int port) override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void _setPreviewVideoWindow(jobject window);
void _setVideoWindow(jobject window);
......@@ -154,39 +162,7 @@ AndroidPlatformHelpers::~AndroidPlatformHelpers () {
lInfo() << "AndroidPlatformHelpers has been destroyed.";
}
void AndroidPlatformHelpers::setDnsServers () {
if (!mJavaHelper || linphone_core_get_dns_set_by_app(mCore)) {
lError() << "AndroidPlatformHelpers' mJavaHelper is null.";
return;
}
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper, mGetDnsServersId);
bctbx_list_t *l = nullptr;
if (env->ExceptionCheck()) {
env->ExceptionClear();
lError() << "AndroidPlatformHelpers::setDnsServers() exception.";
return;
}
if (jservers != nullptr) {
int count = env->GetArrayLength(jservers);
for (int i = 0; i < count; i++) {
jstring jserver = (jstring)env->GetObjectArrayElement(jservers, i);
const char *str = env->GetStringUTFChars(jserver, nullptr);
if (str) {
lInfo() << "AndroidPlatformHelpers found DNS server " << str;
l = bctbx_list_append(l, ms_strdup(str));
env->ReleaseStringUTFChars(jserver, str);
}
}
} else {
lError() << "AndroidPlatformHelpers::setDnsServers() failed to get DNS servers list";
}
linphone_core_set_dns_servers(mCore, l);
bctbx_list_free_with_data(l, ms_free);
}
}
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::acquireWifiLock () {
callVoidMethod(mWifiLockAcquireId);
......@@ -212,7 +188,18 @@ void AndroidPlatformHelpers::releaseCpuLock () {
callVoidMethod(mCpuLockReleaseId);
}
string AndroidPlatformHelpers::getDataPath () {
// -----------------------------------------------------------------------------
string AndroidPlatformHelpers::getConfigPath () const {
JNIEnv *env = ms_get_jni_env();
jstring jconfig_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetConfigPathId);
const char *config_path = GetStringUTFChars(env, jconfig_path);
string configPath = config_path;
ReleaseStringUTFChars(env, jconfig_path, config_path);
return configPath + "/";
}
string AndroidPlatformHelpers::getDataPath () const {
JNIEnv *env = ms_get_jni_env();
jstring jdata_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetDataPathId);
const char *data_path = GetStringUTFChars(env, jdata_path);
......@@ -221,40 +208,36 @@ string AndroidPlatformHelpers::getDataPath () {
return dataPath + "/";
}
string AndroidPlatformHelpers::getNativeLibraryDir () {
JNIEnv *env = ms_get_jni_env();
string libPath;
jstring jlib_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetNativeLibraryDirId);
if (jlib_path){
const char *lib_path = GetStringUTFChars(env, jlib_path);
libPath = lib_path;
ReleaseStringUTFChars(env, jlib_path, lib_path);
}
return libPath;
string AndroidPlatformHelpers::getDataResource (const string &filename) const {
return getFilePath(
linphone_factory_get_data_resources_dir(linphone_factory_get()),
filename
);
}
string AndroidPlatformHelpers::getConfigPath () {
JNIEnv *env = ms_get_jni_env();
jstring jconfig_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetConfigPathId);
const char *config_path = GetStringUTFChars(env, jconfig_path);
string configPath = config_path;
ReleaseStringUTFChars(env, jconfig_path, config_path);
return configPath + "/";
string AndroidPlatformHelpers::getImageResource (const string &filename) const {
return getFilePath(
linphone_factory_get_image_resources_dir(linphone_factory_get()),
filename
);
}
int AndroidPlatformHelpers::callVoidMethod (jmethodID id) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, id);
if (env->ExceptionCheck()) {
env->ExceptionClear();
return -1;
} else
return 0;
} else
return -1;
string AndroidPlatformHelpers::getRingResource (const string &filename) const {
return getFilePath(
linphone_factory_get_ring_resources_dir(linphone_factory_get()),
filename
);
}
string AndroidPlatformHelpers::getSoundResource (const string &filename) const {
return getFilePath(
linphone_factory_get_sound_resources_dir(linphone_factory_get()),
filename
);
}
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::setVideoPreviewWindow (void *windowId) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
......@@ -279,6 +262,74 @@ void AndroidPlatformHelpers::setVideoWindow (void *windowId) {
}
}
// -----------------------------------------------------------------------------
bool AndroidPlatformHelpers::isNetworkReachable() {
return mNetworkReachable;
}
void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnWifiOnlyEnabledId, (jboolean)enabled);
}
}
void AndroidPlatformHelpers::setHttpProxy(string host, int port) {
linphone_core_set_http_proxy_host(mCore, host.c_str());
linphone_core_set_http_proxy_port(mCore, port);
}
void AndroidPlatformHelpers::setDnsServers () {
if (!mJavaHelper || linphone_core_get_dns_set_by_app(mCore)) {
lError() << "AndroidPlatformHelpers' mJavaHelper is null.";
return;
}
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper, mGetDnsServersId);
bctbx_list_t *l = nullptr;
if (env->ExceptionCheck()) {
env->ExceptionClear();
lError() << "AndroidPlatformHelpers::setDnsServers() exception.";
return;
}
if (jservers != nullptr) {
int count = env->GetArrayLength(jservers);
for (int i = 0; i < count; i++) {
jstring jserver = (jstring)env->GetObjectArrayElement(jservers, i);
const char *str = env->GetStringUTFChars(jserver, nullptr);
if (str) {
lInfo() << "AndroidPlatformHelpers found DNS server " << str;
l = bctbx_list_append(l, ms_strdup(str));
env->ReleaseStringUTFChars(jserver, str);
}
}
} else {
lError() << "AndroidPlatformHelpers::setDnsServers() failed to get DNS servers list";
}
linphone_core_set_dns_servers(mCore, l);
bctbx_list_free_with_data(l, ms_free);
}
}
void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable ? 1 : 0);
}
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::onLinphoneCoreReady(bool monitoringEnabled) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreReadyId, (jboolean)monitoringEnabled);
}
}
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::_setPreviewVideoWindow(jobject window) {
JNIEnv *env = ms_get_jni_env();
LinphoneCore *lc = getCore();
......@@ -309,32 +360,31 @@ void AndroidPlatformHelpers::_setVideoWindow(jobject window) {
_linphone_core_set_native_video_window_id(lc, (void *)mVideoWindow);
}
void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
mNetworkReachable = reachable;
linphone_core_set_network_reachable_internal(mCore, reachable ? 1 : 0);
}
bool AndroidPlatformHelpers::isNetworkReachable() {
return mNetworkReachable;
}
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::onLinphoneCoreReady(bool monitoringEnabled) {
int AndroidPlatformHelpers::callVoidMethod (jmethodID id) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreReadyId, (jboolean)monitoringEnabled);
}
env->CallVoidMethod(mJavaHelper, id);
if (env->ExceptionCheck()) {
env->ExceptionClear();
return -1;
} else
return 0;
} else
return -1;
}
void AndroidPlatformHelpers::onWifiOnlyEnabled(bool enabled) {
string AndroidPlatformHelpers::getNativeLibraryDir () {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnWifiOnlyEnabledId, (jboolean)enabled);
string libPath;
jstring jlib_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetNativeLibraryDirId);
if (jlib_path){
const char *lib_path = GetStringUTFChars(env, jlib_path);
libPath = lib_path;
ReleaseStringUTFChars(env, jlib_path, lib_path);
}
}
void AndroidPlatformHelpers::setHttpProxy(string host, int port) {
linphone_core_set_http_proxy_host(mCore, host.c_str());
linphone_core_set_http_proxy_port(mCore, port);
return libPath;
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
......
......@@ -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) {}