Introduce tfs_get_string helper

true_false_strings have no helper function to properly retrieve the
string representing the true or false value, much like unit_strings,
even though this is not uncommon in dissectors.
This change introduces the helper function and modifies the dissectors,
so that they use this helper i.s.o. their own expressions.

Change-Id: I477ed2d90a9a529fc5dcfef7e3ea42ec180d27ae
Reviewed-on: https://code.wireshark.org/review/36920
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Jaap Keuter 2020-04-24 14:21:51 +02:00 committed by Anders Broman
parent c9295f161c
commit 9750d00ff1
18 changed files with 100 additions and 89 deletions

View File

@ -1605,6 +1605,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
tfs_fail_success@Base 1.9.1
tfs_found_not_found@Base 1.9.1
tfs_full_half@Base 1.99.1
tfs_get_string@Base 3.3.0
tfs_group_unique_name@Base 1.9.1
tfs_high_low@Base 1.9.1
tfs_high_normal@Base 2.5.1

View File

@ -4235,7 +4235,7 @@ elem_xmode(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 offset,
proto_tree_add_item(tree, hf_ansi_a_xmode_tfo_mode, tvb, curr_offset, 1, ENC_BIG_ENDIAN);
proto_item_append_text(data_p->elem_item, " - (%s)",
(oct & 0x01) ? tfs_ansi_a_xmode_tfo_mode.true_string : tfs_ansi_a_xmode_tfo_mode.false_string);
tfs_get_string(oct & 0x01, &tfs_ansi_a_xmode_tfo_mode));
curr_offset++;

View File

