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