diff --git a/include/libwebsockets/lws-client.h b/include/libwebsockets/lws-client.h index a1661b0a9..86a50c157 100644 --- a/include/libwebsockets/lws-client.h +++ b/include/libwebsockets/lws-client.h @@ -119,6 +119,11 @@ struct lws_client_connect_info { * tokens */ + void *opaque_user_data; + /**< This data has no meaning to lws but is applied to the client wsi + * and can be retrieved by user code with lws_get_opaque_user_data() + */ + /* Add new things just above here ---^ * This is part of the ABI, don't needlessly break compatibility * diff --git a/include/libwebsockets/lws-misc.h b/include/libwebsockets/lws-misc.h index 02fe432d5..d84415c28 100644 --- a/include/libwebsockets/lws-misc.h +++ b/include/libwebsockets/lws-misc.h @@ -545,6 +545,12 @@ lws_get_opaque_parent_data(const struct lws *wsi); LWS_VISIBLE LWS_EXTERN void lws_set_opaque_parent_data(struct lws *wsi, void *data); +LWS_VISIBLE LWS_EXTERN void * +lws_get_opaque_user_data(const struct lws *wsi); + +LWS_VISIBLE LWS_EXTERN void +lws_set_opaque_user_data(struct lws *wsi, void *data); + LWS_VISIBLE LWS_EXTERN int lws_get_child_pending_on_writable(const struct lws *wsi); diff --git a/lib/core/connect.c b/lib/core/connect.c index daffc193c..50111f8ad 100644 --- a/lib/core/connect.c +++ b/lib/core/connect.c @@ -189,6 +189,7 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i) wsi->stash->address = lws_strdup(i->address); wsi->stash->path = lws_strdup(i->path); wsi->stash->host = lws_strdup(i->host); + wsi->stash->opaque_user_data = i->opaque_user_data; if (!wsi->stash->address || !wsi->stash->path || !wsi->stash->host) goto bail1; diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c index 47b01dcec..661493c51 100644 --- a/lib/core/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -2367,6 +2367,18 @@ lws_set_opaque_parent_data(struct lws *wsi, void *data) wsi->opaque_parent_data = data; } +LWS_VISIBLE LWS_EXTERN void * +lws_get_opaque_user_data(const struct lws *wsi) +{ + return wsi->opaque_user_data; +} + +LWS_VISIBLE LWS_EXTERN void +lws_set_opaque_user_data(struct lws *wsi, void *data) +{ + wsi->opaque_user_data = data; +} + LWS_VISIBLE LWS_EXTERN int lws_get_child_pending_on_writable(const struct lws *wsi) { diff --git a/lib/core/private.h b/lib/core/private.h index d89716339..295f27d51 100644 --- a/lib/core/private.h +++ b/lib/core/private.h @@ -831,6 +831,7 @@ struct client_info_stash { char *method; char *iface; char *alpn; + void *opaque_user_data; /* not allocated or freed by lws */ }; #endif @@ -915,6 +916,7 @@ struct lws { #endif void *user_space; void *opaque_parent_data; + void *opaque_user_data; struct lws_buflist *buflist; /* input-side buflist */ struct lws_buflist *buflist_out; /* output-side buflist */ diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index 48b2b41f7..7650e8fe3 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -1267,6 +1267,8 @@ lws_h2_parse_end_of_frame(struct lws *wsi) h2n->swsi->user_space = wsi->user_space; h2n->swsi->user_space_externally_allocated = wsi->user_space_externally_allocated; + h2n->swsi->opaque_user_data = wsi->opaque_user_data; + wsi->opaque_user_data = NULL; wsi->user_space = NULL; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 6b4e98f34..88cbb7862 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -928,6 +928,8 @@ lws_http_client_connect_via_info2(struct lws *wsi) if (!stash) return wsi; + wsi->opaque_user_data = wsi->stash->opaque_user_data; + /* * we're not necessarily in a position to action these right away, * stash them... we only need during connect phase so into a temp