From 6163df27ad6fd2a5da5d9bbb48bb457d8a07a2b6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 16 Jan 2017 18:20:37 +0300 Subject: DB_AUTH_BLOB: handy piece of code moved into the core --- plugins/NewEventNotify/src/popup.cpp | 40 ++++++++------------------ plugins/Spamotron/src/spamotron.cpp | 54 +++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 54 deletions(-) (limited to 'plugins') diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp index 466cbf0661..4edd1c8bad 100644 --- a/plugins/NewEventNotify/src/popup.cpp +++ b/plugins/NewEventNotify/src/popup.cpp @@ -282,36 +282,20 @@ static wchar_t* GetEventPreview(DBEVENTINFO *dbei) case EVENTTYPE_AUTHREQUEST: if (dbei->pBlob) { - char szUin[16]; - wchar_t szBuf[2048]; - wchar_t* szNick = NULL; - char *pszNick = (char *)dbei->pBlob + 8; - char *pszFirst = pszNick + mir_strlen(pszNick) + 1; - char *pszLast = pszFirst + mir_strlen(pszFirst) + 1; - char *pszEmail = pszLast + mir_strlen(pszLast) + 1; - - mir_snprintf(szUin, "%d", *((DWORD*)dbei->pBlob)); - if (mir_strlen(pszNick) > 0) { - if (dbei->flags & DBEF_UTF) - szNick = mir_utf8decodeW(pszNick); - else - szNick = mir_a2u(pszNick); + DB_AUTH_BLOB blob(dbei->pBlob); + + wchar_t *szNick = NULL; + if (blob.get_nick()) + szNick = dbei->getString(blob.get_nick()); + else if (blob.get_email()) + szNick = dbei->getString(blob.get_email()); + else if (blob.get_uin()) { + char szUin[16]; + szNick = mir_a2u(itoa(blob.get_uin(), szUin, 10)); } - else if (mir_strlen(pszEmail) > 0) { - if (dbei->flags & DBEF_UTF) - szNick = mir_utf8decodeW(pszEmail); - else - szNick = mir_a2u(pszEmail); - } - else if (*((DWORD*)dbei->pBlob) > 0) - szNick = mir_a2u(szUin); - if (szNick) { - mir_wstrcpy(szBuf, szNick); - mir_wstrcat(szBuf, TranslateT(" requested authorization")); - mir_free(szNick); - comment1 = mir_wstrdup(szBuf); - } + if (szNick) + comment1 = CMStringW(FORMAT, L"%s%s", szNick, TranslateT(" requested authorization")).Detach(); } commentFix = POPUP_COMMENT_AUTH; break; diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp index 2ae09ab0b1..fe48153a0e 100644 --- a/plugins/Spamotron/src/spamotron.cpp +++ b/plugins/Spamotron/src/spamotron.cpp @@ -117,7 +117,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) msgblob = (char *)dbei->pBlob; } else if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { - msgblob = (char *)(dbei->pBlob + sizeof(DWORD) + sizeof(HANDLE)); + msgblob = (char *)(dbei->pBlob + sizeof(DWORD) + sizeof(DWORD)); for(a = 4; a > 0; a--) msgblob += mir_strlen(msgblob)+1; } @@ -336,16 +336,16 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) } // Accept if event is EVENTTYPE_AUTHREQUEST and ReplyOnAuth is NOT set - if (dbei->eventType == EVENTTYPE_AUTHREQUEST && !_getOptB("ReplyOnAuth", defaultReplyOnAuth)) - return 0; + if (dbei->eventType == EVENTTYPE_AUTHREQUEST && !_getOptB("ReplyOnAuth", defaultReplyOnAuth)) + return 0; // Accept if event is EVENTTYPE_MESSAGE and ReplyOnMsg is NOT set - if (dbei->eventType == EVENTTYPE_MESSAGE && !_getOptB("ReplyOnMsg", defaultReplyOnMsg)) - return 0; - + if (dbei->eventType == EVENTTYPE_MESSAGE && !_getOptB("ReplyOnMsg", defaultReplyOnMsg)) + return 0; + /*** Send Challenge ***/ - challengeW = (wchar_t *)malloc(maxmsglen*sizeof(wchar_t)); - tmpW = (wchar_t *)malloc(maxmsglen*sizeof(wchar_t)); + challengeW = (wchar_t *)malloc(maxmsglen * sizeof(wchar_t)); + tmpW = (wchar_t *)malloc(maxmsglen * sizeof(wchar_t)); switch (_getOptB("Mode", defaultMode)) { case SPAMOTRON_MODE_PLAIN: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) @@ -356,14 +356,14 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW)); _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending plain challenge to %s."), message); break; - + case SPAMOTRON_MODE_ROTATE: if (dbei->eventType == EVENTTYPE_AUTHREQUEST) _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); else _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); _getOptS(buf, buflen, "Response", defaultResponse); - if (_getCOptD(hContact, "ResponseNum", 0) >= (unsigned int)(get_response_num(buf)-1)) + if (_getCOptD(hContact, "ResponseNum", 0) >= (unsigned int)(get_response_num(buf) - 1)) _setCOptD(hContact, "ResponseNum", -1); _setCOptD(hContact, "ResponseNum", _getCOptD(hContact, "ResponseNum", -1) + 1); @@ -415,17 +415,17 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) /*** Do any post-send procedures we need to do ***/ // Increment MsgSent if it was sent the same day. Otherwise set it to 1. - if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime",0))) - _setCOptD(hContact, "MsgSent", _getCOptD(hContact, "MsgSent", 0)+1); - else + if (isOneDay(dbei->timestamp, _getCOptD(hContact, "MsgSentTime", 0))) + _setCOptD(hContact, "MsgSent", _getCOptD(hContact, "MsgSent", 0) + 1); + else _setCOptD(hContact, "MsgSent", 1); _setCOptD(hContact, "MsgSentTime", dbei->timestamp); // Save Last Msg and update SameMsgCount if (message != NULL) { if (mir_wstrcmp(_getCOptS(buf, buflen, hContact, "LastInMsg", L""), message) == 0) - _setCOptD(hContact, "SameMsgCount", 1+_getCOptD(hContact, "SameMsgCount", 0)); - else + _setCOptD(hContact, "SameMsgCount", 1 + _getCOptD(hContact, "SameMsgCount", 0)); + else _setCOptD(hContact, "SameMsgCount", 1); _setCOptTS(hContact, "LastInMsg", message); } @@ -446,10 +446,11 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) _setCOptB(hContact, "AuthEventPending", TRUE); free(eventdata); } - } else { + } + else { if (_getOptB("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval)) { DBVARIANT _dbv; - DWORD dbei_size = 3*sizeof(DWORD) + sizeof(WORD) + dbei->cbBlob + (DWORD)mir_strlen(dbei->szModule)+1; + DWORD dbei_size = 3 * sizeof(DWORD) + sizeof(WORD) + dbei->cbBlob + (DWORD)mir_strlen(dbei->szModule) + 1; PBYTE eventdata = (PBYTE)malloc(dbei_size); PBYTE pos = eventdata; if (eventdata != NULL && dbei->cbBlob > 0) { @@ -461,16 +462,17 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) db_free(&_dbv); } memcpy(pos, &dbei->eventType, sizeof(WORD)); - memcpy(pos+sizeof(WORD), &dbei->flags, sizeof(DWORD)); - memcpy(pos+sizeof(WORD)+sizeof(DWORD), &dbei->timestamp, sizeof(DWORD)); - memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2, dbei->szModule, mir_strlen(dbei->szModule)+1); - memcpy(pos+sizeof(WORD)+sizeof(DWORD)*2+mir_strlen(dbei->szModule)+1, &dbei->cbBlob, sizeof(DWORD)); - memcpy(pos+sizeof(WORD)+sizeof(DWORD)*3+mir_strlen(dbei->szModule)+1, dbei->pBlob, dbei->cbBlob); + memcpy(pos + sizeof(WORD), &dbei->flags, sizeof(DWORD)); + memcpy(pos + sizeof(WORD) + sizeof(DWORD), &dbei->timestamp, sizeof(DWORD)); + memcpy(pos + sizeof(WORD) + sizeof(DWORD) * 2, dbei->szModule, mir_strlen(dbei->szModule) + 1); + memcpy(pos + sizeof(WORD) + sizeof(DWORD) * 2 + mir_strlen(dbei->szModule) + 1, &dbei->cbBlob, sizeof(DWORD)); + memcpy(pos + sizeof(WORD) + sizeof(DWORD) * 3 + mir_strlen(dbei->szModule) + 1, dbei->pBlob, dbei->cbBlob); db_set_blob(hContact, PLUGIN_NAME, "LastMsgEvents", eventdata, (pos - eventdata) + dbei_size); free(eventdata); } - - } else { + + } + else { dbei->flags |= DBEF_READ; db_event_add(hContact, dbei); } @@ -483,7 +485,7 @@ int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) void RemoveNotOnListSettings() { DBVARIANT dbv; - char protoName[256] = {0}; + char protoName[256] = { 0 }; MCONTACT hContact = db_find_first(); mir_strcpy(protoName, "proto_"); while (hContact != NULL) { @@ -537,4 +539,4 @@ extern "C" _declspec(dllexport) int Unload(void) UnhookEvent(hDBEventAdded); UnhookEvent(hDBEventFilterAdd); return 0; -} \ No newline at end of file +} -- cgit v1.2.3