2
0
mirror of https://github.com/curl/curl.git synced 2025-04-24 16:40:32 +08:00

ws: minor fixes for web sockets without the CONNECT_ONLY flag

- Fixed an issue where is_in_callback was getting cleared when using web
  sockets with debug logging enabled
- Ensure the handle is is_in_callback when calling out to fwrite_func
- Change the write vs. send_data decision to whether or not the handle
  is in CONNECT_ONLY mode.
- Account for buflen not including the header length in curl_ws_send

Closes 
This commit is contained in:
Paul Seligman 2022-10-07 07:52:31 -04:00 committed by Daniel Stenberg
parent d905de2769
commit b261389dba
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 12 additions and 6 deletions

@ -735,9 +735,10 @@ void Curl_debug(struct Curl_easy *data, curl_infotype type,
static const char s_infotype[CURLINFO_END][3] = {
"* ", "< ", "> ", "{ ", "} ", "{ ", "} " };
if(data->set.fdebug) {
bool inCallback = Curl_is_in_callback(data);
Curl_set_in_callback(data, true);
(void)(*data->set.fdebug)(data, type, ptr, size, data->set.debugdata);
Curl_set_in_callback(data, false);
Curl_set_in_callback(data, inCallback);
}
else {
switch(type) {

@ -334,6 +334,7 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */,
else if(nitems) {
unsigned char *frame = NULL;
size_t flen = 0;
size_t wrote = 0;
CURLcode result;
unsigned char *endp;
curl_off_t oleft;
@ -383,7 +384,10 @@ size_t Curl_ws_writecb(char *buffer, size_t size /* 1 */,
}
else {
/* deliver the decoded frame to the user callback */
if(data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr) != flen)
Curl_set_in_callback(data, true);
wrote = data->set.fwrite_func((char *)frame, 1, flen, writebody_ptr);
Curl_set_in_callback(data, false);
if(wrote != flen)
return 0;
}
if(oleft)
@ -681,12 +685,13 @@ CURL_EXTERN CURLcode curl_ws_send(struct Curl_easy *data, const void *buffer,
out = data->state.ulbuf;
if(buflen)
/* for PING and PONG etc there might not be a payload */
ws_xor(data, buffer, (unsigned char *)out + headlen, buflen - headlen);
if(Curl_is_in_callback(data))
ws_xor(data, buffer, (unsigned char *)out + headlen, buflen);
if(data->set.connect_only)
result = Curl_senddata(data, out, buflen + headlen, &written);
else
result = Curl_write(data, data->conn->writesockfd, out,
buflen + headlen, &written);
else
result = Curl_senddata(data, out, buflen + headlen, &written);
infof(data, "WS: wanted to send %zu bytes, sent %zu bytes",
headlen + buflen, written);