Source

Target

Commits (1)
Showing with 26 additions and 33 deletions
......@@ -96,7 +96,8 @@ AccountParams::AccountParams (LinphoneCore *lc) {
if (lc && lc->push_config) {
mPushNotificationConfig = PushNotificationConfig::toCpp(lc->push_config)->clone();
} else {
mPushNotificationConfig = new PushNotificationConfig(string(lc ? linphone_config_get_default_string(lc->config, "proxy", "push_parameters", "") : ""));
mPushNotificationConfig = new PushNotificationConfig();
mPushNotificationConfig->readPushParamsFromString(string(lc ? linphone_config_get_default_string(lc->config, "proxy", "push_parameters", "") : ""));
}
}
......@@ -128,24 +129,13 @@ AccountParams::AccountParams (LinphoneCore *lc, int index) : AccountParams(lc) {
mContactUriParameters = linphone_config_get_string(config, key, "contact_uri_parameters", mContactUriParameters.c_str());
string pushParameters = linphone_config_get_string(config, key, "push_parameters", "");
bool corePushEnabled = linphone_core_is_push_notification_enabled(lc);
if (corePushEnabled && !pushParameters.empty()) {
// If pushParameters have been saved previously, then we have all the necessary push informations available and we should not need to save
// the push informations from the core (voip token, remote token, team ID, bundle identifier)
if (mPushNotificationConfig) mPushNotificationConfig->unref();
mPushNotificationConfig = new PushNotificationConfig(pushParameters);
} else {
PushNotificationConfig* oldConfig = mPushNotificationConfig;
mPushNotificationConfig = new PushNotificationConfig(mContactUriParameters);
if (oldConfig) {
// Saving the push infos that may have been set before the account was created
mPushNotificationConfig->setVoipToken(oldConfig->getVoipToken());
mPushNotificationConfig->setRemoteToken(oldConfig->getRemoteToken());
mPushNotificationConfig->setTeamId(oldConfig->getTeamId());
mPushNotificationConfig->setBundleIdentifer(oldConfig->getBundleIdentifer());
oldConfig->unref();
}
//mPushNotificationConfig can't be null because it is always created in AccountParams(lc) called previously
if (linphone_core_is_push_notification_enabled(lc) && !pushParameters.empty()) {
mPushNotificationConfig->readPushParamsFromString(pushParameters);
} else if (!mContactUriParameters.empty()){
mPushNotificationConfig->readPushParamsFromString(mContactUriParameters);
}
mExpires = linphone_config_get_int(config, key, "reg_expires", mExpires);
mRegisterEnabled = !!linphone_config_get_int(config, key, "reg_sendregister", mRegisterEnabled);
mPublishEnabled = !!linphone_config_get_int(config, key, "publish", mPublishEnabled);
......
......@@ -42,21 +42,6 @@ PushNotificationConfig::PushNotificationConfig() {
mRemoteToken = "";
}
PushNotificationConfig::PushNotificationConfig(string const &serializedConfig) : PushNotificationConfig() {
Address pushParamsWrapper("sip:dummy;" + serializedConfig);
for (auto &param : mPushParams) {
string paramValue = pushParamsWrapper.getUriParamValue(param.first);
if (paramValue.empty()) {
// Check for legacy parameters
if (param.first == PushConfigPridKey) paramValue = pushParamsWrapper.getUriParamValue("pn-tok");
if (param.first == PushConfigParamKey) paramValue = pushParamsWrapper.getUriParamValue("app-id");
if (param.first == PushConfigProviderKey) paramValue = pushParamsWrapper.getUriParamValue("pn-type");
}
if (!paramValue.empty())
param.second = paramValue;
}
}
PushNotificationConfig::PushNotificationConfig(const PushNotificationConfig &other) : HybridObject(other) {
mPushParams = other.mPushParams;
mTeamId = other.mTeamId;
......@@ -249,4 +234,19 @@ string PushNotificationConfig::asString(bool withRemoteSpecificParams, bool isLe
return serializedConfig;
}
void PushNotificationConfig::readPushParamsFromString(string const& serializedConfig) {
Address pushParamsWrapper("sip:dummy;" + serializedConfig);
for (auto &param : mPushParams) {
string paramValue = pushParamsWrapper.getUriParamValue(param.first);
if (paramValue.empty()) {
// Check for legacy parameters
if (param.first == PushConfigPridKey) paramValue = pushParamsWrapper.getUriParamValue("pn-tok");
if (param.first == PushConfigParamKey) paramValue = pushParamsWrapper.getUriParamValue("app-id");
if (param.first == PushConfigProviderKey) paramValue = pushParamsWrapper.getUriParamValue("pn-type");
}
if (!paramValue.empty())
param.second = paramValue;
}
}
LINPHONE_END_NAMESPACE
......@@ -82,6 +82,7 @@ class PushNotificationConfig: public bellesip::HybridObject<LinphonePushNotifica
* MsgStr, CallStr, GroupChatStr, CallSnd and MsgSnd will only be saved if withRemoteSpecificParams == true *
* /!\ TeamId, BundleId, VoipToken and RemoteToken will not be saved /!\ */
string asString(bool withRemoteSpecificParams=true, bool isLegacy=false) const;
void readPushParamsFromString(string const& serializedConfig);
private:
string mTeamId;
......
......@@ -210,6 +210,7 @@ static void remote_provisioning_check_push_params(void) {
linphone_push_notification_config_set_voip_token(linphone_core_get_push_notification_config(marie->lc), "token:voip");
linphone_push_notification_config_set_bundle_identifier(linphone_core_get_push_notification_config(marie->lc), "linphone-tester");
linphone_push_notification_config_set_param(linphone_core_get_push_notification_config(marie->lc), "param");
linphone_core_manager_start(marie, FALSE);
BC_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
......@@ -225,6 +226,7 @@ static void remote_provisioning_check_push_params(void) {
BC_ASSERT_STRING_EQUAL(linphone_push_notification_config_get_voip_token(linphone_account_params_get_push_notification_config(marie_params)), "token:voip");
BC_ASSERT_STRING_EQUAL(linphone_push_notification_config_get_bundle_identifier(linphone_account_params_get_push_notification_config(marie_params)), "linphone-tester");
BC_ASSERT_STRING_EQUAL(linphone_push_notification_config_get_param(linphone_account_params_get_push_notification_config(marie_params)), "param");
linphone_account_params_set_push_notification_allowed(marie_params, TRUE);
......