Comment: | Merge trunk into branch "amiga-library" |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | amiga-library |
Files: | files | file ages | folders |
SHA3-256: |
80dbc3c570cf2dce3b0e0034a9224752 |
User & Date: | js on 2022-10-18 22:19:55 |
Other Links: | branch diff | manifest | tags |
2022-10-19
| ||
19:02 | src/linklib/init.m: Add new classes check-in: cc4338a9cd user: js tags: amiga-library | |
2022-10-18
| ||
22:19 | Merge trunk into branch "amiga-library" check-in: 80dbc3c570 user: js tags: amiga-library | |
22:17 | Merge trunk into branch "amiga-library" check-in: ac19ed9d40 user: js tags: amiga-library | |
17:59 | GitHub Actions: Replace Ubuntu 18.04 with latest check-in: a62fba3dc8 user: js tags: trunk | |
Deleted .cirrus.yml version [6338675a88].
|
| < < < < < < < < < < < < < < < < < < < < < < |
Modified .fossil-settings/clean-glob from [c4150a9711] to [06b87ad48d].
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 56 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | > | 46 47 48 49 50 51 52 53 54 55 56 57 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified .fossil-settings/ignore-glob from [ed0ba1aa38] to [23cb69850b].
︙ | ︙ | |||
51 52 53 54 55 56 57 58 59 60 61 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | > | 51 52 53 54 55 56 57 58 59 60 61 62 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Deleted .github/workflows/macos-10.15.yml version [0b4e6d02a3].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added .github/workflows/macos-12.yml version [a15421158f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | name: macos-12 on: [push, pull_request] jobs: tests: runs-on: macos-12 strategy: matrix: configure_flags: - - --disable-threads - --disable-threads --disable-sockets - --disable-threads --disable-files - --disable-threads --disable-sockets --disable-files - --disable-sockets - --disable-sockets --disable-files - --disable-files - --disable-shared steps: - name: Install dependencies run: brew install autoconf automake - uses: actions/checkout@v2 - name: autogen.sh run: ./autogen.sh - name: configure run: ./configure ${{ matrix.configure_flags }} - name: make run: make -j$(sysctl -n hw.logicalcpu) - name: make check run: make check - name: make install run: sudo make install |
Renamed and modified .github/workflows/ubuntu-18.04-32bit.yml [96c9a8ae41] to .github/workflows/ubuntu-latest-32bit.yml [3cbf56442c].
|
| | | | 1 2 3 4 5 6 7 8 9 10 11 12 | name: ubuntu-latest, 32 bit on: [push, pull_request] jobs: tests: runs-on: ubuntu-latest strategy: matrix: configure_flags: - --without-tls - --without-tls --enable-seluid24 - --without-tls --disable-compiler-tls - --without-tls --disable-threads |
︙ | ︙ |
Renamed and modified .github/workflows/ubuntu-18.04-gcc-32bit.yml [0e720701c6] to .github/workflows/ubuntu-latest-gcc-32bit.yml [b827a9a41f].
|
| | | | 1 2 3 4 5 6 7 8 9 10 11 12 | name: ubuntu-latest, GCC, 32 bit on: [push, pull_request] jobs: tests: runs-on: ubuntu-latest strategy: matrix: configure_flags: - --without-tls - --without-tls --enable-seluid24 - --without-tls --disable-compiler-tls - --without-tls --disable-threads |
︙ | ︙ |
Renamed and modified .github/workflows/ubuntu-18.04-gcc.yml [9e75cc2f04] to .github/workflows/ubuntu-latest-gcc.yml [4509107d9f].
|
| | | | 1 2 3 4 5 6 7 8 9 10 11 12 | name: ubuntu-latest, GCC on: [push, pull_request] jobs: tests: runs-on: ubuntu-latest strategy: matrix: configure_flags: - - --enable-seluid24 - --disable-compiler-tls - --disable-threads |
︙ | ︙ |
Renamed and modified .github/workflows/ubuntu-18.04.yml [d0186b3566] to .github/workflows/ubuntu-latest.yml [36a38ec742].
|
| | | | 1 2 3 4 5 6 7 8 9 10 11 12 | name: ubuntu-latest on: [push, pull_request] jobs: tests: runs-on: ubuntu-latest strategy: matrix: configure_flags: - - --enable-seluid24 - --disable-compiler-tls - --disable-threads |
︙ | ︙ |
Modified .gitignore from [42e9f25720] to [726b780402].
︙ | ︙ | |||
51 52 53 54 55 56 57 58 59 60 61 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | > | 51 52 53 54 55 56 57 58 59 60 61 62 | tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified Doxyfile from [f4ff92fbc3] to [6b8aa42255].
1 2 3 4 5 6 7 8 9 10 11 | PROJECT_NAME = "ObjFW" OUTPUT_DIRECTORY = docs/ INPUT = src src/exceptions src/runtime FILE_PATTERNS = *.h *.m HTML_OUTPUT = . HAVE_DOT = NO GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES TYPEDEF_HIDES_STRUCT = YES PREDEFINED = __OBJC__ \ | | | | | | | | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | PROJECT_NAME = "ObjFW" OUTPUT_DIRECTORY = docs/ INPUT = src src/exceptions src/runtime FILE_PATTERNS = *.h *.m HTML_OUTPUT = . HAVE_DOT = NO GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES TYPEDEF_HIDES_STRUCT = YES PREDEFINED = __OBJC__ \ _Nonnull= \ _Nullable= \ DOXYGEN \ OF_BOXABLE= \ OF_CONSUMED= \ OF_DESIGNATED_INITIALIZER= \ OF_GENERIC(...)= \ OF_HAVE_BLOCKS \ OF_HAVE_FILES \ OF_HAVE_SANDBOX \ OF_HAVE_SOCKETS \ OF_HAVE_THREADS \ OF_KINDOF(...)= \ OF_NO_RETURN= \ OF_NO_RETURN_FUNC= \ OF_NULLABLE_PROPERTY(...)= \ OF_NULL_RESETTABLE_PROPERTY(...)= \ OF_REQUIRES_SUPER= \ OF_RETURNS_INNER_POINTER= \ OF_RETURNS_NOT_RETAINED= \ OF_RETURNS_RETAINED= \ OF_ROOT_CLASS= \ OF_SENTINEL= \ OF_WARN_UNUSED_RESULT= \ OF_WEAK_UNAVAILABLE= \ SIGHUP \ SIGUSR1 \ SIGUSR2 MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES IGNORE_PREFIX = OF of_ |
Modified Makefile from [63e28abf9d] to [4341fed160].
︙ | ︙ | |||
24 25 26 27 28 29 30 | doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ | | | < | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ --exclude '.fossil*,.git*' | ofarc -ttgz -xq - cp configure config.h.in objfw-${PACKAGE_VERSION}/ ofarc -cq objfw-${PACKAGE_VERSION}.tar objfw-${PACKAGE_VERSION} rm -fr objfw-${PACKAGE_VERSION} gzip -9 objfw-${PACKAGE_VERSION}.tar rm -f objfw-${PACKAGE_VERSION}.tar gpg -b objfw-${PACKAGE_VERSION}.tar.gz || true echo "Generating documentation..." rm -fr docs doxygen >/dev/null rm -fr objfw-docs-${PACKAGE_VERSION} objfw-docs-${PACKAGE_VERSION}.tar \ objfw-docs-${PACKAGE_VERSION}.tar.gz mv docs objfw-docs-${PACKAGE_VERSION} echo "Generating docs tarball for version ${PACKAGE_VERSION}..." ofarc -cq objfw-docs-${PACKAGE_VERSION}.tar \ objfw-docs-${PACKAGE_VERSION} rm -fr objfw-docs-${PACKAGE_VERSION} gzip -9 objfw-docs-${PACKAGE_VERSION}.tar rm -f objfw-docs-${PACKAGE_VERSION}.tar gpg -b objfw-docs-${PACKAGE_VERSION}.tar.gz || true |
Modified README.md from [939967b8be] to [711c05e9ce].
︙ | ︙ | |||
225 226 227 228 229 230 231 | The first thing to install is [MSYS2](https://www.msys2.org) to provide a basic UNIX-like environment for Windows. Unfortunately, the binaries are not signed, so make sure you download it via HTTPS. However, packages you download and install via MSYS2 are cryptographically signed. <h3 id="setting-up-msys2">Setting up MSYS2</h3> | | | | < | < < < < < > > > > > > > > > > > > > > > > | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | The first thing to install is [MSYS2](https://www.msys2.org) to provide a basic UNIX-like environment for Windows. Unfortunately, the binaries are not signed, so make sure you download it via HTTPS. However, packages you download and install via MSYS2 are cryptographically signed. <h3 id="setting-up-msys2">Setting up MSYS2</h3> MSYS2 currently supports 7 different [environments](https://www.msys2.org/docs/environments/). All of them except for the one called just "MSYS" are supported, but which packages you need to install depends on the environment(s) you want to use. If you only want to target Windows 10 and newer, the CLANG64 and CLANG32 environments are the recommended ones. For CLANG64, use: $ pacman -Syu mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-fossil For CLANG32, use: $ pacman -Syu mingw-w64-clang-i686-clang mingw-w64-clang-i686-fossil For CLANGARM64, use (you need to use Fossil via another environment): $ pacman -Syu mingw-w64-clang-aarch64-clang For MINGW64, use: $ pacman -Syu mingw-w64-x86_64-clang mingw-w64-x86_64-fossil For MINGW32, use: $ pacman -Syu mingw-w64-i686-clang mingw-w64-i686-fossil For UCRT64, use: $ pacman -Syu mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-fossil When using `pacman` to install the packages, `pacman` might tell you to close the window. If it does so, close the window, restart MSYS2 and execute the `pacman` command again. There is nothing wrong with installing multiple environments, as MSYS2 has created shortcuts for each of them in your start menu. Just make sure to use the correct shortcut for the environment you want to use. |
︙ | ︙ | |||
307 308 309 310 311 312 313 | $ ./configure --host=m68k-amigaos <h1 id="first-app">Writing your first application with ObjFW</h1> To create your first, empty application, you can use `objfw-new`: | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | $ ./configure --host=m68k-amigaos <h1 id="first-app">Writing your first application with ObjFW</h1> To create your first, empty application, you can use `objfw-new`: $ objfw-new --app MyFirstApp This creates a file `MyFirstApp.m`. The `-[applicationDidFinishLaunching]` method is called as soon as ObjFW finished all initialization. Use this as the entry point to your own code. For example, you could add the following line there to create a "Hello World": [OFStdOut writeLine: @"Hello World!"]; |
︙ | ︙ |
Modified build-aux/m4/buildsys.m4 from [824bccf73b] to [0e90ccf38e].
︙ | ︙ | |||
205 206 207 208 209 210 211 | *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) LIB_CFLAGS='' LIB_LDFLAGS='-shared -Wl,--export-all-symbols' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='' LIB_SUFFIX='${LIB_MAJOR}.dll' | | | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) LIB_CFLAGS='' LIB_LDFLAGS='-shared -Wl,--export-all-symbols' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='' LIB_SUFFIX='${LIB_MAJOR}.dll' LINK_LIB='&& rm -f lib$${out%${LIB_SUFFIX}}.dll.a && ${LN_S} $$out lib$${out%${LIB_SUFFIX}}.dll.a' PLUGIN_CFLAGS='' PLUGIN_LDFLAGS='-shared -Wl,--export-all-symbols' PLUGIN_SUFFIX='.dll' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_LIB='&& ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 lib$${i%${LIB_SUFFIX}}.dll.a ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' UNINSTALL_LIB='&& rm -f ${DESTDIR}${bindir}/$$i ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.dll.a' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' |
︙ | ︙ |
Modified buildsys.mk.in from [a085f99653] to [2dfee6e012].
︙ | ︙ | |||
77 78 79 80 81 82 83 | MKDIR_P = mkdir -p INSTALL = @INSTALL@ SHELL = @SHELL@ MSGFMT = @MSGFMT@ JAVAC = @JAVAC@ JAVACFLAGS = @JAVACFLAGS@ JAR = @JAR@ | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | MKDIR_P = mkdir -p INSTALL = @INSTALL@ SHELL = @SHELL@ MSGFMT = @MSGFMT@ JAVAC = @JAVAC@ JAVACFLAGS = @JAVACFLAGS@ JAR = @JAR@ RC = @RC@ BUILD_AND_HOST_ARE_DARWIN = @BUILD_AND_HOST_ARE_DARWIN@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ libdir = @libdir@ amigalibdir ?= ${prefix}/libs plugindir ?= ${libdir}/${PACKAGE_NAME} |
︙ | ︙ | |||
575 576 577 578 579 580 581 | ${COMPILE_FAILED}; \ fi .rc.o .rc.lib.o .rc.plugin.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ | | | 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | ${COMPILE_FAILED}; \ fi .rc.o .rc.lib.o .rc.plugin.o: ${COMPILE_STATUS} in="$<"; \ out="$@"; \ if ${RC} ${RCFLAGS} ${CPPFLAGS} -J rc -O coff -o $@ $<; then \ ${COMPILE_OK}; \ else \ ${COMPILE_FAILED}; \ fi .S.o .S.amigalib.o: ${COMPILE_STATUS} |
︙ | ︙ | |||
769 770 771 772 773 774 775 | ${DIR_ENTER}; \ ${MAKE} -s uninstall || exit $$?; \ ${DIR_LEAVE}; \ done for i in "" ${SHARED_LIB}; do \ test x"$$i" = x"" && continue; \ | | | 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | ${DIR_ENTER}; \ ${MAKE} -s uninstall || exit $$?; \ ${DIR_LEAVE}; \ done for i in "" ${SHARED_LIB}; do \ test x"$$i" = x"" && continue; \ if test -f ${DESTDIR}${libdir}/$$i -o -f ${DESTDIR}${bindir}/$$i; then \ if : @UNINSTALL_LIB@; then \ ${DELETE_OK}; \ else \ ${DELETE_FAILED}; \ fi \ fi; \ done |
︙ | ︙ |
Modified configure.ac from [0a2b73491f] to [7dabccc96d].
︙ | ︙ | |||
99 100 101 102 103 104 105 | ;; *-msdosdjgpp*) enable_shared="no" enable_threads="no" enable_sockets="no" ;; *-*-mingw*) | | | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | ;; *-msdosdjgpp*) enable_shared="no" enable_threads="no" enable_sockets="no" ;; *-*-mingw*) LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition -static-libgcc" LIBS="$LIBS -lversion" AC_SUBST(USE_SRCS_WINDOWS, '${SRCS_WINDOWS}') ;; *-psp-*) AS_IF([test x"$DEVKITPSP" = x""], [ AC_MSG_ERROR([DEVKITPSP is not set! Please set DEVKITPSP.]) |
︙ | ︙ | |||
401 402 403 404 405 406 407 408 409 410 411 412 413 414 | ], [ AC_MSG_RESULT(no) AC_MSG_ERROR(Compiler does not support properties!) ]) AC_CHECK_TOOL(AR, ar) AC_PROG_RANLIB AC_ARG_ENABLE(amiga-lib, AS_HELP_STRING([--disable-amiga-lib], [do not build Amiga library])) AS_IF([test x"$supports_amiga_lib" != x"yes"], [enable_amiga_lib="no"]) AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) | > > > > > > | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | ], [ AC_MSG_RESULT(no) AC_MSG_ERROR(Compiler does not support properties!) ]) AC_CHECK_TOOL(AR, ar) AC_PROG_RANLIB case "$host_os" in mingw*) AC_CHECK_TOOL(RC, windres) ;; esac AC_ARG_ENABLE(amiga-lib, AS_HELP_STRING([--disable-amiga-lib], [do not build Amiga library])) AS_IF([test x"$supports_amiga_lib" != x"yes"], [enable_amiga_lib="no"]) AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) |
︙ | ︙ | |||
494 495 496 497 498 499 500 501 502 503 504 505 506 507 | #if defined(__GLIBC__) || defined(__MINGW32__) || \ defined(__NEWLIB__) || defined(__MORPHOS__) || defined(__MINT__) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" gnu_source="yes" ], [ AC_MSG_RESULT(no) ]) case "$host_os" in | > | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | #if defined(__GLIBC__) || defined(__MINGW32__) || \ defined(__NEWLIB__) || defined(__MORPHOS__) || defined(__MINT__) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 $CPPFLAGS" CPPFLAGS="-D_GNU_SOURCE $CPPFLAGS" gnu_source="yes" ], [ AC_MSG_RESULT(no) ]) case "$host_os" in |
︙ | ︙ | |||
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | dnl Compiler TLS is broken on AArch64 Android with Clang enable_compiler_tls="no" ;; m68k-*-amigaos* | powerpc-*-amigaos*) dnl Compiler TLS is broken on AmigaOS enable_compiler_tls="no" ;; *-*-morphos*) dnl Compiler TLS needs helpers that we don't want in the dnl .library enable_compiler_tls="no" ;; esac | > > > > | 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 | dnl Compiler TLS is broken on AArch64 Android with Clang enable_compiler_tls="no" ;; m68k-*-amigaos* | powerpc-*-amigaos*) dnl Compiler TLS is broken on AmigaOS enable_compiler_tls="no" ;; *-*-mingw*) dnl Causes emutls to be pulled in, which pulls in winpthread. enable_compiler_tls="no" ;; *-*-morphos*) dnl Compiler TLS needs helpers that we don't want in the dnl .library enable_compiler_tls="no" ;; esac |
︙ | ︙ | |||
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | AC_MSG_RESULT($atomic_ops) AC_ARG_ENABLE(files, AS_HELP_STRING([--disable-files], [disable file support])) AS_IF([test x"$enable_files" != x"no"], [ AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files]) AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}') AC_SUBST(OFARC, "ofarc") AC_SUBST(OFHASH, "ofhash") case "$host_os" in msdosdjgpp*) dnl DJGPP has the type, but it's not really usable. ;; | > | 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 | AC_MSG_RESULT($atomic_ops) AC_ARG_ENABLE(files, AS_HELP_STRING([--disable-files], [disable file support])) AS_IF([test x"$enable_files" != x"no"], [ AC_DEFINE(OF_HAVE_FILES, 1, [Whether we have files]) AC_SUBST(USE_SRCS_FILES, '${SRCS_FILES}') AC_SUBST(OBJFW_NEW, "objfw-new") AC_SUBST(OFARC, "ofarc") AC_SUBST(OFHASH, "ofhash") case "$host_os" in msdosdjgpp*) dnl DJGPP has the type, but it's not really usable. ;; |
︙ | ︙ |
Modified extra.mk.in from [889cd88ab7] to [886ab17692].
︙ | ︙ | |||
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | LINKLIB = @LINKLIB@ LOOKUP_ASM_A = @LOOKUP_ASM_A@ LOOKUP_ASM_AMIGALIB_A = @LOOKUP_ASM_AMIGALIB_A@ LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@ MAP_LDFLAGS = @MAP_LDFLAGS@ OBJC_SYNC = @OBJC_SYNC@ OBJFW_LIBS = @OBJFW_LIBS@ OFARC = @OFARC@ OFDNS = @OFDNS@ OFHASH = @OFHASH@ OFHTTP = @OFHTTP@ OFHTTP_LIBS = @OFHTTP_LIBS@ OF_BLOCK_TESTS_M = @OF_BLOCK_TESTS_M@ OF_EPOLL_KERNEL_EVENT_OBSERVER_M = @OF_EPOLL_KERNEL_EVENT_OBSERVER_M@ | > | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | LINKLIB = @LINKLIB@ LOOKUP_ASM_A = @LOOKUP_ASM_A@ LOOKUP_ASM_AMIGALIB_A = @LOOKUP_ASM_AMIGALIB_A@ LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@ MAP_LDFLAGS = @MAP_LDFLAGS@ OBJC_SYNC = @OBJC_SYNC@ OBJFW_LIBS = @OBJFW_LIBS@ OBJFW_NEW = @OBJFW_NEW@ OFARC = @OFARC@ OFDNS = @OFDNS@ OFHASH = @OFHASH@ OFHTTP = @OFHTTP@ OFHTTP_LIBS = @OFHTTP_LIBS@ OF_BLOCK_TESTS_M = @OF_BLOCK_TESTS_M@ OF_EPOLL_KERNEL_EVENT_OBSERVER_M = @OF_EPOLL_KERNEL_EVENT_OBSERVER_M@ |
︙ | ︙ |
Modified generators/library/LibraryGenerator.m from [ffe3d87b12] to [9e464281b0].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFApplication.h" #import "OFFile.h" #import "OFFileManager.h" | | | | | | | | | | | | | | | | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | */ #include "config.h" #import "OFApplication.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFURI.h" #import "OFXMLElement.h" #import "FuncArrayGenerator.h" #import "GlueGenerator.h" #import "LinkLibGenerator.h" @interface LibraryGenerator: OFObject <OFApplicationDelegate> @end OF_APPLICATION_DELEGATE(LibraryGenerator) @implementation LibraryGenerator - (void)generateInDirectory: (OFString *)directory { OFURI *sourcesURI = [[OFFileManager defaultManager].currentDirectoryURI URIByAppendingPathComponent: directory]; OFURI *libraryURI = [sourcesURI URIByAppendingPathComponent: @"amiga-library.xml"]; OFURI *linkLibURI = [sourcesURI URIByAppendingPathComponent: @"linklib/linklib.m"]; OFURI *glueHeaderURI = [sourcesURI URIByAppendingPathComponent: @"amiga-glue.h"]; OFURI *glueURI = [sourcesURI URIByAppendingPathComponent: @"amiga-glue.m"]; OFURI *funcArrayURI = [sourcesURI URIByAppendingPathComponent: @"amiga-funcarray.inc"]; OFXMLElement *library = [OFXMLElement elementWithStream: [OFFile fileWithPath: libraryURI.fileSystemRepresentation mode: @"r"]]; OFFile *linkLib = [OFFile fileWithPath: linkLibURI.fileSystemRepresentation mode: @"w"]; OFFile *glueHeader = [OFFile fileWithPath: glueHeaderURI.fileSystemRepresentation mode: @"w"]; OFFile *glue = [OFFile fileWithPath: glueURI.fileSystemRepresentation mode: @"w"]; OFFile *funcArray = [OFFile fileWithPath: funcArrayURI.fileSystemRepresentation mode: @"w"]; LinkLibGenerator *linkLibGenerator = [[[LinkLibGenerator alloc] initWithLibrary: library implementation: linkLib] autorelease]; GlueGenerator *glueGenerator = [[[GlueGenerator alloc] initWithLibrary: library header: glueHeader |
︙ | ︙ |
Modified generators/unicode/TableGenerator.m from [442fb49647] to [c1835e042f].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #include <string.h> #import "OFString.h" #import "OFArray.h" #import "OFApplication.h" | | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include "config.h" #include <string.h> #import "OFString.h" #import "OFArray.h" #import "OFApplication.h" #import "OFURI.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFHTTPClient.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFOutOfRangeException.h" #import "TableGenerator.h" #import "copyright.h" static OFString *const unicodeDataURI = @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"; static OFString *const caseFoldingURI = @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"; OF_APPLICATION_DELEGATE(TableGenerator) @implementation TableGenerator - (instancetype)init { |
︙ | ︙ | |||
64 65 66 67 68 69 70 | - (void)applicationDidFinishLaunching { OFHTTPRequest *request; [OFStdOut writeString: @"Downloading UnicodeData.txt…"]; _state = stateUnicodeData; | | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | - (void)applicationDidFinishLaunching { OFHTTPRequest *request; [OFStdOut writeString: @"Downloading UnicodeData.txt…"]; _state = stateUnicodeData; request = [OFHTTPRequest requestWithURI: [OFURI URIWithString: unicodeDataURI]]; [_HTTPClient asyncPerformRequest: request]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception |
︙ | ︙ | |||
133 134 135 136 137 138 139 | OFArray *decomposed = [[components objectAtIndex: 5] componentsSeparatedByString: @" "]; bool compat = false; OFMutableString *string; if ([decomposed.firstObject hasPrefix: @"<"]) { decomposed = [decomposed objectsInRange: | | | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | OFArray *decomposed = [[components objectAtIndex: 5] componentsSeparatedByString: @" "]; bool compat = false; OFMutableString *string; if ([decomposed.firstObject hasPrefix: @"<"]) { decomposed = [decomposed objectsInRange: OFMakeRange(1, decomposed.count - 1)]; compat = true; } string = [OFMutableString string]; for (OFString *character in decomposed) { OFUnichar unichar = (OFUnichar)[character |
︙ | ︙ | |||
164 165 166 167 168 169 170 | [self applyDecompositionRecursivelyForTable: _decompositionTable]; [self applyDecompositionRecursivelyForTable: _decompositionCompatTable]; [OFStdOut writeLine: @" done"]; [OFStdOut writeString: @"Downloading CaseFolding.txt…"]; _state = stateCaseFolding; | | | | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | [self applyDecompositionRecursivelyForTable: _decompositionTable]; [self applyDecompositionRecursivelyForTable: _decompositionCompatTable]; [OFStdOut writeLine: @" done"]; [OFStdOut writeString: @"Downloading CaseFolding.txt…"]; _state = stateCaseFolding; request = [OFHTTPRequest requestWithURI: [OFURI URIWithString: caseFoldingURI]]; [_HTTPClient asyncPerformRequest: request]; } - (void)parseCaseFolding: (OFHTTPResponse *)response { OFString *line; |
︙ | ︙ | |||
266 267 268 269 270 271 272 | objc_autoreleasePoolPop(pool); } } while (!done); } - (void)writeFiles { | | | | | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | objc_autoreleasePoolPop(pool); } } while (!done); } - (void)writeFiles { OFURI *URI; [OFStdOut writeString: @"Writing files…"]; URI = [OFURI fileURIWithPath: @"../../src/unicode.m"]; [self writeTablesToFile: URI.fileSystemRepresentation]; URI = [OFURI fileURIWithPath: @"../../src/unicode.h"]; [self writeHeaderToFile: URI.fileSystemRepresentation]; [OFStdOut writeLine: @" done"]; [OFApplication terminate]; } - (void)writeTablesToFile: (OFString *)path |
︙ | ︙ |
Modified src/Makefile from [aac3885b94] to [154d61da0e].
︙ | ︙ | |||
27 28 29 30 31 32 33 | OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptographicHashing.m \ OFData+MessagePackParsing.m \ OFDate.m \ OFDictionary.m \ | < < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptographicHashing.m \ OFData+MessagePackParsing.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ OFFileManager.m \ OFGZIPStream.m \ OFHMAC.m \ OFINICategory.m \ OFINIFile.m \ OFInflate64Stream.m \ OFInflateStream.m \ OFInvocation.m \ OFLHAArchive.m \ OFLHAArchiveEntry.m \ OFList.m \ OFLocale.m \ |
︙ | ︙ | |||
56 57 58 59 60 61 62 | OFMutableDictionary.m \ OFMutableLHAArchiveEntry.m \ OFMutablePair.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableTarArchiveEntry.m \ OFMutableTriple.m \ | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | OFMutableDictionary.m \ OFMutableLHAArchiveEntry.m \ OFMutablePair.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableTarArchiveEntry.m \ OFMutableTriple.m \ OFMutableURI.m \ OFMutableZIPArchiveEntry.m \ OFNotification.m \ OFNotificationCenter.m \ OFNull.m \ OFNumber.m \ OFObject.m \ OFObject+KeyValueCoding.m \ |
︙ | ︙ | |||
89 90 91 92 93 94 95 96 97 | OFSet.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptographicHashing.m \ OFString+JSONParsing.m \ OFString+PropertyListParsing.m \ OFString+Serialization.m \ | > < | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | OFSet.m \ OFSortedList.m \ OFStdIOStream.m \ OFStream.m \ OFString.m \ OFString+CryptographicHashing.m \ OFString+JSONParsing.m \ OFString+PercentEncoding.m \ OFString+PropertyListParsing.m \ OFString+Serialization.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ ${OF_SUBPROCESS_M} \ OFSettings.m \ OFSystemInfo.m \ OFTarArchive.m \ OFTarArchiveEntry.m \ OFThread.m \ OFTimer.m \ OFTriple.m \ OFURI.m \ OFURIHandler.m \ OFUUID.m \ OFValue.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ OFXMLElement.m \ |
︙ | ︙ | |||
157 158 159 160 161 162 163 | SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m | < | > > > > > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m SRCS_WINDOWS = OFWindowsRegistryKey.m INCLUDES_ATOMIC = OFAtomic.h \ platform/GCC4/OFAtomic.h \ platform/GCC4.7/OFAtomic.h \ platform/PowerPC/OFAtomic.h \ platform/macOS/OFAtomic.h \ platform/x86/OFAtomic.h INCLUDES := ${SRCS:.m=.h} \ OFArchiveEntry.h \ OFCollection.h \ OFCryptographicHash.h \ OFJSONRepresentation.h \ OFKernelEventObserver.h \ OFKeyValueCoding.h \ OFLocking.h \ OFMessagePackRepresentation.h \ OFMutableArchiveEntry.h \ ObjFW.h \ macros.h \ objfw-defs.h \ platform.h \ ${USE_INCLUDES_ATOMIC} SRCS += OFASPrintF.m \ OFAdjacentArray.m \ OFAdjacentSubarray.m \ OFArchiveURIHandler.m \ OFBase64.m \ OFBitSetCharacterSet.m \ OFBytesValue.m \ OFCRC16.m \ OFCRC32.m \ OFCountedMapTableSet.m \ OFEmbeddedURIHandler.m \ OFHuffmanTree.m \ OFINIFileSettings.m \ OFInvertedCharacterSet.m \ OFLHADecompressingStream.m \ OFMapTableDictionary.m \ OFMapTableSet.m \ OFMutableAdjacentArray.m \ OFMutableMapTableDictionary.m \ OFMutableMapTableSet.m \ |
︙ | ︙ | |||
212 213 214 215 216 217 218 | OFSizeValue.m \ OFStrPTime.m \ OFSubarray.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} \ | | | | > > | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | OFSizeValue.m \ OFStrPTime.m \ OFSubarray.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} \ ${UNICODE_M} SRCS_FILES += OFFileURIHandler.m SRCS_SOCKETS += OFDNSResolverSettings.m \ ${OF_EPOLL_KERNEL_EVENT_OBSERVER_M} \ OFHTTPURIHandler.m \ OFHostAddressResolver.m \ OFIPSocketAsyncConnector.m \ OFKernelEventObserver.m \ ${OF_KQUEUE_KERNEL_EVENT_OBSERVER_M} \ ${OF_POLL_KERNEL_EVENT_OBSERVER_M} \ ${OF_SELECT_KERNEL_EVENT_OBSERVER_M} \ OFTCPSocketSOCKS5Connector.m SRCS_WINDOWS += platform/Windows/OFWin32ConsoleStdIOStream.m \ versioninfo.rc OBJS_EXTRA = exceptions/exceptions.a \ encodings/encodings.a \ forwarding/forwarding.a LIB_OBJS_EXTRA = exceptions/exceptions.lib.a \ encodings/encodings.lib.a \ forwarding/forwarding.lib.a |
︙ | ︙ | |||
252 253 254 255 256 257 258 | LD = ${OBJC} FRAMEWORK_LIBS := -Fruntime \ ${RUNTIME_FRAMEWORK_LIBS} \ ${REEXPORT_RUNTIME_FRAMEWORK} \ ${LIBS} LIBS := -Lruntime -Lruntime/linklib ${RUNTIME_LIBS} ${REEXPORT_RUNTIME} ${LIBS} AMIGA_LIB_LIBS = ${LIBS} | > > > > > | 256 257 258 259 260 261 262 263 264 265 266 267 | LD = ${OBJC} FRAMEWORK_LIBS := -Fruntime \ ${RUNTIME_FRAMEWORK_LIBS} \ ${REEXPORT_RUNTIME_FRAMEWORK} \ ${LIBS} LIBS := -Lruntime -Lruntime/linklib ${RUNTIME_LIBS} ${REEXPORT_RUNTIME} ${LIBS} AMIGA_LIB_LIBS = ${LIBS} RCFLAGS = --use-temp-file \ -DOBJFW_LIB_MAJOR=${OBJFW_LIB_MAJOR} \ -DOBJFW_LIB_MINOR=${OBJFW_LIB_MINOR} \ -DOBJFW_LIB_VERSION=\"${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}\" \ -DOBJFW_SHARED_LIB=\"${OBJFW_SHARED_LIB}\" |
Modified src/OFASPrintF.m from [31044637f2] to [882db55cea].
︙ | ︙ | |||
578 579 580 581 582 583 584 | return false; /* * If there's no asprintf_l, we have no other choice than to * use this ugly hack to replace the locale's decimal point * back to ".". */ | | | 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | return false; /* * If there's no asprintf_l, we have no other choice than to * use this ugly hack to replace the locale's decimal point * back to ".". */ point = [OFLocale decimalSeparator]; if (!ctx->useLocale && point != nil && ![point isEqual: @"."]) { void *pool = objc_autoreleasePoolPush(); char *tmp2; @try { OFMutableString *tmpStr = [OFMutableString |
︙ | ︙ |
Added src/OFArchiveEntry.h version [70aea150d9].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFDate; @class OFNumber; /** * @protocol OFArchiveEntry OFArchiveEntry.h ObjFW/OFArchiveEntry.h * * @brief A class which represents an entry in an archive. */ @protocol OFArchiveEntry <OFObject> /** * @brief The file name of the entry. */ @property (readonly, copy, nonatomic) OFString *fileName; /** * @brief The compressed size of the entry's file. */ @property (readonly, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ @property (readonly, nonatomic) unsigned long long uncompressedSize; @optional /** * @brief The modification date of the file. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; /** * @brief The comment of the entry's file. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fileComment; /** * @brief The POSIX permissions of the file. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *POSIXPermissions; /** * @brief The file owner's account ID. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *ownerAccountID; /** * @brief The file owner's group account ID. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *groupOwnerAccountID; /** * @brief The file owner's account name. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFString *ownerAccountName; /** * @brief The file owner's group account name. */ @property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFString *groupOwnerAccountName; @end OF_ASSUME_NONNULL_END #import "OFMutableArchiveEntry.h" |
Added src/OFArchiveURIHandler.h version [7c81cf8db2].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 OFArchiveURIHandler: OFURIHandler @end #ifdef __cplusplus extern "C" { #endif extern OFURI *OFArchiveURIHandlerURIForFileInArchive(OFString *, OFString *, OFURI *); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Added src/OFArchiveURIHandler.m version [010e8050b6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 <errno.h> #import "OFArchiveURIHandler.h" #import "OFCharacterSet.h" #import "OFGZIPStream.h" #import "OFLHAArchive.h" #import "OFStream.h" #import "OFTarArchive.h" #import "OFURI.h" #import "OFZIPArchive.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" @interface OFArchiveURIHandlerPathAllowedCharacterSet: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } @end static OFCharacterSet *pathAllowedCharacters; static void initPathAllowedCharacters(void) { pathAllowedCharacters = [[OFArchiveURIHandlerPathAllowedCharacterSet alloc] init]; } @implementation OFArchiveURIHandler - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFString *scheme = URI.scheme; OFString *percentEncodedPath, *path; size_t pos; OFURI *archiveURI; OFStream *stream; if (URI.host != nil || URI.port != nil || URI.user != nil || URI.password != nil || URI.query != nil || URI.fragment != nil) @throw [OFInvalidArgumentException exception]; if (![mode isEqual: @"r"]) /* * Writing has some implications that are not decided yet: Will * it always append to an archive? What happens if the file * already exists? */ @throw [OFInvalidArgumentException exception]; /* * GZIP only compresses one file and thus has no path inside an * archive. */ if ([scheme isEqual: @"gzip"]) { stream = [OFURIHandler openItemAtURI: [OFURI URIWithString: URI.path] mode: @"r"]; stream = [OFGZIPStream streamWithStream: stream mode: @"r"]; goto end; } percentEncodedPath = URI.percentEncodedPath; pos = [percentEncodedPath rangeOfString: @"!"].location; if (pos == OFNotFound) @throw [OFInvalidArgumentException exception]; archiveURI = [OFURI URIWithString: [percentEncodedPath substringWithRange: OFMakeRange(0, pos)] .stringByRemovingPercentEncoding]; path = [percentEncodedPath substringWithRange: OFMakeRange(pos + 1, percentEncodedPath.length - pos - 1)] .stringByRemovingPercentEncoding; if ([scheme isEqual: @"lha"]) { OFLHAArchive *archive = [OFLHAArchive archiveWithURI: archiveURI mode: @"r"]; OFLHAArchiveEntry *entry; while ((entry = [archive nextEntry]) != nil) { if ([entry.fileName isEqual: path]) { stream = [archive streamForReadingCurrentEntry]; goto end; } } @throw [OFOpenItemFailedException exceptionWithURI: URI mode: mode errNo: ENOENT]; } else if ([scheme isEqual: @"tar"]) { OFTarArchive *archive = [OFTarArchive archiveWithURI: archiveURI mode: @"r"]; OFTarArchiveEntry *entry; while ((entry = [archive nextEntry]) != nil) { if ([entry.fileName isEqual: path]) { stream = [archive streamForReadingCurrentEntry]; goto end; } } @throw [OFOpenItemFailedException exceptionWithURI: URI mode: mode errNo: ENOENT]; } else if ([scheme isEqual: @"zip"]) { OFZIPArchive *archive = [OFZIPArchive archiveWithURI: archiveURI mode: @"r"]; stream = [archive streamForReadingFile: path]; } else @throw [OFInvalidArgumentException exception]; end: stream = [stream retain]; objc_autoreleasePoolPop(pool); return [stream autorelease]; } @end @implementation OFArchiveURIHandlerPathAllowedCharacterSet - (instancetype)init { self = [super init]; @try { _characterSet = [[OFCharacterSet URIPathAllowedCharacterSet] retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return (character != '!' && _characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end OFURI * OFArchiveURIHandlerURIForFileInArchive(OFString *scheme, OFString *pathInArchive, OFURI *archiveURI) { static OFOnceControl onceControl = OFOnceControlInitValue; OFMutableURI *ret = [OFMutableURI URIWithScheme: scheme]; void *pool = objc_autoreleasePoolPush(); OFString *archiveURIString; OFOnce(&onceControl, initPathAllowedCharacters); pathInArchive = [pathInArchive stringByAddingPercentEncodingWithAllowedCharacters: pathAllowedCharacters]; archiveURIString = [archiveURI.string stringByAddingPercentEncodingWithAllowedCharacters: pathAllowedCharacters]; ret.percentEncodedPath = [OFString stringWithFormat: @"%@!%@", archiveURIString, pathInArchive]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } |
Modified src/OFArray.m from [7359b37923] to [c89de989b4].
︙ | ︙ | |||
238 239 240 241 242 243 244 | - (id const *)objects { size_t count = self.count; id *buffer = OFAllocMemory(count, sizeof(id)); id const *ret; @try { | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | - (id const *)objects { size_t count = self.count; id *buffer = OFAllocMemory(count, sizeof(id)); id const *ret; @try { [self getObjects: buffer inRange: OFMakeRange(0, count)]; ret = [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); |
︙ | ︙ | |||
531 532 533 534 535 536 537 | if (self.count == 0) return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { | | | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | if (self.count == 0) return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret insertString: @"(\n" atIndex: 0]; [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)"]; } @catch (id e) { [ret release]; @throw e; } |
︙ | ︙ | |||
747 748 749 750 751 752 753 | return new; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { | | | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | return new; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFRange range = OFMakeRange(state->state, count); if (range.length > SIZE_MAX - range.location) @throw [OFOutOfRangeException exception]; if (range.location + range.length > self.count) range.length = self.count - range.location; |
︙ | ︙ |
Modified src/OFColor.m from [5191910ddc] to [ff82ab6aae].
︙ | ︙ | |||
124 125 126 127 128 129 130 | unsigned long hash; float tmp; OFHashInit(&hash); tmp = OFToLittleEndianFloat(_red); for (uint_fast8_t i = 0; i < sizeof(float); i++) | | | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | unsigned long hash; float tmp; OFHashInit(&hash); tmp = OFToLittleEndianFloat(_red); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_green); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_blue); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_alpha); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (void)getRed: (float *)red |
︙ | ︙ |
Modified src/OFCondition.h from [b8eb2412a1] to [ced99784d6].
︙ | ︙ | |||
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /** * @brief Blocks the current thread until another thread calls @ref signal or * @ref broadcast. * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref wait returned! */ - (void)wait; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or an Exec Signal is received. * * @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. */ - (void)waitForConditionOrExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @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 */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @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 */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @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 */ - (bool)waitUntilDate: (OFDate *)date; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @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 */ - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask; #endif /** * @brief Signals the next waiting thread to continue. */ - (void)signal; /** * @brief Signals all threads to continue. */ - (void)broadcast; @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | /** * @brief Blocks the current thread until another thread calls @ref signal or * @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 */ - (void)wait; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or an Exec Signal is received. * * @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 */ - (void)waitForConditionOrExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @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 */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @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 */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * * @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 */ - (bool)waitUntilDate: (OFDate *)date; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @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 */ - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask; #endif /** * @brief Signals the next waiting thread to continue. * * @throw OFConditionSignalFailedException Signaling the condition failed */ - (void)signal; /** * @brief Signals all threads to continue. * * @throw OFConditionBroadcastFailedException Broadcasting the condition failed */ - (void)broadcast; @end OF_ASSUME_NONNULL_END |
Modified src/OFConstantString.m from [d768085319] to [3adc07df05].
︙ | ︙ | |||
352 353 354 355 356 357 358 | - (OFString *)stringByAppendingPathExtension: (OFString *)extension { [self finishInitialization]; return [self stringByAppendingPathExtension: extension]; } | < < < < < < | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | - (OFString *)stringByAppendingPathExtension: (OFString *)extension { [self finishInitialization]; return [self stringByAppendingPathExtension: extension]; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self finishInitialization]; return [self stringByReplacingOccurrencesOfString: string withString: replacement]; } |
︙ | ︙ | |||
479 480 481 482 483 484 485 | - (long long)longLongValue { [self finishInitialization]; return self.longLongValue; } | | | | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | - (long long)longLongValue { [self finishInitialization]; return self.longLongValue; } - (long long)longLongValueWithBase: (unsigned char)base { [self finishInitialization]; return [self longLongValueWithBase: base]; } - (unsigned long long)unsignedLongLongValue { [self finishInitialization]; return self.unsignedLongLongValue; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { [self finishInitialization]; return [self unsignedLongLongValueWithBase: base]; } - (float)floatValue { |
︙ | ︙ | |||
587 588 589 590 591 592 593 | - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToFile: path encoding: encoding]; } #endif | | | | | | 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToFile: path encoding: encoding]; } #endif - (void)writeToURI: (OFURI *)URI { [self finishInitialization]; [self writeToURI: URI]; } - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToURI: URI encoding: encoding]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { [self finishInitialization]; [self enumerateLinesUsingBlock: block]; } #endif @end |
Modified src/OFCryptographicHash.h from [21f208b184] to [635d4f982a].
︙ | ︙ | |||
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | @property (readonly, nonatomic, getter=isCalculated) bool calculated; /** * @brief A buffer containing the cryptographic hash. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief Creates a new cryptographic hash. * | > > | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | @property (readonly, nonatomic, getter=isCalculated) bool calculated; /** * @brief A buffer containing the cryptographic hash. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. * * @throw OFHashNotCalculatedException The hash hasn't been calculated yet */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief Creates a new cryptographic hash. * |
︙ | ︙ | |||
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | - (instancetype)init OF_UNAVAILABLE; /** * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the cryptographic hash. */ - (void)calculate; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If | > > > | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | - (instancetype)init OF_UNAVAILABLE; /** * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer * @throw OFHashAlreadyCalculatedException The hash has already been calculated */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the cryptographic hash. * * @throw OFHashAlreadyCalculatedException The hash has already been calculated */ - (void)calculate; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If |
︙ | ︙ |
Modified src/OFDNSQuery.h from [9c2a0f4bc6] to [b49f52a5a4].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 | @class OFString; /** * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h * * @brief A class representing a DNS query. */ @interface OFDNSQuery: OFObject <OFCopying> { OFString *_domainName; OFDNSClass _DNSClass; OFDNSRecordType _recordType; | > < | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | @class OFString; /** * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h * * @brief A class representing a DNS query. */ OF_SUBCLASSING_RESTRICTED @interface OFDNSQuery: OFObject <OFCopying> { OFString *_domainName; OFDNSClass _DNSClass; OFDNSRecordType _recordType; } /** * @brief The domain name of the query. */ @property (readonly, nonatomic) OFString *domainName; |
︙ | ︙ |
Modified src/OFDNSQuery.m from [03ea4234b3] to [eb5858939c].
︙ | ︙ | |||
93 94 95 96 97 98 99 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); | | | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType); OFHashFinalize(&hash); return hash; } - (id)copy { |
︙ | ︙ |
Modified src/OFDNSResolver.h from [0eee98275d] to [a91104c174].
︙ | ︙ | |||
256 257 258 259 260 261 262 263 264 265 266 267 268 269 | /** * @brief Synchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @return OFData containing several OFSocketAddress */ - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily; /** * @brief Closes all sockets and cancels all ongoing queries. */ | > > | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | /** * @brief Synchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @return OFData containing several OFSocketAddress * @throw OFInvalidServerResponseException The received response was invalid * @throw OFTruncatedDataException The received response was truncated */ - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily; /** * @brief Closes all sockets and cancels all ongoing queries. */ |
︙ | ︙ |
Modified src/OFDNSResolver.m from [6722a88381] to [982d647b8f].
︙ | ︙ | |||
34 35 36 37 38 39 40 | #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSQueryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" | | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSQueryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #ifndef SOCK_DNS # define SOCK_DNS 0 #endif |
︙ | ︙ | |||
124 125 126 127 128 129 130 | componentLength = buffer[(*i)++]; if (componentLength & 0xC0) { size_t j; OFString *suffix; if (pointerLevel == 0) | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | componentLength = buffer[(*i)++]; if (componentLength & 0xC0) { size_t j; OFString *suffix; if (pointerLevel == 0) @throw [OFInvalidServerResponseException exception]; if (*i >= length) @throw [OFTruncatedDataException exception]; j = ((componentLength & 0x3F) << 8) | buffer[(*i)++]; if (j == *i - 2) /* Pointing to itself?! */ @throw [OFInvalidServerResponseException exception]; suffix = parseName(buffer, length, &j, pointerLevel - 1); if (components.count == 0) return suffix; |
︙ | ︙ | |||
171 172 173 174 175 176 177 | OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer, size_t length, size_t i, uint16_t dataLength) { if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 4) | | | | | | | 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer, size_t length, size_t i, uint16_t dataLength) { if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 4) @throw [OFInvalidServerResponseException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv4; address.length = sizeof(address.sockaddr.in); address.sockaddr.in.sin_family = AF_INET; memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4); return [[[OFADNSResourceRecord alloc] initWithName: name address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeNS) { size_t j = i; OFString *authoritativeHost = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFNSDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass authoritativeHost: authoritativeHost TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeCNAME) { size_t j = i; OFString *alias = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFCNAMEDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass alias: alias TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSOA) { size_t j = i; OFString *primaryNameServer = parseName(buffer, length, &j, maxAllowedPointers); OFString *responsiblePerson; uint32_t serialNumber, refreshInterval, retryInterval; uint32_t expirationInterval, minTTL; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; responsiblePerson = parseName(buffer, length, &j, maxAllowedPointers); if (dataLength - (j - i) != 20) @throw [OFInvalidServerResponseException exception]; serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) | (buffer[j + 2] << 8) | buffer[j + 3]; refreshInterval = (buffer[j + 4] << 24) | (buffer[j + 5] << 16) | (buffer[j + 6] << 8) | buffer[j + 7]; retryInterval = (buffer[j + 8] << 24) | (buffer[j + 9] << 16) | |
︙ | ︙ | |||
257 258 259 260 261 262 263 | TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypePTR) { size_t j = i; OFString *domainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) | | | | | | | | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypePTR) { size_t j = i; OFString *domainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFPTRDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass domainName: domainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeHINFO) { size_t j = i; OFString *CPU = parseString(buffer, length, &j); OFString *OS; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; OS = parseString(buffer, length, &j); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFHINFODNSResourceRecord alloc] initWithName: name DNSClass: DNSClass CPU: CPU OS: OS TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeMX) { uint16_t preference; size_t j; OFString *mailExchange; if (dataLength < 2) @throw [OFInvalidServerResponseException exception]; preference = (buffer[i] << 8) | buffer[i + 1]; j = i + 2; mailExchange = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFMXDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass preference: preference mailExchange: mailExchange TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeTXT) { OFMutableArray *textStrings = [OFMutableArray array]; while (dataLength > 0) { uint_fast8_t stringLength = buffer[i++]; dataLength--; if (stringLength > dataLength) @throw [OFInvalidServerResponseException exception]; [textStrings addObject: [OFData dataWithItems: buffer + i count: stringLength]]; i += stringLength; |
︙ | ︙ | |||
339 340 341 342 343 344 345 | } else if (recordType == OFDNSRecordTypeRP) { size_t j = i; OFString *mailbox = parseName(buffer, length, &j, maxAllowedPointers); OFString *TXTDomainName; if (j > i + dataLength) | | | | | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | } else if (recordType == OFDNSRecordTypeRP) { size_t j = i; OFString *mailbox = parseName(buffer, length, &j, maxAllowedPointers); OFString *TXTDomainName; if (j > i + dataLength) @throw [OFInvalidServerResponseException exception]; TXTDomainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFRPDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass mailbox: mailbox TXTDomainName: TXTDomainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeAAAA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 16) @throw [OFInvalidServerResponseException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv6; address.length = sizeof(address.sockaddr.in6); #ifdef AF_INET6 address.sockaddr.in6.sin6_family = AF_INET6; |
︙ | ︙ | |||
382 383 384 385 386 387 388 | } else if (recordType == OFDNSRecordTypeSRV && DNSClass == OFDNSClassIN) { uint16_t priority, weight, port; size_t j; OFString *target; if (dataLength < 6) | | | | 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | } else if (recordType == OFDNSRecordTypeSRV && DNSClass == OFDNSClassIN) { uint16_t priority, weight, port; size_t j; OFString *target; if (dataLength < 6) @throw [OFInvalidServerResponseException exception]; priority = (buffer[i] << 8) | buffer[i + 1]; weight = (buffer[i + 2] << 8) | buffer[i + 3]; port = (buffer[i + 4] << 8) | buffer[i + 5]; j = i + 6; target = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerResponseException exception]; return [[[OFSRVDNSResourceRecord alloc] initWithName: name priority: priority weight: weight target: target port: port |
︙ | ︙ | |||
933 934 935 936 937 938 939 | context->_queryData.count < 12) @throw [OFInvalidArgumentException exception]; queryDataBuffer = context->_queryData.items; /* QR */ if ((buffer[2] & 0x80) == 0) | | | | 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 | context->_queryData.count < 12) @throw [OFInvalidArgumentException exception]; queryDataBuffer = context->_queryData.items; /* QR */ if ((buffer[2] & 0x80) == 0) @throw [OFInvalidServerResponseException exception]; /* Opcode */ if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78)) @throw [OFInvalidServerResponseException exception]; /* TC */ if (buffer[2] & 0x02) { OFRunLoopMode runLoopMode; if (context->_settings->_usesTCP) @throw [OFTruncatedDataException exception]; |
︙ | ︙ |
Modified src/OFDNSResolverSettings.m from [a43cd003ad] to [27f5b4db4d].
︙ | ︙ | |||
178 179 180 181 182 183 184 | static OFArray OF_GENERIC(OFString *) * parseNetStackArray(OFString *string) { if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"]) return nil; | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | static OFArray OF_GENERIC(OFString *) * parseNetStackArray(OFString *string) { if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"]) return nil; string = [string substringWithRange: OFMakeRange(1, string.length - 2)]; return [string componentsSeparatedByString: @"|"]; } #endif @implementation OFDNSResolverSettings - (void)dealloc |
︙ | ︙ | |||
282 283 284 285 286 287 288 | options: OFStringSkipEmptyComponents]; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: | | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | options: OFStringSkipEmptyComponents]; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFMakeRange(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; |
︙ | ︙ | |||
385 386 387 388 389 390 391 | if (components.count < 2) { objc_autoreleasePoolPop(pool2); continue; } option = components.firstObject; arguments = [components objectsInRange: | | | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | if (components.count < 2) { objc_autoreleasePoolPop(pool2); continue; } option = components.firstObject; arguments = [components objectsInRange: OFMakeRange(1, components.count - 1)]; if ([option isEqual: @"nameserver"]) { if (arguments.count != 1) { objc_autoreleasePoolPop(pool2); continue; } |
︙ | ︙ | |||
484 485 486 487 488 489 490 | OFArray *hosts; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: | | | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | OFArray *hosts; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFMakeRange(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; |
︙ | ︙ | |||
619 620 621 622 623 624 625 | [self setDefaults]; #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES OFWindowsRegistryKey *key = [[OFWindowsRegistryKey localMachineKey] openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters" | | > | 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | [self setDefaults]; #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES OFWindowsRegistryKey *key = [[OFWindowsRegistryKey localMachineKey] openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters" accessRights: KEY_QUERY_VALUE options: 0]; path = [[[key stringForValueNamed: @"DataBasePath"] stringByAppendingPathComponent: @"hosts"] stringByExpandingWindowsEnvironmentStrings]; if (path != nil) [self parseHosts: path]; # endif |
︙ | ︙ |
Modified src/OFDNSResourceRecord.h from [1c8f2631a7] to [30273f1f1b].
︙ | ︙ | |||
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | extern OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType); /** * @brief Parses the specified string as an @ref OFDNSClass. * * @param string The string to parse as an @ref OFDNSClass * @return The parsed OFDNSClass */ extern OFDNSClass OFDNSClassParseName(OFString *_Nonnull string); /** * @brief Parses the specified string as an @ref OFDNSRecordType. * * @param string The string to parse as an @ref OFDNSRecordType * @return The parsed OFDNSRecordType */ extern OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END | > > | 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | extern OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType); /** * @brief Parses the specified string as an @ref OFDNSClass. * * @param string The string to parse as an @ref OFDNSClass * @return The parsed OFDNSClass * @throw OFInvalidFormatException The specified string is not valid DNS class */ extern OFDNSClass OFDNSClassParseName(OFString *_Nonnull string); /** * @brief Parses the specified string as an @ref OFDNSRecordType. * * @param string The string to parse as an @ref OFDNSRecordType * @return The parsed OFDNSRecordType * @throw OFInvalidFormatException The specified string is not valid DNS class */ extern OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFDNSResourceRecord.m from [5aceee5a6c] to [b7ec251a31].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFDNSResourceRecord.h" #import "OFArray.h" #import "OFData.h" | < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #import "OFDNSResourceRecord.h" #import "OFArray.h" #import "OFData.h" #import "OFInvalidFormatException.h" OFString * OFDNSClassName(OFDNSClass DNSClass) { switch (DNSClass) { case OFDNSClassIN: |
︙ | ︙ | |||
75 76 77 78 79 80 81 | OFDNSClass DNSClass; string = string.uppercaseString; if ([string isEqual: @"IN"]) DNSClass = OFDNSClassIN; else { | < | | < < < | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | OFDNSClass DNSClass; string = string.uppercaseString; if ([string isEqual: @"IN"]) DNSClass = OFDNSClassIN; else { DNSClass = (OFDNSClass)[string unsignedLongLongValueWithBase: 0]; } objc_autoreleasePoolPop(pool); return DNSClass; } |
︙ | ︙ | |||
121 122 123 124 125 126 127 | else if ([string isEqual: @"AAAA"]) recordType = OFDNSRecordTypeAAAA; else if ([string isEqual: @"SRV"]) recordType = OFDNSRecordTypeSRV; else if ([string isEqual: @"ALL"]) recordType = OFDNSRecordTypeAll; else { | < | | < < < | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | else if ([string isEqual: @"AAAA"]) recordType = OFDNSRecordTypeAAAA; else if ([string isEqual: @"SRV"]) recordType = OFDNSRecordTypeSRV; else if ([string isEqual: @"ALL"]) recordType = OFDNSRecordTypeAll; else { recordType = (OFDNSRecordType)[string unsignedLongLongValueWithBase: 0]; } objc_autoreleasePoolPop(pool); return recordType; } |
︙ | ︙ | |||
246 247 248 249 250 251 252 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
331 332 333 334 335 336 337 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
426 427 428 429 430 431 432 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _alias.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
528 529 530 531 532 533 534 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _CPU.hash); OFHashAddHash(&hash, _OS.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
632 633 634 635 636 637 638 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | | | 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _preference >> 8); OFHashAddByte(&hash, _preference); OFHashAddHash(&hash, _mailExchange.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
733 734 735 736 737 738 739 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _authoritativeHost.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
831 832 833 834 835 836 837 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _domainName.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
936 937 938 939 940 941 942 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _mailbox.hash); OFHashAddHash(&hash, _TXTDomainName.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
1072 1073 1074 1075 1076 1077 1078 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | | | | | | | | | | | | | | | | | | | | | 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _primaryNameServer.hash); OFHashAddHash(&hash, _responsiblePerson.hash); OFHashAddByte(&hash, _serialNumber >> 24); OFHashAddByte(&hash, _serialNumber >> 16); OFHashAddByte(&hash, _serialNumber >> 8); OFHashAddByte(&hash, _serialNumber); OFHashAddByte(&hash, _refreshInterval >> 24); OFHashAddByte(&hash, _refreshInterval >> 16); OFHashAddByte(&hash, _refreshInterval >> 8); OFHashAddByte(&hash, _refreshInterval); OFHashAddByte(&hash, _retryInterval >> 24); OFHashAddByte(&hash, _retryInterval >> 16); OFHashAddByte(&hash, _retryInterval >> 8); OFHashAddByte(&hash, _retryInterval); OFHashAddByte(&hash, _expirationInterval >> 24); OFHashAddByte(&hash, _expirationInterval >> 16); OFHashAddByte(&hash, _expirationInterval >> 8); OFHashAddByte(&hash, _expirationInterval); OFHashAddByte(&hash, _minTTL >> 24); OFHashAddByte(&hash, _minTTL >> 16); OFHashAddByte(&hash, _minTTL >> 8); OFHashAddByte(&hash, _minTTL); OFHashFinalize(&hash); return hash; } - (OFString *)description |
︙ | ︙ | |||
1213 1214 1215 1216 1217 1218 1219 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | | | | | | | 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddByte(&hash, _priority >> 8); OFHashAddByte(&hash, _priority); OFHashAddByte(&hash, _weight >> 8); OFHashAddByte(&hash, _weight); OFHashAddHash(&hash, _target.hash); OFHashAddByte(&hash, _port >> 8); OFHashAddByte(&hash, _port); OFHashFinalize(&hash); return hash; } - (OFString *)description |
︙ | ︙ | |||
1318 1319 1320 1321 1322 1323 1324 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); | | | | | | 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddByte(&hash, _DNSClass >> 8); OFHashAddByte(&hash, _DNSClass); OFHashAddByte(&hash, _recordType >> 8); OFHashAddByte(&hash, _recordType); OFHashAddHash(&hash, _textStrings.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ |
Modified src/OFDNSResponse.h from [12d5300b31] to [229f42ebfc].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 | OF_KINDOF(OFDNSResourceRecord *)) *) *OFDNSResponseRecords; /** * @class OFDNSResponse OFDNSResponse.h ObjFW/OFDNSResponse.h * * @brief A class storing a response from @ref OFDNSResolver. */ @interface OFDNSResponse: OFObject { OFString *_domainName; OFDNSResponseRecords _answerRecords, _authorityRecords; OFDNSResponseRecords _additionalRecords; | > < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | OF_KINDOF(OFDNSResourceRecord *)) *) *OFDNSResponseRecords; /** * @class OFDNSResponse OFDNSResponse.h ObjFW/OFDNSResponse.h * * @brief A class storing a response from @ref OFDNSResolver. */ OF_SUBCLASSING_RESTRICTED @interface OFDNSResponse: OFObject { OFString *_domainName; OFDNSResponseRecords _answerRecords, _authorityRecords; OFDNSResponseRecords _additionalRecords; } /** * @brief The domain name of the response. */ @property (readonly, nonatomic) OFString *domainName; |
︙ | ︙ |
Modified src/OFData+MessagePackParsing.h from [38e581e80e] to [1a7c410992].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | } #endif @interface OFData (MessagePackParsing) /** * @brief The data interpreted as MessagePack representation and parsed as an * object. */ @property (readonly, nonatomic) id objectByParsingMessagePack; /** * @brief Parses the MessagePack representation and returns it as an object. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * @return The MessagePack representation as an object */ - (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | } #endif @interface OFData (MessagePackParsing) /** * @brief The data interpreted as MessagePack representation and parsed as an * object. * * @throw OFInvalidFormatException The MessagePack representation contained in * the data contained an invalid format * @throw OFTruncatedDataException The MessagePack representation contained in * the data is truncated * @throw OFOutOfRangeException The depth limit has been exceeded */ @property (readonly, nonatomic) id objectByParsingMessagePack; /** * @brief Parses the MessagePack representation and returns it as an object. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * @return The MessagePack representation as an object * @throw OFInvalidFormatException The MessagePack representation contained in * the data contained an invalid format * @throw OFTruncatedDataException The MessagePack representation contained in * the data is truncated * @throw OFOutOfRangeException The depth limit has been exceeded */ - (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END |
Modified src/OFData.h from [858a27b08c] to [750f7eff94].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFMessagePackRepresentation.h" /*! @file */ OF_ASSUME_NONNULL_BEGIN @class OFString; | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFMessagePackRepresentation.h" /*! @file */ OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFURI; /** * @brief Options for searching in data. * * This is a bit mask. */ typedef enum { |
︙ | ︙ | |||
163 164 165 166 167 168 169 | * @return A new autoreleased OFData */ + (instancetype)dataWithContentsOfFile: (OFString *)path; #endif /** * @brief Creates a new OFData with an item size of 1, containing the data of | | | | > > > > | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | * @return A new autoreleased OFData */ + (instancetype)dataWithContentsOfFile: (OFString *)path; #endif /** * @brief Creates a new OFData with an item size of 1, containing the data of * the specified URI. * * @param URI The URI to the contents for the OFData * @return A new autoreleased OFData */ + (instancetype)dataWithContentsOfURI: (OFURI *)URI; /** * @brief Creates a new OFData with an item size of 1, containing the data of * the hex string representation. * * @param string The hex string representation of the data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ + (instancetype)dataWithStringRepresentation: (OFString *)string; /** * @brief Creates a new OFData with an item size of 1, containing the data of * the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ + (instancetype)dataWithBase64EncodedString: (OFString *)string; /** * @brief Initializes an already allocated OFData with the specified `count` * items of size 1. * |
︙ | ︙ | |||
262 263 264 265 266 267 268 | * @return An initialized OFData */ - (instancetype)initWithContentsOfFile: (OFString *)path; #endif /** * @brief Initializes an already allocated OFData with an item size of 1, | | | | > > > > | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | * @return An initialized OFData */ - (instancetype)initWithContentsOfFile: (OFString *)path; #endif /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the specified URI. * * @param URI The URI to the contents for the OFData * @return A new autoreleased OFData */ - (instancetype)initWithContentsOfURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the hex string representation. * * @param string The hex string representation of the data * @return A new autoreleased OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ - (instancetype)initWithStringRepresentation: (OFString *)string; /** * @brief Initializes an already allocated OFData with an item size of 1, * containing the data of the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return An initialized OFData * @throw OFInvalidFormatException The specified string is not correctly * formatted */ - (instancetype)initWithBase64EncodedString: (OFString *)string; /** * @brief Compares the data to other data. * * @param data Data to compare the data to |
︙ | ︙ | |||
334 335 336 337 338 339 340 | * * @param path The path of the file to write to */ - (void)writeToFile: (OFString *)path; #endif /** | | | | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | * * @param path The path of the file to write to */ - (void)writeToFile: (OFString *)path; #endif /** * @brief Writes the OFData to the specified URI. * * @param URI The URI to write to */ - (void)writeToURI: (OFURI *)URI; @end OF_ASSUME_NONNULL_END #import "OFMutableData.h" #import "OFData+CryptographicHashing.h" #import "OFData+MessagePackParsing.h" |
Modified src/OFData.m from [b6152aa57a] to [9d8368a480].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" | | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" /* References for static linking */ void |
︙ | ︙ | |||
89 90 91 92 93 94 95 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } #endif | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } #endif + (instancetype)dataWithContentsOfURI: (OFURI *)URI { return [[[self alloc] initWithContentsOfURI: URI] autorelease]; } + (instancetype)dataWithStringRepresentation: (OFString *)string { return [[[self alloc] initWithStringRepresentation: string] autorelease]; } |
︙ | ︙ | |||
211 212 213 214 215 216 217 | @throw e; } return self; } #endif | | < | < < < < < < | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | @throw e; } return self; } #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFStream *stream = [OFURIHandler openItemAtURI: URI mode: @"r"]; size_t pageSize; unsigned char *buffer; _count = 0; _itemSize = 1; _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); |
︙ | ︙ | |||
480 481 482 483 484 485 486 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < _count * _itemSize; i++) | | | 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < _count * _itemSize; i++) OFHashAddByte(&hash, ((uint8_t *)_items)[i]); OFHashFinalize(&hash); return hash; } - (OFData *)subdataWithRange: (OFRange)range |
︙ | ︙ | |||
554 555 556 557 558 559 560 | range.location + range.length > _count) @throw [OFOutOfRangeException exception]; if (data == nil || data.itemSize != _itemSize) @throw [OFInvalidArgumentException exception]; if ((searchLength = data.count) == 0) | | | | | | | < < < < | | > | > | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | range.location + range.length > _count) @throw [OFOutOfRangeException exception]; if (data == nil || data.itemSize != _itemSize) @throw [OFInvalidArgumentException exception]; if ((searchLength = data.count) == 0) return OFMakeRange(0, 0); if (searchLength > range.length) return OFMakeRange(OFNotFound, 0); search = data.items; if (options & OFDataSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(_items + i * _itemSize, search, searchLength * _itemSize) == 0) return OFMakeRange(i, searchLength); /* No match and we're at the last item */ if (i == 0) break; } } else { for (size_t i = range.location; i <= range.length - searchLength; i++) if (memcmp(_items + i * _itemSize, search, searchLength * _itemSize) == 0) return OFMakeRange(i, searchLength); } return OFMakeRange(OFNotFound, 0); } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"w"]; @try { [file writeBuffer: _items length: _count * _itemSize]; } @finally { [file release]; } } #endif - (void)writeToURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); [[OFURIHandler openItemAtURI: URI mode: @"w"] writeData: self]; objc_autoreleasePoolPop(pool); } - (OFXMLElement *)XMLElementBySerializing { void *pool; OFXMLElement *element; if (_itemSize != 1) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: OFBase64Encode(_items, _count * _itemSize)]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFData *)messagePackRepresentation { OFMutableData *data; if (_itemSize != 1) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (_count <= UINT8_MAX) { uint8_t type = 0xC4; uint8_t tmp = (uint8_t)_count; data = [OFMutableData dataWithCapacity: _count + 2]; [data addItem: &type]; |
︙ | ︙ |
Modified src/OFDatagramSocket.h from [c9d6b20376] to [777d90d4d3].
︙ | ︙ | |||
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | OF_RESERVE_IVARS(OFDatagramSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket can send to broadcast addresses. */ @property (nonatomic) bool canSendToBroadcastAddresses; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are | > > > > | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | OF_RESERVE_IVARS(OFDatagramSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. * * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket can send to broadcast addresses. * * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canSendToBroadcastAddresses; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are |
︙ | ︙ | |||
147 148 149 150 151 152 153 154 155 156 157 158 159 160 | * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param sender A pointer to an @ref OFSocketAddress, which will be set to the * address of the sender * @return The length of the received datagram */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender; /** * @brief Asynchronously receives a datagram and stores it into the specified | > > | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param sender A pointer to an @ref OFSocketAddress, which will be set to the * address of the sender * @return The length of the received datagram * @throw OFReadFailedException Receiving failed * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender; /** * @brief Asynchronously receives a datagram and stores it into the specified |
︙ | ︙ | |||
226 227 228 229 230 231 232 233 234 235 236 237 238 239 | /** * @brief Sends the specified datagram to the specified address. * * @param buffer The buffer to send as a datagram * @param length The length of the buffer * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent */ - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. | > > | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | /** * @brief Sends the specified datagram to the specified address. * * @param buffer The buffer to send as a datagram * @param length The length of the buffer * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. |
︙ | ︙ | |||
293 294 295 296 297 298 299 300 301 302 303 304 | * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. */ - (void)close; @end OF_ASSUME_NONNULL_END | > > | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 | * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. * * @throw OFNotOpenException The socket is not open */ - (void)close; @end OF_ASSUME_NONNULL_END |
Modified src/OFDate.h from [f33ded2414] to [ba59d767f1].
︙ | ︙ | |||
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Creates a new OFDate with the specified string in the specified * format. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Returns a date in the distant future. * | > > | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Creates a new OFDate with the specified string in the specified * format. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%a, %%b, %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%z, %%, %%n and * %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return A new, autoreleased OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ + (instancetype)dateWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Returns a date in the distant future. * |
︙ | ︙ | |||
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Initializes an already allocated OFDate with the specified string in * the specified format. * * If no time zone is specified, local time is assumed. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Compares the date to another date. * * @param date The date to compare the date to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFDate *)date; /** * @brief Creates a string of the date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString */ - (OFString *)dateStringWithFormat: (OFConstantString *)format; /** * @brief Creates a string of the local date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString */ - (OFString *)localDateStringWithFormat: (OFConstantString *)format; /** * @brief Returns the earlier of the two dates. * * If the argument is `nil`, it returns the receiver. | > > > > | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format; /** * @brief Initializes an already allocated OFDate with the specified string in * the specified format. * * If no time zone is specified, local time is assumed. * * See the man page for `strftime` for information on the format. * * @warning The format is currently limited to the following format specifiers: * %%d, %%e, %%H, %%m, %%M, %%S, %%y, %%Y, %%, %%n and %%t. * * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time * @throw OFInvalidFormatException The specified format is invalid */ - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Compares the date to another date. * * @param date The date to compare the date to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFDate *)date; /** * @brief Creates a string of the date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)dateStringWithFormat: (OFConstantString *)format; /** * @brief Creates a string of the local date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString * @throw OFInvalidFormatException The specified format is invalid */ - (OFString *)localDateStringWithFormat: (OFConstantString *)format; /** * @brief Returns the earlier of the two dates. * * If the argument is `nil`, it returns the receiver. |
︙ | ︙ |
Modified src/OFDate.m from [ebc414dd12] to [692871b1cf].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" |
︙ | ︙ | |||
502 503 504 505 506 507 508 509 510 511 512 513 514 515 | @try { void *pool = objc_autoreleasePoolPush(); unsigned long long value; if (![element.name isEqual: @"OFDate"] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @throw [OFOutOfRangeException exception]; seconds = OFFromBigEndianDouble(OFRawUInt64ToDouble( | > > > > | 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | @try { void *pool = objc_autoreleasePoolPush(); unsigned long long value; if (![element.name isEqual: @"OFDate"] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; if (![[element attributeForName: @"encoding"].stringValue isEqual: @"hex"]) @throw [OFInvalidFormatException exception]; value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @throw [OFOutOfRangeException exception]; seconds = OFFromBigEndianDouble(OFRawUInt64ToDouble( |
︙ | ︙ | |||
548 549 550 551 552 553 554 | double tmp; OFHashInit(&hash); tmp = OFToLittleEndianDouble(self.timeIntervalSince1970); for (size_t i = 0; i < sizeof(double); i++) | | | 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 | double tmp; OFHashInit(&hash); tmp = OFToLittleEndianDouble(self.timeIntervalSince1970); for (size_t i = 0; i < sizeof(double); i++) OFHashAddByte(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (id)copy |
︙ | ︙ | |||
586 587 588 589 590 591 592 593 594 595 596 597 598 599 | { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" namespace: OFSerializationNS]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.timeIntervalSince1970)))]; [element retain]; objc_autoreleasePoolPop(pool); | > | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" namespace: OFSerializationNS]; [element addAttributeWithName: @"encoding" stringValue: @"hex"]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.timeIntervalSince1970)))]; [element retain]; objc_autoreleasePoolPop(pool); |
︙ | ︙ |
Modified src/OFDictionary.h from [a605581e45] to [73af2a9ef3].
︙ | ︙ | |||
89 90 91 92 93 94 95 | @property (readonly, nonatomic) OFArray OF_GENERIC(KeyType) *allKeys; /** * @brief An array of all objects. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects; | < < < < < | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | @property (readonly, nonatomic) OFArray OF_GENERIC(KeyType) *allKeys; /** * @brief An array of all objects. */ @property (readonly, nonatomic) OFArray OF_GENERIC(ObjectType) *allObjects; /** * @brief Creates a new OFDictionary. * * @return A new autoreleased OFDictionary */ + (instancetype)dictionary; |
︙ | ︙ | |||
243 244 245 246 247 248 249 | * @return The value for the given key or `nil` if the key was not found */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Sets a value for a key. * | | < > | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | * @return The value for the given key or `nil` if the key was not found */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Sets a value for a key. * * This is equivalent to OFMutableDictionary#setObject:forKey:. * * @param key The key to set * @param value The value to set the key to * @throw OFUndefinedKeyException The dictionary is immutable */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Checks whether the dictionary contains an object equal to the * specified object. * |
︙ | ︙ |
Modified src/OFDictionary.m from [a48510c034] to [9689ae0f89].
︙ | ︙ | |||
32 33 34 35 36 37 38 | #import "OFOutOfRangeException.h" #import "OFUndefinedKeyException.h" static struct { Class isa; } placeholder; | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "OFOutOfRangeException.h" #import "OFUndefinedKeyException.h" static struct { Class isa; } placeholder; static OFCharacterSet *URIQueryPartAllowedCharacterSet = nil; @interface OFDictionary () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end |
︙ | ︙ | |||
54 55 56 57 58 59 60 | OFEnumerator *_keyEnumerator; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary; @end OF_DIRECT_MEMBERS | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | OFEnumerator *_keyEnumerator; } - (instancetype)initWithDictionary: (OFDictionary *)dictionary; @end OF_DIRECT_MEMBERS @interface OFURIQueryPartAllowedCharacterSet: OFCharacterSet + (OFCharacterSet *)URIQueryPartAllowedCharacterSet; @end @implementation OFDictionaryPlaceholder - (instancetype)init { return (id)[[OFMapTableDictionary alloc] init]; } |
︙ | ︙ | |||
137 138 139 140 141 142 143 | - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end | | | | | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end @implementation OFURIQueryPartAllowedCharacterSet + (void)initialize { if (self != [OFURIQueryPartAllowedCharacterSet class]) return; URIQueryPartAllowedCharacterSet = [[OFURIQueryPartAllowedCharacterSet alloc] init]; } + (OFCharacterSet *)URIQueryPartAllowedCharacterSet { return URIQueryPartAllowedCharacterSet; } - (instancetype)autorelease { return self; } |
︙ | ︙ | |||
628 629 630 631 632 633 634 | [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } |
︙ | ︙ |
Renamed and modified src/OFEmbeddedFileURLHandler.h [b889d68d61] to src/OFEmbeddedURIHandler.h [5163464dd8].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * 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. */ | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * * 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 OFEmbeddedURIHandler: OFURIHandler @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFEmbeddedFileURLHandler.m [10ad5c2607] to src/OFEmbeddedURIHandler.m [bac2da914b].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <errno.h> #include <stdlib.h> #include <string.h> | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include "config.h" #include <errno.h> #include <stdlib.h> #include <string.h> #import "OFEmbeddedURIHandler.h" #import "OFMemoryStream.h" #import "OFURI.h" #import "OFInvalidArgumentException.h" #import "OFOpenItemFailedException.h" #ifdef OF_HAVE_THREADS # import "OFOnce.h" # import "OFPlainMutex.h" |
︙ | ︙ | |||
67 68 69 70 71 72 73 | numEmbeddedFiles++; #ifdef OF_HAVE_THREADS OFEnsure(OFPlainMutexUnlock(&mutex) == 0); #endif } | | | | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | numEmbeddedFiles++; #ifdef OF_HAVE_THREADS OFEnsure(OFPlainMutexUnlock(&mutex) == 0); #endif } @implementation OFEmbeddedURIHandler - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { const char *path; if (![URI.scheme isEqual: @"embedded"] || URI.host.length > 0 || URI.port != nil || URI.user != nil || URI.password != nil || URI.query != nil || URI.fragment != nil) @throw [OFInvalidArgumentException exception]; if (![mode isEqual: @"r"]) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: mode errNo: EROFS]; if ((path = URI.path.UTF8String) == NULL) { @throw [OFInvalidArgumentException exception]; } #ifdef OF_HAVE_THREADS OFEnsure(OFPlainMutexLock(&mutex) == 0); @try { #endif |
︙ | ︙ | |||
106 107 108 109 110 111 112 | } #ifdef OF_HAVE_THREADS } @finally { OFEnsure(OFPlainMutexUnlock(&mutex) == 0); } #endif | | | 106 107 108 109 110 111 112 113 114 115 116 117 | } #ifdef OF_HAVE_THREADS } @finally { OFEnsure(OFPlainMutexUnlock(&mutex) == 0); } #endif @throw [OFOpenItemFailedException exceptionWithURI: URI mode: mode errNo: ENOENT]; } @end |
Modified src/OFEnumerator.h from [514f228b0c] to [bebf66139d].
︙ | ︙ | |||
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | * doing a fast enumeration. * * @param state Context information for the enumeration * @param objects A pointer to an array where to put the objects * @param count The number of objects that can be stored at objects * @return The number of objects returned in objects or 0 when the enumeration * finished. */ - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id __unsafe_unretained _Nonnull *_Nonnull) objects count: (int)count; @end /** * @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A class which provides methods to enumerate through collections. */ @interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration> #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif | > > < < < < > > | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | * doing a fast enumeration. * * @param state Context information for the enumeration * @param objects A pointer to an array where to put the objects * @param count The number of objects that can be stored at objects * @return The number of objects returned in objects or 0 when the enumeration * finished. * @throw OFEnumerationMutationException The object was mutated during * enumeration */ - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id __unsafe_unretained _Nonnull *_Nonnull) objects count: (int)count; @end /** * @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A class which provides methods to enumerate through collections. */ @interface OFEnumerator OF_GENERIC(ObjectType): OFObject <OFFastEnumeration> #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif /** * @brief Returns the next object or `nil` if there is none left. * * @return The next object or `nil` if there is none left * @throw OFEnumerationMutationException The object was mutated during * enumeration */ - (nullable ObjectType)nextObject; /** * @brief Returns an array of all remaining objects in the collection. * * @return An array of all remaining objects in the collection. |
︙ | ︙ |
Modified src/OFEpollKernelEventObserver.m from [ddd2075d1e] to [a510ac5746].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #import "OFEpollKernelEventObserver.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #import "OFEpollKernelEventObserver.h" #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #define eventListSize 64 static const OFMapTableFunctions mapFunctions = { NULL }; @implementation OFEpollKernelEventObserver - (instancetype)init |
︙ | ︙ | |||
100 101 102 103 104 105 106 | memset(&event, 0, sizeof(event)); event.events = (int)events | addEvents; event.data.ptr = object; if (epoll_ctl(_epfd, (events == 0 ? EPOLL_CTL_ADD : EPOLL_CTL_MOD), fd, &event) == -1) | > | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | memset(&event, 0, sizeof(event)); event.events = (int)events | addEvents; event.data.ptr = object; if (epoll_ctl(_epfd, (events == 0 ? EPOLL_CTL_ADD : EPOLL_CTL_MOD), fd, &event) == -1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents setObject: (void *)(events | addEvents) forKey: (void *)((intptr_t)fd + 1)]; } - (void)of_removeObject: (id)object fileDescriptor: (int)fd |
︙ | ︙ | |||
125 126 127 128 129 130 131 | if (epoll_ctl(_epfd, EPOLL_CTL_DEL, fd, NULL) == -1) /* * When an async connect fails, it seems the socket is * automatically removed from epoll, meaning ENOENT is * returned when we try to remove it after it failed. */ if (errno != ENOENT) | | | | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | if (epoll_ctl(_epfd, EPOLL_CTL_DEL, fd, NULL) == -1) /* * When an async connect fails, it seems the socket is * automatically removed from epoll, meaning ENOENT is * returned when we try to remove it after it failed. */ if (errno != ENOENT) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents removeObjectForKey: (void *)((intptr_t)fd + 1)]; } else { struct epoll_event event; memset(&event, 0, sizeof(event)); event.events = (int)events; event.data.ptr = object; if (epoll_ctl(_epfd, EPOLL_CTL_MOD, fd, &event) == -1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [_FDToEvents setObject: (void *)events forKey: (void *)((intptr_t)fd + 1)]; } } |
︙ | ︙ | |||
196 197 198 199 200 201 202 | if ([self of_processReadBuffers]) return; events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) | > | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | if ([self of_processReadBuffers]) return; events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].events & EPOLLIN) { void *pool = objc_autoreleasePoolPush(); if (eventList[i].data.ptr == nullObject) { char buffer; |
︙ | ︙ |
Modified src/OFFile.h from [70f5f785c7] to [b56cdf66da].
︙ | ︙ | |||
23 24 25 26 27 28 29 | #else typedef struct _OFFileHandle *OFFileHandle; static const OFFileHandle OFInvalidFileHandle = NULL; #endif OF_ASSUME_NONNULL_BEGIN | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #else typedef struct _OFFileHandle *OFFileHandle; static const OFFileHandle OFInvalidFileHandle = NULL; #endif OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFFile OFFile.h ObjFW/OFFile.h * * @brief A class which provides methods to read and write files. */ OF_SUBCLASSING_RESTRICTED |
︙ | ︙ | |||
58 59 60 61 62 63 64 65 66 67 68 69 70 71 | * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile */ + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Creates a new OFFile with the specified native file handle. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this | > | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile * @throw OFOpenItemFailedException Opening the file failed */ + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Creates a new OFFile with the specified native file handle. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this |
︙ | ︙ | |||
92 93 94 95 96 97 98 99 100 101 102 103 104 105 | * `w` | read-write, create, truncate * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Initializes an already allocated OFFile. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this | > | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | * `w` | read-write, create, truncate * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile * @throw OFOpenItemFailedException Opening the file failed */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Initializes an already allocated OFFile. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this |
︙ | ︙ |
Modified src/OFFile.m from [6bda5c55f7] to [57c941bba1].
︙ | ︙ | |||
29 30 31 32 33 34 35 | # include <sys/stat.h> #endif #import "OFFile.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # include <sys/stat.h> #endif #import "OFFile.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURI.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" |
︙ | ︙ | |||
446 447 448 449 450 451 452 | bytesWritten: 0 errNo: errno]; #endif return (size_t)bytesWritten; } | | > | > > > > > > > > > > > > > > > > > > | | | | | | | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | bytesWritten: 0 errNo: errno]; #endif return (size_t)bytesWritten; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OFStreamOffset ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_AMIGAOS int translatedWhence; switch (whence) { case OFSeekSet: translatedWhence = SEEK_SET; break; case OFSeekCurrent: translatedWhence = SEEK_CUR; break; case OFSeekEnd: translatedWhence = SEEK_END; break; default: @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; } # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, translatedWhence); # elif defined(HAVE_LSEEK64) ret = lseek64(_handle, offset, translatedWhence); # else ret = lseek(_handle, offset, translatedWhence); # endif if (ret == -1) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: errno]; #else LONG translatedWhence; switch (whence) { case OFSeekSet: translatedWhence = OFFSET_BEGINNING; break; case OFSeekCurrent: translatedWhence = OFFSET_CURRENT; break; case OFSeekEnd: translatedWhence = OFFSET_END; break; default: @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; |
︙ | ︙ |
Modified src/OFFileManager.h from [e259c02d73] to [1cfc8cfdf6].
︙ | ︙ | |||
35 36 37 38 39 40 41 | # endif #endif @class OFArray OF_GENERIC(ObjectType); @class OFConstantString; @class OFDate; @class OFString; | | | | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | # endif #endif @class OFArray OF_GENERIC(ObjectType); @class OFConstantString; @class OFDate; @class OFString; @class OFURI; /** * @brief A key for a file attribute in the file attributes dictionary. * * Possible keys for file URIs are: * * * @ref OFFileSize * * @ref OFFileType * * @ref OFFilePOSIXPermissions * * @ref OFFileOwnerAccountID * * @ref OFFileGroupOwnerAccountID * * @ref OFFileOwnerAccountName * * @ref OFFileGroupOwnerAccountName * * @ref OFFileLastAccessDate * * @ref OFFileModificationDate * * @ref OFFileStatusChangeDate * * @ref OFFileCreationDate * * @ref OFFileSymbolicLinkDestination * * Other URI schemes might not have all keys and might have keys not listed. */ typedef OFConstantString *OFFileAttributeKey; /** * @brief The type of a file. * * Possibles values for file URIs are: * * * @ref OFFileTypeRegular * * @ref OFFileTypeDirectory * * @ref OFFileTypeSymbolicLink * * @ref OFFileTypeFIFO * * @ref OFFileTypeCharacterSpecial * * @ref OFFileTypeBlockSpecial * * @ref OFFileTypeSocket * * @ref OFFileTypeUnknown * * Other URI schemes might not have all types and might have types not listed. */ typedef OFConstantString *OFFileAttributeType; /** * @brief A dictionary mapping keys of type @ref OFFileAttributeKey to their * attribute values. */ |
︙ | ︙ | |||
255 256 257 258 259 260 261 262 263 264 265 | #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFFileManager *defaultManager; #endif #ifdef OF_HAVE_FILES /** * @brief The path of the current working directory. */ @property (readonly, nonatomic) OFString *currentDirectoryPath; /** | > > | > > | > > | | | > > > > | > > > > > | | | > > > > > > > | | | | > > | | | | > > | > > > | | > > > | | | > > > > | > > | | | > > > > | > > | > > | > > > | | > > > > > | > > > > > > > > | | > > > > > > > > > > | > | | | > > > | > > > | | | | > > > > > | > > > | | | > > | | | | | | | | | | | | | | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFFileManager *defaultManager; #endif #ifdef OF_HAVE_FILES /** * @brief The path of the current working directory. * * @throw OFGetCurrentDirectoryFailedException Couldn't get current directory */ @property (readonly, nonatomic) OFString *currentDirectoryPath; /** * @brief The URI of the current working directory. * * @throw OFGetCurrentDirectoryFailedException Couldn't get current directory */ @property (readonly, nonatomic) OFURI *currentDirectoryURI; #endif /** * @brief Returns the default file manager. */ + (OFFileManager *)defaultManager; #ifdef OF_HAVE_FILES /** * @brief Returns the attributes for the item at the specified path. * * @param path The path to return the attributes for * @return A dictionary of attributes for the specified path, with the keys of * type @ref OFFileAttributeKey * @throw OFGetItemAttributesFailedException Failed to get the attributes of * the item */ - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path; #endif /** * @brief Returns the attributes for the item at the specified URI. * * @param URI The URI to return the attributes for * @return A dictionary of attributes for the specified URI, with the keys of * type @ref OFFileAttributeKey * @throw OFGetItemAttributesFailedException Failed to get the attributes of * the item * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Sets the attributes for the item at the specified path. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified path * @param path The path of the item to set the attributes for * @throw OFSetItemAttributesFailedException Failed to set the attributes of * the item * @throw OFNotImplementedException Setting one or more of the specified * attributes is not implemented for the * specified item */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path; #endif /** * @brief Sets the attributes for the item at the specified URI. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified URI * @param URI The URI of the item to set the attributes for * @throw OFSetItemAttributesFailedException Failed to set the attributes of * the item * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme * @throw OFNotImplementedException Setting one or more of the specified * attributes is not implemented for the * specified item */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Checks whether a file exists at the specified path. * * @param path The path to check * @return A boolean whether there is a file at the specified path */ - (bool)fileExistsAtPath: (OFString *)path; #endif /** * @brief Checks whether a file exists at the specified URI. * * @param URI The URI to check * @return A boolean whether there is a file at the specified URI * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (bool)fileExistsAtURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Checks whether a directory exists at the specified path. * * @param path The path to check * @return A boolean whether there is a directory at the specified path */ - (bool)directoryExistsAtPath: (OFString *)path; #endif /** * @brief Checks whether a directory exists at the specified URI. * * @param URI The URI to check * @return A boolean whether there is a directory at the specified URI * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (bool)directoryExistsAtURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Creates a directory at the specified path. * * @param path The path of the directory to create * @throw OFCreateDirectoryFailedException Creating the directory failed */ - (void)createDirectoryAtPath: (OFString *)path; /** * @brief Creates a directory at the specified path. * * @param path The path of the directory to create * @param createParents Whether to create the parents of the directory * @throw OFCreateDirectoryFailedException Creating the directory or one of its * parents failed */ - (void)createDirectoryAtPath: (OFString *)path createParents: (bool)createParents; #endif /** * @brief Creates a directory at the specified URI. * * @param URI The URI of the directory to create * @throw OFCreateDirectoryFailedException Creating the directory failed * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (void)createDirectoryAtURI: (OFURI *)URI; /** * @brief Creates a directory at the specified URI. * * @param URI The URI of the directory to create * @param createParents Whether to create the parents of the directory * @throw OFCreateDirectoryFailedException Creating the directory or one of its * parents failed * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (void)createDirectoryAtURI: (OFURI *)URI createParents: (bool)createParents; #ifdef OF_HAVE_FILES /** * @brief Returns an array with the items in the specified directory. * * @note `.` and `..` are not part of the returned array. * * @param path The path to the directory whose items should be returned * @return An array of OFString with the items in the specified directory * @throw OFOpenItemFailedException Opening the directory failed * @throw OFReadFailedException Reading from the directory failed */ - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path; #endif /** * @brief Returns an array with the URIs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param URI The URI to the directory whose items should be returned * @return An array with the URIs of the items in the specified directory * @throw OFOpenItemFailedException Opening the directory failed * @throw OFReadFailedException Reading from the directory failed * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Returns an array with all subpaths of the specified directory. * * @note `.` and `..` (of the directory itself or any subdirectory) are not * part of the returned array. * * @param path The path to the directory whose subpaths should be returned * @return An array of OFString with the subpaths of the specified directory */ - (OFArray OF_GENERIC(OFString *) *)subpathsOfDirectoryAtPath: (OFString *)path; /** * @brief Changes the current working directory. * * @param path The new directory to change to * @throw OFChangeCurrentDirectoryFailedException Changing the current working * directory failed */ - (void)changeCurrentDirectoryPath: (OFString *)path; /** * @brief Changes the current working directory. * * @param URI The new directory to change to * @throw OFChangeCurrentDirectoryFailedException Changing the current working * directory failed */ - (void)changeCurrentDirectoryURI: (OFURI *)URI; /** * @brief Copies a file, directory or symbolic link (if supported by the OS). * * The destination path must be a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination path * @throw OFCopyItemFailedException Copying failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed */ - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Copies a file, directory or symbolic link (if supported by the OS). * * The destination URI must have a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination URI * @throw OFCopyItemFailedException Copying failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed * @throw OFUnsupportedProtocolException No handler is registered for either of * the URI's scheme */ - (void)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination; #ifdef OF_HAVE_FILES /** * @brief Moves an item. * * The destination path must be a full path, which means it must include the * name of the item. * * If the destination is on a different logical device, the source will be * copied to the destination using @ref copyItemAtPath:toPath: and the source * removed using @ref removeItemAtPath:. * * @param source The item to rename * @param destination The new name for the item * @throw OFMoveItemFailedException Moving failed * @throw OFCopyItemFailedException Copying (to move between different devices) * failed * @throw OFRemoveItemFailedException Removing the source after copying to the * destination (to move between different * devices) failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed */ - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Moves an item. * * The destination URI must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, the source will be copied to the destination using * @ref copyItemAtURI:toURI: and the source removed using @ref removeItemAtURI:. * * @param source The item to rename * @param destination The new name for the item * @throw OFMoveItemFailedException Moving failed * @throw OFCopyItemFailedException Copying (to move between different devices) * failed * @throw OFRemoveItemFailedException Removing the source after copying to the * destination (to move between different * devices) failed * @throw OFCreateDirectoryFailedException Creating a destination directory * failed * @throw OFUnsupportedProtocolException No handler is registered for either of * the URI's scheme */ - (void)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination; #ifdef OF_HAVE_FILES /** * @brief Removes the item at the specified path. * * If the item at the specified path is a directory, it is removed recursively. * * @param path The path to the item which should be removed * @throw OFRemoveItemFailedException Removing the item failed */ - (void)removeItemAtPath: (OFString *)path; #endif /** * @brief Removes the item at the specified URI. * * If the item at the specified URI is a directory, it is removed recursively. * * @param URI The URI to the item which should be removed * @throw OFRemoveItemFailedException Removing the item failed * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (void)removeItemAtURI: (OFURI *)URI; #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS /** * @brief Creates a hard link for the specified item. * * The destination path must be a full path, which means it must include the * name of the item. * * This method is not available on some systems. * * @param source The path to the item for which a link should be created * @param destination The path to the item which should link to the source * @throw OFLinkItemFailedException Linking the item failed * @throw OFNotImplementedException Hardlinks are not implemented for the * specified URI */ - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Creates a hard link for the specified item. * * The destination URI must have a full path, which means it must include the * name of the item. * * This method is not available for all URIs. * * @param source The URI to the item for which a link should be created * @param destination The URI to the item which should link to the source * @throw OFLinkItemFailedException Linking the item failed * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme * @throw OFNotImplementedException Hardlinks are not implemented for the * specified URI */ - (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination; #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS /** * @brief Creates a symbolic link for an item. * * The destination path must be a full path, which means it must include the * name of the item. * * This method is not available on some systems. * * @note On Windows, this requires at least Windows Vista and administrator * privileges! * * @param path The path to the item which should symbolically link to the target * @param target The target of the symbolic link * @throw OFCreateSymbolicLinkFailedException Creating the symbolic link failed * @throw OFNotImplementedException Symbolic links are not implemented for the * specified URI */ - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target; #endif /** * @brief Creates a symbolic link for an item. * * The destination URI must have a full path, which means it must include the * name of the item. * * This method is not available for all URIs. * * @note On Windows, this requires at least Windows Vista and administrator * privileges! * * @param URI The URI to the item which should symbolically link to the target * @param target The target of the symbolic link * @throw OFUnsupportedProtocolException No handler is registered for the URI's * scheme */ - (void)createSymbolicLinkAtURI: (OFURI *)URI withDestinationPath: (OFString *)target; @end @interface OFDictionary (FileAttributes) /** * @brief The @ref OFFileSize key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long long fileSize; /** * @brief The @ref OFFileType key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFFileAttributeType fileType; /** * @brief The @ref OFFilePOSIXPermissions key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long filePOSIXPermissions; /** * @brief The @ref OFFileOwnerAccountID key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long fileOwnerAccountID; /** * @brief The @ref OFFileGroupOwnerAccountID key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID; /** * @brief The @ref OFFileOwnerAccountName key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileOwnerAccountName; /** * @brief The @ref OFFileGroupOwnerAccountName key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName; /** * @brief The @ref OFFileLastAccessDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileLastAccessDate; /** * @brief The @ref OFFileModificationDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileModificationDate; /** * @brief The @ref OFFileStatusChangeDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileStatusChangeDate; /** * @brief The @ref OFFileCreationDate key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFDate *fileCreationDate; /** * @brief The @ref OFFileSymbolicLinkDestination key from the dictionary. * * @throw OFUndefinedKeyException The key is missing */ @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination; @end OF_ASSUME_NONNULL_END |
Modified src/OFFileManager.m from [8b48822fc3] to [f5483886a4].
︙ | ︙ | |||
35 36 37 38 39 40 41 | #endif #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" | | | | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #endif #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFChangeCurrentDirectoryFailedException.h" #import "OFCopyItemFailedException.h" #import "OFCreateDirectoryFailedException.h" #import "OFGetCurrentDirectoryFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRemoveItemFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFUndefinedKeyException.h" #import "OFUnsupportedProtocolException.h" #ifdef OF_WINDOWS # include <windows.h> # include <direct.h> # include <ntdef.h> |
︙ | ︙ | |||
167 168 169 170 171 172 173 | return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; # else char buffer[PATH_MAX]; if ((getcwd(buffer, PATH_MAX)) == NULL) | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; # else char buffer[PATH_MAX]; if ((getcwd(buffer, PATH_MAX)) == NULL) @throw [OFGetCurrentDirectoryFailedException exceptionWithErrNo: errno]; # ifdef OF_DJGPP /* * For some reason, getcwd() returns forward slashes on DJGPP, even * though the native format is to use backwards slashes. */ for (char *tmp = buffer; *tmp != '\0'; tmp++) if (*tmp == '/') *tmp = '\\'; # endif return [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; # endif } - (OFURI *)currentDirectoryURI { void *pool = objc_autoreleasePoolPush(); OFURI *ret; ret = [OFURI fileURIWithPath: self.currentDirectoryPath]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; return [URIHandler attributesOfItemAtURI: URI]; } #ifdef OF_HAVE_FILES - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFileAttributes ret; ret = [self attributesOfItemAtURI: [OFURI fileURIWithPath: path]]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; [URIHandler setAttributes: attributes ofItemAtURI: URI]; } #ifdef OF_HAVE_FILES - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self setAttributes: attributes ofItemAtURI: [OFURI fileURIWithPath: path]]; objc_autoreleasePoolPop(pool); } #endif - (bool)fileExistsAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; return [URIHandler fileExistsAtURI: URI]; } #ifdef OF_HAVE_FILES - (bool)fileExistsAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); bool ret; ret = [self fileExistsAtURI: [OFURI fileURIWithPath: path]]; objc_autoreleasePoolPop(pool); return ret; } #endif - (bool)directoryExistsAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; return [URIHandler directoryExistsAtURI: URI]; } #ifdef OF_HAVE_FILES - (bool)directoryExistsAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); bool ret; ret = [self directoryExistsAtURI: [OFURI fileURIWithPath: path]]; objc_autoreleasePoolPop(pool); return ret; } #endif - (void)createDirectoryAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; [URIHandler createDirectoryAtURI: URI]; } - (void)createDirectoryAtURI: (OFURI *)URI createParents: (bool)createParents { void *pool = objc_autoreleasePoolPush(); OFMutableURI *mutableURI; OFArray OF_GENERIC(OFString *) *components; OFMutableArray OF_GENERIC(OFURI *) *componentURIs; size_t componentURIsCount; ssize_t i; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (!createParents) { [self createDirectoryAtURI: URI]; return; } /* * Try blindly creating the directory first. * * The reason for this is that we might be sandboxed, so attempting to * create any of the parent directories will fail, while creating the * directory itself will work. */ if ([self directoryExistsAtURI: URI]) return; @try { [self createDirectoryAtURI: URI]; return; } @catch (OFCreateDirectoryFailedException *e) { /* * If we didn't fail because any of the parents is missing, * there is no point in trying to create the parents. */ if (e.errNo != ENOENT) @throw e; } /* * Because we might be sandboxed (and for remote URIs don't even know * anything at all), we generate the URI for every component. We then * iterate them in reverse order until we find the first existing * directory, and then create subdirectories from there. */ mutableURI = [[URI mutableCopy] autorelease]; mutableURI.percentEncodedPath = @"/"; components = URI.pathComponents; componentURIs = [OFMutableArray arrayWithCapacity: components.count]; for (OFString *component in components) { [mutableURI appendPathComponent: component]; if (![mutableURI.percentEncodedPath isEqual: @"/"]) [componentURIs addObject: [[mutableURI copy] autorelease]]; } componentURIsCount = componentURIs.count; for (i = componentURIsCount - 1; i > 0; i--) { if ([self directoryExistsAtURI: [componentURIs objectAtIndex: i]]) break; } if (++i == (ssize_t)componentURIsCount) { /* * The URI exists, even though before we made sure it did not. * That means it was created in the meantime by something else, * so we're done here. */ objc_autoreleasePoolPop(pool); return; } for (; i < (ssize_t)componentURIsCount; i++) [self createDirectoryAtURI: [componentURIs objectAtIndex: i]]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES - (void)createDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self createDirectoryAtURI: [OFURI fileURIWithPath: path]]; objc_autoreleasePoolPop(pool); } - (void)createDirectoryAtPath: (OFString *)path createParents: (bool)createParents { void *pool = objc_autoreleasePoolPush(); [self createDirectoryAtURI: [OFURI fileURIWithPath: path] createParents: createParents]; objc_autoreleasePoolPop(pool); } #endif - (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; return [URIHandler contentsOfDirectoryAtURI: URI]; } #ifdef OF_HAVE_FILES - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFURI *) *URIs; OFMutableArray OF_GENERIC(OFString *) *ret; URIs = [self contentsOfDirectoryAtURI: [OFURI fileURIWithPath: path]]; ret = [OFMutableArray arrayWithCapacity: URIs.count]; for (OFURI *URI in URIs) [ret addObject: URI.lastPathComponent]; [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; |
︙ | ︙ | |||
511 512 513 514 515 516 517 | errNo = ENOENT; break; default: errNo = 0; break; } | | | 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | errNo = ENOENT; break; default: errNo = 0; break; } @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errNo]; } oldLock = CurrentDir(lock); if (!dirChanged) |
︙ | ︙ | |||
536 537 538 539 540 541 542 | status = _wchdir(path.UTF16String); else # endif status = chdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | status = _wchdir(path.UTF16String); else # endif status = chdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFChangeCurrentDirectoryFailedException exceptionWithPath: path errNo: errno]; # endif } - (void)changeCurrentDirectoryURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); [self changeCurrentDirectoryPath: URI.fileSystemRepresentation]; objc_autoreleasePoolPop(pool); } - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self copyItemAtURI: [OFURI fileURIWithPath: source] toURI: [OFURI fileURIWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination { void *pool; OFURIHandler *URIHandler; OFFileAttributes attributes; OFFileAttributeType type; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((URIHandler = [OFURIHandler handlerForURI: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: source]; if ([URIHandler copyItemAtURI: source toURI: destination]) return; if ([self fileExistsAtURI: destination]) @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: EEXIST]; @try { attributes = [self attributesOfItemAtURI: source]; } @catch (OFGetItemAttributesFailedException *e) { @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: e.errNo]; } type = attributes.fileType; if ([type isEqual: OFFileTypeDirectory]) { OFArray OF_GENERIC(OFURI *) *contents; @try { [self createDirectoryAtURI: destination]; @try { OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes ofItemAtURI: destination]; } } @catch (OFNotImplementedException *e) { } contents = [self contentsOfDirectoryAtURI: source]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: [e errNo]]; @throw e; } for (OFURI *item in contents) { void *pool2 = objc_autoreleasePoolPush(); OFURI *destinationURI = [destination URIByAppendingPathComponent: item.lastPathComponent]; [self copyItemAtURI: item toURI: destinationURI]; objc_autoreleasePoolPop(pool2); } } else if ([type isEqual: OFFileTypeRegular]) { size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; buffer = OFAllocMemory(1, pageSize); @try { sourceStream = [OFURIHandler openItemAtURI: source mode: @"r"]; destinationStream = [OFURIHandler openItemAtURI: destination mode: @"w"]; while (!sourceStream.atEndOfStream) { size_t length; length = [sourceStream readIntoBuffer: buffer length: pageSize]; |
︙ | ︙ | |||
685 686 687 688 689 690 691 | if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes ofItemAtURI: destination]; } } @catch (OFNotImplementedException *e) { } } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: [e errNo]]; @throw e; } @finally { [sourceStream close]; [destinationStream close]; OFFreeMemory(buffer); } } else if ([type isEqual: OFFileTypeSymbolicLink]) { @try { OFString *linkDestination = attributes.fileSymbolicLinkDestination; [self createSymbolicLinkAtURI: destination withDestinationPath: linkDestination]; } @catch (id e) { /* * Only convert exceptions to OFCopyItemFailedException * that have an errNo property. This covers all I/O * related exceptions from the operations used to copy * an item, all others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: [e errNo]]; @throw e; } } else @throw [OFCopyItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self moveItemAtURI: [OFURI fileURIWithPath: source] toURI: [OFURI fileURIWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination { void *pool; OFURIHandler *URIHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((URIHandler = [OFURIHandler handlerForURI: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: source]; @try { if ([URIHandler moveItemAtURI: source toURI: destination]) return; } @catch (OFMoveItemFailedException *e) { if (e.errNo != EXDEV) @throw e; } if ([self fileExistsAtURI: destination]) @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: EEXIST]; @try { [self copyItemAtURI: source toURI: destination]; } @catch (OFCopyItemFailedException *e) { [self removeItemAtURI: destination]; @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: e.errNo]; } @try { [self removeItemAtURI: source]; } @catch (OFRemoveItemFailedException *e) { @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: e.errNo]; } objc_autoreleasePoolPop(pool); } - (void)removeItemAtURI: (OFURI *)URI { OFURIHandler *URIHandler; if (URI == nil) @throw [OFInvalidArgumentException exception]; if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; [URIHandler removeItemAtURI: URI]; } #ifdef OF_HAVE_FILES - (void)removeItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self removeItemAtURI: [OFURI fileURIWithPath: path]]; objc_autoreleasePoolPop(pool); } #endif - (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination { void *pool = objc_autoreleasePoolPush(); OFURIHandler *URIHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![destination.scheme isEqual: source.scheme]) @throw [OFInvalidArgumentException exception]; URIHandler = [OFURIHandler handlerForURI: source]; if (URIHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: source]; [URIHandler linkItemAtURI: source toURI: destination]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self linkItemAtURI: [OFURI fileURIWithPath: source] toURI: [OFURI fileURIWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)createSymbolicLinkAtURI: (OFURI *)URI withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); OFURIHandler *URIHandler; if (URI == nil || target == nil) @throw [OFInvalidArgumentException exception]; URIHandler = [OFURIHandler handlerForURI: URI]; if (URIHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; [URIHandler createSymbolicLinkAtURI: URI withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); [self createSymbolicLinkAtURI: [OFURI fileURIWithPath: path] withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #endif @end @implementation OFDefaultFileManager |
︙ | ︙ |
Renamed and modified src/OFFileURLHandler.h [bc6fd1985b] to src/OFFileURIHandler.h [24ec18a27d].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * 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. */ | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * 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 OFFileURIHandler: OFURIHandler + (bool)of_directoryExistsAtPath: (OFString *)path OF_DIRECT; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFFileURLHandler.m [50a5ea9a56] to src/OFFileURIHandler.m [85f56ad9ce].
︙ | ︙ | |||
37 38 39 40 41 42 43 | #ifdef HAVE_PWD_H # include <pwd.h> #endif #ifdef HAVE_GRP_H # include <grp.h> #endif | | | > | < | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | #ifdef HAVE_PWD_H # include <pwd.h> #endif #ifdef HAVE_GRP_H # include <grp.h> #endif #import "OFFileURIHandler.h" #import "OFArray.h" #import "OFDate.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFNumber.h" #import "OFSystemInfo.h" #import "OFURI.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFCreateDirectoryFailedException.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFLinkItemFailedException.h" #import "OFMoveItemFailedException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFRemoveItemFailedException.h" #import "OFSetItemAttributesFailedException.h" #ifdef OF_WINDOWS # include <windows.h> # include <direct.h> # include <ntdef.h> # include <wchar.h> #endif #ifdef OF_AMIGAOS # include <proto/exec.h> # include <proto/dos.h> # include <proto/locale.h> # ifdef OF_AMIGAOS4 # define DeleteFile(path) Delete(path) # endif #endif #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) typedef struct { OFStreamOffset st_size; unsigned int st_mode; OFTimeInterval st_atime, st_mtime, st_ctime; # ifdef OF_WINDOWS # define HAVE_STRUCT_STAT_ST_BIRTHTIME OFTimeInterval st_birthtime; DWORD fileAttributes; # endif |
︙ | ︙ | |||
138 139 140 141 142 143 144 | filetimeToTimeInterval(const FILETIME *filetime) { return (double)((int64_t)filetime->dwHighDateTime << 32 | filetime->dwLowDateTime) / 10000000.0 - 11644473600.0; } static int | | | | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | filetimeToTimeInterval(const FILETIME *filetime) { return (double)((int64_t)filetime->dwHighDateTime << 32 | filetime->dwLowDateTime) / 10000000.0 - 11644473600.0; } static int lastError(void) { switch (GetLastError()) { case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: case ERROR_NO_MORE_FILES: return ENOENT; case ERROR_ACCESS_DENIED: return EACCES; case ERROR_DIRECTORY: return ENOTDIR; case ERROR_NOT_READY: return EBUSY; default: return EIO; } } #endif #ifdef OF_AMIGAOS static int lastError(void) { switch (IoErr()) { case ERROR_DELETE_PROTECTED: case ERROR_READ_PROTECTED: case ERROR_WRITE_PROTECTED: return EACCES; case ERROR_DISK_NOT_VALIDATED: |
︙ | ︙ | |||
207 208 209 210 211 212 213 | GetFileExInfoStandard, &data); else success = GetFileAttributesExA( [path cStringWithEncoding: [OFLocale encoding]], GetFileExInfoStandard, &data); if (!success) | | | | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | GetFileExInfoStandard, &data); else success = GetFileAttributesExA( [path cStringWithEncoding: [OFLocale encoding]], GetFileExInfoStandard, &data); if (!success) return lastError(); buffer->st_size = (uint64_t)data.nFileSizeHigh << 32 | data.nFileSizeLow; if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) buffer->st_mode = S_IFDIR; else if (data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) { /* * No need to use A functions in this branch: This is only * available on NTFS (and hence Windows NT) anyway. */ WIN32_FIND_DATAW findData; HANDLE findHandle; if ((findHandle = FindFirstFileW(path.UTF16String, &findData)) == INVALID_HANDLE_VALUE) return lastError(); @try { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) /* Race? Indicate to try again. */ return EAGAIN; |
︙ | ︙ | |||
264 265 266 267 268 269 270 | # endif OFTimeInterval timeInterval; struct Locale *locale; struct DateStamp *date; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) | | | | 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | # endif OFTimeInterval timeInterval; struct Locale *locale; struct DateStamp *date; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) return lastError(); # if defined(OF_MORPHOS) if (!Examine64(lock, &fib, TAG_DONE)) { # elif defined(OF_AMIGAOS4) if ((ed = ExamineObjectTags(EX_FileLockInput, lock, TAG_END)) == NULL) { # else if (!Examine(lock, &fib)) { # endif int error = lastError(); UnLock(lock); return error; } UnLock(lock); # if defined(OF_MORPHOS) |
︙ | ︙ | |||
453 454 455 456 457 458 459 | # endif #endif } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS static void setSymbolicLinkDestinationAttribute(OFMutableFileAttributes attributes, | | | | | | | | | | | | | | | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | # endif #endif } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS static void setSymbolicLinkDestinationAttribute(OFMutableFileAttributes attributes, OFURI *URI) { OFString *path = URI.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; char destinationC[PATH_MAX]; ssize_t length; OFString *destination; length = readlink([path cStringWithEncoding: encoding], destinationC, PATH_MAX); if (length < 0) @throw [OFGetItemAttributesFailedException exceptionWithURI: URI errNo: errno]; destination = [OFString stringWithCString: destinationC encoding: encoding length: length]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # else HANDLE handle; OFString *destination; if (createSymbolicLinkWFuncPtr == NULL) return; if ((handle = CreateFileW(path.UTF16String, 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) @throw [OFGetItemAttributesFailedException exceptionWithURI: URI errNo: lastError()]; @try { union { char bytes[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER data; } buffer; DWORD size; wchar_t *tmp; if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer.bytes, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &size, NULL)) @throw [OFGetItemAttributesFailedException exceptionWithURI: URI errNo: lastError()]; if (buffer.data.ReparseTag != IO_REPARSE_TAG_SYMLINK) @throw [OFGetItemAttributesFailedException exceptionWithURI: URI errNo: lastError()]; # define slrb buffer.data.SymbolicLinkReparseBuffer tmp = slrb.PathBuffer + (slrb.SubstituteNameOffset / sizeof(wchar_t)); destination = [OFString stringWithUTF16String: tmp |
︙ | ︙ | |||
531 532 533 534 535 536 537 | } @finally { CloseHandle(handle); } # endif } #endif | | | | 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | } @finally { CloseHandle(handle); } # endif } #endif @implementation OFFileURIHandler + (void)initialize { #ifdef OF_WINDOWS HMODULE module; #endif if (self != [OFFileURIHandler class]) return; #if defined(OF_FILE_MANAGER_SUPPORTS_OWNER) && defined(OF_HAVE_THREADS) passwdMutex = [[OFMutex alloc] init]; atexit(releasePasswdMutex); #endif #if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS) |
︙ | ︙ | |||
583 584 585 586 587 588 589 | if (statWrapper(path, &s) != 0) return false; return S_ISDIR(s.st_mode); } | | | | | | | | | | | | | | | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | if (statWrapper(path, &s) != 0) return false; return S_ISDIR(s.st_mode); } - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFFile *file = [[OFFile alloc] initWithPath: URI.fileSystemRepresentation mode: mode]; objc_autoreleasePoolPop(pool); return [file autorelease]; } - (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI { OFMutableFileAttributes ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![[URI scheme] isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URI.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFGetItemAttributesFailedException exceptionWithURI: URI errNo: error]; if (s.st_size < 0) @throw [OFOutOfRangeException exception]; [ret setObject: [NSNumber numberWithUnsignedLongLong: s.st_size] forKey: OFFileSize]; setTypeAttribute(ret, &s); [ret setObject: [NSNumber numberWithUnsignedLong: s.st_mode] forKey: OFFilePOSIXPermissions]; setOwnerAndGroupAttributes(ret, &s); setDateAttributes(ret, &s); #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS if (S_ISLNK(s.st_mode)) setSymbolicLinkDestinationAttribute(ret, URI); #endif objc_autoreleasePoolPop(pool); return ret; } - (void)of_setLastAccessDate: (OFDate *)lastAccessDate andModificationDate: (OFDate *)modificationDate ofItemAtURI: (OFURI *)URI attributes: (OFFileAttributes)attributes OF_DIRECT { OFString *path = URI.fileSystemRepresentation; OFFileAttributeKey attributeKey = (modificationDate != nil ? OFFileModificationDate : OFFileLastAccessDate); if (lastAccessDate == nil) lastAccessDate = modificationDate; if (modificationDate == nil) modificationDate = lastAccessDate; #if defined(OF_WINDOWS) if (_wutime64FuncPtr != NULL) { struct __utimbuf64 times = { .actime = (__time64_t)lastAccessDate.timeIntervalSince1970, .modtime = (__time64_t)modificationDate.timeIntervalSince1970 }; if (_wutime64FuncPtr([path UTF16String], ×) != 0) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; } else { struct _utimbuf times = { .actime = (time_t)lastAccessDate.timeIntervalSince1970, .modtime = (time_t)modificationDate.timeIntervalSince1970 }; int status; if ([OFSystemInfo isWindowsNT]) status = _wutime([path UTF16String], ×); else status = _utime( [path cStringWithEncoding: [OFLocale encoding]], ×); if (status != 0) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; } #elif defined(OF_AMIGAOS) /* AmigaOS does not support access time. */ OFTimeInterval modificationTime = |
︙ | ︙ | |||
724 725 726 727 728 729 730 | if (!SetDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # else if (!SetFileDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # endif @throw [OFSetItemAttributesFailedException | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | if (!SetDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # else if (!SetFileDate([path cStringWithEncoding: [OFLocale encoding]], &date) != 0) # endif @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: lastError()]; #else OFTimeInterval lastAccessTime = lastAccessDate.timeIntervalSince1970; OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct timeval times[2] = { { .tv_sec = (time_t)lastAccessTime, .tv_usec = (int)((lastAccessTime - times[0].tv_sec) * 1000000) }, { .tv_sec = (time_t)modificationTime, .tv_usec = (int)((modificationTime - times[1].tv_sec) * 1000000) }, }; if (utimes([path cStringWithEncoding: [OFLocale encoding]], times) != 0) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; #endif } - (void)of_setPOSIXPermissions: (OFNumber *)permissions ofItemAtURI: (OFURI *)URI attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS mode_t mode = (mode_t)permissions.unsignedLongValue; OFString *path = URI.fileSystemRepresentation; int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wchmod(path.UTF16String, mode); else # endif status = chmod( [path cStringWithEncoding: [OFLocale encoding]], mode); if (status != 0) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: OFFilePOSIXPermissions errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)of_setOwnerAccountName: (OFString *)owner andGroupOwnerAccountName: (OFString *)group ofItemAtURI: (OFURI *)URI attributeKey: (OFFileAttributeKey)attributeKey attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER OFString *path = URI.fileSystemRepresentation; uid_t uid = -1; gid_t gid = -1; OFStringEncoding encoding; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exception]; encoding = [OFLocale encoding]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif if (owner != nil) { struct passwd *passwd; if ((passwd = getpwnam([owner cStringWithEncoding: encoding])) == NULL) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; uid = passwd->pw_uid; } if (group != nil) { struct group *group_; if ((group_ = getgrnam([group cStringWithEncoding: encoding])) == NULL) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; gid = group_->gr_gid; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } # endif if (chown([path cStringWithEncoding: encoding], uid, gid) != 0) @throw [OFSetItemAttributesFailedException exceptionWithURI: URI attributes: attributes failedAttribute: attributeKey errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); OFEnumerator OF_GENERIC(OFFileAttributeKey) *keyEnumerator; OFEnumerator *objectEnumerator; OFFileAttributeKey key; id object; OFDate *lastAccessDate, *modificationDate; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; keyEnumerator = [attributes keyEnumerator]; objectEnumerator = [attributes objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { if ([key isEqual: OFFileModificationDate] || [key isEqual: OFFileLastAccessDate]) continue; else if ([key isEqual: OFFilePOSIXPermissions]) [self of_setPOSIXPermissions: object ofItemAtURI: URI attributes: attributes]; else if ([key isEqual: OFFileOwnerAccountName]) [self of_setOwnerAccountName: object andGroupOwnerAccountName: nil ofItemAtURI: URI attributeKey: key attributes: attributes]; else if ([key isEqual: OFFileGroupOwnerAccountName]) [self of_setOwnerAccountName: nil andGroupOwnerAccountName: object ofItemAtURI: URI attributeKey: key attributes: attributes]; else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } lastAccessDate = [attributes objectForKey: OFFileLastAccessDate]; modificationDate = [attributes objectForKey: OFFileModificationDate]; if (lastAccessDate != nil || modificationDate != nil) [self of_setLastAccessDate: lastAccessDate andModificationDate: modificationDate ofItemAtURI: URI attributes: attributes]; objc_autoreleasePoolPop(pool); } - (bool)fileExistsAtURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; if (statWrapper(URI.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISREG(s.st_mode); objc_autoreleasePoolPop(pool); return ret; } - (bool)directoryExistsAtURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; if (statWrapper(URI.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISDIR(s.st_mode); objc_autoreleasePoolPop(pool); return ret; } - (void)createDirectoryAtURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); OFString *path; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URI.fileSystemRepresentation; #if defined(OF_WINDOWS) int status; if ([OFSystemInfo isWindowsNT]) status = _wmkdir(path.UTF16String); else status = _mkdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFCreateDirectoryFailedException exceptionWithURI: URI errNo: errno]; #elif defined(OF_AMIGAOS) BPTR lock; if ((lock = CreateDir( [path cStringWithEncoding: [OFLocale encoding]])) == 0) @throw [OFCreateDirectoryFailedException exceptionWithURI: URI errNo: lastError()]; UnLock(lock); #else if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0) @throw [OFCreateDirectoryFailedException exceptionWithURI: URI errNo: errno]; #endif objc_autoreleasePoolPop(pool); } - (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI { OFMutableArray *URIs = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *path; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URI.fileSystemRepresentation; #if defined(OF_WINDOWS) HANDLE handle; path = [path stringByAppendingString: @"\\*"]; if ([OFSystemInfo isWindowsNT]) { WIN32_FIND_DATAW fd; if ((handle = FindFirstFileW(path.UTF16String, &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: lastError()]; @try { do { OFString *file; if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue; file = [[OFString alloc] initWithUTF16String: fd.cFileName]; @try { [URIs addObject: [URI URIByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileW(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { FindClose(handle); } } else { OFStringEncoding encoding = [OFLocale encoding]; WIN32_FIND_DATA fd; if ((handle = FindFirstFileA( [path cStringWithEncoding: encoding], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: lastError()]; @try { do { OFString *file; if (strcmp(fd.cFileName, ".") == 0 || strcmp(fd.cFileName, "..") == 0) continue; file = [[OFString alloc] initWithCString: fd.cFileName encoding: encoding]; @try { [URIs addObject: [URI URIByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileA(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { FindClose(handle); } } #elif defined(OF_AMIGAOS) OFStringEncoding encoding = [OFLocale encoding]; BPTR lock; if ((lock = Lock([path cStringWithEncoding: encoding], SHARED_LOCK)) == 0) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: lastError()]; @try { # ifdef OF_AMIGAOS4 struct ExamineData *ed; APTR context; if ((context = ObtainDirContextTags(EX_FileLockInput, lock, EX_DoCurrentDir, TRUE, EX_DataFields, EXF_NAME, TAG_END)) == NULL) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: lastError()]; @try { while ((ed = ExamineDir(context)) != NULL) { OFString *file = [[OFString alloc] initWithCString: ed->Name encoding: encoding]; @try { [URIs addObject: [URI URIByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { ReleaseDirContext(context); } # else struct FileInfoBlock fib; if (!Examine(lock, &fib)) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: lastError()]; while (ExNext(lock, &fib)) { OFString *file = [[OFString alloc] initWithCString: fib.fib_FileName encoding: encoding]; @try { [URIs addObject: [URI URIByAppendingPathComponent: file]]; } @finally { [file release]; } } # endif if (IoErr() != ERROR_NO_MORE_ENTRIES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: lastError()]; } @finally { UnLock(lock); } #else OFStringEncoding encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithURI: URI mode: nil errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) @try { [readdirMutex lock]; } @catch (id e) { |
︙ | ︙ | |||
1217 1218 1219 1220 1221 1222 1223 | if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 | if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { [URIs addObject: [URI URIByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { closedir(dir); # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) [readdirMutex unlock]; # endif } #endif [URIs makeImmutable]; objc_autoreleasePoolPop(pool); return URIs; } - (void)removeItemAtURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (URI == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URI.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRemoveItemFailedException exceptionWithURI: URI errNo: error]; if (S_ISDIR(s.st_mode)) { OFArray OF_GENERIC(OFURI *) *contents; @try { contents = [self contentsOfDirectoryAtURI: URI]; } @catch (id e) { /* * Only convert exceptions to * OFRemoveItemFailedException that have an errNo * property. This covers all I/O related exceptions * from the operations used to remove an item, all * others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFRemoveItemFailedException exceptionWithURI: URI errNo: [e errNo]]; @throw e; } for (OFURI *item in contents) { void *pool2 = objc_autoreleasePoolPush(); [self removeItemAtURI: item]; objc_autoreleasePoolPop(pool2); } #ifndef OF_AMIGAOS int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wrmdir(path.UTF16String); else # endif status = rmdir( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFRemoveItemFailedException exceptionWithURI: URI errNo: errno]; } else { int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wunlink(path.UTF16String); else # endif status = unlink( [path cStringWithEncoding: [OFLocale encoding]]); if (status != 0) @throw [OFRemoveItemFailedException exceptionWithURI: URI errNo: errno]; #endif } #ifdef OF_AMIGAOS if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]])) @throw [OFRemoveItemFailedException exceptionWithURI: URI errNo: lastError()]; #endif objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination { void *pool = objc_autoreleasePoolPush(); OFString *sourcePath, *destinationPath; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; sourcePath = source.fileSystemRepresentation; destinationPath = destination.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (link([sourcePath cStringWithEncoding: encoding], [destinationPath cStringWithEncoding: encoding]) != 0) @throw [OFLinkItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: errno]; # else if (createHardLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createHardLinkWFuncPtr(destinationPath.UTF16String, sourcePath.UTF16String, NULL)) @throw [OFLinkItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtURI: (OFURI *)URI withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); OFString *path; if (URI == nil || target == nil) @throw [OFInvalidArgumentException exception]; if (![URI.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URI.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (symlink([target cStringWithEncoding: encoding], [path cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithURI: URI target: target errNo: errno]; # else if (createSymbolicLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createSymbolicLinkWFuncPtr(path.UTF16String, target.UTF16String, 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithURI: URI target: target errNo: lastError()]; # endif objc_autoreleasePoolPop(pool); } #endif - (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination { void *pool; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) return false; if ([self fileExistsAtURI: destination]) @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: EEXIST]; pool = objc_autoreleasePoolPush(); #ifdef OF_AMIGAOS OFStringEncoding encoding = [OFLocale encoding]; if (!Rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding])) @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: lastError()]; #else int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wrename(source.fileSystemRepresentation.UTF16String, destination.fileSystemRepresentation.UTF16String); |
︙ | ︙ | |||
1460 1461 1462 1463 1464 1465 1466 | cStringWithEncoding: encoding]); # ifdef OF_WINDOWS } # endif if (status != 0) @throw [OFMoveItemFailedException | | | | 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 | cStringWithEncoding: encoding]); # ifdef OF_WINDOWS } # endif if (status != 0) @throw [OFMoveItemFailedException exceptionWithSourceURI: source destinationURI: destination errNo: errno]; #endif objc_autoreleasePoolPop(pool); return true; } @end |
Modified src/OFHMAC.h from [618167fc85] to [2d8e8879fb].
︙ | ︙ | |||
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | @property (readonly, nonatomic) bool allowsSwappableMemory; /** * @brief A buffer containing the HMAC. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief The size of the digest. */ | > > | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | @property (readonly, nonatomic) bool allowsSwappableMemory; /** * @brief A buffer containing the HMAC. * * The size of the buffer depends on the hash used. The buffer is part of the * receiver's memory pool. * * @throw OFHashNotCalculatedException The HMAC hasn't been calculated yet */ @property (readonly, nonatomic) const unsigned char *digest OF_RETURNS_INNER_POINTER; /** * @brief The size of the digest. */ |
︙ | ︙ | |||
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | - (void)setKey: (const void *)key length: (size_t)length; /** * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the HMAC. */ - (void)calculate; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can | > > > | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | - (void)setKey: (const void *)key length: (size_t)length; /** * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer * @throw OFHashAlreadyCalculatedException The HMAC has already been calculated */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Performs the final calculation of the HMAC. * * @throw OFHashAlreadyCalculatedException The HMAC has already been calculated */ - (void)calculate; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can |
︙ | ︙ |
Modified src/OFHTTPClient.h from [4532ba7b26] to [d5da950339].
︙ | ︙ | |||
24 25 26 27 28 29 30 | @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFStream; @class OFTCPSocket; @class OFTLSStream; | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFHTTPClient; @class OFHTTPRequest; @class OFHTTPResponse; @class OFStream; @class OFTCPSocket; @class OFTLSStream; @class OFURI; /** * @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A delegate for OFHTTPClient. */ @protocol OFHTTPClientDelegate <OFObject> |
︙ | ︙ | |||
115 116 117 118 119 120 121 | * to detect a redirect. * * This callback will only be called if the OFHTTPClient will follow a * redirect. If the maximum number of redirects has been reached already, this * callback will not be called. * * @param client The OFHTTPClient which wants to follow a redirect | | | | | | | | | | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | * to detect a redirect. * * This callback will only be called if the OFHTTPClient will follow a * redirect. If the maximum number of redirects has been reached already, this * callback will not be called. * * @param client The OFHTTPClient which wants to follow a redirect * @param URI The URI to which it will follow a redirect * @param statusCode The status code for the redirection * @param request The request for which the OFHTTPClient wants to redirect. * You are allowed to change the request's headers from this * callback and they will be used when following the redirect * (e.g. to set the cookies for the new URI), however, keep in * mind that this will change the request you originally passed. * @param response The response indicating the redirect * @return A boolean whether the OFHTTPClient should follow the redirect */ - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToURI: (OFURI *)URI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response; @end /** * @class OFHTTPClient OFHTTPClient.h ObjFW/OFHTTPClient.h * * @brief A class for performing HTTP requests. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPClient: OFObject { #ifdef OF_HTTP_CLIENT_M @public #endif OFObject <OFHTTPClientDelegate> *_Nullable _delegate; bool _allowsInsecureRedirects, _inProgress; OFStream *_Nullable _stream; OFURI *_Nullable _lastURI; bool _lastWasHEAD; OFHTTPResponse *_Nullable _lastResponse; } /** * @brief The delegate of the HTTP request. */ |
︙ | ︙ | |||
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @return The OFHTTPResponse for the request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request; /** * @brief Synchronously performs the specified HTTP request. * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse * @return The OFHTTPResponse for the request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform */ - (void)asyncPerformRequest: (OFHTTPRequest *)request; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse */ - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Closes connections that are still open due to keep-alive. */ - (void)close; @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > > | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @return The OFHTTPResponse for the request * @throw OFHTTPRequestFailedException The HTTP request failed * @throw OFInvalidServerResponseException The server sent an invalid response * @throw OFUnsupportedVersionException The server responded in an unsupported * version * @throw OFAlreadyConnectedException The client is already performing a request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request; /** * @brief Synchronously performs the specified HTTP request. * * @note You must not change the delegate while a synchronous request is * running! If you want to change the delegate during the request, * perform an asynchronous request instead! * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse * @return The OFHTTPResponse for the request * @throw OFHTTPRequestFailedException The HTTP request failed * @throw OFInvalidServerResponseException The server sent an invalid response * @throw OFUnsupportedVersionException The server responded in an unsupported * version * @throw OFAlreadyConnectedException The client is already performing a request */ - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform * @throw OFAlreadyConnectedException The client is already performing a request */ - (void)asyncPerformRequest: (OFHTTPRequest *)request; /** * @brief Asynchronously performs the specified HTTP request. * * @param request The request to perform * @param redirects The maximum number of redirects after which no further * attempt is done to follow the redirect, but instead the * redirect is treated as an OFHTTPResponse * @throw OFAlreadyConnectedException The client is already performing a request */ - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects; /** * @brief Closes connections that are still open due to keep-alive. */ - (void)close; @end OF_ASSUME_NONNULL_END |
Modified src/OFHTTPClient.m from [74f8b0c30d] to [fbd23d3190].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * 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. */ | | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | * * 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. */ #define OF_HTTP_CLIENT_M #include "config.h" #include <errno.h> #include <string.h> #import "OFHTTPClient.h" #import "OFData.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFKernelEventObserver.h" #import "OFNumber.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" #import "OFURI.h" #import "OFAlreadyConnectedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" |
︙ | ︙ | |||
113 114 115 116 117 118 119 | @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); OFHTTPRequestMethod method = request.method; | | | | | | | | | | > | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); OFHTTPRequestMethod method = request.method; OFURI *URI = request.URI; OFString *path; OFString *user = URI.user, *password = URI.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; bool hasContentLength, chunked; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; if (URI.path != nil) path = URI.percentEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: @"%s %@", OFHTTPRequestMethodName(method), path]; if (URI.query != nil) { [requestString appendString: @"?"]; [requestString appendString: URI.percentEncodedQuery]; } [requestString appendString: @" HTTP/"]; [requestString appendString: request.protocolVersionString]; [requestString appendString: @"\r\n"]; headers = [[request.headers mutableCopy] autorelease]; if (headers == nil) headers = [OFMutableDictionary dictionary]; if ([headers objectForKey: @"Host"] == nil) { OFNumber *port = URI.port; if (port != nil) { OFString *host = [OFString stringWithFormat: @"%@:%@", URI.percentEncodedHost, port]; [headers setObject: host forKey: @"Host"]; } else [headers setObject: URI.percentEncodedHost forKey: @"Host"]; } if ((user.length > 0 || password.length > 0) && [headers objectForKey: @"Authorization"] == nil) { OFMutableData *authorizationData = [OFMutableData data]; OFString *authorization; |
︙ | ︙ | |||
294 295 296 297 298 299 300 | didPerformRequest: _request response: nil exception: exception]; } - (void)createResponseWithStreamOrThrow: (OFStream *)stream { | | | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | didPerformRequest: _request response: nil exception: exception]; } - (void)createResponseWithStreamOrThrow: (OFStream *)stream { OFURI *URI = _request.URI; OFHTTPClientResponse *response; OFString *connectionHeader; bool keepAlive; OFString *location; id exception; response = [[[OFHTTPClientResponse alloc] initWithStream: stream] |
︙ | ︙ | |||
325 326 327 328 329 330 331 | keepAlive = false; } if (keepAlive) { response.of_keepAlive = true; _client->_stream = [stream retain]; | | | | | < | | | | | | > | | | | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | keepAlive = false; } if (keepAlive) { response.of_keepAlive = true; _client->_stream = [stream retain]; _client->_lastURI = [URI copy]; _client->_lastWasHEAD = (_request.method == OFHTTPRequestMethodHead); _client->_lastResponse = [response retain]; } if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && (location = [_serverHeaders objectForKey: @"Location"]) != nil) { bool follow = true; OFURI *newURI; OFString *newURIScheme; newURI = [OFURI URIWithString: location relativeToURI: URI]; newURIScheme = newURI.scheme; if ([newURIScheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [newURIScheme caseInsensitiveCompare: @"https"] != OFOrderedSame) follow = false; if (!_client->_allowsInsecureRedirects && [URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame && [newURIScheme caseInsensitiveCompare: @"http"] == OFOrderedSame) follow = false; if (follow && [_client->_delegate respondsToSelector: @selector(client:shouldFollowRedirectToURI:statusCode: request:response:)]) follow = [_client->_delegate client: _client shouldFollowRedirectToURI: newURI statusCode: _status request: _request response: response]; else if (follow) follow = defaultShouldFollow(_request.method, _status); if (follow) { OFDictionary OF_GENERIC(OFString *, OFString *) *headers = _request.headers; OFHTTPRequest *newRequest = [[_request copy] autorelease]; OFMutableDictionary *newHeaders = [[headers mutableCopy] autorelease]; if (![newURI.host isEqual: URI.host]) [newHeaders removeObjectForKey: @"Host"]; /* * 303 means the request should be converted to a GET * request before redirection. This also means stripping * the entity of the request. */ |
︙ | ︙ | |||
399 400 401 402 403 404 405 | [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; newRequest.method = OFHTTPRequestMethodGet; } | | | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; newRequest.method = OFHTTPRequestMethodGet; } newRequest.URI = newURI; newRequest.headers = newHeaders; _client->_inProgress = false; [_client asyncPerformRequest: newRequest redirects: _redirects - 1]; return; |
︙ | ︙ | |||
453 454 455 456 457 458 459 | if (line == nil) { [self closeAndReconnect]; return false; } if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') | | | | | | | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | if (line == nil) { [self closeAndReconnect]; return false; } if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') @throw [OFInvalidServerResponseException exception]; _version = [[line substringWithRange: OFMakeRange(5, 3)] copy]; if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"]) @throw [OFUnsupportedVersionException exceptionWithVersion: _version]; status = [line substringWithRange: OFMakeRange(9, 3)].longLongValue; if (status < 0 || status > 599) @throw [OFInvalidServerResponseException exception]; _status = (short)status; return true; } - (bool)handleServerHeader: (OFString *)line stream: (OFStream *)stream { OFString *key, *value, *old; const char *lineC, *tmp; char *keyC; if (line == nil) @throw [OFInvalidServerResponseException exception]; if (line.length == 0) { [_serverHeaders makeImmutable]; if ([_client->_delegate respondsToSelector: @selector(client: didReceiveHeaders:statusCode:request:)]) [_client->_delegate client: _client |
︙ | ︙ | |||
501 502 503 504 505 506 507 | return false; } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) | | | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | return false; } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerResponseException exception]; keyC = OFAllocMemory(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { |
︙ | ︙ | |||
540 541 542 543 544 545 546 | exception: (id)exception { bool ret; if (exception != nil) { if ([exception isKindOfClass: [OFInvalidEncodingException class]]) | | > | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 | exception: (id)exception { bool ret; if (exception != nil) { if ([exception isKindOfClass: [OFInvalidEncodingException class]]) exception = [OFInvalidServerResponseException exception]; [self raiseException: exception]; return false; } @try { if (_firstLine) { |
︙ | ︙ | |||
642 643 644 645 646 647 648 | if ([_client->_delegate respondsToSelector: @selector(client:didCreateTCPSocket:request:)]) [_client->_delegate client: _client didCreateTCPSocket: sock request: _request]; | | | | | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | if ([_client->_delegate respondsToSelector: @selector(client:didCreateTCPSocket:request:)]) [_client->_delegate client: _client didCreateTCPSocket: sock request: _request]; if ([_request.URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) { OFTLSStream *stream; @try { stream = [OFTLSStream streamWithStream: sock]; } @catch (OFNotImplementedException *e) { [self raiseException: [OFUnsupportedProtocolException exceptionWithURI: _request.URI]]; return; } if ([_client->_delegate respondsToSelector: @selector(client:didCreateTLSStream:request:)]) [_client->_delegate client: _client didCreateTLSStream: stream request: _request]; stream.delegate = self; [stream asyncPerformClientHandshakeWithHost: _request.URI.host]; } else { sock.delegate = self; [self performSelector: @selector(handleStream:) withObject: sock afterDelay: 0]; } } |
︙ | ︙ | |||
686 687 688 689 690 691 692 | [self performSelector: @selector(handleStream:) withObject: stream afterDelay: 0]; } - (void)start { | | | | | | | | | | | | | | | | 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 | [self performSelector: @selector(handleStream:) withObject: stream afterDelay: 0]; } - (void)start { OFURI *URI = _request.URI; OFStream *stream; /* Can we reuse the last socket? */ if (_client->_stream != nil && !_client->_stream.atEndOfStream && [_client->_lastURI.scheme isEqual: URI.scheme] && [_client->_lastURI.host isEqual: URI.host] && (_client->_lastURI.port == URI.port || [_client->_lastURI.port isEqual: URI.port]) && (_client->_lastWasHEAD || _client->_lastResponse.atEndOfStream)) { /* * Set _stream to nil, so that in case of an error it won't be * reused. If everything is successful, we set _stream again * at the end. */ stream = [_client->_stream autorelease]; _client->_stream = nil; [_client->_lastURI release]; _client->_lastURI = nil; [_client->_lastResponse release]; _client->_lastResponse = nil; stream.delegate = self; [self performSelector: @selector(handleStream:) withObject: stream afterDelay: 0]; } else [self closeAndReconnect]; } - (void)closeAndReconnect { @try { OFURI *URI = _request.URI; OFTCPSocket *sock; uint16_t port; OFNumber *URIPort; [_client close]; sock = [OFTCPSocket socket]; if ([URI.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) port = 443; else port = 80; URIPort = URI.port; if (URIPort != nil) port = URIPort.unsignedShortValue; sock.delegate = self; [sock asyncConnectToHost: URI.host port: port]; } @catch (id e) { [self raiseException: e]; } } @end @implementation OFHTTPClientRequestBodyStream |
︙ | ︙ | |||
897 898 899 900 901 902 903 | _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; contentLength = [headers objectForKey: @"Content-Length"]; if (contentLength != nil) { if (_chunked || contentLength.length == 0) | | | | 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; contentLength = [headers objectForKey: @"Content-Length"]; if (contentLength != nil) { if (_chunked || contentLength.length == 0) @throw [OFInvalidServerResponseException exception]; _hasContentLength = true; @try { unsigned long long toRead = contentLength.unsignedLongLongValue; if (toRead > LLONG_MAX) @throw [OFOutOfRangeException exception]; _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerResponseException exception]; } } } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_stream == nil) |
︙ | ︙ | |||
956 957 958 959 960 961 962 | if (_toRead == -2) { char tmp[2]; switch ([_stream readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') | | | | | 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 | if (_toRead == -2) { char tmp[2]; switch ([_stream readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') @throw [OFInvalidServerResponseException exception]; case 1: _toRead++; if (tmp[0] != '\r') @throw [OFInvalidServerResponseException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead == -1) { char tmp; if ([_stream readIntoBuffer: &tmp length: 1] == 1) { _toRead++; if (tmp != '\n') @throw [OFInvalidServerResponseException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; |
︙ | ︙ | |||
1002 1003 1004 1005 1006 1007 1008 | void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; @try { line = [_stream tryReadLine]; } @catch (OFInvalidEncodingException *e) { | | | | | 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; @try { line = [_stream tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerResponseException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the stream is * at end of stream. */ if (_stream.atEndOfStream && pos == OFNotFound) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidServerResponseException exception]; } @try { unsigned long long toRead = [line unsignedLongLongValueWithBase: 16]; if (toRead > LLONG_MAX) @throw [OFOutOfRangeException exception]; _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerResponseException exception]; } if (_toRead == 0) { _setAtEndOfStream = true; _toRead = -2; } |
︙ | ︙ | |||
1196 1197 1198 1199 1200 1201 1202 | @selector(client:didReceiveHeaders:statusCode:request:)]) [_delegate client: client didReceiveHeaders: headers statusCode: statusCode request: request]; } | | | | | | | | | | | | | | 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | @selector(client:didReceiveHeaders:statusCode:request:)]) [_delegate client: client didReceiveHeaders: headers statusCode: statusCode request: request]; } - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToURI: (OFURI *)URI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if ([_delegate respondsToSelector: @selector( client:shouldFollowRedirectToURI:statusCode:request:response:)]) return [_delegate client: client shouldFollowRedirectToURI: URI statusCode: statusCode request: request response: response]; else return defaultShouldFollow(request.method, statusCode); } @end @implementation OFHTTPClient @synthesize delegate = _delegate; |
︙ | ︙ | |||
1261 1262 1263 1264 1265 1266 1267 | [self asyncPerformRequest: request redirects: defaultRedirects]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); | | | | < | | | 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 | [self asyncPerformRequest: request redirects: defaultRedirects]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); OFURI *URI = request.URI; OFString *scheme = URI.scheme; if ([scheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; if (_inProgress) @throw [OFAlreadyConnectedException exception]; _inProgress = true; [[[[OFHTTPClientRequestHandler alloc] initWithClient: self request: request redirects: redirects] autorelease] start]; objc_autoreleasePoolPop(pool); } - (void)close { [_stream release]; _stream = nil; [_lastURI release]; _lastURI = nil; [_lastResponse release]; _lastResponse = nil; } @end |
Modified src/OFHTTPCookie.h from [c915720e1d] to [ff53970b1e].
︙ | ︙ | |||
18 19 20 21 22 23 24 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); | | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFURI; /** * @class OFHTTPCookie OFHTTPCookie.h ObjFW/OFHTTPCookie.h * * @brief A class for storing and manipulating HTTP cookies. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPCookie: OFObject <OFCopying> { OFString *_name, *_value, *_domain, *_path; OFDate *_Nullable _expires; bool _secure, _HTTPOnly; OFMutableArray OF_GENERIC(OFString *) *_extensions; } /** * @brief The name of the cookie. */ @property (copy, nonatomic) OFString *name; |
︙ | ︙ | |||
76 77 78 79 80 81 82 | /** * @brief An array of other attributes. */ @property (readonly, nonatomic) OFMutableArray OF_GENERIC(OFString *) *extensions; /** | | | > > | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | /** * @brief An array of other attributes. */ @property (readonly, nonatomic) OFMutableArray OF_GENERIC(OFString *) *extensions; /** * @brief Parses the specified response header fields for the specified URI and * returns an array of cookies. * * @param headerFields The response header fields to parse * @param URI The URI for the response header fields to parse * @return An array of cookies * @throw OFInvalidFormatException The specified response header has an invalid * format */ + (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesWithResponseHeaderFields: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forURI: (OFURI *)URI; /** * @brief Returns the request header fields for the specified cookies. * * @param cookies The cookies to return the request header fields for * @return The request header fields for the specified cookies */ |
︙ | ︙ |
Modified src/OFHTTPCookie.m from [30659cca3c] to [a7d6a07918].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFHTTPCookie.h" #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #import "OFHTTPCookie.h" #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFURI.h" #import "OFInvalidFormatException.h" static void handleAttribute(OFHTTPCookie *cookie, OFString *name, OFString *value) { OFString *lowercaseName = name.lowercaseString; |
︙ | ︙ | |||
58 59 60 61 62 63 64 | @implementation OFHTTPCookie @synthesize name = _name, value = _value, domain = _domain, path = _path; @synthesize expires = _expires, secure = _secure, HTTPOnly = _HTTPOnly; @synthesize extensions = _extensions; + (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesWithResponseHeaderFields: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields | | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | @implementation OFHTTPCookie @synthesize name = _name, value = _value, domain = _domain, path = _path; @synthesize expires = _expires, secure = _secure, HTTPOnly = _HTTPOnly; @synthesize extensions = _extensions; + (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesWithResponseHeaderFields: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forURI: (OFURI *)URI { OFMutableArray OF_GENERIC(OFHTTPCookie *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *string = [headerFields objectForKey: @"Set-Cookie"]; OFString *domain = URI.host; const OFUnichar *characters = string.characters; size_t length = string.length, last = 0; enum { statePreName, stateName, stateExpectValue, stateValue, |
︙ | ︙ | |||
91 92 93 94 95 96 97 | last = i; i--; } break; case stateName: if (characters[i] == '=') { name = [string substringWithRange: | | | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | last = i; i--; } break; case stateName: if (characters[i] == '=') { name = [string substringWithRange: OFMakeRange(last, i - last)]; state = stateExpectValue; } break; case stateExpectValue: if (characters[i] == '"') { state = stateQuotedValue; last = i + 1; } else { state = stateValue; last = i; } i--; break; case stateValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFMakeRange(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateQuotedValue: if (characters[i] == '"') { value = [string substringWithRange: OFMakeRange(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = statePostQuotedValue; } |
︙ | ︙ | |||
151 152 153 154 155 156 157 | last = i; i--; } break; case stateAttrName: if (characters[i] == '=') { name = [string substringWithRange: | | | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | last = i; i--; } break; case stateAttrName: if (characters[i] == '=') { name = [string substringWithRange: OFMakeRange(last, i - last)]; state = stateAttrValue; last = i + 1; } else if (characters[i] == ';' || characters[i] == ',') { name = [string substringWithRange: OFMakeRange(last, i - last)]; handleAttribute(ret.lastObject, name, nil); state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateAttrValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFMakeRange(last, i - last)]; /* * Expires often contains a comma, even though * the comma is used as a separator for * concatenating headers as per RFC 2616, * meaning RFC 6265 contradicts RFC 2616. * Solve this by special casing this. |
︙ | ︙ | |||
211 212 213 214 215 216 217 | break; case stateName: case stateQuotedValue: @throw [OFInvalidFormatException exception]; break; case stateValue: value = [string substringWithRange: | | | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | break; case stateName: case stateQuotedValue: @throw [OFInvalidFormatException exception]; break; case stateValue: value = [string substringWithRange: OFMakeRange(last, length - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; break; /* We end up here if the cookie is just foo= */ case stateExpectValue: [ret addObject: [OFHTTPCookie cookieWithName: name value: @"" domain: domain]]; break; case stateAttrName: if (last != length) { name = [string substringWithRange: OFMakeRange(last, length - last)]; handleAttribute(ret.lastObject, name, nil); } break; case stateAttrValue: value = [string substringWithRange: OFMakeRange(last, length - last)]; handleAttribute(ret.lastObject, name, value); break; } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
367 368 369 370 371 372 373 | OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _value.hash); OFHashAddHash(&hash, _domain.hash); OFHashAddHash(&hash, _path.hash); OFHashAddHash(&hash, _expires.hash); | | | | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _value.hash); OFHashAddHash(&hash, _domain.hash); OFHashAddHash(&hash, _path.hash); OFHashAddHash(&hash, _expires.hash); OFHashAddByte(&hash, _secure); OFHashAddByte(&hash, _HTTPOnly); OFHashAddHash(&hash, _extensions.hash); OFHashFinalize(&hash); return hash; } - (id)copy |
︙ | ︙ |
Modified src/OFHTTPCookieManager.h from [776c67cc36] to [3cc0432376].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFHTTPCookie; @class OFMutableArray OF_GENERIC(ObjectType); | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFHTTPCookie; @class OFMutableArray OF_GENERIC(ObjectType); @class OFURI; /** * @class OFHTTPCookieManager OFHTTPCookieManager.h ObjFW/OFHTTPCookieManager.h * * @brief A class for managing cookies for multiple domains. */ OF_SUBCLASSING_RESTRICTED |
︙ | ︙ | |||
42 43 44 45 46 47 48 | * @brief Create a new cookie manager. * * @return A new, autoreleased OFHTTPCookieManager */ + (instancetype)manager; /** | | | | | | | | | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | * @brief Create a new cookie manager. * * @return A new, autoreleased OFHTTPCookieManager */ + (instancetype)manager; /** * @brief Adds the specified cookie for the specified URI. * * @warning This modifies the cookie (e.g. it sets the domain if it is unset)! * If you do not want this, pass a copy! * * @param cookie The cookie to add to the manager * @param URI The URI for which the cookie should be added */ - (void)addCookie: (OFHTTPCookie *)cookie forURI: (OFURI *)URI; /** * @brief Adds the specified cookies for the specified URI. * * @warning This modifies the cookies (e.g. it sets the domain if it is unset)! * If you do not want this, pass copies! * * @param cookies An array of cookies to add to the manager * @param URI The URI for which the cookies should be added */ - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies forURI: (OFURI *)URI; /** * @brief Returns the cookies for the specified URI. * * @param URI The URI for which the cookies should be returned * @return The cookies for the specified URI */ - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURI: (OFURI *)URI; /** * @brief Purges all expired cookies. */ - (void)purgeExpiredCookies; @end OF_ASSUME_NONNULL_END |
Modified src/OFHTTPCookieManager.m from [ab6e7fb16a] to [1dd74fe07e].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFHTTPCookieManager.h" #import "OFArray.h" #import "OFDate.h" #import "OFHTTPCookie.h" | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #import "OFHTTPCookieManager.h" #import "OFArray.h" #import "OFDate.h" #import "OFHTTPCookie.h" #import "OFURI.h" @implementation OFHTTPCookieManager + (instancetype)manager { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
49 50 51 52 53 54 55 | } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { return [[_cookies copy] autorelease]; } | | | | | | | | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { return [[_cookies copy] autorelease]; } - (void)addCookie: (OFHTTPCookie *)cookie forURI: (OFURI *)URI { void *pool = objc_autoreleasePoolPush(); OFString *cookieDomain, *URIHost; size_t i; if (![cookie.path hasPrefix: @"/"]) cookie.path = @"/"; if (cookie.secure && [URI.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) { objc_autoreleasePoolPop(pool); return; } cookieDomain = cookie.domain.lowercaseString; cookie.domain = cookieDomain; URIHost = URI.host.lowercaseString; if (![cookieDomain isEqual: URIHost]) { URIHost = [@"." stringByAppendingString: URIHost]; if (![cookieDomain hasSuffix: URIHost]) { objc_autoreleasePoolPop(pool); return; } } i = 0; for (OFHTTPCookie *iter in _cookies) { |
︙ | ︙ | |||
96 97 98 99 100 101 102 | [_cookies addObject: cookie]; objc_autoreleasePoolPop(pool); } - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies | | | | | | | | | | | | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | [_cookies addObject: cookie]; objc_autoreleasePoolPop(pool); } - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies forURI: (OFURI *)URI { for (OFHTTPCookie *cookie in cookies) [self addCookie: cookie forURI: URI]; } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURI: (OFURI *)URI { OFMutableArray *ret = [OFMutableArray array]; for (OFHTTPCookie *cookie in _cookies) { void *pool; OFDate *expires; OFString *cookieDomain, *URIHost, *cookiePath, *URIPath; bool match; expires = cookie.expires; if (expires != nil && expires.timeIntervalSinceNow <= 0) continue; if (cookie.secure && [URI.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) continue; pool = objc_autoreleasePoolPush(); cookieDomain = cookie.domain.lowercaseString; URIHost = URI.host.lowercaseString; if ([cookieDomain hasPrefix: @"."]) { if ([URIHost hasSuffix: cookieDomain]) match = true; else { cookieDomain = [cookieDomain substringFromIndex: 1]; match = [cookieDomain isEqual: URIHost]; } } else match = [cookieDomain isEqual: URIHost]; if (!match) { objc_autoreleasePoolPop(pool); continue; } cookiePath = cookie.path; URIPath = URI.path; if (![cookiePath isEqual: @"/"]) { if ([cookiePath isEqual: URIPath]) match = true; else { if (![cookiePath hasSuffix: @"/"]) cookiePath = [cookiePath stringByAppendingString: @"/"]; match = [URIPath hasPrefix: cookiePath]; } if (!match) { objc_autoreleasePoolPop(pool); continue; } } |
︙ | ︙ |
Modified src/OFHTTPRequest.h from [cc3f0d316f] to [1278addd47].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFData; @class OFString; /** @file */ /** |
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 | } OFHTTPRequestProtocolVersion; /** * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief A class for storing HTTP requests. */ @interface OFHTTPRequest: OFObject <OFCopying> { | > | < | | > > > > > > > > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | } OFHTTPRequestProtocolVersion; /** * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief A class for storing HTTP requests. */ OF_SUBCLASSING_RESTRICTED @interface OFHTTPRequest: OFObject <OFCopying> { OFURI *_URI; OFHTTPRequestMethod _method; OFHTTPRequestProtocolVersion _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; OFSocketAddress _remoteAddress; bool _hasRemoteAddress; } /** * @brief The URI of the HTTP request. */ @property (copy, nonatomic) OFURI *URI; /** * @brief The protocol version of the HTTP request. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request as a string. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported * @throw OFInvalidFormatException The specified version cannot be set because * it is not in a valid format */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The request method of the HTTP request. */ @property (nonatomic) OFHTTPRequestMethod method; |
︙ | ︙ | |||
106 107 108 109 110 111 112 | * @brief The remote address from which the request originates. * * @note The setter creates a copy of the remote address. */ @property OF_NULLABLE_PROPERTY (nonatomic) const OFSocketAddress *remoteAddress; /** | | | | | | | | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | * @brief The remote address from which the request originates. * * @note The setter creates a copy of the remote address. */ @property OF_NULLABLE_PROPERTY (nonatomic) const OFSocketAddress *remoteAddress; /** * @brief Creates a new OFHTTPRequest with the specified URI. * * @param URI The URI for the request * @return A new, autoreleased OFHTTPRequest */ + (instancetype)requestWithURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFHTTPRequest with the specified URI. * * @param URI The URI for the request * @return An initialized OFHTTPRequest */ - (instancetype)initWithURI: (OFURI *)URI; - (instancetype)init OF_UNAVAILABLE; @end #ifdef __cplusplus extern "C" { #endif |
︙ | ︙ | |||
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * * @param string The string for which the request method should be returned * @return The request method for the specified string */ extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END | > > | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * * @param string The string for which the request method should be returned * @return The request method for the specified string * @throw OFInvalidFormatException The specified string is not a valid HTTP * request method */ extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFHTTPRequest.m from [723c374a89] to [c85955ea02].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "OFHTTPRequest.h" #import "OFString.h" | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #include <string.h> #import "OFHTTPRequest.h" #import "OFString.h" #import "OFURI.h" #import "OFDictionary.h" #import "OFData.h" #import "OFArray.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" |
︙ | ︙ | |||
70 71 72 73 74 75 76 | if ([string isEqual: @"DELETE"]) return OFHTTPRequestMethodDelete; if ([string isEqual: @"TRACE"]) return OFHTTPRequestMethodTrace; if ([string isEqual: @"CONNECT"]) return OFHTTPRequestMethodConnect; | | | | | | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | if ([string isEqual: @"DELETE"]) return OFHTTPRequestMethodDelete; if ([string isEqual: @"TRACE"]) return OFHTTPRequestMethodTrace; if ([string isEqual: @"CONNECT"]) return OFHTTPRequestMethodConnect; @throw [OFInvalidFormatException exception]; } @implementation OFHTTPRequest @synthesize URI = _URI, method = _method, headers = _headers; + (instancetype)requestWithURI: (OFURI *)URI { return [[[self alloc] initWithURI: URI] autorelease]; } - (instancetype)initWithURI: (OFURI *)URI { self = [super init]; @try { _URI = [URI copy]; _method = OFHTTPRequestMethodGet; _protocolVersion.major = 1; _protocolVersion.minor = 1; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_URI release]; [_headers release]; [super dealloc]; } - (void)setRemoteAddress: (const OFSocketAddress *)remoteAddress { |
︙ | ︙ | |||
129 130 131 132 133 134 135 | return &_remoteAddress; return NULL; } - (id)copy { | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | return &_remoteAddress; return NULL; } - (id)copy { OFHTTPRequest *copy = [[OFHTTPRequest alloc] initWithURI: _URI]; @try { copy->_method = _method; copy->_protocolVersion = _protocolVersion; copy.headers = _headers; copy.remoteAddress = self.remoteAddress; } @catch (id e) { |
︙ | ︙ | |||
159 160 161 162 163 164 165 | return false; request = object; if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || | | | | | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | return false; request = object; if (request->_method != _method || request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_URI isEqual: _URI] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && !OFSocketAddressEqual(request.remoteAddress, self.remoteAddress)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, _method); OFHashAddByte(&hash, _protocolVersion.major); OFHashAddByte(&hash, _protocolVersion.minor); OFHashAddHash(&hash, _URI.hash); OFHashAddHash(&hash, _headers.hash); if (_hasRemoteAddress) OFHashAddHash(&hash, OFSocketAddressHash(&_remoteAddress)); OFHashFinalize(&hash); return hash; |
︙ | ︙ | |||
252 253 254 255 256 257 258 | if (_hasRemoteAddress) remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: | | | | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | if (_hasRemoteAddress) remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURI = %@\n" @"\tMethod = %s\n" @"\tHeaders = %@\n" @"\tRemote address = %@\n" @">", self.class, _URI, method, indentedHeaders, remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end |
Modified src/OFHTTPResponse.h from [b3d8087036] to [3c482db81b].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 | @class OFArray OF_GENERIC(ObjectType); /** * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request response as a stream. */ @interface OFHTTPResponse: OFStream { OFHTTPRequestProtocolVersion _protocolVersion; short _statusCode; OFDictionary OF_GENERIC(OFString *, OFString *) *_headers; | > > > < > > > > > > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | @class OFArray OF_GENERIC(ObjectType); /** * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request response as a stream. */ #if !defined(OF_HTTP_CLIENT_M) && !defined(OF_HTTP_SERVER_M) OF_SUBCLASSING_RESTRICTED #endif @interface OFHTTPResponse: OFStream { OFHTTPRequestProtocolVersion _protocolVersion; short _statusCode; OFDictionary OF_GENERIC(OFString *, OFString *) *_headers; } /** * @brief The protocol version of the HTTP request response. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request response as a string. * * @throw OFUnsupportedVersionException The specified version cannot be set * because it is not supported * @throw OFInvalidFormatException The specified version cannot be set because * it is not in a valid format */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The status code of the response to the HTTP request. */ @property (nonatomic) short statusCode; |
︙ | ︙ |
Modified src/OFHTTPServer.h from [a2fd4b8141] to [ba5fc5aae1].
︙ | ︙ | |||
102 103 104 105 106 107 108 | OFArray *_threadPool; #endif } /** * @brief The host on which the HTTP server will listen. * | < | > < | > < | > | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | OFArray *_threadPool; #endif } /** * @brief The host on which the HTTP server will listen. * * @throw OFAlreadyConnectedException The host could not be set because * @ref start had already been called */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *host; /** * @brief The port on which the HTTP server will listen. * * @throw OFAlreadyConnectedException The port could not be set because * @ref start had already been called */ @property (nonatomic) uint16_t port; /** * @brief The delegate for the HTTP server. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFHTTPServerDelegate> delegate; #ifdef OF_HAVE_THREADS /** * @brief The number of threads the OFHTTPServer should use. * * If this is larger than 1 (the default), one thread will be used to accept * incoming connections and all others will be used to handle connections. * * For maximum CPU utilization, set this to `[OFSystemInfo numberOfCPUs] + 1`. * * @throw OFAlreadyConnectedException The number of threads could not be set * because @ref start had already been called */ @property (nonatomic) size_t numberOfThreads; #endif /** * @brief The server name the server presents to clients. * |
︙ | ︙ | |||
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | * * @return A new HTTP server */ + (instancetype)server; /** * @brief Starts the HTTP server in the current thread's run loop. */ - (void)start; /** * @brief Stops the HTTP server, meaning it will not accept any new incoming * connections, but still handle existing connections until they are * finished or timed out. */ - (void)stop; @end OF_ASSUME_NONNULL_END | > > | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | * * @return A new HTTP server */ + (instancetype)server; /** * @brief Starts the HTTP server in the current thread's run loop. * * @throw OFAlreadyConnectedException The server had already been started */ - (void)start; /** * @brief Stops the HTTP server, meaning it will not accept any new incoming * connections, but still handle existing connections until they are * finished or timed out. */ - (void)stop; @end OF_ASSUME_NONNULL_END |
Modified src/OFHTTPServer.m from [56dd1ea76e] to [e75cf57b42].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * * 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 <errno.h> #include <stdlib.h> #include <string.h> #import "OFHTTPServer.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFNumber.h" #import "OFSocket+Private.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" | > > | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * 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. */ #define OF_HTTP_SERVER_M #include "config.h" #include <errno.h> #include <stdlib.h> #include <string.h> #import "OFHTTPServer.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFNumber.h" #import "OFSocket+Private.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFURI.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" |
︙ | ︙ | |||
355 356 357 358 359 360 361 | { OFString *method; OFMutableString *path; size_t pos; @try { OFString *version = [line | | | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | { OFString *method; OFMutableString *path; size_t pos; @try { OFString *version = [line substringWithRange: OFMakeRange(line.length - 9, 9)]; OFUnichar tmp; if (![version hasPrefix: @" HTTP/1."]) return [self sendErrorAndClose: 505]; tmp = [version characterAtIndex: 8]; if (tmp < '0' || tmp > '9') |
︙ | ︙ | |||
382 383 384 385 386 387 388 | @try { _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { | | | 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | @try { _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { OFRange range = OFMakeRange(pos + 1, line.length - pos - 10); path = [[[line substringWithRange: range] mutableCopy] autorelease]; } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } |
︙ | ︙ | |||
508 509 510 511 512 513 514 | date, _server.name]; return false; } - (void)createResponse { void *pool = objc_autoreleasePoolPush(); | | | < | | | | | | | | 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | date, _server.name]; return false; } - (void)createResponse { void *pool = objc_autoreleasePoolPush(); OFMutableURI *URI; OFHTTPRequest *request; OFHTTPServerResponse *response; size_t pos; [_timer invalidate]; [_timer release]; _timer = nil; if (_host == nil || _port == 0) { if (_HTTPMinorVersion > 0) { [self sendErrorAndClose: 400]; return; } [_host release]; _host = [_server.host copy]; _port = [_server port]; } URI = [OFMutableURI URIWithScheme: @"http"]; URI.host = _host; if (_port != 80) URI.port = [OFNumber numberWithUnsignedShort: _port]; @try { if ((pos = [_path rangeOfString: @"?"].location) != OFNotFound) { OFString *path, *query; path = [_path substringToIndex: pos]; query = [_path substringFromIndex: pos + 1]; URI.percentEncodedPath = path; URI.percentEncodedQuery = query; } else URI.percentEncodedPath = _path; } @catch (OFInvalidFormatException *e) { objc_autoreleasePoolPop(pool); [self sendErrorAndClose: 400]; return; } [URI makeImmutable]; request = [OFHTTPRequest requestWithURI: URI]; request.method = _method; request.protocolVersion = (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion }; request.headers = _headers; request.remoteAddress = _socket.remoteAddress; response = [[[OFHTTPServerResponse alloc] |
︙ | ︙ |
Renamed and modified src/OFHTTPURLHandler.h [6b4755acdc] to src/OFHTTPURIHandler.h [1fbd933246].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * 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. */ | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * * 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 OFHTTPURIHandler: OFURIHandler @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFHTTPURLHandler.m [c4a43aad17] to src/OFHTTPURIHandler.m [9e6fa9d3fe].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | < | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * 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 "OFHTTPURIHandler.h" #import "OFHTTPClient.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" @implementation OFHTTPURIHandler - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFHTTPClient *client = [OFHTTPClient client]; OFHTTPRequest *request = [OFHTTPRequest requestWithURI: URI]; OFHTTPResponse *response = [client performRequest: request]; [response retain]; objc_autoreleasePoolPop(pool); return [response autorelease]; |
︙ | ︙ |
Modified src/OFINICategory.h from [e194c2c9e1] to [8e0c968abf].
︙ | ︙ | |||
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the long long should be returned * @param defaultValue The value to return if the key does not exist * @return The long long for the specified key or the specified default value * if it does not exist */ - (long long)longLongForKey: (OFString *)key defaultValue: (long long)defaultValue; /** * @brief Returns the bool for the specified key or the specified default value * if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the bool should be returned * @param defaultValue The value to return if the key does not exist * @return The bool for the specified key or the specified default value if it * does not exist */ - (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue; /** * @brief Returns the float for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the float should be returned * @param defaultValue The value to return if the key does not exist * @return The float for the specified key or the specified default value if it * does not exist */ - (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue; /** * @brief Returns the double for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the double should be returned * @param defaultValue The value to return if the key does not exist * @return The double for the specified key or the specified default value if * it does not exist */ - (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue; /** * @brief Returns an array of strings for the specified multi-key, or an empty * array if the key does not exist. * | > > > > > > > > | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the long long should be returned * @param defaultValue The value to return if the key does not exist * @return The long long for the specified key or the specified default value * if it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a long long */ - (long long)longLongForKey: (OFString *)key defaultValue: (long long)defaultValue; /** * @brief Returns the bool for the specified key or the specified default value * if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the bool should be returned * @param defaultValue The value to return if the key does not exist * @return The bool for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a bool */ - (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue; /** * @brief Returns the float for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the float should be returned * @param defaultValue The value to return if the key does not exist * @return The float for the specified key or the specified default value if it * does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a float */ - (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue; /** * @brief Returns the double for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the double should be returned * @param defaultValue The value to return if the key does not exist * @return The double for the specified key or the specified default value if * it does not exist * @throw OFInvalidFormatException The specified key is not in the correct * format for a double */ - (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue; /** * @brief Returns an array of strings for the specified multi-key, or an empty * array if the key does not exist. * |
︙ | ︙ |
Modified src/OFINICategory.m from [0938799665] to [1db2d24df3].
︙ | ︙ | |||
54 55 56 57 58 59 60 | [mutableString replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [mutableString replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [mutableString replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [mutableString replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [mutableString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | [mutableString replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [mutableString replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [mutableString replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [mutableString replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [mutableString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [mutableString insertString: @"\"" atIndex: 0]; [mutableString appendString: @"\""]; [mutableString makeImmutable]; return mutableString; } static OFString * unescapeString(OFString *string) { OFMutableString *mutableString; if (![string hasPrefix: @"\""] || ![string hasSuffix: @"\""]) return string; string = [string substringWithRange: OFMakeRange(1, string.length - 2)]; mutableString = [[string mutableCopy] autorelease]; [mutableString replaceOccurrencesOfString: @"\\f" withString: @"\f"]; [mutableString replaceOccurrencesOfString: @"\\r" withString: @"\r"]; [mutableString replaceOccurrencesOfString: @"\\n" withString: @"\n"]; [mutableString replaceOccurrencesOfString: @"\\\"" withString: @"\""]; [mutableString replaceOccurrencesOfString: @"\\\\" withString: @"\\"]; |
︙ | ︙ |
Modified src/OFINIFile.h from [de47c3e875] to [f35fd21473].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFObject.h" #import "OFString.h" #import "OFINICategory.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); | | | > > > > | | < > > > > | | > > > > | | < > > > > | | | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | #import "OFObject.h" #import "OFString.h" #import "OFINICategory.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @class OFURI; /** * @class OFINIFile OFINIFile.h ObjFW/OFINIFile.h * * @brief A class for reading, creating and modifying INI files. */ OF_SUBCLASSING_RESTRICTED @interface OFINIFile: OFObject { OFMutableArray OF_GENERIC(OFINICategory *) *_categories; } /** * @brief All categories in the INI file. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFINICategory *) *categories; /** * @brief Creates a new OFINIFile with the contents of the specified file. * * @param URI The URI to the file whose contents the OFINIFile should contain * * @return A new, autoreleased OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ + (instancetype)fileWithURI: (OFURI *)URI; /** * @brief Creates a new OFINIFile with the contents of the specified file in * the specified encoding. * * @param URI The URI to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * @return A new, autoreleased OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ + (instancetype)fileWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFINIFile with the contents of the * specified file. * * @param URI The URI to the file whose contents the OFINIFile should contain * * @return An initialized OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ - (instancetype)initWithURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFINIFile with the contents of the * specified file in the specified encoding. * * @param URI The URI to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * @return An initialized OFINIFile with the contents of the specified file * @throw OFInvalidFormatException The format of the specified INI file is * invalid * @throw OFInvalidEncodingException The INI file is not in the specified * encoding */ - (instancetype)initWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding OF_DESIGNATED_INITIALIZER; /** * @brief Returns an @ref OFINICategory for the category with the specified * name. * * @param name The name of the category for which an @ref OFINICategory should * be returned * * @return An @ref OFINICategory for the category with the specified name */ - (OFINICategory *)categoryForName: (OFString *)name; /** * @brief Writes the contents of the OFINIFile to a file. * * @param URI The URI of the file to write to */ - (void)writeToURI: (OFURI *)URI; /** * @brief Writes the contents of the OFINIFile to a file in the specified * encoding. * * @param URI The URI of the file to write to * @param encoding The encoding to use */ - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END |
Modified src/OFINIFile.m from [5568ad8169] to [7850530cf1].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFINIFile.h" #import "OFArray.h" #import "OFINICategory+Private.h" #import "OFINICategory.h" #import "OFStream.h" #import "OFString.h" | | | | | | | | | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #import "OFINIFile.h" #import "OFArray.h" #import "OFINICategory+Private.h" #import "OFINICategory.h" #import "OFStream.h" #import "OFString.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" OF_DIRECT_MEMBERS @interface OFINIFile () - (void)of_parseURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = line.UTF8String; size_t length = line.UTF8StringLength; for (size_t i = 0; i < length; i++) if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile @synthesize categories = _categories; + (instancetype)fileWithURI: (OFURI *)URI { return [[[self alloc] initWithURI: URI] autorelease]; } + (instancetype)fileWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithURI: URI encoding: encoding] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI { return [self initWithURI: URI encoding: OFStringEncodingAutodetect]; } - (instancetype)initWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { self = [super init]; @try { _categories = [[OFMutableArray alloc] init]; [self of_parseURI: URI encoding: encoding]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
106 107 108 109 110 111 112 | [_categories addObject: category]; objc_autoreleasePoolPop(pool); return category; } | | > > > < | | | | | | < < | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | [_categories addObject: category]; objc_autoreleasePoolPop(pool); return category; } - (void)of_parseURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file; OFINICategory *category = nil; OFString *line; if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; @try { file = [OFURIHandler openItemAtURI: URI mode: @"r"]; } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if (e.errNo == ENOENT) return; @throw e; } while ((line = [file readLineWithEncoding: encoding]) != nil) { if (isWhitespaceLine(line)) continue; if ([line hasPrefix: @"["]) { OFString *categoryName; if (![line hasSuffix: @"]"]) @throw [OFInvalidFormatException exception]; categoryName = [line substringWithRange: OFMakeRange(1, line.length - 2)]; category = [[[OFINICategory alloc] of_initWithName: categoryName] autorelease]; [_categories addObject: category]; } else { if (category == nil) @throw [OFInvalidFormatException exception]; [category of_parseLine: line]; } } objc_autoreleasePoolPop(pool); } - (void)writeToURI: (OFURI *)URI { [self writeToURI: URI encoding: OFStringEncodingUTF8]; } - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"w"]; bool first = true; for (OFINICategory *category in _categories) if ([category of_writeToStream: file encoding: encoding first: first]) first = false; |
︙ | ︙ |
Modified src/OFINIFileSettings.h from [e6622a40c7] to [125e92a3e8].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFSettings.h" OF_ASSUME_NONNULL_BEGIN @class OFINIFile; @class OFString; | | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #import "OFSettings.h" OF_ASSUME_NONNULL_BEGIN @class OFINIFile; @class OFString; @class OFURI; @interface OFINIFileSettings: OFSettings { OFURI *_fileURI; OFINIFile *_INIFile; } @end OF_ASSUME_NONNULL_END |
Modified src/OFINIFileSettings.m from [06a12ac82c] to [b3d1a39e2b].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "OFINIFileSettings.h" #import "OFArray.h" #import "OFINIFile.h" #import "OFString.h" #import "OFSystemInfo.h" | | | | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include "config.h" #import "OFINIFileSettings.h" #import "OFArray.h" #import "OFINIFile.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURI.h" @implementation OFINIFileSettings - (instancetype)initWithApplicationName: (OFString *)applicationName { self = [super initWithApplicationName: applicationName]; @try { void *pool = objc_autoreleasePoolPush(); OFString *fileName; fileName = [applicationName stringByAppendingString: @".ini"]; _fileURI = [[[OFSystemInfo userConfigURI] URIByAppendingPathComponent: fileName] copy]; _INIFile = [[OFINIFile alloc] initWithURI: _fileURI]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_fileURI release]; [_INIFile release]; [super dealloc]; } - (void)of_getCategory: (OFString **)category andKey: (OFString **)key |
︙ | ︙ | |||
239 240 241 242 243 244 245 | [[_INIFile categoryForName: category] removeValueForKey: key]; objc_autoreleasePoolPop(pool); } - (void)save { | | | 239 240 241 242 243 244 245 246 247 248 | [[_INIFile categoryForName: category] removeValueForKey: key]; objc_autoreleasePoolPop(pool); } - (void)save { [_INIFile writeToURI: _fileURI]; } @end |
Modified src/OFIPXSocket.h from [a2ca3d4d82] to [08f31366a1].
︙ | ︙ | |||
67 68 69 70 71 72 73 74 75 76 77 78 | * @brief Bind the socket to the specified network, node and port with the * specified packet type. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END | > > | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | * @brief Bind the socket to the specified network, node and port with the * specified packet type. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @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 OFAlreadyConnectedException The socket is already bound */ - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END |
Modified src/OFInvocation.h from [324ba0dca4] to [ab7d9433d5].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 | @class OFMutableData; /** * @class OFInvocation OFInvocation.h ObjFW/OFInvocation.h * * @brief A class for storing and accessing invocations, and invoking them. */ @interface OFInvocation: OFObject { OFMethodSignature *_methodSignature; OFMutableArray OF_GENERIC(OFMutableData *) *_arguments; OFMutableData *_returnValue; | > < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | @class OFMutableData; /** * @class OFInvocation OFInvocation.h ObjFW/OFInvocation.h * * @brief A class for storing and accessing invocations, and invoking them. */ OF_SUBCLASSING_RESTRICTED @interface OFInvocation: OFObject { OFMethodSignature *_methodSignature; OFMutableArray OF_GENERIC(OFMutableData *) *_arguments; OFMutableData *_returnValue; } /** * @brief The method signature for the invocation. */ @property (readonly, nonatomic) OFMethodSignature *methodSignature; |
︙ | ︙ |
Modified src/OFKernelEventObserver.h from [21aebcf8a0] to [81efdafa0c].
︙ | ︙ | |||
41 42 43 44 45 46 47 | */ @protocol OFKernelEventObserverDelegate <OFObject> @optional /** * @brief This callback is called when an object did get ready for reading. * * @note If the object is a subclass of @ref OFStream and | | | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | */ @protocol OFKernelEventObserverDelegate <OFObject> @optional /** * @brief This callback is called when an object did get ready for reading. * * @note If the object is a subclass of @ref OFStream and * @ref OFStream::tryReadLine or @ref OFStream::tryReadUntilDelimiter: * has been called on the stream, this callback will not be called again * until new data has been received, even though there is still data in * the cache. The reason for this is to prevent spinning in a loop when * there is an incomplete string in the cache. Once the string has been * completed, the callback will be called again as long there is data in * the cache. * * @param object The object which did become ready for reading |
︙ | ︙ | |||
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | * This is also used to observe a listening socket for incoming connections, * which then triggers a read event for the observed object. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for reading */ - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object; /** * @brief Adds an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for writing */ - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object; /** * @brief Removes an object to observe for reading. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for reading */ - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object; /** * @brief Removes an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for writing */ - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object; /** * @brief Observes all objects and blocks until an event happens on an object. */ - (void)observe; /** * @brief Observes all objects until an event happens on an object or the * timeout is reached. * * @param timeInterval The time to wait for an event, in seconds */ - (void)observeForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Observes all objects until an event happens on an object or the * specified date is reached. * * @param date The until which to observe */ - (void)observeUntilDate: (OFDate *)date; /** * @brief Cancels the currently blocking observe call. * * This is the only method that can and should be called from another thread | > > > > > > > > > > > > > > > | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | * This is also used to observe a listening socket for incoming connections, * which then triggers a read event for the observed object. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for reading * @throw OFObserveKernelEventsFailedException Adding the object for observing * failed */ - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object; /** * @brief Adds an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent blocking even though the newly added object is ready. * * @param object The object to observe for writing * @throw OFObserveKernelEventsFailedException Adding the object for observing * failed */ - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object; /** * @brief Removes an object to observe for reading. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for reading * @throw OFObserveKernelEventsFailedException Removing the object for observing * failed */ - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object; /** * @brief Removes an object to observe for writing. * * If there is an @ref observe call blocking, it will be canceled. The reason * for this is to prevent the removed object from still being observed. * * @param object The object to remove from observing for writing * @throw OFObserveKernelEventsFailedException Removing the object for observing * failed */ - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object; /** * @brief Observes all objects and blocks until an event happens on an object. * * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observe; /** * @brief Observes all objects until an event happens on an object or the * timeout is reached. * * @param timeInterval The time to wait for an event, in seconds * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observeForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Observes all objects until an event happens on an object or the * specified date is reached. * * @param date The until which to observe * @throw OFObserveKernelEventsFailedException Observing for kernel events * failed */ - (void)observeUntilDate: (OFDate *)date; /** * @brief Cancels the currently blocking observe call. * * This is the only method that can and should be called from another thread |
︙ | ︙ |
Modified src/OFKeyValueCoding.h from [06cc2c1de6] to [3568d90874].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | */ @protocol OFKeyValueCoding /** * @brief Returns the value for the specified key. * * @param key The key of the value to return * @return The value for the specified key */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Returns the value for the specified key path. * * @param keyPath The key path of the value to return * @return The value for the specified key path */ - (nullable id)valueForKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref valueForKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param key The undefined key of the value to return * @return The value for the specified undefined key */ - (nullable id)valueForUndefinedKey: (OFString *)key; /** * @brief Set the value for the specified key. * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Set the value for the specified key path. * * @param value The value for the specified key path * @param keyPath The key path of the value to set */ - (void)setValue: (nullable id)value forKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref setValue:forKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param value The value for the specified undefined key * @param key The undefined key of the value to set */ - (void)setValue: (nullable id)value forUndefinedKey: (OFString *)key; /** * @brief This is called by @ref setValue:forKey: if the specified key is a * scalar, but the value specified is `nil`. * | > > > > > > > > > > > > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | */ @protocol OFKeyValueCoding /** * @brief Returns the value for the specified key. * * @param key The key of the value to return * @return The value for the specified key * @throw OFUndefinedKeyException The specified key does not exist and * @ref valueForUndefinedKey: was not overridden */ - (nullable id)valueForKey: (OFString *)key; /** * @brief Returns the value for the specified key path. * * @param keyPath The key path of the value to return * @return The value for the specified key path * @throw OFUndefinedKeyException The specified key does not exist and * @ref valueForUndefinedKey: was not overridden */ - (nullable id)valueForKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref valueForKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param key The undefined key of the value to return * @return The value for the specified undefined key * @throw OFUndefinedKeyException The specified key does not exist */ - (nullable id)valueForUndefinedKey: (OFString *)key; /** * @brief Set the value for the specified key. * * @param value The value for the specified key * @param key The key of the value to set * @throw OFUndefinedKeyException The specified key does not exist and * @ref setValue:forUndefinedKey: was not * overridden */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Set the value for the specified key path. * * @param value The value for the specified key path * @param keyPath The key path of the value to set * @throw OFUndefinedKeyException The specified key does not exist and * @ref setValue:forUndefinedKey: was not * overridden */ - (void)setValue: (nullable id)value forKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref setValue:forKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param value The value for the specified undefined key * @param key The undefined key of the value to set * @throw OFUndefinedKeyException The specified key does not exist */ - (void)setValue: (nullable id)value forUndefinedKey: (OFString *)key; /** * @brief This is called by @ref setValue:forKey: if the specified key is a * scalar, but the value specified is `nil`. * |
︙ | ︙ |
Modified src/OFKqueueKernelEventObserver.m from [bcb05813e9] to [ef6117c8da].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #include <sys/event.h> #include <sys/time.h> #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <sys/event.h> #include <sys/time.h> #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #define eventListSize 64 @implementation OFKqueueKernelEventObserver - (instancetype)init { |
︙ | ︙ | |||
90 91 92 93 94 95 96 | /* * Ugly hack required for NetBSD: NetBSD used `intptr_t` for udata, but * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) | > | | > | | > | | > | | > | | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /* * Ugly hack required for NetBSD: NetBSD used `intptr_t` for udata, but * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super addObjectForReading: object]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_ADD; /* * Ugly hack required for NetBSD: NetBSD used `intptr_t` for udata, but * switched this to `void *` in NetBSD 10. */ event.udata = (__typeof__(event.udata))object; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForReading; event.filter = EVFILT_READ; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { struct kevent event; memset(&event, 0, sizeof(event)); event.ident = object.fileDescriptorForWriting; event.filter = EVFILT_WRITE; event.flags = EV_DELETE; if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { struct timespec timeout; struct kevent eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = (long)((timeInterval - timeout.tv_sec) * 1000000000); events = kevent(_kernelQueue, NULL, 0, eventList, eventListSize, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { void *pool; if (eventList[i].flags & EV_ERROR) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: (int)eventList[i].data]; if (eventList[i].ident == (uintptr_t)_cancelFD[0]) { char buffer; assert(eventList[i].filter == EVFILT_READ); |
︙ | ︙ |
Modified src/OFLHAArchive.h from [eaf15d177e] to [d69e07845d].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFKernelEventObserver.h" #import "OFLHAArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; /** * @class OFLHAArchive OFLHAArchive.h ObjFW/OFLHAArchive.h * * @brief A class for accessing and manipulating LHA files. */ OF_SUBCLASSING_RESTRICTED @interface OFLHAArchive: OFObject { OFStream *_stream; uint_least8_t _mode; OFStringEncoding _encoding; OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to ISO 8859-1. */ @property (nonatomic) OFStringEncoding encoding; | > > > > > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #import "OFKernelEventObserver.h" #import "OFLHAArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; @class OFURI; /** * @class OFLHAArchive OFLHAArchive.h ObjFW/OFLHAArchive.h * * @brief A class for accessing and manipulating LHA files. */ OF_SUBCLASSING_RESTRICTED @interface OFLHAArchive: OFObject { OFStream *_stream; uint_least8_t _mode; OFStringEncoding _encoding; OFLHAArchiveEntry *_Nullable _currentEntry; #ifdef OF_LHA_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to ISO 8859-1. */ @property (nonatomic) OFStringEncoding encoding; |
︙ | ︙ | |||
59 60 61 62 63 64 65 | * @param mode The mode for the LHA 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 OFLHAArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; | < | | | > > > > > > > > > > < | | < > > > > | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | * @param mode The mode for the LHA 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 OFLHAArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFLHAArchive object with the specified file. * * @param URI The URI to the LHA file * @param mode The mode for the LHA 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 OFLHAArchive */ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Creates a URI for accessing a the specified file within the specified * LHA archive. * * @param path The path of the file within the archive * @param URI The URI of the archive * @return A URI for accessing the specified file within the specified LHA * archive */ + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated 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. * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFLHAArchive object with the * specified file. * * @param URI The URI to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns the next entry from the LHA archive or `nil` if all entries * have been read. * * @note This is only available in read mode. * * @warning Calling @ref nextEntry will invalidate all streams returned by * @ref streamForReadingCurrentEntry or * @ref streamForWritingEntry:! Reading from or writing to an * invalidated stream will throw an @ref OFReadFailedException or * @ref OFWriteFailedException! * * @return The next entry from the LHA archive or `nil` if all entries have * been read * @throw OFInvalidFormatException The archive's format is invalid * @throw OFUnsupportedVersionException The archive's format is of an * unsupported version * @throw OFTruncatedDataException The archive was truncated */ - (nullable OFLHAArchiveEntry *)nextEntry; /** * @brief Returns a stream for writing the specified entry. * * @note This is only available in write and append mode. |
︙ | ︙ |
Modified src/OFLHAArchive.m from [5dc375ab00] to [fa04eb799a].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * * 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 <errno.h> #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" | > > | < | < > | | > > | | > | > | > | | | < | | | > > > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | * * 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. */ #define OF_LHA_ARCHIVE_M #include "config.h" #include <errno.h> #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArchiveURIHandler.h" #import "OFCRC16.h" #import "OFLHADecompressingStream.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFString.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFLHAArchiveFileReadStream: OFStream <OFReadyForReadingObserving> { OFLHAArchive *_archive; OFStream *_stream, *_decompressedStream; OFLHAArchiveEntry *_entry; unsigned long long _toRead; uint16_t _CRC16; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; - (void)of_skip; @end OF_DIRECT_MEMBERS @interface OFLHAArchiveFileWriteStream: OFStream <OFReadyForWritingObserving> { OFLHAArchive *_archive; OFMutableLHAArchiveEntry *_entry; OFStringEncoding _encoding; OFSeekableStream *_stream; OFStreamOffset _headerOffset; uint32_t _bytesWritten; uint16_t _CRC16; } - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding; @end @implementation OFLHAArchive @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode { return [[[self alloc] initWithURI: URI mode: mode] autorelease]; } + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI { return OFArchiveURIHandlerURIForFileInArchive(@"lha", path, URI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode |
︙ | ︙ | |||
112 113 114 115 116 117 118 | if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) [(OFSeekableStream *)_stream seekToOffset: 0 | | < | > | > | | | < > > > > | | | < < | > < > > < > > > < | | < < < < | | | > > | > > > > | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) [(OFSeekableStream *)_stream seekToOffset: 0 whence: OFSeekEnd]; _encoding = OFStringEncodingISO8859_1; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFURIHandler openItemAtURI: URI mode: @"r+"]; else stream = [OFURIHandler openItemAtURI: URI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_stream != nil) [self close]; [_currentEntry release]; [super dealloc]; } - (OFLHAArchiveEntry *)nextEntry { char header[21]; size_t headerLen; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; [_currentEntry release]; _currentEntry = nil; [(OFLHAArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; for (headerLen = 0; headerLen < 21;) { if (_stream.atEndOfStream) { if (headerLen == 0) return nil; if (headerLen == 1 && header[0] == 0) return nil; @throw [OFTruncatedDataException exception]; } headerLen += [_stream readIntoBuffer: header + headerLen length: 21 - headerLen]; } _currentEntry= [[OFLHAArchiveEntry alloc] of_initWithHeader: header stream: _stream encoding: _encoding]; return _currentEntry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry == nil) @throw [OFInvalidArgumentException exception]; _lastReturnedStream = [[[OFLHAArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: _currentEntry] autorelease]; [_currentEntry release]; _currentEntry = nil; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFLHAArchiveEntry *)entry { OFString *compressionMethod; if (_mode != modeWrite && _mode != modeAppend) |
︙ | ︙ | |||
227 228 229 230 231 232 233 | object: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } | < | > | | | | < < | > | > | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | object: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; _lastReturnedStream = [[[OFLHAArchiveFileWriteStream alloc] of_initWithArchive: self stream: (OFSeekableStream *)_stream entry: entry encoding: _encoding] autorelease]; return _lastReturnedStream; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; [_stream release]; _stream = nil; } @end @implementation OFLHAArchiveFileReadStream - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry { self = [super init]; @try { OFString *compressionMethod; _archive = [archive retain]; _stream = [stream retain]; compressionMethod = entry.compressionMethod; if ([compressionMethod isEqual: @"-lh4-"] || [compressionMethod isEqual: @"-lh5-"]) _decompressedStream = [[OFLHADecompressingStream alloc] |
︙ | ︙ | |||
306 307 308 309 310 311 312 313 314 315 316 317 318 319 | - (void)dealloc { if (_stream != nil || _decompressedStream != nil) [self close]; [_entry release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; | > > > > > | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | - (void)dealloc { if (_stream != nil || _decompressedStream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; |
︙ | ︙ | |||
331 332 333 334 335 336 337 | if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) | | | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = OFCRC16(_CRC16, buffer, ret); if (_toRead == 0) { |
︙ | ︙ | |||
371 372 373 374 375 376 377 | return ((id <OFReadyForReadingObserving>)_decompressedStream) .fileDescriptorForReading; } - (void)of_skip { OFStream *stream; | | | 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | return ((id <OFReadyForReadingObserving>)_decompressedStream) .fileDescriptorForReading; } - (void)of_skip { OFStream *stream; unsigned long long toRead; if (_stream == nil || _skipped) return; stream = _stream; toRead = _toRead; |
︙ | ︙ | |||
396 397 398 399 400 401 402 | toRead = _entry.compressedSize - decompressingStream.bytesConsumed; stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && | | | | | | > | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | toRead = _entry.compressedSize - decompressingStream.bytesConsumed; stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && toRead < LLONG_MAX && (long long)toRead == (OFStreamOffset)toRead) [(OFSeekableStream *)stream seekToOffset: (OFStreamOffset)toRead whence: OFSeekCurrent]; else { while (toRead > 0) { char buffer[512]; unsigned long long min = toRead; if (min > 512) min = 512; toRead -= [stream readIntoBuffer: buffer length: (size_t)min]; } } _toRead = 0; _skipped = true; } |
︙ | ︙ | |||
433 434 435 436 437 438 439 | _decompressedStream = nil; [super close]; } @end @implementation OFLHAArchiveFileWriteStream | > | | | > | | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | _decompressedStream = nil; [super close]; } @end @implementation OFLHAArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFLHAArchive *)archive stream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [archive retain]; _entry = [entry mutableCopy]; _encoding = encoding; _headerOffset = [stream seekToOffset: 0 whence: OFSeekCurrent]; [_entry of_writeToStream: stream encoding: _encoding]; /* * Retain stream last, so that -[close] called by -[dealloc] * doesn't write in case of an error. */ _stream = [stream retain]; |
︙ | ︙ | |||
465 466 467 468 469 470 471 472 473 474 475 476 477 478 | - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) | > > > > > | 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) |
︙ | ︙ | |||
513 514 515 516 517 518 519 | { return ((id <OFReadyForWritingObserving>)_stream) .fileDescriptorForWriting; } - (void)close { | | | | | | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | { return ((id <OFReadyForWritingObserving>)_stream) .fileDescriptorForWriting; } - (void)close { OFStreamOffset offset; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; offset = [_stream seekToOffset: 0 whence: OFSeekCurrent]; [_stream seekToOffset: _headerOffset whence: OFSeekSet]; [_entry of_writeToStream: _stream encoding: _encoding]; [_stream seekToOffset: offset whence: OFSeekSet]; [_stream release]; _stream = nil; [super close]; } @end |
Modified src/OFLHAArchiveEntry+Private.h from [dc492f96c5] to [521b95b2fc].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFLHAArchive.h" OF_ASSUME_NONNULL_BEGIN | < > | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * file. */ #import "OFLHAArchive.h" OF_ASSUME_NONNULL_BEGIN @interface OFLHAArchiveEntry () - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (char [_Nonnull 21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init) OF_DIRECT; - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_DIRECT; @end OF_ASSUME_NONNULL_END |
Modified src/OFLHAArchiveEntry.h from [e47bb8e429] to [89ea23a8c1].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * 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 "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFData; @class OFDate; @class OFMutableArray OF_GENERIC(ObjectType); @class OFNumber; @class OFString; /** * @class OFLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFLHAArchiveEntry.h * * @brief A class which represents an entry in an LHA archive. */ | > | > | | > | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | * 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 "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFData; @class OFDate; @class OFMutableArray OF_GENERIC(ObjectType); @class OFNumber; @class OFString; /** * @class OFLHAArchiveEntry OFLHAArchiveEntry.h ObjFW/OFLHAArchiveEntry.h * * @brief A class which represents an entry in an LHA archive. */ @interface OFLHAArchiveEntry: OFObject <OFArchiveEntry, OFCopying, OFMutableCopying> { OFString *_fileName, *_Nullable _directoryName, *_compressionMethod; unsigned long long _compressedSize, _uncompressedSize; OFDate *_modificationDate; uint8_t _headerLevel; uint16_t _CRC16; uint8_t _operatingSystemIdentifier; OFString *_Nullable _fileComment; OFNumber *_Nullable _POSIXPermissions, *_Nullable _ownerAccountID; OFNumber *_Nullable _groupOwnerAccountID; OFString *_Nullable _ownerAccountName; OFString *_Nullable _groupOwnerAccountName; OFMutableArray OF_GENERIC(OFData *) *_extensions; OF_RESERVE_IVARS(OFLHAArchiveEntry, 4) } /** * @brief The compression method of the entry. */ @property (readonly, copy, nonatomic) OFString *compressionMethod; /** * @brief The LHA level of the file. */ @property (readonly, nonatomic) uint8_t headerLevel; /** * @brief The CRC16 of the file. */ @property (readonly, nonatomic) uint16_t CRC16; /** * @brief The operating system identifier of the file. */ @property (readonly, nonatomic) uint8_t operatingSystemIdentifier; /** * @brief The LHA extensions of the file. */ @property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #import "OFMutableLHAArchiveEntry.h" |
Modified src/OFLHAArchiveEntry.m from [45c1be7d3b] to [b338459827].
︙ | ︙ | |||
109 110 111 112 113 114 115 | length: extension.count - 1]; } static void parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { | | | | | | > | | | | | | | | | | > | > | | | | | | | | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | length: extension.count - 1]; } static void parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t POSIXPermissions; if (extension.count != 3) @throw [OFInvalidFormatException exception]; memcpy(&POSIXPermissions, (char *)extension.items + 1, 2); POSIXPermissions = OFFromLittleEndian16(POSIXPermissions); [entry->_POSIXPermissions release]; entry->_POSIXPermissions = nil; entry->_POSIXPermissions = [[OFNumber alloc] initWithUnsignedShort: POSIXPermissions]; } static void parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t ownerAccountID, groupOwnerAccountID; if (extension.count != 5) @throw [OFInvalidFormatException exception]; memcpy(&groupOwnerAccountID, (char *)extension.items + 1, 2); groupOwnerAccountID = OFFromLittleEndian16(groupOwnerAccountID); memcpy(&ownerAccountID, (char *)extension.items + 3, 2); ownerAccountID = OFFromLittleEndian16(ownerAccountID); [entry->_groupOwnerAccountID release]; entry->_groupOwnerAccountID = nil; [entry->_ownerAccountID release]; entry->_ownerAccountID = nil; entry->_groupOwnerAccountID = [[OFNumber alloc] initWithUnsignedShort: groupOwnerAccountID]; entry->_ownerAccountID = [[OFNumber alloc] initWithUnsignedShort: ownerAccountID]; } static void parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_groupOwnerAccountName release]; entry->_groupOwnerAccountName = nil; entry->_groupOwnerAccountName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseOwnerExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_ownerAccountName release]; entry->_ownerAccountName = nil; entry->_ownerAccountName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseModificationDateExtension(OFLHAArchiveEntry *entry, OFData *extension, |
︙ | ︙ | |||
299 300 301 302 303 304 305 | *fileName = cString + pos; *fileNameLength = length - pos; *directoryName = cString; *directoryNameLength = pos; } | < < < < < | < | | 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | *fileName = cString + pos; *fileNameLength = length - pos; *directoryName = cString; *directoryNameLength = pos; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _compressionMethod = @"-lh0-"; _modificationDate = [[OFDate alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
339 340 341 342 343 344 345 346 | uint32_t date; _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; memcpy(&_compressedSize, header + 7, 4); | > > > > | > | > | | | 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | uint32_t date; _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; if (_compressedSize > UINT32_MAX || _uncompressedSize > UINT32_MAX) @throw [OFOutOfRangeException exception]; memcpy(&_compressedSize, header + 7, 4); _compressedSize = OFFromLittleEndian32((uint32_t)_compressedSize); memcpy(&_uncompressedSize, header + 11, 4); _uncompressedSize = OFFromLittleEndian32((uint32_t)_uncompressedSize); memcpy(&date, header + 15, 4); date = OFFromLittleEndian32(date); _headerLevel = header[20]; _extensions = [[OFMutableArray alloc] init]; switch (_headerLevel) { case 0: case 1:; void *pool = objc_autoreleasePoolPush(); uint8_t fileNameLength; OFString *tmp; _modificationDate = [parseMSDOSDate(date) retain]; fileNameLength = [stream readInt8]; tmp = [stream readStringWithLength: fileNameLength encoding: encoding]; tmp = [tmp stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; _fileName = [tmp copy]; _CRC16 = [stream readLittleEndianInt16]; if (_headerLevel == 1) { _operatingSystemIdentifier = [stream readInt8]; readExtensions(self, stream, encoding, false); } objc_autoreleasePoolPop(pool); break; case 2: _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: date]; _CRC16 = [stream readLittleEndianInt16]; _operatingSystemIdentifier = [stream readInt8]; readExtensions(self, stream, encoding, true); |
︙ | ︙ | |||
412 413 414 415 416 417 418 | } - (void)dealloc { [_compressionMethod release]; [_fileName release]; [_directoryName release]; | | | | | | | | | | | | | | | < | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | } - (void)dealloc { [_compressionMethod release]; [_fileName release]; [_directoryName release]; [_modificationDate release]; [_fileComment release]; [_POSIXPermissions release]; [_ownerAccountID release]; [_groupOwnerAccountID release]; [_ownerAccountName release]; [_groupOwnerAccountName release]; [_extensions release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFLHAArchiveEntry *copy = [[OFMutableLHAArchiveEntry alloc] initWithFileName: _fileName]; @try { [copy->_compressionMethod release]; copy->_compressionMethod = nil; [copy->_modificationDate release]; copy->_modificationDate = nil; copy->_directoryName = [_directoryName copy]; copy->_compressionMethod = [_compressionMethod copy]; copy->_compressedSize = _compressedSize; copy->_uncompressedSize = _uncompressedSize; copy->_modificationDate = [_modificationDate copy]; copy->_headerLevel = _headerLevel; copy->_CRC16 = _CRC16; copy->_operatingSystemIdentifier = _operatingSystemIdentifier; copy->_fileComment = [_fileComment copy]; copy->_POSIXPermissions = [_POSIXPermissions retain]; copy->_ownerAccountID = [_ownerAccountID retain]; copy->_groupOwnerAccountID = [_groupOwnerAccountID retain]; copy->_ownerAccountName = [_ownerAccountName copy]; copy->_groupOwnerAccountName = [_groupOwnerAccountName copy]; copy->_extensions = [_extensions copy]; } @catch (id e) { [copy release]; @throw e; } return copy; |
︙ | ︙ | |||
478 479 480 481 482 483 484 | } - (OFString *)compressionMethod { return _compressionMethod; } | | | | | | 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | } - (OFString *)compressionMethod { return _compressionMethod; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (OFDate *)modificationDate { return _modificationDate; } - (uint8_t)headerLevel { return _headerLevel; } |
︙ | ︙ | |||
513 514 515 516 517 518 519 | } - (OFString *)fileComment { return _fileComment; } | | | | | | | | | | | < < < < < | 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | } - (OFString *)fileComment { return _fileComment; } - (OFNumber *)POSIXPermissions { return _POSIXPermissions; } - (OFNumber *)ownerAccountID { return _ownerAccountID; } - (OFNumber *)groupOwnerAccountID { return _groupOwnerAccountID; } - (OFString *)ownerAccountName { return _ownerAccountName; } - (OFString *)groupOwnerAccountName { return _groupOwnerAccountName; } - (OFArray OF_GENERIC(OFData *) *)extensions { return _extensions; } |
︙ | ︙ | |||
567 568 569 570 571 572 573 | OFStringEncodingASCII] != 5) @throw [OFInvalidArgumentException exception]; getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength, &directoryName, &directoryNameLength); if (fileNameLength > UINT16_MAX - 3 || | | > | | | > | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | OFStringEncodingASCII] != 5) @throw [OFInvalidArgumentException exception]; getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength, &directoryName, &directoryNameLength); if (fileNameLength > UINT16_MAX - 3 || directoryNameLength > UINT16_MAX - 3 || _compressedSize > UINT32_MAX || _uncompressedSize > UINT32_MAX) @throw [OFOutOfRangeException exception]; /* Length. Filled in after we're done. */ [data increaseCountBy: 2]; [data addItems: [_compressionMethod cStringWithEncoding: OFStringEncodingASCII] count: 5]; tmp32 = OFToLittleEndian32((uint32_t)_compressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32((uint32_t)_uncompressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32( (uint32_t)_modificationDate.timeIntervalSince1970); [data addItems: &tmp32 count: sizeof(tmp32)]; /* Reserved */ [data increaseCountBy: 1]; /* Header level */ [data addItem: "\x02"]; |
︙ | ︙ | |||
631 632 633 634 635 636 637 | tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x3F"]; [data addItems: [_fileComment cStringWithEncoding: encoding] count: fileCommentLength]; } | | > | | | | > | | | | | | | > | | | | | | | < < | < < < < | < < < | 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x3F"]; [data addItems: [_fileComment cStringWithEncoding: encoding] count: fileCommentLength]; } if (_POSIXPermissions != nil) { tmp16 = OFToLittleEndian16(5); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x50"]; tmp16 = OFToLittleEndian16(_POSIXPermissions.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_ownerAccountID != nil || _groupOwnerAccountID != nil) { if (_ownerAccountID == nil || _groupOwnerAccountID == nil) @throw [OFInvalidArgumentException exception]; tmp16 = OFToLittleEndian16(7); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x51"]; tmp16 = OFToLittleEndian16( _groupOwnerAccountID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; tmp16 = OFToLittleEndian16(_ownerAccountID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_groupOwnerAccountName != nil) { size_t length = [_groupOwnerAccountName cStringLengthWithEncoding: encoding]; if (length > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)length + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x52"]; [data addItems: [_groupOwnerAccountName cStringWithEncoding: encoding] count: length]; } if (_ownerAccountName != nil) { size_t length = [_ownerAccountName cStringLengthWithEncoding: encoding]; if (length > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)length + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x53"]; [data addItems: [_ownerAccountName cStringWithEncoding: encoding] count: length]; } for (OFData *extension in _extensions) { size_t extensionLength = extension.count; if (extension.itemSize != 1) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
731 732 733 734 735 736 737 | objc_autoreleasePoolPop(pool); } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); | | < > > > > > > | | | | | | | | | < | | > | | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | objc_autoreleasePoolPop(pool); } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *POSIXPermissions = nil; OFString *extensions = [_extensions.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; OFString *ret; if (_POSIXPermissions != nil) POSIXPermissions = [OFString stringWithFormat: @"%ho", _POSIXPermissions.unsignedShortValue]; ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tCompression method = %@\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tModification date = %@\n" @"\tHeader level = %u\n" @"\tCRC16 = %04" @PRIX16 @"\n" @"\tOperating system identifier = %c\n" @"\tComment = %@\n" @"\tPOSIX permissions = %@\n" @"\tOwner account ID = %@\n" @"\tGroup owner account ID = %@\n" @"\tOwner account name = %@\n" @"\tGroup owner accounut name = %@\n" @"\tExtensions: %@" @">", self.class, self.fileName, _compressionMethod, _compressedSize, _uncompressedSize, _modificationDate, _headerLevel, _CRC16, _operatingSystemIdentifier, _fileComment, POSIXPermissions, _ownerAccountID, _groupOwnerAccountID, _ownerAccountName, _groupOwnerAccountName, extensions]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end |
Modified src/OFLocale.h from [fcc8f077d2] to [ca12b9c93f].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | * @def OF_LOCALIZED * * @brief Returns the localized string for the specified ID with the specified * arguments inserted. * * @param ID The ID of the localized string to retrieve * @return The localized string with the specified arguments replaced */ #define OF_LOCALIZED(ID, ...) \ [[OFLocale currentLocale] localizedStringForID: ID \ fallback: __VA_ARGS__, nil] @class OFMutableArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @class OFLocale OFLocale.h ObjFW/OFLocale.h * * @brief A class for querying the locale and retrieving localized strings. */ OF_SUBCLASSING_RESTRICTED @interface OFLocale: OFObject { | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | * @def OF_LOCALIZED * * @brief Returns the localized string for the specified ID with the specified * arguments inserted. * * @param ID The ID of the localized string to retrieve * @return The localized string with the specified arguments replaced * @throw OFInvalidFormatException The string (either the fallback or the * localized one) contains an invalid format */ #define OF_LOCALIZED(ID, ...) \ [[OFLocale currentLocale] localizedStringForID: ID \ fallback: __VA_ARGS__, nil] @class OFMutableArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @class OFLocale OFLocale.h ObjFW/OFLocale.h * * @brief A class for querying the locale and retrieving localized strings. */ OF_SUBCLASSING_RESTRICTED @interface OFLocale: OFObject { OFString *_Nullable _languageCode, *_Nullable _countryCode; OFStringEncoding _encoding; OFString *_decimalSeparator; OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *) *_localizedStrings; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFLocale *currentLocale; @property (class, readonly, nullable, nonatomic) OFString *languageCode; @property (class, readonly, nullable, nonatomic) OFString *countryCode; @property (class, readonly, nonatomic) OFStringEncoding encoding; @property (class, readonly, nullable, nonatomic) OFString *decimalSeparator; #endif /** * @brief The language code of the locale for messages. * * If the language is unknown, it is `nil`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *languageCode; /** * @brief The country code of the locale for messages. * * If the territory is unknown, it is `nil`. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *countryCode; /** * @brief The native 8-bit string encoding of the locale for messages. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. */ @property (readonly, nonatomic) OFStringEncoding encoding; /** * @brief The decimal separator of the locale. */ @property (readonly, nonatomic) OFString *decimalSeparator; /** * @brief Returns the current OFLocale. * * @warning If you don't use @ref OFApplication, this might be `nil`! In this * case, you need to manually allocate an instance and call * @ref init once. * * @return The current OFLocale instance */ + (nullable OFLocale *)currentLocale; /** * @brief Returns the language code of the locale. * * If the language is unknown, `nil` is returned. * * @return The language code of the locale. */ + (nullable OFString *)languageCode; /** * @brief Returns the country code of the locale. * * If the country is unknown, `nil` is returned. * * @return The country code of the locale. */ + (nullable OFString *)countryCode; /** * @brief Returns the native 8-bit string encoding for the locale. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. * * @return The native 8-bit string encoding for the locale */ + (OFStringEncoding)encoding; /** * @brief Returns the decimal point of the system's locale. * * @return The decimal point of the system's locale */ + (nullable OFString *)decimalSeparator; #ifdef OF_HAVE_FILES /** * @brief Adds a directory to scan for localizations. * * @param path The path to the directory to scan for localizations */ + (void)addLocalizationDirectory: (OFString *)path; #endif /** * @brief Initializes the current OFLocale. * * @warning This sets the locale via `setlocale()`! * * @warning You should never call this yourself, except if you do not use * @ref OFApplication. In this case, you need to allocate exactly one * instance of OFLocale, which will become the current locale, and * call this method. */ - (instancetype)init; #ifdef OF_HAVE_FILES /** * @brief Adds a directory to scan for localizations. * * @param path The path to the directory to scan for localizations */ - (void)addLocalizationDirectory: (OFString *)path; #endif /** * @brief Returns the localized string for the specified ID, using the fallback * string if it cannot be looked up or is missing. * * @note This takes a variadic argument, terminated by `nil`, that consists of * pairs of variable names and variable values, which will be replaced * inside the localized string. For example, you can pass * `@"name", @"foo", nil`, causing `%[name]` to be replaced with `foo` in * the localized string. * * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes * care of the `nil` sentinel automatically. * * @param ID The ID for the localized string * @param fallback The fallback to use in case the localized string cannot be * looked up or is missing. This can also be an array and use * plural scripting, just like with the JSON localization files. * @return The localized string */ - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... OF_SENTINEL; /** * @brief Returns the localized string for the specified ID, using the fallback |
︙ | ︙ | |||
200 201 202 203 204 205 206 | * * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes * care of the `nil` sentinel automatically. * * @param ID The ID for the localized string * @param fallback The fallback to use in case the localized string cannot be * looked up or is missing. This can also be an array and use | | > > | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | * * @note Generally, you want to use @ref OF_LOCALIZED instead, which also takes * care of the `nil` sentinel automatically. * * @param ID The ID for the localized string * @param fallback The fallback to use in case the localized string cannot be * looked up or is missing. This can also be an array and use * plural scripting, just like with the JSON localization files. * @param arguments A va_list of arguments, consisting of pairs of variable * names and values to replace in the localized string, * terminated with `nil` * @return The localized string * @throw OFInvalidFormatException The string (either the fallback or the * localized one) contains an invalid format */ - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback arguments: (va_list)arguments; @end OF_ASSUME_NONNULL_END |
Modified src/OFLocale.m from [ccac2d9a08] to [e8b5569b76].
︙ | ︙ | |||
36 37 38 39 40 41 42 | static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; #ifndef OF_AMIGAOS static void parseLocale(char *locale, OFStringEncoding *encoding, | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; #ifndef OF_AMIGAOS static void parseLocale(char *locale, OFStringEncoding *encoding, OFString **languageCode, OFString **countryCode) { locale = OFStrDup(locale); @try { OFStringEncoding enc = OFStringEncodingASCII; char *tmp; |
︙ | ︙ | |||
61 62 63 64 65 66 67 | *encoding = OFStringEncodingParseName( [OFString stringWithCString: tmp encoding: enc]); } @catch (OFInvalidArgumentException *e) { } } | | | > | | | | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | *encoding = OFStringEncodingParseName( [OFString stringWithCString: tmp encoding: enc]); } @catch (OFInvalidArgumentException *e) { } } /* Country code */ if ((tmp = strrchr(locale, '_')) != NULL) { *tmp++ = '\0'; if (countryCode != NULL) *countryCode = [OFString stringWithCString: tmp encoding: enc]; } if (languageCode != NULL) *languageCode = [OFString stringWithCString: locale encoding: enc]; } @finally { OFFreeMemory(locale); } } #endif static bool |
︙ | ︙ | |||
299 300 301 302 303 304 305 | [string makeImmutable]; return string; } @implementation OFLocale | | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | [string makeImmutable]; return string; } @implementation OFLocale @synthesize languageCode = _languageCode, countryCode = _countryCode; @synthesize encoding = _encoding, decimalSeparator = _decimalSeparator; + (void)initialize { OFNumber *one, *two, *three, *four; if (self != [OFLocale class]) return; |
︙ | ︙ | |||
336 337 338 339 340 341 342 | } + (OFLocale *)currentLocale { return currentLocale; } | | | | | | | | | | | | | | | 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | } + (OFLocale *)currentLocale { return currentLocale; } + (OFString *)languageCode { return currentLocale.languageCode; } + (OFString *)countryCode { return currentLocale.countryCode; } + (OFStringEncoding)encoding { return currentLocale.encoding; } + (OFString *)decimalSeparator { return currentLocale.decimalSeparator; } #ifdef OF_HAVE_FILES + (void)addLocalizationDirectory: (OFString *)path { [currentLocale addLocalizationDirectory: path]; } #endif - (instancetype)init { self = [super init]; @try { #ifndef OF_AMIGAOS char *locale, *messagesLocale = NULL; if (currentLocale != nil) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _encoding = OFStringEncodingUTF8; _decimalSeparator = @"."; _localizedStrings = [[OFMutableArray alloc] init]; if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalSeparator = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; # ifdef LC_MESSAGES messagesLocale = setlocale(LC_MESSAGES, ""); # endif if (messagesLocale == NULL) messagesLocale = locale; if (messagesLocale != NULL) { void *pool = objc_autoreleasePoolPush(); parseLocale(messagesLocale, &_encoding, &_languageCode, &_countryCode); [_languageCode retain]; [_countryCode retain]; objc_autoreleasePoolPop(pool); } #else void *pool = objc_autoreleasePoolPush(); char buffer[32]; struct Locale *locale; |
︙ | ︙ | |||
435 436 437 438 439 440 441 | } else _encoding = OFStringEncodingISO8859_1; /* * Get it via localeconv() instead of from the Locale struct, * to make sure we and printf etc. have the same expectations. */ | | | | | | | | | 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | } else _encoding = OFStringEncodingISO8859_1; /* * Get it via localeconv() instead of from the Locale struct, * to make sure we and printf etc. have the same expectations. */ _decimalSeparator = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; _localizedStrings = [[OFMutableArray alloc] init]; if (GetVar("Language", buffer, sizeof(buffer), 0) > 0) _languageCode = [[OFString alloc] initWithCString: buffer encoding: _encoding]; if ((locale = OpenLocale(NULL)) != NULL) { @try { uint32_t countryCode; size_t length; countryCode = OFToBigEndian32(locale->loc_CountryCode); for (length = 0; length < 4; length++) if (((char *)&countryCode)[length] == 0) break; _countryCode = [[OFString alloc] initWithCString: (char *)&countryCode encoding: _encoding length: length]; } @finally { CloseLocale(locale); } } |
︙ | ︙ | |||
481 482 483 484 485 486 487 | currentLocale = self; return self; } - (void)dealloc { | | | | | | | | | | | | | > | | > | | | | | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | currentLocale = self; return self; } - (void)dealloc { [_languageCode release]; [_countryCode release]; [_decimalSeparator release]; [_localizedStrings release]; [super dealloc]; } #ifdef OF_HAVE_FILES - (void)addLocalizationDirectory: (OFString *)path { void *pool; OFString *mapPath, *languageCode, *countryCode, *localizationFile; OFDictionary *map; if (_languageCode == nil) return; pool = objc_autoreleasePoolPush(); mapPath = [path stringByAppendingPathComponent: @"localizations.json"]; @try { map = [[OFString stringWithContentsOfFile: mapPath] objectByParsingJSON]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } languageCode = _languageCode.lowercaseString; countryCode = _countryCode.lowercaseString; if (countryCode == nil) countryCode = @""; localizationFile = [[map objectForKey: languageCode] objectForKey: countryCode]; if (localizationFile == nil) localizationFile = [[map objectForKey: languageCode] objectForKey: @""]; if (localizationFile == nil) { objc_autoreleasePoolPop(pool); return; } localizationFile = [path stringByAppendingPathComponent: [localizationFile stringByAppendingString: @".json"]]; [_localizedStrings addObject: [[OFString stringWithContentsOfFile: localizationFile] objectByParsingJSON]]; objc_autoreleasePoolPop(pool); } #endif - (OFString *)localizedStringForID: (OFConstantString *)ID fallback: (id)fallback, ... |
︙ | ︙ |
Modified src/OFLocking.h from [ae2e49ea45] to [155544ed9e].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | /** * @brief The name of the lock. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name; /** * @brief Locks the lock. */ - (void)lock; /** * @brief Tries to lock the lock. * * @return A boolean whether the lock could be locked */ - (bool)tryLock; /** * @brief Unlocks the lock. */ - (void)unlock; @end OF_ASSUME_NONNULL_END | > > > > > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | /** * @brief The name of the lock. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name; /** * @brief Locks the lock. * * @throw OFLockFailedException Acquiring the lock failed */ - (void)lock; /** * @brief Tries to lock the lock. * * @return A boolean whether the lock could be locked * * @throw OFLockFailedException The lock could not be acquired for another * reason than it already being held */ - (bool)tryLock; /** * @brief Unlocks the lock. * * @throw OFUnlockFailedException Releasing the lock failed */ - (void)unlock; @end OF_ASSUME_NONNULL_END |
Modified src/OFMapTable.h from [db5052bd42] to [382835ac81].
︙ | ︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 | /** * @class OFMapTableEnumerator OFMapTable.h ObjFW/OFMapTable.h * * @brief A class which provides methods to enumerate through an OFMapTable's * keys or objects. */ @interface OFMapTableEnumerator: OFObject { OFMapTable *_mapTable; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; uint32_t _capacity; unsigned long _mutations, *_Nullable _mutationsPtr, _position; } | > > > | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | /** * @class OFMapTableEnumerator OFMapTable.h ObjFW/OFMapTable.h * * @brief A class which provides methods to enumerate through an OFMapTable's * keys or objects. */ #ifndef OF_MAP_TABLE_M OF_SUBCLASSING_RESTRICTED #endif @interface OFMapTableEnumerator: OFObject { OFMapTable *_mapTable; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; uint32_t _capacity; unsigned long _mutations, *_Nullable _mutationsPtr, _position; } |
︙ | ︙ |
Modified src/OFMapTable.m from [155910f8b1] to [61602c79fe].
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | * 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 <stdlib.h> #include <string.h> #include <assert.h> | > > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * 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. */ #define OF_MAP_TABLE_M #include "config.h" #include <stdlib.h> #include <string.h> #include <assert.h> |
︙ | ︙ |
Modified src/OFMemoryStream.m from [1697ea3e2b] to [d9d07c7da0].
︙ | ︙ | |||
42 43 44 45 46 47 48 | - (instancetype)initWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable { self = [super init]; @try { | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | - (instancetype)initWithMemoryAddress: (void *)address size: (size_t)size writable: (bool)writable { self = [super init]; @try { if (size > SSIZE_MAX || (ssize_t)size != (OFStreamOffset)size) @throw [OFOutOfRangeException exception]; _address = address; _size = size; _writable = writable; } @catch (id e) { [self release]; |
︙ | ︙ | |||
97 98 99 100 101 102 103 | } - (bool)lowlevelIsAtEndOfStream { return (_position == _size); } | | > | | | | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | } - (bool)lowlevelIsAtEndOfStream { return (_position == _size); } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OFStreamOffset new; switch (whence) { case OFSeekSet: new = offset; break; case OFSeekCurrent: new = (OFStreamOffset)_position + offset; break; case OFSeekEnd: new = (OFStreamOffset)_size + offset; break; default: @throw [OFInvalidArgumentException exception]; } if (new < 0 || new > (OFStreamOffset)_size) @throw [OFSeekFailedException exceptionWithStream: self offset: offset whence: whence errNo: EINVAL]; return (_position = (size_t)new); } @end |
Modified src/OFMessagePackExtension.h from [45f0ba641f] to [99c89d24f1].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 | /** * @class OFMessagePackExtension \ * OFMessagePackExtension.h ObjFW/OFMessagePackExtension.h * * @brief A class for representing the MessagePack extension type. */ @interface OFMessagePackExtension: OFObject <OFMessagePackRepresentation, OFCopying> { int8_t _type; OFData *_data; | > < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /** * @class OFMessagePackExtension \ * OFMessagePackExtension.h ObjFW/OFMessagePackExtension.h * * @brief A class for representing the MessagePack extension type. */ OF_SUBCLASSING_RESTRICTED @interface OFMessagePackExtension: OFObject <OFMessagePackRepresentation, OFCopying> { int8_t _type; OFData *_data; } /** * @brief The MessagePack extension type. */ @property (readonly, nonatomic) int8_t type; |
︙ | ︙ |
Modified src/OFMessagePackExtension.m from [7009717fd9] to [a3971287d8].
︙ | ︙ | |||
170 171 172 173 174 175 176 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, (uint8_t)_type); OFHashAddHash(&hash, _data.hash); OFHashFinalize(&hash); return hash; } |
︙ | ︙ |
Modified src/OFMethodSignature.h from [6c7eab90df] to [996cafd8b2].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 | @class OFMutableData; /** * @class OFMethodSignature OFMethodSignature.h ObjFW/OFMethodSignature.h * * @brief A class for parsing type encodings and accessing them. */ @interface OFMethodSignature: OFObject { char *_types; OFMutableData *_typesPointers, *_offsets; | > < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | @class OFMutableData; /** * @class OFMethodSignature OFMethodSignature.h ObjFW/OFMethodSignature.h * * @brief A class for parsing type encodings and accessing them. */ OF_SUBCLASSING_RESTRICTED @interface OFMethodSignature: OFObject { char *_types; OFMutableData *_typesPointers, *_offsets; } /** * @brief The number of arguments of the method. */ @property (readonly, nonatomic) size_t numberOfArguments; |
︙ | ︙ | |||
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | @property (readonly, nonatomic) size_t frameLength; /** * @brief Creates a new OFMethodSignature with the specified ObjC types. * * @param types The ObjC types of the method * @return A new, autoreleased OFMethodSignature */ + (instancetype)signatureWithObjCTypes: (const char *)types; /** * @brief Initializes an already allocated OFMethodSignature with the specified * ObjC types. * * @param types The ObjC types of the method * @return An Initialized OFMethodSignature */ - (instancetype)initWithObjCTypes: (const char *)types; /** * @brief Returns the ObjC type for the argument at the specified index. * * @param index The index of the argument for which to return the ObjC type | > > | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | @property (readonly, nonatomic) size_t frameLength; /** * @brief Creates a new OFMethodSignature with the specified ObjC types. * * @param types The ObjC types of the method * @return A new, autoreleased OFMethodSignature * @throw OFInvalidFormatException The type encoding is invalid */ + (instancetype)signatureWithObjCTypes: (const char *)types; /** * @brief Initializes an already allocated OFMethodSignature with the specified * ObjC types. * * @param types The ObjC types of the method * @return An Initialized OFMethodSignature * @throw OFInvalidFormatException The type encoding is invalid */ - (instancetype)initWithObjCTypes: (const char *)types; /** * @brief Returns the ObjC type for the argument at the specified index. * * @param index The index of the argument for which to return the ObjC type |
︙ | ︙ | |||
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | extern "C" { #endif /** * @brief Returns the size for the specified type encoding. * * @param type The type encoding to return the size for * @return The size for the specified type encoding */ extern size_t OFSizeOfTypeEncoding(const char *type); /** * @brief Returns the alignment for the specified type encoding. * * @param type The type encoding to return the alignment for * @return The alignment for the specified type encoding */ extern size_t OFAlignmentOfTypeEncoding(const char *type); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END | > > | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | extern "C" { #endif /** * @brief Returns the size for the specified type encoding. * * @param type The type encoding to return the size for * @return The size for the specified type encoding * @throw OFInvalidFormatException The type encoding is invalid */ extern size_t OFSizeOfTypeEncoding(const char *type); /** * @brief Returns the alignment for the specified type encoding. * * @param type The type encoding to return the alignment for * @return The alignment for the specified type encoding * @throw OFInvalidFormatException The type encoding is invalid */ extern size_t OFAlignmentOfTypeEncoding(const char *type); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Added src/OFMutableArchiveEntry.h version [ffb170561c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFMutableArchiveEntry \ * OFMutableArchiveEntry.h ObjFW/OFMutableArchiveEntry.h * * @brief A class which represents a mutable entry in an archive. */ @protocol OFMutableArchiveEntry <OFArchiveEntry> /** * @brief The file name of the entry. */ @property (readwrite, copy, nonatomic) OFString *fileName; /** * @brief The compressed size of the entry's file. */ @property (readwrite, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ @property (readwrite, nonatomic) unsigned long long uncompressedSize; @optional /** * @brief The modification date of the file. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; /** * @brief The comment of the entry's file. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *fileComment; /** * @brief The POSIX permissions of the file. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *POSIXPermissions; /** * @brief The file owner's account ID. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *ownerAccountID; /** * @brief The file owner's group account ID. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *groupOwnerAccountID; /** * @brief The file owner's account name. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFString *ownerAccountName; /** * @brief The file owner's group account name. */ @property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFString *groupOwnerAccountName; @end OF_ASSUME_NONNULL_END #import "OFMutableArchiveEntry.h" |
Modified src/OFMutableArray.m from [8e711f8f4a] to [ba1c079bde].
︙ | ︙ | |||
377 378 379 380 381 382 383 | return; [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { | | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | return; [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { [self removeObjectsInRange: OFMakeRange(0, self.count)]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { |
︙ | ︙ |
Modified src/OFMutableData.h from [5eba71457e] to [23548715da].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN @class OFString; | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #import "OFData.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFURI; /** * @class OFMutableData OFMutableData.h ObjFW/OFMutableData.h * * @brief A class for storing and manipulating arbitrary data in an array. */ @interface OFMutableData: OFData |
︙ | ︙ | |||
200 201 202 203 204 205 206 | /** * @brief Removes all items. */ - (void)removeAllItems; /** | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 | /** * @brief Removes all items. */ - (void)removeAllItems; /** * @brief Converts the mutable data to an immutable data. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableData.m from [2aa51e2819] to [b4151ce5ed].
︙ | ︙ | |||
240 241 242 243 244 245 246 | memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; } - (void)removeItemAtIndex: (size_t)idx { | | | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; } - (void)removeItemAtIndex: (size_t)idx { [self removeItemsInRange: OFMakeRange(idx, 1)]; } - (void)removeItemsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; |
︙ | ︙ |
Modified src/OFMutableLHAArchiveEntry.h from [4253f691f5] to [5bfb2f1e47].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * 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 "OFLHAArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableLHAArchiveEntry \ * OFMutableLHAArchiveEntry.h ObjFW/OFMutableLHAArchiveEntry.h * * @brief A class which represents a mutable entry in an LHA archive. */ | > | < < < < < < < < < < < < < < < < < < < < | | < | < < | < < < < | < < < < | < < | | < < | < < < < < | < | > < > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | * 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 "OFLHAArchiveEntry.h" #import "OFMutableArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableLHAArchiveEntry \ * OFMutableLHAArchiveEntry.h ObjFW/OFMutableLHAArchiveEntry.h * * @brief A class which represents a mutable entry in an LHA archive. */ @interface OFMutableLHAArchiveEntry: OFLHAArchiveEntry <OFMutableArchiveEntry> { OF_RESERVE_IVARS(OFMutableLHAArchiveEntry, 4) } /** * @brief The compression method of the entry. */ @property (readwrite, copy, nonatomic) OFString *compressionMethod; /** * @brief The LHA level of the file. */ @property (readwrite, nonatomic) uint8_t headerLevel; /** * @brief The CRC16 of the file. */ @property (readwrite, nonatomic) uint16_t CRC16; /** * @brief The operating system identifier of the file. */ @property (readwrite, nonatomic) uint8_t operatingSystemIdentifier; /** * @brief The LHA extensions of the file. */ @property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions; /** * @brief Creates a new OFMutableLHAArchiveEntry with the specified file name. * * @param fileName The file name for the OFLHAArchiveEntry * @return A new, autoreleased OFLHAArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableLHAArchiveEntry with the * specified file name. * * @param fileName The file name for the OFLHAArchiveEntry * @return An initialized OFLHAArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableLHAArchiveEntry to an immutable * OFLHAArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableLHAArchiveEntry.m from [8d9a6a0cb1] to [84adbb8df8].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFMutableLHAArchiveEntry.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableLHAArchiveEntry | > | | > > | > > > > > > > > > > > > > > > > > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFMutableLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableLHAArchiveEntry @dynamic fileName, compressionMethod, compressedSize, uncompressedSize; @dynamic modificationDate, headerLevel, CRC16, operatingSystemIdentifier; @dynamic fileComment, POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic ownerAccountName, groupOwnerAccountName, extensions; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { _fileName = [fileName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableLHAArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; |
︙ | ︙ | |||
50 51 52 53 54 55 56 | - (void)setCompressionMethod: (OFString *)compressionMethod { OFString *old = _compressionMethod; _compressionMethod = [compressionMethod copy]; [old release]; } | | | | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | - (void)setCompressionMethod: (OFString *)compressionMethod { OFString *old = _compressionMethod; _compressionMethod = [compressionMethod copy]; [old release]; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; } - (void)setHeaderLevel: (uint8_t)headerLevel { _headerLevel = headerLevel; } |
︙ | ︙ | |||
89 90 91 92 93 94 95 | - (void)setFileComment: (OFString *)fileComment { OFString *old = _fileComment; _fileComment = [fileComment copy]; [old release]; } | | | | | | | < < < < < < | | < | | | | | | | | | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | - (void)setFileComment: (OFString *)fileComment { OFString *old = _fileComment; _fileComment = [fileComment copy]; [old release]; } - (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions { OFNumber *old = _POSIXPermissions; _POSIXPermissions = [POSIXPermissions retain]; [old release]; } - (void)setOwnerAccountID: (OFNumber *)ownerAccountID { OFNumber *old = _ownerAccountID; _ownerAccountID = [ownerAccountID retain]; [old release]; } - (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID { OFNumber *old = _groupOwnerAccountID; _groupOwnerAccountID = [groupOwnerAccountID retain]; [old release]; } - (void)setOwnerAccountName: (OFString *)ownerAccountName { OFString *old = _ownerAccountName; _ownerAccountName = [ownerAccountName copy]; [old release]; } - (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName { OFString *old = _groupOwnerAccountName; _groupOwnerAccountName = [groupOwnerAccountName copy]; [old release]; } - (void)setExtensions: (OFArray OF_GENERIC(OFData *) *)extensions { OFArray OF_GENERIC(OFData *) *old = _extensions; _extensions = [extensions copy]; |
︙ | ︙ |
Modified src/OFMutableString.h from [9300a1f2cf] to [f372a7a142].
︙ | ︙ | |||
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | */ - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append */ - (void)appendUTF8String: (const char *)UTF8String; /** * @brief Appends a UTF-8 encoded C string with the specified length to the * OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append * @param UTF8StringLength The length of the UTF-8 encoded C string */ - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** * @brief Appends a C string with the specified encoding to the OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Appends a C string with the specified encoding and length to the * OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Appends a formatted string to the OFMutableString. * * See `printf` for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append */ - (void)appendFormat: (OFConstantString *)format, ...; /** * @brief Appends a formatted string to the OFMutableString. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string */ - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments; | > > > > > > > > > > > > < < < < < < < < < < < < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | */ - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendUTF8String: (const char *)UTF8String; /** * @brief Appends a UTF-8 encoded C string with the specified length to the * OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append * @param UTF8StringLength The length of the UTF-8 encoded C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength; /** * @brief Appends a C string with the specified encoding to the OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Appends a C string with the specified encoding and length to the * OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string * @throw OFInvalidEncodingException The C string is not in not in the correct * encoding */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Appends a formatted string to the OFMutableString. * * See `printf` for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @throw OFInvalidFormatException The specified format is invalid * @throw OFInvalidEncodingException The resulting string is not in not in UTF-8 * encoding */ - (void)appendFormat: (OFConstantString *)format, ...; /** * @brief Appends a formatted string to the OFMutableString. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string * @throw OFInvalidFormatException The specified format is invalid */ - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments; /** * @brief Converts the string to uppercase. */ - (void)uppercase; /** * @brief Converts the string to lowercase. |
︙ | ︙ |
Modified src/OFMutableString.m from [a015aada74] to [eb3bef8a08].
︙ | ︙ | |||
170 171 172 173 174 175 176 | { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif | | | | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI { return (id)[[OFMutableUTF8String alloc] initWithContentsOfURI: URI]; } - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithContentsOfURI: URI encoding: encoding]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { return (id)[[OFMutableUTF8String alloc] initWithSerialization: element]; } |
︙ | ︙ | |||
285 286 287 288 289 290 291 | #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithCharacters: &character length: 1]; | | | 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithCharacters: &character length: 1]; [self replaceCharactersInRange: OFMakeRange(idx, 1) withString: string]; objc_autoreleasePoolPop(pool); } - (void)appendString: (OFString *)string { [self insertString: string atIndex: self.length]; } |
︙ | ︙ | |||
368 369 370 371 372 373 374 | @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } | < < < < < < < < < < < < < < < < | 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } #ifdef OF_HAVE_UNICODE_TABLES - (void)uppercase { [self of_convertWithWordStartTable: OFUnicodeUppercaseTable wordMiddleTable: OFUnicodeUppercaseTable wordStartTableSize: OFUnicodeUppercaseTableSize wordMiddleTableSize: OFUnicodeUppercaseTableSize]; |
︙ | ︙ | |||
427 428 429 430 431 432 433 | { convert(self, OFASCIIToUpper, OFASCIIToLower); } #endif - (void)insertString: (OFString *)string atIndex: (size_t)idx { | | | | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | { convert(self, OFASCIIToUpper, OFASCIIToLower); } #endif - (void)insertString: (OFString *)string atIndex: (size_t)idx { [self replaceCharactersInRange: OFMakeRange(idx, 0) withString: string]; } - (void)deleteCharactersInRange: (OFRange)range { [self replaceCharactersInRange: range withString: @""]; } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement { OF_UNRECOGNIZED_SELECTOR } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self replaceOccurrencesOfString: string withString: replacement options: 0 range: OFMakeRange(0, self.length)]; } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { |
︙ | ︙ | |||
481 482 483 484 485 486 487 | characters = self.characters; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) != 0) continue; | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | characters = self.characters; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) != 0) continue; [self replaceCharactersInRange: OFMakeRange(i, searchLength) withString: replacement]; range.length -= searchLength; range.length += replacementLength; i += replacementLength - 1; |
︙ | ︙ | |||
513 514 515 516 517 518 519 | if (!OFASCIIIsSpace(c)) break; } objc_autoreleasePoolPop(pool); | | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | if (!OFASCIIIsSpace(c)) break; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFMakeRange(0, i)]; } - (void)deleteTrailingWhitespaces { void *pool; const OFUnichar *characters, *p; size_t length, d; |
︙ | ︙ | |||
540 541 542 543 544 545 546 | break; d++; } objc_autoreleasePoolPop(pool); | | | 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | break; d++; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFMakeRange(length - d, d)]; } - (void)deleteEnclosingWhitespaces { [self deleteLeadingWhitespaces]; [self deleteTrailingWhitespaces]; } |
︙ | ︙ |
Modified src/OFMutableTarArchiveEntry.h from [f3b4444a50] to [d5cbafa370].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * 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 "OFTarArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableTarArchiveEntry \ * OFMutableTarArchiveEntry.h ObjFW/OFMutableTarArchiveEntry.h * * @brief A class which represents a mutable entry of a tar archive. */ | > | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > > > > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | * 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 "OFTarArchiveEntry.h" #import "OFMutableArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableTarArchiveEntry \ * OFMutableTarArchiveEntry.h ObjFW/OFMutableTarArchiveEntry.h * * @brief A class which represents a mutable entry of a tar archive. */ @interface OFMutableTarArchiveEntry: OFTarArchiveEntry <OFMutableArchiveEntry> { OF_RESERVE_IVARS(OFMutableTarArchiveEntry, 4) } /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readwrite, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *targetFileName; /** * @brief The device major (if the file is a device). */ @property (readwrite, nonatomic) unsigned long deviceMajor; /** * @brief The device major (if the file is a device). */ @property (readwrite, nonatomic) unsigned long deviceMinor; /** * @brief Creates a new OFMutableTarArchiveEntry with the specified file name. * * @param fileName The file name for the OFTarArchiveEntry * @return A new, autoreleased OFTarArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableTarArchiveEntry with the * specified file name. * * @param fileName The file name for the OFTarArchiveEntry * @return An initialized OFTarArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableTarArchiveEntry to an immutable * OFTarArchiveEntry. */ - (void)makeImmutable; @end |
︙ | ︙ |
Modified src/OFMutableTarArchiveEntry.m from [bfb188d370] to [f1fcc51707].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFMutableTarArchiveEntry.h" | > | | > > > > > | > > > > | > > > > > > > > > > > > > | | > > | > > > > | > > > > > | | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFMutableTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFNumber.h" #import "OFString.h" @implementation OFMutableTarArchiveEntry @dynamic fileName, POSIXPermissions, ownerAccountID, groupOwnerAccountID; @dynamic compressedSize, uncompressedSize, modificationDate, type; @dynamic targetFileName, ownerAccountName, groupOwnerAccountName, deviceMajor; @dynamic deviceMinor; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { _fileName = [fileName copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableTarArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setFileName: (OFString *)fileName { OFString *old = _fileName; _fileName = [fileName copy]; [old release]; } - (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions { OFNumber *old = _POSIXPermissions; _POSIXPermissions = [POSIXPermissions retain]; [old release]; } - (void)setOwnerAccountID: (OFNumber *)ownerAccountID { OFNumber *old = _ownerAccountID; _ownerAccountID = [ownerAccountID retain]; [old release]; } - (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID { OFNumber *old = _groupOwnerAccountID; _groupOwnerAccountID = [groupOwnerAccountID retain]; [old release]; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; |
︙ | ︙ | |||
74 75 76 77 78 79 80 | - (void)setTargetFileName: (OFString *)targetFileName { OFString *old = _targetFileName; _targetFileName = [targetFileName copy]; [old release]; } | | | | | | | | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | - (void)setTargetFileName: (OFString *)targetFileName { OFString *old = _targetFileName; _targetFileName = [targetFileName copy]; [old release]; } - (void)setOwnerAccountName: (OFString *)ownerAccountName { OFString *old = _ownerAccountName; _ownerAccountName = [ownerAccountName copy]; [old release]; } - (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName { OFString *old = _groupOwnerAccountName; _groupOwnerAccountName = [groupOwnerAccountName copy]; [old release]; } - (void)setDeviceMajor: (unsigned long)deviceMajor { _deviceMajor = deviceMajor; } |
︙ | ︙ |
Renamed and modified src/OFMutableURL.h [28e4adf533] to src/OFMutableURI.h [9400cfdc05].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * 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. */ | | | | > | | | < < | < | | < < | < | | > > > | | | | > > > | | | | > > > | | | | | > > > | | | | | | > > > | < | > > > | | | | | > > > | | | | | | | > > | | | | | > > > | | > | | > > > > > > > > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | * * 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 "OFURI.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableURI OFMutableURI.h ObjFW/OFMutableURI.h * * @brief A class for parsing URIs as per RFC 3986 and accessing and modifying * parts of it. */ @interface OFMutableURI: OFURI { OF_RESERVE_IVARS(OFMutableURI, 4) } /** * @brief The scheme part of the URI. * * @throw OFInvalidFormatException The scheme being set is not in the correct * format */ @property (readwrite, copy, nonatomic) OFString *scheme; /** * @brief The host part of the URI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *host; /** * @brief The host part of the URI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The host being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedHost; /** * @brief The port part of the URI. * * @throw OFInvalidArgumentException The port is not valid (e.g. negative or * too big) */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFNumber *port; /** * @brief The user part of the URI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *user; /** * @brief The user part of the URI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The user being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedUser; /** * @brief The password part of the URI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *password; /** * @brief The password part of the URI in URI-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The password being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedPassword; /** * @brief The path part of the URI. */ @property (readwrite, copy, nonatomic) OFString *path; /** * @brief The path part of the URI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The path being set is not in the correct * format */ @property (readwrite, copy, nonatomic) OFString *percentEncodedPath; /** * @brief The path of the URI split into components. * * The first component must always be empty to designate the root. * * @throw OFInvalidFormatException The path components being set are not in the * correct format */ @property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /** * @brief The query part of the URI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *query; /** * @brief The query part of the URI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The query being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedQuery; /** * @brief The query part of the URI as an array. * * For example, a query like `key1=value1&key2=value2` would correspond to the * following array: * * @[ * [OFPair pairWithFirstObject: @"key1" secondObject: @"value1"], * [OFPair pairWithFirstObject: @"key2" secondObject: @"value2"], * ] * * @throw OFInvalidFormatException The query is not in the correct format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems; /** * @brief The fragment part of the URI. */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *fragment; /** * @brief The fragment part of the URI in percent-encoded form. * * Setting this retains the original percent-encoding used - if more characters * than necessary are percent-encoded, it is kept this way. * * @throw OFInvalidFormatException The fragment being set is not in the correct * format */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *percentEncodedFragment; /** * @brief Creates a new mutable URI with the specified schemed. * * @param scheme The scheme for the URI * @return A new, autoreleased OFMutableURI */ + (instancetype)URIWithScheme: (OFString *)scheme; /** * @brief Initializes an already allocated mutable URI with the specified * schemed. * * @param scheme The scheme for the URI * @return An initialized OFMutableURI */ - (instancetype)initWithScheme: (OFString *)scheme; /** * @brief Appends the specified path component. * * @param component The component to append */ - (void)appendPathComponent: (OFString *)component; |
︙ | ︙ | |||
178 179 180 181 182 183 184 | /** * @brief Resolves relative subpaths. */ - (void)standardizePath; /** | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 | /** * @brief Resolves relative subpaths. */ - (void)standardizePath; /** * @brief Converts the mutable URI to an immutable URI. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFMutableURL.m [ce9685e8ce] to src/OFMutableURI.m [375c07c449].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | > > > | | | | | | | > > > > > > > > > > > > > > > | > > | > | > > < < < < < < < < < < < < < | | | | | | | | | | | | | | | | > > > > | > | | | | | | | | | | | | | | | | | | | > | | | < | | | | < < < < < | | > > > > | > | | | | | | | | | | > | < | | | | | < < | < < > | | > | | > | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | < < < < < | < < < > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | * 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 "OFMutableURI.h" #import "OFURI+Private.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFileManager.h" #endif #import "OFNumber.h" #import "OFPair.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" @implementation OFMutableURI @dynamic scheme, host, percentEncodedHost, port, user, percentEncodedUser; @dynamic password, percentEncodedPassword, path, percentEncodedPath; @dynamic pathComponents, query, percentEncodedQuery, queryItems, fragment; @dynamic percentEncodedFragment; + (instancetype)URIWithScheme: (OFString *)scheme { return [[[self alloc] initWithScheme: scheme] autorelease]; } - (instancetype)initWithScheme: (OFString *)scheme { self = [super of_init]; @try { self.scheme = scheme; _percentEncodedPath = @""; } @catch (id e) { [self release]; @throw e; } return self; } - (void)setScheme: (OFString *)scheme { void *pool = objc_autoreleasePoolPush(); OFString *old = _scheme; if (scheme.length < 1 || !OFASCIIIsAlpha(*scheme.UTF8String)) @throw [OFInvalidFormatException exception]; OFURIVerifyIsEscaped(scheme, [OFCharacterSet URISchemeAllowedCharacterSet], false); _scheme = [scheme.lowercaseString copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setHost: (OFString *)host { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedHost; if (OFURIIsIPv6Host(host)) _percentEncodedHost = [[OFString alloc] initWithFormat: @"[%@]", host]; else _percentEncodedHost = [[host stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIHostAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedHost: (OFString *)percentEncodedHost { OFString *old; if ([percentEncodedHost hasPrefix: @"["] && [percentEncodedHost hasSuffix: @"]"]) { if (!OFURIIsIPv6Host([percentEncodedHost substringWithRange: OFMakeRange(1, percentEncodedHost.length - 2)])) @throw [OFInvalidFormatException exception]; } else if (percentEncodedHost != nil) OFURIVerifyIsEscaped(percentEncodedHost, [OFCharacterSet URIHostAllowedCharacterSet], true); old = _percentEncodedHost; _percentEncodedHost = [percentEncodedHost copy]; [old release]; } - (void)setPort: (OFNumber *)port { OFNumber *old = _port; if (port.longLongValue < 0 || port.longLongValue > 65535) @throw [OFInvalidArgumentException exception]; _port = [port copy]; [old release]; } - (void)setUser: (OFString *)user { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedUser; _percentEncodedUser = [[user stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIUserAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedUser: (OFString *)percentEncodedUser { OFString *old; if (percentEncodedUser != nil) OFURIVerifyIsEscaped(percentEncodedUser, [OFCharacterSet URIUserAllowedCharacterSet], true); old = _percentEncodedUser; _percentEncodedUser = [percentEncodedUser copy]; [old release]; } - (void)setPassword: (OFString *)password { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedPassword; _percentEncodedPassword = [[password stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIPasswordAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedPassword: (OFString *)percentEncodedPassword { OFString *old; if (percentEncodedPassword != nil) OFURIVerifyIsEscaped(percentEncodedPassword, [OFCharacterSet URIPasswordAllowedCharacterSet], true); old = _percentEncodedPassword; _percentEncodedPassword = [percentEncodedPassword copy]; [old release]; } - (void)setPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedPath; _percentEncodedPath = [[path stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIPathAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedPath: (OFString *)percentEncodedPath { OFString *old; OFURIVerifyIsEscaped(percentEncodedPath, [OFCharacterSet URIPathAllowedCharacterSet], true); old = _percentEncodedPath; _percentEncodedPath = [percentEncodedPath copy]; [old release]; } - (void)setPathComponents: (OFArray *)components { void *pool = objc_autoreleasePoolPush(); if (components.count == 0) @throw [OFInvalidFormatException exception]; if ([components.firstObject isEqual: @"/"]) { OFMutableArray *mutComponents = [[components mutableCopy] autorelease]; [mutComponents replaceObjectAtIndex: 0 withObject: @""]; components = mutComponents; } self.path = [components componentsJoinedByString: @"/"]; objc_autoreleasePoolPop(pool); } - (void)setQuery: (OFString *)query { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedQuery; _percentEncodedQuery = [[query stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIQueryAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedQuery: (OFString *)percentEncodedQuery { OFString *old; if (percentEncodedQuery != nil) OFURIVerifyIsEscaped(percentEncodedQuery, [OFCharacterSet URIQueryAllowedCharacterSet], true); old = _percentEncodedQuery; _percentEncodedQuery = [percentEncodedQuery copy]; [old release]; } - (void)setQueryItems: (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *) queryItems { void *pool; OFMutableString *percentEncodedQuery; OFCharacterSet *characterSet; OFString *old; if (queryItems == nil) { [_percentEncodedQuery release]; _percentEncodedQuery = nil; return; } pool = objc_autoreleasePoolPush(); percentEncodedQuery = [OFMutableString string]; characterSet = [OFCharacterSet URIQueryKeyValueAllowedCharacterSet]; for (OFPair OF_GENERIC(OFString *, OFString *) *item in queryItems) { OFString *key = [item.firstObject stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; OFString *value = [item.secondObject stringByAddingPercentEncodingWithAllowedCharacters: characterSet]; if (percentEncodedQuery.length > 0) [percentEncodedQuery appendString: @"&"]; [percentEncodedQuery appendFormat: @"%@=%@", key, value]; } old = _percentEncodedQuery; _percentEncodedQuery = [percentEncodedQuery copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setFragment: (OFString *)fragment { void *pool = objc_autoreleasePoolPush(); OFString *old = _percentEncodedFragment; _percentEncodedFragment = [[fragment stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIFragmentAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setPercentEncodedFragment: (OFString *)percentEncodedFragment { OFString *old; if (percentEncodedFragment != nil) OFURIVerifyIsEscaped(percentEncodedFragment, [OFCharacterSet URIFragmentAllowedCharacterSet], true); old = _percentEncodedFragment; _percentEncodedFragment = [percentEncodedFragment copy]; [old release]; } - (id)copy { OFMutableURI *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)appendPathComponent: (OFString *)component { [self appendPathComponent: component isDirectory: false]; #ifdef OF_HAVE_FILES if ([_scheme isEqual: @"file"] && ![_percentEncodedPath hasSuffix: @"/"] && [[OFFileManager defaultManager] directoryExistsAtURI: self]) { void *pool = objc_autoreleasePoolPush(); OFString *path = [_percentEncodedPath stringByAppendingString: @"/"]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } #endif } - (void)appendPathComponent: (OFString *)component isDirectory: (bool)isDirectory { void *pool; OFString *path; if ([component isEqual: @"/"] && [_percentEncodedPath hasSuffix: @"/"]) return; pool = objc_autoreleasePoolPush(); component = [component stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIPathAllowedCharacterSet]]; #if defined(OF_WINDOWS) || defined(OF_MSDOS) if ([_percentEncodedPath hasSuffix: @"/"] || ([_scheme isEqual: @"file"] && [_percentEncodedPath hasSuffix: @":"])) #else if ([_percentEncodedPath hasSuffix: @"/"]) #endif path = [_percentEncodedPath stringByAppendingString: component]; else path = [_percentEncodedPath stringByAppendingFormat: @"/%@", component]; if (isDirectory && ![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; [_percentEncodedPath release]; _percentEncodedPath = [path retain]; objc_autoreleasePoolPop(pool); } - (void)standardizePath { void *pool = objc_autoreleasePoolPush(); OFMutableArray OF_GENERIC(OFString *) *array; bool done = false, startsWithEmpty, endsWithEmpty; OFString *path; array = [[[_percentEncodedPath componentsSeparatedByString: @"/"] mutableCopy] autorelease]; endsWithEmpty = ([array.lastObject length] == 0); startsWithEmpty = ([array.firstObject length] == 0); while (!done) { size_t length = array.count; done = true; for (size_t i = 0; i < length; i++) { |
︙ | ︙ | |||
398 399 400 401 402 403 404 | done = false; break; } if ([current isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | > | | | | | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | done = false; break; } if ([current isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } if (startsWithEmpty) [array insertObject: @"" atIndex: 0]; if (endsWithEmpty) [array addObject: @""]; path = [array componentsJoinedByString: @"/"]; if (startsWithEmpty && path.length == 0) path = @"/"; self.percentEncodedPath = path; objc_autoreleasePoolPop(pool); } - (void)makeImmutable { object_setClass(self, [OFURI class]); } @end |
Modified src/OFMutableUTF8String.m from [e069c57766] to [57e4df0b5d].
︙ | ︙ | |||
421 422 423 424 425 426 427 | @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } - (void)insertString: (OFString *)string atIndex: (size_t)idx { size_t newCStringLength; if (idx > _s->length) @throw [OFOutOfRangeException exception]; |
︙ | ︙ |
Modified src/OFMutableZIPArchiveEntry.h from [7d57139a39] to [019337b54d].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * 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 "OFZIPArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableZIPArchiveEntry \ * OFMutableZIPArchiveEntry.h ObjFW/OFMutableZIPArchiveEntry.h * * @brief A class which represents a mutable entry in the central directory of * a ZIP archive. */ | > | < < < < < < < < < < < | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * 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 "OFZIPArchiveEntry.h" #import "OFMutableArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutableZIPArchiveEntry \ * OFMutableZIPArchiveEntry.h ObjFW/OFMutableZIPArchiveEntry.h * * @brief A class which represents a mutable entry in the central directory of * a ZIP archive. */ @interface OFMutableZIPArchiveEntry: OFZIPArchiveEntry <OFMutableArchiveEntry> { OF_RESERVE_IVARS(OFMutableZIPArchiveEntry, 4) } /** * @brief The extra field of the entry. * * The item size *must* be 1! */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFData *extraField; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; | < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > > > > | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readwrite, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The CRC32 checksum of the entry's file. */ @property (readwrite, nonatomic) uint32_t CRC32; /** * @brief The version specific attributes. * * The meaning of the version specific attributes depends on the attribute * compatibility part of the version that made the entry. */ @property (readwrite, nonatomic) uint32_t versionSpecificAttributes; /** * @brief The general purpose bit flag of the entry. * * See the ZIP specification for details. */ @property (readwrite, nonatomic) uint16_t generalPurposeBitFlag; /** * @brief Creates a new OFMutableZIPArchiveEntry with the specified file name. * * @param fileName The file name for the OFZIPArchiveEntry * @return A new, autoreleased OFZIPArchiveEntry */ + (instancetype)entryWithFileName: (OFString *)fileName; /** * @brief Initializes an already allocated OFMutableZIPArchiveEntry with the * specified file name. * * @param fileName The file name for the OFZIPArchiveEntry * @return An initialized OFZIPArchiveEntry */ - (instancetype)initWithFileName: (OFString *)fileName; /** * @brief Converts the OFMutableZIPArchiveEntry to an immutable * OFZIPArchiveEntry. */ - (void)makeImmutable; @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableZIPArchiveEntry.m from [bdaf9f4cc4] to [5de5ffdaad].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFOutOfRangeException.h" @implementation OFMutableZIPArchiveEntry @dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } | > > > > > > > > > > > > > > > > > > > > > > > > > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #import "OFOutOfRangeException.h" @implementation OFMutableZIPArchiveEntry @dynamic fileName, fileComment, extraField, versionMadeBy, minVersionNeeded; @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)initWithFileName: (OFString *)fileName { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (fileName.UTF8StringLength > UINT16_MAX) @throw [OFOutOfRangeException exception]; _fileName = [fileName copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } |
︙ | ︙ | |||
112 113 114 115 116 117 118 | - (void)setCompressionMethod: (OFZIPArchiveEntryCompressionMethod)compressionMethod { _compressionMethod = compressionMethod; } | | | | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | - (void)setCompressionMethod: (OFZIPArchiveEntryCompressionMethod)compressionMethod { _compressionMethod = compressionMethod; } - (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } - (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setCRC32: (uint32_t)CRC32 { _CRC32 = CRC32; |
︙ | ︙ |
Modified src/OFMutex.h from [f277ea27da] to [60974c2165].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | OF_ASSUME_NONNULL_BEGIN /** * @class OFMutex OFMutex.h ObjFW/OFMutex.h * * @brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject <OFLocking> { OFPlainMutex _mutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFMutex, 4) | > > > > > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | OF_ASSUME_NONNULL_BEGIN /** * @class OFMutex OFMutex.h ObjFW/OFMutex.h * * @brief A class for creating mutual exclusions. * * If the mutex is deallocated while being held, it throws an * @ref OFStillLockedException. While this might break ARC's assumption that no * object ever throws in dealloc, it is considered a fatal programmer error * that should terminate the application. */ @interface OFMutex: OFObject <OFLocking> { OFPlainMutex _mutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFMutex, 4) |
︙ | ︙ |
Modified src/OFNotification.h from [de7bff6c2a] to [c3409634e1].
︙ | ︙ | |||
29 30 31 32 33 34 35 | /** * @class OFNotification OFNotification.h ObjFW/OFNotification.h * * @brief A class to represent a notification for or from * @ref OFNotificationCenter. */ | < > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /** * @class OFNotification OFNotification.h ObjFW/OFNotification.h * * @brief A class to represent a notification for or from * @ref OFNotificationCenter. */ @interface OFNotification: OFObject <OFCopying> { OFNotificationName _name; id _Nullable _object; OFDictionary *_Nullable _userInfo; OF_RESERVE_IVARS(OFNotification, 4) } /** * @brief The name of the notification. */ @property (readonly, nonatomic) OFNotificationName name; |
︙ | ︙ |
Modified src/OFNotificationCenter.h from [6d89a35135] to [2edf55e2db].
︙ | ︙ | |||
35 36 37 38 39 40 41 42 43 44 45 46 47 | /** * @class OFNotificationCenter OFNotificationCenter.h \ * ObjFW/OFNotificationCenter.h * * @brief A class to send and register for notifications. */ @interface OFNotificationCenter: OFObject { #ifdef OF_HAVE_THREADS OFMutex *_mutex; #endif OFMutableDictionary *_handles; | > > > < | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | /** * @class OFNotificationCenter OFNotificationCenter.h \ * ObjFW/OFNotificationCenter.h * * @brief A class to send and register for notifications. */ #ifndef OF_NOTIFICATION_CENTER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNotificationCenter: OFObject { #ifdef OF_HAVE_THREADS OFMutex *_mutex; #endif OFMutableDictionary *_handles; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFNotificationCenter *defaultCenter; #endif /** |
︙ | ︙ |
Modified src/OFNotificationCenter.m from [3332a25cc3] to [a7b0a81fd8].
︙ | ︙ | |||
8 9 10 11 12 13 14 15 16 17 18 19 20 21 | * 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 "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_THREADS | > > | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * 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. */ #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_THREADS |
︙ | ︙ |
Modified src/OFNumber.m from [fd08ff8e66] to [0d84e74204].
︙ | ︙ | |||
1034 1035 1036 1037 1038 1039 1040 | if (isnan(self.doubleValue)) return 0; d = OFToLittleEndianDouble(self.doubleValue); for (uint_fast8_t i = 0; i < sizeof(double); i++) | | | | 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | if (isnan(self.doubleValue)) return 0; d = OFToLittleEndianDouble(self.doubleValue); for (uint_fast8_t i = 0; i < sizeof(double); i++) OFHashAddByte(&hash, ((char *)&d)[i]); } else if (isSigned(self) || isUnsigned(self)) { unsigned long long value = self.unsignedLongLongValue; while (value != 0) { OFHashAddByte(&hash, value & 0xFF); value >>= 8; } } else @throw [OFInvalidFormatException exception]; OFHashFinalize(&hash); |
︙ | ︙ |
Modified src/OFObject.h from [73c8d5277c] to [c53ca874a9].
︙ | ︙ | |||
106 107 108 109 110 111 112 | * @brief Creates a new OFRange. * * @param start The starting index of the range * @param length The length of the range * @return An OFRangeith the specified start and length */ static OF_INLINE OFRange OF_CONST_FUNC | | | | 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * @brief Creates a new OFRange. * * @param start The starting index of the range * @param length The length of the range * @return An OFRangeith the specified start and length */ static OF_INLINE OFRange OF_CONST_FUNC OFMakeRange(size_t start, size_t length) { OFRange range = { start, length }; return range; } /** * @brief Returns whether the two ranges are equal. * * @param range1 The first range for the comparison * @param range2 The second range for the comparison * @return Whether the two ranges are equal */ static OF_INLINE bool OFEqualRanges(OFRange range1, OFRange range2) { if (range1.location != range2.location) return false; if (range1.length != range2.length) return false; |
︙ | ︙ | |||
157 158 159 160 161 162 163 | * @brief Creates a new OFPoint. * * @param x The x coordinate of the point * @param y The x coordinate of the point * @return An OFPoint with the specified coordinates */ static OF_INLINE OFPoint OF_CONST_FUNC | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | * @brief Creates a new OFPoint. * * @param x The x coordinate of the point * @param y The x coordinate of the point * @return An OFPoint with the specified coordinates */ static OF_INLINE OFPoint OF_CONST_FUNC OFMakePoint(float x, float y) { OFPoint point = { x, y }; return point; } /** * @brief Returns whether the two points are equal. * * @param point1 The first point for the comparison * @param point2 The second point for the comparison * @return Whether the two points are equal */ static OF_INLINE bool OFEqualPoints(OFPoint point1, OFPoint point2) { if (point1.x != point2.x) return false; if (point1.y != point2.y) return false; |
︙ | ︙ | |||
203 204 205 206 207 208 209 | * @brief Creates a new OFSize. * * @param width The width of the size * @param height The height of the size * @return An OFSize with the specified width and height */ static OF_INLINE OFSize OF_CONST_FUNC | | | | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | * @brief Creates a new OFSize. * * @param width The width of the size * @param height The height of the size * @return An OFSize with the specified width and height */ static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize(float width, float height) { OFSize size = { width, height }; return size; } /** * @brief Returns whether the two sizes are equal. * * @param size1 The first size for the comparison * @param size2 The second size for the comparison * @return Whether the two sizes are equal */ static OF_INLINE bool OFEqualSizes(OFSize size1, OFSize size2) { if (size1.width != size2.width) return false; if (size1.height != size2.height) return false; |
︙ | ︙ | |||
251 252 253 254 255 256 257 | * @param x The x coordinate of the top left corner of the rectangle * @param y The y coordinate of the top left corner of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @return An OFRect with the specified origin and size */ static OF_INLINE OFRect OF_CONST_FUNC | | | | | | | | | | | | | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | * @param x The x coordinate of the top left corner of the rectangle * @param y The y coordinate of the top left corner of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @return An OFRect with the specified origin and size */ static OF_INLINE OFRect OF_CONST_FUNC OFMakeRect(float x, float y, float width, float height) { OFRect rect = { OFMakePoint(x, y), OFMakeSize(width, height) }; return rect; } /** * @brief Returns whether the two rectangles are equal. * * @param rect1 The first rectangle for the comparison * @param rect2 The second rectangle for the comparison * @return Whether the two rectangles are equal */ static OF_INLINE bool OFEqualRects(OFRect rect1, OFRect rect2) { if (!OFEqualPoints(rect1.origin, rect2.origin)) return false; if (!OFEqualSizes(rect1.size, rect2.size)) return false; return true; } /** * @brief Adds the specified byte to the hash. * * @param hash A pointer to a hash to add the byte to * @param byte The byte to add to the hash */ static OF_INLINE void OFHashAddByte(unsigned long *_Nonnull hash, unsigned char byte) { uint32_t tmp = (uint32_t)*hash; tmp += byte; tmp += tmp << 10; tmp ^= tmp >> 6; *hash = tmp; } /** * @brief Adds the specified hash to the hash. * * @param hash A pointer to a hash to add the hash to * @param otherHash The hash to add to the hash */ static OF_INLINE void OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash) { OFHashAddByte(hash, (otherHash >> 24) & 0xFF); OFHashAddByte(hash, (otherHash >> 16) & 0xFF); OFHashAddByte(hash, (otherHash >> 8) & 0xFF); OFHashAddByte(hash, otherHash & 0xFF); } /** * @brief Finalizes the specified hash. * * @param hash A pointer to the hash to finalize */ |
︙ | ︙ | |||
358 359 360 361 362 363 364 | * @brief Returns the superclass of the object. * * @return The superclass of the object */ - (nullable Class)superclass; /** | | | < < < < < < < | | | 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | * @brief Returns the superclass of the object. * * @return The superclass of the object */ - (nullable Class)superclass; /** * @brief Returns a hash for the object. * * Classes containing data (like strings, arrays, lists etc.) should reimplement * this! * * @warning If you reimplement this, you also need to reimplement @ref isEqual: * to behave in a way compatible to your reimplementation of this * method! * * @return A hash for the object */ - (unsigned long)hash; /** * @brief Returns the retain count. * * @return The retain count */ - (unsigned int)retainCount; /** * @brief Returns whether the object is a proxy object. * * @return Whether the object is a proxy object */ - (bool)isProxy; /** * @brief Returns a boolean whether the object is of the specified kind. * * @param class_ The class for which the receiver is checked * @return A boolean whether the object is of the specified kind */ - (bool)isKindOfClass: (Class)class_; /** * @brief Returns a boolean whether the object is a member of the specified * class. |
︙ | ︙ | |||
548 549 550 551 552 553 554 555 556 557 558 559 560 561 | /** * @brief Returns the receiver. * * @return The receiver */ - (instancetype)self; /** * @brief Retain a weak reference to this object. * * @return Whether a weak reference to this object has been retained */ - (bool)retainWeakReference; @end | > > > > > > > | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | /** * @brief Returns the receiver. * * @return The receiver */ - (instancetype)self; /** * @brief Returns whether the object allows a weak reference. * * @return Whether the object allows a weak references */ - (bool)allowsWeakReference; /** * @brief Retain a weak reference to this object. * * @return Whether a weak reference to this object has been retained */ - (bool)retainWeakReference; @end |
︙ | ︙ | |||
646 647 648 649 650 651 652 | */ + (void)initialize; /** * @brief Allocates memory for an instance of the class and sets up the memory * pool for the object. * | | < > > > | 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | */ + (void)initialize; /** * @brief Allocates memory for an instance of the class and sets up the memory * pool for the object. * * This method will never return `nil`. * * @return The allocated object * @throw OFAllocFailedException There was not enough memory to allocate the * object * @throw OFInitializationFailedException The instance could not be constructed */ + (instancetype)alloc; /** * @brief Calls @ref alloc on `self` and then `init` on the returned object. * * @return An allocated and initialized object |
︙ | ︙ | |||
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 | /** * @brief Handles messages which are not understood by the receiver. * * @warning If you override this method, you must make sure that it never * returns! * * @param selector The selector not understood by the receiver */ - (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN; @end #else typedef void OFObject; #endif | > | 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 | /** * @brief Handles messages which are not understood by the receiver. * * @warning If you override this method, you must make sure that it never * returns! * * @param selector The selector not understood by the receiver * @throw OFNotImplementedException */ - (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN; @end #else typedef void OFObject; #endif |
︙ | ︙ | |||
1288 1289 1290 1291 1292 1293 1294 | #endif /** * @brief Allocates memory for the specified number of items of the specified * size. * * To free the allocated memory, use @ref OFFreeMemory. * | < < < > > > < < < > > > < < < > > > > | 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 | #endif /** * @brief Allocates memory for the specified number of items of the specified * size. * * To free the allocated memory, use @ref OFFreeMemory. * * @param count The number of items to allocate * @param size The size of each item to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. * @throw OFOutOfMemoryException The allocation failed due to not enough memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFAllocMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Allocates memory for the specified number of items of the specified * size and initializes it with zeros. * * To free the allocated memory, use @ref OFFreeMemory. * * @param size The size of each item to allocate * @param count The number of items to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. * @throw OFOutOfMemoryException The allocation failed due to not enough memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Resizes memory to the specified number of items of the specified size. * * To free the allocated memory, use @ref OFFreeMemory. * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. * * @param pointer A pointer to the already allocated memory * @param size The size of each item to resize to * @param count The number of items to resize to * @return A pointer to the resized memory chunk * @throw OFOutOfMemoryException The reallocation failed due to not enough * memory * @throw OFOutOfRangeException The requested `count * size` exceeds the * address space */ extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Frees memory allocated by @ref OFAllocMemory, @ref OFAllocZeroedMemory * or @ref OFResizeMemory. |
︙ | ︙ |
Modified src/OFObject.m from [ac239733f0] to [2ac228feac].
︙ | ︙ | |||
40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #import "OFRunLoop.h" #if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS) # import "OFPlainMutex.h" /* For OFSpinlock */ #endif #import "OFString.h" #import "OFThread.h" #import "OFTimer.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" | > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #import "OFRunLoop.h" #if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS) # import "OFPlainMutex.h" /* For OFSpinlock */ #endif #import "OFString.h" #import "OFThread.h" #import "OFTimer.h" #import "OFValue.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" |
︙ | ︙ | |||
256 257 258 259 260 261 262 | } #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; | | > | > | > > > > > | > > | > | > > > > > > | > > > > > > > > > > > > > | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | } #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; OFArray OF_GENERIC(OFValue *) *stackTraceAddresses = nil; OFArray OF_GENERIC(OFString *) *stackTraceSymbols = nil; OFStringEncoding encoding = [OFLocale encoding]; fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [description cStringWithEncoding: encoding]); if ([exception respondsToSelector: @selector(stackTraceAddresses)]) stackTraceAddresses = [exception stackTraceAddresses]; if (stackTraceAddresses != nil) { size_t count = stackTraceAddresses.count; if ([exception respondsToSelector: @selector(stackTraceSymbols)]) stackTraceSymbols = [exception stackTraceSymbols]; if (stackTraceSymbols.count != count) stackTraceSymbols = nil; fputs("\nStack trace:\n", stderr); if (stackTraceSymbols != nil) { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; const char *symbol = [[stackTraceSymbols objectAtIndex: i] cStringWithEncoding: encoding]; fprintf(stderr, " %p %s\n", address, symbol); } } else { for (size_t i = 0; i < count; i++) { void *address = [[stackTraceAddresses objectAtIndex: i] pointerValue]; fprintf(stderr, " %p\n", address); } } fputs("\n", stderr); } abort(); } #endif static void |
︙ | ︙ | |||
336 337 338 339 340 341 342 343 344 345 346 347 348 349 | exceptionWithClass: class]; } #endif instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN); if (!objc_constructInstance(class, instance)) { free((char *)instance - PRE_IVARS_ALIGN); @throw [OFInitializationFailedException exceptionWithClass: class]; } if OF_UNLIKELY (extra != NULL) *extra = (char *)instance + instanceSize + extraAlignment; | > > > > | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | exceptionWithClass: class]; } #endif instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN); if (!objc_constructInstance(class, instance)) { #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&((struct PreIvars *)(void *) ((char *)instance - PRE_IVARS_ALIGN))->retainCountSpinlock); #endif free((char *)instance - PRE_IVARS_ALIGN); @throw [OFInitializationFailedException exceptionWithClass: class]; } if OF_UNLIKELY (extra != NULL) *extra = (char *)instance + instanceSize + extraAlignment; |
︙ | ︙ | |||
1086 1087 1088 1089 1090 1091 1092 | { uintptr_t ptr = (uintptr_t)self; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(ptr); i++) { | | | 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 | { uintptr_t ptr = (uintptr_t)self; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(ptr); i++) { OFHashAddByte(&hash, ptr & 0xFF); ptr >>= 8; } OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | return true; } - (void)dealloc { objc_destructInstance(self); free((char *)self - PRE_IVARS_ALIGN); } /* Required to use properties with the Apple runtime */ - (id)copyWithZone: (void *)zone { | > > > > | 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 | return true; } - (void)dealloc { objc_destructInstance(self); #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlockFree(&PRE_IVARS->retainCountSpinlock); #endif free((char *)self - PRE_IVARS_ALIGN); } /* Required to use properties with the Apple runtime */ - (id)copyWithZone: (void *)zone { |
︙ | ︙ |
Modified src/OFOptionsParser.m from [6586be74a2] to [c0426ac296].
︙ | ︙ | |||
195 196 197 198 199 200 201 | OFNotFound) _argument = [[argument substringFromIndex: pos + 1] copy]; else pos = argument.length; _lastLongOption = [[argument substringWithRange: | | | 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | OFNotFound) _argument = [[argument substringFromIndex: pos + 1] copy]; else pos = argument.length; _lastLongOption = [[argument substringWithRange: OFMakeRange(2, pos - 2)] copy]; objc_autoreleasePoolPop(pool); option = [_longOptions objectForKey: _lastLongOption]; if (option == NULL) return '?'; |
︙ | ︙ | |||
267 268 269 270 271 272 273 | return '?'; } - (OFArray *)remainingArguments { return [_arguments objectsInRange: | | | 267 268 269 270 271 272 273 274 275 276 | return '?'; } - (OFArray *)remainingArguments { return [_arguments objectsInRange: OFMakeRange(_index, _arguments.count - _index)]; } @end |
Modified src/OFPlugin.h from [4badab4fb7] to [a9cf165ddb].
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | /** * @brief Creates a new OFPlugin by loading the plugin with the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An new, autoreleased OFPlugin */ + (instancetype)pluginWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFPlugin by loading the plugin with * the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An initialized OFPlugin */ - (instancetype)initWithPath: (OFString *)path; /** * @brief Returns the address for the specified symbol, or `nil` if not found. * * @param symbol The symbol to return the address for | > > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | /** * @brief Creates a new OFPlugin by loading the plugin with the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An new, autoreleased OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ + (instancetype)pluginWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFPlugin by loading the plugin with * the specified path. * * @param path The path to the plugin file. The suffix is appended * automatically. * @return An initialized OFPlugin * @throw OFLoadPluginFailedException The plugin could not be loaded */ - (instancetype)initWithPath: (OFString *)path; /** * @brief Returns the address for the specified symbol, or `nil` if not found. * * @param symbol The symbol to return the address for |
︙ | ︙ |
Modified src/OFPollKernelEventObserver.m from [458ef336b0] to [e4119778c6].
︙ | ︙ | |||
24 25 26 27 28 29 30 | # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFSocket+Private.h" | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFSocket+Private.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_WII # define pollfd pollsd # define fd socket #endif |
︙ | ︙ | |||
70 71 72 73 74 75 76 | addObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t count; bool found; if (fd < 0) | > | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | addObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t count; bool found; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; count = self->_FDs.count; found = false; for (size_t i = 0; i < count; i++) { if (FDs[i].fd == fd) { |
︙ | ︙ | |||
106 107 108 109 110 111 112 | static void removeObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t nFDs; if (fd < 0) | > | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | static void removeObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t nFDs; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; nFDs = self->_FDs.count; for (size_t i = 0; i < nFDs; i++) { if (FDs[i].fd == fd) { FDs[i].events &= ~events; |
︙ | ︙ | |||
181 182 183 184 185 186 187 | @throw [OFOutOfRangeException exception]; #endif events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) | > | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | @throw [OFOutOfRangeException exception]; #endif events = poll(FDs, (nfds_t)nFDs, (int)(timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: errno]; for (size_t i = 0; i < nFDs; i++) { assert(FDs[i].fd <= _maxFD); if (FDs[i].revents & POLLIN) { void *pool2; |
︙ | ︙ |
Modified src/OFRecursiveMutex.h from [5662e5ef58] to [e91aa73730].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | OF_ASSUME_NONNULL_BEGIN /** * @class OFRecursiveMutex OFRecursiveMutex.h ObjFW/OFRecursiveMutex.h * * @brief A class for creating mutual exclusions which can be entered * recursively. */ OF_SUBCLASSING_RESTRICTED @interface OFRecursiveMutex: OFObject <OFLocking> { OFPlainRecursiveMutex _rmutex; bool _initialized; OFString *_Nullable _name; } /** * @brief Creates a new recursive mutex. * * @return A new autoreleased recursive mutex. */ | > > > > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | OF_ASSUME_NONNULL_BEGIN /** * @class OFRecursiveMutex OFRecursiveMutex.h ObjFW/OFRecursiveMutex.h * * @brief A class for creating mutual exclusions which can be entered * recursively. * * If the mutex is deallocated while being held, it throws an * @ref OFStillLockedException. While this might break ARC's assumption that no * object ever throws in dealloc, it is considered a fatal programmer error * that should terminate the application. */ OF_SUBCLASSING_RESTRICTED @interface OFRecursiveMutex: OFObject <OFLocking> { OFPlainRecursiveMutex _rmutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFRecursiveMutex, 4) } /** * @brief Creates a new recursive mutex. * * @return A new autoreleased recursive mutex. */ |
︙ | ︙ |
Modified src/OFRunLoop.m from [e671b17f7b] to [ccade11e78].
︙ | ︙ | |||
37 38 39 40 41 42 43 | # import "OFCondition.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # import "OFCondition.h" #endif #import "OFSortedList.h" #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveKernelEventsFailedException.h" #import "OFWriteFailedException.h" #include "OFRunLoopConstants.inc" static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject |
︙ | ︙ | |||
1647 1648 1649 1650 1651 1652 1653 | if (timeout < 0) timeout = 0; #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observeForTimeInterval: timeout]; | | | 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 | if (timeout < 0) timeout = 0; #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observeForTimeInterval: timeout]; } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; # ifdef OF_AMIGAOS signalMask = state->_execSignalMask; |
︙ | ︙ | |||
1675 1676 1677 1678 1679 1680 1681 | * No more timers and no deadline: Just watch for I/O * until we get an event. If a timer is added by * another thread, it cancels the observe. */ #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observe]; | | | 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 | * No more timers and no deadline: Just watch for I/O * until we get an event. If a timer is added by * another thread, it cancels the observe. */ #if defined(OF_HAVE_SOCKETS) @try { [state->_kernelEventObserver observe]; } @catch (OFObserveKernelEventsFailedException *e) { if (e.errNo != EINTR) @throw e; } #elif defined(OF_HAVE_THREADS) [state->_condition lock]; # ifdef OF_AMIGAOS signalMask = state->_execSignalMask; |
︙ | ︙ |
Modified src/OFSPXSocket.h from [4d2a1f1863] to [f7b34dfc4b].
︙ | ︙ | |||
85 86 87 88 89 90 91 92 93 94 95 96 97 98 | /** * @brief Connect the OFSPXSocket to the specified destination. * * @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 */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. | > > | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | /** * @brief Connect the OFSPXSocket to the specified destination. * * @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 OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. |
︙ | ︙ | |||
154 155 156 157 158 159 160 161 162 163 164 165 | /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END | > > | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached * @throw OFBindFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFSPXStreamSocket.h from [273c44a2b3] to [9a246da830].
︙ | ︙ | |||
86 87 88 89 90 91 92 93 94 95 96 97 98 99 | /** * @brief Connect the OFSPXStreamSocket to the specified destination. * * @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 */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified | > > | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | /** * @brief Connect the OFSPXStreamSocket to the specified destination. * * @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 OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToNetwork: (uint32_t)network node: (unsigned char [_Nonnull IPX_NODE_LEN])node port: (uint16_t)port; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified |
︙ | ︙ | |||
159 160 161 162 163 164 165 166 167 168 169 170 | /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END | > > | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached * @throw OFConnectionFailedException Binding failed * @throw OFAlreadyConnectedException The socket is already connected or bound */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFSandbox.h from [8f1c6b186c] to [021642ddcf].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFPair OF_GENERIC(FirstType, SecondType); typedef OFPair OF_GENERIC(OFString *, OFString *) *OFSandboxUnveilPath; @interface OFSandbox: OFObject <OFCopying> { unsigned int _allowsStdIO: 1; unsigned int _allowsReadingFiles: 1; unsigned int _allowsWritingFiles: 1; unsigned int _allowsCreatingFiles: 1; unsigned int _allowsCreatingSpecialFiles: 1; | > | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFPair OF_GENERIC(FirstType, SecondType); typedef OFPair OF_GENERIC(OFString *, OFString *) *OFSandboxUnveilPath; OF_SUBCLASSING_RESTRICTED @interface OFSandbox: OFObject <OFCopying> { unsigned int _allowsStdIO: 1; unsigned int _allowsReadingFiles: 1; unsigned int _allowsWritingFiles: 1; unsigned int _allowsCreatingFiles: 1; unsigned int _allowsCreatingSpecialFiles: 1; |
︙ | ︙ | |||
54 55 56 57 58 59 60 | unsigned int _allowsAudio: 1; unsigned int _allowsBPF: 1; unsigned int _allowsUnveil: 1; unsigned int _returnsErrors: 1; OFMutableArray OF_GENERIC(OFSandboxUnveilPath) *_unveiledPaths; @public size_t _unveiledPathsIndex; | < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | unsigned int _allowsAudio: 1; unsigned int _allowsBPF: 1; unsigned int _allowsUnveil: 1; unsigned int _returnsErrors: 1; OFMutableArray OF_GENERIC(OFSandboxUnveilPath) *_unveiledPaths; @public size_t _unveiledPathsIndex; } @property (nonatomic) bool allowsStdIO; @property (nonatomic) bool allowsReadingFiles; @property (nonatomic) bool allowsWritingFiles; @property (nonatomic) bool allowsCreatingFiles; @property (nonatomic) bool allowsCreatingSpecialFiles; |
︙ | ︙ |
Modified src/OFSandbox.m from [a04c417381] to [de6e0ab02e].
︙ | ︙ | |||
469 470 471 472 473 474 475 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, _allowsStdIO); OFHashAddByte(&hash, _allowsReadingFiles); OFHashAddByte(&hash, _allowsWritingFiles); OFHashAddByte(&hash, _allowsCreatingFiles); OFHashAddByte(&hash, _allowsCreatingSpecialFiles); OFHashAddByte(&hash, _allowsTemporaryFiles); OFHashAddByte(&hash, _allowsIPSockets); OFHashAddByte(&hash, _allowsMulticastSockets); OFHashAddByte(&hash, _allowsChangingFileAttributes); OFHashAddByte(&hash, _allowsFileOwnerChanges); OFHashAddByte(&hash, _allowsFileLocks); OFHashAddByte(&hash, _allowsUNIXSockets); OFHashAddByte(&hash, _allowsDNS); OFHashAddByte(&hash, _allowsUserDatabaseReading); OFHashAddByte(&hash, _allowsFileDescriptorSending); OFHashAddByte(&hash, _allowsFileDescriptorReceiving); OFHashAddByte(&hash, _allowsTape); OFHashAddByte(&hash, _allowsTTY); OFHashAddByte(&hash, _allowsProcessOperations); OFHashAddByte(&hash, _allowsExec); OFHashAddByte(&hash, _allowsProtExec); OFHashAddByte(&hash, _allowsSetTime); OFHashAddByte(&hash, _allowsPS); OFHashAddByte(&hash, _allowsVMInfo); OFHashAddByte(&hash, _allowsChangingProcessRights); OFHashAddByte(&hash, _allowsPF); OFHashAddByte(&hash, _allowsAudio); OFHashAddByte(&hash, _allowsBPF); OFHashAddByte(&hash, _allowsUnveil); OFHashAddByte(&hash, _returnsErrors); OFHashFinalize(&hash); return hash; } #ifdef OF_HAVE_PLEDGE |
︙ | ︙ |
Modified src/OFSecureData.h from [6ad4e10f23] to [9dc679ab94].
︙ | ︙ | |||
60 61 62 63 64 65 66 | * smaller than a single page! * * @param size The number of bytes of unswappable memory to preallocate */ + (void)preallocateUnswappableMemoryWithSize: (size_t)size; /** | | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | * smaller than a single page! * * @param size The number of bytes of unswappable memory to preallocate */ + (void)preallocateUnswappableMemoryWithSize: (size_t)size; /** * @brief Creates a new, autoreleased OFSecureData with `count` items of item * size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return A new, autoreleased OFSecureData */ + (instancetype)dataWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Creates a new, autoreleased OFSecureData with `count` items of the * specified item size, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param itemSize The size of a single item in the OFSecureData in bytes * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return A new, autoreleased OFSecureData |
︙ | ︙ | |||
100 101 102 103 104 105 106 | + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif | | | | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | + (instancetype)dataWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif + (instancetype)dataWithContentsOfURI: (OFURI *)URI OF_UNAVAILABLE; + (instancetype)dataWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; + (instancetype)dataWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSecureData with `count` items of * item size 1, all set to zero. * * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return An initialized OFSecureData */ - (instancetype)initWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Initializes an already allocated OFSecureData with `count` items of * the specified item size, all set to zero. * * @param itemSize The size of a single item in the OFSecureData in bytes * @param count The number of zero items the OFSecureData should contain * @param allowsSwappableMemory Whether the data may be stored in swappable * memory * @return An initialized OFSecureData */ |
︙ | ︙ | |||
146 147 148 149 150 151 152 | - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path OF_UNAVAILABLE; #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI OF_UNAVAILABLE; - (instancetype)initWithStringRepresentation: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithBase64EncodedString: (OFString *)string OF_UNAVAILABLE; - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; /** * @brief Returns a specific item of the OFSecureData. * |
︙ | ︙ | |||
183 184 185 186 187 188 189 | - (void)zero; - (OFString *)stringRepresentation OF_UNAVAILABLE; - (OFString *)stringByBase64Encoding OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path OF_UNAVAILABLE; #endif | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 | - (void)zero; - (OFString *)stringRepresentation OF_UNAVAILABLE; - (OFString *)stringByBase64Encoding OF_UNAVAILABLE; #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path OF_UNAVAILABLE; #endif - (void)writeToURI: (OFURI *)URI OF_UNAVAILABLE; - (OFXMLElement *)XMLElementBySerializing OF_UNAVAILABLE; - (OFData *)messagePackRepresentation OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/OFSecureData.m from [ea6060539c] to [7420c1ca0e].
︙ | ︙ | |||
371 372 373 374 375 376 377 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif | | | 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | #ifdef OF_HAVE_FILES + (instancetype)dataWithContentsOfFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif + (instancetype)dataWithContentsOfURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } + (instancetype)dataWithStringRepresentation: (OFString *)string { OF_UNRECOGNIZED_SELECTOR |
︙ | ︙ | |||
495 496 497 498 499 500 501 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { OF_INVALID_INIT_METHOD } #endif | | | 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { OF_INVALID_INIT_METHOD } #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI { OF_INVALID_INIT_METHOD } - (instancetype)initWithStringRepresentation: (OFString *)string { OF_INVALID_INIT_METHOD |
︙ | ︙ | |||
627 628 629 630 631 632 633 | #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif | | | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } #endif - (void)writeToURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (OFXMLElement *)XMLElementBySerializing { OF_UNRECOGNIZED_SELECTOR |
︙ | ︙ |
Modified src/OFSeekableStream.h from [dfe5585e9c] to [b1e0890846].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN #if defined(OF_WINDOWS) | > > | | | | | > > > > > > > > > > > > | | < < < < < < > > | > | < < < < < < > > | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN /** @file */ #if defined(OF_WINDOWS) typedef __int64 OFStreamOffset; #elif defined(OF_ANDROID) typedef long long OFStreamOffset; #elif defined(OF_MORPHOS) typedef signed long long OFStreamOffset; #elif defined(OF_HAVE_OFF64_T) typedef off64_t OFStreamOffset; #else typedef off_t OFStreamOffset; #endif /** * @brief From where to seek. */ typedef enum { /** Seek to the end of the stream + offset. */ OFSeekSet, /** Seek to the current location + offset. */ OFSeekCurrent, /** Seek to the specified byte. */ OFSeekEnd } OFSeekWhence; /** * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * * @note If you want to subclass this, override * @ref lowlevelSeekToOffset:whence:. OFSeekableStream uses this method * and makes it work together with the caching of OFStream. If you * override this methods without the `lowlevel` prefix, you *will* break * caching, get broken results and seek to the wrong position! */ @interface OFSeekableStream: OFStream { OF_RESERVE_IVARS(OFSeekableStream, 4) } /** * @brief Seeks to the specified offset. * * @param offset The offset in bytes * @param whence From where to seek. * @return The new offset form the start of the file * @throw OFSeekFailedException Seeking failed * @throw OFNotOpenException The stream is not open */ - (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence; /** * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! * * @note Override this method with your actual seek implementation when * subclassing! * * @param offset The offset to seek to * @param whence From where to seek. * @return The new offset from the start of the file * @throw OFSeekFailedException Seeking failed * @throw OFNotOpenException The stream is not open */ - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence; @end OF_ASSUME_NONNULL_END |
Modified src/OFSeekableStream.m from [9e766aeca1] to [b6c980d4ae].
︙ | ︙ | |||
34 35 36 37 38 39 40 | @throw e; } } return [super init]; } | | > | > | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | @throw e; } } return [super init]; } - (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { OF_UNRECOGNIZED_SELECTOR } - (OFStreamOffset)seekToOffset: (OFStreamOffset)offset whence: (OFSeekWhence)whence { if (whence == OFSeekCurrent) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; |
︙ | ︙ |
Modified src/OFSelectKernelEventObserver.m from [14ac36d0e0] to [178271bdfe].
︙ | ︙ | |||
30 31 32 33 34 35 36 | #include <sys/time.h> #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFSocket+Private.h" #import "OFInitializationFailedException.h" | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #include <sys/time.h> #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFSocket+Private.h" #import "OFInitializationFailedException.h" #import "OFObserveKernelEventsFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # include <proto/exec.h> #endif #ifdef OF_HPUX |
︙ | ︙ | |||
80 81 82 83 84 85 86 | } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { int fd = object.fileDescriptorForReading; if (fd < 0) | > | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
104 105 106 107 108 109 110 | } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { int fd = object.fileDescriptorForWriting; if (fd < 0) | > | | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; if (fd > INT_MAX - 1) @throw [OFOutOfRangeException exception]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
130 131 132 133 134 135 136 | - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) | > | | > | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((OFSocketHandle)fd, &_readFDs); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif |
︙ | ︙ | |||
202 203 204 205 206 207 208 | #else timeout.tv_sec = (long)timeInterval; #endif timeout.tv_usec = (int)((timeInterval - timeout.tv_sec) * 1000000); #ifdef OF_AMIGAOS if ((cancelSignal = AllocSignal(-1)) == (BYTE)-1) | > | | | 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | #else timeout.tv_sec = (long)timeInterval; #endif timeout.tv_usec = (int)((timeInterval - timeout.tv_sec) * 1000000); #ifdef OF_AMIGAOS if ((cancelSignal = AllocSignal(-1)) == (BYTE)-1) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: EAGAIN]; execSignalMask = _execSignalMask | (1ul << cancelSignal); Forbid(); _waitingTask = FindTask(NULL); _cancelSignal = cancelSignal; |
︙ | ︙ | |||
227 228 229 230 231 232 233 | Permit(); #else events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | Permit(); #else events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) @throw [OFObserveKernelEventsFailedException exceptionWithObserver: self errNo: OFSocketErrNo()]; #ifdef OF_AMIGAOS if (execSignalMask != 0 && [_delegate respondsToSelector: @selector(execSignalWasReceived:)]) [_delegate execSignalWasReceived: execSignalMask]; |
︙ | ︙ |
Modified src/OFSequencedPacketSocket.h from [c4199b3715] to [b8e6a1fd31].
︙ | ︙ | |||
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket is a listening socket. */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are | > > > > > | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** * @brief Whether the socket can block. * * By default, a socket can block. * * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief Whether the socket is a listening socket. */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! * * @throw OFNotOpenException The socket is not open * @throw OFInvalidArgumentException The socket has no remote address */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are |
︙ | ︙ | |||
171 172 173 174 175 176 177 178 179 180 181 182 183 184 | * @brief Receives a packet and stores it into the specified buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * | > > | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | * @brief Receives a packet and stores it into the specified buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet * @throw OFReadFailedException Receiving failed * @throw OFNotOpenException The socket is not open */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * |
︙ | ︙ | |||
244 245 246 247 248 249 250 251 252 253 254 255 256 257 | #endif /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer */ - (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet | > > | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | #endif /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer * @throw OFWriteFailedException Sending failed * @throw OFNotOpenException The socket is not open */ - (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet |
︙ | ︙ | |||
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | block: (OFSequencedPacketSocketAsyncSendDataBlock)block; #endif /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased sequenced packet socket for the accepted connection. */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; | > > > > > > > | 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | block: (OFSequencedPacketSocketAsyncSendDataBlock)block; #endif /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. * @throw OFListenFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * * @throw OFListenFailedException 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 OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; |
︙ | ︙ | |||
350 351 352 353 354 355 356 357 358 359 360 361 | * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. */ - (void)close; @end OF_ASSUME_NONNULL_END | > > | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; /** * @brief Closes the socket so that it can neither receive nor send any more * datagrams. * * @throw OFNotOpenException The socket is not open */ - (void)close; @end OF_ASSUME_NONNULL_END |
Modified src/OFSequencedPacketSocket.m from [f3c3c9897f] to [a8c0e899a1].
︙ | ︙ | |||
314 315 316 317 318 319 320 | errNo: OFSocketErrNo()]; _listening = true; } - (instancetype)accept { | | < > > > > | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | errNo: OFSocketErrNo()]; _listening = true; } - (instancetype)accept { OFSequencedPacketSocket *client; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; # endif #endif if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; client = [[[[self class] alloc] init] autorelease]; client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, (struct sockaddr *)&client->_remoteAddress.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == |
︙ | ︙ |
Modified src/OFSerialization.h from [6913e132ee] to [6c8c4c9563].
︙ | ︙ | |||
32 33 34 35 36 37 38 39 40 41 42 43 44 45 | @property (readonly, nonatomic) OFXMLElement *XMLElementBySerializing; /** * @brief Initializes the object with the specified XML element serialization. * * @param element An OFXMLElement with the serialized object * @return An initialized object */ - (instancetype)initWithSerialization: (OFXMLElement *)element; @end #ifdef __cplusplus extern "C" { #endif | > > | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | @property (readonly, nonatomic) OFXMLElement *XMLElementBySerializing; /** * @brief Initializes the object with the specified XML element serialization. * * @param element An OFXMLElement with the serialized object * @return An initialized object * @throw OFInvalidFormatException The specified element is not of the correct * serialization format */ - (instancetype)initWithSerialization: (OFXMLElement *)element; @end #ifdef __cplusplus extern "C" { #endif |
︙ | ︙ |
Modified src/OFSocket.h from [0929d955af] to [6ae41ef6ce].
︙ | ︙ | |||
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | /** * @brief Parses the specified IP (either v4 or v6) and port into an * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use * @return The parsed IP and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use * @return The parsed IPv4 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket | > > > | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | /** * @brief Parses the specified IP (either v4 or v6) and port into an * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use * @return The parsed IP and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IP */ extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use * @return The parsed IPv4 and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IPv4 */ extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress * @throw OFInvalidFormatException The specified string is not a valid IPv6 */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates a UNIX socket address from the specified path. * * @param path The path of the UNIX socket |
︙ | ︙ |
Modified src/OFSocket.m from [b9058d4f4d] to [65b91d8086].
︙ | ︙ | |||
230 231 232 233 234 235 236 | # endif if (socketBase != NULL) CloseLibrary(socketBase); } #endif int | | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | # endif if (socketBase != NULL) CloseLibrary(socketBase); } #endif int OFSocketErrNo(void) { #if defined(OF_WINDOWS) switch (WSAGetLastError()) { case WSAEACCES: return EACCES; case WSAEADDRINUSE: return EADDRINUSE; |
︙ | ︙ | |||
665 666 667 668 669 670 671 | unsigned long OFSocketAddressHash(const OFSocketAddress *address) { unsigned long hash; OFHashInit(&hash); | | | | > | > | | | | | | | | | > | | 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | unsigned long OFSocketAddressHash(const OFSocketAddress *address) { unsigned long hash; OFHashInit(&hash); OFHashAddByte(&hash, address->family); switch (address->family) { case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address->length < (socklen_t)sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #endif OFHashAddByte(&hash, address->sockaddr.in.sin_port >> 8); OFHashAddByte(&hash, address->sockaddr.in.sin_port); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 24); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 16); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr >> 8); OFHashAddByte(&hash, address->sockaddr.in.sin_addr.s_addr); break; case OFSocketAddressFamilyIPv6: if (address->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; OFHashAddByte(&hash, address->sockaddr.in6.sin6_port >> 8); OFHashAddByte(&hash, address->sockaddr.in6.sin6_port); for (size_t i = 0; i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++) OFHashAddByte(&hash, address->sockaddr.in6.sin6_addr.s6_addr[i]); break; case OFSocketAddressFamilyUNIX:; void *pool = objc_autoreleasePoolPush(); OFString *path = OFSocketAddressUNIXPath(address); hash = path.hash; objc_autoreleasePoolPop(pool); return hash; case OFSocketAddressFamilyIPX:; unsigned char network[ sizeof(address->sockaddr.ipx.sipx_network)]; if (address->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; OFHashAddByte(&hash, address->sockaddr.ipx.sipx_port >> 8); OFHashAddByte(&hash, address->sockaddr.ipx.sipx_port); memcpy(network, &address->sockaddr.ipx.sipx_network, sizeof(network)); for (size_t i = 0; i < sizeof(network); i++) OFHashAddByte(&hash, network[i]); for (size_t i = 0; i < IPX_NODE_LEN; i++) OFHashAddByte(&hash, address->sockaddr.ipx.sipx_node[i]); break; default: @throw [OFInvalidArgumentException exception]; } OFHashFinalize(&hash); |
︙ | ︙ |
Modified src/OFStream.h from [2b820d15bb] to [a93512463b].
︙ | ︙ | |||
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | @property (readonly, nonatomic) bool hasDataInReadBuffer; /** * @brief Whether the stream can block. * * By default, a stream can block. * On Win32, setting this currently only works for sockets! */ @property (nonatomic) bool canBlock; /** * @brief The delegate for asynchronous operations on the stream. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFStreamDelegate> delegate; /** | > > | > > | > > > > | | 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | @property (readonly, nonatomic) bool hasDataInReadBuffer; /** * @brief Whether the stream can block. * * By default, a stream can block. * On Win32, setting this currently only works for sockets! * * @throw OFSetOptionFailedException The option could not be set */ @property (nonatomic) bool canBlock; /** * @brief The delegate for asynchronous operations on the stream. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFStreamDelegate> delegate; /** * @brief Reads *at most* `length` bytes from the stream into a buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref readIntoBuffer:exactLength:. Note that a read can even return 0 bytes - * this does not necessarily mean that the stream ended, so you still need to * check @ref atEndOfStream. Do not assume that the stream ended just because a * read returned 0 bytes - some streams do internal processing that has a * result of 0 bytes. * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @return The number of bytes read * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (size_t)readIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Reads exactly the specified `length` bytes from the stream into a * buffer. * * Unlike @ref readIntoBuffer:length:, this method does not return when less * than the specified length has been read - instead, it waits until it got * exactly the specified length. * * @warning Only call this when you know that specified amount of data is * available! Otherwise you will get an exception! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading the specified amount * @throw OFNotOpenException The stream is not open */ - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:. Note that a read can even return 0 * bytes - this does not necessarily mean that the stream ended, so you still * need to check @ref atEndOfStream. Do not assume that the stream ended just |
︙ | ︙ | |||
284 285 286 287 288 289 290 | * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length; /** | | | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:. Note that a read can even return 0 * bytes - this does not necessarily mean that the stream ended, so you still * need to check @ref atEndOfStream. Do not assume that the stream ended just |
︙ | ︙ | |||
309 310 311 312 313 314 315 | * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; /** | | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * |
︙ | ︙ | |||
349 350 351 352 353 354 355 | */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** | | | | 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously reads *at most* ref `length` bytes from the stream * into a buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:block:. Note that a read can even * return 0 bytes - this does not necessarily mean that the stream ended, so * you still need to check @ref atEndOfStream. Do not assume that the stream * ended just because a read returned 0 bytes - some streams do internal |
︙ | ︙ | |||
378 379 380 381 382 383 384 | * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block; /** | | | 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads *at most* `length` bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use * @ref asyncReadIntoBuffer:exactLength:block:. Note that a read can even * return 0 bytes - this does not necessarily mean that the stream ended, so * you still need to check @ref atEndOfStream. Do not assume that the stream |
︙ | ︙ | |||
409 410 411 412 413 414 415 | */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; /** | | | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it * waits until it got exactly the specified length, the stream has ended or an * exception occurred. * |
︙ | ︙ | |||
434 435 436 437 438 439 440 | * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block; /** | | | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified `length` bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it * waits until it got exactly the specified length, the stream has ended or an * exception occurred. * |
︙ | ︙ | |||
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | /** * @brief Reads a uint8_t from the stream. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint8_t from the stream */ - (uint8_t)readInt8; /** * @brief Reads a uint16_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess */ - (uint16_t)readBigEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess */ - (uint32_t)readBigEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess */ - (uint64_t)readBigEndianInt64; /** * @brief Reads a float from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess */ - (float)readBigEndianFloat; /** * @brief Reads a double from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess */ - (double)readBigEndianDouble; /** * @brief Reads a uint16_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess */ - (uint16_t)readLittleEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess */ - (uint32_t)readLittleEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess */ - (uint64_t)readLittleEndianInt64; /** * @brief Reads a float from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess */ - (float)readLittleEndianFloat; /** * @brief Reads a double from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess */ - (double)readLittleEndianDouble; /** * @brief Reads the specified number of items with an item size of 1 from the * stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param count The number of items to read * @return OFData with count items. */ - (OFData *)readDataWithCount: (size_t)count; /** * @brief Reads the specified number of items with the specified item size from * the stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. */ - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count; /** * @brief Returns OFData with all the remaining data of the stream. * * @return OFData with an item size of 1 with all the data of the stream until * the end of the stream is reached. */ - (OFData *)readDataUntilEndOfStream; /** * @brief Reads a string with the specified length from the stream. * * If `\0` appears in the stream, the string will be truncated at the `\0` and * the rest of the bytes of the string will be lost. This way, reading from the * stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length */ - (OFString *)readStringWithLength: (size_t)length; /** * @brief Reads a string with the specified encoding and length from the stream. * * If a `\0` appears in the stream, the string will be truncated at the `\0` * and the rest of the bytes of the string will be lost. This way, reading from * the stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param encoding The encoding of the string to read from the stream * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length */ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding; /** * @brief Reads until a newline, `\0` or end of stream occurs. * * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readLine; /** * @brief Reads with the specified encoding until a newline, `\0` or end of * stream occurs. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readLineWithEncoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | /** * @brief Reads a uint8_t from the stream. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint8_t from the stream * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint8_t)readInt8; /** * @brief Reads a uint16_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readBigEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readBigEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readBigEndianInt64; /** * @brief Reads a float from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readBigEndianFloat; /** * @brief Reads a double from the stream which is encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readBigEndianDouble; /** * @brief Reads a uint16_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint16_t from the stream in native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint16_t)readLittleEndianInt16; /** * @brief Reads a uint32_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint32_t from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint32_t)readLittleEndianInt32; /** * @brief Reads a uint64_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A uint64_t from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (uint64_t)readLittleEndianInt64; /** * @brief Reads a float from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A float from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (float)readLittleEndianFloat; /** * @brief Reads a double from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @return A double from the stream in the native endianess * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (double)readLittleEndianDouble; /** * @brief Reads the specified number of items with an item size of 1 from the * stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithCount: (size_t)count; /** * @brief Reads the specified number of items with the specified item size from * the stream and returns them as OFData. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. * @throw OFReadFailedException Reading failed * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count; /** * @brief Returns OFData with all the remaining data of the stream. * * @return OFData with an item size of 1 with all the data of the stream until * the end of the stream is reached. * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (OFData *)readDataUntilEndOfStream; /** * @brief Reads a string with the specified length from the stream. * * If `\0` appears in the stream, the string will be truncated at the `\0` and * the rest of the bytes of the string will be lost. This way, reading from the * stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length; /** * @brief Reads a string with the specified encoding and length from the stream. * * If a `\0` appears in the stream, the string will be truncated at the `\0` * and the rest of the bytes of the string will be lost. This way, reading from * the stream will not break because of a `\0` because the specified number of * bytes is still being read and only the string gets truncated. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param encoding The encoding of the string to read from the stream * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFTruncatedDataException The end of the stream was reached before * reading enough bytes * @throw OFNotOpenException The stream is not open */ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding; /** * @brief Reads until a newline, `\0` or end of stream occurs. * * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readLine; /** * @brief Reads with the specified encoding until a newline, `\0` or end of * stream occurs. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readLineWithEncoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. |
︙ | ︙ | |||
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | /** * @brief Tries to read a line from the stream (see @ref readLine) and returns * `nil` if no complete line has been received yet. * * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet */ - (nullable OFString *)tryReadLine; /** * @brief Tries to read a line from the stream with the specified encoding (see * @ref readLineWithEncoding:) and returns `nil` if no complete line has * been received yet. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet */ - (nullable OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ | > > > > > > > > > > > > | > > > > | | | > > > > | | > > > > | | | 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 | /** * @brief Tries to read a line from the stream (see @ref readLine) and returns * `nil` if no complete line has been received yet. * * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadLine; /** * @brief Tries to read a line from the stream with the specified encoding (see * @ref readLineWithEncoding:) and returns `nil` if no complete line has * been received yet. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readUntilDelimiter: (OFString *)delimiter; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)readUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Tries to reads until the specified string or `\0` is found or the end * of stream (see @ref readUntilDelimiter:) and returns `nil` if not * enough data has been received yet. * * @param delimiter The delimiter * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadUntilDelimiter: (OFString *)delimiter; /** * @brief Tries to read until the specified string or `\0` is found or the end * of stream occurs (see @ref readUntilDelimiter:encoding:) and returns * `nil` if not enough data has been received yet. * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. * @throw OFReadFailedException Reading failed * @throw OFInvalidEncodingException The string read from the stream has * invalid encoding * @throw OFNotOpenException The stream is not open */ - (nullable OFString *)tryReadUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Writes everything in the write buffer to the stream. * * @return Whether the write buffer was flushed entirely. On non-blocking * sockets, this can return `false` if flushing the write buffer in its * entirety would block. |
︙ | ︙ | |||
832 833 834 835 836 837 838 839 840 841 842 843 844 845 | * being set to `EWOULDBLOCK` or `EAGAIN` (you need to check for both, as they * are not the same on some systems) and * @ref OFWriteFailedException#bytesWritten being set to the number of bytes * that were written, if any. * * @param buffer The buffer from which the data is written into the stream * @param length The length of the data that should be written */ - (void)writeBuffer: (const void *)buffer length: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously writes data into the stream. * | > > | 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | * being set to `EWOULDBLOCK` or `EAGAIN` (you need to check for both, as they * are not the same on some systems) and * @ref OFWriteFailedException#bytesWritten being set to the number of bytes * that were written, if any. * * @param buffer The buffer from which the data is written into the stream * @param length The length of the data that should be written * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBuffer: (const void *)buffer length: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously writes data into the stream. * |
︙ | ︙ | |||
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 | /** * @brief Writes a uint8_t into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int8 A uint8_t */ - (void)writeInt8: (uint8_t)int8; /** * @brief Writes a uint16_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t */ - (void)writeBigEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t */ - (void)writeBigEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t */ - (void)writeBigEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float */ - (void)writeBigEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double */ - (void)writeBigEndianDouble: (double)double_; /** * @brief Writes a uint16_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t */ - (void)writeLittleEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t */ - (void)writeLittleEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t */ - (void)writeLittleEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float */ - (void)writeLittleEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double */ - (void)writeLittleEndianDouble: (double)double_; /** * @brief Writes OFData into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param data The OFData to write into the stream */ - (void)writeData: (OFData *)data; /** * @brief Writes a string into the stream, without the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream */ - (void)writeString: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding, without * the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream */ - (void)writeString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a string into the stream with a trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream */ - (void)writeLine: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding with a * trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream */ - (void)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format */ - (void)writeFormat: (OFConstantString *)format, ...; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format * @param arguments The arguments used in the format string */ - (void)writeFormat: (OFConstantString *)format arguments: (va_list)arguments; #ifdef OF_HAVE_SOCKETS /** * @brief Cancels all pending asynchronous requests on the stream. */ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 | /** * @brief Writes a uint8_t into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int8 A uint8_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeInt8: (uint8_t)int8; /** * @brief Writes a uint16_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in big endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeBigEndianDouble: (double)double_; /** * @brief Writes a uint16_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int16 A uint16_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt16: (uint16_t)int16; /** * @brief Writes a uint32_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int32 A uint32_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt32: (uint32_t)int32; /** * @brief Writes a uint64_t into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param int64 A uint64_t * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianInt64: (uint64_t)int64; /** * @brief Writes a float into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param float_ A float * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianFloat: (float)float_; /** * @brief Writes a double into the stream, encoded in little endian. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param double_ A double * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLittleEndianDouble: (double)double_; /** * @brief Writes OFData into the stream. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param data The OFData to write into the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeData: (OFData *)data; /** * @brief Writes a string into the stream, without the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeString: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding, without * the trailing zero. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a string into the stream with a trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLine: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding with a * trailing newline. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (void)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open * @throw OFInvalidFormatException The specified format is invalid */ - (void)writeFormat: (OFConstantString *)format, ...; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * In non-blocking mode, the behavior is the same as @ref writeBuffer:length:. * * @param format A string used as format * @param arguments The arguments used in the format string * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open * @throw OFInvalidFormatException The specified format is invalid */ - (void)writeFormat: (OFConstantString *)format arguments: (va_list)arguments; #ifdef OF_HAVE_SOCKETS /** * @brief Cancels all pending asynchronous requests on the stream. */ |
︙ | ︙ | |||
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 | */ - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length; /** * @brief Closes the stream. * * @note If you override this, make sure to call `[super close]`! */ - (void)close; /** * @brief Performs a lowlevel read. * * @warning Do not call this directly! * * @note Override this method with your actual read implementation when * subclassing! * * @param buffer The buffer for the data to read * @param length The length of the buffer * @return The number of bytes read */ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Performs a lowlevel write. * * @warning Do not call this directly! * * @note Override this method with your actual write implementation when * subclassing! * * @param buffer The buffer with the data to write * @param length The length of the data to write * @return The number of bytes written */ - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length; /** * @brief Returns whether the lowlevel is at the end of the stream. * * @warning Do not call this directly! | > > > > > > | 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 | */ - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length; /** * @brief Closes the stream. * * @note If you override this, make sure to call `[super close]`! * * @throw OFNotOpenException The stream is not open */ - (void)close; /** * @brief Performs a lowlevel read. * * @warning Do not call this directly! * * @note Override this method with your actual read implementation when * subclassing! * * @param buffer The buffer for the data to read * @param length The length of the buffer * @return The number of bytes read * @throw OFReadFailedException Reading failed * @throw OFNotOpenException The stream is not open */ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Performs a lowlevel write. * * @warning Do not call this directly! * * @note Override this method with your actual write implementation when * subclassing! * * @param buffer The buffer with the data to write * @param length The length of the data to write * @return The number of bytes written * @throw OFWriteFailedException Writing failed * @throw OFNotOpenException The stream is not open */ - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length; /** * @brief Returns whether the lowlevel is at the end of the stream. * * @warning Do not call this directly! |
︙ | ︙ |
Modified src/OFStream.m from [7df47f7053] to [e660892e5a].
︙ | ︙ | |||
670 671 672 673 674 675 676 | #endif - (OFString *)tryReadLine { return [self tryReadLineWithEncoding: OFStringEncodingUTF8]; } | | | | 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | #endif - (OFString *)tryReadLine { return [self tryReadLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)tryReadUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; |
︙ | ︙ | |||
832 833 834 835 836 837 838 | } _waitingForDelimiter = true; return nil; } | | | | | | | | | | | | 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 | } _waitingForDelimiter = true; return nil; } - (OFString *)readUntilDelimiter: (OFString *)delimiter { return [self readUntilDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (OFString *)readUntilDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { OFString *ret = nil; while ((ret = [self tryReadUntilDelimiter: delimiter encoding: encoding]) == nil) if (self.atEndOfStream) return nil; return ret; } - (OFString *)tryReadUntilDelimiter: (OFString *)delimiter { return [self tryReadUntilDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (bool)flushWriteBuffer { size_t bytesWritten; if (_writeBuffer == NULL) |
︙ | ︙ |
Modified src/OFStreamSocket.h from [5c1a8b3304] to [310cc8cd98].
︙ | ︙ | |||
76 77 78 79 80 81 82 83 84 85 86 87 88 89 | */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are | > > > | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! * * @throw OFNotOpenException The socket is not open * @throw OFInvalidArgumentException The socket has no remote address */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are |
︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | */ + (instancetype)socket; /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. */ - (void)listen; /** * @brief Accept an incoming connection. * * @return An autoreleased OFStreamSocket for the accepted connection. */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; | > > > > > > > | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | */ + (instancetype)socket; /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. * @throw OFListenFailedException Listening failed * @throw OFNotOpenException The socket is not open */ - (void)listenWithBacklog: (int)backlog; /** * @brief Listen on the socket. * * @throw OFListenFailedException 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 OFNotOpenException The socket is not open */ - (instancetype)accept; /** * @brief Asynchronously accept an incoming connection. */ - (void)asyncAccept; |
︙ | ︙ |
Modified src/OFString+JSONParsing.h from [ace137eeef] to [77287ce8c5].
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. */ @property (readonly, nonatomic) id objectByParsingJSON; /** * @brief Creates an object from the JSON value of the string. * * @note This also allows parsing JSON5, an extension of JSON. See * http://json5.org/ for more details. * * @warning Although not specified by the JSON specification, this can also * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) | > > < > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. * * @throw OFInvalidJSONException The string contained invalid JSON */ @property (readonly, nonatomic) id objectByParsingJSON; /** * @brief Creates an object from the JSON value of the string. * * @note This also allows parsing JSON5, an extension of JSON. See * http://json5.org/ for more details. * * @warning Although not specified by the JSON specification, this can also * return primitives like strings and numbers. The rationale behind * this is that most JSON parsers allow JSON data just consisting of a * single primitive, leading to real world JSON files sometimes only * consisting of a single primitive. Therefore, you should not make any * assumptions about the object returned by this method if you don't * want your program to terminate due to a message not understood, but * instead check the returned object using @ref isKindOfClass:. * * @param depthLimit The maximum depth the parser should accept (defaults to 32 * if not specified, 0 means no limit (insecure!)) * @return An object * @throw OFInvalidJSONException The string contained invalid JSON */ - (id)objectByParsingJSONWithDepthLimit: (size_t)depthLimit; @end OF_ASSUME_NONNULL_END |
Modified src/OFString+PathAdditions.h from [2a2be8d086] to [01351c2d45].
︙ | ︙ | |||
82 83 84 85 86 87 88 | * * @param extension The extension to append * @return A new, autoreleased OFString with the path extension appended */ - (OFString *)stringByAppendingPathExtension: (OFString *)extension; - (bool)of_isDirectoryPath; | | | | | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | * * @param extension The extension to append * @return A new, autoreleased OFString with the path extension appended */ - (OFString *)stringByAppendingPathExtension: (OFString *)extension; - (bool)of_isDirectoryPath; - (OFString *)of_pathToURIPathWithPercentEncodedHost: (OFString *__autoreleasing _Nullable *_Nonnull)percentEncodedHost; - (OFString *)of_URIPathToPathWithPercentEncodedHost: (nullable OFString *)percentEncodedHost; - (OFString *)of_pathComponentToURIPathComponent; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFString+URLEncoding.h [b50441492b] to src/OFString+PercentEncoding.h [8762d6fc4c].
︙ | ︙ | |||
18 19 20 21 22 23 24 | OF_ASSUME_NONNULL_BEGIN @class OFCharacterSet; #ifdef __cplusplus extern "C" { #endif | | | | > > | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | OF_ASSUME_NONNULL_BEGIN @class OFCharacterSet; #ifdef __cplusplus extern "C" { #endif extern int _OFString_PercentEncoding_reference; #ifdef __cplusplus } #endif @interface OFString (PercentEncoding) /** * @brief The string with percent encoding removed. * * @throw OFInvalidFormatException The string is not in proper percent encoding */ @property (readonly, nonatomic) OFString *stringByRemovingPercentEncoding; /** * @brief Percent-encodes a string for use in a URI, but does not escape the * specified allowed characters. * * @param allowedCharacters A character set of characters that should not be * escaped * * @return A new autoreleased string */ - (OFString *)stringByAddingPercentEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFString+URLEncoding.m [7c362d8c35] to src/OFString+PercentEncoding.m [46a599b120].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <stdlib.h> #include <string.h> | | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | */ #include "config.h" #include <stdlib.h> #include <string.h> #import "OFString+PercentEncoding.h" #import "OFCharacterSet.h" #import "OFInvalidFormatException.h" #import "OFInvalidEncodingException.h" #import "OFOutOfMemoryException.h" /* Reference for static linking */ int _OFString_PercentEncoding_reference; @implementation OFString (PercentEncoding) - (OFString *)stringByAddingPercentEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = |
︙ | ︙ | |||
71 72 73 74 75 76 77 | } objc_autoreleasePoolPop(pool); return ret; } | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | } objc_autoreleasePoolPop(pool); return ret; } - (OFString *)stringByRemovingPercentEncoding { void *pool = objc_autoreleasePoolPush(); const char *string = self.UTF8String; size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; |
︙ | ︙ |
Modified src/OFString+PropertyListParsing.h from [c22c9f1090] to [6aa9059d9b].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 | #endif @interface OFString (PropertyListParsing) /** * @brief The string interpreted as a property list and parsed as an object. * * @note This only supports XML property lists! */ @property (readonly, nonatomic) id objectByParsingPropertyList; @end OF_ASSUME_NONNULL_END | > > > > > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #endif @interface OFString (PropertyListParsing) /** * @brief The string interpreted as a property list and parsed as an object. * * @note This only supports XML property lists! * * @throw OFInvalidFormatException The string is not in correct XML property * list format * @throw OFUnsupportedVersionException The property list is using a version * that is not supported */ @property (readonly, nonatomic) id objectByParsingPropertyList; @end OF_ASSUME_NONNULL_END |
Modified src/OFString.h from [b34719db3c] to [9816b06102].
︙ | ︙ | |||
95 96 97 98 99 100 101 | /** Mac OS Roman */ OFStringEncodingMacRoman, /** KOI8-R */ OFStringEncodingKOI8R, /** KOI8-U */ OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | /** Mac OS Roman */ OFStringEncodingMacRoman, /** KOI8-R */ OFStringEncodingKOI8R, /** KOI8-U */ OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ OFStringEncodingAutodetect = -1 } OFStringEncoding; /** * @brief Options for searching in strings. * * This is a bit mask. */ |
︙ | ︙ | |||
132 133 134 135 136 137 138 | */ typedef void (^OFStringLineEnumerationBlock)(OFString *line, bool *stop); #endif #ifdef __OBJC__ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | */ typedef void (^OFStringLineEnumerationBlock)(OFString *line, bool *stop); #endif #ifdef __OBJC__ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFURI; /** * @class OFString OFString.h ObjFW/OFString.h * * @brief A class for handling strings. */ @interface OFString: OFObject <OFCopying, OFMutableCopying, OFComparing, |
︙ | ︙ | |||
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | /** * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFUnichar *characters OF_RETURNS_INNER_POINTER; /** * @brief The string in UTF-16 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFChar16 *UTF16String OF_RETURNS_INNER_POINTER; /** * @brief The length of the string in UTF-16 characters. */ @property (readonly, nonatomic) size_t UTF16StringLength; /** * @brief The string in UTF-32 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFChar32 *UTF32String OF_RETURNS_INNER_POINTER; /** * @brief The string with leading whitespaces deleted. */ | > > > > > > | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | /** * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is *not* null-terminated. */ @property (readonly, nonatomic) const OFUnichar *characters OF_RETURNS_INNER_POINTER; /** * @brief The string in UTF-16 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. */ @property (readonly, nonatomic) const OFChar16 *UTF16String OF_RETURNS_INNER_POINTER; /** * @brief The length of the string in UTF-16 characters. */ @property (readonly, nonatomic) size_t UTF16StringLength; /** * @brief The string in UTF-32 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. */ @property (readonly, nonatomic) const OFChar32 *UTF32String OF_RETURNS_INNER_POINTER; /** * @brief The string with leading whitespaces deleted. */ |
︙ | ︙ | |||
409 410 411 412 413 414 415 | */ + (instancetype)stringWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string. * | | | | | | | | | | 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | */ + (instancetype)stringWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string A zero-terminated UTF-16 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string, 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 A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @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 */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string. * * @param string A zero-terminated UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-32 encoded string, assuming the * specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; |
︙ | ︙ | |||
529 530 531 532 533 534 535 | * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** | | | | | | | | | | 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Creates a new OFString with the contents of the specified URI. * * If the URI's scheme is file, it tries UTF-8 encoding. * * If the URI's scheme is http(s), it tries to detect the encoding from the HTTP * 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 */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI; /** * @brief Creates a new OFString with the contents of the specified URI in the * specified encoding. * * @param URI The URI to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** * @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 |
︙ | ︙ | |||
667 668 669 670 671 672 673 | */ - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string. * | | | | | | | | | | 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 | */ - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string. * * @param string A zero-terminated UTF-16 string * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length. * * @param string A zero-terminated UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string, * 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 */ - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @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 */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string. * * @param string A zero-terminated UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-32 string, * assuming the specified byte order if no byte order mark is found. * * @param string A zero-terminated UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @param string A zero-terminated UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; |
︙ | ︙ | |||
802 803 804 805 806 807 808 | */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Initializes an already allocated OFString with the contents of the | | | | | | | | | | 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 | */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Initializes an already allocated OFString with the contents of the * specified URI. * * If the URI's scheme is file, it tries UTF-8 encoding. * * If the URI's scheme is http(s), it tries to detect the encoding from the HTTP * 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 */ - (instancetype)initWithContentsOfURI: (OFURI *)URI; /** * @brief Initializes an already allocated OFString with the contents of the * 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 */ - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding. * * @param cString The C string to write into |
︙ | ︙ | |||
1042 1043 1044 1045 1046 1047 1048 | * * @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 */ | | | | 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 | * * @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 */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The value of the string in the specified base as an * `unsigned long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an * @ref OFInvalidFormatException is thrown. * * If the number is too big to fit into an `unsigned long long`, an * @ref OFOutOfRangeException is thrown. * * @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 */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; /** * @brief Creates a new string by appending another string. * * @param string The string to append * @return A new, autoreleased OFString with the specified string appended */ |
︙ | ︙ | |||
1090 1091 1092 1093 1094 1095 1096 | * @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 */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; | < < < < < < < < | | 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 | * @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 */ - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments; /** * @brief Creates a new string by replacing the occurrences of the specified * string with the specified replacement. * * @param string The string to replace * @param replacement The string with which it should be replaced * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement; /** * @brief Creates a new string by replacing the occurrences of the specified * string in the specified range with the specified replacement. * * @param string The string to replace * @param replacement The string with which it should be replaced * @param options Options modifying search behaviour. * Possible values are: * * None yet, pass 0 * @param range The range in which to replace the string * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range; |
︙ | ︙ | |||
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | /** * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** * @brief Returns the string in UTF-32 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param byteOrder The byte order for the UTF-32 encoding * @return The string in UTF-32 encoding with the specified byte order */ - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; | > > > > | 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | /** * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * 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 */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** * @brief Returns the string in UTF-32 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * The returned string is null-terminated. * * @param byteOrder The byte order for the UTF-32 encoding * @return The string in UTF-32 encoding with the specified byte order */ - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; |
︙ | ︙ | |||
1239 1240 1241 1242 1243 1244 1245 | * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** | | | | | | | | | 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 | * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Writes the string to the specified URI using UTF-8 encoding. * * @param URI The URI to write to */ - (void)writeToURI: (OFURI *)URI; /** * @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 */ - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_BLOCKS /** * Enumerates all lines in the receiver using the specified block. * * @brief block The block to call for each line */ |
︙ | ︙ | |||
1306 1307 1308 1309 1310 1311 1312 | #include "OFMutableString.h" #ifdef __OBJC__ # import "OFString+CryptographicHashing.h" # import "OFString+JSONParsing.h" # ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" # endif | | | | | 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 | #include "OFMutableString.h" #ifdef __OBJC__ # import "OFString+CryptographicHashing.h" # import "OFString+JSONParsing.h" # ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" # endif # import "OFString+PercentEncoding.h" # import "OFString+PropertyListParsing.h" # import "OFString+Serialization.h" # import "OFString+XMLEscaping.h" # import "OFString+XMLUnescaping.h" #endif #if defined(__OBJC__) && !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* * Very *ugly* hack required for string boxing literals to work. |
︙ | ︙ |
Modified src/OFString.m from [0292b59c78] to [66ea400d53].
︙ | ︙ | |||
38 39 40 41 42 43 44 | #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFLocale.h" #import "OFStream.h" #import "OFSystemInfo.h" | | | > < | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFLocale.h" #import "OFStream.h" #import "OFSystemInfo.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFXMLElement.h" #import "OFGetItemAttributesFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "unicode.h" /* * It seems strtod is buggy on Win32. |
︙ | ︙ | |||
129 130 131 132 133 134 135 136 137 | _references_to_categories_of_OFString(void) { _OFString_CryptographicHashing_reference = 1; _OFString_JSONParsing_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PropertyListParsing_reference = 1; _OFString_Serialization_reference = 1; | > < | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | _references_to_categories_of_OFString(void) { _OFString_CryptographicHashing_reference = 1; _OFString_JSONParsing_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PercentEncoding_reference = 1; _OFString_PropertyListParsing_reference = 1; _OFString_Serialization_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void _reference_to_OFConstantString(void) { |
︙ | ︙ | |||
578 579 580 581 582 583 584 | encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif | | | | | | 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI { return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI]; } - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI encoding: encoding]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { return (id)[[OFUTF8String alloc] initWithSerialization: element]; } |
︙ | ︙ | |||
792 793 794 795 796 797 798 | encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } #endif | | | | | | 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } #endif + (instancetype)stringWithContentsOfURI: (OFURI *)URI { return [[[self alloc] initWithContentsOfURI: URI] autorelease]; } + (instancetype)stringWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfURI: URI encoding: encoding] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFString class]]) { @try { |
︙ | ︙ | |||
1000 1001 1002 1003 1004 1005 1006 | @try { void *pool = objc_autoreleasePoolPush(); OFFile *file = nil; @try { fileSize = [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; | | | 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | @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); |
︙ | ︙ | |||
1062 1063 1064 1065 1066 1067 1068 | } } return self; } #endif | | | | | | 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 | } } return self; } #endif - (instancetype)initWithContentsOfURI: (OFURI *)URI { return [self initWithContentsOfURI: URI encoding: OFStringEncodingAutodetect]; } - (instancetype)initWithContentsOfURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data; @try { data = [OFData dataWithContentsOfURI: URI]; } @catch (id e) { [self release]; @throw e; } /* FIXME: Detect encoding where we can. */ if (encoding == OFStringEncodingAutodetect) |
︙ | ︙ | |||
1349 1350 1351 1352 1353 1354 1355 | @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif default: | | < | 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif default: @throw [OFInvalidArgumentException exception]; } } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { |
︙ | ︙ | |||
1431 1432 1433 1434 1435 1436 1437 | } @catch (id e) { OFFreeMemory(cString); @throw e; } break; default: | | | 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 | } @catch (id e) { OFFreeMemory(cString); @throw e; } break; default: @throw [OFInvalidArgumentException exception]; } @try { ret = [[OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true] items]; } @catch (id e) { |
︙ | ︙ | |||
1502 1503 1504 1505 1506 1507 1508 | case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: return self.length; default: | | | 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 | case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: return self.length; default: @throw [OFInvalidArgumentException exception]; } } - (size_t)UTF8StringLength { return [self cStringLengthWithEncoding: OFStringEncodingUTF8]; } |
︙ | ︙ | |||
1681 1682 1683 1684 1685 1686 1687 | unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < length; i++) { const OFUnichar c = characters[i]; | | | | | 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 | unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < length; i++) { const OFUnichar c = characters[i]; OFHashAddByte(&hash, (c & 0xFF0000) >> 16); OFHashAddByte(&hash, (c & 0x00FF00) >> 8); OFHashAddByte(&hash, c & 0x0000FF); } OFHashFinalize(&hash); return hash; } |
︙ | ︙ | |||
1752 1753 1754 1755 1756 1757 1758 | if (options & OFJSONRepresentationOptionIsIdentifier) { const char *cString = self.UTF8String; if ((!OFASCIIIsAlpha(cString[0]) && cString[0] != '_' && cString[0] != '$') || strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) { | | | | | 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 | if (options & OFJSONRepresentationOptionIsIdentifier) { const char *cString = self.UTF8String; if ((!OFASCIIIsAlpha(cString[0]) && cString[0] != '_' && cString[0] != '$') || strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) { [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } } else { [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } } else { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [JSON insertString: @"\"" atIndex: 0]; [JSON appendString: @"\""]; } [JSON makeImmutable]; return JSON; } |
︙ | ︙ | |||
1816 1817 1818 1819 1820 1821 1822 | return data; } - (OFRange)rangeOfString: (OFString *)string { return [self rangeOfString: string options: 0 | | | | | | | | | | | 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 | return data; } - (OFRange)rangeOfString: (OFString *)string { return [self rangeOfString: string options: 0 range: OFMakeRange(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options { return [self rangeOfString: string options: options range: OFMakeRange(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { void *pool; const OFUnichar *searchCharacters; OFUnichar *characters; size_t searchLength; if ((searchLength = string.length) == 0) return OFMakeRange(0, 0); if (searchLength > range.length) return OFMakeRange(OFNotFound, 0); if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFMakeRange(range.location + i, searchLength); } /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFMakeRange(range.location + i, searchLength); } } } } @finally { OFFreeMemory(characters); } objc_autoreleasePoolPop(pool); return OFMakeRange(OFNotFound, 0); } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { return [self indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options { return [self indexOfCharacterFromSet: characterSet options: options range: OFMakeRange(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range { bool (*characterIsMember)(id, SEL, OFUnichar) = |
︙ | ︙ | |||
1977 1978 1979 1980 1981 1982 1983 | objc_autoreleasePoolPop(pool); return false; } - (OFString *)substringFromIndex: (size_t)idx { | | | | 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 | objc_autoreleasePoolPop(pool); return false; } - (OFString *)substringFromIndex: (size_t)idx { return [self substringWithRange: OFMakeRange(idx, self.length - idx)]; } - (OFString *)substringToIndex: (size_t)idx { return [self substringWithRange: OFMakeRange(0, idx)]; } - (OFString *)substringWithRange: (OFRange)range { void *pool; OFString *ret; |
︙ | ︙ | |||
2036 2037 2038 2039 2040 2041 2042 | { OFMutableString *new = [OFMutableString stringWithString: self]; [new appendFormat: format arguments: arguments]; [new makeImmutable]; return new; } | < < < < < < < < | 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 | { OFMutableString *new = [OFMutableString stringWithString: self]; [new appendFormat: format arguments: arguments]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement]; [new makeImmutable]; return new; |
︙ | ︙ | |||
2128 2129 2130 2131 2132 2133 2134 | if ((prefixLength = prefix.length) > self.length) return false; tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); | | | 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 | if ((prefixLength = prefix.length) > self.length) return false; tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFMakeRange(0, prefixLength)]; hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { OFFreeMemory(tmp); |
︙ | ︙ | |||
2158 2159 2160 2161 2162 2163 2164 | length = self.length; tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp | | | 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 | length = self.length; tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFMakeRange(length - suffixLength, suffixLength)]; suffixCharacters = suffix.characters; hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
2218 2219 2220 2221 2222 2223 2224 | last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(OFUnichar)) != 0) continue; component = [self substringWithRange: | | | | 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 | last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(OFUnichar)) != 0) continue; component = [self substringWithRange: OFMakeRange(last, i - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; i += delimiterLength - 1; last = i + 1; } component = [self substringWithRange: OFMakeRange(last, length - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; [array makeImmutable]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
2263 2264 2265 2266 2267 2268 2269 | last = 0; for (size_t i = 0; i < length; i++) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) { if (!skipEmpty || i != last) { OFString *component = [self substringWithRange: | | | | | 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 | last = 0; for (size_t i = 0; i < length; i++) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) { if (!skipEmpty || i != last) { OFString *component = [self substringWithRange: OFMakeRange(last, i - last)]; [array addObject: component]; } last = i + 1; } } if (!skipEmpty || length != last) { OFString *component = [self substringWithRange: OFMakeRange(last, length - last)]; [array addObject: component]; } [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (long long)longLongValue { return [self longLongValueWithBase: 10]; } - (long long)longLongValueWithBase: (unsigned char)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; bool negative = false; long long value = 0; while (OFASCIIIsSpace(*UTF8String)) |
︙ | ︙ | |||
2364 2365 2366 2367 2368 2369 2370 | } - (unsigned long long)unsignedLongLongValue { return [self unsignedLongLongValueWithBase: 10]; } | | | 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 | } - (unsigned long long)unsignedLongLongValue { return [self unsignedLongLongValueWithBase: 10]; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; unsigned long long value = 0; while (OFASCIIIsSpace(*UTF8String)) UTF8String++; |
︙ | ︙ | |||
2455 2456 2457 2458 2459 2460 2461 | #ifdef HAVE_STRTOF_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtof_l, we have no other choice but to replace "." * with the locale's decimal point. */ | | | | 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 | #ifdef HAVE_STRTOF_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtof_l, we have no other choice but to replace "." * with the locale's decimal point. */ OFString *decimalSeparator = [OFLocale decimalSeparator]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalSeparator].UTF8String; #endif char *endPtr = NULL; float value; errno = 0; #ifdef HAVE_STRTOF_L value = strtof_l(UTF8String, &endPtr, cLocale); |
︙ | ︙ | |||
2508 2509 2510 2511 2512 2513 2514 | #ifdef HAVE_STRTOD_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtod_l, we have no other choice but to replace "." * with the locale's decimal point. */ | | | | 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 | #ifdef HAVE_STRTOD_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtod_l, we have no other choice but to replace "." * with the locale's decimal point. */ OFString *decimalSeparator = [OFLocale decimalSeparator]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalSeparator].UTF8String; #endif char *endPtr = NULL; double value; errno = 0; #ifdef HAVE_STRTOD_L value = strtod_l(UTF8String, &endPtr, cLocale); |
︙ | ︙ | |||
2546 2547 2548 2549 2550 2551 2552 | { size_t length = self.length; OFUnichar *buffer; const OFUnichar *ret; buffer = OFAllocMemory(length, sizeof(OFUnichar)); @try { | | | 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 | { size_t length = self.length; OFUnichar *buffer; const OFUnichar *ret; buffer = OFAllocMemory(length, sizeof(OFUnichar)); @try { [self getCharacters: buffer inRange: OFMakeRange(0, length)]; ret = [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); |
︙ | ︙ | |||
2654 2655 2656 2657 2658 2659 2660 | { size_t length = self.length; OFChar32 *buffer; const OFChar32 *ret; buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { | | | 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 | { size_t length = self.length; OFChar32 *buffer; const OFChar32 *ret; buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { [self getCharacters: buffer inRange: OFMakeRange(0, length)]; buffer[length] = 0; if (byteOrder != OFByteOrderNative) for (size_t i = 0; i < length; i++) buffer[i] = OFByteSwap32(buffer[i]); ret = [[OFData dataWithItemsNoCopy: buffer |
︙ | ︙ | |||
2746 2747 2748 2749 2750 2751 2752 | void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #endif | | | | < < < < | | 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 | void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #endif - (void)writeToURI: (OFURI *)URI { [self writeToURI: URI encoding: OFStringEncodingUTF8]; } - (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFStream *stream; stream = [OFURIHandler openItemAtURI: URI mode: @"w"]; [stream writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block |
︙ | ︙ | |||
2786 2787 2788 2789 2790 2791 2792 | continue; } if (characters[i] == '\n' || characters[i] == '\r') { void *pool2 = objc_autoreleasePoolPush(); block([self substringWithRange: | | | | 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 | continue; } if (characters[i] == '\n' || characters[i] == '\r') { void *pool2 = objc_autoreleasePoolPush(); block([self substringWithRange: OFMakeRange(last, i - last)], &stop); last = i + 1; objc_autoreleasePoolPop(pool2); } lastCarriageReturn = (characters[i] == '\r'); } if (!stop) block([self substringWithRange: OFMakeRange(last, i - last)], &stop); objc_autoreleasePoolPop(pool); } #endif @end |
Modified src/OFSystemInfo.h from [b9e5001c12] to [8b4f866788].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN | | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | */ #import "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFSystemInfo OFSystemInfo.h ObjFW/OFSystemInfo.h * * @brief A class for querying information about the system. */ OF_SUBCLASSING_RESTRICTED @interface OFSystemInfo: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) size_t pageSize; @property (class, readonly, nonatomic) size_t numberOfCPUs; @property (class, readonly, nonatomic) OFString *ObjFWVersion; @property (class, readonly, nonatomic) unsigned short ObjFWVersionMajor; @property (class, readonly, nonatomic) unsigned short ObjFWVersionMinor; @property (class, readonly, nullable, nonatomic) OFString *operatingSystemName; @property (class, readonly, nullable, nonatomic) OFString *operatingSystemVersion; @property (class, readonly, nullable, nonatomic) OFURI *userDataURI; @property (class, readonly, nullable, nonatomic) OFURI *userConfigURI; @property (class, readonly, nullable, nonatomic) OFURI *temporaryDirectoryURI; @property (class, readonly, nullable, nonatomic) OFString *CPUVendor; @property (class, readonly, nullable, nonatomic) OFString *CPUModel; # if defined(OF_X86_64) || defined(OF_X86) || defined(DOXYGEN) @property (class, readonly, nonatomic) bool supportsMMX; @property (class, readonly, nonatomic) bool supportsSSE; @property (class, readonly, nonatomic) bool supportsSSE2; @property (class, readonly, nonatomic) bool supportsSSE3; |
︙ | ︙ | |||
122 123 124 125 126 127 128 | * On macOS and iOS, it uses the `NSApplicationSupportDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory.@n * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user data for the application can be stored */ | | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | * On macOS and iOS, it uses the `NSApplicationSupportDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory.@n * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user data for the application can be stored */ + (nullable OFURI *)userDataURI; /** * @brief Returns the path where user configuration for the application can be * stored. * * On UNIX systems, this adheres to the XDG Base Directory specification.@n * On macOS and iOS, it uses the `Preferences` directory inside of * `NSLibraryDirectory` directory.@n * On Windows, it uses the `APPDATA` environment variable.@n * On Haiku, it uses the `B_USER_SETTINGS_DIRECTORY` directory. * On AmigaOS and MorphOS, it returns `PROGDIR:`. * * @return The path where user configuration for the application can be stored */ + (nullable OFURI *)userConfigURI; /** * @brief Returns a path where temporary files for can be stored. * * If possible, returns a temporary directory for the user, otherwise returns a * global temporary directory. * * On UNIX systems, this adheres to the XDG Base Directory specification and * returns `/tmp` if `XDG_RUNTIME_DIR` is not set.@n * On macOS and iOS, this uses `_CS_DARWIN_USER_TEMP_DIR`, falling back to * `/tmp` if this fails.@n * On Windows, it uses `GetTempPath`.@n * On Haiku, it uses the `B_SYSTEM_TEMP_DIRECTORY` directory. * On AmigaOS and MorphOS, it returns `T:`. * * @return A path where temporary files can be stored */ + (nullable OFURI *)temporaryDirectoryURI; /** * @brief Returns the vendor of the CPU. * * If the vendor could not be determined, `nil` is returned instead. * * @return The vendor of the CPU |
︙ | ︙ |
Modified src/OFSystemInfo.m from [9f029f0dfb] to [fb8661ad24].
︙ | ︙ | |||
50 51 52 53 54 55 56 | #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFOnce.h" #import "OFString.h" | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFOnce.h" #import "OFString.h" #import "OFURI.h" #if defined(OF_MACOS) || defined(OF_IOS) # ifdef HAVE_SYSDIR_H # include <sysdir.h> # endif #endif #ifdef OF_WINDOWS |
︙ | ︙ | |||
238 239 240 241 242 243 244 | operatingSystemVersion = [[OFString alloc] initWithCString: utsname.release encoding: [OFLocale encoding]]; #endif } #ifdef OF_NINTENDO_SWITCH | | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | operatingSystemVersion = [[OFString alloc] initWithCString: utsname.release encoding: [OFLocale encoding]]; #endif } #ifdef OF_NINTENDO_SWITCH static OFURI *tmpFSURI = nil; static void mountTmpFS(void) { if (R_SUCCEEDED(fsdevMountTemporaryStorage("tmpfs"))) tmpFSURI = [[OFURI alloc] initFileURIWithPath: @"tmpfs:/" isDirectory: true]; } #endif #if defined(OF_X86_64) || defined(OF_X86) static OF_INLINE struct X86Regs OF_CONST_FUNC x86CPUID(uint32_t eax, uint32_t ecx) |
︙ | ︙ | |||
360 361 362 363 364 365 366 | { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemVersion); return operatingSystemVersion; } | | | 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemVersion); return operatingSystemVersion; } + (OFURI *)userDataURI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char pathC[PATH_MAX]; OFMutableString *path; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION |
︙ | ︙ | |||
396 397 398 399 400 401 402 | if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; | | | | | | | | | | | | | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; [path deleteCharactersInRange: OFMakeRange(0, 1)]; [path insertString: home atIndex: 0]; } [path makeImmutable]; return [OFURI fileURIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFDictionary *env = [OFApplication environment]; OFString *appData; if ((appData = [env objectForKey: @"APPDATA"]) == nil) return nil; return [OFURI fileURIWithPath: appData isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFURI fileURIWithPath: @"PROGDIR:" isDirectory: true]; # else OFDictionary *env = [OFApplication environment]; OFString *var; OFURI *URI; void *pool; if ((var = [env objectForKey: @"XDG_DATA_HOME"]) != nil && var.length > 0) return [OFURI fileURIWithPath: var isDirectory: true]; if ((var = [env objectForKey: @"HOME"]) == nil) return nil; pool = objc_autoreleasePoolPush(); var = [OFString pathWithComponents: [OFArray arrayWithObjects: var, @".local", @"share", nil]]; URI = [[OFURI alloc] initFileURIWithPath: var isDirectory: true]; objc_autoreleasePoolPop(pool); return [URI autorelease]; # endif #else return nil; #endif } + (OFURI *)userConfigURI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char pathC[PATH_MAX]; OFMutableString *path; # ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION |
︙ | ︙ | |||
485 486 487 488 489 490 491 | if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; | | | | | | | | | | | | | | | | | | | | | 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | if ([path hasPrefix: @"~"]) { OFDictionary *env = [OFApplication environment]; OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) return nil; [path deleteCharactersInRange: OFMakeRange(0, 1)]; [path insertString: home atIndex: 0]; } [path appendString: @"/Preferences"]; [path makeImmutable]; return [OFURI fileURIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFDictionary *env = [OFApplication environment]; OFString *appData; if ((appData = [env objectForKey: @"APPDATA"]) == nil) return nil; return [OFURI fileURIWithPath: appData isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFURI fileURIWithPath: @"PROGDIR:" isDirectory: true]; # else OFDictionary *env = [OFApplication environment]; OFString *var; if ((var = [env objectForKey: @"XDG_CONFIG_HOME"]) != nil && var.length > 0) return [OFURI fileURIWithPath: var isDirectory: true]; if ((var = [env objectForKey: @"HOME"]) == nil) return nil; var = [var stringByAppendingPathComponent: @".config"]; return [OFURI fileURIWithPath: var isDirectory: true]; # endif #else return nil; #endif } + (OFURI *)temporaryDirectoryURI { #ifdef OF_HAVE_FILES # if defined(OF_MACOS) || defined(OF_IOS) char buffer[PATH_MAX]; size_t length; OFString *path; if ((length = confstr(_CS_DARWIN_USER_TEMP_DIR, buffer, PATH_MAX)) == 0) return [OFURI fileURIWithPath: @"/tmp" isDirectory: true]; path = [OFString stringWithCString: buffer encoding: [OFLocale encoding] length: length - 1]; return [OFURI fileURIWithPath: path isDirectory: true]; # elif defined(OF_WINDOWS) OFString *path; if ([self isWindowsNT]) { wchar_t buffer[PATH_MAX]; if (!GetTempPathW(PATH_MAX, buffer)) return nil; path = [OFString stringWithUTF16String: buffer]; } else { char buffer[PATH_MAX]; if (!GetTempPathA(PATH_MAX, buffer)) return nil; path = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; } return [OFURI fileURIWithPath: path isDirectory: true]; # elif defined(OF_HAIKU) char pathC[PATH_MAX]; if (find_directory(B_SYSTEM_TEMP_DIRECTORY, 0, false, pathC, PATH_MAX) != B_OK) return nil; return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC] isDirectory: true]; # elif defined(OF_AMIGAOS) return [OFURI fileURIWithPath: @"T:" isDirectory: true]; # elif defined(OF_MSDOS) OFString *path = [[OFApplication environment] objectForKey: @"TEMP"]; if (path == nil) return nil; return [OFURI fileURIWithPath: path isDirectory: true]; # elif defined(OF_MINT) return [OFURI fileURIWithPath: @"u:\\tmp" isDirectory: true]; # elif defined(OF_NINTENDO_SWITCH) static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, mountTmpFS); return tmpFSURI; # else OFString *path = [[OFApplication environment] objectForKey: @"XDG_RUNTIME_DIR"]; if (path != nil) return [OFURI fileURIWithPath: path]; return [OFURI fileURIWithPath: @"/tmp"]; # endif #else return nil; #endif } + (OFString *)CPUVendor |
︙ | ︙ |
Modified src/OFTCPSocket.h from [fc53b099cc] to [13742bc171].
︙ | ︙ | |||
79 80 81 82 83 84 85 86 87 88 89 90 91 | #endif #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) /** * @brief Whether the socket sends keep alives for the connection. * * @warning This is not available on the Wii or Nintendo 3DS! */ @property (nonatomic) bool sendsKeepAlives; #endif #ifndef OF_WII /** | > > > | > > > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #endif #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) /** * @brief Whether the socket sends keep alives for the connection. * * @warning This is not available on the Wii or Nintendo 3DS! * * @throw OFSetOptionFailedException The option could not be set * @throw OFGetOptionFailedException The option could not be gotten */ @property (nonatomic) bool sendsKeepAlives; #endif #ifndef OF_WII /** * @brief Whether sending segments can be delayed. Setting this to `false` sets * TCP_NODELAY on the socket. * * @warning This is not available on the Wii! * * @throw OFSetOptionFailedException The option could not be set * @throw OFGetOptionFailedException The option could not be gotten */ @property (nonatomic) bool canDelaySendingSegments; #endif /** * @brief The host to use as a SOCKS5 proxy. */ |
︙ | ︙ | |||
146 147 148 149 150 151 152 153 154 155 156 157 158 159 | + (uint16_t)SOCKS5Port; /** * @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 */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to | > > | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | + (uint16_t)SOCKS5Port; /** * @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 OFAlreadyConnectedException The socket is already connected or bound */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connects the OFTCPSocket to the specified destination. * * @param host The host to connect to |
︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 211 212 213 | * @brief Binds the socket to the specified host and port. * * @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 */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END | > > | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | * @brief Binds the socket to the specified host and port. * * @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 OFAlreadyConnectedException The socket is already connected or bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFTCPSocket.m from [922c01af3e] to [3962a70e27].
︙ | ︙ | |||
217 218 219 220 221 222 223 | - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate; | < < < | 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port delegate: _delegate #ifdef OF_HAVE_BLOCKS |
︙ | ︙ | |||
265 266 267 268 269 270 271 | port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate = nil; | < < < | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate = nil; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port delegate: nil block: block] autorelease]; |
︙ | ︙ |
Modified src/OFTLSStream.h from [0ae2a154e2] to [66003bcff2].
︙ | ︙ | |||
141 142 143 144 145 146 147 148 149 150 151 152 153 154 | - (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 */ - (void)performClientHandshakeWithHost: (OFString *)host; @end #ifdef __cplusplus extern "C" { #endif | > | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | - (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 */ - (void)performClientHandshakeWithHost: (OFString *)host; @end #ifdef __cplusplus extern "C" { #endif |
︙ | ︙ |
Modified src/OFTarArchive.h from [a9bc537672] to [4a06438b7d].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "OFKernelEventObserver.h" #import "OFString.h" #import "OFTarArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; /** * @class OFTarArchive OFTarArchive.h ObjFW/OFTarArchive.h * * @brief A class for accessing and manipulating tar archives. */ OF_SUBCLASSING_RESTRICTED @interface OFTarArchive: OFObject { OFStream *_stream; enum OFTarArchiveMode { OFTarArchiveModeRead, OFTarArchiveModeWrite, OFTarArchiveModeAppend } _mode; OFStringEncoding _encoding; OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; | > > > > > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #import "OFKernelEventObserver.h" #import "OFString.h" #import "OFTarArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; @class OFURI; /** * @class OFTarArchive OFTarArchive.h ObjFW/OFTarArchive.h * * @brief A class for accessing and manipulating tar archives. */ OF_SUBCLASSING_RESTRICTED @interface OFTarArchive: OFObject { OFStream *_stream; enum OFTarArchiveMode { OFTarArchiveModeRead, OFTarArchiveModeWrite, OFTarArchiveModeAppend } _mode; OFStringEncoding _encoding; OFTarArchiveEntry *_Nullable _currentEntry; #ifdef OF_TAR_ARCHIVE_M @public #endif OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; |
︙ | ︙ | |||
63 64 65 66 67 68 69 | * @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 */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; | < | | | > > > > > > > > > > < | | < | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | * @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 */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFTarArchive object with the specified file. * * @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 */ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Creates a URI for accessing a the specified file within the specified * tar archive. * * @param path The path of the file within the archive * @param URI The URI of the archive * @return A URI for accessing the specified file within the specified tar * archive */ + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated 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 An initialized OFTarArchive */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFTarArchive object with the * specified file. * * @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 */ - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns the next entry from the tar archive or `nil` if all entries * have been read. * * @note This is only available in read mode. * |
︙ | ︙ |
Modified src/OFTarArchive.m from [5a61b65e4b] to [8086f04e85].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * * 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 <errno.h> #import "OFTarArchive.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFSeekableStream.h" #import "OFStream.h" | > > > < | | > | | > | > | | > | < | | | > > > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | * * 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. */ #define OF_TAR_ARCHIVE_M #include "config.h" #include <errno.h> #import "OFTarArchive.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFArchiveURIHandler.h" #import "OFDate.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" OF_DIRECT_MEMBERS @interface OFTarArchiveFileReadStream: OFStream <OFReadyForReadingObserving> { OFTarArchive *_archive; OFTarArchiveEntry *_entry; OFStream *_stream; unsigned long long _toRead; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; - (void)of_skip; @end OF_DIRECT_MEMBERS @interface OFTarArchiveFileWriteStream: OFStream <OFReadyForWritingObserving> { OFTarArchive *_archive; OFTarArchiveEntry *_entry; OFStream *_stream; unsigned long long _toWrite; } - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; @end @implementation OFTarArchive: OFObject @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode { return [[[self alloc] initWithURI: URI mode: mode] autorelease]; } + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI { return OFArchiveURIHandlerURIForFileInArchive(@"tar", path, URI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode |
︙ | ︙ | |||
100 101 102 103 104 105 106 | uint32_t buffer[1024 / sizeof(uint32_t)]; bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [(OFSeekableStream *)_stream seekToOffset: -1024 | | | < | > | > | | | < > > > > | | | < < | > < > > < > > > < | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | uint32_t buffer[1024 / sizeof(uint32_t)]; bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [(OFSeekableStream *)_stream seekToOffset: -1024 whence: OFSeekEnd]; [_stream readIntoBuffer: buffer exactLength: 1024]; for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++) if (buffer[i] != 0) empty = false; if (!empty) @throw [OFInvalidFormatException exception]; [(OFSeekableStream *)stream seekToOffset: -1024 whence: OFSeekEnd]; } _encoding = OFStringEncodingUTF8; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFURIHandler openItemAtURI: URI mode: @"r+"]; else stream = [OFURIHandler openItemAtURI: URI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { [self close]; [_currentEntry release]; [super dealloc]; } - (OFTarArchiveEntry *)nextEntry { uint32_t buffer[512 / sizeof(uint32_t)]; bool empty = true; if (_mode != OFTarArchiveModeRead) @throw [OFInvalidArgumentException exception]; [_currentEntry release]; _currentEntry = nil; [(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_stream.atEndOfStream) return nil; [_stream readIntoBuffer: buffer exactLength: 512]; |
︙ | ︙ | |||
187 188 189 190 191 192 193 | for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) @throw [OFInvalidFormatException exception]; return nil; } | | | < < < < | | | > > | > > > > < < < < < | > | | < < | < < | > | > | > > > | < | | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) @throw [OFInvalidFormatException exception]; return nil; } _currentEntry = [[OFTarArchiveEntry alloc] of_initWithHeader: (unsigned char *)buffer encoding: _encoding]; return _currentEntry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != OFTarArchiveModeRead) @throw [OFInvalidArgumentException exception]; if (_currentEntry == nil) @throw [OFInvalidArgumentException exception]; _lastReturnedStream = [[[OFTarArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: _currentEntry] autorelease]; [_currentEntry release]; _currentEntry = nil; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry { if (_mode != OFTarArchiveModeWrite && _mode != OFTarArchiveModeAppend) @throw [OFInvalidArgumentException exception]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; [entry of_writeToStream: _stream encoding: _encoding]; _lastReturnedStream = [[[OFTarArchiveFileWriteStream alloc] of_initWithArchive: self stream: _stream entry: entry] autorelease]; return _lastReturnedStream; } - (void)close { if (_stream == nil) return; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_mode == OFTarArchiveModeWrite || _mode == OFTarArchiveModeAppend) { char buffer[1024]; memset(buffer, '\0', 1024); [_stream writeBuffer: buffer length: 1024]; } [_stream release]; _stream = nil; } @end @implementation OFTarArchiveFileReadStream - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _entry = [entry copy]; _stream = [stream retain]; _toRead = entry.uncompressedSize; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; #if SIZE_MAX >= ULLONG_MAX if (length > ULLONG_MAX) @throw [OFOutOfRangeException exception]; #endif if ((unsigned long long)length > _toRead) length = (size_t)_toRead; ret = [_stream readIntoBuffer: buffer length: length]; if (ret == 0) _atEndOfStream = true; _toRead -= ret; |
︙ | ︙ | |||
357 358 359 360 361 362 363 | - (void)of_skip { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && | > | | | > | | | | | | > | > | > > > | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | - (void)of_skip { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && _toRead <= LLONG_MAX && (OFStreamOffset)_toRead == (long long)_toRead) { unsigned long long size; [(OFSeekableStream *)_stream seekToOffset: (OFStreamOffset)_toRead whence: OFSeekCurrent]; _toRead = 0; size = _entry.uncompressedSize; if (size % 512 != 0) [(OFSeekableStream *)_stream seekToOffset: 512 - (size % 512) whence: OFSeekCurrent]; } else { char buffer[512]; unsigned long long size; while (_toRead >= 512) { [_stream readIntoBuffer: buffer exactLength: 512]; _toRead -= 512; } if (_toRead > 0) { [_stream readIntoBuffer: buffer exactLength: (size_t)_toRead]; _toRead = 0; } size = _entry.uncompressedSize; if (size % 512 != 0) [_stream readIntoBuffer: buffer exactLength: (size_t)(512 - (size % 512))]; } _skipped = true; } @end @implementation OFTarArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFTarArchive *)archive stream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _entry = [entry copy]; _stream = [stream retain]; _toWrite = entry.uncompressedSize; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (length > _toWrite) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); |
︙ | ︙ | |||
467 468 469 470 471 472 473 | { return ((id <OFReadyForWritingObserving>)_stream) .fileDescriptorForWriting; } - (void)close { | | | | 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | { return ((id <OFReadyForWritingObserving>)_stream) .fileDescriptorForWriting; } - (void)close { unsigned long long remainder; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_toWrite > 0) @throw [OFTruncatedDataException exception]; remainder = 512 - _entry.uncompressedSize % 512; if (remainder != 512) { bool didBufferWrites = _stream.buffersWrites; _stream.buffersWrites = true; while (remainder--) |
︙ | ︙ |
Modified src/OFTarArchiveEntry+Private.h from [92ff63bc6f] to [d7e9114597].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFTarArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; | < > | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFTarArchiveEntry.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFStream; @interface OFTarArchiveEntry () - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init) OF_DIRECT; - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_DIRECT; @end OF_ASSUME_NONNULL_END |
Modified src/OFTarArchiveEntry.h from [68a10bc9a2] to [a18b395a59].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * 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 "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDate; /** * @brief The type of the archive entry. */ typedef enum { /** Normal file */ OFTarArchiveEntryTypeFile = '0', | > > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * 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 "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDate; @class OFNumber; /** * @brief The type of the archive entry. */ typedef enum { /** Normal file */ OFTarArchiveEntryTypeFile = '0', |
︙ | ︙ | |||
44 45 46 47 48 49 50 | } OFTarArchiveEntryType; /** * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h * * @brief A class which represents an entry of a tar archive. */ | | > < > | < | > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | } OFTarArchiveEntryType; /** * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h * * @brief A class which represents an entry of a tar archive. */ @interface OFTarArchiveEntry: OFObject <OFArchiveEntry, OFCopying, OFMutableCopying> { OFString *_fileName; OFNumber *_POSIXPermissions, *_ownerAccountID, *_groupOwnerAccountID; unsigned long long _compressedSize, _uncompressedSize; OFDate *_modificationDate; OFTarArchiveEntryType _type; OFString *_Nullable _targetFileName; OFString *_Nullable _ownerAccountName; OFString *_Nullable _groupOwnerAccountName; unsigned long _deviceMajor, _deviceMinor; OF_RESERVE_IVARS(OFTarArchiveEntry, 4) } /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readonly, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *targetFileName; /** * @brief The device major (if the file is a device). */ @property (readonly, nonatomic) unsigned long deviceMajor; /** * @brief The device major (if the file is a device). */ @property (readonly, nonatomic) unsigned long deviceMinor; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END #import "OFMutableTarArchiveEntry.h" |
Modified src/OFTarArchiveEntry.m from [1a8a203480] to [6db7373fe9].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | */ #include "config.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" static OFString * stringFromBuffer(const unsigned char *buffer, size_t length, | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #import "OFTarArchiveEntry.h" #import "OFTarArchiveEntry+Private.h" #import "OFDate.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" static OFString * stringFromBuffer(const unsigned char *buffer, size_t length, |
︙ | ︙ | |||
70 71 72 73 74 75 76 | if (value > max) @throw [OFOutOfRangeException exception]; return value; } @implementation OFTarArchiveEntry | < < < < < > > > > > > > > > > > > > > > > | | | | > | | | > > > | < | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | if (value > max) @throw [OFOutOfRangeException exception]; return value; } @implementation OFTarArchiveEntry - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _type = OFTarArchiveEntryTypeFile; _POSIXPermissions = [[OFNumber alloc] initWithUnsignedShort: 0644]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)of_initWithHeader: (unsigned char [512])header encoding: (OFStringEncoding)encoding { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *targetFileName; _fileName = [stringFromBuffer(header, 100, encoding) copy]; _POSIXPermissions = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 100, 8, ULONG_MAX)]; _ownerAccountID = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 108, 8, ULONG_MAX)]; _groupOwnerAccountID = [[OFNumber alloc] initWithUnsignedLongLong: octalValueFromBuffer(header + 116, 8, ULONG_MAX)]; _uncompressedSize = (unsigned long long)octalValueFromBuffer( header + 124, 12, ULLONG_MAX); _compressedSize = _uncompressedSize + (512 - _uncompressedSize % 512); _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (OFTimeInterval)octalValueFromBuffer( header + 136, 12, ULLONG_MAX)]; _type = header[156]; targetFileName = stringFromBuffer(header + 157, 100, encoding); if (targetFileName.length > 0) _targetFileName = [targetFileName copy]; if (_type == '\0') _type = OFTarArchiveEntryTypeFile; if (memcmp(header + 257, "ustar\0" "00", 8) == 0) { OFString *prefix; _ownerAccountName = [stringFromBuffer(header + 265, 32, encoding) copy]; _groupOwnerAccountName = [stringFromBuffer(header + 297, 32, encoding) copy]; _deviceMajor = (unsigned long)octalValueFromBuffer( header + 329, 8, ULONG_MAX); _deviceMinor = (unsigned long)octalValueFromBuffer( header + 337, 8, ULONG_MAX); prefix = stringFromBuffer(header + 345, 155, encoding); |
︙ | ︙ | |||
143 144 145 146 147 148 149 | [self release]; @throw e; } return self; } | < < < < < < < < < < < < < < < < > > > | | > > > | | | | > > > > | > | | | | | | | | | | | > > > > > > | | | | | > | | | > | > > > | | | | | | | | | | > > | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | [self release]; @throw e; } return self; } - (void)dealloc { [_fileName release]; [_POSIXPermissions release]; [_ownerAccountID release]; [_groupOwnerAccountID release]; [_modificationDate release]; [_targetFileName release]; [_ownerAccountName release]; [_groupOwnerAccountName release]; [super dealloc]; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFTarArchiveEntry *copy = [[OFMutableTarArchiveEntry alloc] initWithFileName: _fileName]; @try { copy->_POSIXPermissions = [_POSIXPermissions retain]; copy->_ownerAccountID = [_ownerAccountID retain]; copy->_groupOwnerAccountID = [_groupOwnerAccountID retain]; copy->_compressedSize = _compressedSize; copy->_uncompressedSize = _uncompressedSize; copy->_modificationDate = [_modificationDate copy]; copy->_type = _type; copy->_targetFileName = [_targetFileName copy]; copy->_ownerAccountName = [_ownerAccountName copy]; copy->_groupOwnerAccountName = [_groupOwnerAccountName copy]; copy->_deviceMajor = _deviceMajor; copy->_deviceMinor = _deviceMinor; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)fileName { return _fileName; } - (OFNumber *)POSIXPermissions { return _POSIXPermissions; } - (OFNumber *)ownerAccountID { return _ownerAccountID; } - (OFNumber *)groupOwnerAccountID { return _groupOwnerAccountID; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (OFDate *)modificationDate { return _modificationDate; } - (OFTarArchiveEntryType)type { return _type; } - (OFString *)targetFileName { return _targetFileName; } - (OFString *)ownerAccountName { return _ownerAccountName; } - (OFString *)groupOwnerAccountName { return _groupOwnerAccountName; } - (unsigned long)deviceMajor { return _deviceMajor; } - (unsigned long)deviceMinor { return _deviceMinor; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *POSIXPermissions = nil, *ret; if (_POSIXPermissions != nil) POSIXPermissions = [OFString stringWithFormat: @"%ho", _POSIXPermissions.unsignedShortValue]; ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tPOSIX permissions = %@\n" @"\tOwner account ID = %@\n" @"\tGroup owner account ID = %@\n" @"\tCompressed size = %llu\n" @"\tUncompressed size = %llu\n" @"\tModification date = %@\n" @"\tType = %u\n" @"\tTarget file name = %@\n" @"\tOwner account name = %@\n" @"\tGroup owner account name = %@\n" @"\tDevice major = %" PRIu32 @"\n" @"\tDevice minor = %" PRIu32 @"\n" @">", self.class, _fileName, POSIXPermissions, _ownerAccountID, _groupOwnerAccountID, _compressedSize, _uncompressedSize, _modificationDate, _type, _targetFileName, _ownerAccountName, _groupOwnerAccountName, _deviceMajor, _deviceMinor]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); unsigned char buffer[512]; unsigned long long modificationDate; uint16_t checksum = 0; stringToBuffer(buffer, _fileName, 100, encoding); stringToBuffer(buffer + 100, [OFString stringWithFormat: @"%06o ", _POSIXPermissions.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 108, [OFString stringWithFormat: @"%06o ", _ownerAccountID.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 116, [OFString stringWithFormat: @"%06o ", _groupOwnerAccountID.unsignedShortValue], 8, OFStringEncodingASCII); stringToBuffer(buffer + 124, [OFString stringWithFormat: @"%011llo ", _uncompressedSize], 12, OFStringEncodingASCII); modificationDate = _modificationDate.timeIntervalSince1970; stringToBuffer(buffer + 136, [OFString stringWithFormat: @"%011llo", modificationDate], 12, OFStringEncodingASCII); /* * During checksumming, the checksum field is expected to be set to 8 * spaces. */ memset(buffer + 148, ' ', 8); buffer[156] = _type; stringToBuffer(buffer + 157, _targetFileName, 100, encoding); /* ustar */ memcpy(buffer + 257, "ustar\0" "00", 8); stringToBuffer(buffer + 265, _ownerAccountName, 32, encoding); stringToBuffer(buffer + 297, _groupOwnerAccountName, 32, encoding); stringToBuffer(buffer + 329, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8, OFStringEncodingASCII); stringToBuffer(buffer + 337, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8, OFStringEncodingASCII); memset(buffer + 345, '\0', 155 + 12); /* Fill in the checksum */ for (size_t i = 0; i < 500; i++) checksum += buffer[i]; stringToBuffer(buffer + 148, [OFString stringWithFormat: @"%06" PRIo16, checksum], 7, OFStringEncodingASCII); [stream writeBuffer: buffer length: sizeof(buffer)]; objc_autoreleasePoolPop(pool); } @end |
Added src/OFTarURIHandler.h version [7411ddfdf4].
> > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 |
Modified src/OFThread.h from [edfcfa680d] to [878e01b6fc].
︙ | ︙ | |||
70 71 72 73 74 75 76 | OFThreadStateRunning, OFThreadStateWaitingForJoin } _running; # ifndef OF_OBJFW_RUNTIME void *_pool; # endif # ifdef OF_HAVE_BLOCKS | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | OFThreadStateRunning, OFThreadStateWaitingForJoin } _running; # ifndef OF_OBJFW_RUNTIME void *_pool; # endif # ifdef OF_HAVE_BLOCKS OFThreadBlock _Nullable _block; # endif jmp_buf _exitEnv; id _returnValue; bool _supportsSockets; OFRunLoop *_Nullable _runLoop; OFMutableDictionary *_threadDictionary; OFString *_Nullable _name; |
︙ | ︙ | |||
114 115 116 117 118 119 120 | */ @property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /** * @brief The block to execute in the thread. */ | | | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | */ @property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /** * @brief The block to execute in the thread. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThreadBlock block; # endif /** * @brief The run loop for the thread. */ @property (readonly, nonatomic) OFRunLoop *runLoop; |
︙ | ︙ | |||
160 161 162 163 164 165 166 | */ + (instancetype)thread; # ifdef OF_HAVE_BLOCKS /** * @brief Creates a new thread with the specified block. * | | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | */ + (instancetype)thread; # ifdef OF_HAVE_BLOCKS /** * @brief Creates a new thread with the specified block. * * @param block A block which is executed by the thread * @return A new, autoreleased thread */ + (instancetype)threadWithBlock: (OFThreadBlock)block; # endif /** * @brief Returns the current thread. * * @return The current thread */ |
︙ | ︙ | |||
199 200 201 202 203 204 205 206 207 208 | */ + (nullable OFMutableDictionary *)threadDictionary; #endif #ifdef OF_HAVE_SOCKETS /** * @brief Returns the DNS resolver for the current thread. * * @return The DNS resolver for the current thread */ | > > > | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | */ + (nullable OFMutableDictionary *)threadDictionary; #endif #ifdef OF_HAVE_SOCKETS /** * @brief Returns the DNS resolver for the current thread. * * Constructs the DNS resolver is there is none yet, unless @ref currentThread * is `nil`, in which case it returns `nil`. * * @return The DNS resolver for the current thread */ + (nullable OFDNSResolver *)DNSResolver; #endif /** * @brief Suspends execution of the current thread for the specified time * interval. * * @param timeInterval The number of seconds to sleep |
︙ | ︙ | |||
260 261 262 263 264 265 266 | */ + (nullable OFString *)name; # ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated thread with the specified block. * | | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | */ + (nullable OFString *)name; # ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated thread with the specified block. * * @param block A block which is executed by the thread * @return An initialized OFThread. */ - (instancetype)initWithBlock: (OFThreadBlock)block; # endif /** * @brief The main routine of the thread. You need to reimplement this! * * @return The object the join method should return when called for this thread */ |
︙ | ︙ |
Modified src/OFThread.m from [9e6c736b19] to [51c302d474].
︙ | ︙ | |||
129 130 131 132 133 134 135 | /* * Nasty workaround for thread implementations which can't return a * pointer on join, or don't have a way to exit a thread. */ if (setjmp(thread->_exitEnv) == 0) { # ifdef OF_HAVE_BLOCKS | | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | /* * Nasty workaround for thread implementations which can't return a * pointer on join, or don't have a way to exit a thread. */ if (setjmp(thread->_exitEnv) == 0) { # ifdef OF_HAVE_BLOCKS if (thread->_block != NULL) thread->_returnValue = [thread->_block() retain]; else # endif thread->_returnValue = [[thread main] retain]; } [thread handleTermination]; |
︙ | ︙ | |||
156 157 158 159 160 161 162 | thread->_running = OFThreadStateWaitingForJoin; [thread release]; } @synthesize name = _name; # ifdef OF_HAVE_BLOCKS | | | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | thread->_running = OFThreadStateWaitingForJoin; [thread release]; } @synthesize name = _name; # ifdef OF_HAVE_BLOCKS @synthesize block = _block; # endif + (void)initialize { if (self != [OFThread class]) return; if (OFTLSKeyNew(&threadSelfKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)thread { return [[[self alloc] init] autorelease]; } # ifdef OF_HAVE_BLOCKS + (instancetype)threadWithBlock: (OFThreadBlock)block { return [[[self alloc] initWithBlock: block] autorelease]; } # endif + (OFThread *)currentThread { return OFTLSKeyGet(threadSelfKey); } |
︙ | ︙ | |||
376 377 378 379 380 381 382 | @throw e; } return self; } # ifdef OF_HAVE_BLOCKS | | | | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | @throw e; } return self; } # ifdef OF_HAVE_BLOCKS - (instancetype)initWithBlock: (OFThreadBlock)block { self = [self init]; @try { _block = [block copy]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
539 540 541 542 543 544 545 | * the resources. */ if (_running == OFThreadStateWaitingForJoin) OFPlainThreadDetach(_thread); [_returnValue release]; # ifdef OF_HAVE_BLOCKS | | | 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | * the resources. */ if (_running == OFThreadStateWaitingForJoin) OFPlainThreadDetach(_thread); [_returnValue release]; # ifdef OF_HAVE_BLOCKS [_block release]; # endif [super dealloc]; } #else - (instancetype)init { OF_INVALID_INIT_METHOD } #endif @end |
Modified src/OFUDPSocket.h from [3a21c440bc] to [e94e3865e1].
︙ | ︙ | |||
68 69 70 71 72 73 74 75 76 77 78 79 | * @brief Binds the socket to the specified host and port. * * @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 */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END | > > | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | * @brief Binds the socket to the specified host and port. * * @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 OFAlreadyConnectedException The socket is already bound */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFUNIXDatagramSocket.h from [15597b10d9] to [342ce1dbb2].
︙ | ︙ | |||
61 62 63 64 65 66 67 68 69 70 71 72 | id <OFUNIXDatagramSocketDelegate> delegate; /** * @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 */ - (OFSocketAddress)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END | > > | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | id <OFUNIXDatagramSocketDelegate> delegate; /** * @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 OFAlreadyConnectedException The socket is already bound */ - (OFSocketAddress)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END |
Modified src/OFUNIXStreamSocket.h from [34276ad0c9] to [8a5717e58d].
︙ | ︙ | |||
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFUNIXStreamSocketDelegate> delegate; /** * @brief Connects the OFUNIXStreamSocket to the specified destination. * * @param path The path to connect to */ - (void)connectToPath: (OFString *)path; /** * @brief Binds the socket to the specified host and port. * * @param path The path to bind to */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END | > > > > | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFUNIXStreamSocketDelegate> delegate; /** * @brief Connects the OFUNIXStreamSocket to the specified destination. * * @param path The path to connect to * @throw OFConnectionFailedException 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 OFAlreadyConnectedException The socket is already connected or bound */ - (void)bindToPath: (OFString *)path; @end OF_ASSUME_NONNULL_END |
Added src/OFURI+Private.h version [c5dc8bc44b].
> > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "OFURI.h" OF_ASSUME_NONNULL_BEGIN @interface OFURI () - (instancetype)of_init OF_METHOD_FAMILY(init); @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFURL.h [40faae77ac] to src/OFURI.h [b3a4d03434].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 | #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; @class OFString; /** | > | | | > | | | > | > | | | < < < < < < | | | | | | | | | | | | | | < | | | < | | | | | | | | | | > > | | | | | | | | | < | | | > > | | | | | | > > | | | | | | | | | | > > | | | | | > > | | | | | | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; @class OFPair OF_GENERIC(FirstType, SecondType); @class OFString; /** * @class OFURI OFURI.h ObjFW/OFURI.h * * @brief A class for parsing URIs as per RFC 3986 and accessing parts of it. */ @interface OFURI: OFObject <OFCopying, OFMutableCopying, OFSerialization> { OFString *_scheme; OFString *_Nullable _percentEncodedHost; OFNumber *_Nullable _port; OFString *_Nullable _percentEncodedUser; OFString *_Nullable _percentEncodedPassword; OFString *_percentEncodedPath; OFString *_Nullable _percentEncodedQuery; OFString *_Nullable _percentEncodedFragment; OF_RESERVE_IVARS(OFURI, 4) } /** * @brief The scheme part of the URI. */ @property (readonly, copy, nonatomic) OFString *scheme; /** * @brief The host part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host; /** * @brief The host part of the URI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedHost; /** * @brief The port part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port; /** * @brief The user part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user; /** * @brief The user part of the URI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedUser; /** * @brief The password part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password; /** * @brief The password part of the URI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedPassword; /** * @brief The path part of the URI. */ @property (readonly, copy, nonatomic) OFString *path; /** * @brief The path part of the URI in percent-encoded form. */ @property (readonly, copy, nonatomic) OFString *percentEncodedPath; /** * @brief The path of the URI split into components. * * The first component must always be `/` to designate the root. */ @property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFString *) *pathComponents; /** * @brief The last path component of the URI. * * Returns the empty string if the path is the root. */ @property (readonly, copy, nonatomic) OFString *lastPathComponent; /** * @brief The query part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query; /** * @brief The query part of the URI in percent-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedQuery; /** * @brief The query part of the URI as an array. * * For example, a query like `key1=value1&key2=value2` would correspond to the * following array: * * @[ * [OFPair pairWithFirstObject: @"key1" secondObject: @"value1"], * [OFPair pairWithFirstObject: @"key2" secondObject: @"value2"], * ] * * @throw OFInvalidFormatException The query is not in the correct format */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems; /** * @brief The fragment part of the URI. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment; /** * @brief The fragment part of the URI in URI-encoded form. */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *percentEncodedFragment; /** * @brief The URI as a string. */ @property (readonly, nonatomic) OFString *string; /** * @brief The URI with relative subpaths resolved. */ @property (readonly, nonatomic) OFURI *URIByStandardizingPath; #ifdef OF_HAVE_FILES /** * @brief The local file system representation for a file URI. * * @note This only exists for URIs with the file scheme and throws an exception * otherwise. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *fileSystemRepresentation; #endif /** * @brief Creates a new URI with the specified string. * * @param string A string describing a URI * @return A new, autoreleased OFURI * @throw OFInvalidFormatException The specified string is not a valid URI * string */ + (instancetype)URIWithString: (OFString *)string; /** * @brief Creates a new URI with the specified string relative to the * specified URI. * * @param string A string describing a relative or absolute URI * @param URI An URI to which the string is relative * @return A new, autoreleased OFURI * @throw OFInvalidFormatException The specified string is not a valid URI * string */ + (instancetype)URIWithString: (OFString *)string relativeToURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Creates a new URI with the specified local file path. * * 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 */ + (instancetype)fileURIWithPath: (OFString *)path; /** * @brief Creates a new URI with the specified local file path. * * @param path The local file path * @param isDirectory Whether the path is a directory, in which case a slash is * appened if there is no slash yet * @return An initialized OFURI */ + (instancetype)fileURIWithPath: (OFString *)path isDirectory: (bool)isDirectory; #endif /** * @brief Initializes an already allocated OFURI with the specified string. * * @param string A string describing a URI * @return An initialized OFURI * @throw OFInvalidFormatException The specified string is not a valid URI * string */ - (instancetype)initWithString: (OFString *)string; /** * @brief Initializes an already allocated OFURI with the specified string and * relative URI. * * @param string A string describing a relative or absolute URI * @param URI A URI to which the string is relative * @return An initialized OFURI * @throw OFInvalidFormatException The specified string is not a valid URI * string */ - (instancetype)initWithString: (OFString *)string relativeToURI: (OFURI *)URI; #ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFURI with the specified local file * path. * * 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 */ - (instancetype)initFileURIWithPath: (OFString *)path; /** * @brief Initializes an already allocated OFURI with the specified local file * path. * * @param path The local file path * @param isDirectory Whether the path is a directory, in which case a slash is * appened if there is no slash yet * @return An initialized OFURI */ - (instancetype)initFileURIWithPath: (OFString *)path isDirectory: (bool)isDirectory; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a new URI with the specified path component appended. * * If the URI is a file URI, the file system is queried whether the appended * component is a directory. * * @param component The path component to append. If it starts with the slash, * the component is not appended, but replaces the path * instead. * @return A new URI with the specified path component appended */ - (OFURI *)URIByAppendingPathComponent: (OFString *)component; /** * @brief Returns a new URI with the specified path component appended. * * @param component The path component to append. If it starts with the slash, * the component is not appended, but replaces the path * instead. * @param isDirectory Whether the appended component is a directory, meaning * that the URI path should have a trailing slash * @return A new URI with the specified path component appended */ - (OFURI *)URIByAppendingPathComponent: (OFString *)component isDirectory: (bool)isDirectory; @end @interface OFCharacterSet (URICharacterSets) #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFCharacterSet *URISchemeAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIHostAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIUserAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIPasswordAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIPathAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIQueryAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIQueryKeyValueAllowedCharacterSet; @property (class, readonly, nonatomic) OFCharacterSet *URIFragmentAllowedCharacterSet; #endif /** * @brief Returns the characters allowed in the scheme part of a URI. * * @return The characters allowed in the scheme part of a URI. */ + (OFCharacterSet *)URISchemeAllowedCharacterSet; /** * @brief Returns the characters allowed in the host part of a URI. * * @return The characters allowed in the host part of a URI. */ + (OFCharacterSet *)URIHostAllowedCharacterSet; /** * @brief Returns the characters allowed in the user part of a URI. * * @return The characters allowed in the user part of a URI. */ + (OFCharacterSet *)URIUserAllowedCharacterSet; /** * @brief Returns the characters allowed in the password part of a URI. * * @return The characters allowed in the password part of a URI. */ + (OFCharacterSet *)URIPasswordAllowedCharacterSet; /** * @brief Returns the characters allowed in the path part of a URI. * * @return The characters allowed in the path part of a URI. */ + (OFCharacterSet *)URIPathAllowedCharacterSet; /** * @brief Returns the characters allowed in the query part of a URI. * * @return The characters allowed in the query part of a URI. */ + (OFCharacterSet *)URIQueryAllowedCharacterSet; /** * @brief Returns the characters allowed in a key/value in the query part of a * URI. * * @return The characters allowed in a key/value in the query part of a URI. */ + (OFCharacterSet *)URIQueryKeyValueAllowedCharacterSet; /** * @brief Returns the characters allowed in the fragment part of a URI. * * @return The characters allowed in the fragment part of a URI. */ + (OFCharacterSet *)URIFragmentAllowedCharacterSet; @end #ifdef __cplusplus extern "C" { #endif extern bool OFURIIsIPv6Host(OFString *host); extern void OFURIVerifyIsEscaped(OFString *, OFCharacterSet *, bool); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFMutableURI.h" |
Renamed and modified src/OFURL.m [54ccbf7591] to src/OFURI.m [fd812a6a57].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <stdlib.h> #include <string.h> | | | > | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | */ #include "config.h" #include <stdlib.h> #include <string.h> #import "OFURI.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFileManager.h" # import "OFFileURIHandler.h" #endif #import "OFNumber.h" #import "OFOnce.h" #import "OFPair.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" @interface OFURIAllowedCharacterSetBase: OFCharacterSet @end @interface OFURIAllowedCharacterSet: OFURIAllowedCharacterSetBase @end @interface OFURISchemeAllowedCharacterSet: OFURIAllowedCharacterSetBase @end @interface OFURIPathAllowedCharacterSet: OFURIAllowedCharacterSetBase @end @interface OFURIQueryOrFragmentAllowedCharacterSet: OFURIAllowedCharacterSetBase @end @interface OFURIQueryKeyValueAllowedCharacterSet: OFURIAllowedCharacterSetBase @end OF_DIRECT_MEMBERS @interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet; @end static OFCharacterSet *URIAllowedCharacterSet = nil; static OFCharacterSet *URISchemeAllowedCharacterSet = nil; static OFCharacterSet *URIPathAllowedCharacterSet = nil; static OFCharacterSet *URIQueryOrFragmentAllowedCharacterSet = nil; static OFCharacterSet *URIQueryKeyValueAllowedCharacterSet = nil; static OFOnceControl URIAllowedCharacterSetOnce = OFOnceControlInitValue; static OFOnceControl URIQueryOrFragmentAllowedCharacterSetOnce = OFOnceControlInitValue; static void initURIAllowedCharacterSet(void) { URIAllowedCharacterSet = [[OFURIAllowedCharacterSet alloc] init]; } static void initURISchemeAllowedCharacterSet(void) { URISchemeAllowedCharacterSet = [[OFURISchemeAllowedCharacterSet alloc] init]; } static void initURIPathAllowedCharacterSet(void) { URIPathAllowedCharacterSet = [[OFURIPathAllowedCharacterSet alloc] init]; } static void initURIQueryOrFragmentAllowedCharacterSet(void) { URIQueryOrFragmentAllowedCharacterSet = [[OFURIQueryOrFragmentAllowedCharacterSet alloc] init]; } static void initURIQueryKeyValueAllowedCharacterSet(void) { URIQueryKeyValueAllowedCharacterSet = [[OFURIQueryKeyValueAllowedCharacterSet alloc] init]; } bool OFURIIsIPv6Host(OFString *host) { const char *UTF8String = host.UTF8String; bool hasColon = false; while (*UTF8String != '\0') { if (!OFASCIIIsDigit(*UTF8String) && *UTF8String != ':' && (*UTF8String < 'a' || *UTF8String > 'f') && (*UTF8String < 'A' || *UTF8String > 'F')) return false; if (*UTF8String == ':') hasColon = true; UTF8String++; } return hasColon; } @implementation OFURIAllowedCharacterSetBase - (instancetype)autorelease { return self; } - (instancetype)retain { return self; } - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } @end @implementation OFURIAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': |
︙ | ︙ | |||
173 174 175 176 177 178 179 | return true; default: return false; } } @end | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | return true; default: return false; } } @end @implementation OFURISchemeAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '+': case '-': case '.': return true; default: return false; } } @end @implementation OFURIPathAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': |
︙ | ︙ | |||
222 223 224 225 226 227 228 | return true; default: return false; } } @end | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | return true; default: return false; } } @end @implementation OFURIQueryOrFragmentAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': |
︙ | ︙ | |||
255 256 257 258 259 260 261 | return true; default: return false; } } @end | | | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | return true; default: return false; } } @end @implementation OFURIQueryKeyValueAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': |
︙ | ︙ | |||
319 320 321 322 323 324 325 | { return (character != '%' && !_characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end void | | > > | | > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > | > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | < | < < < < < | | > | | < < | | < | | | < | < < | | < < < < > | < < < < < < < < < < < < < < < < < < < < < < < < < | > < | | | < < | > > > > < < > > > | < | | > | < | | | > < < < < < > | | < < | < | < < < | > > | | < < < | < | | | < < < | > > | < < < | < < < | < < < | < < > | < | < < | < < < > | | < < < < < > | < < | < < < < | < < < < | > > < | | < < | > | > | > > < < < < | < < < < < | | | < | < < < > | < < | | < < | > | | < < < < > > | > > | < | | < > > > > > > | > > > | | < | | | < | | < | < < | < < < | < < | | < | | | > > | > | | < < < < | | | | | | | | | | | > > > > > > > > > > | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | { return (character != '%' && !_characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end void OFURIVerifyIsEscaped(OFString *string, OFCharacterSet *characterSet, bool allowPercent) { void *pool = objc_autoreleasePoolPush(); if (allowPercent) characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc] initWithCharacterSet: characterSet] autorelease]; else characterSet = characterSet.invertedSet; if ([string indexOfCharacterFromSet: characterSet] != OFNotFound) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); } @implementation OFCharacterSet (URICharacterSets) + (OFCharacterSet *)URISchemeAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURISchemeAllowedCharacterSet); return URISchemeAllowedCharacterSet; } + (OFCharacterSet *)URIHostAllowedCharacterSet { OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet); return URIAllowedCharacterSet; } + (OFCharacterSet *)URIUserAllowedCharacterSet { OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet); return URIAllowedCharacterSet; } + (OFCharacterSet *)URIPasswordAllowedCharacterSet { OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet); return URIAllowedCharacterSet; } + (OFCharacterSet *)URIPathAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURIPathAllowedCharacterSet); return URIPathAllowedCharacterSet; } + (OFCharacterSet *)URIQueryAllowedCharacterSet { OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce, initURIQueryOrFragmentAllowedCharacterSet); return URIQueryOrFragmentAllowedCharacterSet; } + (OFCharacterSet *)URIQueryKeyValueAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURIQueryKeyValueAllowedCharacterSet); return URIQueryKeyValueAllowedCharacterSet; } + (OFCharacterSet *)URIFragmentAllowedCharacterSet { OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce, initURIQueryOrFragmentAllowedCharacterSet); return URIQueryOrFragmentAllowedCharacterSet; } @end @implementation OFURI + (instancetype)URI { return [[[self alloc] init] autorelease]; } + (instancetype)URIWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } + (instancetype)URIWithString: (OFString *)string relativeToURI: (OFURI *)URI { return [[[self alloc] initWithString: string relativeToURI: URI] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)fileURIWithPath: (OFString *)path { return [[[self alloc] initFileURIWithPath: path] autorelease]; } + (instancetype)fileURIWithPath: (OFString *)path isDirectory: (bool)isDirectory { return [[[self alloc] initFileURIWithPath: path isDirectory: isDirectory] autorelease]; } #endif static void parseUserInfo(OFURI *self, const char *UTF8String, size_t length) { const char *colon; if ((colon = memchr(UTF8String, ':', length)) != NULL) { self->_percentEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String length: colon - UTF8String]; self->_percentEncodedPassword = [[OFString alloc] initWithUTF8String: colon + 1 length: length - (colon - UTF8String) - 1]; OFURIVerifyIsEscaped(self->_percentEncodedPassword, [OFCharacterSet URIPasswordAllowedCharacterSet], true); } else self->_percentEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String length: length]; OFURIVerifyIsEscaped(self->_percentEncodedUser, [OFCharacterSet URIUserAllowedCharacterSet], true); } static void parseHostPort(OFURI *self, const char *UTF8String, size_t length) { OFString *portString; if (*UTF8String == '[') { const char *end = memchr(UTF8String, ']', length); if (end == NULL) @throw [OFInvalidFormatException exception]; for (const char *iter = UTF8String + 1; iter < end; iter++) if (!OFASCIIIsDigit(*iter) && *iter != ':' && (*iter < 'a' || *iter > 'f') && (*iter < 'A' || *iter > 'F')) @throw [OFInvalidFormatException exception]; self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: end - UTF8String + 1]; length -= (end - UTF8String) + 1; UTF8String = end + 1; } else { const char *colon = memchr(UTF8String, ':', length); if (colon != NULL) { self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: colon - UTF8String]; length -= colon - UTF8String; UTF8String = colon; } else { self->_percentEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String length: length]; UTF8String += length; length = 0; } OFURIVerifyIsEscaped(self->_percentEncodedHost, [OFCharacterSet URIHostAllowedCharacterSet], true); } if (length == 0) return; if (length <= 1 || *UTF8String != ':') @throw [OFInvalidFormatException exception]; UTF8String++; length--; for (size_t i = 0; i < length; i++) if (!OFASCIIIsDigit(UTF8String[i])) @throw [OFInvalidFormatException exception]; portString = [OFString stringWithUTF8String: UTF8String length: length]; if (portString.unsignedLongLongValue > 65535) @throw [OFInvalidFormatException exception]; self->_port = [[OFNumber alloc] initWithUnsignedShort: (unsigned short)portString.unsignedLongLongValue]; } static size_t parseAuthority(OFURI *self, const char *UTF8String, size_t length) { size_t ret; const char *slash, *at; if ((slash = memchr(UTF8String, '/', length)) != NULL) length = slash - UTF8String; ret = length; if ((at = memchr(UTF8String, '@', length)) != NULL) { parseUserInfo(self, UTF8String, at - UTF8String); length -= at - UTF8String + 1; UTF8String = at + 1; } parseHostPort(self, UTF8String, length); return ret; } static void parsePathQueryFragment(const char *UTF8String, size_t length, OFString **pathString, OFString **queryString, OFString **fragmentString) { const char *fragment, *query; if ((fragment = memchr(UTF8String, '#', length)) != NULL) { *fragmentString = [OFString stringWithUTF8String: fragment + 1 length: length - (fragment - UTF8String) - 1]; OFURIVerifyIsEscaped(*fragmentString, [OFCharacterSet URIQueryAllowedCharacterSet], true); length = fragment - UTF8String; } if ((query = memchr(UTF8String, '?', length)) != NULL) { *queryString = [OFString stringWithUTF8String: query + 1 length: length - (query - UTF8String) - 1]; OFURIVerifyIsEscaped(*queryString, [OFCharacterSet URIFragmentAllowedCharacterSet], true); length = query - UTF8String; } *pathString = [OFString stringWithUTF8String: UTF8String length: length]; OFURIVerifyIsEscaped(*pathString, [OFCharacterSet URIQueryAllowedCharacterSet], true); } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; const char *colon; OFString *path, *query = nil, *fragment = nil; if ((colon = strchr(UTF8String, ':')) == NULL || colon - UTF8String < 1 || !OFASCIIIsAlpha(UTF8String[0])) @throw [OFInvalidFormatException exception]; _scheme = [[[OFString stringWithUTF8String: UTF8String length: colon - UTF8String] lowercaseString] copy]; OFURIVerifyIsEscaped(_scheme, [OFCharacterSet URISchemeAllowedCharacterSet], false); length -= colon - UTF8String + 1; UTF8String = colon + 1; if (length >= 2 && UTF8String[0] == '/' && UTF8String[1] == '/') { size_t authorityLength; UTF8String += 2; length -= 2; authorityLength = parseAuthority(self, UTF8String, length); UTF8String += authorityLength; length -= authorityLength; if (length > 0) OFEnsure(UTF8String[0] == '/'); } parsePathQueryFragment(UTF8String, length, &path, &query, &fragment); _percentEncodedPath = [path copy]; _percentEncodedQuery = [query copy]; _percentEncodedFragment = [fragment copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } static bool isAbsolute(OFString *string) { void *pool = objc_autoreleasePoolPush(); @try { const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; if (length < 1) return false; if (!OFASCIIIsAlpha(UTF8String[0])) return false; for (size_t i = 1; i < length; i++) { if (UTF8String[i] == ':') return true; if (!OFASCIIIsAlnum(UTF8String[i]) && UTF8String[i] != '+' && UTF8String[i] != '-' && UTF8String[i] != '.') return false; } } @finally { objc_autoreleasePoolPop(pool); } return false; } static OFString * merge(OFString *base, OFString *path) { OFMutableArray *components; if (base.length == 0) base = @"/"; components = [[[base componentsSeparatedByString: @"/"] mutableCopy] autorelease]; if (components.count == 1) [components addObject: path]; else [components replaceObjectAtIndex: components.count - 1 withObject: path]; return [components componentsJoinedByString: @"/"]; } - (instancetype)initWithString: (OFString *)string relativeToURI: (OFURI *)URI { bool absolute; @try { absolute = isAbsolute(string); } @catch (id e) { [self release]; @throw e; } if (absolute) return [self initWithString: string]; self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength; bool hasAuthority = false; OFString *path, *query = nil, *fragment = nil; _scheme = [URI->_scheme copy]; if (length >= 2 && UTF8String[0] == '/' && UTF8String[1] == '/') { size_t authorityLength; hasAuthority = true; UTF8String += 2; length -= 2; authorityLength = parseAuthority(self, UTF8String, length); UTF8String += authorityLength; length -= authorityLength; if (length > 0) OFEnsure(UTF8String[0] == '/'); } else { _percentEncodedHost = [URI->_percentEncodedHost copy]; _port = [URI->_port copy]; _percentEncodedUser = [URI->_percentEncodedUser copy]; _percentEncodedPassword = [URI->_percentEncodedPassword copy]; } parsePathQueryFragment(UTF8String, length, &path, &query, &fragment); _percentEncodedFragment = [fragment copy]; if (hasAuthority) { _percentEncodedPath = [path copy]; _percentEncodedQuery = [query copy]; } else { if (path.length == 0) { _percentEncodedPath = [URI->_percentEncodedPath copy]; _percentEncodedQuery = (query != nil ? [query copy] : [URI->_percentEncodedQuery copy]); } else { if ([path hasPrefix: @"/"]) _percentEncodedPath = [path copy]; else _percentEncodedPath = [merge( URI->_percentEncodedPath, path) copy]; _percentEncodedQuery = [query copy]; } } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initFileURIWithPath: (OFString *)path { bool isDirectory; @try { void *pool = objc_autoreleasePoolPush(); isDirectory = [path of_isDirectoryPath]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } self = [self initFileURIWithPath: path isDirectory: isDirectory]; return self; } - (instancetype)initFileURIWithPath: (OFString *)path isDirectory: (bool)isDirectory { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *percentEncodedHost = nil; if (!path.absolutePath) { OFString *currentDirectoryPath = [OFFileManager defaultManager].currentDirectoryPath; path = [currentDirectoryPath stringByAppendingPathComponent: path]; path = path.stringByStandardizingPath; } path = [path of_pathToURIPathWithPercentEncodedHost: &percentEncodedHost]; _percentEncodedHost = [percentEncodedHost copy]; if (isDirectory && ![path hasSuffix: @"/"]) path = [path stringByAppendingString: @"/"]; _scheme = @"file"; _percentEncodedPath = [[path stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIPathAllowedCharacterSet]] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { |
︙ | ︙ | |||
801 802 803 804 805 806 807 | objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { | | | | | | | | | | | < | | | | | | | | < | | | | | | | | | | | | < < < < < | | | | | | | | | | | | | | | | | | | | | | | > | < | < < < < < | 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { [_scheme release]; [_percentEncodedHost release]; [_port release]; [_percentEncodedUser release]; [_percentEncodedPassword release]; [_percentEncodedPath release]; [_percentEncodedQuery release]; [_percentEncodedFragment release]; [super dealloc]; } - (bool)isEqual: (id)object { OFURI *URI; if (object == self) return true; if (![object isKindOfClass: [OFURI class]]) return false; URI = object; if (![URI->_scheme isEqual: _scheme]) return false; if (URI->_percentEncodedHost != _percentEncodedHost && ![URI->_percentEncodedHost isEqual: _percentEncodedHost]) return false; if (URI->_port != _port && ![URI->_port isEqual: _port]) return false; if (URI->_percentEncodedUser != _percentEncodedUser && ![URI->_percentEncodedUser isEqual: _percentEncodedUser]) return false; if (URI->_percentEncodedPassword != _percentEncodedPassword && ![URI->_percentEncodedPassword isEqual: _percentEncodedPassword]) return false; if (![URI->_percentEncodedPath isEqual: _percentEncodedPath]) return false; if (URI->_percentEncodedQuery != _percentEncodedQuery && ![URI->_percentEncodedQuery isEqual: _percentEncodedQuery]) return false; if (URI->_percentEncodedFragment != _percentEncodedFragment && ![URI->_percentEncodedFragment isEqual: _percentEncodedFragment]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _scheme.hash); OFHashAddHash(&hash, _percentEncodedHost.hash); OFHashAddHash(&hash, _port.hash); OFHashAddHash(&hash, _percentEncodedUser.hash); OFHashAddHash(&hash, _percentEncodedPassword.hash); OFHashAddHash(&hash, _percentEncodedPath.hash); OFHashAddHash(&hash, _percentEncodedQuery.hash); OFHashAddHash(&hash, _percentEncodedFragment.hash); OFHashFinalize(&hash); return hash; } - (OFString *)scheme { return _scheme; } - (OFString *)host { if ([_percentEncodedHost hasPrefix: @"["] && [_percentEncodedHost hasSuffix: @"]"]) { OFString *host = [_percentEncodedHost substringWithRange: OFMakeRange(1, _percentEncodedHost.length - 2)]; if (!OFURIIsIPv6Host(host)) @throw [OFInvalidArgumentException exception]; return host; } return _percentEncodedHost.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedHost { return _percentEncodedHost; } - (OFNumber *)port { return _port; } - (OFString *)user { return _percentEncodedUser.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedUser { return _percentEncodedUser; } - (OFString *)password { return _percentEncodedPassword.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedPassword { return _percentEncodedPassword; } - (OFString *)path { return _percentEncodedPath.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedPath { return _percentEncodedPath; } - (OFArray *)pathComponents { void *pool = objc_autoreleasePoolPush(); #ifdef OF_HAVE_FILES bool isFile = [_scheme isEqual: @"file"]; #endif OFMutableArray *ret; size_t count; #ifdef OF_HAVE_FILES if (isFile) { OFString *path = [_percentEncodedPath of_URIPathToPathWithPercentEncodedHost: nil]; ret = [[path.pathComponents mutableCopy] autorelease]; if (![ret.firstObject isEqual: @"/"]) [ret insertObject: @"/" atIndex: 0]; } else #endif ret = [[[_percentEncodedPath componentsSeparatedByString: @"/"] mutableCopy] autorelease]; count = ret.count; if (count > 0 && [ret.firstObject length] == 0) [ret replaceObjectAtIndex: 0 withObject: @"/"]; for (size_t i = 0; i < count; i++) { OFString *component = [ret objectAtIndex: i]; #ifdef OF_HAVE_FILES if (isFile) component = [component of_pathComponentToURIPathComponent]; #endif component = component.stringByRemovingPercentEncoding; [ret replaceObjectAtIndex: i withObject: component]; } [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)lastPathComponent { void *pool = objc_autoreleasePoolPush(); OFString *path = _percentEncodedPath; const char *UTF8String, *lastComponent; size_t length; OFString *ret; if ([path isEqual: @"/"]) { objc_autoreleasePoolPop(pool); return @"/"; } if ([path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; |
︙ | ︙ | |||
1020 1021 1022 1023 1024 1025 1026 | break; } } ret = [OFString stringWithUTF8String: lastComponent length: length - (lastComponent - UTF8String)]; | | | | | | | > | | | > | > | > > > > | | | | < | | | | | | | > > > > | > | | | | | < < < < | | < | | | | | | | > | | | | | | | | | | | | | | | | 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 | break; } } ret = [OFString stringWithUTF8String: lastComponent length: length - (lastComponent - UTF8String)]; ret = [ret.stringByRemovingPercentEncoding retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)query { return _percentEncodedQuery.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedQuery { return _percentEncodedQuery; } - (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *)queryItems { void *pool; OFArray OF_GENERIC(OFString *) *pairs; OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *ret; if (_percentEncodedQuery == nil) return nil; pool = objc_autoreleasePoolPush(); pairs = [_percentEncodedQuery componentsSeparatedByString: @"&"]; ret = [OFMutableArray arrayWithCapacity: pairs.count]; for (OFString *pair in pairs) { OFArray *parts = [pair componentsSeparatedByString: @"="]; OFString *name, *value; if (parts.count != 2) @throw [OFInvalidFormatException exception]; name = [[parts objectAtIndex: 0] stringByRemovingPercentEncoding]; value = [[parts objectAtIndex: 1] stringByRemovingPercentEncoding]; [ret addObject: [OFPair pairWithFirstObject: name secondObject: value]]; } [ret makeImmutable]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)fragment { return _percentEncodedFragment.stringByRemovingPercentEncoding; } - (OFString *)percentEncodedFragment { return _percentEncodedFragment; } - (id)copy { return [self retain]; } - (id)mutableCopy { OFURI *copy = [[OFMutableURI alloc] initWithScheme: _scheme]; @try { copy->_percentEncodedHost = [_percentEncodedHost copy]; copy->_port = [_port copy]; copy->_percentEncodedUser = [_percentEncodedUser copy]; copy->_percentEncodedPassword = [_percentEncodedPassword copy]; copy->_percentEncodedPath = [_percentEncodedPath copy]; copy->_percentEncodedQuery = [_percentEncodedQuery copy]; copy->_percentEncodedFragment = [_percentEncodedFragment copy]; } @catch (id e) { [copy release]; @throw e; } return copy; } - (OFString *)string { OFMutableString *ret = [OFMutableString string]; [ret appendFormat: @"%@:", _scheme]; if (_percentEncodedHost != nil || _port != nil || _percentEncodedUser != nil || _percentEncodedPassword != nil) [ret appendString: @"//"]; if (_percentEncodedUser != nil && _percentEncodedPassword != nil) [ret appendFormat: @"%@:%@@", _percentEncodedUser, _percentEncodedPassword]; else if (_percentEncodedUser != nil) [ret appendFormat: @"%@@", _percentEncodedUser]; if (_percentEncodedHost != nil) [ret appendString: _percentEncodedHost]; if (_port != nil) [ret appendFormat: @":%@", _port]; [ret appendString: _percentEncodedPath]; if (_percentEncodedQuery != nil) [ret appendFormat: @"?%@", _percentEncodedQuery]; if (_percentEncodedFragment != nil) [ret appendFormat: @"#%@", _percentEncodedFragment]; [ret makeImmutable]; return ret; } #ifdef OF_HAVE_FILES - (OFString *)fileSystemRepresentation { void *pool = objc_autoreleasePoolPush(); OFString *path; if (![_scheme isEqual: @"file"]) @throw [OFInvalidArgumentException exception]; if (![_percentEncodedPath hasPrefix: @"/"]) @throw [OFInvalidFormatException exception]; path = [self.path of_URIPathToPathWithPercentEncodedHost: _percentEncodedHost]; [path retain]; objc_autoreleasePoolPop(pool); return [path autorelease]; } #endif - (OFURI *)URIByAppendingPathComponent: (OFString *)component { OFMutableURI *URI = [[self mutableCopy] autorelease]; [URI appendPathComponent: component]; [URI makeImmutable]; return URI; } - (OFURI *)URIByAppendingPathComponent: (OFString *)component isDirectory: (bool)isDirectory { OFMutableURI *URI = [[self mutableCopy] autorelease]; [URI appendPathComponent: component isDirectory: isDirectory]; [URI makeImmutable]; return URI; } - (OFURI *)URIByStandardizingPath { OFMutableURI *URI = [[self mutableCopy] autorelease]; [URI standardizePath]; [URI makeImmutable]; return URI; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.string]; } |
︙ | ︙ |
Renamed and modified src/OFURLHandler.h [0e58f1d36b] to src/OFURIHandler.h [09864efcca].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFStream; | | | | | | | | | > > | > > > > > > > > > > > > > > > > > > > > > > > > > | | | > > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDate; @class OFStream; @class OFURI; /** * @class OFURIHandler OFURIHandler.h ObjFW/OFURIHandler.h * * @brief A handler for a URI scheme. */ @interface OFURIHandler: OFObject { OFString *_scheme; OF_RESERVE_IVARS(OFURIHandler, 4) } /** * @brief The scheme this OFURIHandler handles. */ @property (readonly, nonatomic) OFString *scheme; /** * @brief Registers the specified class as the handler for the specified scheme. * * If the same class is specified for two schemes, one instance of it is * created per scheme. * * @param class_ The class to register as the handler for the specified scheme * @param scheme The scheme for which to register the handler * @return Whether the class was successfully registered. If a handler for the * same scheme is already registered, registration fails. */ + (bool)registerClass: (Class)class_ forScheme: (OFString *)scheme; /** * @brief Returns the handler for the specified URI. * * @return The handler for the specified URI. * @throw OFUnsupportedProtocolException The specified URI is not supported */ + (OFURIHandler *)handlerForURI: (OFURI *)URI; /** * @brief Opens the item at the specified URI. * * @param URI The URI of the item which should be opened * @param mode The mode in which the file should be opened.@n * Possible modes are: * @n * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. * @return The opened stream if it was successfully opened * @throw OFOpenItemFailedException Opening the item failed * @throw OFUnsupportedProtocolException The specified URI is not supported */ + (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes the handler for the specified scheme. * * @param scheme The scheme to initialize for * @return An initialized URI handler */ - (instancetype)initWithScheme: (OFString *)scheme OF_DESIGNATED_INITIALIZER; /** * @brief Opens the item at the specified URI. * * @param URI The URI of the item which should be opened * @param mode The mode in which the file should be opened.@n * Possible modes are: * @n * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. * @return The opened stream if it was successfully opened * @throw OFOpenItemFailedException Opening the item failed * @throw OFUnsupportedProtocolException The specified URI is not supported by * the handler */ - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns the attributes for the item at the specified URI. * * @param URI The URI to return the attributes for * @return A dictionary of attributes for the specified URI, with the keys of * type @ref OFFileAttributeKey */ - (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI; /** * @brief Sets the attributes for the item at the specified URI. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified URI * @param URI The URI of the item to set the attributes for */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI; /** * @brief Checks whether a file exists at the specified URI. * * @param URI The URI to check * @return A boolean whether there is a file at the specified URI */ - (bool)fileExistsAtURI: (OFURI *)URI; /** * @brief Checks whether a directory exists at the specified URI. * * @param URI The URI to check * @return A boolean whether there is a directory at the specified URI */ - (bool)directoryExistsAtURI: (OFURI *)URI; /** * @brief Creates a directory at the specified URI. * * @param URI The URI of the directory to create */ - (void)createDirectoryAtURI: (OFURI *)URI; /** * @brief Returns an array with the URIs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param URI The URI to the directory whose items should be returned * @return An array with the URIs of the items in the specified directory */ - (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI; /** * @brief Removes the item at the specified URI. * * If the item at the specified URI is a directory, it is removed recursively. * * @param URI The URI to the item which should be removed */ - (void)removeItemAtURI: (OFURI *)URI; /** * @brief Creates a hard link for the specified item. * * The destination URI must have a full path, which means it must include the * name of the item. * * This method is not available for all URIs. * * @param source The URI to the item for which a link should be created * @param destination The URI to the item which should link to the source */ - (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination; /** * @brief Creates a symbolic link for an item. * * The destination URI must have a full path, which means it must include the * name of the item. * * This method is not available for all URIs. * * @note On Windows, this requires at least Windows Vista and administrator * privileges! * * @param URI The URI to the item which should symbolically link to the target * @param target The target of the symbolic link */ - (void)createSymbolicLinkAtURI: (OFURI *)URI withDestinationPath: (OFString *)target; /** * @brief Tries to efficiently copy an item. If a copy would only be possible * by reading the entire item and then writing it, it returns false. * * The destination URI must have a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination URI * @return True if an efficient copy was performed, false if an efficient copy * was not possible. Note that errors while performing a copy are * reported via exceptions and not by returning false! */ - (bool)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination; /** * @brief Tries to efficiently move an item. If a move would only be possible * by copying the source and deleting it, it returns false. * * The destination URI must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, an efficient move is not possible and false is returned. * * @param source The item to rename * @param destination The new name for the item * @return True if an efficient move was performed, false if an efficient move * was not possible. Note that errors while performing a move are * reported via exceptions and not by returning false! */ - (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFURLHandler.m [c3c8bcc62a] to src/OFURIHandler.m [1cc8c8dac2].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | > | | | > > | | | | | | | | > > > > | | | | > > > > > > > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * 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 "OFURIHandler.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFURI.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFArchiveURIHandler.h" #import "OFEmbeddedURIHandler.h" #ifdef OF_HAVE_FILES # import "OFFileURIHandler.h" #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) # import "OFHTTPURIHandler.h" #endif #import "OFUnsupportedProtocolException.h" static OFMutableDictionary OF_GENERIC(OFString *, OFURIHandler *) *handlers; #ifdef OF_HAVE_THREADS static OFMutex *mutex; static void releaseMutex(void) { [mutex release]; } #endif @implementation OFURIHandler @synthesize scheme = _scheme; + (void)initialize { if (self != [OFURIHandler class]) return; handlers = [[OFMutableDictionary alloc] init]; #ifdef OF_HAVE_THREADS mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif [self registerClass: [OFEmbeddedURIHandler class] forScheme: @"embedded"]; #ifdef OF_HAVE_FILES [self registerClass: [OFFileURIHandler class] forScheme: @"file"]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self registerClass: [OFHTTPURIHandler class] forScheme: @"http"]; [self registerClass: [OFHTTPURIHandler class] forScheme: @"https"]; #endif [self registerClass: [OFArchiveURIHandler class] forScheme: @"gzip"]; [self registerClass: [OFArchiveURIHandler class] forScheme: @"lha"]; [self registerClass: [OFArchiveURIHandler class] forScheme: @"tar"]; [self registerClass: [OFArchiveURIHandler class] forScheme: @"zip"]; } + (bool)registerClass: (Class)class forScheme: (OFString *)scheme { #ifdef OF_HAVE_THREADS [mutex lock]; @try { #endif OFURIHandler *handler; if ([handlers objectForKey: scheme] != nil) return false; handler = [[class alloc] initWithScheme: scheme]; @try { [handlers setObject: handler forKey: scheme]; } @finally { [handler release]; } #ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } #endif return true; } + (OFURIHandler *)handlerForURI: (OFURI *)URI { OF_KINDOF(OFURIHandler *) handler; #ifdef OF_HAVE_THREADS [mutex lock]; @try { #endif handler = [handlers objectForKey: URI.scheme]; #ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } #endif if (handler == nil) @throw [OFUnsupportedProtocolException exceptionWithURI: URI]; return handler; } + (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { return [[self handlerForURI: URI] openItemAtURI: URI mode: mode]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithScheme: (OFString *)scheme |
︙ | ︙ | |||
134 135 136 137 138 139 140 | - (void)dealloc { [_scheme release]; [super dealloc]; } | | | | | | | | | | | | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | - (void)dealloc { [_scheme release]; [super dealloc]; } - (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode { OF_UNRECOGNIZED_SELECTOR } - (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (bool)fileExistsAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (bool)directoryExistsAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (void)createDirectoryAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (void)removeItemAtURI: (OFURI *)URI { OF_UNRECOGNIZED_SELECTOR } - (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination { OF_UNRECOGNIZED_SELECTOR } - (void)createSymbolicLinkAtURI: (OFURI *)destination withDestinationPath: (OFString *)source { OF_UNRECOGNIZED_SELECTOR } - (bool)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination { return false; } - (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination { return false; } @end |
Modified src/OFUTF8String.m from [0c9d61efea] to [c76e8c2ef7].
︙ | ︙ | |||
342 343 344 345 346 347 348 | CASE(OFStringEncodingKOI8R, OFKOI8RTable) #endif #ifdef HAVE_KOI8_U CASE(OFStringEncodingKOI8U, OFKOI8UTable) #endif #undef CASE default: | | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | CASE(OFStringEncodingKOI8R, OFKOI8RTable) #endif #ifdef HAVE_KOI8_U CASE(OFStringEncodingKOI8U, OFKOI8UTable) #endif #undef CASE default: @throw [OFInvalidArgumentException exception]; } j = 0; for (size_t i = 0; i < cStringLength; i++) { unsigned char character = (unsigned char)cString[i]; OFUnichar unichar; char buffer[4]; |
︙ | ︙ | |||
928 929 930 931 932 933 934 | OFUnichar c; ssize_t length; if ((length = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c)) <= 0) @throw [OFInvalidEncodingException exception]; | | | | | 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | OFUnichar c; ssize_t length; if ((length = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c)) <= 0) @throw [OFInvalidEncodingException exception]; OFHashAddByte(&hash, (c & 0xFF0000) >> 16); OFHashAddByte(&hash, (c & 0x00FF00) >> 8); OFHashAddByte(&hash, c & 0x0000FF); i += length - 1; } OFHashFinalize(&hash); _s->hash = hash; |
︙ | ︙ | |||
1002 1003 1004 1005 1006 1007 1008 | _s->cStringLength - rangeLocation); } else { rangeLocation = range.location; rangeLength = range.length; } if (cStringLength == 0) | | | | | | 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 | _s->cStringLength - rangeLocation); } else { rangeLocation = range.location; rangeLength = range.length; } if (cStringLength == 0) return OFMakeRange(0, 0); if (cStringLength > rangeLength) return OFMakeRange(OFNotFound, 0); if (options & OFStringSearchBackwards) { for (size_t i = rangeLength - cStringLength;; i--) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } /* Did not match and we're at the last char */ if (i == 0) return OFMakeRange(OFNotFound, 0); } } else { for (size_t i = 0; i <= rangeLength - cStringLength; i++) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } } } return OFMakeRange(OFNotFound, 0); } - (bool)containsString: (OFString *)string { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; |
︙ | ︙ |
Modified src/OFUUID.h from [e7cc13e47d] to [e73d2af113].
︙ | ︙ | |||
52 53 54 55 56 57 58 59 60 61 62 63 64 65 | + (instancetype)UUIDWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Creates a new UUID with the specified UUID string. * * @param string The UUID string for the UUID * @return A new, autoreleased OFUUID */ + (instancetype)UUIDWithUUIDString: (OFString *)string; /** * @brief Initializes an already allocated OFUUID as a new random UUID as per * RFC 4122 version 4. * | > > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | + (instancetype)UUIDWithUUIDBytes: (const unsigned char [_Nonnull 16])bytes; /** * @brief Creates a new UUID with the specified UUID string. * * @param string The UUID string for the UUID * @return A new, autoreleased OFUUID * @throw OFInvalidFormatException The specified string is not a valid UUID * string */ + (instancetype)UUIDWithUUIDString: (OFString *)string; /** * @brief Initializes an already allocated OFUUID as a new random UUID as per * RFC 4122 version 4. * |
︙ | ︙ | |||
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /** * @brief Initializes an already allocated OFUUID with the specified UUID * string. * * @param string The UUID string to initialize the OFUUID with * @return An initialized OFUUID */ - (instancetype)initWithUUIDString: (OFString *)string; /** * @brief Compares the UUID to another UUID. * * @param UUID The UUID to compare to | > > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | /** * @brief Initializes an already allocated OFUUID with the specified UUID * string. * * @param string The UUID string to initialize the OFUUID with * @return An initialized OFUUID * @throw OFInvalidFormatException The specified string is not a valid UUID * string */ - (instancetype)initWithUUIDString: (OFString *)string; /** * @brief Compares the UUID to another UUID. * * @param UUID The UUID to compare to |
︙ | ︙ |
Modified src/OFUUID.m from [2113b35dea] to [3edaa624cf].
︙ | ︙ | |||
183 184 185 186 187 188 189 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(_bytes); i++) | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(_bytes); i++) OFHashAddByte(&hash, _bytes[i]); OFHashFinalize(&hash); return hash; } - (id)copy |
︙ | ︙ |
Modified src/OFValue.h from [823407a4d9] to [94dd083371].
︙ | ︙ | |||
31 32 33 34 35 36 37 | * @brief The ObjC type encoding of the value. */ @property (readonly, nonatomic) const char *objCType; /** * @brief The value as a pointer to void. * | | | | | | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | * @brief The ObjC type encoding of the value. */ @property (readonly, nonatomic) const char *objCType; /** * @brief The value as a pointer to void. * * @throw OFOutOfRangeException The value is not pointer-sized */ @property (readonly, nonatomic) void *pointerValue; /** * @brief The value as a non-retained object. * * @throw OFOutOfRangeException The value is not pointer-sized */ @property (readonly, nonatomic) id nonretainedObjectValue; /** * @brief The value as an OFRange. * * @throw OFOutOfRangeException The value is not OFRange-sized */ @property (readonly, nonatomic) OFRange rangeValue; /** * @brief The value as an OFPoint. * * @throw OFOutOfRangeException The value is not OFPoint-sized */ @property (readonly, nonatomic) OFPoint pointValue; /** * @brief The value as an OFSize. * * @throw OFOutOfRangeException The value is not OFSize-sized */ @property (readonly, nonatomic) OFSize sizeValue; /** * @brief The value as a OFRect. * * @throw OFOutOfRangeException The value is not OFRect-sized */ @property (readonly, nonatomic) OFRect rectValue; /** * @brief Creates a new, autorelease OFValue with the specified bytes of the * specified type. * |
︙ | ︙ | |||
150 151 152 153 154 155 156 | */ - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType; /** * @brief Gets the value. * | < < < > | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | */ - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType; /** * @brief Gets the value. * * @param value The buffer to copy the value into * @param size The size of the value * @throw OFOutOfRangeException The specified size does not match the value */ - (void)getValue: (void *)value size: (size_t)size; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for array literals to work */ @compatibility_alias NSValue OFValue; #endif |
Modified src/OFValue.m from [4253491c94] to [d37e008646].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * * 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 "OFValue.h" #import "OFBytesValue.h" #import "OFMethodSignature.h" #import "OFNonretainedObjectValue.h" #import "OFPointValue.h" #import "OFPointerValue.h" #import "OFRangeValue.h" | > > | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * * 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 "OFValue.h" #import "OFBytesValue.h" #import "OFMethodSignature.h" #import "OFNonretainedObjectValue.h" #import "OFPointValue.h" #import "OFPointerValue.h" #import "OFRangeValue.h" |
︙ | ︙ | |||
128 129 130 131 132 133 134 | value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; OFHashInit(&hash); for (size_t i = 0; i < size; i++) | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; OFHashInit(&hash); for (size_t i = 0; i < size; i++) OFHashAddByte(&hash, value[i]); OFHashFinalize(&hash); } @finally { OFFreeMemory(value); } return hash; |
︙ | ︙ |
Modified src/OFWindowsRegistryKey.h from [c114c8ff33] to [ad68073b0d].
︙ | ︙ | |||
70 71 72 73 74 75 76 | - (instancetype)init OF_UNAVAILABLE; /** * @brief Opens the subkey at the specified path. * * @param path The path of the subkey to open | | | < < < < < < < < < < < > | < < < < < < < < < < < < < < | < < | > > > | | < | | > | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | - (instancetype)init OF_UNAVAILABLE; /** * @brief Opens the subkey at the specified path. * * @param path The path of the subkey to open * @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 */ - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options; /** * @brief Creates a subkey at the specified path or opens it if it already * exists. * * @param path The path of the subkey to create * @param accessRights Please refer to the `RegCreateKeyEx()` documentation for * `samDesired` * @param securityAttributes Please refer to the `RegCreateKeyEx()` * documentation for `lpSecurityAttributes`. Usually * NULL. * @param options Please refer to the `RegCreateKeyEx()` documentation for * `dwOptions`. Usually 0. * @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 */ - (OFWindowsRegistryKey *) createSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes options: (DWORD)options disposition: (nullable DWORD *)disposition; /** * @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 |
︙ | ︙ |
Modified src/OFWindowsRegistryKey.m from [d93d6521e9] to [bf1674ca4d].
︙ | ︙ | |||
89 90 91 92 93 94 95 | if (_close) RegCloseKey(_hKey); [super dealloc]; } - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path | | < < < < < < < < | | > < < < < < < < < < < < | < | | > | | | | < < | > | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | if (_close) RegCloseKey(_hKey); [super dealloc]; } - (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options { void *pool = objc_autoreleasePoolPush(); LSTATUS status; HKEY subKey; if ([OFSystemInfo isWindowsNT]) status = RegOpenKeyExW(_hKey, path.UTF16String, options, accessRights, &subKey); else status = RegOpenKeyExA(_hKey, [path cStringWithEncoding: [OFLocale encoding]], options, accessRights, &subKey); if (status != ERROR_SUCCESS) @throw [OFOpenWindowsRegistryKeyFailedException exceptionWithRegistryKey: self path: path accessRights: accessRights options: options status: status]; objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; } - (OFWindowsRegistryKey *) createSubkeyAtPath: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options disposition: (DWORD *)disposition { void *pool = objc_autoreleasePoolPush(); LSTATUS status; HKEY subKey; if ([OFSystemInfo isWindowsNT]) status = RegCreateKeyExW(_hKey, path.UTF16String, 0, NULL, options, accessRights, securityAttributes, &subKey, NULL); else status = RegCreateKeyExA(_hKey, [path cStringWithEncoding: [OFLocale encoding]], 0, NULL, options, accessRights, securityAttributes, &subKey, NULL); if (status != ERROR_SUCCESS) @throw [OFCreateWindowsRegistryKeyFailedException exceptionWithRegistryKey: self path: path accessRights: accessRights securityAttributes: securityAttributes options: options status: status]; objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; |
︙ | ︙ |
Modified src/OFXMLAttribute.h from [facd4b4e2b] to [f37ed8f3fd].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | @class OFString; /** * @class OFXMLAttribute OFXMLAttribute.h ObjFW/OFXMLAttribute.h * * @brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFXMLNode { #if defined(OF_XML_ELEMENT_M) || defined(OF_XML_PARSER_M) @public #endif OFString *_name, *_Nullable _namespace, *_stringValue; bool _useDoubleQuotes; | > < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | @class OFString; /** * @class OFXMLAttribute OFXMLAttribute.h ObjFW/OFXMLAttribute.h * * @brief A representation of an attribute of an XML element as an object. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLAttribute: OFXMLNode { #if defined(OF_XML_ELEMENT_M) || defined(OF_XML_PARSER_M) @public #endif OFString *_name, *_Nullable _namespace, *_stringValue; bool _useDoubleQuotes; } /** * @brief The name of the attribute. */ @property (readonly, nonatomic) OFString *name; |
︙ | ︙ | |||
87 88 89 90 91 92 93 | * @param name The name of the attribute * @param nameSpace The namespace of the attribute * @param stringValue The string value of the attribute * @return An initialized OFXMLAttribute with the specified parameters */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 | * @param name The name of the attribute * @param nameSpace The namespace of the attribute * @param stringValue The string value of the attribute * @return An initialized OFXMLAttribute with the specified parameters */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (OFString *)stringValue OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END |
Modified src/OFXMLAttribute.m from [f2a6cbc394] to [fef93ca0aa].
︙ | ︙ | |||
66 67 68 69 70 71 72 | } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { | | > | | | | | | > > > | > > > > > > | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool; OFString *name, *namespace, *stringValue; @try { pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; name = [element attributeForName: @"name"].stringValue; namespace = [element attributeForName: @"namespace"] .stringValue; stringValue = [element attributeForName: @"stringValue"] .stringValue; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: name namespace: namespace stringValue: stringValue]; @try { objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
174 175 176 177 178 179 180 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)description { | | | > | | 184 185 186 187 188 189 190 191 192 193 194 195 196 | objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: name=%@, namespace=%@, " @"stringValue=%@>", self.class, _name, _namespace, _stringValue]; } @end |
Modified src/OFXMLCDATA.h from [566e9353f4] to [45c442f70d].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCDATA OFXMLCDATA.h ObjFW/OFXMLCDATA.h * * @brief A class representing XML CDATA. */ @interface OFXMLCDATA: OFXMLNode { OFString *_CDATA; | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCDATA OFXMLCDATA.h ObjFW/OFXMLCDATA.h * * @brief A class representing XML CDATA. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLCDATA: OFXMLNode { OFString *_CDATA; } /** * @brief Creates a new OFXMLCDATA with the specified string. * * @param string The string value for the CDATA * @return A new OFXMLCDATA |
︙ | ︙ |
Modified src/OFXMLCDATA.m from [53038bdcd2] to [268b8de778].
︙ | ︙ | |||
112 113 114 115 116 117 118 | OFString *ret = [OFString stringWithFormat: @"<![CDATA[%@]]>", tmp]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } | < < < < < < < < < < < | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | OFString *ret = [OFString stringWithFormat: @"<![CDATA[%@]]>", tmp]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { |
︙ | ︙ |
Modified src/OFXMLCharacters.h from [314ee7db3d] to [50ac8d5a7f].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCharacters OFXMLCharacters.h ObjFW/OFXMLCharacters.h * * @brief A class representing XML characters. */ @interface OFXMLCharacters: OFXMLNode { OFString *_characters; | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLCharacters OFXMLCharacters.h ObjFW/OFXMLCharacters.h * * @brief A class representing XML characters. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLCharacters: OFXMLNode { OFString *_characters; } /** * @brief Creates a new OFXMLCharacters with the specified string. * * @param string The string value for the characters * @return A new OFXMLCharacters |
︙ | ︙ |
Modified src/OFXMLCharacters.m from [9ea4b56013] to [53e16f06bf].
︙ | ︙ | |||
104 105 106 107 108 109 110 | } - (OFString *)XMLString { return _characters.stringByXMLEscaping; } | < < < < < < < < < < < | | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | } - (OFString *)XMLString { return _characters.stringByXMLEscaping; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _characters]; |
︙ | ︙ |
Modified src/OFXMLComment.h from [cf96f4e7b5] to [566c15f0b8].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLComment OFXMLComment.h ObjFW/OFXMLComment.h * * @brief A class for representing XML comments. */ @interface OFXMLComment: OFXMLNode { OFString *_text; | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLComment OFXMLComment.h ObjFW/OFXMLComment.h * * @brief A class for representing XML comments. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLComment: OFXMLNode { OFString *_text; } /** * @brief The comment text. */ @property (readonly, nonatomic) OFString *text; |
︙ | ︙ |
Modified src/OFXMLComment.m from [842e736751] to [9e48182a96].
︙ | ︙ | |||
101 102 103 104 105 106 107 | } - (OFString *)XMLString { return [OFString stringWithFormat: @"<!--%@-->", _text]; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | } - (OFString *)XMLString { return [OFString stringWithFormat: @"<!--%@-->", _text]; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _text]; |
︙ | ︙ |
Modified src/OFXMLElement.h from [470c1e0790] to [03aa33631b].
︙ | ︙ | |||
28 29 30 31 32 33 34 | /** * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h * * @brief A class which stores an XML element. */ @interface OFXMLElement: OFXMLNode { | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /** * @class OFXMLElement OFXMLElement.h ObjFW/OFXMLElement.h * * @brief A class which stores an XML element. */ @interface OFXMLElement: OFXMLNode { OFString *_name, *_Nullable _namespace; OFMutableArray OF_GENERIC(OFXMLAttribute *) *_Nullable _attributes; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _namespaces; OFMutableArray OF_GENERIC(OFXMLNode *) *_Nullable _children; OF_RESERVE_IVARS(OFXMLElement, 4) } |
︙ | ︙ | |||
51 52 53 54 55 56 57 | #ifndef __cplusplus @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *namespace; #else @property OF_NULLABLE_PROPERTY (copy, nonatomic, getter=namespace, setter=setNamespace:) OFString *nameSpace; #endif | < < < < < < | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #ifndef __cplusplus @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *namespace; #else @property OF_NULLABLE_PROPERTY (copy, nonatomic, getter=namespace, setter=setNamespace:) OFString *nameSpace; #endif /** * @brief An array with the attributes of the element. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFArray OF_GENERIC(OFXMLAttribute *) *attributes; /** |
︙ | ︙ | |||
118 119 120 121 122 123 124 | * @return A new autoreleased OFXMLElement with the specified element name, * namespace and value */ + (instancetype)elementWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (nullable OFString *)stringValue; | < < < < < < < < < | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | * @return A new autoreleased OFXMLElement with the specified element name, * namespace and value */ + (instancetype)elementWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (nullable OFString *)stringValue; /** * @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 */ + (instancetype)elementWithXMLString: (OFString *)string; |
︙ | ︙ | |||
176 177 178 179 180 181 182 | * * @param name The name for the element * @param nameSpace The namespace for the element * @return An initialized OFXMLElement with the specified element name and * namespace */ - (instancetype)initWithName: (OFString *)name | | > < < < < < < < < < < < < | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | * * @param name The name for the element * @param nameSpace The namespace for the element * @return An initialized OFXMLElement with the specified element name and * namespace */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFXMLElement with the specified name, * namespace and value. * * @param name The name for the element * @param nameSpace The namespace for the element * @param stringValue The value for the element * @return An initialized OFXMLElement with the specified element name, * namespace and value */ - (instancetype)initWithName: (OFString *)name namespace: (nullable OFString *)nameSpace stringValue: (nullable OFString *)stringValue; /** * @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 */ - (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 */ - (instancetype)initWithStream: (OFStream *)stream; /** * @brief Sets a prefix for a namespace. * * @param prefix The prefix for the namespace * @param nameSpace The namespace for which the prefix is set */ - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)nameSpace; |
︙ | ︙ | |||
345 346 347 348 349 350 351 | - (void)removeChild: (OFXMLNode *)child; /** * @brief Removes the child at the specified index. * * @param index The index of the child to remove */ | < > | 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | - (void)removeChild: (OFXMLNode *)child; /** * @brief Removes the child at the specified index. * * @param index The index of the child to remove */ - (void)removeChildAtIndex: (size_t)index; /** * @brief Replaces the first child that is equal to the specified OFXMLNode * with the specified node. * * @param child The child to replace * @param node The node to replace the child with */ |
︙ | ︙ | |||
369 370 371 372 373 374 375 | - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node; /** * @brief Returns all children that have the specified namespace. * * @return All children that have the specified namespace */ | | | | | | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node; /** * @brief Returns all children that have the specified namespace. * * @return All children that have the specified namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForNamespace: (nullable OFString *)elementNS; /** * @brief Returns the first child element with the specified name. * * @param elementName The name of the element * @return The first child element with the specified name */ - (nullable OFXMLElement *)elementForName: (OFString *)elementName; /** * @brief Returns the child elements with the specified name. * * @param elementName The name of the elements * @return The child elements with the specified name */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForName: (OFString *)elementName; /** * @brief Returns the first child element with the specified name and namespace. * * @param elementName The name of the element * @param elementNS The namespace of the element * @return The first child element with the specified name and namespace |
︙ | ︙ | |||
409 410 411 412 413 414 415 416 417 418 419 420 | * @param elementName The name of the elements * @param elementNS The namespace of the elements * @return The child elements with the specified name and namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForName: (OFString *)elementName namespace: (nullable OFString *)elementNS; @end OF_ASSUME_NONNULL_END #import "OFXMLElement+Serialization.h" | > > > > > > > > > > > > > > > > > > > > > > | 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | * @param elementName The name of the elements * @param elementNS The namespace of the elements * @return The child elements with the specified name and namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *) elementsForName: (OFString *)elementName namespace: (nullable OFString *)elementNS; /** * @brief Returns an OFString representing the OFXMLElement as an XML string * with the specified indentation per level. * * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation */ - (OFString *)XMLStringWithIndentation: (unsigned int)indentation; /** * @brief Returns an OFString representing the OFXMLElement as an XML string * with the specified default namespace and indentation per level. * * @param defaultNS The default namespace * @param indentation The indentation per level * @return An OFString representing the OFXMLNode as an XML string with * indentation */ - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation; @end OF_ASSUME_NONNULL_END #import "OFXMLElement+Serialization.h" |
Modified src/OFXMLElement.m from [5df92b5be9] to [ada192cadd].
︙ | ︙ | |||
69 70 71 72 73 74 75 | [super dealloc]; } @end @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; | < | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | [super dealloc]; } @end @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; + (instancetype)elementWithName: (OFString *)name { return [[[self alloc] initWithName: name] autorelease]; } + (instancetype)elementWithName: (OFString *)name |
︙ | ︙ | |||
99 100 101 102 103 104 105 | stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name namespace: namespace stringValue: stringValue] autorelease]; } | < < < < < | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | stringValue: (OFString *)stringValue { return [[[self alloc] initWithName: name namespace: namespace stringValue: stringValue] autorelease]; } + (instancetype)elementWithXMLString: (OFString *)string { return [[[self alloc] initWithXMLString: string] autorelease]; } + (instancetype)elementWithStream: (OFStream *)stream { |
︙ | ︙ | |||
135 136 137 138 139 140 141 | namespace: nil stringValue: stringValue]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { | < < < < < < < < < < | > > | | < < | < < < < < < > > > | | | < < | | | | | | | | | | | | > | > > > | > > > > > > > > > > > > | > > > > > > > | | | < < | | | | | | | | | | > | > > > | > > > > > > > > > > > > | > > > > | > | < < < < | > | > > > > | > | > | > > > | | | | | | > > > > > > > > | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | namespace: nil stringValue: stringValue]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { self = [super of_init]; @try { if (name == nil) @throw [OFInvalidArgumentException exception]; _name = [name copy]; _namespace = [namespace copy]; _namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: @"http://www.w3.org/XML/1998/namespace", @"xml", @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { self = [self initWithName: name namespace: namespace]; @try { if (stringValue != nil) self.stringValue = stringValue; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithXMLString: (OFString *)string { void *pool; OFXMLElement *element; @try { OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElementElementBuilderDelegate *delegate; if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseString: string]; if (!parser.hasFinishedParsing) @throw [OFMalformedXMLException exceptionWithParser: parser]; element = delegate->_element; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: element->_name namespace: element->_namespace]; @try { [_attributes release]; _attributes = [element->_attributes retain]; [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithStream: (OFStream *)stream { void *pool; OFXMLElement *element; @try { OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElementElementBuilderDelegate *delegate; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseStream: stream]; if (!parser.hasFinishedParsing) @throw [OFMalformedXMLException exceptionWithParser: parser]; element = delegate->_element; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: element->_name namespace: element->_namespace]; @try { [_attributes release]; _attributes = [element->_attributes retain]; [_namespaces release]; _namespaces = [element->_namespaces retain]; [_children release]; _children = [element->_children retain]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool; OFString *name, *namespace; @try { pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; name = [element attributeForName: @"name"].stringValue; namespace = [element attributeForName: @"namespace"].stringValue; } @catch (id e) { [self release]; @throw e; } self = [self initWithName: name namespace: namespace]; @try { OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; attributesElement = [[element elementForName: @"attributes" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; namespacesElement = [[element elementForName: @"namespaces" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; childrenElement = [[element elementForName: @"children" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; [_attributes release]; _attributes = nil; _attributes = [attributesElement.objectByDeserializing mutableCopy]; [_namespaces release]; _namespaces = nil; _namespaces = [namespacesElement.objectByDeserializing mutableCopy]; [_children release]; _children = nil; _children = [childrenElement.objectByDeserializing mutableCopy]; /* Sanity checks */ if ((_attributes != nil && ![_attributes isKindOfClass: [OFMutableArray class]]) || (_namespaces != nil && ![_namespaces isKindOfClass: |
︙ | ︙ | |||
328 329 330 331 332 333 334 | [_namespaces setObject: @"xml" forKey: @"http://www.w3.org/XML/1998/namespace"]; [_namespaces setObject: @"xmlns" forKey: @"http://www.w3.org/2000/xmlns/"]; | < < < < | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | [_namespaces setObject: @"xml" forKey: @"http://www.w3.org/XML/1998/namespace"]; [_namespaces setObject: @"xmlns" forKey: @"http://www.w3.org/2000/xmlns/"]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_name release]; [_namespace release]; [_attributes release]; [_namespaces release]; [_children release]; [super dealloc]; } |
︙ | ︙ | |||
401 402 403 404 405 406 407 | } [ret makeImmutable]; return ret; } | | | | | | < < < < < < < < < < < < < | | | < > > | | | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 | } [ret makeImmutable]; return ret; } - (OFString *)of_XMLStringWithDefaultNS: (OFString *)defaultNS namespaces: (OFDictionary *)allNS indentation: (unsigned int)indentation level: (unsigned int)level OF_DIRECT { void *pool; char *cString; size_t length, i; OFString *prefix, *ret; pool = objc_autoreleasePoolPush(); /* Add the namespaces of the current element */ if (allNS != nil) { OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; OFString *key, *object; tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [tmp setObject: object forKey: key]; allNS = tmp; } else allNS = _namespaces; prefix = [allNS objectForKey: (_namespace != nil ? _namespace : (OFString *)@"")]; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); cString = OFAllocMemory(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; if (prefix.length > 0) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; /* xmlns if necessary */ if (prefix.length == 0 && defaultNS != _namespace && ![defaultNS isEqual: _namespace]) { length += _namespace.UTF8StringLength + 9; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); i += _namespace.UTF8StringLength; cString[i++] = '\''; defaultNS = _namespace; } /* Attributes */ for (OFXMLAttribute *attribute in _attributes) { void *pool2 = objc_autoreleasePoolPush(); const char *attributeNameCString = attribute->_name.UTF8String; size_t attributeNameLength = attribute->_name.UTF8StringLength; OFString *attributePrefix = nil; OFString *tmp = attribute.stringValue.stringByXMLEscaping; char delimiter = (attribute->_useDoubleQuotes ? '"' : '\''); if (attribute->_namespace != nil && [(attributePrefix = [allNS objectForKey: attribute->_namespace]) length] == 0) @throw [OFUnboundNamespaceException exceptionWithNamespace: attribute.namespace element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; |
︙ | ︙ | |||
559 560 561 562 563 564 565 | unsigned int ind = (indent ? indentation : 0); if (ind) [tmp addItem: "\n"]; if ([child isKindOfClass: [OFXMLElement class]]) childString = [(OFXMLElement *)child | | | | | > | | < > | | > | 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | unsigned int ind = (indent ? indentation : 0); if (ind) [tmp addItem: "\n"]; if ([child isKindOfClass: [OFXMLElement class]]) childString = [(OFXMLElement *)child of_XMLStringWithDefaultNS: defaultNS namespaces: allNS indentation: ind level: level + 1]; else { childString = child.XMLString; for (unsigned int j = 0; j < ind * (level + 1); j++) [tmp addItem: " "]; } [tmp addItems: childString.UTF8String count: childString.UTF8StringLength]; } if (indent) [tmp addItem: "\n"]; |
︙ | ︙ | |||
592 593 594 595 596 597 598 | if (indent) { memset(cString + i, ' ', level * indentation); i += level * indentation; } cString[i++] = '<'; cString[i++] = '/'; | | | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 | if (indent) { memset(cString + i, ' ', level * indentation); i += level * indentation; } cString[i++] = '<'; cString[i++] = '/'; if (prefix.length > 0) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; |
︙ | ︙ | |||
622 623 624 625 626 627 628 | OFFreeMemory(cString); } return ret; } - (OFString *)XMLString { | | | | | | | | | | | | | | | < < < < | 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | OFFreeMemory(cString); } return ret; } - (OFString *)XMLString { return [self of_XMLStringWithDefaultNS: nil namespaces: nil indentation: 0 level: 0]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return [self of_XMLStringWithDefaultNS: nil namespaces: nil indentation: indentation level: 0]; } - (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS indentation: (unsigned int)indentation { return [self of_XMLStringWithDefaultNS: defaultNS namespaces: nil indentation: indentation level: 0]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; if (_name != nil) [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) [element addAttributeWithName: @"namespace" stringValue: _namespace]; if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" namespace: OFSerializationNS]; [attributesElement addChild: |
︙ | ︙ | |||
812 813 814 815 816 817 818 | } } - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { if (prefix.length == 0) @throw [OFInvalidArgumentException exception]; | < < | 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | } } - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { if (prefix.length == 0) @throw [OFInvalidArgumentException exception]; [_namespaces setObject: prefix forKey: namespace]; } - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { [self setPrefix: prefix forNamespace: namespace]; |
︙ | ︙ | |||
992 993 994 995 996 997 998 | element = object; if (element->_name != _name && ![element->_name isEqual: _name]) return false; if (element->_namespace != _namespace && ![element->_namespace isEqual: _namespace]) return false; | < < < | 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 | element = object; if (element->_name != _name && ![element->_name isEqual: _name]) return false; if (element->_namespace != _namespace && ![element->_namespace isEqual: _namespace]) return false; if (element->_attributes != _attributes && ![element->_attributes isEqual: _attributes]) return false; if (element->_namespaces != _namespaces && ![element->_namespaces isEqual: _namespaces]) return false; if (element->_children != _children && |
︙ | ︙ | |||
1016 1017 1018 1019 1020 1021 1022 | { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); | < > > > > > > > > > > > | > | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); OFHashAddHash(&hash, _attributes.hash); OFHashAddHash(&hash, _namespaces.hash); OFHashAddHash(&hash, _children.hash); OFHashFinalize(&hash); return hash; } - (id)copy { OFXMLElement *copy = [[OFXMLElement alloc] of_init]; @try { copy->_name = [_name copy]; copy->_namespace = [_namespace copy]; copy->_attributes = [_attributes mutableCopy]; copy->_namespaces = [_namespaces mutableCopy]; copy->_children = [_children mutableCopy]; } @catch (id e) { [copy release]; @throw e; } return copy; } @end |
Modified src/OFXMLElementBuilder.h from [657f65f42e] to [db177baac1].
︙ | ︙ | |||
50 51 52 53 54 55 56 | * * This is usually called for comments or whitespace character data before the * root element. * * @param builder The builder which built the OFXMLNode without parent * @param node The OFXMLNode the OFXMLElementBuilder built */ | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | * * This is usually called for comments or whitespace character data before the * root element. * * @param builder The builder which built the OFXMLNode without parent * @param node The OFXMLNode the OFXMLElementBuilder built */ - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildOrphanNode: (OFXMLNode *)node; /** * @brief This callback is called when the OFXMLElementBuilder gets a close tag * which does not belong there. * * Most likely, the OFXMLElementBuilder was used to build XML only of a child * of the root element and the root element was closed. Often the delegate is |
︙ | ︙ | |||
98 99 100 101 102 103 104 105 106 107 108 | * @brief A class implementing the OFXMLParserDelegate protocol that can build * OFXMLElements from the document parsed by the OFXMLParser. * * It can also be used to build OFXMLElements from parts of the document by * first parsing stuff using the OFXMLParser with another delegate and then * setting the OFXMLElementBuilder as delegate for the parser. */ @interface OFXMLElementBuilder: OFObject <OFXMLParserDelegate> { OFMutableArray OF_GENERIC(OFXMLElement *) *_stack; id <OFXMLElementBuilderDelegate> _Nullable _delegate; | > < | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | * @brief A class implementing the OFXMLParserDelegate protocol that can build * OFXMLElements from the document parsed by the OFXMLParser. * * It can also be used to build OFXMLElements from parts of the document by * first parsing stuff using the OFXMLParser with another delegate and then * setting the OFXMLElementBuilder as delegate for the parser. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLElementBuilder: OFObject <OFXMLParserDelegate> { OFMutableArray OF_GENERIC(OFXMLElement *) *_stack; id <OFXMLElementBuilderDelegate> _Nullable _delegate; } /** * @brief The delegate for the OFXMLElementBuilder. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFXMLElementBuilderDelegate> delegate; |
︙ | ︙ |
Modified src/OFXMLElementBuilder.m from [b8984275c9] to [87c5fa2116].
︙ | ︙ | |||
54 55 56 57 58 59 60 | [_stack release]; [super dealloc]; } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target | | | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | [_stack release]; [super dealloc]; } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (OFString *)text { OFXMLProcessingInstruction *node = [OFXMLProcessingInstruction processingInstructionWithTarget: target text: text]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attributes |
︙ | ︙ | |||
132 133 134 135 136 137 138 | node = [OFXMLCharacters charactersWithString: characters]; parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: | | | | | | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | node = [OFXMLCharacters charactersWithString: characters]; parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA { OFXMLCDATA *node = [OFXMLCDATA CDATAWithString: CDATA]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { OFXMLComment *node = [OFXMLComment commentWithText: comment]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildOrphanNode:)]) [_delegate elementBuilder: self didBuildOrphanNode: node]; } - (OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(elementBuilder:foundUnknownEntityNamed:)]) return [_delegate elementBuilder: self foundUnknownEntityNamed: entity]; return nil; } @end |
Modified src/OFXMLNode.h from [506d741d52] to [7374215293].
︙ | ︙ | |||
62 63 64 65 66 67 68 | * @brief A string representing the node as an XML string. */ @property (readonly, nonatomic) OFString *XMLString; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; | < < < < < < < < < < < < < < < < < < < < < < | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | * @brief A string representing the node as an XML string. */ @property (readonly, nonatomic) OFString *XMLString; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithSerialization: (OFXMLElement *)element OF_UNAVAILABLE; /** * @brief The contents of the receiver as a `long long` value in the specified * base. * * @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 contents of the receiver as a `long long` value in the specified * base */ - (long long)longLongValueWithBase: (unsigned char)base; /** * @brief The contents of the receiver as an `unsigned long long` value in the * specified base. * * @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 contents of the receiver as an `unsigned long long` value in the * specified base */ - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base; @end OF_ASSUME_NONNULL_END |
Modified src/OFXMLNode.m from [fd3b7789fd] to [ae31a5d0f3].
︙ | ︙ | |||
45 46 47 48 49 50 51 | } - (long long)longLongValue { return self.stringValue.longLongValue; } | | | < < < < < < < < < < < | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | } - (long long)longLongValue { return self.stringValue.longLongValue; } - (long long)longLongValueWithBase: (unsigned char)base { return [self.stringValue longLongValueWithBase: base]; } - (unsigned long long)unsignedLongLongValue { return self.stringValue.unsignedLongLongValue; } - (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base { return [self.stringValue unsignedLongLongValueWithBase: base]; } - (float)floatValue { return self.stringValue.floatValue; } - (double)doubleValue { return self.stringValue.doubleValue; } - (OFString *)XMLString { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { OF_UNRECOGNIZED_SELECTOR } - (id)copy { return [self retain]; } @end |
Modified src/OFXMLParser.h from [e4ba7bdb79] to [beb6c0af85].
︙ | ︙ | |||
35 36 37 38 39 40 41 | @optional /** * @brief This callback is called when the XML parser found a processing * instruction. * * @param parser The parser which found a processing instruction * @param target The target of the processing instruction | | | | | | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | @optional /** * @brief This callback is called when the XML parser found a processing * instruction. * * @param parser The parser which found a processing instruction * @param target The target of the processing instruction * @param text The text of the processing instruction */ - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (OFString *)text; /** * @brief This callback is called when the XML parser found the start of a new * tag. * * @param parser The parser which found a new tag * @param name The name of the tag which just started * @param prefix The prefix of the tag which just started or `nil` * @param nameSpace The namespace of the tag which just started or `nil` * @param attributes The attributes included in the tag which just started or * `nil` */ - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (nullable OFString *)prefix namespace: (nullable OFString *)nameSpace attributes: (nullable OFArray OF_GENERIC(OFXMLAttribute *) *)attributes; /** * @brief This callback is called when the XML parser found the end of a tag. * * @param parser The parser which found the end of a tag * @param name The name of the tag which just ended * @param prefix The prefix of the tag which just ended or `nil` * @param nameSpace The namespace of the tag which just ended or `nil` */ - (void)parser: (OFXMLParser *)parser didEndElement: (OFString *)name prefix: (nullable OFString *)prefix namespace: (nullable OFString *)nameSpace; /** * @brief This callback is called when the XML parser found characters. * * In case there are comments or CDATA, it is possible that this callback is * called multiple times in a row. * |
︙ | ︙ |
Modified src/OFXMLParser.m from [beb767fa68] to [7be6fc7234].
︙ | ︙ | |||
110 111 112 113 114 115 116 | [stateInDOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, OFStringEncoding encoding, size_t length) { | | | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | [stateInDOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, OFStringEncoding encoding, size_t length) { if OF_LIKELY (encoding == OFStringEncodingUTF8) [buffer addItems: string count: length]; else { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; [buffer addItems: tmp.UTF8String count: tmp.UTF8StringLength]; |
︙ | ︙ | |||
495 496 497 498 499 500 501 | static void inProcessingInstructionState(OFXMLParser *self) { if (self->_data[self->_i] == '?') self->_level = 1; else if (self->_level == 1 && self->_data[self->_i] == '>') { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | static void inProcessingInstructionState(OFXMLParser *self) { if (self->_data[self->_i] == '?') self->_level = 1; else if (self->_level == 1 && self->_data[self->_i] == '>') { void *pool = objc_autoreleasePoolPush(); OFString *PI, *target, *text = nil; OFCharacterSet *whitespaceCS; size_t pos; appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); PI = transformString(self, self->_buffer, 1, false); whitespaceCS = [OFCharacterSet characterSetWithCharactersInString: @" \r\n\r"]; pos = [PI indexOfCharacterFromSet: whitespaceCS]; if (pos != OFNotFound) { target = [PI substringToIndex: pos]; text = [[PI substringFromIndex: pos + 1] stringByDeletingEnclosingWhitespaces]; if (text.length == 0) text = nil; } else target = PI; if ([target caseInsensitiveCompare: @"xml"] == OFOrderedSame) if (!parseXMLProcessingInstruction(self, text)) @throw [OFMalformedXMLException exceptionWithParser: self]; if ([self->_delegate respondsToSelector: @selector( parser:foundProcessingInstructionWithTarget:text:)]) [self->_delegate parser: self foundProcessingInstructionWithTarget: target text: text]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; |
︙ | ︙ |
Modified src/OFXMLProcessingInstruction.h from [c7ed4d9c0a] to [2e0c868afb].
︙ | ︙ | |||
19 20 21 22 23 24 25 26 27 | /** * @class OFXMLProcessingInstruction \ * OFXMLProcessingInstruction.h ObjFW/OFXMLProcessingInstruction.h * * @brief A class for representing an XML processing instruction. */ @interface OFXMLProcessingInstruction: OFXMLNode { | > | < | | | | | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | /** * @class OFXMLProcessingInstruction \ * OFXMLProcessingInstruction.h ObjFW/OFXMLProcessingInstruction.h * * @brief A class for representing an XML processing instruction. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLProcessingInstruction: OFXMLNode { OFString *_target, *_Nullable _text; } /** * @brief The target of the processing instruction. */ @property (readonly, nonatomic) OFString *target; /** * @brief The text of the processing instruction. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *text; /** * @brief Creates a new OFXMLProcessingInstruction with the specified target * and text. * * @param target The target for the processing instruction * @param text The text for the processing instruction * @return A new OFXMLProcessingInstruction */ + (instancetype)processingInstructionWithTarget: (OFString *)target text: (OFString *)text; /** * @brief Initializes an already allocated OFXMLProcessingInstruction with the * specified target and text. * * @param target The target for the processing instruction * @param text The text for the processing instruction * @return An initialized OFXMLProcessingInstruction */ - (instancetype)initWithTarget: (OFString *)target text: (OFString *)text OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END |
Modified src/OFXMLProcessingInstruction.m from [16bf6dae0d] to [98f7922e9f].
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLNode+Private.h" #import "OFInvalidArgumentException.h" @implementation OFXMLProcessingInstruction | | | | | | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLNode+Private.h" #import "OFInvalidArgumentException.h" @implementation OFXMLProcessingInstruction @synthesize target = _target, text = _text; + (instancetype)processingInstructionWithTarget: (OFString *)target text: (OFString *)text { return [[[self alloc] initWithTarget: target text: text] autorelease]; } - (instancetype)initWithTarget: (OFString *)target text: (OFString *)text { self = [super of_init]; @try { _target = [target copy]; _text = [text copy]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
63 64 65 66 67 68 69 | targetAttr = [element attributeForName: @"target" namespace: OFSerializationNS]; if (targetAttr.stringValue.length == 0) @throw [OFInvalidArgumentException exception]; self = [self initWithTarget: targetAttr.stringValue | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | targetAttr = [element attributeForName: @"target" namespace: OFSerializationNS]; if (targetAttr.stringValue.length == 0) @throw [OFInvalidArgumentException exception]; self = [self initWithTarget: targetAttr.stringValue text: element.stringValue]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_target release]; [_text release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLProcessingInstruction *processingInstruction; if (object == self) return true; if (![object isKindOfClass: [OFXMLProcessingInstruction class]]) return false; processingInstruction = object; if (![processingInstruction->_target isEqual: _target]) return false; if (processingInstruction->_text != _text && ![processingInstruction->_text isEqual: _text]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _target.hash); OFHashAddHash(&hash, _text.hash); OFHashFinalize(&hash); return hash; } - (OFString *)stringValue { return @""; } - (OFString *)XMLString { if (_text.length > 0) return [OFString stringWithFormat: @"<?%@ %@?>", _target, _text]; else return [OFString stringWithFormat: @"<?%@?>", _target]; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *ret = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _text]; void *pool = objc_autoreleasePoolPush(); [ret addAttribute: [OFXMLAttribute attributeWithName: @"target" stringValue: _target]]; objc_autoreleasePoolPop(pool); return ret; } @end |
Modified src/OFZIPArchive.h from [cd08e80056] to [f20f6f1fc0].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | * * @brief A class for accessing and manipulating ZIP files. */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { OFStream *_stream; int64_t _offset; uint_least8_t _mode; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_Nullable _archiveComment; OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_Nullable _lastReturnedStream; } /** | > > > > > > > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | * * @brief A class for accessing and manipulating ZIP files. */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { OFStream *_stream; #ifdef OF_ZIP_ARCHIVE_M @public #endif int64_t _offset; @protected uint_least8_t _mode; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_Nullable _archiveComment; #ifdef OF_ZIP_ARCHIVE_M @public #endif OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) *_pathToEntryMap; OFStream *_Nullable _lastReturnedStream; } /** |
︙ | ︙ | |||
70 71 72 73 74 75 76 | * @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 */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; | < | | | > > > > > > > > > > < | | < | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | * @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 */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; /** * @brief Creates a new OFZIPArchive object with the specified file. * * @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 */ + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Creates a URI for accessing a the specified file within the specified * ZIP archive. * * @param path The path of the file within the archive * @param URI The URI of the archive * @return A URI for accessing the specified file within the specified ZIP * archive */ + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFZIPArchive object with the * specified stream. * * @param stream A stream from which the ZIP archive will be read. * 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 */ - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFZIPArchive object with the * specified file. * * @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 */ - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode; /** * @brief Returns a stream for reading the specified file from the archive. * * @note This method is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the |
︙ | ︙ |
Modified src/OFZIPArchive.m from [2bbedc5f4d] to [3d9576934f].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 17 18 19 20 21 22 | * * 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 <errno.h> #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" | > > > | | | > | < | < | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * * 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. */ #define OF_ZIP_ARCHIVE_M #include "config.h" #include <errno.h> #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFArchiveURIHandler.h" #import "OFArray.h" #import "OFCRC32.h" #import "OFData.h" #import "OFDictionary.h" #import "OFInflate64Stream.h" #import "OFInflateStream.h" #import "OFSeekableStream.h" #import "OFStream.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" |
︙ | ︙ | |||
56 57 58 59 60 61 62 | modeAppend }; OF_DIRECT_MEMBERS @interface OFZIPArchive () - (void)of_readZIPInfo; - (void)of_readEntries; | < | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | modeAppend }; OF_DIRECT_MEMBERS @interface OFZIPArchive () - (void)of_readZIPInfo; - (void)of_readEntries; - (void)of_writeCentralDirectory; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveLocalFileHeader: OFObject { @public |
︙ | ︙ | |||
79 80 81 82 83 84 85 86 87 | - (instancetype)initWithStream: (OFStream *)stream; - (bool)matchesEntry: (OFZIPArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveFileReadStream: OFStream { OFStream *_stream, *_decompressedStream; OFZIPArchiveEntry *_entry; | > | | > | > | > | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | - (instancetype)initWithStream: (OFStream *)stream; - (bool)matchesEntry: (OFZIPArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveFileReadStream: OFStream { OFZIPArchive *_archive; OFStream *_stream, *_decompressedStream; OFZIPArchiveEntry *_entry; unsigned long long _toRead; uint32_t _CRC32; bool _atEndOfStream; } - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFZIPArchiveEntry *)entry; @end OF_DIRECT_MEMBERS @interface OFZIPArchiveFileWriteStream: OFStream { OFZIPArchive *_archive; OFStream *_stream; uint32_t _CRC32; @public unsigned long long _bytesWritten; OFMutableZIPArchiveEntry *_entry; } - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry; @end uint32_t OFZIPArchiveReadField32(const uint8_t **data, uint16_t *size) { uint32_t field = 0; |
︙ | ︙ | |||
140 141 142 143 144 145 146 | *size -= 8; return field; } static void seekOrThrowInvalidFormat(OFSeekableStream *stream, | | < | | | > > > > | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | *size -= 8; return field; } static void seekOrThrowInvalidFormat(OFSeekableStream *stream, OFStreamOffset offset, OFSeekWhence whence) { @try { [stream seekToOffset: offset whence: whence]; } @catch (OFSeekFailedException *e) { if (e.errNo == EINVAL) @throw [OFInvalidFormatException exception]; @throw e; } } @implementation OFZIPArchive @synthesize archiveComment = _archiveComment; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } + (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode { return [[[self alloc] initWithURI: URI mode: mode] autorelease]; } + (OFURI *)URIForFilePath: (OFString *)path inArchiveWithURI: (OFURI *)URI { return OFArchiveURIHandlerURIForFileInArchive(@"zip", path, URI); } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode |
︙ | ︙ | |||
201 202 203 204 205 206 207 | [self of_readZIPInfo]; [self of_readEntries]; } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, | | < | > | > | | | < > > > > | | | < < | > < < | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | [self of_readZIPInfo]; [self of_readEntries]; } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFStreamOffset)_offset, OFSeekSet); } } @catch (id e) { /* * If we are in write or append mode, we do not want -[close] * to write anything to it on error - after all, it might not * be a ZIP file which we would destroy otherwise. */ [_stream release]; _stream = nil; [self release]; @throw e; } return self; } - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFStream *stream; @try { if ([mode isEqual: @"a"]) stream = [OFURIHandler openItemAtURI: URI mode: @"r+"]; else stream = [OFURIHandler openItemAtURI: URI mode: mode]; } @catch (id e) { [self release]; @throw e; } self = [self initWithStream: stream mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_stream != nil) [self close]; [_stream release]; [_archiveComment release]; [_entries release]; [_pathToEntryMap release]; [super dealloc]; } - (void)of_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; OFStreamOffset offset = -22; bool valid = false; do { seekOrThrowInvalidFormat((OFSeekableStream *)_stream, offset, OFSeekEnd); if ([_stream readLittleEndianInt32] == 0x06054B50) { valid = true; break; } } while (--offset >= -65557); |
︙ | ︙ | |||
295 296 297 298 299 300 301 | _centralDirectoryEntries == 0xFFFF || _centralDirectorySize == 0xFFFFFFFF || _centralDirectoryOffset == 0xFFFFFFFF) { int64_t offset64; uint64_t size; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, | | | | | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | _centralDirectoryEntries == 0xFFFF || _centralDirectorySize == 0xFFFFFFFF || _centralDirectoryOffset == 0xFFFFFFFF) { int64_t offset64; uint64_t size; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, offset - 20, OFSeekEnd); if ([_stream readLittleEndianInt32] != 0x07064B50) { objc_autoreleasePoolPop(pool); return; } /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ [_stream readLittleEndianInt32]; offset64 = [_stream readLittleEndianInt64]; if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFStreamOffset)offset64, OFSeekSet); if ([_stream readLittleEndianInt32] != 0x06064B50) @throw [OFInvalidFormatException exception]; size = [_stream readLittleEndianInt64]; if (size < 44) @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
336 337 338 339 340 341 342 | _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt64]; _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || | | | | | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt64]; _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; } objc_autoreleasePoolPop(pool); } - (void)of_readEntries { void *pool = objc_autoreleasePoolPush(); if (_centralDirectoryOffset < 0 || (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFStreamOffset)_centralDirectoryOffset, OFSeekSet); for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc] of_initWithStream: _stream] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
394 395 396 397 398 399 400 | old = _archiveComment; _archiveComment = [comment copy]; [old release]; objc_autoreleasePoolPop(pool); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > | | | > > | > | | < < | | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | old = _archiveComment; _archiveComment = [comment copy]; [old release]; objc_autoreleasePoolPop(pool); } - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry; OFZIPArchiveLocalFileHeader *localFileHeader; int64_t offset64; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if ((entry = [_pathToEntryMap objectForKey: path]) == nil) @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: ENOENT]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; offset64 = entry.of_localFileHeaderOffset; if (offset64 < 0 || (OFStreamOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFStreamOffset)offset64, OFSeekSet); localFileHeader = [[[OFZIPArchiveLocalFileHeader alloc] initWithStream: _stream] autorelease]; if (![localFileHeader matchesEntry: entry]) @throw [OFInvalidFormatException exception]; if ((localFileHeader->_minVersionNeeded & 0xFF) > 45) { OFString *version = [OFString stringWithFormat: @"%u.%u", (localFileHeader->_minVersionNeeded & 0xFF) / 10, (localFileHeader->_minVersionNeeded & 0xFF) % 10]; @throw [OFUnsupportedVersionException exceptionWithVersion: version]; } objc_autoreleasePoolPop(pool); _lastReturnedStream = [[[OFZIPArchiveFileReadStream alloc] of_initWithArchive: self stream: _stream entry: entry] autorelease]; return _lastReturnedStream; } - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry_ { /* TODO: Avoid data descriptor when _stream is an OFSeekableStream */ int64_t offsetAdd = 0; void *pool; |
︙ | ︙ | |||
503 504 505 506 507 508 509 | mode: @"w" errNo: EEXIST]; if (entry.compressionMethod != OFZIPArchiveEntryCompressionMethodNone) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; | > > > > > | | 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | mode: @"w" errNo: EEXIST]; if (entry.compressionMethod != OFZIPArchiveEntryCompressionMethodNone) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; fileName = entry.fileName; fileNameLength = fileName.UTF8StringLength; extraField = entry.extraField; extraFieldLength = extraField.count; if (UINT16_MAX - extraFieldLength < 20) |
︙ | ︙ | |||
556 557 558 559 560 561 562 | if (INT64_MAX - _offset < offsetAdd) @throw [OFOutOfRangeException exception]; _offset += offsetAdd; _lastReturnedStream = [[OFZIPArchiveFileWriteStream alloc] | > | | | | 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | if (INT64_MAX - _offset < offsetAdd) @throw [OFOutOfRangeException exception]; _offset += offsetAdd; _lastReturnedStream = [[OFZIPArchiveFileWriteStream alloc] of_initWithArchive: self stream: _stream entry: entry]; objc_autoreleasePoolPop(pool); return [_lastReturnedStream autorelease]; } - (void)of_writeCentralDirectory { void *pool = objc_autoreleasePoolPush(); _centralDirectoryEntries = 0; |
︙ | ︙ | |||
618 619 620 621 622 623 624 | } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; | > > > > > | | 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } _lastReturnedStream = nil; if (_mode == modeWrite || _mode == modeAppend) [self of_writeCentralDirectory]; [_stream release]; _stream = nil; } |
︙ | ︙ | |||
670 671 672 673 674 675 676 | ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = | | | 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 | ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFMakeRange(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); |
︙ | ︙ | |||
728 729 730 731 732 733 734 | return false; return true; } @end @implementation OFZIPArchiveFileReadStream | | > | > | 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 | return false; return true; } @end @implementation OFZIPArchiveFileReadStream - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFZIPArchiveEntry *)entry { self = [super init]; @try { _archive = [archive retain]; _stream = [stream retain]; switch (entry.compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: _decompressedStream = [stream retain]; break; case OFZIPArchiveEntryCompressionMethodDeflate: |
︙ | ︙ | |||
772 773 774 775 776 777 778 779 780 781 782 783 784 785 | - (void)dealloc { if (_stream != nil || _decompressedStream != nil) [self close]; [_entry release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; | > > > > > | 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | - (void)dealloc { if (_stream != nil || _decompressedStream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; |
︙ | ︙ | |||
801 802 803 804 805 806 807 | @throw [OFTruncatedDataException exception]; #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif | | | 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 | @throw [OFTruncatedDataException exception]; #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC32 = OFCRC32(_CRC32, buffer, ret); |
︙ | ︙ | |||
855 856 857 858 859 860 861 | _decompressedStream = nil; [super close]; } @end @implementation OFZIPArchiveFileWriteStream | > | | > > > > > > | | | > > > | | > > > > > > > > | 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | _decompressedStream = nil; [super close]; } @end @implementation OFZIPArchiveFileWriteStream - (instancetype)of_initWithArchive: (OFZIPArchive *)archive stream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry { self = [super init]; _archive = [archive retain]; _stream = [stream retain]; _entry = [entry retain]; _CRC32 = ~0; return self; } - (void)dealloc { if (_stream != nil) [self close]; [_entry release]; if (_archive->_lastReturnedStream == self) _archive->_lastReturnedStream = nil; [_archive release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #if SIZE_MAX >= INT64_MAX if (length > INT64_MAX) @throw [OFOutOfRangeException exception]; #endif if (ULLONG_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); _bytesWritten += (unsigned long long)e.bytesWritten; _CRC32 = OFCRC32(_CRC32, buffer, e.bytesWritten); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } _bytesWritten += (unsigned long long)length; _CRC32 = OFCRC32(_CRC32, buffer, length); return length; } - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_bytesWritten > UINT64_MAX) @throw [OFOutOfRangeException exception]; [_stream writeLittleEndianInt32: 0x08074B50]; [_stream writeLittleEndianInt32: _CRC32]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream release]; _stream = nil; _entry.CRC32 = ~_CRC32; _entry.compressedSize = _bytesWritten; _entry.uncompressedSize = _bytesWritten; [_entry makeImmutable]; _bytesWritten += (2 * 4 + 2 * 8); [_archive->_entries addObject: _entry]; [_archive->_pathToEntryMap setObject: _entry forKey: _entry.fileName]; if (ULLONG_MAX - _archive->_offset < _bytesWritten) @throw [OFOutOfRangeException exception]; _archive->_offset += _bytesWritten; [super close]; } @end |
Modified src/OFZIPArchiveEntry+Private.h from [9241ef29c2] to [1ac3d985fc].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 | OF_ASSUME_NONNULL_BEGIN @interface OFZIPArchiveEntry () @property (readonly, nonatomic) uint16_t of_lastModifiedFileTime, of_lastModifiedFileDate; @property (readonly, nonatomic) int64_t of_localFileHeaderOffset; - (instancetype)of_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init) OF_DIRECT; - (uint64_t)of_writeToStream: (OFStream *)stream OF_DIRECT; @end @interface OFMutableZIPArchiveEntry () @property (readwrite, nonatomic, setter=of_setLocalFileHeaderOffset:) | > | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | OF_ASSUME_NONNULL_BEGIN @interface OFZIPArchiveEntry () @property (readonly, nonatomic) uint16_t of_lastModifiedFileTime, of_lastModifiedFileDate; @property (readonly, nonatomic) int64_t of_localFileHeaderOffset; - (instancetype)of_init OF_METHOD_FAMILY(init); - (instancetype)of_initWithStream: (OFStream *)stream OF_METHOD_FAMILY(init) OF_DIRECT; - (uint64_t)of_writeToStream: (OFStream *)stream OF_DIRECT; @end @interface OFMutableZIPArchiveEntry () @property (readwrite, nonatomic, setter=of_setLocalFileHeaderOffset:) |
︙ | ︙ |
Modified src/OFZIPArchiveEntry.h from [053b7bad8d] to [463b0f575c].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 | * 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 "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** @file */ typedef enum { OFZIPArchiveEntryCompressionMethodNone = 0, | > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * 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 "OFObject.h" #import "OFArchiveEntry.h" OF_ASSUME_NONNULL_BEGIN /** @file */ typedef enum { OFZIPArchiveEntryCompressionMethodNone = 0, |
︙ | ︙ | |||
96 97 98 99 100 101 102 | /** * @class OFZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents an entry in the central directory of a ZIP * archive. */ | | > | < < < < < < < < < < < | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /** * @class OFZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents an entry in the central directory of a ZIP * archive. */ @interface OFZIPArchiveEntry: OFObject <OFArchiveEntry, OFCopying, OFMutableCopying> { OFZIPArchiveEntryAttributeCompatibility _versionMadeBy; OFZIPArchiveEntryAttributeCompatibility _minVersionNeeded; uint16_t _generalPurposeBitFlag; OFZIPArchiveEntryCompressionMethod _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; unsigned long long _compressedSize, _uncompressedSize; OFString *_fileName; OFData *_Nullable _extraField; OFString *_Nullable _fileComment; uint32_t _startDiskNumber; uint16_t _internalAttributes; uint32_t _versionSpecificAttributes; int64_t _localFileHeaderOffset; OF_RESERVE_IVARS(OFZIPArchiveEntry, 4) } /** * @brief The extra field of the entry. * * The item size *must* be 1! */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFData *extraField; |
︙ | ︙ | |||
153 154 155 156 157 158 159 | * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readonly, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The CRC32 checksum of the entry's file. */ @property (readonly, nonatomic) uint32_t CRC32; /** * @brief The version specific attributes. * * The meaning of the version specific attributes depends on the attribute * compatibility part of the version that made the entry. */ @property (readonly, nonatomic) uint32_t versionSpecificAttributes; /** * @brief The general purpose bit flag of the entry. * * See the ZIP specification for details. */ @property (readonly, nonatomic) uint16_t generalPurposeBitFlag; - (instancetype)init OF_UNAVAILABLE; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Converts the ZIP entry version to a string. |
︙ | ︙ |
Modified src/OFZIPArchiveEntry.m from [6b838273dc] to [7156204ba2].
︙ | ︙ | |||
168 169 170 171 172 173 174 | } *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry | < < < < < | | < < < < < < < < < < < < < < < < | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | } *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { return [super init]; } - (instancetype)of_initWithStream: (OFStream *)stream { self = [super init]; @try { |
︙ | ︙ | |||
251 252 253 254 255 256 257 | ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = | | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFMakeRange(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); |
︙ | ︙ | |||
383 384 385 386 387 388 389 | } - (OFZIPArchiveEntryCompressionMethod)compressionMethod { return _compressionMethod; } | | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | } - (OFZIPArchiveEntryCompressionMethod)compressionMethod { return _compressionMethod; } - (unsigned long long)compressedSize { return _compressedSize; } - (unsigned long long)uncompressedSize { return _uncompressedSize; } - (uint32_t)CRC32 { return _CRC32; |
︙ | ︙ |
Modified src/ObjFW.h from [eef584b01b] to [4cea05be8a].
︙ | ︙ | |||
42 43 44 45 46 47 48 | #import "OFMethodSignature.h" #import "OFInvocation.h" #import "OFNumber.h" #import "OFDate.h" #import "OFUUID.h" | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #import "OFMethodSignature.h" #import "OFInvocation.h" #import "OFNumber.h" #import "OFDate.h" #import "OFUUID.h" #import "OFURI.h" #import "OFURIHandler.h" #import "OFColor.h" #import "OFNotification.h" #import "OFNotificationCenter.h" #import "OFStream.h" #import "OFSeekableStream.h" |
︙ | ︙ | |||
146 147 148 149 150 151 152 | #import "OFAllocFailedException.h" #import "OFException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" #endif | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | #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 |
︙ | ︙ | |||
172 173 174 175 176 177 178 | #endif #ifdef OF_WINDOWS # import "OFDeleteWindowsRegistryKeyFailedException.h" # import "OFDeleteWindowsRegistryValueFailedException.h" #endif #import "OFEnumerationMutationException.h" #ifdef OF_HAVE_FILES | | > | | | < | 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | #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" |
︙ | ︙ |
Modified src/exceptions/Makefile from [277ff12337] to [2af4cf20bf].
1 2 3 4 5 6 7 | include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} STATIC_AMIGA_LIB_NOINST = ${EXCEPTIONS_AMIGALIB_A} SRCS = OFAllocFailedException.m \ | < > | | < > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} STATIC_AMIGA_LIB_NOINST = ${EXCEPTIONS_AMIGALIB_A} SRCS = OFAllocFailedException.m \ OFChecksumMismatchException.m \ OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFGetItemAttributesFailedException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ OFHashNotCalculatedException.m \ OFInitializationFailedException.m \ OFInvalidArgumentException.m \ OFInvalidEncodingException.m \ OFInvalidFormatException.m \ OFInvalidJSONException.m \ OFInvalidServerResponseException.m \ OFLinkItemFailedException.m \ OFLockFailedException.m \ OFMalformedXMLException.m \ OFMoveItemFailedException.m \ OFNotImplementedException.m \ OFNotOpenException.m \ OFOpenItemFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ OFSeekFailedException.m \ OFSetItemAttributesFailedException.m \ OFSetOptionFailedException.m \ OFStillLockedException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ OFUnboundPrefixException.m \ OFUndefinedKeyException.m \ OFUnknownXMLEntityException.m \ OFUnlockFailedException.m \ OFUnsupportedProtocolException.m \ OFUnsupportedVersionException.m \ OFWriteFailedException.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFChangeCurrentDirectoryFailedException.m \ OFGetCurrentDirectoryFailedException.m SRCS_PLUGINS = OFLoadPluginFailedException.m SRCS_SOCKETS = OFAcceptFailedException.m \ OFAlreadyConnectedException.m \ OFBindFailedException.m \ OFConnectionFailedException.m \ OFDNSQueryFailedException.m \ OFHTTPRequestFailedException.m \ OFListenFailedException.m \ OFObserveKernelEventsFailedException.m \ OFResolveHostFailedException.m \ OFTLSHandshakeFailedException.m SRCS_THREADS = OFConditionBroadcastFailedException.m \ OFConditionSignalFailedException.m \ OFConditionStillWaitingException.m \ OFConditionWaitFailedException.m \ OFThreadJoinFailedException.m \ |
︙ | ︙ |
Modified src/exceptions/OFAcceptFailedException.h from [257583a910] to [af9482eaa0].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * * @brief An exception indicating that accepting a connection failed. */ @interface OFAcceptFailedException: OFException { id _socket; int _errNo; } /** * @brief The socket which could not accept a connection. */ @property (readonly, nonatomic) id socket; | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFAllocFailedException.h from [89360977c8] to [01cde7dcb3].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * it. * * This is the only exception which is not an OFException as it's special. It * does not know for which class allocation failed and it should not be handled * like other exceptions, as the exception handling code is not allowed to * allocate *any* memory. */ @interface OFAllocFailedException: OFObject + (instancetype)exception OF_UNAVAILABLE; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a description of the exception. * | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * it. * * This is the only exception which is not an OFException as it's special. It * does not know for which class allocation failed and it should not be handled * like other exceptions, as the exception handling code is not allowed to * allocate *any* memory. */ OF_SUBCLASSING_RESTRICTED @interface OFAllocFailedException: OFObject + (instancetype)exception OF_UNAVAILABLE; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns a description of the exception. * |
︙ | ︙ |
Modified src/exceptions/OFAlreadyConnectedException.h from [56f0934858] to [ac208c2ef2].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * * @brief An exception indicating an attempt to connect or bind an already * connected or bound socket. */ @interface OFAlreadyConnectedException: OFException { id _socket; } /** * @brief The socket which is already connected. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id socket; | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * * @brief An exception indicating an attempt to connect or bind an already * connected or bound socket. */ @interface OFAlreadyConnectedException: OFException { id _socket; OF_RESERVE_IVARS(OFAlreadyConnectedException, 4) } /** * @brief The socket which is already connected. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id socket; |
︙ | ︙ |
Modified src/exceptions/OFBindFailedException.h from [5fb5dee342] to [9447c1c83e].
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 45 46 47 48 49 | uint16_t _port; /* IPX */ uint8_t _packetType; /* UNIX socket */ OFString *_Nullable _path; id _socket; int _errNo; } /** * @brief The host on which binding failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; | > | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 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; |
︙ | ︙ |
Renamed and modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.h [fce19a8f8b] to src/exceptions/OFChangeCurrentDirectoryFailedException.h [c93252d4da].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** | | | | | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFChangeCurrentDirectoryFailedException \ * OFChangeCurrentDirectoryFailedException.h \ * ObjFW/OFChangeCurrentDirectoryFailedException.h * * @brief An exception indicating that changing the current directory path * failed. */ @interface OFChangeCurrentDirectoryFailedException: OFException { OFString *_path; int _errNo; OF_RESERVE_IVARS(OFChangeCurrentDirectoryFailedException, 4) } /** * @brief The path of the directory to which the current path could not be * changed. */ @property (readonly, nonatomic) OFString *path; |
︙ | ︙ |
Renamed and modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.m [35ec7fdb32] to src/exceptions/OFChangeCurrentDirectoryFailedException.m [7267a7e220].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * 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 "OFChangeCurrentDirectoryFailedException.h" #import "OFString.h" @implementation OFChangeCurrentDirectoryFailedException @synthesize path = _path, errNo = _errNo; + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo { return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; } |
︙ | ︙ | |||
57 58 59 60 61 62 63 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: | | | 57 58 59 60 61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to change the current directory to %@: %@", _path, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFChecksumMismatchException.h from [e6f142cd8f] to [5d6d269610].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * OFChecksumMismatchException.h ObjFW/OFChecksumMismatchException.h * * @brief An exception indicating that a checksum did not match. */ @interface OFChecksumMismatchException: OFException { OFString *_actualChecksum, *_expectedChecksum; } /** * @brief The actual checksum calculated. */ @property (readonly, nonatomic) OFString *actualChecksum; | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * OFChecksumMismatchException.h ObjFW/OFChecksumMismatchException.h * * @brief An exception indicating that a checksum did not match. */ @interface OFChecksumMismatchException: OFException { OFString *_actualChecksum, *_expectedChecksum; OF_RESERVE_IVARS(OFChecksumMismatchException, 4) } /** * @brief The actual checksum calculated. */ @property (readonly, nonatomic) OFString *actualChecksum; |
︙ | ︙ |
Modified src/exceptions/OFConditionBroadcastFailedException.h from [d2d182c69d] to [920b114a94].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @brief An exception indicating broadcasting a condition failed. */ @interface OFConditionBroadcastFailedException: OFException { OFCondition *_condition; int _errNo; } /** * @brief The condition which could not be broadcasted. */ @property (readonly, nonatomic) OFCondition *condition; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFConditionSignalFailedException.h from [92e2796a89] to [fd45072644].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @brief An exception indicating signaling a condition failed. */ @interface OFConditionSignalFailedException: OFException { OFCondition *_condition; int _errNo; } /** * @brief The condition which could not be signaled. */ @property (readonly, nonatomic) OFCondition *condition; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFConditionStillWaitingException.h from [63592271b5] to [6424437193].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @brief An exception indicating that a thread is still waiting for a * condition. */ @interface OFConditionStillWaitingException: OFException { OFCondition *_condition; } /** * @brief The condition for which is still being waited. */ @property (readonly, nonatomic) OFCondition *condition; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * @brief An exception indicating that a thread is still waiting for a * condition. */ @interface OFConditionStillWaitingException: OFException { OFCondition *_condition; OF_RESERVE_IVARS(OFConditionStillWaitingException, 4) } /** * @brief The condition for which is still being waited. */ @property (readonly, nonatomic) OFCondition *condition; |
︙ | ︙ |
Modified src/exceptions/OFConditionWaitFailedException.h from [4c780f1cdc] to [219a53d1c9].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @brief An exception indicating waiting for a condition failed. */ @interface OFConditionWaitFailedException: OFException { OFCondition *_condition; int _errNo; } /** * @brief The condition for which could not be waited. */ @property (readonly, nonatomic) OFCondition *condition; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFConnectionFailedException.h from [6f75d86327] to [3f23880b21].
︙ | ︙ | |||
34 35 36 37 38 39 40 41 42 43 44 45 46 47 | OFString *_Nullable _host; uint16_t _port; OFString *_Nullable _path; uint32_t _network; unsigned char _node[IPX_NODE_LEN]; id _socket; int _errNo; } /** * @brief The host to which the connection failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host; | > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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; |
︙ | ︙ |
Modified src/exceptions/OFCopyItemFailedException.h from [6dbfc6ae6a] to [123bfde77a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFCopyItemFailedException \ * OFCopyItemFailedException.h ObjFW/OFCopyItemFailedException.h * * @brief An exception indicating that copying a item failed. */ @interface OFCopyItemFailedException: OFException { OFURI *_sourceURI, *_destinationURI; int _errNo; OF_RESERVE_IVARS(OFCopyItemFailedException, 4) } /** * @brief The URI of the source item. */ @property (readonly, nonatomic) OFURI *sourceURI; /** * @brief The destination URI. */ @property (readonly, nonatomic) OFURI *destinationURI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased copy item failed exception. * * @param sourceURI The URI of the source item * @param destinationURI The destination URI * @param errNo The errno of the error that occurred * @return A new, autoreleased copy item failed exception */ + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated copy item failed exception. * * @param sourceURI The URI of the source item * @param destinationURI The destination URI * @param errNo The errno of the error that occurred * @return An initialized copy item failed exception */ - (instancetype)initWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFCopyItemFailedException.m from [db6f54b209] to [86e24afee9].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFCopyItemFailedException.h" #import "OFString.h" | | | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | * file. */ #include "config.h" #import "OFCopyItemFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFCopyItemFailedException @synthesize sourceURI = _sourceURI, destinationURI = _destinationURI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { return [[[self alloc] initWithSourceURI: sourceURI destinationURI: destinationURI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { self = [super init]; @try { _sourceURI = [sourceURI copy]; _destinationURI = [destinationURI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceURI release]; [_destinationURI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@", _sourceURI, _destinationURI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateDirectoryFailedException.h from [9fb2f6c383] to [e16c672401].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFCreateDirectoryFailedException \ * OFCreateDirectoryFailedException.h \ * ObjFW/OFCreateDirectoryFailedException.h * * @brief An exception indicating a directory couldn't be created. */ @interface OFCreateDirectoryFailedException: OFException { OFURI *_URI; int _errNo; OF_RESERVE_IVARS(OFCreateDirectoryFailedException, 4) } /** * @brief The URI of the directory which couldn't be created. */ @property (readonly, nonatomic) OFURI *URI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased create directory failed exception. * * @param URI The URI of the directory which could not be created * @param errNo The errno of the error that occurred * @return A new, autoreleased create directory failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated create directory failed exception. * * @param URI The URI of the directory which could not be created * @param errNo The errno of the error that occurred * @return An initialized create directory failed exception */ - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFCreateDirectoryFailedException.m from [c77cc11072] to [cd0b53b912].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFCreateDirectoryFailedException.h" #import "OFString.h" | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | * file. */ #include "config.h" #import "OFCreateDirectoryFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFCreateDirectoryFailedException @synthesize URI = _URI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo { return [[[self alloc] initWithURI: URI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_URI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create directory %@: %@", _URI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateSymbolicLinkFailedException.h from [3600a35794] to [79c2f6b7ee].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFCreateSymbolicLinkFailedException \ * OFCreateSymbolicLinkFailedException.h \ * ObjFW/OFCreateSymbolicLinkFailedException.h * * @brief An exception indicating that creating a symbolic link failed. */ @interface OFCreateSymbolicLinkFailedException: OFException { OFURI *_URI; OFString *_target; int _errNo; OF_RESERVE_IVARS(OFCreateSymbolicLinkFailedException, 4) } /** * @brief The URI at which the symlink should have been created. */ @property (readonly, nonatomic) OFURI *URI; /** * @brief The target for the symlink. */ @property (readonly, nonatomic) OFString *target; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased create symbolic link failed exception. * * @param URI The URI where the symlink should have been created * @param target The target for the symbolic link * @param errNo The errno of the error that occurred * @return A new, autoreleased create symbolic link failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI target: (OFString *)target errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated create symbolic link failed * exception. * * @param URI The URI where the symlink should have been created * @param target The target for the symbolic link * @param errNo The errno of the error that occurred * @return An initialized create symbolic link failed exception */ - (instancetype)initWithURI: (OFURI *)URI target: (OFString *)target errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFCreateSymbolicLinkFailedException.m from [98cc87f63e] to [c5e085b246].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFString.h" | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | * file. */ #include "config.h" #import "OFCreateSymbolicLinkFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFCreateSymbolicLinkFailedException @synthesize URI = _URI, target = _target, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURI: (OFURI *)URI target: (OFString *)target errNo: (int)errNo { return [[[self alloc] initWithURI: URI target: target errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI target: (OFString *)target errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _target = [target copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_URI release]; [_target release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create symbolic link %@ with target %@: %@", _URI, _target, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.h from [f321fddf5e] to [3739e39dc2].
︙ | ︙ | |||
28 29 30 31 32 33 34 | * @brief An exception indicating that creating a Windows registry key failed. */ @interface OFCreateWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; DWORD _options; | | > < < < < < | < | > > > > > | < | > < | > | < | > < | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | * @brief An exception indicating that creating a Windows registry key failed. */ @interface OFCreateWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; DWORD _options; REGSAM _accessRights; LPSECURITY_ATTRIBUTES _Nullable _securityAttributes; LSTATUS _status; OF_RESERVE_IVARS(OFCreateWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which creating the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The path for the subkey that could not be created. */ @property (readonly, nonatomic) OFString *path; /** * @brief The access rights for the subkey that could not be created. */ @property (readonly, nonatomic) REGSAM accessRights; /** * @brief The security options for the subkey that could not be created. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) LPSECURITY_ATTRIBUTES securityAttributes; /** * @brief The options for the subkey that could not be created. */ @property (readonly, nonatomic) DWORD options; /** * @brief The status returned by RegCreateKeyEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased create Windows registry key failed * exception. * * @param registryKey The registry key on which creating the subkey failed * @param path The path for the subkey that could not be created * @param accessRights The access rights for the sub key that could not be * created * @param securityAttributes The security options for the subkey that could * not be created * @param options The options for the subkey that could not be created * @param status The status returned by RegCreateKeyEx() * @return A new, autoreleased creates Windows registry key failed exception */ + (instancetype) exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated create Windows registry key failed * exception. * * @param registryKey The registry key on which creating the subkey failed * @param path The path for the subkey that could not be created * @param accessRights The access rights for the sub key that could not be * created * @param securityAttributes The security options for the subkey that could * not be created * @param options The options for the subkey that could not be created * @param status The status returned by RegCreateKeyEx() * @return An initialized create Windows registry key failed exception */ - (instancetype) initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (nullable LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.m from [661d98b08e] to [3f8a5e58b7].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFCreateWindowsRegistryKeyFailedException.h" @implementation OFCreateWindowsRegistryKeyFailedException | | | | > < | > < | > < | | < | | > | < | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | */ #include "config.h" #import "OFCreateWindowsRegistryKeyFailedException.h" @implementation OFCreateWindowsRegistryKeyFailedException @synthesize registryKey = _registryKey, path = _path; @synthesize accessRights = _accessRights; @synthesize securityAttributes = _securityAttributes, options = _options; @synthesize status = _status; + (instancetype) exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey path: path accessRights: accessRights securityAttributes: securityAttributes options: options status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes options: (DWORD)options status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _path = [path copy]; _accessRights = accessRights; _securityAttributes = securityAttributes; _options = options; _status = status; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ |
Modified src/exceptions/OFDNSQueryFailedException.h from [852291054a] to [e0cf12b730].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * * @brief An exception indicating that a DNS query failed. */ @interface OFDNSQueryFailedException: OFException { OFDNSQuery *_query; OFDNSResolverErrorCode _errorCode; } /** * @brief The query which could not be performed. */ @property (readonly, nonatomic) OFDNSQuery *query; | > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * * @brief An exception indicating that a DNS query failed. */ @interface OFDNSQueryFailedException: OFException { OFDNSQuery *_query; OFDNSResolverErrorCode _errorCode; OF_RESERVE_IVARS(OFDNSQueryFailedException, 4) } /** * @brief The query which could not be performed. */ @property (readonly, nonatomic) OFDNSQuery *query; |
︙ | ︙ |
Modified src/exceptions/OFDeleteWindowsRegistryKeyFailedException.h from [ce80a5fb98] to [7a006ec7b5].
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * @brief An exception indicating that deleting a Windows registry key failed. */ @interface OFDeleteWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_subkeyPath; LSTATUS _status; } /** * @brief The registry key on which deleting the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * @brief An exception indicating that deleting a Windows registry key failed. */ @interface OFDeleteWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_subkeyPath; LSTATUS _status; OF_RESERVE_IVARS(OFDeleteWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which deleting the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; |
︙ | ︙ |
Modified src/exceptions/OFDeleteWindowsRegistryValueFailedException.h from [fb187a24ce] to [0a7f480a16].
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * @brief An exception indicating that deleting a Windows registry value failed. */ @interface OFDeleteWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; } /** * @brief The registry key on which deleting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * @brief An exception indicating that deleting a Windows registry value failed. */ @interface OFDeleteWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; OF_RESERVE_IVARS(OFDeleteWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which deleting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; |
︙ | ︙ |
Modified src/exceptions/OFEnumerationMutationException.h from [2ab98f2cf4] to [1a130e7399].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that a mutation was detected during * enumeration. */ @interface OFEnumerationMutationException: OFException { id _object; } /** * @brief The object which was mutated during enumeration. */ @property (readonly, nonatomic) id object; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @brief An exception indicating that a mutation was detected during * enumeration. */ @interface OFEnumerationMutationException: OFException { id _object; OF_RESERVE_IVARS(OFEnumerationMutationException, 4) } /** * @brief The object which was mutated during enumeration. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFException.h from [e8334cf8f9] to [e7c0836484].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #ifdef OF_WINDOWS # include <windows.h> #endif OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #ifdef OF_WINDOWS # include <windows.h> #endif OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFString; @class OFValue; #define OFStackTraceSize 16 #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # ifndef EADDRINUSE # define EADDRINUSE WSAEADDRINUSE # endif # ifndef EADDRNOTAVAIL # define EADDRNOTAVAIL WSAEADDRNOTAVAIL |
︙ | ︙ | |||
145 146 147 148 149 150 151 | * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { | | > | | > > > > > > | > > > | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { void *_stackTrace[OFStackTraceSize]; OF_RESERVE_IVARS(OFException, 4) } /** * @brief Creates a new, autoreleased exception. * * @return A new, autoreleased exception */ + (instancetype)exception; /** * @brief Returns a description of the exception. * * @return A description of the exception */ - (OFString *)description; /** * @brief Returns a stack trace of when the exception was created or `nil` if * no stack trace is available. The returned array contains OFValues * with @ref OFValue#pointerValue set to the address. * * @return The stack trace as array of addresses */ - (nullable OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses; /** * @brief Returns a stack trace of when the exception was created or `nil` if * no stack trace symbols are available. * * @return The stack trace as array of symbols */ - (nullable OFArray OF_GENERIC(OFString *) *)stackTraceSymbols; @end #ifdef __cplusplus extern "C" { #endif extern OFString *OFStrError(int errNo); #ifdef OF_WINDOWS |
︙ | ︙ |
Modified src/exceptions/OFException.m from [21f1fa3002] to [700714ee53].
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #import "OFArray.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # include <winerror.h> | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFArray.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFValue.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # include <winerror.h> |
︙ | ︙ | |||
254 255 256 257 258 259 260 | #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code backtraceCallback(struct _Unwind_Context *ctx, void *data) { struct BacktraceCtx *bt = data; | | | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code backtraceCallback(struct _Unwind_Context *ctx, void *data) { struct BacktraceCtx *bt = data; if (bt->i < OFStackTraceSize) { # ifndef HAVE_ARM_EHABI_EXCEPTIONS bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx); # else uintptr_t ip; _Unwind_VRS_Get(ctx, 0, 15, 0, &ip); bt->backtrace[bt->i++] = (void *)(ip & ~1); |
︙ | ︙ | |||
283 284 285 286 287 288 289 | #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { struct BacktraceCtx ctx; self = [super init]; | | | | > | > > | > > > > > > > > > > > > > > > > > > > | > > | | > | | < | | > > | < | | < | | | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { struct BacktraceCtx ctx; self = [super init]; ctx.backtrace = _stackTrace; ctx.i = 0; _Unwind_Backtrace(backtraceCallback, &ctx); return self; } #endif - (OFString *)description { return [OFString stringWithFormat: @"An exception of type %@ occurred!", self.class]; } - (OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses { #ifdef HAVE__UNWIND_BACKTRACE OFMutableArray OF_GENERIC(OFValue *) *stackTrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint_fast8_t i = 0; i < OFStackTraceSize && _stackTrace[i] != NULL; i++) [stackTrace addObject: [OFValue valueWithPointer: _stackTrace[i]]]; objc_autoreleasePoolPop(pool); [stackTrace makeImmutable]; return stackTrace; #else return nil; #endif } - (OFArray OF_GENERIC(OFString *) *)stackTraceSymbols { #if defined(HAVE__UNWIND_BACKTRACE) && defined(HAVE_DLADDR) OFMutableArray OF_GENERIC(OFString *) *stackTrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint_fast8_t i = 0; i < OFStackTraceSize && _stackTrace[i] != NULL; i++) { Dl_info info; if (dladdr(_stackTrace[i], &info)) { ptrdiff_t offset = (char *)_stackTrace[i] - (char *)info.dli_saddr; OFString *frame; if (info.dli_fname != NULL && info.dli_sname != NULL) frame = [OFString stringWithFormat: @"%s`%s+%td", info.dli_fname, info.dli_sname, offset]; else if (info.dli_sname != NULL) frame = [OFString stringWithFormat: @"%s+%td", info.dli_sname, offset]; else if (info.dli_fname != NULL) frame = [OFString stringWithFormat: @"%s`%p", info.dli_fname, _stackTrace[i]]; else frame = [OFString stringWithFormat: @"%p", _stackTrace[i]]; [stackTrace addObject: frame]; } else [stackTrace addObject: [OFString stringWithFormat: @"%p", _stackTrace[i]]]; } objc_autoreleasePoolPop(pool); [stackTrace makeImmutable]; return stackTrace; #else return nil; #endif } @end |
Renamed and modified src/exceptions/OFGetCurrentDirectoryPathFailedException.h [8e5eb876c7] to src/exceptions/OFGetCurrentDirectoryFailedException.h [60ae2d8910].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** | | | | | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFGetCurrentDirectoryFailedException \ * OFGetCurrentDirectoryFailedException.h \ * ObjFW/OFGetCurrentDirectoryFailedException.h * * @brief An exception indicating that getting the current directory path * failed. */ @interface OFGetCurrentDirectoryFailedException: OFException { int _errNo; OF_RESERVE_IVARS(OFGetCurrentDirectoryFailedException, 4) } /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; |
︙ | ︙ |
Renamed and modified src/exceptions/OFGetCurrentDirectoryPathFailedException.m [60672e8d84] to src/exceptions/OFGetCurrentDirectoryFailedException.m [b29d0ac295].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * 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 "OFGetCurrentDirectoryFailedException.h" #import "OFString.h" @implementation OFGetCurrentDirectoryFailedException @synthesize errNo = _errNo; + (instancetype)exceptionWithErrNo: (int)errNo { return [[[self alloc] initWithErrNo: errNo] autorelease]; } |
︙ | ︙ |
Renamed and modified src/exceptions/OFRetrieveItemAttributesFailedException.h [2269d1ffef] to src/exceptions/OFGetItemAttributesFailedException.h [354af07fb2].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | | | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFGetItemAttributesFailedException \ * OFGetItemAttributesFailedException.h \ * ObjFW/OFGetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be retrieved. */ @interface OFGetItemAttributesFailedException: OFException { OFURI *_URI; int _errNo; OF_RESERVE_IVARS(OFGetItemAttributesFailedException, 4) } /** * @brief The URI of the item whose attributes could not be retrieved. */ @property (readonly, nonatomic) OFURI *URI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased retrieve item attributes failed exception. * * @param URI The URI of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased retrieve item attributes failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated retrieve item attributes failed * exception. * * @param URI The URI of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return An initialized retrieve item attributes failed exception */ - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/exceptions/OFRetrieveItemAttributesFailedException.m [8b9c2b49f4] to src/exceptions/OFGetItemAttributesFailedException.m [db212ce8f9].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | | | | | | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | * 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 "OFGetItemAttributesFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFGetItemAttributesFailedException @synthesize URI = _URI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo { return [[[self alloc] initWithURI: URI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_URI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to get attributes for item %@: %@", _URI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFGetOptionFailedException.h from [07bdd97238] to [a8c8d533b3].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * * @brief An exception indicating that getting an option for an object failed. */ @interface OFGetOptionFailedException: OFException { id _object; int _errNo; } /** * @brief The object for which the option could not be retrieved. */ @property (readonly, nonatomic) id object; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that getting an option for an object failed. */ @interface OFGetOptionFailedException: OFException { id _object; int _errNo; OF_RESERVE_IVARS(OFGetOptionFailedException, 4) } /** * @brief The object for which the option could not be retrieved. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFGetWindowsRegistryValueFailedException.h from [733c657ffd] to [1bae299028].
︙ | ︙ | |||
27 28 29 30 31 32 33 | * * @brief An exception indicating that getting a Windows registry value failed. */ @interface OFGetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; | < > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * * @brief An exception indicating that getting a Windows registry value failed. */ @interface OFGetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; OF_RESERVE_IVARS(OFGetWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which getting the value at the key path failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; |
︙ | ︙ |
Modified src/exceptions/OFHTTPRequestFailedException.h from [59803d0bef] to [d5947528d2].
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * * @brief An exception indicating that an HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { OFHTTPRequest *_request; OFHTTPResponse *_response; } /** * @brief The HTTP request which failed. */ @property (readonly, nonatomic) OFHTTPRequest *request; | > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | * * @brief An exception indicating that an HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { OFHTTPRequest *_request; OFHTTPResponse *_response; OF_RESERVE_IVARS(OFHTTPRequestFailedException, 4) } /** * @brief The HTTP request which failed. */ @property (readonly, nonatomic) OFHTTPRequest *request; |
︙ | ︙ |
Modified src/exceptions/OFHTTPRequestFailedException.m from [02e986bf36] to [f93ff97e23].
︙ | ︙ | |||
60 61 62 63 64 65 66 | } - (OFString *)description { const char *method = OFHTTPRequestMethodName(_request.method); return [OFString stringWithFormat: | | | | 60 61 62 63 64 65 66 67 68 69 70 | } - (OFString *)description { const char *method = OFHTTPRequestMethodName(_request.method); return [OFString stringWithFormat: @"An HTTP %s request with URI %@ failed with code %hd!", method, _request.URI, _response.statusCode]; } @end |
Modified src/exceptions/OFHashAlreadyCalculatedException.h from [9fce34d334] to [0455e7b89e].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * ObjFW/OFHashAlreadyCalculatedException.h * * @brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException { id _object; } /** * @brief The hash which has already been calculated. */ @property (readonly, nonatomic) id object; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * ObjFW/OFHashAlreadyCalculatedException.h * * @brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException { id _object; OF_RESERVE_IVARS(OFHashAlreadyCalculatedException, 4) } /** * @brief The hash which has already been calculated. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFHashNotCalculatedException.h from [768ce1b6b5] to [e76b9886eb].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * ObjFW/OFHashNotCalculatedException.h * * @brief An exception indicating that the hash has not been calculated yet. */ @interface OFHashNotCalculatedException: OFException { id _object; } /** * @brief The hash which has not been calculated yet. */ @property (readonly, nonatomic) id object; | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * ObjFW/OFHashNotCalculatedException.h * * @brief An exception indicating that the hash has not been calculated yet. */ @interface OFHashNotCalculatedException: OFException { id _object; OF_RESERVE_IVARS(OFHashNotCalculatedException, 4) } /** * @brief The hash which has not been calculated yet. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFInitializationFailedException.h from [20206324fd] to [280997dfe1].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * ObjFW/OFInitializationFailedException.h * * @brief An exception indicating that initializing something failed. */ @interface OFInitializationFailedException: OFException { Class _inClass; } /** * @brief The class for which initialization failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class inClass; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * ObjFW/OFInitializationFailedException.h * * @brief An exception indicating that initializing something failed. */ @interface OFInitializationFailedException: OFException { Class _inClass; OF_RESERVE_IVARS(OFInitializationFailedException, 4) } /** * @brief The class for which initialization failed. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class inClass; |
︙ | ︙ |
Modified src/exceptions/OFInvalidArgumentException.h from [d5e2417590] to [835c000126].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 | /** * @class OFInvalidArgumentException \ * OFInvalidArgumentException.h ObjFW/OFInvalidArgumentException.h * * @brief An exception indicating that the argument is invalid for this method. */ @interface OFInvalidArgumentException: OFException @end OF_ASSUME_NONNULL_END | > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * @class OFInvalidArgumentException \ * OFInvalidArgumentException.h ObjFW/OFInvalidArgumentException.h * * @brief An exception indicating that the argument is invalid for this method. */ @interface OFInvalidArgumentException: OFException { OF_RESERVE_IVARS(OFInvalidArgumentException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFInvalidEncodingException.h from [393547809a] to [36e737e07d].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 | /** * @class OFInvalidEncodingException \ * OFInvalidEncodingException.h ObjFW/OFInvalidEncodingException.h * * @brief An exception indicating that the encoding is invalid for this object. */ @interface OFInvalidEncodingException: OFException @end OF_ASSUME_NONNULL_END | > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * @class OFInvalidEncodingException \ * OFInvalidEncodingException.h ObjFW/OFInvalidEncodingException.h * * @brief An exception indicating that the encoding is invalid for this object. */ @interface OFInvalidEncodingException: OFException { OF_RESERVE_IVARS(OFInvalidEncodingException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFInvalidFormatException.h from [e6f46ae68c] to [7bd0078c9f].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 | /** * @class OFInvalidFormatException \ * OFInvalidFormatException.h ObjFW/OFInvalidFormatException.h * * @brief An exception indicating that the format is invalid. */ @interface OFInvalidFormatException: OFException @end OF_ASSUME_NONNULL_END | > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * @class OFInvalidFormatException \ * OFInvalidFormatException.h ObjFW/OFInvalidFormatException.h * * @brief An exception indicating that the format is invalid. */ @interface OFInvalidFormatException: OFException { OF_RESERVE_IVARS(OFInvalidFormatException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFInvalidJSONException.h from [9ac94f6e36] to [a9bef800fe].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * * @brief An exception indicating a JSON representation is invalid. */ @interface OFInvalidJSONException: OFException { OFString *_string; size_t _line; } /** * @brief The string containing the invalid JSON representation. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *string; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating a JSON representation is invalid. */ @interface OFInvalidJSONException: OFException { OFString *_string; size_t _line; OF_RESERVE_IVARS(OFInvalidJSONException, 4) } /** * @brief The string containing the invalid JSON representation. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *string; |
︙ | ︙ |
Renamed and modified src/exceptions/OFInvalidServerReplyException.h [90e12ae8cf] to src/exceptions/OFInvalidServerResponseException.h [8680d9915b].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** | | | > | | > > > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFInvalidServerResponseException \ * OFInvalidServerResponseException.h \ * ObjFW/OFInvalidServerResponseException.h * * @brief An exception indicating that the server sent an invalid response. */ @interface OFInvalidServerResponseException: OFException { OF_RESERVE_IVARS(OFInvalidServerResponseException, 4) } @end OF_ASSUME_NONNULL_END |
Renamed and modified src/exceptions/OFInvalidServerReplyException.m [aae10c2dab] to src/exceptions/OFInvalidServerResponseException.m [8436f85f3d].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * 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 "OFInvalidServerResponseException.h" #import "OFString.h" @implementation OFInvalidServerResponseException - (OFString *)description { return @"Got an invalid response from the server!"; } @end |
Renamed and modified src/exceptions/OFLinkFailedException.h [099d3c2419] to src/exceptions/OFLinkItemFailedException.h [bc4e6321e5].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | | | | > | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFLinkItemFailedException \ * OFLinkItemFailedException.h ObjFW/OFLinkItemFailedException.h * * @brief An exception indicating that creating a link failed. */ @interface OFLinkItemFailedException: OFException { OFURI *_sourceURI, *_destinationURI; int _errNo; OF_RESERVE_IVARS(OFLinkItemFailedException, 4) } /** * @brief A URI with the source for the link. */ @property (readonly, nonatomic) OFURI *sourceURI; /** * @brief A URI with the destination for the link. */ @property (readonly, nonatomic) OFURI *destinationURI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased link failed exception. * * @param sourceURI The source for the link * @param destinationURI The destination for the link * @param errNo The errno of the error that occurred * @return A new, autoreleased link failed exception */ + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated link failed exception. * * @param sourceURI The source for the link * @param destinationURI The destination for the link * @param errNo The errno of the error that occurred * @return An initialized link failed exception */ - (instancetype)initWithSourceURI: (OFURI*)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/exceptions/OFLinkFailedException.m [7710ab3fd2] to src/exceptions/OFLinkItemFailedException.m [3033895110].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | | | | | | | | | | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | * 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 "OFLinkItemFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFLinkItemFailedException @synthesize sourceURI = _sourceURI, destinationURI = _destinationURI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { return [[[self alloc] initWithSourceURI: sourceURI destinationURI: destinationURI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { self = [super init]; @try { _sourceURI = [sourceURI copy]; _destinationURI = [destinationURI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceURI release]; [_destinationURI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@", _sourceURI, _destinationURI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFListenFailedException.h from [32d4375802] to [a41aaff3ca].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | * * @brief An exception indicating that listening on the socket failed. */ @interface OFListenFailedException: OFException { id _socket; int _backlog, _errNo; } /** * @brief The socket which failed to listen. */ @property (readonly, nonatomic) id socket; | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFLoadPluginFailedException.h from [7c45470186] to [bb70233a5c].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * OFLoadPluginFailedException.h ObjFW/OFLoadPluginFailedException.h * * @brief An exception indicating a plugin could not be loaded. */ @interface OFLoadPluginFailedException: OFException { OFString *_path, *_Nullable _error; } /** * @brief The path of the plugin which could not be loaded */ @property (readonly, nonatomic) OFString *path; | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * OFLoadPluginFailedException.h ObjFW/OFLoadPluginFailedException.h * * @brief An exception indicating a plugin could not be loaded. */ @interface OFLoadPluginFailedException: OFException { OFString *_path, *_Nullable _error; OF_RESERVE_IVARS(OFLoadPluginFailedException, 4) } /** * @brief The path of the plugin which could not be loaded */ @property (readonly, nonatomic) OFString *path; |
︙ | ︙ |
Modified src/exceptions/OFLockFailedException.h from [e861f27ee4] to [58545dfa42].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that locking a lock failed. */ @interface OFLockFailedException: OFException { id <OFLocking> _Nullable _lock; int _errNo; } /** * @brief The lock which could not be locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @brief An exception indicating that locking a lock failed. */ @interface OFLockFailedException: OFException { id <OFLocking> _Nullable _lock; int _errNo; OF_RESERVE_IVARS(OFLockFailedException, 4) } /** * @brief The lock which could not be locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; |
︙ | ︙ |
Modified src/exceptions/OFMalformedXMLException.h from [3b999908e6] to [d319798b44].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * OFMalformedXMLException.h ObjFW/OFMalformedXMLException.h * * @brief An exception indicating that a parser encountered malformed XML. */ @interface OFMalformedXMLException: OFException { OFXMLParser *_parser; } /** * @brief The parser which encountered malformed XML. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFXMLParser *parser; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * OFMalformedXMLException.h ObjFW/OFMalformedXMLException.h * * @brief An exception indicating that a parser encountered malformed XML. */ @interface OFMalformedXMLException: OFException { OFXMLParser *_parser; OF_RESERVE_IVARS(OFMalformedXMLException, 4) } /** * @brief The parser which encountered malformed XML. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFXMLParser *parser; |
︙ | ︙ |
Modified src/exceptions/OFMoveItemFailedException.h from [c4c3e18fa9] to [f2cc0cdf02].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFMoveItemFailedException \ * OFMoveItemFailedException.h ObjFW/OFMoveItemFailedException.h * * @brief An exception indicating that moving an item failed. */ @interface OFMoveItemFailedException: OFException { OFURI *_sourceURI, *_destinationURI; int _errNo; OF_RESERVE_IVARS(OFMoveItemFailedException, 4) } /** * @brief The original URI. */ @property (readonly, nonatomic) OFURI *sourceURI; /** * @brief The new URI. */ @property (readonly, nonatomic) OFURI *destinationURI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased move item failed exception. * * @param sourceURI The original URI * @param destinationURI The new URI * @param errNo The errno of the error that occurred * @return A new, autoreleased move item failed exception */ + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated move item failed exception. * * @param sourceURI The original URI * @param destinationURI The new URI * @param errNo The errno of the error that occurred * @return An initialized move item failed exception */ - (instancetype)initWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFMoveItemFailedException.m from [4ea07cc8dd] to [7df7241c06].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFMoveItemFailedException.h" #import "OFString.h" | | | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | * file. */ #include "config.h" #import "OFMoveItemFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFMoveItemFailedException @synthesize sourceURI = _sourceURI, destinationURI = _destinationURI; @synthesize errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { return [[[self alloc] initWithSourceURI: sourceURI destinationURI: destinationURI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSourceURI: (OFURI *)sourceURI destinationURI: (OFURI *)destinationURI errNo: (int)errNo { self = [super init]; @try { _sourceURI = [sourceURI copy]; _destinationURI = [destinationURI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_sourceURI release]; [_destinationURI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to move item at %@ to %@: %@", _sourceURI, _destinationURI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFNotImplementedException.h from [891dc14bbc] to [f0426204c4].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * @brief An exception indicating that a method or part of it is not * implemented. */ @interface OFNotImplementedException: OFException { SEL _selector; id _Nullable _object; } /** * @brief The selector which is not or not fully implemented. */ @property (readonly, nonatomic) SEL selector; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * @brief An exception indicating that a method or part of it is not * implemented. */ @interface OFNotImplementedException: OFException { SEL _selector; id _Nullable _object; OF_RESERVE_IVARS(OFNotImplementedException, 4) } /** * @brief The selector which is not or not fully implemented. */ @property (readonly, nonatomic) SEL selector; |
︙ | ︙ |
Modified src/exceptions/OFNotOpenException.h from [45f02f6f12] to [5a826ad61e].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | * @class OFNotOpenException OFNotOpenException.h ObjFW/OFNotOpenException.h * * @brief An exception indicating an object is not open, connected or bound. */ @interface OFNotOpenException: OFException { id _object; } /** * @brief The object which is not open, connected or bound. */ @property (readonly, nonatomic) id object; | > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * @class OFNotOpenException OFNotOpenException.h ObjFW/OFNotOpenException.h * * @brief An exception indicating an object is not open, connected or bound. */ @interface OFNotOpenException: OFException { id _object; OF_RESERVE_IVARS(OFNotOpenException, 4) } /** * @brief The object which is not open, connected or bound. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Renamed and modified src/exceptions/OFObserveFailedException.h [6c7bf7885c] to src/exceptions/OFObserveKernelEventsFailedException.h [a11562c534].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFKernelEventObserver; /** | | | > | > | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFKernelEventObserver; /** * @class OFObserveKernelEventsFailedException \ * OFObserveKernelEventsFailedException.h \ * ObjFW/OFObserveKernelEventsFailedException.h * * @brief An exception indicating that observing failed. */ @interface OFObserveKernelEventsFailedException: OFException { OFKernelEventObserver *_observer; int _errNo; OF_RESERVE_IVARS(OFObserveKernelEventsFailedException, 4) } /** * @brief The observer which failed to observe. */ @property (readonly, nonatomic) OFKernelEventObserver *observer; |
︙ | ︙ |
Renamed and modified src/exceptions/OFObserveFailedException.m [1a09e82eb7] to src/exceptions/OFObserveKernelEventsFailedException.m [1f89b66175].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | * 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 "OFObserveKernelEventsFailedException.h" #import "OFString.h" #import "OFKernelEventObserver.h" @implementation OFObserveKernelEventsFailedException @synthesize observer = _observer, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } |
︙ | ︙ |
Modified src/exceptions/OFOpenItemFailedException.h from [bf32fbec46] to [fe988003bf].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFOpenItemFailedException \ * OFOpenItemFailedException.h ObjFW/OFOpenItemFailedException.h * * @brief An exception indicating an item could not be opened. */ @interface OFOpenItemFailedException: OFException { OFURI *_Nullable _URI; OFString *_Nullable _path; OFString *_mode; int _errNo; OF_RESERVE_IVARS(OFOpenItemFailedException, 4) } /** * @brief The URI of the item which could not be opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFURI *URI; /** * @brief The path of the item which could not be opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path; /** * @brief The mode in which the item should have been opened. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *mode; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased open item failed exception. * * @param URI The URI of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return A new, autoreleased open item failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI mode: (nullable OFString *)mode errNo: (int)errNo; /** * @brief Creates a new, autoreleased open item failed exception. * * @param path The path of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return A new, autoreleased open item failed exception */ + (instancetype)exceptionWithPath: (OFString *)path mode: (nullable OFString *)mode errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated open item failed exception. * * @param URI The URI of the item which could not be opened * @param mode A string with the mode in which the item should have been opened * @param errNo The errno of the error that occurred * @return An initialized open item failed exception */ - (instancetype)initWithURI: (OFURI *)URI mode: (nullable OFString *)mode errNo: (int)errNo; /** * @brief Initializes an already allocated open item failed exception. * * @param path The path of the item which could not be opened |
︙ | ︙ |
Modified src/exceptions/OFOpenItemFailedException.m from [2b4ec7a8b3] to [7129cdf836].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFOpenItemFailedException.h" #import "OFString.h" | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | * file. */ #include "config.h" #import "OFOpenItemFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFOpenItemFailedException @synthesize URI = _URI, path = _path, mode = _mode, errNo = _errNo; + (instancetype)exceptionWithURI: (OFURI *)URI mode: (OFString *)mode errNo: (int)errNo { return [[[self alloc] initWithURI: URI mode: mode errNo: errNo] autorelease]; } + (instancetype)exceptionWithPath: (OFString *)path mode: (OFString *)mode errNo: (int)errNo { return [[[self alloc] initWithPath: path mode: mode errNo: errNo] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _mode = [mode copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
84 85 86 87 88 89 90 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { | | | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_URI release]; [_path release]; [_mode release]; [super dealloc]; } - (OFString *)description { id item = nil; if (_URI != nil) item = _URI; else if (_path != nil) item = _path; if (_mode != nil) return [OFString stringWithFormat: @"Failed to open file %@ with mode %@: %@", item, _mode, OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to open item %@: %@", item, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.h from [5fb8a73f7a] to [36fb64cf1a].
︙ | ︙ | |||
27 28 29 30 31 32 33 | * * @brief An exception indicating that opening a Windows registry key failed. */ @interface OFOpenWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; | < | > > > > > > > < < < < < < > > < < < | | > | < | > > < < < | | > | < | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | * * @brief An exception indicating that opening a Windows registry key failed. */ @interface OFOpenWindowsRegistryKeyFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_path; REGSAM _accessRights; LPSECURITY_ATTRIBUTES _Nullable _securityAttributes; DWORD _options; LSTATUS _status; OF_RESERVE_IVARS(OFOpenWindowsRegistryKeyFailedException, 4) } /** * @brief The registry key on which opening the subkey failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The path for the subkey that could not be opened. */ @property (readonly, nonatomic) OFString *path; /** * @brief The access rights for the subkey that could not be opened. */ @property (readonly, nonatomic) REGSAM accessRights; /** * @brief The options for the subkey that could not be opened. */ @property (readonly, nonatomic) DWORD options; /** * @brief The status returned by RegOpenKeyEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased open Windows registry key failed * exception. * * @param registryKey The registry key on which opening the subkey failed * @param path The path for the subkey that could not be opened * @param accessRights The access rights for the sub key that could not be * opened * @param options The options for the subkey that could not be opened * @param status The status returned by RegOpenKeyEx() * @return A new, autoreleased open Windows registry key failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated open Windows registry key failed * exception. * * @param registryKey The registry key on which opening the subkey failed * @param path The path for the subkey that could not be opened * @param accessRights The access rights for the sub key that could not be * opened * @param options The options for the subkey that could not be opened * @param status The status returned by RegOpenKeyEx() * @return An initialized open Windows registry key failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.m from [52118b22c0] to [64b24e1261].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFOpenWindowsRegistryKeyFailedException.h" @implementation OFOpenWindowsRegistryKeyFailedException | | < | < | | > | < | > < < | | > | < | > < | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | */ #include "config.h" #import "OFOpenWindowsRegistryKeyFailedException.h" @implementation OFOpenWindowsRegistryKeyFailedException @synthesize registryKey = _registryKey, path = _path; @synthesize accessRights = _accessRights, options = _options, status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey path: path accessRights: accessRights options: options status: status] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey path: (OFString *)path accessRights: (REGSAM)accessRights options: (DWORD)options status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _path = [path copy]; _accessRights = accessRights; _options = options; _status = status; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ |
Modified src/exceptions/OFOutOfMemoryException.h from [a0abc1f6de] to [f5654732f6].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * OFOutOfMemoryException.h ObjFW/OFOutOfMemoryException.h * * @brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { size_t _requestedSize; } /** * @brief The size of the memory that could not be allocated. */ @property (readonly, nonatomic) size_t requestedSize; | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * OFOutOfMemoryException.h ObjFW/OFOutOfMemoryException.h * * @brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { size_t _requestedSize; OF_RESERVE_IVARS(OFOutOfMemoryException, 4) } /** * @brief The size of the memory that could not be allocated. */ @property (readonly, nonatomic) size_t requestedSize; |
︙ | ︙ |
Modified src/exceptions/OFOutOfRangeException.h from [ad1a11af88] to [f8a5e124cb].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 | /** * @class OFOutOfRangeException \ * OFOutOfRangeException.h ObjFW/OFOutOfRangeException.h * * @brief An exception indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException @end OF_ASSUME_NONNULL_END | > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * @class OFOutOfRangeException \ * OFOutOfRangeException.h ObjFW/OFOutOfRangeException.h * * @brief An exception indicating the given value is out of range. */ @interface OFOutOfRangeException: OFException { OF_RESERVE_IVARS(OFOutOfRangeException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFReadFailedException.h from [a4ca6ea7be] to [1ab276c5fd].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 | /** * @class OFReadFailedException \ * OFReadFailedException.h ObjFW/OFReadFailedException.h * * @brief An exception indicating that reading from an object failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException @end OF_ASSUME_NONNULL_END | > > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * @class OFReadFailedException \ * OFReadFailedException.h ObjFW/OFReadFailedException.h * * @brief An exception indicating that reading from an object failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException { OF_RESERVE_IVARS(OFReadFailedException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFReadOrWriteFailedException.h from [17403f4ccf] to [2c37db7aa0].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * failed. */ @interface OFReadOrWriteFailedException: OFException { id _object; size_t _requestedLength; int _errNo; } /** * @brief The stream which caused the read or write failed exception. */ @property (readonly, nonatomic) id object; | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * failed. */ @interface OFReadOrWriteFailedException: OFException { id _object; size_t _requestedLength; int _errNo; OF_RESERVE_IVARS(OFReadOrWriteFailedException, 4) } /** * @brief The stream which caused the read or write failed exception. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFRemoveItemFailedException.h from [c9bfaec2ab] to [18b7b9ee6b].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFRemoveItemFailedException \ * OFRemoveItemFailedException.h ObjFW/OFRemoveItemFailedException.h * * @brief An exception indicating that removing an item failed. */ @interface OFRemoveItemFailedException: OFException { OFURI *_URI; int _errNo; OF_RESERVE_IVARS(OFRemoveItemFailedException, 4) } /** * @brief The URI of the item which could not be removed. */ @property (readonly, nonatomic) OFURI *URI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased remove failed exception. * * @param URI The URI of the item which could not be removed * @param errNo The errno of the error that occurred * @return A new, autoreleased remove item failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated remove failed exception. * * @param URI The URI of the item which could not be removed * @param errNo The errno of the error that occurred * @return An initialized remove item failed exception */ - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFRemoveItemFailedException.m from [be28f37327] to [790fd92540].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFRemoveItemFailedException.h" #import "OFString.h" | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | * file. */ #include "config.h" #import "OFRemoveItemFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFRemoveItemFailedException @synthesize URI = _URI, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo { return [[[self alloc] initWithURI: URI errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_URI release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to remove item at URI %@: %@", _URI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFResolveHostFailedException.h from [26d03aec04] to [983add21d8].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * @brief An exception indicating that resolving a host failed. */ @interface OFResolveHostFailedException: OFException { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolverErrorCode _errorCode; } /** * @brief The host which could not be resolved. */ @property (readonly, nonatomic) OFString *host; | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * @brief An exception indicating that resolving a host failed. */ @interface OFResolveHostFailedException: OFException { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolverErrorCode _errorCode; OF_RESERVE_IVARS(OFResolveHostFailedException, 4) } /** * @brief The host which could not be resolved. */ @property (readonly, nonatomic) OFString *host; |
︙ | ︙ |
Modified src/exceptions/OFSeekFailedException.h from [f6a3b56229] to [2132111c3a].
︙ | ︙ | |||
23 24 25 26 27 28 29 | * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; | | > | > | | | | | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; OFStreamOffset _offset; OFSeekWhence _whence; int _errNo; OF_RESERVE_IVARS(OFSeekFailedException, 4) } /** * @brief The stream for which seeking failed. */ @property (readonly, nonatomic) OFSeekableStream *stream; /** * @brief The offset to which seeking failed. */ @property (readonly, nonatomic) OFStreamOffset offset; /** * @brief To what the offset is relative. */ @property (readonly, nonatomic) OFSeekWhence whence; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief Creates a new, autoreleased seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return An initialized seek failed exception */ - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSeekFailedException.m from [8afbb45d54] to [20812553c7].
︙ | ︙ | |||
25 26 27 28 29 30 31 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream | | | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo { return [[[self alloc] initWithStream: stream offset: offset whence: whence errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFStreamOffset)offset whence: (OFSeekWhence)whence errNo: (int)errNo { self = [super init]; _stream = [stream retain]; _offset = offset; _whence = whence; |
︙ | ︙ |
Modified src/exceptions/OFSetItemAttributesFailedException.h from [40e626240d] to [4b245f8a54].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * 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" | | | | > | | | | | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | * 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" #import "OFURIHandler.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFSetItemAttributesFailedException \ * OFSetItemAttributesFailedException.h \ * ObjFW/OFSetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be set. */ @interface OFSetItemAttributesFailedException: OFException { OFURI *_URI; OFFileAttributes _attributes; OFFileAttributeKey _failedAttribute; int _errNo; OF_RESERVE_IVARS(OFSetItemAttributesFailedException, 4) } /** * @brief The URI of the item whose attributes could not be set. */ @property (readonly, nonatomic) OFURI *URI; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief The attributes that should have been set. */ @property (readonly, nonatomic) OFFileAttributes attributes; /** * @brief The first attribute that could not be set. */ @property (readonly, nonatomic) OFFileAttributeKey failedAttribute; /** * @brief Creates a new, autoreleased set item attributes failed exception. * * @param URI The URI of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set item attributes failed exception */ + (instancetype)exceptionWithURI: (OFURI *)URI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Initializes an already allocated set item attributes failed exception. * * @param URI The URI of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return An initialized set item attributes failed exception */ - (instancetype)initWithURI: (OFURI *)URI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSetItemAttributesFailedException.m from [c7f09ee0c0] to [419b3c1aff].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFSetItemAttributesFailedException.h" #import "OFString.h" | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | * file. */ #include "config.h" #import "OFSetItemAttributesFailedException.h" #import "OFString.h" #import "OFURI.h" @implementation OFSetItemAttributesFailedException @synthesize URI = _URI, attributes = _attributes; @synthesize failedAttribute = _failedAttribute, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURI: (OFURI *)URI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { return [[[self alloc] initWithURI: URI attributes: attributes failedAttribute: failedAttribute errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURI: (OFURI *)URI attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { self = [super init]; @try { _URI = [URI copy]; _attributes = [attributes copy]; _failedAttribute = [failedAttribute copy]; _errNo = errNo; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_URI release]; [_attributes release]; [_failedAttribute release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set attribute %@ for item %@: %@", _failedAttribute, _URI, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSetOptionFailedException.h from [fd8e9dd895] to [2fa10041b9].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * * @brief An exception indicating that setting an option for an object failed. */ @interface OFSetOptionFailedException: OFException { id _object; int _errNo; } /** * @brief The object for which the option could not be set. */ @property (readonly, nonatomic) id object; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that setting an option for an object failed. */ @interface OFSetOptionFailedException: OFException { id _object; int _errNo; OF_RESERVE_IVARS(OFSetOptionFailedException, 4) } /** * @brief The object for which the option could not be set. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFSetWindowsRegistryValueFailedException.h from [881eab26fa] to [88eed12b7b].
︙ | ︙ | |||
30 31 32 33 34 35 36 37 38 39 40 41 42 43 | @interface OFSetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; OFData *_Nullable _data; DWORD _type; LSTATUS _status; } /** * @brief The registry key on which setting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | @interface OFSetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; OFData *_Nullable _data; DWORD _type; LSTATUS _status; OF_RESERVE_IVARS(OFSetWindowsRegistryValueFailedException, 4) } /** * @brief The registry key on which setting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; |
︙ | ︙ |
Modified src/exceptions/OFStillLockedException.h from [9e844f7b24] to [da104224a4].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * OFStillLockedException.h ObjFW/OFStillLockedException.h * * @brief An exception indicating that a lock is still locked. */ @interface OFStillLockedException: OFException { id <OFLocking> _Nullable _lock; } /** * @brief The lock which is still locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * OFStillLockedException.h ObjFW/OFStillLockedException.h * * @brief An exception indicating that a lock is still locked. */ @interface OFStillLockedException: OFException { id <OFLocking> _Nullable _lock; OF_RESERVE_IVARS(OFStillLockedException, 4) } /** * @brief The lock which is still locked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; |
︙ | ︙ |
Modified src/exceptions/OFTLSHandshakeFailedException.h from [624dc0f97d] to [f9e2ae9630].
︙ | ︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | * @brief An exception indicating that a TLS handshake. */ @interface OFTLSHandshakeFailedException: OFException { OFTLSStream *_stream; OFString *_Nullable _host; OFTLSStreamErrorCode _errorCode; } /** * @brief The TLS stream which failed the handshake. */ @property (readonly, nonatomic) OFTLSStream *stream; | > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | * @brief An exception indicating that a TLS handshake. */ @interface OFTLSHandshakeFailedException: OFException { OFTLSStream *_stream; OFString *_Nullable _host; OFTLSStreamErrorCode _errorCode; OF_RESERVE_IVARS(OFTLSHandshakeFailedException, 4) } /** * @brief The TLS stream which failed the handshake. */ @property (readonly, nonatomic) OFTLSStream *stream; |
︙ | ︙ |
Modified src/exceptions/OFThreadJoinFailedException.h from [8bf49777b7] to [d301dc0b05].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * * @brief An exception indicating that joining a thread failed. */ @interface OFThreadJoinFailedException: OFException { OFThread *_Nullable _thread; int _errNo; } /** * @brief The thread which could not be joined. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; | > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFThreadStartFailedException.h from [d864107627] to [744fa4d2f0].
︙ | ︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * * @brief An exception indicating that starting a thread failed. */ @interface OFThreadStartFailedException: OFException { OFThread *_Nullable _thread; int _errNo; } /** * @brief The thread which could not be started. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; | > | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | * * @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; |
︙ | ︙ |
Modified src/exceptions/OFThreadStillRunningException.h from [2982187d56] to [8cadaadd37].
︙ | ︙ | |||
28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * OFThreadStillRunningException.h ObjFW/OFThreadStillRunningException.h * * @brief An exception indicating that a thread is still running. */ @interface OFThreadStillRunningException: OFException { OFThread *_Nullable _thread; } /** * @brief The thread which is still running. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; | > | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * OFThreadStillRunningException.h ObjFW/OFThreadStillRunningException.h * * @brief An exception indicating that a thread is still running. */ @interface OFThreadStillRunningException: OFException { OFThread *_Nullable _thread; OF_RESERVE_IVARS(OFThreadStillRunningException, 4) } /** * @brief The thread which is still running. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThread *thread; |
︙ | ︙ |
Modified src/exceptions/OFTruncatedDataException.h from [8a558e22e7] to [c355984cb5].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 | * @class OFTruncatedDataException \ * OFTruncatedDataException.h ObjFW/OFTruncatedDataException.h * * @brief An exception indicating that data was truncated while it should not * have been truncated. */ @interface OFTruncatedDataException: OFException @end OF_ASSUME_NONNULL_END | > > > | 21 22 23 24 25 26 27 28 29 30 31 32 33 | * @class OFTruncatedDataException \ * OFTruncatedDataException.h ObjFW/OFTruncatedDataException.h * * @brief An exception indicating that data was truncated while it should not * have been truncated. */ @interface OFTruncatedDataException: OFException { OF_RESERVE_IVARS(OFTruncatedDataException, 4) } @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFUnboundNamespaceException.h from [cc4424a80d] to [782770074b].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @brief An exception indicating an attempt to use an unbound namespace. */ @interface OFUnboundNamespaceException: OFException { OFString *_namespace; OFXMLElement *_element; } /** * @brief The unbound namespace. */ #ifndef __cplusplus @property (readonly, nonatomic) OFString *namespace; | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * * @brief An exception indicating an attempt to use an unbound namespace. */ @interface OFUnboundNamespaceException: OFException { OFString *_namespace; OFXMLElement *_element; OF_RESERVE_IVARS(OFUnboundNamespaceException, 4) } /** * @brief The unbound namespace. */ #ifndef __cplusplus @property (readonly, nonatomic) OFString *namespace; |
︙ | ︙ |
Modified src/exceptions/OFUnboundPrefixException.h from [6d7bca5c41] to [c1eaadb13e].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @brief An exception indicating an attempt to use an unbound prefix. */ @interface OFUnboundPrefixException: OFException { OFString *_prefix; OFXMLParser *_parser; } /** * @brief The unbound prefix. */ @property (readonly, nonatomic) OFString *prefix; | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * * @brief An exception indicating an attempt to use an unbound prefix. */ @interface OFUnboundPrefixException: OFException { OFString *_prefix; OFXMLParser *_parser; OF_RESERVE_IVARS(OFUnboundPrefixException, 4) } /** * @brief The unbound prefix. */ @property (readonly, nonatomic) OFString *prefix; |
︙ | ︙ |
Modified src/exceptions/OFUndefinedKeyException.h from [1d0c472b52] to [1b1bc72e6f].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * Coding). */ @interface OFUndefinedKeyException: OFException { id _object; OFString *_Nullable _key; id _Nullable _value; } /** * @brief The object on which the key is undefined. */ @property (readonly, nonatomic) id object; | > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | * Coding). */ @interface OFUndefinedKeyException: OFException { id _object; OFString *_Nullable _key; id _Nullable _value; OF_RESERVE_IVARS(OFUndefinedKeyException, 4) } /** * @brief The object on which the key is undefined. */ @property (readonly, nonatomic) id object; |
︙ | ︙ |
Modified src/exceptions/OFUnknownXMLEntityException.h from [fdd37fe4f2] to [effb41465b].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * * @brief An exception indicating that a parser encountered an unknown XML * entity. */ @interface OFUnknownXMLEntityException: OFException { OFString *_entityName; } /** * @brief The name of the unknown XML entity. */ @property (readonly, nonatomic) OFString *entityName; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that a parser encountered an unknown XML * entity. */ @interface OFUnknownXMLEntityException: OFException { OFString *_entityName; OF_RESERVE_IVARS(OFUnknownXMLEntityException, 4) } /** * @brief The name of the unknown XML entity. */ @property (readonly, nonatomic) OFString *entityName; |
︙ | ︙ |
Modified src/exceptions/OFUnlockFailedException.h from [ab29b208b2] to [2273de4dc6].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that unlocking a lock failed. */ @interface OFUnlockFailedException: OFException { id <OFLocking> _Nullable _lock; int _errNo; } /** * @brief The lock which could not be unlocked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * * @brief An exception indicating that unlocking a lock failed. */ @interface OFUnlockFailedException: OFException { id <OFLocking> _Nullable _lock; int _errNo; OF_RESERVE_IVARS(OFUnlockFailedException, 4) } /** * @brief The lock which could not be unlocked. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) id <OFLocking> lock; |
︙ | ︙ |
Modified src/exceptions/OFUnsupportedProtocolException.h from [8223e3796e] to [229fefef5c].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN | | | | > | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFURI; /** * @class OFUnsupportedProtocolException \ * OFUnsupportedProtocolException.h \ * ObjFW/OFUnsupportedProtocolException.h * * @brief An exception indicating that the protocol specified by the URI is not * supported. */ @interface OFUnsupportedProtocolException: OFException { OFURI *_Nullable _URI; OF_RESERVE_IVARS(OFUnsupportedProtocolException, 4) } /** * @brief The URI whose protocol is unsupported. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFURI *URI; /** * @brief Creates a new, autoreleased unsupported protocol exception. * * @param URI The URI whose protocol is unsupported * @return A new, autoreleased unsupported protocol exception */ + (instancetype)exceptionWithURI: (nullable OFURI*)URI; /** * @brief Initializes an already allocated unsupported protocol exception * * @param URI The URI whose protocol is unsupported * @return An initialized unsupported protocol exception */ - (instancetype)initWithURI: (nullable OFURI*)URI OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFUnsupportedProtocolException.m from [ba097adb5e] to [a391485837].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFUnsupportedProtocolException.h" #import "OFString.h" | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | * file. */ #include "config.h" #import "OFUnsupportedProtocolException.h" #import "OFString.h" #import "OFURI.h" @implementation OFUnsupportedProtocolException @synthesize URI = _URI; + (instancetype)exceptionWithURI: (OFURI *)URI { return [[[self alloc] initWithURI: URI] autorelease]; } - (instancetype)initWithURI: (OFURI *)URI { self = [super init]; _URI = [URI retain]; return self; } - (void)dealloc { [_URI release]; [super dealloc]; } - (OFString *)description { if (_URI != nil) return [OFString stringWithFormat: @"The protocol of URI %@ is not supported!", _URI]; else return @"The requested protocol is unsupported!"; } @end |
Modified src/exceptions/OFUnsupportedVersionException.h from [fd604be220] to [2da3b1eaf2].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * * @brief An exception indicating that the specified version of the format or * protocol is not supported. */ @interface OFUnsupportedVersionException: OFException { OFString *_version; } /** * @brief The version which is unsupported. */ @property (readonly, nonatomic) OFString *version; | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | * * @brief An exception indicating that the specified version of the format or * protocol is not supported. */ @interface OFUnsupportedVersionException: OFException { OFString *_version; OF_RESERVE_IVARS(OFUnsupportedVersionException, 4) } /** * @brief The version which is unsupported. */ @property (readonly, nonatomic) OFString *version; |
︙ | ︙ |
Modified src/exceptions/OFWriteFailedException.h from [52a0c0096f] to [6dee61073a].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * OFWriteFailedException.h ObjFW/OFWriteFailedException.h * * @brief An exception indicating that writing to an object failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException { size_t _bytesWritten; } /** * @brief The number of bytes already written before the write failed. * * This can be used to make sure that a retry does not write data already * written before. | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * OFWriteFailedException.h ObjFW/OFWriteFailedException.h * * @brief An exception indicating that writing to an object failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException { size_t _bytesWritten; OF_RESERVE_IVARS(OFWriteFailedException, 4) } /** * @brief The number of bytes already written before the write failed. * * This can be used to make sure that a retry does not write data already * written before. |
︙ | ︙ |
Modified src/platform/AmigaOS/OFString+PathAdditions.m from [1da7b3fb62] to [60752aa5d1].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileURIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components |
︙ | ︙ | |||
151 152 153 154 155 156 157 | } objc_autoreleasePoolPop(pool); return @""; } components = [components objectsInRange: | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | } objc_autoreleasePoolPop(pool); return @""; } components = [components objectsInRange: OFMakeRange(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } |
︙ | ︙ | |||
231 232 233 234 235 236 237 | done = false; break; } if ([component isEqual: @"/"] && parent != nil && ![parent isEqual: @"/"]) { [array removeObjectsInRange: | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | done = false; break; } if ([component isEqual: @"/"] && parent != nil && ![parent isEqual: @"/"]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
289 290 291 292 293 294 295 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [self hasSuffix: @":"] || | | | > | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [self hasSuffix: @":"] || [OFFileURIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToURIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { OFArray OF_GENERIC(OFString *) *components = self.pathComponents; OFMutableString *ret = [OFMutableString string]; for (OFString *component in components) { if (component.length == 0) continue; |
︙ | ︙ | |||
314 315 316 317 318 319 320 | } [ret makeImmutable]; return ret; } | | > | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | } [ret makeImmutable]; return ret; } - (OFString *)of_URIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; OFMutableArray OF_GENERIC(OFString *) *components; |
︙ | ︙ | |||
347 348 349 350 351 352 353 | if ([component isEqual: @".."]) [components replaceObjectAtIndex: i withObject: @"/"]; } return [OFString pathWithComponents: components]; } | | | 349 350 351 352 353 354 355 356 357 358 359 360 | if ([component isEqual: @".."]) [components replaceObjectAtIndex: i withObject: @"/"]; } return [OFString pathWithComponents: components]; } - (OFString *)of_pathComponentToURIPathComponent { return self; } @end |
Modified src/platform/POSIX/OFString+PathAdditions.m from [fcc8205b0e] to [d1f51523cf].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileURIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components |
︙ | ︙ | |||
273 274 275 276 277 278 279 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
334 335 336 337 338 339 340 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || | | | > | > | | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [OFFileURIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToURIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { return self; } - (OFString *)of_URIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; return path; } - (OFString *)of_pathComponentToURIPathComponent { return self; } @end |
Modified src/platform/Windows/OFString+PathAdditions.m from [353eef09b4] to [ec08b34f89].
︙ | ︙ | |||
18 19 20 21 22 23 24 | * Windows-specific parts! */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * Windows-specific parts! */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileURIHandler.h" #import "OFURI.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) |
︙ | ︙ | |||
199 200 201 202 203 204 205 | } objc_autoreleasePoolPop(pool); return @"."; } components = [components objectsInRange: | | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | } objc_autoreleasePoolPop(pool); return @"."; } components = [components objectsInRange: OFMakeRange(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } |
︙ | ︙ | |||
284 285 286 287 288 289 290 | if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."] && ![parent hasSuffix: @":"] && ![parent hasSuffix: @":\\"] && ![parent hasSuffix: @"://"] && (![parent hasPrefix: @"\\"] || i != 1)) { [array removeObjectsInRange: | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."] && ![parent hasSuffix: @":"] && ![parent hasSuffix: @":\\"] && ![parent hasSuffix: @"://"] && (![parent hasPrefix: @"\\"] || i != 1)) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
339 340 341 342 343 344 345 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] || | | | > | | | | | | > | | > | | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] || [OFFileURIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToURIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { OFString *path = self; if ([path hasPrefix: @"\\\\"]) { OFArray *components = path.pathComponents; if (components.count < 2) @throw [OFInvalidFormatException exception]; *percentEncodedHost = [[components objectAtIndex: 1] stringByAddingPercentEncodingWithAllowedCharacters: [OFCharacterSet URIHostAllowedCharacterSet]]; path = [OFString pathWithComponents: [components objectsInRange: OFMakeRange(2, components.count - 2)]]; } path = [path stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; path = [@"/" stringByAppendingString: path]; return path; } - (OFString *)of_URIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"] && ![path hasSuffix: @":/"]) path = [path substringToIndex: path.length - 1]; path = [path substringFromIndex: 1]; path = [path stringByReplacingOccurrencesOfString: @"/" withString: @"\\"]; if (percentEncodedHost != nil) { OFString *host = [percentEncodedHost stringByRemovingPercentEncoding]; if (path.length == 0) path = [OFString stringWithFormat: @"\\\\%@", host]; else path = [OFString stringWithFormat: @"\\\\%@\\%@", host, path]; } return path; } - (OFString *)of_pathComponentToURIPathComponent { return [self stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; } @end |
Modified src/platform/Windows/OFSubprocess.m from [0ef8b1e769] to [4951913bf9].
︙ | ︙ | |||
151 152 153 154 155 156 157 | [OFMutableString stringWithString: programName]; [argumentsString replaceOccurrencesOfString: @"\\\"" withString: @"\\\\\""]; [argumentsString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; if ([argumentsString containsString: @" "]) { | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | [OFMutableString stringWithString: programName]; [argumentsString replaceOccurrencesOfString: @"\\\"" withString: @"\\\\\""]; [argumentsString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; if ([argumentsString containsString: @" "]) { [argumentsString insertString: @"\"" atIndex: 0]; [argumentsString appendString: @"\""]; } for (OFString *argument in arguments) { OFMutableString *tmp = [[argument mutableCopy] autorelease]; bool containsSpaces = [tmp containsString: @" "]; |
︙ | ︙ |
Name change from src/OFWin32ConsoleStdIOStream.m to src/platform/Windows/OFWin32ConsoleStdIOStream.m.
︙ | ︙ |
Modified src/platform/libfat/OFString+PathAdditions.m from [7996727ec2] to [6647377f7a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "OFString+PathAdditions.h" #import "OFArray.h" #import "OFFileURIHandler.h" #import "OFOutOfRangeException.h" int _OFString_PathAdditions_reference; @implementation OFString (PathAdditions) + (OFString *)pathWithComponents: (OFArray *)components |
︙ | ︙ | |||
277 278 279 280 281 282 283 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFMakeRange(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
335 336 337 338 339 340 341 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || | | | > | | > | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | } else return [self stringByAppendingFormat: @".%@", extension]; } - (bool)of_isDirectoryPath { return ([self hasSuffix: @"/"] || [OFFileURIHandler of_directoryExistsAtPath: self]); } - (OFString *)of_pathToURIPathWithPercentEncodedHost: (OFString **)percentEncodedHost { return [@"/" stringByAppendingString: self]; } - (OFString *)of_URIPathToPathWithPercentEncodedHost: (OFString *)percentEncodedHost { OFString *path = self; if (path.length > 1 && [path hasSuffix: @"/"]) path = [path substringToIndex: path.length - 1]; return [path substringFromIndex: 1]; } - (OFString *)of_pathComponentToURIPathComponent { return self; } @end |
Modified src/runtime/Makefile from [6dd30f7bce] to [23dfac9b53].
︙ | ︙ | |||
27 28 29 30 31 32 33 | property.m \ protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ synchronized.m \ tagged-pointer.m \ | | > > > > > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | property.m \ protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ synchronized.m \ tagged-pointer.m \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_THREADS = OFOnce.m \ OFPlainMutex.m \ OFTLSKey.m \ threading.m SRCS_WINDOWS = versioninfo.rc INCLUDES = ObjFWRT.h includesubdir = ObjFWRT OBJS_EXTRA = lookup-asm/lookup-asm.a LIB_OBJS_EXTRA = lookup-asm/lookup-asm.lib.a AMIGA_LIB_OBJS_START = amiga-library.amigalib.o AMIGA_LIB_OBJS_EXTRA = amiga-glue.amigalib.o \ lookup-asm/lookup-asm.amigalib.a \ amiga-end.amigalib.o include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. \ -DOBJC_COMPILING_RUNTIME \ -DOBJFWRT_AMIGA_LIB=\"${OBJFWRT_AMIGA_LIB}\" \ -DOBJFWRT_LIB_MAJOR=${OBJFWRT_LIB_MAJOR} \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} AMIGA_LIB_CFLAGS += -DOBJC_COMPILING_AMIGA_LIBRARY LD = ${OBJC} FRAMEWORK_LIBS = ${LIBS} RCFLAGS = --use-temp-file \ -DOBJFWRT_LIB_MAJOR=${OBJFWRT_LIB_MAJOR} \ -DOBJFWRT_LIB_MINOR=${OBJFWRT_LIB_MINOR} \ -DOBJFWRT_LIB_VERSION=\"${OBJFWRT_LIB_MAJOR}.${OBJFWRT_LIB_MINOR}\" \ -DOBJFWRT_SHARED_LIB=\"${OBJFWRT_SHARED_LIB}\" |
Modified src/runtime/amiga-library.m from [5e255cd58a] to [8a6730d0a3].
︙ | ︙ | |||
39 40 41 42 43 44 45 | # define OBJC_M68K_REG(reg) __asm__(#reg) #else # define OBJC_M68K_REG(reg) #endif /* This always needs to be the first thing in the file. */ int | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # define OBJC_M68K_REG(reg) __asm__(#reg) #else # define OBJC_M68K_REG(reg) #endif /* This always needs to be the first thing in the file. */ int _start(void) { return -1; } #ifdef OF_AMIGAOS_M68K void __init_eh(void) |
︙ | ︙ | |||
290 291 292 293 294 295 296 | OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) if (base->parent != NULL) { struct ObjFWRTBase *parent; #ifdef OF_AMIGAOS_M68K if (base->initialized) | | > | < | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | OBJC_M68K_ARG(struct ObjFWRTBase *, base, a6) if (base->parent != NULL) { struct ObjFWRTBase *parent; #ifdef OF_AMIGAOS_M68K if (base->initialized) for (void *const *frame = _EH_FRAME_BEGINS__; *frame != NULL;) libc.__deregister_frame_info(*frame++); #endif parent = base->parent; FreeMem(base->dataSeg - DATA_OFFSET, getDataSize()); FreeMem((char *)base - base->library.lib_NegSize, base->library.lib_NegSize + base->library.lib_PosSize); |
︙ | ︙ | |||
341 342 343 344 345 346 347 | if (base->initialized) return true; memcpy(&libc, libc_, sizeof(libc)); #ifdef OF_AMIGAOS_M68K | | < | < | < | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | if (base->initialized) return true; memcpy(&libc, libc_, sizeof(libc)); #ifdef OF_AMIGAOS_M68K for (void *const *frame = _EH_FRAME_OBJECTS__, **object = _EH_FRAME_OBJECTS__; *frame != NULL;) libc.__register_frame_info(*frame++, *object++); iter0 = &__CTOR_LIST__[1]; #elif defined(OF_MORPHOS) __asm__ ( "lis %0, __EH_FRAME_BEGIN__@ha\n\t" "la %0, __EH_FRAME_BEGIN__@l(%0)\n\t" "lis %1, __CTOR_LIST__@ha\n\t" |
︙ | ︙ |
Modified src/runtime/autorelease.m from [44274c4d6f] to [a652114a4e].
︙ | ︙ | |||
59 60 61 62 63 64 65 | if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 || OFTLSKeyNew(&sizeKey) != 0) OBJC_ERROR("Failed to create TLS keys!"); } #endif void * | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 || OFTLSKeyNew(&sizeKey) != 0) OBJC_ERROR("Failed to create TLS keys!"); } #endif void * objc_autoreleasePoolPush(void) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); #endif return (void *)count; } |
︙ | ︙ |
Modified src/runtime/class.m from [8d4b7cca0f] to [bcbf47b312].
︙ | ︙ | |||
401 402 403 404 405 406 407 | initializeClass(class); objc_globalMutex_unlock(); } static void | | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | initializeClass(class); objc_globalMutex_unlock(); } static void processLoadQueue(void) { for (size_t i = 0; i < loadQueueCount; i++) { setUpClass(loadQueue[i]); if (loadQueue[i]->info & OBJC_CLASS_INFO_SETUP) { callLoad(loadQueue[i]); |
︙ | ︙ |
Modified src/runtime/static-instances.m from [a4b6846d46] to [7d72566e27].
︙ | ︙ | |||
91 92 93 94 95 96 97 | staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 | staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void objc_forgetPendingStaticInstances(void) { free(staticInstancesList); staticInstancesList = NULL; staticInstancesCount = 0; } |
Added src/runtime/versioninfo.rc version [6986fc8cab].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include "config.h" #include "winver.h" 1 VERSIONINFO FILEVERSION OBJFWRT_LIB_MAJOR, OBJFWRT_LIB_MINOR, 0, 0 PRODUCTVERSION OBJFW_VERSION_MAJOR, OBJFW_VERSION_MINOR, 0, 0 FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL { BLOCK "StringFileInfo" { BLOCK "040904E4" { VALUE "ProductName", "ObjFW Runtime" VALUE "ProductVersion", PACKAGE_VERSION VALUE "FileVersion", OBJFWRT_LIB_VERSION VALUE "FileDescription", "Objective-C runtime" VALUE "LegalCopyright", "(c) 2008-2022 Jonathan Schleifer" VALUE "InternalName", "ObjFWRT" VALUE "OriginalFilename", OBJFWRT_SHARED_LIB } } BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1252 } } |
Added src/versioninfo.rc version [ec5c3868fe].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include "config.h" #include "winver.h" 1 VERSIONINFO FILEVERSION OBJFW_LIB_MAJOR, OBJFW_LIB_MINOR, 0, 0 PRODUCTVERSION OBJFW_VERSION_MAJOR, OBJFW_VERSION_MINOR, 0, 0 FILEOS VOS__WINDOWS32 FILETYPE VFT_DLL { BLOCK "StringFileInfo" { BLOCK "040904E4" { VALUE "ProductName", "ObjFW" VALUE "ProductVersion", PACKAGE_VERSION VALUE "FileVersion", OBJFW_LIB_VERSION VALUE "FileDescription", "Objective-C framework" VALUE "LegalCopyright", "(c) 2008-2022 Jonathan Schleifer" VALUE "InternalName", "ObjFW" VALUE "OriginalFilename", OBJFW_SHARED_LIB } } BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1252 } } |
Modified tests/Makefile from [de6109dac1] to [8b1874ff5a].
︙ | ︙ | |||
46 47 48 49 50 51 52 | OFSHA512HashTests.m \ OFScryptTests.m \ OFSerializationTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | OFSHA512HashTests.m \ OFScryptTests.m \ OFSerializationTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFURITests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ RuntimeTests.m \ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ |
︙ | ︙ | |||
87 88 89 90 91 92 93 | IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk serialization_xml.m: serialization.xml | | | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk serialization_xml.m: serialization.xml ${SHELL} ../utils/objfw-embed serialization.xml serialization.xml $@ testfile_bin.m: testfile.bin ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ testfile_ini.m: testfile.ini ${SHELL} ../utils/objfw-embed testfile.ini testfile.ini $@ .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} |
︙ | ︙ |
Modified tests/OFArrayTests.m from [b0ef1c947a] to [cc2ce2f7d0].
︙ | ︙ | |||
182 183 184 185 186 187 188 | TEST(@"-[indexOfObject:]", [array1 indexOfObject: cArray[1]] == 1) TEST(@"-[indexOfObjectIdenticalTo:]", [array2 indexOfObjectIdenticalTo: cArray[1]] == 1) TEST(@"-[objectsInRange:]", | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | TEST(@"-[indexOfObject:]", [array1 indexOfObject: cArray[1]] == 1) TEST(@"-[indexOfObjectIdenticalTo:]", [array2 indexOfObjectIdenticalTo: cArray[1]] == 1) TEST(@"-[objectsInRange:]", [[array1 objectsInRange: OFMakeRange(1, 2)] isEqual: [arrayClass arrayWithObjects: cArray[1], cArray[2], nil]]) TEST(@"-[replaceObject:withObject:]", R([mutableArray1 replaceObject: cArray[1] withObject: cArray[0]]) && [[mutableArray1 objectAtIndex: 0] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]]) |
︙ | ︙ | |||
222 223 224 225 226 227 228 | TEST(@"-[removeObjectAtIndex:]", R([mutableArray2 removeObjectAtIndex: 1]) && mutableArray2.count == 2 && [[mutableArray2 objectAtIndex: 1] isEqual: cArray[2]]) mutableArray2 = [[array1 mutableCopy] autorelease]; TEST(@"-[removeObjectsInRange:]", | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | TEST(@"-[removeObjectAtIndex:]", R([mutableArray2 removeObjectAtIndex: 1]) && mutableArray2.count == 2 && [[mutableArray2 objectAtIndex: 1] isEqual: cArray[2]]) mutableArray2 = [[array1 mutableCopy] autorelease]; TEST(@"-[removeObjectsInRange:]", R([mutableArray2 removeObjectsInRange: OFMakeRange(0, 2)]) && mutableArray2.count == 1 && [[mutableArray2 objectAtIndex: 0] isEqual: cArray[2]]) mutableArray2 = [[array1 mutableCopy] autorelease]; [mutableArray2 addObject: @"qux"]; [mutableArray2 addObject: @"last"]; TEST(@"-[reverse]", |
︙ | ︙ | |||
258 259 260 261 262 263 264 | @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [array1 objectAtIndex: array1.count]) EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", OFOutOfRangeException, [mutableArray1 removeObjectsInRange: | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [array1 objectAtIndex: array1.count]) EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", OFOutOfRangeException, [mutableArray1 removeObjectsInRange: OFMakeRange(0, mutableArray1.count + 1)]) TEST(@"-[componentsJoinedByString:]", (array2 = [arrayClass arrayWithObjects: @"", @"a", @"b", @"c", nil]) && [[array2 componentsJoinedByString: @" "] isEqual: @" a b c"] && (array2 = [arrayClass arrayWithObject: @"foo"]) && [[array2 componentsJoinedByString: @" "] isEqual: @"foo"]) |
︙ | ︙ | |||
427 428 429 430 431 432 433 | valueForKey: @"length"] isEqual: [arrayClass arrayWithObjects: [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil]] && [[[arrayClass arrayWithObjects: @"1", @"2", nil] valueForKey: @"@count"] isEqual: [OFNumber numberWithInt: 2]]) mutableArray1 = [mutableArrayClass arrayWithObjects: | | | | | | | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | valueForKey: @"length"] isEqual: [arrayClass arrayWithObjects: [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil]] && [[[arrayClass arrayWithObjects: @"1", @"2", nil] valueForKey: @"@count"] isEqual: [OFNumber numberWithInt: 2]]) mutableArray1 = [mutableArrayClass arrayWithObjects: [OFMutableURI URIWithString: @"http://foo.bar/"], [OFMutableURI URIWithString: @"http://bar.qux/"], [OFMutableURI URIWithString: @"http://qux.quxqux/"], nil]; TEST(@"-[setValue:forKey:]", R([mutableArray1 setValue: [OFNumber numberWithShort: 1234] forKey: @"port"]) && [mutableArray1 isEqual: [arrayClass arrayWithObjects: [OFURI URIWithString: @"http://foo.bar:1234/"], [OFURI URIWithString: @"http://bar.qux:1234/"], [OFURI URIWithString: @"http://qux.quxqux:1234/"], nil]]) objc_autoreleasePoolPop(pool); } - (void)arrayTests { module = @"OFArray"; |
︙ | ︙ |
Modified tests/OFCharacterSetTests.m from [9f65e98d38] to [9bcb0257c8].
︙ | ︙ | |||
71 72 73 74 75 76 77 | } TEST(@"-[characterIsMember:]", ok); module = @"OFRangeCharacterSet"; TEST(@"+[characterSetWithRange:]", (characterSet = [OFCharacterSet | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | } TEST(@"-[characterIsMember:]", ok); module = @"OFRangeCharacterSet"; TEST(@"+[characterSetWithRange:]", (characterSet = [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]) && [characterSet isKindOfClass: [OFRangeCharacterSet class]]) ok = true; for (OFUnichar c = 0; c < 65536; c++) { if (c >= '0' && c <= '9') { if (![characterSet characterIsMember: c]) ok = false; |
︙ | ︙ |
Modified tests/OFDataTests.m from [cc1d29fd59] to [ffac8c7aa2].
︙ | ︙ | |||
72 73 74 75 76 77 78 | mutableData = [OFMutableData dataWithItems: "abcdef" count: 6]; TEST(@"-[removeLastItem]", R([mutableData removeLastItem]) && mutableData.count == 5 && memcmp(mutableData.items, "abcde", 5) == 0) TEST(@"-[removeItemsInRange:]", | | | | | | | | | | | | | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | mutableData = [OFMutableData dataWithItems: "abcdef" count: 6]; TEST(@"-[removeLastItem]", R([mutableData removeLastItem]) && mutableData.count == 5 && memcmp(mutableData.items, "abcde", 5) == 0) TEST(@"-[removeItemsInRange:]", R([mutableData removeItemsInRange: OFMakeRange(1, 2)]) && mutableData.count == 3 && memcmp(mutableData.items, "ade", 3) == 0) TEST(@"-[insertItems:atIndex:count:]", R([mutableData insertItems: "bc" atIndex: 1 count: 2]) && mutableData.count == 5 && memcmp(mutableData.items, "abcde", 5) == 0) data = [OFData dataWithItems: "aaabaccdacaabb" count: 7 itemSize: 2]; range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; TEST(@"-[rangeOfData:options:range:] #1", range.location == 0 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFMakeRange(0, 7)]; TEST(@"-[rangeOfData:options:range:] #2", range.location == 5 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "ac" count: 1 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; TEST(@"-[rangeOfData:options:range:] #3", range.location == 2 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aabb" count: 2 itemSize: 2] options: 0 range: OFMakeRange(0, 7)]; TEST(@"-[rangeOfData:options:range:] #4", range.location == 5 && range.length == 2) TEST(@"-[rangeOfData:options:range:] #5", R(range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFMakeRange(1, 6)]) && range.location == 5 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFMakeRange(0, 5)]; TEST(@"-[rangeOfData:options:range:] #6", range.location == 0 && range.length == 1) EXPECT_EXCEPTION( @"-[rangeOfData:options:range:] failing on different itemSize", OFInvalidArgumentException, [data rangeOfData: [OFData dataWithItems: "aaa" count: 1 itemSize: 3] options: 0 range: OFMakeRange(0, 1)]) EXPECT_EXCEPTION( @"-[rangeOfData:options:range:] failing on out of range", OFOutOfRangeException, [data rangeOfData: [OFData dataWithItems: "" count: 0 itemSize: 2] options: 0 range: OFMakeRange(8, 1)]) TEST(@"-[subdataWithRange:]", [[data subdataWithRange: OFMakeRange(2, 4)] isEqual: [OFData dataWithItems: "accdacaa" count: 4 itemSize: 2]] && [[mutableData subdataWithRange: OFMakeRange(2, 3)] isEqual: [OFData dataWithItems: "cde" count: 3]]) EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #1", OFOutOfRangeException, [data subdataWithRange: OFMakeRange(7, 1)]) EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #2", OFOutOfRangeException, [mutableData subdataWithRange: OFMakeRange(6, 1)]) TEST(@"-[stringByMD5Hashing]", [mutableData.stringByMD5Hashing isEqual: @"ab56b4d92b40713acc5af89985d4b786"]) TEST(@"-[stringByRIPEMD160Hashing]", [mutableData.stringByRIPEMD160Hashing |
︙ | ︙ | |||
214 215 216 217 218 219 220 | EXPECT_EXCEPTION(@"Detect out of range in -[addItems:count:]", OFOutOfRangeException, [mutableData addItems: raw[0] count: SIZE_MAX]) EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, | | | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | EXPECT_EXCEPTION(@"Detect out of range in -[addItems:count:]", OFOutOfRangeException, [mutableData addItems: raw[0] count: SIZE_MAX]) EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, [mutableData removeItemsInRange: OFMakeRange(mutableData.count, 1)]) OFFreeMemory(raw[0]); OFFreeMemory(raw[1]); objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFDictionaryTests.m from [7127a0734c] to [856ca278b2].
︙ | ︙ | |||
247 248 249 250 251 252 253 | ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) [mutableDict removeObjectForKey: @""]; | < < < < < | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) [mutableDict removeObjectForKey: @""]; #ifdef OF_HAVE_BLOCKS { __block size_t j = 0; __block bool blockOk = true; [mutableDict enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { |
︙ | ︙ |
Modified tests/OFHMACTests.m from [bac63969c0] to [dc8ace4048].
︙ | ︙ | |||
47 48 49 50 51 52 53 | "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E" "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99"; @implementation TestsAppDelegate (OFHMACTests) - (void)HMACTests { void *pool = objc_autoreleasePoolPush(); | | | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E" "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99"; @implementation TestsAppDelegate (OFHMACTests) - (void)HMACTests { void *pool = objc_autoreleasePoolPush(); OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; OFHMAC *HMACMD5, *HMACSHA1, *HMACRMD160; OFHMAC *HMACSHA256, *HMACSHA384, *HMACSHA512; TEST(@"+[HMACWithHashClass:] with MD5", (HMACMD5 = [OFHMAC HMACWithHashClass: [OFMD5Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with SHA-1", |
︙ | ︙ |
Modified tests/OFHTTPClientTests.m from [0615ead311] to [64ad652a21].
︙ | ︙ | |||
97 98 99 100 101 102 103 | [[OFRunLoop mainRunLoop] stop]; } - (void)HTTPClientTests { void *pool = objc_autoreleasePoolPush(); HTTPClientTestsServer *server; | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | [[OFRunLoop mainRunLoop] stop]; } - (void)HTTPClientTests { void *pool = objc_autoreleasePoolPush(); HTTPClientTestsServer *server; OFURI *URI; OFHTTPClient *client; OFHTTPRequest *request; OFData *data; condition = [OFCondition condition]; [condition lock]; server = [[[HTTPClientTestsServer alloc] init] autorelease]; server.supportsSockets = true; [server start]; [condition wait]; [condition unlock]; URI = [OFURI URIWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[asyncPerformRequest:]", (client = [OFHTTPClient client]) && (client.delegate = self) && (request = [OFHTTPRequest requestWithURI: URI]) && (request.headers = [OFDictionary dictionaryWithObject: @"5" forKey: @"Content-Length"]) && R([client asyncPerformRequest: request])) [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; |
︙ | ︙ |
Modified tests/OFHTTPCookieManagerTests.m from [8647894d6b] to [fc980e6e00].
︙ | ︙ | |||
20 21 22 23 24 25 26 | static OFString *const module = @"OFHTTPCookieManager"; @implementation TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests { void *pool = objc_autoreleasePoolPush(); OFHTTPCookieManager *manager = [OFHTTPCookieManager manager]; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | static OFString *const module = @"OFHTTPCookieManager"; @implementation TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests { void *pool = objc_autoreleasePoolPush(); OFHTTPCookieManager *manager = [OFHTTPCookieManager manager]; OFURI *URI1, *URI2, *URI3, *URI4; OFHTTPCookie *cookie1, *cookie2, *cookie3, *cookie4, *cookie5; URI1 = [OFURI URIWithString: @"http://nil.im/foo"]; URI2 = [OFURI URIWithString: @"https://nil.im/foo/bar"]; URI3 = [OFURI URIWithString: @"https://test.nil.im/foo/bar"]; URI4 = [OFURI URIWithString: @"http://webkeks.org/foo/bar"]; cookie1 = [OFHTTPCookie cookieWithName: @"test" value: @"1" domain: @"nil.im"]; TEST(@"-[addCookie:forURI:] #1", R([manager addCookie: cookie1 forURI: URI1])) TEST(@"-[cookiesForURI:] #1", [[manager cookiesForURI: URI1] isEqual: [OFArray arrayWithObject: cookie1]]) cookie2 = [OFHTTPCookie cookieWithName: @"test" value: @"2" domain: @"webkeks.org"]; TEST(@"-[addCookie:forURI:] #2", R([manager addCookie: cookie2 forURI: URI1])) TEST(@"-[cookiesForURI:] #2", [[manager cookiesForURI: URI1] isEqual: [OFArray arrayWithObject: cookie1]] && [[manager cookiesForURI: URI4] isEqual: [OFArray array]]) cookie3 = [OFHTTPCookie cookieWithName: @"test" value: @"3" domain: @"nil.im"]; cookie3.secure = true; TEST(@"-[addCookie:forURI:] #3", R([manager addCookie: cookie3 forURI: URI2])) TEST(@"-[cookiesForURI:] #3", [[manager cookiesForURI: URI2] isEqual: [OFArray arrayWithObject: cookie3]] && [[manager cookiesForURI: URI1] isEqual: [OFArray array]]) cookie3.expires = [OFDate dateWithTimeIntervalSinceNow: -1]; cookie4 = [OFHTTPCookie cookieWithName: @"test" value: @"4" domain: @"nil.im"]; cookie4.domain = @".nil.im"; TEST(@"-[addCookie:forURI:] #4", R([manager addCookie: cookie4 forURI: URI2])) TEST(@"-[cookiesForURI:] #4", [[manager cookiesForURI: URI2] isEqual: [OFArray arrayWithObject: cookie4]] && [[manager cookiesForURI: URI3] isEqual: [OFArray arrayWithObject: cookie4]]) cookie5 = [OFHTTPCookie cookieWithName: @"bar" value: @"5" domain: @"test.nil.im"]; TEST(@"-[addCookie:forURI:] #5", R([manager addCookie: cookie5 forURI: URI1])) TEST(@"-[cookiesForURI:] #5", [[manager cookiesForURI: URI1] isEqual: [OFArray arrayWithObject: cookie4]] && [[manager cookiesForURI: URI3] isEqual: [OFArray arrayWithObjects: cookie4, cookie5, nil]]) TEST(@"-[purgeExpiredCookies]", [manager.cookies isEqual: [OFArray arrayWithObjects: cookie3, cookie4, cookie5, nil]] && R([manager purgeExpiredCookies]) && [manager.cookies isEqual: |
︙ | ︙ |
Modified tests/OFHTTPCookieTests.m from [e2e55e8f73] to [beb8a32ced].
︙ | ︙ | |||
19 20 21 22 23 24 25 | static OFString *const module = @"OFHTTPCookie"; @implementation TestsAppDelegate (OFHTTPCookieTests) - (void)HTTPCookieTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | static OFString *const module = @"OFHTTPCookie"; @implementation TestsAppDelegate (OFHTTPCookieTests) - (void)HTTPCookieTests { void *pool = objc_autoreleasePoolPush(); OFURI *URI = [OFURI URIWithString: @"http://nil.im"]; OFHTTPCookie *cookie1, *cookie2; OFArray OF_GENERIC(OFHTTPCookie *) *cookies; cookie1 = [OFHTTPCookie cookieWithName: @"foo" value: @"bar" domain: @"nil.im"]; TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #1", [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar" forKey: @"Set-Cookie"] forURI: URI] isEqual: [OFArray arrayWithObject: cookie1]]) cookie2 = [OFHTTPCookie cookieWithName: @"qux" value: @"cookie" domain: @"nil.im"]; TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #2", [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar,qux=cookie" forKey: @"Set-Cookie"] forURI: URI] isEqual: [OFArray arrayWithObjects: cookie1, cookie2, nil]]) cookie1.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie2.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie1.path = @"/x"; cookie2.domain = @"webkeks.org"; cookie2.path = @"/objfw"; cookie2.secure = true; cookie2.HTTPOnly = true; [cookie2.extensions addObject: @"foo"]; [cookie2.extensions addObject: @"bar"]; TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #3", [(cookies = [OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar; Expires=Fri, 13 Feb 2009 23:31:30 GMT; Path=/x," @"qux=cookie; Expires=Fri, 13 Feb 2009 23:31:30 GMT; " @"Domain=webkeks.org; Path=/objfw; Secure; HTTPOnly; foo; bar" forKey: @"Set-Cookie"] forURI: URI]) isEqual: [OFArray arrayWithObjects: cookie1, cookie2, nil]]) TEST(@"+[requestHeaderFieldsWithCookies:]", [[OFHTTPCookie requestHeaderFieldsWithCookies: cookies] isEqual: [OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie" forKey: @"Cookie"]]) |
︙ | ︙ |
Modified tests/OFINIFileTests.m from [edfee9097f] to [18e2931d0e].
︙ | ︙ | |||
39 40 41 42 43 44 45 | @"[types]\r\n" @"integer=16\r\n" @"bool=false\r\n" @"float=0.25\r\n" @"array1=foo\r\n" @"array1=bar\r\n" @"double=0.75\r\n"; | | | | | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | @"[types]\r\n" @"integer=16\r\n" @"bool=false\r\n" @"float=0.25\r\n" @"array1=foo\r\n" @"array1=bar\r\n" @"double=0.75\r\n"; OFURI *URI; OFINIFile *file; OFINICategory *tests, *foobar, *types; OFArray *array; #if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) OFURI *writeURI; #endif module = @"OFINIFile"; URI = [OFURI URIWithString: @"embedded:testfile.ini"]; TEST(@"+[fileWithURI:encoding:]", (file = [OFINIFile fileWithURI: URI encoding: OFStringEncodingCodepage437])) tests = [file categoryForName: @"tests"]; foobar = [file categoryForName: @"foobar"]; types = [file categoryForName: @"types"]; TEST(@"-[categoryForName:]", tests != nil && foobar != nil && types != nil) |
︙ | ︙ | |||
112 113 114 115 116 117 118 | R([foobar removeValueForKey: @"quxqux "]) && R([types removeValueForKey: @"array2"])) module = @"OFINIFile"; /* FIXME: Find a way to write files on Nintendo DS */ #if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) | | | | | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | R([foobar removeValueForKey: @"quxqux "]) && R([types removeValueForKey: @"array2"])) module = @"OFINIFile"; /* FIXME: Find a way to write files on Nintendo DS */ #if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) writeURI = [[OFSystemInfo temporaryDirectoryURI] URIByAppendingPathComponent: @"objfw-tests.ini" isDirectory: false]; TEST(@"-[writeToFile:encoding:]", R([file writeToURI: writeURI encoding: OFStringEncodingCodepage437]) && [[OFString stringWithContentsOfURI: writeURI encoding: OFStringEncodingCodepage437] isEqual: output]) [[OFFileManager defaultManager] removeItemAtURI: writeURI]; #else (void)output; #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFLocaleTests.m from [08f116fb95] to [a51f4edb4e].
︙ | ︙ | |||
20 21 22 23 24 25 26 | @implementation TestsAppDelegate (OFLocaleTests) - (void)localeTests { void *pool = objc_autoreleasePoolPush(); [OFStdOut setForegroundColor: [OFColor lime]]; | | | | | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | @implementation TestsAppDelegate (OFLocaleTests) - (void)localeTests { void *pool = objc_autoreleasePoolPush(); [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeFormat: @"[OFLocale] Language code: %@\n", [OFLocale languageCode]]; [OFStdOut writeFormat: @"[OFLocale] Country code: %@\n", [OFLocale countryCode]]; [OFStdOut writeFormat: @"[OFLocale] Encoding: %@\n", OFStringEncodingName([OFLocale encoding])]; [OFStdOut writeFormat: @"[OFLocale] Decimal separator: %@\n", [OFLocale decimalSeparator]]; objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFMD5HashTests.m from [66b4d11501] to [5005b07061].
︙ | ︙ | |||
25 26 27 28 29 30 31 | "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; @implementation TestsAppDelegate (OFMD5HashTests) - (void)MD5HashTests { void *pool = objc_autoreleasePoolPush(); OFMD5Hash *MD5, *MD5Copy; | | | < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; @implementation TestsAppDelegate (OFMD5HashTests) - (void)MD5HashTests { void *pool = objc_autoreleasePoolPush(); OFMD5Hash *MD5, *MD5Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (MD5 = [OFMD5Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; |
︙ | ︙ |
Modified tests/OFMemoryStreamTests.m from [b4124576dd] to [14fae61fb2].
︙ | ︙ | |||
45 46 47 48 49 50 51 | memcmp(buffer, "fgh", 3) == 0 && [stream lowlevelReadIntoBuffer: buffer length: 10] == 5 && memcmp(buffer, "ijkl", 5) == 0) TEST(@"-[lowlevelIsAtEndOfStream]", [stream lowlevelIsAtEndOfStream]) TEST(@"-[lowlevelSeekToOffset:whence:]", | | | | | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | memcmp(buffer, "fgh", 3) == 0 && [stream lowlevelReadIntoBuffer: buffer length: 10] == 5 && memcmp(buffer, "ijkl", 5) == 0) TEST(@"-[lowlevelIsAtEndOfStream]", [stream lowlevelIsAtEndOfStream]) TEST(@"-[lowlevelSeekToOffset:whence:]", [stream lowlevelSeekToOffset: 0 whence: OFSeekCurrent] == sizeof(string) && [stream lowlevelIsAtEndOfStream] && [stream lowlevelSeekToOffset: 4 whence: OFSeekSet] == 4 && ![stream lowlevelIsAtEndOfStream] && [stream lowlevelReadIntoBuffer: buffer length: 10] == 9 && memcmp(buffer, "efghijkl", 9) == 0 && [stream lowlevelSeekToOffset: -2 whence: OFSeekEnd] == 11 && [stream lowlevelReadIntoBuffer: buffer length: 10] == 2 && memcmp(buffer, "l", 2) == 0 && [stream lowlevelReadIntoBuffer: buffer length: 10] == 0) EXPECT_EXCEPTION(@"Writes rejected on read-only stream", OFWriteFailedException, [stream lowlevelWriteBuffer: "" length: 1]) data = [OFMutableData dataWithCapacity: 13]; [data increaseCountBy: 13]; stream = [OFMemoryStream streamWithMemoryAddress: data.mutableItems size: data.count writable: true]; TEST(@"-[lowlevelWriteBuffer:length:]", [stream lowlevelWriteBuffer: "abcde" length: 5] == 5 && [stream lowlevelWriteBuffer: "fgh" length: 3] == 3 && [stream lowlevelWriteBuffer: "ijkl" length: 5] == 5 && memcmp(data.items, string, data.count) == 0 && [stream lowlevelSeekToOffset: -3 whence: OFSeekEnd] == 10) EXPECT_EXCEPTION(@"Out of bound writes rejected", OFWriteFailedException, [stream lowlevelWriteBuffer: "xyz" length: 4]) TEST(@"Partial write for too long write", memcmp(data.items, "abcdefghijxyz", 13) == 0) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFRIPEMD160HashTests.m from [d9eb71eb42] to [c46510efe0].
︙ | ︙ | |||
26 27 28 29 30 31 32 | "\xE6\x08\x8B"; @implementation TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests { void *pool = objc_autoreleasePoolPush(); OFRIPEMD160Hash *RIPEMD160, *RIPEMD160Copy; | | | < | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "\xE6\x08\x8B"; @implementation TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests { void *pool = objc_autoreleasePoolPush(); OFRIPEMD160Hash *RIPEMD160, *RIPEMD160Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (RIPEMD160 = [OFRIPEMD160Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; |
︙ | ︙ |
Modified tests/OFSHA1HashTests.m from [8dbe2b957f] to [76d8541713].
︙ | ︙ | |||
26 27 28 29 30 31 32 | "\x94\xE7\x17"; @implementation TestsAppDelegate (SHA1HashTests) - (void)SHA1HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA1Hash *SHA1, *SHA1Copy; | | | < | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "\x94\xE7\x17"; @implementation TestsAppDelegate (SHA1HashTests) - (void)SHA1HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA1Hash *SHA1, *SHA1Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA1 = [OFSHA1Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; |
︙ | ︙ |
Modified tests/OFSHA224HashTests.m from [3be83604b4] to [a723282b7a].
︙ | ︙ | |||
26 27 28 29 30 31 32 | "\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; @implementation TestsAppDelegate (SHA224HashTests) - (void)SHA224HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA224Hash *SHA224, *SHA224Copy; | | | < | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; @implementation TestsAppDelegate (SHA224HashTests) - (void)SHA224HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA224Hash *SHA224, *SHA224Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA224 = [OFSHA224Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; |
︙ | ︙ |
Modified tests/OFSHA256HashTests.m from [2658ed96c0] to [ea4a5936cb].
︙ | ︙ | |||
26 27 28 29 30 31 32 | "\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; @implementation TestsAppDelegate (SHA256HashTests) - (void)SHA256HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA256Hash *SHA256, *SHA256Copy; | | | < | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | "\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; @implementation TestsAppDelegate (SHA256HashTests) - (void)SHA256HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA256Hash *SHA256, *SHA256Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA256 = [OFSHA256Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; |
︙ | ︙ |
Modified tests/OFSHA384HashTests.m from [dd9d5ffdb4] to [4335e4cd7c].
︙ | ︙ | |||
27 28 29 30 31 32 33 | "\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; @implementation TestsAppDelegate (SHA384HashTests) - (void)SHA384HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA384Hash *SHA384, *SHA384Copy; | | | < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | "\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; @implementation TestsAppDelegate (SHA384HashTests) - (void)SHA384HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA384Hash *SHA384, *SHA384Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA384 = [OFSHA384Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[128]; size_t length = [file readIntoBuffer: buffer length: 128]; |
︙ | ︙ |
Modified tests/OFSHA512HashTests.m from [759fed7ea6] to [9748b0700b].
︙ | ︙ | |||
28 29 30 31 32 33 34 | "\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; @implementation TestsAppDelegate (SHA512HashTests) - (void)SHA512HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA512Hash *SHA512, *SHA512Copy; | | | < | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | "\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; @implementation TestsAppDelegate (SHA512HashTests) - (void)SHA512HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA512Hash *SHA512, *SHA512Copy; OFURI *URI = [OFURI URIWithString: @"embedded:testfile.bin"]; OFStream *file = [OFURIHandler openItemAtURI: URI mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA512 = [OFSHA512Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[128]; size_t length = [file readIntoBuffer: buffer length: 128]; |
︙ | ︙ |
Modified tests/OFSPXSocketTests.m from [2f53dc9a06] to [c95d72f728].
︙ | ︙ | |||
165 166 167 168 169 170 171 | port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) | | | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveKernelEventsFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[asyncAccept] & " @"-[asyncConnectToNetwork:node:port:]: select() " @"not supported for SPX, skipping test"]; |
︙ | ︙ |
Modified tests/OFSPXStreamSocketTests.m from [7313f54116] to [af4ba0ff2c].
︙ | ︙ | |||
92 93 94 95 96 97 98 99 100 101 102 103 104 105 | case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; | > | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: case EPROTONOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; |
︙ | ︙ | |||
168 169 170 171 172 173 174 | port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) | | | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveKernelEventsFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[asyncAccept] & " @"-[asyncConnectToNetwork:node:port:]: select() " @"not supported for SPX, skipping test"]; |
︙ | ︙ |
Modified tests/OFSerializationTests.m from [8a1b6d269b] to [d36329ce8f].
︙ | ︙ | |||
37 38 39 40 41 42 43 | [array addObject: [OFDate dateWithTimeIntervalSince1970: 1234.5678]]; [dict setObject: @"Hello" forKey: array]; [dict setObject: @"B\"la" forKey: @"Blub"]; [list appendObject: @"Hello"]; [list appendObject: @"Wo\rld!\nHow are you?"]; | | | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | [array addObject: [OFDate dateWithTimeIntervalSince1970: 1234.5678]]; [dict setObject: @"Hello" forKey: array]; [dict setObject: @"B\"la" forKey: @"Blub"]; [list appendObject: @"Hello"]; [list appendObject: @"Wo\rld!\nHow are you?"]; [list appendObject: [OFURI URIWithString: @"https://objfw.nil.im/"]]; [list appendObject: [OFXMLElement elementWithXMLString: @"<x><y/><![CDATA[<]]></x>"]]; [list appendObject: [OFSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [list appendObject: [OFCountedSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [dict setObject: @"list" forKey: list]; data = [OFData dataWithItems: "0123456789:;<ABCDEFGHJIKLMNOPQRSTUVWXYZ" count: 39]; [dict setObject: @"data" forKey: data]; UUID = [OFUUID UUIDWithUUIDString: @"01234567-89AB-CDEF-FEDC-BA9876543210"]; [dict setObject: @"uuid" forKey: UUID]; TEST(@"-[stringBySerializing]", (string = dict.stringBySerializing) && [string isEqual: [OFString stringWithContentsOfURI: [OFURI URIWithString: @"embedded:serialization.xml"]]]) TEST(@"-[objectByDeserializing]", [string.objectByDeserializing isEqual: dict]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFStringTests.m from [bed905834b] to [10adf25aaa].
︙ | ︙ | |||
290 291 292 293 294 295 296 | [mutableString1 characterAtIndex: 1] == 0xE4 && [mutableString1 characterAtIndex: 3] == 0x20AC && [mutableString1 characterAtIndex: 5] == 0x1D11E) EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]", OFOutOfRangeException, [mutableString1 characterAtIndex: 7]) | < < < | | | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | [mutableString1 characterAtIndex: 1] == 0xE4 && [mutableString1 characterAtIndex: 3] == 0x20AC && [mutableString1 characterAtIndex: 5] == 0x1D11E) EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]", OFOutOfRangeException, [mutableString1 characterAtIndex: 7]) mutableString2 = [mutableStringClass stringWithString: @"abc"]; #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"TÄS€1𝄞3"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) TEST(@"-[lowercase]", R([mutableString1 lowercase]) && [mutableString1 isEqual: @"täs€1𝄞3"] && R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"]) TEST(@"-[uppercaseString]", [[mutableString1 uppercaseString] isEqual: @"TÄS€1𝄞3"]) TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) && [[mutableString1 lowercaseString] isEqual: @"täs€1𝄞3"]) TEST(@"-[capitalizedString]", [C(@"džbla tdžst TDŽST").capitalizedString isEqual: @"Džbla Tdžst Tdžst"]) #else TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"3𝄞1€SäT"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) |
︙ | ︙ | |||
356 357 358 359 360 361 362 | #ifdef OF_HAVE_FILES TEST(@"+[stringWithContentsOfFile:encoding]", (string = [stringClass stringWithContentsOfFile: @"testfile.txt" encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) | | | | 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | #ifdef OF_HAVE_FILES TEST(@"+[stringWithContentsOfFile:encoding]", (string = [stringClass stringWithContentsOfFile: @"testfile.txt" encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) TEST(@"+[stringWithContentsOfURI:encoding]", (string = [stringClass stringWithContentsOfURI: [OFURI fileURIWithPath: @"testfile.txt"] encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) #endif TEST(@"-[appendUTFString:length:]", R([mutableString1 appendUTF8String: "\xEF\xBB\xBF" "barqux" length: 6]) && |
︙ | ︙ | |||
505 506 507 508 509 510 511 | options: OFStringSearchBackwards].location == 0 && [C(@"𝄞öö") rangeOfString: @"x" options: OFStringSearchBackwards].location == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[rangeOfString:options:range:]", OFOutOfRangeException, | | | | | | | | | < < < | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 | options: OFStringSearchBackwards].location == 0 && [C(@"𝄞öö") rangeOfString: @"x" options: OFStringSearchBackwards].location == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[rangeOfString:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFMakeRange(3, 1)]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; TEST(@"-[indexOfCharacterFromSet:]", [C(@"abcđabcđe") indexOfCharacterFromSet: characterSet] == 2 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: OFStringSearchBackwards] == 7 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(4, 4)] == 6 && [C(@"abcđabcđëf") indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(8, 2)] == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[indexOfCharacterFromSet:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") indexOfCharacterFromSet: characterSet options: 0 range: OFMakeRange(3, 1)]) TEST(@"-[substringWithRange:]", [[C(@"𝄞öö") substringWithRange: OFMakeRange(1, 1)] isEqual: @"ö"] && [[C(@"𝄞öö") substringWithRange: OFMakeRange(3, 0)] isEqual: @""]) EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1", OFOutOfRangeException, [C(@"𝄞öö") substringWithRange: OFMakeRange(2, 2)]) EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2", OFOutOfRangeException, [C(@"𝄞öö") substringWithRange: OFMakeRange(4, 0)]) TEST(@"-[stringByAppendingString:]", [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"]) #ifdef OF_HAVE_FILES # if defined(OF_WINDOWS) TEST(@"-[isAbsolutePath]", C(@"C:\\foo").absolutePath && C(@"a:/foo").absolutePath && !C(@"foo").absolutePath && !C(@"b:foo").absolutePath && C(@"\\\\foo").absolutePath) # elif defined(OF_MSDOS) |
︙ | ︙ | |||
600 601 602 603 604 605 606 607 608 609 610 611 612 613 | TEST(@"-[stringByAppendingPathExtension:]", [[C(@"foo") stringByAppendingPathExtension: @"bar"] isEqual: @"foo.bar"] && [[C(@"c:\\tmp\\foo") stringByAppendingPathExtension: @"bar"] isEqual: @"c:\\tmp\\foo.bar"] && [[C(@"c:\\tmp\\/\\") stringByAppendingPathExtension: @"bar"] isEqual: @"c:\\tmp.bar"]) # else TEST(@"-[stringByAppendingPathExtension:]", [[C(@"foo") stringByAppendingPathExtension: @"bar"] isEqual: @"foo.bar"] && [[C(@"foo/bar") stringByAppendingPathExtension: @"baz"] isEqual: @"foo/bar.baz"] && [[C(@"foo///") stringByAppendingPathExtension: @"bar"] | > > > > > > | 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | TEST(@"-[stringByAppendingPathExtension:]", [[C(@"foo") stringByAppendingPathExtension: @"bar"] isEqual: @"foo.bar"] && [[C(@"c:\\tmp\\foo") stringByAppendingPathExtension: @"bar"] isEqual: @"c:\\tmp\\foo.bar"] && [[C(@"c:\\tmp\\/\\") stringByAppendingPathExtension: @"bar"] isEqual: @"c:\\tmp.bar"]) # elif defined(OF_AMIGAOS) TEST(@"-[stringByAppendingPathExtension:]", [[C(@"foo") stringByAppendingPathExtension: @"bar"] isEqual: @"foo.bar"] && [[C(@"foo/bar") stringByAppendingPathExtension: @"baz"] isEqual: @"foo/bar.baz"]) # else TEST(@"-[stringByAppendingPathExtension:]", [[C(@"foo") stringByAppendingPathExtension: @"bar"] isEqual: @"foo.bar"] && [[C(@"foo/bar") stringByAppendingPathExtension: @"baz"] isEqual: @"foo/bar.baz"] && [[C(@"foo///") stringByAppendingPathExtension: @"bar"] |
︙ | ︙ | |||
1273 1274 1275 1276 1277 1278 1279 | TEST(@"-[stringBySHA512Hashing]", [C(@"asdfoobar").stringBySHA512Hashing isEqual: @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56" @"412a9247c3579a329e53a5dc74676b106755e3394f9454a2d4227324" @"2615d32f80437d61"]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"abfo'_~$🍏"]; | | | > | | | | > | | | > | | | | | | | | | | | | | 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 | TEST(@"-[stringBySHA512Hashing]", [C(@"asdfoobar").stringBySHA512Hashing isEqual: @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56" @"412a9247c3579a329e53a5dc74676b106755e3394f9454a2d4227324" @"2615d32f80437d61"]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"abfo'_~$🍏"]; TEST(@"-[stringByAddingPercentEncodingWithAllowedCharacters:]", [[C(@"foo\"ba'_~$]🍏🍌") stringByAddingPercentEncodingWithAllowedCharacters: characterSet] isEqual: @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"]) TEST(@"-[stringByRemovingPercentEncoding]", [C(@"foo%20bar%22+%24%F0%9F%8D%8C").stringByRemovingPercentEncoding isEqual: @"foo bar\"+$🍌"]) TEST(@"-[insertString:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 insertString: @"äöü" atIndex: 3]) && [mutableString1 isEqual: @"𝄞ööäöüöbä€"]) EXPECT_EXCEPTION(@"Detect invalid format in " @"-[stringByRemovingPercentEncoding] #1", OFInvalidFormatException, [C(@"foo%xbar") stringByRemovingPercentEncoding]) EXPECT_EXCEPTION(@"Detect invalid encoding in " @"-[stringByRemovingPercentEncoding] #2", OFInvalidEncodingException, [C(@"foo%FFbar") stringByRemovingPercentEncoding]) TEST(@"-[setCharacter:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"abäde"]) && R([mutableString1 setCharacter: 0xF6 atIndex: 2]) && [mutableString1 isEqual: @"aböde"] && R([mutableString1 setCharacter: 'c' atIndex: 2]) && [mutableString1 isEqual: @"abcde"] && R([mutableString1 setCharacter: 0x20AC atIndex: 3]) && [mutableString1 isEqual: @"abc€e"] && R([mutableString1 setCharacter: 'x' atIndex: 1]) && [mutableString1 isEqual: @"axc€e"]) TEST(@"-[deleteCharactersInRange:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 deleteCharactersInRange: OFMakeRange(1, 3)]) && [mutableString1 isEqual: @"𝄞bä€"] && R([mutableString1 deleteCharactersInRange: OFMakeRange(0, 4)]) && [mutableString1 isEqual: @""]) TEST(@"-[replaceCharactersInRange:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 replaceCharactersInRange: OFMakeRange(1, 3) withString: @"äöüß"]) && [mutableString1 isEqual: @"𝄞äöüßbä€"] && R([mutableString1 replaceCharactersInRange: OFMakeRange(4, 2) withString: @"b"]) && [mutableString1 isEqual: @"𝄞äöübä€"] && R([mutableString1 replaceCharactersInRange: OFMakeRange(0, 7) withString: @""]) && [mutableString1 isEqual: @""]) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1", OFOutOfRangeException, { mutableString1 = [mutableStringClass stringWithString: @"𝄞öö"]; [mutableString1 deleteCharactersInRange: OFMakeRange(2, 2)]; }) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2", OFOutOfRangeException, [mutableString1 deleteCharactersInRange: OFMakeRange(4, 0)]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #1", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFMakeRange(2, 2) withString: @""]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #2", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFMakeRange(4, 0) withString: @""]) TEST(@"-[replaceOccurrencesOfString:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"asd fo asd fofo asd"]) && R([mutableString1 replaceOccurrencesOfString: @"fo" withString: @"foo"]) && [mutableString1 isEqual: @"asd foo asd foofoo asd"] && (mutableString1 = [mutableStringClass stringWithString: @"XX"]) && R([mutableString1 replaceOccurrencesOfString: @"X" withString: @"XX"]) && [mutableString1 isEqual: @"XXXX"]) TEST(@"-[replaceOccurrencesOfString:withString:options:range:]", (mutableString1 = [mutableStringClass stringWithString: @"foofoobarfoobarfoo"]) && R([mutableString1 replaceOccurrencesOfString: @"oo" withString: @"óò" options: 0 range: OFMakeRange(2, 15)]) && [mutableString1 isEqual: @"foofóòbarfóòbarfoo"]) TEST(@"-[deleteLeadingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteLeadingWhitespaces]) && [mutableString1 isEqual: @"asd \t \t\t\r\n"] && |
︙ | ︙ |
Modified tests/OFSystemInfoTests.m from [79401c47ef] to [5b9edfd152].
︙ | ︙ | |||
42 43 44 45 46 47 48 | [OFStdOut writeFormat: @"[OFSystemInfo] Operating system name: %@\n", [OFSystemInfo operatingSystemName]]; [OFStdOut writeFormat: @"[OFSystemInfo] Operating system version: %@\n", [OFSystemInfo operatingSystemVersion]]; | | | | | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | [OFStdOut writeFormat: @"[OFSystemInfo] Operating system name: %@\n", [OFSystemInfo operatingSystemName]]; [OFStdOut writeFormat: @"[OFSystemInfo] Operating system version: %@\n", [OFSystemInfo operatingSystemVersion]]; [OFStdOut writeFormat: @"[OFSystemInfo] User config URI: %@\n", [OFSystemInfo userConfigURI].string]; [OFStdOut writeFormat: @"[OFSystemInfo] User data URI: %@\n", [OFSystemInfo userDataURI].string]; [OFStdOut writeFormat: @"[OFSystemInfo] Temporary directory URI: %@\n", [OFSystemInfo temporaryDirectoryURI].string]; [OFStdOut writeFormat: @"[OFSystemInfo] CPU vendor: %@\n", [OFSystemInfo CPUVendor]]; [OFStdOut writeFormat: @"[OFSystemInfo] CPU model: %@\n", [OFSystemInfo CPUModel]]; |
︙ | ︙ |
Modified tests/OFUNIXDatagramSocketTests.m from [54c71e4e91] to [54df3210f6].
︙ | ︙ | |||
27 28 29 30 31 32 33 | void *pool = objc_autoreleasePoolPush(); OFString *path; OFUNIXDatagramSocket *sock; OFSocketAddress address1, address2; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) | | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | void *pool = objc_autoreleasePoolPush(); OFString *path; OFUNIXDatagramSocket *sock; OFSocketAddress address1, address2; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryURI] URIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectoryURI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif TEST(@"+[socket]", (sock = [OFUNIXDatagramSocket socket])) |
︙ | ︙ |
Modified tests/OFUNIXStreamSocketTests.m from [d4ca26b9c4] to [72ce4faa3f].
︙ | ︙ | |||
26 27 28 29 30 31 32 | { void *pool = objc_autoreleasePoolPush(); OFString *path; OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) | | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | { void *pool = objc_autoreleasePoolPush(); OFString *path; OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryURI] URIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectoryURI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif TEST(@"+[socket]", (sockClient = [OFUNIXStreamSocket socket]) && |
︙ | ︙ |
Renamed and modified tests/OFURLTests.m [e63dcbf6b8] to tests/OFURITests.m [e9cb46977b].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | > | | | | | | | | | | > > > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | | > > > > > > | > | > | > | | | > | | > | | > > > | | | | | | | | | > | | | | | > > | | | | | | < < < < < < < < | | | | | | | | | | | | | | | | | > | | > > | | | > | | | | | | | | > | | > | | | | | | | > | | | | | > | | > | | | | | | | > | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFURI"; static OFString *URIString = @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/" @"pa%3Fth?que%23ry=1&f%26oo=b%3dar#frag%23ment"; @implementation TestsAppDelegate (OFURITests) - (void)URITests { void *pool = objc_autoreleasePoolPush(); OFURI *URI1, *URI2, *URI3, *URI4, *URI5, *URI6, *URI7, *URI8, *URI9; OFURI *URI10; OFMutableURI *mutableURI; TEST(@"+[URIWithString:]", R(URI1 = [OFURI URIWithString: URIString]) && R(URI2 = [OFURI URIWithString: @"http://foo:80"]) && R(URI3 = [OFURI URIWithString: @"http://bar/"]) && R(URI4 = [OFURI URIWithString: @"file:///etc/passwd"]) && R(URI5 = [OFURI URIWithString: @"http://foo/bar/qux/foo%2fbar"]) && R(URI6 = [OFURI URIWithString: @"https://[12:34::56:abcd]/"]) && R(URI7 = [OFURI URIWithString: @"https://[12:34::56:abcd]:234/"]) && R(URI8 = [OFURI URIWithString: @"urn:qux:foo"]) && R(URI9 = [OFURI URIWithString: @"file:/foo?query#frag"]) && R(URI10 = [OFURI URIWithString: @"file:foo@bar/qux?query#frag"])) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #1", OFInvalidFormatException, [OFURI URIWithString: @"ht,tp://foo"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #2", OFInvalidFormatException, [OFURI URIWithString: @"http://f`oo"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #3", OFInvalidFormatException, [OFURI URIWithString: @"http://foo/`"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #4", OFInvalidFormatException, [OFURI URIWithString: @"http://foo/foo?`"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #5", OFInvalidFormatException, [OFURI URIWithString: @"http://foo/foo?foo#`"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #6", OFInvalidFormatException, [OFURI URIWithString: @"https://[g]/"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #7", OFInvalidFormatException, [OFURI URIWithString: @"https://[f]:/"]) EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #8", OFInvalidFormatException, [OFURI URIWithString: @"https://[f]:f/"]) TEST(@"+[URIWithString:relativeToURI:]", [[[OFURI URIWithString: @"/foo" relativeToURI: URI1] string] isEqual: @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/foo"] && [[[OFURI URIWithString: @"foo/bar?q" relativeToURI: [OFURI URIWithString: @"http://h/qux/quux"]] string] isEqual: @"http://h/qux/foo/bar?q"] && [[[OFURI URIWithString: @"foo/bar" relativeToURI: [OFURI URIWithString: @"http://h/qux/?x"]] string] isEqual: @"http://h/qux/foo/bar"] && [[[OFURI URIWithString: @"http://foo/?q" relativeToURI: URI1] string] isEqual: @"http://foo/?q"] && [[[OFURI URIWithString: @"foo" relativeToURI: [OFURI URIWithString: @"http://foo/bar"]] string] isEqual: @"http://foo/foo"] && [[[OFURI URIWithString: @"foo" relativeToURI: [OFURI URIWithString: @"http://foo"]] string] isEqual: @"http://foo/foo"]) EXPECT_EXCEPTION( @"+[URIWithString:relativeToURI:] fails with invalid characters #1", OFInvalidFormatException, [OFURI URIWithString: @"`" relativeToURI: URI1]) EXPECT_EXCEPTION( @"+[URIWithString:relativeToURI:] fails with invalid characters #2", OFInvalidFormatException, [OFURI URIWithString: @"/`" relativeToURI: URI1]) EXPECT_EXCEPTION( @"+[URIWithString:relativeToURI:] fails with invalid characters #3", OFInvalidFormatException, [OFURI URIWithString: @"?`" relativeToURI: URI1]) EXPECT_EXCEPTION( @"+[URIWithString:relativeToURI:] fails with invalid characters #4", OFInvalidFormatException, [OFURI URIWithString: @"#`" relativeToURI: URI1]) #ifdef OF_HAVE_FILES TEST(@"+[fileURIWithPath:]", [[[OFURI fileURIWithPath: @"testfile.txt"] fileSystemRepresentation] isEqual: [[OFFileManager defaultManager].currentDirectoryPath stringByAppendingPathComponent: @"testfile.txt"]]) # if defined(OF_WINDOWS) || defined(OF_MSDOS) OFURI *tmp; TEST(@"+[fileURIWithPath:] for c:\\", (tmp = [OFURI fileURIWithPath: @"c:\\"]) && [tmp.string isEqual: @"file:/c:/"] && [tmp.fileSystemRepresentation isEqual: @"c:\\"]) # endif # ifdef OF_WINDOWS TEST(@"+[fileURIWithPath:] with UNC", (tmp = [OFURI fileURIWithPath: @"\\\\foo\\bar" isDirectory: false]) && [tmp.host isEqual: @"foo"] && [tmp.path isEqual: @"/bar"] && [tmp.string isEqual: @"file://foo/bar"] && [tmp.fileSystemRepresentation isEqual: @"\\\\foo\\bar"] && (tmp = [OFURI fileURIWithPath: @"\\\\test" isDirectory: true]) && [tmp.host isEqual: @"test"] && [tmp.path isEqual: @"/"] && [tmp.string isEqual: @"file://test/"] && [tmp.fileSystemRepresentation isEqual: @"\\\\test"]) # endif #endif TEST(@"-[string]", [URI1.string isEqual: URIString] && [URI2.string isEqual: @"http://foo:80"] && [URI3.string isEqual: @"http://bar/"] && [URI4.string isEqual: @"file:///etc/passwd"] && [URI5.string isEqual: @"http://foo/bar/qux/foo%2fbar"] && [URI6.string isEqual: @"https://[12:34::56:abcd]/"] && [URI7.string isEqual: @"https://[12:34::56:abcd]:234/"] && [URI8.string isEqual: @"urn:qux:foo"] && [URI9.string isEqual: @"file:/foo?query#frag"] && [URI10.string isEqual: @"file:foo@bar/qux?query#frag"]) TEST(@"-[scheme]", [URI1.scheme isEqual: @"ht+tp"] && [URI4.scheme isEqual: @"file"] && [URI9.scheme isEqual: @"file"] && [URI10.scheme isEqual: @"file"]) TEST(@"-[user]", [URI1.user isEqual: @"us:er"] && URI4.user == nil && URI10.user == nil) TEST(@"-[password]", [URI1.password isEqual: @"p@w"] && URI4.password == nil && URI10.password == nil) TEST(@"-[host]", [URI1.host isEqual: @"ho:st"] && [URI6.host isEqual: @"12:34::56:abcd"] && [URI7.host isEqual: @"12:34::56:abcd"] && URI8.host == nil && URI9.host == nil && URI10.host == nil) TEST(@"-[port]", URI1.port.unsignedShortValue == 1234 && [URI4 port] == nil && URI7.port.unsignedShortValue == 234 && URI8.port == nil && URI9.port == nil && URI10.port == nil) TEST(@"-[path]", [URI1.path isEqual: @"/pa?th"] && [URI4.path isEqual: @"/etc/passwd"] && [URI8.path isEqual: @"qux:foo"] && [URI9.path isEqual: @"/foo"] && [URI10.path isEqual: @"foo@bar/qux"]) TEST(@"-[pathComponents]", [URI1.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"pa?th", nil]] && [URI4.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"etc", @"passwd", nil]] && [URI5.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"bar", @"qux", @"foo/bar", nil]]) TEST(@"-[lastPathComponent]", [[[OFURI URIWithString: @"http://host/foo//bar/baz"] lastPathComponent] isEqual: @"baz"] && [[[OFURI URIWithString: @"http://host/foo//bar/baz/"] lastPathComponent] isEqual: @"baz"] && [[[OFURI URIWithString: @"http://host/foo/"] lastPathComponent] isEqual: @"foo"] && [[[OFURI URIWithString: @"http://host/"] lastPathComponent] isEqual: @"/"] && [URI5.lastPathComponent isEqual: @"foo/bar"]) TEST(@"-[query]", [URI1.query isEqual: @"que#ry=1&f&oo=b=ar"] && URI4.query == nil && [URI9.query isEqual: @"query"] && [URI10.query isEqual: @"query"]) TEST(@"-[queryItems]", [URI1.queryItems isEqual: [OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"que#ry" secondObject: @"1"], [OFPair pairWithFirstObject: @"f&oo" secondObject: @"b=ar"], nil]]); TEST(@"-[fragment]", [URI1.fragment isEqual: @"frag#ment"] && URI4.fragment == nil && [URI9.fragment isEqual: @"frag"] && [URI10.fragment isEqual: @"frag"]) TEST(@"-[copy]", R(URI4 = [[URI1 copy] autorelease])) TEST(@"-[isEqual:]", [URI1 isEqual: URI4] && ![URI2 isEqual: URI3] && [[OFURI URIWithString: @"HTTP://bar/"] isEqual: URI3]) TEST(@"-[hash:]", URI1.hash == URI4.hash && URI2.hash != URI3.hash) EXPECT_EXCEPTION(@"Detection of invalid format", OFInvalidFormatException, [OFURI URIWithString: @"http"]) mutableURI = [OFMutableURI URIWithScheme: @"dummy"]; EXPECT_EXCEPTION( @"-[setPercentEncodedScheme:] with invalid characters fails", OFInvalidFormatException, mutableURI.scheme = @"%20") TEST(@"-[setHost:]", (mutableURI.host = @"ho:st") && [mutableURI.percentEncodedHost isEqual: @"ho%3Ast"] && (mutableURI.host = @"12:34:ab") && [mutableURI.percentEncodedHost isEqual: @"[12:34:ab]"] && (mutableURI.host = @"12:34:aB") && [mutableURI.percentEncodedHost isEqual: @"[12:34:aB]"] && (mutableURI.host = @"12:34:g") && [mutableURI.percentEncodedHost isEqual: @"12%3A34%3Ag"]) TEST(@"-[setPercentEncodedHost:]", (mutableURI.percentEncodedHost = @"ho%3Ast") && [mutableURI.host isEqual: @"ho:st"] && (mutableURI.percentEncodedHost = @"[12:34]") && [mutableURI.host isEqual: @"12:34"] && (mutableURI.percentEncodedHost = @"[12::ab]") && [mutableURI.host isEqual: @"12::ab"]) EXPECT_EXCEPTION( @"-[setPercentEncodedHost:] with invalid characters fails #1", OFInvalidFormatException, mutableURI.percentEncodedHost = @"/") EXPECT_EXCEPTION( @"-[setPercentEncodedHost:] with invalid characters fails #2", OFInvalidFormatException, mutableURI.percentEncodedHost = @"[12:34") EXPECT_EXCEPTION( @"-[setPercentEncodedHost:] with invalid characters fails #3", OFInvalidFormatException, mutableURI.percentEncodedHost = @"[a::g]") TEST(@"-[setUser:]", (mutableURI.user = @"us:er") && [mutableURI.percentEncodedUser isEqual: @"us%3Aer"]) TEST(@"-[setPercentEncodedUser:]", (mutableURI.percentEncodedUser = @"us%3Aer") && [mutableURI.user isEqual: @"us:er"]) EXPECT_EXCEPTION( @"-[setPercentEncodedUser:] with invalid characters fails", OFInvalidFormatException, mutableURI.percentEncodedHost = @"/") TEST(@"-[setPassword:]", (mutableURI.password = @"pass:word") && [mutableURI.percentEncodedPassword isEqual: @"pass%3Aword"]) TEST(@"-[setPercentEncodedPassword:]", (mutableURI.percentEncodedPassword = @"pass%3Aword") && [mutableURI.password isEqual: @"pass:word"]) EXPECT_EXCEPTION( @"-[setPercentEncodedPassword:] with invalid characters fails", OFInvalidFormatException, mutableURI.percentEncodedPassword = @"/") TEST(@"-[setPath:]", (mutableURI.path = @"pa/th@?") && [mutableURI.percentEncodedPath isEqual: @"pa/th@%3F"]) TEST(@"-[setPercentEncodedPath:]", (mutableURI.percentEncodedPath = @"pa/th@%3F") && [mutableURI.path isEqual: @"pa/th@?"]) EXPECT_EXCEPTION( @"-[setPercentEncodedPath:] with invalid characters fails", OFInvalidFormatException, mutableURI.percentEncodedPath = @"?") TEST(@"-[setQuery:]", (mutableURI.query = @"que/ry?#") && [mutableURI.percentEncodedQuery isEqual: @"que/ry?%23"]) TEST(@"-[setPercentEncodedQuery:]", (mutableURI.percentEncodedQuery = @"que/ry?%23") && [mutableURI.query isEqual: @"que/ry?#"]) EXPECT_EXCEPTION( @"-[setPercentEncodedQuery:] with invalid characters fails", OFInvalidFormatException, mutableURI.percentEncodedQuery = @"`") TEST(@"-[setQueryItems:]", (mutableURI.queryItems = [OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"foo&bar" secondObject: @"baz=qux"], [OFPair pairWithFirstObject: @"f=oobar" secondObject: @"b&azqux"], nil]) && [mutableURI.percentEncodedQuery isEqual: @"foo%26bar=baz%3Dqux&f%3Doobar=b%26azqux"]) TEST(@"-[setFragment:]", (mutableURI.fragment = @"frag/ment?#") && [mutableURI.percentEncodedFragment isEqual: @"frag/ment?%23"]) TEST(@"-[setPercentEncodedFragment:]", (mutableURI.percentEncodedFragment = @"frag/ment?%23") && [mutableURI.fragment isEqual: @"frag/ment?#"]) EXPECT_EXCEPTION( @"-[setPercentEncodedFragment:] with invalid characters fails", OFInvalidFormatException, mutableURI.percentEncodedFragment = @"`") TEST(@"-[URIByAppendingPathComponent:isDirectory:]", [[[OFURI URIWithString: @"file:///foo/bar"] URIByAppendingPathComponent: @"qux" isDirectory: false] isEqual: [OFURI URIWithString: @"file:///foo/bar/qux"]] && [[[OFURI URIWithString: @"file:///foo/bar/"] URIByAppendingPathComponent: @"qux" isDirectory: false] isEqual: [OFURI URIWithString: @"file:///foo/bar/qux"]] && [[[OFURI URIWithString: @"file:///foo/bar/"] URIByAppendingPathComponent: @"qu?x" isDirectory: false] isEqual: [OFURI URIWithString: @"file:///foo/bar/qu%3Fx"]] && [[[OFURI URIWithString: @"file:///foo/bar/"] URIByAppendingPathComponent: @"qu?x" isDirectory: true] isEqual: [OFURI URIWithString: @"file:///foo/bar/qu%3Fx/"]]) TEST(@"-[URIByStandardizingPath]", [[[OFURI URIWithString: @"http://foo/bar/.."] URIByStandardizingPath] isEqual: [OFURI URIWithString: @"http://foo/"]] && [[[OFURI URIWithString: @"http://foo/bar/%2E%2E/../qux/"] URIByStandardizingPath] isEqual: [OFURI URIWithString: @"http://foo/bar/qux/"]] && [[[OFURI URIWithString: @"http://foo/bar/./././qux/./"] URIByStandardizingPath] isEqual: [OFURI URIWithString: @"http://foo/bar/qux/"]] && [[[OFURI URIWithString: @"http://foo/bar/../../qux"] URIByStandardizingPath] isEqual: [OFURI URIWithString: @"http://foo/../qux"]]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFValueTests.m from [545d0b4ed0] to [f614b296d4].
︙ | ︙ | |||
21 22 23 24 25 26 27 | static OFString *const module = @"OFValue"; @implementation TestsAppDelegate (OFValueTests) - (void)valueTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | static OFString *const module = @"OFValue"; @implementation TestsAppDelegate (OFValueTests) - (void)valueTests { void *pool = objc_autoreleasePoolPush(); OFRange range = OFMakeRange(1, 64), range2; OFPoint point = OFMakePoint(1.5f, 3.0f), point2; OFSize size = OFMakeSize(4.5f, 5.0f), size2; OFRect rect = OFMakeRect(1.5f, 3.0f, 4.5f, 6.0f), rect2; OFValue *value; void *pointer = &value; TEST(@"+[valueWithBytes:objCType:]", (value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)])) TEST(@"-[objCType]", strcmp(value.objCType, @encode(OFRange)) == 0) TEST(@"-[getValue:size:]", R([value getValue: &range2 size: sizeof(OFRange)]) && OFEqualRanges(range2, range)) EXPECT_EXCEPTION(@"-[getValue:size:] with wrong size throws", OFOutOfRangeException, [value getValue: &range size: sizeof(OFRange) - 1]) TEST(@"+[valueWithPointer:]", (value = [OFValue valueWithPointer: pointer])) |
︙ | ︙ | |||
72 73 74 75 76 77 78 | [[OFValue valueWithBytes: "a" objCType: @encode(char)] nonretainedObjectValue]) TEST(@"+[valueWithRange:]", (value = [OFValue valueWithRange: range])) TEST(@"-[rangeValue]", | | | | | | | | | | | | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | [[OFValue valueWithBytes: "a" objCType: @encode(char)] nonretainedObjectValue]) TEST(@"+[valueWithRange:]", (value = [OFValue valueWithRange: range])) TEST(@"-[rangeValue]", OFEqualRanges(value.rangeValue, range) && (value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)]) && OFEqualRanges(value.rangeValue, range)) TEST(@"-[getValue:size:] for OFRangeValue", (value = [OFValue valueWithRange: range]) && R([value getValue: &range2 size: sizeof(range2)]) && OFEqualRanges(range2, range)) EXPECT_EXCEPTION(@"-[rangeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] rangeValue]) TEST(@"+[valueWithPoint:]", (value = [OFValue valueWithPoint: point])) TEST(@"-[pointValue]", OFEqualPoints(value.pointValue, point) && (value = [OFValue valueWithBytes: &point objCType: @encode(OFPoint)]) && OFEqualPoints(value.pointValue, point)) TEST(@"-[getValue:size:] for OFPointValue", (value = [OFValue valueWithPoint: point]) && R([value getValue: &point2 size: sizeof(point2)]) && OFEqualPoints(point2, point)) EXPECT_EXCEPTION(@"-[pointValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] pointValue]) TEST(@"+[valueWithSize:]", (value = [OFValue valueWithSize: size])) TEST(@"-[sizeValue]", OFEqualSizes(value.sizeValue, size) && (value = [OFValue valueWithBytes: &size objCType: @encode(OFSize)]) && OFEqualSizes(value.sizeValue, size)) TEST(@"-[getValue:size:] for OFSizeValue", (value = [OFValue valueWithSize: size]) && R([value getValue: &size2 size: sizeof(size2)]) && OFEqualSizes(size2, size)) EXPECT_EXCEPTION(@"-[sizeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] sizeValue]) TEST(@"+[valueWithRect:]", (value = [OFValue valueWithRect: rect])) TEST(@"-[rectValue]", OFEqualRects(value.rectValue, rect) && (value = [OFValue valueWithBytes: &rect objCType: @encode(OFRect)]) && OFEqualRects(value.rectValue, rect)) TEST(@"-[getValue:size:] for OFRectValue", (value = [OFValue valueWithRect: rect]) && R([value getValue: &rect2 size: sizeof(rect2)]) && OFEqualRects(rect2, rect)) EXPECT_EXCEPTION(@"-[rectValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] rectValue]) TEST(@"-[isEqual:]", [[OFValue valueWithRect: rect] |
︙ | ︙ |
Modified tests/OFWindowsRegistryKeyTests.m from [60470d17f4] to [ddf274227c].
︙ | ︙ | |||
38 39 40 41 42 43 44 | TEST(@"+[OFWindowsRegistryKey localMachineKey]", [OFWindowsRegistryKey localMachineKey]) TEST(@"+[OFWindowsRegistryKey usersKey]", [OFWindowsRegistryKey usersKey]) | | | | > | | | > | > | > > > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | TEST(@"+[OFWindowsRegistryKey localMachineKey]", [OFWindowsRegistryKey localMachineKey]) TEST(@"+[OFWindowsRegistryKey usersKey]", [OFWindowsRegistryKey usersKey]) TEST(@"-[openSubkeyAtPath:accessRights:options:] #1", (softwareKey = [[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"Software" accessRights: KEY_ALL_ACCESS options: 0])) EXPECT_EXCEPTION(@"-[openSubkeyAtPath:accessRights:options:] #2", OFOpenWindowsRegistryKeyFailedException, [[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"nonexistent" accessRights: KEY_ALL_ACCESS options: 0]) TEST(@"-[createSubkeyAtPath:accessRights:securityAttributes:options:" @"disposition:]", (objFWKey = [softwareKey createSubkeyAtPath: @"ObjFW" accessRights: KEY_ALL_ACCESS securityAttributes: NULL options: 0 disposition: NULL])) TEST(@"-[setData:forValueNamed:type:]", R([objFWKey setData: data forValueNamed: @"data" type: REG_BINARY])) TEST(@"-[dataForValueNamed:subkeyPath:flags:type:]", [[objFWKey dataForValueNamed: @"data" type: &type] isEqual: data] && type == REG_BINARY) |
︙ | ︙ |
Modified tests/OFXMLElementBuilderTests.m from [3226c89147] to [82fd282c44].
︙ | ︙ | |||
25 26 27 28 29 30 31 | - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { OFEnsure(i == 0); nodes[i++] = [element retain]; } | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { OFEnsure(i == 0); nodes[i++] = [element retain]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildOrphanNode: (OFXMLNode *)node { OFEnsure(i == 1); nodes[i++] = [node retain]; } - (void)XMLElementBuilderTests { |
︙ | ︙ |
Modified tests/OFXMLParserTests.m from [c00f2c66ff] to [dc6afcdede].
︙ | ︙ | |||
271 272 273 274 275 276 277 | prefix == nil && namespace == nil); break; } } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target | | | | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | prefix == nil && namespace == nil); break; } } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target text: (OFString *)text { [self parser: parser didCreateEvent: eventTypeProcessingInstruction name: target prefix: nil namespace: nil attributes: nil string: text]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attrs |
︙ | ︙ |
Modified tests/RuntimeARCTests.m from [3a41eba7d4] to [62782bae47].
︙ | ︙ | |||
23 24 25 26 27 28 29 | @end @implementation RuntimeARCTest - (instancetype)init { self = [super init]; | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | @end @implementation RuntimeARCTest - (instancetype)init { self = [super init]; #if defined(OF_WINDOWS) && defined(OF_X86_64) /* * Clang has a bug on Windows where it creates an invalid call into * objc_retainAutoreleasedReturnValue(). Work around it by not using an * autoreleased exception. */ @throw [[OFException alloc] init]; #else |
︙ | ︙ |
Modified tests/TestsAppDelegate.h from [273606ed24] to [951626637b].
︙ | ︙ | |||
255 256 257 258 259 260 261 | - (void)UNIXDatagramSocketTests; @end @interface TestsAppDelegate (OFUNIXStreamSocketTests) - (void)UNIXStreamSocketTests; @end | | | | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | - (void)UNIXDatagramSocketTests; @end @interface TestsAppDelegate (OFUNIXStreamSocketTests) - (void)UNIXStreamSocketTests; @end @interface TestsAppDelegate (OFURITests) - (void)URITests; @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end @interface TestsAppDelegate (OFWindowsRegistryKeyTests) |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [213ce429af] to [aae0a2de42].
︙ | ︙ | |||
179 180 181 182 183 184 185 | defined(OF_NINTENDO_SWITCH) @try { return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); } @catch (id e) { OFString *string = [OFString stringWithFormat: @"\nRuntime error: Unhandled exception:\n%@\n", e]; | < < < > > | > > > | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | defined(OF_NINTENDO_SWITCH) @try { return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); } @catch (id e) { OFString *string = [OFString stringWithFormat: @"\nRuntime error: Unhandled exception:\n%@\n", e]; [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeString: string]; if ([e stackTraceAddresses] != nil) [OFStdOut writeString: @"\nStack trace:\n"]; for (OFValue *address in [e stackTraceAddresses]) [OFStdOut writeFormat: @" %p\n", address.pointerValue]; # if defined(OF_WII) [OFStdOut reset]; [OFStdOut writeString: @"Press home button to exit!"]; for (;;) { WPAD_ScanPads(); |
︙ | ︙ | |||
427 428 429 430 431 432 433 | [self UNIXStreamSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif | | | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | [self UNIXStreamSocketTests]; # endif [self kernelEventObserverTests]; #endif #ifdef OF_HAVE_THREADS [self threadTests]; #endif [self URITests]; #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif #ifdef OF_HAVE_SOCKETS [self HTTPCookieTests]; [self HTTPCookieManagerTests]; #endif |
︙ | ︙ |
Modified tests/objc_sync/test.m from [63dc58fd99] to [1f28b08c51].
︙ | ︙ | |||
41 42 43 44 45 46 47 | printf("[%s] Left #1\n", name); return nil; } @end int | | | | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | printf("[%s] Left #1\n", name); return nil; } @end int main(void) { MyThread *t1, *t2; lock = [[OFObject alloc] init]; t1 = [MyThread thread]; t1.name = @"A"; t2 = [MyThread thread]; t2.name = @"B"; [t1 start]; [t2 start]; [t1 join]; [t2 join]; |
︙ | ︙ |
Modified tests/serialization.xml from [d106910237] to [ea3d1a36ad].
︙ | ︙ | |||
10 11 12 13 14 15 16 | <key> <OFString>Blub</OFString> </key> <object> <OFString>B"la</OFString> </object> <key> | < < < < < < < < < < < < < < < < < < < | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <key> <OFString>Blub</OFString> </key> <object> <OFString>B"la</OFString> </object> <key> <OFList> <OFString>Hello</OFString> <OFString>Wo
ld! How are you?</OFString> <OFURI>https://objfw.nil.im/</OFURI> <OFXMLElement name='x'> <children> <OFMutableArray> <OFXMLElement name='y'/> <OFXMLCDATA><![CDATA[<]]></OFXMLCDATA> </OFMutableArray> </children> |
︙ | ︙ | |||
59 60 61 62 63 64 65 66 67 | </object> </OFCountedSet> </OFList> </key> <object> <OFString>list</OFString> </object> </OFMutableDictionary> </serialization> | > > > > > > > > > > > > > > > > > > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | </object> </OFCountedSet> </OFList> </key> <object> <OFString>list</OFString> </object> <key> <OFData>MDEyMzQ1Njc4OTo7PEFCQ0RFRkdISklLTE1OT1BRUlNUVVZXWFla</OFData> </key> <object> <OFString>data</OFString> </object> <key> <OFArray> <OFString>Qu"xbar test</OFString> <OFNumber type='signed'>1234</OFNumber> <OFNumber type='float'>40934a456d5cfaad</OFNumber> <OFMutableString>asd</OFMutableString> <OFDate encoding='hex'>40934a456d5cfaad</OFDate> </OFArray> </key> <object> <OFString>Hello</OFString> </object> </OFMutableDictionary> </serialization> |
Modified tests/terminal/TerminalTests.m from [eb6cacca17] to [695364c6d5].
︙ | ︙ | |||
88 89 90 91 92 93 94 | [OFStdOut eraseLine]; [OFStdOut writeString: @"World!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut clear]; [OFThread sleepForTimeInterval: 2]; | | | | | | | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | [OFStdOut eraseLine]; [OFStdOut writeString: @"World!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut clear]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorPosition: OFMakePoint(5, 3)]; [OFStdOut writeString: @"Text at (5, 3)"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(-2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(0, -2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(0, 2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(1, 1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFMakePoint(-1, -1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorColumn: 2]; [OFThread sleepForTimeInterval: 2]; [OFStdOut reset]; |
︙ | ︙ |
Modified utils/Makefile from [b7affc6883] to [d5d46e8aaf].
1 2 | include ../extra.mk | | > | 1 2 3 4 5 6 7 8 9 10 11 | include ../extra.mk SUBDIRS += ${OBJFW_NEW} \ ${OFARC} \ ${OFDNS} \ ${OFHASH} \ ${OFHTTP} \ completions include ../buildsys.mk |
︙ | ︙ |
Modified utils/objfw-compile from [3a536375c5] to [ffd05ad528].
︙ | ︙ | |||
296 297 298 299 300 301 302 | objs="$objs $obj" build="no" if test ! -f "$obj" -o "$i" -nt "$obj"; then build="yes" else deps=$($OBJC -E -M $CPPFLAGS $OBJCFLAGS $i | | | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | objs="$objs $obj" build="no" if test ! -f "$obj" -o "$i" -nt "$obj"; then build="yes" else deps=$($OBJC -E -M $CPPFLAGS $OBJCFLAGS $i | sed -e 's/.*: //' -e 's/\\//g') for dep in $deps; do test "$dep" -nt $obj && build="yes" done fi if test x"$build" = x"yes"; then link="yes" |
︙ | ︙ |
Modified utils/objfw-embed from [a4ff5f4233] to [b832fbf4cf].
︙ | ︙ | |||
10 11 12 13 14 15 16 | #include <stddef.h> #include <stdint.h> extern void OFRegisterEmbeddedFile(const char *, const uint8_t *, size_t); static const uint8_t bytes[] = { EOF | | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <stddef.h> #include <stdint.h> extern void OFRegisterEmbeddedFile(const char *, const uint8_t *, size_t); static const uint8_t bytes[] = { EOF od -vtx1 $1 | sed -e '/^[^ ][^ ]*$/d;s/ */ /g' -e 's/ $//g;s/^[^ ][^ ]* //' -e 's/ /, 0x/g' -e 's/^/ 0x/' -e 's/$/,/' cat <<EOF }; static void __attribute__((__constructor__)) ctor(void) { OFRegisterEmbeddedFile("$2", bytes, sizeof(bytes)); |
︙ | ︙ |
Added utils/objfw-new/Makefile version [fe068759c6].
> > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. LIBS := -L../../src -lobjfw \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Added utils/objfw-new/NewApp.m version [a817ca083b].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 <errno.h> #import "OFApplication.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newApp(OFString *name) { OFString *path = [name stringByAppendingPathExtension: @"m"]; OFFile *file = nil; @try { file = [OFFile fileWithPath: path mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } [file writeFormat: @"#import <ObjFW/ObjFW.h>\n" @"\n" @"@interface %@: OFObject <OFApplicationDelegate>\n" @"@end\n" @"\n" @"OF_APPLICATION_DELEGATE(%@)\n" @"\n" @"@implementation %@\n" @"- (void)applicationDidFinishLaunching\n" @"{\n" @" [OFApplication terminate];\n" @"}\n" @"@end\n", name, name, name]; [file close]; } |
Added utils/objfw-new/NewClass.m version [13b11d77d3].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 <errno.h> #import "Property.h" #import "OFApplication.h" #import "OFArray.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newClass(OFString *name, OFString *superclass, OFMutableArray *properties) { OFString *headerPath = [name stringByAppendingPathExtension: @"h"]; OFString *implPath = [name stringByAppendingPathExtension: @"m"]; OFFile *headerFile = nil, *implFile = nil; bool needsDealloc = false; @try { headerFile = [OFFile fileWithPath: headerPath mode: @"wx"]; implFile = [OFFile fileWithPath: implPath mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } if (superclass == nil) superclass = @"OFObject"; for (size_t i = 0; i < properties.count; i++) { Property *property = [Property propertyWithString: [properties objectAtIndex: i]]; [properties replaceObjectAtIndex: i withObject: property]; } [headerFile writeFormat: @"#import <ObjFW/ObjFW.h>\n" @"\n" @"OF_ASSUME_NONNULL_BEGIN\n" @"\n" @"@interface %@: %@\n", name, superclass]; if (properties.count > 0) [headerFile writeString: @"{\n"]; for (Property *property in properties) [headerFile writeFormat: @"\t%@_%@;\n", property.type, property.name]; if (properties.count > 0) [headerFile writeString: @"}\n\n"]; for (Property *property in properties) { [headerFile writeString: @"@property "]; if (property.attributes.count > 0) { bool first = true; if ([property.attributes containsObject: @"nullable"]) [headerFile writeString: @"OF_NULLABLE_PROPERTY "]; [headerFile writeString: @"("]; for (OFString *attribute in property.attributes) { if ([attribute isEqual: @"nullable"]) continue; if ([attribute isEqual: @"retain"] || [attribute isEqual: @"copy"]) needsDealloc = true; if (!first) [headerFile writeString: @", "]; [headerFile writeString: attribute]; first = false; } [headerFile writeString: @") "]; } [headerFile writeFormat: @"%@%@;\n", property.type, property.name]; } [headerFile writeString: @"@end\n" @"\n" @"OF_ASSUME_NONNULL_END\n"]; [implFile writeFormat: @"#import \"%@\"\n" @"\n" @"@implementation %@\n", headerPath, name]; for (Property *property in properties) [implFile writeFormat: @"@synthesize %@ = _%@;\n", property.name, property.name]; if (needsDealloc) { [implFile writeString: @"\n" @"- (void)dealloc\n" @"{\n"]; for (Property *property in properties) if ([property.attributes containsObject: @"retain"] || [property.attributes containsObject: @"copy"]) [implFile writeFormat: @"\t[_%@ release];\n", property.name]; [implFile writeString: @"\n" @"\t[super dealloc];\n" @"}\n"]; } [implFile writeString: @"@end\n"]; [headerFile close]; [implFile close]; } |
Added utils/objfw-new/ObjFWNew.m version [efa3835453].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "OFApplication.h" #import "OFArray.h" #import "OFObject.h" #import "OFOptionsParser.h" #import "OFStdIOStream.h" #import "OFString.h" @interface ObjFWNew: OFObject <OFApplicationDelegate> @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); OF_APPLICATION_DELEGATE(ObjFWNew) static void showUsage(void) { [OFStdErr writeFormat: @"Usage: %@ --app|--class name\n", [OFApplication programName]]; [OFApplication terminateWithStatus: 1]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching { bool app, class; OFString *superclass = nil, *name; OFMutableArray OF_GENERIC(OFString *) *properties = nil; const OFOptionsParserOption options[] = { { 'a', @"app", 0, &app, NULL }, { 'c', @"class", 0, &class, NULL }, { 's', @"superclass", 1, NULL, &superclass }, { 'p', @"property", 1, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'p': if (properties == nil) properties = [OFMutableArray array]; [properties addObject: optionsParser.argument]; break; case '?': case ':': case '=': showUsage(); break; } } if ((app ^ class) != 1 || optionsParser.remainingArguments.count != 1) showUsage(); if ((superclass && !class) || (properties != nil && !class)) showUsage(); name = optionsParser.remainingArguments.firstObject; if ([name rangeOfString: @"."].location != OFNotFound) { [OFStdErr writeLine: @"Name must not contain dots!"]; [OFApplication terminate]; } if (app) newApp(name); else if (class) newClass(name, superclass, properties); else showUsage(); [OFApplication terminate]; } @end |
Added utils/objfw-new/Property.h version [e9facd5dfc].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "OFObject.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface Property: OFObject { OFString *_name, *_type; OFArray OF_GENERIC(OFString *) *_attributes; } + (instancetype)propertyWithString: (OFString *)string; - (instancetype)initWithString: (OFString *)string; @property (readonly, nonatomic) OFString *name; @property (readonly, nonatomic) OFString *type; @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *attributes; @end OF_ASSUME_NONNULL_END |
Added utils/objfw-new/Property.m version [b0b533e64d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | /* * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im> * * 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 "Property.h" #import "OFArray.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" @interface Property () - (void)parseString: (OFString *)string; @end @implementation Property @synthesize name = _name, type = _type, attributes = _attributes; + (instancetype)propertyWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } - (instancetype)initWithString: (OFString *)string { self = [super init]; @try { [self parseString: string]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)parseString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; size_t length = string.UTF8StringLength, nameIdx = -1; OFMutableArray *attributes = nil; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if (UTF8String[0] == '(') { for (size_t i = 0, level = 0; i < length; i++) { if (UTF8String[i] == '(') level++; else if (UTF8String[i] == ')') { if (--level == 0) { OFString *attributesString = [OFString stringWithUTF8String: UTF8String + 1 length: i - 1]; attributes = [[[attributesString componentsSeparatedByString: @","] mutableCopy] autorelease]; UTF8String += i + 1; length += i + 1; while (*UTF8String == ' ' || *UTF8String == '\t') { UTF8String++; length--; } break; } } } } for (size_t i = 0; i < attributes.count; i++) { OFString *attribute = [[attributes objectAtIndex: i] stringByDeletingEnclosingWhitespaces]; [attributes replaceObjectAtIndex: i withObject: attribute]; } [attributes makeImmutable]; _attributes = [attributes copy]; for (ssize_t i = (ssize_t)length - 1; i > 0; i--) { if (UTF8String[i] == '*' || UTF8String[i] == ' ' || UTF8String[i] == '\t') { nameIdx = i + 1; break; } } if (nameIdx < 0) @throw [OFInvalidArgumentException exception]; _name = [[OFString alloc] initWithUTF8String: UTF8String + nameIdx]; _type = [[OFString alloc] initWithUTF8String: UTF8String length: (size_t)nameIdx]; objc_autoreleasePoolPop(pool); } - (void)dealloc { [_name release]; [_type release]; [super dealloc]; } @end |
Modified utils/ofarc/LHAArchive.m from [fb0bc51e00] to [7f7a619844].
︙ | ︙ | |||
36 37 38 39 40 41 42 | withString: @"\n\t"]; } static void setPermissions(OFString *path, OFLHAArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS | | | | | | < | < < < < < < < < < < < < < | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | withString: @"\n\t"]; } static void setPermissions(OFString *path, OFLHAArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *POSIXPermissions = entry.POSIXPermissions; if (POSIXPermissions == nil) return; POSIXPermissions = [OFNumber numberWithUnsignedShort: POSIXPermissions.unsignedShortValue & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: POSIXPermissions forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif } static void setModificationDate(OFString *path, OFLHAArchiveEntry *entry) { OFFileAttributes attributes = [OFDictionary dictionaryWithObject: entry.modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation LHAArchive + (void)initialize |
︙ | ︙ | |||
130 131 132 133 134 135 136 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { | | | | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%llu", entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" |
︙ | ︙ | |||
171 172 173 174 175 176 177 | @"Compression method: %[method]", @"method", entry.compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; | | > | | | | | > | | > | | | | > | | | | | | | | | | | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | @"Compression method: %[method]", @"method", entry.compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (entry.POSIXPermissions != nil) { OFString *permissionsString = [OFString stringWithFormat: @"%llo", entry.POSIXPermissions .unsignedLongLongValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_posix_permissions", @"POSIX permissions: %[perm]", @"perm", permissionsString)]; } if (entry.ownerAccountID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_id", @"Owner account ID: %[id]", @"id", entry.ownerAccountID)]; } if (entry.groupOwnerAccountID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_gid", @"Group owner account ID: %[id]", @"id", entry.groupOwnerAccountID)]; } if (entry.ownerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_name", @"Owner account name: %[name]", @"name", entry.ownerAccountName)]; } if (entry.groupOwnerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_name", @"Group: %[name]", @"name", entry.groupOwnerAccountName)]; } if (app->_outputLevel >= 2) { OFString *headerLevel = [OFString stringWithFormat: @"%" PRIu8, entry.headerLevel]; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " "%[osid]", @"osid", OSID)]; } | < < < < < < < < < < < | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " "%[osid]", @"osid", OSID)]; } } if (app->_outputLevel >= 3) { OFString *extensions = indent(entry.extensions.description); [OFStdOut writeString: @"\t"]; |
︙ | ︙ | |||
278 279 280 281 282 283 284 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; | | | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; |
︙ | ︙ | |||
464 465 466 467 468 469 470 | @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS | | | | | | | | | > | > | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.POSIXPermissions = [attributes objectForKey: OFFilePOSIXPermissions]; #endif entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.ownerAccountID = [attributes objectForKey: OFFileOwnerAccountID]; entry.groupOwnerAccountID = [attributes objectForKey: OFFileGroupOwnerAccountID]; entry.ownerAccountName = [attributes objectForKey: OFFileOwnerAccountName]; entry.groupOwnerAccountName = [attributes objectForKey: OFFileGroupOwnerAccountName]; #endif if ([type isEqual: OFFileTypeDirectory]) { entry.compressionMethod = @"-lhd-"; if (![entry.fileName hasSuffix: @"/"]) entry.fileName = [entry.fileName |
︙ | ︙ |
Modified utils/ofarc/Makefile from [3f568364e5] to [0cf5c1ca98].
1 2 3 4 5 6 7 8 | include ../../extra.mk PROG = ofarc${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFArc.m \ TarArchive.m \ ZIPArchive.m | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | include ../../extra.mk PROG = ofarc${PROG_SUFFIX} SRCS = GZIPArchive.m \ LHAArchive.m \ OFArc.m \ TarArchive.m \ ZIPArchive.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofarc ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofarc/localization\" LIBS := -L../../src -L../../src/linklib ${OBJFW_LIBS} \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Modified utils/ofarc/OFArc.m from [6ddf1e5e68] to [92125fd380].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFArray.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "OFArray.h" #import "OFFile.h" #import "OFFileManager.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFURI.h" #import "OFArc.h" #import "GZIPArchive.h" #import "LHAArchive.h" #import "TarArchive.h" #import "ZIPArchive.h" |
︙ | ︙ | |||
203 204 205 206 207 208 209 | /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS | | > | | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectory: @LOCALIZATION_DIR]; #else [OFLocale addLocalizationDirectory: @"PROGDIR:/share/ofarc/localization"]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'f': if (_overwrite < 0) |
︙ | ︙ | |||
333 334 335 336 337 338 339 | switch (mode) { case 'a': case 'c': if (remainingArguments.count < 1) help(OFStdErr, false, 1); files = [remainingArguments objectsInRange: | | | 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | switch (mode) { case 'a': case 'c': if (remainingArguments.count < 1) help(OFStdErr, false, 1); files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: (mode == 'a' ? @"rwc" : @"wc")]; for (OFString *path in files) |
︙ | ︙ | |||
390 391 392 393 394 395 396 | permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif files = [remainingArguments objectsInRange: | | | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; archive = [self openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive printFiles: files]; break; case 'x': if (remainingArguments.count < 1) help(OFStdErr, false, 1); files = [remainingArguments objectsInRange: OFMakeRange(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; if (files.count > 0) |
︙ | ︙ | |||
457 458 459 460 461 462 463 | OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", | | | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", @"dir", e.URI.fileSystemRepresentation, @"error", error)]; _exitStatus = 1; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; |
︙ | ︙ |
Modified utils/ofarc/TarArchive.m from [52a1c25d9d] to [1feea72626].
︙ | ︙ | |||
29 30 31 32 33 34 35 | static OFArc *app; static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS | | > | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | static OFArc *app; static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *POSIXPermissions = [OFNumber numberWithUnsignedLongLong: entry.POSIXPermissions.longLongValue & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: POSIXPermissions forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif } |
︙ | ︙ | |||
111 112 113 114 115 116 117 | [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *date = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *size = [OFString stringWithFormat: | < < | | < | | > | > | < > | > | | | > | | | | | | | | | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *date = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *size = [OFString stringWithFormat: @"%llu", entry.uncompressedSize]; OFString *permissionsString = [OFString stringWithFormat: @"%llo", entry.POSIXPermissions .unsignedLongLongValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_size", @"[" @" 'Size: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", size)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_posix_permissions", @"POSIX permissions: %[perm]", @"perm", permissionsString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_id", @"Owner account ID: %[id]", @"id", entry.ownerAccountID)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_id", @"Group owner account ID: %[id]", @"id", entry.groupOwnerAccountID)]; if (entry.ownerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner_account_name", @"Owner account name: %[name]", @"name", entry.ownerAccountName)]; } if (entry.groupOwnerAccountName != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group_owner_account_name", @"Group owner account name: %[name]", @"name", entry.groupOwnerAccountName)]; } [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", date)]; |
︙ | ︙ | |||
277 278 279 280 281 282 283 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFTarArchiveEntryType type = entry.type; OFString *outFileName, *directory; OFFile *output; OFStream *stream; | | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFTarArchiveEntryType type = entry.type; OFString *outFileName, *directory; OFFile *output; OFStream *stream; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; if (type != OFTarArchiveEntryTypeFile && type != OFTarArchiveEntryTypeDirectory) { |
︙ | ︙ | |||
475 476 477 478 479 480 481 | @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS | | > | | > | > | > | | | | > | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.POSIXPermissions = [attributes objectForKey: OFFilePOSIXPermissions]; #endif entry.uncompressedSize = attributes.fileSize; entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.ownerAccountID = [attributes objectForKey: OFFileOwnerAccountID]; entry.groupOwnerAccountID = [attributes objectForKey: OFFileGroupOwnerAccountID]; entry.ownerAccountName = attributes.fileOwnerAccountName; entry.groupOwnerAccountName = attributes.fileGroupOwnerAccountName; #endif if ([type isEqual: OFFileTypeRegular]) entry.type = OFTarArchiveEntryTypeFile; else if ([type isEqual: OFFileTypeDirectory]) { entry.type = OFTarArchiveEntryTypeDirectory; entry.uncompressedSize = 0; } else if ([type isEqual: OFFileTypeSymbolicLink]) { entry.type = OFTarArchiveEntryTypeSymlink; entry.targetFileName = attributes.fileSymbolicLinkDestination; entry.uncompressedSize = 0; } [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if (entry.type == OFTarArchiveEntryTypeFile) { unsigned long long written = 0; unsigned long long size = entry.uncompressedSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { ssize_t length = [app |
︙ | ︙ |
Modified utils/ofarc/ZIPArchive.m from [0cdfabe7b0] to [6652b0186c].
︙ | ︙ | |||
244 245 246 247 248 249 250 | for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; | | | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; |
︙ | ︙ | |||
435 436 437 438 439 440 441 | [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; size = (isDirectory ? 0 : attributes.fileSize); | | | | | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"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; entry.modificationDate = attributes.fileModificationDate; [entry makeImmutable]; |
︙ | ︙ |
Renamed and modified utils/ofarc/lang/de.json [d777ea4bdf] to utils/ofarc/localization/de.json [173fef355f].
︙ | ︙ | |||
71 72 73 74 75 76 77 | "list_size": [ "Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], | | | | > > | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | "list_size": [ "Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], "list_posix_permissions": "POSIX-Berechtigungen: %[perm]", "list_owner_account_id": "Besitzerkontennummer: %[id]", "list_group_owner_account_id": "Gruppenbesitzerkontennummer: %[id]", "list_owner_account_name": "Besitzerkontenname: %[name]", "list_group_owner_account_name": "Gruppebesitzerkontenname: %[name]", "list_header_level": "Header-Level: %[level]", "list_modification_date": "Änderungsdatum: %[date]", "list_type_normal": "Typ: Normale Datei", "list_type_hardlink": "Typ: Harter Link", "list_type_symlink": "Typ: Symbolischer Link", "list_link_target": "Zieldateiname: %[target]", "list_type_character_device": "Typ: Zeichenorientiertes Gerät", |
︙ | ︙ | |||
103 104 105 106 107 108 109 | "Unkomprimierte Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], "list_compression_method": "Kompressionsmethode: %[method]", | < | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | "Unkomprimierte Größe: ", [ {"size == 1": "1 Byte"}, {"": "%[size] Bytes"} ] ], "list_compression_method": "Kompressionsmethode: %[method]", "list_osid": "Betriebssystem-Identifikator: %[osid]", "list_extensions": "Erweiterungen: %[extensions]", "list_version_made_by": "Erstellt mit Version: %[version]", "list_min_version_needed": "Mindestens benötigte Version: %[version]", "list_general_purpose_bit_flag": "General Purpose Bit Flag: %[gpbf]", "list_extra_field": "Extra-Feld: %[extra]", "list_comment": "Kommentar: %[comment]", |
︙ | ︙ |
Name change from utils/ofarc/lang/languages.json to utils/ofarc/localization/localizations.json.
︙ | ︙ |
Modified utils/ofdns/Makefile from [8b305bc200] to [4bcd154270].
1 2 3 4 | include ../../extra.mk PROG = ofdns${PROG_SUFFIX} SRCS = OFDNS.m | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | include ../../extra.mk PROG = ofdns${PROG_SUFFIX} SRCS = OFDNS.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofdns ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofdns/localization\" LIBS := -L../../src -L../../src/linklib ${OBJFW_LIBS} \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Modified utils/ofdns/OFDNS.m from [4408352570] to [7740440ce7].
︙ | ︙ | |||
95 96 97 98 99 100 101 | OFUnichar option; OFArray OF_GENERIC(OFString *) *remainingArguments; OFDNSResolver *resolver; OFDNSClass DNSClass; #ifdef OF_HAVE_FILES # ifndef OF_AMIGAOS | | > | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | OFUnichar option; OFArray OF_GENERIC(OFString *) *remainingArguments; OFDNSResolver *resolver; OFDNSClass DNSClass; #ifdef OF_HAVE_FILES # ifndef OF_AMIGAOS [OFLocale addLocalizationDirectory: @LOCALIZATION_DIR]; # else [OFLocale addLocalizationDirectory: @"PROGDIR:/share/ofdns/localization"]; # endif #endif #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [[OFSandbox alloc] init]; @try { sandbox.allowsStdIO = true; |
︙ | ︙ |
Name change from utils/ofdns/lang/de.json to utils/ofdns/localization/de.json.
︙ | ︙ |
Name change from utils/ofdns/lang/languages.json to utils/ofdns/localization/localizations.json.
︙ | ︙ |
Modified utils/ofhash/Makefile from [32371c1afb] to [8a288c8a72].
1 2 3 4 | include ../../extra.mk PROG = ofhash${PROG_SUFFIX} SRCS = OFHash.m | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | include ../../extra.mk PROG = ofhash${PROG_SUFFIX} SRCS = OFHash.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofhash ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLOCALIZATION_DIR=\"${datadir}/ofhash/localization\" LIBS := -L../../src -L../../src/linklib ${OBJFW_LIBS} \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Modified utils/ofhash/OFHash.m from [1e29e681a3] to [9cab35b0cf].
︙ | ︙ | |||
91 92 93 94 95 96 97 | OFSHA1Hash *SHA1Hash = nil; OFSHA224Hash *SHA224Hash = nil; OFSHA256Hash *SHA256Hash = nil; OFSHA384Hash *SHA384Hash = nil; OFSHA512Hash *SHA512Hash = nil; #ifndef OF_AMIGAOS | | > | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | OFSHA1Hash *SHA1Hash = nil; OFSHA224Hash *SHA224Hash = nil; OFSHA256Hash *SHA256Hash = nil; OFSHA384Hash *SHA384Hash = nil; OFSHA512Hash *SHA512Hash = nil; #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectory: @LOCALIZATION_DIR]; #else [OFLocale addLocalizationDirectory: @"PROGDIR:/share/ofhash/localization"]; #endif while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: |
︙ | ︙ | |||
130 131 132 133 134 135 136 | sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsUserDatabaseReading = true; for (OFString *path in optionsParser.remainingArguments) [sandbox unveilPath: path permissions: @"r"]; | | | 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsUserDatabaseReading = true; for (OFString *path in optionsParser.remainingArguments) [sandbox unveilPath: path permissions: @"r"]; [sandbox unveilPath: @LOCALIZATION_DIR permissions: @"r"]; [OFApplication of_activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif |
︙ | ︙ |
Name change from utils/ofhash/lang/de.json to utils/ofhash/localization/de.json.
︙ | ︙ |
Name change from utils/ofhash/lang/languages.json to utils/ofhash/localization/localizations.json.
︙ | ︙ |
Modified utils/ofhttp/Makefile from [b04564652b] to [cd8c3dfe6d].
1 2 3 4 5 | include ../../extra.mk PROG = ofhttp${PROG_SUFFIX} SRCS = OFHTTP.m \ ProgressBar.m | | | | | | | | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | include ../../extra.mk PROG = ofhttp${PROG_SUFFIX} SRCS = OFHTTP.m \ ProgressBar.m DATA = localization/de.json \ localization/localizations.json include ../../buildsys.mk PACKAGE_NAME = ofhttp ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../../src/tls \ -I../.. \ -DLOCALIZATION_DIR='"${datadir}/ofhttp/localization"' \ -DLIB_PREFIX='"${LIB_PREFIX}"' \ -DLIB_SUFFIX='"${LIB_SUFFIX}"' LIBS := -L../../src -L../../src/linklib -L../../src/tls \ ${OFHTTP_LIBS} ${OBJFW_LIBS} \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Modified utils/ofhttp/OFHTTP.m from [aa1d962c4e] to [2267fb0c48].
︙ | ︙ | |||
30 31 32 33 34 35 36 | # import "OFPlugin.h" #endif #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" | | > | < | | | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | # import "OFPlugin.h" #endif #import "OFSandbox.h" #import "OFStdIOStream.h" #import "OFSystemInfo.h" #import "OFTCPSocket.h" #import "OFTLSStream.h" #import "OFURI.h" #ifdef HAVE_TLS_SUPPORT # import "ObjFWTLS.h" #endif #import "OFConnectionFailedException.h" #import "OFGetItemAttributesFailedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerResponseException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFResolveHostFailedException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) @interface OFHTTP: OFObject <OFApplicationDelegate, OFHTTPClientDelegate, OFStreamDelegate> { OFArray OF_GENERIC(OFString *) *_URIs; size_t _URIIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectFileNameRequest; bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus; bool _useUnicode; OFStream *_body; OFHTTPRequestMethod _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; unsigned long long _received, _length, _resumedFrom; ProgressBar *_progressBar; } - (void)downloadNextURI; @end #ifdef HAVE_TLS_SUPPORT void _reference_to_ObjFWTLS(void) { _ObjFWTLS_reference = 1; } #endif OF_APPLICATION_DELEGATE(OFHTTP) static void help(OFStream *stream, bool full, int status) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[cehHmoOPqv] uri1 [uri2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", @"Options:\n " @"-b --body " |
︙ | ︙ | |||
351 352 353 354 355 356 357 | [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; contentLength = [OFString stringWithFormat: @"%ju", fileSize]; [_clientHeaders setObject: contentLength forKey: @"Content-Length"]; | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; contentLength = [OFString stringWithFormat: @"%ju", fileSize]; [_clientHeaders setObject: contentLength forKey: @"Content-Length"]; } @catch (OFGetItemAttributesFailedException *e) { } } if (contentLength == nil) [_clientHeaders setObject: @"chunked" forKey: @"Transfer-Encoding"]; } |
︙ | ︙ | |||
447 448 449 450 451 452 453 | /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS | | > | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLocalizationDirectory: @LOCALIZATION_DIR]; #else [OFLocale addLocalizationDirectory: @"PROGDIR:/share/ofhttp/localization"]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'b': [self setBody: optionsParser.argument]; |
︙ | ︙ | |||
541 542 543 544 545 546 547 | [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif _outputPath = [outputPath copy]; | | | | | | | | 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 | [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif _outputPath = [outputPath copy]; _URIs = [optionsParser.remainingArguments copy]; if (_URIs.count < 1) help(OFStdErr, false, 1); if (_quiet && _verbose) { [OFStdErr writeLine: OF_LOCALIZED(@"quiet_xor_verbose", @"%[prog]: -q / --quiet and -v / --verbose are mutually " @"exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _detectFileName) { [OFStdErr writeLine: OF_LOCALIZED( @"output_xor_detect_filename", @"%[prog]: -o / --output and -O / --detect-filename are " @"mutually exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _URIs.count > 1) { [OFStdErr writeLine: OF_LOCALIZED(@"output_only_with_one_uri", @"%[prog]: Cannot use -o / --output when more than one URI " @"has been specified!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_insecure) _HTTPClient.allowsInsecureRedirects = true; #ifdef OF_WINDOWS _useUnicode = [OFSystemInfo isWindowsNT]; #else _useUnicode = ([OFLocale encoding] == OFStringEncodingUTF8); #endif [self performSelector: @selector(downloadNextURI) afterDelay: 0]; } - (void)client: (OFHTTPClient *)client didCreateTLSStream: (OFTLSStream *)stream request: (OFHTTPRequest *)request { /* Use setter instead of property access to work around GCC bug. */ |
︙ | ︙ | |||
604 605 606 607 608 609 610 | while (!_body.atEndOfStream) { char buffer[4096]; size_t length = [_body readIntoBuffer: buffer length: 4096]; [body writeBuffer: buffer length: length]; } } | | | | | | | | | | | | | | 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 | while (!_body.atEndOfStream) { char buffer[4096]; size_t length = [_body readIntoBuffer: buffer length: 4096]; [body writeBuffer: buffer length: length]; } } - (bool)client: (OFHTTPClient *)client shouldFollowRedirectToURI: (OFURI *)URI statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if (_verbose) { void *pool = objc_autoreleasePoolPush(); OFDictionary OF_GENERIC(OFString *, OFString *) *headers = response.headers; OFEnumerator *keyEnumerator = [headers keyEnumerator]; OFEnumerator *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [OFStdOut writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"☇ %@", URI.string]; else [OFStdOut writeFormat: @"< %@", URI.string]; } _length = 0; return true; } - (bool)stream: (OFStream *)response didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { if (exception != nil) { OFString *URI; [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_error", @"Error!")]; } URI = [_URIs objectAtIndex: _URIIndex - 1]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_exception", @"%[prog]: Failed to download <%[uri]>!\n" @" %[exception]", @"prog", [OFApplication programName], @"uri", URI, @"exception", exception)]; _errorCode = 1; [self performSelector: @selector(downloadNextURI) afterDelay: 0]; return false; } [_output writeBuffer: buffer length: length]; _received += length; |
︙ | ︙ | |||
688 689 690 691 692 693 694 | if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_done", @"Done!")]; } | | | 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_done", @"Done!")]; } [self performSelector: @selector(downloadNextURI) afterDelay: 0]; return false; } return true; } |
︙ | ︙ | |||
812 813 814 815 816 817 818 | if ([exception isKindOfClass: [OFResolveHostFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_resolve_host_failed", | | | | | | | | | | | 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | if ([exception isKindOfClass: [OFResolveHostFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_resolve_host_failed", @"%[prog]: Failed to download <%[uri]>!\n" @" Failed to resolve host: %[exception]", @"prog", [OFApplication programName], @"uri", request.URI.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @"%[prog]: Failed to download <%[uri]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"uri", request.URI.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFInvalidServerResponseException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_invalid_server_response", @"%[prog]: Failed to download <%[uri]>!\n" @" Invalid server response!", @"prog", [OFApplication programName], @"uri", request.URI.string)]; } else if ([exception isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"no_tls_support", @"%[prog]: No TLS support in ObjFW!\n" |
︙ | ︙ | |||
876 877 878 879 880 881 882 | error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"write", @"Write failed"); [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_read_or_write_failed", | | | | | | | | | | 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 | error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"write", @"Write failed"); [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[uri]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], @"uri", request.URI.string, @"error", error, @"exception", exception)]; } else if ([exception isKindOfClass: [OFHTTPRequestFailedException class]]) { short statusCode; OFString *codeString; if (_ignoreStatus) { exception = nil; goto after_exception_handling; } statusCode = response.statusCode; codeString = [OFString stringWithFormat: @"%hd %@", statusCode, OFHTTPStatusCodeString(statusCode)]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[uri]>!\n" @" HTTP status code: %[code]", @"prog", [OFApplication programName], @"uri", request.URI.string, @"code", codeString)]; } else @throw exception; _errorCode = 1; [self performSelector: @selector(downloadNextURI) afterDelay: 0]; return; } after_exception_handling: if (_method == OFHTTPRequestMethodHead) goto next; if (_detectFileNameRequest) { _currentFileName = [fileNameFromContentDisposition( [response.headers objectForKey: @"Content-Disposition"]) copy]; _detectedFileName = true; /* Handle this URI on the next -[downloadNextURI] call */ _URIIndex--; [self performSelector: @selector(downloadNextURI) afterDelay: 0]; return; } if ([_outputPath isEqual: @"-"]) _output = [OFStdOut copy]; else { |
︙ | ︙ | |||
982 983 984 985 986 987 988 | [response asyncReadIntoBuffer: _buffer length: [OFSystemInfo pageSize]]; return; next: [_currentFileName release]; _currentFileName = nil; | | | | | | | | | | | | | | | | | | | 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | [response asyncReadIntoBuffer: _buffer length: [OFSystemInfo pageSize]]; return; next: [_currentFileName release]; _currentFileName = nil; [self performSelector: @selector(downloadNextURI) afterDelay: 0]; } - (void)downloadNextURI { OFString *URIString = nil; OFURI *URI; OFMutableDictionary *clientHeaders; OFHTTPRequest *request; _received = _length = _resumedFrom = 0; if (_output != OFStdOut) [_output release]; _output = nil; if (_URIIndex >= _URIs.count) [OFApplication terminateWithStatus: _errorCode]; @try { URIString = [_URIs objectAtIndex: _URIIndex++]; URI = [OFURI URIWithString: URIString]; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_uri", @"%[prog]: Invalid URI: <%[uri]>!", @"prog", [OFApplication programName], @"uri", URIString)]; _errorCode = 1; goto next; } if (![URI.scheme isEqual: @"http"] && ![URI.scheme isEqual: @"https"]) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_scheme", @"%[prog]: Invalid scheme: <%[uri]>!", @"prog", [OFApplication programName], @"uri", URIString)]; _errorCode = 1; goto next; } clientHeaders = [[_clientHeaders mutableCopy] autorelease]; if (_detectFileName && !_detectedFileName) { if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⠒ %@", URI.string]; else [OFStdOut writeFormat: @"? %@", URI.string]; } request = [OFHTTPRequest requestWithURI: URI]; request.headers = clientHeaders; request.method = OFHTTPRequestMethodHead; _detectFileNameRequest = true; [_HTTPClient asyncPerformRequest: request]; return; } if (!_detectedFileName) { [_currentFileName release]; _currentFileName = nil; } else _detectedFileName = false; if (_currentFileName == nil) _currentFileName = [_outputPath copy]; if (_currentFileName == nil) _currentFileName = [URI.path.lastPathComponent copy]; if ([_currentFileName isEqual: @"/"]) { [_currentFileName release]; _currentFileName = nil; } if (_currentFileName == nil) |
︙ | ︙ | |||
1078 1079 1080 1081 1082 1083 1084 | @throw [OFOutOfRangeException exception]; _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; | | | | | | | 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | @throw [OFOutOfRangeException exception]; _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; } @catch (OFGetItemAttributesFailedException *e) { } } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⇣ %@", URI.string]; else [OFStdOut writeFormat: @"< %@", URI.string]; } request = [OFHTTPRequest requestWithURI: URI]; request.headers = clientHeaders; request.method = _method; _detectFileNameRequest = false; [_HTTPClient asyncPerformRequest: request]; return; next: [self performSelector: @selector(downloadNextURI) afterDelay: 0]; } @end |
Renamed and modified utils/ofhttp/lang/de.json [027af9bd4c] to utils/ofhttp/localization/de.json [839a028930].
1 | { | | | 1 2 3 4 5 6 7 8 9 | { "usage": "Benutzung: %[prog] -[cehHmoOPqv] uri1 [uri2 ...]", "full_usage": [ "Optionen:\n", " -b --body Angegebene Datei als Body übergeben\n", " (- für Standard-Eingabe)\n", " -c --continue Download von existierender Datei ", "fortsetzen\n", " -f --force Existierende Datei überschreiben\n", |
︙ | ︙ | |||
32 33 34 35 36 37 38 | "%[prog]: -q / --quiet und -v / --verbose schließen sich gegenseitig ", "aus!" ], "output_xor_detect_filename": [ "%[prog]: -o / --output und -O / --detect-filename schließen sich ", "gegenseitig aus!" ], | | | | | | | | | | | | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | "%[prog]: -q / --quiet und -v / --verbose schließen sich gegenseitig ", "aus!" ], "output_xor_detect_filename": [ "%[prog]: -o / --output und -O / --detect-filename schließen sich ", "gegenseitig aus!" ], "output_only_with_one_uri": [ "%[prog]: -o / --output kann nicht mit mehr als einer URI benutzt ", "werden!" ], "download_resolve_host_failed": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " Host auflösen fehlgeschlagen: %[exception]" ], "download_failed_connection_failed": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " Verbindung fehlgeschlagen: %[exception]" ], "download_failed_invalid_server_response": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " Ungültige Antwort vom Server!" ], "no_tls_support": [ "%[prog]: Keine TLS-Unterstützung in ObjFW!\n", " Um via HTTPS runterzuladen müssen Sie entweder ObjFW mit TLS-", "Unterstützung\n", " kompilieren oder eine Bibliothek mittels „preload” laden, welche ", "TLS-Support\n", " zu ObjFW hinzufügt!" ], "download_failed_read_or_write_failed_any": "Lesen oder Schreiben", "download_failed_read_or_write_failed_read": "Lesen", "download_failed_read_or_write_failed_write": "Schreiben", "download_failed_read_or_write_failed": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " %[error]: %[exception]" ], "download_failed": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " HTTP Status-Code: %[code]" ], "download_error": "Fehler!", "download_failed_exception": [ "%[prog]: Fehler beim Download von <%[uri]>!\n", " %[exception]" ], "download_done": "Fertig!", "invalid_uri": "%[prog]: Ungültige URI: <%[uri]>!", "invalid_scheme": "%[prog]: Ungültiges Schema: <%[uri]>!", "type_unknown": "unbekannt", "size_gib": "%[num] GiB", "size_mib": "%[num] MiB", "size_kib": "%[num] KiB", "size_bytes": [ [ {"num == 1": "1 Byte"}, |
︙ | ︙ |
Name change from utils/ofhttp/lang/languages.json to utils/ofhttp/localization/localizations.json.
︙ | ︙ |