diff --git a/CMakeLists.txt b/CMakeLists.txt index f297c58b..4df0dfbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -273,6 +273,18 @@ if (NOT LWS_WITHOUT_CLIENT) ) endif() +# select the active platform files + +if (WIN32) + list(APPEND SOURCES + lib/lws-plat-win.c + ) +else() + list(APPEND SOURCES + lib/lws-plat-unix.c + ) +endif() + if (NOT LWS_WITHOUT_SERVER) list(APPEND SOURCES lib/server.c diff --git a/lib/extension.c b/lib/extension.c index 0003fe9a..19d68cb5 100644 --- a/lib/extension.c +++ b/lib/extension.c @@ -53,8 +53,8 @@ int lws_ext_callback_for_each_active(struct libwebsocket *wsi, int reason, wsi->active_extensions[n]->name, reason); return -1; } - if (m) - handled = 1; + if (m > handled) + handled = m; } return handled; @@ -194,24 +194,3 @@ lws_any_extension_handled(struct libwebsocket_context *context, return handled; } - - -void * -lws_get_extension_user_matching_ext(struct libwebsocket *wsi, - struct libwebsocket_extension *ext) -{ - int n = 0; - - if (wsi == NULL) - return NULL; - - while (n < wsi->count_active_extensions) { - if (wsi->active_extensions[n] != ext) { - n++; - continue; - } - return wsi->active_extensions_user[n]; - } - - return NULL; -} diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index c28c8a7f..d537aa4e 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -21,28 +21,6 @@ #include "private-libwebsockets.h" -#if defined(WIN32) || defined(_WIN32) -#include -#include -#ifdef _WIN32_WCE -#define vsnprintf _vsnprintf -#endif -#else -#ifdef LWS_BUILTIN_GETIFADDRS -#include -#else -#include -#endif -#include -#include -#include -#include -#endif - -#ifdef HAVE_SYS_TYPES_H -#include -#endif - #ifdef LWS_OPENSSL_SUPPORT int openssl_websocket_private_data_index; #endif @@ -55,6 +33,24 @@ static int log_level = LLL_ERR | LLL_WARN | LLL_NOTICE; static void lwsl_emit_stderr(int level, const char *line); static void (*lwsl_emit)(int level, const char *line) = lwsl_emit_stderr; +void lws_plat_delete_socket_from_fds(struct libwebsocket_context *context, + struct libwebsocket *wsi, int m); +void lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, + struct libwebsocket *wsi); +void lws_plat_service_periodic(struct libwebsocket_context *context); + +int lws_plat_change_pollfd(struct libwebsocket_context *context, + struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd); +int lws_plat_context_early_init(void); +void lws_plat_context_early_destroy(struct libwebsocket_context *context); +void lws_plat_context_late_destroy(struct libwebsocket_context *context); +int lws_poll_listen_fd(struct libwebsocket_pollfd *fd); +int +lws_plat_service(struct libwebsocket_context *context, int timeout_ms); +int lws_plat_init_fd_tables(struct libwebsocket_context *context); +void lws_plat_drop_app_privileges(struct lws_context_creation_info *info); +unsigned long long time_in_microseconds(void); + #ifdef LWS_USE_LIBEV #define _LWS_EV_TAG " libev" #else @@ -87,22 +83,6 @@ static const char * const log_level_names[] = { struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd); #endif -/* - * This is just used to interrupt poll waiting - * we don't have to do anything with it. - */ -#ifdef LWS_OPENSSL_SUPPORT -static void lws_sigusr2(int sig) -{ -} -#endif - -#if defined(WIN32) || defined(_WIN32) -#include "lws-plat-win.c" -#else -#include "lws-plat-unix.c" -#endif - /** * lws_get_library_version: get version and git hash library built from * @@ -234,16 +214,11 @@ void libwebsocket_close_and_free_session(struct libwebsocket_context *context, struct libwebsocket *wsi, enum lws_close_status reason) { - int n; + int n, m, ret; int old_state; unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 + LWS_SEND_BUFFER_POST_PADDING]; -#ifndef LWS_NO_EXTENSIONS - int ret; - int m; struct lws_tokens eff_buf; - struct libwebsocket_extension *ext; -#endif if (!wsi) return; @@ -283,30 +258,15 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, } } -#ifndef LWS_NO_EXTENSIONS /* * are his extensions okay with him closing? Eg he might be a mux * parent and just his ch1 aspect is closing? */ - - for (n = 0; n < wsi->count_active_extensions; n++) { - if (!wsi->active_extensions[n]->callback) - continue; - - m = wsi->active_extensions[n]->callback(context, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, - wsi->active_extensions_user[n], NULL, 0); - - /* - * if somebody vetoed actually closing him at this time.... - * up to the extension to track the attempted close, let's - * just bail - */ - if (m) { - lwsl_ext("extension vetoed close\n"); - return; - } + + if (lws_ext_callback_for_each_active(wsi, + LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, NULL, 0) > 0) { + lwsl_ext("extension vetoed close\n"); + return; } /* @@ -314,34 +274,25 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, * if there are problems with send, just nuke the connection */ - ret = 1; - while (ret == 1) { - - /* default to nobody has more to spill */ - + do { ret = 0; eff_buf.token = NULL; eff_buf.token_len = 0; /* show every extension the new incoming data */ - for (n = 0; n < wsi->count_active_extensions; n++) { - m = wsi->active_extensions[n]->callback( - wsi->protocol->owning_server, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_FLUSH_PENDING_TX, - wsi->active_extensions_user[n], &eff_buf, 0); - if (m < 0) { - lwsl_ext("Extension reports fatal error\n"); - goto just_kill_connection; - } - if (m) - /* - * at least one extension told us he has more - * to spill, so we will go around again after - */ - ret = 1; + m = lws_ext_callback_for_each_active(wsi, + LWS_EXT_CALLBACK_FLUSH_PENDING_TX, &eff_buf, 0); + if (m < 0) { + lwsl_ext("Extension reports fatal error\n"); + goto just_kill_connection; } + if (m) + /* + * at least one extension told us he has more + * to spill, so we will go around again after + */ + ret = 1; /* assuming they left us something to send, send it */ @@ -351,8 +302,7 @@ libwebsocket_close_and_free_session(struct libwebsocket_context *context, lwsl_debug("close: ext spill failed\n"); goto just_kill_connection; } - } -#endif + } while (ret); /* * signal we are closing, libsocket_write will @@ -451,34 +401,21 @@ just_kill_connection: } else lwsl_debug("not calling back closed\n"); -#ifndef LWS_NO_EXTENSIONS /* deallocate any active extension contexts */ - - for (n = 0; n < wsi->count_active_extensions; n++) { - if (!wsi->active_extensions[n]->callback) - continue; - - wsi->active_extensions[n]->callback(context, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_DESTROY, - wsi->active_extensions_user[n], NULL, 0); - + + if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_DESTROY, NULL, 0) < 0) + lwsl_warn("extension destruction failed\n"); +#ifndef LWS_NO_EXTENSIONS + for (n = 0; n < wsi->count_active_extensions; n++) free(wsi->active_extensions_user[n]); - } - +#endif /* * inform all extensions in case they tracked this guy out of band * even though not active on him specifically */ - - ext = context->extensions; - while (ext && ext->callback) { - ext->callback(context, ext, wsi, - LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, - NULL, NULL, 0); - ext++; - } -#endif + if (lws_ext_callback_for_each_extension_type(context, wsi, + LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING, NULL, 0) < 0) + lwsl_warn("ext destroy wsi failed\n"); /* lwsl_info("closing fd=%d\n", wsi->sock); */ @@ -640,13 +577,10 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context, struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd) { int n; - -#ifndef LWS_NO_EXTENSIONS struct lws_tokens eff_buf; int ret; int m; int handled = 0; -#endif /* pending truncated sends have uber priority */ @@ -658,25 +592,14 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context, return 0; } -#ifndef LWS_NO_EXTENSIONS - for (n = 0; n < wsi->count_active_extensions; n++) { - if (!wsi->active_extensions[n]->callback) - continue; - - m = wsi->active_extensions[n]->callback(context, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_IS_WRITEABLE, - wsi->active_extensions_user[n], NULL, 0); - if (m > handled) - handled = m; - } - + m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE, + NULL, 0); if (handled == 1) goto notify_action; - +#ifndef LWS_NO_EXTENSIONS if (!wsi->extension_data_pending || handled == 2) goto user_service; - +#endif /* * check in on the active extensions, see if they * had pending stuff to spill... they need to get the @@ -695,24 +618,20 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context, eff_buf.token_len = 0; /* give every extension a chance to spill */ - - for (n = 0; n < wsi->count_active_extensions; n++) { - m = wsi->active_extensions[n]->callback( - wsi->protocol->owning_server, - wsi->active_extensions[n], wsi, + + m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_PACKET_TX_PRESEND, - wsi->active_extensions_user[n], &eff_buf, 0); - if (m < 0) { - lwsl_err("ext reports fatal error\n"); - return -1; - } - if (m) - /* - * at least one extension told us he has more - * to spill, so we will go around again after - */ - ret = 1; + &eff_buf, 0); + if (m < 0) { + lwsl_err("ext reports fatal error\n"); + return -1; } + if (m) + /* + * at least one extension told us he has more + * to spill, so we will go around again after + */ + ret = 1; /* assuming they gave us something to send, send it */ @@ -757,7 +676,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context, return 0; } - +#ifndef LWS_NO_EXTENSIONS wsi->extension_data_pending = 0; user_service: @@ -773,10 +692,8 @@ user_service: (struct ev_io *)&wsi->w_write); #endif /* LWS_USE_LIBEV */ } -#ifndef LWS_NO_EXTENSIONS -notify_action: -#endif +notify_action: if (wsi->mode == LWS_CONNMODE_WS_CLIENT) n = LWS_CALLBACK_CLIENT_WRITEABLE; else @@ -793,20 +710,12 @@ int libwebsocket_service_timeout_check(struct libwebsocket_context *context, struct libwebsocket *wsi, unsigned int sec) { -#ifndef LWS_NO_EXTENSIONS - int n; - /* * if extensions want in on it (eg, we are a mux parent) * give them a chance to service child timeouts */ - - for (n = 0; n < wsi->count_active_extensions; n++) - wsi->active_extensions[n]->callback( - context, wsi->active_extensions[n], - wsi, LWS_EXT_CALLBACK_1HZ, - wsi->active_extensions_user[n], NULL, sec); -#endif + if (lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_1HZ, NULL, sec) < 0) + return 0; if (!wsi->pending_timeout) return 0; @@ -815,11 +724,10 @@ libwebsocket_service_timeout_check(struct libwebsocket_context *context, * if we went beyond the allowed time, kill the * connection */ - if (sec > wsi->pending_timeout_limit) { lwsl_info("TIMEDOUT WAITING\n"); libwebsocket_close_and_free_session(context, - wsi, LWS_CLOSE_STATUS_NOSTATUS); + wsi, LWS_CLOSE_STATUS_NOSTATUS); return 1; } @@ -861,10 +769,7 @@ libwebsocket_service_fd(struct libwebsocket_context *context, int timed_out = 0; int our_fd = 0; char draining_flow = 0; - -#ifndef LWS_NO_EXTENSIONS - int more = 1; -#endif + int more; struct lws_tokens eff_buf; if (context->listen_service_fd) @@ -1065,27 +970,18 @@ read_pending: eff_buf.token = (char *)context->service_buffer; drain: -#ifndef LWS_NO_EXTENSIONS - more = 1; - while (more) { + + do { more = 0; + + m = lws_ext_callback_for_each_active(wsi, + LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, &eff_buf, 0); + if (m < 0) + goto close_and_handled; + if (m) + more = 1; - for (n = 0; n < wsi->count_active_extensions; n++) { - m = wsi->active_extensions[n]->callback(context, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_PACKET_RX_PREPARSE, - wsi->active_extensions_user[n], - &eff_buf, 0); - if (m < 0) { - lwsl_ext( - "Extension reports fatal error\n"); - goto close_and_handled; - } - if (m) - more = 1; - } -#endif /* service incoming data */ if (eff_buf.token_len) { @@ -1098,11 +994,11 @@ drain: goto handled; } } -#ifndef LWS_NO_EXTENSIONS + eff_buf.token = NULL; eff_buf.token_len = 0; - } -#endif + } while (more); + if (draining_flow && wsi->u.ws.rxflow_buffer && wsi->u.ws.rxflow_pos == wsi->u.ws.rxflow_len) { lwsl_info("flow buffer: drained\n"); @@ -1152,10 +1048,6 @@ LWS_VISIBLE void libwebsocket_context_destroy(struct libwebsocket_context *context) { int n; -#ifndef LWS_NO_EXTENSIONS - int m; - struct libwebsocket_extension *ext; -#endif /* ndef LWS_NO_EXTENSIONS */ struct libwebsocket_protocols *protocol = context->protocols; #ifdef LWS_LATENCY @@ -1173,23 +1065,16 @@ libwebsocket_context_destroy(struct libwebsocket_context *context) n--; } -#ifndef LWS_NO_EXTENSIONS /* * give all extensions a chance to clean up any per-context * allocations they might have made */ - - ext = context->extensions; - m = LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT; - if (context->listen_port) - m = LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT; - while (ext && ext->callback) { - ext->callback(context, ext, NULL, - (enum libwebsocket_extension_callback_reasons)m, - NULL, NULL, 0); - ext++; - } -#endif /* ndef LWS_NO_EXTENSIONS */ + if (context->listen_port) { + if (lws_ext_callback_for_each_extension_type(context, NULL, LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, NULL, 0) < 0) + return; + } else + if (lws_ext_callback_for_each_extension_type(context, NULL, LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, NULL, 0) < 0) + return; /* * inform all the protocols that they are done and will have no more @@ -1344,25 +1229,10 @@ LWS_VISIBLE int libwebsocket_callback_on_writable(struct libwebsocket_context *context, struct libwebsocket *wsi) { -#ifndef LWS_NO_EXTENSIONS - int n; - int handled = 0; - - /* maybe an extension will take care of it for us */ - - for (n = 0; n < wsi->count_active_extensions; n++) { - if (!wsi->active_extensions[n]->callback) - continue; - - handled |= wsi->active_extensions[n]->callback(context, - wsi->active_extensions[n], wsi, - LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, - wsi->active_extensions_user[n], NULL, 0); - } - - if (handled) + if (lws_ext_callback_for_each_active(wsi, + LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE, NULL, 0)) return 1; -#endif + if (wsi->position_in_fds_table < 0) { lwsl_err("%s: failed to find socket %d\n", __func__, wsi->sock); return -1; @@ -1715,10 +1585,6 @@ libwebsocket_create_context(struct lws_context_creation_info *info) struct sockaddr_in serv_addr4; struct sockaddr *v; #endif -#ifndef LWS_NO_EXTENSIONS - int m; - struct libwebsocket_extension *ext; -#endif #ifdef LWS_OPENSSL_SUPPORT SSL_METHOD *method; @@ -2212,9 +2078,6 @@ libwebsocket_create_context(struct lws_context_creation_info *info) } memset(wsi, 0, sizeof(struct libwebsocket)); wsi->sock = sockfd; -#ifndef LWS_NO_EXTENSIONS - wsi->count_active_extensions = 0; -#endif wsi->mode = LWS_CONNMODE_SERVER_LISTENER; insert_wsi_socket_into_fds(context, wsi); @@ -2257,27 +2120,21 @@ libwebsocket_create_context(struct lws_context_creation_info *info) NULL, LWS_CALLBACK_PROTOCOL_INIT, NULL, NULL, 0); } -#ifndef LWS_NO_EXTENSIONS /* * give all extensions a chance to create any per-context * allocations they need */ - m = LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT; - if (info->port != CONTEXT_PORT_NO_LISTEN) - m = LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT; - - if (info->extensions) { - ext = info->extensions; - while (ext->callback) { - lwsl_ext(" Extension: %s\n", ext->name); - ext->callback(context, ext, NULL, - (enum libwebsocket_extension_callback_reasons)m, - NULL, NULL, 0); - ext++; - } - } -#endif + if (info->port != CONTEXT_PORT_NO_LISTEN) { + if (lws_ext_callback_for_each_extension_type(context, NULL, + LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, + NULL, 0) < 0) + goto bail; + } else + if (lws_ext_callback_for_each_extension_type(context, NULL, + LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT, + NULL, 0) < 0) + goto bail; return context; diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index 70b73c54..2c8fd9d6 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -1,8 +1,10 @@ +#include "private-libwebsockets.h" + /* * included from libwebsockets.c for unix builds */ -static unsigned long long time_in_microseconds(void) +unsigned long long time_in_microseconds(void) { struct timeval tv; gettimeofday(&tv, NULL); @@ -38,11 +40,21 @@ LWS_VISIBLE int lws_send_pipe_choked(struct libwebsocket *wsi) return 0; } -static int lws_poll_listen_fd(struct libwebsocket_pollfd *fd) +LWS_VISIBLE int +lws_poll_listen_fd(struct libwebsocket_pollfd *fd) { return poll(fd, 1, 0); } +/* + * This is just used to interrupt poll waiting + * we don't have to do anything with it. + */ +#ifdef LWS_OPENSSL_SUPPORT +static void lws_sigusr2(int sig) +{ +} +#endif #ifdef LWS_USE_LIBEV LWS_VISIBLE void @@ -224,7 +236,8 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms) return 0; } -int lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) +LWS_VISIBLE int +lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) { int optval = 1; socklen_t optlen = sizeof(optval); @@ -280,7 +293,8 @@ int lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) return 0; } -static void lws_plat_drop_app_privileges(struct lws_context_creation_info *info) +LWS_VISIBLE void +lws_plat_drop_app_privileges(struct lws_context_creation_info *info) { if (info->gid != -1) if (setgid(info->gid)) @@ -290,7 +304,8 @@ static void lws_plat_drop_app_privileges(struct lws_context_creation_info *info) lwsl_warn("setuid: %s\n", strerror(LWS_ERRNO)); } -static int lws_plat_init_fd_tables(struct libwebsocket_context *context) +LWS_VISIBLE int +lws_plat_init_fd_tables(struct libwebsocket_context *context) { #ifdef LWS_USE_LIBEV if (LWS_LIBEV_ENABLED(context)) { @@ -325,7 +340,8 @@ static void sigpipe_handler(int x) } -static int lws_plat_context_early_init(void) +LWS_VISIBLE int +lws_plat_context_early_init(void) { sigset_t mask; @@ -340,11 +356,13 @@ static int lws_plat_context_early_init(void) return 0; } -static void lws_plat_context_early_destroy(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_context_early_destroy(struct libwebsocket_context *context) { } -static void lws_plat_context_late_destroy(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_context_late_destroy(struct libwebsocket_context *context) { close(context->dummy_pipe_fds[0]); close(context->dummy_pipe_fds[1]); @@ -353,7 +371,7 @@ static void lws_plat_context_late_destroy(struct libwebsocket_context *context) /* cast a struct sockaddr_in6 * into addr for ipv6 */ -int +LWS_VISIBLE int interface_to_sa(struct libwebsocket_context *context, const char *ifname, struct sockaddr_in *addr, size_t addrlen) { @@ -413,7 +431,8 @@ interface_to_sa(struct libwebsocket_context *context, return rc; } -void lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, +LWS_VISIBLE void +lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, struct libwebsocket *wsi) { #ifdef LWS_USE_LIBEV @@ -423,12 +442,14 @@ void lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, context->fds[context->fds_count++].revents = 0; } -void lws_plat_delete_socket_from_fds(struct libwebsocket_context *context, +LWS_VISIBLE void +lws_plat_delete_socket_from_fds(struct libwebsocket_context *context, struct libwebsocket *wsi, int m) { } -static void lws_plat_service_periodic(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_service_periodic(struct libwebsocket_context *context) { /* if our parent went down, don't linger around */ if (context->started_with_parent && @@ -436,13 +457,15 @@ static void lws_plat_service_periodic(struct libwebsocket_context *context) kill(getpid(), SIGTERM); } -static int lws_plat_change_pollfd(struct libwebsocket_context *context, +LWS_VISIBLE int +lws_plat_change_pollfd(struct libwebsocket_context *context, struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd) { return 0; } -int lws_plat_open_file(const char* filename, unsigned long* filelen) +LWS_VISIBLE int +lws_plat_open_file(const char* filename, unsigned long* filelen) { struct stat stat_buf; int ret = open(filename, O_RDONLY); diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index 2ec4e3cc..c9d7b4bd 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -1,4 +1,6 @@ -static unsigned long long +#include "private-libwebsockets.h" + +unsigned long long time_in_microseconds() { #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL @@ -23,7 +25,7 @@ time_in_microseconds() } #ifdef _WIN32_WCE -static inline time_t time(time_t *t) +time_t time(time_t *t) { time_t ret = time_in_microseconds() / 1000000; *t = ret; @@ -146,7 +148,8 @@ lws_plat_service(struct libwebsocket_context *context, int timeout_ms) return libwebsocket_service_fd(context, pfd); } -int lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) +LWS_VISIBLE int +lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) { int optval = 1; socklen_t optlen = sizeof(optval); @@ -181,11 +184,13 @@ int lws_plat_set_socket_options(struct libwebsocket_context *context, int fd) return 0; } -static void lws_plat_drop_app_privileges(struct lws_context_creation_info *info) +LWS_VISIBLE void +lws_plat_drop_app_privileges(struct lws_context_creation_info *info) { } -static int lws_plat_init_fd_tables(struct libwebsocket_context *context) +LWS_VISIBLE int +lws_plat_init_fd_tables(struct libwebsocket_context *context) { context->events = (WSAEVENT *)malloc(sizeof(WSAEVENT) * (context->max_fds + 1)); @@ -203,7 +208,8 @@ static int lws_plat_init_fd_tables(struct libwebsocket_context *context) return 0; } -static int lws_plat_context_early_init(void) +LWS_VISIBLE int +lws_plat_context_early_init(void) { WORD wVersionRequested; WSADATA wsaData; @@ -224,7 +230,8 @@ static int lws_plat_context_early_init(void) return 1; } -static void lws_plat_context_early_destroy(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_context_early_destroy(struct libwebsocket_context *context) { if (context->events) { WSACloseEvent(context->events[0]); @@ -232,19 +239,21 @@ static void lws_plat_context_early_destroy(struct libwebsocket_context *context) } } -static void lws_plat_context_late_destroy(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_context_late_destroy(struct libwebsocket_context *context) { WSACleanup(); } -int +LWS_VISIBLE int interface_to_sa(struct libwebsocket_context *context, const char *ifname, struct sockaddr_in *addr, size_t addrlen) { return -1; } -void lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, +LWS_VISIBLE void +lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, struct libwebsocket *wsi) { context->fds[context->fds_count++].revents = 0; @@ -252,18 +261,21 @@ void lws_plat_insert_socket_into_fds(struct libwebsocket_context *context, WSAEventSelect(wsi->sock, context->events[context->fds_count], LWS_POLLIN); } -static void lws_plat_delete_socket_from_fds(struct libwebsocket_context *context, +LWS_VISIBLE void +lws_plat_delete_socket_from_fds(struct libwebsocket_context *context, struct libwebsocket *wsi, int m) { WSACloseEvent(context->events[m + 1]); context->events[m + 1] = context->events[context->fds_count + 1]; } -static void lws_plat_service_periodic(struct libwebsocket_context *context) +LWS_VISIBLE void +lws_plat_service_periodic(struct libwebsocket_context *context) { } -static int lws_plat_change_pollfd(struct libwebsocket_context *context, +LWS_VISIBLE int +lws_plat_change_pollfd(struct libwebsocket_context *context, struct libwebsocket *wsi, struct libwebsocket_pollfd *pfd) { long networkevents = LWS_POLLOUT | LWS_POLLHUP; @@ -281,7 +293,8 @@ static int lws_plat_change_pollfd(struct libwebsocket_context *context, return 1; } -HANDLE lws_plat_open_file(const char* filename, unsigned long* filelen) +LWS_VISIBLE HANDLE +lws_plat_open_file(const char* filename, unsigned long* filelen) { HANDLE ret; WCHAR buffer[MAX_PATH]; diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 9458d6d6..1a58dd88 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -26,17 +26,19 @@ #if defined(WIN32) || defined(_WIN32) #define inline __inline #include -#else +#include +#ifdef _WIN32_WCE +#define vsnprintf _vsnprintf +#endif + +#else /* not WIN32 */ #include "config.h" -#ifdef LWS_BUILTIN_GETIFADDRS -#include -#else -#include -#endif -#include -#include -#include -#endif + +#endif /* not WIN32 */ +#endif /* not CMAKE */ + +#ifdef HAVE_SYS_TYPES_H +#include #endif #include @@ -90,6 +92,15 @@ #include #include #include +#ifdef LWS_BUILTIN_GETIFADDRS + #include +#else + #include +#endif +#include +#include +#include +#include #ifndef LWS_NO_FORK #ifdef HAVE_SYS_PRCTL_H #include