# HG changeset patch # User Tero Marttila # Date 1236649100 -7200 # Node ID ae66e9ae4afbc29f1066a4d8b2b300a68b196d65 # Parent 98ea2bd591954f8703a5ae138ec0dacb9c1078ca convert line_proto to use a line_proto_callbacks struct diff -r 98ea2bd59195 -r ae66e9ae4afb src/irc_conn.c --- a/src/irc_conn.c Tue Mar 10 03:29:53 2009 +0200 +++ b/src/irc_conn.c Tue Mar 10 03:38:20 2009 +0200 @@ -80,6 +80,10 @@ } } +static struct line_proto_callbacks _lp_callbacks = { + .on_line = &irc_conn_on_line, +}; + err_t irc_conn_create (struct irc_conn **conn_ptr, struct sock_stream *sock, const struct irc_conn_callbacks *callbacks, void *cb_arg, struct error_info *err) { @@ -101,7 +105,7 @@ goto error; // create the line_proto, with our on_line handler - if (line_proto_create(&conn->lp, sock, IRC_LINE_MAX * 1.5, &irc_conn_on_line, conn, err)) + if (line_proto_create(&conn->lp, sock, IRC_LINE_MAX * 1.5, &_lp_callbacks, conn, err)) goto error; // ok diff -r 98ea2bd59195 -r ae66e9ae4afb src/line_proto.c --- a/src/line_proto.c Tue Mar 10 03:29:53 2009 +0200 +++ b/src/line_proto.c Tue Mar 10 03:38:20 2009 +0200 @@ -32,7 +32,7 @@ struct error_info err; /* Callback info */ - line_proto_read_cb cb_read; + struct line_proto_callbacks callbacks; void *cb_arg; }; @@ -60,7 +60,7 @@ // got a line? if (line) - lp->cb_read(line, lp->cb_arg); + lp->callbacks.on_line(line, lp->cb_arg); } while (line); @@ -102,7 +102,7 @@ }; err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size, - line_proto_read_cb cb_func, void *cb_arg, struct error_info *err) + const struct line_proto_callbacks *callbacks, void *cb_arg, struct error_info *err) { struct line_proto *lp; @@ -117,7 +117,7 @@ // store lp->sock = sock; lp->buf_len = buf_size; - lp->cb_read = cb_func; + lp->callbacks = *callbacks; lp->cb_arg = cb_arg; // initialize event-based stuff diff -r 98ea2bd59195 -r ae66e9ae4afb src/line_proto.h --- a/src/line_proto.h Tue Mar 10 03:29:53 2009 +0200 +++ b/src/line_proto.h Tue Mar 10 03:38:20 2009 +0200 @@ -1,38 +1,42 @@ #ifndef LINE_PROTO_H #define LINE_PROTO_H -/* +/** + * @file + * * Support for protocols that send/receive lines */ #include "sock.h" #include "error.h" -/* - * The state handle +/** + * The line_proto state handle */ struct line_proto; -/* - * The callback for receiving lines +/** + * User callback list */ -typedef void (*line_proto_read_cb)(char *line, void *arg); +struct line_proto_callbacks { + /** Handle received line */ + void (*on_line) (char *line, void *arg); + +}; /** * Create a new line_proto off the the given sock_stream. The newly allocated line_proto will be returned via *lp_ptr. * * The incoming lines are buffered in a buffer of \a buf_size bytes. This imposes a maximum limit on the line length. * - * The given callback function/argument will be used to provide event-based recv support. - * * @param lp_ptr a pointer to the new line_proto will be returned via this pointer * @param sock the sock_stream to use * @param buf_size the incoming/outgoing buffer size, should be enough to hold the biggest possible line - * @param cb_func the read_cb callback + * @param callbacks the callback struct to use * @param cb_arg the read_cb callback argument * @param err error information is returned via this pointer */ err_t line_proto_create (struct line_proto **lp_ptr, struct sock_stream *sock, size_t buf_size, - line_proto_read_cb cb_func, void *cb_arg, struct error_info *err); + const struct line_proto_callbacks *callbacks, void *cb_arg, struct error_info *err); /** * Runs the socket recv() into our internal buffer. If a full line was received, a pointer to our internal bufffer is