[Dnsmail-cvs] dnsmail DNSAPI.cs, 1.3, 1.4 Erle.DnsMail.csproj, 1.4, 1.5 DnsCache.cs, 1.3, NONE
Brought to you by:
ethem
From: Ethem E. <et...@us...> - 2006-08-04 15:23:04
|
Update of /cvsroot/dnsmail/dnsmail In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv25008/dnsmail Modified Files: DNSAPI.cs Erle.DnsMail.csproj Removed Files: DnsCache.cs Log Message: DnsCache removed. Index: Erle.DnsMail.csproj =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/Erle.DnsMail.csproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Erle.DnsMail.csproj 4 Aug 2006 12:53:36 -0000 1.4 --- Erle.DnsMail.csproj 4 Aug 2006 15:22:59 -0000 1.5 *************** *** 100,108 **** /> <File - RelPath = "DnsCache.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "MIME.cs" SubType = "Code" --- 100,103 ---- *************** *** 158,159 **** --- 153,155 ---- </CSHARP> </VisualStudioProject> + Index: DNSAPI.cs =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/DNSAPI.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DNSAPI.cs 21 Mar 2006 18:52:32 -0000 1.3 --- DNSAPI.cs 4 Aug 2006 15:22:59 -0000 1.4 *************** *** 10,32 **** using MxRecord = Erle.DnsMail.MxRecord; using MxRecordComparer = Erle.DnsMail.MxRecordComparer; public sealed class DNSAPI { private DNSAPI(){} - static DNSAPI() - { - DnsCache.DeletedAll += new EventHandler(DeletedAll); - } - - #region DeletedAll - private static void DeletedAll(object sender, EventArgs e) - { - dnsServers = null; - localHost = null; - hello = null; - - GC.Collect(); - } - #endregion #region LocalHost --- 10,18 ---- using MxRecord = Erle.DnsMail.MxRecord; using MxRecordComparer = Erle.DnsMail.MxRecordComparer; + using DnsException = Erle.DnsMail.DnsException; public sealed class DNSAPI { private DNSAPI(){} #region LocalHost *************** *** 101,108 **** return null; - MxRecord[] cache = DnsCache.GetFromCache(domain); - if (cache != null && cache.Length > 0) - return (cache); // struct-copy - IntPtr pQuery = IntPtr.Zero; UInt32 status = UnsafeNativeMethods.DnsQuery( --- 87,90 ---- *************** *** 115,119 **** ); ! if (status == STRUCTURES.SUCCESS && pQuery != IntPtr.Zero) { try --- 97,101 ---- ); ! if (status == STRUCTURES.SUCCESS && pQuery != IntPtr.Zero) { try *************** *** 141,145 **** // Resolve - bool err = false; for(int i = 0; i < mxs.Length; i++) { --- 123,126 ---- *************** *** 149,153 **** if (ipx == null || ipx.Length == 0) continue; foreach(IPAddress ipadr in ipx) mxs[i] += ipadr; - } catch(SocketException se) --- 130,133 ---- *************** *** 156,168 **** continue; // The requested name is valid, but no data of the requested type was found } ! catch ! { ! err = true; ! } } - - if (!err) - DnsCache.AddToCache(domain, mxs); - tmp.Clear(); return mxs; --- 136,141 ---- continue; // The requested name is valid, but no data of the requested type was found } ! catch {} } tmp.Clear(); return mxs; *************** *** 182,185 **** --- 155,224 ---- } #endregion + + #region InternalResolve + internal static IPAddress[] InternalResolve(ref string mailHost, ref bool usedMx, ref MxRecord[] mxss) + { + if( mailHost == null || mailHost == String.Empty || + mailHost == "localhost" || mailHost == "127.0.0.1") + mailHost = DNSAPI.LocalHost; + + if (mailHost[0] >= '1' && mailHost[0] <= '9' && IsIp4(mailHost)) + { + usedMx = false; + return new IPAddress[] { IPAddress.Parse(mailHost) }; + } + + if(usedMx) + { + mxss = DNSAPI.GetMxRecords(mailHost); + if (mxss != null && mxss.Length > 0) + { + usedMx = true; + return null; + } + } + + try + { + IPAddress[] addresses = Dns.Resolve(mailHost).AddressList; + if (addresses != null && addresses.Length > 0) + { + usedMx = false; + return addresses; + } + } + catch {} + throw new DnsException(String.Format("No" + + ( (usedMx) ? " MaileXchange (MX) or" : String.Empty ) + + " IP (A) record could be found for {0}.", mailHost)); + } + + private static bool IsIp4(string address) + { + if (address == null || + address == string.Empty || + address.IndexOf('.') == -1) + return false; + + int labelCount = 0, octet; + string[] ips = address.Split(new char[] {'.'}); + for(int i = 0; i < ips.Length; i++) + { + try + { + octet = int.Parse(ips[i]); + if ( ( octet < 0 ) || ( octet > 255 ) ) + return false; + else + labelCount++; + } + catch + { + return false; + } + } + return ( (labelCount > 0) && (labelCount < 5) ); + } + #endregion } }; --- DnsCache.cs DELETED --- |