code refactoring changes.

This commit is contained in:
Shreyas Zare
2023-02-05 16:32:28 +05:30
parent 975bc5d584
commit 73cbff24a0
7 changed files with 22 additions and 22 deletions

View File

@@ -948,7 +948,7 @@ namespace DnsServerCore
}
//add missing admin permissions
List<AuthZoneInfo> zones = _dnsServer.AuthZoneManager.ListZones();
List<AuthZoneInfo> zones = _dnsServer.AuthZoneManager.GetAllZones();
Group admins = _authManager.GetGroup(Group.ADMINISTRATORS);
Group dnsAdmins = _authManager.GetGroup(Group.DNS_ADMINISTRATORS);
@@ -1009,7 +1009,7 @@ namespace DnsServerCore
IPAddress[] localAddresses = new IPAddress[count];
for (int i = 0; i < count; i++)
localAddresses[i] = IPAddressExtension.ReadFrom(bR);
localAddresses[i] = IPAddressExtensions.ReadFrom(bR);
_webServiceLocalAddresses = localAddresses;
}
@@ -1054,7 +1054,7 @@ namespace DnsServerCore
IPEndPoint[] localEndPoints = new IPEndPoint[count];
for (int i = 0; i < count; i++)
localEndPoints[i] = (IPEndPoint)EndPointExtension.ReadFrom(bR);
localEndPoints[i] = (IPEndPoint)EndPointExtensions.ReadFrom(bR);
_dnsServer.LocalEndPoints = localEndPoints;
}
@@ -1239,7 +1239,7 @@ namespace DnsServerCore
for (int i = 0; i < count; i++)
{
IPAddress customAddress = IPAddressExtension.ReadFrom(bR);
IPAddress customAddress = IPAddressExtensions.ReadFrom(bR);
switch (customAddress.AddressFamily)
{
@@ -1351,7 +1351,7 @@ namespace DnsServerCore
IPAddress[] localAddresses = new IPAddress[count];
for (int i = 0; i < count; i++)
localAddresses[i] = IPAddressExtension.ReadFrom(bR);
localAddresses[i] = IPAddressExtensions.ReadFrom(bR);
_webServiceLocalAddresses = localAddresses;
}
@@ -1655,7 +1655,7 @@ namespace DnsServerCore
for (int i = 0; i < count; i++)
{
IPAddress customAddress = IPAddressExtension.ReadFrom(bR);
IPAddress customAddress = IPAddressExtensions.ReadFrom(bR);
switch (customAddress.AddressFamily)
{
@@ -1715,7 +1715,7 @@ namespace DnsServerCore
IPEndPoint[] localEndPoints = new IPEndPoint[count];
for (int i = 0; i < count; i++)
localEndPoints[i] = (IPEndPoint)EndPointExtension.ReadFrom(bR);
localEndPoints[i] = (IPEndPoint)EndPointExtensions.ReadFrom(bR);
_dnsServer.LocalEndPoints = localEndPoints;
}
@@ -1728,7 +1728,7 @@ namespace DnsServerCore
IPEndPoint[] localEndPoints = new IPEndPoint[count];
for (int i = 0; i < count; i++)
localEndPoints[i] = new IPEndPoint(IPAddressExtension.ReadFrom(bR), 53);
localEndPoints[i] = new IPEndPoint(IPAddressExtensions.ReadFrom(bR), 53);
_dnsServer.LocalEndPoints = localEndPoints;
}

View File

@@ -120,7 +120,7 @@ namespace DnsServerCore
return parse(value);
}
public static T GetQueryOrForm<T>(this HttpRequest request, string parameter) where T : struct
public static T GetQueryOrFormEnum<T>(this HttpRequest request, string parameter) where T : struct
{
string value = request.QueryOrForm(parameter);
if (string.IsNullOrEmpty(value))
@@ -138,7 +138,7 @@ namespace DnsServerCore
return parse(value);
}
public static T GetQueryOrForm<T>(this HttpRequest request, string parameter, T defaultValue) where T : struct
public static T GetQueryOrFormEnum<T>(this HttpRequest request, string parameter, T defaultValue) where T : struct
{
string value = request.QueryOrForm(parameter);
if (string.IsNullOrEmpty(value))
@@ -169,7 +169,7 @@ namespace DnsServerCore
return true;
}
public static bool TryGetQueryOrForm<T>(this HttpRequest request, string parameter, out T value) where T : struct
public static bool TryGetQueryOrFormEnum<T>(this HttpRequest request, string parameter, out T value) where T : struct
{
string strValue = request.QueryOrForm(parameter);
if (string.IsNullOrEmpty(strValue))

View File

@@ -161,8 +161,8 @@ namespace DnsServerCore
string server = request.GetQueryOrForm("server");
string domain = request.GetQueryOrForm("domain").Trim(new char[] { '\t', ' ', '.' });
DnsResourceRecordType type = request.GetQueryOrForm<DnsResourceRecordType>("type");
DnsTransportProtocol protocol = request.GetQueryOrForm("protocol", DnsTransportProtocol.Udp);
DnsResourceRecordType type = request.GetQueryOrFormEnum<DnsResourceRecordType>("type");
DnsTransportProtocol protocol = request.GetQueryOrFormEnum("protocol", DnsTransportProtocol.Udp);
bool dnssecValidation = request.GetQueryOrForm("dnssec", bool.Parse, false);
bool importResponse = request.GetQueryOrForm("import", bool.Parse, false);
NetProxy proxy = _dnsWebService.DnsServer.Proxy;

View File

@@ -829,7 +829,7 @@ namespace DnsServerCore
if (!_dnsWebService._authManager.IsPermitted(PermissionSection.Administration, session.User, PermissionFlag.View))
throw new DnsWebServiceException("Access was denied.");
section = request.GetQueryOrForm<PermissionSection>("section");
section = request.GetQueryOrFormEnum<PermissionSection>("section");
break;
case PermissionSection.Zones:
@@ -877,7 +877,7 @@ namespace DnsServerCore
if (!_dnsWebService._authManager.IsPermitted(PermissionSection.Administration, session.User, PermissionFlag.Delete))
throw new DnsWebServiceException("Access was denied.");
section = request.GetQueryOrForm<PermissionSection>("section");
section = request.GetQueryOrFormEnum<PermissionSection>("section");
break;
case PermissionSection.Zones:

View File

@@ -497,7 +497,7 @@ namespace DnsServerCore
HttpRequest request = context.Request;
string strType = request.GetQueryOrForm("type", "lastHour");
TopStatsType statsType = request.GetQueryOrForm<TopStatsType>("statsType");
TopStatsType statsType = request.GetQueryOrFormEnum<TopStatsType>("statsType");
int limit = request.GetQueryOrForm("limit", int.Parse, 1000);
List<KeyValuePair<string, long>> topStatsData;

View File

@@ -223,7 +223,7 @@ namespace DnsServerCore
jsonWriter.WriteEndArray();
WebServiceZonesApi.WriteRecordsAsJson(new List<DnsResourceRecord>(records), jsonWriter, false);
WebServiceZonesApi.WriteRecordsAsJson(records, jsonWriter, true);
}
public void ImportAllowedZones(HttpContext context)
@@ -395,7 +395,7 @@ namespace DnsServerCore
jsonWriter.WriteEndArray();
WebServiceZonesApi.WriteRecordsAsJson(new List<DnsResourceRecord>(records), jsonWriter, false);
WebServiceZonesApi.WriteRecordsAsJson(records, jsonWriter, true);
}
public void ImportBlockedZones(HttpContext context)