@ -1602,7 +1602,7 @@ proto_tree_add_debug_text(tree, "OCTET STRING dissect_ber_octet_string(%s) enter
"BER Error: OctetString expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class,
pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -1836,7 +1836,7 @@ dissect_ber_null(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbu
"BER Error: NULL expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class,
pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pc, &ber_pc_codes_short),
tag);
}
@ -2213,7 +2213,7 @@ proto_tree_add_debug_text(tree, "SEQUENCE dissect_ber_sequence(%s) entered\n", n
"BER Error: Sequence expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(classx, ber_class_codes, "Unknown"),
classx,
pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pcx, &ber_pc_codes_short),
tagx);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -2573,7 +2573,7 @@ proto_tree_add_debug_text(tree, "SET dissect_ber_set(%s) entered\n", name);
"BER Error: SET expected but class:%s(%d) %s tag:%d was found",
val_to_str_const(classx, ber_class_codes, "Unknown"),
classx,
pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pcx, &ber_pc_codes_short),
tagx);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3067,7 +3067,7 @@ dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int
tvb, identifier_offset, identifier_len,
"BER Error: GeneralString expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
ber_class, tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3138,7 +3138,7 @@ proto_tree_add_debug_text(tree, "RESTRICTED STRING dissect_ber_octet_string(%s)
"BER Error: String with tag=%d expected but class:%s(%d) %s tag:%d was unexpected",
type,
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
ber_class, tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3239,7 +3239,7 @@ proto_tree_add_debug_text(tree, "OBJECT IDENTIFIER dissect_ber_any_oid(%s) enter
"BER Error: Object Identifier expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class,
pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3383,7 +3383,7 @@ proto_tree_add_debug_text(tree, "SQ OF dissect_ber_sq_of(%s) entered\n", name);
"BER Error: %s OF expected but class:%s(%d) %s tag:%d was unexpected",
(type == BER_UNI_TAG_SEQUENCE) ? "SET" : "SEQUENCE",
val_to_str_const(classx, ber_class_codes, "Unknown"),
classx, pcx ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
classx, tfs_get_string(pcx, &ber_pc_codes_short),
tagx);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(causex, ett_ber_unknown);
@ -3641,7 +3641,7 @@ dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree
"BER Error: GeneralizedTime expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class,
pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3827,7 +3827,7 @@ dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, t
"BER Error: UTCTime expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class,
pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);
@ -3996,7 +3996,7 @@ dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto
tvb, identifier_offset, identifier_len,
"BER Error: BitString expected but class:%s(%d) %s tag:%d was unexpected",
val_to_str_const(ber_class, ber_class_codes, "Unknown"),
ber_class, pc ? ber_pc_codes_short.true_string : ber_pc_codes_short.false_string,
ber_class, tfs_get_string(pc, &ber_pc_codes_short),
tag);
if (decode_unexpected) {
proto_tree *unknown_tree = proto_item_add_subtree(cause, ett_ber_unknown);

View File

@ -6945,7 +6945,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
cost_com_item = proto_tree_add_item(community_tree, hf_bgp_ext_com_cost_cost, tvb,
offset+4, 4, ENC_BIG_ENDIAN);
proto_item_append_text(cost_com_item, " (%s)",
(tvb_get_guint8(tvb, offset+3) & BGP_EXT_COM_COST_CID_REP) ? tfs_cost_replace.true_string : tfs_cost_replace.false_string);
tfs_get_string(tvb_get_guint8(tvb, offset+3) & BGP_EXT_COM_COST_CID_REP, &tfs_cost_replace));
proto_item_append_text(community_item, " %u, POI: %s (%s)",
tvb_get_ntohl(tvb, offset+4),
@ -6967,7 +6967,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
proto_tree_add_item(ospf_rt_opt_tree, hf_bgp_ext_com_value_ospf_rt_options_mt,
tvb, offset+7, 1, ENC_BIG_ENDIAN);
proto_item_append_text(ospf_rt_opt_item, " (Metric: %s)",
(tvb_get_guint8(tvb,offset+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? tfs_ospf_rt_mt.true_string : tfs_ospf_rt_mt.false_string);
tfs_get_string(tvb_get_guint8(tvb,offset+7) & BGP_OSPF_RTYPE_METRIC_TYPE, &tfs_ospf_rt_mt));
proto_item_append_text(community_item, " Area: %s, Type: %s",
tvb_ip_to_str(tvb,offset+2),
@ -7021,7 +7021,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
cost_com_item = proto_tree_add_item(community_tree, hf_bgp_ext_com_cost_cost, tvb,
offset+4, 4, ENC_BIG_ENDIAN);
proto_item_append_text(cost_com_item, " (%s)",
(tvb_get_guint8(tvb, offset+3) & BGP_EXT_COM_COST_CID_REP) ? tfs_cost_replace.true_string : tfs_cost_replace.false_string);
tfs_get_string(tvb_get_guint8(tvb, offset+3) & BGP_EXT_COM_COST_CID_REP, &tfs_cost_replace));
proto_item_append_text(community_item, " %u, POI: %s (%s)",
tvb_get_ntohl(tvb, offset+4),
@ -7129,7 +7129,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
proto_item_set_generated(ti);
proto_item_append_text(community_item, " %s, Label: %u",
(tvb_get_guint8(tvb, offset+2) & BGP_EXT_COM_ESI_LABEL_FLAGS) ? tfs_esi_label_flag.true_string : tfs_esi_label_flag.false_string,
tfs_get_string(tvb_get_guint8(tvb, offset+2) & BGP_EXT_COM_ESI_LABEL_FLAGS, &tfs_esi_label_flag),
tvb_get_ntoh24(tvb,offset+5) >> 4);
}
break;
@ -7222,7 +7222,7 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
proto_tree_add_item(ospf_rt_opt_tree, hf_bgp_ext_com_value_ospf_rt_options_mt,
tvb, offset+7, 1, ENC_BIG_ENDIAN);
proto_item_append_text(ospf_rt_opt_item, " (Metric: %s)",
(tvb_get_guint8(tvb,offset+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? tfs_ospf_rt_mt.true_string : tfs_ospf_rt_mt.false_string);
tfs_get_string(tvb_get_guint8(tvb,offset+7) & BGP_OSPF_RTYPE_METRIC_TYPE, &tfs_ospf_rt_mt));
proto_item_append_text(community_item, " Area: %s, Type: %s",
tvb_ip_to_str(tvb,offset+2),
@ -7263,8 +7263,8 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
proto_tree_add_item(community_tree, hf_bgp_ext_com_flow_act_term_act, tvb, offset+7, 1, ENC_BIG_ENDIAN);
proto_item_append_text(community_item, " Sample: %s, Terminal: %s",
(tvb_get_guint8(tvb,offset+7) & BGP_EXT_COM_FSPEC_ACT_S) ? tfs_yes_no.true_string : tfs_yes_no.false_string,
(tvb_get_guint8(tvb,offset+7) & BGP_EXT_COM_FSPEC_ACT_T) ? tfs_yes_no.true_string : tfs_yes_no.false_string);
tfs_get_string(tvb_get_guint8(tvb,offset+7) & BGP_EXT_COM_FSPEC_ACT_S, &tfs_yes_no),
tfs_get_string(tvb_get_guint8(tvb,offset+7) & BGP_EXT_COM_FSPEC_ACT_T, &tfs_yes_no));
break;
case BGP_EXT_COM_STYPE_EXP_F_RED: /* Flow spec redirect [RFC5575] */
@ -7412,9 +7412,9 @@ dissect_bgp_update_ext_com(proto_tree *parent_tree, tvbuff_t *tvb, guint16 tlen,
proto_tree_add_item(eigrp_flags_tree, hf_bgp_ext_com_eigrp_flags_rt, tvb, offset+2, 2, ENC_BIG_ENDIAN);
proto_item_append_text(eigrp_flags_tree, " (%s)",
(tvb_get_ntohs(tvb, offset+2) & BGP_EXT_COM_EXP_EIGRP_FLAG_RT) ? tfs_eigrp_rtype.true_string : tfs_eigrp_rtype.false_string);
tfs_get_string(tvb_get_ntohs(tvb, offset+2) & BGP_EXT_COM_EXP_EIGRP_FLAG_RT, &tfs_eigrp_rtype));
proto_item_append_text(community_tree, " %s route",
(tvb_get_ntohs(tvb, offset+2) & BGP_EXT_COM_EXP_EIGRP_FLAG_RT) ? tfs_eigrp_rtype.true_string : tfs_eigrp_rtype.false_string);
tfs_get_string(tvb_get_ntohs(tvb, offset+2) & BGP_EXT_COM_EXP_EIGRP_FLAG_RT, &tfs_eigrp_rtype));
proto_tree_add_item(community_tree, hf_bgp_ext_com_eigrp_rtag, tvb, offset+4, 4, ENC_BIG_ENDIAN);
proto_item_append_text(community_tree, ", Tag: %u", tvb_get_ntohl(tvb, offset+4));

View File

@ -816,7 +816,7 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
if (ch_sel_valid) {
proto_item_append_text(advertising_header_item, ", ChSel: %s",
(header & 0x20) ? tfs_ch_sel.true_string : tfs_ch_sel.false_string);
tfs_get_string(header & 0x20, &tfs_ch_sel));
proto_tree_add_item(advertising_header_tree, hf_advertising_header_ch_sel, tvb, offset, 1, ENC_LITTLE_ENDIAN);
} else {
proto_tree_add_item(advertising_header_tree, hf_advertising_header_rfu_2, tvb, offset, 1, ENC_LITTLE_ENDIAN);
@ -824,7 +824,7 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
if (tx_add_valid) {
proto_item_append_text(advertising_header_item, ", TxAdd: %s",
(header & 0x40) ? tfs_random_public.true_string : tfs_random_public.false_string);
tfs_get_string(header & 0x40, &tfs_random_public));
proto_tree_add_item(advertising_header_tree, hf_advertising_header_randomized_tx, tvb, offset, 1, ENC_LITTLE_ENDIAN);
} else {
proto_tree_add_item(advertising_header_tree, hf_advertising_header_rfu_3, tvb, offset, 1, ENC_LITTLE_ENDIAN);
@ -832,7 +832,7 @@ dissect_btle(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
if (rx_add_valid) {
proto_item_append_text(advertising_header_item, ", RxAdd: %s",
(header & 0x80) ? tfs_random_public.true_string : tfs_random_public.false_string);
tfs_get_string(header & 0x80, &tfs_random_public));
proto_tree_add_item(advertising_header_tree, hf_advertising_header_randomized_rx, tvb, offset, 1, ENC_LITTLE_ENDIAN);
} else {
proto_tree_add_item(advertising_header_tree, hf_advertising_header_rfu_4, tvb, offset, 1, ENC_LITTLE_ENDIAN);

View File

@ -2806,7 +2806,7 @@ static gint dissect_dmp_envelope (tvbuff_t *tvb, packet_info *pinfo,
tf = proto_tree_add_boolean_format (envelope_tree, hf_envelope_extensions,
tvb, offset, 1, envelope,
"Extensions: %s",
(envelope & 0x80) ? "Present" : "Absent");
tfs_get_string(envelope & 0x80, &tfs_present_absent));
field_tree = proto_item_add_subtree (tf, ett_envelope_extensions);
proto_tree_add_item (field_tree, hf_envelope_extensions, tvb, offset, 1, ENC_BIG_ENDIAN);
}
@ -2816,7 +2816,7 @@ static gint dissect_dmp_envelope (tvbuff_t *tvb, packet_info *pinfo,
tf = proto_tree_add_boolean_format (envelope_tree,hf_envelope_rec_present,
tvb, offset, 1, envelope,
"Recipient Present: %s",
(envelope & 0x20) ? "Present" : "Absent");
tfs_get_string(envelope & 0x20, &tfs_present_absent));
field_tree = proto_item_add_subtree (tf, ett_envelope_rec_present);
proto_tree_add_item (field_tree, hf_envelope_rec_present, tvb, offset, 1, ENC_BIG_ENDIAN);
}
@ -2825,9 +2825,7 @@ static gint dissect_dmp_envelope (tvbuff_t *tvb, packet_info *pinfo,
tf = proto_tree_add_boolean_format (envelope_tree, hf_envelope_addr_enc,
tvb, offset, 1, envelope,
"Address Encoding: %s",
(envelope & 0x10) ?
addr_enc.true_string :
addr_enc.false_string);
tfs_get_string(envelope & 0x10, &addr_enc));
field_tree = proto_item_add_subtree (tf, ett_envelope_addr_enc);
proto_tree_add_item (field_tree, hf_envelope_addr_enc, tvb, offset, 1, ENC_BIG_ENDIAN);
@ -3173,9 +3171,8 @@ static gint dissect_dmp_report (tvbuff_t *tvb, packet_info *pinfo,
/* Report Type */
tf = proto_tree_add_boolean_format (report_tree, hf_report_type,
tvb, offset, 1, report,
"Report Type: %s", rep_type ?
report_type.true_string :
report_type.false_string);
"Report Type: %s",
tfs_get_string(rep_type, &report_type));
field_tree = proto_item_add_subtree (tf, ett_report_type);
proto_tree_add_item (field_tree, hf_report_type, tvb, offset, 1, ENC_BIG_ENDIAN);
@ -3185,7 +3182,8 @@ static gint dissect_dmp_report (tvbuff_t *tvb, packet_info *pinfo,
info_present = (report & 0x40);
tf = proto_tree_add_boolean_format (report_tree,hf_report_info_present_dr,
tvb, offset, 1, report,
"Info Present: %s", (report & 0x40) ? "Present" : "Absent");
"Info Present: %s",
tfs_get_string(report & 0x40, &tfs_present_absent));
field_tree = proto_item_add_subtree (tf, ett_report_info_present_dr);
proto_tree_add_item (field_tree, hf_report_info_present_dr, tvb, offset, 1, ENC_BIG_ENDIAN);
@ -3194,9 +3192,7 @@ static gint dissect_dmp_report (tvbuff_t *tvb, packet_info *pinfo,
tf = proto_tree_add_boolean_format (report_tree, hf_report_addr_enc_dr,
tvb, offset, 1, report,
"Address Encoding: %s",
(report & 0x20) ?
addr_enc.true_string :
addr_enc.false_string);
tfs_get_string(report & 0x20, &addr_enc));
field_tree = proto_item_add_subtree (tf, ett_report_addr_enc_dr);
proto_tree_add_item (field_tree, hf_report_addr_enc_dr, tvb, offset, 1, ENC_BIG_ENDIAN);
@ -3235,9 +3231,7 @@ static gint dissect_dmp_report (tvbuff_t *tvb, packet_info *pinfo,
tf = proto_tree_add_boolean_format (report_tree, hf_report_addr_enc_ndr,
tvb, offset, 1, report,
"Address Encoding: %s",
(report & 0x40) ?
addr_enc.true_string :
addr_enc.false_string);
tfs_get_string(report & 0x40, &addr_enc));
field_tree = proto_item_add_subtree (tf, ett_report_addr_enc_ndr);
proto_tree_add_item (field_tree, hf_report_addr_enc_ndr, tvb, offset, 1, ENC_BIG_ENDIAN);
@ -3780,13 +3774,11 @@ static gint dissect_dmp_content (tvbuff_t *tvb, packet_info *pinfo,
proto_item_append_text (tf, "Reserved (0x%2.2x)", dtg & 0x7F);
} else if (secs == 0) {
proto_item_append_text (tf, "0 minutes in the %s (%s)",
(dtg & 0x80) ? dtg_sign.true_string :
dtg_sign.false_string,
tfs_get_string(dtg & 0x80, &dtg_sign),
abs_time_secs_to_str (wmem_packet_scope(), dmp.subm_time, ABSOLUTE_TIME_LOCAL, TRUE));
} else {
proto_item_append_text (tf, "%s in the %s (%s)", signed_time_secs_to_str(wmem_packet_scope(), secs),
(dtg & 0x80) ? dtg_sign.true_string :
dtg_sign.false_string, (dtg & 0x80) ?
tfs_get_string(dtg & 0x80, &dtg_sign), (dtg & 0x80) ?
abs_time_secs_to_str (wmem_packet_scope(), dmp.subm_time + secs, ABSOLUTE_TIME_LOCAL, TRUE) :
abs_time_secs_to_str (wmem_packet_scope(), dmp.subm_time - secs, ABSOLUTE_TIME_LOCAL, TRUE));
}

View File

@ -2040,8 +2040,8 @@ dissect_low_trailer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint o
* and "OUT", but rather can continue to use typical boolean values. "IN"
* and "OUT" are provided as convenience. */
proto_tree_add_boolean_format_value(tree, hf_ingress, tvb, o, 1, ingress, "%s (%s)",
ingress ? tfs_true_false.true_string : tfs_true_false.false_string,
ingress ? f5tfs_ing.true_string : f5tfs_ing.false_string);
tfs_get_string(ingress, &tfs_true_false),
tfs_get_string(ingress, &f5tfs_ing));
o++;
proto_tree_add_uint(tree, slot_display_field, tvb, o, 1, slot_display);
@ -2445,8 +2445,8 @@ dissect_dpt_trailer_noise_low(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tre
* and "OUT", but rather can continue to use typical boolean values. "IN"
* and "OUT" are provided as convenience. */
pi = proto_tree_add_boolean_format_value(tree, hf_ingress, tvb, offset, 1, ingress,
"%s (%s)", ingress ? tfs_true_false.true_string : tfs_true_false.false_string,
ingress ? f5tfs_ing.true_string : f5tfs_ing.false_string);
"%s (%s)", tfs_get_string(ingress, &tfs_true_false),
tfs_get_string(ingress, &f5tfs_ing));
if (ver > 2) {
/* The old ingress field is now a flag field. Leave the old ingress field
* for backward compatability for users that are accustomed to using

View File

@ -4456,7 +4456,7 @@ dissect_ieee802154_assoc_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
};
cap = tvb_get_guint8(tvb, 0);
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", (cap & IEEE802154_CMD_CINFO_DEVICE_TYPE) ? tfs_cinfo_device_type.true_string : tfs_cinfo_device_type.false_string);
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", tfs_get_string(cap & IEEE802154_CMD_CINFO_DEVICE_TYPE, &tfs_cinfo_device_type));
/* Create a subtree for this command frame. */
subtree = proto_tree_add_subtree(tree, tvb, 0, 1, ett_ieee802154_cmd, NULL,

View File

@ -2655,7 +2655,7 @@ add_events(tvbuff_t *tvb, int offs, proto_tree *tree, const struct true_false_st
}
msk = 1 << j;
proto_tree_add_boolean_format_value(s_tree, *bsel[i][j], tvb, offs, 1,
val & msk, "%s", (val & msk) ? tfs->true_string : tfs->false_string);
val & msk, "%s", tfs_get_string(val & msk, tfs));
}
}
}

