|
|
@ -33,9 +33,6 @@
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rfbClientPtr pointerClient = NULL; /* Mutex for pointer events */
|
|
|
|
rfbClientPtr pointerClient = NULL; /* Mutex for pointer events */
|
|
|
|
|
|
|
|
|
|
|
@ -43,52 +40,74 @@ static void rfbProcessClientProtocolVersion(rfbClientPtr cl);
|
|
|
|
static void rfbProcessClientNormalMessage(rfbClientPtr cl);
|
|
|
|
static void rfbProcessClientNormalMessage(rfbClientPtr cl);
|
|
|
|
static void rfbProcessClientInitMessage(rfbClientPtr cl);
|
|
|
|
static void rfbProcessClientInitMessage(rfbClientPtr cl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
|
|
|
|
void rfbIncrClientRef(rfbClientPtr cl)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cl->refCountMutex);
|
|
|
|
|
|
|
|
cl->refCount++;
|
|
|
|
|
|
|
|
UNLOCK(cl->refCountMutex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void rfbDecrClientRef(rfbClientPtr cl)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LOCK(cl->refCountMutex);
|
|
|
|
|
|
|
|
cl->refCount--;
|
|
|
|
|
|
|
|
if(cl->refCount<=0) /* just to be sure also < 0 */
|
|
|
|
|
|
|
|
SIGNAL(cl->deleteCond);
|
|
|
|
|
|
|
|
UNLOCK(cl->refCountMutex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MUTEX(rfbClientListMutex);
|
|
|
|
|
|
|
|
|
|
|
|
struct rfbClientIterator {
|
|
|
|
struct rfbClientIterator {
|
|
|
|
rfbClientPtr next;
|
|
|
|
rfbClientPtr next;
|
|
|
|
|
|
|
|
rfbScreenInfoPtr screen;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
|
|
|
|
static pthread_mutex_t rfbClientListMutex;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct rfbClientIterator rfbClientIteratorInstance;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
rfbClientListInit(rfbScreenInfoPtr rfbScreen)
|
|
|
|
rfbClientListInit(rfbScreenInfoPtr rfbScreen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rfbScreen->rfbClientHead = NULL;
|
|
|
|
rfbScreen->rfbClientHead = NULL;
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
|
|
|
|
pthread_mutex_init(&rfbClientListMutex, NULL);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rfbClientIteratorPtr
|
|
|
|
rfbClientIteratorPtr
|
|
|
|
rfbGetClientIterator(rfbScreenInfoPtr rfbScreen)
|
|
|
|
rfbGetClientIterator(rfbScreenInfoPtr rfbScreen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
rfbClientIteratorPtr i =
|
|
|
|
pthread_mutex_lock(&rfbClientListMutex);
|
|
|
|
(rfbClientIteratorPtr)malloc(sizeof(struct rfbClientIterator));
|
|
|
|
#endif
|
|
|
|
i->next = 0;
|
|
|
|
rfbClientIteratorInstance.next = rfbScreen->rfbClientHead;
|
|
|
|
i->screen = rfbScreen;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
return &rfbClientIteratorInstance;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rfbClientPtr
|
|
|
|
rfbClientPtr
|
|
|
|
rfbClientIteratorNext(rfbClientIteratorPtr iterator)
|
|
|
|
rfbClientIteratorNext(rfbClientIteratorPtr i)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rfbClientPtr result;
|
|
|
|
if(i->next == 0) {
|
|
|
|
result = iterator->next;
|
|
|
|
LOCK(rfbClientListMutex);
|
|
|
|
if (result)
|
|
|
|
i->next = i->screen->rfbClientHead;
|
|
|
|
iterator->next = result->next;
|
|
|
|
UNLOCK(rfbClientListMutex);
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
IF_PTHREADS(rfbClientPtr cl = i->next);
|
|
|
|
|
|
|
|
i->next = i->next->next;
|
|
|
|
|
|
|
|
IF_PTHREADS(rfbDecrClientRef(cl));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
|
|
|
|
while(i->next && i->next->sock<0)
|
|
|
|
|
|
|
|
i->next = i->next->next;
|
|
|
|
|
|
|
|
if(i->next)
|
|
|
|
|
|
|
|
rfbIncrClientRef(i->next);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return i->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void
|
|
|
|
rfbReleaseClientIterator(rfbClientIteratorPtr iterator)
|
|
|
|
rfbReleaseClientIterator(rfbClientIteratorPtr iterator)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
IF_PTHREADS(if(iterator->next) rfbDecrClientRef(iterator->next));
|
|
|
|
pthread_mutex_unlock(&rfbClientListMutex);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -169,9 +188,7 @@ rfbNewClient(rfbScreen,sock)
|
|
|
|
getpeername(sock, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
getpeername(sock, (struct sockaddr *)&addr, &addrlen);
|
|
|
|
cl->host = strdup(inet_ntoa(addr.sin_addr));
|
|
|
|
cl->host = strdup(inet_ntoa(addr.sin_addr));
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
INIT_MUTEX(cl->outputMutex);
|
|
|
|
pthread_mutex_init(&cl->outputMutex, NULL);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cl->state = RFB_PROTOCOL_VERSION;
|
|
|
|
cl->state = RFB_PROTOCOL_VERSION;
|
|
|
|
|
|
|
|
|
|
|
@ -189,10 +206,8 @@ rfbNewClient(rfbScreen,sock)
|
|
|
|
cl->modifiedRegion =
|
|
|
|
cl->modifiedRegion =
|
|
|
|
sraRgnCreateRect(0,0,rfbScreen->width,rfbScreen->height);
|
|
|
|
sraRgnCreateRect(0,0,rfbScreen->width,rfbScreen->height);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
INIT_MUTEX(cl->updateMutex);
|
|
|
|
pthread_mutex_init(&cl->updateMutex, NULL);
|
|
|
|
INIT_COND(cl->updateCond);
|
|
|
|
pthread_cond_init(&cl->updateCond, NULL);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cl->requestedRegion = sraRgnCreate();
|
|
|
|
cl->requestedRegion = sraRgnCreate();
|
|
|
|
|
|
|
|
|
|
|
@ -200,18 +215,16 @@ rfbNewClient(rfbScreen,sock)
|
|
|
|
cl->translateFn = rfbTranslateNone;
|
|
|
|
cl->translateFn = rfbTranslateNone;
|
|
|
|
cl->translateLookupTable = NULL;
|
|
|
|
cl->translateLookupTable = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
LOCK(rfbClientListMutex);
|
|
|
|
pthread_mutex_lock(&rfbClientListMutex);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
cl->refCount = 0;
|
|
|
|
cl->next = rfbScreen->rfbClientHead;
|
|
|
|
cl->next = rfbScreen->rfbClientHead;
|
|
|
|
cl->prev = NULL;
|
|
|
|
cl->prev = NULL;
|
|
|
|
if (rfbScreen->rfbClientHead)
|
|
|
|
if (rfbScreen->rfbClientHead)
|
|
|
|
rfbScreen->rfbClientHead->prev = cl;
|
|
|
|
rfbScreen->rfbClientHead->prev = cl;
|
|
|
|
|
|
|
|
|
|
|
|
rfbScreen->rfbClientHead = cl;
|
|
|
|
rfbScreen->rfbClientHead = cl;
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
UNLOCK(rfbClientListMutex);
|
|
|
|
pthread_mutex_unlock(&rfbClientListMutex);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cl->tightCompressLevel = TIGHT_DEFAULT_COMPRESSION;
|
|
|
|
cl->tightCompressLevel = TIGHT_DEFAULT_COMPRESSION;
|
|
|
|
cl->tightQualityLevel = -1;
|
|
|
|
cl->tightQualityLevel = -1;
|
|
|
@ -261,12 +274,23 @@ rfbClientConnectionGone(cl)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOCK(rfbClientListMutex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cl->prev)
|
|
|
|
|
|
|
|
cl->prev->next = cl->next;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
cl->screen->rfbClientHead = cl->next;
|
|
|
|
|
|
|
|
if (cl->next)
|
|
|
|
|
|
|
|
cl->next->prev = cl->prev;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
/*
|
|
|
|
LOCK(cl->refCountMutex);
|
|
|
|
pthread_mutex_lock(&cl->updateMutex);
|
|
|
|
if(cl->refCount) {
|
|
|
|
pthread_mutex_lock(&cl->outputMutex);
|
|
|
|
UNLOCK(cl->refCountMutex);
|
|
|
|
*/
|
|
|
|
WAIT(cl->deleteCond,cl->refCountMutex);
|
|
|
|
pthread_mutex_lock(&rfbClientListMutex);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
UNLOCK(cl->refCountMutex);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
cl->clientGoneHook(cl);
|
|
|
|
cl->clientGoneHook(cl);
|
|
|
@ -287,28 +311,19 @@ rfbClientConnectionGone(cl)
|
|
|
|
if (pointerClient == cl)
|
|
|
|
if (pointerClient == cl)
|
|
|
|
pointerClient = NULL;
|
|
|
|
pointerClient = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (cl->prev)
|
|
|
|
|
|
|
|
cl->prev->next = cl->next;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
cl->screen->rfbClientHead = cl->next;
|
|
|
|
|
|
|
|
if (cl->next)
|
|
|
|
|
|
|
|
cl->next->prev = cl->prev;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sraRgnDestroy(cl->modifiedRegion);
|
|
|
|
sraRgnDestroy(cl->modifiedRegion);
|
|
|
|
|
|
|
|
|
|
|
|
rfbPrintStats(cl);
|
|
|
|
UNLOCK(rfbClientListMutex);
|
|
|
|
|
|
|
|
|
|
|
|
if (cl->translateLookupTable) free(cl->translateLookupTable);
|
|
|
|
if (cl->translateLookupTable) free(cl->translateLookupTable);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
TINI_COND(cl->updateCond);
|
|
|
|
pthread_mutex_unlock(&rfbClientListMutex);
|
|
|
|
TINI_MUTEX(cl->updateMutex);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
LOCK(cl->outputMutex);
|
|
|
|
pthread_cond_destroy(&cl->updateCond);
|
|
|
|
TINI_MUTEX(cl->outputMutex);
|
|
|
|
pthread_mutex_destroy(&cl->updateMutex);
|
|
|
|
|
|
|
|
pthread_mutex_destroy(&cl->outputMutex);
|
|
|
|
rfbPrintStats(cl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xfree(cl);
|
|
|
|
xfree(cl);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -694,9 +709,7 @@ rfbProcessClientNormalMessage(cl)
|
|
|
|
Swap16IfLE(msg.fur.x)+Swap16IfLE(msg.fur.w),
|
|
|
|
Swap16IfLE(msg.fur.x)+Swap16IfLE(msg.fur.w),
|
|
|
|
Swap16IfLE(msg.fur.y)+Swap16IfLE(msg.fur.h));
|
|
|
|
Swap16IfLE(msg.fur.y)+Swap16IfLE(msg.fur.h));
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
LOCK(cl->updateMutex);
|
|
|
|
pthread_mutex_lock(&cl->updateMutex);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sraRgnOr(cl->requestedRegion,tmpRegion);
|
|
|
|
sraRgnOr(cl->requestedRegion,tmpRegion);
|
|
|
|
|
|
|
|
|
|
|
|
if (!cl->readyForSetColourMapEntries) {
|
|
|
|
if (!cl->readyForSetColourMapEntries) {
|
|
|
@ -713,19 +726,16 @@ rfbProcessClientNormalMessage(cl)
|
|
|
|
if (!msg.fur.incremental) {
|
|
|
|
if (!msg.fur.incremental) {
|
|
|
|
sraRgnOr(cl->modifiedRegion,tmpRegion);
|
|
|
|
sraRgnOr(cl->modifiedRegion,tmpRegion);
|
|
|
|
sraRgnSubtract(cl->copyRegion,tmpRegion);
|
|
|
|
sraRgnSubtract(cl->copyRegion,tmpRegion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef HAVE_PTHREADS
|
|
|
|
SIGNAL(cl->updateCond);
|
|
|
|
pthread_cond_signal(&cl->updateCond);
|
|
|
|
UNLOCK(cl->updateMutex);
|
|
|
|
pthread_mutex_unlock(&cl->updateMutex);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(cl->sock>=0 && FB_UPDATE_PENDING(cl)) {
|
|
|
|
|
|
|
|
rfbSendFramebufferUpdate(cl,cl->modifiedRegion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sraRgnDestroy(tmpRegion);
|
|
|
|
if(cl->sock>=0 && FB_UPDATE_PENDING(cl)) {
|
|
|
|
|
|
|
|
rfbSendFramebufferUpdate(cl,cl->modifiedRegion);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sraRgnDestroy(tmpRegion);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case rfbKeyEvent:
|
|
|
|
case rfbKeyEvent:
|
|
|
@ -1209,6 +1219,9 @@ Bool
|
|
|
|
rfbSendUpdateBuf(cl)
|
|
|
|
rfbSendUpdateBuf(cl)
|
|
|
|
rfbClientPtr cl;
|
|
|
|
rfbClientPtr cl;
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(cl->sock<0)
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
|
|
if (WriteExact(cl, cl->updateBuf, cl->ublen) < 0) {
|
|
|
|
if (WriteExact(cl, cl->updateBuf, cl->ublen) < 0) {
|
|
|
|
rfbLogPerror("rfbSendUpdateBuf: write");
|
|
|
|
rfbLogPerror("rfbSendUpdateBuf: write");
|
|
|
|
rfbCloseClient(cl);
|
|
|
|
rfbCloseClient(cl);
|
|
|
@ -1275,17 +1288,19 @@ rfbSendSetColourMapEntries(cl, firstColour, nColours)
|
|
|
|
void
|
|
|
|
void
|
|
|
|
rfbSendBell(rfbScreenInfoPtr rfbScreen)
|
|
|
|
rfbSendBell(rfbScreenInfoPtr rfbScreen)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rfbClientPtr cl, nextCl;
|
|
|
|
rfbClientIteratorPtr i;
|
|
|
|
|
|
|
|
rfbClientPtr cl;
|
|
|
|
rfbBellMsg b;
|
|
|
|
rfbBellMsg b;
|
|
|
|
|
|
|
|
|
|
|
|
for (cl = rfbScreen->rfbClientHead; cl; cl = nextCl) {
|
|
|
|
i = rfbGetClientIterator(rfbScreen);
|
|
|
|
nextCl = cl->next;
|
|
|
|
while((cl=rfbClientIteratorNext(i))) {
|
|
|
|
b.type = rfbBell;
|
|
|
|
b.type = rfbBell;
|
|
|
|
if (WriteExact(cl, (char *)&b, sz_rfbBellMsg) < 0) {
|
|
|
|
if (WriteExact(cl, (char *)&b, sz_rfbBellMsg) < 0) {
|
|
|
|
rfbLogPerror("rfbSendBell: write");
|
|
|
|
rfbLogPerror("rfbSendBell: write");
|
|
|
|
rfbCloseClient(cl);
|
|
|
|
rfbCloseClient(cl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rfbReleaseClientIterator(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|