The user protocols struct has not been const until now.
This has been painful for a while because the semantics of the protocols
struct look like it's going to be treated as const.
At context creation, the protocols struct has been getting marked with the context,
and three apis exploited that to only need to be passed a pointer to a protocol to
get access to the context.
This patch removes the two writeable members in the context (these were never directly
used by user code), changes all pointers to protocols to be const, and adds an explicit
first argument to the three affected apis so they can have access to context.
The three affected apis are these
LWS_VISIBLE LWS_EXTERN int
-lws_callback_on_writable_all_protocol(const struct lws_protocols *protocol);
+lws_callback_on_writable_all_protocol(const struct lws_context *context,
+ const struct lws_protocols *protocol);
LWS_VISIBLE LWS_EXTERN int
-lws_callback_all_protocol(const struct lws_protocols *protocol, int reason);
+lws_callback_all_protocol(struct lws_context *context,
+ const struct lws_protocols *protocol, int reason);
LWS_VISIBLE LWS_EXTERN void
-lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol);
+lws_rx_flow_allow_all_protocol(const struct lws_context *context,
+ const struct lws_protocols *protocol);
unfortunately the original apis can no longer be emulated and users of them must update.
Signed-off-by: Andy Green <andy.green@linaro.org>
const char *pc;
char *p;
#ifndef LWS_NO_EXTENSIONS
- struct lws_extension *ext;
+ const struct lws_extension *ext;
char ext_name[128];
const char *c;
int more = 1;
char buf[128], hash[20], key_b64[40], *p = pkt;
int n;
#ifndef LWS_NO_EXTENSIONS
- struct lws_extension *ext;
+ const struct lws_extension *ext;
int ext_count = 0;
#endif
LWS_VISIBLE void
lws_context_destroy(struct lws_context *context)
{
- struct lws_protocols *protocol = NULL;
+ const struct lws_protocols *protocol = NULL;
int n;
lwsl_notice("%s\n", __func__);
int lws_extension_callback_deflate_frame(
struct lws_context *context,
- struct lws_extension *ext,
+ const struct lws_extension *ext,
struct lws *wsi,
enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len)
extern int lws_extension_callback_deflate_frame(
struct lws_context *context,
- struct lws_extension *ext,
+ const struct lws_extension *ext,
struct lws *wsi,
enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len);
int lws_extension_callback_deflate_stream(
struct lws_context *context,
- struct lws_extension *ext,
+ const struct lws_extension *ext,
struct lws *wsi,
enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len)
extern int lws_extension_callback_deflate_stream(
struct lws_context *context,
- struct lws_extension *ext,
+ const struct lws_extension *ext,
struct lws *wsi,
enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len);
int reason, void *arg, int len)
{
int n = 0, m, handled = 0;
- struct lws_extension *ext = context->extensions;
+ const struct lws_extension *ext = context->extensions;
while (ext && ext->callback && !handled) {
m = ext->callback(context, ext, wsi, reason,
*/
LWS_VISIBLE int
-lws_callback_all_protocol(const struct lws_protocols *protocol, int reason)
+lws_callback_all_protocol(struct lws_context *context,
+ const struct lws_protocols *protocol, int reason)
{
- struct lws_context *context = protocol->owning_server;
struct lws *wsi;
int n;
*/
LWS_VISIBLE void
-lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol)
+lws_rx_flow_allow_all_protocol(const struct lws_context *context,
+ const struct lws_protocols *protocol)
{
- struct lws_context *context = protocol->owning_server;
int n;
struct lws *wsi;
}
LWS_VISIBLE LWS_EXTERN struct lws_context *
-lws_get_ctx(struct lws *wsi)
+lws_get_ctx(const struct lws *wsi)
{
return wsi->context;
}
return lws_get_protocol(wsi);
}
-#undef libwebsocket_callback_on_writable_all_protocol
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_callback_on_writable_all_protocol(
- const struct lws_protocols *protocol)
-{
- return lws_callback_on_writable_all_protocol(protocol);
-}
#undef libwebsocket_callback_on_writable
LWS_VISIBLE LWS_EXTERN int
return lws_callback_on_writable(context, wsi);
}
-#undef libwebsocket_callback_all_protocol
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_callback_all_protocol(
- const struct lws_protocols *protocol, int reason)
-{
- return lws_callback_all_protocol(protocol, reason);
-}
-
#undef libwebsocket_get_socket_fd
LWS_VISIBLE LWS_EXTERN int
libwebsocket_get_socket_fd(struct lws *wsi)
return lws_rx_flow_control(wsi, enable);
}
-#undef libwebsocket_rx_flow_allow_all_protocol
-LWS_VISIBLE LWS_EXTERN void
-libwebsocket_rx_flow_allow_all_protocol(const struct lws_protocols *protocol)
-{
- lws_rx_flow_allow_all_protocol(protocol);
-}
-
#undef libwebsockets_remaining_packet_payload
LWS_VISIBLE LWS_EXTERN size_t
libwebsockets_remaining_packet_payload(struct lws *wsi)
* duration of wsi dereference from the other thread context.
*/
LWS_VISIBLE LWS_EXTERN int
-callback(struct lws_context *context, struct lws *wsi,
+callback(const struct lws_context *context, const struct lws *wsi,
enum lws_callback_reasons reason, void *user, void *in, size_t len);
-typedef int (callback_function)(struct lws_context *context, struct lws *wsi,
+typedef int (callback_function)(struct lws_context *context,
+ struct lws *wsi,
enum lws_callback_reasons reason, void *user,
void *in, size_t len);
* set the lws_tokens token pointer to it.
*/
LWS_VISIBLE LWS_EXTERN int
-extension_callback(struct lws_context *context, struct lws_extension *ext,
+extension_callback(struct lws_context *context, const struct lws_extension *ext,
struct lws *wsi, enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len);
typedef int (extension_callback_function)(struct lws_context *context,
- struct lws_extension *ext, struct lws *wsi,
+ const struct lws_extension *ext, struct lws *wsi,
enum lws_extension_callback_reasons reason,
void *user, void *in, size_t len);
#endif
struct lws_context_creation_info {
int port;
const char *iface;
- struct lws_protocols *protocols;
- struct lws_extension *extensions;
- struct lws_token_limits *token_limits;
+ const struct lws_protocols *protocols;
+ const struct lws_extension *extensions;
+ const struct lws_token_limits *token_limits;
const char *ssl_private_key_password;
const char *ssl_cert_filepath;
const char *ssl_private_key_filepath;
lws_get_protocol(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int
-lws_callback_on_writable(struct lws_context *context, struct lws *wsi);
+lws_callback_on_writable(const struct lws_context *context, struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int
-lws_callback_on_writable_all_protocol(const struct lws_protocols *protocol);
+lws_callback_on_writable_all_protocol(const struct lws_context *context,
+ const struct lws_protocols *protocol);
LWS_VISIBLE LWS_EXTERN int
-lws_callback_all_protocol(const struct lws_protocols *protocol, int reason);
+lws_callback_all_protocol(struct lws_context *context,
+ const struct lws_protocols *protocol, int reason);
LWS_VISIBLE LWS_EXTERN int
lws_get_socket_fd(struct lws *wsi);
lws_rx_flow_control(struct lws *wsi, int enable);
LWS_VISIBLE LWS_EXTERN void
-lws_rx_flow_allow_all_protocol(const struct lws_protocols *protocol);
+lws_rx_flow_allow_all_protocol(const struct lws_context *context,
+ const struct lws_protocols *protocol);
LWS_VISIBLE LWS_EXTERN size_t
lws_remaining_packet_payload(struct lws *wsi);
lws_get_fops(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN struct lws_context *
-lws_get_ctx(struct lws *wsi);
+lws_get_ctx(const struct lws *wsi);
/*
* File Operations access helpers
*/
LWS_VISIBLE int
-lws_callback_on_writable(struct lws_context *context,
- struct lws *wsi)
+lws_callback_on_writable(const struct lws_context *context, struct lws *wsi)
{
#ifdef LWS_USE_HTTP2
struct lws *network_wsi, *wsi2;
*/
LWS_VISIBLE int
-lws_callback_on_writable_all_protocol(
+lws_callback_on_writable_all_protocol(const struct lws_context *context,
const struct lws_protocols *protocol)
{
- struct lws_context *context = protocol->owning_server;
int n;
struct lws *wsi;
#else
#define lws_ssl_anybody_has_buffered_read(ctx) (0)
#endif
- struct lws_protocols *protocols;
+ const struct lws_protocols *protocols;
int count_protocols;
#ifndef LWS_NO_EXTENSIONS
- struct lws_extension *extensions;
+ const struct lws_extension *extensions;
#endif
- struct lws_token_limits *token_limits;
+ const struct lws_token_limits *token_limits;
void *user_space;
struct lws_plat_file_ops fops;
struct lws_io_watcher w_read;
struct lws_io_watcher w_write;
#endif /* LWS_USE_LIBEV */
- const struct lws_context *context;
+ struct lws_context *context;
const struct lws_protocols *protocol;
#ifndef LWS_NO_EXTENSIONS
- struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
+ const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
void *active_extensions_user[LWS_MAX_EXTENSIONS_ACTIVE];
unsigned char count_active_extensions;
unsigned int extension_data_pending:1;
int n;
char *c;
char ext_name[128];
- struct lws_extension *ext;
+ const struct lws_extension *ext;
int ext_count = 0;
int more = 1;
*/
static int
-callback_dumb_increment(struct lws_context *this,
+callback_dumb_increment(struct lws_context *context,
struct lws *wsi,
enum lws_callback_reasons reason,
void *user, void *in, size_t len)
gettimeofday(&tv, NULL);
if (((((unsigned long long)tv.tv_sec * 1000000) + tv.tv_usec) - oldus) > rate_us) {
- lws_callback_on_writable_all_protocol(&protocols[0]);
+ lws_callback_on_writable_all_protocol(context,
+ &protocols[0]);
oldus = ((unsigned long long)tv.tv_sec * 1000000) + tv.tv_usec;
}
}
if (((ringbuffer_head - pss->ringbuffer_tail) &
(MAX_MESSAGE_QUEUE - 1)) == (MAX_MESSAGE_QUEUE - 15))
- lws_rx_flow_allow_all_protocol(
+ lws_rx_flow_allow_all_protocol(context,
lws_get_protocol(wsi));
if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
lws_rx_flow_control(wsi, 0);
done:
- lws_callback_on_writable_all_protocol(
+ lws_callback_on_writable_all_protocol(context,
lws_get_protocol(wsi));
break;
* them is protected by the same lock
*/
pthread_mutex_lock(&lock_established_conns);
- lws_callback_on_writable_all_protocol(
+ lws_callback_on_writable_all_protocol(context,
&protocols[PROTOCOL_DUMB_INCREMENT]);
pthread_mutex_unlock(&lock_established_conns);
usleep(100000);
ms = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
if ((ms - oldms) > 50) {
- lws_callback_on_writable_all_protocol(
+ lws_callback_on_writable_all_protocol(context,
&protocols[PROTOCOL_DUMB_INCREMENT]);
oldms = ms;
}