diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index e229ab3a..05b2664b 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -907,6 +907,31 @@ lws_callback_all_protocol_vhost(struct lws_vhost *vh, return 0; } +/** + * lws_callback_vhost_protocols() - Callback all protocols enabled on a vhost + * with the given reason + * + * @wsi: wsi whose vhost will get callbacks + * @reason: Callback reason index + * @in: in argument to callback + * @len: len argument to callback + * + * This is useful when informing all fellow enabled protocols on a vhost about + * a vhost-wide event, eg, creation or deletion of an account + */ + +LWS_VISIBLE LWS_EXTERN int +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len) +{ + int n; + + for (n = 0; n < wsi->vhost->count_protocols; n++) + if (wsi->vhost->protocols[n].callback(wsi, reason, NULL, in, len)) + return 1; + + return 0; +} + #if LWS_POSIX /** diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index aff74932..3b17d453 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -2071,6 +2071,9 @@ LWS_VISIBLE LWS_EXTERN int lws_callback_all_protocol_vhost(struct lws_vhost *vh, const struct lws_protocols *protocol, int reason); +LWS_VISIBLE LWS_EXTERN int +lws_callback_vhost_protocols(struct lws *wsi, int reason, void *in, int len); + LWS_VISIBLE LWS_EXTERN int lws_get_socket_fd(struct lws *wsi);