Compare commits

...
Sign in to create a new pull request.

30 commits

Author SHA1 Message Date
Andy Green
e5823158b3 update openssl url
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-22 12:54:48 +08:00
Andy Green
5462be9a44 client account for retries
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-22 12:32:20 +08:00
Andy Green
c93c47f3a4 client init fds pos to minus 1
Signed-off-by: Andy Green <andy@warmcat.com>
2016-04-22 12:31:50 +08:00
Justin Chen
6406f44b76 recv treat zero return as error
https://github.com/warmcat/libwebsockets/issues/475
2016-04-14 21:42:25 +08:00
Andrew Cooks
1e9c1a5a1a update the cmake version number to match the git tag and rpm version. 2016-02-09 10:17:11 +08:00
Andrew Cooks
14ebad74fd bump packaged version to 1.6.3 2016-02-09 10:16:12 +08:00
Andrew Cooks
1d8bd55062 spec file cleanups as recommended by fedora-review 2016-02-09 10:15:31 +08:00
Andrew Cooks
0a7374b647 Merge improvements from previously reviewed spec on RH bug #1198498 2016-02-09 10:11:40 +08:00
Andy Green
ebfdb0d24d license clarification and test apps CC zero
The test apps are intended to be adapted into user code freely,
this relicenses them public domain to make that clear.

Fixes and improvements are of course still welcome.

LICENSE clarifies now that some sources also have a more liberal license,
it was always told in the source itself but now it's summarized.

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-08 08:46:05 +08:00
gaby64
784231a642 libev context destroy
https://github.com/warmcat/libwebsockets/issues/380
2016-01-29 08:40:11 +08:00
Andy Green
ba955592eb libev complete unix plat context init
https://github.com/warmcat/libwebsockets/issues/381

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-29 08:38:47 +08:00
Andy Green
0c034953e9 v1.6.2
The only change from v1.6.1 is it's possible to build without
test apps and avoid dependency on pthreads, if your OS + toolchain
can do that (eg, openwrt).

There's no need to update to this otherwise.

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-25 21:35:13 +08:00
Andy Green
e04f4c9ced pthreads only as needed
This just lets you build lws 1.6 without pthreads if your OS / toolchain
makes that possible, in the case you don't build the test apps
(libwebsockets-test-server-pthreads needs it)

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-25 20:52:37 +08:00
Andy Green
9cf4dbe1e7 update VERSION_PATCH
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-22 15:55:13 +08:00
Andy Green
c29af6641d fuzzer handle junk after upgrade header
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-21 11:10:26 +08:00
Andy Green
1587c5537d more return code checking
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 17:02:41 +08:00
Andrew Cooks
c967906307 fix missing ${LIB_SUFFIX} on cmake config dir 2016-01-20 14:21:54 +08:00
Andy Green
5344b20c43 header fragment reject empty early
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:43:22 +08:00
Roger A. Light
243a04efcb Subject: [PATCH] Typo in macro name. 2016-01-20 09:39:44 +08:00
Andy Green
9b2b9d1a7e parser issue_char audit
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
9d73971cf5 test server http dont print junk if string too long
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
e7f9232c1a avoid using deallocated things during context dedtroy
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
bf6ba0427b remove double free attempts from no ACCEPT server response cleanup path
The generic wsi close code is smart enough to clean up after these allocations itself

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
10da4c1236 fuzzer eliminate hsecond ah free path firing assert sentinel
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
ffd361430c fuzzer rx overflow mitigate
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:49 +08:00
Andy Green
00e5eb8658 uridecoding lws_hdr_fragment_length
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:42 +08:00
Andy Green
0f8b1919ef uridecode no need to require length plus 2
length + 1 (for the '\0' is enough)

Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:23 +08:00
Andy Green
7070968f94 uridecoding disallow uriencoded equals in name part
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:37:08 +08:00
Andy Green
466ad50d6a uridecoding handle plus chars as space
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:36:56 +08:00
Andy Green
4036b51690 uridecoding support optional semicolon as delimiter
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-01-20 09:36:41 +08:00
29 changed files with 375 additions and 229 deletions

View file

@ -10,7 +10,7 @@ set(PACKAGE "libwebsockets")
set(CPACK_PACKAGE_NAME "${PACKAGE}")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "6")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_VERSION_PATCH "3")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
@ -492,7 +492,7 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID
endif(UNIX)
endif ()
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
if (UNIX)
# jeez clang understands -pthread but dies if he sees it at link time!
# http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
@ -978,7 +978,7 @@ endif(UNIX)
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR cmake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/libwebsockets)
set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
endif()
set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")

20
LICENSE
View file

@ -22,6 +22,26 @@ satisfy this requirement:
"[program] is based in part on the work of the libwebsockets project
(http://libwebsockets.org)"
3) Some sources included have their own, more liberal licenses, or options
to get original sources with the liberal terms.
Original liberal license retained
- lib/sha-1.c - 3-clause BSD license retained, link to original
- win32port/zlib - ZLIB license (see zlib.h)
Relicensed to libwebsocket license
- lib/base64-decode.c - relicensed to LGPL2.1+SLE, link to original
- lib/daemonize.c - relicensed from Public Domain to LGPL2.1+SLE,
link to original Public Domain version
Public Domain (CC-zero) to simplify reuse
- test-server/*.c
- test-server/*.h
GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999

View file

@ -14,8 +14,8 @@ environment:
- LWS_METHOD: nossl
CMAKE_ARGS: -DLWS_WITH_SSL=OFF
install:
- appveyor DownloadFile https://libwebsockets.org/Win32OpenSSL-1_0_2d.exe
- Win32OpenSSL-1_0_2d.exe /silent /verysilent /sp- /suppressmsgboxes
- appveyor DownloadFile https://slproweb.com/download/Win32OpenSSL-1_0_2g.exe
- Win32OpenSSL-1_0_2g.exe /silent /verysilent /sp- /suppressmsgboxes
- cinst -y nsis
- SET PATH=C:\Program Files\NSIS\;C:\Program Files (x86)\NSIS\;%PATH%
build:

View file

@ -33,7 +33,7 @@
* Bob Trower 08/04/01 -- Create Version 0.00.00B
*
* I cleaned it up quite a bit to match the (linux kernel) style of the rest
* of libwebsockets; this version is under LGPL2 like the rest of libwebsockets
* of libwebsockets; this version is under LGPL2.1 + SLE like the rest of lws
* since he explicitly allows sublicensing, but I give the URL above so you can
* get the original with Bob's super-liberal terms directly if you prefer.
*/

View file

@ -304,6 +304,10 @@ lws_client_connect_2(struct lws *wsi)
oom4:
lws_free(wsi->u.hdr.ah);
wsi->u.hdr.ah = NULL;
/* take care that we might be inserted in fds already */
if (wsi->position_in_fds_table != -1)
goto failed;
lws_free(wsi);
return NULL;
@ -359,6 +363,7 @@ lws_client_connect(struct lws_context *context, const char *address,
wsi->state = LWSS_CLIENT_UNCONNECTED;
wsi->protocol = NULL;
wsi->pending_timeout = NO_PENDING_TIMEOUT;
wsi->position_in_fds_table = -1;
#ifdef LWS_OPENSSL_SUPPORT
wsi->use_ssl = ssl_connection;

View file

@ -503,18 +503,18 @@ lws_client_interpret_server_handshake(struct lws *wsi)
* Now let's confirm it sent all the necessary headers
*/
if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) {
lwsl_info("no ACCEPT\n");
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP);
isErrorCodeReceived = 1;
goto bail3;
}
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP);
if (!p) {
lwsl_info("no URI\n");
goto bail3;
}
if (lws_hdr_total_length(wsi, WSI_TOKEN_ACCEPT) == 0) {
lwsl_info("no ACCEPT\n");
isErrorCodeReceived = 1;
goto bail3;
}
if (p && strncmp(p, "101", 3)) {
lwsl_warn(
"lws_client_handshake: got bad HTTP response '%s'\n", p);
@ -703,7 +703,7 @@ check_accept:
p = lws_hdr_simple_ptr(wsi, WSI_TOKEN_ACCEPT);
if (strcmp(p, wsi->u.hdr.ah->initial_handshake_hash_base64)) {
lwsl_warn("lws_client_int_s_hs: accept %s wrong vs %s\n", p,
lwsl_warn("lws_client_int_s_hs: accept '%s' wrong vs '%s'\n", p,
wsi->u.hdr.ah->initial_handshake_hash_base64);
goto bail2;
}
@ -751,6 +751,7 @@ check_accept:
lwsl_err("Out of Mem allocating rx buffer %d\n", n);
goto bail2;
}
wsi->u.ws.rx_ubuf_alloc = n;
lwsl_info("Allocating client RX buffer %d\n", n);
if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&n,
@ -789,7 +790,6 @@ check_accept:
return 0;
bail3:
lws_free_set_NULL(wsi->u.ws.rx_user_buffer);
close_reason = LWS_CLOSE_STATUS_NOSTATUS;
bail2:
@ -808,8 +808,7 @@ bail2:
lwsl_info("closing connection due to bail2 connection error\n");
/* free up his parsing allocations */
lws_free_set_NULL(wsi->u.hdr.ah);
/* closing will free up his parsing allocations */
lws_close_free_wsi(wsi, close_reason);
return 1;

View file

@ -261,6 +261,8 @@ lws_context_destroy(struct lws_context *context)
if (!context)
return;
context->being_destroyed = 1;
memset(&wsi, 0, sizeof(wsi));
wsi.context = context;
@ -302,6 +304,11 @@ lws_context_destroy(struct lws_context *context)
protocol++;
}
}
#ifdef LWS_USE_LIBEV
ev_io_stop(context->io_loop, &context->w_accept.watcher);
if(context->use_ev_sigint)
ev_signal_stop(context->io_loop, &context->w_sigint.watcher);
#endif /* LWS_USE_LIBEV */
lws_plat_context_early_destroy(context);
lws_ssl_context_destroy(context);

View file

@ -7,7 +7,8 @@
* he replied it is Public Domain. Use the URL above to get the original
* Public Domain version if you want it.
*
* This version is LGPL2 and is (c)2006 - 2013 Andy Green <andy@warmcat.com>
* This version is LGPL2.1+SLE like the rest of libwebsockets and is
* Copyright (c)2006 - 2013 Andy Green <andy@warmcat.com>
*/
#include <stdlib.h>

View file

@ -372,7 +372,8 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
if (addr4.sin_family == AF_UNSPEC)
return -1;
lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len);
if (lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len) == NULL)
return -1;
return 0;
#else

View file

@ -1555,11 +1555,25 @@ lws_b64_decode_string(const char *in, char *out, int out_size);
LWS_VISIBLE LWS_EXTERN const char *
lws_get_library_version(void);
/* access to headers... only valid while headers valid */
/*
* Access to http headers
*
* In lws the client http headers are temporarily malloc'd only for the
* duration of the http part of the handshake. It's because in most cases,
* the header content is ignored for the whole rest of the connection lifetime
* and would then just be taking up space needlessly.
*
* During LWS_CALLBACK_HTTP when the URI path is delivered is the last time
* the http headers are still allocated, you can use these apis then to
* look at and copy out interesting header content (cookies, etc)
*/
LWS_VISIBLE LWS_EXTERN int
lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
LWS_VISIBLE LWS_EXTERN int
lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
/*
* copies the whole, aggregated header, even if it was delivered in
* several actual headers piece by piece
@ -1576,6 +1590,7 @@ LWS_VISIBLE LWS_EXTERN int
lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
enum lws_token_indexes h, int frag_idx);
/* get the active file operations struct */
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
lws_get_fops(struct lws_context *context);

View file

