diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index a2d8328a..9c990866 100755 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1374,6 +1374,16 @@ lws_wsi_user(struct lws *wsi) return wsi->user_space; } +LWS_VISIBLE LWS_EXTERN void +lws_set_wsi_user(struct lws *wsi, void *data) +{ + if (wsi->user_space_externally_allocated) + wsi->user_space = data; + else + lwsl_err("%s: Cannot set internally-allocated user_space\n", + __func__); +} + LWS_VISIBLE LWS_EXTERN struct lws * lws_get_parent(const struct lws *wsi) { diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 90f5faa9..b1e5d9f5 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -3902,6 +3902,19 @@ lws_get_library_version(void); LWS_VISIBLE LWS_EXTERN void * lws_wsi_user(struct lws *wsi); +/** + * lws_wsi_set_user() - set the user data associated with the client connection + * \param wsi: lws connection + * \param user: user data + * + * By default lws allocates this and it's not legal to externally set it + * yourself. However client connections may have it set externally when the + * connection is created... if so, this api can be used to modify it at + * runtime additionally. + */ +LWS_VISIBLE LWS_EXTERN void +lws_set_wsi_user(struct lws *wsi, void *user); + /** * lws_parse_uri: cut up prot:/ads:port/path into pieces * Notice it does so by dropping '\0' into input string