Example #1
0
 ///<summary>Called when we receive a reply from the FTP server.</summary>
 ///<param name="ar">The result of the asynchronous operation.</param>
 private void OnReplyReceived(IAsyncResult ar)
 {
     try
     {
         int Ret = DestinationSocket.EndReceive(ar);
         if (Ret <= 0)
         {
             Dispose();
             return;
         }
         if (DataForward != null && DataForward.ExpectsReply)
         {
             if (!DataForward.ProcessPasvReplyRecv(Encoding.ASCII.GetString(RemoteBuffer, 0, Ret)))
             {
                 DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnReplyReceived), DestinationSocket);
             }
         }
         else
         {
             ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(OnReplySent), ClientSocket);
         }
     }
     catch
     {
         Dispose();
     }
 }
Example #2
0
 ///<summary>Called when we receive a reply from the FTP server that should be ignored.</summary>
 ///<param name="ar">The result of the asynchronous operation.</param>
 private void OnIgnoreReply(IAsyncResult ar)
 {
     try
     {
         int Ret = DestinationSocket.EndReceive(ar);
         if (Ret <= 0)
         {
             Dispose();
             return;
         }
         FtpReply += Encoding.ASCII.GetString(RemoteBuffer, 0, Ret);
         if (IsValidReply(FtpReply))
         {
             DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnReplyReceived), DestinationSocket);
             DestinationSocket.BeginSend(Encoding.ASCII.GetBytes(User), 0, User.Length, SocketFlags.None, new AsyncCallback(OnCommandSent), DestinationSocket);
         }
         else
         {
             DestinationSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, new AsyncCallback(OnIgnoreReply), DestinationSocket);
         }
     }
     catch
     {
         Dispose();
     }
 }
Example #3
0
 ///<summary>Called when we have received data from the remote host.<br>Incoming data will immediately be forwarded to the local client.</br></summary>
 ///<param name="ar">The result of the asynchronous operation.</param>
 protected void OnRemoteReceive(IAsyncResult ar)
 {
     try {
         int Ret = DestinationSocket.EndReceive(ar);
         if (Ret <= 0)
         {
             Dispose();
             return;
         }
         ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(this.OnClientSent), ClientSocket);
     } catch {
         Dispose();
     }
 }
Example #4
0
 protected void OnRemoteReceive(IAsyncResult ar)
 {
     try
     {
         var ret = DestinationSocket.EndReceive(ar);
         if (ret <= 0)
         {
             Dispose();
             return;
         }
         ClientSocket.BeginSend(RemoteBuffer, 0, ret, SocketFlags.None, OnClientSent, ClientSocket);
     }
     catch
     {
         Dispose();
     }
 }
Example #5
0
 ///<summary>Called when we have received data from the remote host.<br>Incoming data will immediately be forwarded to the local client.</br></summary>
 ///<param name="ar">The result of the asynchronous operation.</param>
 protected void OnRemoteReceive(IAsyncResult ar)
 {
     try
     {
         int Ret = DestinationSocket.EndReceive(ar);
         if (Ret <= 0)
         {
             Dispose();
             return;
         }
         ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(this.OnClientSent), ClientSocket);
         CompleteReadBuffer += System.Text.Encoding.ASCII.GetString(RemoteBuffer, 0, Ret);
     }
     catch
     {
         Dispose();
     }
 }
Example #6
0
        public void OnRemoteReceive(IAsyncResult ar)
        {
            try
            {
                if (DestinationSocket == null)
                {
                    return;
                }

                int size = DestinationSocket.EndReceive(ar);
                if (size > 0 && ClientSocket != null)
                {
                    ClientSocket.BeginSend(RemoteBuffer, 0, size, SocketFlags.None, OnClientSent, ClientSocket);
                }
            }
            catch
            {
                Dispose();
            }
        }
