WildIp: code refactoring changes done.

This commit is contained in:
Shreyas Zare
2024-02-04 17:08:59 +05:30
parent 14d5af31a6
commit cedb5380d2

View File

@@ -1,6 +1,6 @@
/* /*
Technitium DNS Server Technitium DNS Server
Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com) Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -26,10 +26,13 @@ using TechnitiumLibrary.Net.Dns.ResourceRecords;
namespace WildIp namespace WildIp
{ {
public class App : IDnsApplication, IDnsAppRecordRequestHandler public sealed class App : IDnsApplication, IDnsAppRecordRequestHandler
{ {
#region variables #region variables
static readonly char[] aRecordSeparator = new char[] { '.', '-' };
static readonly char[] aaaaRecordSeparator = new char[] { '.' };
IDnsServer _dnsServer; IDnsServer _dnsServer;
#endregion #endregion
@@ -66,7 +69,7 @@ namespace WildIp
case DnsResourceRecordType.A: case DnsResourceRecordType.A:
{ {
string subdomain = qname.Substring(0, qname.Length - appRecordName.Length); string subdomain = qname.Substring(0, qname.Length - appRecordName.Length);
string[] parts = subdomain.Split(new char[] { '.', '-' }, StringSplitOptions.RemoveEmptyEntries); string[] parts = subdomain.Split(aRecordSeparator, StringSplitOptions.RemoveEmptyEntries);
byte[] rawIp = new byte[4]; byte[] rawIp = new byte[4];
int i = 0; int i = 0;
@@ -84,7 +87,7 @@ namespace WildIp
case DnsResourceRecordType.AAAA: case DnsResourceRecordType.AAAA:
{ {
string subdomain = qname.Substring(0, qname.Length - appRecordName.Length - 1); string subdomain = qname.Substring(0, qname.Length - appRecordName.Length - 1);
string[] parts = subdomain.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string[] parts = subdomain.Split(aaaaRecordSeparator, StringSplitOptions.RemoveEmptyEntries);
IPAddress address = null; IPAddress address = null;
foreach (string part in parts) foreach (string part in parts)
@@ -102,7 +105,7 @@ namespace WildIp
if (addr is null) if (addr is null)
addr = part.Substring(i, 4); addr = part.Substring(i, 4);
else else
addr += ":" + part.Substring(i, 4); addr += string.Concat(":", part.AsSpan(i, 4));
} }
if (IPAddress.TryParse(addr, out address)) if (IPAddress.TryParse(addr, out address))