Sat, 23 Nov 2024 19:42:35 -0600
Remove dead Windows code
`winpidgin_get_lastactive` and the `Dwm*` function prototypes are not used by anything.
`purple_got_protocol_handler_uri` no longer exists, so there's no need to run a message-only window to process those requests. And without that window, there's no need to track `HINSTANCE` for the DLL and EXE.
Also, remove some outdated `#include`.
Testing Done:
Cross-compiled in mingw.
Reviewed at https://reviews.imfreedom.org/r/3675/
--- a/libpurple/win32/win32dep.c Sat Nov 23 19:39:07 2024 -0600 +++ b/libpurple/win32/win32dep.c Sat Nov 23 19:42:35 2024 -0600 @@ -31,7 +31,6 @@ #include "debug.h" #include "glibcompat.h" -#include "notify.h" #define MAX_PATH_LEN 2048
--- a/pidgin/libpidgin.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/libpidgin.c Sat Nov 23 19:42:35 2024 -0600 @@ -69,9 +69,5 @@ */ g_object_unref(app); -#ifdef _WIN32 - winpidgin_cleanup(); -#endif - return ret; }
--- a/pidgin/pidgin.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/pidgin.c Sat Nov 23 19:42:35 2024 -0600 @@ -28,8 +28,8 @@ #ifdef _WIN32 /* suppress gcc "no previous prototype" warning */ G_MODULE_EXPORT -int __cdecl pidgin_main(HINSTANCE hint, int argc, char *argv[]); -int __cdecl pidgin_main(HINSTANCE hint, int argc, char *argv[]) +int __cdecl pidgin_main(int argc, char *argv[]); +int __cdecl pidgin_main(int argc, char *argv[]) #else int main(int argc, char *argv[]) #endif @@ -47,9 +47,5 @@ g_set_application_name(PIDGIN_NAME); -#ifdef _WIN32 - winpidgin_set_exe_hinstance(hint); -#endif - return pidgin_start(argc, argv); }
--- a/pidgin/pidginapplication.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/pidginapplication.c Sat Nov 23 19:42:35 2024 -0600 @@ -766,10 +766,6 @@ pidgin_application_setup_debug(PIDGIN_APPLICATION(application)); -#ifdef _WIN32 - winpidgin_init(); -#endif - if(!purple_core_init(pidgin_ui_new(), &error)) { AdwDialog *dialog = NULL; const char *error_message = "unknown error";
--- a/pidgin/win32/gtkwin32dep.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/win32/gtkwin32dep.c Sat Nov 23 19:42:35 2024 -0600 @@ -40,122 +40,17 @@ #include "resource.h" #include "gtkwin32dep.h" -#include "pidgindisplaywindow.h" - -/* - * GLOBALS - */ -HINSTANCE exe_hInstance = 0; -HINSTANCE dll_hInstance = 0; -HWND messagewin_hwnd; /* * PUBLIC CODE */ -HINSTANCE winpidgin_exe_hinstance(void) { - return exe_hInstance; -} - -void winpidgin_set_exe_hinstance(HINSTANCE hint) -{ - exe_hInstance = hint; -} - -HINSTANCE winpidgin_dll_hinstance(void) { - return dll_hInstance; -} - -#define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14) - -static LRESULT CALLBACK -message_window_handler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - if (msg == PIDGIN_WM_PROTOCOL_HANDLE) { - char *proto_msg = (char *) lparam; - purple_debug_info("winpidgin", "Got protocol handler request: %s\n", proto_msg ? proto_msg : ""); - purple_got_protocol_handler_uri(proto_msg); - return TRUE; - } - - return DefWindowProc(hwnd, msg, wparam, lparam); -} - -static HWND winpidgin_message_window_init(void) { - HWND win_hwnd; - WNDCLASSEX wcx; - LPCTSTR wname; - - wname = TEXT("WinpidginMsgWinCls"); - - wcx.cbSize = sizeof(wcx); - wcx.style = 0; - wcx.lpfnWndProc = message_window_handler; - wcx.cbClsExtra = 0; - wcx.cbWndExtra = 0; - wcx.hInstance = winpidgin_exe_hinstance(); - wcx.hIcon = NULL; - wcx.hCursor = NULL; - wcx.hbrBackground = NULL; - wcx.lpszMenuName = NULL; - wcx.lpszClassName = wname; - wcx.hIconSm = NULL; - - RegisterClassEx(&wcx); - - /* Create the window */ - if(!(win_hwnd = CreateWindow(wname, TEXT("WinpidginMsgWin"), 0, 0, 0, 0, 0, - NULL, NULL, winpidgin_exe_hinstance(), 0))) { - purple_debug_error("winpidgin", - "Unable to create message window.\n"); - return NULL; - } - - return win_hwnd; -} - -void winpidgin_init(void) { - if (purple_debug_is_verbose()) - purple_debug_misc("winpidgin", "winpidgin_init start\n"); - - messagewin_hwnd = winpidgin_message_window_init(); - - if (purple_debug_is_verbose()) - purple_debug_misc("winpidgin", "winpidgin_init end\n"); -} - -/* Windows Cleanup */ - -void winpidgin_cleanup(void) { - purple_debug_info("winpidgin", "winpidgin_cleanup\n"); - - if(messagewin_hwnd) - DestroyWindow(messagewin_hwnd); - -} - /* DLL initializer */ /* suppress gcc "no previous prototype" warning */ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved); -BOOL WINAPI DllMain(HINSTANCE hinstDLL, G_GNUC_UNUSED DWORD fdwReason, G_GNUC_UNUSED LPVOID lpvReserved) { - dll_hInstance = hinstDLL; +BOOL WINAPI +DllMain(G_GNUC_UNUSED HINSTANCE hinstDLL, G_GNUC_UNUSED DWORD fdwReason, + G_GNUC_UNUSED LPVOID lpvReserved) +{ return TRUE; } - -typedef HRESULT (WINAPI* DwmIsCompositionEnabledFunction)(BOOL*); -typedef HRESULT (WINAPI* DwmGetWindowAttributeFunction)(HWND, DWORD, PVOID, DWORD); -#ifndef DWMWA_EXTENDED_FRAME_BOUNDS -# define DWMWA_EXTENDED_FRAME_BOUNDS 9 -#endif - -DWORD winpidgin_get_lastactive() { - DWORD result = 0; - - LASTINPUTINFO lii; - memset(&lii, 0, sizeof(lii)); - lii.cbSize = sizeof(lii); - if (GetLastInputInfo(&lii)) - result = lii.dwTime; - - return result; -} -
--- a/pidgin/win32/gtkwin32dep.h Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/win32/gtkwin32dep.h Sat Nov 23 19:42:35 2024 -0600 @@ -25,16 +25,5 @@ #include <purple.h> -HINSTANCE winpidgin_dll_hinstance(void); -HINSTANCE winpidgin_exe_hinstance(void); -void winpidgin_set_exe_hinstance(HINSTANCE hint); - -/* Misc */ -DWORD winpidgin_get_lastactive(void); - -/* init / cleanup */ -void winpidgin_init(void); -void winpidgin_cleanup(void); - #endif /* _GTKWIN32DEP_H_ */
--- a/pidgin/win32/winpidgin.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/win32/winpidgin.c Sat Nov 23 19:42:35 2024 -0600 @@ -50,7 +50,7 @@ # define PIDGIN_WIN32_UNUSED #endif -typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**); +typedef int (__cdecl* LPFNPIDGINMAIN)(int, char**); typedef BOOL (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR); typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD); typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD); @@ -72,90 +72,8 @@ return err_msg; } -#define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14) - -#define PROTO_HANDLER_SWITCH L"--protocolhandler=" - -static void handle_protocol(wchar_t *cmd) { - char *remote_msg, *utf8msg; - wchar_t *tmp1, *tmp2; - int len, wlen; - SIZE_T len_written; - HWND msg_win; - DWORD pid; - HANDLE process; - - /* The start of the message */ - tmp1 = cmd + wcslen(PROTO_HANDLER_SWITCH); - - /* The end of the message */ - if ((tmp2 = wcschr(tmp1, L' '))) - wlen = (tmp2 - tmp1); - else - wlen = wcslen(tmp1); - - if (wlen == 0) { - wprintf(L"No protocol message specified.\n"); - return; - } - - if (!(msg_win = FindWindowExW(NULL, NULL, L"WinpidginMsgWinCls", NULL))) { - wprintf(L"Unable to find an instance of Pidgin to handle protocol message.\n"); - return; - } - - len = WideCharToMultiByte(CP_UTF8, 0, tmp1, - wlen, NULL, 0, NULL, NULL); - if (len) { - utf8msg = malloc(len); - len = WideCharToMultiByte(CP_UTF8, 0, tmp1, - wlen, utf8msg, len, NULL, NULL); - } - - if (len == 0) { - wprintf(L"No protocol message specified.\n"); - return; - } - - GetWindowThreadProcessId(msg_win, &pid); - if (!(process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, pid))) { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to open Pidgin process. (%u) %ls\n", - (UINT)dw, err_msg); - return; - } - - wprintf(L"Trying to handle protocol message:\n'%.*ls'\n", wlen, tmp1); - - /* MEM_COMMIT initializes the memory to zero - * so we don't need to worry that our section of utf8msg isn't nul-terminated */ - if ((remote_msg = (char*) VirtualAllocEx(process, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE))) { - if (WriteProcessMemory(process, remote_msg, utf8msg, len, &len_written)) { - if (!SendMessageA(msg_win, PIDGIN_WM_PROTOCOL_HANDLE, len_written, (LPARAM) remote_msg)) - printf("Unable to send protocol message to Pidgin instance.\n"); - } else { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to write to remote memory. (%u) %ls\n", - (UINT)dw, err_msg); - } - - VirtualFreeEx(process, remote_msg, 0, MEM_RELEASE); - } else { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to allocate remote memory. (%u) %ls\n", - (UINT)dw, err_msg); - } - - CloseHandle(process); - free(utf8msg); -} - - int __stdcall -WinMain(struct HINSTANCE__ *hInstance, +WinMain(PIDGIN_WIN32_UNUSED struct HINSTANCE__ *hInstance, PIDGIN_WIN32_UNUSED struct HINSTANCE__ *hPrevInstance, PIDGIN_WIN32_UNUSED char *lpszCmdLine, PIDGIN_WIN32_UNUSED int nCmdShow) @@ -165,11 +83,10 @@ wchar_t *pidgin_dir_start = NULL; wchar_t exe_name[MAX_PATH]; HMODULE hmod; - wchar_t *wtmp; int pidgin_argc; char **pidgin_argv; /* This is in utf-8 */ int i, j, k; - BOOL debug = FALSE, help = FALSE, version = FALSE, multiple = FALSE, success; + BOOL debug = FALSE, help = FALSE, version = FALSE, success; LPWSTR *szArglist; LPWSTR cmdLine; @@ -184,8 +101,6 @@ help = TRUE; else if (strstr(__argv[i], "--version") == __argv[i]) version = TRUE; - else if (strstr(__argv[i], "--multiple") == __argv[i]) - multiple = TRUE; } else { if (strchr(__argv[i], 'd')) debug = TRUE; @@ -193,8 +108,6 @@ help = TRUE; if (strchr(__argv[i], 'v')) version = TRUE; - if (strchr(__argv[i], 'm')) - multiple = TRUE; } } } @@ -225,12 +138,6 @@ cmdLine = GetCommandLineW(); - /* If this is a protocol handler invocation, deal with it accordingly */ - if ((wtmp = wcsstr(cmdLine, PROTO_HANDLER_SWITCH)) != NULL) { - handle_protocol(wtmp); - return 0; - } - /* Load exception handler if we have it */ if (GetModuleFileNameW(NULL, pidgin_dir, MAX_PATH) != 0) { @@ -389,6 +296,5 @@ } LocalFree(szArglist); - - return pidgin_main(hInstance, pidgin_argc, pidgin_argv); + return pidgin_main(pidgin_argc, pidgin_argv); }