Compare commits

...

16 Commits

Author SHA1 Message Date
MkQtS
714a061ba3 main.go: improve codes (#3366)
* main.go: improve codes

* main.go: add parseInclusion

- seprate from parseEntry
- not allow affiliation for inclusion
2026-03-18 15:58:47 +08:00
TripleA
5ff8142411 Update category-speedtest (#3365) 2026-03-18 00:01:38 +08:00
MkQtS
becbd7a8ad wordpress: add wordpress.net (#3364) 2026-03-16 19:05:25 +08:00
xchacha20-poly1305
cd2d66eb72 baidu: Add xdrtc.com (#3362) 2026-03-15 21:55:53 +08:00
MkQtS
4c4ad053ef nvidia: add nvidia.custhelp.com 2026-03-15 14:51:57 +08:00
MkQtS
6544f6d3a6 oracle: add custhelp.com 2026-03-15 14:51:57 +08:00
MkQtS
673a70c380 category-ai-!cn: add spicywriter.com (#3360) 2026-03-15 14:32:27 +08:00
TripleA
be078767c4 Update category-ip-geo-detect (#3359) 2026-03-15 14:21:52 +08:00
深鸣
15fde0da4b Add more cn domains (#3358) 2026-03-15 14:20:57 +08:00
pover0k
5dd4779425 nodeseek: add nodeget.com (#3357) 2026-03-15 14:16:38 +08:00
Mikhail
eeccde7239 kinopub: add ahc.ovh (#3353)
Add ahc.ovh entry as a sub domains mirror
2026-03-13 21:52:34 +08:00
Larin Sergey
235988ffe4 anthropic: add clau.de (#3350) 2026-03-12 15:14:55 +08:00
MkQtS
a45bf04e9b category-ai-!cn: add more domains (#3352) 2026-03-12 15:08:42 +08:00
MkQtS
f31764e263 annas-archive: add new domains (#3349)
listed in https://en.wikipedia.org/wiki/Anna's_Archive

close https://github.com/v2fly/domain-list-community/issues/3347
2026-03-11 21:45:55 +08:00
MkQtS
540b28d5e4 Add more cn domains (#3348)
* geolocation-cn: remove zsxq.com

already in category-social-media-cn

* category-dev-cn: add zuidaima.com

* geolocation-cn: remove zimuzu.io

not in cn and seems dead

* geolocation-cn: reorder zhaopin.com

* geolocation-cn: reorder airline domains

* geolocation-cn: reorder more airline domains

* geolocation-cn: add more airline domains

* sohu: add 56.com domains
2026-03-11 21:42:32 +08:00
MkQtS
9c06656430 Add more cn domains (#3346)
* geolocation-cn: remove zrblog.net

not in cn

* category-wiki-cn: add allhistory.com

* category-education-cn: add more domains

* netease: add yunxindns.com
2026-03-11 14:03:34 +08:00
19 changed files with 249 additions and 131 deletions

View File

@@ -1,5 +1,8 @@
annas-archive.gd
annas-archive.gl
annas-archive.in annas-archive.in
annas-archive.li annas-archive.li
annas-archive.org annas-archive.org
annas-archive.pk
annas-archive.pm annas-archive.pm
annas-archive.se annas-archive.se

View File

@@ -1,8 +1,9 @@
anthropic.com anthropic.com
clau.de
claude.ai claude.ai
claude.com claude.com
claudeusercontent.com
claudemcpclient.com claudemcpclient.com
claudeusercontent.com
# CDN # CDN
full:servd-anthropic-website.b-cdn.net full:servd-anthropic-website.b-cdn.net

View File

@@ -64,6 +64,7 @@ shifen.com
smartapps.cn smartapps.cn
tieba.com tieba.com
tiebaimg.com tiebaimg.com
xdrtc.com
xianfae.com xianfae.com
xiaodutv.com xiaodutv.com
yoojia.com yoojia.com

View File

@@ -30,6 +30,7 @@ clipdrop.co
jasper.ai jasper.ai
chutes.ai chutes.ai
clawhub.ai
copilot.microsoft.com copilot.microsoft.com
devin.ai devin.ai
diabrowser.com diabrowser.com
@@ -37,9 +38,12 @@ diabrowser.engineering
dify.ai dify.ai
duck.ai duck.ai
gateway.ai.cloudflare.com gateway.ai.cloudflare.com
h2o.ai
kiro.dev kiro.dev
lovart.ai lovart.ai
meta.ai meta.ai
mistral.ai mistral.ai
openart.ai openart.ai
openclaw.ai
openrouter.ai openrouter.ai
spicywriter.com

View File

@@ -25,3 +25,4 @@ jinrishici.com
openvela.com openvela.com
pingcode.com pingcode.com
tipdm.org tipdm.org
zuidaima.com

View File

@@ -10,6 +10,8 @@ include:shanbay
include:xueersi include:xueersi
include:yuanfudao include:yuanfudao
edu.cn
# 雨课堂 # 雨课堂
include:yuketang include:yuketang
## 雨豆课堂 ## 雨豆课堂
@@ -19,8 +21,6 @@ yushiyan.net
## 学堂在线 ## 学堂在线
xuetangx.com xuetangx.com
edu.cn
# 国家智慧教育公共服务平台 # 国家智慧教育公共服务平台
cbern.com.cn cbern.com.cn
smartedu.cn smartedu.cn
@@ -118,6 +118,11 @@ llscdn.com
llsserver.com llsserver.com
# 马哥教育 # 马哥教育
magedu.com magedu.com
# 墨墨背单词
maimemo.com
maimemostatus.com
# 墨墨记忆卡
markji.com
# CIS NanoMasters # CIS NanoMasters
neoscholar.com neoscholar.com
neoschool.com neoschool.com
@@ -127,6 +132,8 @@ oldboyedu.com
pigai.org pigai.org
# 公考知识库 # 公考知识库
saduck.top saduck.top
# 外研在线
unipus.cn
# 未来云校 # 未来云校
weilaiyunxiao.com weilaiyunxiao.com
# 北京嘉瑞新创教育咨询有限公司 # 北京嘉瑞新创教育咨询有限公司

View File

@@ -57,10 +57,14 @@ anitabi.cn
# 暴风影音 # 暴风影音
baofeng.com baofeng.com
baofeng.net baofeng.net
# 街机地图
bemanicn.com
# 布咕阅读 # 布咕阅读
bgwxc.com bgwxc.com
# B站空降助手 # B站空降助手
bsbsb.top bsbsb.top
# CdkeyNoGap
cdkeynogap.com
# 动漫之家 #703 # 动漫之家 #703
dmzj.com dmzj.com
muwai.com muwai.com

View File

@@ -131,6 +131,8 @@ wtfismyip.com
# Subdomains/internal api used for ip-geo-detect # Subdomains/internal api used for ip-geo-detect
full:checkip.amazonaws.com full:checkip.amazonaws.com
full:ipv4-check-perf.radar.cloudflare.com
full:ipv6-check-perf.radar.cloudflare.com
geoip.noc.gov.ru geoip.noc.gov.ru
ip.mail.ru ip.mail.ru
ip.nic.ru ip.nic.ru

View File

@@ -3,33 +3,62 @@ include:openspeedtest
cnspeedtest.cn @cn cnspeedtest.cn @cn
fast.com fast.com
fastspeedtest.com
linkmeter.net
measurementlab.net measurementlab.net
meter.net
nperf.com nperf.com
openspeedtest.ru
speed.cloudflare.com speed.cloudflare.com
speed.dler.io speed.dler.io
speed.ee
speed.hinet.net speed.hinet.net
speed.nccu.edu.tw speed.nccu.edu.tw
speed.neu6.edu.cn @cn speed.neu6.edu.cn @cn
speed.nju.edu.cn @cn
speed.nuaa.edu.cn @cn speed.nuaa.edu.cn @cn
speed.qlu.edu.cn @cn speed.qlu.edu.cn @cn
speed.ujs.edu.cn @cn speed.ujs.edu.cn @cn
speed6.ujs.edu.cn @cn
speed2.hinet.net speed2.hinet.net
speed5.ntu.edu.tw speed5.ntu.edu.tw
speed6.ujs.edu.cn @cn
speedcheck.org
speedgeo.net
speedof.me
speedtest.cesnet.cz
speedtest.ch
speedtest.citylink.pro
speedtest.cn @cn speedtest.cn @cn
speedtest.co.za
speedtest.de
speedtest.dno-it.ru
speedtest.frontier.com
speedtest.im speedtest.im
speedtest.mail.ru
speedtest.mfcyun.com @cn speedtest.mfcyun.com @cn
speedtest.net.in
speedtest.net.ua
speedtest.net.uk
speedtest.org
speedtest.rt.ru
speedtest.ru
speedtest.shaw.ca
speedtest.shu.edu.cn @cn speedtest.shu.edu.cn @cn
speedtest6.shu.edu.cn @cn speedtest.su
speedtest.uz
speedtest.volia.com
speedtest.xaut.edu.cn @cn speedtest.xaut.edu.cn @cn
speedtest.xfinity.com speedtest.xfinity.com
speedtestcustom.com speedtest.xyz
test.ustc.edu.cn @cn speedtest24.ru
test6.ustc.edu.cn @cn speedtest6.shu.edu.cn @cn
test.nju.edu.cn @cn test.nju.edu.cn @cn
test.ustc.edu.cn @cn
test6.nju.edu.cn @cn test6.nju.edu.cn @cn
speed.nju.edu.cn @cn test6.ustc.edu.cn @cn
testmy.net testmy.net
testmyspeed.com
testskorosti.ru
xnfz.seu.edu.cn @cn xnfz.seu.edu.cn @cn
full:hk-global-bgp.hkg.speedtest.yecaoyun.com @!cn full:hk-global-bgp.hkg.speedtest.yecaoyun.com @!cn

View File

@@ -1,3 +1,4 @@
allhistory.com
fgo.wiki fgo.wiki
jikipedia.com jikipedia.com
mbalib.com mbalib.com

View File

@@ -226,23 +226,65 @@ cma.cn
nmc.cn nmc.cn
# Public transportation # Public transportation
include:airchina # 中国国际航空 ## 中国国际航空
include:hainanairlines # 海南航空 include:airchina
## 海南航空
include:hainanairlines
## 长安航空
airchangan.com
## 桂林航空
airguilin.com
## 中国东方航空
ceair.com
## 春秋航空
ch.com
china-sss.com
springairlines.com
## 华夏航空
chinaexpressair.com
## 中国南方航空
csair.com
## 中国联合航空
flycua.com
## 广西北部湾航空
gxairlines.com
## 河北航空
hbhk.com.cn
## 首都航空
jdair.net
## 吉祥航空
juneyaoair.com
## 长龙航空
loongair.cn
## 祥鹏航空
luckyair.net
## 山东航空
sda.cn
## 深圳航空
shenzhenair.com
## 四川航空
sichuanair.com
## 天津航空
tianjin-air.com
## 西藏航空
tibetairlines.com.cn
## 乌鲁木齐航空
urumqi-air.com
## 厦门航空
xiamenair.com
## 中国民航局
caac.gov.cn
## 信天游(航空电子客票验真)
travelskymobile.cn
## 航旅纵横
umetrip.com
umetrip.com.cn
umetrip.net.cn
ume-trip.cn
## 飞常准
variflight.com
# 中国民航局 caac.gov.cn
ceair.com # 中国东方航空
chinaexpressair.com # 华夏航空
csair.com # 中国南方航空
flycua.com # 中国联合航空
hbhk.com.cn # 河北航空
jdair.net # 首都航空
juneyaoair.com # 吉祥航空
luckyair.net # 祥鹏航空
sichuanair.com # 四川航空
tibetairlines.com.cn # 西藏航空
travelskymobile.cn # 信天游(航空电子客票验真)
variflight.com # 飞常准
xiamenair.com # 厦门航空
## Railway ## Railway
12306.cn 12306.cn
95306.cn 95306.cn
@@ -257,11 +299,6 @@ kuajing84.com
mygolbs.com mygolbs.com
## 宁停车 ## 宁停车
ningtingche.com ningtingche.com
## 航旅纵横
umetrip.com
umetrip.com.cn
umetrip.net.cn
ume-trip.cn
# Science & Technology & Knowledge & Scholar & Press & E-learning & Education # Science & Technology & Knowledge & Scholar & Press & E-learning & Education
include:category-education-cn include:category-education-cn
@@ -288,6 +325,10 @@ guoxuemi.com
zyh365.com zyh365.com
## 温州市图书馆 ## 温州市图书馆
wzlib.cn wzlib.cn
## 中国大百科全书
zgbk.com
## 浙江图书馆
zjlib.cn
# Services & Softwares # Services & Softwares
include:category-ai-cn include:category-ai-cn
@@ -425,6 +466,7 @@ xbext.com
yinxiang.com yinxiang.com
## 智联招聘 ## 智联招聘
zhaopin.cn zhaopin.cn
zhaopin.com
# Tech companies & Orginations # Tech companies & Orginations
include:aisiku # 北京艾斯酷科技有限公司 include:aisiku # 北京艾斯酷科技有限公司
@@ -646,7 +688,6 @@ ycrx360.com
52z.com 52z.com
53kf.com 53kf.com
55.com 55.com
56.com
5577.com 5577.com
55bbs.com 55bbs.com
58pic.com 58pic.com
@@ -692,8 +733,6 @@ aiemy.com
aiketour.com aiketour.com
aiops.com aiops.com
aipai.com aipai.com
airchangan.com
airguilin.com
aiskycn.com aiskycn.com
aizhan.com aizhan.com
aldwx.com # 京ICP备17030349号-1 aldwx.com # 京ICP备17030349号-1
@@ -757,7 +796,6 @@ cecdc.com
cecport.com cecport.com
centanet.com centanet.com
cerambath.org cerambath.org
ch.com
chachaba.com chachaba.com
changba.com changba.com
chaojituzi.net chaojituzi.net
@@ -942,7 +980,6 @@ gupzs.com
gushiwen.org gushiwen.org
guzhangting.com guzhangting.com
gwdang.com gwdang.com
gxairlines.com
gxb.io gxb.io
gzcqs.com gzcqs.com
gzwanju.com gzwanju.com
@@ -1300,7 +1337,6 @@ taoche.com
te5.com te5.com
tenxcloud.com tenxcloud.com
tianjimedia.com tianjimedia.com
tianjin-air.com
tianlailive.com tianlailive.com
tietuku.com tietuku.com
tiexue.net tiexue.net
@@ -1336,7 +1372,6 @@ ucbug.com
uggame.com uggame.com
uoko.com uoko.com
urselect.com urselect.com
urumqi-air.com
useso.com useso.com
uuu9.com uuu9.com
uzzf.com uzzf.com
@@ -1500,7 +1535,6 @@ zhangyoubao.com
zhanzhang.net zhanzhang.net
zhaodanji.com zhaodanji.com
zhaokao.net zhaokao.net
zhaopin.com
zhcw.com zhcw.com
zhenai.com zhenai.com
zhibo8.cc zhibo8.cc
@@ -1511,15 +1545,11 @@ zhongkao.com
zhuangjiba.com zhuangjiba.com
zhuanyewanjia.com zhuanyewanjia.com
zhuayoukong.com zhuayoukong.com
zimuzu.io
zixiaomao.com zixiaomao.com
zixuntop.com zixuntop.com
zmengzhu.com zmengzhu.com
zpb365.com zpb365.com
zrblog.net
zsxq.com
zuhaowan.com zuhaowan.com
zuidaima.com
zuowen.com zuowen.com
zuowen8.com zuowen8.com
zuowenwang.net zuowenwang.net

View File

@@ -3,6 +3,7 @@ kinopub.online
kpdl.link kpdl.link
# Mirror sites # Mirror sites
ahc.ovh # sub domains mirror
gfw.ovh # sub domains mirror gfw.ovh # sub domains mirror
mos-gorsud.co # kinopub domain to generate a mirror site through gfw.ovh mos-gorsud.co # kinopub domain to generate a mirror site through gfw.ovh

View File

@@ -32,6 +32,7 @@ static163.net
ydstatic.com ydstatic.com
yeah.net yeah.net
youdao.com youdao.com
yunxindns.com
yunxinfw.com yunxinfw.com
zhuanzfx.com zhuanzfx.com

View File

@@ -1,5 +1,6 @@
22112211.xyz 22112211.xyz
deepflood.com deepflood.com
nodeget.com
nodeimage.com nodeimage.com
nodequality.com nodequality.com
nodeseek.com nodeseek.com

View File

@@ -59,6 +59,7 @@ tegrazone.com
tegrazone.jp tegrazone.jp
tegrazone.kr tegrazone.kr
full:nvidia.custhelp.com
full:nvidia.tt.omtrdc.net full:nvidia.tt.omtrdc.net
# NVIDIA 文件下载服务器中国镜像 # NVIDIA 文件下载服务器中国镜像

View File

@@ -1,10 +1,14 @@
# All .oracle domains # All .oracle domains
oracle oracle
include:addthis
include:java
ateam-oracle.com ateam-oracle.com
bronto.com bronto.com
covid19-rx.org covid19-rx.org
covid19rx.org covid19rx.org
custhelp.com
oracle.com oracle.com
oraclecloud.com oraclecloud.com
oraclefoundation.org oraclefoundation.org
@@ -12,6 +16,3 @@ oracleimg.com
oracleinfinity.io oracleinfinity.io
sun.com sun.com
virtualbox.org virtualbox.org
include:addthis
include:java

View File

@@ -9,6 +9,10 @@ itc.cn
sohu.com sohu.com
sohucs.com sohucs.com
# 56网
56.com
56img.com
# Ads/tracking # Ads/tracking
adnet.sohu.com @ads adnet.sohu.com @ads
ads.sohu.com @ads ads.sohu.com @ads

View File

@@ -1,6 +1,7 @@
videopress.com videopress.com
w.org w.org
wordpress.com wordpress.com
wordpress.net
wordpress.org wordpress.org
wordpress.tv wordpress.tv
wp-themes.com wp-themes.com

197
main.go
View File

@@ -47,7 +47,7 @@ type Processor struct {
cirIncMap map[string]bool cirIncMap map[string]bool
} }
func makeProtoList(listName string, entries []*Entry) (*router.GeoSite, error) { func makeProtoList(listName string, entries []*Entry) *router.GeoSite {
site := &router.GeoSite{ site := &router.GeoSite{
CountryCode: listName, CountryCode: listName,
Domain: make([]*router.Domain, 0, len(entries)), Domain: make([]*router.Domain, 0, len(entries)),
@@ -73,7 +73,7 @@ func makeProtoList(listName string, entries []*Entry) (*router.GeoSite, error) {
} }
site.Domain = append(site.Domain, pdomain) site.Domain = append(site.Domain, pdomain)
} }
return site, nil return site
} }
func writePlainList(listname string, entries []*Entry) error { func writePlainList(listname string, entries []*Entry) error {
@@ -89,46 +89,28 @@ func writePlainList(listname string, entries []*Entry) error {
return w.Flush() return w.Flush()
} }
func parseEntry(line string) (*Entry, []string, error) { func parseEntry(typ, rule string) (*Entry, []string, error) {
entry := new(Entry) entry := &Entry{Type: typ}
parts := strings.Fields(line) parts := strings.Fields(rule)
if len(parts) == 0 { if len(parts) == 0 {
return entry, nil, fmt.Errorf("empty line") return entry, nil, fmt.Errorf("empty domain rule")
} }
// Parse value
// Parse type and value switch entry.Type {
typ, val, isTypeSpecified := strings.Cut(parts[0], ":") case dlc.RuleTypeRegexp:
typ = strings.ToLower(typ) if _, err := regexp.Compile(parts[0]); err != nil {
if !isTypeSpecified { // Default RuleType return entry, nil, fmt.Errorf("invalid regexp %q: %w", parts[0], err)
if !validateDomainChars(typ) {
return entry, nil, fmt.Errorf("invalid domain: %q", typ)
} }
entry.Type = dlc.RuleTypeDomain entry.Value = parts[0]
entry.Value = typ case dlc.RuleTypeDomain, dlc.RuleTypeFullDomain, dlc.RuleTypeKeyword:
} else { entry.Value = strings.ToLower(parts[0])
switch typ { if !validateDomainChars(entry.Value) {
case dlc.RuleTypeRegexp: return entry, nil, fmt.Errorf("invalid domain: %q", entry.Value)
if _, err := regexp.Compile(val); err != nil {
return entry, nil, fmt.Errorf("invalid regexp %q: %w", val, err)
}
entry.Type = dlc.RuleTypeRegexp
entry.Value = val
case dlc.RuleTypeInclude:
entry.Type = dlc.RuleTypeInclude
entry.Value = strings.ToUpper(val)
if !validateSiteName(entry.Value) {
return entry, nil, fmt.Errorf("invalid included list name: %q", entry.Value)
}
case dlc.RuleTypeDomain, dlc.RuleTypeFullDomain, dlc.RuleTypeKeyword:
entry.Type = typ
entry.Value = strings.ToLower(val)
if !validateDomainChars(entry.Value) {
return entry, nil, fmt.Errorf("invalid domain: %q", entry.Value)
}
default:
return entry, nil, fmt.Errorf("invalid type: %q", typ)
} }
default:
return entry, nil, fmt.Errorf("unknown rule type: %q", entry.Type)
} }
plen := len(entry.Type) + len(entry.Value) + 1
// Parse attributes and affiliations // Parse attributes and affiliations
var affs []string var affs []string
@@ -140,6 +122,7 @@ func parseEntry(line string) (*Entry, []string, error) {
return entry, affs, fmt.Errorf("invalid attribute: %q", attr) return entry, affs, fmt.Errorf("invalid attribute: %q", attr)
} }
entry.Attrs = append(entry.Attrs, attr) entry.Attrs = append(entry.Attrs, attr)
plen += 2 + len(attr)
case '&': case '&':
aff := strings.ToUpper(part[1:]) aff := strings.ToUpper(part[1:])
if !validateSiteName(aff) { if !validateSiteName(aff) {
@@ -147,33 +130,70 @@ func parseEntry(line string) (*Entry, []string, error) {
} }
affs = append(affs, aff) affs = append(affs, aff)
default: default:
return entry, affs, fmt.Errorf("invalid attribute/affiliation: %q", part) return entry, affs, fmt.Errorf("unknown field: %q", part)
} }
} }
if entry.Type != dlc.RuleTypeInclude { slices.Sort(entry.Attrs) // Sort attributes
slices.Sort(entry.Attrs) // Sort attributes // Formated plain entry: type:domain.tld:@attr1,@attr2
// Formated plain entry: type:domain.tld:@attr1,@attr2 var plain strings.Builder
var plain strings.Builder plain.Grow(plen)
plain.Grow(len(entry.Type) + len(entry.Value) + 10) plain.WriteString(entry.Type)
plain.WriteString(entry.Type) plain.WriteByte(':')
plain.WriteByte(':') plain.WriteString(entry.Value)
plain.WriteString(entry.Value) for i, attr := range entry.Attrs {
for i, attr := range entry.Attrs { if i == 0 {
if i == 0 { plain.WriteByte(':')
plain.WriteByte(':') } else {
} else { plain.WriteByte(',')
plain.WriteByte(',')
}
plain.WriteByte('@')
plain.WriteString(attr)
} }
entry.Plain = plain.String() plain.WriteByte('@')
plain.WriteString(attr)
} }
entry.Plain = plain.String()
return entry, affs, nil return entry, affs, nil
} }
func parseInclusion(rule string) (*Inclusion, error) {
parts := strings.Fields(rule)
if len(parts) == 0 {
return nil, fmt.Errorf("empty inclusion")
}
inc := &Inclusion{Source: strings.ToUpper(parts[0])}
if !validateSiteName(inc.Source) {
return inc, fmt.Errorf("invalid included list name: %q", inc.Source)
}
// Parse attributes
for _, part := range parts[1:] {
switch part[0] {
case '@':
attr := strings.ToLower(part[1:])
if attr[0] == '-' {
battr := attr[1:]
if !validateAttrChars(battr) {
return inc, fmt.Errorf("invalid ban attribute: %q", battr)
}
inc.BanAttrs = append(inc.BanAttrs, battr)
} else {
if !validateAttrChars(attr) {
return inc, fmt.Errorf("invalid must attribute: %q", attr)
}
inc.MustAttrs = append(inc.MustAttrs, attr)
}
case '&':
return inc, fmt.Errorf("affiliation is not allowed for inclusion")
default:
return inc, fmt.Errorf("unknown field: %q", part)
}
}
return inc, nil
}
func validateDomainChars(domain string) bool { func validateDomainChars(domain string) bool {
if domain == "" {
return false
}
for i := range domain { for i := range domain {
c := domain[i] c := domain[i]
if (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-' { if (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '.' || c == '-' {
@@ -185,9 +205,12 @@ func validateDomainChars(domain string) bool {
} }
func validateAttrChars(attr string) bool { func validateAttrChars(attr string) bool {
if attr == "" {
return false
}
for i := range attr { for i := range attr {
c := attr[i] c := attr[i]
if (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '!' || c == '-' { if (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '!' {
continue continue
} }
return false return false
@@ -196,6 +219,9 @@ func validateAttrChars(attr string) bool {
} }
func validateSiteName(name string) bool { func validateSiteName(name string) bool {
if name == "" {
return false
}
for i := range name { for i := range name {
c := name[i] c := name[i]
if (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '!' || c == '-' { if (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '!' || c == '-' {
@@ -232,26 +258,23 @@ func (p *Processor) loadData(listName string, path string) error {
if line == "" { if line == "" {
continue continue
} }
entry, affs, err := parseEntry(line) typ, rule, isTypeSpecified := strings.Cut(line, ":")
if err != nil { if !isTypeSpecified { // Default RuleType
return fmt.Errorf("error in %q at line %d: %w", path, lineIdx, err) typ, rule = dlc.RuleTypeDomain, typ
} else {
typ = strings.ToLower(typ)
} }
if typ == dlc.RuleTypeInclude {
if entry.Type == dlc.RuleTypeInclude { inc, err := parseInclusion(rule)
inc := &Inclusion{Source: entry.Value} if err != nil {
for _, attr := range entry.Attrs { return fmt.Errorf("error in %q at line %d: %w", path, lineIdx, err)
if attr[0] == '-' {
inc.BanAttrs = append(inc.BanAttrs, attr[1:])
} else {
inc.MustAttrs = append(inc.MustAttrs, attr)
}
}
for _, aff := range affs {
apl := p.getOrCreateParsedList(aff)
apl.Inclusions = append(apl.Inclusions, inc)
} }
pl.Inclusions = append(pl.Inclusions, inc) pl.Inclusions = append(pl.Inclusions, inc)
} else { } else {
entry, affs, err := parseEntry(typ, rule)
if err != nil {
return fmt.Errorf("error in %q at line %d: %w", path, lineIdx, err)
}
for _, aff := range affs { for _, aff := range affs {
apl := p.getOrCreateParsedList(aff) apl := p.getOrCreateParsedList(aff)
apl.Entries = append(apl.Entries, entry) apl.Entries = append(apl.Entries, entry)
@@ -259,7 +282,7 @@ func (p *Processor) loadData(listName string, path string) error {
pl.Entries = append(pl.Entries, entry) pl.Entries = append(pl.Entries, entry)
} }
} }
return nil return scanner.Err()
} }
func isMatchAttrFilters(entry *Entry, incFilter *Inclusion) bool { func isMatchAttrFilters(entry *Entry, incFilter *Inclusion) bool {
@@ -360,6 +383,9 @@ func (p *Processor) resolveList(plname string) error {
} }
} }
} }
if len(roughMap) == 0 {
return fmt.Errorf("empty list")
}
p.finalMap[plname] = polishList(roughMap) p.finalMap[plname] = polishList(roughMap)
return nil return nil
} }
@@ -387,13 +413,15 @@ func run() error {
return fmt.Errorf("failed to loadData: %w", err) return fmt.Errorf("failed to loadData: %w", err)
} }
// Generate finalMap // Generate finalMap
processor.finalMap = make(map[string][]*Entry, len(processor.plMap)) sitesCount := len(processor.plMap)
processor.finalMap = make(map[string][]*Entry, sitesCount)
processor.cirIncMap = make(map[string]bool) processor.cirIncMap = make(map[string]bool)
for plname := range processor.plMap { for plname := range processor.plMap {
if err := processor.resolveList(plname); err != nil { if err := processor.resolveList(plname); err != nil {
return fmt.Errorf("failed to resolveList %q: %w", plname, err) return fmt.Errorf("failed to resolveList %q: %w", plname, err)
} }
} }
processor.plMap = nil
// Make sure output directory exists // Make sure output directory exists
if err := os.MkdirAll(*outputDir, 0755); err != nil { if err := os.MkdirAll(*outputDir, 0755); err != nil {
@@ -403,27 +431,24 @@ func run() error {
for rawEpList := range strings.SplitSeq(*exportLists, ",") { for rawEpList := range strings.SplitSeq(*exportLists, ",") {
if epList := strings.TrimSpace(rawEpList); epList != "" { if epList := strings.TrimSpace(rawEpList); epList != "" {
entries, exist := processor.finalMap[strings.ToUpper(epList)] entries, exist := processor.finalMap[strings.ToUpper(epList)]
if !exist || len(entries) == 0 { if !exist {
fmt.Printf("list %q does not exist or is empty\n", epList) fmt.Printf("[Warn] list %q does not exist\n", epList)
continue continue
} }
if err := writePlainList(epList, entries); err != nil { if err := writePlainList(epList, entries); err != nil {
fmt.Printf("failed to write list %q: %v\n", epList, err) fmt.Printf("[Error] failed to write list %q: %v\n", epList, err)
continue continue
} }
fmt.Printf("list %q has been generated successfully.\n", epList) fmt.Printf("list %q has been generated successfully\n", epList)
} }
} }
// Generate dat file // Generate dat file
protoList := new(router.GeoSiteList) protoList := &router.GeoSiteList{Entry: make([]*router.GeoSite, 0, sitesCount)}
for siteName, siteEntries := range processor.finalMap { for siteName, siteEntries := range processor.finalMap {
site, err := makeProtoList(siteName, siteEntries) protoList.Entry = append(protoList.Entry, makeProtoList(siteName, siteEntries))
if err != nil {
return fmt.Errorf("failed to makeProtoList %q: %w", siteName, err)
}
protoList.Entry = append(protoList.Entry, site)
} }
processor = nil
// Sort protoList so the marshaled list is reproducible // Sort protoList so the marshaled list is reproducible
slices.SortFunc(protoList.Entry, func(a, b *router.GeoSite) int { slices.SortFunc(protoList.Entry, func(a, b *router.GeoSite) int {
return strings.Compare(a.CountryCode, b.CountryCode) return strings.Compare(a.CountryCode, b.CountryCode)
@@ -436,14 +461,14 @@ func run() error {
if err := os.WriteFile(filepath.Join(*outputDir, *outputName), protoBytes, 0644); err != nil { if err := os.WriteFile(filepath.Join(*outputDir, *outputName), protoBytes, 0644); err != nil {
return fmt.Errorf("failed to write output: %w", err) return fmt.Errorf("failed to write output: %w", err)
} }
fmt.Printf("%q has been generated successfully.\n", *outputName) fmt.Printf("%q has been generated successfully\n", *outputName)
return nil return nil
} }
func main() { func main() {
flag.Parse() flag.Parse()
if err := run(); err != nil { if err := run(); err != nil {
fmt.Printf("Fatal error: %v\n", err) fmt.Printf("[Fatal] critical error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }