diff options
author | George Hazan <george.hazan@gmail.com> | 2014-08-18 13:25:06 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-08-18 13:25:06 +0000 |
commit | abf173b5523410a3654c710f96bb0966982efd43 (patch) | |
tree | f965fdd960bac20e5d1fb1b02ec7505462bf5ecc /protocols | |
parent | cce5649ad860c44bbc31fa04f152c247b21c2653 (diff) |
patch for CRITICAL_SECTION extinction in MSN
git-svn-id: http://svn.miranda-ng.org/main/trunk@10227 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/MSN/src/msn_avatar.cpp | 2 | ||||
-rw-r--r-- | protocols/MSN/src/msn_lists.cpp | 281 | ||||
-rw-r--r-- | protocols/MSN/src/msn_msgqueue.cpp | 52 | ||||
-rw-r--r-- | protocols/MSN/src/msn_p2ps.cpp | 138 | ||||
-rw-r--r-- | protocols/MSN/src/msn_proto.cpp | 247 | ||||
-rw-r--r-- | protocols/MSN/src/msn_proto.h | 15 | ||||
-rw-r--r-- | protocols/MSN/src/msn_threads.cpp | 197 | ||||
-rw-r--r-- | protocols/MSN/src/version.h | 4 |
8 files changed, 336 insertions, 600 deletions
diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp index 6f6f86998a..ba3b0da6ce 100644 --- a/protocols/MSN/src/msn_avatar.cpp +++ b/protocols/MSN/src/msn_avatar.cpp @@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void CMsnProto::AvatarQueue_Init()
{
- ::InitializeCriticalSection(&csAvatarQueue);
hevAvatarQueue = ::CreateEvent(NULL, FALSE, FALSE, NULL);
ForkThread(&CMsnProto::MSN_AvatarsThread, 0);
@@ -30,7 +29,6 @@ void CMsnProto::AvatarQueue_Init() void CMsnProto::AvatarQueue_Uninit()
{
- ::DeleteCriticalSection(&csAvatarQueue);
::CloseHandle(hevAvatarQueue);
}
diff --git a/protocols/MSN/src/msn_lists.cpp b/protocols/MSN/src/msn_lists.cpp index 94c51a3a62..57a227a22f 100644 --- a/protocols/MSN/src/msn_lists.cpp +++ b/protocols/MSN/src/msn_lists.cpp @@ -24,90 +24,70 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "msn_proto.h"
#include "m_smileyadd.h"
-void CMsnProto::Lists_Init(void)
-{
- InitializeCriticalSection(&csLists);
-}
-
void CMsnProto::Lists_Uninit(void)
{
Lists_Wipe();
- DeleteCriticalSection(&csLists);
}
void CMsnProto::Lists_Wipe(void)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
contList.destroy();
- LeaveCriticalSection(&csLists);
}
bool CMsnProto::Lists_IsInList(int list, const char* email)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnContact* p = contList.find((MsnContact*)&email);
bool res = p != NULL;
if (res && list != -1)
res &= ((p->list & list) == list);
-
- LeaveCriticalSection(&csLists);
return res;
}
MsnContact* CMsnProto::Lists_Get(const char* email)
{
- EnterCriticalSection(&csLists);
-
- MsnContact* p = contList.find((MsnContact*)&email);
-
- LeaveCriticalSection(&csLists);
- return p;
+ mir_cslock lck(csLists);
+ return contList.find((MsnContact*)&email);
}
MsnContact* CMsnProto::Lists_Get(MCONTACT hContact)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
- MsnContact* p = NULL;
for (int i = 0; i < contList.getCount(); ++i)
- {
if (contList[i].hContact == hContact)
- {
- p = &contList[i];
- break;
- }
- }
+ return &contList[i];
- LeaveCriticalSection(&csLists);
- return p;
+ return NULL;
}
MsnPlace* CMsnProto::Lists_GetPlace(const char* wlid)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
char *szEmail, *szInst;
parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, &szInst);
- if (szInst == NULL) szInst = (char*)sttVoidUid;
+ if (szInst == NULL)
+ szInst = (char*)sttVoidUid;
MsnPlace* pl = NULL;
MsnContact* p = contList.find((MsnContact*)&szEmail);
- if (p) pl = p->places.find((MsnPlace*)&szInst);
+ if (p)
+ pl = p->places.find((MsnPlace*)&szInst);
- LeaveCriticalSection(&csLists);
return pl;
}
MsnPlace* CMsnProto::Lists_AddPlace(const char* email, const char* id, unsigned cap1, unsigned cap2)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnPlace* pl = NULL;
MsnContact* p = contList.find((MsnContact*)&email);
- if (p)
- {
+ if (p) {
pl = p->places.find((MsnPlace*)&id);
if (!pl) {
pl = new MsnPlace;
@@ -117,84 +97,70 @@ MsnPlace* CMsnProto::Lists_AddPlace(const char* email, const char* id, unsigned pl->cap2 = cap2;
pl->p2pMsgId = 0;
pl->p2pPktNum = 0;
-
p->places.insert(pl);
}
}
- LeaveCriticalSection(&csLists);
return pl;
}
MsnContact* CMsnProto::Lists_GetNext(int& i)
{
- MsnContact* p = NULL;
+ MsnContact* p = NULL;
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
while (p == NULL && ++i < contList.getCount())
- {
- if (contList[i].hContact) p = &contList[i];
- }
+ if (contList[i].hContact)
+ p = &contList[i];
- LeaveCriticalSection(&csLists);
return p;
}
int CMsnProto::Lists_GetMask(const char* email)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnContact* p = contList.find((MsnContact*)&email);
- int res = p ? p->list : 0;
-
- LeaveCriticalSection(&csLists);
- return res;
+ return p ? p->list : 0;
}
int CMsnProto::Lists_GetNetId(const char* email)
{
if (email[0] == 0) return NETID_UNKNOWN;
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnContact* p = contList.find((MsnContact*)&email);
- int res = p ? p->netId : NETID_UNKNOWN;
-
- LeaveCriticalSection(&csLists);
- return res;
+ return p ? p->netId : NETID_UNKNOWN;
}
unsigned CMsnProto::p2p_getMsgId(const char* wlid, int inc)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnPlace* p = Lists_GetPlace(wlid);
unsigned res = p && p->p2pMsgId ? p->p2pMsgId : MSN_GenRandom();
- if (p) p->p2pMsgId = res + inc;
+ if (p)
+ p->p2pMsgId = res + inc;
- LeaveCriticalSection(&csLists);
return res;
}
unsigned CMsnProto::p2p_getPktNum(const char* wlid)
{
- EnterCriticalSection(&csLists);
- MsnPlace* p = Lists_GetPlace(wlid);
-
- unsigned res = p ? p->p2pPktNum++ : 0;
+ mir_cslock lck(csLists);
- LeaveCriticalSection(&csLists);
- return res;
+ MsnPlace* p = Lists_GetPlace(wlid);
+ return p ? p->p2pPktNum++ : 0;
}
int CMsnProto::Lists_Add(int list, int netId, const char* email, MCONTACT hContact, const char* nick, const char* invite)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
MsnContact* p = contList.find((MsnContact*)&email);
- if (p == NULL)
- {
+ if (p == NULL) {
p = new MsnContact;
p->list = list;
p->netId = netId;
@@ -205,8 +171,7 @@ int CMsnProto::Lists_Add(int list, int netId, const char* email, MCONTACT hConta p->p2pMsgId = 0;
contList.insert(p);
}
- else
- {
+ else {
p->list |= list;
if (invite) replaceStr(p->invite, invite);
if (hContact) p->hContact = hContact;
@@ -214,25 +179,21 @@ int CMsnProto::Lists_Add(int list, int netId, const char* email, MCONTACT hConta if (p->netId == NETID_UNKNOWN && netId != NETID_UNKNOWN)
p->netId = netId;
}
- int result = p->list;
-
- LeaveCriticalSection(&csLists);
- return result;
+ return p->list;
}
void CMsnProto::Lists_Remove(int list, const char* email)
{
- EnterCriticalSection(&csLists);
+ mir_cslock lck(csLists);
+
int i = contList.getIndex((MsnContact*)&email);
- if (i != -1)
- {
- MsnContact& p = contList[i];
+ if (i != -1) {
+ MsnContact &p = contList[i];
p.list &= ~list;
if (list & LIST_PL) { mir_free(p.invite); p.invite = NULL; }
if (p.list == 0 && p.hContact == NULL)
contList.remove(i);
}
- LeaveCriticalSection(&csLists);
}
@@ -258,7 +219,7 @@ void CMsnProto::Lists_Populate(void) void CMsnProto::MSN_CleanupLists(void)
{
- for (int i=contList.getCount(); i--;) {
+ for (int i = contList.getCount(); i--;) {
MsnContact& p = contList[i];
if (p.list & LIST_FL)
MSN_SetContactDb(p.hContact, p.email);
@@ -316,72 +277,63 @@ void CMsnProto::MSN_CreateContList(void) char cxml[8192];
- size_t sz = mir_snprintf(cxml , sizeof(cxml), "<ml l=\"1\">");
-
- EnterCriticalSection(&csLists);
-
- for (int i=0; i < contList.getCount(); i++)
+ size_t sz = mir_snprintf(cxml, sizeof(cxml), "<ml l=\"1\">");
{
- if (used[i]) continue;
+ mir_cslock lck(csLists);
- const char* lastds = strchr(contList[i].email, '@');
- bool newdom = true;
+ for (int i = 0; i < contList.getCount(); i++) {
+ if (used[i]) continue;
- for (int j=0; j < contList.getCount(); j++)
- {
- if (used[j]) continue;
-
- const MsnContact& C = contList[j];
+ const char* lastds = strchr(contList[i].email, '@');
+ bool newdom = true;
- if (C.list == LIST_RL || C.list == LIST_PL || C.list == LIST_LL)
- {
- used[j] = true;
- continue;
- }
+ for (int j = 0; j < contList.getCount(); j++) {
+ if (used[j]) continue;
- const char* dom = strchr(C.email, '@');
- if (dom == NULL && lastds == NULL)
- {
- if (sz == 0) sz = mir_snprintf(cxml+sz, sizeof(cxml), "<ml l=\"1\">");
- if (newdom)
- {
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "<t>");
- newdom = false;
+ const MsnContact& C = contList[j];
+ if (C.list == LIST_RL || C.list == LIST_PL || C.list == LIST_LL) {
+ used[j] = true;
+ continue;
}
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "<c n=\"%s\" l=\"%d\"/>", C.email, C.list & ~(LIST_RL | LIST_LL));
- used[j] = true;
- }
- else if (dom != NULL && lastds != NULL && _stricmp(lastds, dom) == 0)
- {
- if (sz == 0) sz = mir_snprintf(cxml, sizeof(cxml), "<ml l=\"1\">");
- if (newdom)
- {
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "<d n=\"%s\">", lastds+1);
- newdom = false;
- }
+ const char *dom = strchr(C.email, '@');
+ if (dom == NULL && lastds == NULL) {
+ if (sz == 0) sz = mir_snprintf(cxml + sz, sizeof(cxml), "<ml l=\"1\">");
+ if (newdom) {
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "<t>");
+ newdom = false;
+ }
- *(char*)dom = 0;
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "<c n=\"%s\" l=\"%d\" t=\"%d\"/>", C.email, C.list & ~(LIST_RL | LIST_LL), C.netId);
- *(char*)dom = '@';
- used[j] = true;
- }
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "<c n=\"%s\" l=\"%d\"/>", C.email, C.list & ~(LIST_RL | LIST_LL));
+ used[j] = true;
+ }
+ else if (dom != NULL && lastds != NULL && _stricmp(lastds, dom) == 0) {
+ if (sz == 0) sz = mir_snprintf(cxml, sizeof(cxml), "<ml l=\"1\">");
+ if (newdom) {
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "<d n=\"%s\">", lastds + 1);
+ newdom = false;
+ }
+
+ *(char*)dom = 0;
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "<c n=\"%s\" l=\"%d\" t=\"%d\"/>", C.email, C.list & ~(LIST_RL | LIST_LL), C.netId);
+ *(char*)dom = '@';
+ used[j] = true;
+ }
- if (used[j] && sz > 7400)
- {
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "</%c></ml>", lastds ? 'd' : 't');
- msnNsThread->sendPacket("ADL", "%d\r\n%s", sz, cxml);
- sz = 0;
- newdom = true;
+ if (used[j] && sz > 7400) {
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "</%c></ml>", lastds ? 'd' : 't');
+ msnNsThread->sendPacket("ADL", "%d\r\n%s", sz, cxml);
+ sz = 0;
+ newdom = true;
+ }
}
+ if (!newdom)
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, lastds ? "</d>" : "</t>");
}
- if (!newdom) sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, lastds ? "</d>" : "</t>");
}
- LeaveCriticalSection(&csLists);
- if (sz)
- {
- sz += mir_snprintf(cxml+sz, sizeof(cxml)-sz, "</ml>");
+ if (sz) {
+ sz += mir_snprintf(cxml + sz, sizeof(cxml) - sz, "</ml>");
msnNsThread->sendPacket("ADL", "%d\r\n%s", sz, cxml);
}
@@ -393,14 +345,13 @@ void CMsnProto::MSN_CreateContList(void) static void AddPrivacyListEntries(HWND hwndList, CMsnProto *proto)
{
- CLCINFOITEM cii = {0};
+ CLCINFOITEM cii = { 0 };
cii.cbSize = sizeof(cii);
cii.flags = CLCIIF_BELOWCONTACTS;
// Delete old info
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0);
- while (hItem)
- {
+ while (hItem) {
HANDLE hItemNext = (HANDLE)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXT, (LPARAM)hItem);
if (IsHContactInfo(hItem))
@@ -410,19 +361,17 @@ static void AddPrivacyListEntries(HWND hwndList, CMsnProto *proto) }
// Add new info
- for (int i=0; i<proto->contList.getCount(); ++i)
- {
+ for (int i = 0; i < proto->contList.getCount(); ++i) {
MsnContact &cont = proto->contList[i];
- if (!(cont.list & (LIST_FL | LIST_LL)))
- {
- cii.pszText = (TCHAR*)cont.email;
+ if (!(cont.list & (LIST_FL | LIST_LL))) {
+ cii.pszText = (TCHAR*)cont.email;
HANDLE hItem = (HANDLE)SendMessage(hwndList, CLM_ADDINFOITEMA, 0, (LPARAM)&cii);
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0,(cont.list & LIST_LL)?1:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1,(cont.list & LIST_FL)?2:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2,(cont.list & LIST_AL)?3:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3,(cont.list & LIST_BL)?4:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(4,(cont.list & LIST_RL)?5:0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, (cont.list & LIST_LL) ? 1 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, (cont.list & LIST_FL) ? 2 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2, (cont.list & LIST_AL) ? 3 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3, (cont.list & LIST_BL) ? 4 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(4, (cont.list & LIST_RL) ? 5 : 0));
}
}
}
@@ -441,11 +390,11 @@ static void SetContactIcons(MCONTACT hItem, HWND hwndList, CMsnProto* proto) }
DWORD dwMask = proto->Lists_GetMask(szEmail);
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0,(dwMask & LIST_LL)?1:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1,(dwMask & LIST_FL)?2:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2,(dwMask & LIST_AL)?3:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3,(dwMask & LIST_BL)?4:0));
- SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(4,(dwMask & LIST_RL)?5:0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, (dwMask & LIST_LL) ? 1 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, (dwMask & LIST_FL) ? 2 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2, (dwMask & LIST_AL) ? 3 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3, (dwMask & LIST_BL) ? 4 : 0));
+ SendMessage(hwndList, CLM_SETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(4, (dwMask & LIST_RL) ? 5 : 0));
}
static void SetAllContactIcons(MCONTACT hItem, HWND hwndList, CMsnProto* proto)
@@ -453,8 +402,7 @@ static void SetAllContactIcons(MCONTACT hItem, HWND hwndList, CMsnProto* proto) if (hItem == NULL)
hItem = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0);
- while (hItem)
- {
+ while (hItem) {
MCONTACT hItemN = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXT, (LPARAM)hItem);
if (IsHContactGroup(hItem)) {
@@ -492,8 +440,7 @@ static void SaveSettings(MCONTACT hItem, HWND hwndList, CMsnProto* proto) if (hItem == NULL)
hItem = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0);
- while (hItem)
- {
+ while (hItem) {
if (IsHContactGroup(hItem)) {
MCONTACT hItemT = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_CHILD, (LPARAM)hItem);
if (hItemT)
@@ -514,24 +461,21 @@ static void SaveSettings(MCONTACT hItem, HWND hwndList, CMsnProto* proto) }
int dwMask = proto->Lists_GetMask(szEmail);
- SaveListItem(hItem, szEmail, LIST_LL, (dwMask & LIST_LL)?1:0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0,0)), proto);
- SaveListItem(hItem, szEmail, LIST_FL, (dwMask & LIST_FL)?2:0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1,0)), proto);
- SaveListItem(hItem, szEmail, LIST_AL, (dwMask & LIST_AL)?3:0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2,0)), proto);
- SaveListItem(hItem, szEmail, LIST_BL, (dwMask & LIST_BL)?4:0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3,0)), proto);
+ SaveListItem(hItem, szEmail, LIST_LL, (dwMask & LIST_LL) ? 1 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(0, 0)), proto);
+ SaveListItem(hItem, szEmail, LIST_FL, (dwMask & LIST_FL) ? 2 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(1, 0)), proto);
+ SaveListItem(hItem, szEmail, LIST_AL, (dwMask & LIST_AL) ? 3 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(2, 0)), proto);
+ SaveListItem(hItem, szEmail, LIST_BL, (dwMask & LIST_BL) ? 4 : 0, SendMessage(hwndList, CLM_GETEXTRAIMAGE, (WPARAM)hItem, MAKELPARAM(3, 0)), proto);
int newMask = proto->Lists_GetMask(szEmail);
int xorMask = newMask ^ dwMask;
- if (xorMask && newMask & (LIST_FL | LIST_LL))
- {
+ if (xorMask && newMask & (LIST_FL | LIST_LL)) {
MCONTACT hContact = IsHContactInfo(hItem) ? proto->MSN_HContactFromEmail(szEmail, szEmail, true, false) : hItem;
proto->MSN_SetContactDb(hContact, szEmail);
}
- if (xorMask & (LIST_FL | LIST_LL) && !(newMask & (LIST_FL | LIST_LL)))
- {
- if (!IsHContactInfo(hItem))
- {
+ if (xorMask & (LIST_FL | LIST_LL) && !(newMask & (LIST_FL | LIST_LL))) {
+ if (!IsHContactInfo(hItem)) {
CallService(MS_DB_CONTACT_DELETE, (WPARAM)hItem, 0);
MsnContact* msc = proto->Lists_Get(szEmail);
if (msc) msc->hContact = NULL;
@@ -544,8 +488,9 @@ static void SaveSettings(MCONTACT hItem, HWND hwndList, CMsnProto* proto) INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch(msg)
- {
+ CMsnProto *proto = (CMsnProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
@@ -557,23 +502,23 @@ INT_PTR CALLBACK DlgProcMsnServLists(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR ImageList_AddIcon(hIml, hIcon);
Skin_ReleaseIcon(hIcon);
- hIcon = LoadIconEx("list_lc");
+ hIcon = LoadIconEx("list_lc");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ICON_LC, STM_SETICON, (WPARAM)hIcon, 0);
- hIcon = LoadIconEx("list_fl");
+ hIcon = LoadIconEx("list_fl");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ICON_FL, STM_SETICON, (WPARAM)hIcon, 0);
- hIcon = LoadIconEx("list_al");
+ hIcon = LoadIconEx("list_al");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ICON_AL, STM_SETICON, (WPARAM)hIcon, 0);
- hIcon = LoadIconEx("list_bl");
+ hIcon = LoadIconEx("list_bl");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ICON_BL, STM_SETICON, (WPARAM)hIcon, 0);
- hIcon = LoadIconEx("list_rl");
+ hIcon = LoadIconEx("list_rl");
ImageList_AddIcon(hIml, hIcon);
SendDlgItemMessage(hwndDlg, IDC_ICON_RL, STM_SETICON, (WPARAM)hIcon, 0);
diff --git a/protocols/MSN/src/msn_msgqueue.cpp b/protocols/MSN/src/msn_msgqueue.cpp index ae231e7097..c11887c53d 100644 --- a/protocols/MSN/src/msn_msgqueue.cpp +++ b/protocols/MSN/src/msn_msgqueue.cpp @@ -29,18 +29,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void CMsnProto::MsgQueue_Init(void)
{
msgQueueSeq = 1;
- InitializeCriticalSection(&csMsgQueue);
}
void CMsnProto::MsgQueue_Uninit(void)
{
MsgQueue_Clear();
- DeleteCriticalSection(&csMsgQueue);
}
int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int msgSize, filetransfer* ft, int flags, STRLIST *cnt)
{
- EnterCriticalSection(&csMsgQueue);
+ mir_cslock lck(csMsgQueue);
MsgQueueEntry* E = new MsgQueueEntry;
lsMessageQueue.insert(E);
@@ -60,55 +58,45 @@ int CMsnProto::MsgQueue_Add(const char* wlid, int msgType, const char* msg, int E->flags = flags;
E->allocatedToThread = 0;
E->ts = time(NULL);
-
- LeaveCriticalSection(&csMsgQueue);
return seq;
}
// shall we create another session?
const char* CMsnProto::MsgQueue_CheckContact(const char* wlid, time_t tsc)
{
- EnterCriticalSection(&csMsgQueue);
-
time_t ts = time(NULL);
- const char* ret = NULL;
+
+ mir_cslock lck(csMsgQueue);
+
for (int i=0; i < lsMessageQueue.getCount(); i++)
- {
if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0 && (tsc == 0 || (ts - lsMessageQueue[i].ts) < tsc))
- {
- ret = wlid;
- break;
- }
- }
+ return wlid;
- LeaveCriticalSection(&csMsgQueue);
- return ret;
+ return NULL;
}
//for threads to determine who they should connect to
const char* CMsnProto::MsgQueue_GetNextRecipient(void)
{
- EnterCriticalSection(&csMsgQueue);
+ mir_cslock lck(csMsgQueue);
- const char* ret = NULL;
for (int i=0; i < lsMessageQueue.getCount(); i++)
{
MsgQueueEntry& E = lsMessageQueue[i];
if (!E.allocatedToThread)
{
E.allocatedToThread = 1;
- ret = E.wlid;
+ const char *ret = E.wlid;
while(++i < lsMessageQueue.getCount())
if (_stricmp(lsMessageQueue[i].wlid, ret) == 0)
lsMessageQueue[i].allocatedToThread = 1;
- break;
+ return ret;
}
}
- LeaveCriticalSection(&csMsgQueue);
- return ret;
+ return NULL;
}
//deletes from list. Must mir_free() return value
@@ -116,8 +104,8 @@ bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) {
int i;
- EnterCriticalSection(&csMsgQueue);
- for(i=0; i < lsMessageQueue.getCount(); i++)
+ mir_cslock lck(csMsgQueue);
+ for (i = 0; i < lsMessageQueue.getCount(); i++)
if (_stricmp(lsMessageQueue[i].wlid, wlid) == 0)
break;
@@ -127,19 +115,18 @@ bool CMsnProto::MsgQueue_GetNext(const char* wlid, MsgQueueEntry& retVal) retVal = lsMessageQueue[i];
lsMessageQueue.remove(i);
}
- LeaveCriticalSection(&csMsgQueue);
+
return res;
}
int CMsnProto::MsgQueue_NumMsg(const char* wlid)
{
int res = 0;
- EnterCriticalSection(&csMsgQueue);
+ mir_cslock lck(csMsgQueue);
for(int i=0; i < lsMessageQueue.getCount(); i++)
res += (_stricmp(lsMessageQueue[i].wlid, wlid) == 0);
- LeaveCriticalSection(&csMsgQueue);
return res;
}
@@ -147,10 +134,9 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) {
int i;
- EnterCriticalSection(&csMsgQueue);
+ mir_cslockfull lck(csMsgQueue);
if (wlid == NULL)
{
-
for(i=0; i < lsMessageQueue.getCount(); i++)
{
const MsgQueueEntry& E = lsMessageQueue[i];
@@ -184,19 +170,17 @@ void CMsnProto::MsgQueue_Clear(const char* wlid, bool msg) if (E.cont) delete E.cont;
lsMessageQueue.remove(i);
- if (msgfnd)
- {
- LeaveCriticalSection(&csMsgQueue);
+ if (msgfnd) {
+ lck.unlock();
MCONTACT hContact = MSN_HContactFromEmail(wlid);
ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)seq,
(LPARAM)Translate("Message delivery failed"));
i = 0;
- EnterCriticalSection(&csMsgQueue);
+ lck.lock();
}
}
}
}
- LeaveCriticalSection(&csMsgQueue);
}
void __cdecl CMsnProto::MsgQueue_AllClearThread(void* arg)
diff --git a/protocols/MSN/src/msn_p2ps.cpp b/protocols/MSN/src/msn_p2ps.cpp index 780c27b197..07d8f80d5a 100644 --- a/protocols/MSN/src/msn_p2ps.cpp +++ b/protocols/MSN/src/msn_p2ps.cpp @@ -28,9 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. void CMsnProto::p2p_registerSession(filetransfer* ft)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
sessionList.insert(ft);
- LeaveCriticalSection(&sessionLock);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -38,11 +37,8 @@ void CMsnProto::p2p_registerSession(filetransfer* ft) void CMsnProto::p2p_unregisterSession(filetransfer* ft)
{
- EnterCriticalSection(&sessionLock);
-// int idx = sessionList.getIndex(ft);
-// if (idx > -1)
- sessionList.remove(ft);
- LeaveCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
+ sessionList.remove(ft);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -53,24 +49,15 @@ filetransfer* CMsnProto::p2p_getSessionByID(unsigned id) if (id == 0)
return NULL;
- filetransfer* ft = NULL;
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
- for (int i=0; i < sessionList.getCount(); i++)
- {
+ for (int i=0; i < sessionList.getCount(); i++) {
filetransfer* FT = &sessionList[i];
if (FT->p2p_sessionid == id)
- {
- ft = FT;
- break;
- }
+ return FT;
}
- LeaveCriticalSection(&sessionLock);
- if (ft == NULL)
- debugLogA("Ignoring unknown session id %08x", id);
-
- return ft;
+ return NULL;
}
filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id)
@@ -78,24 +65,16 @@ filetransfer* CMsnProto::p2p_getSessionByUniqueID(unsigned id) if (id == 0)
return NULL;
- filetransfer* ft = NULL;
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
for (int i=0; i < sessionList.getCount(); i++)
{
filetransfer* FT = &sessionList[i];
if (FT->p2p_acksessid == id)
- {
- ft = FT;
- break;
- }
+ return FT;
}
- LeaveCriticalSection(&sessionLock);
- if (ft == NULL)
- debugLogA("Ignoring unknown unique id %08x", id);
-
- return ft;
+ return NULL;
}
@@ -104,34 +83,27 @@ bool CMsnProto::p2p_sessionRegistered(filetransfer* ft) if (ft != NULL && ft->p2p_appID == 0)
return true;
- EnterCriticalSection(&sessionLock);
- int idx = sessionList.getIndex(ft);
- LeaveCriticalSection(&sessionLock);
- return idx > -1;
+ mir_cslock lck(sessionLock);
+ return sessionList.getIndex(ft) > -1;
}
filetransfer* CMsnProto::p2p_getThreadSession(MCONTACT hContact, TInfoType mType)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
- filetransfer* result = NULL;
for (int i=0; i < sessionList.getCount(); i++)
{
filetransfer* FT = &sessionList[i];
if (FT->std.hContact == hContact && FT->tType == mType)
- {
- result = FT;
- break;
- }
+ return FT;
}
- LeaveCriticalSection(&sessionLock);
- return result;
+ return NULL;
}
void CMsnProto::p2p_clearThreadSessions(MCONTACT hContact, TInfoType mType)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
for (int i=0; i < sessionList.getCount(); i++)
{
@@ -143,31 +115,25 @@ void CMsnProto::p2p_clearThreadSessions(MCONTACT hContact, TInfoType mType) p2p_sendCancel(ft);
}
}
-
- LeaveCriticalSection(&sessionLock);
}
filetransfer* CMsnProto::p2p_getAvatarSession(MCONTACT hContact)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
- filetransfer* result = NULL;
for (int i=0; i < sessionList.getCount(); i++)
{
filetransfer* FT = &sessionList[i];
- if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && FT->p2p_type == MSN_APPID_AVATAR) {
- result = FT;
- break;
- }
+ if (FT->std.hContact == hContact && !(FT->std.flags & PFTS_SENDING) && FT->p2p_type == MSN_APPID_AVATAR)
+ return FT;
}
- LeaveCriticalSection(&sessionLock);
- return result;
+ return NULL;
}
bool CMsnProto::p2p_isAvatarOnly(MCONTACT hContact)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
bool result = true;
for (int i=0; i < sessionList.getCount(); i++)
@@ -176,13 +142,12 @@ bool CMsnProto::p2p_isAvatarOnly(MCONTACT hContact) result &= FT->std.hContact != hContact || FT->p2p_type != MSN_APPID_FILE;
}
- LeaveCriticalSection(&sessionLock);
return result;
}
void CMsnProto::p2p_clearDormantSessions(void)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslockfull lck(sessionLock);
time_t ts = time(NULL);
for (int i=0; i < sessionList.getCount(); i++)
@@ -194,19 +159,17 @@ void CMsnProto::p2p_clearDormantSessions(void) {
FT->bCanceled = true;
p2p_sendCancel(FT);
- LeaveCriticalSection(&sessionLock);
+ lck.unlock();
p2p_unregisterSession(FT);
- EnterCriticalSection(&sessionLock);
+ lck.lock();
i = 0;
}
}
-
- LeaveCriticalSection(&sessionLock);
}
void CMsnProto::p2p_redirectSessions(const char *wlid)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
ThreadData* T = MSN_GetP2PThreadByContact(wlid);
for (int i=0; i < sessionList.getCount(); i++)
@@ -228,13 +191,11 @@ void CMsnProto::p2p_redirectSessions(const char *wlid) }
}
}
-
- LeaveCriticalSection(&sessionLock);
}
void CMsnProto::p2p_startSessions(const char* wlid)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
char* szEmail;
parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
@@ -250,21 +211,17 @@ void CMsnProto::p2p_startSessions(const char* wlid) p2p_invite(FT->p2p_type, FT, wlid);
}
}
-
- LeaveCriticalSection(&sessionLock);
}
void CMsnProto::p2p_cancelAllSessions(void)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
for (int i=0; i < sessionList.getCount(); i++)
{
sessionList[i].bCanceled = true;
p2p_sendCancel(&sessionList[i]);
}
-
- LeaveCriticalSection(&sessionLock);
}
filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* wlid)
@@ -272,9 +229,8 @@ filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* if (CallID == NULL)
return NULL;
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
- filetransfer* ft = NULL;
char* szEmail = NULL;
for (int i=0; i < sessionList.getCount(); i++)
{
@@ -288,31 +244,24 @@ filetransfer* CMsnProto::p2p_getSessionByCallID(const char* CallID, const char* if (_stricmp(FT->p2p_dest, szEmail))
continue;
}
- ft = FT;
- break;
+ return FT;
}
}
- LeaveCriticalSection(&sessionLock);
- if (ft == NULL)
- debugLogA("Ignoring unknown session call id %s", CallID);
-
- return ft;
+ return NULL;
}
void CMsnProto::p2p_registerDC(directconnection* dc)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
dcList.insert(dc);
- LeaveCriticalSection(&sessionLock);
}
void CMsnProto::p2p_unregisterDC(directconnection* dc)
{
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
dcList.remove(dc);
- LeaveCriticalSection(&sessionLock);
}
directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* wlid)
@@ -320,39 +269,24 @@ directconnection* CMsnProto::p2p_getDCByCallID(const char* CallID, const char* w if (CallID == NULL)
return NULL;
- EnterCriticalSection(&sessionLock);
+ mir_cslock lck(sessionLock);
- directconnection* dc = NULL;
for (int i=0; i < dcList.getCount(); i++)
{
directconnection* DC = &dcList[i];
if (DC->callId != NULL && !strcmp(DC->callId, CallID) && !strcmp(DC->wlid, wlid))
- {
- dc = DC;
- break;
- }
+ return DC;
}
- LeaveCriticalSection(&sessionLock);
-
- return dc;
+ return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
// external functions
-void CMsnProto::P2pSessions_Init(void)
-{
- InitializeCriticalSection(&sessionLock);
-}
-
void CMsnProto::P2pSessions_Uninit(void)
{
- EnterCriticalSection(&sessionLock);
-
+ mir_cslock lck(sessionLock);
sessionList.destroy();
dcList.destroy();
-
- LeaveCriticalSection(&sessionLock);
- DeleteCriticalSection(&sessionLock);
}
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp index b46434f68e..f289313ee6 100644 --- a/protocols/MSN/src/msn_proto.cpp +++ b/protocols/MSN/src/msn_proto.cpp @@ -53,30 +53,30 @@ CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) : // Protocol services and events...
hMSNNudge = CreateProtoEvent("/Nudge");
- CreateProtoService(PS_CREATEACCMGRUI, &CMsnProto::SvcCreateAccMgrUI);
+ CreateProtoService(PS_CREATEACCMGRUI, &CMsnProto::SvcCreateAccMgrUI);
- CreateProtoService(PS_GETAVATARINFOT, &CMsnProto::GetAvatarInfo);
- CreateProtoService(PS_GETMYAWAYMSG, &CMsnProto::GetMyAwayMsg);
+ CreateProtoService(PS_GETAVATARINFOT, &CMsnProto::GetAvatarInfo);
+ CreateProtoService(PS_GETMYAWAYMSG, &CMsnProto::GetMyAwayMsg);
- CreateProtoService(PS_LEAVECHAT, &CMsnProto::OnLeaveChat);
+ CreateProtoService(PS_LEAVECHAT, &CMsnProto::OnLeaveChat);
- CreateProtoService(PS_GETMYAVATART, &CMsnProto::GetAvatar);
- CreateProtoService(PS_SETMYAVATART, &CMsnProto::SetAvatar);
- CreateProtoService(PS_GETAVATARCAPS, &CMsnProto::GetAvatarCaps);
+ CreateProtoService(PS_GETMYAVATART, &CMsnProto::GetAvatar);
+ CreateProtoService(PS_SETMYAVATART, &CMsnProto::SetAvatar);
+ CreateProtoService(PS_GETAVATARCAPS, &CMsnProto::GetAvatarCaps);
- CreateProtoService(PS_GET_LISTENINGTO, &CMsnProto::GetCurrentMedia);
- CreateProtoService(PS_SET_LISTENINGTO, &CMsnProto::SetCurrentMedia);
+ CreateProtoService(PS_GET_LISTENINGTO, &CMsnProto::GetCurrentMedia);
+ CreateProtoService(PS_SET_LISTENINGTO, &CMsnProto::SetCurrentMedia);
- CreateProtoService(PS_SETMYNICKNAME, &CMsnProto::SetNickName);
- CreateProtoService(PS_SEND_NUDGE, &CMsnProto::SendNudge);
+ CreateProtoService(PS_SETMYNICKNAME, &CMsnProto::SetNickName);
+ CreateProtoService(PS_SEND_NUDGE, &CMsnProto::SendNudge);
- CreateProtoService(PS_GETUNREADEMAILCOUNT, &CMsnProto::GetUnreadEmailCount);
+ CreateProtoService(PS_GETUNREADEMAILCOUNT, &CMsnProto::GetUnreadEmailCount);
// event hooks
- HookProtoEvent(ME_MSG_WINDOWPOPUP, &CMsnProto::OnWindowPopup);
- HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMsnProto::OnGroupChange);
- HookProtoEvent(ME_OPT_INITIALISE, &CMsnProto::OnOptionsInit);
- HookProtoEvent(ME_CLIST_DOUBLECLICKED, &CMsnProto::OnContactDoubleClicked);
+ HookProtoEvent(ME_MSG_WINDOWPOPUP, &CMsnProto::OnWindowPopup);
+ HookProtoEvent(ME_CLIST_GROUPCHANGE, &CMsnProto::OnGroupChange);
+ HookProtoEvent(ME_OPT_INITIALISE, &CMsnProto::OnOptionsInit);
+ HookProtoEvent(ME_CLIST_DOUBLECLICKED, &CMsnProto::OnContactDoubleClicked);
LoadOptions();
@@ -110,17 +110,14 @@ CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) : mir_snprintf(alertsoundname, 64, "%s:Alerts", m_szModuleName);
SkinAddNewSoundExT(alertsoundname, m_tszUserName, LPGENT("Live Alert"));
- MSN_InitThreads();
- Lists_Init();
MsgQueue_Init();
AvatarQueue_Init();
- P2pSessions_Init();
InitCustomFolders();
TCHAR szBuffer[MAX_PATH];
char szDbsettings[64];
- NETLIBUSER nlu1 = {0};
+ NETLIBUSER nlu1 = { 0 };
nlu1.cbSize = sizeof(nlu1);
nlu1.flags = NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu1.szSettingsModule = szDbsettings;
@@ -130,7 +127,7 @@ CMsnProto::CMsnProto(const char* aProtoName, const TCHAR* aUserName) : mir_sntprintf(szBuffer, SIZEOF(szBuffer), TranslateT("%s plugin HTTPS connections"), m_tszUserName);
hNetlibUserHttps = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu1);
- NETLIBUSER nlu = {0};
+ NETLIBUSER nlu = { 0 };
nlu.cbSize = sizeof(nlu);
nlu.flags = NUF_INCOMING | NUF_OUTGOING | NUF_HTTPCONNS | NUF_TCHAR;
nlu.szSettingsModule = m_szModuleName;
@@ -165,7 +162,7 @@ CMsnProto::~CMsnProto() mir_free(mailsoundname);
mir_free(alertsoundname);
- for (int i=0; i < MSN_NUM_MODES; i++)
+ for (int i = 0; i < MSN_NUM_MODES; i++)
mir_free(msnModeMsgs[i]);
mir_free(msnLastStatusMsg);
@@ -181,7 +178,7 @@ CMsnProto::~CMsnProto() int CMsnProto::OnModulesLoaded(WPARAM, LPARAM)
{
- GCREGISTER gcr = {0};
+ GCREGISTER gcr = { 0 };
gcr.cbSize = sizeof(GCREGISTER);
gcr.dwFlags = GC_TYPNOTIF | GC_CHANMGR;
gcr.iMaxText = 0;
@@ -212,7 +209,6 @@ int CMsnProto::OnPreShutdown(WPARAM, LPARAM) return 0;
}
-
/////////////////////////////////////////////////////////////////////////////////////////
// MsnAddToList - adds contact to the server list
@@ -220,21 +216,15 @@ MCONTACT CMsnProto::AddToListByEmail(const char *email, const char *nick, DWORD {
MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, flags & PALF_TEMPORARY);
- if (flags & PALF_TEMPORARY)
- {
+ if (flags & PALF_TEMPORARY) {
if (db_get_b(hContact, "CList", "NotOnList", 0) == 1)
db_set_b(hContact, "CList", "Hidden", 1);
}
- else
- {
+ else {
db_unset(hContact, "CList", "Hidden");
- if (msnLoggedIn)
- {
-// int netId = Lists_GetNetId(email);
-// if (netId == NETID_UNKNOWN)
+ if (msnLoggedIn) {
int netId = strncmp(email, "tel:", 4) ? NETID_MSN : NETID_MOB;
- if (MSN_AddUser(hContact, email, netId, LIST_FL))
- {
+ if (MSN_AddUser(hContact, email, netId, LIST_FL)) {
MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
MSN_AddUser(hContact, email, netId, LIST_AL);
@@ -264,12 +254,12 @@ MCONTACT __cdecl CMsnProto::AddToListByEvent(int flags, int iContact, HANDLE hDb if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1))
return NULL;
- dbei.pBlob=(PBYTE) alloca(dbei.cbBlob);
+ dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
if (db_event_get(hDbEvent, &dbei)) return NULL;
if (strcmp(dbei.szModule, m_szModuleName)) return NULL;
if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return NULL;
- char* nick = (char *) (dbei.pBlob + sizeof(DWORD)*2);
+ char* nick = (char *)(dbei.pBlob + sizeof(DWORD) * 2);
char* firstName = nick + strlen(nick) + 1;
char* lastName = firstName + strlen(firstName) + 1;
char* email = lastName + strlen(lastName) + 1;
@@ -288,19 +278,15 @@ int CMsnProto::AuthRecv(MCONTACT hContact, PROTORECVEVENT* pre) int __cdecl CMsnProto::AuthRequest(MCONTACT hContact, const TCHAR* szMessage)
{
- if (msnLoggedIn)
- {
+ if (msnLoggedIn) {
char email[MSN_MAX_EMAIL_LEN];
if (db_get_static(hContact, m_szModuleName, "e-mail", email, sizeof(email)))
return 1;
char* szMsg = mir_utf8encodeT(szMessage);
-// int netId = Lists_GetNetId(email);
-// if (netId == NETID_UNKNOWN)
int netId = strncmp(email, "tel:", 4) == 0 ? NETID_MOB : NETID_MSN;
- if (MSN_AddUser(hContact, email, netId, LIST_FL, szMsg))
- {
+ if (MSN_AddUser(hContact, email, netId, LIST_FL, szMsg)) {
MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
MSN_AddUser(hContact, email, netId, LIST_AL);
@@ -336,10 +322,10 @@ int CMsnProto::Authorize(HANDLE hDbEvent) if (strcmp(dbei.szModule, m_szModuleName))
return 1;
- char* nick = (char*)(dbei.pBlob + sizeof(DWORD)*2);
- char* firstName = nick + strlen(nick) + 1;
- char* lastName = firstName + strlen(firstName) + 1;
- char* email = lastName + strlen(lastName) + 1;
+ char *nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
+ char *firstName = nick + strlen(nick) + 1;
+ char *lastName = firstName + strlen(firstName) + 1;
+ char *email = lastName + strlen(lastName) + 1;
MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, 0);
int netId = Lists_GetNetId(email);
@@ -374,7 +360,7 @@ int CMsnProto::AuthDeny(HANDLE hDbEvent, const TCHAR* szReason) if (strcmp(dbei.szModule, m_szModuleName))
return 1;
- char* nick = (char*)(dbei.pBlob + sizeof(DWORD)*2);
+ char* nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
char* firstName = nick + strlen(nick) + 1;
char* lastName = firstName + strlen(firstName) + 1;
char* email = lastName + strlen(lastName) + 1;
@@ -386,8 +372,7 @@ int CMsnProto::AuthDeny(HANDLE hDbEvent, const TCHAR* szReason) MSN_AddUser(NULL, email, msc->netId, LIST_BL);
MSN_AddUser(NULL, email, msc->netId, LIST_RL);
- if (!(msc->list & (LIST_FL | LIST_LL)))
- {
+ if (!(msc->list & (LIST_FL | LIST_LL))) {
if (msc->hContact) CallService(MS_DB_CONTACT_DELETE, (WPARAM)msc->hContact, 0);
msc->hContact = NULL;
MCONTACT hContact = MSN_HContactFromEmail(email);
@@ -405,8 +390,7 @@ void __cdecl CMsnProto::MsnSearchAckThread(void* arg) const TCHAR* emailT = (TCHAR*)arg;
char *email = mir_utf8encodeT(emailT);
- if (Lists_IsInList(LIST_FL, email))
- {
+ if (Lists_IsInList(LIST_FL, email)) {
MSN_ShowPopup(emailT, TranslateT("Contact already in your contact list"), MSN_ALLOW_MSGBOX, NULL);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, arg, 0);
mir_free(arg);
@@ -414,17 +398,16 @@ void __cdecl CMsnProto::MsnSearchAckThread(void* arg) }
unsigned res = MSN_ABContactAdd(email, NULL, NETID_MSN, NULL, 1, true);
- switch(res)
- {
+ switch (res) {
case 0:
case 2:
case 3:
{
- PROTOSEARCHRESULT isr = {0};
+ PROTOSEARCHRESULT isr = { 0 };
isr.cbSize = sizeof(isr);
isr.flags = PSR_TCHAR;
- isr.id = (TCHAR*)emailT;
- isr.nick = (TCHAR*)emailT;
+ isr.id = (TCHAR*)emailT;
+ isr.nick = (TCHAR*)emailT;
isr.email = (TCHAR*)emailT;
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, arg, (LPARAM)&isr);
@@ -435,8 +418,7 @@ void __cdecl CMsnProto::MsnSearchAckThread(void* arg) case 1:
if (strstr(email, "@yahoo.com") == NULL)
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, arg, 0);
- else
- {
+ else {
msnSearchId = arg;
MSN_FindYahooUser(email);
}
@@ -498,14 +480,12 @@ void __cdecl CMsnProto::MsnFileAckThread(void* arg) bool fcrt = ft->create() != -1;
- if (ft->p2p_appID != 0)
- {
+ if (ft->p2p_appID != 0) {
if (fcrt)
p2p_sendFeedStart(ft);
p2p_sendStatus(ft, fcrt ? 200 : 603);
}
- else
- msnftp_sendAcceptReject (ft, fcrt);
+ else msnftp_sendAcceptReject(ft, fcrt);
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
}
@@ -517,14 +497,12 @@ HANDLE __cdecl CMsnProto::FileAllow(MCONTACT hContact, HANDLE hTransfer, const P if (!msnLoggedIn || !p2p_sessionRegistered(ft))
return 0;
- if ((ft->std.tszWorkingDir = mir_tstrdup(szPath)) == NULL)
- {
+ if ((ft->std.tszWorkingDir = mir_tstrdup(szPath)) == NULL) {
TCHAR szCurrDir[MAX_PATH];
GetCurrentDirectory(SIZEOF(szCurrDir), szCurrDir);
ft->std.tszWorkingDir = mir_tstrdup(szCurrDir);
}
- else
- {
+ else {
size_t len = _tcslen(ft->std.tszWorkingDir) - 1;
if (ft->std.tszWorkingDir[len] == '\\')
ft->std.tszWorkingDir[len] = 0;
@@ -545,20 +523,17 @@ int __cdecl CMsnProto::FileCancel(MCONTACT hContact, HANDLE hTransfer) if (!msnLoggedIn || !p2p_sessionRegistered(ft))
return 0;
- if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1)
- {
+ if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1) {
if (ft->p2p_appID != 0)
p2p_sendStatus(ft, 603);
else
- msnftp_sendAcceptReject (ft, false);
+ msnftp_sendAcceptReject(ft, false);
}
- else
- {
+ else {
ft->bCanceled = true;
- if (ft->p2p_appID != 0)
- {
+ if (ft->p2p_appID != 0) {
p2p_sendCancel(ft);
- if (!(ft->std.flags & PFTS_SENDING) && ft->p2p_isV2)
+ if (!(ft->std.flags & PFTS_SENDING) && ft->p2p_isV2)
p2p_sessionComplete(ft);
}
}
@@ -578,15 +553,13 @@ int __cdecl CMsnProto::FileDeny(MCONTACT hContact, HANDLE hTransfer, const PROTO if (!msnLoggedIn || !p2p_sessionRegistered(ft))
return 1;
- if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1)
- {
+ if (!(ft->std.flags & PFTS_SENDING) && ft->fileId == -1) {
if (ft->p2p_appID != 0)
p2p_sendStatus(ft, 603);
else
- msnftp_sendAcceptReject (ft, false);
+ msnftp_sendAcceptReject(ft, false);
}
- else
- {
+ else {
ft->bCanceled = true;
if (ft->p2p_appID != 0)
p2p_sendCancel(ft);
@@ -605,13 +578,12 @@ int __cdecl CMsnProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR if (!msnLoggedIn || !p2p_sessionRegistered(ft))
return 1;
- switch (*action)
- {
+ switch (*action) {
case FILERESUME_SKIP:
if (ft->p2p_appID != 0)
p2p_sendStatus(ft, 603);
else
- msnftp_sendAcceptReject (ft, false);
+ msnftp_sendAcceptReject(ft, false);
break;
case FILERESUME_RENAME:
@@ -619,15 +591,14 @@ int __cdecl CMsnProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR default:
bool fcrt = ft->create() != -1;
- if (ft->p2p_appID != 0)
- {
+ if (ft->p2p_appID != 0) {
if (fcrt)
p2p_sendFeedStart(ft);
p2p_sendStatus(ft, fcrt ? 200 : 603);
}
else
- msnftp_sendAcceptReject (ft, fcrt);
+ msnftp_sendAcceptReject(ft, fcrt);
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft, 0);
break;
@@ -675,11 +646,11 @@ HANDLE __cdecl CMsnProto::GetAwayMsg(MCONTACT hContact) DWORD_PTR __cdecl CMsnProto::GetCaps(int type, MCONTACT hContact)
{
- switch(type) {
+ switch (type) {
case PFLAGNUM_1:
return PF1_IM | PF1_SERVERCLIST | PF1_AUTHREQ | PF1_BASICSEARCH |
- PF1_ADDSEARCHRES | PF1_CHAT |
- PF1_FILESEND | PF1_FILERECV | PF1_URLRECV | PF1_VISLIST | PF1_MODEMSG;
+ PF1_ADDSEARCHRES | PF1_CHAT |
+ PF1_FILESEND | PF1_FILERECV | PF1_URLRECV | PF1_VISLIST | PF1_MODEMSG;
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE;
@@ -692,7 +663,7 @@ DWORD_PTR __cdecl CMsnProto::GetCaps(int type, MCONTACT hContact) PF4_IMSENDOFFLINE | PF4_NOAUTHDENYREASON;
case PFLAGNUM_5:
- return PF2_ONTHEPHONE;
+ return PF2_ONTHEPHONE;
case PFLAG_UNIQUEIDTEXT:
return (UINT_PTR)Translate("Live ID");
@@ -785,26 +756,22 @@ HANDLE __cdecl CMsnProto::SendFile(MCONTACT hContact, const PROTOCHAR* szDescrip sft->std.flags |= PFTS_SENDING;
int count = 0;
- while (ppszFiles[count] != NULL)
- {
+ while (ppszFiles[count] != NULL) {
struct _stati64 statbuf;
- if (_tstati64(ppszFiles[count++], &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0)
- {
+ if (_tstati64(ppszFiles[count++], &statbuf) == 0 && (statbuf.st_mode & _S_IFDIR) == 0) {
sft->std.totalBytes += statbuf.st_size;
++sft->std.totalFiles;
}
}
- if (sft->openNext() == -1)
- {
+ if (sft->openNext() == -1) {
delete sft;
return 0;
}
if (cont->cap1 & 0xf0000000)
p2p_invite(MSN_APPID_FILE, sft, NULL);
- else
- {
+ else {
sft->p2p_dest = mir_strdup(cont->email);
msnftp_invite(sft);
}
@@ -823,7 +790,7 @@ struct TFakeAckParams id(p3),
msg(p4),
proto(p5)
- {}
+ {}
MCONTACT hContact;
long id;
@@ -847,16 +814,14 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) {
const char *errMsg = NULL;
- if (!msnLoggedIn)
- {
+ if (!msnLoggedIn) {
errMsg = Translate("Protocol is offline");
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
return 999999;
}
char tEmail[MSN_MAX_EMAIL_LEN];
- if (MSN_IsMeByContact(hContact, tEmail))
- {
+ if (MSN_IsMeByContact(hContact, tEmail)) {
errMsg = Translate("You cannot send message to yourself");
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, 999999, errMsg, this));
return 999999;
@@ -865,11 +830,9 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) char *msg = (char*)pszSrc;
if (msg == NULL) return 0;
- if (flags & PREF_UNICODE)
- {
+ if (flags & PREF_UNICODE) {
char* p = strchr(msg, '\0');
- if (p != msg)
- {
+ if (p != msg) {
while (*(++p) == '\0') {}
msg = mir_utf8encodeW((wchar_t*)p);
}
@@ -882,17 +845,15 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) int rtlFlag = (flags & PREF_RTL) ? MSG_RTL : 0;
int seq = 0;
- int netId = Lists_GetNetId(tEmail);
+ int netId = Lists_GetNetId(tEmail);
switch (netId) {
case NETID_MOB:
- if (strlen(msg) > 133)
- {
+ if (strlen(msg) > 133) {
errMsg = Translate("Message is too long: SMS page limited to 133 UTF8 chars");
seq = 999997;
}
- else
- {
+ else {
errMsg = NULL;
seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
}
@@ -900,42 +861,34 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) break;
case NETID_YAHOO:
- if (strlen(msg) > 1202)
- {
+ if (strlen(msg) > 1202) {
seq = 999996;
errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
}
- else
- {
+ else {
seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag);
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
}
break;
default:
- if (strlen(msg) > 1202)
- {
+ if (strlen(msg) > 1202) {
seq = 999996;
errMsg = Translate("Message is too long: MSN messages are limited by 1202 UTF8 chars");
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
}
- else
- {
+ else {
const char msgType = MyOptions.SlowSend ? 'A' : 'N';
bool isOffline;
ThreadData* thread = MSN_StartSB(tEmail, isOffline);
- if (thread == NULL)
- {
- if (isOffline)
- {
- if (netId != NETID_LCS)
- {
+ if (thread == NULL) {
+ if (isOffline) {
+ if (netId != NETID_LCS) {
seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE);
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
}
- else
- {
+ else {
seq = 999993;
errMsg = Translate("Offline messaging is not allowed for LCS contacts");
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
@@ -944,8 +897,7 @@ int __cdecl CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc) else
seq = MsgQueue_Add(tEmail, msgType, msg, 0, 0, rtlFlag);
}
- else
- {
+ else {
seq = thread->sendMessage(msgType, tEmail, netId, msg, rtlFlag);
if (!MyOptions.SlowSend)
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, NULL, this));
@@ -970,18 +922,16 @@ int __cdecl CMsnProto::SetAwayMsg(int status, const TCHAR* msg) mir_free(*msgptr);
char* buf = *msgptr = mir_utf8encodeT(msg);
- if (buf && strlen(buf) > 1859)
- {
+ if (buf && strlen(buf) > 1859) {
buf[1859] = 0;
const int i = 1858;
- if (buf[i] & 128)
- {
+ if (buf[i] & 128) {
if (buf[i] & 64)
buf[i] = '\0';
- else if ((buf[i-1] & 224) == 224)
- buf[i-1] = '\0';
+ else if ((buf[i - 1] & 224) == 224)
+ buf[i - 1] = '\0';
else if ((buf[i - 2] & 240) == 240)
- buf[i-2] = '\0';
+ buf[i - 2] = '\0';
}
}
@@ -1009,24 +959,20 @@ int __cdecl CMsnProto::SetStatus(int iNewStatus) m_iDesiredStatus = iNewStatus;
debugLogA("PS_SETSTATUS(%d,0)", iNewStatus);
- if (m_iDesiredStatus == ID_STATUS_OFFLINE)
- {
+ if (m_iDesiredStatus == ID_STATUS_OFFLINE) {
if (msnNsThread)
msnNsThread->sendTerminate();
}
- else if (!msnLoggedIn && m_iStatus == ID_STATUS_OFFLINE)
- {
+ else if (!msnLoggedIn && m_iStatus == ID_STATUS_OFFLINE) {
char szPassword[100];
int ps = db_get_static(NULL, m_szModuleName, "Password", szPassword, sizeof(szPassword));
- if (ps != 0 || *szPassword == 0)
- {
+ if (ps != 0 || *szPassword == 0) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
return 0;
}
- if (*MyOptions.szEmail == 0)
- {
+ if (*MyOptions.szEmail == 0) {
ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID);
m_iStatus = m_iDesiredStatus = ID_STATUS_OFFLINE;
return 0;
@@ -1067,8 +1013,7 @@ int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) bool typing = type == PROTOTYPE_SELFTYPING_ON;
int netId = Lists_GetNetId(tEmail);
- switch (netId)
- {
+ switch (netId) {
case NETID_UNKNOWN:
case NETID_MSN:
case NETID_LCS:
@@ -1076,8 +1021,7 @@ int __cdecl CMsnProto::UserIsTyping(MCONTACT hContact, int type) bool isOffline;
ThreadData* thread = MSN_StartSB(tEmail, isOffline);
- if (thread == NULL)
- {
+ if (thread == NULL) {
if (isOffline) return 0;
MsgQueue_Add(tEmail, 2571, NULL, 0, NULL, typing);
}
@@ -1111,7 +1055,7 @@ int __cdecl CMsnProto::SendUrl(MCONTACT hContact, int flags, const char* url) int __cdecl CMsnProto::SetApparentMode(MCONTACT hContact, int mode)
{
if (mode && mode != ID_STATUS_OFFLINE)
- return 1;
+ return 1;
WORD oldMode = getWord(hContact, "ApparentMode", 0);
if (mode != oldMode)
@@ -1122,8 +1066,7 @@ int __cdecl CMsnProto::SetApparentMode(MCONTACT hContact, int mode) int __cdecl CMsnProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam)
{
- switch(eventType)
- {
+ switch (eventType) {
case EV_PROTO_ONLOAD:
return OnModulesLoaded(0, 0);
@@ -1142,8 +1085,8 @@ int __cdecl CMsnProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM l char szDbsettings[64];
mir_snprintf(szDbsettings, sizeof(szDbsettings), "%s_HTTPS", m_szModuleName);
CallService(MS_DB_MODULE_DELETE, 0, (LPARAM)szDbsettings);
- break;
}
+ break;
case EV_PROTO_ONRENAME:
if (mainMenuRoot) {
diff --git a/protocols/MSN/src/msn_proto.h b/protocols/MSN/src/msn_proto.h index 49d99761d0..9c0b27214b 100644 --- a/protocols/MSN/src/msn_proto.h +++ b/protocols/MSN/src/msn_proto.h @@ -123,23 +123,23 @@ struct CMsnProto : public PROTO<CMsnProto> char *abCacheKey, *sharingCacheKey, *storageCacheKey;
- CRITICAL_SECTION csLists;
+ mir_cs csLists;
OBJLIST<MsnContact> contList;
LIST<ServerGroupItem> grpList;
- CRITICAL_SECTION sttLock;
+ mir_cs csThreads;
OBJLIST<ThreadData> sttThreads;
- CRITICAL_SECTION sessionLock;
+ mir_cs sessionLock;
OBJLIST<filetransfer> sessionList;
OBJLIST<directconnection> dcList;
- CRITICAL_SECTION csMsgQueue;
+ mir_cs csMsgQueue;
int msgQueueSeq;
OBJLIST<MsgQueueEntry> lsMessageQueue;
- CRITICAL_SECTION csAvatarQueue;
+ mir_cs csAvatarQueue;
LIST<AvatarQueueEntry> lsAvatarQueue;
HANDLE hevAvatarQueue;
@@ -148,7 +148,7 @@ struct CMsnProto : public PROTO<CMsnProto> int msnPingTimeout;
HANDLE hKeepAliveThreadEvt;
- char* msnModeMsgs[MSN_NUM_MODES];
+ char* msnModeMsgs[MSN_NUM_MODES];
LISTENINGTOINFO msnCurrentMedia;
MYOPTIONS MyOptions;
@@ -286,7 +286,6 @@ struct CMsnProto : public PROTO<CMsnProto> void Threads_Uninit(void);
void MSN_CloseConnections(void);
- void MSN_InitThreads(void);
int MSN_GetChatThreads(ThreadData** parResult);
int MSN_GetActiveThreads(ThreadData**);
ThreadData* MSN_GetThreadByConnection(HANDLE hConn);
@@ -375,7 +374,6 @@ struct CMsnProto : public PROTO<CMsnProto> void p2p_unregisterSession(filetransfer* ft);
void p2p_sessionComplete(filetransfer* ft);
- void P2pSessions_Init(void);
void P2pSessions_Uninit(void);
filetransfer* p2p_getAvatarSession(MCONTACT hContact);
@@ -434,7 +432,6 @@ struct CMsnProto : public PROTO<CMsnProto> MsnPlace* Lists_GetPlace(const char* wlid);
MsnPlace* Lists_AddPlace(const char* email, const char* id, unsigned cap1, unsigned cap2);
- void Lists_Init(void);
void Lists_Uninit(void);
void AddDelUserContList(const char* email, const int list, const int netId, const bool del);
diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp index 057f694311..e643bce91b 100644 --- a/protocols/MSN/src/msn_threads.cpp +++ b/protocols/MSN/src/msn_threads.cpp @@ -300,14 +300,9 @@ LBL_Exit: debugLogA("Thread [%08X] ending now", GetCurrentThreadId());
}
-void CMsnProto::MSN_InitThreads(void)
-{
- InitializeCriticalSection(&sttLock);
-}
-
void CMsnProto::MSN_CloseConnections(void)
{
- EnterCriticalSection(&sttLock);
+ mir_cslockfull lck(csThreads);
NETLIBSELECTEX nls = {0};
nls.cbSize = sizeof(nls);
@@ -335,7 +330,7 @@ void CMsnProto::MSN_CloseConnections(void) }
}
- LeaveCriticalSection(&sttLock);
+ lck.unlock();
if (hHttpsConnection)
CallService(MS_NETLIB_SHUTDOWN, (WPARAM)hHttpsConnection, 0);
@@ -343,16 +338,13 @@ void CMsnProto::MSN_CloseConnections(void) void CMsnProto::Threads_Uninit(void)
{
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
sttThreads.destroy();
- LeaveCriticalSection(&sttLock);
- DeleteCriticalSection(&sttLock);
}
ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
if (type == SERVER_P2P_DIRECT)
{
@@ -363,80 +355,58 @@ ThreadData* CMsnProto::MSN_GetThreadByContact(const char* wlid, TInfoType type) continue;
if (_stricmp(T->mJoinedIdentContactsWLID[0], wlid) == 0)
- {
- result = T;
- break;
- }
+ return T;
}
}
- if (result == NULL)
- {
- char *szEmail = NULL;
- parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
+ char *szEmail = NULL;
+ parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
- for (int i=0; i < sttThreads.getCount(); i++)
- {
- ThreadData* T = &sttThreads[i];
- if (T->mType != type || !T->mJoinedContactsWLID.getCount() || T->mInitialContactWLID || T->s == NULL)
- continue;
+ for (int i=0; i < sttThreads.getCount(); i++)
+ {
+ ThreadData* T = &sttThreads[i];
+ if (T->mType != type || !T->mJoinedContactsWLID.getCount() || T->mInitialContactWLID || T->s == NULL)
+ continue;
- if (_stricmp(T->mJoinedContactsWLID[0], szEmail) == 0 && T->mChatID[0] == 0)
- {
- result = T;
- break;
- }
- }
+ if (_stricmp(T->mJoinedContactsWLID[0], szEmail) == 0 && T->mChatID[0] == 0)
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
ThreadData* CMsnProto::MSN_GetThreadByChatId(const TCHAR* chatId)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
ThreadData* T = &sttThreads[i];
if (_tcsicmp(T->mChatID, chatId) == 0)
- {
- result = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
ThreadData* CMsnProto::MSN_GetThreadByTimer(UINT timerId)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
ThreadData* T = &sttThreads[i];
if (T->mType == SERVER_SWITCHBOARD && T->mTimerId == timerId)
- {
- result = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid)
{
- ThreadData *result = NULL;
-
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
@@ -445,43 +415,34 @@ ThreadData* CMsnProto::MSN_GetP2PThreadByContact(const char *wlid) continue;
if (_stricmp(T->mJoinedIdentContactsWLID[0], wlid) == 0)
- {
- result = T;
- break;
- }
+ return T;
}
- if (result == NULL)
- {
- char *szEmail = NULL;
- parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
+ char *szEmail = NULL;
+ parseWLID(NEWSTR_ALLOCA(wlid), NULL, &szEmail, NULL);
- for (int i=0; i < sttThreads.getCount(); i++)
+ ThreadData *result = NULL;
+ for (int i=0; i < sttThreads.getCount(); i++)
+ {
+ ThreadData* T = &sttThreads[i];
+ if (T->mJoinedContactsWLID.getCount() && !T->mInitialContactWLID &&
+ _stricmp(T->mJoinedContactsWLID[0], szEmail) == 0)
{
- ThreadData* T = &sttThreads[i];
- if (T->mJoinedContactsWLID.getCount() && !T->mInitialContactWLID &&
- _stricmp(T->mJoinedContactsWLID[0], szEmail) == 0)
- {
- if (T->mType == SERVER_P2P_DIRECT)
- {
- result = T;
- break;
- }
- else if (T->mType == SERVER_SWITCHBOARD)
- result = T;
- }
+ if (T->mType == SERVER_P2P_DIRECT)
+ return T;
+
+ if (T->mType == SERVER_SWITCHBOARD)
+ result = T;
}
}
- LeaveCriticalSection(&sttLock);
-
return result;
}
void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid)
{
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
@@ -489,20 +450,17 @@ void CMsnProto::MSN_StartP2PTransferByContact(const char* wlid) if (T->mType == SERVER_FILETRANS && T->hWaitEvent != INVALID_HANDLE_VALUE)
{
if ((T->mInitialContactWLID && !_stricmp(T->mInitialContactWLID, wlid)) ||
- (T->mJoinedContactsWLID.getCount() && !_stricmp(T->mJoinedContactsWLID[0], wlid)) ||
- (T->mJoinedIdentContactsWLID.getCount() && !_stricmp(T->mJoinedIdentContactsWLID[0], wlid)))
+ (T->mJoinedContactsWLID.getCount() && !_stricmp(T->mJoinedContactsWLID[0], wlid)) ||
+ (T->mJoinedIdentContactsWLID.getCount() && !_stricmp(T->mJoinedIdentContactsWLID[0], wlid)))
ReleaseSemaphore(T->hWaitEvent, 1, NULL);
}
}
-
- LeaveCriticalSection(&sttLock);
}
ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
@@ -511,20 +469,15 @@ ThreadData* CMsnProto::MSN_GetOtherContactThread(ThreadData* thread) continue;
if (T != thread && _stricmp(T->mJoinedContactsWLID[0], thread->mJoinedContactsWLID[0]) == 0)
- {
- result = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
char* szEmail = (char*)wlid;
@@ -535,14 +488,10 @@ ThreadData* CMsnProto::MSN_GetUnconnectedThread(const char* wlid, TInfoType type {
ThreadData* T = &sttThreads[i];
if (T->mType == type && T->mInitialContactWLID && _stricmp(T->mInitialContactWLID, szEmail) == 0)
- {
- result = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
@@ -559,8 +508,7 @@ ThreadData* CMsnProto::MSN_StartSB(const char* wlid, bool& isOffline) if (MSN_GetUnconnectedThread(wlid) == NULL && MsgQueue_CheckContact(wlid, 5) == NULL)
msnNsThread->sendPacket("XFR", "SB");
}
- else
- isOffline = true;
+ else isOffline = true;
}
return thread;
}
@@ -570,7 +518,7 @@ ThreadData* CMsnProto::MSN_StartSB(const char* wlid, bool& isOffline) int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult)
{
int tCount = 0;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
@@ -579,46 +527,35 @@ int CMsnProto::MSN_GetActiveThreads(ThreadData** parResult) parResult[tCount++] = T;
}
- LeaveCriticalSection(&sttLock);
return tCount;
}
ThreadData* CMsnProto::MSN_GetThreadByConnection(HANDLE s)
{
- ThreadData* tResult = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
- for (int i=0; i < sttThreads.getCount(); i++)
+ for (int i = 0; i < sttThreads.getCount(); i++)
{
ThreadData* T = &sttThreads[i];
if (T->s == s)
- {
- tResult = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return tResult;
+ return NULL;
}
ThreadData* CMsnProto::MSN_GetThreadByPort(WORD wPort)
{
- ThreadData* result = NULL;
- EnterCriticalSection(&sttLock);
+ mir_cslock lck(csThreads);
for (int i=0; i < sttThreads.getCount(); i++)
{
ThreadData* T = &sttThreads[i];
if (T->mIncomingPort == wPort)
- {
- result = T;
- break;
- }
+ return T;
}
- LeaveCriticalSection(&sttLock);
- return result;
+ return NULL;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -680,9 +617,9 @@ ThreadData::~ThreadData() if (proto && mType == SERVER_P2P_DIRECT)
proto->p2p_clearDormantSessions();
- if (wlid != NULL && mType == SERVER_SWITCHBOARD &&
- proto->MSN_GetThreadByContact(wlid) == NULL &&
- proto->MSN_GetUnconnectedThread(wlid) == NULL)
+ if (wlid != NULL && mType == SERVER_SWITCHBOARD &&
+ proto->MSN_GetThreadByContact(wlid) == NULL &&
+ proto->MSN_GetUnconnectedThread(wlid) == NULL)
{
proto->MsgQueue_Clear(wlid, true);
}
@@ -758,10 +695,10 @@ void __cdecl CMsnProto::ThreadStub(void* arg) (this->*(info->mFunc))(info);
debugLogA("Leaving thread %08X (%08X)", GetCurrentThreadId(), info->mFunc);
-
- EnterCriticalSection(&sttLock);
- sttThreads.LIST<ThreadData>::remove(info);
- LeaveCriticalSection(&sttLock);
+ {
+ mir_cslock lck(csThreads);
+ sttThreads.LIST<ThreadData>::remove(info);
+ }
delete info;
}
@@ -769,11 +706,10 @@ void ThreadData::startThread(MsnThreadFunc parFunc, CMsnProto *prt) {
mFunc = parFunc;
proto = prt;
-
- EnterCriticalSection(&proto->sttLock);
- proto->sttThreads.insert(this);
- LeaveCriticalSection(&proto->sttLock);
-
+ {
+ mir_cslock lck(prt->csThreads);
+ proto->sttThreads.insert(this);
+ }
proto->ForkThread(&CMsnProto::ThreadStub, this);
}
@@ -795,8 +731,7 @@ HReadBuffer::~HReadBuffer() memmove(buffer, buffer + startOffset, (totalDataSize -= startOffset));
owner->mBytesInData = (int)totalDataSize;
}
- else
- owner->mBytesInData = 0;
+ else owner->mBytesInData = 0;
}
BYTE* HReadBuffer::surelyRead(size_t parBytes)
diff --git a/protocols/MSN/src/version.h b/protocols/MSN/src/version.h index 5730b096e0..f3f5952fe3 100644 --- a/protocols/MSN/src/version.h +++ b/protocols/MSN/src/version.h @@ -20,8 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define __MAJOR_VERSION 0
#define __MINOR_VERSION 11
-#define __RELEASE_NUM 0
-#define __BUILD_NUM 3
+#define __RELEASE_NUM 1
+#define __BUILD_NUM 1
#include <stdver.h>
|