From: Alan T. DeKok Date: Wed, 13 Nov 2024 13:01:00 +0000 (-0500) Subject: print casts for values of raw attributes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a634f4c6a713beb4154ba033dc68f6124918280;p=thirdparty%2Ffreeradius-server.git print casts for values of raw attributes now that we parse the cast, they should be printed, too --- diff --git a/src/lib/util/pair_print.c b/src/lib/util/pair_print.c index f01f25ea912..b8b64f75433 100644 --- a/src/lib/util/pair_print.c +++ b/src/lib/util/pair_print.c @@ -40,15 +40,17 @@ ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_token_t quote) { fr_sbuff_t our_out; + ssize_t slen; PAIR_VERIFY(vp); + our_out = FR_SBUFF(out); + switch (vp->vp_type) { /* * For structural types descend down */ case FR_TYPE_STRUCTURAL: - our_out = FR_SBUFF(out); if (fr_pair_list_empty(&vp->vp_group)) { FR_SBUFF_IN_CHAR_RETURN(&our_out, '{', ' ', '}'); @@ -66,8 +68,21 @@ ssize_t fr_pair_print_value_quoted(fr_sbuff_t *out, fr_pair_t const *vp, fr_toke * For simple types just print the box */ default: - return fr_value_box_print_quoted(out, &vp->data, quote); + /* + * If it's raw / unknown and not octets, print the cast before the type. + * + * Otherwise on parsing, we don't know how to interpret the value. :( + */ + if ((vp->da->flags.is_raw || vp->da->flags.is_unknown) && + (vp->vp_type != FR_TYPE_OCTETS)) { + FR_SBUFF_IN_SPRINTF_RETURN(&our_out, "(%s) ", fr_type_to_str(vp->vp_type)); + } + + slen = fr_value_box_print_quoted(&our_out, &vp->data, quote); + if (slen <= 0) return slen; } + + FR_SBUFF_SET_RETURN(out, &our_out); } /** Print one attribute and value to a string diff --git a/src/tests/unit/protocols/cbor/base.txt b/src/tests/unit/protocols/cbor/base.txt index a528f8c21aa..e515f6f5bef 100644 --- a/src/tests/unit/protocols/cbor/base.txt +++ b/src/tests/unit/protocols/cbor/base.txt @@ -64,7 +64,7 @@ match Vendor-Specific = { Nokia-SR = { Dhcp6-Renew-Time = 3600.5 } } # But because CBOR is typed, we can decode typed data. # decode-pair 9f a1 18 1a 9f a1 19 19 7f 9f a1 18 ff d9 03 ea a2 01 19 0e 10 28 1a 1d cd 65 00 ff ff ff -match Vendor-Specific = { Nokia-SR = { raw.255 = 3600.5 } } +match Vendor-Specific = { Nokia-SR = { raw.255 = (time_delta) 3600.5 } } # # Note that we have to add a cast here :(