summaryrefslogtreecommitdiffstats
path: root/libvncserver
diff options
context:
space:
mode:
authordscho <dscho>2005-09-27 15:18:22 +0000
committerdscho <dscho>2005-09-27 15:18:22 +0000
commit93be927b1c1c74bc4da6f6d5978ba8e6e52f3cc2 (patch)
tree0ec66825e92a2cf60e0f32b7ab74bc5777318bd6 /libvncserver
parent94fcd86cc20dd2ccf7e2299a7dfbcc255c6cc771 (diff)
downloadlibtdevnc-93be927b1c1c74bc4da6f6d5978ba8e6e52f3cc2.tar.gz
libtdevnc-93be927b1c1c74bc4da6f6d5978ba8e6e52f3cc2.zip
Introduce generic protocol extension method. Deprecate
the processCustomClientMessage() method.
Diffstat (limited to 'libvncserver')
-rw-r--r--libvncserver/cargs.c25
-rw-r--r--libvncserver/main.c38
-rw-r--r--libvncserver/rfbserver.c43
-rwxr-xr-xlibvncserver/sockets.c7
4 files changed, 103 insertions, 10 deletions
diff --git a/libvncserver/cargs.c b/libvncserver/cargs.c
index d0e3309..10926a9 100644
--- a/libvncserver/cargs.c
+++ b/libvncserver/cargs.c
@@ -19,6 +19,8 @@ extern int rfbStringToAddr(char *str, in_addr_t *iface);
void
rfbUsage(void)
{
+ rfbProtocolExtension* extension;
+
fprintf(stderr, "-rfbport port TCP port for RFB protocol\n");
fprintf(stderr, "-rfbwait time max time in ms to wait for RFB client\n");
fprintf(stderr, "-rfbauth passwd-file use authentication on RFB protocol\n"
@@ -40,6 +42,11 @@ rfbUsage(void)
fprintf(stderr, "-progressive height enable progressive updating for slow links\n");
fprintf(stderr, "-listen ipaddr listen for connections only on network interface with\n");
fprintf(stderr, " addr ipaddr. '-listen localhost' and hostname work too.\n");
+
+ for(extension=rfbGetExtensionIterator();extension;extension=extension->next)
+ if(extension->usage)
+ extension->usage();
+ rfbReleaseExtensionIterator();
}
/* purges COUNT arguments from ARGV at POSITION and decrements ARGC.
@@ -138,9 +145,21 @@ rfbProcessArguments(rfbScreenInfoPtr rfbScreen,int* argc, char *argv[])
return FALSE;
}
} else {
- i++;
- i1=i;
- continue;
+ rfbProtocolExtension* extension;
+ int handled=0;
+
+ for(extension=rfbGetExtensionIterator();handled==0 && extension;
+ extension=extension->next)
+ if(extension->processArgument)
+ handled = extension->processArgument(argv + i);
+ rfbReleaseExtensionIterator();
+
+ if(handled==0) {
+ i++;
+ i1=i;
+ continue;
+ }
+ i+=handled-1;
}
/* we just remove the processed arguments from the list */
rfbPurgeArguments(argc,&i1,i-i1+1,argv);
diff --git a/libvncserver/main.c b/libvncserver/main.c
index a9161ce..905bb83 100644
--- a/libvncserver/main.c
+++ b/libvncserver/main.c
@@ -40,6 +40,7 @@
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
static MUTEX(logMutex);
+static MUTEX(extMutex);
#endif
static int rfbEnableLogging=1;
@@ -50,6 +51,43 @@ char rfbEndianTest = 0;
char rfbEndianTest = -1;
#endif
+/*
+ * Protocol extensions
+ */
+
+static rfbProtocolExtension* rfbExtensionHead = NULL;
+
+void
+rfbRegisterProtocolExtension(rfbProtocolExtension* extension)
+{
+ rfbProtocolExtension* last;
+
+ LOCK(extMutex);
+ last = extension;
+
+ while(last->next)
+ last = last->next;
+
+ last->next = rfbExtensionHead;
+ rfbExtensionHead = extension;
+ UNLOCK(extMutex);
+}
+
+rfbProtocolExtension* rfbGetExtensionIterator()
+{
+ LOCK(extMutex);
+ return rfbExtensionHead;
+}
+
+void rfbReleaseExtensionIterator()
+{
+ UNLOCK(extMutex);
+}
+
+/*
+ * Logging
+ */
+
void rfbLogEnable(int enabled) {
rfbEnableLogging=enabled;
}
diff --git a/libvncserver/rfbserver.c b/libvncserver/rfbserver.c
index 1f71a18..730c789 100644
--- a/libvncserver/rfbserver.c
+++ b/libvncserver/rfbserver.c
@@ -3,6 +3,7 @@
*/
/*
+ * Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
* Copyright (C) 2002 RealVNC Ltd.
* OSXvnc Copyright (C) 2001 Dan McGuirk <[email protected]>.
* Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
@@ -347,6 +348,8 @@ rfbNewTCPOrUDPClient(rfbScreenInfoPtr rfbScreen,
cl->progressiveSliceY = 0;
+ cl->extensions = NULL;
+
sprintf(pv,rfbProtocolVersionFormat,rfbProtocolMajorVersion,
rfbProtocolMinorVersion);
@@ -603,6 +606,7 @@ rfbProcessClientInitMessage(rfbClientPtr cl)
int len, n;
rfbClientIteratorPtr iterator;
rfbClientPtr otherCl;
+ rfbProtocolExtension* extension;
if ((n = rfbReadExact(cl, (char *)&ci,sz_rfbClientInitMsg)) <= 0) {
if (n == 0)
@@ -613,7 +617,7 @@ rfbProcessClientInitMessage(rfbClientPtr cl)
return;
}
- memset(buf,0,256);
+ memset(buf,0,sizeof(buf));
si->framebufferWidth = Swap16IfLE(cl->screen->width);
si->framebufferHeight = Swap16IfLE(cl->screen->height);
@@ -632,6 +636,19 @@ rfbProcessClientInitMessage(rfbClientPtr cl)
return;
}
+ for(extension=rfbGetExtensionIterator();extension;extension=extension->next)
+ if(extension->init) {
+ void* data;
+ if(extension->init(cl, &data)) {
+ rfbExtensionData* extensionData=calloc(sizeof(rfbExtensionData),1);
+ extensionData->extension=extension;
+ extensionData->data=data;
+ extensionData->next=cl->extensions;
+ cl->extensions=extensionData;
+ }
+ }
+ rfbReleaseExtensionIterator();
+
cl->state = RFB_NORMAL;
if (!cl->reverseConnection &&
@@ -1046,15 +1063,27 @@ rfbProcessClientNormalMessage(rfbClientPtr cl)
default:
+ {
+ rfbExtensionData* extension;
+
+ for(extension=cl->extensions; extension; extension=extension->next)
+ if(extension->extension->handleMessage &&
+ extension->extension->handleMessage(cl, extension->data, msg))
+ return;
- if(cl->screen->processCustomClientMessage(cl,msg.type))
+ if(cl->screen->processCustomClientMessage(cl,msg.type)) {
+ rfbLog("Warning: this program uses processCustomClientMessage, "
+ "which is deprecated.\n"
+ "Please use rfbRegisterProtocolExtension instead.\n");
return;
+ }
- rfbLog("rfbProcessClientNormalMessage: unknown message type %d\n",
- msg.type);
- rfbLog(" ... closing connection\n");
- rfbCloseClient(cl);
- return;
+ rfbLog("rfbProcessClientNormalMessage: unknown message type %d\n",
+ msg.type);
+ rfbLog(" ... closing connection\n");
+ rfbCloseClient(cl);
+ return;
+ }
}
}
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c
index 24a787d..44843c2 100755
--- a/libvncserver/sockets.c
+++ b/libvncserver/sockets.c
@@ -19,6 +19,7 @@
*/
/*
+ * Copyright (C) 2005 Rohit Kumar, Johannes E. Schindelin
* OSXvnc Copyright (C) 2001 Dan McGuirk <[email protected]>.
* Original Xvnc code Copyright (C) 1999 AT&T Laboratories Cambridge.
* All Rights Reserved.
@@ -344,6 +345,12 @@ rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen)
void
rfbCloseClient(rfbClientPtr cl)
{
+ rfbExtensionData* extension;
+
+ for(extension=cl->extensions; extension; extension=extension->next)
+ if(extension->extension->close)
+ extension->extension->close(cl, extension->data);
+
LOCK(cl->updateMutex);
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
if (cl->sock != -1)