X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=file.c;h=58518d68aca8dcbb86ca3227b98bca32903a74b4;hb=2e411dba93bf2ceecf3dd201b2d100864229ce02;hp=10a4507ed6246adf503e4bf73008f432d6e75491;hpb=4e17bd6229a09c149c4e0ac7e5a090febfc15c10;p=metze%2Fwireshark%2Fwip.git diff --git a/file.c b/file.c index 10a4507ed6..58518d68ac 100644 --- a/file.c +++ b/file.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include "cfile.h" #include "file.h" @@ -323,6 +325,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp wtap_set_cb_new_ipv4(cf->provider.wth, add_ipv4_name); wtap_set_cb_new_ipv6(cf->provider.wth, (wtap_new_ipv6_callback_t) add_ipv6_name); + wtap_set_cb_new_secrets(cf->provider.wth, secrets_wtap_callback); return CF_OK; @@ -547,9 +550,9 @@ cf_read(capture_file *cf, gboolean reloading) else cf_callback_invoke(cf_cb_file_read_started, cf); - /* Record whether the file is compressed. + /* Record the file's compression type. XXX - do we know this at open time? */ - cf->iscompressed = wtap_iscompressed(cf->provider.wth); + cf->compression_type = wtap_get_compression_type(cf->provider.wth); /* The packet list window will be empty until the file is completly loaded */ packet_list_freeze(); @@ -805,7 +808,7 @@ cf_continue_tail(capture_file *cf, volatile int to_read, int *err) aren't any packets left to read) exit. */ break; } - if (read_record(cf, dfcode, &edt, (column_info *) cinfo, data_offset)) { + if (read_record(cf, dfcode, &edt, cinfo, data_offset)) { newly_displayed_packets++; } to_read--; @@ -1156,11 +1159,11 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, * TODO: actually detect that situation or maybe apply other optimizations? */ if (edt->tree && color_filters_used()) { color_filters_prime_edt(edt); - fdata->flags.need_colorize = 1; + fdata->need_colorize = 1; } #endif - if (!fdata->flags.visited) { + if (!fdata->visited) { /* This is the first pass, so prime the epan_dissect_t with the hfids postdissectors want on the first pass. */ prime_epan_dissect_with_postdissector_wanted_hfids(edt); @@ -1173,9 +1176,9 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, /* If we don't have a display filter, set "passed_dfilter" to 1. */ if (dfcode != NULL) { - fdata->flags.passed_dfilter = dfilter_apply_edt(dfcode, edt) ? 1 : 0; + fdata->passed_dfilter = dfilter_apply_edt(dfcode, edt) ? 1 : 0; - if (fdata->flags.passed_dfilter) { + if (fdata->passed_dfilter) { /* This frame passed the display filter but it may depend on other * (potentially not displayed) frames. Find those frames and mark them * as depended upon. @@ -1183,9 +1186,9 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, g_slist_foreach(edt->pi.dependent_frames, find_and_mark_frame_depended_upon, cf->provider.frames); } } else - fdata->flags.passed_dfilter = 1; + fdata->passed_dfilter = 1; - if (fdata->flags.passed_dfilter || fdata->flags.ref_time) + if (fdata->passed_dfilter || fdata->ref_time) cf->displayed_count++; if (add_to_packet_list) { @@ -1193,7 +1196,7 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, packet_list_append(cinfo, fdata); } - if (fdata->flags.passed_dfilter || fdata->flags.ref_time) + if (fdata->passed_dfilter || fdata->ref_time) { frame_data_set_after_dissect(fdata, &cf->cum_bytes); cf->provider.prev_dis = fdata; @@ -1808,7 +1811,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb } /* Frame dependencies from the previous dissection/filtering are no longer valid. */ - fdata->flags.dependent_of_displayed = 0; + fdata->dependent_of_displayed = 0; if (!cf_read_record(cf, fdata)) break; /* error reading the frame */ @@ -1816,7 +1819,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb /* If the previous frame is displayed, and we haven't yet seen the selected frame, remember that frame - it's the closest one we've yet seen before the selected frame. */ - if (prev_frame_num != -1 && !selected_frame_seen && prev_frame->flags.passed_dfilter) { + if (prev_frame_num != -1 && !selected_frame_seen && prev_frame->passed_dfilter) { preceding_frame_num = prev_frame_num; preceding_frame = prev_frame; } @@ -1830,13 +1833,13 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb seen displayed after the selected frame, remember this frame - it's the closest one we've yet seen at or after the selected frame. */ - if (fdata->flags.passed_dfilter && selected_frame_seen && following_frame_num == -1) { + if (fdata->passed_dfilter && selected_frame_seen && following_frame_num == -1) { following_frame_num = fdata->num; following_frame = fdata; } if (fdata == selected_frame) { selected_frame_seen = TRUE; - if (fdata->flags.passed_dfilter) + if (fdata->passed_dfilter) selected_frame_num = fdata->num; } @@ -1993,7 +1996,7 @@ ref_time_packets(capture_file *cf) cf->provider.ref = fdata; /* if this frames is marked as a reference time frame, reset firstsec and firstusec to this frame */ - if (fdata->flags.ref_time) + if (fdata->ref_time) cf->provider.ref = fdata; /* If we don't have the time stamp of the previous displayed packet, @@ -2018,7 +2021,7 @@ ref_time_packets(capture_file *cf) /* If this frame is displayed, get the time elapsed between the previous displayed packet and this packet. */ - if ( fdata->flags.passed_dfilter ) { + if ( fdata->passed_dfilter ) { fdata->prev_dis_num = cf->provider.prev_dis->num; cf->provider.prev_dis = fdata; } @@ -2026,11 +2029,11 @@ ref_time_packets(capture_file *cf) /* * Byte counts */ - if ( (fdata->flags.passed_dfilter) || (fdata->flags.ref_time) ) { + if ( (fdata->passed_dfilter) || (fdata->ref_time) ) { /* This frame either passed the display filter list or is marked as a time reference frame. All time reference frames are displayed even if they don't pass the display filter */ - if (fdata->flags.ref_time) { + if (fdata->ref_time) { /* if this was a TIME REF frame we should reset the cum_bytes field */ cf->cum_bytes = fdata->pkt_len; fdata->cum_bytes = cf->cum_bytes; @@ -2627,6 +2630,7 @@ typedef struct { FILE *fh; epan_dissect_t edt; print_args_t *print_args; + json_dumper jdumper; } write_packet_callback_args_t; static gboolean @@ -2938,7 +2942,8 @@ write_json_packet(capture_file *cf, frame_data *fdata, wtap_rec *rec, /* Write out the information in that tree. */ write_json_proto_tree(NULL, args->print_args->print_dissections, args->print_args->print_hex, NULL, PF_NONE, - &args->edt, &cf->cinfo, proto_node_group_children_by_unique, args->fh); + &args->edt, &cf->cinfo, proto_node_group_children_by_unique, + &args->jdumper); epan_dissect_reset(&args->edt); @@ -2956,7 +2961,7 @@ cf_write_json_packets(capture_file *cf, print_args_t *print_args) if (fh == NULL) return CF_PRINT_OPEN_ERROR; /* attempt to open destination failed */ - write_json_preamble(fh); + callback_args.jdumper = write_json_preamble(fh); if (ferror(fh)) { fclose(fh); return CF_PRINT_WRITE_ERROR; @@ -2990,7 +2995,7 @@ cf_write_json_packets(capture_file *cf, print_args_t *print_args) return CF_PRINT_WRITE_ERROR; } - write_json_finale(fh); + write_json_finale(&callback_args.jdumper); if (ferror(fh)) { fclose(fh); return CF_PRINT_WRITE_ERROR; @@ -3518,7 +3523,7 @@ cf_find_packet_marked(capture_file *cf, search_direction dir) static match_result match_marked(capture_file *cf _U_, frame_data *fdata, void *criterion _U_) { - return fdata->flags.marked ? MR_MATCHED : MR_NOTMATCHED; + return fdata->marked ? MR_MATCHED : MR_NOTMATCHED; } gboolean @@ -3530,7 +3535,7 @@ cf_find_packet_time_reference(capture_file *cf, search_direction dir) static match_result match_time_reference(capture_file *cf _U_, frame_data *fdata, void *criterion _U_) { - return fdata->flags.ref_time ? MR_MATCHED : MR_NOTMATCHED; + return fdata->ref_time ? MR_MATCHED : MR_NOTMATCHED; } static gboolean @@ -3651,7 +3656,7 @@ find_packet(capture_file *cf, count++; /* Is this packet in the display? */ - if (fdata && fdata->flags.passed_dfilter) { + if (fdata && fdata->passed_dfilter) { /* Yes. Does it match the search criterion? */ result = (*match_function)(cf, fdata, criterion); if (result == MR_ERROR) { @@ -3718,7 +3723,7 @@ cf_goto_frame(capture_file *cf, guint fnumber) statusbar_push_temporary_msg("There is no packet number %u.", fnumber); return FALSE; /* we failed to go to that packet */ } - if (!fdata->flags.passed_dfilter) { + if (!fdata->passed_dfilter) { /* that packet currently isn't displayed */ /* XXX - add it to the set of displayed packets? */ statusbar_push_temporary_msg("Packet number %u isn't displayed.", fnumber); @@ -3822,8 +3827,8 @@ cf_unselect_packet(capture_file *cf) void cf_mark_frame(capture_file *cf, frame_data *frame) { - if (! frame->flags.marked) { - frame->flags.marked = TRUE; + if (! frame->marked) { + frame->marked = TRUE; if (cf->count > cf->marked_count) cf->marked_count++; } @@ -3835,8 +3840,8 @@ cf_mark_frame(capture_file *cf, frame_data *frame) void cf_unmark_frame(capture_file *cf, frame_data *frame) { - if (frame->flags.marked) { - frame->flags.marked = FALSE; + if (frame->marked) { + frame->marked = FALSE; if (cf->marked_count > 0) cf->marked_count--; } @@ -3848,8 +3853,8 @@ cf_unmark_frame(capture_file *cf, frame_data *frame) void cf_ignore_frame(capture_file *cf, frame_data *frame) { - if (! frame->flags.ignored) { - frame->flags.ignored = TRUE; + if (! frame->ignored) { + frame->ignored = TRUE; if (cf->count > cf->ignored_count) cf->ignored_count++; } @@ -3861,8 +3866,8 @@ cf_ignore_frame(capture_file *cf, frame_data *frame) void cf_unignore_frame(capture_file *cf, frame_data *frame) { - if (frame->flags.ignored) { - frame->flags.ignored = FALSE; + if (frame->ignored) { + frame->ignored = FALSE; if (cf->ignored_count > 0) cf->ignored_count--; } @@ -3931,11 +3936,11 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd) char *comment; /* fetch user comment */ - if (fd->flags.has_user_comment) + if (fd->has_user_comment) return g_strdup(cap_file_provider_get_user_comment(&cf->provider, fd)); /* fetch phdr comment */ - if (fd->flags.has_phdr_comment) { + if (fd->has_phdr_comment) { wtap_rec rec; /* Record metadata */ Buffer buf; /* Record data */ @@ -4044,12 +4049,12 @@ save_record(capture_file *cf, frame_data *fdata, wtap_rec *rec, /* Make changes based on anything that the user has done but that hasn't been saved yet. */ - if (fdata->flags.has_user_comment) + if (fdata->has_user_comment) pkt_comment = cap_file_provider_get_user_comment(&cf->provider, fdata); else pkt_comment = rec->opt_comment; new_rec.opt_comment = g_strdup(pkt_comment); - new_rec.has_comment_changed = fdata->flags.has_user_comment ? TRUE : FALSE; + new_rec.has_comment_changed = fdata->has_user_comment ? TRUE : FALSE; /* XXX - what if times have been shifted? */ /* and save the packet */ @@ -4228,9 +4233,9 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) cf_callback_invoke(cf_cb_file_rescan_started, cf); - /* Record whether the file is compressed. + /* Record the file's compression type. XXX - do we know this at open time? */ - cf->iscompressed = wtap_iscompressed(cf->provider.wth); + cf->compression_type = wtap_get_compression_type(cf->provider.wth); /* Find the size of the file. */ size = wtap_file_size(cf->provider.wth, NULL); @@ -4333,8 +4338,8 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) cf_write_status_t cf_save_records(capture_file *cf, const char *fname, guint save_format, - gboolean compressed, gboolean discard_comments, - gboolean dont_reopen) + wtap_compression_type compression_type, + gboolean discard_comments, gboolean dont_reopen) { gchar *err_info; gchar *fname_new = NULL; @@ -4364,7 +4369,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, addr_lists = get_addrinfo_list(); - if (save_format == cf->cd_t && compressed == cf->iscompressed + if (save_format == cf->cd_t && compression_type == cf->compression_type && !discard_comments && !cf->unsaved_changes && (wtap_addrinfo_list_empty(addr_lists) || !wtap_dump_has_name_resolution(save_format))) { /* We're saving in the format it's already in, and we're not discarding @@ -4470,9 +4475,10 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname_new, save_format, compression_type, ¶ms, + &err); } else { - pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname, save_format, compression_type, ¶ms, &err); } /* XXX idb_inf is documented to be used until wtap_dump_close. */ g_free(params.idb_inf); @@ -4659,8 +4665,8 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, for (framenum = 1; framenum <= cf->count; framenum++) { fdata = frame_data_sequence_find(cf->provider.frames, framenum); - fdata->flags.has_phdr_comment = FALSE; - fdata->flags.has_user_comment = FALSE; + fdata->has_phdr_comment = FALSE; + fdata->has_user_comment = FALSE; } if (cf->provider.frames_user_comments) { @@ -4691,7 +4697,7 @@ fail: cf_write_status_t cf_export_specified_packets(capture_file *cf, const char *fname, packet_range_t *range, guint save_format, - gboolean compressed) + wtap_compression_type compression_type) { gchar *fname_new = NULL; int err; @@ -4726,9 +4732,10 @@ cf_export_specified_packets(capture_file *cf, const char *fname, we *HAVE* to do that, otherwise we're overwriting the file from which we're reading the packets that we're writing!) */ fname_new = g_strdup_printf("%s~", fname); - pdh = wtap_dump_open(fname_new, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname_new, save_format, compression_type, ¶ms, + &err); } else { - pdh = wtap_dump_open(fname, save_format, compressed, ¶ms, &err); + pdh = wtap_dump_open(fname, save_format, compression_type, ¶ms, &err); } /* XXX idb_inf is documented to be used until wtap_dump_close. */ g_free(params.idb_inf);