New feature to automatically highlight the field found when doing a find.

This works for both string and hex searches.  This resolves feature request
bug #776.


svn path=/trunk/; revision=19897
This commit is contained in:
Stephen Fisher 2006-11-14 22:35:22 +00:00
parent dd26a7021b
commit 90303fb17f
5 changed files with 69 additions and 5 deletions

View File

@ -67,6 +67,7 @@ typedef struct _capture_file {
gboolean sbackward; /* TRUE if search is backward, FALSE if forward */
gboolean hex; /* TRUE is raw data search is being performed */
gboolean string; /* TRUE is text search is being performed */
guint32 search_pos; /* Position of last character found in search */
search_charset_t scs_type; /* Character set for text search */
gboolean case_type; /* TRUE if case-insensitive text search */
gboolean decode_data; /* TRUE if searching protocol tree text */

8
file.c
View File

@ -2609,6 +2609,8 @@ match_ascii_and_unicode(capture_file *cf, frame_data *fdata, void *criterion)
c_match++;
if (c_match == textlen) {
frame_matched = TRUE;
cf->search_pos = i; /* Save the position of the last character
for highlighting the field. */
break;
}
} else
@ -2640,6 +2642,8 @@ match_ascii(capture_file *cf, frame_data *fdata, void *criterion)
c_match++;
if (c_match == textlen) {
frame_matched = TRUE;
cf->search_pos = i; /* Save the position of the last character
for highlighting the field. */
break;
}
} else
@ -2671,6 +2675,8 @@ match_unicode(capture_file *cf, frame_data *fdata, void *criterion)
i++;
if (c_match == textlen) {
frame_matched = TRUE;
cf->search_pos = i; /* Save the position of the last character
for highlighting the field. */
break;
}
} else
@ -2697,6 +2703,8 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion)
c_match++;
if (c_match == datalen) {
frame_matched = TRUE;
cf->search_pos = i; /* Save the position of the last character
for highlighting the field. */
break;
}
} else

View File

@ -1861,6 +1861,20 @@ main_cf_cb_packet_selected(gpointer data)
add_main_byte_views(cf->edt);
main_proto_tree_draw(cf->edt->tree);
/* The user is searching for a string in the data or a hex value,
* highlight the field that is found in the tree and hex displays. */
#if GTK_MAJOR_VERSION < 2
if((cfile.string || cfile.hex) && cfile.search_pos != 0) {
highlight_field(cf->edt->tvb, cfile.search_pos,
(GtkCTree *)tree_view, cf->edt->tree);
#else
if((cfile.string || cfile.hex) && cfile.search_pos != 0) {
highlight_field(cf->edt->tvb, cfile.search_pos,
(GtkTreeView *)tree_view, cf->edt->tree);
#endif
cfile.search_pos = 0; /* Reset the position */
}
/* A packet is selected. */
set_menus_for_selected_packet(cf);
}

View File

@ -386,15 +386,10 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event)
GtkText *bv = GTK_TEXT(widget);
#else
GtkTreeView *tree_view;
GtkTreeModel *model;
GtkTreePath *first_path, *path;
GtkTreeIter parent;
GtkTextView *bv = GTK_TEXT_VIEW(widget);
gint x, y;
GtkTextIter iter;
struct field_lookup_info fli;
#endif
field_info *finfo;
int row, column;
int byte;
tvbuff_t *tvb;
@ -546,6 +541,34 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event)
/* Get the data source tvbuff */
tvb = OBJECT_GET_DATA(widget, E_BYTE_VIEW_TVBUFF_KEY);
#if GTK_MAJOR_VERSION < 2
return highlight_field(tvb, byte, ctree, tree);
#else
return highlight_field(tvb, byte, tree_view, tree);
#endif
}
/* This highlights the field in the proto tree that is at position byte */
#if GTK_MAJOR_VERSION < 2
gboolean
highlight_field(tvbuff_t *tvb, gint byte, GtkCTree *ctree,
proto_tree *tree)
#else
gboolean
highlight_field(tvbuff_t *tvb, gint byte, GtkTreeView *tree_view,
proto_tree *tree)
#endif
{
#if GTK_MAJOR_VERSION < 2
GtkCTreeNode *node, *parent;
#else
GtkTreeModel *model;
GtkTreePath *first_path, *path;
GtkTreeIter parent;
struct field_lookup_info fli;
#endif
field_info *finfo;
/* Find the finfo that corresponds to our byte. */
finfo = proto_find_field_from_offset(tree, byte, tvb);

View File

@ -102,6 +102,24 @@ extern void add_byte_views(epan_dissect_t *edt, GtkWidget *tree_view,
*/
extern gboolean byte_view_select(GtkWidget *widget, GdkEventButton *event);
/** This highlights the field in the proto tree that is at position byte
*
* @param tvb the current tvbuff
* @param byte the byte offset within the packet to highlight
* @param tree_view the current tree_view
* @param tree the current tree
* @return TRUE if highlighting was successful
*/
#if GTK_MAJOR_VERSION < 2
gboolean
highlight_field(tvbuff_t *tvb, gint byte, GtkCTree *ctree,
proto_tree *tree);
#else
gboolean
highlight_field(tvbuff_t *tvb, gint byte, GtkTreeView *tree_view,
proto_tree *tree);
#endif
/** Callback for "Export Selected Packet Bytes" operation.
*
* @param w unused