WebSockets: make support official (non-experimental)

Inverts the configure/cmake options to instead provide options that
disable WebSockets and have them (ws + wss) enabled by default.

Closes #14936
This commit is contained in:
Daniel Stenberg 2024-09-27 13:19:55 +02:00
parent cfae354a9a
commit d78e129d50
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
26 changed files with 108 additions and 107 deletions

View File

@ -345,6 +345,8 @@ mark_as_advanced(CURL_DISABLE_SMB)
option(CURL_DISABLE_SMTP "Disable SMTP" OFF) option(CURL_DISABLE_SMTP "Disable SMTP" OFF)
mark_as_advanced(CURL_DISABLE_SMTP) mark_as_advanced(CURL_DISABLE_SMTP)
option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF) option(CURL_DISABLE_SOCKETPAIR "Disable use of socketpair for curl_multi_poll" OFF)
option(CURL_DISABLE_WEBSOCKETS "Disable WebSockets" OFF)
mark_as_advanced(CURL_DISABLE_WEBSOCKETS)
mark_as_advanced(CURL_DISABLE_SOCKETPAIR) mark_as_advanced(CURL_DISABLE_SOCKETPAIR)
option(CURL_DISABLE_TELNET "Disable Telnet" OFF) option(CURL_DISABLE_TELNET "Disable Telnet" OFF)
mark_as_advanced(CURL_DISABLE_TELNET) mark_as_advanced(CURL_DISABLE_TELNET)
@ -1608,16 +1610,12 @@ unset(CMAKE_REQUIRED_FLAGS)
option(ENABLE_WEBSOCKETS "Enable WebSockets (experimental)" OFF) option(ENABLE_WEBSOCKETS "Enable WebSockets (experimental)" OFF)
if(ENABLE_WEBSOCKETS) foreach(_curl_test IN ITEMS
if(SIZEOF_CURL_OFF_T GREATER 4) HAVE_GLIBC_STRERROR_R
set(USE_WEBSOCKETS ON) HAVE_POSIX_STRERROR_R
else() )
message(WARNING "curl_off_t is too small to enable WebSockets") curl_internal_test(${_curl_test})
endif() endforeach()
endif()
curl_internal_test(HAVE_GLIBC_STRERROR_R)
curl_internal_test(HAVE_POSIX_STRERROR_R)
# Check for reentrant # Check for reentrant
foreach(_curl_test IN ITEMS foreach(_curl_test IN ITEMS
@ -1855,8 +1853,8 @@ _add_if("IPNS" NOT CURL_DISABLE_IPFS)
_add_if("RTSP" NOT CURL_DISABLE_RTSP) _add_if("RTSP" NOT CURL_DISABLE_RTSP)
_add_if("RTMP" USE_LIBRTMP) _add_if("RTMP" USE_LIBRTMP)
_add_if("MQTT" NOT CURL_DISABLE_MQTT) _add_if("MQTT" NOT CURL_DISABLE_MQTT)
_add_if("WS" USE_WEBSOCKETS) _add_if("WS" NOT CURL_DISABLE_WEBSOCKETS)
_add_if("WSS" USE_WEBSOCKETS AND _ssl_enabled) _add_if("WSS" NOT CURL_DISABLE_WEBSOCKETS AND _ssl_enabled)
if(_items) if(_items)
list(SORT _items) list(SORT _items)
endif() endif()

View File

@ -175,7 +175,6 @@ curl_verbose_msg="enabled (--disable-verbose)"
curl_altsvc_msg="enabled (--disable-alt-svc)" curl_altsvc_msg="enabled (--disable-alt-svc)"
curl_headers_msg="enabled (--disable-headers-api)" curl_headers_msg="enabled (--disable-headers-api)"
curl_hsts_msg="enabled (--disable-hsts)" curl_hsts_msg="enabled (--disable-hsts)"
curl_ws_msg="no (--enable-websockets)"
ssl_backends= ssl_backends=
curl_h1_msg="enabled (internal)" curl_h1_msg="enabled (internal)"
curl_h2_msg="no (--with-nghttp2)" curl_h2_msg="no (--with-nghttp2)"
@ -4954,6 +4953,7 @@ if test "x$OPENSSL_ENABLED" = "x1"; then
AC_CHECK_FUNCS([SSL_set0_wbio]) AC_CHECK_FUNCS([SSL_set0_wbio])
fi fi
if test "x$CURL_DISABLE_HTTP" != "x1"; then
dnl ************************************************************* dnl *************************************************************
dnl WebSockets dnl WebSockets
dnl dnl
@ -4964,27 +4964,28 @@ AS_HELP_STRING([--disable-websockets],[Disable WebSockets support]),
[ case "$enableval" in [ case "$enableval" in
no) no)
AC_MSG_RESULT(no) AC_MSG_RESULT(no)
AC_DEFINE(CURL_DISABLE_WEBSOCKETS, [1], [disable WebSockets])
AC_SUBST(CURL_DISABLE_WEBSOCKETS, [1])
;; ;;
*) *)
if test ${ac_cv_sizeof_curl_off_t} -gt 4; then if test ${ac_cv_sizeof_curl_off_t} -gt 4; then
AC_MSG_RESULT(yes) AC_MSG_RESULT(yes)
curl_ws_msg="enabled"
AC_DEFINE_UNQUOTED(USE_WEBSOCKETS, [1], [enable WebSockets support])
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS WS"
if test "x$SSL_ENABLED" = "x1"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS WSS"
fi
experimental="$experimental WebSockets"
else else
dnl WebSockets requires >32 bit curl_off_t dnl WebSockets requires >32 bit curl_off_t
AC_MSG_RESULT(no) AC_MSG_RESULT(no)
AC_MSG_WARN([WebSockets disabled due to lack of >32 bit curl_off_t]) AC_MSG_WARN([WebSockets disabled due to lack of >32 bit curl_off_t])
AC_DEFINE(CURL_DISABLE_WEBSOCKETS, [1], [disable WebSockets])
AC_SUBST(CURL_DISABLE_WEBSOCKETS, [1])
fi fi
;; ;;
esac ], esac ],
AC_MSG_RESULT(no) AC_MSG_RESULT(yes)
) )
else
AC_MSG_WARN([WebSockets disabled because HTTP is disabled])
AC_DEFINE(CURL_DISABLE_WEBSOCKETS, [1], [disable WebSockets])
AC_SUBST(CURL_DISABLE_WEBSOCKETS, [1])
fi
dnl ************************************************************ dnl ************************************************************
dnl hiding of library internal symbols dnl hiding of library internal symbols
@ -5311,6 +5312,12 @@ fi
if test "x$USE_LIBRTMP" = "x1"; then if test "x$USE_LIBRTMP" = "x1"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS RTMP" SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS RTMP"
fi fi
if test "x$CURL_DISABLE_WEBSOCKETS" != "x1"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS WS"
if test "x$SSL_ENABLED" = "x1"; then
SUPPORT_PROTOCOLS="$SUPPORT_PROTOCOLS WSS"
fi
fi
dnl replace spaces with newlines dnl replace spaces with newlines
dnl sort the lines dnl sort the lines
@ -5428,7 +5435,6 @@ AC_MSG_NOTICE([Configured to build curl/libcurl:
HTTP2: ${curl_h2_msg} HTTP2: ${curl_h2_msg}
HTTP3: ${curl_h3_msg} HTTP3: ${curl_h3_msg}
ECH: ${curl_ech_msg} ECH: ${curl_ech_msg}
WebSockets: ${curl_ws_msg}
Protocols: ${SUPPORT_PROTOCOLS_LOWER} Protocols: ${SUPPORT_PROTOCOLS_LOWER}
Features: ${SUPPORT_FEATURES} Features: ${SUPPORT_FEATURES}
]) ])

