⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionmanagerimp.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                return false;
            }
        }

        private void RegHTSipConnection(SipConnectionImp myImp, TcpSipConnectionOption tcpOption)
        {
            if ((string.Compare(Imps.Client.Core.FixedClientSetting.Instance.HTMode, "off", true) != 0) && ((string.Compare(Imps.Client.Core.FixedClientSetting.Instance.HTMode, "nav", true) != 0) || !string.IsNullOrEmpty(this._User.Configuration.SystemSetting.ServerUriSetting.SipcSslProxy)))
            {
                myImp.RegisterConnectionType(typeof(Imps.Client.CommLayer.HTSipConnection.HTSipConnection), tcpOption);
            }
        }

        public void Reset()
        {
            if (this.IsHttpConnectionInitialized)
            {
                this.IsHttpConnectionInitialized = false;
            }
        }

        public void TestConnection(TestConnectionCallBack callBack, IConnectionConfigation configation, ConnectionType connectionType)
        {
            try
            {
                switch (connectionType)
                {
                    case ConnectionType.Direct:
                        this.TestDirect(callBack, configation);
                        return;

                    case ConnectionType.SocksProxy:
                        if (!VerfiyProxyHost(configation.SocksProxyHost))
                        {
                            break;
                        }
                        this.TestSocksProxy(callBack, configation);
                        return;

                    case ConnectionType.HttpProxy:
                        if (!configation.UseIeProxy && !VerfiyProxyHost(configation.HttpProxyHost))
                        {
                            goto Label_0064;
                        }
                        this.TestHttpProxy(callBack, configation);
                        return;

                    default:
                        return;
                }
                DoCallBack(callBack, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.SocksProxyHostError);
                return;
            Label_0064:
                DoCallBack(callBack, TestConnectionStatus.Failed, "HTTP 代理服务器地址不正确!");
            }
            catch
            {
                try
                {
                    DoCallBack(callBack, TestConnectionStatus.Failed, "未知原因导致连接测试失败!");
                }
                catch
                {
                }
            }
        }

        private void TestDirect(TestConnectionCallBack callback, IConnectionConfigation configation)
        {
            string serverHost;
            int serverPort;
            DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.QueryNavigator);
            IWebProxy webProxy = FixWebProxy(configation.HttpProxyHost, configation.HttpProxyPort, configation.HttpProxyUserName, configation.HttpProxyPassword, configation.UseDirect, configation.UseHttpProxy, configation.UseIeProxy);
            if (!this.QueryNavigator(out serverHost, out serverPort, webProxy))
            {
                DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.QueryNatigatorFailed);
            }
            else
            {
                <>c__DisplayClass2 class2;
                DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.QueryNavigatorSuccessed);
                DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.TestConnectServer);
                TcpSipConnectionOption option = new TcpSipConnectionOption();
                Imps.Client.CommLayer.TcpSipConnection.TcpSipConnection connection = new Imps.Client.CommLayer.TcpSipConnection.TcpSipConnection(null, option);
                this._tcpTestWaitEvent = new ManualResetEvent(false);
                this._doTcpTestSuccessed = false;
                IicUri uri = this._User.Uri;
                this._User.Uri = new IicUri("sip:13910000000@fetion.com.cn");
                connection.StateChanged += new EventHandler<StateChangedEventArgs>(class2, (IntPtr) this.<TestDirect>b__0);
                connection.ConnectFailed += new EventHandler<FailedEventArgs>(this, (IntPtr) this.<TestDirect>b__1);
                if ((webProxy != null) && !TestHttps(webProxy))
                {
                    DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.TestConnectionFailed);
                }
                else
                {
                    connection.Connect(serverHost, serverPort);
                    this._tcpTestWaitEvent.WaitOne(0x927c0, true);
                    this._User.Uri = uri;
                    if (!this._doTcpTestSuccessed)
                    {
                        try
                        {
                            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl);
                            request.Proxy = null;
                            request.KeepAlive = false;
                            ((HttpWebResponse) request.GetResponse()).Close();
                            DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.TestConnectionSuccessed);
                            DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.TestConnectionAllSuccessed);
                        }
                        catch
                        {
                            DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.TestConnectionFailed);
                        }
                    }
                }
            }
        }

        private void TestHttpProxy(TestConnectionCallBack callback, IConnectionConfigation configation)
        {
            string serverHost;
            int serverPort;
            string httpTurnal;
            string ssiUrl;
            DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.QueryNavigator);
            IWebProxy webProxy = FixWebProxy(configation.HttpProxyHost, configation.HttpProxyPort, configation.HttpProxyUserName, configation.HttpProxyPassword, false, configation.UseHttpProxy, configation.UseIeProxy);
            if (!this.QueryNavigator(out serverHost, out serverPort, out httpTurnal, out ssiUrl, webProxy))
            {
                DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.QueryNatigatorFailed);
            }
            else
            {
                DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.QueryNavigatorSuccessed);
                DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.TestConnectServer);
                try
                {
                    if (QueryTestPage(httpTurnal, webProxy, true) && QueryTestPage(ssiUrl, webProxy, true))
                    {
                        DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.TestConnectionSuccessed);
                        DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.TestConnectionAllSuccessed);
                    }
                    else
                    {
                        DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.TestConnectionFailed);
                    }
                }
                catch (Exception exception)
                {
                    if ((exception is WebException) && (((WebException) exception).Status == ((WebExceptionStatus) 0x1f6)))
                    {
                        DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.TestConnectionHttpsNotSupported);
                    }
                    DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.TestConnectionFailed);
                }
            }
        }

        private static bool TestHttps(IWebProxy webProxy)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create(Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl);
                request.Method = "GET";
                request.KeepAlive = false;
                request.Proxy = webProxy;
                ((HttpWebResponse) request.GetResponse()).Close();
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void TestSocksProxy(TestConnectionCallBack callback, IConnectionConfigation configaion)
        {
            if (!configaion.UseHttpProxy && !configaion.UseDirect)
            {
                DoCallBack(callback, TestConnectionStatus.Failed, StringTable.ClientCommLayerString.OnSelectSocksConnectionTypeError);
            }
            else
            {
                string serverHost;
                int serverPort;
                DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.QueryNavigator);
                IWebProxy webProxy = FixWebProxy(configaion.HttpProxyHost, configaion.HttpProxyPort, configaion.HttpProxyUserName, configaion.HttpProxyPassword, configaion.UseDirect, configaion.UseHttpProxy, configaion.UseIeProxy);
                if (!this.QueryNavigator(out serverHost, out serverPort, webProxy))
                {
                    DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.QueryNatigatorFailed);
                }
                else
                {
                    DoCallBack(callback, TestConnectionStatus.Successed, StringTable.NetworkSettingOption.QueryNavigatorSuccessed);
                    if ((webProxy != null) && !TestHttps(webProxy))
                    {
                        DoCallBack(callback, TestConnectionStatus.Failed, StringTable.NetworkSettingOption.TestConnectionFailed);
                    }
                    else
                    {
                        <>c__DisplayClass6 class2;
                        SocksSipConnectionOption option = new SocksSipConnectionOption(configaion.SocksProxyHost, configaion.SocksProxyPort, configaion.SocksProxyUserName, configaion.SocksProxyPassword);
                        Imps.Client.CommLayer.SocksSipConnection.SocksSipConnection connection = new Imps.Client.CommLayer.SocksSipConnection.SocksSipConnection(null, option);
                        DoCallBack(callback, TestConnectionStatus.Info, StringTable.NetworkSettingOption.TestConnectServer);
                        ManualResetEvent @event = new ManualResetEvent(false);
                        connection.StateChanged += new EventHandler<StateChangedEventArgs>(class2, (IntPtr) this.<TestSocksProxy>b__4);
                        connection.ConnectFailed += new EventHandler<FailedEventArgs>(class2, (IntPtr) this.<TestSocksProxy>b__5);
                        connection.Connect(serverHost, serverPort);
                        @event.WaitOne(0x927c0, true);
                    }
                }
            }
        }

        private static bool TestWebProxy(IWebProxy webProxy)
        {
            try
            {
                Trace.WriteLine(string.Format("[{0:HH-mm-ss.ffff}]TestWebProxy - " + Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl, DateTime.Now));
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create(Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl);
                if (webProxy == null)
                {
                    request.Timeout = 0x1f40;
                }
                request.Method = "GET";
                request.Proxy = webProxy;
                request.KeepAlive = false;
                ((HttpWebResponse) request.GetResponse()).Close();
                LogTestHttpProxy(webProxy, true);
                return true;
            }
            catch (Exception)
            {
                LogTestHttpProxy(webProxy, false);
                return false;
            }
        }

        private static bool ValidateSSLCert(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }

        public static bool VerfiyProxyHost(string host)
        {
            try
            {
                IPAddress address;
                if (string.IsNullOrEmpty(host))
                {
                    return false;
                }
                Regex regex = new Regex(@"^[a-zA-Z0-9\-]{1,15}$");
                if (regex.IsMatch(host) && !AreAllCharsNumber(host))
                {
                    return true;
                }
                if ((host.IndexOf('.') > 0) && IPAddress.TryParse(host, ref address))
                {
                    return true;
                }
                Regex regex2 = new Regex(@"^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$");
                return regex2.IsMatch(host);
            }
            catch
            {
                return false;
            }
        }

        public bool DoTcpTestSuccessed
        {
            get
            {
                return this._doTcpTestSuccessed;
            }
            set
            {
                this._doTcpTestSuccessed = value;
            }
        }

        public ManualResetEvent TcpTestWaitEvent
        {
            get
            {
                return this._tcpTestWaitEvent;
            }
        }

        public IWebProxy WebProxy
        {
            get
            {
                if (!this.IsHttpConnectionInitialized)
                {
                    lock (this)
                    {
                        if (!this.IsHttpConnectionInitialized)
                        {
                            this._webProxy = FixWebProxy();
                            this.LogProxyInfo();
                            this.IsHttpConnectionInitialized = true;
                        }
                    }
                }
                return this._webProxy;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -