Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into veyon-4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
tobydox committed Nov 27, 2024
2 parents 56e762b + 4b3b9d9 commit da774c7
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 24 deletions.
51 changes: 50 additions & 1 deletion examples/client/qt5client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ class VncViewer : public QWidget
int serverPort;
std::thread *vncThread() const;
void paintEvent(QPaintEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void closeEvent(QCloseEvent *event) override;

private:
bool m_startFlag = false;
QImage m_image;
rfbClient *cl;
std::thread *m_vncThread;
Expand All @@ -74,6 +79,7 @@ void VncViewer::finishedFramebufferUpdate(rfbClient *cl)

update();
}

void VncViewer::paintEvent(QPaintEvent *event)
{
event->accept();
Expand All @@ -82,6 +88,45 @@ void VncViewer::paintEvent(QPaintEvent *event)
painter.drawImage(this->rect(), m_image);
}

void VncViewer::mouseMoveEvent(QMouseEvent *event)
{
if (m_startFlag) {
SendPointerEvent(cl,
event->localPos().x() / width() * cl->width,
event->localPos().y() / height() * cl->height,
(event->buttons() & Qt::LeftButton) ? 1 : 0);
}
}

void VncViewer::mousePressEvent(QMouseEvent *event)
{
if (m_startFlag) {
SendPointerEvent(cl,
event->localPos().x() / width() * cl->width,
event->localPos().y() / height() * cl->height,
1);
}
}

void VncViewer::mouseReleaseEvent(QMouseEvent *event)
{
if (m_startFlag) {
SendPointerEvent(cl,
event->localPos().x() / width() * cl->width,
event->localPos().y() / height() * cl->height,
0);
}
}

void VncViewer::closeEvent(QCloseEvent *event)
{
m_startFlag = false;
if (m_vncThread->joinable()) {
m_vncThread->join();
}
QWidget::closeEvent(event);
}

void VncViewer::start()
{
cl = rfbGetClient(8, 3, 4);
Expand Down Expand Up @@ -109,9 +154,13 @@ void VncViewer::start()
std::cout << "[INFO] disconnected" << std::endl;
return;
}
m_startFlag = true;

std::cout << "[INFO] screen size: " << cl->width << " x " << cl->height << std::endl;
this->resize(cl->width, cl->height);

