From 4c0dd0e628b42d3ab7ac14c381650dcbf865edc1 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Wed, 24 Apr 2019 12:53:10 +0300 Subject: [PATCH] - added support for IPv6 (not tested due to lack of IPv6 network) - new "Prefer IPv6" config option - IPv6 address is allowed in DNS Server and Outbound Proxy - added log_level config file variable - added Google IPv6 DNS server address --- app/src/main/assets/config | 3 ++ app/src/main/cpp/baresip.c | 8 ++++ .../com/tutpro/baresip/AccountActivity.kt | 7 +++- .../com/tutpro/baresip/BaresipService.kt | 6 ++- .../com/tutpro/baresip/ConfigActivity.kt | 22 ++++++++++- .../main/kotlin/com/tutpro/baresip/Utils.kt | 5 --- app/src/main/res/layout/activity_config.xml | 39 ++++++++++++++----- app/src/main/res/values/strings.xml | 10 ++++- 8 files changed, 80 insertions(+), 20 deletions(-) diff --git a/app/src/main/assets/config b/app/src/main/assets/config index 7ca9accd..b24f8e26 100644 --- a/app/src/main/assets/config +++ b/app/src/main/assets/config @@ -1,4 +1,5 @@ auto_start no +log_level 2 poll_method epoll sip_trans_bsize 128 call_local_timeout 120 @@ -14,6 +15,8 @@ rtcp_mux no jitter_buffer_delay 5-10 rtp_stats no dns_server 8.8.8.8:53 +dns_server [2001:4860:4860::8888]:53 +prefer_ipv6 no module opus.so module g711.so module opensles.so diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c index 816e3432..599a8529 100644 --- a/app/src/main/cpp/baresip.c +++ b/app/src/main/cpp/baresip.c @@ -439,6 +439,14 @@ Java_com_tutpro_baresip_BaresipService_baresipStart(JNIEnv *env, jobject instanc if (err) goto out; + /* char debug_buf[2048]; + int l; + l = re_snprintf(&(debug_buf[0]), 2047, "%H", net_debug, baresip_network()); + if (l != -1) { + debug_buf[l] = '\0'; + LOGD("%s\n", debug_buf); + } */ + LOGI("running main loop ...\n"); err = re_main(signal_handler); diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt index 25be6867..6b451ddc 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt @@ -212,7 +212,7 @@ class AccountActivity : AppCompatActivity() { if (ob != acc.outbound) { val outbound = ArrayList() for (i in ob.indices) { - if ((ob[i] == "") || Utils.checkOutboundUri(ob[i])) { + if ((ob[i] == "") || checkOutboundUri(ob[i])) { if (account_set_outbound(acc.accp, ob[i], i) == 0) { if (ob[i] != "") outbound.add(account_outbound(acc.accp, i)) @@ -413,6 +413,11 @@ class AccountActivity : AppCompatActivity() { } } + private fun checkOutboundUri(uri: String): Boolean { + if (!uri.startsWith("sip:")) return false + return Utils.checkHostPortParams(uri.substring(4)) + } + private fun checkDisplayName(dn: String): Boolean { if (dn == "") return true val dnRegex = Regex("^([* .!%_`'~]|[+]|[-a-zA-Z0-9]){1,63}\$") diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 385dd7a5..f1945182 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -155,8 +155,12 @@ class BaresipService: Service() { Api.log_level_set(ll) Log.logLevelSet(ll) } + if (!contents.contains("prefer_ipv6")) { + contents = "prefer_ipv6 no\n${contents}" + write = true + } if (write) { - Log.d(LOG_TAG, "Writing $contents") + Log.d(LOG_TAG, "Writing '$contents'") Utils.putFileContents(file, contents) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt index 22ab2713..4006b15b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt @@ -15,12 +15,14 @@ class ConfigActivity : AppCompatActivity() { internal lateinit var configFile: File internal lateinit var autoStart: CheckBox + internal lateinit var preferIPv6: CheckBox internal lateinit var dnsServers: EditText internal lateinit var opusBitRate: EditText internal lateinit var iceLite: CheckBox internal lateinit var debug: CheckBox private var oldAutoStart = "" + private var oldPreferIPv6 = "" private var oldDnsServers = "" private var oldOpusBitrate = "" private var oldIceMode = "" @@ -47,6 +49,11 @@ class ConfigActivity : AppCompatActivity() { oldAutoStart = if (asCv.size == 0) "no" else asCv[0] autoStart.isChecked = oldAutoStart == "yes" + preferIPv6 = findViewById(R.id.PreferIPv6) as CheckBox + val piCv = Utils.getNameValue(config, "prefer_ipv6") + oldPreferIPv6 = if (piCv.size == 0) "no" else piCv[0] + preferIPv6.isChecked = oldPreferIPv6 == "yes" + dnsServers = findViewById(R.id.DnsServers) as EditText val dsCv = Utils.getNameValue(config, "dns_server") var dsTv = "" @@ -96,7 +103,16 @@ class ConfigActivity : AppCompatActivity() { restart = false } - val dnsServers = dnsServers.text.toString().trim() + var preferIPv6String = "no" + if (preferIPv6.isChecked) preferIPv6String = "yes" + if (oldPreferIPv6 != preferIPv6String) { + config = Utils.removeLinesStartingWithName(config, "prefer_ipv6") + config = "prefer_ipv6 $preferIPv6String\n$config" + save = true + restart = true + } + + val dnsServers = dnsServers.text.toString().trim().toLowerCase() if (dnsServers != oldDnsServers) { if (!checkDnsServers(dnsServers)) { Utils.alertView(this, "Notice", "Invalid DNS Servers: $dnsServers") @@ -148,6 +164,7 @@ class ConfigActivity : AppCompatActivity() { // Log.d("Baresip", "Config line $trimmedLine") newConfig += trimmedLine.split("#")[0] + "\n" } + Log.d("Baresip", "New config '$newConfig'") Utils.putFileContents(configFile, newConfig) // Api.reload_config() } @@ -172,6 +189,9 @@ class ConfigActivity : AppCompatActivity() { findViewById(R.id.AutoStartTitle) as TextView-> { Utils.alertView(this, "Start Automatically", getString(R.string.autoStart)) } + findViewById(R.id.PreferIPv6Title) as TextView-> { + Utils.alertView(this, "Prefer IPv6", getString(R.string.preferIPv6)) + } findViewById(R.id.DnsServersTitle) as TextView -> { Utils.alertView(this, "DNS Servers", getString(R.string.dnsServers)) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt index 36dc4daa..967b45fb 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt @@ -244,11 +244,6 @@ object Utils { return checkDomain(userDomain[1]) || checkIP(userDomain[1]) } - fun checkOutboundUri(uri: String): Boolean { - if (!uri.startsWith("sip:")) return false - return checkHostPortParams(uri.substring(4)) - } - fun checkPrintAscii(s: String): Boolean { if (s == "") return true return Regex("^[ -~]*\$").matches(s) diff --git a/app/src/main/res/layout/activity_config.xml b/app/src/main/res/layout/activity_config.xml index fcc8e545..580d20c1 100644 --- a/app/src/main/res/layout/activity_config.xml +++ b/app/src/main/res/layout/activity_config.xml @@ -47,7 +47,7 @@ android:layout_height="wrap_content" android:orientation="horizontal" > + android:text="Prefer IPv6" > - - + android:layout_gravity="end" + android:checked="false" > + + + + + + + SIP URI of one or two proxies that must be used when sending requests. If two is given, REGISTER requests are sent to both and other requests are sent to one that responds. If no outbound proxy is given, requests are sent based on - DNS NAPTR/SRV/A record lookup of callee URI hostpart.\nExample:\nsip:foo.com:5060;transport=tls + DNS NAPTR/SRV/A record lookup of callee URI hostpart. If hostpart of SIP URI is an IPv6 + address, the address must be written inside brackets [].\nExamples:\n + • sip:foo.com:5060;transport=tls\n + • sip:[2001:67c:223:777::10]:5060;transport=tcp If checked, registration is enabled and REGISTER requests are sent at 12 minute intervals. @@ -51,8 +54,11 @@ If checked, this account is selected when baresip is started. > If checked, baresip starts automatically after device (re)start. + Prefer IPv6 if both IPv4 and IPv6 are available. Comma separated list of DNS servers. Each DNS server is of form - server:port. Factory default value is \'8.8.8.8:53\' pointing to public Google DNS server. + \'server:port\'. If server is an IPv6 address, the address must be written inside brackets []. + Factory default value is \'8.8.8.8:53,[2001:4860:4860::8888]:53\' pointing to public Google + DNS servers. Average maximum bit rate used by Opus audio stream. Valid value are 6000-510000. Factory default is 28000. If checked, ICE Lite Mode is used.