From 93a5b586a355d5e1284be72ee5c3165e07218cb9 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 5 Aug 2017 10:38:59 +0800 Subject: [PATCH] lws_callback_all_protocol_vhost_args --- lib/libwebsockets.c | 19 ++++++++++++++----- lib/libwebsockets.h | 27 ++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index e774b930..b402375f 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1056,8 +1056,9 @@ lws_callback_all_protocol(struct lws_context *context, } LWS_VISIBLE int -lws_callback_all_protocol_vhost(struct lws_vhost *vh, - const struct lws_protocols *protocol, int reason) +lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, + const struct lws_protocols *protocol, int reason, + void *argp, size_t len) { struct lws_context *context = vh->context; struct lws_context_per_thread *pt = &context->pt[0]; @@ -1069,9 +1070,10 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, wsi = wsi_from_fd(context, pt->fds[n].fd); if (!wsi) continue; - if (wsi->vhost == vh && wsi->protocol == protocol) - protocol->callback(wsi, reason, wsi->user_space, - NULL, 0); + if (wsi->vhost == vh && (wsi->protocol == protocol || + !protocol)) + wsi->protocol->callback(wsi, reason, + wsi->user_space, argp, len); } pt++; } @@ -1079,6 +1081,13 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, return 0; } +LWS_VISIBLE int +lws_callback_all_protocol_vhost(struct lws_vhost *vh, + const struct lws_protocols *protocol, int reason) +{ + return lws_callback_all_protocol_vhost_args(vh, protocol, reason, NULL, 0); +} + LWS_VISIBLE LWS_EXTERN int lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) { diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index ef8efca4..47d4d5c2 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -3974,10 +3974,11 @@ lws_callback_all_protocol(struct lws_context *context, /** * lws_callback_all_protocol_vhost() - Callback all connections using - * the given protocol with the given reason + * the given protocol with the given reason. This is + * deprecated since v2.4: use lws_callback_all_protocol_vhost_args * * \param vh: Vhost whose connections will get callbacks - * \param protocol: Which protocol to match + * \param protocol: Which protocol to match. NULL means all. * \param reason: Callback reason index * * - Which: connections using this protocol on GIVEN VHOST ONLY @@ -3986,7 +3987,27 @@ lws_callback_all_protocol(struct lws_context *context, */ LWS_VISIBLE LWS_EXTERN int lws_callback_all_protocol_vhost(struct lws_vhost *vh, - const struct lws_protocols *protocol, int reason); + const struct lws_protocols *protocol, int reason) +LWS_WARN_DEPRECATED; + +/** + * lws_callback_all_protocol_vhost_args() - Callback all connections using + * the given protocol with the given reason and args + * + * \param vh: Vhost whose connections will get callbacks + * \param protocol: Which protocol to match. NULL means all. + * \param reason: Callback reason index + * \param argp: Callback "in" parameter + * \param len: Callback "len" parameter + * + * - Which: connections using this protocol on GIVEN VHOST ONLY + * - When: now + * - What: reason + */ +LWS_VISIBLE int +lws_callback_all_protocol_vhost_args(struct lws_vhost *vh, + const struct lws_protocols *protocol, int reason, + void *argp, size_t len); /** * lws_callback_vhost_protocols() - Callback all protocols enabled on a vhost