From 16ee4b6f0d3a89c38844e736c0d5f57e5dfd523f Mon Sep 17 00:00:00 2001 From: Lukas Geyer Date: Tue, 28 Feb 2017 21:17:25 +0800 Subject: [PATCH] client: allow change externally-defined wsi user_data https://github.com/warmcat/libwebsockets/issues/819 AG: add explanation in doxygen comment and check user_space was externally set --- lib/libwebsockets.c | 10 ++++++++++ lib/libwebsockets.h | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index a2d8328ae..9c990866e 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 90f5faa9e..b1e5d9f5d 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