[Development] Enhance Security class to be usable by viewer.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4041 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/common/rfb/CSecurityNone.h b/common/rfb/CSecurityNone.h
index 54c1016..a7db6e0 100644
--- a/common/rfb/CSecurityNone.h
+++ b/common/rfb/CSecurityNone.h
@@ -22,6 +22,7 @@
 #ifndef __CSECURITYNONE_H__
 #define __CSECURITYNONE_H__
 
+#include <rfb/Security.h>
 #include <rfb/CSecurity.h>
 
 namespace rfb {
diff --git a/common/rfb/Security.cxx b/common/rfb/Security.cxx
index adc21c9..daf3ac5 100644
--- a/common/rfb/Security.cxx
+++ b/common/rfb/Security.cxx
@@ -21,6 +21,8 @@
 #ifdef _WIN32
 #define strcasecmp _stricmp
 #endif
+#include <rfb/CSecurityNone.h>
+#include <rfb/CSecurityVncAuth.h>
 #include <rdr/Exception.h>
 #include <rfb/LogWriter.h>
 #include <rfb/Security.h>
@@ -39,7 +41,7 @@
  "Specify which security scheme to use (None, VncAuth)",
  "VncAuth");
 
-Security::Security(void)
+Security::Security(void) : upg(NULL)
 {
   char *secTypesStr = secTypes.getData();
 
@@ -78,9 +80,22 @@
   switch (secType) {
   case secTypeNone: return new SSecurityNone();
   case secTypeVncAuth: return new SSecurityVncAuth();
-  default:
-    vlog.error("Undefined security type %d, aborting");
-    abort();
+  }
+
+bail:
+  throw Exception("Security type not supported");
+}
+
+CSecurity* Security::GetCSecurity(rdr::U8 secType)
+{
+  assert (upg != NULL); /* (upg == NULL) means bug in the viewer */
+
+  if (!IsSupported(secType))
+    goto bail;
+
+  switch (secType) {
+  case secTypeNone: return new CSecurityNone();
+  case secTypeVncAuth: return new CSecurityVncAuth(upg);
   }
 
 bail:
diff --git a/common/rfb/Security.h b/common/rfb/Security.h
index cb49911..edbcd44 100644
--- a/common/rfb/Security.h
+++ b/common/rfb/Security.h
@@ -24,7 +24,9 @@
 
 #include <rdr/types.h>
 #include <rfb/Configuration.h>
+#include <rfb/CSecurity.h>
 #include <rfb/SSecurity.h>
+#include <rfb/UserPasswdGetter.h>
 
 #include <list>
 
@@ -51,7 +53,9 @@
 
   class Security {
   public:
-    /* Create Security instance */
+    /*
+     * Create Security instance.
+     */
     Security(void);
 
     /* Enable/Disable certain security type */
@@ -68,7 +72,16 @@
     /* Create server side SSecurity class instance */
     SSecurity* GetSSecurity(rdr::U8 secType);
 
+    /* Create client side CSecurity class instance */
+    CSecurity* GetCSecurity(rdr::U8 secType);
+
     static StringParameter secTypes;
+
+    /*
+     * Use variable directly instead of dumb get/set methods. It is used
+     * only in viewer-side code and MUST be set by viewer.
+     */
+    UserPasswdGetter *upg;
   private:
     std::list<rdr::U8> enabledSecTypes;
   };