mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:31:16 -07:00
backport: don't hang on portscan
svn path=/branches/KDE_3_1_BRANCH/kdenetwork/krfb/; revision=236038
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
#include <qglobal.h>
|
||||
#include <qlabel.h>
|
||||
#include <qmutex.h>
|
||||
#include <qdesktopwidget.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
@@ -150,6 +151,10 @@ static void clientGoneHook(rfbClientPtr)
|
||||
self->handleClientGone();
|
||||
}
|
||||
|
||||
static void inetdDisconnectHook()
|
||||
{
|
||||
self->handleClientGone();
|
||||
}
|
||||
|
||||
|
||||
void ConnectionDialog::closeEvent(QCloseEvent *)
|
||||
@@ -178,9 +183,9 @@ void KeyboardEvent::initKeycodes() {
|
||||
int i,j,minkey,maxkey,syms_per_keycode;
|
||||
|
||||
dpy = qt_xdisplay();
|
||||
|
||||
|
||||
memset(modifiers,-1,sizeof(modifiers));
|
||||
|
||||
|
||||
XDisplayKeycodes(dpy,&minkey,&maxkey);
|
||||
ASSERT(minkey >= 8);
|
||||
ASSERT(maxkey < 256);
|
||||
@@ -274,7 +279,12 @@ PointerEvent::PointerEvent(int b, int _x, int _y) :
|
||||
}
|
||||
|
||||
void PointerEvent::exec() {
|
||||
XTestFakeMotionEvent(dpy, 0, x, y, CurrentTime);
|
||||
static QDesktopWidget desktopWidget;
|
||||
|
||||
int screen = desktopWidget.screenNumber();
|
||||
if (screen < 0)
|
||||
screen = 0;
|
||||
XTestFakeMotionEvent(dpy, screen, x, y, CurrentTime);
|
||||
for(int i = 0; i < 5; i++)
|
||||
if ((buttonMask&(1<<i))!=(button_mask&(1<<i)))
|
||||
XTestFakeButtonEvent(dpy,
|
||||
@@ -319,6 +329,7 @@ RFBController::RFBController(Configuration *c) :
|
||||
connect(dialog.refuseConnectionButton, SIGNAL(clicked()),
|
||||
SLOT(dialogRefused()));
|
||||
connect(&dialog, SIGNAL(closed()), SLOT(dialogRefused()));
|
||||
connect(&initIdleTimer, SIGNAL(timeout()), SLOT(checkAsyncEvents()));
|
||||
connect(&idleTimer, SIGNAL(timeout()), SLOT(idleSlot()));
|
||||
|
||||
asyncQueue.setAutoDelete(true);
|
||||
@@ -394,6 +405,7 @@ void RFBController::startServer(int inetdFd, bool xtestGrab)
|
||||
server->kbdAddEvent = keyboardHook;
|
||||
server->ptrAddEvent = pointerHook;
|
||||
server->newClientHook = newClientHook;
|
||||
server->inetdDisconnectHook = inetdDisconnectHook;
|
||||
server->passwordCheck = passwordCheck;
|
||||
|
||||
if (!myCursor)
|
||||
@@ -417,6 +429,7 @@ void RFBController::startServer(int inetdFd, bool xtestGrab)
|
||||
}
|
||||
|
||||
rfbRunEventLoop(server, -1, TRUE);
|
||||
initIdleTimer.start(IDLE_PAUSE);
|
||||
}
|
||||
|
||||
void RFBController::stopServer(bool xtestUngrab)
|
||||
@@ -440,6 +453,7 @@ void RFBController::connectionAccepted(bool aRC)
|
||||
|
||||
allowDesktopControl = aRC;
|
||||
emit desktopControlSettingChanged(aRC);
|
||||
initIdleTimer.stop();
|
||||
idleTimer.start(IDLE_PAUSE);
|
||||
|
||||
server->rfbClientHead->clientGoneHook = clientGoneHook;
|
||||
@@ -498,6 +512,7 @@ void RFBController::connectionClosed()
|
||||
.arg(remoteIp));
|
||||
|
||||
idleTimer.stop();
|
||||
initIdleTimer.stop();
|
||||
state = RFB_WAITING;
|
||||
if (forcedClose)
|
||||
emit quitApp();
|
||||
|
||||
@@ -158,13 +158,13 @@ signals:
|
||||
private:
|
||||
void stopServer(bool xtestUngrab = true);
|
||||
void sendKNotifyEvent(const QString &name, const QString &desc);
|
||||
bool checkAsyncEvents();
|
||||
void sendSessionEstablished();
|
||||
|
||||
QString remoteIp;
|
||||
bool allowDesktopControl;
|
||||
|
||||
QTimer idleTimer;
|
||||
QTimer initIdleTimer;
|
||||
Configuration *configuration;
|
||||
XUpdateScanner *scanner;
|
||||
ConnectionDialog dialog;
|
||||
@@ -179,6 +179,7 @@ private:
|
||||
bool closePending; // set when libvncserver detected close
|
||||
bool forcedClose; // set when user closed connection
|
||||
private slots:
|
||||
bool checkAsyncEvents();
|
||||
void idleSlot();
|
||||
void dialogAccepted();
|
||||
void dialogRefused();
|
||||
|
||||
@@ -327,15 +327,17 @@ listenerRun(void *data)
|
||||
|
||||
if (rfbScreen->inetdSock != -1) {
|
||||
cl = rfbNewClient(rfbScreen, rfbScreen->inetdSock);
|
||||
if (cl && !cl->onHold )
|
||||
rfbStartOnHoldClient(cl);
|
||||
if (cl && !cl->onHold)
|
||||
rfbStartOnHoldClient(cl);
|
||||
else if (rfbScreen->inetdDisconnectHook && !cl)
|
||||
rfbScreen->inetdDisconnectHook();
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = sizeof(peer);
|
||||
|
||||
/* TODO: this thread wont die by restarting the server */
|
||||
while ((client_fd = accept(rfbScreen->rfbListenSock,
|
||||
while ((client_fd = accept(rfbScreen->rfbListenSock,
|
||||
(struct sockaddr*)&peer, &len)) >= 0) {
|
||||
cl = rfbNewClient(rfbScreen,client_fd);
|
||||
len = sizeof(peer);
|
||||
@@ -606,6 +608,7 @@ rfbScreenInfoPtr rfbGetScreen(int* argc,char** argv,
|
||||
rfbScreen->setTranslateFunction = rfbSetTranslateFunction;
|
||||
rfbScreen->newClientHook = defaultNewClientHook;
|
||||
rfbScreen->displayHook = 0;
|
||||
rfbScreen->inetdDisconnectHook = 0;
|
||||
|
||||
/* initialize client list and iterator mutex */
|
||||
rfbClientListInit(rfbScreen);
|
||||
|
||||
@@ -207,6 +207,7 @@ typedef Bool (*SetTranslateFunctionProcPtr)(struct _rfbClientRec* cl);
|
||||
typedef Bool (*PasswordCheckProcPtr)(struct _rfbClientRec* cl,const char* encryptedPassWord,int len);
|
||||
typedef enum rfbNewClientAction (*NewClientHookPtr)(struct _rfbClientRec* cl);
|
||||
typedef void (*DisplayHookPtr)(struct _rfbClientRec* cl);
|
||||
typedef void (*InetdDisconnectPtr)();
|
||||
|
||||
typedef struct {
|
||||
CARD32 count;
|
||||
@@ -344,12 +345,14 @@ typedef struct _rfbScreenInfo
|
||||
SetXCutTextProcPtr setXCutText;
|
||||
GetCursorProcPtr getCursorPtr;
|
||||
SetTranslateFunctionProcPtr setTranslateFunction;
|
||||
|
||||
|
||||
/* newClientHook is called just after a new client is created */
|
||||
NewClientHookPtr newClientHook;
|
||||
/* displayHook is called just before a frame buffer update */
|
||||
DisplayHookPtr displayHook;
|
||||
|
||||
/* inetdDisconnectHook is called when the connection has been
|
||||
interrupted before a client could connect. */
|
||||
InetdDisconnectPtr inetdDisconnectHook;
|
||||
#ifdef HAVE_PTHREADS
|
||||
MUTEX(cursorMutex);
|
||||
Bool backgroundLoop;
|
||||
|
||||
Reference in New Issue
Block a user