Clean up the code.

This commit is contained in:
Jonathan Schleifer 2011-02-16 21:05:14 +01:00
parent fa59d3ce32
commit 4690b47ae9
11 changed files with 186 additions and 184 deletions

View file

@ -1,8 +1,7 @@
#import <ObjFW/ObjFW.h> #import <ObjFW/ObjFW.h>
#import "XMPPJID.h"
@class XMPPConnection; @class XMPPConnection;
@class XMPPJID;
@class XMPPIQ; @class XMPPIQ;
@class XMPPMessage; @class XMPPMessage;
@class XMPPPresence; @class XMPPPresence;
@ -18,47 +17,26 @@
@end @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 <OFXMLElementBuilderDelegate> @interface XMPPConnection: OFObject <OFXMLElementBuilderDelegate>
{ {
OFTCPSocket *sock; OFTCPSocket *sock;
OFXMLParser *parser; OFXMLParser *parser;
OFXMLElementBuilder *elementBuilder; OFXMLElementBuilder *elementBuilder;
/// The username to connect with
/**
* The username to connect with
*/
OFString *username; OFString *username;
/// The password to connect with
/**
* The password to connect with
*/
OFString *password; OFString *password;
/// The server to connect to
/**
* The server to connect to
*/
OFString *server; OFString *server;
/// The resource to connect with
/**
* The resource to connect with
*/
OFString *resource; 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; XMPPJID *JID;
/// The port to connect to
/**
* The port to connect to
*/
short port; short port;
/// Whether to use TLS
/**
* Whether to use TLS
*/
BOOL useTLS; BOOL useTLS;
id <XMPPConnectionDelegate> delegate; id <XMPPConnectionDelegate> delegate;
OFMutableArray *mechanisms; OFMutableArray *mechanisms;
@ -68,23 +46,23 @@
@property (copy) OFString *password; @property (copy) OFString *password;
@property (copy) OFString *server; @property (copy) OFString *server;
@property (copy) OFString *resource; @property (copy) OFString *resource;
@property (readonly) XMPPJID *JID; @property (copy, readonly) XMPPJID *JID;
@property (assign) short port; @property (assign) short port;
@property (assign) BOOL useTLS; @property (assign) BOOL useTLS;
@property (retain) id <XMPPConnectionDelegate> delegate; @property (retain) id <XMPPConnectionDelegate> delegate;
/** /**
* Connects to the XMPP service * Connects to the XMPP service.
*/ */
- (void)connect; - (void)connect;
/** /**
* Starts a loop handling incomming data * Starts a loop handling incomming data.
*/ */
- (void)handleConnection; - (void)handleConnection;
/** /**
* Sends a OFXMLElement (usually a XMPPStanza) * Sends an OFXMLElement, usually an XMPPStanza.
* *
* \param elem The element to send * \param elem The element to send
*/ */

View file

@ -4,6 +4,7 @@
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPStanza.h" #import "XMPPStanza.h"
#import "XMPPJID.h"
#import "XMPPIQ.h" #import "XMPPIQ.h"
#define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind" #define NS_BIND @"urn:ietf:params:xml:ns:xmpp-bind"
@ -55,8 +56,8 @@
char *node; char *node;
Stringprep_rc rc; Stringprep_rc rc;
if ((rc = stringprep_profile([username_ cString], &node, "SASLprep", 0)) if ((rc = stringprep_profile([username_ cString], &node,
!= STRINGPREP_OK) { "SASLprep", 0)) != STRINGPREP_OK) {
of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); of_log(@"SASLprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -76,8 +77,8 @@
char *res; char *res;
Stringprep_rc rc; Stringprep_rc rc;
if ((rc = stringprep_profile([resource_ cString], &res, "Resourceprep", 0)) if ((rc = stringprep_profile([resource_ cString], &res,
!= STRINGPREP_OK) { "Resourceprep", 0)) != STRINGPREP_OK) {
of_log(@"Resourceprep failed: %s", stringprep_strerror(rc)); of_log(@"Resourceprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -97,8 +98,8 @@
char *srv; char *srv;
Stringprep_rc rc; Stringprep_rc rc;
if ((rc = stringprep_profile([server_ cString], &srv, "Nameprep", 0)) if ((rc = stringprep_profile([server_ cString], &srv,
!= STRINGPREP_OK) { "Nameprep", 0)) != STRINGPREP_OK) {
of_log(@"Nameprep failed: %s", stringprep_strerror(rc)); of_log(@"Nameprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -118,8 +119,8 @@
char *pass; char *pass;
Stringprep_rc rc; Stringprep_rc rc;
if ((rc = stringprep_profile([password_ cString], &pass, "SASLprep", 0)) if ((rc = stringprep_profile([password_ cString], &pass,
!= STRINGPREP_OK) { "SASLprep", 0)) != STRINGPREP_OK) {
of_log(@"SASLprep failed: %s", stringprep_strerror(rc)); of_log(@"SASLprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -145,7 +146,8 @@
{ {
OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
[sock connectToHost: server onPort: port]; [sock connectToHost: server
onPort: port];
[self _startStream]; [self _startStream];
[pool release]; [pool release];
@ -181,13 +183,18 @@
attributes: (OFArray*)attrs attributes: (OFArray*)attrs
{ {
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
![ns isEqual: NS_STREAM]) ![ns isEqual: NS_STREAM]) {
of_log(@"Did not get expected stream start!"); 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"] && if ([attr.name isEqual: @"from"] &&
![attr.stringValue isEqual: server]) ![attr.stringValue isEqual: server]) {
of_log(@"Got invalid from in stream start!"); of_log(@"Got invalid from in stream start!");
assert(0);
}
}
parser.delegate = elementBuilder; parser.delegate = elementBuilder;
} }
@ -244,6 +251,7 @@
- (void)_handleResourceBind: (XMPPIQ*)iq - (void)_handleResourceBind: (XMPPIQ*)iq
{ {
OFXMLElement *bindElem = iq.children.firstObject; OFXMLElement *bindElem = iq.children.firstObject;
if ([bindElem.name isEqual: @"bind"] && if ([bindElem.name isEqual: @"bind"] &&
[bindElem.namespace isEqual: NS_BIND]) { [bindElem.namespace isEqual: NS_BIND]) {
OFXMLElement *jidElem = bindElem.children.firstObject; OFXMLElement *jidElem = bindElem.children.firstObject;
@ -302,10 +310,11 @@
if ([elem.name isEqual: @"iq"] && if ([elem.name isEqual: @"iq"] &&
[elem.namespace isEqual: NS_CLIENT]) { [elem.namespace isEqual: NS_CLIENT]) {
XMPPIQ *iq = [XMPPIQ stanzaWithElement: elem]; 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]; [self _handleResourceBind: iq];
} }
}
} }
- (void)elementBuilder: (OFXMLElementBuilder*)b - (void)elementBuilder: (OFXMLElementBuilder*)b

View file

@ -1,11 +1,11 @@
#import "XMPPStanza.h" #import "XMPPStanza.h"
/** /**
* \brief A class describing a IQ stanza * \brief A class describing an IQ stanza.
*/ */
@interface XMPPIQ: XMPPStanza @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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -15,7 +15,7 @@
ID: (OFString*)ID; 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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute

View file

@ -11,10 +11,10 @@
- initWithType: (OFString*)type_ - initWithType: (OFString*)type_
ID: (OFString*)ID_ ID: (OFString*)ID_
{ {
if (!([type_ isEqual: @"get"] || if (![type_ isEqual: @"get"] &&
[type_ isEqual: @"set"] || ![type_ isEqual: @"set"] &&
[type_ isEqual: @"result"] || ![type_ isEqual: @"result"] &&
[type_ isEqual: @"error"])) ![type_ isEqual: @"error"])
of_log(@"Invalid IQ type!"); of_log(@"Invalid IQ type!");
return [super initWithName: @"iq" return [super initWithName: @"iq"

View file

@ -1,23 +1,15 @@
#import <ObjFW/ObjFW.h> #import <ObjFW/ObjFW.h>
/** /**
* \brief A class for easy handling of JIDs * \brief A class for easy handling of JIDs.
*/ */
@interface XMPPJID: OFObject @interface XMPPJID: OFObject
{ {
/** /// The JID's localpart
* The JID's localpart
*/
OFString *node; OFString *node;
/// The JID's domainpart
/**
* The JID's domainpart
*/
OFString *domain; OFString *domain;
/// The JID's resourcepart
/**
* The JID's resourcepart
*/
OFString *resource; OFString *resource;
} }
@ -26,14 +18,14 @@
@property (copy) OFString *resource; @property (copy) OFString *resource;
/** /**
* Creates a new XMPPJID * Creates a new autoreleased XMPPJID.
* *
* \return A new autoreleased XMPPJID * \return A new autoreleased XMPPJID
*/ */
+ JID; + 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 * \param str The string to parse into a JID object
* \return A new autoreleased XMPPJID * \return A new autoreleased XMPPJID
@ -41,7 +33,7 @@
+ JIDWithString: (OFString*)str; + 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 * \param str The string to parse into a JID object
* \return A initialized XMPPJID * \return A initialized XMPPJID
@ -49,12 +41,12 @@
- initWithString: (OFString*)str; - initWithString: (OFString*)str;
/** /**
* \return A OFString containing the bare JID * \return An OFString containing the bare JID
*/ */
- (OFString*)bareJID; - (OFString*)bareJID;
/** /**
* \return A OFString containing the full JID * \return An OFString containing the full JID
*/ */
- (OFString*)fullJID; - (OFString*)fullJID;
@end @end

View file

@ -1,5 +1,7 @@
#include <assert.h> #include <assert.h>
#include <stringprep.h> #include <stringprep.h>
#import "XMPPJID.h" #import "XMPPJID.h"
@implementation XMPPJID @implementation XMPPJID
@ -25,14 +27,14 @@
nodesep = [str indexOfFirstOccurrenceOfString: @"@"]; nodesep = [str indexOfFirstOccurrenceOfString: @"@"];
resourcesep = [str indexOfFirstOccurrenceOfString: @"/"]; resourcesep = [str indexOfFirstOccurrenceOfString: @"/"];
if (nodesep == -1) if (nodesep == SIZE_MAX)
[self setNode: @""]; [self setNode: nil];
else else
[self setNode: [str substringFromIndex: 0 [self setNode: [str substringFromIndex: 0
toIndex: nodesep]]; toIndex: nodesep]];
if (resourcesep == -1) { if (resourcesep == SIZE_MAX) {
[self setResource: @""]; [self setResource: nil];
resourcesep = [str length]; resourcesep = [str length];
} else } else
[self setResource: [str substringFromIndex: resourcesep + 1 [self setResource: [str substringFromIndex: resourcesep + 1
@ -48,10 +50,16 @@
{ {
OFString *old = node; OFString *old = node;
char *nodepart; char *nodepart;
Stringprep_rc rc; 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)); of_log(@"Nodeprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -69,10 +77,10 @@
{ {
OFString *old = domain; OFString *old = domain;
char *srv; char *srv;
Stringprep_rc rc; 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)); of_log(@"Nameprep failed: %s", stringprep_strerror(rc));
assert(0); assert(0);
} }
@ -90,8 +98,14 @@
{ {
OFString *old = resource; OFString *old = resource;
char *res; char *res;
Stringprep_rc rc; Stringprep_rc rc;
if (resource_ == nil) {
[old release];
resource = nil;
return;
}
if ((rc = stringprep_profile([resource_ cString], &res, if ((rc = stringprep_profile([resource_ cString], &res,
"Resourceprep", 0)) != STRINGPREP_OK) { "Resourceprep", 0)) != STRINGPREP_OK) {
of_log(@"Resourceprep failed: %s", stringprep_strerror(rc)); of_log(@"Resourceprep failed: %s", stringprep_strerror(rc));
@ -109,7 +123,7 @@
- (OFString*)bareJID - (OFString*)bareJID
{ {
if ([node length]) if (node != nil)
return [OFString stringWithFormat: @"%@@%@", node, domain]; return [OFString stringWithFormat: @"%@@%@", node, domain];
else else
return [OFString stringWithFormat: @"%@", domain]; return [OFString stringWithFormat: @"%@", domain];
@ -117,7 +131,7 @@
- (OFString*)fullJID - (OFString*)fullJID
{ {
if ([node length]) if (node != nil)
return [OFString stringWithFormat: @"%@@%@/%@", return [OFString stringWithFormat: @"%@@%@/%@",
node, domain, resource]; node, domain, resource];
else else

View file

@ -1,21 +1,18 @@
#import "XMPPStanza.h" #import "XMPPStanza.h"
/** /**
* \brief A class describing a message stanza * \brief A class describing a message stanza.
*/ */
@interface XMPPMessage: XMPPStanza @interface XMPPMessage: XMPPStanza
{
}
/** /**
* Creates a new XMPPMessage * Creates a new autoreleased XMPPMessage.
* *
* \return A new autoreleased XMPPMessage * \return A new autoreleased XMPPMessage
*/ */
+ message; + 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 * \param ID The value for the stanza's id attribute
* \return A new autoreleased XMPPMessage * \return A new autoreleased XMPPMessage
@ -23,7 +20,7 @@
+ messageWithID: (OFString*)ID; + 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 * \param type The value for the stanza's type attribute
* \return A new autoreleased XMPPMessage * \return A new autoreleased XMPPMessage
@ -31,7 +28,7 @@
+ messageWithType: (OFString*)type; + 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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -41,14 +38,14 @@
ID: (OFString*)ID; ID: (OFString*)ID;
/** /**
* Initializes an already allocated XMPPMessage * Initializes an already allocated XMPPMessage.
* *
* \return A initialized XMPPMessage * \return A initialized XMPPMessage
*/ */
- init; - 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 * \param ID The value for the stanza's id attribute
* \return A initialized XMPPMessage * \return A initialized XMPPMessage
@ -56,7 +53,7 @@
- initWithID: (OFString*)ID; - 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 * \param type The value for the stanza's type attribute
* \return A initialized XMPPMessage * \return A initialized XMPPMessage
@ -64,7 +61,7 @@
- initWithType: (OFString*)type; - 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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute

View file

@ -1,21 +1,18 @@
#import "XMPPStanza.h" #import "XMPPStanza.h"
/** /**
* \brief A class describing a presence stanza * \brief A class describing a presence stanza.
*/ */
@interface XMPPPresence: XMPPStanza @interface XMPPPresence: XMPPStanza
{
}
/** /**
* Creates a new XMPPPresence * Creates a new autoreleased XMPPPresence.
* *
* \return A new autoreleased XMPPPresence * \return A new autoreleased XMPPPresence
*/ */
+ presence; + 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 * \param ID The value for the stanza's id attribute
* \return A new autoreleased XMPPPresence * \return A new autoreleased XMPPPresence
@ -23,7 +20,7 @@
+ presenceWithID: (OFString*)ID; + 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 * \param type The value for the stanza's type attribute
* \return A new autoreleased XMPPPresence * \return A new autoreleased XMPPPresence
@ -31,7 +28,7 @@
+ presenceWithType: (OFString*)type; + 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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -41,14 +38,14 @@
ID: (OFString*)ID; ID: (OFString*)ID;
/** /**
* Initializes an already allocated XMPPPresence * Initializes an already allocated XMPPPresence.
* *
* \return A initialized XMPPPresence * \return A initialized XMPPPresence
*/ */
- init; - 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 * \param ID The value for the stanza's id attribute
* \return A initialized XMPPPresence * \return A initialized XMPPPresence
@ -56,7 +53,7 @@
- initWithID: (OFString*)ID; - 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 * \param type The value for the stanza's type attribute
* \return A initialized XMPPPresence * \return A initialized XMPPPresence
@ -64,7 +61,7 @@
- initWithType: (OFString*)type; - 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 type The value for the stanza's type attribute
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -74,21 +71,21 @@
ID: (OFString*)ID; 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 * \param show The text content of the show element
*/ */
- (void)addShow: (OFString*)show; - (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 * \param status The text content of the status element
*/ */
- (void)addStatus: (OFString*)status; - (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 * \param priority The text content of the priority element
*/ */

View file

@ -1,28 +1,17 @@
#import <ObjFW/ObjFW.h> #import <ObjFW/ObjFW.h>
/** /**
* \brief A class describing a XMPP Stanza * \brief A class describing an XMPP Stanza.
*/ */
@interface XMPPStanza: OFXMLElement @interface XMPPStanza: OFXMLElement
{ {
/** /// The value of the stanza's from attribute
* The value of the stanza's from attribute
*/
OFString *from; OFString *from;
/// The value of the stanza's to attribute
/**
* The value of the stanza's to attribute
*/
OFString *to; OFString *to;
/// The value of the stanza's type attribute
/**
* The value of the stanza's type attribute
*/
OFString *type; OFString *type;
/// The value of the stanza's id attribute
/**
* The value of the stanza's id attribute
*/
OFString *ID; OFString *ID;
} }
@ -32,7 +21,7 @@
@property (copy) OFString *ID; @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) * \param name The stanza's name (one of iq, message or presence)
* \return A new autoreleased XMPPStanza * \return A new autoreleased XMPPStanza
@ -40,7 +29,7 @@
+ stanzaWithName: (OFString*)name; + 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 name The stanza's name (one of iq, message or presence)
* \param type The value for the stanza's type attribute * \param type The value for the stanza's type attribute
@ -50,7 +39,7 @@
type: (OFString*)type; 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 name The stanza's name (one of iq, message or presence)
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -60,7 +49,7 @@
ID: (OFString*)ID; 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 name The stanza's name (one of iq, message or presence)
* \param type The value for the stanza's type attribute * \param type The value for the stanza's type attribute
@ -72,7 +61,7 @@
ID: (OFString*)ID; 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 * \param elem The element to base the XMPPStanza on
* \return A new autoreleased XMPPStanza * \return A new autoreleased XMPPStanza
@ -80,7 +69,7 @@
+ stanzaWithElement: (OFXMLElement*)elem; + 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) * \param name The stanza's name (one of iq, message or presence)
* \return A initialized XMPPStanza * \return A initialized XMPPStanza
@ -88,7 +77,7 @@
- initWithName: (OFString*)name; - 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 name The stanza's name (one of iq, message or presence)
* \param type The value for the stanza's type attribute * \param type The value for the stanza's type attribute
@ -98,7 +87,7 @@
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 name The stanza's name (one of iq, message or presence)
* \param ID The value for the stanza's id attribute * \param ID The value for the stanza's id attribute
@ -108,7 +97,8 @@
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 name The stanza's name (one of iq, message or presence)
* \param type The value for the stanza's type attribute * \param type The value for the stanza's type attribute

View file

@ -65,17 +65,26 @@
type: (OFString*)type_ type: (OFString*)type_
ID: (OFString*)ID_ ID: (OFString*)ID_
{ {
if (!([name_ isEqual: @"iq"] || if (![name_ isEqual: @"iq"] &&
[name_ isEqual: @"message"] || ![name_ isEqual: @"message"] &&
[name_ isEqual: @"presence"])) ![name_ isEqual: @"presence"])
of_log(@"Invalid stanza name!"); of_log(@"Invalid stanza name!");
self = [super initWithName: name_]; self = [super initWithName: name_];
@try {
[self setDefaultNamespace: @"jabber:client"]; [self setDefaultNamespace: @"jabber:client"];
if (type_) if (type_)
[self setType: type_]; [self setType: type_];
if (ID_) if (ID_)
[self setID: ID_]; [self setID: ID_];
} @catch (id e) {
[self release];
@throw e;
}
return self; return self;
} }
@ -84,26 +93,28 @@
self = [super initWithName: elem.name self = [super initWithName: elem.name
namespace: elem.namespace]; namespace: elem.namespace];
@try {
OFXMLAttribute *attr; 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; OFXMLElement *el;
for (el in elem.children) { 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]; [self addChild: el];
} @catch (id e) {
[self release];
@throw e;
} }
return self; return self;
@ -124,7 +135,10 @@
OFString* old = from; OFString* old = from;
from = [from_ copy]; from = [from_ copy];
[old release]; [old release];
[self addAttributeWithName: @"from" stringValue: from_];
/* FIXME: Remove old attribute! */
[self addAttributeWithName: @"from"
stringValue: from_];
} }
- (void)setTo: (OFString*)to_ - (void)setTo: (OFString*)to_
@ -132,7 +146,10 @@
OFString* old = to; OFString* old = to;
to = [to_ copy]; to = [to_ copy];
[old release]; [old release];
[self addAttributeWithName: @"to" stringValue: to];
/* FIXME: Remove old attribute! */
[self addAttributeWithName: @"to"
stringValue: to];
} }
- (void)setType: (OFString*)type_ - (void)setType: (OFString*)type_
@ -140,7 +157,10 @@
OFString* old = type; OFString* old = type;
type = [type_ copy]; type = [type_ copy];
[old release]; [old release];
[self addAttributeWithName: @"type" stringValue: type];
/* FIXME: Remove old attribute! */
[self addAttributeWithName: @"type"
stringValue: type];
} }
- (void)setID: (OFString*)ID_ - (void)setID: (OFString*)ID_
@ -148,6 +168,8 @@
OFString* old = ID; OFString* old = ID;
ID = [ID_ copy]; ID = [ID_ copy];
[old release]; [old release];
/* FIXME: Remove old attribute! */
[self addAttributeWithName: @"id" [self addAttributeWithName: @"id"
stringValue: ID]; stringValue: ID];
} }

View file

@ -4,6 +4,9 @@
#import "XMPPConnection.h" #import "XMPPConnection.h"
#import "XMPPStanza.h" #import "XMPPStanza.h"
#import "XMPPIQ.h"
#import "XMPPMessage.h"
#import "XMPPPresence.h"
@interface AppDelegate: OFObject @interface AppDelegate: OFObject
{ {