--- /dev/null
+<config xmlns="http://babelmonkeys.de/jubjub/config">
+ <domain>localhost</domain>
+ <!--<server>127.0.0.1</server>-->
+ <username>alice</username>
+ <password>test</password>
+</config>
--- /dev/null
+#import <ObjFW/ObjFW.h>
+
+#define CONFIG_NS @"http://babelmonkeys.de/jubjub/config"
+
+@interface JubConfig : OFObject <OFXMLElementBuilderDelegate>
+{
+ OFString *domain, *server;
+ OFString *username;
+ OFString *password;
+}
+@property (readonly) OFString *domain, *server;
+@property (readonly) OFString *username;
+@property (readonly) OFString *password;
+
+- initWithFile: (OFString*)file;
+@end
--- /dev/null
+#import "JubConfig.h"
+
+@implementation JubConfig
+@synthesize domain, server;
+@synthesize username;
+@synthesize password;
+
+- initWithFile: (OFString*)file
+{
+ self = [super init];
+
+ @try {
+ OFAutoreleasePool *pool = [OFAutoreleasePool new];
+ OFXMLParser *parser = [OFXMLParser parser];
+ OFXMLElementBuilder *builder =
+ [OFXMLElementBuilder elementBuilder];
+
+ parser.delegate = builder;
+ builder.delegate = self;
+
+ [parser parseFile: file];
+
+ [pool release];
+ } @catch (id e) {
+ [self release];
+ @throw e;
+ }
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [domain release];
+ [server release];
+ [username release];
+ [password release];
+
+ [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
STATIC_LIB_NOINST = core.a
-SRCS = main.m
+SRCS = main.m \
+ JubConfig.m
include ../../buildsys.mk
#import <ObjXMPP/ObjXMPP.h>
#import "JubGtkUI.h"
+#import "JubConfig.h"
@interface AppDelegate: OFObject
<OFApplicationDelegate, XMPPConnectionDelegate, XMPPRosterDelegate>
- (void)applicationDidFinishLaunching
{
id<XMPPRosterDelegate, XMPPConnectionDelegate> rosterDelegate;
+ JubConfig *config = [[JubConfig alloc] initWithFile: @"config.xml"];
connection = [[XMPPConnection alloc] init];
[connection addDelegate: self];
- connection.domain = @"localhost";
- connection.username = @"alice";
- connection.password = @"test";
+ connection.domain = config.domain;
+ connection.server = config.server;
+ connection.username = config.username;
+ connection.password = config.password;
ui = [[JubGtkUI alloc] initWithConnection: connection];
rosterDelegate = [ui rosterDelegate];