@@ -22,13 +22,28 @@
- (void)_parseConfig: (OFXMLElement *)config;
- (void)_parseListens: (OFArray OF_GENERIC(OFXMLElement *) *)elements;
- (void)_parseModules: (OFArray OF_GENERIC(OFXMLElement *) *)elements;
- (void)_invalidConfig: (OFString *)message;
@end
+
+@implementation ListenConfig
+@synthesize host = _host, port = _port;
+@synthesize TLSCertificateFile = _TLSCertificateFile;
+@synthesize TLSKeyFile = _TLSKeyFile;
+
+- (void)dealloc
+{
+ [_host release];
+ [_TLSCertificateFile release];
+ [_TLSKeyFile release];
+
+ [super dealloc];
+}
+@end
@implementation ConfigParser
-@synthesize listenHosts = _listenHosts, modules = _modules;
+@synthesize listenConfigs = _listenConfigs, modules = _modules;
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
@@ -53,11 +68,11 @@
return self;
}
- (void)dealloc
{
- [_listenHosts release];
+ [_listenConfigs release];
[super dealloc];
}
- (void)_parseConfig: (OFXMLElement *)config
@@ -74,43 +89,63 @@
objc_autoreleasePoolPop(pool);
}
- (void)_parseListens: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
- OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFString *, OFNumber *) *)
- *listenHosts = [OFMutableArray array];
+ OFMutableArray OF_GENERIC(ListenConfig *) *listenConfigs =
+ [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];
- OFNumber *port;
+ 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];
+
@try {
- intmax_t tmp = [portString decimalValue];
- if (tmp < 0 || tmp > 65535)
+ intmax_t port = [portString decimalValue];
+ if (port < 0 || port > 65535)
@throw [OFInvalidFormatException exception];
- port = [OFNumber numberWithUInt16: (uint16_t)tmp];
+ [listenConfig setPort: port];
} @catch (OFInvalidFormatException *e) {
[self _invalidConfig: @" has invalid port"];
}
- [listenHosts addObject: [OFPair pairWithFirstObject: host
- secondObject: port]];
+ if (TLS != nil) {
+ OFString *certificateFile =
+ [[TLS attributeForName: @"cert"] stringValue];
+ OFString *keyFile =
+ [[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];
+ }
+
+ [listenConfigs addObject: listenConfig];
}
- [listenHosts makeImmutable];
- _listenHosts = [listenHosts copy];
+ [listenConfigs makeImmutable];
+ _listenConfigs = [listenConfigs copy];
}
- (void)_parseModules: (OFArray OF_GENERIC(OFXMLElement *) *)elements
{
OFMutableArray OF_GENERIC(OFXMLElement *) *modules =