From d8b8542d59736bbf7c2cc1fbceb14310e5630a03 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 19 Jun 2013 15:10:26 +0200 Subject: [PATCH 1/6] Declare "sha1_init" statically to avoid naming conflicts if linked statically with other libraries providing a method with the same name (e.g. OpenSSL). --- lib/sha-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sha-1.c b/lib/sha-1.c index 6020c227e..1491502d2 100644 --- a/lib/sha-1.c +++ b/lib/sha-1.c @@ -215,7 +215,7 @@ sha1_step(struct sha1_ctxt *ctxt) /*------------------------------------------------------------*/ -void +static void sha1_init(struct sha1_ctxt *ctxt) { bzero(ctxt, sizeof(struct sha1_ctxt)); From d727e9f698e91e1832a53e088ad54f2fda69dba8 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Sun, 23 Jun 2013 14:47:26 +0800 Subject: [PATCH 2/6] Support empty ping and pong packets. --- lib/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/output.c b/lib/output.c index ef823c3e9..37502dd27 100644 --- a/lib/output.c +++ b/lib/output.c @@ -311,7 +311,7 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, int m; #endif - if (len == 0 && protocol != LWS_WRITE_CLOSE) { + if (len == 0 && protocol != LWS_WRITE_CLOSE && protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) { lwsl_warn("zero length libwebsocket_write attempt\n"); return 0; } From db761be972dbeb8a9d5f96d7181860c887bd668b Mon Sep 17 00:00:00 2001 From: "Niall T. Davidson" Date: Sat, 29 Jun 2013 10:16:18 +0800 Subject: [PATCH 3/6] Added additional LWS_CALLBACK_CLOSED_HTTP callback to just_kill_connection branch of close_and_free_session --- lib/libwebsockets.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index e75a51009..661876eda 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -370,6 +370,10 @@ just_kill_connection: lwsl_debug("calling back CLOSED\n"); wsi->protocol->callback(context, wsi, LWS_CALLBACK_CLOSED, wsi->user_space, NULL, 0); + } else if ( wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED ) { + lwsl_debug("calling back CLOSED_HTTP\n"); + context->protocols[0].callback(context, wsi, + LWS_CALLBACK_CLOSED_HTTP, wsi->user_space, NULL, 0 ); } else lwsl_debug("not calling back closed\n"); From eb51a7a6efc3c9941d3ccb862936395966deba7c Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Sat, 29 Jun 2013 10:18:52 +0800 Subject: [PATCH 4/6] add CMake find function for libwebsockets Signed-off-by: Jiri Hnidek --- scripts/FindLibWebSockets.cmake | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/FindLibWebSockets.cmake diff --git a/scripts/FindLibWebSockets.cmake b/scripts/FindLibWebSockets.cmake new file mode 100644 index 000000000..e7d283932 --- /dev/null +++ b/scripts/FindLibWebSockets.cmake @@ -0,0 +1,33 @@ +# This module tries to find libWebsockets library and include files +# +# LIBWEBSOCKETS_INCLUDE_DIR, path where to find libwebsockets.h +# LIBWEBSOCKETS_LIBRARY_DIR, path where to find libwebsockets.so +# LIBWEBSOCKETS_LIBRARIES, the library to link against +# LIBWEBSOCKETS_FOUND, If false, do not try to use libWebSockets +# +# This currently works probably only for Linux + +FIND_PATH ( LIBWEBSOCKETS_INCLUDE_DIR libwebsockets.h + /usr/local/include + /usr/include +) + +FIND_LIBRARY ( LIBWEBSOCKETS_LIBRARIES websockets + /usr/local/lib + /usr/lib +) + +GET_FILENAME_COMPONENT( LIBWEBSOCKETS_LIBRARY_DIR ${LIBWEBSOCKETS_LIBRARIES} PATH ) + +SET ( LIBWEBSOCKETS_FOUND "NO" ) +IF ( LIBWEBSOCKETS_INCLUDE_DIR ) + IF ( LIBWEBSOCKETS_LIBRARIES ) + SET ( LIBWEBSOCKETS_FOUND "YES" ) + ENDIF ( LIBWEBSOCKETS_LIBRARIES ) +ENDIF ( LIBWEBSOCKETS_INCLUDE_DIR ) + +MARK_AS_ADVANCED( + LIBWEBSOCKETS_LIBRARY_DIR + LIBWEBSOCKETS_INCLUDE_DIR + LIBWEBSOCKETS_LIBRARIES +) From 8294c1fa4f6485fa6c5f15078d609f62b3026d98 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Sat, 29 Jun 2013 10:22:09 +0800 Subject: [PATCH 5/6] Request "send" not to trigger SIGPIPE on errors. --- lib/client-handshake.c | 2 +- lib/client.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client-handshake.c b/lib/client-handshake.c index de99a208e..2dd810c56 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -85,7 +85,7 @@ struct libwebsocket *__libwebsocket_client_connect_2( if (context->http_proxy_port) { - n = send(wsi->sock, context->service_buffer, plen, 0); + n = send(wsi->sock, context->service_buffer, plen, MSG_NOSIGNAL); if (n < 0) { compatible_close(wsi->sock); lwsl_debug("ERROR writing to proxy socket\n"); diff --git a/lib/client.c b/lib/client.c index b6236a2b8..94a669471 100644 --- a/lib/client.c +++ b/lib/client.c @@ -229,7 +229,7 @@ int lws_client_socket_service(struct libwebsocket_context *context, else #endif n = send(wsi->sock, context->service_buffer, - p - (char *)context->service_buffer, 0); + p - (char *)context->service_buffer, MSG_NOSIGNAL); lws_latency(context, wsi, "send or SSL_write LWS_CONNMODE...HANDSHAKE", n, n >= 0); From 6c58228577306c023b072b5c7c7a2b044a94f12a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Sat, 29 Jun 2013 10:24:16 +0800 Subject: [PATCH 6/6] fix http incomplete send handling Signed-off-by: David Gauchard --- lib/output.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/output.c b/lib/output.c index 37502dd27..224a0f27a 100644 --- a/lib/output.c +++ b/lib/output.c @@ -504,7 +504,6 @@ send_raw: LWS_VISIBLE int libwebsockets_serve_http_file_fragment( struct libwebsocket_context *context, struct libwebsocket *wsi) { - int ret = 0; int n, m; while (!lws_send_pipe_choked(wsi)) { @@ -516,7 +515,7 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment( if (m < 0) return -1; - wsi->u.http.filepos += n; + wsi->u.http.filepos += m; if (m != n) /* adjust for what was not sent */ lseek(wsi->u.http.fd, m - n, SEEK_CUR); @@ -525,23 +524,23 @@ LWS_VISIBLE int libwebsockets_serve_http_file_fragment( if (n < 0) return -1; /* caller will close */ - if (n < sizeof(context->service_buffer) || - wsi->u.http.filepos == wsi->u.http.filelen) { + if (wsi->u.http.filepos == wsi->u.http.filelen) { wsi->state = WSI_STATE_HTTP; if (wsi->protocol->callback) - ret = user_callback_handle_rxflow( + /* ignore callback returned value */ + user_callback_handle_rxflow( wsi->protocol->callback, context, wsi, LWS_CALLBACK_HTTP_FILE_COMPLETION, wsi->user_space, NULL, 0); - return ret; + return 1; /* >0 indicates completed */ } } lwsl_notice("choked before able to send whole file (post)\n"); libwebsocket_callback_on_writable(context, wsi); - return ret; + return 0; /* indicates further processing must be done */ } /**