]> source.dussan.org Git - tigervnc.git/commitdiff
Use StringParameters directly
authorPierre Ossman <ossman@cendio.se>
Tue, 10 Jan 2023 18:26:48 +0000 (19:26 +0100)
committerPierre Ossman <ossman@cendio.se>
Sat, 4 Feb 2023 13:03:13 +0000 (14:03 +0100)
We don't need to make extra copies of the string in most cases, so let's
simplify the code and access the string directly when we can.

20 files changed:
common/rfb/CSecurityTLS.cxx
common/rfb/CSecurityTLS.h
common/rfb/SDesktop.h
common/rfb/SSecurity.h
common/rfb/SSecurityRSAAES.cxx
common/rfb/SSecurityTLS.cxx
common/rfb/SSecurityTLS.h
common/rfb/SSecurityVncAuth.cxx
common/rfb/Security.cxx
common/rfb/UnixPasswordValidator.cxx
unix/vncconfig/vncconfig.cxx
unix/x0vncserver/Geometry.cxx
unix/x0vncserver/x0vncserver.cxx
unix/xserver/hw/vnc/vncExtInit.cc
vncviewer/UserDialog.cxx
vncviewer/vncviewer.cxx
win/rfb_win32/SDisplay.cxx
win/vncconfig/Connections.h
win/vncconfig/Desktop.h
win/winvnc/VNCServerWin32.cxx

index ca1c919becedd19abef2904dd9b115bc2f5ddbab..aaf792d34359dcd8f17c6df43da8a81b3a858dc4 100644 (file)
@@ -92,9 +92,6 @@ CSecurityTLS::CSecurityTLS(CConnection* cc, bool _anon)
   : CSecurity(cc), session(NULL), anon_cred(NULL), cert_cred(NULL),
     anon(_anon), tlsis(NULL), tlsos(NULL), rawis(NULL), rawos(NULL)
 {
-  cafile = X509CA.getData();
-  crlfile = X509CRL.getData();
-
   if (gnutls_global_init() != GNUTLS_E_SUCCESS)
     throw AuthFailureException("gnutls_global_init failed");
 }
@@ -146,9 +143,6 @@ CSecurityTLS::~CSecurityTLS()
 {
   shutdown();
 
-  delete[] cafile;
-  delete[] crlfile;
-
   gnutls_global_deinit();
 }
 
@@ -287,10 +281,10 @@ void CSecurityTLS::setParam()
     if (gnutls_certificate_set_x509_system_trust(cert_cred) < 1)
       vlog.error("Could not load system certificate trust store");
 
-    if (*cafile && gnutls_certificate_set_x509_trust_file(cert_cred,cafile,GNUTLS_X509_FMT_PEM) < 0)
+    if (gnutls_certificate_set_x509_trust_file(cert_cred, X509CA, GNUTLS_X509_FMT_PEM) < 0)
       vlog.error("Could not load user specified certificate authority");
 
-    if (*crlfile && gnutls_certificate_set_x509_crl_file(cert_cred,crlfile,GNUTLS_X509_FMT_PEM) < 0)
+    if (gnutls_certificate_set_x509_crl_file(cert_cred, X509CRL, GNUTLS_X509_FMT_PEM) < 0)
       vlog.error("Could not load user specified certificate revocation list");
 
     if (gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, cert_cred) != GNUTLS_E_SUCCESS)
