some code cleanup in range.c
svn path=/trunk/; revision=9609
This commit is contained in:
parent
563f423d76
commit
7e20ddc9f6
6
file.c
6
file.c
|
@ -1,7 +1,7 @@
|
|||
/* file.c
|
||||
* File I/O routines
|
||||
*
|
||||
* $Id: file.c,v 1.335 2004/01/09 02:57:07 obiot Exp $
|
||||
* $Id: file.c,v 1.336 2004/01/09 14:04:52 ulfl Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -2304,6 +2304,8 @@ cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
packet_range_process_init(range);
|
||||
|
||||
/* Used to be :
|
||||
* if (!save_filtered && !save_marked && !save_manual_range &&
|
||||
* !save_marked_range && !save_curr && save_format == cf->cd_t) {
|
||||
|
@ -2419,7 +2421,7 @@ cf_save(char *fname, capture_file *cf, packet_range_t *range, guint save_format)
|
|||
progbar_count++;
|
||||
|
||||
/* do we have to process this packet? */
|
||||
process_this = packet_range_process(range, fdata);
|
||||
process_this = packet_range_process_packet(range, fdata);
|
||||
if (process_this == range_process_next) {
|
||||
/* this packet uninteresting, continue with next one */
|
||||
continue;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* file_dlg.c
|
||||
* Dialog boxes for handling files
|
||||
*
|
||||
* $Id: file_dlg.c,v 1.77 2004/01/08 10:40:04 ulfl Exp $
|
||||
* $Id: file_dlg.c,v 1.78 2004/01/09 14:05:20 ulfl Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -693,11 +693,11 @@ toggle_select_all(GtkWidget *widget, gpointer data _U_)
|
|||
}
|
||||
|
||||
static void
|
||||
toggle_select_curr(GtkWidget *widget, gpointer data _U_)
|
||||
toggle_select_selected(GtkWidget *widget, gpointer data _U_)
|
||||
{
|
||||
/* is the button now active? */
|
||||
if (GTK_TOGGLE_BUTTON (widget)->active) {
|
||||
range.process = range_process_curr;
|
||||
range.process = range_process_selected;
|
||||
set_file_type_list(ft_om);
|
||||
file_set_save_dynamics();
|
||||
}
|
||||
|
@ -881,7 +881,7 @@ file_save_as_cmd_cb(GtkWidget *w _U_, gpointer data _U_)
|
|||
#endif
|
||||
gtk_table_attach_defaults(GTK_TABLE(range_tb), select_curr_rb, 0, 1, 2, 3);
|
||||
gtk_tooltips_set_tip (tooltips,select_curr_rb,("Save the currently selected packet only"), NULL);
|
||||
SIGNAL_CONNECT(select_curr_rb, "toggled", toggle_select_curr, NULL);
|
||||
SIGNAL_CONNECT(select_curr_rb, "toggled", toggle_select_selected, NULL);
|
||||
gtk_widget_show(select_curr_rb);
|
||||
|
||||
select_curr_c_lb = gtk_label_new("?");
|
||||
|
@ -1054,10 +1054,6 @@ file_save_as_ok_cb(GtkWidget *w _U_, GtkFileSelection *fs) {
|
|||
gchar *cf_name;
|
||||
gchar *dirname;
|
||||
|
||||
/* obtain the range specifications in case we selected a user specified range */
|
||||
if (range.process == range_process_user_range) {
|
||||
range_entry(range_specs);
|
||||
}
|
||||
|
||||
cf_name = g_strdup(gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs)));
|
||||
|
||||
|
|
123
range.c
123
range.c
|
@ -1,7 +1,7 @@
|
|||
/* range.c
|
||||
* Packet range routines (save, print, ...)
|
||||
*
|
||||
* $Id: range.c,v 1.6 2004/01/08 10:40:33 ulfl Exp $
|
||||
* $Id: range.c,v 1.7 2004/01/09 14:04:52 ulfl Exp $
|
||||
*
|
||||
* Dick Gooris <gooris@lucent.com>
|
||||
* Ulf Lamping <ulf.lamping@web.de>
|
||||
|
@ -67,9 +67,9 @@ void packet_range_calc(packet_range_t *range) {
|
|||
range->displayed_marked_cnt = 0L;
|
||||
range->displayed_mark_range = 0L;
|
||||
|
||||
/* The next for-loop is used to obtain the amount of packets to be saved
|
||||
/* The next for-loop is used to obtain the amount of packets to be processed
|
||||
* and is used to present the information in the Save/Print As widget.
|
||||
* We have different types of saving : All the packets, the number
|
||||
* We have different types of ranges: All the packets, the number
|
||||
* of packets of a marked range, a single packet, and a user specified
|
||||
* packet range. The last one is not calculated here since this
|
||||
* data must be entered in the widget by the user.
|
||||
|
@ -166,16 +166,23 @@ void packet_range_init(packet_range_t *range) {
|
|||
range->ranges[range->nranges].low = 0L;
|
||||
range->ranges[range->nranges].high = 0L;
|
||||
|
||||
/* "enumeration" values */
|
||||
range->range_active = FALSE;
|
||||
range->markers = cfile.marked_count;
|
||||
range->process_curr_done = FALSE;
|
||||
|
||||
/* calculate all packet range counters */
|
||||
packet_range_calc(range);
|
||||
packet_range_calc_user(range);
|
||||
}
|
||||
|
||||
/* init the processing run */
|
||||
void packet_range_process_init(packet_range_t *range) {
|
||||
/* "enumeration" values */
|
||||
range->marked_range_active = FALSE;
|
||||
range->selected_done = FALSE;
|
||||
|
||||
if (range->process_filtered == FALSE) {
|
||||
range->markers = range->mark_range;
|
||||
} else {
|
||||
range->markers = range->displayed_mark_range;
|
||||
}
|
||||
}
|
||||
|
||||
/* do we have to process all packets? */
|
||||
gboolean packet_range_process_all(packet_range_t *range) {
|
||||
|
@ -183,71 +190,53 @@ gboolean packet_range_process_all(packet_range_t *range) {
|
|||
}
|
||||
|
||||
/* do we have to process this packet? */
|
||||
range_process_e packet_range_process(packet_range_t *range, frame_data *fdata) {
|
||||
range_process_e packet_range_process_packet(packet_range_t *range, frame_data *fdata) {
|
||||
|
||||
/* do we have to process this packet at all? */
|
||||
if (
|
||||
(!range->process_filtered && range->process != range_process_marked) ||
|
||||
(!range->process_filtered && range->process == range_process_marked && fdata->flags.marked) ||
|
||||
(range->process_filtered && range->process == range_process_marked && fdata->flags.marked && fdata->flags.passed_dfilter) ||
|
||||
(range->process_filtered && range->process != range_process_marked && fdata->flags.passed_dfilter) ||
|
||||
(range->process == range_process_curr) ||
|
||||
(range->process == range_process_marked_range) ||
|
||||
(range->process == range_process_user_range) ||
|
||||
(range->range_active)
|
||||
) {
|
||||
/* yes, we have to */
|
||||
} else {
|
||||
return range_process_next;
|
||||
}
|
||||
|
||||
/* In case we process a user specified range, we check whether the packet number
|
||||
* is in any of the ranges as defined the array ranges, see file_dlg.c
|
||||
* If a match is found, we process it, else we process the next packet.
|
||||
*/
|
||||
if (range->process == range_process_user_range) {
|
||||
if (range->process_filtered) {
|
||||
if (fdata->flags.passed_dfilter == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
}
|
||||
if (packet_is_in_range(range, fdata->num) == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
}
|
||||
|
||||
/* For processing a marked range, ignore any packet until we get the first marked packet.
|
||||
* At that time we set the range_active to TRUE, and decrement the markers count. Then continue
|
||||
* accepting each packet, until we find the last marker (markers count becomes zero)
|
||||
* We then reset range_active to FALSE to ignore any packet from then on.
|
||||
*/
|
||||
if (range->process == range_process_marked_range) {
|
||||
if (range->markers == 0) {
|
||||
switch(range->process) {
|
||||
case(range_process_all):
|
||||
break;
|
||||
case(range_process_selected):
|
||||
if (range->selected_done) {
|
||||
return range_processing_finished;
|
||||
}
|
||||
if (fdata->flags.marked == TRUE) {
|
||||
range->range_active = TRUE;
|
||||
}
|
||||
if (fdata->num != cfile.current_frame->num) {
|
||||
return range_process_next;
|
||||
}
|
||||
range->selected_done = TRUE;
|
||||
break;
|
||||
case(range_process_marked):
|
||||
if (fdata->flags.marked == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
break;
|
||||
case(range_process_marked_range):
|
||||
if (range->markers == 0) {
|
||||
return range_processing_finished;
|
||||
}
|
||||
if (fdata->flags.marked == TRUE) {
|
||||
range->marked_range_active = TRUE;
|
||||
if (!range->process_filtered ||
|
||||
(range->process_filtered && fdata->flags.passed_dfilter == TRUE))
|
||||
{
|
||||
range->markers--;
|
||||
}
|
||||
if (range->process_filtered) {
|
||||
if (fdata->flags.passed_dfilter == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
}
|
||||
if (range->range_active == FALSE ) {
|
||||
}
|
||||
if (range->marked_range_active == FALSE ) {
|
||||
return range_process_next;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case(range_process_user_range):
|
||||
if (packet_is_in_range(range, fdata->num) == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
/* Only process the selected packet */
|
||||
if (range->process == range_process_curr) {
|
||||
if (range->process_curr_done) {
|
||||
return range_processing_finished;
|
||||
}
|
||||
if (fdata->num != cfile.current_frame->num) {
|
||||
return range_process_next;
|
||||
}
|
||||
range->process_curr_done = TRUE;
|
||||
/* this packet has to pass the display filter but didn't? -> try next */
|
||||
if (range->process_filtered && fdata->flags.passed_dfilter == FALSE) {
|
||||
return range_process_next;
|
||||
}
|
||||
|
||||
/* We fell through the conditions above, so we accept this packet */
|
||||
|
@ -255,8 +244,6 @@ range_process_e packet_range_process(packet_range_t *range, frame_data *fdata) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************** Range Entry Parser *********************************/
|
||||
|
||||
/* Converts a range string to a fast comparable array of ranges.
|
||||
|
|
33
range.h
33
range.h
|
@ -1,7 +1,7 @@
|
|||
/* range.h
|
||||
* Packet range routines (save, print, ...)
|
||||
*
|
||||
* $Id: range.h,v 1.6 2004/01/08 10:40:33 ulfl Exp $
|
||||
* $Id: range.h,v 1.7 2004/01/09 14:04:53 ulfl Exp $
|
||||
*
|
||||
* Dick Gooris <gooris@lucent.com>
|
||||
* Ulf Lamping <ulf.lamping@web.de>
|
||||
|
@ -36,7 +36,7 @@ extern guint32 curr_selected_frame;
|
|||
|
||||
typedef enum {
|
||||
range_process_all,
|
||||
range_process_curr,
|
||||
range_process_selected,
|
||||
range_process_marked,
|
||||
range_process_marked_range,
|
||||
range_process_user_range
|
||||
|
@ -57,17 +57,17 @@ typedef struct packet_range_tag {
|
|||
gboolean process_filtered; /* captured or filtered packets */
|
||||
|
||||
/* user specified range(s) */
|
||||
guint nranges;
|
||||
guint nranges; /* number of entries in ranges (0 based) */
|
||||
range_admin_t ranges[MaxRange];
|
||||
|
||||
/* calculated values */
|
||||
guint32 selected_packet; /* the currently selected packet */
|
||||
guint32 selected_packet; /* the currently selected packet */
|
||||
|
||||
/* current packet counts (captured) */
|
||||
/* cfile.count */ /* packets in capture file */
|
||||
/* cfile.marked_count */ /* packets marked */
|
||||
guint32 mark_range; /* packets in marked range */
|
||||
guint32 user_range; /* packets in user specified range */
|
||||
/* cfile.count */ /* packets in capture file */
|
||||
/* cfile.marked_count */ /* packets marked */
|
||||
guint32 mark_range; /* packets in marked range */
|
||||
guint32 user_range; /* packets in user specified range */
|
||||
|
||||
/* current packet counts (displayed) */
|
||||
guint32 displayed_cnt;
|
||||
|
@ -76,25 +76,28 @@ typedef struct packet_range_tag {
|
|||
guint32 displayed_user_range;
|
||||
|
||||
/* "enumeration" values */
|
||||
gboolean range_active;
|
||||
guint32 markers;
|
||||
gboolean process_curr_done;
|
||||
gboolean marked_range_active; /* marked range is currently processed */
|
||||
guint32 markers; /* marked range packets left to do */
|
||||
gboolean selected_done; /* selected packet already processed */
|
||||
} packet_range_t;
|
||||
|
||||
typedef enum {
|
||||
range_process_next,
|
||||
range_processing_finished,
|
||||
range_process_this
|
||||
range_process_this, /* process this packet */
|
||||
range_process_next, /* skip this packet, process next */
|
||||
range_processing_finished /* stop processing, required packets done */
|
||||
} range_process_e;
|
||||
|
||||
/* init the range structure */
|
||||
extern void packet_range_init(packet_range_t *range);
|
||||
|
||||
/* init the processing run */
|
||||
void packet_range_process_init(packet_range_t *range);
|
||||
|
||||
/* do we have to process all packets? */
|
||||
extern gboolean packet_range_process_all(packet_range_t *range);
|
||||
|
||||
/* do we have to process this packet? */
|
||||
extern range_process_e packet_range_process(packet_range_t *range, frame_data *fdata);
|
||||
extern range_process_e packet_range_process_packet(packet_range_t *range, frame_data *fdata);
|
||||
|
||||
/* convert user given string to the internal user specified range representation */
|
||||
extern void packet_range_convert_str(packet_range_t *range, const gchar *es);
|
||||
|
|
Loading…
Reference in New Issue