[Dnsmail-cvs] dnsmail DnsCache.cs,1.5,1.6
Brought to you by:
ethem
From: Ethem E. <et...@us...> - 2006-08-07 10:12:33
|
Update of /cvsroot/dnsmail/dnsmail In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv456/dnsmail Modified Files: DnsCache.cs Log Message: InternalResolve prototype changed. Coding art. tabs, spaces, etc... :) Index: DnsCache.cs =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/DnsCache.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DnsCache.cs 7 Aug 2006 08:43:41 -0000 1.5 --- DnsCache.cs 7 Aug 2006 10:12:29 -0000 1.6 *************** *** 8,15 **** using Erle.DnsMail; using System.Net; ! internal sealed class DnsCache { ! private DnsCache(){} private const double REMOVECACHEAFTER = 10.0D; private static Hashtable m_CacheTbl = new Hashtable(); --- 8,15 ---- using Erle.DnsMail; using System.Net; ! internal sealed class DnsCache { ! private DnsCache() { } private const double REMOVECACHEAFTER = 10.0D; private static Hashtable m_CacheTbl = new Hashtable(); *************** *** 33,37 **** } #endregion ! internal static MxRecord[] GetFromCache(String domain) { --- 33,37 ---- } #endregion ! internal static MxRecord[] GetFromCache(String domain) { *************** *** 49,53 **** } } ! catch {} return null; } --- 49,53 ---- } } ! catch { } return null; } *************** *** 63,79 **** m_CacheTbl[domain] = new CacheEntry(data); } ! catch{} finally { Monitor.Exit(m_CacheTbl); } } ! private static void DeleteAll() { m_NextUpdate = NextUpdate(); ! Monitor.Enter( m_CacheTbl ); try { m_CacheTbl.Clear(); } ! catch {} finally { --- 63,79 ---- m_CacheTbl[domain] = new CacheEntry(data); } ! catch { } finally { Monitor.Exit(m_CacheTbl); } } ! private static void DeleteAll() { m_NextUpdate = NextUpdate(); ! Monitor.Enter(m_CacheTbl); try { m_CacheTbl.Clear(); } ! catch { } finally { *************** *** 90,94 **** DeletedAll(typeof(DnsCache), e); } ! catch {} } --- 90,94 ---- DeletedAll(typeof(DnsCache), e); } ! catch { } } *************** *** 98,113 **** 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++; } --- 98,113 ---- 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++; } *************** *** 117,127 **** } } ! return ( (labelCount > 0) && (labelCount < 5) ); } internal static event EventHandler DeletedAll; ! 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; --- 117,127 ---- } } ! return ((labelCount > 0) && (labelCount < 5)); } internal static event EventHandler DeletedAll; ! internal static void InternalResolve(ref string mailHost, ref bool usedMx, out MxRecord[] mxss, out IPAddress[] ips) { ! if (mailHost == null || mailHost == String.Empty || mailHost == "localhost" || mailHost == "127.0.0.1") mailHost = DNSAPI.LocalHost; *************** *** 129,160 **** 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)); } static void Log(String log) { --- 129,164 ---- if (mailHost[0] >= '1' && mailHost[0] <= '9' && IsIp4(mailHost)) { + ips = new IPAddress[] { IPAddress.Parse(mailHost) }; + mxss = null; usedMx = false; ! return; } ! if (usedMx) { mxss = DNSAPI.GetMxRecords(mailHost); if (mxss != null && mxss.Length > 0) { ! ips = null; ! return; } } ! try { ! ips = Dns.Resolve(mailHost).AddressList; ! if (ips != null && ips.Length > 0) { + mxss = null; usedMx = false; ! return; } } ! catch { } throw new DnsException(String.Format("No" + ! ((usedMx) ? " MaileXchange (MX) or" : String.Empty) ! + " IP (A) record could be found for {0}.", mailHost)); } + static void Log(String log) { *************** *** 168,172 **** internal static void Debug() { ! if (m_CacheTbl == null) return; --- 172,176 ---- internal static void Debug() { ! if (m_CacheTbl == null) return; *************** *** 176,180 **** StringBuilder sb = new StringBuilder(); sb.Append("<ul>" + crlf); ! for(IDictionaryEnumerator iex = m_CacheTbl.GetEnumerator();iex.MoveNext();) { ce = (CacheEntry)iex.Value; --- 180,184 ---- StringBuilder sb = new StringBuilder(); sb.Append("<ul>" + crlf); ! for (IDictionaryEnumerator iex = m_CacheTbl.GetEnumerator(); iex.MoveNext(); ) { ce = (CacheEntry)iex.Value; *************** *** 183,191 **** MxRecord[] ht = ce.RecordObj as MxRecord[]; sb.Append("<li><b>" + iex.Key + "</b> (" + ce.DeleteTime + ")" + crlf + " <ul>" + crlf); ! for(int im = 0; im < ht.Length; im++) { sb.AppendFormat("\t<li>{0} (", ht[im].NameExchange); ArrayList ips = ht[im].IPAddresses; ! for(int i = 0; i < ips.Count; i++) sb.Append(ips[i].ToString() + ", "); sb.Append(")" + crlf); --- 187,195 ---- MxRecord[] ht = ce.RecordObj as MxRecord[]; sb.Append("<li><b>" + iex.Key + "</b> (" + ce.DeleteTime + ")" + crlf + " <ul>" + crlf); ! for (int im = 0; im < ht.Length; im++) { sb.AppendFormat("\t<li>{0} (", ht[im].NameExchange); ArrayList ips = ht[im].IPAddresses; ! for (int i = 0; i < ips.Count; i++) sb.Append(ips[i].ToString() + ", "); sb.Append(")" + crlf); *************** *** 196,200 **** sb.Append("</ul>" + crlf); System.Web.HttpContext.Current.Response.Write(sb.ToString()); ! } } --- 200,204 ---- sb.Append("</ul>" + crlf); System.Web.HttpContext.Current.Response.Write(sb.ToString()); ! } } |