diff options
author | Linus Nordberg <linus@nordu.net> | 2011-02-19 18:55:51 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2011-02-19 18:55:51 +0100 |
commit | e0749025f259754aa031d997457a308686136909 (patch) | |
tree | a0c9c98e09c6089c780f06053e9abbaec4a24438 /lib/conn.c | |
parent | 020e7688d91f2db00d1b573c8496119ede15e773 (diff) |
Improve protocol robustness and invoke user callbacks.
All aborts are removed, as well as all asserts which aren't
programming errors.
When an invalid packet is received, the connection is closed, as per
draft-ietf-radext-tcp-transport-08 (2.6.4).
Use new rs_debug() macro rather than fprintf() for debug printouts.
Coding style overhaul.
Diffstat (limited to 'lib/conn.c')
-rw-r--r-- | lib/conn.c | 51 |
1 files changed, 46 insertions, 5 deletions
@@ -4,7 +4,9 @@ #include <config.h> #endif +#include <string.h> #include <assert.h> +#include <debug.h> #include <event2/event.h> #include <radsec/radsec.h> #include <radsec/radsec-impl.h> @@ -90,12 +92,33 @@ rs_conn_add_listener (struct rs_connection *conn, rs_conn_type_t type, "%s: NYI", __func__); } -void + +int +rs_conn_disconnect (struct rs_connection *conn) +{ + int err = 0; + + assert (conn); + + err = evutil_closesocket (conn->active_peer->fd); + conn->active_peer->fd = -1; + return err; +} + +int rs_conn_destroy (struct rs_connection *conn) { struct rs_peer *p; + int err = 0; -#warning "TODO: Disconnect active_peer." + assert (conn); + + if (conn->active_peer->is_connected) + { + err = rs_conn_disconnect (conn); + if (err) + return err; + } for (p = conn->peers; p; p = p->next) { @@ -107,6 +130,8 @@ rs_conn_destroy (struct rs_connection *conn) if (conn->evb) event_base_free (conn->evb); + + return 0; } int @@ -116,11 +141,27 @@ rs_conn_set_eventbase (struct rs_connection *conn, struct event_base *eb) "%s: NYI", __func__); } -int +void rs_conn_set_callbacks (struct rs_connection *conn, struct rs_conn_callbacks *cb) { - return rs_err_conn_push_fl (conn, RSE_NOSYS, __FILE__, __LINE__, - "%s: NYI", __func__); + assert (conn); + conn->user_dispatch_flag = 1; + memcpy (&conn->callbacks, cb, sizeof (conn->callbacks)); +} + +void +rs_conn_del_callbacks (struct rs_connection *conn) +{ + assert (conn); + conn->user_dispatch_flag = 0; + memset (&conn->callbacks, 0, sizeof (conn->callbacks)); +} + +struct rs_conn_callbacks * +rs_conn_get_callbacks(struct rs_connection *conn) +{ + assert (conn); + return &conn->callbacks; } int |