From 53789fddda974222f729d608558ce9ae662c6d9f Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Mon, 25 Apr 2016 21:12:44 +0100 Subject: [PATCH] sslproc: simplify ssl open callback Don't use the librb callback type as we're always passing client_p. Provide a return value so that the connect handler can exit_client() and the accept handler can opt to use the default dead handler. --- include/client.h | 5 +++-- ircd/s_serv.c | 11 +++++++++-- ircd/sslproc.c | 19 ++++++++----------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/client.h b/include/client.h index a23f444bf..43d3dfe76 100644 --- a/include/client.h +++ b/include/client.h @@ -68,6 +68,8 @@ struct ListClient; struct scache_entry; struct ws_ctl; +typedef int SSL_OPEN_CB(struct Client *, int status); + /* * Client structures */ @@ -275,8 +277,7 @@ struct LocalUser struct _ssl_ctl *ssl_ctl; /* which ssl daemon we're associate with */ struct _ssl_ctl *z_ctl; /* second ctl for ssl+zlib */ struct ws_ctl *ws_ctl; /* ctl for wsockd */ - CNCB *ssl_callback; /* ssl connection is now open */ - void *ssl_data; /* data for callback */ + SSL_OPEN_CB *ssl_callback; /* ssl connection is now open */ uint32_t localflags; struct ZipStats *zipstats; /* zipstats */ uint16_t cork_count; /* used for corking/uncorking connections */ diff --git a/ircd/s_serv.c b/ircd/s_serv.c index e6c424f2f..6f43537fc 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -151,6 +151,7 @@ init_builtin_capabs(void) static CNCB serv_connect_callback; static CNCB serv_connect_ssl_callback; +static SSL_OPEN_CB serv_connect_ssl_open_callback; /* * hunt_server - Do the basic thing in delivering the message (command) @@ -1180,8 +1181,7 @@ serv_connect_ssl_callback(rb_fde_t *F, int status, void *data) } client_p->localClient->F = xF[0]; - client_p->localClient->ssl_callback = serv_connect_callback; - client_p->localClient->ssl_data = data; + client_p->localClient->ssl_callback = serv_connect_ssl_open_callback; client_p->localClient->ssl_ctl = start_ssld_connect(F, xF[1], connid_get(client_p)); if(!client_p->localClient->ssl_ctl) @@ -1192,6 +1192,13 @@ serv_connect_ssl_callback(rb_fde_t *F, int status, void *data) SetSSL(client_p); } +static int +serv_connect_ssl_open_callback(struct Client *client_p, int status) +{ + serv_connect_callback(client_p->localClient->F, status, client_p); + return 1; /* suppress default exit_client handler for status != RB_OK */ +} + /* * serv_connect_callback() - complete a server connection. * diff --git a/ircd/sslproc.c b/ircd/sslproc.c index 51e594a9d..8780e1ac4 100644 --- a/ircd/sslproc.c +++ b/ircd/sslproc.c @@ -393,13 +393,11 @@ ssl_process_open_fd(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) if(client_p->localClient->ssl_callback) { - CNCB *hdl = client_p->localClient->ssl_callback; - void *data = client_p->localClient->ssl_data; + SSL_OPEN_CB *hdl = client_p->localClient->ssl_callback; client_p->localClient->ssl_callback = NULL; - client_p->localClient->ssl_data = NULL; - hdl(client_p->localClient->F, RB_OK, data); + hdl(client_p, RB_OK); } } @@ -428,16 +426,15 @@ ssl_process_dead_fd(ssl_ctl_t * ctl, ssl_ctl_buf_t * ctl_buf) /* if there is still a pending callback, call it now */ if(client_p->localClient->ssl_callback) { - CNCB *hdl = client_p->localClient->ssl_callback; - void *data = client_p->localClient->ssl_data; + SSL_OPEN_CB *hdl = client_p->localClient->ssl_callback; client_p->localClient->ssl_callback = NULL; - client_p->localClient->ssl_data = NULL; - hdl(client_p->localClient->F, RB_ERROR_SSL, data); - - /* the callback should have exited the client */ - return; + if (hdl(client_p, RB_ERROR_SSL)) + { + /* the callback has exited the client */ + return; + } } if(IsAnyServer(client_p) || IsRegistered(client_p))