@ -497,13 +497,13 @@ lws_plat_init(struct lws_context *context,
return 1;
}
if (lws_libev_init_fd_table(context))
/* libev handled it instead */
return 0;
if (!lws_libev_init_fd_table(context)) {
/* otherwise libev handled it instead */
if (pipe(context->dummy_pipe_fds)) {
lwsl_err("Unable to create pipe\n");
return 1;
if (pipe(context->dummy_pipe_fds)) {
lwsl_err("Unable to create pipe\n");
return 1;
}
}
/* use the read end of pipe as first item */

View file

@ -576,7 +576,7 @@ lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len)
int n;
n = recv(wsi->sock, (char *)buf, len, 0);
if (n >= 0)
if (n > 0)
return n;
#if LWS_POSIX
if (LWS_ERRNO == LWS_EAGAIN ||

View file

@ -81,6 +81,23 @@ int lws_free_header_table(struct lws *wsi)
return 0;
};
LWS_VISIBLE int
lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx)
{
int n;
n = wsi->u.hdr.ah->frag_index[h];
if (!n)
return 0;
do {
if (!frag_idx)
return wsi->u.hdr.ah->frags[n].len;
n = wsi->u.hdr.ah->frags[n].nfrag;
} while (frag_idx-- && n);
return 0;
}
LWS_VISIBLE int lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h)
{
int n;
@ -103,6 +120,9 @@ LWS_VISIBLE int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len,
int n = 0;
int f = wsi->u.hdr.ah->frag_index[h];
if (!f)
return -1;
while (n < frag_idx) {
f = wsi->u.hdr.ah->frags[f].nfrag;
if (!f)
@ -110,7 +130,7 @@ LWS_VISIBLE int lws_hdr_copy_fragment(struct lws *wsi, char *dst, int len,
n++;
}
if (wsi->u.hdr.ah->frags[f].len >= (len - 1))
if (wsi->u.hdr.ah->frags[f].len >= len)
return -1;
memcpy(dst, &wsi->u.hdr.ah->data[wsi->u.hdr.ah->frags[f].offset],
@ -218,6 +238,10 @@ static int issue_char(struct lws *wsi, unsigned char c)
/* Insert a null character when we *hit* the limit: */
if (frag_len == wsi->u.hdr.current_token_limit) {
if (wsi->u.hdr.ah->pos == sizeof(wsi->u.hdr.ah->data)) {
lwsl_warn("excessive header content 2\n");
return -1;
}
wsi->u.hdr.ah->data[wsi->u.hdr.ah->pos++] = '\0';
lwsl_warn("header %i exceeds limit\n",
wsi->u.hdr.parser_state);
@ -298,7 +322,8 @@ int lws_parse(struct lws *wsi, unsigned char c)
case URIES_SEEN_PERCENT_H1:
if (char_to_hex(c) < 0) {
/* regurgitate */
issue_char(wsi, '%');
if (issue_char(wsi, '%') < 0)
return -1;
wsi->u.hdr.ues = URIES_IDLE;
/* regurgitate + assess */
if (lws_parse(wsi, wsi->u.hdr.esc_stash) < 0)
@ -323,9 +348,12 @@ int lws_parse(struct lws *wsi, unsigned char c)
switch (wsi->u.hdr.ups) {
case URIPS_IDLE:
if (!c)
return -1;
/* genuine delimiter */
if (c == '&' && !enc) {
issue_char(wsi, c);
if ((c == '&' || c == ';') && !enc) {
if (issue_char(wsi, c) < 0)
return 1;
/* swallow the terminator */
ah->frags[ah->nfrag].len--;
/* link to next fragment */
@ -334,11 +362,23 @@ int lws_parse(struct lws *wsi, unsigned char c)
if (ah->nfrag >= ARRAY_SIZE(ah->frags))
goto excessive;
/* start next fragment after the & */
wsi->u.hdr.post_literal_equal = 0;
ah->frags[ah->nfrag].offset = ah->pos;
ah->frags[ah->nfrag].len = 0;
ah->frags[ah->nfrag].nfrag = 0;
goto swallow;
}
/* uriencoded = in the name part, disallow */
if (c == '=' && enc && !wsi->u.hdr.post_literal_equal)
c = '_';
/* after the real =, we don't care how many = */
if (c == '=' && !enc)
wsi->u.hdr.post_literal_equal = 1;
/* + to space */
if (c == '+' && !enc)
c = ' ';
/* issue the first / always */
if (c == '/' && !ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS])
wsi->u.hdr.ups = URIPS_SEEN_SLASH;
@ -400,7 +440,8 @@ int lws_parse(struct lws *wsi, unsigned char c)
if (c == '?' && !enc &&
!ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS]) { /* start of URI arguments */
/* seal off uri header */
ah->data[ah->pos++] = '\0';
if (issue_char(wsi, '\0') < 0)
return -1;
/* move to using WSI_TOKEN_HTTP_URI_ARGS */
ah->nfrag++;
@ -410,6 +451,7 @@ int lws_parse(struct lws *wsi, unsigned char c)
ah->frags[ah->nfrag].len = 0;
ah->frags[ah->nfrag].nfrag = 0;
wsi->u.hdr.post_literal_equal = 0;
ah->frag_index[WSI_TOKEN_HTTP_URI_ARGS] = ah->nfrag;
wsi->u.hdr.ups = URIPS_IDLE;
goto swallow;
@ -538,14 +580,8 @@ excessive:
while (ah->frags[n].nfrag)
n = ah->frags[n].nfrag;
ah->frags[n].nfrag = ah->nfrag;
if (ah->pos == sizeof(ah->data)) {
lwsl_warn("excessive header content\n");
if (issue_char(wsi, ' ') < 0)
return -1;
}
ah->data[ah->pos++] = ' ';
ah->frags[ah->nfrag].len++;
break;
/* skipping arg part of a name we didn't recognize */
@ -855,6 +891,10 @@ handle_first:
return 1;
}
if (wsi->u.ws.rx_user_buffer_head + LWS_SEND_BUFFER_PRE_PADDING >= wsi->u.ws.rx_ubuf_alloc) {
lwsl_err("Attempted overflow\n");
return -1;
}
if (wsi->u.ws.all_zero_nonce)
wsi->u.ws.rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING +
(wsi->u.ws.rx_user_buffer_head++)] = c;

View file

@ -535,6 +535,7 @@ struct lws_context {
void *user_space;
struct lws_plat_file_ops fops;
unsigned int being_destroyed:1;
};
enum {
@ -810,6 +811,7 @@ struct _lws_header_related {
enum uri_path_states ups;
enum uri_esc_states ues;
char esc_stash;
char post_literal_equal;
};
struct _lws_websocket_related {
@ -817,6 +819,7 @@ struct _lws_websocket_related {
unsigned int rx_user_buffer_head;
unsigned char mask_nonce[4];
unsigned char frame_mask_index;
unsigned int rx_ubuf_alloc;
size_t rx_packet_length;
unsigned char opcode;
unsigned int final:1;

View file

@ -270,8 +270,7 @@ handshake_0405(struct lws_context *context, struct lws *wsi)
bail:
/* free up his parsing allocations */
lws_free_header_table(wsi);
/* caller will free up his parsing allocations */
return -1;
}

View file

@ -149,6 +149,9 @@ bail:
int
_lws_rx_flow_control(struct lws *wsi)
{
if (!wsi || wsi->context->being_destroyed)
return 0;
/* there is no pending change */
if (!(wsi->rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE))
return 0;
@ -344,6 +347,9 @@ int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
/* LWSCM_WS_SERVING */
while (len--) {
assert(wsi->mode == LWSCM_HTTP_SERVING);
if (lws_parse(wsi, *(*buf)++)) {
lwsl_info("lws_parse failed\n");
goto bail_nuke_ah;
@ -359,33 +365,40 @@ int lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len)
/* is this websocket protocol or normal http 1.0? */
if (!lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE) ||
!lws_hdr_total_length(wsi, WSI_TOKEN_CONNECTION)) {
ah = wsi->u.hdr.ah;
lws_union_transition(wsi, LWSCM_HTTP_SERVING_ACCEPTED);
wsi->state = LWSS_HTTP;
wsi->u.http.fd = LWS_INVALID_FILE;
/* expose it at the same offset as u.hdr */
wsi->u.http.ah = ah;
n = lws_http_action(wsi);
return n;
if (lws_hdr_total_length(wsi, WSI_TOKEN_UPGRADE)) {
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
"websocket")) {
lwsl_info("Upgrade to ws\n");
goto upgrade_ws;
}
#ifdef LWS_USE_HTTP2
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
"h2c-14")) {
lwsl_info("Upgrade to h2c-14\n");
goto upgrade_h2c;
}
#endif
lwsl_err("Unknown upgrade\n");
/* dunno what he wanted to upgrade to */
goto bail_nuke_ah;
}
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
"websocket"))
goto upgrade_ws;
#ifdef LWS_USE_HTTP2
if (!strcasecmp(lws_hdr_simple_ptr(wsi, WSI_TOKEN_UPGRADE),
"h2c-14"))
goto upgrade_h2c;
#endif
/* dunno what he wanted to upgrade to */
goto bail_nuke_ah;
/* no upgrade ack... he remained as HTTP */
lwsl_info("No upgrade\n");
ah = wsi->u.hdr.ah;
lws_union_transition(wsi, LWSCM_HTTP_SERVING_ACCEPTED);
wsi->state = LWSS_HTTP;
wsi->u.http.fd = LWS_INVALID_FILE;
/* expose it at the same offset as u.hdr */
wsi->u.http.ah = ah;
lwsl_debug("%s: wsi %p: ah %p\n", __func__, (void *)wsi, (void *)wsi->u.hdr.ah);
n = lws_http_action(wsi);
return n;
#ifdef LWS_USE_HTTP2
upgrade_h2c:
@ -566,6 +579,7 @@ upgrade_ws:
lwsl_err("Out of Mem allocating rx buffer %d\n", n);
return 1;
}
wsi->u.ws.rx_ubuf_alloc = n;
lwsl_info("Allocating RX buffer %d\n", n);
#if LWS_POSIX
if (setsockopt(wsi->sock, SOL_SOCKET, SO_SNDBUF,
@ -574,8 +588,9 @@ upgrade_ws:
return 1;
}
#endif
lwsl_parser("accepted v%02d connection\n",
wsi->ietf_spec_revision);
lwsl_parser("accepted v%02d connection\n", wsi->ietf_spec_revision);
return 0;
} /* while all chars are handled */
return 0;

View file

@ -1,66 +1,83 @@
Name: libwebsockets
Version: 1.4
Release: 48.gmaster_16fb0132%{?dist}
Summary: Websocket Server Library
Name: libwebsockets
Version: 1.6.3
Release: 1%{?dist}
Summary: A lightweight C library for Websockets
Group: System
License: GPL
URL: http://warmcat.com
Source0: %{name}-%{version}.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
Group: System Environment/Libraries
# base64-decode.c and ssl-http2.c is under MIT license with FPC exception.
# https://fedorahosted.org/fpc/ticket/546
# sha-1.c is BSD 3 clause, but we link to openssl instead.
# getifaddrs is BSD 3 clause, but we use system-provided instead.
# source tarball contains BSD and zlib licensed code in win32port.
License: LGPLv2 with exceptions and MIT and BSD and zlib
URL: http://libwebsockets.org
Source0: https://github.com/warmcat/libwebsockets/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
BuildRequires: openssl-devel
Requires: openssl
BuildRequires: cmake
BuildRequires: openssl-devel
Requires: openssl
Provides: bundled(base64-decode)
Provides: bundled(ssl-http2)
%description
Webserver server library
This is the libwebsockets C library for lightweight websocket clients and
servers.
%package devel
Summary: Development files for libwebsockets
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: openssl-devel
Summary: Headers for developing programs that will use %{name}
Group: Development/Libraries
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: openssl-devel
%description devel
Development files for libwebsockets
This package contains the header files needed for developing
%{name} applications.
%prep
%setup -q
%setup -qn %{name}-%{version}
%build
mkdir -p build
cd build
%cmake ..
make
%cmake \
-D LWS_LINK_TESTAPPS_DYNAMIC=ON \
-D LWS_USE_LIBEV=OFF \
-D LWS_USE_BUNDLED_ZLIB=OFF \
-D LWS_WITHOUT_BUILTIN_GETIFADDRS=ON \
-D LWS_WITHOUT_BUILTIN_SHA1=ON \
-D LWS_WITH_STATIC=OFF \
..
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
cd build
make install DESTDIR=$RPM_BUILD_ROOT
%post -p /sbin/ldconfig
%clean
rm -rf $RPM_BUILD_ROOT
%postun -p /sbin/ldconfig
%files
%defattr(-,root,root,-)
%attr(755,root,root) /usr/bin/libwebsockets-test-server
%attr(755,root,root) /usr/bin/libwebsockets-test-server-extpoll
%attr(755,root,root) /usr/bin/libwebsockets-test-client
%attr(755,root,root) /usr/bin/libwebsockets-test-ping
%attr(755,root,root) /usr/bin/libwebsockets-test-echo
%attr(755,root,root) /usr/bin/libwebsockets-test-fraggle
%attr(755,root,root)
/%{_libdir}/libwebsockets.so.5
/%{_libdir}/libwebsockets.so
%attr(755,root,root) /usr/share/libwebsockets-test-server
%doc
%license LICENSE
%doc README.md
%{_libdir}/%{name}.so.*
%{_libdir}/cmake/%{name}*
%files devel
%defattr(-,root,root,-)
/usr/include/*
%attr(755,root,root)
/%{_libdir}/libwebsockets.a
/%{_libdir}/pkgconfig/libwebsockets.pc
%license LICENSE
%doc README.coding.md README.test-apps.md changelog libwebsockets-api-doc.html
%{_bindir}/%{name}*
%{_includedir}/%{name}.h
%{_includedir}/lws_config.h
%{_libdir}/%{name}.so
%{_libdir}/pkgconfig/%{name}.pc
%{_datadir}/libwebsockets-test-server
%changelog
* Tue Feb 9 2016 Andrew Cooks <acooks@linux.com> 1.6.3-1
- Update to version 1.6.3
* Sun Jan 17 2016 Andrew Cooks <acooks@linux.com> 1.6.0-1
- First attempt at a repeatable packaging process

View file

@ -21,7 +21,7 @@
#define LWS_LIBRARY_VERSION_MINOR ${LWS_LIBRARY_VERSION_MINOR}
#define LWS_LIBRARY_VERSION_PATCH ${LWS_LIBRARY_VERSION_PATCH}
/* LWS_LIBRARY_VERSION_NUMBER looks like 1005001 for e.g. version 1.5.1 */
#define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_MAJOR*1000000)+(LWS_LIBRARY_VERSION_MINOR*1000)+LWS_LIBRARY_VERSION_PATCH
#define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_VERSION_MAJOR*1000000)+(LWS_LIBRARY_VERSION_MINOR*1000)+LWS_LIBRARY_VERSION_PATCH
/* The current git commit hash that we're building from */
#cmakedefine LWS_BUILD_HASH "${LWS_BUILD_HASH}"

View file

@ -83,6 +83,20 @@ check 2 "Root_Channels_1_Channel_name_http_post=?"
check 3 "Root_Channels_1_Channel_location_http_post=?"
check
echo
echo "---- ? processing (/cgi-bin/settings.js?key1=value1)"
rm -f /tmp/lwscap
echo -e "GET /cgi-bin/settings.js?key1=value1 HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap
check 1 "key1=value1"
check
echo
echo "---- ? processing (/test?key1%3d2=value1)"
rm -f /tmp/lwscap
echo -e "GET /test?key1%3d2=value1 HTTP/1.1\x0d\x0a\x0d\x0a" | nc $SERVER $PORT | sed '1,/^\r$/d'> /tmp/lwscap
check 1 "key1_2=value1"
check
echo
echo "---- ? processing (%2f%2e%2e%2f%2e./test.html?arg=1)"
rm -f /tmp/lwscap

View file

@ -3,20 +3,19 @@
*
* Copyright (C) 2011 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 <stdio.h>

View file

@ -1,25 +1,21 @@
/*
* libwebsockets-test-echo - libwebsockets echo test implementation
*
* This implements both the client and server sides. It defaults to
* serving, use --client <remote address> to connect as client.
* libwebsockets-test-echo
*
* Copyright (C) 2010-2013 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 <stdio.h>

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-fraggle - random fragmentation test
*
* Copyright (C) 2010-2011 Andy Green <andy@warmcat.com>
* Copyright (C) 2011-2016 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 <stdio.h>

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-ping - libwebsockets floodping
* libwebsockets-test-ping - libwebsockets test floodping
*
* Copyright (C) 2011 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 <stdio.h>

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 "test-server.h"

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 "test-server.h"
@ -62,7 +61,7 @@ struct serveable {
void
dump_handshake_info(struct lws *wsi)
{
int n = 0;
int n = 0, len;
char buf[256];
const unsigned char *c;
@ -73,12 +72,14 @@ dump_handshake_info(struct lws *wsi)
continue;
}
if (!lws_hdr_total_length(wsi, n)) {
len = lws_hdr_total_length(wsi, n);
if (!len || len > sizeof(buf) - 1) {
n++;
continue;
}
lws_hdr_copy(wsi, buf, sizeof buf, n);
buf[sizeof(buf) - 1] = '\0';
fprintf(stderr, " %s = %s\n", (char *)c, buf);
n++;

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 "test-server.h"

View file

@ -3,20 +3,19 @@
*
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 "test-server.h"

View file

@ -1,22 +1,21 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
* libwebsockets-test-servet - libwebsockets test implementation
*
* Copyright (C) 2010-2015 Andy Green <andy@warmcat.com>
* Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation:
* version 2.1 of the License.
* This file is made available under the Creative Commons CC0 1.0
* Universal Public Domain Dedication.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
* 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 "test-server.h"

View file

@ -1,3 +1,23 @@
/*
* libwebsockets-test-server - libwebsockets test implementation
*
* Copyright (C) 2010-2016 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.
*/
#if defined(_WIN32) && defined(EXTERNAL_POLL)
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600