[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/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: