diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2018-05-23 20:15:32 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2018-05-24 04:10:14 +0000 |
commit | 1b6c702226a6b84ad89b2acc444254b93bf616b7 (patch) | |
tree | e543bb4f91dc9474941e0f05cc47650bc1522264 /file.c | |
parent | c159d48420e184f068ed6cea1715ab697fda4f7d (diff) |
Qt: Support search without a selected packet
Support doing Find Packet, search for next/previous marked packet and
search for next/previous time reference without having a packet selected
in the packet list.
Change-Id: I648b26365385d98155e905cda270e9e785b9f1da
Reviewed-on: https://code.wireshark.org/review/27752
Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 211 |
1 files changed, 105 insertions, 106 deletions
@@ -3401,6 +3401,7 @@ find_packet(capture_file *cf, { frame_data *start_fd; guint32 framenum; + guint32 prev_framenum; frame_data *fdata; frame_data *new_fd = NULL; progdlg_t *progbar = NULL; @@ -3415,132 +3416,130 @@ find_packet(capture_file *cf, start_fd = cf->current_frame; if (start_fd != NULL) { - /* Iterate through the list of packets, starting at the packet we've - picked, calling a routine to run the filter on the packet, see if - it matches, and stop if so. */ - count = 0; - framenum = start_fd->num; + prev_framenum = start_fd->num; + } else { + prev_framenum = 0; /* No start packet selected. */ + } - g_timer_start(prog_timer); - /* Progress so far. */ - progbar_val = 0.0f; + /* Iterate through the list of packets, starting at the packet we've + picked, calling a routine to run the filter on the packet, see if + it matches, and stop if so. */ + count = 0; + framenum = prev_framenum; + + g_timer_start(prog_timer); + /* Progress so far. */ + progbar_val = 0.0f; - cf->stop_flag = FALSE; - g_get_current_time(&start_time); + cf->stop_flag = FALSE; + g_get_current_time(&start_time); - title = cf->sfilter?cf->sfilter:""; - for (;;) { - /* Create the progress bar if necessary. - We check on every iteration of the loop, so that it takes no - longer than the standard time to create it (otherwise, for a + title = cf->sfilter?cf->sfilter:""; + for (;;) { + /* Create the progress bar if necessary. + We check on every iteration of the loop, so that it takes no + longer than the standard time to create it (otherwise, for a large file, we might take considerably longer than that standard - time in order to get to the next progress bar step). */ - if (progbar == NULL) - progbar = delayed_create_progress_dlg(cf->window, "Searching", title, - FALSE, &cf->stop_flag, &start_time, progbar_val); + time in order to get to the next progress bar step). */ + if (progbar == NULL) + progbar = delayed_create_progress_dlg(cf->window, "Searching", title, + FALSE, &cf->stop_flag, &start_time, progbar_val); - /* - * Update the progress bar, but do it only after PROGBAR_UPDATE_INTERVAL - * has elapsed. Calling update_progress_dlg and packets_bar_update will - * likely trigger UI paint events, which might take a while depending on - * the platform and display. Reset our timer *after* painting. + /* + * Update the progress bar, but do it only after PROGBAR_UPDATE_INTERVAL + * has elapsed. Calling update_progress_dlg and packets_bar_update will + * likely trigger UI paint events, which might take a while depending on + * the platform and display. Reset our timer *after* painting. + */ + if (g_timer_elapsed(prog_timer, NULL) > PROGBAR_UPDATE_INTERVAL) { + /* let's not divide by zero. I should never be started + * with count == 0, so let's assert that */ - if (g_timer_elapsed(prog_timer, NULL) > PROGBAR_UPDATE_INTERVAL) { - /* let's not divide by zero. I should never be started - * with count == 0, so let's assert that - */ - g_assert(cf->count > 0); + g_assert(cf->count > 0); - progbar_val = (gfloat) count / cf->count; + progbar_val = (gfloat) count / cf->count; - g_snprintf(status_str, sizeof(status_str), - "%4u of %u packets", count, cf->count); - update_progress_dlg(progbar, progbar_val, status_str); - - g_timer_start(prog_timer); - } + g_snprintf(status_str, sizeof(status_str), + "%4u of %u packets", count, cf->count); + update_progress_dlg(progbar, progbar_val, status_str); - if (cf->stop_flag) { - /* Well, the user decided to abort the search. Go back to the - frame where we started. */ - new_fd = start_fd; - break; - } + g_timer_start(prog_timer); + } - /* Go past the current frame. */ - if (dir == SD_BACKWARD) { - /* Go on to the previous frame. */ - if (framenum == 1) { - /* - * XXX - other apps have a bit more of a detailed message - * for this, and instead of offering "OK" and "Cancel", - * they offer things such as "Continue" and "Cancel"; - * we need an API for popping up alert boxes with - * {Verb} and "Cancel". - */ - - if (prefs.gui_find_wrap) - { - statusbar_push_temporary_msg("Search reached the beginning. Continuing at end."); - framenum = cf->count; /* wrap around */ - } - else - { - statusbar_push_temporary_msg("Search reached the beginning."); - framenum = start_fd->num; /* stay on previous packet */ - } - } else - framenum--; - } else { - /* Go on to the next frame. */ - if (framenum == cf->count) { - if (prefs.gui_find_wrap) - { - statusbar_push_temporary_msg("Search reached the end. Continuing at beginning."); - framenum = 1; /* wrap around */ - } - else - { - statusbar_push_temporary_msg("Search reached the end."); - framenum = start_fd->num; /* stay on previous packet */ - } - } else - framenum++; - } - fdata = frame_data_sequence_find(cf->provider.frames, framenum); + if (cf->stop_flag) { + /* Well, the user decided to abort the search. Go back to the + frame where we started. */ + new_fd = start_fd; + break; + } - count++; + /* Go past the current frame. */ + if (dir == SD_BACKWARD) { + /* Go on to the previous frame. */ + if (framenum <= 1) { + /* + * XXX - other apps have a bit more of a detailed message + * for this, and instead of offering "OK" and "Cancel", + * they offer things such as "Continue" and "Cancel"; + * we need an API for popping up alert boxes with + * {Verb} and "Cancel". + */ - /* Is this packet in the display? */ - if (fdata->flags.passed_dfilter) { - /* Yes. Does it match the search criterion? */ - result = (*match_function)(cf, fdata, criterion); - if (result == MR_ERROR) { - /* Error; our caller has reported the error. Go back to the frame - where we started. */ - new_fd = start_fd; - break; - } else if (result == MR_MATCHED) { - /* Yes. Go to the new frame. */ - new_fd = fdata; - break; + if (prefs.gui_find_wrap) { + statusbar_push_temporary_msg("Search reached the beginning. Continuing at end."); + framenum = cf->count; /* wrap around */ + } else { + statusbar_push_temporary_msg("Search reached the beginning."); + framenum = prev_framenum; /* stay on previous packet */ } - } + } else + framenum--; + } else { + /* Go on to the next frame. */ + if (framenum == cf->count) { + if (prefs.gui_find_wrap) { + statusbar_push_temporary_msg("Search reached the end. Continuing at beginning."); + framenum = 1; /* wrap around */ + } else { + statusbar_push_temporary_msg("Search reached the end."); + framenum = prev_framenum; /* stay on previous packet */ + } + } else + framenum++; + } + + fdata = frame_data_sequence_find(cf->provider.frames, framenum); + count++; - if (fdata == start_fd) { - /* We're back to the frame we were on originally, and that frame - doesn't match the search filter. The search failed. */ + /* Is this packet in the display? */ + if (fdata && fdata->flags.passed_dfilter) { + /* Yes. Does it match the search criterion? */ + result = (*match_function)(cf, fdata, criterion); + if (result == MR_ERROR) { + /* Error; our caller has reported the error. Go back to the frame + where we started. */ + new_fd = start_fd; + break; + } else if (result == MR_MATCHED) { + /* Yes. Go to the new frame. */ + new_fd = fdata; break; } } - /* We're done scanning the packets; destroy the progress bar if it - was created. */ - if (progbar != NULL) - destroy_progress_dlg(progbar); - g_timer_destroy(prog_timer); + if (fdata == start_fd) { + /* We're back to the frame we were on originally, and that frame + doesn't match the search filter. The search failed. */ + break; + } } + /* We're done scanning the packets; destroy the progress bar if it + was created. */ + if (progbar != NULL) + destroy_progress_dlg(progbar); + g_timer_destroy(prog_timer); + if (new_fd != NULL) { /* Find and select */ cf->search_in_progress = TRUE; |