- Use net_set_address API function to set IPv6 address.

This commit is contained in:
Juha Heinanen
2019-11-03 11:46:17 +02:00
parent a47ca666f4
commit 91717628f9
6 changed files with 109 additions and 58 deletions
@@ -11,84 +11,78 @@ object Config {
private var config = String(Utils.getFileContents(configPath)!!, StandardCharsets.ISO_8859_1)
fun initialize(dnsServers: List<InetAddress>) {
Log.d("Baresip", "Config is '$config'")
var write = false
if (!config.contains("zrtp_hash")) {
config = "${config}zrtp_hash yes\n"
write = true
}
if (!config.contains(Regex("ausrc_format s16"))) {
config = "${config}ausrc_format s16\nauplay_format s16\nauenc_format s16\naudec_format s16\nmodule webrtc_aec.so\n"
write = true
}
if (config.contains(Regex("#module_app[ ]+mwi.so"))) {
config = config.replace(Regex("#module_app[ ]+mwi.so"),
"module_app mwi.so")
write = true
}
if (!config.contains("opus_application")) {
config = "${config}opus_application voip\n"
write = true
}
if (!config.contains("opus_samplerate")) {
config = "${config}opus_samplerate 16000\n"
val accountsPath = BaresipService.filesPath + "/accounts"
var accounts = String(Utils.getFileContents(accountsPath)!!, StandardCharsets.ISO_8859_1)
accounts = accounts.replace("opus/48000/1", "opus/16000/1")
Utils.putFileContents(accountsPath, accounts.toByteArray())
write = true
}
if (!config.contains("opus_stereo")) {
config = "${config}opus_stereo no\n"
write = true
}
if (!config.contains("opus_sprop_stereo")) {
config = "${config}opus_sprop_stereo no\n"
write = true
}
if (!config.contains("log_level")) {
config = "${config}log_level 2\n"
Api.log_level_set(2)
Log.logLevel = Log.LogLevel.WARN
write = true
} else {
val ll = variable("log_level")[0].toInt()
Api.log_level_set(ll)
Log.logLevelSet(ll)
}
val preferIpv6 = variable("prefer_ipv6")
if (preferIpv6.size > 0) {
removeVariable("prefer_ipv6")
config = "net_prefer_ipv6 ${preferIpv6[0]}\n${config}"
write = true
val preferIpV6 = variable("prefer_ipv6")
if (preferIpV6.size == 0) {
BaresipService.preferIpV6 = false
} else {
if (!config.contains("net_prefer_ipv6")) {
config = "net_prefer_ipv6 no\n${config}"
write = true
}
BaresipService.preferIpV6 = preferIpV6[0] == "yes"
}
if (!config.contains("call_volume")) {
config = "${config}call_volume 0\n"
write = true
} 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 '$config'")
Utils.putFileContents(configPath, config.toByteArray())
}
Log.e("Baresip", "Initialized config to '$config'")
Utils.putFileContents(configPath, config.toByteArray())
}
fun variable(name: String): ArrayList<String> {
@@ -148,4 +142,10 @@ object Config {
}
return Api.net_use_nameserver(servers)
}
fun updateNetAddress(ipAddress: String, prefer: Boolean): Int {
return Api.net_set_address(ipAddress, prefer)
}
}