From 6647f383bff7d38db530c623caae63d1f50cbc71 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 13 Apr 2015 11:24:22 +0000 Subject: Tox: - fixed incoming message encoding - added support "force ANSI" flag (please, don't use it) git-svn-id: http://svn.miranda-ng.org/main/trunk@12782 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/common.h | 6 ++-- protocols/Tox/src/tox_accounts.cpp | 2 +- protocols/Tox/src/tox_avatars.cpp | 14 ++------ protocols/Tox/src/tox_messages.cpp | 72 +++++++++++++++++++++----------------- 4 files changed, 45 insertions(+), 49 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index d5450728cc..ae093169bf 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -61,8 +61,8 @@ extern HINSTANCE g_hInstance; #define TOX_ERROR -1 -#define TOX_MAX_CONNECT_RETRIES 200 -#define TOX_MAX_DISCONNECT_RETRIES 200 +#define TOX_MAX_CONNECT_RETRIES 300 +#define TOX_MAX_DISCONNECT_RETRIES 300 #define TOX_INI_PATH "%miranda_path%\\Plugins\\tox.ini" @@ -81,7 +81,7 @@ extern HINSTANCE g_hInstance; #define TOX_DB_EVENT_TYPE_ACTION 10001 -#define TOX_FILE_BLOCK_SIZE 1024 * 1024 +#define TOX_MAX_AVATAR_SIZE 1024 * 1024 extern HMODULE g_hToxLibrary; diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 228599866d..21f884272c 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -35,7 +35,7 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit); HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage); - //InitGroupChatModule(); + //InitGroupChatModule return 0; } diff --git a/protocols/Tox/src/tox_avatars.cpp b/protocols/Tox/src/tox_avatars.cpp index fb37813e26..1d9859f146 100644 --- a/protocols/Tox/src/tox_avatars.cpp +++ b/protocols/Tox/src/tox_avatars.cpp @@ -7,23 +7,15 @@ std::tstring CToxProto::GetAvatarFilePath(MCONTACT hContact) DWORD dwAttributes = GetFileAttributes(path); if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) - { CallService(MS_UTILS_CREATEDIRTREET, 0, (LPARAM)path); - } ptrT id(getTStringA(hContact, TOX_SETTINGS_ID)); if (hContact != NULL) - { mir_sntprintf(path, MAX_PATH, _T("%s\\%s.png"), path, id); - } else if (id != NULL) - { mir_sntprintf(path, MAX_PATH, _T("%s\\%s avatar.png"), path, id); - } else - { return _T(""); - } return path; } @@ -40,7 +32,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) fseek(hFile, 0, SEEK_END); size_t length = ftell(hFile); rewind(hFile); - if (length > 1024 * 1024) + if (length > TOX_MAX_AVATAR_SIZE) { fclose(hFile); debugLogA(__FUNCTION__": new avatar size is excessive"); @@ -102,9 +94,7 @@ void CToxProto::SetToxAvatar(std::tstring path, bool checkHash) mir_free(data); if (checkHash) - { db_set_blob(NULL, m_szModuleName, TOX_SETTINGS_AVATAR_HASH, (void*)hash, TOX_HASH_LENGTH); - } } INT_PTR CToxProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) @@ -129,7 +119,7 @@ INT_PTR CToxProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) return lParam == PA_FORMAT_PNG; case AF_MAXFILESIZE: - return 1024 * 1024; + return TOX_MAX_AVATAR_SIZE; } return 0; diff --git a/protocols/Tox/src/tox_messages.cpp b/protocols/Tox/src/tox_messages.cpp index a73aec2f7c..ddcf5fa2f8 100644 --- a/protocols/Tox/src/tox_messages.cpp +++ b/protocols/Tox/src/tox_messages.cpp @@ -8,21 +8,23 @@ void CToxProto::OnFriendMessage(Tox*, uint32_t friendNumber, TOX_MESSAGE_TYPE ty CToxProto *proto = (CToxProto*)arg; MCONTACT hContact = proto->GetContact(friendNumber); - if (hContact) - { - std::string test((char*)message); - ptrA szMessage((char*)mir_alloc(length + 1)); - mir_strncpy(szMessage, (const char*)message, length); - - PROTORECVEVENT recv = { 0 }; - recv.flags = PREF_UTF; - recv.timestamp = time(NULL); - recv.szMessage = szMessage; - recv.lParam = type == TOX_MESSAGE_TYPE_NORMAL - ? EVENTTYPE_MESSAGE : TOX_DB_EVENT_TYPE_ACTION; - - ProtoChainRecvMsg(hContact, &recv); - } + if (hContact == NULL) + return; + + char *rawMessage = (char*)mir_alloc(length + 1); + mir_strncpy(rawMessage, (const char*)message, length); + rawMessage[length] = 0; + + PROTORECVEVENT recv = { 0 }; + recv.flags = PREF_UTF; + recv.timestamp = time(NULL); + recv.szMessage = rawMessage; + recv.lParam = type == TOX_MESSAGE_TYPE_NORMAL + ? EVENTTYPE_MESSAGE : TOX_DB_EVENT_TYPE_ACTION; + + ProtoChainRecvMsg(hContact, &recv); + + CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF); } // writing message/even into db @@ -37,7 +39,7 @@ int CToxProto::OnReceiveMessage(MCONTACT hContact, PROTORECVEVENT *pre) dbei.timestamp = pre->timestamp; dbei.flags = DBEF_UTF; dbei.eventType = pre->lParam; - dbei.cbBlob = (DWORD)strlen(pre->szMessage) + 1; + dbei.cbBlob = (DWORD)mir_strlen(pre->szMessage) + 1; dbei.pBlob = (PBYTE)pre->szMessage; return (INT_PTR)db_event_add(hContact, &dbei); @@ -55,10 +57,10 @@ int CToxProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessage ptrA message; if (flags & PREF_UNICODE) message = mir_utf8encodeW((wchar_t*)&szMessage[mir_strlen(szMessage) + 1]); - else if (flags & PREF_UTF) + else //if (flags & PREF_UTF) message = mir_strdup(szMessage); - else - message = mir_utf8encode(szMessage); + //else + //message = mir_utf8encode(szMessage); size_t msgLen = mir_strlen(message); uint8_t *msg = (uint8_t*)(char*)message; @@ -73,7 +75,9 @@ int CToxProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessage if (error != TOX_ERR_FRIEND_SEND_MESSAGE_OK) { debugLogA(__FUNCTION__": failed to send message (%d)", error); + return 0; } + return messageId; } @@ -83,9 +87,11 @@ void CToxProto::OnReadReceipt(Tox*, uint32_t friendNumber, uint32_t messageId, v CToxProto *proto = (CToxProto*)arg; MCONTACT hContact = proto->GetContact(friendNumber); - if (hContact) - proto->ProtoBroadcastAck( - hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)messageId, 0); + if (hContact == NULL) + return; + + proto->ProtoBroadcastAck( + hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)messageId, 0); } // preparing message/action to writing into db @@ -96,17 +102,17 @@ int CToxProto::OnPreCreateMessage(WPARAM, LPARAM lParam) return 0; char *message = (char*)evt->dbei->pBlob; - if (strncmp(message, "/me ", 4) == 0) - { - evt->dbei->cbBlob = evt->dbei->cbBlob - 4; - PBYTE action = (PBYTE)mir_alloc(evt->dbei->cbBlob); - memcpy(action, &evt->dbei->pBlob[4], evt->dbei->cbBlob); - mir_free(evt->dbei->pBlob); - evt->dbei->pBlob = action; - evt->dbei->eventType = TOX_DB_EVENT_TYPE_ACTION; - } + if (strncmp(message, "/me ", 4) != 0) + return 0; + + evt->dbei->cbBlob = evt->dbei->cbBlob - 4; + PBYTE action = (PBYTE)mir_alloc(evt->dbei->cbBlob); + memcpy(action, &evt->dbei->pBlob[4], evt->dbei->cbBlob); + mir_free(evt->dbei->pBlob); + evt->dbei->pBlob = action; + evt->dbei->eventType = TOX_DB_EVENT_TYPE_ACTION; - return 1; + return 0; } /* TYPING */ @@ -116,7 +122,7 @@ int CToxProto::OnUserIsTyping(MCONTACT hContact, int type) int32_t friendNumber = GetToxFriendNumber(hContact); if (friendNumber == UINT32_MAX) return 0; - + TOX_ERR_SET_TYPING error; if (!tox_self_set_typing(tox, friendNumber, type == PROTOTYPE_SELFTYPING_ON, &error)) debugLogA(__FUNCTION__": failed to send typing (%d)", error); -- cgit v1.2.3