diff options
author | Linus Nordberg <linus@nordu.net> | 2010-10-11 19:06:06 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2010-10-11 19:06:06 +0200 |
commit | e06796fe52596f417d74b3c3758ff0a321f67274 (patch) | |
tree | e79094450d53fe48de78f3f6efe7e3a9a9f6add2 /lib/request.c | |
parent | 887a170a35bb083fbe4cc6b7315bb15676b99e9f (diff) | |
parent | 06936d1f263c456017e20ea6c74d2756e1e30fcc (diff) |
Merge branch 'merge-luke' into libradsec
8a676ab Robustness fixes (and some callback invocation) by Luke Howard.
ff55882 Request object implementation and bug fixes by Luke Howard.
06936d1 Have rad_decode() verify responses.
Diffstat (limited to 'lib/request.c')
-rw-r--r-- | lib/request.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/lib/request.c b/lib/request.c index 3d4b096..5cb87bb 100644 --- a/lib/request.c +++ b/lib/request.c @@ -1,6 +1,7 @@ /* See the file COPYING for licensing information. */ #include <time.h> +#include <assert.h> #include <event2/event.h> #include <radsec/radsec.h> #include <radsec/radsec-impl.h> @@ -8,7 +9,7 @@ #include <radsec/request-impl.h> int -rs_req_create (struct rs_connection *conn, struct rs_request **req_out) +rs_request_create (struct rs_connection *conn, struct rs_request **req_out) { struct rs_request *req = rs_malloc (conn->ctx, sizeof(*req)); if (!req) @@ -20,7 +21,7 @@ rs_req_create (struct rs_connection *conn, struct rs_request **req_out) } void -rs_req_destroy(struct rs_request *request) +rs_request_destroy (struct rs_request *request) { rs_packet_destroy (request->req); rs_packet_destroy (request->resp); @@ -35,12 +36,58 @@ _timer_cb(evutil_socket_t fd, short what, void *arg) } #endif +static void +_rs_req_connected(void *user_data) +{ + struct rs_request *request = (struct rs_request *)user_data; +} + +static void +_rs_req_disconnected(void *user_data) +{ + struct rs_request *request = (struct rs_request *)user_data; +} + +static void +_rs_req_packet_received(const struct rs_packet *pkt, void *user_data) +{ + struct rs_request *request = (struct rs_request *)user_data; +} + +static void +_rs_req_packet_sent(void *user_data) +{ + struct rs_request *request = (struct rs_request *)user_data; +} + int -rs_req_send(struct rs_request *request, struct rs_packet *req, - struct rs_packet **resp) +rs_request_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*/ + int err; + struct rs_connection *conn; + + assert (request); + assert (request->conn); + conn = request->conn; + + request->req = req; /* take ownership */ + request->saved_cb = conn->callbacks; + + conn->callbacks.connected_cb = _rs_req_connected; + conn->callbacks.disconnected_cb = _rs_req_disconnected; + conn->callbacks.received_cb = _rs_req_packet_received; + conn->callbacks.sent_cb = _rs_req_packet_sent; + + err = rs_packet_send(request->req, request); + if (err) + goto cleanup; + + err = rs_conn_receive_packet(request->conn, request->req, resp); + if (err) + goto cleanup; - return -1; +cleanup: + conn->callbacks = request->saved_cb; + return err; } |