diff --git a/include/libwebsockets/lws-context-vhost.h b/include/libwebsockets/lws-context-vhost.h index 96fb883da..b9205ae40 100644 --- a/include/libwebsockets/lws-context-vhost.h +++ b/include/libwebsockets/lws-context-vhost.h @@ -894,6 +894,16 @@ lws_get_vhost(struct lws *wsi); LWS_VISIBLE LWS_EXTERN const char * lws_get_vhost_name(struct lws_vhost *vhost); +/** + * lws_get_vhost_by_name() - returns the vhost with the requested name, or NULL + * + * \param name: vhost name we are looking for + * + * Returns NULL, or the vhost with the name \p name + */ +LWS_VISIBLE LWS_EXTERN struct lws_vhost * +lws_get_vhost_by_name(struct lws_context *context, const char *name); + /** * lws_get_vhost_port() - returns the port a vhost listens on, or -1 * diff --git a/lib/core-net/vhost.c b/lib/core-net/vhost.c index 013acd52b..6d478acf0 100644 --- a/lib/core-net/vhost.c +++ b/lib/core-net/vhost.c @@ -1301,3 +1301,18 @@ lws_context_deprecate(struct lws_context *context, lws_reload_func cb) context->deprecated = 1; context->deprecation_cb = cb; } + +#if defined(LWS_WITH_NETWORK) +struct lws_vhost * +lws_get_vhost_by_name(struct lws_context *context, const char *name) +{ + lws_start_foreach_ll(struct lws_vhost *, v, + context->vhost_list) { + if (!strcmp(v->name, name)) + return v; + + } lws_end_foreach_ll(v, vhost_next); + + return NULL; +} +#endif