Skip to content

Commit

Permalink
From Cal Turney via enhancement bug #5587: In hex or string searches …
Browse files Browse the repository at this point in the history
…of the

packet data highlight the target rather than the entire field.


svn path=/trunk/; revision=35584
  • Loading branch information
Stephen Fisher committed Jan 19, 2011
1 parent 30b0472 commit 347d0a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions cfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ typedef struct _capture_file {
gboolean case_type; /* TRUE if case-insensitive text search */
gboolean decode_data; /* TRUE if searching protocol tree text */
gboolean summary_data; /* TRUE if searching Info column text */
gboolean search_in_progress; /* TRUE if user just clicked OK in the Find dialog or hit <control>N/B */
/* packet data */
union wtap_pseudo_header pseudo_header; /* Packet pseudo_header */
guint8 pd[WTAP_MAX_PACKET_SIZE]; /* Packet data */
Expand Down
3 changes: 3 additions & 0 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3992,7 +3992,10 @@ find_packet(capture_file *cf,
if (new_fd != NULL) {
#ifdef NEW_PACKET_LIST
/* Find and select */
cf->search_in_progress = TRUE;
row = new_packet_list_find_row_from_data(fdata, TRUE);
cf->search_in_progress = FALSE;
cf->search_pos = 0; /* Reset the position */
#else
/* We found a frame. Find what row it's in. */
row = packet_list_find_row_from_data(new_fd);
Expand Down
13 changes: 6 additions & 7 deletions gtk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1681,14 +1681,13 @@ 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((cfile.string || cfile.hex) && cfile.search_pos != 0) {
highlight_field(cf->edt->tvb, cfile.search_pos,
/* Note: Both string and hex value searches in the packet data produce a non-zero
search_pos if successful */
if(cf->search_in_progress && cf->search_pos != 0) {
highlight_field(cf->edt->tvb, cf->search_pos,
(GtkTreeView *)tree_view_gbl, cf->edt->tree);
cfile.search_pos = 0; /* Reset the position */
}

}

/* A packet is selected. */
set_menus_for_selected_packet(cf);
}
Expand Down
29 changes: 27 additions & 2 deletions gtk/main_proto_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,16 @@ highlight_field(tvbuff_t *tvb, gint byte, GtkTreeView *tree_view,
gtk_tree_selection_select_path(gtk_tree_view_get_selection(tree_view),
first_path);

/* If the last search was a string or hex search within "Packet data", the entire field might
not be highlighted. If the user just clicked on one of the bytes comprising that field, the
above call didn't trigger a 'gtk_tree_view_get_selection' event. Call redraw_packet_bytes()
to make the highlighting of the entire field visible. */
if (!cfile.search_in_progress) {
if (cfile.hex || (cfile.string && !(cfile.summary_data || cfile.decode_data))) {
redraw_packet_bytes(byte_nb_ptr_gbl, cfile.current_frame, cfile.finfo_selected);
}
}

/* And position the window so the selection is visible.
* Position the selection in the middle of the viewable
* pane. */
Expand Down Expand Up @@ -1562,8 +1572,23 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd,


if (finfo != NULL) {
bstart = finfo->start;
blen = finfo->length;

if (cfile.search_in_progress) {
if (cfile.hex || (cfile.string && !(cfile.summary_data || cfile.decode_data))) {
/* In the hex view, only highlight the target bytes or string. The entire
field can then be displayed by clicking on any of the bytes in the field. */
if (cfile.hex) {
blen = strlen(cfile.sfilter)/2;
} else {
blen = strlen(cfile.sfilter);
}
bstart = cfile.search_pos - (blen-1);
}
} else {
blen = finfo->length;
bstart = finfo->start;
}

/* bmask = finfo->hfinfo->bitmask << finfo->hfinfo->bitshift; */ /* (value & mask) >> shift */
bmask = finfo->hfinfo->bitmask;
astart = finfo->appendix_start;
Expand Down

0 comments on commit 347d0a7

Please sign in to comment.