From 11c05bfa09a0d4a71588a6eb8d03aba5e1c48e59 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Wed, 16 Dec 2015 18:19:08 +0800 Subject: [PATCH] public api remove superfluous context params API BREAK Extend the cleanout caused by wsi having a context pointer into the public api. There's no point keeping the 1.5 compatibility work, we have changed the api in several places and rebuilt wasn't going to be enough a while ago. Signed-off-by: Andy Green --- CMakeLists.txt | 2 - README.coding.md | 12 +- changelog | 74 ++++++++-- lib/client-handshake.c | 4 +- lib/client-parser.c | 2 +- lib/client.c | 9 +- lib/extension.c | 3 +- lib/handshake.c | 13 +- lib/header.c | 43 +++--- lib/hpack.c | 19 ++- lib/http2.c | 8 +- lib/libev.c | 8 +- lib/libwebsockets.c | 284 +-------------------------------------- lib/libwebsockets.h | 91 +++---------- lib/lws-plat-mbed3.cpp | 2 +- lib/lws-plat-unix.c | 2 +- lib/output.c | 10 +- lib/parsers.c | 2 +- lib/pollfd.c | 9 +- lib/private-libwebsockets.h | 30 ++--- lib/server.c | 46 +++---- lib/service.c | 9 +- lib/ssl.c | 6 +- lws_config.h.in | 3 - test-server/test-client.c | 4 +- test-server/test-echo.c | 2 +- test-server/test-fraggle.c | 6 +- test-server/test-ping.c | 8 +- test-server/test-server-http.c | 35 +++-- test-server/test-server-mirror.c | 2 +- 30 files changed, 216 insertions(+), 532 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 829b1a8..6fd47a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,6 @@ option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON) 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) @@ -1100,7 +1099,6 @@ message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}") 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() diff --git a/README.coding.md b/README.coding.md index c2a5f3b..6026318 100644 --- a/README.coding.md +++ b/README.coding.md @@ -296,23 +296,23 @@ The user code can get a pointer to the file operations struct 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. diff --git a/changelog b/changelog index 6cf7d19..0c1a7e4 100644 --- a/changelog +++ b/changelog @@ -60,23 +60,73 @@ The reason for this change is struct lws_protocols has been changed to remove 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 diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 3876956..76807df 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -162,7 +162,7 @@ lws_client_connect_2(struct lws *wsi) 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; @@ -235,7 +235,7 @@ lws_client_connect_2(struct lws *wsi) */ 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; } diff --git a/lib/client-parser.c b/lib/client-parser.c index f8dafa3..f55c29f 100644 --- a/lib/client-parser.c +++ b/lib/client-parser.c @@ -326,7 +326,7 @@ spill: 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; diff --git a/lib/client.c b/lib/client.c index 040e378..1c771c8 100644 --- a/lib/client.c +++ b/lib/client.c @@ -123,7 +123,7 @@ int lws_client_socket_service(struct lws_context *context, */ 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 */ @@ -229,8 +229,7 @@ int lws_client_socket_service(struct lws_context *context, 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; @@ -291,7 +290,7 @@ some_wait: */ lwsl_info("SSL_connect WANT_WRITE... retrying\n"); - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); goto some_wait; } @@ -369,7 +368,7 @@ 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; } diff --git a/lib/extension.c b/lib/extension.c index 5f2ee46..8388da3 100644 --- a/lib/extension.c +++ b/lib/extension.c @@ -175,8 +175,7 @@ lws_issue_raw_ext_access(struct lws *wsi, * 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; } diff --git a/lib/handshake.c b/lib/handshake.c index c77e6ed..eee3bc6 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -58,8 +58,7 @@ */ 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; @@ -84,7 +83,7 @@ lws_read(struct lws_context *context, struct lws *wsi, unsigned char *buf, /* 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; @@ -105,7 +104,7 @@ http_new: 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; @@ -191,18 +190,18 @@ postbody_completion: } 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? */ diff --git a/lib/header.c b/lib/header.c index b2d7828..0e34518 100644 --- a/lib/header.c +++ b/lib/header.c @@ -31,18 +31,16 @@ const unsigned char *lws_token_to_string(enum lws_token_indexes token) } 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) @@ -62,10 +60,9 @@ lws_add_http_header_by_name(struct lws_context *context, struct lws *wsi, 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; @@ -81,24 +78,22 @@ int lws_finalize_http_header(struct lws_context *context, struct lws *wsi, } 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) { @@ -106,7 +101,7 @@ int lws_add_http_header_content_length(struct lws_context *context, 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; @@ -145,7 +140,7 @@ static const char *err500[] = { }; 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) { @@ -155,7 +150,7 @@ lws_add_http_header_status(struct lws_context *context, struct lws *wsi, #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]; @@ -164,7 +159,7 @@ lws_add_http_header_status(struct lws_context *context, struct lws *wsi, 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); } @@ -179,11 +174,10 @@ lws_add_http_header_status(struct lws_context *context, struct lws *wsi, * 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; @@ -193,18 +187,17 @@ lws_return_http_status(struct lws_context *context, struct lws *wsi, 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); diff --git a/lib/hpack.c b/lib/hpack.c index 88aa291..f311d70 100644 --- a/lib/hpack.c +++ b/lib/hpack.c @@ -349,8 +349,7 @@ static int lws_write_indexed_hdr(struct lws *wsi, int idx) 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; @@ -619,7 +618,7 @@ static int lws_http2_num(int starting_bits, unsigned long num, 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) @@ -654,8 +653,7 @@ int lws_add_http2_header_by_name(struct lws_context *context, struct lws *wsi, 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) { @@ -665,11 +663,10 @@ int lws_add_http2_header_by_token(struct lws_context *context, struct lws *wsi, 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) { @@ -679,9 +676,9 @@ int lws_add_http2_header_status(struct lws_context *context, struct lws *wsi, 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; diff --git a/lib/http2.c b/lib/http2.c index 0eb2d6a..72a6436 100644 --- a/lib/http2.c +++ b/lib/http2.c @@ -196,11 +196,11 @@ static const char * https_client_preface = "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: @@ -243,7 +243,7 @@ lws_http2_parser(struct lws_context *context, struct lws *wsi, unsigned char c) 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: @@ -313,7 +313,7 @@ lws_http2_parser(struct lws_context *context, struct lws *wsi, unsigned char c) 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; } diff --git a/lib/libev.c b/lib/libev.c index 433939c..d06ead7 100644 --- a/lib/libev.c +++ b/lib/libev.c @@ -133,9 +133,9 @@ lws_initloop( } 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; @@ -149,8 +149,10 @@ lws_libev_accept(struct lws_context *context, } 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; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index e0b8d52..b494dfb 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -92,7 +92,7 @@ lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason) 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); @@ -407,9 +407,8 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name, */ 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; @@ -417,6 +416,7 @@ lws_get_peer_addresses(struct lws_context *context, struct lws *wsi, struct sockaddr_in6 sin6; #endif struct sockaddr_in sin4; + struct lws_context *context = wsi->context; int ret = -1; void *p; @@ -446,7 +446,6 @@ lws_get_peer_addresses(struct lws_context *context, struct lws *wsi, bail: lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1); #else - (void)context; (void)wsi; (void)fd; (void)name; @@ -898,7 +897,7 @@ void lws_set_protocol_write_pending(struct lws *wsi, 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 @@ -943,276 +942,3 @@ lws_wsi_user(struct lws *wsi) { 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 - diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 33ef500..af71d29 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -22,49 +22,6 @@ #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 #include @@ -1356,34 +1313,22 @@ LWS_VISIBLE LWS_EXTERN const unsigned char * 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); @@ -1502,21 +1447,20 @@ lws_write(struct lws *wsi, unsigned char *buf, size_t len, 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, @@ -1582,7 +1526,7 @@ lws_canonical_hostname(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); @@ -1702,8 +1646,7 @@ lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount, */ 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(); diff --git a/lib/lws-plat-mbed3.cpp b/lib/lws-plat-mbed3.cpp index 66bef3d..e43b77d 100644 --- a/lib/lws-plat-mbed3.cpp +++ b/lib/lws-plat-mbed3.cpp @@ -229,7 +229,7 @@ lws_plat_insert_socket_into_fds(struct lws_context *context, 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; } diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index 91cf75c..ca9becb 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -383,7 +383,7 @@ LWS_VISIBLE void 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; } diff --git a/lib/output.c b/lib/output.c index 70be3c6..2e46e7a 100644 --- a/lib/output.c +++ b/lib/output.c @@ -157,7 +157,7 @@ handle_truncated_send: } } /* always callback on writeable */ - lws_callback_on_writable(lws_get_ctx(wsi), wsi); + lws_callback_on_writable(wsi); return n; } @@ -205,7 +205,7 @@ handle_truncated_send: 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; } @@ -505,9 +505,9 @@ send_raw: 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; @@ -570,7 +570,7 @@ all_sent: } 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 */ } diff --git a/lib/parsers.c b/lib/parsers.c index 736aeed..c80b29a 100644 --- a/lib/parsers.c +++ b/lib/parsers.c @@ -956,7 +956,7 @@ process_as_ping: 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; diff --git a/lib/pollfd.c b/lib/pollfd.c index a4e6881..d41e834 100644 --- a/lib/pollfd.c +++ b/lib/pollfd.c @@ -76,7 +76,7 @@ remove_wsi_socket_from_fds(struct lws *wsi) 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; @@ -208,7 +208,7 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or) */ 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; @@ -257,7 +257,6 @@ lws_callback_on_writable(const struct lws_context *context, struct lws *wsi) network_sock: #endif - (void)context; if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, NULL, 0)) return 1; @@ -270,7 +269,7 @@ network_sock: 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; } @@ -296,7 +295,7 @@ lws_callback_on_writable_all_protocol(const struct lws_context *context, if (!wsi) continue; if (wsi->protocol == protocol) - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); } return 0; diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 778dd2f..795c277 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -547,11 +547,9 @@ enum { #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 @@ -564,8 +562,8 @@ lws_libev_run(const struct lws_context *context); #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 @@ -1048,8 +1046,7 @@ lws_http2_interpret_settings_payload(struct http2_settings *settings, 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, @@ -1057,21 +1054,20 @@ 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 @@ -1093,8 +1089,7 @@ LWS_EXTERN char * 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); @@ -1222,12 +1217,11 @@ lws_server_socket_service(struct lws_context *context, 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 diff --git a/lib/server.c b/lib/server.c index 0fe82ee..f60da78 100644 --- a/lib/server.c +++ b/lib/server.c @@ -152,8 +152,6 @@ int lws_context_init_server(struct lws_context_creation_info *info, 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; @@ -161,7 +159,7 @@ _lws_rx_flow_control(struct lws *wsi) /* 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; } @@ -256,8 +254,8 @@ int lws_http_action(struct lws *wsi) 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); } @@ -339,9 +337,9 @@ bail_nuke_ah: } -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]; @@ -745,8 +743,7 @@ int lws_server_socket_service(struct lws_context *context, * 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; @@ -766,7 +763,7 @@ try_pollout: 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( @@ -782,7 +779,7 @@ try_pollout: } /* >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; @@ -858,7 +855,7 @@ try_pollout: 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 @@ -902,12 +899,12 @@ fail: * 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; @@ -915,29 +912,26 @@ LWS_VISIBLE int lws_serve_http_file(struct lws_context *context, 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) { @@ -947,7 +941,7 @@ LWS_VISIBLE int lws_serve_http_file(struct lws_context *context, 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); @@ -959,7 +953,7 @@ LWS_VISIBLE int lws_serve_http_file(struct lws_context *context, 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, diff --git a/lib/service.c b/lib/service.c index de3fa67..e924c6d 100644 --- a/lib/service.c +++ b/lib/service.c @@ -212,11 +212,11 @@ user_service: 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 @@ -577,9 +577,8 @@ drain: /* 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; diff --git a/lib/ssl.c b/lib/ssl.c index 8f05360..638c5b9 100644 --- a/lib/ssl.c +++ b/lib/ssl.c @@ -610,7 +610,7 @@ lws_server_socket_service_ssl(struct lws **pwsi, struct lws *new_wsi, 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); @@ -678,7 +678,7 @@ go_again: 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; @@ -687,7 +687,7 @@ go_again: 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", diff --git a/lws_config.h.in b/lws_config.h.in index df2e043..c5f19a8 100644 --- a/lws_config.h.in +++ b/lws_config.h.in @@ -68,7 +68,4 @@ /* 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} diff --git a/test-server/test-client.c b/test-server/test-client.c index b36d93d..77be412 100644 --- a/test-server/test-client.c +++ b/test-server/test-client.c @@ -167,7 +167,7 @@ callback_lws_mirror(struct lws_context *context, * 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: @@ -201,7 +201,7 @@ callback_lws_mirror(struct lws_context *context, return -1; } /* get notified as soon as we can write again */ - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); break; default: diff --git a/test-server/test-echo.c b/test-server/test-echo.c index 8fbd9b2..a850ec2 100644 --- a/test-server/test-echo.c +++ b/test-server/test-echo.c @@ -87,7 +87,7 @@ do_rx: } 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 diff --git a/test-server/test-fraggle.c b/test-server/test-fraggle.c index 9a3f492..4a1bf39 100644 --- a/test-server/test-fraggle.c +++ b/test-server/test-fraggle.c @@ -76,7 +76,7 @@ callback_fraggle(struct lws_context *context, 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: @@ -177,7 +177,7 @@ callback_fraggle(struct lws_context *context, return -1; } - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); break; case FRAGSTATE_POST_PAYLOAD_SUM: @@ -202,7 +202,7 @@ callback_fraggle(struct lws_context *context, psf->state = FRAGSTATE_START_MESSAGE; - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); break; } break; diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 8bba9f0..2dd284e 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -144,7 +144,7 @@ callback_lws_mirror(struct lws_context * this, * 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: @@ -451,8 +451,7 @@ int main(int argc, char **argv) } } - 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", @@ -487,8 +486,7 @@ int main(int argc, char **argv) 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 diff --git a/test-server/test-server-http.c b/test-server/test-server-http.c index 52b0b0f..6f7e4d1 100644 --- a/test-server/test-server-http.c +++ b/test-server/test-server-http.c @@ -150,15 +150,15 @@ int callback_http(struct lws_context *context, struct lws *wsi, } 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; } @@ -194,23 +194,22 @@ int callback_http(struct lws_context *context, struct lws *wsi, * 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; /* @@ -235,7 +234,7 @@ int callback_http(struct lws_context *context, struct lws *wsi, /* * book us a LWS_CALLBACK_HTTP_WRITEABLE callback */ - lws_callback_on_writable(context, wsi); + lws_callback_on_writable(wsi); break; } @@ -253,12 +252,12 @@ int callback_http(struct lws_context *context, struct lws *wsi, 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; @@ -272,7 +271,7 @@ int callback_http(struct lws_context *context, struct lws *wsi, 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))) @@ -281,8 +280,7 @@ int callback_http(struct lws_context *context, struct lws *wsi, 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 */ @@ -308,8 +306,7 @@ int callback_http(struct lws_context *context, struct lws *wsi, 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: @@ -379,12 +376,12 @@ int callback_http(struct lws_context *context, struct lws *wsi, } 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); diff --git a/test-server/test-server-mirror.c b/test-server/test-server-mirror.c index d577830..dfe16d9 100644 --- a/test-server/test-server-mirror.c +++ b/test-server/test-server-mirror.c @@ -86,7 +86,7 @@ callback_lws_mirror(struct lws_context *context, 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; } } -- 2.7.4