1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

aliases: Make parsing functions methods of the resolver

Today, the parsing functions are stand-alone since they don't need
anything from the resolver.

But in future patches, that will change.

In anticipation of that, move those functions to be methods of the
resolver.
This commit is contained in:
Alberto Bertogli
2023-09-23 20:31:45 +01:00
parent 8bbb6118e5
commit d086fbbb97
2 changed files with 10 additions and 6 deletions

View File

@@ -303,7 +303,7 @@ func (v *Resolver) AddAliasesFile(domain, path string) error {
v.domains[domain] = true
v.mu.Unlock()
aliases, err := parseFile(domain, path)
aliases, err := v.parseFile(domain, path)
if os.IsNotExist(err) {
return nil
}
@@ -333,7 +333,7 @@ func (v *Resolver) Reload() error {
for domain, paths := range v.files {
for _, path := range paths {
aliases, err := parseFile(domain, path)
aliases, err := v.parseFile(domain, path)
if os.IsNotExist(err) {
continue
}
@@ -355,21 +355,21 @@ func (v *Resolver) Reload() error {
return nil
}
func parseFile(domain, path string) (map[string][]Recipient, error) {
func (v *Resolver) parseFile(domain, path string) (map[string][]Recipient, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
aliases, err := parseReader(domain, f)
aliases, err := v.parseReader(domain, f)
if err != nil {
return nil, fmt.Errorf("reading %q: %v", path, err)
}
return aliases, nil
}
func parseReader(domain string, r io.Reader) (map[string][]Recipient, error) {
func (v *Resolver) parseReader(domain string, r io.Reader) (map[string][]Recipient, error) {
aliases := map[string][]Recipient{}
scanner := bufio.NewScanner(r)

View File

@@ -504,7 +504,11 @@ func TestHookError(t *testing.T) {
// Fuzz testing for the parser.
func FuzzReader(f *testing.F) {
resolver := NewResolver(allUsersExist)
resolver.AddDomain("domain")
resolver.DropChars = "."
resolver.SuffixSep = "-+"
f.Fuzz(func(t *testing.T, data []byte) {
parseReader("domain", bytes.NewReader(data))
resolver.parseReader("domain", bytes.NewReader(data))
})
}