Example #7
0
        ///<summary>Called when we have received data from the remote host.<br>Incoming data will immediately be forwarded to the local client.</br></summary>
        ///<param name="ar">The result of the asynchronous operation.</param>
        protected void OnRemoteReceive(IAsyncResult ar)
        {
            int Ret = 0;

            try {
                Ret = DestinationSocket.EndReceive(ar);
                if (Ret <= 0)
                {
                    Dispose();
                    return;
                }
            }
            catch {
                try{
                    Dispose();
                } catch {}
            }
            try{
                //just before it goes out, HTTP and HTTPs
                if (toggleReq)
                {
                    lock ((object)newreq){
                        //lets just make sure that there is something to submit...
                        if (newreq.header.Length >= 2)
                        {
                            int maxlen   = ByteLength(RemoteBuffer);
                            int cutpoint = 1024;
                            if (cutpoint > maxlen)
                            {
                                cutpoint = maxlen;
                            }
                            string moo = Encoding.ASCII.GetString(RemoteBuffer, 0, cutpoint);
                            //just in case
                            moo            += "\r\n\r\n";
                            newreq.response = moo.Substring(0, moo.IndexOf("\r\n\r\n"));
                            newreq.isSSL    = isThisSSL;
                            toggleReq       = false;
                            WebProxy.Requests.Add(newreq);
                        }
                    }
                }
            } catch {
                //really - there is no request
                toggleReq = false;
            }
            try{
                //search and replace - Incoming
                byte[] ReplacedBuffer = SearchandReplace(RemoteBuffer, "o", "o", Ret);
                foreach (string item in Mentalis.Proxy.WebProxy.SRListIncoming)
                {
                    string[] parts = item.Split('\t');
                    ReplacedBuffer = SearchandReplace(ReplacedBuffer, parts[0], parts[1], Ret);
                }

                ClientSocket.BeginSend(ReplacedBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(this.OnClientSent), ClientSocket);
            } catch {
                try{
                    Dispose();
                } catch {}
            }
        }
Example #8
0
        ///<summary>Called when we have received data from the remote host.<br>Incoming data will immediately be forwarded to the local client.</br></summary>
        ///<param name="ar">The result of the asynchronous operation.</param>
        protected void OnRemoteReceive(IAsyncResult ar)
        {
            lock (_bufferLock)
            {
                try
                {
                    if (DestinationSocket == null)
                    {
                        return;
                    }

                    int Ret = DestinationSocket.EndReceive(ar);
                    if (Ret <= 0)
                    {
                        if (OnRemoteReceivedEnd != null)
                        {
                            if (_cachedRemoteBuffer != null)
                            {
                                //OnRemoteReceivedEnd.BeginInvoke(DestinationSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer, true, null, null);
                                OnRemoteReceivedEnd.Invoke(DestinationSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer.Count == 0 ? null : _cachedRemoteBuffer, true);
                            }
                            else
                            {
                                OnRemoteReceivedEnd.Invoke(DestinationSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer, true);
                            }
                        }

                        if (OnClientSentEnd != null)
                        {
                            if (_cachedRemoteBufferHeaders != null)
                            {
                                //OnClientSentEnd.BeginInvoke(ClientSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer, true, null, null);
                                OnClientSentEnd.Invoke(ClientSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer.Count == 0 ? null : _cachedRemoteBuffer, true);
                            }
                            else
                            {
                                OnClientSentEnd.Invoke(ClientSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer, true);
                            }
                        }

                        Dispose();
                        return;
                    }
                    _cachedRemoteBuffer.AddRange(RemoteBuffer);
                    if (_cacheRemoteBufferHeaders)
                    {
                        _cachedRemoteBufferHeaders = Encoding.Default.GetString(_cachedRemoteBuffer.ToArray()).TrimEnd("\0".ToCharArray());

                        int index = _cachedRemoteBufferHeaders.IndexOf("\r\n\r\n");
                        if (index != -1)
                        {
                            _cachedRemoteBufferHeaders = _cachedRemoteBufferHeaders.Substring(0, index);

                            _cacheRemoteBufferHeaders = false;
                            if (Ret != index + 4)
                            {
                                _cachedRemoteBuffer = _cachedRemoteBuffer.GetRange(index + 4, _cachedRemoteBuffer.Count - index - 4);
                            }
                            else
                            {
                                _cachedClientBuffer.Clear();
                                _cachedRemoteBuffer.Clear();
                            }

                            if (OnRemoteHeadersParsed != null)
                            {
                                OnRemoteHeadersParsed.Invoke(_cachedRemoteBufferHeaders);
                            }
                        }
                    }
                    if (OnRemoteReceivedEnd != null)
                    {
                        OnRemoteReceivedEnd.Invoke(DestinationSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer.Count == 0 ? null : _cachedRemoteBuffer, false);
                        //OnRemoteReceivedEnd.BeginInvoke(DestinationSocket, this, _cachedRemoteBufferHeaders, _cachedRemoteBuffer.Count == 0 ? null : _cachedRemoteBuffer, false, null, null);
                    }
                    if (!Cancel)
                    {
                        ClientSocket.BeginSend(RemoteBuffer, 0, Ret, SocketFlags.None, new AsyncCallback(OnClientSent), ClientSocket);
                    }
                    else
                    {
                        Dispose();
                    }
                }
                catch
                {
                    Dispose();
                }
            }
        }