summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-12-14 16:56:48 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-12-14 16:56:48 +0000
commit1afba55381a1697d80daea5e9a12aeb567a92402 (patch)
treefcdae1248b1ca05b634f37928b686498736b1702
parenta20e356240c3336cbc1f441760a0bca0769dd604 (diff)
- another atavism (DBVTF_DENYUNICODE) removed;
- default text formatter for EVENTTYPE_AUTHREQUEST added git-svn-id: http://svn.miranda-ng.org/main/trunk@7208 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/delphi/m_core.inc1
-rw-r--r--include/m_database.h5
-rw-r--r--include/m_system_cpp.h1
-rw-r--r--plugins/IEView/src/HTMLBuilder.cpp2
-rw-r--r--src/modules/database/dbutils.cpp106
5 files changed, 72 insertions, 43 deletions
diff --git a/include/delphi/m_core.inc b/include/delphi/m_core.inc
index 40298ee87b..9a5b054f6d 100644
--- a/include/delphi/m_core.inc
+++ b/include/delphi/m_core.inc
@@ -50,7 +50,6 @@ const
DBVT_UTF8 = 253; // pszVal is valid
DBVT_WCHAR = 252; // pszVal is valid
DBVTF_VARIABLELENGTH = $80; // ?
- DBVTF_DENYUNICODE = $10000;
type
PDBVARIANT = ^TDBVARIANT;
diff --git a/include/m_database.h b/include/m_database.h
index ddc32d1e7b..f5a8c1d7da 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -299,16 +299,13 @@ Retrieves the event's text
wParam = (WPARAM)0 (unused)
lParam = (LPARAM)(DBEVENTGETTEXT*)egt - pointer to structure with parameters
egt->dbei should be the valid database event read via db_event_get()
- egt->datatype = DBVT_WCHAR or DBVT_ASCIIZ or DBVT_TCHAR. If a caller wants to
-suppress Unicode part of event in answer, add DBVTF_DENYUNICODE to this field.
+ egt->datatype = DBVT_WCHAR or DBVT_ASCIIZ or DBVT_TCHAR.
egt->codepage is any valid codepage, CP_ACP by default.
Function returns a pointer to a string in the required format.
This string should be freed by a call of mir_free
*/
-#define DBVTF_DENYUNICODE 0x10000
-
typedef struct {
DBEVENTINFO* dbei;
int datatype;
diff --git a/include/m_system_cpp.h b/include/m_system_cpp.h
index d30c857713..2775f5220f 100644
--- a/include/m_system_cpp.h
+++ b/include/m_system_cpp.h
@@ -51,6 +51,7 @@ public:
__inline T* operator->() const { return data; }
__inline operator T*() const { return data; }
__inline operator INT_PTR() const { return (INT_PTR)data; }
+ __inline T* detouch() { T *res = data; data = NULL; return res; }
};
typedef mir_ptr<char> ptrA;
diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp
index 684516e9a4..7dc86f2f19 100644
--- a/plugins/IEView/src/HTMLBuilder.cpp
+++ b/plugins/IEView/src/HTMLBuilder.cpp
@@ -370,7 +370,7 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event)
eventData->bIsMe = FALSE;
}
if (dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == EVENTTYPE_URL || dbei.eventType == EVENTTYPE_STATUSCHANGE || dbei.eventType == EVENTTYPE_JABBER_CHATSTATES) {
- DBEVENTGETTEXT temp = { &dbei, DBVT_WCHAR + ((event->dwFlags & IEEF_NO_UNICODE) ? DBVTF_DENYUNICODE : 0), newEvent.codepage };
+ DBEVENTGETTEXT temp = { &dbei, DBVT_WCHAR, newEvent.codepage };
WCHAR* pwszEventText = (WCHAR*)CallService(MS_DB_EVENT_GETTEXT,0,(LPARAM)&temp);
eventData->pszTextW = mir_tstrdup(pwszEventText);
mir_free(pwszEventText);
diff --git a/src/modules/database/dbutils.cpp b/src/modules/database/dbutils.cpp
index 8281eb27f0..6c63013a10 100644
--- a/src/modules/database/dbutils.cpp
+++ b/src/modules/database/dbutils.cpp
@@ -83,28 +83,76 @@ static INT_PTR DbEventTypeGet(WPARAM wParam, LPARAM lParam)
return (INT_PTR)eventTypes[idx];
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static TCHAR* getEventString(DBEVENTINFO *dbei, LPSTR &buf)
+{
+ LPSTR in = buf;
+ buf += strlen(buf) + 1;
+ return (dbei->flags & DBEF_UTF) ? Utf8DecodeT(in) : mir_a2t(in);
+}
+
static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
{
DBEVENTGETTEXT* egt = (DBEVENTGETTEXT*)lParam;
- BOOL bIsDenyUnicode = (egt->datatype & DBVTF_DENYUNICODE);
+ if (egt == NULL)
+ return 0;
- DBEVENTINFO* dbei = egt->dbei;
- DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType);
+ DBEVENTINFO *dbei = egt->dbei;
+ DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType);
if (et && ServiceExists(et->textService))
return CallService(et->textService, wParam, lParam);
- if ( !dbei->pBlob) return 0;
+ if (!dbei->pBlob)
+ return 0;
+
+ // no text for this kind of events
+ if (dbei->eventType == EVENTTYPE_AUTHREQUEST) {
+ // blob is: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ)
+ DWORD uin = *(DWORD*)dbei->pBlob;
+ HANDLE hContact = (HANDLE)*(DWORD*)(dbei->pBlob + sizeof(DWORD));
+ char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2;
+ ptrT tszNick(getEventString(dbei, buf));
+ ptrT tszFirst(getEventString(dbei, buf));
+ ptrT tszLast(getEventString(dbei, buf));
+ ptrT tszEmail(getEventString(dbei, buf));
+ ptrT tszReason(getEventString(dbei, buf));
+
+ CMString nick, text;
+ if (tszFirst || tszLast) {
+ nick.AppendFormat(_T("%s %s"), tszFirst, tszLast);
+ nick.Trim();
+ }
+ if (tszEmail) {
+ if (!nick.IsEmpty())
+ nick.Append(_T(", "));
+ nick.Append(tszEmail);
+ }
+ if (uin != 0) {
+ if (!nick.IsEmpty())
+ nick.Append(_T(", "));
+ nick.AppendFormat(_T("%d"), uin);
+ }
+ if (!nick.IsEmpty())
+ nick = _T("(") + nick + _T(")");
+
+ text.Format(_T("Authorization request from %s%s: %s"),
+ (*tszNick == 0) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason);
+
+ return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text);
+ }
if (dbei->eventType == EVENTTYPE_FILE) {
- char *filename = ((char *)dbei->pBlob) + sizeof(DWORD);
- char *descr = filename + lstrlenA(filename) + 1;
- char *str = (*descr == 0) ? filename : descr;
+ char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD);
+ ptrT tszFileName(getEventString(dbei, buf));
+ ptrT tszDescription(getEventString(dbei, buf));
+ ptrT &ptszText = (*tszDescription == 0) ? tszFileName : tszDescription;
switch (egt->datatype) {
case DBVT_WCHAR:
- return (INT_PTR)((dbei->flags & DBEF_UTF) ? Utf8DecodeT(str) : mir_a2t(str));
+ return (INT_PTR)ptszText.detouch();
case DBVT_ASCIIZ:
- return (INT_PTR)((dbei->flags & DBEF_UTF) ? Utf8Decode(mir_strdup(str), NULL) : mir_strdup(str));
+ return (INT_PTR)mir_t2a(ptszText);
}
return 0;
}
@@ -114,39 +162,23 @@ static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam)
if (dbei->eventType == 25368 && dbei->cbBlob == 1 && dbei->pBlob[0] == 1)
return 0;
- egt->datatype &= ~DBVTF_DENYUNICODE;
+ // by default treat an event's blob as a string
if (egt->datatype == DBVT_WCHAR) {
- WCHAR *msg = NULL;
+ char *str = (char*)alloca(dbei->cbBlob + 1);
+ memcpy(str, dbei->pBlob, dbei->cbBlob);
+ str[dbei->cbBlob] = 0;
+
if (dbei->flags & DBEF_UTF) {
- char *str = (char*)alloca(dbei->cbBlob + 1);
- if (str == NULL) return NULL;
- memcpy(str, dbei->pBlob, dbei->cbBlob);
- str[dbei->cbBlob] = 0;
+ WCHAR *msg = NULL;
Utf8DecodeCP(str, egt->codepage, &msg);
+ if (msg)
+ return (INT_PTR)msg;
}
- else {
- size_t msglen = strlen((char*)dbei->pBlob) + 1, msglenW = 0;
- if (msglen != dbei->cbBlob) {
- size_t i, count = ((dbei->cbBlob - msglen) / sizeof(WCHAR));
- WCHAR *p = (WCHAR*)&dbei->pBlob[ msglen ];
- for (i=0; i < count; i++) {
- if (p[i] == 0) {
- msglenW = i;
- break;
- }
- }
- }
-
- if (msglenW > 0 && msglenW < msglen && !bIsDenyUnicode)
- msg = mir_wstrdup((WCHAR*)&dbei->pBlob[ msglen ]);
- else {
- msg = (WCHAR*)mir_alloc(sizeof(WCHAR) * msglen);
- MultiByteToWideChar(egt->codepage, 0, (char *) dbei->pBlob, -1, msg, (int)msglen);
- }
- }
- return (INT_PTR)msg;
+
+ return (INT_PTR)mir_a2t_cp(str, egt->codepage);
}
- else if (egt->datatype == DBVT_ASCIIZ) {
+
+ if (egt->datatype == DBVT_ASCIIZ) {
char *msg = mir_strdup((char*)dbei->pBlob);
if (dbei->flags & DBEF_UTF)
Utf8DecodeCP(msg, egt->codepage, NULL);