summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-10-03 16:24:57 +0200
committerLinus Nordberg <linus@nordu.net>2010-10-03 16:24:57 +0200
commit21300197afcabc90366454eaa34e67187c53d974 (patch)
treeaa2b92a3e041335130994a0d3f6652f14983f634 /lib
parent81aa93c41def5b73bc5523de852c429355926e93 (diff)
WIP -- prepare for request objects.
Diffstat (limited to 'lib')
-rw-r--r--lib/HACKING7
-rw-r--r--lib/examples/Makefile4
-rw-r--r--lib/examples/client-blocking.c19
-rw-r--r--lib/include/radsec/request-impl.h10
-rw-r--r--lib/include/radsec/request.h7
-rw-r--r--lib/packet.c7
-rw-r--r--lib/request.c46
7 files changed, 93 insertions, 7 deletions
diff --git a/lib/HACKING b/lib/HACKING
index 9cbab82..884ce2c 100644
--- a/lib/HACKING
+++ b/lib/HACKING
@@ -3,12 +3,15 @@ HACKING file for libradsec (in Emacs -*- org -*- mode).
* Functionality
** Not implemented
- reading config file
-- server fail over
- resending packets
+- custom allocation scheme used in all places
+- callbacks invoked properly
+- server fail over
- matching responses
-- TLS, DTLS
+- TLS
- TLS PSK
- autoconf/automake/libtool
+- DTLS
** Not tested
- short read
- short write
diff --git a/lib/examples/Makefile b/lib/examples/Makefile
index 692e9d6..4a0ab8f 100644
--- a/lib/examples/Makefile
+++ b/lib/examples/Makefile
@@ -1,4 +1,6 @@
-CFLAGS = -Wall -g -I ../include
+SPECIAL = # -DUSE_REQUEST_OBJECT
+
+CFLAGS = -Wall -g -I ../include $(SPECIAL)
HFILES = ../include/radsec/radsec.h ../include/radsec/radsec-impl.h
diff --git a/lib/examples/client-blocking.c b/lib/examples/client-blocking.c
index 54fc05b..1e6ec25 100644
--- a/lib/examples/client-blocking.c
+++ b/lib/examples/client-blocking.c
@@ -7,6 +7,9 @@
#include <event2/event.h>
#include <freeradius/libradius.h>
#include <radsec/radsec.h>
+#if defined(USE_REQUEST_OBJECT)
+#include <radsec/request.h>
+#endif
#define SECRET "sikrit"
#define USER_NAME "bob"
@@ -29,19 +32,31 @@ rsx_client (const char *srvname, int srvport)
return rs_conn_err_pop (conn);
if (rs_conn_add_server (conn, &server, RS_CONN_TYPE_UDP, srvname, srvport))
return rs_conn_err_pop (conn);
- rs_server_set_timeout (server, 10);
+ rs_server_set_timeout (server, 1);
rs_server_set_tries (server, 3);
rs_server_set_secret (server, SECRET);
if (rs_packet_create_acc_request (conn, &req, USER_NAME, USER_PW))
return rs_conn_err_pop (conn);
+#if !defined(USE_REQUEST_OBJECT)
if (rs_packet_send (req, NULL))
return rs_conn_err_pop (conn);
req = NULL;
-
if (rs_conn_receive_packet (conn, &resp))
return rs_conn_err_pop (conn);
+#else
+ {
+ struct rs_request *request;
+
+ if (rs_request_new (conn, &request))
+ return rs_conn_err_pop (conn);
+ if (rs_req_send (request, req, &resp))
+ return rs_conn_err_pop (conn);
+ rs_request_destroy (request);
+ }
+#endif /* !defined(USE_REQUEST_OBJECT) */
+
fr_pkt = rs_packet_frpkt (resp);
fr_vp = fr_pkt->vps; /* FIXME: Is there an accessor? */
vp_printlist(stdout, fr_vp);
diff --git a/lib/include/radsec/request-impl.h b/lib/include/radsec/request-impl.h
new file mode 100644
index 0000000..339dfea
--- /dev/null
+++ b/lib/include/radsec/request-impl.h
@@ -0,0 +1,10 @@
+/* See the file COPYING for licensing information. */
+
+struct rs_request
+{
+ struct rs_connection *conn;
+ struct event *timer;
+ struct rs_packet *req;
+ struct rs_packet *resp;
+ struct rs_conn_callbacks saved_cb;
+};
diff --git a/lib/include/radsec/request.h b/lib/include/radsec/request.h
new file mode 100644
index 0000000..3827da5
--- /dev/null
+++ b/lib/include/radsec/request.h
@@ -0,0 +1,7 @@
+/* See the file COPYING for licensing information. */
+
+struct rs_request;
+
+int rs_req_create(struct rs_connection *conn, struct rs_request **req_out);
+void rs_req_destroy(struct rs_request *request);
+int rs_req_send(struct rs_request *request, struct rs_packet *req, struct rs_packet **resp);
diff --git a/lib/packet.c b/lib/packet.c
index 79c140d..f39e4d6 100644
--- a/lib/packet.c
+++ b/lib/packet.c
@@ -418,6 +418,9 @@ rs_packet_frpkt(struct rs_packet *pkt)
void
rs_packet_destroy(struct rs_packet *pkt)
{
- rad_free (&pkt->rpkt);
- rs_free (pkt->conn->ctx, pkt);
+ if (pkt)
+ {
+ rad_free (&pkt->rpkt);
+ rs_free (pkt->conn->ctx, pkt);
+ }
}
diff --git a/lib/request.c b/lib/request.c
new file mode 100644
index 0000000..da38015
--- /dev/null
+++ b/lib/request.c
@@ -0,0 +1,46 @@
+/* See the file COPYING for licensing information. */
+
+#include <time.h>
+#include <event2/event.h>
+#include <radsec/radsec.h>
+#include <radsec/radsec-impl.h>
+#include <radsec/request.h>
+#include <radsec/request-impl.h>
+
+int
+rs_req_create (struct rs_connection *conn, struct rs_request **req_out)
+{
+ struct rs_request *req = rs_malloc (conn->ctx, sizeof(*req));
+ if (!req)
+ return rs_conn_err_push_fl (conn, RSE_NOMEM, __FILE__, __LINE__, NULL);
+ memset (req, 0, sizeof(*req));
+ req->conn = conn;
+ *req_out = req;
+ return RSE_OK;
+}
+
+void
+rs_req_destroy(struct rs_request *request)
+{
+ rs_packet_destroy (request->req);
+ rs_packet_destroy (request->resp);
+ rs_free (request->conn->ctx, request);
+}
+
+#if 0
+static void
+_timer_cb(evutil_socket_t fd, short what, void *arg)
+
+{
+}
+#endif
+
+int
+rs_req_send(struct rs_request *request, struct rs_packet *req,
+ struct rs_packet **resp)
+{
+ /* install our own callback, backing up any user provided one in
+ req->saved_cb*/
+
+ return -1;
+}