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
|
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
|
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
-
-
-
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "OFURIHandler.h"
#import "OFIRIHandler.h"
#import "OFDictionary.h"
#import "OFNumber.h"
#import "OFURI.h"
#import "OFIRI.h"
#import "OFNumber.h"
#ifdef OF_HAVE_THREADS
# import "OFMutex.h"
#endif
#import "OFArchiveURIHandler.h"
#import "OFEmbeddedURIHandler.h"
#import "OFArchiveIRIHandler.h"
#import "OFEmbeddedIRIHandler.h"
#ifdef OF_HAVE_FILES
# import "OFFileURIHandler.h"
# import "OFFileIRIHandler.h"
#endif
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
# import "OFHTTPURIHandler.h"
# import "OFHTTPIRIHandler.h"
#endif
#import "OFUnsupportedProtocolException.h"
static OFMutableDictionary OF_GENERIC(OFString *, OFURIHandler *) *handlers;
static OFMutableDictionary OF_GENERIC(OFString *, OFIRIHandler *) *handlers;
#ifdef OF_HAVE_THREADS
static OFMutex *mutex;
static void
releaseMutex(void)
{
[mutex release];
}
#endif
@implementation OFURIHandler
@implementation OFIRIHandler
@synthesize scheme = _scheme;
+ (void)initialize
{
if (self != [OFURIHandler class])
if (self != [OFIRIHandler class])
return;
handlers = [[OFMutableDictionary alloc] init];
#ifdef OF_HAVE_THREADS
mutex = [[OFMutex alloc] init];
atexit(releaseMutex);
#endif
[self registerClass: [OFEmbeddedURIHandler class]
[self registerClass: [OFEmbeddedIRIHandler class]
forScheme: @"embedded"];
#ifdef OF_HAVE_FILES
[self registerClass: [OFFileURIHandler class] forScheme: @"file"];
[self registerClass: [OFFileIRIHandler class] forScheme: @"file"];
#endif
#if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS)
[self registerClass: [OFHTTPURIHandler class] forScheme: @"http"];
[self registerClass: [OFHTTPURIHandler class] forScheme: @"https"];
[self registerClass: [OFHTTPIRIHandler class] forScheme: @"http"];
[self registerClass: [OFHTTPIRIHandler 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"];
[self registerClass: [OFArchiveIRIHandler class] forScheme: @"gzip"];
[self registerClass: [OFArchiveIRIHandler class] forScheme: @"lha"];
[self registerClass: [OFArchiveIRIHandler class] forScheme: @"tar"];
[self registerClass: [OFArchiveIRIHandler class] forScheme: @"zip"];
}
+ (bool)registerClass: (Class)class forScheme: (OFString *)scheme
{
#ifdef OF_HAVE_THREADS
[mutex lock];
@try {
#endif
OFURIHandler *handler;
OFIRIHandler *handler;
if ([handlers objectForKey: scheme] != nil)
return false;
handler = [[class alloc] initWithScheme: scheme];
@try {
[handlers setObject: handler forKey: scheme];
} @finally {
[handler release];
}
#ifdef OF_HAVE_THREADS
} @finally {
[mutex unlock];
}
#endif
return true;
}
+ (OFURIHandler *)handlerForURI: (OFURI *)URI
+ (OFIRIHandler *)handlerForIRI: (OFIRI *)IRI
{
OF_KINDOF(OFURIHandler *) handler;
OF_KINDOF(OFIRIHandler *) handler;
#ifdef OF_HAVE_THREADS
[mutex lock];
@try {
#endif
handler = [handlers objectForKey: URI.scheme];
handler = [handlers objectForKey: IRI.scheme];
#ifdef OF_HAVE_THREADS
} @finally {
[mutex unlock];
}
#endif
if (handler == nil)
@throw [OFUnsupportedProtocolException exceptionWithURI: URI];
@throw [OFUnsupportedProtocolException exceptionWithIRI: IRI];
return handler;
}
+ (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
+ (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode
{
return [[self handlerForURI: URI] openItemAtURI: URI mode: mode];
return [[self handlerForIRI: IRI] openItemAtIRI: IRI mode: mode];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
|
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
|
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
|
- (void)dealloc
{
[_scheme release];
[super dealloc];
}
- (OFStream *)openItemAtURI: (OFURI *)URI mode: (OFString *)mode
- (OFStream *)openItemAtIRI: (OFIRI *)IRI mode: (OFString *)mode
{
OF_UNRECOGNIZED_SELECTOR
}
- (OFFileAttributes)attributesOfItemAtURI: (OFURI *)URI
- (OFFileAttributes)attributesOfItemAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtURI: (OFURI *)URI
- (void)setAttributes: (OFFileAttributes)attributes ofItemAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (bool)fileExistsAtURI: (OFURI *)URI
- (bool)fileExistsAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (bool)directoryExistsAtURI: (OFURI *)URI
- (bool)directoryExistsAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)createDirectoryAtURI: (OFURI *)URI
- (void)createDirectoryAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (OFArray OF_GENERIC(OFURI *) *)contentsOfDirectoryAtURI: (OFURI *)URI
- (OFArray OF_GENERIC(OFIRI *) *)contentsOfDirectoryAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)removeItemAtURI: (OFURI *)URI
- (void)removeItemAtIRI: (OFIRI *)IRI
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)linkItemAtURI: (OFURI *)source toURI: (OFURI *)destination
- (void)linkItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)createSymbolicLinkAtURI: (OFURI *)destination
- (void)createSymbolicLinkAtIRI: (OFIRI *)destination
withDestinationPath: (OFString *)source
{
OF_UNRECOGNIZED_SELECTOR
}
- (bool)copyItemAtURI: (OFURI *)source toURI: (OFURI *)destination
- (bool)copyItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination
{
return false;
}
- (bool)moveItemAtURI: (OFURI *)source toURI: (OFURI *)destination
- (bool)moveItemAtIRI: (OFIRI *)source toIRI: (OFIRI *)destination
{
return false;
}
@end
|