diff options
author | Pierre Ossman <ossman@cendio.se> | 2024-09-02 22:58:35 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2024-11-06 21:06:27 +0100 |
commit | 1d9b2f9984fefbc050c8e3295397ffd280e41788 (patch) | |
tree | c6fa8a4f5e0e6fbc0e165c2bd80b2c81a48bf6bc | |
parent | 5c3588c464520a4757bfc20974090e21af220cdc (diff) | |
download | tigervnc-1d9b2f9984fefbc050c8e3295397ffd280e41788.tar.gz tigervnc-1d9b2f9984fefbc050c8e3295397ffd280e41788.zip |
Use standard exception classes
Use the more specific already included exception classes for common
errors to keep things more understandable.
70 files changed, 363 insertions, 343 deletions
diff --git a/common/network/Socket.cxx b/common/network/Socket.cxx index 8bb96763..03844acd 100644 --- a/common/network/Socket.cxx +++ b/common/network/Socket.cxx @@ -39,6 +39,8 @@ #include <fcntl.h> #include <errno.h> +#include <rdr/Exception.h> + #include <network/Socket.h> using namespace network; diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx index 38cb6eb3..455df749 100644 --- a/common/network/TcpSocket.cxx +++ b/common/network/TcpSocket.cxx @@ -38,7 +38,10 @@ #include <stdlib.h> #include <unistd.h> +#include <rdr/Exception.h> + #include <network/TcpSocket.h> + #include <rfb/LogWriter.h> #include <rfb/Configuration.h> #include <rfb/util.h> @@ -200,7 +203,7 @@ TcpSocket::TcpSocket(const char *host, int port) if (sock == -1) { if (err == 0) - throw Exception("No useful address for host"); + throw std::runtime_error("No useful address for host"); else throw SocketException("unable to connect to socket", err); } @@ -607,7 +610,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { parts = rfb::split(&p[1], '/'); if (parts.size() > 2) - throw Exception("invalid filter specified"); + throw std::invalid_argument("invalid filter specified"); if (parts[0].empty()) { // Match any address @@ -641,8 +644,8 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { if (parts.size() > 1) { if (family == AF_INET && (parts[1].find('.') != std::string::npos)) { - throw Exception("mask no longer supported for filter, " - "use prefix instead"); + throw std::invalid_argument("mask no longer supported for " + "filter, use prefix instead"); } pattern.prefixlen = (unsigned int) atoi(parts[1].c_str()); @@ -655,7 +658,7 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { pattern.prefixlen = 128; break; default: - throw Exception("unknown address family"); + throw std::runtime_error("unknown address family"); } } } @@ -663,8 +666,9 @@ TcpFilter::Pattern TcpFilter::parsePattern(const char* p) { family = pattern.address.u.sa.sa_family; if (pattern.prefixlen > (family == AF_INET ? 32: 128)) - throw Exception(rfb::format("invalid prefix length for filter address: %u", - pattern.prefixlen)); + throw std::invalid_argument(rfb::format("invalid prefix length for " + "filter address: %u", + pattern.prefixlen)); // Compute mask from address and prefix length memset (&pattern.mask, 0, sizeof (pattern.mask)); diff --git a/common/network/UnixSocket.cxx b/common/network/UnixSocket.cxx index 3a422b6c..4b82b4b7 100644 --- a/common/network/UnixSocket.cxx +++ b/common/network/UnixSocket.cxx @@ -29,7 +29,10 @@ #include <stdlib.h> #include <stddef.h> +#include <rdr/Exception.h> + #include <network/UnixSocket.h> + #include <rfb/LogWriter.h> using namespace network; diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 204202ec..bf94a950 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -24,7 +24,6 @@ #include <assert.h> #include <rdr/BufferedInStream.h> -#include <rdr/Exception.h> #include <rfb/util.h> @@ -65,10 +64,12 @@ void BufferedInStream::ensureSpace(size_t needed) uint8_t* newBuffer; if (needed > MAX_BUF_SIZE) - throw Exception(rfb::format("BufferedInStream overrun: requested " - "size of %lu bytes exceeds maximum " - "of %lu bytes", (long unsigned)needed, - (long unsigned)MAX_BUF_SIZE)); + throw std::out_of_range(rfb::format("BufferedInStream overrun: " + "requested size of %lu bytes " + "exceeds maximum of %lu " + "bytes", + (long unsigned)needed, + (long unsigned)MAX_BUF_SIZE)); newSize = DEFAULT_BUF_SIZE; while (newSize < needed) diff --git a/common/rdr/BufferedOutStream.cxx b/common/rdr/BufferedOutStream.cxx index f5062bf2..efb71dd7 100644 --- a/common/rdr/BufferedOutStream.cxx +++ b/common/rdr/BufferedOutStream.cxx @@ -23,7 +23,6 @@ #endif #include <rdr/BufferedOutStream.h> -#include <rdr/Exception.h> #include <rfb/util.h> @@ -139,10 +138,11 @@ void BufferedOutStream::overrun(size_t needed) // We'll need to allocate more buffer space... if (totalNeeded > MAX_BUF_SIZE) - throw Exception(rfb::format("BufferedOutStream overrun: requested " - "size of %lu bytes exceeds maximum of " - "%lu bytes", (long unsigned)totalNeeded, - (long unsigned)MAX_BUF_SIZE)); + throw std::out_of_range(rfb::format("BufferedOutStream overrun: " + "requested size of %lu bytes " + "exceeds maximum of %lu bytes", + (long unsigned)totalNeeded, + (long unsigned)MAX_BUF_SIZE)); newSize = DEFAULT_BUF_SIZE; while (newSize < totalNeeded) diff --git a/common/rdr/HexInStream.cxx b/common/rdr/HexInStream.cxx index 11f98498..69c3e260 100644 --- a/common/rdr/HexInStream.cxx +++ b/common/rdr/HexInStream.cxx @@ -23,7 +23,6 @@ #include <algorithm> #include <rdr/HexInStream.h> -#include <rdr/Exception.h> #include <rfb/util.h> using namespace rdr; @@ -46,7 +45,7 @@ bool HexInStream::fillBuffer() { uint8_t* optr = (uint8_t*) end; for (size_t i=0; i<length; i++) { if (!rfb::hexToBin((const char*)&iptr[i*2], 2, &optr[i], 1)) - throw Exception("HexInStream: Invalid input data"); + throw std::runtime_error("HexInStream: Invalid input data"); } in_stream.setptr(length*2); diff --git a/common/rdr/InStream.h b/common/rdr/InStream.h index 939439e1..5623142c 100644 --- a/common/rdr/InStream.h +++ b/common/rdr/InStream.h @@ -28,7 +28,7 @@ #include <stdint.h> #include <string.h> // for memcpy -#include <rdr/Exception.h> +#include <stdexcept> // Check that callers are using InStream properly, // useful when writing new protocol handling @@ -101,21 +101,21 @@ namespace rdr { inline void setRestorePoint() { #ifdef RFB_INSTREAM_CHECK if (restorePoint != nullptr) - throw Exception("Nested use of input stream restore point"); + throw std::logic_error("Nested use of input stream restore point"); #endif restorePoint = ptr; } inline void clearRestorePoint() { #ifdef RFB_INSTREAM_CHECK if (restorePoint == nullptr) - throw Exception("Incorrect clearing of input stream restore point"); + throw std::logic_error("Incorrect clearing of input stream restore point"); #endif restorePoint = nullptr; } inline void gotoRestorePoint() { #ifdef RFB_INSTREAM_CHECK if (restorePoint == nullptr) - throw Exception("Incorrect activation of input stream restore point"); + throw std::logic_error("Incorrect activation of input stream restore point"); #endif ptr = restorePoint; clearRestorePoint(); @@ -176,7 +176,7 @@ namespace rdr { inline const uint8_t* getptr(size_t length) { check(length); return ptr; } inline void setptr(size_t length) { if (length > avail()) - throw Exception("Input stream overflow"); + throw std::out_of_range("Input stream overflow"); skip(length); } private: @@ -189,11 +189,11 @@ namespace rdr { inline void check(size_t bytes) { #ifdef RFB_INSTREAM_CHECK if (bytes > checkedBytes) - throw Exception("Input stream used without underrun check"); + throw std::logic_error("Input stream used without underrun check"); checkedBytes -= bytes; #endif if (bytes > (size_t)(end - ptr)) - throw Exception("InStream buffer underrun"); + throw std::out_of_range("InStream buffer underrun"); } // overrun() is implemented by a derived class to cope with buffer overrun. diff --git a/common/rdr/MemOutStream.h b/common/rdr/MemOutStream.h index 9bf2b810..bf05d92c 100644 --- a/common/rdr/MemOutStream.h +++ b/common/rdr/MemOutStream.h @@ -23,7 +23,6 @@ #ifndef __RDR_MEMOUTSTREAM_H__ #define __RDR_MEMOUTSTREAM_H__ -#include <rdr/Exception.h> #include <rdr/OutStream.h> namespace rdr { @@ -61,7 +60,7 @@ namespace rdr { len = (end - start) * 2; if (len < (size_t)(end - start)) - throw Exception("Overflow in MemOutStream::overrun()"); + throw std::out_of_range("Overflow in MemOutStream::overrun()"); uint8_t* newStart = new uint8_t[len]; memcpy(newStart, start, ptr - start); diff --git a/common/rdr/OutStream.h b/common/rdr/OutStream.h index 2921b232..b78ec4b0 100644 --- a/common/rdr/OutStream.h +++ b/common/rdr/OutStream.h @@ -27,7 +27,8 @@ #include <stdint.h> #include <string.h> // for memcpy -#include <rdr/Exception.h> +#include <stdexcept> + #include <rdr/InStream.h> namespace rdr { @@ -129,7 +130,7 @@ namespace rdr { inline uint8_t* getptr(size_t length) { check(length); return ptr; } inline void setptr(size_t length) { if (length > avail()) - throw Exception("Output stream overflow"); + throw std::out_of_range("Output stream overflow"); ptr += length; } private: diff --git a/common/rdr/ZlibInStream.cxx b/common/rdr/ZlibInStream.cxx index a90d50f7..c9f8aeca 100644 --- a/common/rdr/ZlibInStream.cxx +++ b/common/rdr/ZlibInStream.cxx @@ -23,7 +23,6 @@ #include <assert.h> #include <rdr/ZlibInStream.h> -#include <rdr/Exception.h> #include <zlib.h> using namespace rdr; @@ -50,7 +49,7 @@ void ZlibInStream::flushUnderlying() { while (bytesIn > 0) { if (!hasData(1)) - throw Exception("ZlibInStream: failed to flush remaining stream data"); + throw std::runtime_error("ZlibInStream: failed to flush remaining stream data"); skip(avail()); } @@ -76,7 +75,7 @@ void ZlibInStream::init() if (inflateInit(zs) != Z_OK) { delete zs; zs = nullptr; - throw Exception("ZlibInStream: inflateInit failed"); + throw std::runtime_error("ZlibInStream: inflateInit failed"); } } @@ -92,7 +91,7 @@ void ZlibInStream::deinit() bool ZlibInStream::fillBuffer() { if (!underlying) - throw Exception("ZlibInStream overrun: no underlying stream"); + throw std::runtime_error("ZlibInStream overrun: no underlying stream"); zs->next_out = (uint8_t*)end; zs->avail_out = availSpace(); @@ -107,7 +106,7 @@ bool ZlibInStream::fillBuffer() int rc = inflate(zs, Z_SYNC_FLUSH); if (rc < 0) { - throw Exception("ZlibInStream: inflate failed"); + throw std::runtime_error("ZlibInStream: inflate failed"); } bytesIn -= length - zs->avail_in; diff --git a/common/rdr/ZlibOutStream.cxx b/common/rdr/ZlibOutStream.cxx index 1b59f54e..13788f8d 100644 --- a/common/rdr/ZlibOutStream.cxx +++ b/common/rdr/ZlibOutStream.cxx @@ -24,7 +24,6 @@ #include <stdio.h> #include <rdr/ZlibOutStream.h> -#include <rdr/Exception.h> #include <rfb/LogWriter.h> #include <zlib.h> @@ -46,7 +45,7 @@ ZlibOutStream::ZlibOutStream(OutStream* os, int compressLevel) zs->avail_in = 0; if (deflateInit(zs, compressLevel) != Z_OK) { delete zs; - throw Exception("ZlibOutStream: deflateInit failed"); + throw std::runtime_error("ZlibOutStream: deflateInit failed"); } } @@ -113,7 +112,7 @@ void ZlibOutStream::deflate(int flush) int rc; if (!underlying) - throw Exception("ZlibOutStream: underlying OutStream has not been set"); + throw std::runtime_error("ZlibOutStream: underlying OutStream has not been set"); if ((flush == Z_NO_FLUSH) && (zs->avail_in == 0)) return; @@ -134,7 +133,7 @@ void ZlibOutStream::deflate(int flush) if ((rc == Z_BUF_ERROR) && (flush != Z_NO_FLUSH)) break; - throw Exception("ZlibOutStream: deflate failed"); + throw std::runtime_error("ZlibOutStream: deflate failed"); } #ifdef ZLIBOUT_DEBUG @@ -168,7 +167,7 @@ void ZlibOutStream::checkCompressionLevel() // explicit flush we did above. It should be safe to ignore though // as the first flush should have left things in a stable state... if (rc != Z_BUF_ERROR) - throw Exception("ZlibOutStream: deflateParams failed"); + throw std::runtime_error("ZlibOutStream: deflateParams failed"); } compressionLevel = newLevel; diff --git a/common/rfb/CConnection.cxx b/common/rfb/CConnection.cxx index 3a34740f..244c8862 100644 --- a/common/rfb/CConnection.cxx +++ b/common/rfb/CConnection.cxx @@ -147,11 +147,11 @@ bool CConnection::processMsg() case RFBSTATE_INITIALISATION: return processInitMsg(); break; case RFBSTATE_NORMAL: return reader_->readMsg(); break; case RFBSTATE_CLOSING: - throw Exception("CConnection::processMsg: called while closing"); + throw std::logic_error("CConnection::processMsg: called while closing"); case RFBSTATE_UNINITIALISED: - throw Exception("CConnection::processMsg: not initialised yet?"); + throw std::logic_error("CConnection::processMsg: not initialised yet?"); default: - throw Exception("CConnection::processMsg: invalid state"); + throw std::logic_error("CConnection::processMsg: invalid state"); } } diff --git a/common/rfb/CMsgWriter.cxx b/common/rfb/CMsgWriter.cxx index 1bd8040f..1c801412 100644 --- a/common/rfb/CMsgWriter.cxx +++ b/common/rfb/CMsgWriter.cxx @@ -31,7 +31,6 @@ #include <rfb/fenceTypes.h> #include <rfb/qemuTypes.h> #include <rfb/clipboardTypes.h> -#include <rfb/Exception.h> #include <rfb/PixelFormat.h> #include <rfb/Rect.h> #include <rfb/ServerParams.h> @@ -77,7 +76,7 @@ void CMsgWriter::writeSetDesktopSize(int width, int height, const ScreenSet& layout) { if (!server->supportsSetDesktopSize) - throw Exception("Server does not support SetDesktopSize"); + throw std::logic_error("Server does not support SetDesktopSize"); startMsg(msgTypeSetDesktopSize); os->pad(1); @@ -116,7 +115,7 @@ void CMsgWriter::writeEnableContinuousUpdates(bool enable, int x, int y, int w, int h) { if (!server->supportsContinuousUpdates) - throw Exception("Server does not support continuous updates"); + throw std::logic_error("Server does not support continuous updates"); startMsg(msgTypeEnableContinuousUpdates); @@ -133,11 +132,11 @@ void CMsgWriter::writeEnableContinuousUpdates(bool enable, void CMsgWriter::writeFence(uint32_t flags, unsigned len, const uint8_t data[]) { if (!server->supportsFence) - throw Exception("Server does not support fences"); + throw std::logic_error("Server does not support fences"); if (len > 64) - throw Exception("Too large fence payload"); + throw std::out_of_range("Too large fence payload"); if ((flags & ~fenceFlagsSupported) != 0) - throw Exception("Unknown fence flags"); + throw std::invalid_argument("Unknown fence flags"); startMsg(msgTypeClientFence); os->pad(3); @@ -192,7 +191,7 @@ void CMsgWriter::writePointerEvent(const Point& pos, uint8_t buttonMask) void CMsgWriter::writeClientCutText(const char* str) { if (strchr(str, '\r') != nullptr) - throw Exception("Invalid carriage return in clipboard data"); + throw std::invalid_argument("Invalid carriage return in clipboard data"); std::string latin1(utf8ToLatin1(str)); @@ -209,7 +208,7 @@ void CMsgWriter::writeClipboardCaps(uint32_t caps, size_t i, count; if (!(server->clipboardFlags() & clipboardCaps)) - throw Exception("Server does not support clipboard \"caps\" action"); + throw std::logic_error("Server does not support clipboard \"caps\" action"); count = 0; for (i = 0;i < 16;i++) { @@ -235,7 +234,7 @@ void CMsgWriter::writeClipboardCaps(uint32_t caps, void CMsgWriter::writeClipboardRequest(uint32_t flags) { if (!(server->clipboardFlags() & clipboardRequest)) - throw Exception("Server does not support clipboard \"request\" action"); + throw std::logic_error("Server does not support clipboard \"request\" action"); startMsg(msgTypeClientCutText); os->pad(3); @@ -247,7 +246,7 @@ void CMsgWriter::writeClipboardRequest(uint32_t flags) void CMsgWriter::writeClipboardPeek(uint32_t flags) { if (!(server->clipboardFlags() & clipboardPeek)) - throw Exception("Server does not support clipboard \"peek\" action"); + throw std::logic_error("Server does not support clipboard \"peek\" action"); startMsg(msgTypeClientCutText); os->pad(3); @@ -259,7 +258,7 @@ void CMsgWriter::writeClipboardPeek(uint32_t flags) void CMsgWriter::writeClipboardNotify(uint32_t flags) { if (!(server->clipboardFlags() & clipboardNotify)) - throw Exception("Server does not support clipboard \"notify\" action"); + throw std::logic_error("Server does not support clipboard \"notify\" action"); startMsg(msgTypeClientCutText); os->pad(3); @@ -278,7 +277,7 @@ void CMsgWriter::writeClipboardProvide(uint32_t flags, int i, count; if (!(server->clipboardFlags() & clipboardProvide)) - throw Exception("Server does not support clipboard \"provide\" action"); + throw std::logic_error("Server does not support clipboard \"provide\" action"); zos.setUnderlying(&mos); diff --git a/common/rfb/CSecurityDH.cxx b/common/rfb/CSecurityDH.cxx index 6eafbd9c..e37a3a33 100644 --- a/common/rfb/CSecurityDH.cxx +++ b/common/rfb/CSecurityDH.cxx @@ -112,7 +112,7 @@ void CSecurityDH::writeCredentials() std::vector<uint8_t> bBytes(keyLength); if (!rs.hasData(keyLength)) - throw Exception("failed to generate DH private key"); + throw std::runtime_error("failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -132,13 +132,13 @@ void CSecurityDH::writeCredentials() uint8_t buf[128]; if (!rs.hasData(128)) - throw Exception("failed to generate random padding"); + throw std::runtime_error("failed to generate random padding"); rs.readBytes(buf, 128); if (username.size() >= 64) - throw Exception("username is too long"); + throw std::out_of_range("username is too long"); memcpy(buf, username.c_str(), username.size() + 1); if (password.size() >= 64) - throw Exception("password is too long"); + throw std::out_of_range("password is too long"); memcpy(buf + 64, password.c_str(), password.size() + 1); aes128_encrypt(&aesCtx, 128, buf, buf); diff --git a/common/rfb/CSecurityMSLogonII.cxx b/common/rfb/CSecurityMSLogonII.cxx index f8ff36c1..85736b44 100644 --- a/common/rfb/CSecurityMSLogonII.cxx +++ b/common/rfb/CSecurityMSLogonII.cxx @@ -39,7 +39,6 @@ #include <rdr/InStream.h> #include <rdr/OutStream.h> #include <rdr/RandomStream.h> -#include <rfb/Exception.h> #include <os/os.h> using namespace rfb; @@ -101,7 +100,7 @@ void CSecurityMSLogonII::writeCredentials() std::vector<uint8_t> bBytes(8); if (!rs.hasData(8)) - throw Exception("failed to generate DH private key"); + throw std::runtime_error("failed to generate DH private key"); rs.readBytes(bBytes.data(), bBytes.size()); nettle_mpz_set_str_256_u(b, bBytes.size(), bBytes.data()); mpz_powm(k, A, b, p); @@ -123,14 +122,14 @@ void CSecurityMSLogonII::writeCredentials() } if (!rs.hasData(256 + 64)) - throw Exception("failed to generate random padding"); + throw std::runtime_error("failed to generate random padding"); rs.readBytes(user, 256); rs.readBytes(pass, 64); if (username.size() >= 256) - throw Exception("username is too long"); + throw std::out_of_range("username is too long"); memcpy(user, username.c_str(), username.size() + 1); if (password.size() >= 64) - throw Exception("password is too long"); + throw std::out_of_range("password is too long"); memcpy(pass, password.c_str(), password.size() + 1); // DES-CBC with the original key as IV, and the reversed one as the DES key diff --git a/common/rfb/CSecurityRSAAES.cxx b/common/rfb/CSecurityRSAAES.cxx index 4baeb235..37b59532 100644 --- a/common/rfb/CSecurityRSAAES.cxx +++ b/common/rfb/CSecurityRSAAES.cxx @@ -134,7 +134,7 @@ static void random_func(void* ctx, size_t length, uint8_t* dst) { rdr::RandomStream* rs = (rdr::RandomStream*)ctx; if (!rs->hasData(length)) - throw Exception("failed to generate random"); + throw std::runtime_error("failed to generate random"); rs->readBytes(dst, length); } @@ -155,7 +155,7 @@ void CSecurityRSAAES::writePublicKey() if (!rsa_generate_keypair(&clientPublicKey, &clientKey, &rs, random_func, nullptr, nullptr, clientKeyLength, 0)) - throw Exception("failed to generate key"); + throw std::runtime_error("failed to generate key"); clientKeyN = new uint8_t[rsaKeySize]; clientKeyE = new uint8_t[rsaKeySize]; nettle_mpz_get_str_256(rsaKeySize, clientKeyN, clientPublicKey.n); @@ -222,7 +222,7 @@ void CSecurityRSAAES::writeRandom() { rdr::OutStream* os = cc->getOutStream(); if (!rs.hasData(keySize / 8)) - throw Exception("failed to generate random"); + throw std::runtime_error("failed to generate random"); rs.readBytes(clientRandom, keySize / 8); mpz_t x; mpz_init(x); @@ -236,7 +236,7 @@ void CSecurityRSAAES::writeRandom() } if (!res) { mpz_clear(x); - throw Exception("failed to encrypt random"); + throw std::runtime_error("failed to encrypt random"); } uint8_t* buffer = new uint8_t[serverKey.size]; nettle_mpz_get_str_256(serverKey.size, buffer, x); @@ -443,7 +443,7 @@ void CSecurityRSAAES::writeCredentials() if (subtype == secTypeRA2UserPass) { if (username.size() > 255) - throw Exception("username is too long"); + throw std::out_of_range("username is too long"); raos->writeU8(username.size()); raos->writeBytes((const uint8_t*)username.data(), username.size()); } else { @@ -451,7 +451,7 @@ void CSecurityRSAAES::writeCredentials() } if (password.size() > 255) - throw Exception("password is too long"); + throw std::out_of_range("password is too long"); raos->writeU8(password.size()); raos->writeBytes((const uint8_t*)password.data(), password.size()); raos->flush(); diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index 2722415b..ae916139 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -387,8 +387,8 @@ void CSecurityTLS::checkSession() hostsDir = os::getvncstatedir(); if (hostsDir == nullptr) { - throw Exception("Could not obtain VNC state directory path for " - "known hosts storage"); + throw std::runtime_error("Could not obtain VNC state directory " + "path for known hosts storage"); } std::string dbPath; @@ -509,7 +509,7 @@ void CSecurityTLS::checkSession() if (status != 0) { vlog.error("Unhandled certificate problems: 0x%x", status); - throw Exception("Unhandled certificate problems"); + throw std::logic_error("Unhandled certificate problems"); } if (!hostname_match) { @@ -625,7 +625,7 @@ void CSecurityTLS::checkSession() if (status != 0) { vlog.error("Unhandled certificate problems: 0x%x", status); - throw Exception("Unhandled certificate problems"); + throw std::logic_error("Unhandled certificate problems"); } if (!hostname_match) { diff --git a/common/rfb/ClientParams.cxx b/common/rfb/ClientParams.cxx index 3f80f109..495b4bd1 100644 --- a/common/rfb/ClientParams.cxx +++ b/common/rfb/ClientParams.cxx @@ -22,7 +22,8 @@ #include <config.h> #endif -#include <rfb/Exception.h> +#include <stdexcept> + #include <rfb/encodings.h> #include <rfb/ledStates.h> #include <rfb/clipboardTypes.h> @@ -63,7 +64,7 @@ void ClientParams::setDimensions(int width, int height) void ClientParams::setDimensions(int width, int height, const ScreenSet& layout) { if (!layout.validate(width, height)) - throw Exception("Attempted to configure an invalid screen layout"); + throw std::invalid_argument("Attempted to configure an invalid screen layout"); width_ = width; height_ = height; @@ -75,7 +76,7 @@ void ClientParams::setPF(const PixelFormat& pf) pf_ = pf; if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) - throw Exception("setPF: not 8, 16 or 32 bpp?"); + throw std::invalid_argument("setPF: not 8, 16 or 32 bpp?"); } void ClientParams::setName(const char* name) @@ -161,7 +162,7 @@ uint32_t ClientParams::clipboardSize(unsigned int format) const return clipSizes[i]; } - throw Exception(rfb::format("Invalid clipboard format 0x%x", format)); + throw std::invalid_argument(rfb::format("Invalid clipboard format 0x%x", format)); } void ClientParams::setClipboardCaps(uint32_t flags, const uint32_t* lengths) diff --git a/common/rfb/Configuration.cxx b/common/rfb/Configuration.cxx index f58a9c2f..8f7cb6a7 100644 --- a/common/rfb/Configuration.cxx +++ b/common/rfb/Configuration.cxx @@ -30,12 +30,13 @@ #include <ctype.h> #include <string.h> +#include <stdexcept> + #include <os/Mutex.h> #include <rfb/util.h> #include <rfb/Configuration.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> #define LOCK_CONFIG os::AutoMutex a(mutex) @@ -376,7 +377,7 @@ StringParameter::StringParameter(const char* name_, const char* desc_, { if (!v) { vlog.error("Default value <null> for %s not allowed",name_); - throw rfb::Exception("Default value <null> not allowed"); + throw std::invalid_argument("Default value <null> not allowed"); } } @@ -387,7 +388,7 @@ bool StringParameter::setParam(const char* v) { LOCK_CONFIG; if (immutable) return true; if (!v) - throw rfb::Exception("setParam(<null>) not allowed"); + throw std::invalid_argument("setParam(<null>) not allowed"); vlog.debug("set %s(String) to %s", getName(), v); value = v; return true; diff --git a/common/rfb/Cursor.cxx b/common/rfb/Cursor.cxx index fa596bc5..94844144 100644 --- a/common/rfb/Cursor.cxx +++ b/common/rfb/Cursor.cxx @@ -24,9 +24,10 @@ #include <assert.h> #include <string.h> +#include <stdexcept> + #include <rfb/Cursor.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> using namespace rfb; @@ -260,7 +261,7 @@ const uint8_t* RenderedCursor::getBuffer(const Rect& _r, int* stride) const r = _r.translate(offset.negate()); if (!r.enclosed_by(buffer.getRect())) - throw Exception("RenderedCursor: Invalid area requested"); + throw std::out_of_range("RenderedCursor: Invalid area requested"); return buffer.getBuffer(r, stride); } diff --git a/common/rfb/DecodeManager.cxx b/common/rfb/DecodeManager.cxx index 6000063f..2b121ebe 100644 --- a/common/rfb/DecodeManager.cxx +++ b/common/rfb/DecodeManager.cxx @@ -149,7 +149,7 @@ bool DecodeManager::decodeRect(const Rect& r, int encoding, if (!decoder->readRect(r, conn->getInStream(), conn->server, bufferStream)) return false; } catch (std::exception& e) { - throw Exception(format("Error reading rect: %s", e.what())); + throw std::runtime_error(format("Error reading rect: %s", e.what())); } stats[encoding].rects++; @@ -250,7 +250,7 @@ void DecodeManager::setThreadException(const std::exception& e) if (threadException != nullptr) return; - threadException = new rdr::Exception(format("Exception on worker thread: %s", e.what())); + threadException = new std::runtime_error(format("Exception on worker thread: %s", e.what())); } void DecodeManager::throwThreadException() diff --git a/common/rfb/EncodeManager.cxx b/common/rfb/EncodeManager.cxx index 5c1429d2..4526c0b3 100644 --- a/common/rfb/EncodeManager.cxx +++ b/common/rfb/EncodeManager.cxx @@ -32,7 +32,6 @@ #include <rfb/SMsgWriter.h> #include <rfb/UpdateTracker.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> #include <rfb/util.h> #include <rfb/RawEncoder.h> @@ -1055,7 +1054,7 @@ void EncodeManager::OffsetPixelBuffer::update(const PixelFormat& pf, uint8_t* EncodeManager::OffsetPixelBuffer::getBufferRW(const Rect& /*r*/, int* /*stride*/) { - throw rfb::Exception("Invalid write attempt to OffsetPixelBuffer"); + throw std::logic_error("Invalid write attempt to OffsetPixelBuffer"); } template<class T> diff --git a/common/rfb/H264Decoder.cxx b/common/rfb/H264Decoder.cxx index 3178a17b..89850ba4 100644 --- a/common/rfb/H264Decoder.cxx +++ b/common/rfb/H264Decoder.cxx @@ -30,7 +30,6 @@ #include <rdr/InStream.h> #include <rdr/OutStream.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> #include <rfb/H264Decoder.h> #include <rfb/H264DecoderContext.h> @@ -128,12 +127,12 @@ void H264Decoder::decodeRect(const Rect& r, const uint8_t* buffer, } ctx = H264DecoderContext::createContext(r); if (!ctx) - throw Exception("H264Decoder: Context not be created"); + throw std::runtime_error("H264Decoder: Context not be created"); contexts.push_back(ctx); } if (!ctx->isReady()) - throw Exception("H264Decoder: Context is not ready"); + throw std::runtime_error("H264Decoder: Context is not ready"); if (reset & resetContext) ctx->reset(); diff --git a/common/rfb/H264DecoderContext.cxx b/common/rfb/H264DecoderContext.cxx index 87ac0d85..b2054554 100644 --- a/common/rfb/H264DecoderContext.cxx +++ b/common/rfb/H264DecoderContext.cxx @@ -22,8 +22,9 @@ #include <config.h> #endif +#include <stdexcept> + #include <os/Mutex.h> -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include <rfb/H264DecoderContext.h> @@ -45,7 +46,7 @@ H264DecoderContext *H264DecoderContext::createContext(const Rect &r) H264DecoderContext *ret = new H264DecoderContextType(r); if (!ret->initCodec()) { - throw Exception("H264DecoderContext: Unable to create context"); + throw std::runtime_error("H264DecoderContext: Unable to create context"); } return ret; diff --git a/common/rfb/H264LibavDecoderContext.cxx b/common/rfb/H264LibavDecoderContext.cxx index fa2f367b..2d8d03e7 100644 --- a/common/rfb/H264LibavDecoderContext.cxx +++ b/common/rfb/H264LibavDecoderContext.cxx @@ -33,7 +33,6 @@ extern "C" { #define FFMPEG_INIT_PACKET_DEPRECATED #endif -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include <rfb/PixelBuffer.h> #include <rfb/H264LibavDecoderContext.h> @@ -118,7 +117,7 @@ uint8_t* H264LibavDecoderContext::makeH264WorkBuffer(const uint8_t* buffer, uint { h264WorkBuffer = (uint8_t*)realloc(h264WorkBuffer, reserve_len); if (h264WorkBuffer == nullptr) { - throw Exception("H264LibavDecoderContext: Unable to allocate memory"); + throw std::bad_alloc(); } h264WorkBufferLength = reserve_len; } diff --git a/common/rfb/Hostname.h b/common/rfb/Hostname.h index f6a11a60..de4a330e 100644 --- a/common/rfb/Hostname.h +++ b/common/rfb/Hostname.h @@ -23,7 +23,9 @@ #include <ctype.h> #include <stdlib.h> #include <string.h> -#include <rdr/Exception.h> + +#include <stdexcept> + #include <rfb/util.h> namespace rfb { @@ -47,7 +49,7 @@ namespace rfb { const char* portStart; if (hi == nullptr) - throw rdr::Exception("NULL host specified"); + throw std::invalid_argument("NULL host specified"); // Trim leading whitespace while(isspace(*hi)) @@ -60,7 +62,7 @@ namespace rfb { hostStart = &hi[1]; hostEnd = strchr(hostStart, ']'); if (hostEnd == nullptr) - throw rdr::Exception("unmatched [ in host"); + throw std::invalid_argument("unmatched [ in host"); portStart = hostEnd + 1; if (isAllSpace(portStart)) @@ -99,14 +101,14 @@ namespace rfb { char* end; if (portStart[0] != ':') - throw rdr::Exception("invalid port specified"); + throw std::invalid_argument("invalid port specified"); if (portStart[1] != ':') *port = strtol(portStart + 1, &end, 10); else *port = strtol(portStart + 2, &end, 10); if (*end != '\0' && ! isAllSpace(end)) - throw rdr::Exception("invalid port specified"); + throw std::invalid_argument("invalid port specified"); if ((portStart[1] != ':') && (*port < 100)) *port += basePort; diff --git a/common/rfb/JpegCompressor.cxx b/common/rfb/JpegCompressor.cxx index 49ed4b61..67a86cd9 100644 --- a/common/rfb/JpegCompressor.cxx +++ b/common/rfb/JpegCompressor.cxx @@ -22,8 +22,9 @@ #include <config.h> #endif +#include <stdexcept> + #include <rfb/JpegCompressor.h> -#include <rdr/Exception.h> #include <rfb/Rect.h> #include <rfb/PixelFormat.h> #include <rfb/ClientParams.h> @@ -127,7 +128,7 @@ JpegCompressor::JpegCompressor(int bufferLen) : MemOutStream(bufferLen) if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error - throw rdr::Exception(err->lastError); + throw std::runtime_error(err->lastError); } jpeg_create_compress(cinfo); @@ -171,7 +172,7 @@ void JpegCompressor::compress(const uint8_t *buf, volatile int stride, jpeg_abort_compress(cinfo); if (srcBufIsTemp && srcBuf) delete[] srcBuf; if (rowPointer) delete[] rowPointer; - throw rdr::Exception(err->lastError); + throw std::runtime_error(err->lastError); } cinfo->image_width = w; @@ -256,5 +257,5 @@ void JpegCompressor::compress(const uint8_t *buf, volatile int stride, void JpegCompressor::writeBytes(const uint8_t* /*data*/, int /*length*/) { - throw rdr::Exception("writeBytes() is not valid with a JpegCompressor instance. Use compress() instead."); + throw std::logic_error("writeBytes() is not valid with a JpegCompressor instance. Use compress() instead."); } diff --git a/common/rfb/JpegDecompressor.cxx b/common/rfb/JpegDecompressor.cxx index 4b3b4db7..9406b43d 100644 --- a/common/rfb/JpegDecompressor.cxx +++ b/common/rfb/JpegDecompressor.cxx @@ -120,7 +120,7 @@ JpegDecompressor::JpegDecompressor(void) if(setjmp(err->jmpBuffer)) { // this will execute if libjpeg has an error - throw rdr::Exception(err->lastError); + throw std::runtime_error(err->lastError); } jpeg_create_decompress(dinfo); @@ -168,7 +168,7 @@ void JpegDecompressor::decompress(const uint8_t *jpegBuf, jpeg_abort_decompress(dinfo); if (dstBufIsTemp && dstBuf) delete[] dstBuf; if (rowPointer) delete[] rowPointer; - throw rdr::Exception(err->lastError); + throw std::runtime_error(err->lastError); } src->pub.next_input_byte = jpegBuf; diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index ca2a5845..5590c214 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -28,7 +28,8 @@ #include <string.h> -#include <rfb/Exception.h> +#include <stdexcept> + #include <rfb/LogWriter.h> #include <rfb/PixelBuffer.h> #include <rfb/util.h> @@ -71,10 +72,10 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) const const uint8_t* end; if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); data = getBuffer(r, &inStride); @@ -108,10 +109,10 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, } if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); if (stride == 0) stride = r.width(); @@ -125,9 +126,9 @@ void PixelBuffer::getImage(const PixelFormat& pf, void* imageBuf, void PixelBuffer::setSize(int width, int height) { if ((width < 0) || (width > maxPixelBufferWidth)) - throw rfb::Exception(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); + throw std::out_of_range(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); if ((height < 0) || (height > maxPixelBufferHeight)) - throw rfb::Exception(rfb::format("Invalid PixelBuffer height of %d pixels requested", height)); + throw std::out_of_range(rfb::format("Invalid PixelBuffer height of %d pixels requested", height)); width_ = width; height_ = height; @@ -156,10 +157,10 @@ void ModifiablePixelBuffer::fillRect(const Rect& r, const void* pix) int w, h, b; if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); w = r.width(); h = r.height(); @@ -208,10 +209,10 @@ void ModifiablePixelBuffer::imageRect(const Rect& r, uint8_t* end; if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); bytesPerPixel = getPF().bpp/8; @@ -248,17 +249,17 @@ void ModifiablePixelBuffer::copyRect(const Rect &rect, drect = rect; if (!drect.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - drect.width(), drect.height(), - drect.tl.x, drect.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + drect.width(), drect.height(), + drect.tl.x, drect.tl.y, + width(), height())); srect = drect.translate(move_by_delta.negate()); if (!srect.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", - srect.width(), srect.height(), - srect.tl.x, srect.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Source rect %dx%d at %d,%d exceeds framebuffer %dx%d", + srect.width(), srect.height(), + srect.tl.x, srect.tl.y, + width(), height())); bytesPerPixel = format.bpp/8; @@ -311,10 +312,10 @@ void ModifiablePixelBuffer::imageRect(const PixelFormat& pf, const Rect &dest, int dstStride; if (!dest.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", - dest.width(), dest.height(), - dest.tl.x, dest.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Destination rect %dx%d at %d,%d exceeds framebuffer %dx%d", + dest.width(), dest.height(), + dest.tl.x, dest.tl.y, + width(), height())); if (stride == 0) stride = dest.width(); @@ -341,10 +342,10 @@ FullFramePixelBuffer::~FullFramePixelBuffer() {} uint8_t* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) { if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); *stride_ = stride; return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)]; @@ -357,10 +358,10 @@ void FullFramePixelBuffer::commitBufferRW(const Rect& /*r*/) const uint8_t* FullFramePixelBuffer::getBuffer(const Rect& r, int* stride_) const { if (!r.enclosed_by(getRect())) - throw rfb::Exception(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", - r.width(), r.height(), - r.tl.x, r.tl.y, - width(), height())); + throw std::out_of_range(rfb::format("Pixel buffer request %dx%d at %d,%d exceeds framebuffer %dx%d", + r.width(), r.height(), + r.tl.x, r.tl.y, + width(), height())); *stride_ = stride; return &data[(r.tl.x + (r.tl.y * stride)) * (format.bpp/8)]; @@ -370,13 +371,13 @@ void FullFramePixelBuffer::setBuffer(int width, int height, uint8_t* data_, int stride_) { if ((width < 0) || (width > maxPixelBufferWidth)) - throw rfb::Exception(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); + throw std::out_of_range(rfb::format("Invalid PixelBuffer width of %d pixels requested", width)); if ((height < 0) || (height > maxPixelBufferHeight)) - throw rfb::Exception(rfb::format("Invalid PixelBuffer height of %d pixels requested", height)); + throw std::out_of_range(rfb::format("Invalid PixelBuffer height of %d pixels requested", height)); if ((stride_ < 0) || (stride_ > maxPixelBufferStride) || (stride_ < width)) - throw rfb::Exception(rfb::format("Invalid PixelBuffer stride of %d pixels requested", stride_)); + throw std::invalid_argument(rfb::format("Invalid PixelBuffer stride of %d pixels requested", stride_)); if ((width != 0) && (height != 0) && (data_ == nullptr)) - throw rfb::Exception(rfb::format("PixelBuffer requested without a valid memory area")); + throw std::logic_error(rfb::format("PixelBuffer requested without a valid memory area")); ModifiablePixelBuffer::setSize(width, height); stride = stride_; @@ -386,7 +387,7 @@ void FullFramePixelBuffer::setBuffer(int width, int height, void FullFramePixelBuffer::setSize(int /*w*/, int /*h*/) { // setBuffer() should be used - throw rfb::Exception("Invalid call to FullFramePixelBuffer::setSize()"); + throw std::logic_error("Invalid call to FullFramePixelBuffer::setSize()"); } // -=- Managed pixel buffer class diff --git a/common/rfb/PixelFormat.cxx b/common/rfb/PixelFormat.cxx index b90fc206..f883cbf5 100644 --- a/common/rfb/PixelFormat.cxx +++ b/common/rfb/PixelFormat.cxx @@ -86,7 +86,7 @@ PixelFormat::PixelFormat(int b, int d, bool e, bool t, redShift(rs), greenShift(gs), blueShift(bs) { if (!isSane()) - throw Exception("invalid pixel format"); + throw std::invalid_argument("invalid pixel format"); updateState(); } diff --git a/common/rfb/SConnection.cxx b/common/rfb/SConnection.cxx index c43ed493..cf9dde05 100644 --- a/common/rfb/SConnection.cxx +++ b/common/rfb/SConnection.cxx @@ -95,14 +95,14 @@ bool SConnection::processMsg() case RFBSTATE_INITIALISATION: return processInitMsg(); break; case RFBSTATE_NORMAL: return reader_->readMsg(); break; case RFBSTATE_QUERYING: - throw Exception("SConnection::processMsg: bogus data from client while " - "querying"); + throw std::logic_error("SConnection::processMsg: bogus data from " + "client while querying"); case RFBSTATE_CLOSING: - throw Exception("SConnection::processMsg: called while closing"); + throw std::logic_error("SConnection::processMsg: called while closing"); case RFBSTATE_UNINITIALISED: - throw Exception("SConnection::processMsg: not initialised yet?"); + throw std::logic_error("SConnection::processMsg: not initialised yet?"); default: - throw Exception("SConnection::processMsg: invalid state"); + throw std::logic_error("SConnection::processMsg: invalid state"); } } @@ -336,7 +336,7 @@ void SConnection::setAccessRights(AccessRights ar) bool SConnection::accessCheck(AccessRights ar) const { if (state_ < RFBSTATE_QUERYING) - throw Exception("SConnection::accessCheck: invalid state"); + throw std::logic_error("SConnection::accessCheck: invalid state"); return (accessRights & ar) == ar; } @@ -449,7 +449,7 @@ void SConnection::queryConnection(const char* /*userName*/) void SConnection::approveConnection(bool accept, const char* reason) { if (state_ != RFBSTATE_QUERYING) - throw Exception("SConnection::approveConnection: invalid state"); + throw std::logic_error("SConnection::approveConnection: invalid state"); if (!client.beforeVersion(3,8) || ssecurity->getType() != secTypeNone) { if (accept) { diff --git a/common/rfb/SMsgWriter.cxx b/common/rfb/SMsgWriter.cxx index 0c03b51d..f525d25a 100644 --- a/common/rfb/SMsgWriter.cxx +++ b/common/rfb/SMsgWriter.cxx @@ -31,7 +31,6 @@ #include <rfb/msgTypes.h> #include <rfb/fenceTypes.h> #include <rfb/clipboardTypes.h> -#include <rfb/Exception.h> #include <rfb/ClientParams.h> #include <rfb/UpdateTracker.h> #include <rfb/Encoder.h> @@ -94,7 +93,7 @@ void SMsgWriter::writeBell() void SMsgWriter::writeServerCutText(const char* str) { if (strchr(str, '\r') != nullptr) - throw Exception("Invalid carriage return in clipboard data"); + throw std::invalid_argument("Invalid carriage return in clipboard data"); std::string latin1(utf8ToLatin1(str)); @@ -111,7 +110,7 @@ void SMsgWriter::writeClipboardCaps(uint32_t caps, size_t i, count; if (!client->supportsEncoding(pseudoEncodingExtendedClipboard)) - throw Exception("Client does not support extended clipboard"); + throw std::logic_error("Client does not support extended clipboard"); count = 0; for (i = 0;i < 16;i++) { @@ -137,9 +136,9 @@ void SMsgWriter::writeClipboardCaps(uint32_t caps, void SMsgWriter::writeClipboardRequest(uint32_t flags) { if (!client->supportsEncoding(pseudoEncodingExtendedClipboard)) - throw Exception("Client does not support extended clipboard"); + throw std::logic_error("Client does not support extended clipboard"); if (!(client->clipboardFlags() & clipboardRequest)) - throw Exception("Client does not support clipboard \"request\" action"); + throw std::logic_error("Client does not support clipboard \"request\" action"); startMsg(msgTypeServerCutText); os->pad(3); @@ -151,9 +150,9 @@ void SMsgWriter::writeClipboardRequest(uint32_t flags) void SMsgWriter::writeClipboardPeek(uint32_t flags) { if (!client->supportsEncoding(pseudoEncodingExtendedClipboard)) - throw Exception("Client does not support extended clipboard"); + throw std::logic_error("Client does not support extended clipboard"); if (!(client->clipboardFlags() & clipboardPeek)) - throw Exception("Client does not support clipboard \"peek\" action"); + throw std::logic_error("Client does not support clipboard \"peek\" action"); startMsg(msgTypeServerCutText); os->pad(3); @@ -165,9 +164,9 @@ void SMsgWriter::writeClipboardPeek(uint32_t flags) void SMsgWriter::writeClipboardNotify(uint32_t flags) { if (!client->supportsEncoding(pseudoEncodingExtendedClipboard)) - throw Exception("Client does not support extended clipboard"); + throw std::logic_error("Client does not support extended clipboard"); if (!(client->clipboardFlags() & clipboardNotify)) - throw Exception("Client does not support clipboard \"notify\" action"); + throw std::logic_error("Client does not support clipboard \"notify\" action"); startMsg(msgTypeServerCutText); os->pad(3); @@ -186,9 +185,9 @@ void SMsgWriter::writeClipboardProvide(uint32_t flags, int i, count; if (!client->supportsEncoding(pseudoEncodingExtendedClipboard)) - throw Exception("Client does not support extended clipboard"); + throw std::logic_error("Client does not support extended clipboard"); if (!(client->clipboardFlags() & clipboardProvide)) - throw Exception("Client does not support clipboard \"provide\" action"); + throw std::logic_error("Client does not support clipboard \"provide\" action"); zos.setUnderlying(&mos); @@ -215,11 +214,11 @@ void SMsgWriter::writeFence(uint32_t flags, unsigned len, const uint8_t data[]) { if (!client->supportsEncoding(pseudoEncodingFence)) - throw Exception("Client does not support fences"); + throw std::logic_error("Client does not support fences"); if (len > 64) - throw Exception("Too large fence payload"); + throw std::out_of_range("Too large fence payload"); if ((flags & ~fenceFlagsSupported) != 0) - throw Exception("Unknown fence flags"); + throw std::invalid_argument("Unknown fence flags"); startMsg(msgTypeServerFence); os->pad(3); @@ -237,7 +236,7 @@ void SMsgWriter::writeFence(uint32_t flags, unsigned len, void SMsgWriter::writeEndOfContinuousUpdates() { if (!client->supportsEncoding(pseudoEncodingContinuousUpdates)) - throw Exception("Client does not support continuous updates"); + throw std::logic_error("Client does not support continuous updates"); startMsg(msgTypeEndOfContinuousUpdates); endMsg(); @@ -249,7 +248,7 @@ void SMsgWriter::writeDesktopSize(uint16_t reason, uint16_t result) if (!client->supportsEncoding(pseudoEncodingDesktopSize) && !client->supportsEncoding(pseudoEncodingExtendedDesktopSize)) - throw Exception("Client does not support desktop size changes"); + throw std::logic_error("Client does not support desktop size changes"); msg.reason = reason; msg.result = result; @@ -260,7 +259,7 @@ void SMsgWriter::writeDesktopSize(uint16_t reason, uint16_t result) void SMsgWriter::writeSetDesktopName() { if (!client->supportsEncoding(pseudoEncodingDesktopName)) - throw Exception("Client does not support desktop name changes"); + throw std::logic_error("Client does not support desktop name changes"); needSetDesktopName = true; } @@ -271,7 +270,7 @@ void SMsgWriter::writeCursor() !client->supportsEncoding(pseudoEncodingXCursor) && !client->supportsEncoding(pseudoEncodingCursorWithAlpha) && !client->supportsEncoding(pseudoEncodingVMwareCursor)) - throw Exception("Client does not support local cursor"); + throw std::logic_error("Client does not support local cursor"); needCursor = true; } @@ -279,7 +278,7 @@ void SMsgWriter::writeCursor() void SMsgWriter::writeCursorPos() { if (!client->supportsEncoding(pseudoEncodingVMwareCursorPosition)) - throw Exception("Client does not support cursor position"); + throw std::logic_error("Client does not support cursor position"); needCursorPos = true; } @@ -288,9 +287,9 @@ void SMsgWriter::writeLEDState() { if (!client->supportsEncoding(pseudoEncodingLEDState) && !client->supportsEncoding(pseudoEncodingVMwareLEDState)) - throw Exception("Client does not support LED state"); + throw std::logic_error("Client does not support LED state"); if (client->ledState() == ledUnknown) - throw Exception("Server has not specified LED state"); + throw std::logic_error("Server has not specified LED state"); needLEDState = true; } @@ -298,7 +297,7 @@ void SMsgWriter::writeLEDState() void SMsgWriter::writeQEMUKeyEvent() { if (!client->supportsEncoding(pseudoEncodingQEMUKeyEvent)) - throw Exception("Client does not support QEMU key events"); + throw std::logic_error("Client does not support QEMU key events"); needQEMUKeyEvent = true; } @@ -379,8 +378,8 @@ void SMsgWriter::writeFramebufferUpdateStart(int nRects) void SMsgWriter::writeFramebufferUpdateEnd() { if (nRectsInUpdate != nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeFramebufferUpdateEnd: " - "nRects out of sync"); + throw std::logic_error("SMsgWriter::writeFramebufferUpdateEnd: " + "nRects out of sync"); if (nRectsInHeader == 0) { // Send last rect. marker @@ -405,7 +404,7 @@ void SMsgWriter::writeCopyRect(const Rect& r, int srcX, int srcY) void SMsgWriter::startRect(const Rect& r, int encoding) { if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::startRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::startRect: nRects out of sync"); os->writeS16(r.tl.x); os->writeS16(r.tl.y); @@ -470,7 +469,7 @@ void SMsgWriter::writePseudoRects() cursor.hotspot().x, cursor.hotspot().y, bitmap.data(), mask.data()); } else { - throw Exception("Client does not support local cursor"); + throw std::logic_error("Client does not support local cursor"); } needCursor = false; @@ -482,7 +481,7 @@ void SMsgWriter::writePseudoRects() if (client->supportsEncoding(pseudoEncodingVMwareCursorPosition)) { writeSetVMwareCursorPositionRect(cursorPos.x, cursorPos.y); } else { - throw Exception("Client does not support cursor position"); + throw std::logic_error("Client does not support cursor position"); } needCursorPos = false; @@ -519,7 +518,7 @@ void SMsgWriter::writeNoDataRects() // more after this writeSetDesktopSizeRect(client->width(), client->height()); } else { - throw Exception("Client does not support desktop size changes"); + throw std::logic_error("Client does not support desktop size changes"); } extendedDesktopSizeMsgs.clear(); @@ -529,9 +528,9 @@ void SMsgWriter::writeNoDataRects() void SMsgWriter::writeSetDesktopSizeRect(int width, int height) { if (!client->supportsEncoding(pseudoEncodingDesktopSize)) - throw Exception("Client does not support desktop resize"); + throw std::logic_error("Client does not support desktop resize"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetDesktopSizeRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetDesktopSizeRect: nRects out of sync"); os->writeS16(0); os->writeS16(0); @@ -549,9 +548,9 @@ void SMsgWriter::writeExtendedDesktopSizeRect(uint16_t reason, ScreenSet::const_iterator si; if (!client->supportsEncoding(pseudoEncodingExtendedDesktopSize)) - throw Exception("Client does not support extended desktop resize"); + throw std::logic_error("Client does not support extended desktop resize"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeExtendedDesktopSizeRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeExtendedDesktopSizeRect: nRects out of sync"); os->writeU16(reason); os->writeU16(result); @@ -575,9 +574,9 @@ void SMsgWriter::writeExtendedDesktopSizeRect(uint16_t reason, void SMsgWriter::writeSetDesktopNameRect(const char *name) { if (!client->supportsEncoding(pseudoEncodingDesktopName)) - throw Exception("Client does not support desktop rename"); + throw std::logic_error("Client does not support desktop rename"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetDesktopNameRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetDesktopNameRect: nRects out of sync"); os->writeS16(0); os->writeS16(0); @@ -594,9 +593,9 @@ void SMsgWriter::writeSetCursorRect(int width, int height, const uint8_t* mask) { if (!client->supportsEncoding(pseudoEncodingCursor)) - throw Exception("Client does not support local cursors"); + throw std::logic_error("Client does not support local cursors"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetCursorRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetCursorRect: nRects out of sync"); os->writeS16(hotspotX); os->writeS16(hotspotY); @@ -613,9 +612,9 @@ void SMsgWriter::writeSetXCursorRect(int width, int height, const uint8_t* mask) { if (!client->supportsEncoding(pseudoEncodingXCursor)) - throw Exception("Client does not support local cursors"); + throw std::logic_error("Client does not support local cursors"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetXCursorRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetXCursorRect: nRects out of sync"); os->writeS16(hotspotX); os->writeS16(hotspotY); @@ -639,9 +638,9 @@ void SMsgWriter::writeSetCursorWithAlphaRect(int width, int height, const uint8_t* data) { if (!client->supportsEncoding(pseudoEncodingCursorWithAlpha)) - throw Exception("Client does not support local cursors"); + throw std::logic_error("Client does not support local cursors"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetCursorWithAlphaRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetCursorWithAlphaRect: nRects out of sync"); os->writeS16(hotspotX); os->writeS16(hotspotY); @@ -667,9 +666,9 @@ void SMsgWriter::writeSetVMwareCursorRect(int width, int height, const uint8_t* data) { if (!client->supportsEncoding(pseudoEncodingVMwareCursor)) - throw Exception("Client does not support local cursors"); + throw std::logic_error("Client does not support local cursors"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync"); os->writeS16(hotspotX); os->writeS16(hotspotY); @@ -687,9 +686,9 @@ void SMsgWriter::writeSetVMwareCursorRect(int width, int height, void SMsgWriter::writeSetVMwareCursorPositionRect(int hotspotX, int hotspotY) { if (!client->supportsEncoding(pseudoEncodingVMwareCursorPosition)) - throw Exception("Client does not support cursor position"); + throw std::logic_error("Client does not support cursor position"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeSetVMwareCursorRect: nRects out of sync"); os->writeS16(hotspotX); os->writeS16(hotspotY); @@ -702,11 +701,11 @@ void SMsgWriter::writeLEDStateRect(uint8_t state) { if (!client->supportsEncoding(pseudoEncodingLEDState) && !client->supportsEncoding(pseudoEncodingVMwareLEDState)) - throw Exception("Client does not support LED state updates"); + throw std::logic_error("Client does not support LED state updates"); if (client->ledState() == ledUnknown) - throw Exception("Server does not support LED state updates"); + throw std::logic_error("Server does not support LED state updates"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeLEDStateRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeLEDStateRect: nRects out of sync"); os->writeS16(0); os->writeS16(0); @@ -724,9 +723,9 @@ void SMsgWriter::writeLEDStateRect(uint8_t state) void SMsgWriter::writeQEMUKeyEventRect() { if (!client->supportsEncoding(pseudoEncodingQEMUKeyEvent)) - throw Exception("Client does not support QEMU extended key events"); + throw std::logic_error("Client does not support QEMU extended key events"); if (++nRectsInUpdate > nRectsInHeader && nRectsInHeader) - throw Exception("SMsgWriter::writeQEMUKeyEventRect: nRects out of sync"); + throw std::logic_error("SMsgWriter::writeQEMUKeyEventRect: nRects out of sync"); os->writeS16(0); os->writeS16(0); diff --git a/common/rfb/SSecurityPlain.cxx b/common/rfb/SSecurityPlain.cxx index e009de39..1115b7ff 100644 --- a/common/rfb/SSecurityPlain.cxx +++ b/common/rfb/SSecurityPlain.cxx @@ -87,7 +87,7 @@ bool SSecurityPlain::processMsg() char password[1024]; if (!valid) - throw Exception("No password validator configured"); + throw std::logic_error("No password validator configured"); if (state == 0) { if (!is->hasData(8)) diff --git a/common/rfb/SSecurityRSAAES.cxx b/common/rfb/SSecurityRSAAES.cxx index 6dd700ce..10e901fb 100644 --- a/common/rfb/SSecurityRSAAES.cxx +++ b/common/rfb/SSecurityRSAAES.cxx @@ -161,7 +161,7 @@ void SSecurityRSAAES::loadPrivateKey() size_t size = ftell(file); if (size == 0 || size > MaxKeyFileSize) { fclose(file); - throw Exception("size of key file is zero or too big"); + throw std::runtime_error("size of key file is zero or too big"); } fseek(file, 0, SEEK_SET); std::vector<uint8_t> data(size); @@ -184,7 +184,7 @@ void SSecurityRSAAES::loadPrivateKey() loadPKCS8Key(der.data(), der.size()); return; } - throw Exception("failed to import key"); + throw std::runtime_error("failed to import key"); } void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) @@ -195,7 +195,7 @@ void SSecurityRSAAES::loadPKCS1Key(const uint8_t* data, size_t size) if (!rsa_keypair_from_der(&pub, &serverKey, 0, size, data)) { rsa_private_key_clear(&serverKey); rsa_public_key_clear(&pub); - throw Exception("failed to import key"); + throw std::runtime_error("failed to import key"); } serverKeyLength = serverKey.size * 8; serverKeyN = new uint8_t[serverKey.size]; @@ -235,7 +235,7 @@ void SSecurityRSAAES::loadPKCS8Key(const uint8_t* data, size_t size) loadPKCS1Key(i.data, i.length); return; failed: - throw Exception("failed to import key"); + throw std::runtime_error("failed to import key"); } bool SSecurityRSAAES::processMsg() @@ -319,7 +319,7 @@ static void random_func(void* ctx, size_t length, uint8_t* dst) { rdr::RandomStream* rs = (rdr::RandomStream*)ctx; if (!rs->hasData(length)) - throw Exception("failed to encrypt random"); + throw std::runtime_error("failed to encrypt random"); rs->readBytes(dst, length); } @@ -327,7 +327,7 @@ void SSecurityRSAAES::writeRandom() { rdr::OutStream* os = sc->getOutStream(); if (!rs.hasData(keySize / 8)) - throw Exception("failed to generate random"); + throw std::runtime_error("failed to generate random"); rs.readBytes(serverRandom, keySize / 8); mpz_t x; mpz_init(x); @@ -341,7 +341,7 @@ void SSecurityRSAAES::writeRandom() } if (!res) { mpz_clear(x); - throw Exception("failed to encrypt random"); + throw std::runtime_error("failed to encrypt random"); } uint8_t* buffer = new uint8_t[clientKey.size]; nettle_mpz_get_str_256(clientKey.size, buffer, x); @@ -566,7 +566,7 @@ void SSecurityRSAAES::verifyUserPass() } delete valid; #else - throw Exception("No password validator configured"); + throw std::logic_error("No password validator configured"); #endif } @@ -577,7 +577,7 @@ void SSecurityRSAAES::verifyPass() pg->getVncAuthPasswd(&passwd, &passwdReadOnly); if (passwd.empty()) - throw Exception("No password configured"); + throw std::runtime_error("No password configured"); if (password == passwd) { accessRights = AccessDefault; diff --git a/common/rfb/SSecurityVncAuth.cxx b/common/rfb/SSecurityVncAuth.cxx index 272c7ca1..b0401840 100644 --- a/common/rfb/SSecurityVncAuth.cxx +++ b/common/rfb/SSecurityVncAuth.cxx @@ -83,7 +83,7 @@ bool SSecurityVncAuth::processMsg() if (!sentChallenge) { rdr::RandomStream rs; if (!rs.hasData(vncAuthChallengeSize)) - throw Exception("Could not generate random data for VNC auth challenge"); + throw std::runtime_error("Could not generate random data for VNC auth challenge"); rs.readBytes(challenge, vncAuthChallengeSize); os->writeBytes(challenge, vncAuthChallengeSize); os->flush(); @@ -100,7 +100,7 @@ bool SSecurityVncAuth::processMsg() pg->getVncAuthPasswd(&passwd, &passwdReadOnly); if (passwd.empty()) - throw Exception("No password configured"); + throw std::runtime_error("No password configured"); if (verifyResponse(passwd.c_str())) { accessRights = AccessDefault; diff --git a/common/rfb/SecurityClient.cxx b/common/rfb/SecurityClient.cxx index 9cd3b904..878edde9 100644 --- a/common/rfb/SecurityClient.cxx +++ b/common/rfb/SecurityClient.cxx @@ -27,7 +27,6 @@ #include <rfb/CSecurityVeNCrypt.h> #include <rfb/CSecurityVncAuth.h> #include <rfb/CSecurityPlain.h> -#include <rfb/Exception.h> #include <rfb/Security.h> #ifdef HAVE_GNUTLS #include <rfb/CSecurityTLS.h> @@ -110,5 +109,5 @@ CSecurity* SecurityClient::GetCSecurity(CConnection* cc, uint32_t secType) } bail: - throw Exception("Security type not supported"); + throw std::invalid_argument("Security type not supported"); } diff --git a/common/rfb/SecurityServer.cxx b/common/rfb/SecurityServer.cxx index b5297736..d692f4fc 100644 --- a/common/rfb/SecurityServer.cxx +++ b/common/rfb/SecurityServer.cxx @@ -21,7 +21,6 @@ #include <config.h> #endif -#include <rfb/Exception.h> #include <rfb/Security.h> #include <rfb/SSecurityNone.h> #include <rfb/SSecurityStack.h> @@ -90,6 +89,6 @@ SSecurity* SecurityServer::GetSSecurity(SConnection* sc, uint32_t secType) } bail: - throw Exception("Security type not supported"); + throw std::invalid_argument("Security type not supported"); } diff --git a/common/rfb/ServerParams.cxx b/common/rfb/ServerParams.cxx index 2a8d3a8e..df8ad40d 100644 --- a/common/rfb/ServerParams.cxx +++ b/common/rfb/ServerParams.cxx @@ -22,7 +22,8 @@ #include <config.h> #endif -#include <rfb/Exception.h> +#include <stdexcept> + #include <rfb/ledStates.h> #include <rfb/ServerParams.h> #include <rfb/util.h> @@ -60,7 +61,7 @@ void ServerParams::setDimensions(int width, int height) void ServerParams::setDimensions(int width, int height, const ScreenSet& layout) { if (!layout.validate(width, height)) - throw Exception("Attempted to configure an invalid screen layout"); + throw std::invalid_argument("Attempted to configure an invalid screen layout"); width_ = width; height_ = height; @@ -72,7 +73,7 @@ void ServerParams::setPF(const PixelFormat& pf) pf_ = pf; if (pf.bpp != 8 && pf.bpp != 16 && pf.bpp != 32) - throw Exception("setPF: not 8, 16 or 32 bpp?"); + throw std::invalid_argument("setPF: not 8, 16 or 32 bpp?"); } void ServerParams::setName(const char* name) @@ -100,7 +101,7 @@ uint32_t ServerParams::clipboardSize(unsigned int format) const return clipSizes[i]; } - throw Exception(rfb::format("Invalid clipboard format 0x%x", format)); + throw std::invalid_argument(rfb::format("Invalid clipboard format 0x%x", format)); } void ServerParams::setClipboardCaps(uint32_t flags, const uint32_t* lengths) diff --git a/common/rfb/VNCServerST.cxx b/common/rfb/VNCServerST.cxx index f1ea2958..c2f47476 100644 --- a/common/rfb/VNCServerST.cxx +++ b/common/rfb/VNCServerST.cxx @@ -58,7 +58,6 @@ #include <network/Socket.h> #include <rfb/ComparingUpdateTracker.h> -#include <rfb/Exception.h> #include <rfb/KeyRemapper.h> #include <rfb/KeysymStr.h> #include <rfb/LogWriter.h> @@ -224,7 +223,7 @@ void VNCServerST::processSocketReadEvent(network::Socket* sock) return; } } - throw rdr::Exception("invalid Socket in VNCServerST"); + throw std::invalid_argument("invalid Socket in VNCServerST"); } void VNCServerST::processSocketWriteEvent(network::Socket* sock) @@ -237,7 +236,7 @@ void VNCServerST::processSocketWriteEvent(network::Socket* sock) return; } } - throw rdr::Exception("invalid Socket in VNCServerST"); + throw std::invalid_argument("invalid Socket in VNCServerST"); } void VNCServerST::blockUpdates() @@ -284,13 +283,13 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_, const ScreenSet& layout) screenLayout = ScreenSet(); if (desktopStarted) - throw Exception("setPixelBuffer: null PixelBuffer when desktopStarted?"); + throw std::logic_error("setPixelBuffer: null PixelBuffer when desktopStarted?"); return; } if (!layout.validate(pb->width(), pb->height())) - throw Exception("setPixelBuffer: invalid screen layout"); + throw std::invalid_argument("setPixelBuffer: invalid screen layout"); screenLayout = layout; @@ -342,9 +341,9 @@ void VNCServerST::setPixelBuffer(PixelBuffer* pb_) void VNCServerST::setScreenLayout(const ScreenSet& layout) { if (!pb) - throw Exception("setScreenLayout: new screen layout without a PixelBuffer"); + throw std::logic_error("setScreenLayout: new screen layout without a PixelBuffer"); if (!layout.validate(pb->width(), pb->height())) - throw Exception("setScreenLayout: invalid screen layout"); + throw std::invalid_argument("setScreenLayout: invalid screen layout"); screenLayout = layout; @@ -378,7 +377,7 @@ void VNCServerST::sendClipboardData(const char* data) std::list<VNCSConnectionST*>::iterator ci; if (strchr(data, '\r') != nullptr) - throw Exception("Invalid carriage return in clipboard data"); + throw std::invalid_argument("Invalid carriage return in clipboard data"); for (ci = clipboardRequestors.begin(); ci != clipboardRequestors.end(); ++ci) @@ -566,7 +565,7 @@ unsigned int VNCServerST::setDesktopSize(VNCSConnectionST* requester, // Sanity check if (screenLayout != layout) - throw Exception("Desktop configured a different screen layout than requested"); + throw std::runtime_error("Desktop configured a different screen layout than requested"); // Notify other clients for (ci = clients.begin(); ci != clients.end(); ++ci) { @@ -727,7 +726,7 @@ void VNCServerST::startDesktop() slog.debug("starting desktop"); desktop->start(); if (!pb) - throw Exception("SDesktop::start() did not set a valid PixelBuffer"); + throw std::logic_error("SDesktop::start() did not set a valid PixelBuffer"); desktopStarted = true; // The tracker might have accumulated changes whilst we were // stopped, so flush those out diff --git a/common/rfb/obfuscate.cxx b/common/rfb/obfuscate.cxx index 2afc1512..a88d2822 100644 --- a/common/rfb/obfuscate.cxx +++ b/common/rfb/obfuscate.cxx @@ -28,11 +28,12 @@ #include <assert.h> #include <string.h> +#include <stdexcept> + extern "C" { #include <rfb/d3des.h> } -#include <rdr/Exception.h> #include <rfb/obfuscate.h> static unsigned char d3desObfuscationKey[] = {23,82,107,6,35,78,88,7}; @@ -57,7 +58,7 @@ std::string rfb::deobfuscate(const uint8_t *data, size_t len) char buf[9]; if (len != 8) - throw rdr::Exception("bad obfuscated password length"); + throw std::invalid_argument("bad obfuscated password length"); assert(data != nullptr); diff --git a/tests/perf/decperf.cxx b/tests/perf/decperf.cxx index cc8b39d0..41a93b3a 100644 --- a/tests/perf/decperf.cxx +++ b/tests/perf/decperf.cxx @@ -110,7 +110,7 @@ void DummyOutStream::overrun(size_t needed) { flush(); if (avail() < needed) - throw rdr::Exception("Insufficient dummy output buffer"); + throw std::out_of_range("Insufficient dummy output buffer"); } CConn::CConn(const char *filename) @@ -202,7 +202,7 @@ static struct stats runTest(const char *fn) try { cc = new CConn(fn); - } catch (rdr::Exception& e) { + } catch (std::exception& e) { fprintf(stderr, "Failed to open rfb file: %s\n", e.what()); exit(1); } @@ -211,7 +211,7 @@ static struct stats runTest(const char *fn) while (true) cc->processMsg(); } catch (rdr::EndOfStream& e) { - } catch (rdr::Exception& e) { + } catch (std::exception& e) { fprintf(stderr, "Failed to run rfb file: %s\n", e.what()); exit(1); } diff --git a/tests/perf/encperf.cxx b/tests/perf/encperf.cxx index 63794340..9c7c77fd 100644 --- a/tests/perf/encperf.cxx +++ b/tests/perf/encperf.cxx @@ -171,7 +171,7 @@ void DummyOutStream::overrun(size_t needed) { flush(); if (avail() < needed) - throw rdr::Exception("Insufficient dummy output buffer"); + throw std::out_of_range("Insufficient dummy output buffer"); } CConn::CConn(const char *filename) diff --git a/tests/unit/pixelformat.cxx b/tests/unit/pixelformat.cxx index 9d86fb9f..54e68ccf 100644 --- a/tests/unit/pixelformat.cxx +++ b/tests/unit/pixelformat.cxx @@ -22,8 +22,9 @@ #include <stdio.h> +#include <stdexcept> + #include <rfb/PixelFormat.h> -#include <rfb/Exception.h> static void doTest(bool should_fail, int b, int d, bool e, bool t, int rm, int gm, int bm, int rs, int gs, int bs) diff --git a/unix/tx/TXDialog.h b/unix/tx/TXDialog.h index 3a22fd07..c663ffae 100644 --- a/unix/tx/TXDialog.h +++ b/unix/tx/TXDialog.h @@ -28,6 +28,8 @@ #ifndef __TXDIALOG_H__ #define __TXDIALOG_H__ +#include <rdr/Exception.h> + #include "TXWindow.h" #include <errno.h> diff --git a/unix/x0vncserver/XDesktop.cxx b/unix/x0vncserver/XDesktop.cxx index 9251e371..b4e795ef 100644 --- a/unix/x0vncserver/XDesktop.cxx +++ b/unix/x0vncserver/XDesktop.cxx @@ -31,7 +31,6 @@ #include <network/Socket.h> #include <rfb/LogWriter.h> -#include <rfb/Exception.h> #include <x0vncserver/XDesktop.h> @@ -98,7 +97,7 @@ XDesktop::XDesktop(Display* dpy_, Geometry *geometry_) if (!XkbQueryExtension(dpy, &xkbOpcode, &xkbEventBase, &xkbErrorBase, &major, &minor)) { vlog.error("XKEYBOARD extension not present"); - throw Exception("XKEYBOARD extension not present"); + throw std::runtime_error("XKEYBOARD extension not present"); } XkbSelectEvents(dpy, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, diff --git a/unix/xserver/hw/vnc/vncExtInit.cc b/unix/xserver/hw/vnc/vncExtInit.cc index ab4b28d3..e56e0db0 100644 --- a/unix/xserver/hw/vnc/vncExtInit.cc +++ b/unix/xserver/hw/vnc/vncExtInit.cc @@ -250,7 +250,7 @@ void vncExtensionInit(void) } if (!inetd && listeners.empty()) - throw rdr::Exception("No path or port configured for incoming connections"); + throw std::runtime_error("No path or port configured for incoming connections"); PixelFormat pf = vncGetPixelFormat(scr); 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 3de4e388..d4ec2006 100644 --- a/vncviewer/ServerDialog.cxx +++ b/vncviewer/ServerDialog.cxx @@ -346,7 +346,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); @@ -382,8 +382,11 @@ void ServerDialog::loadServerHistory() if (len == (sizeof(line) - 1)) { fclose(f); - throw Exception(format(_("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 +425,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); 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_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/Viewport.cxx b/vncviewer/Viewport.cxx index 42a5d002..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; 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 f1b5a852..de728987 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -305,16 +305,16 @@ 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) @@ -330,7 +330,7 @@ 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) @@ -347,7 +347,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; @@ -365,14 +365,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,7 +387,7 @@ 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){ @@ -407,7 +407,7 @@ 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) { @@ -465,8 +465,8 @@ static void saveToReg(const char* servername) { setKeyString("ServerName", servername, &hKey); } catch (std::exception& e) { RegCloseKey(hKey); - throw Exception(format(_("Failed to save \"%s\": %s"), - "ServerName", e.what())); + 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 +478,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 (std::exception& e) { RegCloseKey(hKey); - throw Exception(format(_("Failed to save \"%s\": %s"), - parameterArray[i]->getName(), e.what())); + throw std::runtime_error(format(_("Failed to save \"%s\": %s"), + parameterArray[i]->getName(), + e.what())); } } @@ -495,9 +496,9 @@ static void saveToReg(const char* servername) { removeValue(readOnlyParameterArray[i]->getName(), &hKey); } catch (std::exception& e) { RegCloseKey(hKey); - throw Exception(format(_("Failed to remove \"%s\": %s"), - readOnlyParameterArray[i]->getName(), - e.what())); + throw std::runtime_error(format(_("Failed to remove \"%s\": %s"), + readOnlyParameterArray[i]->getName(), + e.what())); } } @@ -570,7 +571,7 @@ 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(std::exception& e) { // Just ignore this entry and continue with the rest @@ -638,7 +639,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 { @@ -657,9 +658,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(servername, encodingBuffer, buffersize)) { fclose(f); - throw Exception(format(_("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); @@ -668,9 +669,9 @@ void saveViewerParameters(const char *filename, const char *servername) { if (!encodeValue(*(StringParameter*)param, encodingBuffer, buffersize)) { fclose(f); - throw Exception(format(_("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) { @@ -679,9 +680,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(format(_("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); @@ -700,7 +701,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; } @@ -718,7 +719,7 @@ static bool findAndSetViewerParameterFromValue( } } else { - throw Exception(_("Unknown parameter type")); + throw std::logic_error(_("Unknown parameter type")); } } @@ -744,7 +745,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 { @@ -777,8 +778,11 @@ char* loadViewerParameters(const char *filename) { if (strlen(line) == (sizeof(line) - 1)) { fclose(f); - throw Exception(format(_("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 @@ -787,8 +791,9 @@ char* loadViewerParameters(const char *filename) { continue; fclose(f); - throw Exception(format(_("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 @@ -822,7 +827,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; diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 78a44f12..df3b8964 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> @@ -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); diff --git a/win/rfb_win32/CurrentUser.cxx b/win/rfb_win32/CurrentUser.cxx index fc0f689e..2ca48dd6 100644 --- a/win/rfb_win32/CurrentUser.cxx +++ b/win/rfb_win32/CurrentUser.cxx @@ -92,7 +92,7 @@ ImpersonateCurrentUser::ImpersonateCurrentUser() { if (!isServiceProcess()) return; if (!token.canImpersonate()) - throw rdr::Exception("Cannot impersonate unsafe or null token"); + throw std::runtime_error("Cannot impersonate unsafe or null token"); if (!ImpersonateLoggedOnUser(token)) { DWORD err = GetLastError(); if (err != ERROR_CALL_NOT_IMPLEMENTED) diff --git a/win/rfb_win32/DIBSectionBuffer.cxx b/win/rfb_win32/DIBSectionBuffer.cxx index ca6f3c9a..62b917c0 100644 --- a/win/rfb_win32/DIBSectionBuffer.cxx +++ b/win/rfb_win32/DIBSectionBuffer.cxx @@ -56,7 +56,7 @@ void DIBSectionBuffer::initBuffer(const PixelFormat& pf, int w, int h) { uint8_t* new_data = nullptr; if (!pf.trueColour) - throw rfb::Exception("palette format not supported"); + throw std::invalid_argument("palette format not supported"); format = pf; @@ -158,7 +158,7 @@ void DIBSectionBuffer::initBuffer(const PixelFormat& pf, int w, int h) { bits = bits >> 1; } if (depth > bpp) - throw Exception("Bad DIBSection format (depth exceeds bpp)"); + throw std::runtime_error("Bad DIBSection format (depth exceeds bpp)"); format = PixelFormat(bpp, depth, false, true, redMax, greenMax, blueMax, diff --git a/win/rfb_win32/DeviceContext.cxx b/win/rfb_win32/DeviceContext.cxx index fa0beaf9..210bbf80 100644 --- a/win/rfb_win32/DeviceContext.cxx +++ b/win/rfb_win32/DeviceContext.cxx @@ -87,7 +87,7 @@ PixelFormat DeviceContext::getPF(HDC dc) { break; default: vlog.error("bits per pixel %u not supported", bi.bmiHeader.biBitCount); - throw rdr::Exception("unknown bits per pixel specified"); + throw std::invalid_argument("unknown bits per pixel specified"); }; break; case BI_BITFIELDS: diff --git a/win/rfb_win32/DeviceFrameBuffer.cxx b/win/rfb_win32/DeviceFrameBuffer.cxx index 752aeb4c..4da4d814 100644 --- a/win/rfb_win32/DeviceFrameBuffer.cxx +++ b/win/rfb_win32/DeviceFrameBuffer.cxx @@ -54,14 +54,14 @@ DeviceFrameBuffer::DeviceFrameBuffer(HDC deviceContext, const Rect& wRect) int capabilities = GetDeviceCaps(device, RASTERCAPS); if (!(capabilities & RC_BITBLT)) { - throw Exception("device does not support BitBlt"); + throw std::invalid_argument("device does not support BitBlt"); } if (!(capabilities & RC_DI_BITMAP)) { - throw Exception("device does not support GetDIBits"); + throw std::invalid_argument("device does not support GetDIBits"); } /* if (GetDeviceCaps(device, PLANES) != 1) { - throw Exception("device does not support planar displays"); + throw std::invalid_argument("device does not support planar displays"); } */ @@ -140,9 +140,9 @@ void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server) if (!GetObject(iconInfo.hbmMask, sizeof(BITMAP), &maskInfo)) throw rdr::Win32Exception("GetObject() failed", GetLastError()); if (maskInfo.bmPlanes != 1) - throw rdr::Exception("unsupported multi-plane cursor"); + throw std::invalid_argument("unsupported multi-plane cursor"); if (maskInfo.bmBitsPixel != 1) - throw rdr::Exception("unsupported cursor mask format"); + throw std::invalid_argument("unsupported cursor mask format"); width = maskInfo.bmWidth; height = maskInfo.bmHeight; @@ -188,7 +188,7 @@ void DeviceFrameBuffer::setCursor(HCURSOR hCursor, VNCServer* server) if ((bi.bV5RedMask != ((unsigned)0xff << ridx*8)) || (bi.bV5GreenMask != ((unsigned)0xff << gidx*8)) || (bi.bV5BlueMask != ((unsigned)0xff << bidx*8))) - throw rdr::Exception("unsupported cursor colour format"); + throw std::invalid_argument("unsupported cursor colour format"); uint8_t* rwbuffer = buffer.data(); for (int y = 0; y < height; y++) { diff --git a/win/rfb_win32/Dialog.cxx b/win/rfb_win32/Dialog.cxx index 3fcb96f7..d5938e8d 100644 --- a/win/rfb_win32/Dialog.cxx +++ b/win/rfb_win32/Dialog.cxx @@ -78,7 +78,7 @@ int Dialog::getItemInt(int id) { BOOL trans; int result = GetDlgItemInt(handle, id, &trans, TRUE); if (!trans) - throw rdr::Exception("unable to read dialog Int"); + throw std::runtime_error("unable to read dialog Int"); return result; } const char* Dialog::getItemString(int id) { diff --git a/win/rfb_win32/EventManager.cxx b/win/rfb_win32/EventManager.cxx index f034d36d..995c4fe2 100644 --- a/win/rfb_win32/EventManager.cxx +++ b/win/rfb_win32/EventManager.cxx @@ -22,8 +22,9 @@ #include <windows.h> +#include <stdexcept> + #include <rfb_win32/EventManager.h> -#include <rdr/Exception.h> #include <rfb/LogWriter.h> using namespace rfb; @@ -59,7 +60,7 @@ void EventManager::removeEvent(HANDLE event) { return; } } - throw rdr::Exception("Event not registered"); + throw std::runtime_error("Event not registered"); } diff --git a/win/rfb_win32/Registry.cxx b/win/rfb_win32/Registry.cxx index 15b25776..54de8928 100644 --- a/win/rfb_win32/Registry.cxx +++ b/win/rfb_win32/Registry.cxx @@ -247,14 +247,14 @@ std::string RegKey::getRepresentation(const char* valname) const { std::vector<char> expanded(required); length = ExpandEnvironmentStrings(str.c_str(), expanded.data(), required); if (required<length) - throw rdr::Exception("unable to expand environment strings"); + throw std::runtime_error("unable to expand environment strings"); return expanded.data(); } else { return ""; } } default: - throw rdr::Exception("unsupported registry type"); + throw std::logic_error("unsupported registry type"); } } diff --git a/win/rfb_win32/SDisplay.cxx b/win/rfb_win32/SDisplay.cxx index 703334f3..94b02a6d 100644 --- a/win/rfb_win32/SDisplay.cxx +++ b/win/rfb_win32/SDisplay.cxx @@ -35,7 +35,6 @@ #include <rfb_win32/MonitorInfo.h> #include <rfb_win32/SDisplayCorePolling.h> #include <rfb_win32/SDisplayCoreWMHooks.h> -#include <rfb/Exception.h> #include <rfb/LogWriter.h> #include <rfb/ledStates.h> @@ -172,12 +171,12 @@ void SDisplay::startCore() { // Currently, we just check whether we're in the console session, and // fail if not if (!inConsoleSession()) - throw rdr::Exception("Console is not session zero - oreconnect to restore Console sessin"); + throw std::runtime_error("Console is not session zero - oreconnect to restore Console sessin"); // Switch to the current input desktop if (rfb::win32::desktopChangeRequired()) { if (!rfb::win32::changeDesktop()) - throw rdr::Exception("unable to switch into input desktop"); + throw std::runtime_error("unable to switch into input desktop"); } // Initialise the change tracker and clipper @@ -200,7 +199,7 @@ void SDisplay::startCore() { } catch (std::exception& e) { delete core; core = nullptr; if (tryMethod == 0) - throw rdr::Exception("unable to access desktop"); + throw std::runtime_error("unable to access desktop"); tryMethod--; vlog.error("%s", e.what()); } @@ -435,7 +434,7 @@ SDisplay::processEvent(HANDLE event) { } return; } - throw rdr::Exception("No such event"); + throw std::runtime_error("No such event"); } diff --git a/win/rfb_win32/SDisplayCoreWMHooks.cxx b/win/rfb_win32/SDisplayCoreWMHooks.cxx index 8165be3d..4c307600 100644 --- a/win/rfb_win32/SDisplayCoreWMHooks.cxx +++ b/win/rfb_win32/SDisplayCoreWMHooks.cxx @@ -40,7 +40,7 @@ SDisplayCoreWMHooks::SDisplayCoreWMHooks(SDisplay* d, UpdateTracker* ut) consolePollTimer(getHandle(), consolePollTimerId), pollConsoles(false) { if (!hooks.setEvent(display->getUpdateEvent())) - throw rdr::Exception("hook subsystem failed to initialise"); + throw std::runtime_error("hook subsystem failed to initialise"); poller.setUpdateTracker(updateTracker); cursorTimer.start(20); consolePollTimer.start(200); diff --git a/win/rfb_win32/Security.cxx b/win/rfb_win32/Security.cxx index 04f92402..65153732 100644 --- a/win/rfb_win32/Security.cxx +++ b/win/rfb_win32/Security.cxx @@ -96,7 +96,7 @@ void AccessEntries::addEntry(const PSID sid, PSID Sid::copySID(const PSID sid) { if (!IsValidSid(sid)) - throw rdr::Exception("invalid SID in copyPSID"); + throw std::invalid_argument("invalid SID in copyPSID"); PSID buf = (PSID)new uint8_t[GetLengthSid(sid)]; if (!CopySid(GetLengthSid(sid), buf, sid)) throw rdr::Win32Exception("CopySid failed", GetLastError()); @@ -105,7 +105,7 @@ PSID Sid::copySID(const PSID sid) { void Sid::setSID(const PSID sid) { if (!IsValidSid(sid)) - throw rdr::Exception("invalid SID in copyPSID"); + throw std::invalid_argument("invalid SID in copyPSID"); resize(GetLengthSid(sid)); if (!CopySid(GetLengthSid(sid), data(), sid)) throw rdr::Win32Exception("CopySid failed", GetLastError()); diff --git a/win/rfb_win32/SocketManager.cxx b/win/rfb_win32/SocketManager.cxx index 6226e033..3d8c101e 100644 --- a/win/rfb_win32/SocketManager.cxx +++ b/win/rfb_win32/SocketManager.cxx @@ -25,6 +25,8 @@ #include <winsock2.h> #include <list> +#include <rdr/Exception.h> + #include <network/Socket.h> #include <rfb/LogWriter.h> @@ -75,7 +77,7 @@ void SocketManager::addListener(network::SocketListener* sock_, // addEvent is the last thing we do, so that the event is NOT registered if previous steps fail if (!event || !addEvent(event, this)) - throw rdr::Exception("Unable to add listener"); + throw std::runtime_error("Unable to add listener"); } catch (std::exception& e) { if (event) WSACloseEvent(event); @@ -103,7 +105,7 @@ void SocketManager::remListener(network::SocketListener* sock) { return; } } - throw rdr::Exception("Listener not registered"); + throw std::runtime_error("Listener not registered"); } @@ -136,7 +138,7 @@ void SocketManager::remSocket(network::Socket* sock_) { return; } } - throw rdr::Exception("Socket not registered"); + throw std::runtime_error("Socket not registered"); } bool SocketManager::getDisable(VNCServer* srvr) @@ -147,7 +149,7 @@ bool SocketManager::getDisable(VNCServer* srvr) return i->second.disable; } } - throw rdr::Exception("Listener not registered"); + throw std::runtime_error("Listener not registered"); } void SocketManager::setDisable(VNCServer* srvr, bool disable) @@ -163,7 +165,7 @@ void SocketManager::setDisable(VNCServer* srvr, bool disable) } } if (!found) - throw rdr::Exception("Listener not registered"); + throw std::runtime_error("Listener not registered"); } int SocketManager::checkTimeouts() { diff --git a/win/rfb_win32/Win32Util.cxx b/win/rfb_win32/Win32Util.cxx index f7b5b6c7..b22311af 100644 --- a/win/rfb_win32/Win32Util.cxx +++ b/win/rfb_win32/Win32Util.cxx @@ -81,7 +81,7 @@ const char* FileVersionInfo::getVerString(const char* name, DWORD langId) { UINT length = 0; if (!VerQueryValue(buf, infoName.c_str(), (void**)&buffer, &length)) { printf("unable to find %s version string", infoName.c_str()); - throw rdr::Exception("VerQueryValue failed"); + throw std::runtime_error("VerQueryValue failed"); } return buffer; } diff --git a/win/vncconfig/Legacy.cxx b/win/vncconfig/Legacy.cxx index 855d7363..1edc2bfa 100644 --- a/win/vncconfig/Legacy.cxx +++ b/win/vncconfig/Legacy.cxx @@ -85,7 +85,7 @@ void LegacyPage::LoadPrefs() if (bits) strcat(pattern, "."); if (parts[j].size() > 3) - throw rdr::Exception("Invalid IP address part"); + throw std::invalid_argument("Invalid IP address part"); if (!parts[j].empty()) { strcat(pattern, parts[j].c_str()); bits += 8; diff --git a/win/winvnc/QueryConnectDialog.cxx b/win/winvnc/QueryConnectDialog.cxx index 24918b2a..6ec62bbd 100644 --- a/win/winvnc/QueryConnectDialog.cxx +++ b/win/winvnc/QueryConnectDialog.cxx @@ -60,7 +60,7 @@ void QueryConnectDialog::worker() { countdown = timeout; try { if (desktopChangeRequired() && !changeDesktop()) - throw rdr::Exception("changeDesktop failed"); + throw std::runtime_error("changeDesktop failed"); approve = Dialog::showDialog(MAKEINTRESOURCE(IDD_QUERY_CONNECT)); server->queryConnectionComplete(); } catch (...) { diff --git a/win/winvnc/winvnc.cxx b/win/winvnc/winvnc.cxx index 25e6875f..4feff6b2 100644 --- a/win/winvnc/winvnc.cxx +++ b/win/winvnc/winvnc.cxx @@ -119,7 +119,7 @@ static void processParams(int argc, char** argv) { if (host != nullptr) { HWND hwnd = FindWindow(nullptr, "winvnc::IPC_Interface"); if (!hwnd) - throw rdr::Exception("Unable to locate existing VNC Server."); + throw std::runtime_error("Unable to locate existing VNC Server."); COPYDATASTRUCT copyData; copyData.dwData = 1; // *** AddNewClient copyData.cbData = strlen(host); @@ -132,7 +132,7 @@ static void processParams(int argc, char** argv) { runServer = false; HWND hwnd = FindWindow(nullptr, "winvnc::IPC_Interface"); if (!hwnd) - throw rdr::Exception("Unable to locate existing VNC Server."); + throw std::runtime_error("Unable to locate existing VNC Server."); COPYDATASTRUCT copyData; copyData.dwData = 2; // *** DisconnectClients copyData.lpData = nullptr; |