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

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

View file

@ -148,6 +148,9 @@
/* disables SMTP */
#cmakedefine CURL_DISABLE_SMTP 1
/* disabled WebSockets */
#cmakedefine CURL_DISABLE_WEBSOCKETS 1
/* disables use of socketpair for curl_multi_poll */
#cmakedefine CURL_DISABLE_SOCKETPAIR 1
@ -812,9 +815,6 @@ ${SIZEOF_TIME_T_CODE}
/* to enable Apple IDN */
#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. */
#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 */
#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 = {
"WS",
CURL_LOG_LVL_NONE,
@ -255,7 +255,7 @@ void Curl_trc_ws(struct Curl_easy *data, const char *fmt, ...)
va_end(ap);
}
}
#endif /* USE_WEBSOCKETS && !CURL_DISABLE_HTTP */
#endif /* !CURL_DISABLE_WEBSOCKETS && !CURL_DISABLE_HTTP */
#define TRC_CT_NONE (0)
#define TRC_CT_PROTOCOL (1<<(0))
@ -279,7 +279,7 @@ static struct trc_feat_def trc_feats[] = {
#ifndef CURL_DISABLE_SMTP
{ &Curl_trc_feat_smtp, TRC_CT_PROTOCOL },
#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 },
#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)) \
Curl_trc_smtp(data, __VA_ARGS__); } while(0)
#endif /* !CURL_DISABLE_SMTP */
#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS(data, ...) \
#if !defined(CURL_DISABLE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)
#define CURL_TRC_WS(data, ...) \
do { if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_ws)) \
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 */
@ -113,7 +113,7 @@ void Curl_failf(struct Curl_easy *data,
#ifndef CURL_DISABLE_SMTP
#define CURL_TRC_SMTP Curl_trc_smtp
#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
#endif
@ -169,7 +169,7 @@ extern struct curl_trc_feat Curl_trc_feat_smtp;
void Curl_trc_smtp(struct Curl_easy *data,
const char *fmt, ...) CURL_PRINTF(2, 3);
#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;
void Curl_trc_ws(struct Curl_easy *data,
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;
}
#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, ...)
{
(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;
}
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
CURLcode Curl_connect_only_attach(struct Curl_easy *data)
{
CURLcode result;
@ -1264,7 +1264,7 @@ CURLcode Curl_connect_only_attach(struct Curl_easy *data)
return CURLE_OK;
}
#endif /* USE_WEBSOCKETS */
#endif /* !CURL_DISABLE_WEBSOCKETS */
/*
* Sends data over the connected socket.

View file

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

View file

@ -2697,7 +2697,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
}
result = Curl_http_cookies(data, conn, &req);
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
if(!result && conn->handler->protocol&(CURLPROTO_WS|CURLPROTO_WSS))
result = Curl_ws_request(data, &req);
#endif
@ -3449,7 +3449,7 @@ static CURLcode http_on_response(struct Curl_easy *data,
goto out;
*pconsumed += blen;
}
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
else if(k->upgr101 == UPGR101_WS) {
/* verify the response. Any passed `buf` bytes are already in
* WebSockets format and taken in by the protocol handler. */
@ -3534,7 +3534,7 @@ static CURLcode http_on_response(struct Curl_easy *data,
}
#endif
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
/* All >=200 HTTP status codes are errors when wanting WebSockets */
if(data->req.upgr101 == UPGR101_WS) {
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:
data->set.prereq_userp = va_arg(param, void *);
break;
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
case CURLOPT_WS_OPTIONS: {
bool raw;
arg = va_arg(param, long);

View file

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

View file

@ -64,7 +64,7 @@ struct curl_trc_featt;
# define CURLECH_CLA_CFG (1<<4)
#endif
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
/* 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
* 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
struct mqtt_conn mqtt;
#endif
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
struct websocket *ws;
#endif
unsigned int unused:1; /* avoids empty union */
@ -1844,7 +1844,7 @@ struct UserDefined {
BIT(doh_verifystatus); /* DoH certificate status verification */
#endif
BIT(http09_allowed); /* allow HTTP/0.9 responses */
#ifdef USE_WEBSOCKETS
#ifndef CURL_DISABLE_WEBSOCKETS
BIT(ws_raw_mode);
#endif
#ifdef USE_ECH

View file

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

View file

@ -24,7 +24,7 @@
#include "curl_setup.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 "bufq.h"
@ -930,9 +930,7 @@ CURL_EXTERN CURLcode curl_ws_recv(struct Curl_easy *data, void *buffer,
{
struct connectdata *conn = data->conn;
struct websocket *ws;
bool done = FALSE; /* not filled passed buffer yet */
struct ws_collect ctx;
CURLcode result;
if(!conn) {
/* 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.buflen = buflen;
while(!done) {
while(1) {
CURLcode result;
/* receive more when our buffer is empty */
if(Curl_bufq_is_empty(&ws->recvbuf)) {
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");
continue; /* nothing written, try more input */
}
done = TRUE;
break;
}
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.
* There are frames like PING were we auto-respond to and
* that we do not return. For these `ctx.written` is not set. */
done = TRUE;
break;
}
}
@ -1387,4 +1385,4 @@ CURL_EXTERN const struct curl_ws_frame *curl_ws_meta(struct Curl_easy *data)
(void)data;
return NULL;
}
#endif /* USE_WEBSOCKETS */
#endif /* !CURL_DISABLE_WEBSOCKETS */

View file

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