Overview
Context
Changes
Modified ConfigParser.m
from [46101b0094]
to [ddb184ed8d].
︙ | | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
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
|
+
+
+
+
-
+
+
+
|
}
- (instancetype)initWithConfigPath: (OFString *)configPath
{
self = [super init];
@try {
void *pool = objc_autoreleasePoolPush();
OFFile *configFile = [OFFile fileWithPath: configPath
mode: @"r"];
OFXMLElement *config = [[OFXMLElement alloc]
initWithFile: configPath];
initWithStream: configFile];
@try {
[self _parseConfig: config];
} @finally {
[config release];
}
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
|
︙ | | |
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
-
+
|
if (portString == nil)
[self _invalidConfig:
@"<listen/> is missing port attribute"];
listenConfig.host = host;
@try {
intmax_t port = portString.decimalValue;
long long port = portString.longLongValue;
if (port < 0 || port > 65535)
@throw [OFInvalidFormatException exception];
listenConfig.port = port;
} @catch (OFInvalidFormatException *e) {
[self _invalidConfig: @"<listen/> has invalid port"];
}
|
︙ | | |
165
166
167
168
169
170
171
172
173
174
175
|
171
172
173
174
175
176
177
178
179
180
181
|
-
+
|
[modules makeImmutable];
_modules = [modules copy];
}
- (void)_invalidConfig: (OFString *)message
{
[of_stderr writeFormat: @"Error parsing config: %@", message];
[OFStdErr writeFormat: @"Error parsing config: %@", message];
[OFApplication terminateWithStatus: 1];
}
@end
|
Modified ObjWebServer.m
from [2c2a999a6a]
to [031cb2e333].
︙ | | |
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
-
+
-
+
|
}
- (OFPlugin <Module> *)loadModuleAtPath: (OFString *)path
withConfig: (OFXMLElement *)config
{
OFPlugin <Module> *module;
of_log(@"Loading module at %@", path);
OFLog(@"Loading module at %@", path);
module = [OFPlugin pluginFromFile: path];
module = [OFPlugin pluginWithPath: path];
[module parseConfig: config];
return module;
}
- (void)startWebserverWithListenConfig: (ListenConfig *)listenConfig
{
|
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
server.certificateFile = listenConfig.TLSCertificateFile;
server.privateKeyFile = listenConfig.TLSKeyFile;
}
server.numberOfThreads = [OFSystemInfo numberOfCPUs] + 1;
server.delegate = self;
of_log(@"Starting server on host %@ port %" PRIu16,
OFLog(@"Starting server on host %@ port %" PRIu16,
listenConfig.host, listenConfig.port);
[server start];
}
- (void)server: (OFHTTPServer *)server
didReceiveRequest: (OFHTTPRequest *)request
requestBody: (OFStream *)requestBody
response: (OFHTTPResponse *)response
{
OFString *path = request.URL.path;
of_log(@"Request: %@", request);
OFLog(@"Request: %@", request);
for (OFPair OF_GENERIC(OFString *, id <Module>) *module in _modules)
if ([path hasPrefix: module.firstObject])
if ([module.secondObject handleRequest: request
requestBody: requestBody
response: response])
return;
}
- (bool)server: (OFHTTPServer *)server
didReceiveExceptionOnListeningSocket: (id)exception
{
of_log(@"Exception on listening socket: %@", exception);
OFLog(@"Exception on listening socket: %@", exception);
return true;
}
@end
|
Modified StaticModule.m
from [1eb8b41163]
to [110f6395ae].
︙ | | |
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
|
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
|
-
+
-
+
-
+
|
- (void)parseConfig: (OFXMLElement *)config
{
OFMutableDictionary OF_GENERIC(OFString *, OFString *) *MIMETypes;
_root = [[config elementForName: @"root"].stringValue copy];
if (_root == nil) {
[of_stderr writeString:
[OFStdErr writeString:
@"Error parsing config: No <root/> element!"];
[OFApplication terminateWithStatus: 1];
}
MIMETypes = [OFMutableDictionary dictionary];
for (OFXMLElement *MIMEType in [config elementsForName: @"mime-type"]) {
OFString *extension =
[MIMEType attributeForName: @"extension"].stringValue;
OFString *type =
[MIMEType attributeForName: @"type"].stringValue;
if (extension == nil) {
[of_stderr writeString:
[OFStdErr writeString:
@"Error parsing config: "
@"<mime-type/> has no extension attribute!"];
[OFApplication terminateWithStatus: 1];
}
if (type == nil) {
[of_stderr writeString:
[OFStdErr writeString:
@"Error parsing config: "
@"<mime-type/> has no type attribute!"];
[OFApplication terminateWithStatus: 1];
}
[MIMETypes setObject: type
forKey: extension];
|
︙ | | |
185
186
187
188
189
190
191
192
193
194
195
|
185
186
187
188
189
190
191
192
193
194
195
|
-
+
|
[response asyncWriteData: readData(fileSender->_file)];
return true;
}
@end
StaticModule *
init_plugin(void)
OFPluginInit(void)
{
return [[[StaticModule alloc] init] autorelease];
}
|