diff --git a/app/src/main/cpp/baresip.c b/app/src/main/cpp/baresip.c
index 8957b5de..94b045ef 100644
--- a/app/src/main/cpp/baresip.c
+++ b/app/src/main/cpp/baresip.c
@@ -941,12 +941,21 @@ Java_com_tutpro_baresip_Api_account_1stun_1uri(JNIEnv *env, jobject thiz, jstrin
const struct stun_uri *stun_uri = account_stun_uri(acc);
if (stun_uri) {
char uri_str[256];
- if (stun_uri->port != 0)
- sprintf(uri_str, "%s:%s:%d", stunuri_scheme_name(stun_uri->scheme),
- stun_uri->host, stun_uri->port);
- else
- sprintf(uri_str, "%s:%s", stunuri_scheme_name(stun_uri->scheme),
- stun_uri->host);
+ if (stun_uri->port != 0) {
+ if (stun_uri->proto == IPPROTO_TCP)
+ sprintf(uri_str, "%s:%s:%d?transport=tcp",
+ stunuri_scheme_name(stun_uri->scheme), stun_uri->host, stun_uri->port);
+ else
+ sprintf(uri_str, "%s:%s:%d",
+ stunuri_scheme_name(stun_uri->scheme), stun_uri->host, stun_uri->port);
+ } else {
+ if (stun_uri->proto == IPPROTO_TCP)
+ sprintf(uri_str, "%s:%s?transport=tcp",
+ stunuri_scheme_name(stun_uri->scheme), stun_uri->host);
+ else
+ sprintf(uri_str, "%s:%s",
+ stunuri_scheme_name(stun_uri->scheme), stun_uri->host);
+ }
return (*env)->NewStringUTF(env, uri_str);
}
}
diff --git a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt
index 5e684a54..1d253aa6 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/AccountActivity.kt
@@ -481,7 +481,8 @@ class AccountActivity : AppCompatActivity() {
if (((mediaNat == "stun") || (mediaNat == "ice")) && (newStunServer == ""))
newStunServer = resources.getString(R.string.stun_server_default)
if (!Utils.checkStunUri(newStunServer) ||
- ((mediaNat == "turn") && !newStunServer.startsWith("turn:"))) {
+ (mediaNat == "turn" &&
+ newStunServer.substringBefore(":") !in setOf("turn", "turns"))) {
Utils.alertView(this, getString(R.string.notice),
String.format(getString(R.string.invalid_stun_server), newStunServer))
return false
diff --git a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt
index 2690f677..3397a1ac 100644
--- a/app/src/main/kotlin/com/tutpro/baresip/Utils.kt
+++ b/app/src/main/kotlin/com/tutpro/baresip/Utils.kt
@@ -142,10 +142,17 @@ object Utils {
params[0] in arrayOf("transport=udp", "transport=tcp", "transport=tls"))
}
+ private fun checkTransport(transport: String, transports: Set): Boolean {
+ return transport.split("=")[0] == "transport" &&
+ transport.split("=")[1].lowercase() in transports
+ }
+
fun checkStunUri(uri: String): Boolean {
- if (!uri.startsWith("stun:") && !uri.startsWith("turn:"))
+ if (uri.substringBefore(":").lowercase() !in setOf("stun", "stuns", "turn", "turns"))
return false
- return checkHostPort(uri.substringAfter(":"))
+ return checkHostPort(uri.substringAfter(":").substringBefore("?")) &&
+ (uri.indexOf("?") == -1 ||
+ checkTransport(uri.substringAfter("?"), setOf("udp", "tcp")))
}
fun isE164Number(no: String): Boolean {
@@ -213,12 +220,11 @@ object Utils {
}
private fun checkParam(param: String): Boolean {
+ /* Todo: do proper check */
val nameValue = param.split("=")
if (nameValue.size == 1)
- /* Todo: do proper check */
return true
if (nameValue.size == 2) {
- /* Todo: do proper check */
if ((nameValue[0] == "transport") &&
setOf("udp", "tcp", "tls", "wss").contains(nameValue[1].lowercase()))
return true
diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml
index 84bd4fa3..85679a26 100644
--- a/app/src/main/res/values-fi/strings.xml
+++ b/app/src/main/res/values-fi/strings.xml
@@ -167,8 +167,8 @@
for NAT, RFC 5389) ja ICE (Interactive Connectivity Establishment, RFC 5245).
STUN/TURN-palvelin
- STUN/TURN-palvelimen muotoa \'kaava:palvelin[:portti]\'
- oleva URI, missä kaava on \'stun\' tai \'turn\'. Oletus STUN-palvelin
+ STUN/TURN-palvelimen muotoa \'kaava:palvelin[:portti][?transport=udp|tcp]\'
+ oleva URI, missä kaava on \'stun\', \'stuns\', \'turn\' tai \'turns\'. Oletus STUN-palvelin
STUN- ja ICE-protokollille on \'stun:stun.l.google.com:19302\', joka osoittaa Google:n
julkiseen STUN-palvelimeen. TURN-palvelimella ei ole oletusarvoa.
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 632f95a3..e3cb7366 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -151,10 +151,10 @@
Establishment, RFC 5245).
STUN/TURN Server
- A STUN/TURN Server URI of form scheme:host[:port], where scheme
- is \'stun\' or \'turn\'. Factory default STUN Server for STUN and
- ICE protocols is \'stun:stun.l.google.com:19302\' pointing to public Google STUN server.
- There is no factory default TURN server.
+ A STUN/TURN Server URI of form scheme:host[:port][?transport=udp|tcp],
+ where scheme is \'stun\', \'stuns\', \'turn\', or \'turns\'. Factory default STUN Server
+ for STUN and ICE protocols is \'stun:stun.l.google.com:19302\' pointing to public Google
+ STUN server. There is no factory default TURN server.
STUN/TURN Server URI
Invalid STUN/TURN Server URI \'%1$s\'