]> git.babelmonkeys.de Git - jubjub.git/commitdiff
Improve config parsing.
authorJonathan Schleifer <js@webkeks.org>
Fri, 15 Feb 2013 12:10:13 +0000 (13:10 +0100)
committerFlorian Zeitz <florob@babelmonkeys.de>
Sat, 16 Feb 2013 12:04:06 +0000 (13:04 +0100)
src/core/JubConfig.h
src/core/JubConfig.m

index 00173fa56a03f92da5d4b7c63eae54f3d115ddca..8e8e6ae86b2720812ffe2cbb35eacc7b476eaa2b 100644 (file)
@@ -2,7 +2,7 @@
 
 #define CONFIG_NS @"http://babelmonkeys.de/jubjub/config"
 
-@interface JubConfig : OFObject <OFXMLElementBuilderDelegate>
+@interface JubConfig : OFObject
 {
        OFString *domain, *server;
        OFString *username;
index 33fe2c5d82f33ac3a6f84e1681c31304291b3f9c..a3f11960ac064d6d5c9fdaf0e12511fa61575666 100644 (file)
 
        @try {
                OFAutoreleasePool *pool = [OFAutoreleasePool new];
-               OFXMLParser *parser = [OFXMLParser parser];
-               OFXMLElementBuilder *builder =
-                   [OFXMLElementBuilder elementBuilder];
-
-               parser.delegate = builder;
-               builder.delegate = self;
-
-               [parser parseFile: file];
+               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) {
 
        [super dealloc];
 }
-
-- (void)elementBuilder: (OFXMLElementBuilder*)builder
-       didBuildElement: (OFXMLElement*)element
-{
-       // TODO: At 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];
-}
 @end