option(LWS_IPV6 "Compile with support for ipv6" OFF)
option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
option(LWS_MBED3 "Platform is MBED3" OFF)
-option(LWS_WITH_OLD_API_WRAPPERS "Compile with binary compatibility with pre-v1.6 apis" OFF)
if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING)
message(" LWS_IPV6 = ${LWS_IPV6}")
message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
message(" LWS_MBED3 = ${LWS_MBED3}")
-message(" LWS_WITH_OLD_API_WRAPPERS = ${LWS_WITH_OLD_API_WRAPPERS}")
message("---------------------------------------------------------------------")
# These will be available to parent projects including libwebsockets using add_subdirectory()
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
`lws_get_fops`(struct lws_context *context);
-and then can use it with helpers to also leverage these platform-independent
+and then can use helpers to also leverage these platform-independent
file handling apis
static inline lws_filefd_type
-`lws_plat_file_open`(struct lws_plat_file_ops *fops, const char *filename, unsigned long *filelen, int flags)
+`lws_plat_file_open`(struct lws *wsi, const char *filename, unsigned long *filelen, int flags)
static inline int
-`lws_plat_file_close`(struct lws_plat_file_ops *fops, lws_filefd_type fd)
+`lws_plat_file_close`(struct lws *wsi, lws_filefd_type fd)
static inline unsigned long
-`lws_plat_file_seek_cur`(struct lws_plat_file_ops *fops, lws_filefd_type fd, long offset_from_cur_pos)
+`lws_plat_file_seek_cur`(struct lws *wsi, lws_filefd_type fd, long offset_from_cur_pos)
static inline int
-`lws_plat_file_read`(struct lws_plat_file_ops *fops, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
+`lws_plat_file_read`(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
static inline int
-`lws_plat_file_write`(struct lws_plat_file_ops *fops, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
+`lws_plat_file_write`(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, unsigned char *buf, unsigned long len)
The user code can also override or subclass the file operations, to either
wrap or replace them. An example is shown in test server.
members that lws used for private storage: so the protocols struct in now
truly const and may be reused serially or simultaneously by different contexts.
-2) Several older apis start with libwebsocket_ or libwebsockets_ while newer ones
-all begin lws_. These apis have been changed to all begin with lws_.
+2) Eleven APIs
-However except for the three APIs mentioned above in 1), compatibility defines
-have been added in libwebsockets.h, so it is largely build-compatible with
-older sources using the old api names.
+LWS_VISIBLE LWS_EXTERN int
+lws_add_http_header_by_name(struct lws_context *context,
+ struct lws *wsi,
+ const unsigned char *name,
+ const unsigned char *value,
+ int length,
+ unsigned char **p,
+ unsigned char *end);
+LWS_VISIBLE LWS_EXTERN int
+lws_finalize_http_header(struct lws_context *context,
+ struct lws *wsi,
+ unsigned char **p,
+ unsigned char *end);
+LWS_VISIBLE LWS_EXTERN int
+lws_add_http_header_by_token(struct lws_context *context,
+ struct lws *wsi,
+ enum lws_token_indexes token,
+ const unsigned char *value,
+ int length,
+ unsigned char **p,
+ unsigned char *end);
+LWS_VISIBLE LWS_EXTERN int
+lws_add_http_header_content_length(struct lws_context *context,
+ struct lws *wsi,
+ unsigned long content_length,
+ unsigned char **p,
+ unsigned char *end);
+LWS_VISIBLE LWS_EXTERN int
+lws_add_http_header_status(struct lws_context *context, struct lws *wsi,
+ unsigned int code, unsigned char **p,
+ unsigned char *end);
-If you are using lws with a distro, or otherwise can't rebuild the user code,
-you should add
+LWS_VISIBLE LWS_EXTERN int
+lws_serve_http_file(struct lws_context *context, struct lws *wsi,
+ const char *file, const char *content_type,
+ const char *other_headers, int other_headers_len);
+LWS_VISIBLE LWS_EXTERN int
+lws_serve_http_file_fragment(struct lws_context *context, struct lws *wsi);
- -DLWS_WITH_OLD_API_WRAPPERS=1
+LWS_VISIBLE LWS_EXTERN int
+lws_return_http_status(struct lws_context *context, struct lws *wsi,
+ unsigned int code, const char *html_body);
+
+LWS_VISIBLE LWS_EXTERN int
+lws_callback_on_writable(const struct lws_context *context, struct lws *wsi);
+
+LWS_VISIBLE LWS_EXTERN void
+lws_get_peer_addresses(struct lws_context *context, struct lws *wsi,
+ lws_sockfd_type fd, char *name, int name_len,
+ char *rip, int rip_len);
+
+LWS_VISIBLE LWS_EXTERN int
+lws_read(struct lws_context *context, struct lws *wsi,
+ unsigned char *buf, size_t len);
+
+no longer require their initial struct lws_context * parameter.
+
+3) Several older apis start with libwebsocket_ or libwebsockets_ while newer ones
+all begin lws_. These apis have been changed to all begin with lws_.
-to your cmake args. This builds lws with all the old apis as wrappers around
-the new apis, so the library still exports the old apis.
+To convert, search-replace
-In this way you can have lws export both the new and old apis simultaneously
-for compatibility.
+ - libwebsockets_/lws_
+ - libwebsocket_/lws_
+ - struct\ libwebsocket/struct\ lws
v1.5-chrome47-firefox41
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT;
- lws_libev_accept(context, wsi, wsi->sock);
+ lws_libev_accept(wsi, wsi->sock);
if (insert_wsi_socket_into_fds(context, wsi)) {
compatible_close(wsi->sock);
goto oom4;
*/
if (lws_change_pollfd(wsi, 0, LWS_POLLOUT))
goto failed;
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_WRITE);
return wsi;
}
wsi->u.ws.ping_pending_flag = 1;
/* get it sent as soon as possible */
- lws_callback_on_writable(lws_get_ctx(wsi), wsi);
+ lws_callback_on_writable(wsi);
ping_drop:
wsi->u.ws.rx_user_buffer_head = 0;
handled = 1;
*/
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
return -1;
- lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
#ifdef LWS_OPENSSL_SUPPORT
/* we can retry this... just cook the SSL BIO the first time */
lwsl_info(
"SSL_connect WANT_WRITE... retrying\n");
- lws_callback_on_writable(
- context, wsi);
+ lws_callback_on_writable(wsi);
some_wait:
wsi->mode = LWS_CONNMODE_WS_CLIENT_WAITING_SSL;
*/
lwsl_info("SSL_connect WANT_WRITE... retrying\n");
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
goto some_wait;
}
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 0;
case LWS_SSL_CAPABLE_MORE_SERVICE:
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
}
* Yes, he's choked. Don't spill the rest now get a callback
* when he is ready to send and take care of it there
*/
- lws_callback_on_writable(
- lws_get_ctx(wsi), wsi);
+ lws_callback_on_writable(wsi);
wsi->extension_data_pending = 1;
ret = 0;
}
*/
LWS_VISIBLE int
-lws_read(struct lws_context *context, struct lws *wsi, unsigned char *buf,
- size_t len)
+lws_read(struct lws *wsi, unsigned char *buf, size_t len)
{
unsigned char *last_char;
int body_chunk_len;
/* account for what we're using in rxflow buffer */
if (wsi->rxflow_buffer)
wsi->rxflow_pos++;
- if (lws_http2_parser(context, wsi, buf[n++]))
+ if (lws_http2_parser(wsi, buf[n++]))
goto bail;
}
break;
goto bail;
last_char = buf;
- if (lws_handshake_server(context, wsi, &buf, len))
+ if (lws_handshake_server(wsi, &buf, len))
/* Handshake indicates this session is done. */
goto bail;
}
break;
default:
- lwsl_err("lws_read: Unhandled state\n");
+ lwsl_err("%s: Unhandled state\n", __func__);
break;
}
read_ok:
/* Nothing more to do for now */
- lwsl_debug("lws_read: read_ok\n");
+ lwsl_debug("%s: read_ok\n", __func__);
return 0;
http_complete:
- lwsl_debug("lws_read: http_complete\n");
+ lwsl_debug("%s: http_complete\n", __func__);
#ifndef LWS_NO_SERVER
/* Did the client want to keep the HTTP connection going? */
}
int
-lws_add_http_header_by_name(struct lws_context *context, struct lws *wsi,
- const unsigned char *name,
+lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
{
#ifdef LWS_USE_HTTP2
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
- return lws_add_http2_header_by_name(context, wsi, name,
+ return lws_add_http2_header_by_name(wsi, name,
value, length, p, end);
#else
(void)wsi;
- (void)context;
#endif
if (name) {
while (*p < end && *name)
return 0;
}
-int lws_finalize_http_header(struct lws_context *context, struct lws *wsi,
- unsigned char **p, unsigned char *end)
+int lws_finalize_http_header(struct lws *wsi, unsigned char **p,
+ unsigned char *end)
{
- (void)context;
#ifdef LWS_USE_HTTP2
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
return 0;
}
int
-lws_add_http_header_by_token(struct lws_context *context, struct lws *wsi,
- enum lws_token_indexes token,
+lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
{
const unsigned char *name;
#ifdef LWS_USE_HTTP2
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
- return lws_add_http2_header_by_token(context, wsi, token, value, length, p, end);
+ return lws_add_http2_header_by_token(wsi, token, value, length, p, end);
#endif
name = lws_token_to_string(token);
if (!name)
return 1;
- return lws_add_http_header_by_name(context, wsi, name, value, length, p, end);
+ return lws_add_http_header_by_name(wsi, name, value, length, p, end);
}
-int lws_add_http_header_content_length(struct lws_context *context,
- struct lws *wsi,
+int lws_add_http_header_content_length(struct lws *wsi,
unsigned long content_length,
unsigned char **p, unsigned char *end)
{
int n;
n = sprintf(b, "%lu", content_length);
- if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, (unsigned char *)b, n, p, end))
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH, (unsigned char *)b, n, p, end))
return 1;
wsi->u.http.content_length = content_length;
wsi->u.http.content_remain = content_length;
};
int
-lws_add_http_header_status(struct lws_context *context, struct lws *wsi,
+lws_add_http_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end)
{
#ifdef LWS_USE_HTTP2
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING)
- return lws_add_http2_header_status(context, wsi, code, p, end);
+ return lws_add_http2_header_status(wsi, code, p, end);
#endif
if (code >= 400 && code < (400 + ARRAY_SIZE(err400)))
description = err400[code - 400];
n = sprintf((char *)code_and_desc, "HTTP/1.0 %u %s", code, description);
- return lws_add_http_header_by_name(context, wsi, NULL, code_and_desc,
+ return lws_add_http_header_by_name(wsi, NULL, code_and_desc,
n, p, end);
}
* consistently
*/
LWS_VISIBLE int
-lws_return_http_status(struct lws_context *context, struct lws *wsi,
- unsigned int code, const char *html_body)
+lws_return_http_status(struct lws *wsi, unsigned int code, const char *html_body)
{
int n, m;
-
+ struct lws_context *context = lws_get_ctx(wsi);
unsigned char *p = context->service_buffer +
LWS_SEND_BUFFER_PRE_PADDING;
unsigned char *start = p;
if (!html_body)
html_body = "";
- if (lws_add_http_header_status(context, wsi, code, &p, end))
+ if (lws_add_http_header_status(wsi, code, &p, end))
return 1;
- if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER,
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
(unsigned char *)"libwebsockets", 13,
&p, end))
return 1;
- if (lws_add_http_header_by_token(context, wsi,
- WSI_TOKEN_HTTP_CONTENT_TYPE,
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
(unsigned char *)"text/html", 9,
&p, end))
return 1;
- if (lws_finalize_http_header(context, wsi, &p, end))
+ if (lws_finalize_http_header(wsi, &p, end))
return 1;
m = lws_write(wsi, start, p - start, LWS_WRITE_HTTP_HEADERS);
return 0;
}
-int lws_hpack_interpret(struct lws_context *context,
- struct lws *wsi, unsigned char c)
+int lws_hpack_interpret(struct lws *wsi, unsigned char c)
{
unsigned int prev;
unsigned char c1;
return 0;
}
-int lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi,
+int lws_add_http2_header_by_name(struct lws *wsi,
const unsigned char *name,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
return 0;
}
-int lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi,
- enum lws_token_indexes token,
+int lws_add_http2_header_by_token(struct lws *wsi, enum lws_token_indexes token,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end)
{
if (!name)
return 1;
- return lws_add_http2_header_by_name(context, wsi, name, value,
- length, p, end);
+ return lws_add_http2_header_by_name(wsi, name, value, length, p, end);
}
-int lws_add_http2_header_status(struct lws_context *context, struct lws *wsi,
+int lws_add_http2_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end)
{
wsi->u.http2.send_END_STREAM = !!(code >= 400);
n = sprintf((char *)status, "%u", code);
- if (lws_add_http2_header_by_token(context, wsi,
- WSI_TOKEN_HTTP_COLON_STATUS, status,
- n, p, end))
+ if (lws_add_http2_header_by_token(wsi, WSI_TOKEN_HTTP_COLON_STATUS,
+ status, n, p, end))
+
return 1;
return 0;
"PRI * HTTP/2.0\x0d\x0a\x0d\x0aSM\x0d\x0a\x0d\x0a";
int
-lws_http2_parser(struct lws_context *context, struct lws *wsi, unsigned char c)
+lws_http2_parser(struct lws *wsi, unsigned char c)
{
+ struct lws_context *context = wsi->context;
struct lws *swsi;
int n;
- //dstruct lws *wsi_new;
switch (wsi->state) {
case WSI_STATE_HTTP2_AWAIT_CLIENT_PREFACE:
case LWS_HTTP2_FRAME_TYPE_CONTINUATION:
case LWS_HTTP2_FRAME_TYPE_HEADERS:
lwsl_info(" %02X\n", c);
- if (lws_hpack_interpret(context, wsi->u.http2.stream_wsi, c))
+ if (lws_hpack_interpret(wsi->u.http2.stream_wsi, c))
return 1;
break;
case LWS_HTTP2_FRAME_TYPE_GOAWAY:
if (swsi->u.http2.waiting_tx_credit && swsi->u.http2.tx_credit > 0) {
lwsl_info("%s: %p: waiting_tx_credit -> wait on writeable\n", __func__, wsi);
swsi->u.http2.waiting_tx_credit = 0;
- lws_callback_on_writable(context, swsi);
+ lws_callback_on_writable(swsi);
}
break;
}
}
LWS_VISIBLE void
-lws_libev_accept(struct lws_context *context,
- struct lws *new_wsi, int accept_fd)
+lws_libev_accept(struct lws *new_wsi, int accept_fd)
{
+ struct lws_context *context = lws_get_ctx(new_wsi);
struct ev_io *r = &new_wsi->w_read.watcher;
struct ev_io *w = &new_wsi->w_write.watcher;
}
LWS_VISIBLE void
-lws_libev_io(const struct lws_context *context, struct lws *wsi, int flags)
+lws_libev_io(struct lws *wsi, int flags)
{
+ struct lws_context *context = lws_get_ctx(wsi);
+
if (!LWS_LIBEV_ENABLED(context))
return;
case WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE:
if (wsi->truncated_send_len) {
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
return;
}
lwsl_info("wsi %p completed WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE\n", wsi);
*/
LWS_VISIBLE void
-lws_get_peer_addresses(struct lws_context *context, struct lws *wsi,
- lws_sockfd_type fd, char *name, int name_len,
- char *rip, int rip_len)
+lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
+ int name_len, char *rip, int rip_len)
{
#if LWS_POSIX
socklen_t len;
struct sockaddr_in6 sin6;
#endif
struct sockaddr_in sin4;
+ struct lws_context *context = wsi->context;
int ret = -1;
void *p;
bail:
lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1);
#else
- (void)context;
(void)wsi;
(void)fd;
(void)name;
lwsl_err("pps overwrite\n");
wsi->pps = pend;
lws_rx_flow_control(wsi, 0);
- lws_callback_on_writable(wsi->context, wsi);
+ lws_callback_on_writable(wsi);
}
LWS_VISIBLE size_t
{
return wsi->user_space;
}
-
-#ifdef LWS_WITH_OLD_API_WRAPPERS
-
-/*
- * To maintain .so abi, also produce wrappers using old api naming.
- *
- * This is disabled by default, use "LWS_WITH_OLD_API_WRAPPERS" on cmake to
- * enable.
- *
- * You only need these if you have existing binary applications using the old
- * api names and you don't want to / can't recompile them against new lws.
- * With these new lws .so is compatible with old and new api names.
- *
- * If you can recompile your application (using old api names still) against
- * current lws, you don't need these compatibility helpers since
- * libwebsockets.h will map them at compile time.
- */
-
-#undef libwebsocket
-
-#undef libwebsocket_create_context
-LWS_VISIBLE LWS_EXTERN struct lws_context *
-libwebsocket_create_context(struct lws_context_creation_info *info)
-{
- return lws_create_context(info);
-}
-
-#undef libwebsocket_set_proxy
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_set_proxy(struct lws_context *context, const char *proxy)
-{
- return lws_set_proxy(context, proxy);
-}
-
-#undef libwebsocket_context_destroy
-LWS_VISIBLE LWS_EXTERN void
-libwebsocket_context_destroy(struct lws_context *context)
-{
- lws_context_destroy(context);
-}
-
-#undef libwebsocket_service
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_service(struct lws_context *context, int timeout_ms)
-{
- return lws_service(context, timeout_ms);
-}
-
-#undef libwebsocket_cancel_service
-LWS_VISIBLE LWS_EXTERN void
-libwebsocket_cancel_service(struct lws_context *context)
-{
- lws_cancel_service(context);
-}
-
-#ifdef LWS_USE_LIBEV
-#undef libwebsocket_sigint_cfg
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_sigint_cfg(struct lws_context *context, int use_ev_sigint,
- lws_ev_signal_cb* cb)
-{
- return lws_sigint_cfg(context, use_ev_sigint, cb);
-}
-
-#undef libwebsocket_initloop
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_initloop(struct lws_context *context, struct ev_loop *loop)
-{
- return lws_initloop(context, loop);
-}
-
-#undef libwebsocket_sigint_cb
-LWS_VISIBLE void
-libwebsocket_sigint_cb(
- struct ev_loop *loop, struct ev_signal *watcher, int revents)
-{
- lws_sigint_cb(loop, watcher, revents);
-}
-#endif /* LWS_USE_LIBEV */
-
-#undef libwebsocket_service_fd
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_service_fd(struct lws_context *context,
- struct lws_pollfd *pollfd)
-{
- return lws_service_fd(context, pollfd);
-}
-
-#undef libwebsocket_context_user
-LWS_VISIBLE LWS_EXTERN void *
-libwebsocket_context_user(struct lws_context *context)
-{
- return lws_context_user(context);
-}
-
-#undef libwebsocket_set_timeout
-LWS_VISIBLE LWS_EXTERN void
-libwebsocket_set_timeout(struct lws *wsi,
- enum pending_timeout reason, int secs)
-{
- lws_set_timeout(wsi, reason, secs);
-}
-
-#undef libwebsocket_write
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_write(struct lws *wsi, unsigned char *buf, size_t len,
- enum lws_write_protocol protocol)
-{
- return lws_write(wsi, buf, len, protocol);
-}
-
-#undef libwebsockets_serve_http_file_fragment
-LWS_VISIBLE LWS_EXTERN int
-libwebsockets_serve_http_file_fragment(struct lws_context *context,
- struct lws *wsi)
-{
- return lws_serve_http_file_fragment(context, wsi);
-}
-
-#undef libwebsockets_serve_http_file
-LWS_VISIBLE LWS_EXTERN int
-libwebsockets_serve_http_file(struct lws_context *context,
- struct lws *wsi, const char *file,
- const char *content_type, const char *other_headers,
- int other_headers_len)
-{
- return lws_serve_http_file(context, wsi, file, content_type,
- other_headers, other_headers_len);
-}
-
-#undef libwebsockets_return_http_status
-LWS_VISIBLE LWS_EXTERN int
-libwebsockets_return_http_status(
- struct lws_context *context,
- struct lws *wsi, unsigned int code,
- const char *html_body)
-{
- return lws_return_http_status(context, wsi, code, html_body);
-}
-
-#undef libwebsockets_get_protocol
-LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
-libwebsockets_get_protocol(struct lws *wsi)
-{
- return lws_get_protocol(wsi);
-}
-
-
-#undef libwebsocket_callback_on_writable
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_callback_on_writable(struct lws_context *context,
- struct lws *wsi)
-{
- return lws_callback_on_writable(context, wsi);
-}
-
-#undef libwebsocket_get_socket_fd
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_get_socket_fd(struct lws *wsi)
-{
- return lws_get_socket_fd(wsi);
-}
-
-#undef libwebsocket_is_final_fragment
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_is_final_fragment(struct lws *wsi)
-{
- return lws_is_final_fragment(wsi);
-}
-
-#undef libwebsocket_get_reserved_bits
-LWS_VISIBLE LWS_EXTERN unsigned char
-libwebsocket_get_reserved_bits(struct lws *wsi)
-{
- return lws_get_reserved_bits(wsi);
-}
-
-#undef libwebsocket_rx_flow_control
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_rx_flow_control(struct lws *wsi, int enable)
-{
- return lws_rx_flow_control(wsi, enable);
-}
-
-#undef libwebsockets_remaining_packet_payload
-LWS_VISIBLE LWS_EXTERN size_t
-libwebsockets_remaining_packet_payload(struct lws *wsi)
-{
- return lws_remaining_packet_payload(wsi);
-}
-
-#undef libwebsocket_client_connect
-LWS_VISIBLE LWS_EXTERN struct lws *
-libwebsocket_client_connect(struct lws_context *clients,
- const char *address,
- int port,
- int ssl_connection,
- const char *path,
- const char *host,
- const char *origin,
- const char *protocol,
- int ietf_version_or_minus_one)
-{
- return lws_client_connect(clients, address, port, ssl_connection,
- path, host, origin, protocol, ietf_version_or_minus_one);
-}
-LWS_VISIBLE LWS_EXTERN struct lws *
-libwebsocket_client_connect_extended(struct lws_context *clients,
- const char *address,
- int port,
- int ssl_connection,
- const char *path,
- const char *host,
- const char *origin,
- const char *protocol,
- int ietf_version_or_minus_one, void *userdata)
-{
- return lws_client_connect_extended(clients, address, port, ssl_connection,
- path, host, origin, protocol, ietf_version_or_minus_one,
- userdata);
-}
-
-#undef libwebsocket_canonical_hostname
-LWS_VISIBLE LWS_EXTERN const char *
-libwebsocket_canonical_hostname(struct lws_context *context)
-{
- return lws_canonical_hostname(context);
-}
-
-#undef libwebsockets_get_peer_addresses
-LWS_VISIBLE LWS_EXTERN void
-libwebsockets_get_peer_addresses(struct lws_context *context,
- struct lws *wsi, lws_sockfd_type fd, char *name,
- int name_len, char *rip, int rip_len)
-{
- lws_get_peer_addresses(context, wsi, fd, name, name_len, rip, rip_len);
-}
-
-#undef libwebsockets_get_random
-LWS_VISIBLE LWS_EXTERN int
-libwebsockets_get_random(struct lws_context *context, void *buf, int len)
-{
- return lws_get_random(context, buf, len);
-}
-
-#ifndef LWS_SHA1_USE_OPENSSL_NAME
-#undef libwebsockets_SHA1
-LWS_VISIBLE LWS_EXTERN unsigned char *
-libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md)
-{
- return lws_SHA1(d, n, md);
-}
-#endif
-
-#undef libwebsocket_read
-LWS_VISIBLE LWS_EXTERN int
-libwebsocket_read(struct lws_context *context, struct lws *wsi,
- unsigned char *buf, size_t len)
-{
- return lws_read(context, wsi, buf, len);
-}
-
-#ifndef LWS_NO_EXTENSIONS
-#undef libwebsocket_get_internal_extensions
-LWS_VISIBLE LWS_EXTERN struct lws_extension *
-libwebsocket_get_internal_extensions()
-{
- return lws_get_internal_extensions();
-}
-#endif
-
-#endif
-
#ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
#define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
-/* old (pre 1.6) api name compatibility defines */
-
-#define libwebsocket_create_context lws_create_context
-#define libwebsocket_set_proxy lws_set_proxy
-#define libwebsocket_context_destroy lws_context_destroy
-#define libwebsocket_service lws_service
-#define libwebsocket_cancel_service lws_cancel_service
-#define libwebsocket_sigint_cfg lws_sigint_cfg
-#define libwebsocket_initloop lws_initloop
-#define libwebsocket_sigint_cb lws_sigint_cb
-#define libwebsocket_service_fd lws_service_fd
-#define libwebsocket_context_user lws_context_user
-#define libwebsocket_set_timeout lws_set_timeout
-#define libwebsocket_write lws_write
-#define libwebsockets_serve_http_file_fragment lws_serve_http_file_fragment
-#define libwebsockets_serve_http_file lws_serve_http_file
-#define libwebsockets_return_http_status lws_return_http_status
-#define libwebsockets_get_protocol lws_get_protocol
-#define libwebsocket_callback_on_writable_all_protocol lws_callback_on_writable_all_protocol
-#define libwebsocket_callback_on_writable lws_callback_on_writable
-#define libwebsocket_callback_all_protocol lws_callback_all_protocol
-#define libwebsocket_get_socket_fd lws_get_socket_fd
-#define libwebsocket_is_final_fragment lws_is_final_fragment
-#define libwebsocket_get_reserved_bits lws_get_reserved_bits
-#define libwebsocket_rx_flow_control lws_rx_flow_control
-#define libwebsocket_rx_flow_allow_all_protocol lws_rx_flow_allow_all_protocol
-#define libwebsockets_remaining_packet_payload lws_remaining_packet_payload
-#define libwebsocket_client_connect lws_client_connect
-#define libwebsocket_canonical_hostname lws_canonical_hostname
-#define libwebsockets_get_peer_addresses lws_get_peer_addresses
-#define libwebsockets_get_random lws_get_random
-#define libwebsockets_SHA1 lws_SHA1
-#define libwebsocket_read lws_read
-#define libwebsocket_get_internal_extensions lws_get_internal_extensions
-#define libwebsocket_write_protocol lws_write_protocol
-
-#define libwebsocket_protocols lws_protocols
-#define libwebsocket_extension lws_extension
-#define libwebsocket_context lws_context
-#define libwebsocket_pollfd lws_pollfd
-#define libwebsocket_callback_reasons lws_callback_reasons
-#define libwebsocket lws
-
#ifdef __cplusplus
#include <cstddef>
#include <cstdarg>
lws_token_to_string(enum lws_token_indexes token);
LWS_VISIBLE LWS_EXTERN int
-lws_add_http_header_by_name(struct lws_context *context,
- struct lws *wsi,
- const unsigned char *name,
- const unsigned char *value,
- int length,
- unsigned char **p,
- unsigned char *end);
+lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
+ const unsigned char *value, int length,
+ unsigned char **p, unsigned char *end);
LWS_VISIBLE LWS_EXTERN int
-lws_finalize_http_header(struct lws_context *context,
- struct lws *wsi,
- unsigned char **p,
+lws_finalize_http_header(struct lws *wsi, unsigned char **p,
unsigned char *end);
LWS_VISIBLE LWS_EXTERN int
-lws_add_http_header_by_token(struct lws_context *context,
- struct lws *wsi,
- enum lws_token_indexes token,
- const unsigned char *value,
- int length,
- unsigned char **p,
- unsigned char *end);
+lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
+ const unsigned char *value, int length,
+ unsigned char **p, unsigned char *end);
LWS_VISIBLE LWS_EXTERN int
-lws_add_http_header_content_length(struct lws_context *context,
- struct lws *wsi,
+lws_add_http_header_content_length(struct lws *wsi,
unsigned long content_length,
- unsigned char **p,
- unsigned char *end);
+ unsigned char **p, unsigned char *end);
LWS_VISIBLE LWS_EXTERN int
-lws_add_http_header_status(struct lws_context *context, struct lws *wsi,
+lws_add_http_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end);
lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
LWS_VISIBLE LWS_EXTERN int
-lws_serve_http_file(struct lws_context *context, struct lws *wsi,
- const char *file, const char *content_type,
+lws_serve_http_file(struct lws *wsi, const char *file, const char *content_type,
const char *other_headers, int other_headers_len);
LWS_VISIBLE LWS_EXTERN int
-lws_serve_http_file_fragment(struct lws_context *context, struct lws *wsi);
+lws_serve_http_file_fragment(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int
-lws_return_http_status(struct lws_context *context, struct lws *wsi,
- unsigned int code, const char *html_body);
+lws_return_http_status(struct lws *wsi, unsigned int code,
+ const char *html_body);
LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
lws_get_protocol(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int
-lws_callback_on_writable(const struct lws_context *context, struct lws *wsi);
+lws_callback_on_writable(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int
lws_callback_on_writable_all_protocol(const struct lws_context *context,
LWS_VISIBLE LWS_EXTERN void
-lws_get_peer_addresses(struct lws_context *context, struct lws *wsi,
+lws_get_peer_addresses(struct lws *wsi,
lws_sockfd_type fd, char *name, int name_len,
char *rip, int rip_len);
*/
LWS_VISIBLE LWS_EXTERN int
-lws_read(struct lws_context *context, struct lws *wsi,
- unsigned char *buf, size_t len);
+lws_read(struct lws *wsi, unsigned char *buf, size_t len);
#ifndef LWS_NO_EXTENSIONS
LWS_VISIBLE LWS_EXTERN struct lws_extension *lws_get_internal_extensions();
struct lws *wsi)
{
(void)wsi;
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_READ);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_READ);
context->fds[context->fds_count++].revents = 0;
}
lws_plat_insert_socket_into_fds(struct lws_context *context,
struct lws *wsi)
{
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_READ);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_READ);
context->fds[context->fds_count++].revents = 0;
}
}
}
/* always callback on writeable */
- lws_callback_on_writable(lws_get_ctx(wsi), wsi);
+ lws_callback_on_writable(wsi);
return n;
}
memcpy(wsi->truncated_send_malloc, buf + n, real_len - n);
/* since something buffered, force it to get another chance to send */
- lws_callback_on_writable(lws_get_ctx(wsi), wsi);
+ lws_callback_on_writable(wsi);
return real_len;
}
return n - (pre + post);
}
-LWS_VISIBLE int lws_serve_http_file_fragment(struct lws_context *context,
- struct lws *wsi)
+LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
{
+ struct lws_context *context = wsi->context;
unsigned long amount;
int n, m;
}
lwsl_info("choked before able to send whole file (post)\n");
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
return 0; /* indicates further processing must be done */
}
wsi->u.ws.ping_pending_flag = 1;
/* get it sent as soon as possible */
- lws_callback_on_writable(lws_get_ctx(wsi), wsi);
+ lws_callback_on_writable(wsi);
ping_drop:
wsi->u.ws.rx_user_buffer_head = 0;
return 0;
struct lws_pollargs pa = { wsi->sock, 0, 0 };
struct lws_context *context = wsi->context;
- lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_READ | LWS_EV_WRITE);
--context->fds_count;
*/
LWS_VISIBLE int
-lws_callback_on_writable(const struct lws_context *context, struct lws *wsi)
+lws_callback_on_writable(struct lws *wsi)
{
#ifdef LWS_USE_HTTP2
struct lws *network_wsi, *wsi2;
network_sock:
#endif
- (void)context;
if (lws_ext_callback_for_each_active(wsi,
LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, NULL, 0))
return 1;
if (lws_change_pollfd(wsi, 0, LWS_POLLOUT))
return -1;
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_WRITE);
return 1;
}
if (!wsi)
continue;
if (wsi->protocol == protocol)
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
}
return 0;
#define LWS_LIBEV_ENABLED(context) (context->options & LWS_SERVER_OPTION_LIBEV)
LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info);
LWS_EXTERN void
-lws_libev_accept(struct lws_context *context,
- struct lws *new_wsi, lws_sockfd_type accept_fd);
+lws_libev_accept(struct lws *new_wsi, lws_sockfd_type accept_fd);
LWS_EXTERN void
-lws_libev_io(const struct lws_context *context,
- struct lws *wsi, int flags);
+lws_libev_io(struct lws *wsi, int flags);
LWS_EXTERN int
lws_libev_init_fd_table(struct lws_context *context);
LWS_EXTERN void
#else
#define lws_feature_status_libev(_a)
#endif
-#define lws_libev_accept(_a, _b, _c) ((void) 0)
-#define lws_libev_io(_a, _b, _c) ((void) 0)
+#define lws_libev_accept(_a, _b) ((void) 0)
+#define lws_libev_io(_a, _b) ((void) 0)
#define lws_libev_init_fd_table(_a) (0)
#define lws_libev_run(_a) ((void) 0)
#endif
unsigned char *buf, int len);
LWS_EXTERN void lws_http2_init(struct http2_settings *settings);
LWS_EXTERN int
-lws_http2_parser(struct lws_context *context,
- struct lws *wsi, unsigned char c);
+lws_http2_parser(struct lws *wsi, unsigned char c);
LWS_EXTERN int lws_http2_do_pps_send(struct lws_context *context,
struct lws *wsi);
LWS_EXTERN int lws_http2_frame_write(struct lws *wsi, int type, int flags,
unsigned char *buf);
LWS_EXTERN struct lws *
lws_http2_wsi_from_id(struct lws *wsi, unsigned int sid);
-LWS_EXTERN int lws_hpack_interpret(struct lws_context *context,
- struct lws *wsi,
+LWS_EXTERN int lws_hpack_interpret(struct lws *wsi,
unsigned char c);
LWS_EXTERN int
-lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi,
+lws_add_http2_header_by_name(struct lws *wsi,
const unsigned char *name,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end);
LWS_EXTERN int
-lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi,
+lws_add_http2_header_by_token(struct lws *wsi,
enum lws_token_indexes token,
const unsigned char *value, int length,
unsigned char **p, unsigned char *end);
LWS_EXTERN int
-lws_add_http2_header_status(struct lws_context *context, struct lws *wsi,
+lws_add_http2_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end);
LWS_EXTERN
lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
LWS_EXTERN int
-lws_hdr_simple_create(struct lws *wsi,
- enum lws_token_indexes h, const char *s);
+lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s);
LWS_EXTERN int
lws_ensure_user_space(struct lws *wsi);
LWS_EXTERN int
_lws_rx_flow_control(struct lws *wsi);
LWS_EXTERN int
-lws_handshake_server(struct lws_context *context,
- struct lws *wsi, unsigned char **buf, size_t len);
+lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
#else
#define lws_server_socket_service(_a, _b, _c) (0)
#define _lws_rx_flow_control(_a) (0)
-#define lws_handshake_server(_a, _b, _c, _d) (0)
+#define lws_handshake_server(_a, _b, _c) (0)
#endif
LWS_EXTERN int
int
_lws_rx_flow_control(struct lws *wsi)
{
- struct lws_context *context = lws_get_ctx(wsi);
-
/* there is no pending change */
if (!(wsi->rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE))
return 0;
/* stuff is still buffered, not ready to really accept new input */
if (wsi->rxflow_buffer) {
/* get ourselves called back to deal with stashed buffer */
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
return 0;
}
if (lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_CONTENT_LENGTH)) {
lws_hdr_copy(wsi, content_length_str,
- sizeof(content_length_str) - 1,
- WSI_TOKEN_HTTP_CONTENT_LENGTH);
+ sizeof(content_length_str) - 1,
+ WSI_TOKEN_HTTP_CONTENT_LENGTH);
wsi->u.http.content_length = atoi(content_length_str);
}
}
-int lws_handshake_server(struct lws_context *context, struct lws *wsi,
- unsigned char **buf, size_t len)
+int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
{
+ struct lws_context *context = lws_get_ctx(wsi);
struct allocated_headers *ah;
int protocol_len, n, hit;
char protocol_list[128];
* hm this may want to send
* (via HTTP callback for example)
*/
- n = lws_read(context, wsi,
- context->service_buffer, len);
+ n = lws_read(wsi, context->service_buffer, len);
if (n < 0) /* we closed wsi */
return 1;
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
goto fail;
- lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
if (wsi->state != WSI_STATE_HTTP_ISSUING_FILE) {
n = user_callback_handle_rxflow(
}
/* >0 == completion, <0 == error */
- n = lws_serve_http_file_fragment(context, wsi);
+ n = lws_serve_http_file_fragment(wsi);
if (n < 0 || (n > 0 && lws_http_transaction_completed(wsi)))
goto fail;
break;
LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED,
NULL, NULL, 0);
- lws_libev_accept(context, new_wsi, accept_fd);
+ lws_libev_accept(new_wsi, accept_fd);
if (!LWS_SSL_ENABLED(context)) {
#if LWS_POSIX
* the wsi should be left alone.
*/
-LWS_VISIBLE int lws_serve_http_file(struct lws_context *context,
- struct lws *wsi, const char *file,
+LWS_VISIBLE int lws_serve_http_file(struct lws *wsi, const char *file,
const char *content_type,
const char *other_headers,
int other_headers_len)
{
+ struct lws_context *context = lws_get_ctx(wsi);
unsigned char *response = context->service_buffer +
LWS_SEND_BUFFER_PRE_PADDING;
unsigned char *p = response;
LWS_SEND_BUFFER_PRE_PADDING;
int ret = 0;
- wsi->u.http.fd = lws_plat_file_open(wsi, file,
- &wsi->u.http.filelen, O_RDONLY);
+ wsi->u.http.fd = lws_plat_file_open(wsi, file, &wsi->u.http.filelen, O_RDONLY);
if (wsi->u.http.fd == LWS_INVALID_FILE) {
lwsl_err("Unable to open '%s'\n", file);
- lws_return_http_status(context, wsi, HTTP_STATUS_NOT_FOUND,
- NULL);
+ lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL);
+
return -1;
}
- if (lws_add_http_header_status(context, wsi, 200, &p, end))
+ if (lws_add_http_header_status(wsi, 200, &p, end))
return -1;
- if (lws_add_http_header_by_token(context, wsi, WSI_TOKEN_HTTP_SERVER,
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
(unsigned char *)"libwebsockets", 13,
&p, end))
return -1;
- if (lws_add_http_header_by_token(context, wsi,
- WSI_TOKEN_HTTP_CONTENT_TYPE,
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_CONTENT_TYPE,
(unsigned char *)content_type,
strlen(content_type), &p, end))
return -1;
- if (lws_add_http_header_content_length(context, wsi,
- wsi->u.http.filelen, &p, end))
+ if (lws_add_http_header_content_length(wsi, wsi->u.http.filelen, &p, end))
return -1;
if (other_headers) {
p += other_headers_len;
}
- if (lws_finalize_http_header(context, wsi, &p, end))
+ if (lws_finalize_http_header(wsi, &p, end))
return -1;
ret = lws_write(wsi, response, p - response, LWS_WRITE_HTTP_HEADERS);
wsi->u.http.filepos = 0;
wsi->state = WSI_STATE_HTTP_ISSUING_FILE;
- return lws_serve_http_file_fragment(context, wsi);
+ return lws_serve_http_file_fragment(wsi);
}
int lws_interpret_incoming_packet(struct lws *wsi, unsigned char *buf,
if (pollfd) {
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) {
- lwsl_info("failled at set pollfd\n");
+ lwsl_info("failed at set pollfd\n");
return 1;
}
- lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
}
#ifdef LWS_USE_HTTP2
/* service incoming data */
if (eff_buf.token_len) {
- n = lws_read(context, wsi,
- (unsigned char *)eff_buf.token,
- eff_buf.token_len);
+ n = lws_read(wsi, (unsigned char *)eff_buf.token,
+ eff_buf.token_len);
if (n < 0) {
/* we closed wsi */
n = 0;
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0))
goto fail;
- lws_libev_io(context, wsi, LWS_EV_STOP | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_STOP | LWS_EV_WRITE);
lws_latency_pre(context, wsi);
if (lws_change_pollfd(wsi, 0, LWS_POLLIN))
goto fail;
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_READ);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_READ);
lwsl_info("SSL_ERROR_WANT_READ\n");
break;
if (lws_change_pollfd(wsi, 0, LWS_POLLOUT))
goto fail;
- lws_libev_io(context, wsi, LWS_EV_START | LWS_EV_WRITE);
+ lws_libev_io(wsi, LWS_EV_START | LWS_EV_WRITE);
break;
}
lwsl_debug("SSL_accept failed skt %u: %s\n",
/* use SHA1() not internal libwebsockets_SHA1 */
#cmakedefine LWS_SHA1_USE_OPENSSL_NAME
-/* whether to provide pre v1.6 compatibility wrappers */
-#cmakedefine LWS_WITH_OLD_API_WRAPPERS
-
${LWS_SIZEOFPTR_CODE}
* start the ball rolling,
* LWS_CALLBACK_CLIENT_WRITEABLE will come next service
*/
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
case LWS_CALLBACK_CLOSED:
return -1;
}
/* get notified as soon as we can write again */
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
default:
}
memcpy(&pss->buf[LWS_SEND_BUFFER_PRE_PADDING], in, len);
pss->len = (unsigned int)len;
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
#endif
fprintf(stderr, "server sees client connect\n");
psf->state = FRAGSTATE_START_MESSAGE;
/* start the ball rolling */
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
case LWS_CALLBACK_CLIENT_ESTABLISHED:
return -1;
}
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
case FRAGSTATE_POST_PAYLOAD_SUM:
psf->state = FRAGSTATE_START_MESSAGE;
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
}
break;
* LWS_CALLBACK_CLIENT_WRITEABLE will come next service
*/
- lws_callback_on_writable(this, wsi);
+ lws_callback_on_writable(wsi);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
}
}
- lws_get_peer_addresses(context, ping_wsi[0],
- lws_get_socket_fd(ping_wsi[0]),
+ lws_get_peer_addresses(ping_wsi[0], lws_get_socket_fd(ping_wsi[0]),
peer_name, sizeof peer_name, ip, sizeof ip);
fprintf(stderr, "Websocket PING %s (%s) %d bytes of data.\n",
if (!interrupted_time) {
if ((l - oldus) > interval_us) {
for (n = 0; n < clients; n++)
- lws_callback_on_writable(
- context, ping_wsi[n]);
+ lws_callback_on_writable(ping_wsi[n]);
oldus = l;
}
} else
}
if (len < 1) {
- lws_return_http_status(context, wsi,
+ lws_return_http_status(wsi,
HTTP_STATUS_BAD_REQUEST, NULL);
goto try_to_reuse;
}
/* this example server has no concept of directories */
if (strchr((const char *)in + 1, '/')) {
- lws_return_http_status(context, wsi,
- HTTP_STATUS_FORBIDDEN, NULL);
+ lws_return_http_status(wsi,
+ HTTP_STATUS_FORBIDDEN, NULL);
goto try_to_reuse;
}
* depending on what connection it happens to be working
* on
*/
- if (lws_add_http_header_status(context, wsi, 200, &p, end))
+ if (lws_add_http_header_status(wsi, 200, &p, end))
return 1;
- if (lws_add_http_header_by_token(context, wsi,
- WSI_TOKEN_HTTP_SERVER,
+ if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
(unsigned char *)"libwebsockets",
13, &p, end))
return 1;
- if (lws_add_http_header_by_token(context, wsi,
+ if (lws_add_http_header_by_token(wsi,
WSI_TOKEN_HTTP_CONTENT_TYPE,
(unsigned char *)"image/jpeg",
10, &p, end))
return 1;
- if (lws_add_http_header_content_length(context, wsi,
+ if (lws_add_http_header_content_length(wsi,
file_len, &p,
end))
return 1;
- if (lws_finalize_http_header(context, wsi, &p, end))
+ if (lws_finalize_http_header(wsi, &p, end))
return 1;
/*
/*
* book us a LWS_CALLBACK_HTTP_WRITEABLE callback
*/
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
}
mimetype = get_mimetype(buf);
if (!mimetype) {
lwsl_err("Unknown mimetype for %s\n", buf);
- lws_return_http_status(context, wsi,
+ lws_return_http_status(wsi,
HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, NULL);
return -1;
}
- /* demostrates how to set a cookie on / */
+ /* demonstrates how to set a cookie on / */
other_headers = NULL;
n = 0;
p = (unsigned char *)leaf_path;
- if (lws_add_http_header_by_name(context, wsi,
+ if (lws_add_http_header_by_name(wsi,
(unsigned char *)"set-cookie:",
(unsigned char *)b64, n, &p,
(unsigned char *)leaf_path + sizeof(leaf_path)))
other_headers = leaf_path;
}
- n = lws_serve_http_file(context, wsi, buf,
- mimetype, other_headers, n);
+ n = lws_serve_http_file(wsi, buf, mimetype, other_headers, n);
if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi)))
return -1; /* error or can't reuse connection: close the socket */
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION\n");
/* the whole of the sent body arrived, close or reuse the connection */
- lws_return_http_status(context, wsi,
- HTTP_STATUS_OK, NULL);
+ lws_return_http_status(wsi, HTTP_STATUS_OK, NULL);
goto try_to_reuse;
case LWS_CALLBACK_HTTP_FILE_COMPLETION:
} while (!lws_send_pipe_choked(wsi));
later:
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
flush_bail:
/* true if still partial pending */
if (lws_partial_buffered(wsi)) {
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
}
lws_plat_file_close(wsi, pss->fd);
lws_get_protocol(wsi));
if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
- lws_callback_on_writable(context, wsi);
+ lws_callback_on_writable(wsi);
break;
}
}