Main Page | Alphabetical List | Class List | File List | Class Members | File Members

RemoteSocket.cpp

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2004  Anders Hedstrom
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 */
00023 //#include <stdio.h>
00024 
00025 #include "Socks4Handler.h"
00026 #include "Socks4Socket.h"
00027 #include "RemoteSocket.h"
00028 
00029 
00030 
00031 
00032 RemoteSocket::RemoteSocket(ISocketHandler& h)
00033 :TcpSocket(h)
00034 ,m_pRemote(NULL)
00035 {
00036 }
00037 
00038 
00039 RemoteSocket::~RemoteSocket()
00040 {
00041 }
00042 
00043 
00044 void RemoteSocket::OnConnect()
00045 {
00046         if (m_pRemote && Handler().Valid(m_pRemote))
00047         {
00048                 m_pRemote -> Connected();
00049         }
00050         else
00051         {
00052                 Handler().LogError(this, "OnConnect", 0, "Remote not valid", LOG_LEVEL_FATAL);
00053                 SetCloseAndDelete();
00054         }
00055 }
00056 
00057 
00058 void RemoteSocket::OnConnectFailed()
00059 {
00060         if (m_pRemote && Handler().Valid(m_pRemote))
00061         {
00062                 m_pRemote -> ConnectFailed();
00063         }
00064         else
00065         {
00066                 Handler().LogError(this, "OnConnectFailed", 0, "Remote not valid", LOG_LEVEL_FATAL);
00067                 SetCloseAndDelete();
00068         }
00069 }
00070 
00071 
00072 void RemoteSocket::OnRead()
00073 {
00074         TcpSocket::OnRead();
00075         size_t l = ibuf.GetLength();
00076         char buf[TCP_BUFSIZE_READ];
00077         ibuf.Read(buf, l);
00078         if (m_pRemote && Handler().Valid(m_pRemote))
00079         {
00080                 m_pRemote -> SendBuf(buf, l);
00081         }
00082         else
00083         {
00084                 Handler().LogError(this, "OnRead", 0, "Remote not valid", LOG_LEVEL_FATAL);
00085                 SetCloseAndDelete();
00086         }
00087 }
00088 
00089 
00090 void RemoteSocket::OnAccept()
00091 {
00092         Socket *p0 = static_cast<Socks4Handler&>(Handler()).GetSocks4( GetParent() );
00093         Socks4Socket *pRemote = dynamic_cast<Socks4Socket *>(p0);
00094         if (p0 && Handler().Valid(p0) && pRemote)
00095         {
00096                 SetRemote(pRemote);
00097                 pRemote -> SetRemote(this);
00098                 m_pRemote -> Accept();
00099         }
00100         else
00101         {
00102                 Handler().LogError(this, "OnAccept", 0, "Remote not valid", LOG_LEVEL_FATAL);
00103                 SetCloseAndDelete();
00104         }
00105 }
00106 
00107 

Generated on Tue Oct 3 23:44:54 2006 for Socks4 Server by  doxygen 1.4.4