WIP.
[radsecproxy.git] / lib / attr.c
1 #include <freeradius/libradius.h>
2 #include "libradsec.h"
3 #include "libradsec-impl.h"
4
5 int
6 rs_attr_create(struct rs_connection *conn, struct rs_attr **attr, const char *type, const char *val)
7 {
8   VALUE_PAIR *vp;
9   struct rs_attr *a;
10
11   *attr = NULL;
12   a = (struct rs_attr *) malloc (sizeof(struct rs_attr));
13   if (!a)
14     return rs_conn_err_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
15   memset (a, 0, sizeof(struct rs_attr));
16
17   vp = pairmake (type, val, T_OP_EQ);
18   if (!vp)
19     {
20       rs_attr_destroy (a);
21       return rs_conn_err_push_fl (conn, RSE_FR, __FILE__, __LINE__,
22                                   "pairmake: %s", fr_strerror());
23     }
24
25   a->vp = vp;
26   *attr = a;
27   return RSE_OK;
28 }
29
30 void
31 rs_attr_destroy (struct rs_attr *attr)
32 {
33   if (attr->vp)
34     pairfree (&attr->vp);
35   free (attr);
36 }