Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a few more convenience methods.

  • Loading branch information...
commit d10a11d7870431cc1186d2c3a1d8b744d7d74ce0 1 parent d560d0f
@robbiehanson authored
Showing with 54 additions and 16 deletions.
  1. +2 −0  Core/XMPPIQ.h
  2. +10 −0 Core/XMPPIQ.m
  3. +13 −1 Core/XMPPJID.h
  4. +29 −15 Core/XMPPJID.m
View
2  Core/XMPPIQ.h
@@ -23,6 +23,7 @@
* If the type or elementID parameters are nil, those attributes will not be added.
**/
+ (XMPPIQ *)iq;
++ (XMPPIQ *)iqWithType:(NSString *)type;
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid;
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
@@ -32,6 +33,7 @@
* If the type or elementID parameters are nil, those attributes will not be added.
**/
- (id)init;
+- (id)initWithType:(NSString *)type;
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid;
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
View
10 Core/XMPPIQ.m
@@ -41,6 +41,11 @@ + (XMPPIQ *)iq
return [[[XMPPIQ alloc] initWithType:nil to:nil elementID:nil child:nil] autorelease];
}
++ (XMPPIQ *)iqWithType:(NSString *)type
+{
+ return [[[XMPPIQ alloc] initWithType:type to:nil elementID:nil child:nil] autorelease];
+}
+
+ (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid
{
return [[[XMPPIQ alloc] initWithType:type to:jid elementID:nil child:nil] autorelease];
@@ -61,6 +66,11 @@ - (id)init
return [self initWithType:nil to:nil elementID:nil child:nil];
}
+- (id)initWithType:(NSString *)type
+{
+ return [self initWithType:type to:nil elementID:nil child:nil];
+}
+
- (id)initWithType:(NSString *)type to:(XMPPJID *)jid
{
return [self initWithType:type to:jid elementID:nil child:nil];
View
14 Core/XMPPJID.h
@@ -1,5 +1,16 @@
#import <Foundation/Foundation.h>
+enum XMPPJIDCompareOptions
+{
+ XMPPJIDCompareUser = 1, // 001
+ XMPPJIDCompareDomain = 2, // 010
+ XMPPJIDCompareResource = 4, // 100
+
+ XMPPJIDCompareBare = 3, // 011
+ XMPPJIDCompareFull = 7, // 111
+};
+typedef enum XMPPJIDCompareOptions XMPPJIDCompareOptions;
+
@interface XMPPJID : NSObject <NSCoding, NSCopying>
{
@@ -33,6 +44,7 @@
/**
* When you know both objects are JIDs, this method is a faster way to check equality than isEqual:.
**/
-- (BOOL)isEqualToJID:(XMPPJID *)aJID;
+- (BOOL)isEqualToJID:(XMPPJID *)aJID;
+- (BOOL)isEqualToJID:(XMPPJID *)aJID options:(XMPPJIDCompareOptions)mask;
@end
View
44 Core/XMPPJID.m
@@ -362,27 +362,41 @@ - (BOOL)isEqual:(id)anObject
- (BOOL)isEqualToJID:(XMPPJID *)aJID
{
+ return [self isEqualToJID:aJID options:XMPPJIDCompareFull];
+}
+
+- (BOOL)isEqualToJID:(XMPPJID *)aJID options:(XMPPJIDCompareOptions)mask
+{
if (aJID == nil) return NO;
- if (user) {
- if (![user isEqualToString:aJID->user]) return NO;
- }
- else {
- if (aJID->user) return NO;
+ if (mask & XMPPJIDCompareUser)
+ {
+ if (user) {
+ if (![user isEqualToString:aJID->user]) return NO;
+ }
+ else {
+ if (aJID->user) return NO;
+ }
}
- if (domain) {
- if (![domain isEqualToString:aJID->domain]) return NO;
- }
- else {
- if (aJID->domain) return NO;
+ if (mask & XMPPJIDCompareDomain)
+ {
+ if (domain) {
+ if (![domain isEqualToString:aJID->domain]) return NO;
+ }
+ else {
+ if (aJID->domain) return NO;
+ }
}
- if (resource) {
- if (![resource isEqualToString:aJID->resource]) return NO;
- }
- else {
- if (aJID->resource) return NO;
+ if (mask & XMPPJIDCompareResource)
+ {
+ if (resource) {
+ if (![resource isEqualToString:aJID->resource]) return NO;
+ }
+ else {
+ if (aJID->resource) return NO;
+ }
}
return YES;
Please sign in to comment.
Something went wrong with that request. Please try again.