Add/use init functions in the XMPPStanza classes

This commit is contained in:
Florian Zeitz 2011-02-10 23:30:48 +01:00
parent 4e73c4a229
commit 3f2a22140e
3 changed files with 158 additions and 39 deletions

View file

@ -14,9 +14,23 @@
@property (copy) OFString *ID; @property (copy) OFString *ID;
+ stanzaWithName: (OFString*)name; + stanzaWithName: (OFString*)name;
+ stanzaWithName: (OFString*)name
type: (OFString*)type_;
+ stanzaWithName: (OFString*)name
ID: (OFString*)ID_;
+ stanzaWithName: (OFString*)name
type: (OFString*)type_
ID: (OFString*)ID_;
+ stanzaWithElement: (OFXMLElement*)elem; + stanzaWithElement: (OFXMLElement*)elem;
- initWithName: (OFString*)name; - initWithName: (OFString*)name;
- initWithName: (OFString*)name
type: (OFString*)type_;
- initWithName: (OFString*)name
ID: (OFString*)ID_;
- initWithName: (OFString*)name
type: (OFString*)type_
ID: (OFString*)ID_;
- initWithElement: (OFXMLElement*)elem; - initWithElement: (OFXMLElement*)elem;
@end @end
@ -26,6 +40,9 @@
+ IQWithType: (OFString*)type_ + IQWithType: (OFString*)type_
ID: (OFString*)ID_; ID: (OFString*)ID_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
@end @end
@interface XMPPMessage: XMPPStanza @interface XMPPMessage: XMPPStanza
@ -38,6 +55,12 @@
+ messageWithType: (OFString*)type_ + messageWithType: (OFString*)type_
ID: (OFString*)ID_; ID: (OFString*)ID_;
- init;
- initWithID: (OFString*)ID_;
- initWithType: (OFString*)type_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
- (void)addBody: (OFString*)body; - (void)addBody: (OFString*)body;
@end @end
@ -51,6 +74,12 @@
+ presenceWithType: (OFString*)type_ + presenceWithType: (OFString*)type_
ID: (OFString*)ID_; ID: (OFString*)ID_;
- init;
- initWithID: (OFString*)ID_;
- initWithType: (OFString*)type_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
- (void)addShow: (OFString*)show; - (void)addShow: (OFString*)show;
- (void)addStatus: (OFString*)status; - (void)addStatus: (OFString*)status;
- (void)addPriority: (int8_t)priority; - (void)addPriority: (int8_t)priority;

View file

