diff options
Diffstat (limited to 'vncviewer')
-rw-r--r-- | vncviewer/CConn.cxx | 26 | ||||
-rw-r--r-- | vncviewer/EmulateMB.cxx | 6 | ||||
-rw-r--r-- | vncviewer/PlatformPixelBuffer.cxx | 7 | ||||
-rw-r--r-- | vncviewer/ServerDialog.cxx | 53 | ||||
-rw-r--r-- | vncviewer/Surface_OSX.cxx | 12 | ||||
-rw-r--r-- | vncviewer/Surface_Win32.cxx | 22 | ||||
-rw-r--r-- | vncviewer/Surface_X11.cxx | 10 | ||||
-rw-r--r-- | vncviewer/UserDialog.cxx | 6 | ||||
-rw-r--r-- | vncviewer/Viewport.cxx | 33 | ||||
-rw-r--r-- | vncviewer/Win32TouchHandler.cxx | 5 | ||||
-rw-r--r-- | vncviewer/parameters.cxx | 135 | ||||
-rw-r--r-- | vncviewer/touch.cxx | 7 | ||||
-rw-r--r-- | vncviewer/vncviewer.cxx | 31 | ||||
-rw-r--r-- | vncviewer/vncviewer.h | 6 |
14 files changed, 186 insertions, 173 deletions
diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 81bea534..31f5321d 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -27,6 +27,8 @@ #include <unistd.h> #endif +#include <rdr/Exception.h> + #include <rfb/CMsgWriter.h> #include <rfb/CSecurity.h> #include <rfb/Exception.h> @@ -107,10 +109,10 @@ CConn::CConn(const char* vncServerName, network::Socket* socket=nullptr) vlog.info(_("Connected to host %s port %d"), serverHost.c_str(), serverPort); } - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection(_("Failed to connect to \"%s\":\n\n%s"), - vncServerName, e.str()); + vncServerName, e.what()); return; } } @@ -261,8 +263,8 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) } cc->getOutStream()->cork(false); - } catch (rdr::EndOfStream& e) { - vlog.info("%s", e.str()); + } catch (rdr::end_of_stream& e) { + vlog.info("%s", e.what()); if (!cc->desktop) { vlog.error(_("The connection was dropped by the server before " "the session could be established.")); @@ -271,16 +273,16 @@ void CConn::socketEvent(FL_SOCKET fd, void *data) } else { disconnect(); } - } catch (rfb::AuthCancelledException& e) { - vlog.info("%s", e.str()); + } catch (rfb::auth_cancelled& e) { + vlog.info("%s", e.what()); disconnect(); - } catch (rfb::AuthFailureException& e) { + } catch (rfb::auth_error& e) { cc->resetPassword(); - vlog.error(_("Authentication failed: %s"), e.str()); + vlog.error(_("Authentication failed: %s"), e.what()); abort_connection(_("Failed to authenticate with the server. Reason " - "given by the server:\n\n%s"), e.str()); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + "given by the server:\n\n%s"), e.what()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } diff --git a/vncviewer/EmulateMB.cxx b/vncviewer/EmulateMB.cxx index fef8b3d9..8eeed568 100644 --- a/vncviewer/EmulateMB.cxx +++ b/vncviewer/EmulateMB.cxx @@ -54,7 +54,7 @@ #include <assert.h> -#include <rfb/Exception.h> +#include <stdexcept> #include "parameters.h" #include "i18n.h" @@ -223,7 +223,7 @@ void EmulateMB::filterPointerEvent(const rfb::Point& pos, uint8_t buttonMask) btstate |= 0x2; if ((state > 10) || (state < 0)) - throw rfb::Exception(_("Invalid state for 3 button emulation")); + throw std::runtime_error(_("Invalid state for 3 button emulation")); action1 = stateTab[state][btstate][0]; @@ -286,7 +286,7 @@ void EmulateMB::handleTimeout(rfb::Timer *t) return; if ((state > 10) || (state < 0)) - throw rfb::Exception(_("Invalid state for 3 button emulation")); + throw std::runtime_error(_("Invalid state for 3 button emulation")); // Timeout shouldn't trigger when there's no timeout action assert(stateTab[state][4][2] >= 0); diff --git a/vncviewer/PlatformPixelBuffer.cxx b/vncviewer/PlatformPixelBuffer.cxx index bcb4cb23..0f152e11 100644 --- a/vncviewer/PlatformPixelBuffer.cxx +++ b/vncviewer/PlatformPixelBuffer.cxx @@ -28,11 +28,12 @@ #include <sys/shm.h> #endif +#include <stdexcept> + #include <FL/Fl.H> #include <FL/x.H> #include <rfb/LogWriter.h> -#include <rdr/Exception.h> #include "PlatformPixelBuffer.h" @@ -52,11 +53,11 @@ PlatformPixelBuffer::PlatformPixelBuffer(int width, int height) : xim = XCreateImage(fl_display, (Visual*)CopyFromParent, 32, ZPixmap, 0, nullptr, width, height, 32, 0); if (!xim) - throw rdr::Exception("XCreateImage"); + throw std::runtime_error("XCreateImage"); xim->data = (char*)malloc(xim->bytes_per_line * xim->height); if (!xim->data) - throw rdr::Exception("malloc"); + throw std::bad_alloc(); vlog.debug("Using standard XImage"); } diff --git a/vncviewer/ServerDialog.cxx b/vncviewer/ServerDialog.cxx index 8622fff1..e24438d6 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -36,7 +36,9 @@ #include <FL/Fl_File_Chooser.H> #include <os/os.h> -#include <rfb/Exception.h> + +#include <rdr/Exception.h> + #include <rfb/Hostname.h> #include <rfb/LogWriter.h> #include <rfb/util.h> @@ -140,10 +142,10 @@ void ServerDialog::run(const char* servername, char *newservername) for (const string& entry : dialog.serverHistory) fltk_menu_add(dialog.serverName->menubutton(), entry.c_str(), 0, nullptr); - } catch (Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); fl_alert(_("Unable to load the server history:\n\n%s"), - e.str()); + e.what()); } while (dialog.shown()) Fl::wait(); @@ -192,10 +194,10 @@ void ServerDialog::handleLoad(Fl_Widget* /*widget*/, void* data) try { dialog->serverName->value(loadViewerParameters(filename)); - } catch (Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); fl_alert(_("Unable to load the specified configuration file:\n\n%s"), - e.str()); + e.what()); } delete(file_chooser); @@ -253,10 +255,10 @@ void ServerDialog::handleSaveAs(Fl_Widget* /*widget*/, void* data) try { saveViewerParameters(filename, servername); - } catch (Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); fl_alert(_("Unable to save the specified configuration " - "file:\n\n%s"), e.str()); + "file:\n\n%s"), e.what()); } delete(file_chooser); @@ -287,10 +289,10 @@ void ServerDialog::handleConnect(Fl_Widget* /*widget*/, void *data) try { saveViewerParameters(nullptr, servername); - } catch (Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); fl_alert(_("Unable to save the default configuration:\n\n%s"), - e.str()); + e.what()); } // avoid duplicates in the history @@ -299,10 +301,10 @@ void ServerDialog::handleConnect(Fl_Widget* /*widget*/, void *data) try { dialog->saveServerHistory(); - } catch (Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); fl_alert(_("Unable to save the server history:\n\n%s"), - e.str()); + e.what()); } } @@ -320,7 +322,7 @@ static bool same_server(const string& a, const string& b) try { getHostAndPort(a.c_str(), &hostA, &portA); getHostAndPort(b.c_str(), &hostB, &portB); - } catch (Exception& e) { + } catch (std::exception& e) { return false; } @@ -346,7 +348,7 @@ void ServerDialog::loadServerHistory() const char* stateDir = os::getvncstatedir(); if (stateDir == nullptr) - throw Exception(_("Could not determine VNC state directory path")); + throw std::runtime_error(_("Could not determine VNC state directory path")); char filepath[PATH_MAX]; snprintf(filepath, sizeof(filepath), "%s/%s", stateDir, SERVER_HISTORY); @@ -359,7 +361,7 @@ void ServerDialog::loadServerHistory() return; } std::string msg = format(_("Could not open \"%s\""), filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } int lineNr = 0; @@ -375,15 +377,18 @@ void ServerDialog::loadServerHistory() fclose(f); std::string msg = format(_("Failed to read line %d in " "file \"%s\""), lineNr, filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } int len = strlen(line); if (len == (sizeof(line) - 1)) { fclose(f); - throw Exception(_("Failed to read line %d in file %s: %s"), - lineNr, filepath, _("Line too long")); + throw std::runtime_error(format("%s: %s", + format(_("Failed to read line %d " + "in file %s"), + lineNr, filepath).c_str(), + _("Line too long"))); } if ((len > 0) && (line[len-1] == '\n')) { @@ -422,7 +427,7 @@ void ServerDialog::saveServerHistory() const char* stateDir = os::getvncstatedir(); if (stateDir == nullptr) - throw Exception(_("Could not determine VNC state directory path")); + throw std::runtime_error(_("Could not determine VNC state directory path")); char filepath[PATH_MAX]; snprintf(filepath, sizeof(filepath), "%s/%s", stateDir, SERVER_HISTORY); @@ -431,7 +436,7 @@ void ServerDialog::saveServerHistory() FILE* f = fopen(filepath, "w+"); if (!f) { std::string msg = format(_("Could not open \"%s\""), filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } // Save the last X elements to the config file. diff --git a/vncviewer/Surface_OSX.cxx b/vncviewer/Surface_OSX.cxx index 673f37e9..dcc3d857 100644 --- a/vncviewer/Surface_OSX.cxx +++ b/vncviewer/Surface_OSX.cxx @@ -22,14 +22,14 @@ #include <assert.h> +#include <stdexcept> + #include <ApplicationServices/ApplicationServices.h> #include <FL/Fl_RGB_Image.H> #include <FL/Fl_Window.H> #include <FL/x.H> -#include <rdr/Exception.h> - #include "cocoa.h" #include "Surface.h" @@ -47,7 +47,7 @@ static CGImageRef create_image(CGColorSpaceRef lut, provider = CGDataProviderCreateWithData(nullptr, data, w * h * 4, nullptr); if (!provider) - throw rdr::Exception("CGDataProviderCreateWithData"); + throw std::runtime_error("CGDataProviderCreateWithData"); // FIXME: This causes a performance hit, but is necessary to avoid // artifacts in the edges of the window @@ -62,7 +62,7 @@ static CGImageRef create_image(CGColorSpaceRef lut, kCGRenderingIntentDefault); CGDataProviderRelease(provider); if (!image) - throw rdr::Exception("CGImageCreate"); + throw std::runtime_error("CGImageCreate"); return image; } @@ -85,7 +85,7 @@ static void render(CGContextRef gc, CGColorSpaceRef lut, subimage = CGImageCreateWithImageInRect(image, rect); if (!subimage) - throw rdr::Exception("CGImageCreateImageWithImageInRect"); + throw std::runtime_error("CGImageCreateImageWithImageInRect"); CGContextSaveGState(gc); @@ -112,7 +112,7 @@ static CGContextRef make_bitmap(int width, int height, unsigned char* data) bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, srgb, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little); if (!bitmap) - throw rdr::Exception("CGBitmapContextCreate"); + throw std::runtime_error("CGBitmapContextCreate"); return bitmap; } diff --git a/vncviewer/Surface_Win32.cxx b/vncviewer/Surface_Win32.cxx index 67ba15c5..c992dbea 100644 --- a/vncviewer/Surface_Win32.cxx +++ b/vncviewer/Surface_Win32.cxx @@ -57,10 +57,10 @@ void Surface::draw(int src_x, int src_y, int dst_x, int dst_y, dc = CreateCompatibleDC(fl_gc); if (!dc) - throw rdr::Win32Exception("CreateCompatibleDC", GetLastError()); + throw rdr::win32_error("CreateCompatibleDC", GetLastError()); if (!SelectObject(dc, bitmap)) - throw rdr::Win32Exception("SelectObject", GetLastError()); + throw rdr::win32_error("SelectObject", GetLastError()); if (!BitBlt(fl_gc, dst_x, dst_y, dst_w, dst_h, dc, src_x, src_y, SRCCOPY)) { @@ -70,7 +70,7 @@ void Surface::draw(int src_x, int src_y, int dst_x, int dst_y, // with it. For now, we've only seen this error and for this function // so only ignore this combination. if (GetLastError() != ERROR_INVALID_HANDLE) - throw rdr::Win32Exception("BitBlt", GetLastError()); + throw rdr::win32_error("BitBlt", GetLastError()); } DeleteDC(dc); @@ -83,10 +83,10 @@ void Surface::draw(Surface* dst, int src_x, int src_y, dstdc = CreateCompatibleDC(nullptr); if (!dstdc) - throw rdr::Win32Exception("CreateCompatibleDC", GetLastError()); + throw rdr::win32_error("CreateCompatibleDC", GetLastError()); if (!SelectObject(dstdc, dst->bitmap)) - throw rdr::Win32Exception("SelectObject", GetLastError()); + throw rdr::win32_error("SelectObject", GetLastError()); origdc = fl_gc; fl_gc = dstdc; @@ -113,15 +113,15 @@ void Surface::blend(Surface* dst, int src_x, int src_y, dstdc = CreateCompatibleDC(nullptr); if (!dstdc) - throw rdr::Win32Exception("CreateCompatibleDC", GetLastError()); + throw rdr::win32_error("CreateCompatibleDC", GetLastError()); srcdc = CreateCompatibleDC(nullptr); if (!srcdc) - throw rdr::Win32Exception("CreateCompatibleDC", GetLastError()); + throw rdr::win32_error("CreateCompatibleDC", GetLastError()); if (!SelectObject(dstdc, dst->bitmap)) - throw rdr::Win32Exception("SelectObject", GetLastError()); + throw rdr::win32_error("SelectObject", GetLastError()); if (!SelectObject(srcdc, bitmap)) - throw rdr::Win32Exception("SelectObject", GetLastError()); + throw rdr::win32_error("SelectObject", GetLastError()); blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; @@ -136,7 +136,7 @@ void Surface::blend(Surface* dst, int src_x, int src_y, // with it. For now, we've only seen this error and for this function // so only ignore this combination. if (GetLastError() != ERROR_INVALID_HANDLE) - throw rdr::Win32Exception("BitBlt", GetLastError()); + throw rdr::win32_error("BitBlt", GetLastError()); } DeleteDC(srcdc); @@ -161,7 +161,7 @@ void Surface::alloc() bitmap = CreateDIBSection(nullptr, (BITMAPINFO*)&bih, DIB_RGB_COLORS, (void**)&data, nullptr, 0); if (!bitmap) - throw rdr::Win32Exception("CreateDIBSection", GetLastError()); + throw rdr::win32_error("CreateDIBSection", GetLastError()); } void Surface::dealloc() diff --git a/vncviewer/Surface_X11.cxx b/vncviewer/Surface_X11.cxx index d27fcd26..e73985f0 100644 --- a/vncviewer/Surface_X11.cxx +++ b/vncviewer/Surface_X11.cxx @@ -23,11 +23,11 @@ #include <assert.h> #include <stdlib.h> +#include <stdexcept> + #include <FL/Fl_RGB_Image.H> #include <FL/x.H> -#include <rdr/Exception.h> - #include "Surface.h" void Surface::clear(unsigned char r, unsigned char g, unsigned char b, unsigned char a) @@ -156,7 +156,7 @@ void Surface::alloc() &templ, 0); if (!format) - throw rdr::Exception("XRenderFindFormat"); + throw std::runtime_error("XRenderFindFormat"); picture = XRenderCreatePicture(fl_display, pixmap, format, 0, nullptr); @@ -185,11 +185,11 @@ void Surface::update(const Fl_RGB_Image* image) ZPixmap, 0, nullptr, width(), height(), 32, 0); if (!img) - throw rdr::Exception("XCreateImage"); + throw std::runtime_error("XCreateImage"); img->data = (char*)malloc(img->bytes_per_line * img->height); if (!img->data) - throw rdr::Exception("malloc"); + throw std::bad_alloc(); // Convert data and pre-multiply alpha in = (const unsigned char*)image->data()[0]; diff --git a/vncviewer/UserDialog.cxx b/vncviewer/UserDialog.cxx index ed75a53c..c6cc02f7 100644 --- a/vncviewer/UserDialog.cxx +++ b/vncviewer/UserDialog.cxx @@ -36,6 +36,8 @@ #include <FL/Fl_Return_Button.H> #include <FL/Fl_Pixmap.H> +#include <rdr/Exception.h> + #include <rfb/Exception.h> #include <rfb/obfuscate.h> @@ -118,7 +120,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, fp = fopen(passwordFileName, "rb"); if (!fp) - throw rdr::PosixException(_("Opening password file failed"), errno); + throw rdr::posix_error(_("Opening password file failed"), errno); obfPwd.resize(fread(obfPwd.data(), 1, obfPwd.size(), fp)); fclose(fp); @@ -249,7 +251,7 @@ void UserDialog::getUserPasswd(bool secure_, std::string* user, delete win; if (ret_val != 0) - throw rfb::AuthCancelledException(); + throw rfb::auth_cancelled(); } bool UserDialog::showMsgBox(MsgBoxFlags flags, const char* title, const char* text) diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx index e29c877c..52fde49c 100644 --- a/vncviewer/Viewport.cxx +++ b/vncviewer/Viewport.cxx @@ -27,7 +27,6 @@ #include <rfb/CMsgWriter.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> #include <rfb/KeysymStr.h> #include <rfb/ledStates.h> #include <rfb/util.h> @@ -130,11 +129,11 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& /*serverPF*/, CConn* cc xkb = XkbGetMap(fl_display, 0, XkbUseCoreKbd); if (!xkb) - throw rfb::Exception("XkbGetMap"); + throw std::runtime_error("XkbGetMap"); status = XkbGetNames(fl_display, XkbKeyNamesMask, xkb); if (status != Success) - throw rfb::Exception("XkbGetNames"); + throw std::runtime_error("XkbGetNames"); memset(code_map_keycode_to_qnum, 0, sizeof(code_map_keycode_to_qnum)); for (KeyCode keycode = xkb->min_key_code; @@ -575,8 +574,8 @@ int Viewport::handle(int event) try { cc->sendClipboardData(filtered.c_str()); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } @@ -668,8 +667,8 @@ void Viewport::sendPointerEvent(const rfb::Point& pos, uint8_t buttonMask) if ((pointerEventInterval == 0) || (buttonMask != lastButtonMask)) { try { cc->writer()->writePointerEvent(pos, buttonMask); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } } else { @@ -775,8 +774,8 @@ void Viewport::handleClipboardChange(int source, void *data) vlog.debug("Local clipboard changed, notifying server"); try { self->cc->announceClipboard(true); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } } @@ -788,8 +787,8 @@ void Viewport::flushPendingClipboard() vlog.debug("Focus regained after local clipboard change, notifying server"); try { cc->announceClipboard(true); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } } @@ -813,8 +812,8 @@ void Viewport::handlePointerTimeout(void *data) try { self->cc->writer()->writePointerEvent(self->lastPointerPos, self->lastButtonMask); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } } @@ -885,8 +884,8 @@ void Viewport::handleKeyPress(int keyCode, uint32_t keySym) cc->writer()->writeKeyEvent(keySym, 0, true); else cc->writer()->writeKeyEvent(keySym, keyCode, true); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } } @@ -915,8 +914,8 @@ void Viewport::handleKeyRelease(int keyCode) cc->writer()->writeKeyEvent(iter->second, 0, false); else cc->writer()->writeKeyEvent(iter->second, keyCode, false); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_connection_with_unexpected_error(e); } diff --git a/vncviewer/Win32TouchHandler.cxx b/vncviewer/Win32TouchHandler.cxx index e21768f9..2be27ede 100644 --- a/vncviewer/Win32TouchHandler.cxx +++ b/vncviewer/Win32TouchHandler.cxx @@ -22,9 +22,10 @@ #include <math.h> +#include <stdexcept> + #define XK_MISCELLANY #include <rfb/keysymdef.h> -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include "i18n.h" @@ -44,7 +45,7 @@ Win32TouchHandler::Win32TouchHandler(HWND hWnd_) : // If window is registered as touch we can not receive gestures, // this should not happen if (IsTouchWindow(hWnd, nullptr)) - throw rfb::Exception(_("Window is registered for touch instead of gestures")); + throw std::runtime_error(_("Window is registered for touch instead of gestures")); // We will not receive any touch/gesture events if this service // isn't running - Logging is enough diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index c75cad8b..a6229a34 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -33,7 +33,9 @@ #include "parameters.h" #include <os/os.h> -#include <rfb/Exception.h> + +#include <rdr/Exception.h> + #include <rfb/LogWriter.h> #include <rfb/SecurityClient.h> #include <rfb/util.h> @@ -305,20 +307,20 @@ static void setKeyString(const char *_name, const char *_value, HKEY* hKey) { wchar_t name[buffersize]; unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) - throw Exception(_("The name of the parameter is too large")); + throw std::invalid_argument(_("The name of the parameter is too large")); char encodingBuffer[buffersize]; if (!encodeValue(_value, encodingBuffer, buffersize)) - throw Exception(_("The parameter is too large")); + throw std::invalid_argument(_("The parameter is too large")); wchar_t value[buffersize]; size = fl_utf8towc(encodingBuffer, strlen(encodingBuffer)+1, value, buffersize); if (size >= buffersize) - throw Exception(_("The parameter is too large")); + throw std::invalid_argument(_("The parameter is too large")); LONG res = RegSetValueExW(*hKey, name, 0, REG_SZ, (BYTE*)&value, (wcslen(value)+1)*2); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception("RegSetValueExW", res); + throw rdr::win32_error("RegSetValueExW", res); } @@ -330,11 +332,11 @@ static void setKeyInt(const char *_name, const int _value, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) - throw Exception(_("The name of the parameter is too large")); + throw std::out_of_range(_("The name of the parameter is too large")); LONG res = RegSetValueExW(*hKey, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD)); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception("RegSetValueExW", res); + throw rdr::win32_error("RegSetValueExW", res); } @@ -347,7 +349,7 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) - throw Exception(_("The name of the parameter is too large")); + throw std::out_of_range(_("The name of the parameter is too large")); value = new WCHAR[destSize]; valuesize = destSize; @@ -355,7 +357,7 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h if (res != ERROR_SUCCESS){ delete [] value; if (res != ERROR_FILE_NOT_FOUND) - throw rdr::Win32Exception("RegQueryValueExW", res); + throw rdr::win32_error("RegQueryValueExW", res); // The value does not exist, defaults will be used. return false; } @@ -365,14 +367,14 @@ static bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* h delete [] value; if (size >= destSize) { delete [] utf8val; - throw Exception(_("The parameter is too large")); + throw std::out_of_range(_("The parameter is too large")); } bool ret = decodeValue(utf8val, dest, destSize); delete [] utf8val; if (!ret) - throw Exception(_("Invalid format or too large value")); + throw std::invalid_argument(_("Invalid format or too large value")); return true; } @@ -387,12 +389,12 @@ static bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) - throw Exception(_("The name of the parameter is too large")); + throw std::out_of_range(_("The name of the parameter is too large")); LONG res = RegQueryValueExW(*hKey, name, nullptr, nullptr, (LPBYTE)&value, &dwordsize); if (res != ERROR_SUCCESS){ if (res != ERROR_FILE_NOT_FOUND) - throw rdr::Win32Exception("RegQueryValueExW", res); + throw rdr::win32_error("RegQueryValueExW", res); // The value does not exist, defaults will be used. return false; } @@ -407,12 +409,12 @@ static void removeValue(const char* _name, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) - throw Exception(_("The name of the parameter is too large")); + throw std::out_of_range(_("The name of the parameter is too large")); LONG res = RegDeleteValueW(*hKey, name); if (res != ERROR_SUCCESS) { if (res != ERROR_FILE_NOT_FOUND) - throw rdr::Win32Exception("RegDeleteValueW", res); + throw rdr::win32_error("RegDeleteValueW", res); // The value does not exist, no need to remove it. return; } @@ -426,7 +428,7 @@ void saveHistoryToRegKey(const list<string>& serverHistory) { &hKey, nullptr); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to create registry key"), res); + throw rdr::win32_error(_("Failed to create registry key"), res); unsigned index = 0; assert(SERVER_HISTORY_SIZE < 100); @@ -440,14 +442,14 @@ void saveHistoryToRegKey(const list<string>& serverHistory) { setKeyString(indexString, entry.c_str(), &hKey); index++; } - } catch (Exception& e) { + } catch (std::exception& e) { RegCloseKey(hKey); throw; } res = RegCloseKey(hKey); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to close registry key"), res); + throw rdr::win32_error(_("Failed to close registry key"), res); } static void saveToReg(const char* servername) { @@ -459,14 +461,14 @@ static void saveToReg(const char* servername) { REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nullptr, &hKey, nullptr); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to create registry key"), res); + throw rdr::win32_error(_("Failed to create registry key"), res); try { setKeyString("ServerName", servername, &hKey); - } catch (Exception& e) { + } catch (std::exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to save \"%s\": %s"), - "ServerName", e.str()); + throw std::runtime_error(format(_("Failed to save \"%s\": %s"), + "ServerName", e.what())); } for (size_t i = 0; i < sizeof(parameterArray)/sizeof(VoidParameter*); i++) { @@ -478,12 +480,13 @@ static void saveToReg(const char* servername) { } else if (dynamic_cast<BoolParameter*>(parameterArray[i]) != nullptr) { setKeyInt(parameterArray[i]->getName(), (int)*(BoolParameter*)parameterArray[i], &hKey); } else { - throw Exception(_("Unknown parameter type")); + throw std::logic_error(_("Unknown parameter type")); } - } catch (Exception& e) { + } catch (std::exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to save \"%s\": %s"), - parameterArray[i]->getName(), e.str()); + throw std::runtime_error(format(_("Failed to save \"%s\": %s"), + parameterArray[i]->getName(), + e.what())); } } @@ -493,16 +496,17 @@ static void saveToReg(const char* servername) { for (size_t i = 0; i < sizeof(readOnlyParameterArray)/sizeof(VoidParameter*); i++) { try { removeValue(readOnlyParameterArray[i]->getName(), &hKey); - } catch (Exception& e) { + } catch (std::exception& e) { RegCloseKey(hKey); - throw Exception(_("Failed to remove \"%s\": %s"), - readOnlyParameterArray[i]->getName(), e.str()); + throw std::runtime_error(format(_("Failed to remove \"%s\": %s"), + readOnlyParameterArray[i]->getName(), + e.what())); } } res = RegCloseKey(hKey); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to close registry key"), res); + throw rdr::win32_error(_("Failed to close registry key"), res); } list<string> loadHistoryFromRegKey() { @@ -518,7 +522,7 @@ list<string> loadHistoryFromRegKey() { return serverHistory; } - throw rdr::Win32Exception(_("Failed to open registry key"), res); + throw rdr::win32_error(_("Failed to open registry key"), res); } unsigned index; @@ -533,10 +537,10 @@ list<string> loadHistoryFromRegKey() { if (!getKeyString(indexString, servernameBuffer, buffersize, &hKey)) break; - } catch (Exception& e) { + } catch (std::exception& e) { // Just ignore this entry and try the next one vlog.error(_("Failed to read server history entry %d: %s"), - (int)index, e.str()); + (int)index, e.what()); continue; } @@ -545,7 +549,7 @@ list<string> loadHistoryFromRegKey() { res = RegCloseKey(hKey); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to close registry key"), res); + throw rdr::win32_error(_("Failed to close registry key"), res); return serverHistory; } @@ -569,12 +573,12 @@ static void getParametersFromReg(VoidParameter* parameters[], if (getKeyInt(parameters[i]->getName(), &intValue, hKey)) ((BoolParameter*)parameters[i])->setParam(intValue); } else { - throw Exception(_("Unknown parameter type")); + throw std::logic_error(_("Unknown parameter type")); } - } catch(Exception& e) { + } catch(std::exception& e) { // Just ignore this entry and continue with the rest vlog.error(_("Failed to read parameter \"%s\": %s"), - parameters[i]->getName(), e.str()); + parameters[i]->getName(), e.what()); } } } @@ -592,7 +596,7 @@ static char* loadFromReg() { return nullptr; } - throw rdr::Win32Exception(_("Failed to open registry key"), res); + throw rdr::win32_error(_("Failed to open registry key"), res); } const size_t buffersize = 256; @@ -602,9 +606,9 @@ static char* loadFromReg() { try { if (getKeyString("ServerName", servernameBuffer, buffersize, &hKey)) snprintf(servername, buffersize, "%s", servernameBuffer); - } catch(Exception& e) { + } catch(std::exception& e) { vlog.error(_("Failed to read parameter \"%s\": %s"), - "ServerName", e.str()); + "ServerName", e.what()); strcpy(servername, ""); } @@ -614,7 +618,7 @@ static char* loadFromReg() { res = RegCloseKey(hKey); if (res != ERROR_SUCCESS) - throw rdr::Win32Exception(_("Failed to close registry key"), res); + throw rdr::win32_error(_("Failed to close registry key"), res); return servername; } @@ -637,7 +641,7 @@ void saveViewerParameters(const char *filename, const char *servername) { const char* configDir = os::getvncconfigdir(); if (configDir == nullptr) - throw Exception(_("Could not determine VNC config directory path")); + throw std::runtime_error(_("Could not determine VNC config directory path")); snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", configDir); } else { @@ -648,7 +652,7 @@ void saveViewerParameters(const char *filename, const char *servername) { FILE* f = fopen(filepath, "w+"); if (!f) { std::string msg = format(_("Could not open \"%s\""), filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } fprintf(f, "%s\n", IDENTIFIER_STRING); @@ -656,8 +660,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(servername, encodingBuffer, buffersize)) { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - "ServerName", _("Could not encode parameter")); + throw std::runtime_error(format(_("Failed to save \"%s\": %s"), + "ServerName", + _("Could not encode parameter"))); } fprintf(f, "ServerName=%s\n", encodingBuffer); @@ -666,9 +671,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(*(StringParameter*)param, encodingBuffer, buffersize)) { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - param->getName(), - _("Could not encode parameter")); + throw std::runtime_error(format(_("Failed to save \"%s\": %s"), + param->getName(), + _("Could not encode parameter"))); } fprintf(f, "%s=%s\n", ((StringParameter*)param)->getName(), encodingBuffer); } else if (dynamic_cast<IntParameter*>(param) != nullptr) { @@ -677,9 +682,9 @@ void saveViewerParameters(const char *filename, const char *servername) { fprintf(f, "%s=%d\n", ((BoolParameter*)param)->getName(), (int)*(BoolParameter*)param); } else { fclose(f); - throw Exception(_("Failed to save \"%s\": %s"), - param->getName(), - _("Unknown parameter type")); + throw std::logic_error(format(_("Failed to save \"%s\": %s"), + param->getName(), + _("Unknown parameter type"))); } } fclose(f); @@ -698,7 +703,7 @@ static bool findAndSetViewerParameterFromValue( if (dynamic_cast<StringParameter*>(parameters[i]) != nullptr) { if (strcasecmp(line, ((StringParameter*)parameters[i])->getName()) == 0) { if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) - throw Exception(_("Invalid format or too large value")); + throw std::runtime_error(_("Invalid format or too large value")); ((StringParameter*)parameters[i])->setParam(decodingBuffer); return false; } @@ -716,7 +721,7 @@ static bool findAndSetViewerParameterFromValue( } } else { - throw Exception(_("Unknown parameter type")); + throw std::logic_error(_("Unknown parameter type")); } } @@ -742,7 +747,7 @@ char* loadViewerParameters(const char *filename) { const char* configDir = os::getvncconfigdir(); if (configDir == nullptr) - throw Exception(_("Could not determine VNC config directory path")); + throw std::runtime_error(_("Could not determine VNC config directory path")); snprintf(filepath, sizeof(filepath), "%s/default.tigervnc", configDir); } else { @@ -755,7 +760,7 @@ char* loadViewerParameters(const char *filename) { if (!filename) return nullptr; // Use defaults. std::string msg = format(_("Could not open \"%s\""), filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } int lineNr = 0; @@ -770,13 +775,16 @@ char* loadViewerParameters(const char *filename) { fclose(f); std::string msg = format(_("Failed to read line %d in " "file \"%s\""), lineNr, filepath); - throw rdr::PosixException(msg.c_str(), errno); + throw rdr::posix_error(msg.c_str(), errno); } if (strlen(line) == (sizeof(line) - 1)) { fclose(f); - throw Exception(_("Failed to read line %d in file %s: %s"), - lineNr, filepath, _("Line too long")); + throw std::runtime_error(format("%s: %s", + format(_("Failed to read line %d " + "in file \"%s\""), + lineNr, filepath).c_str(), + _("Line too long"))); } // Make sure that the first line of the file has the file identifier string @@ -785,8 +793,9 @@ char* loadViewerParameters(const char *filename) { continue; fclose(f); - throw Exception(_("Configuration file %s is in an invalid format"), - filepath); + throw std::runtime_error(format(_("Configuration file %s is in " + "an invalid format"), + filepath)); } // Skip empty lines and comments @@ -820,7 +829,7 @@ char* loadViewerParameters(const char *filename) { if (strcasecmp(line, "ServerName") == 0) { if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) - throw Exception(_("Invalid format or too large value")); + throw std::runtime_error(_("Invalid format or too large value")); snprintf(servername, sizeof(decodingBuffer), "%s", decodingBuffer); invalidParameterName = false; @@ -833,10 +842,10 @@ char* loadViewerParameters(const char *filename) { value, line); } } - } catch(Exception& e) { + } catch(std::exception& e) { // Just ignore this entry and continue with the rest vlog.error(_("Failed to read line %d in file %s: %s"), - lineNr, filepath, e.str()); + lineNr, filepath, e.what()); continue; } diff --git a/vncviewer/touch.cxx b/vncviewer/touch.cxx index 1efd3e46..572e726e 100644 --- a/vncviewer/touch.cxx +++ b/vncviewer/touch.cxx @@ -36,7 +36,6 @@ #include <FL/Fl.H> #include <FL/x.H> -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include "i18n.h" @@ -180,9 +179,9 @@ static int handleTouchEvent(void *event, void* /*data*/) if (msg->message == WM_PAINT && handlers.count(msg->hwnd) == 0) { try { handlers[msg->hwnd] = new Win32TouchHandler(msg->hwnd); - } catch (rfb::Exception& e) { - vlog.error(_("Failed to create touch handler: %s"), e.str()); - abort_vncviewer(_("Failed to create touch handler: %s"), e.str()); + } catch (std::exception& e) { + vlog.error(_("Failed to create touch handler: %s"), e.what()); + abort_vncviewer(_("Failed to create touch handler: %s"), e.what()); } // Add a special hook-in for handling events sent directly to WndProc if (!SetWindowSubclass(msg->hwnd, &win32WindowProc, 1, 0)) { diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index a1d9b39d..5acab1a1 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -55,7 +55,6 @@ #include <rfb/Hostname.h> #include <rfb/LogWriter.h> #include <rfb/Timer.h> -#include <rfb/Exception.h> #include <rdr/Exception.h> #include <network/TcpSocket.h> #include <os/os.h> @@ -155,9 +154,9 @@ void abort_connection(const char *error, ...) exitMainloop = true; } -void abort_connection_with_unexpected_error(const rdr::Exception &e) { +void abort_connection_with_unexpected_error(const std::exception &e) { abort_connection(_("An unexpected error occurred when communicating " - "with the server:\n\n%s"), e.str()); + "with the server:\n\n%s"), e.what()); } void disconnect() @@ -513,10 +512,10 @@ potentiallyLoadConfigurationFile(const char *filename) // don't try to connect to the filename strncpy(vncServerName, newServerName, VNCSERVERNAMELEN-1); vncServerName[VNCSERVERNAMELEN-1] = '\0'; - } catch (rfb::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); abort_vncviewer(_("Unable to load the specified configuration " - "file:\n\n%s"), e.str()); + "file:\n\n%s"), e.what()); } } } @@ -671,8 +670,8 @@ int main(int argc, char** argv) strncpy(defaultServerName, configServerName, VNCSERVERNAMELEN-1); defaultServerName[VNCSERVERNAMELEN-1] = '\0'; } - } catch (rfb::Exception& e) { - vlog.error("%s", e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); } for (int i = 1; i < argc;) { @@ -757,7 +756,7 @@ int main(int argc, char** argv) createTcpListeners(&listeners, nullptr, port); if (listeners.empty()) - throw Exception(_("Unable to listen for incoming connections")); + throw std::runtime_error(_("Unable to listen for incoming connections")); vlog.info(_("Listening on port %d"), port); @@ -774,7 +773,7 @@ int main(int argc, char** argv) vlog.debug("Interrupted select() system call"); continue; } else { - throw rdr::SocketException("select", errno); + throw rdr::socket_error("select", errno); } } @@ -786,9 +785,9 @@ int main(int argc, char** argv) break; } } - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); - abort_vncviewer(_("Failure waiting for incoming VNC connection:\n\n%s"), e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); + abort_vncviewer(_("Failure waiting for incoming VNC connection:\n\n%s"), e.what()); return 1; /* Not reached */ } @@ -807,9 +806,9 @@ int main(int argc, char** argv) if (strlen(via) > 0) { try { mktunnel(); - } catch (rdr::Exception& e) { - vlog.error("%s", e.str()); - abort_vncviewer(_("Failure setting up encrypted tunnel:\n\n%s"), e.str()); + } catch (std::exception& e) { + vlog.error("%s", e.what()); + abort_vncviewer(_("Failure setting up encrypted tunnel:\n\n%s"), e.what()); } } #endif diff --git a/vncviewer/vncviewer.h b/vncviewer/vncviewer.h index f39a5776..57fd845d 100644 --- a/vncviewer/vncviewer.h +++ b/vncviewer/vncviewer.h @@ -21,15 +21,11 @@ #define VNCSERVERNAMELEN 256 -namespace rdr { - struct Exception; -}; - void abort_vncviewer(const char *error, ...) __attribute__((__format__ (__printf__, 1, 2))); void abort_connection(const char *error, ...) __attribute__((__format__ (__printf__, 1, 2))); -void abort_connection_with_unexpected_error(const rdr::Exception &); +void abort_connection_with_unexpected_error(const std::exception &); void disconnect(); bool should_disconnect(); |