From 9169d138e879b3df5a24ea943d66fb1428ee332f Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 15 Jul 2018 18:14:30 +0530 Subject: [PATCH] Zone: GetAllRecords() added type parameter to filter records by type. --- DnsServerCore/Zone.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/DnsServerCore/Zone.cs b/DnsServerCore/Zone.cs index f786980d..708d813b 100644 --- a/DnsServerCore/Zone.cs +++ b/DnsServerCore/Zone.cs @@ -267,14 +267,17 @@ namespace DnsServerCore return null; } - private DnsResourceRecord[] GetAllRecords(bool includeSubDomains) + private DnsResourceRecord[] GetAllRecords(DnsResourceRecordType type, bool includeSubDomains) { List allRecords = new List(); foreach (KeyValuePair entry in _entries) { if (entry.Key != DnsResourceRecordType.ANY) - allRecords.AddRange(entry.Value); + { + if ((type == DnsResourceRecordType.ANY) || (entry.Key == type)) + allRecords.AddRange(entry.Value); + } } if (includeSubDomains) @@ -282,7 +285,7 @@ namespace DnsServerCore foreach (KeyValuePair zone in _zones) { if (!zone.Value._entries.ContainsKey(DnsResourceRecordType.SOA)) - allRecords.AddRange(zone.Value.GetAllRecords(true)); + allRecords.AddRange(zone.Value.GetAllRecords(type, true)); } } @@ -853,13 +856,13 @@ namespace DnsServerCore currentZone.DeleteRecords(type); } - public DnsResourceRecord[] GetAllRecords(string domain = "", bool includeSubDomains = true, bool authoritative = false) + public DnsResourceRecord[] GetAllRecords(string domain = "", DnsResourceRecordType type = DnsResourceRecordType.ANY, bool includeSubDomains = true, bool authoritative = false) { Zone currentZone = GetZone(this, domain, authoritative); if (currentZone == null) return new DnsResourceRecord[] { }; - DnsResourceRecord[] records = currentZone.GetAllRecords(includeSubDomains); + DnsResourceRecord[] records = currentZone.GetAllRecords(type, includeSubDomains); if (records != null) return records;