- fixed adding of new contacts
- improved checking of uris
This commit is contained in:
@@ -186,7 +186,7 @@ class AccountActivity : AppCompatActivity() {
|
|||||||
if (ob != acc.outbound) {
|
if (ob != acc.outbound) {
|
||||||
val outbound = ArrayList<String>()
|
val outbound = ArrayList<String>()
|
||||||
for (i in ob.indices) {
|
for (i in ob.indices) {
|
||||||
if ((ob[i] == "") || Api.uri_decode(ob[i])) {
|
if ((ob[i] == "") || Utils.checkOutboundUri(ob[i])) {
|
||||||
if (account_set_outbound(acc.accp, ob[i], i) == 0) {
|
if (account_set_outbound(acc.accp, ob[i], i) == 0) {
|
||||||
if (ob[i] != "")
|
if (ob[i] != "")
|
||||||
outbound.add(account_outbound(acc.accp, i))
|
outbound.add(account_outbound(acc.accp, i))
|
||||||
@@ -196,7 +196,7 @@ class AccountActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Utils.alertView(this, "Notice",
|
Utils.alertView(this, "Notice",
|
||||||
"Invalid Outbound Proxy: ${ob[i]}")
|
"Invalid Proxy Server URI: ${ob[i]}")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ class AccountsActivity : AppCompatActivity() {
|
|||||||
addAccountButton.setOnClickListener{
|
addAccountButton.setOnClickListener{
|
||||||
var aor = newAorView.text.toString().trim()
|
var aor = newAorView.text.toString().trim()
|
||||||
if (!aor.startsWith("sip:")) aor = "sip:$aor"
|
if (!aor.startsWith("sip:")) aor = "sip:$aor"
|
||||||
if (!checkSipUri(aor)) {
|
if (!Utils.checkAorUri(aor)) {
|
||||||
Log.e("Baresip", "Invalid SIP URI $aor")
|
Log.e("Baresip", "Invalid SIP Address of Record $aor")
|
||||||
Utils.alertView(this, "Notice",
|
Utils.alertView(this, "Notice",
|
||||||
"Invalid SIP URI: $aor")
|
"Invalid SIP Address of Record: $aor")
|
||||||
} else if (Account.exists(MainActivity.uas, aor)) {
|
} else if (Account.exists(MainActivity.uas, aor)) {
|
||||||
Log.e("Baresip", "Account $aor already exists")
|
Log.e("Baresip", "Account $aor already exists")
|
||||||
} else {
|
} else {
|
||||||
@@ -75,15 +75,6 @@ class AccountsActivity : AppCompatActivity() {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkSipUri(uri: String): Boolean {
|
|
||||||
if (!uri.startsWith("sip:")) return false
|
|
||||||
val userDomain = uri.replace("sip:", "").split("@")
|
|
||||||
if (userDomain.size != 2) return false
|
|
||||||
if (!Utils.checkUserID(userDomain[0]) && !Utils.checkTelNo(userDomain[0]))
|
|
||||||
return false
|
|
||||||
return Utils.checkDomain(userDomain[1]) || Utils.checkIP(userDomain[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
var accounts = ArrayList<AccountRow>()
|
var accounts = ArrayList<AccountRow>()
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
uriView = findViewById(R.id.Uri) as EditText
|
uriView = findViewById(R.id.Uri) as EditText
|
||||||
|
|
||||||
val uri = intent.extras.getString("uri")
|
val uri = intent.extras.getString("uri")
|
||||||
if (intent.extras.getBoolean("new")) {
|
new = intent.extras.getBoolean("new")
|
||||||
|
|
||||||
|
if (new) {
|
||||||
setTitle("New Contact")
|
setTitle("New Contact")
|
||||||
nameView.setText("")
|
nameView.setText("")
|
||||||
nameView.hint = "Contact name"
|
nameView.hint = "Contact name"
|
||||||
@@ -70,7 +72,7 @@ class ContactActivity : AppCompatActivity() {
|
|||||||
var newUri = uriView.text.toString().trim()
|
var newUri = uriView.text.toString().trim()
|
||||||
if (!newUri.startsWith("<")) {
|
if (!newUri.startsWith("<")) {
|
||||||
if (!newUri.startsWith("sip:")) newUri = "sip:$newUri"
|
if (!newUri.startsWith("sip:")) newUri = "sip:$newUri"
|
||||||
if (!Utils.checkUri(newUri)) {
|
if (!Utils.checkSipUri(newUri)) {
|
||||||
Utils.alertView(this, "Notice","Invalid contact URI: $newUri")
|
Utils.alertView(this, "Notice","Invalid contact URI: $newUri")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,12 +240,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
.trim()
|
.trim()
|
||||||
if (calleeText.length > 0) {
|
if (calleeText.length > 0) {
|
||||||
var uri = ContactsActivity.findContactURI(calleeText)
|
var uri = ContactsActivity.findContactURI(calleeText)
|
||||||
if (!uri.startsWith("sip:")) uri = "sip:$uri"
|
if (!uri.startsWith("sip:")) {
|
||||||
if (!uri.contains("@")) {
|
uri = "sip:$uri"
|
||||||
val host = aor.substring(aor.indexOf("@") + 1)
|
if (!uri.contains("@")) {
|
||||||
uri = "$uri@$host"
|
val host = aor.substring(aor.indexOf("@") + 1)
|
||||||
|
uri = "$uri@$host"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
call(ua, uri)
|
if (!Utils.checkSipUri(uri))
|
||||||
|
Utils.alertView(this,"Notice",
|
||||||
|
"Invalid SIP URI '$uri'")
|
||||||
|
else
|
||||||
|
call(ua, uri)
|
||||||
} else {
|
} else {
|
||||||
val latest = CallHistory.aorLatestHistory(history, aor)
|
val latest = CallHistory.aorLatestHistory(history, aor)
|
||||||
if (latest != null)
|
if (latest != null)
|
||||||
@@ -344,7 +350,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Toast.makeText(applicationContext,
|
Toast.makeText(applicationContext,
|
||||||
"Baresip has stopped! Check your network connectivity.",
|
"Baresip has stopped! Check your network connectivity.",
|
||||||
Toast.LENGTH_SHORT).show()
|
Toast.LENGTH_SHORT).show()
|
||||||
finish()
|
// finish()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val uap = params[0]
|
val uap = params[0]
|
||||||
|
|||||||
@@ -121,12 +121,53 @@ object Utils {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun checkUri(uri: String): Boolean {
|
fun checkPort(p: String) : Boolean {
|
||||||
|
val number = p.toIntOrNull()
|
||||||
|
if (number == null) return false
|
||||||
|
return (number > 0) and (number < 65536)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkHostPort(hp: String) : Boolean {
|
||||||
|
val parts = hp.split(":")
|
||||||
|
if (parts.size == 1) return checkIP(parts[0]) || checkDomain(parts[0])
|
||||||
|
return checkPort(parts[1]) && (checkIP(parts[0]) || checkDomain(parts[0]))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkParams(p: String) : Boolean {
|
||||||
|
/* todo: proper check */
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkHostPortParams(hpp: String) : Boolean {
|
||||||
|
val restParams = hpp.split(";", limit = 2)
|
||||||
|
if (restParams.size == 1)
|
||||||
|
return checkHostPort(restParams[0])
|
||||||
|
else
|
||||||
|
return checkHostPort(restParams[0]) && checkParams(restParams[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkSipUri(uri: String): Boolean {
|
||||||
if (!uri.startsWith("sip:")) return false
|
if (!uri.startsWith("sip:")) return false
|
||||||
val parts = uri.substring(4).split("@")
|
val userRest = uri.substring(4).split("@")
|
||||||
val hostParams = parts[1].split(";", limit = 2)
|
if (userRest.size == 1) {
|
||||||
// todo: check also possible params
|
return checkHostPortParams(userRest[0])
|
||||||
return checkUriUser(parts[0]) && (checkDomain(hostParams[0]) || checkIP(hostParams[0]))
|
} else if (userRest.size == 2) {
|
||||||
|
return checkUriUser(userRest[0]) && checkHostPortParams(userRest[1])
|
||||||
|
} else
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkAorUri(uri: String): Boolean {
|
||||||
|
if (!uri.startsWith("sip:")) return false
|
||||||
|
val userDomain = uri.replace("sip:", "").split("@")
|
||||||
|
if (userDomain.size != 2) return false
|
||||||
|
if (!checkUserID(userDomain[0]) && !checkTelNo(userDomain[0])) return false
|
||||||
|
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 {
|
fun checkPrintASCII(s: String): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user