diff --git a/lib/context.c b/lib/context.c index 604f7cb2..705f8ea0 100644 --- a/lib/context.c +++ b/lib/context.c @@ -482,6 +482,7 @@ lws_create_vhost(struct lws_context *context, vh->options = info->options; vh->pvo = info->pvo; vh->headers = info->headers; + vh->user = info->user; vh->ssl_info_event_mask = info->ssl_info_event_mask; if (info->keepalive_timeout) vh->keepalive_timeout = info->keepalive_timeout; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 780d220f..ff2d4009 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1011,6 +1011,12 @@ bail: } +LWS_EXTERN void * +lws_vhost_user(struct lws_vhost *vhost) +{ + return vhost->user; +} + LWS_EXTERN void * lws_context_user(struct lws_context *context) { diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index ba05028d..9a08a05f 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -1935,8 +1935,14 @@ struct lws_context_creation_info { unsigned int options; /**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */ void *user; - /**< CONTEXT: optional user pointer that can be recovered via the context - * pointer using lws_context_user */ + /**< VHOST + CONTEXT: optional user pointer that will be associated + * with the context when creating the context (and can be retrieved by + * lws_context_user(context), or with the vhost when creating the vhost + * (and can be retrieved by lws_vhost_user(vhost)). You will need to + * use LWS_SERVER_OPTION_EXPLICIT_VHOSTS and create the vhost separately + * if you care about giving the context and vhost different user pointer + * values. + */ int ka_time; /**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive * timeout to all libwebsocket sockets, client or server */ @@ -2349,6 +2355,17 @@ LWS_VISIBLE LWS_EXTERN int lws_json_dump_context(const struct lws_context *context, char *buf, int len, int hide_vhosts); +/** + * lws_vhost_user() - get the user data associated with the vhost + * \param vhost: Websocket vhost + * + * This returns the optional user pointer that can be attached to + * a vhost when it was created. Lws never dereferences this pointer, it only + * sets it when the vhost is created, and returns it using this api. + */ +LWS_VISIBLE LWS_EXTERN void * +lws_vhost_user(struct lws_vhost *vhost); + /** * lws_context_user() - get the user data associated with the context * \param context: Websocket context diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index a6a2a562..4830a2ec 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -881,6 +881,7 @@ struct lws_vhost { #ifndef LWS_NO_EXTENSIONS const struct lws_extension *extensions; #endif + void *user; int listen_port; unsigned int http_proxy_port;