From 6163df27ad6fd2a5da5d9bbb48bb457d8a07a2b6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 16 Jan 2017 18:20:37 +0300 Subject: DB_AUTH_BLOB: handy piece of code moved into the core --- protocols/JabberG/src/jabber_misc.cpp | 19 ++++--------------- protocols/JabberG/src/jabber_proto.cpp | 33 ++++++++------------------------- 2 files changed, 12 insertions(+), 40 deletions(-) (limited to 'protocols/JabberG/src') 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(). -- cgit v1.2.3