From f2af67c5eefd2239f7c3cc7688896bd3258bb7ec Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Fri, 15 Feb 2013 13:10:13 +0100 Subject: [PATCH] Improve config parsing. --- src/core/JubConfig.h | 2 +- src/core/JubConfig.m | 46 ++++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 24 deletions(-) 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 -- 2.39.5