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/Tlen | |
parent | e021b02022a37bd23b599801026d631f5fd9f48c (diff) |
DB_AUTH_BLOB: handy piece of code moved into the core
Diffstat (limited to 'protocols/Tlen')
-rw-r--r-- | protocols/Tlen/src/tlen_misc.cpp | 31 | ||||
-rw-r--r-- | protocols/Tlen/src/tlen_svc.cpp | 32 |
2 files changed, 18 insertions, 45 deletions
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;
}
|