- By default, obtain DNS server addresses dynamically from the system.
This commit is contained in:
@@ -2,6 +2,7 @@ package com.tutpro.baresip
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
import java.net.InetAddress
|
||||
|
||||
object Config {
|
||||
|
||||
@@ -9,7 +10,7 @@ object Config {
|
||||
private val file = File(path)
|
||||
private var config = Utils.getFileContents(file)
|
||||
|
||||
fun initialize() {
|
||||
fun initialize(dnsServers: List<InetAddress>) {
|
||||
var write = false
|
||||
if (!config.contains("zrtp_hash")) {
|
||||
config = "${config}zrtp_hash yes\n"
|
||||
@@ -52,6 +53,17 @@ object Config {
|
||||
} else {
|
||||
BaresipService.callVolume = variable("call_volume")[0].toInt()
|
||||
}
|
||||
if (!config.contains("dyn_dns")) {
|
||||
config = "${config}dyn_dns no\n"
|
||||
write = true
|
||||
} else {
|
||||
if (config.contains(Regex("dyn_dns[ ]+yes"))) {
|
||||
for (dnsServer in dnsServers)
|
||||
config = "${config}dns_server ${dnsServer.hostAddress}:53\n"
|
||||
BaresipService.dynDns = true
|
||||
write = true
|
||||
}
|
||||
}
|
||||
if (write) {
|
||||
Log.e("Baresip", "Writing '$config'")
|
||||
Utils.putFileContents(file, config)
|
||||
@@ -59,8 +71,8 @@ object Config {
|
||||
}
|
||||
|
||||
fun variable(name: String): ArrayList<String> {
|
||||
val lines = config.split("\n")
|
||||
val result = ArrayList<String>()
|
||||
val lines = config.split("\n")
|
||||
for (line in lines) {
|
||||
if (line.startsWith(name))
|
||||
result.add((line.substring(name.length).trim()).split("# \t")[0])
|
||||
@@ -69,7 +81,7 @@ object Config {
|
||||
}
|
||||
|
||||
fun add(variable: String, value: String) {
|
||||
config += "\n$variable $value\n"
|
||||
config += "$variable $value\n"
|
||||
}
|
||||
|
||||
fun remove(variable: String) {
|
||||
@@ -87,8 +99,29 @@ object Config {
|
||||
}
|
||||
|
||||
fun save() {
|
||||
var result = ""
|
||||
for (line in config.split("\n"))
|
||||
if (line.length > 0)
|
||||
result = result + line + '\n'
|
||||
config = result
|
||||
Utils.putFileContents(file, config)
|
||||
Log.d("Baresip", "New config '$config'")
|
||||
Log.d("Baresip", "New config '$result'")
|
||||
// Api.reload_config()
|
||||
}
|
||||
}
|
||||
|
||||
fun updateDnsServers(dnsServers: List<InetAddress>): Int {
|
||||
var servers = ""
|
||||
for (dnsServer in dnsServers) {
|
||||
var address = dnsServer.hostAddress
|
||||
if (Utils.checkIpV4(address))
|
||||
address = "${address}:53"
|
||||
else
|
||||
address = "[${address}]:53"
|
||||
if (servers == "")
|
||||
servers = address
|
||||
else
|
||||
servers = "${servers},${address}"
|
||||
}
|
||||
return Api.dnsc_srv_set(servers)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user