14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
*/
#include "config.h"
#include <errno.h>
#import "OFArchiveURIHandler.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"
@implementation OFArchiveURIHandler
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
{
void *pool = objc_autoreleasePoolPush();
OFString *scheme = URI.scheme;
OFString *percentEncodedPath, *path;
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
*/
#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;
|
117
118
119
120
121
122
123
|
stream = [stream retain];
objc_autoreleasePoolPop(pool);
return [stream autorelease];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
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 URI];
void *pool = objc_autoreleasePoolPush();
OFString *archiveURIString;
OFOnce(&onceControl, initPathAllowedCharacters);
pathInArchive = [pathInArchive
stringByAddingPercentEncodingWithAllowedCharacters:
pathAllowedCharacters];
archiveURIString = [archiveURI.string
stringByAddingPercentEncodingWithAllowedCharacters:
pathAllowedCharacters];
ret.scheme = scheme;
ret.percentEncodedPath = [OFString
stringWithFormat: @"%@!%@", archiveURIString, pathInArchive];
[ret makeImmutable];
objc_autoreleasePoolPop(pool);
return ret;
}
|