summaryrefslogtreecommitdiffstats
path: root/libvncserver
diff options
context:
space:
mode:
Diffstat (limited to 'libvncserver')
-rwxr-xr-xlibvncserver/auth.c58
-rw-r--r--libvncserver/main.c73
-rw-r--r--libvncserver/tightvnc-filetransfer/rfbtightserver.c5
3 files changed, 127 insertions, 9 deletions
diff --git a/libvncserver/auth.c b/libvncserver/auth.c
index e3a89eb..fd4c487 100755
--- a/libvncserver/auth.c
+++ b/libvncserver/auth.c
@@ -35,18 +35,68 @@
static rfbSecurityHandler* securityHandlers = NULL;
+/*
+ * This method registers a list of new security types.
+ * It avoids same security type getting registered multiple times.
+ * The order is not preserved if multiple security types are
+ * registered at one-go.
+ */
void
rfbRegisterSecurityHandler(rfbSecurityHandler* handler)
{
- rfbSecurityHandler* last = handler;
+ rfbSecurityHandler *head = securityHandlers, *next = NULL;
+
+ if(handler == NULL)
+ return;
- while(last->next)
- last = last->next;
+ next = handler->next;
- last->next = securityHandlers;
+ while(head != NULL) {
+ if(head == handler) {
+ rfbRegisterSecurityHandler(next);
+ return;
+ }
+
+ head = head->next;
+ }
+
+ handler->next = securityHandlers;
securityHandlers = handler;
+
+ rfbRegisterSecurityHandler(next);
}
+/*
+ * This method unregisters a list of security types.
+ * These security types won't be available for any new
+ * client connection.
+ */
+void
+rfbUnregisterSecurityHandler(rfbSecurityHandler* handler)
+{
+ rfbSecurityHandler *cur = NULL, *pre = NULL;
+
+ if(handler == NULL)
+ return;
+
+ if(securityHandlers == handler) {
+ securityHandlers = securityHandlers->next;
+ rfbUnregisterSecurityHandler(handler->next);
+ return;
+ }
+
+ cur = pre = securityHandlers;
+
+ while(cur) {
+ if(cur == handler) {
+ pre->next = cur->next;
+ break;
+ }
+ pre = cur;
+ cur = cur->next;
+ }
+ rfbUnregisterSecurityHandler(handler->next);
+}
/*
* Send the authentication challenge.
diff --git a/libvncserver/main.c b/libvncserver/main.c
index ada1a7a..bf14062 100644
--- a/libvncserver/main.c
+++ b/libvncserver/main.c
@@ -59,10 +59,21 @@ char rfbEndianTest = -1;
static rfbProtocolExtension* rfbExtensionHead = NULL;
+/*
+ * This method registers a list of new extensions.
+ * It avoids same extension getting registered multiple times.
+ * The order is not preserved if multiple extensions are
+ * registered at one-go.
+ */
void
rfbRegisterProtocolExtension(rfbProtocolExtension* extension)
{
- rfbProtocolExtension* last;
+ rfbProtocolExtension *head = rfbExtensionHead, *next = NULL;
+
+ if(extension == NULL)
+ return;
+
+ next = extension->next;
if (! extMutex_initialized) {
INIT_MUTEX(extMutex);
@@ -70,14 +81,66 @@ rfbRegisterProtocolExtension(rfbProtocolExtension* extension)
}
LOCK(extMutex);
- last = extension;
- while(last->next)
- last = last->next;
+ while(head != NULL) {
+ if(head == extension) {
+ UNLOCK(extMutex);
+ rfbRegisterProtocolExtension(next);
+ return;
+ }
+
+ head = head->next;
+ }
- last->next = rfbExtensionHead;
+ extension->next = rfbExtensionHead;
rfbExtensionHead = extension;
+
+ UNLOCK(extMutex);
+ rfbRegisterProtocolExtension(next);
+}
+
+/*
+ * This method unregisters a list of extensions.
+ * These extensions won't be available for any new
+ * client connection.
+ */
+void
+rfbUnregisterProtocolExtension(rfbProtocolExtension* extension)
+{
+
+ rfbProtocolExtension *cur = NULL, *pre = NULL;
+
+ if(extension == NULL)
+ return;
+
+ if (! extMutex_initialized) {
+ INIT_MUTEX(extMutex);
+ extMutex_initialized = 1;
+ }
+
+ LOCK(extMutex);
+
+ if(rfbExtensionHead == extension) {
+ rfbExtensionHead = rfbExtensionHead->next;
+ UNLOCK(extMutex);
+ rfbUnregisterProtocolExtension(extension->next);
+ return;
+ }
+
+ cur = pre = rfbExtensionHead;
+
+ while(cur) {
+ if(cur == extension) {
+ pre->next = cur->next;
+ break;
+ }
+ pre = cur;
+ cur = cur->next;
+ }
+
UNLOCK(extMutex);
+
+ rfbUnregisterProtocolExtension(extension->next);
}
rfbProtocolExtension* rfbGetExtensionIterator()
diff --git a/libvncserver/tightvnc-filetransfer/rfbtightserver.c b/libvncserver/tightvnc-filetransfer/rfbtightserver.c
index 933025f..2acfa9c 100644
--- a/libvncserver/tightvnc-filetransfer/rfbtightserver.c
+++ b/libvncserver/tightvnc-filetransfer/rfbtightserver.c
@@ -506,4 +506,9 @@ void rfbRegisterTightVNCFileTransferExtension() {
rfbRegisterSecurityHandler(&tightVncSecurityHandler);
}
+void
+rfbUnregisterTightVNCFileTransferExtension() {
+ rfbUnregisterProtocolExtension(&tightVncFileTransferExtension);
+ rfbUnregisterSecurityHandler(&tightVncSecurityHandler);
+}