Add a routine to make a newly-allocated copy of a block.

It currently wraps wtap_block_create() and wtap_block_copy(); if there
are no remaining use cases for wtap_block_copy() at some point, it can
just *replace* wtap_block_copy().
This commit is contained in:
Guy Harris 2020-10-21 19:10:49 -07:00
parent ec59b17544
commit 7c488e4c71
5 changed files with 20 additions and 8 deletions

View File

@ -41,6 +41,7 @@ libwiretap.so.0 libwiretap0 #MINVER#
wtap_block_get_string_option_value@Base 2.1.2
wtap_block_get_uint64_option_value@Base 2.1.2
wtap_block_get_uint8_option_value@Base 2.1.2
wtap_block_make_copy@Base 3.3.2
wtap_block_remove_nth_option_instance@Base 2.2.0
wtap_block_remove_option@Base 2.2.0
wtap_block_set_custom_option_value@Base 2.1.2

View File

@ -2336,8 +2336,7 @@ wtap_dump_init_dumper(int file_type_subtype, wtap_compression_type compression_t
for (itf_count = 0; itf_count < interfaces->len; itf_count++) {
file_int_data = g_array_index(interfaces, wtap_block_t, itf_count);
file_int_data_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(file_int_data);
descr = wtap_block_create(WTAP_BLOCK_IF_DESCR);
wtap_block_copy(descr, file_int_data);
descr = wtap_block_make_copy(file_int_data);
if ((params->encap != WTAP_ENCAP_PER_PACKET) && (params->encap != file_int_data_mand->wtap_encap)) {
descr_mand = (wtapng_if_descr_mandatory_t*)wtap_block_get_mandatory_data(descr);
descr_mand->wtap_encap = params->encap;

View File

@ -124,8 +124,7 @@ wtap_file_get_shb_for_new_file(wtap *wth)
for (shb_count = 0; shb_count < wth->shb_hdrs->len; shb_count++) {
shb_hdr_src = g_array_index(wth->shb_hdrs, wtap_block_t, shb_count);
shb_hdr_dest = wtap_block_create(WTAP_BLOCK_NG_SECTION);
wtap_block_copy(shb_hdr_dest, shb_hdr_src);
shb_hdr_dest = wtap_block_make_copy(shb_hdr_src);
g_array_append_val(shb_hdrs, shb_hdr_dest);
}
@ -426,8 +425,7 @@ wtap_file_get_nrb_for_new_file(wtap *wth)
for (nrb_count = 0; nrb_count < wth->nrb_hdrs->len; nrb_count++) {
nrb_hdr_src = g_array_index(wth->nrb_hdrs, wtap_block_t, nrb_count);
nrb_hdr_dest = wtap_block_create(WTAP_BLOCK_NG_NRB);
wtap_block_copy(nrb_hdr_dest, nrb_hdr_src);
nrb_hdr_dest = wtap_block_make_copy(nrb_hdr_src);
g_array_append_val(nrb_hdrs, nrb_hdr_dest);
}

View File

@ -305,6 +305,15 @@ wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block)
}
}
wtap_block_t wtap_block_make_copy(wtap_block_t block)
{
wtap_block_t block_copy;
block_copy = wtap_block_create(block->info->block_type);
wtap_block_copy(block_copy, block);
return block_copy;
}
void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data)
{
guint i;
@ -965,8 +974,7 @@ static void idb_copy_mand(wtap_block_t dest_block, wtap_block_t src_block)
for (j = 0; j < src_mand->num_stat_entries; j++)
{
src_if_stats = g_array_index(src_mand->interface_statistics, wtap_block_t, j);
dest_if_stats = wtap_block_create(WTAP_BLOCK_IF_STATS);
wtap_block_copy(dest_if_stats, src_if_stats);
dest_if_stats = wtap_block_make_copy(src_if_stats);
dest_mand->interface_statistics = g_array_append_val(dest_mand->interface_statistics, dest_if_stats);
}
}

View File

@ -512,6 +512,12 @@ wtap_block_remove_nth_option_instance(wtap_block_t block, guint option_id,
*/
WS_DLL_PUBLIC void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_block);
/** Make a copy of a block.
*
* @param[in] block Block to be copied from
* @return Newly allocated copy of that block
*/
WS_DLL_PUBLIC wtap_block_t wtap_block_make_copy(wtap_block_t block);
typedef void (*wtap_block_foreach_func)(wtap_block_t block, guint option_id, wtap_opttype_e option_type, wtap_optval_t *option, void *user_data);
WS_DLL_PUBLIC void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data);