]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
ws: minor fixes for web sockets without the CONNECT_ONLY flag
authorPaul Seligman <pseligman@apple.com>
Fri, 7 Oct 2022 11:52:31 +0000 (07:52 -0400)
committerDaniel Stenberg <daniel@haxx.se>
Sun, 9 Oct 2022 21:09:58 +0000 (23:09 +0200)
- 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 #9665

lib/sendf.c
lib/ws.c

index 66cec059755492e6539a787d4d180e4dbcb015c5..d26b7e7cd794dee355efd966ffe3dc23e9ae628c 100644 (file)
@@ -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) {
index dbe8788da799cea0b2f4c827732d502857aba1fe..cfd267ee208d5154989de67d78293bffcc365d96 100644 (file)
--- a/lib/ws.c
+++ b/lib/ws.c
@@ -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);