@ -42,9 +42,121 @@
/* Global options structure */
/* Global options structure */
options_t o ;
options_t o ;
int state_connected = connected , state_disconnected = disconnected ,
int state_connected = connected , state_disconnected = disconnected ,
state_onhold = onhold ;
state_onhold = onhold ;
static connection_t * active_profile ;
/* Override management handlers that generate user dialogs
* and pass them on only for currently active profile .
* Also ensure no unwanted popus are generated .
*/
static void
OnStop_ ( connection_t * c , UNUSED char * msg )
{
dmsg ( L " profile: %ls with state = %d " , c - > config_name , c - > state ) ;
/* do not show any popup error messages */
c - > state = disconnected ;
SetDlgItemText ( c - > hwndStatus , ID_TXT_STATUS , LoadLocalizedString ( IDS_NFO_STATE_DISCONNECTED ) ) ;
SetStatusWinIcon ( c - > hwndStatus , ID_ICO_DISCONNECTED ) ;
SendMessage ( c - > hwndStatus , WM_CLOSE , 0 , 0 ) ;
}
/* Override OnInfoMsg: We filter out anything other
* than CR_TEXT : In particular , OPEN_URL is not supported
* in PLAP context .
*/
static void
OnInfoMsg_ ( connection_t * c , char * msg )
{
if ( strbegins ( msg , " CR_TEXT: " ) )
{
if ( c = = active_profile )
{
OnInfoMsg ( c , msg ) ;
}
else
{
DetachOpenVPN ( c ) ; /* next attach will handle it */
}
}
}
static void
OnNeedOk_ ( connection_t * c , char * msg )
{
if ( c = = active_profile )
{
OnNeedOk ( c , msg ) ;
}
else
{
DetachOpenVPN ( c ) ; /* next attach will handle it */
}
}
static void
OnNeedStr_ ( connection_t * c , char * msg )
{
if ( c = = active_profile )
{
OnNeedStr ( c , msg ) ;
}
else
{
DetachOpenVPN ( c ) ; /* next attach will handle it */
}
}
static void
OnPassword_ ( connection_t * c , char * msg )
{
if ( c = = active_profile )
{
OnPassword ( c , msg ) ;
}
else
{
DetachOpenVPN ( c ) ; /* next attach will handle it */
}
}
static void
OnProxy_ ( connection_t * c , char * msg )
{
if ( c = = active_profile )
{
OnProxy ( c , msg ) ;
}
else
{
DetachOpenVPN ( c ) ; /* next attach will handle it */
}
}
/* Intercept state change. Keep track of previous state and handle
* cases like user wants to disconnect but connection completed in
* the meantime .
*/
void
OnStateChange_ ( connection_t * c , char * msg )
{
int state_prev = c - > state ;
OnStateChange ( c , msg ) ;
if ( c - > state = = connected & & state_prev = = disconnecting )
{
/* connection completed while user clicked disconnect,
* let disconnect process continue . This is required to
* retain the hold state after SIGHUP restart .
*/
c - > state = disconnecting ;
}
}
/* Initialize GUI data structures. Returns 0 on success */
/* Initialize GUI data structures. Returns 0 on success */
DWORD
DWORD
InitializeUI ( HINSTANCE hinstance )
InitializeUI ( HINSTANCE hinstance )
@ -90,15 +202,15 @@ InitializeUI(HINSTANCE hinstance)
{ ready_ , OnReady } ,
{ ready_ , OnReady } ,
{ hold_ , OnHold } ,
{ hold_ , OnHold } ,
{ log_ , OnLogLine } ,
{ log_ , OnLogLine } ,
{ state_ , OnStateChange } ,
{ state_ , OnStateChange _ } ,
{ password_ , OnPassword } ,
{ password_ , OnPassword _ } ,
{ proxy_ , OnProxy } ,
{ proxy_ , OnProxy _ } ,
{ stop_ , OnStop } ,
{ stop_ , OnStop _ } ,
{ needok_ , OnNeedOk } ,
{ needok_ , OnNeedOk _ } ,
{ needstr_ , OnNeedStr } ,
{ needstr_ , OnNeedStr _ } ,
{ echo_ , OnEcho } ,
{ echo_ , OnEcho } ,
{ bytecount_ , OnByteCount } ,
{ bytecount_ , OnByteCount } ,
{ infomsg_ , OnInfoMsg } ,
{ infomsg_ , OnInfoMsg _ } ,
{ timeout_ , OnTimeout } ,
{ timeout_ , OnTimeout } ,
{ 0 , NULL }
{ 0 , NULL }
} ;
} ;
@ -356,3 +468,12 @@ DisconnectHelper(connection_t *c)
dmsg ( L " profile: %ls state = %d " , c - > config_name , c - > state ) ;
dmsg ( L " profile: %ls state = %d " , c - > config_name , c - > state ) ;
}
}
/* Set the currently active profile in Connect() operation -- pass NULL to unset.
* We allow UI dialogs only on the current profile .
*/
void
SetActiveProfile ( connection_t * c )
{
active_profile = c ;
}