summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/server.cpp13
-rw-r--r--protocols/FacebookRM/src/process.cpp20
-rw-r--r--protocols/IcqOscarJ/src/fam_04message.cpp17
-rw-r--r--protocols/IcqOscarJ/src/fam_13servclist.cpp37
-rw-r--r--protocols/JabberG/src/jabber_misc.cpp19
-rwxr-xr-xprotocols/JabberG/src/jabber_proto.cpp33
-rw-r--r--protocols/MRA/src/MraProto.cpp35
-rw-r--r--protocols/MSN/src/msn_misc.cpp25
-rw-r--r--protocols/MSN/src/msn_proto.cpp40
-rw-r--r--protocols/SkypeWeb/src/skype_proto.cpp2
-rw-r--r--protocols/SkypeWeb/src/skype_utils.h58
-rw-r--r--protocols/Steam/src/steam_contacts.cpp24
-rw-r--r--protocols/Tlen/src/tlen_misc.cpp31
-rw-r--r--protocols/Tlen/src/tlen_svc.cpp32
-rw-r--r--protocols/Tox/src/tox_contacts.cpp20
-rw-r--r--protocols/VKontakte/src/misc.cpp38
16 files changed, 106 insertions, 338 deletions
diff --git a/protocols/Discord/src/server.cpp b/protocols/Discord/src/server.cpp
index 858be58c55..0b7c59fa9a 100644
--- a/protocols/Discord/src/server.cpp
+++ b/protocols/Discord/src/server.cpp
@@ -116,10 +116,21 @@ void CDiscordProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpReques
setId(hContact, DB_KEY_ID, m_ownId);
setByte(hContact, DB_KEY_MFA, root["mfa_enabled"].as_bool());
- setDword(hContact, DB_KEY_DISCR, root["discriminator"].as_int());
+ setDword(hContact, DB_KEY_DISCR, _wtoi(root["discriminator"].as_mstring()));
setWString(hContact, DB_KEY_NICK, root["username"].as_mstring());
setWString(hContact, DB_KEY_EMAIL, root["email"].as_mstring());
+ switch (root["type"].as_int()) {
+ case 1: // confirmed
+ db_unset(hContact, "CList", "NotOnList");
+ break;
+
+ case 3: // expecting autorization
+ db_set_b(hContact, "CList", "NotOnList", 1);
+ break;
+ }
+
+
CMStringW wszNewAvatar(root["avatar"].as_mstring());
setWString(hContact, DB_KEY_AVHASH, wszNewAvatar);
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 91124a04ab..e9aded49e9 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -1099,31 +1099,21 @@ void FacebookProto::ProcessFriendRequests(void*)
isNew = true;
setString(hContact, "RequestTime", time.c_str());
- //blob is: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
- //blob is: 0(DWORD), hContact(HANDLE), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
+ DB_AUTH_BLOB blob(hContact, fbu.real_name.c_str(), 0, 0, fbu.user_id.c_str(), reason.c_str());
+
DBEVENTINFO dbei = { 0 };
dbei.cbSize = sizeof(DBEVENTINFO);
dbei.szModule = m_szModuleName;
dbei.timestamp = ::time(NULL);
dbei.flags = DBEF_UTF;
dbei.eventType = EVENTTYPE_AUTHREQUEST;
- dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + fbu.real_name.length() + fbu.user_id.length() + reason.length() + 5);
-
- PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
- *(PDWORD)pCurBlob = 0; pCurBlob += sizeof(DWORD); // UID
- *(PDWORD)pCurBlob = (DWORD)hContact; pCurBlob += sizeof(DWORD); // Contact Handle
- mir_strcpy((char*)pCurBlob, fbu.real_name.data()); pCurBlob += fbu.real_name.length() + 1; // Nickname
- *pCurBlob = '\0'; pCurBlob++; // First Name
- *pCurBlob = '\0'; pCurBlob++; // Last Name
- mir_strcpy((char*)pCurBlob, fbu.user_id.data()); pCurBlob += fbu.user_id.length() + 1; // E-mail (we use it for string ID)
- mir_strcpy((char*)pCurBlob, reason.data()); pCurBlob += reason.length() + 1; // Reason (we use it for info about common friends)
-
+ dbei.cbBlob = blob.size();
+ dbei.pBlob = blob;
db_event_add(0, &dbei);
}
debugLogA(" < (%s) Friendship request [%s]", (isNew ? "New" : "Old"), time.c_str());
- } else {
- debugLogA("!!! Wrong friendship request:\n%s", req.c_str());
}
+ else debugLogA("!!! Wrong friendship request:\n%s", req.c_str());
}
facy.handle_success("friendRequests");
diff --git a/protocols/IcqOscarJ/src/fam_04message.cpp b/protocols/IcqOscarJ/src/fam_04message.cpp
index 1d2b182bd9..ff2438da29 100644
--- a/protocols/IcqOscarJ/src/fam_04message.cpp
+++ b/protocols/IcqOscarJ/src/fam_04message.cpp
@@ -1627,20 +1627,13 @@ void CIcqProto::handleMessageTypes(DWORD dwUin, char *szUID, DWORD dwTimestamp,
break;
}
{
+ DB_AUTH_BLOB blob(hContact, pszMsgField[0], pszMsgField[1], pszMsgField[2], pszMsgField[3], pszMsgField[5]);
+ *(PBYTE)blob = dwUin;
+
PROTORECVEVENT pre = { 0 };
pre.timestamp = dwTimestamp;
- pre.lParam = sizeof(DWORD) * 2 + mir_strlen(pszMsgField[0]) + mir_strlen(pszMsgField[1]) + mir_strlen(pszMsgField[2]) + mir_strlen(pszMsgField[3]) + mir_strlen(pszMsgField[5]) + 5;
-
- // blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
- char *szBlob, *pCurBlob = szBlob = (char *)_alloca(pre.lParam);
- *(DWORD*)pCurBlob = dwUin; pCurBlob += sizeof(DWORD);
- *(DWORD*)pCurBlob = DWORD(hContact); pCurBlob += sizeof(DWORD);
- mir_strcpy((char*)pCurBlob, pszMsgField[0]); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- mir_strcpy((char*)pCurBlob, pszMsgField[1]); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- mir_strcpy((char*)pCurBlob, pszMsgField[2]); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- mir_strcpy((char*)pCurBlob, pszMsgField[3]); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- mir_strcpy((char*)pCurBlob, pszMsgField[5]);
- pre.szMessage = (char *)szBlob;
+ pre.lParam = blob.size();
+ pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
}
break;
diff --git a/protocols/IcqOscarJ/src/fam_13servclist.cpp b/protocols/IcqOscarJ/src/fam_13servclist.cpp
index 3c11e20a7f..3e7b1004db 100644
--- a/protocols/IcqOscarJ/src/fam_13servclist.cpp
+++ b/protocols/IcqOscarJ/src/fam_13servclist.cpp
@@ -1377,53 +1377,30 @@ void CIcqProto::handleRecvAuthRequest(unsigned char *buf, size_t wLen)
int bAdded;
MCONTACT hContact = HContactFromUID(dwUin, szUid, &bAdded);
- PROTORECVEVENT pre = { 0 };
- pre.timestamp = time(NULL);
- pre.lParam = sizeof(DWORD) * 2 + 5;
// Prepare reason
char *szReason = (char*)SAFE_MALLOC(wReasonLen + 1);
- int nReasonLen = 0;
if (szReason) {
memcpy(szReason, buf, wReasonLen);
szReason[wReasonLen] = '\0';
- nReasonLen = (int)mir_strlen(szReason);
}
// Read nick name from DB
- char *szNick = NULL;
+ char *szNick;
if (dwUin)
szNick = getSettingStringUtf(hContact, "Nick", NULL);
else
szNick = null_strdup(szUid);
- size_t nNickLen = mir_strlen(szNick);
-
- pre.lParam += nNickLen + nReasonLen;
+ DB_AUTH_BLOB blob(hContact, szNick, 0, 0, 0, szReason);
+ *(DWORD*)(PBYTE)blob = dwUin;
setByte(hContact, "Grant", 1);
- /*blob is: uin(DWORD), hcontact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)*/
- char *szBlob = (char *)_alloca(pre.lParam);
- char *pCurBlob = szBlob;
- *(DWORD*)pCurBlob = dwUin; pCurBlob += sizeof(DWORD);
- *(DWORD*)pCurBlob = DWORD(hContact); pCurBlob += sizeof(DWORD);
-
- if (nNickLen) { // if we have nick we add it, otherwise keep trailing zero
- memcpy(pCurBlob, szNick, nNickLen);
- pCurBlob += nNickLen;
- }
- *pCurBlob = 0; pCurBlob++; // Nick
- *pCurBlob = 0; pCurBlob++; // FirstName
- *pCurBlob = 0; pCurBlob++; // LastName
- *pCurBlob = 0; pCurBlob++; // email
- if (nReasonLen) {
- memcpy(pCurBlob, szReason, nReasonLen);
- pCurBlob += nReasonLen;
- }
- *pCurBlob = 0; // Reason
- pre.szMessage = szBlob;
-
// TODO: Change for new auth system, include all known informations
+ PROTORECVEVENT pre = { 0 };
+ pre.timestamp = time(NULL);
+ pre.lParam = blob.size();
+ pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
SAFE_FREE(&szNick);
diff --git a/protocols/JabberG/src/jabber_misc.cpp b/protocols/JabberG/src/jabber_misc.cpp
index 6b6d6b9c0c..ed0320d301 100644
--- a/protocols/JabberG/src/jabber_misc.cpp
+++ b/protocols/JabberG/src/jabber_misc.cpp
@@ -48,28 +48,17 @@ void CJabberProto::DBAddAuthRequest(const wchar_t *jid, const wchar_t *nick)
MCONTACT hContact = DBCreateContact(jid, nick, true, true);
delSetting(hContact, "Hidden");
- T2Utf szJid(jid);
- T2Utf szNick(nick);
+ DB_AUTH_BLOB blob(hContact, T2Utf(nick), NULL, NULL, T2Utf(jid), NULL);
- // blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
- // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ)
DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
dbei.szModule = m_szModuleName;
dbei.timestamp = (DWORD)time(NULL);
dbei.flags = DBEF_UTF;
dbei.eventType = EVENTTYPE_AUTHREQUEST;
- dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(szNick) + mir_strlen(szJid) + 5);
- PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
- *((PDWORD)pCurBlob) = 0; pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact; pCurBlob += sizeof(DWORD);
- mir_strcpy((char*)pCurBlob, szNick); pCurBlob += mir_strlen(szNick) + 1;
- *pCurBlob = '\0'; pCurBlob++; //firstName
- *pCurBlob = '\0'; pCurBlob++; //lastName
- mir_strcpy((char*)pCurBlob, szJid); pCurBlob += mir_strlen(szJid) + 1;
- *pCurBlob = '\0'; //reason
-
+ dbei.cbBlob = blob.size();
+ dbei.pBlob = blob;
db_event_add(NULL, &dbei);
- debugLogA("Setup DBAUTHREQUEST with nick='%s' jid='%s'", szNick, szJid);
+ debugLogA("Setup DBAUTHREQUEST with nick='%s' jid='%s'", blob.get_nick(), blob.get_email());
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 9da06d589e..075f2defea 100755
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -340,23 +340,11 @@ MCONTACT __cdecl CJabberProto::AddToListByEvent(int flags, int /*iContact*/, MEV
return NULL;
if (mir_strcmp(dbei.szModule, m_szModuleName))
return NULL;
-
- // EVENTTYPE_CONTACTS is when adding from when we receive contact list (not used in Jabber)
- // EVENTTYPE_ADDED is when adding from when we receive "You are added" (also not used in Jabber)
- // Jabber will only handle the case of EVENTTYPE_AUTHREQUEST
- // EVENTTYPE_AUTHREQUEST is when adding from the authorization request dialog
if (dbei.eventType != EVENTTYPE_AUTHREQUEST)
return NULL;
- char *nick = (char*)(dbei.pBlob + sizeof(DWORD)*2);
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *jid = lastName + mir_strlen(lastName) + 1;
-
- wchar_t *newJid = (dbei.flags & DBEF_UTF) ? mir_utf8decodeW(jid) : mir_a2u(jid);
- MCONTACT hContact = (MCONTACT)AddToListByJID(newJid, flags);
- mir_free(newJid);
- return hContact;
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ return AddToListByJID(ptrW(dbei.getString(blob.get_email())), flags);
}
////////////////////////////////////////////////////////////////////////////////////////
@@ -379,23 +367,18 @@ int CJabberProto::Authorize(MEVENT hDbEvent)
if (mir_strcmp(dbei.szModule, m_szModuleName))
return 1;
- char *nick = (char*)(dbei.pBlob + sizeof(DWORD)*2);
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *jid = lastName + mir_strlen(lastName) + 1;
-
- debugLogW(L"Send 'authorization allowed' to %s", jid);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ debugLogW(L"Send 'authorization allowed' to %s", blob.get_email());
- wchar_t *newJid = (dbei.flags & DBEF_UTF) ? mir_utf8decodeW(jid) : mir_a2u(jid);
+ ptrW newJid(dbei.getString(blob.get_email()));
m_ThreadInfo->send(XmlNode(L"presence") << XATTR(L"to", newJid) << XATTR(L"type", L"subscribed"));
// Automatically add this user to my roster if option is enabled
if (m_options.AutoAdd == TRUE) {
- JABBER_LIST_ITEM *item;
-
- if ((item = ListGetItemPtr(LIST_ROSTER, newJid)) == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
- debugLogW(L"Try adding contact automatically jid = %s", jid);
+ JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, newJid);
+ if (item == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
+ debugLogW(L"Try adding contact automatically jid = %s", blob.get_email());
if (MCONTACT hContact = AddToListByJID(newJid, 0)) {
// Trigger actual add by removing the "NotOnList" added by AddToListByJID()
// See AddToListByJID() and JabberDbSettingChanged().
diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp
index 71b3f23c66..20ac13f3b8 100644
--- a/protocols/MRA/src/MraProto.cpp
+++ b/protocols/MRA/src/MraProto.cpp
@@ -168,11 +168,8 @@ MCONTACT CMraProto::AddToListByEvent(int, int, MEVENT hDbEvent)
!mir_strcmp(dbei.szModule, m_szModuleName) &&
(dbei.eventType == EVENTTYPE_AUTHREQUEST || dbei.eventType == EVENTTYPE_CONTACTS))
{
- char *nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *email = lastName + mir_strlen(lastName) + 1;
- return AddToListByEmail(ptrW(mir_utf8decodeW(email)), ptrW(mir_utf8decodeW(nick)), ptrW(mir_utf8decodeW(firstName)), ptrW(mir_utf8decodeW(lastName)), 0);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ return AddToListByEmail(dbei.getString(blob.get_email()), dbei.getString(blob.get_nick()), dbei.getString(blob.get_firstName()), dbei.getString(blob.get_lastName()), 0);
}
}
return 0;
@@ -189,14 +186,12 @@ int CMraProto::Authorize(MEVENT hDBEvent)
return 1;
dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
- if (db_event_get(hDBEvent, &dbei)) return 1;
- if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
- if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
-
- LPSTR lpszNick = (LPSTR)(dbei.pBlob + sizeof(DWORD) * 2);
- LPSTR lpszFirstName = lpszNick + mir_strlen(lpszNick) + 1;
- LPSTR lpszLastName = lpszFirstName + mir_strlen(lpszFirstName) + 1;
- MraAuthorize(CMStringA(lpszLastName + mir_strlen(lpszLastName) + 1));
+ if (db_event_get(hDBEvent, &dbei)) return 1;
+ if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
+ if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
+
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ MraAuthorize(blob.get_email());
return 0;
}
@@ -209,16 +204,12 @@ int CMraProto::AuthDeny(MEVENT hDBEvent, const wchar_t* szReason)
return 1;
dbei.pBlob = (PBYTE)alloca(dbei.cbBlob);
- if (db_event_get(hDBEvent, &dbei)) return 1;
- if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
- if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
-
- LPSTR lpszNick = (LPSTR)(dbei.pBlob + sizeof(DWORD) * 2);
- LPSTR lpszFirstName = lpszNick + mir_strlen(lpszNick) + 1;
- LPSTR lpszLastName = lpszFirstName + mir_strlen(lpszFirstName) + 1;
- LPSTR szEmail = lpszLastName + mir_strlen(lpszLastName) + 1;
+ if (db_event_get(hDBEvent, &dbei)) return 1;
+ if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1;
+ if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1;
- MraMessage(FALSE, NULL, 0, 0, szEmail, szReason, NULL, 0);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ MraMessage(FALSE, NULL, 0, 0, blob.get_email(), szReason, NULL, 0);
return 0;
}
diff --git a/protocols/MSN/src/msn_misc.cpp b/protocols/MSN/src/msn_misc.cpp
index cc620c1dc1..d4e873b20f 100644
--- a/protocols/MSN/src/msn_misc.cpp
+++ b/protocols/MSN/src/msn_misc.cpp
@@ -81,33 +81,14 @@ char** CMsnProto::GetStatusMsgLoc(int status)
// MSN_AddAuthRequest - adds the authorization event to the database
void CMsnProto::MSN_AddAuthRequest(const char *email, const char *nick, const char *reason)
{
- //blob is: UIN=0(DWORD), hContact(DWORD), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ)
-
MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, true);
- int emaillen = (int)mir_strlen(email);
-
- if (nick == NULL) nick = "";
- int nicklen = (int)mir_strlen(nick);
-
- if (reason == NULL) reason = "";
- int reasonlen = (int)mir_strlen(reason);
+ DB_AUTH_BLOB blob(hContact, nick, 0, 0, email, reason);
PROTORECVEVENT pre = { 0 };
pre.timestamp = (DWORD)time(NULL);
- pre.lParam = sizeof(DWORD) + sizeof(HANDLE) + nicklen + emaillen + 5 + reasonlen;
-
- char* pCurBlob = (char*)alloca(pre.lParam);
- pre.szMessage = pCurBlob;
-
- *(PDWORD)pCurBlob = 0; pCurBlob += sizeof(DWORD); // UID
- *(PDWORD)pCurBlob = (DWORD)hContact; pCurBlob += sizeof(DWORD); // Contact Handle
- mir_strcpy(pCurBlob, nick); pCurBlob += nicklen + 1; // Nickname
- *pCurBlob = '\0'; pCurBlob++; // First Name
- *pCurBlob = '\0'; pCurBlob++; // Last Name
- mir_strcpy(pCurBlob, email); pCurBlob += emaillen + 1; // E-mail
- mir_strcpy(pCurBlob, reason); // Reason
-
+ pre.lParam = blob.size();
+ pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
}
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp
index b93d1a1903..208320aa45 100644
--- a/protocols/MSN/src/msn_proto.cpp
+++ b/protocols/MSN/src/msn_proto.cpp
@@ -276,12 +276,8 @@ MCONTACT __cdecl CMsnProto::AddToListByEvent(int flags, int, MEVENT hDbEvent)
if (mir_strcmp(dbei.szModule, m_szModuleName)) return NULL;
if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return NULL;
- char* nick = (char *)(dbei.pBlob + sizeof(DWORD) * 2);
- char* firstName = nick + mir_strlen(nick) + 1;
- char* lastName = firstName + mir_strlen(firstName) + 1;
- char* email = lastName + mir_strlen(lastName) + 1;
-
- return AddToListByEmail(email, nick, flags);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ return AddToListByEmail(blob.get_email(), blob.get_nick(), flags);
}
int CMsnProto::AuthRecv(MCONTACT, PROTORECVEVENT* pre)
@@ -333,19 +329,16 @@ int CMsnProto::Authorize(MEVENT hDbEvent)
if (mir_strcmp(dbei.szModule, m_szModuleName))
return 1;
- char *nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *email = lastName + mir_strlen(lastName) + 1;
+ DB_AUTH_BLOB blob(dbei.pBlob);
- MCONTACT hContact = MSN_HContactFromEmail(email, nick, true, 0);
- int netId = Lists_GetNetId(email);
+ MCONTACT hContact = MSN_HContactFromEmail(blob.get_email(), blob.get_nick(), true, 0);
+ int netId = Lists_GetNetId(blob.get_email());
- MSN_AddUser(hContact, email, netId, LIST_AL);
- MSN_AddUser(hContact, email, netId, LIST_BL + LIST_REMOVE);
- MSN_AddUser(hContact, email, netId, LIST_PL + LIST_REMOVE);
+ MSN_AddUser(hContact, blob.get_email(), netId, LIST_AL);
+ MSN_AddUser(hContact, blob.get_email(), netId, LIST_BL + LIST_REMOVE);
+ MSN_AddUser(hContact, blob.get_email(), netId, LIST_PL + LIST_REMOVE);
- MSN_SetContactDb(hContact, email);
+ MSN_SetContactDb(hContact, blob.get_email());
return 0;
}
@@ -369,22 +362,19 @@ int CMsnProto::AuthDeny(MEVENT hDbEvent, const wchar_t*)
if (mir_strcmp(dbei.szModule, m_szModuleName))
return 1;
- char* nick = (char*)(dbei.pBlob + sizeof(DWORD) * 2);
- char* firstName = nick + mir_strlen(nick) + 1;
- char* lastName = firstName + mir_strlen(firstName) + 1;
- char* email = lastName + mir_strlen(lastName) + 1;
+ DB_AUTH_BLOB blob(dbei.pBlob);
- MsnContact* msc = Lists_Get(email);
+ MsnContact* msc = Lists_Get(blob.get_email());
if (msc == NULL) return 0;
- MSN_AddUser(NULL, email, msc->netId, LIST_PL + LIST_REMOVE);
- MSN_AddUser(NULL, email, msc->netId, LIST_BL);
- MSN_AddUser(NULL, email, msc->netId, LIST_RL);
+ MSN_AddUser(NULL, blob.get_email(), msc->netId, LIST_PL + LIST_REMOVE);
+ MSN_AddUser(NULL, blob.get_email(), msc->netId, LIST_BL);
+ MSN_AddUser(NULL, blob.get_email(), msc->netId, LIST_RL);
if (!(msc->list & (LIST_FL | LIST_LL))) {
if (msc->hContact) db_delete_contact(msc->hContact);
msc->hContact = NULL;
- MCONTACT hContact = MSN_HContactFromEmail(email);
+ MCONTACT hContact = MSN_HContactFromEmail(blob.get_email());
if (hContact) db_delete_contact(hContact);
}
diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp
index feaee28f15..275d8b0e2a 100644
--- a/protocols/SkypeWeb/src/skype_proto.cpp
+++ b/protocols/SkypeWeb/src/skype_proto.cpp
@@ -175,7 +175,7 @@ MCONTACT CSkypeProto::AddToListByEvent(int, int, MEVENT hDbEvent)
DB_AUTH_BLOB blob(dbei.pBlob);
- MCONTACT hContact = AddContact(ptrA(blob.get_id()));
+ MCONTACT hContact = AddContact(blob.get_email());
return hContact;
}
diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h
index b6d847e677..ec5e386af8 100644
--- a/protocols/SkypeWeb/src/skype_utils.h
+++ b/protocols/SkypeWeb/src/skype_utils.h
@@ -18,64 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef _UTILS_H_
#define _UTILS_H_
-class DB_AUTH_BLOB
-{
- MCONTACT hContact;
- ptrA szNick, szFirstName, szLastName, szId, szReason;
-
- PBYTE makeBlob()
- {
- size_t size = this->size();
-
- /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_calloc(size);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
-
- if (szNick) { mir_strcpy((char*)pCurBlob, szNick ); pCurBlob += mir_strlen(szNick ); } pCurBlob++;
- if (szFirstName){ mir_strcpy((char*)pCurBlob, szFirstName); pCurBlob += mir_strlen(szFirstName); } pCurBlob++;
- if (szLastName) { mir_strcpy((char*)pCurBlob, szLastName ); pCurBlob += mir_strlen(szLastName ); } pCurBlob++;
- if (szId) { mir_strcpy((char*)pCurBlob, szId ); pCurBlob += mir_strlen(szId ); } pCurBlob++;
- if (szReason) { mir_strcpy((char*)pCurBlob, szReason ); pCurBlob += mir_strlen(szReason ); } pCurBlob++;
-
- return pBlob;
- }
-
-public:
- __inline explicit
- DB_AUTH_BLOB(MCONTACT _hContact, LPCSTR nick, LPCSTR fname, LPCSTR lname, LPCSTR id, LPCSTR reason)
- : hContact(_hContact), szNick(mir_strdup(nick)), szFirstName(mir_strdup(fname)), szLastName(mir_strdup(lname)), szId(mir_strdup(id)), szReason(mir_strdup(reason)) {}
-
- __inline explicit DB_AUTH_BLOB(PBYTE blob)
- {
- PBYTE pCurBlob = blob;
- pCurBlob += sizeof(DWORD);
- hContact = *(PDWORD)pCurBlob;
- pCurBlob += sizeof(DWORD);
- szNick = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- szFirstName = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- szLastName = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- szId = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
- szReason = mir_strdup((char*)pCurBlob);
- }
-
- __inline size_t size(){ return ((sizeof(DWORD) * 2) + (mir_strlen(szNick) + 1) + (mir_strlen(szFirstName) + 1) + (mir_strlen(szLastName) + 1) + (mir_strlen(szId) + 1) + (mir_strlen(szReason) + 1)); }
-
- __inline operator char*(){ return (char*)makeBlob(); };
- __inline operator BYTE*(){ return makeBlob(); };
-
- __inline MCONTACT get_hcontact() { return hContact; }
- __inline char *get_nick() { return mir_strdup(szNick); }
- __inline char *get_firstname() { return mir_strdup(szFirstName); }
- __inline char *get_lastname() { return mir_strdup(szLastName); }
- __inline char *get_id() { return mir_strdup(szId); }
- __inline char *get_reason() { return mir_strdup(szReason); }
-};
-
class EventHandle
{
HANDLE _hEvent;
diff --git a/protocols/Steam/src/steam_contacts.cpp b/protocols/Steam/src/steam_contacts.cpp
index 92a0bb5c63..efb76d7142 100644
--- a/protocols/Steam/src/steam_contacts.cpp
+++ b/protocols/Steam/src/steam_contacts.cpp
@@ -332,30 +332,12 @@ void CSteamProto::ContactIsAskingAuth(MCONTACT hContact)
char reason[MAX_PATH];
mir_snprintf(reason, Translate("%s has added you to his or her Friend List"), nickName);
- // blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), sid(ASCIIZ), reason(ASCIIZ)
- DWORD cbBlob = (DWORD)(sizeof(DWORD)* 2 + mir_strlen(nickName) + mir_strlen(firstName) + mir_strlen(lastName) + mir_strlen(steamId) + mir_strlen(reason) + 5);
-
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_alloc(cbBlob);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
- mir_strcpy((char*)pCurBlob, nickName);
- pCurBlob += mir_strlen(nickName) + 1;
- mir_strcpy((char*)pCurBlob, firstName);
- pCurBlob += mir_strlen(firstName) + 1;
- mir_strcpy((char*)pCurBlob, lastName);
- pCurBlob += mir_strlen(lastName) + 1;
- mir_strcpy((char*)pCurBlob, steamId);
- pCurBlob += mir_strlen(steamId) + 1;
- mir_strcpy((char*)pCurBlob, reason);
+ DB_AUTH_BLOB blob(hContact, nickName, firstName, lastName, steamId, reason);
PROTORECVEVENT recv = { 0 };
recv.timestamp = time(NULL);
- recv.szMessage = (char*)pBlob;
- recv.lParam = cbBlob;
+ recv.szMessage = blob;
+ recv.lParam = blob.size();
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&recv);
// remember to not create this event again, unless authorization status changes again
diff --git a/protocols/Tlen/src/tlen_misc.cpp b/protocols/Tlen/src/tlen_misc.cpp
index 48f2bf617a..edf15ab1c6 100644
--- a/protocols/Tlen/src/tlen_misc.cpp
+++ b/protocols/Tlen/src/tlen_misc.cpp
@@ -38,38 +38,23 @@ void TlenDBAddEvent(TlenProtocol *proto, MCONTACT hContact, int eventType, DWORD
void TlenDBAddAuthRequest(TlenProtocol *proto, char *jid, char *nick)
{
- char *s;
- PBYTE pCurBlob;
- PBYTE pBlob;
- DWORD cbBlob;
- MCONTACT hContact;
-
- if ((hContact=TlenHContactFromJID(proto, jid)) == NULL) {
+ MCONTACT hContact = TlenHContactFromJID(proto, jid);
+ if (hContact == NULL) {
hContact = db_add_contact();
Proto_AddToContact(hContact, proto->m_szModuleName);
// strip resource if present
- s = TlenLoginFromJID(jid);
+ char *s = TlenLoginFromJID(jid);
_strlwr(s);
db_set_s(hContact, proto->m_szModuleName, "jid", s);
mir_free(s);
}
- else {
- db_unset(hContact, proto->m_szModuleName, "Hidden");
- }
+ else db_unset(hContact, proto->m_szModuleName, "Hidden");
+
db_set_s(hContact, proto->m_szModuleName, "Nick", nick);
+
proto->debugLogA("auth request: %s, %s", jid, nick);
- //blob is: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
- //blob is: 0(DWORD), hContact(HANDLE), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), email(ASCIIZ), ""(ASCIIZ)
- cbBlob = sizeof(DWORD) + sizeof(HANDLE) + (int)mir_strlen(nick) + (int)mir_strlen(jid) + 5;
- pBlob = pCurBlob = (PBYTE) mir_alloc(cbBlob);
- *((PDWORD)pCurBlob) = 0; pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact; pCurBlob += sizeof(DWORD);
- mir_strcpy((char *) pCurBlob, nick); pCurBlob += mir_strlen(nick)+1;
- *pCurBlob = '\0'; pCurBlob++; //firstName
- *pCurBlob = '\0'; pCurBlob++; //lastName
- mir_strcpy((char *) pCurBlob, jid); pCurBlob += mir_strlen(jid)+1;
- *pCurBlob = '\0'; //reason
- TlenDBAddEvent(proto, NULL, EVENTTYPE_AUTHREQUEST, 0, pBlob, cbBlob);
+ DB_AUTH_BLOB blob(hContact, nick, 0, 0, jid, 0);
+ TlenDBAddEvent(proto, NULL, EVENTTYPE_AUTHREQUEST, 0, blob, blob.size());
}
char *TlenJIDFromHContact(TlenProtocol *proto, MCONTACT hContact)
diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp
index 25442c0dba..2ec63b93f3 100644
--- a/protocols/Tlen/src/tlen_svc.cpp
+++ b/protocols/Tlen/src/tlen_svc.cpp
@@ -251,12 +251,8 @@ MCONTACT TlenProtocol::AddToListByEvent(int flags, int, MEVENT hDbEvent)
return NULL;
}
- char *nick = (char *)dbei.pBlob + sizeof(DWORD) * 2;
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *jid = lastName + mir_strlen(lastName) + 1;
-
- MCONTACT hContact = (MCONTACT)AddToListByJID(this, jid, flags);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ MCONTACT hContact = (MCONTACT)AddToListByJID(this, blob.get_email(), flags);
mir_free(dbei.pBlob);
return hContact;
}
@@ -284,21 +280,17 @@ int TlenProtocol::Authorize(MEVENT hDbEvent)
return 1;
}
- char *nick = (char *)dbei.pBlob + sizeof(DWORD) * 2;
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *jid = lastName + mir_strlen(lastName) + 1;
-
- TlenSend(this, "<presence to='%s' type='subscribed'/>", jid);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ TlenSend(this, "<presence to='%s' type='subscribed'/>", blob.get_email());
// Automatically add this user to my roster if option is enabled
if (db_get_b(NULL, m_szModuleName, "AutoAdd", TRUE) == TRUE) {
MCONTACT hContact;
- TLEN_LIST_ITEM *item = TlenListGetItemPtr(this, LIST_ROSTER, jid);
+ TLEN_LIST_ITEM *item = TlenListGetItemPtr(this, LIST_ROSTER, blob.get_email());
if (item == NULL || (item->subscription != SUB_BOTH && item->subscription != SUB_TO)) {
- debugLogA("Try adding contact automatically jid=%s", jid);
- if ((hContact = AddToListByJID(this, jid, 0)) != NULL) {
+ debugLogA("Try adding contact automatically jid=%s", blob.get_email());
+ if ((hContact = AddToListByJID(this, blob.get_email(), 0)) != NULL) {
// Trigger actual add by removing the "NotOnList" added by AddToListByJID()
// See AddToListByJID() and TlenDbSettingChanged().
db_unset(hContact, "CList", "NotOnList");
@@ -333,13 +325,9 @@ int TlenProtocol::AuthDeny(MEVENT hDbEvent, const wchar_t*)
return 1;
}
- char *nick = (char *)dbei.pBlob + sizeof(DWORD) * 2;
- char *firstName = nick + mir_strlen(nick) + 1;
- char *lastName = firstName + mir_strlen(firstName) + 1;
- char *jid = lastName + mir_strlen(lastName) + 1;
-
- TlenSend(this, "<presence to='%s' type='unsubscribed'/>", jid);
- TlenSend(this, "<iq type='set'><query xmlns='jabber:iq:roster'><item jid='%s' subscription='remove'/></query></iq>", jid);
+ DB_AUTH_BLOB blob(dbei.pBlob);
+ TlenSend(this, "<presence to='%s' type='unsubscribed'/>", blob.get_email());
+ TlenSend(this, "<iq type='set'><query xmlns='jabber:iq:roster'><item jid='%s' subscription='remove'/></query></iq>", blob.get_email());
mir_free(dbei.pBlob);
return 0;
}
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 4c2f582e41..9cfbd81b00 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -260,24 +260,12 @@ void CToxProto::OnFriendRequest(Tox*, const uint8_t *pubKey, const uint8_t *mess
proto->delSetting(hContact, "Auth");
+ DB_AUTH_BLOB blob(hContact, 0, 0, 0, (LPCSTR)address, (LPCSTR)message);
+
PROTORECVEVENT pre = { 0 };
pre.timestamp = time(NULL);
- pre.lParam = (DWORD)(sizeof(DWORD) * 2 + address.GetLength() + length + 5);
-
- /*blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), firstName(ASCIIZ), lastName(ASCIIZ), id(ASCIIZ), reason(ASCIIZ)*/
- PBYTE pBlob, pCurBlob;
- pCurBlob = pBlob = (PBYTE)mir_calloc(pre.lParam);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD);
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD);
- pCurBlob += 3;
- mir_strcpy((char *)pCurBlob, address);
- pCurBlob += address.GetLength() + 1;
- mir_strcpy((char *)pCurBlob, (char*)message);
- pre.szMessage = (char*)pBlob;
-
+ pre.lParam = blob.size();
+ pre.szMessage = blob;
ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre);
}
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index f8f3bec513..1b01726814 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -551,42 +551,20 @@ void CVkProto::DBAddAuthRequest(const MCONTACT hContact, bool added)
{
debugLogA("CVkProto::DBAddAuthRequest");
- T2Utf szNick(ptrW(db_get_wsa(hContact, m_szModuleName, "Nick")));
- T2Utf szFirstName(ptrW(db_get_wsa(hContact, m_szModuleName, "FirstName")));
- T2Utf szLastName(ptrW(db_get_wsa(hContact, m_szModuleName, "LastName")));
+ DB_AUTH_BLOB blob(hContact,
+ T2Utf(ptrW(db_get_wsa(hContact, m_szModuleName, "Nick"))),
+ T2Utf(ptrW(db_get_wsa(hContact, m_szModuleName, "FirstName"))),
+ T2Utf(ptrW(db_get_wsa(hContact, m_szModuleName, "LastName"))), NULL, NULL);
- //blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
- //blob is: 0(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ)
DBEVENTINFO dbei = { sizeof(DBEVENTINFO) };
dbei.szModule = m_szModuleName;
dbei.timestamp = (DWORD)time(NULL);
dbei.flags = DBEF_UTF;
dbei.eventType = added ? EVENTTYPE_ADDED : EVENTTYPE_AUTHREQUEST;
- dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + mir_strlen(szNick) + mir_strlen(szFirstName) + mir_strlen(szLastName) + 5);
-
- PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
-
- *((PDWORD)pCurBlob) = 0;
- pCurBlob += sizeof(DWORD); // uin(DWORD) = 0 (DWORD)
-
- *((PDWORD)pCurBlob) = (DWORD)hContact;
- pCurBlob += sizeof(DWORD); // hContact(DWORD)
-
- mir_strcpy((char*)pCurBlob, szNick);
- pCurBlob += mir_strlen(szNick) + 1;
-
- mir_strcpy((char*)pCurBlob, szFirstName);
- pCurBlob += mir_strlen(szFirstName) + 1;
-
- mir_strcpy((char*)pCurBlob, szLastName);
- pCurBlob += mir_strlen(szLastName) + 1;
-
- *pCurBlob = '\0'; //email
- pCurBlob++;
- *pCurBlob = '\0'; //reason
-
+ dbei.cbBlob = blob.size();
+ dbei.pBlob = blob;
db_event_add(NULL, &dbei);
- debugLogA("CVkProto::DBAddAuthRequest %s", szNick ? szNick : "<null>");
+ debugLogA("CVkProto::DBAddAuthRequest %s", blob.get_nick() ? blob.get_nick() : "<null>");
}
MCONTACT CVkProto::MContactFromDbEvent(MEVENT hDbEvent)
@@ -1478,7 +1456,7 @@ void CVkProto::AddVkDeactivateEvent(MCONTACT hContact, CMStringW& wszType)
dbei.szModule = m_szModuleName;
dbei.timestamp = time(NULL);
dbei.eventType = VK_USER_DEACTIVATE_ACTION;
- dbei.cbBlob = mir_strlen(vkDeactivateEvent[iDEIdx].szDescription) + 1;
+ dbei.cbBlob = (DWORD)mir_strlen(vkDeactivateEvent[iDEIdx].szDescription) + 1;
dbei.pBlob = (PBYTE)mir_strdup(vkDeactivateEvent[iDEIdx].szDescription);
dbei.flags = DBEF_UTF | (m_vkOptions.bShowVkDeactivateEvents ? 0 : DBEF_READ);
db_event_add(hContact, &dbei);