summaryrefslogtreecommitdiff
path: root/src/mir_app/src/auth.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2017-12-05 18:28:41 +0300
committerGeorge Hazan <ghazan@miranda.im>2017-12-05 18:28:47 +0300
commit1b803834c3f1736e658477a042b51d1926e11e7b (patch)
tree358d9a49dc0d9754351d45ac55a2c8d79ef6bf69 /src/mir_app/src/auth.cpp
parenta2734d21545621f9cf80a9bc4dc19b69c27d0a0f (diff)
StdAuth plugin merged back with mir_app.dll
Diffstat (limited to 'src/mir_app/src/auth.cpp')
-rw-r--r--src/mir_app/src/auth.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/mir_app/src/auth.cpp b/src/mir_app/src/auth.cpp
new file mode 100644
index 0000000000..119b86e061
--- /dev/null
+++ b/src/mir_app/src/auth.cpp
@@ -0,0 +1,104 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright (c) 2012-17 Miranda NG project (https://miranda-ng.org),
+Copyright (c) 2000-12 Miranda IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+#define MS_AUTH_SHOWREQUEST "Auth/ShowRequest"
+#define MS_AUTH_SHOWADDED "Auth/ShowAdded"
+
+INT_PTR CALLBACK DlgProcAuthReq(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+INT_PTR CALLBACK DlgProcAdded(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+
+INT_PTR ShowReqWindow(WPARAM, LPARAM lParam)
+{
+ CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_AUTHREQ), NULL, DlgProcAuthReq, (LPARAM)((CLISTEVENT *)lParam)->hDbEvent);
+ return 0;
+}
+
+INT_PTR ShowAddedWindow(WPARAM, LPARAM lParam)
+{
+ CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_ADDED), NULL, DlgProcAdded, (LPARAM)((CLISTEVENT *)lParam)->hDbEvent);
+ return 0;
+}
+
+static int AuthEventAdded(WPARAM, LPARAM lParam)
+{
+ wchar_t szTooltip[256];
+ MEVENT hDbEvent = (MEVENT)lParam;
+
+ DBEVENTINFO dbei = {};
+ db_event_get(lParam, &dbei);
+ if (dbei.flags & (DBEF_SENT | DBEF_READ) || (dbei.eventType != EVENTTYPE_AUTHREQUEST && dbei.eventType != EVENTTYPE_ADDED))
+ return 0;
+
+ dbei.cbBlob = db_event_getBlobSize(hDbEvent);
+ dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
+ db_event_get(hDbEvent, &dbei);
+
+ MCONTACT hContact = DbGetAuthEventContact(&dbei);
+
+ CLISTEVENT cle = {};
+ cle.hContact = hContact;
+ cle.szTooltip.w = szTooltip;
+ cle.flags = CLEF_UNICODE;
+ cle.lParam = lParam;
+ cle.hDbEvent = hDbEvent;
+
+ ptrW szUid(Contact_GetInfo(CNF_UNIQUEID, hContact));
+
+ if (dbei.eventType == EVENTTYPE_AUTHREQUEST) {
+ Skin_PlaySound("AuthRequest");
+ if (szUid)
+ mir_snwprintf(szTooltip, TranslateT("%s requests authorization"), szUid);
+ else
+ mir_snwprintf(szTooltip, TranslateT("%u requests authorization"), *(PDWORD)dbei.pBlob);
+
+ cle.hIcon = Skin_LoadIcon(SKINICON_AUTH_REQUEST);
+ cle.pszService = MS_AUTH_SHOWREQUEST;
+ cli.pfnAddEvent(&cle);
+ }
+ else if (dbei.eventType == EVENTTYPE_ADDED) {
+ Skin_PlaySound("AddedEvent");
+ if (szUid)
+ mir_snwprintf(szTooltip, TranslateT("%s added you to their contact list"), szUid);
+ else
+ mir_snwprintf(szTooltip, TranslateT("%u added you to their contact list"), *(PDWORD)dbei.pBlob);
+
+ cle.hIcon = Skin_LoadIcon(SKINICON_AUTH_ADD);
+ cle.pszService = MS_AUTH_SHOWADDED;
+ cli.pfnAddEvent(&cle);
+ }
+ return 0;
+}
+
+int LoadSendRecvAuthModule(void)
+{
+ CreateServiceFunction(MS_AUTH_SHOWREQUEST, ShowReqWindow);
+ CreateServiceFunction(MS_AUTH_SHOWADDED, ShowAddedWindow);
+ HookEvent(ME_DB_EVENT_ADDED, AuthEventAdded);
+
+ Skin_AddSound("AuthRequest", LPGENW("Alerts"), LPGENW("Authorization request"));
+ Skin_AddSound("AddedEvent", LPGENW("Alerts"), LPGENW("Added event"));
+ return 0;
+}