Unicode interface (the communication itself is still in ASCII, I hope).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2140 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ove Kaaven 1999-04-13 12:44:37 +00:00
parent 8bec6d4ae8
commit 4846abaf45
3 changed files with 51 additions and 48 deletions

View File

@ -50,7 +50,7 @@
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxFTP, wxProtocol) IMPLEMENT_DYNAMIC_CLASS(wxFTP, wxProtocol)
IMPLEMENT_PROTOCOL(wxFTP, "ftp", "ftp", TRUE) IMPLEMENT_PROTOCOL(wxFTP, _T("ftp"), _T("ftp"), TRUE)
#endif #endif
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -60,14 +60,14 @@ IMPLEMENT_PROTOCOL(wxFTP, "ftp", "ftp", TRUE)
wxFTP::wxFTP() wxFTP::wxFTP()
: wxProtocol() : wxProtocol()
{ {
char tmp[256]; wxChar tmp[256];
m_lastError = wxPROTO_NOERR; m_lastError = wxPROTO_NOERR;
m_streaming = FALSE; m_streaming = FALSE;
m_user = "anonymous"; m_user = _T("anonymous");
wxGetUserName(tmp, 256); wxGetUserName(tmp, 256);
m_passwd.sprintf("%s@",tmp); m_passwd.sprintf(_T("%s@"),tmp);
wxGetHostName(tmp, 256); wxGetHostName(tmp, 256);
m_passwd += tmp; m_passwd += tmp;
@ -106,13 +106,13 @@ bool wxFTP::Connect(wxSockAddress& addr, bool WXUNUSED(wait))
return FALSE; return FALSE;
} }
command.sprintf("USER %s", (const char *)m_user); command.sprintf(_T("USER %s"), (const wxChar *)m_user);
if (!SendCommand(command, '3')) { if (!SendCommand(command, '3')) {
Close(); Close();
return FALSE; return FALSE;
} }
command.sprintf("PASS %s", (const char *)m_passwd); command.sprintf(_T("PASS %s"), (const wxChar *)m_passwd);
if (!SendCommand(command, '2')) { if (!SendCommand(command, '2')) {
Close(); Close();
return FALSE; return FALSE;
@ -127,7 +127,7 @@ bool wxFTP::Connect(const wxString& host)
wxString my_host = host; wxString my_host = host;
addr.Hostname(my_host); addr.Hostname(my_host);
addr.Service("ftp"); addr.Service(_T("ftp"));
return Connect(addr); return Connect(addr);
} }
@ -139,7 +139,7 @@ bool wxFTP::Close()
return FALSE; return FALSE;
} }
if (m_connected) if (m_connected)
SendCommand(wxString("QUIT"), '2'); SendCommand(wxString(_T("QUIT")), '2');
return wxSocketClient::Close(); return wxSocketClient::Close();
} }
@ -154,8 +154,9 @@ bool wxFTP::SendCommand(const wxString& command, char exp_ret)
m_lastError = wxPROTO_STREAMING; m_lastError = wxPROTO_STREAMING;
return FALSE; return FALSE;
} }
tmp_str = command + "\r\n"; tmp_str = command + _T("\r\n");
if (Write((char *)tmp_str.GetData(), tmp_str.Length()).Error()) { wxWX2MBbuf tmp_buf = tmp_str.mb_str();
if (Write(MBSTRINGCAST tmp_buf, strlen(tmp_buf)).Error()) {
m_lastError = wxPROTO_NETERR; m_lastError = wxPROTO_NETERR;
return FALSE; return FALSE;
} }
@ -174,7 +175,7 @@ bool wxFTP::GetResult(char exp)
if (m_lastResult.GetChar(3) == '-') { if (m_lastResult.GetChar(3) == '-') {
wxString key = m_lastResult.Left((size_t)3); wxString key = m_lastResult.Left((size_t)3);
key += ' '; key += _T(' ');
while (m_lastResult.Index(key) != 0) { while (m_lastResult.Index(key) != 0) {
if ((m_lastError = GetLine(this, m_lastResult))) if ((m_lastError = GetLine(this, m_lastResult)))
@ -191,14 +192,14 @@ bool wxFTP::ChDir(const wxString& dir)
{ {
wxString str = dir; wxString str = dir;
str.Prepend("CWD "); str.Prepend(_T("CWD "));
return SendCommand(str, '2'); return SendCommand(str, '2');
} }
bool wxFTP::MkDir(const wxString& dir) bool wxFTP::MkDir(const wxString& dir)
{ {
wxString str = dir; wxString str = dir;
str.Prepend("MKD "); str.Prepend(_T("MKD "));
return SendCommand(str, '2'); return SendCommand(str, '2');
} }
@ -206,7 +207,7 @@ bool wxFTP::RmDir(const wxString& dir)
{ {
wxString str = dir; wxString str = dir;
str.Prepend("PWD "); str.Prepend(_T("PWD "));
return SendCommand(str, '2'); return SendCommand(str, '2');
} }
@ -214,11 +215,11 @@ wxString wxFTP::Pwd()
{ {
int beg, end; int beg, end;
if (!SendCommand("PWD", '2')) if (!SendCommand(_T("PWD"), '2'))
return wxString((char *)NULL); return wxString((char *)NULL);
beg = m_lastResult.Find('\"',FALSE); beg = m_lastResult.Find(_T('\"'),FALSE);
end = m_lastResult.Find('\"',TRUE); end = m_lastResult.Find(_T('\"'),TRUE);
return wxString(beg+1, end); return wxString(beg+1, end);
} }
@ -227,11 +228,11 @@ bool wxFTP::Rename(const wxString& src, const wxString& dst)
{ {
wxString str; wxString str;
str = "RNFR " + src; str = _T("RNFR ") + src;
if (!SendCommand(str, '3')) if (!SendCommand(str, '3'))
return FALSE; return FALSE;
str = "RNTO " + dst; str = _T("RNTO ") + dst;
return SendCommand(str, '2'); return SendCommand(str, '2');
} }
@ -239,7 +240,7 @@ bool wxFTP::RmFile(const wxString& path)
{ {
wxString str; wxString str;
str = "DELE "; str = _T("DELE ");
str += path; str += path;
return SendCommand(str, '2'); return SendCommand(str, '2');
} }
@ -291,17 +292,17 @@ wxSocketClient *wxFTP::GetPort()
wxString straddr; wxString straddr;
int addr_pos; int addr_pos;
if (!SendCommand("PASV", '2')) if (!SendCommand(_T("PASV"), '2'))
return NULL; return NULL;
sin.sa_family = AF_INET; sin.sa_family = AF_INET;
addr_pos = m_lastResult.Find('('); addr_pos = m_lastResult.Find(_T('('));
if (addr_pos == -1) { if (addr_pos == -1) {
m_lastError = wxPROTO_PROTERR; m_lastError = wxPROTO_PROTERR;
return NULL; return NULL;
} }
straddr = m_lastResult(addr_pos+1, m_lastResult.Length()); straddr = m_lastResult(addr_pos+1, m_lastResult.Length());
sscanf((const char *)straddr,"%d,%d,%d,%d,%d,%d",&a[2],&a[3],&a[4],&a[5],&a[0],&a[1]); 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[2] = (char)a[2];
sin.sa_data[3] = (char)a[3]; sin.sa_data[3] = (char)a[3];
sin.sa_data[4] = (char)a[4]; sin.sa_data[4] = (char)a[4];
@ -324,7 +325,7 @@ wxSocketClient *wxFTP::GetPort()
bool wxFTP::Abort(void) bool wxFTP::Abort(void)
{ {
m_streaming = FALSE; m_streaming = FALSE;
if (!SendCommand("ABOR", '4')) if (!SendCommand(_T("ABOR"), '4'))
return FALSE; return FALSE;
return GetResult('2'); return GetResult('2');
} }
@ -335,7 +336,7 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path)
int pos_size; int pos_size;
wxInputFTPStream *in_stream; wxInputFTPStream *in_stream;
if (!SendCommand("TYPE I", '2')) if (!SendCommand(_T("TYPE I"), '2'))
return NULL; return NULL;
wxSocketClient *sock = GetPort(); wxSocketClient *sock = GetPort();
@ -345,17 +346,17 @@ wxInputStream *wxFTP::GetInputStream(const wxString& path)
return NULL; return NULL;
} }
tmp_str = "RETR " + path; tmp_str = _T("RETR ") + path;
if (!SendCommand(tmp_str, '1')) if (!SendCommand(tmp_str, '1'))
return NULL; return NULL;
in_stream = new wxInputFTPStream(this, sock); in_stream = new wxInputFTPStream(this, sock);
pos_size = m_lastResult.Index('('); pos_size = m_lastResult.Index(_T('('));
if (pos_size != wxNOT_FOUND) { if (pos_size != wxNOT_FOUND) {
wxString str_size = m_lastResult(pos_size+1, m_lastResult.Index(')')-1); wxString str_size = m_lastResult(pos_size+1, m_lastResult.Index(_T(')'))-1);
in_stream->m_ftpsize = atoi(WXSTRINGCAST str_size); in_stream->m_ftpsize = wxAtoi(WXSTRINGCAST str_size);
} }
return in_stream; return in_stream;
@ -365,12 +366,12 @@ wxOutputStream *wxFTP::GetOutputStream(const wxString& path)
{ {
wxString tmp_str; wxString tmp_str;
if (!SendCommand("TYPE I", '2')) if (!SendCommand(_T("TYPE I"), '2'))
return NULL; return NULL;
wxSocketClient *sock = GetPort(); wxSocketClient *sock = GetPort();
tmp_str = "STOR " + path; tmp_str = _T("STOR ") + path;
if (!SendCommand(tmp_str, '1')) if (!SendCommand(tmp_str, '1'))
return FALSE; return FALSE;
@ -381,7 +382,7 @@ wxList *wxFTP::GetList(const wxString& wildcard)
{ {
wxList *file_list = new wxList; wxList *file_list = new wxList;
wxSocketBase *sock = GetPort(); wxSocketBase *sock = GetPort();
wxString tmp_str = "NLST"; wxString tmp_str = _T("NLST");
if (!wildcard.IsNull()) if (!wildcard.IsNull())
tmp_str += wildcard; tmp_str += wildcard;

View File

@ -36,7 +36,7 @@
#if !USE_SHARED_LIBRARY #if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxHTTP, wxProtocol) IMPLEMENT_DYNAMIC_CLASS(wxHTTP, wxProtocol)
IMPLEMENT_PROTOCOL(wxHTTP, "http", "80", TRUE) IMPLEMENT_PROTOCOL(wxHTTP, _T("http"), _T("80"), TRUE)
#endif #endif
#define HTTP_BSIZE 2048 #define HTTP_BSIZE 2048
@ -66,7 +66,7 @@ wxHTTP::~wxHTTP()
wxString wxHTTP::GetContentType() wxString wxHTTP::GetContentType()
{ {
return GetHeader("Content-Type"); return GetHeader(_T("Content-Type"));
} }
void wxHTTP::SetHeader(const wxString& header, const wxString& h_data) void wxHTTP::SetHeader(const wxString& header, const wxString& h_data)
@ -104,9 +104,10 @@ void wxHTTP::SendHeaders()
wxString *str = (wxString *)head->Data(); wxString *str = (wxString *)head->Data();
wxString buf; wxString buf;
buf.Printf("%s: %s\n\r", head->GetKeyString(), str->GetData()); buf.Printf(_T("%s: %s\n\r"), head->GetKeyString(), str->GetData());
Write(buf, buf.Len()); wxWX2MBbuf cbuf = buf.mb_str();
Write(cbuf, strlen(cbuf));
head = head->Next(); head = head->Next();
} }
@ -127,7 +128,7 @@ bool wxHTTP::ParseHeaders()
if (line.Length() == 0) if (line.Length() == 0)
break; break;
printf("Header: %s\n", WXSTRINGCAST line); wxPrintf(_T("Header: %s\n"), WXSTRINGCAST line);
int pos = line.Find(':'); int pos = line.Find(':');
if (pos == -1) if (pos == -1)
return FALSE; return FALSE;
@ -163,7 +164,7 @@ bool wxHTTP::Connect(const wxString& host)
return FALSE; return FALSE;
} }
if (!addr->Service("http")) if (!addr->Service(_T("http")))
addr->Service(80); addr->Service(80);
return TRUE; return TRUE;
@ -186,6 +187,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
{ {
char *tmp_buf; char *tmp_buf;
char buf[HTTP_BSIZE]; char buf[HTTP_BSIZE];
wxWX2MBbuf pathbuf = path.mb_str();
switch (req) { switch (req) {
case wxHTTP_GET: case wxHTTP_GET:
@ -199,7 +201,7 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
Notify(FALSE); Notify(FALSE);
SetFlags(WAITALL); SetFlags(WAITALL);
sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char *)path); sprintf(buf, "%s %s HTTP/1.0\n\r", tmp_buf, (const char*)pathbuf);
Write(buf, strlen(buf)); Write(buf, strlen(buf));
SendHeaders(); SendHeaders();
sprintf(buf, "\n\r"); sprintf(buf, "\n\r");
@ -213,22 +215,22 @@ bool wxHTTP::BuildRequest(const wxString& path, wxHTTP_Req req)
return FALSE; return FALSE;
} }
if (!tmp_str.Contains("HTTP/")) { if (!tmp_str.Contains(_T("HTTP/"))) {
// TODO: support HTTP v0.9 which can have no header. // TODO: support HTTP v0.9 which can have no header.
SetHeader("Content-Length", "-1"); SetHeader(_T("Content-Length"), _T("-1"));
SetHeader("Content-Type", "none/none"); SetHeader(_T("Content-Type"), _T("none/none"));
RestoreState(); RestoreState();
return TRUE; return TRUE;
} }
wxStringTokenizer token(tmp_str,' '); wxStringTokenizer token(tmp_str,_T(' '));
wxString tmp_str2; wxString tmp_str2;
bool ret_value; bool ret_value;
token.NextToken(); token.NextToken();
tmp_str2 = token.NextToken(); tmp_str2 = token.NextToken();
switch (atoi(tmp_str2)) { switch (wxAtoi(tmp_str2)) {
case 200: case 200:
break; break;
default: default:
@ -272,9 +274,9 @@ wxInputStream *wxHTTP::GetInputStream(const wxString& path)
if (!BuildRequest(path, wxHTTP_GET)) if (!BuildRequest(path, wxHTTP_GET))
return NULL; return NULL;
printf("Len = %s\n", WXSTRINGCAST GetHeader("Content-Length")); wxPrintf(_T("Len = %s\n"), WXSTRINGCAST GetHeader(_T("Content-Length")));
if (!GetHeader("Content-Length").IsEmpty()) if (!GetHeader(_T("Content-Length")).IsEmpty())
inp_stream->m_httpsize = atoi(WXSTRINGCAST GetHeader("Content-Length")); inp_stream->m_httpsize = wxAtoi(WXSTRINGCAST GetHeader(_T("Content-Length")));
return inp_stream; return inp_stream;
} }

View File

@ -40,7 +40,7 @@
* -------------------------------------------------------------- * --------------------------------------------------------------
*/ */
wxProtoInfo::wxProtoInfo(const char *name, const char *serv, wxProtoInfo::wxProtoInfo(const wxChar *name, const wxChar *serv,
const bool need_host1, wxClassInfo *info) const bool need_host1, wxClassInfo *info)
{ {
m_protoname = name; m_protoname = name;