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 /src | |
parent | e021b02022a37bd23b599801026d631f5fd9f48c (diff) |
DB_AUTH_BLOB: handy piece of code moved into the core
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/db_events.cpp | 97 | ||||
-rw-r--r-- | src/mir_app/src/db_util.cpp | 73 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 15 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 15 | ||||
-rw-r--r-- | src/mir_app/src/netlib.cpp | 2 |
5 files changed, 153 insertions, 49 deletions
diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp index 9bafc0930e..df027c4616 100644 --- a/src/mir_app/src/db_events.cpp +++ b/src/mir_app/src/db_events.cpp @@ -97,7 +97,7 @@ static wchar_t* getEventString(DBEVENTINFO *dbei, LPSTR &buf) {
LPSTR in = buf;
buf += mir_strlen(buf) + 1;
- return (dbei->flags & DBEF_UTF) ? Utf8DecodeT(in) : mir_a2u(in);
+ return (dbei->flags & DBEF_UTF) ? Utf8DecodeW(in) : mir_a2u(in);
}
static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatype)
@@ -113,15 +113,12 @@ static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatyp return 0;
if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) {
- // EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
- // EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
- DWORD uin = *(DWORD*)dbei->pBlob;
- MCONTACT hContact = (MCONTACT)*(DWORD*)(dbei->pBlob + sizeof(DWORD));
- char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2;
- ptrW tszNick(getEventString(dbei, buf));
- ptrW tszFirst(getEventString(dbei, buf));
- ptrW tszLast(getEventString(dbei, buf));
- ptrW tszEmail(getEventString(dbei, buf));
+ DB_AUTH_BLOB blob(dbei->pBlob);
+
+ ptrW tszNick(dbei->getString(blob.get_nick()));
+ ptrW tszFirst(dbei->getString(blob.get_firstName()));
+ ptrW tszLast(dbei->getString(blob.get_lastName()));
+ ptrW tszEmail(dbei->getString(blob.get_email()));
CMStringW nick, text;
if (tszFirst || tszLast) {
@@ -133,21 +130,21 @@ static INT_PTR DbEventGetTextWorker(DBEVENTINFO *dbei, int codepage, int datatyp nick.Append(L", ");
nick.Append(tszEmail);
}
- if (uin != 0) {
+ if (blob.get_uin() != 0) {
if (!nick.IsEmpty())
nick.Append(L", ");
- nick.AppendFormat(L"%d", uin);
+ nick.AppendFormat(L"%d", blob.get_uin());
}
if (!nick.IsEmpty())
nick = L"(" + nick + L")";
if (dbei->eventType == EVENTTYPE_AUTHREQUEST) {
- ptrW tszReason(getEventString(dbei, buf));
+ ptrW tszReason(dbei->getString(blob.get_reason()));
text.Format(TranslateT("Authorization request from %s%s: %s"),
- (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason);
+ (tszNick == NULL) ? cli.pfnGetContactDisplayName(blob.get_contact(), 0) : tszNick, nick, tszReason);
}
else text.Format(TranslateT("You were added by %s%s"),
- (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick);
+ (tszNick == NULL) ? cli.pfnGetContactDisplayName(blob.get_contact(), 0) : tszNick, nick);
return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text);
}
@@ -267,48 +264,52 @@ MIR_APP_DLL(wchar_t*) DbEvent_GetString(DBEVENTINFO *dbei, const char *str) /////////////////////////////////////////////////////////////////////////////////////////
-MIR_APP_DLL(int) Profile_GetPathA(size_t cbLen, char *pszDest)
+DB_AUTH_BLOB::DB_AUTH_BLOB(MCONTACT hContact, LPCSTR nick, LPCSTR fname, LPCSTR lname, LPCSTR email, LPCSTR reason) :
+ m_hContact(hContact),
+ m_szNick(mir_strdup(nick)),
+ m_szFirstName(mir_strdup(fname)),
+ m_szLastName(mir_strdup(lname)),
+ m_szEmail(mir_strdup(email)),
+ m_szReason(mir_strdup(reason))
{
- if (!pszDest || !cbLen)
- return 1;
-
- strncpy_s(pszDest, cbLen, _T2A(g_profileDir), _TRUNCATE);
- return 0;
+ m_size = DWORD(sizeof(DWORD) * 2 + 5 + mir_strlen(m_szNick) + mir_strlen(m_szFirstName) + mir_strlen(m_szLastName) + mir_strlen(m_szEmail) + mir_strlen(m_szReason));
}
-MIR_APP_DLL(int) Profile_GetPathW(size_t cbLen, wchar_t *pwszDest)
+DB_AUTH_BLOB::DB_AUTH_BLOB(PBYTE blob)
{
- if (!pwszDest || !cbLen)
- return 1;
-
- wcsncpy_s(pwszDest, cbLen, g_profileDir, _TRUNCATE);
- return 0;
+ PBYTE pCurBlob = blob;
+ pCurBlob += sizeof(DWORD);
+ m_hContact = *(PDWORD)pCurBlob;
+ pCurBlob += sizeof(DWORD);
+ m_szNick = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
+ m_szFirstName = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
+ m_szLastName = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
+ m_szEmail = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
+ m_szReason = mir_strdup((char*)pCurBlob); pCurBlob += mir_strlen((char*)pCurBlob) + 1;
+ m_size = DWORD(pCurBlob - blob);
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-MIR_APP_DLL(int) Profile_GetNameA(size_t cbLen, char *pszDest)
+DB_AUTH_BLOB::~DB_AUTH_BLOB()
{
- if (!cbLen || !pszDest)
- return 1;
-
- strncpy_s(pszDest, cbLen, ptrA(makeFileName(g_profileName)), _TRUNCATE);
- return 0;
}
-MIR_APP_DLL(int) Profile_GetNameW(size_t cbLen, wchar_t *pwszDest)
+PBYTE DB_AUTH_BLOB::makeBlob()
{
- if (!cbLen || !pwszDest)
- return 1;
-
- wcsncpy_s(pwszDest, cbLen, g_profileName, _TRUNCATE);
- return 0;
+ PBYTE pBlob, pCurBlob;
+ pCurBlob = pBlob = (PBYTE)mir_alloc(m_size + 1);
+
+ *((PDWORD)pCurBlob) = 0;
+ pCurBlob += sizeof(DWORD);
+ *((PDWORD)pCurBlob) = (DWORD)m_hContact;
+ pCurBlob += sizeof(DWORD);
+
+ mir_snprintf((char*)pCurBlob, m_size - 8, "%s%c%s%c%s%c%s%c%s%c",
+ (m_szNick) ? m_szNick : "", 0,
+ (m_szFirstName) ? m_szFirstName : "", 0,
+ (m_szLastName) ? m_szLastName : "", 0,
+ (m_szEmail) ? m_szEmail : "", 0,
+ (m_szReason) ? m_szReason : 0);
+
+ return pBlob;
}
-/////////////////////////////////////////////////////////////////////////////////////////
-
-MIR_APP_DLL(void) Profile_SetDefault(const wchar_t *pwszPath)
-{
- extern wchar_t* g_defaultProfile;
- replaceStrW(g_defaultProfile, pwszPath);
-}
diff --git a/src/mir_app/src/db_util.cpp b/src/mir_app/src/db_util.cpp new file mode 100644 index 0000000000..d9eb2736f5 --- /dev/null +++ b/src/mir_app/src/db_util.cpp @@ -0,0 +1,73 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-17 Miranda NG project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "profilemanager.h" + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Profile_GetPathA(size_t cbLen, char *pszDest) +{ + if (!pszDest || !cbLen) + return 1; + + strncpy_s(pszDest, cbLen, _T2A(g_profileDir), _TRUNCATE); + return 0; +} + +MIR_APP_DLL(int) Profile_GetPathW(size_t cbLen, wchar_t *pwszDest) +{ + if (!pwszDest || !cbLen) + return 1; + + wcsncpy_s(pwszDest, cbLen, g_profileDir, _TRUNCATE); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Profile_GetNameA(size_t cbLen, char *pszDest) +{ + if (!cbLen || !pszDest) + return 1; + + strncpy_s(pszDest, cbLen, ptrA(makeFileName(g_profileName)), _TRUNCATE); + return 0; +} + +MIR_APP_DLL(int) Profile_GetNameW(size_t cbLen, wchar_t *pwszDest) +{ + if (!cbLen || !pwszDest) + return 1; + + wcsncpy_s(pwszDest, cbLen, g_profileName, _TRUNCATE); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(void) Profile_SetDefault(const wchar_t *pwszPath) +{ + extern wchar_t* g_defaultProfile; + replaceStrW(g_defaultProfile, pwszPath); +} diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index cf2ce8a022..5fb730b3d6 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -380,3 +380,18 @@ Netlib_SetHttpProxyInfo @380 Netlib_DestroySecurityProvider @381
Netlib_InitSecurityProvider @382
Netlib_NtlmCreateResponse @383
+??0DB_AUTH_BLOB@@QAE@IPBD0000@Z @384 NONAME
+??0DB_AUTH_BLOB@@QAE@PAE@Z @385 NONAME
+??1DB_AUTH_BLOB@@QAE@XZ @386 NONAME
+??4DB_AUTH_BLOB@@QAEAAV0@ABV0@@Z @387 NONAME
+??BDB_AUTH_BLOB@@QAEPADXZ @388 NONAME
+??BDB_AUTH_BLOB@@QAEPAEXZ @389 NONAME
+?get_contact@DB_AUTH_BLOB@@QBEIXZ @390 NONAME
+?get_email@DB_AUTH_BLOB@@QBEPBDXZ @391 NONAME
+?get_firstName@DB_AUTH_BLOB@@QBEPBDXZ @392 NONAME
+?get_lastName@DB_AUTH_BLOB@@QBEPBDXZ @393 NONAME
+?get_nick@DB_AUTH_BLOB@@QBEPBDXZ @394 NONAME
+?get_reason@DB_AUTH_BLOB@@QBEPBDXZ @395 NONAME
+?get_uin@DB_AUTH_BLOB@@QBEKXZ @396 NONAME
+?makeBlob@DB_AUTH_BLOB@@AAEPAEXZ @397 NONAME
+?size@DB_AUTH_BLOB@@QBEKXZ @398 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index ba931ff6bc..c239ba0fec 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -380,3 +380,18 @@ Netlib_SetHttpProxyInfo @380 Netlib_DestroySecurityProvider @381
Netlib_InitSecurityProvider @382
Netlib_NtlmCreateResponse @383
+??0DB_AUTH_BLOB@@QEAA@IPEBD0000@Z @384 NONAME
+??0DB_AUTH_BLOB@@QEAA@PEAE@Z @385 NONAME
+??1DB_AUTH_BLOB@@QEAA@XZ @386 NONAME
+??4DB_AUTH_BLOB@@QEAAAEAV0@AEBV0@@Z @387 NONAME
+??BDB_AUTH_BLOB@@QEAAPEADXZ @388 NONAME
+??BDB_AUTH_BLOB@@QEAAPEAEXZ @389 NONAME
+?get_contact@DB_AUTH_BLOB@@QEBAIXZ @390 NONAME
+?get_email@DB_AUTH_BLOB@@QEBAPEBDXZ @391 NONAME
+?get_firstName@DB_AUTH_BLOB@@QEBAPEBDXZ @392 NONAME
+?get_lastName@DB_AUTH_BLOB@@QEBAPEBDXZ @393 NONAME
+?get_nick@DB_AUTH_BLOB@@QEBAPEBDXZ @394 NONAME
+?get_reason@DB_AUTH_BLOB@@QEBAPEBDXZ @395 NONAME
+?get_uin@DB_AUTH_BLOB@@QEBAKXZ @396 NONAME
+?makeBlob@DB_AUTH_BLOB@@AEAAPEAEXZ @397 NONAME
+?size@DB_AUTH_BLOB@@QEBAKXZ @398 NONAME
diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp index 4405f265e5..d9531f8156 100644 --- a/src/mir_app/src/netlib.cpp +++ b/src/mir_app/src/netlib.cpp @@ -316,7 +316,7 @@ MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib) /////////////////////////////////////////////////////////////////////////////////////////
-MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HANDLE hConnection)
+MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HNETLIBCONN hConnection)
{
SOCKET s;
if (hConnection == 0) {
|