From 48266e479d1fcf5153b29c612866845990fccad8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 21 May 2015 16:11:58 +0000 Subject: war against atavisms continues - everything that goes to PSS_MESSAGE should be sent as utf8 string; - thus PREF_UNICODE & PREF_UTF support discontinued, these constants are removed; - support for PREF_UNICODE & PREF_UTF in protocols also removed; - PREF_UNICODE used in file transfers (PROTOFILERECVT) replaced with PRFF_UNICODE / PRFF_TCHAR git-svn-id: http://svn.miranda-ng.org/main/trunk@13734 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MirFox/src/MirandaUtils.cpp | 71 ++++++++++++------------------------- 1 file changed, 22 insertions(+), 49 deletions(-) (limited to 'plugins/MirFox/src/MirandaUtils.cpp') diff --git a/plugins/MirFox/src/MirandaUtils.cpp b/plugins/MirFox/src/MirandaUtils.cpp index 79a897b098..737add6ca9 100644 --- a/plugins/MirFox/src/MirandaUtils.cpp +++ b/plugins/MirFox/src/MirandaUtils.cpp @@ -149,25 +149,11 @@ void MirandaUtils::sendMessage(ActionThreadArgStruct* args, MFENUM_SEND_MESSAGE_ return; } - int mirandaSendModeFlag = getMirandaSendModeFlag(targetHandleSzProto); - - char* msgBuffer = NULL; - std::size_t bufSize = 0; - - if (mirandaSendModeFlag == PREF_UTF){ - msgBuffer = mir_utf8encodeW(args->userActionSelection); - bufSize = strlen(msgBuffer) + 1; - } else if (mirandaSendModeFlag == PREF_UNICODE){ - msgBuffer = mir_t2a(args->userActionSelection); - bufSize = strlen(msgBuffer) + 1; - size_t bufSizeT = (wcslen(args->userActionSelection) + 1) * sizeof(wchar_t); - msgBuffer = (char*)mir_realloc(msgBuffer, bufSizeT + bufSize); - memcpy((wchar_t*)&msgBuffer[bufSize], args->userActionSelection, bufSizeT); - bufSize += bufSizeT; - } + ptrA msgBuffer(mir_utf8encodeW(args->userActionSelection)); + std::size_t bufSize = strlen(msgBuffer) + 1; - logger->log_p(L"SMTC: mirandaSendModeFlag = [%d] bufSize = [%d]", mirandaSendModeFlag, bufSize); - HANDLE hProcess = sendMessageMiranda((MCONTACT)args->targetHandle, mirandaSendModeFlag, msgBuffer); + logger->log_p(L"SMTC: bufSize = [%d]", bufSize); + HANDLE hProcess = sendMessageMiranda((MCONTACT)args->targetHandle, msgBuffer); logger->log_p(L"SMTC: hProcess = [" SCNuPTR L"]", hProcess); MIRFOXACKDATA* myMfAck = NULL; @@ -204,40 +190,38 @@ void MirandaUtils::sendMessage(ActionThreadArgStruct* args, MFENUM_SEND_MESSAGE_ if (mirandaContact){ contactNameW = mirandaContact->contactNameW.c_str(); MirandaAccount* mirandaAccount = mirandaContact->mirandaAccountPtr; - if (mirandaAccount){ + if (mirandaAccount) tszAccountName = mirandaAccount->tszAccountName; - } } if(myMfAck != NULL && myMfAck->result == ACKRESULT_SUCCESS){ - addMessageToDB((MCONTACT)args->targetHandle, mirandaSendModeFlag, msgBuffer, bufSize, targetHandleSzProto); + addMessageToDB((MCONTACT)args->targetHandle, msgBuffer, bufSize, targetHandleSzProto); if (mode == MFENUM_SMM_ONLY_SEND){ //show notyfication popup (only in SMM_ONLY_SEND mode) wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)]; - if (contactNameW != NULL && tszAccountName != NULL){ + if (contactNameW != NULL && tszAccountName != NULL) mir_sntprintf(buffer, 1024, TranslateT("Message sent to %s (%s)"), contactNameW, tszAccountName); - } else { + else mir_sntprintf(buffer, 1024, TranslateT("Message sent")); - } - if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) { + if(ServiceExists(MS_POPUP_ADDPOPUPCLASS)) ShowClassPopupT("MirFox_Notify", _T("MirFox"), buffer); - } else { + else PUShowMessageT(buffer, SM_NOTIFY); - } delete[] buffer; - } else if (mode == MFENUM_SMM_SEND_AND_SHOW_MW){ + } + else if (mode == MFENUM_SMM_SEND_AND_SHOW_MW){ //notify hook to open window if (args->mirfoxDataPtr != NULL && args->mirfoxDataPtr->hhook_EventOpenMW != NULL){ OnHookOpenMvStruct* onHookOpenMv = new(OnHookOpenMvStruct); onHookOpenMv->targetHandle = args->targetHandle; onHookOpenMv->msgBuffer = NULL; NotifyEventHooks(args->mirfoxDataPtr->hhook_EventOpenMW, (WPARAM)onHookOpenMv, 0); - } else { - logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL"); } + else logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL"); } - } else { + } + else { //error - show error popup wchar_t* buffer = new wchar_t[1024 * sizeof(wchar_t)]; if (myMfAck != NULL){ @@ -281,9 +265,8 @@ void MirandaUtils::sendMessage(ActionThreadArgStruct* args, MFENUM_SEND_MESSAGE_ EnterCriticalSection(&ackMapCs); ackMap.erase(hProcess); LeaveCriticalSection(&ackMapCs); - - mir_free(msgBuffer); - } else if (mode == MFENUM_SMM_ONLY_SHOW_MW){ + } + else if (mode == MFENUM_SMM_ONLY_SHOW_MW) { //notify hook to open window if (args->mirfoxDataPtr != NULL && args->mirfoxDataPtr->hhook_EventOpenMW != NULL){ @@ -295,32 +278,22 @@ void MirandaUtils::sendMessage(ActionThreadArgStruct* args, MFENUM_SEND_MESSAGE_ msgBuffer->append(L"\r\n"); onHookOpenMv->msgBuffer = msgBuffer; NotifyEventHooks(args->mirfoxDataPtr->hhook_EventOpenMW, (WPARAM)onHookOpenMv, 0); - } else { - logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL"); } + else logger->log(L"SMTC: ERROR1 args->mirfoxDataPtr == NULL || args->mirfoxDataPtr->hhook_EventOpenMW == NULL"); } } -int MirandaUtils::getMirandaSendModeFlag(char* targetHandleSzProto) -{ - if (CallProtoService(targetHandleSzProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_IMSENDUTF){ - return PREF_UTF; - } else { - return PREF_UNICODE; - } -} - -HANDLE MirandaUtils::sendMessageMiranda(MCONTACT hContact, int mirandaSendModeFlag, char* msgBuffer) +HANDLE MirandaUtils::sendMessageMiranda(MCONTACT hContact, char *msgBuffer) { - return (HANDLE)CallContactService(hContact, PSS_MESSAGE, (WPARAM)mirandaSendModeFlag, (LPARAM)msgBuffer); + return (HANDLE)CallContactService(hContact, PSS_MESSAGE, 0, (LPARAM)msgBuffer); } -void MirandaUtils::addMessageToDB(MCONTACT hContact, int mirandaSendModeFlag, char* msgBuffer, std::size_t bufSize, char* targetHandleSzProto) +void MirandaUtils::addMessageToDB(MCONTACT hContact, char* msgBuffer, std::size_t bufSize, char* targetHandleSzProto) { DBEVENTINFO dbei = {0}; dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = DBEF_SENT | ((mirandaSendModeFlag&PREF_UTF)==PREF_UTF ? DBEF_UTF : 0); + dbei.flags = DBEF_SENT | DBEF_UTF; dbei.szModule = targetHandleSzProto; dbei.timestamp = (DWORD)time(NULL); dbei.cbBlob = (DWORD)bufSize; -- cgit v1.2.3