Formatting changes.
[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,
14                struct rs_attr **attr,
15                const char *type,
16                const char *val)
17 {
18   VALUE_PAIR *vp;
19   struct rs_attr *a;
20
21   *attr = NULL;
22   a = (struct rs_attr *) malloc (sizeof(struct rs_attr));
23   if (!a)
24     return rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
25   memset (a, 0, sizeof(struct rs_attr));
26
27   vp = pairmake (type, val, T_OP_EQ);
28   if (!vp)
29     {
30       rs_attr_destroy (a);
31       return rs_err_conn_push_fl (conn, RSE_FR, __FILE__, __LINE__,
32                                   "pairmake: %s", fr_strerror ());
33     }
34
35   a->vp = vp;
36   *attr = a;
37   return RSE_OK;
38 }
39
40 void
41 rs_attr_destroy (struct rs_attr *attr)
42 {
43   if (attr->vp)
44     pairfree (&attr->vp);
45   free (attr);
46 }