Index: .github/workflows/amiga-gcc.yml ================================================================== --- .github/workflows/amiga-gcc.yml +++ .github/workflows/amiga-gcc.yml @@ -1,37 +1,21 @@ name: amiga-gcc on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + container: amigadev/crosstools:m68k-amigaos strategy: matrix: configure_flags: - - --disable-amiga-lib steps: - - name: Install dependencies - run: docker pull amigadev/crosstools:m68k-amigaos - uses: actions/checkout@v2 - name: autogen.sh run: ./autogen.sh - name: configure - run: | - docker run \ - -e PATH="/opt/m68k-amigaos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:m68k-amigaos \ - sh -c 'cd /objfw && ./configure --host=m68k-amigaos ${{ matrix.configure_flags }}' + run: ./configure --host=m68k-amigaos ${{ matrix.configure_flags }} - name: make - run: | - docker run \ - -e PATH="/opt/m68k-amigaos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:m68k-amigaos \ - sh -c "cd /objfw && make -j$(nproc)" + run: make -j$(nproc) - name: make install - run: | - docker run \ - -e PATH="/opt/m68k-amigaos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:m68k-amigaos \ - sh -c "cd /objfw && make -j$(nproc)" + run: make install Index: .github/workflows/morphos.yml ================================================================== --- .github/workflows/morphos.yml +++ .github/workflows/morphos.yml @@ -1,37 +1,21 @@ name: morphos on: [push, pull_request] jobs: build: runs-on: ubuntu-latest + container: amigadev/crosstools:ppc-morphos strategy: matrix: configure_flags: - - --disable-amiga-lib steps: - - name: Install dependencies - run: docker pull amigadev/crosstools:ppc-morphos - uses: actions/checkout@v2 - name: autogen.sh run: ./autogen.sh - name: configure - run: | - docker run \ - -e PATH="/opt/ppc-morphos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:ppc-morphos \ - sh -c 'cd /objfw && ./configure --host=ppc-morphos ${{ matrix.configure_flags }}' + run: ./configure --host=ppc-morphos ${{ matrix.configure_flags }} - name: make - run: | - docker run \ - -e PATH="/opt/ppc-morphos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:ppc-morphos \ - sh -c "cd /objfw && make -j$(nproc)" + run: make -j$(nproc) - name: make install - run: | - docker run \ - -e PATH="/opt/ppc-morphos/bin:$PATH" \ - -v "$PWD:/objfw" \ - amigadev/crosstools:ppc-morphos \ - sh -c "cd /objfw && make -j$(nproc)" + run: make install Index: .github/workflows/nintendo-3ds.yml ================================================================== --- .github/workflows/nintendo-3ds.yml +++ .github/workflows/nintendo-3ds.yml @@ -30,6 +30,6 @@ docker run \ -e DEVKITPRO=/opt/devkitpro \ -e PATH="/opt/devkitpro/devkitARM/bin:$PATH" \ -v "$PWD:/objfw" \ devkitpro/devkitarm \ - sh -c "cd /objfw && make -j$(nproc)" + sh -c "cd /objfw && make install" Index: .github/workflows/nintendo-ds.yml ================================================================== --- .github/workflows/nintendo-ds.yml +++ .github/workflows/nintendo-ds.yml @@ -30,6 +30,6 @@ docker run \ -e DEVKITPRO=/opt/devkitpro \ -e PATH="/opt/devkitpro/devkitARM/bin:$PATH" \ -v "$PWD:/objfw" \ devkitpro/devkitarm \ - sh -c "cd /objfw && make -j$(nproc)" + sh -c "cd /objfw && make install" Index: .github/workflows/nintendo-switch.yml ================================================================== --- .github/workflows/nintendo-switch.yml +++ .github/workflows/nintendo-switch.yml @@ -30,6 +30,6 @@ docker run \ -e DEVKITPRO=/opt/devkitpro \ -e PATH="/opt/devkitpro/devkitA64/bin:$PATH" \ -v "$PWD:/objfw" \ devkitpro/devkita64 \ - sh -c "cd /objfw && make -j$(nproc)" + sh -c "cd /objfw && make install" Index: .github/workflows/wii-u.yml ================================================================== --- .github/workflows/wii-u.yml +++ .github/workflows/wii-u.yml @@ -30,6 +30,6 @@ docker run \ -e DEVKITPRO=/opt/devkitpro \ -e PATH="/opt/devkitpro/devkitPPC/bin:$PATH" \ -v "$PWD:/objfw" \ devkitpro/devkitppc \ - sh -c "cd /objfw && make -j$(nproc)" + sh -c "cd /objfw && make install" Index: .github/workflows/wii.yml ================================================================== --- .github/workflows/wii.yml +++ .github/workflows/wii.yml @@ -30,6 +30,6 @@ docker run \ -e DEVKITPRO=/opt/devkitpro \ -e PATH="/opt/devkitpro/devkitPPC/bin:$PATH" \ -v "$PWD:/objfw" \ devkitpro/devkitppc \ - sh -c "cd /objfw && make -j$(nproc)" + sh -c "cd /objfw && make install" Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -1418,27 +1418,24 @@ AC_CHECK_HEADER(sys/socket.h, [ AC_DEFINE(OF_HAVE_SYS_SOCKET_H, 1, [Whether we have sys/socket.h]) ]) + AC_CHECK_HEADER(netinet/in.h, [ AC_DEFINE(OF_HAVE_NETINET_IN_H, 1, [Whether we have netinet/in.h]) ]) AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) - AC_CHECK_HEADERS([arpa/inet.h netdb.h]) + AC_CHECK_HEADERS([arpa/inet.h netdb.h net/if.h]) + AC_CHECK_FUNCS([if_indextoname if_nametoindex]) AC_CHECK_HEADER(sys/un.h, [ AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h]) ]) - AC_CHECK_HEADER(netipx/ipx.h, [ - AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1, - [Whether we have netipx/ipx.h]) - ]) - AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [ AC_EGREP_CPP(egrep_cpp_yes, [ #ifdef _WIN32 typedef int BOOL; #endif @@ -1521,10 +1518,14 @@ #ifdef __MINT__ # error Gives invalid argument at runtime #endif ]) + AC_CHECK_HEADER(netipx/ipx.h, [ + AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1, + [Whether we have netipx/ipx.h]) + ]) AC_CHECK_MEMBER(struct sockaddr_ipx.sipx_network, [], [ AC_CHECK_MEMBER(struct sockaddr_ipx.sa_netnum, [], [], [ #ifdef _WIN32 typedef int BOOL; #endif @@ -1592,10 +1593,101 @@ ], [ AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX]) AC_SUBST(USE_SRCS_IPX, '${SRCS_IPX}') ]) ]) + + AC_CHECK_HEADER(netat/appletalk.h, [ + AC_DEFINE(OF_HAVE_NETAT_APPLETALK_H, 1, + [Whether we have netat/appletalk.h]) + ]) + AC_CHECK_HEADER(netatalk/at.h, [ + AC_DEFINE(OF_HAVE_NETATALK_AT_H, 1, + [Whether we have netatalk/at.h]) + ]) + AC_CHECK_MEMBER(struct sockaddr_at.sat_addr, [], [ + AC_CHECK_MEMBER(struct sockaddr_at.sat_net, [], [], [ + #ifdef _WIN32 + typedef int BOOL; + #endif + + #ifdef OF_HAVE_SYS_TYPES_H + # include + #endif + #if defined(OF_HAVE_NETAT_APPLETALK_H) + # include + #elif defined(OF_HAVE_NETATALK_AT_H) + # include + #endif + + #ifdef _WIN32 + # ifdef __MINGW32__ + # include <_mingw.h> + # ifdef __MINGW64_VERSION_MAJOR + # include + # endif + # endif + # include + # include + #endif + ]) + ], [ + #ifdef _WIN32 + typedef int BOOL; + #endif + + #ifdef OF_HAVE_SYS_TYPES_H + # include + #endif + #if defined(OF_HAVE_NETAT_APPLETALK_H) + # include + #elif defined(OF_HAVE_NETATALK_AT_H) + # include + #endif + + #ifdef _WIN32 + # ifdef __MINGW32__ + # include <_mingw.h> + # ifdef __MINGW64_VERSION_MAJOR + # include + # endif + # endif + # include + # include + #endif + ]) + AS_IF([test x"$ac_cv_member_struct_sockaddr_at_sat_addr" = x"yes" \ + -o x"$ac_cv_member_struct_sockaddr_at_sat_net" = x"yes"], [ + AC_EGREP_CPP(egrep_cpp_yes, [ + #ifdef _WIN32 + typedef int BOOL; + #endif + + #ifdef OF_HAVE_SYS_SOCKET_H + # include + #endif + + #ifdef _WIN32 + # ifdef __MINGW32__ + # include <_mingw.h> + # ifdef __MINGW64_VERSION_MAJOR + # include + # endif + # endif + # include + # include + #endif + + #ifdef AF_APPLETALK + egrep_cpp_yes + #endif + ], [ + AC_DEFINE(OF_HAVE_APPLETALK, 1, + [Whether we have AppleTalk]) + AC_SUBST(USE_SRCS_APPLETALK, '${SRCS_APPLETALK}') + ]) + ]) AC_CHECK_FUNCS(paccept accept4, break) AC_CHECK_FUNCS(kqueue1 kqueue, [ AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue]) @@ -1668,10 +1760,27 @@ ], []) LIBS="$old_LIBS" ]) ]) + + AS_IF([test x"$with_tls" = x"gnutls" \ + -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [ + PKG_CHECK_MODULES(gnutls, [gnutls >= 3.5.0], [ + AC_DEFINE(HAVE_GNUTLS, 1, [Whether we have GnuTLS]) + + tls_support="GnuTLS" + TLS_CPPFLAGS="$gnutls_CFLAGS $TLS_CPPFLAGS" + TLS_LIBS="$gnutls_LIBS $TLS_LIBS" + + AC_SUBST(OF_GNUTLS_TLS_STREAM_M, "OFGnuTLSTLSStream.m") + ], [ + dnl Disable default action-if-not-found, which exits + dnl configure with an error. + : + ]) + ]) AS_IF([test x"$with_tls" = x"openssl" \ -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [ case "$host_os" in morphos*) @@ -1696,27 +1805,10 @@ "OFOpenSSLTLSStream.m") ]) ], [], [-l$crypto]) ]) - AS_IF([test x"$with_tls" = x"gnutls" \ - -o \( x"$with_tls" = x"yes" -a x"$tls_support" = x"no" \)], [ - PKG_CHECK_MODULES(gnutls, [gnutls >= 3.5.0], [ - AC_DEFINE(HAVE_GNUTLS, 1, [Whether we have GnuTLS]) - - tls_support="GnuTLS" - TLS_CPPFLAGS="$gnutls_CFLAGS $TLS_CPPFLAGS" - TLS_LIBS="$gnutls_LIBS $TLS_LIBS" - - AC_SUBST(OF_GNUTLS_TLS_STREAM_M, "OFGnuTLSTLSStream.m") - ], [ - dnl Disable default action-if-not-found, which exits - dnl configure with an error. - : - ]) - ]) - AS_IF([test x"$tls_support" != x"no"], [ AC_SUBST(TLS, "tls") AC_SUBST(TLS_CPPFLAGS) AC_SUBST(TLS_LIBS) AC_DEFINE(HAVE_TLS_SUPPORT, 1, @@ -2028,11 +2120,12 @@ # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ abort(); \ \ - _Pragma("clang diagnostic push ignore \ + _Pragma("clang diagnostic push"); \ + _Pragma("clang diagnostic ignored \ \"-Wunreachable-code\""); \ [super dealloc]; \ _Pragma("clang diagnostic pop"); #else # define OF_DEALLOC_UNSUPPORTED \ Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -82,13 +82,14 @@ TLS = @TLS@ TLS_CPPFLAGS = @TLS_CPPFLAGS@ TLS_LIBS = @TLS_LIBS@ UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ +USE_SRCS_APPLETALK = @USE_SRCS_APPLETALK@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ USE_SRCS_UNIX_SOCKETS = @USE_SRCS_UNIX_SOCKETS@ USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@ WRAPPER = @WRAPPER@ Index: objfw.spec ================================================================== --- objfw.spec +++ objfw.spec @@ -30,11 +30,11 @@ BuildRequires: autoconf BuildRequires: automake BuildRequires: clang BuildRequires: make -BuildRequires: pkgconfig(openssl) +BuildRequires: pkgconfig(gnutls) Requires: %{libobjfw_pkgname}%{_isa} = %{version}-%{release} Requires: %{libobjfw_pkgname}-devel = %{version}-%{release} Requires: %{libobjfwrt_pkgname}%{_isa} = %{version}-%{release} Requires: %{libobjfwrt_pkgname}-devel = %{version}-%{release} Requires: ofarc%{_isa} = %{version}-%{release} @@ -87,11 +87,11 @@ The %{libobjfwrt_pkgname}-devel package contains header files and libraries for ObjFW's Objective-C runtime library. %package -n %{libobjfwtls_pkgname} Summary: TLS support for ObjFW -Requires: openssl%{_isa} >= 1.1.1 +Requires: gnutls%{_isa} >= 3.0.5 %description -n %{libobjfwtls_pkgname} The %{libobjfwtls_pkgname} package contains TLS support for ObjFW %package -n %{libobjfwtls_pkgname}-devel @@ -136,14 +136,14 @@ Requires: %{libobjfw_pkgname}%{_isa} = %{version}-%{release} Requires: %{libobjfwrt_pkgname}%{_isa} = %{version}-%{release} Requires: %{libobjfwtls_pkgname}%{_isa} = %{version}-%{release} %description -n ofhttp -ofhttp is a command line downloader for HTTP and HTTPS (via ObjOpenSSL) using -ObjFW's OFHTTPClient class. It supports all features one would expect from a -modern command line downloader such as resuming of downloads, using a SOCKS5 -proxy, a modern terminal-based UI, etc. +ofhttp is a command line downloader for HTTP and HTTPS using ObjFW's +OFHTTPClient class. It supports all features one would expect from a modern +command line downloader such as resuming of downloads, using a SOCKS5 proxy, a +modern terminal-based UI, etc. %prep %autosetup ./autogen.sh Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -143,12 +143,14 @@ OFSocket.m \ OFStreamSocket.m \ OFTCPSocket.m \ OFTLSStream.m \ OFUDPSocket.m \ + ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} +SRCS_APPLETALK = OFDDPSocket.m SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocket.m \ OFUNIXStreamSocket.m Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -40,14 +40,14 @@ #import "OFString.h" #import "OFSystemInfo.h" #import "OFThread+Private.h" #import "OFThread.h" +#import "OFActivateSandboxFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" -#import "OFSandboxActivationFailedException.h" #if defined(OF_MACOS) # include #elif defined(OF_WINDOWS) # include @@ -652,11 +652,11 @@ sandbox->_unveiledPathsIndex = unveiledPathsCount; promises = [sandbox.pledgeString cStringWithEncoding: encoding]; if (pledge(promises, NULL) != 0) - @throw [OFSandboxActivationFailedException + @throw [OFActivateSandboxFailedException exceptionWithSandbox: sandbox errNo: errno]; objc_autoreleasePoolPop(pool); @@ -680,11 +680,11 @@ promises = [sandbox.pledgeString cStringWithEncoding: [OFLocale encoding]]; if (pledge(NULL, promises) != 0) - @throw [OFSandboxActivationFailedException + @throw [OFActivateSandboxFailedException exceptionWithSandbox: sandbox errNo: errno]; objc_autoreleasePoolPop(pool); Index: src/OFCondition.h ================================================================== --- src/OFCondition.h +++ src/OFCondition.h @@ -44,11 +44,11 @@ * @ref broadcast. * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref wait returned! * - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (void)wait; #ifdef OF_AMIGAOS /** @@ -57,11 +57,11 @@ * * @note This is only available on AmigaOS! * * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (void)waitForConditionOrExecSignal: (ULONG *)signalMask; #endif /** @@ -71,11 +71,11 @@ * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitForTimeInterval: returned! * * @param timeInterval The time interval until the timeout is reached * @return Whether the condition has been signaled - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval; #ifdef OF_AMIGAOS /** @@ -86,11 +86,11 @@ * * @param timeInterval The time interval until the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask; #endif @@ -101,11 +101,11 @@ * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitUntilDate: returned! * * @param date The date at which the timeout is reached * @return Whether the condition has been signaled - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitUntilDate: (OFDate *)date; #ifdef OF_AMIGAOS /** @@ -116,26 +116,26 @@ * * @param date The date at which the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received - * @throw OFConditionWaitFailedException Waiting for the condition failed + * @throw OFWaitForConditionFailedException Waiting for the condition failed */ - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask; #endif /** * @brief Signals the next waiting thread to continue. * - * @throw OFConditionSignalFailedException Signaling the condition failed + * @throw OFSignalConditionFailedException Signaling the condition failed */ - (void)signal; /** * @brief Signals all threads to continue. * - * @throw OFConditionBroadcastFailedException Broadcasting the condition failed + * @throw OFBroadcastConditionFailedException Broadcasting the condition failed */ - (void)broadcast; @end OF_ASSUME_NONNULL_END Index: src/OFCondition.m ================================================================== --- src/OFCondition.m +++ src/OFCondition.m @@ -18,15 +18,15 @@ #include #import "OFCondition.h" #import "OFDate.h" -#import "OFConditionBroadcastFailedException.h" -#import "OFConditionSignalFailedException.h" +#import "OFBroadcastConditionFailedException.h" #import "OFConditionStillWaitingException.h" -#import "OFConditionWaitFailedException.h" #import "OFInitializationFailedException.h" +#import "OFSignalConditionFailedException.h" +#import "OFWaitForConditionFailedException.h" @implementation OFCondition + (instancetype)condition { return [[[self alloc] init] autorelease]; @@ -66,11 +66,11 @@ - (void)wait { int error = OFPlainConditionWait(&_condition, &_mutex); if (error != 0) - @throw [OFConditionWaitFailedException + @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; } #ifdef OF_AMIGAOS @@ -78,11 +78,11 @@ { int error = OFPlainConditionWaitOrExecSignal(&_condition, &_mutex, signalMask); if (error != 0) - @throw [OFConditionWaitFailedException + @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; } #endif @@ -93,11 +93,11 @@ if (error == ETIMEDOUT) return false; if (error != 0) - @throw [OFConditionWaitFailedException + @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; return true; } @@ -111,11 +111,11 @@ if (error == ETIMEDOUT) return false; if (error != 0) - @throw [OFConditionWaitFailedException + @throw [OFWaitForConditionFailedException exceptionWithCondition: self errNo: error]; return true; } @@ -137,20 +137,20 @@ - (void)signal { int error = OFPlainConditionSignal(&_condition); if (error != 0) - @throw [OFConditionSignalFailedException + @throw [OFSignalConditionFailedException exceptionWithCondition: self errNo: error]; } - (void)broadcast { int error = OFPlainConditionBroadcast(&_condition); if (error != 0) - @throw [OFConditionBroadcastFailedException + @throw [OFBroadcastConditionFailedException exceptionWithCondition: self errNo: error]; } @end ADDED src/OFDDPSocket.h Index: src/OFDDPSocket.h ================================================================== --- src/OFDDPSocket.h +++ src/OFDDPSocket.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFDatagramSocket.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OFString; + +/** + * @protocol OFDDPSocketDelegate OFDDPSocket.h ObjFW/OFDDPSocket.h + * + * @brief A delegate for OFDDPSocket. + */ +@protocol OFDDPSocketDelegate +@end + +/** + * @class OFDDPSocket OFDDPSocket.h ObjFW/OFDDPSocket.h + * + * @brief A class which provides methods to create and use AppleTalk DDP + * sockets. + * + * Addresses are of type @ref OFSocketAddress. You can use + * @ref OFSocketAddressMakeAppleTalk to create an address or + * @ref OFSocketAddressAppleTalkNetwork to get the AppleTalk network, + * @ref OFSocketAddressAppleTalkNode to get the AppleTalk node and + * @ref OFSocketAddressAppleTalkPort to get the port (sometimes also called + * socket number). + * + * @note On some systems, packets received with the wrong protocol type just + * get filtered by the kernel, however, on other systems, the packet is + * queued up and will raise an @ref OFReadFailedException with the + * @ref errNo set to `ENOMSG` when being received. + * + * @warning Even though the OFCopying protocol is implemented, it does *not* + * return an independent copy of the socket, but instead retains it. + * This is so that the socket can be used as a key for a dictionary, + * so context can be associated with a socket. Using a socket in more + * than one thread at the same time is not thread-safe, even if copy + * was called to create one "instance" for every thread! + */ +@interface OFDDPSocket: OFDatagramSocket +{ +#if !defined(OF_MACOS) && !defined(OF_WINDOWS) + uint8_t _protocolType; +#endif + OF_RESERVE_IVARS(OFDDPSocket, 4) +} + +/** + * @brief The delegate for asynchronous operations on the socket. + * + * @note The delegate is retained for as long as asynchronous operations are + * still ongoing. + */ +@property OF_NULLABLE_PROPERTY (assign, nonatomic) + id delegate; + +/** + * @brief Bind the socket to the specified network, node and port. + * + * @param network The network to bind to. 0 means any. + * @param node The node to bind to. 0 means "this node". + * @param port The port to bind to. 0 means to pick one and return it via the + * returned socket address. + * @param protocolType The DDP protocol type to use. Must not be 0. If you want + * to use DDP directly and not a protocol built on top of + * it, use 11 for compatibility with Open Transport. + * @return The address on which this socket can be reached + * @throw OFBindDDPSockeFailedException Binding failed + * @throw OFAlreadyConnectedException The socket is already bound + */ +- (OFSocketAddress)bindToNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFDDPSocket.m Index: src/OFDDPSocket.m ================================================================== --- src/OFDDPSocket.m +++ src/OFDDPSocket.m @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#ifdef HAVE_FCNTL_H +# include +#endif + +#import "OFDDPSocket.h" +#import "OFSocket.h" +#import "OFSocket+Private.h" + +#import "OFAlreadyConnectedException.h" +#import "OFBindDDPSocketFailedException.h" +#import "OFInvalidArgumentException.h" +#import "OFNotOpenException.h" +#import "OFReadFailedException.h" +#import "OFWriteFailedException.h" + +#ifdef OF_HAVE_NETAT_APPLETALK_H +# include +# include + +/* Unfortulately, there is no struct for the following in userland headers */ +struct ATInterfaceConfig { + char interfaceName[16]; + unsigned int flags; + struct at_addr address, router; + unsigned short netStart, netEnd; + at_nvestr_t zoneName; +}; +#endif + +#ifndef ATPROTO_BASE +# define ATPROTO_BASE 0 +#endif + +@implementation OFDDPSocket +@dynamic delegate; + +- (OFSocketAddress)bindToNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType +{ +#ifdef OF_MACOS + const int one = 1; + struct ATInterfaceConfig config = { { 0 } }; +#endif + OFSocketAddress address; +#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) + int flags; +#endif + + if (protocolType == 0) + @throw [OFInvalidArgumentException exception]; + + if (_socket != OFInvalidSocketHandle) + @throw [OFAlreadyConnectedException exceptionWithSocket: self]; + + address = OFSocketAddressMakeAppleTalk(network, node, port); + +#ifdef OF_MACOS + if ((_socket = socket(address.sockaddr.at.sat_family, + SOCK_RAW | SOCK_CLOEXEC, protocolType)) == OFInvalidSocketHandle) +#else + if ((_socket = socket(address.sockaddr.at.sat_family, + SOCK_DGRAM | SOCK_CLOEXEC, ATPROTO_BASE + protocolType)) == + OFInvalidSocketHandle) +#endif + @throw [OFBindDDPSocketFailedException + exceptionWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: self + errNo: OFSocketErrNo()]; + + _canBlock = true; + +#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) + if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) + fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); +#endif + + if (bind(_socket, (struct sockaddr *)&address.sockaddr, + address.length) != 0) { + int errNo = OFSocketErrNo(); + + closesocket(_socket); + _socket = OFInvalidSocketHandle; + + @throw [OFBindDDPSocketFailedException + exceptionWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: self + errNo: errNo]; + } + + memset(&address, 0, sizeof(address)); + address.family = OFSocketAddressFamilyAppleTalk; + address.length = (socklen_t)sizeof(address.sockaddr); + + if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr, + &address.length) != 0) { + int errNo = OFSocketErrNo(); + + closesocket(_socket); + _socket = OFInvalidSocketHandle; + + @throw [OFBindDDPSocketFailedException + exceptionWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: self + errNo: errNo]; + } + + if (address.sockaddr.at.sat_family != AF_APPLETALK) { + closesocket(_socket); + _socket = OFInvalidSocketHandle; + + @throw [OFBindDDPSocketFailedException + exceptionWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: self + errNo: EAFNOSUPPORT]; + } + +#ifdef OF_MACOS + if (setsockopt(_socket, ATPROTO_NONE, DDP_STRIPHDR, &one, + sizeof(one)) != 0 || ioctl(_socket, _IOWR('a', 2, + struct ATInterfaceConfig), &config) != 0) + @throw [OFBindDDPSocketFailedException + exceptionWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: self + errNo: OFSocketErrNo()]; + + OFSocketAddressSetAppleTalkNetwork(&address, config.address.s_net); + OFSocketAddressSetAppleTalkNode(&address, config.address.s_node); +#endif + +#if !defined(OF_MACOS) && !defined(OF_WINDOWS) + _protocolType = protocolType; +#endif + + return address; +} + +/* + * Everybody but macOS and Windows is probably using a netatalk-compatible + * implementation, which includes the protocol type as the first byte of the + * data instead of considering it part of the header. + * + * The following overrides prepend the protocol type when sending and compare + * and strip it when receiving. + * + * Unfortunately, the downside of this is that the only way to handle receiving + * a packet with the wrong protocol type is to throw an exception with errNo + * ENOMSG, while macOS and Windows just filter those out in the kernel. + * Returning 0 would mean this is indistinguishable from an empty packet, so it + * has to be an exception. + */ +#if !defined(OF_MACOS) && !defined(OF_WINDOWS) +- (size_t)receiveIntoBuffer: (void *)buffer + length: (size_t)length + sender: (OFSocketAddress *)sender +{ + ssize_t ret; + uint8_t protocolType; + struct iovec iov[2] = { + { &protocolType, 1 }, + { buffer, length } + }; + struct msghdr msg = { + .msg_name = (struct sockaddr *)&sender->sockaddr, + .msg_namelen = (socklen_t)sizeof(sender->sockaddr), + .msg_iov = iov, + .msg_iovlen = 2 + }; + + if (_socket == OFInvalidSocketHandle) + @throw [OFNotOpenException exceptionWithObject: self]; + + if ((ret = recvmsg(_socket, &msg, 0)) < 0) + @throw [OFReadFailedException + exceptionWithObject: self + requestedLength: length + errNo: OFSocketErrNo()]; + + if (ret < 1 || protocolType != _protocolType) + @throw [OFReadFailedException exceptionWithObject: self + requestedLength: length + errNo: ENOMSG]; + + sender->length = msg.msg_namelen; + sender->family = OFSocketAddressFamilyAppleTalk; + + return ret - 1; +} + +- (void)sendBuffer: (const void *)buffer + length: (size_t)length + receiver: (const OFSocketAddress *)receiver +{ + struct iovec iov[2] = { + { &_protocolType, 1 }, + { (void *)buffer, length } + }; + struct msghdr msg = { + .msg_name = (struct sockaddr *)&receiver->sockaddr, + .msg_namelen = receiver->length, + .msg_iov = iov, + .msg_iovlen = 2 + }; + ssize_t bytesWritten; + + if (_socket == OFInvalidSocketHandle) + @throw [OFNotOpenException exceptionWithObject: self]; + + if ((bytesWritten = sendmsg(_socket, &msg, 0)) < 0) + @throw [OFWriteFailedException + exceptionWithObject: self + requestedLength: length + bytesWritten: 0 + errNo: OFSocketErrNo()]; + + if ((size_t)bytesWritten != length + 1) { + bytesWritten--; + + if (bytesWritten < 0) + bytesWritten = 0; + + @throw [OFWriteFailedException exceptionWithObject: self + requestedLength: length + bytesWritten: bytesWritten + errNo: 0]; + } +} +#endif +@end Index: src/OFDNSResolverSettings.m ================================================================== --- src/OFDNSResolverSettings.m +++ src/OFDNSResolverSettings.m @@ -266,11 +266,13 @@ return; } staticHosts = [OFMutableDictionary dictionary]; - while ((line = [file readLine]) != nil) { + /* Use ISO 8859-1 to ignore any potential non-UTF-8 comments. */ + while ((line = + [file readLineWithEncoding: OFStringEncodingISO8859_1]) != nil) { OFArray *components, *hosts; size_t pos; OFString *address; pos = [line rangeOfString: @"#"].location; @@ -366,11 +368,13 @@ } if (nameServers == nil) nameServers = [OFMutableArray array]; - while ((line = [file readLine]) != nil) { + /* Use ISO 8859-1 to ignore any potential non-UTF-8 comments. */ + while ((line = + [file readLineWithEncoding: OFStringEncodingISO8859_1]) != nil) { void *pool2 = objc_autoreleasePoolPush(); size_t pos; OFArray *components, *arguments; OFString *option; Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -173,40 +173,36 @@ #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { char *buffer = NULL; - unsigned long long size; + OFStreamOffset fileSize; @try { - OFFile *file; + void *pool = objc_autoreleasePoolPush(); + OFFile *file = [OFFile fileWithPath: path mode: @"r"]; + fileSize = [file seekToOffset: 0 whence: OFSeekEnd]; - size = [[OFFileManager defaultManager] - attributesOfItemAtPath: path].fileSize; - -# if ULLONG_MAX > SIZE_MAX - if (size > SIZE_MAX) + if (fileSize < 0 || (unsigned long long)fileSize > SIZE_MAX) @throw [OFOutOfRangeException exception]; -# endif - - buffer = OFAllocMemory((size_t)size, 1); - file = [[OFFile alloc] initWithPath: path mode: @"r"]; - @try { - [file readIntoBuffer: buffer exactLength: (size_t)size]; - } @finally { - [file release]; - } + + [file seekToOffset: 0 whence: OFSeekSet]; + + buffer = OFAllocMemory((size_t)fileSize, 1); + [file readIntoBuffer: buffer exactLength: (size_t)fileSize]; + + objc_autoreleasePoolPop(pool); } @catch (id e) { OFFreeMemory(buffer); [self release]; @throw e; } @try { self = [self initWithItemsNoCopy: buffer - count: (size_t)size + count: (size_t)fileSize freeWhenDone: true]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } Index: src/OFDatagramSocket.m ================================================================== --- src/OFDatagramSocket.m +++ src/OFDatagramSocket.m @@ -210,10 +210,15 @@ #endif #ifdef OF_HAVE_IPX case AF_IPX: sender->family = OFSocketAddressFamilyIPX; break; +#endif +#ifdef OF_HAVE_APPLETALK + case AF_APPLETALK: + sender->family = OFSocketAddressFamilyAppleTalk; + break; #endif default: sender->family = OFSocketAddressFamilyUnknown; break; } Index: src/OFFileManager.m ================================================================== --- src/OFFileManager.m +++ src/OFFileManager.m @@ -19,11 +19,11 @@ #include #include #include "unistd_wrapper.h" -#import "platform.h" +#include "platform.h" #ifdef OF_PSP # include #endif Index: src/OFFileURIHandler.m ================================================================== --- src/OFFileURIHandler.m +++ src/OFFileURIHandler.m @@ -23,11 +23,11 @@ #ifdef HAVE_DIRENT_H # include #endif #include "unistd_wrapper.h" -#import "platform.h" +#include "platform.h" #ifdef HAVE_SYS_STAT_H # include #endif #include #ifdef OF_WINDOWS Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -124,11 +124,11 @@ OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; bool hasContentLength, chunked; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; - if (URI.path != nil) + if (URI.path.length > 0) path = URI.percentEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: Index: src/OFIPSocketAsyncConnector.m ================================================================== --- src/OFIPSocketAsyncConnector.m +++ src/OFIPSocketAsyncConnector.m @@ -21,11 +21,11 @@ #import "OFData.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" -#import "OFConnectionFailedException.h" +#import "OFConnectIPSocketFailedException.h" #import "OFInvalidFormatException.h" @implementation OFIPSocketAsyncConnector - (instancetype)initWithSocket: (id)sock host: (OFString *)host @@ -124,27 +124,27 @@ [self didConnect]; } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { - return [OFConnectionFailedException exceptionWithHost: _host - port: _port - socket: _socket - errNo: errNo]; + return [OFConnectIPSocketFailedException exceptionWithHost: _host + port: _port + socket: _socket + errNo: errNo]; } - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = *(const OFSocketAddress *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; - OFSocketAddressSetPort(&address, _port); + OFSocketAddressSetIPPort(&address, _port); if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { if (_socketAddressesIndex >= _socketAddresses.count) { - _exception = [[OFConnectionFailedException alloc] + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; @@ -185,11 +185,11 @@ } else { #endif [_socket of_closeSocket]; if (_socketAddressesIndex >= _socketAddresses.count) { - _exception = [[OFConnectionFailedException + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; Index: src/OFIPXSocket.h ================================================================== --- src/OFIPXSocket.h +++ src/OFIPXSocket.h @@ -34,11 +34,11 @@ * * Addresses are of type @ref OFSocketAddress. You can use * @ref OFSocketAddressMakeIPX to create an address or * @ref OFSocketAddressIPXNetwork to get the IPX network, * @ref OFSocketAddressIPXNode to get the IPX node and - * @ref OFSocketAddressPort to get the port (sometimes also called + * @ref OFSocketAddressIPXPort to get the port (sometimes also called * socket number). * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, @@ -65,16 +65,23 @@ /** * @brief Bind the socket to the specified network, node and port with the * specified packet type. * + * @param network The IPX network to bind to. 0 means the current network. + * @param node The IPX network to bind to. An all zero node means the + * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to - * pick one and return it. + * pick one and return via the returned socket address. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached - * @throw OFBindFailedException Binding failed + * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ -- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; +- (OFSocketAddress) + bindToNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END Index: src/OFIPXSocket.m ================================================================== --- src/OFIPXSocket.m +++ src/OFIPXSocket.m @@ -24,42 +24,46 @@ #import "OFIPXSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" +#import "OFBindIPXSocketFailedException.h" @implementation OFIPXSocket @dynamic delegate; -- (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType +- (OFSocketAddress)bindToNetwork: (uint32_t)network + node: (const unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType { - const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; int protocol = 0; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(0, zeroNode, port); + address = OFSocketAddressMakeIPX(network, node, port); #ifdef OF_WINDOWS protocol = NSPROTO_IPX + packetType; #else _packetType = address.sockaddr.ipx.sipx_type = packetType; #endif if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle) - @throw [OFBindFailedException - exceptionWithPort: port - packetType: packetType - socket: self - errNo: OFSocketErrNo()]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: packetType + socket: self + errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) @@ -71,14 +75,17 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: packetType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: packetType + socket: self + errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); @@ -88,24 +95,30 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: packetType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: packetType + socket: self + errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: packetType - socket: self - errNo: EAFNOSUPPORT]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: packetType + socket: self + errNo: EAFNOSUPPORT]; } return address; } Index: src/OFLHAArchive.h ================================================================== --- src/OFLHAArchive.h +++ src/OFLHAArchive.h @@ -44,20 +44,10 @@ /** * @brief The encoding to use for the archive. Defaults to ISO 8859-1. */ @property (nonatomic) OFStringEncoding encoding; -/** - * @brief A stream for reading the current entry. - * - * @note This is only available in read mode. - * - * @note The returned stream conforms to @ref OFReadyForReadingObserving if the - * underlying stream does so, too. - */ -@property (readonly, nonatomic) OFStream *streamForReadingCurrentEntry; - /** * @brief Creates a new OFLHAArchive object with the specified stream. * * @param stream A stream from which the LHA archive will be read. * For read and append mode, this needs to be an OFSeekableStream. @@ -137,10 +127,22 @@ * unsupported version * @throw OFTruncatedDataException The archive was truncated */ - (nullable OFLHAArchiveEntry *)nextEntry; +/** + * @brief Returns a stream for reading the current entry. + * + * @note This is only available in read mode. + * + * @note The returned stream conforms to @ref OFReadyForReadingObserving if the + * underlying stream does so, too. + * + * @return A stream for reading the current entry + */ +- (OFStream *)streamForReadingCurrentEntry; + /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. * @@ -161,10 +163,12 @@ */ - (OFStream *)streamForWritingEntry: (OFLHAArchiveEntry *)entry; /** * @brief Closes the OFLHAArchive. + * + * @throw OFNotOpenException The archive is not open */ - (void)close; @end OF_ASSUME_NONNULL_END Index: src/OFMutableTarArchiveEntry.m ================================================================== --- src/OFMutableTarArchiveEntry.m +++ src/OFMutableTarArchiveEntry.m @@ -24,10 +24,15 @@ @implementation OFMutableTarArchiveEntry @dynamic fileName, POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic compressedSize, uncompressedSize, modificationDate, type; @dynamic targetFileName, ownerAccountName, groupOwnerAccountName, deviceMajor; @dynamic deviceMinor; +/* + * The following is optional in OFMutableArchiveEntry, but Apple GCC 4.0.1 is + * buggy and needs this to stop complaining. + */ +@dynamic fileComment; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } Index: src/OFMutableZIPArchiveEntry.m ================================================================== --- src/OFMutableZIPArchiveEntry.m +++ src/OFMutableZIPArchiveEntry.m @@ -27,10 +27,16 @@ @implementation OFMutableZIPArchiveEntry @dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; +/* + * The following are optional in OFMutableArchiveEntry, but Apple GCC 4.0.1 is + * buggy and needs this to stop complaining. + */ +@dynamic POSIXPermissions, ownerAccountID, groupOwnerAccountID; +@dynamic ownerAccountName, groupOwnerAccountName; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } Index: src/OFOnce.h ================================================================== --- src/OFOnce.h +++ src/OFOnce.h @@ -15,12 +15,10 @@ #include "objfw-defs.h" #import "macros.h" -/** @file */ - #if defined(OF_HAVE_PTHREADS) # include typedef pthread_once_t OFOnceControl; # define OFOnceControlInitValue PTHREAD_ONCE_INIT #elif defined(OF_HAVE_ATOMIC_OPS) @@ -29,11 +27,13 @@ #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS) typedef int OFOnceControl; # define OFOnceControlInitValue 0 #endif -typedef void (*OFOnceFunction)(void); +OF_ASSUME_NONNULL_BEGIN + +/** @file */ #ifdef __cplusplus extern "C" { #endif /** @@ -46,5 +46,7 @@ */ extern void OFOnce(OFOnceControl *control, void (*function)(void)); #ifdef __cplusplus } #endif + +OF_ASSUME_NONNULL_END Index: src/OFSPXSocket.h ================================================================== --- src/OFSPXSocket.h +++ src/OFSPXSocket.h @@ -50,11 +50,11 @@ * @param exception An exception that occurred while connecting, or nil on * success */ - (void)socket: (OFSPXSocket *)socket didConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port exception: (nullable id)exception; @end /** @@ -87,15 +87,15 @@ * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to - * @throw OFConnectionFailedException Connecting failed + * @throw OFConnectSPXSocketFailedException Connecting failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * @@ -103,11 +103,11 @@ * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * @@ -116,11 +116,11 @@ * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** @@ -131,11 +131,11 @@ * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. @@ -146,24 +146,30 @@ * connect to * @param runLoopMode The run loop mode in which to perform the async connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * + * @param network The IPX network to bind to. 0 means the current network. + * @param node The IPX network to bind to. An all zero node means the + * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to - * pick one and return it. + * pick one and return via the returned socket address. * @return The address on which this socket can be reached - * @throw OFBindFailedException Binding failed + * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ -- (OFSocketAddress)bindToPort: (uint16_t)port; +- (OFSocketAddress) + bindToNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXSocket.m ================================================================== --- src/OFSPXSocket.m +++ src/OFSPXSocket.m @@ -22,12 +22,12 @@ #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" -#import "OFConnectionFailedException.h" +#import "OFBindIPXSocketFailedException.h" +#import "OFConnectSPXSocketFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif @@ -54,11 +54,11 @@ #endif } - (instancetype)initWithSocket: (OFSPXSocket *)socket network: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif ; @@ -66,11 +66,11 @@ @end @implementation OFSPXSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXSocket *)sock network: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif { @@ -164,15 +164,15 @@ #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { - return [OFConnectionFailedException exceptionWithNetwork: _network - node: _node - port: _port - socket: _socket - errNo: errNo]; + return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network + node: _node + port: _port + socket: _socket + errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; @@ -222,48 +222,48 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) - @throw [OFConnectionFailedException + @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; - @throw [OFConnectionFailedException + @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); @@ -280,11 +280,11 @@ objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block { [self asyncConnectToNetwork: network node: node @@ -292,11 +292,11 @@ runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); @@ -311,31 +311,34 @@ objc_autoreleasePoolPop(pool); } #endif -- (OFSocketAddress)bindToPort: (uint16_t)port +- (OFSocketAddress)bindToNetwork: (uint32_t)network + node: (const unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port { - const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(0, zeroNode, port); + address = OFSocketAddressMakeIPX(network, node, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) - @throw [OFBindFailedException - exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: OFSocketErrNo()]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) @@ -347,14 +350,17 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); @@ -364,24 +370,30 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: EAFNOSUPPORT]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: EAFNOSUPPORT]; } return address; } @end Index: src/OFSPXStreamSocket.h ================================================================== --- src/OFSPXStreamSocket.h +++ src/OFSPXStreamSocket.h @@ -51,11 +51,11 @@ * @param exception An exception that occurred while connecting, or nil on * success */ - (void)socket: (OFSPXStreamSocket *)socket didConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port exception: (nullable id)exception; @end /** @@ -88,15 +88,15 @@ * * @param network The network on which the node to connect to is * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to - * @throw OFConnectionFailedException Connecting failed + * @throw OFConnectSPXSocketFailedException Connecting failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. @@ -105,11 +105,11 @@ * @param node The node to connect to * @param port The port (sometimes also called socket number) on the node to * connect to */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. @@ -119,11 +119,11 @@ * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** @@ -135,11 +135,11 @@ * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified @@ -151,24 +151,30 @@ * connect to * @param runLoopMode The run loop mode in which to perform the async connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * + * @param network The IPX network to bind to. 0 means the current network. + * @param node The IPX network to bind to. An all zero node means the + * computer's node. * @param port The port (sometimes called socket number) to bind to. 0 means to - * pick one and return it. + * pick one and return via the returned socket address. * @return The address on which this socket can be reached - * @throw OFConnectionFailedException Binding failed + * @throw OFBindIPXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ -- (OFSocketAddress)bindToPort: (uint16_t)port; +- (OFSocketAddress) + bindToNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFSPXStreamSocket.m ================================================================== --- src/OFSPXStreamSocket.m +++ src/OFSPXStreamSocket.m @@ -22,12 +22,12 @@ #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" -#import "OFConnectionFailedException.h" +#import "OFBindIPXSocketFailedException.h" +#import "OFConnectSPXSocketFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif @@ -55,11 +55,11 @@ #endif } - (instancetype)initWithSocket: (OFSPXStreamSocket *)socket network: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif ; @@ -67,11 +67,11 @@ @end @implementation OFSPXStreamSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXStreamSocket *)sock network: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif { @@ -166,15 +166,15 @@ #endif } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { - return [OFConnectionFailedException exceptionWithNetwork: _network - node: _node - port: _port - socket: _socket - errNo: errNo]; + return [OFConnectSPXSocketFailedException exceptionWithNetwork: _network + node: _node + port: _port + socket: _socket + errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; @@ -188,11 +188,11 @@ if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if ((_socket = socket(address->sockaddr.ipx.sipx_family, - SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == + SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) { *errNo = OFSocketErrNo(); return false; } @@ -224,48 +224,48 @@ closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) - @throw [OFConnectionFailedException + @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; - @throw [OFConnectionFailedException + @throw [OFConnectSPXSocketFailedException exceptionWithNetwork: network node: node port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port { [self asyncConnectToNetwork: network node: node port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); @@ -282,11 +282,11 @@ objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block { [self asyncConnectToNetwork: network node: node @@ -294,11 +294,11 @@ runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNetwork: (uint32_t)network - node: (unsigned char [_Nonnull IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); @@ -313,30 +313,33 @@ objc_autoreleasePoolPop(pool); } #endif -- (OFSocketAddress)bindToPort: (uint16_t)port +- (OFSocketAddress)bindToNetwork: (uint32_t)network + node: (const unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port { - const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; - address = OFSocketAddressMakeIPX(0, zeroNode, port); + address = OFSocketAddressMakeIPX(network, node, port); if ((_socket = socket(address.sockaddr.ipx.sipx_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) - @throw [OFBindFailedException - exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: OFSocketErrNo()]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) @@ -348,14 +351,17 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); @@ -365,24 +371,30 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: errNo]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: errNo]; } if (address.sockaddr.ipx.sipx_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPort: port - packetType: SPXPacketType - socket: self - errNo: EAFNOSUPPORT]; + @throw [OFBindIPXSocketFailedException + exceptionWithNetwork: network + node: node + port: port + packetType: SPXPacketType + socket: self + errNo: EAFNOSUPPORT]; } return address; } @end Index: src/OFSequencedPacketSocket.h ================================================================== --- src/OFSequencedPacketSocket.h +++ src/OFSequencedPacketSocket.h @@ -303,28 +303,28 @@ /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased sequenced packet socket for the accepted connection. - * @throw OFAcceptFailedException Accepting failed + * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** Index: src/OFSequencedPacketSocket.m ================================================================== --- src/OFSequencedPacketSocket.m +++ src/OFSequencedPacketSocket.m @@ -33,14 +33,14 @@ #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSocket.h" #import "OFSocket+Private.h" -#import "OFAcceptFailedException.h" +#import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" -#import "OFListenFailedException.h" +#import "OFListenOnSocketFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @@ -306,11 +306,11 @@ { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) - @throw [OFListenFailedException + @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; @@ -335,26 +335,26 @@ #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) Index: src/OFSocket.h ================================================================== --- src/OFSocket.h +++ src/OFSocket.h @@ -33,25 +33,33 @@ # include #endif #ifdef OF_HAVE_NETINET_TCP_H # include #endif -#ifdef OF_HAVE_NETIPX_IPX_H -# include -#endif #ifdef OF_HAVE_SYS_UN_H # include #endif #ifdef OF_HAVE_AFUNIX_H # include +#endif +#ifdef OF_HAVE_NETIPX_IPX_H +# include +#endif +#if defined(OF_HAVE_NETAT_APPLETALK_H) +# include +#elif defined(OF_HAVE_NETATALK_AT_H) +# include #endif #ifdef OF_WINDOWS # include # include # ifdef OF_HAVE_IPX # include +# endif +# ifdef OF_HAVE_APPLETALK +# include # endif #endif /** @file */ @@ -101,10 +109,12 @@ OFSocketAddressFamilyIPv6, /** UNIX */ OFSocketAddressFamilyUNIX, /** IPX */ OFSocketAddressFamilyIPX, + /** AppleTalk */ + OFSocketAddressFamilyAppleTalk, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 @@ -142,10 +152,27 @@ # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif +#ifndef OF_HAVE_APPLETALK +struct sockaddr_at { + sa_family_t sat_family; + uint8_t sat_port; + struct at_addr { + uint16_t s_net; + uint8_t s_node; + } sat_addr; +}; +#endif +#ifdef OF_WINDOWS +# define sat_port sat_socket +#else +# define sat_net sat_addr.s_net +# define sat_node sat_addr.s_node +#endif + /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ @@ -158,10 +185,11 @@ union { struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_un un; struct sockaddr_ipx ipx; + struct sockaddr_at at; } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus @@ -205,20 +233,32 @@ * @return A UNIX socket address with the specified path */ extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path); /** - * @brief Creates an IPX address for the specified node, network and port. + * @brief Creates an IPX address for the specified network, node and port. * * @param network The IPX network * @param node The node in the IPX network * @param port The IPX port (sometimes called socket number) on the node * @return An IPX socket address with the specified node, network and port. */ extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port); +/** + * @brief Creates an AppleTalk address for the specified network, node and port. + * + * @param network The AppleTalk network + * @param node The node in the AppleTalk network + * @param port The AppleTalk (sometimes called socket number) on the node + * @return An AppleTalk socket address with the specified node, network and + * port. + */ +extern OFSocketAddress OFSocketAddressMakeAppleTalk(uint16_t network, + uint8_t node, uint8_t port); + /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address @@ -244,27 +284,25 @@ */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** - * @brief Sets the port of the specified @ref OFSocketAddress, independent of - * the address family used. + * @brief Sets the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to set the port * @param port The port to set on the address */ -extern void OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, +extern void OFSocketAddressSetIPPort(OFSocketAddress *_Nonnull address, uint16_t port); /** - * @brief Returns the port of the specified @ref OFSocketAddress, independent of - * the address family used. + * @brief Returns the IP port of the specified @ref OFSocketAddress. * * @param address The address on which to get the port * @return The port of the address */ -extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); +extern uint16_t OFSocketAddressIPPort(const OFSocketAddress *_Nonnull address); /** * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress. * * @param address The address on which to get the UNIX socket path @@ -304,13 +342,84 @@ * @brief Gets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX node * @param node A byte array to store the IPX node of the address */ -extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, +extern void OFSocketAddressGetIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); +/** + * @brief Sets the IPX port of the specified @ref OFSocketAddress. + * + * @param address The address on which to set the port + * @param port The port to set on the address + */ +extern void OFSocketAddressSetIPXPort(OFSocketAddress *_Nonnull address, + uint16_t port); + +/** + * @brief Returns the IPX port of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the port + * @return The port of the address + */ +extern uint16_t OFSocketAddressIPXPort(const OFSocketAddress *_Nonnull address); + +/** + * @brief Sets the AppleTalk network of the specified @ref OFSocketAddress. + * + * @param address The address on which to set the AppleTalk network + * @param network The AppleTalk network to set on the address + */ +extern void OFSocketAddressSetAppleTalkNetwork( + OFSocketAddress *_Nonnull address, uint16_t network); + +/** + * @brief Returns the AppleTalk network of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the AppleTalk network + * @return The AppleTalk network of the address + */ +extern uint16_t OFSocketAddressAppleTalkNetwork( + const OFSocketAddress *_Nonnull address); + +/** + * @brief Sets the AppleTalk node of the specified @ref OFSocketAddress. + * + * @param address The address on which to set the AppleTalk node + * @param node The AppleTalk node to set on the address + */ +extern void OFSocketAddressSetAppleTalkNode(OFSocketAddress *_Nonnull address, + uint8_t node); + +/** + * @brief Gets the AppleTalk node of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the AppleTalk node + * @return The AppleTalk node of the address + */ +extern uint8_t OFSocketAddressAppleTalkNode( + const OFSocketAddress *_Nonnull address); + +/** + * @brief Sets the AppleTalk port of the specified @ref OFSocketAddress. + * + * @param address The address on which to set the port + * @param port The port to set on the address + */ +extern void OFSocketAddressSetAppleTalkPort(OFSocketAddress *_Nonnull address, + uint8_t port); + +/** + * @brief Returns the AppleTalk port of the specified @ref OFSocketAddress. + * + * @param address The address on which to get the port + * @return The port of the address + */ +extern uint8_t OFSocketAddressAppleTalkPort( + const OFSocketAddress *_Nonnull address); + extern bool OFSocketInit(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void OFSocketDeinit(void); #endif extern int OFSocketErrNo(void); Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -45,10 +45,14 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" #import "OFOutOfRangeException.h" #import "OFUnlockFailedException.h" + +#ifdef HAVE_NET_IF_H +# include +#endif #ifdef OF_AMIGAOS # include #endif @@ -431,11 +435,11 @@ OFSocketAddressParseIPv6(OFString *IPv6, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFSocketAddress ret; struct sockaddr_in6 *addrIn6 = &ret.sockaddr.in6; - size_t doubleColon; + size_t doubleColon, percent; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPv6; ret.length = sizeof(ret.sockaddr.in6); @@ -443,13 +447,30 @@ addrIn6->sin6_family = AF_INET6; #else addrIn6->sin6_family = AF_UNSPEC; #endif addrIn6->sin6_port = OFToBigEndian16(port); + + if ((percent = [IPv6 rangeOfString: @"%"].location) != OFNotFound) { + OFString *interface = [IPv6 substringFromIndex: percent + 1]; + IPv6 = [IPv6 substringToIndex: percent]; + + @try { + addrIn6->sin6_scope_id = (uint32_t)[interface + unsignedLongLongValueWithBase: 10]; + } @catch (OFInvalidFormatException *e) { +#if defined(HAVE_IF_NAMETOINDEX) && !defined(OF_WINDOWS) + addrIn6->sin6_scope_id = if_nametoindex([interface + cStringWithEncoding: [OFLocale encoding]]); +#endif + } + + if (addrIn6->sin6_scope_id == 0) + @throw [OFInvalidArgumentException exception]; + } doubleColon = [IPv6 rangeOfString: @"::"].location; - if (doubleColon != OFNotFound) { OFString *left = [IPv6 substringToIndex: doubleColon]; OFString *right = [IPv6 substringFromIndex: doubleColon + 2]; OFArray OF_GENERIC(OFString *) *leftComponents; OFArray OF_GENERIC(OFString *) *rightComponents; @@ -570,18 +591,44 @@ memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port); return ret; } + +OFSocketAddress +OFSocketAddressMakeAppleTalk(uint16_t network, uint8_t node, uint8_t port) +{ + OFSocketAddress ret; + + memset(&ret, '\0', sizeof(ret)); + ret.family = OFSocketAddressFamilyAppleTalk; + ret.length = sizeof(ret.sockaddr.at); + +#ifdef AF_APPLETALK + ret.sockaddr.at.sat_family = AF_APPLETALK; +#else + ret.sockaddr.at.sat_family = AF_UNSPEC; +#endif +#ifdef OF_WINDOWS + ret.sockaddr.at.sat_net = network; +#else + ret.sockaddr.at.sat_net = OFToBigEndian16(network); +#endif + ret.sockaddr.at.sat_node = node; + ret.sockaddr.at.sat_port = port; + + return ret; +} bool OFSocketAddressEqual(const OFSocketAddress *address1, const OFSocketAddress *address2) { const struct sockaddr_in *addrIn1, *addrIn2; const struct sockaddr_in6 *addrIn6_1, *addrIn6_2; const struct sockaddr_ipx *addrIPX1, *addrIPX2; + const struct sockaddr_at *addrAT1, *addrAT2; void *pool; OFString *path1, *path2; bool ret; if (address1->family != address2->family) @@ -655,10 +702,26 @@ return false; if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node, IPX_NODE_LEN) != 0) return false; + return true; + case OFSocketAddressFamilyAppleTalk: + if (address1->length < (socklen_t)sizeof(struct sockaddr_at) || + address2->length < (socklen_t)sizeof(struct sockaddr_at)) + @throw [OFInvalidArgumentException exception]; + + addrAT1 = &address1->sockaddr.at; + addrAT2 = &address2->sockaddr.at; + + if (addrAT1->sat_net != addrAT2->sat_net) + return false; + if (addrAT1->sat_node != addrAT2->sat_node) + return false; + if (addrAT1->sat_port != addrAT2->sat_port) + return false; + return true; default: @throw [OFInvalidArgumentException exception]; } } @@ -731,10 +794,19 @@ for (size_t i = 0; i < IPX_NODE_LEN; i++) OFHashAddByte(&hash, address->sockaddr.ipx.sipx_node[i]); + break; + case OFSocketAddressFamilyAppleTalk: + if (address->length < (socklen_t)sizeof(struct sockaddr_at)) + @throw [OFInvalidArgumentException exception]; + + OFHashAddByte(&hash, address->sockaddr.at.sat_net >> 8); + OFHashAddByte(&hash, address->sockaddr.at.sat_net); + OFHashAddByte(&hash, address->sockaddr.at.sat_port); + break; default: @throw [OFInvalidArgumentException exception]; } @@ -816,10 +888,21 @@ (addrIn6->sin6_addr.s6_addr[i] << 8) | addrIn6->sin6_addr.s6_addr[i + 1]]; first = false; } } + + if (addrIn6->sin6_scope_id != 0) { +#if defined(HAVE_IF_INDEXTONAME) && !defined(OF_WINDOWS) + char interface[IF_NAMESIZE]; + + if (if_indextoname(addrIn6->sin6_scope_id, interface) != NULL) + [string appendFormat: @"%%%s", interface]; + else +# endif + [string appendFormat: @"%%%u", addrIn6->sin6_scope_id]; + } [string makeImmutable]; return string; } @@ -836,37 +919,32 @@ @throw [OFInvalidArgumentException exception]; } } void -OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port) +OFSocketAddressSetIPPort(OFSocketAddress *address, uint16_t port) { switch (address->family) { case OFSocketAddressFamilyIPv4: address->sockaddr.in.sin_port = OFToBigEndian16(port); break; case OFSocketAddressFamilyIPv6: address->sockaddr.in6.sin6_port = OFToBigEndian16(port); break; - case OFSocketAddressFamilyIPX: - address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); - break; default: @throw [OFInvalidArgumentException exception]; } } uint16_t -OFSocketAddressPort(const OFSocketAddress *address) +OFSocketAddressIPPort(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return OFFromBigEndian16(address->sockaddr.in.sin_port); case OFSocketAddressFamilyIPv6: return OFFromBigEndian16(address->sockaddr.in6.sin6_port); - case OFSocketAddressFamilyIPX: - return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); default: @throw [OFInvalidArgumentException exception]; } } @@ -925,13 +1003,93 @@ memcpy(address->sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); } void -OFSocketAddressIPXNode(const OFSocketAddress *address, +OFSocketAddressGetIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN]) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } + +void +OFSocketAddressSetIPXPort(OFSocketAddress *address, uint16_t port) +{ + if (address->family != OFSocketAddressFamilyIPX) + @throw [OFInvalidArgumentException exception]; + + address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); +} + +uint16_t +OFSocketAddressIPXPort(const OFSocketAddress *address) +{ + if (address->family != OFSocketAddressFamilyIPX) + @throw [OFInvalidArgumentException exception]; + + return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); +} + +void +OFSocketAddressSetAppleTalkNetwork(OFSocketAddress *address, uint16_t network) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + +#ifdef OF_WINDOWS + address->sockaddr.at.sat_net = network; +#else + address->sockaddr.at.sat_net = OFToBigEndian16(network); +#endif +} + +uint16_t +OFSocketAddressAppleTalkNetwork(const OFSocketAddress *address) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + +#ifdef OF_WINDOWS + return address->sockaddr.at.sat_net; +#else + return OFFromBigEndian16(address->sockaddr.at.sat_net); +#endif +} + +void +OFSocketAddressSetAppleTalkNode(OFSocketAddress *address, uint8_t node) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + + address->sockaddr.at.sat_node = node; +} + +uint8_t +OFSocketAddressAppleTalkNode(const OFSocketAddress *address) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + + return address->sockaddr.at.sat_node; +} + +void +OFSocketAddressSetAppleTalkPort(OFSocketAddress *address, uint8_t port) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + + address->sockaddr.at.sat_port = port; +} + +uint8_t +OFSocketAddressAppleTalkPort(const OFSocketAddress *address) +{ + if (address->family != OFSocketAddressFamilyAppleTalk) + @throw [OFInvalidArgumentException exception]; + + return address->sockaddr.at.sat_port; +} Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -104,28 +104,28 @@ /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * - * @throw OFListenFailedException Listening failed + * @throw OFListenOnSocketFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased OFStreamSocket for the accepted connection. - * @throw OFAcceptFailedException Accepting failed + * @throw OFAcceptSocketFailedException Accepting failed * @throw OFNotOpenException The socket is not open */ - (instancetype)accept; /** Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -29,14 +29,14 @@ #import "OFStreamSocket+Private.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket+Private.h" -#import "OFAcceptFailedException.h" +#import "OFAcceptSocketFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" -#import "OFListenFailedException.h" +#import "OFListenOnSocketFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" @@ -231,11 +231,11 @@ { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) - @throw [OFListenFailedException + @throw [OFListenOnSocketFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; @@ -256,26 +256,26 @@ #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, (struct sockaddr * )&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) - @throw [OFAcceptFailedException + @throw [OFAcceptSocketFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) Index: src/OFString+Serialization.h ================================================================== --- src/OFString+Serialization.h +++ src/OFString+Serialization.h @@ -26,10 +26,17 @@ #endif @interface OFString (Serialization) /** * @brief The string interpreted as serialization and parsed as an object. + * + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundNamespaceException A prefix was used that was not bound to + * any namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified + * @throw OFUnsupportedVersionException The serialization is in an unsupported + * version */ @property (readonly, nonatomic) id objectByDeserializing; @end OF_ASSUME_NONNULL_END Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -36,17 +36,11 @@ OFXMLElement *root; OFString *version; OFArray *elements; id object; - @try { - root = [OFXMLElement elementWithXMLString: self]; - } @catch (OFMalformedXMLException *e) { - @throw [OFInvalidArgumentException exception]; - } @catch (OFUnboundNamespaceException *e) { - @throw [OFInvalidArgumentException exception]; - } + root = [OFXMLElement elementWithXMLString: self]; version = [root attributeForName: @"version"].stringValue; if (version == nil) @throw [OFInvalidArgumentException exception]; Index: src/OFString+XMLUnescaping.h ================================================================== --- src/OFString+XMLUnescaping.h +++ src/OFString+XMLUnescaping.h @@ -72,10 +72,12 @@ /** * @brief Unescapes XML in the string and uses the specified delegate for * unknown entities. * * @param delegate An OFXMLUnescapingDelegate as a handler for unknown entities + * @throw OFInvalidFormatException The string is not a valid XML string + * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithDelegate: (nullable id )delegate; #ifdef OF_HAVE_BLOCKS @@ -82,11 +84,13 @@ /** * @brief Unescapes XML in the string and uses the specified block for unknown * entities. * * @param block A block which handles unknown entities + * @throw OFInvalidFormatException The string is not a valid XML string + * @throw OFUnknownXMLEntityException The string contains unknown XML entities */ - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block; #endif @end OF_ASSUME_NONNULL_END Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -210,20 +210,20 @@ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The float value of the string as a float. * - * If the string contains any non-number characters, an - * @ref OFInvalidFormatException is thrown. + * @throw OFInvalidFormatException The string cannot be parsed as a `float` + * @throw OFOutOfRangeException The value cannot be represented as a `float` */ @property (readonly, nonatomic) float floatValue; /** * @brief The double value of the string as a double. * - * If the string contains any non-number characters, an - * @ref OFInvalidFormatException is thrown. + * @throw OFInvalidFormatException The string cannot be parsed as a `double` + * @throw OFOutOfRangeException The value cannot be represented as a `double` */ @property (readonly, nonatomic) double doubleValue; /** * @brief The string as an array of Unicode characters. @@ -312,10 +312,11 @@ /** * @brief Creates a new OFString from a UTF-8 encoded C string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String; /** * @brief Creates a new OFString from a UTF-8 encoded C string with the @@ -322,10 +323,11 @@ * specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** @@ -339,10 +341,11 @@ * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** @@ -357,10 +360,11 @@ * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when the OFString gets * deallocated * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; @@ -368,10 +372,11 @@ * @brief Creates a new OFString from a C string with the specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** @@ -380,10 +385,11 @@ * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; @@ -391,10 +397,11 @@ * @brief Creates a new OFString from OFData with the specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** @@ -419,10 +426,11 @@ /** * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string A zero-terminated UTF-16 string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string; /** * @brief Creates a new OFString from a UTF-16 encoded string with the @@ -429,10 +437,11 @@ * specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** @@ -440,10 +449,11 @@ * specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** @@ -453,10 +463,11 @@ * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; @@ -511,10 +522,13 @@ * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; # ifdef OF_HAVE_FILES /** @@ -521,10 +535,11 @@ * @brief Creates a new OFString with the contents of the specified UTF-8 * encoded file. * * @param path The path to the file * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ + (instancetype)stringWithContentsOfFile: (OFString *)path; /** * @brief Creates a new OFString with the contents of the specified file in the @@ -531,10 +546,11 @@ * specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif @@ -547,10 +563,11 @@ * headers. If it could not detect the encoding using the HTTP headers, it tries * UTF-8. * * @param URI The URI to the contents for the string * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the expected encoding */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI; /** * @brief Creates a new OFString with the contents of the specified URI in the @@ -557,10 +574,11 @@ * specified encoding. * * @param URI The URI to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** @@ -567,10 +585,11 @@ * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C @@ -577,10 +596,11 @@ * string with the specified length. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** @@ -594,10 +614,11 @@ * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone; /** @@ -613,10 +634,11 @@ * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @param UTF8StringLength The length of the UTF-8 encoded C string * @param freeWhenDone Whether to free the C string when it is not needed * anymore * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone; @@ -625,10 +647,11 @@ * specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** @@ -637,10 +660,11 @@ * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; @@ -649,10 +673,11 @@ * specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** @@ -677,10 +702,11 @@ /** * @brief Initializes an already allocated OFString with a UTF-16 string. * * @param string A zero-terminated UTF-16 string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string; /** * @brief Initializes an already allocated OFString with a UTF-16 string with @@ -687,10 +713,11 @@ * the specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** @@ -698,10 +725,11 @@ * assuming the specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** @@ -711,10 +739,11 @@ * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-16-encoded */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; @@ -769,10 +798,13 @@ * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return An initialized OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format, ...; /** * @brief Initializes an already allocated OFString with a format string. @@ -782,10 +814,13 @@ * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString + * @throw OFInvalidFormatException The specified format is invalid + * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 + * encoding */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; # ifdef OF_HAVE_FILES @@ -793,10 +828,11 @@ * @brief Initializes an already allocated OFString with the contents of the * specified file in the specified encoding. * * @param path The path to the file * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not properly UTF-8-encoded */ - (instancetype)initWithContentsOfFile: (OFString *)path; /** * @brief Initializes an already allocated OFString with the contents of the @@ -803,10 +839,11 @@ * specified file in the specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif @@ -820,10 +857,11 @@ * headers. If it could not detect the encoding using the HTTP headers, it tries * UTF-8. * * @param URI The URI to the contents for the string * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the expected encoding */ - (instancetype)initWithContentsOfURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFString with the contents of the @@ -830,10 +868,11 @@ * specified URI in the specified encoding. * * @param URI The URI to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString + * @throw OFInvalidEncodingException The string is not in the specified encoding */ - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** @@ -844,10 +883,12 @@ * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; @@ -874,10 +915,12 @@ * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (const char *)cStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** @@ -899,10 +942,12 @@ * @brief Returns the number of bytes the string needs in the specified * encoding. * * @param encoding The encoding for the string * @return The number of bytes the string needs in the specified encoding. + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding; /** * @brief Compares the string to another string. @@ -1049,10 +1094,12 @@ * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base + * @throw OFInvalidFormatException The string cannot be parsed as a `long long` + * @throw OFOutOfRangeException The value cannot be represented as a `long long` */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The value of the string in the specified base as an @@ -1069,10 +1116,14 @@ * @param base The base to use. If the base is 0, base 16 is assumed if the * string starts with 0x (after stripping white spaces). If the * string starts with 0, base 8 is assumed. Otherwise, base 10 is * assumed. * @return The value of the string in the specified base + * @throw OFInvalidFormatException The string cannot be parsed as an + * `unsigned long long` + * @throw OFOutOfRangeException The value cannot be represented as an + * `unsigned long long` */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; /** * @brief Creates a new string by appending another string. @@ -1085,19 +1136,25 @@ /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @return A new, autoreleased OFString with the specified format appended + * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded + * after formatting it + * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ...; /** * @brief Creates a new string by appending the specified format. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @return A new, autoreleased OFString with the specified format appended + * @throw OFInvalidEncodingException The string was not properly UTF-8-encoded + * after formatting it + * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; /** @@ -1197,10 +1254,11 @@ * * The returned string is null-terminated. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order + * @throw OFInvalidEncodingException The string cannot be represented in UTF-16 */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** @@ -1221,10 +1279,12 @@ /** * @brief Returns the string as OFData with the specified encoding. * * @param encoding The encoding to use for the returned OFData * @return The string as OFData with the specified encoding + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (OFData *)dataWithEncoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_FILES /** @@ -1238,10 +1298,12 @@ * @brief Writes the string into the specified file using the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** @@ -1254,10 +1316,12 @@ /** * @brief Writes the string to the specified URI using the specified encoding. * * @param URI The URI to write to * @param encoding The encoding to use to write the string to the URI + * @throw OFInvalidEncodingException The string cannot be represented in the + * specified encoding */ - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_BLOCKS /** Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -992,75 +992,58 @@ } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { - char *tmp; - unsigned long long fileSize; + char *buffer = NULL; + OFStreamOffset fileSize; @try { void *pool = objc_autoreleasePoolPush(); - OFFile *file = nil; - - @try { - fileSize = [[OFFileManager defaultManager] - attributesOfItemAtPath: path].fileSize; - } @catch (OFGetItemAttributesFailedException *e) { - @throw [OFOpenItemFailedException - exceptionWithPath: path - mode: @"r" - errNo: e.errNo]; - } - - objc_autoreleasePoolPop(pool); - -# if ULLONG_MAX > SIZE_MAX - if (fileSize > SIZE_MAX) - @throw [OFOutOfRangeException exception]; -#endif + OFFile *file = [OFFile fileWithPath: path mode: @"r"]; + fileSize = [file seekToOffset: 0 whence: OFSeekEnd]; + + if (fileSize < 0 || (unsigned long long)fileSize > SIZE_MAX) + @throw [OFOutOfRangeException exception]; /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; - tmp = OFAllocMemory((size_t)fileSize + 1, 1); - @try { - file = [[OFFile alloc] initWithPath: path mode: @"r"]; - [file readIntoBuffer: tmp - exactLength: (size_t)fileSize]; - } @catch (id e) { - OFFreeMemory(tmp); - @throw e; - } @finally { - [file release]; - } - - tmp[(size_t)fileSize] = '\0'; - } @catch (id e) { + [file seekToOffset: 0 whence: OFSeekSet]; + + buffer = OFAllocMemory((size_t)fileSize + 1, 1); + [file readIntoBuffer: buffer exactLength: (size_t)fileSize]; + buffer[(size_t)fileSize] = '\0'; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + OFFreeMemory(buffer); [self release]; + @throw e; } if (encoding == OFStringEncodingUTF8) { @try { - self = [self initWithUTF8StringNoCopy: tmp + self = [self initWithUTF8StringNoCopy: buffer length: (size_t)fileSize freeWhenDone: true]; } @catch (id e) { - OFFreeMemory(tmp); + OFFreeMemory(buffer); @throw e; } } else { @try { - self = [self initWithCString: tmp + self = [self initWithCString: buffer encoding: encoding length: (size_t)fileSize]; } @finally { - OFFreeMemory(tmp); + OFFreeMemory(buffer); } } return self; } Index: src/OFSubprocess.h ================================================================== --- src/OFSubprocess.h +++ src/OFSubprocess.h @@ -192,18 +192,23 @@ * @brief Closes the write direction of the subprocess. * * This method needs to be called for some programs before data can be read, * since some programs don't start processing before the write direction is * closed. + * + * @throw OFNotOpenException The subprocess was already closed */ - (void)closeForWriting; /** * @brief Waits for the subprocess to terminate and returns the exit status. * * If the subprocess has already exited, this returns the exit status * immediately. + * + * @return The status code of the subprocess + * @throw OFNotOpenException The subprocess was already closed */ - (int)waitForTermination; @end OF_ASSUME_NONNULL_END Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -68,10 +68,14 @@ # include #endif #ifdef OF_QNX # include #endif + +#if !defined(PATH_MAX) && defined(MAX_PATH) +# define PATH_MAX MAX_PATH +#endif #if defined(OF_MACOS) || defined(OF_IOS) /* * These have been dropped from newer iOS SDKs, however, their replacements are * not available on iOS < 10. This means it's impossible to search for the Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -154,11 +154,11 @@ /** * @brief Connects the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to - * @throw OFConnectionFailedException Connecting failed + * @throw OFConnectIPSocketFailedException Connecting failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** @@ -212,12 +212,12 @@ * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to - * @throw OFBindFailedException Binding failed + * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -42,11 +42,11 @@ #import "OFString.h" #import "OFTCPSocketSOCKS5Connector.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" +#import "OFBindIPSocketFailedException.h" #import "OFGetOptionFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFSetOptionFailedException.h" @@ -309,16 +309,16 @@ socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; - OFSocketAddressSetPort(&address, port); + OFSocketAddressSetIPPort(&address, port); if ((_socket = socket( ((struct sockaddr *)&address.sockaddr)->sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: OFSocketErrNo()]; @@ -340,14 +340,15 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; + @throw [OFBindIPSocketFailedException + exceptionWithHost: host + port: port + socket: self + errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; @@ -354,11 +355,11 @@ int ret; while (rnd < 1024) rnd = (uint16_t)rand(); - OFSocketAddressSetPort(&address, rnd); + OFSocketAddressSetIPPort(&address, rnd); if ((ret = bind(_socket, (struct sockaddr *)&address.sockaddr, address.length)) == 0) { port = rnd; @@ -369,11 +370,11 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } @@ -395,14 +396,14 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: errNo]; + @throw [OFBindIPSocketFailedException exceptionWithHost: host + port: port + socket: self + errNo: errNo]; } switch (((struct sockaddr *)&address.sockaddr)->sa_family) { case AF_INET: return OFFromBigEndian16(address.sockaddr.in.sin_port); @@ -412,22 +413,23 @@ # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EAFNOSUPPORT]; + @throw [OFBindIPSocketFailedException + exceptionWithHost: host + port: port + socket: self + errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithHost: host - port: port - socket: self - errNo: EADDRNOTAVAIL]; + @throw [OFBindIPSocketFailedException exceptionWithHost: host + port: port + socket: self + errNo: EADDRNOTAVAIL]; #endif } #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) - (void)setSendsKeepAlives: (bool)sendsKeepAlives Index: src/OFTCPSocketSOCKS5Connector.m ================================================================== --- src/OFTCPSocketSOCKS5Connector.m +++ src/OFTCPSocketSOCKS5Connector.m @@ -21,11 +21,11 @@ #import "OFTCPSocketSOCKS5Connector.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFString.h" -#import "OFConnectionFailedException.h" +#import "OFConnectIPSocketFailedException.h" enum { stateSendAuthentication = 1, stateReadVersion, stateSendRequest, @@ -142,11 +142,11 @@ switch (_SOCKS5State) { case stateReadVersion: SOCKSVersion = buffer; if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) { - _exception = [[OFConnectionFailedException alloc] + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; @@ -171,11 +171,11 @@ return false; case stateReadResponse: response = buffer; if (response[0] != 5 || response[2] != 0) { - _exception = [[OFConnectionFailedException alloc] + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; @@ -214,11 +214,11 @@ errNo = 0; #endif break; } - _exception = [[OFConnectionFailedException alloc] + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; @@ -244,11 +244,11 @@ [_socket asyncReadIntoBuffer: _buffer exactLength: 16 + 2 runLoopMode: runLoopMode]; return false; default: - _exception = [[OFConnectionFailedException alloc] + _exception = [[OFConnectIPSocketFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; Index: src/OFTLSStream.h ================================================================== --- src/OFTLSStream.h +++ src/OFTLSStream.h @@ -126,28 +126,33 @@ /** * @brief Asynchronously performs the TLS client handshake for the specified * host and calls the delegate afterwards. * * @param host The host to perform the handshake with + * @throw OFTLSHandshakeFailedException The TLS handshake failed + * @throw OFAlreadyConnectedException The handshake was already performed */ - (void)asyncPerformClientHandshakeWithHost: (OFString *)host; /** * @brief Asynchronously performs the TLS client handshake for the specified * host and calls the delegate afterwards. * * @param host The host to perform the handshake with * @param runLoopMode The run loop mode in which to perform the async handshake + * @throw OFTLSHandshakeFailedException The TLS handshake failed + * @throw OFAlreadyConnectedException The handshake was already performed */ - (void)asyncPerformClientHandshakeWithHost: (OFString *)host runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Performs the TLS client handshake for the specified host. * * @param host The host to perform the handshake with * @throw OFTLSHandshakeFailedException The TLS handshake failed + * @throw OFAlreadyConnectedException The handshake was already performed */ - (void)performClientHandshakeWithHost: (OFString *)host; @end #ifdef __cplusplus Index: src/OFTarArchive.h ================================================================== --- src/OFTarArchive.h +++ src/OFTarArchive.h @@ -48,29 +48,22 @@ /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; -/** - * @brief A stream for reading the current entry. - * - * @note This is only available in read mode. - * - * @note The returned stream conforms to @ref OFReadyForReadingObserving if the - * underlying stream does so, too. - */ -@property (readonly, nonatomic) OFStream *streamForReadingCurrentEntry; - /** * @brief Creates a new OFTarArchive object with the specified stream. * * @param stream A stream from which the tar archive will be read. * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive + * @throw OFInvalidFormatException The archive has an invalid format + * @throw OFSeekFailedException The archive was open in append mode and seeking + * failed */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFTarArchive object with the specified file. @@ -78,10 +71,13 @@ * @param URI The URI to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive + * @throw OFInvalidFormatException The archive has an invalid format + * @throw OFSeekFailedException The archive was open in append mode and seeking + * failed */ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Creates a URI for accessing a the specified file within the specified @@ -104,10 +100,13 @@ * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive + * @throw OFInvalidFormatException The archive has an invalid format + * @throw OFSeekFailedException The archive was open in append mode and seeking + * failed */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** @@ -117,10 +116,13 @@ * @param URI The URI to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive + * @throw OFInvalidFormatException The archive has an invalid format + * @throw OFSeekFailedException The archive was open in append mode and seeking + * failed */ - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns the next entry from the tar archive or `nil` if all entries @@ -134,13 +136,26 @@ * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @return The next entry from the tar archive or `nil` if all entries have * been read + * @throw OFInvalidFormatException The archive has an invalid format */ - (nullable OFTarArchiveEntry *)nextEntry; +/** + * @brief Returns a stream for reading the current entry. + * + * @note This is only available in read mode. + * + * @note The returned stream conforms to @ref OFReadyForReadingObserving if the + * underlying stream does so, too. + * + * @return A stream for reading the current entry + */ +- (OFStream *)streamForReadingCurrentEntry; + /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. * @@ -158,10 +173,12 @@ */ - (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry; /** * @brief Closes the OFTarArchive. + * + * @throw OFNotOpenException The archive is not open */ - (void)close; @end OF_ASSUME_NONNULL_END Index: src/OFTarArchiveEntry.m ================================================================== --- src/OFTarArchiveEntry.m +++ src/OFTarArchiveEntry.m @@ -73,10 +73,16 @@ return value; } @implementation OFTarArchiveEntry +/* + * The following is optional in OFArchiveEntry, but Apple GCC 4.0.1 is buggy + * and needs this to stop complaining. + */ +@dynamic fileComment; + - (instancetype)init { OF_INVALID_INIT_METHOD } DELETED src/OFTarURIHandler.h Index: src/OFTarURIHandler.h ================================================================== --- src/OFTarURIHandler.h +++ src/OFTarURIHandler.h @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFURIHandler.h" - -OF_ASSUME_NONNULL_BEGIN - -@interface OFTarURIHandler: OFURIHandler -@end - -OF_ASSUME_NONNULL_END Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -132,26 +132,36 @@ * @note This has to be set before the thread is started! * * This is a value between -1.0 (meaning lowest priority that still schedules) * and +1.0 (meaning highest priority that still allows getting preempted) * with normal priority being 0.0 (meaning being the same as the main thread). + * + * @throw OFThreadStillRunningException The thread is already/still running and + * thus the priority cannot be changed */ @property (nonatomic) float priority; /** * @brief The stack size of the thread. * * @note This has to be set before the thread is started! + * + * @throw OFThreadStillRunningException The thread is already/still running and + * thus the stack size cannot be changed */ @property (nonatomic) size_t stackSize; /** * @brief Whether the thread supports sockets. * * Some operating systems such as AmigaOS need special per-thread * initialization of sockets. If you intend to use sockets in the thread, set * this property to true before starting the thread. + * + * @throw OFThreadStillRunningException The thread is already/still running and + * thus the sockets support cannot be + * enabled/disabled */ @property (nonatomic) bool supportsSockets; /** * @brief Creates a new thread. @@ -241,10 +251,11 @@ /** * @brief Terminates the current thread, letting it return the specified object. * * @param object The object which the terminated thread will return + * @throw OFInvalidArgumentException The method was called from the main thread */ + (void)terminateWithObject: (nullable id)object OF_NO_RETURN; /** * @brief Sets the name of the current thread. @@ -288,20 +299,24 @@ */ - (void)handleTermination OF_REQUIRES_SUPER; /** * @brief Starts the thread. + * + * @throw OFStartThreadFailedException Starting the thread failed + * @throw OFThreadStillRunningException The thread is still running */ - (void)start; /** * @brief Joins a thread. * * @return The object returned by the main method of the thread. + * @throw OFJoinThreadFailedException Joining the thread failed */ - (id)join; #else - (instancetype)init OF_UNAVAILABLE; #endif @end OF_ASSUME_NONNULL_END Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -73,12 +73,12 @@ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #ifdef OF_HAVE_THREADS -# import "OFThreadJoinFailedException.h" -# import "OFThreadStartFailedException.h" +# import "OFJoinThreadFailedException.h" +# import "OFStartThreadFailedException.h" # import "OFThreadStillRunningException.h" #endif #ifdef OF_MINT /* freemint-gcc does not have trunc() */ @@ -435,11 +435,11 @@ _running = OFThreadStateRunning; if ((error = OFPlainThreadNew(&_thread, [_name cStringWithEncoding: [OFLocale encoding]], callMain, self, &_attr)) != 0) { [self release]; - @throw [OFThreadStartFailedException + @throw [OFStartThreadFailedException exceptionWithThread: self errNo: error]; } } @@ -446,16 +446,16 @@ - (id)join { int error; if (_running == OFThreadStateNotRunning) - @throw [OFThreadJoinFailedException + @throw [OFJoinThreadFailedException exceptionWithThread: self errNo: EINVAL]; if ((error = OFPlainThreadJoin(_thread)) != 0) - @throw [OFThreadJoinFailedException exceptionWithThread: self + @throw [OFJoinThreadFailedException exceptionWithThread: self errNo: error]; _running = OFThreadStateNotRunning; return _returnValue; Index: src/OFUDPSocket.h ================================================================== --- src/OFUDPSocket.h +++ src/OFUDPSocket.h @@ -33,11 +33,11 @@ * @brief A class which provides methods to create and use UDP sockets. * * Addresses are of type @ref OFSocketAddress. You can use the current thread's * @ref OFDNSResolver to create an address for a host / port pair, * @ref OFSocketAddressString to get the IP address string for an address and - * @ref OFSocketAddressPort to get the port for an address. If you want to + * @ref OFSocketAddressIPPort to get the port for an address. If you want to * compare two addresses, you can use * @ref OFSocketAddressEqual and you can use @ref OFSocketAddressHash to get a * hash to use in e.g. @ref OFMapTable. * * @warning Even though the OFCopying protocol is implemented, it does *not* @@ -70,12 +70,12 @@ * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to - * @throw OFBindFailedException Binding failed + * @throw OFBindIPSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END Index: src/OFUDPSocket.m ================================================================== --- src/OFUDPSocket.m +++ src/OFUDPSocket.m @@ -33,11 +33,11 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" +#import "OFBindIPSocketFailedException.h" @implementation OFUDPSocket @dynamic delegate; - (uint16_t)of_bindToAddress: (OFSocketAddress *)address @@ -50,13 +50,13 @@ #endif if ((_socket = socket( ((struct sockaddr *)&address->sockaddr)->sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -66,22 +66,22 @@ fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); } #endif #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) - if (OFSocketAddressPort(address) != 0) { + if (OFSocketAddressIPPort(address) != 0) { #endif if (bind(_socket, (struct sockaddr *)&address->sockaddr, address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { @@ -90,26 +90,26 @@ int ret; while (rnd < 1024) rnd = (uint16_t)rand(); - OFSocketAddressSetPort(address, rnd); + OFSocketAddressSetIPPort(address, rnd); if ((ret = bind(_socket, (struct sockaddr *)&address->sockaddr, address->length)) == 0) break; if (OFSocketErrNo() != EADDRINUSE) { int errNo = OFSocketErrNo(); OFString *host = OFSocketAddressString(address); - port = OFSocketAddressPort(address); + port = OFSocketAddressIPPort(address); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } @@ -117,11 +117,11 @@ } #endif objc_autoreleasePoolPop(pool); - if ((port = OFSocketAddressPort(address)) > 0) + if ((port = OFSocketAddressIPPort(address)) > 0) return port; #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(address, 0, sizeof(*address)); @@ -131,13 +131,13 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: errNo]; } switch (((struct sockaddr *)&address->sockaddr)->sa_family) { @@ -149,23 +149,23 @@ # endif default: closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException + @throw [OFBindIPSocketFailedException exceptionWithHost: OFSocketAddressString(address) - port: OFSocketAddressPort(address) + port: OFSocketAddressIPPort(address) socket: self errNo: EADDRNOTAVAIL]; #endif } @@ -181,14 +181,14 @@ socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; - OFSocketAddressSetPort(&address, port); + OFSocketAddressSetIPPort(&address, port); port = [self of_bindToAddress: &address extraType: 0]; objc_autoreleasePoolPop(pool); return port; } @end Index: src/OFUNIXDatagramSocket.h ================================================================== --- src/OFUNIXDatagramSocket.h +++ src/OFUNIXDatagramSocket.h @@ -63,12 +63,12 @@ /** * @brief Bind the socket to the specified path. * * @param path The path to bind to * @return The address on which this socket can be reached - * @throw OFBindFailedException Binding failed + * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already bound */ - (OFSocketAddress)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END Index: src/OFUNIXDatagramSocket.m ================================================================== --- src/OFUNIXDatagramSocket.m +++ src/OFUNIXDatagramSocket.m @@ -23,11 +23,11 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" +#import "OFBindUNIXSocketFailedException.h" @implementation OFUNIXDatagramSocket @dynamic delegate; - (OFSocketAddress)bindToPath: (OFString *)path @@ -42,11 +42,11 @@ address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindFailedException + @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -61,13 +61,14 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPath: path - socket: self - errNo: errNo]; + @throw [OFBindUNIXSocketFailedException + exceptionWithPath: path + socket: self + errNo: errNo]; } return address; } @end Index: src/OFUNIXStreamSocket.h ================================================================== --- src/OFUNIXStreamSocket.h +++ src/OFUNIXStreamSocket.h @@ -52,21 +52,21 @@ /** * @brief Connects the OFUNIXStreamSocket to the specified destination. * * @param path The path to connect to - * @throw OFConnectionFailedException Connecting failed + * @throw OFConnectUNIXSocketFailedException Connecting failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToPath: (OFString *)path; /** * @brief Binds the socket to the specified host and port. * * @param path The path to bind to - * @throw OFBindFailedException Binding failed + * @throw OFBindUNIXSocketFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END Index: src/OFUNIXStreamSocket.m ================================================================== --- src/OFUNIXStreamSocket.m +++ src/OFUNIXStreamSocket.m @@ -23,12 +23,12 @@ #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFAlreadyConnectedException.h" -#import "OFBindFailedException.h" -#import "OFConnectionFailedException.h" +#import "OFBindUNIXSocketFailedException.h" +#import "OFConnectUNIXSocketFailedException.h" @implementation OFUNIXStreamSocket @dynamic delegate; - (void)connectToPath: (OFString *)path @@ -43,11 +43,11 @@ address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFConnectionFailedException + @throw [OFConnectUNIXSocketFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -62,13 +62,14 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFConnectionFailedException exceptionWithPath: path - socket: self - errNo: errNo]; + @throw [OFConnectUNIXSocketFailedException + exceptionWithPath: path + socket: self + errNo: errNo]; } } - (void)bindToPath: (OFString *)path { @@ -82,11 +83,11 @@ address = OFSocketAddressMakeUNIX(path); if ((_socket = socket(address.sockaddr.un.sun_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) - @throw [OFBindFailedException + @throw [OFBindUNIXSocketFailedException exceptionWithPath: path socket: self errNo: OFSocketErrNo()]; _canBlock = true; @@ -101,11 +102,12 @@ int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; - @throw [OFBindFailedException exceptionWithPath: path - socket: self - errNo: errNo]; + @throw [OFBindUNIXSocketFailedException + exceptionWithPath: path + socket: self + errNo: errNo]; } } @end Index: src/OFURI.h ================================================================== --- src/OFURI.h +++ src/OFURI.h @@ -199,10 +199,11 @@ * If a directory exists at the specified path, a slash is appended if there is * no slash yet. * * @param path The local file path * @return A new, autoreleased OFURI + * @throw OFInvalidFormatException The specified path is not a valid path */ + (instancetype)fileURIWithPath: (OFString *)path; /** * @brief Creates a new URI with the specified local file path. @@ -246,10 +247,11 @@ * If a directory exists at the specified path, a slash is appended if there is * no slash yet. * * @param path The local file path * @return An initialized OFURI + * @throw OFInvalidFormatException The specified path is not a valid path */ - (instancetype)initFileURIWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFURI with the specified local file Index: src/OFWindowsRegistryKey.h ================================================================== --- src/OFWindowsRegistryKey.h +++ src/OFWindowsRegistryKey.h @@ -77,10 +77,11 @@ * @param accessRights Please refer to the `RegOpenKeyEx()` documentation for * `samDesired` * @param options Please refer to the `RegOpenKeyEx()` documentation for * `ulOptions`. Usually 0. * @return The subkey with the specified path + * @throw OFOpenWindowsRegistryKeyFailedException Opening the key failed */ - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options; /** @@ -98,10 +99,11 @@ * @param disposition A pointer to a variable that will be set to whether the * key was created or already existed, or `NULL`. Please * refer to the `RegCreateKeyEx()` documentation for * `lpdwDisposition`. * @return The subkey with the specified path + * @throw OFCreateWindowsRegistryKeyFailedException Creating the key failed */ - (OFWindowsRegistryKey *) createSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes @@ -112,10 +114,11 @@ * @brief Returns the data for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The data for the specified value + * @throw OFGetWindowsRegistryValueFailedException Getting the value failed */ - (nullable OFData *)dataForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** @@ -122,10 +125,11 @@ * @brief Sets the data for the specified value. * * @param data The data to set the value to * @param name The name of the value to set * @param type The type for the value + * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setData: (nullable OFData *)data forValueNamed: (nullable OFString *)name type: (DWORD)type; @@ -132,28 +136,33 @@ /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @return The string for the specified value + * @throw OFGetWindowsRegistryValueFailedException Getting the value failed + * @throw OFInvalidEncodingException The encoding of the value is invalid */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name; /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The string for the specified value + * @throw OFGetWindowsRegistryValueFailedException Getting the value failed + * @throw OFInvalidEncodingException The encoding of the value is invalid */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set + * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name; /** @@ -160,10 +169,11 @@ * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set * @param type The type for the value + * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name type: (DWORD)type; @@ -170,48 +180,56 @@ /** * @brief Returns the DWORD for the specified value at the specified path. * * @param name The name of the value to return * @return The DWORD for the specified value + * @throw OFGetWindowsRegistryValueFailedException Getting the value failed + * @throw OFUndefinedKeyException There is no value with the specified key */ - (uint32_t)DWORDForValueNamed: (nullable OFString *)name; /** * @brief Sets the DWORD for the specified value. * * @param dword The DWORD to set the value to * @param name The name of the value to set + * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setDWORD: (uint32_t)dword forValueNamed: (nullable OFString *)name; /** * @brief Returns the QWORD for the specified value at the specified path. * * @param name The name of the value to return * @return The QWORD for the specified value + * @throw OFGetWindowsRegistryValueFailedException Getting the value failed + * @throw OFUndefinedKeyException There is no value with the specified key */ - (uint64_t)QWORDForValueNamed: (nullable OFString *)name; /** * @brief Sets the QWORD for the specified value. * * @param qword The QWORD to set the value to * @param name The name of the value to set + * @throw OFSetWindowsRegistryValueFailedException Setting the value failed */ - (void)setQWORD: (uint64_t)qword forValueNamed: (nullable OFString *)name; /** * @brief Deletes the specified value. * * @param name The value to delete + * @throw OFDeleteWindowsRegistryValueFailedException Deleting the value failed */ - (void)deleteValueNamed: (nullable OFString *)name; /** * @brief Deletes the specified subkey. * * @param subkeyPath The path of the subkey to delete + * @throw OFDeleteWindowsRegistryKeyFailedException Deleting the key failed */ - (void)deleteSubkeyAtPath: (OFString *)subkeyPath; @end OF_ASSUME_NONNULL_END Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -119,19 +119,27 @@ /** * @brief Parses the string and returns an OFXMLElement for it. * * @param string The string to parse * @return A new autoreleased OFXMLElement with the contents of the string + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ + (instancetype)elementWithXMLString: (OFString *)string; /** * @brief Parses the specified stream and returns an OFXMLElement for it. * * @param stream The stream to parse * @return A new autoreleased OFXMLElement with the contents of the specified * stream + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ + (instancetype)elementWithStream: (OFStream *)stream; - (instancetype)init OF_UNAVAILABLE; @@ -186,19 +194,27 @@ * @brief Parses the string and initializes an already allocated OFXMLElement * with it. * * @param string The string to parse * @return An initialized OFXMLElement with the contents of the string + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (instancetype)initWithXMLString: (OFString *)string; /** * @brief Parses the specified stream and initializes an already allocated * OFXMLElement with it. * * @param stream The stream to parse * @return An initialized OFXMLElement with the contents of the specified stream + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (instancetype)initWithStream: (OFStream *)stream; /** * @brief Sets a prefix for a namespace. @@ -393,10 +409,13 @@ * with the specified indentation per level. * * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation + * @throw OFUnboundNamespaceException The node uses a namespace that was not + * bound to a prefix in a context where it + * needs a prefix */ - (OFString *)XMLStringWithIndentation: (unsigned int)indentation; /** * @brief Returns an OFString representing the OFXMLElement as an XML string @@ -404,13 +423,16 @@ * * @param defaultNS The default namespace * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation + * @throw OFUnboundNamespaceException The node uses a namespace that was not + * bound to a prefix in a context where it + * needs a prefix */ - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation; @end OF_ASSUME_NONNULL_END #import "OFXMLElement+Serialization.h" Index: src/OFXMLNode.h ================================================================== --- src/OFXMLNode.h +++ src/OFXMLNode.h @@ -38,30 +38,43 @@ */ @property (nonatomic, copy) OFString *stringValue; /** * @brief The contents of the receiver as a `long long` value. + * + * @throw OFInvalidFormatException The node cannot be parsed as a `long long` */ @property (readonly, nonatomic) long long longLongValue; /** * @brief The contents of the receiver as an `unsigned long long` value. + * + * @throw OFInvalidFormatException The node cannot be parsed as an + * `unsigned long long` */ @property (readonly, nonatomic) unsigned long long unsignedLongLongValue; /** * @brief The contents of the receiver as a float value. + * + * @throw OFInvalidFormatException The node cannot be parsed as a `float` */ @property (readonly, nonatomic) float floatValue; /** * @brief The contents of the receiver as a double value. + * + * @throw OFInvalidFormatException The node cannot be parsed as a `double` */ @property (readonly, nonatomic) double doubleValue; /** * @brief A string representing the node as an XML string. + * + * @throw OFUnboundNamespaceException The node uses a namespace that was not + * bound to a prefix in a context where it + * needs a prefix */ @property (readonly, nonatomic) OFString *XMLString; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -185,24 +185,36 @@ /** * @brief Parses the specified buffer with the specified size. * * @param buffer The buffer to parse * @param length The length of the buffer + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseBuffer: (const char *)buffer length: (size_t)length; /** * @brief Parses the specified string. * * @param string The string to parse + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseString: (OFString *)string; /** * @brief Parses the specified stream. * * @param stream The stream to parse + * @throw OFMalformedXMLException The XML was malformed + * @throw OFUnboundPrefixException A prefix was used that was not bound to any + * namespace + * @throw OFInvalidEncodingException The XML is not in the encoding it specified */ - (void)parseStream: (OFStream *)stream; @end OF_ASSUME_NONNULL_END Index: src/OFZIPArchive.h ================================================================== --- src/OFZIPArchive.h +++ src/OFZIPArchive.h @@ -76,10 +76,11 @@ * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFZIPArchive object with the specified file. @@ -87,10 +88,11 @@ * @param URI The URI to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Creates a URI for accessing a the specified file within the specified @@ -113,10 +115,11 @@ * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** @@ -126,10 +129,11 @@ * @param URI The URI to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive + * @throw OFInvalidFormatException The format is not that of a valid ZIP archive */ - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns a stream for reading the specified file from the archive. @@ -145,10 +149,18 @@ * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @param path The path to the file inside the archive * @return A stream for reading the specified file form the archive + * @throw OFNotOpenException The archive is not open + * @throw OFInvalidArgumentException The archive is not in read mode + * @throw OFOpenItemFailedException Opening the specified file within the + * archive failed + * @throw OFInvalidFormatException The local header and the header in the + * central directory do not match enough + * @throw OFUnsupportedVersionException The file uses a version of the ZIP + * format that is not supported */ - (OFStream *)streamForReadingFile: (OFString *)path; /** * @brief Returns a stream for writing the specified entry to the archive. @@ -171,15 +183,25 @@ * * The compressed size. * * The uncompressed size. * * The CRC32. * * Bit 3 and 11 of the general purpose bit flag. * @return A stream for writing the specified entry to the archive + * @throw OFNotOpenException The archive is not open + * @throw OFInvalidArgumentException The archive is not in write mode + * @throw OFOpenItemFailedException Opening the specified file within the + * archive failed. If @ref errNo is `EEXIST`, + * because there is already a file with the + * same name in the archive. + * @throw OFNotImplementedException The desired compression method is not + * implemented */ - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry; /** * @brief Closes the OFZIPArchive. + * + * @throw OFNotOpenException The archive is not open */ - (void)close; @end #ifdef __cplusplus Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -170,10 +170,17 @@ *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry +/* + * The following are optional in OFArchiveEntry, but Apple GCC 4.0.1 is buggy + * and needs this to stop complaining. + */ +@dynamic POSIXPermissions, ownerAccountID, groupOwnerAccountID; +@dynamic ownerAccountName, groupOwnerAccountName; + - (instancetype)init { OF_INVALID_INIT_METHOD } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -82,24 +82,23 @@ # import "OFKernelEventObserver.h" # import "OFDNSQuery.h" # import "OFDNSResourceRecord.h" # import "OFDNSResponse.h" # import "OFDNSResolver.h" +# ifdef OF_HAVE_UNIX_SOCKETS +# import "OFUNIXDatagramSocket.h" +# import "OFUNIXStreamSocket.h" +# endif # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif -# ifdef OF_HAVE_UNIX_SOCKETS -# import "OFUNIXDatagramSocket.h" -# import "OFUNIXStreamSocket.h" -# endif -#endif -#ifdef OF_HAVE_SOCKETS -# ifdef OF_HAVE_THREADS -# import "OFHTTPClient.h" -# endif +# ifdef OF_HAVE_APPLETALK +# import "OFDDPSocket.h" +# endif +# import "OFHTTPClient.h" # import "OFHTTPCookie.h" # import "OFHTTPCookieManager.h" # import "OFHTTPRequest.h" # import "OFHTTPResponse.h" # import "OFHTTPServer.h" @@ -143,114 +142,102 @@ # import "OFWindowsRegistryKey.h" #endif #import "OFAllocFailedException.h" #import "OFException.h" -#ifdef OF_HAVE_SOCKETS -# import "OFAcceptFailedException.h" -# import "OFAlreadyConnectedException.h" -# import "OFBindFailedException.h" -#endif #import "OFChangeCurrentDirectoryFailedException.h" #import "OFChecksumMismatchException.h" -#ifdef OF_HAVE_THREADS -# import "OFConditionBroadcastFailedException.h" -# import "OFConditionSignalFailedException.h" -# import "OFConditionStillWaitingException.h" -# import "OFConditionWaitFailedException.h" -#endif -#ifdef OF_HAVE_SOCKETS -# import "OFConnectionFailedException.h" -#endif #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" -#ifdef OF_WINDOWS -# import "OFCreateWindowsRegistryKeyFailedException.h" -#endif -#ifdef OF_HAVE_SOCKETS -# import "OFDNSQueryFailedException.h" -#endif -#ifdef OF_WINDOWS -# import "OFDeleteWindowsRegistryKeyFailedException.h" -# import "OFDeleteWindowsRegistryValueFailedException.h" -#endif #import "OFEnumerationMutationException.h" #ifdef OF_HAVE_FILES # import "OFGetCurrentDirectoryFailedException.h" #endif #import "OFGetItemAttributesFailedException.h" #import "OFGetOptionFailedException.h" -#ifdef OF_WINDOWS -# import "OFGetWindowsRegistryValueFailedException.h" -#endif #import "OFHashAlreadyCalculatedException.h" #import "OFHashNotCalculatedException.h" -#ifdef OF_HAVE_SOCKETS -# import "OFHTTPRequestFailedException.h" -#endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidJSONException.h" #import "OFInvalidServerResponseException.h" #import "OFLinkItemFailedException.h" -#ifdef OF_HAVE_SOCKETS -# import "OFListenFailedException.h" -#endif #ifdef OF_HAVE_PLUGINS # import "OFLoadPluginFailedException.h" #endif #import "OFLockFailedException.h" #import "OFMalformedXMLException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" -#ifdef OF_HAVE_SOCKETS -# import "OFObserveKernelEventsFailedException.h" -#endif #import "OFOpenItemFailedException.h" -#ifdef OF_WINDOWS -# import "OFOpenWindowsRegistryKeyFailedException.h" -#endif #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" -#ifdef OF_HAVE_SOCKETS -# import "OFResolveHostFailedException.h" -#endif #import "OFSeekFailedException.h" #import "OFSetItemAttributesFailedException.h" #import "OFSetOptionFailedException.h" -#ifdef OF_WINDOWS -# import "OFSetWindowsRegistryValueFailedException.h" -#endif #import "OFStillLockedException.h" -#ifdef OF_HAVE_THREADS -# import "OFThreadJoinFailedException.h" -# import "OFThreadStartFailedException.h" -# import "OFThreadStillRunningException.h" -#endif -#ifdef OF_HAVE_SOCKETS -# import "OFTLSHandshakeFailedException.h" -#endif #import "OFTruncatedDataException.h" #import "OFUnboundNamespaceException.h" #import "OFUnboundPrefixException.h" #import "OFUndefinedKeyException.h" #import "OFUnknownXMLEntityException.h" #import "OFUnlockFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" - +#ifdef OF_HAVE_SOCKETS +# import "OFAcceptSocketFailedException.h" +# import "OFAlreadyConnectedException.h" +# import "OFBindIPSocketFailedException.h" +# import "OFBindSocketFailedException.h" +# import "OFConnectIPSocketFailedException.h" +# import "OFConnectSocketFailedException.h" +# import "OFDNSQueryFailedException.h" +# import "OFHTTPRequestFailedException.h" +# import "OFListenOnSocketFailedException.h" +# import "OFObserveKernelEventsFailedException.h" +# import "OFResolveHostFailedException.h" +# import "OFTLSHandshakeFailedException.h" +# ifdef OF_HAVE_UNIX_SOCKETS +# import "OFBindUNIXSocketFailedException.h" +# import "OFConnectUNIXSocketFailedException.h" +# endif +# ifdef OF_HAVE_IPX +# import "OFBindIPXSocketFailedException.h" +# import "OFConnectSPXSocketFailedException.h" +# endif +# ifdef OF_HAVE_APPLETALK +# import "OFBindDDPSocketFailedException.h" +# endif +#endif +#ifdef OF_HAVE_THREADS +# import "OFBroadcastConditionFailedException.h" +# import "OFConditionStillWaitingException.h" +# import "OFJoinThreadFailedException.h" +# import "OFSignalConditionFailedException.h" +# import "OFStartThreadFailedException.h" +# import "OFThreadStillRunningException.h" +# import "OFWaitForConditionFailedException.h" +#endif #ifdef OF_HAVE_PLUGINS # import "OFPlugin.h" #endif +#ifdef OF_WINDOWS +# import "OFCreateWindowsRegistryKeyFailedException.h" +# import "OFDeleteWindowsRegistryKeyFailedException.h" +# import "OFDeleteWindowsRegistryValueFailedException.h" +# import "OFGetWindowsRegistryValueFailedException.h" +# import "OFOpenWindowsRegistryKeyFailedException.h" +# import "OFSetWindowsRegistryValueFailedException.h" +#endif #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFLocking.h" Index: src/exceptions/Makefile ================================================================== --- src/exceptions/Makefile +++ src/exceptions/Makefile @@ -52,36 +52,46 @@ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \ OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m -SRCS_SOCKETS = OFAcceptFailedException.m \ +SRCS_SOCKETS = OFAcceptSocketFailedException.m \ OFAlreadyConnectedException.m \ - OFBindFailedException.m \ - OFConnectionFailedException.m \ + OFBindIPSocketFailedException.m \ + OFBindSocketFailedException.m \ + OFConnectIPSocketFailedException.m \ + OFConnectSocketFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ - OFListenFailedException.m \ + OFListenOnSocketFailedException.m \ OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ - OFTLSHandshakeFailedException.m -SRCS_THREADS = OFConditionBroadcastFailedException.m \ - OFConditionSignalFailedException.m \ + OFTLSHandshakeFailedException.m \ + ${USE_SRCS_APPLETALK} \ + ${USE_SRCS_IPX} \ + ${USE_SRCS_UNIX_SOCKETS} +SRCS_APPLETALK = OFBindDDPSocketFailedException.m +SRCS_IPX = OFBindIPXSocketFailedException.m \ + OFConnectSPXSocketFailedException.m +SRCS_UNIX_SOCKETS = OFBindUNIXSocketFailedException.m \ + OFConnectUNIXSocketFailedException.m +SRCS_THREADS = OFBroadcastConditionFailedException.m \ OFConditionStillWaitingException.m \ - OFConditionWaitFailedException.m \ - OFThreadJoinFailedException.m \ - OFThreadStartFailedException.m \ - OFThreadStillRunningException.m + OFJoinThreadFailedException.m \ + OFSignalConditionFailedException.m \ + OFStartThreadFailedException.m \ + OFThreadStillRunningException.m \ + OFWaitForConditionFailedException.m SRCS_WINDOWS = OFCreateWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryValueFailedException.m \ OFGetWindowsRegistryValueFailedException.m \ OFOpenWindowsRegistryKeyFailedException.m \ OFSetWindowsRegistryValueFailedException.m INCLUDES := ${SRCS:.m=.h} -SRCS += OFSandboxActivationFailedException.m +SRCS += OFActivateSandboxFailedException.m include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../runtime DELETED src/exceptions/OFAcceptFailedException.h Index: src/exceptions/OFAcceptFailedException.h ================================================================== --- src/exceptions/OFAcceptFailedException.h +++ src/exceptions/OFAcceptFailedException.h @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFAcceptFailedException \ - * OFAcceptFailedException.h ObjFW/OFAcceptFailedException.h - * - * @brief An exception indicating that accepting a connection failed. - */ -@interface OFAcceptFailedException: OFException -{ - id _socket; - int _errNo; - OF_RESERVE_IVARS(OFAcceptFailedException, 4) -} - -/** - * @brief The socket which could not accept a connection. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The errno from when the exception was created. - */ -@property (readonly, nonatomic) int errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Creates a new, autoreleased accept failed exception. - * - * @param socket The socket which could not accept a connection - * @param errNo The errno for the error - * @return A new, autoreleased accept failed exception - */ -+ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; - -- (instancetype)init OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated accept failed exception. - * - * @param socket The socket which could not accept a connection - * @param errNo The errno for the error - * @return An initialized accept failed exception - */ -- (instancetype)initWithSocket: (id)socket - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFAcceptFailedException.m Index: src/exceptions/OFAcceptFailedException.m ================================================================== --- src/exceptions/OFAcceptFailedException.m +++ src/exceptions/OFAcceptFailedException.m @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFAcceptFailedException.h" -#import "OFString.h" - -@implementation OFAcceptFailedException -@synthesize socket = _socket, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo -{ - return [[[self alloc] initWithSocket: socket errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSocket: (id)socket errNo: (int)errNo -{ - self = [super init]; - - _socket = [socket retain]; - _errNo = errNo; - - return self; -} - -- (void)dealloc -{ - [_socket release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to accept connection in socket of class %@: %@", - [_socket class], OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFAcceptSocketFailedException.h Index: src/exceptions/OFAcceptSocketFailedException.h ================================================================== --- src/exceptions/OFAcceptSocketFailedException.h +++ src/exceptions/OFAcceptSocketFailedException.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFAcceptSocketFailedException \ + * OFAcceptSocketFailedException.h ObjFW/OFAcceptSocketFailedException.h + * + * @brief An exception indicating that accepting a connection failed. + */ +@interface OFAcceptSocketFailedException: OFException +{ + id _socket; + int _errNo; + OF_RESERVE_IVARS(OFAcceptSocketFailedException, 4) +} + +/** + * @brief The socket which could not accept a connection. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The errno from when the exception was created. + */ +@property (readonly, nonatomic) int errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Creates a new, autoreleased accept failed exception. + * + * @param socket The socket which could not accept a connection + * @param errNo The errno for the error + * @return A new, autoreleased accept failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + +- (instancetype)init OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated accept failed exception. + * + * @param socket The socket which could not accept a connection + * @param errNo The errno for the error + * @return An initialized accept failed exception + */ +- (instancetype)initWithSocket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFAcceptSocketFailedException.m Index: src/exceptions/OFAcceptSocketFailedException.m ================================================================== --- src/exceptions/OFAcceptSocketFailedException.m +++ src/exceptions/OFAcceptSocketFailedException.m @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFAcceptSocketFailedException.h" +#import "OFString.h" + +@implementation OFAcceptSocketFailedException +@synthesize socket = _socket, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + self = [super init]; + + _socket = [sock retain]; + _errNo = errNo; + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to accept connection in socket of class %@: %@", + [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFActivateSandboxFailedException.h Index: src/exceptions/OFActivateSandboxFailedException.h ================================================================== --- src/exceptions/OFActivateSandboxFailedException.h +++ src/exceptions/OFActivateSandboxFailedException.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OFSandbox; + +@interface OFActivateSandboxFailedException: OFException +{ + OFSandbox *_sandbox; + int _errNo; +} + +@property (readonly, nonatomic) OFSandbox *sandbox; +@property (readonly, nonatomic) int errNo; + ++ (instancetype)exception OF_UNAVAILABLE; ++ (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo; +- (instancetype)init OF_UNAVAILABLE; +- (instancetype)initWithSandbox: (OFSandbox *)sandbox + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFActivateSandboxFailedException.m Index: src/exceptions/OFActivateSandboxFailedException.m ================================================================== --- src/exceptions/OFActivateSandboxFailedException.m +++ src/exceptions/OFActivateSandboxFailedException.m @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFActivateSandboxFailedException.h" +#import "OFString.h" +#import "OFSandbox.h" + +@implementation OFActivateSandboxFailedException +@synthesize sandbox = _sandbox, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo +{ + return [[[self alloc] initWithSandbox: sandbox + errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo +{ + self = [super init]; + + _sandbox = [sandbox retain]; + _errNo = errNo; + + return self; +} + +- (void)dealloc +{ + [_sandbox release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"The sandbox could not be applied: %@", OFStrError(_errNo)]; +} +@end Index: src/exceptions/OFAlreadyConnectedException.m ================================================================== --- src/exceptions/OFAlreadyConnectedException.m +++ src/exceptions/OFAlreadyConnectedException.m @@ -19,25 +19,25 @@ #import "OFString.h" @implementation OFAlreadyConnectedException @synthesize socket = _socket; -+ (instancetype)exceptionWithSocket: (id)socket ++ (instancetype)exceptionWithSocket: (id)sock { - return [[[self alloc] initWithSocket: socket] autorelease]; + return [[[self alloc] initWithSocket: sock] autorelease]; } - (instancetype)init { return [self initWithSocket: nil]; } -- (instancetype)initWithSocket: (id)socket +- (instancetype)initWithSocket: (id)sock { self = [super init]; - _socket = [socket retain]; + _socket = [sock retain]; return self; } - (void)dealloc ADDED src/exceptions/OFBindDDPSocketFailedException.h Index: src/exceptions/OFBindDDPSocketFailedException.h ================================================================== --- src/exceptions/OFBindDDPSocketFailedException.h +++ src/exceptions/OFBindDDPSocketFailedException.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindDDPSocketFailedException \ + * OFBindDDPSocketFailedException.h \ + * ObjFW/OFBindDDPSocketFailedException.h + * + * @brief An exception indicating that binding a DDP socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindDDPSocketFailedException: OFBindSocketFailedException +{ + uint16_t _network; + uint8_t _node, _port, _protocolType; +} + +/** + * @brief The DDP network on which binding failed. + */ +@property (readonly, nonatomic) uint16_t network; + +/** + * @brief The DDP node for which binding failed. + */ +@property (readonly, nonatomic) uint8_t node; + +/** + * @brief The DDP port on which binding failed. + */ +@property (readonly, nonatomic) uint8_t port; + +/** + * @brief The DDP protocol type for which binding failed. + */ +@property (readonly, nonatomic) uint8_t protocolType; + +/** + * @brief Creates a new, autoreleased bind DDP socket failed exception. + * + * @param network The DDP network on which binding failed + * @param node The DDP node for which binding failed + * @param port The DDP port on which binding failed + * @param protocolType The DDP protocol type for which binding failed. + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind DDP socket failed exception + */ ++ (instancetype)exceptionWithNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind DDP socket failed exception. + * + * @param network The DDP network on which binding failed + * @param node The DDP node for which binding failed + * @param port The DDP port on which binding failed + * @param protocolType The DDP protocol type for which binding failed. + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind DDP socket failed exception + */ +- (instancetype)initWithNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindDDPSocketFailedException.m Index: src/exceptions/OFBindDDPSocketFailedException.m ================================================================== --- src/exceptions/OFBindDDPSocketFailedException.m +++ src/exceptions/OFBindDDPSocketFailedException.m @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindDDPSocketFailedException.h" +#import "OFData.h" +#import "OFString.h" + +@implementation OFBindDDPSocketFailedException +@synthesize network = _network, node = _node, port = _port; +@synthesize protocolType = _protocolType; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithNetwork: network + node: node + port: port + protocolType: protocolType + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithNetwork: (uint16_t)network + node: (uint8_t)node + port: (uint8_t)port + protocolType: (uint8_t)protocolType + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _network = network; + _node = node; + _port = port; + _protocolType = protocolType; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to port %" @PRIx8 @" of node %" @PRIx8 @" on network " + @"%" PRIx16 @" with protocol type " @PRIx8 @" failed in socket of " + @"type %@: %@", + _port, _node, _network, _protocolType, [_socket class], + OFStrError(_errNo)]; +} +@end DELETED src/exceptions/OFBindFailedException.h Index: src/exceptions/OFBindFailedException.h ================================================================== --- src/exceptions/OFBindFailedException.h +++ src/exceptions/OFBindFailedException.h @@ -1,160 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -#import "OFSocket.h" - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFBindFailedException \ - * OFBindFailedException.h ObjFW/OFBindFailedException.h - * - * @brief An exception indicating that binding a socket failed. - */ -@interface OFBindFailedException: OFException -{ - /* IP */ - OFString *_Nullable _host; - uint16_t _port; - /* IPX */ - uint8_t _packetType; - /* UNIX socket */ - OFString *_Nullable _path; - id _socket; - int _errNo; - OF_RESERVE_IVARS(OFBindFailedException, 4) -} - -/** - * @brief The host on which binding failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; - -/** - * @brief The port on which binding failed. - */ -@property (readonly, nonatomic) uint16_t port; - -/** - * @brief The IPX packet type for which binding failed. - */ -@property (readonly, nonatomic) uint8_t packetType; - -/** - * @brief The path on which binding failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; - -/** - * @brief The socket which could not be bound. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased bind failed exception. - * - * @param host The host on which binding failed - * @param port The port on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception - */ -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Creates a new, autoreleased bind failed exception. - * - * @param port The IPX port to which binding failed - * @param packetType The IPX packet type for which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception - */ -+ (instancetype)exceptionWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Creates a new, autoreleased bind failed exception. - * - * @param path The path on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return A new, autoreleased bind failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param host The host on which binding failed - * @param port The port on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param port The IPX port to which binding failed - * @param packetType The IPX packet type for which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)socket - errNo: (int)errNo; -/** - * @brief Initializes an already allocated bind failed exception. - * - * @param path The path on which binding failed - * @param socket The socket which could not be bound - * @param errNo The errno of the error that occurred - * @return An initialized bind failed exception - */ -- (instancetype)initWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFBindFailedException.m Index: src/exceptions/OFBindFailedException.m ================================================================== --- src/exceptions/OFBindFailedException.m +++ src/exceptions/OFBindFailedException.m @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFBindFailedException.h" -#import "OFString.h" - -@implementation OFBindFailedException -@synthesize host = _host, port = _port, packetType = _packetType, path = _path; -@synthesize socket = _socket, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithHost: host - port: port - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exceptionWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithPort: port - packetType: packetType - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path - socket: sock - errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _host = [host copy]; - _port = port; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithPort: (uint16_t)port - packetType: (uint8_t)packetType - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _port = port; - _packetType = packetType; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _path = [path copy]; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (void)dealloc -{ - [_host release]; - [_path release]; - [_socket release]; - - [super dealloc]; -} - -- (OFString *)description -{ - if (_path != nil) - return [OFString stringWithFormat: - @"Binding to path %@ failed in socket of type %@: %@", - _path, [_socket class], OFStrError(_errNo)]; - else if (_host != nil) - return [OFString stringWithFormat: - @"Binding to port %" @PRIu16 @" on host %@ failed in " - @"socket of type %@: %@", - _port, _host, [_socket class], OFStrError(_errNo)]; - else - return [OFString stringWithFormat: - @"Binding to port %" @PRIx16 @" for packet type %" @PRIx8 - @" failed in socket of type %@: %@", - _port, _packetType, [_socket class], OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFBindIPSocketFailedException.h Index: src/exceptions/OFBindIPSocketFailedException.h ================================================================== --- src/exceptions/OFBindIPSocketFailedException.h +++ src/exceptions/OFBindIPSocketFailedException.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindIPSocketFailedException \ + * OFBindIPSocketFailedException.h ObjFW/OFBindIPSocketFailedException.h + * + * @brief An exception indicating that binding an IP socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindIPSocketFailedException: OFBindSocketFailedException +{ + OFString *_Nullable _host; + uint16_t _port; +} + +/** + * @brief The host on which binding failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; + +/** + * @brief The port on which binding failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief Creates a new, autoreleased bind IP socket failed exception. + * + * @param host The host on which binding failed + * @param port The port on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind IP socket failed exception + */ ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind IP socket failed exception. + * + * @param host The host on which binding failed + * @param port The port on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind IP socket failed exception + */ +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindIPSocketFailedException.m Index: src/exceptions/OFBindIPSocketFailedException.m ================================================================== --- src/exceptions/OFBindIPSocketFailedException.m +++ src/exceptions/OFBindIPSocketFailedException.m @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindIPSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindIPSocketFailedException +@synthesize host = _host, port = _port; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithHost: host + port: port + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _host = [host copy]; + _port = port; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_host release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to port %" @PRIu16 @" on host %@ failed in socket of " + @"type %@: %@", + _port, _host, [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFBindIPXSocketFailedException.h Index: src/exceptions/OFBindIPXSocketFailedException.h ================================================================== --- src/exceptions/OFBindIPXSocketFailedException.h +++ src/exceptions/OFBindIPXSocketFailedException.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindIPXSocketFailedException \ + * OFBindIPXSocketFailedException.h \ + * ObjFW/OFBindIPXSocketFailedException.h + * + * @brief An exception indicating that binding an IPX socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindIPXSocketFailedException: OFBindSocketFailedException +{ + uint32_t _network; + unsigned char _node[IPX_NODE_LEN]; + uint16_t _port; + uint8_t _packetType; +} + +/** + * @brief The IPX network on which binding failed. + */ +@property (readonly, nonatomic) uint32_t network; + +/** + * @brief The IPX port on which binding failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief The IPX packet type for which binding failed. + */ +@property (readonly, nonatomic) uint8_t packetType; + +/** + * @brief Creates a new, autoreleased bind IPX socket failed exception. + * + * @param network The IPX network to which binding failed + * @param node The IPX node to which binding failed + * @param port The IPX port to which binding failed + * @param packetType The IPX packet type for which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind IPX socket failed exception + */ ++ (instancetype) + exceptionWithNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind IPX socket failed exception. + * + * @param network The IPX network to which binding failed + * @param node The IPX node to which binding failed + * @param port The IPX port to which binding failed + * @param packetType The IPX packet type for which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind IPX socket failed exception + */ +- (instancetype) + initWithNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Get the IPX node for which binding failed. + * + * @param node A pointer to where to write the node to + */ +- (void)getNode: (unsigned char [_Nonnull IPX_NODE_LEN])node; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindIPXSocketFailedException.m Index: src/exceptions/OFBindIPXSocketFailedException.m ================================================================== --- src/exceptions/OFBindIPXSocketFailedException.m +++ src/exceptions/OFBindIPXSocketFailedException.m @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFBindIPXSocketFailedException.h" +#import "OFData.h" +#import "OFString.h" + +@implementation OFBindIPXSocketFailedException +@synthesize network = _network, port = _port, packetType = _packetType; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype) + exceptionWithNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithNetwork: network + node: node + port: port + packetType: packetType + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype) + initWithNetwork: (uint32_t)network + node: (const unsigned char [_Nonnull IPX_NODE_LEN])node + port: (uint16_t)port + packetType: (uint8_t)packetType + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _network = network; + memcpy(_node, node, sizeof(_node)); + _port = port; + _packetType = packetType; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)getNode: (unsigned char [IPX_NODE_LEN])node +{ + memcpy(node, _node, sizeof(_node)); +} + +- (OFString *)description +{ + OFData *node = [OFData dataWithItems: _node count: sizeof(_node)]; + + return [OFString stringWithFormat: + @"Binding to network %" @PRIx16 " on node %@ with port %" @PRIx16 + @" failed for packet type %" @PRIx8 " in socket of type %@: %@", + _network, node, _port, _packetType, [_socket class], + OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFBindSocketFailedException.h Index: src/exceptions/OFBindSocketFailedException.h ================================================================== --- src/exceptions/OFBindSocketFailedException.h +++ src/exceptions/OFBindSocketFailedException.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +#import "OFSocket.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindSocketFailedException \ + * OFBindSocketFailedException.h ObjFW/OFBindSocketFailedException.h + * + * @brief An exception indicating that binding a socket failed. + */ +@interface OFBindSocketFailedException: OFException +{ + id _socket; + int _errNo; + OF_RESERVE_IVARS(OFBindSocketFailedException, 4) +} + +/** + * @brief The socket which could not be bound. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased bind socket failed exception. + * + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind socket failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind socket failed exception. + * + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind socket failed exception + */ +- (instancetype)initWithSocket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindSocketFailedException.m Index: src/exceptions/OFBindSocketFailedException.m ================================================================== --- src/exceptions/OFBindSocketFailedException.m +++ src/exceptions/OFBindSocketFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindSocketFailedException +@synthesize socket = _socket, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + self = [super init]; + + @try { + _socket = [sock retain]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding a socket of type %@ failed: %@", + [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFBindUNIXSocketFailedException.h Index: src/exceptions/OFBindUNIXSocketFailedException.h ================================================================== --- src/exceptions/OFBindUNIXSocketFailedException.h +++ src/exceptions/OFBindUNIXSocketFailedException.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFBindSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFBindUNIXSocketFailedException \ + * OFBindUNIXSocketFailedException.h \ + * ObjFW/OFBindUNIXSocketFailedException.h + * + * @brief An exception indicating that binding a UNIX socket failed. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFBindUNIXSocketFailedException: OFBindSocketFailedException +{ + OFString *_Nullable _path; +} + +/** + * @brief The path on which binding failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; + +/** + * @brief Creates a new, autoreleased bind UNIX socket failed exception. + * + * @param path The path on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return A new, autoreleased bind UNIX socket failed exception + */ ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated bind UNIX socket failed exception. + * + * @param path The path on which binding failed + * @param socket The socket which could not be bound + * @param errNo The errno of the error that occurred + * @return An initialized bind UNIX socket failed exception + */ +- (instancetype)initWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBindUNIXSocketFailedException.m Index: src/exceptions/OFBindUNIXSocketFailedException.m ================================================================== --- src/exceptions/OFBindUNIXSocketFailedException.m +++ src/exceptions/OFBindUNIXSocketFailedException.m @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFBindUNIXSocketFailedException.h" +#import "OFString.h" + +@implementation OFBindUNIXSocketFailedException +@synthesize path = _path; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithPath: path + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _path = [path copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_path release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Binding to path %@ failed in socket of type %@: %@", + _path, [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFBroadcastConditionFailedException.h Index: src/exceptions/OFBroadcastConditionFailedException.h ================================================================== --- src/exceptions/OFBroadcastConditionFailedException.h +++ src/exceptions/OFBroadcastConditionFailedException.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class OFCondition; + +/** + * @class OFBroadcastConditionFailedException \ + * OFBroadcastConditionFailedException.h \ + * ObjFW/OFBroadcastConditionFailedException.h + * + * @brief An exception indicating broadcasting a condition failed. + */ +@interface OFBroadcastConditionFailedException: OFException +{ + OFCondition *_condition; + int _errNo; + OF_RESERVE_IVARS(OFBroadcastConditionFailedException, 4) +} + +/** + * @brief The condition which could not be broadcasted. + */ +@property (readonly, nonatomic) OFCondition *condition; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Returns a new, autoreleased condition broadcast failed exception. + * + * @param condition The condition which could not be broadcasted + * @param errNo The errno of the error that occurred + * @return A new, autoreleased condition broadcast failed exception + */ ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated condition broadcast failed exception. + * + * @param condition The condition which could not be broadcasted + * @param errNo The errno of the error that occurred + * @return An initialized condition broadcast failed exception + */ +- (instancetype)initWithCondition: (OFCondition *)condition + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFBroadcastConditionFailedException.m Index: src/exceptions/OFBroadcastConditionFailedException.m ================================================================== --- src/exceptions/OFBroadcastConditionFailedException.m +++ src/exceptions/OFBroadcastConditionFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFBroadcastConditionFailedException.h" +#import "OFString.h" +#import "OFCondition.h" + +@implementation OFBroadcastConditionFailedException +@synthesize condition = _condition, errNo = _errNo; + ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo +{ + return [[[self alloc] initWithCondition: condition + errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo +{ + self = [super init]; + + _condition = [condition retain]; + _errNo = errNo; + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_condition release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Broadcasting a condition of type %@ failed: %s", + _condition.class, strerror(_errNo)]; +} +@end DELETED src/exceptions/OFConditionBroadcastFailedException.h Index: src/exceptions/OFConditionBroadcastFailedException.h ================================================================== --- src/exceptions/OFConditionBroadcastFailedException.h +++ src/exceptions/OFConditionBroadcastFailedException.h @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_THREADS -# error No threads available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -@class OFCondition; - -/** - * @class OFConditionBroadcastFailedException \ - * OFConditionBroadcastFailedException.h \ - * ObjFW/OFConditionBroadcastFailedException.h - * - * @brief An exception indicating broadcasting a condition failed. - */ -@interface OFConditionBroadcastFailedException: OFException -{ - OFCondition *_condition; - int _errNo; - OF_RESERVE_IVARS(OFConditionBroadcastFailedException, 4) -} - -/** - * @brief The condition which could not be broadcasted. - */ -@property (readonly, nonatomic) OFCondition *condition; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Returns a new, autoreleased condition broadcast failed exception. - * - * @param condition The condition which could not be broadcasted - * @param errNo The errno of the error that occurred - * @return A new, autoreleased condition broadcast failed exception - */ -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated condition broadcast failed exception. - * - * @param condition The condition which could not be broadcasted - * @param errNo The errno of the error that occurred - * @return An initialized condition broadcast failed exception - */ -- (instancetype)initWithCondition: (OFCondition *)condition - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFConditionBroadcastFailedException.m Index: src/exceptions/OFConditionBroadcastFailedException.m ================================================================== --- src/exceptions/OFConditionBroadcastFailedException.m +++ src/exceptions/OFConditionBroadcastFailedException.m @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFConditionBroadcastFailedException.h" -#import "OFString.h" -#import "OFCondition.h" - -@implementation OFConditionBroadcastFailedException -@synthesize condition = _condition, errNo = _errNo; - -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo -{ - return [[[self alloc] initWithCondition: condition - errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo -{ - self = [super init]; - - _condition = [condition retain]; - _errNo = errNo; - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_condition release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Broadcasting a condition of type %@ failed: %s", - _condition.class, strerror(_errNo)]; -} -@end DELETED src/exceptions/OFConditionSignalFailedException.h Index: src/exceptions/OFConditionSignalFailedException.h ================================================================== --- src/exceptions/OFConditionSignalFailedException.h +++ src/exceptions/OFConditionSignalFailedException.h @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_THREADS -# error No threads available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -@class OFCondition; - -/** - * @class OFConditionSignalFailedException \ - * OFConditionSignalFailedException.h \ - * ObjFW/OFConditionSignalFailedException.h - * - * @brief An exception indicating signaling a condition failed. - */ -@interface OFConditionSignalFailedException: OFException -{ - OFCondition *_condition; - int _errNo; - OF_RESERVE_IVARS(OFConditionSignalFailedException, 4) -} - -/** - * @brief The condition which could not be signaled. - */ -@property (readonly, nonatomic) OFCondition *condition; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased condition signal failed exception. - * - * @param condition The condition which could not be signaled - * @param errNo The errno of the error that occurred - * @return A new, autoreleased condition signal failed exception - */ -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated condition signal failed exception. - * - * @param condition The condition which could not be signaled - * @param errNo The errno of the error that occurred - * @return An initialized condition signal failed exception - */ -- (instancetype)initWithCondition: (OFCondition *)condition - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFConditionSignalFailedException.m Index: src/exceptions/OFConditionSignalFailedException.m ================================================================== --- src/exceptions/OFConditionSignalFailedException.m +++ src/exceptions/OFConditionSignalFailedException.m @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFConditionSignalFailedException.h" -#import "OFString.h" -#import "OFCondition.h" - -@implementation OFConditionSignalFailedException -@synthesize condition = _condition, errNo = _errNo; - -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo -{ - return [[[self alloc] initWithCondition: condition - errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo -{ - self = [super init]; - - _condition = [condition retain]; - _errNo = errNo; - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_condition release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Signaling a condition of type %@ failed: %s", - _condition.class, strerror(_errNo)]; -} -@end DELETED src/exceptions/OFConditionWaitFailedException.h Index: src/exceptions/OFConditionWaitFailedException.h ================================================================== --- src/exceptions/OFConditionWaitFailedException.h +++ src/exceptions/OFConditionWaitFailedException.h @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_THREADS -# error No threads available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -@class OFCondition; - -/** - * @class OFConditionWaitFailedException \ - * OFConditionWaitFailedException.h \ - * ObjFW/OFConditionWaitFailedException.h - * - * @brief An exception indicating waiting for a condition failed. - */ -@interface OFConditionWaitFailedException: OFException -{ - OFCondition *_condition; - int _errNo; - OF_RESERVE_IVARS(OFConditionWaitFailedException, 4) -} - -/** - * @brief The condition for which could not be waited. - */ -@property (readonly, nonatomic) OFCondition *condition; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased condition wait failed exception. - * - * @param condition The condition for which could not be waited - * @param errNo The errno of the error that occurred - * @return A new, autoreleased condition wait failed exception - */ -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated condition wait failed exception. - * - * @param condition The condition for which could not be waited - * @param errNo The errno of the error that occurred - * @return An initialized condition wait failed exception - */ -- (instancetype)initWithCondition: (OFCondition *)condition - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFConditionWaitFailedException.m Index: src/exceptions/OFConditionWaitFailedException.m ================================================================== --- src/exceptions/OFConditionWaitFailedException.m +++ src/exceptions/OFConditionWaitFailedException.m @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFConditionWaitFailedException.h" -#import "OFString.h" -#import "OFCondition.h" - -@implementation OFConditionWaitFailedException -@synthesize condition = _condition, errNo = _errNo; - -+ (instancetype)exceptionWithCondition: (OFCondition *)condition - errNo: (int)errNo -{ - return [[[self alloc] initWithCondition: condition - errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo -{ - self = [super init]; - - _condition = [condition retain]; - _errNo = errNo; - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_condition release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Waiting for a condition of type %@ failed: %s", - _condition.class, strerror(_errNo)]; -} -@end ADDED src/exceptions/OFConnectIPSocketFailedException.h Index: src/exceptions/OFConnectIPSocketFailedException.h ================================================================== --- src/exceptions/OFConnectIPSocketFailedException.h +++ src/exceptions/OFConnectIPSocketFailedException.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFConnectSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFConnectIPSocketFailedException \ + * OFConnectIPSocketFailedException.h \ + * ObjFW/OFConnectIPSocketFailedException.h + * + * @brief An exception indicating that an IP connection could not be + * established. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFConnectIPSocketFailedException: OFConnectSocketFailedException +{ + OFString *_Nullable _host; + uint16_t _port; +} + +/** + * @brief The host to which the connection failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; + +/** + * @brief The port on the host to which the connection failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief Creates a new, autoreleased connect IP socket failed exception. + * + * @param host The host to which the connection failed + * @param port The port on the host to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return A new, autoreleased connect IP socket failed exception + */ ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated connect IP socket failed exception. + * + * @param host The host to which the connection failed + * @param port The port on the host to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return An initialized connect IP socket failed exception + */ +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFConnectIPSocketFailedException.m Index: src/exceptions/OFConnectIPSocketFailedException.m ================================================================== --- src/exceptions/OFConnectIPSocketFailedException.m +++ src/exceptions/OFConnectIPSocketFailedException.m @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFConnectIPSocketFailedException.h" +#import "OFString.h" + +@implementation OFConnectIPSocketFailedException +@synthesize host = _host, port = _port; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithHost: host + port: port + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithHost: (OFString *)host + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _host = [host copy]; + _port = port; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_host release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"A connection to %@ on port %" @PRIu16 @" could not be " + @"established in socket of type %@: %@", + _host, _port, [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFConnectSPXSocketFailedException.h Index: src/exceptions/OFConnectSPXSocketFailedException.h ================================================================== --- src/exceptions/OFConnectSPXSocketFailedException.h +++ src/exceptions/OFConnectSPXSocketFailedException.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFConnectSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFConnectSPXSocketFailedException \ + * OFConnectSPXSocketFailedException.h \ + * ObjFW/OFConnectSocketFailedException.h + * + * @brief An exception indicating that an SPX connection could not be + * established. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFConnectSPXSocketFailedException: OFConnectSocketFailedException +{ + uint32_t _network; + unsigned char _node[IPX_NODE_LEN]; + uint16_t _port; +} + + +/** + * @brief The IPX network of the node to which the connection failed. + */ +@property (readonly, nonatomic) uint32_t network; + +/** + * @brief The IPX port on the host to which the connection failed. + */ +@property (readonly, nonatomic) uint16_t port; + +/** + * @brief Creates a new, autoreleased connect SPX socket failed exception. + * + * @param network The IPX network of the node to which the connection failed + * @param node The node to which the connection failed + * @param port The port on the node to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return A new, autoreleased connect SPX socket failed exception + */ ++ (instancetype) + exceptionWithNetwork: (uint32_t)network + node: (const unsigned char [_Nullable IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated connect SPX socket failed exception. + * + * @param network The IPX network of the node to which the connection failed + * @param node The node to which the connection failed + * @param port The port on the node to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return An initialized connect SPX socket failed exception + */ +- (instancetype) + initWithNetwork: (uint32_t)network + node: (const unsigned char [_Nullable IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Get the IPX node to which the connection failed. + * + * @param node A pointer to where to write the node to + */ +- (void)getNode: (unsigned char [_Nonnull IPX_NODE_LEN])node; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFConnectSPXSocketFailedException.m Index: src/exceptions/OFConnectSPXSocketFailedException.m ================================================================== --- src/exceptions/OFConnectSPXSocketFailedException.m +++ src/exceptions/OFConnectSPXSocketFailedException.m @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFConnectSPXSocketFailedException.h" +#import "OFData.h" +#import "OFString.h" + +@implementation OFConnectSPXSocketFailedException +@synthesize network = _network, port = _port; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithNetwork: (uint32_t)network + node: (const unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithNetwork: network + node: node + port: port + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithNetwork: (uint32_t)network + node: (const unsigned char [IPX_NODE_LEN])node + port: (uint16_t)port + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _network = network; + memcpy(_node, node, IPX_NODE_LEN); + _port = port; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)getNode: (unsigned char [IPX_NODE_LEN])node +{ + memcpy(node, _node, sizeof(_node)); +} + +- (OFString *)description +{ + OFData *node = [OFData dataWithItems: _node count: sizeof(_node)]; + + return [OFString stringWithFormat: + @"A connection to %@ port %" @PRIu16 @" on network %" @PRIX32 + " could not be established in socket of type %@: %@", + node, _port, _network, [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFConnectSocketFailedException.h Index: src/exceptions/OFConnectSocketFailedException.h ================================================================== --- src/exceptions/OFConnectSocketFailedException.h +++ src/exceptions/OFConnectSocketFailedException.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +#import "OFSocket.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFConnectSocketFailedException \ + * OFConnectSocketFailedException.h \ + * ObjFW/OFConnectSocketFailedException.h + * + * @brief An exception indicating that a connection could not be established. + */ +@interface OFConnectSocketFailedException: OFException +{ + id _socket; + int _errNo; + OF_RESERVE_IVARS(OFConnectSocketFailedException, 4) +} + +/** + * @brief The socket which could not connect. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased connect socket failed exception. + * + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return A new, autoreleased connect socket failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated connect socket failed exception. + * + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return An initialized connect socket failed exception + */ +- (instancetype)initWithSocket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFConnectSocketFailedException.m Index: src/exceptions/OFConnectSocketFailedException.m ================================================================== --- src/exceptions/OFConnectSocketFailedException.m +++ src/exceptions/OFConnectSocketFailedException.m @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFConnectSocketFailedException.h" +#import "OFString.h" + +@implementation OFConnectSocketFailedException +@synthesize socket = _socket, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + self = [super init]; + + @try { + _socket = [sock retain]; + _errNo = errNo; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"A connection to could not be established in socket of type " + @"%@: %@", + [_socket class], OFStrError(_errNo)]; +} +@end ADDED src/exceptions/OFConnectUNIXSocketFailedException.h Index: src/exceptions/OFConnectUNIXSocketFailedException.h ================================================================== --- src/exceptions/OFConnectUNIXSocketFailedException.h +++ src/exceptions/OFConnectUNIXSocketFailedException.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFConnectSocketFailedException.h" + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFConnectUNIXSocketFailedException \ + * OFConnectUNIXSocketFailedException.h \ + * ObjFW/OFConnectUNIXSocketFailedException.h + * + * @brief An exception indicating that a UNIX socket connection could not be + * established. + */ +OF_SUBCLASSING_RESTRICTED +@interface OFConnectUNIXSocketFailedException: OFConnectSocketFailedException +{ + OFString *_Nullable _path; +} + +/** + * @brief The path to which the connection failed. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; + +/** + * @brief Creates a new, autoreleased connect UNIX socket failed exception. + * + * @param path The path to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return A new, autoreleased connect UNIX socket failed exception + */ ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo; + ++ (instancetype)exceptionWithSocket: (id)socket + errNo: (int)errNo OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated connect UNIX socket failed exception. + * + * @param path The path to which the connection failed + * @param socket The socket which could not connect + * @param errNo The errno of the error that occurred + * @return An initialized connect UNIX socket failed exception + */ +- (instancetype)initWithPath: (OFString *)path + socket: (id)socket + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)initWithSocket: (id)socket errNo: (int)errNo OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFConnectUNIXSocketFailedException.m Index: src/exceptions/OFConnectUNIXSocketFailedException.m ================================================================== --- src/exceptions/OFConnectUNIXSocketFailedException.m +++ src/exceptions/OFConnectUNIXSocketFailedException.m @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFConnectUNIXSocketFailedException.h" +#import "OFString.h" + +@implementation OFConnectUNIXSocketFailedException +@synthesize path = _path; + ++ (instancetype)exceptionWithSocket: (id)sock errNo: (int)errNo +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + return [[[self alloc] initWithPath: path + socket: sock + errNo: errNo] autorelease]; +} + +- (instancetype)initWithSocket: (id)sock errNo: (int)errNo +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithPath: (OFString *)path + socket: (id)sock + errNo: (int)errNo +{ + self = [super initWithSocket: sock errNo: errNo]; + + @try { + _path = [path copy]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_path release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"A connection to %@ could not be established in socket of type " + @"%@: %@", + _path, [_socket class], OFStrError(_errNo)]; +} +@end DELETED src/exceptions/OFConnectionFailedException.h Index: src/exceptions/OFConnectionFailedException.h ================================================================== --- src/exceptions/OFConnectionFailedException.h +++ src/exceptions/OFConnectionFailedException.h @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -#import "OFSocket.h" - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFConnectionFailedException \ - * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h - * - * @brief An exception indicating that a connection could not be established. - */ -@interface OFConnectionFailedException: OFException -{ - OFString *_Nullable _host; - uint16_t _port; - OFString *_Nullable _path; - uint32_t _network; - unsigned char _node[IPX_NODE_LEN]; - id _socket; - int _errNo; - OF_RESERVE_IVARS(OFConnectionFailedException, 4) -} - -/** - * @brief The host to which the connection failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; - -/** - * @brief The port on the host to which the connection failed. - */ -@property (readonly, nonatomic) uint16_t port; - -/** - * @brief The path to which the connection failed. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; - -/** - * @brief The IPX network of the node to which the connection failed. - */ -@property (readonly, nonatomic) uint32_t network; - -/** - * @brief The IPX node to which the connection failed. - */ -@property (readonly, nonatomic) unsigned char *node; - -/** - * @brief The socket which could not connect. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased connection failed exception. - * - * @param host The host to which the connection failed - * @param port The port on the host to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return A new, autoreleased connection failed exception - */ -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Creates a new, autoreleased connection failed exception. - * - * @param path The path to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return A new, autoreleased connection failed exception - */ -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Creates a new, autoreleased connection failed exception. - * - * @param network The IPX network of the node to which the connection failed - * @param node The node to which the connection failed - * @param port The port on the node to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return A new, autoreleased connection failed exception - */ -+ (instancetype) - exceptionWithNetwork: (uint32_t)network - node: (unsigned char [_Nullable IPX_NODE_LEN])node - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated connection failed exception. - * - * @param host The host to which the connection failed - * @param port The port on the host to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return An initialized connection failed exception - */ -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated connection failed exception. - * - * @param path The path to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return An initialized connection failed exception - */ -- (instancetype)initWithPath: (OFString *)path - socket: (id)socket - errNo: (int)errNo; - -/** - * @brief Initializes an already allocated connection failed exception. - * - * @param network The IPX network of the node to which the connection failed - * @param node The node to which the connection failed - * @param port The port on the node to which the connection failed - * @param socket The socket which could not connect - * @param errNo The errno of the error that occurred - * @return An initialized connection failed exception - */ -- (instancetype)initWithNetwork: (uint32_t)network - node: (unsigned char [_Nullable IPX_NODE_LEN])node - port: (uint16_t)port - socket: (id)socket - errNo: (int)errNo; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFConnectionFailedException.m Index: src/exceptions/OFConnectionFailedException.m ================================================================== --- src/exceptions/OFConnectionFailedException.m +++ src/exceptions/OFConnectionFailedException.m @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFConnectionFailedException.h" -#import "OFString.h" - -@implementation OFConnectionFailedException -@synthesize host = _host, port = _port, path = _path, network = _network; -@synthesize socket = _socket, errNo = _errNo; - -+ (instancetype)exceptionWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithHost: host - port: port - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithPath: path - socket: sock - errNo: errNo] autorelease]; -} - -+ (instancetype)exceptionWithNetwork: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - return [[[self alloc] initWithNetwork: network - node: node - port: port - socket: sock - errNo: errNo] autorelease]; -} - -- (instancetype)initWithHost: (OFString *)host - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _host = [host copy]; - _port = port; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithPath: (OFString *)path - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _path = [path copy]; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithNetwork: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node - port: (uint16_t)port - socket: (id)sock - errNo: (int)errNo -{ - self = [super init]; - - @try { - _network = network; - memcpy(_node, node, IPX_NODE_LEN); - _port = port; - _socket = [sock retain]; - _errNo = errNo; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_host release]; - [_path release]; - [_socket release]; - - [super dealloc]; -} - -- (unsigned char *)node -{ - return _node; -} - -- (OFString *)description -{ - if (_path != nil) - return [OFString stringWithFormat: - @"A connection to %@ could not be established in socket of " - @"type %@: %@", - _path, [_socket class], OFStrError(_errNo)]; - else if (_host != nil) - return [OFString stringWithFormat: - @"A connection to %@ on port %" @PRIu16 @" could not be " - @"established in socket of type %@: %@", - _host, _port, [_socket class], OFStrError(_errNo)]; - else if (memcmp(_node, "\0\0\0\0\0", IPX_NODE_LEN) == 0) - return [OFString stringWithFormat: - @"A connection to %02X%02X%02X%02X%02X%02X port %" @PRIu16 - @" on network %" @PRIX32 " could not be established in " - @"socket of type %@: %@", - _node[0], _node[1], _node[2], _node[3], _node[4], _node[5], - _port, _network, [_socket class], OFStrError(_errNo)]; - else - return [OFString stringWithFormat: - @"A connection could not be established in socket of " - @"type %@: %@", - [_socket class], OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFJoinThreadFailedException.h Index: src/exceptions/OFJoinThreadFailedException.h ================================================================== --- src/exceptions/OFJoinThreadFailedException.h +++ src/exceptions/OFJoinThreadFailedException.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class OFThread; + +/** + * @class OFJoinThreadFailedException \ + * OFJoinThreadFailedException.h ObjFW/OFJoinThreadFailedException.h + * + * @brief An exception indicating that joining a thread failed. + */ +@interface OFJoinThreadFailedException: OFException +{ + OFThread *_Nullable _thread; + int _errNo; + OF_RESERVE_IVARS(OFJoinThreadFailedException, 4) +} + +/** + * @brief The thread which could not be joined. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased thread join failed exception. + * + * @param thread The thread which could not be joined + * @param errNo The errno of the error that occurred + * @return A new, autoreleased thread join failed exception + */ ++ (instancetype)exceptionWithThread: (nullable OFThread *)thread + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated thread join failed exception. + * + * @param thread The thread which could not be joined + * @param errNo The errno of the error that occurred + * @return An initialized thread join failed exception + */ +- (instancetype)initWithThread: (nullable OFThread *)thread + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFJoinThreadFailedException.m Index: src/exceptions/OFJoinThreadFailedException.m ================================================================== --- src/exceptions/OFJoinThreadFailedException.m +++ src/exceptions/OFJoinThreadFailedException.m @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFJoinThreadFailedException.h" +#import "OFString.h" +#import "OFThread.h" + +@implementation OFJoinThreadFailedException +@synthesize thread = _thread, errNo = _errNo; + ++ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo +{ + return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo +{ + self = [super init]; + + _thread = [thread retain]; + _errNo = errNo; + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_thread release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Joining a thread of type %@ failed: %s", + _thread.class, strerror(_errNo)]; +} +@end DELETED src/exceptions/OFListenFailedException.h Index: src/exceptions/OFListenFailedException.h ================================================================== --- src/exceptions/OFListenFailedException.h +++ src/exceptions/OFListenFailedException.h @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_SOCKETS -# error No sockets available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -/** - * @class OFListenFailedException \ - * OFListenFailedException.h ObjFW/OFListenFailedException.h - * - * @brief An exception indicating that listening on the socket failed. - */ -@interface OFListenFailedException: OFException -{ - id _socket; - int _backlog, _errNo; - OF_RESERVE_IVARS(OFListenFailedException, 4) -} - -/** - * @brief The socket which failed to listen. - */ -@property (readonly, nonatomic) id socket; - -/** - * @brief The requested back log. - */ -@property (readonly, nonatomic) int backlog; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased listen failed exception. - * - * @param socket The socket which failed to listen - * @param backlog The requested size of the back log - * @param errNo The errno of the error that occurred - * @return A new, autoreleased listen failed exception - */ -+ (instancetype)exceptionWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated listen failed exception. - * - * @param socket The socket which failed to listen - * @param backlog The requested size of the back log - * @param errNo The errno of the error that occurred - * @return An initialized listen failed exception - */ -- (instancetype)initWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFListenFailedException.m Index: src/exceptions/OFListenFailedException.m ================================================================== --- src/exceptions/OFListenFailedException.m +++ src/exceptions/OFListenFailedException.m @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFListenFailedException.h" -#import "OFString.h" - -@implementation OFListenFailedException -@synthesize socket = _socket, backlog = _backlog, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo -{ - return [[[self alloc] initWithSocket: socket - backlog: backlog - errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSocket: (id)socket - backlog: (int)backlog - errNo: (int)errNo -{ - self = [super init]; - - _socket = [socket retain]; - _backlog = backlog; - _errNo = errNo; - - return self; -} - -- (void)dealloc -{ - [_socket release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Failed to listen in socket of type %@ with a back log of %d: %@", - [_socket class], _backlog, OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFListenOnSocketFailedException.h Index: src/exceptions/OFListenOnSocketFailedException.h ================================================================== --- src/exceptions/OFListenOnSocketFailedException.h +++ src/exceptions/OFListenOnSocketFailedException.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_SOCKETS +# error No sockets available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +/** + * @class OFListenOnSocketFailedException \ + * OFListenOnSocketFailedException.h \ + * ObjFW/OFListenOnSocketFailedException.h + * + * @brief An exception indicating that listening on the socket failed. + */ +@interface OFListenOnSocketFailedException: OFException +{ + id _socket; + int _backlog, _errNo; + OF_RESERVE_IVARS(OFListenOnSocketFailedException, 4) +} + +/** + * @brief The socket which failed to listen. + */ +@property (readonly, nonatomic) id socket; + +/** + * @brief The requested back log. + */ +@property (readonly, nonatomic) int backlog; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased listen failed exception. + * + * @param socket The socket which failed to listen + * @param backlog The requested size of the back log + * @param errNo The errno of the error that occurred + * @return A new, autoreleased listen failed exception + */ ++ (instancetype)exceptionWithSocket: (id)socket + backlog: (int)backlog + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated listen failed exception. + * + * @param socket The socket which failed to listen + * @param backlog The requested size of the back log + * @param errNo The errno of the error that occurred + * @return An initialized listen failed exception + */ +- (instancetype)initWithSocket: (id)socket + backlog: (int)backlog + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFListenOnSocketFailedException.m Index: src/exceptions/OFListenOnSocketFailedException.m ================================================================== --- src/exceptions/OFListenOnSocketFailedException.m +++ src/exceptions/OFListenOnSocketFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFListenOnSocketFailedException.h" +#import "OFString.h" + +@implementation OFListenOnSocketFailedException +@synthesize socket = _socket, backlog = _backlog, errNo = _errNo; + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + ++ (instancetype)exceptionWithSocket: (id)sock + backlog: (int)backlog + errNo: (int)errNo +{ + return [[[self alloc] initWithSocket: sock + backlog: backlog + errNo: errNo] autorelease]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (instancetype)initWithSocket: (id)sock backlog: (int)backlog errNo: (int)errNo +{ + self = [super init]; + + _socket = [sock retain]; + _backlog = backlog; + _errNo = errNo; + + return self; +} + +- (void)dealloc +{ + [_socket release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Failed to listen in socket of type %@ with a back log of %d: %@", + [_socket class], _backlog, OFStrError(_errNo)]; +} +@end DELETED src/exceptions/OFSandboxActivationFailedException.h Index: src/exceptions/OFSandboxActivationFailedException.h ================================================================== --- src/exceptions/OFSandboxActivationFailedException.h +++ src/exceptions/OFSandboxActivationFailedException.h @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFSandbox; - -@interface OFSandboxActivationFailedException: OFException -{ - OFSandbox *_sandbox; - int _errNo; -} - -@property (readonly, nonatomic) OFSandbox *sandbox; -@property (readonly, nonatomic) int errNo; - -+ (instancetype)exception OF_UNAVAILABLE; -+ (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo; -- (instancetype)init OF_UNAVAILABLE; -- (instancetype)initWithSandbox: (OFSandbox *)sandbox - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFSandboxActivationFailedException.m Index: src/exceptions/OFSandboxActivationFailedException.m ================================================================== --- src/exceptions/OFSandboxActivationFailedException.m +++ src/exceptions/OFSandboxActivationFailedException.m @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFSandboxActivationFailedException.h" -#import "OFString.h" -#import "OFSandbox.h" - -@implementation OFSandboxActivationFailedException -@synthesize sandbox = _sandbox, errNo = _errNo; - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -+ (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo -{ - return [[[self alloc] initWithSandbox: sandbox - errNo: errNo] autorelease]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo -{ - self = [super init]; - - _sandbox = [sandbox retain]; - _errNo = errNo; - - return self; -} - -- (void)dealloc -{ - [_sandbox release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"The sandbox could not be applied: %@", OFStrError(_errNo)]; -} -@end ADDED src/exceptions/OFSignalConditionFailedException.h Index: src/exceptions/OFSignalConditionFailedException.h ================================================================== --- src/exceptions/OFSignalConditionFailedException.h +++ src/exceptions/OFSignalConditionFailedException.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class OFCondition; + +/** + * @class OFSignalConditionFailedException \ + * OFSignalConditionFailedException.h \ + * ObjFW/OFSignalConditionFailedException.h + * + * @brief An exception indicating signaling a condition failed. + */ +@interface OFSignalConditionFailedException: OFException +{ + OFCondition *_condition; + int _errNo; + OF_RESERVE_IVARS(OFSignalConditionFailedException, 4) +} + +/** + * @brief The condition which could not be signaled. + */ +@property (readonly, nonatomic) OFCondition *condition; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased condition signal failed exception. + * + * @param condition The condition which could not be signaled + * @param errNo The errno of the error that occurred + * @return A new, autoreleased condition signal failed exception + */ ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated condition signal failed exception. + * + * @param condition The condition which could not be signaled + * @param errNo The errno of the error that occurred + * @return An initialized condition signal failed exception + */ +- (instancetype)initWithCondition: (OFCondition *)condition + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFSignalConditionFailedException.m Index: src/exceptions/OFSignalConditionFailedException.m ================================================================== --- src/exceptions/OFSignalConditionFailedException.m +++ src/exceptions/OFSignalConditionFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFSignalConditionFailedException.h" +#import "OFString.h" +#import "OFCondition.h" + +@implementation OFSignalConditionFailedException +@synthesize condition = _condition, errNo = _errNo; + ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo +{ + return [[[self alloc] initWithCondition: condition + errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo +{ + self = [super init]; + + _condition = [condition retain]; + _errNo = errNo; + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_condition release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Signaling a condition of type %@ failed: %s", + _condition.class, strerror(_errNo)]; +} +@end ADDED src/exceptions/OFStartThreadFailedException.h Index: src/exceptions/OFStartThreadFailedException.h ================================================================== --- src/exceptions/OFStartThreadFailedException.h +++ src/exceptions/OFStartThreadFailedException.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class OFThread; + +/** + * @class OFStartThreadFailedException \ + * OFStartThreadFailedException.h ObjFW/OFStartThreadFailedException.h + * + * @brief An exception indicating that starting a thread failed. + */ +@interface OFStartThreadFailedException: OFException +{ + OFThread *_Nullable _thread; + int _errNo; + OF_RESERVE_IVARS(OFStartThreadFailedException, 4) +} + +/** + * @brief The thread which could not be started. + */ +@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased thread start failed exception. + * + * @param thread The thread which could not be started + * @param errNo The errno of the error that occurred + * @return A new, autoreleased thread start failed exception + */ ++ (instancetype)exceptionWithThread: (nullable OFThread *)thread + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated thread start failed exception. + * + * @param thread The thread which could not be started + * @param errNo The errno of the error that occurred + * @return An initialized thread start failed exception + */ +- (instancetype)initWithThread: (nullable OFThread *)thread + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFStartThreadFailedException.m Index: src/exceptions/OFStartThreadFailedException.m ================================================================== --- src/exceptions/OFStartThreadFailedException.m +++ src/exceptions/OFStartThreadFailedException.m @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFStartThreadFailedException.h" +#import "OFString.h" +#import "OFThread.h" + +@implementation OFStartThreadFailedException +@synthesize thread = _thread, errNo = _errNo; + ++ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo +{ + return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo +{ + self = [super init]; + + _thread = [thread retain]; + _errNo = errNo; + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_thread release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Starting a thread of type %@ failed: %s", + _thread.class, strerror(_errNo)]; +} +@end DELETED src/exceptions/OFThreadJoinFailedException.h Index: src/exceptions/OFThreadJoinFailedException.h ================================================================== --- src/exceptions/OFThreadJoinFailedException.h +++ src/exceptions/OFThreadJoinFailedException.h @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_THREADS -# error No threads available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -@class OFThread; - -/** - * @class OFThreadJoinFailedException \ - * OFThreadJoinFailedException.h ObjFW/OFThreadJoinFailedException.h - * - * @brief An exception indicating that joining a thread failed. - */ -@interface OFThreadJoinFailedException: OFException -{ - OFThread *_Nullable _thread; - int _errNo; - OF_RESERVE_IVARS(OFThreadJoinFailedException, 4) -} - -/** - * @brief The thread which could not be joined. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased thread join failed exception. - * - * @param thread The thread which could not be joined - * @param errNo The errno of the error that occurred - * @return A new, autoreleased thread join failed exception - */ -+ (instancetype)exceptionWithThread: (nullable OFThread *)thread - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated thread join failed exception. - * - * @param thread The thread which could not be joined - * @param errNo The errno of the error that occurred - * @return An initialized thread join failed exception - */ -- (instancetype)initWithThread: (nullable OFThread *)thread - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFThreadJoinFailedException.m Index: src/exceptions/OFThreadJoinFailedException.m ================================================================== --- src/exceptions/OFThreadJoinFailedException.m +++ src/exceptions/OFThreadJoinFailedException.m @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFThreadJoinFailedException.h" -#import "OFString.h" -#import "OFThread.h" - -@implementation OFThreadJoinFailedException -@synthesize thread = _thread, errNo = _errNo; - -+ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo -{ - return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo -{ - self = [super init]; - - _thread = [thread retain]; - _errNo = errNo; - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_thread release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Joining a thread of type %@ failed: %s", - _thread.class, strerror(_errNo)]; -} -@end DELETED src/exceptions/OFThreadStartFailedException.h Index: src/exceptions/OFThreadStartFailedException.h ================================================================== --- src/exceptions/OFThreadStartFailedException.h +++ src/exceptions/OFThreadStartFailedException.h @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#import "OFException.h" - -#ifndef OF_HAVE_THREADS -# error No threads available! -#endif - -OF_ASSUME_NONNULL_BEGIN - -@class OFThread; - -/** - * @class OFThreadStartFailedException \ - * OFThreadStartFailedException.h ObjFW/OFThreadStartFailedException.h - * - * @brief An exception indicating that starting a thread failed. - */ -@interface OFThreadStartFailedException: OFException -{ - OFThread *_Nullable _thread; - int _errNo; - OF_RESERVE_IVARS(OFThreadStartFailedException, 4) -} - -/** - * @brief The thread which could not be started. - */ -@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; - -/** - * @brief The errno of the error that occurred. - */ -@property (readonly, nonatomic) int errNo; - -/** - * @brief Creates a new, autoreleased thread start failed exception. - * - * @param thread The thread which could not be started - * @param errNo The errno of the error that occurred - * @return A new, autoreleased thread start failed exception - */ -+ (instancetype)exceptionWithThread: (nullable OFThread *)thread - errNo: (int)errNo; - -+ (instancetype)exception OF_UNAVAILABLE; - -/** - * @brief Initializes an already allocated thread start failed exception. - * - * @param thread The thread which could not be started - * @param errNo The errno of the error that occurred - * @return An initialized thread start failed exception - */ -- (instancetype)initWithThread: (nullable OFThread *)thread - errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - -- (instancetype)init OF_UNAVAILABLE; -@end - -OF_ASSUME_NONNULL_END DELETED src/exceptions/OFThreadStartFailedException.m Index: src/exceptions/OFThreadStartFailedException.m ================================================================== --- src/exceptions/OFThreadStartFailedException.m +++ src/exceptions/OFThreadStartFailedException.m @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2008-2022 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "OFThreadStartFailedException.h" -#import "OFString.h" -#import "OFThread.h" - -@implementation OFThreadStartFailedException -@synthesize thread = _thread, errNo = _errNo; - -+ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo -{ - return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; -} - -+ (instancetype)exception -{ - OF_UNRECOGNIZED_SELECTOR -} - -- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo -{ - self = [super init]; - - _thread = [thread retain]; - _errNo = errNo; - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_thread release]; - - [super dealloc]; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"Starting a thread of type %@ failed: %s", - _thread.class, strerror(_errNo)]; -} -@end ADDED src/exceptions/OFWaitForConditionFailedException.h Index: src/exceptions/OFWaitForConditionFailedException.h ================================================================== --- src/exceptions/OFWaitForConditionFailedException.h +++ src/exceptions/OFWaitForConditionFailedException.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFException.h" + +#ifndef OF_HAVE_THREADS +# error No threads available! +#endif + +OF_ASSUME_NONNULL_BEGIN + +@class OFCondition; + +/** + * @class OFWaitForConditionFailedException \ + * OFWaitForConditionFailedException.h \ + * ObjFW/OFWaitForConditionFailedException.h + * + * @brief An exception indicating waiting for a condition failed. + */ +@interface OFWaitForConditionFailedException: OFException +{ + OFCondition *_condition; + int _errNo; + OF_RESERVE_IVARS(OFWaitForConditionFailedException, 4) +} + +/** + * @brief The condition for which could not be waited. + */ +@property (readonly, nonatomic) OFCondition *condition; + +/** + * @brief The errno of the error that occurred. + */ +@property (readonly, nonatomic) int errNo; + +/** + * @brief Creates a new, autoreleased condition wait failed exception. + * + * @param condition The condition for which could not be waited + * @param errNo The errno of the error that occurred + * @return A new, autoreleased condition wait failed exception + */ ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo; + ++ (instancetype)exception OF_UNAVAILABLE; + +/** + * @brief Initializes an already allocated condition wait failed exception. + * + * @param condition The condition for which could not be waited + * @param errNo The errno of the error that occurred + * @return An initialized condition wait failed exception + */ +- (instancetype)initWithCondition: (OFCondition *)condition + errNo: (int)errNo OF_DESIGNATED_INITIALIZER; + +- (instancetype)init OF_UNAVAILABLE; +@end + +OF_ASSUME_NONNULL_END ADDED src/exceptions/OFWaitForConditionFailedException.m Index: src/exceptions/OFWaitForConditionFailedException.m ================================================================== --- src/exceptions/OFWaitForConditionFailedException.m +++ src/exceptions/OFWaitForConditionFailedException.m @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "OFWaitForConditionFailedException.h" +#import "OFString.h" +#import "OFCondition.h" + +@implementation OFWaitForConditionFailedException +@synthesize condition = _condition, errNo = _errNo; + ++ (instancetype)exceptionWithCondition: (OFCondition *)condition + errNo: (int)errNo +{ + return [[[self alloc] initWithCondition: condition + errNo: errNo] autorelease]; +} + ++ (instancetype)exception +{ + OF_UNRECOGNIZED_SELECTOR +} + +- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo +{ + self = [super init]; + + _condition = [condition retain]; + _errNo = errNo; + + return self; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} + +- (void)dealloc +{ + [_condition release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: + @"Waiting for a condition of type %@ failed: %s", + _condition.class, strerror(_errNo)]; +} +@end Index: src/macros.h ================================================================== --- src/macros.h +++ src/macros.h @@ -389,17 +389,18 @@ } \ \ abort(); #endif #ifdef __clang__ -# define OF_DEALLOC_UNSUPPORTED \ - [self doesNotRecognizeSelector: _cmd]; \ - \ - abort(); \ - \ - _Pragma("clang diagnostic push ignored \"-Wunreachable-code\""); \ - [super dealloc]; /* Get rid of a stupid warning */ \ +# define OF_DEALLOC_UNSUPPORTED \ + [self doesNotRecognizeSelector: _cmd]; \ + \ + abort(); \ + \ + _Pragma("clang diagnostic push"); \ + _Pragma("clang diagnostic ignored \"-Wunreachable-code\""); \ + [super dealloc]; /* Get rid of a stupid warning */ \ _Pragma("clang diagnostic pop"); #else # define OF_DEALLOC_UNSUPPORTED \ [self doesNotRecognizeSelector: _cmd]; \ \ Index: src/objfw-defs.h.in ================================================================== --- src/objfw-defs.h.in +++ src/objfw-defs.h.in @@ -1,9 +1,10 @@ #undef OF_APPLE_RUNTIME #undef OF_BIG_ENDIAN #undef OF_FLOAT_BIG_ENDIAN #undef OF_HAVE_AFUNIX_H +#undef OF_HAVE_APPLETALK #undef OF_HAVE_ATOMIC_BUILTINS #undef OF_HAVE_ATOMIC_OPS #undef OF_HAVE_BUILTIN_BSWAP16 #undef OF_HAVE_BUILTIN_BSWAP32 #undef OF_HAVE_BUILTIN_BSWAP64 @@ -14,25 +15,27 @@ #undef OF_HAVE_IPV6 #undef OF_HAVE_IPX #undef OF_HAVE_LIMITS_H #undef OF_HAVE_LINK #undef OF_HAVE_MAX_ALIGN_T +#undef OF_HAVE_NETATALK_AT_H +#undef OF_HAVE_NETAT_APPLETALK_H #undef OF_HAVE_NETINET_IN_H #undef OF_HAVE_NETINET_TCP_H #undef OF_HAVE_NETIPX_IPX_H #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 #undef OF_HAVE_PIPE #undef OF_HAVE_PLEDGE #undef OF_HAVE_PLUGINS -#undef OF_HAVE_SUBPROCESSES #undef OF_HAVE_PTHREADS #undef OF_HAVE_PTHREAD_SPINLOCKS #undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES #undef OF_HAVE_SCHED_YIELD #undef OF_HAVE_SOCKETS #undef OF_HAVE_STDNORETURN +#undef OF_HAVE_SUBPROCESSES #undef OF_HAVE_SYMLINK #undef OF_HAVE_SYNC_BUILTINS #undef OF_HAVE_SYS_SOCKET_H #undef OF_HAVE_SYS_TYPES_H #undef OF_HAVE_SYS_UN_H Index: src/platform/POSIX/OFSubprocess.m ================================================================== --- src/platform/POSIX/OFSubprocess.m +++ src/platform/POSIX/OFSubprocess.m @@ -361,12 +361,14 @@ return _writePipe[1]; } - (void)closeForWriting { - if (_writePipe[1] != -1) - close(_writePipe[1]); + if (_readPipe[0] == -1 || _writePipe[1] == -1) + @throw [OFNotOpenException exceptionWithObject: self]; + + close(_writePipe[1]); _writePipe[1] = -1; } - (void)close Index: src/platform/Windows/OFSubprocess.m ================================================================== --- src/platform/Windows/OFSubprocess.m +++ src/platform/Windows/OFSubprocess.m @@ -368,12 +368,14 @@ return (size_t)bytesWritten; } - (void)closeForWriting { - if (_writePipe[1] != NULL) - CloseHandle(_writePipe[1]); + if (_readPipe[0] == NULL || _writePipe[1] == NULL) + @throw [OFNotOpenException exceptionWithObject: self]; + + CloseHandle(_writePipe[1]); _writePipe[1] = NULL; } - (void)close Index: src/runtime/amiga-end.m ================================================================== --- src/runtime/amiga-end.m +++ src/runtime/amiga-end.m @@ -13,11 +13,11 @@ * file. */ #include "config.h" -#import "platform.h" +#include "platform.h" #ifdef OF_MORPHOS __asm__ ( ".section .eh_frame, \"aw\"\n" " .long 0\n" Index: src/runtime/private.h ================================================================== --- src/runtime/private.h +++ src/runtime/private.h @@ -14,11 +14,10 @@ */ #include "config.h" #import "macros.h" -#import "platform.h" #if !defined(__has_feature) || !__has_feature(nullability) # ifndef _Nonnull # define _Nonnull # endif Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -73,12 +73,14 @@ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ + ${USE_SRCS_APPLETALK} \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} +SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m ADDED tests/OFDDPSocketTests.m Index: tests/OFDDPSocketTests.m ================================================================== --- tests/OFDDPSocketTests.m +++ tests/OFDDPSocketTests.m @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2008-2022 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "TestsAppDelegate.h" + +static OFString *const module = @"OFDDPSocket"; + +@implementation TestsAppDelegate (OFDDPSocketTests) +- (void)DDPSocketTests +{ + void *pool = objc_autoreleasePoolPush(); + OFDDPSocket *sock; + OFSocketAddress address1, address2; + char buffer[5]; + + TEST(@"+[socket]", (sock = [OFDDPSocket socket])) + + @try { + TEST(@"-[bindToNetwork:node:port:]", + R(address1 = [sock bindToNetwork: 0 + node: 0 + port: 0 + protocolType: 11])) + } @catch (OFBindSocketFailedException *e) { + switch (e.errNo) { + case EAFNOSUPPORT: + [OFStdOut setForegroundColor: [OFColor lime]]; + [OFStdOut writeLine: + @"\r[OFDDPSocket] -[bindToNetwork:node:port:" + @"protocolType:] AppleTalk unsupported, skipping " + @"tests"]; + break; + case EADDRNOTAVAIL: + [OFStdOut setForegroundColor: [OFColor lime]]; + [OFStdOut writeLine: + @"\r[OFDDPSocket] -[bindToNetwork:node:port:" + @"protocolType:] AppleTalk not configured, " + @"skipping tests"]; + break; + default: + @throw e; + } + + objc_autoreleasePoolPop(pool); + return; + } + + TEST(@"-[sendBuffer:length:receiver:]", + R([sock sendBuffer: "Hello" length: 5 receiver: &address1])) + + TEST(@"-[receiveIntoBuffer:length:sender:]", + [sock receiveIntoBuffer: buffer length: 5 sender: &address2] == 5 && + memcmp(buffer, "Hello", 5) == 0 && + OFSocketAddressEqual(&address1, &address2) && + OFSocketAddressHash(&address1) == OFSocketAddressHash(&address2)) + + objc_autoreleasePoolPop(pool); +} +@end Index: tests/OFIPXSocketTests.m ================================================================== --- tests/OFIPXSocketTests.m +++ tests/OFIPXSocketTests.m @@ -22,33 +22,38 @@ static OFString *const module = @"OFIPXSocket"; @implementation TestsAppDelegate (OFIPXSocketTests) - (void)IPXSocketTests { + const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; void *pool = objc_autoreleasePoolPush(); OFIPXSocket *sock; OFSocketAddress address1, address2; char buffer[5]; TEST(@"+[socket]", (sock = [OFIPXSocket socket])) @try { - TEST(@"-[bindToPort:packetType:]", - R(address1 = [sock bindToPort: 0 packetType: 0])) - } @catch (OFBindFailedException *e) { + TEST(@"-[bindToNetwork:node:port:packetType:]", + R(address1 = [sock bindToNetwork: 0 + node: zeroNode + port: 0 + packetType: 0])) + } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFIPXSocket] -[bindToPort:packetType:]: " - @"IPX unsupported, skipping tests"]; + @"\r[OFIPXSocket] -[bindToNetwork:node:port:" + @"packetType:]: IPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFIPXSocket] -[bindToPort:packetType:]: " - @"IPX not configured, skipping tests"]; + @"\r[OFIPXSocket] -[bindToNetwork:node:port:" + @"packetType:]: IPX not configured, skipping " + @"tests"]; break; default: @throw e; } Index: tests/OFSPXSocketTests.m ================================================================== --- tests/OFSPXSocketTests.m +++ tests/OFSPXSocketTests.m @@ -50,11 +50,11 @@ return false; } - (void)socket: (OFSPXSocket *)sock didConnectToNetwork: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); @@ -69,10 +69,11 @@ @end @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { + const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer = nil, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; uint32_t network; @@ -83,30 +84,32 @@ TEST(@"+[socket]", (sockClient = [OFSPXSocket socket]) && (sockServer = [OFSPXSocket socket])) @try { - TEST(@"-[bindToPort:]", - R(address1 = [sockServer bindToPort: 0])) - } @catch (OFBindFailedException *e) { + TEST(@"-[bindToNetwork:node:port:]", + R(address1 = [sockServer bindToNetwork: 0 + node: zeroNode + port: 0])) + } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXSocket] -[bindToPort:]: " + @"\r[OFSPXSocket] -[bindToNetwork:node:port:]: " @"IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXSocket] -[bindToPort:]: " + @"\r[OFSPXSocket] -[bindToNetwork:node:port:]: " @"SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXSocket] -[bindToPort:]: " + @"\r[OFSPXSocket] -[bindToNetwork:node:port:]: " @"IPX not configured, skipping tests"]; break; default: @throw e; } @@ -114,12 +117,12 @@ objc_autoreleasePoolPop(pool); return; } network = OFSocketAddressIPXNetwork(&address1); - OFSocketAddressIPXNode(&address1, node); - port = OFSocketAddressPort(&address1); + OFSocketAddressGetIPXNode(&address1, node); + port = OFSocketAddressIPXPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNetwork:node:port:]", R([sockClient connectToNetwork: network node: node port: port])) @@ -134,11 +137,11 @@ memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && OFSocketAddressIPXNetwork(address2) == network && - R(OFSocketAddressIPXNode(address2, node2)) && + R(OFSocketAddressGetIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0) delegate = [[[SPXSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXSocket socket]; @@ -147,19 +150,19 @@ sockClient = [OFSPXSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; - address1 = [sockServer bindToPort: 0]; + address1 = [sockServer bindToNetwork: 0 node: zeroNode port: 0]; [sockServer listen]; [sockServer asyncAccept]; delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); - OFSocketAddressIPXNode(&address1, node); + OFSocketAddressGetIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedPort = port = OFSocketAddressPort(&address1); + delegate->_expectedPort = port = OFSocketAddressIPXPort(&address1); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; Index: tests/OFSPXStreamSocketTests.m ================================================================== --- tests/OFSPXStreamSocketTests.m +++ tests/OFSPXStreamSocketTests.m @@ -50,11 +50,11 @@ return false; } - (void)socket: (OFSPXStreamSocket *)sock didConnectToNetwork: (uint32_t)network - node: (unsigned char [IPX_NODE_LEN])node + node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); @@ -69,10 +69,11 @@ @end @implementation TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests { + const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; void *pool = objc_autoreleasePoolPush(); OFSPXStreamSocket *sockClient, *sockServer = nil, *sockAccepted; OFSocketAddress address1; const OFSocketAddress *address2; uint32_t network; @@ -83,32 +84,34 @@ TEST(@"+[socket]", (sockClient = [OFSPXStreamSocket socket]) && (sockServer = [OFSPXStreamSocket socket])) @try { - TEST(@"-[bindToPort:]", - R(address1 = [sockServer bindToPort: 0])) - } @catch (OFBindFailedException *e) { + TEST(@"-[bindToNetwork:node:port:]", + R(address1 = [sockServer bindToNetwork: 0 + node: zeroNode + port: 0])) + } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXStreamSocket] -[bindToPort:]: " - @"IPX unsupported, skipping tests"]; + @"\r[OFSPXStreamSocket] -[bindToNetwork:node:" + @"port:]: IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: case EPROTONOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXStreamSocket] -[bindToPort:]: " - @"SPX unsupported, skipping tests"]; + @"\r[OFSPXStreamSocket] -[bindToNetwork:node:" + @"port:]: SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: - @"\r[OFSPXStreamSocket] -[bindToPort:]: " - @"IPX not configured, skipping tests"]; + @"\r[OFSPXStreamSocket] -[bindToNetwork:node:" + @"port:]: IPX not configured, skipping tests"]; break; default: @throw e; } @@ -115,12 +118,12 @@ objc_autoreleasePoolPop(pool); return; } network = OFSocketAddressIPXNetwork(&address1); - OFSocketAddressIPXNode(&address1, node); - port = OFSocketAddressPort(&address1); + OFSocketAddressGetIPXNode(&address1, node); + port = OFSocketAddressIPXPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNetwork:node:port:]", R([sockClient connectToNetwork: network node: node port: port])) @@ -138,11 +141,11 @@ memcmp(buffer, "llo", 3) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && OFSocketAddressIPXNetwork(address2) == network && - R(OFSocketAddressIPXNode(address2, node2)) && + R(OFSocketAddressGetIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0) delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXStreamSocket socket]; @@ -151,19 +154,19 @@ sockClient = [OFSPXStreamSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; - address1 = [sockServer bindToPort: 0]; + address1 = [sockServer bindToNetwork: 0 node: zeroNode port: 0]; [sockServer listen]; [sockServer asyncAccept]; delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); - OFSocketAddressIPXNode(&address1, node); + OFSocketAddressGetIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); - delegate->_expectedPort = port = OFSocketAddressPort(&address1); + delegate->_expectedPort = port = OFSocketAddressIPXPort(&address1); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; Index: tests/OFSocketTests.m ================================================================== --- tests/OFSocketTests.m +++ tests/OFSocketTests.m @@ -81,11 +81,11 @@ OFSocketAddressParseIP(@"127.0.a.1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #6", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0..1", 1234)) - TEST(@"Port of an IPv4 address", OFSocketAddressPort(&addr) == 1234) + TEST(@"Port of an IPv4 address", OFSocketAddressIPPort(&addr) == 1234) TEST(@"Converting an IPv4 to a string", [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", @@ -143,11 +143,11 @@ OFSocketAddressParseIP(@"1:2:3:4:5:6:7::", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #10", OFInvalidFormatException, OFSocketAddressParseIP(@"1:2", 1234)) - TEST(@"Port of an IPv6 address", OFSocketAddressPort(&addr) == 1234) + TEST(@"Port of an IPv6 address", OFSocketAddressIPPort(&addr) == 1234) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #1", [OFSocketAddressString(&addr) isEqual: @"::"]) Index: tests/OFUDPSocketTests.m ================================================================== --- tests/OFUDPSocketTests.m +++ tests/OFUDPSocketTests.m @@ -42,11 +42,11 @@ TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 && !memcmp(buf, "Hello", 6) && [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] && - OFSocketAddressPort(&addr2) == port1) + OFSocketAddressIPPort(&addr2) == port1) addr3 = OFSocketAddressParseIP(@"127.0.0.1", port1 + 1); /* * TODO: Move those tests elsewhere as soon as the DNS resolving part Index: tests/OFUNIXDatagramSocketTests.m ================================================================== --- tests/OFUNIXDatagramSocketTests.m +++ tests/OFUNIXDatagramSocketTests.m @@ -48,11 +48,11 @@ TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket])) @try { TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path])) - } @catch (OFBindFailedException *e) { + } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: Index: tests/OFUNIXStreamSocketTests.m ================================================================== --- tests/OFUNIXStreamSocketTests.m +++ tests/OFUNIXStreamSocketTests.m @@ -48,11 +48,11 @@ TEST(@"+[socket]", (sockClient = [OFUNIXStreamSocket socket]) && (sockServer = [OFUNIXStreamSocket socket])) @try { TEST(@"-[bindToPath:]", R([sockServer bindToPath: path])) - } @catch (OFBindFailedException *e) { + } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -68,10 +68,14 @@ @end @interface TestsAppDelegate (OFCharacterSetTests) - (void)characterSetTests; @end + +@interface TestsAppDelegate (OFDDPSocketTests) +- (void)DDPSocketTests; +@end @interface TestsAppDelegate (OFDNSResolverTests) - (void)DNSResolverTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -417,18 +417,21 @@ #endif #ifdef OF_HAVE_SOCKETS [self socketTests]; [self TCPSocketTests]; [self UDPSocketTests]; +# ifdef OF_HAVE_UNIX_SOCKETS + [self UNIXDatagramSocketTests]; + [self UNIXStreamSocketTests]; +# endif # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif -# ifdef OF_HAVE_UNIX_SOCKETS - [self UNIXDatagramSocketTests]; - [self UNIXStreamSocketTests]; +# ifdef OF_HAVE_APPLETALK + [self DDPSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; Index: utils/objfw-new/Property.m ================================================================== --- utils/objfw-new/Property.m +++ utils/objfw-new/Property.m @@ -51,11 +51,12 @@ - (void)parseString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; - size_t length = string.UTF8StringLength, nameIdx = -1; + size_t length = string.UTF8StringLength; + ssize_t nameIdx = -1; OFMutableArray *attributes = nil; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; Index: utils/ofarc/ZIPArchive.m ================================================================== --- utils/ofarc/ZIPArchive.m +++ utils/ofarc/ZIPArchive.m @@ -437,13 +437,10 @@ @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; size = (isDirectory ? 0 : attributes.fileSize); - if (size < 0 || size > ULLONG_MAX) - @throw [OFOutOfRangeException exception]; - entry.compressedSize = size; entry.uncompressedSize = size; entry.compressionMethod = OFZIPArchiveEntryCompressionMethodNone; Index: utils/ofhttp/OFHTTP.m ================================================================== --- utils/ofhttp/OFHTTP.m +++ utils/ofhttp/OFHTTP.m @@ -38,11 +38,11 @@ #ifdef HAVE_TLS_SUPPORT # import "ObjFWTLS.h" #endif -#import "OFConnectionFailedException.h" +#import "OFConnectSocketFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" @@ -821,11 +821,11 @@ @" Failed to resolve host: %[exception]", @"prog", [OFApplication programName], @"uri", request.URI.string, @"exception", exception)]; } else if ([exception isKindOfClass: - [OFConnectionFailedException class]]) { + [OFConnectSocketFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed_connection_failed",