summaryrefslogtreecommitdiff
path: root/lib/peer.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-02-28 11:46:14 +0100
committerLinus Nordberg <linus@nordu.net>2011-02-28 11:46:14 +0100
commit9e601f905d91f55c7a36f15fe5998d694c38444f (patch)
treed01ef4bbdafa4185517a4ca86cce2ac30213a7f4 /lib/peer.c
parent2befa02ee876e83a8f8849388e61250e74d75eaf (diff)
API changes: rs_client* --> rs_peer.
Move peer (former server) things to new file peer.c. Update examples.
Diffstat (limited to 'lib/peer.c')
-rw-r--r--lib/peer.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/peer.c b/lib/peer.c
new file mode 100644
index 0000000..4fbb54f
--- /dev/null
+++ b/lib/peer.c
@@ -0,0 +1,70 @@
+/* See the file COPYING for licensing information. */
+#if defined HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <radsec/radsec.h>
+#include <radsec/radsec-impl.h>
+
+int
+rs_peer_create (struct rs_connection *conn, struct rs_peer **peer_out)
+{
+ struct rs_peer *peer;
+
+ peer = _rs_peer_create (conn->ctx, &conn->peers);
+ if (peer)
+ {
+ peer->conn = conn;
+ peer->realm->timeout = 2;
+ peer->realm->retries = 2;
+ }
+ else
+ return rs_err_conn_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
+ if (*peer_out)
+ *peer_out = peer;
+ return RSE_OK;
+}
+
+int
+rs_peer_set_address (struct rs_peer *peer, const char *hostname,
+ const char *service)
+{
+ struct rs_error *err;
+
+ assert (peer);
+ assert (peer->realm);
+
+ err = _rs_resolv (&peer->addr, peer->realm->type, hostname, service);
+ if (err)
+ return _rs_err_conn_push_err (peer->conn, err);
+ return RSE_OK;
+}
+
+void
+rs_peer_set_timeout (struct rs_peer *peer, int timeout)
+{
+ assert (peer);
+ assert (peer->realm);
+ peer->realm->timeout = timeout;
+}
+void
+rs_peer_set_retries (struct rs_peer *peer, int retries)
+{
+ assert (peer);
+ assert (peer->realm);
+ peer->realm->retries = retries;
+}
+
+int
+rs_peer_set_secret (struct rs_peer *peer, const char *secret)
+{
+ if (peer->secret)
+ free (peer->secret);
+ peer->secret = (char *) malloc (strlen(secret) + 1);
+ if (!peer->secret)
+ return rs_err_conn_push (peer->conn, RSE_NOMEM, NULL);
+ strcpy (peer->secret, secret);
+ return RSE_OK;
+}
+