X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/259d1674f293dcb7bbc0fa1c38392d899ce71bc0..236a9de39afa090fdee3cf91cb5364ceca69e3f8:/src/common/ftp.cpp diff --git a/src/common/ftp.cpp b/src/common/ftp.cpp index 8b85a33b67..829d4bf212 100644 --- a/src/common/ftp.cpp +++ b/src/common/ftp.cpp @@ -32,10 +32,7 @@ #include #include "wx/string.h" #include "wx/utils.h" -// #include "wx/data.h" -#define WXSOCK_INTERNAL #include "wx/sckaddr.h" -#undef WXSOCK_INTERNAL #include "wx/socket.h" #include "wx/url.h" #include "wx/sckstrm.h" @@ -48,10 +45,8 @@ #define FTP_BSIZE 1024 -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxFTP, wxProtocol) -IMPLEMENT_PROTOCOL(wxFTP, _T("ftp"), _T("ftp"), TRUE) -#endif +IMPLEMENT_PROTOCOL(wxFTP, wxT("ftp"), wxT("ftp"), TRUE) //////////////////////////////////////////////////////////////// ////// wxFTP constructor and destructor //////////////////////// @@ -63,13 +58,13 @@ wxFTP::wxFTP() m_lastError = wxPROTO_NOERR; m_streaming = FALSE; - m_user = _T("anonymous"); + m_user = wxT("anonymous"); m_passwd = wxGetUserId(); - m_passwd += '@'; + m_passwd += wxT('@'); m_passwd += wxGetHostName(); SetNotify(0); - SetFlags(NONE); + SetFlags(wxSOCKET_NONE); } wxFTP::~wxFTP() @@ -99,13 +94,13 @@ bool wxFTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait)) return FALSE; } - command.sprintf(_T("USER %s"), (const wxChar *)m_user); + command.sprintf(wxT("USER %s"), (const wxChar *)m_user); if (!SendCommand(command, '3')) { Close(); return FALSE; } - command.sprintf(_T("PASS %s"), (const wxChar *)m_passwd); + command.sprintf(wxT("PASS %s"), (const wxChar *)m_passwd); if (!SendCommand(command, '2')) { Close(); return FALSE; @@ -120,7 +115,7 @@ bool wxFTP::Connect(const wxString& host) wxString my_host = host; addr.Hostname(my_host); - addr.Service(_T("ftp")); + addr.Service(wxT("ftp")); return Connect(addr); } @@ -131,8 +126,9 @@ bool wxFTP::Close() m_lastError = wxPROTO_STREAMING; return FALSE; } - if (m_connected) - SendCommand(wxString(_T("QUIT")), '2'); + if (IsConnected()) + SendCommand(wxString(wxT("QUIT")), '2'); + return wxSocketClient::Close(); } @@ -147,9 +143,9 @@ bool wxFTP::SendCommand(const wxString& command, char exp_ret) m_lastError = wxPROTO_STREAMING; return FALSE; } - tmp_str = command + _T("\r\n"); + tmp_str = command + wxT("\r\n"); const wxWX2MBbuf tmp_buf = tmp_str.mb_str(); - if (Write(MBSTRINGCAST tmp_buf, strlen(tmp_buf)).Error()) { + if (Write(wxMBSTRINGCAST tmp_buf, strlen(tmp_buf)).Error()) { m_lastError = wxPROTO_NETERR; return FALSE; } @@ -169,7 +165,7 @@ bool wxFTP::GetResult(char exp) if (m_lastResult.GetChar(3) == '-') { wxString key = m_lastResult.Left((size_t)3); - key += _T(' '); + key += wxT(' '); while (m_lastResult.Index(key) != 0) { m_lastError = GetLine(this, m_lastResult); @@ -187,14 +183,14 @@ bool wxFTP::ChDir(const wxString& dir) { wxString str = dir; - str.Prepend(_T("CWD ")); + str.Prepend(wxT("CWD ")); return SendCommand(str, '2'); } bool wxFTP::MkDir(const wxString& dir) { wxString str = dir; - str.Prepend(_T("MKD ")); + str.Prepend(wxT("MKD ")); return SendCommand(str, '2'); } @@ -202,7 +198,7 @@ bool wxFTP::RmDir(const wxString& dir) { wxString str = dir; - str.Prepend(_T("PWD ")); + str.Prepend(wxT("PWD ")); return SendCommand(str, '2'); } @@ -210,11 +206,11 @@ wxString wxFTP::Pwd() { int beg, end; - if (!SendCommand(_T("PWD"), '2')) + if (!SendCommand(wxT("PWD"), '2')) return wxString((char *)NULL); - beg = m_lastResult.Find(_T('\"'),FALSE); - end = m_lastResult.Find(_T('\"'),TRUE); + beg = m_lastResult.Find(wxT('\"'),FALSE); + end = m_lastResult.Find(wxT('\"'),TRUE); return wxString(beg+1, end); } @@ -223,11 +219,11 @@ bool wxFTP::Rename(const wxString& src, const wxString& dst) { wxString str; - str = _T("RNFR ") + src; + str = wxT("RNFR ") + src; if (!SendCommand(str, '3')) return FALSE; - str = _T("RNTO ") + dst; + str = wxT("RNTO ") + dst; return SendCommand(str, '2'); } @@ -235,7 +231,7 @@ bool wxFTP::RmFile(const wxString& path) { wxString str; - str = _T("DELE "); + str = wxT("DELE "); str += path; return SendCommand(str, '2'); } @@ -251,7 +247,7 @@ 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) @@ -288,16 +284,16 @@ wxSocketClient *wxFTP::GetPort() wxUint16 port; wxUint32 hostaddr; - if (!SendCommand(_T("PASV"), '2')) + if (!SendCommand(wxT("PASV"), '2')) return NULL; - addr_pos = m_lastResult.Find(_T('(')); + addr_pos = m_lastResult.Find(wxT('(')); if (addr_pos == -1) { m_lastError = wxPROTO_PROTERR; return NULL; } 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]); + wxSscanf((const wxChar *)straddr,wxT("%d,%d,%d,%d,%d,%d"),&a[2],&a[3],&a[4],&a[5],&a[0],&a[1]); hostaddr = (wxUint16)a[5] << 24 | (wxUint16)a[4] << 16 | (wxUint16)a[3] << 8 | a[2]; @@ -319,7 +315,7 @@ wxSocketClient *wxFTP::GetPort() bool wxFTP::Abort(void) { m_streaming = FALSE; - if (!SendCommand(_T("ABOR"), '4')) + if (!SendCommand(wxT("ABOR"), '4')) return FALSE; return GetResult('2'); } @@ -330,7 +326,7 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path) int pos_size; wxInputFTPStream *in_stream; - if (!SendCommand(_T("TYPE I"), '2')) + if (!SendCommand(wxT("TYPE I"), '2')) return NULL; wxSocketClient *sock = GetPort(); @@ -340,19 +336,19 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path) return NULL; } - tmp_str = _T("RETR ") + path; + tmp_str = wxT("RETR ") + wxURL::ConvertFromURI(path); if (!SendCommand(tmp_str, '1')) return NULL; in_stream = new wxInputFTPStream(this, sock); - pos_size = m_lastResult.Index(_T('(')); + pos_size = m_lastResult.Index(wxT('(')); if (pos_size != wxNOT_FOUND) { - wxString str_size = m_lastResult(pos_size+1, m_lastResult.Index(_T(')'))-1); + wxString str_size = m_lastResult(pos_size+1, m_lastResult.Index(wxT(')'))-1); in_stream->m_ftpsize = wxAtoi(WXSTRINGCAST str_size); } - sock->SetFlags(WAITALL); + sock->SetFlags(wxSOCKET_WAITALL); return in_stream; } @@ -361,12 +357,12 @@ wxOutputStream *wxFTP::GetOutputStream(const wxString& path) { wxString tmp_str; - if (!SendCommand(_T("TYPE I"), '2')) + if (!SendCommand(wxT("TYPE I"), '2')) return NULL; wxSocketClient *sock = GetPort(); - tmp_str = _T("STOR ") + path; + tmp_str = wxT("STOR ") + path; if (!SendCommand(tmp_str, '1')) return FALSE; @@ -377,7 +373,7 @@ wxList *wxFTP::GetList(const wxString& wildcard) { wxList *file_list = new wxList; wxSocketBase *sock = GetPort(); - wxString tmp_str = _T("NLST"); + wxString tmp_str = wxT("NLST"); if (!wildcard.IsNull()) tmp_str += wildcard;