From 613400a7189f6781ddeca8b6ba82ca0327a696d3 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sat, 19 Feb 2011 17:40:41 +0100 Subject: [PATCH] Use XMPPJID for from and to. --- src/XMPPStanza.h | 10 ++++++---- src/XMPPStanza.m | 28 ++++++++++++++-------------- tests/test.m | 13 +++++++------ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/XMPPStanza.h b/src/XMPPStanza.h index 978631d..a2ce9a2 100644 --- a/src/XMPPStanza.h +++ b/src/XMPPStanza.h @@ -23,23 +23,25 @@ #import +@class XMPPJID; + /** * \brief A class describing an XMPP Stanza. */ @interface XMPPStanza: OFXMLElement { /// The value of the stanza's from attribute - OFString *from; + XMPPJID *from; /// The value of the stanza's to attribute - OFString *to; + XMPPJID *to; /// The value of the stanza's type attribute OFString *type; /// The value of the stanza's id attribute OFString *ID; } -@property (copy) OFString *from; -@property (copy) OFString *to; +@property (copy) XMPPJID *from; +@property (copy) XMPPJID *to; @property (copy) OFString *type; @property (copy) OFString *ID; diff --git a/src/XMPPStanza.m b/src/XMPPStanza.m index c96fbe2..34243e1 100644 --- a/src/XMPPStanza.m +++ b/src/XMPPStanza.m @@ -22,6 +22,7 @@ */ #import "XMPPStanza.h" +#import "XMPPJID.h" @implementation XMPPStanza @synthesize from; @@ -118,14 +119,13 @@ namespace: elem.namespace]; @try { - OFXMLAttribute *attr; - OFXMLElement *el; - - for (attr in elem.attributes) { + for (OFXMLAttribute *attr in elem.attributes) { if ([attr.name isEqual: @"from"]) - [self setFrom: [attr stringValue]]; + [self setFrom: [XMPPJID JIDWithString: + [attr stringValue]]]; else if ([attr.name isEqual: @"to"]) - [self setTo: [attr stringValue]]; + [self setTo: [XMPPJID JIDWithString: + [attr stringValue]]]; else if ([attr.name isEqual: @"type"]) [self setType: [attr stringValue]]; else if ([attr.name isEqual: @"id"]) @@ -134,7 +134,7 @@ [self addAttribute: attr]; } - for (el in elem.children) + for (OFXMLElement *el in elem.children) [self addChild: el]; } @catch (id e) { [self release]; @@ -154,31 +154,31 @@ [super dealloc]; } -- (void)setFrom: (OFString*)from_ +- (void)setFrom: (XMPPJID*)from_ { - OFString* old = from; + XMPPJID *old = from; from = [from_ copy]; [old release]; [self removeAttributeForName: @"from"]; [self addAttributeWithName: @"from" - stringValue: from_]; + stringValue: from_.fullJID]; } -- (void)setTo: (OFString*)to_ +- (void)setTo: (XMPPJID*)to_ { - OFString* old = to; + XMPPJID *old = to; to = [to_ copy]; [old release]; [self removeAttributeForName: @"to"]; [self addAttributeWithName: @"to" - stringValue: to]; + stringValue: to_.fullJID]; } - (void)setType: (OFString*)type_ { - OFString* old = type; + OFString *old = type; type = [type_ copy]; [old release]; diff --git a/tests/test.m b/tests/test.m index 8ec56e8..d979a4d 100644 --- a/tests/test.m +++ b/tests/test.m @@ -26,6 +26,7 @@ #import #import "XMPPConnection.h" +#import "XMPPJID.h" #import "XMPPStanza.h" #import "XMPPIQ.h" #import "XMPPMessage.h" @@ -48,8 +49,8 @@ OF_APPLICATION_DELEGATE(AppDelegate) [pres addShow: @"chat"]; [pres addStatus: @"Bored"]; [pres addPriority: 20]; - pres.to = @"alice@example.com"; - pres.from = @"bob@example.org"; + pres.to = [XMPPJID JIDWithString: @"alice@example.com"]; + pres.from = [XMPPJID JIDWithString: @"bob@example.org"]; assert([[pres stringValue] isEqual: @"chat" @"Bored20" @@ -57,16 +58,16 @@ OF_APPLICATION_DELEGATE(AppDelegate) XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"]; [msg addBody: @"Hello everyone"]; - msg.to = @"jdev@conference.jabber.org"; - msg.from = @"alice@example.com"; + msg.to = [XMPPJID JIDWithString: @"jdev@conference.jabber.org"]; + msg.from = [XMPPJID JIDWithString: @"alice@example.com"]; assert([[msg stringValue] isEqual: @"Hello everyone" @""]); XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"]; - iq.to = @"juliet@capulet.lit"; - iq.from = @"romeo@montague.lit"; + iq.to = [XMPPJID JIDWithString: @"juliet@capulet.lit"]; + iq.from = [XMPPJID JIDWithString: @"romeo@montague.lit"]; assert([[iq stringValue] isEqual: @""]);