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