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;
+ 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;
- 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;
@end
@ -26,6 +40,9 @@
+ IQWithType: (OFString*)type_
ID: (OFString*)ID_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
@end
@interface XMPPMessage: XMPPStanza
@ -38,6 +55,12 @@
+ messageWithType: (OFString*)type_
ID: (OFString*)ID_;
- init;
- initWithID: (OFString*)ID_;
- initWithType: (OFString*)type_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
- (void)addBody: (OFString*)body;
@end
@ -51,6 +74,12 @@
+ presenceWithType: (OFString*)type_
ID: (OFString*)ID_;
- init;
- initWithID: (OFString*)ID_;
- initWithType: (OFString*)type_;
- initWithType: (OFString*)type_
ID: (OFString*)ID_;
- (void)addShow: (OFString*)show;
- (void)addStatus: (OFString*)status;
- (void)addPriority: (int8_t)priority;

View file

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

Binary file not shown.