]> cgit.babelmonkeys.de Git - jubjub.git/blob - src/core/JubConfig.m
a3f11960ac064d6d5c9fdaf0e12511fa61575666
[jubjub.git] / src / core / JubConfig.m
1 #import "JubConfig.h"
2
3 @implementation JubConfig
4 @synthesize domain, server;
5 @synthesize username;
6 @synthesize password;
7
8 - initWithFile: (OFString*)file
9 {
10         self = [super init];
11
12         @try {
13                 OFAutoreleasePool *pool = [OFAutoreleasePool new];
14                 OFXMLElement *element = [OFXMLElement elementWithFile: file];
15
16                 if (![element.name isEqual: @"config"] ||
17                     ![element.namespace isEqual: CONFIG_NS]) {
18                         // TODO: load default config
19                         [pool release];
20                         return self;
21                 }
22
23                 // TODO: Add error handling for missing elements
24                 of_log(@"Parsed file: %@", element);
25                 domain = [[[element
26                     elementForName: @"domain"
27                          namespace: CONFIG_NS] stringValue] copy];
28                 server = [[[element
29                     elementForName: @"server"
30                          namespace: CONFIG_NS] stringValue] copy];
31                 username = [[[element
32                     elementForName: @"username"
33                          namespace: CONFIG_NS] stringValue] copy];
34                 password = [[[element
35                     elementForName: @"password"
36                          namespace: CONFIG_NS] stringValue] copy];
37
38                 [pool release];
39         } @catch (id e) {
40                 [self release];
41                 @throw e;
42         }
43
44         return self;
45 }
46
47 - (void)dealloc
48 {
49         [domain release];
50         [server release];
51         [username release];
52         [password release];
53
54         [super dealloc];
55 }
56 @end