summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/maxmind/country_csv.go17
-rw-r--r--plugin/maxmind/mmdb_in.go25
-rw-r--r--plugin/plaintext/text_in.go8
-rw-r--r--plugin/singbox/srs_in.go29
-rw-r--r--plugin/special/cutter.go4
-rw-r--r--plugin/special/private.go4
-rw-r--r--plugin/special/stdin.go29
-rw-r--r--plugin/special/test.go4
-rw-r--r--plugin/v2ray/dat_in.go26
9 files changed, 76 insertions, 70 deletions
diff --git a/plugin/maxmind/country_csv.go b/plugin/maxmind/country_csv.go
index 4608f121..aea07a73 100644
--- a/plugin/maxmind/country_csv.go
+++ b/plugin/maxmind/country_csv.go
@@ -4,6 +4,7 @@ import (
"encoding/csv"
"encoding/json"
"errors"
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -113,6 +114,10 @@ func (g *geoLite2CountryCSV) Input(container lib.Container) (lib.Container, erro
}
}
+ if len(entries) == 0 {
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeCountryCSV, g.Action)
+ }
+
var ignoreIPType lib.IgnoreIPOption
switch g.OnlyIPType {
case lib.IPv4:
@@ -121,14 +126,16 @@ func (g *geoLite2CountryCSV) Input(container lib.Container) (lib.Container, erro
ignoreIPType = lib.IgnoreIPv4
}
- for name, entry := range entries {
+ for _, entry := range entries {
switch g.Action {
case lib.ActionAdd:
if err := container.Add(entry, ignoreIPType); err != nil {
return nil, err
}
case lib.ActionRemove:
- container.Remove(name, ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
default:
return nil, lib.ErrUnknownAction
}
@@ -193,10 +200,8 @@ func (g *geoLite2CountryCSV) process(file string, ccMap map[string]string, entri
for _, line := range lines[1:] {
ccID := strings.TrimSpace(line[1])
if countryCode, found := ccMap[ccID]; found {
- if len(wantList) > 0 {
- if _, found := wantList[countryCode]; !found {
- continue
- }
+ if len(wantList) > 0 && !wantList[countryCode] {
+ continue
}
cidrStr := strings.ToLower(strings.TrimSpace(line[0]))
entry, found := entries[countryCode]
diff --git a/plugin/maxmind/mmdb_in.go b/plugin/maxmind/mmdb_in.go
index eef4c7d6..0c94a12c 100644
--- a/plugin/maxmind/mmdb_in.go
+++ b/plugin/maxmind/mmdb_in.go
@@ -107,7 +107,7 @@ func (g *maxmindMMDBIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is newly generated", typeMaxmindMMDBIn, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeMaxmindMMDBIn, g.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -138,7 +138,11 @@ func (g *maxmindMMDBIn) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(name, ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
}
@@ -197,23 +201,14 @@ func (g *maxmindMMDBIn) generateEntries(entries map[string]*lib.Entry) error {
continue
}
- var entry *lib.Entry
name := strings.ToUpper(record.Country.IsoCode)
- if theEntry, found := entries[name]; found {
- entry = theEntry
- } else {
+ entry, found := entries[name]
+ if !found {
entry = lib.NewEntry(name)
}
- switch g.Action {
- case lib.ActionAdd:
- if err := entry.AddPrefix(subnet); err != nil {
- return err
- }
- case lib.ActionRemove:
- if err := entry.RemovePrefix(subnet.String()); err != nil {
- return err
- }
+ if err := entry.AddPrefix(subnet); err != nil {
+ return err
}
entries[name] = entry
diff --git a/plugin/plaintext/text_in.go b/plugin/plaintext/text_in.go
index 246a4ac1..0180e52c 100644
--- a/plugin/plaintext/text_in.go
+++ b/plugin/plaintext/text_in.go
@@ -106,7 +106,7 @@ func (t *textIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("type %s | action %s no entry are generated", t.Type, t.Action)
+ return nil, fmt.Errorf("type %s | action %s no entry is generated", t.Type, t.Action)
}
for _, entry := range entries {
@@ -116,7 +116,11 @@ func (t *textIn) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(entry.GetName(), ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
}
diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go
index 343fd4ca..44812cb8 100644
--- a/plugin/singbox/srs_in.go
+++ b/plugin/singbox/srs_in.go
@@ -114,7 +114,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("type %s | action %s no entry are generated", s.Type, s.Action)
+ return nil, fmt.Errorf("type %s | action %s no entry is generated", s.Type, s.Action)
}
for _, entry := range entries {
@@ -124,7 +124,11 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(entry.GetName(), ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
}
@@ -200,10 +204,9 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
}
func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error {
- entry := lib.NewEntry(name)
- if theEntry, found := entries[entry.GetName()]; found {
- fmt.Printf("⚠️ [type %s | action %s] found duplicated entry: %s. Process anyway\n", typeSRSIn, s.Action, name)
- entry = theEntry
+ entry, found := entries[name]
+ if !found {
+ entry = lib.NewEntry(name)
}
plainRuleSet, err := srs.Read(reader, true)
@@ -213,20 +216,12 @@ func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[strin
for _, rule := range plainRuleSet.Rules {
for _, cidrStr := range rule.DefaultOptions.IPCIDR {
- switch s.Action {
- case lib.ActionAdd:
- if err := entry.AddPrefix(cidrStr); err != nil {
- return err
- }
- case lib.ActionRemove:
- if err := entry.RemovePrefix(cidrStr); err != nil {
- return err
- }
+ if err := entry.AddPrefix(cidrStr); err != nil {
+ return err
}
}
}
- entries[entry.GetName()] = entry
-
+ entries[name] = entry
return nil
}
diff --git a/plugin/special/cutter.go b/plugin/special/cutter.go
index c5543c2b..d14e286d 100644
--- a/plugin/special/cutter.go
+++ b/plugin/special/cutter.go
@@ -89,7 +89,9 @@ func (c *cutter) Input(container lib.Container) (lib.Container, error) {
if len(wantList) > 0 && !wantList[name] {
continue
}
- container.Remove(name, ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemoveEntry, ignoreIPType); err != nil {
+ return nil, err
+ }
}
return container, nil
diff --git a/plugin/special/private.go b/plugin/special/private.go
index a3907aee..ec81acd1 100644
--- a/plugin/special/private.go
+++ b/plugin/special/private.go
@@ -85,7 +85,9 @@ func (p *private) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(entryNamePrivate)
+ if err := container.Remove(entry, lib.CaseRemovePrefix); err != nil {
+ return nil, err
+ }
default:
return nil, lib.ErrUnknownAction
}
diff --git a/plugin/special/stdin.go b/plugin/special/stdin.go
index 1f59c1fe..4f56d756 100644
--- a/plugin/special/stdin.go
+++ b/plugin/special/stdin.go
@@ -3,6 +3,7 @@ package special
import (
"bufio"
"encoding/json"
+ "fmt"
"os"
"strings"
@@ -35,6 +36,10 @@ func newStdin(action lib.Action, data json.RawMessage) (lib.InputConverter, erro
}
}
+ if tmp.Name == "" {
+ return nil, fmt.Errorf("type %s | action %s missing name", typeStdin, action)
+ }
+
return &stdin{
Type: typeStdin,
Action: action,
@@ -81,15 +86,8 @@ func (s *stdin) Input(container lib.Container) (lib.Container, error) {
continue
}
- switch s.Action {
- case lib.ActionAdd:
- if err := entry.AddPrefix(line); err != nil {
- continue
- }
- case lib.ActionRemove:
- if err := entry.RemovePrefix(line); err != nil {
- continue
- }
+ if err := entry.AddPrefix(line); err != nil {
+ continue
}
}
@@ -105,8 +103,17 @@ func (s *stdin) Input(container lib.Container) (lib.Container, error) {
ignoreIPType = lib.IgnoreIPv4
}
- if err := container.Add(entry, ignoreIPType); err != nil {
- return nil, err
+ switch s.Action {
+ case lib.ActionAdd:
+ if err := container.Add(entry, ignoreIPType); err != nil {
+ return nil, err
+ }
+ case lib.ActionRemove:
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
return container, nil
diff --git a/plugin/special/test.go b/plugin/special/test.go
index 9a19004f..cf83ed83 100644
--- a/plugin/special/test.go
+++ b/plugin/special/test.go
@@ -65,7 +65,9 @@ func (t *test) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(entryNameTest)
+ if err := container.Remove(entry, lib.CaseRemovePrefix); err != nil {
+ return nil, err
+ }
default:
return nil, lib.ErrUnknownAction
}
diff --git a/plugin/v2ray/dat_in.go b/plugin/v2ray/dat_in.go
index 65b9a674..5baf32f2 100644
--- a/plugin/v2ray/dat_in.go
+++ b/plugin/v2ray/dat_in.go
@@ -92,7 +92,7 @@ func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("❌ [type %s | action %s] no entry is newly generated", typeGeoIPdatIn, g.Action)
+ return nil, fmt.Errorf("❌ [type %s | action %s] no entry is generated", typeGeoIPdatIn, g.Action)
}
var ignoreIPType lib.IgnoreIPOption
@@ -123,7 +123,11 @@ func (g *geoIPDatIn) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(name, ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
}
@@ -174,26 +178,16 @@ func (g *geoIPDatIn) generateEntries(reader io.Reader, entries map[string]*lib.E
}
for _, geoip := range geoipList.Entry {
- var entry *lib.Entry
name := geoip.CountryCode
- if theEntry, found := entries[name]; found {
- fmt.Printf("⚠️ [type %s | action %s] found duplicated entry: %s. Process anyway\n", typeGeoIPdatIn, g.Action, name)
- entry = theEntry
- } else {
+ entry, found := entries[name]
+ if !found {
entry = lib.NewEntry(name)
}
for _, v2rayCIDR := range geoip.Cidr {
ipStr := net.IP(v2rayCIDR.GetIp()).String() + "/" + fmt.Sprint(v2rayCIDR.GetPrefix())
- switch g.Action {
- case lib.ActionAdd:
- if err := entry.AddPrefix(ipStr); err != nil {
- return err
- }
- case lib.ActionRemove:
- if err := entry.RemovePrefix(ipStr); err != nil {
- return err
- }
+ if err := entry.AddPrefix(ipStr); err != nil {
+ return err
}
}