diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index dc0af6299..c9e58db19 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -639,6 +639,8 @@ class CoreContext configurationMigration5To6() } else if (oldVersion < 600004) { // 6.0.4 disablePushNotificationsFromThirdPartySipAccounts() + } else if (oldVersion < 600009) { // 6.0.9 + removePortFromSipIdentity() } if (core.logCollectionUploadServerUrl.isNullOrEmpty()) { @@ -1092,6 +1094,22 @@ class CoreContext // Migration between versions related + @WorkerThread + private fun removePortFromSipIdentity() { + for (account in core.accountList) { + val params = account.params + val identity = params.identityAddress + if (identity != null && identity.port != 0) { + val clone = params.clone() + val newIdentity = identity.clone() + newIdentity.port = 0 + clone.identityAddress = newIdentity + Log.w("$TAG Found account with identity address [${identity.asStringUriOnly()}] that contains port information in domain, removing port information in new identity [${newIdentity.asStringUriOnly()}]") + account.params = clone + } + } + } + @WorkerThread private fun disablePushNotificationsFromThirdPartySipAccounts() { for (account in core.accountList) { diff --git a/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt b/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt index ac2c57db8..1b7c62adf 100644 --- a/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt +++ b/app/src/main/java/org/linphone/ui/assistant/viewmodel/ThirdPartySipAccountLoginViewModel.kt @@ -173,11 +173,17 @@ class ThirdPartySipAccountLoginViewModel // Remove sip: in front of domain, just in case... val domainValue = domain.value.orEmpty().trim() - val domain = if (domainValue.startsWith("sip:")) { + val domainWithoutSip = if (domainValue.startsWith("sip:")) { domainValue.substring("sip:".length) } else { domainValue } + val domainAddress = Factory.instance().createAddress("sip:$domainWithoutSip") + val port = domainAddress?.port ?: -1 + if (port != -1) { + Log.w("$TAG It seems a port [$port] was set in the domain [$domainValue], removing it from SIP identity but setting it to proxy server URI") + } + val domain = domainAddress?.domain ?: domainWithoutSip // Allow to enter SIP identity instead of simply username // in case identity domain doesn't match proxy domain @@ -194,7 +200,6 @@ class ThirdPartySipAccountLoginViewModel val userId = authId.value.orEmpty().trim() Log.i("$TAG Parsed username is [$user], user ID [$userId] and domain [$domain]") - val identity = "sip:$user@$domain" val identityAddress = Factory.instance().createAddress(identity) if (identityAddress == null) { @@ -202,13 +207,14 @@ class ThirdPartySipAccountLoginViewModel showRedToast(R.string.assistant_login_cant_parse_address_toast, R.drawable.warning_circle) return@postOnCoreThread } + Log.i("$TAG Computed SIP identity is [${identityAddress.asStringUriOnly()}]") val accounts = core.accountList val found = accounts.find { it.params.identityAddress?.weakEqual(identityAddress) == true } if (found != null) { - Log.w("$TAG An account with the same identity address [${identityAddress.asStringUriOnly()}] already exists, do not add it again!") + Log.w("$TAG An account with the same identity address [${found.params.identityAddress?.asStringUriOnly()}] already exists, do not add it again!") showRedToast(R.string.assistant_account_login_already_connected_error, R.drawable.warning_circle) return@postOnCoreThread } @@ -219,7 +225,7 @@ class ThirdPartySipAccountLoginViewModel password.value.orEmpty().trim(), null, null, - domainValue + domainAddress?.domain ?: domainValue ) core.addAuthInfo(newlyCreatedAuthInfo) @@ -239,7 +245,7 @@ class ThirdPartySipAccountLoginViewModel } Factory.instance().createAddress(server) } else { - Factory.instance().createAddress("sip:$domain") + domainAddress ?: Factory.instance().createAddress("sip:$domainWithoutSip") } serverAddress?.transport = when (transport.value.orEmpty().trim()) { @@ -247,6 +253,7 @@ class ThirdPartySipAccountLoginViewModel TransportType.Tls.name.uppercase(Locale.getDefault()) -> TransportType.Tls else -> TransportType.Udp } + Log.i("$TAG Created proxy server SIP address [${serverAddress?.asStringUriOnly()}]") accountParams.serverAddress = serverAddress val prefix = internationalPrefix.value.orEmpty().trim()