@ -11,26 +11,73 @@
return [[[self alloc] initWithName: name] autorelease]; return [[[self alloc] initWithName: name] autorelease];
} }
+ stanzaWithName: (OFString*)name
type: (OFString*)type_
{
return [[[self alloc] initWithName: name
type: type_] autorelease];
}
+ stanzaWithName: (OFString*)name
ID: (OFString*)ID_
{
return [[[self alloc] initWithName: name
ID: ID_] autorelease];
}
+ stanzaWithName: (OFString*)name
type: (OFString*)type_
ID: (OFString*)ID_
{
return [[[self alloc] initWithName: name
type: type_
ID: ID_] autorelease];
}
+ stanzaWithElement: (OFXMLElement*)elem { + stanzaWithElement: (OFXMLElement*)elem {
return [[[self alloc] initWithElement: elem] autorelease]; return [[[self alloc] initWithElement: elem] autorelease];
} }
- initWithName: (OFString*)name_ - initWithName: (OFString*)name_
{
return [self initWithName: name_
type: nil
ID: nil];
}
- initWithName: (OFString*)name_
type: (OFString*)type_
{
return [self initWithName: name_
type: type_
ID: nil];
}
- initWithName: (OFString*)name_
ID: (OFString*)ID_
{
return [self initWithName: name_
type: nil
ID: ID_];
}
- initWithName: (OFString*)name_
type: (OFString*)type_
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_]; id ret;
ret = [super initWithName: name_];
[self setDefaultNamespace: @"jabber:client"]; [self setDefaultNamespace: @"jabber:client"];
if (type_)
from = [[OFString alloc] init]; [ret setType: type_];
to = [[OFString alloc] init]; if (ID_)
type = [[OFString alloc] init]; [ret setID: ID_];
ID = [[OFString alloc] init]; return ret;
return self;
} }
- initWithElement: (OFXMLElement*)elem - initWithElement: (OFXMLElement*)elem
@ -38,11 +85,6 @@
self = [super initWithName: elem.name self = [super initWithName: elem.name
namespace: elem.namespace]; namespace: elem.namespace];
from = [[OFString alloc] init];
to = [[OFString alloc] init];
type = [[OFString alloc] init];
ID = [[OFString alloc] init];
OFXMLAttribute *attr; OFXMLAttribute *attr;
for (attr in elem.attributes) { for (attr in elem.attributes) {
@ -107,13 +149,21 @@
OFString* old = ID; OFString* old = ID;
ID = [ID_ copy]; ID = [ID_ copy];
[old release]; [old release];
[self addAttributeWithName: @"id" stringValue: ID]; [self addAttributeWithName: @"id"
stringValue: ID];
} }
@end @end
@implementation XMPPIQ @implementation XMPPIQ
+ IQWithType: (OFString*)type_ + IQWithType: (OFString*)type_
ID: (OFString*)ID_ ID: (OFString*)ID_
{
return [[[self alloc] initWithType: type_
ID: ID_] autorelease];
}
- initWithType: (OFString*)type_
ID: (OFString*)ID_
{ {
if (!([type_ isEqual: @"get"] || if (!([type_ isEqual: @"get"] ||
[type_ isEqual: @"set"] || [type_ isEqual: @"set"] ||
@ -121,40 +171,59 @@
[type_ isEqual: @"error"])) [type_ isEqual: @"error"]))
of_log(@"Invalid IQ type!"); of_log(@"Invalid IQ type!");
id ret; return [super initWithName: @"iq"
ret = [[[self alloc] initWithName: @"iq"] autorelease]; type: type_
[ret setType: type_]; ID: ID_];
[ret setID: ID_];
return ret;
} }
@end @end
@implementation XMPPMessage @implementation XMPPMessage
+ message + message
{ {
return [self messageWithType: nil ID: nil]; return [[[self alloc] init] autorelease];
} }
+ messageWithID: (OFString*)ID_ + messageWithID: (OFString*)ID_
{ {
return [self messageWithType: nil ID: ID_]; return [[[self alloc] initWithID: ID_] autorelease];
} }
+ messageWithType: (OFString*)type_ + messageWithType: (OFString*)type_
{ {
return [self messageWithType: type_ ID: nil]; return [[[self alloc] initWithType: type_] autorelease];
} }
+ messageWithType: (OFString*)type_ + messageWithType: (OFString*)type_
ID: (OFString*)ID_ ID: (OFString*)ID_
{ {
id ret; return [[[self alloc] initWithType: type_
ret = [[[self alloc] initWithName: @"message"] autorelease]; ID: ID_] autorelease];
if (type_) }
[ret setType: type_];
if (ID_) - init
[ret setID: ID_]; {
return ret; return [self initWithType: nil
ID: nil];
}
- initWithID: (OFString*)ID_
{
return [self initWithType: nil
ID: ID_];
}
- initWithType: (OFString*)type_
{
return [self initWithType: type_
ID: nil];
}
- initWithType: (OFString*)type_
ID: (OFString*)ID_
{
return [super initWithName: @"message"
type: type_
ID: ID_];
} }
- (void)addBody: (OFString*)body - (void)addBody: (OFString*)body
@ -167,29 +236,50 @@
@implementation XMPPPresence @implementation XMPPPresence
+ presence + presence
{ {
return [self presenceWithType: nil ID: nil]; return [[[self alloc] init] autorelease];
} }
+ presenceWithID: (OFString*)ID_ + presenceWithID: (OFString*)ID_
{ {
return [self presenceWithType: nil ID: ID_]; return [[[self alloc] initWithID: ID_] autorelease];
} }
+ presenceWithType: (OFString*)type_ + presenceWithType: (OFString*)type_
{ {
return [self presenceWithType: type_ ID: nil]; return [[[self alloc] initWithType: type_] autorelease];
} }
+ presenceWithType: (OFString*)type_ + presenceWithType: (OFString*)type_
ID: (OFString*)ID_ ID: (OFString*)ID_
{ {
id ret; return [[[self alloc] initWithType: type_
ret = [[[self alloc] initWithName: @"presence"] autorelease]; ID: ID_] autorelease];
if (type_) }
[ret setType: type_];
if (ID_) - init
[ret setID: ID_]; {
return ret; return [self initWithType: nil
ID: nil];
}
- initWithID: (OFString*)ID_
{
return [self initWithType: nil
ID: ID_];
}
- initWithType: (OFString*)type_
{
return [self initWithType: type_
ID: nil];
}
- initWithType: (OFString*)type_
ID: (OFString*)ID_
{
return [super initWithName: @"presence"
type: type_
ID: ID_];
} }
- (void)addShow: (OFString*)show - (void)addShow: (OFString*)show

Binary file not shown.