diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-07-14 16:01:57 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-07-14 23:02:39 +0000 |
commit | 1f8999bb96018446e48529e75e56bf17dd3c77cf (patch) | |
tree | 0103d875702fa1a7c64816e21e079d7ceee190c2 /ui/gtk | |
parent | 42e72d529cdbab62d52a26332985ecf28b997a87 (diff) |
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 <guy@alum.mit.edu>
Diffstat (limited to 'ui/gtk')
-rw-r--r-- | ui/gtk/file_import_dlg.c | 24 | ||||
-rw-r--r-- | ui/gtk/summary_dlg.c | 45 |
2 files changed, 33 insertions, 36 deletions
diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c index 338c312ad4..dc6a97a4f5 100644 --- a/ui/gtk/file_import_dlg.c +++ b/ui/gtk/file_import_dlg.c @@ -458,10 +458,10 @@ file_import_open(text_import_info_t *info) int err; /* pcapng defs */ - wtap_optionblock_t shb_hdr; - GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t)); + wtap_block_t shb_hdr; + GArray *shb_hdrs = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); wtapng_iface_descriptions_t *idb_inf; - wtap_optionblock_t int_data; + wtap_block_t int_data; wtapng_if_descr_mandatory_t *int_data_mand; GString *os_info_str; gsize opt_len; @@ -470,35 +470,35 @@ file_import_open(text_import_info_t *info) os_info_str = g_string_new(""); get_os_version_info(os_info_str); - shb_hdr = wtap_optionblock_create(WTAP_OPTION_BLOCK_NG_SECTION); + shb_hdr = wtap_block_create(WTAP_BLOCK_NG_SECTION); /* options */ - wtap_optionblock_set_option_string_format(shb_hdr, OPT_COMMENT, "File created by File->Import of file %s", info->import_text_filename); + wtap_block_add_string_option_format(shb_hdr, OPT_COMMENT, "File created by File->Import of file %s", info->import_text_filename); /* * UTF-8 string containing the name of the operating system used to create * this section. */ opt_len = os_info_str->len; - wtap_optionblock_set_option_string(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len); + wtap_block_add_string_option(shb_hdr, OPT_SHB_OS, g_string_free(os_info_str, TRUE), opt_len); /* * UTF-8 string containing the name of the application used to create * this section. */ - wtap_optionblock_set_option_string_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info()); + wtap_block_add_string_option_format(shb_hdr, OPT_SHB_USERAPPL, "Wireshark %s", get_ws_vcs_version_info()); /* Create fake IDB info */ idb_inf = g_new(wtapng_iface_descriptions_t,1); - idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_optionblock_t)); + idb_inf->interface_data = g_array_new(FALSE, FALSE, sizeof(wtap_block_t)); /* create the fake interface data */ - int_data = wtap_optionblock_create(WTAP_OPTION_BLOCK_IF_DESCR); - int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_optionblock_get_mandatory_data(int_data); + int_data = wtap_block_create(WTAP_BLOCK_IF_DESCR); + int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(int_data); int_data_mand->wtap_encap = info->encapsulation; int_data_mand->time_units_per_second = 1000000; /* default microsecond resolution */ int_data_mand->link_type = wtap_wtap_encap_to_pcap_encap(info->encapsulation); int_data_mand->snap_len = WTAP_MAX_PACKET_SIZE; - wtap_optionblock_set_option_string(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import")); + wtap_block_add_string_option(int_data, OPT_IDB_NAME, "Fake IF File->Import", strlen("Fake IF File->Import")); g_array_append_val(idb_inf->interface_data, int_data); g_array_append_val(shb_hdrs, shb_hdr); @@ -557,7 +557,7 @@ end: g_free(info->date_timestamp_format); g_free(info); g_free(capfile_name); - wtap_optionblock_array_free(shb_hdrs); + wtap_block_array_free(shb_hdrs); wtap_free_idb_info(idb_inf); window_destroy(file_import_dlg_w); } diff --git a/ui/gtk/summary_dlg.c b/ui/gtk/summary_dlg.c index 8bb85774ab..78f596c49e 100644 --- a/ui/gtk/summary_dlg.c +++ b/ui/gtk/summary_dlg.c @@ -188,9 +188,8 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) unsigned int elapsed_time; iface_options iface; - wtap_optionblock_t shb_inf; + wtap_block_t shb_inf; unsigned int i; - GArray *opts; if (summary_dlg != NULL) { /* There's already a Summary dialog box; reactivate it. */ @@ -293,14 +292,13 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (comment_view)); gtk_text_buffer_set_text (buffer, "", -1); if (shb_inf != NULL) { - wtap_optionblock_get_string_options(shb_inf, OPT_COMMENT, &opts); - for (i = 0; i < opts->len; i++) { - /* XXX - this only shows the last comment */ - char *opt_comment = g_array_index(opts, char *, i); + char *opt_comment; + + /* XXX - this only shows the last comment */ + for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) { if (opt_comment != NULL && opt_comment[0] != '\0') gtk_text_buffer_set_text (buffer, opt_comment, -1); } - g_array_free(opts, TRUE); } gtk_box_pack_start(GTK_BOX(comment_vbox), comment_view, TRUE, TRUE, 0); gtk_widget_show (comment_view); @@ -350,21 +348,21 @@ summary_open_cb(GtkWidget *w _U_, gpointer d _U_) if (shb_inf != NULL) { char *str; - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_HARDWARE, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str); add_string_to_grid(grid, &row, "Capture HW:",string_buff); } - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_OS, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { /* truncate the strings to a reasonable length */ g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str); add_string_to_grid(grid, &row, "OS:", string_buff); } - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_USERAPPL, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { /* truncate the strings to a reasonable length */ g_snprintf(string_buff, SHB_STR_SNIP_LEN, "%s", str); add_string_to_grid(grid, &row, "Capture application:", string_buff); @@ -664,8 +662,7 @@ summary_to_texbuff(GtkTextBuffer *buffer) summary_tally summary; gchar string_buff[SUM_STR_MAX]; gchar tmp_buff[SUM_STR_MAX]; - wtap_optionblock_t shb_inf; - GArray *opts; + wtap_block_t shb_inf; unsigned int i; unsigned int elapsed_time; iface_options iface; @@ -768,20 +765,20 @@ summary_to_texbuff(GtkTextBuffer *buffer) if (shb_inf != NULL) { char *str; - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_HARDWARE, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_HARDWARE, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { /* truncate the string to a reasonable length */ g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture HW: %s\n", str); gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1); } - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_OS, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_OS, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { /* truncate the strings to a reasonable length */ g_snprintf(string_buff, SUM_STR_MAX, INDENT "OS: %s\n", str); gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1); } - wtap_optionblock_get_option_string(shb_inf, OPT_SHB_USERAPPL, &str); - if (str != NULL && str[0] != '\0') { + if (wtap_block_get_string_option_value(shb_inf, OPT_SHB_USERAPPL, &str) == WTAP_OPTTYPE_SUCCESS && + str != NULL && str[0] != '\0') { /* truncate the string to a reasonable length */ g_snprintf(string_buff, SUM_STR_MAX, INDENT "Capture application: %s\n", str); gtk_text_buffer_insert_at_cursor (buffer, string_buff, -1); @@ -901,10 +898,10 @@ summary_to_texbuff(GtkTextBuffer *buffer) /* Trace file comments from SHB */ shb_inf = wtap_file_get_shb(cfile.wth); if (shb_inf != NULL) { - wtap_optionblock_get_string_options(shb_inf, OPT_COMMENT, &opts); - for (i = 0; i < opts->len; i++) { + char *opt_comment; + + for (i = 0; wtap_block_get_nth_string_option_value(shb_inf, OPT_COMMENT, i, &opt_comment) == WTAP_OPTTYPE_SUCCESS; i++) { /* XXX - separator between comments? */ - char *opt_comment = g_array_index(opts, char *, i); if (opt_comment != NULL && opt_comment[0] != '\0') gtk_text_buffer_insert_at_cursor(buffer, opt_comment, -1); } |