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
|
#include "commonheaders.h"
static void sttWaitForExchange(LPVOID param)
{
MCONTACT hContact = (UINT_PTR)param;
pUinKey ptr = getUinKey(hContact);
if (!ptr)
return;
for (int i = 0; i < db_get_w(0, MODULENAME, "ket", 10) * 10; i++) {
Sleep(100);
if (ptr->waitForExchange != 1)
break;
}
Sent_NetLog("sttWaitForExchange: %d", ptr->waitForExchange);
// if keyexchange failed or timeout
if (ptr->waitForExchange == 1 || ptr->waitForExchange == 3) { // ïðîòóõëî - îòïðàâëÿåì íåçàøèôðîâàííî, åñëè íàäî
if (ptr->msgQueue && msgbox1(nullptr, sim104, MODULENAME, MB_YESNO | MB_ICONQUESTION) == IDYES) {
mir_cslock lck(localQueueMutex);
ptr->sendQueue = true;
pWM ptrMessage = ptr->msgQueue;
while (ptrMessage) {
Sent_NetLog("Sent (unencrypted) message from queue: %s", ptrMessage->Message);
// send unencrypted messages
ProtoChainSend(ptr->hContact, PSS_MESSAGE, (WPARAM)ptrMessage->wParam | PREF_METANODB, (LPARAM)ptrMessage->Message);
mir_free(ptrMessage->Message);
pWM tmp = ptrMessage;
ptrMessage = ptrMessage->nextMessage;
mir_free(tmp);
}
ptr->msgQueue = nullptr;
ptr->sendQueue = false;
}
ptr->waitForExchange = 0;
ShowStatusIconNotify(ptr->hContact);
}
else if (ptr->waitForExchange == 2) { // äîñëàòü î÷åðåäü ÷åðåç óñòàíîâëåííîå ñîåäèíåíèå
mir_cslock lck(localQueueMutex);
// we need to resend last send back message with new crypto Key
pWM ptrMessage = ptr->msgQueue;
while (ptrMessage) {
Sent_NetLog("Sent (encrypted) message from queue: %s", ptrMessage->Message);
// send unencrypted messages
ProtoChainSend(ptr->hContact, PSS_MESSAGE, (WPARAM)ptrMessage->wParam | PREF_METANODB, (LPARAM)ptrMessage->Message);
mir_free(ptrMessage->Message);
pWM tmp = ptrMessage;
ptrMessage = ptrMessage->nextMessage;
mir_free(tmp);
}
ptr->msgQueue = nullptr;
ptr->waitForExchange = 0;
}
else if (ptr->waitForExchange == 0) { // î÷èñòèòü î÷åðåäü
mir_cslock lck(localQueueMutex);
// we need to resend last send back message with new crypto Key
pWM ptrMessage = ptr->msgQueue;
while (ptrMessage) {
mir_free(ptrMessage->Message);
pWM tmp = ptrMessage;
ptrMessage = ptrMessage->nextMessage;
mir_free(tmp);
}
ptr->msgQueue = nullptr;
}
}
// set wait flag and run thread
void waitForExchange(pUinKey ptr, int flag)
{
switch (flag) {
case 0: // reset
case 2: // send secure
case 3: // send unsecure
if (ptr->waitForExchange)
ptr->waitForExchange = flag;
break;
case 1: // launch
if (ptr->waitForExchange)
break;
ptr->waitForExchange = 1;
mir_forkthread(sttWaitForExchange, (void*)ptr->hContact);
break;
}
}
|