Index: src/XMPPStanza.h ================================================================== --- src/XMPPStanza.h +++ src/XMPPStanza.h @@ -21,27 +21,29 @@ * POSSIBILITY OF SUCH DAMAGE. */ #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; /** * Creates a new autoreleased XMPPStanza with the specified name. Index: src/XMPPStanza.m ================================================================== --- src/XMPPStanza.m +++ src/XMPPStanza.m @@ -20,10 +20,11 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #import "XMPPStanza.h" +#import "XMPPJID.h" @implementation XMPPStanza @synthesize from; @synthesize to; @synthesize type; @@ -116,27 +117,26 @@ { self = [super initWithName: elem.name 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"]) [self setID: [attr stringValue]]; else [self addAttribute: attr]; } - for (el in elem.children) + for (OFXMLElement *el in elem.children) [self addChild: el]; } @catch (id e) { [self release]; @throw e; } @@ -152,35 +152,35 @@ [ID release]; [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]; [self removeAttributeForName: @"type"]; [self addAttributeWithName: @"type" Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -24,10 +24,11 @@ #include #import #import "XMPPConnection.h" +#import "XMPPJID.h" #import "XMPPStanza.h" #import "XMPPIQ.h" #import "XMPPMessage.h" #import "XMPPPresence.h" @@ -46,29 +47,29 @@ XMPPPresence *pres = [XMPPPresence presence]; [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" @""]); 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: @""]); OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"];