1 /* Copyright 2010, 2011 NORDUnet A/S. All rights reserved.
2 See the file COPYING for licensing information. */
4 #if defined HAVE_CONFIG_H
15 #include <freeradius/libradius.h>
16 #include <event2/event.h>
17 #include <event2/util.h>
18 #include <radsec/radsec.h>
19 #include <radsec/radsec-impl.h>
20 #if defined (RS_ENABLE_TLS)
24 #include "../radsecproxy.h"
26 #include "rsp_debug.h"
29 /* Public functions. */
31 rs_context_create(struct rs_context **ctx, const char *dict)
35 char *buf1 = NULL, *buf2 = NULL;
42 h = (struct rs_context *) malloc (sizeof(struct rs_context));
46 /* Initialize freeradius dictionary. */
47 buf1 = malloc (strlen (dict) + 1);
48 buf2 = malloc (strlen (dict) + 1);
58 if (dict_init (dir, fn) < 0)
66 #if defined (RS_ENABLE_TLS)
73 debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
75 memset (h, 0, sizeof(struct rs_context));
76 fr_randinit (&h->fr_randctx, 0);
77 fr_rand_seed (NULL, 0);
95 _rs_peer_create (struct rs_context *ctx, struct rs_peer **rootp)
99 p = (struct rs_peer *) rs_malloc (ctx, sizeof(*p));
102 memset (p, 0, sizeof(struct rs_peer));
105 p->next = (*rootp)->next;
115 _rs_peer_destroy (struct rs_peer *p)
119 assert (p->conn->ctx);
120 /* NOTE: The peer object doesn't own its connection (conn). */
123 evutil_freeaddrinfo (p->addr);
127 rs_free (p->conn->ctx, p->secret);
128 rs_free (p->conn->ctx, p);
132 rs_context_destroy (struct rs_context *ctx)
134 struct rs_realm *r = NULL;
135 struct rs_peer *p = NULL;
137 for (r = ctx->realms; r; )
139 struct rs_realm *tmp = r;
140 for (p = r->peers; p; )
142 struct rs_peer *tmp = p;
144 _rs_peer_destroy (tmp);
157 int rs_context_set_alloc_scheme(struct rs_context *ctx,
158 struct rs_alloc_scheme *scheme)
160 return rs_err_ctx_push_fl (ctx, RSE_NOSYS, __FILE__, __LINE__, NULL);