Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove last call to pairdatacpy and remove pairdatacpy
  • Loading branch information
arr2036 committed Dec 11, 2014
1 parent 1c15c16 commit 26ad3c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 89 deletions.
1 change: 0 additions & 1 deletion src/include/libradius.h
Expand Up @@ -629,7 +629,6 @@ void pairmemsteal(VALUE_PAIR *vp, uint8_t const *src);
void pairstrsteal(VALUE_PAIR *vp, char const *src);
void pairstrcpy(VALUE_PAIR *vp, char const * src);
void pairstrncpy(VALUE_PAIR *vp, char const * src, size_t len);
int pairdatacpy(VALUE_PAIR *vp, PW_TYPE type, value_data_t const *data, size_t len);
void pairsprintf(VALUE_PAIR *vp, char const * fmt, ...) CC_HINT(format (printf, 2, 3));
void pairmove(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from);
void pairfilter(TALLOC_CTX *ctx, VALUE_PAIR **to, VALUE_PAIR **from,
Expand Down
82 changes: 0 additions & 82 deletions src/lib/pair.c
Expand Up @@ -2107,88 +2107,6 @@ void pairstrncpy(VALUE_PAIR *vp, char const *src, size_t len)
pairtypeset(vp);
}

/** Copy data from one VP to another
*
* Allocate a new pair using da, and copy over the value from the specified vp.
*
* @todo Should be able to do type conversions.
*
* @param[in,out] vp to update.
* @param[in] type of data represented by data.
* @param[in] data to copy.
* @param[in] len of data to copy.
* @return 0 on success -1 on failure.
*/
int pairdatacpy(VALUE_PAIR *vp, PW_TYPE type, value_data_t const *data, size_t len)
{
void *old;
VERIFY_VP(vp);

/*
* The types have to be identical, OR the "from" type has
* to be octets.
*/
if (vp->da->type != type) {
/*
* Decode the octets buffer using the RADIUS decoder.
*/
if (type == PW_TYPE_OCTETS) {
if (data2vp(vp, NULL, NULL, NULL, vp->da, data->octets, len, len, &vp) < 0) return -1;
vp->type = VT_DATA;
return 0;
}

/*
* Else if the destination type is octets
*/
if (vp->da->type == PW_TYPE_OCTETS) {
int ret;
uint8_t *buff;
VALUE_PAIR const *pvp = vp;

buff = talloc_array(vp, uint8_t, dict_attr_sizes[type][1] + 2);

ret = rad_vp2rfc(NULL, NULL, NULL, &pvp, buff, dict_attr_sizes[type][1]);
if (ret < 0) return -1;

pairmemcpy(vp, buff + 2, ret - 2);
talloc_free(buff);

return 0;
}

/*
* Fixme...
*/
fr_strerror_printf("Data conversion not supported");
return -1;
}

/*
* Clear existing value if there is one
*/
memcpy(&old, &vp->data.ptr, sizeof(old));
talloc_free(old);

switch (vp->da->type) {
case PW_TYPE_TLV:
case PW_TYPE_OCTETS:
pairmemcpy(vp, data->octets, len);
break;

case PW_TYPE_STRING:
pairstrncpy(vp, data->strvalue, len);
break;

default:
memcpy(&vp->data, data, sizeof(vp->data));
break;
}
vp->vp_length = len;

return 0;
}

/** Print data into an "string" data type.
*
* @param[in,out] vp to update
Expand Down
12 changes: 10 additions & 2 deletions src/lib/value.c
Expand Up @@ -1193,10 +1193,18 @@ ssize_t value_data_cast(TALLOC_CTX *ctx, value_data_t *dst,
return src_len;
}

ssize_t value_data_copy(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE type,
/** Copy value data verbatim duplicating any buffers
*
* @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.
* @param src_len Where
*/
ssize_t value_data_copy(TALLOC_CTX *ctx, value_data_t *dst, PW_TYPE src_type,
const value_data_t *src, size_t src_len)
{
switch (type) {
switch (src_type) {
default:
memcpy(dst, src, sizeof(*src));
break;
Expand Down
8 changes: 4 additions & 4 deletions src/modules/rlm_cache/serialize.c
Expand Up @@ -139,6 +139,7 @@ int cache_deserialize(rlm_cache_entry_t *c, char *in, ssize_t inlen)
while (((size_t)(p - in)) < (size_t)inlen) {
value_pair_map_t *map = NULL;
VALUE_PAIR *vp = NULL;
ssize_t len;

q = strchr(p, '\n');
if (!q) break; /* List should also be terminated with a \n */
Expand Down Expand Up @@ -172,10 +173,9 @@ int cache_deserialize(rlm_cache_entry_t *c, char *in, ssize_t inlen)
if (!tmpl_cast_in_place(map->rhs, map->lhs->tmpl_da->type, map->lhs->tmpl_da)) goto error;

vp = pairalloc(c, map->lhs->tmpl_da);
if (pairdatacpy(vp, map->rhs->tmpl_data_type, &map->rhs->tmpl_data_value,
map->rhs->tmpl_data_length) < 0) {
goto error;
}
len = value_data_copy(vp, &vp->data, map->rhs->tmpl_data_type,
&map->rhs->tmpl_data_value, map->rhs->tmpl_data_length);
if (len < 0) goto error;

/*
* Pull out the special attributes, and set the
Expand Down

0 comments on commit 26ad3c0

Please sign in to comment.