If "!=" or "ne" are used in a display filter, warn the user that the results
may be unexpected. svn path=/trunk/; revision=24232
This commit is contained in:
parent
f3747bf637
commit
9703c2bb75
|
@ -39,6 +39,7 @@ struct _dfilter_t {
|
|||
gboolean *attempted_load;
|
||||
int *interesting_fields;
|
||||
int num_interesting_fields;
|
||||
GPtrArray *deprecated;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -115,6 +115,7 @@ dfilter_new(void)
|
|||
|
||||
df = g_new(dfilter_t, 1);
|
||||
df->insns = NULL;
|
||||
df->deprecated = NULL;
|
||||
|
||||
return df;
|
||||
}
|
||||
|
@ -219,6 +220,9 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
dfilter_t *dfilter;
|
||||
dfwork_t *dfw;
|
||||
gboolean failure = FALSE;
|
||||
char *depr_test;
|
||||
guint i;
|
||||
GPtrArray *deprecated = g_ptr_array_new();
|
||||
|
||||
dfilter_error_msg = NULL;
|
||||
|
||||
|
@ -245,6 +249,22 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
break;
|
||||
}
|
||||
|
||||
/* See if the node is deprecated */
|
||||
depr_test = stnode_deprecated(df_lval);
|
||||
|
||||
if (depr_test) {
|
||||
for (i = 0; i < deprecated->len; i++) {
|
||||
if (strcasecmp(depr_test, g_ptr_array_index(deprecated, i)) == 0) {
|
||||
/* It's already in our list */
|
||||
depr_test = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (depr_test) {
|
||||
g_ptr_array_add(deprecated, depr_test);
|
||||
}
|
||||
|
||||
/* Give the token to the parser */
|
||||
Dfilter(ParserObj, token, df_lval, dfw);
|
||||
/* We've used the stnode_t, so we don't want to free it */
|
||||
|
@ -254,6 +274,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
failure = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
} /* while (1) */
|
||||
|
||||
/* If we created an stnode_t but didn't use it, free it; the
|
||||
|
@ -285,6 +306,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
* it and set *dfp to NULL */
|
||||
if (dfw->st_root == NULL) {
|
||||
*dfp = NULL;
|
||||
g_ptr_array_free(deprecated, TRUE);
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -314,6 +336,9 @@ dfilter_compile(const gchar *text, dfilter_t **dfp)
|
|||
/* Initialize constants */
|
||||
dfvm_init_const(dfilter);
|
||||
|
||||
/* Add any deprecated items */
|
||||
dfilter->deprecated = deprecated;
|
||||
|
||||
/* And give it to the user. */
|
||||
*dfp = dfilter;
|
||||
}
|
||||
|
@ -325,6 +350,7 @@ FAILURE:
|
|||
if (dfw) {
|
||||
dfwork_free(dfw);
|
||||
}
|
||||
g_ptr_array_free(deprecated, TRUE);
|
||||
dfilter_fail("Unable to parse filter string \"%s\".", text);
|
||||
*dfp = NULL;
|
||||
return FALSE;
|
||||
|
@ -355,9 +381,28 @@ dfilter_prime_proto_tree(const dfilter_t *df, proto_tree *tree)
|
|||
}
|
||||
}
|
||||
|
||||
GPtrArray *
|
||||
dfilter_deprecated_tokens(dfilter_t *df) {
|
||||
if (df->deprecated && df->deprecated->len > 0) {
|
||||
return df->deprecated;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
dfilter_dump(dfilter_t *df)
|
||||
{
|
||||
guint i;
|
||||
gchar *sep = "";
|
||||
|
||||
dfvm_dump(stdout, df->insns);
|
||||
|
||||
if (df->deprecated && df->deprecated->len) {
|
||||
printf("\nDeprecated tokens: ");
|
||||
for (i = 0; i < df->deprecated->len; i++) {
|
||||
printf("%s\"%s\"", sep, (char *) g_ptr_array_index(df->deprecated, i));
|
||||
sep = ", ";
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,9 @@ dfilter_apply(dfilter_t *df, proto_tree *tree);
|
|||
void
|
||||
dfilter_prime_proto_tree(const dfilter_t *df, proto_tree *tree);
|
||||
|
||||
GPtrArray *
|
||||
dfilter_deprecated_tokens(dfilter_t *df);
|
||||
|
||||
/* Print bytecode of dfilter to stdout */
|
||||
void
|
||||
dfilter_dump(dfilter_t *df);
|
||||
|
|
|
@ -83,6 +83,7 @@ static int set_lval_int(int token, char *s);
|
|||
static int simple(int token);
|
||||
static gboolean str_to_gint32(char *s, gint32* pint);
|
||||
GString* quoted_string = NULL;
|
||||
static void mark_lval_deprecated(const char *s);
|
||||
|
||||
%}
|
||||
|
||||
|
@ -102,8 +103,14 @@ GString* quoted_string = NULL;
|
|||
|
||||
"==" return simple(TOKEN_TEST_EQ);
|
||||
"eq" return simple(TOKEN_TEST_EQ);
|
||||
"!=" return simple(TOKEN_TEST_NE);
|
||||
"ne" return simple(TOKEN_TEST_NE);
|
||||
"!=" {
|
||||
mark_lval_deprecated("!=");
|
||||
return simple(TOKEN_TEST_NE);
|
||||
}
|
||||
"ne" {
|
||||
mark_lval_deprecated("ne");
|
||||
return simple(TOKEN_TEST_NE);
|
||||
}
|
||||
">" return simple(TOKEN_TEST_GT);
|
||||
"gt" return simple(TOKEN_TEST_GT);
|
||||
">=" return simple(TOKEN_TEST_GE);
|
||||
|
@ -417,4 +424,10 @@ str_to_gint32(char *s, gint32* pint)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
mark_lval_deprecated(const char *s)
|
||||
{
|
||||
df_lval->deprecated_token = s;
|
||||
}
|
||||
|
||||
#include <lemonflex-tail.inc>
|
||||
|
|
|
@ -92,6 +92,7 @@ stnode_new(sttype_id_t type_id, gpointer data)
|
|||
|
||||
node = g_new(stnode_t, 1);
|
||||
node->magic = STNODE_MAGIC;
|
||||
node->deprecated_token = NULL;
|
||||
|
||||
if (type_id == STTYPE_UNINITIALIZED) {
|
||||
node->type = NULL;
|
||||
|
@ -188,3 +189,12 @@ stnode_value(stnode_t *node)
|
|||
assert_magic(node, STNODE_MAGIC);
|
||||
return node->value;
|
||||
}
|
||||
|
||||
char *
|
||||
stnode_deprecated(stnode_t *node)
|
||||
{
|
||||
if (!node) {
|
||||
return NULL;
|
||||
}
|
||||
return node->deprecated_token;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef struct {
|
|||
* set aside to time to do so. */
|
||||
gpointer data;
|
||||
gint32 value;
|
||||
char *deprecated_token;
|
||||
} stnode_t;
|
||||
|
||||
/* These are the sttype_t registration function prototypes. */
|
||||
|
@ -103,6 +104,9 @@ stnode_data(stnode_t *node);
|
|||
gint32
|
||||
stnode_value(stnode_t *node);
|
||||
|
||||
char *
|
||||
stnode_deprecated(stnode_t *node);
|
||||
|
||||
#define assert_magic(obj, mnum) \
|
||||
g_assert((obj)); \
|
||||
if ((obj)->magic != (mnum)) { \
|
||||
|
|
|
@ -1482,6 +1482,13 @@ colorize_filter_te_as_invalid(GtkWidget *w)
|
|||
color_filter_te(w, 0xFFFF, 0xAFFF, 0xAFFF);
|
||||
}
|
||||
|
||||
void
|
||||
colorize_filter_te_as_deprecated(GtkWidget *w)
|
||||
{
|
||||
/* light yellow */
|
||||
color_filter_te(w, 0xFFFF, 0xFFFF, 0xAFFF);
|
||||
}
|
||||
|
||||
void
|
||||
colorize_filter_te_as_valid(GtkWidget *w)
|
||||
{
|
||||
|
@ -1494,19 +1501,39 @@ filter_te_syntax_check_cb(GtkWidget *w)
|
|||
{
|
||||
const gchar *strval;
|
||||
dfilter_t *dfp;
|
||||
GPtrArray *depr = NULL;
|
||||
gchar *msg;
|
||||
|
||||
statusbar_pop_filter_msg();
|
||||
|
||||
strval = gtk_entry_get_text(GTK_ENTRY(w));
|
||||
|
||||
/* colorize filter string entry */
|
||||
if (strval && dfilter_compile(strval, &dfp)) {
|
||||
if (dfp != NULL)
|
||||
if (dfp != NULL) {
|
||||
depr = dfilter_deprecated_tokens(dfp);
|
||||
dfilter_free(dfp);
|
||||
if (strlen(strval) == 0)
|
||||
}
|
||||
if (strlen(strval) == 0) {
|
||||
colorize_filter_te_as_empty(w);
|
||||
else
|
||||
} else if (depr) {
|
||||
/* You keep using that word. I do not think it means what you think it means. */
|
||||
colorize_filter_te_as_deprecated(w);
|
||||
/*
|
||||
* We're being lazy and only printing the first "problem" token.
|
||||
* Would it be better to print all of them?
|
||||
*/
|
||||
msg = g_strdup_printf("\"%s\" may have unexpected results.",
|
||||
(char *) g_ptr_array_index(depr, 0));
|
||||
statusbar_push_filter_msg(msg);
|
||||
g_free(msg);
|
||||
} else {
|
||||
colorize_filter_te_as_valid(w);
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
colorize_filter_te_as_invalid(w);
|
||||
statusbar_push_filter_msg("Invalid filter");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
21
gtk/main.c
21
gtk/main.c
|
@ -225,7 +225,7 @@ static GtkWidget *info_bar;
|
|||
static GtkWidget *packets_bar = NULL;
|
||||
static GtkWidget *profile_bar = NULL;
|
||||
static GtkWidget *welcome_pane;
|
||||
static guint main_ctx, file_ctx, help_ctx;
|
||||
static guint main_ctx, file_ctx, help_ctx, filter_ctx;
|
||||
static guint packets_ctx;
|
||||
static guint profile_ctx;
|
||||
static gchar *packets_str = NULL;
|
||||
|
@ -1008,6 +1008,24 @@ statusbar_pop_field_msg(void)
|
|||
gtk_statusbar_pop(GTK_STATUSBAR(info_bar), help_ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* Push a message referring to the current filter onto the statusbar.
|
||||
*/
|
||||
void
|
||||
statusbar_push_filter_msg(const gchar *msg)
|
||||
{
|
||||
gtk_statusbar_push(GTK_STATUSBAR(info_bar), filter_ctx, msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pop a message referring to the current filter off the statusbar.
|
||||
*/
|
||||
void
|
||||
statusbar_pop_filter_msg(void)
|
||||
{
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(info_bar), filter_ctx);
|
||||
}
|
||||
|
||||
/*
|
||||
* update the packets statusbar to the current values
|
||||
*/
|
||||
|
@ -3358,6 +3376,7 @@ static GtkWidget *info_bar_new(void)
|
|||
main_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "main");
|
||||
file_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "file");
|
||||
help_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "help");
|
||||
filter_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(info_bar), "filter");
|
||||
#if GTK_MAJOR_VERSION >= 2
|
||||
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(info_bar), FALSE);
|
||||
#endif
|
||||
|
|
12
gtk/main.h
12
gtk/main.h
|
@ -349,4 +349,16 @@ extern void change_configuration_profile(const gchar *profile_name);
|
|||
|
||||
extern GtkWidget *pkt_scrollw;
|
||||
|
||||
/** Push a message referring to the current filter onto the statusbar.
|
||||
*
|
||||
* @param msg The message
|
||||
*/
|
||||
void
|
||||
statusbar_push_filter_msg(const gchar *msg);
|
||||
|
||||
/** Pop a message referring to the current filter off the statusbar.
|
||||
*/
|
||||
void
|
||||
statusbar_pop_filter_msg(void);
|
||||
|
||||
#endif /* __MAIN_H__ */
|
||||
|
|
Loading…
Reference in New Issue