View File

@ -3397,9 +3397,9 @@ dissect_isakmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _
proto_tree_add_item(ftree, hf_isakmp_flag_r, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_item_append_text(fti, " (%s, %s, %s)",
(flags & I_FLAG) ? flag_i.true_string : flag_i.false_string,
(flags & V_FLAG) ? flag_v.true_string : flag_v.false_string,
(flags & R_FLAG) ? flag_r.true_string : flag_r.false_string);
tfs_get_string(flags & I_FLAG, &flag_i),
tfs_get_string(flags & V_FLAG, &flag_v),
tfs_get_string(flags & R_FLAG, &flag_r));
}
offset += 1;
}
@ -3412,8 +3412,8 @@ dissect_isakmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _
if (isakmp_version == 2) {
col_append_fstr(pinfo->cinfo, COL_INFO, " MID=%02u %s %s",
hdr.message_id,
(flags & I_FLAG) ? flag_i.true_string : flag_i.false_string,
(flags & R_FLAG) ? flag_r.true_string : flag_r.false_string);
tfs_get_string(flags & I_FLAG, &flag_i),
tfs_get_string(flags & R_FLAG, &flag_r));
}
if (hdr.length < ISAKMP_HDR_SIZE) {

View File

@ -521,15 +521,11 @@ static int dissect_iso14443_atqb(tvbuff_t *tvb, gint offset,
nad_supported = tvb_get_guint8(tvb, offset) & 0x02;
proto_tree_add_boolean_bits_format_value(prot_inf_tree,
hf_iso14443_nad_supported, tvb, 8*offset+6, 1, nad_supported,
"%s", nad_supported ?
tfs_supported_not_supported.true_string :
tfs_supported_not_supported.false_string);
"%s", tfs_get_string(nad_supported, &tfs_supported_not_supported));
cid_supported = tvb_get_guint8(tvb, offset) & 0x01;
proto_tree_add_boolean_bits_format_value(prot_inf_tree,
hf_iso14443_cid_supported, tvb, 8*offset+7, 1, cid_supported,
"%s", cid_supported ?
tfs_supported_not_supported.true_string :
tfs_supported_not_supported.false_string);
"%s", tfs_get_string(cid_supported, &tfs_supported_not_supported));
offset++;
/* XXX - extended ATQB */
@ -571,8 +567,7 @@ dissect_iso14443_cmd_type_wupb(tvbuff_t *tvb, packet_info *pinfo,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(tree, hf_iso14443_wupb,
tvb, offset, 1, ENC_BIG_ENDIAN);
msg_type = (param & 0x08) ?
tfs_wupb_reqb.true_string : tfs_wupb_reqb.false_string;
msg_type = tfs_get_string(param & 0x08, &tfs_wupb_reqb);
col_set_str(pinfo->cinfo, COL_INFO, msg_type);
proto_item_append_text(ti, ": %s", msg_type);
proto_tree_add_uint_bits_format_value(tree, hf_iso14443_n,
@ -772,15 +767,11 @@ static int dissect_iso14443_ats(tvbuff_t *tvb, gint offset,
cid_supported = tvb_get_guint8(tvb, offset) & 0x02;
proto_tree_add_boolean_bits_format_value(tc1_tree,
hf_iso14443_cid_supported, tvb, 8*offset+6, 1, cid_supported,
"%s", cid_supported ?
tfs_supported_not_supported.true_string :
tfs_supported_not_supported.false_string);
"%s", tfs_get_string(cid_supported, &tfs_supported_not_supported));
nad_supported = tvb_get_guint8(tvb, offset) & 0x01;
proto_tree_add_boolean_bits_format_value(tc1_tree,
hf_iso14443_nad_supported, tvb, 8*offset+7, 1, nad_supported,
"%s", nad_supported ?
tfs_supported_not_supported.true_string :
tfs_supported_not_supported.false_string);
"%s", tfs_get_string(nad_supported, &tfs_supported_not_supported));
offset++;
}
hist_len = tl - (offset - offset_tl);
@ -1147,8 +1138,7 @@ dissect_iso14443_cmd_type_block(tvbuff_t *tvb, packet_info *pinfo,
case R_BLOCK_TYPE:
col_append_sep_str(pinfo->cinfo, COL_INFO, NULL,
(pcb & 0x10) ?
tfs_nak_ack.true_string : tfs_nak_ack.false_string);
tfs_get_string(pcb & 0x10, &tfs_nak_ack));
proto_tree_add_item(pcb_tree, hf_iso14443_nak,
tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(pcb_tree, hf_iso14443_cid_following,

View File

@ -844,7 +844,7 @@ dissect_netlink_route_ifla_attrs(tvbuff_t *tvb, void *data, struct packet_netlin
return 1;
case WS_IFLA_CARRIER:
proto_tree_add_item_ret_boolean(tree, &hfi_netlink_route_ifla_carrier, tvb, offset, len, nl_data->encoding, &flag);
proto_item_append_text(tree, ": %s", flag ? tfs_restricted_not_restricted.true_string : tfs_restricted_not_restricted.false_string);
proto_item_append_text(tree, ": %s", tfs_get_string(flag, &tfs_restricted_not_restricted));
return 1;
case WS_IFLA_CARRIER_CHANGES:
proto_tree_add_item_ret_uint(tree, &hfi_netlink_route_ifla_carrier_changes, tvb, offset, len, nl_data->encoding, &value);

View File

@ -3897,7 +3897,7 @@ decode_pfcp_urr_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, prot
offset += 4;
proto_item_append_text(item, "%s %u",
((urr_id_flag)? pfcp_id_predef_dynamic_tfs.true_string : pfcp_id_predef_dynamic_tfs.false_string),
tfs_get_string(urr_id_flag, &pfcp_id_predef_dynamic_tfs),
(urr_id & 0x7fffffff));
return offset;
@ -4657,7 +4657,7 @@ decode_pfcp_far_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, prot
offset += 4;
proto_item_append_text(item, "%s %u",
((far_id_flag)? pfcp_id_predef_dynamic_tfs.true_string : pfcp_id_predef_dynamic_tfs.false_string),
tfs_get_string(far_id_flag, &pfcp_id_predef_dynamic_tfs),
(far_id & 0x7fffffff));
return offset;
@ -4695,7 +4695,7 @@ decode_pfcp_qer_id(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, prot
offset += 4;
proto_item_append_text(item, "%s %u",
((qer_id_flag)? pfcp_id_predef_dynamic_tfs.true_string : pfcp_id_predef_dynamic_tfs.false_string),
tfs_get_string(qer_id_flag, &pfcp_id_predef_dynamic_tfs),
(qer_id & 0x7fffffff));
return offset;

View File

@ -5201,9 +5201,7 @@ int dissect_wassp_tlv(proto_tree *wassp_tree, tvbuff_t *tvb, packet_info *pinfo,
case EID_RU_STATE: // 11
proto_tree_add_item(tlv_tree, hf_wassp_tlv_eid_rustate, tvb, offset + TLV_VALUE, length - 4, ENC_BIG_ENDIAN);
proto_item_append_text(tlvi, ": %s",
(tvb_get_guint8(tvb, offset + TLV_VALUE) ?
wassp_eid_rustate_types.true_string :
wassp_eid_rustate_types.false_string));
tfs_get_string(tvb_get_guint8(tvb, offset + TLV_VALUE), &wassp_eid_rustate_types));
offset += length;
break;

View File

@ -6338,9 +6338,7 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence,
tfstring = (const struct true_false_string*) hfinfo->strings;
}
offset_r += protoo_strlcpy(result+offset_r,
number64 ?
tfstring->true_string :
tfstring->false_string, size-offset_r);
tfs_get_string(!!number64, tfstring), size-offset_r);
offset_e += protoo_strlcpy(expr+offset_e,
number64 ? "1" : "0", size-offset_e);
@ -9098,7 +9096,7 @@ fill_label_boolean(field_info *fi, gchar *label_str)
}
/* Fill in the textual info */
label_fill(label_str, bitfield_byte_length, hfinfo, value ? tfstring->true_string : tfstring->false_string);
label_fill(label_str, bitfield_byte_length, hfinfo, tfs_get_string(!!value, tfstring));
}
static const char *
@ -11953,8 +11951,7 @@ _proto_tree_add_bits_ret_val(proto_tree *tree, const int hfindex, tvbuff_t *tvb,
tfstring = (const true_false_string *)hf_field->strings;
return proto_tree_add_boolean_format(tree, hfindex, tvb, offset, length, (guint32)value,
"%s = %s: %s",
bf_str, hf_field->name,
value ? tfstring->true_string : tfstring->false_string);
bf_str, hf_field->name, tfs_get_string(!!value, tfstring));
break;
case FT_CHAR:
@ -12135,8 +12132,7 @@ proto_tree_add_split_bits_item_ret_val(proto_tree *tree, const int hfindex, tvbu
return proto_tree_add_boolean_format(tree, hfindex,
tvb, octet_offset, octet_length, (guint32)value,
"%s = %s: %s",
bf_str, hf_field->name,
value ? tfstring->true_string : tfstring->false_string);
bf_str, hf_field->name, tfs_get_string(!!value, tfstring));
break;
case FT_CHAR:

