refactor: core code in lib/core and private-libwebsockets.h to core/private.h

This commit is coverity-clean as tested

cmake .. -DLWS_WITH_MINIMAL_EXAMPLES=1 -DLWS_WITHOUT_EXTENSIONS=1 -DLWS_WITH_ACME=1 -DLWS_WITH_LWSWS=1 -DLWS_WITH_LIBUV=1 -DLWS_WITH_HTTP2=1 -DLWS_WITHOUT_CLIENT=0 -DLWS_WITHOUT_SERVER=0 -DLWS_UNIX_SOCK=1 -DLWS_WITH_TLS=0 -DLWS_WITH_MBEDTLS=0 -DLWS_WITH_CGI=1 -DCMAKE_BUILD_TYPE=DEBUG -DLWS_WITH_GENERIC_SESSIONS=1 -DLWS_WITH_RANGES=1 -DLWS_ROLE_WS=1 -DLWS_MAX_SMP=16 -DLWS_ROLE_H1=1 -DLWS_WITH_WOLFSSL=0 -DLWS_WITH_LIBEV=0 -DLWS_WITH_LIBEVENT=1
This commit is contained in:
Andy Green 2018-05-03 10:49:36 +08:00
parent a01ad0dd20
commit de064fd65a
79 changed files with 145 additions and 830 deletions

1
.gitignore vendored
View file

@ -49,3 +49,4 @@ build/
doc
/build2/
/build3/
/cov-int/

View file

@ -718,7 +718,7 @@ include_directories("${PROJECT_SOURCE_DIR}/lib")
# Group headers and sources.
# Some IDEs use this for nicer file structure.
set(HDR_PRIVATE
lib/private-libwebsockets.h)
lib/core/private.h)
set(HDR_PUBLIC
"${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
@ -728,12 +728,12 @@ set(HDR_PUBLIC
set(SOURCES
lib/misc/base64-decode.c
lib/libwebsockets.c
lib/service.c
lib/pollfd.c
lib/output.c
lib/context.c
lib/alloc.c
lib/core/libwebsockets.c
lib/core/service.c
lib/core/pollfd.c
lib/core/output.c
lib/core/context.c
lib/core/alloc.c
lib/roles/pipe/ops-pipe.c
lib/misc/lws-ring.c)
@ -1645,29 +1645,6 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
""
"")
endif()
if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
AND LWS_WITH_LIBEV)
create_test_app(test-server-libev
"test-apps/test-server-libev.c"
""
""
""
""
"")
# libev generates a big mess of warnings with gcc, maintainer claims gcc to blame
set_source_files_properties( test-apps/test-server-libev.c PROPERTIES COMPILE_FLAGS "-Wno-error" )
endif()
if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
AND LWS_WITH_LIBEVENT)
create_test_app(test-server-libevent
"test-apps/test-server-libevent.c"
""
""
""
""
"")
endif()
endif()
#

14
lib/README.md Normal file
View file

@ -0,0 +1,14 @@
## Library sources layout
Code that goes in the libwebsockets library itself lives down ./lib
Path|Sources
---|---
lib/core|Core lws code related to generic fd and wsi servicing and management
lib/event-libs|Code containing optional event-lib specific adaptations
lib/misc|Code for various mostly optional miscellaneous features
lib/plat|Platform-specific adaptation code
lib/roles|Code for specific optional wsi roles, eg, http/1, h2, ws, raw, etc
lib/tls|Code supporting the various TLS libraries
libwebsockets.h|Public API header for the whole of lws

View file

@ -1,4 +1,4 @@
#include "private-libwebsockets.h"
#include "core/private.h"
#if defined(LWS_PLAT_OPTEE)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#ifndef LWS_BUILD_HASH
#define LWS_BUILD_HASH "unknown-build-hash"

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#ifdef LWS_HAVE_SYS_TYPES_H
#include <sys/types.h>
@ -672,8 +672,9 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char *
if (!wsi->told_user_closed && lwsi_role_http(wsi) &&
lwsi_role_server(wsi)) {
if (wsi->user_space && wsi->protocol_bind_balance) {
wsi->vhost->protocols->callback(wsi,
if (wsi->user_space && wsi->protocol &&
wsi->protocol_bind_balance) {
wsi->protocol->callback(wsi,
LWS_CALLBACK_HTTP_DROP_PROTOCOL,
wsi->user_space, NULL, 0);
wsi->protocol_bind_balance = 0;
@ -2927,7 +2928,7 @@ lws_cmdline_option(int argc, const char **argv, const char *val)
while (--c > 0)
if (!strncmp(argv[c], val, n)) {
if (!*(argv[c] + n) && c != argc - 1)
if (!*(argv[c] + n) && c < argc - 1)
return argv[c + 1];
return argv[c] + n;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* notice this returns number of bytes consumed, or -1

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
int
_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)

View file

@ -26,8 +26,14 @@
#define _GNU_SOURCE
#endif
#if defined(__COVERITY__)
typedef struct { long double x, y; } _Float128;
#if defined(__COVERITY__) && !defined(LWS_COVERITY_WORKAROUND)
#define LWS_COVERITY_WORKAROUND
typedef float _Float32;
typedef float _Float64;
typedef float _Float128;
typedef float _Float32x;
typedef float _Float64x;
typedef float _Float128x;
#endif
#ifdef LWS_HAVE_SYS_TYPES_H
@ -1076,8 +1082,8 @@ struct lws {
#endif
#endif
lws_usec_t pending_timer;
time_t pending_timeout_set;
lws_usec_t pending_timer; /* hrtimer fires */
time_t pending_timeout_set; /* second-resolution timeout start */
/* ints */
int position_in_fds_table;
@ -1443,7 +1449,7 @@ lws_pt_unlock(struct lws_context_per_thread *pt)
pt->lock_depth--;
return;
}
pt->last_lock_reason ="free";
pt->last_lock_reason = "free";
pt->lock_owner = 0;
//lwsl_notice("tid %d: unlock %s\n", pt->tid, pt->last_lock_reason);
pthread_mutex_unlock(&pt->lock);

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
int
lws_callback_as_writeable(struct lws *wsi)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static void
lws_ev_hrtimer_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents)

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_WITH_LIBEV
* This is included from core/private.h if LWS_WITH_LIBEV
*/
#include <ev.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static void
lws_event_hrtimer_cb(int fd, short event, void *p)

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_WITH_LIBEVENT
* This is included from core/private.h if LWS_WITH_LIBEVENT
*/
#include <event2/event.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static void
lws_uv_hrtimer_cb(uv_timer_t *timer
@ -666,21 +666,18 @@ static int
elops_init_vhost_listen_wsi_uv(struct lws *wsi)
{
struct lws_context_per_thread *pt;
struct lws_vhost *vh = wsi->vhost;
int n;
if (!wsi)
wsi = vh->lserv_wsi;
if (!wsi)
return 0;
if (wsi->w_read.context)
return 0;
pt = &vh->context->pt[(int)wsi->tsi];
pt = &wsi->context->pt[(int)wsi->tsi];
if (!pt->uv.io_loop)
return 0;
wsi->w_read.context = vh->context;
wsi->w_read.context = wsi->context;
n = uv_poll_init_socket(pt->uv.io_loop,
&wsi->w_read.uv.watcher, wsi->desc.sockfd);
if (n) {

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_WITH_LIBUV
* This is included from core/private.h if LWS_WITH_LIBUV
*/
#include <uv.h>

View file

@ -18,10 +18,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
* This is included from core/private.h if LWS_ROLE_WS
*/
#include <private-libwebsockets.h>
#include <core/private.h>
struct lws_event_loop_ops event_loop_ops_poll = {
/* name */ "poll",

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h
* This is included from core/private.h
*/
struct lws_event_loop_ops {

View file

@ -27,7 +27,7 @@
#ifdef __cplusplus
#include <cstddef>
#include <cstdarg>
#
extern "C" {
#else
#include <stdarg.h>

View file

@ -40,7 +40,7 @@
#include <stdio.h>
#include <string.h>
#include "private-libwebsockets.h"
#include "core/private.h"
static const char encode_orig[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz0123456789+/";

View file

@ -22,7 +22,7 @@
#include <unistd.h>
#include <errno.h>
#include "private-libwebsockets.h"
#include "core/private.h"
int pid_daemon;
static char *lock_path;

View file

@ -43,7 +43,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "private-libwebsockets.h"
#include "core/private.h"
#ifdef LWS_HAVE_SYS_SOCKIO_H
#include <sys/sockio.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include <fcntl.h>
#include <unistd.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* JSON Web Signature is defined in RFC7515

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
LWS_VISIBLE LWS_EXTERN struct lws_ring *
lws_ring_create(size_t element_len, size_t count,

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/* requires context->lock */
static void

View file

@ -32,7 +32,7 @@
* implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#ifdef LWS_HAVE_SYS_TYPES_H
#include <sys/types.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static unsigned int
lwsgs_now_secs(void)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include "freertos/timers.h"
#include <esp_attr.h>
#include <esp_system.h>

View file

@ -1,4 +1,4 @@
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* included from libwebsockets.c for OPTEE builds

View file

@ -20,7 +20,7 @@
*/
#define _GNU_SOURCE
#include "private-libwebsockets.h"
#include "core/private.h"
#include <pwd.h>
#include <grp.h>

View file

@ -1,7 +1,7 @@
#ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#endif
#include "private-libwebsockets.h"
#include "core/private.h"
int
lws_plat_socket_offset(void)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#if defined(WIN32) || defined(_WIN32)
#else

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
static int
rops_handle_POLLIN_cgi(struct lws_context_per_thread *pt, struct lws *wsi,

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
* This is included from core/private.h if LWS_ROLE_WS
*/
extern struct lws_role_ops role_ops_cgi;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_ROLE_H1
* This is included from core/private.h if LWS_ROLE_H1
*
* Most of the h1 business is defined in the h1 / h2 common roles/http dir
*/

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* Official static header table for HPACK

View file

@ -20,7 +20,7 @@
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* bitmap of control messages that are valid to receive for each http2 state

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
/*
* These are the standardized defaults.

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_ROLE_H2
* This is included from core/private.h if LWS_ROLE_H2
*/
extern struct lws_role_ops role_ops_h2;

View file

@ -1,4 +1,4 @@
#include "private-libwebsockets.h"
#include "core/private.h"
static int
lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result)
@ -78,7 +78,9 @@ lws_client_connect_2(struct lws *wsi)
*/
adsin = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS);
lws_vhost_lock(wsi->vhost);
lws_vhost_lock(wsi->vhost); /* ----------------------------------- { */
lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1,
wsi->vhost->dll_active_client_conns.next) {
struct lws *w = lws_container_of(d, struct lws,
@ -101,6 +103,7 @@ lws_client_connect_2(struct lws *wsi)
if (w->keepalive_rejected) {
lwsl_info("defeating pipelining due to no "
"keepalive on server\n");
lws_vhost_unlock(wsi->vhost); /* } ---------- */
goto create_new_conn;
}
#if defined (LWS_WITH_HTTP2)
@ -117,7 +120,7 @@ lws_client_connect_2(struct lws *wsi)
wsi->client_h2_alpn = 1;
lws_wsi_h2_adopt(w, wsi);
lws_vhost_unlock(wsi->vhost);
lws_vhost_unlock(wsi->vhost); /* } ---------- */
return wsi;
}
@ -140,12 +143,13 @@ lws_client_connect_2(struct lws *wsi)
wsi_piggyback = w;
lws_vhost_unlock(wsi->vhost);
lws_vhost_unlock(wsi->vhost); /* } ---------- */
goto send_hs;
}
} lws_end_foreach_dll_safe(d, d1);
lws_vhost_unlock(wsi->vhost);
lws_vhost_unlock(wsi->vhost); /* } ---------------------------------- */
create_new_conn:
#endif

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
LWS_VISIBLE LWS_EXTERN void
lws_client_http_body_pending(struct lws *wsi, int something_left_to_send)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include "lextable-strings.h"

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if either H1 or H2 roles are
* This is included from core/private.h if either H1 or H2 roles are
* enabled
*/

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* Produce Apache-compatible log string for wsi, like this:

View file

@ -51,7 +51,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include <zlib.h>

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#ifndef _WIN32
/* this is needed for Travis CI */

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#define LWS_MAX_ELEM_NAME 32

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static const unsigned char lextable[] = {
#include "../lextable.h"

View file

@ -21,7 +21,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* RFC7233 examples

View file

@ -1,4 +1,4 @@
#include "private-libwebsockets.h"
#include "core/private.h"
LWS_EXTERN struct lws_rewrite *

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
const char * const method_names[] = {
"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "CONNECT", "HEAD",

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
static int
rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi,

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
static int
rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi,

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h
* This is included from core/private.h
*/
typedef uint32_t lws_wsi_state_t;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
static int
rops_handle_POLLIN_raw_skt(struct lws_context_per_thread *pt, struct lws *wsi,

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* parsers.c: lws_ws_rx_sm() needs to be roughly kept in
@ -29,10 +29,13 @@
int lws_ws_client_rx_sm(struct lws *wsi, unsigned char c)
{
int callback_action = LWS_CALLBACK_CLIENT_RECEIVE;
int handled, n, m, rx_draining_ext = 0;
int handled, m;
unsigned short close_code;
struct lws_tokens ebuf;
unsigned char *pp;
#if !defined(LWS_WITHOUT_EXTENSIONS)
int rx_draining_ext = 0, n;
#endif
ebuf.token = NULL;
ebuf.len = 0;
@ -498,12 +501,14 @@ drain_extension:
wsi->socket_is_permanently_unusable = 1;
return -1;
}
#else
n = 0;
#endif
lwsl_debug("post inflate ebuf len %d\n", ebuf.len);
if (rx_draining_ext && !ebuf.len) {
if (
#if !defined(LWS_WITHOUT_EXTENSIONS)
rx_draining_ext &&
#endif
!ebuf.len) {
lwsl_debug(" --- ending drain on 0 read result\n");
goto already_done;
}
@ -520,7 +525,11 @@ drain_extension:
/* we are ending partway through utf-8 character? */
if (!wsi->ws->rx_packet_length && wsi->ws->final &&
wsi->ws->utf8 && !n) {
wsi->ws->utf8
#if !defined(LWS_WITHOUT_EXTENSIONS)
&& !n
#endif
) {
lwsl_info("FINAL utf8 error\n");
lws_close_reason(wsi,
LWS_CLOSE_STATUS_INVALID_PAYLOAD,
@ -550,9 +559,9 @@ utf8_fail:
if (
/* coverity says dead code otherwise */
//#if !defined(LWS_WITHOUT_EXTENSIONS)
#if !defined(LWS_WITHOUT_EXTENSIONS)
n &&
//#endif
#endif
ebuf.len)
/* extension had more... main loop will come back
* we want callback to be done with this set, if so,

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
/*
* In-place str to lower case

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include "extension-permessage-deflate.h"
#include <stdio.h>
#include <string.h>

View file

@ -1,4 +1,4 @@
#include "private-libwebsockets.h"
#include "core/private.h"
#include "extension-permessage-deflate.h"

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
#define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); }
@ -32,12 +32,13 @@ int
lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c)
{
int callback_action = LWS_CALLBACK_RECEIVE;
int ret = 0, rx_draining_ext = 0;
int ret = 0;
unsigned short close_code;
struct lws_tokens ebuf;
unsigned char *pp;
int n = 0;
#if !defined(LWS_WITHOUT_EXTENSIONS)
int rx_draining_ext = 0;
int lin;
#endif
@ -586,7 +587,11 @@ drain_extension:
return -1;
}
#endif
if (rx_draining_ext && ebuf.len == 0)
if (
#if !defined(LWS_WITHOUT_EXTENSIONS)
rx_draining_ext &&
#endif
ebuf.len == 0)
goto already_done;
if (

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_ROLE_WS
* This is included from core/private.h if LWS_ROLE_WS
*/
extern struct lws_role_ops role_ops_ws;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include <private-libwebsockets.h>
#include <core/private.h>
#define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); }

View file

@ -21,7 +21,7 @@
* lws_genhash provides a hash / hmac abstraction api in lws that works the
* same whether you are using openssl or mbedtls hash functions underneath.
*/
#include "private-libwebsockets.h"
#include "core/private.h"
LWS_VISIBLE void
lws_jwk_destroy_genrsa_elements(struct lws_genrsa_elements *el)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
static int
OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include <mbedtls/x509_csr.h>
int

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include <mbedtls/oid.h>
void

View file

@ -21,7 +21,7 @@
* lws_genhash provides a hash / hmac abstraction api in lws that works the
* same whether you are using openssl or mbedtls hash functions underneath.
*/
#include "private-libwebsockets.h"
#include "core/private.h"
LWS_VISIBLE void
lws_jwk_destroy_genrsa_elements(struct lws_genrsa_elements *el)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
extern int openssl_websocket_private_data_index,
openssl_SSL_CTX_private_data_index;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
extern int openssl_websocket_private_data_index,
openssl_SSL_CTX_private_data_index;

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#include <errno.h>
int openssl_websocket_private_data_index,

View file

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* This is included from private-libwebsockets.h if LWS_WITH_TLS
* This is included from core/private.h if LWS_WITH_TLS
*/
#if defined(LWS_WITH_TLS)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
int
lws_ssl_client_connect1(struct lws *wsi)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
#if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \
OPENSSL_VERSION_NUMBER >= 0x10002000L)

View file

@ -19,7 +19,7 @@
* MA 02110-1301 USA
*/
#include "private-libwebsockets.h"
#include "core/private.h"
/*
* fakes POLLIN on all tls guys with buffered rx

View file

@ -120,7 +120,8 @@ wait_unlock:
pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */
wait:
usleep(100000 + (rand() & 0xfffff));
/* rand() would make more sense but coverity shrieks */
usleep(100000 + (time(NULL) & 0xffff));
} while (!vhd->finished);

View file

@ -1,349 +0,0 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2011-2018 Andy Green <andy@warmcat.com>
*
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* The person who associated a work with this deed has dedicated
* the work to the public domain by waiving all of his or her rights
* to the work worldwide under copyright law, including all related
* and neighboring rights, to the extent allowed by law. You can copy,
* modify, distribute and perform the work, even for commercial purposes,
* all without asking permission.
*
* The test apps are intended to be adapted for use in your code, which
* may be proprietary. So unlike the library itself, they are licensed
* Public Domain.
*/
#include <libwebsockets.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
int close_testing;
int max_poll_elements;
int debug_level = 7;
volatile int force_exit = 0;
struct lws_context *context;
struct lws_plat_file_ops fops_plat;
/* http server gets files from this path */
#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server"
char *resource_path = LOCAL_RESOURCE_PATH;
#if defined(LWS_WITH_TLS) && defined(LWS_HAVE_SSL_CTX_set1_param)
char crl_path[1024] = "";
#endif
#define LWS_PLUGIN_STATIC
#include "../plugins/protocol_dumb_increment.c"
#include "../plugins/protocol_lws_mirror.c"
#include "../plugins/protocol_lws_status.c"
#include "../plugins/protocol_post_demo.c"
/* list of supported protocols and callbacks */
static struct lws_protocols protocols[] = {
/* first protocol must always be HTTP handler */
{ "http-only", lws_callback_http_dummy, 0, 0, },
LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT,
LWS_PLUGIN_PROTOCOL_MIRROR,
LWS_PLUGIN_PROTOCOL_LWS_STATUS,
LWS_PLUGIN_PROTOCOL_POST_DEMO,
{ NULL, NULL, 0, 0 } /* terminator */
};
static const struct lws_extension exts[] = {
{
"permessage-deflate",
lws_extension_callback_pm_deflate,
"permessage-deflate; client_no_context_takeover; client_max_window_bits"
},
{ NULL, NULL, NULL /* terminator */ }
};
/*
* mount handlers for sections of the URL space
*/
static const struct lws_http_mount mount_ziptest = {
NULL, /* linked-list pointer to next*/
"/ziptest", /* mountpoint in URL namespace on this vhost */
LOCAL_RESOURCE_PATH"/candide.zip", /* handler */
NULL, /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_FILE, /* origin points to a callback */
8, /* strlen("/ziptest"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
static const struct lws_http_mount mount_post = {
(struct lws_http_mount *)&mount_ziptest, /* linked-list pointer to next*/
"/formtest", /* mountpoint in URL namespace on this vhost */
"protocol-post-demo", /* handler */
NULL, /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_CALLBACK, /* origin points to a callback */
9, /* strlen("/formtest"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
/*
* mount a filesystem directory into the URL space at /
* point it to our /usr/share directory with our assets in
* stuff from here is autoserved by the library
*/
static const struct lws_http_mount mount = {
(struct lws_http_mount *)&mount_post, /* linked-list pointer to next*/
"/", /* mountpoint in URL namespace on this vhost */
LOCAL_RESOURCE_PATH, /* where to go on the filesystem for that */
"test.html", /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_FILE, /* mount type is a directory in a filesystem */
1, /* strlen("/"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
/* this shows how to override the lws file operations. You don't need
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
static lws_fop_fd_t
test_server_fops_open(const struct lws_plat_file_ops *fops,
const char *vfs_path, const char *vpath,
lws_fop_flags_t *flags)
{
lws_fop_fd_t n;
/* call through to original platform implementation */
n = fops_plat.open(fops, vfs_path, vpath, flags);
lwsl_debug("%s: opening %s, ret %p\n", __func__, vfs_path, n);
return n;
}
void signal_cb(struct ev_loop *loop, struct ev_signal* watcher, int revents)
{
lwsl_notice("Signal caught, exiting...\n");
force_exit = 1;
switch (watcher->signum) {
case SIGTERM:
case SIGINT:
ev_break(loop, EVBREAK_ALL);
break;
default:
signal(SIGABRT, SIG_DFL);
abort();
break;
}
}
static struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "debug", required_argument, NULL, 'd' },
{ "port", required_argument, NULL, 'p' },
{ "ssl", no_argument, NULL, 's' },
{ "allow-non-ssl", no_argument, NULL, 'a' },
{ "interface", required_argument, NULL, 'i' },
{ "closetest", no_argument, NULL, 'c' },
#ifndef LWS_NO_DAEMONIZE
{ "daemonize", no_argument, NULL, 'D' },
#endif
{ "resource_path", required_argument, NULL, 'r' },
{ NULL, 0, 0, 0 }
};
int main(int argc, char **argv)
{
int sigs[] = { SIGINT, SIGKILL, SIGTERM, SIGSEGV, SIGFPE };
struct ev_signal signals[ARRAY_SIZE(sigs)];
struct ev_loop *loop = ev_default_loop(0);
struct lws_context_creation_info info;
char interface_name[128] = "";
const char *iface = NULL;
void *foreign_loops[1];
char cert_path[1024];
char key_path[1024];
int use_ssl = 0;
int opts = 0;
int n = 0;
#ifndef LWS_NO_DAEMONIZE
int daemonize = 0;
#endif
/*
* take care to zero down the info struct, he contains random garbaage
* from the stack otherwise
*/
memset(&info, 0, sizeof info);
info.port = 7681;
while (n >= 0) {
n = getopt_long(argc, argv, "ci:hsap:d:Dr:", options, NULL);
if (n < 0)
continue;
switch (n) {
#ifndef LWS_NO_DAEMONIZE
case 'D':
daemonize = 1;
#ifndef _WIN32
syslog_options &= ~LOG_PERROR;
#endif
break;
#endif
case 'd':
debug_level = atoi(optarg);
break;
case 's':
use_ssl = 1;
break;
case 'a':
opts |= LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT;
break;
case 'p':
info.port = atoi(optarg);
break;
case 'i':
lws_strncpy(interface_name, optarg, sizeof interface_name);
iface = interface_name;
break;
case 'c':
close_testing = 1;
fprintf(stderr, " Close testing mode -- closes on "
"client after 50 dumb increments"
"and suppresses lws_mirror spam\n");
break;
case 'r':
resource_path = optarg;
printf("Setting resource path to \"%s\"\n", resource_path);
break;
case 'h':
fprintf(stderr, "Usage: test-server "
"[--port=<p>] [--ssl] "
"[-d <log bitfield>] "
"[--resource_path <path>]\n");
exit(1);
}
}
#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32)
/*
* normally lock path would be /var/lock/lwsts or similar, to
* simplify getting started without having to take care about
* permissions or running as root, set to /tmp/.lwsts-lock
*/
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
fprintf(stderr, "Failed to daemonize\n");
return 1;
}
#endif
for (n = 0; n < (int)ARRAY_SIZE(sigs); n++) {
ev_init(&signals[n], signal_cb);
ev_signal_set(&signals[n], sigs[n]);
ev_signal_start(loop, &signals[n]);
}
/* tell the library what debug level to emit and to send it to stderr */
lws_set_log_level(debug_level, NULL);
lwsl_notice("libwebsockets test server libev - license LGPL2.1+SLE\n");
lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n");
printf("Using resource path \"%s\"\n", resource_path);
info.iface = iface;
info.protocols = protocols;
info.extensions = exts;
info.mounts = &mount;
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
if (use_ssl) {
if (strlen(resource_path) > sizeof(cert_path) - 32) {
lwsl_err("resource path too long\n");
return -1;
}
sprintf(cert_path, "%s/libwebsockets-test-server.pem",
resource_path);
if (strlen(resource_path) > sizeof(key_path) - 32) {
lwsl_err("resource path too long\n");
return -1;
}
sprintf(key_path, "%s/libwebsockets-test-server.key.pem",
resource_path);
info.ssl_cert_filepath = cert_path;
info.ssl_private_key_filepath = key_path;
opts |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
}
info.gid = -1;
info.uid = -1;
info.options = opts | LWS_SERVER_OPTION_LIBEV;
foreign_loops[0] = &loop;
info.foreign_loops = foreign_loops;
context = lws_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
}
/*
* this shows how to override the lws file operations. You don't need
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
/* stash original platform fops */
fops_plat = *(lws_get_fops(context));
/* override the active fops */
lws_get_fops(context)->open = test_server_fops_open;
lws_service(context, 0);
lws_context_destroy(context);
lwsl_notice("libwebsockets-test-server exited cleanly\n");
return 0;
}

View file

@ -1,351 +0,0 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2011-2017 Andy Green <andy@warmcat.com>
*
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* The person who associated a work with this deed has dedicated
* the work to the public domain by waiving all of his or her rights
* to the work worldwide under copyright law, including all related
* and neighboring rights, to the extent allowed by law. You can copy,
* modify, distribute and perform the work, even for commercial purposes,
* all without asking permission.
*
* The test apps are intended to be adapted for use in your code, which
* may be proprietary. So unlike the library itself, they are licensed
* Public Domain.
*/
#include <libwebsockets.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
int close_testing;
int max_poll_elements;
int debug_level = 7;
volatile int force_exit = 0;
struct lws_context *context;
struct lws_plat_file_ops fops_plat;
/* http server gets files from this path */
#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server"
char *resource_path = LOCAL_RESOURCE_PATH;
#if defined(LWS_WITH_TLS) && defined(LWS_HAVE_SSL_CTX_set1_param)
char crl_path[1024] = "";
#endif
#define LWS_PLUGIN_STATIC
#include "../plugins/protocol_dumb_increment.c"
#include "../plugins/protocol_lws_mirror.c"
#include "../plugins/protocol_lws_status.c"
#include "../plugins/protocol_post_demo.c"
/* list of supported protocols and callbacks */
static struct lws_protocols protocols[] = {
/* first protocol must always be HTTP handler */
{ "http-only", lws_callback_http_dummy, 0, 0, },
LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT,
LWS_PLUGIN_PROTOCOL_MIRROR,
LWS_PLUGIN_PROTOCOL_LWS_STATUS,
LWS_PLUGIN_PROTOCOL_POST_DEMO,
{ NULL, NULL, 0, 0 } /* terminator */
};
static const struct lws_extension exts[] = {
{
"permessage-deflate",
lws_extension_callback_pm_deflate,
"permessage-deflate; client_no_context_takeover; client_max_window_bits"
},
{ NULL, NULL, NULL /* terminator */ }
};
/* this shows how to override the lws file operations. You don't need
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
static lws_fop_fd_t
test_server_fops_open(const struct lws_plat_file_ops *fops,
const char *vfs_path, const char *vpath,
lws_fop_flags_t *flags)
{
lws_fop_fd_t n;
/* call through to original platform implementation */
n = fops_plat.open(fops, vfs_path, vpath, flags);
lwsl_notice("%s: opening %s, ret %p\n", __func__, vfs_path, n);
return n;
}
void signal_cb(evutil_socket_t sock_fd, short events, void *ctx)
{
struct event_base *event_base_loop = ctx;
lwsl_notice("Signal caught, exiting...\n");
force_exit = 1;
if (events & EV_SIGNAL)
event_base_loopbreak(event_base_loop);
}
/*
* mount handlers for sections of the URL space
*/
static const struct lws_http_mount mount_ziptest = {
NULL, /* linked-list pointer to next*/
"/ziptest", /* mountpoint in URL namespace on this vhost */
LOCAL_RESOURCE_PATH"/candide.zip", /* handler */
NULL, /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_FILE, /* origin points to a callback */
8, /* strlen("/ziptest"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
static const struct lws_http_mount mount_post = {
(struct lws_http_mount *)&mount_ziptest, /* linked-list pointer to next*/
"/formtest", /* mountpoint in URL namespace on this vhost */
"protocol-post-demo", /* handler */
NULL, /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_CALLBACK, /* origin points to a callback */
9, /* strlen("/formtest"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
/*
* mount a filesystem directory into the URL space at /
* point it to our /usr/share directory with our assets in
* stuff from here is autoserved by the library
*/
static const struct lws_http_mount mount = {
(struct lws_http_mount *)&mount_post, /* linked-list pointer to next*/
"/", /* mountpoint in URL namespace on this vhost */
LOCAL_RESOURCE_PATH, /* where to go on the filesystem for that */
"test.html", /* default filename if none given */
NULL,
NULL,
NULL,
NULL,
0,
0,
0,
0,
0,
0,
LWSMPRO_FILE, /* mount type is a directory in a filesystem */
1, /* strlen("/"), ie length of the mountpoint */
NULL,
{ NULL, NULL } // sentinel
};
static struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "debug", required_argument, NULL, 'd' },
{ "port", required_argument, NULL, 'p' },
{ "ssl", no_argument, NULL, 's' },
{ "allow-non-ssl", no_argument, NULL, 'a' },
{ "interface", required_argument, NULL, 'i' },
{ "closetest", no_argument, NULL, 'c' },
{ "libevent", no_argument, NULL, 'e' },
#ifndef LWS_NO_DAEMONIZE
{ "daemonize", no_argument, NULL, 'D' },
#endif
{ "resource_path", required_argument, NULL, 'r' },
{ NULL, 0, 0, 0 }
};
int main(int argc, char **argv)
{
int sigs[] = { SIGINT, SIGKILL, SIGTERM, SIGSEGV, SIGFPE };
struct event *signals[ARRAY_SIZE(sigs)];
struct event_base *event_base_loop = event_base_new();
struct lws_context_creation_info info;
char interface_name[128] = "";
void *foreign_loops[1];
const char *iface = NULL;
char cert_path[1024];
char key_path[1024];
int use_ssl = 0;
int opts = 0;
int n = 0;
#ifndef LWS_NO_DAEMONIZE
int daemonize = 0;
#endif
/*
* take care to zero down the info struct, he contains random garbaage
* from the stack otherwise
*/
memset(&info, 0, sizeof info);
info.port = 7681;
while (n >= 0) {
n = getopt_long(argc, argv, "eci:hsap:d:Dr:", options, NULL);
if (n < 0)
continue;
switch (n) {
case 'e':
opts |= LWS_SERVER_OPTION_LIBEVENT;
break;
#ifndef LWS_NO_DAEMONIZE
case 'D':
daemonize = 1;
#ifndef _WIN32
syslog_options &= ~LOG_PERROR;
#endif
break;
#endif
case 'd':
debug_level = atoi(optarg);
break;
case 's':
use_ssl = 1;
break;
case 'a':
opts |= LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT;
break;
case 'p':
info.port = atoi(optarg);
break;
case 'i':
lws_strncpy(interface_name, optarg, sizeof interface_name);
iface = interface_name;
break;
case 'c':
close_testing = 1;
fprintf(stderr, " Close testing mode -- closes on "
"client after 50 dumb increments"
"and suppresses lws_mirror spam\n");
break;
case 'r':
resource_path = optarg;
printf("Setting resource path to \"%s\"\n", resource_path);
break;
case 'h':
fprintf(stderr, "Usage: test-server "
"[--port=<p>] [--ssl] "
"[-d <log bitfield>] "
"[--resource_path <path>]\n");
exit(1);
}
}
#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32)
/*
* normally lock path would be /var/lock/lwsts or similar, to
* simplify getting started without having to take care about
* permissions or running as root, set to /tmp/.lwsts-lock
*/
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
fprintf(stderr, "Failed to daemonize\n");
return 1;
}
#endif
for (n = 0; n < (int)ARRAY_SIZE(sigs); n++) {
signals[n] = evsignal_new(event_base_loop, sigs[n], signal_cb,
event_base_loop);
evsignal_add(signals[n], NULL);
}
/* tell the library what debug level to emit and to send it to stderr */
lws_set_log_level(debug_level, NULL);
lwsl_notice("libwebsockets test server libevent - license LGPL2.1+SLE\n");
lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n");
printf("Using resource path \"%s\"\n", resource_path);
info.iface = iface;
info.protocols = protocols;
info.extensions = exts;
info.mounts = &mount;
info.ssl_cert_filepath = NULL;
info.ssl_private_key_filepath = NULL;
if (use_ssl) {
if (strlen(resource_path) > sizeof(cert_path) - 32) {
lwsl_err("resource path too long\n");
return -1;
}
sprintf(cert_path, "%s/libwebsockets-test-server.pem",
resource_path);
if (strlen(resource_path) > sizeof(key_path) - 32) {
lwsl_err("resource path too long\n");
return -1;
}
sprintf(key_path, "%s/libwebsockets-test-server.key.pem",
resource_path);
info.ssl_cert_filepath = cert_path;
info.ssl_private_key_filepath = key_path;
opts |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
}
info.gid = -1;
info.uid = -1;
info.options = opts | LWS_SERVER_OPTION_LIBEVENT;
foreign_loops[0] = event_base_loop;
info.foreign_loops = foreign_loops;
context = lws_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
}
/*
* this shows how to override the lws file operations. You don't need
* to do any of this unless you have a reason (eg, want to serve
* compressed files without decompressing the whole archive)
*/
/* stash original platform fops */
fops_plat = *(lws_get_fops(context));
/* override the active fops */
lws_get_fops(context)->open = test_server_fops_open;
event_base_dispatch(event_base_loop);
for (n = 0; n < (int)ARRAY_SIZE(sigs); n++)
event_free(signals[n]);
lws_context_destroy(context);
lwsl_notice("libwebsockets-test-server exited cleanly\n");
return 0;
}