Radcli library 2.0.0
A simple radius library -- new API reference
Loading...
Searching...
No Matches
radcli_avp_concat_str()/_by_num() – join every occurrence of a text attribute

Concatenate every occurrence of an attribute into a bounded buffer, following snprintf()'s buffer-sizing contract (buf may be NULL/buflen may be 0 to size a buffer first; the return value is always the number of bytes the joined result would occupy, whether or not it fit). More...

Functions

int radcli_avp_concat_str (char *buf, size_t buflen, const radcli_avp_list *list, const radcli_attr_def *def, const char *sep)
 Concatenate every occurrence of an attribute into a bounded buffer.
int radcli_avp_concat_str_by_num (char *buf, size_t buflen, const radcli_avp_list *list, const radcli_ctx *ctx, uint32_t attrid, uint32_t vendor, const char *sep)
 Look up an attribute by legacy numeric ID and concatenate every occurrence into a bounded buffer.

Detailed Description

Concatenate every occurrence of an attribute into a bounded buffer, following snprintf()'s buffer-sizing contract (buf may be NULL/buflen may be 0 to size a buffer first; the return value is always the number of bytes the joined result would occupy, whether or not it fit).

Function Documentation

◆ radcli_avp_concat_str()

int radcli_avp_concat_str ( char * buf,
size_t buflen,
const radcli_avp_list * list,
const radcli_attr_def * def,
const char * sep )

Concatenate every occurrence of an attribute into a bounded buffer.

Generalizes the one convenience legacy radcli.h's rc_aaa() folded into its own call signature (its msg parameter: "will contain the concatenation of any PW_REPLY_MESSAGE received", lib/buildreq.c) to any attribute, since the pattern – walk every occurrence of one attribute in a reply, join as text – is not specific to Reply-Message. A caller wanting rc_aaa()'s old convenience no longer needs to hand-roll the radcli_avp_get()-in-a-loop this replaces.

If no occurrence of def is present in list, buf is set to an empty string and 0 is returned – this is not a failure, the same way rc_aaa()'s msg started as '\0' and simply stayed that way when no Reply-Message arrived. An attribute whose value contains an embedded NUL byte, or (for a RADCLI_TYPE_TEXT attribute) invalid UTF-8, is skipped (radcli_avp_get_cstr()'s policy), not treated as a failure either.

Follows snprintf()'s buffer-sizing contract exactly: buf may be NULL and/or buflen may be 0 to size a buffer before allocating one (nothing is written in that case), and the return value is always the number of bytes the joined result would occupy, whether or not it fit – a return >= buflen means the result was truncated, and buf (if non-NULL and buflen > 0) then holds only a valid NUL-terminated prefix of what fits, never garbage and never unterminated.

Parameters
bufdestination buffer, or NULL to only compute the needed size; always left NUL-terminated on return (including on truncation, containing whatever fit), whenever buf is non-NULL and buflen > 0.
buflensize of buf, in bytes; may be 0.
listthe list to search.
defthe attribute to concatenate occurrences of.
sepseparator inserted between occurrences; NULL or "" for none.
Returns
the number of bytes the joined result occupies (excluding the NUL terminator), whether or not it fit in buf – or -1 if def is NULL.

Definition at line 1117 of file avp.c.

◆ radcli_avp_concat_str_by_num()

int radcli_avp_concat_str_by_num ( char * buf,
size_t buflen,
const radcli_avp_list * list,
const radcli_ctx * ctx,
uint32_t attrid,
uint32_t vendor,
const char * sep )

Look up an attribute by legacy numeric ID and concatenate every occurrence into a bounded buffer.

The _by_num() wrapper for radcli_avp_concat_str(): equivalent to radcli_avp_concat_str(buf, buflen, l, radcli_dict_lookup_num(ctx, attrid, vendor), sep), except that an unresolvable attribute ID is not itself a failure here – it is treated the same as "no occurrence present" (buf set to an empty string, 0 returned), matching this function's legacy-ID convenience role: a caller passing a well-known PW_* constant should not have to separately handle "not in this dictionary" as an error case, the same way rc_aaa()'s msg never failed just because a reply had no Reply-Message.

Parameters
bufdestination buffer, or NULL to only compute the needed size; see radcli_avp_concat_str().
buflensize of buf, in bytes; may be 0.
listthe list to search.
ctxa context with a dictionary loaded.
attridthe attribute ID (a PW_* constant, or a vendor type ID when vendor is non-zero).
vendorthe vendor PEN, or 0 for a standard attribute.
sepseparator inserted between occurrences; NULL or "" for none.
Returns
the number of bytes the joined result occupies (excluding the NUL terminator), whether or not it fit in buf; 0 if attrid/vendor resolves to no attribute.

Definition at line 1189 of file avp.c.