示例#1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal void OnDisconnect(Inbound inbound)
        {
            inbound.Close();

            currentInboundListMutex_.WaitOne();
            currentInboundList_.Remove(inbound);
            currentInboundListMutex_.ReleaseMutex();
        }
示例#2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal void OnError(Inbound inbound, ProxyRequest request, Exception exception, string error)
        {
            string s = error + "\r\n";

            if (exception != null)
            {
                s += exception.Message + "\r\n";
                s += exception.StackTrace + "\r\n";
            }
            log_.Write("WwwProxy.OnError", s);

            OnErrorParams onErrorParams;

            onErrorParams.inbound   = inbound;
            onErrorParams.request   = request;
            onErrorParams.exception = exception;
            onErrorParams.error     = error;

            Thread onErrorThread = new Thread(new ParameterizedThreadStart(DoError));

            onErrorThread.Start(onErrorParams);
        }
示例#3
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal void OnConnect(Inbound inbound)
        {
        }
示例#4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        internal Outbound(WwwProxy wwwProxy, Inbound inbound, bool ssl, string host, ushort port)
        {
            wwwProxy_ = wwwProxy;
            inbound_  = inbound;

            ssl_  = ssl;
            host_ = host.ToLower();
            port_ = port;

            if (wwwProxy.remoteProxy_ != null)
            {
                if (wwwProxy_.remoteProxyExceptions_ != null)
                {
                    bool exceptionMatch = false;

                    bool     hostIsIp     = Regex.Match(host_, @"^[\*\d]{1,3}\.[\*\d]{1,3}\.[\*\d]{1,3}\.[\*\d]{1,3}$").Success;
                    string[] hostElements = host_.Split('.');

                    foreach (string e in wwwProxy_.remoteProxyExceptions_)
                    {
                        bool     exceptionIsIp     = Regex.Match(e, @"^[\*\d]{1,3}\.[\*\d]{1,3}\.[\*\d]{1,3}\.[\*\d]{1,3}$").Success;
                        string[] exceptionElements = e.Split('.');

                        if (hostIsIp == exceptionIsIp)
                        {
                            for (int i = 0; i < Math.Min(hostElements.Length, exceptionElements.Length); ++i)
                            {
                                string hostElement      = hostElements[hostIsIp ? i : hostElements.Length - i - 1];
                                string exceptionElement = exceptionElements[exceptionIsIp ? i : exceptionElements.Length - i - 1];

                                if ((hostElement != exceptionElement) && (exceptionElement != "*"))
                                {
                                    exceptionMatch = false;
                                    break;
                                }
                                else
                                {
                                    exceptionMatch = true;
                                }
                            }
                        }

                        if (exceptionMatch)
                        {
                            break;
                        }
                    }

                    if (!exceptionMatch)
                    {
                        outboundIpEndPoint_ = wwwProxy.remoteProxy_;
                        useRemoteProxy_     = true;
                    }
                }
                else
                {
                    outboundIpEndPoint_ = wwwProxy.remoteProxy_;
                    useRemoteProxy_     = true;
                }
            }

            if (outboundIpEndPoint_ == null)
            {
                if (Regex.Match(host, @"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$").Success)
                {
                    outboundIpEndPoint_ = new IPEndPoint(IPAddress.Parse(host_), port);
                }
                else
                {
                    outboundIpEndPoint_ = new IPEndPoint(IPAddress.Parse(System.Net.Dns.GetHostEntry(host_).AddressList[0].ToString()), port_);
                }
            }

            outboundThreadExitEvent_      = new ManualResetEvent(false);
            outboundSocketReceiveEvent_   = new ManualResetEvent(false);
            sslNetworkStreamReceiveEvent_ = new ManualResetEvent(false);
        }