diff options
author | George Hazan <ghazan@miranda.im> | 2018-01-16 16:21:00 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-01-16 16:21:00 +0300 |
commit | 634a32a8d9114b1da1ffd0dc2b78dde3060a731f (patch) | |
tree | 7bb66f2941c6aff4f0b1ec6807e5c3a043dfe5d6 /protocols | |
parent | 954ee9077fb34e5e6dcda3485ae9c192d9b19fd2 (diff) |
ICQCorp:
- crash fixed when one sends a file;
- all file names went to Unicode;
- all messages are being send in Utf8 instead of ANSI;
- version bump;
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/ICQCorp/src/event.h | 3 | ||||
-rw-r--r-- | protocols/ICQCorp/src/protocol.cpp | 10 | ||||
-rw-r--r-- | protocols/ICQCorp/src/protocol.h | 2 | ||||
-rw-r--r-- | protocols/ICQCorp/src/services.cpp | 39 | ||||
-rw-r--r-- | protocols/ICQCorp/src/transfer.cpp | 63 | ||||
-rw-r--r-- | protocols/ICQCorp/src/transfer.h | 11 | ||||
-rw-r--r-- | protocols/ICQCorp/src/version.h | 6 |
7 files changed, 67 insertions, 67 deletions
diff --git a/protocols/ICQCorp/src/event.h b/protocols/ICQCorp/src/event.h index ee204927e2..3d469ee688 100644 --- a/protocols/ICQCorp/src/event.h +++ b/protocols/ICQCorp/src/event.h @@ -32,7 +32,8 @@ public: bool isEvent(SOCKET hSocket, unsigned long theSequence);
void noAck();
unsigned short cmd, subCmd;
- unsigned int uin, sequence;
+ unsigned int uin;
+ int sequence;
int reply;
unsigned int hTimer;
Packet *packet;
diff --git a/protocols/ICQCorp/src/protocol.cpp b/protocols/ICQCorp/src/protocol.cpp index e38e9b9e31..d57ceaaad1 100644 --- a/protocols/ICQCorp/src/protocol.cpp +++ b/protocols/ICQCorp/src/protocol.cpp @@ -1548,7 +1548,7 @@ ICQEvent *ICQ::sendReadAwayMsg(ICQUser *u) ///////////////////////////////////////////////////////////////////////////////
-ICQTransfer *ICQ::sendFile(ICQUser *u, char *description, char *filename, unsigned int size, char **files)
+ICQTransfer *ICQ::sendFile(ICQUser *u, char *description, char *filename, unsigned int size, wchar_t **files)
{
if (!u->socket.connected() && !openConnection(u->socket))
return nullptr;
@@ -1558,16 +1558,16 @@ ICQTransfer *ICQ::sendFile(ICQUser *u, char *description, char *filename, unsign ICQTransfer *transfer = new ICQTransfer(u, tcpSequenceVal);
for (i = 0; files[i]; i++);
- transfer->files = new char*[i + 1];
- for (i = 0; files[i]; i++) transfer->files[i] = _strdup(files[i]);
+ transfer->files = new wchar_t*[i + 1];
+ for (i = 0; files[i]; i++) transfer->files[i] = _wcsdup(files[i]);
transfer->files[i] = nullptr;
transfer->description = _strdup(description);
transfer->count = i;
transfer->totalSize = size;
- transfer->path = _strdup(transfer->files[0]);
- char *s = strrchr(transfer->path, '\\');
+ transfer->path = _wcsdup(transfer->files[0]);
+ wchar_t *s = wcsrchr(transfer->path, '\\');
if (s != nullptr)
*s = 0;
diff --git a/protocols/ICQCorp/src/protocol.h b/protocols/ICQCorp/src/protocol.h index 60294d834c..185e7ce097 100644 --- a/protocols/ICQCorp/src/protocol.h +++ b/protocols/ICQCorp/src/protocol.h @@ -150,7 +150,7 @@ public: ICQEvent *sendMessage(ICQUser *u, char *m);
ICQEvent *sendUrl(ICQUser *u, char *url);
ICQEvent *sendReadAwayMsg(ICQUser *u);
- ICQTransfer *sendFile(ICQUser *u, char *description, char *filename, unsigned int size, char **files);
+ ICQTransfer *sendFile(ICQUser *u, char *description, char *filename, unsigned int size, wchar_t **files);
bool logon(unsigned short logonStatus);
void logoff(bool reconnect);
diff --git a/protocols/ICQCorp/src/services.cpp b/protocols/ICQCorp/src/services.cpp index d182c0bc33..91c3856b39 100644 --- a/protocols/ICQCorp/src/services.cpp +++ b/protocols/ICQCorp/src/services.cpp @@ -179,11 +179,10 @@ static INT_PTR icqSendMessage(WPARAM, LPARAM lParam) CCSDATA *ccs = (CCSDATA *)lParam;
ICQUser *u = icq.getUserByContact(ccs->hContact);
- // uin = db_get_dw(ccs->hContact, ICQCORP_PROTONAME, "UIN", 0);
if (u == nullptr || icq.statusVal <= ID_STATUS_OFFLINE)
return 0;
- ICQEvent *icqEvent = icq.sendMessage(u, ptrA(mir_utf8decodeA((char*)ccs->lParam)));
+ ICQEvent *icqEvent = icq.sendMessage(u, (char*)ccs->lParam);
return icqEvent ? icqEvent->sequence : 0;
}
@@ -201,7 +200,9 @@ static INT_PTR icqRecvMessage(WPARAM, LPARAM lParam) DBEVENTINFO dbei = {};
dbei.szModule = protoName;
dbei.timestamp = pre->timestamp;
- dbei.flags = pre->flags & (PREF_CREATEREAD ? DBEF_READ : 0);
+ dbei.flags = (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0;
+ if (Utf8CheckString(pre->szMessage))
+ dbei.flags |= DBEF_UTF;
dbei.eventType = EVENTTYPE_MESSAGE;
dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1;
dbei.pBlob = (PBYTE)pre->szMessage;
@@ -301,21 +302,20 @@ static INT_PTR icqRecvAwayMsg(WPARAM, LPARAM lParam) static INT_PTR icqSendFile(WPARAM, LPARAM lParam)
{
CCSDATA *ccs = (CCSDATA *)lParam;
- char **files = (char **)ccs->lParam;
- //HANDLE hFile;
- ICQUser *u;
+ wchar_t **files = (wchar_t**)ccs->lParam;
T("[ ] send file\n");
- u = icq.getUserByContact(ccs->hContact);
- if (u == nullptr || u->statusVal == ID_STATUS_OFFLINE || icq.statusVal <= ID_STATUS_OFFLINE) return 0;
+ ICQUser *u = icq.getUserByContact(ccs->hContact);
+ if (u == nullptr || u->statusVal == ID_STATUS_OFFLINE || icq.statusVal <= ID_STATUS_OFFLINE)
+ return 0;
unsigned long filesCount, directoriesCount, filesSize = 0;
char filename[MAX_PATH], format[32];
- WIN32_FIND_DATA findData;
+ WIN32_FIND_DATAW findData;
for (filesCount = 0, directoriesCount = 0; files[filesCount]; filesCount++) {
- FindClose(FindFirstFile(files[filesCount], &findData));
+ FindClose(FindFirstFileW(files[filesCount], &findData));
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) directoriesCount++;
else filesSize += findData.nFileSizeLow;
}
@@ -327,8 +327,8 @@ static INT_PTR icqSendFile(WPARAM, LPARAM lParam) }
else {
if (filesCount == 1) {
- char *p = strrchr(files[0], '\\');
- mir_strcpy(filename, p ? p + 1 : files[0]);
+ wchar_t *p = wcsrchr(files[0], '\\');
+ mir_strcpy(filename, _T2A(p ? p + 1 : files[0]));
}
else sprintf(filename, filesCount == 1 ? Translate("%d file") : Translate("%d files"), filesCount);
}
@@ -340,16 +340,15 @@ static INT_PTR icqSendFile(WPARAM, LPARAM lParam) static INT_PTR icqFileAllow(WPARAM, LPARAM lParam)
{
- CCSDATA *ccs = (CCSDATA *)lParam;
- ICQTransfer *t = (ICQTransfer *)ccs->wParam;
- ICQUser *u;
-
T("[ ] send accept file request\n");
- u = icq.getUserByContact(ccs->hContact);
- if (u == nullptr || u->statusVal == ID_STATUS_OFFLINE) return 0;
+ CCSDATA *ccs = (CCSDATA *)lParam;
+ ICQUser *u = icq.getUserByContact(ccs->hContact);
+ if (u == nullptr || u->statusVal == ID_STATUS_OFFLINE)
+ return 0;
- t->path = _strdup((char*)ccs->lParam);
+ ICQTransfer *t = (ICQTransfer *)ccs->wParam;
+ t->path = _wcsdup((wchar_t*)ccs->lParam);
icq.acceptFile(u, t->sequence, (char*)ccs->lParam);
return (INT_PTR)t;
@@ -444,8 +443,8 @@ static INT_PTR icqFileResume(WPARAM wParam, LPARAM lParam) ICQTransfer *t = (ICQTransfer *)wParam;
T("[ ] send file resume\n");
- t->resume(pfr->action, (char*)pfr->szFilename);
+ t->resume(pfr->action, (wchar_t*)pfr->szFilename);
return 0;
}
diff --git a/protocols/ICQCorp/src/transfer.cpp b/protocols/ICQCorp/src/transfer.cpp index 3bf64e3c1e..13a8eb6499 100644 --- a/protocols/ICQCorp/src/transfer.cpp +++ b/protocols/ICQCorp/src/transfer.cpp @@ -70,7 +70,7 @@ void ICQTransfer::processTcpPacket(Packet &packet) {
unsigned int /*i,*/ status, junkLong;
unsigned char cmd/*, junkChar*/;
- char *name = nullptr, *directoryName = nullptr;
+ char *name = nullptr, *directoryName = nullptr, *fileName = nullptr;
packet >> cmd;
switch (cmd) {
@@ -82,8 +82,8 @@ void ICQTransfer::processTcpPacket(Packet &packet) >> speed
>> name;
- files = new char*[count + 1];
- ZeroMemory(files, (count + 1)*sizeof(char*));
+ files = new wchar_t*[count + 1];
+ ZeroMemory(files, (count + 1)*sizeof(wchar_t*));
ack(ACKRESULT_INITIALISING);
sendPacket0x01();
@@ -101,18 +101,17 @@ void ICQTransfer::processTcpPacket(Packet &packet) case 0x02:
T("[tcp] recieve next file\n");
packet >> directory
- >> files[++current]
+ >> fileName
>> directoryName
>> fileSize
>> fileDate
>> speed;
- if (directoryName[0]) {
- char *fullName = new char[mir_strlen(directoryName) + mir_strlen(files[current]) + 2];
- sprintf(fullName, "%s\\%s", directoryName, files[current]);
- delete[] files[current];
- files[current] = fullName;
- }
+ ++current;
+ if (directoryName[0])
+ files[current] = CMStringW(FORMAT, L"%s\\%s", ptrW(Utf8DecodeW(directoryName)), ptrW(Utf8DecodeW(fileName))).Detach();
+ else
+ files[current] = Utf8DecodeW(fileName);
if (directory) createDirectory();
else openFile();
@@ -220,16 +219,16 @@ void ICQTransfer::sendPacket0x02() current++;
openFile();
- char *directoryName = _strdup(fileName);
- char *p = strrchr(directoryName, '\\');
+ wchar_t *directoryName = _wcsdup(fileName);
+ wchar_t *p = wcsrchr(directoryName, '\\');
p[0] = 0;
p[1] = 0;
Packet packet;
packet << (unsigned char)0x02
<< directory
- << (strrchr(fileName, '\\') + 1)
- << (directoryName + mir_strlen(path) + 1)
+ << ptrA(mir_utf8encodeW(wcsrchr(fileName, '\\') + 1)).get()
+ << ptrA(mir_utf8encodeW(directoryName + mir_wstrlen(path) + 1)).get()
<< fileSize
<< fileDate
<< speed;
@@ -307,14 +306,15 @@ void ICQTransfer::ack(unsigned int result) PROTOFILETRANSFERSTATUS fts;
fts.cbSize = sizeof(fts);
+ fts.flags = PFTS_UNICODE;
fts.hContact = hContact;
- fts.pszFiles = files;
+ fts.pwszFiles = files;
fts.totalFiles = count;
fts.currentFileNumber = current;
fts.totalBytes = totalSize;
fts.totalProgress = totalProgress;
- fts.szWorkingDir = path;
- fts.szCurrentFile = fileName;
+ fts.wszWorkingDir = path;
+ fts.wszCurrentFile = fileName;
fts.currentFileSize = fileSize;
fts.currentFileProgress = fileProgress;
fts.currentFileTime = TimeZone_ToLocal(fileDate);
@@ -361,7 +361,7 @@ void ICQTransfer::process() ///////////////////////////////////////////////////////////////////////////////
-void ICQTransfer::resume(int action, const char *newName)
+void ICQTransfer::resume(int action, const wchar_t *newName)
{
switch (action) {
case FILERESUME_OVERWRITE:
@@ -375,10 +375,8 @@ void ICQTransfer::resume(int action, const char *newName) case FILERESUME_RENAME:
T("[ ] rename file\n");
- delete[] fileName;
- fileName = new char[mir_strlen(newName) + 1];
- mir_strcpy(fileName, newName);
- files[current] = fileName;
+
+ replaceStrW(fileName, fileName);
openFile();
fileProgress = 0;
@@ -406,16 +404,16 @@ void ICQTransfer::openFile() if (hFile != INVALID_HANDLE_VALUE)
closeFile();
if (path)
- SetCurrentDirectory(path);
+ SetCurrentDirectoryW(path);
fileName = files[current];
- WIN32_FIND_DATA findData;
- HANDLE hFind = FindFirstFile(fileName, &findData);
+ WIN32_FIND_DATAW findData;
+ HANDLE hFind = FindFirstFileW(fileName, &findData);
if (hFind != INVALID_HANDLE_VALUE) {
FindClose(hFind);
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- T("open directory %s\n", fileName);
+ T("open directory %S\n", fileName);
directory = 1;
fileProgress = 0;
fileSize = 0;
@@ -425,12 +423,15 @@ void ICQTransfer::openFile() }
directory = 0;
- hFile = CreateFile(fileName, sending ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, 0, nullptr);
+ hFile = CreateFileW(fileName, sending ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, 0, nullptr);
if (hFile == INVALID_HANDLE_VALUE) {
char msg[2048];
- T("can't open file %s\n", fileName);
- sprintf(msg, "%s\n%s", sending ? Translate("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it.") : Translate("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."), fileName);
+ T("can't open file %S\n", fileName);
+ sprintf(msg, "%s\n%S", sending ?
+ Translate("Your file transfer has been aborted because one of the files that you selected to send is no longer readable from the disk. You may have deleted or moved it.") :
+ Translate("Your file receive has been aborted because Miranda could not open the destination file in order to write to it. You may be trying to save to a read-only folder."),
+ fileName);
MessageBox(nullptr, msg, Translate(protoName), MB_ICONWARNING | MB_OK);
return;
}
@@ -472,10 +473,10 @@ void ICQTransfer::setFilePosition() void ICQTransfer::createDirectory()
{
if (path)
- SetCurrentDirectory(path);
+ SetCurrentDirectoryW(path);
fileName = files[current];
- CreateDirectory(fileName, nullptr);
+ CreateDirectoryW(fileName, nullptr);
fileProgress = 0;
}
diff --git a/protocols/ICQCorp/src/transfer.h b/protocols/ICQCorp/src/transfer.h index 8bfed7fe4a..4d19ecf281 100644 --- a/protocols/ICQCorp/src/transfer.h +++ b/protocols/ICQCorp/src/transfer.h @@ -29,15 +29,14 @@ public: MCONTACT hContact;
unsigned int sequence;
TCPSocket socket;
- char **files;
- char *description;
- char *path;
+ wchar_t **files;
+ wchar_t *path, *fileName;
+ char *description;
unsigned char directory;
unsigned int sending;
unsigned int speed;
unsigned int count;
- unsigned int current;
- char *fileName;
+ unsigned int current;
unsigned int fileDate;
unsigned int fileSize;
unsigned int fileProgress;
@@ -59,7 +58,7 @@ public: void sendPacket0x06();
void ack(unsigned int result);
void process();
- void resume(int action, const char *newName);
+ void resume(int action, const wchar_t *newName);
void openFile();
void closeFile();
void setFilePosition();
diff --git a/protocols/ICQCorp/src/version.h b/protocols/ICQCorp/src/version.h index cd7dbb2ab2..dea0e7a201 100644 --- a/protocols/ICQCorp/src/version.h +++ b/protocols/ICQCorp/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
-#define __MINOR_VERSION 0
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 0
+#define __MINOR_VERSION 1
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>
|