void rfbSendServerCutText(char *str, int len)
{
  rfbClientPtr cl, nextCl;
  rfbServerCutTextMsg sct;

  if (rfbViewOnly || rfbAuthDisableCBSend || !str || len <= 0)
    return;

  for (cl = rfbClientHead; cl; cl = nextCl) {
    nextCl = cl->next;
    if (cl->state != RFB_NORMAL || cl->viewOnly)
      continue;
    if (cl->cutTextLen == len && cl->cutText && !memcmp(cl->cutText, str, len))
      continue;
    if (cl->cutText)
      free(cl->cutText);
    cl->cutText = rfbAlloc(len);
    memcpy(cl->cutText, str, len);
    cl->cutTextLen = len;
    memset(&sct, 0, sz_rfbServerCutTextMsg);
    sct.type = rfbServerCutText;
    sct.length = Swap32IfLE(len);
    if (WriteExact(cl, (char *)&sct, sz_rfbServerCutTextMsg) < 0) {
      rfbLogPerror("rfbSendServerCutText: write");
      rfbCloseClient(cl);
      continue;
    }
    if (WriteExact(cl, str, len) < 0) {
      rfbLogPerror("rfbSendServerCutText: write");
      rfbCloseClient(cl);
      continue;
    }
    if (cl->captureFD >= 0)
      WriteCapture(cl->captureFD, str, len);
  }
  LogMessage(X_DEBUG, "Sent server clipboard: '%.*s%s' (%d bytes)\n",
             len <= 20 ? len : 20, str, len <= 20 ? "" : "...", len);
}
void rfbSendServerCutText(char *str, int len)
{
  rfbClientPtr cl, nextCl;
  rfbServerCutTextMsg sct;

  if (rfbViewOnly || rfbAuthDisableCBSend || !str || len <= 0)
    return;

  for (cl = rfbClientHead; cl; cl = nextCl) {
    nextCl = cl->next;
    if (cl->state != RFB_NORMAL || cl->viewOnly)
      continue;
    if (cl->cutTextLen == len && cl->cutText && !memcmp(cl->cutText, str, len))
      continue;
    if (cl->cutText)
      free(cl->cutText);
    cl->cutText = rfbAlloc(len);
    memcpy(cl->cutText, str, len);
    cl->cutTextLen = len;
    memset(&sct, 0, sz_rfbServerCutTextMsg);
    sct.type = rfbServerCutText;
    sct.length = Swap32IfLE(len);
    if (WriteExact(cl, (char *)&sct, sz_rfbServerCutTextMsg) < 0) {
      rfbLogPerror("rfbSendServerCutText: write");
      rfbCloseClient(cl);
      continue;
    }
    if (WriteExact(cl, str, len) < 0) {
      rfbLogPerror("rfbSendServerCutText: write");
      rfbCloseClient(cl);
      continue;
    }
    if (cl->captureFD >= 0)
      WriteCapture(cl->captureFD, str, len);
  }
  LogMessage(X_DEBUG, "Sent server clipboard: '%.*s%s' (%d bytes)\n",
             len <= 20 ? len : 20, str, len <= 20 ? "" : "...", len);
}