[PATCH] RFC2640 Support for FileZilla 2.2.11?
Posted: 2005-02-26 17:10
Here is a simple patch for filezilla 2.2.11 to support RFC-2640. (maybe....)
If the FEAT response show UTF8 support, this patch will encode all control socket command/response form Windows ANSI codepage to UTF-8, and encode the list result from UTF-8 to Windows ANSI codepage.
I've tested this patch for Chinese Windows XP (CP950, Big5) to a UTF-8 ftp server. It work for me.
http://www.teatime.com.tw/~tommy/filezi ... 2640.patch
If the FEAT response show UTF8 support, this patch will encode all control socket command/response form Windows ANSI codepage to UTF-8, and encode the list result from UTF-8 to Windows ANSI codepage.
I've tested this patch for Chinese Windows XP (CP950, Big5) to a UTF-8 ftp server. It work for me.
http://www.teatime.com.tw/~tommy/filezi ... 2640.patch
Code: Select all
diff -Nur source.orig\FtpControlSocket.cpp source.patched\FtpControlSocket.cpp
--- source.orig\FtpControlSocket.cpp Sat Jan 15 19:46:52 2005
+++ source.patched\FtpControlSocket.cpp Sun Feb 27 00:53:06 2005
@@ -146,6 +146,8 @@
m_useZlib = false;
m_zlibSupported = false;
m_zlibLevel = 8;
+
+ m_bUTF8 = false;
}
CFtpControlSocket::~CFtpControlSocket()
@@ -552,8 +554,10 @@
{ // authentication succeeded, we're now get the response to the CWD command
if (GetReplyCode() == 2) // we're logged on
{
- if (Send("FEAT"))
+ if (Send("FEAT")) {
+ m_bUTF8 = false;
m_Operation.nOpState = CONNECT_FEAT;
+ }
return;
}
else
@@ -581,8 +585,10 @@
DoClose();
return;
case LO: //LO means we are logged on
- if (Send("FEAT"))
+ if (Send("FEAT")) {
+ m_bUTF8 = false;
m_Operation.nOpState = CONNECT_FEAT;
+ }
return;
}
}
@@ -696,6 +702,17 @@
{
if (!m_RecvBuffer.empty() && m_RecvBuffer.back()!=_T("") )
{
+ if (m_bUTF8) {
+ // convert from UTF-8 to ANSI
+ int len = MultiByteToWideChar(CP_UTF8, 0, m_RecvBuffer.back(), -1, NULL, 0);
+ char *p1 = new char[len * 2 + 1];
+ char *p2 = new char[len * 2 + 1];
+ MultiByteToWideChar(CP_UTF8, 0, m_RecvBuffer.back(), -1 , (LPWSTR)p1, len*2);
+ WideCharToMultiByte(CP_ACP, 0,(LPCWSTR)p1, -1, p2, len*2, NULL, NULL);
+ m_RecvBuffer.back() = p2;
+ delete [] p1;
+ delete [] p2;
+ }
ShowStatus(m_RecvBuffer.back(), 3);
//Check for multi-line responses
if (m_RecvBuffer.back().GetLength()>3)
@@ -832,8 +849,22 @@
ShowStatus(str,2);
str+="\r\n";
- LPCSTR lpszAsciiSend=T2CA(str);
- int res = CAsyncSocketEx::Send(lpszAsciiSend,strlen(lpszAsciiSend));
+ int res;
+ if (m_bUTF8) {
+ // Convert ANSI to UTF-8
+ int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+ char *p1 = new char[len * 2 + 1];
+ char *p2 = new char[len * 2 + 1];
+ MultiByteToWideChar(CP_ACP, 0, str, -1 , (LPWSTR)p1, len*2);
+ WideCharToMultiByte(CP_UTF8, 0,(LPCWSTR)p1, -1, p2, len*2, NULL, NULL);
+ res = CAsyncSocketEx::Send(p2, strlen(p2));
+ delete [] p1;
+ delete [] p2;
+ }
+ else {
+ LPCSTR lpszAsciiSend=T2CA(str);
+ res = CAsyncSocketEx::Send(lpszAsciiSend,strlen(lpszAsciiSend));
+ }
if (!res)
{
if (GetLastError()!=WSAEWOULDBLOCK)
@@ -4875,6 +4906,9 @@
line.MakeUpper();
if (line == _T(" MODE Z") || line.Left(8) == _T(" MODE Z "))
m_zlibSupported = true;
+ if (line == _T(" UTF8") || line.Left(8) == _T(" UTF8 ")) {
+ m_bUTF8 = true;
+ }
}
}
diff -Nur source.orig\FtpControlSocket.h source.patched\FtpControlSocket.h
--- source.orig\FtpControlSocket.h Mon Jun 07 22:59:10 2004
+++ source.patched\FtpControlSocket.h Sun Feb 27 00:15:08 2005
@@ -130,6 +130,8 @@
bool m_zlibSupported;
int m_zlibLevel;
+ bool m_bUTF8;
+
private:
BOOL m_bCheckForTimeout;
};
diff -Nur source.orig\FtpListResult.cpp source.patched\FtpListResult.cpp
--- source.orig\FtpListResult.cpp Sun Feb 27 00:35:57 2005
+++ source.patched\FtpListResult.cpp Sun Feb 27 00:41:10 2005
@@ -142,11 +142,12 @@
#endif
-CFtpListResult::CFtpListResult(t_server server)
+CFtpListResult::CFtpListResult(t_server server, bool bUTF8)
{
listhead=curpos=0;
m_server = server;
+ m_bUTF8 = bUTF8;
pos=0;
@@ -369,8 +370,23 @@
while (line)
{
int tmp;
- char *tmpline=new char[strlen(line)+1];
- strcpy(tmpline, line);
+ char *tmpline;
+
+ if (m_bUTF8) {
+ // convert from UTF-8 to ANSI
+ int len = MultiByteToWideChar(CP_UTF8, 0, line, -1, NULL, 0);
+ char *p1 = new char[len * 2 + 1];
+ char *p2 = new char[len * 2 + 1];
+ MultiByteToWideChar(CP_UTF8, 0, line, -1 , (LPWSTR)p1, len*2);
+ WideCharToMultiByte(CP_ACP, 0,(LPCWSTR)p1, -1, p2, len*2, NULL, NULL);
+ tmpline = p2;
+ delete [] p1;
+ //delete [] p2;
+ }
+ else {
+ tmpline=new char[strlen(line)+1];
+ strcpy(tmpline, line);
+ }
if (parseLine(tmpline, strlen(tmpline), direntry, tmp))
{
delete [] tmpline;
@@ -541,8 +557,23 @@
break;
}
int tmp;
- char *tmpline = new char[strlen(line)+1];
- strcpy(tmpline, line);
+ char *tmpline;
+
+ if (m_bUTF8) {
+ // convert from UTF-8 to ANSI
+ int len = MultiByteToWideChar(CP_UTF8, 0, line, -1, NULL, 0);
+ char *p1 = new char[len * 2 + 1];
+ char *p2 = new char[len * 2 + 1];
+ MultiByteToWideChar(CP_UTF8, 0, line, -1 , (LPWSTR)p1, len*2);
+ WideCharToMultiByte(CP_ACP, 0,(LPCWSTR)p1, -1, p2, len*2, NULL, NULL);
+ tmpline = p2;
+ delete [] p1;
+ //delete [] p2;
+ }
+ else {
+ tmpline=new char[strlen(line)+1];
+ strcpy(tmpline, line);
+ }
if (parseLine(tmpline, strlen(tmpline), direntry, tmp))
{
delete [] tmpline;
diff -Nur source.orig\FtpListResult.h source.patched\FtpListResult.h
--- source.orig\FtpListResult.h Fri Jan 14 14:50:46 2005
+++ source.patched\FtpListResult.h Sun Feb 27 00:16:17 2005
@@ -55,9 +55,10 @@
{
public:
t_server m_server;
+ bool m_bUTF8;
void SendToMessageLog(HWND hWnd, UINT nMsg);
void AddData(char *data,int size);
- CFtpListResult(t_server server);
+ CFtpListResult(t_server server, bool bUTF8 = false);
~CFtpListResult();
t_directory::t_direntry *getList(int &num, CTime EntryTime);
diff -Nur source.orig\TransferSocket.cpp source.patched\TransferSocket.cpp
--- source.orig\TransferSocket.cpp Sun Feb 20 12:30:52 2005
+++ source.patched\TransferSocket.cpp Sun Feb 27 00:14:15 2005
@@ -79,7 +79,7 @@
m_pSslLayer = NULL;
m_pGssLayer = NULL;
- m_pListResult = new CFtpListResult(pOwner->m_CurrentServer);
+ m_pListResult = new CFtpListResult(pOwner->m_CurrentServer, pOwner->m_bUTF8);
m_LastUpdateTime.QuadPart = 0;
memset(&m_zlibStream, 0, sizeof(m_zlibStream));