summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-03-17 04:32:00 +0100
committerJonathan Schleifer <js@heap.zone>2019-03-17 04:32:00 +0100
commita7c5e7c1f51d753462519bce6f93380ca1831f73 (patch)
treeab7568359f3e804a650886bb65f6193f475a436e
parent609dacb6b006fd70f3b1af32e85d942db683221a (diff)
Use dot syntax
-rw-r--r--ConfigParser.m33
-rw-r--r--ObjWebServer.m38
-rw-r--r--StaticModule.m28
3 files changed, 49 insertions, 50 deletions
diff --git a/ConfigParser.m b/ConfigParser.m
index 53346ad..93595fc 100644
--- a/ConfigParser.m
+++ b/ConfigParser.m
@@ -79,8 +79,7 @@
{
void *pool = objc_autoreleasePoolPush();
- if ([config namespace] != nil ||
- ![[config name] isEqual: @"ObjWebServer"])
+ if (config.namespace != nil || ![config.name isEqual: @"ObjWebServer"])
[self _invalidConfig: @"Root element is not ObjWebServer"];
[self _parseListens: [config elementsForName: @"listen"]];
@@ -97,10 +96,10 @@
for (OFXMLElement *element in elements) {
ListenConfig *listenConfig =
[[[ListenConfig alloc] init] autorelease];
- OFString *host = [[element
- attributeForName: @"host"] stringValue];
- OFString *portString = [[element
- attributeForName: @"port"] stringValue];
+ OFString *host =
+ [element attributeForName: @"host"].stringValue;
+ OFString *portString =
+ [element attributeForName: @"port"].stringValue;
OFXMLElement *TLS = [element elementForName: @"tls"];
if (host == nil)
@@ -110,23 +109,23 @@
[self _invalidConfig:
@"<listen/> is missing port attribute"];
- [listenConfig setHost: host];
+ listenConfig.host = host;
@try {
- intmax_t port = [portString decimalValue];
+ intmax_t port = portString.decimalValue;
if (port < 0 || port > 65535)
@throw [OFInvalidFormatException exception];
- [listenConfig setPort: port];
+ listenConfig.port = port;
} @catch (OFInvalidFormatException *e) {
[self _invalidConfig: @"<listen/> has invalid port"];
}
if (TLS != nil) {
OFString *certificateFile =
- [[TLS attributeForName: @"cert"] stringValue];
+ [TLS attributeForName: @"cert"].stringValue;
OFString *keyFile =
- [[TLS attributeForName: @"key"] stringValue];
+ [TLS attributeForName: @"key"].stringValue;
if (certificateFile == nil)
[self _invalidConfig:
@@ -135,8 +134,8 @@
[self _invalidConfig:
@"<tls/> has no key attribute"];
- [listenConfig setTLSCertificateFile: certificateFile];
- [listenConfig setTLSKeyFile: keyFile];
+ listenConfig.TLSCertificateFile = certificateFile;
+ listenConfig.TLSKeyFile = keyFile;
}
[listenConfigs addObject: listenConfig];
@@ -152,10 +151,10 @@
[OFMutableArray array];
for (OFXMLElement *element in elements) {
- OFString *path = [[element
- attributeForName: @"path"] stringValue];
- OFString *prefix = [[element
- attributeForName: @"prefix"] stringValue];
+ OFString *path =
+ [element attributeForName: @"path"].stringValue;
+ OFString *prefix =
+ [element attributeForName: @"prefix"].stringValue;
if (path == nil || prefix == nil)
[self _invalidConfig:
diff --git a/ObjWebServer.m b/ObjWebServer.m
index 9bad080..4492054 100644
--- a/ObjWebServer.m
+++ b/ObjWebServer.m
@@ -49,9 +49,9 @@ OF_APPLICATION_DELEGATE(ObjWebServer)
modules = [OFMutableArray array];
for (OFXMLElement *config in [_config modules]) {
OFString *path =
- [[config attributeForName: @"path"] stringValue];
+ [config attributeForName: @"path"].stringValue;
OFString *prefix =
- [[config attributeForName: @"prefix"] stringValue];
+ [config attributeForName: @"prefix"].stringValue;
OFPlugin <Module> *module = [self loadModuleAtPath: path
withConfig: config];
@@ -61,7 +61,7 @@ OF_APPLICATION_DELEGATE(ObjWebServer)
[modules makeImmutable];
_modules = [modules copy];
- for (ListenConfig *listenConfig in [_config listenConfigs])
+ for (ListenConfig *listenConfig in _config.listenConfigs)
[self startWebserverWithListenConfig: listenConfig];
}
@@ -81,21 +81,21 @@ OF_APPLICATION_DELEGATE(ObjWebServer)
- (void)startWebserverWithListenConfig: (ListenConfig *)listenConfig
{
OFHTTPServer *server = [OFHTTPServer server];
- [server setHost: [listenConfig host]];
- [server setPort: [listenConfig port]];
-
- if ([listenConfig TLSCertificateFile] != nil &&
- [listenConfig TLSKeyFile] != nil) {
- [server setUsesTLS: true];
- [server setCertificateFile: [listenConfig TLSCertificateFile]];
- [server setPrivateKeyFile: [listenConfig TLSKeyFile]];
+ server.host = listenConfig.host;
+ server.port = listenConfig.port;
+
+ if (listenConfig.TLSCertificateFile != nil &&
+ listenConfig.TLSKeyFile != nil) {
+ server.usesTLS = true;
+ server.certificateFile = listenConfig.TLSCertificateFile;
+ server.privateKeyFile = listenConfig.TLSKeyFile;
}
- [server setNumberOfThreads: [OFSystemInfo numberOfCPUs] + 1];
- [server setDelegate: self];
+ server.numberOfThreads = [OFSystemInfo numberOfCPUs] + 1;
+ server.delegate = self;
of_log(@"Starting server on host %@ port %" PRIu16,
- [listenConfig host], [listenConfig port]);
+ listenConfig.host, listenConfig.port);
[server start];
}
@@ -105,15 +105,15 @@ OF_APPLICATION_DELEGATE(ObjWebServer)
requestBody: (OFStream *)requestBody
response: (OFHTTPResponse *)response
{
- OFString *path = [[request URL] path];
+ OFString *path = request.URL.path;
of_log(@"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])
+ if ([path hasPrefix: module.firstObject])
+ if ([module.secondObject handleRequest: request
+ requestBody: requestBody
+ response: response])
return;
}
diff --git a/StaticModule.m b/StaticModule.m
index fbe58aa..067781f 100644
--- a/StaticModule.m
+++ b/StaticModule.m
@@ -71,12 +71,12 @@ readData(OFStream *stream)
[super dealloc];
}
-- (OFData *)stream: (OF_KINDOF(OFStream *))stream
+- (OFData *)stream: (OFStream *)stream
didWriteData: (OFData *)data
bytesWritten: (size_t)bytesWritten
exception: (id)exception
{
- if (exception != nil || [_file isAtEndOfStream])
+ if (exception != nil || _file.atEndOfStream)
return nil;
return readData(_file);
@@ -95,7 +95,7 @@ readData(OFStream *stream)
{
OFMutableDictionary OF_GENERIC(OFString *, OFString *) *MIMETypes;
- _root = [[[config elementForName: @"root"] stringValue] copy];
+ _root = [[config elementForName: @"root"].stringValue copy];
if (_root == nil) {
[of_stderr writeString:
@"Error parsing config: No <root/> element!"];
@@ -105,9 +105,9 @@ readData(OFStream *stream)
MIMETypes = [OFMutableDictionary dictionary];
for (OFXMLElement *MIMEType in [config elementsForName: @"mime-type"]) {
OFString *extension =
- [[MIMEType attributeForName: @"extension"] stringValue];
+ [MIMEType attributeForName: @"extension"].stringValue;
OFString *type =
- [[MIMEType attributeForName: @"type"] stringValue];
+ [MIMEType attributeForName: @"type"].stringValue;
if (extension == nil) {
[of_stderr writeString:
@@ -133,16 +133,16 @@ readData(OFStream *stream)
requestBody: (OFStream *)requestBody
response: (OFHTTPResponse *)response
{
- OFURL *URL = [[request URL] URLByStandardizingPath];
- OFString *path = [URL path];
+ OFURL *URL = request.URL.URLByStandardizingPath;
+ OFString *path = URL.path;
OFMutableDictionary *headers = [OFMutableDictionary dictionary];
OFFileManager *fileManager;
bool firstComponent = true;
OFString *MIMEType;
StaticModule_FileSender *fileSender;
- for (OFString *component in [URL pathComponents]) {
- if (firstComponent && [component length] != 0)
+ for (OFString *component in URL.pathComponents) {
+ if (firstComponent && component.length != 0)
return false;
if ([component isEqual: @"."] || [component isEqual: @".."])
@@ -162,11 +162,11 @@ readData(OFStream *stream)
path = [path stringByAppendingPathComponent: @"index.html"];
if (![fileManager fileExistsAtPath: path]) {
- [response setStatusCode: 404];
+ response.statusCode = 404;
return false;
}
- MIMEType = [_MIMETypes objectForKey: [path pathExtension]];
+ MIMEType = [_MIMETypes objectForKey: path.pathExtension];
if (MIMEType == nil)
MIMEType = [_MIMETypes objectForKey: @""];
@@ -179,9 +179,9 @@ readData(OFStream *stream)
mode: @"r"];
fileSender->_response = [response retain];
- [response setStatusCode: 200];
- [response setHeaders: headers];
- [response setDelegate: fileSender];
+ response.statusCode = 200;
+ response.headers = headers;
+ response.delegate = fileSender;
[response asyncWriteData: readData(fileSender->_file)];
return true;