Prevent port from being set in third party account SIP identity + update existing accounts to remove port from identity

This commit is contained in:
Sylvain Berfini 2025-06-02 10:32:38 +02:00
parent e7f95adab9
commit 0c17aea1c7
2 changed files with 30 additions and 5 deletions

View file

@ -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) {

View file

@ -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()