| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | package file
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	"github.com/miekg/coredns/middleware"
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | 	"github.com/miekg/coredns/middleware/file/tree"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | type Transfer struct {
 | 
					
						
							|  |  |  | 	Out bool
 | 
					
						
							|  |  |  | 	In  bool
 | 
					
						
							|  |  |  | 	// more later
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | type Zone struct {
 | 
					
						
							|  |  |  | 	SOA  *dns.SOA
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	SIG  []dns.RR
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | 	name string
 | 
					
						
							|  |  |  | 	*tree.Tree
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	Masters  []string
 | 
					
						
							|  |  |  | 	Transfer *Transfer
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func NewZone(name string) *Zone {
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 	return &Zone{name: dns.Fqdn(name), Tree: &tree.Tree{}, Transfer: &Transfer{}}
 | 
					
						
							| 
									
										
										
										
											2016-03-27 07:37:23 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (z *Zone) Insert(r dns.RR) {
 | 
					
						
							|  |  |  | 	z.Tree.Insert(r)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (z *Zone) Delete(r dns.RR) {
 | 
					
						
							|  |  |  | 	z.Tree.Delete(r)
 | 
					
						
							|  |  |  | }
 | 
					
						
							| 
									
										
										
										
											2016-03-28 12:08:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // It the transfer request allowed.
 | 
					
						
							|  |  |  | func (z *Zone) TransferAllowed(state middleware.State) bool {
 | 
					
						
							|  |  |  | 	if z.Transfer == nil {
 | 
					
						
							|  |  |  | 		return false
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return z.Transfer.Out
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // All returns all records from the zone, the first record will be the SOA record,
 | 
					
						
							|  |  |  | // otionally followed by all RRSIG(SOA)s.
 | 
					
						
							|  |  |  | func (z *Zone) All() []dns.RR {
 | 
					
						
							|  |  |  | 	records := []dns.RR{}
 | 
					
						
							|  |  |  | 	allNodes := z.Tree.All()
 | 
					
						
							|  |  |  | 	for _, a := range allNodes {
 | 
					
						
							|  |  |  | 		records = append(records, a.All()...)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if len(z.SIG) > 0 {
 | 
					
						
							|  |  |  | 		records = append(z.SIG, records...)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | 	return append([]dns.RR{z.SOA}, records...)
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Apex function?
 |