Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/SoftEtherVPN/SoftEtherVPN_Stable.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordnobori <da.git@softether.co.jp>2015-04-03 23:58:09 +0300
committerdnobori <da.git@softether.co.jp>2015-04-03 23:58:09 +0300
commit983c19c043ae80ac528c3efb19668c0049817fec (patch)
tree7650d511ffd102d37954e7ae855e0b94f54138e1 /src/Mayaqua
parent18b120e5f747a84d26302ec706f6c1c91d642ace (diff)
v4.15-9539-beta
Diffstat (limited to 'src/Mayaqua')
-rw-r--r--src/Mayaqua/Microsoft.c237
-rw-r--r--src/Mayaqua/Microsoft.h24
2 files changed, 260 insertions, 1 deletions
diff --git a/src/Mayaqua/Microsoft.c b/src/Mayaqua/Microsoft.c
index 09f2f671..1c92db6d 100644
--- a/src/Mayaqua/Microsoft.c
+++ b/src/Mayaqua/Microsoft.c
@@ -215,6 +215,9 @@ static HANDLE hLsa = NULL;
static ULONG lsa_package_id = 0;
static TOKEN_SOURCE lsa_token_source;
static LOCK *vlan_lock = NULL;
+static COUNTER *suspend_handler_singleton = NULL;
+static COUNTER *vlan_card_counter = NULL;
+static volatile BOOL vlan_card_should_stop_flag = false;
// msi.dll
static HINSTANCE hMsi = NULL;
@@ -5769,6 +5772,229 @@ void MsGenerateUserModeSvcGlobalPulseName(char *name, UINT size, char *svc_name)
BinToStr(name, size, hash, sizeof(hash));
}
+// Declare the beginning of use of a VLAN card
+void MsBeginVLanCard()
+{
+ Inc(vlan_card_counter);
+}
+
+// Declare the ending of use of a VLAN card
+void MsEndVLanCard()
+{
+ Dec(vlan_card_counter);
+}
+
+// Return the flag whether the VLAN cards must be stopped
+bool MsIsVLanCardShouldStop()
+{
+ return vlan_card_should_stop_flag;
+}
+
+// Suspend procs
+void MsProcEnterSuspend()
+{
+ UINT64 giveup_tick = Tick64() + 2000;
+ UINT num = 0;
+
+ vlan_card_should_stop_flag = true;
+
+ while (true)
+ {
+ UINT64 now = Tick64();
+
+ if (now >= giveup_tick)
+ {
+ break;
+ }
+
+ if (Count(vlan_card_counter) == 0)
+ {
+ break;
+ }
+ num++;
+
+ SleepThread(100);
+ }
+
+ if (num >= 1)
+ {
+ SleepThread(512);
+ }
+}
+void MsProcLeaveSuspend()
+{
+ vlan_card_should_stop_flag = false;
+}
+
+// Suspend handler window proc
+LRESULT CALLBACK MsSuspendHandlerWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ MS_SUSPEND_HANDLER *h;
+ CREATESTRUCT *cs;
+ // Validate arguments
+ if (hWnd == NULL)
+ {
+ return 0;
+ }
+
+ h = (MS_SUSPEND_HANDLER *)GetWindowLongPtrA(hWnd, GWLP_USERDATA);
+ if (h == NULL && msg != WM_CREATE)
+ {
+ goto LABEL_END;
+ }
+
+ switch (msg)
+ {
+ case WM_CREATE:
+ cs = (CREATESTRUCT *)lParam;
+ h = (MS_SUSPEND_HANDLER *)cs->lpCreateParams;
+ SetWindowLongPtrA(hWnd, GWLP_USERDATA, (LONG_PTR)h);
+ break;
+
+ case WM_POWERBROADCAST:
+ switch (wParam)
+ {
+ case PBT_APMSUSPEND:
+ MsProcEnterSuspend();
+ return 1;
+
+ case PBT_APMRESUMEAUTOMATIC:
+ case PBT_APMRESUMESUSPEND:
+ MsProcLeaveSuspend();
+ return 1;
+ }
+ break;
+
+ case WM_LBUTTONUP:
+ /*
+ MsProcEnterSuspend();
+ MsgBox(hWnd, 0, L"TEST");
+ MsProcLeaveSuspend();*/
+ break;
+
+ case WM_CLOSE:
+ /*if (h->AboutToClose == false)
+ {
+ return 0;
+ }*/
+ break;
+
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ }
+
+LABEL_END:
+ return DefWindowProc(hWnd, msg, wParam, lParam);
+}
+
+// Suspend handler thread
+void MsSuspendHandlerThreadProc(THREAD *thread, void *param)
+{
+ char wndclass_name[MAX_PATH];
+ WNDCLASS wc;
+ HWND hWnd;
+ MSG msg;
+ MS_SUSPEND_HANDLER *h = (MS_SUSPEND_HANDLER *)param;
+ // Validate arguments
+ if (h == NULL || thread == NULL)
+ {
+ return;
+ }
+
+ Format(wndclass_name, sizeof(wndclass_name), "WNDCLASS_%X", Rand32());
+
+ Zero(&wc, sizeof(wc));
+ wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hIcon = NULL;
+ wc.hInstance = ms->hInst;
+ wc.lpfnWndProc = MsSuspendHandlerWindowProc;
+ wc.lpszClassName = wndclass_name;
+ if (RegisterClassA(&wc) == 0)
+ {
+ NoticeThreadInit(thread);
+ return;
+ }
+
+ hWnd = CreateWindowA(wndclass_name, wndclass_name, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, ms->hInst, h);
+
+ h->hWnd = hWnd;
+
+ NoticeThreadInit(thread);
+
+ if (hWnd == NULL)
+ {
+ UnregisterClassA(wndclass_name, ms->hInst);
+ return;
+ }
+
+ //ShowWindow(hWnd, SW_SHOWNORMAL);
+
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ vlan_card_should_stop_flag = false;
+
+ DestroyWindow(hWnd);
+
+ UnregisterClassA(wndclass_name, ms->hInst);
+}
+
+// New suspend handler
+MS_SUSPEND_HANDLER *MsNewSuspendHandler()
+{
+ THREAD *t;
+ MS_SUSPEND_HANDLER *h;
+
+ if (Inc(suspend_handler_singleton) >= 2)
+ {
+ Dec(suspend_handler_singleton);
+ return NULL;
+ }
+
+ h = ZeroMalloc(sizeof(MS_SUSPEND_HANDLER));
+
+ t = NewThread(MsSuspendHandlerThreadProc, h);
+
+ WaitThreadInit(t);
+
+ h->Thread = t;
+
+ vlan_card_should_stop_flag = false;
+
+ return h;
+}
+
+void MsFreeSuspendHandler(MS_SUSPEND_HANDLER *h)
+{
+ // Validate arguments
+ if (h == NULL)
+ {
+ return;
+ }
+
+ if (h->hWnd != NULL)
+ {
+ h->AboutToClose = true;
+ PostMessageA(h->hWnd, WM_CLOSE, 0, 0);
+ }
+
+ WaitThread(h->Thread, INFINITE);
+ ReleaseThread(h->Thread);
+
+ Free(h);
+
+ Dec(suspend_handler_singleton);
+
+ vlan_card_should_stop_flag = false;
+}
+
// Start in user mode
void MsUserMode(char *title, SERVICE_FUNCTION *start, SERVICE_FUNCTION *stop, UINT icon)
{
@@ -14212,6 +14438,10 @@ void MsInit()
return;
}
+ suspend_handler_singleton = NewCounter();
+ vlan_card_counter = NewCounter();
+ vlan_card_should_stop_flag = false;
+
ms = ZeroMalloc(sizeof(MS));
// Getting instance handle
@@ -14685,6 +14915,13 @@ void MsFree()
// Delete the lock
DeleteLock(vlan_lock);
vlan_lock = NULL;
+
+ DeleteCounter(suspend_handler_singleton);
+ suspend_handler_singleton = NULL;
+
+ DeleteCounter(vlan_card_counter);
+ vlan_card_counter = NULL;
+ vlan_card_should_stop_flag = false;
}
// Directory acquisition related
diff --git a/src/Mayaqua/Microsoft.h b/src/Mayaqua/Microsoft.h
index e8683fc9..6685e197 100644
--- a/src/Mayaqua/Microsoft.h
+++ b/src/Mayaqua/Microsoft.h
@@ -181,6 +181,9 @@ typedef void *HWND;
#define VLAN_CONNECTION_NAME_OLD "%s - SoftEther VPN Client 2.0"
+// Suspend handler windows class name
+#define MS_SUSPEND_HANDLER_WNDCLASSNAME "MS_SUSPEND_HANDLER"
+
// Command line format in the service mode
#define SVC_RUN_COMMANDLINE L"\"%s\" /service"
@@ -632,6 +635,14 @@ typedef struct MS_DRIVER_VER
UINT Major, Minor, Build;
} MS_DRIVER_VER;
+// Suspend handler
+typedef struct MS_SUSPEND_HANDLER
+{
+ HWND hWnd;
+ THREAD *Thread;
+ volatile bool AboutToClose;
+} MS_SUSPEND_HANDLER;
+
// Function prototype
void MsInit();
@@ -1139,6 +1150,15 @@ void MsTest();
bool MsSaveSystemInfo(wchar_t *dst_filename);
bool MsCollectVpnInfo(BUF *bat, char *tmpdir, char *svc_name, wchar_t *config_name, wchar_t *logdir_name);
+MS_SUSPEND_HANDLER *MsNewSuspendHandler();
+void MsFreeSuspendHandler(MS_SUSPEND_HANDLER *h);
+
+void MsBeginVLanCard();
+void MsEndVLanCard();
+bool MsIsVLanCardShouldStop();
+void MsProcEnterSuspend();
+void MsProcLeaveSuspend();
+
// Inner functions
#ifdef MICROSOFT_C
@@ -1173,8 +1193,10 @@ HANDLE MsCreateUserToken();
SID *MsGetSidFromAccountName(char *name);
void MsFreeSid(SID *sid);
bool CALLBACK MsEnumResourcesInternalProc(HMODULE hModule, const char *type, char *name, LONG_PTR lParam);
-
void CALLBACK MsScmDispatcher(DWORD argc, LPTSTR *argv);
+LRESULT CALLBACK MsSuspendHandlerWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+void MsSuspendHandlerThreadProc(THREAD *thread, void *param);
+
#endif // MICROSOFT_C