ObjFW  Check-in [d1dd66e668]

Overview
Comment:Merge trunk into 1.0 branch
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 1.0
Files: files | file ages | folders
SHA3-256: d1dd66e6680884845c97769680b98ba39462ba4eae828bb113dff05e239065ea
User & Date: js on 2022-10-18 21:34:46
Other Links: branch diff | manifest | tags
Context
2023-07-20
20:02
Merge trunk into 1.0 branch check-in: 124fe8b500 user: js tags: 1.0
2022-10-18
21:34
Merge trunk into 1.0 branch check-in: d1dd66e668 user: js tags: 1.0
17:59
GitHub Actions: Replace Ubuntu 18.04 with latest check-in: a62fba3dc8 user: js tags: trunk
2022-04-19
16:17
Merge trunk into 1.0 branch check-in: fe760fdbbb user: js tags: 1.0
Changes

Deleted .cirrus.yml version [6338675a88].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22






















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
task:
  name: FreeBSD 12.1
  freebsd_instance:
    image_family: freebsd-12-1
  install_script:
    pkg install -y autoconf automake
  shared_script:
    - ./autogen.sh
    - ./configure
    - make -j4 install
  static_script:
    - ./autogen.sh
    - ./configure --disable-shared
    - make -j4 install
  shared_seluid24_script:
    - ./autogen.sh
    - ./configure --enable-seluid24
    - make -j4 install
  static_seluid24_script:
    - ./autogen.sh
    - ./configure --disable-shared --enable-seluid24
    - make -j4 install

Modified .fossil-settings/clean-glob from [0c0ff942fb] to [06b87ad48d].

35
36
37
38
39
40
41

42


43
44
45
46


47

48
49
50
51
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+

+
+




+
+

+




src/tls/Info.plist
tests/DerivedData
tests/EBOOT.PBP
tests/Info.plist
tests/PARAM.SFO
tests/objc_sync/objc_sync
tests/plugin/Info.plist
tests/serialization_xml.m
tests/terminal/terminal_tests
tests/testfile_bin.m
tests/testfile_ini.m
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 [13af81fd69] to [23cb69850b].

40
41
42
43
44
45
46

47


48
49
50
51


52

53
54
55
56
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+

+
+




+
+

+




tests/Info.plist
tests/PARAM.SFO
tests/iOS.xcodeproj/*.pbxuser
tests/iOS.xcodeproj/project.xcworkspace
tests/iOS.xcodeproj/xcuserdata
tests/objc_sync/objc_sync
tests/plugin/Info.plist
tests/serialization_xml.m
tests/terminal/terminal_tests
tests/testfile_bin.m
tests/testfile_ini.m
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].

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-10.15
on: [push, pull_request]
jobs:
  tests:
    runs-on: macos-10.15
    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

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

Added .github/workflows/nintendo-switch.yml version [2a5a4851c5].




































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
name: nintendo-switch
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Install dependencies
      run: docker pull devkitpro/devkita64
    - uses: actions/checkout@v2
    - name: autogen.sh
      run: ./autogen.sh
    - name: configure
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitA64/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkita64 \
          sh -c 'cd /objfw && ./configure --host=aarch64-none-elf --with-nintendo-switch'
    - name: make
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitA64/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkita64 \
          sh -c "cd /objfw && make -j$(nproc)"
    - name: make install
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitA64/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkita64 \
          sh -c "cd /objfw && make -j$(nproc)"

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

1
2
3
4

5
6
7
8
9
10
11
12
-
+



-
+







name: ubuntu-18.04, 32 bit
name: ubuntu-latest, 32 bit
on: [push, pull_request]
jobs:
  tests:
    runs-on: ubuntu-18.04
    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

1
2
3
4

5
6
7
8
9
10
11
12
-
+



-
+







name: ubuntu-18.04, GCC, 32 bit
name: ubuntu-latest, GCC, 32 bit
on: [push, pull_request]
jobs:
  tests:
    runs-on: ubuntu-18.04
    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

1
2
3
4

5
6
7
8
9
10
11
12
-
+



-
+







name: ubuntu-18.04, GCC
name: ubuntu-latest, GCC
on: [push, pull_request]
jobs:
  tests:
    runs-on: ubuntu-18.04
    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

1
2
3
4

5
6
7
8
9
10
11
12
-
+



-
+







name: ubuntu-18.04
name: ubuntu-latest
on: [push, pull_request]
jobs:
  tests:
    runs-on: ubuntu-18.04
    runs-on: ubuntu-latest
    strategy:
      matrix:
        configure_flags:
          -
          - --enable-seluid24
          - --disable-compiler-tls
          - --disable-threads

Added .github/workflows/wii-u.yml version [b25255900b].




































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
name: wii-u
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Install dependencies
      run: docker pull devkitpro/devkitppc
    - uses: actions/checkout@v2
    - name: autogen.sh
      run: ./autogen.sh
    - name: configure
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitPPC/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkitppc \
          sh -c 'cd /objfw && ./configure --host=powerpc-eabi --with-wii-u'
    - name: make
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitPPC/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkitppc \
          sh -c "cd /objfw && make -j$(nproc)"
    - name: make install
      run: |
        docker run \
          -e DEVKITPRO=/opt/devkitpro \
          -e PATH="/opt/devkitpro/devkitPPC/bin:$PATH" \
          -v "$PWD:/objfw" \
          devkitpro/devkitppc \
          sh -c "cd /objfw && make -j$(nproc)"

Modified .gitignore from [fdb1296647] to [726b780402].

40
41
42
43
44
45
46

47


48
49
50
51


52

53
54
55
56
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62







+

+
+




+
+

+




tests/Info.plist
tests/PARAM.SFO
tests/iOS.xcodeproj/*.pbxuser
tests/iOS.xcodeproj/project.xcworkspace
tests/iOS.xcodeproj/xcuserdata
tests/objc_sync/objc_sync
tests/plugin/Info.plist
tests/serialization_xml.m
tests/terminal/terminal_tests
tests/testfile_bin.m
tests/testfile_ini.m
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
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
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				\
	     _Nonnull=				\
	     _Nullable=				\
	     DOXYGEN				\
	     OF_BOXABLE				\
	     OF_CONSUMED			\
	     OF_DESIGNATED_INITIALIZER		\
	     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_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		\
	     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
31

32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47

48
49
50
51
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 '.cirrus*,.fossil*,.git*' | ofarc -ttgz -xq -
		--exclude '.fossil*,.git*' | ofarc -ttgz -xq -
	cp configure config.h.in objfw-${PACKAGE_VERSION}/
	ofarc -cq objfw-${PACKAGE_VERSION}.tar \
	ofarc -cq objfw-${PACKAGE_VERSION}.tar objfw-${PACKAGE_VERSION}
		$$(find objfw-${PACKAGE_VERSION} | sort)
	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 \
		$$(find objfw-docs-${PACKAGE_VERSION} | sort)
		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 PLATFORMS.md from [74dca258ba] to [cb8b9b98c6].

150
151
152
153
154
155
156










157
158
159
160
161
162
163
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173







+
+
+
+
+
+
+
+
+
+








  * Architectures: ARM (EABI)
  * Compilers: GCC 4.8.2 (devkitARM release 42)
  * Runtimes: ObjFW
  * Limitations: No threads, no sockets
  * Notes: File support requires an argv-compatible launcher (such as HBMenu)


Nintendo Switch
---------------

  * OS Versions: yuzu 1093
  * Architectures: AArch64
  * Compilers: GCC 12.1.0 (devkitA64 release 19) 
  * Runtimes: ObjFW
  * Limitations: No sockets, no shared libraries, not tested on real hardware


OpenBSD
-------

  * OS Versions: 5.2-6.7
  * Architectures: MIPS64, PA-RISC, PowerPC, SPARC64, x86_64
  * Compilers: GCC 6.3.0, Clang 4.0
197
198
199
200
201
202
203











204
205
206
207
208
209
210

211
212
213


214
215
216
217
218
219
220
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







+
+
+
+
+
+
+
+
+
+
+






-
+


-
+
+








  * OS Versions: 4.3E / Homebrew Channel 1.1.0
  * Architectures: PowerPC
  * Compilers: GCC 4.6.3 (devkitPPC release 26)
  * Runtimes: ObjFW
  * Limitations: No threads


Wii U
-----

  * OS Versions: Cemu 12.26.2f
  * Architectures: PowerPC
  * Compilers: gcc version 12.1.0 (devkitPPC release 41)
  * Runtimes: ObjFW
  * Limitations: No files, no threads, no sockets, no shared libraries, not
                 tested on real hardware


Windows
-------

  * OS Versions: 98 SE, NT 4.0, XP (x86), 7 (x64), 8 (x64), 8.1 (x64), 10, 11,
                 Wine (x86 & x64)
  * Architectures: x86, x86_64
  * Architectures: x86, x86_64, AArch64
  * Compilers: GCC 5.3.0 & 6.2.0 from msys2 (x86 & x64),
               Clang 3.9.0 from msys2 (x86),
               Clang 10.0 from msys2 (x86 & x86_64)
               Clang 10.0 from msys2 (x86 & x86_64),
               Clang 14.0.4 from msys2 (AArch64)
  * Runtimes: ObjFW


Others
------

Basically, it should run on any POSIX system to which GCC >= 4.6 or a recent

Modified README.md from [cc434070e1] to [711c05e9ce].

29
30
31
32
33
34
35

36
37
38
39
40
41
42
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43







+







     * [Wii](#wii)
   * [Amiga](#amiga)
 * [Writing your first application with ObjFW](#first-app)
 * [Documentation](#documentation)
 * [Bugs and feature requests](#bugs)
 * [Support and community](#support)
 * [Donating](#donating)
 * [Thanks](#thanks)
 * [Commercial use](#commercial-use)


<h1 id="what">What is ObjFW?</h1>

  ObjFW is a portable, lightweight framework for the Objective-C language. It
  enables you to write an application in Objective-C that will run on any
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
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







-
+
+

+
+
+
+
-
+







-
+
+







    $ ./autogen.sh

<h2 id="macos-and-ios">macOS and iOS</h2>

<h3 id="building-framework">Building as a framework</h3>

  When building for macOS or iOS, everything is built as a `.framework` by
  default if `--disable-shared` has not been specified to `configure`.
  default if `--disable-shared` has not been specified to `./configure`. The
  frameworks will end up in `$PREFIX/Library/Frameworks`.

  To build for macOS, just follow the
  <a href="#installation">regular instructions</a> above.

  To build for iOS, follow the regular instructions, but instead of
  To build for iOS, use something like this:
  `./configure` do something like this:

    $ clang="clang -isysroot $(xcrun --sdk iphoneos --show-sdk-path)"
    $ export OBJC="$clang -arch armv7 -arch arm64"
    $ export OBJCPP="$clang -arch armv7 -E"
    $ export IPHONEOS_DEPLOYMENT_TARGET="9.0"
    $ ./configure --prefix=/usr/local/ios --host=arm64-apple-darwin

  To build for the iOS simulator, use something like this:
  To build for the iOS simulator, follow the regular instructions, but instead
  of `./configure` use something like this:

    $ clang="clang -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)"
    $ export OBJC="$clang -arch arm64 -arch x86_64"
    $ export OBJCPP="$clang -arch arm64 -E"
    $ export IPHONEOS_DEPLOYMENT_TARGET="9.0"
    $ ./configure --prefix=/usr/local/iossim --host=arm64-apple-darwin

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
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 5 different
  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.

  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
  For MINGW64, use:

  recommended ones.
    $ pacman -Syu mingw-w64-x86_64-clang mingw-w64-x86_64-fossil

  For UCRT64, use:

    $ pacman -Syu mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-fossil

  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.
300
301
302
303
304
305
306
307

308
309
310
311
312
313
314
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
    $ 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!"];
366
367
368
369
370
371
372









373
374
375
376
377
378
379
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405







+
+
+
+
+
+
+
+
+









<h1 id="donating">Donating</h1>

  If you want to donate to ObjFW, you can read about possible ways to do so
  [here](https://objfw.nil.im/wiki?name=Donating).


<h1 id="thanks">Thanks</h1>

  * Thank you to [Jonathan Neuschäfer](https://github.com/neuschaefer) for
    reviewing the *entirety* (all 84k LoC at the time) of ObjFW's codebase in
    2017!
  * Thank you to [Hill Ma](https://github.com/mahiuchun) for donating an M1 Mac
    Mini to the project!


<h1 id="commercial-use">Commercial use</h1>

  If for whatever reason neither the terms of the QPL nor those of the GPL work
  for you, a proprietary license for ObjFW including support is available upon
  request. Just write a mail to js@nil.im and we can find a reasonable solution
  for both parties.

Modified build-aux/m4/buildsys.m4 from [824bccf73b] to [0e90ccf38e].

205
206
207
208
209
210
211
212

213
214
215
216
217
218
219
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='&& ${LN_S} $$out lib$${out%${LIB_SUFFIX}}.dll.a'
		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
84

85
86
87
88
89
90
91
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@
WINDRES = @WINDRES@
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
582

583
584
585
586
587
588
589
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 ${WINDRES} ${CPPFLAGS} -J rc -O coff -o $@ $<; then \
	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
776

777
778
779
780
781
782
783
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; then \
		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 [953d9f0c40] to [998091ff78].

94
95
96
97
98
99
100
101

102
103
104
105
106
107
108
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







-
+







	;;
*-msdosdjgpp*)
	enable_shared="no"
	enable_threads="no"
	enable_sockets="no"
	;;
*-*-mingw*)
	LDFLAGS="$LDFLAGS -Wl,--allow-multiple-definition"
	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.])
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
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







+








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+














+









-















+











-


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.])
	])

	flags="-mrvl -mcpu=750 -meabi -mhard-float"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	CPPFLAGS="$CPPFLAGS -DGEKKO -I$DEVKITPRO/libogc/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DGEKKO -I\$DEVKITPRO/libogc/include"
	LDFLAGS="$LDFLAGS -mrvl -mcpu=750 -meabi -mhard-float"
	LIBS="$LIBS -L$DEVKITPRO/libogc/lib/wii -lfat -logc"
	TESTS_LIBS="$TESTS_LIBS -lwiiuse -lbte"
	enable_shared="no"
	enable_threads="no"	# TODO
	with_tls="no"

	AC_DEFINE(OF_WII, 1, [Whether we are compiling for Wii])
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

AC_ARG_WITH(wii-u,
	AS_HELP_STRING([--with-wii-u], [build for Wii U]))
AS_IF([test x"$with_wii_u" = x"yes"], [
	AS_IF([test x"$DEVKITPRO" = x""], [
		AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.])
	])

	flags="-mcpu=750 -meabi -mhard-float"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	CPPFLAGS="-isystem $DEVKITPRO/wut/include -D__WIIU__ -D__WUT__"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -isystem \$DEVKITPRO/wut/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DGEKKO -I\$DEVKITPRO/libogc/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__WIIU__ -D__WUT__"
	LDFLAGS="-specs=$DEVKITPRO/wut/share/wut.specs"
	LIBS="-L$DEVKITPRO/wut/lib -L$DEVKITPRO/wut/lib/stubs -lwut"
	enable_files="no"	# TODO
	enable_shared="no"	# TODO
	enable_threads="no"	# TODO
	enable_sockets="no"	# TODO

	AC_DEFINE(OF_WII_U, 1, [Whether we are compiling for Wii U])
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

AC_ARG_WITH(nds,
	AS_HELP_STRING([--with-nds], [build for Nintendo DS]))
AS_IF([test x"$with_nds" = x"yes"], [
	AS_IF([test x"$DEVKITPRO" = x""], [
		AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.])
	])

	flags="-march=armv5te -mtune=arm946e-s -mthumb -mthumb-interwork"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	CPPFLAGS="$CPPFLAGS -DARM9 -I$DEVKITPRO/libnds/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM9 -I\$DEVKITPRO/libnds/include"
	ASFLAGS="$ASFLAGS -march=armv5te"
	LDFLAGS="$LDFLAGS -specs=ds_arm9.specs"
	LIBS="$LIBS -L$DEVKITPRO/libnds/lib -lfilesystem -lfat -lnds9"
	enable_shared="no"
	enable_threads="no"	# TODO
	enable_sockets="no"	# TODO
	check_pedantic="no"

	AC_DEFINE(OF_NINTENDO_DS, 1, [Whether we are compiling for Nintendo DS])
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM9 -I\$DEVKITPRO/libnds/include"
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

AC_ARG_WITH(3ds,
	AS_HELP_STRING([--with-3ds], [build for Nintendo 3DS]))
AS_IF([test x"$with_3ds" = x"yes"], [
	AS_IF([test x"$DEVKITPRO" = x""], [
		AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.])
	])

	flags="-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft"
	flags="$flags -mword-relocations"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	CPPFLAGS="$CPPFLAGS -DARM11 -I$DEVKITPRO/libctru/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM11 -I\$DEVKITPRO/libctru/include"
	ASFLAGS="$ASFLAGS -march=armv6k"
	LDFLAGS="$LDFLAGS -specs=3dsx.specs -march=armv6k -mtune=mpcore"
	LDFLAGS="$LDFLAGS -mfloat-abi=hard -mtp=soft -mword-relocations"
	LIBS="$LIBS -L$DEVKITPRO/libctru/lib -lctru"
	enable_shared="no"
	enable_threads="no"	# TODO
	with_tls="no"
	check_pedantic="no"

	AC_DEFINE(OF_NINTENDO_3DS, 1,
		[Whether we are compiling for Nintendo 3DS])
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -DARM11 -I\$DEVKITPRO/libctru/include"
	AC_SUBST(MAP_LDFLAGS, ['-Wl,-Map,$@.map'])
])

AC_ARG_WITH(nintendo-switch,
	AS_HELP_STRING([--with-nintendo-switch], [build for Nintendo Switch]))
AS_IF([test x"$with_nintendo_switch" = x"yes"], [
	AS_IF([test x"$DEVKITPRO" = x""], [
		AC_MSG_ERROR([DEVKITPRO is not set! Please set DEVKITPRO.])
	])

	flags="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE"
	OBJCFLAGS="$OBJCFLAGS $flags"
	OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
	CPPFLAGS="$CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include"
	OBJFW_CPPFLAGS="$OBJFW_CPPFLAGS -D__SWITCH__ -I$DEVKITPRO/libnx/include"
	ASFLAGS="$ASFLAGS $flags"
	LDFLAGS="$LDFLAGS -specs=$DEVKITPRO/libnx/switch.specs $flags"
	LIBS="$LIBS -L$DEVKITPRO/libnx/lib -lnx"
	enable_shared="no"
	enable_threads="yes"
	enable_sockets="no"	# TODO
	check_pedantic="no"

	AC_DEFINE(OF_NINTENDO_SWITCH, 1,
		[Whether we are compiling for Nintendo Switch])
])

CPP="$OBJCPP"
CPPFLAGS="$CPPFLAGS $OBJCPPFLAGS -DOF_COMPILING_OBJFW"
flags="-fexceptions -fobjc-exceptions -funwind-tables"
flags="$flags -fconstant-string-class=OFConstantString"
OBJCFLAGS="$OBJCFLAGS -Wall $flags"
OBJFW_OBJCFLAGS="$OBJFW_OBJCFLAGS $flags"
348
349
350
351
352
353
354






355
356
357
358
359
360
361
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415







+
+
+
+
+
+







], [
	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(shared,
	AS_HELP_STRING([--disable-shared], [do not build shared library]))
AS_IF([test x"$enable_shared" != x"no"], [
	BUILDSYS_SHARED_LIB
	AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}")
	AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a")
426
427
428
429
430
431
432

433
434
435
436
437
438
439
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494







+








	#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
994
995
996
997
998
999
1000




1001
1002
1003
1004
1005
1006
1007
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066







+
+
+
+







		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

1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243







+







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.
		;;
1336
1337
1338
1339
1340
1341
1342



1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409



1410
1411
1412
1413
1414
1415
1416







+
+
+




-
-
-







			[Whether we have netinet/in.h])
	])
	AC_CHECK_HEADER(netinet/tcp.h, [
		AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1,
			[Whether we have netinet/tcp.h])
	])
	AC_CHECK_HEADERS([arpa/inet.h netdb.h])
	AC_CHECK_HEADER(sys/un.h, [
		AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h])
	])
	AC_CHECK_HEADER(netipx/ipx.h, [
		AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1,
			[Whether we have netipx/ipx.h])
	])
	AC_CHECK_HEADER(sys/un.h, [
		AC_DEFINE(OF_HAVE_SYS_UN_H, 1, [Whether we have sys/un.h])
	])

	AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [
		AC_EGREP_CPP(egrep_cpp_yes, [
			#ifdef _WIN32
			typedef int BOOL;
			#endif

1395
1396
1397
1398
1399
1400
1401


































1402
1403
1404
1405
1406
1407
1408
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		#   include <winsock2.h>
		#  endif
		# endif
		# include <windows.h>
		# include <ws2tcpip.h>
		#endif
	])

	AC_CHECK_HEADERS(afunix.h, [
		AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h])
	], [], [
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
	])
	AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [
		AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1,
			[Whether we have UNIX sockets])
		AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}')
	], [], [
		#ifdef OF_HAVE_SYS_TYPES_H
		# include <sys/types.h>
		#endif
		#ifdef OF_HAVE_SYS_UN_H
		# include <sys/un.h>
		#endif
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
		#ifdef HAVE_AFUNIX_H
		# include <afunix.h>
		#endif

		#ifdef __morphos__
		# error MorphOS has the struct but does not support it
		#endif

		#ifdef __MINT__
		# error Gives invalid argument at runtime
		#endif
	])

	AC_CHECK_MEMBER(struct sockaddr_ipx.sipx_network, [], [
		AC_CHECK_MEMBER(struct sockaddr_ipx.sa_netnum, [], [], [
			#ifdef _WIN32
			typedef int BOOL;
			#endif

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1562
1563
1564
1565
1566
1567
1568


































1569
1570
1571
1572
1573
1574
1575







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







			#endif
		], [
			AC_DEFINE(OF_HAVE_IPX, 1, [Whether we have IPX/SPX])
			AC_SUBST(USE_SRCS_IPX, '${SRCS_IPX}')
		])
	])

	AC_CHECK_HEADERS(afunix.h, [
		AC_DEFINE(OF_HAVE_AFUNIX_H, 1, [Whether we have afunix.h])
	], [], [
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
	])
	AC_CHECK_MEMBER(struct sockaddr_un.sun_path, [
		AC_DEFINE(OF_HAVE_UNIX_SOCKETS, 1,
			[Whether we have UNIX sockets])
		AC_SUBST(USE_SRCS_UNIX_SOCKETS, '${SRCS_UNIX_SOCKETS}')
	], [], [
		#ifdef OF_HAVE_SYS_TYPES_H
		# include <sys/types.h>
		#endif
		#ifdef OF_HAVE_SYS_UN_H
		# include <sys/un.h>
		#endif
		#ifdef _WIN32
		# include <winsock2.h>
		#endif
		#ifdef HAVE_AFUNIX_H
		# include <afunix.h>
		#endif

		#ifdef __morphos__
		# error MorphOS has the struct but does not support it
		#endif

		#ifdef __MINT__
		# error Gives invalid argument at runtime
		#endif
	])

	AC_CHECK_FUNCS(paccept accept4, break)

	AC_CHECK_FUNCS(kqueue1 kqueue, [
		AC_DEFINE(HAVE_KQUEUE, 1, [Whether we have kqueue])
		AC_SUBST(OF_KQUEUE_KERNEL_EVENT_OBSERVER_M,
			"OFKqueueKernelEventObserver.m")
		break

Modified extra.mk.in from [8ae8820dcd] to [a3fba56a2a].

39
40
41
42
43
44
45

46
47
48
49
50
51
52
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53







+







LIBOBJFW_DEP_LVL2 = @LIBOBJFW_DEP_LVL2@
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_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 [1dc8a4f1e6] to [69ede2939c].

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
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







-
+














-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 */

#include "config.h"

#import "OFApplication.h"
#import "OFFile.h"
#import "OFFileManager.h"
#import "OFURL.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)applicationDidFinishLaunching
{
	OFURL *sourcesURL = [[OFFileManager defaultManager].currentDirectoryURL
	    URLByAppendingPathComponent: @"../../src"];
	OFURL *runtimeLibraryURL = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/amiga-library.xml"];
	OFURL *runtimeLinkLibURL = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/linklib/linklib.m"];
	OFURL *runtimeGlueHeaderURL = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/amiga-glue.h"];
	OFURL *runtimeGlueURL = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/amiga-glue.m"];
	OFURL *runtimeFuncArrayURL = [sourcesURL
	    URLByAppendingPathComponent: @"runtime/amiga-funcarray.inc"];
	OFURI *sourcesURI = [[OFFileManager defaultManager].currentDirectoryURI
	    URIByAppendingPathComponent: @"../../src"];
	OFURI *runtimeLibraryURI = [sourcesURI
	    URIByAppendingPathComponent: @"runtime/amiga-library.xml"];
	OFURI *runtimeLinkLibURI = [sourcesURI
	    URIByAppendingPathComponent: @"runtime/linklib/linklib.m"];
	OFURI *runtimeGlueHeaderURI = [sourcesURI
	    URIByAppendingPathComponent: @"runtime/amiga-glue.h"];
	OFURI *runtimeGlueURI = [sourcesURI
	    URIByAppendingPathComponent: @"runtime/amiga-glue.m"];
	OFURI *runtimeFuncArrayURI = [sourcesURI
	    URIByAppendingPathComponent: @"runtime/amiga-funcarray.inc"];
	OFXMLElement *runtimeLibrary = [OFXMLElement elementWithStream:
	    [OFFile fileWithURL: runtimeLibraryURL
			   mode: @"r"]];
	OFFile *runtimeLinkLib = [OFFile fileWithURL: runtimeLinkLibURL
						mode: @"w"];
	OFFile *runtimeGlueHeader = [OFFile fileWithURL: runtimeGlueHeaderURL
						   mode: @"w"];
	OFFile *runtimeGlue = [OFFile fileWithURL: runtimeGlueURL
					     mode: @"w"];
	OFFile *runtimeFuncArray = [OFFile fileWithURL: runtimeFuncArrayURL
						  mode: @"w"];
	    [OFFile fileWithPath: runtimeLibraryURI.fileSystemRepresentation
			    mode: @"r"]];
	OFFile *runtimeLinkLib =
	    [OFFile fileWithPath: runtimeLinkLibURI.fileSystemRepresentation
			    mode: @"w"];
	OFFile *runtimeGlueHeader =
	    [OFFile fileWithPath: runtimeGlueHeaderURI.fileSystemRepresentation
			    mode: @"w"];
	OFFile *runtimeGlue =
	    [OFFile fileWithPath: runtimeGlueURI.fileSystemRepresentation
			    mode: @"w"];
	OFFile *runtimeFuncArray =
	    [OFFile fileWithPath: runtimeFuncArrayURI.fileSystemRepresentation
			    mode: @"w"];
	LinkLibGenerator *runtimeLinkLibGenerator = [[[LinkLibGenerator alloc]
	    initWithLibrary: runtimeLibrary
	     implementation: runtimeLinkLib] autorelease];
	GlueGenerator *runtimeGlueGenerator = [[[GlueGenerator alloc]
	    initWithLibrary: runtimeLibrary
		     header: runtimeGlueHeader
	     implementation: runtimeGlue] autorelease];

Modified generators/unicode/TableGenerator.m from [f2c27273a6] to [c1835e042f].

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
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







-
+











-
+

-
+




















-

+











-
-
+
+







#include "config.h"

#include <string.h>

#import "OFString.h"
#import "OFArray.h"
#import "OFApplication.h"
#import "OFURL.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 unicodeDataURL =
static OFString *const unicodeDataURI =
    @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt";
static OFString *const caseFoldingURL =
static OFString *const caseFoldingURI =
    @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt";

OF_APPLICATION_DELEGATE(TableGenerator)

@implementation TableGenerator
- (instancetype)init
{
	self = [super init];

	@try {
		_HTTPClient = [[OFHTTPClient alloc] init];
		_HTTPClient.delegate = self;

		_uppercaseTableSize           = SIZE_MAX;
		_lowercaseTableSize           = SIZE_MAX;
		_titlecaseTableSize           = SIZE_MAX;
		_caseFoldingTableSize         = SIZE_MAX;
		_decompositionTableSize       = SIZE_MAX;
		_decompositionCompatTableSize = SIZE_MAX;
	} @catch (id e) {
		@throw e;
		[self release];
		@throw e;
	}

	return self;
}

- (void)applicationDidFinishLaunching
{
	OFHTTPRequest *request;

	[OFStdOut writeString: @"Downloading UnicodeData.txt…"];
	_state = stateUnicodeData;
	request = [OFHTTPRequest requestWithURL:
	    [OFURL URLWithString: unicodeDataURL]];
	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
140

141
142
143
144
145
146
147
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:
				    OFRangeMake(1, decomposed.count - 1)];
				    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
171
172


173
174
175
176
177
178
179
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 requestWithURL:
	    [OFURL URLWithString: caseFoldingURL]];
	request = [OFHTTPRequest requestWithURI:
	    [OFURI URIWithString: caseFoldingURI]];
	[_HTTPClient asyncPerformRequest: request];
}

- (void)parseCaseFolding: (OFHTTPResponse *)response
{
	OFString *line;

266
267
268
269
270
271
272
273

274
275
276
277
278


279
280
281


282
283
284
285
286
287
288
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
{
	OFURL *URL;
	OFURI *URI;

	[OFStdOut writeString: @"Writing files…"];

	URL = [OFURL fileURLWithPath: @"../../src/unicode.m"];
	[self writeTablesToFile: URL.fileSystemRepresentation];
	URI = [OFURI fileURIWithPath: @"../../src/unicode.m"];
	[self writeTablesToFile: URI.fileSystemRepresentation];

	URL = [OFURL fileURLWithPath: @"../../src/unicode.h"];
	[self writeHeaderToFile: URL.fileSystemRepresentation];
	URI = [OFURI fileURIWithPath: @"../../src/unicode.h"];
	[self writeHeaderToFile: URI.fileSystemRepresentation];

	[OFStdOut writeLine: @" done"];

	[OFApplication terminate];
}

- (void)writeTablesToFile: (OFString *)path

Modified src/Makefile from [a18929d7e2] to [bbebb28fe1].

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
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












-
-
+

-

-
-













+
-
+









+











-
+







include ../extra.mk

SUBDIRS = ${RUNTIME} exceptions encodings forwarding
SUBDIRS_AFTER = ${BRIDGE} ${TLS}
DISTCLEAN = Info.plist objfw-defs.h

SHARED_LIB = ${OBJFW_SHARED_LIB}
STATIC_LIB = ${OBJFW_STATIC_LIB}
FRAMEWORK = ${OBJFW_FRAMEWORK}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}

SRCS = OFASPrintF.m			\
       OFApplication.m			\
SRCS = OFApplication.m			\
       OFArray.m			\
       OFBase64.m			\
       OFBlock.m			\
       OFCRC16.m			\
       OFCRC32.m			\
       OFCharacterSet.m			\
       OFColor.m			\
       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			\
       OFHuffmanTree.m			\
       OFINIFile.m			\
       OFInflate64Stream.m		\
       OFInflateStream.m		\
       OFInvocation.m			\
       OFLHAArchive.m			\
       OFLHAArchiveEntry.m		\
       OFList.m				\
       OFLocale.m			\
       OFMD5Hash.m			\
       OFMapTable.m			\
       OFMemoryStream.m			\
       OFMessagePackExtension.m		\
       OFMethodSignature.m		\
       OFMutableArray.m			\
       OFMutableData.m			\
       OFMutableDictionary.m		\
       OFMutableLHAArchiveEntry.m	\
       OFMutablePair.m			\
       OFMutableSet.m			\
       OFMutableString.m		\
       OFMutableTarArchiveEntry.m	\
       OFMutableTriple.m		\
       OFMutableURL.m			\
       OFMutableURI.m			\
       OFMutableZIPArchiveEntry.m	\
       OFNotification.m			\
       OFNotificationCenter.m		\
       OFNull.m				\
       OFNumber.m			\
       OFObject.m			\
       OFObject+KeyValueCoding.m	\
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
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







-




+


-



+






-
-
+
+




















-
-
-







       OFScrypt.m			\
       OFSecureData.m			\
       OFSeekableStream.m		\
       OFSerialization.m		\
       OFSet.m				\
       OFSortedList.m			\
       OFStdIOStream.m			\
       OFStrPTime.m			\
       OFStream.m			\
       OFString.m			\
       OFString+CryptographicHashing.m	\
       OFString+JSONParsing.m		\
       OFString+PercentEncoding.m	\
       OFString+PropertyListParsing.m	\
       OFString+Serialization.m		\
       OFString+URLEncoding.m		\
       OFString+XMLEscaping.m		\
       OFString+XMLUnescaping.m		\
       ${OF_SUBPROCESS_M}		\
       OFSettings.m			\
       OFSystemInfo.m			\
       OFTarArchive.m			\
       OFTarArchiveEntry.m		\
       OFThread.m			\
       OFTimer.m			\
       OFTriple.m			\
       OFURL.m				\
       OFURLHandler.m			\
       OFURI.m				\
       OFURIHandler.m			\
       OFUUID.m				\
       OFValue.m			\
       OFXMLAttribute.m			\
       OFXMLCDATA.m			\
       OFXMLCharacters.m		\
       OFXMLComment.m			\
       OFXMLElement.m			\
       OFXMLElement+Serialization.m	\
       OFXMLElementBuilder.m		\
       OFXMLNode.m			\
       OFXMLParser.m			\
       OFXMLProcessingInstruction.m	\
       OFZIPArchive.m			\
       OFZIPArchiveEntry.m		\
       ${USE_SRCS_FILES}		\
       ${USE_SRCS_PLUGINS}		\
       ${USE_SRCS_SOCKETS}		\
       ${USE_SRCS_THREADS}		\
       ${USE_SRCS_WINDOWS}
SRCS_FILES = OFFile.m			\
	     OFINICategory.m		\
	     OFINIFile.m		\
	     OFSettings.m		\
	     OFString+PathAdditions.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SOCKETS = OFDNSQuery.m			\
	       OFDNSResolver.m			\
	       OFDNSResourceRecord.m		\
	       OFDNSResponse.m			\
	       OFDatagramSocket.m		\
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





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







-
+
-
-
-
+








+







+






+
-
+

+
+


+
+

+
+
+
















+





-
-
+
+
-


-
+







+
+

















+
+
+
+
+
		    OFUNIXStreamSocket.m
SRCS_THREADS = OFCondition.m		\
	       OFMutex.m		\
	       OFPlainCondition.m	\
	       OFPlainMutex.m		\
	       OFPlainThread.m		\
	       OFRecursiveMutex.m	\
	       OFTLSKey.m		\
	       OFTLSKey.m
	       OFThreadPool.m
SRCS_WINDOWS = OFWin32ConsoleStdIOStream.m	\
	       OFWindowsRegistryKey.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			\
SRCS += OFAdjacentArray.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		\
	OFMutableUTF8String.m		\
	OFNonretainedObjectValue.m	\
	OFPointValue.m			\
	OFPointerValue.m		\
	OFRangeCharacterSet.m		\
	OFRangeValue.m			\
	OFRectValue.m			\
	OFSandbox.m			\
	OFSizeValue.m			\
	OFStrPTime.m			\
	OFSubarray.m			\
	OFUTF8String.m			\
	${LIBBASES_M}			\
	${RUNTIME_AUTORELEASE_M}	\
	${RUNTIME_INSTANCE_M}		\
       ${UNICODE_M}
SRCS_FILES += OFFileURLHandler.m	\
	${UNICODE_M}
SRCS_FILES += OFFileURIHandler.m
	      OFINIFileSettings.m
SRCS_SOCKETS += OFDNSResolverSettings.m			\
		${OF_EPOLL_KERNEL_EVENT_OBSERVER_M}	\
		OFHTTPURLHandler.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

include ../buildsys.mk

CPPFLAGS += -I. -I.. -Iexceptions -Iruntime
LD = ${OBJC}
FRAMEWORK_LIBS := -Fruntime				\
		  ${RUNTIME_FRAMEWORK_LIBS}		\
		  ${REEXPORT_RUNTIME_FRAMEWORK}		\
		  ${LIBS}
LIBS := -Lruntime ${RUNTIME_LIBS} ${REEXPORT_RUNTIME} ${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
585

586
587
588
589
590
591
592
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 decimalPoint];
		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.h from [844dffab7b] to [f90f803ff9].

178
179
180
181
182
183
184
185
186
187


188
189
190
191
192
193
194
178
179
180
181
182
183
184



185
186
187
188
189
190
191
192
193







-
-
-
+
+







 * @brief Creates a new OFArray with the objects from the specified C array of
 *	  the specified length.
 *
 * @param objects A C array of objects
 * @param count The length of the C array
 * @return A new autoreleased OFArray
 */
+ (instancetype)
    arrayWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
	       count: (size_t)count;
+ (instancetype)arrayWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
			   count: (size_t)count;

/**
 * @brief Initializes an OFArray with the specified object.
 *
 * @param object An object
 * @return An initialized OFArray
 */
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
432
433
434
435
436
437
438








439
440
441
442
443
444
445







-
-
-
-
-
-
-
-







 *
 * @param array The array with objects to add
 * @return A new array with the objects from the specified array added
 */
- (OFArray OF_GENERIC(ObjectType) *)arrayByAddingObjectsFromArray:
    (OFArray OF_GENERIC(ObjectType) *)array;

/**
 * @brief Creates a new array with the specified object removed.
 *
 * @param object The object to remove
 * @return A new array with the specified object removed
 */
- (OFArray OF_GENERIC(ObjectType) *)arrayByRemovingObject: (ObjectType)object;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Executes a block for each object.
 *
 * @param block The block to execute for each object
 */
- (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block;

Modified src/OFArray.m from [3f7a80c4c6] to [c89de989b4].

238
239
240
241
242
243
244
245

246
247
248
249
250
251
252
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: OFRangeMake(0, count)];
		[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
538

539
540
541
542
543
544
545
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 prependString: @"(\n"];
		[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
754

755
756
757
758
759
760
761
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 = OFRangeMake(state->state, 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;

811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
811
812
813
814
815
816
817








818
819
820
821
822
823
824







-
-
-
-
-
-
-
-







	OFMutableArray *ret = [[self mutableCopy] autorelease];
	[ret addObjectsFromArray: array];
	[ret makeImmutable];

	return ret;
}

- (OFArray *)arrayByRemovingObject: (id)object
{
	OFMutableArray *ret = [[self mutableCopy] autorelease];
	[ret removeObject: object];
	[ret makeImmutable];
	return ret;
}

#ifdef OF_HAVE_BLOCKS
- (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block
{
	OFArray *ret;
	size_t count = self.count;
	id *tmp = OFAllocMemory(count, sizeof(id));

Modified src/OFColor.m from [5191910ddc] to [ff82ab6aae].

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
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++)
		OFHashAdd(&hash, ((char *)&tmp)[i]);
		OFHashAddByte(&hash, ((char *)&tmp)[i]);

	tmp = OFToLittleEndianFloat(_green);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OFHashAdd(&hash, ((char *)&tmp)[i]);
		OFHashAddByte(&hash, ((char *)&tmp)[i]);

	tmp = OFToLittleEndianFloat(_blue);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OFHashAdd(&hash, ((char *)&tmp)[i]);
		OFHashAddByte(&hash, ((char *)&tmp)[i]);

	tmp = OFToLittleEndianFloat(_alpha);
	for (uint_fast8_t i = 0; i < sizeof(float); i++)
		OFHashAdd(&hash, ((char *)&tmp)[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
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 [069ffd9312] to [3adc07df05].

346
347
348
349
350
351
352
353

354
355
356

357
358
359
360
361
362
363
346
347
348
349
350
351
352

353
354
355

356
357
358
359
360
361
362
363







-
+


-
+








- (OFString *)stringByAppendingPathComponent: (OFString *)component
{
	[self finishInitialization];
	return [self stringByAppendingPathComponent: component];
}

- (OFString *)stringByPrependingString: (OFString *)string
- (OFString *)stringByAppendingPathExtension: (OFString *)extension
{
	[self finishInitialization];
	return [self stringByPrependingString: string];
	return [self stringByAppendingPathExtension: extension];
}

- (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string
					withString: (OFString *)replacement
{
	[self finishInitialization];
	return [self stringByReplacingOccurrencesOfString: string
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
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: (int)base
- (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: (int)base
- (unsigned long long)unsignedLongLongValueWithBase: (unsigned char)base
{
	[self finishInitialization];
	return [self unsignedLongLongValueWithBase: base];
}

- (float)floatValue
{
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
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)writeToURL: (OFURL *)URL
- (void)writeToURI: (OFURI *)URI
{
	[self finishInitialization];
	[self writeToURL: URL];
	[self writeToURI: URI];
}

- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	[self finishInitialization];
	[self writeToURL: URL encoding: encoding];
	[self writeToURI: URI encoding: encoding];
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
{
	[self finishInitialization];
	[self enumerateLinesUsingBlock: block];
}
#endif
@end

Modified src/OFCountedMapTableSet.m from [7493fdfb12] to [d7ae224517].

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53







-
+







{
	self = [self init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		if ([set isKindOfClass: [OFCountedSet class]]) {
			OFCountedSet *countedSet = (OFCountedSet *)countedSet;
			OFCountedSet *countedSet = (OFCountedSet *)set;

			for (id object in countedSet) {
				size_t count =
				    [countedSet countForObject: object];

				for (size_t i = 0; i < count; i++)
					[self addObject: object];

Modified src/OFCryptographicHash.h from [21f208b184] to [635d4f982a].

54
55
56
57
58
59
60


61
62
63
64
65
66
67
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
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
33
34
35
36
37
38
39
40
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;
	OF_RESERVE_IVARS(OFDNSQuery, 4)
}

/**
 * @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
100
101


102
103
104
105
106
107
108
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);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType);
	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
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
41

42
43
44
45
46
47
48
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 "OFInvalidServerReplyException.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
131

132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
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 [OFInvalidServerReplyException
				@throw [OFInvalidServerResponseException
				    exception];

			if (*i >= length)
				@throw [OFTruncatedDataException exception];

			j = ((componentLength & 0x3F) << 8) | buffer[(*i)++];

			if (j == *i - 2)
				/* Pointing to itself?! */
				@throw [OFInvalidServerReplyException
				@throw [OFInvalidServerResponseException
				    exception];

			suffix = parseName(buffer, length, &j,
			    pointerLevel - 1);

			if (components.count == 0)
				return suffix;
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
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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		responsiblePerson = parseName(buffer, length, &j,
		    maxAllowedPointers);

		if (dataLength - (j - i) != 20)
			@throw [OFInvalidServerReplyException exception];
			@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
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
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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		OS = parseString(buffer, length, &j);

		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		preference = (buffer[i] << 8) | buffer[i + 1];

		j = i + 2;
		mailExchange = parseName(buffer, length, &j,
		    maxAllowedPointers);

		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException
				@throw [OFInvalidServerResponseException
				    exception];

			[textStrings addObject:
			    [OFData dataWithItems: buffer + i
					    count: stringLength]];

			i += stringLength;
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
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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		TXTDomainName = parseName(buffer, length, &j,
		    maxAllowedPointers);

		if (j != i + dataLength)
			@throw [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@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
389

390
391
392
393
394
395
396
397
398
399

400
401
402
403
404
405
406
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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		return [[[OFSRVDNSResourceRecord alloc]
		    initWithName: name
			priority: priority
			  weight: weight
			  target: target
			    port: port
933
934
935
936
937
938
939
940

941
942
943
944

945
946
947
948
949
950
951
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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		/* Opcode */
		if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78))
			@throw [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];

		/* TC */
		if (buffer[2] & 0x02) {
			OFRunLoopMode runLoopMode;

			if (context->_settings->_usesTCP)
				@throw [OFTruncatedDataException exception];

Modified src/OFDNSResolverSettings.m from [94502fce5f] to [27f5b4db4d].

62
63
64
65
66
67
68




69
70
71
72
73
74
75
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79







+
+
+
+







#elif defined(OF_AMIGAOS)
# define HOSTS_PATH @"AmiTCP:db/hosts"
# define RESOLV_CONF_PATH @"AmiTCP:db/resolv.conf"
#else
# define HOSTS_PATH @"/etc/hosts"
# define RESOLV_CONF_PATH @"/etc/resolv.conf"
#endif

#ifndef HOST_NAME_MAX
# define HOST_NAME_MAX 255
#endif

#ifndef OF_WII
static OFString *
domainFromHostname(OFString *hostname)
{
	OFString *ret;

98
99
100
101
102
103
104
105

106
107

108
109
110
111
112
113
114
102
103
104
105
106
107
108

109
110

111
112
113
114
115
116
117
118







-
+

-
+







}
#endif

#if !defined(OF_WII) && !defined(OF_MORPHOS)
static OFString *
obtainHostname(void)
{
	char hostname[256];
	char hostname[HOST_NAME_MAX + 1];

	if (gethostname(hostname, 256) != 0)
	if (gethostname(hostname, HOST_NAME_MAX + 1) != 0)
		return nil;

	return [OFString stringWithCString: hostname
				  encoding: [OFLocale encoding]];
}
#endif

174
175
176
177
178
179
180
181

182
183
184
185
186
187
188
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: OFRangeMake(1, string.length - 2)];
	string = [string substringWithRange: OFMakeRange(1, string.length - 2)];

	return [string componentsSeparatedByString: @"|"];
}
#endif

@implementation OFDNSResolverSettings
- (void)dealloc
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
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:
		    OFRangeMake(1, components.count - 1)];
		    OFMakeRange(1, components.count - 1)];

		for (OFString *host in hosts) {
			OFMutableArray *addresses =
			    [staticHosts objectForKey: host];

			if (addresses == nil) {
				addresses = [OFMutableArray array];
381
382
383
384
385
386
387
388

389
390
391
392
393
394
395
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:
		    OFRangeMake(1, components.count - 1)];
		    OFMakeRange(1, components.count - 1)];

		if ([option isEqual: @"nameserver"]) {
			if (arguments.count != 1) {
				objc_autoreleasePoolPop(pool2);
				continue;
			}

480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
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:
		    OFRangeMake(1, components.count - 1)];
		    OFMakeRange(1, components.count - 1)];

		for (OFString *host in hosts) {
			OFMutableArray *addresses =
			    [staticHosts objectForKey: host];

			if (addresses == nil) {
				addresses = [OFMutableArray array];
615
616
617
618
619
620
621
622


623
624
625
626
627
628
629
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"
	    securityAndAccessRights: KEY_QUERY_VALUE];
		       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
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
22
23
24
25
26
27
28
29
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 "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"

OFString *
OFDNSClassName(OFDNSClass DNSClass)
{
	switch (DNSClass) {
	case OFDNSClassIN:
75
76
77
78
79
80
81
82
83
84


85
86
87
88
89
90
91
92
93
94
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 {
		@try {
			DNSClass = (OFDNSClass)
			    [string unsignedLongLongValueWithBase: 0];
		DNSClass =
		    (OFDNSClass)[string unsignedLongLongValueWithBase: 0];
		} @catch (OFInvalidFormatException *e) {
			@throw [OFInvalidArgumentException exception];
		}
	}

	objc_autoreleasePoolPop(pool);

	return DNSClass;
}

121
122
123
124
125
126
127
128
129
130


131
132
133
134
135
136
137
138
139
140
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 {
		@try {
			recordType = (OFDNSRecordType)
			    [string unsignedLongLongValueWithBase: 0];
		recordType =
		    (OFDNSRecordType)[string unsignedLongLongValueWithBase: 0];
		} @catch (OFInvalidFormatException *e) {
			@throw [OFInvalidArgumentException exception];
		}
	}

	objc_autoreleasePoolPop(pool);

	return recordType;
}

246
247
248
249
250
251
252
253
254
255
256




257
258
259
260
261
262
263
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
338
339
340
341




342
343
344
345
346
347
348
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
433
434
435
436




437
438
439
440
441
442
443
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
535
536
537
538




539
540
541
542
543
544
545
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
639
640
641
642
643
644






645
646
647
648
649
650
651
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	OFHashAdd(&hash, _preference >> 8);
	OFHashAdd(&hash, _preference);
	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
740
741
742
743




744
745
746
747
748
749
750
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
838
839
840
841




842
843
844
845
846
847
848
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
943
944
945
946




947
948
949
950
951
952
953
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
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
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	OFHashAddByte(&hash, _DNSClass >> 8);
	OFHashAddByte(&hash, _DNSClass);
	OFHashAddByte(&hash, _recordType >> 8);
	OFHashAddByte(&hash, _recordType);
	OFHashAddHash(&hash, _primaryNameServer.hash);
	OFHashAddHash(&hash, _responsiblePerson.hash);
	OFHashAdd(&hash, _serialNumber >> 24);
	OFHashAdd(&hash, _serialNumber >> 16);
	OFHashAdd(&hash, _serialNumber >> 8);
	OFHashAdd(&hash, _serialNumber);
	OFHashAdd(&hash, _refreshInterval >> 24);
	OFHashAdd(&hash, _refreshInterval >> 16);
	OFHashAdd(&hash, _refreshInterval >> 8);
	OFHashAdd(&hash, _refreshInterval);
	OFHashAdd(&hash, _retryInterval >> 24);
	OFHashAdd(&hash, _retryInterval >> 16);
	OFHashAdd(&hash, _retryInterval >> 8);
	OFHashAdd(&hash, _retryInterval);
	OFHashAdd(&hash, _expirationInterval >> 24);
	OFHashAdd(&hash, _expirationInterval >> 16);
	OFHashAdd(&hash, _expirationInterval >> 8);
	OFHashAdd(&hash, _expirationInterval);
	OFHashAdd(&hash, _minTTL >> 24);
	OFHashAdd(&hash, _minTTL >> 16);
	OFHashAdd(&hash, _minTTL >> 8);
	OFHashAdd(&hash, _minTTL);
	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
1220
1221
1222
1223
1224
1225
1226
1227








1228
1229
1230


1231
1232
1233
1234
1235
1236
1237
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	OFHashAdd(&hash, _priority >> 8);
	OFHashAdd(&hash, _priority);
	OFHashAdd(&hash, _weight >> 8);
	OFHashAdd(&hash, _weight);
	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);
	OFHashAdd(&hash, _port >> 8);
	OFHashAdd(&hash, _port);
	OFHashAddByte(&hash, _port >> 8);
	OFHashAddByte(&hash, _port);

	OFHashFinalize(&hash);

	return hash;
}

- (OFString *)description
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328




1329
1330
1331
1332
1333
1334
1335
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);
	OFHashAdd(&hash, _DNSClass >> 8);
	OFHashAdd(&hash, _DNSClass);
	OFHashAdd(&hash, _recordType >> 8);
	OFHashAdd(&hash, _recordType);
	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
37
38
39
40
41
42
43
44
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;
	OF_RESERVE_IVARS(OFDNSResponse, 4)
}

/**
 * @brief The domain name of the response.
 */
@property (readonly, nonatomic) OFString *domainName;

Modified src/OFDNSResponse.m from [815c0760a5] to [6e61ece6f0].

52
53
54
55
56
57
58
59

60
61
62
63
64
65
66
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66







-
+







		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init OF_UNAVAILABLE
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_domainName release];

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
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 [9d153a29a2] to [750f7eff94].

18
19
20
21
22
23
24
25

26
27
28
29
30
31
32
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 OFURL;
@class OFURI;

/**
 * @brief Options for searching in data.
 *
 * This is a bit mask.
 */
typedef enum {
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
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







-
+



-
+


















-
+
+







 *
 * For security reasons, serialization and deserialization is only implemented
 * for OFData with item size 1.
 */
@interface OFData: OFObject <OFCopying, OFMutableCopying, OFComparing,
    OFSerialization, OFMessagePackRepresentation>
{
	unsigned char *_items;
	unsigned char *_Nullable _items;
	size_t _count, _itemSize;
	bool _freeWhenDone;
@private
	OFData *_parentData;
	OFData *_Nullable _parentData;
	OF_RESERVE_IVARS(OFData, 4)
}

/**
 * @brief The size of a single item in the OFData in bytes.
 */
@property (readonly, nonatomic) size_t itemSize;

/**
 * @brief The number of items in the OFData.
 */
@property (readonly, nonatomic) size_t count;

/**
 * @brief All elements of the OFData as a C array.
 *
 * @warning The pointer is only valid until the OFData is changed!
 */
@property (readonly, nonatomic) const void *items OF_RETURNS_INNER_POINTER;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *items
    OF_RETURNS_INNER_POINTER;

/**
 * @brief The first item of the OFData or `NULL`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) const void *firstItem
    OF_RETURNS_INNER_POINTER;

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
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







-
+

-
+


-
+



-
+

-
+

+
+









+
+




-
+









-
+







 * @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 URL.
 *	  the specified URI.
 *
 * @param URL The URL to the contents for the OFData
 * @param URI The URI to the contents for the OFData
 * @return A new autoreleased OFData
 */
+ (instancetype)dataWithContentsOfURL: (OFURL *)URL;
+ (instancetype)dataWithContentsOfURI: (OFURI *)URI;

/**
 * @brief Creates a new OFData with an item size of 1, containing the data of
 *	  the string representation.
 *	  the hex string representation.
 *
 * @param string The string representation of the data
 * @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 Initialized an already allocated OFData with the specified `count`
 * @brief Initializes an already allocated OFData with the specified `count`
 *	  items of size 1.
 *
 * @param items The items to store in the OFData
 * @param count The number of items
 * @return An initialized OFData
 */
- (instancetype)initWithItems: (const void *)items count: (size_t)count;

/**
 * @brief Initialized an already allocated OFData with the specified `count`
 * @brief Initializes an already allocated OFData with the specified `count`
 *	  items of the specified size.
 *
 * @param items The items to store in the OFData
 * @param count The number of items
 * @param itemSize The item size of a single item in bytes
 * @return An initialized OFData
 */
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
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 URL.
 *	  containing the data of the specified URI.
 *
 * @param URL The URL to the contents for the OFData
 * @param URI The URI to the contents for the OFData
 * @return A new autoreleased OFData
 */
- (instancetype)initWithContentsOfURL: (OFURL *)URL;
- (instancetype)initWithContentsOfURI: (OFURI *)URI;

/**
 * @brief Initializes an already allocated OFData with an item size of 1,
 *	  containing the data of the string representation.
 *	  containing the data of the hex string representation.
 *
 * @param string The string representation of the data
 * @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
333
334
335
336
337
338
339
340

341
342

343
344

345
346
347
348
349
350
351
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 URL.
 * @brief Writes the OFData to the specified URI.
 *
 * @param URL The URL to write to
 * @param URI The URI to write to
 */
- (void)writeToURL: (OFURL *)URL;
- (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
32
33


34
35
36
37
38

39
40
41
42
43
44
45
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 "OFURL.h"
#import "OFURLHandler.h"
#import "OFURI.h"
#import "OFURIHandler.h"
#import "OFXMLElement.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.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
96

97
98

99
100
101
102
103
104
105
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)dataWithContentsOfURL: (OFURL *)URL
+ (instancetype)dataWithContentsOfURI: (OFURI *)URI
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
	return [[[self alloc] initWithContentsOfURI: URI] autorelease];
}

+ (instancetype)dataWithStringRepresentation: (OFString *)string
{
	return [[[self alloc]
	    initWithStringRepresentation: string] autorelease];
}
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
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)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFURLHandler *URLHandler;
		OFStream *stream;
		OFStream *stream = [OFURIHandler openItemAtURI: URI mode: @"r"];
		size_t pageSize;
		unsigned char *buffer;

		if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
			@throw [OFUnsupportedProtocolException
			    exceptionWithURL: URL];

		stream = [URLHandler openItemAtURL: URL mode: @"r"];

		_count = 0;
		_itemSize = 1;
		_freeWhenDone = true;

		pageSize = [OFSystemInfo pageSize];
		buffer = OFAllocMemory(1, pageSize);

480
481
482
483
484
485
486
487

488
489
490
491
492
493
494
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++)
		OFHashAdd(&hash, ((uint8_t *)_items)[i]);
		OFHashAddByte(&hash, ((uint8_t *)_items)[i]);

	OFHashFinalize(&hash);

	return hash;
}

- (OFData *)subdataWithRange: (OFRange)range
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
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 OFRangeMake(0, 0);
		return OFMakeRange(0, 0);

	if (searchLength > range.length)
		return OFRangeMake(OFNotFound, 0);
		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 OFRangeMake(i, searchLength);
				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 OFRangeMake(i, searchLength);
				return OFMakeRange(i, searchLength);
	}

	return OFRangeMake(OFNotFound, 0);
	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)writeToURL: (OFURL *)URL
- (void)writeToURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	OFURLHandler *URLHandler;

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	[[URLHandler openItemAtURL: URL mode: @"w"] writeData: self];
	[[OFURIHandler openItemAtURI: URI mode: @"w"] writeData: self];

	objc_autoreleasePoolPop(pool);
}

- (OFXMLElement *)XMLElementBySerializing
{
	void *pool;
	OFXMLElement *element;

	if (_itemSize != 1)
		@throw [OFInvalidArgumentException exception];
		@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 [OFInvalidArgumentException exception];
		@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 [22b01704fe] to [777d90d4d3].

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
37
38
39
40
41
42
43


44
45
46
47
48

49
50
51
52
53
54
55







-
-





-







 */
typedef bool (^OFDatagramSocketAsyncReceiveBlock)(size_t length,
    const OFSocketAddress *_Nonnull sender, id _Nullable exception);

/**
 * @brief A block which is called when a packet has been sent.
 *
 * @param data The data which was sent
 * @param receiver The receiver for the packet
 * @param exception An exception which occurred while reading or `nil` on
 *		    success
 * @return The data to repeat the send with or nil if it should not repeat
 */
typedef OFData *_Nullable (^OFDatagramSocketAsyncSendDataBlock)(
    OFData *_Nonnull data, const OFSocketAddress *_Nonnull receiver,
    id _Nullable exception);
#endif

/**
 * @protocol OFDatagramSocketDelegate OFDatagramSocket.h \
 *	     ObjFW/OFDatagramSocket.h
 *
116
117
118
119
120
121
122


123
124
125
126
127


128
129
130
131
132
133
134
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
150
151
152
153
154
155
156


157
158
159
160
161
162
163
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
229
230
231
232
233
234
235


236
237
238
239
240
241
242
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.
296
297
298
299
300
301
302


303
304
305
306
307
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/OFDatagramSocket.m from [57abed2c44] to [bbb2f277d7].

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
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







-
+









-
+






-
+








-
-
-
-
-




+
+
+
+
+







	if (_socket == OFInvalidSocketHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	sender->length = (socklen_t)sizeof(sender->sockaddr);

#ifndef OF_WINDOWS
	if ((ret = recvfrom(_socket, buffer, length, 0,
	    &sender->sockaddr.sockaddr, &sender->length)) < 0)
	    (struct sockaddr *)&sender->sockaddr, &sender->length)) < 0)
		@throw [OFReadFailedException
		    exceptionWithObject: self
			requestedLength: length
				  errNo: OFSocketErrNo()];
#else
	if (length > INT_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = recvfrom(_socket, buffer, (int)length, 0,
	    &sender->sockaddr.sockaddr, &sender->length)) < 0)
	    (struct sockaddr *)&sender->sockaddr, &sender->length)) < 0)
		@throw [OFReadFailedException
		    exceptionWithObject: self
			requestedLength: length
				  errNo: OFSocketErrNo()];
#endif

	switch (sender->sockaddr.sockaddr.sa_family) {
	switch (((struct sockaddr *)&sender->sockaddr)->sa_family) {
	case AF_INET:
		sender->family = OFSocketAddressFamilyIPv4;
		break;
#ifdef OF_HAVE_IPV6
	case AF_INET6:
		sender->family = OFSocketAddressFamilyIPv6;
		break;
#endif
#ifdef OF_HAVE_IPX
	case AF_IPX:
		sender->family = OFSocketAddressFamilyIPX;
		break;
#endif
#ifdef OF_HAVE_UNIX_SOCKETS
	case AF_UNIX:
		sender->family = OFSocketAddressFamilyUNIX;
		break;
#endif
#ifdef OF_HAVE_IPX
	case AF_IPX:
		sender->family = OFSocketAddressFamilyIPX;
		break;
#endif
	default:
		sender->family = OFSocketAddressFamilyUnknown;
		break;
	}

	return ret;
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
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







-
+
-












-
+







#ifndef OF_WINDOWS
	ssize_t bytesWritten;

	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if ((bytesWritten = sendto(_socket, (void *)buffer, length, 0,
	    (struct sockaddr *)&receiver->sockaddr.sockaddr,
	    (struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
	    receiver->length)) < 0)
		@throw [OFWriteFailedException
		    exceptionWithObject: self
			requestedLength: length
			   bytesWritten: 0
				  errNo: OFSocketErrNo()];
#else
	int bytesWritten;

	if (length > INT_MAX)
		@throw [OFOutOfRangeException exception];

	if ((bytesWritten = sendto(_socket, buffer, (int)length, 0,
	    &receiver->sockaddr.sockaddr, receiver->length)) < 0)
	    (struct sockaddr *)&receiver->sockaddr, receiver->length)) < 0)
		@throw [OFWriteFailedException
		    exceptionWithObject: self
			requestedLength: length
			   bytesWritten: 0
				  errNo: OFSocketErrNo()];
#endif

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
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
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
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
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
555

556
557
558
559
560
561
562
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++)
		OFHashAdd(&hash, ((char *)&tmp)[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
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 [975907dd0c] to [73af2a9ef3].

30
31
32
33
34
35
36








37








38








39
40
41
42
43
44
45
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







+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+







#import "OFMessagePackRepresentation.h"

OF_ASSUME_NONNULL_BEGIN

@class OFArray OF_GENERIC(ObjectType);

#ifdef OF_HAVE_BLOCKS
/**
 * @brief A block for enumerating an OFDictionary.
 *
 * @param key The current key
 * @param object The object for the current key
 * @param stop A pointer to a variable that can be set to true to stop the
 *	       enumeration.
 */
typedef void (^OFDictionaryEnumerationBlock)(id key, id object, bool *stop);

/**
 * @brief A block for filtering an OFDictionary.
 *
 * @param key The key to inspect
 * @param object The object for the key to inspect
 * @return Whether the object should be in the filtered dictionary.
 */
typedef bool (^OFDictionaryFilterBlock)(id key, id object);

/**
 * @brief A block for mapping keys to objects in an OFDictionary.
 *
 * @param key The key to map
 * @param object The current object for the key
 * @return The object to map the key to
 */
typedef id _Nonnull (^OFDictionaryMapBlock)(id key, id object);
#endif

/**
 * @class OFDictionary OFDictionary.h ObjFW/OFDictionary.h
 *
 * @brief An abstract class for storing objects in a dictionary.
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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 A URL-encoded string with the contents of the dictionary.
 */
@property (readonly, nonatomic) OFString *stringByURLEncoding;

/**
 * @brief Creates a new OFDictionary.
 *
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)dictionary;

102
103
104
105
106
107
108
109
110
111


112
113
114
115
116
117
118
121
122
123
124
125
126
127



128
129
130
131
132
133
134
135
136







-
-
-
+
+







/**
 * @brief Creates a new OFDictionary with the specified keys and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @return A new autoreleased OFDictionary
 */
+ (instancetype)
    dictionaryWithObjects: (OFArray OF_GENERIC(ObjectType) *)objects
		  forKeys: (OFArray OF_GENERIC(KeyType) *)keys;
+ (instancetype)dictionaryWithObjects: (OFArray OF_GENERIC(ObjectType) *)objects
			      forKeys: (OFArray OF_GENERIC(KeyType) *)keys;

/**
 * @brief Creates a new OFDictionary with the specified keys and objects.
 *
 * @param keys An array of keys
 * @param objects An array of objects
 * @param count The number of objects in the arrays
220
221
222
223
224
225
226
227

228
229
230
231

232
233
234
235
236
237
238
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:. If the
 * This is equivalent to OFMutableDictionary#setObject:forKey:.
 * dictionary is immutable, an @ref OFUndefinedKeyException is thrown.
 *
 * @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
39

40
41
42
43
44
45
46
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 *URLQueryPartAllowedCharacterSet = nil;
static OFCharacterSet *URIQueryPartAllowedCharacterSet = nil;

@interface OFDictionary ()
- (OFString *)
    of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options
			       depth: (size_t)depth;
@end

54
55
56
57
58
59
60
61
62


63
64
65
66
67
68
69
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 OFURLQueryPartAllowedCharacterSet: OFCharacterSet
+ (OFCharacterSet *)URLQueryPartAllowedCharacterSet;
@interface OFURIQueryPartAllowedCharacterSet: OFCharacterSet
+ (OFCharacterSet *)URIQueryPartAllowedCharacterSet;
@end

@implementation OFDictionaryPlaceholder
- (instancetype)init
{
	return (id)[[OFMapTableDictionary alloc] init];
}
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
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 OFURLQueryPartAllowedCharacterSet
@implementation OFURIQueryPartAllowedCharacterSet
+ (void)initialize
{
	if (self != [OFURLQueryPartAllowedCharacterSet class])
	if (self != [OFURIQueryPartAllowedCharacterSet class])
		return;

	URLQueryPartAllowedCharacterSet =
	    [[OFURLQueryPartAllowedCharacterSet alloc] init];
	URIQueryPartAllowedCharacterSet =
	    [[OFURIQueryPartAllowedCharacterSet alloc] init];
}

+ (OFCharacterSet *)URLQueryPartAllowedCharacterSet
+ (OFCharacterSet *)URIQueryPartAllowedCharacterSet
{
	return URLQueryPartAllowedCharacterSet;
	return URIQueryPartAllowedCharacterSet;
}

- (instancetype)autorelease
{
	return self;
}

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
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;
}

- (OFString *)stringByURLEncoding
{
	OFMutableString *ret = [OFMutableString string];
	void *pool = objc_autoreleasePoolPush();
	OFEnumerator *keyEnumerator = [self keyEnumerator];
	OFEnumerator *objectEnumerator = [self objectEnumerator];
	OFCharacterSet *allowed = [OFURLQueryPartAllowedCharacterSet
	    URLQueryPartAllowedCharacterSet];
	bool first = true;
	OFObject *key, *object;

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		if OF_UNLIKELY (first)
			first = false;
		else
			[ret appendString: @"&"];

		[ret appendString: [key.description
		    stringByURLEncodingWithAllowedCharacters: allowed]];
		[ret appendString: @"="];
		[ret appendString: [object.description
		    stringByURLEncodingWithAllowedCharacters: allowed]];
	}

	[ret makeImmutable];

	objc_autoreleasePoolPop(pool);

	return ret;
}

Added src/OFEmbeddedURIHandler.h version [5163464dd8].
























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 OFEmbeddedURIHandler: OFURIHandler
@end

OF_ASSUME_NONNULL_END

Added src/OFEmbeddedURIHandler.m version [bac2da914b].






















































































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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>
#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"
#endif

struct EmbeddedFile {
	const char *name;
	const uint8_t *bytes;
	size_t size;
} *embeddedFiles = NULL;
size_t numEmbeddedFiles = 0;
#ifdef OF_HAVE_THREADS
static OFPlainMutex mutex;

static void
init(void)
{
	OFEnsure(OFPlainMutexNew(&mutex) == 0);
}
#endif

void
OFRegisterEmbeddedFile(const char *name, const uint8_t *bytes, size_t size)
{
#ifdef OF_HAVE_THREADS
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, init);

	OFEnsure(OFPlainMutexLock(&mutex) == 0);
#endif

	embeddedFiles = realloc(embeddedFiles,
	    sizeof(*embeddedFiles) * (numEmbeddedFiles + 1));
	OFEnsure(embeddedFiles != NULL);

	embeddedFiles[numEmbeddedFiles].name = name;
	embeddedFiles[numEmbeddedFiles].bytes = bytes;
	embeddedFiles[numEmbeddedFiles].size = size;
	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
		for (size_t i = 0; i < numEmbeddedFiles; i++) {
			if (strcmp(embeddedFiles[i].name, path) != 0)
				continue;

			return [OFMemoryStream
			    streamWithMemoryAddress: (void *)
							 embeddedFiles[i].bytes
					       size: embeddedFiles[i].size
					   writable: false];
		}
#ifdef OF_HAVE_THREADS
	} @finally {
		OFEnsure(OFPlainMutexUnlock(&mutex) == 0);
	}
#endif

	@throw [OFOpenItemFailedException exceptionWithURI: URI
						      mode: mode
						     errNo: ENOENT];
}
@end

Modified src/OFEnumerator.h from [553d9ef899] to [bebf66139d].

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
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







-
-










+
+




















+
+
















-
-
-
-




+
+







 * this as well.
 */
/**
 * @struct OFFastEnumerationState OFEnumerator.h ObjFW/OFEnumerator.h
 *
 * @brief State information for fast enumerations.
 */
#define OFFastEnumerationState NSFastEnumerationState
#ifndef NSINTEGER_DEFINED
typedef struct {
	/** Arbitrary state information for the enumeration */
	unsigned long state;
	/** Pointer to a C array of objects to return */
	id __unsafe_unretained _Nullable *_Nullable itemsPtr;
	/** Arbitrary state information to detect mutations */
	unsigned long *_Nullable mutationsPtr;
	/** Additional arbitrary state information */
	unsigned long extra[5];
} OFFastEnumerationState;
#ifndef NSINTEGER_DEFINED
typedef OFFastEnumerationState NSFastEnumerationState;
#endif

/**
 * @protocol OFFastEnumeration OFEnumerator.h ObjFW/OFEnumerator.h
 *
 * @brief A protocol for fast enumeration.
 *
 * The OFFastEnumeration protocol needs to be implemented by all classes
 * supporting fast enumeration.
 */
@protocol OFFastEnumeration
/**
 * @brief A method which is called by the code produced by the compiler when
 *	  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
{
	OF_RESERVE_IVARS(OFEnumerator, 4)
}

/**
 * @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
34

35
36
37
38
39
40
41
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 "OFObserveFailedException.h"
#import "OFObserveKernelEventsFailedException.h"

#define eventListSize 64

static const OFMapTableFunctions mapFunctions = { NULL };

@implementation OFEpollKernelEventObserver
- (instancetype)init
100
101
102
103
104
105
106

107
108


109
110
111
112
113
114
115
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
132

133
134
135
136
137
138
139
140
141
142
143
144
145

146
147
148
149
150
151
152
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 [OFObserveFailedException
				@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 [OFObserveFailedException
			@throw [OFObserveKernelEventsFailedException
			    exceptionWithObserver: self
					    errNo: errno];

		[_FDToEvents setObject: (void *)events
				forKey: (void *)((intptr_t)fd + 1)];
	}
}
196
197
198
199
200
201
202

203
204


205
206
207
208
209
210
211
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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 [edc70158f4] to [b56cdf66da].

23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
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 OFURL;
@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
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
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







+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-







 *	       `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 URL and mode.
 *
 * @param URL The URL to the file to open
 * @param mode The mode in which the file should be opened.@n
 *	       Possible modes are:
 *	       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
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithURL: (OFURL *)URL 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
 *		 is a file descriptor. The handle is closed when the OFFile
 *		 object is deallocated!
 * @return A new autoreleased OFFile
 */
+ (instancetype)fileWithHandle: (OFFileHandle)handle;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFFile.
 *
 * @param path The path to the file to open as a string
 * @param mode The mode in which the file should be opened.@n
 *	       Possible modes are:
 *	       Mode           | Description
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
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







+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-









+
+



 *	       `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 URL The URL to the file to open
 * @param mode The mode in which the file should be opened.@n
 *	       Possible modes are:
 *	       Mode           | Description
 *	       ---------------|-------------------------------------
 *	       `r`            | read-only
 *	       `rb`           | read-only, binary
 *	       `r+`           | read-write
 *	       `rb+` or `r+b` | read-write, binary
 *	       `w`            | write-only, create, truncate
 *	       `wb`           | write-only, create, truncate, binary
 *	       `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)initWithURL: (OFURL *)URL mode: (OFString *)mode;

/**
 * @brief Initializes an already allocated OFFile.
 *
 * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this
 *		 is a file descriptor. The handle is closed when the OFFile
 *		 object is deallocated!
 * @return An initialized OFFile
 */
- (instancetype)initWithHandle: (OFFileHandle)handle OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/OFFile.m from [6d43aa3c50] to [57c941bba1].

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
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







-
+














+
+
+
+
+










-
-
-
+
+
+
+







# include <sys/stat.h>
#endif

#import "OFFile.h"
#import "OFLocale.h"
#import "OFString.h"
#import "OFSystemInfo.h"
#import "OFURL.h"
#import "OFURI.h"

#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFNotOpenException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFSeekFailedException.h"
#import "OFWriteFailedException.h"

#ifdef OF_WINDOWS
# include <windows.h>
#endif

#ifdef OF_AMIGAOS
# include <proto/exec.h>
# include <proto/dos.h>
#endif

#ifdef OF_WII
# include <fat.h>
#endif

#ifdef OF_NINTENDO_DS
# include <stdbool.h>
# include <filesystem.h>
#endif

#ifdef OF_AMIGAOS
# include <proto/exec.h>
# include <proto/dos.h>
#ifdef OF_NINTENDO_SWITCH
# define id nx_id
# include <switch.h>
# undef id
#endif

#ifndef O_BINARY
# define O_BINARY 0
#endif
#ifndef O_CLOEXEC
# define O_CLOEXEC 0
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
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







+
+
+
+
+
+
+
+
+







-
-
-
-
-





-
-
-
-
-







#endif

#ifdef OF_NINTENDO_DS
	if (!nitroFSInit(NULL))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
#endif

#ifdef OF_NINTENDO_SWITCH
	if (R_SUCCEEDED(romfsInit()))
		/*
		 * Errors are intentionally ignored, as it's possible we just
		 * have no romfs.
		 */
		atexit((void (*)(void))romfsExit);
#endif
}

+ (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
}

+ (instancetype)fileWithURL: (OFURL *)URL mode: (OFString *)mode
{
	return [[[self alloc] initWithURL: URL mode: mode] autorelease];
}

+ (instancetype)fileWithHandle: (OFFileHandle)handle
{
	return [[[self alloc] initWithHandle: handle] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
{
	OFFileHandle handle;

	@try {
		void *pool = objc_autoreleasePoolPush();
		int flags;
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
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







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








+
+
+
+
+







		closeHandle(handle);
		@throw e;
	}

	return self;
}

- (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFString *fileSystemRepresentation;

	@try {
		fileSystemRepresentation = URL.fileSystemRepresentation;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithPath: fileSystemRepresentation mode: mode];

	objc_autoreleasePoolPop(pool);

	return self;
}

- (instancetype)initWithHandle: (OFFileHandle)handle
{
	self = [super init];

	_handle = handle;

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (bool)lowlevelIsAtEndOfStream
{
	if (_handle == OFInvalidFileHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	return _atEndOfStream;
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
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;
}

- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence
- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset
				whence: (OFSeekWhence)whence
{
	OFFileOffset ret;
	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, whence);
	ret = _lseeki64(_handle, offset, translatedWhence);
# elif defined(HAVE_LSEEK64)
	ret = lseek64(_handle, offset, whence);
	ret = lseek64(_handle, offset, translatedWhence);
# else
	ret = lseek(_handle, offset, whence);
	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 SEEK_SET:
	case OFSeekSet:
		translatedWhence = OFFSET_BEGINNING;
		break;
	case SEEK_CUR:
	case OFSeekCurrent:
		translatedWhence = OFFSET_CURRENT;
		break;
	case SEEK_END:
	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
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
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 OFURL;
@class OFURI;

/**
 * @brief A key for a file attribute in the file attributes dictionary.
 *
 * Possible keys for file URLs are:
 * 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 URL schemes might not have all keys and might have keys not listed.
 * 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 URLs are:
 * Possibles values for file URIs are:
 *
 *  * @ref OFFileTypeRegular
 *  * @ref OFFileTypeDirectory
 *  * @ref OFFileTypeSymbolicLink
 *  * @ref OFFileTypeFIFO
 *  * @ref OFFileTypeCharacterSpecial
 *  * @ref OFFileTypeBlockSpecial
 *  * @ref OFFileTypeSocket
 *  * @ref OFFileTypeUnknown
 *
 * Other URL schemes might not have all types and might have types not listed.
 * 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
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
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 URL of the current working directory.
 * @brief The URI of the current working directory.
 *
 * @throw OFGetCurrentDirectoryFailedException Couldn't get current directory
 */
@property (readonly, nonatomic) OFURL *currentDirectoryURL;
@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 URL.
 * @brief Returns the attributes for the item at the specified URI.
 *
 * @param URL The URL to return the attributes for
 * @return A dictionary of attributes for the specified URL, with the keys of
 * @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)attributesOfItemAtURL: (OFURL *)URL;
- (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 URL.
 * @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 URL
 * @param URL The URL of the item to set the attributes for
 * @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 ofItemAtURL: (OFURL *)URL;
- (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 URL.
 * @brief Checks whether a file exists at the specified URI.
 *
 * @param URL The URL to check
 * @return A boolean whether there is a file at the specified URL
 * @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)fileExistsAtURL: (OFURL *)URL;
- (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 URL.
 * @brief Checks whether a directory exists at the specified URI.
 *
 * @param URL The URL to check
 * @return A boolean whether there is a directory at the specified URL
 * @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)directoryExistsAtURL: (OFURL *)URL;
- (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 URL.
 * @brief Creates a directory at the specified URI.
 *
 * @param URL The URL of the directory to create
 * @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)createDirectoryAtURL: (OFURL *)URL;
- (void)createDirectoryAtURI: (OFURI *)URI;

/**
 * @brief Creates a directory at the specified URL.
 * @brief Creates a directory at the specified URI.
 *
 * @param URL The URL of the directory to create
 * @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)createDirectoryAtURL: (OFURL *)URL createParents: (bool)createParents;
- (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 URLs of the items in the specified
 * @brief Returns an array with the URIs of the items in the specified
 *	  directory.
 *
 * @note `.` and `..` are not part of the returned array.
 *
 * @param URL The URL to the directory whose items should be returned
 * @return An array with the URLs of the items in the specified directory
 * @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(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL;
- (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 URL The new directory to change to
 * @param URI The new directory to change to
 * @throw OFChangeCurrentDirectoryFailedException Changing the current working
 *						  directory failed
 */
- (void)changeCurrentDirectoryURL: (OFURL *)URL;
- (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 URL must have a full path, which means it must include the
 * 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 URL
 * @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)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (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 URL must have a full path, which means it must include the
 * 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 copyItemAtURL:toURL: and the source removed using @ref removeItemAtURL:.
 * @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)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (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 URL.
 * @brief Removes the item at the specified URI.
 *
 * If the item at the specified URL is a directory, it is removed recursively.
 * If the item at the specified URI is a directory, it is removed recursively.
 *
 * @param URL The URL to the item which should be removed
 * @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)removeItemAtURL: (OFURL *)URL;
- (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 URL must have a full path, which means it must include the
 * 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 URLs.
 * This method is not available for all URIs.
 *
 * @param source The URL to the item for which a link should be created
 * @param destination The URL to the item which should link to the source
 * @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)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (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 uRL must have a full path, which means it must include the
 * 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 URLs.
 * This method is not available for all URIs.
 *
 * @note On Windows, this requires at least Windows Vista and administrator
 *	 privileges!
 *
 * @param URL The URL to the item which should symbolically link to the target
 * @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)createSymbolicLinkAtURL: (OFURL *)URL
- (void)createSymbolicLinkAtURI: (OFURI *)URI
	    withDestinationPath: (OFString *)target;
@end

@interface OFDictionary (FileAttributes)
/**
 * @brief The @ref OFFileSize key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) unsigned long long fileSize;

/**
 * @brief The @ref OFFileType key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFFileAttributeType fileType;

/**
 * @brief The @ref OFFilePOSIXPermissions key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) unsigned long filePOSIXPermissions;

/**
 * @brief The @ref OFFileOwnerAccountID key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) unsigned long fileOwnerAccountID;

/**
 * @brief The @ref OFFileGroupOwnerAccountID key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID;

/**
 * @brief The @ref OFFileOwnerAccountName key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFString *fileOwnerAccountName;

/**
 * @brief The @ref OFFileGroupOwnerAccountName key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFString *fileGroupOwnerAccountName;

/**
 * @brief The @ref OFFileLastAccessDate key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFDate *fileLastAccessDate;

/**
 * @brief The @ref OFFileModificationDate key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFDate *fileModificationDate;

/**
 * @brief The @ref OFFileStatusChangeDate key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFDate *fileStatusChangeDate;

/**
 * @brief The @ref OFFileCreationDate key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @throw OFUndefinedKeyException The key is missing
 */
@property (readonly, nonatomic) OFDate *fileCreationDate;

/**
 * @brief The @ref OFFileSymbolicLinkDestination key from the dictionary.
 *
 * Raises an @ref OFUndefinedKeyException if the key is missing.
 * @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
42
43


44
45

46
47
48

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
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 "OFURL.h"
#import "OFURLHandler.h"
#import "OFURI.h"
#import "OFURIHandler.h"

#import "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChangeCurrentDirectoryFailedException.h"
#import "OFCopyItemFailedException.h"
#import "OFCreateDirectoryFailedException.h"
#import "OFGetCurrentDirectoryPathFailedException.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 "OFRetrieveItemAttributesFailedException.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
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
460
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 [OFGetCurrentDirectoryPathFailedException
		@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
}

- (OFURL *)currentDirectoryURL
- (OFURI *)currentDirectoryURI
{
	void *pool = objc_autoreleasePoolPush();
	OFURL *ret;
	OFURI *ret;

	ret = [OFURL fileURLWithPath: self.currentDirectoryPath];
	ret = [OFURI fileURIWithPath: self.currentDirectoryPath];

	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}
#endif

- (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL
- (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	return [URLHandler attributesOfItemAtURL: URL];
	return [URIHandler attributesOfItemAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (OFFileAttributes)attributesOfItemAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFFileAttributes ret;

	ret = [self attributesOfItemAtURL: [OFURL fileURLWithPath: path]];
	ret = [self attributesOfItemAtURI: [OFURI fileURIWithPath: path]];

	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
#endif

- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	[URLHandler setAttributes: attributes ofItemAtURL: URL];
	[URIHandler setAttributes: attributes ofItemAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (void)setAttributes: (OFFileAttributes)attributes
	 ofItemAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	[self setAttributes: attributes
		ofItemAtURL: [OFURL fileURLWithPath: path]];
		ofItemAtURI: [OFURI fileURIWithPath: path]];
	objc_autoreleasePoolPop(pool);
}
#endif

- (bool)fileExistsAtURL: (OFURL *)URL
- (bool)fileExistsAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	return [URLHandler fileExistsAtURL: URL];
	return [URIHandler fileExistsAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (bool)fileExistsAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	bool ret;

	ret = [self fileExistsAtURL: [OFURL fileURLWithPath: path]];
	ret = [self fileExistsAtURI: [OFURI fileURIWithPath: path]];

	objc_autoreleasePoolPop(pool);

	return ret;
}
#endif

- (bool)directoryExistsAtURL: (OFURL *)URL
- (bool)directoryExistsAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	return [URLHandler directoryExistsAtURL: URL];
	return [URIHandler directoryExistsAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (bool)directoryExistsAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	bool ret;

	ret = [self directoryExistsAtURL: [OFURL fileURLWithPath: path]];
	ret = [self directoryExistsAtURI: [OFURI fileURIWithPath: path]];

	objc_autoreleasePoolPop(pool);

	return ret;
}
#endif

- (void)createDirectoryAtURL: (OFURL *)URL
- (void)createDirectoryAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	[URLHandler createDirectoryAtURL: URL];
	[URIHandler createDirectoryAtURI: URI];
}

- (void)createDirectoryAtURL: (OFURL *)URL
- (void)createDirectoryAtURI: (OFURI *)URI createParents: (bool)createParents
	       createParents: (bool)createParents
{
	void *pool = objc_autoreleasePoolPush();
	OFMutableURL *mutableURL;
	OFMutableURI *mutableURI;
	OFArray OF_GENERIC(OFString *) *components;
	OFMutableArray OF_GENERIC(OFURL *) *componentURLs;
	size_t componentURLsCount;
	OFMutableArray OF_GENERIC(OFURI *) *componentURIs;
	size_t componentURIsCount;
	ssize_t i;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (!createParents) {
		[self createDirectoryAtURL: URL];
		[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 directoryExistsAtURL: URL])
	if ([self directoryExistsAtURI: URI])
		return;

	@try {
		[self createDirectoryAtURL: URL];
		[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 URLs don't even know
	 * anything at all), we generate the URL for every component. We then
	 * 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.
	 */
	mutableURL = [[URL mutableCopy] autorelease];
	mutableURL.URLEncodedPath = @"/";
	components = URL.pathComponents;
	componentURLs = [OFMutableArray arrayWithCapacity: components.count];
	mutableURI = [[URI mutableCopy] autorelease];
	mutableURI.percentEncodedPath = @"/";
	components = URI.pathComponents;
	componentURIs = [OFMutableArray arrayWithCapacity: components.count];

	for (OFString *component in components) {
		[mutableURL appendPathComponent: component];
		[mutableURI appendPathComponent: component];

		if (![mutableURL.URLEncodedPath isEqual: @"/"])
			[componentURLs addObject:
			    [[mutableURL copy] autorelease]];
		if (![mutableURI.percentEncodedPath isEqual: @"/"])
			[componentURIs addObject:
			    [[mutableURI copy] autorelease]];
	}

	componentURLsCount = componentURLs.count;
	for (i = componentURLsCount - 1; i > 0; i--) {
		if ([self directoryExistsAtURL:
		    [componentURLs objectAtIndex: i]])
	componentURIsCount = componentURIs.count;
	for (i = componentURIsCount - 1; i > 0; i--) {
		if ([self directoryExistsAtURI:
		    [componentURIs objectAtIndex: i]])
			break;
	}

	if (++i == (ssize_t)componentURLsCount) {
	if (++i == (ssize_t)componentURIsCount) {
		/*
		 * The URL exists, even though before we made sure it did not.
		 * 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)componentURLsCount; i++)
		[self createDirectoryAtURL: [componentURLs objectAtIndex: i]];
	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 createDirectoryAtURL: [OFURL fileURLWithPath: path]];
	[self createDirectoryAtURI: [OFURI fileURIWithPath: path]];

	objc_autoreleasePoolPop(pool);
}

- (void)createDirectoryAtPath: (OFString *)path
		createParents: (bool)createParents
{
	void *pool = objc_autoreleasePoolPush();

	[self createDirectoryAtURL: [OFURL fileURLWithPath: path]
	[self createDirectoryAtURI: [OFURI fileURIWithPath: path]
		     createParents: createParents];

	objc_autoreleasePoolPop(pool);
}
#endif

- (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL
- (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	return [URLHandler contentsOfDirectoryAtURL: URL];
	return [URIHandler contentsOfDirectoryAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFArray OF_GENERIC(OFURL *) *URLs;
	OFArray OF_GENERIC(OFURI *) *URIs;
	OFMutableArray OF_GENERIC(OFString *) *ret;

	URLs = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]];
	ret = [OFMutableArray arrayWithCapacity: URLs.count];
	URIs = [self contentsOfDirectoryAtURI: [OFURI fileURIWithPath: path]];
	ret = [OFMutableArray arrayWithCapacity: URIs.count];

	for (OFURL *URL in URLs)
		[ret addObject: URL.lastPathComponent];
	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
518

519
520
521
522
523
524
525
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524







-
+







			errNo = ENOENT;
			break;
		default:
			errNo = 0;
			break;
		}

		@throw [OFChangeCurrentDirectoryPathFailedException
		@throw [OFChangeCurrentDirectoryFailedException
		    exceptionWithPath: path
				errNo: errNo];
	}

	oldLock = CurrentDir(lock);

	if (!dirChanged)
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
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 [OFChangeCurrentDirectoryPathFailedException
		@throw [OFChangeCurrentDirectoryFailedException
		    exceptionWithPath: path
				errNo: errno];
# endif
}

- (void)changeCurrentDirectoryURL: (OFURL *)URL
- (void)changeCurrentDirectoryURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();

	[self changeCurrentDirectoryPath: URL.fileSystemRepresentation];
	[self changeCurrentDirectoryPath: URI.fileSystemRepresentation];

	objc_autoreleasePoolPop(pool);
}

- (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination
{
	void *pool = objc_autoreleasePoolPush();

	[self copyItemAtURL: [OFURL fileURLWithPath: source]
		      toURL: [OFURL fileURLWithPath: destination]];
	[self copyItemAtURI: [OFURI fileURIWithPath: source]
		      toURI: [OFURI fileURIWithPath: destination]];

	objc_autoreleasePoolPop(pool);
}
#endif

- (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (void)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	void *pool;
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;
	OFFileAttributes attributes;
	OFFileAttributeType type;

	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil)
	if ((URIHandler = [OFURIHandler handlerForURI: source]) == nil)
		@throw [OFUnsupportedProtocolException
		    exceptionWithURL: source];
		    exceptionWithURI: source];

	if ([URLHandler copyItemAtURL: source toURL: destination])
	if ([URIHandler copyItemAtURI: source toURI: destination])
		return;

	if ([self fileExistsAtURL: destination])
	if ([self fileExistsAtURI: destination])
		@throw [OFCopyItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: EEXIST];

	@try {
		attributes = [self attributesOfItemAtURL: source];
	} @catch (OFRetrieveItemAttributesFailedException *e) {
		attributes = [self attributesOfItemAtURI: source];
	} @catch (OFGetItemAttributesFailedException *e) {
		@throw [OFCopyItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: e.errNo];
	}

	type = attributes.fileType;

	if ([type isEqual: OFFileTypeDirectory]) {
		OFArray OF_GENERIC(OFURL *) *contents;
		OFArray OF_GENERIC(OFURI *) *contents;

		@try {
			[self createDirectoryAtURL: destination];
			[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
					      ofItemAtURL: destination];
					      ofItemAtURI: destination];
				}
			} @catch (OFNotImplementedException *e) {
			}

			contents = [self contentsOfDirectoryAtURL: source];
			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
				    exceptionWithSourceURL: source
					    destinationURL: destination
				    exceptionWithSourceURI: source
					    destinationURI: destination
						     errNo: [e errNo]];

			@throw e;
		}

		for (OFURL *item in contents) {
		for (OFURI *item in contents) {
			void *pool2 = objc_autoreleasePoolPush();
			OFURL *destinationURL = [destination
			    URLByAppendingPathComponent:
			OFURI *destinationURI = [destination
			    URIByAppendingPathComponent:
			    item.lastPathComponent];

			[self copyItemAtURL: item toURL: destinationURL];
			[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 = [[OFURLHandler handlerForURL: source]
			    openItemAtURL: source
				     mode: @"r"];
			destinationStream = [[OFURLHandler handlerForURL:
			    destination] openItemAtURL: destination
						  mode: @"w"];
			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
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
891
892
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
					      ofItemAtURL: destination];
					      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
				    exceptionWithSourceURL: source
					    destinationURL: destination
				    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 createSymbolicLinkAtURL: destination
			[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
				    exceptionWithSourceURL: source
					    destinationURL: destination
				    exceptionWithSourceURI: source
					    destinationURI: destination
						     errNo: [e errNo]];

			@throw e;
		}
	} else
		@throw [OFCopyItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    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 moveItemAtURL: [OFURL fileURLWithPath: source]
		      toURL: [OFURL fileURLWithPath: destination]];
	[self moveItemAtURI: [OFURI fileURIWithPath: source]
		      toURI: [OFURI fileURIWithPath: destination]];
	objc_autoreleasePoolPop(pool);
}
#endif

- (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (void)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	void *pool;
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil)
	if ((URIHandler = [OFURIHandler handlerForURI: source]) == nil)
		@throw [OFUnsupportedProtocolException
		    exceptionWithURL: source];
		    exceptionWithURI: source];

	@try {
		if ([URLHandler moveItemAtURL: source toURL: destination])
		if ([URIHandler moveItemAtURI: source toURI: destination])
			return;
	} @catch (OFMoveItemFailedException *e) {
		if (e.errNo != EXDEV)
			@throw e;
	}

	if ([self fileExistsAtURL: destination])
	if ([self fileExistsAtURI: destination])
		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: EEXIST];

	@try {
		[self copyItemAtURL: source toURL: destination];
		[self copyItemAtURI: source toURI: destination];
	} @catch (OFCopyItemFailedException *e) {
		[self removeItemAtURL: destination];
		[self removeItemAtURI: destination];

		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: e.errNo];
	}

	@try {
		[self removeItemAtURL: source];
		[self removeItemAtURI: source];
	} @catch (OFRemoveItemFailedException *e) {
		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: e.errNo];
	}

	objc_autoreleasePoolPop(pool);
}

- (void)removeItemAtURL: (OFURL *)URL
- (void)removeItemAtURI: (OFURI *)URI
{
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if ((URIHandler = [OFURIHandler handlerForURI: URI]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	[URLHandler removeItemAtURL: URL];
	[URIHandler removeItemAtURI: URI];
}

#ifdef OF_HAVE_FILES
- (void)removeItemAtPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	[self removeItemAtURL: [OFURL fileURLWithPath: path]];
	[self removeItemAtURI: [OFURI fileURIWithPath: path]];
	objc_autoreleasePoolPop(pool);
}
#endif

- (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	void *pool = objc_autoreleasePoolPush();
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	if (![destination.scheme isEqual: source.scheme])
		@throw [OFInvalidArgumentException exception];

	URLHandler = [OFURLHandler handlerForURL: source];
	URIHandler = [OFURIHandler handlerForURI: source];

	if (URLHandler == nil)
	if (URIHandler == nil)
		@throw [OFUnsupportedProtocolException
		    exceptionWithURL: source];
		    exceptionWithURI: source];

	[URLHandler linkItemAtURL: source toURL: destination];
	[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 linkItemAtURL: [OFURL fileURLWithPath: source]
		      toURL: [OFURL fileURLWithPath: destination]];
	[self linkItemAtURI: [OFURI fileURIWithPath: source]
		      toURI: [OFURI fileURIWithPath: destination]];
	objc_autoreleasePoolPop(pool);
}
#endif

- (void)createSymbolicLinkAtURL: (OFURL *)URL
- (void)createSymbolicLinkAtURI: (OFURI *)URI
	    withDestinationPath: (OFString *)target
{
	void *pool = objc_autoreleasePoolPush();
	OFURLHandler *URLHandler;
	OFURIHandler *URIHandler;

	if (URL == nil || target == nil)
	if (URI == nil || target == nil)
		@throw [OFInvalidArgumentException exception];

	URLHandler = [OFURLHandler handlerForURL: URL];
	URIHandler = [OFURIHandler handlerForURI: URI];

	if (URLHandler == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
	if (URIHandler == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	[URLHandler createSymbolicLinkAtURL: URL withDestinationPath: target];
	[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 createSymbolicLinkAtURL: [OFURL fileURLWithPath: path]
	[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
16

17
18
19
20

21
22
23
24
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 "OFURLHandler.h"
#import "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFFileURLHandler: OFURLHandler
@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
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
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 "OFFileURLHandler.h"
#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 "OFURL.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 "OFLinkFailedException.h"
#import "OFLinkItemFailedException.h"
#import "OFMoveItemFailedException.h"
#import "OFNotImplementedException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFRemoveItemFailedException.h"
#import "OFRetrieveItemAttributesFailedException.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 {
	OFFileOffset st_size;
	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
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
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
retrieveError(void)
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
retrieveError(void)
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
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
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 retrieveError();
		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 retrieveError();
			return lastError();

		@try {
			if (!(findData.dwFileAttributes &
			    FILE_ATTRIBUTE_REPARSE_POINT))
				/* Race? Indicate to try again. */
				return EAGAIN;

264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279
280

281
282
283
284
285
286
287
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 retrieveError();
		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 = retrieveError();
		int error = lastError();
		UnLock(lock);
		return error;
	}

	UnLock(lock);

# if defined(OF_MORPHOS)
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
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,
    OFURL *URL)
    OFURI *URI)
{
	OFString *path = URL.fileSystemRepresentation;
	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 [OFRetrieveItemAttributesFailedException
		    exceptionWithURL: URL
		@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 [OFRetrieveItemAttributesFailedException
		    exceptionWithURL: URL
			       errNo: retrieveError()];
		@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 [OFRetrieveItemAttributesFailedException
			    exceptionWithURL: URL
				       errNo: retrieveError()];
			@throw [OFGetItemAttributesFailedException
			    exceptionWithURI: URI
				       errNo: lastError()];

		if (buffer.data.ReparseTag != IO_REPARSE_TAG_SYMLINK)
			@throw [OFRetrieveItemAttributesFailedException
			    exceptionWithURL: URL
				       errNo: retrieveError()];
			@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
538

539
540
541
542
543
544
545

546
547
548
549
550
551
552
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 OFFileURLHandler
@implementation OFFileURIHandler
+ (void)initialize
{
#ifdef OF_WINDOWS
	HMODULE module;
#endif

	if (self != [OFFileURLHandler class])
	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
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
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 *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file = [[OFFile alloc]
	    initWithPath: URL.fileSystemRepresentation
	    initWithPath: URI.fileSystemRepresentation
		    mode: mode];

	objc_autoreleasePoolPop(pool);

	return [file autorelease];
}

- (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL
- (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI
{
	OFMutableFileAttributes ret = [OFMutableDictionary dictionary];
	void *pool = objc_autoreleasePoolPush();
	OFString *path;
	int error;
	Stat s;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![[URL scheme] isEqual: _scheme])
	if (![[URI scheme] isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;
	path = URI.fileSystemRepresentation;

	if ((error = lstatWrapper(path, &s)) != 0)
		@throw [OFRetrieveItemAttributesFailedException
		    exceptionWithURL: URL
		@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, URL);
		setSymbolicLinkDestinationAttribute(ret, URI);
#endif

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (void)of_setLastAccessDate: (OFDate *)lastAccessDate
	 andModificationDate: (OFDate *)modificationDate
		 ofItemAtURL: (OFURL *)URL
		 ofItemAtURI: (OFURI *)URI
		  attributes: (OFFileAttributes)attributes OF_DIRECT
{
	OFString *path = URL.fileSystemRepresentation;
	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], &times) != 0)
			@throw [OFSetItemAttributesFailedException
			    exceptionWithURL: URL
			    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], &times);
		else
			status = _utime(
			    [path cStringWithEncoding: [OFLocale encoding]],
			    &times);

		if (status != 0)
			@throw [OFSetItemAttributesFailedException
			    exceptionWithURL: URL
			    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
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
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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			  attributes: attributes
		     failedAttribute: attributeKey
			       errNo: retrieveError()];
			       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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			  attributes: attributes
		     failedAttribute: attributeKey
			       errNo: errno];
#endif
}

- (void)of_setPOSIXPermissions: (OFNumber *)permissions
		   ofItemAtURL: (OFURL *)URL
		   ofItemAtURI: (OFURI *)URI
		    attributes: (OFFileAttributes)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
	mode_t mode = (mode_t)permissions.unsignedLongValue;
	OFString *path = URL.fileSystemRepresentation;
	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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			  attributes: attributes
		     failedAttribute: OFFilePOSIXPermissions
			       errNo: errno];
#else
	OF_UNRECOGNIZED_SELECTOR
#endif
}

- (void)of_setOwnerAccountName: (OFString *)owner
      andGroupOwnerAccountName: (OFString *)group
		   ofItemAtURL: (OFURL *)URL
		   ofItemAtURI: (OFURI *)URI
		  attributeKey: (OFFileAttributeKey)attributeKey
		    attributes: (OFFileAttributes)attributes OF_DIRECT
{
#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
	OFString *path = URL.fileSystemRepresentation;
	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
				    exceptionWithURL: URL
				    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
				    exceptionWithURL: URL
				    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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			  attributes: attributes
		     failedAttribute: attributeKey
			       errNo: errno];
#else
	OF_UNRECOGNIZED_SELECTOR
#endif
}

- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL
- (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 (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	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
					 ofItemAtURL: URL
					 ofItemAtURI: URI
					  attributes: attributes];
		else if ([key isEqual: OFFileOwnerAccountName])
			[self of_setOwnerAccountName: object
			    andGroupOwnerAccountName: nil
					 ofItemAtURL: URL
					 ofItemAtURI: URI
					attributeKey: key
					  attributes: attributes];
		else if ([key isEqual: OFFileGroupOwnerAccountName])
			[self of_setOwnerAccountName: nil
			    andGroupOwnerAccountName: object
					 ofItemAtURL: URL
					 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
			       ofItemAtURL: URL
			       ofItemAtURI: URI
				attributes: attributes];

	objc_autoreleasePoolPop(pool);
}

- (bool)fileExistsAtURL: (OFURL *)URL
- (bool)fileExistsAtURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	Stat s;
	bool ret;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	if (statWrapper(URL.fileSystemRepresentation, &s) != 0) {
	if (statWrapper(URI.fileSystemRepresentation, &s) != 0) {
		objc_autoreleasePoolPop(pool);
		return false;
	}

	ret = S_ISREG(s.st_mode);

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (bool)directoryExistsAtURL: (OFURL *)URL
- (bool)directoryExistsAtURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	Stat s;
	bool ret;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	if (statWrapper(URL.fileSystemRepresentation, &s) != 0) {
	if (statWrapper(URI.fileSystemRepresentation, &s) != 0) {
		objc_autoreleasePoolPop(pool);
		return false;
	}

	ret = S_ISDIR(s.st_mode);

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (void)createDirectoryAtURL: (OFURL *)URL
- (void)createDirectoryAtURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;
	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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			       errNo: errno];
#elif defined(OF_AMIGAOS)
	BPTR lock;

	if ((lock = CreateDir(
	    [path cStringWithEncoding: [OFLocale encoding]])) == 0)
		@throw [OFCreateDirectoryFailedException
		    exceptionWithURL: URL
			       errNo: retrieveError()];
		    exceptionWithURI: URI
			       errNo: lastError()];

	UnLock(lock);
#else
	if (mkdir([path cStringWithEncoding: [OFLocale encoding]], 0777) != 0)
		@throw [OFCreateDirectoryFailedException
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			       errNo: errno];
#endif

	objc_autoreleasePoolPop(pool);
}

- (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL
- (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI
{
	OFMutableArray *URLs = [OFMutableArray array];
	OFMutableArray *URIs = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	OFString *path;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;
	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
			    exceptionWithURL: URL
			    exceptionWithURI: URI
					mode: nil
				       errNo: retrieveError()];
				       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 {
					[URLs addObject: [URL
					    URLByAppendingPathComponent: file]];
					[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: retrieveError()];
						  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
			    exceptionWithURL: URL
			    exceptionWithURI: URI
					mode: nil
				       errNo: retrieveError()];
				       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 {
					[URLs addObject: [URL
					    URLByAppendingPathComponent: file]];
					[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: retrieveError()];
						  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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
				mode: nil
			       errNo: retrieveError()];
			       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
			    exceptionWithURL: URL
			    exceptionWithURI: URI
					mode: nil
				       errNo: retrieveError()];
				       errNo: lastError()];

		@try {
			while ((ed = ExamineDir(context)) != NULL) {
				OFString *file = [[OFString alloc]
				    initWithCString: ed->Name
					   encoding: encoding];

				@try {
					[URLs addObject: [URL
					    URLByAppendingPathComponent: file]];
					[URIs addObject: [URI
					    URIByAppendingPathComponent: file]];
				} @finally {
					[file release];
				}
			}
		} @finally {
			ReleaseDirContext(context);
		}
# else
		struct FileInfoBlock fib;

		if (!Examine(lock, &fib))
			@throw [OFOpenItemFailedException
			    exceptionWithURL: URL
			    exceptionWithURI: URI
					mode: nil
				       errNo: retrieveError()];
				       errNo: lastError()];

		while (ExNext(lock, &fib)) {
			OFString *file = [[OFString alloc]
			    initWithCString: fib.fib_FileName
				   encoding: encoding];
			@try {
				[URLs addObject:
				    [URL URLByAppendingPathComponent: file]];
				[URIs addObject:
				    [URI URIByAppendingPathComponent: file]];
			} @finally {
				[file release];
			}
		}
# endif

		if (IoErr() != ERROR_NO_MORE_ENTRIES)
			@throw [OFReadFailedException
			    exceptionWithObject: self
				requestedLength: 0
					  errNo: retrieveError()];
					  errNo: lastError()];
	} @finally {
		UnLock(lock);
	}
#else
	OFStringEncoding encoding = [OFLocale encoding];
	DIR *dir;
	if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
		@throw [OFOpenItemFailedException exceptionWithURL: URL
		@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
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
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 {
				[URLs addObject:
				    [URL URLByAppendingPathComponent: file]];
				[URIs addObject:
				    [URI URIByAppendingPathComponent: file]];
			} @finally {
				[file release];
			}
		}
	} @finally {
		closedir(dir);
# if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS)
		[readdirMutex unlock];
# endif
	}
#endif

	[URLs makeImmutable];
	[URIs makeImmutable];

	objc_autoreleasePoolPop(pool);

	return URLs;
	return URIs;
}

- (void)removeItemAtURL: (OFURL *)URL
- (void)removeItemAtURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;
	int error;
	Stat s;

	if (URL == nil)
	if (URI == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;
	path = URI.fileSystemRepresentation;

	if ((error = lstatWrapper(path, &s)) != 0)
		@throw [OFRemoveItemFailedException exceptionWithURL: URL
		@throw [OFRemoveItemFailedException exceptionWithURI: URI
							       errNo: error];

	if (S_ISDIR(s.st_mode)) {
		OFArray OF_GENERIC(OFURL *) *contents;
		OFArray OF_GENERIC(OFURI *) *contents;

		@try {
			contents = [self contentsOfDirectoryAtURL: URL];
			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
				    exceptionWithURL: URL
				    exceptionWithURI: URI
					       errNo: [e errNo]];

			@throw e;
		}

		for (OFURL *item in contents) {
		for (OFURI *item in contents) {
			void *pool2 = objc_autoreleasePoolPush();

			[self removeItemAtURL: item];
			[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
				exceptionWithURL: URL
				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
			    exceptionWithURL: URL
			    exceptionWithURI: URI
				       errNo: errno];
#endif
	}

#ifdef OF_AMIGAOS
	if (!DeleteFile([path cStringWithEncoding: [OFLocale encoding]]))
		@throw [OFRemoveItemFailedException
		    exceptionWithURL: URL
			       errNo: retrieveError()];
		    exceptionWithURI: URI
			       errNo: lastError()];
#endif

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_FILE_MANAGER_SUPPORTS_LINKS
- (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (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 [OFLinkFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		@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 [OFLinkFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: retrieveError()];
		@throw [OFLinkItemFailedException
		    exceptionWithSourceURI: source
			    destinationURI: destination
				     errNo: lastError()];
# endif

	objc_autoreleasePoolPop(pool);
}
#endif

#ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS
- (void)createSymbolicLinkAtURL: (OFURL *)URL
- (void)createSymbolicLinkAtURI: (OFURI *)URI
	    withDestinationPath: (OFString *)target
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;

	if (URL == nil || target == nil)
	if (URI == nil || target == nil)
		@throw [OFInvalidArgumentException exception];

	if (![URL.scheme isEqual: _scheme])
	if (![URI.scheme isEqual: _scheme])
		@throw [OFInvalidArgumentException exception];

	path = URL.fileSystemRepresentation;
	path = URI.fileSystemRepresentation;

# ifndef OF_WINDOWS
	OFStringEncoding encoding = [OFLocale encoding];

	if (symlink([target cStringWithEncoding: encoding],
	    [path cStringWithEncoding: encoding]) != 0)
		@throw [OFCreateSymbolicLinkFailedException
		    exceptionWithURL: URL
		    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
		    exceptionWithURL: URL
		    exceptionWithURI: URI
			      target: target
			       errNo: retrieveError()];
			       errNo: lastError()];
# endif

	objc_autoreleasePoolPop(pool);
}
#endif

- (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	void *pool;

	if (![source.scheme isEqual: _scheme] ||
	    ![destination.scheme isEqual: _scheme])
		return false;

	if ([self fileExistsAtURL: destination])
	if ([self fileExistsAtURI: destination])
		@throw [OFMoveItemFailedException
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    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
		    exceptionWithSourceURL: source
			    destinationURL: destination
				     errNo: retrieveError()];
		    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
1467
1468


1469
1470
1471
1472
1473
1474
1475
1476
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
		    exceptionWithSourceURL: source
			    destinationURL: destination
		    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
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
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
31

32
33
34
35
36
37
38
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 OFURL;
@class OFURI;

/**
 * @protocol OFHTTPClientDelegate OFHTTPClient.h ObjFW/OFHTTPClient.h
 *
 * @brief A delegate for OFHTTPClient.
 */
@protocol OFHTTPClientDelegate <OFObject>
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
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 URL The URL to which it will 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 URL), however, keep in
 *		  (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
  shouldFollowRedirect: (OFURL *)URL
	    statusCode: (short)statusCode
	       request: (OFHTTPRequest *)request
	      response: (OFHTTPResponse *)response;
-	       (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_HTTPCLIENT_M
#ifdef OF_HTTP_CLIENT_M
@public
#endif
	OFObject <OFHTTPClientDelegate> *_Nullable _delegate;
	bool _allowsInsecureRedirects, _inProgress;
	OFStream *_Nullable _stream;
	OFURL *_Nullable _lastURL;
	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
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
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
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_HTTPCLIENT_M
#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 "OFURL.h"
#import "OFURI.h"

#import "OFAlreadyConnectedException.h"
#import "OFHTTPRequestFailedException.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFInvalidServerReplyException.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
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
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;
	OFURL *URL = request.URL;
	OFURI *URI = request.URI;
	OFString *path;
	OFString *user = URL.user, *password = URL.password;
	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 (URL.path != nil)
		path = URL.URLEncodedPath;
	if (URI.path != nil)
		path = URI.percentEncodedPath;
	else
		path = @"/";

	requestString = [OFMutableString stringWithFormat:
	    @"%s %@", OFHTTPRequestMethodName(method), path];

	if (URL.query != nil) {
	if (URI.query != nil) {
		[requestString appendString: @"?"];
		[requestString appendString: URL.URLEncodedQuery];
		[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 = URL.port;
		OFNumber *port = URI.port;

		if (port != nil) {
			OFString *host = [OFString stringWithFormat:
			    @"%@:%@", URL.URLEncodedHost, port];
			    @"%@:%@", URI.percentEncodedHost, port];

			[headers setObject: host forKey: @"Host"];
		} else
			[headers setObject: URL.URLEncodedHost forKey: @"Host"];
			[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
301

302
303
304
305
306
307
308
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
{
	OFURL *URL = _request.URL;
	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
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
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->_lastURL = [URL copy];
		_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;
		OFURL *newURL;
		OFString *newURLScheme;
		OFURI *newURI;
		OFString *newURIScheme;

		newURL = [OFURL URLWithString: location
		newURI = [OFURI URIWithString: location relativeToURI: URI];
				relativeToURL: URL];
		newURLScheme = newURL.scheme;
		newURIScheme = newURI.scheme;

		if ([newURLScheme caseInsensitiveCompare: @"http"] !=
		if ([newURIScheme caseInsensitiveCompare: @"http"] !=
		    OFOrderedSame &&
		    [newURLScheme caseInsensitiveCompare: @"https"] !=
		    [newURIScheme caseInsensitiveCompare: @"https"] !=
		    OFOrderedSame)
			follow = false;

		if (!_client->_allowsInsecureRedirects &&
		    [URL.scheme caseInsensitiveCompare: @"https"] ==
		    [URI.scheme caseInsensitiveCompare: @"https"] ==
		    OFOrderedSame &&
		    [newURLScheme caseInsensitiveCompare: @"http"] ==
		    [newURIScheme caseInsensitiveCompare: @"http"] ==
		    OFOrderedSame)
			follow = false;

		if (follow && [_client->_delegate respondsToSelector: @selector(
		    client:shouldFollowRedirect:statusCode:request:response:)])
		if (follow && [_client->_delegate respondsToSelector:
		    @selector(client:shouldFollowRedirectToURI:statusCode:
		    request:response:)])
			follow = [_client->_delegate client: _client
				       shouldFollowRedirect: newURL
				  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 (![newURL.host isEqual: URL.host])
			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
406

407
408
409
410
411
412
413
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.URL = newURL;
			newRequest.URI = newURI;
			newRequest.headers = newHeaders;

			_client->_inProgress = false;

			[_client asyncPerformRequest: newRequest
					   redirects: _redirects - 1];
			return;
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
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 [OFInvalidServerReplyException exception];
		@throw [OFInvalidServerResponseException exception];

	_version = [[line substringWithRange: OFRangeMake(5, 3)] copy];
	_version = [[line substringWithRange: OFMakeRange(5, 3)] copy];
	if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"])
		@throw [OFUnsupportedVersionException
		    exceptionWithVersion: _version];

	status = [line substringWithRange: OFRangeMake(9, 3)].longLongValue;
	status = [line substringWithRange: OFMakeRange(9, 3)].longLongValue;

	if (status < 0 || status > 599)
		@throw [OFInvalidServerReplyException exception];
		@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 [OFInvalidServerReplyException exception];
		@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
508

509
510
511
512
513
514
515
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 [OFInvalidServerReplyException exception];
		@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
547


548
549
550
551
552
553
554
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 = [OFInvalidServerReplyException exception];
			exception =
			    [OFInvalidServerResponseException exception];

		[self raiseException: exception];
		return false;
	}

	@try {
		if (_firstLine) {
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
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.URL.scheme caseInsensitiveCompare: @"https"] ==
	if ([_request.URI.scheme caseInsensitiveCompare: @"https"] ==
	    OFOrderedSame) {
		OFTLSStream *stream;
		@try {
			stream = [OFTLSStream streamWithStream: sock];
		} @catch (OFNotImplementedException *e) {
			[self raiseException:
			    [OFUnsupportedProtocolException
			    exceptionWithURL: _request.URL]];
			    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.URL.host];
		[stream asyncPerformClientHandshakeWithHost: _request.URI.host];
	} else {
		sock.delegate = self;
		[self performSelector: @selector(handleStream:)
			   withObject: sock
			   afterDelay: 0];
	}
}
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
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
{
	OFURL *URL = _request.URL;
	OFURI *URI = _request.URI;
	OFStream *stream;

	/* Can we reuse the last socket? */
	if (_client->_stream != nil && !_client->_stream.atEndOfStream &&
	    [_client->_lastURL.scheme isEqual: URL.scheme] &&
	    [_client->_lastURL.host isEqual: URL.host] &&
	    (_client->_lastURL.port == URL.port ||
	    [_client->_lastURL.port isEqual: URL.port]) &&
	    [_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->_lastURL release];
		_client->_lastURL = 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 {
		OFURL *URL = _request.URL;
		OFURI *URI = _request.URI;
		OFTCPSocket *sock;
		uint16_t port;
		OFNumber *URLPort;
		OFNumber *URIPort;

		[_client close];

		sock = [OFTCPSocket socket];

		if ([URL.scheme caseInsensitiveCompare: @"https"] ==
		if ([URI.scheme caseInsensitiveCompare: @"https"] ==
		    OFOrderedSame)
			port = 443;
		else
			port = 80;

		URLPort = URL.port;
		if (URLPort != nil)
			port = URLPort.unsignedShortValue;
		URIPort = URI.port;
		if (URIPort != nil)
			port = URIPort.unsignedShortValue;

		sock.delegate = self;
		[sock asyncConnectToHost: URL.host port: port];
		[sock asyncConnectToHost: URI.host port: port];
	} @catch (id e) {
		[self raiseException: e];
	}
}
@end

@implementation OFHTTPClientRequestBodyStream
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
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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];
		}
	}
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
{
	if (_stream == nil)
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
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 [OFInvalidServerReplyException
				@throw [OFInvalidServerResponseException
				    exception];
		case 1:
			_toRead++;
			if (tmp[0] != '\r')
				@throw [OFInvalidServerReplyException
				@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 [OFInvalidServerReplyException
				@throw [OFInvalidServerResponseException
				    exception];
		}

		if (_setAtEndOfStream && _toRead == 0)
			_atEndOfStream = true;

		return 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
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 [OFInvalidServerReplyException exception];
			@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 [OFInvalidServerReplyException
				@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 [OFInvalidServerReplyException exception];
			@throw [OFInvalidServerResponseException exception];
		}

		if (_toRead == 0) {
			_setAtEndOfStream = true;
			_toRead = -2;
		}

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
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
  shouldFollowRedirect: (OFURL *)URL
	    statusCode: (short)statusCode
	       request: (OFHTTPRequest *)request
	      response: (OFHTTPResponse *)response
-	       (bool)client: (OFHTTPClient *)client
  shouldFollowRedirectToURI: (OFURI *)URI
		 statusCode: (short)statusCode
		    request: (OFHTTPRequest *)request
		   response: (OFHTTPResponse *)response
{
	if ([_delegate respondsToSelector: @selector(client:
	    shouldFollowRedirect:statusCode:request:response:)])
		return [_delegate client: client
		    shouldFollowRedirect: URL
			      statusCode: statusCode
				 request: request
				response: 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
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
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();
	OFURL *URL = request.URL;
	OFString *scheme = URL.scheme;
	OFURI *URI = request.URI;
	OFString *scheme = URI.scheme;

	if ([scheme caseInsensitiveCompare: @"http"] != OFOrderedSame &&
	    [scheme caseInsensitiveCompare: @"https"] != OFOrderedSame)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];
		@throw [OFUnsupportedProtocolException exceptionWithURI: URI];

	if (_inProgress)
		/* TODO: Find a better exception */
		@throw [OFAlreadyConnectedException exception];

	_inProgress = true;

	[[[[OFHTTPClientRequestHandler alloc]
	    initWithClient: self
		   request: request
		 redirects: redirects] autorelease] start];

	objc_autoreleasePoolPop(pool);
}

- (void)close
{
	[_stream release];
	_stream = nil;

	[_lastURL release];
	_lastURL = 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
25

26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 OFURL;
@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;
	OF_RESERVE_IVARS(OFHTTPCookie, 4)
}

/**
 * @brief The name of the cookie.
 */
@property (copy, nonatomic) OFString *name;

76
77
78
79
80
81
82
83

84
85
86
87

88


89
90
91
92

93
94
95
96
97
98
99
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 URL and
 * @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 URL The URL for 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
    forURL: (OFURL *)URL;
    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
22

23
24
25
26
27
28
29
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 "OFURL.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
65

66
67
68
69
70

71
72
73
74
75
76
77
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
    forURL: (OFURL *)URL
    forURI: (OFURI *)URI
{
	OFMutableArray OF_GENERIC(OFHTTPCookie *) *ret = [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();
	OFString *string = [headerFields objectForKey: @"Set-Cookie"];
	OFString *domain = URL.host;
	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
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
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:
				    OFRangeMake(last, i - last)];
				    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:
				    OFRangeMake(last, i - last)];
				    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:
				    OFRangeMake(last, i - last)];
				    OFMakeRange(last, i - last)];
				[ret addObject:
				    [OFHTTPCookie cookieWithName: name
							   value: value
							  domain: domain]];

				state = statePostQuotedValue;
			}
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
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:
				    OFRangeMake(last, i - last)];
				    OFMakeRange(last, i - last)];

				state = stateAttrValue;
				last = i + 1;
			} else if (characters[i] == ';' ||
			    characters[i] == ',') {
				name = [string substringWithRange:
				    OFRangeMake(last, i - last)];
				    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:
				    OFRangeMake(last, i - last)];
				    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
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
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:
		    OFRangeMake(last, length - last)];
		    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:
			    OFRangeMake(last, length - last)];
			    OFMakeRange(last, length - last)];

			handleAttribute(ret.lastObject, name, nil);
		}
		break;
	case stateAttrValue:
		value = [string substringWithRange:
		    OFRangeMake(last, length - last)];
		    OFMakeRange(last, length - last)];

		handleAttribute(ret.lastObject, name, value);

		break;
	}

	objc_autoreleasePoolPop(pool);
367
368
369
370
371
372
373
374
375


376
377
378
379
380
381
382
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);
	OFHashAdd(&hash, _secure);
	OFHashAdd(&hash, _HTTPOnly);
	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
23

24
25
26
27
28
29
30
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 OFURL;
@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
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
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 URL.
 * @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 URL The URL for which the cookie should be added
 * @param URI The URI for which the cookie should be added
 */
- (void)addCookie: (OFHTTPCookie *)cookie forURL: (OFURL *)URL;
- (void)addCookie: (OFHTTPCookie *)cookie forURI: (OFURI *)URI;

/**
 * @brief Adds the specified cookies for the specified URL.
 * @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 URL The URL for which the cookies should be added
 * @param URI The URI for which the cookies should be added
 */
- (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies
	    forURL: (OFURL *)URL;
	    forURI: (OFURI *)URI;

/**
 * @brief Returns the cookies for the specified URL.
 * @brief Returns the cookies for the specified URI.
 *
 * @param URL The URL for which the cookies should be returned
 * @return The cookies for the specified URL
 * @param URI The URI for which the cookies should be returned
 * @return The cookies for the specified URI
 */
- (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURL: (OFURL *)URL;
- (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
22

23
24
25
26
27
28
29
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 "OFURL.h"
#import "OFURI.h"

@implementation OFHTTPCookieManager
+ (instancetype)manager
{
	return [[[self alloc] init] 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
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 forURL: (OFURL *)URL
- (void)addCookie: (OFHTTPCookie *)cookie forURI: (OFURI *)URI
{
	void *pool = objc_autoreleasePoolPush();
	OFString *cookieDomain, *URLHost;
	OFString *cookieDomain, *URIHost;
	size_t i;

	if (![cookie.path hasPrefix: @"/"])
		cookie.path = @"/";

	if (cookie.secure &&
	    [URL.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) {
	    [URI.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) {
		objc_autoreleasePoolPop(pool);
		return;
	}

	cookieDomain = cookie.domain.lowercaseString;
	cookie.domain = cookieDomain;

	URLHost = URL.host.lowercaseString;
	if (![cookieDomain isEqual: URLHost]) {
		URLHost = [@"." stringByAppendingString: URLHost];
	URIHost = URI.host.lowercaseString;
	if (![cookieDomain isEqual: URIHost]) {
		URIHost = [@"." stringByAppendingString: URIHost];

		if (![cookieDomain hasSuffix: URLHost]) {
		if (![cookieDomain hasSuffix: URIHost]) {
			objc_autoreleasePoolPop(pool);
			return;
		}
	}

	i = 0;
	for (OFHTTPCookie *iter in _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
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
	    forURL: (OFURL *)URL
	    forURI: (OFURI *)URI
{
	for (OFHTTPCookie *cookie in cookies)
		[self addCookie: cookie forURL: URL];
		[self addCookie: cookie forURI: URI];
}

- (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURL: (OFURL *)URL
- (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURI: (OFURI *)URI
{
	OFMutableArray *ret = [OFMutableArray array];

	for (OFHTTPCookie *cookie in _cookies) {
		void *pool;
		OFDate *expires;
		OFString *cookieDomain, *URLHost, *cookiePath, *URLPath;
		OFString *cookieDomain, *URIHost, *cookiePath, *URIPath;
		bool match;

		expires = cookie.expires;
		if (expires != nil && expires.timeIntervalSinceNow <= 0)
			continue;

		if (cookie.secure && [URL.scheme caseInsensitiveCompare:
		if (cookie.secure && [URI.scheme caseInsensitiveCompare:
		    @"https"] != OFOrderedSame)
			continue;

		pool = objc_autoreleasePoolPush();

		cookieDomain = cookie.domain.lowercaseString;
		URLHost = URL.host.lowercaseString;
		URIHost = URI.host.lowercaseString;
		if ([cookieDomain hasPrefix: @"."]) {
			if ([URLHost hasSuffix: cookieDomain])
			if ([URIHost hasSuffix: cookieDomain])
				match = true;
			else {
				cookieDomain =
				    [cookieDomain substringFromIndex: 1];

				match = [cookieDomain isEqual: URLHost];
				match = [cookieDomain isEqual: URIHost];
			}
		} else
			match = [cookieDomain isEqual: URLHost];
			match = [cookieDomain isEqual: URIHost];

		if (!match) {
			objc_autoreleasePoolPop(pool);
			continue;
		}

		cookiePath = cookie.path;
		URLPath = URL.path;
		URIPath = URI.path;
		if (![cookiePath isEqual: @"/"]) {
			if ([cookiePath isEqual: URLPath])
			if ([cookiePath isEqual: URIPath])
				match = true;
			else {
				if (![cookiePath hasSuffix: @"/"])
					cookiePath = [cookiePath
					    stringByAppendingString: @"/"];

				match = [URLPath hasPrefix: cookiePath];
				match = [URIPath hasPrefix: cookiePath];
			}

			if (!match) {
				objc_autoreleasePoolPop(pool);
				continue;
			}
		}

Modified src/OFHTTPRequest.h from [2a4f5e7d62] to [1278addd47].

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
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 OFURL;
@class OFURI;
@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFData;
@class OFString;

/** @file */

/**
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
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>
{
	OFURL *_URL;
	OFURI *_URI;
	OFHTTPRequestMethod _method;
	OFHTTPRequestProtocolVersion _protocolVersion;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers;
	OFSocketAddress _remoteAddress;
	bool _hasRemoteAddress;
	OF_RESERVE_IVARS(OFHTTPRequest, 4)
}

/**
 * @brief The URL of the HTTP request.
 * @brief The URI of the HTTP request.
 */
@property (copy, nonatomic) OFURL *URL;
@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
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
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







-
+

-
-
-
-
-
-
-
-
+


-
+


-
+

-
+


-
+
+
+



















+
+







 * @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.
 * @brief Creates a new OFHTTPRequest with the specified URI.
 *
 * @return A new, autoreleased OFHTTPRequest
 */
+ (instancetype)request;

/**
 * @brief Creates a new OFHTTPRequest with the specified URL.
 *
 * @param URL The URL for the request
 * @param URI The URI for the request
 * @return A new, autoreleased OFHTTPRequest
 */
+ (instancetype)requestWithURL: (OFURL *)URL;
+ (instancetype)requestWithURI: (OFURI *)URI;

/**
 * @brief Initializes an already allocated OFHTTPRequest with the specified URL.
 * @brief Initializes an already allocated OFHTTPRequest with the specified URI.
 *
 * @param URL The URL for the request
 * @param URI The URI for the request
 * @return An initialized OFHTTPRequest
 */
- (instancetype)initWithURL: (OFURL *)URL;
- (instancetype)initWithURI: (OFURI *)URI;

- (instancetype)init OF_UNAVAILABLE;
@end

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Returns a C string describing the specified request method.
 *
 * @param method The request method which should be described as a C string
 * @return A C string describing the specified request method
 */
extern const char *_Nullable OFHTTPRequestMethodName(
    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 [31af8cb418] to [c85955ea02].

15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
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 "OFURL.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
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
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 [OFInvalidArgumentException exception];
	@throw [OFInvalidFormatException exception];
}

@implementation OFHTTPRequest
@synthesize URL = _URL, method = _method, headers = _headers;
@synthesize URI = _URI, method = _method, headers = _headers;

+ (instancetype)request
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)requestWithURL: (OFURL *)URL
+ (instancetype)requestWithURI: (OFURI *)URI
{
	return [[[self alloc] initWithURL: URL] autorelease];
	return [[[self alloc] initWithURI: URI] autorelease];
}

- (instancetype)init
- (instancetype)initWithURI: (OFURI *)URI
{
	self = [super init];

	@try {
		_URI = [URI copy];
	_method = OFHTTPRequestMethodGet;
	_protocolVersion.major = 1;
	_protocolVersion.minor = 1;
		_method = OFHTTPRequestMethodGet;
		_protocolVersion.major = 1;
		_protocolVersion.minor = 1;

	return self;
}

- (instancetype)initWithURL: (OFURL *)URL
{
	self = [self init];

	@try {
		_URL = [URL copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_URL release];
	[_URI release];
	[_headers release];

	[super dealloc];
}

- (void)setRemoteAddress: (const OFSocketAddress *)remoteAddress
{
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
129
130
131
132
133
134
135

136
137
138
139
140

141
142
143
144
145
146
147







-
+




-







		return &_remoteAddress;

	return NULL;
}

- (id)copy
{
	OFHTTPRequest *copy = [[OFHTTPRequest alloc] init];
	OFHTTPRequest *copy = [[OFHTTPRequest alloc] initWithURI: _URI];

	@try {
		copy->_method = _method;
		copy->_protocolVersion = _protocolVersion;
		copy.URL = _URL;
		copy.headers = _headers;
		copy.remoteAddress = self.remoteAddress;
	} @catch (id e) {
		[copy release];
		@throw e;
	}

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
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->_URL isEqual: _URL] ||
	    ![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);

	OFHashAdd(&hash, _method);
	OFHashAdd(&hash, _protocolVersion.major);
	OFHashAdd(&hash, _protocolVersion.minor);
	OFHashAddHash(&hash, _URL.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;
261
262
263
264
265
266
267
268

269
270
271
272
273

274
275
276
277
278
279
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\tURL = %@\n"
	    @"<%@:\n\tURI = %@\n"
	    @"\tMethod = %s\n"
	    @"\tHeaders = %@\n"
	    @"\tRemote address = %@\n"
	    @">",
	    self.class, _URL, method, indentedHeaders, remoteAddress];
	    self.class, _URI, method, indentedHeaders, remoteAddress];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}
@end

Modified src/OFHTTPResponse.h from [d907091625] to [3c482db81b].

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
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







-
+

+
+
+





-



-
+
+
+
+




-
+
+
+
+
+
+




-
+




-
+





-
+
+
+
+

-
+


-
+


-
+

-
+








@class OFDictionary OF_GENERIC(KeyType, ObjectType);
@class OFArray OF_GENERIC(ObjectType);

/**
 * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h
 *
 * @brief A class for representing an HTTP request reply as a stream.
 * @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;
	OF_RESERVE_IVARS(OFHTTPResponse, 4)
}

/**
 * @brief The protocol version of the HTTP request reply.
 * @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 reply as a string.
 * @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 reply to the HTTP request.
 * @brief The status code of the response to the HTTP request.
 */
@property (nonatomic) short statusCode;

/**
 * @brief The headers of the reply to the HTTP request.
 * @brief The headers of the response to the HTTP request.
 */
@property (copy, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *)
    *headers;

/**
 * @brief The reply as a string, trying to detect the encoding.
 * @brief Read the response as a string, trying to detect the encoding and
 *	  falling back to the specified encoding if not detectable.
 *
 * @return The response as a string
 */
@property (readonly, nonatomic) OFString *string;
- (OFString *)readString;

/**
 * @brief Returns the reply as a string, trying to detect the encoding and
 * @brief Rread the response as a string, trying to detect the encoding and
 *	  falling back to the specified encoding if not detectable.
 *
 * @return The reply as a string
 * @return The response as a string
 */
- (OFString *)stringWithEncoding: (OFStringEncoding)encoding;
- (OFString *)readStringWithEncoding: (OFStringEncoding)encoding;
@end

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Returns a description string for the specified HTTP status code.

Modified src/OFHTTPResponse.m from [0f4a35ed7a] to [17a72a5d36].

292
293
294
295
296
297
298
299

300
301

302
303
304

305
306
307
308
309
310
311
292
293
294
295
296
297
298

299
300

301
302
303

304
305
306
307
308
309
310
311







-
+

-
+


-
+







- (OFString *)protocolVersionString
{
	return [OFString stringWithFormat: @"%hhu.%hhu",
					   _protocolVersion.major,
					   _protocolVersion.minor];
}

- (OFString *)string
- (OFString *)readString
{
	return [self stringWithEncoding: OFStringEncodingAutodetect];
	return [self readStringWithEncoding: OFStringEncodingAutodetect];
}

- (OFString *)stringWithEncoding: (OFStringEncoding)encoding
- (OFString *)readStringWithEncoding: (OFStringEncoding)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFString *contentType, *contentLengthString, *ret;
	OFData *data;

	if (encoding == OFStringEncodingAutodetect &&
	    (contentType = [_headers objectForKey: @"Content-Type"]) != nil)

Modified src/OFHTTPServer.h from [df6e847201] to [ba5fc5aae1].

60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74
75







-
+
+







 *	   connections will still be handled and you can start accepting new
 *	   connections again by calling @ref OFHTTPServer::start again.
 */
-			  (bool)server: (OFHTTPServer *)server
  didReceiveExceptionOnListeningSocket: (id)exception;

/**
 * @brief This method is called when a client socket encountered an exception.
 * @brief This method is called when a socket for a client encountered an
 * exception.
 *
 * This can happen when the OFHTTPServer tries to properly close the
 * connection. If no headers have been sent yet, it will send headers, and if
 * chunked transfer encoding was used, it will send a chunk of size 0. However,
 * if the other end already closed the connection before that, this will raise
 * an exception.
 *
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
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.
 *
 * Setting this after @ref start has been called raises an
 * @ref OFAlreadyConnectedException.
 * @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.
 *
 * Setting this after @ref start has been called raises an
 * @ref OFAlreadyConnectedException.
 * @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`.
 *
 * Setting this after @ref start has been called raises an
 * @ref OFAlreadyConnectedException.
 * @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.
 *
152
153
154
155
156
157
158


159
160
161
162
163
164
165
166
167
168
169
170
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 [879c93d87f] 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
34

35
36
37
38
39
40
41
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 "OFURL.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
362

363
364
365
366
367
368
369
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: OFRangeMake(line.length - 9, 9)];
		    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
389

390
391
392
393
394
395
396
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 = OFRangeMake(pos + 1, line.length - pos - 10);
		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
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
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();
	OFMutableURL *URL;
	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];
	}

	URL = [OFMutableURL URL];
	URI = [OFMutableURI URIWithScheme: @"http"];
	URL.scheme = @"http";
	URL.host = _host;
	URI.host = _host;
	if (_port != 80)
		URL.port = [OFNumber numberWithUnsignedShort: _port];
		URI.port = [OFNumber numberWithUnsignedShort: _port];

	@try {
	if ((pos = [_path rangeOfString: @"?"].location) != OFNotFound) {
		OFString *path, *query;
		if ((pos = [_path rangeOfString: @"?"].location) !=
		    OFNotFound) {
			OFString *path, *query;

		path = [_path substringToIndex: pos];
		query = [_path substringFromIndex: pos + 1];
			path = [_path substringToIndex: pos];
			query = [_path substringFromIndex: pos + 1];

		URL.URLEncodedPath = path;
		URL.URLEncodedQuery = query;
	} else
		URL.URLEncodedPath = _path;

	[URL makeImmutable];
			URI.percentEncodedPath = path;
			URI.percentEncodedQuery = query;
		} else
			URI.percentEncodedPath = _path;
	} @catch (OFInvalidFormatException *e) {
		objc_autoreleasePoolPop(pool);
		[self sendErrorAndClose: 400];
		return;
	}

	[URI makeImmutable];

	request = [OFHTTPRequest requestWithURL: URL];
	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
16

17
18
19
20

21
22
23
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 "OFURLHandler.h"
#import "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@interface OFHTTPURLHandler: OFURLHandler
@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
18

19
20
21
22
23
24


25
26
27
28
29

30
31
32
33
34
35
36
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 "OFHTTPURLHandler.h"
#import "OFHTTPURIHandler.h"
#import "OFHTTPClient.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"

@implementation OFHTTPURLHandler
- (OFStream *)openItemAtURL: (OFURL *)URL
@implementation OFHTTPURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
		       mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFHTTPClient *client = [OFHTTPClient client];
	OFHTTPRequest *request = [OFHTTPRequest requestWithURL: URL];
	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
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
61

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
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 prependString: @"\""];
	[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: OFRangeMake(1, string.length - 2)];
	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 [85f822e023] to [f35fd21473].

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
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 path The path to the file whose contents the OFINIFile should contain
 * @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)fileWithPath: (OFString *)path;
+ (instancetype)fileWithURI: (OFURI *)URI;

/**
 * @brief Creates a new OFINIFile with the contents of the specified file in
 *	  the specified encoding.
 *
 * @param path The path to the file whose contents the OFINIFile should contain
 * @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)fileWithPath: (OFString *)path
		    encoding: (OFStringEncoding)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 path The path to the file whose contents the OFINIFile should contain
 * @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)initWithPath: (OFString *)path;
- (instancetype)initWithURI: (OFURI *)URI;

/**
 * @brief Initializes an already allocated OFINIFile with the contents of the
 *	  specified file in the specified encoding.
 *
 * @param path The path to the file whose contents the OFINIFile should contain
 * @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)initWithPath: (OFString *)path
		    encoding: (OFStringEncoding)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 path The path of the file to write to
 * @param URI The URI of the file to write to
 */
- (void)writeToFile: (OFString *)path;
- (void)writeToURI: (OFURI *)URI;

/**
 * @brief Writes the contents of the OFINIFile to a file in the specified
 *	  encoding.
 *
 * @param path The path of the file to write to
 * @param URI The URI of the file to write to
 * @param encoding The encoding to use
 */
- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding;
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding;
@end

OF_ASSUME_NONNULL_END

Modified src/OFINIFile.m from [f3dcfaef7e] to [7850530cf1].

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
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







+
-
-
-
-
+
+
+
+
+






-
+


















-
+

-
+


-
-
+

-
+
-







-
+

-
+


-
-
+






-
+








#include "config.h"

#include <errno.h>

#import "OFINIFile.h"
#import "OFArray.h"
#import "OFINICategory+Private.h"
#import "OFString.h"
#import "OFFile.h"
#import "OFINICategory.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_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding;
- (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)fileWithPath: (OFString *)path
+ (instancetype)fileWithURI: (OFURI *)URI
{
	return [[[self alloc] initWithPath: path] autorelease];
	return [[[self alloc] initWithURI: URI] autorelease];
}

+ (instancetype)fileWithPath: (OFString *)path
		    encoding: (OFStringEncoding)encoding
+ (instancetype)fileWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	return [[[self alloc] initWithPath: path
	return [[[self alloc] initWithURI: URI encoding: encoding] autorelease];
				  encoding: encoding] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPath: (OFString *)path
- (instancetype)initWithURI: (OFURI *)URI
{
	return [self initWithPath: path encoding: OFStringEncodingUTF8];
	return [self initWithURI: URI encoding: OFStringEncodingAutodetect];
}

- (instancetype)initWithPath: (OFString *)path
		    encoding: (OFStringEncoding)encoding
- (instancetype)initWithURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	self = [super init];

	@try {
		_categories = [[OFMutableArray alloc] init];

		[self of_parseFile: path encoding: encoding];
		[self of_parseURI: URI encoding: encoding];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
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_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding
- (void)of_parseURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *file;
	OFINICategory *category = nil;
	OFString *line;

	if (encoding == OFStringEncodingAutodetect)
		encoding = OFStringEncodingUTF8;

	@try {
		file = [OFFile fileWithPath: path mode: @"r"];
		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:
			    OFRangeMake(1, line.length - 2)];
			    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)writeToFile: (OFString *)path
- (void)writeToURI: (OFURI *)URI
{
	[self writeToFile: path encoding: OFStringEncodingUTF8];
	[self writeToURI: URI encoding: OFStringEncodingUTF8];
}

- (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file = [OFFile fileWithPath: path mode: @"w"];
	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 [1f5bf8dc61] to [125e92a3e8].

13
14
15
16
17
18
19

20
21

22
23
24
25

26
27
28
29
30
13
14
15
16
17
18
19
20
21

22
23
24
25

26
27
28
29
30
31







+

-
+



-
+





 * file.
 */

#import "OFSettings.h"

OF_ASSUME_NONNULL_BEGIN

@class OFINIFile;
@class OFString;
@class OFINIFile;
@class OFURI;

@interface OFINIFileSettings: OFSettings
{
	OFString *_filePath;
	OFURI *_fileURI;
	OFINIFile *_INIFile;
}
@end

OF_ASSUME_NONNULL_END

Modified src/OFINIFileSettings.m from [768ab5ebfe] to [b3d1a39e2b].

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
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 "OFINIFileSettings.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFINIFile.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"];
		_filePath = [[[OFSystemInfo userConfigPath]
		    stringByAppendingPathComponent: fileName] copy];
		_INIFile = [[OFINIFile alloc] initWithPath: _filePath];
		_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
{
	[_filePath release];
	[_fileURI release];
	[_INIFile release];

	[super dealloc];
}

- (void)of_getCategory: (OFString **)category
		andKey: (OFString **)key
238
239
240
241
242
243
244
245

246
247
239
240
241
242
243
244
245

246
247
248







-
+


	[[_INIFile categoryForName: category] removeValueForKey: key];

	objc_autoreleasePoolPop(pool);
}

- (void)save
{
	[_INIFile writeToFile: _filePath];
	[_INIFile writeToURI: _fileURI];
}
@end

Modified src/OFIPXSocket.h from [a2ca3d4d82] to [08f31366a1].

67
68
69
70
71
72
73


74
75
76
77
78
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/OFIPXSocket.m from [832ec6a7bd] to [f0059481b5].

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
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







-
+







-
+














+
-
+















-
+












-
+







#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeIPX(zeroNode, 0, port);
	address = OFSocketAddressMakeIPX(0, zeroNode, port);

#ifdef OF_WINDOWS
	protocol = NSPROTO_IPX + packetType;
#else
	_packetType = address.sockaddr.ipx.sipx_type = packetType;
#endif

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.ipx.sipx_family,
	    SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithPort: port
			   packetType: packetType
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (bind(_socket, (struct sockaddr *)&address.sockaddr,
	if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: packetType
							 socket: self
							  errNo: errNo];
	}

	memset(&address, 0, sizeof(address));
	address.family = OFSocketAddressFamilyIPX;
	address.length = (socklen_t)sizeof(address.sockaddr);

	if (OFGetSockName(_socket, &address.sockaddr.sockaddr,
	if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
	    &address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: packetType
							 socket: self
							  errNo: errNo];
	}

	if (address.sockaddr.sockaddr.sa_family != AF_IPX) {
	if (address.sockaddr.ipx.sipx_family != AF_IPX) {
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: packetType
							 socket: self
							  errNo: EAFNOSUPPORT];

Modified src/OFInflate64Stream.h from [a8a5f45dbe] to [2f3dc057f8].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 "OFStream.h"
#import "OFHuffmanTree.h"
#import "OFKernelEventObserver.h"

OF_ASSUME_NONNULL_BEGIN

#define OFInflate64StreamBufferSize 4096

/**
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
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







-
-
-
-
+
+
+
+






-
-
-
+
+
+







			uint8_t position;
			uint8_t length[4];
		} uncompressedHeader;
		struct {
			uint16_t position, length;
		} uncompressed;
		struct {
			OFHuffmanTree _Nullable litLenTree;
			OFHuffmanTree _Nullable distTree;
			OFHuffmanTree _Nullable codeLenTree;
			OFHuffmanTree _Nullable treeIter;
			struct _OFHuffmanTree *_Nullable litLenTree;
			struct _OFHuffmanTree *_Nullable distTree;
			struct _OFHuffmanTree *_Nullable codeLenTree;
			struct _OFHuffmanTree *_Nullable treeIter;
			uint8_t *_Nullable lengths;
			uint16_t receivedCount;
			uint8_t value, litLenCodesCount, distCodesCount;
			uint8_t codeLenCodesCount;
		} huffmanTree;
		struct {
			OFHuffmanTree _Nullable litLenTree;
			OFHuffmanTree _Nullable distTree;
			OFHuffmanTree _Nullable treeIter;
			struct _OFHuffmanTree *_Nullable litLenTree;
			struct _OFHuffmanTree *_Nullable distTree;
			struct _OFHuffmanTree *_Nullable treeIter;
			int state;
			uint16_t value, length, distance, extraBits;
		} huffman;
	} _context;
	bool _inLastBlock, _atEndOfStream;
}

Modified src/OFInflateStream.h from [a63ce643c9] to [fe62e030fd].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 "OFStream.h"
#import "OFHuffmanTree.h"
#import "OFKernelEventObserver.h"

OF_ASSUME_NONNULL_BEGIN

#define OFInflateStreamBufferSize 4096

/**
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
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







-
-
-
-
+
+
+
+






-
-
-
+
+
+







			uint8_t position;
			uint8_t length[4];
		} uncompressedHeader;
		struct {
			uint16_t position, length;
		} uncompressed;
		struct {
			OFHuffmanTree _Nullable litLenTree;
			OFHuffmanTree _Nullable distTree;
			OFHuffmanTree _Nullable codeLenTree;
			OFHuffmanTree _Nullable treeIter;
			struct _OFHuffmanTree *_Nullable litLenTree;
			struct _OFHuffmanTree *_Nullable distTree;
			struct _OFHuffmanTree *_Nullable codeLenTree;
			struct _OFHuffmanTree *_Nullable treeIter;
			uint8_t *_Nullable lengths;
			uint16_t receivedCount;
			uint8_t value, litLenCodesCount, distCodesCount;
			uint8_t codeLenCodesCount;
		} huffmanTree;
		struct {
			OFHuffmanTree _Nullable litLenTree;
			OFHuffmanTree _Nullable distTree;
			OFHuffmanTree _Nullable treeIter;
			struct _OFHuffmanTree *_Nullable litLenTree;
			struct _OFHuffmanTree *_Nullable distTree;
			struct _OFHuffmanTree *_Nullable treeIter;
			int state;
			uint16_t value, length, distance, extraBits;
		} huffman;
	} _context;
	bool _inLastBlock, _atEndOfStream;
}

Modified src/OFInvocation.h from [324ba0dca4] to [ab7d9433d5].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
40
41
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;
	OF_RESERVE_IVARS(OFInvocation, 4)
}

/**
 * @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
48
49


50
51
52
53
54
55
56
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::tryReadTillDelimiter: has
 *	 been called on the stream, this callback will not be called again
 *	 @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
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
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
34

35
36
37
38
39
40
41
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 "OFObserveFailedException.h"
#import "OFObserveKernelEventsFailedException.h"
#import "OFOutOfRangeException.h"

#define eventListSize 64

@implementation OFKqueueKernelEventObserver
- (instancetype)init
{
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
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    exceptionWithObserver: self
				    errNo: errno];

	for (int i = 0; i < events; i++) {
		void *pool;

		if (eventList[i].flags & EV_ERROR)
			@throw [OFObserveFailedException
			@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
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
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
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;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFLHAArchive object with the specified file.
 *
 * @param path The path to the LHA 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)archiveWithPath: (OFString *)path mode: (OFString *)mode;
#endif
+ (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;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFLHAArchive object with the
 *	  specified file.
 *
 * @param path The path to the LHA 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)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode;
#endif

/**
 * @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
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
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 "OFCRC16.h"
#import "OFArchiveURIHandler.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#import "OFCRC16.h"
#endif
#import "OFLHADecompressingStream.h"
#import "OFSeekableStream.h"
#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFString.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;
	uint32_t _toRead, _bytesConsumed;
	unsigned long long _toRead;
	uint16_t _CRC16;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry;
- (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;
	OFFileOffset _headerOffset;
	OFStreamOffset _headerOffset;
	uint32_t _bytesWritten;
	uint16_t _CRC16;
}

- (instancetype)of_initWithArchive: (OFLHAArchive *)archive
- (instancetype)of_initWithStream: (OFSeekableStream *)stream
			    entry: (OFLHAArchiveEntry *)entry
			 encoding: (OFStringEncoding)encoding;
			    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];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}
#endif

+ (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
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
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: SEEK_END];
							   whence: OFSeekEnd];

		_encoding = OFStringEncodingISO8859_1;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURIHandler openItemAtURI: URI mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURIHandler openItemAtURI: URI mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[_currentEntry release];

	[super dealloc];
}

- (OFLHAArchiveEntry *)nextEntry
{
	OFLHAArchiveEntry *entry;
	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 release];
	_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];
	}

	entry = [[[OFLHAArchiveEntry alloc]
	_currentEntry= [[OFLHAArchiveEntry alloc]
	    of_initWithHeader: header
		       stream: _stream
		     encoding: _encoding] autorelease];
		     encoding: _encoding];

	_lastReturnedStream = [[OFLHAArchiveFileReadStream alloc]
	    of_initWithStream: _stream
			entry: entry];

	return entry;
	return _currentEntry;
}

- (OFStream *)streamForReadingCurrentEntry
{
	if (_mode != modeRead)
		@throw [OFInvalidArgumentException exception];

	if (_lastReturnedStream == nil)
	if (_currentEntry == nil)
		@throw [OFInvalidArgumentException exception];

	return [[(OFLHAArchiveFileReadStream *)_lastReturnedStream
	    retain] autorelease];
	_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
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
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 release];
	_lastReturnedStream = nil;

	_lastReturnedStream = [[OFLHAArchiveFileWriteStream alloc]
	    of_initWithStream: (OFSeekableStream *)_stream
			entry: entry
		     encoding: _encoding];
	_lastReturnedStream = [[[OFLHAArchiveFileWriteStream alloc]
	    of_initWithArchive: self
			stream: (OFSeekableStream *)_stream
			 entry: entry
		      encoding: _encoding] autorelease];

	return [[(OFLHAArchiveFileWriteStream *)_lastReturnedStream
	return _lastReturnedStream;
	    retain] autorelease];
}

- (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 release];
	_lastReturnedStream = nil;

	[_stream release];
	_stream = nil;
}
@end

@implementation OFLHAArchiveFileReadStream
- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFLHAArchiveEntry *)entry
- (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
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
338

339
340
341
342
343
344
345
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 = _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
378

379
380
381
382
383
384
385
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;
	uint32_t toRead;
	unsigned long long toRead;

	if (_stream == nil || _skipped)
		return;

	stream = _stream;
	toRead = _toRead;

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
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]] &&
	    (sizeof(OFFileOffset) > 4 || toRead < INT32_MAX))
		[(OFSeekableStream *)stream seekToOffset: (OFFileOffset)toRead
						  whence: SEEK_CUR];
	    toRead < LLONG_MAX && (long long)toRead == (OFStreamOffset)toRead)
		[(OFSeekableStream *)stream seekToOffset: (OFStreamOffset)toRead
						  whence: OFSeekCurrent];
	else {
		while (toRead > 0) {
			char buffer[512];
			size_t min = toRead;
			unsigned long long min = toRead;

			if (min > 512)
				min = 512;

			toRead -= [stream readIntoBuffer: buffer length: min];
			toRead -= [stream readIntoBuffer: buffer
						  length: (size_t)min];
		}
	}

	_toRead = 0;
	_skipped = true;
}

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
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
- (instancetype)of_initWithStream: (OFSeekableStream *)stream
			    entry: (OFLHAArchiveEntry *)entry
			 encoding: (OFStringEncoding)encoding
			    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: SEEK_CUR];
		_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
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
520

521
522
523
524
525
526
527
528
529
530


531
532

533
534
535
536
537
538
539
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
{
	OFFileOffset offset;
	OFStreamOffset offset;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	_entry.uncompressedSize = _bytesWritten;
	_entry.compressedSize = _bytesWritten;
	_entry.CRC16 = _CRC16;

	offset = [_stream seekToOffset: 0 whence: SEEK_CUR];
	[_stream seekToOffset: _headerOffset whence: SEEK_SET];
	offset = [_stream seekToOffset: 0 whence: OFSeekCurrent];
	[_stream seekToOffset: _headerOffset whence: OFSeekSet];
	[_entry of_writeToStream: _stream encoding: _encoding];
	[_stream seekToOffset: offset whence: SEEK_SET];
	[_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
20
21

22
23
24
25

26
27

28
29
30
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

OF_DIRECT_MEMBERS
@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_METHOD_FAMILY(init) OF_DIRECT;
- (void)of_writeToStream: (OFStream *)stream
		encoding: (OFStringEncoding)encoding;
		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
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
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 <OFCopying, OFMutableCopying>
@interface OFLHAArchiveEntry: OFObject <OFArchiveEntry, OFCopying,
    OFMutableCopying>
{
	OFString *_fileName, *_Nullable _directoryName, *_compressionMethod;
	uint32_t _compressedSize, _uncompressedSize;
	OFDate *_date;
	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 _mode, *_Nullable _UID, *_Nullable _GID;
	OFString *_Nullable _owner, *_Nullable _group;
	OFDate *_Nullable _modificationDate;
	OFNumber *_Nullable _groupOwnerAccountID;
	OFString *_Nullable _ownerAccountName;
	OFString *_Nullable _groupOwnerAccountName;
	OFMutableArray OF_GENERIC(OFData *) *_extensions;
	OF_RESERVE_IVARS(OFLHAArchiveEntry, 4)
}

/**
 * @brief The file name of the entry.
 */
@property (readonly, copy, nonatomic) OFString *fileName;

/**
 * @brief The compression method of the entry.
 */
@property (readonly, copy, nonatomic) OFString *compressionMethod;

/**
 * @brief The compressed size of the entry's file.
 */
@property (readonly, nonatomic) uint32_t compressedSize;

/**
 * @brief The uncompressed size of the entry's file.
 */
@property (readonly, nonatomic) uint32_t uncompressedSize;

/**
 * @brief The date of the file.
 */
@property (readonly, retain, nonatomic) OFDate *date;

/**
 * @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 comment of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *fileComment;

/**
 * @brief The mode of the entry.
 */
@property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *mode;

/**
 * @brief The UID of the owner.
 */
@property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *UID;

/**
 * @brief The GID of the group.
 */
@property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic) OFNumber *GID;

/**
 * @brief The owner of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *owner;

/**
 * @brief The group of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *group;

/**
 * @brief The date of the last modification of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, retain, nonatomic)
    OFDate *modificationDate;

/**
 * @brief The LHA extensions of the file.
 */
@property (readonly, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions;

/**
 * @brief Creates a new OFLHAArchiveEntry with the specified file name.
 *
 * @param fileName The file name for the OFLHAArchiveEntry
 * @return A new, autoreleased OFLHAArchiveEntry
 */
+ (instancetype)entryWithFileName: (OFString *)fileName;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFLHAArchiveEntry with the specified
 *	  file name.
 *
 * @param fileName The file name for the OFLHAArchiveEntry
 * @return An initialized OFLHAArchiveEntry
 */
- (instancetype)initWithFileName: (OFString *)fileName;
@end

OF_ASSUME_NONNULL_END

#import "OFMutableLHAArchiveEntry.h"

Modified src/OFLHAArchiveEntry.m from [45c1be7d3b] to [b338459827].

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
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 mode;
	uint16_t POSIXPermissions;

	if (extension.count != 3)
		@throw [OFInvalidFormatException exception];

	memcpy(&mode, (char *)extension.items + 1, 2);
	mode = OFFromLittleEndian16(mode);
	memcpy(&POSIXPermissions, (char *)extension.items + 1, 2);
	POSIXPermissions = OFFromLittleEndian16(POSIXPermissions);

	[entry->_mode release];
	entry->_mode = nil;
	[entry->_POSIXPermissions release];
	entry->_POSIXPermissions = nil;

	entry->_POSIXPermissions =
	entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode];
	    [[OFNumber alloc] initWithUnsignedShort: POSIXPermissions];
}

static void
parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension,
    OFStringEncoding encoding)
{
	uint16_t UID, GID;
	uint16_t ownerAccountID, groupOwnerAccountID;

	if (extension.count != 5)
		@throw [OFInvalidFormatException exception];

	memcpy(&GID, (char *)extension.items + 1, 2);
	GID = OFFromLittleEndian16(GID);
	memcpy(&groupOwnerAccountID, (char *)extension.items + 1, 2);
	groupOwnerAccountID = OFFromLittleEndian16(groupOwnerAccountID);

	memcpy(&UID, (char *)extension.items + 3, 2);
	UID = OFFromLittleEndian16(UID);
	memcpy(&ownerAccountID, (char *)extension.items + 3, 2);
	ownerAccountID = OFFromLittleEndian16(ownerAccountID);

	[entry->_GID release];
	entry->_GID = nil;
	[entry->_groupOwnerAccountID release];
	entry->_groupOwnerAccountID = nil;

	[entry->_UID release];
	entry->_UID = nil;
	[entry->_ownerAccountID release];
	entry->_ownerAccountID = nil;

	entry->_groupOwnerAccountID =
	entry->_GID = [[OFNumber alloc] initWithUnsignedShort: GID];
	entry->_UID = [[OFNumber alloc] initWithUnsignedShort: UID];
	    [[OFNumber alloc] initWithUnsignedShort: groupOwnerAccountID];
	entry->_ownerAccountID =
	    [[OFNumber alloc] initWithUnsignedShort: ownerAccountID];
}

static void
parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension,
    OFStringEncoding encoding)
{
	[entry->_group release];
	entry->_group = nil;
	[entry->_groupOwnerAccountName release];
	entry->_groupOwnerAccountName = nil;

	entry->_group = [[OFString alloc]
	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->_owner release];
	entry->_owner = nil;
	[entry->_ownerAccountName release];
	entry->_ownerAccountName = nil;

	entry->_owner = [[OFString alloc]
	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
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
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)entryWithFileName: (OFString *)fileName
{
	return [[[self alloc] initWithFileName: fileName] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithFileName: (OFString *)fileName
- (instancetype)of_init
{
	self = [super init];

	@try {
		_fileName = [fileName copy];
		_compressionMethod = @"-lh0-";
		_date = [[OFDate alloc] initWithTimeIntervalSince1970: 0];
		_modificationDate = [[OFDate alloc] init];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
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(_compressedSize);
		_compressedSize =
		    OFFromLittleEndian32((uint32_t)_compressedSize);

		memcpy(&_uncompressedSize, header + 11, 4);
		_uncompressedSize = OFFromLittleEndian32(_uncompressedSize);
		_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;

			_date = [parseMSDOSDate(date) retain];
			_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:
			_date = [[OFDate alloc]
			_modificationDate = [[OFDate alloc]
			    initWithTimeIntervalSince1970: date];

			_CRC16 = [stream readLittleEndianInt16];
			_operatingSystemIdentifier = [stream readInt8];

			readExtensions(self, stream, encoding, true);

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
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];
	[_date release];
	[_modificationDate release];
	[_fileComment release];
	[_mode release];
	[_UID release];
	[_GID release];
	[_owner release];
	[_group 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->_date release];
		copy->_date = nil;
		[copy->_modificationDate release];
		copy->_modificationDate = nil;

		copy->_directoryName = [_directoryName copy];
		copy->_compressionMethod = [_compressionMethod copy];
		copy->_compressedSize = _compressedSize;
		copy->_uncompressedSize = _uncompressedSize;
		copy->_date = [_date copy];
		copy->_modificationDate = [_modificationDate copy];
		copy->_headerLevel = _headerLevel;
		copy->_CRC16 = _CRC16;
		copy->_operatingSystemIdentifier = _operatingSystemIdentifier;
		copy->_fileComment = [_fileComment copy];
		copy->_mode = [_mode retain];
		copy->_UID = [_UID retain];
		copy->_GID = [_GID retain];
		copy->_owner = [_owner copy];
		copy->_group = [_group copy];
		copy->_POSIXPermissions = [_POSIXPermissions retain];
		copy->_ownerAccountID = [_ownerAccountID retain];
		copy->_groupOwnerAccountID = [_groupOwnerAccountID retain];
		copy->_ownerAccountName = [_ownerAccountName copy];
		copy->_groupOwnerAccountName = [_groupOwnerAccountName copy];
		copy->_modificationDate = [_modificationDate retain];
		copy->_extensions = [_extensions copy];
	} @catch (id e) {
		[copy release];
		@throw e;
	}

	return copy;
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
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;
}

- (uint32_t)compressedSize
- (unsigned long long)compressedSize
{
	return _compressedSize;
}

- (uint32_t)uncompressedSize
- (unsigned long long)uncompressedSize
{
	return _uncompressedSize;
}

- (OFDate *)date
- (OFDate *)modificationDate
{
	return _date;
	return _modificationDate;
}

- (uint8_t)headerLevel
{
	return _headerLevel;
}

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
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 *)mode
- (OFNumber *)POSIXPermissions
{
	return _mode;
	return _POSIXPermissions;
}

- (OFNumber *)UID
- (OFNumber *)ownerAccountID
{
	return _UID;
	return _ownerAccountID;
}

- (OFNumber *)GID
- (OFNumber *)groupOwnerAccountID
{
	return _GID;
	return _groupOwnerAccountID;
}

- (OFString *)owner
- (OFString *)ownerAccountName
{
	return _owner;
	return _ownerAccountName;
}

- (OFString *)group
- (OFString *)groupOwnerAccountName
{
	return _group;
	return _groupOwnerAccountName;
}

- (OFDate *)modificationDate
{
	return _modificationDate;
}

- (OFArray OF_GENERIC(OFData *) *)extensions
{
	return _extensions;
}

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
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)
	    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(_compressedSize);
	tmp32 = OFToLittleEndian32((uint32_t)_compressedSize);
	[data addItems: &tmp32 count: sizeof(tmp32)];

	tmp32 = OFToLittleEndian32(_uncompressedSize);
	tmp32 = OFToLittleEndian32((uint32_t)_uncompressedSize);
	[data addItems: &tmp32 count: sizeof(tmp32)];

	tmp32 = OFToLittleEndian32((uint32_t)_date.timeIntervalSince1970);
	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
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
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 (_mode != nil) {
	if (_POSIXPermissions != nil) {
		tmp16 = OFToLittleEndian16(5);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x50"];

		tmp16 =
		tmp16 = OFToLittleEndian16(_mode.unsignedShortValue);
		    OFToLittleEndian16(_POSIXPermissions.unsignedShortValue);
		[data addItems: &tmp16 count: sizeof(tmp16)];
	}

	if (_UID != nil || _GID != nil) {
		if (_UID == nil || _GID == nil)
	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(_GID.unsignedShortValue);
		tmp16 = OFToLittleEndian16(
		    _groupOwnerAccountID.unsignedShortValue);
		[data addItems: &tmp16 count: sizeof(tmp16)];

		tmp16 = OFToLittleEndian16(_UID.unsignedShortValue);
		tmp16 = OFToLittleEndian16(_ownerAccountID.unsignedShortValue);
		[data addItems: &tmp16 count: sizeof(tmp16)];
	}

	if (_group != nil) {
		size_t groupLength =
		    [_group cStringLengthWithEncoding: encoding];
	if (_groupOwnerAccountName != nil) {
		size_t length = [_groupOwnerAccountName
		    cStringLengthWithEncoding: encoding];

		if (groupLength > UINT16_MAX - 3)
		if (length > UINT16_MAX - 3)
			@throw [OFOutOfRangeException exception];

		tmp16 = OFToLittleEndian16((uint16_t)groupLength + 3);
		tmp16 = OFToLittleEndian16((uint16_t)length + 3);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x52"];
		[data addItems: [_group cStringWithEncoding: encoding]
			 count: groupLength];
		[data addItems: [_groupOwnerAccountName
				    cStringWithEncoding: encoding]
			 count: length];
	}

	if (_owner != nil) {
		size_t ownerLength =
		    [_owner cStringLengthWithEncoding: encoding];
	if (_ownerAccountName != nil) {
		size_t length =
		    [_ownerAccountName cStringLengthWithEncoding: encoding];

		if (ownerLength > UINT16_MAX - 3)
		if (length > UINT16_MAX - 3)
			@throw [OFOutOfRangeException exception];

		tmp16 = OFToLittleEndian16((uint16_t)ownerLength + 3);
		tmp16 = OFToLittleEndian16((uint16_t)length + 3);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x53"];
		[data addItems: [_owner cStringWithEncoding: encoding]
		[data addItems: [_ownerAccountName
			 count: ownerLength];
	}

				    cStringWithEncoding: encoding]
	if (_modificationDate != nil) {
		tmp16 = OFToLittleEndian16(7);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x54"];

			 count: length];
		tmp32 = OFToLittleEndian32(
		    (uint32_t)_modificationDate.timeIntervalSince1970);
		[data addItems: &tmp32 count: sizeof(tmp32)];
	}

	for (OFData *extension in _extensions) {
		size_t extensionLength = extension.count;

		if (extension.itemSize != 1)
			@throw [OFInvalidArgumentException exception];
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
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 *mode = (_mode == nil ? nil
	OFString *POSIXPermissions = nil;
	    : [OFString stringWithFormat: @"%ho", _mode.unsignedShortValue]);
	OFString *extensions = [_extensions.description
	    stringByReplacingOccurrencesOfString: @"\n"
				      withString: @"\n\t"];
	OFString *ret;

	if (_POSIXPermissions != nil)
		POSIXPermissions = [OFString stringWithFormat: @"%ho",
		    _POSIXPermissions.unsignedShortValue];

	OFString *ret = [OFString stringWithFormat:
	ret = [OFString stringWithFormat:
	    @"<%@:\n"
	    @"\tFile name = %@\n"
	    @"\tCompression method = %@\n"
	    @"\tCompressed size = %" @PRIu32 "\n"
	    @"\tUncompressed size = %" @PRIu32 "\n"
	    @"\tDate = %@\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"
	    @"\tMode = %@\n"
	    @"\tUID = %@\n"
	    @"\tGID = %@\n"
	    @"\tOwner = %@\n"
	    @"\tGroup = %@\n"
	    @"\tPOSIX permissions = %@\n"
	    @"\tOwner account ID = %@\n"
	    @"\tGroup owner account ID = %@\n"
	    @"\tOwner account name = %@\n"
	    @"\tGroup owner accounut name = %@\n"
	    @"\tModification date = %@\n"
	    @"\tExtensions: %@"
	    @">",
	    self.class, self.fileName, _compressionMethod, _compressedSize,
	    _uncompressedSize, _date, _headerLevel, _CRC16,
	    _operatingSystemIdentifier, _fileComment, mode, _UID, _GID, _owner,
	    _group, _modificationDate, extensions];
	    _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 [ecd033e52b] 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
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
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 _language, *_Nullable _territory;
	OFString *_Nullable _languageCode, *_Nullable _countryCode;
	OFStringEncoding _encoding;
	OFString *_decimalPoint;
	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 *language;
@property (class, readonly, nullable, nonatomic) OFString *territory;
@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 *decimalPoint;
@property (class, readonly, nullable, nonatomic) OFString *decimalSeparator;
#endif

/**
 * @brief The language of the locale for messages.
 * @brief The language code of the locale for messages.
 *
 * If the language is unknown, it is `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *language;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *languageCode;

/**
 * @brief The territory of the locale for messages.
 * @brief The country code of the locale for messages.
 *
 * If the territory is unknown, it is `nil`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *territory;
@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 point of the system's locale.
 * @brief The decimal separator of the locale.
 */
@property (readonly, nonatomic) OFString *decimalPoint;
@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 of the locale.
 * @brief Returns the language code of the locale.
 *
 * If the language is unknown, `nil` is returned.
 *
 * @return The language of the locale.
 * @return The language code of the locale.
 */
+ (nullable OFString *)language;
+ (nullable OFString *)languageCode;

/**
 * @brief Returns the territory of the locale.
 * @brief Returns the country code of the locale.
 *
 * If the territory is unknown, `nil` is returned.
 * If the country is unknown, `nil` is returned.
 *
 * @return The territory of the locale.
 * @return The country code of the locale.
 */
+ (nullable OFString *)territory;
+ (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 *)decimalPoint;
+ (nullable OFString *)decimalSeparator;

#ifdef OF_HAVE_FILES
/**
 * @brief Adds a directory to scan for language files.
 * @brief Adds a directory to scan for localizations.
 *
 * @param path The path to the directory to scan for language files
 * @param path The path to the directory to scan for localizations
 */
+ (void)addLanguageDirectory: (OFString *)path;
+ (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 be come the current locale, and
 *	    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 language files.
 * @brief Adds a directory to scan for localizations.
 *
 * @param path The path to the directory to scan for language files
 * @param path The path to the directory to scan for localizations 
 */
- (void)addLanguageDirectory: (OFString *)path;
- (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 language files.
 *		   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
207

208
209
210
211


212
213
214
215
216
217
218
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 language files.
 *		   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
43

44
45
46
47
48
49
50
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 **language, OFString **territory)
    OFString **languageCode, OFString **countryCode)
{
	locale = OFStrDup(locale);

	@try {
		OFStringEncoding enc = OFStringEncodingASCII;
		char *tmp;

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
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) {
			}
		}

		/* Territory */
		/* Country code */
		if ((tmp = strrchr(locale, '_')) != NULL) {
			*tmp++ = '\0';

			if (territory != NULL)
				*territory = [OFString stringWithCString: tmp
								encoding: enc];
			if (countryCode != NULL)
				*countryCode = [OFString
				    stringWithCString: tmp
					     encoding: enc];
		}

		if (language != NULL)
			*language = [OFString stringWithCString: locale
						       encoding: enc];
		if (languageCode != NULL)
			*languageCode = [OFString stringWithCString: locale
							   encoding: enc];
	} @finally {
		OFFreeMemory(locale);
	}
}
#endif

static bool
299
300
301
302
303
304
305
306
307


308
309
310
311
312
313
314
300
301
302
303
304
305
306


307
308
309
310
311
312
313
314
315







-
-
+
+








	[string makeImmutable];

	return string;
}

@implementation OFLocale
@synthesize language = _language, territory = _territory, encoding = _encoding;
@synthesize decimalPoint = _decimalPoint;
@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
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
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 *)language
+ (OFString *)languageCode
{
	return currentLocale.language;
	return currentLocale.languageCode;
}

+ (OFString *)territory
+ (OFString *)countryCode
{
	return currentLocale.territory;
	return currentLocale.countryCode;
}

+ (OFStringEncoding)encoding
{
	return currentLocale.encoding;
}

+ (OFString *)decimalPoint
+ (OFString *)decimalSeparator
{
	return currentLocale.decimalPoint;
	return currentLocale.decimalSeparator;
}

#ifdef OF_HAVE_FILES
+ (void)addLanguageDirectory: (OFString *)path
+ (void)addLocalizationDirectory: (OFString *)path
{
	[currentLocale addLanguageDirectory: 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;
		_decimalPoint = @".";
		_decimalSeparator = @".";
		_localizedStrings = [[OFMutableArray alloc] init];

		if ((locale = setlocale(LC_ALL, "")) != NULL)
			_decimalPoint = [[OFString alloc]
			_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,
			    &_language, &_territory);
			    &_languageCode, &_countryCode);

			[_language retain];
			[_territory retain];
			[_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
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
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.
		 */
		_decimalPoint = [[OFString alloc]
		_decimalSeparator = [[OFString alloc]
		    initWithCString: localeconv()->decimal_point
			   encoding: _encoding];

		_localizedStrings = [[OFMutableArray alloc] init];

		if (GetVar("Language", buffer, sizeof(buffer), 0) > 0)
			_language = [[OFString alloc]
			_languageCode = [[OFString alloc]
			    initWithCString: buffer
				   encoding: _encoding];

		if ((locale = OpenLocale(NULL)) != NULL) {
			@try {
				uint32_t territory;
				uint32_t countryCode;
				size_t length;

				territory =
				countryCode =
				    OFToBigEndian32(locale->loc_CountryCode);

				for (length = 0; length < 4; length++)
					if (((char *)&territory)[length] == 0)
					if (((char *)&countryCode)[length] == 0)
						break;

				_territory = [[OFString alloc]
				    initWithCString: (char *)&territory
				_countryCode = [[OFString alloc]
				    initWithCString: (char *)&countryCode
					   encoding: _encoding
					     length: length];
			} @finally {
				CloseLocale(locale);
			}
		}

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
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
{
	[_language release];
	[_territory release];
	[_decimalPoint release];
	[_languageCode release];
	[_countryCode release];
	[_decimalSeparator release];
	[_localizedStrings release];

	[super dealloc];
}

#ifdef OF_HAVE_FILES
- (void)addLanguageDirectory: (OFString *)path
- (void)addLocalizationDirectory: (OFString *)path
{
	void *pool;
	OFString *mapPath, *language, *territory, *languageFile;
	OFString *mapPath, *languageCode, *countryCode, *localizationFile;
	OFDictionary *map;

	if (_language == nil)
	if (_languageCode == nil)
		return;

	pool = objc_autoreleasePoolPush();

	mapPath = [path stringByAppendingPathComponent: @"languages.json"];
	mapPath = [path stringByAppendingPathComponent: @"localizations.json"];
	@try {
		map = [[OFString stringWithContentsOfFile: mapPath]
		     objectByParsingJSON];
	} @catch (OFOpenItemFailedException *e) {
		objc_autoreleasePoolPop(pool);
		return;
	}

	language = _language.lowercaseString;
	territory = _territory.lowercaseString;
	languageCode = _languageCode.lowercaseString;
	countryCode = _countryCode.lowercaseString;

	if (territory == nil)
		territory = @"";
	if (countryCode == nil)
		countryCode = @"";

	languageFile = [[map objectForKey: language] objectForKey: territory];
	if (languageFile == nil)
		languageFile = [[map objectForKey: language] objectForKey: @""];
	localizationFile = [[map objectForKey: languageCode]
	    objectForKey: countryCode];
	if (localizationFile == nil)
		localizationFile = [[map objectForKey: languageCode]
		    objectForKey: @""];

	if (languageFile == nil) {
	if (localizationFile == nil) {
		objc_autoreleasePoolPop(pool);
		return;
	}

	languageFile = [path stringByAppendingPathComponent:
	    [languageFile stringByAppendingString: @".json"]];
	localizationFile = [path stringByAppendingPathComponent:
	    [localizationFile stringByAppendingString: @".json"]];

	[_localizedStrings addObject: [[OFString stringWithContentsOfFile:
	    languageFile] objectByParsingJSON]];
	    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
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
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
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>

Added src/OFMemoryStream.h version [173e3dc728].




































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 "OFSeekableStream.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFMemoryStream OFMemoryStream.h ObjFW/OFMemoryStream.h
 *
 * @brief A seekable stream for reading from and writing to memory.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFMemoryStream: OFSeekableStream
{
	char *_address;
	size_t _size, _position;
	bool _writable;
}

/**
 * @brief Creates a new OFMemoryStream with the specified memory.
 *
 * @warning The memory is not copied, so it is your responsibility that the
 *	    specified memory stays alive for as long as the OFMemoryStream does!
 *
 * @param address The memory address for the stream
 * @param size The size of the memory at the specified address
 * @param writable Whether writes to memory should be allowed
 * @return A new autoreleased OFMemoryStream
 */
+ (instancetype)streamWithMemoryAddress: (void *)address
				   size: (size_t)size
			       writable: (bool)writable;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFMemoryStream with the specified
 *	  memory.
 *
 * @warning The memory is not copied, so it is your responsibility that the
 *	    specified memory stays alive for as long as the OFMemoryStream does!
 *
 * @param address The memory address for the stream
 * @param size The size of the memory at the specified address
 * @param writable Whether writes to memory should be allowed
 * @return An initialized OFMemoryStream
 */
- (instancetype)initWithMemoryAddress: (void *)address
				 size: (size_t)size
			     writable: (bool)writable;
@end

OF_ASSUME_NONNULL_END

Added src/OFMemoryStream.m version [d9d07c7da0].




































































































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 "OFMemoryStream.h"

#import "OFInvalidArgumentException.h"
#import "OFOutOfRangeException.h"
#import "OFWriteFailedException.h"
#import "OFSeekFailedException.h"

@implementation OFMemoryStream
+ (instancetype)streamWithMemoryAddress: (void *)address
				   size: (size_t)size
			       writable: (bool)writable
{
	return [[[self alloc] initWithMemoryAddress: address
					       size: size
					   writable: writable] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (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];
		@throw e;
	}

	return self;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
{
	if (SIZE_MAX - _position < length || _position + length > _size)
		length = _size - _position;

	memcpy(buffer, _address + _position, length);
	_position += length;

	return length;
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
{
	size_t bytesWritten = length;

	if (!_writable)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
						      bytesWritten: 0
							     errNo: EBADF];

	if (SIZE_MAX - _position < length || _position + length > _size)
		bytesWritten = _size - _position;

	memcpy(_address + _position, buffer, bytesWritten);
	_position += bytesWritten;

	if (bytesWritten != length)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
						      bytesWritten: bytesWritten
							     errNo: EFBIG];

	return bytesWritten;
}

- (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
34
35
36
37
38
39
40
41
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;
	OF_RESERVE_IVARS(OFMessagePackExtension, 4)
}

/**
 * @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
177

178
179
180
181
182
183
184
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184







-
+








- (unsigned long)hash
{
	unsigned long hash;

	OFHashInit(&hash);

	OFHashAdd(&hash, (uint8_t)_type);
	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
31
32
33
34
35
36
37
38
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;
	OF_RESERVE_IVARS(OFMethodSignature, 4)
}

/**
 * @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
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
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

Modified src/OFMutableAdjacentArray.m from [0c03af836c] to [7ff7f8969c].

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
103
104
105
106
107
108
109


110
111
112
113
114
115
116







-
-







	count = _array.count;

	for (size_t i = 0; i < count; i++) {
		if ([objects[i] isEqual: oldObject]) {
			[newObject retain];
			[objects[i] release];
			objects[i] = newObject;

			return;
		}
	}
}

- (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object
{
	id *objects;
162
163
164
165
166
167
168
169

170
171
172
173
174

175


176


177
178
179
180
181
182
183
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







-
+




-
+

+
+
-
+
+







		@throw [OFInvalidArgumentException exception];

	objects = _array.items;
	count = _array.count;

	for (size_t i = 0; i < count; i++) {
		if ([objects[i] isEqual: object]) {
			object = objects[i];
			id tmp = objects[i];

			[_array removeItemAtIndex: i];
			_mutations++;

			[object release];
			[tmp release];

			objects = _array.items;
			i--;
			return;
			count--;
			continue;
		}
	}
}

- (void)removeObjectIdenticalTo: (id)object
{
	id const *objects;
192
193
194
195
196
197
198


199


200
201
202
203
204
205
206
193
194
195
196
197
198
199
200
201

202
203
204
205
206
207
208
209
210







+
+
-
+
+







	for (size_t i = 0; i < count; i++) {
		if (objects[i] == object) {
			[_array removeItemAtIndex: i];
			_mutations++;

			[object release];

			objects = _array.items;
			i--;
			return;
			count--;
			continue;
		}
	}
}

- (void)removeObjectAtIndex: (size_t)idx
{
#ifndef __clang_analyzer__

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.h from [2f55547945] to [43a8133fa8].

90
91
92
93
94
95
96
97

98
99
100
101
102
103
104
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104







-
+







 * @param array An array of objects
 * @param index The index where the objects should be inserted
 */
- (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array
		       atIndex: (size_t)index;

/**
 * @brief Replaces the first object equivalent to the specified object with the
 * @brief Replaces all objects equivalent to the specified object with the
 *	  other specified object.
 *
 * @param oldObject The object to replace
 * @param newObject The replacement object
 */
- (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject;

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
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







-
+






-
+














-
+







 * @param oldObject The object to replace
 * @param newObject The replacement object
 */
- (void)replaceObjectIdenticalTo: (ObjectType)oldObject
		      withObject: (ObjectType)newObject;

/**
 * @brief Removes the first object equivalent to the specified object.
 * @brief Removes all objects equivalent to the specified object.
 *
 * @param object The object to remove
 */
- (void)removeObject: (ObjectType)object;

/**
 * @brief Removes the first object that has the same address as the specified
 * @brief Removes all objects that have the same address as the specified
 *	  object.
 *
 * @param object The object to remove
 */
- (void)removeObjectIdenticalTo: (ObjectType)object;

/**
 * @brief Removes the object at the specified index.
 *
 * @param index The index of the object to remove
 */
- (void)removeObjectAtIndex: (size_t)index;

/**
 * @brief Removes the object in the specified range.
 * @brief Removes the objects in the specified range.
 *
 * @param range The range of the objects to remove
 */
- (void)removeObjectsInRange: (OFRange)range;

/**
 * @brief Removes the last object.

Modified src/OFMutableArray.m from [16cfb7990f] to [ba1c079bde].

291
292
293
294
295
296
297
298
299


300
301
302
303
304
305
306
307
308
309
310
291
292
293
294
295
296
297


298
299
300



301
302
303
304
305
306
307







-
-
+
+

-
-
-







	size_t count;

	if (oldObject == nil || newObject == nil)
		@throw [OFInvalidArgumentException exception];

	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([[self objectAtIndex: i] isEqual: oldObject]) {
	for (size_t i = 0; i < count; i++)
		if ([[self objectAtIndex: i] isEqual: oldObject])
			[self replaceObjectAtIndex: i withObject: newObject];
			return;
		}
	}
}

- (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject
{
	size_t count;

	if (oldObject == nil || newObject == nil)
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
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







+
-
+
+

















+
-
+
+








	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([[self objectAtIndex: i] isEqual: object]) {
			[self removeObjectAtIndex: i];

			i--;
			return;
			count--;
			continue;
		}
	}
}

- (void)removeObjectIdenticalTo: (id)object
{
	size_t count;

	if (object == nil)
		@throw [OFInvalidArgumentException exception];

	count = self.count;

	for (size_t i = 0; i < count; i++) {
		if ([self objectAtIndex: i] == object) {
			[self removeObjectAtIndex: i];

			i--;
			return;
			count--;
			continue;
		}
	}
}

- (void)removeObjectsInRange: (OFRange)range
{
	for (size_t i = 0; i < range.length; i++)
376
377
378
379
380
381
382
383

384
385
386
387
388
389
390
377
378
379
380
381
382
383

384
385
386
387
388
389
390
391







-
+







		return;

	[self removeObjectAtIndex: count - 1];
}

- (void)removeAllObjects
{
	[self removeObjectsInRange: OFRangeMake(0, self.count)];
	[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 [98bc9e545b] to [23548715da].

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
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







-
+




















-
+
+







 */

#import "OFData.h"

OF_ASSUME_NONNULL_BEGIN

@class OFString;
@class OFURL;
@class OFURI;

/**
 * @class OFMutableData OFMutableData.h ObjFW/OFMutableData.h
 *
 * @brief A class for storing and manipulating arbitrary data in an array.
 */
@interface OFMutableData: OFData
{
	size_t _capacity;
	OF_RESERVE_IVARS(OFMutableData, 4)
}

/**
 * @brief All items of the OFMutableData as a C array.
 *
 * @warning The pointer is only valid until the OFMutableData is changed!
 *
 * Modifying the returned array directly is allowed and will change the contents
 * of the data.
 */
@property (readonly, nonatomic) void *mutableItems OF_RETURNS_INNER_POINTER;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableItems
    OF_RETURNS_INNER_POINTER;

/**
 * @brief The first item of the OFMutableData or `NULL`.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *mutableFirstItem
    OF_RETURNS_INNER_POINTER;

199
200
201
202
203
204
205
206

207
208
209
210
211
200
201
202
203
204
205
206

207
208
209
210
211
212







-
+






/**
 * @brief Removes all items.
 */
- (void)removeAllItems;

/**
 * @brief Converts the mutable URL to an immutable URL.
 * @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
247

248
249
250
251
252
253
254
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: OFRangeMake(idx, 1)];
	[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
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
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
@interface OFMutableLHAArchiveEntry: OFLHAArchiveEntry <OFMutableArchiveEntry>
{
	OF_RESERVE_IVARS(OFMutableLHAArchiveEntry, 4)
}

/**
 * @brief The file name of the entry.
 */
@property (readwrite, copy, nonatomic) OFString *fileName;

/**
 * @brief The compression method of the entry.
 */
@property (readwrite, copy, nonatomic) OFString *compressionMethod;

/**
 * @brief The compressed size of the entry's file.
 */
@property (readwrite, nonatomic) uint32_t compressedSize;

/**
 * @brief The uncompressed size of the entry's file.
 */
@property (readwrite, nonatomic) uint32_t uncompressedSize;

/**
 * @brief The date of the file.
 */
@property (readwrite, retain, nonatomic) OFDate *date;

/**
 * @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 comment of the file.
 * @brief The LHA extensions of the file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic)
@property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions;
    OFString *fileComment;

/**
 * @brief The mode of the entry.
 * @brief Creates a new OFMutableLHAArchiveEntry with the specified file name.
 */
@property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *mode;

 *
/**
 * @brief The UID of the owner.
 */
@property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *UID;

 * @param fileName The file name for the OFLHAArchiveEntry
/**
 * @brief The GID of the group.
 */
@property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic) OFNumber *GID;

 * @return A new, autoreleased OFLHAArchiveEntry
/**
 * @brief The owner of the file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *owner;
+ (instancetype)entryWithFileName: (OFString *)fileName;

/**
 * @brief The group of the file.
 * @brief Initializes an already allocated OFMutableLHAArchiveEntry with the
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *group;

 *	  specified file name.
/**
 * @brief The date of the last modification of the file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, retain, nonatomic)
    OFDate *modificationDate;

 *
/**
 * @brief The LHA extensions of the file.
 * @param fileName The file name for the OFLHAArchiveEntry
 * @return An initialized OFLHAArchiveEntry
 */
@property (readwrite, copy, nonatomic) OFArray OF_GENERIC(OFData *) *extensions;
- (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
27
28
29























30
31
32
33
34
35
36
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, date;
@dynamic headerLevel, CRC16, operatingSystemIdentifier, fileComment, mode, UID;
@dynamic GID, owner, group, modificationDate, extensions;
@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
57

58
59
60
61
62

63
64
65
66
67

68
69
70


71
72
73
74
75
76
77
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: (uint32_t)compressedSize
- (void)setCompressedSize: (unsigned long long)compressedSize
{
	_compressedSize = compressedSize;
}

- (void)setUncompressedSize: (uint32_t)uncompressedSize
- (void)setUncompressedSize: (unsigned long long)uncompressedSize
{
	_uncompressedSize = uncompressedSize;
}

- (void)setDate: (OFDate *)date
- (void)setModificationDate: (OFDate *)modificationDate
{
	OFDate *old = _date;
	_date = [date retain];
	OFDate *old = _modificationDate;
	_modificationDate = [modificationDate retain];
	[old release];
}

- (void)setHeaderLevel: (uint8_t)headerLevel
{
	_headerLevel = headerLevel;
}
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
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)setMode: (OFNumber *)mode
- (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions
{
	OFNumber *old = _mode;
	_mode = [mode retain];
	OFNumber *old = _POSIXPermissions;
	_POSIXPermissions = [POSIXPermissions retain];
	[old release];
}

- (void)setUID: (OFNumber *)UID
- (void)setOwnerAccountID: (OFNumber *)ownerAccountID
{
	OFNumber *old = _UID;
	_UID = [UID retain];
	OFNumber *old = _ownerAccountID;
	_ownerAccountID = [ownerAccountID retain];
	[old release];
}

- (void)setGID: (OFNumber *)GID
{
	OFNumber *old = _GID;
	_GID = [GID retain];
	[old release];
}


- (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID
- (void)setOwner: (OFString *)owner
{
	OFString *old = _owner;
	_owner = [owner copy];
	OFNumber *old = _groupOwnerAccountID;
	_groupOwnerAccountID = [groupOwnerAccountID retain];
	[old release];
}

- (void)setGroup: (OFString *)group
- (void)setOwnerAccountName: (OFString *)ownerAccountName
{
	OFString *old = _group;
	_group = [group copy];
	OFString *old = _ownerAccountName;
	_ownerAccountName = [ownerAccountName copy];
	[old release];
}

- (void)setModificationDate: (OFDate *)modificationDate
- (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName
{
	OFDate *old = _modificationDate;
	_modificationDate = [modificationDate retain];
	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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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 Prepends another OFString to the OFMutableString.
 *
 * @param string An OFString to prepend
 */
- (void)prependString: (OFString *)string;

/**
 * @brief Reverses the string.
 */
- (void)reverse;

/**
 * @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
177

178
179

180
181
182

183
184
185
186

187
188
189
190
191
192
193
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)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
	return (id)[[OFMutableUTF8String alloc] initWithContentsOfURL: URL];
	return (id)[[OFMutableUTF8String alloc] initWithContentsOfURI: URI];
}

- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
			     encoding: (OFStringEncoding)encoding
{
	return (id)[[OFMutableUTF8String alloc]
	    initWithContentsOfURL: URL
	    initWithContentsOfURI: URI
			 encoding: encoding];
}

- (instancetype)initWithSerialization: (OFXMLElement *)element
{
	return (id)[[OFMutableUTF8String alloc] initWithSerialization: element];
}
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
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: OFRangeMake(idx, 1) withString: string];
	[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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
368
369
370
371
372
373
374
















375
376
377
378
379
380
381







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	@try {
		[self appendUTF8String: UTF8String length: UTF8StringLength];
	} @finally {
		free(UTF8String);
	}
}

- (void)prependString: (OFString *)string
{
	[self insertString: string atIndex: 0];
}

- (void)reverse
{
	size_t i, j, length = self.length;

	for (i = 0, j = length - 1; i < length / 2; i++, j--) {
		OFUnichar tmp = [self characterAtIndex: j];
		[self setCharacter: [self characterAtIndex: i] atIndex: j];
		[self setCharacter: tmp atIndex: i];
	}
}

#ifdef OF_HAVE_UNICODE_TABLES
- (void)uppercase
{
	[self of_convertWithWordStartTable: OFUnicodeUppercaseTable
			   wordMiddleTable: OFUnicodeUppercaseTable
			wordStartTableSize: OFUnicodeUppercaseTableSize
		       wordMiddleTableSize: OFUnicodeUppercaseTableSize];
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
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: OFRangeMake(idx, 0) withString: string];
	[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: OFRangeMake(0, self.length)];
				   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
488

489
490
491
492
493
494
495
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: OFRangeMake(i, searchLength)
		[self replaceCharactersInRange: OFMakeRange(i, searchLength)
				    withString: replacement];

		range.length -= searchLength;
		range.length += replacementLength;

		i += replacementLength - 1;

513
514
515
516
517
518
519
520

521
522
523
524
525
526
527
497
498
499
500
501
502
503

504
505
506
507
508
509
510
511







-
+








		if (!OFASCIIIsSpace(c))
			break;
	}

	objc_autoreleasePoolPop(pool);

	[self deleteCharactersInRange: OFRangeMake(0, i)];
	[self deleteCharactersInRange: OFMakeRange(0, i)];
}

- (void)deleteTrailingWhitespaces
{
	void *pool;
	const OFUnichar *characters, *p;
	size_t length, d;
540
541
542
543
544
545
546
547

548
549
550
551
552
553
554
524
525
526
527
528
529
530

531
532
533
534
535
536
537
538







-
+







			break;

		d++;
	}

	objc_autoreleasePoolPop(pool);

	[self deleteCharactersInRange: OFRangeMake(length - d, d)];
	[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
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
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
@interface OFMutableTarArchiveEntry: OFTarArchiveEntry <OFMutableArchiveEntry>
{
	OF_RESERVE_IVARS(OFMutableTarArchiveEntry, 4)
}

/**
 * @brief The file name of the entry.
 */
@property (readwrite, copy, nonatomic) OFString *fileName;

/**
 * @brief The mode of the entry.
 */
@property (readwrite, nonatomic) unsigned long mode;

/**
 * @brief The UID of the owner.
 */
@property (readwrite, nonatomic) unsigned long UID;

/**
 * @brief The GID of the group.
 */
@property (readwrite, nonatomic) unsigned long GID;

/**
 * @brief The size of the file.
 */
@property (readwrite, nonatomic) unsigned long long size;

/**
 * @brief The date of the last modification of the file.
 */
@property (readwrite, retain, nonatomic) OFDate *modificationDate;

/**
 * @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 owner of the file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *owner;

/**
 * @brief The group of the file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *group;

/**
 * @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

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
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 "OFString.h"
#import "OFDate.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;
@dynamic fileName, mode, UID, GID, size, modificationDate, type, targetFileName;
@dynamic owner, group, deviceMajor, 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)setMode: (unsigned long)mode
- (void)setPOSIXPermissions: (OFNumber *)POSIXPermissions
{
	_mode = mode;
	OFNumber *old = _POSIXPermissions;
	_POSIXPermissions = [POSIXPermissions retain];
	[old release];
}

- (void)setUID: (unsigned long)UID
- (void)setOwnerAccountID: (OFNumber *)ownerAccountID
{
	OFNumber *old = _ownerAccountID;
	_ownerAccountID = [ownerAccountID retain];
	[old release];
}
	_UID = UID;

- (void)setGroupOwnerAccountID: (OFNumber *)groupOwnerAccountID
{
	OFNumber *old = _groupOwnerAccountID;
	_groupOwnerAccountID = [groupOwnerAccountID retain];
	[old release];
}

- (void)setGID: (unsigned long)GID
- (void)setCompressedSize: (unsigned long long)compressedSize
{
	_GID = GID;
	_compressedSize = compressedSize;
}

- (void)setSize: (unsigned long long)size
- (void)setUncompressedSize: (unsigned long long)uncompressedSize
{
	_size = size;
	_uncompressedSize = uncompressedSize;
}

- (void)setModificationDate: (OFDate *)modificationDate
{
	OFDate *old = _modificationDate;
	_modificationDate = [modificationDate retain];
	[old release];
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
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)setOwner: (OFString *)owner
- (void)setOwnerAccountName: (OFString *)ownerAccountName
{
	OFString *old = _owner;
	_owner = [owner copy];
	OFString *old = _ownerAccountName;
	_ownerAccountName = [ownerAccountName copy];
	[old release];
}

- (void)setGroup: (OFString *)group
- (void)setGroupOwnerAccountName: (OFString *)groupOwnerAccountName
{
	OFString *old = _group;
	_group = [group copy];
	OFString *old = _groupOwnerAccountName;
	_groupOwnerAccountName = [groupOwnerAccountName copy];
	[old release];
}

- (void)setDeviceMajor: (unsigned long)deviceMajor
{
	_deviceMajor = deviceMajor;
}

Renamed and modified src/OFMutableURL.h [cf84e1efee] to src/OFMutableURI.h [9400cfdc05].

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
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
201
202
203
204
205
206
207
208
209

210
211
212
213
214

215
216
217
218
219
220







-
+




-
+

-
+
+

-
+

-
+



-
+
-
-
-
+
-
-
-
+
+
-
-

-
+
-


-
+




-
+
+
+
+

-
-
+
+


-
+


-
+
+
+
+




-
+




-
+

-
-
+
+
+
+
+


-
+


-
+




-
+

-
-
+
+
+
+
+


-
+


-
+

-
+


-
+

-
-
+
+
+
+
+

-
+
-


-
+


+
+
+

-
+



-
+




-
+

-
-
+
+
+
+
+


-
+


-
+


-
+

-
-
-
-
+
+
+
+
+
+


-
+


-
+




-
+

-
-
+
+
+
+
+


-
+


-
+

+
-
+

-
+
+
+
+
+
+
+
+
+
+



















-
+




-
+





 *
 * 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 "OFURL.h"
#import "OFURI.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFMutableURL OFMutableURL.h ObjFW/OFMutableURL.h
 * @class OFMutableURI OFMutableURI.h ObjFW/OFMutableURI.h
 *
 * @brief A class for parsing URLs and accessing parts of it.
 * @brief A class for parsing URIs as per RFC 3986 and accessing and modifying
 *	  parts of it.
 */
@interface OFMutableURL: OFURL
@interface OFMutableURI: OFURI
{
	OF_RESERVE_IVARS(OFMutableURL, 4)
	OF_RESERVE_IVARS(OFMutableURI, 4)
}

/**
 * @brief The scheme part of the URL.
 * @brief The scheme part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *scheme;

 *
/**
 * @brief The scheme part of the URL in URL-encoded form.
 *
 * @throw OFInvalidFormatException The scheme being set is not in the correct
 *				   format
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic)
@property (readwrite, copy, nonatomic) OFString *scheme;
    OFString *URLEncodedScheme;

/**
 * @brief The host part of the URL.
 * @brief The host part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *host;

/**
 * @brief The host part of the URL in URL-encoded form.
 * @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.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-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 *URLEncodedHost;
    OFString *percentEncodedHost;

/**
 * @brief The port part of the URL.
 * @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 URL.
 * @brief The user part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *user;

/**
 * @brief The user part of the URL in URL-encoded form.
 * @brief The user part of the URI in percent-encoded form.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 * 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 *URLEncodedUser;
    OFString *percentEncodedUser;

/**
 * @brief The password part of the URL.
 * @brief The password part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *password;

/**
 * @brief The password part of the URL in URL-encoded form.
 * @brief The password part of the URI in URI-encoded form.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 * 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 *URLEncodedPassword;
    OFString *percentEncodedPassword;

/**
 * @brief The path part of the URL.
 * @brief The path part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *path;
@property (readwrite, copy, nonatomic) OFString *path;

/**
 * @brief The path part of the URL in URL-encoded form.
 * @brief The path part of the URI in percent-encoded form.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 * 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 OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic)
@property (readwrite, copy, nonatomic) OFString *percentEncodedPath;
    OFString *URLEncodedPath;

/**
 * @brief The path of the URL split into components.
 * @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 OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic)
@property (readwrite, copy, nonatomic)
    OFArray OF_GENERIC(OFString *) *pathComponents;

/**
 * @brief The query part of the URL.
 * @brief The query part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *query;

/**
 * @brief The query part of the URL in URL-encoded form.
 * @brief The query part of the URI in percent-encoded form.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 * 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 *URLEncodedQuery;
    OFString *percentEncodedQuery;

/**
 * @brief The query part of the URL as a dictionary.
 * @brief The query part of the URI as an array.
 *
 * For example, a query like `key1=value1&key2=value2` would correspond to the
 * following dictionary:
 * following array:
 *
 *     @{
 *         @"key1": "value1",
 *         @"key2": "value2"
 *     }
 *     @[
 *         [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)
    OFDictionary OF_GENERIC(OFString *, OFString *) *queryDictionary;
    OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems;

/**
 * @brief The fragment part of the URL.
 * @brief The fragment part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *fragment;

/**
 * @brief The fragment part of the URL in URL-encoded form.
 * @brief The fragment part of the URI in percent-encoded form.
 *
 * Setting this retains the original URL-encoding used - if more characters
 * than necessary are URL-encoded, it is kept this way.
 * 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 *URLEncodedFragment;
    OFString *percentEncodedFragment;

/**
 * @brief Creates a new mutable URL.
 * @brief Creates a new mutable URI with the specified schemed.
 *
 * @param scheme The scheme for the URI
 * @return A new, autoreleased OFMutableURL
 * @return A new, autoreleased OFMutableURI
 */
+ (instancetype)URL;
+ (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;

/**
 * @brief Appends the specified path component.
 *
 * @param component The component to append
 * @param isDirectory Whether the path is a directory, in which case a slash is
 *		      appened if there is no slash yet
 */
- (void)appendPathComponent: (OFString *)component
		isDirectory: (bool)isDirectory;

/**
 * @brief Resolves relative sub paths.
 * @brief Resolves relative subpaths.
 */
- (void)standardizePath;

/**
 * @brief Converts the mutable URL to an immutable URL.
 * @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
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
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 "OFMutableURL.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 OFMutableURL
@dynamic scheme, URLEncodedScheme, host, URLEncodedHost, port, user;
@dynamic URLEncodedUser, password, URLEncodedPassword, path, URLEncodedPath;
@dynamic pathComponents, query, URLEncodedQuery, queryDictionary, fragment;
@dynamic URLEncodedFragment;
@implementation OFMutableURI
@dynamic scheme, host, percentEncodedHost, port, user, percentEncodedUser;
@dynamic password, percentEncodedPassword, path, percentEncodedPath;
@dynamic pathComponents, query, percentEncodedQuery, queryItems, fragment;
@dynamic percentEncodedFragment;

+ (instancetype)URL
+ (instancetype)URIWithScheme: (OFString *)scheme
{
	return [[[self alloc] init] autorelease];
	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 = _URLEncodedScheme;
	OFString *old = _scheme;

	if (scheme.length < 1 || !OFASCIIIsAlpha(*scheme.UTF8String))
		@throw [OFInvalidFormatException exception];
	_URLEncodedScheme = [[scheme stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLSchemeAllowedCharacterSet]] copy];

	OFURIVerifyIsEscaped(scheme,
	    [OFCharacterSet URISchemeAllowedCharacterSet], false);

	_scheme = [scheme.lowercaseString copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedScheme: (OFString *)URLEncodedScheme
{
	OFString *old;

	if (URLEncodedScheme != nil)
		OFURLVerifyIsEscaped(URLEncodedScheme,
		    [OFCharacterSet URLSchemeAllowedCharacterSet]);

	old = _URLEncodedScheme;
	_URLEncodedScheme = [URLEncodedScheme copy];
	[old release];
}

- (void)setHost: (OFString *)host
{
	void *pool = objc_autoreleasePoolPush();
	OFString *old = _URLEncodedHost;
	OFString *old = _percentEncodedHost;

	if (OFURLIsIPv6Host(host))
		_URLEncodedHost = [[OFString alloc]
	if (OFURIIsIPv6Host(host))
		_percentEncodedHost = [[OFString alloc]
		    initWithFormat: @"[%@]", host];
	else
		_URLEncodedHost = [[host
		    stringByURLEncodingWithAllowedCharacters:
		    [OFCharacterSet URLHostAllowedCharacterSet]] copy];
		_percentEncodedHost = [[host
		    stringByAddingPercentEncodingWithAllowedCharacters:
		    [OFCharacterSet URIHostAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedHost: (OFString *)URLEncodedHost
- (void)setPercentEncodedHost: (OFString *)percentEncodedHost
{
	OFString *old;

	if ([URLEncodedHost hasPrefix: @"["] &&
	    [URLEncodedHost hasSuffix: @"]"]) {
		if (!OFURLIsIPv6Host([URLEncodedHost substringWithRange:
		    OFRangeMake(1, URLEncodedHost.length - 2)]))
	if ([percentEncodedHost hasPrefix: @"["] &&
	    [percentEncodedHost hasSuffix: @"]"]) {
		if (!OFURIIsIPv6Host([percentEncodedHost substringWithRange:
		    OFMakeRange(1, percentEncodedHost.length - 2)]))
			@throw [OFInvalidFormatException exception];
	} else if (URLEncodedHost != nil)
		OFURLVerifyIsEscaped(URLEncodedHost,
		    [OFCharacterSet URLHostAllowedCharacterSet]);
	} else if (percentEncodedHost != nil)
		OFURIVerifyIsEscaped(percentEncodedHost,
		    [OFCharacterSet URIHostAllowedCharacterSet], true);

	old = _URLEncodedHost;
	_URLEncodedHost = [URLEncodedHost copy];
	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 = _URLEncodedUser;
	OFString *old = _percentEncodedUser;

	_percentEncodedUser = [[user
	_URLEncodedUser = [[user stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLUserAllowedCharacterSet]] copy];
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIUserAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedUser: (OFString *)URLEncodedUser
- (void)setPercentEncodedUser: (OFString *)percentEncodedUser
{
	OFString *old;

	if (URLEncodedUser != nil)
		OFURLVerifyIsEscaped(URLEncodedUser,
		    [OFCharacterSet URLUserAllowedCharacterSet]);
	if (percentEncodedUser != nil)
		OFURIVerifyIsEscaped(percentEncodedUser,
		    [OFCharacterSet URIUserAllowedCharacterSet], true);

	old = _URLEncodedUser;
	_URLEncodedUser = [URLEncodedUser copy];
	old = _percentEncodedUser;
	_percentEncodedUser = [percentEncodedUser copy];
	[old release];
}

- (void)setPassword: (OFString *)password
{
	void *pool = objc_autoreleasePoolPush();
	OFString *old = _URLEncodedPassword;
	OFString *old = _percentEncodedPassword;

	_URLEncodedPassword = [[password
	    stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLPasswordAllowedCharacterSet]] copy];
	_percentEncodedPassword = [[password
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIPasswordAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedPassword: (OFString *)URLEncodedPassword
- (void)setPercentEncodedPassword: (OFString *)percentEncodedPassword
{
	OFString *old;

	if (URLEncodedPassword != nil)
		OFURLVerifyIsEscaped(URLEncodedPassword,
		    [OFCharacterSet URLPasswordAllowedCharacterSet]);
	if (percentEncodedPassword != nil)
		OFURIVerifyIsEscaped(percentEncodedPassword,
		    [OFCharacterSet URIPasswordAllowedCharacterSet], true);

	old = _URLEncodedPassword;
	_URLEncodedPassword = [URLEncodedPassword copy];
	old = _percentEncodedPassword;
	_percentEncodedPassword = [percentEncodedPassword copy];
	[old release];
}

- (void)setPath: (OFString *)path
{
	void *pool = objc_autoreleasePoolPush();
	OFString *old = _URLEncodedPath;
	OFString *old = _percentEncodedPath;

	_percentEncodedPath = [[path
	_URLEncodedPath = [[path stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLPathAllowedCharacterSet]] copy];
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIPathAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedPath: (OFString *)URLEncodedPath
- (void)setPercentEncodedPath: (OFString *)percentEncodedPath
{
	OFString *old;

	if (URLEncodedPath != nil)
		OFURLVerifyIsEscaped(URLEncodedPath,
		    [OFCharacterSet URLPathAllowedCharacterSet]);
	OFURIVerifyIsEscaped(percentEncodedPath,
	    [OFCharacterSet URIPathAllowedCharacterSet], true);

	old = _URLEncodedPath;
	_URLEncodedPath = [URLEncodedPath copy];
	old = _percentEncodedPath;
	_percentEncodedPath = [percentEncodedPath copy];
	[old release];
}

- (void)setPathComponents: (OFArray *)components
{
	void *pool = objc_autoreleasePoolPush();

	if (components == nil) {
		self.path = nil;
		return;
	}

	if (components.count == 0)
		@throw [OFInvalidFormatException exception];

	if ([components.firstObject length] != 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 = _URLEncodedQuery;
	OFString *old = _percentEncodedQuery;

	_percentEncodedQuery = [[query
	_URLEncodedQuery = [[query stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLQueryAllowedCharacterSet]] copy];
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIQueryAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedQuery: (OFString *)URLEncodedQuery
- (void)setPercentEncodedQuery: (OFString *)percentEncodedQuery
{
	OFString *old;

	if (URLEncodedQuery != nil)
		OFURLVerifyIsEscaped(URLEncodedQuery,
		    [OFCharacterSet URLQueryAllowedCharacterSet]);
	if (percentEncodedQuery != nil)
		OFURIVerifyIsEscaped(percentEncodedQuery,
		    [OFCharacterSet URIQueryAllowedCharacterSet], true);

	old = _URLEncodedQuery;
	_URLEncodedQuery = [URLEncodedQuery copy];
	old = _percentEncodedQuery;
	_percentEncodedQuery = [percentEncodedQuery copy];
	[old release];
}

- (void)setQueryDictionary:
    (OFDictionary OF_GENERIC(OFString *, OFString *) *)dictionary
- (void)setQueryItems:
    (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *)
    queryItems
{
	void *pool;
	OFMutableString *URLEncodedQuery;
	OFMutableString *percentEncodedQuery;
	OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator;
	OFCharacterSet *characterSet;
	OFString *key, *object, *old;
	OFString *old;

	if (dictionary == nil) {
		[_URLEncodedQuery release];
		_URLEncodedQuery = nil;
	if (queryItems == nil) {
		[_percentEncodedQuery release];
		_percentEncodedQuery = nil;
		return;
	}

	pool = objc_autoreleasePoolPush();
	URLEncodedQuery = [OFMutableString string];
	percentEncodedQuery = [OFMutableString string];
	keyEnumerator = [dictionary keyEnumerator];
	objectEnumerator = [dictionary objectEnumerator];
	characterSet = [OFCharacterSet URLQueryKeyValueAllowedCharacterSet];
	characterSet = [OFCharacterSet URIQueryKeyValueAllowedCharacterSet];

	while ((key = [keyEnumerator nextObject]) != nil &&
	    (object = [objectEnumerator nextObject]) != nil) {
		key = [key
		    stringByURLEncodingWithAllowedCharacters: characterSet];
		object = [object
		    stringByURLEncodingWithAllowedCharacters: characterSet];
	for (OFPair OF_GENERIC(OFString *, OFString *) *item in queryItems) {
		OFString *key = [item.firstObject
		    stringByAddingPercentEncodingWithAllowedCharacters:
		    characterSet];
		OFString *value = [item.secondObject
		    stringByAddingPercentEncodingWithAllowedCharacters:
		    characterSet];

		if (URLEncodedQuery.length > 0)
			[URLEncodedQuery appendString: @"&"];
		if (percentEncodedQuery.length > 0)
			[percentEncodedQuery appendString: @"&"];

		[URLEncodedQuery appendFormat: @"%@=%@", key, object];
		[percentEncodedQuery appendFormat: @"%@=%@", key, value];
	}

	old = _URLEncodedQuery;
	_URLEncodedQuery = [URLEncodedQuery copy];
	old = _percentEncodedQuery;
	_percentEncodedQuery = [percentEncodedQuery copy];
	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setFragment: (OFString *)fragment
{
	void *pool = objc_autoreleasePoolPush();
	OFString *old = _URLEncodedFragment;
	OFString *old = _percentEncodedFragment;

	_URLEncodedFragment = [[fragment
	    stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLFragmentAllowedCharacterSet]] copy];
	_percentEncodedFragment = [[fragment
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIFragmentAllowedCharacterSet]] copy];

	[old release];

	objc_autoreleasePoolPop(pool);
}

- (void)setURLEncodedFragment: (OFString *)URLEncodedFragment
- (void)setPercentEncodedFragment: (OFString *)percentEncodedFragment
{
	OFString *old;

	if (URLEncodedFragment != nil)
		OFURLVerifyIsEscaped(URLEncodedFragment,
		    [OFCharacterSet URLFragmentAllowedCharacterSet]);
	if (percentEncodedFragment != nil)
		OFURIVerifyIsEscaped(percentEncodedFragment,
		    [OFCharacterSet URIFragmentAllowedCharacterSet], true);

	old = _URLEncodedFragment;
	_URLEncodedFragment = [URLEncodedFragment copy];
	old = _percentEncodedFragment;
	_percentEncodedFragment = [percentEncodedFragment copy];
	[old release];
}

- (id)copy
{
	OFMutableURL *copy = [self mutableCopy];
	OFMutableURI *copy = [self mutableCopy];

	[copy makeImmutable];

	return copy;
}

- (void)appendPathComponent: (OFString *)component
{
	[self appendPathComponent: component isDirectory: false];

#ifdef OF_HAVE_FILES
	if ([_URLEncodedScheme isEqual: @"file"] &&
	    ![_URLEncodedPath hasSuffix: @"/"] &&
	    [[OFFileManager defaultManager] directoryExistsAtURL: self]) {
	if ([_scheme isEqual: @"file"] &&
	    ![_percentEncodedPath hasSuffix: @"/"] &&
	    [[OFFileManager defaultManager] directoryExistsAtURI: self]) {
		void *pool = objc_autoreleasePoolPush();
		OFString *path = [_URLEncodedPath
		OFString *path = [_percentEncodedPath
		    stringByAppendingString: @"/"];

		[_URLEncodedPath release];
		_URLEncodedPath = [path retain];
		[_percentEncodedPath release];
		_percentEncodedPath = [path retain];

		objc_autoreleasePoolPop(pool);
	}
#endif
}

- (void)appendPathComponent: (OFString *)component
		isDirectory: (bool)isDirectory
{
	void *pool;
	OFString *path;

	if ([component isEqual: @"/"] && [_URLEncodedPath hasSuffix: @"/"])
	if ([component isEqual: @"/"] && [_percentEncodedPath hasSuffix: @"/"])
		return;

	pool = objc_autoreleasePoolPush();
	component = [component stringByURLEncodingWithAllowedCharacters:
	    [OFCharacterSet URLPathAllowedCharacterSet]];
	component = [component
	    stringByAddingPercentEncodingWithAllowedCharacters:
	    [OFCharacterSet URIPathAllowedCharacterSet]];

#if defined(OF_WINDOWS) || defined(OF_MSDOS)
	if ([_URLEncodedPath hasSuffix: @"/"] ||
	    ([_URLEncodedScheme isEqual: @"file"] &&
	    [_URLEncodedPath hasSuffix: @":"]))
	if ([_percentEncodedPath hasSuffix: @"/"] ||
	    ([_scheme isEqual: @"file"] &&
	    [_percentEncodedPath hasSuffix: @":"]))
#else
	if ([_URLEncodedPath hasSuffix: @"/"])
	if ([_percentEncodedPath hasSuffix: @"/"])
#endif
		path = [_URLEncodedPath stringByAppendingString: component];
		path = [_percentEncodedPath stringByAppendingString: component];
	else
		path = [_URLEncodedPath
		path = [_percentEncodedPath
		    stringByAppendingFormat: @"/%@", component];

	if (isDirectory && ![path hasSuffix: @"/"])
		path = [path stringByAppendingString: @"/"];

	[_URLEncodedPath release];
	_URLEncodedPath = [path retain];
	[_percentEncodedPath release];
	_percentEncodedPath = [path retain];

	objc_autoreleasePoolPop(pool);
}

- (void)standardizePath
{
	void *pool;
	void *pool = objc_autoreleasePoolPush();
	OFMutableArray OF_GENERIC(OFString *) *array;
	bool done = false, endsWithEmpty;
	bool done = false, startsWithEmpty, endsWithEmpty;
	OFString *path;

	if (_URLEncodedPath == nil)
		return;

	pool = objc_autoreleasePoolPush();

	array = [[[_URLEncodedPath
	array = [[[_percentEncodedPath
	    componentsSeparatedByString: @"/"] mutableCopy] autorelease];

	if ([array.firstObject length] != 0)
		@throw [OFInvalidFormatException exception];

	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
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
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:
				    OFRangeMake(i - 1, 2)];
				    OFMakeRange(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

	if (startsWithEmpty)
	[array insertObject: @"" atIndex: 0];
		[array insertObject: @"" atIndex: 0];
	if (endsWithEmpty)
		[array addObject: @""];

	path = [array componentsJoinedByString: @"/"];
	if (path.length == 0)
	if (startsWithEmpty && path.length == 0)
		path = @"/";

	[self setURLEncodedPath: path];
	self.percentEncodedPath = path;

	objc_autoreleasePoolPop(pool);
}

- (void)makeImmutable
{
	object_setClass(self, [OFURL class]);
	object_setClass(self, [OFURI class]);
}
@end

Modified src/OFMutableUTF8String.m from [e069c57766] to [57e4df0b5d].

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
421
422
423
424
425
426
427
















































































428
429
430
431
432
433
434







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	@try {
		[self appendUTF8String: UTF8String length: UTF8StringLength];
	} @finally {
		free(UTF8String);
	}
}

- (void)reverse
{
	size_t i, j;

	_s->hasHash = false;

	/* We reverse all bytes and restore UTF-8 later, if necessary */
	for (i = 0, j = _s->cStringLength - 1; i < _s->cStringLength / 2;
	    i++, j--) {
		_s->cString[i] ^= _s->cString[j];
		_s->cString[j] ^= _s->cString[i];
		_s->cString[i] ^= _s->cString[j];
	}

	if (!_s->isUTF8)
		return;

	for (i = 0; i < _s->cStringLength; i++) {
		/* ASCII */
		if OF_LIKELY (!(_s->cString[i] & 0x80))
			continue;

		/* A start byte can't happen first as we reversed everything */
		if OF_UNLIKELY (_s->cString[i] & 0x40)
			@throw [OFInvalidEncodingException exception];

		/* Next byte must not be ASCII */
		if OF_UNLIKELY (_s->cStringLength < i + 1 ||
		    !(_s->cString[i + 1] & 0x80))
			@throw [OFInvalidEncodingException exception];

		/* Next byte is the start byte */
		if OF_LIKELY (_s->cString[i + 1] & 0x40) {
			_s->cString[i] ^= _s->cString[i + 1];
			_s->cString[i + 1] ^= _s->cString[i];
			_s->cString[i] ^= _s->cString[i + 1];

			i++;
			continue;
		}

		/* Second next byte must not be ASCII */
		if OF_UNLIKELY (_s->cStringLength < i + 2 ||
		    !(_s->cString[i + 2] & 0x80))
			@throw [OFInvalidEncodingException exception];

		/* Second next byte is the start byte */
		if OF_LIKELY (_s->cString[i + 2] & 0x40) {
			_s->cString[i] ^= _s->cString[i + 2];
			_s->cString[i + 2] ^= _s->cString[i];
			_s->cString[i] ^= _s->cString[i + 2];

			i += 2;
			continue;
		}

		/* Third next byte must not be ASCII */
		if OF_UNLIKELY (_s->cStringLength < i + 3 ||
		    !(_s->cString[i + 3] & 0x80))
			@throw [OFInvalidEncodingException exception];

		/* Third next byte is the start byte */
		if OF_LIKELY (_s->cString[i + 3] & 0x40) {
			_s->cString[i] ^= _s->cString[i + 3];
			_s->cString[i + 3] ^= _s->cString[i];
			_s->cString[i] ^= _s->cString[i + 3];

			_s->cString[i + 1] ^= _s->cString[i + 2];
			_s->cString[i + 2] ^= _s->cString[i + 1];
			_s->cString[i + 1] ^= _s->cString[i + 2];

			i += 3;
			continue;
		}

		/* UTF-8 does not allow more than 4 bytes per character */
		@throw [OFInvalidEncodingException exception];
	}
}

- (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
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
@interface OFMutableZIPArchiveEntry: OFZIPArchiveEntry <OFMutableArchiveEntry>
{
	OF_RESERVE_IVARS(OFMutableZIPArchiveEntry, 4)
}

/**
 * @brief The file name of the entry.
 */
@property (readwrite, copy, nonatomic) OFString *fileName;

/**
 * @brief The comment of the entry's file.
 */
@property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic)
    OFString *fileComment;

/**
 * @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
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
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 last modification date of the entry's file.
 *
 * @note Due to limitations of the ZIP format, this has only 2 second precision.
 */
@property (readwrite, retain, nonatomic) OFDate *modificationDate;

/**
 * @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 compressed size of the entry's file.
 */
@property (readwrite, nonatomic) uint64_t compressedSize;

/**
 * @brief The uncompressed size of the entry's file.
 */
@property (readwrite, nonatomic) uint64_t uncompressedSize;

/**
 * @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
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
119

120
121
122
123
124

125
126
127
128
129
130
131
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: (uint64_t)compressedSize
- (void)setCompressedSize: (unsigned long long)compressedSize
{
	_compressedSize = compressedSize;
}

- (void)setUncompressedSize: (uint64_t)uncompressedSize
- (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
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 [e3ac678499] to [c3409634e1].

29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
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.
 */
OF_SUBCLASSING_RESTRICTED
@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;

104
105
106
107
108
109
110


111
112
113
104
105
106
107
108
109
110
111
112
113
114
115







+
+



 * @param userInfo Additional information for the notification
 * @return An initialized OFNotification
 */
- (instancetype)initWithName: (OFNotificationName)name
		      object: (nullable id)object
		    userInfo: (nullable OFDictionary *)userInfo
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/OFNotification.m from [c262c407bd] to [d51e2a4110].

55
56
57
58
59
60
61





62
63
64
65
66
67
68
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73







+
+
+
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_name release];
	[_object release];
	[_userInfo release];

Modified src/OFNotificationCenter.h from [6d89a35135] to [2edf55e2db].

35
36
37
38
39
40
41



42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
	OF_RESERVE_IVARS(OFNotificationCenter, 4)
}

#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
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.h from [312b6f2b4b] to [eff21822aa].

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
120
121
122
123
124
125
126

127
128
129
130
131
132
133
134

135
136
137
138
139
140
141







-








-







@property (readonly, nonatomic) double doubleValue;

/**
 * @brief The OFNumber as a string.
 */
@property (readonly, nonatomic) OFString *stringValue;

#ifdef OF_HAVE_UNAVAILABLE
+ (instancetype)valueWithBytes: (const void *)bytes
		      objCType: (const char *)objCType OF_UNAVAILABLE;
+ (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE;
+ (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE;
+ (instancetype)valueWithRange: (OFRange)range OF_UNAVAILABLE;
+ (instancetype)valueWithPoint: (OFPoint)point OF_UNAVAILABLE;
+ (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE;
+ (instancetype)valueWithRect: (OFRect)rect OF_UNAVAILABLE;
#endif

/**
 * @brief Creates a new OFNumber with the specified `bool`.
 *
 * @param value The `bool` value which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
234
235
236
237
238
239
240

241
242

243
244
245
246
247
248
249







-


-







 *
 * @param value The `double` value which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithDouble: (double)value;

- (instancetype)init OF_UNAVAILABLE;
#ifdef OF_HAVE_UNAVAILABLE
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType OF_UNAVAILABLE;
#endif

/**
 * @brief Initializes an already allocated OFNumber with the specified `bool`.
 *
 * @param value The `bool` value which the OFNumber should contain
 * @return An initialized OFNumber
 */

Modified src/OFNumber.m from [bc852126ea] to [0d84e74204].

507
508
509
510
511
512
513




































514
515
516
517
518
519
520
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+ (instancetype)alloc
{
	if (self == [OFNumber class])
		return (id)&placeholder;

	return [super alloc];
}

+ (instancetype)valueWithBytes: (const void *)bytes
		      objCType: (const char *)objCType
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithPointer: (const void *)pointer
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithNonretainedObject: (id)object
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithRange: (OFRange)range
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithPoint: (OFPoint)point
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithSize: (OFSize)size
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)valueWithRect: (OFRect)rect
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)numberWithBool: (bool)value
{
	return [[[self alloc] initWithBool: value] autorelease];
}

+ (instancetype)numberWithChar: (signed char)value
575
576
577
578
579
580
581






582
583
584
585
586
587
588
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630







+
+
+
+
+
+







+ (instancetype)numberWithDouble: (double)value
{
	return [[[self alloc] initWithDouble: value] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithBool: (bool)value
{
	self = [super init];

992
993
994
995
996
997
998
999

1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
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++)
			OFHashAdd(&hash, ((char *)&d)[i]);
			OFHashAddByte(&hash, ((char *)&d)[i]);
	} else if (isSigned(self) || isUnsigned(self)) {
		unsigned long long value = self.unsignedLongLongValue;

		while (value != 0) {
			OFHashAdd(&hash, value & 0xFF);
			OFHashAddByte(&hash, value & 0xFF);
			value >>= 8;
		}
	} else
		@throw [OFInvalidFormatException exception];

	OFHashFinalize(&hash);

Modified src/OFObject.h from [48eed47979] to [698abcee0b].

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
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
OFRangeMake(size_t start, size_t length)
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
OFRangeEqual(OFRange range1, OFRange range2)
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
164

165
166
167
168
169
170
171
172
173
174
175
176
177
178
179

180
181
182
183
184
185
186
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
OFPointMake(float x, float y)
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
OFPointEqual(OFPoint point1, OFPoint point2)
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
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225

226
227
228
229
230
231
232
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
OFSizeMake(float width, float height)
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
OFSizeEqual(OFSize size1, OFSize size2)
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
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
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
OFRectMake(float x, float y, float width, float height)
OFMakeRect(float x, float y, float width, float height)
{
	OFRect rect = {
		OFPointMake(x, y),
		OFSizeMake(width, height)
		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
OFRectEqual(OFRect rect1, OFRect rect2)
OFEqualRects(OFRect rect1, OFRect rect2)
{
	if (!OFPointEqual(rect1.origin, rect2.origin))
	if (!OFEqualPoints(rect1.origin, rect2.origin))
		return false;

	if (!OFSizeEqual(rect1.size, rect2.size))
	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
OFHashAdd(unsigned long *_Nonnull hash, unsigned char byte)
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)
{
	OFHashAdd(hash, (otherHash >> 24) & 0xFF);
	OFHashAdd(hash, (otherHash >> 16) & 0xFF);
	OFHashAdd(hash, (otherHash >>  8) & 0xFF);
	OFHashAdd(hash, otherHash & 0xFF);
	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
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
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 32 bit hash for the object.
 * @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 32 bit hash for the object
 * @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 whether the object allows weak references.
 *
 * @return Whether the object allows weak references
 */
- (bool)allowsWeakReference;

/**
 * @brief Returns a boolean whether the object of the specified kind.
 * @brief Returns a boolean whether the object is of the specified kind.
 *
 * @param class_ The class whose kind is checked
 * @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
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
653

654
655
656



657
658
659
660
661
662
663
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`, instead, it will throw an
 * This method will never return `nil`.
 * @ref OFAllocFailedException.
 *
 * @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
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
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
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.
 *
 * Throws @ref OFOutOfMemoryException if allocating failed and
 * @ref OFOutOfRangeException if the requested size exceeds the address space.
 *
 * @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.
 *
 * Throws @ref OFOutOfMemoryException if allocating failed and
 * @ref OFOutOfRangeException if the requested size exceeds the address space.
 *
 * @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.
 *
 * Throws @ref OFOutOfMemoryException if allocating failed and
 * @ref OFOutOfRangeException if the requested size exceeds the address space.
 *
 * @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 [8b7ed1ef23] to [0477c3fb09].

40
41
42
43
44
45
46

47
48
49
50
51
52
53
54
55
56
57
58
59
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59







+





-







#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 "OFMemoryNotPartOfObjectException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#if defined(OF_APPLE_RUNTIME) && __OBJC2__
# import <objc/objc-exception.h>
#elif defined(OF_OBJFW_RUNTIME)
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
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







-
+
+





-
-
+
+
+
+
+

+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







}

#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
static void
uncaughtExceptionHandler(id exception)
{
	OFString *description = [exception description];
	OFArray *backtrace = nil;
	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(backtrace)])
		backtrace = [exception backtrace];
	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 (backtrace != nil) {
		OFString *s = [backtrace componentsJoinedByString: @"\n  "];
		fprintf(stderr, "\nBacktrace:\n  %s\n\n",
		    [s cStringWithEncoding: encoding]);

		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
329
330
331
332
333
334
335




336
337
338
339
340
341
342
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375







+
+
+
+







		    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;
1079
1080
1081
1082
1083
1084
1085
1086

1087
1088
1089
1090
1091
1092
1093
1112
1113
1114
1115
1116
1117
1118

1119
1120
1121
1122
1123
1124
1125
1126







-
+







{
	uintptr_t ptr = (uintptr_t)self;
	unsigned long hash;

	OFHashInit(&hash);

	for (size_t i = 0; i < sizeof(ptr); i++) {
		OFHashAdd(&hash, ptr & 0xFF);
		OFHashAddByte(&hash, ptr & 0xFF);
		ptr >>= 8;
	}

	OFHashFinalize(&hash);

	return hash;
}
1199
1200
1201
1202
1203
1204
1205




1206
1207
1208
1209
1210
1211
1212
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249







+
+
+
+








	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/OFOnce.h from [fee56e64fa] to [3af1572f79].

28
29
30
31
32
33
34








35

36
37
38
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43
44
45
46







+
+
+
+
+
+
+
+
-
+



typedef int OFOnceControl;
# define OFOnceControlInitValue 0
#endif

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @brief Executes the specified function exactly once in the application's
 *	  lifetime, even in a multi-threaded environment.
 *
 * @param control An OFOnceControl. This should be a static variable
 *		  preinitialized to `OFOnceControlInitValue`.
 * @param function The function to execute once
 */
extern void OFOnce(OFOnceControl *control, void (*func)(void));
extern void OFOnce(OFOnceControl *control, void (*function)(void));
#ifdef __cplusplus
}
#endif

Modified src/OFOnce.m from [a3ef1477f9] to [72d5ba7049].

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
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







-
+



-
+



-
+






-
+







#endif

#ifdef OF_AMIGAOS
# include <proto/exec.h>
#endif

void
OFOnce(OFOnceControl *control, void (*func)(void))
OFOnce(OFOnceControl *control, void (*function)(void))
{
#if !defined(OF_HAVE_THREADS)
	if (*control == 0) {
		func();
		function();
		*control = 1;
	}
#elif defined(OF_HAVE_PTHREADS)
	pthread_once(control, func);
	pthread_once(control, function);
#elif defined(OF_HAVE_ATOMIC_OPS)
	/* Avoid atomic operations in case it's already done. */
	if (*control == 2)
		return;

	if (OFAtomicIntCompareAndSwap(control, 0, 1)) {
		func();
		function();

		OFMemoryBarrier();

		OFAtomicIntIncrease(control);
	} else
		while (*control == 1)
			OFYieldThread();
71
72
73
74
75
76
77
78

79
80
81
82
83
84
71
72
73
74
75
76
77

78
79
80
81
82
83
84







-
+






			Forbid();
		}
	}

	Permit();

	if (run) {
		func();
		function();
		*control = 2;
	}
#else
# error No OFOnce available
#endif
}

Modified src/OFOptionsParser.m from [6586be74a2] to [c0426ac296].

195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
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:
			    OFRangeMake(2, pos - 2)] copy];
			    OFMakeRange(2, pos - 2)] copy];

			objc_autoreleasePoolPop(pool);

			option = [_longOptions objectForKey: _lastLongOption];
			if (option == NULL)
				return '?';

267
268
269
270
271
272
273
274

275
276
267
268
269
270
271
272
273

274
275
276







-
+



	return '?';
}

- (OFArray *)remainingArguments
{
	return [_arguments objectsInRange:
	    OFRangeMake(_index, _arguments.count - _index)];
	    OFMakeRange(_index, _arguments.count - _index)];
}
@end

Modified src/OFPlugin.h from [9b033eeb96] to [a9cf165ddb].

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
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







-
-
-
-
-



-
-
-
-
-







-
+

-
-
-

+


-
+
-



-
+

+
+
+
-
-
+
+

-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+


#import "OFObject.h"

@class OFString;

#ifndef OF_WINDOWS
# include <dlfcn.h>
typedef void *OFPluginHandle;

typedef enum {
	OFDLOpenFlagLazy = RTLD_LAZY,
	OFDLOpenFlagNow  = RTLD_NOW
} OFDLOpenFlags;
#else
# include <windows.h>
typedef HMODULE OFPluginHandle;

typedef enum {
	OFDLOpenFlagLazy = 0,
	OFDLOpenFlagNow  = 0
} OFDLOpenFlags;
#endif

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFPlugin OFPlugin.h ObjFW/OFPlugin.h
 *
 * @brief Provides a system for loading plugins at runtime.
 * @brief A class representing a loaded plugin (shared library).
 *
 * A plugin must subclass @ref OFPlugin and have a global function called
 * `OFPluginInit`, which returns an instance of the @ref OFPlugin subclass and
 * takes no parameters.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFPlugin: OFObject
{
	OFPluginHandle _pluginHandle;
	OFPluginHandle _handle;
	OF_RESERVE_IVARS(OFPlugin, 4)
}

/**
 * @brief Loads a plugin from a file.
 * @brief Returns the plugin path for a plugin with the specified name.
 *
 * E.g. on ELF systems, it appends .so, while on macOS and iOS, it creates the
 * appropriate plugin path. This can also be prefixed by a directory.
 *
 * @param path Path to the plugin file. The suffix is appended automatically.
 * @return The loaded plugin
 * @param name The name to return the plugin path for
 * @return The plugin path
 */
+ (OF_KINDOF(OFPlugin *))pluginWithPath: (OFString *)path;
@end

+ (OFString *)pathForName: (OFString *)name;

/**
 * @brief Creates a new OFPlugin by loading the plugin with the specified path.
 *
#ifdef __cplusplus
extern "C" {
#endif
extern OFPluginHandle OFDLOpen(OFString *path, OFDLOpenFlags flags);
extern void *OFDLSym(OFPluginHandle handle, const char *symbol);
extern OFString *_Nullable OFDLError(void);
 * @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;
extern void OFDLClose(OFPluginHandle handle);
#ifdef __cplusplus
}
#endif

/**
 * @brief Returns the address for the specified symbol, or `nil` if not found.
 *
 * @param symbol The symbol to return the address for
 * @return The address for the speccified symbol, or `nil` if not found
 */
- (nullable void *)addressForSymbol: (OFString *)symbol;
@end

OF_ASSUME_NONNULL_END

Modified src/OFPlugin.m from [e14701ced1] to [dfbf2c9e77].

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
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







-
+
+
+

-
-
+
+

-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-



+
+
+
+
+
-
+
-
-
+

-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+

+
+
-
+
+
+

-
-
-
-
+
+
+
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-

-
+

-
-
-
-
-
-
+
+
+
+
-

-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+

-
-
+
+

+
+
+
-
+
+
+
+
+
+




+
-
+
+
+
+


-
-


#import "OFLocale.h"
#import "OFString.h"
#import "OFSystemInfo.h"

#import "OFInitializationFailedException.h"
#import "OFLoadPluginFailedException.h"

typedef OFPlugin *(*PluginInit)(void);
#ifndef RTLD_LAZY
# define RTLD_LAZY 0
#endif

OFPluginHandle
OFDLOpen(OFString *path, OFDLOpenFlags flags)
@implementation OFPlugin
+ (instancetype)pluginWithPath: (OFString *)path
{
#ifndef OF_WINDOWS
	return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags);
#else
	if (path == nil)
	return [[[self alloc] initWithPath: path] autorelease];
}

+ (OFString *)pathForName: (OFString *)name
		return GetModuleHandle(NULL);

	if ([OFSystemInfo isWindowsNT])
		return LoadLibraryW(path.UTF16String);
	else
		return LoadLibraryA(
{
#if defined(OF_MACOS)
	return [name stringByAppendingFormat: @".bundle/Contents/MacOS/%@",
					      name.lastPathComponent];
#elif defined(OF_IOS)
	return [name stringByAppendingFormat: @".bundle/%@",
					      name.lastPathComponent];
#else
	return [name stringByAppendingString: @PLUGIN_SUFFIX];
		    [path cStringWithEncoding: [OFLocale encoding]]);
#endif
}

- (instancetype)initWithPath: (OFString *)path
{
	self = [super init];

	@try {
void *
		void *pool = objc_autoreleasePoolPush();
OFDLSym(OFPluginHandle handle, const char *symbol)
{

#ifndef OF_WINDOWS
	return dlsym(handle, symbol);
#else
	return (void *)(uintptr_t)GetProcAddress(handle, symbol);
#endif
}

void
OFDLClose(OFPluginHandle handle)
{
#ifndef OF_WINDOWS
	dlclose(handle);
		_handle = dlopen(
#else
	FreeLibrary(handle);
#endif
}

OFString *
OFDLError(void)
{
#ifndef OF_WINDOWS
	return [OFString stringWithCString: dlerror()
				  encoding: [OFLocale encoding]];
		    [path cStringWithEncoding: [OFLocale encoding]], RTLD_LAZY);
#else
		if ([OFSystemInfo isWindowsNT])
			_handle = LoadLibraryW(path.UTF16String);
	return nil;
		else
			_handle = LoadLibraryA(
			    [path cStringWithEncoding: [OFLocale encoding]]);
#endif
}

@implementation OFPlugin
+ (id)pluginWithPath: (OFString *)path

		if (_handle == NULL) {
#ifndef OF_WINDOWS
			OFString *error = [OFString
{
	void *pool = objc_autoreleasePoolPush();
	OFPluginHandle handle;
			    stringWithCString: dlerror()
	PluginInit initPlugin;
	OFPlugin *plugin;

				     encoding: [OFLocale encoding]];
#if defined(OF_MACOS)
	path = [path stringByAppendingFormat: @".bundle/Contents/MacOS/%@",
					      path.lastPathComponent];
#elif defined(OF_IOS)
	path = [path stringByAppendingFormat: @".bundle/%@",
					      path.lastPathComponent];
#else
	path = [path stringByAppendingString: @PLUGIN_SUFFIX];
			OFString *error = nil;
#endif

	if ((handle = OFDLOpen(path, OFDLOpenFlagLazy)) == NULL)
		@throw [OFLoadPluginFailedException
		    exceptionWithPath: path
				error: OFDLError()];

			@throw [OFLoadPluginFailedException
			    exceptionWithPath: path
					error: error];
		}
	objc_autoreleasePoolPop(pool);

	initPlugin = (PluginInit)(uintptr_t)OFDLSym(handle, "OFPluginInit");
	if (initPlugin == (PluginInit)0 || (plugin = initPlugin()) == nil) {
		OFDLClose(handle);
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
	}

		objc_autoreleasePoolPop(pool);
	plugin->_pluginHandle = handle;
	return plugin;
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFPlugin class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
		} @catch (id e) {
			[self release];
			@throw e;
		}
	} @catch (id e) {
		[self release];
		@throw e;
	}

		abort();
	}
	return self;
}

- (void *)addressForSymbol: (OFString *)symbol
{
#ifndef OF_WINDOWS
	return [super init];
	return dlsym(_handle,
	    [symbol cStringWithEncoding: [OFLocale encoding]]);
#else
	return (void *)(uintptr_t)GetProcAddress(_handle,
	    [symbol cStringWithEncoding: [OFLocale encoding]]);
#endif
}

- (void)dealloc
{
#ifndef OF_WINDOWS
	OFPluginHandle h = _pluginHandle;
	dlclose(_handle);
#else
	FreeLibrary(_handle);
#endif

	[super dealloc];

	OFDLClose(h);
}
@end

Modified src/OFPollKernelEventObserver.m from [458ef336b0] to [e4119778c6].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
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 "OFObserveFailedException.h"
#import "OFObserveKernelEventsFailedException.h"
#import "OFOutOfRangeException.h"

#ifdef OF_WII
# define pollfd pollsd
# define fd socket
#endif

70
71
72
73
74
75
76

77
78


79
80
81
82
83
84
85
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    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

113
114


115
116
117
118
119
120
121
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    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

188
189


190
191
192
193
194
195
196
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: errno];
		    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
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 [6aa5ca009f] to [ccade11e78].

37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
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 "OFObserveFailedException.h"
#import "OFObserveKernelEventsFailedException.h"
#import "OFWriteFailedException.h"

#include "OFRunLoopConstants.inc"

static OFRunLoop *mainRunLoop = nil;

@interface OFRunLoopState: OFObject
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
586
587
588
589
590
591
592

593
594
595
596
597
598
599
600







-
+







	OFEnsure(_writtenLength <= dataLength);

	if (_writtenLength != dataLength && exception == nil)
		return true;

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL) {
		newData = _block(_data, _writtenLength, exception);
		newData = _block(_writtenLength, exception);

		if (newData == nil)
			return false;

		oldData = _data;
		_data = [newData copy];
		[oldData release];
663
664
665
666
667
668
669
670

671
672
673
674
675
676
677
663
664
665
666
667
668
669

670
671
672
673
674
675
676
677







-
+







	OFEnsure(_writtenLength <= cStringLength);

	if (_writtenLength != cStringLength && exception == nil)
		return true;

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL) {
		newString = _block(_string, _writtenLength, exception);
		newString = _block(_writtenLength, exception);

		if (newString == nil)
			return false;

		oldString = _string;
		_string = [newString copy];
		[oldString release];
857
858
859
860
861
862
863
864

865
866
867
868
869
870
871
857
858
859
860
861
862
863

864
865
866
867
868
869
870
871







-
+







			  receiver: &_receiver];
	} @catch (id e) {
		exception = e;
	}

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL) {
		newData = _block(_data, &_receiver, exception);
		newData = _block(exception);

		if (newData == nil)
			return false;

		oldData = _data;
		_data = [newData copy];
		[oldData release];
958
959
960
961
962
963
964
965

966
967
968
969
970
971
972
958
959
960
961
962
963
964

965
966
967
968
969
970
971
972







-
+







			    length: _data.count * _data.itemSize];
	} @catch (id e) {
		exception = e;
	}

# ifdef OF_HAVE_BLOCKS
	if (_block != NULL) {
		newData = _block(_data, exception);
		newData = _block(exception);

		if (newData == nil)
			return false;

		oldData = _data;
		_data = [newData copy];
		[oldData release];
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
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 (OFObserveFailedException *e) {
			} @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
1682

1683
1684
1685
1686
1687
1688
1689
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 (OFObserveFailedException *e) {
			} @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 [0544ae262f] to [f7b34dfc4b].

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
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







-

+




-
-
+
+
+
-
-
-
+
+







 */
@protocol OFSPXSocketDelegate <OFSequencedPacketSocketDelegate>
@optional
/**
 * @brief A method which is called when a socket connected.
 *
 * @param socket The socket which connected
 * @param node The node the socket connected to
 * @param network The network of the node the socket connected to
 * @param node The node the socket connected to
 * @param port The port of the node to which the socket connected
 * @param exception An exception that occurred while connecting, or nil on
 *		    success
 */
-     (void)socket: (OFSPXSocket *)socket
  didConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
-	 (void)socket: (OFSPXSocket *)socket
  didConnectToNetwork: (uint32_t)network
		 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	   network: (uint32_t)network
	      port: (uint16_t)port
	 exception: (nullable id)exception;
		 port: (uint16_t)port
	    exception: (nullable id)exception;
@end

/**
 * @class OFSPXSocket OFSPXSocket.h ObjFW/OFSPXSocket.h
 *
 * @brief A class which provides methods to create and use SPX sockets.
 *
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
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







-

+


+
+

+
-
+
-
-
+




-

+



+
-
+
-
-
+




-

+




+
-
+
-
-
-
+
+











+
-
+
-
-
-
+
+











+
-
+
-
-
-
-
+
+
+








+
+





 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
    id <OFSPXSocketDelegate> delegate;

/**
 * @brief Connect the OFSPXSocket to the specified destination.
 *
 * @param node The node to connect to
 * @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
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
		    node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	      network: (uint32_t)network
		 port: (uint16_t)port;
		    port: (uint16_t)port;

/**
 * @brief Asynchronously connect the OFSPXSocket to the specified destination.
 *
 * @param node The node to connect to
 * @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)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port;
			 port: (uint16_t)port;

/**
 * @brief Asynchronously connect the OFSPXSocket to the specified destination.
 *
 * @param node The node to connect to
 * @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
 * @param runLoopMode The run loop mode in which to perform the async connect
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode;
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Asynchronously connect the OFSPXSocket to the specified destination.
 *
 * @param node The node to connect to
 * @param network The network on which the node to connect to is
 * @param port The port (sometimes also called socket number) on the node to
 *	       connect to
 * @param block The block to execute once the connection has been established
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
		     block: (OFSPXSocketAsyncConnectBlock)block;
			 port: (uint16_t)port
			block: (OFSPXSocketAsyncConnectBlock)block;

/**
 * @brief Asynchronously connect the OFSPXSocket to the specified destination.
 *
 * @param node The node to connect to
 * @param network The network on which the node to connect to is
 * @param port The port (sometimes also called socket number) on the node to
 *	       connect to
 * @param runLoopMode The run loop mode in which to perform the async connect
 * @param block The block to execute once the connection has been established
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
		     block: (OFSPXSocketAsyncConnectBlock)block;
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
			block: (OFSPXSocketAsyncConnectBlock)block;
#endif

/**
 * @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/OFSPXSocket.m from [772214332c] to [63c27817f9].

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
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







-

+







-

+










-

+









-

+







- (void)of_closeSocket;
@end

OF_DIRECT_MEMBERS
@interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate>
{
	OFSPXSocket *_socket;
	unsigned char _node[IPX_NODE_LEN];
	uint32_t _network;
	unsigned char _node[IPX_NODE_LEN];
	uint16_t _port;
#ifdef OF_HAVE_BLOCKS
	OFSPXSocketAsyncConnectBlock _block;
#endif
}

- (instancetype)initWithSocket: (OFSPXSocket *)socket
			  node: (unsigned char [IPX_NODE_LEN])node
		       network: (uint32_t)network
			  node: (unsigned char [IPX_NODE_LEN])node
			  port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
			 block: (OFSPXSocketAsyncConnectBlock)block
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end

@implementation OFSPXSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXSocket *)sock
			  node: (unsigned char [IPX_NODE_LEN])node
		       network: (uint32_t)network
			  node: (unsigned char [IPX_NODE_LEN])node
			  port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
			 block: (OFSPXSocketAsyncConnectBlock)block
#endif
{
	self = [super init];

	@try {
		_socket = [sock retain];
		memcpy(_node, node, IPX_NODE_LEN);
		_network = network;
		memcpy(_node, node, IPX_NODE_LEN);
		_port = port;
#ifdef OF_HAVE_BLOCKS
		_block = [block copy];
#endif
	} @catch (id e) {
		[self release];
		@throw e;
101
102
103
104
105
106
107
108

109
110
111
112
113
114
115
101
102
103
104
105
106
107

108
109
110
111
112
113
114
115







-
+








	[super dealloc];
}

- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
	OFSocketAddress address =
	    OFSocketAddressMakeIPX(_node, _network, _port);
	    OFSocketAddressMakeIPX(_network, _node, _port);
	id exception = nil;
	int errNo;

	if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
		exception = [self of_connectionFailedExceptionForErrNo: errNo];
		goto inform_delegate;
	}
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
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







-
-
-
-
-
-
+
+
+
+
+
+







-
-
-
-
-
+
+
+
+
+








#ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		_block(exception);
	else {
#endif
		if ([delegate respondsToSelector:
		    @selector(socket:didConnectToNode:network:port:exception:)])
			[delegate     socket: _socket
			    didConnectToNode: _node
				     network: _network
					port: _port
				   exception: exception];
		    @selector(socket:didConnectToNetwork:node:port:exception:)])
			[delegate	 socket: _socket
			    didConnectToNetwork: _network
					   node: _node
					   port: _port
				      exception: exception];
#ifdef OF_HAVE_BLOCKS
	}
#endif
}

- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
	return [OFConnectionFailedException exceptionWithNode: _node
						      network: _network
							 port: _port
						       socket: _socket
							errNo: errNo];
	return [OFConnectionFailedException exceptionWithNetwork: _network
							    node: _node
							    port: _port
							  socket: _socket
							   errNo: errNo];
}
@end

@implementation OFSPXSocket
@dynamic delegate;

- (int)of_createSocketForAddress: (const OFSocketAddress *)address
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
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







-
+














+
-
+
-
-
+

-
+




-
-
-
-
-
+
+
+
+
+





-
-
-
-
-
+
+
+
+
+



+
-
+
-
-
+

-
-
-
-
+
+
+
+


+
-
+
-
-
-
+
+





-

+










+
-
+
-
-
-
+
+

-
-
-
-
-
+
+
+
+
+


+
-
+
-
-
-
-
+
+
+





-

+



















-
+

-
+















+
-
+















-
+












-
+













- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address
			    errNo: (int *)errNo
{
	if (_socket == OFInvalidSocketHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (connect(_socket, &address->sockaddr.sockaddr,
	if (connect(_socket, (struct sockaddr *)&address->sockaddr,
	    address->length) != 0) {
		*errNo = OFSocketErrNo();
		return false;
	}

	return true;
}

- (void)of_closeSocket
{
	closesocket(_socket);
	_socket = OFInvalidSocketHandle;
}

- (void)connectToNetwork: (uint32_t)network
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
		    node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	      network: (uint32_t)network
		 port: (uint16_t)port
		    port: (uint16_t)port
{
	OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port);
	OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port);
	int errNo;

	if (![self of_createSocketForAddress: &address errNo: &errNo])
		@throw [OFConnectionFailedException
		    exceptionWithNode: node
			      network: network
				 port: port
			       socket: self
				errNo: errNo];
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: errNo];

	if (![self of_connectSocketToAddress: &address errNo: &errNo]) {
		[self of_closeSocket];

		@throw [OFConnectionFailedException
		    exceptionWithNode: node
			      network: network
				 port: port
			       socket: self
				errNo: errNo];
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: errNo];
	}
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
			 port: (uint16_t)port
{
	[self asyncConnectToNode: node
			 network: network
			    port: port
		     runLoopMode: OFDefaultRunLoopMode];
	[self asyncConnectToNetwork: network
			       node: node
			       port: port
			runLoopMode: OFDefaultRunLoopMode];
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFSPXSocketAsyncConnectDelegate alloc]
	    initWithSocket: self
		      node: node
		   network: network
		      node: node
		      port: port
#ifdef OF_HAVE_BLOCKS
		     block: NULL
#endif
	    ] autorelease] startWithRunLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
		     block: (OFSPXSocketAsyncConnectBlock)block
			 port: (uint16_t)port
			block: (OFSPXSocketAsyncConnectBlock)block
{
	[self asyncConnectToNode: node
			 network: network
			    port: port
		     runLoopMode: OFDefaultRunLoopMode
			   block: block];
	[self asyncConnectToNetwork: network
			       node: node
			       port: port
			runLoopMode: OFDefaultRunLoopMode
			      block: block];
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
		     block: (OFSPXSocketAsyncConnectBlock)block
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
			block: (OFSPXSocketAsyncConnectBlock)block
{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFSPXSocketAsyncConnectDelegate alloc]
	    initWithSocket: self
		      node: node
		   network: network
		      node: node
		      port: port
		     block: block
	    ] autorelease] startWithRunLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}
#endif

- (OFSocketAddress)bindToPort: (uint16_t)port
{
	const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
	OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeIPX(zeroNode, 0, port);
	address = OFSocketAddressMakeIPX(0, zeroNode, port);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.ipx.sipx_family,
	    SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) ==
	    OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithPort: port
			   packetType: SPXPacketType
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (bind(_socket, (struct sockaddr *)&address.sockaddr,
	if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
	}

	memset(&address, 0, sizeof(address));
	address.family = OFSocketAddressFamilyIPX;
	address.length = (socklen_t)sizeof(address.sockaddr);

	if (OFGetSockName(_socket, &address.sockaddr.sockaddr,
	if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
	    &address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
	}

	if (address.sockaddr.sockaddr.sa_family != AF_IPX) {
	if (address.sockaddr.ipx.sipx_family != AF_IPX) {
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: EAFNOSUPPORT];
	}

	return address;
}
@end

Modified src/OFSPXStreamSocket.h from [ccec1c33a6] to [9a246da830].

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
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







-

+




-
-
+
+
+
-
-
-
+
+







 */
@protocol OFSPXStreamSocketDelegate <OFStreamSocketDelegate>
@optional
/**
 * @brief A method which is called when a socket connected.
 *
 * @param socket The socket which connected
 * @param node The node the socket connected to
 * @param network The network of the node the socket connected to
 * @param node The node the socket connected to
 * @param port The port of the node to which the socket connected
 * @param exception An exception that occurred while connecting, or nil on
 *		    success
 */
-     (void)socket: (OFSPXStreamSocket *)socket
  didConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
-	 (void)socket: (OFSPXStreamSocket *)socket
  didConnectToNetwork: (uint32_t)network
		 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	   network: (uint32_t)network
	      port: (uint16_t)port
	 exception: (nullable id)exception;
		 port: (uint16_t)port
	    exception: (nullable id)exception;
@end

/**
 * @class OFSPXStreamSocket OFSPXStreamSocket.h ObjFW/OFSPXStreamSocket.h
 *
 * @brief A class which provides methods to create and use SPX stream sockets.
 *
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
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







-

+


+
+

+
-
+
-
-
+





-

+



+
-
+
-
-
+





-

+




+
-
+
-
-
-
+
+






-

+




+
-
+
-
-
-
+
+





-

+





+
-
+
-
-
-
-
+
+
+








+
+





 */
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
    id <OFSPXStreamSocketDelegate> delegate;

/**
 * @brief Connect the OFSPXStreamSocket to the specified destination.
 *
 * @param node The node to connect to
 * @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
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
		    node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	      network: (uint32_t)network
		 port: (uint16_t)port;
		    port: (uint16_t)port;

/**
 * @brief Asynchronously connect the OFSPXStreamSocket to the specified
 *	  destination.
 *
 * @param node The node to connect to
 * @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)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port;
			 port: (uint16_t)port;

/**
 * @brief Asynchronously connect the OFSPXStreamSocket to the specified
 *	  destination.
 *
 * @param node The node to connect to
 * @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
 * @param runLoopMode The run loop mode in which to perform the async connect
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode;
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Asynchronously connect the OFSPXStreamSocket to the specified
 *	  destination.
 *
 * @param node The node to connect to
 * @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
 * @param block The block to execute once the connection has been established
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
		     block: (OFSPXStreamSocketAsyncConnectBlock)block;
			 port: (uint16_t)port
			block: (OFSPXStreamSocketAsyncConnectBlock)block;

/**
 * @brief Asynchronously connect the OFSPXStreamSocket to the specified
 *	  destination.
 *
 * @param node The node to connect to
 * @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
 * @param runLoopMode The run loop mode in which to perform the async connect
 * @param block The block to execute once the connection has been established
 */
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
		     block: (OFSPXStreamSocketAsyncConnectBlock)block;
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
			block: (OFSPXStreamSocketAsyncConnectBlock)block;
#endif

/**
 * @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/OFSPXStreamSocket.m from [f7ce692f2d] to [94f78e3e0d].

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
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







-

+







-

+










-

+









-

+







@end

OF_DIRECT_MEMBERS
@interface OFSPXStreamSocketAsyncConnectDelegate: OFObject
    <OFRunLoopConnectDelegate>
{
	OFSPXStreamSocket *_socket;
	unsigned char _node[IPX_NODE_LEN];
	uint32_t _network;
	unsigned char _node[IPX_NODE_LEN];
	uint16_t _port;
#ifdef OF_HAVE_BLOCKS
	OFSPXStreamSocketAsyncConnectBlock _block;
#endif
}

- (instancetype)initWithSocket: (OFSPXStreamSocket *)socket
			  node: (unsigned char [IPX_NODE_LEN])node
		       network: (uint32_t)network
			  node: (unsigned char [IPX_NODE_LEN])node
			  port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
			 block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
;
- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode;
@end

@implementation OFSPXStreamSocketAsyncConnectDelegate
- (instancetype)initWithSocket: (OFSPXStreamSocket *)sock
			  node: (unsigned char [IPX_NODE_LEN])node
		       network: (uint32_t)network
			  node: (unsigned char [IPX_NODE_LEN])node
			  port: (uint16_t)port
#ifdef OF_HAVE_BLOCKS
			 block: (OFSPXStreamSocketAsyncConnectBlock)block
#endif
{
	self = [super init];

	@try {
		_socket = [sock retain];
		memcpy(_node, node, IPX_NODE_LEN);
		_network = network;
		memcpy(_node, node, IPX_NODE_LEN);
		_port = port;
#ifdef OF_HAVE_BLOCKS
		_block = [block copy];
#endif
	} @catch (id e) {
		[self release];
		@throw e;
102
103
104
105
106
107
108
109

110
111
112
113
114
115
116
102
103
104
105
106
107
108

109
110
111
112
113
114
115
116







-
+








	[super dealloc];
}

- (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode
{
	OFSocketAddress address =
	    OFSocketAddressMakeIPX(_node, _network, _port);
	    OFSocketAddressMakeIPX(_network, _node, _port);
	id exception = nil;
	int errNo;

	if (![_socket of_createSocketForAddress: &address errNo: &errNo]) {
		exception = [self of_connectionFailedExceptionForErrNo: errNo];
		goto inform_delegate;
	}
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
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







-
-
-
-
-
-
+
+
+
+
+
+







-
-
-
-
-
+
+
+
+
+








#ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		_block(exception);
	else {
#endif
		if ([delegate respondsToSelector:
		    @selector(socket:didConnectToNode:network:port:exception:)])
			[delegate     socket: _socket
			    didConnectToNode: _node
				     network: _network
					port: _port
				   exception: exception];
		    @selector(socket:didConnectToNetwork:node:port:exception:)])
			[delegate	 socket: _socket
			    didConnectToNetwork: _network
					   node: _node
					   port: _port
				      exception: exception];
#ifdef OF_HAVE_BLOCKS
	}
#endif
}

- (id)of_connectionFailedExceptionForErrNo: (int)errNo
{
	return [OFConnectionFailedException exceptionWithNode: _node
						      network: _network
							 port: _port
						       socket: _socket
							errNo: errNo];
	return [OFConnectionFailedException exceptionWithNetwork: _network
							    node: _node
							    port: _port
							  socket: _socket
							   errNo: errNo];
}
@end

@implementation OFSPXStreamSocket
@dynamic delegate;

- (int)of_createSocketForAddress: (const OFSocketAddress *)address
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
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







-
+














+
-
+
-
-
+

-
+




-
-
-
-
-
+
+
+
+
+





-
-
-
-
-
+
+
+
+
+



+
-
+
-
-
+

-
-
-
-
+
+
+
+


+
-
+
-
-
-
+
+





-

+










+
-
+
-
-
-
+
+

-
-
-
-
-
+
+
+
+
+


+
-
+
-
-
-
-
+
+
+





-

+



















-
+

-
+














+
-
+















-
+












-
+













- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address
			    errNo: (int *)errNo
{
	if (_socket == OFInvalidSocketHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (connect(_socket, &address->sockaddr.sockaddr,
	if (connect(_socket, (struct sockaddr *)&address->sockaddr,
	    address->length) != 0) {
		*errNo = OFSocketErrNo();
		return false;
	}

	return true;
}

- (void)of_closeSocket
{
	closesocket(_socket);
	_socket = OFInvalidSocketHandle;
}

- (void)connectToNetwork: (uint32_t)network
- (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
		    node: (unsigned char [_Nonnull IPX_NODE_LEN])node
	      network: (uint32_t)network
		 port: (uint16_t)port
		    port: (uint16_t)port
{
	OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port);
	OFSocketAddress address = OFSocketAddressMakeIPX(network, node, port);
	int errNo;

	if (![self of_createSocketForAddress: &address errNo: &errNo])
		@throw [OFConnectionFailedException
		    exceptionWithNode: node
			      network: network
				 port: port
			       socket: self
				errNo: errNo];
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: errNo];

	if (![self of_connectSocketToAddress: &address errNo: &errNo]) {
		[self of_closeSocket];

		@throw [OFConnectionFailedException
		    exceptionWithNode: node
			      network: network
				 port: port
			       socket: self
				errNo: errNo];
		    exceptionWithNetwork: network
				    node: node
				    port: port
				  socket: self
				   errNo: errNo];
	}
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
			 port: (uint16_t)port
{
	[self asyncConnectToNode: node
			 network: network
			    port: port
		     runLoopMode: OFDefaultRunLoopMode];
	[self asyncConnectToNetwork: network
			       node: node
			       port: port
			runLoopMode: OFDefaultRunLoopMode];
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
	    initWithSocket: self
		      node: node
		   network: network
		      node: node
		      port: port
#ifdef OF_HAVE_BLOCKS
		     block: NULL
#endif
	    ] autorelease] startWithRunLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
		     block: (OFSPXStreamSocketAsyncConnectBlock)block
			 port: (uint16_t)port
			block: (OFSPXStreamSocketAsyncConnectBlock)block
{
	[self asyncConnectToNode: node
			 network: network
			    port: port
		     runLoopMode: OFDefaultRunLoopMode
			   block: block];
	[self asyncConnectToNetwork: network
			       node: node
			       port: port
			runLoopMode: OFDefaultRunLoopMode
			      block: block];
}

- (void)asyncConnectToNetwork: (uint32_t)network
- (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node
			 node: (unsigned char [_Nonnull IPX_NODE_LEN])node
		   network: (uint32_t)network
		      port: (uint16_t)port
	       runLoopMode: (OFRunLoopMode)runLoopMode
		     block: (OFSPXStreamSocketAsyncConnectBlock)block
			 port: (uint16_t)port
		  runLoopMode: (OFRunLoopMode)runLoopMode
			block: (OFSPXStreamSocketAsyncConnectBlock)block
{
	void *pool = objc_autoreleasePoolPush();

	[[[[OFSPXStreamSocketAsyncConnectDelegate alloc]
	    initWithSocket: self
		      node: node
		   network: network
		      node: node
		      port: port
		     block: block
	    ] autorelease] startWithRunLoopMode: runLoopMode];

	objc_autoreleasePoolPop(pool);
}
#endif

- (OFSocketAddress)bindToPort: (uint16_t)port
{
	const unsigned char zeroNode[IPX_NODE_LEN] = { 0 };
	OFSocketAddress address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeIPX(zeroNode, 0, port);
	address = OFSocketAddressMakeIPX(0, zeroNode, port);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.ipx.sipx_family,
	    SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithPort: port
			   packetType: SPXPacketType
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (bind(_socket, (struct sockaddr *)&address.sockaddr,
	if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
	}

	memset(&address, 0, sizeof(address));
	address.family = OFSocketAddressFamilyIPX;
	address.length = (socklen_t)sizeof(address.sockaddr);

	if (OFGetSockName(_socket, &address.sockaddr.sockaddr,
	if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
	    &address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: errNo];
	}

	if (address.sockaddr.sockaddr.sa_family != AF_IPX) {
	if (address.sockaddr.ipx.sipx_family != AF_IPX) {
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPort: port
						     packetType: SPXPacketType
							 socket: self
							  errNo: EAFNOSUPPORT];
	}

	return address;
}
@end

Modified src/OFSandbox.h from [8f1c6b186c] to [021642ddcf].

19
20
21
22
23
24
25

26
27
28
29
30
31
32
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
61
62
63
64
65
66
67
68
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;
	OF_RESERVE_IVARS(OFSandbox, 4)
}

@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
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
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);

	OFHashAdd(&hash, _allowsStdIO);
	OFHashAdd(&hash, _allowsReadingFiles);
	OFHashAdd(&hash, _allowsWritingFiles);
	OFHashAdd(&hash, _allowsCreatingFiles);
	OFHashAdd(&hash, _allowsCreatingSpecialFiles);
	OFHashAdd(&hash, _allowsTemporaryFiles);
	OFHashAdd(&hash, _allowsIPSockets);
	OFHashAdd(&hash, _allowsMulticastSockets);
	OFHashAdd(&hash, _allowsChangingFileAttributes);
	OFHashAdd(&hash, _allowsFileOwnerChanges);
	OFHashAdd(&hash, _allowsFileLocks);
	OFHashAdd(&hash, _allowsUNIXSockets);
	OFHashAdd(&hash, _allowsDNS);
	OFHashAdd(&hash, _allowsUserDatabaseReading);
	OFHashAdd(&hash, _allowsFileDescriptorSending);
	OFHashAdd(&hash, _allowsFileDescriptorReceiving);
	OFHashAdd(&hash, _allowsTape);
	OFHashAdd(&hash, _allowsTTY);
	OFHashAdd(&hash, _allowsProcessOperations);
	OFHashAdd(&hash, _allowsExec);
	OFHashAdd(&hash, _allowsProtExec);
	OFHashAdd(&hash, _allowsSetTime);
	OFHashAdd(&hash, _allowsPS);
	OFHashAdd(&hash, _allowsVMInfo);
	OFHashAdd(&hash, _allowsChangingProcessRights);
	OFHashAdd(&hash, _allowsPF);
	OFHashAdd(&hash, _allowsAudio);
	OFHashAdd(&hash, _allowsBPF);
	OFHashAdd(&hash, _allowsUnveil);
	OFHashAdd(&hash, _returnsErrors);
	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
67

68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
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
 * @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
 * @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
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
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)dataWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE;
+ (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
 * @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.
 * @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
153

154
155
156
157
158
159
160
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)initWithContentsOfURL: (OFURL *)URL OF_UNAVAILABLE;
- (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
190

191
192
193
194
195
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)writeToURL: (OFURL *)URL OF_UNAVAILABLE;
- (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
378

379
380
381
382
383
384
385
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)dataWithContentsOfURL: (OFURL *)URL
+ (instancetype)dataWithContentsOfURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)dataWithStringRepresentation: (OFString *)string
{
	OF_UNRECOGNIZED_SELECTOR
495
496
497
498
499
500
501
502

503
504
505
506
507
508
509
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)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithStringRepresentation: (OFString *)string
{
	OF_INVALID_INIT_METHOD
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
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)writeToURL: (OFURL *)URL
- (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
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
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 OFFileOffset;
typedef __int64 OFStreamOffset;
#elif defined(OF_ANDROID)
typedef long long OFFileOffset;
typedef long long OFStreamOffset;
#elif defined(OF_MORPHOS)
typedef signed long long OFFileOffset;
typedef signed long long OFStreamOffset;
#elif defined(OF_HAVE_OFF64_T)
typedef off64_t OFFileOffset;
typedef off64_t OFStreamOffset;
#else
typedef off_t OFFileOffset;
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 absolute offset.
 * @brief Seeks to the specified offset.
 *
 * @param offset The offset in bytes
 * @param whence From where to seek.@n
 * @param whence From where to seek.
 *		 Possible values are:
 *		 Value      | Description
 *		 -----------|---------------------------------------
 *		 `SEEK_SET` | Seek to the specified byte
 *		 `SEEK_CUR` | Seek to the current location + offset
 *		 `SEEK_END` | Seek to the end of the stream + offset
 * @return The new offset form the start of the file
 * @throw OFSeekFailedException Seeking failed
 * @throw OFNotOpenException The stream is not open
 */
- (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence;
- (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.@n
 * @param whence From where to seek.
 *		 Possible values are:
 *		 Value      | Description
 *		 -----------|---------------------------------------
 *		 `SEEK_SET` | Seek to the specified byte
 *		 `SEEK_CUR` | Seek to the current location + offset
 *		 `SEEK_END` | Seek to the end of the stream + offset
 * @return The new offset from the start of the file
 * @throw OFSeekFailedException Seeking failed
 * @throw OFNotOpenException The stream is not open
 */
- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence;
- (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
41


42
43
44
45
46


47
48

49
50
51
52
53
54
55
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];
}

- (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence
- (OFStreamOffset)lowlevelSeekToOffset: (OFStreamOffset)offset
				whence: (OFSeekWhence)whence
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence
- (OFStreamOffset)seekToOffset: (OFStreamOffset)offset
			whence: (OFSeekWhence)whence
{
	if (whence == SEEK_CUR)
	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
37

38
39
40
41
42
43
44
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 "OFObserveFailedException.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

87
88


89
90
91
92
93
94
95
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    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

111
112


113
114
115
116
117
118
119
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    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

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
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EBADF];
		    exceptionWithObserver: self
				    errNo: EBADF];


#ifndef OF_WINDOWS
	if (fd >= (int)FD_SETSIZE)
		@throw [OFOutOfRangeException exception];
#endif

202
203
204
205
206
207
208

209
210


211
212
213
214
215
216
217
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
		@throw [OFObserveFailedException exceptionWithObserver: self
								 errNo: EAGAIN];
		    exceptionWithObserver: self
				    errNo: EAGAIN];

	execSignalMask = _execSignalMask | (1ul << cancelSignal);

	Forbid();

	_waitingTask = FindTask(NULL);
	_cancelSignal = cancelSignal;
227
228
229
230
231
232
233
234

235
236
237
238
239
240
241
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 [OFObserveFailedException
		@throw [OFObserveKernelEventsFailedException
		    exceptionWithObserver: self
				    errNo: OFSocketErrNo()];

#ifdef OF_AMIGAOS
	if (execSignalMask != 0 &&
	    [_delegate respondsToSelector: @selector(execSignalWasReceived:)])
		[_delegate execSignalWasReceived: execSignalMask];

Modified src/OFSequencedPacketSocket.h from [4d7aaf9b3b] to [b8e6a1fd31].

36
37
38
39
40
41
42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
36
37
38
39
40
41
42

43
44
45
46
47

48
49
50
51
52
53
54
55







-





-
+







 */
typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length,
    id _Nullable exception);

/**
 * @brief A block which is called when a packet has been sent.
 *
 * @param data The data which was sent
 * @param exception An exception which occurred while reading or `nil` on
 *		    success
 * @return The data to repeat the send with or nil if it should not repeat
 */
typedef OFData *_Nullable (^OFSequencedPacketSocketAsyncSendDataBlock)(
    OFData *_Nonnull data, id _Nullable exception);
    id _Nullable exception);

/**
 * @brief A block which is called when the socket accepted a connection.
 *
 * @param acceptedSocket The socket which has been accepted
 * @param exception An exception which occurred while accepting the socket or
 *		    `nil` on success
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
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
172
173
174
175
176
177
178


179
180
181
182
183
184
185
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.
 *
245
246
247
248
249
250
251


252
253
254
255
256
257
258
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
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
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;
351
352
353
354
355
356
357


358
359
360
361
362
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 [da50d869cb] to [a8c0e899a1].

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
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







-
+
-






+
+
+
+





-
+







-
+







-
+














-
+
+







				  errNo: OFSocketErrNo()];

	_listening = true;
}

- (instancetype)accept
{
	OFSequencedPacketSocket *client =
	OFSequencedPacketSocket *client;
	    [[[[self class] alloc] init] autorelease];
#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,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr *)&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
	    OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
	if ((client->_socket = accept4(_socket,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr *)&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length, SOCK_CLOEXEC)) ==
	    OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];
#else
	if ((client->_socket = accept(_socket,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr *)&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length)) == OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];

# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
		fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif

	assert(client->_remoteAddress.length <=
	    (socklen_t)sizeof(client->_remoteAddress.sockaddr));

	switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) {
	switch (((struct sockaddr *)&client->_remoteAddress.sockaddr)
	    ->sa_family) {
	case AF_INET:
		client->_remoteAddress.family = OFSocketAddressFamilyIPv4;
		break;
#ifdef OF_HAVE_IPV6
	case AF_INET6:
		client->_remoteAddress.family = OFSocketAddressFamilyIPv6;
		break;

Modified src/OFSerialization.h from [6913e132ee] to [6c8c4c9563].

32
33
34
35
36
37
38


39
40
41
42
43
44
45
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/OFSet.h from [d5a622be48] to [4c0dd3a76f].

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
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







-
-
-
-
-
-
-
-
-
-











+
+
+
+
+
+
+
+
+
+







 * @brief Initializes an already allocated set with the specified objects.
 *
 * @param firstObject The first object for the set
 * @return An initialized set with the specified objects
 */
- (instancetype)initWithObjects: (ObjectType)firstObject, ... OF_SENTINEL;

/**
 * @brief Initializes an already allocated set with the specified objects.
 *
 * @param objects An array of objects for the set
 * @param count The number of objects in the specified array
 * @return An initialized set with the specified objects
 */
- (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
			  count: (size_t)count;

/**
 * @brief Initializes an already allocated set with the specified object and
 *	  va_list.
 *
 * @param firstObject The first object for the set
 * @param arguments A va_list with the other objects
 * @return An initialized set with the specified object and va_list
 */
- (instancetype)initWithObject: (ObjectType)firstObject
		     arguments: (va_list)arguments;

/**
 * @brief Initializes an already allocated set with the specified objects.
 *
 * @param objects An array of objects for the set
 * @param count The number of objects in the specified array
 * @return An initialized set with the specified objects
 */
- (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects
			  count: (size_t)count;

/**
 * @brief Returns an OFEnumerator to enumerate through all objects of the set.
 *
 * @return An OFEnumerator to enumerate through all objects of the set
 */
- (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator;

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
182
183
184
185
186
187
188


















189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-






-
+







 *	  object in common.
 *
 * @return Whether the receiver and the specified set have at least one object
 *	   in common
 */
- (bool)intersectsSet: (OFSet OF_GENERIC(ObjectType) *)set;

/**
 * @brief Creates a new set which contains the objects which are in the
 *	  receiver, but not in the specified set.
 *
 * @param set The set whose objects will not be in the new set
 */
- (OFSet OF_GENERIC(ObjectType) *)setBySubtractingSet:
    (OFSet OF_GENERIC(ObjectType) *)set;

/**
 * @brief Creates a new set by creating the intersection of the receiver and
 *	  the specified set.
 *
 * @param set The set to intersect with
 */
- (OFSet OF_GENERIC(ObjectType) *)setByIntersectingWithSet:
    (OFSet OF_GENERIC(ObjectType) *)set;

/**
 * @brief Creates a new set by creating the union of the receiver and the
 *	  specified set.
 *
 * @param set The set to create the union with
 */
- (OFSet OF_GENERIC(ObjectType) *)setByAddingSet:
- (OFSet OF_GENERIC(ObjectType) *)setByAddingObjectsFromSet:
    (OFSet OF_GENERIC(ObjectType) *)set;

/**
 * @brief Checks whether the set contains an object equal to the specified
 *	  object.
 *
 * @param object The object which is checked for being in the set

Modified src/OFSet.m from [deacc26990] to [c2dcb9f429].

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
383
384
385
386
387
388
389

















390
391
392
393
394
395
396
397







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+







	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFSet *)setBySubtractingSet: (OFSet *)set
{
	OFMutableSet *new = [[self mutableCopy] autorelease];
	[new minusSet: set];
	[new makeImmutable];
	return new;
}

- (OFSet *)setByIntersectingWithSet: (OFSet *)set
{
	OFMutableSet *new = [[self mutableCopy] autorelease];
	[new intersectSet: set];
	[new makeImmutable];
	return new;
}

- (OFSet *)setByAddingSet: (OFSet *)set
- (OFSet *)setByAddingObjectsFromSet: (OFSet *)set
{
	OFMutableSet *new = [[self mutableCopy] autorelease];
	[new unionSet: set];
	[new makeImmutable];
	return new;
}

Modified src/OFSettings.m from [020bd4039a] to [206814d076].

44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59







-

+







- (instancetype)initWithApplicationName: (OFString *)applicationName
{
	self = [super init];

	@try {
		_applicationName = [applicationName copy];
	} @catch (id e) {
		@throw e;
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{

Modified src/OFSocket.h from [fb1a5b55eb] to [6ae41ef6ce].

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
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







-
-
-
-
+
+
+
+















+
+
+
+
+
+
+



















-
-
-
-
-
-
-






+

-
+
-
-
-
-
+

-

-


-
-
+
+














+









+









+



-
-
-
-
-
-
-
-
-
-
-
-








+
+
+
+
+
+
+
+
+
+
+







typedef enum {
	/** An unknown address family. */
	OFSocketAddressFamilyUnknown,
	/** IPv4 */
	OFSocketAddressFamilyIPv4,
	/** IPv6 */
	OFSocketAddressFamilyIPv6,
	/** IPX */
	OFSocketAddressFamilyIPX,
	/** UNIX */
	OFSocketAddressFamilyUNIX,
	/** UNIX */
	OFSocketAddressFamilyUNIX,
	/** IPX */
	OFSocketAddressFamilyIPX,
	/** Any address family */
	OFSocketAddressFamilyAny = 255
} OFSocketAddressFamily;

#ifndef OF_HAVE_IPV6
struct sockaddr_in6 {
	sa_family_t sin6_family;
	in_port_t sin6_port;
	uint32_t sin6_flowinfo;
	struct in6_addr {
		uint8_t s6_addr[16];
	} sin6_addr;
	uint32_t sin6_scope_id;
};
#endif

#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT)
struct sockaddr_un {
	sa_family_t sun_family;
	char sun_path[108];
};
#endif

#ifndef OF_HAVE_IPX
# define IPX_NODE_LEN 6
struct sockaddr_ipx {
	sa_family_t sipx_family;
	uint32_t sipx_network;
	unsigned char sipx_node[IPX_NODE_LEN];
	uint16_t sipx_port;
	uint8_t sipx_type;
};
#endif
#ifdef OF_WINDOWS
# define IPX_NODE_LEN 6
# define sipx_family sa_family
# define sipx_network sa_netnum
# define sipx_node sa_nodenum
# define sipx_port sa_socket
#endif

#if !defined(OF_HAVE_UNIX_SOCKETS) && !defined(OF_MORPHOS) && !defined(OF_MINT)
struct sockaddr_un {
	sa_family_t sun_family;
	char sun_path[108];
};
#endif

/**
 * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h
 *
 * @brief A struct which represents a host / port pair for a socket.
 */
typedef struct OF_BOXABLE {
	OFSocketAddressFamily family;
	/*
	 * Even though struct sockaddr contains the family, we need to use our
	 * We can't use struct sockaddr as it can contain variable length
	 * own family, as we need to support storing an IPv6 address on systems
	 * that don't support IPv6. These may not have AF_INET6 defined and we
	 * can't just define it, as the value is system-dependent and might
	 * clash with an existing value.
	 * arrays.
	 */
	OFSocketAddressFamily family;
	union {
		struct sockaddr sockaddr;
		struct sockaddr_in in;
		struct sockaddr_in6 in6;
		struct sockaddr_ipx ipx;
		struct sockaddr_un un;
		struct sockaddr_un un;
		struct sockaddr_ipx ipx;
	} sockaddr;
	socklen_t length;
} OFSocketAddress;

#ifdef __cplusplus
extern "C" {
#endif
/**
 * @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 an IPX address for the specified node, network and port.
 *
 * @param node The node in the IPX network
 * @param network The IPX network
 * @param port The IPX port (sometimes called socket number) on the node
 * @return An IPX socket address with the specified node, network and port.
 */
extern OFSocketAddress OFSocketAddressMakeIPX(
    const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network,
    uint16_t port);

/**
 * @brief Creates a UNIX socket address from the specified path.
 *
 * @param path The path of the UNIX socket
 * @return A UNIX socket address with the specified path
 */
extern OFSocketAddress OFSocketAddressMakeUNIX(OFString *path);

/**
 * @brief Creates an IPX address for the specified node, network and port.
 *
 * @param network The IPX network
 * @param node The node in the IPX network
 * @param port The IPX port (sometimes called socket number) on the node
 * @return An IPX socket address with the specified node, network and port.
 */
extern OFSocketAddress OFSocketAddressMakeIPX(uint32_t network,
    const unsigned char node[_Nonnull IPX_NODE_LEN], uint16_t port);

/**
 * @brief Compares two OFSocketAddress for equality.
 *
 * @param address1 The address to compare with the second address
 * @param address2 The second address
 * @return Whether the two addresses are equal
 */
262
263
264
265
266
267
268









269
270
271
272
273
274
275
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282







+
+
+
+
+
+
+
+
+







 *	  the address family used.
 *
 * @param address The address on which to get the port
 * @return The port of the address
 */
extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address);

/**
 * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress.
 *
 * @param address The address on which to get the UNIX socket path
 * @return The UNIX socket path
 */
extern OFString *_Nullable OFSocketAddressUNIXPath(
    const OFSocketAddress *_Nonnull address);

/**
 * @brief Sets the IPX network of the specified @ref OFSocketAddress.
 *
 * @param address The address on which to set the IPX network
 * @param network The IPX network to set on the address
 */
extern void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address,
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
305
306
307
308
309
310
311









312
313
314
315
316
317
318







-
-
-
-
-
-
-
-
-







 *
 * @param address The address on which to get the IPX node
 * @param node A byte array to store the IPX node of the address
 */
extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address,
    unsigned char node[_Nonnull IPX_NODE_LEN]);

/**
 * @brief Gets the UNIX socket path of the specified @ref OFSocketAddress.
 *
 * @param address The address on which to get the UNIX socket path
 * @return The UNIX socket path
 */
extern OFString *_Nullable OFSocketAddressUNIXPath(
    const OFSocketAddress *_Nonnull address);

extern bool OFSocketInit(void);
#if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS)
extern void OFSocketDeinit(void);
#endif
extern int OFSocketErrNo(void);
#if !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
extern int OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr,

Modified src/OFSocket.m from [8f11763ca5] to [65b91d8086].

52
53
54
55
56
57
58






59
60
61
62
63
64
65
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71







+
+
+
+
+
+







# include <proto/exec.h>
#endif

#ifdef OF_NINTENDO_3DS
# include <3ds/types.h>
# include <3ds/services/soc.h>
#endif

#ifdef OF_NINTENDO_SWITCH
# define id nx_id
# include <switch.h>
# undef id
#endif

#if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS))
static OFMutex *mutex;

static void
releaseMutex(void)
{
126
127
128
129
130
131
132





133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148





149
150
151
152
153
154
155







+
+
+
+
+





-
-
-
-
-







	if ((ctx = memalign(0x1000, 0x100000)) == NULL)
		return;

	if (socInit(ctx, 0x100000) != 0)
		return;

	atexit((void (*)(void))socExit);
# elif defined(OF_NINTENDO_SWITCH)
	if (R_FAILED(socketInitializeDefault()))
		return;

	atexit(socketExit);
# endif

# if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS))
	mutex = [[OFMutex alloc] init];
	atexit(releaseMutex);

#  ifdef OF_WII
	if (OFSpinlockNew(&spinlock) != 0)
		return;
#  endif
# endif

	initSuccessful = true;
}

OF_DESTRUCTOR()
{
224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
230
231
232
233
234
235
236

237
238
239
240
241
242
243
244







-
+







# endif
	if (socketBase != NULL)
		CloseLibrary(socketBase);
}
#endif

int
OFSocketErrNo()
OFSocketErrNo(void)
{
#if defined(OF_WINDOWS)
	switch (WSAGetLastError()) {
	case WSAEACCES:
		return EACCES;
	case WSAEADDRINUSE:
		return EADDRINUSE;
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
516
517
518
519
520
521
522
























523
524
525
526
527
528
529







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







	} @catch (OFInvalidFormatException *e) {
		ret = OFSocketAddressParseIPv4(IP, port);
	}

	return ret;
}

OFSocketAddress
OFSocketAddressMakeIPX(const unsigned char node[IPX_NODE_LEN], uint32_t network,
    uint16_t port)
{
	OFSocketAddress ret;

	memset(&ret, '\0', sizeof(ret));
	ret.family = OFSocketAddressFamilyIPX;
	ret.length = sizeof(ret.sockaddr.ipx);

#ifdef AF_IPX
	ret.sockaddr.ipx.sipx_family = AF_IPX;
#else
	ret.sockaddr.ipx.sipx_family = AF_UNSPEC;
#endif
	memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN);
	network = OFToBigEndian32(network);
	memcpy(&ret.sockaddr.ipx.sipx_network, &network,
	    sizeof(ret.sockaddr.ipx.sipx_network));
	ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port);

	return ret;
}

OFSocketAddress
OFSocketAddressMakeUNIX(OFString *path)
{
	void *pool = objc_autoreleasePoolPush();
	OFStringEncoding encoding = [OFLocale encoding];
	size_t length = [path cStringLengthWithEncoding: encoding];
	OFSocketAddress ret;
560
561
562
563
564
565
566
























567
568
569
570
571
572
573
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	ret.sockaddr.un.sun_family = AF_UNSPEC;
#endif
	memcpy(ret.sockaddr.un.sun_path,
	    [path cStringWithEncoding: encoding], length);

	objc_autoreleasePoolPop(pool);

	return ret;
}

OFSocketAddress
OFSocketAddressMakeIPX(uint32_t network, const unsigned char node[IPX_NODE_LEN],
    uint16_t port)
{
	OFSocketAddress ret;

	memset(&ret, '\0', sizeof(ret));
	ret.family = OFSocketAddressFamilyIPX;
	ret.length = sizeof(ret.sockaddr.ipx);

#ifdef AF_IPX
	ret.sockaddr.ipx.sipx_family = AF_IPX;
#else
	ret.sockaddr.ipx.sipx_family = AF_UNSPEC;
#endif
	network = OFToBigEndian32(network);
	memcpy(&ret.sockaddr.ipx.sipx_network, &network,
	    sizeof(ret.sockaddr.ipx.sipx_network));
	memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN);
	ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port);

	return ret;
}

bool
OFSocketAddressEqual(const OFSocketAddress *address1,
    const OFSocketAddress *address2)
{
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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-











-
+











-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
-
+
+



-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







			return false;
		if (memcmp(addrIn6_1->sin6_addr.s6_addr,
		    addrIn6_2->sin6_addr.s6_addr,
		    sizeof(addrIn6_1->sin6_addr.s6_addr)) != 0)
			return false;

		return true;
	case OFSocketAddressFamilyUNIX:
		pool = objc_autoreleasePoolPush();

		path1 = OFSocketAddressUNIXPath(address1);
		path2 = OFSocketAddressUNIXPath(address2);

		if (path1 == nil || path2 == nil) {
			objc_autoreleasePoolPop(pool);

			return false;
		}

		ret = [path1 isEqual: path2];

		objc_autoreleasePoolPop(pool);

		return ret;
	case OFSocketAddressFamilyIPX:
		if (address1->length < (socklen_t)sizeof(struct sockaddr_ipx) ||
		    address2->length < (socklen_t)sizeof(struct sockaddr_ipx))
			@throw [OFInvalidArgumentException exception];

		addrIPX1 = &address1->sockaddr.ipx;
		addrIPX2 = &address2->sockaddr.ipx;

		if (addrIPX1->sipx_port != addrIPX2->sipx_port)
			return false;
		if (memcmp(&addrIPX1->sipx_network, &addrIPX2->sipx_network,
		    4) != 0)
			return false;
		if (memcmp(addrIPX1->sipx_node, addrIPX2->sipx_node,
		    IPX_NODE_LEN) != 0)
			return false;

		return true;
	case OFSocketAddressFamilyUNIX:
		pool = objc_autoreleasePoolPush();

		path1 = OFSocketAddressUNIXPath(address1);
		path2 = OFSocketAddressUNIXPath(address2);

		if (path1 == nil || path2 == nil) {
			objc_autoreleasePoolPop(pool);

			return false;
		}

		ret = [path1 isEqual: path2];

		objc_autoreleasePoolPop(pool);

		return ret;
	default:
		@throw [OFInvalidArgumentException exception];
	}
}

unsigned long
OFSocketAddressHash(const OFSocketAddress *address)
{
	unsigned long hash;

	OFHashInit(&hash);
	OFHashAdd(&hash, address->family);
	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

		OFHashAdd(&hash, address->sockaddr.in.sin_port >> 8);
		OFHashAdd(&hash, address->sockaddr.in.sin_port);
		OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 24);
		OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 16);
		OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 8);
		OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr);
		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];

		OFHashAdd(&hash, address->sockaddr.in6.sin6_port >> 8);
		OFHashAdd(&hash, address->sockaddr.in6.sin6_port);
		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++)
			OFHashAdd(&hash,
			OFHashAddByte(&hash,
			    address->sockaddr.in6.sin6_addr.s6_addr[i]);

		break;
	case OFSocketAddressFamilyIPX:;
		unsigned char network[
		    sizeof(address->sockaddr.ipx.sipx_network)];

		if (address->length < (socklen_t)sizeof(struct sockaddr_ipx))
			@throw [OFInvalidArgumentException exception];

		OFHashAdd(&hash, address->sockaddr.ipx.sipx_port >> 8);
		OFHashAdd(&hash, address->sockaddr.ipx.sipx_port);

		memcpy(network, &address->sockaddr.ipx.sipx_network,
		    sizeof(network));

		for (size_t i = 0; i < sizeof(network); i++)
			OFHashAdd(&hash, network[i]);

		for (size_t i = 0; i < IPX_NODE_LEN; i++)
			OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[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);

	return hash;
856
857
858
859
860
861
862






















863
864
865
866
867
868
869
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		return OFFromBigEndian16(address->sockaddr.in6.sin6_port);
	case OFSocketAddressFamilyIPX:
		return OFFromBigEndian16(address->sockaddr.ipx.sipx_port);
	default:
		@throw [OFInvalidArgumentException exception];
	}
}

OFString *
OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address)
{
	socklen_t length;

	if (address->family != OFSocketAddressFamilyUNIX)
		@throw [OFInvalidArgumentException exception];

	length = address->length - offsetof(struct sockaddr_un, sun_path);

	for (socklen_t i = 0; i < length; i++)
		if (address->sockaddr.un.sun_path[i] == 0)
			length = i;

	if (length <= 0)
		return nil;

	return [OFString stringWithCString: address->sockaddr.un.sun_path
				  encoding: [OFLocale encoding]
				    length: length];
}

void
OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network)
{
	if (address->family != OFSocketAddressFamilyIPX)
		@throw [OFInvalidArgumentException exception];

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
931
932
933
934
935
936
937





























-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
    unsigned char node[IPX_NODE_LEN])
{
	if (address->family != OFSocketAddressFamilyIPX)
		@throw [OFInvalidArgumentException exception];

	memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN);
}

OFString *
OFSocketAddressUNIXPath(const OFSocketAddress *_Nonnull address)
{
	socklen_t length;

	if (address->family != OFSocketAddressFamilyUNIX)
		@throw [OFInvalidArgumentException exception];

	length = address->length - offsetof(struct sockaddr_un, sun_path);

	for (socklen_t i = 0; i < length; i++)
		if (address->sockaddr.un.sun_path[i] == 0)
			length = i;

	if (length <= 0)
		return nil;

	return [OFString stringWithCString: address->sockaddr.un.sun_path
				  encoding: [OFLocale encoding]
				    length: length];
}

Modified src/OFStdIOStream+Private.h from [689e88ea63] to [9900a9e7b0].

15
16
17
18
19
20
21
22
23





24
25

26
27
28
29
30
15
16
17
18
19
20
21


22
23
24
25
26
27

28

29
30
31
32







-
-
+
+
+
+
+

-
+
-





#import "OFStdIOStream.h"

OF_ASSUME_NONNULL_BEGIN

OF_DIRECT_MEMBERS
@interface OFStdIOStream ()
#ifndef OF_AMIGAOS
- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init);
#if defined(OF_AMIGAOS)
- (instancetype)of_initWithHandle: (BPTR)handle
			 closable: (bool)closable OF_METHOD_FAMILY(init);
#elif defined(OF_WII_U)
- (instancetype)of_init OF_METHOD_FAMILY(init);
#else
- (instancetype)of_initWithHandle: (BPTR)handle
- (instancetype)of_initWithFileDescriptor: (int)fd OF_METHOD_FAMILY(init);
			 closable: (bool)closable OF_METHOD_FAMILY(init);
#endif
@end

OF_ASSUME_NONNULL_END

Modified src/OFStdIOStream.h from [fc2f501857] to [2dc46172ae].

34
35
36
37
38
39
40
41

42
43
44
45

46
47
48
49


50
51
52
53
54
55
56
34
35
36
37
38
39
40

41
42
43
44

45


46
47
48
49
50
51
52
53
54
55
56







-
+



-
+
-
-


+
+







 * The global variables @ref OFStdIn, @ref OFStdOut and @ref OFStdErr are
 * instances of this class and need no initialization.
 */
#ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H
OF_SUBCLASSING_RESTRICTED
#endif
@interface OFStdIOStream: OFStream
#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)
#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U)
    <OFReadyForReadingObserving, OFReadyForWritingObserving>
#endif
{
#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
	int _fd;
#else
	BPTR _handle;
	bool _closable;
#elif !defined(OF_WII_U)
	int _fd;
#endif
	bool _atEndOfStream;
}

/**
 * @brief Whether there is an underlying terminal.
 */

Modified src/OFStdIOStream.m from [f006bf536d] to [ef45e21ee6].

47
48
49
50
51
52
53






54
55
56
57
58
59
60
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66







+
+
+
+
+
+







#endif

#ifdef OF_AMIGAOS
# include <proto/exec.h>
# include <proto/dos.h>
# undef HAVE_ISATTY
#endif

#ifdef OF_WII_U
# define BOOL WUT_BOOL
# include <coreinit/debug.h>
# undef BOOL
#endif

/* References for static linking */
#ifdef OF_WINDOWS
void
_reference_to_OFWin32ConsoleStdIOStream(void)
{
	[OFWin32ConsoleStdIOStream class];
104
105
106
107
108
109
110
111

112
113
114
115
116
117
118
110
111
112
113
114
115
116

117
118
119
120
121
122
123
124







-
+








	[OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString,
			       date.microsecond / 1000, me, getpid(), msg];

	objc_autoreleasePoolPop(pool);
}

#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
static int
colorToANSI(OFColor *color)
{
	if ([color isEqual: [OFColor black]])
		return 30;
	if ([color isEqual: [OFColor maroon]])
		return 31;
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
158
159
160
161
162
163
164

165











166
167
168
169
170
171
172







-
+
-
-
-
-
-
-
-
-
-
-
-







@implementation OFStdIOStream
#ifndef OF_WINDOWS
+ (void)load
{
	if (self != [OFStdIOStream class])
		return;

# ifndef OF_AMIGAOS
# if defined(OF_AMIGAOS)
	int fd;

	if ((fd = fileno(stdin)) >= 0)
		OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd];
	if ((fd = fileno(stdout)) >= 0)
		OFStdOut = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
	if ((fd = fileno(stderr)) >= 0)
		OFStdErr = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
# else
	BPTR input, output, error;
	bool inputClosable = false, outputClosable = false,
	    errorClosable = false;

	input = Input();
	output = Output();
	error = ((struct Process *)FindTask(NULL))->pr_CES;
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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
+
-
-
-
-
-
-
-
-
-









+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+
+
+
+

-
+
-

-






-
+
-
-

+
+
-
+

+






+


+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

















-
-
-
-
-
-
-
-
-
-
-
-





+




-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








	OFStdIn = [[OFStdIOStream alloc] of_initWithHandle: input
						  closable: inputClosable];
	OFStdOut = [[OFStdIOStream alloc] of_initWithHandle: output
						   closable: outputClosable];
	OFStdErr = [[OFStdIOStream alloc] of_initWithHandle: error
						   closable: errorClosable];
# elif defined(OF_WII_U)
	OFStdOut = [[OFStdIOStream alloc] of_init];
	OFStdErr = [[OFStdIOStream alloc] of_init];
# else
	int fd;

	if ((fd = fileno(stdin)) >= 0)
		OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd];
	if ((fd = fileno(stdout)) >= 0)
		OFStdOut = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
	if ((fd = fileno(stderr)) >= 0)
		OFStdErr = [[OFStdIOStream alloc]
		    of_initWithFileDescriptor: fd];
# endif
}
#endif

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
- (instancetype)of_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;
}
#else
- (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable
{
	self = [super init];

	_handle = handle;
	_closable = closable;

	return self;
}
#elif defined(OF_WII_U)
- (instancetype)of_init
{
	return [super init];
}
#else
- (instancetype)of_initWithFileDescriptor: (int)fd
{
	self = [super init];

	_fd = fd;

	return self;
}
#endif

- (void)dealloc
{
#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
	if (_handle != 0)
		[self close];
#elif !defined(OF_WII_U)
	if (_fd != -1)
#else
		[self close];
	if (_handle != 0)
#endif
		[self close];

	[super dealloc];
}

- (bool)lowlevelIsAtEndOfStream
{
#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
	if (_fd == -1)
#else
	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];
#elif !defined(OF_WII_U)
#endif
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];
#endif

	return _atEndOfStream;
}

- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
{
#if defined(OF_AMIGAOS)
	ssize_t ret;

	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];
#ifndef OF_AMIGAOS

	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = Read(_handle, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: EIO];

	if (ret == 0)
		_atEndOfStream = true;

	return ret;
#elif defined(OF_WII_U)
	@throw [OFReadFailedException exceptionWithObject: self
					  requestedLength: length
						    errNo: EOPNOTSUPP];
#else
	ssize_t ret;

	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

# ifndef OF_WINDOWS
	if ((ret = read(_fd, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: errno];
# else
	if (length > UINT_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = read(_fd, buffer, (unsigned int)length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: errno];
# endif
#else
	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (length > LONG_MAX)
		@throw [OFOutOfRangeException exception];

	if ((ret = Read(_handle, buffer, length)) < 0)
		@throw [OFReadFailedException exceptionWithObject: self
						  requestedLength: length
							    errNo: EIO];
#endif

	if (ret == 0)
		_atEndOfStream = true;

	return ret;
#endif
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
{
#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
	LONG bytesWritten;

	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
						      bytesWritten: 0
							     errNo: EIO];

	return (size_t)bytesWritten;
#elif defined(OF_WII_U)
	OSConsoleWrite(buffer, length);

	return length;
#else
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

# ifndef OF_WINDOWS
	ssize_t bytesWritten;

	if (length > SSIZE_MAX)
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
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







-
-

-
-
-
-
-
-
-
-
-
-
+
-

-
+
-
-
+
-
-
+













-
+
-
-
-
-
-
-







+
+
+
+
+
+








	if ((bytesWritten = write(_fd, buffer, (int)length)) < 0)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
						      bytesWritten: 0
							     errNo: errno];
# endif
#else
	LONG bytesWritten;

	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (length > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if ((bytesWritten = Write(_handle, (void *)buffer, length)) < 0)
		@throw [OFWriteFailedException exceptionWithObject: self
						   requestedLength: length
						      bytesWritten: 0
	return (size_t)bytesWritten;
							     errNo: EIO];
#endif

}
	return (size_t)bytesWritten;
}


#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)
#if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && !defined(OF_WII_U)
- (int)fileDescriptorForReading
{
	return _fd;
}

- (int)fileDescriptorForWriting
{
	return _fd;
}
#endif

- (void)close
{
#ifndef OF_AMIGAOS
#if defined(OF_AMIGAOS)
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

	close(_fd);
	_fd = -1;
#else
	if (_handle == 0)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_closable)
		Close(_handle);

	_handle = 0;
#elif !defined(OF_WII_U)
	if (_fd == -1)
		@throw [OFNotOpenException exceptionWithObject: self];

	close(_fd);
	_fd = -1;
#endif

	[super close];
}

- (instancetype)autorelease
{
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
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







-
+








-
+
+













-
+
+













-
+














-
+














-
+









-
+









-
+









-
+












-
+










-
+







- (unsigned int)retainCount
{
	return OFMaxRetainCount;
}

- (bool)hasTerminal
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	return isatty(_fd);
#else
	return false;
#endif
}

- (int)columns
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS)
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \
    !defined(OF_AMIGAOS) && !defined(OF_WII_U)
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_col;
#else
	return -1;
#endif
}

- (int)rows
{
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && !defined(OF_AMIGAOS)
#if defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ) && \
    !defined(OF_AMIGAOS) && !defined(OF_WII_U)
	struct winsize ws;

	if (ioctl(_fd, TIOCGWINSZ, &ws) != 0)
		return -1;

	return ws.ws_row;
#else
	return -1;
#endif
}

- (void)setForegroundColor: (OFColor *)color
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	int code;

	if (!isatty(_fd))
		return;

	if ((code = colorToANSI(color)) == -1)
		return;

	[self writeFormat: @"\033[%um", code];
#endif
}

- (void)setBackgroundColor: (OFColor *)color
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	int code;

	if (!isatty(_fd))
		return;

	if ((code = colorToANSI(color)) == -1)
		return;

	[self writeFormat: @"\033[%um", code + 10];
#endif
}

- (void)reset
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[0m"];
#endif
}

- (void)clear
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[2J"];
#endif
}

- (void)eraseLine
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	[self writeString: @"\033[2K"];
#endif
}

- (void)setCursorColumn: (unsigned int)column
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%uG", column + 1];
#endif
}

- (void)setCursorPosition: (OFPoint)position
{
	if (position.x < 0 || position.y < 0)
		@throw [OFInvalidArgumentException exception];

#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	[self writeFormat: @"\033[%u;%uH",
			   (unsigned)position.y + 1, (unsigned)position.x + 1];
#endif
}

- (void)setRelativeCursorPosition: (OFPoint)position
{
#ifdef HAVE_ISATTY
#if defined(HAVE_ISATTY) && !defined(OF_WII_U)
	if (!isatty(_fd))
		return;

	if (position.x > 0)
		[self writeFormat: @"\033[%uC", (unsigned)position.x];
	else if (position.x < 0)
		[self writeFormat: @"\033[%uD", (unsigned)-position.x];

Modified src/OFStream.h from [b3e894dafd] to [a93512463b].

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
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







-







-
-
+
+





-








-
+







typedef bool (^OFStreamAsyncReadLineBlock)(OFString *_Nullable line,
    id _Nullable exception);

/**
 * @brief A block which is called when data was written asynchronously to a
 *	  stream.
 *
 * @param data The data which was written to the stream
 * @param bytesWritten The number of bytes which have been written. This
 *		       matches the length of the specified data on the
 *		       asynchronous write if no exception was encountered.
 * @param exception An exception which occurred while writing or `nil` on
 *		    success
 * @return The data to repeat the write with or nil if it should not repeat
 */
typedef OFData *_Nullable (^OFStreamAsyncWriteDataBlock)(OFData *_Nonnull data,
    size_t bytesWritten, id _Nullable exception);
typedef OFData *_Nullable (^OFStreamAsyncWriteDataBlock)(size_t bytesWritten,
    id _Nullable exception);

/**
 * @brief A block which is called when a string was written asynchronously to a
 *	  stream.
 *
 * @param string The string which was written to the stream
 * @param bytesWritten The number of bytes which have been written. This
 *		       matches the length of the specified data on the
 *		       asynchronous write if no exception was encountered.
 * @param exception An exception which occurred while writing or `nil` on
 *		    success
 * @return The string to repeat the write with or nil if it should not repeat
 */
typedef OFString *_Nullable (^OFStreamAsyncWriteStringBlock)(
    OFString *_Nonnull string, size_t bytesWritten, id _Nullable exception);
    size_t bytesWritten, id _Nullable exception);
#endif

/**
 * @protocol OFStreamDelegate OFStream.h ObjFW/OFStream.h
 *
 * A delegate for OFStream.
 */
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
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* size bytes from the stream into a buffer.
 * @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
 * @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* size bytes from the stream into a
 * @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
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
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* size bytes from the stream into a
 * @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
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
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
 * @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
 * @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.
 *
351
352
353
354
355
356
357
358
359


360
361
362
363
364
365
366
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 size bytes from the stream into a
 *	  buffer.
 * @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
380
381
382
383
384
385
386
387

388
389
390
391
392
393
394
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* ref size bytes from the stream into a
 * @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
411
412
413
414
415
416
417
418

419
420
421
422
423
424
425
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
 * @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.
 *
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
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
 * @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.
 *
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
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.
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
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 *)readTillDelimiter: (OFString *)delimiter;
- (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 *)readTillDelimiter: (OFString *)delimiter
				encoding: (OFStringEncoding)encoding;
- (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 readTillDelimiter:) and returns `nil` if not
 *	  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 *)tryReadTillDelimiter: (OFString *)delimiter;
- (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 readTillDelimiter:encoding:) and returns
 *	  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 *)tryReadTillDelimiter: (OFString *)delimiter
				   encoding: (OFStringEncoding)encoding;
- (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.
834
835
836
837
838
839
840


841
842
843
844
845
846
847
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.
 *
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
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.
 */
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
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
677
678


679
680
681
682
683
684
685
670
671
672
673
674
675
676


677
678
679
680
681
682
683
684
685







-
-
+
+







#endif

- (OFString *)tryReadLine
{
	return [self tryReadLineWithEncoding: OFStringEncodingUTF8];
}

- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
			  encoding: (OFStringEncoding)encoding
- (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
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
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 *)readTillDelimiter: (OFString *)delimiter
- (OFString *)readUntilDelimiter: (OFString *)delimiter
{
	return [self readTillDelimiter: delimiter
			      encoding: OFStringEncodingUTF8];
	return [self readUntilDelimiter: delimiter
			       encoding: OFStringEncodingUTF8];
}

- (OFString *)readTillDelimiter: (OFString *)delimiter
		       encoding: (OFStringEncoding)encoding
- (OFString *)readUntilDelimiter: (OFString *)delimiter
			encoding: (OFStringEncoding)encoding
{
	OFString *ret = nil;

	while ((ret = [self tryReadTillDelimiter: delimiter
					encoding: encoding]) == nil)
	while ((ret = [self tryReadUntilDelimiter: delimiter
					 encoding: encoding]) == nil)
		if (self.atEndOfStream)
			return nil;

	return ret;
}

- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
- (OFString *)tryReadUntilDelimiter: (OFString *)delimiter
{
	return [self tryReadTillDelimiter: delimiter
				 encoding: OFStringEncodingUTF8];
	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
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
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/OFStreamSocket.m from [f14a71e66a] to [6c817945cd].

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
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







-
+







-
+







-
+














-
+
+








-
-
-
-
-




+
+
+
+
+







#endif

	client->_remoteAddress.length =
	    (socklen_t)sizeof(client->_remoteAddress.sockaddr);

#if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC)
	if ((client->_socket = paccept(_socket,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr *)&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) ==
	    OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];
#elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
	if ((client->_socket = accept4(_socket,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr * )&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length, SOCK_CLOEXEC)) ==
	    OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];
#else
	if ((client->_socket = accept(_socket,
	    &client->_remoteAddress.sockaddr.sockaddr,
	    (struct sockaddr *)&client->_remoteAddress.sockaddr,
	    &client->_remoteAddress.length)) == OFInvalidSocketHandle)
		@throw [OFAcceptFailedException
		    exceptionWithSocket: self
				  errNo: OFSocketErrNo()];

# if defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1)
		fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC);
# endif
#endif

	assert(client->_remoteAddress.length <=
	    (socklen_t)sizeof(client->_remoteAddress.sockaddr));

	switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) {
	switch (((struct sockaddr *)&client->_remoteAddress.sockaddr)
	    ->sa_family) {
	case AF_INET:
		client->_remoteAddress.family = OFSocketAddressFamilyIPv4;
		break;
#ifdef OF_HAVE_IPV6
	case AF_INET6:
		client->_remoteAddress.family = OFSocketAddressFamilyIPv6;
		break;
#endif
#ifdef OF_HAVE_IPX
	case AF_IPX:
		client->_remoteAddress.family = OFSocketAddressFamilyIPX;
		break;
#endif
#ifdef OF_HAVE_UNIX_SOCKETS
	case AF_UNIX:
		client->_remoteAddress.family = OFSocketAddressFamilyUNIX;
		break;
#endif
#ifdef OF_HAVE_IPX
	case AF_IPX:
		client->_remoteAddress.family = OFSocketAddressFamilyIPX;
		break;
#endif
	default:
		client->_remoteAddress.family = OFSocketAddressFamilyUnknown;
		break;
	}

	return client;

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
63
64

65
66
67
68
69
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 [c69c663e20] to [01351c2d45].

73
74
75
76
77
78
79








80
81
82
83
84
85





86
87
88
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 Creates a new string by appending a path component.
 *
 * @param component The path component to append
 * @return A new, autoreleased OFString with the path component appended
 */
- (OFString *)stringByAppendingPathComponent: (OFString *)component;

/**
 * @brief Creates a new string by appending a path extension.
 *
 * @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_pathToURLPathWithURLEncodedHost:
    (OFString *__autoreleasing _Nullable *_Nonnull)URLEncodedHost;
- (OFString *)of_URLPathToPathWithURLEncodedHost:
    (nullable OFString *)URLEncodedHost;
- (OFString *)of_pathComponentToURLPathComponent;
- (OFString *)of_pathToURIPathWithPercentEncodedHost:
    (OFString *__autoreleasing _Nullable *_Nonnull)percentEncodedHost;
- (OFString *)of_URIPathToPathWithPercentEncodedHost:
    (nullable OFString *)percentEncodedHost;
- (OFString *)of_pathComponentToURIPathComponent;
@end

OF_ASSUME_NONNULL_END

Modified src/OFString+PathAdditions.m from [422d7384b5] to [dfeb40c068].

17
18
19
20
21
22
23
24


25
26
27
28
17
18
19
20
21
22
23

24
25
26
27
28
29







-
+
+





#include "platform.h"

#if defined(OF_WINDOWS) || defined(OF_MSDOS) || defined(OF_MINT)
# import "platform/Windows/OFString+PathAdditions.m"
#elif defined(OF_AMIGAOS)
# import "platform/AmigaOS/OFString+PathAdditions.m"
#elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
#elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
# import "platform/libfat/OFString+PathAdditions.m"
#else
# import "platform/POSIX/OFString+PathAdditions.m"
#endif

Renamed and modified src/OFString+URLEncoding.h [b50441492b] to src/OFString+PercentEncoding.h [8762d6fc4c].

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
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_URLEncoding_reference;
extern int _OFString_PercentEncoding_reference;
#ifdef __cplusplus
}
#endif

@interface OFString (URLEncoding)
@interface OFString (PercentEncoding)
/**
 * @brief The string as an URL decoded string.
 * @brief The string with percent encoding removed.
 *
 * @throw OFInvalidFormatException The string is not in proper percent encoding
 */
@property (readonly, nonatomic) OFString *stringByURLDecoding;
@property (readonly, nonatomic) OFString *stringByRemovingPercentEncoding;

/**
 * @brief Encodes a string for use in a URL, but does not escape the specified
 *	  allowed characters.
 * @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 *)stringByURLEncodingWithAllowedCharacters:
- (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
21

22
23
24
25
26
27
28
29

30
31
32


33
34
35
36
37
38
39
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+URLEncoding.h"
#import "OFString+PercentEncoding.h"
#import "OFCharacterSet.h"

#import "OFInvalidFormatException.h"
#import "OFInvalidEncodingException.h"
#import "OFOutOfMemoryException.h"

/* Reference for static linking */
int _OFString_URLEncoding_reference;
int _OFString_PercentEncoding_reference;

@implementation OFString (URLEncoding)
- (OFString *)stringByURLEncodingWithAllowedCharacters:
@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
78

79
80
81
82
83
84
85
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85







-
+







	}

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (OFString *)stringByURLDecoding
- (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
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
102

103
104
105
106
107
108
109
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 = 0xFF
	OFStringEncodingAutodetect = -1
} OFStringEncoding;

/**
 * @brief Options for searching in strings.
 *
 * This is a bit mask.
 */
132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
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 OFURL;
@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
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
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
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 The UTF-16 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 The UTF-16 string
 * @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 The UTF-16 string
 * @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 The UTF-16 string
 * @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 The UTF-32 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 The UTF-32 string
 * @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 The UTF-32 string
 * @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 The UTF-32 string
 * @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
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
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 URL.
 * @brief Creates a new OFString with the contents of the specified URI.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 * If the URI's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP
 * 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 URL The URL to the contents for the string
 * @param URI The URI to the contents for the string
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL;
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI;

/**
 * @brief Creates a new OFString with the contents of the specified URL in the
 * @brief Creates a new OFString with the contents of the specified URI in the
 *	  specified encoding.
 *
 * @param URL The URL to the contents for the string
 * @param URI The URI to the contents for the string
 * @param encoding The encoding to assume
 * @return A new autoreleased OFString
 */
+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
+ (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
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
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 The 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 The UTF-16 string
 * @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 The UTF-16 string
 * @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 The UTF-16 string
 * @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 The 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 The UTF-32 string
 * @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 The UTF-32 string
 * @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 The UTF-32 string
 * @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
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
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 URL.
 *	  specified URI.
 *
 * If the URL's scheme is file, it tries UTF-8 encoding.
 * If the URI's scheme is file, it tries UTF-8 encoding.
 *
 * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP
 * 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 URL The URL to the contents for the string
 * @param URI The URI to the contents for the string
 * @return An initialized OFString
 */
- (instancetype)initWithContentsOfURL: (OFURL *)URL;
- (instancetype)initWithContentsOfURI: (OFURI *)URI;

/**
 * @brief Initializes an already allocated OFString with the contents of the
 *	  specified URL in the specified encoding.
 *	  specified URI in the specified encoding.
 *
 * @param URL The URL to the contents for the string
 * @param URI The URI to the contents for the string
 * @param encoding The encoding to assume
 * @return An initialized OFString
 */
- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (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
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
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: (int)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: (int)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
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
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 prepending another string.
 *
 * @param string The string to prepend
 * @return A new autoreleased OFString with the specified string prepended
 */
- (OFString *)stringByPrependingString: (OFString *)string;

/**
 * @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
 *		    * 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
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
1246

1247
1248

1249
1250

1251
1252
1253

1254
1255
1256


1257
1258

1259
1260
1261
1262
1263
1264
1265
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 URL using UTF-8 encoding.
 * @brief Writes the string to the specified URI using UTF-8 encoding.
 *
 * @param URL The URL to write to
 * @param URI The URI to write to
 */
- (void)writeToURL: (OFURL *)URL;
- (void)writeToURI: (OFURI *)URI;

/**
 * @brief Writes the string to the specified URL using the specified encoding.
 * @brief Writes the string to the specified URI using the specified encoding.
 *
 * @param URL The URL to write to
 * @param encoding The encoding to use to write the string to the URL
 * @param URI The URI to write to
 * @param encoding The encoding to use to write the string to the URI
 */
- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding;
- (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
1313
1314
1315



1316
1317
1318
1319
1320
1321
1322
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+PropertyListParsing.h"
# import "OFString+Serialization.h"
# import "OFString+URLEncoding.h"
# 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 [05a5b5b79b] to [66ea400d53].

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
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 "OFURL.h"
#import "OFURLHandler.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 "OFRetrieveItemAttributesFailedException.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
138
139
140
141
142
143
144
145
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_URLEncoding_reference = 1;
	_OFString_XMLEscaping_reference = 1;
	_OFString_XMLUnescaping_reference = 1;
}

void
_reference_to_OFConstantString(void)
{
578
579
580
581
582
583
584
585

586
587

588
589
590

591
592
593

594
595
596
597
598
599
600
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)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
	return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL];
	return (id)[[OFUTF8String alloc] initWithContentsOfURI: URI];
}

- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
			     encoding: (OFStringEncoding)encoding
{
	return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL
	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
799

800
801

802
803
804

805
806
807

808
809
810
811
812
813
814
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)stringWithContentsOfURL: (OFURL *)URL
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
{
	return [[[self alloc] initWithContentsOfURL: URL] autorelease];
	return [[[self alloc] initWithContentsOfURI: URI] autorelease];
}

+ (instancetype)stringWithContentsOfURL: (OFURL *)URL
+ (instancetype)stringWithContentsOfURI: (OFURI *)URI
			       encoding: (OFStringEncoding)encoding
{
	return [[[self alloc] initWithContentsOfURL: URL
	return [[[self alloc] initWithContentsOfURI: URI
					   encoding: encoding] autorelease];
}

- (instancetype)init
{
	if ([self isMemberOfClass: [OFString class]]) {
		@try {
1000
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
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 (OFRetrieveItemAttributesFailedException *e) {
		} @catch (OFGetItemAttributesFailedException *e) {
			@throw [OFOpenItemFailedException
			    exceptionWithPath: path
					 mode: @"r"
					errNo: e.errNo];
		}

		objc_autoreleasePoolPop(pool);
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
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







-
+

-
+



-
+






-
+




+
+
+
+







		}
	}

	return self;
}
#endif

- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
{
	return [self initWithContentsOfURL: URL
	return [self initWithContentsOfURI: URI
				  encoding: OFStringEncodingAutodetect];
}

- (instancetype)initWithContentsOfURL: (OFURL *)URL
- (instancetype)initWithContentsOfURI: (OFURI *)URI
			     encoding: (OFStringEncoding)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFData *data;

	@try {
		data = [OFData dataWithContentsOfURL: URL];
		data = [OFData dataWithContentsOfURI: URI];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	/* FIXME: Detect encoding where we can. */
	if (encoding == OFStringEncodingAutodetect)
		encoding = OFStringEncodingUTF8;

	self = [self initWithCString: data.items
			    encoding: encoding
			      length: data.count * data.itemSize];

	objc_autoreleasePoolPop(pool);

1345
1346
1347
1348
1349
1350
1351
1352

1353
1354
1355
1356
1357
1358
1359
1360
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 [OFNotImplementedException exceptionWithSelector: _cmd
		@throw [OFInvalidArgumentException exception];
								 object: self];
	}
}

- (size_t)getCString: (char *)cString
	   maxLength: (size_t)maxLength
	    encoding: (OFStringEncoding)encoding
{
1427
1428
1429
1430
1431
1432
1433
1434

1435
1436
1437
1438
1439
1440
1441
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 [OFInvalidEncodingException exception];
		@throw [OFInvalidArgumentException exception];
	}

	@try {
		ret = [[OFData dataWithItemsNoCopy: cString
					     count: cStringLength + 1
				      freeWhenDone: true] items];
	} @catch (id e) {
1498
1499
1500
1501
1502
1503
1504
1505

1506
1507
1508
1509
1510
1511
1512
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 [OFInvalidEncodingException exception];
		@throw [OFInvalidArgumentException exception];
	}
}

- (size_t)UTF8StringLength
{
	return [self cStringLengthWithEncoding: OFStringEncodingUTF8];
}
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686



1687
1688
1689
1690
1691
1692
1693
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];

		OFHashAdd(&hash, (c & 0xFF0000) >> 16);
		OFHashAdd(&hash, (c & 0x00FF00) >> 8);
		OFHashAdd(&hash, c & 0x0000FF);
		OFHashAddByte(&hash, (c & 0xFF0000) >> 16);
		OFHashAddByte(&hash, (c & 0x00FF00) >> 8);
		OFHashAddByte(&hash, c & 0x0000FF);
	}

	OFHashFinalize(&hash);

	return hash;
}

1748
1749
1750
1751
1752
1753
1754
1755

1756
1757
1758
1759

1760
1761
1762
1763
1764
1765

1766
1767
1768
1769
1770
1771
1772
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 prependString: @"\""];
				[JSON insertString: @"\"" atIndex: 0];
				[JSON appendString: @"\""];
			}
		} else {
			[JSON prependString: @"\""];
			[JSON insertString: @"\"" atIndex: 0];
			[JSON appendString: @"\""];
		}
	} else {
		[JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"];

		[JSON prependString: @"\""];
		[JSON insertString: @"\"" atIndex: 0];
		[JSON appendString: @"\""];
	}

	[JSON makeImmutable];

	return JSON;
}
1812
1813
1814
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
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: OFRangeMake(0, self.length)];
			     range: OFMakeRange(0, self.length)];
}

- (OFRange)rangeOfString: (OFString *)string
		 options: (OFStringSearchOptions)options
{
	return [self rangeOfString: string
			   options: options
			     range: OFRangeMake(0, self.length)];
			     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 OFRangeMake(0, 0);
		return OFMakeRange(0, 0);

	if (searchLength > range.length)
		return OFRangeMake(OFNotFound, 0);
		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 OFRangeMake(range.location + i,
					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 OFRangeMake(range.location + i,
					return OFMakeRange(range.location + i,
					    searchLength);
				}
			}
		}
	} @finally {
		OFFreeMemory(characters);
	}

	objc_autoreleasePoolPop(pool);

	return OFRangeMake(OFNotFound, 0);
	return OFMakeRange(OFNotFound, 0);
}

- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
{
	return [self indexOfCharacterFromSet: characterSet
				     options: 0
				       range: OFRangeMake(0, self.length)];
				       range: OFMakeRange(0, self.length)];
}

- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
			  options: (OFStringSearchOptions)options
{
	return [self indexOfCharacterFromSet: characterSet
				     options: options
				       range: OFRangeMake(0, self.length)];
				       range: OFMakeRange(0, self.length)];
}

- (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet
			  options: (OFStringSearchOptions)options
			    range: (OFRange)range
{
	bool (*characterIsMember)(id, SEL, OFUnichar) =
1973
1974
1975
1976
1977
1978
1979
1980

1981
1982
1983
1984
1985

1986
1987
1988
1989
1990
1991
1992
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: OFRangeMake(idx, self.length - idx)];
	return [self substringWithRange: OFMakeRange(idx, self.length - idx)];
}

- (OFString *)substringToIndex: (size_t)idx
{
	return [self substringWithRange: OFRangeMake(0, idx)];
	return [self substringWithRange: OFMakeRange(0, idx)];
}

- (OFString *)substringWithRange: (OFRange)range
{
	void *pool;
	OFString *ret;

2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
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 *)stringByPrependingString: (OFString *)string
{
	OFMutableString *new = [[string mutableCopy] autorelease];
	[new appendString: self];
	[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;
2124
2125
2126
2127
2128
2129
2130
2131

2132
2133
2134
2135
2136
2137
2138
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: OFRangeMake(0, prefixLength)];
		[self getCharacters: tmp inRange: OFMakeRange(0, prefixLength)];

		hasPrefix = (memcmp(tmp, prefix.characters,
		    prefixLength * sizeof(OFUnichar)) == 0);

		objc_autoreleasePoolPop(pool);
	} @finally {
		OFFreeMemory(tmp);
2154
2155
2156
2157
2158
2159
2160
2161

2162
2163
2164
2165
2166
2167
2168
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: OFRangeMake(length - suffixLength,
			    inRange: OFMakeRange(length - suffixLength,
					 suffixLength)];

		suffixCharacters = suffix.characters;
		hasSuffix = (memcmp(tmp, suffixCharacters,
		    suffixLength * sizeof(OFUnichar)) == 0);

		objc_autoreleasePoolPop(pool);
2214
2215
2216
2217
2218
2219
2220
2221

2222
2223
2224
2225
2226
2227
2228

2229
2230
2231
2232
2233
2234
2235
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:
		    OFRangeMake(last, i - last)];
		    OFMakeRange(last, i - last)];
		if (!skipEmpty || component.length > 0)
			[array addObject: component];

		i += delimiterLength - 1;
		last = i + 1;
	}
	component = [self substringWithRange: OFRangeMake(last, length - last)];
	component = [self substringWithRange: OFMakeRange(last, length - last)];
	if (!skipEmpty || component.length > 0)
		[array addObject: component];

	[array makeImmutable];

	objc_autoreleasePoolPop(pool);

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
2294
2295
2296
2297
2298
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:
				    OFRangeMake(last, i - last)];
				    OFMakeRange(last, i - last)];
				[array addObject: component];
			}

			last = i + 1;
		}
	}
	if (!skipEmpty || length != last) {
		OFString *component = [self substringWithRange:
		    OFRangeMake(last, length - last)];
		    OFMakeRange(last, length - last)];
		[array addObject: component];
	}

	[array makeImmutable];

	objc_autoreleasePoolPop(pool);

	return array;
}

- (long long)longLongValue
{
	return [self longLongValueWithBase: 10];
}

- (long long)longLongValueWithBase: (int)base
- (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))
2360
2361
2362
2363
2364
2365
2366
2367

2368
2369
2370
2371
2372
2373
2374
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: (int)base
- (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++;
2451
2452
2453
2454
2455
2456
2457
2458

2459
2460
2461

2462
2463
2464
2465
2466
2467
2468
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 *decimalPoint = [OFLocale decimalPoint];
	OFString *decimalSeparator = [OFLocale decimalSeparator];
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
				      withString: decimalSeparator].UTF8String;
#endif
	char *endPtr = NULL;
	float value;

	errno = 0;
#ifdef HAVE_STRTOF_L
	value = strtof_l(UTF8String, &endPtr, cLocale);
2504
2505
2506
2507
2508
2509
2510
2511

2512
2513
2514

2515
2516
2517
2518
2519
2520
2521
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 *decimalPoint = [OFLocale decimalPoint];
	OFString *decimalSeparator = [OFLocale decimalSeparator];
	const char *UTF8String = [self
	    stringByReplacingOccurrencesOfString: @"."
				      withString: decimalPoint].UTF8String;
				      withString: decimalSeparator].UTF8String;
#endif
	char *endPtr = NULL;
	double value;

	errno = 0;
#ifdef HAVE_STRTOD_L
	value = strtod_l(UTF8String, &endPtr, cLocale);
2542
2543
2544
2545
2546
2547
2548
2549

2550
2551
2552
2553
2554
2555
2556
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: OFRangeMake(0, length)];
		[self getCharacters: buffer inRange: OFMakeRange(0, length)];

		ret = [[OFData dataWithItemsNoCopy: buffer
					     count: length
					  itemSize: sizeof(OFUnichar)
				      freeWhenDone: true] items];
	} @catch (id e) {
		OFFreeMemory(buffer);
2650
2651
2652
2653
2654
2655
2656
2657

2658
2659
2660
2661
2662
2663
2664
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: OFRangeMake(0, length)];
		[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
2742
2743
2744
2745
2746
2747
2748
2749

2750
2751

2752
2753
2754

2755
2756
2757
2758
2759
2760
2761
2762
2763

2764
2765
2766
2767
2768
2769
2770
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)writeToURL: (OFURL *)URL
- (void)writeToURI: (OFURI *)URI
{
	[self writeToURL: URL encoding: OFStringEncodingUTF8];
	[self writeToURI: URI encoding: OFStringEncodingUTF8];
}

- (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding
- (void)writeToURI: (OFURI *)URI encoding: (OFStringEncoding)encoding
{
	void *pool = objc_autoreleasePoolPush();
	OFURLHandler *URLHandler;
	OFStream *stream;

	if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil)
		@throw [OFUnsupportedProtocolException exceptionWithURL: URL];

	stream = [URLHandler openItemAtURL: URL mode: @"w"];
	stream = [OFURIHandler openItemAtURI: URI mode: @"w"];
	[stream writeString: self encoding: encoding];

	objc_autoreleasePoolPop(pool);
}

#ifdef OF_HAVE_BLOCKS
- (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block
2782
2783
2784
2785
2786
2787
2788
2789

2790
2791
2792
2793
2794
2795
2796
2797
2798
2799

2800
2801
2802
2803
2804
2805
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:
			    OFRangeMake(last, i - last)], &stop);
			    OFMakeRange(last, i - last)], &stop);
			last = i + 1;

			objc_autoreleasePoolPop(pool2);
		}

		lastCarriageReturn = (characters[i] == '\r');
	}

	if (!stop)
		block([self substringWithRange: OFRangeMake(last, i - last)],
		block([self substringWithRange: OFMakeRange(last, i - last)],
		    &stop);

	objc_autoreleasePoolPop(pool);
}
#endif
@end

Modified src/OFSystemInfo.h from [b4c18f307a] to [8b4f866788].

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
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 int ObjFWVersionMajor;
@property (class, readonly, nonatomic) unsigned int ObjFWVersionMinor;
@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;
# ifdef OF_HAVE_FILES
@property (class, readonly, nullable, nonatomic) OFString *userDataPath;
@property (class, readonly, nullable, nonatomic) OFString *userConfigPath;
@property (class, readonly, nullable, nonatomic) OFURI *userDataURI;
@property (class, readonly, nullable, nonatomic) OFURI *userConfigURI;
@property (class, readonly, nullable, nonatomic) OFURI *temporaryDirectoryURI;
# endif
@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;
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
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







-
+






-
+

















-











-
+














-
+

















-
+
-







+ (OFString *)ObjFWVersion;

/**
 * @brief The major version of ObjFW.
 *
 * @return The major version of ObjFW
 */
+ (unsigned int)ObjFWVersionMajor;
+ (unsigned short)ObjFWVersionMajor;

/**
 * @brief The minor version of ObjFW.
 *
 * @return The minor version of ObjFW
 */
+ (unsigned int)ObjFWVersionMinor;
+ (unsigned short)ObjFWVersionMinor;

/**
 * @brief Returns the name of the operating system the application is running
 *	  on.
 *
 * @return The name of the operating system the application is running on
 */
+ (nullable OFString *)operatingSystemName;

/**
 * @brief Returns the version of the operating system the application is
 *	  running on.
 *
 * @return The version of the operating system the application is running on
 */
+ (nullable OFString *)operatingSystemVersion;

#ifdef OF_HAVE_FILES
/**
 * @brief Returns the path where user data 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 `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 OFString *)userDataPath;
+ (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 OFString *)userConfigPath;
+ (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 OFString *)temporaryDirectoryPath;
+ (nullable OFURI *)temporaryDirectoryURI;
#endif

/**
 * @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 [2e51e54a8c] to [fb8661ad24].

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
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







-
+













+
+
+
+
+
+








-
-
+







#include "unistd_wrapper.h"

#include "platform.h"

#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif
#if defined(OF_MACOS) || defined(OF_NETBSD)
#if defined(OF_MACOS) || defined(OF_IOS) || defined(OF_NETBSD)
# include <sys/sysctl.h>
#endif

#ifdef OF_AMIGAOS
# include <exec/execbase.h>
# include <proto/exec.h>
#endif

#if defined(OF_AMIGAOS4)
# include <exec/exectags.h>
#elif defined(OF_MORPHOS)
# include <exec/system.h>
#endif

#ifdef OF_NINTENDO_SWITCH
# define id nx_id
# import <switch.h>
# undef nx_id
#endif

#import "OFSystemInfo.h"
#import "OFApplication.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFLocale.h"
#import "OFOnce.h"
#import "OFString.h"

#import "OFNotImplementedException.h"
#import "OFURI.h"

#if defined(OF_MACOS) || defined(OF_IOS)
# ifdef HAVE_SYSDIR_H
#  include <sysdir.h>
# endif
#endif
#ifdef OF_WINDOWS
231
232
233
234
235
236
237












238
239
240
241
242
243
244
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







+
+
+
+
+
+
+
+
+
+
+
+







		return;

	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)
{
	struct X86Regs regs;

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
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







-
+




-
+




















-
-
+

+












-
+
-
-







-
+
-
-










-
+
-
-

-
-
+
+




-
+





-
+
-

-
+





-
+
-

-
+
+

-
+



+




-
+


-
+
-



-
-
+
+
+



-
+

+
+
+


-
+

+











-
+
-
-







-
+
-
-










-
+
-
-

-
-
+
+





-
+





-
+
-

-
+





-
+
-

-
+
+

-
+






-
+


-
+
-

-
+
+
+

+
+
+


-
+

+



+


-
+

-
+


+
+

+
+






-
+






-
+


+
+





-
+
-

-
+
+

-
+

-
+
+
+
+
+
+

+
+
+
+
+
-
+





-
+

+
+
+
-
-
+
+

-







}

+ (OFString *)ObjFWVersion
{
	return @PACKAGE_VERSION;
}

+ (unsigned int)ObjFWVersionMajor
+ (unsigned short)ObjFWVersionMajor
{
	return OBJFW_VERSION_MAJOR;
}

+ (unsigned int)ObjFWVersionMinor
+ (unsigned short)ObjFWVersionMinor
{
	return OBJFW_VERSION_MINOR;
}

+ (OFString *)operatingSystemName
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initOperatingSystemName);

	return operatingSystemName;
}

+ (OFString *)operatingSystemVersion
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initOperatingSystemVersion);

	return operatingSystemVersion;
}

#ifdef OF_HAVE_FILES
+ (OFString *)userDataPath
+ (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
	if (@available(macOS 10.12, iOS 10, *)) {
		sysdir_search_path_enumeration_state state;

		state = sysdir_start_search_path_enumeration(
		    SYSDIR_DIRECTORY_APPLICATION_SUPPORT,
		    SYSDIR_DOMAIN_MASK_USER);
		if (sysdir_get_next_search_path_enumeration(state, pathC) == 0)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];
	} else {
#  endif
		NSSearchPathEnumerationState state;

		state = NSStartSearchPathEnumeration(
		    NSApplicationSupportDirectory, NSUserDomainMask);
		if (NSGetNextSearchPathEnumeration(state, pathC) == 0)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];
#  ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION
	}
#  endif

	path = [OFMutableString stringWithUTF8String: pathC];
	if ([path hasPrefix: @"~"]) {
		OFDictionary *env = [OFApplication environment];
		OFString *home;

		if ((home = [env objectForKey: @"HOME"]) == nil)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];

		[path deleteCharactersInRange: OFRangeMake(0, 1)];
		[path prependString: home];
		[path deleteCharactersInRange: OFMakeRange(0, 1)];
		[path insertString: home atIndex: 0];
	}

	[path makeImmutable];

	return path;
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_WINDOWS)
	OFDictionary *env = [OFApplication environment];
	OFString *appData;

	if ((appData = [env objectForKey: @"APPDATA"]) == nil)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return appData;
	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)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return [OFString stringWithUTF8String: pathC];
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return @"PROGDIR:";
	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 var;
		return [OFURI fileURIWithPath: var isDirectory: true];

	if ((var = [env objectForKey: @"HOME"]) == nil)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	pool = objc_autoreleasePoolPush();

	var = [[OFString pathWithComponents: [OFArray arrayWithObjects:
	    var, @".local", @"share", nil]] retain];
	var = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    var, @".local", @"share", nil]];
	URI = [[OFURI alloc] initFileURIWithPath: var isDirectory: true];

	objc_autoreleasePoolPop(pool);

	return [var autorelease];
	return [URI autorelease];
# endif
#else
	return nil;
#endif
}

+ (OFString *)userConfigPath
+ (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
	if (@available(macOS 10.12, iOS 10, *)) {
		sysdir_search_path_enumeration_state state;

		state = sysdir_start_search_path_enumeration(
		    SYSDIR_DIRECTORY_LIBRARY, SYSDIR_DOMAIN_MASK_USER);
		if (sysdir_get_next_search_path_enumeration(state, pathC) == 0)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];
	} else {
#  endif
		NSSearchPathEnumerationState state;

		state = NSStartSearchPathEnumeration(NSLibraryDirectory,
		    NSUserDomainMask);
		if (NSGetNextSearchPathEnumeration(state, pathC) == 0)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];
#  ifdef HAVE_SYSDIR_START_SEARCH_PATH_ENUMERATION
	}
#  endif

	path = [OFMutableString stringWithUTF8String: pathC];
	if ([path hasPrefix: @"~"]) {
		OFDictionary *env = [OFApplication environment];
		OFString *home;

		if ((home = [env objectForKey: @"HOME"]) == nil)
			@throw [OFNotImplementedException
			return nil;
			    exceptionWithSelector: _cmd
					   object: self];

		[path deleteCharactersInRange: OFRangeMake(0, 1)];
		[path prependString: home];
		[path deleteCharactersInRange: OFMakeRange(0, 1)];
		[path insertString: home atIndex: 0];
	}

	[path appendString: @"/Preferences"];
	[path makeImmutable];

	return path;
	return [OFURI fileURIWithPath: path isDirectory: true];
# elif defined(OF_WINDOWS)
	OFDictionary *env = [OFApplication environment];
	OFString *appData;

	if ((appData = [env objectForKey: @"APPDATA"]) == nil)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return appData;
	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)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return [OFString stringWithUTF8String: pathC];
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return @"PROGDIR:";
	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 var;
		return [OFURI fileURIWithPath: var isDirectory: true];

	if ((var = [env objectForKey: @"HOME"]) == nil)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return [var stringByAppendingPathComponent: @".config"];
	var = [var stringByAppendingPathComponent: @".config"];

	return [OFURI fileURIWithPath: var isDirectory: true];
# endif
#else
	return nil;
#endif
}

+ (OFString *)temporaryDirectoryPath
+ (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 @"/tmp";
		return [OFURI fileURIWithPath: @"/tmp" isDirectory: true];

	return [OFString stringWithCString: buffer
	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;

		return [OFString stringWithUTF16String: buffer];
		path = [OFString stringWithUTF16String: buffer];
	} else {
		char buffer[PATH_MAX];

		if (!GetTempPathA(PATH_MAX, buffer))
			return nil;

		return [OFString stringWithCString: buffer
		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)
		@throw [OFNotImplementedException exceptionWithSelector: _cmd
		return nil;
								 object: self];

	return [OFString stringWithUTF8String: pathC];
	return [OFURI fileURIWithPath: [OFString stringWithUTF8String: pathC]
			  isDirectory: true];
# elif defined(OF_AMIGAOS)
	return @"T:";
	return [OFURI fileURIWithPath: @"T:" isDirectory: true];
# elif defined(OF_MSDOS)
	return [[OFApplication environment] objectForKey: @"TEMP"];
	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 @"u:\\tmp";
	return tmpFSURI;
# else
	OFString *path =
	    [[OFApplication environment] objectForKey: @"XDG_RUNTIME_DIR"];

	if (path != nil)
		return path;
		return [OFURI fileURIWithPath: path];

	return [OFURI fileURIWithPath: @"/tmp"];
# endif
#else
	return @"/tmp";
# endif
	return nil;
#endif
}
#endif

+ (OFString *)CPUVendor
{
#if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__)
	struct X86Regs regs = x86CPUID(0, 0);
	uint32_t buffer[3];

620
621
622
623
624
625
626











627
628
629
630
631
632
633
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







+
+
+
+
+
+
+
+
+
+
+







		buffer[i++] = regs.ebx;
		buffer[i++] = regs.ecx;
		buffer[i++] = regs.edx;
	}

	return [OFString stringWithCString: (char *)buffer
				  encoding: OFStringEncodingASCII];
#elif defined(OF_MACOS) || defined(OF_IOS)
	char buffer[128];
	size_t length = sizeof(buffer);

	if (sysctlbyname("machdep.cpu.brand_string", &buffer, &length,
	    NULL, 0) != 0)
		return nil;

	return [OFString stringWithCString: buffer
				  encoding: [OFLocale encoding]
				    length: length];
#elif defined(OF_AMIGAOS4)
	CONST_STRPTR model, version;

	GetCPUInfoTags(GCIT_ModelString, &model,
	    GCIT_VersionString, &version, TAG_END);

	if (version != NULL)

Modified src/OFTCPSocket.h from [fc53b099cc] to [13742bc171].

79
80
81
82
83
84
85



86
87
88
89
90
91
92

93
94
95



96
97
98
99
100
101
102
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 NO sets
 * @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
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
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 [06bb1cad5c] to [3962a70e27].

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
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







-
+
+




















-
+







#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	int flags;
#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	if ((_socket = socket(address->sockaddr.sockaddr.sa_family,
	if ((_socket = socket(
	    ((struct sockaddr *)&address->sockaddr)->sa_family,
	    SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) {
		*errNo = OFSocketErrNo();
		return false;
	}

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	return true;
}

- (bool)of_connectSocketToAddress: (const OFSocketAddress *)address
			    errNo: (int *)errNo
{
	if (_socket == OFInvalidSocketHandle)
		@throw [OFNotOpenException exceptionWithObject: self];

	/* Cast needed for AmigaOS, where the argument is declared non-const */
	if (connect(_socket, (struct sockaddr *)&address->sockaddr.sockaddr,
	if (connect(_socket, (struct sockaddr *)&address->sockaddr,
	    address->length) != 0) {
		*errNo = OFSocketErrNo();
		return false;
	}

	return true;
}
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
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 (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	if (_SOCKS5Host != nil) {
		delegate = [[[OFTCPSocketSOCKS5Connector alloc]
		    initWithSocket: self
			      host: host
			      port: port
			  delegate: _delegate
#ifdef OF_HAVE_BLOCKS
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
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 (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	if (_SOCKS5Host != nil) {
		delegate = [[[OFTCPSocketSOCKS5Connector alloc]
		    initWithSocket: self
			      host: host
			      port: port
			  delegate: nil
			     block: block] autorelease];
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
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







-
+
+




















-
+







	socketAddresses = [[OFThread DNSResolver]
	    resolveAddressesForHost: host
		      addressFamily: OFSocketAddressFamilyAny];

	address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0];
	OFSocketAddressSetPort(&address, port);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(
	    ((struct sockaddr *)&address.sockaddr)->sa_family,
	    SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithHost: host
				 port: port
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
	    (char *)&one, (socklen_t)sizeof(one));

#if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS)
	if (port != 0) {
#endif
		if (bind(_socket, &address.sockaddr.sockaddr,
		if (bind(_socket, (struct sockaddr *)&address.sockaddr,
		    address.length) != 0) {
			int errNo = OFSocketErrNo();

			closesocket(_socket);
			_socket = OFInvalidSocketHandle;

			@throw [OFBindFailedException exceptionWithHost: host
358
359
360
361
362
363
364
365


366
367
368
369
370
371
372
354
355
356
357
358
359
360

361
362
363
364
365
366
367
368
369







-
+
+







			int ret;

			while (rnd < 1024)
				rnd = (uint16_t)rand();

			OFSocketAddressSetPort(&address, rnd);

			if ((ret = bind(_socket, &address.sockaddr.sockaddr,
			if ((ret = bind(_socket,
			    (struct sockaddr *)&address.sockaddr,
			    address.length)) == 0) {
				port = rnd;
				break;
			}

			if (OFSocketErrNo() != EADDRINUSE) {
				int errNo = OFSocketErrNo();
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
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







-
+












-
+
+


-
+


-
+







	if (port > 0)
		return port;

#if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
	memset(&address, 0, sizeof(address));

	address.length = (socklen_t)sizeof(address.sockaddr);
	if (OFGetSockName(_socket, &address.sockaddr.sockaddr,
	if (OFGetSockName(_socket, (struct sockaddr *)&address.sockaddr,
	    &address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithHost: host
							   port: port
							 socket: self
							  errNo: errNo];
	}

	if (address.sockaddr.sockaddr.sa_family == AF_INET)
	switch (((struct sockaddr *)&address.sockaddr)->sa_family) {
	case AF_INET:
		return OFFromBigEndian16(address.sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
	else if (address.sockaddr.sockaddr.sa_family == AF_INET6)
	case AF_INET6:
		return OFFromBigEndian16(address.sockaddr.in6.sin6_port);
# endif
	else {
	default:
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithHost: host
							   port: port
							 socket: self
							  errNo: EAFNOSUPPORT];

Modified src/OFTLSStream.h from [0ae2a154e2] to [66003bcff2].

141
142
143
144
145
146
147

148
149
150
151
152
153
154
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
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
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
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;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFTarArchive object with the specified file.
 *
 * @param path The path to the tar archive
 * @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)archiveWithPath: (OFString *)path mode: (OFString *)mode;
#endif
+ (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;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFTarArchive object with the
 *	  specified file.
 *
 * @param path The path to the tar archive
 * @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)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode;
#endif

/**
 * @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
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
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"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
#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;
	uint64_t _toRead;
	unsigned long long _toRead;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry;
- (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;
	uint64_t _toWrite;
	unsigned long long _toWrite;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry;
- (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];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}
#endif

+ (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
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
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: SEEK_END];
							   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: SEEK_END];
							  whence: OFSeekEnd];
		}

		_encoding = OFStringEncodingUTF8;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURIHandler openItemAtURI: URI mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURIHandler openItemAtURI: URI mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	[self close];

	[_currentEntry release];

	[super dealloc];
}

- (OFTarArchiveEntry *)nextEntry
{
	OFTarArchiveEntry *entry;
	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 release];
	_lastReturnedStream = nil;

	if (_stream.atEndOfStream)
		return nil;

	[_stream readIntoBuffer: buffer exactLength: 512];

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
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;
	}

	entry = [[[OFTarArchiveEntry alloc]
	_currentEntry = [[OFTarArchiveEntry alloc]
	    of_initWithHeader: (unsigned char *)buffer
		     encoding: _encoding] autorelease];
		     encoding: _encoding];

	_lastReturnedStream = [[OFTarArchiveFileReadStream alloc]
	    of_initWithStream: _stream
			entry: entry];

	return entry;
	return _currentEntry;
}

- (OFStream *)streamForReadingCurrentEntry
{
	if (_mode != OFTarArchiveModeRead)
		@throw [OFInvalidArgumentException exception];

	if (_lastReturnedStream == nil)
	if (_currentEntry == nil)
		@throw [OFInvalidArgumentException exception];

	return [[(OFTarArchiveFileReadStream *)_lastReturnedStream
	    retain] autorelease];
	_lastReturnedStream = [[[OFTarArchiveFileReadStream alloc]
	    of_initWithArchive: self
			stream: _stream
			 entry: _currentEntry] autorelease];
	[_currentEntry release];
	_currentEntry = nil;

	return _lastReturnedStream;
}

- (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry
{
	void *pool;

	if (_mode != OFTarArchiveModeWrite && _mode != OFTarArchiveModeAppend)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	@try {
		[_lastReturnedStream close];
	} @catch (OFNotOpenException *e) {
		/* Might have already been closed by the user - that's fine. */
	}
	[_lastReturnedStream release];
	_lastReturnedStream = nil;

	[entry of_writeToStream: _stream encoding: _encoding];

	_lastReturnedStream = [[OFTarArchiveFileWriteStream alloc]
	    of_initWithStream: _stream
			entry: entry];
	_lastReturnedStream = [[[OFTarArchiveFileWriteStream alloc]
	    of_initWithArchive: self
			stream: _stream
			 entry: entry] autorelease];

	objc_autoreleasePoolPop(pool);

	return [[(OFTarArchiveFileWriteStream *)_lastReturnedStream
	return _lastReturnedStream;
	    retain] autorelease];
}

- (void)close
{
	if (_stream == nil)
		return;

	@try {
		[_lastReturnedStream close];
	} @catch (OFNotOpenException *e) {
		/* Might have already been closed by the user - that's fine. */
	}
	[_lastReturnedStream release];
	_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_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry
- (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.size;
		_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
- (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length
			  length: (size_t)length
{
	size_t ret;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_atEndOfStream)
		return 0;

#if SIZE_MAX >= UINT64_MAX
	if (length > UINT64_MAX)
#if SIZE_MAX >= ULLONG_MAX
	if (length > ULLONG_MAX)
		@throw [OFOutOfRangeException exception];
#endif

	if ((uint64_t)length > _toRead)
	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

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
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 &&
	    _toRead <= INT64_MAX && (OFFileOffset)_toRead == (int64_t)_toRead) {
		uint64_t size;
	    (OFStreamOffset)_toRead == (long long)_toRead) {
		unsigned long long size;

		[(OFSeekableStream *)_stream seekToOffset: (OFFileOffset)_toRead
						   whence: SEEK_CUR];
		[(OFSeekableStream *)_stream
		    seekToOffset: (OFStreamOffset)_toRead
			  whence: OFSeekCurrent];

		_toRead = 0;

		size = _entry.size;
		size = _entry.uncompressedSize;

		if (size % 512 != 0)
			[(OFSeekableStream *)_stream
			    seekToOffset: 512 - (size % 512)
				  whence: SEEK_CUR];
				  whence: OFSeekCurrent];
	} else {
		char buffer[512];
		uint64_t size;
		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.size;
		size = _entry.uncompressedSize;

		if (size % 512 != 0)
			[_stream readIntoBuffer: buffer
				    exactLength: (size_t)(512 - (size % 512))];
	}

	_skipped = true;
}
@end

@implementation OFTarArchiveFileWriteStream
- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry
- (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.size;
		_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 ((uint64_t)length > _toWrite)
	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
474

475
476
477
478
479
480
481
482

483
484
485
486
487
488
489
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
{
	uint64_t remainder;
	unsigned long long remainder;

	if (_stream == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	if (_toWrite > 0)
		@throw [OFTruncatedDataException exception];

	remainder = 512 - _entry.size % 512;
	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
23
24

25
26
27

28
29

30
31
32
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;

OF_DIRECT_MEMBERS
@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_METHOD_FAMILY(init) OF_DIRECT;
- (void)of_writeToStream: (OFStream *)stream
		encoding: (OFStringEncoding)encoding;
		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
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
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
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 <OFCopying, OFMutableCopying>
@interface OFTarArchiveEntry: OFObject <OFArchiveEntry, OFCopying,
    OFMutableCopying>
{
	OFString *_fileName;
	unsigned long _mode;
	unsigned long long _size;
	OFNumber *_POSIXPermissions, *_ownerAccountID, *_groupOwnerAccountID;
	unsigned long long _compressedSize, _uncompressedSize;
	unsigned long _UID, _GID;
	OFDate *_modificationDate;
	OFTarArchiveEntryType _type;
	OFString *_Nullable _targetFileName;
	OFString *_Nullable _owner, *_Nullable _group;
	OFString *_Nullable _ownerAccountName;
	OFString *_Nullable _groupOwnerAccountName;
	unsigned long _deviceMajor, _deviceMinor;
	OF_RESERVE_IVARS(OFTarArchiveEntry, 4)
}

/**
 * @brief The file name of the entry.
 */
@property (readonly, copy, nonatomic) OFString *fileName;

/**
 * @brief The mode of the entry.
 */
@property (readonly, nonatomic) unsigned long mode;

/**
 * @brief The UID of the owner.
 */
@property (readonly, nonatomic) unsigned long UID;

/**
 * @brief The GID of the group.
 */
@property (readonly, nonatomic) unsigned long GID;

/**
 * @brief The size of the file.
 */
@property (readonly, nonatomic) unsigned long long size;

/**
 * @brief The date of the last modification of the file.
 */
@property (readonly, retain, nonatomic) OFDate *modificationDate;

/**
 * @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 owner of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *owner;

/**
 * @brief The group of the file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *group;

/**
 * @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;

/**
 * @brief Creates a new OFTarArchiveEntry with the specified file name.
 *
 * @param fileName The file name for the OFTarArchiveEntry
 * @return A new, autoreleased OFTarArchiveEntry
 */
+ (instancetype)entryWithFileName: (OFString *)fileName;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFTarArchiveEntry with the specified
 *	  file name.
 *
 * @param fileName The file name for the OFTarArchiveEntry
 * @return An initialized OFTarArchiveEntry
 */
- (instancetype)initWithFileName: (OFString *)fileName;
@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
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
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
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)entryWithFileName: (OFString *)fileName
{
	return [[[self alloc] initWithFileName: fileName] autorelease];
}

- (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];
		_mode = (unsigned long)octalValueFromBuffer(
		    header + 100, 8, ULONG_MAX);
		_UID = (unsigned long)octalValueFromBuffer(
		    header + 108, 8, ULONG_MAX);
		_GID = (unsigned long)octalValueFromBuffer(
		    header + 116, 8, ULONG_MAX);
		_size = (unsigned long long)octalValueFromBuffer(
		_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 =
			_owner = [stringFromBuffer(header + 265, 32, encoding)
			    [stringFromBuffer(header + 265, 32, encoding) copy];
			    copy];
			_group = [stringFromBuffer(header + 297, 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
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
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;
}

- (instancetype)initWithFileName: (OFString *)fileName
{
	self = [super init];

	@try {
		_fileName = [fileName copy];
		_type = OFTarArchiveEntryTypeFile;
		_mode = 0644;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_fileName release];
	[_POSIXPermissions release];
	[_ownerAccountID release];
	[_groupOwnerAccountID release];
	[_modificationDate release];
	[_targetFileName release];
	[_owner release];
	[_group 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->_mode = _mode;
		copy->_size = _size;
		copy->_compressedSize = _compressedSize;
		copy->_uncompressedSize = _uncompressedSize;
		copy->_modificationDate = [_modificationDate copy];
		copy->_type = _type;
		copy->_targetFileName = [_targetFileName copy];
		copy->_owner = [_owner copy];
		copy->_group = [_group 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;
}
- (unsigned long)mode

- (OFNumber *)ownerAccountID
{
	return _mode;
	return _ownerAccountID;
}

- (unsigned long)UID
- (OFNumber *)groupOwnerAccountID
{
	return _UID;
	return _groupOwnerAccountID;
}

- (unsigned long)GID
- (unsigned long long)compressedSize
{
	return _GID;
	return _compressedSize;
}

- (unsigned long long)size
- (unsigned long long)uncompressedSize
{
	return _size;
	return _uncompressedSize;
}

- (OFDate *)modificationDate
{
	return _modificationDate;
}

- (OFTarArchiveEntryType)type
{
	return _type;
}

- (OFString *)targetFileName
{
	return _targetFileName;
}

- (OFString *)owner
- (OFString *)ownerAccountName
{
	return _owner;
	return _ownerAccountName;
}

- (OFString *)group
- (OFString *)groupOwnerAccountName
{
	return _group;
	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];

	OFString *ret = [OFString stringWithFormat: @"<%@:\n"
	ret = [OFString stringWithFormat: @"<%@:\n"
	     @"\tFile name = %@\n"
	     @"\tMode = %06o\n"
	     @"\tUID = %u\n"
	     @"\tGID = %u\n"
	     @"\tSize = %" PRIu64 @"\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 = %@\n"
	     @"\tGroup = %@\n"
	     @"\tOwner account name = %@\n"
	     @"\tGroup owner account name = %@\n"
	     @"\tDevice major = %" PRIu32 @"\n"
	     @"\tDevice minor = %" PRIu32 @"\n"
	     @">",
	    self.class, _fileName, _mode, _UID, _GID, _size, _modificationDate,
	    _type, _targetFileName, _owner, _group, _deviceMajor, _deviceMinor];
	    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: @"%06" PRIo16 " ", _mode], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _POSIXPermissions.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 108,
	    [OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _ownerAccountID.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 116,
	    [OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8,
	    OFStringEncodingASCII);
	    [OFString stringWithFormat: @"%06o ",
	    _groupOwnerAccountID.unsignedShortValue], 8, OFStringEncodingASCII);
	stringToBuffer(buffer + 124,
	    [OFString stringWithFormat: @"%011" PRIo64 " ", _size], 12,
	    [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, _owner, 32, encoding);
	stringToBuffer(buffer + 297, _group, 32, encoding);
	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
77

78
79
80
81
82
83
84
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 _threadBlock;
	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
121

122
123
124
125
126
127
128
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 threadBlock;
@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
167

168
169
170

171
172
173
174
175
176
177
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 threadBlock A block which is executed by the thread
 * @param block A block which is executed by the thread
 * @return A new, autoreleased thread
 */
+ (instancetype)threadWithThreadBlock: (OFThreadBlock)threadBlock;
+ (instancetype)threadWithBlock: (OFThreadBlock)block;
# endif

/**
 * @brief Returns the current thread.
 *
 * @return The current thread
 */
199
200
201
202
203
204
205



206
207
208
209

210
211
212
213
214
215
216
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
 */
+ (OFDNSResolver *)DNSResolver;
+ (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
267

268
269
270

271
272
273
274
275
276
277
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 threadBlock A block which is executed by the thread
 * @param block A block which is executed by the thread
 * @return An initialized OFThread.
 */
- (instancetype)initWithThreadBlock: (OFThreadBlock)threadBlock;
- (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
136
137


138
139
140
141
142
143
144
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->_threadBlock != NULL)
			thread->_returnValue = [thread->_threadBlock() retain];
		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
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
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 threadBlock = _threadBlock;
@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)threadWithThreadBlock: (OFThreadBlock)threadBlock
+ (instancetype)threadWithBlock: (OFThreadBlock)block
{
	return [[[self alloc] initWithThreadBlock: threadBlock] autorelease];
	return [[[self alloc] initWithBlock: block] autorelease];
}
# endif

+ (OFThread *)currentThread
{
	return OFTLSKeyGet(threadSelfKey);
}
376
377
378
379
380
381
382
383

384
385
386
387
388

389
390
391
392
393
394
395
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)initWithThreadBlock: (OFThreadBlock)threadBlock
- (instancetype)initWithBlock: (OFThreadBlock)block
{
	self = [self init];

	@try {
		_threadBlock = [threadBlock copy];
		_block = [block copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554
555
556
557
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
	[_threadBlock release];
	[_block release];
# endif

	[super dealloc];
}
#else
- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}
#endif
@end

Deleted src/OFThreadPool.h version [2c0219fb7b].

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




















































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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"

OF_ASSUME_NONNULL_BEGIN

/** @file */

#ifdef OF_HAVE_BLOCKS
/**
 * @brief A block for a job which should be executed in a thread pool.
 */
typedef void (^OFThreadPoolBlock)(void);
#endif

@class OFCondition;
@class OFList OF_GENERIC(ObjectType);
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFThreadPoolJob;

/**
 * @class OFThreadPool OFThreadPool.h ObjFW/OFThreadPool.h
 *
 * @brief A class providing a pool of reusable threads.
 *
 * @note When the thread pool is released, all threads will terminate after
 *	 they finish the job they are currently processing.
 */
OF_SUBCLASSING_RESTRICTED
@interface OFThreadPool: OFObject
{
	size_t _size;
	OFMutableArray *_threads;
	volatile int _count;
#ifdef OF_THREAD_POOL_M
@public
#endif
	OFList *_queue;
	OFCondition *_queueCondition;
	volatile int _doneCount;
	OFCondition *_countCondition;
}

/**
 * @brief The size of the thread pool.
 */
@property (readonly, nonatomic) size_t size;

/**
 * @brief Returns a new thread pool with one thread for each core in the system.
 *
 * @warning If for some reason the number of cores in the system could not be
 *	    determined, the pool will only have one thread!
 *
 * @return A new thread pool with one thread for each core in the system
 */
+ (instancetype)threadPool;

/**
 * @brief Returns a new thread pool with the specified number of threads.
 *
 * @param size The number of threads for the pool
 * @return A new thread pool with the specified number of threads
 */
+ (instancetype)threadPoolWithSize: (size_t)size;

/**
 * @brief Initializes an already allocated OFThreadPool with the specified
 *	  number of threads.
 *
 * @param size The number of threads for the pool
 * @return An initialized OFThreadPool with the specified number of threads
 */
- (instancetype)initWithSize: (size_t)size OF_DESIGNATED_INITIALIZER;

/**
 * @brief Execute the specified selector on the specified target with the
 *	  specified object as soon as a thread is ready.
 *
 * @param target The target on which to perform the selector
 * @param selector The selector to perform on the target
 * @param object The object with which the selector is performed on the target
 */
- (void)dispatchWithTarget: (id)target
		  selector: (SEL)selector
		    object: (nullable id)object;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Executes the specified block as soon as a thread is ready.
 *
 * @param block The block to execute
 */
- (void)dispatchWithBlock: (OFThreadPoolBlock)block;
#endif

/**
 * @brief Waits until all jobs are done.
 */
- (void)waitUntilDone;
@end

OF_ASSUME_NONNULL_END

Deleted src/OFThreadPool.m version [2a390f83e6].

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
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








































































































































































































































































































































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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"

#define OF_THREAD_POOL_M

#import "OFThreadPool.h"
#import "OFArray.h"
#import "OFList.h"
#import "OFThread.h"
#import "OFCondition.h"
#import "OFSystemInfo.h"

OF_DIRECT_MEMBERS
@interface OFThreadPoolJob: OFObject
{
	id _target;
	SEL _selector;
	id _object;
#ifdef OF_HAVE_BLOCKS
	OFThreadPoolBlock _block;
#endif
}

- (instancetype)initWithTarget: (id)target
		      selector: (SEL)selector
			object: (id)object;
#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (OFThreadPoolBlock)block;
#endif
- (void)perform;
@end

@implementation OFThreadPoolJob
- (instancetype)initWithTarget: (id)target
		      selector: (SEL)selector
			object: (id)object
{
	self = [super init];

	@try {
		_target = [target retain];
		_selector = selector;
		_object = [object retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (OFThreadPoolBlock)block
{
	self = [super init];

	@try {
		_block = [block copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
#endif

- (void)dealloc
{
	[_target release];
	[_object release];
#ifdef OF_HAVE_BLOCKS
	[_block release];
#endif

	[super dealloc];
}

- (void)perform
{
#ifdef OF_HAVE_BLOCKS
	if (_block != NULL)
		_block();
	else
#endif
		[_target performSelector: _selector withObject: _object];
}
@end

OF_DIRECT_MEMBERS
@interface OFThreadPoolThread: OFThread
{
	OFList *_queue;
	OFCondition *_queueCondition, *_countCondition;
@public
	volatile bool _terminate;
	volatile int *_doneCount;
}

+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool;
- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool;
@end

@implementation OFThreadPoolThread
+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool
{
	return [[(OFThreadPoolThread *)[self alloc]
	    initWithThreadPool: threadPool] autorelease];
}

- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool
{
	self = [super init];

	@try {
		_queue = [threadPool->_queue retain];
		_queueCondition = [threadPool->_queueCondition retain];
		_countCondition = [threadPool->_countCondition retain];
		_doneCount = &threadPool->_doneCount;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_queue release];
	[_queueCondition release];
	[_countCondition release];

	[super dealloc];
}

- (id)main
{
	void *pool;

	if (_terminate)
		return nil;

	pool = objc_autoreleasePoolPush();

	for (;;) {
		OFThreadPoolJob *job;

		[_queueCondition lock];
		@try {
			OFListItem listItem;

			if (_terminate) {
				objc_autoreleasePoolPop(pool);
				return nil;
			}

			listItem = _queue.firstListItem;

			while (listItem == NULL) {
				[_queueCondition wait];

				if (_terminate) {
					objc_autoreleasePoolPop(pool);
					return nil;
				}

				listItem = _queue.firstListItem;
			}

			job = [[OFListItemObject(listItem) retain] autorelease];
			[_queue removeListItem: listItem];
		} @finally {
			[_queueCondition unlock];
		}

		if (_terminate) {
			objc_autoreleasePoolPop(pool);
			return nil;
		}

		[job perform];

		if (_terminate) {
			objc_autoreleasePoolPop(pool);
			return nil;
		}

		objc_autoreleasePoolPop(pool);
		pool = objc_autoreleasePoolPush();

		[_countCondition lock];
		@try {
			if (_terminate) {
				objc_autoreleasePoolPop(pool);
				return nil;
			}

			(*_doneCount)++;

			[_countCondition signal];
		} @finally {
			[_countCondition unlock];
		}
	}
}
@end

@implementation OFThreadPool
+ (instancetype)threadPool
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)threadPoolWithSize: (size_t)size
{
	return [[[self alloc] initWithSize: size] autorelease];
}

- (instancetype)init
{
	return [self initWithSize: [OFSystemInfo numberOfCPUs]];
}

- (instancetype)initWithSize: (size_t)size
{
	self = [super init];

	@try {
		_size = size;
		_threads = [[OFMutableArray alloc] init];
		_queue = [[OFList alloc] init];
		_queueCondition = [[OFCondition alloc] init];
		_countCondition = [[OFCondition alloc] init];

		for (size_t i = 0; i < size; i++) {
			void *pool = objc_autoreleasePoolPush();

			OFThreadPoolThread *thread =
			    [OFThreadPoolThread threadWithThreadPool: self];

			[_threads addObject: thread];

			objc_autoreleasePoolPop(pool);
		}

		/*
		 * We need to start the threads in a separate loop to make sure
		 * _threads is not modified anymore to prevent a race condition.
		 */
		for (size_t i = 0; i < size; i++)
			[[_threads objectAtIndex: i] start];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_queueCondition lock];
	@try {
		[_countCondition lock];
		@try {
			for (OFThreadPoolThread *thread in _threads)
				thread->_terminate = true;
		} @finally {
			[_countCondition unlock];
		}

		[_queueCondition broadcast];
	} @finally {
		[_queueCondition unlock];
	}

	[_threads release];
	[_queue release];
	[_queueCondition release];
	[_countCondition release];

	[super dealloc];
}

- (void)of_dispatchJob: (OFThreadPoolJob *)job OF_DIRECT
{
	[_countCondition lock];
	_count++;
	[_countCondition unlock];

	[_queueCondition lock];
	@try {
		[_queue appendObject: job];
		[_queueCondition signal];
	} @finally {
		[_queueCondition unlock];
	}
}

- (void)waitUntilDone
{
	for (;;) {
		[_countCondition lock];
		@try {
			if (_doneCount == _count)
				return;

			[_countCondition wait];
		} @finally {
			[_countCondition unlock];
		}
	}
}

- (void)dispatchWithTarget: (id)target
		  selector: (SEL)selector
		    object: (id)object
{
	OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithTarget: target
							      selector: selector
								object: object];
	@try {
		[self of_dispatchJob: job];
	} @finally {
		[job release];
	}
}

#ifdef OF_HAVE_BLOCKS
- (void)dispatchWithBlock: (OFThreadPoolBlock)block
{
	OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithBlock: block];
	@try {
		[self of_dispatchJob: job];
	} @finally {
		[job release];
	}
}
#endif

- (size_t)size
{
	return _size;
}
@end

Modified src/OFTimer.m from [a9abf62d66] to [6b846b58a6].

677
678
679
680
681
682
683
684

685


686















687
688
689
690
691
692

693
694
695
696









697
698
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







-
+

+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






+



-
+
+
+
+
+
+
+
+
+


		    @"\tInterval: %lf\n"
		    @"\tRepeats: %s\n"
		    @"\tBlock: %@\n"
		    @"\tValid: %s\n"
		    @">",
		    self.class, _fireDate, _interval, (_repeats ? "yes" : "no"),
		    _block, (_valid ? "yes" : "no")];
	else
	else {
#endif
		void *pool = objc_autoreleasePoolPush();
		OFString *objects = @"", *ret;
		return [OFString stringWithFormat:

		if (_arguments >= 1)
			objects = [objects stringByAppendingFormat:
			    @"\tObject: %@\n", _object1];
		if (_arguments >= 2)
			objects = [objects stringByAppendingFormat:
			    @"\tObject: %@\n", _object2];
		if (_arguments >= 3)
			objects = [objects stringByAppendingFormat:
			    @"\tObject: %@\n", _object3];
		if (_arguments >= 4)
			objects = [objects stringByAppendingFormat:
			    @"\tObject: %@\n", _object4];

		ret = [[OFString alloc] initWithFormat:
		    @"<%@:\n"
		    @"\tFire date: %@\n"
		    @"\tInterval: %lf\n"
		    @"\tRepeats: %s\n"
		    @"\tTarget: %@\n"
		    @"\tSelector: %s\n"
		    @"%@"
		    @"\tValid: %s\n"
		    @">",
		    self.class, _fireDate, _interval, (_repeats ? "yes" : "no"),
		    _target, sel_getName(_selector), (_valid ? "yes" : "no")];
		    _target, sel_getName(_selector), objects,
		    (_valid ? "yes" : "no")];

		objc_autoreleasePoolPop(pool);

		return [ret autorelease];
#ifdef OF_HAVE_BLOCKS
	}
#endif
}
@end

Modified src/OFUDPSocket.h from [3a21c440bc] to [e94e3865e1].

68
69
70
71
72
73
74


75
76
77
78
79
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/OFUDPSocket.m from [b89b6c4724] to [61fa5cfa02].

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
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







-
+
+



















-
+







{
	void *pool = objc_autoreleasePoolPush();
	uint16_t port;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	int flags;
#endif

	if ((_socket = socket(address->sockaddr.sockaddr.sa_family,
	if ((_socket = socket(
	    ((struct sockaddr *)&address->sockaddr)->sa_family,
	    SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithHost: OFSocketAddressString(address)
				 port: OFSocketAddressPort(address)
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	/* {} needed to avoid warning with Clang 10 if next #if is false. */
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) {
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
	}
#endif

#if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS)
	if (OFSocketAddressPort(address) != 0) {
#endif
		if (bind(_socket, &address->sockaddr.sockaddr,
		if (bind(_socket, (struct sockaddr *)&address->sockaddr,
		    address->length) != 0) {
			int errNo = OFSocketErrNo();

			closesocket(_socket);
			_socket = OFInvalidSocketHandle;

			@throw [OFBindFailedException
89
90
91
92
93
94
95
96


97
98
99
100
101
102
103
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105







-
+
+







			int ret;

			while (rnd < 1024)
				rnd = (uint16_t)rand();

			OFSocketAddressSetPort(address, rnd);

			if ((ret = bind(_socket, &address->sockaddr.sockaddr,
			if ((ret = bind(_socket,
			    (struct sockaddr *)&address->sockaddr,
			    address->length)) == 0)
				break;

			if (OFSocketErrNo() != EADDRINUSE) {
				int errNo = OFSocketErrNo();
				OFString *host = OFSocketAddressString(address);
				port = OFSocketAddressPort(address);
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
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







-
+













-
+
+


-
+


-
+







	if ((port = OFSocketAddressPort(address)) > 0)
		return port;

#if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS)
	memset(address, 0, sizeof(*address));

	address->length = (socklen_t)sizeof(address->sockaddr);
	if (OFGetSockName(_socket, &address->sockaddr.sockaddr,
	if (OFGetSockName(_socket, (struct sockaddr *)&address->sockaddr,
	    &address->length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException
		    exceptionWithHost: OFSocketAddressString(address)
				 port: OFSocketAddressPort(address)
			       socket: self
				errNo: errNo];
	}

	if (address->sockaddr.sockaddr.sa_family == AF_INET)
	switch (((struct sockaddr *)&address->sockaddr)->sa_family) {
	case AF_INET:
		return OFFromBigEndian16(address->sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
	else if (address->sockaddr.sockaddr.sa_family == AF_INET6)
	case AF_INET6:
		return OFFromBigEndian16(address->sockaddr.in6.sin6_port);
# endif
	else {
	default:
		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException
		    exceptionWithHost: OFSocketAddressString(address)
				 port: OFSocketAddressPort(address)
			       socket: self

Modified src/OFUNIXDatagramSocket.h from [15597b10d9] to [342ce1dbb2].

61
62
63
64
65
66
67


68
69
70
71
72
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/OFUNIXDatagramSocket.m from [0b41257c02] to [2b20715dbe].

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
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







-
+













+
-
+







#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeUNIX(path);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.un.sun_family,
	    SOCK_DGRAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithPath: path
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (bind(_socket, (struct sockaddr *)&address.sockaddr,
	if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPath: path
							 socket: self

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
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

Modified src/OFUNIXStreamSocket.m from [72303f60dd] to [70b73d6c70].

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
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







-
+













+
-
+







#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeUNIX(path);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.un.sun_family,
	    SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
		@throw [OFConnectionFailedException
		    exceptionWithPath: path
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (connect(_socket, (struct sockaddr *)&address.sockaddr,
	if (connect(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFConnectionFailedException exceptionWithPath: path
							       socket: self
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
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







-
+













+
-
+











#endif

	if (_socket != OFInvalidSocketHandle)
		@throw [OFAlreadyConnectedException exceptionWithSocket: self];

	address = OFSocketAddressMakeUNIX(path);

	if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
	if ((_socket = socket(address.sockaddr.un.sun_family,
	    SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle)
		@throw [OFBindFailedException
		    exceptionWithPath: path
			       socket: self
				errNo: OFSocketErrNo()];

	_canBlock = true;

#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
	if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
		fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif

	if (bind(_socket, (struct sockaddr *)&address.sockaddr,
	if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
	    address.length) != 0) {
		int errNo = OFSocketErrNo();

		closesocket(_socket);
		_socket = OFInvalidSocketHandle;

		@throw [OFBindFailedException exceptionWithPath: path
							 socket: self
							  errNo: errNo];
	}
}
@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 [1399f037a2] to src/OFURI.h [b3a4d03434].

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

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 OFURL OFURL.h ObjFW/OFURL.h
 * @class OFURI OFURI.h ObjFW/OFURI.h
 *
 * @brief A class for parsing URLs and accessing parts of it.
 * @brief A class for parsing URIs as per RFC 3986 and accessing parts of it.
 */
@interface OFURL: OFObject <OFCopying, OFMutableCopying, OFSerialization>
@interface OFURI: OFObject <OFCopying, OFMutableCopying, OFSerialization>
{
	OFString *_scheme;
	OFString *_Nullable _URLEncodedScheme, *_Nullable _URLEncodedHost;
	OFString *_Nullable _percentEncodedHost;
	OFNumber *_Nullable _port;
	OFString *_Nullable _URLEncodedUser, *_Nullable _URLEncodedPassword;
	OFString *_Nullable _URLEncodedPath;
	OFString *_Nullable _URLEncodedQuery, *_Nullable _URLEncodedFragment;
	OF_RESERVE_IVARS(OFURL, 4)
	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 URL.
 * @brief The scheme part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *scheme;
@property (readonly, copy, nonatomic) OFString *scheme;

/**
 * @brief The scheme part of the URL in URL-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedScheme;

/**
 * @brief The host part of the URL.
 * @brief The host part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *host;

/**
 * @brief The host part of the URL in URL-encoded form.
 * @brief The host part of the URI in percent-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedHost;
    OFString *percentEncodedHost;

/**
 * @brief The port part of the URL.
 * @brief The port part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFNumber *port;

/**
 * @brief The user part of the URL.
 * @brief The user part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *user;

/**
 * @brief The user part of the URL in URL-encoded form.
 * @brief The user part of the URI in percent-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedUser;
    OFString *percentEncodedUser;

/**
 * @brief The password part of the URL.
 * @brief The password part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *password;

/**
 * @brief The password part of the URL in URL-encoded form.
 * @brief The password part of the URI in percent-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedPassword;
    OFString *percentEncodedPassword;

/**
 * @brief The path part of the URL.
 * @brief The path part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *path;
@property (readonly, copy, nonatomic) OFString *path;

/**
 * @brief The path part of the URL in URL-encoded form.
 * @brief The path part of the URI in percent-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
@property (readonly, copy, nonatomic) OFString *percentEncodedPath;
    OFString *URLEncodedPath;

/**
 * @brief The path of the URL split into components.
 * @brief The path of the URI split into components.
 *
 * The first component must always be `/` to designate the root.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
@property (readonly, copy, nonatomic)
    OFArray OF_GENERIC(OFString *) *pathComponents;

/**
 * @brief The last path component of the URL.
 * @brief The last path component of the URI.
 *
 * Returns the empty string if the path is the root.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *lastPathComponent;
@property (readonly, copy, nonatomic) OFString *lastPathComponent;

/**
 * @brief The query part of the URL.
 * @brief The query part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *query;

/**
 * @brief The query part of the URL in URL-encoded form.
 * @brief The query part of the URI in percent-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedQuery;
    OFString *percentEncodedQuery;

/**
 * @brief The query part of the URL as a dictionary.
 * @brief The query part of the URI as an array.
 *
 * For example, a query like `key1=value1&key2=value2` would correspond to the
 * following dictionary:
 * following array:
 *
 *     @{
 *         @"key1": "value1",
 *         @"key2": "value2"
 *     }
 *     @[
 *         [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)
    OFDictionary OF_GENERIC(OFString *, OFString *) *queryDictionary;
    OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *queryItems;

/**
 * @brief The fragment part of the URL.
 * @brief The fragment part of the URI.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *fragment;

/**
 * @brief The fragment part of the URL in URL-encoded form.
 * @brief The fragment part of the URI in URI-encoded form.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *URLEncodedFragment;
    OFString *percentEncodedFragment;

/**
 * @brief The URL as a string.
 * @brief The URI as a string.
 */
@property (readonly, nonatomic) OFString *string;

/**
 * @brief The URL with relative sub paths resolved.
 * @brief The URI with relative subpaths resolved.
 */
@property (readonly, nonatomic) OFURL *URLByStandardizingPath;
@property (readonly, nonatomic) OFURI *URIByStandardizingPath;

#ifdef OF_HAVE_FILES
/**
 * @brief The local file system representation for a file URL.
 * @brief The local file system representation for a file URI.
 *
 * @note This only exists for URLs with the file scheme and throws an exception
 * @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 URL with the specified string.
 * @brief Creates a new URI with the specified string.
 *
 * @param string A string describing a URL
 * @return A new, autoreleased OFURL
 * @param string A string describing a URI
 * @return A new, autoreleased OFURI
 * @throw OFInvalidFormatException The specified string is not a valid URI
 *				   string
 */
+ (instancetype)URLWithString: (OFString *)string;
+ (instancetype)URIWithString: (OFString *)string;

/**
 * @brief Creates a new URL with the specified string relative to the
 *	  specified URL.
 * @brief Creates a new URI with the specified string relative to the
 *	  specified URI.
 *
 * @param string A string describing a URL
 * @param URL An URL to which the string is relative
 * @return A new, autoreleased OFURL
 * @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)URLWithString: (OFString *)string relativeToURL: (OFURL *)URL;
+ (instancetype)URIWithString: (OFString *)string relativeToURI: (OFURI *)URI;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new URL with the specified local file path.
 * @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 OFURL
 * @return A new, autoreleased OFURI
 */
+ (instancetype)fileURLWithPath: (OFString *)path;
+ (instancetype)fileURIWithPath: (OFString *)path;

/**
 * @brief Creates a new URL with the specified local file 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 OFURL
 * @return An initialized OFURI
 */
+ (instancetype)fileURLWithPath: (OFString *)path
+ (instancetype)fileURIWithPath: (OFString *)path
		    isDirectory: (bool)isDirectory;
#endif

/**
 * @brief Initializes an already allocated OFURL with the specified string.
 * @brief Initializes an already allocated OFURI with the specified string.
 *
 * @param string A string describing a URL
 * @return An initialized OFURL
 * @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 OFURL with the specified string and
 *	  relative URL.
 * @brief Initializes an already allocated OFURI with the specified string and
 *	  relative URI.
 *
 * @param string A string describing a URL
 * @param URL A URL to which the string is relative
 * @return An initialized OFURL
 * @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 relativeToURL: (OFURL *)URL;
- (instancetype)initWithString: (OFString *)string relativeToURI: (OFURI *)URI;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFURL with the specified local file
 * @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 OFURL
 * @return An initialized OFURI
 */
- (instancetype)initFileURLWithPath: (OFString *)path;
- (instancetype)initFileURIWithPath: (OFString *)path;

/**
 * @brief Initializes an already allocated OFURL with the specified local file
 * @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 OFURL
 * @return An initialized OFURI
 */
- (instancetype)initFileURLWithPath: (OFString *)path
- (instancetype)initFileURIWithPath: (OFString *)path
			isDirectory: (bool)isDirectory;
#endif

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Returns a new URL with the specified path component appended.
 * @brief Returns a new URI with the specified path component appended.
 *
 * If the URL is a file URL, the file system is queried whether the 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 URL with the specified path component appended
 * @return A new URI with the specified path component appended
 */
- (OFURL *)URLByAppendingPathComponent: (OFString *)component;
- (OFURI *)URIByAppendingPathComponent: (OFString *)component;

/**
 * @brief Returns a new URL with the specified path component appended.
 * @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 URL path should have a trailing slash
 * @return A new URL with the specified path component appended
 *		      that the URI path should have a trailing slash
 * @return A new URI with the specified path component appended
 */
- (OFURL *)URLByAppendingPathComponent: (OFString *)component
- (OFURI *)URIByAppendingPathComponent: (OFString *)component
			   isDirectory: (bool)isDirectory;
@end

@interface OFCharacterSet (URLCharacterSets)
@interface OFCharacterSet (URICharacterSets)
#ifdef OF_HAVE_CLASS_PROPERTIES
@property (class, readonly, nonatomic)
    OFCharacterSet *URLSchemeAllowedCharacterSet;
    OFCharacterSet *URISchemeAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLHostAllowedCharacterSet;
    OFCharacterSet *URIHostAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLUserAllowedCharacterSet;
    OFCharacterSet *URIUserAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLPasswordAllowedCharacterSet;
    OFCharacterSet *URIPasswordAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLPathAllowedCharacterSet;
    OFCharacterSet *URIPathAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLQueryAllowedCharacterSet;
    OFCharacterSet *URIQueryAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLQueryKeyValueAllowedCharacterSet;
    OFCharacterSet *URIQueryKeyValueAllowedCharacterSet;
@property (class, readonly, nonatomic)
    OFCharacterSet *URLFragmentAllowedCharacterSet;
    OFCharacterSet *URIFragmentAllowedCharacterSet;
#endif

/**
 * @brief Returns the characters allowed in the scheme part of a URL.
 * @brief Returns the characters allowed in the scheme part of a URI.
 *
 * @return The characters allowed in the scheme part of a URL.
 * @return The characters allowed in the scheme part of a URI.
 */
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet;
+ (OFCharacterSet *)URISchemeAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the host part of a URL.
 * @brief Returns the characters allowed in the host part of a URI.
 *
 * @return The characters allowed in the host part of a URL.
 * @return The characters allowed in the host part of a URI.
 */
+ (OFCharacterSet *)URLHostAllowedCharacterSet;
+ (OFCharacterSet *)URIHostAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the user part of a URL.
 * @brief Returns the characters allowed in the user part of a URI.
 *
 * @return The characters allowed in the user part of a URL.
 * @return The characters allowed in the user part of a URI.
 */
+ (OFCharacterSet *)URLUserAllowedCharacterSet;
+ (OFCharacterSet *)URIUserAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the password part of a URL.
 * @brief Returns the characters allowed in the password part of a URI.
 *
 * @return The characters allowed in the password part of a URL.
 * @return The characters allowed in the password part of a URI.
 */
+ (OFCharacterSet *)URLPasswordAllowedCharacterSet;
+ (OFCharacterSet *)URIPasswordAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the path part of a URL.
 * @brief Returns the characters allowed in the path part of a URI.
 *
 * @return The characters allowed in the path part of a URL.
 * @return The characters allowed in the path part of a URI.
 */
+ (OFCharacterSet *)URLPathAllowedCharacterSet;
+ (OFCharacterSet *)URIPathAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the query part of a URL.
 * @brief Returns the characters allowed in the query part of a URI.
 *
 * @return The characters allowed in the query part of a URL.
 * @return The characters allowed in the query part of a URI.
 */
+ (OFCharacterSet *)URLQueryAllowedCharacterSet;
+ (OFCharacterSet *)URIQueryAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in a key/value in the query part of a
 *	  URL.
 *	  URI.
 *
 * @return The characters allowed in a key/value in the query part of a URL.
 * @return The characters allowed in a key/value in the query part of a URI.
 */
+ (OFCharacterSet *)URLQueryKeyValueAllowedCharacterSet;
+ (OFCharacterSet *)URIQueryKeyValueAllowedCharacterSet;

/**
 * @brief Returns the characters allowed in the fragment part of a URL.
 * @brief Returns the characters allowed in the fragment part of a URI.
 *
 * @return The characters allowed in the fragment part of a URL.
 * @return The characters allowed in the fragment part of a URI.
 */
+ (OFCharacterSet *)URLFragmentAllowedCharacterSet;
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet;
@end

#ifdef __cplusplus
extern "C" {
#endif
extern bool OFURLIsIPv6Host(OFString *host);
extern void OFURLVerifyIsEscaped(OFString *, OFCharacterSet *);
extern bool OFURIIsIPv6Host(OFString *host);
extern void OFURIVerifyIsEscaped(OFString *, OFCharacterSet *, bool);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

#import "OFMutableURL.h"
#import "OFMutableURI.h"

Renamed and modified src/OFURL.m [8192f78e14] to src/OFURI.m [fd812a6a57].

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
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 "OFURL.h"
#import "OFURI.h"
#import "OFArray.h"
#import "OFDictionary.h"
#ifdef OF_HAVE_FILES
# import "OFFileManager.h"
# import "OFFileURLHandler.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 OFURLAllowedCharacterSetBase: OFCharacterSet
@interface OFURIAllowedCharacterSetBase: OFCharacterSet
@end

@interface OFURLAllowedCharacterSet: OFURLAllowedCharacterSetBase
@interface OFURIAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURLSchemeAllowedCharacterSet: OFURLAllowedCharacterSetBase
@interface OFURISchemeAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURLPathAllowedCharacterSet: OFURLAllowedCharacterSetBase
@interface OFURIPathAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURLQueryOrFragmentAllowedCharacterSet: OFURLAllowedCharacterSetBase
@interface OFURIQueryOrFragmentAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

@interface OFURLQueryKeyValueAllowedCharacterSet: OFURLAllowedCharacterSetBase
@interface OFURIQueryKeyValueAllowedCharacterSet: OFURIAllowedCharacterSetBase
@end

static OFCharacterSet *URLAllowedCharacterSet = nil;
static OFCharacterSet *URLSchemeAllowedCharacterSet = nil;
static OFCharacterSet *URLPathAllowedCharacterSet = nil;
static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil;
static OFCharacterSet *URLQueryKeyValueAllowedCharacterSet = nil;

static OFOnceControl URLAllowedCharacterSetOnce = OFOnceControlInitValue;
static OFOnceControl URLQueryOrFragmentAllowedCharacterSetOnce =
    OFOnceControlInitValue;

static void
initURLAllowedCharacterSet(void)
{
	URLAllowedCharacterSet = [[OFURLAllowedCharacterSet alloc] init];
}

static void
initURLSchemeAllowedCharacterSet(void)
{
	URLSchemeAllowedCharacterSet =
	    [[OFURLSchemeAllowedCharacterSet alloc] init];
}

static void
initURLPathAllowedCharacterSet(void)
{
	URLPathAllowedCharacterSet =
	    [[OFURLPathAllowedCharacterSet alloc] init];
}

static void
initURLQueryOrFragmentAllowedCharacterSet(void)
{
	URLQueryOrFragmentAllowedCharacterSet =
	    [[OFURLQueryOrFragmentAllowedCharacterSet alloc] init];
}

static void
initURLQueryKeyValueAllowedCharacterSet(void)
{
	URLQueryKeyValueAllowedCharacterSet =
	    [[OFURLQueryKeyValueAllowedCharacterSet alloc] init];
}

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
OFURLIsIPv6Host(OFString *host)
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 OFURLAllowedCharacterSetBase
@implementation OFURIAllowedCharacterSetBase
- (instancetype)autorelease
{
	return self;
}

- (instancetype)retain
{
	return self;
}

- (void)release
{
}

- (unsigned int)retainCount
{
	return OFMaxRetainCount;
}
@end

@implementation OFURLAllowedCharacterSet
@implementation OFURIAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	switch (character) {
	case '-':
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
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 OFURLSchemeAllowedCharacterSet
@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 OFURLPathAllowedCharacterSet
@implementation OFURIPathAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	switch (character) {
	case '-':
222
223
224
225
226
227
228
229

230
231
232
233
234
235
236
223
224
225
226
227
228
229

230
231
232
233
234
235
236
237







-
+







		return true;
	default:
		return false;
	}
}
@end

@implementation OFURLQueryOrFragmentAllowedCharacterSet
@implementation OFURIQueryOrFragmentAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	switch (character) {
	case '-':
255
256
257
258
259
260
261
262

263
264
265
266
267
268
269
256
257
258
259
260
261
262

263
264
265
266
267
268
269
270







-
+







		return true;
	default:
		return false;
	}
}
@end

@implementation OFURLQueryKeyValueAllowedCharacterSet
@implementation OFURIQueryKeyValueAllowedCharacterSet
- (bool)characterIsMember: (OFUnichar)character
{
	if (character < CHAR_MAX && OFASCIIIsAlnum(character))
		return true;

	switch (character) {
	case '-':
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
761
762
763
764
765




766
767
768
769
770
771
772
773
774
775










776
777
778
779
780
781
782
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
OFURLVerifyIsEscaped(OFString *string, OFCharacterSet *characterSet)
OFURIVerifyIsEscaped(OFString *string, OFCharacterSet *characterSet,
    bool allowPercent)
{
	void *pool = objc_autoreleasePoolPush();

	if (allowPercent)
	characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc]
	    initWithCharacterSet: characterSet] autorelease];
		characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc]
		    initWithCharacterSet: characterSet] autorelease];
	else
		characterSet = characterSet.invertedSet;

	if ([string indexOfCharacterFromSet: characterSet] != OFNotFound)
		@throw [OFInvalidFormatException exception];

	objc_autoreleasePoolPop(pool);
}

@implementation OFCharacterSet (URLCharacterSets)
+ (OFCharacterSet *)URLSchemeAllowedCharacterSet
@implementation OFCharacterSet (URICharacterSets)
+ (OFCharacterSet *)URISchemeAllowedCharacterSet
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURLSchemeAllowedCharacterSet);
	OFOnce(&onceControl, initURISchemeAllowedCharacterSet);

	return URLSchemeAllowedCharacterSet;
	return URISchemeAllowedCharacterSet;
}

+ (OFCharacterSet *)URLHostAllowedCharacterSet
+ (OFCharacterSet *)URIHostAllowedCharacterSet
{
	OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet);
	OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet);

	return URLAllowedCharacterSet;
	return URIAllowedCharacterSet;
}

+ (OFCharacterSet *)URLUserAllowedCharacterSet
+ (OFCharacterSet *)URIUserAllowedCharacterSet
{
	OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet);
	OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet);

	return URLAllowedCharacterSet;
	return URIAllowedCharacterSet;
}

+ (OFCharacterSet *)URLPasswordAllowedCharacterSet
+ (OFCharacterSet *)URIPasswordAllowedCharacterSet
{
	OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet);
	OFOnce(&URIAllowedCharacterSetOnce, initURIAllowedCharacterSet);

	return URLAllowedCharacterSet;
	return URIAllowedCharacterSet;
}

+ (OFCharacterSet *)URLPathAllowedCharacterSet
+ (OFCharacterSet *)URIPathAllowedCharacterSet
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURLPathAllowedCharacterSet);
	OFOnce(&onceControl, initURIPathAllowedCharacterSet);

	return URLPathAllowedCharacterSet;
	return URIPathAllowedCharacterSet;
}

+ (OFCharacterSet *)URLQueryAllowedCharacterSet
+ (OFCharacterSet *)URIQueryAllowedCharacterSet
{
	OFOnce(&URLQueryOrFragmentAllowedCharacterSetOnce,
	    initURLQueryOrFragmentAllowedCharacterSet);
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);

	return URLQueryOrFragmentAllowedCharacterSet;
	return URIQueryOrFragmentAllowedCharacterSet;
}

+ (OFCharacterSet *)URLQueryKeyValueAllowedCharacterSet
+ (OFCharacterSet *)URIQueryKeyValueAllowedCharacterSet
{
	static OFOnceControl onceControl = OFOnceControlInitValue;
	OFOnce(&onceControl, initURLQueryKeyValueAllowedCharacterSet);
	OFOnce(&onceControl, initURIQueryKeyValueAllowedCharacterSet);

	return URLQueryKeyValueAllowedCharacterSet;
	return URIQueryKeyValueAllowedCharacterSet;
}

+ (OFCharacterSet *)URLFragmentAllowedCharacterSet
+ (OFCharacterSet *)URIFragmentAllowedCharacterSet
{
	OFOnce(&URLQueryOrFragmentAllowedCharacterSetOnce,
	    initURLQueryOrFragmentAllowedCharacterSet);
	OFOnce(&URIQueryOrFragmentAllowedCharacterSetOnce,
	    initURIQueryOrFragmentAllowedCharacterSet);

	return URLQueryOrFragmentAllowedCharacterSet;
	return URIQueryOrFragmentAllowedCharacterSet;
}
@end

@implementation OFURL
+ (instancetype)URL
@implementation OFURI
+ (instancetype)URI
{
	return [[[self alloc] init] autorelease];
}

+ (instancetype)URLWithString: (OFString *)string
+ (instancetype)URIWithString: (OFString *)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

+ (instancetype)URLWithString: (OFString *)string
		relativeToURL: (OFURL *)URL
+ (instancetype)URIWithString: (OFString *)string
		relativeToURI: (OFURI *)URI
{
	return [[[self alloc] initWithString: string
			       relativeToURL: URL] autorelease];
			       relativeToURI: URI] autorelease];
}

#ifdef OF_HAVE_FILES
+ (instancetype)fileURLWithPath: (OFString *)path
+ (instancetype)fileURIWithPath: (OFString *)path
{
	return [[[self alloc] initFileURLWithPath: path] autorelease];
	return [[[self alloc] initFileURIWithPath: path] autorelease];
}

+ (instancetype)fileURLWithPath: (OFString *)path
+ (instancetype)fileURIWithPath: (OFString *)path
		    isDirectory: (bool)isDirectory
{
	return [[[self alloc] initFileURLWithPath: path
	return [[[self alloc] initFileURIWithPath: path
				      isDirectory: isDirectory] autorelease];
}
#endif

static void
parseUserInfo(OFURI *self, const char *UTF8String, size_t length)
{
	const char *colon;
- (instancetype)initWithString: (OFString *)string
{
	char *UTF8String, *UTF8String2 = NULL;

	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();
		char *tmp, *tmp2;
		bool isIPv6Host = false;

		UTF8String = UTF8String2 = OFStrDup(string.UTF8String);
		const char *UTF8String = string.UTF8String;
		size_t length = string.UTF8StringLength;
		const char *colon;
		OFString *path, *query = nil, *fragment = nil;

		if ((tmp = strchr(UTF8String, ':')) == NULL)
		if ((colon = strchr(UTF8String, ':')) == NULL ||
			@throw [OFInvalidFormatException exception];

		    colon - UTF8String < 1 || !OFASCIIIsAlpha(UTF8String[0]))
		if (strncmp(tmp, "://", 3) != 0)
			@throw [OFInvalidFormatException exception];

		for (tmp2 = UTF8String; tmp2 < tmp; tmp2++)
			*tmp2 = OFASCIIToLower(*tmp2);

		_URLEncodedScheme = [[OFString alloc]
		    initWithUTF8String: UTF8String
				length: tmp - UTF8String];

		_scheme = [[[OFString stringWithUTF8String: UTF8String
						    length: colon - UTF8String]
		    lowercaseString] copy];
		OFURLVerifyIsEscaped(_URLEncodedScheme,
		    [OFCharacterSet URLSchemeAllowedCharacterSet]);

		UTF8String = tmp + 3;

		if ((tmp = strchr(UTF8String, '/')) != NULL) {
			*tmp = '\0';
			tmp++;
		}

		if ((tmp2 = strchr(UTF8String, '@')) != NULL) {
			char *tmp3;

			*tmp2 = '\0';
			tmp2++;

			if ((tmp3 = strchr(UTF8String, ':')) != NULL) {
				*tmp3 = '\0';
				tmp3++;

				_URLEncodedUser = [[OFString alloc]
				    initWithUTF8String: UTF8String];
				_URLEncodedPassword = [[OFString alloc]
				    initWithUTF8String: tmp3];

				OFURLVerifyIsEscaped(_URLEncodedPassword,
				    [OFCharacterSet
				    URLPasswordAllowedCharacterSet]);
		OFURIVerifyIsEscaped(_scheme,
		    [OFCharacterSet URISchemeAllowedCharacterSet], false);

			} else
				_URLEncodedUser = [[OFString alloc]
				    initWithUTF8String: UTF8String];
		length -= colon - UTF8String + 1;
		UTF8String = colon + 1;

		if (length >= 2 && UTF8String[0] == '/' &&
			OFURLVerifyIsEscaped(_URLEncodedUser,
			    [OFCharacterSet URLUserAllowedCharacterSet]);
		    UTF8String[1] == '/') {
			size_t authorityLength;

			UTF8String = tmp2;
		}

			UTF8String += 2;
			length -= 2;

			authorityLength = parseAuthority(self,
		if (UTF8String[0] == '[') {
			tmp2 = UTF8String++;
			    UTF8String, length);

			while (OFASCIIIsDigit(*UTF8String) ||
			    *UTF8String == ':' ||
			    (*UTF8String >= 'a' && *UTF8String <= 'f') ||
			    (*UTF8String >= 'A' && *UTF8String <= 'F'))
				UTF8String++;

			UTF8String += authorityLength;
			length -= authorityLength;

			if (length > 0)
				OFEnsure(UTF8String[0] == '/');
		}
			if (*UTF8String != ']')
				@throw [OFInvalidFormatException exception];

			UTF8String++;

			_URLEncodedHost = [[OFString alloc]
			    initWithUTF8String: tmp2
		parsePathQueryFragment(UTF8String, length,
		    &path, &query, &fragment);
		_percentEncodedPath = [path copy];
		_percentEncodedQuery = [query copy];
		_percentEncodedFragment = [fragment copy];
					length: UTF8String - tmp2];

		objc_autoreleasePoolPop(pool);
			if (*UTF8String == ':') {
				OFString *portString;

	} @catch (id e) {
		[self release];
		@throw e;
	}
				tmp2 = ++UTF8String;

				while (*UTF8String != '\0') {
	return self;
					if (!OFASCIIIsDigit(*UTF8String))
						@throw [OFInvalidFormatException
						    exception];

}
					UTF8String++;
				}


static bool
isAbsolute(OFString *string)
{
				portString = [OFString
	void *pool = objc_autoreleasePoolPush();
				    stringWithUTF8String: tmp2
						  length: UTF8String - tmp2];

	@try {
				if (portString.length == 0 ||
				    portString.unsignedLongLongValue > 65535)
		const char *UTF8String = string.UTF8String;
		size_t length = string.UTF8StringLength;
					@throw [OFInvalidFormatException
					    exception];

				_port = [[OFNumber alloc] initWithUnsignedShort:
				    portString.unsignedLongLongValue];
			} else if (*UTF8String != '\0')
		if (length < 1)
				@throw [OFInvalidFormatException exception];
			return false;

			isIPv6Host = true;
		} else if ((tmp2 = strchr(UTF8String, ':')) != NULL) {
		if (!OFASCIIIsAlpha(UTF8String[0]))
			OFString *portString;
			return false;

			*tmp2 = '\0';
			tmp2++;
		for (size_t i = 1; i < length; i++) {
			if (UTF8String[i] == ':')
				return true;

			_URLEncodedHost = [[OFString alloc]
			    initWithUTF8String: UTF8String];

			portString = [OFString stringWithUTF8String: tmp2];

			if (!OFASCIIIsAlnum(UTF8String[i]) &&
			    UTF8String[i] != '+' && UTF8String[i] != '-' &&
			    UTF8String[i] != '.')
				return false;
			if (portString.unsignedLongLongValue > 65535)
				@throw [OFInvalidFormatException exception];

		}
			_port = [[OFNumber alloc] initWithUnsignedShort:
			    portString.unsignedLongLongValue];
		} else
	} @finally {
			_URLEncodedHost = [[OFString alloc]
			    initWithUTF8String: UTF8String];

		objc_autoreleasePoolPop(pool);
	}
		if (!isIPv6Host)
			OFURLVerifyIsEscaped(_URLEncodedHost,
			    [OFCharacterSet URLHostAllowedCharacterSet]);

		if ((UTF8String = tmp) != NULL) {
			if ((tmp = strchr(UTF8String, '#')) != NULL) {
				*tmp = '\0';

	return false;
}
				_URLEncodedFragment = [[OFString alloc]
				    initWithUTF8String: tmp + 1];

				OFURLVerifyIsEscaped(_URLEncodedFragment,
				    [OFCharacterSet
static OFString *
merge(OFString *base, OFString *path)
{
	OFMutableArray *components;
				    URLFragmentAllowedCharacterSet]);
			}


	if (base.length == 0)
			if ((tmp = strchr(UTF8String, '?')) != NULL) {
				*tmp = '\0';
		base = @"/";

				_URLEncodedQuery = [[OFString alloc]
				    initWithUTF8String: tmp + 1];
	components = [[[base componentsSeparatedByString: @"/"]
	    mutableCopy] autorelease];

				OFURLVerifyIsEscaped(_URLEncodedQuery,
				    [OFCharacterSet
				    URLQueryAllowedCharacterSet]);
			}

	if (components.count == 1)
		[components addObject: path];
	else
		[components replaceObjectAtIndex: components.count - 1
				      withObject: path];

	return [components componentsJoinedByString: @"/"];
}
			/*
			 * Some versions of GCC issue a false-positive warning
			 * (turned error) about a string overflow. This is a
			 * false positive because UTF8String is set to tmp
			 * above and tmp is either NULL or points *after* the
			 * slash for the path. So all we do here is go back to
			 * that slash and restore it.
			 */
#if OF_GCC_VERSION >= 402
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wpragmas"
# pragma GCC diagnostic ignored "-Wunknown-warning-option"
# pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif
			UTF8String--;
			*UTF8String = '/';
#if OF_GCC_VERSION >= 402
# pragma GCC diagnostic pop
#endif

			_URLEncodedPath = [[OFString alloc]
- (instancetype)initWithString: (OFString *)string relativeToURI: (OFURI *)URI
			    initWithUTF8String: UTF8String];

{
			OFURLVerifyIsEscaped(_URLEncodedPath,
			    [OFCharacterSet URLPathAllowedCharacterSet]);
		}

	bool absolute;

	@try {
		objc_autoreleasePoolPop(pool);
		absolute = isAbsolute(string);
	} @catch (id e) {
		[self release];
		@throw e;
	} @finally {
		OFFreeMemory(UTF8String2);
	}

	return self;
}

	if (absolute)
- (instancetype)initWithString: (OFString *)string relativeToURL: (OFURL *)URL
{
	char *UTF8String, *UTF8String2 = NULL;

	if ([string containsString: @"://"])
		return [self initWithString: string];

	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		char *tmp;

		_URLEncodedScheme = [URL->_URLEncodedScheme copy];
		const char *UTF8String = string.UTF8String;
		size_t length = string.UTF8StringLength;
		bool hasAuthority = false;
		_URLEncodedHost = [URL->_URLEncodedHost copy];
		_port = [URL->_port copy];
		OFString *path, *query = nil, *fragment = nil;
		_URLEncodedUser = [URL->_URLEncodedUser copy];
		_URLEncodedPassword = [URL->_URLEncodedPassword copy];

		UTF8String = UTF8String2 = OFStrDup(string.UTF8String);
		_scheme = [URI->_scheme copy];

		if ((tmp = strchr(UTF8String, '#')) != NULL) {
		if (length >= 2 && UTF8String[0] == '/' &&
			*tmp = '\0';
			_URLEncodedFragment = [[OFString alloc]
			    initWithUTF8String: tmp + 1];

		    UTF8String[1] == '/') {
			size_t authorityLength;
			OFURLVerifyIsEscaped(_URLEncodedFragment,
			    [OFCharacterSet URLFragmentAllowedCharacterSet]);
		}

			hasAuthority = true;

		if ((tmp = strchr(UTF8String, '?')) != NULL) {
			*tmp = '\0';
			UTF8String += 2;
			length -= 2;
			_URLEncodedQuery = [[OFString alloc]
			    initWithUTF8String: tmp + 1];

			OFURLVerifyIsEscaped(_URLEncodedQuery,
			    [OFCharacterSet URLQueryAllowedCharacterSet]);
		}
			authorityLength = parseAuthority(self,
			    UTF8String, length);

			UTF8String += authorityLength;
			length -= authorityLength;

		if (*UTF8String == '/')
			if (length > 0)
			_URLEncodedPath = [[OFString alloc]
			    initWithUTF8String: UTF8String];
		else {
				OFEnsure(UTF8String[0] == '/');
		} else {
			OFString *relativePath =
			    [OFString stringWithUTF8String: UTF8String];
			_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 ([URL->_URLEncodedPath hasSuffix: @"/"])
				_URLEncodedPath = [[URL->_URLEncodedPath
		if (hasAuthority) {
			_percentEncodedPath = [path copy];
				    stringByAppendingString: relativePath]
				    copy];
			else {
				OFMutableString *path = [OFMutableString
			_percentEncodedQuery = [query copy];
		} else {
			if (path.length == 0) {
				    stringWithString:
				    (URL->_URLEncodedPath != nil
				    ? URL->_URLEncodedPath
				_percentEncodedPath =
				    [URI->_percentEncodedPath copy];
				    : @"/")];
				OFRange range = [path
				_percentEncodedQuery = (query != nil
				    rangeOfString: @"/"
					  options: OFStringSearchBackwards];

				    ? [query copy]
				if (range.location == OFNotFound)
					@throw [OFInvalidFormatException
					    exception];

				    : [URI->_percentEncodedQuery copy]);
				range.location++;
				range.length = path.length - range.location;

				[path replaceCharactersInRange: range
			} else {
				if ([path hasPrefix: @"/"])
						    withString: relativePath];
				[path makeImmutable];

				_URLEncodedPath = [path copy];
			}
		}

					_percentEncodedPath = [path copy];
				else
					_percentEncodedPath = [merge(
					    URI->_percentEncodedPath, path)
					    copy];

				_percentEncodedQuery = [query copy];
			}
		}
		OFURLVerifyIsEscaped(_URLEncodedPath,
		    [OFCharacterSet URLPathAllowedCharacterSet]);

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	} @finally {
		OFFreeMemory(UTF8String2);
	}

	return self;
}

#ifdef OF_HAVE_FILES
- (instancetype)initFileURLWithPath: (OFString *)path
- (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 initFileURLWithPath: path isDirectory: isDirectory];
	self = [self initFileURIWithPath: path isDirectory: isDirectory];

	return self;
}

- (instancetype)initFileURLWithPath: (OFString *)path
- (instancetype)initFileURIWithPath: (OFString *)path
			isDirectory: (bool)isDirectory
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFString *URLEncodedHost = nil;
		OFString *percentEncodedHost = nil;

		if (!path.absolutePath) {
			OFString *currentDirectoryPath = [OFFileManager
			    defaultManager].currentDirectoryPath;

			path = [currentDirectoryPath
			    stringByAppendingPathComponent: path];
			path = path.stringByStandardizingPath;
		}

		path = [path
		    of_pathToURLPathWithURLEncodedHost: &URLEncodedHost];
		_URLEncodedHost = [URLEncodedHost copy];
		path = [path of_pathToURIPathWithPercentEncodedHost:
		    &percentEncodedHost];
		_percentEncodedHost = [percentEncodedHost copy];

		if (isDirectory && ![path hasSuffix: @"/"])
			path = [path stringByAppendingString: @"/"];

		_URLEncodedScheme = @"file";
		_URLEncodedPath = [[path
		    stringByURLEncodingWithAllowedCharacters:
		    [OFCharacterSet URLPathAllowedCharacterSet]] copy];
		_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 {
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
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
{
	[_URLEncodedScheme release];
	[_URLEncodedHost release];
	[_scheme release];
	[_percentEncodedHost release];
	[_port release];
	[_URLEncodedUser release];
	[_URLEncodedPassword release];
	[_URLEncodedPath release];
	[_URLEncodedQuery release];
	[_URLEncodedFragment release];
	[_percentEncodedUser release];
	[_percentEncodedPassword release];
	[_percentEncodedPath release];
	[_percentEncodedQuery release];
	[_percentEncodedFragment release];

	[super dealloc];
}

- (bool)isEqual: (id)object
{
	OFURL *URL;
	OFURI *URI;

	if (object == self)
		return true;

	if (![object isKindOfClass: [OFURL class]])
	if (![object isKindOfClass: [OFURI class]])
		return false;

	URL = object;
	URI = object;

	if (URL->_URLEncodedScheme != _URLEncodedScheme &&
	    ![URL->_URLEncodedScheme isEqual: _URLEncodedScheme])
	if (![URI->_scheme isEqual: _scheme])
		return false;
	if (URL->_URLEncodedHost != _URLEncodedHost &&
	    ![URL->_URLEncodedHost isEqual: _URLEncodedHost])
	if (URI->_percentEncodedHost != _percentEncodedHost &&
	    ![URI->_percentEncodedHost isEqual: _percentEncodedHost])
		return false;
	if (URL->_port != _port && ![URL->_port isEqual: _port])
	if (URI->_port != _port && ![URI->_port isEqual: _port])
		return false;
	if (URL->_URLEncodedUser != _URLEncodedUser &&
	    ![URL->_URLEncodedUser isEqual: _URLEncodedUser])
	if (URI->_percentEncodedUser != _percentEncodedUser &&
	    ![URI->_percentEncodedUser isEqual: _percentEncodedUser])
		return false;
	if (URL->_URLEncodedPassword != _URLEncodedPassword &&
	    ![URL->_URLEncodedPassword isEqual: _URLEncodedPassword])
	if (URI->_percentEncodedPassword != _percentEncodedPassword &&
	    ![URI->_percentEncodedPassword isEqual: _percentEncodedPassword])
		return false;
	if (URL->_URLEncodedPath != _URLEncodedPath &&
	    ![URL->_URLEncodedPath isEqual: _URLEncodedPath])
	if (![URI->_percentEncodedPath isEqual: _percentEncodedPath])
		return false;
	if (URL->_URLEncodedQuery != _URLEncodedQuery &&
	    ![URL->_URLEncodedQuery isEqual: _URLEncodedQuery])
	if (URI->_percentEncodedQuery != _percentEncodedQuery &&
	    ![URI->_percentEncodedQuery isEqual: _percentEncodedQuery])
		return false;
	if (URL->_URLEncodedFragment != _URLEncodedFragment &&
	    ![URL->_URLEncodedFragment isEqual: _URLEncodedFragment])
	if (URI->_percentEncodedFragment != _percentEncodedFragment &&
	    ![URI->_percentEncodedFragment isEqual: _percentEncodedFragment])
		return false;

	return true;
}

- (unsigned long)hash
{
	unsigned long hash;

	OFHashInit(&hash);

	OFHashAddHash(&hash, _URLEncodedScheme.hash);
	OFHashAddHash(&hash, _URLEncodedHost.hash);
	OFHashAddHash(&hash, _scheme.hash);
	OFHashAddHash(&hash, _percentEncodedHost.hash);
	OFHashAddHash(&hash, _port.hash);
	OFHashAddHash(&hash, _URLEncodedUser.hash);
	OFHashAddHash(&hash, _URLEncodedPassword.hash);
	OFHashAddHash(&hash, _URLEncodedPath.hash);
	OFHashAddHash(&hash, _URLEncodedQuery.hash);
	OFHashAddHash(&hash, _URLEncodedFragment.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 _URLEncodedScheme.stringByURLDecoding;
}

- (OFString *)URLEncodedScheme
{
	return _URLEncodedScheme;
	return _scheme;
}

- (OFString *)host
{
	if ([_URLEncodedHost hasPrefix: @"["] &&
	    [_URLEncodedHost hasSuffix: @"]"]) {
		OFString *host = [_URLEncodedHost substringWithRange:
		    OFRangeMake(1, _URLEncodedHost.length - 2)];
	if ([_percentEncodedHost hasPrefix: @"["] &&
	    [_percentEncodedHost hasSuffix: @"]"]) {
		OFString *host = [_percentEncodedHost substringWithRange:
		    OFMakeRange(1, _percentEncodedHost.length - 2)];

		if (!OFURLIsIPv6Host(host))
		if (!OFURIIsIPv6Host(host))
			@throw [OFInvalidArgumentException exception];

		return host;
	}

	return _URLEncodedHost.stringByURLDecoding;
	return _percentEncodedHost.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedHost
- (OFString *)percentEncodedHost
{
	return _URLEncodedHost;
	return _percentEncodedHost;
}

- (OFNumber *)port
{
	return _port;
}

- (OFString *)user
{
	return _URLEncodedUser.stringByURLDecoding;
	return _percentEncodedUser.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedUser
- (OFString *)percentEncodedUser
{
	return _URLEncodedUser;
	return _percentEncodedUser;
}

- (OFString *)password
{
	return _URLEncodedPassword.stringByURLDecoding;
	return _percentEncodedPassword.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedPassword
- (OFString *)percentEncodedPassword
{
	return _URLEncodedPassword;
	return _percentEncodedPassword;
}

- (OFString *)path
{
	return _URLEncodedPath.stringByURLDecoding;
	return _percentEncodedPath.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedPath
- (OFString *)percentEncodedPath
{
	return _URLEncodedPath;
	return _percentEncodedPath;
}

- (OFArray *)pathComponents
{
	void *pool = objc_autoreleasePoolPush();
#ifdef OF_HAVE_FILES
	bool isFile = [_URLEncodedScheme isEqual: @"file"];
	bool isFile = [_scheme isEqual: @"file"];
#endif
	OFMutableArray *ret;
	size_t count;

#ifdef OF_HAVE_FILES
	if (isFile) {
		OFString *path = [_URLEncodedPath
		    of_URLPathToPathWithURLEncodedHost: nil];
		OFString *path = [_percentEncodedPath
		    of_URIPathToPathWithPercentEncodedHost: nil];
		ret = [[path.pathComponents mutableCopy] autorelease];

		if (![ret.firstObject isEqual: @"/"])
			[ret insertObject: @"/" atIndex: 0];
	} else
#endif
		ret = [[[_URLEncodedPath componentsSeparatedByString: @"/"]
		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_pathComponentToURLPathComponent];
			    [component of_pathComponentToURIPathComponent];
#endif

		component = component.stringByRemovingPercentEncoding;
		[ret replaceObjectAtIndex: i
		[ret replaceObjectAtIndex: i withObject: component];
			       withObject: component.stringByURLDecoding];
	}

	[ret makeImmutable];
	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (OFString *)lastPathComponent
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path = _URLEncodedPath;
	OFString *path = _percentEncodedPath;
	const char *UTF8String, *lastComponent;
	size_t length;
	OFString *ret;

	if (path == nil) {
		objc_autoreleasePoolPop(pool);
		return nil;
	}

	if ([path isEqual: @"/"]) {
		objc_autoreleasePoolPop(pool);
		return @"/";
	}

	if ([path hasSuffix: @"/"])
		path = [path substringToIndex: path.length - 1];
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
1182
1183
1184




1185
1186
1187
1188
1189
1190
1191
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.stringByURLDecoding retain];
	ret = [ret.stringByRemovingPercentEncoding retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (OFString *)query
{
	return _URLEncodedQuery.stringByURLDecoding;
	return _percentEncodedQuery.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedQuery
- (OFString *)percentEncodedQuery
{
	return _URLEncodedQuery;
	return _percentEncodedQuery;
}

- (OFDictionary OF_GENERIC(OFString *, OFString *) *)queryDictionary
- (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *) *)queryItems
{
	void *pool;
	OFArray OF_GENERIC(OFString *) *pairs;
	OFMutableDictionary OF_GENERIC(OFString *, OFString *) *ret;
	OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFString *) *)
	    *ret;

	if (_URLEncodedQuery == nil)
	if (_percentEncodedQuery == nil)
		return nil;

	pool = objc_autoreleasePoolPush();
	pairs = [_URLEncodedQuery componentsSeparatedByString: @"&"];
	ret = [OFMutableDictionary dictionaryWithCapacity: pairs.count];
	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];

		[ret setObject: [[parts objectAtIndex: 1] stringByURLDecoding]
			forKey: [[parts objectAtIndex: 0] stringByURLDecoding]];
		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 _URLEncodedFragment.stringByURLDecoding;
	return _percentEncodedFragment.stringByRemovingPercentEncoding;
}

- (OFString *)URLEncodedFragment
- (OFString *)percentEncodedFragment
{
	return _URLEncodedFragment;
	return _percentEncodedFragment;
}

- (id)copy
{
	return [self retain];
}

- (id)mutableCopy
{
	OFURL *copy = [[OFMutableURL alloc] init];
	OFURI *copy = [[OFMutableURI alloc] initWithScheme: _scheme];

	@try {
		copy->_URLEncodedScheme = [_URLEncodedScheme copy];
		copy->_URLEncodedHost = [_URLEncodedHost copy];
		copy->_percentEncodedHost = [_percentEncodedHost copy];
		copy->_port = [_port copy];
		copy->_URLEncodedUser = [_URLEncodedUser copy];
		copy->_URLEncodedPassword = [_URLEncodedPassword copy];
		copy->_URLEncodedPath = [_URLEncodedPath copy];
		copy->_URLEncodedQuery = [_URLEncodedQuery copy];
		copy->_URLEncodedFragment = [_URLEncodedFragment 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: @"%@://", _URLEncodedScheme];
	[ret appendFormat: @"%@:", _scheme];

	if (_percentEncodedHost != nil || _port != nil ||
	    _percentEncodedUser != nil || _percentEncodedPassword != nil)
		[ret appendString: @"//"];

	if (_URLEncodedUser != nil && _URLEncodedPassword != nil)
	if (_percentEncodedUser != nil && _percentEncodedPassword != nil)
		[ret appendFormat: @"%@:%@@",
				   _percentEncodedUser,
				   _URLEncodedUser, _URLEncodedPassword];
	else if (_URLEncodedUser != nil)
		[ret appendFormat: @"%@@", _URLEncodedUser];
				   _percentEncodedPassword];
	else if (_percentEncodedUser != nil)
		[ret appendFormat: @"%@@", _percentEncodedUser];

	if (_URLEncodedHost != nil)
		[ret appendString: _URLEncodedHost];
	if (_percentEncodedHost != nil)
		[ret appendString: _percentEncodedHost];
	if (_port != nil)
		[ret appendFormat: @":%@", _port];

	if (_URLEncodedPath != nil) {
		if (![_URLEncodedPath hasPrefix: @"/"])
			@throw [OFInvalidFormatException exception];

		[ret appendString: _URLEncodedPath];
	}
	[ret appendString: _percentEncodedPath];


	if (_URLEncodedQuery != nil)
		[ret appendFormat: @"?%@", _URLEncodedQuery];
	if (_percentEncodedQuery != nil)
		[ret appendFormat: @"?%@", _percentEncodedQuery];

	if (_URLEncodedFragment != nil)
		[ret appendFormat: @"#%@", _URLEncodedFragment];
	if (_percentEncodedFragment != nil)
		[ret appendFormat: @"#%@", _percentEncodedFragment];

	[ret makeImmutable];

	return ret;
}

#ifdef OF_HAVE_FILES
- (OFString *)fileSystemRepresentation
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;

	if (![_URLEncodedScheme isEqual: @"file"])
	if (![_scheme isEqual: @"file"])
		@throw [OFInvalidArgumentException exception];

	if (![_URLEncodedPath hasPrefix: @"/"])
	if (![_percentEncodedPath hasPrefix: @"/"])
		@throw [OFInvalidFormatException exception];

	path = [self.path of_URLPathToPathWithURLEncodedHost: _URLEncodedHost];
	path = [self.path
	    of_URIPathToPathWithPercentEncodedHost: _percentEncodedHost];

	[path retain];

	objc_autoreleasePoolPop(pool);

	return [path autorelease];
}
#endif

- (OFURL *)URLByAppendingPathComponent: (OFString *)component
- (OFURI *)URIByAppendingPathComponent: (OFString *)component
{
	OFMutableURL *URL = [[self mutableCopy] autorelease];
	[URL appendPathComponent: component];
	[URL makeImmutable];
	return URL;
	OFMutableURI *URI = [[self mutableCopy] autorelease];
	[URI appendPathComponent: component];
	[URI makeImmutable];
	return URI;
}

- (OFURL *)URLByAppendingPathComponent: (OFString *)component
- (OFURI *)URIByAppendingPathComponent: (OFString *)component
			   isDirectory: (bool)isDirectory
{
	OFMutableURL *URL = [[self mutableCopy] autorelease];
	[URL appendPathComponent: component isDirectory: isDirectory];
	[URL makeImmutable];
	return URL;
	OFMutableURI *URI = [[self mutableCopy] autorelease];
	[URI appendPathComponent: component isDirectory: isDirectory];
	[URI makeImmutable];
	return URI;
}

- (OFURL *)URLByStandardizingPath
- (OFURI *)URIByStandardizingPath
{
	OFMutableURL *URL = [[self mutableCopy] autorelease];
	[URL standardizePath];
	[URL makeImmutable];
	return URL;
	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
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
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 OFURL;
@class OFURI;

/**
 * @class OFURLHandler OFURLHandler.h ObjFW/OFURLHandler.h
 * @class OFURIHandler OFURIHandler.h ObjFW/OFURIHandler.h
 *
 * @brief A handler for a URL scheme.
 * @brief A handler for a URI scheme.
 */
@interface OFURLHandler: OFObject
@interface OFURIHandler: OFObject
{
	OFString *_scheme;
	OF_RESERVE_IVARS(OFURLHandler, 4)
	OF_RESERVE_IVARS(OFURIHandler, 4)
}

/**
 * @brief The scheme this OFURLHandler handles.
 * @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 URL.
 * @brief Returns the handler for the specified URI.
 *
 * @return The handler for the specified URL.
 * @return The handler for the specified URI.
 * @throw OFUnsupportedProtocolException The specified URI is not supported
 */
+ (OFURIHandler *)handlerForURI: (OFURI *)URI;
+ (nullable OF_KINDOF(OFURLHandler *))handlerForURL: (OFURL *)URL;

/**
 * @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 URL handler
 * @return An initialized URI handler
 */
- (instancetype)initWithScheme: (OFString *)scheme OF_DESIGNATED_INITIALIZER;

/**
 * @brief Opens the item at the specified URL.
 * @brief Opens the item at the specified URI.
 *
 * @param URL The URL of the item which should be opened
 * @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 *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode;
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode;

/**
 * @brief Returns the attributes for the item at the specified URL.
 * @brief Returns the attributes for the item at the specified URI.
 *
 * @param URL The URL to return the attributes for
 * @return A dictionary of attributes for the specified URL, with the keys of
 * @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)attributesOfItemAtURL: (OFURL *)URL;
- (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI;

/**
 * @brief Sets the attributes for the item at the specified URL.
 * @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 URL
 * @param URL The URL of the item to set the attributes for
 * @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 ofItemAtURL: (OFURL *)URL;
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI;

/**
 * @brief Checks whether a file exists at the specified URL.
 * @brief Checks whether a file exists at the specified URI.
 *
 * @param URL The URL to check
 * @return A boolean whether there is a file at the specified URL
 * @param URI The URI to check
 * @return A boolean whether there is a file at the specified URI
 */
- (bool)fileExistsAtURL: (OFURL *)URL;
- (bool)fileExistsAtURI: (OFURI *)URI;

/**
 * @brief Checks whether a directory exists at the specified URL.
 * @brief Checks whether a directory exists at the specified URI.
 *
 * @param URL The URL to check
 * @return A boolean whether there is a directory at the specified URL
 * @param URI The URI to check
 * @return A boolean whether there is a directory at the specified URI
 */
- (bool)directoryExistsAtURL: (OFURL *)URL;
- (bool)directoryExistsAtURI: (OFURI *)URI;

/**
 * @brief Creates a directory at the specified URL.
 * @brief Creates a directory at the specified URI.
 *
 * @param URL The URL of the directory to create
 * @param URI The URI of the directory to create
 */
- (void)createDirectoryAtURL: (OFURL *)URL;
- (void)createDirectoryAtURI: (OFURI *)URI;

/**
 * @brief Returns an array with the URLs of the items in the specified
 * @brief Returns an array with the URIs of the items in the specified
 *	  directory.
 *
 * @note `.` and `..` are not part of the returned array.
 *
 * @param URL The URL to the directory whose items should be returned
 * @return An array with the URLs of the items in the specified directory
 * @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(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL;
- (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI;

/**
 * @brief Removes the item at the specified URL.
 * @brief Removes the item at the specified URI.
 *
 * If the item at the specified URL is a directory, it is removed recursively.
 * If the item at the specified URI is a directory, it is removed recursively.
 *
 * @param URL The URL to the item which should be removed
 * @param URI The URI to the item which should be removed
 */
- (void)removeItemAtURL: (OFURL *)URL;
- (void)removeItemAtURI: (OFURI *)URI;

/**
 * @brief Creates a hard link for the specified item.
 *
 * The destination URL must have a full path, which means it must include the
 * 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 URLs.
 * This method is not available for all URIs.
 *
 * @param source The URL to the item for which a link should be created
 * @param destination The URL to the item which should link to the source
 * @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)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination;

/**
 * @brief Creates a symbolic link for an item.
 *
 * The destination uRL must have a full path, which means it must include the
 * 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 URLs.
 * This method is not available for all URIs.
 *
 * @note On Windows, this requires at least Windows Vista and administrator
 *	 privileges!
 *
 * @param URL The URL to the item which should symbolically link to the target
 * @param URI The URI to the item which should symbolically link to the target
 * @param target The target of the symbolic link
 */
- (void)createSymbolicLinkAtURL: (OFURL *)URL
- (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 URL must have a full path, which means it must include the
 * 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 URL
 * @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)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (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 URL must have a full path, which means it must include the
 * 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)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination;
- (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/OFURLHandler.m [0e5a95e00a] to src/OFURIHandler.m [1cc8c8dac2].

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
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 "OFURLHandler.h"
#import "OFURIHandler.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFURL.h"
#import "OFURI.h"

#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif

#import "OFArchiveURIHandler.h"
#import "OFEmbeddedURIHandler.h"
#ifdef OF_HAVE_FILES
# import "OFFileURLHandler.h"
# import "OFFileURIHandler.h"
#endif
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
# import "OFHTTPURLHandler.h"
# import "OFHTTPURIHandler.h"
#endif

#import "OFUnsupportedProtocolException.h"

static OFMutableDictionary OF_GENERIC(OFString *, OFURLHandler *) *handlers;
static OFMutableDictionary OF_GENERIC(OFString *, OFURIHandler *) *handlers;
#ifdef OF_HAVE_THREADS
static OFMutex *mutex;

static void
releaseMutex(void)
{
	[mutex release];
}
#endif

@implementation OFURLHandler
@implementation OFURIHandler
@synthesize scheme = _scheme;

+ (void)initialize
{
	if (self != [OFURLHandler class])
	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: [OFFileURLHandler class] forScheme: @"file"];
	[self registerClass: [OFFileURIHandler class] forScheme: @"file"];
#endif
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
	[self registerClass: [OFHTTPURLHandler class] forScheme: @"http"];
	[self registerClass: [OFHTTPURLHandler class] forScheme: @"https"];
	[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
		OFURLHandler *handler;
		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;
}

+ (OF_KINDOF(OFURLHandler *))handlerForURL: (OFURL *)URL
+ (OFURIHandler *)handlerForURI: (OFURI *)URI
{
	OF_KINDOF(OFURLHandler *) handler;
	OF_KINDOF(OFURIHandler *) handler;

#ifdef OF_HAVE_THREADS
	[mutex lock];
	@try {
#endif
		handler = [handlers objectForKey: URL.scheme];
		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
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
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 *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL
- (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (bool)fileExistsAtURL: (OFURL *)URL
- (bool)fileExistsAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (bool)directoryExistsAtURL: (OFURL *)URL
- (bool)directoryExistsAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)createDirectoryAtURL: (OFURL *)URL
- (void)createDirectoryAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL
- (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)removeItemAtURL: (OFURL *)URL
- (void)removeItemAtURI: (OFURI *)URI
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)createSymbolicLinkAtURL: (OFURL *)destination
- (void)createSymbolicLinkAtURI: (OFURI *)destination
	    withDestinationPath: (OFString *)source
{
	OF_UNRECOGNIZED_SELECTOR
}

- (bool)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (bool)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination
{
	return false;
}

- (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination
- (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
349

350
351
352
353
354
355
356
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 [OFInvalidEncodingException exception];
			@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
935
936
937



938
939
940
941
942
943
944
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];

		OFHashAdd(&hash, (c & 0xFF0000) >> 16);
		OFHashAdd(&hash, (c & 0x00FF00) >> 8);
		OFHashAdd(&hash, c & 0x0000FF);
		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
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
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 OFRangeMake(0, 0);
		return OFMakeRange(0, 0);

	if (cStringLength > rangeLength)
		return OFRangeMake(OFNotFound, 0);
		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 OFRangeMake(OFNotFound, 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 OFRangeMake(OFNotFound, 0);
	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
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
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
190

191
192
193
194
195
196
197
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++)
		OFHashAdd(&hash, _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
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
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.
 *
 * If the value is not pointer-sized, @ref OFOutOfRangeException is thrown.
 * @throw OFOutOfRangeException The value is not pointer-sized
 */
@property (readonly, nonatomic) void *pointerValue;

/**
 * @brief The value as a non-retained object.
 *
 * If the value is not pointer-sized, @ref OFOutOfRangeException is thrown.
 * @throw OFOutOfRangeException The value is not pointer-sized
 */
@property (readonly, nonatomic) id nonretainedObjectValue;

/**
 * @brief The value as an OFRange.
 *
 * If the value is not OFRange-sized, @ref OFOutOfRangeException is thrown.
 * @throw OFOutOfRangeException The value is not OFRange-sized
 */
@property (readonly, nonatomic) OFRange rangeValue;

/**
 * @brief The value as an OFPoint.
 *
 * If the value is not OFPoint-sized, @ref OFOutOfRangeException is thrown.
 * @throw OFOutOfRangeException The value is not OFPoint-sized
 */
@property (readonly, nonatomic) OFPoint pointValue;

/**
 * @brief The value as an OFSize.
 *
 * If the value is not OFSize-sized, @ref OFOutOfRangeException is thrown.
 * @throw OFOutOfRangeException The value is not OFSize-sized
 */
@property (readonly, nonatomic) OFSize sizeValue;

/**
 * @brief The value as a OFRect.
 *
 * If the value is not OFRect-sized, @ref OFOutOfRangeException is thrown.
 * @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
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
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.
 *
 * If the specified size does not match, this raises an
 * @ref OFOutOfRangeException.
 *
 * @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
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
135

136
137
138
139
140
141
142
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++)
			OFHashAdd(&hash, value[i]);
			OFHashAddByte(&hash, value[i]);

		OFHashFinalize(&hash);
	} @finally {
		OFFreeMemory(value);
	}

	return hash;

Modified src/OFWindowsRegistryKey.h from [6b5ceedf22] to [ad68073b0d].

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
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 securityAndAccessRights Please refer to the `RegOpenKeyEx()`
 *				  documentation for `samDesired`
 * @param accessRights Please refer to the `RegOpenKeyEx()` documentation for
 *		       `samDesired`
 * @return The subkey with the specified path, or nil if it does not exist
 */
- (nullable OFWindowsRegistryKey *)
	   openSubkeyAtPath: (OFString *)path
    securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @brief Opens the subkey at the specified path.
 *
 * @param path The path of the subkey to open
 * @param options Please refer to the `RegOpenKeyEx()` documentation for
 *		  `ulOptions`. Usually 0.
 * @param securityAndAccessRights Please refer to the `RegOpenKeyEx()`
 *				  documentation for `samDesired`
 * @return The subkey with the specified path, or nil if it does not exist
 * @return The subkey with the specified path
 */
- (nullable OFWindowsRegistryKey *)
	   openSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
			      accessRights: (REGSAM)accessRights
				   options: (DWORD)options;
    securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @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 securityAndAccessRights Please refer to the `RegCreateKeyEx()`
 *				  documentation for `samDesired`
 * @return The subkey with the specified path
 */
- (OFWindowsRegistryKey *)createSubkeyAtPath: (OFString *)path
		     securityAndAccessRights: (REGSAM)securityAndAccessRights;

/**
 * @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 options Please refer to the `RegCreateKeyEx()` documentation.
 * @param accessRights Please refer to the `RegCreateKeyEx()` documentation for
 *		  Usually 0.
 * @param securityAndAccessRights Please refer to the `RegCreateKeyEx()`
 *				  documentation for `samDesired`
 *		       `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
 * @param disposition Whether the key was created or already existed. Please
 *		      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
    createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes
		disposition: (nullable DWORD *)disposition;
	  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
188
189
190
191
192
193
194
































195
196
197
198
199
200
201
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 * @param name The name of the value to set
 * @param type The type for the value
 */
- (void)setString: (nullable OFString *)string
    forValueNamed: (nullable OFString *)name
	     type: (DWORD)type;

/**
 * @brief Returns the DWORD for the specified value at the specified path.
 *
 * @param name The name of the value to return
 * @return The DWORD for the specified value
 */
- (uint32_t)DWORDForValueNamed: (nullable OFString *)name;

/**
 * @brief Sets the DWORD for the specified value.
 *
 * @param dword The DWORD to set the value to
 * @param name The name of the value to set
 */
- (void)setDWORD: (uint32_t)dword forValueNamed: (nullable OFString *)name;

/**
 * @brief Returns the QWORD for the specified value at the specified path.
 *
 * @param name The name of the value to return
 * @return The QWORD for the specified value
 */
- (uint64_t)QWORDForValueNamed: (nullable OFString *)name;

/**
 * @brief Sets the QWORD for the specified value.
 *
 * @param qword The QWORD to set the value to
 * @param name The name of the value to set
 */
- (void)setQWORD: (uint64_t)qword forValueNamed: (nullable OFString *)name;

/**
 * @brief Deletes the specified value.
 *
 * @param name The value to delete
 */
- (void)deleteValueNamed: (nullable OFString *)name;

Modified src/OFWindowsRegistryKey.m from [1f4e8759ef] to [bf1674ca4d].

27
28
29
30
31
32
33

34
35
36
37
38
39
40
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41







+







#import "OFDeleteWindowsRegistryValueFailedException.h"
#import "OFGetWindowsRegistryValueFailedException.h"
#import "OFInvalidEncodingException.h"
#import "OFInvalidFormatException.h"
#import "OFOpenWindowsRegistryKeyFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetWindowsRegistryValueFailedException.h"
#import "OFUndefinedKeyException.h"

OF_DIRECT_MEMBERS
@interface OFWindowsRegistryKey ()
- (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close;
@end

@implementation OFWindowsRegistryKey
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
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
		   securityAndAccessRights: (REGSAM)securityAndAccessRights
			      accessRights: (REGSAM)accessRights
{
	return [self openSubkeyAtPath: path
			      options: 0
	      securityAndAccessRights: securityAndAccessRights];
}

- (OFWindowsRegistryKey *)openSubkeyAtPath: (OFString *)path
				   options: (DWORD)options
		   securityAndAccessRights: (REGSAM)securityAndAccessRights
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;
	HKEY subKey;

	if ([OFSystemInfo isWindowsNT])
		status = RegOpenKeyExW(_hKey, path.UTF16String, options,
		    securityAndAccessRights, &subKey);
		    accessRights, &subKey);
	else
		status = RegOpenKeyExA(_hKey,
		    [path cStringWithEncoding: [OFLocale encoding]], options,
		    securityAndAccessRights, &subKey);
		    accessRights, &subKey);

	if (status != ERROR_SUCCESS) {
	if (status != ERROR_SUCCESS)
		if (status == ERROR_FILE_NOT_FOUND) {
			objc_autoreleasePoolPop(pool);
			return nil;
		}

		@throw [OFOpenWindowsRegistryKeyFailedException
		    exceptionWithRegistryKey: self
					path: path
				accessRights: accessRights
				     options: options
		     securityAndAccessRights: securityAndAccessRights
				      status: status];
	}

	objc_autoreleasePoolPop(pool);

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];
}

- (OFWindowsRegistryKey *)createSubkeyAtPath: (OFString *)path
		     securityAndAccessRights: (REGSAM)securityAndAccessRights
{
	return [self createSubkeyAtPath: path
				options: 0
		securityAndAccessRights: securityAndAccessRights
		     securityAttributes: NULL
			    disposition: NULL];
}

- (OFWindowsRegistryKey *)
	 createSubkeyAtPath: (OFString *)path
    createSubkeyAtPath: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		disposition: (DWORD *)disposition
	  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, securityAndAccessRights, securityAttributes,
		    &subKey, NULL);
		    NULL, options, accessRights, securityAttributes, &subKey,
		    NULL);
	else
		status = RegCreateKeyExA(_hKey,
		    [path cStringWithEncoding: [OFLocale encoding]], 0, NULL,
		    options, securityAndAccessRights, securityAttributes,
		    options, accessRights, securityAttributes, &subKey, NULL);
		    &subKey, NULL);

	if (status != ERROR_SUCCESS)
		@throw [OFCreateWindowsRegistryKeyFailedException
		    exceptionWithRegistryKey: self
					path: path
				     options: options
		     securityAndAccessRights: securityAndAccessRights
				accessRights: accessRights
			  securityAttributes: securityAttributes
				     options: options
				      status: status];

	objc_autoreleasePoolPop(pool);

	return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey
							close: true]
	    autorelease];
360
361
362
363
364
365
366

































































367
368
369
370
371
372
373
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		data = [OFData dataWithItems: cString count: length + 1];
	}

	[self setData: data forValueNamed: name type: type];

	objc_autoreleasePoolPop(pool);
}

- (uint32_t)DWORDForValueNamed: (OFString *)name
{
	void *pool = objc_autoreleasePoolPush();
	DWORD type, ret;
	OFData *data = [self dataForValueNamed: name type: &type];

	if (data == nil)
		@throw [OFUndefinedKeyException exceptionWithObject: self
								key: name
							      value: nil];

	if (type != REG_DWORD)
		@throw [OFInvalidEncodingException exception];

	if (data.count != sizeof(ret) || data.itemSize != 1)
		@throw [OFInvalidFormatException exception];

	memcpy(&ret, data.items, sizeof(ret));

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (void)setDWORD: (uint32_t)dword forValueNamed: (OFString *)name
{
	void *pool = objc_autoreleasePoolPush();
	OFData *data = [OFData dataWithItems: &dword count: sizeof(dword)];
	[self setData: data forValueNamed: name type: REG_DWORD];
	objc_autoreleasePoolPop(pool);
}

- (uint64_t)QWORDForValueNamed: (OFString *)name
{
	void *pool = objc_autoreleasePoolPush();
	DWORD type;
	uint64_t ret;
	OFData *data = [self dataForValueNamed: name type: &type];

	if (data == nil)
		@throw [OFUndefinedKeyException exceptionWithObject: self
								key: name
							      value: nil];

	if (type != REG_QWORD)
		@throw [OFInvalidEncodingException exception];

	if (data.count != sizeof(ret) || data.itemSize != 1)
		@throw [OFInvalidFormatException exception];

	memcpy(&ret, data.items, sizeof(ret));

	objc_autoreleasePoolPop(pool);

	return ret;
}

- (void)setQWORD: (uint64_t)qword forValueNamed: (OFString *)name
{
	void *pool = objc_autoreleasePoolPush();
	OFData *data = [OFData dataWithItems: &qword count: sizeof(qword)];
	[self setData: data forValueNamed: name type: REG_QWORD];
	objc_autoreleasePoolPop(pool);
}

- (void)deleteValueNamed: (OFString *)name
{
	void *pool = objc_autoreleasePoolPush();
	LSTATUS status;

	if ([OFSystemInfo isWindowsNT])

Modified src/OFXMLAttribute.h from [facd4b4e2b] to [f37ed8f3fd].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
	OF_RESERVE_IVARS(OFXMLAttribute, 4)
}

/**
 * @brief The name of the attribute.
 */
@property (readonly, nonatomic) OFString *name;

87
88
89
90
91
92
93
94

95
96
97
98
99
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;
		 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
73


74
75
76

77
78
79
80
81
82
83
84
85
86
87















88
89
90
91
92
93
94
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
{
	self = [super of_init];
	void *pool;
	OFString *name, *namespace, *stringValue;

	@try {
		void *pool = objc_autoreleasePoolPush();
		pool = objc_autoreleasePoolPush();

		if (![element.name isEqual: self.className] ||
		    ![element.namespace isEqual: OFSerializationNS])
			@throw [OFInvalidArgumentException exception];

		_name = [[element attributeForName: @"name"].stringValue copy];
		_namespace = [[element attributeForName: @"namespace"]
		    .stringValue copy];
		_stringValue = [[element attributeForName: @"stringValue"]
		    .stringValue copy];

		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
181
182
183




184
185
184
185
186
187
188
189
190



191
192
193
194
195
196







-
-
-
+
+
+
+


	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<OFXMLAttribute: name=%@, "
					   @"namespace=%@, stringValue=%@>",
					   _name, _namespace, _stringValue];
	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
28
29
30
31
32
33
34
35
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;
	OF_RESERVE_IVARS(OFXMLCDATA, 4)
}

/**
 * @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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
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 *)XMLStringWithIndentation: (unsigned int)indentation
{
	return self.XMLString;
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	return self.XMLString;
}

- (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
28
29
30
31
32
33
34
35
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;
	OF_RESERVE_IVARS(OFXMLCharacters, 4)
}

/**
 * @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
111
112
113
114
115
116
117
118
119
120
121
122
123
124

125
126
127
128
129
130
131
104
105
106
107
108
109
110











111
112

113
114
115
116
117
118
119
120







-
-
-
-
-
-
-
-
-
-
-


-
+







}

- (OFString *)XMLString
{
	return _characters.stringByXMLEscaping;
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return _characters.stringByXMLEscaping;
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	return _characters.stringByXMLEscaping;
}

- (OFString *)description
{
	return _characters.stringByXMLEscaping;
	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
28
29
30
31
32
33
34
35
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;
	OF_RESERVE_IVARS(OFXMLComment, 4)
}

/**
 * @brief The comment text.
 */
@property (readonly, nonatomic) OFString *text;

Modified src/OFXMLComment.m from [842e736751] to [9e48182a96].

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
101
102
103
104
105
106
107



























108
109

110
111
112
113
114
115
116
117







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-


-
+







}

- (OFString *)XMLString
{
	return [OFString stringWithFormat: @"<!--%@-->", _text];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return [OFString stringWithFormat: @"<!--%@-->", _text];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	OFString *ret;

	if (indentation > 0 && level > 0) {
		char *whitespaces = OFAllocMemory((level * indentation) + 1, 1);
		memset(whitespaces, ' ', level * indentation);
		whitespaces[level * indentation] = 0;

		@try {
			ret = [OFString stringWithFormat: @"%s<!--%@-->",
							  whitespaces, _text];
		} @finally {
			OFFreeMemory(whitespaces);
		}
	} else
		ret = [OFString stringWithFormat: @"<!--%@-->", _text];

	return ret;
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"<!--%@-->", _text];
	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
35

36
37
38
39
40
41
42
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, *_Nullable _defaultNamespace;
	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
58
59
60
61
62
63
64
65
66
67
68
69
70
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 The default namespace for the element to be used if there is no
 *	  parent.
 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *defaultNamespace;

/**
 * @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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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 Creates a new element with the specified element.
 *
 * @param element An OFXMLElement to initialize the OFXMLElement with
 * @return A new autoreleased OFXMLElement with the contents of the specified
 *	   element
 */
+ (instancetype)elementWithElement: (OFXMLElement *)element;

/**
 * @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
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
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;
		   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 Initializes an already allocated OFXMLElement with the specified
 *	  element.
 *
 * @param element An OFXMLElement to initialize the OFXMLElement with
 * @return A new autoreleased OFXMLElement with the contents of the specified
 *	   element
 */
- (instancetype)initWithElement: (OFXMLElement *)element;

/**
 * @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;

- (instancetype)initWithSerialization: (OFXMLElement *)element;

/**
 * @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
352
353

354
355
356
357
358
359
360
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
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
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;
- (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;
- (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
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
76
77
78
79
80
81
82
83
69
70
71
72
73
74
75

76
77
78
79
80
81
82







-








	[super dealloc];
}
@end

@implementation OFXMLElement
@synthesize name = _name, namespace = _namespace;
@synthesize defaultNamespace = _defaultNamespace;

+ (instancetype)elementWithName: (OFString *)name
{
	return [[[self alloc] initWithName: name] autorelease];
}

+ (instancetype)elementWithName: (OFString *)name
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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)elementWithElement: (OFXMLElement *)element
{
	return [[[self alloc] initWithElement: element] autorelease];
}

+ (instancetype)elementWithXMLString: (OFString *)string
{
	return [[[self alloc] initWithXMLString: string] autorelease];
}

+ (instancetype)elementWithStream: (OFStream *)stream
{
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
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
{
	return [self initWithName: name namespace: namespace stringValue: nil];
}

- (instancetype)initWithName: (OFString *)name
		   namespace: (OFString *)namespace
		 stringValue: (OFString *)stringValue
{
	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];

		if (stringValue != nil)
			self.stringValue = stringValue;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithElement: (OFXMLElement *)element
- (instancetype)initWithName: (OFString *)name
		   namespace: (OFString *)namespace
		 stringValue: (OFString *)stringValue
{
	self = [super of_init];
	self = [self initWithName: name namespace: namespace];

	@try {
		if (element == nil ||
		if (stringValue != nil)
		    ![element isKindOfClass: [OFXMLElement class]])
			@throw [OFInvalidArgumentException exception];

			self.stringValue = stringValue;
		_name = [element->_name copy];
		_namespace = [element->_namespace copy];
		_defaultNamespace = [element->_defaultNamespace copy];
		_attributes = [element->_attributes mutableCopy];
		_namespaces = [element->_namespaces mutableCopy];
		_children = [element->_children mutableCopy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithXMLString: (OFString *)string
{
	void *pool;
	OFXMLElement *element;

	@try {
	OFXMLParser *parser;
	OFXMLElementBuilder *builder;
	OFXMLElementElementBuilderDelegate *delegate;
		OFXMLParser *parser;
		OFXMLElementBuilder *builder;
		OFXMLElementElementBuilderDelegate *delegate;

	[self release];

	if (string == nil)
		@throw [OFInvalidArgumentException exception];
		if (string == nil)
			@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();
		pool = objc_autoreleasePoolPush();

	parser = [OFXMLParser parser];
	builder = [OFXMLElementBuilder builder];
	delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
	    autorelease];
		parser = [OFXMLParser parser];
		builder = [OFXMLElementBuilder builder];
		delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
		    autorelease];

	parser.delegate = builder;
	builder.delegate = delegate;
		parser.delegate = builder;
		builder.delegate = delegate;

	[parser parseString: string];
		[parser parseString: string];

	if (!parser.hasFinishedParsing)
		@throw [OFMalformedXMLException exceptionWithParser: parser];
		if (!parser.hasFinishedParsing)
			@throw [OFMalformedXMLException
			    exceptionWithParser: parser];

	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);
		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;
		OFXMLParser *parser;
		OFXMLElementBuilder *builder;
		OFXMLElementElementBuilderDelegate *delegate;

	[self release];

	pool = objc_autoreleasePoolPush();
		pool = objc_autoreleasePoolPush();

	parser = [OFXMLParser parser];
	builder = [OFXMLElementBuilder builder];
	delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
	    autorelease];
		parser = [OFXMLParser parser];
		builder = [OFXMLElementBuilder builder];
		delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
		    autorelease];

	parser.delegate = builder;
	builder.delegate = delegate;
		parser.delegate = builder;
		builder.delegate = delegate;

	[parser parseStream: stream];
		[parser parseStream: stream];

	if (!parser.hasFinishedParsing)
		@throw [OFMalformedXMLException exceptionWithParser: parser];
		if (!parser.hasFinishedParsing)
			@throw [OFMalformedXMLException
			    exceptionWithParser: parser];

	self = [delegate->_element retain];

	objc_autoreleasePoolPop(pool);
		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
{
	self = [super of_init];
	void *pool;
	OFString *name, *namespace;

	@try {
		void *pool = objc_autoreleasePoolPush();
		pool = objc_autoreleasePoolPush();
		OFXMLElement *attributesElement, *namespacesElement;
		OFXMLElement *childrenElement;
		OFEnumerator *keyEnumerator, *objectEnumerator;
		OFString *key, *object;

		if (![element.name isEqual: self.className] ||
		    ![element.namespace isEqual: OFSerializationNS])
			@throw [OFInvalidArgumentException exception];

		_name = [[element attributeForName: @"name"].stringValue copy];
		_namespace = [[element attributeForName: @"namespace"]
		    .stringValue copy];
		_defaultNamespace = [[element attributeForName:
		    @"defaultNamespace"].stringValue copy];
		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;
			 namespace: OFSerializationNS]
		    elementsForNamespace: OFSerializationNS].firstObject;
		namespacesElement = [[element
		    elementForName: @"namespaces"
			 namespace: OFSerializationNS] elementsForNamespace:
		    OFSerializationNS].firstObject;
			 namespace: OFSerializationNS]
		    elementsForNamespace: OFSerializationNS].firstObject;
		childrenElement = [[element
		    elementForName: @"children"
			 namespace: OFSerializationNS] elementsForNamespace:
		    OFSerializationNS].firstObject;
			 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
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/"];

		if (_name == nil)
			@throw [OFInvalidArgumentException exception];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_name release];
	[_namespace release];
	[_defaultNamespace release];
	[_attributes release];
	[_namespaces release];
	[_children release];

	[super dealloc];
}

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
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_XMLStringWithParent: (OFXMLElement *)parent
			  namespaces: (OFDictionary *)allNS
			 indentation: (unsigned int)indentation
			       level: (unsigned int)level OF_DIRECT
- (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, *parentPrefix;
	OFString *prefix, *ret;
	OFString *ret;
	OFString *defaultNS;

	pool = objc_autoreleasePoolPush();

	parentPrefix = [allNS objectForKey:
	    (parent != nil && parent->_namespace != nil
	    ? parent->_namespace : (OFString *)@"")];

	/* 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 *)@"")];

	if (parent != nil && parent->_namespace != nil && parentPrefix == nil)
		defaultNS = parent->_namespace;
	else if (parent != nil && parent->_defaultNamespace != nil)
		defaultNS = parent->_defaultNamespace;
	else
		defaultNS = _defaultNamespace;

	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 != nil && ![_namespace isEqual: defaultNS]) {
		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 == nil && ((_namespace != nil &&
		    ![_namespace isEqual: defaultNS]) ||
		if (prefix.length == 0 && defaultNS != _namespace &&
		    ![defaultNS isEqual: _namespace]) {
		    (_namespace == nil && defaultNS != nil))) {
			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]) == 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
566
567
568
569
570
571







572
573
574




575
576
577
578
579
580
581
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_XMLStringWithParent: self
							namespaces: allNS
						       indentation: ind
							     level: level + 1];
				else
					childString = [child
					    of_XMLStringWithDefaultNS: defaultNS
							   namespaces: allNS
							  indentation: ind
								level: level +
									   1];
				else {
					childString = child.XMLString;
					    XMLStringWithIndentation: ind
							       level: level +
								      1];
					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
599

600
601
602
603
604
605
606
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 != nil) {
			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
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
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_XMLStringWithParent: nil
				 namespaces: nil
				indentation: 0
				      level: 0];
	return [self of_XMLStringWithDefaultNS: nil
				    namespaces: nil
				   indentation: 0
					 level: 0];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return [self of_XMLStringWithParent: nil
				 namespaces: nil
				indentation: indentation
				      level: 0];
	return [self of_XMLStringWithDefaultNS: nil
				    namespaces: nil
				   indentation: indentation
					 level: 0];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
- (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS
				indentation: (unsigned int)indentation
{
	return [self of_XMLStringWithParent: nil
				 namespaces: nil
				indentation: indentation
				      level: level];
	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 (_defaultNamespace != nil)
		[element addAttributeWithName: @"defaultNamespace"
				  stringValue: _defaultNamespace];

	if (_attributes != nil) {
		OFXMLElement *attributesElement;

		attributesElement =
		    [OFXMLElement elementWithName: @"attributes"
					namespace: OFSerializationNS];
		[attributesElement addChild:
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
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];
	if (namespace == nil)
		namespace = @"";

	[_namespaces setObject: prefix forKey: namespace];
}

- (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace
{
	[self setPrefix: prefix forNamespace: namespace];
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
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->_defaultNamespace != _defaultNamespace &&
	    ![element->_defaultNamespace isEqual: _defaultNamespace])
		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
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034











1035


1036
1037
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, _defaultNamespace.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 [[[self class] alloc] initWithElement: self];

	return copy;
}
@end

Modified src/OFXMLElementBuilder.h from [657f65f42e] to [db177baac1].

50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
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
  didBuildParentlessNode: (OFXMLNode *)node;
- (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
109
110
111
112
113
114
115
116
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;
	OF_RESERVE_IVARS(OFXMLElementBuilder, 4)
}

/**
 * @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
61

62
63
64
65

66
67
68
69
70
71
72


73
74
75
76
77
78
79
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
				  data: (OFString *)data
				  text: (OFString *)text
{
	OFXMLProcessingInstruction *node = [OFXMLProcessingInstruction
	    processingInstructionWithTarget: target
				       data: data];
				       text: text];
	OFXMLElement *parent = _stack.lastObject;

	if (parent != nil)
		[parent addChild: node];
	else if ([_delegate respondsToSelector:
	    @selector(elementBuilder:didBuildParentlessNode:)])
		[_delegate elementBuilder: self didBuildParentlessNode: node];
	    @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
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
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:didBuildParentlessNode:)])
		[_delegate  elementBuilder: self didBuildParentlessNode: node];
	    @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:didBuildParentlessNode:)])
		[_delegate elementBuilder: self didBuildParentlessNode: node];
	    @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:didBuildParentlessNode:)])
		[_delegate elementBuilder: self didBuildParentlessNode: node];
	    @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
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
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 Returns an OFString representing the OFXMLNode as an XML string with
 *	  indentation.
 *
 * @param indentation The indentation for the XML string
 * @return An OFString representing the OFXMLNode as an XML string with
 *	   indentation
 */
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation;

/**
 * @brief Returns an OFString representing the OFXMLNode as an XML string with
 *	  indentation for the specified level.
 *
 * @param indentation The indentation for the XML string
 * @param level The level of indentation
 * @return An OFString representing the OFXMLNode as an XML string with
 *	   indentation
 */
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level;

/**
 * @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: (int)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: (int)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
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
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: (int)base
- (long long)longLongValueWithBase: (unsigned char)base
{
	return [self.stringValue longLongValueWithBase: base];
}

- (unsigned long long)unsignedLongLongValue
{
	return self.stringValue.unsignedLongLongValue;
}

- (unsigned long long)unsignedLongLongValueWithBase: (int)base
- (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
{
	return [self XMLStringWithIndentation: 0 level: 0];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return [self XMLStringWithIndentation: 0 level: 0];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	OF_UNRECOGNIZED_SELECTOR
}

- (OFString *)description
{
	return [self XMLStringWithIndentation: 2 level: 0];
	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
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
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 data The data of the processing instruction
 * @param text The text of the processing instruction
 */
-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  data: (OFString *)data;
				  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 ns The namespace 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 *)ns
	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 ns The namespace 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 *)ns;
      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
117

118
119
120
121
122
123
124
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)
	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
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
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, *data = nil;
		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];
			data = [[PI substringFromIndex: pos + 1]
			text = [[PI substringFromIndex: pos + 1]
			    stringByDeletingEnclosingWhitespaces];

			if (data.length == 0)
				data = nil;
			if (text.length == 0)
				text = nil;
		} else
			target = PI;

		if ([target caseInsensitiveCompare: @"xml"] == OFOrderedSame)
			if (!parseXMLProcessingInstruction(self, data))
			if (!parseXMLProcessingInstruction(self, text))
				@throw [OFMalformedXMLException
				    exceptionWithParser: self];

		if ([self->_delegate respondsToSelector: @selector(
		    parser:foundProcessingInstructionWithTarget:data:)])
		    parser:foundProcessingInstructionWithTarget:text:)])
			[self->_delegate parser: self
			    foundProcessingInstructionWithTarget: target
							    data: data];
							    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
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
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, *_data;
	OFString *_target, *_Nullable _text;
	OF_RESERVE_IVARS(OFXMLProcessingInstruction, 4)
}

/**
 * @brief The target of the processing instruction.
 */
@property (readonly, nonatomic) OFString *target;

/**
 * @brief The data of the processing instruction.
 * @brief The text of the processing instruction.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *data;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *text;

/**
 * @brief Creates a new OFXMLProcessingInstruction with the specified target
 *	  and data.
 *	  and text.
 *
 * @param target The target for the processing instruction
 * @param data The data for the processing instruction
 * @param text The text for the processing instruction
 * @return A new OFXMLProcessingInstruction
 */
+ (instancetype)processingInstructionWithTarget: (OFString *)target
					   data: (OFString *)data;
					   text: (OFString *)text;

/**
 * @brief Initializes an already allocated OFXMLProcessingInstruction with the
 *	  specified target and data.
 *	  specified target and text.
 *
 * @param target The target for the processing instruction
 * @param data The data for the processing instruction
 * @param text The text for the processing instruction
 * @return An initialized OFXMLProcessingInstruction
 */
- (instancetype)initWithTarget: (OFString *)target
			  data: (OFString *)data OF_DESIGNATED_INITIALIZER;
			  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
29

30
31
32

33
34
35

36
37
38
39

40
41
42
43
44
45

46
47
48
49
50
51
52
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, data = _data;
@synthesize target = _target, text = _text;

+ (instancetype)processingInstructionWithTarget: (OFString *)target
					   data: (OFString *)data
					   text: (OFString *)text
{
	return [[[self alloc] initWithTarget: target
					data: data] autorelease];
					text: text] autorelease];
}

- (instancetype)initWithTarget: (OFString *)target
			  data: (OFString *)data
			  text: (OFString *)text
{
	self = [super of_init];

	@try {
		_target = [target copy];
		_data = [data copy];
		_text = [text copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
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
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
				       data: element.stringValue];
				       text: element.stringValue];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_target release];
	[_data 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->_data != _data &&
	    ![processingInstruction->_data isEqual: _data])
	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, _data.hash);
	OFHashAddHash(&hash, _text.hash);
	OFHashFinalize(&hash);

	return hash;
}

- (OFString *)stringValue
{
	return @"";
}

- (OFString *)XMLString
{
	if (_data.length > 0)
	if (_text.length > 0)
		return [OFString stringWithFormat: @"<?%@ %@?>",
						   _target, _data];
						   _target, _text];
	else
		return [OFString stringWithFormat: @"<?%@?>", _target];
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
	return self.XMLString;
}

- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
				 level: (unsigned int)level
{
	if (indentation > 0 && level > 0) {
		OFString *ret;
		char *whitespaces = OFAllocMemory((level * indentation) + 1, 1);
		memset(whitespaces, ' ', level * indentation);
		whitespaces[level * indentation] = 0;

		@try {
			if (_data.length > 0)
				ret = [OFString stringWithFormat:
				    @"%s<?%@ %@?>", whitespaces,
				    _target, _data];
			else
				ret = [OFString stringWithFormat:
				    @"%s<?%@?>", whitespaces, _target];
		} @finally {
			OFFreeMemory(whitespaces);
		}

		return ret;
	} else
		return self.XMLString;
}

- (OFString *)description
{
	return self.XMLString;
}

- (OFXMLElement *)XMLElementBySerializing
{
	OFXMLElement *ret = [OFXMLElement elementWithName: self.className
						namespace: OFSerializationNS
					      stringValue: _data];
					      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
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
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
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;

#ifdef OF_HAVE_FILES
/**
 * @brief Creates a new OFZIPArchive object with the specified file.
 *
 * @param path The path to the ZIP 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)archiveWithPath: (OFString *)path mode: (OFString *)mode;
#endif
+ (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;

#ifdef OF_HAVE_FILES
/**
 * @brief Initializes an already allocated OFZIPArchive object with the
 *	  specified file.
 *
 * @param path The path to the ZIP 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)initWithPath: (OFString *)path mode: (OFString *)mode;
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode;
#endif

/**
 * @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

23
24
25



26

27

28
29
30

31
32
33


34
35
36
37
38
39
40
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 "OFCRC32.h"
#import "OFData.h"
#import "OFArray.h"
#import "OFArray.h"
#import "OFCRC32.h"
#import "OFData.h"
#import "OFDictionary.h"
#import "OFInflate64Stream.h"
#import "OFStream.h"
#import "OFInflateStream.h"
#import "OFSeekableStream.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#import "OFStream.h"
#endif
#import "OFInflateStream.h"
#import "OFInflate64Stream.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
63
64
65
66
67
68
69
70
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_closeLastReturnedStream;
- (void)of_writeCentralDirectory;
@end

OF_DIRECT_MEMBERS
@interface OFZIPArchiveLocalFileHeader: OFObject
{
@public
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
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;
	uint64_t _toRead;
	unsigned long long _toRead;
	uint32_t _CRC32;
	bool _atEndOfStream;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFZIPArchiveEntry *)entry;
- (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
	int64_t _bytesWritten;
	unsigned long long _bytesWritten;
	OFMutableZIPArchiveEntry *_entry;
}

- (instancetype)of_initWithArchive: (OFZIPArchive *)archive
- (instancetype)initWithStream: (OFStream *)stream
			 entry: (OFMutableZIPArchiveEntry *)entry;
			    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
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
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,
    OFFileOffset offset, int whence)
    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];
}

#ifdef OF_HAVE_FILES
+ (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode
+ (instancetype)archiveWithURI: (OFURI *)URI mode: (OFString *)mode
{
	return [[[self alloc] initWithPath: path mode: mode] autorelease];
	return [[[self alloc] initWithURI: URI mode: mode] autorelease];
}
#endif

+ (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
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
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,
			    (OFFileOffset)_offset, SEEK_SET);
			    (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;
}

#ifdef OF_HAVE_FILES
- (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode
- (instancetype)initWithURI: (OFURI *)URI mode: (OFString *)mode
{
	void *pool = objc_autoreleasePoolPush();
	OFFile *file;
	OFStream *stream;

	@try {
	if ([mode isEqual: @"a"])
		file = [[OFFile alloc] initWithPath: path mode: @"r+"];
	else
		if ([mode isEqual: @"a"])
			stream = [OFURIHandler openItemAtURI: URI mode: @"r+"];
		else
		file = [[OFFile alloc] initWithPath: path mode: mode];

	@try {
		self = [self initWithStream: file mode: mode];
			stream = [OFURIHandler openItemAtURI: URI mode: mode];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	self = [self initWithStream: stream mode: mode];
	} @finally {
		[file release];
	}

	objc_autoreleasePoolPop(pool);

	return self;
}
#endif

- (void)dealloc
{
	if (_stream != nil)
		[self close];

	[_stream release];
	[_archiveComment release];
	[_entries release];
	[_pathToEntryMap release];
	[_lastReturnedStream release];

	[super dealloc];
}

- (void)of_readZIPInfo
{
	void *pool = objc_autoreleasePoolPush();
	uint16_t commentLength;
	OFFileOffset offset = -22;
	OFStreamOffset offset = -22;
	bool valid = false;

	do {
		seekOrThrowInvalidFormat((OFSeekableStream *)_stream,
		    offset, SEEK_END);
		    offset, OFSeekEnd);

		if ([_stream readLittleEndianInt32] == 0x06054B50) {
			valid = true;
			break;
		}
	} while (--offset >= -65557);

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
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, SEEK_END);
		    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 || (OFFileOffset)offset64 != offset64)
		if (offset64 < 0 || (OFStreamOffset)offset64 != offset64)
			@throw [OFOutOfRangeException exception];

		seekOrThrowInvalidFormat((OFSeekableStream *)_stream,
		    (OFFileOffset)offset64, SEEK_SET);
		    (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
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
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 ||
		    (OFFileOffset)_centralDirectoryOffset !=
		    (OFStreamOffset)_centralDirectoryOffset !=
		    _centralDirectoryOffset)
			@throw [OFOutOfRangeException exception];
	}

	objc_autoreleasePoolPop(pool);
}

- (void)of_readEntries
{
	void *pool = objc_autoreleasePoolPush();

	if (_centralDirectoryOffset < 0 ||
	    (OFFileOffset)_centralDirectoryOffset != _centralDirectoryOffset)
	    (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset)
		@throw [OFOutOfRangeException exception];

	seekOrThrowInvalidFormat((OFSeekableStream *)_stream,
	    (OFFileOffset)_centralDirectoryOffset, SEEK_SET);
	    (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
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
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);
}

- (void)of_closeLastReturnedStream
{
	@try {
		[_lastReturnedStream close];
	} @catch (OFNotOpenException *e) {
		/* Might have already been closed by the user - that's fine. */
	}

	if ((_mode == modeWrite || _mode == modeAppend) &&
	    [_lastReturnedStream isKindOfClass:
	    [OFZIPArchiveFileWriteStream class]]) {
		OFZIPArchiveFileWriteStream *stream =
		    (OFZIPArchiveFileWriteStream *)_lastReturnedStream;

		if (INT64_MAX - _offset < stream->_bytesWritten)
			@throw [OFOutOfRangeException exception];

		_offset += stream->_bytesWritten;

		if (stream->_entry != nil) {
			[_entries addObject: stream->_entry];
			[_pathToEntryMap setObject: stream->_entry
					    forKey: [stream->_entry fileName]];
		}
	}

	[_lastReturnedStream release];
	_lastReturnedStream = nil;
}

- (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. */
	}
	[self of_closeLastReturnedStream];
	_lastReturnedStream = nil;

	offset64 = entry.of_localFileHeaderOffset;
	if (offset64 < 0 || (OFFileOffset)offset64 != offset64)
	if (offset64 < 0 || (OFStreamOffset)offset64 != offset64)
		@throw [OFOutOfRangeException exception];

	seekOrThrowInvalidFormat((OFSeekableStream *)_stream,
	    (OFFileOffset)offset64, SEEK_SET);
	    (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_initWithStream: _stream
			 entry: entry];
	_lastReturnedStream = [[[OFZIPArchiveFileReadStream alloc]
	    of_initWithArchive: self
			stream: _stream
			 entry: entry] autorelease];

	objc_autoreleasePoolPop(pool);

	return [[_lastReturnedStream retain] 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





510

511
512
513
514
515
516
517
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. */
	}
	[self of_closeLastReturnedStream];
	_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

563
564


565
566
567
568

569
570
571
572
573
574
575
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
	     initWithStream: _stream
		      entry: entry];
			stream: _stream
			 entry: entry];

	objc_autoreleasePoolPop(pool);

	return [[_lastReturnedStream retain] autorelease];
	return [_lastReturnedStream autorelease];
}

- (void)of_writeCentralDirectory
{
	void *pool = objc_autoreleasePoolPush();

	_centralDirectoryEntries = 0;
618
619
620
621
622
623
624





625

626
627
628
629
630
631
632
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. */
	}
	[self of_closeLastReturnedStream];
	_lastReturnedStream = nil;

	if (_mode == modeWrite || _mode == modeAppend)
		[self of_writeCentralDirectory];

	[_stream release];
	_stream = nil;
}
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
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 =
			    OFRangeMake(ZIP64Index - 4, ZIP64Size + 4);
			    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
735
736



737
738
739
740

741
742
743
744
745
746
747
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_initWithStream: (OFStream *)stream
			    entry: (OFZIPArchiveEntry *)entry
- (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
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
808

809
810
811
812
813
814
815
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 ((uint64_t)length > _toRead)
	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

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
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
- (instancetype)initWithStream: (OFStream *)stream
			 entry: (OFMutableZIPArchiveEntry *)entry
			    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 (INT64_MAX - _bytesWritten < (int64_t)length)
	if (ULLONG_MAX - _bytesWritten < length)
		@throw [OFOutOfRangeException exception];

	@try {
		[_stream writeBuffer: buffer length: length];
	} @catch (OFWriteFailedException *e) {
		OFEnsure(e.bytesWritten <= length);

		_bytesWritten += (int64_t)e.bytesWritten;
		_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 += (int64_t)length;
	_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: _bytesWritten];
	[_stream writeLittleEndianInt64: _bytesWritten];
	[_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
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
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
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
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 <OFCopying, OFMutableCopying>
@interface OFZIPArchiveEntry: OFObject <OFArchiveEntry, OFCopying,
    OFMutableCopying>
{
	OFZIPArchiveEntryAttributeCompatibility _versionMadeBy;
	OFZIPArchiveEntryAttributeCompatibility _minVersionNeeded;
	uint16_t _generalPurposeBitFlag;
	OFZIPArchiveEntryCompressionMethod _compressionMethod;
	uint16_t _lastModifiedFileTime, _lastModifiedFileDate;
	uint32_t _CRC32;
	uint64_t _compressedSize, _uncompressedSize;
	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 file name of the entry.
 */
@property (readonly, copy, nonatomic) OFString *fileName;

/**
 * @brief The comment of the entry's file.
 */
@property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic)
    OFString *fileComment;

/**
 * @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
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
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 last modification date of the entry's file.
 *
 * @note Due to limitations of the ZIP format, this has only 2 second precision.
 */
@property (readonly, retain, nonatomic) OFDate *modificationDate;

/**
 * @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 compressed size of the entry's file.
 */
@property (readonly, nonatomic) uint64_t compressedSize;

/**
 * @brief The uncompressed size of the entry's file.
 */
@property (readonly, nonatomic) uint64_t uncompressedSize;

/**
 * @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;

/**
 * @brief Creates a new OFZIPArchiveEntry with the specified file name.
 *
 * @param fileName The file name for the OFZIPArchiveEntry
 * @return A new, autoreleased OFZIPArchiveEntry
 */
+ (instancetype)entryWithFileName: (OFString *)fileName;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFZIPArchiveEntry with the specified
 *	  file name.
 *
 * @param fileName The file name for the OFZIPArchiveEntry
 * @return An initialized OFZIPArchiveEntry
 */
- (instancetype)initWithFileName: (OFString *)fileName;
@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
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
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)entryWithFileName: (OFString *)fileName
{
	return [[[self alloc] initWithFileName: fileName] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithFileName: (OFString *)fileName
- (instancetype)of_init
{
	self = [super init];
	return [super 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;
}

- (instancetype)of_initWithStream: (OFStream *)stream
{
	self = [super init];

	@try {
251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
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 =
			    OFRangeMake(ZIP64Index - 4, ZIP64Size + 4);
			    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
390

391
392
393
394
395

396
397
398
399
400
401
402
362
363
364
365
366
367
368

369
370
371
372
373

374
375
376
377
378
379
380
381







-
+




-
+







}

- (OFZIPArchiveEntryCompressionMethod)compressionMethod
{
	return _compressionMethod;
}

- (uint64_t)compressedSize
- (unsigned long long)compressedSize
{
	return _compressedSize;
}

- (uint64_t)uncompressedSize
- (unsigned long long)uncompressedSize
{
	return _uncompressedSize;
}

- (uint32_t)CRC32
{
	return _CRC32;

Modified src/ObjFW.h from [e47897350b] to [4cea05be8a].

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
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







-
-
+
+






+
+













+
-
-
+
+
-








#import "OFMethodSignature.h"
#import "OFInvocation.h"

#import "OFNumber.h"
#import "OFDate.h"
#import "OFUUID.h"
#import "OFURL.h"
#import "OFURLHandler.h"
#import "OFURI.h"
#import "OFURIHandler.h"
#import "OFColor.h"

#import "OFNotification.h"
#import "OFNotificationCenter.h"

#import "OFStream.h"
#import "OFSeekableStream.h"
#import "OFMemoryStream.h"
#import "OFStdIOStream.h"
#import "OFInflateStream.h"
#import "OFInflate64Stream.h"
#import "OFGZIPStream.h"
#import "OFLHAArchive.h"
#import "OFLHAArchiveEntry.h"
#import "OFTarArchive.h"
#import "OFTarArchiveEntry.h"
#import "OFZIPArchive.h"
#import "OFZIPArchiveEntry.h"
#import "OFFileManager.h"
#ifdef OF_HAVE_FILES
# import "OFFile.h"
#endif
# import "OFINIFile.h"
# import "OFSettings.h"
#import "OFINIFile.h"
#import "OFSettings.h"
#endif
#ifdef OF_HAVE_SOCKETS
# import "OFStreamSocket.h"
# import "OFDatagramSocket.h"
# import "OFSequencedPacketSocket.h"
# import "OFTCPSocket.h"
# import "OFUDPSocket.h"
# import "OFTLSStream.h"
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
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 "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChangeCurrentDirectoryFailedException.h"
#import "OFChecksumMismatchException.h"
#ifdef OF_HAVE_THREADS
# import "OFConditionBroadcastFailedException.h"
# import "OFConditionSignalFailedException.h"
# import "OFConditionStillWaitingException.h"
# import "OFConditionWaitFailedException.h"
#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


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
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 "OFGetCurrentDirectoryPathFailedException.h"
# 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 "OFInvalidServerReplyException.h"
#import "OFLinkFailedException.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 "OFMemoryNotPartOfObjectException.h"
#import "OFMoveItemFailedException.h"
#import "OFNotImplementedException.h"
#import "OFNotOpenException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFObserveFailedException.h"
# 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 "OFRetrieveItemAttributesFailedException.h"
#import "OFSeekFailedException.h"
#import "OFSetItemAttributesFailedException.h"
#import "OFSetOptionFailedException.h"
#ifdef OF_WINDOWS
# import "OFSetWindowsRegistryValueFailedException.h"
#endif
#import "OFStillLockedException.h"
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
260
261
262
263
264
265
266

267
268





269
270








-


-
-
-
-
-


-
# import "OFCondition.h"
# import "OFMutex.h"
# import "OFPlainCondition.h"
# import "OFPlainMutex.h"
# import "OFPlainThread.h"
# import "OFRecursiveMutex.h"
# import "OFTLSKey.h"
# import "OFThreadPool.h"
#endif

#import "OFASPrintF.h"
#import "OFBase64.h"
#import "OFCRC16.h"
#import "OFCRC32.h"
#import "OFHuffmanTree.h"
#import "OFPBKDF2.h"
#import "OFScrypt.h"
#import "OFStrPTime.h"

Modified src/exceptions/Makefile from [d0a796337a] to [a8a6570db6].

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
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






-






+








-
-
+
+


-









-


















+
-
+








-
+







include ../../extra.mk

STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A}
STATIC_LIB_NOINST = ${EXCEPTIONS_A}

SRCS = OFAllocFailedException.m				\
       OFChangeCurrentDirectoryPathFailedException.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				\
       OFInvalidServerReplyException.m			\
       OFLinkFailedException.m				\
       OFInvalidServerResponseException.m		\
       OFLinkItemFailedException.m			\
       OFLockFailedException.m				\
       OFMalformedXMLException.m			\
       OFMemoryNotPartOfObjectException.m		\
       OFMoveItemFailedException.m			\
       OFNotImplementedException.m			\
       OFNotOpenException.m				\
       OFOpenItemFailedException.m			\
       OFOutOfMemoryException.m				\
       OFOutOfRangeException.m				\
       OFReadFailedException.m				\
       OFReadOrWriteFailedException.m			\
       OFRemoveItemFailedException.m			\
       OFRetrieveItemAttributesFailedException.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	\
SRCS_FILES = OFGetCurrentDirectoryPathFailedException.m
	     OFGetCurrentDirectoryFailedException.m
SRCS_PLUGINS = OFLoadPluginFailedException.m
SRCS_SOCKETS = OFAcceptFailedException.m		\
	       OFAlreadyConnectedException.m		\
	       OFBindFailedException.m			\
	       OFConnectionFailedException.m		\
	       OFDNSQueryFailedException.m		\
	       OFHTTPRequestFailedException.m		\
	       OFListenFailedException.m		\
	       OFObserveFailedException.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
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
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
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 [cce9c4501d] to [9447c1c83e].

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
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







-
+







+





-
+







 *	  OFBindFailedException.h ObjFW/OFBindFailedException.h
 *
 * @brief An exception indicating that binding a socket failed.
 */
@interface OFBindFailedException: OFException
{
	/* IP */
	OFString *_host;
	OFString *_Nullable _host;
	uint16_t _port;
	/* IPX */
	uint8_t _packetType;
	/* UNIX socket */
	OFString *_Nullable _path;
	id _socket;
	int _errNo;
	OF_RESERVE_IVARS(OFBindFailedException, 4)
}

/**
 * @brief The host on which binding failed.
 */
@property (readonly, nonatomic) OFString *host;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host;

/**
 * @brief The port on which binding failed.
 */
@property (readonly, nonatomic) uint16_t port;

/**
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
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







-
-













+
+







@property (readonly, nonatomic) id socket;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased bind failed exception.
 *
 * @param host The host on which binding failed
 * @param port The port on which binding failed
 * @param socket The socket which could not be bound
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased bind failed exception
 */
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket
			    errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased bind failed exception.
 *
 * @param port The IPX port to which binding failed
 * @param packetType The IPX packet type for which binding failed
 * @param socket The socket which could not be bound
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
111
112
113
114
115
116
117


118
119
120
121
122
123
124







-
-







 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased bind failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path
			   socket: (id)socket
			    errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated bind failed exception.
 *
 * @param host The host on which binding failed
 * @param port The port on which binding failed
 * @param socket The socket which could not be bound
 * @param errNo The errno of the error that occurred
150
151
152
153
154
155
156


157
158
159
149
150
151
152
153
154
155
156
157
158
159
160







+
+



 * @param socket The socket which could not be bound
 * @param errNo The errno of the error that occurred
 * @return An initialized bind failed exception
 */
- (instancetype)initWithPath: (OFString *)path
		      socket: (id)socket
		       errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.h [b19c09d67c] to src/exceptions/OFChangeCurrentDirectoryFailedException.h [c93252d4da].

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
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







-
-
-
+
+
+




-
+



+













-
-











-
+











+
+



 */

#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFChangeCurrentDirectoryPathFailedException \
 *	  OFChangeCurrentDirectoryPathFailedException.h \
 *	  ObjFW/OFChangeCurrentDirectoryPathFailedException.h
 * @class OFChangeCurrentDirectoryFailedException \
 *	  OFChangeCurrentDirectoryFailedException.h \
 *	  ObjFW/OFChangeCurrentDirectoryFailedException.h
 *
 * @brief An exception indicating that changing the current directory path
 *	  failed.
 */
@interface OFChangeCurrentDirectoryPathFailedException: OFException
@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;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased change current directory path failed
 *	  exception.
 *
 * @param path The path of the directory to which the current path could not be
 *	       changed
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased change current directory path failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated change directory failed exception.
 *
 * @param path The path of the directory to which the current path could not be
 *	       changed
 * @param errNo The errno of the error that occurred
 * @return An initialized change current directory path failed exception
 */
- (instancetype)initWithPath: (OFString *)path
		       errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.m [e479f99364] to src/exceptions/OFChangeCurrentDirectoryFailedException.m [7267a7e220].

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
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







-
+


-
+


-
-
-
-
-





-
+

-
+
















+
+
+
+
+











-
+



 * 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 "OFChangeCurrentDirectoryPathFailedException.h"
#import "OFChangeCurrentDirectoryFailedException.h"
#import "OFString.h"

@implementation OFChangeCurrentDirectoryPathFailedException
@implementation OFChangeCurrentDirectoryFailedException
@synthesize path = _path, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo
{
	return [[[self alloc] initWithPath: path errNo: errNo] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithPath: (OFString *)path errNo: (int)errNo
{
	self = [super init];

	@try {
		_path = [path copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_path release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to change the current directory path to %@: %@",
	    @"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
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 [5b7dda8eaf] to [920b114a94].

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
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







+





-
+













-
+

+
+








-
+






 *
 * @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 OF_NULLABLE_PROPERTY (readonly, nonatomic) OFCondition *condition;
@property (readonly, nonatomic) OFCondition *condition;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

/**
 * @brief Returns a new, autoreleased condition broadcast failed exception.
 *
 * @param condition The condition which could not be broadcasted
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased condition broadcast failed exception
 */
+ (instancetype)exceptionWithCondition: (nullable OFCondition *)condition
+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated condition broadcast failed exception.
 *
 * @param condition The condition which could not be broadcasted
 * @param errNo The errno of the error that occurred
 * @return An initialized condition broadcast failed exception
 */
- (instancetype)initWithCondition: (nullable OFCondition *)condition
- (instancetype)initWithCondition: (OFCondition *)condition
			    errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFConditionBroadcastFailedException.m from [f91e77933c] to [0c18d20911].

26
27
28
29
30
31
32





33
34
35
36
37
38
39
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+
+








+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo
{
	return [[[self alloc] initWithCondition: condition
					  errNo: errNo] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo
{
	self = [super init];

	_condition = [condition retain];
	_errNo = errNo;

Modified src/exceptions/OFConditionSignalFailedException.h from [adad767da9] to [fd45072644].

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
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







+





-
+













-
+

+
+








-
+






 *
 * @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 OF_NULLABLE_PROPERTY (readonly, nonatomic) OFCondition *condition;
@property (readonly, nonatomic) OFCondition *condition;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

/**
 * @brief Creates a new, autoreleased condition signal failed exception.
 *
 * @param condition The condition which could not be signaled
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased condition signal failed exception
 */
+ (instancetype)exceptionWithCondition: (nullable OFCondition *)condition
+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated condition signal failed exception.
 *
 * @param condition The condition which could not be signaled
 * @param errNo The errno of the error that occurred
 * @return An initialized condition signal failed exception
 */
- (instancetype)initWithCondition: (nullable OFCondition *)condition
- (instancetype)initWithCondition: (OFCondition *)condition
			    errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFConditionSignalFailedException.m from [372841b0e4] to [7b1b56675f].

26
27
28
29
30
31
32





33
34
35
36
37
38
39
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+
+








+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo
{
	return [[[self alloc] initWithCondition: condition
					  errNo: errNo] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo
{
	self = [super init];

	_condition = [condition retain];
	_errNo = errNo;

Modified src/exceptions/OFConditionStillWaitingException.h from [05c3183470] to [6424437193].

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
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







+





-
+







-
+
+
+







-
+

+
+



 *
 * @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 OF_NULLABLE_PROPERTY (readonly, nonatomic) OFCondition *condition;
@property (readonly, nonatomic) OFCondition *condition;

/**
 * @brief Creates a new, autoreleased condition still waiting exception.
 *
 * @param condition The condition for which is still being waited
 * @return A new, autoreleased condition still waiting exception
 */
+ (instancetype)exceptionWithCondition: (nullable OFCondition *)condition;
+ (instancetype)exceptionWithCondition: (OFCondition *)condition;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated condition still waiting exception.
 *
 * @param condition The condition for which is still being waited
 * @return An initialized condition still waiting exception
 */
- (instancetype)initWithCondition: (nullable OFCondition *)condition
- (instancetype)initWithCondition: (OFCondition *)condition
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFConditionStillWaitingException.m from [a171b7f96b] to [28d38d170f].

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
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







-
+

-
+










+
+
+
+
+










-
-
-
-
-
+
+
+
+
-
-
-


@synthesize condition = _condition;

+ (instancetype)exceptionWithCondition: (OFCondition *)condition
{
	return [[[self alloc] initWithCondition: condition] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	return [self initWithCondition: nil];
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithCondition: (OFCondition *)condition
{
	self = [super init];

	_condition = [condition retain];

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_condition release];

	[super dealloc];
}

- (OFString *)description
{
	if (_condition != nil)
		return [OFString stringWithFormat:
		    @"Deallocation of a condition of type %@ was tried, even "
		    "though a thread was still waiting for it!",
		    _condition.class];
	return [OFString stringWithFormat:
	    @"Deallocation of a condition of type %@ was tried, even though "
	    "a thread was still waiting for it!",
	    _condition.class];
	else
		return @"Deallocation of a condition was tried, even though a "
		    "thread was still waiting for it!";
}
@end

Modified src/exceptions/OFConditionWaitFailedException.h from [34a34c8f45] to [219a53d1c9].

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
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







+





-
+













-
+

+
+








-
+






 *
 * @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 OF_NULLABLE_PROPERTY (readonly, nonatomic) OFCondition *condition;
@property (readonly, nonatomic) OFCondition *condition;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

/**
 * @brief Creates a new, autoreleased condition wait failed exception.
 *
 * @param condition The condition for which could not be waited
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased condition wait failed exception
 */
+ (instancetype)exceptionWithCondition: (nullable OFCondition *)condition
+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated condition wait failed exception.
 *
 * @param condition The condition for which could not be waited
 * @param errNo The errno of the error that occurred
 * @return An initialized condition wait failed exception
 */
- (instancetype)initWithCondition: (nullable OFCondition *)condition
- (instancetype)initWithCondition: (OFCondition *)condition
			    errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFConditionWaitFailedException.m from [da9da9acc0] to [5702b9d98a].

26
27
28
29
30
31
32





33
34
35
36
37
38
39
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+
+
+








+ (instancetype)exceptionWithCondition: (OFCondition *)condition
				 errNo: (int)errNo
{
	return [[[self alloc] initWithCondition: condition
					  errNo: errNo] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo
{
	self = [super init];

	_condition = [condition retain];
	_errNo = errNo;

Modified src/exceptions/OFConnectionFailedException.h from [ee6b1c27c4] to [3f23880b21].

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
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







-
+

-
+

-
+


+













-
+

-
+







-
+

-
+











-
-









-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
















+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+










-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



 * @class OFConnectionFailedException \
 *	  OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h
 *
 * @brief An exception indicating that a connection could not be established.
 */
@interface OFConnectionFailedException: OFException
{
	OFString *_host;
	OFString *_Nullable _host;
	uint16_t _port;
	unsigned char _node[IPX_NODE_LEN];
	OFString *_Nullable _path;
	uint32_t _network;
	OFString *_Nullable _path;
	unsigned char _node[IPX_NODE_LEN];
	id _socket;
	int _errNo;
	OF_RESERVE_IVARS(OFConnectionFailedException, 4)
}

/**
 * @brief The host to which the connection failed.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host;

/**
 * @brief The port on the host to which the connection failed.
 */
@property (readonly, nonatomic) uint16_t port;

/**
 * @brief The IPX node to which the connection failed.
 * @brief The path to which the connection failed.
 */
@property (readonly, nonatomic) unsigned char *node;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path;

/**
 * @brief The IPX network of the node to which the connection failed.
 */
@property (readonly, nonatomic) uint32_t network;

/**
 * @brief The path to which the connection failed.
 * @brief The IPX node to which the connection failed.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *path;
@property (readonly, nonatomic) unsigned char *node;

/**
 * @brief The socket which could not connect.
 */
@property (readonly, nonatomic) id socket;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased connection failed exception.
 *
 * @param host The host to which the connection failed
 * @param port The port on the host to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased connection failed exception
 */
+ (instancetype)exceptionWithHost: (nullable OFString *)host
+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (id)socket
			    errNo: (int)errNo;

/**
 * @brief Creates a new, autoreleased connection failed exception.
 *
 * @param node The node to which the connection failed
 * @param network The IPX network of the node to which the connection failed
 * @param port The port on the node to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased connection failed exception
 */
+ (instancetype)exceptionWithNode: (unsigned char [_Nullable IPX_NODE_LEN])node
			  network: (uint32_t)network
			     port: (uint16_t)port
			   socket: (id)socket
			    errNo: (int)errNo;

/**
 * @brief Creates a new, autoreleased connection failed exception.
 *
 * @param path The path to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased connection failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path
			   socket: (id)socket
			    errNo: (int)errNo;

/**
 * @brief Creates a new, autoreleased connection failed exception.
 *
 * @param network The IPX network of the node to which the connection failed
 * @param node The node to which the connection failed
 * @param port The port on the node to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased connection failed exception
 */
- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)
    exceptionWithNetwork: (uint32_t)network
		    node: (unsigned char [_Nullable IPX_NODE_LEN])node
		    port: (uint16_t)port
		  socket: (id)socket
		   errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated connection failed exception.
 *
 * @param host The host to which the connection failed
 * @param port The port on the host to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return An initialized connection failed exception
 */
- (instancetype)initWithHost: (nullable OFString *)host
- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      socket: (id)socket
		       errNo: (int)errNo;

/**
 * @brief Initializes an already allocated connection failed exception.
 *
 * @param node The node to which the connection failed
 * @param network The IPX network of the node to which the connection failed
 * @param port The port on the node to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return An initialized connection failed exception
 */
- (instancetype)initWithNode: (unsigned char [_Nullable IPX_NODE_LEN])node
		     network: (uint32_t)network
			port: (uint16_t)port
		      socket: (id)socket
		       errNo: (int)errNo;

/**
 * @brief Initializes an already allocated connection failed exception.
 *
 * @param path The path to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return An initialized connection failed exception
 */
- (instancetype)initWithPath: (OFString *)path
		      socket: (id)socket
		       errNo: (int)errNo;

/**
 * @brief Initializes an already allocated connection failed exception.
 *
 * @param network The IPX network of the node to which the connection failed
 * @param node The node to which the connection failed
 * @param port The port on the node to which the connection failed
 * @param socket The socket which could not connect
 * @param errNo The errno of the error that occurred
 * @return An initialized connection failed exception
 */
- (instancetype)initWithNetwork: (uint32_t)network
			   node: (unsigned char [_Nullable IPX_NODE_LEN])node
			   port: (uint16_t)port
			 socket: (id)socket
			  errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFConnectionFailedException.m from [6f77903dfd] to [2c0b32486f].

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
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







-
+


-
-
-
-
-











-
+
-
-
-
-

-
-
-
-
-
+











-
+
+
+
+
+

-
+
+
+
+
+












-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-








#include "config.h"

#import "OFConnectionFailedException.h"
#import "OFString.h"

@implementation OFConnectionFailedException
@synthesize host = _host, port = _port, network = _network, path = _path;
@synthesize host = _host, port = _port, path = _path, network = _network;
@synthesize socket = _socket, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithHost: (OFString *)host
			     port: (uint16_t)port
			   socket: (id)sock
			    errNo: (int)errNo
{
	return [[[self alloc] initWithHost: host
				      port: port
				    socket: sock
				     errNo: errNo] autorelease];
}

+ (instancetype)exceptionWithNode: (unsigned char [IPX_NODE_LEN])node
+ (instancetype)exception
			  network: (uint32_t)network
			     port: (uint16_t)port
			   socket: (id)sock
			    errNo: (int)errNo
{
	return [[[self alloc] initWithNode: node
				   network: network
				      port: port
				    socket: sock
				     errNo: errNo] autorelease];
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithPath: (OFString *)path
			   socket: (id)sock
			    errNo: (int)errNo
{
	return [[[self alloc] initWithPath: path
				    socket: sock
				     errNo: errNo] autorelease];
}

- (instancetype)init
+ (instancetype)exceptionWithNetwork: (uint32_t)network
				node: (unsigned char [IPX_NODE_LEN])node
				port: (uint16_t)port
			      socket: (id)sock
			       errNo: (int)errNo
{
	OF_INVALID_INIT_METHOD
	return [[[self alloc] initWithNetwork: network
					 node: node
					 port: port
				       socket: sock
					errNo: errNo] autorelease];
}

- (instancetype)initWithHost: (OFString *)host
			port: (uint16_t)port
		      socket: (id)sock
		       errNo: (int)errNo
{
	self = [super init];

	@try {
		_host = [host copy];
		_port = port;
		_socket = [sock retain];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithNode: (unsigned char [IPX_NODE_LEN])node
		     network: (uint32_t)network
			port: (uint16_t)port
		      socket: (id)sock
		       errNo: (int)errNo
{
	self = [super init];

	@try {
		memcpy(_node, node, IPX_NODE_LEN);
		_network = network;
		_port = port;
		_socket = [sock retain];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

120
121
122
123
124
125
126



























127
128
129
130
131
132
133
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)initWithNetwork: (uint32_t)network
			   node: (unsigned char [IPX_NODE_LEN])node
			   port: (uint16_t)port
			 socket: (id)sock
			  errNo: (int)errNo
{
	self = [super init];

	@try {
		_network = network;
		memcpy(_node, node, IPX_NODE_LEN);
		_port = port;
		_socket = [sock retain];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_host release];
	[_path release];
	[_socket release];

Modified src/exceptions/OFCopyItemFailedException.h from [688510c190] to [123bfde77a].

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
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 OFURL;
@class OFURI;

/**
 * @class OFCopyItemFailedException \
 *	  OFCopyItemFailedException.h ObjFW/OFCopyItemFailedException.h
 *
 * @brief An exception indicating that copying a item failed.
 */
@interface OFCopyItemFailedException: OFException
{
	OFURL *_sourceURL, *_destinationURL;
	OFURI *_sourceURI, *_destinationURI;
	int _errNo;
	OF_RESERVE_IVARS(OFCopyItemFailedException, 4)
}

/**
 * @brief The path of the source item.
 * @brief The URI of the source item.
 */
@property (readonly, nonatomic) OFURL *sourceURL;
@property (readonly, nonatomic) OFURI *sourceURI;

/**
 * @brief The destination path.
 * @brief The destination URI.
 */
@property (readonly, nonatomic) OFURL *destinationURL;
@property (readonly, nonatomic) OFURI *destinationURI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased copy item failed exception.
 *
 * @param sourceURL The original path
 * @param destinationURL The new path
 * @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)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated copy item failed exception.
 *
 * @param sourceURL The original path
 * @param destinationURL The new path
 * @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)initWithSourceURL: (OFURL *)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFCopyItemFailedException
@synthesize sourceURL = _sourceURL, destinationURL = _destinationURL;
@synthesize sourceURI = _sourceURI, destinationURI = _destinationURI;
@synthesize errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo
{
	return [[[self alloc] initWithSourceURL: sourceURL
				 destinationURL: destinationURL
	return [[[self alloc] initWithSourceURI: sourceURI
				 destinationURI: destinationURI
					  errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithSourceURL: (OFURL *)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (instancetype)initWithSourceURI: (OFURI *)sourceURI
		   destinationURI: (OFURI *)destinationURI
			    errNo: (int)errNo
{
	self = [super init];

	@try {
		_sourceURL = [sourceURL copy];
		_destinationURL = [destinationURL copy];
		_sourceURI = [sourceURI copy];
		_destinationURI = [destinationURI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_sourceURL release];
	[_destinationURL release];
	[_sourceURI release];
	[_destinationURI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@",
	    _sourceURL, _destinationURL, OFStrError(_errNo)];
	    _sourceURI, _destinationURI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFCreateDirectoryFailedException.h from [181da1d1b3] to [e16c672401].

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
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 OFURL;
@class OFURI;

/**
 * @class OFCreateDirectoryFailedException \
 *	  OFCreateDirectoryFailedException.h \
 *	  ObjFW/OFCreateDirectoryFailedException.h
 *
 * @brief An exception indicating a directory couldn't be created.
 */
@interface OFCreateDirectoryFailedException: OFException
{
	OFURL *_URL;
	OFURI *_URI;
	int _errNo;
	OF_RESERVE_IVARS(OFCreateDirectoryFailedException, 4)
}

/**
 * @brief The URL of the directory which couldn't be created.
 * @brief The URI of the directory which couldn't be created.
 */
@property (readonly, nonatomic) OFURL *URL;
@property (readonly, nonatomic) OFURI *URI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased create directory failed exception.
 *
 * @param URL The URL of the directory which could not be created
 * @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)exceptionWithURL: (OFURL *)URL errNo: (int)errNo;
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated create directory failed exception.
 *
 * @param URL The URL of the directory which could not be created
 * @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)initWithURL: (OFURL *)URL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFCreateDirectoryFailedException
@synthesize URL = _URL, errNo = _errNo;
@synthesize URI = _URI, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL errNo: errNo] autorelease];
	return [[[self alloc] initWithURI: URI errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo
- (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to create directory %@: %@", _URL, OFStrError(_errNo)];
	    @"Failed to create directory %@: %@", _URI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFCreateSymbolicLinkFailedException.h from [4a1beb3f78] to [79c2f6b7ee].

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
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 OFURL;
@class OFURI;

/**
 * @class OFCreateSymbolicLinkFailedException \
 *	  OFCreateSymbolicLinkFailedException.h \
 *	  ObjFW/OFCreateSymbolicLinkFailedException.h
 *
 * @brief An exception indicating that creating a symbolic link failed.
 */
@interface OFCreateSymbolicLinkFailedException: OFException
{
	OFURL *_URL;
	OFURI *_URI;
	OFString *_target;
	int _errNo;
	OF_RESERVE_IVARS(OFCreateSymbolicLinkFailedException, 4)
}

/**
 * @brief The URL at which the symlink should have been created.
 * @brief The URI at which the symlink should have been created.
 */
@property (readonly, nonatomic) OFURL *URL;
@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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased create symbolic link failed exception.
 *
 * @param URL The URL where the symlink should have been created
 * @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)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
			  target: (OFString *)target
			   errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated create symbolic link failed
 *	  exception.
 *
 * @param URL The URL where the symlink should have been created
 * @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)initWithURL: (OFURL *)URL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFCreateSymbolicLinkFailedException
@synthesize URL = _URL, target = _target, errNo = _errNo;
@synthesize URI = _URI, target = _target, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
			  target: (OFString *)target
			   errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL
	return [[[self alloc] initWithURI: URI
				   target: target
				    errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURI: (OFURI *)URI
		     target: (OFString *)target
		      errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_target = [target copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];
	[_target release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to create symbolic link %@ with target %@: %@",
	    _URL, _target, OFStrError(_errNo)];
	    _URI, _target, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.h from [f321fddf5e] to [3739e39dc2].

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
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 _securityAndAccessRights;
	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 options for the subkey that could not be created.
 */
@property (readonly, nonatomic) DWORD options;

/**
 * @brief The security and access rights for the subkey that could not be
 * @brief The access rights for the subkey that could not be created.
 *	  created.
 */
@property (readonly, nonatomic) REGSAM securityAndAccessRights;
@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 options The options for the subkey that could not be created
 * @param accessRights The access rights for the sub key that could not be
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 *		       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
		     options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		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 options The options for the subkey that could not be created
 * @param accessRights The access rights for the sub key that could not be
 * @param securityAndAccessRights The security and access rights for the sub
 *				  key that could not be created
 *		       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
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	       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
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
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, options = _options;
@synthesize securityAndAccessRights = _securityAndAccessRights;
@synthesize securityAttributes = _securityAttributes, status = _status;
@synthesize registryKey = _registryKey, path = _path;
@synthesize accessRights = _accessRights;
@synthesize securityAttributes = _securityAttributes, options = _options;
@synthesize status = _status;

+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		accessRights: (REGSAM)accessRights
	  securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		     options: (DWORD)options
		      status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					     path: path
					  options: options
			  securityAndAccessRights: securityAndAccessRights
				     accessRights: accessRights
			       securityAttributes: securityAttributes
					  options: options
					   status: status] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
	 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
		     status: (LSTATUS)status
		       accessRights: (REGSAM)accessRights
		 securityAttributes: (LPSECURITY_ATTRIBUTES)securityAttributes
			    options: (DWORD)options
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_path = [path copy];
		_options = options;
		_securityAndAccessRights = securityAndAccessRights;
		_accessRights = accessRights;
		_securityAttributes = securityAttributes;
		_options = options;
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;

Modified src/exceptions/OFDNSQueryFailedException.h from [c91d3240d5] to [e0cf12b730].

26
27
28
29
30
31
32

33
34
35
36
37
38
39
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;

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
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







+
+









+
+












 * @param query The query which could not be performed
 * @param errorCode The error from the resolver
 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithQuery: (OFDNSQuery *)query
			 errorCode: (OFDNSResolverErrorCode)errorCode;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated DNS query failed exception.
 *
 * @param query The query which could not be performed
 * @param errorCode The error from the resolver
 * @return An initialized address translation failed exception
 */
- (instancetype)initWithQuery: (OFDNSQuery *)query
		    errorCode: (OFDNSResolverErrorCode)errorCode;

- (instancetype)init OF_UNAVAILABLE;
@end

#ifdef __cplusplus
extern "C" {
#endif
extern OFString *OFDNSResolverErrorCodeDescription(
    OFDNSResolverErrorCode errorCode);
#ifdef __cplusplus
}
#endif

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFDNSQueryFailedException.m from [bf738fa470] to [d34eb3c9de].

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
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







+
+
+
+
+
















+
+
+
+
+








+ (instancetype)exceptionWithQuery: (OFDNSQuery *)query
			 errorCode: (OFDNSResolverErrorCode)errorCode
{
	return [[[self alloc] initWithQuery: query
				  errorCode: errorCode] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithQuery: (OFDNSQuery *)query
		    errorCode: (OFDNSResolverErrorCode)errorCode
{
	self = [super init];

	@try {
		_query = [query copy];
		_errorCode = errorCode;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_query release];

	[super dealloc];
}

Modified src/exceptions/OFDeleteWindowsRegistryKeyFailedException.h from [ce80a5fb98] to [7a006ec7b5].

28
29
30
31
32
33
34

35
36
37
38
39
40
41
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
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 [3a61865e6c] to [1a130e7399].

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
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







+







-
-








-
+








+
+



 *
 * @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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased enumeration mutation exception.
 *
 * @param object The object which was mutated during enumeration
 * @return A new, autoreleased enumeration mutation exception
 */
+ (instancetype)exceptionWithObject: (id)object;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated enumeration mutation exception.
 *
 * @param object The object which was mutated during enumeration
 * @return An initialized enumeration mutation exception
 */
- (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFException.h from [e8334cf8f9] to [e7c0836484].

18
19
20
21
22
23
24
25
26


27
28

29
30
31
32
33
34
35
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 OFMutableArray OF_GENERIC(ObjectType);
@class OFString;
@class OFString;
@class OFValue;

#define OFBacktraceSize 16
#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
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
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 *_backtrace[OFBacktraceSize];
	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 backtrace of when the exception was created or nil if no
 *	  backtrace is available.
 * @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;

/**
 * @return A backtrace of when the exception was created
 * @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 *) *)backtrace;
- (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
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
261

262
263
264
265
266
267
268
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 < OFBacktraceSize) {
	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
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
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 = _backtrace;
	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(OFString *) *)backtrace
- (OFArray OF_GENERIC(OFValue *) *)stackTraceAddresses
{
#ifdef HAVE__UNWIND_BACKTRACE
	OFMutableArray OF_GENERIC(OFString *) *backtrace =
	OFMutableArray OF_GENERIC(OFValue *) *stackTrace =
	    [OFMutableArray array];
	void *pool = objc_autoreleasePoolPush();

	for (uint_fast8_t i = 0; i < OFStackTraceSize &&
	for (uint8_t i = 0; i < OFBacktraceSize && _backtrace[i] != NULL; i++) {
# ifdef HAVE_DLADDR
	    _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(_backtrace[i], &info)) {
		if (dladdr(_stackTrace[i], &info)) {
			ptrdiff_t offset = (char *)_stackTrace[i] -
			    (char *)info.dli_saddr;
			OFString *frame;

			if (info.dli_sname != NULL) {
				ptrdiff_t offset = (char *)_backtrace[i] -
				    (char *)info.dli_saddr;

			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:
				    @"%p <%s+%td> at %s",
				    _backtrace[i], info.dli_sname, offset,
				    info.dli_fname];
			} else
				    @"%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 <?" @"?> at %s",
				    _backtrace[i], info.dli_fname];
				    @"%p", _stackTrace[i]];

			[backtrace addObject: frame];
			[stackTrace addObject: frame];
		} else
# endif
			[backtrace addObject:
			    [OFString stringWithFormat: @"%p", _backtrace[i]]];
			[stackTrace addObject:
			    [OFString stringWithFormat: @"%p", _stackTrace[i]]];
	}

	objc_autoreleasePoolPop(pool);

	[backtrace makeImmutable];
	[stackTrace makeImmutable];

	return backtrace;
	return stackTrace;
#else
	return nil;
#endif
}
@end

Renamed and modified src/exceptions/OFGetCurrentDirectoryPathFailedException.h [742413e56f] to src/exceptions/OFGetCurrentDirectoryFailedException.h [60ae2d8910].

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
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







-
-
-
+
+
+




-
+


+







-
-









-
+









+
+



 */

#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFGetCurrentDirectoryPathFailedException \
 *	  OFGetCurrentDirectoryPathFailedException.h \
 *	  ObjFW/OFGetCurrentDirectoryPathFailedException.h
 * @class OFGetCurrentDirectoryFailedException \
 *	  OFGetCurrentDirectoryFailedException.h \
 *	  ObjFW/OFGetCurrentDirectoryFailedException.h
 *
 * @brief An exception indicating that getting the current directory path
 *	  failed.
 */
@interface OFGetCurrentDirectoryPathFailedException: OFException
@interface OFGetCurrentDirectoryFailedException: OFException
{
	int _errNo;
	OF_RESERVE_IVARS(OFGetCurrentDirectoryFailedException, 4)
}

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased get current directory path failed
 *	  exception.
 *
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased get current directory failed exception
 */
+ (instancetype)exceptionWithErrNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated get current directory path failed
 *	  exception.
 *
 * @param errNo The errno of the error that occurred
 * @return An initialized get current directory path failed exception
 */
- (instancetype)initWithErrNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFGetCurrentDirectoryPathFailedException.m [d72c905408] to src/exceptions/OFGetCurrentDirectoryFailedException.m [b29d0ac295].

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
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







-
+


-
+


-
-
-
-
-





-
+

-
+










+
+
+
+
+







 * 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 "OFGetCurrentDirectoryPathFailedException.h"
#import "OFGetCurrentDirectoryFailedException.h"
#import "OFString.h"

@implementation OFGetCurrentDirectoryPathFailedException
@implementation OFGetCurrentDirectoryFailedException
@synthesize errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithErrNo: (int)errNo
{
	return [[[self alloc] initWithErrNo: errNo] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithErrNo: (int)errNo
{
	self = [super init];

	_errNo = errNo;

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Getting the current directory path failed: %@",
	    OFStrError(_errNo)];
}

Renamed and modified src/exceptions/OFRetrieveItemAttributesFailedException.h [40aecc6b11] to src/exceptions/OFGetItemAttributesFailedException.h [354af07fb2].

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
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 OFURL;
@class OFURI;

/**
 * @class OFRetrieveItemAttributesFailedException \
 *	  OFRetrieveItemAttributesFailedException.h \
 *	  ObjFW/OFRetrieveItemAttributesFailedException.h
 * @class OFGetItemAttributesFailedException \
 *	  OFGetItemAttributesFailedException.h \
 *	  ObjFW/OFGetItemAttributesFailedException.h
 *
 * @brief An exception indicating an item's attributes could not be retrieved.
 */
@interface OFRetrieveItemAttributesFailedException: OFException
@interface OFGetItemAttributesFailedException: OFException
{
	OFURL *_URL;
	OFURI *_URI;
	int _errNo;
	OF_RESERVE_IVARS(OFGetItemAttributesFailedException, 4)
}

/**
 * @brief The URL of the item whose attributes could not be retrieved.
 * @brief The URI of the item whose attributes could not be retrieved.
 */
@property (readonly, nonatomic) OFURL *URL;
@property (readonly, nonatomic) OFURI *URI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased retrieve item attributes failed exception.
 *
 * @param URL The URL of the item whose attributes could not be retrieved
 * @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)exceptionWithURL: (OFURL *)URL errNo: (int)errNo;
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated retrieve item attributes failed
 *	  exception.
 *
 * @param URL The URL of the item whose attributes could not be retrieved
 * @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)initWithURL: (OFURL *)URL
- (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
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
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 "OFRetrieveItemAttributesFailedException.h"
#import "OFGetItemAttributesFailedException.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFURI.h"

@implementation OFRetrieveItemAttributesFailedException
@synthesize URL = _URL, errNo = _errNo;
@implementation OFGetItemAttributesFailedException
@synthesize URI = _URI, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL errNo: errNo] autorelease];
	return [[[self alloc] initWithURI: URI errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo
- (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to retrieve attributes for item %@: %@",
	    _URL, OFStrError(_errNo)];
	    @"Failed to get attributes for item %@: %@",
	    _URI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFGetOptionFailedException.h from [3a9cb36035] to [a8c8d533b3].

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
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







+












-
-









-
+










+
+



 *
 * @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;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased get option failed exception.
 *
 * @param object The object for which the option could not be retrieved
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased get option failed exception
 */
+ (instancetype)exceptionWithObject: (id)object errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated get option failed exception.
 *
 * @param object The object for which the option could not be retrieved
 * @param errNo The errno of the error that occurred
 * @return An initialized get option failed exception
 */
- (instancetype)initWithObject: (id)object
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFGetWindowsRegistryValueFailedException.h from [4f2322992c] to [1bae299028].

27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
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;
	DWORD _flags;
	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;

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
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







-
+














+
+



 * @param status The status returned by RegGetValueEx()
 * @return A new, autoreleased get Windows registry value failed exception
 */
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       valueName: (nullable OFString *)valueName
				  status: (LSTATUS)status;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated get Windows registry value failed
 *	  exception.
 *
 * @param registryKey The registry key on which getting the value at the sub
 *		      key path failed
 * @param valueName The name of the value which could not be retrieved
 * @param status The status returned by RegGetValueEx()
 * @return An initialized get Windows registry value failed exception
 */
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			  valueName: (nullable OFString *)valueName
			     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFGetWindowsRegistryValueFailedException.m from [da334a4e57] to [57087b05b3].

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
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







-
+

-
+



















+
+
+
+
+







				  status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					valueName: valueName
					   status: status] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			  valueName: (OFString *)valueName
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_valueName = [valueName copy];
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_registryKey release];
	[_valueName release];

	[super dealloc];

Modified src/exceptions/OFHTTPRequestFailedException.h from [84a4067f01] to [d5947528d2].

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
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







+












-
-










-
+











+
+



 *
 * @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;

/**
 * @brief The response for the failed HTTP request.
 */
@property (readonly, nonatomic) OFHTTPResponse *response;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased HTTP request failed exception.
 *
 * @param request The HTTP request which failed
 * @param response The response for the failed HTTP request
 * @return A new, autoreleased HTTP request failed exception
 */
+ (instancetype)exceptionWithRequest: (OFHTTPRequest *)request
			    response: (OFHTTPResponse *)response;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated HTTP request failed exception.
 *
 * @param request The HTTP request which failed
 * @param response The response for the failed HTTP request
 * @return A new HTTP request failed exception
 */
- (instancetype)initWithRequest: (OFHTTPRequest *)request
		       response: (OFHTTPResponse *)response
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFHTTPRequestFailedException.m from [d7570f882e] to [f93ff97e23].

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
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







-
-
-
-
-







-
+

-
+












+
+
+
+
+














-
-
+
+


#import "OFString.h"
#import "OFHTTPRequest.h"
#import "OFHTTPResponse.h"

@implementation OFHTTPRequestFailedException
@synthesize request = _request, response = _response;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithRequest: (OFHTTPRequest *)request
			    response: (OFHTTPResponse *)response
{
	return [[[self alloc] initWithRequest: request
				     response: response] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithRequest: (OFHTTPRequest *)request
		       response: (OFHTTPResponse *)response
{
	self = [super init];

	_request = [request retain];
	_response = [response retain];

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_request release];
	[_response release];

	[super dealloc];
}

- (OFString *)description
{
	const char *method = OFHTTPRequestMethodName(_request.method);

	return [OFString stringWithFormat:
	    @"An HTTP %s request with URL %@ failed with code %hd!", method,
	    _request.URL, _response.statusCode];
	    @"An HTTP %s request with URI %@ failed with code %hd!", method,
	    _request.URI, _response.statusCode];
}
@end

Modified src/exceptions/OFHashAlreadyCalculatedException.h from [f4d411e365] to [0455e7b89e].

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
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







+







-
-








-
+








+
+



 *	  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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased hash already calculated exception.
 *
 * @param object The hash which has already been calculated
 * @return A new, autoreleased hash already calculated exception
 */
+ (instancetype)exceptionWithObject: (id)object;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated hash already calculated exception.
 *
 * @param object The hash which has already been calculated
 * @return An initialized hash already calculated exception
 */
- (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFHashNotCalculatedException.h from [83488903fa] to [e76b9886eb].

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
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







+







-
-








-
+








+
+



 *	  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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased hash not calculated exception.
 *
 * @param object The hash which has not been calculated yet
 * @return A new, autoreleased hash not calculated exception
 */
+ (instancetype)exceptionWithObject: (id)object;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated hash not calculated exception.
 *
 * @param object The hash which has not been calculated yet
 * @return An initialized hash not calculated exception
 */
- (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFInitializationFailedException.h from [20206324fd] to [280997dfe1].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
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
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
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
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 [936e9013a0] to [a9bef800fe].

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
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







+












-
-










-
+










+
+



 *
 * @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;

/**
 * @brief The line in which parsing the JSON representation failed.
 */
@property (readonly, nonatomic) size_t line;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased invalid JSON exception.
 *
 * @param string The string containing the invalid JSON representation
 * @param line The line in which the parsing error was encountered
 * @return A new, autoreleased invalid JSON exception
 */
+ (instancetype)exceptionWithString: (nullable OFString *)string
			       line: (size_t)line;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated invalid JSON exception.
 *
 * @param string The string containing the invalid JSON representation
 * @param line The line in which the parsing error was encountered
 * @return An initialized invalid JSON exception
 */
- (instancetype)initWithString: (nullable OFString *)string
			  line: (size_t)line OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFInvalidServerReplyException.h [90e12ae8cf] to src/exceptions/OFInvalidServerResponseException.h [8680d9915b].

14
15
16
17
18
19
20
21
22



23
24

25
26




27
28
29
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 OFInvalidServerReplyException \
 *	  OFInvalidServerReplyException.h ObjFW/OFInvalidServerReplyException.h
 * @class OFInvalidServerResponseException \
 *	  OFInvalidServerResponseException.h \
 *	  ObjFW/OFInvalidServerResponseException.h
 *
 * @brief An exception indicating that the server sent an invalid reply.
 * @brief An exception indicating that the server sent an invalid response.
 */
@interface OFInvalidServerReplyException: OFException
@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
18

19
20
21

22
23
24

25
26
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 "OFInvalidServerReplyException.h"
#import "OFInvalidServerResponseException.h"
#import "OFString.h"

@implementation OFInvalidServerReplyException
@implementation OFInvalidServerResponseException
- (OFString *)description
{
	return @"Got an invalid reply from the server!";
	return @"Got an invalid response from the server!";
}
@end

Renamed and modified src/exceptions/OFLinkFailedException.h [a8550fc627] to src/exceptions/OFLinkItemFailedException.h [bc4e6321e5].

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
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 OFURL;
@class OFURI;

/**
 * @class OFLinkFailedException \
 *	  OFLinkFailedException.h ObjFW/OFLinkFailedException.h
 * @class OFLinkItemFailedException \
 *	  OFLinkItemFailedException.h ObjFW/OFLinkItemFailedException.h
 *
 * @brief An exception indicating that creating a link failed.
 */
@interface OFLinkFailedException: OFException
@interface OFLinkItemFailedException: OFException
{
	OFURL *_sourceURL, *_destinationURL;
	OFURI *_sourceURI, *_destinationURI;
	int _errNo;
	OF_RESERVE_IVARS(OFLinkItemFailedException, 4)
}

/**
 * @brief A URL with the source for the link.
 * @brief A URI with the source for the link.
 */
@property (readonly, nonatomic) OFURL *sourceURL;
@property (readonly, nonatomic) OFURI *sourceURI;

/**
 * @brief A URL with the destination for the link.
 * @brief A URI with the destination for the link.
 */
@property (readonly, nonatomic) OFURL *destinationURL;
@property (readonly, nonatomic) OFURI *destinationURI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased link failed exception.
 *
 * @param sourceURL The source for the link
 * @param destinationURL The destination for the link
 * @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)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated link failed exception.
 *
 * @param sourceURL The source for the link
 * @param destinationURL The destination for the link
 * @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)initWithSourceURL: (OFURL*)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (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
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
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 "OFLinkFailedException.h"
#import "OFLinkItemFailedException.h"
#import "OFString.h"
#import "OFURL.h"
#import "OFURI.h"

@implementation OFLinkFailedException
@synthesize sourceURL = _sourceURL, destinationURL = _destinationURL;
@implementation OFLinkItemFailedException
@synthesize sourceURI = _sourceURI, destinationURI = _destinationURI;
@synthesize errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo
{
	return [[[self alloc] initWithSourceURL: sourceURL
				 destinationURL: destinationURL
	return [[[self alloc] initWithSourceURI: sourceURI
				 destinationURI: destinationURI
					  errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithSourceURL: (OFURL *)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (instancetype)initWithSourceURI: (OFURI *)sourceURI
		   destinationURI: (OFURI *)destinationURI
			    errNo: (int)errNo
{
	self = [super init];

	@try {
		_sourceURL = [sourceURL copy];
		_destinationURL = [destinationURL copy];
		_sourceURI = [sourceURI copy];
		_destinationURI = [destinationURI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_sourceURL release];
	[_destinationURL release];
	[_sourceURI release];
	[_destinationURI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@",
	    _sourceURL, _destinationURL, OFStrError(_errNo)];
	    _sourceURI, _destinationURI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFListenFailedException.h from [08d597b7f2] to [a41aaff3ca].

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
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







+

















-
-












-
+












+
+



 *
 * @brief An exception indicating that listening on the socket failed.
 */
@interface OFListenFailedException: OFException
{
	id _socket;
	int _backlog, _errNo;
	OF_RESERVE_IVARS(OFListenFailedException, 4)
}

/**
 * @brief The socket which failed to listen.
 */
@property (readonly, nonatomic) id socket;

/**
 * @brief The requested back log.
 */
@property (readonly, nonatomic) int backlog;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased listen failed exception.
 *
 * @param socket The socket which failed to listen
 * @param backlog The requested size of the back log
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased listen failed exception
 */
+ (instancetype)exceptionWithSocket: (id)socket
			    backlog: (int)backlog
			      errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated listen failed exception.
 *
 * @param socket The socket which failed to listen
 * @param backlog The requested size of the back log
 * @param errNo The errno of the error that occurred
 * @return An initialized listen failed exception
 */
- (instancetype)initWithSocket: (id)socket
		       backlog: (int)backlog
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFLoadPluginFailedException.h from [b46d478f30] to [bb70233a5c].

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
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







+












-
-










-
+











+
+



 *	  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;

/**
 * @brief The error why the plugin could not be loaded, as a string
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *error;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased load plugin failed exception.
 *
 * @param path The path of the plugin which could not be loaded
 * @param error The error why the plugin could not be loaded, as a string
 * @return A new, autoreleased load plugin failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path
			    error: (nullable OFString *)error;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated load plugin failed exception.
 *
 * @param path The path of the plugin which could not be loaded
 * @param error The error why the plugin could not be loaded, as a string
 * @return An initialized load plugin failed exception
 */
- (instancetype)initWithPath: (OFString *)path
		       error: (nullable OFString *)error
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFLoadPluginFailedException.m from [47fc9f6837] to [73caeab9c3].

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
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







-
-
-
-
-





-
+

-
+
















+
+
+
+
+








#import "OFLoadPluginFailedException.h"
#import "OFString.h"

@implementation OFLoadPluginFailedException
@synthesize path = _path, error = _error;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithPath: (OFString *)path error: (OFString *)error
{
	return [[[self alloc] initWithPath: path error: error] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithPath: (OFString *)path error: (OFString *)error
{
	self = [super init];

	@try {
		_path = [path copy];
		_error = [error copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_path release];
	[_error release];

	[super dealloc];

Modified src/exceptions/OFLockFailedException.h from [390a803abf] to [58545dfa42].

22
23
24
25
26
27
28
29

30

31
32
33
34
35
36
37
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38







-
+

+







 * @class OFLockFailedException \
 *	  OFLockFailedException.h ObjFW/OFLockFailedException.h
 *
 * @brief An exception indicating that locking a lock failed.
 */
@interface OFLockFailedException: OFException
{
	id <OFLocking> _lock;
	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;

55
56
57
58
59
60
61
62
63
64
65
66
56
57
58
59
60
61
62


63
64
65







-
-



 *
 * @param lock The lock which could not be locked
 * @param errNo The errno of the error that occurred
 * @return An initialized lock failed exception
 */
- (instancetype)initWithLock: (nullable id <OFLocking>)lock
		       errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFLockFailedException.m from [c19f1ae74a] to [77b32492ca].

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
34
35
36
37
38
39
40





41
42
43
44
45
46
47
48
49
50



51
52
53
54
55
56
57







-
-
-
-
-









+
-
-
-
+
+
+
+
+



	_lock = [lock retain];
	_errNo = errNo;

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_lock release];

	[super dealloc];
}

- (OFString *)description
{
	if (_lock != nil)
	return [OFString stringWithFormat:
	    @"A lock of type %@ could not be locked: %s",
	    [_lock class], strerror(_errNo)];
		return [OFString stringWithFormat:
		    @"A lock of type %@ could not be locked: %s",
		    [_lock class], strerror(_errNo)];
	else
		return @"A lock could not be locked!";
}
@end

Modified src/exceptions/OFMalformedXMLException.h from [3b999908e6] to [d319798b44].

24
25
26
27
28
29
30

31
32
33
34
35
36
37
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;

Deleted src/exceptions/OFMemoryNotPartOfObjectException.h version [6dea04ef8c].

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




































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 "OFException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OFMemoryNotPartOfObjectException \
 *	  OFMemoryNotPartOfObjectException.h \
 *	  ObjFW/OFMemoryNotPartOfObjectException.h
 *
 * @brief An exception indicating the given memory is not part of the object.
 */
@interface OFMemoryNotPartOfObjectException: OFException
{
	void *_Nullable _pointer;
	id _object;
}

/**
 * @brief A pointer to the memory which is not part of the object.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) void *pointer;

/**
 * @brief The object which the memory is not part of.
 */
@property (readonly, nonatomic) id object;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased memory not part of object exception.
 *
 * @param pointer A pointer to the memory that is not part of the object
 * @param object The object which the memory is not part of
 * @return A new, autoreleased memory not part of object exception
 */
+ (instancetype)exceptionWithPointer: (nullable void *)pointer
			      object: (id)object;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated memory not part of object exception.
 *
 * @param pointer A pointer to the memory that is not part of the object
 * @param object The object which the memory is not part of
 * @return An initialized memory not part of object exception
 */
- (instancetype)initWithPointer: (nullable void *)pointer
			 object: (id)object OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Deleted src/exceptions/OFMemoryNotPartOfObjectException.m version [af3211991f].

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

































































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
/*
 * 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 "OFMemoryNotPartOfObjectException.h"
#import "OFString.h"

@implementation OFMemoryNotPartOfObjectException
@synthesize pointer = _pointer, object = _object;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithPointer: (void *)pointer object: (id)object
{
	return [[[self alloc] initWithPointer: pointer
				       object: object] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithPointer: (void *)pointer object: (id)object
{
	self = [super init];

	_pointer = pointer;
	_object = [object retain];

	return self;
}

- (void)dealloc
{
	[_object release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Deallocation or reallocation of memory not allocated as part of "
	    @"object of type %@ was attempted! It is also possible that there "
	    @"was an attempt to free the same memory twice.",
	    [_object class]];
}
@end

Modified src/exceptions/OFMoveItemFailedException.h from [435c29fd24] to [f2cc0cdf02].

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
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 OFURL;
@class OFURI;

/**
 * @class OFMoveItemFailedException \
 *	  OFMoveItemFailedException.h ObjFW/OFMoveItemFailedException.h
 *
 * @brief An exception indicating that moving an item failed.
 */
@interface OFMoveItemFailedException: OFException
{
	OFURL *_sourceURL, *_destinationURL;
	OFURI *_sourceURI, *_destinationURI;
	int _errNo;
	OF_RESERVE_IVARS(OFMoveItemFailedException, 4)
}

/**
 * @brief The original URL.
 * @brief The original URI.
 */
@property (readonly, nonatomic) OFURL *sourceURL;
@property (readonly, nonatomic) OFURI *sourceURI;

/**
 * @brief The new URL.
 * @brief The new URI.
 */
@property (readonly, nonatomic) OFURL *destinationURL;
@property (readonly, nonatomic) OFURI *destinationURI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased move item failed exception.
 *
 * @param sourceURL The original URL
 * @param destinationURL The new URL
 * @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)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated move item failed exception.
 *
 * @param sourceURL The original URL
 * @param destinationURL The new URL
 * @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)initWithSourceURL: (OFURL *)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFMoveItemFailedException
@synthesize sourceURL = _sourceURL, destinationURL = _destinationURL;
@synthesize sourceURI = _sourceURI, destinationURI = _destinationURI;
@synthesize errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL
			destinationURL: (OFURL *)destinationURL
+ (instancetype)exceptionWithSourceURI: (OFURI *)sourceURI
			destinationURI: (OFURI *)destinationURI
				 errNo: (int)errNo
{
	return [[[self alloc] initWithSourceURL: sourceURL
				 destinationURL: destinationURL
	return [[[self alloc] initWithSourceURI: sourceURI
				 destinationURI: destinationURI
					  errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithSourceURL: (OFURL *)sourceURL
		   destinationURL: (OFURL *)destinationURL
- (instancetype)initWithSourceURI: (OFURI *)sourceURI
		   destinationURI: (OFURI *)destinationURI
			    errNo: (int)errNo
{
	self = [super init];

	@try {
		_sourceURL = [sourceURL copy];
		_destinationURL = [destinationURL copy];
		_sourceURI = [sourceURI copy];
		_destinationURI = [destinationURI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_sourceURL release];
	[_destinationURL release];
	[_sourceURI release];
	[_destinationURI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to move item at %@ to %@: %@",
	    _sourceURL, _destinationURL, OFStrError(_errNo)];
	    _sourceURI, _destinationURI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFNotImplementedException.h from [c702b7e9be] to [f0426204c4].

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
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







+










-
+
-
-











-
+










+
+



 * @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;

/**
 * @brief The object which does not (fully) implement the selector.
 */
@property (readonly, nonatomic) id object;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) id object;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased not implemented exception.
 *
 * @param selector The selector which is not or not fully implemented
 * @param object The object which does not (fully) implement the selector
 * @return A new, autoreleased not implemented exception
 */
+ (instancetype)exceptionWithSelector: (SEL)selector
			       object: (nullable id)object;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated not implemented exception.
 *
 * @param selector The selector which is not or not fully implemented
 * @param object The object which does not (fully) implement the selector
 * @return An initialized not implemented exception
 */
- (instancetype)initWithSelector: (SEL)selector
			  object: (nullable id)object OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFNotOpenException.h from [8d763bd50d] to [5a826ad61e].

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
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







+







-
-








-
+








+
+



 * @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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased not open exception.
 *
 * @param object The object which is not open, connected or bound
 * @return A new, autoreleased not open exception
 */
+ (instancetype)exceptionWithObject: (id)object;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated not open exception.
 *
 * @param object The object which is not open, connected or bound
 * @return An initialized not open exception
 */
- (instancetype)initWithObject: (id)object OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFObserveFailedException.h [7940ecc296] to src/exceptions/OFObserveKernelEventsFailedException.h [a11562c534].

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
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







-
-
+
+
+



-
+



+












-
-










-
+










+
+



#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN

@class OFKernelEventObserver;

/**
 * @class OFObserveFailedException \
 *	  OFObserveFailedException.h ObjFW/OFObserveFailedException.h
 * @class OFObserveKernelEventsFailedException \
 *	  OFObserveKernelEventsFailedException.h \
 *	  ObjFW/OFObserveKernelEventsFailedException.h
 *
 * @brief An exception indicating that observing failed.
 */
@interface OFObserveFailedException: OFException
@interface OFObserveKernelEventsFailedException: OFException
{
	OFKernelEventObserver *_observer;
	int _errNo;
	OF_RESERVE_IVARS(OFObserveKernelEventsFailedException, 4)
}

/**
 * @brief The observer which failed to observe.
 */
@property (readonly, nonatomic) OFKernelEventObserver *observer;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased observe failed exception.
 *
 * @param observer The observer which failed to observe
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased observe failed exception
 */
+ (instancetype)exceptionWithObserver: (OFKernelEventObserver *)observer
				errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated observe failed exception.
 *
 * @param observer The observer which failed to observe
 * @param errNo The errno of the error that occurred
 * @return An initialized observe failed exception
 */
- (instancetype)initWithObserver: (OFKernelEventObserver *)observer
			   errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/OFObserveFailedException.m [1a09e82eb7] to src/exceptions/OFObserveKernelEventsFailedException.m [1f89b66175].

11
12
13
14
15
16
17
18

19
20
21
22

23
24
25
26
27
28
29
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 "OFObserveFailedException.h"
#import "OFObserveKernelEventsFailedException.h"
#import "OFString.h"
#import "OFKernelEventObserver.h"

@implementation OFObserveFailedException
@implementation OFObserveKernelEventsFailedException
@synthesize observer = _observer, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

Modified src/exceptions/OFOpenItemFailedException.h from [18b9adfbf8] to [fe988003bf].

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
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







-
+









-
+



+



-
+

-
+
















-
-



-
+




-
+















-
+




-
+




-
+














+
+



 * file.
 */

#import "OFException.h"

OF_ASSUME_NONNULL_BEGIN

@class OFURL;
@class OFURI;

/**
 * @class OFOpenItemFailedException \
 *	  OFOpenItemFailedException.h ObjFW/OFOpenItemFailedException.h
 *
 * @brief An exception indicating an item could not be opened.
 */
@interface OFOpenItemFailedException: OFException
{
	OFURL *_Nullable _URL;
	OFURI *_Nullable _URI;
	OFString *_Nullable _path;
	OFString *_mode;
	int _errNo;
	OF_RESERVE_IVARS(OFOpenItemFailedException, 4)
}

/**
 * @brief The URL of the item which could not be opened.
 * @brief The URI of the item which could not be opened.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFURL *URL;
@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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased open item failed exception.
 *
 * @param URL The URL of the item which could not be opened
 * @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)exceptionWithURL: (OFURL *)URL
+ (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)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated open item failed exception.
 *
 * @param URL The URL of the item which could not be opened
 * @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)initWithURL: (OFURL *)URL
- (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
 * @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)initWithPath: (OFString *)path
			mode: (nullable OFString *)mode
		       errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFOpenItemFailedException.m from [2ae9f29630] to [7129cdf836].

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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFOpenItemFailedException
@synthesize URL = _URL, path = _path, mode = _mode, errNo = _errNo;
@synthesize URI = _URI, path = _path, mode = _mode, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
			    mode: (OFString *)mode
			   errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL
	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)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURI: (OFURI *)URI
		       mode: (OFString *)mode
		      errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_mode = [mode copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

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
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







+
+
+
+
+



-
+










-
-
+
+





-
+






	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_URL release];
	[_URI release];
	[_path release];
	[_mode release];

	[super dealloc];
}

- (OFString *)description
{
	id item = nil;

	if (_URL != nil)
		item = _URL;
	if (_URI != nil)
		item = _URI;
	else if (_path != nil)
		item = _path;

	if (_mode != nil)
		return [OFString stringWithFormat:
		    @"Failed to open item %@ with mode %@: %@",
		    @"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 [339dced1e5] to [36fb64cf1a].

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
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;
	DWORD _options;
	REGSAM _securityAndAccessRights;
	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 security and access rights for the subkey that could not be
 *	  opened.
 */
@property (readonly, nonatomic) REGSAM securityAndAccessRights;

/**
 * @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 securityAndAccessRights The security and access rights for the sub
 *				  key 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
		     options: (DWORD)options
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				    path: (OFString *)path
			    accessRights: (REGSAM)accessRights
				 options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		      status: (LSTATUS)status;
				  status: (LSTATUS)status;

- (instancetype)init OF_UNAVAILABLE;
+ (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 securityAndAccessRights The security and access rights for the sub
 *				  key 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
		    options: (DWORD)options
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		       accessRights: (REGSAM)accessRights
			    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
		     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;
			     status: (LSTATUS)status OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.m from [10e98dc632] to [64b24e1261].

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
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







-
+
-
-
+

-
-
-
-
+
+
+
+
-
-
+



+

-



-
+

-
+


-
-
-
-
+
+
+
+
-
-
+






+

-








+
+
+
+
+







 */

#include "config.h"

#import "OFOpenWindowsRegistryKeyFailedException.h"

@implementation OFOpenWindowsRegistryKeyFailedException
@synthesize registryKey = _registryKey, path = _path, options = _options;
@synthesize registryKey = _registryKey, path = _path;
@synthesize securityAndAccessRights = _securityAndAccessRights;
@synthesize status = _status;
@synthesize accessRights = _accessRights, options = _options, status = _status;

+ (instancetype)
    exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			path: (OFString *)path
		     options: (DWORD)options
+ (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey
				    path: (OFString *)path
			    accessRights: (REGSAM)accessRights
				 options: (DWORD)options
     securityAndAccessRights: (REGSAM)securityAndAccessRights
		      status: (LSTATUS)status
				  status: (LSTATUS)status
{
	return [[[self alloc] initWithRegistryKey: registryKey
					     path: path
				     accessRights: accessRights
					  options: options
			  securityAndAccessRights: securityAndAccessRights
					   status: status] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)
	initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
		       path: (OFString *)path
		    options: (DWORD)options
- (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey
			       path: (OFString *)path
		       accessRights: (REGSAM)accessRights
			    options: (DWORD)options
    securityAndAccessRights: (REGSAM)securityAndAccessRights
		     status: (LSTATUS)status
			     status: (LSTATUS)status
{
	self = [super init];

	@try {
		_registryKey = [registryKey retain];
		_path = [path copy];
		_accessRights = accessRights;
		_options = options;
		_securityAndAccessRights = securityAndAccessRights;
		_status = status;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_registryKey release];
	[_path release];

	[super dealloc];

Modified src/exceptions/OFOutOfMemoryException.h from [a0abc1f6de] to [f5654732f6].

22
23
24
25
26
27
28

29
30
31
32
33
34
35
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
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
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
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 [24c93d1f82] to [18b7b9ee6b].

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
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 OFURL;
@class OFURI;

/**
 * @class OFRemoveItemFailedException \
 *	  OFRemoveItemFailedException.h ObjFW/OFRemoveItemFailedException.h
 *
 * @brief An exception indicating that removing an item failed.
 */
@interface OFRemoveItemFailedException: OFException
{
	OFURL *_URL;
	OFURI *_URI;
	int _errNo;
	OF_RESERVE_IVARS(OFRemoveItemFailedException, 4)
}

/**
 * @brief The URL of the item which could not be removed.
 * @brief The URI of the item which could not be removed.
 */
@property (readonly, nonatomic) OFURL *URL;
@property (readonly, nonatomic) OFURI *URI;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased remove failed exception.
 *
 * @param URL The URL of the item which could not be removed
 * @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)exceptionWithURL: (OFURL *)URL errNo: (int)errNo;
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated remove failed exception.
 *
 * @param URL The URL of the item which could not be removed
 * @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)initWithURL: (OFURL *)URL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFRemoveItemFailedException
@synthesize URL = _URL, errNo = _errNo;
@synthesize URI = _URI, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo
+ (instancetype)exceptionWithURI: (OFURI *)URI errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL errNo: errNo] autorelease];
	return [[[self alloc] initWithURI: URI errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo
- (instancetype)initWithURI: (OFURI *)URI errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to remove item at URL %@: %@", _URL, OFStrError(_errNo)];
	    @"Failed to remove item at URI %@: %@", _URI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFResolveHostFailedException.h from [0f2632a039] to [983add21d8].

25
26
27
28
29
30
31

32
33
34
35
36
37
38
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;

55
56
57
58
59
60
61


62
63
64
65
66
67
68
69
70
71
72
73


74
75
76
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







+
+












+
+



 * @param errorCode The error code from the resolver
 * @return A new, autoreleased address translation failed exception
 */
+ (instancetype)exceptionWithHost: (OFString *)host
		    addressFamily: (OFSocketAddressFamily)addressFamily
			errorCode: (OFDNSResolverErrorCode)errorCode;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated resolve host failed exception.
 *
 * @param host The host which could not be resolved
 * @param addressFamily The address family for which the host could not be
 *			resolved
 * @param errorCode The error code from the resolver
 * @return An initialized address translation failed exception
 */
- (instancetype)initWithHost: (OFString *)host
	       addressFamily: (OFSocketAddressFamily)addressFamily
		   errorCode: (OFDNSResolverErrorCode)errorCode;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFResolveHostFailedException.m from [c7c18985ac] to [a81a110c2f].

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
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







+
+
+
+
+


















+
+
+
+
+







		    addressFamily: (OFSocketAddressFamily)addressFamily
			errorCode: (OFDNSResolverErrorCode)errorCode
{
	return [[[self alloc] initWithHost: host
			     addressFamily: addressFamily
				 errorCode: errorCode] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithHost: (OFString *)host
	       addressFamily: (OFSocketAddressFamily)addressFamily
		   errorCode: (OFDNSResolverErrorCode)errorCode
{
	self = [super init];

	@try {
		_host = [host copy];
		_addressFamily = addressFamily;
		_errorCode = errorCode;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_host release];

	[super dealloc];
}

Modified src/exceptions/OFSeekFailedException.h from [87b4166d9c] to [2132111c3a].

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
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;
	OFFileOffset _offset;
	int _whence, _errNo;
	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) OFFileOffset offset;
@property (readonly, nonatomic) OFStreamOffset offset;

/**
 * @brief To what the offset is relative.
 */
@property (readonly, nonatomic) int whence;
@property (readonly, nonatomic) OFSeekWhence whence;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @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: (OFFileOffset)offset
			     whence: (int)whence
			     offset: (OFStreamOffset)offset
			     whence: (OFSeekWhence)whence
			      errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (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: (OFFileOffset)offset
			whence: (int)whence
			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
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
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: (OFFileOffset)offset
			     whence: (int)whence
			     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: (OFFileOffset)offset
			whence: (int)whence
			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 [f1f6c7b963] to [4b245f8a54].

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
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 "OFURLHandler.h"
#import "OFURIHandler.h"

OF_ASSUME_NONNULL_BEGIN

@class OFURL;
@class OFURI;

/**
 * @class OFSetItemAttributesFailedException \
 *	  OFSetItemAttributesFailedException.h \
 *	  ObjFW/OFSetItemAttributesFailedException.h
 *
 * @brief An exception indicating an item's attributes could not be set.
 */
@interface OFSetItemAttributesFailedException: OFException
{
	OFURL *_URL;
	OFURI *_URI;
	OFFileAttributes _attributes;
	OFFileAttributeKey _failedAttribute;
	int _errNo;
	OF_RESERVE_IVARS(OFSetItemAttributesFailedException, 4)
}

/**
 * @brief The URL of the item whose attributes could not be set.
 * @brief The URI of the item whose attributes could not be set.
 */
@property (readonly, nonatomic) OFURL *URL;
@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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased set item attributes failed exception.
 *
 * @param URL The URL of the item whose attributes could not be set
 * @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)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
		      attributes: (OFFileAttributes)attributes
		 failedAttribute: (OFFileAttributeKey)failedAttribute
			   errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated set item attributes failed exception.
 *
 * @param URL The URL of the item whose attributes could not be set
 * @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)initWithURL: (OFURL *)URL
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFSetItemAttributesFailedException
@synthesize URL = _URL, attributes = _attributes;
@synthesize URI = _URI, attributes = _attributes;
@synthesize failedAttribute = _failedAttribute, errNo = _errNo;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
		      attributes: (OFFileAttributes)attributes
		 failedAttribute: (OFFileAttributeKey)failedAttribute
			   errNo: (int)errNo
{
	return [[[self alloc] initWithURL: URL
	return [[[self alloc] initWithURI: URI
			       attributes: attributes
			  failedAttribute: failedAttribute
				    errNo: errNo] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURI: (OFURI *)URI
		 attributes: (OFFileAttributes)attributes
	    failedAttribute: (OFFileAttributeKey)failedAttribute
		      errNo: (int)errNo
{
	self = [super init];

	@try {
		_URL = [URL copy];
		_URI = [URI copy];
		_attributes = [attributes copy];
		_failedAttribute = [failedAttribute copy];
		_errNo = errNo;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];
	[_attributes release];
	[_failedAttribute release];

	[super dealloc];
}

- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Failed to set attribute %@ for item %@: %@",
	    _failedAttribute, _URL, OFStrError(_errNo)];
	    _failedAttribute, _URI, OFStrError(_errNo)];
}
@end

Modified src/exceptions/OFSetOptionFailedException.h from [1f8eb9d1a2] to [2fa10041b9].

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
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







+












-
-









-
+










+
+



 *
 * @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;

/**
 * @brief The errno of the error that occurred.
 */
@property (readonly, nonatomic) int errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased set option failed exception.
 *
 * @param object The object for which the option could not be set
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased set option failed exception
 */
+ (instancetype)exceptionWithObject: (id)object errNo: (int)errNo;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated set option failed exception.
 *
 * @param object The object for which the option could not be set
 * @param errNo The errno of the error that occurred
 * @return An initialized set option failed exception
 */
- (instancetype)initWithObject: (id)object
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFSetWindowsRegistryValueFailedException.h from [881eab26fa] to [88eed12b7b].

30
31
32
33
34
35
36

37
38
39
40
41
42
43
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 [5d209b5bbe] to [da104224a4].

22
23
24
25
26
27
28
29


30
31
32
33
34
35
36
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37







-
+
+







 * @class OFStillLockedException \
 *	  OFStillLockedException.h ObjFW/OFStillLockedException.h
 *
 * @brief An exception indicating that a lock is still locked.
 */
@interface OFStillLockedException: OFException
{
	id <OFLocking> _lock;
	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 [14ed219e78] to [f9e2ae9630].

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
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







+

















-
-












-
+













+
+



 * @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;

/**
 * @brief The host for the handshake.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *host;

/**
 * @brief The error code from the TLS stream.
 */
@property (readonly, nonatomic) OFTLSStreamErrorCode errorCode;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased TLS handshake failed exception.
 *
 * @param stream The TLS stream which failed the handshake
 * @param host The host for the handshake
 * @param errorCode The error code from the TLS stream
 * @return A new, autoreleased TLS handshake failed exception
 */
+ (instancetype)exceptionWithStream: (OFTLSStream *)stream
			       host: (nullable OFString *)host
			  errorCode: (OFTLSStreamErrorCode)errorCode;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated TLS handshake failed exception.
 *
 * @param stream The TLS stream which failed the handshake
 * @param host The host for the handshake
 * @param errorCode The error code from the TLS stream
 * @return An initialized TLS handshake failed exception
 */
- (instancetype)initWithStream: (OFTLSStream *)stream
			  host: (nullable OFString *)host
		     errorCode: (OFTLSStreamErrorCode)errorCode
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFTLSHandshakeFailedException.m from [18052bd37b] to [9f825e73f8].

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
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







-
-
-
-
-









-
+

-
+



















+
+
+
+
+







#import "OFString.h"

int _OFTLSHandshakeFailedException_reference;

@implementation OFTLSHandshakeFailedException
@synthesize stream = _stream, host = _host, errorCode = _errorCode;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithStream: (OFTLSStream *)stream
			       host: (OFString *)host
			  errorCode: (OFTLSStreamErrorCode)errorCode
{
	return [[[self alloc] initWithStream: stream
					host: host
				   errorCode: errorCode] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithStream: (OFTLSStream *)stream
			  host: (OFString *)host
		     errorCode: (OFTLSStreamErrorCode)errorCode
{
	self = [super init];

	@try {
		_stream = [stream retain];
		_host = [host copy];
		_errorCode = errorCode;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_stream release];
	[_host release];

	[super dealloc];

Modified src/exceptions/OFThreadJoinFailedException.h from [fe83d24fbc] to [d301dc0b05].

27
28
29
30
31
32
33
34

35

36
37
38
39
40
41
42
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43







-
+

+







 * @class OFThreadJoinFailedException \
 *	  OFThreadJoinFailedException.h ObjFW/OFThreadJoinFailedException.h
 *
 * @brief An exception indicating that joining a thread failed.
 */
@interface OFThreadJoinFailedException: OFException
{
	OFThread *_thread;
	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;

50
51
52
53
54
55
56


57
58
59
60
61
62
63
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66







+
+







 *
 * @param thread The thread which could not be joined
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased thread join failed exception
 */
+ (instancetype)exceptionWithThread: (nullable OFThread *)thread
			      errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated thread join failed exception.
 *
 * @param thread The thread which could not be joined
 * @param errNo The errno of the error that occurred
 * @return An initialized thread join failed exception

Modified src/exceptions/OFThreadJoinFailedException.m from [51bd0c22ea] to [3ceaee16ab].

24
25
26
27
28
29
30





31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+
+
+
+
+







@implementation OFThreadJoinFailedException
@synthesize thread = _thread, errNo = _errNo;

+ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo
{
	return [[[self alloc] initWithThread: thread errNo: errNo] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo
{
	self = [super init];

	_thread = [thread retain];
	_errNo = errNo;

Modified src/exceptions/OFThreadStartFailedException.h from [896ed3c90a] to [744fa4d2f0].

27
28
29
30
31
32
33
34

35

36
37
38
39
40
41
42
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42
43







-
+

+







 * @class OFThreadStartFailedException \
 *	  OFThreadStartFailedException.h ObjFW/OFThreadStartFailedException.h
 *
 * @brief An exception indicating that starting a thread failed.
 */
@interface OFThreadStartFailedException: OFException
{
	OFThread *_thread;
	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;

50
51
52
53
54
55
56


57
58
59
60
61
62
63
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66







+
+







 *
 * @param thread The thread which could not be started
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased thread start failed exception
 */
+ (instancetype)exceptionWithThread: (nullable OFThread *)thread
			      errNo: (int)errNo;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated thread start failed exception.
 *
 * @param thread The thread which could not be started
 * @param errNo The errno of the error that occurred
 * @return An initialized thread start failed exception

Modified src/exceptions/OFThreadStartFailedException.m from [02d8e0f542] to [4df0dddce1].

24
25
26
27
28
29
30





31
32
33
34
35
36
37
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+
+
+
+
+







@implementation OFThreadStartFailedException
@synthesize thread = _thread, errNo = _errNo;

+ (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo
{
	return [[[self alloc] initWithThread: thread errNo: errNo] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo
{
	self = [super init];

	_thread = [thread retain];
	_errNo = errNo;

Modified src/exceptions/OFThreadStillRunningException.h from [4ac7372af4] to [8cadaadd37].

27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42







-
+
+







 * @class OFThreadStillRunningException \
 *	  OFThreadStillRunningException.h ObjFW/OFThreadStillRunningException.h
 *
 * @brief An exception indicating that a thread is still running.
 */
@interface OFThreadStillRunningException: OFException
{
	OFThread *_thread;
	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
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 [abee82b29b] to [782770074b].

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
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







+
















-
-










-
+











+
+



 *
 * @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;
#else
@property (readonly, nonatomic, getter=namespace) OFString *nameSpace;
#endif

/**
 * @brief The element in which the namespace was not bound.
 */
@property (readonly, nonatomic) OFXMLElement *element;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased unbound namespace exception.
 *
 * @param nameSpace The namespace which is unbound
 * @param element The element in which the namespace was not bound
 * @return A new, autoreleased unbound namespace exception
 */
+ (instancetype)exceptionWithNamespace: (OFString *)nameSpace
			       element: (OFXMLElement *)element;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated unbound namespace exception.
 *
 * @param nameSpace The namespace which is unbound
 * @param element The element in which the namespace was not bound
 * @return An initialized unbound namespace exception
 */
- (instancetype)initWithNamespace: (OFString *)nameSpace
			  element: (OFXMLElement *)element
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFUnboundPrefixException.h from [aa8941dce1] to [c1eaadb13e].

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
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







+












-
-










-
+










+
+



 *
 * @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;

/**
 * @brief The parser which encountered the unbound prefix.
 */
@property (readonly, nonatomic) OFXMLParser *parser;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased unbound prefix exception.
 *
 * @param prefix The prefix which is unbound
 * @param parser The parser which encountered the unbound prefix
 * @return A new, autoreleased unbound prefix exception
 */
+ (instancetype)exceptionWithPrefix: (OFString *)prefix
			     parser: (OFXMLParser *)parser;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated unbound prefix exception.
 *
 * @param prefix The prefix which is unbound
 * @param parser The parser which encountered the unbound prefix
 * @return An initialized unbound prefix exception
 */
- (instancetype)initWithPrefix: (OFString *)prefix
			parser: (OFXMLParser *)parser OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFUndefinedKeyException.h from [87fea8b2cb] to [1b1bc72e6f].

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
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







-
+

+










-
+






-
-




















-
+


-
+







 *
 * @brief An exception indicating that a key is undefined (e.g. for Key Value
 *	  Coding).
 */
@interface OFUndefinedKeyException: OFException
{
	id _object;
	OFString *_key;
	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;

/**
 * @brief The key which is undefined.
 */
@property (readonly, nonatomic) OFString *key;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *key;

/**
 * @brief The value for the undefined key
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) id value;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased undefined key exception.
 *
 * @param object The object on which the key is undefined
 * @param key The key which is undefined
 *
 * @return A new, autoreleased undefined key exception
 */
+ (instancetype)exceptionWithObject: (id)object key: (OFString *)key;

/**
 * @brief Creates a new, autoreleased undefined key exception.
 *
 * @param object The object on which the key is undefined
 * @param key The key which is undefined
 * @param value The value for the undefined key
 *
 * @return A new, autoreleased undefined key exception
 */
+ (instancetype)exceptionWithObject: (id)object
				key: (OFString *)key
				key: (nullable OFString *)key
			      value: (nullable id)value;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated undefined key exception.
 *
 * @param object The object on which the key is undefined
 * @param key The key which is undefined
 *
89
90
91
92
93
94
95
96

97


98
99
100
88
89
90
91
92
93
94

95
96
97
98
99
100
101







-
+

+
+



 * @param object The object on which the key is undefined
 * @param key The key which is undefined
 * @param value The value for the undefined key
 *
 * @return An initialized undefined key exception
 */
- (instancetype)initWithObject: (id)object
			   key: (OFString *)key
			   key: (nullable OFString *)key
			 value: (nullable id)value OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFUnknownXMLEntityException.h from [dc23a68df4] to [effb41465b].

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
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







+















-
+









+
+



 *
 * @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;

/**
 * @brief Creates a new, autoreleased unknown XML entity exception.
 *
 * @param entityName The name of the unknown XML entity
 * @return A new, autoreleased unknown XML entity exception
 */
+ (instancetype)exceptionWithEntityName: (OFString *)entityName;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated unknown XML entity exception.
 *
 * @param entityName The name of the unknown XML entity
 * @return An initialized unknown XML entity exception
 */
- (instancetype)initWithEntityName: (OFString *)entityName
    OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFUnknownXMLEntityException.m from [aae3e97dd2] to [87056195a2].

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
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







-
+

-
+















+
+
+
+
+







@synthesize entityName = _entityName;

+ (instancetype)exceptionWithEntityName: (OFString *)entityName
{
	return [[[self alloc] initWithEntityName: entityName] autorelease];
}

- (instancetype)init
+ (instancetype)exception
{
	OF_INVALID_INIT_METHOD
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithEntityName: (OFString *)entityName
{
	self = [super init];

	@try {
		_entityName = [entityName copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_entityName release];

	[super dealloc];
}

Modified src/exceptions/OFUnlockFailedException.h from [0a8aacbf87] to [2273de4dc6].

22
23
24
25
26
27
28
29

30

31
32
33
34
35
36
37
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38







-
+

+







 * @class OFUnlockFailedException \
 *	  OFUnlockFailedException.h ObjFW/OFUnlockFailedException.h
 *
 * @brief An exception indicating that unlocking a lock failed.
 */
@interface OFUnlockFailedException: OFException
{
	id <OFLocking> _lock;
	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;

55
56
57
58
59
60
61
62
63
64
65
66
56
57
58
59
60
61
62


63
64
65







-
-



 *
 * @param lock The lock which could not be unlocked
 * @param errNo The errno of the error that occurred
 * @return An initialized unlock failed exception
 */
- (instancetype)initWithLock: (nullable id <OFLocking>)lock
		       errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFUnlockFailedException.m from [54e551ea81] to [68e65cd613].

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
34
35
36
37
38
39
40





41
42
43
44
45
46
47
48
49
50



51
52
53
54
55
56
57







-
-
-
-
-









+
-
-
-
+
+
+
+
+



	_lock = [lock retain];
	_errNo = errNo;

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_lock release];

	[super dealloc];
}

- (OFString *)description
{
	if (_lock != nil)
	return [OFString stringWithFormat:
	    @"A lock of type %@ could not be unlocked: %s",
	    [_lock class], strerror(_errNo)];
		return [OFString stringWithFormat:
		    @"A lock of type %@ could not be unlocked: %s",
		    [_lock class], strerror(_errNo)];
	else
		return @"A lock could not be unlocked!";
}
@end

Modified src/exceptions/OFUnsupportedProtocolException.h from [21fa1afa4d] to [229fefef5c].

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
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 OFURL;
@class OFURI;

/**
 * @class OFUnsupportedProtocolException \
 *	  OFUnsupportedProtocolException.h \
 *	  ObjFW/OFUnsupportedProtocolException.h
 *
 * @brief An exception indicating that the protocol specified by the URL is not
 * @brief An exception indicating that the protocol specified by the URI is not
 *	  supported.
 */
@interface OFUnsupportedProtocolException: OFException
{
	OFURL *_URL;
	OFURI *_Nullable _URI;
	OF_RESERVE_IVARS(OFUnsupportedProtocolException, 4)
}

/**
 * @brief The URL whose protocol is unsupported.
 * @brief The URI whose protocol is unsupported.
 */
@property (readonly, nonatomic) OFURL *URL;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFURI *URI;

/**
 * @brief Creates a new, autoreleased unsupported protocol exception.
 *
 * @param URL The URL whose protocol is unsupported
 * @param URI The URI whose protocol is unsupported
 * @return A new, autoreleased unsupported protocol exception
 */
+ (instancetype)exceptionWithURL: (OFURL*)URL;
+ (instancetype)exceptionWithURI: (nullable OFURI*)URI;

/**
 * @brief Initializes an already allocated unsupported protocol exception
 *
 * @param URL The URL whose protocol is unsupported
 * @param URI The URI whose protocol is unsupported
 * @return An initialized unsupported protocol exception
 */
- (instancetype)initWithURL: (OFURL*)URL OF_DESIGNATED_INITIALIZER;
- (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
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
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 "OFURL.h"
#import "OFURI.h"

@implementation OFUnsupportedProtocolException
@synthesize URL = _URL;
@synthesize URI = _URI;

+ (instancetype)exceptionWithURL: (OFURL *)URL
+ (instancetype)exceptionWithURI: (OFURI *)URI
{
	return [[[self alloc] initWithURL: URL] autorelease];
	return [[[self alloc] initWithURI: URI] autorelease];
}

- (instancetype)initWithURL: (OFURL *)URL
- (instancetype)initWithURI: (OFURI *)URI
{
	self = [super init];

	_URL = [URL retain];
	_URI = [URI retain];

	return self;
}

- (void)dealloc
{
	[_URL release];
	[_URI release];

	[super dealloc];
}

- (OFString *)description
{
	if (_URL != nil)
	if (_URI != nil)
		return [OFString stringWithFormat:
		    @"The protocol of URL %@ is not supported!", _URL];
		    @"The protocol of URI %@ is not supported!", _URI];
	else
		return @"The requested protocol is unsupported!";
}
@end

Modified src/exceptions/OFUnsupportedVersionException.h from [98797d9d3c] to [2da3b1eaf2].

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
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







+







-
-








-
+








+
+



 *
 * @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;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased unsupported version exception.
 *
 * @param version The version which is unsupported
 * @return A new, autoreleased unsupported version exception
 */
+ (instancetype)exceptionWithVersion: (OFString *)version;

- (instancetype)init OF_UNAVAILABLE;
+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated unsupported protocol exception.
 *
 * @param version The version which is unsupported
 * @return An initialized unsupported version exception
 */
- (instancetype)initWithVersion: (OFString *)version OF_DESIGNATED_INITIALIZER;

- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/exceptions/OFWriteFailedException.h from [f6be679ec0] to [6dee61073a].

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
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







+










-
-
-
-
















-
-
-
+
+
+
















+
+
+
+



 *	  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.
 */
@property (readonly, nonatomic) size_t bytesWritten;

+ (instancetype)exceptionWithObject: (id)object
		    requestedLength: (size_t)requestedLength
			      errNo: (int)errNo OF_UNAVAILABLE;

/**
 * @brief Creates a new, autoreleased write failed exception.
 *
 * @param object The object from which reading or to which writing failed
 * @param requestedLength The requested length of the data that could not be
 *			  read / written
 * @param bytesWritten The amount of bytes already written before the write
 *		       failed
 * @param errNo The errno of the error that occurred
 * @return A new, autoreleased write failed exception
 */
+ (instancetype)exceptionWithObject: (id)object
		    requestedLength: (size_t)requestedLength
		       bytesWritten: (size_t)bytesWritten
			      errNo: (int)errNo;

- (instancetype)initWithObject: (id)object
	       requestedLength: (size_t)requestedLength
			 errNo: (int)errNo OF_UNAVAILABLE;
+ (instancetype)exceptionWithObject: (id)object
		    requestedLength: (size_t)requestedLength
			      errNo: (int)errNo OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated write failed exception.
 *
 * @param object The object from which reading or to which writing failed
 * @param requestedLength The requested length of the data that could not be
 *			  read / written
 * @param bytesWritten The amount of bytes already written before the write
 *		       failed
 * @param errNo The errno of the error that occurred
 * @return A new open file failed exception
 */
- (instancetype)initWithObject: (id)object
	       requestedLength: (size_t)requestedLength
		  bytesWritten: (size_t)bytesWritten
			 errNo: (int)errNo OF_DESIGNATED_INITIALIZER;

- (instancetype)initWithObject: (id)object
	       requestedLength: (size_t)requestedLength
			 errNo: (int)errNo OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/macros.h from [5676813928] to [60a41b82a1].

252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
252
253
254
255
256
257
258

259
260
261
262
263
264
265







-







# define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
# define OF_WARN_UNUSED_RESULT
#endif

#if __has_attribute(__unavailable__)
# define OF_UNAVAILABLE __attribute__((__unavailable__))
# define OF_HAVE_UNAVAILABLE
#else
# define OF_UNAVAILABLE
#endif

#if __has_attribute(__objc_requires_super__)
# define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__))
#else

Modified src/objfw-defs.h.in from [69a2e4862c] to [8f5a561d98].

39
40
41
42
43
44
45

46
47
48
49

39
40
41
42
43
44
45
46
47
48
49
50
51







+




+
#undef OF_HAVE_THREADS
#undef OF_HAVE_UNICODE_TABLES
#undef OF_HAVE_UNIX_SOCKETS
#undef OF_HAVE__THREAD_LOCAL
#undef OF_HAVE___THREAD
#undef OF_NINTENDO_3DS
#undef OF_NINTENDO_DS
#undef OF_NINTENDO_SWITCH
#undef OF_NO_SHARED
#undef OF_OBJFW_RUNTIME
#undef OF_UNIVERSAL
#undef OF_WII
#undef OF_WII_U

Modified src/platform/AmigaOS/OFString+PathAdditions.m from [8907c31289] to [60752aa5d1].

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
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 "OFFileURLHandler.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
158

159
160
161
162
163
164
165
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165







-
+







		}

		objc_autoreleasePoolPop(pool);
		return @"";
	}

	components = [components objectsInRange:
	    OFRangeMake(0, components.count - 1)];
	    OFMakeRange(0, components.count - 1)];
	ret = [OFString pathWithComponents: components];

	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}

231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
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:
				    OFRangeMake(i - 1, 2)];
				    OFMakeRange(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

264
265
266
267
268
269
270





















271
272
273
274
275

276
277
278


279
280
281
282
283
284
285
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+


-
+
+







		[ret appendString: component];

		[ret makeImmutable];

		return ret;
	}
}

- (OFString *)stringByAppendingPathExtension: (OFString *)extension
{
	if ([self hasSuffix: @"/"]) {
		void *pool = objc_autoreleasePoolPush();
		OFMutableArray *components;
		OFString *fileName, *ret;

		components =
		    [[self.pathComponents mutableCopy] autorelease];
		fileName = [components.lastObject
		    stringByAppendingFormat: @".%@", extension];
		[components replaceObjectAtIndex: components.count - 1
				      withObject: fileName];

		ret = [[OFString pathWithComponents: components] retain];
		objc_autoreleasePoolPop(pool);
		return [ret autorelease];
	} else
		return [self stringByAppendingFormat: @".%@", extension];
}

- (bool)of_isDirectoryPath
{
	return ([self hasSuffix: @"/"] || [self hasSuffix: @":"] ||
	    [OFFileURLHandler of_directoryExistsAtPath: self]);
	    [OFFileURIHandler of_directoryExistsAtPath: self]);
}

- (OFString *)of_pathToURLPathWithURLEncodedHost: (OFString **)URLEncodedHost
- (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;
293
294
295
296
297
298
299
300


301
302
303
304
305
306
307
315
316
317
318
319
320
321

322
323
324
325
326
327
328
329
330







-
+
+







	}

	[ret makeImmutable];

	return ret;
}

- (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost
- (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;
326
327
328
329
330
331
332
333

334
335
336
337
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_pathComponentToURLPathComponent
- (OFString *)of_pathComponentToURIPathComponent
{
	return self;
}
@end

Modified src/platform/POSIX/OFString+PathAdditions.m from [33c84f0ae4] to [d1f51523cf].

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
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 "OFFileURLHandler.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
280

281
282
283
284
285
286
287
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:
				    OFRangeMake(i - 1, 2)];
				    OFMakeRange(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+


-
+
+




-
+
+









-
+




		[ret appendString: component];

		[ret makeImmutable];

		return ret;
	}
}

- (OFString *)stringByAppendingPathExtension: (OFString *)extension
{
	if ([self hasSuffix: @"/"]) {
		void *pool = objc_autoreleasePoolPush();
		OFMutableArray *components;
		OFString *fileName, *ret;

		components =
		    [[self.pathComponents mutableCopy] autorelease];
		fileName = [components.lastObject
		    stringByAppendingFormat: @".%@", extension];
		[components replaceObjectAtIndex: components.count - 1
				      withObject: fileName];

		ret = [[OFString pathWithComponents: components] retain];
		objc_autoreleasePoolPop(pool);
		return [ret autorelease];
	} else
		return [self stringByAppendingFormat: @".%@", extension];
}

- (bool)of_isDirectoryPath
{
	return ([self hasSuffix: @"/"] ||
	    [OFFileURLHandler of_directoryExistsAtPath: self]);
	    [OFFileURIHandler of_directoryExistsAtPath: self]);
}

- (OFString *)of_pathToURLPathWithURLEncodedHost: (OFString **)URLEncodedHost
- (OFString *)of_pathToURIPathWithPercentEncodedHost:
    (OFString **)percentEncodedHost
{
	return self;
}

- (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost
- (OFString *)of_URIPathToPathWithPercentEncodedHost:
    (OFString *)percentEncodedHost
{
	OFString *path = self;

	if (path.length > 1 && [path hasSuffix: @"/"])
		path = [path substringToIndex: path.length - 1];

	return path;
}

- (OFString *)of_pathComponentToURLPathComponent
- (OFString *)of_pathComponentToURIPathComponent
{
	return self;
}
@end

Modified src/platform/Windows/OFString+PathAdditions.m from [3d18ffcbdd] to [ec08b34f89].

18
19
20
21
22
23
24
25
26


27
28
29
30
31
32
33
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 "OFFileURLHandler.h"
#import "OFURL.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
206

207
208
209
210
211
212
213
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213







-
+







		}

		objc_autoreleasePoolPop(pool);
		return @".";
	}

	components = [components objectsInRange:
	    OFRangeMake(0, components.count - 1)];
	    OFMakeRange(0, components.count - 1)];
	ret = [OFString pathWithComponents: components];

	[ret retain];
	objc_autoreleasePoolPop(pool);
	return [ret autorelease];
}

284
285
286
287
288
289
290
291

292
293
294
295
296
297
298
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:
				    OFRangeMake(i - 1, 2)];
				    OFMakeRange(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+


-
+
+









-
-
-
+
+
+

-
+




-
+




-
+
+











-
-
+
+
+











-
+





		[ret appendString: component];

		[ret makeImmutable];

		return ret;
	}
}

- (OFString *)stringByAppendingPathExtension: (OFString *)extension
{
	if ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"]) {
		void *pool = objc_autoreleasePoolPush();
		OFMutableArray *components;
		OFString *fileName, *ret;

		components =
		    [[self.pathComponents mutableCopy] autorelease];
		fileName = [components.lastObject
		    stringByAppendingFormat: @".%@", extension];
		[components replaceObjectAtIndex: components.count - 1
				      withObject: fileName];

		ret = [[OFString pathWithComponents: components] retain];
		objc_autoreleasePoolPop(pool);
		return [ret autorelease];
	} else
		return [self stringByAppendingFormat: @".%@", extension];
}

- (bool)of_isDirectoryPath
{
	return ([self hasSuffix: @"\\"] || [self hasSuffix: @"/"] ||
	    [OFFileURLHandler of_directoryExistsAtPath: self]);
	    [OFFileURIHandler of_directoryExistsAtPath: self]);
}

- (OFString *)of_pathToURLPathWithURLEncodedHost: (OFString **)URLEncodedHost
- (OFString *)of_pathToURIPathWithPercentEncodedHost:
    (OFString **)percentEncodedHost
{
	OFString *path = self;

	if ([path hasPrefix: @"\\\\"]) {
		OFArray *components = path.pathComponents;

		if (components.count < 2)
			@throw [OFInvalidFormatException exception];

		*URLEncodedHost = [[components objectAtIndex: 1]
		     stringByURLEncodingWithAllowedCharacters:
		     [OFCharacterSet URLHostAllowedCharacterSet]];
		*percentEncodedHost = [[components objectAtIndex: 1]
		     stringByAddingPercentEncodingWithAllowedCharacters:
		     [OFCharacterSet URIHostAllowedCharacterSet]];
		path = [OFString pathWithComponents: [components
		    objectsInRange: OFRangeMake(2, components.count - 2)]];
		    objectsInRange: OFMakeRange(2, components.count - 2)]];
	}

	path = [path stringByReplacingOccurrencesOfString: @"\\"
					       withString: @"/"];
	path = [path stringByPrependingString: @"/"];
	path = [@"/" stringByAppendingString: path];

	return path;
}

- (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost
- (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 (URLEncodedHost != nil) {
		OFString *host = [URLEncodedHost stringByURLDecoding];
	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_pathComponentToURLPathComponent
- (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
158

159
160
161
162
163
164
165
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 prependString: @"\""];
			[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 [9b9e52f706] to [6647377f7a].

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
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 "OFFileURLHandler.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
284

285
286
287
288
289
290
291
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:
				    OFRangeMake(i - 1, 2)];
				    OFMakeRange(i - 1, 2)];

				done = false;
				break;
			}
		}
	}

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
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+


-
+
+

-
+


-
+
+









-
+




		[ret appendString: component];

		[ret makeImmutable];

		return ret;
	}
}

- (OFString *)stringByAppendingPathExtension: (OFString *)extension
{
	if ([self hasSuffix: @"/"]) {
		void *pool = objc_autoreleasePoolPush();
		OFMutableArray *components;
		OFString *fileName, *ret;

		components =
		    [[self.pathComponents mutableCopy] autorelease];
		fileName = [components.lastObject
		    stringByAppendingFormat: @".%@", extension];
		[components replaceObjectAtIndex: components.count - 1
				      withObject: fileName];

		ret = [[OFString pathWithComponents: components] retain];
		objc_autoreleasePoolPop(pool);
		return [ret autorelease];
	} else
		return [self stringByAppendingFormat: @".%@", extension];
}

- (bool)of_isDirectoryPath
{
	return ([self hasSuffix: @"/"] ||
	    [OFFileURLHandler of_directoryExistsAtPath: self]);
	    [OFFileURIHandler of_directoryExistsAtPath: self]);
}

- (OFString *)of_pathToURLPathWithURLEncodedHost: (OFString **)URLEncodedHost
- (OFString *)of_pathToURIPathWithPercentEncodedHost:
    (OFString **)percentEncodedHost
{
	return [self stringByPrependingString: @"/"];
	return [@"/" stringByAppendingString: self];
}

- (OFString *)of_URLPathToPathWithURLEncodedHost: (OFString *)URLEncodedHost
- (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_pathComponentToURLPathComponent
- (OFString *)of_pathComponentToURIPathComponent
{
	return self;
}
@end

Modified src/runtime/Makefile from [6dd30f7bce] to [23dfac9b53].

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





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_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 [d177a01899] to [db6b5f4a82].

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53
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()
_start(void)
{
	return -1;
}

#ifdef OF_AMIGAOS_M68K
void
__init_eh(void)
290
291
292
293
294
295
296
297
298



299
300
301
302
303
304
305
306
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 (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
				libc.__deregister_frame_info(
			for (void *const *frame = _EH_FRAME_BEGINS__;
			    *frame != NULL;)
				libc.__deregister_frame_info(*frame++);
				    (&_EH_FRAME_BEGINS__)[i]);
#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);
338
339
340
341
342
343
344
345

346
347

348
349

350
351
352
353
354
355
356
357
338
339
340
341
342
343
344

345


346


347

348
349
350
351
352
353
354







-
+
-
-
+
-
-
+
-








	if (version > 1)
		return false;

	memcpy(&libc, libc_, sizeof(libc));

#ifdef OF_AMIGAOS_M68K
	if ((size_t)_EH_FRAME_BEGINS__ != (size_t)_EH_FRAME_OBJECTS__)
	for (void *const *frame = _EH_FRAME_OBJECTS__,
		return false;

	    **object = _EH_FRAME_OBJECTS__; *frame != NULL;)
	for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++)
		libc.__register_frame_info((&_EH_FRAME_BEGINS__)[i],
		libc.__register_frame_info(*frame++, *object++);
		    (&_EH_FRAME_OBJECTS__)[i]);

	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
66

67
68
69
70
71
72
73
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()
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
408

409
410
411
412
413
414
415
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415







-
+








	initializeClass(class);

	objc_globalMutex_unlock();
}

static void
processLoadQueue()
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/linklib/init.m from [260b346241] to [6ddafedf04].

149
150
151
152
153
154
155
156
157


158
159
160
161
162
163
164
149
150
151
152
153
154
155


156
157
158
159
160
161
162
163
164







-
-
+
+







static void __attribute__((__used__))
dtor(void)
{
	CloseLibrary(ObjFWRTBase);
}

#if defined(OF_AMIGAOS_M68K)
ADD2INIT(ctor, -5);
ADD2EXIT(dtor, -5);
ADD2INIT(ctor, -5)
ADD2EXIT(dtor, -5)
#elif defined(OF_MORPHOS)
CONSTRUCTOR_P(ObjFWRT, 4000)
{
	ctor();

	return 0;
}

Modified src/runtime/static-instances.m from [a4b6846d46] to [7d72566e27].

91
92
93
94
95
96
97
98

99
100
101
102
103
91
92
93
94
95
96
97

98
99
100
101
102
103







-
+





			staticInstancesList[staticInstancesCount++] =
			    *staticInstances;
		}
	}
}

void
objc_forgetPendingStaticInstances()
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
	}
}

Modified src/tls/OFOpenSSLTLSStream.m from [f8706b398d] to [faf6205c5a].

188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202







-
+







	}

	return bytesWritten;
}

- (bool)hasDataInReadBuffer
{
	if (SSL_has_pending(_SSL) || BIO_ctrl_pending(_readBIO) > 0)
	if (SSL_pending(_SSL) > 0 || BIO_ctrl_pending(_readBIO) > 0)
		return true;

	return super.hasDataInReadBuffer;
}

- (void)asyncPerformClientHandshakeWithHost: (OFString *)host
				runLoopMode: (OFRunLoopMode)runLoopMode

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 [bb692e21b0] to [2482a8a4a6].

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
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









-
+
+
+
+
+
+











+
+




+
+






+
+
+
+
+
+

+




-
+











-
+
-
-
-
-
-
-
+
+
-
-
-
-
+







include ../extra.mk

SUBDIRS = ${TESTPLUGIN}	\
	  ${OBJC_SYNC}	\
	  terminal

CLEAN = EBOOT.PBP		\
	boot.dol		\
	${PROG_NOINST}.arm9	\
	${PROG_NOINST}.nds
	${PROG_NOINST}.nds	\
	${PROG_NOINST}.nro	\
	${PROG_NOINST}.rpx	\
	serialization_xml.m	\
	testfile_bin.m		\
	testfile_ini.m
DISTCLEAN = Info.plist

PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = ForwardingTests.m		\
       OFArrayTests.m			\
       ${OF_BLOCK_TESTS_M}		\
       OFCharacterSetTests.m		\
       OFDataTests.m			\
       OFDateTests.m			\
       OFDictionaryTests.m		\
       OFHMACTests.m			\
       OFINIFileTests.m			\
       OFInvocationTests.m		\
       OFJSONTests.m			\
       OFListTests.m			\
       OFLocaleTests.m			\
       OFMD5HashTests.m			\
       OFMemoryStreamTests.m		\
       OFMethodSignatureTests.m		\
       OFNotificationCenterTests.m	\
       OFNumberTests.m			\
       OFObjectTests.m			\
       OFPBKDF2Tests.m			\
       OFPropertyListTests.m		\
       OFRIPEMD160HashTests.m		\
       OFSHA1HashTests.m		\
       OFSHA224HashTests.m		\
       OFSHA256HashTests.m		\
       OFSHA384HashTests.m		\
       OFSHA512HashTests.m		\
       OFScryptTests.m			\
       OFSerializationTests.m		\
       OFSetTests.m			\
       OFStreamTests.m			\
       OFStringTests.m			\
       OFSystemInfoTests.m		\
       OFURLTests.m			\
       OFURITests.m			\
       OFValueTests.m			\
       OFXMLElementBuilderTests.m	\
       OFXMLNodeTests.m			\
       OFXMLParserTests.m		\
       RuntimeTests.m			\
       ${RUNTIME_ARC_TESTS_M}		\
       TestsAppDelegate.m		\
       ${USE_SRCS_FILES}		\
       ${USE_SRCS_PLUGINS}		\
       ${USE_SRCS_SOCKETS}		\
       ${USE_SRCS_THREADS}		\
       ${USE_SRCS_WINDOWS}
       ${USE_SRCS_WINDOWS}		\
SRCS_FILES = OFHMACTests.m		\
	     OFINIFileTests.m		\
	     OFMD5HashTests.m		\
	     OFRIPEMD160HashTests.m	\
	     OFSerializationTests.m	\
	     OFSHA1HashTests.m		\
       serialization_xml.m		\
       testfile_bin.m			\
	     OFSHA224HashTests.m	\
	     OFSHA256HashTests.m	\
	     OFSHA384HashTests.m	\
	     OFSHA512HashTests.m
       testfile_ini.m
SRCS_PLUGINS = OFPluginTests.m
SRCS_SOCKETS = OFDNSResolverTests.m		\
	       ${OF_HTTP_CLIENT_TESTS_M}	\
	       OFHTTPCookieTests.m		\
	       OFHTTPCookieManagerTests.m	\
	       OFKernelEventObserverTests.m	\
	       OFSocketTests.m			\
77
78
79
80
81
82
83







84
85
86
87
88
89
90
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106







+
+
+
+
+
+
+







SRCS_WINDOWS = OFWindowsRegistryKeyTests.m

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}
	rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}
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
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







-
-
+

















-

-
-

















+
+
+




-
+


-
-
+
+


+
+
+
+
+
+
+
+
+
-
-
+
+






	fi
	echo "Uploading files to iOS device ${IOS_HOST} at ${IOS_TMP}..."
	ssh ${IOS_USER}@${IOS_HOST} \
	    'rm -fr ${IOS_TMP} && mkdir -p ${IOS_TMP}/plugin'
	destname=libobjfw.${OBJFW_LIB_MAJOR}.dylib; \
	scp -q ../src/libobjfw.dylib \
	    ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/$$destname
	scp -q tests testfile.bin testfile.txt testfile.ini serialization.xml \
	    ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/
	scp -q tests testfile.txt ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/
	scp -q plugin/TestPlugin.bundle \
	    ${IOS_USER}@${IOS_HOST}:${IOS_TMP}/plugin/
	echo "Running tests binary on iOS device ${IOS_HOST}..."
	ssh ${IOS_USER}@${IOS_HOST} \
	    'cd ${IOS_TMP} && DYLD_LIBRARY_PATH=. ${WRAPPER} ./tests'

run-on-android: all
	echo "Uploading files to Android device..."
	if test -f ../src/libobjfw.so; then \
		adb push ../src/libobjfw.so \
		    /data/local/tmp/objfw/libobjfw.so.${OBJFW_LIB_MAJOR}; \
	fi
	if test -f ../src/runtime/libobjfwrt.so; then \
		adb push ../src/runtime/libobjfwrt.so \
		    /data/local/tmp/objfw/libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \
	fi
	adb push tests /data/local/tmp/objfw/tests
	adb push testfile.bin /data/local/tmp/objfw/testfile.bin
	adb push testfile.txt /data/local/tmp/objfw/testfile.txt
	adb push testfile.ini /data/local/tmp/objfw/testfile.ini
	adb push serialization.xml /data/local/tmp/objfw/serialization.xml
	if test -f plugin/TestPlugin.so; then \
		adb push plugin/TestPlugin.so \
		    /data/local/tmp/objfw/plugin/TestPlugin.so; \
	fi
	echo "Running tests binary on Android device..."
	adb shell 'cd /data/local/tmp/objfw && LD_LIBRARY_PATH=. exec ${WRAPPER} ./tests'

EBOOT.PBP: ${PROG_NOINST}
	psp-fixup-imports ${PROG_NOINST}
	mksfo "ObjFW Tests" PARAM.SFO
	psp-strip ${PROG_NOINST}
	pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL ${PROG_NOINST} NULL

boot.dol: ${PROG_NOINST}
	elf2dol ${PROG_NOINST} $@

${PROG_NOINST}: ${LIBOBJFW_DEP} ${LIBOBJFWRT_DEP}

${PROG_NOINST}.3dsx: ${PROG_NOINST}
	3dsxtool $< $@

${PROG_NOINST}.arm9: ${PROG_NOINST}
	arm-none-eabi-objcopy -O binary $< $@

${PROG_NOINST}.nds: ${PROG_NOINST}.arm9
${PROG_NOINST}.nds: ${PROG_NOINST}.arm9 testfile.txt
	rm -fr nds-data
	mkdir -p nds-data
	cp testfile.bin testfile.txt testfile.ini serialization.xml nds-data
	ndstool -c $@ -9 $< -d nds-data
	cp testfile.txt nds-data
	ndstool -c $@ -9 ${PROG_NOINST} -d nds-data
	rm -fr nds-data

${PROG_NOINST}.nro: ${PROG_NOINST} testfile.txt
	rm -fr romfs
	mkdir -p romfs
	cp testfile.txt romfs
	nacptool --create "ObjFW tests" "Jonathan Schleifer" \
		"${PACKAGE_VERSION}" tests.nacp
	elf2nro ${PROG_NOINST} $@ --nacp=tests.nacp --romfsdir=romfs
	rm -fr romfs tests.nacp

${PROG_NOINST}.3dsx: ${PROG_NOINST}
	3dsxtool $< $@
${PROG_NOINST}.rpx: ${PROG_NOINST}
	elf2rpl $< $@

CPPFLAGS += -I../src -I../src/exceptions -I../src/runtime -I.. -DSTDOUT
OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions
LIBS := ${TESTS_LIBS} ${LIBS}
LDFLAGS += ${MAP_LDFLAGS}
LD = ${OBJC}

Modified tests/OFArrayTests.m from [76dfc16c23] to [cc2ce2f7d0].

182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
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: OFRangeMake(1, 2)] isEqual:
	    [[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]])
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
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







-
+
+
+













-
+







	    R([mutableArray1 replaceObjectAtIndex: 0 withObject: cArray[0]]) &&
	    [[mutableArray1 objectAtIndex: 0] isEqual: cArray[0]] &&
	    [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] &&
	    [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]])

	TEST(@"-[removeObject:]",
	    R([mutableArray1 removeObject: cArray[0]]) &&
	    mutableArray1.count == 2)
	    mutableArray1.count == 1)

	[mutableArray1 addObject: cArray[0]];

	TEST(@"-[removeObjectIdenticalTo:]",
	    R([mutableArray1 removeObjectIdenticalTo: cArray[2]]) &&
	    mutableArray1.count == 1)

	mutableArray2 = [[array1 mutableCopy] autorelease];
	TEST(@"-[removeObjectAtIndex:]",
	    R([mutableArray2 removeObjectAtIndex: 1]) &&
	    mutableArray2.count == 2 &&
	    [[mutableArray2 objectAtIndex: 1] isEqual: cArray[2]])

	mutableArray2 = [[array1 mutableCopy] autorelease];
	TEST(@"-[removeObjectsInRange:]",
	    R([mutableArray2 removeObjectsInRange: OFRangeMake(0, 2)]) &&
	    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]",
256
257
258
259
260
261
262
263

264
265
266
267
268
269
270
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:
		OFRangeMake(0, mutableArray1.count + 1)])
		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"])
425
426
427
428
429
430
431
432
433
434



435
436
437
438
439
440
441



442
443
444
445
446
447
448
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:
	    [OFMutableURL URLWithString: @"http://foo.bar/"],
	    [OFMutableURL URLWithString: @"http://bar.qux/"],
	    [OFMutableURL URLWithString: @"http://qux.quxqux/"], nil];
	    [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:
	    [OFURL URLWithString: @"http://foo.bar:1234/"],
	    [OFURL URLWithString: @"http://bar.qux:1234/"],
	    [OFURL URLWithString: @"http://qux.quxqux:1234/"], nil]])
	    [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
78

79
80
81
82
83
84
85
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: OFRangeMake('0', 10)]) &&
	    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
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
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: OFRangeMake(1, 2)]) &&
	    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: OFRangeMake(0, 7)];
			    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: OFRangeMake(0, 7)];
			    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: OFRangeMake(0, 7)];
			    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: OFRangeMake(0, 7)];
			    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: OFRangeMake(1, 6)]) &&
				  range: OFMakeRange(1, 6)]) &&
	    range.location == 5 && range.length == 1)

	range = [data rangeOfData: [OFData dataWithItems: "aa"
						   count: 1
						itemSize: 2]
			  options: OFDataSearchBackwards
			    range: OFRangeMake(0, 5)];
			    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: OFRangeMake(0, 1)])
			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: OFRangeMake(8, 1)])
			range: OFMakeRange(8, 1)])

	TEST(@"-[subdataWithRange:]",
	    [[data subdataWithRange: OFRangeMake(2, 4)]
	    [[data subdataWithRange: OFMakeRange(2, 4)]
	    isEqual: [OFData dataWithItems: "accdacaa" count: 4 itemSize: 2]] &&
	    [[mutableData subdataWithRange: OFRangeMake(2, 3)]
	    [[mutableData subdataWithRange: OFMakeRange(2, 3)]
	    isEqual: [OFData dataWithItems: "cde" count: 3]])

	EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #1",
	    OFOutOfRangeException,
	    [data subdataWithRange: OFRangeMake(7, 1)])
	    [data subdataWithRange: OFMakeRange(7, 1)])

	EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #2",
	    OFOutOfRangeException,
	    [mutableData subdataWithRange: OFRangeMake(6, 1)])
	    [mutableData subdataWithRange: OFMakeRange(6, 1)])

	TEST(@"-[stringByMD5Hashing]",
	    [mutableData.stringByMD5Hashing
	    isEqual: @"ab56b4d92b40713acc5af89985d4b786"])

	TEST(@"-[stringByRIPEMD160Hashing]",
	    [mutableData.stringByRIPEMD160Hashing
214
215
216
217
218
219
220
221

222
223
224
225
226
227
228
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: OFRangeMake(mutableData.count, 1)])
	    [mutableData removeItemsInRange: OFMakeRange(mutableData.count, 1)])

	OFFreeMemory(raw[0]);
	OFFreeMemory(raw[1]);

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFDateTests.m from [817a8be5a4] to [f110295df2].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+







 */

#include "config.h"

#include <time.h>

#import "TestsAppDelegate.h"
#import "OFStrPTime.h"

static OFString *const module = @"OFDate";

@implementation TestsAppDelegate (OFDateTests)
- (void)dateTests
{
	void *pool = objc_autoreleasePoolPush();

Modified tests/OFDictionaryTests.m from [7127a0734c] to [856ca278b2].

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
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: @""];

	TEST(@"-[stringByURLEncoding]",
	    [[[OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar",
							  @"q&x", @"q=x", nil]
	    stringByURLEncoding] isEqual: @"q%26x=q%3Dx&foo=bar"])

#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 [7c5227bed5] to [dc8ace4048].

47
48
49
50
51
52
53

54

55
56
57
58
59
60
61
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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
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
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;
	OFURL *URL;
	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];

	URL = [OFURL URLWithString:
	URI = [OFURI URIWithString:
	    [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo",
					server->_port]];

	TEST(@"-[asyncPerformRequest:]",
	    (client = [OFHTTPClient client]) && (client.delegate = self) &&
	    (request = [OFHTTPRequest requestWithURL: URL]) &&
	    (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
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
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];
	OFURL *URL1, *URL2, *URL3, *URL4;
	OFURI *URI1, *URI2, *URI3, *URI4;
	OFHTTPCookie *cookie1, *cookie2, *cookie3, *cookie4, *cookie5;

	URL1 = [OFURL URLWithString: @"http://nil.im/foo"];
	URL2 = [OFURL URLWithString: @"https://nil.im/foo/bar"];
	URL3 = [OFURL URLWithString: @"https://test.nil.im/foo/bar"];
	URL4 = [OFURL URLWithString: @"http://webkeks.org/foo/bar"];
	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:forURL:] #1",
	    R([manager addCookie: cookie1 forURL: URL1]))
	TEST(@"-[addCookie:forURI:] #1",
	    R([manager addCookie: cookie1 forURI: URI1]))

	TEST(@"-[cookiesForURL:] #1",
	    [[manager cookiesForURL: URL1] isEqual:
	TEST(@"-[cookiesForURI:] #1",
	    [[manager cookiesForURI: URI1] isEqual:
	    [OFArray arrayWithObject: cookie1]])

	cookie2 = [OFHTTPCookie cookieWithName: @"test"
					 value: @"2"
					domain: @"webkeks.org"];
	TEST(@"-[addCookie:forURL:] #2",
	    R([manager addCookie: cookie2 forURL: URL1]))
	TEST(@"-[addCookie:forURI:] #2",
	    R([manager addCookie: cookie2 forURI: URI1]))

	TEST(@"-[cookiesForURL:] #2",
	    [[manager cookiesForURL: URL1] isEqual:
	TEST(@"-[cookiesForURI:] #2",
	    [[manager cookiesForURI: URI1] isEqual:
	    [OFArray arrayWithObject: cookie1]] &&
	    [[manager cookiesForURL: URL4] isEqual: [OFArray array]])
	    [[manager cookiesForURI: URI4] isEqual: [OFArray array]])

	cookie3 = [OFHTTPCookie cookieWithName: @"test"
					 value: @"3"
					domain: @"nil.im"];
	cookie3.secure = true;
	TEST(@"-[addCookie:forURL:] #3",
	    R([manager addCookie: cookie3 forURL: URL2]))
	TEST(@"-[addCookie:forURI:] #3",
	    R([manager addCookie: cookie3 forURI: URI2]))

	TEST(@"-[cookiesForURL:] #3",
	    [[manager cookiesForURL: URL2] isEqual:
	TEST(@"-[cookiesForURI:] #3",
	    [[manager cookiesForURI: URI2] isEqual:
	    [OFArray arrayWithObject: cookie3]] &&
	    [[manager cookiesForURL: URL1] isEqual: [OFArray array]])
	    [[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:forURL:] #4",
	    R([manager addCookie: cookie4 forURL: URL2]))
	TEST(@"-[addCookie:forURI:] #4",
	    R([manager addCookie: cookie4 forURI: URI2]))

	TEST(@"-[cookiesForURL:] #4",
	    [[manager cookiesForURL: URL2] isEqual:
	TEST(@"-[cookiesForURI:] #4",
	    [[manager cookiesForURI: URI2] isEqual:
	    [OFArray arrayWithObject: cookie4]] &&
	    [[manager cookiesForURL: URL3] isEqual:
	    [[manager cookiesForURI: URI3] isEqual:
	    [OFArray arrayWithObject: cookie4]])

	cookie5 = [OFHTTPCookie cookieWithName: @"bar"
					 value: @"5"
					domain: @"test.nil.im"];
	TEST(@"-[addCookie:forURL:] #5",
	    R([manager addCookie: cookie5 forURL: URL1]))
	TEST(@"-[addCookie:forURI:] #5",
	    R([manager addCookie: cookie5 forURI: URI1]))

	TEST(@"-[cookiesForURL:] #5",
	    [[manager cookiesForURL: URL1] isEqual:
	TEST(@"-[cookiesForURI:] #5",
	    [[manager cookiesForURI: URI1] isEqual:
	    [OFArray arrayWithObject: cookie4]] &&
	    [[manager cookiesForURL: URL3] isEqual:
	    [[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
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
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();
	OFURL *URL = [OFURL URLWithString: @"http://nil.im"];
	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:forURL:] #1",
	TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #1",
	    [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary
	    dictionaryWithObject: @"foo=bar"
	    forKey: @"Set-Cookie"] forURL: URL]
	    forKey: @"Set-Cookie"] forURI: URI]
	    isEqual: [OFArray arrayWithObject: cookie1]])

	cookie2 = [OFHTTPCookie cookieWithName: @"qux"
					 value: @"cookie"
					domain: @"nil.im"];
	TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #2",
	TEST(@"+[cookiesWithResponseHeaderFields:forURI:] #2",
	    [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary
	    dictionaryWithObject: @"foo=bar,qux=cookie"
	    forKey: @"Set-Cookie"] forURL: URL]
	    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:forURL:] #3",
	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"] forURL: URL]) isEqual:
	    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 [7188d57b9b] to [18e2931d0e].

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
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







+



-
-
+
+




+
-
-
-
+
+
+







	    @"[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;
#ifndef OF_NINTENDO_DS
	OFString *writePath;
#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS)
	OFURI *writeURI;
#endif

	module = @"OFINIFile";

	URI = [OFURI URIWithString: @"embedded:testfile.ini"];
	TEST(@"+[fileWithPath:encoding:]",
	    (file = [OFINIFile fileWithPath: @"testfile.ini"
				   encoding: OFStringEncodingCodepage437]))
	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)

109
110
111
112
113
114
115
116
117
118




119
120
121
122
123




124
125

126
127
128
129
130
131
132
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







-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
+







	TEST(@"-[removeValueForKey:]",
	    R([foobar removeValueForKey: @"quxqux "]) &&
	    R([types removeValueForKey: @"array2"]))

	module = @"OFINIFile";

	/* FIXME: Find a way to write files on Nintendo DS */
#ifndef OF_NINTENDO_DS
	writePath = [[OFSystemInfo temporaryDirectoryPath]
	    stringByAppendingPathComponent: @"objfw-tests.ini"];
#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS)
	writeURI = [[OFSystemInfo temporaryDirectoryURI]
	    URIByAppendingPathComponent: @"objfw-tests.ini"
			    isDirectory: false];
	TEST(@"-[writeToFile:encoding:]",
	    R([file writeToFile: writePath
		       encoding: OFStringEncodingCodepage437]) &&
	    [[OFString stringWithContentsOfFile: writePath
				       encoding: OFStringEncodingCodepage437]
	    R([file writeToURI: writeURI
		      encoding: OFStringEncodingCodepage437]) &&
	    [[OFString stringWithContentsOfURI: writeURI
				      encoding: OFStringEncodingCodepage437]
	    isEqual: output])
	[[OFFileManager defaultManager] removeItemAtPath: writePath];
	[[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
27
28


29
30
31


32
33
34
35
36
37


38
39
40
41
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: %@\n",
	    [OFLocale language]];
	[OFStdOut writeFormat: @"[OFLocale] Language code: %@\n",
	    [OFLocale languageCode]];

	[OFStdOut writeFormat: @"[OFLocale] Territory: %@\n",
	    [OFLocale territory]];
	[OFStdOut writeFormat: @"[OFLocale] Country code: %@\n",
	    [OFLocale countryCode]];

	[OFStdOut writeFormat: @"[OFLocale] Encoding: %@\n",
	    OFStringEncodingName([OFLocale encoding])];

	[OFStdOut writeFormat: @"[OFLocale] Decimal point: %@\n",
	    [OFLocale decimalPoint]];
	[OFStdOut writeFormat: @"[OFLocale] Decimal separator: %@\n",
	    [OFLocale decimalSeparator]];

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFMD5HashTests.m from [6eb26d1d7b] to [5005b07061].

25
26
27
28
29
30
31

32

33
34
35
36
37
38
39
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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];

Added tests/OFMemoryStreamTests.m version [14fae61fb2].
























































































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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * 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 "TestsAppDelegate.h"

static OFString *const module = @"OFMemoryStream";
static const char string[] = "abcdefghijkl";

@implementation TestsAppDelegate (OFMemoryStreamTests)
- (void)memoryStreamTests
{
	void *pool = objc_autoreleasePoolPush();
	OFMemoryStream *stream;
	char buffer[10];
	OFMutableData *data;

	TEST(@"+[streamWithMemoryAddress:size:writable:]",
	    (stream = [OFMemoryStream streamWithMemoryAddress: (char *)string
							 size: sizeof(string)
						     writable: false]));

	/*
	 * Test the lowlevel methods, as otherwise OFStream will do one big
	 * read and we will not test OFMemoryStream.
	 */

	TEST(@"-[lowlevelReadIntoBuffer:length:]",
	    [stream lowlevelReadIntoBuffer: buffer length: 5] == 5 &&
	    memcmp(buffer, "abcde", 5) == 0 &&
	    [stream lowlevelReadIntoBuffer: buffer length: 3] == 3 &&
	    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/OFPluginTests.m from [cebf7a6561] to [bb55705657].

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
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







-
+

-
+








+
+
+
-
+

+
+
-
-
+
+
+
+
+

+
+
-
+
+
+
+




#include "config.h"

#import "TestsAppDelegate.h"

#import "plugin/TestPlugin.h"

#ifndef OF_IOS
static OFString *const pluginPath = @"plugin/TestPlugin";
static OFString *const pluginName = @"plugin/TestPlugin";
#else
static OFString *const pluginPath = @"PlugIns/TestPlugin";
static OFString *const pluginName = @"PlugIns/TestPlugin";
#endif

static OFString *const module = @"OFPlugin";

@implementation TestsAppDelegate (OFPluginTests)
- (void)pluginTests
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;
	OFPlugin *plugin;
	Class (*class)(void);
	TestPlugin *plugin;
	TestPlugin *test;

	TEST(@"+[pathForName:]", (path = [OFPlugin pathForName: pluginName]))

	TEST(@"+[pluginWithPath:]",
	    (plugin = [OFPlugin pluginWithPath: pluginPath]))
	TEST(@"+[pluginWithPath:]", (plugin = [OFPlugin pluginWithPath: path]))

	TEST(@"-[addressForSymbol:]",
	    (class = (Class (*)(void))(uintptr_t)
	    [plugin addressForSymbol: @"class"]))

	test = [[class() alloc] init];
	@try {
	TEST(@"TestPlugin's -[test:]", [plugin test: 1234] == 2468)
		TEST(@"TestPlugin's -[test:]", [test test: 1234] == 2468)
	} @finally {
		[test release];
	}

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFRIPEMD160HashTests.m from [4b80756e64] to [c46510efe0].

26
27
28
29
30
31
32

33

34
35
36
37
38
39
40
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [f5847018f6] to [76d8541713].

26
27
28
29
30
31
32

33

34
35
36
37
38
39
40
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [f0d335ef4f] to [a723282b7a].

26
27
28
29
30
31
32

33

34
35
36
37
38
39
40
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [2075144684] to [ea4a5936cb].

26
27
28
29
30
31
32

33

34
35
36
37
38
39
40
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [9815671ea1] to [4335e4cd7c].

27
28
29
30
31
32
33

34

35
36
37
38
39
40
41
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [8ea1d53446] to [9748b0700b].

28
29
30
31
32
33
34

35

36
37
38
39
40
41
42
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"];
	OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"];
	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 [61979a2be4] to [c95d72f728].

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
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







-
-
+
+
+
-
-
-
+
+




+

-
+
-










-
+


-

+








	if (_accepted && _connected)
		[[OFRunLoop mainRunLoop] stop];

	return false;
}

-     (void)socket: (OFSPXSocket *)sock
  didConnectToNode: (unsigned char [IPX_NODE_LEN])node
-	 (void)socket: (OFSPXSocket *)sock
  didConnectToNetwork: (uint32_t)network
		 node: (unsigned char [IPX_NODE_LEN])node
	   network: (uint32_t)network
	      port: (uint16_t)port
	 exception: (id)exception
		 port: (uint16_t)port
	    exception: (id)exception
{
	OFEnsure(!_connected);

	_connected = (sock == _expectedClientSocket &&
	    network == _expectedNetwork &&
	    memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 &&
	    network == _expectedNetwork && port == _expectedPort &&
	    port == _expectedPort && exception == nil);
	    exception == nil);

	if (_accepted && _connected)
		[[OFRunLoop mainRunLoop] stop];
}
@end

@implementation TestsAppDelegate (OFSPXSocketTests)
- (void)SPXSocketTests
{
	void *pool = objc_autoreleasePoolPush();
	OFSPXSocket *sockClient, *sockServer, *sockAccepted;
	OFSPXSocket *sockClient, *sockServer = nil, *sockAccepted;
	OFSocketAddress address1;
	const OFSocketAddress *address2;
	unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN];
	uint32_t network;
	unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN];
	uint16_t port;
	char buffer[5];
	SPXSocketDelegate *delegate;

	TEST(@"+[socket]", (sockClient = [OFSPXSocket socket]) &&
	    (sockServer = [OFSPXSocket socket]))

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
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







-

+




-
-
+
+












+

-
+
-















-
-


+
+



-
-
-
+
+
+




-
+

-
+





-
+










			@throw e;
		}

		objc_autoreleasePoolPop(pool);
		return;
	}

	OFSocketAddressIPXNode(&address1, node);
	network = OFSocketAddressIPXNetwork(&address1);
	OFSocketAddressIPXNode(&address1, node);
	port = OFSocketAddressPort(&address1);

	TEST(@"-[listen]", R([sockServer listen]))

	TEST(@"-[connectToNode:network:port:]",
	    R([sockClient connectToNode: node network: network port: port]))
	TEST(@"-[connectToNetwork:node:port:]",
	    R([sockClient connectToNetwork: network node: node port: port]))

	TEST(@"-[accept]", (sockAccepted = [sockServer accept]))

	TEST(@"-[sendBuffer:length:]",
	    R([sockAccepted sendBuffer: "Hello" length: 5]))

	TEST(@"-[receiveIntoBuffer:length:]",
	    [sockClient receiveIntoBuffer: buffer length: 5] == 5 &&
	    memcmp(buffer, "Hello", 5) == 0)

	TEST(@"-[remoteAddress]",
	    (address2 = sockAccepted.remoteAddress) &&
	    OFSocketAddressIPXNetwork(address2) == network &&
	    R(OFSocketAddressIPXNode(address2, node2)) &&
	    memcmp(node, node2, IPX_NODE_LEN) == 0 &&
	    memcmp(node, node2, IPX_NODE_LEN) == 0)
	    OFSocketAddressIPXNetwork(address2) == network)

	delegate = [[[SPXSocketDelegate alloc] init] autorelease];

	sockServer = [OFSPXSocket socket];
	delegate->_expectedServerSocket = sockServer;
	sockServer.delegate = delegate;

	sockClient = [OFSPXSocket socket];
	delegate->_expectedClientSocket = sockClient;
	sockClient.delegate = delegate;

	address1 = [sockServer bindToPort: 0];
	[sockServer listen];
	[sockServer asyncAccept];

	OFSocketAddressIPXNode(&address1, node);
	memcpy(delegate->_expectedNode, node, IPX_NODE_LEN);
	delegate->_expectedNetwork = network =
	    OFSocketAddressIPXNetwork(&address1);
	OFSocketAddressIPXNode(&address1, node);
	memcpy(delegate->_expectedNode, node, IPX_NODE_LEN);
	delegate->_expectedPort = port = OFSocketAddressPort(&address1);

	@try {
		[sockClient asyncConnectToNode: node
				       network: network
					  port: port];
		[sockClient asyncConnectToNetwork: network
					     node: node
					     port: port];

		[[OFRunLoop mainRunLoop] runUntilDate:
		    [OFDate dateWithTimeIntervalSinceNow: 2]];

		TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]",
		TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]",
		    delegate->_accepted && delegate->_connected)
	} @catch (OFObserveFailedException *e) {
	} @catch (OFObserveKernelEventsFailedException *e) {
		switch (e.errNo) {
		case ENOTSOCK:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFSPXSocket] -[asyncAccept] & "
			    @"-[asyncConnectToNode:network:port:]: select() "
			    @"-[asyncConnectToNetwork:node:port:]: select() "
			    @"not supported for SPX, skipping test"];
			break;
		default:
			@throw e;
		}
	}

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFSPXStreamSocketTests.m from [3b74a95f13] to [af4ba0ff2c].

22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37







-

+







static OFString *const module = @"OFSPXStreamSocket";

@interface SPXStreamSocketDelegate: OFObject <OFSPXStreamSocketDelegate>
{
@public
	OFStreamSocket *_expectedServerSocket;
	OFSPXStreamSocket *_expectedClientSocket;
	unsigned char _expectedNode[IPX_NODE_LEN];
	uint32_t _expectedNetwork;
	unsigned char _expectedNode[IPX_NODE_LEN];
	uint16_t _expectedPort;
	bool _accepted;
	bool _connected;
}
@end

@implementation SPXStreamSocketDelegate
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
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







-
-
+
+
+
-
-
-
+
+




+

-
+
-










-
+


-

+



















+



















-

+




-
-
+
+















+

-
+
-















-
-


+
+



-
-
-
+
+
+




-
+

-
+





-
+











	if (_accepted && _connected)
		[[OFRunLoop mainRunLoop] stop];

	return false;
}

-     (void)socket: (OFSPXStreamSocket *)sock
  didConnectToNode: (unsigned char [IPX_NODE_LEN])node
-	 (void)socket: (OFSPXStreamSocket *)sock
  didConnectToNetwork: (uint32_t)network
		 node: (unsigned char [IPX_NODE_LEN])node
	   network: (uint32_t)network
	      port: (uint16_t)port
	 exception: (id)exception
		 port: (uint16_t)port
	    exception: (id)exception
{
	OFEnsure(!_connected);

	_connected = (sock == _expectedClientSocket &&
	    network == _expectedNetwork &&
	    memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 &&
	    network == _expectedNetwork && port == _expectedPort &&
	    port == _expectedPort && exception == nil);
	    exception == nil);

	if (_accepted && _connected)
		[[OFRunLoop mainRunLoop] stop];
}
@end

@implementation TestsAppDelegate (OFSPXStreamSocketTests)
- (void)SPXStreamSocketTests
{
	void *pool = objc_autoreleasePoolPush();
	OFSPXStreamSocket *sockClient, *sockServer, *sockAccepted;
	OFSPXStreamSocket *sockClient, *sockServer = nil, *sockAccepted;
	OFSocketAddress address1;
	const OFSocketAddress *address2;
	unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN];
	uint32_t network;
	unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN];
	uint16_t port;
	char buffer[5];
	SPXStreamSocketDelegate *delegate;

	TEST(@"+[socket]", (sockClient = [OFSPXStreamSocket socket]) &&
	    (sockServer = [OFSPXStreamSocket socket]))

	@try {
		TEST(@"-[bindToPort:]",
		    R(address1 = [sockServer bindToPort: 0]))
	} @catch (OFBindFailedException *e) {
		switch (e.errNo) {
		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]];
			[OFStdOut writeLine:
			    @"\r[OFSPXStreamSocket] -[bindToPort:]: "
			    @"IPX not configured, skipping tests"];
			break;
		default:
			@throw e;
		}

		objc_autoreleasePoolPop(pool);
		return;
	}

	OFSocketAddressIPXNode(&address1, node);
	network = OFSocketAddressIPXNetwork(&address1);
	OFSocketAddressIPXNode(&address1, node);
	port = OFSocketAddressPort(&address1);

	TEST(@"-[listen]", R([sockServer listen]))

	TEST(@"-[connectToNode:network:port:]",
	    R([sockClient connectToNode: node network: network port: port]))
	TEST(@"-[connectToNetwork:node:port:]",
	    R([sockClient connectToNetwork: network node: node port: port]))

	TEST(@"-[accept]", (sockAccepted = [sockServer accept]))

	/* Test reassembly (this would not work with OFSPXSocket) */
	TEST(@"-[writeBuffer:length:]",
	    R([sockAccepted writeBuffer: "Hello" length: 5]))

	TEST(@"-[readIntoBuffer:length:]",
	    [sockClient readIntoBuffer: buffer length: 2] == 2 &&
	    memcmp(buffer, "He", 2) == 0 &&
	    [sockClient readIntoBuffer: buffer length: 3] == 3 &&
	    memcmp(buffer, "llo", 3) == 0)

	TEST(@"-[remoteAddress]",
	    (address2 = sockAccepted.remoteAddress) &&
	    OFSocketAddressIPXNetwork(address2) == network &&
	    R(OFSocketAddressIPXNode(address2, node2)) &&
	    memcmp(node, node2, IPX_NODE_LEN) == 0 &&
	    memcmp(node, node2, IPX_NODE_LEN) == 0)
	    OFSocketAddressIPXNetwork(address2) == network)

	delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease];

	sockServer = [OFSPXStreamSocket socket];
	delegate->_expectedServerSocket = sockServer;
	sockServer.delegate = delegate;

	sockClient = [OFSPXStreamSocket socket];
	delegate->_expectedClientSocket = sockClient;
	sockClient.delegate = delegate;

	address1 = [sockServer bindToPort: 0];
	[sockServer listen];
	[sockServer asyncAccept];

	OFSocketAddressIPXNode(&address1, node);
	memcpy(delegate->_expectedNode, node, IPX_NODE_LEN);
	delegate->_expectedNetwork = network =
	    OFSocketAddressIPXNetwork(&address1);
	OFSocketAddressIPXNode(&address1, node);
	memcpy(delegate->_expectedNode, node, IPX_NODE_LEN);
	delegate->_expectedPort = port = OFSocketAddressPort(&address1);

	@try {
		[sockClient asyncConnectToNode: node
				       network: network
					  port: port];
		[sockClient asyncConnectToNetwork: network
					     node: node
					     port: port];

		[[OFRunLoop mainRunLoop] runUntilDate:
		    [OFDate dateWithTimeIntervalSinceNow: 2]];

		TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]",
		TEST(@"-[asyncAccept] & -[asyncConnectToNetwork:node:port:]",
		    delegate->_accepted && delegate->_connected)
	} @catch (OFObserveFailedException *e) {
	} @catch (OFObserveKernelEventsFailedException *e) {
		switch (e.errNo) {
		case ENOTSOCK:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFSPXStreamSocket] -[asyncAccept] & "
			    @"-[asyncConnectToNode:network:port:]: select() "
			    @"-[asyncConnectToNetwork:node:port:]: select() "
			    @"not supported for SPX, skipping test"];
			break;
		default:
			@throw e;
		}
	}

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFSerializationTests.m from [5fdb00c13b] to [d36329ce8f].

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
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: [OFURL URLWithString: @"https://objfw.nil.im/"]];
	[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 stringWithContentsOfFile: @"serialization.xml"]])
	    [OFString stringWithContentsOfURI:
	    [OFURI URIWithString: @"embedded:serialization.xml"]]])

	TEST(@"-[objectByDeserializing]",
	    [string.objectByDeserializing isEqual: dict])

	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/OFStringTests.m from [7a4f20e376] to [10adf25aaa].

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
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])

	TEST(@"-[reverse]",
	    R([mutableString1 reverse]) && [mutableString1 isEqual: @"3𝄞1€sät"])

	mutableString2 = [mutableStringClass stringWithString: @"abc"];

#ifdef OF_HAVE_UNICODE_TABLES
	TEST(@"-[uppercase]", R([mutableString1 uppercase]) &&
	    [mutableString1 isEqual: @"3𝄞1€SÄT"] &&
	    [mutableString1 isEqual: @"TÄS€1𝄞3"] &&
	    R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"])

	TEST(@"-[lowercase]", R([mutableString1 lowercase]) &&
	    [mutableString1 isEqual: @"3𝄞1€sät"] &&
	    [mutableString1 isEqual: @"täs€1𝄞3"] &&
	    R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"])

	TEST(@"-[uppercaseString]",
	    [[mutableString1 uppercaseString] isEqual: @"3𝄞1€SÄT"])
	    [[mutableString1 uppercaseString] isEqual: @"TÄS€1𝄞3"])

	TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) &&
	    [[mutableString1 lowercaseString] isEqual: @"3𝄞1€sät"])
	    [[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
363
364


365
366
367
368
369
370
371
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(@"+[stringWithContentsOfURL:encoding]", (string = [stringClass
	    stringWithContentsOfURL: [OFURL fileURLWithPath: @"testfile.txt"]
	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
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
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







-
+










-
+



-
+






-
+


-
-
+
+



-
+


-
+




-
-
-














-
+
+







	    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: OFRangeMake(3, 1)])
	    [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: OFRangeMake(4, 4)] == 6 &&
					       range: OFMakeRange(4, 4)] == 6 &&
	    [C(@"abcđabcđëf")
	    indexOfCharacterFromSet: characterSet
			    options: 0
			      range: OFRangeMake(8, 2)] == OFNotFound)
			      range: OFMakeRange(8, 2)] == OFNotFound)

	EXPECT_EXCEPTION(
	    @"Detect out of range in -[indexOfCharacterFromSet:options:range:]",
	    OFOutOfRangeException,
	    [C(@"𝄞öö") indexOfCharacterFromSet: characterSet
				       options: 0
					 range: OFRangeMake(3, 1)])
					 range: OFMakeRange(3, 1)])

	TEST(@"-[substringWithRange:]",
	    [[C(@"𝄞öö") substringWithRange: OFRangeMake(1, 1)] isEqual: @"ö"] &&
	    [[C(@"𝄞öö") substringWithRange: OFRangeMake(3, 0)] isEqual: @""])
	    [[C(@"𝄞öö") substringWithRange: OFMakeRange(1, 1)] isEqual: @"ö"] &&
	    [[C(@"𝄞öö") substringWithRange: OFMakeRange(3, 0)] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1",
	    OFOutOfRangeException,
	    [C(@"𝄞öö") substringWithRange: OFRangeMake(2, 2)])
	    [C(@"𝄞öö") substringWithRange: OFMakeRange(2, 2)])
	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2",
	    OFOutOfRangeException,
	    [C(@"𝄞öö") substringWithRange: OFRangeMake(4, 0)])
	    [C(@"𝄞öö") substringWithRange: OFMakeRange(4, 0)])

	TEST(@"-[stringByAppendingString:]",
	    [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"])

#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)
	TEST(@"-[isAbsolutePath]",
	    C(@"C:\\foo").absolutePath && C(@"a:/foo").absolutePath &&
	    !C(@"foo").absolutePath && !C(@"b:foo").absolutePath)
# elif defined(OF_AMIGAOS)
	TEST(@"-[isAbsolutePath]",
	    C(@"dh0:foo").absolutePath && C(@"dh0:a/b").absolutePath &&
	    !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"-[isAbsolutePath]",
	    C(@"sdmc:/foo").absolutePath && !C(@"sdmc:foo").absolutePath &&
	    !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath)
# else
	TEST(@"-[isAbsolutePath]",
	    C(@"/foo").absolutePath && C(@"/foo/bar").absolutePath &&
	    !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath)
590
591
592
593
594
595
596
























597
598
599
600
601
602
603
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	string = [stringClass stringWithString: mutableString2];
	[mutableString2 appendString: @"baz"];
	TEST(@"-[stringByAppendingPathComponent:]",
	    [[mutableString1 stringByAppendingPathComponent: @"baz"]
	    isEqual: mutableString2] &&
	    [[string stringByAppendingPathComponent: @"baz"]
	    isEqual: mutableString2])

# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	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"]
	    isEqual: @"foo.bar"])
# endif
#endif

	TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] &&
	    ![C(@"foobar") hasPrefix: @"foobar0"])

	TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] &&
	    ![C(@"foobar") hasSuffix: @"foobar0"])
726
727
728
729
730
731
732
733


734
735
736
737
738
739
740
745
746
747
748
749
750
751

752
753
754
755
756
757
758
759
760







-
+
+







	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]] isEqual: @"foo/bar/baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo/", @"bar", @"", @"baz", @"/", nil]]
	    isEqual: @"foo//bar/baz//"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", nil]] isEqual: @"foo"])
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"+[pathWithComponents:]",
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"foo", @"bar", @"baz", nil]] isEqual: @"foo/bar/baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
	    @"sdmc:", @"foo", @"bar", @"baz", nil]]
	    isEqual: @"sdmc:/foo/bar/baz"] &&
	    [[stringClass pathWithComponents: [OFArray arrayWithObjects:
850
851
852
853
854
855
856
857


858
859
860
861
862
863
864
870
871
872
873
874
875
876

877
878
879
880
881
882
883
884
885







-
+
+







	    [[array objectAtIndex: 1] isEqual: @"bar"] &&
	    [[array objectAtIndex: 2] isEqual: @"baz"] &&
	    /* foo// */
	    (array = C(@"foo//").pathComponents) && array.count == 2 &&
	    [[array objectAtIndex: 0] isEqual: @"foo"] &&
	    [[array objectAtIndex: 1] isEqual: @"/"] &&
	    C(@"").pathComponents.count == 0)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"-[pathComponents]",
	    /* sdmc:/tmp */
	    (array = C(@"sdmc:/tmp").pathComponents) && array.count == 2 &&
	    [[array objectAtIndex: 0] isEqual: @"sdmc:"] &&
	    [[array objectAtIndex: 1] isEqual: @"tmp"] &&
	    /* sdmc:/ */
	    (array = C(@"sdmc:/").pathComponents) && array.count == 1 &&
931
932
933
934
935
936
937
938


939
940
941
942
943
944
945
952
953
954
955
956
957
958

959
960
961
962
963
964
965
966
967







-
+
+







	    [C(@"dh0:tmp").lastPathComponent isEqual: @"tmp"] &&
	    [C(@"dh0:tmp/").lastPathComponent isEqual: @"tmp"] &&
	    [C(@"dh0:/").lastPathComponent isEqual: @"/"] &&
	    [C(@"dh0:").lastPathComponent isEqual: @"dh0:"] &&
	    [C(@"foo").lastPathComponent isEqual: @"foo"] &&
	    [C(@"foo/bar").lastPathComponent isEqual: @"bar"] &&
	    [C(@"foo/bar/baz/").lastPathComponent isEqual: @"baz"])
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"-[lastPathComponent]",
	    [C(@"sdmc:/tmp").lastPathComponent isEqual: @"tmp"] &&
	    [C(@"sdmc:/tmp/").lastPathComponent isEqual: @"tmp"] &&
	    [C(@"sdmc:/").lastPathComponent isEqual: @"sdmc:/"] &&
	    [C(@"sdmc:").lastPathComponent isEqual: @"sdmc:"] &&
	    [C(@"foo").lastPathComponent isEqual: @"foo"] &&
	    [C(@"foo/bar").lastPathComponent isEqual: @"bar"] &&
997
998
999
1000
1001
1002
1003
1004


1005
1006
1007
1008
1009
1010
1011
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
1033
1034







-
+
+







	    [C(@"dh0:tmp/").stringByDeletingLastPathComponent
	    isEqual: @"dh0:"] &&
	    [C(@"dh0:/").stringByDeletingLastPathComponent isEqual: @"dh0:"] &&
	    [C(@"dh0:tmp/foo/").stringByDeletingLastPathComponent
	    isEqual: @"dh0:tmp"] &&
	    [C(@"foo/bar").stringByDeletingLastPathComponent isEqual: @"foo"] &&
	    [C(@"foo").stringByDeletingLastPathComponent isEqual: @""])
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"-[stringByDeletingLastPathComponent]",
	    [C(@"/tmp/").stringByDeletingLastPathComponent isEqual: @""] &&
	    [C(@"sdmc:/tmp/foo/").stringByDeletingLastPathComponent
	    isEqual: @"sdmc:/tmp"] &&
	    [C(@"sdmc:/").stringByDeletingLastPathComponent
	    isEqual: @"sdmc:/"] &&
	    [C(@"foo/bar").stringByDeletingLastPathComponent isEqual: @"foo"] &&
1044
1045
1046
1047
1048
1049
1050
1051


1052
1053
1054
1055
1056
1057
1058
1067
1068
1069
1070
1071
1072
1073

1074
1075
1076
1077
1078
1079
1080
1081
1082







-
+
+







	    [C(@"dh0:foo./bar.baz").stringByDeletingPathExtension
	    isEqual: @"dh0:foo./bar"] &&
	    [C(@"foo.bar/").stringByDeletingPathExtension isEqual: @"foo"] &&
	    [C(@".foo").stringByDeletingPathExtension isEqual: @".foo"] &&
	    [C(@".foo\\bar").stringByDeletingPathExtension
	    isEqual: @".foo\\bar"] &&
	    [C(@".foo.bar").stringByDeletingPathExtension isEqual: @".foo"])
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII)
# elif defined(OF_NINTENDO_3DS) || defined(OF_WII) || \
    defined(OF_NINTENDO_SWITCH)
	TEST(@"-[stringByDeletingPathExtension]",
	    [C(@"foo.bar").stringByDeletingPathExtension isEqual: @"foo"] &&
	    [C(@"foo..bar").stringByDeletingPathExtension isEqual: @"foo."] &&
	    [C(@"sdmc:/foo./bar").stringByDeletingPathExtension
	    isEqual: @"sdmc:/foo./bar"] &&
	    [C(@"sdmc:/foo./bar.baz").stringByDeletingPathExtension
	    isEqual: @"sdmc:/foo./bar"] &&
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
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(@"-[stringByURLEncodingWithAllowedCharacters:]",
	    [[C(@"foo\"ba'_~$]🍏🍌") stringByURLEncodingWithAllowedCharacters:
	    characterSet] isEqual: @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"])
	TEST(@"-[stringByAddingPercentEncodingWithAllowedCharacters:]",
	    [[C(@"foo\"ba'_~$]🍏🍌")
	    stringByAddingPercentEncodingWithAllowedCharacters: characterSet]
	    isEqual: @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"])

	TEST(@"-[stringByURLDecoding]",
	    [C(@"foo%20bar%22+%24%F0%9F%8D%8C").stringByURLDecoding
	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 -[stringByURLDecoding] "
	    @"#1", OFInvalidFormatException,
	    [C(@"foo%xbar") stringByURLDecoding])
	EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] "
	    @"#2", OFInvalidEncodingException,
	    [C(@"foo%FFbar") stringByURLDecoding])
	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: OFRangeMake(1, 3)]) &&
	    R([mutableString1 deleteCharactersInRange: OFMakeRange(1, 3)]) &&
	    [mutableString1 isEqual: @"𝄞bä€"] &&
	    R([mutableString1 deleteCharactersInRange: OFRangeMake(0, 4)]) &&
	    R([mutableString1 deleteCharactersInRange: OFMakeRange(0, 4)]) &&
	    [mutableString1 isEqual: @""])

	TEST(@"-[replaceCharactersInRange:withString:]",
	    (mutableString1 = [mutableStringClass
	    stringWithString: @"𝄞öööbä€"]) &&
	    R([mutableString1 replaceCharactersInRange: OFRangeMake(1, 3)
	    R([mutableString1 replaceCharactersInRange: OFMakeRange(1, 3)
					    withString: @"äöüß"]) &&
	    [mutableString1 isEqual: @"𝄞äöüßbä€"] &&
	    R([mutableString1 replaceCharactersInRange: OFRangeMake(4, 2)
	    R([mutableString1 replaceCharactersInRange: OFMakeRange(4, 2)
					    withString: @"b"]) &&
	    [mutableString1 isEqual: @"𝄞äöübä€"] &&
	    R([mutableString1 replaceCharactersInRange: OFRangeMake(0, 7)
	    R([mutableString1 replaceCharactersInRange: OFMakeRange(0, 7)
					    withString: @""]) &&
	    [mutableString1 isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1",
	    OFOutOfRangeException,
	    {
		mutableString1 = [mutableStringClass stringWithString: @"𝄞öö"];
		[mutableString1 deleteCharactersInRange: OFRangeMake(2, 2)];
		[mutableString1 deleteCharactersInRange: OFMakeRange(2, 2)];
	    })

	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2",
	    OFOutOfRangeException,
	    [mutableString1 deleteCharactersInRange: OFRangeMake(4, 0)])
	    [mutableString1 deleteCharactersInRange: OFMakeRange(4, 0)])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[replaceCharactersInRange:withString:] #1",
	    OFOutOfRangeException,
	    [mutableString1 replaceCharactersInRange: OFRangeMake(2, 2)
	    [mutableString1 replaceCharactersInRange: OFMakeRange(2, 2)
					  withString: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[replaceCharactersInRange:withString:] #2",
	    OFOutOfRangeException,
	    [mutableString1 replaceCharactersInRange: OFRangeMake(4, 0)
	    [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: OFRangeMake(2, 15)]) &&
				 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 [9c2137f367] to [5b9edfd152].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
17
18
19
20
21
22
23



24
25
26
27
28
29
30







-
-
-








#import "TestsAppDelegate.h"

@implementation TestsAppDelegate (OFSystemInfoTests)
- (void)systemInfoTests
{
	void *pool = objc_autoreleasePoolPush();
#ifdef OF_HAVE_FILES
	OFString *userConfigPath, *userDataPath;
#endif

	[OFStdOut setForegroundColor: [OFColor lime]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Page size: %zd\n",
	    [OFSystemInfo pageSize]];

	[OFStdOut writeFormat: @"[OFSystemInfo] Number of CPUs: %zd\n",
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
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]];

#ifdef OF_HAVE_FILES
	[OFStdOut writeFormat: @"[OFSystemInfo] User config URI: %@\n",
	@try {
		userConfigPath = [OFSystemInfo userConfigPath];
	    [OFSystemInfo userConfigURI].string];
	} @catch (OFNotImplementedException *e) {
		userConfigPath = @"Not implemented";
	}
	[OFStdOut writeFormat: @"[OFSystemInfo] User config path: %@\n",

	[OFStdOut writeFormat: @"[OFSystemInfo] User data URI: %@\n",
	    userConfigPath];

	@try {
		userDataPath = [OFSystemInfo userDataPath];
	    [OFSystemInfo userDataURI].string];
	} @catch (OFNotImplementedException *e) {
		userDataPath = @"Not implemented";
	}
	[OFStdOut writeFormat: @"[OFSystemInfo] User data path: %@\n",

	[OFStdOut writeFormat: @"[OFSystemInfo] Temporary directory URI: %@\n",
	    userDataPath];
#endif
	    [OFSystemInfo temporaryDirectoryURI].string];

	[OFStdOut writeFormat: @"[OFSystemInfo] CPU vendor: %@\n",
	    [OFSystemInfo CPUVendor]];

	[OFStdOut writeFormat: @"[OFSystemInfo] CPU model: %@\n",
	    [OFSystemInfo CPUModel]];

Modified tests/OFUNIXDatagramSocketTests.m from [2f01148368] to [54df3210f6].

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
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







-
-
-
+
+
+
+




+
+
+










+
-
+
+








-
+

+







{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;
	OFUNIXDatagramSocket *sock;
	OFSocketAddress address1, address2;
	char buffer[5];

#ifdef OF_HAVE_FILES
	path = [[OFSystemInfo temporaryDirectoryPath]
	    stringByAppendingPathComponent: [[OFUUID UUID] UUIDString]];
#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]))

	@try {
		TEST(@"-[bindToPath:]", R(address1 = [sock bindToPath: path]))
	} @catch (OFBindFailedException *e) {
		switch (e.errNo) {
		if (e.errNo == EAFNOSUPPORT) {
		case EAFNOSUPPORT:
		case EPERM:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFUNIXDatagramSocket] -[bindToPath:]: "
			    @"UNIX datagram sockets unsupported, skipping "
			    @"tests"];

			objc_autoreleasePoolPop(pool);
			return;
		} else
		default:
			@throw e;
		}
	}

	@try {
		TEST(@"-[sendBuffer:length:receiver:]",
		    R([sock sendBuffer: "Hello" length: 5 receiver: &address1]))

		TEST(@"-[receiveIntoBuffer:length:sender:]",

Modified tests/OFUNIXStreamSocketTests.m from [c984b431f1] to [72ce4faa3f].

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
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







-
-
-
+
+
+
+




+
+
+











+
-
+
+







-
+

+







- (void)UNIXStreamSocketTests
{
	void *pool = objc_autoreleasePoolPush();
	OFString *path;
	OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted;
	char buffer[5];

#ifdef OF_HAVE_FILES
	path = [[OFSystemInfo temporaryDirectoryPath]
	    stringByAppendingPathComponent: [[OFUUID UUID] UUIDString]];
#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]) &&
	    (sockServer = [OFUNIXStreamSocket socket]))

	@try {
		TEST(@"-[bindToPath:]", R([sockServer bindToPath: path]))
	} @catch (OFBindFailedException *e) {
		switch (e.errNo) {
		if (e.errNo == EAFNOSUPPORT) {
		case EAFNOSUPPORT:
		case EPERM:
			[OFStdOut setForegroundColor: [OFColor lime]];
			[OFStdOut writeLine:
			    @"\r[OFUNIXStreamSocket] -[bindToPath:]: "
			    @"UNIX stream sockets unsupported, skipping tests"];

			objc_autoreleasePoolPop(pool);
			return;
		} else
		default:
			@throw e;
		}
	}

	@try {
		TEST(@"-[listen]", R([sockServer listen]))

		TEST(@"-[connectToPath:]",
		    R([sockClient connectToPath: path]))

Renamed and modified tests/OFURLTests.m [e63dcbf6b8] to tests/OFURITests.m [e9cb46977b].

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
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 = @"OFURL";
static OFString *URLString = @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/"
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 (OFURLTests)
- (void)URLTests
@implementation TestsAppDelegate (OFURITests)
- (void)URITests
{
	void *pool = objc_autoreleasePoolPush();
	OFURI *URI1, *URI2, *URI3, *URI4, *URI5, *URI6, *URI7, *URI8, *URI9;
	OFURL *URL1, *URL2, *URL3, *URL4, *URL5, *URL6, *URL7;
	OFMutableURL *mutableURL;
	OFURI *URI10;
	OFMutableURI *mutableURI;

	TEST(@"+[URLWithString:]",
	    R(URL1 = [OFURL URLWithString: URLString]) &&
	    R(URL2 = [OFURL URLWithString: @"http://foo:80"]) &&
	    R(URL3 = [OFURL URLWithString: @"http://bar/"]) &&
	    R(URL4 = [OFURL URLWithString: @"file:///etc/passwd"]) &&
	    R(URL5 = [OFURL URLWithString: @"http://foo/bar/qux/foo%2fbar"]) &&
	    R(URL6 = [OFURL URLWithString: @"https://[12:34::56:abcd]/"]) &&
	    R(URL7 = [OFURL URLWithString: @"https://[12:34::56:abcd]:234/"]))
	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(@"+[URLWithString:] fails with invalid characters #1",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #1",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"ht,tp://foo"])
	    [OFURI URIWithString: @"ht,tp://foo"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #2",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #2",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"http://f`oo"])
	    [OFURI URIWithString: @"http://f`oo"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #3",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #3",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"http://foo/`"])
	    [OFURI URIWithString: @"http://foo/`"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #4",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #4",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"http://foo/foo?`"])
	    [OFURI URIWithString: @"http://foo/foo?`"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #5",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #5",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"http://foo/foo?foo#`"])
	    [OFURI URIWithString: @"http://foo/foo?foo#`"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #6",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #6",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"https://[g]/"])
	    [OFURI URIWithString: @"https://[g]/"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #7",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #7",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"https://[f]:/"])
	    [OFURI URIWithString: @"https://[f]:/"])

	EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #8",
	EXPECT_EXCEPTION(@"+[URIWithString:] fails with invalid characters #8",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"https://[f]:f/"])
	    [OFURI URIWithString: @"https://[f]:f/"])

	TEST(@"+[URLWithString:relativeToURL:]",
	    [[[OFURL URLWithString: @"/foo" relativeToURL: URL1] string]
	    isEqual: @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/foo"] &&
	    [[[OFURL URLWithString: @"foo/bar?q"
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/quux"]]
	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"] &&
	    [[[OFURL URLWithString: @"foo/bar"
		     relativeToURL: [OFURL URLWithString: @"http://h/qux/?x"]]
	    [[[OFURI URIWithString: @"foo/bar"
		     relativeToURI: [OFURI URIWithString: @"http://h/qux/?x"]]
	    string] isEqual: @"http://h/qux/foo/bar"] &&
	    [[[OFURL URLWithString: @"http://foo/?q"
		     relativeToURL: URL1] string] isEqual: @"http://foo/?q"] &&
	    [[[OFURL URLWithString: @"foo"
		     relativeToURL: [OFURL URLWithString: @"http://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"] &&
	    [[[OFURL URLWithString: @"foo"
		     relativeToURL: [OFURL URLWithString: @"http://foo"]]
	    [[[OFURI URIWithString: @"foo"
		     relativeToURI: [OFURI URIWithString: @"http://foo"]]
	    string] isEqual: @"http://foo/foo"])

	EXPECT_EXCEPTION(
	    @"+[URLWithString:relativeToURL:] fails with invalid characters #1",
	    @"+[URIWithString:relativeToURI:] fails with invalid characters #1",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"`" relativeToURL: URL1])
	    [OFURI URIWithString: @"`" relativeToURI: URI1])

	EXPECT_EXCEPTION(
	    @"+[URLWithString:relativeToURL:] fails with invalid characters #2",
	    @"+[URIWithString:relativeToURI:] fails with invalid characters #2",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"/`" relativeToURL: URL1])
	    [OFURI URIWithString: @"/`" relativeToURI: URI1])

	EXPECT_EXCEPTION(
	    @"+[URLWithString:relativeToURL:] fails with invalid characters #3",
	    @"+[URIWithString:relativeToURI:] fails with invalid characters #3",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"?`" relativeToURL: URL1])
	    [OFURI URIWithString: @"?`" relativeToURI: URI1])

	EXPECT_EXCEPTION(
	    @"+[URLWithString:relativeToURL:] fails with invalid characters #4",
	    @"+[URIWithString:relativeToURI:] fails with invalid characters #4",
	    OFInvalidFormatException,
	    [OFURL URLWithString: @"#`" relativeToURL: URL1])
	    [OFURI URIWithString: @"#`" relativeToURI: URI1])

#ifdef OF_HAVE_FILES
	TEST(@"+[fileURLWithPath:]",
	    [[[OFURL fileURLWithPath: @"testfile.txt"] fileSystemRepresentation]
	TEST(@"+[fileURIWithPath:]",
	    [[[OFURI fileURIWithPath: @"testfile.txt"] fileSystemRepresentation]
	    isEqual: [[OFFileManager defaultManager].currentDirectoryPath
	    stringByAppendingPathComponent: @"testfile.txt"]])

# if defined(OF_WINDOWS) || defined(OF_MSDOS)
	OFURL *tmp;
	TEST(@"+[fileURLWithPath:] for c:\\",
	    (tmp = [OFURL fileURLWithPath: @"c:\\"]) &&
	    [tmp.string isEqual: @"file:///c:/"] &&
	OFURI *tmp;
	TEST(@"+[fileURIWithPath:] for c:\\",
	    (tmp = [OFURI fileURIWithPath: @"c:\\"]) &&
	    [tmp.string isEqual: @"file:/c:/"] &&
	    [tmp.fileSystemRepresentation isEqual: @"c:\\"])
# endif

# ifdef OF_WINDOWS
	TEST(@"+[fileURLWithPath:] with UNC",
	    (tmp = [OFURL fileURLWithPath: @"\\\\foo\\bar"]) &&
	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 = [OFURL fileURLWithPath: @"\\\\test"]) &&
	    (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]",
	    [URL1.string isEqual: URLString] &&
	    [URL2.string isEqual: @"http://foo:80"] &&
	    [URL3.string isEqual: @"http://bar/"] &&
	    [URL4.string isEqual: @"file:///etc/passwd"])
	    [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]",
	    [URL1.scheme isEqual: @"ht:tp"] && [URL4.scheme isEqual: @"file"])
	    [URI1.scheme isEqual: @"ht+tp"] && [URI4.scheme isEqual: @"file"] &&
	    [URI9.scheme isEqual: @"file"] && [URI10.scheme isEqual: @"file"])

	TEST(@"-[user]", [URL1.user isEqual: @"us:er"] && URL4.user == nil)
	TEST(@"-[user]", [URI1.user isEqual: @"us:er"] && URI4.user == nil &&
	    URI10.user == nil)
	TEST(@"-[password]",
	    [URL1.password isEqual: @"p@w"] && URL4.password == nil)
	TEST(@"-[host]", [URL1.host isEqual: @"ho:st"] &&
	    [URL6.host isEqual: @"12:34::56:abcd"] &&
	    [URL7.host isEqual: @"12:34::56:abcd"])
	TEST(@"-[port]", URL1.port.unsignedShortValue == 1234 &&
	    [URL4 port] == nil && URL7.port.unsignedShortValue == 234)
	    [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]",
	    [URL1.path isEqual: @"/pa?th"] &&
	    [URL4.path isEqual: @"/etc/passwd"])
	    [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]",
	    [URL1.pathComponents isEqual:
	    [URI1.pathComponents isEqual:
	    [OFArray arrayWithObjects: @"/", @"pa?th", nil]] &&
	    [URL4.pathComponents isEqual:
	    [URI4.pathComponents isEqual:
	    [OFArray arrayWithObjects: @"/", @"etc", @"passwd", nil]] &&
	    [URL5.pathComponents isEqual:
	    [URI5.pathComponents isEqual:
	    [OFArray arrayWithObjects: @"/", @"bar", @"qux", @"foo/bar", nil]])
	TEST(@"-[lastPathComponent]",
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz"]
	    [[[OFURI URIWithString: @"http://host/foo//bar/baz"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo//bar/baz/"]
	    [[[OFURI URIWithString: @"http://host/foo//bar/baz/"]
	    lastPathComponent] isEqual: @"baz"] &&
	    [[[OFURL URLWithString: @"http://host/foo/"]
	    [[[OFURI URIWithString: @"http://host/foo/"]
	    lastPathComponent] isEqual: @"foo"] &&
	    [[[OFURL URLWithString: @"http://host/"]
	    [[[OFURI URIWithString: @"http://host/"]
	    lastPathComponent] isEqual: @"/"] &&
	    [URL5.lastPathComponent isEqual: @"foo/bar"])
	    [URI5.lastPathComponent isEqual: @"foo/bar"])
	TEST(@"-[query]",
	    [URL1.query isEqual: @"que#ry=1&f&oo=b=ar"] && URL4.query == nil)
	TEST(@"-[queryDictionary]",
	    [URL1.queryDictionary isEqual:
	    [OFDictionary dictionaryWithKeysAndObjects:
	    @"que#ry", @"1", @"f&oo", @"b=ar", nil]]);
	    [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]",
	    [URL1.fragment isEqual: @"frag#ment"] && URL4.fragment == nil)
	    [URI1.fragment isEqual: @"frag#ment"] && URI4.fragment == nil &&
	    [URI9.fragment isEqual: @"frag"] &&
	    [URI10.fragment isEqual: @"frag"])

	TEST(@"-[copy]", R(URL4 = [[URL1 copy] autorelease]))
	TEST(@"-[copy]", R(URI4 = [[URI1 copy] autorelease]))

	TEST(@"-[isEqual:]", [URL1 isEqual: URL4] && ![URL2 isEqual: URL3] &&
	    [[OFURL URLWithString: @"HTTP://bar/"] isEqual: URL3])
	TEST(@"-[isEqual:]", [URI1 isEqual: URI4] && ![URI2 isEqual: URI3] &&
	    [[OFURI URIWithString: @"HTTP://bar/"] isEqual: URI3])

	TEST(@"-[hash:]", URL1.hash == URL4.hash && URL2.hash != URL3.hash)
	TEST(@"-[hash:]", URI1.hash == URI4.hash && URI2.hash != URI3.hash)

	EXPECT_EXCEPTION(@"Detection of invalid format",
	    OFInvalidFormatException, [OFURL URLWithString: @"http"])
	    OFInvalidFormatException, [OFURI URIWithString: @"http"])

	mutableURL = [OFMutableURL URL];
	mutableURI = [OFMutableURI URIWithScheme: @"dummy"];

	TEST(@"-[setScheme:]",
	    (mutableURL.scheme = @"ht:tp") &&
	    [mutableURL.URLEncodedScheme isEqual: @"ht%3Atp"])

	TEST(@"-[setURLEncodedScheme:]",
	    (mutableURL.URLEncodedScheme = @"ht%3Atp") &&
	    [mutableURL.scheme isEqual: @"ht:tp"])

	EXPECT_EXCEPTION(
	    @"-[setURLEncodedScheme:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedScheme = @"~")
	    @"-[setPercentEncodedScheme:] with invalid characters fails",
	    OFInvalidFormatException, mutableURI.scheme = @"%20")

	TEST(@"-[setHost:]",
	    (mutableURL.host = @"ho:st") &&
	    [mutableURL.URLEncodedHost isEqual: @"ho%3Ast"] &&
	    (mutableURL.host = @"12:34:ab") &&
	    [mutableURL.URLEncodedHost isEqual: @"[12:34:ab]"] &&
	    (mutableURL.host = @"12:34:aB") &&
	    [mutableURL.URLEncodedHost isEqual: @"[12:34:aB]"] &&
	    (mutableURL.host = @"12:34:g") &&
	    [mutableURL.URLEncodedHost isEqual: @"12%3A34%3Ag"])
	    (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(@"-[setURLEncodedHost:]",
	    (mutableURL.URLEncodedHost = @"ho%3Ast") &&
	    [mutableURL.host isEqual: @"ho:st"] &&
	    (mutableURL.URLEncodedHost = @"[12:34]") &&
	    [mutableURL.host isEqual: @"12:34"] &&
	    (mutableURL.URLEncodedHost = @"[12::ab]") &&
	    [mutableURL.host isEqual: @"12::ab"])
	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(
	EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails"
	    " #1", OFInvalidFormatException, mutableURL.URLEncodedHost = @"/")
	    @"-[setPercentEncodedHost:] with invalid characters fails #1",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedHost = @"/")

	EXPECT_EXCEPTION(
	EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails"
	    " #2", OFInvalidFormatException,
	    mutableURL.URLEncodedHost = @"[12:34")
	    @"-[setPercentEncodedHost:] with invalid characters fails #2",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedHost = @"[12:34")

	EXPECT_EXCEPTION(
	EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails"
	    " #3", OFInvalidFormatException,
	    mutableURL.URLEncodedHost = @"[a::g]")
	    @"-[setPercentEncodedHost:] with invalid characters fails #3",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedHost = @"[a::g]")

	TEST(@"-[setUser:]",
	    (mutableURL.user = @"us:er") &&
	    [mutableURL.URLEncodedUser isEqual: @"us%3Aer"])
	    (mutableURI.user = @"us:er") &&
	    [mutableURI.percentEncodedUser isEqual: @"us%3Aer"])

	TEST(@"-[setURLEncodedUser:]",
	    (mutableURL.URLEncodedUser = @"us%3Aer") &&
	    [mutableURL.user isEqual: @"us:er"])
	TEST(@"-[setPercentEncodedUser:]",
	    (mutableURI.percentEncodedUser = @"us%3Aer") &&
	    [mutableURI.user isEqual: @"us:er"])

	EXPECT_EXCEPTION(
	EXPECT_EXCEPTION(@"-[setURLEncodedUser:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedHost = @"/")
	    @"-[setPercentEncodedUser:] with invalid characters fails",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedHost = @"/")

	TEST(@"-[setPassword:]",
	    (mutableURL.password = @"pass:word") &&
	    [mutableURL.URLEncodedPassword isEqual: @"pass%3Aword"])
	    (mutableURI.password = @"pass:word") &&
	    [mutableURI.percentEncodedPassword isEqual: @"pass%3Aword"])

	TEST(@"-[setURLEncodedPassword:]",
	    (mutableURL.URLEncodedPassword = @"pass%3Aword") &&
	    [mutableURL.password isEqual: @"pass:word"])
	TEST(@"-[setPercentEncodedPassword:]",
	    (mutableURI.percentEncodedPassword = @"pass%3Aword") &&
	    [mutableURI.password isEqual: @"pass:word"])

	EXPECT_EXCEPTION(
	    @"-[setURLEncodedPassword:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedPassword = @"/")
	    @"-[setPercentEncodedPassword:] with invalid characters fails",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedPassword = @"/")

	TEST(@"-[setPath:]",
	    (mutableURL.path = @"pa/th@?") &&
	    [mutableURL.URLEncodedPath isEqual: @"pa/th@%3F"])
	    (mutableURI.path = @"pa/th@?") &&
	    [mutableURI.percentEncodedPath isEqual: @"pa/th@%3F"])

	TEST(@"-[setURLEncodedPath:]",
	    (mutableURL.URLEncodedPath = @"pa/th@%3F") &&
	    [mutableURL.path isEqual: @"pa/th@?"])
	TEST(@"-[setPercentEncodedPath:]",
	    (mutableURI.percentEncodedPath = @"pa/th@%3F") &&
	    [mutableURI.path isEqual: @"pa/th@?"])

	EXPECT_EXCEPTION(
	EXPECT_EXCEPTION(@"-[setURLEncodedPath:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedPath = @"?")
	    @"-[setPercentEncodedPath:] with invalid characters fails",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedPath = @"?")

	TEST(@"-[setQuery:]",
	    (mutableURL.query = @"que/ry?#") &&
	    [mutableURL.URLEncodedQuery isEqual: @"que/ry?%23"])
	    (mutableURI.query = @"que/ry?#") &&
	    [mutableURI.percentEncodedQuery isEqual: @"que/ry?%23"])

	TEST(@"-[setURLEncodedQuery:]",
	    (mutableURL.URLEncodedQuery = @"que/ry?%23") &&
	    [mutableURL.query isEqual: @"que/ry?#"])
	TEST(@"-[setPercentEncodedQuery:]",
	    (mutableURI.percentEncodedQuery = @"que/ry?%23") &&
	    [mutableURI.query isEqual: @"que/ry?#"])

	EXPECT_EXCEPTION(
	    @"-[setURLEncodedQuery:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedQuery = @"`")
	    @"-[setPercentEncodedQuery:] with invalid characters fails",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedQuery = @"`")

	TEST(@"-[setQueryDictionary:]",
	    (mutableURL.queryDictionary =
	    [OFDictionary dictionaryWithKeysAndObjects:
	    @"foo&bar", @"baz=qux", @"f=oobar", @"b&azqux", nil]) &&
	    [mutableURL.URLEncodedQuery isEqual:
	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:]",
	    (mutableURL.fragment = @"frag/ment?#") &&
	    [mutableURL.URLEncodedFragment isEqual: @"frag/ment?%23"])
	    (mutableURI.fragment = @"frag/ment?#") &&
	    [mutableURI.percentEncodedFragment isEqual: @"frag/ment?%23"])

	TEST(@"-[setURLEncodedFragment:]",
	    (mutableURL.URLEncodedFragment = @"frag/ment?%23") &&
	    [mutableURL.fragment isEqual: @"frag/ment?#"])
	TEST(@"-[setPercentEncodedFragment:]",
	    (mutableURI.percentEncodedFragment = @"frag/ment?%23") &&
	    [mutableURI.fragment isEqual: @"frag/ment?#"])

	EXPECT_EXCEPTION(
	    @"-[setURLEncodedFragment:] with invalid characters fails",
	    OFInvalidFormatException, mutableURL.URLEncodedFragment = @"`")
	    @"-[setPercentEncodedFragment:] with invalid characters fails",
	    OFInvalidFormatException,
	    mutableURI.percentEncodedFragment = @"`")

	TEST(@"-[URLByAppendingPathComponent:isDirectory:]",
	    [[[OFURL URLWithString: @"file:///foo/bar"]
	    URLByAppendingPathComponent: @"qux" isDirectory: false] isEqual:
	    [OFURL URLWithString: @"file:///foo/bar/qux"]] &&
	    [[[OFURL URLWithString: @"file:///foo/bar/"]
	    URLByAppendingPathComponent: @"qux" isDirectory: false] isEqual:
	    [OFURL URLWithString: @"file:///foo/bar/qux"]] &&
	    [[[OFURL URLWithString: @"file:///foo/bar/"]
	    URLByAppendingPathComponent: @"qu?x" isDirectory: false] isEqual:
	    [OFURL URLWithString: @"file:///foo/bar/qu%3Fx"]] &&
	    [[[OFURL URLWithString: @"file:///foo/bar/"]
	    URLByAppendingPathComponent: @"qu?x" isDirectory: true] isEqual:
	    [OFURL URLWithString: @"file:///foo/bar/qu%3Fx/"]])
	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(@"-[URLByStandardizingPath]",
	    [[[OFURL URLWithString: @"http://foo/bar/.."]
	    URLByStandardizingPath] isEqual:
	    [OFURL URLWithString: @"http://foo/"]] &&
	    [[[OFURL URLWithString: @"http://foo/bar/%2E%2E/../qux/"]
	    URLByStandardizingPath] isEqual:
	    [OFURL URLWithString: @"http://foo/bar/qux/"]] &&
	    [[[OFURL URLWithString: @"http://foo/bar/./././qux/./"]
	    URLByStandardizingPath] isEqual:
	    [OFURL URLWithString: @"http://foo/bar/qux/"]] &&
	    [[[OFURL URLWithString: @"http://foo/bar/../../qux"]
	    URLByStandardizingPath] isEqual:
	    [OFURL URLWithString: @"http://foo/../qux"]])
	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
28
29
30
31




32
33
34
35
36
37
38
39
40
41
42
43

44
45
46
47
48
49
50
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 = OFRangeMake(1, 64), range2;
	OFPoint point = OFPointMake(1.5f, 3.0f), point2;
	OFSize size = OFSizeMake(4.5f, 5.0f), size2;
	OFRect rect = OFRectMake(1.5f, 3.0f, 4.5f, 6.0f), rect2;
	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)]) &&
	    OFRangeEqual(range2, range))
	    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
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
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]",
	    OFRangeEqual(value.rangeValue, range) &&
	    OFEqualRanges(value.rangeValue, range) &&
	    (value = [OFValue valueWithBytes: &range
				    objCType: @encode(OFRange)]) &&
	    OFRangeEqual(value.rangeValue, range))
	    OFEqualRanges(value.rangeValue, range))

	TEST(@"-[getValue:size:] for OFRangeValue",
	    (value = [OFValue valueWithRange: range]) &&
	    R([value getValue: &range2 size: sizeof(range2)]) &&
	    OFRangeEqual(range2, range))
	    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]",
	    OFPointEqual(value.pointValue, point) &&
	    OFEqualPoints(value.pointValue, point) &&
	    (value = [OFValue valueWithBytes: &point
				    objCType: @encode(OFPoint)]) &&
	    OFPointEqual(value.pointValue, point))
	    OFEqualPoints(value.pointValue, point))

	TEST(@"-[getValue:size:] for OFPointValue",
	    (value = [OFValue valueWithPoint: point]) &&
	    R([value getValue: &point2 size: sizeof(point2)]) &&
	    OFPointEqual(point2, point))
	    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]",
	    OFSizeEqual(value.sizeValue, size) &&
	    OFEqualSizes(value.sizeValue, size) &&
	    (value = [OFValue valueWithBytes: &size
				    objCType: @encode(OFSize)]) &&
	    OFSizeEqual(value.sizeValue, size))
	    OFEqualSizes(value.sizeValue, size))

	TEST(@"-[getValue:size:] for OFSizeValue",
	    (value = [OFValue valueWithSize: size]) &&
	    R([value getValue: &size2 size: sizeof(size2)]) &&
	    OFSizeEqual(size2, size))
	    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]",
	    OFRectEqual(value.rectValue, rect) &&
	    OFEqualRects(value.rectValue, rect) &&
	    (value = [OFValue valueWithBytes: &rect
				    objCType: @encode(OFRect)]) &&
	    OFRectEqual(value.rectValue, rect))
	    OFEqualRects(value.rectValue, rect))

	TEST(@"-[getValue:size:] for OFRectValue",
	    (value = [OFValue valueWithRect: rect]) &&
	    R([value getValue: &rect2 size: sizeof(rect2)]) &&
	    OFRectEqual(rect2, rect))
	    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 [cfc9942552] to [ddf274227c].

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
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:securityAndAccessRights:]",
	    TEST(@"-[openSubkeyAtPath:accessRights:options:] #1",
	    (softwareKey = [[OFWindowsRegistryKey currentUserKey]
		   openSubkeyAtPath: @"Software"
	    securityAndAccessRights: KEY_ALL_ACCESS]) &&
		openSubkeyAtPath: @"Software"
		    accessRights: KEY_ALL_ACCESS
			 options: 0]))

	EXPECT_EXCEPTION(@"-[openSubkeyAtPath:accessRights:options:] #2",
	    OFOpenWindowsRegistryKeyFailedException,
	    [[OFWindowsRegistryKey currentUserKey]
		   openSubkeyAtPath: @"nonexistent"
	    securityAndAccessRights: KEY_ALL_ACCESS] == nil)
		openSubkeyAtPath: @"nonexistent"
		    accessRights: KEY_ALL_ACCESS
			 options: 0])

	TEST(@"-[createSubkeyAtPath:securityAndAccessRights:]",
	TEST(@"-[createSubkeyAtPath:accessRights:securityAttributes:options:"
	    @"disposition:]",
	    (objFWKey = [softwareKey createSubkeyAtPath: @"ObjFW"
				securityAndAccessRights: KEY_ALL_ACCESS]))
					   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
32
33


34
35
36
37
38
39
40
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
  didBuildParentlessNode: (OFXMLNode *)node
- (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
278

279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
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
				  data: (OFString *)data
				  text: (OFString *)text
{
	[self	    parser: parser
	    didCreateEvent: eventTypeProcessingInstruction
		      name: target
		    prefix: nil
		 namespace: nil
		attributes: nil
		    string: data];
		    string: text];
}

-    (void)parser: (OFXMLParser *)parser
  didStartElement: (OFString *)name
	   prefix: (OFString *)prefix
	namespace: (OFString *)namespace
       attributes: (OFArray *)attrs

Modified tests/RuntimeARCTests.m from [c97e42ea4b] to [62782bae47].

23
24
25
26
27
28
29








30

31
32
33
34
35
36
37
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46







+
+
+
+
+
+
+
+

+







@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
	@throw [OFException exception];
#endif

	return self;
}
@end

@implementation TestsAppDelegate (RuntimeARCTests)
- (void)runtimeARCTests

Modified tests/TestsAppDelegate.h from [453017b72e] to [951626637b].

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
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







+
+
+
+
















+
+
+
+







@interface TestsAppDelegate (OFInvocationTests)
- (void)invocationTests;
@end

@interface TestsAppDelegate (OFJSONTests)
- (void)JSONTests;
@end

@interface TestsAppDelegate (OFHMACTests)
- (void)HMACTests;
@end

@interface TestsAppDelegate (OFKernelEventObserverTests)
- (void)kernelEventObserverTests;
@end

@interface TestsAppDelegate (OFListTests)
- (void)listTests;
@end

@interface TestsAppDelegate (OFLocaleTests)
- (void)localeTests;
@end

@interface TestsAppDelegate (OFMD5HashTests)
- (void)MD5HashTests;
@end

@interface TestsAppDelegate  (OFMemoryStreamTests)
- (void)memoryStreamTests;
@end

@interface TestsAppDelegate (OFMethodSignatureTests)
- (void)methodSignatureTests;
@end

@interface TestsAppDelegate (OFNotificationCenterTests)
- (void)notificationCenterTests;
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
223
224
225
226
227
228
229




230
231
232
233
234
235
236







-
-
-
-







- (void)setTests;
@end

@interface TestsAppDelegate (OFSystemInfoTests)
- (void)systemInfoTests;
@end

@interface TestsAppDelegate (OFHMACTests)
- (void)HMACTests;
@end

@interface TestsAppDelegate (OFSocketTests)
- (void)socketTests;
@end

@interface TestsAppDelegate (OFStreamTests)
- (void)streamTests;
@end
251
252
253
254
255
256
257
258
259


260
261
262
263
264
265
266
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 (OFURLTests)
- (void)URLTests;
@interface TestsAppDelegate (OFURITests)
- (void)URITests;
@end

@interface TestsAppDelegate (OFValueTests)
- (void)valueTests;
@end

@interface TestsAppDelegate (OFWindowsRegistryKeyTests)

Modified tests/TestsAppDelegate.m from [e90fb7f104] to [66423efb5a].

46
47
48
49
50
51
52


















53
54
55
56
57
58
59
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







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








#ifdef OF_NINTENDO_3DS
/* Newer versions of libctru started using id as a parameter name. */
# define id id_3ds
# include <3ds.h>
# undef id
#endif

#ifdef OF_NINTENDO_SWITCH
# define id nx_id
# include <switch.h>
# undef id

static OFDate *lastConsoleUpdate;

static void
updateConsole(bool force)
{
	if (force || lastConsoleUpdate.timeIntervalSinceNow <= -1.0 / 60) {
		consoleUpdate(NULL);
		[lastConsoleUpdate release];
		lastConsoleUpdate = [[OFDate alloc] init];
	}
}
#endif

extern unsigned long OFHashSeed;

#ifdef OF_PSP
static int
exitCallback(int arg1, int arg2, void *arg)
{
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
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







+
+
+
+
+
+
+
+
+
+
-
-
+
+
+






-
-
-



+
+
-
+
+
+
+







#ifdef OF_NINTENDO_3DS
	gfxInitDefault();
	atexit(gfxExit);

	consoleInit(GFX_TOP, NULL);
#endif

#ifdef OF_NINTENDO_SWITCH
	consoleInit(NULL);
	padConfigureInput(1, HidNpadStyleSet_NpadStandard);
	updateConsole(true);

# ifdef OF_HAVE_FILES
	[[OFFileManager defaultManager] changeCurrentDirectoryPath: @"romfs:/"];
# endif
#endif

#if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \
	defined(OF_NINTENDO_3DS)
#if defined(OF_WII) || defined(OF_WII_U) || defined(OF_PSP) || \
    defined(OF_NINTENDO_DS) || defined(OF_NINTENDO_3DS) || \
    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];
		OFString *backtrace = [OFString stringWithFormat:
		    @"\nBacktrace:\n  %@\n\n",
		    [[e backtrace] componentsJoinedByString: @"\n  "]];

		[OFStdOut setForegroundColor: [OFColor red]];
		[OFStdOut writeString: string];

		if ([e stackTraceAddresses] != nil)
		[OFStdOut writeString: backtrace];
			[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();
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
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







+
+
+
+
+
+

















+
+
+
+










+
+
+
+








+
+


-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+


-
-
+
+

-
-
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+


-
-
+
+

-
-
+
+

-
-
+
+

-
-
+
+

+
+
+

+
+
+
+
+
+
+
+
+
+
+
+



-
-
+







			hidScanInput();

			if (hidKeysDown() & KEY_START)
				[OFApplication terminateWithStatus: 1];

			gspWaitForVBlank();
		}
# elif defined(OF_NINTENDO_SWITCH)
		while (appletMainLoop())
			updateConsole(true);

		consoleExit(NULL);
		abort();
# else
		abort();
# endif
	}
#else
	return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]);
#endif
}

@implementation TestsAppDelegate
- (void)outputTesting: (OFString *)test inModule: (OFString *)module
{
	if (OFStdOut.hasTerminal) {
		[OFStdOut setForegroundColor: [OFColor yellow]];
		[OFStdOut writeFormat: @"[%@] %@: testing...", module, test];
	} else
		[OFStdOut writeFormat: @"[%@] %@: ", module, test];

#ifdef OF_NINTENDO_SWITCH
	updateConsole(false);
#endif
}

- (void)outputSuccess: (OFString *)test inModule: (OFString *)module
{
	if (OFStdOut.hasTerminal) {
		[OFStdOut setForegroundColor: [OFColor lime]];
		[OFStdOut eraseLine];
		[OFStdOut writeFormat: @"\r[%@] %@: ok\n", module, test];
	} else
		[OFStdOut writeLine: @"ok"];

#ifdef OF_NINTENDO_SWITCH
	updateConsole(false);
#endif
}

- (void)outputFailure: (OFString *)test inModule: (OFString *)module
{
	if (OFStdOut.hasTerminal) {
		[OFStdOut setForegroundColor: [OFColor red]];
		[OFStdOut eraseLine];
		[OFStdOut writeFormat: @"\r[%@] %@: failed\n", module, test];
	} else
		[OFStdOut writeLine: @"failed"];

#ifdef OF_WII
		[OFStdOut reset];
		[OFStdOut writeLine: @"Press A to continue!"];
	[OFStdOut reset];
	[OFStdOut writeLine: @"Press A to continue!"];

		for (;;) {
			WPAD_ScanPads();
	for (;;) {
		WPAD_ScanPads();

			if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
				return;
		if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A)
			return;

			VIDEO_WaitVSync();
		}
		VIDEO_WaitVSync();
	}
#endif
#ifdef OF_PSP
		[OFStdOut reset];
		[OFStdOut writeLine: @"Press X to continue!"];
	[OFStdOut reset];
	[OFStdOut writeLine: @"Press X to continue!"];

		for (;;) {
			SceCtrlData pad;
	for (;;) {
		SceCtrlData pad;

			sceCtrlReadBufferPositive(&pad, 1);
			if (pad.Buttons & PSP_CTRL_CROSS) {
				for (;;) {
					sceCtrlReadBufferPositive(&pad, 1);
					if (!(pad.Buttons & PSP_CTRL_CROSS))
						return;
				}
			}
		}
		sceCtrlReadBufferPositive(&pad, 1);
		if (pad.Buttons & PSP_CTRL_CROSS) {
			for (;;) {
				sceCtrlReadBufferPositive(&pad, 1);
				if (!(pad.Buttons & PSP_CTRL_CROSS))
					return;
			}
		}
	}
#endif
#ifdef OF_NINTENDO_DS
		[OFStdOut reset];
		[OFStdOut writeString: @"Press A to continue!"];
	[OFStdOut reset];
	[OFStdOut writeString: @"Press A to continue!"];

		for (;;) {
			swiWaitForVBlank();
			scanKeys();
			if (keysDown() & KEY_A)
				break;
		}
	for (;;) {
		swiWaitForVBlank();
		scanKeys();
		if (keysDown() & KEY_A)
			break;
	}
#endif
#ifdef OF_NINTENDO_3DS
		[OFStdOut reset];
		[OFStdOut writeString: @"Press A to continue!"];
	[OFStdOut reset];
	[OFStdOut writeString: @"Press A to continue!"];

		for (;;) {
			hidScanInput();
	for (;;) {
		hidScanInput();

			if (hidKeysDown() & KEY_A)
				break;
		if (hidKeysDown() & KEY_A)
			break;

			gspWaitForVBlank();
		}
		gspWaitForVBlank();
	}
#endif
#ifdef OF_NINTENDO_SWITCH
	[OFStdOut reset];
	[OFStdOut writeString: @"Press A to continue!"];

	while (appletMainLoop()) {
		PadState pad;

		padUpdate(&pad);
		updateConsole(true);

		if (padGetButtonsDown(&pad) & HidNpadButton_A)
			break;
	}
#endif

	if (OFStdOut.hasTerminal) {
		[OFStdOut writeString: @"\r"];
		[OFStdOut reset];
		[OFStdOut eraseLine];
	} else
		[OFStdOut writeLine: @"failed"];
	}
}

- (void)applicationDidFinishLaunching
{
#if defined(OF_IOS) && defined(OF_HAVE_FILES)
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
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
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







+

-








-


-
+




















-
+










-

-







	[self dictionaryTests];
	[self listTests];
	[self setTests];
	[self dateTests];
	[self valueTests];
	[self numberTests];
	[self streamTests];
	[self memoryStreamTests];
	[self notificationCenterTests];
#ifdef OF_HAVE_FILES
	[self MD5HashTests];
	[self RIPEMD160HashTests];
	[self SHA1HashTests];
	[self SHA224HashTests];
	[self SHA256HashTests];
	[self SHA384HashTests];
	[self SHA512HashTests];
	[self HMACTests];
#endif
	[self PBKDF2Tests];
	[self scryptTests];
#if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437)
#ifdef HAVE_CODEPAGE_437
	[self INIFileTests];
#endif
#ifdef OF_HAVE_SOCKETS
	[self socketTests];
	[self TCPSocketTests];
	[self UDPSocketTests];
# ifdef OF_HAVE_IPX
	[self IPXSocketTests];
	[self SPXSocketTests];
	[self SPXStreamSocketTests];
# endif
# ifdef OF_HAVE_UNIX_SOCKETS
	[self UNIXDatagramSocketTests];
	[self UNIXStreamSocketTests];
# endif
	[self kernelEventObserverTests];
#endif
#ifdef OF_HAVE_THREADS
	[self threadTests];
#endif
	[self URLTests];
	[self URITests];
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
	[self HTTPClientTests];
#endif
#ifdef OF_HAVE_SOCKETS
	[self HTTPCookieTests];
	[self HTTPCookieManagerTests];
#endif
	[self XMLParserTests];
	[self XMLNodeTests];
	[self XMLElementBuilderTests];
#ifdef OF_HAVE_FILES
	[self serializationTests];
#endif
	[self JSONTests];
	[self propertyListTests];
#if defined(OF_HAVE_PLUGINS)
	[self pluginTests];
#endif
#ifdef OF_WINDOWS
	[self windowsRegistryKeyTests];
430
431
432
433
434
435
436







437
438
439
440
441
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506







+
+
+
+
+
+
+





		hidScanInput();

		if (hidKeysDown() & KEY_START)
			[OFApplication terminateWithStatus: _fails];

		gspWaitForVBlank();
	}
#elif defined(OF_NINTENDO_SWITCH)
	while (appletMainLoop())
		updateConsole(true);

	consoleExit(NULL);

	[OFApplication terminateWithStatus: _fails];
#else
	[OFApplication terminateWithStatus: _fails];
#endif
}
@end

Modified tests/iOS.xcodeproj/project.pbxproj from [feb9f04764] to [2c6fcc5e96].

131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145







-
+







		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		4BEBFB532013934E002E8710 /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastUpgradeCheck = 0920;
				LastUpgradeCheck = 1330;
				ORGANIZATIONNAME = "Jonathan Schleifer";
				TargetAttributes = {
					4BEBFB5A2013934E002E8710 = {
						CreatedOnToolsVersion = 9.2;
						ProvisioningStyle = Automatic;
					};
				};
198
199
200
201
202
203
204

205
206
207
208
209
210
211

212
213
214
215
216
217
218
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220







+







+







				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;
253
254
255
256
257
258
259

260
261
262
263
264
265
266

267
268
269
270
271
272
273
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277







+







+







				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;

Modified tests/objc_sync/test.m from [63dc58fd99] to [1f28b08c51].

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
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()
main(void)
{
	MyThread *t1, *t2;

	lock = [[OFObject alloc] init];

	t1 = [MyThread thread];
	[t1 setName: @"A"];
	t1.name = @"A";

	t2 = [MyThread thread];
	[t2 setName: @"B"];
	t2.name = @"B";

	[t1 start];
	[t2 start];

	[t1 join];
	[t2 join];

Modified tests/plugin/TestPlugin.h from [52670dca56] to [2f9aa9b796].

9
10
11
12
13
14
15
16

17
18

19
20
9
10
11
12
13
14
15

16
17

18
19
20







-
+

-
+


 *
 * 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 "OFPlugin.h"
#import "OFObject.h"

@interface TestPlugin: OFPlugin
@interface TestPlugin: OFObject
- (int)test: (int)num;
@end

Modified tests/plugin/TestPlugin.m from [b5310ee637] to [5616dbe160].

40
41
42
43
44
45
46
47
48


49
50

51
40
41
42
43
44
45
46


47
48
49

50
51







-
-
+
+

-
+

@implementation TestPlugin
- (int)test: (int)num
{
	return num * 2;
}
@end

id
OFPluginInit(void)
Class
class(void)
{
	return [[[TestPlugin alloc] init] autorelease];
	return [TestPlugin class];
}

Modified tests/serialization.xml from [d106910237] to [ea3d1a36ad].

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
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&quot;la</OFString>
    </object>
    <key>
      <OFData>MDEyMzQ1Njc4OTo7PEFCQ0RFRkdISklLTE1OT1BRUlNUVVZXWFla</OFData>
    </key>
    <object>
      <OFString>data</OFString>
    </object>
    <key>
      <OFArray>
        <OFString>Qu&quot;xbar
test</OFString>
        <OFNumber type='signed'>1234</OFNumber>
        <OFNumber type='float'>40934a456d5cfaad</OFNumber>
        <OFMutableString>asd</OFMutableString>
        <OFDate>40934a456d5cfaad</OFDate>
      </OFArray>
    </key>
    <object>
      <OFString>Hello</OFString>
    </object>
    <key>
      <OFList>
        <OFString>Hello</OFString>
        <OFString>Wo&#xD;ld!
How are you?</OFString>
        <OFURL>https://objfw.nil.im/</OFURL>
        <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
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&quot;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
95

96
97
98
99

100
101

102
103

104
105

106
107

108
109

110
111
112
113
114
115
116
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: OFPointMake(5, 3)];
	[OFStdOut setCursorPosition: OFMakePoint(5, 3)];
	[OFStdOut writeString: @"Text at (5, 3)"];
	[OFThread sleepForTimeInterval: 2];

	[OFStdOut setRelativeCursorPosition: OFPointMake(-2, 0)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(-2, 0)];
	[OFThread sleepForTimeInterval: 2];
	[OFStdOut setRelativeCursorPosition: OFPointMake(2, 0)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(2, 0)];
	[OFThread sleepForTimeInterval: 2];
	[OFStdOut setRelativeCursorPosition: OFPointMake(0, -2)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(0, -2)];
	[OFThread sleepForTimeInterval: 2];
	[OFStdOut setRelativeCursorPosition: OFPointMake(0, 2)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(0, 2)];
	[OFThread sleepForTimeInterval: 2];
	[OFStdOut setRelativeCursorPosition: OFPointMake(1, 1)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(1, 1)];
	[OFThread sleepForTimeInterval: 2];
	[OFStdOut setRelativeCursorPosition: OFPointMake(-1, -1)];
	[OFStdOut setRelativeCursorPosition: OFMakePoint(-1, -1)];
	[OFThread sleepForTimeInterval: 2];

	[OFStdOut setCursorColumn: 2];
	[OFThread sleepForTimeInterval: 2];

	[OFStdOut reset];

Modified utils/Makefile from [521b7f89ce] to [d5d46e8aaf].

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
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


-
+
+









-
-
+
+









-
+







include ../extra.mk

SUBDIRS += ${OFARC}	\
SUBDIRS += ${OBJFW_NEW}	\
	   ${OFARC}	\
	   ${OFDNS}	\
	   ${OFHASH}	\
	   ${OFHTTP}	\
	   completions

include ../buildsys.mk

DISTCLEAN = objfw-config

install-extra: objfw-config objfw-compile objfw-new
	for i in objfw-config objfw-compile objfw-new; do \
install-extra: objfw-config objfw-compile objfw-embed
	for i in objfw-config objfw-compile objfw-embed; do \
		${INSTALL_STATUS}; \
		if ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \
			${INSTALL_OK}; \
		else \
			${INSTALL_FAILED}; \
		fi \
	done

uninstall-extra:
	for i in objfw-config objfw-compile objfw-new; do \
	for i in objfw-config objfw-compile objfw-embed; do \
		if test -f ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \
			if rm -f ${DESTDIR}${bindir}/${BIN_PREFIX}$$i; then \
				${DELETE_OK}; \
			else \
				${DELETE_FAILED}; \
			fi \
		fi \

Modified utils/objfw-compile from [3a536375c5] to [ffd05ad528].

296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
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 's/.*: //' | sed 's/\\//g')
			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"

Added utils/objfw-embed version [b832fbf4cf].



























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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#!/bin/sh
if test $# != 3; then
	echo "Usage: $0 source_file filename output.m" 1>&2
	exit 1
fi

exec 1>$3

cat <<EOF
#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));
}
EOF

Deleted utils/objfw-new version [6a6815b394].

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


























































-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#!/bin/sh

show_help() {
	echo "Usage: objfw-new app|class name"
	exit 1
}

already_exists() {
	echo "$1 already exists! Aborting..."
	exit 1
}

type="$1"
name="$2"

test -z "$name" && show_help

case "$1" in
app)
	test -f "$name.m" && already_exists "$name.m"

	cat >"$name.m" <<__EOF__
#import <ObjFW/ObjFW.h>

@interface $name: OFObject <OFApplicationDelegate>
@end

OF_APPLICATION_DELEGATE($name)

@implementation $name
- (void)applicationDidFinishLaunching
{
	[OFApplication terminate];
}
@end
__EOF__
	;;
class)
	test -f "$name.h" && already_exists "$name.h"
	test -f "$name.m" && already_exists "$name.m"

	cat >"$name.h" <<__EOF__
#import <ObjFW/ObjFW.h>

@interface $name: OFObject
@end
__EOF__
		cat >"$name.m" <<__EOF__
#import "$name.h"

@implementation $name
@end
__EOF__
	;;
*)
	show_help
	;;
esac

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
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
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 *mode = entry.mode;
	OFNumber *POSIXPermissions = entry.POSIXPermissions;

	if (mode == nil)
	if (POSIXPermissions == nil)
		return;

	mode = [OFNumber numberWithUnsignedShort:
	    mode.unsignedShortValue & 0777];
	POSIXPermissions = [OFNumber numberWithUnsignedShort:
	    POSIXPermissions.unsignedShortValue & 0777];

	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: mode
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
#endif
}

static void
setModificationDate(OFString *path, OFLHAArchiveEntry *entry)
{
	OFDate *modificationDate = entry.modificationDate;
	OFFileAttributes attributes;
	OFFileAttributes attributes = [OFDictionary

	if (modificationDate == nil) {
		/*
		 * Fall back to the original date if we have no modification
		 * date, as the modification date is a UNIX extension.
		 */
		modificationDate = entry.date;

		if (modificationDate == nil)
			return;
	}

	attributes = [OFDictionary
	    dictionaryWithObject: modificationDate
	    dictionaryWithObject: entry.modificationDate
			  forKey: OFFileModificationDate];
	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
}

@implementation LHAArchive
+ (void)initialize
130
131
132
133
134
135
136
137

138
139
140

141
142

143
144
145
146
147
148
149
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 *date = [entry.date
			OFString *modificationDate = [entry.modificationDate
			    localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"];
			OFString *compressedSize = [OFString stringWithFormat:
			    @"%" PRIu32, entry.compressedSize];
			    @"%llu", entry.compressedSize];
			OFString *uncompressedSize = [OFString stringWithFormat:
			    @"%" PRIu32, entry.uncompressedSize];
			    @"%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
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
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_date",
			    @"Date: %[date]",
			    @"date", date)];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_modification_date",
			    @"Modification date: %[date]",
			    @"date", modificationDate)];

			if (entry.mode != nil) {
				OFString *modeString = [OFString
				    stringWithFormat:
				    @"%ho", entry.mode.unsignedShortValue];
			if (entry.POSIXPermissions != nil) {
				OFString *permissionsString = [OFString
				    stringWithFormat: @"%llo",
				    entry.POSIXPermissions
				    .unsignedLongLongValue];

				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(@"list_mode",
				    @"Mode: %[mode]",
				    @"mode", modeString)];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_posix_permissions",
				    @"POSIX permissions: %[perm]",
				    @"perm", permissionsString)];
			}
			if (entry.UID != nil) {
			if (entry.ownerAccountID != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(@"list_uid",
				    @"UID: %[uid]",
				    @"uid", entry.UID)];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_owner_account_id",
				    @"Owner account ID: %[id]",
				    @"id", entry.ownerAccountID)];
			}
			if (entry.GID != nil) {
			if (entry.groupOwnerAccountID != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(@"list_gid",
				    @"GID: %[gid]",
				    @"gid", entry.GID)];
				    @"Group owner account ID: %[id]",
				    @"id", entry.groupOwnerAccountID)];
			}
			if (entry.owner != nil) {
			if (entry.ownerAccountName != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_owner",
				    @"Owner: %[owner]",
				    @"owner", entry.owner)];
				    @"list_owner_account_name",
				    @"Owner account name: %[name]",
				    @"name", entry.ownerAccountName)];
			}
			if (entry.group != nil) {
			if (entry.groupOwnerAccountName != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_group",
				    @"Group: %[group]",
				    @"group", entry.group)];
				    @"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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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 (entry.modificationDate != nil) {
					OFString *modificationDate =
					    entry.modificationDate.description;

					[OFStdOut writeString: @"\t"];
					[OFStdOut writeLine: OF_LOCALIZED(
					    @"list_modification_date",
					    @"Modification date: %[date]",
					    @"date", modificationDate)];
				}
			}

			if (app->_outputLevel >= 3) {
				OFString *extensions =
				    indent(entry.extensions.description);

				[OFStdOut writeString: @"\t"];
278
279
280
281
282
283
284
285

286
287
288
289
290
291
292
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;
		uint64_t written = 0, size = entry.uncompressedSize;
		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
471
472


473
474

475
476
477
478
479
480
481
482








483
484
485
486
487
488
489
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.mode = [OFNumber numberWithUnsignedLong:
		    attributes.filePOSIXPermissions];
		entry.POSIXPermissions =
		    [attributes objectForKey: OFFilePOSIXPermissions];
#endif
		entry.date = attributes.fileModificationDate;
		entry.modificationDate = attributes.fileModificationDate;

#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
		entry.UID = [OFNumber numberWithUnsignedLong:
		    attributes.fileOwnerAccountID];
		entry.GID = [OFNumber numberWithUnsignedLong:
		    attributes.fileGroupOwnerAccountID];
		entry.owner = attributes.fileOwnerAccountName;
		entry.group = attributes.fileGroupOwnerAccountName;
		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 [957c305108] to [482a60034a].

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
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 = lang/de.json		\
       lang/languages.json
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../..					\
	    -DLANGUAGE_DIR=\"${datadir}/ofarc/lang\"
CPPFLAGS += -I../../src							\
	    -I../../src/runtime						\
	    -I../../src/exceptions					\
	    -I../..							\
	    -DLOCALIZATION_DIR=\"${datadir}/ofarc/localization\"
LIBS := -L../../src -lobjfw						\
	-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
28

29
30
31
32
33
34
35
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 "OFURL.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
210

211

212

213
214
215
216
217
218
219
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 addLanguageDirectory: @LANGUAGE_DIR];
	[OFLocale addLocalizationDirectory: @LOCALIZATION_DIR];
#else
	[OFLocale addLocalizationDirectory:
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"];
	    @"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
340

341
342
343
344
345
346
347
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:
		    OFRangeMake(1, remainingArguments.count - 1)];
		    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
397

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412

413
414
415
416
417
418
419
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:
		    OFRangeMake(1, remainingArguments.count - 1)];
		    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:
		    OFRangeMake(1, remainingArguments.count - 1)];
		    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
464

465
466
467
468
469
470
471
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.URL.fileSystemRepresentation,
			    @"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
36


37
38

39
40
41
42
43
44
45
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 *mode = [OFNumber numberWithUnsignedShort: entry.mode & 0777];
	OFNumber *POSIXPermissions = [OFNumber numberWithUnsignedLongLong:
	    entry.POSIXPermissions.longLongValue & 0777];
	OFFileAttributes attributes = [OFDictionary
	    dictionaryWithObject: mode
	    dictionaryWithObject: POSIXPermissions
			  forKey: OFFilePOSIXPermissions];

	[[OFFileManager defaultManager] setAttributes: attributes
					 ofItemAtPath: path];
#endif
}

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
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:
			    @"%" PRIu64, entry.size];
			OFString *mode = [OFString stringWithFormat:
			    @"%06o", entry.mode];
			OFString *UID = [OFString stringWithFormat:
			    @"%llu", entry.uncompressedSize];
			OFString *permissionsString = [OFString
			    @"%u", entry.UID];
			OFString *GID = [OFString stringWithFormat:
			    @"%u", entry.GID];
			    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_mode",
			    @"Mode: %[mode]",
			[OFStdOut writeLine:
			    OF_LOCALIZED(@"list_posix_permissions",
			    @"POSIX permissions: %[perm]",
			    @"mode", mode)];
			    @"perm", permissionsString)];
			[OFStdOut writeString: @"\t"];
			[OFStdOut writeLine: OF_LOCALIZED(@"list_uid",
			    @"UID: %[uid]",
			    @"uid", UID)];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_owner_account_id",
			    @"Owner account ID: %[id]",
			    @"id", entry.ownerAccountID)];
			[OFStdOut writeString: @"\t"];
			[OFStdOut writeLine: OF_LOCALIZED(@"list_gid",
			    @"GID: %[gid]",
			    @"gid", GID)];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"list_group_owner_account_id",
			    @"Group owner account ID: %[id]",
			    @"id", entry.groupOwnerAccountID)];

			if (entry.owner != nil) {
			if (entry.ownerAccountName != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_owner",
				    @"Owner: %[owner]",
				    @"owner", entry.owner)];
				    @"list_owner_account_name",
				    @"Owner account name: %[name]",
				    @"name", entry.ownerAccountName)];
			}
			if (entry.group != nil) {
			if (entry.groupOwnerAccountName != nil) {
				[OFStdOut writeString: @"\t"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"list_group",
				    @"Group: %[group]",
				    @"group", entry.group)];
				    @"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
284

285
286
287
288
289
290
291
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;
		uint64_t written = 0, size = entry.size;
		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
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
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.mode = attributes.filePOSIXPermissions;
		entry.POSIXPermissions =
		    [attributes objectForKey: OFFilePOSIXPermissions];
#endif
		entry.size = attributes.fileSize;
		entry.uncompressedSize = attributes.fileSize;
		entry.modificationDate = attributes.fileModificationDate;

#ifdef OF_FILE_MANAGER_SUPPORTS_OWNER
		entry.UID = attributes.fileOwnerAccountID;
		entry.GID = attributes.fileGroupOwnerAccountID;
		entry.owner = attributes.fileOwnerAccountName;
		entry.group = attributes.fileGroupOwnerAccountName;
		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.size = 0;
			entry.uncompressedSize = 0;
		} else if ([type isEqual: OFFileTypeSymbolicLink]) {
			entry.type = OFTarArchiveEntryTypeSymlink;
			entry.targetFileName =
			    attributes.fileSymbolicLinkDestination;
			entry.size = 0;
			entry.uncompressedSize = 0;
		}

		[entry makeImmutable];

		output = [_archive streamForWritingEntry: entry];

		if (entry.type == OFTarArchiveEntryTypeFile) {
			uint64_t written = 0, size = entry.size;
			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
251

252
253
254
255
256
257
258
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;
		uint64_t written = 0, size = entry.uncompressedSize;
		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
442

443
444
445
446


447
448
449
450
451
452
453
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 > INT64_MAX)
		if (size < 0 || size > ULLONG_MAX)
			@throw [OFOutOfRangeException exception];

		entry.compressedSize = (int64_t)size;
		entry.uncompressedSize = (int64_t)size;
		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
78
79
80





81
82
83
84
85
86
87
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_mode": "Modus: %[mode]",
    "list_owner": "Besitzer: %[owner]",
    "list_group": "Gruppe: %[group]",
    "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
110
111
112
113
114
115
116
117
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_date": "Datum: %[date]",
    "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 [c6c2ac1b61] to [94aeff9904].

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18





19
20
21
22
23
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 = lang/de.json		\
       lang/languages.json
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../..					\
	    -DLANGUAGE_DIR=\"${datadir}/ofdns/lang\"
CPPFLAGS += -I../../src							\
	    -I../../src/runtime						\
	    -I../../src/exceptions					\
	    -I../..							\
	    -DLOCALIZATION_DIR=\"${datadir}/ofdns/localization\"
LIBS := -L../../src -lobjfw						\
	-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
102

103

104

105
106
107
108
109
110
111
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 addLanguageDirectory: @LANGUAGE_DIR];
	[OFLocale addLocalizationDirectory: @LOCALIZATION_DIR];
# else
	[OFLocale addLocalizationDirectory:
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofdns/lang"];
	    @"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 [4405db897f] to [41087b215e].

1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18





19
20
21
22
23
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 = lang/de.json		\
       lang/languages.json
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../..					\
	    -DLANGUAGE_DIR=\"${datadir}/ofhash/lang\"
CPPFLAGS += -I../../src							\
	    -I../../src/runtime						\
	    -I../../src/exceptions					\
	    -I../..							\
	    -DLOCALIZATION_DIR=\"${datadir}/ofhash/localization\"
LIBS := -L../../src -lobjfw						\
	-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
98

99

100

101
102
103
104
105
106
107
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 addLanguageDirectory: @LANGUAGE_DIR];
	[OFLocale addLocalizationDirectory: @LOCALIZATION_DIR];
#else
	[OFLocale addLocalizationDirectory:
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"];
	    @"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
137

138
139
140
141
142
143
144
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: @LANGUAGE_DIR 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 [a12779af52] to [a53c9301a9].

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
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 = ofhttp${PROG_SUFFIX}
SRCS = OFHTTP.m		\
       ProgressBar.m
DATA = lang/de.json		\
       lang/languages.json
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../..					\
	    -DLANGUAGE_DIR='"${datadir}/ofhttp/lang"'	\
	    -DLIB_PREFIX='"${LIB_PREFIX}"'		\
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/tls ${OFHTTP_LIBS} -lobjfw		\
	-L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS}	\
	${LIBS}
LD = ${OBJC}
LDFLAGS += ${LDFLAGS_RPATH}

Modified utils/ofhttp/OFHTTP.m from [622c13a414] to [2267fb0c48].

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
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 "OFURL.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 "OFInvalidServerReplyException.h"
#import "OFInvalidServerResponseException.h"
#import "OFOpenItemFailedException.h"
#import "OFOutOfRangeException.h"
#import "OFReadFailedException.h"
#import "OFResolveHostFailedException.h"
#import "OFRetrieveItemAttributesFailedException.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 *) *_URLs;
	size_t _URLIndex;
	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)downloadNextURL;
- (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] url1 [url2 ...]",
	    @"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
358

359
360
361
362
363
364
365
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 (OFRetrieveItemAttributesFailedException *e) {
		} @catch (OFGetItemAttributesFailedException *e) {
		}
	}

	if (contentLength == nil)
		[_clientHeaders setObject: @"chunked"
				   forKey: @"Transfer-Encoding"];
}
447
448
449
450
451
452
453
454

455

456

457
458
459
460
461
462
463
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 addLanguageDirectory: @LANGUAGE_DIR];
	[OFLocale addLocalizationDirectory: @LOCALIZATION_DIR];
#else
	[OFLocale addLocalizationDirectory:
	[OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"];
	    @"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
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
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







-
+

-
+



















-
+

-
-
+
+








+
+
+

+

-
+






+
-
+














-
-
-
-
-
+
+
+
+
+


















-
+

-
+













-
+












-
+


-
+


-
+



-
+







	[sandbox unveilPath: @"/etc/ssl" permissions: @"r"];

	sandbox.allowsUnveil = false;
	[OFApplication of_activateSandbox: sandbox];
#endif

	_outputPath = [outputPath copy];
	_URLs = [optionsParser.remainingArguments copy];
	_URIs = [optionsParser.remainingArguments copy];

	if (_URLs.count < 1)
	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 && _URLs.count > 1) {
	if (_outputPath != nil && _URIs.count > 1) {
		[OFStdErr writeLine:
		    OF_LOCALIZED(@"output_only_with_one_url",
		    @"%[prog]: Cannot use -o / --output when more than one URL "
		    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(downloadNextURL) afterDelay: 0];
	[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. */
	stream.verifiesCertificates = !_insecure;
	[stream setVerifiesCertificates: !_insecure];
}

-     (void)client: (OFHTTPClient *)client
  wantsRequestBody: (OFStream *)body
	   request: (OFHTTPRequest *)request
{
	/* TODO: Do asynchronously and print status */
	while (!_body.atEndOfStream) {
		char buffer[4096];
		size_t length = [_body readIntoBuffer: buffer length: 4096];
		[body writeBuffer: buffer length: length];
	}
}

-	  (bool)client: (OFHTTPClient *)client
  shouldFollowRedirect: (OFURL *)URL
	    statusCode: (short)statusCode
	       request: (OFHTTPRequest *)request
	      response: (OFHTTPResponse *)response
-	       (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: @"☇ %@", URL.string];
			[OFStdOut writeFormat: @"☇ %@", URI.string];
		else
			[OFStdOut writeFormat: @"< %@", URL.string];
			[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 *URL;
		OFString *URI;

		[_progressBar stop];
		[_progressBar draw];
		[_progressBar release];
		_progressBar = nil;

		if (!_quiet) {
			[OFStdOut writeString: @"\n  "];
			[OFStdOut writeLine: OF_LOCALIZED(@"download_error",
			    @"Error!")];
		}

		URL = [_URLs objectAtIndex: _URLIndex - 1];
		URI = [_URIs objectAtIndex: _URIIndex - 1];
		[OFStdErr writeLine: OF_LOCALIZED(
		    @"download_failed_exception",
		    @"%[prog]: Failed to download <%[url]>!\n"
		    @"%[prog]: Failed to download <%[uri]>!\n"
		    @"  %[exception]",
		    @"prog", [OFApplication programName],
		    @"url", URL,
		    @"uri", URI,
		    @"exception", exception)];

		_errorCode = 1;
		[self performSelector: @selector(downloadNextURL)
		[self performSelector: @selector(downloadNextURI)
			   afterDelay: 0];
		return false;
	}

	[_output writeBuffer: buffer length: length];

	_received += length;
683
684
685
686
687
688
689
690

691
692
693
694
695
696
697
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(downloadNextURL)
		[self performSelector: @selector(downloadNextURI)
			   afterDelay: 0];
		return false;
	}

	return true;
}

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
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 <%[url]>!\n"
			    @"%[prog]: Failed to download <%[uri]>!\n"
			    @"  Failed to resolve host: %[exception]",
			    @"prog", [OFApplication programName],
			    @"url", request.URL.string,
			    @"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 <%[url]>!\n"
			    @"%[prog]: Failed to download <%[uri]>!\n"
			    @"  Connection failed: %[exception]",
			    @"prog", [OFApplication programName],
			    @"url", request.URL.string,
			    @"uri", request.URI.string,
			    @"exception", exception)];
		} else if ([exception isKindOfClass:
		    [OFInvalidServerReplyException class]]) {
		    [OFInvalidServerResponseException class]]) {
			if (!_quiet)
				[OFStdOut writeString: @"\n"];

			[OFStdErr writeLine: OF_LOCALIZED(
			    @"download_failed_invalid_server_reply",
			    @"%[prog]: Failed to download <%[url]>!\n"
			    @"  Invalid server reply!",
			    @"download_failed_invalid_server_response",
			    @"%[prog]: Failed to download <%[uri]>!\n"
			    @"  Invalid server response!",
			    @"prog", [OFApplication programName],
			    @"url", request.URL.string)];
			    @"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"
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
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 <%[url]>!\n"
			    @"%[prog]: Failed to download <%[uri]>!\n"
			    @"  %[error]: %[exception]",
			    @"prog", [OFApplication programName],
			    @"url", request.URL.string,
			    @"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 <%[url]>!\n"
			    @"%[prog]: Failed to download <%[uri]>!\n"
			    @"  HTTP status code: %[code]",
			    @"prog", [OFApplication programName],
			    @"url", request.URL.string,
			    @"uri", request.URI.string,
			    @"code", codeString)];
		} else
			@throw exception;

		_errorCode = 1;
		[self performSelector: @selector(downloadNextURL)
		[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 URL on the next -[downloadNextURL] call */
		_URLIndex--;
		/* Handle this URI on the next -[downloadNextURI] call */
		_URIIndex--;

		[self performSelector: @selector(downloadNextURL)
		[self performSelector: @selector(downloadNextURI)
			   afterDelay: 0];
		return;
	}

	if ([_outputPath isEqual: @"-"])
		_output = [OFStdOut copy];
	else {
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
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(downloadNextURL) afterDelay: 0];
	[self performSelector: @selector(downloadNextURI) afterDelay: 0];
}

- (void)downloadNextURL
- (void)downloadNextURI
{
	OFString *URLString = nil;
	OFURL *URL;
	OFString *URIString = nil;
	OFURI *URI;
	OFMutableDictionary *clientHeaders;
	OFHTTPRequest *request;

	_received = _length = _resumedFrom = 0;

	if (_output != OFStdOut)
		[_output release];
	_output = nil;

	if (_URLIndex >= _URLs.count)
	if (_URIIndex >= _URIs.count)
		[OFApplication terminateWithStatus: _errorCode];

	@try {
		URLString = [_URLs objectAtIndex: _URLIndex++];
		URL = [OFURL URLWithString: URLString];
		URIString = [_URIs objectAtIndex: _URIIndex++];
		URI = [OFURI URIWithString: URIString];
	} @catch (OFInvalidFormatException *e) {
		[OFStdErr writeLine: OF_LOCALIZED(@"invalid_url",
		    @"%[prog]: Invalid URL: <%[url]>!",
		[OFStdErr writeLine: OF_LOCALIZED(@"invalid_uri",
		    @"%[prog]: Invalid URI: <%[uri]>!",
		    @"prog", [OFApplication programName],
		    @"url", URLString)];
		    @"uri", URIString)];

		_errorCode = 1;
		goto next;
	}

	if (![URL.scheme isEqual: @"http"] && ![URL.scheme isEqual: @"https"]) {
	if (![URI.scheme isEqual: @"http"] && ![URI.scheme isEqual: @"https"]) {
		[OFStdErr writeLine: OF_LOCALIZED(@"invalid_scheme",
		    @"%[prog]: Invalid scheme: <%[url]>!",
		    @"%[prog]: Invalid scheme: <%[uri]>!",
		    @"prog", [OFApplication programName],
		    @"url", URLString)];
		    @"uri", URIString)];

		_errorCode = 1;
		goto next;
	}

	clientHeaders = [[_clientHeaders mutableCopy] autorelease];

	if (_detectFileName && !_detectedFileName) {
		if (!_quiet) {
			if (_useUnicode)
				[OFStdOut writeFormat: @"⠒ %@", URL.string];
				[OFStdOut writeFormat: @"⠒ %@", URI.string];
			else
				[OFStdOut writeFormat: @"? %@", URL.string];
				[OFStdOut writeFormat: @"? %@", URI.string];
		}

		request = [OFHTTPRequest requestWithURL: URL];
		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 = [URL.path.lastPathComponent copy];
		_currentFileName = [URI.path.lastPathComponent copy];

	if ([_currentFileName isEqual: @"/"]) {
		[_currentFileName release];
		_currentFileName = nil;
	}

	if (_currentFileName == nil)
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
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 (OFRetrieveItemAttributesFailedException *e) {
		} @catch (OFGetItemAttributesFailedException *e) {
		}
	}

	if (!_quiet) {
		if (_useUnicode)
			[OFStdOut writeFormat: @"⇣ %@", URL.string];
			[OFStdOut writeFormat: @"⇣ %@", URI.string];
		else
			[OFStdOut writeFormat: @"< %@", URL.string];
			[OFStdOut writeFormat: @"< %@", URI.string];
	}

	request = [OFHTTPRequest requestWithURL: URL];
	request = [OFHTTPRequest requestWithURI: URI];
	request.headers = clientHeaders;
	request.method = _method;

	_detectFileNameRequest = false;
	[_HTTPClient asyncPerformRequest: request];
	return;

next:
	[self performSelector: @selector(downloadNextURL) afterDelay: 0];
	[self performSelector: @selector(downloadNextURI) afterDelay: 0];
}
@end

Renamed and modified utils/ofhttp/lang/de.json [027af9bd4c] to utils/ofhttp/localization/de.json [839a028930].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







{
    "usage": "Benutzung: %[prog] -[cehHmoOPqv] url1 [url2 ...]",
    "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
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
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_url": [
        "%[prog]: -o / --output kann nicht mit mehr als einer URL benutzt ",
    "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 <%[url]>!\n",
        "%[prog]: Fehler beim Download von <%[uri]>!\n",
        "  Host auflösen fehlgeschlagen: %[exception]"
    ],
    "download_failed_connection_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "%[prog]: Fehler beim Download von <%[uri]>!\n",
        "  Verbindung fehlgeschlagen: %[exception]"
    ],
    "download_failed_invalid_server_reply": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
    "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-",
        "  Um via HTTPS runterzuladen müssen Sie entweder ObjFW mit TLS-",
        "Unterstützung\n",
        "  kompilieren oder eine Bibliothek mittels „preoad” laden, welche ",
        "  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 <%[url]>!\n",
        "%[prog]: Fehler beim Download von <%[uri]>!\n",
        "  %[error]: %[exception]"
    ],
    "download_failed": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "%[prog]: Fehler beim Download von <%[uri]>!\n",
        "  HTTP Status-Code: %[code]"
    ],
    "download_error": "Fehler!",
    "download_failed_exception": [
        "%[prog]: Fehler beim Download von <%[url]>!\n",
        "%[prog]: Fehler beim Download von <%[uri]>!\n",
        "  %[exception]"
    ],
    "download_done": "Fertig!",
    "invalid_url": "%[prog]: Ungültige URL: <%[url]>!",
    "invalid_scheme": "%[prog]: Ungültiges Schema: <%[url]>!",
    "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.