wiretap: have the "for each option" routine return a success/fail indication.
Have the routine it calls return a Boolean value, with "true" meaning "keep going" and "false" meaning "stop iterating and return a failure indication". If the callback routine never returns "false", the routine returns "true" as a success indication.
This commit is contained in:
parent
695b4c5bee
commit
c1082bd99e
|
@ -994,7 +994,7 @@ static void erf_dump_priv_init_gen_time(erf_dump_t *dump_priv) {
|
|||
}
|
||||
|
||||
|
||||
static void erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_,
|
||||
static gboolean erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_,
|
||||
guint option_id,
|
||||
wtap_opttype_e option_type _U_,
|
||||
wtap_optval_t *optval,
|
||||
|
@ -1024,9 +1024,11 @@ static void erf_write_wtap_option_to_capture_tag(wtap_block_t block _U_,
|
|||
|
||||
if (tag_ptr)
|
||||
g_ptr_array_add(section_ptr->tags, tag_ptr);
|
||||
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void erf_write_wtap_option_to_host_tag(wtap_block_t block _U_,
|
||||
static gboolean erf_write_wtap_option_to_host_tag(wtap_block_t block _U_,
|
||||
guint option_id,
|
||||
wtap_opttype_e option_type _U_,
|
||||
wtap_optval_t *optval,
|
||||
|
@ -1056,9 +1058,11 @@ static void erf_write_wtap_option_to_host_tag(wtap_block_t block _U_,
|
|||
|
||||
if (tag_ptr)
|
||||
g_ptr_array_add(section_ptr->tags, tag_ptr);
|
||||
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_,
|
||||
static gboolean erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_,
|
||||
guint option_id,
|
||||
wtap_opttype_e option_type _U_,
|
||||
wtap_optval_t *optval,
|
||||
|
@ -1164,6 +1168,7 @@ static void erf_write_wtap_option_to_interface_tag(wtap_block_t block _U_,
|
|||
if (tag_ptr)
|
||||
g_ptr_array_add(section_ptr->tags, tag_ptr);
|
||||
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void erf_populate_section_length_by_tags(struct erf_meta_section *section_ptr) {
|
||||
|
|
156
wiretap/pcapng.c
156
wiretap/pcapng.c
|
@ -3573,7 +3573,7 @@ static guint32 pcapng_compute_custom_option_size(size_t custom_data_len)
|
|||
return (guint32)size;
|
||||
}
|
||||
|
||||
static void compute_shb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data)
|
||||
static gboolean compute_shb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data)
|
||||
{
|
||||
pcapng_block_size_t* block_size = (pcapng_block_size_t*)user_data;
|
||||
guint32 size = 0;
|
||||
|
@ -3605,13 +3605,13 @@ static void compute_shb_option_size(wtap_block_t block _U_, guint option_id, wta
|
|||
}
|
||||
block_size->size += 4;
|
||||
}
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
typedef struct pcapng_write_block_t
|
||||
{
|
||||
wtap_dumper *wdh;
|
||||
int *err;
|
||||
gboolean success;
|
||||
}
|
||||
pcapng_write_block_t;
|
||||
|
||||
|
@ -3667,7 +3667,6 @@ static gboolean pcapng_write_custom_option(wtap_dumper *wdh, guint option_id, cu
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static gboolean pcapng_write_option_eofopt(wtap_dumper *wdh, int *err)
|
||||
{
|
||||
struct pcapng_option_header option_hdr;
|
||||
|
@ -3790,36 +3789,29 @@ static gboolean pcapng_write_option_uint64(wtap_dumper *wdh, guint option_id, gu
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void write_wtap_shb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
static gboolean write_wtap_shb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
{
|
||||
pcapng_write_block_t* write_block = (pcapng_write_block_t*)user_data;
|
||||
|
||||
/* Don't continue if there has been an error */
|
||||
if (!write_block->success)
|
||||
return;
|
||||
|
||||
switch(option_id)
|
||||
{
|
||||
case OPT_COMMENT:
|
||||
case OPT_SHB_HARDWARE:
|
||||
case OPT_SHB_OS:
|
||||
case OPT_SHB_USERAPPL:
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_CUSTOM_STR_COPY:
|
||||
case OPT_CUSTOM_BIN_COPY:
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
/* Unknown options - write by datatype? */
|
||||
break;
|
||||
}
|
||||
return TRUE; /* success */
|
||||
}
|
||||
|
||||
/* Write a section header block.
|
||||
|
@ -3885,10 +3877,8 @@ pcapng_write_section_header_block(wtap_dumper *wdh, int *err)
|
|||
/* Write options */
|
||||
block_data.wdh = wdh;
|
||||
block_data.err = err;
|
||||
block_data.success = TRUE;
|
||||
wtap_block_foreach_option(wdh_shb, write_wtap_shb_option, &block_data);
|
||||
|
||||
if (!block_data.success)
|
||||
if (!wtap_block_foreach_option(wdh_shb, write_wtap_shb_option,
|
||||
&block_data))
|
||||
return FALSE;
|
||||
|
||||
/* Write end of options */
|
||||
|
@ -4539,7 +4529,7 @@ pcapng_write_decryption_secrets_block(wtap_dumper *wdh, wtap_block_t sdata, int
|
|||
|
||||
#define NRES_BLOCK_MAX_SIZE (1024*1024)
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
compute_nrb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data)
|
||||
{
|
||||
pcapng_block_size_t* block_size = (pcapng_block_size_t*)user_data;
|
||||
|
@ -4576,9 +4566,10 @@ compute_nrb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e
|
|||
}
|
||||
block_size->size += 4;
|
||||
}
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t* optval, void* user_data)
|
||||
{
|
||||
guint8 **opt_ptrp = (guint8 **)user_data;
|
||||
|
@ -4661,6 +4652,7 @@ put_nrb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_ty
|
|||
/* Unknown options - size by datatype? */
|
||||
break;
|
||||
}
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -4952,7 +4944,7 @@ pcapng_write_name_resolution_block(wtap_dumper *wdh, int *err)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void compute_isb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
static gboolean compute_isb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
{
|
||||
pcapng_block_size_t* block_size = (pcapng_block_size_t*)user_data;
|
||||
guint32 size = 0;
|
||||
|
@ -4992,52 +4984,42 @@ static void compute_isb_option_size(wtap_block_t block _U_, guint option_id, wta
|
|||
}
|
||||
block_size->size += 4;
|
||||
}
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void write_wtap_isb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
static gboolean write_wtap_isb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
{
|
||||
pcapng_write_block_t* write_block = (pcapng_write_block_t*)user_data;
|
||||
|
||||
/* Don't continue if there has been an error */
|
||||
if (!write_block->success)
|
||||
return;
|
||||
|
||||
switch(option_id)
|
||||
{
|
||||
case OPT_COMMENT:
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_CUSTOM_STR_COPY:
|
||||
case OPT_CUSTOM_BIN_COPY:
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_ISB_STARTTIME:
|
||||
case OPT_ISB_ENDTIME:
|
||||
if (!pcapng_write_option_timestamp(write_block->wdh, option_id, optval->uint64val, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_timestamp(write_block->wdh, option_id, optval->uint64val, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_ISB_IFRECV:
|
||||
case OPT_ISB_IFDROP:
|
||||
case OPT_ISB_FILTERACCEPT:
|
||||
case OPT_ISB_OSDROP:
|
||||
case OPT_ISB_USRDELIV:
|
||||
if (!pcapng_write_option_uint64(write_block->wdh, option_id, optval->uint64val, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_uint64(write_block->wdh, option_id, optval->uint64val, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
/* Unknown options - write by datatype? */
|
||||
break;
|
||||
}
|
||||
return TRUE; /* success */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -5082,10 +5064,8 @@ pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtap_block_t if_stats,
|
|||
if (block_size.size > 0) {
|
||||
block_data.wdh = wdh;
|
||||
block_data.err = err;
|
||||
block_data.success = TRUE;
|
||||
wtap_block_foreach_option(if_stats, write_wtap_isb_option, &block_data);
|
||||
|
||||
if (!block_data.success)
|
||||
if (!wtap_block_foreach_option(if_stats, write_wtap_isb_option,
|
||||
&block_data))
|
||||
return FALSE;
|
||||
|
||||
/* Write end of options */
|
||||
|
@ -5101,7 +5081,7 @@ pcapng_write_interface_statistics_block(wtap_dumper *wdh, wtap_block_t if_stats,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void compute_idb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
static gboolean compute_idb_option_size(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
{
|
||||
pcapng_block_size_t* block_size = (pcapng_block_size_t*)user_data;
|
||||
guint32 size = 0;
|
||||
|
@ -5163,9 +5143,10 @@ static void compute_idb_option_size(wtap_block_t block _U_, guint option_id, wta
|
|||
}
|
||||
block_size->size += 4;
|
||||
}
|
||||
return TRUE; /* we always succeed */
|
||||
}
|
||||
|
||||
static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
static gboolean write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_opttype_e option_type _U_, wtap_optval_t *optval, void* user_data)
|
||||
{
|
||||
pcapng_write_block_t* write_block = (pcapng_write_block_t*)user_data;
|
||||
struct pcapng_option_header option_hdr;
|
||||
|
@ -5178,29 +5159,21 @@ static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_
|
|||
case OPT_IDB_DESCR:
|
||||
case OPT_IDB_OS:
|
||||
case OPT_IDB_HARDWARE:
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_string(write_block->wdh, option_id, optval->stringval, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_CUSTOM_STR_COPY:
|
||||
case OPT_CUSTOM_BIN_COPY:
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_custom_option(write_block->wdh, option_id, &optval->custom_opt, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_IDB_SPEED:
|
||||
if (!pcapng_write_option_uint64(write_block->wdh, option_id, optval->uint64val, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_uint64(write_block->wdh, option_id, optval->uint64val, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_IDB_TSRESOL:
|
||||
if (!pcapng_write_option_uint8(write_block->wdh, option_id, optval->uint8val, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_uint8(write_block->wdh, option_id, optval->uint8val, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
case OPT_IDB_FILTER:
|
||||
{
|
||||
|
@ -5220,7 +5193,7 @@ static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_
|
|||
*
|
||||
* XXX - truncate it? Report an error?
|
||||
*/
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -5235,13 +5208,13 @@ static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_
|
|||
*
|
||||
* XXX - truncate it? Report an error?
|
||||
*/
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/* Unknown filter type; don't write anything. */
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
size = (guint32)(filter_data_len + 1);
|
||||
if ((size % 4)) {
|
||||
|
@ -5252,63 +5225,52 @@ static void write_wtap_idb_option(wtap_block_t block _U_, guint option_id, wtap_
|
|||
|
||||
option_hdr.type = option_id;
|
||||
option_hdr.value_length = size;
|
||||
if (!wtap_dump_file_write(write_block->wdh, &option_hdr, 4, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!wtap_dump_file_write(write_block->wdh, &option_hdr, 4, write_block->err))
|
||||
return FALSE;
|
||||
write_block->wdh->bytes_dumped += 4;
|
||||
|
||||
/* Write the filter type */
|
||||
if (!wtap_dump_file_write(write_block->wdh, &filter_type, 1, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!wtap_dump_file_write(write_block->wdh, &filter_type, 1, write_block->err))
|
||||
return FALSE;
|
||||
write_block->wdh->bytes_dumped += 1;
|
||||
|
||||
switch (filter->type) {
|
||||
|
||||
case if_filter_pcap:
|
||||
/* Write the filter string */
|
||||
if (!wtap_dump_file_write(write_block->wdh, filter->data.filter_str, filter_data_len, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!wtap_dump_file_write(write_block->wdh, filter->data.filter_str, filter_data_len, write_block->err))
|
||||
return FALSE;
|
||||
write_block->wdh->bytes_dumped += filter_data_len;
|
||||
break;
|
||||
|
||||
case if_filter_bpf:
|
||||
if (!wtap_dump_file_write(write_block->wdh, filter->data.bpf_prog.bpf_prog, filter_data_len, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!wtap_dump_file_write(write_block->wdh, filter->data.bpf_prog.bpf_prog, filter_data_len, write_block->err))
|
||||
return FALSE;
|
||||
write_block->wdh->bytes_dumped += filter_data_len;
|
||||
break;
|
||||
|
||||
default:
|
||||
ws_assert_not_reached();
|
||||
return;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* write padding (if any) */
|
||||
if (pad != 0) {
|
||||
if (!wtap_dump_file_write(write_block->wdh, &zero_pad, pad, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!wtap_dump_file_write(write_block->wdh, &zero_pad, pad, write_block->err))
|
||||
return FALSE;
|
||||
write_block->wdh->bytes_dumped += pad;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OPT_IDB_FCSLEN:
|
||||
if (!pcapng_write_option_uint8(write_block->wdh, option_id, optval->uint8val, write_block->err)) {
|
||||
write_block->success = FALSE;
|
||||
return;
|
||||
}
|
||||
if (!pcapng_write_option_uint8(write_block->wdh, option_id, optval->uint8val, write_block->err))
|
||||
return FALSE;
|
||||
break;
|
||||
default:
|
||||
/* Unknown options - size by datatype? */
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -5365,10 +5327,8 @@ pcapng_write_if_descr_block(wtap_dumper *wdh, wtap_block_t int_data, int *err)
|
|||
/* Write options */
|
||||
block_data.wdh = wdh;
|
||||
block_data.err = err;
|
||||
block_data.success = TRUE;
|
||||
wtap_block_foreach_option(int_data, write_wtap_idb_option, &block_data);
|
||||
|
||||
if (!block_data.success)
|
||||
if (!wtap_block_foreach_option(int_data, write_wtap_idb_option,
|
||||
&block_data))
|
||||
return FALSE;
|
||||
|
||||
/* Write end of options */
|
||||
|
|
|
@ -354,7 +354,7 @@ wtap_block_t wtap_block_make_copy(wtap_block_t block)
|
|||
return block_copy;
|
||||
}
|
||||
|
||||
void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data)
|
||||
gboolean wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data)
|
||||
{
|
||||
guint i;
|
||||
wtap_option_t *opt;
|
||||
|
@ -363,8 +363,10 @@ void wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func,
|
|||
for (i = 0; i < block->options->len; i++) {
|
||||
opt = &g_array_index(block->options, wtap_option_t, i);
|
||||
opttype = GET_OPTION_TYPE(block->info->options, opt->option_id);
|
||||
func(block, opt->option_id, opttype->data_type, &opt->value, user_data);
|
||||
if (!func(block, opt->option_id, opttype->data_type, &opt->value, user_data))
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static wtap_opttype_return_val
|
||||
|
|
|
@ -693,8 +693,8 @@ WS_DLL_PUBLIC void wtap_block_copy(wtap_block_t dest_block, wtap_block_t src_blo
|
|||
*/
|
||||
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);
|
||||
typedef gboolean (*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 gboolean wtap_block_foreach_option(wtap_block_t block, wtap_block_foreach_func func, void* user_data);
|
||||
|
||||
/** Cleanup the internal structures
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue