diff options
Diffstat (limited to 'common/rdr')
-rw-r--r-- | common/rdr/AESInStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/BufferedInStream.cxx | 12 | ||||
-rw-r--r-- | common/rdr/BufferedOutStream.cxx | 11 | ||||
-rw-r--r-- | common/rdr/Exception.cxx | 130 | ||||
-rw-r--r-- | common/rdr/Exception.h | 54 | ||||
-rw-r--r-- | common/rdr/FdInStream.cxx | 6 | ||||
-rw-r--r-- | common/rdr/FdOutStream.cxx | 4 | ||||
-rw-r--r-- | common/rdr/FileInStream.cxx | 6 | ||||
-rw-r--r-- | common/rdr/HexInStream.cxx | 3 | ||||
-rw-r--r-- | common/rdr/InStream.h | 14 | ||||
-rw-r--r-- | common/rdr/MemInStream.h | 2 | ||||
-rw-r--r-- | common/rdr/MemOutStream.h | 3 | ||||
-rw-r--r-- | common/rdr/OutStream.h | 5 | ||||
-rw-r--r-- | common/rdr/RandomStream.cxx | 6 | ||||
-rw-r--r-- | common/rdr/TLSException.cxx | 8 | ||||
-rw-r--r-- | common/rdr/TLSException.h | 5 | ||||
-rw-r--r-- | common/rdr/TLSInStream.cxx | 18 | ||||
-rw-r--r-- | common/rdr/TLSInStream.h | 2 | ||||
-rw-r--r-- | common/rdr/TLSOutStream.cxx | 14 | ||||
-rw-r--r-- | common/rdr/TLSOutStream.h | 2 | ||||
-rw-r--r-- | common/rdr/ZlibInStream.cxx | 9 | ||||
-rw-r--r-- | common/rdr/ZlibOutStream.cxx | 11 |
22 files changed, 184 insertions, 145 deletions
diff --git a/common/rdr/AESInStream.cxx b/common/rdr/AESInStream.cxx index d6d944a3..3a56ef73 100644 --- a/common/rdr/AESInStream.cxx +++ b/common/rdr/AESInStream.cxx @@ -21,8 +21,8 @@ #endif #include <assert.h> + #include <rdr/AESInStream.h> -#include <rdr/Exception.h> #ifdef HAVE_NETTLE using namespace rdr; @@ -68,7 +68,7 @@ bool AESInStream::fillBuffer() EAX_DIGEST(&eaxCtx256, aes256_encrypt, 16, macComputed); } if (memcmp(mac, macComputed, 16) != 0) - throw Exception("AESInStream: failed to authenticate message"); + throw std::runtime_error("AESInStream: failed to authenticate message"); in->setptr(2 + length + 16); end += length; diff --git a/common/rdr/BufferedInStream.cxx b/common/rdr/BufferedInStream.cxx index 3c04bafc..bf94a950 100644 --- a/common/rdr/BufferedInStream.cxx +++ b/common/rdr/BufferedInStream.cxx @@ -24,7 +24,8 @@ #include <assert.h> #include <rdr/BufferedInStream.h> -#include <rdr/Exception.h> + +#include <rfb/util.h> using namespace rdr; @@ -63,9 +64,12 @@ void BufferedInStream::ensureSpace(size_t needed) uint8_t* newBuffer; if (needed > MAX_BUF_SIZE) - throw Exception("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 0d6a1eb6..efb71dd7 100644 --- a/common/rdr/BufferedOutStream.cxx +++ b/common/rdr/BufferedOutStream.cxx @@ -23,8 +23,8 @@ #endif #include <rdr/BufferedOutStream.h> -#include <rdr/Exception.h> +#include <rfb/util.h> using namespace rdr; @@ -138,10 +138,11 @@ void BufferedOutStream::overrun(size_t needed) // We'll need to allocate more buffer space... if (totalNeeded > MAX_BUF_SIZE) - throw Exception("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/Exception.cxx b/common/rdr/Exception.cxx index 6a03fa54..694ee359 100644 --- a/common/rdr/Exception.cxx +++ b/common/rdr/Exception.cxx @@ -1,6 +1,7 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. * Copyright (C) 2004 Red Hat Inc. * Copyright (C) 2010 TigerVNC Team + * Copyright 2014-2024 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +28,8 @@ #include <rdr/Exception.h> #include <rdr/TLSException.h> +#include <rfb/util.h> + #ifdef _WIN32 #include <winsock2.h> #include <windows.h> @@ -37,77 +40,94 @@ #include <string.h> -#ifdef HAVE_GNUTLS -#include <gnutls/gnutls.h> -#endif - using namespace rdr; -Exception::Exception(const char *format, ...) { - va_list ap; - va_start(ap, format); - (void) vsnprintf(str_, len, format, ap); - va_end(ap); +getaddrinfo_error::getaddrinfo_error(const char* s, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", s, + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +getaddrinfo_error::getaddrinfo_error(const std::string& s, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", s.c_str(), + strerror(err_).c_str(), err_)), + err(err_) +{ } -GAIException::GAIException(const char* s, int err_) - : Exception("%s", s), err(err_) +std::string getaddrinfo_error::strerror(int err_) const { - strncat(str_, ": ", len-1-strlen(str_)); #ifdef _WIN32 - wchar_t *currStr = new wchar_t[len-strlen(str_)]; - wcsncpy(currStr, gai_strerrorW(err), len-1-strlen(str_)); - WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_), - len-1-strlen(str_), nullptr, nullptr); - delete [] currStr; + char str[256]; + + WideCharToMultiByte(CP_UTF8, 0, gai_strerrorW(err_), -1, str, + sizeof(str), nullptr, nullptr); + + return str; #else - strncat(str_, gai_strerror(err), len-1-strlen(str_)); -#endif - strncat(str_, " (", len-1-strlen(str_)); - char buf[20]; -#ifdef WIN32 - if (err < 0) - sprintf(buf, "%x", err); - else + return gai_strerror(err_); #endif - sprintf(buf,"%d",err); - strncat(str_, buf, len-1-strlen(str_)); - strncat(str_, ")", len-1-strlen(str_)); } -PosixException::PosixException(const char* s, int err_) - : Exception("%s", s), err(err_) +posix_error::posix_error(const char* what_arg, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg, + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +posix_error::posix_error(const std::string& what_arg, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(), + strerror(err_).c_str(), err_)), + err(err_) { - strncat(str_, ": ", len-1-strlen(str_)); - strncat(str_, strerror(err), len-1-strlen(str_)); - strncat(str_, " (", len-1-strlen(str_)); - char buf[20]; - sprintf(buf,"%d",err); - strncat(str_, buf, len-1-strlen(str_)); - strncat(str_, ")", len-1-strlen(str_)); +} + +std::string posix_error::strerror(int err_) const +{ +#ifdef _WIN32 + char str[256]; + + WideCharToMultiByte(CP_UTF8, 0, _wcserror(err_), -1, str, + sizeof(str), nullptr, nullptr); + + return str; +#else + return ::strerror(err_); +#endif } #ifdef WIN32 -Win32Exception::Win32Exception(const char* s, unsigned err_) - : Exception("%s", s), err(err_) +win32_error::win32_error(const char* what_arg, unsigned err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg, + strerror(err_).c_str(), err_)), + err(err_) { - strncat(str_, ": ", len-1-strlen(str_)); - wchar_t *currStr = new wchar_t[len-strlen(str_)]; +} + +win32_error::win32_error(const std::string& what_arg, unsigned err_) + : std::runtime_error(rfb::format("%s: %s (%d)", what_arg.c_str(), + strerror(err_).c_str(), err_)), + err(err_) +{ +} + +std::string win32_error::strerror(unsigned err_) const +{ + wchar_t wstr[256]; + char str[256]; + FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, err, 0, currStr, len-1-strlen(str_), nullptr); - WideCharToMultiByte(CP_UTF8, 0, currStr, -1, str_+strlen(str_), - len-1-strlen(str_), nullptr, nullptr); - delete [] currStr; - - int l = strlen(str_); - if ((l >= 2) && (str_[l-2] == '\r') && (str_[l-1] == '\n')) - str_[l-2] = 0; - - strncat(str_, " (", len-1-strlen(str_)); - char buf[20]; - sprintf(buf,"%d",err); - strncat(str_, buf, len-1-strlen(str_)); - strncat(str_, ")", len-1-strlen(str_)); + nullptr, err_, 0, wstr, sizeof(wstr), nullptr); + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, + sizeof(str), nullptr, nullptr); + + int l = strlen(str); + if ((l >= 2) && (str[l-2] == '\r') && (str[l-1] == '\n')) + str[l-2] = 0; + + return str; } #endif diff --git a/common/rdr/Exception.h b/common/rdr/Exception.h index c59f7e55..f3f878cb 100644 --- a/common/rdr/Exception.h +++ b/common/rdr/Exception.h @@ -1,6 +1,7 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. * Copyright (C) 2004 Red Hat Inc. * Copyright (C) 2010 TigerVNC Team + * Copyright 2015-2024 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,46 +22,57 @@ #ifndef __RDR_EXCEPTION_H__ #define __RDR_EXCEPTION_H__ -namespace rdr { +#include <stdexcept> +#include <string> - struct Exception { - enum { len = 256 }; - char str_[len]; - Exception(const char *format=nullptr, ...) - __attribute__((__format__ (__printf__, 2, 3))); - virtual ~Exception() {} - virtual const char* str() const { return str_; } - }; +namespace rdr { - struct PosixException : public Exception { + class posix_error : public std::runtime_error { + public: int err; - PosixException(const char* s, int err_); + posix_error(const char* what_arg, int err_); + posix_error(const std::string& what_arg, int err_); + private: + std::string strerror(int err_) const; }; #ifdef WIN32 - struct Win32Exception : public Exception { + class win32_error : public std::runtime_error { + public: unsigned err; - Win32Exception(const char* s, unsigned err_); + win32_error(const char* what_arg, unsigned err_); + win32_error(const std::string& what_arg, unsigned err_); + private: + std::string strerror(unsigned err_) const; }; #endif #ifdef WIN32 - struct SocketException : public Win32Exception { - SocketException(const char* text, unsigned err_) : Win32Exception(text, err_) {} + class socket_error : public win32_error { + public: + socket_error(const char* what_arg, unsigned err_) : win32_error(what_arg, err_) {} + socket_error(const std::string& what_arg, unsigned err_) : win32_error(what_arg, err_) {} }; #else - struct SocketException : public PosixException { - SocketException(const char* text, int err_) : PosixException(text, err_) {} + class socket_error : public posix_error { + public: + socket_error(const char* what_arg, unsigned err_) : posix_error(what_arg, err_) {} + socket_error(const std::string& what_arg, unsigned err_) : posix_error(what_arg, err_) {} }; #endif - struct GAIException : public Exception { + class getaddrinfo_error : public std::runtime_error { + public: int err; - GAIException(const char* s, int err_); + getaddrinfo_error(const char* s, int err_); + getaddrinfo_error(const std::string& s, int err_); + private: + std::string strerror(int err_) const; }; - struct EndOfStream : public Exception { - EndOfStream() : Exception("End of stream") {} + class end_of_stream : public std::runtime_error { + public: + end_of_stream() : std::runtime_error("End of stream") {} }; } diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx index bddee482..23ea2f8c 100644 --- a/common/rdr/FdInStream.cxx +++ b/common/rdr/FdInStream.cxx @@ -92,7 +92,7 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SocketException("select", errorNumber); + throw socket_error("select", errorNumber); if (n == 0) return 0; @@ -102,9 +102,9 @@ size_t FdInStream::readFd(uint8_t* buf, size_t len) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SocketException("read", errorNumber); + throw socket_error("read", errorNumber); if (n == 0) - throw EndOfStream(); + throw end_of_stream(); return n; } diff --git a/common/rdr/FdOutStream.cxx b/common/rdr/FdOutStream.cxx index 1b6049ca..6db8c0bb 100644 --- a/common/rdr/FdOutStream.cxx +++ b/common/rdr/FdOutStream.cxx @@ -117,7 +117,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && errorNumber == EINTR); if (n < 0) - throw SocketException("select", errorNumber); + throw socket_error("select", errorNumber); if (n == 0) return 0; @@ -134,7 +134,7 @@ size_t FdOutStream::writeFd(const uint8_t* data, size_t length) } while (n < 0 && (errorNumber == EINTR)); if (n < 0) - throw SocketException("write", errorNumber); + throw socket_error("write", errorNumber); gettimeofday(&lastWrite, nullptr); diff --git a/common/rdr/FileInStream.cxx b/common/rdr/FileInStream.cxx index db646a7e..df09ea76 100644 --- a/common/rdr/FileInStream.cxx +++ b/common/rdr/FileInStream.cxx @@ -33,7 +33,7 @@ FileInStream::FileInStream(const char *fileName) { file = fopen(fileName, "rb"); if (!file) - throw PosixException("fopen", errno); + throw posix_error("fopen", errno); } FileInStream::~FileInStream(void) { @@ -48,9 +48,9 @@ bool FileInStream::fillBuffer() size_t n = fread((uint8_t*)end, 1, availSpace(), file); if (n == 0) { if (ferror(file)) - throw PosixException("fread", errno); + throw posix_error("fread", errno); if (feof(file)) - throw EndOfStream(); + throw end_of_stream(); return false; } end += n; 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/MemInStream.h b/common/rdr/MemInStream.h index e10273b1..78ee2dee 100644 --- a/common/rdr/MemInStream.h +++ b/common/rdr/MemInStream.h @@ -59,7 +59,7 @@ namespace rdr { private: - bool overrun(size_t /*needed*/) override { throw EndOfStream(); } + bool overrun(size_t /*needed*/) override { throw end_of_stream(); } const uint8_t* start; bool deleteWhenDone; }; 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/RandomStream.cxx b/common/rdr/RandomStream.cxx index 449a84c0..485259cf 100644 --- a/common/rdr/RandomStream.cxx +++ b/common/rdr/RandomStream.cxx @@ -89,7 +89,7 @@ bool RandomStream::fillBuffer() { #ifdef RFB_HAVE_WINCRYPT if (provider) { if (!CryptGenRandom(provider, availSpace(), (uint8_t*)end)) - throw rdr::Win32Exception("unable to CryptGenRandom", GetLastError()); + throw rdr::win32_error("unable to CryptGenRandom", GetLastError()); end += availSpace(); } else { #else @@ -97,8 +97,8 @@ bool RandomStream::fillBuffer() { if (fp) { size_t n = fread((uint8_t*)end, 1, availSpace(), fp); if (n <= 0) - throw rdr::PosixException("reading /dev/urandom or /dev/random failed", - errno); + throw rdr::posix_error("reading /dev/urandom or /dev/random " + "failed", errno); end += n; } else { #else diff --git a/common/rdr/TLSException.cxx b/common/rdr/TLSException.cxx index 0f75a4da..ccff6090 100644 --- a/common/rdr/TLSException.cxx +++ b/common/rdr/TLSException.cxx @@ -24,6 +24,8 @@ #include <rdr/TLSException.h> +#include <rfb/util.h> + #include <string.h> #include <stdio.h> #ifdef HAVE_GNUTLS @@ -33,8 +35,10 @@ using namespace rdr; #ifdef HAVE_GNUTLS -TLSException::TLSException(const char* s, int err_) - : Exception("%s: %s (%d)", s, gnutls_strerror(err_), err_), err(err_) +tls_error::tls_error(const char* s, int err_) + : std::runtime_error(rfb::format("%s: %s (%d)", s, + gnutls_strerror(err_), err_)), + err(err_) { } #endif /* HAVE_GNUTLS */ diff --git a/common/rdr/TLSException.h b/common/rdr/TLSException.h index b519bfef..cfa73f69 100644 --- a/common/rdr/TLSException.h +++ b/common/rdr/TLSException.h @@ -25,9 +25,10 @@ namespace rdr { - struct TLSException : public Exception { + class tls_error : public std::runtime_error { + public: int err; - TLSException(const char* s, int err_); + tls_error(const char* s, int err_); }; } diff --git a/common/rdr/TLSInStream.cxx b/common/rdr/TLSInStream.cxx index f8f4fcf9..7c867e88 100644 --- a/common/rdr/TLSInStream.cxx +++ b/common/rdr/TLSInStream.cxx @@ -54,17 +54,17 @@ ssize_t TLSInStream::pull(gnutls_transport_ptr_t str, void* data, size_t size) size = in->avail(); in->readBytes((uint8_t*)data, size); - } catch (EndOfStream&) { + } catch (end_of_stream&) { return 0; - } catch (SocketException& e) { - vlog.error("Failure reading TLS data: %s", e.str()); + } catch (socket_error& e) { + vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, e.err); - self->saved_exception = new SocketException(e); + self->saved_exception = new socket_error(e); return -1; - } catch (Exception& e) { - vlog.error("Failure reading TLS data: %s", e.str()); + } catch (std::exception& e) { + vlog.error("Failure reading TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); - self->saved_exception = new Exception(e); + self->saved_exception = new std::exception(e); return -1; } @@ -121,10 +121,10 @@ size_t TLSInStream::readTLS(uint8_t* buf, size_t len) throw *saved_exception; if (n < 0) - throw TLSException("readTLS", n); + throw tls_error("readTLS", n); if (n == 0) - throw EndOfStream(); + throw end_of_stream(); return n; } diff --git a/common/rdr/TLSInStream.h b/common/rdr/TLSInStream.h index ca69ddde..2269b09d 100644 --- a/common/rdr/TLSInStream.h +++ b/common/rdr/TLSInStream.h @@ -41,7 +41,7 @@ namespace rdr { InStream* in; bool streamEmpty; - Exception* saved_exception; + std::exception* saved_exception; }; }; diff --git a/common/rdr/TLSOutStream.cxx b/common/rdr/TLSOutStream.cxx index ccb229e1..1e555fc1 100644 --- a/common/rdr/TLSOutStream.cxx +++ b/common/rdr/TLSOutStream.cxx @@ -46,15 +46,15 @@ ssize_t TLSOutStream::push(gnutls_transport_ptr_t str, const void* data, try { out->writeBytes((const uint8_t*)data, size); out->flush(); - } catch (SocketException& e) { - vlog.error("Failure sending TLS data: %s", e.str()); + } catch (socket_error& e) { + vlog.error("Failure sending TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, e.err); - self->saved_exception = new SocketException(e); + self->saved_exception = new socket_error(e); return -1; - } catch (Exception& e) { - vlog.error("Failure sending TLS data: %s", e.str()); + } catch (std::exception& e) { + vlog.error("Failure sending TLS data: %s", e.what()); gnutls_transport_set_errno(self->session, EINVAL); - self->saved_exception = new Exception(e); + self->saved_exception = new std::exception(e); return -1; } @@ -118,7 +118,7 @@ size_t TLSOutStream::writeTLS(const uint8_t* data, size_t length) throw *saved_exception; if (n < 0) - throw TLSException("writeTLS", n); + throw tls_error("writeTLS", n); return n; } diff --git a/common/rdr/TLSOutStream.h b/common/rdr/TLSOutStream.h index 35714238..659f16f0 100644 --- a/common/rdr/TLSOutStream.h +++ b/common/rdr/TLSOutStream.h @@ -42,7 +42,7 @@ namespace rdr { gnutls_session_t session; OutStream* out; - Exception* saved_exception; + std::exception* saved_exception; }; }; 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 0b167711..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"); } } @@ -54,7 +53,7 @@ ZlibOutStream::~ZlibOutStream() { try { flush(); - } catch (Exception&) { + } catch (std::exception&) { } deflateEnd(zs); delete zs; @@ -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; |