Index: src/XMPPConnection.h ================================================================== --- src/XMPPConnection.h +++ src/XMPPConnection.h @@ -1,10 +1,9 @@ #import -#import "XMPPJID.h" - @class XMPPConnection; +@class XMPPJID; @class XMPPIQ; @class XMPPMessage; @class XMPPPresence; @protocol XMPPConnectionDelegate @@ -16,77 +15,56 @@ - (void)connection: (XMPPConnection*)conn didReceiveMessage: (XMPPMessage*)msg; @end /** - * \brief A class that abstracts a connection to an XMPP service + * \brief A class which abstracts a connection to an XMPP service. */ @interface XMPPConnection: OFObject { OFTCPSocket *sock; OFXMLParser *parser; OFXMLElementBuilder *elementBuilder; - - /** - * The username to connect with - */ + /// The username to connect with OFString *username; - - /** - * The password to connect with - */ + /// The password to connect with OFString *password; - - /** - * The server to connect to - */ + /// The server to connect to OFString *server; - - /** - * The resource to connect with - */ + /// The resource to connect with OFString *resource; - - /** - * The JID bound to this connection (this is determined by the server) - */ + /// The JID bound to this connection (this is determined by the server) XMPPJID *JID; - - /** - * The port to connect to - */ + /// The port to connect to short port; - - /** - * Whether to use TLS - */ + /// Whether to use TLS BOOL useTLS; id delegate; OFMutableArray *mechanisms; } @property (copy) OFString *username; @property (copy) OFString *password; @property (copy) OFString *server; @property (copy) OFString *resource; -@property (readonly) XMPPJID *JID; +@property (copy, readonly) XMPPJID *JID; @property (assign) short port; @property (assign) BOOL useTLS; @property (retain) id delegate; /** - * Connects to the XMPP service + * Connects to the XMPP service. */ - (void)connect; /** - * Starts a loop handling incomming data + * Starts a loop handling incomming data. */ - (void)handleConnection; /** - * Sends a OFXMLElement (usually a XMPPStanza) + * Sends an OFXMLElement, usually an XMPPStanza. * * \param elem The element to send */ - (void)sendStanza: (OFXMLElement*)elem; @end Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -2,10 +2,11 @@ #include #import "XMPPConnection.h" #import "XMPPStanza.h" +#import "XMPPJID.h" #import "XMPPIQ.h" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_CLIENT @"jabber:client" #define NS_SASL @"urn:ietf:params:xml:ns:xmpp-sasl" @@ -53,12 +54,12 @@ { OFString *old = username; char *node; Stringprep_rc rc; - if ((rc = stringprep_profile([username_ cString], &node, "SASLprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([username_ cString], &node, + "SASLprep", 0)) != STRINGPREP_OK) { of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -74,12 +75,12 @@ { OFString *old = resource; char *res; Stringprep_rc rc; - if ((rc = stringprep_profile([resource_ cString], &res, "Resourceprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([resource_ cString], &res, + "Resourceprep", 0)) != STRINGPREP_OK) { of_log(@"Resourceprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -95,12 +96,12 @@ { OFString *old = server; char *srv; Stringprep_rc rc; - if ((rc = stringprep_profile([server_ cString], &srv, "Nameprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([server_ cString], &srv, + "Nameprep", 0)) != STRINGPREP_OK) { of_log(@"Nameprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -116,12 +117,12 @@ { OFString *old = password; char *pass; Stringprep_rc rc; - if ((rc = stringprep_profile([password_ cString], &pass, "SASLprep", 0)) - != STRINGPREP_OK) { + if ((rc = stringprep_profile([password_ cString], &pass, + "SASLprep", 0)) != STRINGPREP_OK) { of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -143,11 +144,12 @@ - (void)connect { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - [sock connectToHost: server onPort: port]; + [sock connectToHost: server + onPort: port]; [self _startStream]; [pool release]; } @@ -179,17 +181,22 @@ withPrefix: (OFString*)prefix namespace: (OFString*)ns attributes: (OFArray*)attrs { if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || - ![ns isEqual: NS_STREAM]) + ![ns isEqual: NS_STREAM]) { of_log(@"Did not get expected stream start!"); + assert(0); + } - for (OFXMLAttribute *attr in attrs) + for (OFXMLAttribute *attr in attrs) { if ([attr.name isEqual: @"from"] && - ![attr.stringValue isEqual: server]) + ![attr.stringValue isEqual: server]) { of_log(@"Got invalid from in stream start!"); + assert(0); + } + } parser.delegate = elementBuilder; } - (void)_addAuthMechanisms: (OFXMLElement*)mechanisms_ @@ -242,15 +249,16 @@ } - (void)_handleResourceBind: (XMPPIQ*)iq { OFXMLElement *bindElem = iq.children.firstObject; + if ([bindElem.name isEqual: @"bind"] && [bindElem.namespace isEqual: NS_BIND]) { OFXMLElement *jidElem = bindElem.children.firstObject; JID = [[XMPPJID alloc] initWithString: - [jidElem.children.firstObject stringValue]]; + [jidElem.children.firstObject stringValue]]; of_log(@"Bound to JID: %@", [JID fullJID]); } } - (void)_handleFeatures: (OFXMLElement*)elem @@ -300,13 +308,14 @@ } if ([elem.name isEqual: @"iq"] && [elem.namespace isEqual: NS_CLIENT]) { XMPPIQ *iq = [XMPPIQ stanzaWithElement: elem]; - if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) { + + // FIXME: More checking! + if ([iq.ID isEqual: @"bind0"] && [iq.type isEqual: @"result"]) [self _handleResourceBind: iq]; - } } } - (void)elementBuilder: (OFXMLElementBuilder*)b didNotExpectCloseTag: (OFString*)name Index: src/XMPPIQ.h ================================================================== --- src/XMPPIQ.h +++ src/XMPPIQ.h @@ -1,26 +1,26 @@ #import "XMPPStanza.h" /** - * \brief A class describing a IQ stanza + * \brief A class describing an IQ stanza. */ @interface XMPPIQ: XMPPStanza /** - * Creates a new XMPPIQ with a certain type and id + * Creates a new XMPPIQ with the specified type and id. * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPIQ */ + IQWithType: (OFString*)type ID: (OFString*)ID; /** - * Initializes an already allocated XMPPIQ with a certain type and id + * Initializes an already allocated XMPPIQ with the specified type and id * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A initialized XMPPIQ */ - initWithType: (OFString*)type ID: (OFString*)ID; @end Index: src/XMPPIQ.m ================================================================== --- src/XMPPIQ.m +++ src/XMPPIQ.m @@ -9,16 +9,16 @@ } - initWithType: (OFString*)type_ ID: (OFString*)ID_ { - if (!([type_ isEqual: @"get"] || - [type_ isEqual: @"set"] || - [type_ isEqual: @"result"] || - [type_ isEqual: @"error"])) + if (![type_ isEqual: @"get"] && + ![type_ isEqual: @"set"] && + ![type_ isEqual: @"result"] && + ![type_ isEqual: @"error"]) of_log(@"Invalid IQ type!"); return [super initWithName: @"iq" - type: type_ - ID: ID_]; + type: type_ + ID: ID_]; } @end Index: src/XMPPJID.h ================================================================== --- src/XMPPJID.h +++ src/XMPPJID.h @@ -1,60 +1,52 @@ #import /** - * \brief A class for easy handling of JIDs + * \brief A class for easy handling of JIDs. */ @interface XMPPJID: OFObject { - /** - * The JID's localpart - */ + /// The JID's localpart OFString *node; - - /** - * The JID's domainpart - */ + /// The JID's domainpart OFString *domain; - - /** - * The JID's resourcepart - */ + /// The JID's resourcepart OFString *resource; } @property (copy) OFString *node; @property (copy) OFString *domain; @property (copy) OFString *resource; /** - * Creates a new XMPPJID + * Creates a new autoreleased XMPPJID. * * \return A new autoreleased XMPPJID */ + JID; /** - * Creates a new XMPPJID from a OFString + * Creates a new autoreleased XMPPJID from a string. * * \param str The string to parse into a JID object * \return A new autoreleased XMPPJID */ + JIDWithString: (OFString*)str; /** - * Initializes an already allocated XMPPJID using a OFString + * Initializes an already allocated XMPPJID with a string. * * \param str The string to parse into a JID object * \return A initialized XMPPJID */ - initWithString: (OFString*)str; /** - * \return A OFString containing the bare JID + * \return An OFString containing the bare JID */ - (OFString*)bareJID; /** - * \return A OFString containing the full JID + * \return An OFString containing the full JID */ - (OFString*)fullJID; @end Index: src/XMPPJID.m ================================================================== --- src/XMPPJID.m +++ src/XMPPJID.m @@ -1,7 +1,9 @@ #include + #include + #import "XMPPJID.h" @implementation XMPPJID @synthesize node; @synthesize domain; @@ -23,18 +25,18 @@ size_t nodesep, resourcesep; nodesep = [str indexOfFirstOccurrenceOfString: @"@"]; resourcesep = [str indexOfFirstOccurrenceOfString: @"/"]; - if (nodesep == -1) - [self setNode: @""]; + if (nodesep == SIZE_MAX) + [self setNode: nil]; else [self setNode: [str substringFromIndex: 0 toIndex: nodesep]]; - if (resourcesep == -1) { - [self setResource: @""]; + if (resourcesep == SIZE_MAX) { + [self setResource: nil]; resourcesep = [str length]; } else [self setResource: [str substringFromIndex: resourcesep + 1 toIndex: [str length]]]; @@ -46,14 +48,20 @@ - (void)setNode: (OFString*)node_ { OFString *old = node; char *nodepart; - Stringprep_rc rc; - if ((rc = stringprep_profile([node_ cString], &nodepart, "Nodeprep", 0)) - != STRINGPREP_OK) { + + if (node_ == nil) { + [old release]; + node = nil; + return; + } + + if ((rc = stringprep_profile([node_ cString], &nodepart, + "Nodeprep", 0)) != STRINGPREP_OK) { of_log(@"Nodeprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -67,14 +75,14 @@ - (void)setDomain: (OFString*)domain_ { OFString *old = domain; char *srv; - Stringprep_rc rc; - if ((rc = stringprep_profile([domain_ cString], &srv, "Nameprep", 0)) - != STRINGPREP_OK) { + + if ((rc = stringprep_profile([domain_ cString], &srv, + "Nameprep", 0)) != STRINGPREP_OK) { of_log(@"Nameprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -88,14 +96,20 @@ - (void)setResource: (OFString*)resource_ { OFString *old = resource; char *res; - Stringprep_rc rc; + + if (resource_ == nil) { + [old release]; + resource = nil; + return; + } + if ((rc = stringprep_profile([resource_ cString], &res, - "Resourceprep", 0)) != STRINGPREP_OK) { + "Resourceprep", 0)) != STRINGPREP_OK) { of_log(@"Resourceprep failed: %s", stringprep_strerror(rc)); assert(0); } @try { @@ -107,21 +121,21 @@ [old release]; } - (OFString*)bareJID { - if ([node length]) + if (node != nil) return [OFString stringWithFormat: @"%@@%@", node, domain]; else return [OFString stringWithFormat: @"%@", domain]; } - (OFString*)fullJID { - if ([node length]) + if (node != nil) return [OFString stringWithFormat: @"%@@%@/%@", node, domain, resource]; else return [OFString stringWithFormat: @"%@/%@", domain, resource]; } @end Index: src/XMPPMessage.h ================================================================== --- src/XMPPMessage.h +++ src/XMPPMessage.h @@ -1,72 +1,69 @@ #import "XMPPStanza.h" /** - * \brief A class describing a message stanza + * \brief A class describing a message stanza. */ @interface XMPPMessage: XMPPStanza -{ -} - /** - * Creates a new XMPPMessage + * Creates a new autoreleased XMPPMessage. * * \return A new autoreleased XMPPMessage */ + message; /** - * Creates a new XMPPMessage with a certain id + * Creates a new autoreleased XMPPMessage with the specified id. * * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPMessage */ + messageWithID: (OFString*)ID; /** - * Creates a new XMPPMessage with a certain type + * Creates a new autoreleased XMPPMessage with the specified type. * * \param type The value for the stanza's type attribute * \return A new autoreleased XMPPMessage */ + messageWithType: (OFString*)type; /** - * Creates a new XMPPMessage with a certain type and id + * Creates a new autoreleased XMPPMessage with the specified type and id. * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPMessage */ + messageWithType: (OFString*)type ID: (OFString*)ID; /** - * Initializes an already allocated XMPPMessage + * Initializes an already allocated XMPPMessage. * * \return A initialized XMPPMessage */ - init; /** - * Initializes an already allocated XMPPMessage with a certain id + * Initializes an already allocated XMPPMessage with the specified id. * * \param ID The value for the stanza's id attribute * \return A initialized XMPPMessage */ - initWithID: (OFString*)ID; /** - * Initializes an already allocated XMPPMessage with a certain type + * Initializes an already allocated XMPPMessage with the specified type. * * \param type The value for the stanza's type attribute * \return A initialized XMPPMessage */ - initWithType: (OFString*)type; /** - * Initializes an already allocated XMPPMessage with a certain type and id + * Initializes an already allocated XMPPMessage with the specified type and id. * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A initialized XMPPMessage */ Index: src/XMPPPresence.h ================================================================== --- src/XMPPPresence.h +++ src/XMPPPresence.h @@ -1,96 +1,93 @@ #import "XMPPStanza.h" /** - * \brief A class describing a presence stanza + * \brief A class describing a presence stanza. */ @interface XMPPPresence: XMPPStanza -{ -} - /** - * Creates a new XMPPPresence + * Creates a new autoreleased XMPPPresence. * * \return A new autoreleased XMPPPresence */ + presence; /** - * Creates a new XMPPPresence with a certain id + * Creates a new autoreleased XMPPPresence with the specified id. * * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPPresence */ + presenceWithID: (OFString*)ID; /** - * Creates a new XMPPPresence with a certain type + * Creates a new autoreleased XMPPPresence with the specified type. * * \param type The value for the stanza's type attribute * \return A new autoreleased XMPPPresence */ + presenceWithType: (OFString*)type; /** - * Creates a new XMPPPresence with a certain type and id + * Creates a new autoreleased XMPPPresence with the specified type and id. * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPPresence */ + presenceWithType: (OFString*)type ID: (OFString*)ID; /** - * Initializes an already allocated XMPPPresence + * Initializes an already allocated XMPPPresence. * * \return A initialized XMPPPresence */ - init; /** - * Initializes an already allocated XMPPPresence with a certain id + * Initializes an already allocated XMPPPresence with the specified id. * * \param ID The value for the stanza's id attribute * \return A initialized XMPPPresence */ - initWithID: (OFString*)ID; /** - * Initializes an already allocated XMPPPresence with a certain type + * Initializes an already allocated XMPPPresence with the specified type. * * \param type The value for the stanza's type attribute * \return A initialized XMPPPresence */ - initWithType: (OFString*)type; /** - * Initializes an already allocated XMPPPresence with a certain type and id + * Initializes an already allocated XMPPPresence with the specified type and id. * * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A initialized XMPPPresence */ - initWithType: (OFString*)type ID: (OFString*)ID; /** - * Adds a show element to the presence stanza + * Adds a show element to the presence stanza. * * \param show The text content of the show element */ - (void)addShow: (OFString*)show; /** - * Adds a status element to the presence stanza + * Adds a status element to the presence stanza. * * \param status The text content of the status element */ - (void)addStatus: (OFString*)status; /** - * Adds a priority element to the presence stanza + * Adds a priority element to the presence stanza. * * \param priority The text content of the priority element */ - (void)addPriority: (int8_t)priority; @end Index: src/XMPPStanza.h ================================================================== --- src/XMPPStanza.h +++ src/XMPPStanza.h @@ -1,68 +1,57 @@ #import /** - * \brief A class describing a XMPP Stanza + * \brief A class describing an XMPP Stanza. */ @interface XMPPStanza: OFXMLElement { - /** - * The value of the stanza's from attribute - */ + /// The value of the stanza's from attribute OFString *from; - - /** - * The value of the stanza's to attribute - */ + /// The value of the stanza's to attribute OFString *to; - - /** - * The value of the stanza's type attribute - */ + /// The value of the stanza's type attribute OFString *type; - - /** - * The value of the stanza's id attribute - */ + /// The value of the stanza's id attribute OFString *ID; } @property (copy) OFString *from; @property (copy) OFString *to; @property (copy) OFString *type; @property (copy) OFString *ID; /** - * Creates a new XMPPStanza with a certain name + * Creates a new autoreleased XMPPStanza with the specified name. * * \param name The stanza's name (one of iq, message or presence) * \return A new autoreleased XMPPStanza */ + stanzaWithName: (OFString*)name; /** - * Creates a new XMPPStanza with a certain name and type + * Creates a new autoreleased XMPPStanza with the specified name and type. * * \param name The stanza's name (one of iq, message or presence) * \param type The value for the stanza's type attribute * \return A new autoreleased XMPPStanza */ + stanzaWithName: (OFString*)name type: (OFString*)type; /** - * Creates a new XMPPStanza with a certain name and id + * Creates a new autoreleased XMPPStanza with the specified name and id. * * \param name The stanza's name (one of iq, message or presence) * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPStanza */ + stanzaWithName: (OFString*)name ID: (OFString*)ID; /** - * Creates a new XMPPStanza with a certain name, type and id + * Creates a new autoreleased XMPPStanza with the specified name, type and id. * * \param name The stanza's name (one of iq, message or presence) * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A new autoreleased XMPPStanza @@ -70,60 +59,61 @@ + stanzaWithName: (OFString*)name type: (OFString*)type ID: (OFString*)ID; /** - * Creates a new XMPPStanza from a OFXMLElement + * Creates a new autoreleased XMPPStanza from an OFXMLElement. * * \param elem The element to base the XMPPStanza on * \return A new autoreleased XMPPStanza */ + stanzaWithElement: (OFXMLElement*)elem; /** - * Initializes an already allocated XMPPStanza with a certain name + * Initializes an already allocated XMPPStanza with the specified name. * * \param name The stanza's name (one of iq, message or presence) * \return A initialized XMPPStanza */ - initWithName: (OFString*)name; /** - * Initializes an already allocated XMPPStanza with a certain name and type + * Initializes an already allocated XMPPStanza with the specified name and type. * * \param name The stanza's name (one of iq, message or presence) * \param type The value for the stanza's type attribute * \return A initialized XMPPStanza */ - initWithName: (OFString*)name - type: (OFString*)type; + type: (OFString*)type; /** - * Initializes an already allocated XMPPStanza with a certain name and id + * Initializes an already allocated XMPPStanza with the specified name and id. * * \param name The stanza's name (one of iq, message or presence) * \param ID The value for the stanza's id attribute * \return A initialized XMPPStanza */ - initWithName: (OFString*)name - ID: (OFString*)ID; + ID: (OFString*)ID; /** - * Initializes an already allocated XMPPStanza with a certain name, type and id + * Initializes an already allocated XMPPStanza with the specified name, type + * and id. * * \param name The stanza's name (one of iq, message or presence) * \param type The value for the stanza's type attribute * \param ID The value for the stanza's id attribute * \return A initialized XMPPStanza */ - initWithName: (OFString*)name - type: (OFString*)type - ID: (OFString*)ID; + type: (OFString*)type + ID: (OFString*)ID; /** * Initializes an already allocated XMPPStanza based on a OFXMLElement * * \param elem The element to base the XMPPStanza on * \return A initialized XMPPStanza */ - initWithElement: (OFXMLElement*)elem; @end Index: src/XMPPStanza.m ================================================================== --- src/XMPPStanza.m +++ src/XMPPStanza.m @@ -63,49 +63,60 @@ - initWithName: (OFString*)name_ type: (OFString*)type_ ID: (OFString*)ID_ { - if (!([name_ isEqual: @"iq"] || - [name_ isEqual: @"message"] || - [name_ isEqual: @"presence"])) + if (![name_ isEqual: @"iq"] && + ![name_ isEqual: @"message"] && + ![name_ isEqual: @"presence"]) of_log(@"Invalid stanza name!"); self = [super initWithName: name_]; - [self setDefaultNamespace: @"jabber:client"]; - if (type_) - [self setType: type_]; - if (ID_) - [self setID: ID_]; + + @try { + [self setDefaultNamespace: @"jabber:client"]; + + if (type_) + [self setType: type_]; + + if (ID_) + [self setID: ID_]; + } @catch (id e) { + [self release]; + @throw e; + } + return self; } - initWithElement: (OFXMLElement*)elem { self = [super initWithName: elem.name namespace: elem.namespace]; - OFXMLAttribute *attr; - - for (attr in elem.attributes) { - if ([attr.name isEqual: @"from"]) { - [self setFrom: [attr stringValue]]; - } else if ([attr.name isEqual: @"to"]) { - [self setTo: [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]; - } - } - - OFXMLElement *el; - - for (el in elem.children) { - [self addChild: el]; + @try { + OFXMLAttribute *attr; + OFXMLElement *el; + + for (attr in elem.attributes) { + if ([attr.name isEqual: @"from"]) + [self setFrom: [attr stringValue]]; + else if ([attr.name isEqual: @"to"]) + [self setTo: [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) + [self addChild: el]; + } @catch (id e) { + [self release]; + @throw e; } return self; } @@ -122,33 +133,44 @@ - (void)setFrom: (OFString*)from_ { OFString* old = from; from = [from_ copy]; [old release]; - [self addAttributeWithName: @"from" stringValue: from_]; + + /* FIXME: Remove old attribute! */ + [self addAttributeWithName: @"from" + stringValue: from_]; } - (void)setTo: (OFString*)to_ { OFString* old = to; to = [to_ copy]; [old release]; - [self addAttributeWithName: @"to" stringValue: to]; + + /* FIXME: Remove old attribute! */ + [self addAttributeWithName: @"to" + stringValue: to]; } - (void)setType: (OFString*)type_ { OFString* old = type; type = [type_ copy]; [old release]; - [self addAttributeWithName: @"type" stringValue: type]; + + /* FIXME: Remove old attribute! */ + [self addAttributeWithName: @"type" + stringValue: type]; } - (void)setID: (OFString*)ID_ { OFString* old = ID; ID = [ID_ copy]; [old release]; + + /* FIXME: Remove old attribute! */ [self addAttributeWithName: @"id" stringValue: ID]; } @end Index: tests/test.m ================================================================== --- tests/test.m +++ tests/test.m @@ -2,10 +2,13 @@ #import #import "XMPPConnection.h" #import "XMPPStanza.h" +#import "XMPPIQ.h" +#import "XMPPMessage.h" +#import "XMPPPresence.h" @interface AppDelegate: OFObject { XMPPConnection *conn; } @@ -23,40 +26,40 @@ [pres addStatus: @"Bored"]; [pres addPriority: 20]; pres.to = @"alice@example.com"; pres.from = @"bob@example.org"; assert([[pres stringValue] isEqual: @"chat" - @"Bored20" - @""]); + @"from='bob@example.org'>chat" + @"Bored20" + @""]); XMPPMessage *msg = [XMPPMessage messageWithType: @"chat"]; [msg addBody: @"Hello everyone"]; msg.to = @"jdev@conference.jabber.org"; msg.from = @"alice@example.com"; assert([[msg stringValue] isEqual: @"Hello everyone" - @""]); + @"to='jdev@conference.jabber.org' " + @"from='alice@example.com'>Hello everyone" + @""]); XMPPIQ *iq = [XMPPIQ IQWithType: @"set" ID: @"128"]; iq.to = @"juliet@capulet.lit"; iq.from = @"romeo@montague.lit"; assert([[iq stringValue] isEqual: @""]); + @"to='juliet@capulet.lit' " + @"from='romeo@montague.lit'/>"]); OFXMLElement *elem = [OFXMLElement elementWithName: @"iq"]; [elem addAttributeWithName: @"from" stringValue: @"bob@localhost"]; [elem addAttributeWithName: @"to" stringValue: @"alice@localhost"]; [elem addAttributeWithName: @"type" stringValue: @"get"]; [elem addAttributeWithName: @"id" stringValue: @"42"]; XMPPStanza *stanza = [XMPPStanza stanzaWithElement: elem]; assert([[elem stringValue] isEqual: [stanza stringValue]]); assert(([[OFString stringWithFormat: @"%@, %@, %@, %@", stanza.from, - stanza.to, stanza.type, stanza.ID] - isEqual: @"bob@localhost, alice@localhost, get, 42"])); + stanza.to, stanza.type, stanza.ID] + isEqual: @"bob@localhost, alice@localhost, get, 42"])); conn = [[XMPPConnection alloc] init]; if (arguments.count != 3) { of_log(@"Invalid count of command line arguments!");