Add macros for various filter actions and types, and to combine them

into a callback argument and split a callback argument up.

svn path=/trunk/; revision=23747
This commit is contained in:
Guy Harris 2007-12-04 08:27:48 +00:00
parent a8ce49d758
commit 15f3b2c750
1 changed files with 85 additions and 66 deletions

View File

@ -205,25 +205,36 @@ static gint find_summary_data(error_equiv_table *err, const expert_info_t *exper
return -1;
}
/* action is encoded as
filter_action*256+filter_type
/* Filter actions */
#define ACTION_MATCH 0
#define ACTION_PREPARE 1
#define ACTION_FIND_FRAME 2
#define ACTION_FIND_NEXT 3
#define ACTION_FIND_PREVIOUS 4
#define ACTION_COLORIZE 5
#define ACTION_WEB_LOOKUP 6
/* Action type - says what to do with the filter */
#define ACTYPE_SELECTED 0
#define ACTYPE_NOT_SELECTED 1
#define ACTYPE_AND_SELECTED 2
#define ACTYPE_OR_SELECTED 3
#define ACTYPE_AND_NOT_SELECTED 4
#define ACTYPE_OR_NOT_SELECTED 5
/* Encoded callback arguments */
#define CALLBACK_MATCH(type) (ACTION_MATCH<<8 | (type))
#define CALLBACK_PREPARE(type) (ACTION_PREPARE<<8 | (type))
#define CALLBACK_FIND_FRAME(type) (ACTION_FIND_FRAME<<8 | (type))
#define CALLBACK_FIND_NEXT(type) (ACTION_FIND_NEXT<<8 | (type))
#define CALLBACK_FIND_PREVIOUS(type) (ACTION_FIND_PREVIOUS<<8 | (type))
#define CALLBACK_COLORIZE(type) (ACTION_COLORIZE<<8 | (type))
#define CALLBACK_WEB_LOOKUP (ACTION_WEB_LOOKUP<<8)
/* Extract components of callback argument */
#define FILTER_ACTION(cb_action) (((cb_action)>>8) & 0xff)
#define FILTER_ACTYPE(cb_action) ((cb_action)&0xff)
filter_action:
0: Match
1: Prepare
2: Find Frame
3: Find Next
4: Find Previous
5: Colorize Procedure
6: Lookup on Internet
filter_type:
0: Selected
1: Not Selected
2: And Selected
3: Or Selected
4: And Not Selected
5: Or Not Selected
*/
static void
error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
{
@ -238,8 +249,8 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
const expert_info_t expert_data;
#endif
action=(callback_action>>8)&0xff;
type=callback_action&0xff;
action=FILTER_ACTION(callback_action);
type=FILTER_ACTYPE(callback_action);
#if (GTK_MAJOR_VERSION < 2)
@ -280,8 +291,7 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
}
}
switch(type){
case 0:
/* selected */
case ACTYPE_SELECTED:
/* if no expert item was passed */
if (err->procedures[selection].fvalue_value==NULL) {
g_snprintf(str, 255, "%s", err->procedures[selection].entries[2]);
@ -292,8 +302,7 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
g_snprintf(str, 255, "%s", err->procedures[selection].fvalue_value);
}
break;
case 1:
/* not selected */
case ACTYPE_NOT_SELECTED:
/* if no expert item was passed */
if (err->procedures[selection].fvalue_value==NULL) {
g_snprintf(str, 255, "!%s", err->procedures[selection].entries[2]);
@ -305,20 +314,16 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
}
break;
/* the remaining cases will only exist if the expert item exists so no need to check */
case 2:
/* and selected */
case ACTYPE_AND_SELECTED:
g_snprintf(str, 255, "(%s) && (%s)", current_filter, err->procedures[selection].fvalue_value);
break;
case 3:
/* or selected */
case ACTYPE_OR_SELECTED:
g_snprintf(str, 255, "(%s) || (%s)", current_filter, err->procedures[selection].fvalue_value);
break;
case 4:
/* and not selected */
case ACTYPE_AND_NOT_SELECTED:
g_snprintf(str, 255, "(%s) && !(%s)", current_filter, err->procedures[selection].fvalue_value);
break;
case 5:
/* or not selected */
case ACTYPE_OR_NOT_SELECTED:
g_snprintf(str, 255, "(%s) || !(%s)", current_filter, err->procedures[selection].fvalue_value);
break;
default:
@ -327,16 +332,13 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
}
switch(action){
case 0:
/* match */
case ACTION_MATCH:
main_filter_packets(&cfile, str, FALSE);
break;
case 1:
/* prepare */
case ACTION_PREPARE:
gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
break;
case 2:
/* find frame */
case ACTION_FIND_FRAME:
/* When trying to perform a find without expert item, we must pass
* the expert string to the find window. The user might need to modify
* the string and click on the text search to locate the packet in question.
@ -345,8 +347,7 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
*/
find_frame_with_filter(str);
break;
case 3:
/* find next */
case ACTION_FIND_NEXT:
/* In the case of find next, if there was no expert item, then most likely the expert
* string was modified to locate the text inside the message. So we can't just perform
* a find with the expert string or we will not really be performing a find next.
@ -364,8 +365,7 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
find_previous_next_frame_with_filter(str, FALSE);
}
break;
case 4:
/* find previous */
case ACTION_FIND_PREVIOUS:
/* In the case of find previous, if there was no expert item, then most likely the expert
* string was modified to locate the text inside the message. So we can't just perform
* a find with the expert string or we will not really be performing a find previous.
@ -383,11 +383,10 @@ error_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint call
find_previous_next_frame_with_filter(str, TRUE);
}
break;
case 5:
/* colorize procedure */
case ACTION_COLORIZE:
color_display_with_filter(str);
break;
case 6:
case ACTION_WEB_LOOKUP:
/* Lookup expert string on internet. Default search via www.google.com */
g_snprintf(str, 255, "http://www.google.com/search?hl=en&q=%s+'%s'", err->procedures[selection].entries[1], err->procedures[selection].entries[2]);
browser_open_url(str);
@ -421,64 +420,84 @@ static GtkItemFactoryEntry error_list_menu_items[] =
/* Match */
ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/Selected", NULL,
error_select_filter_cb, 0*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/... not Selected", NULL,
error_select_filter_cb, 0*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_NOT_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/.. and Selected", NULL,
error_select_filter_cb, 0*256+2, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_AND_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/... or Selected", NULL,
error_select_filter_cb, 0*256+3, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_OR_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/... and not Selected", NULL,
error_select_filter_cb, 0*256+4, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Apply as Filter/... or not Selected", NULL,
error_select_filter_cb, 0*256+5, NULL, NULL),
error_select_filter_cb, CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED),
NULL, NULL),
/* Prepare */
ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/Selected", NULL,
error_select_filter_cb, 1*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/Not Selected", NULL,
error_select_filter_cb, 1*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_NOT_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and Selected", NULL,
error_select_filter_cb, 1*256+2, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_AND_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or Selected", NULL,
error_select_filter_cb, 1*256+3, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_OR_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/... and not Selected", NULL,
error_select_filter_cb, 1*256+4, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Prepare a Filter/... or not Selected", NULL,
error_select_filter_cb, 1*256+5, NULL, NULL),
error_select_filter_cb, CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED),
NULL, NULL),
/* Find Frame */
ITEM_FACTORY_ENTRY("/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Selected", NULL,
error_select_filter_cb, 2*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_FRAME(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Not Selected", NULL,
error_select_filter_cb, 2*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED),
NULL, NULL),
/* Find Next */
ITEM_FACTORY_ENTRY("/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Selected", NULL,
error_select_filter_cb, 3*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_NEXT(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Not Selected", NULL,
error_select_filter_cb, 3*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED),
NULL, NULL),
/* Find Previous */
ITEM_FACTORY_ENTRY("/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Selected", NULL,
error_select_filter_cb, 4*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Not Selected", NULL,
error_select_filter_cb, 4*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED),
NULL, NULL),
/* Colorize Procedure */
ITEM_FACTORY_ENTRY("/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL),
ITEM_FACTORY_ENTRY("/Colorize Procedure/Selected", NULL,
error_select_filter_cb, 5*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_COLORIZE(ACTYPE_SELECTED),
NULL, NULL),
ITEM_FACTORY_ENTRY("/Colorize Procedure/Not Selected", NULL,
error_select_filter_cb, 5*256+1, NULL, NULL),
error_select_filter_cb, CALLBACK_COLORIZE(ACTYPE_NOT_SELECTED),
NULL, NULL),
/* Search Internet */
ITEM_FACTORY_ENTRY("/Internet Search for Info Text", NULL,
error_select_filter_cb, 6*256+0, NULL, NULL),
error_select_filter_cb, CALLBACK_WEB_LOOKUP, NULL, NULL),
#if (GTK_MAJOR_VERSION < 2)
/* Go to first packet matching this entry */
ITEM_FACTORY_ENTRY("/Goto First Occurrence", NULL,