Ticket #1467: filezilla_sftp_utf8.patch
File filezilla_sftp_utf8.patch, 24.6 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 39 39 class CSFtpControlSocket::CFileTransferData : public CSFtpControlSocket::t_operation::COpData 40 40 { 41 41 public: 42 CFileTransferData(t_server server )42 CFileTransferData(t_server server, bool bUTF8) 43 43 { 44 44 pDirectoryListing=0; 45 45 nWaitNextOpState=0; … … 50 50 transferdata.nTransferStart=0; 51 51 pStartTime=0; 52 52 bUseAbsolutePaths = FALSE; 53 pParser = new CFtpListResult(server );53 pParser = new CFtpListResult(server, bUTF8); 54 54 }; 55 55 virtual ~CFileTransferData() 56 56 { … … 79 79 class CSFtpControlSocket::CListData:public CSFtpControlSocket::t_operation::COpData 80 80 { 81 81 public: 82 CListData(t_server server )82 CListData(t_server server, bool bUTF8) 83 83 { 84 84 pDirectoryListing=0; 85 pParser = new CFtpListResult(server );85 pParser = new CFtpListResult(server, bUTF8); 86 86 } 87 87 virtual ~CListData() 88 88 { … … 124 124 m_bQuit=FALSE; 125 125 m_bCheckForTimeout=TRUE; 126 126 m_bError=FALSE; 127 m_bUTF8 = false; 127 128 } 128 129 129 130 CSFtpControlSocket::~CSFtpControlSocket() … … 154 155 ASSERT(!m_Operation.nOpMode); 155 156 156 157 ASSERT(!m_pProxyLayer); 157 158 159 m_bUTF8 = (server.nUTF8 == 1); 160 158 161 if (!server.fwbypass) 159 162 { 160 163 int nProxyType=COptions::GetOptionVal(OPTION_PROXYTYPE); … … 326 329 if (m_Operation.nOpState==LIST_PWD) 327 330 { //Reply to PWD command 328 331 pData->realpath.SetServer(m_CurrentServer); 329 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 330 { 331 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 332 ResetOperation(FZ_REPLY_ERROR); 333 return; 332 if (m_bUTF8) { 333 USES_CONVERSION; 334 335 // convert from UTF-8 to ANSI 336 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 337 if (len != 0) 338 { 339 LPWSTR p1 = new WCHAR[len + 1]; 340 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 341 CString tempstr = W2CT(p1); 342 delete [] p1; 343 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 344 { 345 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 346 ResetOperation(FZ_REPLY_ERROR); 347 return; 348 } 349 pData->rawpwd=tempstr; 350 } 351 else 352 { 353 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 354 ResetOperation(FZ_REPLY_ERROR); 355 return; 356 } 357 } 358 else { 359 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 360 { 361 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 362 ResetOperation(FZ_REPLY_ERROR); 363 return; 364 } 365 pData->rawpwd=m_Reply; 334 366 } 335 pData->rawpwd=m_Reply;336 367 m_pOwner->SetCurrentPath(pData->realpath); 337 368 if (pData->nListMode&FZ_LIST_USECACHE) 338 369 { … … 363 394 else if (m_Operation.nOpState==LIST_CWD) 364 395 { 365 396 pData->realpath.SetServer(m_CurrentServer); 366 if (m_Reply == "" || !pData->realpath.SetPath(A2CT(m_Reply))) 367 { 368 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 369 ResetOperation(FZ_REPLY_ERROR); 370 return; 397 if (m_bUTF8) { 398 USES_CONVERSION; 399 400 // convert from UTF-8 to ANSI 401 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 402 if (len != 0) 403 { 404 LPWSTR p1 = new WCHAR[len + 1]; 405 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 406 CString tempstr = W2CT(p1); 407 delete [] p1; 408 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 409 { 410 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 411 ResetOperation(FZ_REPLY_ERROR); 412 return; 413 } 414 pData->rawpwd=tempstr; 415 } 416 else 417 { 418 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 419 ResetOperation(FZ_REPLY_ERROR); 420 return; 421 } 422 } 423 else { 424 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 425 { 426 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 427 ResetOperation(FZ_REPLY_ERROR); 428 return; 429 } 430 pData->rawpwd=m_Reply; 371 431 } 372 pData->rawpwd = m_Reply;373 432 m_pOwner->SetCurrentPath(pData->realpath); 374 433 if (pData->nListMode&FZ_LIST_USECACHE && pData->subdir=="") 375 434 { … … 410 469 else if (m_Operation.nOpState==LIST_CWD2) 411 470 { 412 471 pData->realpath.SetServer(m_CurrentServer); 413 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 414 { 415 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 416 ResetOperation(FZ_REPLY_ERROR); 417 return; 472 if (m_bUTF8) { 473 USES_CONVERSION; 474 475 // convert from UTF-8 to ANSI 476 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 477 if (len != 0) 478 { 479 LPWSTR p1 = new WCHAR[len + 1]; 480 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 481 CString tempstr = W2CT(p1); 482 delete [] p1; 483 if (tempstr=="" || !pData->realpath.SetPath(tempstr)) 484 { 485 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 486 ResetOperation(FZ_REPLY_ERROR); 487 return; 488 } 489 pData->rawpwd=tempstr; 490 } 491 else 492 { 493 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 494 ResetOperation(FZ_REPLY_ERROR); 495 return; 496 } 497 } 498 else { 499 if (m_Reply=="" || !pData->realpath.SetPath(A2CT(m_Reply))) 500 { 501 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path") ); 502 ResetOperation(FZ_REPLY_ERROR); 503 return; 504 } 505 pData->rawpwd=m_Reply; 418 506 } 419 pData->rawpwd=m_Reply;420 507 m_pOwner->SetCurrentPath(pData->realpath); 421 508 if (pData->nListMode&FZ_LIST_USECACHE) 422 509 { … … 512 599 513 600 if (m_Operation.nOpState==LIST_INIT) 514 601 { //Initialize some variables 515 pData = new CListData(m_CurrentServer );;602 pData = new CListData(m_CurrentServer, m_bUTF8); 516 603 pData->nListMode=nListMode; 517 604 pData->path=path; 518 605 pData->subdir=subdir; … … 691 778 692 779 m_Operation.nOpMode=CSMODE_TRANSFER|(transferfile->get?CSMODE_DOWNLOAD:CSMODE_UPLOAD); 693 780 694 pData = new CFileTransferData(m_CurrentServer );781 pData = new CFileTransferData(m_CurrentServer, m_bUTF8); 695 782 m_Operation.pData=pData; 696 783 697 784 //Replace invalid characters in the local filename … … 821 908 { 822 909 CServerPath path; 823 910 path.SetServer(m_CurrentServer); 824 if (!path.SetPath(A2CT(m_Reply))) 911 CString tempstr; 912 if (m_bUTF8) { 913 USES_CONVERSION; 914 915 // convert from UTF-8 to ANSI 916 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 917 if (len != 0) 918 { 919 LPWSTR p1 = new WCHAR[len + 1]; 920 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 921 tempstr = W2CT(p1); 922 delete [] p1; 923 } 924 else 925 { 926 tempstr = ""; 927 } 928 } 929 else { 930 tempstr = A2CT(m_Reply); 931 } 932 if (!path.SetPath(tempstr)) 825 933 { 826 934 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path")); 827 935 nReplyError=FZ_REPLY_ERROR; 828 936 } 829 937 else 830 938 { 831 pData->rawpwd= m_Reply;939 pData->rawpwd=tempstr; 832 940 m_pOwner->SetCurrentPath(path); 833 941 if (path!=pData->transferfile.remotepath) 834 942 nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR; … … 1046 1154 { 1047 1155 CServerPath path; 1048 1156 path.SetServer(m_CurrentServer); 1049 if (!path.SetPath(A2CT(m_Reply))) 1157 CString tempstr; 1158 if (m_bUTF8) { 1159 USES_CONVERSION; 1160 1161 // convert from UTF-8 to ANSI 1162 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1, NULL, 0); 1163 if (len != 0) 1164 { 1165 LPWSTR p1 = new WCHAR[len + 1]; 1166 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)m_Reply, -1 , (LPWSTR)p1, len*2); 1167 tempstr = W2CT(p1); 1168 delete [] p1; 1169 } 1170 else 1171 { 1172 tempstr = ""; 1173 } 1174 } 1175 else { 1176 tempstr = A2CT(m_Reply); 1177 } 1178 if (!path.SetPath(tempstr)) 1050 1179 { 1051 1180 LogMessage(__FILE__, __LINE__, this,FZ_LOG_WARNING, _T("Can't parse path")); 1052 1181 nReplyError=FZ_REPLY_ERROR; 1053 1182 } 1054 1183 else 1055 1184 { 1056 pData->rawpwd= m_Reply;1185 pData->rawpwd=tempstr; 1057 1186 m_pOwner->SetCurrentPath(path); 1058 1187 if (path!=pData->transferfile.remotepath) 1059 1188 nReplyError=FZ_REPLY_ERROR | FZ_REPLY_CRITICALERROR; … … 1336 1465 filename = pData->transferfile.remotefile; 1337 1466 else 1338 1467 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); 1468 char *pCmd; 1469 int nLen1; 1470 int nLen2; 1471 CString status = filename + _T(" ") + pData->transferfile.localfile; 1472 if (pData->transferdata.bResume) 1473 status += _T(" TRUE"); 1474 else 1475 status += _T(" FALSE"); 1476 if (m_bUTF8) { 1477 #ifdef _UNICODE 1478 LPCWSTR unicode_remote = T2CW(filename); 1479 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0); 1480 char* utf8_remote = new char[len + 1]; 1481 WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0); 1482 LPCWSTR unicode_local = T2CW(pData->transferfile.localfile); 1483 len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0); 1484 char* utf8_local = new char[len + 1]; 1485 WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0); 1486 nLen1=strlen(utf8_remote) + 1; 1487 nLen2=strlen(utf8_local)+1; 1488 pCmd=new char[nLen1+nLen2+4]; 1489 strcpy(pCmd, utf8_remote); 1490 delete [] utf8_remote; 1491 strcpy(pCmd+nLen1, utf8_local); 1492 delete [] utf8_local; 1493 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1494 #else 1495 LPCWSTR unicode_remote = T2CW(filename); 1496 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, 0, 0, 0, 0); 1497 char* utf8_remote = new char[len + 1]; 1498 WideCharToMultiByte(CP_UTF8, 0, unicode_remote, -1, utf8_remote, len + 1, 0, 0); 1499 nLen1=strlen(utf8_remote) + 1; 1500 nLen2=strlen(T2CA(pData->transferfile.localfile))+1; 1501 pCmd=new char[nLen1+nLen2+4]; 1502 strcpy(pCmd, utf8_remote); 1503 delete [] utf8_remote; 1504 strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile)); 1505 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1506 #endif 1507 } 1508 else { 1509 #ifdef _UNICODE 1510 LPCWSTR unicode_local = T2CW(pData->transferfile.localfile); 1511 int len = WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, 0, 0, 0, 0); 1512 char* utf8_local = new char[len + 1]; 1513 WideCharToMultiByte(CP_UTF8, 0, unicode_local, -1, utf8_local, len + 1, 0, 0); 1514 nLen1=strlen(T2CA(filename)) + 1; 1515 nLen2=strlen(utf8_local)+1; 1516 pCmd=new char[nLen1+nLen2+4]; 1517 strcpy(pCmd, T2CA(filename)); 1518 strcpy(pCmd+nLen1, utf8_local); 1519 delete [] utf8_local; 1520 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1521 #else 1522 nLen1=strlen(T2CA(filename)) + 1; 1523 nLen2=strlen(T2CA(pData->transferfile.localfile))+1; 1524 pCmd=new char[nLen1+nLen2+4]; 1525 strcpy(pCmd, T2CA(filename)); 1526 strcpy(pCmd+nLen1, T2CA(pData->transferfile.localfile)); 1527 memcpy(pCmd+nLen1+nLen2, &pData->transferdata.bResume, 4); 1528 #endif 1529 } 1345 1530 pData->pStartTime = new CTime; 1346 1531 *pData->pStartTime = CTime::GetCurrentTime(); 1347 1532 if (pData->transferfile.get) 1348 1533 { 1349 if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd ))1534 if (!m_pDataChannel->Send(SFTP_DATAID_STC_GET, nLen1+nLen2+4, pCmd, status)) 1350 1535 bError=TRUE; 1351 1536 } 1352 1537 else 1353 if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd ))1538 if (!m_pDataChannel->Send(SFTP_DATAID_STC_PUT, nLen1+nLen2+4, pCmd, status)) 1354 1539 bError=TRUE; 1355 1540 1356 1541 … … 1506 1691 m_Operation.nOpMode = CSMODE_RENAME; 1507 1692 int nLen; 1508 1693 char *pData; 1694 CString s_oldname, s_newname; 1509 1695 if (newPath.IsEmpty()) 1510 1696 { 1511 nLen = _tcslen( path.GetPath() + oldName + path.GetPath() + newName) + 2; 1697 s_oldname = path.GetPath() + oldName; 1698 s_newname = path.GetPath() + newName; 1699 } 1700 else { 1701 s_oldname = path.GetPath() + oldName; 1702 s_newname = newPath.GetPath() + newName; 1703 } 1704 CString status = s_oldname + _T(" ") + s_newname; 1705 if (m_bUTF8) { 1706 LPCWSTR uni_oldname = T2CW(s_oldname); 1707 int len = WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, 0, 0, 0, 0); 1708 char* utf8_oldname = new char[len + 1]; 1709 WideCharToMultiByte(CP_UTF8, 0, uni_oldname, -1, utf8_oldname, len + 1, 0, 0); 1710 LPCWSTR uni_newname = T2CW(s_newname); 1711 len = WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, 0, 0, 0, 0); 1712 char* utf8_newname = new char[len + 1]; 1713 WideCharToMultiByte(CP_UTF8, 0, uni_newname, -1, utf8_newname, len + 1, 0, 0); 1714 nLen = strlen(utf8_oldname) + strlen(utf8_newname) + 2; 1512 1715 pData = new char[nLen]; 1513 strcpy(pData, T2CA(path.GetPath() + oldName)); 1514 strcpy(pData + _tcslen(path.GetPath() + oldName) + 1, T2CA(path.GetPath() + newName)); 1716 strcpy(pData, utf8_oldname); 1717 strcpy(pData + strlen(utf8_oldname) + 1, utf8_newname); 1718 delete [] utf8_oldname; 1719 delete [] utf8_newname; 1515 1720 } 1516 else 1517 { 1518 nLen = _tcslen( path.GetPath() + oldName + newPath.GetPath() + newName) + 2; 1721 else { 1722 nLen = _tcslen( s_oldname + s_newname) + 2; 1519 1723 pData = new char[nLen]; 1520 strcpy(pData, T2CA( path.GetPath() + oldName));1521 strcpy(pData + _tcslen( path.GetPath() + oldName) + 1, T2CA(newPath.GetPath() + newName));1724 strcpy(pData, T2CA(s_oldname)); 1725 strcpy(pData + _tcslen(s_oldname) + 1, T2CA(s_newname)); 1522 1726 } 1523 if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData ))1727 if (!m_pDataChannel->Send(SFTP_DATAID_STC_RENAME, nLen, pData, status)) 1524 1728 { 1525 1729 delete [] pData; 1526 1730 DoClose(); … … 2194 2398 while (p=strstr(str, "\n")) 2195 2399 { 2196 2400 *p = 0; 2197 ShowStatus(str, 3); 2401 if (m_bUTF8) { 2402 USES_CONVERSION; 2403 2404 // convert from UTF-8 to ANSI 2405 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0); 2406 if (len != 0) 2407 { 2408 LPWSTR p1 = new WCHAR[len + 1]; 2409 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2); 2410 CString tempstr = W2CT(p1); 2411 delete [] p1; 2412 ShowStatus(tempstr, 3); 2413 } 2414 else 2415 ShowStatus(str, 3); 2416 } 2417 else 2418 ShowStatus(str, 3); 2198 2419 str = p+1; 2199 2420 } 2200 ShowStatus(str, 3); 2421 if (m_bUTF8) { 2422 USES_CONVERSION; 2423 2424 // convert from UTF-8 to ANSI 2425 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1, NULL, 0); 2426 if (len != 0) 2427 { 2428 LPWSTR p1 = new WCHAR[len + 1]; 2429 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)str, -1 , (LPWSTR)p1, len*2); 2430 CString tempstr = W2CT(p1); 2431 delete [] p1; 2432 ShowStatus(tempstr, 3); 2433 } 2434 else 2435 ShowStatus(str, 3); 2436 } 2437 else 2438 ShowStatus(str, 3); 2201 2439 } 2202 2440 break; 2203 2441 case SFTP_DATAID_CTS_CRITICALERROR: … … 2242 2480 ResetOperation(FZ_REPLY_ERROR); 2243 2481 else 2244 2482 { 2245 ShowStatus((char *)pData, 3); 2483 if (m_bUTF8) { 2484 USES_CONVERSION; 2485 2486 // convert from UTF-8 to ANSI 2487 int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1, NULL, 0); 2488 if (len != 0) 2489 { 2490 LPWSTR p1 = new WCHAR[len + 1]; 2491 MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pData, -1 , (LPWSTR)p1, len*2); 2492 CString tempstr = W2CT(p1); 2493 delete [] p1; 2494 ShowStatus(tempstr, 3); 2495 } 2496 else 2497 ShowStatus((char *)pData, 3); 2498 } 2499 else 2500 ShowStatus((char *)pData, 3); 2246 2501 ProcessReply(); 2247 2502 } 2248 2503 break; … … 2921 3176 USES_CONVERSION; 2922 3177 m_Operation.nOpMode=CSMODE_CHMOD; 2923 3178 CString str; 3179 CString status; 3180 int nLen; 3181 char *pData; 2924 3182 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)) 3183 status = str; 3184 if (m_bUTF8) { 3185 LPCWSTR unicode = T2CW(str); 3186 int len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, 0, 0, 0, 0); 3187 char* utf8 = new char[len + 1]; 3188 WideCharToMultiByte(CP_UTF8, 0, unicode, -1, utf8, len + 1, 0, 0); 3189 nLen=strlen(utf8)+1; 3190 pData=new char[nLen]; 3191 strcpy(pData, utf8); 3192 int pos(str.Find( _T(" ") )); 3193 ASSERT(pos!=-1); 3194 pData[pos]=0; 3195 } 3196 else { 3197 nLen=strlen(T2CA(str))+1; 3198 pData=new char[nLen]; 3199 strcpy(pData, T2CA(str)); 3200 int pos(str.Find( _T(" ") )); 3201 ASSERT(pos!=-1); 3202 pData[pos]=0; 3203 } 3204 if (!m_pDataChannel->Send(SFTP_DATAID_STC_CHMOD, nLen, pData, status)) 2932 3205 DoClose(); 2933 3206 delete [] pData; 2934 3207 } -
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);