summaryrefslogtreecommitdiff
path: root/lib/attr.c
blob: 49735d9e81ee71416f8caa27bd9a0f8b63756c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* See the file COPYING for licensing information.  */

#include <freeradius/libradius.h>
#include <radsec/radsec.h>
#include <radsec/radsec-impl.h>

int
rs_attr_create(struct rs_connection *conn, struct rs_attr **attr, const char *type, const char *val)
{
  VALUE_PAIR *vp;
  struct rs_attr *a;

  *attr = NULL;
  a = (struct rs_attr *) malloc (sizeof(struct rs_attr));
  if (!a)
    return rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
  memset (a, 0, sizeof(struct rs_attr));

  vp = pairmake (type, val, T_OP_EQ);
  if (!vp)
    {
      rs_attr_destroy (a);
      return rs_err_conn_push_fl (conn, RSE_FR, __FILE__, __LINE__,
				  "pairmake: %s", fr_strerror());
    }

  a->vp = vp;
  *attr = a;
  return RSE_OK;
}

void
rs_attr_destroy (struct rs_attr *attr)
{
  if (attr->vp)
    pairfree (&attr->vp);
  free (attr);
}