aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-05-01 10:28:04 -0700
committerGuy Harris <gharris@sonic.net>2020-05-01 19:46:42 +0000
commit582ad24c38713722695177fabafbd3d47ecb1d7d (patch)
treeab702901f09b27c6554dda1c1a0be4191eb3e636 /file.c
parent3a32757313e85368e88fdd9dbb82f839514569f5 (diff)
Remove some single-SHB assumptions.
Make wtap_file_get_shb() take a section number argument, and update code that called it. In most cases, we convert the code to iterate over sections; in cases where a big code change would be required, we temporarily pass it 0 and mark the code as "needs to be updated for multiple sections". Eliminate cf_read_section_comment(); in calls outside file.c, other code directly calls the libwiretap routines it calls and, inside file.c, we just transplant the code and then fix it not to assume a single SHB. Change-Id: I85e94d0a4fc878e9d937088759be04cb004e019b Reviewed-on: https://code.wireshark.org/review/37000 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'file.c')
-rw-r--r--file.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/file.c b/file.c
index c04ddf5840..98e2302bc0 100644
--- a/file.c
+++ b/file.c
@@ -3931,26 +3931,6 @@ cf_unignore_frame(capture_file *cf, frame_data *frame)
}
/*
- * Read the section comment.
- */
-const gchar *
-cf_read_section_comment(capture_file *cf)
-{
- wtap_block_t shb_inf;
- char *shb_comment;
-
- /* Get the SHB. */
- /* XXX - support multiple SHBs */
- shb_inf = wtap_file_get_shb(cf->provider.wth);
-
- /* Get the first comment from the SHB. */
- /* XXX - support multiple comments */
- if (wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, 0, &shb_comment) != WTAP_OPTTYPE_SUCCESS)
- return NULL;
- return shb_comment;
-}
-
-/*
* Modify the section comment.
*/
void
@@ -3959,9 +3939,9 @@ cf_update_section_comment(capture_file *cf, gchar *comment)
wtap_block_t shb_inf;
gchar *shb_comment;
- /* Get the SHB. */
+ /* Get the first SHB. */
/* XXX - support multiple SHBs */
- shb_inf = wtap_file_get_shb(cf->provider.wth);
+ shb_inf = wtap_file_get_shb(cf->provider.wth, 0);
/* Get the first comment from the SHB. */
/* XXX - support multiple comments */
@@ -4054,8 +4034,27 @@ cf_comment_types(capture_file *cf)
{
guint32 comment_types = 0;
- if (cf_read_section_comment(cf) != NULL)
- comment_types |= WTAP_COMMENT_PER_SECTION;
+ /*
+ * Does this file have any sections with at least one comment?
+ */
+ for (guint section_number = 0;
+ section_number < wtap_file_get_num_shbs(cf->provider.wth);
+ section_number++) {
+ wtap_block_t shb_inf;
+ char *shb_comment;
+
+ shb_inf = wtap_file_get_shb(cf->provider.wth, section_number);
+
+ /* Try to get the first comment from that SHB. */
+ if (wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, 0,
+ &shb_comment) == WTAP_OPTTYPE_SUCCESS) {
+ /* We succeeded, so this file has at least one section comment. */
+ comment_types |= WTAP_COMMENT_PER_SECTION;
+
+ /* We don't need to search any more. */
+ break;
+ }
+ }
if (cf->packet_comment_count != 0)
comment_types |= WTAP_COMMENT_PER_PACKET;
return comment_types;