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,
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
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;
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 */
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