Improved implementation of transport protocols and dns servers settings

This commit is contained in:
Juha Heinanen
2026-02-15 07:03:03 +02:00
parent 0058f778cc
commit b0d163bfa7
3 changed files with 17 additions and 20 deletions

View File

@ -286,6 +286,18 @@ object Config {
// Api.reload_config()
}
fun dnsServers(): String {
return if (variable("dyn_dns") == "yes")
""
else {
val servers = variables("dns_server")
var serverList = ""
for (server in servers)
serverList += ", $server"
serverList.trimStart(',').trimStart(' ')
}
}
fun updateDnsServers(dnsServers: List<InetAddress>): Int {
var servers = ""
for (dnsServer in dnsServers) {

View File

@ -1368,7 +1368,7 @@ private fun checkOnClick(ctx: Context, viewModel: SettingsViewModel): Boolean {
val transportProtocols = viewModel.transportProtocols.value
.lowercase(Locale.ROOT).replace(" ", "")
if (transportProtocols != viewModel.oldTransportProtocols) {
if (transportProtocols != Config.variable("sip_transports")) {
if (!checkTransportProtocols(transportProtocols)) {
alertTitle.value = noticeTitle
alertMessage.value = "${ctx.getString(R.string.invalid_transport_protocols)}: " +
@ -1385,7 +1385,7 @@ private fun checkOnClick(ctx: Context, viewModel: SettingsViewModel): Boolean {
val dnsServers = addMissingPorts(viewModel.dnsServers.value
.lowercase(Locale.ROOT).replace(" ", ""))
if (dnsServers != viewModel.oldDnsServers) {
if (dnsServers != Config.dnsServers()) {
if (!checkDnsServers(dnsServers)) {
alertTitle.value = noticeTitle
alertMessage.value = "${ctx.getString(R.string.invalid_dns_servers)}: $dnsServers"

View File

@ -18,13 +18,8 @@ class SettingsViewModel: ViewModel() {
val autoStart = MutableStateFlow(false)
val listenAddress = MutableStateFlow("")
val addressFamily = MutableStateFlow("")
val transportProtocols = MutableStateFlow("")
var oldTransportProtocols = ""
val dnsServers = MutableStateFlow("")
var oldDnsServers = ""
val tlsCertificateFile = MutableStateFlow(false)
val verifyServer = MutableStateFlow(false)
val caFile = MutableStateFlow(false)
@ -43,18 +38,8 @@ class SettingsViewModel: ViewModel() {
private var isLoaded = false
fun loadSettings(ctx: Context) {
if (isLoaded) return else isLoaded = true
oldTransportProtocols = Config.variable("sip_transports")
oldDnsServers = if (Config.variable("dyn_dns") == "yes")
""
else {
val servers = Config.variables("dns_server")
var serverList = ""
for (server in servers)
serverList += ", $server"
serverList.trimStart(',').trimStart(' ')
}
if (isLoaded) return else isLoaded = true
autoStart.value = Config.variable("auto_start") == "yes"
@ -65,9 +50,9 @@ class SettingsViewModel: ViewModel() {
mutableIntStateOf(familyValues.indexOf(Config.variable("net_af").lowercase()))
addressFamily.value = familyValues[itemPosition.intValue]
transportProtocols.value = oldTransportProtocols
transportProtocols.value = Config.variable("sip_transports")
dnsServers.value = oldDnsServers
dnsServers.value = Config.dnsServers()
tlsCertificateFile.value = File(BaresipService.filesPath + "/cert.pem").exists()