From Cal Turney via enhancement bug #5587: In hex or string searches of the
authorsfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 19 Jan 2011 18:21:21 +0000 (18:21 +0000)
committersfisher <sfisher@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 19 Jan 2011 18:21:21 +0000 (18:21 +0000)
packet data highlight the target rather than the entire field.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@35584 f5534014-38df-0310-8fa8-9805f1628bb7

cfile.h
file.c
gtk/main.c
gtk/main_proto_draw.c

diff --git a/cfile.h b/cfile.h
index 5789b0d230a01f9999d083e3dba7ed71d36a276d..fe912bb261cd8cd7229a86ea867bcb8f921e5436 100644 (file)
--- a/cfile.h
+++ b/cfile.h
@@ -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 */
diff --git a/file.c b/file.c
index c69e0ea51877738d14db5580992c228454b6d727..65b35b554b383f5f87bbdee3da23f3182fe9d2a0 100644 (file)
--- a/file.c
+++ b/file.c
@@ -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);
index 99a3993c27198cf4fc4157bee516469e1ce57ca6..8d370d6fc38463f877888f69be839f14f60df9c4 100644 (file)
@@ -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);
 }
index 2a0ebc827e77f2fc9bf6c92e3ee1959a5b1dfd40..5b351d393a97cf59406724581f81da05a18c3be3 100644 (file)
@@ -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. */
@@ -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;