View File

@@ -872,7 +872,7 @@ namespace DnsServerCore
}
//recursion
if (request.TryGetQueryOrForm("recursion", out DnsServerRecursion recursion))
if (request.TryGetQueryOrFormEnum("recursion", out DnsServerRecursion recursion))
_dnsWebService.DnsServer.Recursion = recursion;
string recursionDeniedNetworks = request.QueryOrForm("recursionDeniedNetworks");
@@ -967,7 +967,7 @@ namespace DnsServerCore
if (request.TryGetQueryOrForm("allowTxtBlockingReport", bool.Parse, out bool allowTxtBlockingReport))
_dnsWebService.DnsServer.AllowTxtBlockingReport = allowTxtBlockingReport;
if (request.TryGetQueryOrForm("blockingType", out DnsServerBlockingType blockingType))
if (request.TryGetQueryOrFormEnum("blockingType", out DnsServerBlockingType blockingType))
_dnsWebService.DnsServer.BlockingType = blockingType;
string customBlockingAddresses = request.QueryOrForm("customBlockingAddresses");
@@ -1100,7 +1100,7 @@ namespace DnsServerCore
}
//proxy & forwarders
if (request.TryGetQueryOrForm("proxyType", out NetProxyType proxyType))
if (request.TryGetQueryOrFormEnum("proxyType", out NetProxyType proxyType))
{
if (proxyType == NetProxyType.None)
{
@@ -1129,7 +1129,7 @@ namespace DnsServerCore
}
else
{
DnsTransportProtocol forwarderProtocol = request.GetQueryOrForm("forwarderProtocol", DnsTransportProtocol.Udp);
DnsTransportProtocol forwarderProtocol = request.GetQueryOrFormEnum("forwarderProtocol", DnsTransportProtocol.Udp);
switch (forwarderProtocol)
{