summaryrefslogtreecommitdiff
path: root/protocols/IcqOscarJ/src/askauthentication.cpp
blob: 3a8efc29475ed75e2d5eb50679c0666b346ba295 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ---------------------------------------------------------------------------80
//                ICQ plugin for Miranda Instant Messenger
//                ________________________________________
//
// Copyright © 2000-2001 Richard Hughes, Roland Rabien, Tristan Van de Vreede
// Copyright © 2001-2002 Jon Keating, Richard Hughes
// Copyright © 2002-2004 Martin Öberg, Sam Kothari, Robert Rainwater
// Copyright © 2004-2008 Joe Kucera
// Copyright © 2012-2017 Miranda NG Team
//
// 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"

class AskAuthProcDlg : public CProtoDlgBase<CIcqProto>
{
	MCONTACT m_hContact;

	CCtrlEdit m_auth;
	CCtrlButton m_btnOk;

public:
	AskAuthProcDlg(CIcqProto *_ppro, MCONTACT _hContact) :
		CProtoDlgBase<CIcqProto>(_ppro, IDD_ASKAUTH, false),
		m_hContact(_hContact),
		m_auth(this, IDC_EDITAUTH),
		m_btnOk(this, IDOK)
	{
		m_autoClose = CLOSE_ON_CANCEL; // let onOk() to close window manually
		m_btnOk.OnClick = Callback(this, &AskAuthProcDlg::onOk);
	}

	virtual void OnInitDialog()
	{
		if (!m_hContact || !m_proto->icqOnline())
			EndDialog(m_hwnd, 0);

		m_auth.SendMsg(EM_LIMITTEXT, 255, 0);
		m_auth.SetText(TranslateT("Please authorize me to add you to my contact list."));
	}

	void onOk(CCtrlButton*)
	{
		if (!m_proto->icqOnline())
			return;

		DWORD dwUin;
		uid_str szUid;
		if (m_proto->getContactUid(m_hContact, &dwUin, &szUid))
			return; // Invalid contact

		char *szReason = GetWindowTextUtf(m_auth.GetHwnd());
		m_proto->icq_sendAuthReqServ(dwUin, szUid, szReason);
		SAFE_FREE((void**)&szReason);

		// auth bug fix (thx Bio)
		if (m_proto->m_bSsiEnabled && dwUin)
			m_proto->resetServContactAuthState(m_hContact);

		EndDialog(m_hwnd, 0);
	}
};

INT_PTR CIcqProto::RequestAuthorization(WPARAM wParam, LPARAM)
{
	AskAuthProcDlg(this, wParam).DoModal();
	return 0;
}