diff options
author | George Hazan <george.hazan@gmail.com> | 2024-05-13 14:23:13 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-05-13 14:23:13 +0300 |
commit | c7d065645853b2e614e8557fa01057efaf5e6517 (patch) | |
tree | 6b5233ed788e31014e868c007ccb469ca4d64e60 /src/mir_app | |
parent | 831bffd63776f4ffe82245cadf2b95c48cd44d38 (diff) |
DbEvent_GetTextA: unused function removed
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/src/chat_log.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/chat_tools.cpp | 2 | ||||
-rw-r--r-- | src/mir_app/src/db_events.cpp | 229 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 4 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 4 | ||||
-rw-r--r-- | src/mir_app/src/srmm_base.cpp | 4 |
6 files changed, 109 insertions, 136 deletions
diff --git a/src/mir_app/src/chat_log.cpp b/src/mir_app/src/chat_log.cpp index 1068dcff2d..53b7db4ab8 100644 --- a/src/mir_app/src/chat_log.cpp +++ b/src/mir_app/src/chat_log.cpp @@ -330,7 +330,7 @@ void CRtfLogWindow::CreateChatRtfMessage(RtfChatLogStreamData *streamData, const return;
}
}
- lin.write(streamData, false, buf, ptrW(DbEvent_GetTextW(&dbei)));
+ lin.write(streamData, false, buf, ptrW(dbei.getText()));
return;
}
}
diff --git a/src/mir_app/src/chat_tools.cpp b/src/mir_app/src/chat_tools.cpp index 172cbf1e8b..c28ba62438 100644 --- a/src/mir_app/src/chat_tools.cpp +++ b/src/mir_app/src/chat_tools.cpp @@ -734,7 +734,7 @@ void Chat_EventToGC(SESSION_INFO *si, MEVENT hDbEvent) if (mir_strcmp(szProto, dbei.szModule) || !g_chatApi.DbEventIsShown(dbei) || !dbei.szUserId)
return;
- CMStringW wszText(ptrW(DbEvent_GetTextW(&dbei)));
+ CMStringW wszText(ptrW(dbei.getText()));
wszText.Replace(L"%", L"%%");
GCEVENT gce = { si, GC_EVENT_MESSAGE };
diff --git a/src/mir_app/src/db_events.cpp b/src/mir_app/src/db_events.cpp index 45cbdc9022..210e609dff 100644 --- a/src/mir_app/src/db_events.cpp +++ b/src/mir_app/src/db_events.cpp @@ -91,138 +91,14 @@ MIR_APP_DLL(DBEVENTTYPEDESCR*) DbEvent_GetType(const char *szModule, int eventTy /////////////////////////////////////////////////////////////////////////////////////////
-static wchar_t* getEventString(const DB::EventInfo *dbei, LPSTR &buf)
-{
- LPSTR in = buf;
- buf += mir_strlen(buf) + 1;
- return dbei->getString(in);
-}
-
-static INT_PTR DbEventGetTextWorker(const DB::EventInfo *dbei, int codepage, int datatype)
+MIR_APP_DLL(wchar_t*) DbEvent_GetText(const DBEVENTINFO *dbei)
{
if (dbei == nullptr || dbei->szModule == nullptr)
return 0;
- DBEVENTTYPEDESCR *et = DbEvent_GetType(dbei->szModule, dbei->eventType);
- if (et && ServiceExists(et->textService))
- return CallService(et->textService, (WPARAM)dbei, datatype);
-
- if (!dbei->pBlob)
- return 0;
-
- if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) {
- 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) {
- nick.AppendFormat(L"%s %s", tszFirst.get(), tszLast.get());
- nick.Trim();
- }
- if (tszEmail) {
- if (!nick.IsEmpty())
- nick.Append(L", ");
- nick.Append(tszEmail);
- }
- if (blob.get_uin() != 0) {
- if (!nick.IsEmpty())
- nick.Append(L", ");
- nick.AppendFormat(L"%d", blob.get_uin());
- }
- if (!nick.IsEmpty())
- nick = L"(" + nick + L")";
-
- if (dbei->eventType == EVENTTYPE_AUTHREQUEST) {
- ptrW tszReason(dbei->getString(blob.get_reason()));
- text.Format(TranslateT("Authorization request from %s%s: %s"),
- (tszNick == nullptr) ? Clist_GetContactDisplayName(blob.get_contact()) : tszNick.get(), nick.c_str(), tszReason.get());
- }
- else text.Format(TranslateT("You were added by %s%s"),
- (tszNick == nullptr) ? Clist_GetContactDisplayName(blob.get_contact()) : tszNick.get(), nick.c_str());
- return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text);
- }
-
- if (dbei->eventType == EVENTTYPE_CONTACTS) {
- CMStringW text(TranslateT("Contacts: "));
- // blob is: [uin(ASCIIZ), nick(ASCIIZ)]*
- char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob;
- while (buf < limit) {
- ptrW tszUin(getEventString(dbei, buf));
- ptrW tszNick(getEventString(dbei, buf));
- if (tszNick && *tszNick)
- text.AppendFormat(L"\"%s\" ", tszNick.get());
- if (tszUin && *tszUin)
- text.AppendFormat(L"<%s>; ", tszUin.get());
- }
- return (datatype == DBVT_WCHAR) ? (INT_PTR)mir_wstrdup(text) : (INT_PTR)mir_u2a(text);
- }
-
- if (dbei->eventType == EVENTTYPE_FILE) {
- DB::FILE_BLOB blob(*dbei);
-
- CMStringW wszText(blob.getName());
- if (mir_wstrlen(blob.getDescr())) {
- wszText.Append(L": ");
- wszText.Append(blob.getDescr());
- }
-
- switch (datatype) {
- case DBVT_WCHAR:
- return (INT_PTR)wszText.Detach();
- case DBVT_ASCIIZ:
- return (INT_PTR)mir_u2a(wszText);
- }
- return 0;
- }
-
- if (dbei->flags & DBEF_JSON) {
- JSONNode json = dbei->getJson();
- std::string str = json["b"].as_string();
- switch (datatype) {
- case DBVT_WCHAR:
- return (INT_PTR)mir_utf8decodeW(str.c_str());
- case DBVT_ASCIIZ:
- char *msg = mir_strdup(str.c_str());
- mir_utf8decodecp(msg, codepage, nullptr);
- return (INT_PTR)msg;
- }
- return 0;
- }
-
- // by default treat an event's blob as a string
- if (datatype == DBVT_WCHAR) {
- char *str = (char*)alloca(dbei->cbBlob + 1);
- memcpy(str, dbei->pBlob, dbei->cbBlob);
- str[dbei->cbBlob] = 0;
-
- if (dbei->flags & DBEF_UTF)
- return (INT_PTR)mir_utf8decodeW(str);
-
- return (INT_PTR)mir_a2u_cp(str, codepage);
- }
-
- if (datatype == DBVT_ASCIIZ) {
- char *msg = mir_strdup((char*)dbei->pBlob);
- if (dbei->flags & DBEF_UTF)
- mir_utf8decodecp(msg, codepage, nullptr);
-
- return (INT_PTR)msg;
- }
- return 0;
-}
-
-MIR_APP_DLL(char*) DbEvent_GetTextA(const DBEVENTINFO *dbei, int codepage)
-{
- return (char*)DbEventGetTextWorker((DB::EventInfo *)dbei, codepage, DBVT_ASCIIZ);
-}
-
-MIR_APP_DLL(wchar_t*) DbEvent_GetTextW(const DBEVENTINFO *dbei)
-{
- return (wchar_t*)DbEventGetTextWorker((DB::EventInfo *)dbei, CP_ACP, DBVT_WCHAR);
+ DB::EventInfo tmp;
+ memcpy(&tmp, dbei, sizeof(*dbei));
+ return tmp.getText();
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -362,6 +238,103 @@ wchar_t* DB::EventInfo::getString(const char *str) const return mir_a2u(str);
}
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static wchar_t* getEventString(const DB::EventInfo *dbei, LPSTR &buf)
+{
+ LPSTR in = buf;
+ buf += mir_strlen(buf) + 1;
+ return dbei->getString(in);
+}
+
+wchar_t* DB::EventInfo::getText() const
+{
+ DBEVENTTYPEDESCR *et = DbEvent_GetType(szModule, eventType);
+ if (et && ServiceExists(et->textService))
+ return (wchar_t *)CallService(et->textService, (WPARAM)this, DBVT_WCHAR);
+
+ if (!pBlob)
+ return 0;
+
+ if (eventType == EVENTTYPE_AUTHREQUEST || eventType == EVENTTYPE_ADDED) {
+ DB::AUTH_BLOB blob(pBlob);
+
+ ptrW tszNick(getString(blob.get_nick()));
+ ptrW tszFirst(getString(blob.get_firstName()));
+ ptrW tszLast(getString(blob.get_lastName()));
+ ptrW tszEmail(getString(blob.get_email()));
+
+ CMStringW nick, text;
+ if (tszFirst || tszLast) {
+ nick.AppendFormat(L"%s %s", tszFirst.get(), tszLast.get());
+ nick.Trim();
+ }
+ if (tszEmail) {
+ if (!nick.IsEmpty())
+ nick.Append(L", ");
+ nick.Append(tszEmail);
+ }
+ if (blob.get_uin() != 0) {
+ if (!nick.IsEmpty())
+ nick.Append(L", ");
+ nick.AppendFormat(L"%d", blob.get_uin());
+ }
+ if (!nick.IsEmpty())
+ nick = L"(" + nick + L")";
+
+ if (eventType == EVENTTYPE_AUTHREQUEST) {
+ ptrW tszReason(getString(blob.get_reason()));
+ text.Format(TranslateT("Authorization request from %s%s: %s"),
+ (tszNick == nullptr) ? Clist_GetContactDisplayName(blob.get_contact()) : tszNick.get(), nick.c_str(), tszReason.get());
+ }
+ else text.Format(TranslateT("You were added by %s%s"),
+ (tszNick == nullptr) ? Clist_GetContactDisplayName(blob.get_contact()) : tszNick.get(), nick.c_str());
+ return mir_wstrdup(text);
+ }
+
+ if (eventType == EVENTTYPE_CONTACTS) {
+ CMStringW text(TranslateT("Contacts: "));
+ // blob is: [uin(ASCIIZ), nick(ASCIIZ)]*
+ char *buf = LPSTR(pBlob), *limit = LPSTR(pBlob) + cbBlob;
+ while (buf < limit) {
+ ptrW tszUin(getEventString(this, buf));
+ ptrW tszNick(getEventString(this, buf));
+ if (tszNick && *tszNick)
+ text.AppendFormat(L"\"%s\" ", tszNick.get());
+ if (tszUin && *tszUin)
+ text.AppendFormat(L"<%s>; ", tszUin.get());
+ }
+ return mir_wstrdup(text);
+ }
+
+ if (eventType == EVENTTYPE_FILE) {
+ DB::FILE_BLOB blob(*this);
+
+ CMStringW wszText(blob.getName());
+ if (mir_wstrlen(blob.getDescr())) {
+ wszText.Append(L": ");
+ wszText.Append(blob.getDescr());
+ }
+ return wszText.Detach();
+ }
+
+ if (flags & DBEF_JSON) {
+ JSONNode json = getJson();
+ std::string str = json["b"].as_string();
+ return mir_utf8decodeW(str.c_str());
+ }
+
+ // by default treat an event's blob as a string
+ char *str = (char *)alloca(cbBlob + 1);
+ memcpy(str, pBlob, cbBlob);
+ str[cbBlob] = 0;
+
+ if (flags & DBEF_UTF)
+ return mir_utf8decodeW(str);
+
+ return mir_a2u_cp(str, CP_ACP);
+}
+
void DB::EventInfo::flushJson()
{
if (!m_json)
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 1e528c19e3..eae8101853 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -202,8 +202,7 @@ Srmm_ModifyIcon @280 Srmm_RemoveIcon @281
ExtraIcon_AddIcon @282
DbEvent_GetIcon @283
-DbEvent_GetTextA @285
-DbEvent_GetTextW @286
+DbEvent_GetText @286
DbEvent_GetType @287
DbEvent_RegisterType @288
Profile_GetNameA @290
@@ -976,3 +975,4 @@ g_hevEventSetJson @1109 NONAME ?flushJson@EventInfo@DB@@QAEXXZ @1112 NONAME
?addReaction@EventInfo@DB@@QAEXPBD@Z @1113 NONAME
?delReaction@EventInfo@DB@@QAEXPBD@Z @1114 NONAME
+?getText@EventInfo@DB@@QBEPA_WXZ @1115 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 08a35f4c16..6811b2d393 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -202,8 +202,7 @@ Srmm_ModifyIcon @280 Srmm_RemoveIcon @281
ExtraIcon_AddIcon @282
DbEvent_GetIcon @283
-DbEvent_GetTextA @285
-DbEvent_GetTextW @286
+DbEvent_GetText @286
DbEvent_GetType @287
DbEvent_RegisterType @288
Profile_GetNameA @290
@@ -976,3 +975,4 @@ g_hevEventSetJson @1103 NONAME ?flushJson@EventInfo@DB@@QEAAXXZ @1106 NONAME
?addReaction@EventInfo@DB@@QEAAXPEBD@Z @1107 NONAME
?delReaction@EventInfo@DB@@QEAAXPEBD@Z @1108 NONAME
+?getText@EventInfo@DB@@QEBAPEA_WXZ @1109 NONAME
diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 0def709503..6549190c3c 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -778,7 +778,7 @@ void CSrmmBaseDialog::UpdateChatLog() DB::EventInfo dbei(hDbEvent);
if (dbei && !mir_strcmp(szProto, dbei.szModule) && g_chatApi.DbEventIsShown(dbei) && dbei.szUserId) {
Utf2T wszUserId(dbei.szUserId);
- CMStringW wszText(ptrW(DbEvent_GetTextW(&dbei)));
+ CMStringW wszText(ptrW(dbei.getText()));
wszText.Replace(L"%", L"%%");
GCEVENT gce = { m_si, GC_EVENT_MESSAGE };
@@ -1140,7 +1140,7 @@ void CSrmmBaseDialog::SetQuoteEvent(MEVENT hEvent) if (dbei) {
CMStringW wszText(TranslateT("In reply to"));
wszText += L": ";
- wszText += ptrW(DbEvent_GetTextW(&dbei)).get();
+ wszText += ptrW(dbei.getText()).get();
m_Quote.SetText(wszText);
m_hQuoteEvent = hEvent;
|