Improved implementation of transport protocols and dns servers settings
This commit is contained in:
@ -286,6 +286,18 @@ object Config {
|
|||||||
// Api.reload_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 {
|
fun updateDnsServers(dnsServers: List<InetAddress>): Int {
|
||||||
var servers = ""
|
var servers = ""
|
||||||
for (dnsServer in dnsServers) {
|
for (dnsServer in dnsServers) {
|
||||||
|
|||||||
@ -1368,7 +1368,7 @@ private fun checkOnClick(ctx: Context, viewModel: SettingsViewModel): Boolean {
|
|||||||
|
|
||||||
val transportProtocols = viewModel.transportProtocols.value
|
val transportProtocols = viewModel.transportProtocols.value
|
||||||
.lowercase(Locale.ROOT).replace(" ", "")
|
.lowercase(Locale.ROOT).replace(" ", "")
|
||||||
if (transportProtocols != viewModel.oldTransportProtocols) {
|
if (transportProtocols != Config.variable("sip_transports")) {
|
||||||
if (!checkTransportProtocols(transportProtocols)) {
|
if (!checkTransportProtocols(transportProtocols)) {
|
||||||
alertTitle.value = noticeTitle
|
alertTitle.value = noticeTitle
|
||||||
alertMessage.value = "${ctx.getString(R.string.invalid_transport_protocols)}: " +
|
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
|
val dnsServers = addMissingPorts(viewModel.dnsServers.value
|
||||||
.lowercase(Locale.ROOT).replace(" ", ""))
|
.lowercase(Locale.ROOT).replace(" ", ""))
|
||||||
if (dnsServers != viewModel.oldDnsServers) {
|
if (dnsServers != Config.dnsServers()) {
|
||||||
if (!checkDnsServers(dnsServers)) {
|
if (!checkDnsServers(dnsServers)) {
|
||||||
alertTitle.value = noticeTitle
|
alertTitle.value = noticeTitle
|
||||||
alertMessage.value = "${ctx.getString(R.string.invalid_dns_servers)}: $dnsServers"
|
alertMessage.value = "${ctx.getString(R.string.invalid_dns_servers)}: $dnsServers"
|
||||||
|
|||||||
@ -18,13 +18,8 @@ class SettingsViewModel: ViewModel() {
|
|||||||
val autoStart = MutableStateFlow(false)
|
val autoStart = MutableStateFlow(false)
|
||||||
val listenAddress = MutableStateFlow("")
|
val listenAddress = MutableStateFlow("")
|
||||||
val addressFamily = MutableStateFlow("")
|
val addressFamily = MutableStateFlow("")
|
||||||
|
|
||||||
val transportProtocols = MutableStateFlow("")
|
val transportProtocols = MutableStateFlow("")
|
||||||
var oldTransportProtocols = ""
|
|
||||||
|
|
||||||
val dnsServers = MutableStateFlow("")
|
val dnsServers = MutableStateFlow("")
|
||||||
var oldDnsServers = ""
|
|
||||||
|
|
||||||
val tlsCertificateFile = MutableStateFlow(false)
|
val tlsCertificateFile = MutableStateFlow(false)
|
||||||
val verifyServer = MutableStateFlow(false)
|
val verifyServer = MutableStateFlow(false)
|
||||||
val caFile = MutableStateFlow(false)
|
val caFile = MutableStateFlow(false)
|
||||||
@ -43,18 +38,8 @@ class SettingsViewModel: ViewModel() {
|
|||||||
private var isLoaded = false
|
private var isLoaded = false
|
||||||
|
|
||||||
fun loadSettings(ctx: Context) {
|
fun loadSettings(ctx: Context) {
|
||||||
if (isLoaded) return else isLoaded = true
|
|
||||||
|
|
||||||
oldTransportProtocols = Config.variable("sip_transports")
|
if (isLoaded) return else isLoaded = true
|
||||||
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(' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
autoStart.value = Config.variable("auto_start") == "yes"
|
autoStart.value = Config.variable("auto_start") == "yes"
|
||||||
|
|
||||||
@ -65,9 +50,9 @@ class SettingsViewModel: ViewModel() {
|
|||||||
mutableIntStateOf(familyValues.indexOf(Config.variable("net_af").lowercase()))
|
mutableIntStateOf(familyValues.indexOf(Config.variable("net_af").lowercase()))
|
||||||
addressFamily.value = familyValues[itemPosition.intValue]
|
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()
|
tlsCertificateFile.value = File(BaresipService.filesPath + "/cert.pem").exists()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user