- libwebsockets_/lws_
- libwebsocket_/lws_
- struct\ libwebsocket/struct\ lws
+
+4) context parameter removed from user callback.
+
+Since almost all apis no longer need the context as a parameter, it's no longer
+provided at the user callback directly.
+
+However if you need it, for ALL callbacks wsi is valid and has a valid context
+pointer you can recover using lws_get_ctx(wsi).
v1.5-chrome47-firefox41
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
lwsl_info("Client doing pong callback\n");
- m = wsi->protocol->callback(lws_get_ctx(wsi),
- wsi, (enum lws_callback_reasons)callback_action,
+ m = wsi->protocol->callback(wsi,
+ (enum lws_callback_reasons)callback_action,
wsi->user_space, eff_buf.token, eff_buf.token_len);
/* if user code wants to close, let caller know */
* we seem to be good to go, give client last chance to check
* headers and OK it
*/
- wsi->protocol->callback(context, wsi,
+ wsi->protocol->callback(wsi,
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
wsi->user_space, NULL, 0);
/* call him back to inform him he is up */
- wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLIENT_ESTABLISHED,
+ wsi->protocol->callback(wsi, LWS_CALLBACK_CLIENT_ESTABLISHED,
wsi->user_space, NULL, 0);
#ifndef LWS_NO_EXTENSIONS
/*
bail2:
if (wsi->protocol) {
if (isErrorCodeReceived && p) {
- wsi->protocol->callback(context, wsi,
+ wsi->protocol->callback(wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
wsi->user_space, p,
(unsigned int)strlen(p));
} else {
- wsi->protocol->callback(context, wsi,
+ wsi->protocol->callback(wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
wsi->user_space, NULL, 0);
}
continue;
}
- n = context->protocols[0].callback(context, wsi,
+ n = context->protocols[0].callback(wsi,
LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED,
wsi->user_space, (char *)ext->name, 0);
/* give userland a chance to append, eg, cookies */
- context->protocols[0].callback(context, wsi,
+ context->protocols[0].callback(wsi,
LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER,
NULL, &p,
(pkt + sizeof(context->service_buffer)) - p - 12);
lws_create_context(struct lws_context_creation_info *info)
{
struct lws_context *context = NULL;
+ struct lws wsi;
#ifndef LWS_NO_DAEMONIZE
int pid_daemon = get_daemonize_pid();
#endif
context->ka_interval = info->ka_interval;
context->ka_probes = info->ka_probes;
+ memset(&wsi, 0, sizeof(wsi));
+ wsi.context = context;
+
if (!info->ka_interval && info->ka_time > 0) {
lwsl_err("info->ka_interval can't be 0 if ka_time used\n");
return NULL;
context->count_protocols++)
/*
* inform all the protocols that they are doing their one-time
- * initialization if they want to
+ * initialization if they want to.
+ *
+ * NOTE the wsi is all zeros except for the context pointer
+ * so lws_get_ctx(wsi) can work in the callback.
*/
- info->protocols[context->count_protocols].callback(context,
- NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
+ info->protocols[context->count_protocols].callback(&wsi,
+ LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0);
/*
* give all extensions a chance to create any per-context
protocol = context->protocols;
if (protocol) {
while (protocol->callback) {
- protocol->callback(context, NULL,
+ protocol->callback(NULL,
LWS_CALLBACK_PROTOCOL_DESTROY,
NULL, NULL, 0);
protocol++;
wsi->u.http.content_remain -= body_chunk_len;
len -= body_chunk_len;
- n = wsi->protocol->callback(
- lws_get_ctx(wsi), wsi,
+ n = wsi->protocol->callback(wsi,
LWS_CALLBACK_HTTP_BODY, wsi->user_space,
buf, body_chunk_len);
if (n)
/* he sent all the content in time */
postbody_completion:
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
- n = wsi->protocol->callback(
- lws_get_ctx(wsi), wsi,
+ n = wsi->protocol->callback(wsi,
LWS_CALLBACK_HTTP_BODY_COMPLETION,
wsi->user_space, NULL, 0);
if (n)
lwsl_debug("closing http file\n");
lws_plat_file_close(wsi, wsi->u.http.fd);
wsi->u.http.fd = LWS_INVALID_FILE;
- context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
+ context->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
+ wsi->user_space, NULL, 0);
}
if (wsi->socket_is_permanently_unusable ||
reason == LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY)
goto just_kill_connection;
if (wsi->mode == LWS_CONNMODE_HTTP_SERVING)
- context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0);
+ context->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
+ wsi->user_space, NULL, 0);
/*
* are his extensions okay with him closing? Eg he might be a mux
(old_state == WSI_STATE_AWAITING_CLOSE_ACK) ||
(old_state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE))) {
lwsl_debug("calling back CLOSED\n");
- wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED,
+ wsi->protocol->callback(wsi, LWS_CALLBACK_CLOSED,
wsi->user_space, NULL, 0);
} else if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED) {
lwsl_debug("calling back CLOSED_HTTP\n");
- context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0 );
+ context->protocols[0].callback(wsi, LWS_CALLBACK_CLOSED_HTTP,
+ wsi->user_space, NULL, 0 );
} else if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY ||
wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT) {
lwsl_debug("Connection closed before server reply\n");
- context->protocols[0].callback(context, wsi,
+ context->protocols[0].callback(wsi,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
wsi->user_space, NULL, 0);
} else
}
/* outermost destroy notification for wsi (user_space still intact) */
- context->protocols[0].callback(context, wsi, LWS_CALLBACK_WSI_DESTROY,
+ context->protocols[0].callback(wsi, LWS_CALLBACK_WSI_DESTROY,
wsi->user_space, NULL, 0);
lws_free_wsi(wsi);
if (!wsi)
continue;
if (wsi->protocol == protocol)
- protocol->callback(context, wsi,
- reason, wsi->user_space, NULL, 0);
+ protocol->callback(wsi, reason, wsi->user_space, NULL, 0);
}
return 0;
}
int user_callback_handle_rxflow(callback_function callback_function,
- struct lws_context *context, struct lws *wsi,
+ struct lws *wsi,
enum lws_callback_reasons reason, void *user,
void *in, size_t len)
{
int n;
- n = callback_function(context, wsi, reason, user, in, len);
+ n = callback_function(wsi, reason, user, in, len);
if (!n)
n = _lws_rx_flow_control(wsi);
#include "lws_config.h"
#if defined(WIN32) || defined(_WIN32)
-#if (WINVER < 0x0501)
+#if (WINVER < 0x0600)
#undef WINVER
#undef _WIN32_WINNT
-#define WINVER 0x0501
+#define WINVER 0x0600
#define _WIN32_WINNT WINVER
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
+
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stddef.h>
SHORT events;
SHORT revents;
};
-#if (_WIN32_WINNT < 0x0600)
-WINSOCK_API_LINKAGE int WSAAPI WSAPoll(struct lws_pollfd fdArray[], ULONG fds, INT timeout);
-#endif
#else
#if defined(MBED_OPERATORS)
* duration of wsi dereference from the other thread context.
*/
LWS_VISIBLE LWS_EXTERN int
-callback(const struct lws_context *context, const struct lws *wsi,
- enum lws_callback_reasons reason, void *user, void *in, size_t len);
+callback(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 *wsi,
enum lws_callback_reasons reason, void *user,
void *in, size_t len);
lws_libev_run(context);
- context->service_tid = context->protocols[0].callback(context, NULL,
+ context->service_tid = context->protocols[0].callback(NULL,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
#ifdef LWS_OPENSSL_SUPPORT
if (context == NULL)
return 1;
- context->service_tid = context->protocols[0].callback(context, NULL,
+ context->service_tid = context->protocols[0].callback(NULL,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
for (i = 0; i < context->fds_count; ++i) {
if (wsi->protocol->callback)
/* ignore callback returned value */
user_callback_handle_rxflow(
- wsi->protocol->callback, context, wsi,
+ wsi->protocol->callback, wsi,
LWS_CALLBACK_HTTP_FILE_COMPLETION,
wsi->user_space, NULL, 0);
return 1; /* >0 indicates completed */
ret = user_callback_handle_rxflow(
wsi->protocol->callback,
- lws_get_ctx(wsi),
wsi,
(enum lws_callback_reasons)callback_action,
wsi->user_space,
// lwsl_info("insert_wsi_socket_into_fds: wsi=%p, sock=%d, fds pos=%d\n",
// wsi, wsi->sock, context->fds_count);
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 1))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
+ wsi->user_space, (void *) &pa, 1))
return -1;
insert_wsi(context, wsi);
lws_plat_insert_socket_into_fds(context, wsi);
/* external POLL support via protocol 0 */
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_ADD_POLL_FD, wsi->user_space, (void *) &pa, 0))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_ADD_POLL_FD,
+ wsi->user_space, (void *) &pa, 0))
return -1;
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *)&pa, 1))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
+ wsi->user_space, (void *)&pa, 1))
return -1;
return 0;
lwsl_info("%s: wsi=%p, sock=%d, fds pos=%d\n", __func__,
wsi, wsi->sock, wsi->position_in_fds_table);
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *)&pa, 1))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
+ wsi->user_space, (void *)&pa, 1))
return -1;
m = wsi->position_in_fds_table; /* replace the contents for this */
/* remove also from external POLL support via protocol 0 */
if (lws_socket_is_valid(wsi->sock)) {
- if (context->protocols[0].callback(context, wsi,
+ if (context->protocols[0].callback(wsi,
LWS_CALLBACK_DEL_POLL_FD, wsi->user_space,
(void *) &pa, 0))
return -1;
}
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_UNLOCK_POLL,
- wsi->user_space, (void *) &pa, 1))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
+ wsi->user_space, (void *) &pa, 1))
return -1;
return 0;
pfd = &context->fds[wsi->position_in_fds_table];
pa.fd = wsi->sock;
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_LOCK_POLL, wsi->user_space, (void *) &pa, 0))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_LOCK_POLL,
+ wsi->user_space, (void *) &pa, 0))
return -1;
pa.prev_events = pfd->events;
pa.events = pfd->events = (pfd->events & ~_and) | _or;
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_CHANGE_MODE_POLL_FD,
- wsi->user_space, (void *) &pa, 0))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_CHANGE_MODE_POLL_FD,
+ wsi->user_space, (void *) &pa, 0))
return -1;
/*
* then cancel it to force a restart with our changed events
*/
#if LWS_POSIX
- pa_events = (pa.prev_events != pa.events);
+ pa_events = pa.prev_events != pa.events;
#endif
- if (pa_events)
- {
+ if (pa_events) {
if (lws_plat_change_pollfd(context, wsi, pfd)) {
lwsl_info("%s failed\n", __func__);
sampled_tid = context->service_tid;
if (sampled_tid) {
- tid = context->protocols[0].callback(context, NULL,
+ tid = context->protocols[0].callback(NULL,
LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0);
if (tid == -1)
return -1;
}
}
- if (context->protocols[0].callback(context, wsi,
- LWS_CALLBACK_UNLOCK_POLL, wsi->user_space, (void *) &pa, 0))
+ if (context->protocols[0].callback(wsi, LWS_CALLBACK_UNLOCK_POLL,
+ wsi->user_space, (void *) &pa, 0))
return -1;
return 0;
* Delay waiting for our POLLOUT until peer indicates he has
* space for more using tx window command in http2 layer
*/
- lwsl_info("%s: %p: waiting_tx_credit (%d)\n", __func__, wsi, wsi->u.http2.tx_credit);
+ lwsl_info("%s: %p: waiting_tx_credit (%d)\n", __func__, wsi,
+ wsi->u.http2.tx_credit);
wsi->u.http2.waiting_tx_credit = 1;
return 0;
}
lws_union_transition(struct lws *wsi, enum connection_mode mode);
LWS_EXTERN int
-user_callback_handle_rxflow(callback_function, struct lws_context *context,
- struct lws *wsi, enum lws_callback_reasons reason,
- void *user, void *in, size_t len);
+user_callback_handle_rxflow(callback_function, struct lws *wsi,
+ enum lws_callback_reasons reason, void *user,
+ void *in, size_t len);
#ifdef LWS_USE_HTTP2
LWS_EXTERN struct lws *lws_http2_get_network_wsi(struct lws *wsi);
struct lws * lws_http2_get_nth_child(struct lws *wsi, int n);
* particular connection + protocol
*/
- n = lws_get_ctx(wsi)->
- protocols[0].callback(
- lws_get_ctx(wsi),
- wsi,
- LWS_CALLBACK_CONFIRM_EXTENSION_OKAY,
- wsi->user_space, ext_name, 0);
+ n = lws_get_ctx(wsi)->protocols[0].callback(wsi,
+ LWS_CALLBACK_CONFIRM_EXTENSION_OKAY,
+ wsi->user_space, ext_name, 0);
/*
* zero return from callback means go ahead and allow
/* notify user code that we're ready to roll */
if (wsi->protocol->callback)
- wsi->protocol->callback(lws_get_ctx(wsi),
- wsi, LWS_CALLBACK_ESTABLISHED,
+ wsi->protocol->callback(wsi, LWS_CALLBACK_ESTABLISHED,
wsi->user_space,
#ifdef LWS_OPENSSL_SUPPORT
wsi->ssl,
int lws_http_action(struct lws *wsi)
{
- struct lws_context *context = wsi->context;
enum http_connection_type connection_type;
enum http_version request_version;
char content_length_str[32];
}
wsi->u.http.connection_type = connection_type;
- n = wsi->protocol->callback(context, wsi,
- LWS_CALLBACK_FILTER_HTTP_CONNECTION,
+ n = wsi->protocol->callback(wsi, LWS_CALLBACK_FILTER_HTTP_CONNECTION,
wsi->user_space, uri_ptr, uri_len);
if (!n) {
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
AWAITING_TIMEOUT);
- n = wsi->protocol->callback(context, wsi, LWS_CALLBACK_HTTP,
- wsi->user_space, uri_ptr, uri_len);
+ n = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP,
+ wsi->user_space, uri_ptr, uri_len);
}
/* now drop the header info we kept a pointer to */
* have the opportunity to deny it
*/
- if ((wsi->protocol->callback)(lws_get_ctx(wsi), wsi,
+ if ((wsi->protocol->callback)(wsi,
LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION,
wsi->user_space,
lws_hdr_simple_ptr(wsi, WSI_TOKEN_PROTOCOL), 0)) {
* outermost create notification for wsi
* no user_space because no protocol selection
*/
- context->protocols[0].callback(context, new_wsi,
- LWS_CALLBACK_WSI_CREATE, NULL, NULL, 0);
+ context->protocols[0].callback(new_wsi, LWS_CALLBACK_WSI_CREATE, NULL,
+ NULL, 0);
return new_wsi;
}
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE) {
n = user_callback_handle_rxflow(
wsi->protocol->callback,
- lws_get_ctx(wsi),
wsi, LWS_CALLBACK_HTTP_WRITEABLE,
- wsi->user_space,
- NULL,
- 0);
+ wsi->user_space, NULL, 0);
if (n < 0)
goto fail;
break;
* yet so we issue this to protocols[0]
*/
- if ((context->protocols[0].callback)(context, wsi,
+ if ((context->protocols[0].callback)(wsi,
LWS_CALLBACK_FILTER_NETWORK_CONNECTION,
NULL, (void *)(long)accept_fd, 0)) {
lwsl_debug("Callback denied network connection\n");
* set properties of the newly created wsi. There's no protocol
* selected yet so we issue this to protocols[0]
*/
- (context->protocols[0].callback)(context, new_wsi,
+ (context->protocols[0].callback)(new_wsi,
LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED,
NULL, NULL, 0);
#include "private-libwebsockets.h"
static int
-lws_calllback_as_writeable(struct lws_context *context, struct lws *wsi)
+lws_calllback_as_writeable(struct lws *wsi)
{
int n;
break;
}
lwsl_info("%s: %p (user=%p)\n", __func__, wsi, wsi->user_space);
- return user_callback_handle_rxflow(wsi->protocol->callback, context,
+ return user_callback_handle_rxflow(wsi->protocol->callback,
wsi, (enum lws_callback_reasons) n,
wsi->user_space, NULL, 0);
}
int
lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
{
- struct lws_context *context = wsi->context;
int write_type = LWS_WRITE_PONG;
struct lws_tokens eff_buf;
#ifdef LWS_USE_HTTP2
switch (wsi->pps) {
case LWS_PPS_HTTP2_MY_SETTINGS:
case LWS_PPS_HTTP2_ACK_SETTINGS:
- lws_http2_do_pps_send(context, wsi);
+ lws_http2_do_pps_send(lws_get_ctx(wsi), wsi);
break;
default:
break;
if (!wsi2->u.http2.requested_POLLOUT)
continue;
wsi2->u.http2.requested_POLLOUT = 0;
- if (lws_calllback_as_writeable(context, wsi2)) {
+ if (lws_calllback_as_writeable(wsi2)) {
lwsl_debug("Closing POLLOUT child\n");
lws_close_free_wsi(wsi2, LWS_CLOSE_STATUS_NOSTATUS);
}
return 0;
notify:
#endif
- return lws_calllback_as_writeable(context, wsi);
+ return lws_calllback_as_writeable(wsi);
}
-
-
int
lws_service_timeout_check(struct lws *wsi, unsigned int sec)
{
SSL *ssl;
int n;
struct lws_context *context;
+ struct lws wsi;
ssl = X509_STORE_CTX_get_ex_data(x509_ctx,
SSL_get_ex_data_X509_STORE_CTX_idx());
*/
context = SSL_get_ex_data(ssl, openssl_websocket_private_data_index);
- n = context->protocols[0].callback(NULL, NULL,
- LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION,
- x509_ctx, ssl, preverify_ok);
+ /*
+ * give him a fake wsi with context set, so he can use lws_get_ctx()
+ * in the callback
+ */
+ memset(&wsi, 0, sizeof(wsi));
+ wsi.context = context;
+
+ n = context->protocols[0].callback(&wsi,
+ LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION,
+ x509_ctx, ssl, preverify_ok);
/* convert return code from 0 = OK to 1 = OK */
return !n;
struct lws_context *context)
{
SSL_METHOD *method;
+ struct lws wsi;
int error;
int n;
lwsl_notice(" Using non-SSL mode\n");
}
+ /*
+ * give him a fake wsi with context set, so he can use
+ * lws_get_ctx() in the callback
+ */
+ memset(&wsi, 0, sizeof(wsi));
+ wsi.context = context;
+
/* basic openssl init */
SSL_library_init();
if (info->options &
LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT) {
-
int verify_options = SSL_VERIFY_PEER;
if (!(info->options & LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED))
* allowing it to verify incoming client certs
*/
- context->protocols[0].callback(context, NULL,
+ context->protocols[0].callback(&wsi,
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS,
- context->ssl_ctx, NULL, 0);
+ context->ssl_ctx, NULL, 0);
}
if (info->options & LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT) {
SSL_FILETYPE_PEM) != 1) {
error = ERR_get_error();
lwsl_err("ssl problem getting key '%s' %lu: %s\n",
- info->ssl_private_key_filepath,
- error,
- ERR_error_string(error,
- (char *)context->service_buffer));
+ info->ssl_private_key_filepath, error,
+ ERR_error_string(error,
+ (char *)context->service_buffer));
return 1;
}
}
else {
- if (context->protocols[0].callback(context, NULL,
+ if (context->protocols[0].callback(&wsi,
LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY,
context->ssl_ctx, NULL, 0)) {
lwsl_err("ssl private key not set\n");
+
return 1;
}
}
int error;
int n;
SSL_METHOD *method;
+ struct lws wsi;
if (info->provided_client_ssl_ctx) {
/* use the provided OpenSSL context if given one */
/* support for client-side certificate authentication */
if (info->ssl_cert_filepath) {
- n = SSL_CTX_use_certificate_chain_file(
- context->ssl_client_ctx,
- info->ssl_cert_filepath);
+ n = SSL_CTX_use_certificate_chain_file(context->ssl_client_ctx,
+ info->ssl_cert_filepath);
if (n != 1) {
lwsl_err("problem getting cert '%s' %lu: %s\n",
info->ssl_cert_filepath,
}
/* verify private key */
- if (!SSL_CTX_check_private_key(
- context->ssl_client_ctx)) {
+ if (!SSL_CTX_check_private_key(context->ssl_client_ctx)) {
lwsl_err("Private SSL key doesn't match cert\n");
return 1;
}
}
- context->protocols[0].callback(context, NULL,
- LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS,
- context->ssl_client_ctx, NULL, 0);
+ /*
+ * give him a fake wsi with context set, so he can use
+ * lws_get_ctx() in the callback
+ */
+ memset(&wsi, 0, sizeof(wsi));
+ wsi.context = context;
+
+ context->protocols[0].callback(&wsi,
+ LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS,
+ context->ssl_client_ctx, NULL, 0);
return 0;
}
*/
static int
-callback_dumb_increment(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason,
+callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
switch (reason) {
static int
-callback_lws_mirror(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason,
+callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 4096 +
lwsl_notice("mirror: LWS_CALLBACK_CLIENT_ESTABLISHED\n");
- lws_get_random(context, rands, sizeof(rands[0]));
+ lws_get_random(lws_get_ctx(wsi), rands, sizeof(rands[0]));
mirror_lifetime = 16384 + (rands[0] & 65535);
/* useful to test single connection stability */
if (longlived)
case LWS_CALLBACK_CLIENT_WRITEABLE:
for (n = 0; n < 1; n++) {
- lws_get_random(context, rands, sizeof(rands));
+ lws_get_random(lws_get_ctx(wsi), rands, sizeof(rands));
l += sprintf((char *)&buf[LWS_SEND_BUFFER_PRE_PADDING + l],
"c #%06X %d %d %d;",
(int)rands[0] & 0xffffff,
};
static int
-callback_echo(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason, void *user,
- void *in, size_t len)
+callback_echo(struct lws *wsi, enum lws_callback_reasons reason, void *user,
+ void *in, size_t len)
{
struct per_session_data__echo *pss = (struct per_session_data__echo *)user;
int n;
};
static int
-callback_fraggle(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason,
- void *user, void *in, size_t len)
+callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len)
{
int n;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 8000 +
- LWS_SEND_BUFFER_POST_PADDING];
+ LWS_SEND_BUFFER_POST_PADDING];
struct per_session_data__fraggle *psf = user;
int chunk;
int write_mode = LWS_WRITE_CONTINUATION;
switch (psf->state) {
case FRAGSTATE_START_MESSAGE:
- lws_get_random(context, &ran, sizeof(ran));
+ lws_get_random(lws_get_ctx(wsi), &ran, sizeof(ran));
psf->packets_left = (ran % 1024) + 1;
fprintf(stderr, "Spamming %d random fragments\n",
psf->packets_left);
* code for rx spill because the rx buffer is full
*/
- lws_get_random(context, &ran, sizeof(ran));
+ lws_get_random(lws_get_ctx(wsi), &ran, sizeof(ran));
chunk = (ran % 8000) + 1;
psf->total_message += chunk;
- lws_get_random(context, bp, chunk);
+ lws_get_random(lws_get_ctx(wsi), bp, chunk);
for (n = 0; n < chunk; n++)
psf->sum += bp[n];
static int
-callback_lws_mirror(struct lws_context * this,
- struct lws *wsi,
- enum lws_callback_reasons reason,
- void *user, void *in, size_t len)
+callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len)
{
struct timeval tv;
unsigned char *p;
/* dumb_increment protocol */
int
-callback_dumb_increment(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason,
+callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 512 +
* here on the first protocol server.
*/
-int callback_http(struct lws_context *context, struct lws *wsi,
- enum lws_callback_reasons reason, void *user,
+int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
void *in, size_t len)
{
struct per_session_data__http *pss =
static int ringbuffer_head;
int
-callback_lws_mirror(struct lws_context *context,
- struct lws *wsi,
- enum lws_callback_reasons reason,
+callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
struct per_session_data__lws_mirror *pss =
if (((ringbuffer_head - pss->ringbuffer_tail) &
(MAX_MESSAGE_QUEUE - 1)) == (MAX_MESSAGE_QUEUE - 15))
- lws_rx_flow_allow_all_protocol(context,
+ lws_rx_flow_allow_all_protocol(lws_get_ctx(wsi),
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(context,
+ lws_callback_on_writable_all_protocol(lws_get_ctx(wsi),
lws_get_protocol(wsi));
break;
};
extern int
-callback_http(struct lws_context *context, struct lws *wsi,
- enum lws_callback_reasons reason, void *user, void *in,
- size_t len);
+callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
+ void *in, size_t len);
extern int
-callback_lws_mirror(struct lws_context *context, struct lws *wsi,
- enum lws_callback_reasons reason, void *user, void *in,
- size_t len);
+callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len);
extern int
-callback_dumb_increment(struct lws_context *context, struct lws *wsi,
- enum lws_callback_reasons reason, void *user, void *in,
- size_t len);
+callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
+ void *user, void *in, size_t len);
extern void
dump_handshake_info(struct lws *wsi);