Commit 8f9d8391 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Look for the host with www. removed before searching for an exact match (the...

Look for the host with www. removed before searching for an exact match (the logic treats www.example.com and example.com as the same host)

Fixes #251
parent 38496df5
......@@ -165,30 +165,39 @@ class QueryLogDetailFragment : Fragment() {
if(query.responseSource == QueryListener.Source.LOCALRESOLVER) {
hostSourceWrap.visibility = View.VISIBLE
hostSourceFetchJob = GlobalScope.launch(Dispatchers.IO) {
val sourceRule = getDatabase().dnsRuleDao().findRuleTargetEntity(query.name, query.type, true)
?: getDatabase().dnsRuleDao().findPossibleWildcardRuleTarget(query.name, query. type,
useUserRules = true,
includeWhitelistEntries = false,
includeNonWhitelistEntries = true
).firstOrNull {
DnsRuleDialog.databaseHostToMatcher(it.host).reset(query.name).matches()
}
val text = if (sourceRule != null) {
if(sourceRule.importedFrom == null) {
getString(R.string.windows_querylogging_hostsource__user)
} else {
getDatabase().hostSourceDao().findById(sourceRule.importedFrom)?.name ?: getString(R.string.windows_querylogging_hostsource__unknown)
}
} else {
getString(R.string.windows_querylogging_hostsource__unknown)
}
if(hostSourceFetchJob?.isCancelled == false) launch(Dispatchers.Main) {
hostSource.text = text
}
}
showRuleSource(query)
} else hostSourceWrap.visibility = View.GONE
}
}
private fun showRuleSource(query:DnsQuery) {
hostSourceFetchJob = GlobalScope.launch(Dispatchers.IO) {
val sourceRule = if(query.name.startsWith("www", ignoreCase = true)) {
getDatabase().dnsRuleDao().findRuleTargetEntity(query.name.replaceFirst("www.", ""), query.type, true)
?: getDatabase().dnsRuleDao().findRuleTargetEntity(query.name, query.type, true)
} else {
getDatabase().dnsRuleDao().findRuleTargetEntity(query.name, query.type, true)
} ?: getDatabase().dnsRuleDao().findPossibleWildcardRuleTarget(
query.name, query.type,
useUserRules = true,
includeWhitelistEntries = false,
includeNonWhitelistEntries = true
).firstOrNull {
DnsRuleDialog.databaseHostToMatcher(it.host).reset(query.name).matches()
}
val text = if (sourceRule != null) {
if (sourceRule.importedFrom == null) {
getString(R.string.windows_querylogging_hostsource__user)
} else {
getDatabase().hostSourceDao().findById(sourceRule.importedFrom)?.name
?: getString(R.string.windows_querylogging_hostsource__unknown)
}
} else {
getString(R.string.windows_querylogging_hostsource__unknown)
}
if (hostSourceFetchJob?.isCancelled == false) launch(Dispatchers.Main) {
hostSource.text = text
}
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment