Keep track, in Wiretap, of whether the file is compressed, and provide

an API to fetch that.

When doing "Save" on a compressed file, write it out compressed.

In the Statistics -> Summary dialog and in capinfos, report whether the
file is gzip-compressed.

svn path=/trunk/; revision=42818
This commit is contained in:
Guy Harris 2012-05-24 05:05:29 +00:00
parent 73888ed977
commit cf6d9841e3
12 changed files with 41 additions and 11 deletions

View File

@ -191,6 +191,7 @@ typedef enum {
typedef struct _capture_info {
const char *filename;
guint16 file_type;
gboolean iscompressed;
int file_encap;
gint64 filesize;
@ -358,7 +359,9 @@ print_stats(const gchar *filename, capture_info *cf_info)
stop_time_t = (time_t)cf_info->stop_time;
if (filename) printf ("File name: %s\n", filename);
if (cap_file_type) printf ("File type: %s\n", file_type_string);
if (cap_file_type) printf ("File type: %s%s\n",
file_type_string,
cf_info->iscompressed ? " (gzip compressed)" : "");
if (cap_file_encap) printf ("File encapsulation: %s\n", file_encap_string);
if (cap_file_encap && (cf_info->file_encap == WTAP_ENCAP_PER_PACKET)) {
int i;
@ -749,6 +752,7 @@ process_cap_file(wtap *wth, const char *filename)
/* File Type */
cf_info.file_type = wtap_file_type(wth);
cf_info.iscompressed = wtap_iscompressed(wth);
/* File Encapsulation */
cf_info.file_encap = wtap_file_encap(wth);

View File

@ -73,6 +73,7 @@ typedef struct _capture_file {
gboolean unsaved_changes; /* Does the capture file have changes that have not been saved? */
gint64 f_datalen; /* Size of capture file data (uncompressed) */
guint16 cd_t; /* File type of capture file */
gboolean iscompressed; /* TRUE if the file is compressed */
int lnk_t; /* Link-layer type with which to save capture */
guint32 count; /* Total number of frames */
guint32 displayed_count; /* Number of displayed frames */

6
file.c
View File

@ -530,6 +530,9 @@ cf_read(capture_file *cf, gboolean reloading)
else
cf_callback_invoke(cf_cb_file_read_started, cf);
/* Record whether the file is compressed. */
cf->iscompressed = wtap_iscompressed(cf->wth);
/* Find the size of the file. */
size = wtap_file_size(cf->wth, NULL);
@ -3818,7 +3821,8 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format,
cf_callback_invoke(cf_cb_file_save_started, (gpointer)fname);
if (save_format == cf->cd_t && !cf->unsaved_changes) {
if (save_format == cf->cd_t && compressed == cf->iscompressed
&& !cf->unsaved_changes) {
/* We're saving in the format it's already in, and there are no
changes we have in memory that aren't saved to the file, so
we can just move or copy the raw data. */

View File

@ -141,6 +141,7 @@ summary_fill_in(capture_file *cf, summary_tally *st)
st->filename = cf->filename;
st->file_length = cf->f_datalen;
st->file_type = cf->cd_t;
st->iscompressed = cf->iscompressed;
st->is_tempfile = cf->is_tempfile;
st->encap_type = cf->lnk_t;
st->has_snap = cf->has_snap;

View File

@ -33,7 +33,7 @@ typedef struct iface_options_tag {
char *name;
char *descr;
char *cfilter;
char *isb_comment;
char *isb_comment;
guint64 drops; /**< number of packet drops */
gboolean drops_known; /**< TRUE if number of packet drops is known */
gboolean has_snap; /**< TRUE if maximum capture packet length is known */
@ -64,6 +64,7 @@ typedef struct _summary_tally {
const char *filename;
gint64 file_length; /**< file length in bytes */
int file_type; /**< wiretap file type */
int iscompressed; /**< TRUE if file is compressed */
int encap_type; /**< wiretap encapsulation type */
gboolean has_snap; /**< TRUE if maximum capture packet length is known */
int snap; /**< Maximum captured packet length */

View File

@ -1190,10 +1190,7 @@ file_save_cmd(action_after_save_e action_after_save, gpointer action_after_save_
a copy and free it later. */
fname = g_strdup(cfile.filename);
/* XXX - if we're editing a compressed capture file, we should
remember that it's compressed, and write it out in compressed
form. */
cf_save_packets(&cfile, fname, cfile.cd_t, FALSE);
cf_save_packets(&cfile, fname, cfile.cd_t, cfile.iscompressed);
g_free(fname);
}

View File

@ -238,7 +238,9 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_)
add_string_to_table(table, &row, "Length:", string_buff);
/* format */
g_snprintf(string_buff, SUM_STR_MAX, "%s", wtap_file_type_string(summary.file_type));
g_snprintf(string_buff, SUM_STR_MAX, "%s%s",
wtap_file_type_string(summary.file_type),
summary.iscompressed? " (gzip compressed)" : "");
add_string_to_table(table, &row, "Format:", string_buff);
/* encapsulation */

View File

@ -121,6 +121,7 @@ struct wtap_reader {
gint64 start; /* where the gzip data started, for rewinding */
gint64 raw; /* where the raw data started, for seeking */
int compression; /* 0: ?, 1: uncompressed, 2: zlib */
gboolean is_compressed; /* FALSE if completely uncompressed, TRUE otherwise */
/* seek request */
gint64 skip; /* amount to skip (already rewound if backwards) */
int seek; /* true if seek request pending */
@ -128,8 +129,8 @@ struct wtap_reader {
int err; /* error code */
const char *err_info; /* additional error information string for some errors */
unsigned int avail_in; /* number of bytes available at next_in */
unsigned char *next_in; /* next input byte */
unsigned int avail_in; /* number of bytes available at next_in */
unsigned char *next_in; /* next input byte */
#ifdef HAVE_LIBZ
/* zlib inflate stream */
z_stream strm; /* stream structure in-place (not a pointer) */
@ -140,7 +141,7 @@ struct wtap_reader {
void *fast_seek_cur;
};
/* values for gz_state compression */
/* values for wtap_reader compression */
#define UNKNOWN 0 /* look for a gzip header */
#define UNCOMPRESSED 1 /* copy input directly */
#ifdef HAVE_LIBZ
@ -651,6 +652,7 @@ gz_head(FILE_T state)
inflateReset(&(state->strm));
state->strm.adler = crc32(0L, Z_NULL, 0);
state->compression = ZLIB;
state->is_compressed = TRUE;
#ifdef Z_BLOCK
if (state->fast_seek) {
struct zlib_cur_seek_point *cur = g_malloc(sizeof(struct zlib_cur_seek_point));
@ -786,6 +788,9 @@ filed_open(int fd)
/* open the file with the appropriate mode (or just use fd) */
state->fd = fd;
/* we don't yet know whether it's compressed */
state->is_compressed = FALSE;
/* save the current position for rewinding (only if reading) */
state->start = ws_lseek64(state->fd, 0, SEEK_CUR);
if (state->start == -1) state->start = 0;
@ -1085,6 +1090,12 @@ file_fstat(FILE_T stream, ws_statb64 *statb, int *err)
return 0;
}
gboolean
file_iscompressed(FILE_T stream)
{
return stream->is_compressed;
}
int
file_read(void *buf, unsigned int len, FILE_T file)
{

View File

@ -35,6 +35,7 @@ extern gint64 file_skip(FILE_T file, gint64 delta, int *err);
extern gint64 file_tell(FILE_T stream);
extern gint64 file_tell_raw(FILE_T stream);
extern int file_fstat(FILE_T stream, ws_statb64 *statb, int *err);
extern gboolean file_iscompressed(FILE_T stream);
extern int file_read(void *buf, unsigned int count, FILE_T file);
extern int file_getc(FILE_T stream);
extern char *file_gets(char *buf, int len, FILE_T stream);

View File

@ -78,6 +78,12 @@ wtap_file_type(wtap *wth)
return wth->file_type;
}
gboolean
wtap_iscompressed(wtap *wth)
{
return file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh);
}
guint
wtap_snapshot_length(wtap *wth)
{

View File

@ -61,6 +61,7 @@ wtap_fstat
wtap_get_bytes_dumped
wtap_get_num_encap_types
wtap_get_num_file_types
wtap_iscompressed
wtap_open_offline
wtap_pcap_encap_to_wtap_encap
wtap_phdr

View File

@ -1074,6 +1074,7 @@ guint8 *wtap_buf_ptr(wtap *wth);
* from the file so far. */
gint64 wtap_read_so_far(wtap *wth);
gint64 wtap_file_size(wtap *wth, int *err);
gboolean wtap_iscompressed(wtap *wth);
guint wtap_snapshot_length(wtap *wth); /* per file */
int wtap_file_type(wtap *wth);
int wtap_file_encap(wtap *wth);