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