View File

@ -185,3 +185,7 @@ Disable the TFTP protocol
## `CURL_DISABLE_VERBOSE_STRINGS` ## `CURL_DISABLE_VERBOSE_STRINGS`
Disable verbose strings and error messages. Disable verbose strings and error messages.
## `CURL_DISABLE_WEBSOCKETS`
Disable the WebSocket protocols.

View File

@ -57,15 +57,6 @@ Graduation requirements:
- a reasonable expectation of a stable API going forward. - a reasonable expectation of a stable API going forward.
### WebSocket
Graduation requirements:
- feedback from users saying that the API works for their specific use cases
- unless the above happens, we consider WebSocket silently working by
September 2024 when it has been stewing as EXPERIMENTAL for two years.
## ECH ## ECH
Use of the HTTPS resource record and Encrypted Client Hello (ECH) when using Use of the HTTPS resource record and Encrypted Client Hello (ECH) when using

View File

@ -482,7 +482,7 @@ CURLcode Curl_hyper_stream(struct Curl_easy *data,
k->deductheadercount = k->deductheadercount =
(100 <= http_status && 199 >= http_status) ? k->headerbytecount : 0; (100 <= http_status && 199 >= http_status) ? k->headerbytecount : 0;
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
if(k->upgr101 == UPGR101_WS) { if(k->upgr101 == UPGR101_WS) {
if(http_status == 101) { if(http_status == 101) {
/* verify the response */ /* verify the response */

View File

@ -148,6 +148,9 @@
/* disables SMTP */ /* disables SMTP */
#cmakedefine CURL_DISABLE_SMTP 1 #cmakedefine CURL_DISABLE_SMTP 1
/* disabled WebSockets */
#cmakedefine CURL_DISABLE_WEBSOCKETS 1
/* disables use of socketpair for curl_multi_poll */ /* disables use of socketpair for curl_multi_poll */
#cmakedefine CURL_DISABLE_SOCKETPAIR 1 #cmakedefine CURL_DISABLE_SOCKETPAIR 1
@ -812,9 +815,6 @@ ${SIZEOF_TIME_T_CODE}
/* to enable Apple IDN */ /* to enable Apple IDN */
#cmakedefine USE_APPLE_IDN 1 #cmakedefine USE_APPLE_IDN 1
/* Define to 1 to enable websocket support. */
#cmakedefine USE_WEBSOCKETS 1
/* Define to 1 if OpenSSL has the SSL_CTX_set_srp_username function. */ /* Define to 1 if OpenSSL has the SSL_CTX_set_srp_username function. */
#cmakedefine HAVE_OPENSSL_SRP 1 #cmakedefine HAVE_OPENSSL_SRP 1

View File

@ -239,7 +239,7 @@ void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
} }
#endif /* !CURL_DISABLE_SMTP */ #endif /* !CURL_DISABLE_SMTP */
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
struct curl_trc_feat Curl_trc_feat_ws = { struct curl_trc_feat Curl_trc_feat_ws = {
"WS", "WS",
CURL_LOG_LVL_NONE, CURL_LOG_LVL_NONE,
@ -255,7 +255,7 @@ void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
} }
#endif /* USE_WEBSOCKETS && !CURL_DISABLE_HTTP */ #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
#define TRC_CT_NONE (0) #define TRC_CT_NONE (0)
#define TRC_CT_PROTOCOL (1<<(0)) #define TRC_CT_PROTOCOL (1<<(0))
@ -279,7 +279,7 @@ static struct trc_feat_def trc_feats[] = {
#ifndef CURL_DISABLE_SMTP #ifndef CURL_DISABLE_SMTP
{ &Curl_trc_feat_smtp, TRC_CT_PROTOCOL }, { &Curl_trc_feat_smtp, TRC_CT_PROTOCOL },
#endif #endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
{ &Curl_trc_feat_ws, TRC_CT_PROTOCOL }, { &Curl_trc_feat_ws, TRC_CT_PROTOCOL },
#endif #endif
}; };

View File

@ -94,11 +94,11 @@ void Curl_failf(struct Curl_easy *data,
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \ do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_smtp)) \
Curl_trc_smtp(data, __VA_ARGS__); } while(0) Curl_trc_smtp(data, __VA_ARGS__); } while(0)
#endif /* !CURL_DISABLE_SMTP */ #endif /* !CURL_DISABLE_SMTP */
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS(data, ...) \ #define CURL_TRC_WS(data, ...) \
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \ do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \
Curl_trc_ws(data, __VA_ARGS__); } while(0) Curl_trc_ws(data, __VA_ARGS__); } while(0)
#endif /* USE_WEBSOCKETS && !CURL_DISABLE_HTTP */ #endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
#else /* CURL_HAVE_C99 */ #else /* CURL_HAVE_C99 */
@ -113,7 +113,7 @@ void Curl_failf(struct Curl_easy *data,
#ifndef CURL_DISABLE_SMTP #ifndef CURL_DISABLE_SMTP
#define CURL_TRC_SMTP Curl_trc_smtp #define CURL_TRC_SMTP Curl_trc_smtp
#endif #endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS Curl_trc_ws #define CURL_TRC_WS Curl_trc_ws
#endif #endif
@ -169,7 +169,7 @@ extern struct curl_trc_feat Curl_trc_feat_smtp;
void Curl_trc_smtp(struct Curl_easy *data, void Curl_trc_smtp(struct Curl_easy *data,
const char *fmt, ...) CURL_PRINTF(2, 3); const char *fmt, ...) CURL_PRINTF(2, 3);
#endif #endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
extern struct curl_trc_feat Curl_trc_feat_ws; extern struct curl_trc_feat Curl_trc_feat_ws;
void Curl_trc_ws(struct Curl_easy *data, void Curl_trc_ws(struct Curl_easy *data,
const char *fmt, ...) CURL_PRINTF(2, 3); const char *fmt, ...) CURL_PRINTF(2, 3);
@ -226,7 +226,7 @@ static void Curl_trc_smtp(struct Curl_easy *data, const char *fmt, ...)
(void)data; (void)fmt; (void)data; (void)fmt;
} }
#endif #endif
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) || !defined(CURL_DISABLE_HTTP)
static void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...) static void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
{ {
(void)data; (void)fmt; (void)data; (void)fmt;

View File

@ -1247,7 +1247,7 @@ CURLcode curl_easy_recv(struct Curl_easy *data, void *buffer, size_t buflen,
return CURLE_OK; return CURLE_OK;
} }
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
CURLcode Curl_connect_only_attach(struct Curl_easy *data) CURLcode Curl_connect_only_attach(struct Curl_easy *data)
{ {
CURLcode result; CURLcode result;
@ -1264,7 +1264,7 @@ CURLcode Curl_connect_only_attach(struct Curl_easy *data)
return CURLE_OK; return CURLE_OK;
} }
#endif /* USE_WEBSOCKETS */ #endif /* !CURL_DISABLE_WEBSOCKETS */
/* /*
* Sends data over the connected socket. * Sends data over the connected socket.

View File

@ -30,7 +30,7 @@
CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer, CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
size_t buflen, size_t *n); size_t buflen, size_t *n);
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
CURLcode Curl_connect_only_attach(struct Curl_easy *data); CURLcode Curl_connect_only_attach(struct Curl_easy *data);
#endif #endif

View File

@ -2697,7 +2697,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
} }
result = Curl_http_cookies(data, conn, &req); result = Curl_http_cookies(data, conn, &req);
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS)) if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS))
result = Curl_ws_request(data, &req); result = Curl_ws_request(data, &req);
#endif #endif
@ -3449,7 +3449,7 @@ static CURLcode http_on_response(struct Curl_easy *data,
goto out; goto out;
*pconsumed += blen; *pconsumed += blen;
} }
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
else if(k->upgr101 == UPGR101_WS) { else if(k->upgr101 == UPGR101_WS) {
/* verify the response. Any passed `buf` bytes are already in /* verify the response. Any passed `buf` bytes are already in
* WebSockets format and taken in by the protocol handler. */ * WebSockets format and taken in by the protocol handler. */
@ -3534,7 +3534,7 @@ static CURLcode http_on_response(struct Curl_easy *data,
} }
#endif #endif
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
/* All >=200 HTTP status codes are errors when wanting WebSockets */ /* All >=200 HTTP status codes are errors when wanting WebSockets */
if(data->req.upgr101 == UPGR101_WS) { if(data->req.upgr101 == UPGR101_WS) {
failf(data, "Refused WebSockets upgrade: %d", k->httpcode); failf(data, "Refused WebSockets upgrade: %d", k->httpcode);

View File

@ -3184,7 +3184,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
case CURLOPT_PREREQDATA: case CURLOPT_PREREQDATA:
data->set.prereq_userp = va_arg(param, void *); data->set.prereq_userp = va_arg(param, void *);
break; break;
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
case CURLOPT_WS_OPTIONS: { case CURLOPT_WS_OPTIONS: {
bool raw; bool raw;
arg = va_arg(param, long); arg = va_arg(param, long);

View File

@ -1509,7 +1509,7 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme,
#else #else
NULL, NULL,
#endif #endif
#if defined(USE_WEBSOCKETS) && \ #if !defined(CURL_DISABLE_WEBSOCKETS) && \
defined(USE_SSL) && !defined(CURL_DISABLE_HTTP) defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
&Curl_handler_wss, &Curl_handler_wss,
#else #else
@ -1578,7 +1578,7 @@ const struct Curl_handler *Curl_getn_scheme_handler(const char *scheme,
NULL, NULL,
#endif #endif
NULL, NULL,
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
&Curl_handler_ws, &Curl_handler_ws,
#else #else
NULL, NULL,
@ -2102,7 +2102,7 @@ static char *detect_proxy(struct Curl_easy *data,
} }
if(!proxy) { if(!proxy) {
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
/* websocket proxy fallbacks */ /* websocket proxy fallbacks */
if(strcasecompare("ws_proxy", proxy_env)) { if(strcasecompare("ws_proxy", proxy_env)) {
proxy = curl_getenv("http_proxy"); proxy = curl_getenv("http_proxy");
@ -2120,7 +2120,7 @@ static char *detect_proxy(struct Curl_easy *data,
envp = (char *)"ALL_PROXY"; envp = (char *)"ALL_PROXY";
proxy = curl_getenv(envp); proxy = curl_getenv(envp);
} }
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
} }
#endif #endif
} }

View File

@ -64,7 +64,7 @@ struct curl_trc_featt;
# define CURLECH_CLA_CFG (1<<4) # define CURLECH_CLA_CFG (1<<4)
#endif #endif
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
/* CURLPROTO_GOPHERS (29) is the highest publicly used protocol bit number, /* CURLPROTO_GOPHERS (29) is the highest publicly used protocol bit number,
* the rest are internal information. If we use higher bits we only do this on * the rest are internal information. If we use higher bits we only do this on
* platforms that have a >= 64-bit type and then we use such a type for the * platforms that have a >= 64-bit type and then we use such a type for the
@ -951,7 +951,7 @@ struct connectdata {
#ifndef CURL_DISABLE_MQTT #ifndef CURL_DISABLE_MQTT
struct mqtt_conn mqtt; struct mqtt_conn mqtt;
#endif #endif
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
struct websocket *ws; struct websocket *ws;
#endif #endif
unsigned int unused:1; /* avoids empty union */ unsigned int unused:1; /* avoids empty union */
@ -1844,7 +1844,7 @@ struct UserDefined {
BIT(doh_verifystatus); /* DoH certificate status verification */ BIT(doh_verifystatus); /* DoH certificate status verification */
#endif #endif
BIT(http09_allowed); /* allow HTTP/0.9 responses */ BIT(http09_allowed); /* allow HTTP/0.9 responses */
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
BIT(ws_raw_mode); BIT(ws_raw_mode);
#endif #endif
#ifdef USE_ECH #ifdef USE_ECH

View File

@ -384,11 +384,14 @@ static const char * const supported_protocols[] = {
#ifndef CURL_DISABLE_TFTP #ifndef CURL_DISABLE_TFTP
"tftp", "tftp",
#endif #endif
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_HTTP
/* WebSocket support relies on HTTP */
#ifndef CURL_DISABLE_WEBSOCKETS
"ws", "ws",
#endif #endif
#if defined(USE_SSL) && defined(USE_WEBSOCKETS) #if defined(USE_SSL) && !defined(CURL_DISABLE_WEBSOCKETS)
"wss", "wss",
#endif
#endif #endif
NULL NULL

View File

@ -24,7 +24,7 @@
#include "curl_setup.h" #include "curl_setup.h"
#include <curl/curl.h> #include <curl/curl.h>
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#include "urldata.h" #include "urldata.h"
#include "bufq.h" #include "bufq.h"
@ -930,9 +930,7 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
{ {
struct connectdata *conn = data->conn; struct connectdata *conn = data->conn;
struct websocket *ws; struct websocket *ws;
bool done = FALSE; /* not filled passed buffer yet */
struct ws_collect ctx; struct ws_collect ctx;
CURLcode result;
if(!conn) { if(!conn) {
/* Unhappy hack with lifetimes of transfers and connection */ /* Unhappy hack with lifetimes of transfers and connection */
@ -961,7 +959,9 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
ctx.buffer = buffer; ctx.buffer = buffer;
ctx.buflen = buflen; ctx.buflen = buflen;
while(!done) { while(1) {
CURLcode result;
/* receive more when our buffer is empty */ /* receive more when our buffer is empty */
if(Curl_bufq_is_empty(&ws->recvbuf)) { if(Curl_bufq_is_empty(&ws->recvbuf)) {
ssize_t n = Curl_bufq_slurp(&ws->recvbuf, nw_in_recv, data, &result); ssize_t n = Curl_bufq_slurp(&ws->recvbuf, nw_in_recv, data, &result);
@ -984,7 +984,6 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
ws_dec_info(&ws->dec, data, "need more input"); ws_dec_info(&ws->dec, data, "need more input");
continue; /* nothing written, try more input */ continue; /* nothing written, try more input */
} }
done = TRUE;
break; break;
} }
else if(result) { else if(result) {
@ -994,7 +993,6 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
/* The decoded frame is passed back to our caller. /* The decoded frame is passed back to our caller.
* There are frames like PING were we auto-respond to and * There are frames like PING were we auto-respond to and
* that we do not return. For these `ctx.written` is not set. */ * that we do not return. For these `ctx.written` is not set. */
done = TRUE;
break; break;
} }
} }
@ -1387,4 +1385,4 @@ CURL_EXTERN const struct curl_ws_frame *curl_ws_meta(struct Curl_easy *data)
(void)data; (void)data;
return NULL; return NULL;
} }
#endif /* USE_WEBSOCKETS */ #endif /* !CURL_DISABLE_WEBSOCKETS */

View File

@ -25,7 +25,7 @@
***************************************************************************/ ***************************************************************************/
#include "curl_setup.h" #include "curl_setup.h"
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP) #if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#ifdef USE_HYPER #ifdef USE_HYPER
#define REQTYPE void #define REQTYPE void

View File

@ -70,8 +70,9 @@ static const struct detail scheme[] = {
{"smtps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)" }, {"smtps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)" },
{"telnet", "#ifndef CURL_DISABLE_TELNET" }, {"telnet", "#ifndef CURL_DISABLE_TELNET" },
{"tftp", "#ifndef CURL_DISABLE_TFTP" }, {"tftp", "#ifndef CURL_DISABLE_TFTP" },
{"ws", "#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)" }, {"ws",
{"wss", "#if defined(USE_WEBSOCKETS) && \\\n" "#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)" },
{"wss", "#if !defined(CURL_DISABLE_WEBSOCKETS) && \\\n"
" defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" }, " defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" },
{ NULL, NULL } { NULL, NULL }
}; };

View File

@ -33,7 +33,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
#ifdef _WIN32 #ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
@ -210,7 +210,7 @@ out:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
CURL *curl; CURL *curl;
CURLcode res = CURLE_OK; CURLcode res = CURLE_OK;
const char *url; const char *url;
@ -262,10 +262,10 @@ int main(int argc, char *argv[])
curl_global_cleanup(); curl_global_cleanup();
return (int)res; return (int)res;
#else /* USE_WEBSOCKETS */ #else /* !CURL_DISABLE_WEBSOCKETS */
(void)argc; (void)argc;
(void)argv; (void)argv;
fprintf(stderr, "WebSockets not enabled in libcurl\n"); fprintf(stderr, "WebSockets not enabled in libcurl\n");
return 1; return 1;
#endif /* !USE_WEBSOCKETS */ #endif /* CURL_DISABLE_WEBSOCKETS */
} }

View File

@ -42,7 +42,7 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode ping(CURL *curl, const char *send_payload) static CURLcode ping(CURL *curl, const char *send_payload)
{ {
@ -124,7 +124,7 @@ static CURLcode pingpong(CURL *curl, const char *payload)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
CURL *curl; CURL *curl;
CURLcode res = CURLE_OK; CURLcode res = CURLE_OK;
const char *url, *payload; const char *url, *payload;
@ -157,10 +157,10 @@ int main(int argc, char *argv[])
curl_global_cleanup(); curl_global_cleanup();
return (int)res; return (int)res;
#else /* USE_WEBSOCKETS */ #else /* !CURL_DISABLE_WEBSOCKETS */
(void)argc; (void)argc;
(void)argv; (void)argv;
fprintf(stderr, "WebSockets not enabled in libcurl\n"); fprintf(stderr, "WebSockets not enabled in libcurl\n");
return 1; return 1;
#endif /* !USE_WEBSOCKETS */ #endif /* CURL_DISABLE_WEBSOCKETS */
} }

View File

@ -274,7 +274,7 @@ static const struct testcase get_parts_list[] ={
{"https://user@example.net", {"https://user@example.net",
"https | user | [12] | [13] | example.net | [15] | / | [16] | [17]", "https | user | [12] | [13] | example.net | [15] | / | [16] | [17]",
0, 0, CURLUE_OK}, 0, 0, CURLUE_OK},
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
{"ws://example.com/color/?green", {"ws://example.com/color/?green",
"ws | [11] | [12] | [13] | example.com | [15] | /color/ | green |" "ws | [11] | [12] | [13] | example.com | [15] | /color/ | green |"
" [17]", " [17]",

View File

@ -24,7 +24,7 @@
#include "test.h" #include "test.h"
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
#if 0 #if 0
static CURLcode send_ping(CURL *curl, const char *send_payload) static CURLcode send_ping(CURL *curl, const char *send_payload)

View File

@ -24,7 +24,7 @@
#include "test.h" #include "test.h"
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
struct ws_data { struct ws_data {
CURL *easy; CURL *easy;

View File

@ -24,7 +24,7 @@
#include "test.h" #include "test.h"
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
static CURLcode send_ping(CURL *curl, const char *send_payload) static CURLcode send_ping(CURL *curl, const char *send_payload)
{ {

View File

@ -26,7 +26,7 @@
#include "testtrace.h" #include "testtrace.h"
#include "memdebug.h" #include "memdebug.h"
#ifdef USE_WEBSOCKETS #ifndef CURL_DISABLE_WEBSOCKETS
/* just close the connection */ /* just close the connection */
static void websocket_close(CURL *curl) static void websocket_close(CURL *curl)

View File

@ -141,8 +141,8 @@ SSL_CFLAGS = $(SSL_CFLAGS) /DCURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG
!ENDIF !ENDIF
!ENDIF !ENDIF
!IF "$(ENABLE_WEBSOCKETS)"=="true" !IF "$(DISABLE_WEBSOCKETS)"=="true"
CFLAGS = $(CFLAGS) /DUSE_WEBSOCKETS=1 CFLAGS = $(CFLAGS) /DCURL_DISABLE_WEBSOCKETS=1
!ENDIF !ENDIF
!IFDEF NGHTTP2_PATH !IFDEF NGHTTP2_PATH