move zoneMatch to dns.go

This commit is contained in:
Miek Gieben 2011-07-31 09:53:54 +02:00
parent 770f580540
commit 4925a831aa
2 changed files with 57 additions and 57 deletions

88
dns.go
View File

@ -80,8 +80,8 @@ type RR interface {
type RRset []RR type RRset []RR
func NewRRset() RRset { func NewRRset() RRset {
s := make([]RR, 0) s := make([]RR, 0)
return s return s
} }
func (s RRset) Len() int { return len(s) } func (s RRset) Len() int { return len(s) }
@ -89,44 +89,44 @@ func (s RRset) Less(i, j int) bool { return s[i].Header().Name < s[j].Header().N
func (s RRset) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s RRset) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s RRset) String() string { func (s RRset) String() string {
str := "" str := ""
for _, r := range s { for _, r := range s {
str += r.String() + "\n" str += r.String() + "\n"
} }
return str return str
} }
// Remove the last pushed RR from the RRset. Return nil // Remove the last pushed RR from the RRset. Return nil
// when there is nothing to remove // when there is nothing to remove
func (s *RRset) Pop() RR { func (s *RRset) Pop() RR {
if len(*s) == 0 { if len(*s) == 0 {
return nil return nil
} }
// Pop and remove the entry // Pop and remove the entry
r := (*s)[len(*s)-1] r := (*s)[len(*s)-1]
*s = (*s)[:len(*s)-1] *s = (*s)[:len(*s)-1]
return r return r
} }
// Push the RR r to the RRset // Push the RR r to the RRset
func (s *RRset) Push(r RR) bool { func (s *RRset) Push(r RR) bool {
if s.Len() == 0 { if s.Len() == 0 {
*s = append(*s, r) *s = append(*s, r)
return true return true
} }
// For RRSIGs this is not true (RFC???) // For RRSIGs this is not true (RFC???)
// Don't make it a failure if this happens // Don't make it a failure if this happens
// if (*s)[0].Header().Ttl != r.Header().Ttl { // if (*s)[0].Header().Ttl != r.Header().Ttl {
// return false // return false
// } // }
if (*s)[0].Header().Name != r.Header().Name { if (*s)[0].Header().Name != r.Header().Name {
return false return false
} }
if (*s)[0].Header().Class != r.Header().Class { if (*s)[0].Header().Class != r.Header().Class {
return false return false
} }
*s = append(*s, r) *s = append(*s, r)
return true return true
} }
// Check if the RRset is RFC 2181 compliant. // Check if the RRset is RFC 2181 compliant.
@ -191,3 +191,29 @@ func (h *RR_Header) String() string {
} }
return s return s
} }
func zoneMatch(pattern, zone string) (ok bool) {
if len(pattern) == 0 {
return
}
if pattern[len(pattern)-1] != '.' {
pattern += "."
}
if zone[len(zone)-1] != '.' {
zone += "."
}
i := 0
for {
ok = pattern[len(pattern)-1-i] == zone[len(zone)-1-i]
i++
if !ok {
break
}
if len(pattern)-1-i < 0 || len(zone)-1-i < 0 {
break
}
}
return
}

View File

@ -84,32 +84,6 @@ func ListenAndServe(addr string, network string, handler Handler) os.Error {
return server.ListenAndServe() return server.ListenAndServe()
} }
func zoneMatch(pattern, zone string) (ok bool) {
if len(pattern) == 0 {
return
}
if pattern[len(pattern)-1] != '.' {
pattern += "."
}
if zone[len(zone)-1] != '.' {
zone += "."
}
i := 0
for {
ok = pattern[len(pattern)-1-i] == zone[len(zone)-1-i]
i++
if !ok {
break
}
if len(pattern)-1-i < 0 || len(zone)-1-i < 0 {
break
}
}
return
}
func (mux *ServeMux) match(zone string) Handler { func (mux *ServeMux) match(zone string) Handler {
var h Handler var h Handler
var n = 0 var n = 0