Mute echo message if repeated or disabled

- Suppress messages with exactly same content as previously
  displayed within popup_mute_interval (24h by default). This parameter
  may be set on command line as "--popup_mute_interval n" where n is
  in hours.

- Command line option '--disable_popup_messages' disables all echo
  message popups (window and notification).

This patch only handles suppression of repeated messages during
reconnections.
TODO: Persist message history in the registry and use it to mute
repeated messages after disconnects and across restarts of the GUI.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/391/head
Selva Nair 7 years ago
parent 9c914305d9
commit 82e17b239e

@ -35,6 +35,8 @@
#include "openvpn-gui-res.h"
#include "localization.h"
extern options_t o;
/* echo msg types */
#define ECHO_MSG_WINDOW (1)
#define ECHO_MSG_NOTIFY (2)
@ -80,12 +82,44 @@ echo_msg_add_fp(struct echo_msg *msg, time_t timestamp)
return;
}
/* Add message to history -- update if already present */
/* find message with given digest in history */
static struct echo_msg_history *
echo_msg_recall(const BYTE *digest, struct echo_msg_history *hist)
{
for( ; hist; hist = hist->next)
{
if (memcmp(hist->fp.digest, digest, HASHLEN) == 0) break;
}
return hist;
}
/* Add an item to message history and return the head of the list */
static struct echo_msg_history*
echo_msg_history_add(struct echo_msg_history *head, const struct echo_msg_fp *fp)
{
struct echo_msg_history *hist = malloc(sizeof(struct echo_msg_history));
if (hist)
{
memcpy(&hist->fp, fp, sizeof(*fp));
hist->next = head;
head = hist;
}
return head;
}
/* Save message in history -- update if already present */
static void
echo_msg_save(struct echo_msg *msg)
{
/* Not implemented */
return;
struct echo_msg_history *hist = echo_msg_recall(msg->fp.digest, msg->history);
if (hist) /* update */
{
hist->fp.timestamp = msg->fp.timestamp;
}
else /* add */
{
msg->history = echo_msg_history_add(msg->history, &msg->fp);
}
}
/* persist echo msg history to the registry */
@ -108,8 +142,10 @@ echo_msg_load(connection_t *c)
static BOOL
echo_msg_repeated(const struct echo_msg *msg)
{
/* Not implemented */
return false;
const struct echo_msg_history *hist;
hist = echo_msg_recall(msg->fp.digest, msg->history);
return (hist && (hist->fp.timestamp + o.popup_mute_interval*3600 > msg->fp.timestamp));
}
/* Append a line of echo msg */

@ -133,6 +133,10 @@ AddConfigFileToList(int config, const TCHAR *filename, const TCHAR *config_dir)
if (IsKeyPassSaved(c->config_name))
c->flags |= FLAG_SAVE_KEY_PASS;
}
if (o.disable_popup_messages)
{
DisablePopupMessages(c);
}
}
#define FLAG_WARN_DUPLICATES (0x1)

@ -285,6 +285,15 @@ add_option(options_t *options, int i, TCHAR **p)
exit(1);
}
}
else if (streq(p[0], _T("popup_mute_interval")) && p[1])
{
++i;
options->popup_mute_interval = _ttoi(p[1]);
}
else if (streq(p[0], _T("disable_popup_messages")))
{
options->disable_popup_messages = 1;
}
else
{
/* Unrecognized option or missing parameter */
@ -679,3 +688,10 @@ DisableSavePasswords(connection_t *c)
c->flags &= ~(FLAG_SAVE_AUTH_PASS | FLAG_SAVE_KEY_PASS);
c->flags |= FLAG_DISABLE_SAVE_PASS;
}
/* Do not show popup messages generated by echo msg directives */
void
DisablePopupMessages(connection_t *c)
{
c->flags |= FLAG_DISABLE_ECHO_MSG;
}

@ -207,6 +207,8 @@ typedef struct {
DWORD disconnectscript_timeout; /* Disconnect Script execution timeout (sec) */
DWORD preconnectscript_timeout; /* Preconnect Script execution timeout (sec) */
DWORD config_menu_view; /* 0 for auto, 1 for original flat menu, 2 for hierarchical */
DWORD disable_popup_messages; /* set nonzero to suppress all echo msg messages */
DWORD popup_mute_interval; /* Interval in hours to suppress repeated echo messages */
#ifdef DEBUG
FILE *debug_fp;
@ -236,6 +238,7 @@ INT_PTR CALLBACK ScriptSettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
INT_PTR CALLBACK ConnectionSettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK AdvancedSettingsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
void DisableSavePasswords(connection_t *);
void DisablePopupMessages(connection_t *);
void ExpandOptions(void);
int CompareStringExpanded(const WCHAR *str1, const WCHAR *str2);

@ -63,6 +63,8 @@ struct regkey_int {
{L"show_script_window", &o.show_script_window, 0},
{L"service_only", &o.service_only, 0},
{L"config_menu_view", &o.config_menu_view, CONFIG_VIEW_AUTO}
{L"popup_mute_interval", &o.popup_mute_interval, 24},
{L"disable_popup_messages", &o.disable_popup_messages, 0},
};
static int

Loading…
Cancel
Save