diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-16 18:20:37 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-16 18:20:37 +0300 |
commit | 6163df27ad6fd2a5da5d9bbb48bb457d8a07a2b6 (patch) | |
tree | d0523b56e1b987789c6622916a31e8f356076d23 /protocols/MSN | |
parent | e021b02022a37bd23b599801026d631f5fd9f48c (diff) |
DB_AUTH_BLOB: handy piece of code moved into the core
Diffstat (limited to 'protocols/MSN')
-rw-r--r-- | protocols/MSN/src/msn_misc.cpp | 25 | ||||
-rw-r--r-- | protocols/MSN/src/msn_proto.cpp | 40 |
2 files changed, 18 insertions, 47 deletions
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);
}
|