#import "JubConfig.h"

@implementation JubConfig
@synthesize domain, server;
@synthesize username;
@synthesize password;

- initWithFile: (OFString*)file
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [OFAutoreleasePool new];
		OFXMLElement *element = [OFXMLElement elementWithFile: file];

		if (![element.name isEqual: @"config"] ||
		    ![element.namespace isEqual: CONFIG_NS]) {
			// TODO: load default config
			[pool release];
			return self;
		}

		// TODO: Add error handling for missing elements
		of_log(@"Parsed file: %@", element);
		domain = [[[element
		    elementForName: @"domain"
			 namespace: CONFIG_NS] stringValue] copy];
		server = [[[element
		    elementForName: @"server"
			 namespace: CONFIG_NS] stringValue] copy];
		username = [[[element
		    elementForName: @"username"
			 namespace: CONFIG_NS] stringValue] copy];
		password = [[[element
		    elementForName: @"password"
			 namespace: CONFIG_NS] stringValue] copy];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[domain release];
	[server release];
	[username release];
	[password release];

	[super dealloc];
}
@end