m_vncThread = new std::thread([this]() {
while (true) {
while (m_startFlag) {
int i = WaitForMessage(cl, 500);
if (i < 0) {
std::cout << "[INFO] disconnected" << std::endl;
Expand Down
4 changes: 4 additions & 0 deletions include/rfb/rfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ typedef struct _rfbScreenInfo
uintptr_t listener_thread;
#endif
#ifdef LIBVNCSERVER_HAVE_LIBZ
/** This is called when UTF-8 cut-text is received from a client.
* Set this callback to enable ExtendedClipboard support. */
rfbSetXCutTextUTF8ProcPtr setXCutTextUTF8;
#endif
/* Timeout value for select() calls, mainly used for multithreaded servers. */
int select_timeout_usec;
} rfbScreenInfo, *rfbScreenInfoPtr;


Expand Down
4 changes: 2 additions & 2 deletions src/common/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
rfbBool sock_set_nonblocking(rfbSocket sock, rfbBool non_blocking, void (*log)(const char *format, ...))
{
#ifdef WIN32
unsigned long block = non_blocking ? 0 : 1;
if(ioctlsocket(sock, FIONBIO, &block) == SOCKET_ERROR) {
unsigned long non_blocking_ulong = non_blocking;
if(ioctlsocket(sock, FIONBIO, &non_blocking_ulong) == SOCKET_ERROR) {
errno=WSAGetLastError();
#else
int flags = fcntl(sock, F_GETFL);
Expand Down
2 changes: 1 addition & 1 deletion src/libvncclient/tls_gnutls.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "tls.h"


static const char *rfbTLSPriority = "NORMAL:+DHE-DSS:+RSA:+DHE-RSA:+SRP";
static const char *rfbTLSPriority = "NORMAL:+DHE-DSS:+RSA:+DHE-RSA";
static const char *rfbAnonTLSPriority = "NORMAL:+ANON-ECDH:+ANON-DH";

#define DH_BITS 1024
Expand Down
3 changes: 2 additions & 1 deletion src/libvncclient/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ open_ssl_connection (rfbClient *client, int sockfd, rfbBool anonTLS, rfbCredenti
} else { /* anonTLS here */
/* Need anonymous ciphers for anonTLS, see https://github.com/LibVNC/libvncserver/issues/347#issuecomment-597477103 */
SSL_CTX_set_cipher_list(ssl_ctx, "aNULL");
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined LIBRESSL_VERSION_NUMBER
#if OPENSSL_VERSION_NUMBER >= 0x10100000L || \
(defined (LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x30600000)
/*
See https://www.openssl.org/docs/man1.1.0/man3/SSL_set_security_level.html
Not specifying 0 here makes LibVNCClient fail connecting to some servers.
Expand Down
8 changes: 7 additions & 1 deletion src/libvncserver/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ void rfbHttpShutdownSockets(rfbScreenInfoPtr rfbScreen) {
/*
* httpCheckFds is called from ProcessInputEvents to check for input on the
* HTTP socket(s). If there is input to process, httpProcessInput is called.
* TODO When a new client connects, the active HTTP connection is abruptly
* terminated, the ongoing download or data transfer for the active client will
* be cut off because the server closes the socket without waiting for the
* transfer to complete. The new client then takes over the single httpSock, and
* the previous client loses its connection.
*/

void
Expand Down Expand Up @@ -198,7 +203,8 @@ rfbHttpCheckFds(rfbScreenInfoPtr rfbScreen)
httpProcessInput(rfbScreen);
}

if (FD_ISSET(rfbScreen->httpListenSock, &fds) || FD_ISSET(rfbScreen->httpListen6Sock, &fds)) {
if ((rfbScreen->httpListenSock != RFB_INVALID_SOCKET && FD_ISSET(rfbScreen->httpListenSock, &fds))
|| (rfbScreen->httpListen6Sock != RFB_INVALID_SOCKET && FD_ISSET(rfbScreen->httpListen6Sock, &fds))) {
if (rfbScreen->httpSock != RFB_INVALID_SOCKET) rfbCloseSocket(rfbScreen->httpSock);

if(FD_ISSET(rfbScreen->httpListenSock, &fds)) {
Expand Down
26 changes: 17 additions & 9 deletions src/libvncserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ listenerRun(void *data)
rfbClientPtr cl = NULL;
socklen_t len;
fd_set listen_fds; /* temp file descriptor list for select() */
struct timeval tv;

/*
Only checking socket state here and not using rfbIsActive()
Expand All @@ -634,9 +635,9 @@ listenerRun(void *data)
return true, not ending the listener, making the join in rfbShutdownServer()
wait forever...
*/
/* TODO: HTTP is not handled */
while (screen->socketState != RFB_SOCKET_SHUTDOWN) {
client_fd = -1;
cl = NULL;
FD_ZERO(&listen_fds);
if(screen->listenSock != RFB_INVALID_SOCKET)
FD_SET(screen->listenSock, &listen_fds);
Expand All @@ -647,7 +648,9 @@ listenerRun(void *data)
screen->maxFd = rfbMax(screen->maxFd, screen->pipe_notify_listener_thread[0]);
#endif

if (select(screen->maxFd+1, &listen_fds, NULL, NULL, NULL) == -1) {
tv.tv_sec = 0;
tv.tv_usec = screen->select_timeout_usec;
if (select(screen->maxFd+1, &listen_fds, NULL, NULL, &tv) == -1) {
rfbLogPerror("listenerRun: error in select");
return THREAD_ROUTINE_RETURN_VALUE;
}
Expand All @@ -663,17 +666,20 @@ listenerRun(void *data)
}
#endif

/* there is something on the listening sockets, handle new connections */
/* If there is something on the listening sockets, handle new connections */
len = sizeof (peer);
if (FD_ISSET(screen->listenSock, &listen_fds))
if (screen->listenSock != RFB_INVALID_SOCKET && FD_ISSET(screen->listenSock, &listen_fds))
client_fd = accept(screen->listenSock, (struct sockaddr*)&peer, &len);
else if (FD_ISSET(screen->listen6Sock, &listen_fds))
else if (screen->listen6Sock != RFB_INVALID_SOCKET && FD_ISSET(screen->listen6Sock, &listen_fds))
client_fd = accept(screen->listen6Sock, (struct sockaddr*)&peer, &len);

if(client_fd >= 0)
cl = rfbNewClient(screen,client_fd);
if (cl && !cl->onHold )
rfbStartOnHoldClient(cl);

/* handle HTTP */
rfbHttpCheckFds(screen);
}
return THREAD_ROUTINE_RETURN_VALUE;
}
Expand Down Expand Up @@ -1035,7 +1041,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
screen->ptrAddEvent = rfbDefaultPtrAddEvent;
screen->setXCutText = rfbDefaultSetXCutText;
#ifdef LIBVNCSERVER_HAVE_LIBZ
screen->setXCutTextUTF8 = rfbDefaultSetXCutText;
screen->setXCutTextUTF8 = NULL;
#endif
screen->getCursorPtr = rfbDefaultGetCursorPtr;
screen->setTranslateFunction = rfbSetTranslateFunction;
Expand Down Expand Up @@ -1346,6 +1352,11 @@ rfbBool rfbIsActive(rfbScreenInfoPtr screenInfo) {

void rfbRunEventLoop(rfbScreenInfoPtr screen, long usec, rfbBool runInBackground)
{
if(usec<0)
usec=screen->deferUpdateTime*1000;

screen->select_timeout_usec = usec;

if(runInBackground) {
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
screen->backgroundLoop = TRUE;
Expand All @@ -1368,9 +1379,6 @@ void rfbRunEventLoop(rfbScreenInfoPtr screen, long usec, rfbBool runInBackground
#endif
}

if(usec<0)
usec=screen->deferUpdateTime*1000;

while(rfbIsActive(screen))
rfbProcessEvents(screen,usec);
}
20 changes: 11 additions & 9 deletions src/libvncserver/rfbserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2193,7 +2193,7 @@ rfbProcessExtendedServerCutTextData(rfbClientPtr cl, uint32_t flags, const char
}
if (i == 0) {
/* text */
if (!cl->viewOnly) {
if (!cl->viewOnly && cl->screen->setXCutTextUTF8) {
cl->screen->setXCutTextUTF8(buf, size, cl);
}
}
Expand Down Expand Up @@ -2465,14 +2465,16 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
break;
#ifdef LIBVNCSERVER_HAVE_LIBZ
case rfbEncodingExtendedClipboard:
if (!cl->enableExtendedClipboard) {
rfbLog("Enabling ExtendedClipboard extension for client "
"%s\n", cl->host);
cl->enableExtendedClipboard = TRUE;
}
/* send the capabilities we support, currently only text */
if (!rfbSendExtendedClipboardCapability(cl)) {
return;
if (cl->screen->setXCutTextUTF8) {
if (!cl->enableExtendedClipboard) {
rfbLog("Enabling ExtendedClipboard extension for client "
"%s\n", cl->host);
cl->enableExtendedClipboard = TRUE;
}
/* send the capabilities we support, currently only text */
if (!rfbSendExtendedClipboardCapability(cl)) {
return;
}
}
break;
#endif
Expand Down

0 comments on commit da774c7

Please sign in to comment.