Exemplo n.º 1
0
        public bool SmartStatusCallbackForHttpConnections(ServerType currentActiveServer, bool success)
        {
            if (this.IsSmartForwarderEnable)
            {
                SmartPear smart = this.Controller.SmartPear;
                if (!success)
                {
                    if (smart.ForwarderHttpEnable && smart.DetectorTimeoutEnable)
                    {
                        this.IsSmartForwarderEnable = false;
                        Http.DirectHandle(
                            this,
                            currentActiveServer.GetRequestedAddress(),
                            currentActiveServer.GetRequestedPort(),
                            this.SmartRequestBuffer);
                        return(false);
                    }
                }
                else
                {
                    if (smart.ForwarderHttpEnable && smart.DetectorDnsPoisoningEnable &&
                        currentActiveServer.UnderlyingSocket != null)
                    {
                        if (currentActiveServer.UnderlyingSocket.RemoteEndPoint != null &&
                            smart.DetectorDnsPoisoningRegEx.IsMatch(
                                ((IPEndPoint)currentActiveServer.UnderlyingSocket.RemoteEndPoint).Address.ToString()))
                        {
                            this.IsSmartForwarderEnable = false;
                            Http.DirectHandle(
                                this,
                                currentActiveServer.GetRequestedAddress(),
                                currentActiveServer.GetRequestedPort(),
                                this.SmartRequestBuffer);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool SmartDataReceivedCallbackForHttpConnections(ref byte[] binary, ServerType currentActiveServer)
        {
            SmartPear smart = this.Controller.SmartPear;

            if (smart.ForwarderHttpEnable)
            {
                // If we have Forwarder Enabled
                bool blocked = false;
                if (smart.DetectorStatusHttp && this.SmartResponseBuffer.Length < smart.DetectorHttpMaxBuffering)
                {
                    // If detector is enable and response is less than buffer size
                    byte[] smartResponseBuffer = this.SmartResponseBuffer;
                    Array.Resize(ref smartResponseBuffer, smartResponseBuffer.Length + binary.Length);
                    Array.Copy(
                        binary,
                        0,
                        smartResponseBuffer,
                        smartResponseBuffer.Length - binary.Length,
                        binary.Length);
                    Array.Resize(ref binary, 0);
                    // If Response is blocked
                    blocked = smart.DetectorHttpRegEx.IsMatch(Encoding.ASCII.GetString(smartResponseBuffer));
                    if (blocked && this.IsSmartForwarderEnable && currentActiveServer is NoServer)
                    {
                        blocked = false;
                        this.IsSmartForwarderEnable = false;
                    }
                    this.SmartResponseBuffer = smartResponseBuffer;
                }
                if (blocked)
                {
                    currentActiveServer.ReceiveDataDelegate = null;
                    if (this.IsSmartForwarderEnable)
                    {
                        // If client use NoServer
                        byte[] localReqBackup = new byte[this.SmartRequestBuffer.Length];
                        Array.Copy(this.SmartRequestBuffer, localReqBackup, localReqBackup.Length);
                        this.SmartCleanTheForwarder();
                        this.IsSmartForwarderEnable = false;
                        Http.DirectHandle(
                            this,
                            currentActiveServer.GetRequestedAddress(),
                            currentActiveServer.GetRequestedPort(),
                            localReqBackup);
                        return(false);
                    }
                }
                if (!blocked)
                {
                    // Response is OK
                    if (!this.IsSmartForwarderEnable &&
                        (smart.DetectorStatusHttp || smart.DetectorStatusDnsPoisoning || smart.DetectorStatusTimeout))
                    {
                        // If client use Proxy and one of possible detectors is enable
                        Uri url;
                        if (this.RequestAddress != string.Empty &&
                            Uri.TryCreate(this.RequestAddress, UriKind.Absolute, out url))
                        {
                            smart.AddRuleToHttpForwarder(
                                string.Format("*{0}*", url.Host.ToLower().TrimEnd(new[] { '/', '\\' })));
                        }

                        currentActiveServer.ReceiveDataDelegate = null;
                    }
                }

                if (this.SmartResponseBuffer.Length > 0 &&
                    (!this.IsSmartForwarderEnable ||
                     this.SmartResponseBuffer.Length >= smart.DetectorHttpMaxBuffering))
                {
                    // If we have any thing in Response and (Client use Proxy or NoServer but Response buffer is bigger than buffer)
                    this.SmartFlushTheForwarder(smart.ForwarderHttpEnable);
                    currentActiveServer.ReceiveDataDelegate = null;
                }
            }

            return(true);
        }