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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
#include "stdafx.h"
#include "MraMPop.h"
// MPOP_SESSION
struct MRA_MPOP_SESSION_QUEUE : public FIFO_MT
{
bool bKeyValid; /* lpszMPOPKey contain valid key. */
LPSTR lpszMPOPKey; /* Key for web auth on mail.ru services. */
size_t dwMPOPKeySize; /* Key size. */
};
struct MRA_MPOP_SESSION_QUEUE_ITEM : public FIFO_MT_ITEM
{
LPSTR lpszUrl; /* Url to open. */
size_t dwUrlSize;
};
void MraMPopSessionQueueClear(HANDLE hMPopSessionQueue);
DWORD MraMPopSessionQueueInitialize(HANDLE *phMPopSessionQueue)
{
if (!phMPopSessionQueue)
return ERROR_INVALID_HANDLE;
if ((*phMPopSessionQueue))
return ERROR_ALREADY_INITIALIZED;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = new MRA_MPOP_SESSION_QUEUE();
if (!pmpsqMPopSessionQueue)
return GetLastError();
*phMPopSessionQueue = (HANDLE)pmpsqMPopSessionQueue;
return NO_ERROR;
}
void MraMPopSessionQueueClear(HANDLE hMPopSessionQueue)
{
if (!hMPopSessionQueue)
return;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
pmpsqMPopSessionQueue->bKeyValid = false;
mir_free(pmpsqMPopSessionQueue->lpszMPOPKey);
pmpsqMPopSessionQueue->lpszMPOPKey = NULL;
pmpsqMPopSessionQueue->dwMPOPKeySize = 0;
MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi;
while ( !FifoMTItemPop(pmpsqMPopSessionQueue, NULL, (LPVOID*)&pmpsqi))
mir_free(pmpsqi);
}
void MraMPopSessionQueueDestroy(HANDLE hMPopSessionQueue)
{
if (!hMPopSessionQueue)
return;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
MraMPopSessionQueueClear(hMPopSessionQueue);
delete pmpsqMPopSessionQueue;
}
DWORD CMraProto::MraMPopSessionQueueAddUrl(HANDLE hMPopSessionQueue, const CMStringA &lpszUrl)
{
if (!hMPopSessionQueue)
return ERROR_INVALID_HANDLE;
if (lpszUrl.IsEmpty())
return ERROR_INVALID_DATA;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi;
if (!getByte("AutoAuthOnWebServices", MRA_DEFAULT_AUTO_AUTH_ON_WEB_SVCS) || !m_bLoggedIn) { /* Open without web auth. / Not loggedIn. */
CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)lpszUrl.c_str());
return NO_ERROR;
}
/* Add to queue. */
pmpsqi = (MRA_MPOP_SESSION_QUEUE_ITEM*)mir_calloc((sizeof(MRA_MPOP_SESSION_QUEUE_ITEM) + lpszUrl.GetLength() + sizeof(size_t)));
if (!pmpsqi)
return GetLastError();
pmpsqi->dwUrlSize = lpszUrl.GetLength();
pmpsqi->lpszUrl = (LPSTR)(pmpsqi + 1);
memcpy(pmpsqi->lpszUrl, lpszUrl, lpszUrl.GetLength());
FifoMTItemPush(pmpsqMPopSessionQueue, pmpsqi, (LPVOID)pmpsqi);
MraMPopSessionQueueStart(hMPopSessionQueue);
return NO_ERROR;
}
DWORD CMraProto::MraMPopSessionQueueAddUrlAndEMail(HANDLE hMPopSessionQueue, const CMStringA &lpszUrl, CMStringA &szEmail)
{
if (!hMPopSessionQueue)
return ERROR_INVALID_HANDLE;
if (lpszUrl.IsEmpty() || szEmail.IsEmpty())
return ERROR_INVALID_DATA;
szEmail.MakeLower();
int iStart = 0;
CMStringA szUser = szEmail.Tokenize("@", iStart);
CMStringA szDomain = szEmail.Tokenize("@", iStart);
CMStringA szUrl;
szUrl.Format("%s/%s/%s", lpszUrl.c_str(), szDomain.c_str(), szUser.c_str());
return MraMPopSessionQueueAddUrl(hMPopSessionQueue, szUrl);
}
void CMraProto::MraMPopSessionQueueStart(HANDLE hMPopSessionQueue)
{
if (!hMPopSessionQueue)
return;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi;
if (!getByte("AutoAuthOnWebServices", MRA_DEFAULT_AUTO_AUTH_ON_WEB_SVCS) || !m_bLoggedIn) { /* Open without web auth. / Not loggedIn. */
MraMPopSessionQueueFlush(hMPopSessionQueue);
return;
}
while ( FifoMTGetCount(pmpsqMPopSessionQueue)) {
if (!pmpsqMPopSessionQueue->bKeyValid) { /* We have no key, try to get one. */
if (0 == MraSendCMD(MRIM_CS_GET_MPOP_SESSION, NULL, 0)) /* Fail to send. */
MraMPopSessionQueueFlush(hMPopSessionQueue);
return;
}
if ( FifoMTItemPop(pmpsqMPopSessionQueue, NULL, (LPVOID*)&pmpsqi) == NO_ERROR) {
CMStringA szUrl, szEmail;
if (mraGetStringA(NULL, "e-mail", szEmail)) {
pmpsqMPopSessionQueue->bKeyValid = false;
szEmail.MakeLower();
szUrl.Format(MRA_MPOP_AUTH_URL, szEmail, pmpsqMPopSessionQueue->lpszMPOPKey, pmpsqi->lpszUrl);
CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)szUrl.c_str());
debugLogA("Opening URL: %s\n", szUrl);
}
mir_free(pmpsqi);
}
}
}
void CMraProto::MraMPopSessionQueueFlush(HANDLE hMPopSessionQueue)
{
if (!hMPopSessionQueue)
return;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
MRA_MPOP_SESSION_QUEUE_ITEM *pmpsqi;
while (FifoMTItemPop(pmpsqMPopSessionQueue, NULL, (LPVOID*)&pmpsqi) == NO_ERROR) {
CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)pmpsqi->lpszUrl);
mir_free(pmpsqi);
}
}
DWORD MraMPopSessionQueueSetNewMPopKey(HANDLE hMPopSessionQueue, const CMStringA &szKey)
{
if (!hMPopSessionQueue)
return ERROR_INVALID_HANDLE;
MRA_MPOP_SESSION_QUEUE *pmpsqMPopSessionQueue = (MRA_MPOP_SESSION_QUEUE*)hMPopSessionQueue;
if (pmpsqMPopSessionQueue->dwMPOPKeySize < (size_t)szKey.GetLength() || szKey.IsEmpty()) {
mir_free(pmpsqMPopSessionQueue->lpszMPOPKey);
pmpsqMPopSessionQueue->lpszMPOPKey = (LPSTR)mir_calloc(szKey.GetLength() + sizeof(size_t));
}
if (pmpsqMPopSessionQueue->lpszMPOPKey) {
pmpsqMPopSessionQueue->bKeyValid = true;
pmpsqMPopSessionQueue->dwMPOPKeySize = szKey.GetLength();
memcpy(pmpsqMPopSessionQueue->lpszMPOPKey, szKey, szKey.GetLength());
*(pmpsqMPopSessionQueue->lpszMPOPKey + szKey.GetLength()) = 0;
return NO_ERROR;
}
pmpsqMPopSessionQueue->bKeyValid = false;
pmpsqMPopSessionQueue->lpszMPOPKey = NULL;
pmpsqMPopSessionQueue->dwMPOPKeySize = 0;
return GetLastError();
}
|