Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nathan OBrian
Nebulo
Commits
16425854
Commit
16425854
authored
Jun 05, 2021
by
Daniel Wolf
Browse files
Split wildcard rules into two (one for domain, one for all subdomains)
https://github.com/badmojr/1Hosts/pull/139
parent
8966f33c
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/RuleImportService.kt
View file @
16425854
...
@@ -292,8 +292,8 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -292,8 +292,8 @@ class RuleImportService : IntentService("RuleImportService") {
if
(
remainingMatcher
!=
null
)
{
if
(
remainingMatcher
!=
null
)
{
if
(
remainingMatcher
!!
.
reset
(
line
).
matches
())
{
if
(
remainingMatcher
!!
.
reset
(
line
).
matches
())
{
val
rule
=
processLine
(
remainingMatcher
!!
,
source
,
source
.
whitelistSource
)
val
rule
=
processLine
(
remainingMatcher
!!
,
source
,
source
.
whitelistSource
)
hostsOfRemainingMatcher
!!
.
add
(
rule
.
apply
{
hostsOfRemainingMatcher
!!
.
add
All
(
rule
.
onEach
{
stagingType
=
2
it
.
stagingType
=
2
})
})
if
(
lineCount
>
ruleCommitSize
)
{
if
(
lineCount
>
ruleCommitSize
)
{
ruleCount
+=
commitLines
(
parsers
)
ruleCount
+=
commitLines
(
parsers
)
...
@@ -306,8 +306,8 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -306,8 +306,8 @@ class RuleImportService : IntentService("RuleImportService") {
if
(
matcher
.
reset
(
line
).
matches
())
{
if
(
matcher
.
reset
(
line
).
matches
())
{
successfulMatches
+=
1
successfulMatches
+=
1
val
rule
=
processLine
(
matcher
,
source
,
source
.
whitelistSource
)
val
rule
=
processLine
(
matcher
,
source
,
source
.
whitelistSource
)
hosts
.
second
.
add
(
rule
.
apply
{
hosts
.
second
.
add
All
(
rule
.
onEach
{
stagingType
=
2
it
.
stagingType
=
2
})
})
if
(
lineCount
>
ruleCommitSize
)
{
if
(
lineCount
>
ruleCommitSize
)
{
ruleCount
+=
commitLines
(
parsers
)
ruleCount
+=
commitLines
(
parsers
)
...
@@ -362,7 +362,7 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -362,7 +362,7 @@ class RuleImportService : IntentService("RuleImportService") {
}
}
private
val
wwwRegex
=
Regex
(
"^www\\."
)
private
val
wwwRegex
=
Regex
(
"^www\\."
)
private
fun
processLine
(
matcher
:
Matcher
,
source
:
HostSource
,
isWhitelist
:
Boolean
):
DnsRule
{
private
fun
processLine
(
matcher
:
Matcher
,
source
:
HostSource
,
isWhitelist
:
Boolean
):
Set
<
DnsRule
>
{
val
defaultTargetV4
=
if
(
isWhitelist
)
""
else
"0"
val
defaultTargetV4
=
if
(
isWhitelist
)
""
else
"0"
val
defaultTargetV6
=
if
(
isWhitelist
)
""
else
"1"
val
defaultTargetV6
=
if
(
isWhitelist
)
""
else
"1"
when
{
when
{
...
@@ -387,7 +387,15 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -387,7 +387,15 @@ class RuleImportService : IntentService("RuleImportService") {
matcher
==
hostsMatcher
->
{
matcher
==
hostsMatcher
->
{
return
if
(
isWhitelist
)
{
return
if
(
isWhitelist
)
{
val
host
=
matcher
.
group
(
2
)
!!
.
replace
(
wwwRegex
,
""
)
val
host
=
matcher
.
group
(
2
)
!!
.
replace
(
wwwRegex
,
""
)
DnsRule
(
Record
.
TYPE
.
ANY
,
host
,
defaultTargetV4
,
defaultTargetV6
,
importedFrom
=
source
.
id
)
setOf
(
DnsRule
(
Record
.
TYPE
.
ANY
,
host
,
defaultTargetV4
,
defaultTargetV6
,
importedFrom
=
source
.
id
)
)
}
else
{
}
else
{
var
target
=
matcher
.
group
(
1
)
!!
var
target
=
matcher
.
group
(
1
)
!!
val
type
=
if
(
target
.
contains
(
":"
))
Record
.
TYPE
.
AAAA
else
Record
.
TYPE
.
A
val
type
=
if
(
target
.
contains
(
":"
))
Record
.
TYPE
.
AAAA
else
Record
.
TYPE
.
A
...
@@ -414,21 +422,37 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -414,21 +422,37 @@ class RuleImportService : IntentService("RuleImportService") {
targetV6
:
String
?
=
null
,
targetV6
:
String
?
=
null
,
type
:
Record
.
TYPE
,
type
:
Record
.
TYPE
,
source
:
HostSource
source
:
HostSource
):
DnsRule
{
):
Set
<
DnsRule
>
{
var
isWildcard
=
false
var
isWildcard
=
false
val
alteredHost
=
host
.
let
{
val
alteredHost
:
Set
<
String
>
=
host
.
let
{
if
(
it
.
contains
(
"*"
))
{
if
(
it
.
contains
(
"*"
))
{
isWildcard
=
true
isWildcard
=
true
if
(
source
.
isFileSource
)
{
if
(
source
.
isFileSource
)
{
it
.
replace
(
leadingWildcardRegex
,
"**"
).
replace
(
"**"
,
"%%"
).
replace
(
"*"
,
"%"
)
setOf
(
.
replace
(
wildcardNormalisationRegex
,
"**"
)
it
.
replace
(
"**"
,
"%%"
).
replace
(
"*"
,
"%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
}
else
{
}
else
{
it
.
replace
(
leadingWildcardRegex
,
"**"
).
replace
(
"**"
,
"%%"
).
replace
(
"*"
,
"%%"
)
if
(
it
.
startsWith
(
"*."
))
{
.
replace
(
wildcardNormalisationRegex
,
"**"
)
setOf
(
it
.
replace
(
leadingWildcardRegex
,
""
),
it
.
replace
(
leadingWildcardRegex
,
"**."
).
replace
(
"**"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
}
else
{
setOf
(
it
.
replace
(
"**"
,
"%%"
)
.
replace
(
"*"
,
"%%"
)
.
replace
(
wildcardNormalisationRegex
,
"**"
)
)
}
}
}
}
else
it
}
else
setOf
(
it
)
}
}
return
DnsRule
(
type
,
alteredHost
,
target
,
targetV6
,
source
.
id
,
isWildcard
)
return
alteredHost
.
map
{
DnsRule
(
type
,
it
,
target
,
targetV6
,
source
.
id
,
isWildcard
)
}.
toSet
()
}
}
override
fun
onDestroy
()
{
override
fun
onDestroy
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment