summaryrefslogtreecommitdiff
path: root/src/core/stdfile
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-11 17:07:04 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-11 17:07:04 +0300
commit8f9292d483fcf3a10d9284512359c4562f5311eb (patch)
tree3593ca1eb6a5a4c3b2ef454fa6b4944d4b8da8c4 /src/core/stdfile
parent5f4f070347d20fc85b588138217aa744141e8053 (diff)
DB::FILE_BLOB - file events' access unification
Diffstat (limited to 'src/core/stdfile')
-rw-r--r--src/core/stdfile/src/file.cpp50
-rw-r--r--src/core/stdfile/src/filexferdlg.cpp32
2 files changed, 28 insertions, 54 deletions
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp
index abe3152cdd..126b428c99 100644
--- a/src/core/stdfile/src/file.cpp
+++ b/src/core/stdfile/src/file.cpp
@@ -356,7 +356,7 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
if (pre->fileCount == 0)
return 0;
- DBEVENTINFO dbei = {};
+ DB::EventInfo dbei;
dbei.szModule = Proto_GetBaseAccountName(ccs->hContact);
dbei.timestamp = pre->timestamp;
dbei.eventType = EVENTTYPE_FILE;
@@ -364,47 +364,33 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
if (pre->dwFlags & PREF_CREATEREAD)
dbei.flags |= DBEF_READ;
- bool bUnicode = (pre->dwFlags & PRFF_UNICODE) == PRFF_UNICODE;
+ if ((pre->dwFlags & PRFF_UNICODE) == PRFF_UNICODE) {
+ CMStringW wszFiles;
- const char *szDescr, **pszFiles;
- if (bUnicode) {
- pszFiles = (const char**)alloca(pre->fileCount * sizeof(char*));
- for (int i = 0; i < pre->fileCount; i++)
- pszFiles[i] = mir_utf8encodeW(pre->files.w[i]);
+ for (int i = 0; i < pre->fileCount; i++) {
+ if (i != 0)
+ wszFiles.AppendChar(',');
+ wszFiles.Append(pre->files.w[i]);
+ }
- szDescr = mir_utf8encodeW(pre->descr.w);
+ DB::FILE_BLOB blob(wszFiles, pre->descr.w);
+ blob.write(dbei);
}
else {
- pszFiles = pre->files.a;
- szDescr = pre->descr.a;
- }
-
- dbei.cbBlob = sizeof(uint32_t);
+ CMStringW wszFiles;
- for (int i = 0; i < pre->fileCount; i++)
- dbei.cbBlob += (int)mir_strlen(pszFiles[i]) + 1;
-
- dbei.cbBlob += (int)mir_strlen(szDescr) + 1;
-
- if ((dbei.pBlob = (uint8_t*)mir_alloc(dbei.cbBlob)) == nullptr)
- return 0;
+ for (int i = 0; i < pre->fileCount; i++) {
+ if (i != 0)
+ wszFiles.AppendChar(',');
+ wszFiles.Append(_A2T(pre->files.a[i]));
+ }
- *(uint32_t*)dbei.pBlob = 0;
- uint8_t* p = dbei.pBlob + sizeof(uint32_t);
- for (int i = 0; i < pre->fileCount; i++) {
- mir_strcpy((char*)p, pszFiles[i]);
- p += mir_strlen(pszFiles[i]) + 1;
- if (bUnicode)
- mir_free((void*)pszFiles[i]);
+ DB::FILE_BLOB blob(wszFiles, _A2T(pre->descr.a));
+ blob.write(dbei);
}
- mir_strcpy((char*)p, (szDescr == nullptr) ? "" : szDescr);
- if (bUnicode)
- mir_free((void*)szDescr);
-
MEVENT hdbe = db_event_add(ccs->hContact, &dbei);
PushFileEvent(ccs->hContact, hdbe, pre->lParam);
- mir_free(dbei.pBlob);
return 0;
}
diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp
index e545649b5b..5ab3a0679b 100644
--- a/src/core/stdfile/src/filexferdlg.cpp
+++ b/src/core/stdfile/src/filexferdlg.cpp
@@ -78,24 +78,6 @@ static void SetOpenFileButtonStyle(HWND hwndButton, int enabled)
EnableWindow(hwndButton, enabled);
}
-void FillSendData(FileDlgData *dat, DBEVENTINFO &dbei)
-{
- dbei.szModule = Proto_GetBaseAccountName(dat->hContact);
- dbei.eventType = EVENTTYPE_FILE;
- dbei.flags = DBEF_SENT;
- dbei.timestamp = time(0);
- char *szFileNames = mir_utf8encodeW(dat->szFilenames), *szMsg = mir_utf8encodeW(dat->szMsg);
- dbei.flags |= DBEF_UTF;
-
- dbei.cbBlob = int(sizeof(uint32_t) + mir_strlen(szFileNames) + mir_strlen(szMsg) + 2);
- dbei.pBlob = (uint8_t*)mir_alloc(dbei.cbBlob);
- *(PDWORD)dbei.pBlob = 0;
- mir_strcpy((char*)dbei.pBlob + sizeof(uint32_t), szFileNames);
- mir_strcpy((char*)dbei.pBlob + sizeof(uint32_t) + mir_strlen(szFileNames) + 1, szMsg);
-
- mir_free(szFileNames), mir_free(szMsg);
-}
-
static void __cdecl RunVirusScannerThread(virusscanthreadstartinfo *info)
{
DBVARIANT dbv;
@@ -650,11 +632,17 @@ INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
dat->fs = nullptr; /* protocol will free structure */
SetFtStatus(hwndDlg, LPGENW("Transfer completed."), FTS_TEXT);
- DBEVENTINFO dbei = {};
- FillSendData(dat, dbei);
+ DB::EventInfo dbei;
+ dbei.szModule = Proto_GetBaseAccountName(dat->hContact);
+ dbei.eventType = EVENTTYPE_FILE;
+ dbei.flags = DBEF_SENT;
+ dbei.timestamp = time(0);
+ dbei.flags |= DBEF_UTF;
+
+ DB::FILE_BLOB blob(dat->szFilenames, dat->szMsg);
+ blob.write(dbei);
db_event_add(dat->hContact, &dbei);
- if (dbei.pBlob)
- mir_free(dbei.pBlob);
+
dat->files = nullptr; //protocol library frees this
}
else {