summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-06 17:04:54 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-06 17:04:54 +0100
commit43d0740f143ba737a1fc5ace3a323ffa8b09e7ae (patch)
tree0cd0eb16da49df6def7d37866eb554fd7cc3275c
parente5207cd80b8a522be84e3f66479663e559309ee7 (diff)
request: Save callers user_data and do invoke callers callbacks.
-rw-r--r--lib/include/radsec/request-impl.h1
-rw-r--r--lib/request.c39
2 files changed, 31 insertions, 9 deletions
diff --git a/lib/include/radsec/request-impl.h b/lib/include/radsec/request-impl.h
index 4f50d44..19aef66 100644
--- a/lib/include/radsec/request-impl.h
+++ b/lib/include/radsec/request-impl.h
@@ -11,6 +11,7 @@ struct rs_request
struct rs_packet *req_msg;
struct rs_packet *resp_msg;
struct rs_conn_callbacks saved_cb;
+ void *saved_user_data;
};
#if defined (__cplusplus)
diff --git a/lib/request.c b/lib/request.c
index 0d98544..9c4b58f 100644
--- a/lib/request.c
+++ b/lib/request.c
@@ -62,34 +62,50 @@ rs_request_destroy (struct rs_request *request)
#if 0
static void
-_timer_cb(evutil_socket_t fd, short what, void *arg)
+_timer_cb (evutil_socket_t fd, short what, void *arg)
{
}
#endif
static void
-_rs_req_connected(void *user_data)
+_rs_req_connected (void *user_data)
{
- //struct rs_request *request = (struct rs_request *)user_data;
+ struct rs_request *request = (struct rs_request *) user_data;
+ assert (request);
+ assert (request->conn);
+ if (request->saved_cb.connected_cb)
+ request->saved_cb.connected_cb (request->saved_user_data);
}
static void
-_rs_req_disconnected(void *user_data)
+_rs_req_disconnected (void *user_data)
{
- //struct rs_request *request = (struct rs_request *)user_data;
+ struct rs_request *request = (struct rs_request *) user_data;
+ assert (request);
+ assert (request->conn);
+ if (request->saved_cb.disconnected_cb)
+ request->saved_cb.disconnected_cb (request->saved_user_data);
}
static void
-_rs_req_packet_received(struct rs_packet *msg, void *user_data)
+_rs_req_packet_received (struct rs_packet *msg, void *user_data)
{
- //struct rs_request *request = (struct rs_request *)user_data;
+ struct rs_request *request = (struct rs_request *) user_data;
+ assert (request);
+ assert (request->conn);
+ if (request->saved_cb.received_cb)
+ request->saved_cb.received_cb (msg, request->saved_user_data);
}
static void
-_rs_req_packet_sent(void *user_data)
+_rs_req_packet_sent (void *user_data)
{
- //struct rs_request *request = (struct rs_request *)user_data;
+ struct rs_request *request = (struct rs_request *) user_data;
+ assert (request);
+ assert (request->conn);
+ if (request->saved_cb.sent_cb)
+ request->saved_cb.sent_cb (request->saved_user_data);
}
int
@@ -101,6 +117,10 @@ rs_request_send (struct rs_request *request, struct rs_packet **resp_msg)
if (!request || !request->conn || !request->req_msg || !resp_msg)
return rs_err_conn_push_fl (conn, RSE_INVAL, __FILE__, __LINE__, NULL);
conn = request->conn;
+
+ request->saved_user_data = conn->user_data;
+ conn->user_data = request;
+
request->saved_cb = conn->callbacks;
conn->callbacks.connected_cb = _rs_req_connected;
conn->callbacks.disconnected_cb = _rs_req_disconnected;
@@ -116,6 +136,7 @@ rs_request_send (struct rs_request *request, struct rs_packet **resp_msg)
goto cleanup;
cleanup:
+ conn->user_data = request->saved_user_data;
conn->callbacks = request->saved_cb;
return err;
}