Index: ConfigParser.m ================================================================== --- ConfigParser.m +++ ConfigParser.m @@ -77,12 +77,11 @@ - (void)_parseConfig: (OFXMLElement *)config { 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"]]; [self _parseModules: [config elementsForName: @"module"]]; @@ -95,50 +94,50 @@ [OFMutableArray array]; 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) [self _invalidConfig: @" is missing host attribute"]; if (portString == nil) [self _invalidConfig: @" 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: @" 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: @" has no cert attribute"]; if (keyFile == nil) [self _invalidConfig: @" has no key attribute"]; - [listenConfig setTLSCertificateFile: certificateFile]; - [listenConfig setTLSKeyFile: keyFile]; + listenConfig.TLSCertificateFile = certificateFile; + listenConfig.TLSKeyFile = keyFile; } [listenConfigs addObject: listenConfig]; } @@ -150,14 +149,14 @@ { OFMutableArray OF_GENERIC(OFXMLElement *) *modules = [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: @" has no path attribute"]; Index: ObjWebServer.m ================================================================== --- ObjWebServer.m +++ ObjWebServer.m @@ -47,23 +47,23 @@ initWithConfigPath: @"ObjWebServer.xml"]; 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 = [self loadModuleAtPath: path withConfig: config]; [modules addObject: [OFPair pairWithFirstObject: prefix secondObject: module]]; } [modules makeImmutable]; _modules = [modules copy]; - for (ListenConfig *listenConfig in [_config listenConfigs]) + for (ListenConfig *listenConfig in _config.listenConfigs) [self startWebserverWithListenConfig: listenConfig]; } - (OFPlugin *)loadModuleAtPath: (OFString *)path withConfig: (OFXMLElement *)config @@ -79,43 +79,43 @@ } - (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 setNumberOfThreads: [OFSystemInfo numberOfCPUs] + 1]; - [server setDelegate: self]; - - of_log(@"Starting server on host %@ port %" PRIu16, - [listenConfig host], [listenConfig port]); + 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.numberOfThreads = [OFSystemInfo numberOfCPUs] + 1; + server.delegate = self; + + of_log(@"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]; + OFString *path = request.URL.path; of_log(@"Request: %@", request); for (OFPair OF_GENERIC(OFString *, id ) *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; } - (bool)server: (OFHTTPServer *)server didReceiveExceptionOnListeningSocket: (id)exception Index: StaticModule.m ================================================================== --- StaticModule.m +++ StaticModule.m @@ -69,16 +69,16 @@ [_response release]; [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); } @end @@ -93,23 +93,23 @@ - (void)parseConfig: (OFXMLElement *)config { 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 element!"]; [OFApplication terminateWithStatus: 1]; } 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: @"Error parsing config: " @" has no extension attribute!"]; @@ -131,20 +131,20 @@ - (bool)handleRequest: (OFHTTPRequest *)request 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: @".."]) return false; @@ -160,15 +160,15 @@ fileManager = [OFFileManager defaultManager]; if ([fileManager directoryExistsAtPath: path]) 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: @""]; if (MIMEType != nil) [headers setObject: MIMEType @@ -177,13 +177,13 @@ fileSender = [[[StaticModule_FileSender alloc] init] autorelease]; fileSender->_file = [[OFFile alloc] initWithPath: path 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; } @end