| 
									
										
										
										
											2016-03-18 20:57:35 +00:00
										 |  |  | package middleware
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-22 22:44:50 +00:00
										 |  |  | import (
 | 
					
						
							|  |  |  | 	"strings"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							| 
									
										
										
										
											2016-03-18 20:57:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Zones []string
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-21 21:21:29 +00:00
										 |  |  | // Matches checks to see if other matches p.  The match will return the most
 | 
					
						
							|  |  |  | // specific zones that matches other. The empty string signals a not found
 | 
					
						
							| 
									
										
										
										
											2016-03-18 20:57:35 +00:00
										 |  |  | // condition.
 | 
					
						
							|  |  |  | func (z Zones) Matches(qname string) string {
 | 
					
						
							|  |  |  | 	zone := ""
 | 
					
						
							| 
									
										
										
										
											2016-03-21 21:21:29 +00:00
										 |  |  | 	// TODO(miek): use IsSubDomain here?
 | 
					
						
							| 
									
										
										
										
											2016-03-18 20:57:35 +00:00
										 |  |  | 	for _, zname := range z {
 | 
					
						
							|  |  |  | 		if strings.HasSuffix(qname, zname) {
 | 
					
						
							|  |  |  | 			if len(zname) > len(zone) {
 | 
					
						
							|  |  |  | 				zone = zname
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return zone
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2016-03-22 22:44:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Fully qualify all zones in z
 | 
					
						
							|  |  |  | func (z Zones) FullyQualify() {
 | 
					
						
							|  |  |  | 	for i, _ := range z {
 | 
					
						
							|  |  |  | 		z[i] = dns.Fqdn(z[i])
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }
 |