index fb317748e221ad06f13dc5b59126742015fa54e3..b9c345cfb2403e60363a31ee78609ff1eef21220 100644 (file)
@@ -58,8 +58,6 @@ namespace rfb {
     gnutls_certificate_credentials_t cert_cred;
     bool anon;
 
-    char *cafile, *crlfile;
-
     rdr::InStream* tlsis;
     rdr::OutStream* tlsos;
 
index 0a6203a207a1896b9f83f4ae1741b90314fd40a5..175609fca6429116a727e86fb4a5f8d5afc0680f 100644 (file)
@@ -43,7 +43,6 @@
 #include <rfb/InputHandler.h>
 #include <rfb/Exception.h>
 #include <rfb/screenTypes.h>
-#include <rfb/util.h>
 
 namespace network { class Socket; }
 
index fa3c63cbe293845812aa693193c9eb5dd8905d29..fbc3de6f97e1ce361ac32fff62788589a8612d68 100644 (file)
@@ -44,7 +44,7 @@
 #define __RFB_SSECURITY_H__
 
 #include <rfb/SConnection.h>
-#include <rfb/util.h>
+
 #include <list>
 
 namespace rfb {
index 5ebec79f3b9c367e1d27b7dfbdaf7cebf3bdd0c1..d013717cdc542a31b5901fe1173172e544335afd 100644 (file)
@@ -152,7 +152,7 @@ static bool loadPEM(uint8_t* data, size_t size, const char *begin,
 
 void SSecurityRSAAES::loadPrivateKey()
 {
-  FILE* file = fopen(keyFile.getData(), "rb");
+  FILE* file = fopen(keyFile, "rb");
   if (!file)
     throw ConnFailedException("failed to open key file");
   fseek(file, 0, SEEK_END);
index f3d58ae0450db7c23fc1f2e5a961fca09846b53b..1abfd774bd970e62a1e7311cde34cac0e067d060 100644 (file)
@@ -75,9 +75,6 @@ SSecurityTLS::SSecurityTLS(SConnection* sc, bool _anon)
   dh_params = NULL;
 #endif
 
-  certfile = X509_CertFile.getData();
-  keyfile = X509_KeyFile.getData();
-
   if (gnutls_global_init() != GNUTLS_E_SUCCESS)
     throw AuthFailureException("gnutls_global_init failed");
 }
@@ -136,9 +133,6 @@ SSecurityTLS::~SSecurityTLS()
 {
   shutdown();
 
-  delete[] keyfile;
-  delete[] certfile;
-
   gnutls_global_deinit();
 }
 
@@ -293,7 +287,7 @@ void SSecurityTLS::setParams(gnutls_session_t session)
     gnutls_certificate_set_dh_params(cert_cred, dh_params);
 #endif
 
-    switch (gnutls_certificate_set_x509_key_file(cert_cred, certfile, keyfile, GNUTLS_X509_FMT_PEM)) {
+    switch (gnutls_certificate_set_x509_key_file(cert_cred, X509_CertFile, X509_KeyFile, GNUTLS_X509_FMT_PEM)) {
     case GNUTLS_E_SUCCESS:
       break;
     case GNUTLS_E_CERTIFICATE_KEY_MISMATCH:
index 4e06d6ba2007068d1d50eb2d8834e85ea146af88..d0f735fe46d5d1b3b4f6491726c245ded1292138 100644 (file)
@@ -63,7 +63,6 @@ namespace rfb {
 #endif
     gnutls_anon_server_credentials_t anon_cred;
     gnutls_certificate_credentials_t cert_cred;
-    char *keyfile, *certfile;
 
     bool anon;
 
index d035f97f962117f3eff45484988c158cb1e8588f..bb644cf232c2753609299ae8e8da92c3a8fdf5f1 100644 (file)
@@ -31,7 +31,6 @@
 #include <rfb/Password.h>
 #include <rfb/Configuration.h>
 #include <rfb/LogWriter.h>
-#include <rfb/util.h>
 #include <rfb/Exception.h>
 #include <string.h>
 #include <stdio.h>
@@ -132,15 +131,15 @@ void VncAuthPasswdParameter::getVncAuthPasswd(PlainPasswd *password, PlainPasswd
 
   if (obfuscated.length == 0) {
     if (passwdFile) {
-      CharArray fname(passwdFile->getData());
-      if (!fname.buf[0]) {
+      const char *fname = *passwdFile;
+      if (!fname[0]) {
         vlog.info("neither %s nor %s params set", getName(), passwdFile->getName());
         return;
       }
 
-      FILE* fp = fopen(fname.buf, "r");
+      FILE* fp = fopen(fname, "r");
       if (!fp) {
-        vlog.error("opening password file '%s' failed",fname.buf);
+        vlog.error("opening password file '%s' failed", fname);
         return;
       }
 
index e1c3513949695fe541d9da61bc483a37476d7b59..56d953f0e81bce70ffb43490115223f854d3d3e6 100644 (file)
@@ -61,12 +61,7 @@ Security::Security()
 
 Security::Security(StringParameter &secTypes)
 {
-  char *secTypesStr;
-
-  secTypesStr = secTypes.getData();
-  enabledSecTypes = parseSecTypes(secTypesStr);
-
-  delete [] secTypesStr;
+  enabledSecTypes = parseSecTypes(secTypes);
 }
 
 const std::list<uint8_t> Security::GetEnabledSecTypes(void)
index fa1513a45e5269c8b87c0a28159ff8663df8a9bf..57fa9b39653b58fc9661be9af1208859bed86e5c 100644 (file)
@@ -41,6 +41,5 @@ bool UnixPasswordValidator::validateInternal(SConnection * /*sc*/,
                                             const char *username,
                                             const char *password)
 {
-  CharArray service(strDup(pamService.getData()));
-  return do_pam_auth(service.buf, username, password);
+  return do_pam_auth(pamService, username, password);
 }
index c15d91f45691801e92b990154441a37fd9c3ec36..f39e9934ae3c765f99435edd4397934dd6e7e748 100644 (file)
@@ -225,16 +225,15 @@ int main(int argc, char** argv)
     break;
   }
 
-  CharArray displaynameStr(displayname.getData());
-  if (!(dpy = XOpenDisplay(displaynameStr.buf))) {
+  if (!(dpy = XOpenDisplay(displayname))) {
     fprintf(stderr,"%s: unable to open display \"%s\"\n",
-            programName, XDisplayName(displaynameStr.buf));
+            programName, XDisplayName(displayname));
     exit(1);
   }
 
   if (!XVncExtQueryExtension(dpy, &vncExtEventBase, &vncExtErrorBase)) {
     fprintf(stderr,"No VNC extension on display %s\n",
-            XDisplayName(displaynameStr.buf));
+            XDisplayName(displayname));
     exit(1);
   }
 
index 94ff51ba84e6764daa83b224c2fb0d706035b3ac..37b4e74e49645f360d9129551e15fd211e8cc701 100644 (file)
@@ -50,13 +50,11 @@ void Geometry::recalc(int fullWidth, int fullHeight)
   m_rect.setXYWH(0, 0, fullWidth, fullHeight);
 
   // Parse geometry specification and save the result in m_rect.
-  const char *param = m_geometryParam.getData();
+  const char *param = m_geometryParam;
   bool geometrySpecified = (strlen(param) > 0);
   if (geometrySpecified) {
     m_rect = parseString(param);
   }
-  delete[] param;               // don't forget to deallocate memory
-                                // allocated by StringParameter::getData()
   if (m_rect.is_empty()) {
     vlog.info("Desktop geometry is invalid");
     return;                     // further processing does not make sense
index c89cd8537b1fc2942cb8f83345537d52a271c9eb..9d74f9157424501bbe43f92e8992a53e687b1f27 100644 (file)
@@ -275,11 +275,10 @@ int main(int argc, char** argv)
     usage();
   }
 
-  CharArray dpyStr(displayname.getData());
-  if (!(dpy = XOpenDisplay(dpyStr.buf[0] ? dpyStr.buf : 0))) {
+  if (!(dpy = XOpenDisplay(displayname))) {
     // FIXME: Why not vlog.error(...)?
     fprintf(stderr,"%s: unable to open display \"%s\"\r\n",
-            programName, XDisplayName(dpyStr.buf));
+            programName, XDisplayName(displayname));
     exit(1);
   }
 
@@ -319,14 +318,12 @@ int main(int argc, char** argv)
                 (int)rfbport);
     }
 
-    const char *hostsData = hostsFile.getData();
-    FileTcpFilter fileTcpFilter(hostsData);
-    if (strlen(hostsData) != 0)
+    FileTcpFilter fileTcpFilter(hostsFile);
+    if (strlen(hostsFile) != 0)
       for (std::list<SocketListener*>::iterator i = listeners.begin();
            i != listeners.end();
            i++)
         (*i)->setFilter(&fileTcpFilter);
-    delete[] hostsData;
 
     PollingScheduler sched((int)pollingCycle, (int)maxProcessorUsage);
 
index 8dbc048c39b9061f4e720531271ca6f20938f8cd..4c1fdd4d25604326c463b1d7d0e48f95964331b2 100644 (file)
@@ -33,7 +33,6 @@
 #include <rfb/Configuration.h>
 #include <rfb/Logger_stdio.h>
 #include <rfb/LogWriter.h>
-#include <rfb/util.h>
 #include <rfb/ServerCore.h>
 #include <rdr/HexOutStream.h>
 #include <rfb/LogWriter.h>
@@ -246,13 +245,12 @@ void vncExtensionInit(void)
                     port);
         }
 
-        CharArray desktopNameStr(desktopName.getData());
         PixelFormat pf = vncGetPixelFormat(scr);
 
         vncSetGlueContext(scr);
         desktop[scr] = new XserverDesktop(scr,
                                           listeners,
-                                          desktopNameStr.buf,
+                                          desktopName,
                                           pf,
                                           vncGetScreenWidth(),
                                           vncGetScreenHeight(),
index 878446390651e4c3074240d3cdd14bf37446f4cc..ea5a8053fa8356e2895fdb453a916a1e19e1fc79 100644 (file)
@@ -73,7 +73,7 @@ UserDialog::~UserDialog()
 
 void UserDialog::getUserPasswd(bool secure, char** user, char** password)
 {
-  CharArray passwordFileStr(passwordFile.getData());
+  const char *passwordFileName(passwordFile);
 
   assert(password);
   char *envUsername = getenv("VNC_USERNAME");
@@ -90,11 +90,11 @@ void UserDialog::getUserPasswd(bool secure, char** user, char** password)
     return;
   }
 
-  if (!user && passwordFileStr.buf[0]) {
+  if (!user && passwordFileName[0]) {
     ObfuscatedPasswd obfPwd(256);
     FILE* fp;
 
-    fp = fopen(passwordFileStr.buf, "rb");
+    fp = fopen(passwordFileName, "rb");
     if (!fp)
       throw rfb::Exception(_("Opening password file failed"));
 
index 529f2f30c3bf3ae3994a059382ee6cecf7503194..549a9bedf7e645b07a1fb1c70128d761b7a49868 100644 (file)
@@ -742,7 +742,7 @@ int main(int argc, char** argv)
 
 #ifndef WIN32
   /* Specifying -via and -listen together is nonsense */
-  if (listenMode && strlen(via.getValueStr()) > 0) {
+  if (listenMode && strlen(via) > 0) {
     // TRANSLATORS: "Parameters" are command line arguments, or settings
     // from a file or the Windows registry.
     vlog.error(_("Parameters -listen and -via are incompatible"));
@@ -809,7 +809,7 @@ int main(int argc, char** argv)
     }
 
 #ifndef WIN32
-    if (strlen (via.getValueStr()) > 0 && mktunnel() != 0)
+    if (strlen(via) > 0 && mktunnel() != 0)
       usage(argv[0]);
 #endif
   }
index 02ef548d2685889ba6ceced581b418092598fb0c..110edcb0706737920f7c97ce4008ce90864ddfa7 100644 (file)
@@ -120,13 +120,12 @@ void SDisplay::stop()
   // If we successfully start()ed then perform the DisconnectAction
   if (core) {
     CurrentUserToken cut;
-    CharArray action(disconnectAction.getData());
-    if (stricmp(action.buf, "Logoff") == 0) {
+    if (stricmp(disconnectAction, "Logoff") == 0) {
       if (!cut.h)
         vlog.info("ignoring DisconnectAction=Logoff - no current user");
       else
         ExitWindowsEx(EWX_LOGOFF, 0);
-    } else if (stricmp(action.buf, "Lock") == 0) {
+    } else if (stricmp(disconnectAction, "Lock") == 0) {
       if (!cut.h) {
         vlog.info("ignoring DisconnectAction=Lock - no current user");
       } else {
@@ -448,10 +447,9 @@ SDisplay::recreatePixelBuffer(bool force) {
   //   Opening the whole display with CreateDC doesn't work on multi-monitor
   //   systems for some reason.
   DeviceContext* new_device = 0;
-  CharArray deviceName(displayDevice.getData());
-  if (deviceName.buf[0]) {
-    vlog.info("Attaching to device %s", deviceName.buf);
-    new_device = new DeviceDC(deviceName.buf);
+  if (strlen(displayDevice) > 0) {
+    vlog.info("Attaching to device %s", (const char*)displayDevice);
+    new_device = new DeviceDC(displayDevice);
   }
   if (!new_device) {
     vlog.info("Attaching to virtual desktop");
@@ -460,8 +458,8 @@ SDisplay::recreatePixelBuffer(bool force) {
 
   // Get the coordinates of the specified dispay device
   Rect newScreenRect;
-  if (deviceName.buf[0]) {
-    MonitorInfo info(deviceName.buf);
+  if (strlen(displayDevice) > 0) {
+    MonitorInfo info(displayDevice);
     newScreenRect = Rect(info.rcMonitor.left, info.rcMonitor.top,
                          info.rcMonitor.right, info.rcMonitor.bottom);
   } else {
index ff03897a8752b723194230ac76095bb1a427e439..d3e4dacee02d29cd023a5c23e4c5736d3d20a6e4 100644 (file)
@@ -234,8 +234,7 @@ namespace rfb {
       bool isChanged() {
         try {
           CharArray new_hosts(getHosts());
-          CharArray old_hosts(hosts.getData());
-          return (strcmp(new_hosts.buf, old_hosts.buf) != 0) ||
+          return (strcmp(new_hosts.buf, hosts) != 0) ||
               (localHost != isItemChecked(IDC_LOCALHOST)) ||
               (port_number != getItemInt(IDC_PORT)) ||
               (rfb::Server::idleTimeout != getItemInt(IDC_IDLE_TIMEOUT));
index 65d99946a422a5b5c635a8da2cf69f1972f5e89a..d7ed0bc8b94fa80ee9064f1641eaf97f76d76d79 100644 (file)
@@ -31,9 +31,9 @@ namespace rfb {
       DesktopPage(const RegKey& rk)
         : PropSheetPage(GetModuleHandle(0), MAKEINTRESOURCE(IDD_DESKTOP)), regKey(rk) {}
       void initDialog() {
-        CharArray action(rfb::win32::SDisplay::disconnectAction.getData());
-        bool disconnectLock = stricmp(action.buf, "Lock") == 0;
-        bool disconnectLogoff = stricmp(action.buf, "Logoff") == 0;
+        const char *action(rfb::win32::SDisplay::disconnectAction);
+        bool disconnectLock = stricmp(action, "Lock") == 0;
+        bool disconnectLogoff = stricmp(action, "Logoff") == 0;
         setItemChecked(IDC_DISCONNECT_LOGOFF, disconnectLogoff);
         setItemChecked(IDC_DISCONNECT_LOCK, disconnectLock);
         setItemChecked(IDC_DISCONNECT_NONE, !disconnectLock && !disconnectLogoff);
@@ -47,9 +47,9 @@ namespace rfb {
         case IDC_DISCONNECT_NONE:
         case IDC_REMOVE_WALLPAPER:
         case IDC_DISABLE_EFFECTS:
-          CharArray action(rfb::win32::SDisplay::disconnectAction.getData());
-          bool disconnectLock = stricmp(action.buf, "Lock") == 0;
-          bool disconnectLogoff = stricmp(action.buf, "Logoff") == 0;
+          const char *action(rfb::win32::SDisplay::disconnectAction);
+          bool disconnectLock = stricmp(action, "Lock") == 0;
+          bool disconnectLogoff = stricmp(action, "Logoff") == 0;
           setChanged((disconnectLogoff != isItemChecked(IDC_DISCONNECT_LOGOFF)) ||
                      (disconnectLock != isItemChecked(IDC_DISCONNECT_LOCK)) ||
                      (isItemChecked(IDC_REMOVE_WALLPAPER) != rfb::win32::SDisplay::removeWallpaper) ||
index 70f82ff0f4cd0a540edca6b20ea43aa2454def57..55efabe157cfce9194c76130617a7228841c9bbd 100644 (file)
@@ -151,8 +151,7 @@ void VNCServerWin32::regConfigChanged() {
   rfbSock.setPort(port_number, localHost);
 
   // -=- Update the TCP address filter for both ports, if open.
-  CharArray pattern(hosts.getData());
-  rfbSock.setFilter(pattern.buf);
+  rfbSock.setFilter(hosts);
 
   // -=- Update the tray icon tooltip text with IP addresses
   processAddressChange();