Esempio n. 1
0
        /// <summary>
        /// Cleans up any resource being used.
        /// </summary>
        public void Dispose()
        {
            lock (m_pLock)
            {
                if (this.State == DNS_ClientTransactionState.Disposed)
                {
                    return;
                }

                SetState(DNS_ClientTransactionState.Disposed);

                if (m_pTimeoutTimer != null)
                {
                    m_pTimeoutTimer.Dispose();
                    m_pTimeoutTimer = null;
                }

                m_pOwner = null;

                m_pResponse = null;

                this.StateChanged = null;
                this.Timeout      = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="owner">Owner DNS client.</param>
        /// <param name="dnsServers">DNS servers.</param>
        /// <param name="id">Transaction ID.</param>
        /// <param name="qtype">QTYPE value.</param>
        /// <param name="qname">QNAME value.</param>
        /// <param name="timeout">Timeout in milliseconds.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> or <b>qname</b> is null reference.</exception>
        internal DNS_ClientTransaction(Dns_Client owner, IPAddress[] dnsServers, int id, DNS_QType qtype, string qname, int timeout)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            if (dnsServers == null)
            {
                throw new ArgumentNullException("dnsServers");
            }
            if (qname == null)
            {
                throw new ArgumentNullException("qname");
            }

            m_pOwner      = owner;
            m_pDnsServers = dnsServers;
            m_ID          = id;
            m_QName       = qname;
            m_QType       = qtype;

            m_CreateTime             = DateTime.Now;
            m_pTimeoutTimer          = new TimerEx(timeout);
            m_pTimeoutTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_pTimeoutTimer_Elapsed);
        }
Esempio n. 3
0
        /// <summary>
        /// Resolves host name to IP addresses.
        /// </summary>
        /// <param name="host">Host name or IP address.</param>
        /// <returns>Return specified host IP addresses.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>host</b> is null.</exception>
        public static IPAddress[] Resolve(string host)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }

            // If hostName_IP is IP
            try
            {
                return(new IPAddress[] { IPAddress.Parse(host) });
            }
            catch
            {
            }

            // This is probably NetBios name
            if (host.IndexOf(".") == -1)
            {
                return(System.Net.Dns.GetHostEntry(host).AddressList);
            }
            else
            {
                // hostName_IP must be host name, try to resolve it's IP
                using (Dns_Client dns = new Dns_Client())
                {
                    DnsServerResponse resp = dns.Query(host, DNS_QType.A);
                    if (resp.ResponseCode == DNS_RCode.NO_ERROR)
                    {
                        DNS_rr_A[]  records = resp.GetARecords();
                        IPAddress[] retVal  = new IPAddress[records.Length];
                        for (int i = 0; i < records.Length; i++)
                        {
                            retVal[i] = records[i].IP;
                        }

                        return(retVal);
                    }
                    else
                    {
                        throw new Exception(resp.ResponseCode.ToString());
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="owner">Owner DNS client.</param>
        /// <param name="id">Transaction ID.</param>
        /// <param name="qtype">QTYPE value.</param>
        /// <param name="qname">QNAME value.</param>
        /// <param name="timeout">Timeout in milliseconds.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>owner</b> or <b>qname</b> is null reference.</exception>
        internal DNS_ClientTransaction(Dns_Client owner,int id,DNS_QType qtype,string qname,int timeout)
        {
            if(owner == null){
                throw new ArgumentNullException("owner");
            }
            if(qname == null){
                throw new ArgumentNullException("qname");
            }

            m_pOwner = owner;
            m_ID     = id;
            m_QName  = qname;
            m_QType  = qtype;
                        
            m_CreateTime    = DateTime.Now;
            m_pTimeoutTimer = new TimerEx(timeout);
            m_pTimeoutTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_pTimeoutTimer_Elapsed);
        }
Esempio n. 5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SIP_Stack()
        {            
            m_pTransportLayer = new SIP_TransportLayer(this);
            m_pTransactionLayer = new SIP_TransactionLayer(this);
            m_pNonceManager = new Auth_HttpDigest_NonceManager();
            m_pProxyServers = new List<SIP_Uri>();
            m_pRegistrations = new List<SIP_UA_Registration>();
            m_pCredentials = new List<NetworkCredential>();
            m_RegisterCallID = SIP_t_CallID.CreateCallID();
            
            m_pAllow = new List<string>();
            m_pAllow.AddRange(new string[]{"INVITE","ACK","CANCEL","BYE","MESSAGE"});

            m_pSupported = new List<string>();
                       
            m_pLogger = new Logger();

            m_pDnsClient = new Dns_Client();
        }
Esempio n. 6
0
        /// <summary>
        /// Cleans up any resource being used.
        /// </summary>
        public void Dispose()
        {
            lock(m_pLock){
                if(this.State == DNS_ClientTransactionState.Disposed){
                    return;
                }

                SetState(DNS_ClientTransactionState.Disposed);

                m_pTimeoutTimer.Dispose();
                m_pTimeoutTimer = null;

                m_pOwner = null;

                m_pResponse = null;

                this.StateChanged = null;
                this.Timeout = null;
            }
        }
Esempio n. 7
0
		/// <summary>
		/// Gets host name. If fails returns ip address.
		/// </summary>
		/// <param name="ip">IP address which to reverse lookup.</param>
		/// <returns>Returns host name of specified IP address.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>ip</b> is null.</exception>
		public static string GetHostName(IPAddress ip)
		{
            if(ip == null){
                throw new ArgumentNullException("ip");
            }

            string retVal = ip.ToString();
			try{
                Dns_Client dns = new Dns_Client();
                DnsServerResponse response = dns.Query(ip.ToString(),DNS_QType.PTR);
                if(response.ResponseCode == DNS_RCode.NO_ERROR){
                    DNS_rr_PTR[] ptrs = response.GetPTRRecords();
                    if(ptrs.Length > 0){
                        retVal = ptrs[0].DomainName;
                    }                    
                }
			}
			catch{
			}

            return retVal;
		}
Esempio n. 8
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public Relay_Server()
 {
     m_pQueues     = new List<Relay_Queue>();
     m_pSmartHosts = new CircleCollection<Relay_SmartHost>();
     m_pDsnClient  = new Dns_Client();
 }
Esempio n. 9
0
        /// <summary>
        /// Resolves host name to IP addresses.
        /// </summary>
        /// <param name="host">Host name or IP address.</param>
        /// <returns>Return specified host IP addresses.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>host</b> is null.</exception>
        public static IPAddress[] Resolve(string host)
        {
            if(host == null){
                throw new ArgumentNullException("host");
            }

            // If hostName_IP is IP
            try{
                return new IPAddress[]{IPAddress.Parse(host)};
            }
            catch{
            }

            // This is probably NetBios name
            if(host.IndexOf(".") == -1){
                return System.Net.Dns.GetHostEntry(host).AddressList;
            }
            else{
                // hostName_IP must be host name, try to resolve it's IP
                using(Dns_Client dns = new Dns_Client()){
                    DnsServerResponse resp = dns.Query(host,DNS_QType.A);
                    if(resp.ResponseCode == DNS_RCode.NO_ERROR){
                        DNS_rr_A[] records = resp.GetARecords();
                        IPAddress[] retVal = new IPAddress[records.Length];
                        for(int i=0;i<records.Length;i++){
                            retVal[i] = records[i].IP;
                        }

                        return retVal;
                    }
                    else{
                        throw new Exception(resp.ResponseCode.ToString());
                    }
                }
            }
        }
Esempio n. 10
0
            /// <summary>
            /// Starts operation processing.
            /// </summary>
            /// <param name="dnsClient">DNS client.</param>
            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
            /// <exception cref="ArgumentNullException">Is raised when <b>dnsClient</b> is null reference.</exception>
            internal bool Start(Dns_Client dnsClient)
            {   
                if(dnsClient == null){
                    throw new ArgumentNullException("dnsClient");
                }

                SetState(AsyncOP_State.Active);

                m_pHostEntries = new HostEntry[m_pHostNames.Length];

                // Create look up operations for hosts. The "opList" copy array is needed because
                // when we start asyn OP, m_pIpLookupQueue may be altered when OP completes.
                Dictionary<int,GetHostAddressesAsyncOP> opList = new Dictionary<int,GetHostAddressesAsyncOP>();
                for(int i=0;i<m_pHostNames.Length;i++){
                    GetHostAddressesAsyncOP op = new GetHostAddressesAsyncOP(m_pHostNames[i]);
                    m_pIpLookupQueue.Add(i,op);
                    opList.Add(i,op);
                }

                // Start operations.
                foreach(KeyValuePair<int,GetHostAddressesAsyncOP> entry in opList){
                    // NOTE: We may not access "entry" in CompletedAsync, because next for loop reassigns this value.
                    int index = entry.Key;

                    // This event is raised when GetHostAddressesAsync completes asynchronously.
                    entry.Value.CompletedAsync += delegate(object s1,EventArgs<GetHostAddressesAsyncOP> e1){                        
                        GetHostAddressesCompleted(e1.Value,index);
                    };                    
                    // GetHostAddressesAsync completes synchronously.
                    if(!dnsClient.GetHostAddressesAsync(entry.Value)){
                        GetHostAddressesCompleted(entry.Value,index);
                    }
                }

                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
                // If already completed sync, that flag has no effect.
                lock(m_pLock){
                    m_RiseCompleted = true;

                    return m_State == AsyncOP_State.Active;
                }
            }
Esempio n. 11
0
            /// <summary>
            /// Starts operation processing.
            /// </summary>
            /// <param name="dnsClient">DNS client.</param>
            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
            /// <exception cref="ArgumentNullException">Is raised when <b>dnsClient</b> is null reference.</exception>
            internal bool Start(Dns_Client dnsClient)
            {                
                if(dnsClient == null){
                    throw new ArgumentNullException("dnsClient");
                }

                SetState(AsyncOP_State.Active);

                // Argument 'hostNameOrIP' is IP address.
                if(Net_Utils.IsIPAddress(m_HostNameOrIP)){
                    m_pIPv4Addresses.Add(IPAddress.Parse(m_HostNameOrIP));

                    SetState(AsyncOP_State.Completed);
                }
                // This is probably NetBios name.
			    if(m_HostNameOrIP.IndexOf(".") == -1){
                    try{
                        // This callback is called when BeginGetHostAddresses method has completed.
                        AsyncCallback callback = delegate(IAsyncResult ar){
                            try{
                                foreach(IPAddress ip in  System.Net.Dns.EndGetHostAddresses(ar)){
                                    if(ip.AddressFamily == AddressFamily.InterNetwork){
                                        m_pIPv4Addresses.Add(ip);
                                    }
                                    else{
                                        m_pIPv6Addresses.Add(ip);
                                    }
                                }
                            }
                            catch(Exception x){
                                m_pException = x;
                            }

                            SetState(AsyncOP_State.Completed);
                        };

                        // Start resolving host ip addresses.
                        System.Net.Dns.BeginGetHostAddresses(m_HostNameOrIP,callback,null); 
                    }
                    catch(Exception x){
                        m_pException = x;
                    }
			    }
                // Query A/AAAA records.
                else{
                    #region A records transaction

                    DNS_ClientTransaction transaction_A = dnsClient.CreateTransaction(DNS_QType.A,m_HostNameOrIP,2000);
                    transaction_A.StateChanged += delegate(object s1,EventArgs<DNS_ClientTransaction> e1){ 
                        if(e1.Value.State == DNS_ClientTransactionState.Completed){
                            lock(m_pLock){ 
                                if(e1.Value.Response.ResponseCode != DNS_RCode.NO_ERROR){
                                    m_pException = new DNS_ClientException(e1.Value.Response.ResponseCode);
                                }
                                else{
                                    foreach(DNS_rr_A record in e1.Value.Response.GetARecords()){
                                        m_pIPv4Addresses.Add(record.IP);
                                    }
                                }

                                m_Counter++;

                                // Both A and AAAA transactions are completed, we are done.
                                if(m_Counter == 2){
                                    SetState(AsyncOP_State.Completed);
                                }
                            }
                        }
                    };
                    transaction_A.Timeout += delegate(object s1,EventArgs e1){
                        lock(m_pLock){
                            m_pException = new IOException("DNS transaction timeout, no response from DNS server.");
                            m_Counter++;

                            // Both A and AAAA transactions are completed, we are done.
                            if(m_Counter == 2){
                                SetState(AsyncOP_State.Completed);
                            }
                        }
                    };
                    transaction_A.Start();
                    
                    #endregion

                    #region AAAA records transaction

                    DNS_ClientTransaction transaction_AAAA = dnsClient.CreateTransaction(DNS_QType.AAAA,m_HostNameOrIP,2000);
                    transaction_AAAA.StateChanged += delegate(object s1,EventArgs<DNS_ClientTransaction> e1){
                        if(e1.Value.State == DNS_ClientTransactionState.Completed){
                            lock(m_pLock){
                                if(e1.Value.Response.ResponseCode != DNS_RCode.NO_ERROR){
                                    m_pException = new DNS_ClientException(e1.Value.Response.ResponseCode);
                                }
                                else{
                                    foreach(DNS_rr_AAAA record in e1.Value.Response.GetAAAARecords()){
                                        m_pIPv6Addresses.Add(record.IP);
                                    }
                                }

                                m_Counter++;

                                // Both A and AAAA transactions are completed, we are done.
                                if(m_Counter == 2){
                                    SetState(AsyncOP_State.Completed);
                                }
                            }
                        }
                    };
                    transaction_AAAA.Timeout += delegate(object s1,EventArgs e1){
                        lock(m_pLock){
                            m_pException = new IOException("DNS transaction timeout, no response from DNS server.");
                            m_Counter++;

                            // Both A and AAAA transactions are completed, we are done.
                            if(m_Counter == 2){
                                SetState(AsyncOP_State.Completed);
                            }
                        }
                    };
                    transaction_AAAA.Start();

                    #endregion
                }

                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
                // If already completed sync, that flag has no effect.
                lock(m_pLock){
                    m_RiseCompleted = true;

                    return m_State == AsyncOP_State.Active;
                }
            }
Esempio n. 12
0
        /// <summary>
        /// Stops this virtual server.
        /// </summary>
        public void Stop()
        {
            m_Running = false;

            if(m_pDnsClient != null){
                m_pDnsClient.Dispose();
                m_pDnsClient = null;
            }
            if(m_pSmtpServer != null){
                try{
                    m_pSmtpServer.Dispose();
                }
                catch{
                }
                m_pSmtpServer = null;
            }
            if(m_pPop3Server != null){
                try{
                    m_pPop3Server.Dispose();
                }
                catch{
                }
                m_pPop3Server = null;
            }
            if(m_pImapServer != null){
                try{
                    m_pImapServer.Dispose();
                }
                catch{
                }
                m_pImapServer = null;
            }
            if(m_pRelayServer != null){
                try{
                    m_pRelayServer.Dispose();
                }
                catch{
                }
                m_pRelayServer = null;
            }
            if(m_pFetchServer != null){
                try{
                    m_pFetchServer.Dispose();                    
                }
                catch{
                }
                m_pFetchServer = null;
            } 
            if(m_pSipServer != null){
                try{
                    m_pSipServer.Stack.Stop();                    
                }
                catch{
                }
                m_pSipServer = null;
            } 
            if(m_pTimer != null){
                try{
                    m_pTimer.Dispose();
                }
                catch{
                }
                m_pTimer = null;
            }
            if(m_pRecycleBinManager != null){
                try{
                    m_pRecycleBinManager.Dispose();
                }
                catch{
                }
                m_pRecycleBinManager = null;
            }
            if(m_pBadLoginManager != null){
                try{
                    m_pBadLoginManager.Dispose();
                }
                catch{
                }
                m_pBadLoginManager = null;
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Is called when smart hosts ip addresses resolve operation has completed.
        /// </summary>
        /// <param name="op">Asynchronous operation.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>op</b> is null reference.</exception>
        private void SmartHostsResolveCompleted(Dns_Client.GetHostsAddressesAsyncOP op)
        {
            if(op == null){
                throw new ArgumentNullException("op");
            }

            if(op.Error != null){
                LogText("Failed to resolve relay smart host(s) ip addresses with error: " + op.Error.Message + ".");

                Dispose(op.Error);
            }
            else{
                for(int i=0;i<op.HostEntries.Length;i++){
                    Relay_SmartHost smartHost = m_pSmartHosts[i];

                    foreach(IPAddress ip in op.HostEntries[i].Addresses){
                        m_pTargets.Add(new Relay_Target(smartHost.Host,new IPEndPoint(ip,smartHost.Port),smartHost.SslMode,smartHost.UserName,smartHost.Password));
                    }
                }                

                BeginConnect();
            }

            op.Dispose();
        }
Esempio n. 14
0
        /// <summary>
        /// Is called when email domain target servers resolve operation has completed.
        /// </summary>
        /// <param name="to">RCPT TO: address.</param>
        /// <param name="op">Asynchronous operation.</param>
        /// <exception cref="ArgumentNullException">Is raised when <b>to</b> or <b>op</b> is null reference.</exception>
        private void EmailHostsResolveCompleted(string to,Dns_Client.GetEmailHostsAsyncOP op)
        {
            if(to == null){
                throw new ArgumentNullException("to");
            }
            if(op == null){
                throw new ArgumentNullException("op");
            }
            
            if(op.Error != null){
                LogText("Failed to resolve email domain for email address '" + to + "' with error: " + op.Error.Message + ".");

                Dispose(op.Error);
            }
            else{
                StringBuilder buf = new StringBuilder();
                foreach(HostEntry host in op.Hosts){
                    foreach(IPAddress ip in host.Addresses){
                        m_pTargets.Add(new Relay_Target(host.HostName,new IPEndPoint(ip,25)));
                    }
                    buf.Append(host.HostName + " ");
                }
                LogText("Resolved to following email hosts: (" + buf.ToString().TrimEnd() + ").");

                BeginConnect();
            }

            op.Dispose();
        }
Esempio n. 15
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if(m_IsDisposed){
                return;
            }
            try{
                if(m_IsRunning){
                    Stop();
                }
            }
            catch{
            }
            m_IsDisposed = true;

            // Release events.
            this.Error = null;
            this.SessionCompleted = null;

            m_pQueues     = null;
            m_pSmartHosts = null;

            m_pDsnClient.Dispose();
            m_pDsnClient = null;
        }
Esempio n. 16
0
            /// <summary>
            /// Starts operation processing.
            /// </summary>
            /// <param name="dnsClient">DNS client.</param>
            /// <returns>Returns true if asynchronous operation in progress or false if operation completed synchronously.</returns>
            /// <exception cref="ArgumentNullException">Is raised when <b>dnsClient</b> is null reference.</exception>
            internal bool Start(Dns_Client dnsClient)
            {
                if(dnsClient == null){
                    throw new ArgumentNullException("dnsClient");
                }

                SetState(AsyncOP_State.Active);

                /* RFC 5321 5.
                    The lookup first attempts to locate an MX record associated with the
                    name.  If a CNAME record is found, the resulting name is processed as
                    if it were the initial name.
                 
			        If no MX records are found, but an A RR is found, the A RR is treated as if it 
                    was associated with an implicit MX RR, with a preference of 0, pointing to that host.
			    */

                try{
                    LookupMX(dnsClient,m_Domain,false);
                }
                catch(Exception x){
                    m_pException = x;
                    SetState(AsyncOP_State.Completed);
                }

                // Set flag rise CompletedAsync event flag. The event is raised when async op completes.
                // If already completed sync, that flag has no effect.
                lock(m_pLock){
                    m_RiseCompleted = true;

                    return m_State == AsyncOP_State.Active;
                }
            }
Esempio n. 17
0
            /// <summary>
            /// Starts looking up MX records for specified domain.
            /// </summary>
            /// <param name="dnsClient">DNS client.</param>
            /// <param name="domain">Domain name.</param>
            /// <param name="domainIsCName">If true domain name is CNAME(alias).</param>
            /// <exception cref="ArgumentNullException">Is riased when <b>dnsClient</b> or <b>domain</b> is null reference.</exception>
            private void LookupMX(Dns_Client dnsClient,string domain,bool domainIsCName)
            {
                if(dnsClient == null){
                    throw new ArgumentNullException("dnsClient");
                }
                if(domain == null){
                    throw new ArgumentNullException("domain");
                }

                // Try to get MX records.
                DNS_ClientTransaction transaction_MX = dnsClient.CreateTransaction(DNS_QType.MX,domain,2000);
                transaction_MX.StateChanged += delegate(object s1,EventArgs<DNS_ClientTransaction> e1){
                    try{
                        if(e1.Value.State == DNS_ClientTransactionState.Completed){
                            // No errors.
                            if(e1.Value.Response.ResponseCode == DNS_RCode.NO_ERROR){
                                List<DNS_rr_MX> mxRecords = new List<DNS_rr_MX>();
                                foreach(DNS_rr_MX mx in e1.Value.Response.GetMXRecords()){
                                    // Skip invalid MX records.
                                    if(string.IsNullOrEmpty(mx.Host)){
                                    }
                                    else{
                                        mxRecords.Add(mx);
                                    }
                                }

                                // Use MX records.
                                if(mxRecords.Count > 0){
                                    m_pHosts = new HostEntry[mxRecords.Count];
                                    
                                    // Create name to index map, so we can map asynchronous A/AAAA lookup results back to MX priority index.
                                    Dictionary<string,int> name_to_index_map = new Dictionary<string,int>();
                                    List<string>           lookupQueue       = new List<string>();

                                    // Process MX records.
                                    for(int i=0;i<m_pHosts.Length;i++){
                                        DNS_rr_MX mx = mxRecords[i];
                                    
                                        IPAddress[] ips = Get_A_or_AAAA_FromResponse(mx.Host,e1.Value.Response);
                                        // No A or AAAA records in addtional answers section for MX, we need todo new query for that.
                                        if(ips.Length == 0){
                                            name_to_index_map[mx.Host] = i;
                                            lookupQueue.Add(mx.Host);
                                        }
                                        else{
                                            m_pHosts[i] = new HostEntry(mx.Host,ips,null);
                                        }                                        
                                    }

                                    // We have MX records which A or AAAA records not provided in DNS response, lookup them.
                                    if(lookupQueue.Count > 0){
                                        GetHostsAddressesAsyncOP op = new GetHostsAddressesAsyncOP(lookupQueue.ToArray(),true);
                                        // This event is raised when lookup completes asynchronously.
                                        op.CompletedAsync += delegate(object s2,EventArgs<GetHostsAddressesAsyncOP> e2){
                                            LookupCompleted(op,name_to_index_map);
                                        };
                                        // Lookup completed synchronously.
                                        if(!dnsClient.GetHostsAddressesAsync(op)){
                                            LookupCompleted(op,name_to_index_map);
                                        }
                                    }
                                    // All MX records resolved.
                                    else{
                                        SetState(AsyncOP_State.Completed);
                                    }
                                }
                                // Use CNAME as initial domain name.
                                else if(e1.Value.Response.GetCNAMERecords().Length > 0){
                                    if(domainIsCName){
                                        m_pException = new Exception("CNAME to CNAME loop dedected.");
                                        SetState(AsyncOP_State.Completed);
                                    }
                                    else{
                                        LookupMX(dnsClient,e1.Value.Response.GetCNAMERecords()[0].Alias,true);
                                    }
                                }
                                // Use domain name as MX.
                                else{
                                    m_pHosts = new HostEntry[1];

                                    // Create name to index map, so we can map asynchronous A/AAAA lookup results back to MX priority index.
                                    Dictionary<string,int> name_to_index_map = new Dictionary<string,int>();
                                    name_to_index_map.Add(domain,0);

                                    GetHostsAddressesAsyncOP op = new GetHostsAddressesAsyncOP(new string[]{domain});
                                    // This event is raised when lookup completes asynchronously.
                                    op.CompletedAsync += delegate(object s2,EventArgs<GetHostsAddressesAsyncOP> e2){
                                        LookupCompleted(op,name_to_index_map);
                                    };
                                    // Lookup completed synchronously.
                                    if(!dnsClient.GetHostsAddressesAsync(op)){
                                        LookupCompleted(op,name_to_index_map);
                                    }
                                }
                            }
                            // DNS server returned error, just return error.
                            else{
                                m_pException = new DNS_ClientException(e1.Value.Response.ResponseCode);
                                SetState(AsyncOP_State.Completed);
                            }
                        }
                        transaction_MX.Timeout += delegate(object s2,EventArgs e2){
                            m_pException = new IOException("DNS transaction timeout, no response from DNS server.");
                            SetState(AsyncOP_State.Completed);
                        };
                    }
                    catch(Exception x){
                        m_pException = x;
                        SetState(AsyncOP_State.Completed);
                    }
                };
                transaction_MX.Start();
            }
Esempio n. 18
0
        public static string[] GetDomainHosts(string domain)
        {
            if(domain == null){
                throw new ArgumentNullException("domain");
            }
            if(string.IsNullOrEmpty(domain)){
                throw new ArgumentException("Invalid argument 'domain' value, you need to specify domain value.");
            }

            // We have email address, parse domain.
            if(domain.IndexOf("@") > -1){
                domain = domain.Substring(domain.IndexOf('@') + 1);
            }

            List<string> retVal = new List<string>();

            // Get MX records.
            using(Dns_Client dns = new Dns_Client()){
                DnsServerResponse response = dns.Query(domain,DNS_QType.MX);
                if(response.ResponseCode == DNS_RCode.NO_ERROR){
                    foreach(DNS_rr_MX mx in response.GetMXRecords()){
                        // Block invalid MX records.
                        if(!string.IsNullOrEmpty(mx.Host)){
                            retVal.Add(mx.Host);
                        }
                    }
                }
                else{
                    throw new DNS_ClientException(response.ResponseCode);
                }
            }

            /* RFC 2821 5.
			    If no MX records are found, but an A RR is found, the A RR is treated as if it 
                was associated with an implicit MX RR, with a preference of 0, pointing to that host.
			*/
            if(retVal.Count == 0){
                retVal.Add(domain);
            }

            return retVal.ToArray();
        }
Esempio n. 19
0
        /// <summary>
        /// Starts this virtual server.
        /// </summary>
        public void Start()
        {
            if(m_Running){
                return;
            }
            m_Running = true;

            m_pDnsClient = new Dns_Client();

            m_pSmtpServer = new SMTP_Server();
            m_pSmtpServer.Error += new LumiSoft.Net.ErrorEventHandler(OnServer_SysError);
            m_pSmtpServer.SessionCreated += new EventHandler<TCP_ServerSessionEventArgs<SMTP_Session>>(m_pSmtpServer_SessionCreated);

            m_pPop3Server = new POP3_Server();            
            m_pPop3Server.Error += new LumiSoft.Net.ErrorEventHandler(OnServer_SysError);            
            m_pPop3Server.SessionCreated += new EventHandler<TCP_ServerSessionEventArgs<POP3_Session>>(m_pPop3Server_SessionCreated);
                        
            m_pImapServer = new IMAP_Server();
            m_pImapServer.Error += new LumiSoft.Net.ErrorEventHandler(OnServer_SysError);
            m_pImapServer.SessionCreated += new EventHandler<TCP_ServerSessionEventArgs<IMAP_Session>>(m_pImapServer_SessionCreated);
            
            m_pRelayServer = new RelayServer(this);
            m_pRelayServer.DnsClient = m_pDnsClient;

            m_pFetchServer = new FetchPop3(this,m_pApi);

            m_pSipServer = new SIP_Proxy(new SIP_Stack());
            m_pSipServer.Authenticate += new SIP_AuthenticateEventHandler(m_pSipServer_Authenticate);
            m_pSipServer.IsLocalUri += new SIP_IsLocalUriEventHandler(m_pSipServer_IsLocalUri);
            m_pSipServer.AddressExists += new SIP_AddressExistsEventHandler(m_pSipServer_AddressExists);
            m_pSipServer.Registrar.CanRegister += new SIP_CanRegisterEventHandler(m_pSipServer_CanRegister);
            m_pSipServer.Stack.Error += new EventHandler<ExceptionEventArgs>(m_pSipServer_Error);
            
            m_pRecycleBinManager = new RecycleBinManager(m_pApi);
 
            m_pBadLoginManager = new BadLoginManager();

            m_pTimer = new System.Timers.Timer();            
            m_pTimer.Interval = 15000;
            m_pTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_pTimer_Elapsed);
            m_pTimer.Enabled = true;

            LoadSettings();
        }