View File

@ -13,6 +13,11 @@
#include "tfs.h"
const char *tfs_get_string(gboolean value, const true_false_string *tfs)
{
return value ? tfs->true_string : tfs->false_string;
}
/*
* A default set of true/false strings that dissectors can use for
* FT_BOOLEAN header fields.
@ -98,3 +103,16 @@ const true_false_string tfs_external_internal = { "External", "Internal" };
const true_false_string tfs_changed_not_changed = { "Changed", "Not Changed" };
const true_false_string tfs_needed_not_needed = { "Needed", "Not Needed" };
const true_false_string tfs_selected_not_selected = { "Selected", "Not Selected" };
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -12,6 +12,7 @@
#ifndef __TFS_H__
#define __TFS_H__
#include <glib.h>
#include "ws_symbol_export.h"
#ifdef __cplusplus
@ -24,10 +25,12 @@ extern "C" {
/** Struct for boolean enumerations */
typedef struct true_false_string {
const char *true_string; /**< The string presented when true */
const char *false_string; /**< The string presented when false */
const char *true_string; /**< The string presented when true */
const char *false_string; /**< The string presented when false */
} true_false_string;
WS_DLL_PUBLIC const char *tfs_get_string(gboolean, const true_false_string *);
/*
* A default set of true/false strings that dissectors can use for
* FT_BOOLEAN header fields.
@ -119,3 +122,16 @@ WS_DLL_PUBLIC const true_false_string tfs_selected_not_selected;
#endif /* __cplusplus */
#endif /* __TFS_H__ */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/

View File

@ -1164,8 +1164,8 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
switch(hfinfo->type) {
case FT_BOOLEAN:
uvalue64 = fvalue_get_uinteger64(&finfo->value);
tfstring = (const struct true_false_string*) hfinfo->strings;
g_string_append(label_s, uvalue64 ? tfstring->true_string : tfstring->false_string);
tfstring = (const true_false_string*) hfinfo->strings;
g_string_append(label_s, tfs_get_string(!!uvalue64, tfstring));
break;
case FT_INT8:
case FT_INT16: