From 4f795835fc380a439649751a6c6710841df135c9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Jun 2024 13:43:58 +0300 Subject: Utils_GenerateUUID - a helper for UUID generation --- include/m_utils.h | 5 +++++ libs/win32/mir_core.lib | Bin 498518 -> 498950 bytes libs/win64/mir_core.lib | Bin 503818 -> 504250 bytes protocols/Facebook/src/main.cpp | 2 -- protocols/Facebook/src/proto.cpp | 7 +------ protocols/ICQ-WIM/src/http.cpp | 10 +--------- protocols/ICQ-WIM/src/server.cpp | 11 +++-------- src/mir_core/src/Windows/winutil.cpp | 18 ++++++++++++++++++ src/mir_core/src/mir_core.def | 1 + src/mir_core/src/mir_core64.def | 1 + 10 files changed, 30 insertions(+), 25 deletions(-) diff --git a/include/m_utils.h b/include/m_utils.h index 7949e5dc60..553522bdcf 100644 --- a/include/m_utils.h +++ b/include/m_utils.h @@ -432,6 +432,11 @@ EXTERN_C MIR_CORE_DLL(void) Utils_GetRandom(void *pszDest, size_t cbLen); EXTERN_C MIR_CORE_DLL(bool) Utils_IsRtl(const wchar_t *pszwText); +///////////////////////////////////////////////////////////////////////////////////////// +// UUID generator + +MIR_CORE_DLL(CMStringA) Utils_GenerateUUID(); + ///////////////////////////////////////////////////////////////////////////////////////// // Unzip memory buffer diff --git a/libs/win32/mir_core.lib b/libs/win32/mir_core.lib index cc904117d7..49307cbad9 100644 Binary files a/libs/win32/mir_core.lib and b/libs/win32/mir_core.lib differ diff --git a/libs/win64/mir_core.lib b/libs/win64/mir_core.lib index a6dc575f07..b5a51004fe 100644 Binary files a/libs/win64/mir_core.lib and b/libs/win64/mir_core.lib differ diff --git a/protocols/Facebook/src/main.cpp b/protocols/Facebook/src/main.cpp index 9692c7b828..7d87990901 100644 --- a/protocols/Facebook/src/main.cpp +++ b/protocols/Facebook/src/main.cpp @@ -20,8 +20,6 @@ along with this program. If not, see . #include "stdafx.h" -#pragma comment(lib, "Rpcrt4.lib") - CMPlugin g_plugin; bool g_bMessageState; diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp index 19c2f03a30..ef8fdbbaa3 100644 --- a/protocols/Facebook/src/proto.cpp +++ b/protocols/Facebook/src/proto.cpp @@ -57,13 +57,8 @@ FacebookProto::FacebookProto(const char *proto_name, const wchar_t *username) : m_szDeviceID = getMStringA(DBKEY_DEVICE_ID); if (m_szDeviceID.IsEmpty()) { - UUID deviceId; - UuidCreate(&deviceId); - RPC_CSTR szId; - UuidToStringA(&deviceId, &szId); - m_szDeviceID = szId; + m_szDeviceID = Utils_GenerateUUID(); setString(DBKEY_DEVICE_ID, m_szDeviceID); - RpcStringFreeA(&szId); } m_szClientID = getMStringA(DBKEY_CLIENT_ID); diff --git a/protocols/ICQ-WIM/src/http.cpp b/protocols/ICQ-WIM/src/http.cpp index c5fbdbc836..1bb6c21ffc 100644 --- a/protocols/ICQ-WIM/src/http.cpp +++ b/protocols/ICQ-WIM/src/http.cpp @@ -20,8 +20,6 @@ #include "stdafx.h" -#pragma comment(lib, "Rpcrt4.lib") - void CIcqProto::DropQueue() { mir_cslock lck(m_csHttpQueue); @@ -142,13 +140,7 @@ AsyncHttpRequest::AsyncHttpRequest(IcqConnection conn, int iType, const char *sz else if (*szUrl == '/') m_szUrl.Insert(0, "https://u.icq.net/wim"); - GUID packetId; - UuidCreate(&packetId); - - RPC_CSTR szId; - UuidToStringA(&packetId, &szId); - strncpy_s(m_reqId, (char*)szId, _TRUNCATE); - RpcStringFreeA(&szId); + strncpy_s(m_reqId, Utils_GenerateUUID(), _TRUNCATE); if (iType == REQUEST_POST) AddHeader("Content-Type", "application/x-www-form-urlencoded"); diff --git a/protocols/ICQ-WIM/src/server.cpp b/protocols/ICQ-WIM/src/server.cpp index 1135542926..2e31427eab 100644 --- a/protocols/ICQ-WIM/src/server.cpp +++ b/protocols/ICQ-WIM/src/server.cpp @@ -1062,15 +1062,10 @@ void CIcqProto::ShutdownSession() void CIcqProto::StartSession() { - ptrA szDeviceId(getStringA("DeviceId")); - if (szDeviceId == nullptr) { - UUID deviceId; - UuidCreate(&deviceId); - RPC_CSTR szId; - UuidToStringA(&deviceId, &szId); - szDeviceId = mir_strdup((char*)szId); + CMStringA szDeviceId(getMStringA("DeviceId")); + if (szDeviceId.IsEmpty()) { + szDeviceId = Utils_GenerateUUID(); setString("DeviceId", szDeviceId); - RpcStringFreeA(&szId); } int ts = TS(); diff --git a/src/mir_core/src/Windows/winutil.cpp b/src/mir_core/src/Windows/winutil.cpp index 6320622ada..cdc0f58251 100644 --- a/src/mir_core/src/Windows/winutil.cpp +++ b/src/mir_core/src/Windows/winutil.cpp @@ -133,3 +133,21 @@ MIR_CORE_DLL(int) Utils_CorrectFontSize(int size) return size * ncm.lfMessageFont.lfHeight / -12; } + +///////////////////////////////////////////////////////////////////////////////////////// + +#pragma comment(lib, "rpcrt4.lib") + +MIR_CORE_DLL(CMStringA) Utils_GenerateUUID() +{ + GUID packetId; + UuidCreate(&packetId); + + RPC_CSTR szId; + UuidToStringA(&packetId, &szId); + + CMStringA ret((char *)szId); + + RpcStringFreeA(&szId); + return ret; +} diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index 9ef066901d..5c192dbef0 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -1579,3 +1579,4 @@ _newStrW@4 @1789 NONAME ?GetPlainRtf@CCtrlRichEdit@@QAEPAD_N@Z @1804 NONAME ?SetTooltip@CCtrlMButton@@QAEXPBD@Z @1805 NONAME _db_event_delivered@8 @1806 NONAME +?Utils_GenerateUUID@@YG?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@XZ @1807 NONAME diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index 4e1ba01b17..ee09358441 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -1579,3 +1579,4 @@ newStrW @1789 NONAME ?GetPlainRtf@CCtrlRichEdit@@QEAAPEAD_N@Z @1804 NONAME ?SetTooltip@CCtrlMButton@@QEAAXPEBD@Z @1805 NONAME db_event_delivered @1806 NONAME +?Utils_GenerateUUID@@YA?AV?$CMStringT@DV?$ChTraitsCRT@D@@@@XZ @1807 NONAME -- cgit v1.2.3