X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4846abaf45a5a1b2ba4392fab7fdc45f1518f4d7..3372145d9daa42f680fc5aab7eb00e82d587c5a0:/src/common/ftp.cpp diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp index 9ef749df6f..b789852c92 100644 --- a/src/common/ftp.cpp +++ b/src/common/ftp.cpp @@ -10,14 +10,14 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "ftp.h" + #pragma implementation "ftp.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #if wxUSE_SOCKETS @@ -60,18 +60,16 @@ IMPLEMENT_PROTOCOL(wxFTP, _T("ftp"), _T("ftp"), TRUE) wxFTP::wxFTP() : wxProtocol() { - wxChar tmp[256]; - m_lastError = wxPROTO_NOERR; m_streaming = FALSE; m_user = _T("anonymous"); - wxGetUserName(tmp, 256); - m_passwd.sprintf(_T("%s@"),tmp); - wxGetHostName(tmp, 256); - m_passwd += tmp; + m_passwd = wxGetUserId(); + m_passwd += '@'; + m_passwd += wxGetHostName(); SetNotify(0); + SetFlags(NONE); } wxFTP::~wxFTP() @@ -84,11 +82,6 @@ wxFTP::~wxFTP() //////////////////////////////////////////////////////////////// bool wxFTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait)) { - if (!m_handler) { - m_lastError = wxPROTO_NOHNDLR; - return FALSE; - } - if (!wxProtocol::Connect(addr)) { m_lastError = wxPROTO_NETERR; return FALSE; @@ -155,7 +148,7 @@ bool wxFTP::SendCommand(const wxString& command, char exp_ret) return FALSE; } tmp_str = command + _T("\r\n"); - wxWX2MBbuf tmp_buf = tmp_str.mb_str(); + const wxWX2MBbuf tmp_buf = tmp_str.mb_str(); if (Write(MBSTRINGCAST tmp_buf, strlen(tmp_buf)).Error()) { m_lastError = wxPROTO_NETERR; return FALSE; @@ -165,7 +158,8 @@ bool wxFTP::SendCommand(const wxString& command, char exp_ret) bool wxFTP::GetResult(char exp) { - if ((m_lastError = GetLine(this, m_lastResult))) + m_lastError = GetLine(this, m_lastResult); + if ( m_lastError ) return FALSE; if (m_lastResult.GetChar(0) != exp) { m_lastError = wxPROTO_PROTERR; @@ -178,7 +172,8 @@ bool wxFTP::GetResult(char exp) key += _T(' '); while (m_lastResult.Index(key) != 0) { - if ((m_lastError = GetLine(this, m_lastResult))) + m_lastError = GetLine(this, m_lastResult); + if ( m_lastError ) return FALSE; } } @@ -256,10 +251,10 @@ public: wxInputFTPStream(wxFTP *ftp_clt, wxSocketBase *sock) : wxSocketInputStream(*sock), m_ftp(ftp_clt) {} - size_t StreamSize() const { return m_ftpsize; } + size_t GetSize() const { return m_ftpsize; } virtual ~wxInputFTPStream(void) { - if (LastError() != wxStream_NOERROR) + if (LastError() == wxStream_NOERROR) m_ftp->GetResult('2'); else m_ftp->Abort(); @@ -287,15 +282,15 @@ wxSocketClient *wxFTP::GetPort() { wxIPV4address addr; wxSocketClient *client; - struct sockaddr sin; int a[6]; wxString straddr; int addr_pos; + wxUint16 port; + wxUint32 hostaddr; if (!SendCommand(_T("PASV"), '2')) return NULL; - sin.sa_family = AF_INET; addr_pos = m_lastResult.Find(_T('(')); if (addr_pos == -1) { m_lastError = wxPROTO_PROTERR; @@ -303,16 +298,15 @@ wxSocketClient *wxFTP::GetPort() } straddr = m_lastResult(addr_pos+1, m_lastResult.Length()); wxSscanf((const wxChar *)straddr,_T("%d,%d,%d,%d,%d,%d"),&a[2],&a[3],&a[4],&a[5],&a[0],&a[1]); - sin.sa_data[2] = (char)a[2]; - sin.sa_data[3] = (char)a[3]; - sin.sa_data[4] = (char)a[4]; - sin.sa_data[5] = (char)a[5]; - sin.sa_data[0] = (char)a[0]; - sin.sa_data[1] = (char)a[1]; - addr.Disassemble(&sin, sizeof(sin)); + hostaddr = (wxUint16)a[5] << 24 | (wxUint16)a[4] << 16 | + (wxUint16)a[3] << 8 | a[2]; + addr.Hostname(hostaddr); - client = m_handler->CreateClient(); + port = (wxUint16)a[0] << 8 | a[1]; + addr.Service(port); + + client = new wxSocketClient(); if (!client->Connect(addr)) { delete client; return NULL; @@ -358,6 +352,7 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path) in_stream->m_ftpsize = wxAtoi(WXSTRINGCAST str_size); } + sock->SetFlags(WAITALL); return in_stream; } @@ -404,10 +399,6 @@ wxList *wxFTP::GetList(const wxString& wildcard) return NULL; } - sock->SetEventHandler(*GetNextHandler(), m_id); - sock->Notify(m_notifyme); - sock->SetNotify(m_neededreq); - return file_list; } #endif