summaryrefslogtreecommitdiff
path: root/protocols/ConnectionNotify/src/filter.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:44 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-03-02 12:32:55 +0300
commit931a7dc1ac0dbc7e6c1083583ced915e572f5b47 (patch)
tree9fe9a6448d44030e26aa7107ce16044ed413e0d0 /protocols/ConnectionNotify/src/filter.cpp
parentdd7d9954042254e66e3bbbec7195c6be8b1a0663 (diff)
all protocols (even virtual ones) moved to the Protocols folder
Diffstat (limited to 'protocols/ConnectionNotify/src/filter.cpp')
-rw-r--r--protocols/ConnectionNotify/src/filter.cpp141
1 files changed, 141 insertions, 0 deletions
diff --git a/protocols/ConnectionNotify/src/filter.cpp b/protocols/ConnectionNotify/src/filter.cpp
new file mode 100644
index 0000000000..e5cc01e98e
--- /dev/null
+++ b/protocols/ConnectionNotify/src/filter.cpp
@@ -0,0 +1,141 @@
+#include "stdafx.h"
+
+HWND filterAddDlg = nullptr;
+extern struct CONNECTION *connExceptions;
+extern HANDLE hFilterOptionsThread;
+extern DWORD FilterOptionsThreadId;
+extern struct CONNECTION *connCurrentEdit;
+extern BOOL settingDefaultAction;
+extern HANDLE hExceptionsMutex;
+extern BOOL bOptionsOpen;
+static unsigned __stdcall filterQueue(void *dummy);
+static INT_PTR CALLBACK ConnectionFilterEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
+
+HANDLE startFilterThread()
+{
+ return (HANDLE)mir_forkthreadex(filterQueue, nullptr, (unsigned int*)&FilterOptionsThreadId);
+}
+
+static unsigned __stdcall filterQueue(void *)
+{
+ BOOL bRet;
+ MSG msg;
+ //while(1)
+ while ((bRet = GetMessage(&msg, nullptr, 0, 0)) != 0)
+ {
+ if (msg.message == WM_ADD_FILTER)
+ {
+ struct CONNECTION *conn = (struct CONNECTION *)msg.lParam;
+ filterAddDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FILTER_DIALOG), nullptr, ConnectionFilterEditProc, (LPARAM)conn);
+ ShowWindow(filterAddDlg, SW_SHOW);
+
+ }
+ if (nullptr == filterAddDlg || !IsDialogMessage(filterAddDlg, &msg)) { /* Wine fix. */
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+ hFilterOptionsThread = nullptr;
+ return TRUE;
+}
+
+static INT_PTR CALLBACK ConnectionFilterEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ {
+ struct CONNECTION *conn = (struct CONNECTION*)lParam;
+ TranslateDialogDefault(hWnd);
+
+ SetDlgItemText(hWnd, ID_TEXT_NAME, conn->PName);
+ SetDlgItemText(hWnd, ID_TXT_LOCAL_IP, conn->strIntIp);
+ SetDlgItemText(hWnd, ID_TXT_REMOTE_IP, conn->strExtIp);
+ SetDlgItemInt(hWnd, ID_TXT_LOCAL_PORT, conn->intIntPort, FALSE);
+ SetDlgItemInt(hWnd, ID_TXT_REMOTE_PORT, conn->intExtPort, FALSE);
+ SendDlgItemMessage(hWnd, ID_CBO_ACTION, CB_ADDSTRING, 0, (LPARAM)TranslateT("Always show popup"));
+ SendDlgItemMessage(hWnd, ID_CBO_ACTION, CB_ADDSTRING, 0, (LPARAM)TranslateT("Never show popup"));
+ SendDlgItemMessage(hWnd, ID_CBO_ACTION, CB_SETCURSEL, 0, 0);
+ mir_free(conn);
+ return TRUE;
+ }
+ case WM_ACTIVATE:
+ if (0 == wParam) // becoming inactive
+ filterAddDlg = nullptr;
+ else // becoming active
+ filterAddDlg = hWnd;
+ return FALSE;
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case ID_OK:
+ {
+ wchar_t tmpPort[6];
+ if (bOptionsOpen)
+ {
+ MessageBox(hWnd, TranslateT("First close options window"), L"ConnectionNotify", MB_OK | MB_ICONSTOP);
+ break;
+ }
+ if (WAIT_OBJECT_0 == WaitForSingleObject(hExceptionsMutex, 100))
+ {
+ if (connCurrentEdit == nullptr)
+ {
+ connCurrentEdit = (struct CONNECTION*)mir_alloc(sizeof(struct CONNECTION));
+ connCurrentEdit->next = connExceptions;
+ connExceptions = connCurrentEdit;
+ }
+ GetDlgItemText(hWnd, ID_TXT_LOCAL_PORT, tmpPort, _countof(tmpPort));
+ if (tmpPort[0] == '*')
+ connCurrentEdit->intIntPort = -1;
+ else
+ connCurrentEdit->intIntPort = GetDlgItemInt(hWnd, ID_TXT_LOCAL_PORT, nullptr, FALSE);
+ GetDlgItemText(hWnd, ID_TXT_REMOTE_PORT, tmpPort, _countof(tmpPort));
+ if (tmpPort[0] == '*')
+ connCurrentEdit->intExtPort = -1;
+ else
+ connCurrentEdit->intExtPort = GetDlgItemInt(hWnd, ID_TXT_REMOTE_PORT, nullptr, FALSE);
+
+ GetDlgItemText(hWnd, ID_TXT_LOCAL_IP, connCurrentEdit->strIntIp, _countof(connCurrentEdit->strIntIp));
+ GetDlgItemText(hWnd, ID_TXT_REMOTE_IP, connCurrentEdit->strExtIp, _countof(connCurrentEdit->strExtIp));
+ GetDlgItemText(hWnd, ID_TEXT_NAME, connCurrentEdit->PName, _countof(connCurrentEdit->PName));
+
+ connCurrentEdit->Pid = !(BOOL)SendDlgItemMessage(hWnd, ID_CBO_ACTION, CB_GETCURSEL, 0, 0);
+ connCurrentEdit = nullptr;
+ saveSettingsConnections(connExceptions);
+ ReleaseMutex(hExceptionsMutex);
+ }
+ //EndDialog(hWnd,IDOK);
+ DestroyWindow(hWnd);
+ return TRUE;
+ }
+ case ID_CANCEL:
+ connCurrentEdit = nullptr;
+ DestroyWindow(hWnd);
+ //EndDialog(hWnd,IDCANCEL);
+ return TRUE;
+ }
+ return FALSE;
+
+ break;
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ case WM_DESTROY:
+ filterAddDlg = nullptr;
+ connCurrentEdit = nullptr;
+ //DestroyWindow(hWnd);
+ //PostQuitMessage(0);
+ break;
+ }
+ return FALSE;
+}
+
+BOOL checkFilter(struct CONNECTION *head, struct CONNECTION *conn)
+{
+ for (struct CONNECTION *cur = head; cur != nullptr; cur = cur->next)
+ if (wildcmpw(conn->PName, cur->PName) && wildcmpw(conn->strIntIp, cur->strIntIp) && wildcmpw(conn->strExtIp, cur->strExtIp)
+ && (cur->intIntPort == -1 || cur->intIntPort == conn->intIntPort) && (cur->intExtPort == -1 || cur->intExtPort == conn->intExtPort))
+ return cur->Pid;
+
+ return settingDefaultAction;
+}
+