summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-04-25 20:00:55 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-04-25 20:00:55 +0300
commit9ea18ddc413a8c1eae6c32fe16e162a1998079c1 (patch)
tree0fcf08adc603e6420fae94bf79d7ede357b96edb
parentc104e058686d3d36bc9b15d84bfd9b84740cd3fa (diff)
Telegram: offline files to be links from the very beginning
-rw-r--r--include/m_database.h3
-rw-r--r--include/m_protoint.h3
-rw-r--r--include/m_protosvc.h8
-rw-r--r--libs/win32/mir_app.libbin252050 -> 253056 bytes
-rw-r--r--libs/win64/mir_app.libbin249350 -> 250386 bytes
-rw-r--r--protocols/JabberG/src/jabber_file.cpp11
-rw-r--r--protocols/JabberG/src/jabber_proto.cpp17
-rw-r--r--protocols/JabberG/src/jabber_proto.h3
-rw-r--r--protocols/Telegram/src/avatars.cpp29
-rw-r--r--protocols/Telegram/src/proto.cpp20
-rw-r--r--protocols/Telegram/src/proto.h6
-rw-r--r--protocols/Telegram/src/utils.cpp2
-rw-r--r--src/core/stdfile/src/file.cpp1
-rw-r--r--src/mir_app/src/mir_app.def3
-rw-r--r--src/mir_app/src/mir_app64.def3
-rw-r--r--src/mir_app/src/proto_interface.cpp3
-rw-r--r--src/mir_app/src/protocols.cpp66
17 files changed, 95 insertions, 83 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 42c787aa81..dd8afaca1a 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -721,6 +721,9 @@ namespace DB
bool isCompleted() const;
__forceinline bool isOffline() const { return m_szProtoString != nullptr; }
+
+ __forceinline void setUrl(const char *pszUrl) { m_szProtoString = mir_strdup(pszUrl); }
+ __forceinline void setSize(int64_t iSize) { m_iFileSize = iSize; }
};
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/include/m_protoint.h b/include/m_protoint.h
index 07e461a118..83a4d8d523 100644
--- a/include/m_protoint.h
+++ b/include/m_protoint.h
@@ -266,6 +266,9 @@ public:
// called when the Account Manager needs to draw short account's options
virtual MWindow OnCreateAccMgrUI(MWindow hwndParent);
+ // called when an offline file is being created
+ virtual void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *ft);
+
// called when an event is altered in database
virtual void OnEventDeleted(MCONTACT, MEVENT);
diff --git a/include/m_protosvc.h b/include/m_protosvc.h
index c9e6aacfc2..19bbad22f3 100644
--- a/include/m_protosvc.h
+++ b/include/m_protosvc.h
@@ -772,7 +772,6 @@ EXTERN_C MIR_APP_DLL(MEVENT) Proto_AuthRecv(const char *szProtoName, PROTORECVEV
#define PRFF_UTF 0x0002 // in all MAllCStrings .a contains text in UTF8
#define PRFF_SILENT 0x0004 // do not show file send/receive dialog
-
struct PROTORECVFILE
{
uint32_t dwFlags; // PRFF_*
@@ -796,6 +795,13 @@ __forceinline INT_PTR ProtoChainRecvFile(MCONTACT hContact, PROTORECVFILE *pre)
}
///////////////////////////////////////////////////////////////////////////////
+// Offline file's blob preparation
+// wParam = (DB::FILEBLOB*) blob to patch
+// lParam = (HANDLE) pointer to custom file transfer, passed to PROTORECVFILE.lParam
+
+#define PS_PRECREATE_OFFLINEFILE "/PreCreateOfflineFile"
+
+///////////////////////////////////////////////////////////////////////////////
// Offline file processing
#define PS_OFFLINEFILE "/OfflineFile"
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib
index 01a9e20ebd..bcf9ffa7e9 100644
--- a/libs/win32/mir_app.lib
+++ b/libs/win32/mir_app.lib
Binary files differ
diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib
index c43320f49a..679e154364 100644
--- a/libs/win64/mir_app.lib
+++ b/libs/win64/mir_app.lib
Binary files differ
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index dc622efc31..410957bd45 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -95,7 +95,7 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *param)
if (written) {
DBVARIANT dbv = { DBVT_DWORD };
- dbv.dVal = written;
+ dbv.dVal = (DWORD)written;
db_event_setJson(param->hDbEvent, "ft", &dbv);
db_event_setJson(param->hDbEvent, "fs", &dbv);
NotifyEventHooks(g_hevEventEdited, 0, param->hDbEvent);
@@ -110,6 +110,15 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *param)
delete param;
}
+void CJabberProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
+{
+ if (auto *ft = (filetransfer *)pHandle)
+ if (ft->type == FT_HTTP && ft->httpPath)
+ blob.setUrl(ft->httpPath);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
#define JABBER_NETWORK_BUFFER_SIZE 2048
void __cdecl CJabberProto::FileReceiveHttpThread(filetransfer *ft)
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp
index 9faee94630..7eac9947c8 100644
--- a/protocols/JabberG/src/jabber_proto.cpp
+++ b/protocols/JabberG/src/jabber_proto.cpp
@@ -706,23 +706,6 @@ int CJabberProto::GetInfo(MCONTACT hContact, int /*infoType*/)
}
////////////////////////////////////////////////////////////////////////////////////////
-// RecvFile - writes down an incoming file transfer to db
-
-MEVENT CJabberProto::RecvFile(MCONTACT hContact, PROTORECVFILE *pre)
-{
- MEVENT hEvent = CSuper::RecvFile(hContact, pre);
- if (hEvent) {
- auto *ft = (filetransfer *)pre->lParam;
- if (ft && ft->type == FT_HTTP && ft->httpPath) {
- DBVARIANT dbv = { DBVT_UTF8 };
- dbv.pszVal = ft->httpPath;
- db_event_setJson(hEvent, "u", &dbv);
- }
- }
- return hEvent;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////
// SearchBasic - searches the contact by JID
struct JABBER_SEARCH_BASIC
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h
index 52e8b98c91..15b9b0bff4 100644
--- a/protocols/JabberG/src/jabber_proto.h
+++ b/protocols/JabberG/src/jabber_proto.h
@@ -135,8 +135,6 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
HANDLE SearchAdvanced(HWND owner) override;
HWND CreateExtendedSearchUI(HWND owner) override;
- MEVENT RecvFile(MCONTACT hContact, PROTORECVFILE *pre) override;
-
int SendContacts(MCONTACT hContact, int flags, int nContacts, MCONTACT *hContactsList) override;
HANDLE SendFile(MCONTACT hContact, const wchar_t *szDescription, wchar_t **ppszFiles) override;
int SendMsg(MCONTACT hContact, int flags, const char *msg) override;
@@ -153,6 +151,7 @@ struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
void OnBuildProtoMenu(void) override;
void OnContactDeleted(MCONTACT) override;
MWindow OnCreateAccMgrUI(MWindow) override;
+ void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle);
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
void OnShutdown() override;
diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp
index 07ae3e4e45..a588bfa76f 100644
--- a/protocols/Telegram/src/avatars.cpp
+++ b/protocols/Telegram/src/avatars.cpp
@@ -76,6 +76,7 @@ INT_PTR CTelegramProto::SvcSetMyAvatar(WPARAM, LPARAM)
}
/////////////////////////////////////////////////////////////////////////////////////////
+// Offline file downloader
void CTelegramProto::OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo)
{
@@ -96,12 +97,6 @@ void CTelegramProto::OnGetFileInfo(td::ClientManager::Response &response, void *
SendQuery(new TD::downloadFile(pFile->id_, 10, 0, 0, true));
}
-INT_PTR __cdecl CTelegramProto::OfflineFile(WPARAM param, LPARAM)
-{
- ForkThread((MyThreadFunc)&CTelegramProto::OfflineFileThread, (void *)param);
- return 0;
-}
-
void __cdecl CTelegramProto::OfflineFileThread(void *pParam)
{
auto *ofd = (OFDTHREAD *)pParam;
@@ -123,6 +118,25 @@ void __cdecl CTelegramProto::OfflineFileThread(void *pParam)
delete ofd;
}
+INT_PTR __cdecl CTelegramProto::OfflineFile(WPARAM param, LPARAM)
+{
+ ForkThread((MyThreadFunc)&CTelegramProto::OfflineFileThread, (void *)param);
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// Offline file pre-creator
+
+void CTelegramProto::OnCreateOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
+{
+ if (auto *ft = (TG_FILE_REQUEST *)pHandle) {
+ blob.setUrl(ft->m_uniqueId.GetBuffer());
+ blob.setSize(ft->m_fileSize);
+ }
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
{
mir_cslock lck(m_csFiles);
@@ -134,6 +148,9 @@ TG_FILE_REQUEST* CTelegramProto::PopFile(const char *pszUniqueId)
return nullptr;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// handles file info updates
+
void CTelegramProto::ProcessFile(TD::updateFile *pObj)
{
if (auto *pFile = pObj->file_.get()) {
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index 172b299ebc..a8f36fbe2e 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -278,26 +278,6 @@ INT_PTR CTelegramProto::GetCaps(int type, MCONTACT)
}
}
-////////////////////////////////////////////////////////////////////////////////////////
-// RecvFile - writes down an incoming file transfer to db
-
-MEVENT CTelegramProto::RecvFile(MCONTACT hContact, PROTORECVFILE *pre)
-{
- MEVENT hEvent = CSuper::RecvFile(hContact, pre);
- if (hEvent) {
- if (auto *ft = (TG_FILE_REQUEST *)pre->lParam) {
- DBVARIANT dbv = { DBVT_UTF8 };
- dbv.pszVal = ft->m_uniqueId.GetBuffer();
- db_event_setJson(hEvent, "u", &dbv);
-
- dbv.type = DBVT_DWORD;
- dbv.dVal = ft->m_fileId;
- db_event_setJson(hEvent, "id", &dbv);
- }
- }
- return hEvent;
-}
-
/////////////////////////////////////////////////////////////////////////////////////////
void CTelegramProto::OnSearchResults(td::ClientManager::Response &response)
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index 9dca2f81ec..0228ef285a 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -73,7 +73,7 @@ struct TG_FILE_REQUEST : public MZeroedObject
Type m_type;
bool m_bOpen = false;
MEVENT m_hEvent = 0;
- TD::int53 m_fileId;
+ TD::int53 m_fileId, m_fileSize = 0;
CMStringA m_uniqueId;
CMStringW m_destPath, m_fileName;
};
@@ -290,8 +290,6 @@ public:
INT_PTR GetCaps(int type, MCONTACT hContact = NULL) override;
- MEVENT RecvFile(MCONTACT hContact, PROTORECVFILE *pre) override;
-
HANDLE SearchByName(const wchar_t *nick, const wchar_t *firstName, const wchar_t *lastName) override;
int SendMsg(MCONTACT hContact, int flags, const char *pszMessage) override;
int SetStatus(int iNewStatus) override;
@@ -299,6 +297,7 @@ public:
void OnBuildProtoMenu() override;
void OnContactDeleted(MCONTACT hContact) override;
MWindow OnCreateAccMgrUI(MWindow hwndParent) override;
+ void OnCreateOfflineFile(DB::FILE_BLOB &blob, void *ft) override;
void OnEventDeleted(MCONTACT, MEVENT) override;
void OnMarkRead(MCONTACT, MEVENT) override;
void OnModulesLoaded() override;
@@ -318,6 +317,7 @@ public:
INT_PTR __cdecl AddByPhone(WPARAM, LPARAM);
INT_PTR __cdecl OfflineFile(WPARAM, LPARAM);
+ INT_PTR __cdecl PreCreateOfflineFile(WPARAM, LPARAM);
// Options ///////////////////////////////////////////////////////////////////////////
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp
index e63dd889e3..5529dd2418 100644
--- a/protocols/Telegram/src/utils.cpp
+++ b/protocols/Telegram/src/utils.cpp
@@ -259,7 +259,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg
auto *pRequest = new TG_FILE_REQUEST(TG_FILE_REQUEST::FILE, pFile->id_, pFile->remote_->id_.c_str());
pRequest->m_fileName = Utf2T(pDoc->document_->file_name_.c_str());
- pRequest->m_destPath = GetProtoFolder() + L"\\tmpfiles";
+ pRequest->m_fileSize = pFile->size_;
{
mir_cslock lck(m_csFiles);
m_arFiles.insert(pRequest);
diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp
index b1f8f3670f..652da6a36c 100644
--- a/src/core/stdfile/src/file.cpp
+++ b/src/core/stdfile/src/file.cpp
@@ -355,6 +355,7 @@ static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam)
}
DB::FILE_BLOB blob(wszFiles, bUtf ? Utf2T(pre->descr.a).get() : _A2T(pre->descr.a));
+ CallProtoService(dbei.szModule, PS_PRECREATE_OFFLINEFILE, WPARAM(&blob), pre->lParam);
blob.write(dbei);
}
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 319027ada5..2af6fdb061 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -864,3 +864,6 @@ Chat_IsMuted @941 NONAME
?getIcon@LOGINFO@@QBEHXZ @981 NONAME
?getIndex@LOGINFO@@QBEHXZ @982 NONAME
?write@LOGINFO@@QBEXPAURtfChatLogStreamData@@_NAAV?$CMStringT@DV?$ChTraitsCRT@D@@@@PB_W@Z @983 NONAME
+?OnCreateOfflineFile@PROTO_INTERFACE@@UAEXAAVFILE_BLOB@DB@@PAX@Z @984 NONAME
+?setSize@FILE_BLOB@DB@@QAEX_J@Z @985 NONAME
+?setUrl@FILE_BLOB@DB@@QAEXPBD@Z @986 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 94c6600242..33cd79d291 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -864,3 +864,6 @@ Chat_IsMuted @941 NONAME
?getIcon@LOGINFO@@QEBAHXZ @981 NONAME
?getIndex@LOGINFO@@QEBAHXZ @982 NONAME
?write@LOGINFO@@QEBAXPEAURtfChatLogStreamData@@_NAEAV?$CMStringT@DV?$ChTraitsCRT@D@@@@PEB_W@Z @983 NONAME
+?OnCreateOfflineFile@PROTO_INTERFACE@@UEAAXAEAVFILE_BLOB@DB@@PEAX@Z @984 NONAME
+?setSize@FILE_BLOB@DB@@QEAAX_J@Z @985 NONAME
+?setUrl@FILE_BLOB@DB@@QEAAXPEBD@Z @986 NONAME
diff --git a/src/mir_app/src/proto_interface.cpp b/src/mir_app/src/proto_interface.cpp
index b49e9a74ca..9e3d719126 100644
--- a/src/mir_app/src/proto_interface.cpp
+++ b/src/mir_app/src/proto_interface.cpp
@@ -79,6 +79,9 @@ MWindow PROTO_INTERFACE::OnCreateAccMgrUI(MWindow)
return nullptr; // error
}
+void PROTO_INTERFACE::OnCreateOfflineFile(DB::FILE_BLOB&, void *)
+{}
+
void PROTO_INTERFACE::OnEventDeleted(MCONTACT, MEVENT)
{}
diff --git a/src/mir_app/src/protocols.cpp b/src/mir_app/src/protocols.cpp
index f3a1d60f5c..d369bdf4da 100644
--- a/src/mir_app/src/protocols.cpp
+++ b/src/mir_app/src/protocols.cpp
@@ -43,38 +43,39 @@ static int __cdecl CompareServiceItems(const void *p1, const void *p2)
static TServiceListItem serviceItems[] =
{
- { PS_ADDTOLIST, 1 },
- { PS_ADDTOLISTBYEVENT, 2 },
- { PS_AUTHALLOW, 3 },
- { PS_AUTHDENY, 4 },
- { PSR_AUTH, 5 },
- { PSS_AUTHREQUEST, 6 },
- { PSS_FILEALLOW, 8 },
- { PSS_FILECANCEL, 9 },
- { PSS_FILEDENY, 10 },
- { PS_FILERESUME, 11 },
- { PS_GETCAPS, 12 },
- { PS_LOADICON, 13 },
- { PSS_GETINFO, 14 },
- { PS_BASICSEARCH, 15 },
- { PS_SEARCHBYEMAIL, 16 },
- { PS_SEARCHBYNAME, 17 },
- { PS_SEARCHBYADVANCED, 18 },
- { PS_CREATEADVSEARCHUI, 19 },
- { PSR_CONTACTS, 20 },
- { PSR_FILE, 21 },
- { PSR_MESSAGE, 22 },
- { PSS_CONTACTS, 23 },
- { PSS_FILE, 24 },
- { PSS_MESSAGE, 25 },
- { PSS_SETAPPARENTMODE, 26 },
- { PS_SETSTATUS, 27 },
- { PSS_GETAWAYMSG, 28 },
- { PSR_AWAYMSG, 29 },
- { PS_SETAWAYMSG, 30 },
- { PSS_USERISTYPING, 31 },
- { PS_GETNAME, 32 },
- { PS_GETSTATUS, 33 }
+ { PS_ADDTOLIST, 1 },
+ { PS_ADDTOLISTBYEVENT, 2 },
+ { PS_AUTHALLOW, 3 },
+ { PS_AUTHDENY, 4 },
+ { PSR_AUTH, 5 },
+ { PSS_AUTHREQUEST, 6 },
+ { PS_PRECREATE_OFFLINEFILE, 7 },
+ { PSS_FILEALLOW, 8 },
+ { PSS_FILECANCEL, 9 },
+ { PSS_FILEDENY, 10 },
+ { PS_FILERESUME, 11 },
+ { PS_GETCAPS, 12 },
+ { PS_LOADICON, 13 },
+ { PSS_GETINFO, 14 },
+ { PS_BASICSEARCH, 15 },
+ { PS_SEARCHBYEMAIL, 16 },
+ { PS_SEARCHBYNAME, 17 },
+ { PS_SEARCHBYADVANCED, 18 },
+ { PS_CREATEADVSEARCHUI, 19 },
+ { PSR_CONTACTS, 20 },
+ { PSR_FILE, 21 },
+ { PSR_MESSAGE, 22 },
+ { PSS_CONTACTS, 23 },
+ { PSS_FILE, 24 },
+ { PSS_MESSAGE, 25 },
+ { PSS_SETAPPARENTMODE, 26 },
+ { PS_SETSTATUS, 27 },
+ { PSS_GETAWAYMSG, 28 },
+ { PSR_AWAYMSG, 29 },
+ { PS_SETAWAYMSG, 30 },
+ { PSS_USERISTYPING, 31 },
+ { PS_GETNAME, 32 },
+ { PS_GETSTATUS, 33 },
};
//------------------------------------------------------------------------------------
@@ -400,6 +401,7 @@ INT_PTR CallProtoServiceInt(MCONTACT hContact, const char *szModule, const char
case 4: return (INT_PTR)ppi->AuthDeny((MEVENT)wParam, (wchar_t *)lParam);
case 5: return (INT_PTR)ppi->AuthRecv(hContact, (PROTORECVEVENT *)lParam);
case 6: return (INT_PTR)ppi->AuthRequest(hContact, (wchar_t *)lParam);
+ case 7: ppi->OnCreateOfflineFile(*(DB::FILE_BLOB *)wParam, (void *)lParam); return 0;
case 8: return (INT_PTR)ppi->FileAllow(hContact, (HANDLE)wParam, (wchar_t *)lParam);
case 9: return (INT_PTR)ppi->FileCancel(hContact, (HANDLE)wParam);
case 10: return (INT_PTR)ppi->FileDeny(hContact, (HANDLE)wParam, (wchar_t *)lParam);