Ticket #1467: filezilla_sftp_utf8_2212c.patch
File filezilla_sftp_utf8_2212c.patch, 23.7 KB (added by , 20 years ago) |
---|
-
FzSFtp/psftp.c
diff -Nur source/FzSFtp/psftp.c source.patch/FzSFtp/psftp.c
old new 17 17 #include "int64.h" 18 18 19 19 #include "FzSFtpIpc.h" 20 #include <tchar.h> 20 21 21 22 /* 22 23 * Since SFTP is a request-response oriented protocol, it requires … … 389 390 sfree(fname); 390 391 return 0; 391 392 } 392 393 #ifdef _UNICODE 394 { 395 int len; 396 397 // convert from UTF-8 to ANSI 398 len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)outfname, -1, NULL, 0); 399 if (len != 0) 400 { 401 wchar_t *p1; 402 403 p1 = malloc(sizeof(wchar_t) * (len*2+1)); 404 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)outfname, -1 , (LPWSTR)p1, len*2); 405 if (restart) 406 fp = CreateFile(p1, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 407 else 408 fp = CreateFile(p1, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); 409 free(p1); 410 } 411 else { 412 if (restart) 413 fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 414 else 415 fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); 416 } 417 } 418 #else 393 419 if (restart) 394 420 fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 395 421 else 396 422 fp = CreateFileA(outfname, GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); 397 423 #endif 398 424 if (fp==INVALID_HANDLE_VALUE) 399 425 { 400 426 FzSFtpIpc_Error1("Unable to open %s", outfname); … … 508 534 return 0; 509 535 } 510 536 537 #ifdef _UNICODE 538 { 539 int len; 540 541 // convert from UTF-8 to ANSI 542 len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)localfile, -1, NULL, 0); 543 if (len != 0) 544 { 545 wchar_t *p1; 546 547 p1 = malloc(sizeof(wchar_t) * (len*2+1)); 548 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)localfile, -1 , (LPWSTR)p1, len*2); 549 fp = CreateFile(p1, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 550 free(p1); 551 } 552 else { 553 fp = CreateFileA(localfile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 554 } 555 } 556 #else 511 557 fp = CreateFileA(localfile, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); 558 #endif 512 559 if (fp == INVALID_HANDLE_VALUE) 513 560 { 514 561 FzSFtpIpc_Error1("Unable to open %s", localfile); -
SFtpIpc.cpp
diff -Nur source/SFtpIpc.cpp source.patch/SFtpIpc.cpp
old new 146 146 147 147 m_hReceiveThread=0; 148 148 m_hExitEvent=0; 149 m_bUTF8 = pOwner->m_bUTF8; 149 150 } 150 151 151 152 CSFtpIpc::~CSFtpIpc() … … 326 327 return 0; 327 328 } 328 329 329 BOOL CSFtpIpc::Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData )330 BOOL CSFtpIpc::Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData, CString status) 330 331 { 331 332 USES_CONVERSION; 332 333 ASSERT(m_hSFtpProcess); … … 336 337 ASSERT(!nDataLength || pData); 337 338 338 339 CString str; 339 if (nID==SFTP_DATAID_STC_CONNECT) 340 str.Format( _T("CONNECT %s@%s:%d"), A2CT((char *)pData+strlen((char *)pData)+1+4), A2CT((char *)pData), *(int *)((char *)pData+strlen((char *)pData)+1) ); 340 if (nID==SFTP_DATAID_STC_CONNECT) { 341 if (status == "") 342 str.Format( _T("CONNECT %s@%s:%d"), A2CT((char *)pData+strlen((char *)pData)+1+4), A2CT((char *)pData), *(int *)((char *)pData+strlen((char *)pData)+1) ); 343 else 344 str = _T("CONNECT ") + status; 345 } 341 346 else if (nID==SFTP_DATAID_STC_PWD) 342 347 str="PWD"; 343 else if (nID==SFTP_DATAID_STC_CD) 344 str=(CString)"CD " + (char *)pData; 348 else if (nID==SFTP_DATAID_STC_CD) { 349 if (status == "") 350 str=(CString)"CD " + (char *)pData; 351 else 352 str = _T("CD ") + status; 353 } 345 354 else if (nID==SFTP_DATAID_STC_LIST) 346 355 str="LIST"; 347 else if (nID==SFTP_DATAID_STC_MKD) 348 str=(CString)"MKD " + (char *)pData; 349 else if (nID==SFTP_DATAID_STC_GET) 350 str.Format( _T("GET %s %s %s"), 356 else if (nID==SFTP_DATAID_STC_MKD) { 357 if (status == "") 358 str=(CString)"MKD " + (char *)pData; 359 else 360 str = _T("MKD ") + status; 361 } 362 else if (nID==SFTP_DATAID_STC_GET) { 363 if (status == "") 364 str.Format( _T("GET %s %s %s"), 351 365 A2CT((char *)pData), 352 366 A2CT((char *)pData+strlen((char *)pData)+1), 353 367 ( *(int *)((char *)pData+strlen((char *)pData)+1+strlen((char *)pData+strlen((char *)pData)+1)+1)?_T("TRUE"):_T("FALSE") )); 354 else if (nID==SFTP_DATAID_STC_PUT) 355 str.Format( _T("PUT %s %s %s"), 368 else 369 str = _T("GET ") + status; 370 } 371 else if (nID==SFTP_DATAID_STC_PUT) { 372 if (status == "") 373 str.Format( _T("PUT %s %s %s"), 356 374 A2CT((char *)pData), 357 375 A2CT((char *)pData+strlen((char *)pData)+1), 358 376 ( *(int *)((char *)pData+strlen((char *)pData)+1+strlen((char *)pData+strlen((char *)pData)+1)+1)?_T("TRUE"):_T("FALSE") )); 359 else if (nID==SFTP_DATAID_STC_DELE) 360 str=(CString)"DELE " + (char *)pData; 361 else if (nID==SFTP_DATAID_STC_RMD) 362 str=(CString)"RMD " + (char *)pData; 363 else if (nID==SFTP_DATAID_STC_RENAME) 364 str.Format( _T("RENAME %s %s"), 377 else 378 str = _T("PUT ") + status; 379 } 380 else if (nID==SFTP_DATAID_STC_DELE) { 381 if (status == "") 382 str=(CString)"DELE " + (char *)pData; 383 else 384 str = _T("DELE ") + status; 385 } 386 else if (nID==SFTP_DATAID_STC_RMD) { 387 if (status == "") 388 str=(CString)"RMD " + (char *)pData; 389 else 390 str = _T("RMD ") + status; 391 } 392 else if (nID==SFTP_DATAID_STC_RENAME) { 393 if (status == "") 394 str.Format( _T("RENAME %s %s"), 365 395 A2CT((char *)pData), 366 396 A2CT((char *)pData+strlen((char *)pData)+1)); 367 else if (nID==SFTP_DATAID_STC_CHMOD) 368 str.Format( _T("CHMOD %s %s"), 397 else 398 str = _T("RENAME ") + status; 399 } 400 else if (nID==SFTP_DATAID_STC_CHMOD) { 401 if (status == "") 402 str.Format( _T("CHMOD %s %s"), 369 403 A2CT((char *)pData), 370 404 A2CT((char *)pData+strlen((char *)pData)+1)); 405 else 406 str = _T("CHMOD ") + status; 407 } 371 408 if (str!="") 372 409 m_pOwner->ShowStatus(str, 2); 373 410 … … 417 454 BOOL CSFtpIpc::Send(const DWORD &nID, LPCTSTR str) 418 455 { 419 456 USES_CONVERSION; 420 if (str) 421 return Send(nID, (const DWORD)strlen(T2CA(str))+1, (LPVOID)T2CA(str)); 457 458 if (str) { 459 if (m_bUTF8) 460 { 461 bool res; 462 LPCWSTR unicode = T2CW(str); 463 int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0); 464 char* utf8 = new char[len + 1]; 465 WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0); 466 467 res = Send(nID, (const DWORD)strlen(utf8)+1, (LPVOID)utf8, str); 468 delete [] utf8; 469 return res; 470 } 471 else 472 { 473 return Send(nID, (const DWORD)strlen(T2CA(str))+1, (LPVOID)T2CA(str), str); 474 } 475 } 422 476 else 423 477 return Send(nID, 0, 0); 424 478 } -
SFtpIpc.h
diff -Nur source/SFtpIpc.h source.patch/SFtpIpc.h
old new 34 34 friend CSFtpIpcHelperWindow; 35 35 public: 36 36 BOOL Send(const DWORD &nID, LPCTSTR str); 37 BOOL Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData );37 BOOL Send(const DWORD &nID, const DWORD &nDataLength, const LPVOID pData, CString status = ""); 38 38 BOOL AttachProcess(HANDLE hSFtpProcess); 39 39 CString GetHandleString(); 40 40 CSFtpIpc(CSFtpControlSocket *pOwner); … … 64 64 HANDLE m_hReceiveThread; 65 65 static DWORD WINAPI ReceiveThread( LPVOID pParam ); 66 66 HANDLE m_hExitEvent; 67 bool m_bUTF8; 67 68 }; 68 69 69 70 #endif // !defined(AFX_SFTPIPC_H__71B20B86_C3D8_4197_90C2_349A18548D58__INCLUDED_) -
SftpControlSocket.cpp
diff -Nur source/SftpControlSocket.cpp source.patch/SftpControlSocket.cpp
old new 28 28 #include "SFtpCommandIDs.h" 29 29 #include "FtpListResult.h" 30 30 #include "FileExistsDlg.h" 31 #include "misc/utf8.h" 31 32 32 33 #ifdef _DEBUG 33 34 #undef THIS_FILE … … 39 40 class CSFtpControlSocket::CFileTransferData : public CSFtpControlSocket::t_operation::COpData 40 41 { 41 42 public: 42 CFileTransferData(t_server server )43 CFileTransferData(t_server server, bool *pbUTF8) 43 44 { 44 45 pDirectoryListing=0; 45 46 nWaitNextOpState=0; … … 50 51 transferdata.nTransferStart=0; 51 52 pStartTime=0; 52 53 bUseAbsolutePaths = FALSE; 53 pParser = new CFtpListResult(server );54 pParser = new CFtpListResult(server, pbUTF8); 54 55 }; 55 56 virtual ~CFileTransferData() 56 57 { … … 79 80 class CSFtpControlSocket::CListData:public CSFtpControlSocket::t_operation::COpData 80 81 { 81 82 public: 82 CListData(t_server server )83 CListData(t_server server, bool *pbUTF8) 83 84 { 84 85 pDirectoryListing=0; 85 pParser = new CFtpListResult(server );86 pParser = new CFtpListResult(server, pbUTF8); 86 87 } 87 88 virtual ~CListData() 88 89 { … … 124 125 m_bQuit=FALSE; 125 126 m_bCheckForTimeout=TRUE; 126 127 m_bError=FALSE; 128 m_bUTF8 = false; 127 129 } 128 130 129 131 CSFtpControlSocket::~CSFtpControlSocket() … … 154 156 ASSERT(!m_Operation.nOpMode); 155 157 156 158 ASSERT(!m_pProxyLayer); 157 159 160 m_bUTF8 = (server.nUTF8 == 1); 161 158 162 if (!server.fwbypass) 159 163 { 160 164 int nProxyType=COptions::GetOptionVal(OPTION_PROXYTYPE); … … 326 330 if (m_Operation.nOpState==LIST_PWD) 327 331 { //Reply to PWD command 328 332 pData->realpath.SetServer(m_CurrentServer); 329 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 333 CString tempstr; 334 if (m_bUTF8) { 335 USES_CONVERSION; 336 337 LPCSTR utf8 = (LPCSTR)m_Reply; 338 if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) { 339 tempstr = A2CT(m_Reply); 340 } 341 else { 342 // convert from UTF-8 to ANSI 343 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 344 if (len != 0) 345 { 346 LPWSTR p1 = new WCHAR[len + 1]; 347 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 348 tempstr = W2CT(p1); 349 delete [] p1; 350 } 351 else { 352 tempstr = A2CT(m_Reply); 353 } 354 } 355 } 356 else { 357 tempstr = A2CT(m_Reply); 358 } 359 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 330 360 { 331 361 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 332 362 ResetOperation(FZ_REPLY_ERROR); 333 363 return; 334 364 } 335 pData->rawpwd= m_Reply;365 pData->rawpwd=tempstr; 336 366 m_pOwner->SetCurrentPath(pData->realpath); 337 367 if (pData->nListMode&FZ_LIST_USECACHE) 338 368 { … … 363 393 else if (m_Operation.nOpState==LIST_CWD) 364 394 { 365 395 pData->realpath.SetServer(m_CurrentServer); 366 if (m_Reply == "" || !pData->realpath.SetPath(A2CT(m_Reply))) 396 CString tempstr; 397 if (m_bUTF8) { 398 USES_CONVERSION; 399 400 LPCSTR utf8 = (LPCSTR)m_Reply; 401 if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) { 402 tempstr = A2CT(m_Reply); 403 } 404 else { 405 // convert from UTF-8 to ANSI 406 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 407 if (len != 0) 408 { 409 LPWSTR p1 = new WCHAR[len + 1]; 410 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 411 tempstr = W2CT(p1); 412 delete [] p1; 413 } 414 else { 415 tempstr = A2CT(m_Reply); 416 } 417 } 418 } 419 else { 420 tempstr = A2CT(m_Reply); 421 } 422 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 367 423 { 368 424 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 369 425 ResetOperation(FZ_REPLY_ERROR); 370 426 return; 371 427 } 372 pData->rawpwd = m_Reply;428 pData->rawpwd=tempstr; 373 429 m_pOwner->SetCurrentPath(pData->realpath); 374 430 if (pData->nListMode&FZ_LIST_USECACHE && pData->subdir=="") 375 431 { … … 410 466 else if (m_Operation.nOpState==LIST_CWD2) 411 467 { 412 468 pData->realpath.SetServer(m_CurrentServer); 413 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 469 CString tempstr; 470 if (m_bUTF8) { 471 USES_CONVERSION; 472 473 LPCSTR utf8 = (LPCSTR)m_Reply; 474 if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) { 475 tempstr = A2CT(m_Reply); 476 } 477 else { 478 // convert from UTF-8 to ANSI 479 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 480 if (len != 0) 481 { 482 LPWSTR p1 = new WCHAR[len + 1]; 483 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 484 tempstr = W2CT(p1); 485 delete [] p1; 486 } 487 else { 488 tempstr = A2CT(m_Reply); 489 } 490 } 491 } 492 else { 493 tempstr = A2CT(m_Reply); 494 } 495 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 414 496 { 415 497 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 416 498 ResetOperation(FZ_REPLY_ERROR); 417 499 return; 418 500 } 419 pData->rawpwd= m_Reply;501 pData->rawpwd=tempstr; 420 502 m_pOwner->SetCurrentPath(pData->realpath); 421 503 if (pData->nListMode&FZ_LIST_USECACHE) 422 504 { … … 512 594 513 595 if (m_Operation.nOpState==LIST_INIT) 514 596 { //Initialize some variables 515 pData = new CListData(m_CurrentServer);; 597 pData = new CListData(m_CurrentServer, &m_bUTF8); 598 pData->pParser->InitLog(this); 516 599 pData->nListMode=nListMode; 517 600 pData->path=path; 518 601 pData->subdir=subdir; … … 691 774 692 775 m_Operation.nOpMode=CSMODE_TRANSFER|(transferfile->get?CSMODE_DOWNLOAD:CSMODE_UPLOAD); 693 776 694 pData = new CFileTransferData(m_CurrentServer); 777 pData = new CFileTransferData(m_CurrentServer, &m_bUTF8); 778 pData->pParser->InitLog(this); 695 779 m_Operation.pData=pData; 696 780 697 781 //Replace invalid characters in the local filename … … 821 905 { 822 906 CServerPath path; 823 907 path.SetServer(m_CurrentServer); 824 if (!path.SetPath(A2CT(m_Reply))) 908 CString tempstr; 909 if (m_bUTF8) { 910 USES_CONVERSION; 911 912 LPCSTR utf8 = (LPCSTR)m_Reply; 913 if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) { 914 tempstr = A2CT(m_Reply); 915 } 916 else { 917 // convert from UTF-8 to ANSI 918 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 919 if (len != 0) 920 { 921 LPWSTR p1 = new WCHAR[len + 1]; 922 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 923 tempstr = W2CT(p1); 924 delete [] p1; 925 } 926 else 927 { 928 tempstr = A2CT(m_Reply); 929 } 930 } 931 } 932 else { 933 tempstr = A2CT(m_Reply); 934 } 935 if (!path.SetPath(tempstr)) 825 936 { 826 937 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path")); 827 938 nReplyError=FZ_REPLY_ERROR; 828 939 } 829 940 else 830 941 { 831 pData->rawpwd= m_Reply;942 pData->rawpwd=tempstr; 832 943 m_pOwner->SetCurrentPath(path); 833 944 if (path!=pData->transferfile.remotepath) 834 945 nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR; … … 1046 1157 { 1047 1158 CServerPath path; 1048 1159 path.SetServer(m_CurrentServer); 1049 if (!path.SetPath(A2CT(m_Reply))) 1160 CString tempstr; 1161 if (m_bUTF8) { 1162 USES_CONVERSION; 1163 1164 LPCSTR utf8 = (LPCSTR)m_Reply; 1165 if (!utf8_valid((const unsigned char*)utf8, strlen(utf8))) { 1166 tempstr = A2CT(m_Reply); 1167 } 1168 else { 1169 // convert from UTF-8 to ANSI 1170 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 1171 if (len != 0) 1172 { 1173 LPWSTR p1 = new WCHAR[len + 1]; 1174 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 1175 tempstr = W2CT(p1); 1176 delete [] p1; 1177 } 1178 else 1179 { 1180 tempstr = A2CT(m_Reply); 1181 } 1182 } 1183 } 1184 else { 1185 tempstr = A2CT(m_Reply); 1186 } 1187 if (!path.SetPath(tempstr)) 1050 1188 { 1051 1189 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path")); 1052 1190 nReplyError=FZ_REPLY_ERROR; 1053 1191 } 1054 1192 else 1055 1193 { 1056 pData->rawpwd= m_Reply;1194 pData->rawpwd=tempstr; 1057 1195 m_pOwner->SetCurrentPath(path); 1058 1196 if (path!=pData->transferfile.remotepath) 1059 1197 nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR; … … 1336 1474 filename = pData->transferfile.remotefile; 1337 1475 else 1338 1476 filename = pData->transferfile.remotepath.GetPath() + pData->transferfile.remotefile; 1339 int nLen1 = strlen(T2CA(filename)) + 1; 1340 int nLen2 = strlen(T2CA(pData->transferfile.localfile)) + 1; 1341 char *pCmd=new char[nLen1+nLen2+4]; 1342 strcpy(pCmd, T2CA(filename)); 1343 strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile)); 1344 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1477 char *pCmd; 1478 int nLen1; 1479 int nLen2; 1480 CString status = filename + _T(" ") + pData->transferfile.localfile; 1481 if (pData->transferdata.bResume) 1482 status += _T(" TRUE"); 1483 else 1484 status += _T(" FALSE"); 1485 if (m_bUTF8) { 1486 #ifdef _UNICODE 1487 // convert unicode to UTF-8 1488 LPCWSTR unicode_remote = T2CW(filename); 1489 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0); 1490 char* utf8_remote = new char[len + 1]; 1491 WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0); 1492 LPCWSTR unicode_local = T2CW(pData->transferfile.localfile); 1493 len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0); 1494 char* utf8_local = new char[len + 1]; 1495 WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0); 1496 nLen1=strlen(utf8_remote) + 1; 1497 nLen2=strlen(utf8_local)+1; 1498 pCmd=new char[nLen1+nLen2+4]; 1499 strcpy(pCmd, utf8_remote); 1500 delete [] utf8_remote; 1501 strcpy(pCmd+nLen1, utf8_local); 1502 delete [] utf8_local; 1503 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1504 #else 1505 // convert ANSI to UTF-8 1506 LPCWSTR unicode_remote = T2CW(filename); 1507 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0); 1508 char* utf8_remote = new char[len + 1]; 1509 WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0); 1510 nLen1=strlen(utf8_remote) + 1; 1511 nLen2=strlen(T2CA(pData->transferfile.localfile))+1; 1512 pCmd=new char[nLen1+nLen2+4]; 1513 strcpy(pCmd, utf8_remote); 1514 delete [] utf8_remote; 1515 strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile)); 1516 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1517 #endif 1518 } 1519 else { 1520 #ifdef _UNICODE 1521 // convert unicode to UTF-8 1522 LPCWSTR unicode_local = T2CW(pData->transferfile.localfile); 1523 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0); 1524 char* utf8_local = new char[len + 1]; 1525 WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0); 1526 nLen1=strlen(T2CA(filename)) + 1; 1527 nLen2=strlen(utf8_local)+1; 1528 pCmd=new char[nLen1+nLen2+4]; 1529 strcpy(pCmd, T2CA(filename)); 1530 strcpy(pCmd+nLen1, utf8_local); 1531 delete [] utf8_local; 1532 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1533 #else 1534 nLen1=strlen(T2CA(filename)) + 1; 1535 nLen2=strlen(T2CA(pData->transferfile.localfile))+1; 1536 pCmd=new char[nLen1+nLen2+4]; 1537 strcpy(pCmd, T2CA(filename)); 1538 strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile)); 1539 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1540 #endif 1541 } 1345 1542 pData->pStartTime = new CTime; 1346 1543 *pData->pStartTime = CTime::GetCurrentTime(); 1347 1544 if (pData->transferfile.get) 1348 1545 { 1349 if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd ))1546 if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd, status)) 1350 1547 bError=TRUE; 1351 1548 } 1352 1549 else 1353 if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd ))1550 if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd, status)) 1354 1551 bError=TRUE; 1355 1552 1356 1553 … … 1506 1703 m_Operation.nOpMode = CSMODE_RENAME; 1507 1704 int nLen; 1508 1705 char *pData; 1706 CString s_oldname, s_newname; 1509 1707 if (newPath.IsEmpty()) 1510 1708 { 1511 nLen = _tcslen( path.GetPath() + oldName + path.GetPath() + newName) + 2; 1709 s_oldname = path.GetPath() + oldName; 1710 s_newname = path.GetPath() + newName; 1711 } 1712 else { 1713 s_oldname = path.GetPath() + oldName; 1714 s_newname = newPath.GetPath() + newName; 1715 } 1716 CString status = s_oldname + _T(" ") + s_newname; 1717 if (m_bUTF8) { 1718 LPCWSTR uni_oldname = T2CW(s_oldname); 1719 int len = WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, 0, 0, 0, 0); 1720 char* utf8_oldname = new char[len + 1]; 1721 WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, utf8_oldname, len + 1, 0, 0); 1722 LPCWSTR uni_newname = T2CW(s_newname); 1723 len = WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, 0, 0, 0, 0); 1724 char* utf8_newname = new char[len + 1]; 1725 WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, utf8_newname, len + 1, 0, 0); 1726 nLen = strlen(utf8_oldname) + strlen(utf8_newname) + 2; 1512 1727 pData = new char[nLen]; 1513 strcpy(pData, T2CA(path.GetPath() + oldName)); 1514 strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(path.GetPath() + newName)); 1728 strcpy(pData, utf8_oldname); 1729 strcpy(pData + strlen(utf8_oldname) + 1, utf8_newname); 1730 delete [] utf8_oldname; 1731 delete [] utf8_newname; 1515 1732 } 1516 else 1517 { 1518 nLen = _tcslen( path.GetPath() + oldName + newPath.GetPath() + newName) + 2; 1733 else { 1734 nLen = _tcslen( s_oldname + s_newname) + 2; 1519 1735 pData = new char[nLen]; 1520 strcpy(pData, T2CA( path.GetPath() + oldName));1521 strcpy(pData + _tcslen( path.GetPath() + oldName) + 1, T2CA(newPath.GetPath() + newName));1736 strcpy(pData, T2CA(s_oldname)); 1737 strcpy(pData + _tcslen(s_oldname) + 1, T2CA(s_newname)); 1522 1738 } 1523 if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData ))1739 if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData, status)) 1524 1740 { 1525 1741 delete [] pData; 1526 1742 DoClose(); … … 2194 2410 while (p=strstr(str, "\n")) 2195 2411 { 2196 2412 *p = 0; 2197 ShowStatus(str, 3); 2413 if (m_bUTF8) { 2414 USES_CONVERSION; 2415 2416 // convert from UTF-8 to ANSI 2417 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0); 2418 if (len != 0) 2419 { 2420 LPWSTR p1 = new WCHAR[len + 1]; 2421 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2); 2422 CString tempstr = W2CT(p1); 2423 delete [] p1; 2424 ShowStatus(tempstr, 3); 2425 } 2426 else 2427 ShowStatus(str, 3); 2428 } 2429 else 2430 ShowStatus(str, 3); 2198 2431 str = p+1; 2199 2432 } 2200 ShowStatus(str, 3); 2433 if (m_bUTF8) { 2434 USES_CONVERSION; 2435 2436 // convert from UTF-8 to ANSI 2437 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0); 2438 if (len != 0) 2439 { 2440 LPWSTR p1 = new WCHAR[len + 1]; 2441 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2); 2442 CString tempstr = W2CT(p1); 2443 delete [] p1; 2444 ShowStatus(tempstr, 3); 2445 } 2446 else 2447 ShowStatus(str, 3); 2448 } 2449 else 2450 ShowStatus(str, 3); 2201 2451 } 2202 2452 break; 2203 2453 case SFTP_DATAID_CTS_CRITICALERROR: … … 2242 2492 ResetOperation(FZ_REPLY_ERROR); 2243 2493 else 2244 2494 { 2245 ShowStatus((char *)pData, 3); 2495 if (m_bUTF8) { 2496 USES_CONVERSION; 2497 2498 // convert from UTF-8 to ANSI 2499 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1, NULL, 0); 2500 if (len != 0) 2501 { 2502 LPWSTR p1 = new WCHAR[len + 1]; 2503 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1 , (LPWSTR)p1, len*2); 2504 CString tempstr = W2CT(p1); 2505 delete [] p1; 2506 ShowStatus(tempstr, 3); 2507 } 2508 else 2509 ShowStatus((char *)pData, 3); 2510 } 2511 else 2512 ShowStatus((char *)pData, 3); 2246 2513 ProcessReply(); 2247 2514 } 2248 2515 break; … … 2921 3188 USES_CONVERSION; 2922 3189 m_Operation.nOpMode=CSMODE_CHMOD; 2923 3190 CString str; 3191 CString status; 3192 int nLen; 3193 char *pData; 2924 3194 str.Format( _T("%d %s%s"), nValue, path.GetPath(), filename); 2925 int nLen = strlen(T2CA(str)) + 1; 2926 char *pData=new char[nLen]; 2927 strcpy(pData, T2CA(str)); 2928 int pos(str.Find( _T(" ") )); 2929 ASSERT(pos!=-1); 2930 pData[pos]=0; 2931 if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData)) 3195 status = str; 3196 if (m_bUTF8) { 3197 LPCWSTR unicode = T2CW(str); 3198 int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0); 3199 char* utf8 = new char[len + 1]; 3200 WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0); 3201 nLen=strlen(utf8)+1; 3202 pData=new char[nLen]; 3203 strcpy(pData, utf8); 3204 int pos(str.Find( _T(" ") )); 3205 ASSERT(pos!=-1); 3206 pData[pos]=0; 3207 } 3208 else { 3209 nLen=strlen(T2CA(str))+1; 3210 pData=new char[nLen]; 3211 strcpy(pData, T2CA(str)); 3212 int pos(str.Find( _T(" ") )); 3213 ASSERT(pos!=-1); 3214 pData[pos]=0; 3215 } 3216 if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData, status)) 2932 3217 DoClose(); 2933 3218 delete [] pData; 2934 3219 } -
SftpControlSocket.h
diff -Nur source/SftpControlSocket.h source.patch/SftpControlSocket.h
old new 37 37 class CSFtpControlSocket : public CControlSocket 38 38 { 39 39 public: 40 bool m_bUTF8; 40 41 BOOL m_bError; 41 42 void OnClientError(int nErrorCode); 42 43 int OnClientRequest(int nId, int &nDataLength, LPVOID pData);