mirror of https://github.com/OpenVPN/openvpn-gui
Notify dialog windows when OpenVPN state changes
Use a custom message to pass state change notification from OpenVPN to all top level windows in the thread. Currently only the pending auth dialog responds to this message by closing when the state changes. The state change could be due to timeout, errors or success via out-of-band authentication which makes the dialog no longer valid. The case of CR_TEXT messages that do not require a response is handled in the next commit. See also issue #440 https://github.com/OpenVPN/openvpn-gui/issues/440 Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/443/head
parent
fcc964bf95
commit
131c75e560
1
main.h
1
main.h
|
@ -61,6 +61,7 @@
|
|||
#define WM_OVPN_IMPORT (WM_APP + 20)
|
||||
#define WM_OVPN_RESCAN (WM_APP + 21)
|
||||
#define WM_OVPN_ECHOMSG (WM_APP + 22)
|
||||
#define WM_OVPN_STATE (WM_APP + 23)
|
||||
|
||||
/* bool definitions */
|
||||
#define bool int
|
||||
|
|
31
openvpn.c
31
openvpn.c
|
@ -248,6 +248,20 @@ parse_assigned_ip(connection_t *c, const char *msg)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a custom message to Window hwnd when state changes
|
||||
* hwnd : handle of the window to which the message is sent
|
||||
* lParam : pointer to the state string (char *) received from
|
||||
* OpenVPN daemon (e., "CONNECTED")
|
||||
* The function signature matches callback for EnumThreadWindows.
|
||||
*/
|
||||
BOOL
|
||||
NotifyStateChange(HWND hwnd, LPARAM lParam)
|
||||
{
|
||||
SendMessage(hwnd, WM_OVPN_STATE, 0, lParam);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle a state change notification from the OpenVPN management interface
|
||||
* Format <TIMESTAMP>,<STATE>,[<MESSAGE>],[<LOCAL_IP>][,<REMOTE_IP>]
|
||||
|
@ -274,6 +288,9 @@ OnStateChange(connection_t *c, char *data)
|
|||
return;
|
||||
*pos = '\0';
|
||||
|
||||
/* notify the all windows in the thread of state change */
|
||||
EnumThreadWindows(GetCurrentThreadId(), NotifyStateChange, (LPARAM) state);
|
||||
|
||||
if (strcmp(state, "CONNECTED") == 0)
|
||||
{
|
||||
parse_assigned_ip(c, pos + 1);
|
||||
|
@ -764,6 +781,20 @@ GenericPassDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||
}
|
||||
break;
|
||||
|
||||
case WM_OVPN_STATE: /* state change message is received from OpenVPN daemon */
|
||||
/*
|
||||
* AUTH_PENDING immediately transitions to GET_CONFIG until
|
||||
* auth succeeds or connection restarts/aborts.
|
||||
* Close the CR_TEXT dialog if state changes to anything
|
||||
* other than GET_CONFIG. The state is in lParam.
|
||||
*/
|
||||
param = (auth_param_t *) GetProp(hwndDlg, cfgProp);
|
||||
if ((param->flags & FLAG_CR_TYPE_CRTEXT)
|
||||
&& strcmp((const char *) lParam, "GET_CONFIG"))
|
||||
{
|
||||
EndDialog(hwndDlg, LOWORD(wParam));
|
||||
}
|
||||
return TRUE;
|
||||
case WM_CLOSE:
|
||||
EndDialog(hwndDlg, LOWORD(wParam));
|
||||
return TRUE;
|
||||
|
|
Loading…
Reference in New Issue