Skip to content

Commit

Permalink
Added map2str, to mirror str2map
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Apr 23, 2013
1 parent 7194345 commit 5987696
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/include/radiusd.h
Expand Up @@ -904,6 +904,7 @@ value_pair_map_t *radius_str2map(TALLOC_CTX *ctx, const char *lhs, FR_TOKEN lhs_
pair_lists_t dst_list_def,
request_refs_t src_request_def,
pair_lists_t src_list_def);
size_t radius_map2str(char *buffer, size_t bufsize, value_pair_map_t const *map);
value_pair_map_t *radius_cp2map(TALLOC_CTX *ctx, CONF_PAIR *cp,
request_refs_t dst_request_def,
pair_lists_t dst_list_def,
Expand Down
37 changes: 37 additions & 0 deletions src/main/valuepair.c
Expand Up @@ -1808,6 +1808,43 @@ size_t radius_tmpl2str(char *buffer, size_t bufsize, value_pair_tmpl_t const *vp
}


/** Print a map to a string
*
* @param[out] buffer for the output string
* @param[in] bufsize of the buffer
* @param[in] map to print
* @return the size of the string printed
*/
size_t radius_map2str(char *buffer, size_t bufsize, value_pair_map_t const *map)
{
size_t len;
char *p = buffer;
char *end = buffer + bufsize;

len = radius_str2map(buffer, bufsize, map->dst);
p += len;

strlcpy(p, fr_token_name(map->op), end - p);
p += strlen(p);

/*
* The RHS doesn't matter for many operators
*/
if ((map->op == T_OP_CMP_TRUE) ||
(map->op == T_OP_CMP_FALSE)) {
strlcpy(p, "ANY", (end - p));
p += strlen(p);
return p - buffer;
}

rad_assert(map->src != NULL);
len = radius_str2map(buffer, bufsize, map->src);
p += len;

return p - buffer;
}


/** Add a module failure message VALUE_PAIR to the request
*/
DIAG_OFF(format-nonliteral)
Expand Down

0 comments on commit 5987696

Please sign in to comment.