From: Jonathan Schleifer Date: Fri, 15 Feb 2013 12:10:13 +0000 (+0100) Subject: Improve config parsing. X-Git-Url: https://cgit.babelmonkeys.de/?a=commitdiff_plain;h=f2af67c5eefd2239f7c3cc7688896bd3258bb7ec;p=jubjub.git Improve config parsing. --- diff --git a/src/core/JubConfig.h b/src/core/JubConfig.h index 00173fa..8e8e6ae 100644 --- a/src/core/JubConfig.h +++ b/src/core/JubConfig.h @@ -2,7 +2,7 @@ #define CONFIG_NS @"http://babelmonkeys.de/jubjub/config" -@interface JubConfig : OFObject +@interface JubConfig : OFObject { OFString *domain, *server; OFString *username; diff --git a/src/core/JubConfig.m b/src/core/JubConfig.m index 33fe2c5..a3f1196 100644 --- a/src/core/JubConfig.m +++ b/src/core/JubConfig.m @@ -11,14 +11,29 @@ @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) { @@ -38,19 +53,4 @@ [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