diff options
author | Pierre Ossman <ossman@cendio.se> | 2023-01-13 12:47:48 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2023-02-04 14:03:13 +0100 |
commit | b99daadb05e14e85da6c5e905057e10fc27c0fcf (patch) | |
tree | 752e6fea3900b604d44ef6a498539e9a785bf22f /win | |
parent | e6c5b29f12780303299506fe04f089bc98b80c91 (diff) | |
download | tigervnc-b99daadb05e14e85da6c5e905057e10fc27c0fcf.tar.gz tigervnc-b99daadb05e14e85da6c5e905057e10fc27c0fcf.zip |
Use std::string instead of CharArray
Let's use a more common type instead of something homegrown. Should be
more familiar to new developers.
Diffstat (limited to 'win')
-rw-r--r-- | win/rfb_win32/CurrentUser.cxx | 4 | ||||
-rw-r--r-- | win/rfb_win32/CurrentUser.h | 5 | ||||
-rw-r--r-- | win/rfb_win32/Dialog.cxx | 6 | ||||
-rw-r--r-- | win/rfb_win32/Dialog.h | 6 | ||||
-rw-r--r-- | win/rfb_win32/LaunchProcess.cxx | 28 | ||||
-rw-r--r-- | win/rfb_win32/LaunchProcess.h | 8 | ||||
-rw-r--r-- | win/rfb_win32/MsgBox.h | 13 | ||||
-rw-r--r-- | win/rfb_win32/MsgWindow.cxx | 10 | ||||
-rw-r--r-- | win/rfb_win32/MsgWindow.h | 8 | ||||
-rw-r--r-- | win/rfb_win32/Registry.cxx | 1 | ||||
-rw-r--r-- | win/rfb_win32/Service.cxx | 21 | ||||
-rw-r--r-- | win/rfb_win32/SocketManager.cxx | 1 | ||||
-rw-r--r-- | win/rfb_win32/Win32Util.cxx | 8 | ||||
-rw-r--r-- | win/vncconfig/Authentication.h | 5 | ||||
-rw-r--r-- | win/vncconfig/Connections.h | 34 | ||||
-rw-r--r-- | win/vncconfig/Legacy.cxx | 26 | ||||
-rw-r--r-- | win/vncconfig/PasswordDialog.cxx | 13 | ||||
-rw-r--r-- | win/winvnc/AddNewClientDialog.h | 10 | ||||
-rw-r--r-- | win/winvnc/QueryConnectDialog.cxx | 13 | ||||
-rw-r--r-- | win/winvnc/QueryConnectDialog.h | 5 | ||||
-rw-r--r-- | win/winvnc/STrayIcon.cxx | 13 | ||||
-rw-r--r-- | win/winvnc/STrayIcon.h | 2 | ||||
-rw-r--r-- | win/winvnc/VNCServerService.cxx | 8 | ||||
-rw-r--r-- | win/winvnc/VNCServerWin32.cxx | 9 | ||||
-rw-r--r-- | win/winvnc/winvnc.cxx | 22 |
25 files changed, 135 insertions, 144 deletions
diff --git a/win/rfb_win32/CurrentUser.cxx b/win/rfb_win32/CurrentUser.cxx index 153e415d..e4ef6ccf 100644 --- a/win/rfb_win32/CurrentUser.cxx +++ b/win/rfb_win32/CurrentUser.cxx @@ -110,10 +110,12 @@ ImpersonateCurrentUser::~ImpersonateCurrentUser() { } -UserName::UserName() : CharArray(UNLEN+1) { +UserName::UserName() { + char buf[UNLEN+1]; DWORD len = UNLEN+1; if (!GetUserName(buf, &len)) throw rdr::SystemException("GetUserName failed", GetLastError()); + assign(buf); } diff --git a/win/rfb_win32/CurrentUser.h b/win/rfb_win32/CurrentUser.h index 37fa65b2..12c4b49f 100644 --- a/win/rfb_win32/CurrentUser.h +++ b/win/rfb_win32/CurrentUser.h @@ -26,7 +26,8 @@ #ifndef __RFB_WIN32_CURRENT_USER_H__ #define __RFB_WIN32_CURRENT_USER_H__ -#include <rfb/util.h> +#include <string> + #include <rfb_win32/Handle.h> #include <rfb_win32/Security.h> @@ -67,7 +68,7 @@ namespace rfb { // Returns the name of the user the thread is currently running as. // Raises a SystemException in case of error. - struct UserName : public CharArray { + struct UserName : public std::string { UserName(); }; diff --git a/win/rfb_win32/Dialog.cxx b/win/rfb_win32/Dialog.cxx index 6fee7fd7..8e2c1ee8 100644 --- a/win/rfb_win32/Dialog.cxx +++ b/win/rfb_win32/Dialog.cxx @@ -207,7 +207,7 @@ BOOL PropSheetPage::dialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam PropSheet::PropSheet(HINSTANCE inst_, const char* title_, std::list<PropSheetPage*> pages_, HICON icon_) -: icon(icon_), pages(pages_), inst(inst_), title(strDup(title_)), handle(0), alreadyShowing(0) { +: icon(icon_), pages(pages_), inst(inst_), title(title_), handle(0), alreadyShowing(0) { } PropSheet::~PropSheet() { @@ -264,7 +264,7 @@ bool PropSheet::showPropSheet(HWND owner, bool showApply, bool showCtxtHelp, boo header.pfnCallback = removeCtxtHelp; header.hwndParent = owner; header.hInstance = inst; - header.pszCaption = title.buf; + header.pszCaption = title.c_str(); header.nPages = count; header.nStartPage = 0; header.phpage = hpages; @@ -282,7 +282,7 @@ bool PropSheet::showPropSheet(HWND owner, bool showApply, bool showCtxtHelp, boo (void)capture; #ifdef _DIALOG_CAPTURE if (capture) { - plog.info("capturing \"%s\"", title.buf); + plog.info("capturing \"%s\"", title.c_str()); char* tmpdir = getenv("TEMP"); HDC dc = GetWindowDC(handle); DeviceFrameBuffer fb(dc); diff --git a/win/rfb_win32/Dialog.h b/win/rfb_win32/Dialog.h index f2d718ce..d1a8e831 100644 --- a/win/rfb_win32/Dialog.h +++ b/win/rfb_win32/Dialog.h @@ -25,12 +25,12 @@ #ifndef __RFB_WIN32_DIALOG_H__ #define __RFB_WIN32_DIALOG_H__ +#include <string> + #include <windows.h> #include <prsht.h> #include <list> -#include <rfb/util.h> - namespace rfb { namespace win32 { @@ -131,7 +131,7 @@ namespace rfb { HICON icon; std::list<PropSheetPage*> pages; HINSTANCE inst; - CharArray title; + std::string title; HWND handle; bool alreadyShowing; }; diff --git a/win/rfb_win32/LaunchProcess.cxx b/win/rfb_win32/LaunchProcess.cxx index 7d17caf7..5e702a00 100644 --- a/win/rfb_win32/LaunchProcess.cxx +++ b/win/rfb_win32/LaunchProcess.cxx @@ -33,7 +33,7 @@ using namespace win32; LaunchProcess::LaunchProcess(const char* exeName_, const char* params_) -: exeName(strDup(exeName_)), params(strDup(params_)) { +: exeName(exeName_), params(params_) { memset(&procInfo, 0, sizeof(procInfo)); } @@ -64,30 +64,32 @@ void LaunchProcess::start(HANDLE userToken, bool createConsole) { sinfo.lpDesktop = desktopName; // - Concoct a suitable command-line - CharArray exePath; - if (!strContains(exeName.buf, '\\')) { + std::string exePath; + if (exeName.find('\\') == std::string::npos) { ModuleFileName filename; - CharArray path(strDup(filename.buf)); - if (strContains(path.buf, '\\')) - *strrchr(path.buf, '\\') = '\0'; - exePath.buf = new char[strlen(path.buf) + strlen(exeName.buf) + 2]; - sprintf(exePath.buf, "%s\\%s", path.buf, exeName.buf); + std::string path(filename.buf); + if (path.rfind('\\') != std::string::npos) + path.resize(path.rfind('\\')); + exePath = path + '\\' + exeName; } else { - exePath.buf = strDup(exeName.buf); + exePath = exeName; } // - Start the process // Note: We specify the exe's precise path in the ApplicationName parameter, // AND include the name as the first part of the CommandLine parameter, // because CreateProcess doesn't make ApplicationName argv[0] in C programs. - CharArray cmdLine(strlen(exeName.buf) + 3 + strlen(params.buf) + 1); - sprintf(cmdLine.buf, "\"%s\" %s", exeName.buf, params.buf); + std::string cmdLine; + cmdLine = (std::string)"\"" + exeName + "\" " + params; DWORD flags = createConsole ? CREATE_NEW_CONSOLE : CREATE_NO_WINDOW; BOOL success; if (userToken != INVALID_HANDLE_VALUE) - success = CreateProcessAsUser(userToken, exePath.buf, cmdLine.buf, 0, 0, FALSE, flags, 0, 0, &sinfo, &procInfo); + success = CreateProcessAsUser(userToken, exePath.c_str(), + (char*)cmdLine.c_str(), 0, 0, FALSE, + flags, 0, 0, &sinfo, &procInfo); else - success = CreateProcess(exePath.buf, cmdLine.buf, 0, 0, FALSE, flags, 0, 0, &sinfo, &procInfo); + success = CreateProcess(exePath.c_str(), (char*)cmdLine.c_str(), 0, + 0, FALSE, flags, 0, 0, &sinfo, &procInfo); if (!success) throw rdr::SystemException("unable to launch process", GetLastError()); diff --git a/win/rfb_win32/LaunchProcess.h b/win/rfb_win32/LaunchProcess.h index dc74682a..4cc8a92c 100644 --- a/win/rfb_win32/LaunchProcess.h +++ b/win/rfb_win32/LaunchProcess.h @@ -24,9 +24,9 @@ #ifndef __RFB_WIN32_LAUNCHPROCESS_H__ #define __RFB_WIN32_LAUNCHPROCESS_H__ -#include <windows.h> +#include <string> -#include <rfb/util.h> +#include <windows.h> namespace rfb { @@ -60,8 +60,8 @@ namespace rfb { PROCESS_INFORMATION procInfo; DWORD returnCode; protected: - CharArray exeName; - CharArray params; + std::string exeName; + std::string params; }; diff --git a/win/rfb_win32/MsgBox.h b/win/rfb_win32/MsgBox.h index 30492974..25d36383 100644 --- a/win/rfb_win32/MsgBox.h +++ b/win/rfb_win32/MsgBox.h @@ -19,9 +19,9 @@ #ifndef __RFB_WIN32_MSGBOX_H__ #define __RFB_WIN32_MSGBOX_H__ -#include <windows.h> +#include <string> -#include <rfb/util.h> +#include <windows.h> namespace rfb { namespace win32 { @@ -49,13 +49,12 @@ namespace rfb { flags |= MB_TOPMOST | MB_SETFOREGROUND; int len = strlen(AppName) + 1; if (msgType) len += strlen(msgType) + 3; - CharArray title(new char[len]); - strcpy(title.buf, AppName); + std::string title = AppName; if (msgType) { - strcat(title.buf, " : "); - strcat(title.buf, msgType); + title += " : "; + title += msgType; } - return MessageBox(parent, msg, title.buf, flags); + return MessageBox(parent, msg, title.c_str(), flags); } }; diff --git a/win/rfb_win32/MsgWindow.cxx b/win/rfb_win32/MsgWindow.cxx index 1a987475..251b2762 100644 --- a/win/rfb_win32/MsgWindow.cxx +++ b/win/rfb_win32/MsgWindow.cxx @@ -98,21 +98,21 @@ static MsgWindowClass baseClass; // -=- MsgWindow // -MsgWindow::MsgWindow(const char* name_) : name(strDup(name_)), handle(0) { - vlog.debug("creating window \"%s\"", name.buf); +MsgWindow::MsgWindow(const char* name_) : name(name_), handle(0) { + vlog.debug("creating window \"%s\"", name.c_str()); handle = CreateWindow((const char*)(intptr_t)baseClass.classAtom, - name.buf, WS_OVERLAPPED, 0, 0, 10, 10, 0, 0, + name.c_str(), WS_OVERLAPPED, 0, 0, 10, 10, 0, 0, baseClass.instance, this); if (!handle) { throw rdr::SystemException("unable to create WMNotifier window instance", GetLastError()); } - vlog.debug("created window \"%s\" (%p)", name.buf, handle); + vlog.debug("created window \"%s\" (%p)", name.c_str(), handle); } MsgWindow::~MsgWindow() { if (handle) DestroyWindow(handle); - vlog.debug("destroyed window \"%s\" (%p)", name.buf, handle); + vlog.debug("destroyed window \"%s\" (%p)", name.c_str(), handle); } LRESULT diff --git a/win/rfb_win32/MsgWindow.h b/win/rfb_win32/MsgWindow.h index 22ff1b85..5ede8280 100644 --- a/win/rfb_win32/MsgWindow.h +++ b/win/rfb_win32/MsgWindow.h @@ -24,9 +24,9 @@ #ifndef __RFB_WIN32_MSG_WINDOW_H__ #define __RFB_WIN32_MSG_WINDOW_H__ -#include <windows.h> +#include <string> -#include <rfb/util.h> +#include <windows.h> namespace rfb { @@ -37,13 +37,13 @@ namespace rfb { MsgWindow(const char* _name); virtual ~MsgWindow(); - const char* getName() {return name.buf;} + const char* getName() {return name.c_str();} HWND getHandle() const {return handle;} virtual LRESULT processMessage(UINT msg, WPARAM wParam, LPARAM lParam); protected: - CharArray name; + std::string name; HWND handle; }; diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx index b1e8b07d..d0db60e2 100644 --- a/win/rfb_win32/Registry.cxx +++ b/win/rfb_win32/Registry.cxx @@ -29,6 +29,7 @@ #include <rdr/HexInStream.h> #include <stdlib.h> #include <rfb/LogWriter.h> +#include <rfb/util.h> // These flags are required to control access control inheritance, // but are not defined by VC6's headers. These definitions comes diff --git a/win/rfb_win32/Service.cxx b/win/rfb_win32/Service.cxx index fe85e6c6..259eb762 100644 --- a/win/rfb_win32/Service.cxx +++ b/win/rfb_win32/Service.cxx @@ -30,6 +30,7 @@ #include <logmessages/messages.h> #include <rdr/Exception.h> #include <rfb/LogWriter.h> +#include <rfb/util.h> using namespace rdr; @@ -321,12 +322,12 @@ bool rfb::win32::registerService(const char* name, } // - Add the supplied extra parameters to the command line - CharArray cmdline(cmdline_len+strlen(defaultcmdline)); - sprintf(cmdline.buf, "\"%s\" %s", buffer.buf, defaultcmdline); + std::string cmdline; + cmdline = strFormat("\"%s\" %s", buffer.buf, defaultcmdline); for (i=0; i<argc; i++) { - strcat(cmdline.buf, " \""); - strcat(cmdline.buf, argv[i]); - strcat(cmdline.buf, "\""); + cmdline += " \""; + cmdline += argv[i]; + cmdline += "\""; } // - Register the service @@ -341,7 +342,7 @@ bool rfb::win32::registerService(const char* name, name, display, SC_MANAGER_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_IGNORE, - cmdline.buf, NULL, NULL, NULL, NULL, NULL); + cmdline.c_str(), NULL, NULL, NULL, NULL, NULL); if (!service) throw rdr::SystemException("unable to create service", GetLastError()); @@ -363,11 +364,11 @@ bool rfb::win32::registerService(const char* name, } const char* dllFilename = "logmessages.dll"; - CharArray dllPath(strlen(buffer.buf) + strlen(dllFilename) + 1); - strcpy(dllPath.buf, buffer.buf); - strcat(dllPath.buf, dllFilename); + std::string dllPath; + dllPath = buffer.buf; + dllPath += dllFilename; - hk.setExpandString("EventMessageFile", dllPath.buf); + hk.setExpandString("EventMessageFile", dllPath.c_str()); hk.setInt("TypesSupported", EVENTLOG_ERROR_TYPE | EVENTLOG_INFORMATION_TYPE); Sleep(500); diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 5463b24f..b7cc1cce 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -26,6 +26,7 @@ #include <list> #include <rfb/LogWriter.h> #include <rfb/Timer.h> +#include <rfb/util.h> #include <rfb_win32/SocketManager.h> using namespace rfb; diff --git a/win/rfb_win32/Win32Util.cxx b/win/rfb_win32/Win32Util.cxx index e806b1db..002bf2bd 100644 --- a/win/rfb_win32/Win32Util.cxx +++ b/win/rfb_win32/Win32Util.cxx @@ -73,14 +73,14 @@ const char* FileVersionInfo::getVerString(const char* name, DWORD langId) { } std::string langIdStr(binToHex(langIdBuf, sizeof(langId))); - CharArray infoName(strlen("StringFileInfo") + 4 + strlen(name) + strlen(langIdStr.c_str())); - sprintf(infoName.buf, "\\StringFileInfo\\%s\\%s", langIdStr.c_str(), name); + std::string infoName; + infoName = strFormat("\\StringFileInfo\\%s\\%s", langIdStr.c_str(), name); // Locate the required version string within the version info char* buffer = 0; UINT length = 0; - if (!VerQueryValue(buf, infoName.buf, (void**)&buffer, &length)) { - printf("unable to find %s version string", infoName.buf); + if (!VerQueryValue(buf, infoName.c_str(), (void**)&buffer, &length)) { + printf("unable to find %s version string", infoName.c_str()); throw rdr::Exception("VerQueryValue failed"); } return buffer; diff --git a/win/vncconfig/Authentication.h b/win/vncconfig/Authentication.h index cc162077..a69f7592 100644 --- a/win/vncconfig/Authentication.h +++ b/win/vncconfig/Authentication.h @@ -32,7 +32,6 @@ #ifdef HAVE_GNUTLS #include <rfb/SSecurityTLS.h> #endif -#include <rfb/Password.h> static rfb::BoolParameter queryOnlyIfLoggedOn("QueryOnlyIfLoggedOn", "Only prompt for a local user to accept incoming connections if there is a user logged on", false); @@ -113,9 +112,9 @@ namespace rfb { static bool haveVncPassword() { - PlainPasswd password, passwordReadOnly; + std::string password, passwordReadOnly; SSecurityVncAuth::vncAuthPasswd.getVncAuthPasswd(&password, &passwordReadOnly); - return password.buf && strlen(password.buf) != 0; + return !password.empty(); } static void verifyVncPassword(const RegKey& regKey) { diff --git a/win/vncconfig/Connections.h b/win/vncconfig/Connections.h index 1f974454..1cf01777 100644 --- a/win/vncconfig/Connections.h +++ b/win/vncconfig/Connections.h @@ -42,47 +42,45 @@ namespace rfb { public: ConnHostDialog() : Dialog(GetModuleHandle(0)) {} bool showDialog(const char* pat) { - pattern.replaceBuf(strDup(pat)); + pattern = pat; return Dialog::showDialog(MAKEINTRESOURCE(IDD_CONN_HOST)); } void initDialog() { - if (strlen(pattern.buf) == 0) - pattern.replaceBuf(strDup("+")); + if (pattern.empty()) + pattern = "+"; - if (pattern.buf[0] == '+') + if (pattern[0] == '+') setItemChecked(IDC_ALLOW, true); - else if (pattern.buf[0] == '?') + else if (pattern[0] == '?') setItemChecked(IDC_QUERY, true); else setItemChecked(IDC_DENY, true); - setItemString(IDC_HOST_PATTERN, &pattern.buf[1]); - pattern.replaceBuf(0); + setItemString(IDC_HOST_PATTERN, &pattern.c_str()[1]); + pattern.clear(); } bool onOk() { - CharArray host(strDup(getItemString(IDC_HOST_PATTERN))); - CharArray newPat(strlen(host.buf)+2); + std::string newPat; if (isItemChecked(IDC_ALLOW)) - newPat.buf[0] = '+'; + newPat = '+'; else if (isItemChecked(IDC_QUERY)) - newPat.buf[0] = '?'; + newPat = '?'; else - newPat.buf[0] = '-'; - newPat.buf[1] = 0; - strcat(newPat.buf, host.buf); + newPat = '-'; + newPat += getItemString(IDC_HOST_PATTERN); try { - network::TcpFilter::Pattern pat(network::TcpFilter::parsePattern(newPat.buf)); - pattern.replaceBuf(strDup(network::TcpFilter::patternToStr(pat).c_str())); + network::TcpFilter::Pattern pat(network::TcpFilter::parsePattern(newPat.c_str())); + pattern = network::TcpFilter::patternToStr(pat); } catch(rdr::Exception& e) { MsgBox(NULL, e.str(), MB_ICONEXCLAMATION | MB_OK); return false; } return true; } - const char* getPattern() {return pattern.buf;} + const char* getPattern() {return pattern.c_str();} protected: - CharArray pattern; + std::string pattern; }; class ConnectionsPage : public PropSheetPage { diff --git a/win/vncconfig/Legacy.cxx b/win/vncconfig/Legacy.cxx index bbd796d0..b21bccd7 100644 --- a/win/vncconfig/Legacy.cxx +++ b/win/vncconfig/Legacy.cxx @@ -38,10 +38,9 @@ void LegacyPage::LoadPrefs() // settings from HKCU/Software/ORL/WinVNC3. // Get the name of the current user - CharArray username; + std::string username; try { - UserName name; - username.buf = name.takeBuf(); + username = UserName(); } catch (rdr::SystemException& e) { if (e.err != ERROR_NOT_LOGGED_ON) throw; @@ -64,8 +63,7 @@ void LegacyPage::LoadPrefs() std::string authHosts = winvnc3.getString("AuthHosts", ""); if (!authHosts.empty()) { - CharArray newHosts; - newHosts.buf = strDup(""); + std::string newHosts; // Reformat AuthHosts to Hosts. Wish I'd left the format the same. :( :( :( try { @@ -107,20 +105,14 @@ void LegacyPage::LoadPrefs() strcat(pattern, buf); // Append this pattern to the Hosts value - int length = strlen(newHosts.buf) + strlen(pattern) + 2; - CharArray tmpHosts(length); - strcpy(tmpHosts.buf, pattern); - if (strlen(newHosts.buf)) { - strcat(tmpHosts.buf, ","); - strcat(tmpHosts.buf, newHosts.buf); - } - delete [] newHosts.buf; - newHosts.buf = tmpHosts.takeBuf(); + if (!newHosts.empty()) + newHosts += ","; + newHosts += pattern; } } // Finally, save the Hosts value - regKey.setString("Hosts", newHosts.buf); + regKey.setString("Hosts", newHosts.c_str()); } catch (rdr::Exception&) { MsgBox(0, "Unable to convert AuthHosts setting to Hosts format.", MB_ICONWARNING | MB_OK); @@ -157,10 +149,10 @@ void LegacyPage::LoadPrefs() } // Open the local, user-specific settings - if (userSettings && username.buf) { + if (userSettings && !username.empty()) { try { RegKey userKey; - userKey.openKey(winvnc3, username.buf); + userKey.openKey(winvnc3, username.c_str()); vlog.info("loading local User prefs"); LoadUserPrefs(userKey); } catch(rdr::Exception& e) { diff --git a/win/vncconfig/PasswordDialog.cxx b/win/vncconfig/PasswordDialog.cxx index 0df97001..f35aeb54 100644 --- a/win/vncconfig/PasswordDialog.cxx +++ b/win/vncconfig/PasswordDialog.cxx @@ -19,7 +19,7 @@ #include <vncconfig/resource.h> #include <vncconfig/PasswordDialog.h> #include <rfb_win32/MsgBox.h> -#include <rfb/Password.h> +#include <rfb/obfuscate.h> using namespace rfb; using namespace win32; @@ -33,9 +33,9 @@ bool PasswordDialog::showDialog(HWND owner) { } bool PasswordDialog::onOk() { - PlainPasswd password1(strDup(getItemString(IDC_PASSWORD1))); - PlainPasswd password2(strDup(getItemString(IDC_PASSWORD2))); - if (strcmp(password1.buf, password2.buf) != 0) { + std::string password1(getItemString(IDC_PASSWORD1)); + std::string password2(getItemString(IDC_PASSWORD2)); + if (password1 != password2) { MsgBox(0, "The supplied passwords do not match", MB_ICONEXCLAMATION | MB_OK); return false; @@ -45,8 +45,7 @@ bool PasswordDialog::onOk() { "Are you sure you wish to continue?", MB_YESNO | MB_ICONWARNING) == IDNO)) return false; - PlainPasswd password(strDup(password1.buf)); - ObfuscatedPasswd obfPwd(password); - regKey.setBinary("Password", obfPwd.buf, obfPwd.length); + std::vector<uint8_t> obfPwd = obfuscate(password1.c_str()); + regKey.setBinary("Password", obfPwd.data(), obfPwd.size()); return true; } diff --git a/win/winvnc/AddNewClientDialog.h b/win/winvnc/AddNewClientDialog.h index 4bc489d8..44e15e70 100644 --- a/win/winvnc/AddNewClientDialog.h +++ b/win/winvnc/AddNewClientDialog.h @@ -34,20 +34,20 @@ namespace winvnc { virtual bool showDialog() { return Dialog::showDialog(MAKEINTRESOURCE(IDD_ADD_NEW_CLIENT)); } - const char* getHostName() const {return hostName.buf;} + const char* getHostName() const {return hostName.c_str();} protected: // Dialog methods (protected) virtual void initDialog() { - if (hostName.buf) - setItemString(IDC_HOST, hostName.buf); + if (!hostName.empty()) + setItemString(IDC_HOST, hostName.c_str()); } virtual bool onOk() { - hostName.replaceBuf(rfb::strDup(getItemString(IDC_HOST))); + hostName = getItemString(IDC_HOST); return true; } - rfb::CharArray hostName; + std::string hostName; }; }; diff --git a/win/winvnc/QueryConnectDialog.cxx b/win/winvnc/QueryConnectDialog.cxx index 76568c87..26bd9331 100644 --- a/win/winvnc/QueryConnectDialog.cxx +++ b/win/winvnc/QueryConnectDialog.cxx @@ -45,9 +45,8 @@ QueryConnectDialog::QueryConnectDialog(network::Socket* sock_, const char* userName_, VNCServerWin32* s) : Dialog(GetModuleHandle(0)), - sock(sock_), approve(false), server(s) { - peerIp.buf = strDup(sock->getPeerAddress()); - userName.buf = strDup(userName_); + sock(sock_), peerIp(sock->getPeerAddress()), userName(userName_), + approve(false), server(s) { } void QueryConnectDialog::startDialog() { @@ -76,10 +75,10 @@ void QueryConnectDialog::worker() { void QueryConnectDialog::initDialog() { if (!SetTimer(handle, 1, 1000, 0)) throw rdr::SystemException("SetTimer", GetLastError()); - setItemString(IDC_QUERY_HOST, peerIp.buf); - if (!userName.buf) - userName.buf = strDup("(anonymous)"); - setItemString(IDC_QUERY_USER, userName.buf); + setItemString(IDC_QUERY_HOST, peerIp.c_str()); + if (userName.empty()) + userName = "(anonymous)"; + setItemString(IDC_QUERY_USER, userName.c_str()); setCountdownLabel(); } diff --git a/win/winvnc/QueryConnectDialog.h b/win/winvnc/QueryConnectDialog.h index de5e31ee..36e885f9 100644 --- a/win/winvnc/QueryConnectDialog.h +++ b/win/winvnc/QueryConnectDialog.h @@ -22,7 +22,6 @@ #define __WINVNC_QUERY_CONNECT_DIALOG_H__ #include <rfb_win32/Dialog.h> -#include <rfb/util.h> namespace os { class Thread; } @@ -51,8 +50,8 @@ namespace winvnc { int countdown; network::Socket* sock; - rfb::CharArray peerIp; - rfb::CharArray userName; + std::string peerIp; + std::string userName; bool approve; VNCServerWin32* server; }; diff --git a/win/winvnc/STrayIcon.cxx b/win/winvnc/STrayIcon.cxx index 4ba147c2..e7032998 100644 --- a/win/winvnc/STrayIcon.cxx +++ b/win/winvnc/STrayIcon.cxx @@ -180,10 +180,8 @@ public: switch (command->dwData) { case 1: { - CharArray viewer(command->cbData + 1); - memcpy(viewer.buf, command->lpData, command->cbData); - viewer.buf[command->cbData] = 0; - return thread.server.addNewClient(viewer.buf) ? 1 : 0; + std::string viewer((char*)command->lpData, command->cbData); + return thread.server.addNewClient(viewer.c_str()) ? 1 : 0; } case 2: return thread.server.disconnectClients("IPC disconnect") ? 1 : 0; @@ -220,8 +218,8 @@ public: case WM_SET_TOOLTIP: { os::AutoMutex a(thread.lock); - if (thread.toolTip.buf) - setToolTip(thread.toolTip.buf); + if (!thread.toolTip.empty()) + setToolTip(thread.toolTip.c_str()); } return 0; @@ -280,8 +278,7 @@ void STrayIconThread::worker() { void STrayIconThread::setToolTip(const char* text) { if (!windowHandle) return; os::AutoMutex a(lock); - delete [] toolTip.buf; - toolTip.buf = strDup(text); + toolTip = text; PostMessage(windowHandle, WM_SET_TOOLTIP, 0, 0); } diff --git a/win/winvnc/STrayIcon.h b/win/winvnc/STrayIcon.h index c0385852..511c3ae2 100644 --- a/win/winvnc/STrayIcon.h +++ b/win/winvnc/STrayIcon.h @@ -47,7 +47,7 @@ namespace winvnc { os::Mutex* lock; DWORD thread_id; HWND windowHandle; - rfb::CharArray toolTip; + std::string toolTip; VNCServerWin32& server; UINT inactiveIcon; UINT activeIcon; diff --git a/win/winvnc/VNCServerService.cxx b/win/winvnc/VNCServerService.cxx index 0a0ed520..d2a994aa 100644 --- a/win/winvnc/VNCServerService.cxx +++ b/win/winvnc/VNCServerService.cxx @@ -108,14 +108,16 @@ HANDLE LaunchProcessWin(DWORD /*dwSessionId*/) if (GetSessionUserTokenWin(&hToken)) { ModuleFileName filename; - CharArray cmdLine; - cmdLine.format("\"%s\" -noconsole -service_run", filename.buf); + std::string cmdLine; + cmdLine = strFormat("\"%s\" -noconsole -service_run", filename.buf); STARTUPINFO si; ZeroMemory(&si, sizeof si); si.cb = sizeof si; si.dwFlags = STARTF_USESHOWWINDOW; PROCESS_INFORMATION pi; - if (CreateProcessAsUser(hToken, NULL, cmdLine.buf, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi)) + if (CreateProcessAsUser(hToken, NULL, (char*)cmdLine.c_str(), + NULL, NULL, FALSE, DETACHED_PROCESS, + NULL, NULL, &si, &pi)) { CloseHandle(pi.hThread); hProcess = pi.hProcess; diff --git a/win/winvnc/VNCServerWin32.cxx b/win/winvnc/VNCServerWin32.cxx index 87258986..a243d95e 100644 --- a/win/winvnc/VNCServerWin32.cxx +++ b/win/winvnc/VNCServerWin32.cxx @@ -130,18 +130,17 @@ void VNCServerWin32::processAddressChange() { length += i->size() + 1; // Build the new tip - CharArray toolTip(length); - strcpy(toolTip.buf, prefix); + std::string toolTip(prefix); for (i=addrs.begin(); i!= addrs.end(); i=next_i) { next_i = i; next_i ++; - strcat(toolTip.buf, i->c_str()); + toolTip += *i; if (next_i != addrs.end()) - strcat(toolTip.buf, ","); + toolTip += ","; } // Pass the new tip to the tray icon vlog.info("Refreshing tray icon"); - trayIcon->setToolTip(toolTip.buf); + trayIcon->setToolTip(toolTip.c_str()); } void VNCServerWin32::regConfigChanged() { diff --git a/win/winvnc/winvnc.cxx b/win/winvnc/winvnc.cxx index ee4d94a5..2e705bf0 100644 --- a/win/winvnc/winvnc.cxx +++ b/win/winvnc/winvnc.cxx @@ -106,23 +106,23 @@ static void processParams(int argc, char** argv) { if (strcasecmp(argv[i], "-connect") == 0) { runServer = false; - CharArray host; + const char *host = NULL; if (i+1 < argc) { - host.buf = strDup(argv[i+1]); + host = argv[i+1]; i++; } else { AddNewClientDialog ancd; if (ancd.showDialog()) - host.buf = strDup(ancd.getHostName()); + host = ancd.getHostName(); } - if (host.buf) { + if (host != NULL) { HWND hwnd = FindWindow(0, "winvnc::IPC_Interface"); if (!hwnd) throw rdr::Exception("Unable to locate existing VNC Server."); COPYDATASTRUCT copyData; copyData.dwData = 1; // *** AddNewClient - copyData.cbData = strlen(host.buf); - copyData.lpData = (void*)host.buf; + copyData.cbData = strlen(host); + copyData.lpData = (void*)host; printf("Sending connect request to VNC Server...\n"); if (!SendMessage(hwnd, WM_COPYDATA, 0, (LPARAM)©Data)) MsgBoxOrLog("Connection failed.", true); @@ -152,12 +152,12 @@ static void processParams(int argc, char** argv) { } else if (strcasecmp(argv[i], "-status") == 0) { printf("Querying service status...\n"); runServer = false; - CharArray result; + std::string result; DWORD state = rfb::win32::getServiceState(VNCServerService::Name); - result.format("The %s Service is in the %s state.", - VNCServerService::Name, - rfb::win32::serviceStateName(state)); - MsgBoxOrLog(result.buf); + result = strFormat("The %s Service is in the %s state.", + VNCServerService::Name, + rfb::win32::serviceStateName(state)); + MsgBoxOrLog(result.c_str()); } else if (strcasecmp(argv[i], "-service") == 0) { printf("Run in service mode\n"); runServer = false; |