Skip to content

Commit

Permalink
style: rule_set for dns
Browse files Browse the repository at this point in the history
  • Loading branch information
purofle committed Mar 3, 2024
1 parent 4c8d098 commit b46dbc8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fun buildConfig(
makeSingBoxRule(rule.ip.listByLineOrComma(), true)
}

if (rule_set != null) generateRuleSet(ruleSets)
if (rule_set != null) generateRuleSet(rule_set, ruleSets)

if (rule.port.isNotBlank()) {
port = mutableListOf<Int>()
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/moe/matsuri/nb4a/SingBoxOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -4418,8 +4418,7 @@ public static class DNSRule_DefaultOptions extends DNSRule {
// Generate note: Listable
public List<String> domain_regex;

// Generate note: Listable
public List<String> geosite;
public List<String> rule_set;

// Generate note: Listable
public List<String> source_ip_cidr;
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/moe/matsuri/nb4a/SingBoxOptionsUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ object SingBoxOptionsUtil {
}

fun SingBoxOptions.DNSRule_DefaultOptions.makeSingBoxRule(list: List<String>) {
geosite = mutableListOf<String>()
rule_set = mutableListOf<String>()
domain = mutableListOf<String>()
domain_suffix = mutableListOf<String>()
domain_regex = mutableListOf<String>()
domain_keyword = mutableListOf<String>()
list.forEach {
if (it.startsWith("geosite:")) {
geosite.plusAssign(it.removePrefix("geosite:"))
rule_set.plusAssign(it)
} else if (it.startsWith("full:")) {
domain.plusAssign(it.removePrefix("full:").lowercase())
} else if (it.startsWith("domain:")) {
Expand All @@ -51,20 +51,20 @@ fun SingBoxOptions.DNSRule_DefaultOptions.makeSingBoxRule(list: List<String>) {
domain.plusAssign(it.lowercase())
}
}
geosite?.removeIf { it.isNullOrBlank() }
rule_set?.removeIf { it.isNullOrBlank() }
domain?.removeIf { it.isNullOrBlank() }
domain_suffix?.removeIf { it.isNullOrBlank() }
domain_regex?.removeIf { it.isNullOrBlank() }
domain_keyword?.removeIf { it.isNullOrBlank() }
if (geosite?.isEmpty() == true) geosite = null
if (rule_set?.isEmpty() == true) rule_set = null
if (domain?.isEmpty() == true) domain = null
if (domain_suffix?.isEmpty() == true) domain_suffix = null
if (domain_regex?.isEmpty() == true) domain_regex = null
if (domain_keyword?.isEmpty() == true) domain_keyword = null
}

fun SingBoxOptions.DNSRule_DefaultOptions.checkEmpty(): Boolean {
if (geosite?.isNotEmpty() == true) return false
if (rule_set?.isNotEmpty() == true) return false
if (domain?.isNotEmpty() == true) return false
if (domain_suffix?.isNotEmpty() == true) return false
if (domain_regex?.isNotEmpty() == true) return false
Expand All @@ -73,8 +73,8 @@ fun SingBoxOptions.DNSRule_DefaultOptions.checkEmpty(): Boolean {
return true
}

fun SingBoxOptions.Rule_DefaultOptions.generateRuleSet(ruleSet: MutableList<RuleSet>) {
rule_set?.forEach {
fun generateRuleSet(ruleSetString: List<String>, ruleSet: MutableList<RuleSet>) {
ruleSetString.forEach {
when {
it.startsWith("geoip") -> {
val geoipPath = GeoipUtils.generateRuleSet(country = it.removePrefix("geoip:"))
Expand Down

0 comments on commit b46dbc8

Please sign in to comment.