From 1f8999bb96018446e48529e75e56bf17dd3c77cf Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 14 Jul 2016 16:01:57 -0700 Subject: Redo the block options APIs. A block can have zero or more instances of a given option. We distinguish between "one instance only" options, where a block can have zero or one instance, and "multiple instances allowed" options, where a block can have zero or more instances. For "one instance only" options: "add" routines add an instance if there isn't one already and fail if there is; "set" routines add an instance if there isn't one already and change the value of the existing instance if there is one; "set nth" routines fail; "get" routines return the value of the instance if there is one and fail if there isn't; "get nth" routines fail. For "multiple instances allowed" options: "add" routines add an instance; "set" routines fail; "set nth" routines set the value of the nth instance if there is one and fail otherwise; "get" routines fail; "get nth" routines get the value if the nth instance if there is one and fail otherwise. Rename "optionblock" to just "block"; it describes the contents of a block, including both mandatory items and options. Add some support for NRB options, including IPv4 and IPv6 option types. Change-Id: Iad184f668626c3d1498b2ed00c7f1672e4abf52e Reviewed-on: https://code.wireshark.org/review/16444 Reviewed-by: Guy Harris --- file.c | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index ba84efbd13..db3a4be8de 100644 --- a/file.c +++ b/file.c @@ -3839,28 +3839,47 @@ cf_unignore_frame(capture_file *cf, frame_data *frame) const gchar * cf_read_shb_comment(capture_file *cf) { - /* Get info from SHB */ - return wtap_file_get_shb_comment(cf->wth); + wtap_block_t shb_inf; + char *shb_comment; + + /* Get the SHB. */ + /* XXX - support multiple SHBs */ + shb_inf = wtap_file_get_shb(cf->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; } void cf_update_capture_comment(capture_file *cf, gchar *comment) { - const gchar *shb_comment; - - /* Get info from SHB */ - shb_comment = wtap_file_get_shb_comment(cf->wth); - - /* See if the comment has changed or not */ - if (shb_comment) { - if (strcmp(shb_comment, comment) == 0) { - g_free(comment); - return; + wtap_block_t shb_inf; + gchar *shb_comment; + + /* Get the SHB. */ + /* XXX - support multiple SHBs */ + shb_inf = wtap_file_get_shb(cf->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) { + /* There's no comment - add one. */ + wtap_block_add_string_option(shb_inf, OPT_COMMENT, comment, strlen(comment)); + } else { + /* See if the comment has changed or not */ + if (shb_comment) { + if (strcmp(shb_comment, comment) == 0) { + g_free(comment); + return; + } } - } - /* The comment has changed, let's update it */ - wtap_write_shb_comment(cf->wth, comment); + /* The comment has changed, let's update it */ + wtap_block_set_nth_string_option_value(shb_inf, OPT_COMMENT, 0, comment, strlen(comment)); + } /* Mark the file as having unsaved changes */ cf->unsaved_changes = TRUE; } -- cgit v1.2.1