- 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) {
|
||||
val outbound = ArrayList<String>()
|
||||
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 (ob[i] != "")
|
||||
outbound.add(account_outbound(acc.accp, i))
|
||||
@ -196,7 +196,7 @@ class AccountActivity : AppCompatActivity() {
|
||||
}
|
||||
} else {
|
||||
Utils.alertView(this, "Notice",
|
||||
"Invalid Outbound Proxy: ${ob[i]}")
|
||||
"Invalid Proxy Server URI: ${ob[i]}")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,10 +31,10 @@ class AccountsActivity : AppCompatActivity() {
|
||||
addAccountButton.setOnClickListener{
|
||||
var aor = newAorView.text.toString().trim()
|
||||
if (!aor.startsWith("sip:")) aor = "sip:$aor"
|
||||
if (!checkSipUri(aor)) {
|
||||
Log.e("Baresip", "Invalid SIP URI $aor")
|
||||
if (!Utils.checkAorUri(aor)) {
|
||||
Log.e("Baresip", "Invalid SIP Address of Record $aor")
|
||||
Utils.alertView(this, "Notice",
|
||||
"Invalid SIP URI: $aor")
|
||||
"Invalid SIP Address of Record: $aor")
|
||||
} else if (Account.exists(MainActivity.uas, aor)) {
|
||||
Log.e("Baresip", "Account $aor already exists")
|
||||
} else {
|
||||
@ -75,15 +75,6 @@ class AccountsActivity : AppCompatActivity() {
|
||||
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 {
|
||||
|
||||
var accounts = ArrayList<AccountRow>()
|
||||
|
||||
@ -21,7 +21,9 @@ class ContactActivity : AppCompatActivity() {
|
||||
uriView = findViewById(R.id.Uri) as EditText
|
||||
|
||||
val uri = intent.extras.getString("uri")
|
||||
if (intent.extras.getBoolean("new")) {
|
||||
new = intent.extras.getBoolean("new")
|
||||
|
||||
if (new) {
|
||||
setTitle("New Contact")
|
||||
nameView.setText("")
|
||||
nameView.hint = "Contact name"
|
||||
@ -70,7 +72,7 @@ class ContactActivity : AppCompatActivity() {
|
||||
var newUri = uriView.text.toString().trim()
|
||||
if (!newUri.startsWith("<")) {
|
||||
if (!newUri.startsWith("sip:")) newUri = "sip:$newUri"
|
||||
if (!Utils.checkUri(newUri)) {
|
||||
if (!Utils.checkSipUri(newUri)) {
|
||||
Utils.alertView(this, "Notice","Invalid contact URI: $newUri")
|
||||
return false
|
||||
}
|
||||
|
||||
@ -240,12 +240,18 @@ class MainActivity : AppCompatActivity() {
|
||||
.trim()
|
||||
if (calleeText.length > 0) {
|
||||
var uri = ContactsActivity.findContactURI(calleeText)
|
||||
if (!uri.startsWith("sip:")) uri = "sip:$uri"
|
||||
if (!uri.contains("@")) {
|
||||
val host = aor.substring(aor.indexOf("@") + 1)
|
||||
uri = "$uri@$host"
|
||||
if (!uri.startsWith("sip:")) {
|
||||
uri = "sip:$uri"
|
||||
if (!uri.contains("@")) {
|
||||
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 {
|
||||
val latest = CallHistory.aorLatestHistory(history, aor)
|
||||
if (latest != null)
|
||||
@ -344,7 +350,7 @@ class MainActivity : AppCompatActivity() {
|
||||
Toast.makeText(applicationContext,
|
||||
"Baresip has stopped! Check your network connectivity.",
|
||||
Toast.LENGTH_SHORT).show()
|
||||
finish()
|
||||
// finish()
|
||||
return
|
||||
}
|
||||
val uap = params[0]
|
||||
|
||||
@ -121,12 +121,53 @@ object Utils {
|
||||
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
|
||||
val parts = uri.substring(4).split("@")
|
||||
val hostParams = parts[1].split(";", limit = 2)
|
||||
// todo: check also possible params
|
||||
return checkUriUser(parts[0]) && (checkDomain(hostParams[0]) || checkIP(hostParams[0]))
|
||||
val userRest = uri.substring(4).split("@")
|
||||
if (userRest.size == 1) {
|
||||
return checkHostPortParams(userRest[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 {
|
||||
|
||||
Reference in New Issue
Block a user