summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-06-01 13:04:54 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-06-01 13:04:54 +0300
commit9ff6f169d1e2bd5bc139290d4abd6d7573fa6061 (patch)
tree8c2b2f39ba598eff5bf4ba639accab9e2efb1fe2 /protocols
parent5973a828875dc28b81d0a3882180de38984c7ac5 (diff)
fixes #1388 (MSN: crash on "msn_misc.cpp (580): ThreadData::sendPacketPayload")
Diffstat (limited to 'protocols')
-rw-r--r--protocols/MSN/src/msn_commands.cpp278
-rw-r--r--protocols/MSN/src/msn_threads.cpp38
2 files changed, 154 insertions, 162 deletions
diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp
index 088e9acba3..ca757ae153 100644
--- a/protocols/MSN/src/msn_commands.cpp
+++ b/protocols/MSN/src/msn_commands.cpp
@@ -50,8 +50,8 @@ void CMsnProto::MSN_SetMirVer(MCONTACT hContact, MsnPlace *place)
char szVersion[64];
if (!place || !place->client) return;
- mir_snprintf(szVersion, sizeof(szVersion), "%s (%s)",
- MirVerStr[place->client>=sizeof(MirVerStr)/sizeof(MirVerStr[0])?9:place->client-1], place->szClientVer);
+ mir_snprintf(szVersion, sizeof(szVersion), "%s (%s)",
+ MirVerStr[place->client >= sizeof(MirVerStr) / sizeof(MirVerStr[0]) ? 9 : place->client - 1], place->szClientVer);
setString(hContact, "MirVer", szVersion);
setByte(hContact, "StdMirVer", 1);
}
@@ -62,7 +62,8 @@ void CMsnProto::MSN_SetMirVer(MCONTACT hContact, MsnPlace *place)
/////////////////////////////////////////////////////////////////////////////////////////
void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* params)
{
- union {
+ union
+ {
char* tWords[6];
struct { char *fromEmail, *fromNick, *strMsgBytes; } data;
struct { char *fromEmail, *fromNetId, *toEmail, *toNetId, *typeId, *strMsgBytes; } datau;
@@ -108,7 +109,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
stripColorCode(nick);
}
- char* msg = (char*)alloca(msgBytes+1);
+ char* msg = (char*)alloca(msgBytes + 1);
HReadBuffer buf(info, 0);
BYTE* msgb = buf.surelyRead(msgBytes);
@@ -117,7 +118,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
memcpy(msg, msgb, msgBytes);
msg[msgBytes] = 0;
- debugLogA("Message:\n%s", msg);
+ debugLogA("Message:\n%s", msg);
MimeHeaders tHeader;
char* msgBody = tHeader.readFromBuffer(msg);
@@ -133,7 +134,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
msgBody = tHeader.readFromBuffer(msgBody);
if (!(email = NEWSTR_ALLOCA(tHeader["From"]))) return;
mChatID = mir_a2u(tHeader["To"]);
- if (wcsncmp(mChatID, L"19:", 3)) mChatID[0]=0; // NETID_THREAD
+ if (wcsncmp(mChatID, L"19:", 3)) mChatID[0] = 0; // NETID_THREAD
msgBody = tHeader.readFromBuffer(msgBody);
msgBody = tHeader.readFromBuffer(msgBody);
nick = NEWSTR_ALLOCA(tHeader["IM-Display-Name"]);
@@ -147,7 +148,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
else mChatID = info->mChatID;
const char* tMsgId = tHeader["Message-ID"];
- if (tMsgId) lastMsgId=_atoi64(tMsgId);
+ if (tMsgId) lastMsgId = _atoi64(tMsgId);
// Chunked message
char* newbody = nullptr;
@@ -213,14 +214,13 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
int cnt;
PROTOSEARCHRESULT **psr;
- for (c = ezxml_child(xmli, "c"), cnt=0; c; c = c->next) cnt++;
+ for (c = ezxml_child(xmli, "c"), cnt = 0; c; c = c->next) cnt++;
if (psr = (PROTOSEARCHRESULT**)mir_calloc(sizeof(PROTOSEARCHRESULT*) * cnt)) {
- cnt=0;
+ cnt = 0;
for (c = ezxml_child(xmli, "c"); c; c = c->next) {
const char *t = ezxml_attr(c, "t"), *wlid;
if (t && (wlid = ezxml_attr(c, t))) {
- switch (*t)
- {
+ switch (*t) {
case 's':
case 'p':
psr[cnt] = (PROTOSEARCHRESULT*)mir_calloc(sizeof(PROTOSEARCHRESULT));
@@ -237,7 +237,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
pre.szMessage = (char *)psr;
pre.lParam = cnt;
ProtoChainRecv(hContact, PSR_CONTACTS, 0, (LPARAM)&pre);
- for (cnt=0; cnt<pre.lParam; cnt++) {
+ for (cnt = 0; cnt < pre.lParam; cnt++) {
mir_free(psr[cnt]->email.w);
mir_free(psr[cnt]);
}
@@ -248,7 +248,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
ezxml_free(xmli);
}
}
- else if (!_stricmp(tHeader["Message-Type"], "Control/Typing"))
+ else if (!_stricmp(tHeader["Message-Type"], "Control/Typing"))
CallService(MS_PROTO_CONTACTISTYPING, hContact, 7);
else if (!_stricmp(tHeader["Message-Type"], "Control/ClearTyping"))
CallService(MS_PROTO_CONTACTISTYPING, hContact, 0);
@@ -258,7 +258,7 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
/*if (info->mJoinedContactsWLID.getCount() > 1)
MSN_ChatStart(info);
- else */{
+ else */ {
char *szNet, *szEmail;
parseWLID(NEWSTR_ALLOCA(email), &szNet, &szEmail, nullptr);
sentMsg = _stricmp(szEmail, GetMyUsername(atoi(szNet))) == 0;
@@ -327,35 +327,35 @@ void CMsnProto::MSN_ReceiveMessage(ThreadData* info, char* cmdString, char* para
}
}
else if (!_strnicmp(tContentType, "text/x-msmsgscontrol", 20) ||
- (sdgMsg && !_strnicmp(tContentType, "Application/Message", 19))) {
- const char* tTypingUser = sdgMsg?email:tHeader["TypingUser"];
+ (sdgMsg && !_strnicmp(tContentType, "Application/Message", 19))) {
+ const char* tTypingUser = sdgMsg ? email : tHeader["TypingUser"];
if (tTypingUser != nullptr && info->mChatID[0] == 0 && _stricmp(email, MyOptions.szEmail)) {
MCONTACT hContact = MSN_HContactFromEmail(tTypingUser, tTypingUser);
- CallService(MS_PROTO_CONTACTISTYPING, hContact,
- sdgMsg && !_stricmp(tHeader["Message-Type"], "Control/ClearTyping")?0:7);
+ CallService(MS_PROTO_CONTACTISTYPING, hContact,
+ sdgMsg && !_stricmp(tHeader["Message-Type"], "Control/ClearTyping") ? 0 : 7);
}
}
else if (!_strnicmp(tContentType, "text/x-msnmsgr-datacast", 23)) {
//if (info->mJoinedContactsWLID.getCount()) {
- MCONTACT tContact;
-
- if (mChatID[0]) {
- GC_INFO gci = { 0 };
- gci.Flags = GCF_HCONTACT;
- gci.pszModule = m_szModuleName;
- gci.pszID = mChatID;
- Chat_GetInfo(&gci);
- tContact = gci.hContact;
- }
- else tContact = MSN_HContactFromEmail(email, nick, true, true);
- if (!mir_strcmp(tHeader["Message-Type"], "Nudge"))
- NotifyEventHooks(hMSNNudge, (WPARAM)tContact, 0);
- /* Other msg types:
- * Wink
- * Voice
- * Data
- */
+ MCONTACT tContact;
+
+ if (mChatID[0]) {
+ GC_INFO gci = { 0 };
+ gci.Flags = GCF_HCONTACT;
+ gci.pszModule = m_szModuleName;
+ gci.pszID = mChatID;
+ Chat_GetInfo(&gci);
+ tContact = gci.hContact;
+ }
+ else tContact = MSN_HContactFromEmail(email, nick, true, true);
+ if (!mir_strcmp(tHeader["Message-Type"], "Nudge"))
+ NotifyEventHooks(hMSNNudge, (WPARAM)tContact, 0);
+ /* Other msg types:
+ * Wink
+ * Voice
+ * Data
+ */
}
else if (!_strnicmp(tContentType, "text/x-msmsgsemailnotification", 30))
sttNotificationMessage(msgBody, false);
@@ -376,10 +376,10 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
{
const char *pszSkypeToken;
- if ((pszSkypeToken=authSkypeToken.Token()) && xmli) {
+ if ((pszSkypeToken = authSkypeToken.Token()) && xmli) {
/* FIXME: As soon as core has functions to POST images in a conversation AND gives the possibility to supply a
* callback for fetching that image, this may be possible, but currently due to required Auth-Header, this
- * is not possible and we just send an incoming file transfer
+ * is not possible and we just send an incoming file transfer
const char *thumb = ezxml_attr(xmli, "url_thumbnail");
if (thumb && ServiceExists("IEVIEW/NewWindow")) {
// Supply callback to detch thumb with auth-header and embed [img] BB-code?
@@ -409,17 +409,18 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
hHttpsConnection = nlhrReply->nlc;
if (nlhrReply->resultCode == 200) {
char *pLength, *pEnd;
-
- if ((pLength = strstr(nlhrReply->pData, "\"contents\":")) &&
- (pLength = strstr(pLength, "\"length\":")) && (pEnd = strchr(pLength+9, ','))) {
- pLength+=9;
- *pEnd = 0;
- fileSize=_atoi64(pLength);
+
+ if ((pLength = strstr(nlhrReply->pData, "\"contents\":")) &&
+ (pLength = strstr(pLength, "\"length\":")) && (pEnd = strchr(pLength + 9, ','))) {
+ pLength += 9;
+ *pEnd = 0;
+ fileSize = _atoi64(pLength);
}
}
Netlib_FreeHttpRequest(nlhrReply);
- } else hHttpsConnection = nullptr;
+ }
+ else hHttpsConnection = nullptr;
if (fileSize) {
filetransfer* ft = new filetransfer(this);
@@ -431,23 +432,22 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
ft->p2p_appID = MSN_APPID_FILE;
mir_free(ft->std.szCurrentFile.w);
if (!((originalName = ezxml_child(xmli, "OriginalName")) && (pszFile = (char*)ezxml_attr(originalName, "v")))) {
- if ((originalName = ezxml_child(xmli, "meta")))
- {
+ if ((originalName = ezxml_child(xmli, "meta"))) {
char *p;
pszFile = (char*)ezxml_attr(originalName, "originalName");
- if ((p=strrchr(pszFile, '\\')) || (p=strrchr(pszFile, '/'))) pszFile=p+1;
+ if ((p = strrchr(pszFile, '\\')) || (p = strrchr(pszFile, '/'))) pszFile = p + 1;
}
}
if (!pszFile || !*pszFile) {
if ((originalName = ezxml_child(xmli, "meta")) && (pszFile = (char*)ezxml_attr(originalName, "type"))) {
- if (!mir_strcmp(pszFile, "photo")) pszFile="IMG00001.JPG";
+ if (!mir_strcmp(pszFile, "photo")) pszFile = "IMG00001.JPG";
}
- if (!pszFile || !*pszFile) pszFile="file";
+ if (!pszFile || !*pszFile) pszFile = "file";
}
ft->std.szCurrentFile.w = mir_utf8decodeW(pszFile);
ft->std.totalBytes = ft->std.currentFileSize = fileSize;
ft->std.totalFiles = 1;
- ft->szInvcookie = (char*)mir_calloc(strlen(uri)+16);
+ ft->szInvcookie = (char*)mir_calloc(strlen(uri) + 16);
if ((pszType = (char*)ezxml_attr(xmli, "type")) && !mir_strcmp(pszType, "File.1"))
sprintf(ft->szInvcookie, "%s/content/original", uri);
else
@@ -460,12 +460,13 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
pre.dwFlags = PRFF_UNICODE;
pre.fileCount = 1;
pre.timestamp = time(0);
- pre.descr.w = (desc = ezxml_child(xmli, "Description"))?mir_utf8decodeW(desc->txt):tComment;
+ pre.descr.w = (desc = ezxml_child(xmli, "Description")) ? mir_utf8decodeW(desc->txt) : tComment;
pre.files.w = &ft->std.szCurrentFile.w;
pre.lParam = (LPARAM)ft;
ProtoChainRecvFile(ft->std.hContact, &pre);
if (desc) mir_free(pre.descr.w);
- } else uri=nullptr;
+ }
+ else uri = nullptr;
}
if (uri == nullptr) {
@@ -475,7 +476,7 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
PROTORECVEVENT pre = { 0 };
CMStringA msgtxt((char*)ezxml_txt(xmli));
ezxml_t urllnk;
- if (urllnk=ezxml_child(xmli, "a")) msgtxt.AppendFormat(" %s", ezxml_txt(urllnk));
+ if (urllnk = ezxml_child(xmli, "a")) msgtxt.AppendFormat(" %s", ezxml_txt(urllnk));
pre.szMessage = (char*)(const char*)msgtxt;
pre.timestamp = (DWORD)time(0);
ProtoChainRecvMsg(hContact, &pre);
@@ -593,8 +594,7 @@ void CMsnProto::MSN_ProcessNLN(const char *userStatus, const char *wlid, char *u
char *pszUrl, *pszAvatarHash;
if (cmdstring && *cmdstring && mir_strcmp(cmdstring, "0") &&
- (pszAvatarHash = MSN_GetAvatarHash(cmdstring, &pszUrl)))
- {
+ (pszAvatarHash = MSN_GetAvatarHash(cmdstring, &pszUrl))) {
setString(hContact, "PictContext", cmdstring);
setString(hContact, "AvatarHash", pszAvatarHash);
if (pszUrl)
@@ -640,7 +640,7 @@ void CMsnProto::MSN_ProcessStatusMessage(ezxml_t xmli, const char* wlid)
char* szEmail, *szNetId, *szInst;
parseWLID(NEWSTR_ALLOCA(wlid), &szNetId, &szEmail, &szInst);
- bool bHasPSM=false;
+ bool bHasPSM = false;
char* szStatMsg = nullptr;
for (ezxml_t s = ezxml_child(xmli, "s"); s; s = s->next) {
@@ -649,7 +649,8 @@ void CMsnProto::MSN_ProcessStatusMessage(ezxml_t xmli, const char* wlid)
szStatMsg = ezxml_txt(ezxml_child(s, "Mood"));
if (*szStatMsg) db_set_utf(hContact, "CList", "StatusMsg", szStatMsg);
else if (!bHasPSM) db_unset(hContact, "CList", "StatusMsg");
- } else if (!mir_strcmp(n, "PE")) {
+ }
+ else if (!mir_strcmp(n, "PE")) {
szStatMsg = ezxml_txt(ezxml_child(s, "PSM"));
if (*szStatMsg) {
stripBBCode((char*)szStatMsg);
@@ -760,14 +761,15 @@ int CMsnProto::MSN_HandleCommands(ThreadData* info, char* cmdString)
else params = cmdString + 4;
}
- switch((*(PDWORD)cmdString & 0x00FFFFFF) | 0x20000000) {
+ switch ((*(PDWORD)cmdString & 0x00FFFFFF) | 0x20000000) {
case ' SBS':
break;
case ' HTA': //********* ATH: MSNP21+ Authentication
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -782,33 +784,33 @@ LBL_InvalidCommand:
buf.surelyRead(atol(data.strMsgBytes));
if (!bIgnoreATH) {
- if (!bSentBND)
- {
+ if (!bSentBND) {
info->sendPacketPayload("BND", "CON\\MSGR",
"<msgr><ver>%d</ver>%s<client><name>%s</name><ver>%s</ver></client>"
- "<epid>%.*s</epid></msgr>\r\n",
- msnP24Ver, (msnP24Ver>1?"<altVersions><ver>1</ver></altVersions>":""),
- msnStoreAppId, msnProductVer,
- mir_strlen(MyOptions.szMachineGuid)-2, MyOptions.szMachineGuid+1);
+ "<epid>%.*s</epid></msgr>\r\n",
+ msnP24Ver, (msnP24Ver > 1 ? "<altVersions><ver>1</ver></altVersions>" : ""),
+ msnStoreAppId, msnProductVer,
+ mir_strlen(MyOptions.szMachineGuid) - 2, MyOptions.szMachineGuid + 1);
bSentBND = true;
}
- else
- {
+ else {
msnLoggedIn = true;
isConnectSuccess = true;
- emailEnabled = MyOptions.netId==NETID_MSN; // Let's assume it?
+ emailEnabled = MyOptions.netId == NETID_MSN; // Let's assume it?
MSN_SetServerStatus(m_iDesiredStatus);
MSN_EnableMenuItems(true);
// Fork refreshing and populating contact list to the background
ForkThread(&CMsnProto::msn_loginThread, nullptr);
}
- } else bIgnoreATH = false;
+ }
+ else bIgnoreATH = false;
}
break;
case ' DNB': //********* BND: MSNP21+ bind request answer?
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -822,12 +824,11 @@ LBL_InvalidCommand:
if (!msgb) break;
char* msgBody = tHeader.readFromBuffer((char*)msgb);
- replaceStr(msnRegistration,tHeader["Set-Registration"]);
+ replaceStr(msnRegistration, tHeader["Set-Registration"]);
if (!mir_strcmp(data.typeId, "CON")) {
ezxml_t xmlbnd = ezxml_parse_str(msgBody, mir_strlen(msgBody));
ezxml_t xmlbdy = ezxml_child(xmlbnd, "nonce");
- if (xmlbdy)
- {
+ if (xmlbdy) {
char dgst[64];
MSN_MakeDigest(xmlbdy->txt, dgst);
info->sendPacketPayload("PUT", "MSGR\\CHALLENGE",
@@ -841,7 +842,8 @@ LBL_InvalidCommand:
case ' TNC': //********* CNT: Connect, MSNP21+ Authentication
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -853,21 +855,22 @@ LBL_InvalidCommand:
char* msgBody = (char*)buf.surelyRead(atol(data.strMsgBytes));
if (mir_strcmp(data.typeId, "CON")) break;
- if (MyOptions.netId!=NETID_SKYPE) {
+ if (MyOptions.netId != NETID_SKYPE) {
/* MSN account login */
- if (MSN_AuthOAuth()<1) {
+ if (MSN_AuthOAuth() < 1) {
m_iDesiredStatus = ID_STATUS_OFFLINE;
return 1;
}
- } else {
+ }
+ else {
/* Skype username/pass login */
if (!msgBody) break;
ezxml_t xmlcnt = ezxml_parse_str(msgBody, mir_strlen(msgBody));
ezxml_t xmlnonce = ezxml_child(xmlcnt, "nonce");
if (xmlnonce) {
- char szUIC[1024]={0};
+ char szUIC[1024] = { 0 };
MSN_SkypeAuth(xmlnonce->txt, szUIC);
replaceStr(authUIC, szUIC);
@@ -884,7 +887,8 @@ LBL_InvalidCommand:
case ' TEG': //********* GET: MSNP21+ GET reply
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -899,26 +903,24 @@ LBL_InvalidCommand:
char* msgBody = tHeader.readFromBuffer((char*)msgb);
ezxml_t xmli;
- if (tHeader["Set-Registration"]) replaceStr(msnRegistration,tHeader["Set-Registration"]);
- if (xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody)))
- {
- if (!mir_strcmp(xmli->name, "recentconversations-response"))
- {
+ if (tHeader["Set-Registration"]) replaceStr(msnRegistration, tHeader["Set-Registration"]);
+ if (xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody))) {
+ if (!mir_strcmp(xmli->name, "recentconversations-response")) {
for (ezxml_t conv = ezxml_get(xmli, "conversations", 0, "conversation", -1); conv != nullptr; conv = ezxml_next(conv)) {
ezxml_t id;
MCONTACT hContact;
MEVENT hDbEvent;
DWORD ts = 1;
- if (ezxml_get(conv, "messages", 0, "message", -1) && (id=ezxml_child(conv, "id")))
- {
+ if (ezxml_get(conv, "messages", 0, "message", -1) && (id = ezxml_child(conv, "id"))) {
if (strncmp(id->txt, "19:", 3) == 0) {
/* This is a thread (Groupchat)
* Find out about its current state on the server */
hContact = MSN_HContactFromChatID(id->txt);
- msnNsThread->sendPacketPayload("GET", "MSGR\\THREADS",
+ msnNsThread->sendPacketPayload("GET", "MSGR\\THREADS",
"<threads><thread><id>%s</id></thread></threads>", id->txt);
- } else hContact = MSN_HContactFromEmail(id->txt, nullptr, false, false);
+ }
+ else hContact = MSN_HContactFromEmail(id->txt, nullptr, false, false);
if (hContact) {
// There are messages to be fetched
@@ -929,9 +931,9 @@ LBL_InvalidCommand:
}
db_set_dw(hContact, m_szModuleName, "syncTS", ts);
}
- msnNsThread->sendPacketPayload("GET", "MSGR\\MESSAGESBYCONVERSATION",
+ msnNsThread->sendPacketPayload("GET", "MSGR\\MESSAGESBYCONVERSATION",
"<messagesbyconversation><id>%s</id><start>%llu</start><pagesize>100</pagesize></messagesbyconversation>",
- id->txt, ((unsigned __int64)ts)*1000);
+ id->txt, ((unsigned __int64)ts) * 1000);
}
}
}
@@ -939,47 +941,49 @@ LBL_InvalidCommand:
ezxml_t id;
MCONTACT hContact;
- if ((id=ezxml_child(xmli, "id")))
- {
- bool bIsChat = strncmp(id->txt, "19:", 3)==0;
+ if ((id = ezxml_child(xmli, "id"))) {
+ bool bIsChat = strncmp(id->txt, "19:", 3) == 0;
bool bHasMore = mir_strcmpi(ezxml_txt(ezxml_child(xmli, "hasmore")), "true") == 0;
ezxml_t syncstate;
hContact = MSN_HContactFromEmail(id->txt, nullptr, false, false);
if (!bHasMore && hContact) db_unset(hContact, m_szModuleName, "syncTS");
/* We have to traverse the list in reverse order as newest events are on top (which is the opposite direction of Groupchat) */
- LIST<ezxml> msgs(10,PtrKeySortT);
+ LIST<ezxml> msgs(10, PtrKeySortT);
for (ezxml_t msg = ezxml_get(xmli, "messages", 0, "message", -1); msg != nullptr; msg = ezxml_next(msg)) msgs.insert(msg, 0);
for (auto &msg : msgs) {
ezxml_t arrtime = ezxml_child(msg, "originalarrivaltime"), from = ezxml_child(msg, "from"),
- msgtype = ezxml_child(msg, "messagetype"), content = ezxml_child(msg, "content");
+ msgtype = ezxml_child(msg, "messagetype"), content = ezxml_child(msg, "content");
time_t ts;
char *netId, *email, *message;
bool sentMsg;
if (!arrtime || !from || !content) continue;
- ts=IsoToUnixTime(arrtime->txt);
+ ts = IsoToUnixTime(arrtime->txt);
parseWLID(NEWSTR_ALLOCA(from->txt), &netId, &email, nullptr);
- message=content->txt;
- sentMsg = mir_strcmpi(email, GetMyUsername(atoi(netId)))==0;
+ message = content->txt;
+ sentMsg = mir_strcmpi(email, GetMyUsername(atoi(netId))) == 0;
if (msgtype) {
if (!mir_strcmp(msgtype->txt, "RichText")) {
message = NEWSTR_ALLOCA(message);
stripHTML(message);
HtmlDecode(message);
- } else if (!strncmp(msgtype->txt, "ThreadActivity/", 15)) {
+ }
+ else if (!strncmp(msgtype->txt, "ThreadActivity/", 15)) {
if (ezxml_t xmlact = ezxml_parse_str(content->txt, mir_strlen(content->txt))) {
MSN_GCProcessThreadActivity(xmlact, _A2T(id->txt));
ezxml_free(xmlact);
}
continue;
- } else if (!mir_strcmp(msgtype->txt, "RichText/UriObject") || !mir_strcmp(msgtype->txt, "RichText/Media_GenericFile")) {
+ }
+ else if (!mir_strcmp(msgtype->txt, "RichText/UriObject") || !mir_strcmp(msgtype->txt, "RichText/Media_GenericFile")) {
if (ezxml_t xmlact = ezxml_parse_str(content->txt, mir_strlen(content->txt))) {
MSN_ProcessURIObject(hContact, xmlact);
ezxml_free(xmlact);
}
continue;
- } else if (mir_strcmp(msgtype->txt, "Text")) continue; /* TODO: Implement i.e. RichText/Files for announcement of file transfers */
+ }
+ else if (mir_strcmp(msgtype->txt, "Text")) continue; /* TODO: Implement i.e. RichText/Files for announcement of file transfers */
}
if (bIsChat) {
@@ -998,11 +1002,10 @@ LBL_InvalidCommand:
BYTE *pszMsgBuf = (BYTE*)mir_calloc(cbBlob);
if (pszMsgBuf) {
dbei.pBlob = pszMsgBuf;
- for((hDbEvent = db_event_last(hContact));
- !bDuplicate && hDbEvent;
- hDbEvent=db_event_prev(hContact, hDbEvent))
- {
- if (db_event_get(hDbEvent, &dbei) || dbei.timestamp > ts+1 || dbei.timestamp < ts) break;
+ for ((hDbEvent = db_event_last(hContact));
+ !bDuplicate && hDbEvent;
+ hDbEvent = db_event_prev(hContact, hDbEvent)) {
+ if (db_event_get(hDbEvent, &dbei) || dbei.timestamp > ts + 1 || dbei.timestamp < ts) break;
if (!memcmp((char*)dbei.pBlob, message, cbBlob)) bDuplicate = true;
dbei.cbBlob = cbBlob;
}
@@ -1030,9 +1033,9 @@ LBL_InvalidCommand:
}
/* In groupchat it wouldn't make much sense to sync more as older messages are coming now and that would jumble our log */
if (!bIsChat && bHasMore && (syncstate = ezxml_child(xmli, "messagessyncstate"))) {
- msnNsThread->sendPacketPayload("GET", "MSGR\\MESSAGESBYCONVERSATION",
+ msnNsThread->sendPacketPayload("GET", "MSGR\\MESSAGESBYCONVERSATION",
"<messagesbyconversation><id>%s</id><start>%llu</start><messagessyncstate>%s</messagessyncstate><pagesize>100</pagesize></messagesbyconversation>",
- id->txt, ((unsigned __int64)db_get_dw(hContact, m_szModuleName, "syncTS", 1000))*1000, syncstate->txt);
+ id->txt, ((unsigned __int64)db_get_dw(hContact, m_szModuleName, "syncTS", 1000)) * 1000, syncstate->txt);
}
msgs.destroy();
}
@@ -1042,14 +1045,15 @@ LBL_InvalidCommand:
MSN_ChatStart(thread);
}
ezxml_free(xmli);
- }
+ }
}
break;
case ' YFN': //********* NFY: MSNP21+ Notifications
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -1065,7 +1069,8 @@ LBL_InvalidCommand:
mir_snprintf(szParam, sizeof(szParam), "%s %s", data.typeId, data.strMsgBytes);
MSN_ReceiveMessage(info, cmdString, szParam);
break;
- } else if (!mir_strcmp(data.typeId, "MSGR\\ABCH")) {
+ }
+ else if (!mir_strcmp(data.typeId, "MSGR\\ABCH")) {
MimeHeaders tHeader;
msgBody = tHeader.readFromBuffer(msgBody);
MSN_ProcessNotificationMessage(msgBody, mir_strlen(msgBody));
@@ -1076,33 +1081,29 @@ LBL_InvalidCommand:
MimeHeaders tHeader;
int i;
- for (i=0; i<2; i++) msgBody = tHeader.readFromBuffer(msgBody);
+ for (i = 0; i < 2; i++) msgBody = tHeader.readFromBuffer(msgBody);
char *pszTo = nullptr, *pszToNet;
if (tHeader["To"]) parseWLID(NEWSTR_ALLOCA(tHeader["To"]), &pszToNet, &pszTo, nullptr);
- const char *pszFrom = tHeader["From"];
- for (i=0; i<2; i++) msgBody = tHeader.readFromBuffer(msgBody);
+ const char *pszFrom = tHeader["From"];
+ for (i = 0; i < 2; i++) msgBody = tHeader.readFromBuffer(msgBody);
- if (pszFrom)
- {
+ if (pszFrom) {
ezxml_t xmli;
- if (xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody)))
- {
- if (!mir_strcmp(xmli->name, "user"))
- {
+ if (xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody))) {
+ if (!mir_strcmp(xmli->name, "user")) {
ezxml_t xmlstatus = ezxml_get(xmli, "s", 0, "Status", -1);
- /* FIXME: MSGR\DEL: Instance of user with given EPID disconnected, not
+ /* FIXME: MSGR\DEL: Instance of user with given EPID disconnected, not
* sure if this implies that contact is offline now... */
- if (xmlstatus || !mir_strcmp(data.typeId, "MSGR\\DEL"))
- {
+ if (xmlstatus || !mir_strcmp(data.typeId, "MSGR\\DEL")) {
// These capabilities seem to be something different than in previous MSNP versions?
//ezxml_t xmlcaps = ezxml_get(xmli, "sep", 0, "Capabilities", -1);
ezxml_t usertile = ezxml_get(xmli, "s", 1, "UserTileLocation", -1);
- MSN_ProcessNLN(ezxml_txt(xmlstatus), pszFrom, nullptr, nullptr, usertile?usertile->txt:nullptr);
+ MSN_ProcessNLN(ezxml_txt(xmlstatus), pszFrom, nullptr, nullptr, usertile ? usertile->txt : nullptr);
}
MSN_ProcessStatusMessage(xmli, pszFrom);
}
ezxml_free(xmli);
- }
+ }
}
}
else if (!mir_strcmp(data.typeId, "MSGR\\THREAD")) {
@@ -1120,7 +1121,8 @@ LBL_InvalidCommand:
case ' TUP': //******** MSNP21+: PUT notifications
case ' GNP': //******** MSNP21+: PNG reply
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -1134,8 +1136,8 @@ LBL_InvalidCommand:
if (!msgb) break;
char* msgBody = tHeader.readFromBuffer((char*)msgb);
- if (tHeader["Set-Registration"]) replaceStr(msnRegistration,tHeader["Set-Registration"]);
- if (cmdString[1]=='N') { // PNG
+ if (tHeader["Set-Registration"]) replaceStr(msnRegistration, tHeader["Set-Registration"]);
+ if (cmdString[1] == 'N') { // PNG
if (ezxml_t xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody))) {
if (ezxml_t wait = ezxml_child(xmli, "wait")) {
msnPingTimeout = atoi(ezxml_txt(wait));
@@ -1143,8 +1145,9 @@ LBL_InvalidCommand:
SetEvent(hKeepAliveThreadEvt);
}
ezxml_free(xmli);
- }
- } else { // PUT
+ }
+ }
+ else { // PUT
ezxml_t xmli;
if (*msgBody && (xmli = ezxml_parse_str(msgBody, mir_strlen(msgBody)))) {
if (!mir_strcmp(xmli->name, "presence-response")) {
@@ -1152,8 +1155,9 @@ LBL_InvalidCommand:
if ((user = ezxml_child(xmli, "user")) && (from = ezxml_child(xmli, "from"))) {
if (ezxml_t xmlstatus = ezxml_get(user, "s", 0, "Status", -1)) {
ezxml_t usertile = ezxml_get(user, "s", 1, "UserTileLocation", -1);
- MSN_ProcessNLN(ezxml_txt(xmlstatus), from->txt, nullptr, nullptr, usertile?usertile->txt:nullptr);
- } else {
+ MSN_ProcessNLN(ezxml_txt(xmlstatus), from->txt, nullptr, nullptr, usertile ? usertile->txt : nullptr);
+ }
+ else {
int oldMode = m_iStatus;
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)oldMode, m_iStatus);
@@ -1162,7 +1166,7 @@ LBL_InvalidCommand:
}
}
ezxml_free(xmli);
- }
+ }
}
}
break;
@@ -1173,7 +1177,8 @@ LBL_InvalidCommand:
case ' RFX': //******** XFR: sections 7.4 Referral, 8.1 Referral to Switchboard
{
- union {
+ union
+ {
char* tWords[2];
struct { char *typeId, *strMsgBytes; } data;
};
@@ -1189,8 +1194,7 @@ LBL_InvalidCommand:
if (!mir_strcmp(data.typeId, "CON")) {
ezxml_t xmlxfr = ezxml_parse_str(msgBody, mir_strlen(msgBody));
ezxml_t xmltgt = ezxml_child(xmlxfr, "target");
- if (xmltgt)
- {
+ if (xmltgt) {
ThreadData* newThread = new ThreadData;
mir_strcpy(newThread->mServer, xmltgt->txt);
mir_strcpy(newThread->mState, ezxml_txt(ezxml_child(xmlxfr, "state")));
diff --git a/protocols/MSN/src/msn_threads.cpp b/protocols/MSN/src/msn_threads.cpp
index 4f762b02e8..e0db9495fa 100644
--- a/protocols/MSN/src/msn_threads.cpp
+++ b/protocols/MSN/src/msn_threads.cpp
@@ -253,36 +253,24 @@ void __cdecl CMsnProto::MSNServerThread(void* arg)
LBL_Exit:
if (info->mIsMainThread) {
- /*
- if (!isConnectSuccess && !usingGateway && m_iDesiredStatus != ID_STATUS_OFFLINE) {
- msnNsThread = NULL;
- usingGateway = true;
+ msnNsThread = nullptr;
- ThreadData* newThread = new ThreadData;
- newThread->mType = SERVER_NOTIFICATION;
- newThread->mIsMainThread = true;
-
- newThread->startThread(&CMsnProto::MSNServerThread, this);
+ if (hKeepAliveThreadEvt) {
+ msnPingTimeout *= -1;
+ SetEvent(hKeepAliveThreadEvt);
}
- else*/ {
- if (hKeepAliveThreadEvt) {
- msnPingTimeout *= -1;
- SetEvent(hKeepAliveThreadEvt);
- }
-
- if (info->s == nullptr)
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
- else
- MSN_CloseConnections();
- if (hHttpsConnection) {
- Netlib_CloseHandle(hHttpsConnection);
- hHttpsConnection = nullptr;
- }
+ if (info->s == nullptr)
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
+ else
+ MSN_CloseConnections();
- MSN_GoOffline();
- msnNsThread = nullptr;
+ if (hHttpsConnection) {
+ Netlib_CloseHandle(hHttpsConnection);
+ hHttpsConnection = nullptr;
}
+
+ MSN_GoOffline();
}
debugLogA("Thread [%08X] ending now", GetCurrentThreadId());