Skip to content

Commit

Permalink
Add value_data_steal
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed May 15, 2015
1 parent 3d2bfdd commit 30c6635
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/include/libradius.h
Expand Up @@ -678,6 +678,8 @@ size_t value_data_prints(char *out, size_t outlen,
PW_TYPE type, DICT_ATTR const *enumv,
value_data_t const *data, char quote);

int value_data_steal(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE type, value_data_t const *src);

char *value_data_aprints(TALLOC_CTX *ctx,
PW_TYPE type, DICT_ATTR const *enumv, value_data_t const *data,
char quote);
Expand Down
30 changes: 30 additions & 0 deletions src/lib/value.c
Expand Up @@ -1413,7 +1413,37 @@ int value_data_copy(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE src_type, const
return 0;
}

/** Copy value data verbatim moving any buffers to the specified context
*
* @param ctx To allocate buffers in.
* @param dst Where to copy value_data to.
* @param src_type Type of src.
* @param src Where to copy value_data from.
* @return
* - 0 on success.
* - -1 on failure.
*/
int value_data_steal(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE src_type, const value_data_t *src)
{
switch (src_type) {
default:
memcpy(dst, src, sizeof(*src));
break;

case PW_TYPE_STRING:
dst->strvalue = talloc_steal(ctx, src->strvalue);
if (!dst->strvalue) return -1;
break;

case PW_TYPE_OCTETS:
dst->octets = talloc_steal(ctx, src->octets);
if (!dst->octets) return -1;
break;
}
dst->length = src->length;

return 0;
}

/** Print one attribute value to a string
*
Expand Down

0 comments on commit 30c6635

Please sign in to comment.