Skip to content
This repository
Browse code

Adding a few more convenience methods.

  • Loading branch information...
commit d10a11d7870431cc1186d2c3a1d8b744d7d74ce0 1 parent d560d0f
Robbie Hanson authored
2  Core/XMPPIQ.h
@@ -23,6 +23,7 @@
23 23 * If the type or elementID parameters are nil, those attributes will not be added.
24 24 **/
25 25 + (XMPPIQ *)iq;
  26 ++ (XMPPIQ *)iqWithType:(NSString *)type;
26 27 + (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid;
27 28 + (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
28 29 + (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
@@ -32,6 +33,7 @@
32 33 * If the type or elementID parameters are nil, those attributes will not be added.
33 34 **/
34 35 - (id)init;
  36 +- (id)initWithType:(NSString *)type;
35 37 - (id)initWithType:(NSString *)type to:(XMPPJID *)jid;
36 38 - (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid;
37 39 - (id)initWithType:(NSString *)type to:(XMPPJID *)jid elementID:(NSString *)eid child:(NSXMLElement *)childElement;
10 Core/XMPPIQ.m
@@ -41,6 +41,11 @@ + (XMPPIQ *)iq
41 41 return [[[XMPPIQ alloc] initWithType:nil to:nil elementID:nil child:nil] autorelease];
42 42 }
43 43
  44 ++ (XMPPIQ *)iqWithType:(NSString *)type
  45 +{
  46 + return [[[XMPPIQ alloc] initWithType:type to:nil elementID:nil child:nil] autorelease];
  47 +}
  48 +
44 49 + (XMPPIQ *)iqWithType:(NSString *)type to:(XMPPJID *)jid
45 50 {
46 51 return [[[XMPPIQ alloc] initWithType:type to:jid elementID:nil child:nil] autorelease];
@@ -61,6 +66,11 @@ - (id)init
61 66 return [self initWithType:nil to:nil elementID:nil child:nil];
62 67 }
63 68
  69 +- (id)initWithType:(NSString *)type
  70 +{
  71 + return [self initWithType:type to:nil elementID:nil child:nil];
  72 +}
  73 +
64 74 - (id)initWithType:(NSString *)type to:(XMPPJID *)jid
65 75 {
66 76 return [self initWithType:type to:jid elementID:nil child:nil];
14 Core/XMPPJID.h
... ... @@ -1,5 +1,16 @@
1 1 #import <Foundation/Foundation.h>
2 2
  3 +enum XMPPJIDCompareOptions
  4 +{
  5 + XMPPJIDCompareUser = 1, // 001
  6 + XMPPJIDCompareDomain = 2, // 010
  7 + XMPPJIDCompareResource = 4, // 100
  8 +
  9 + XMPPJIDCompareBare = 3, // 011
  10 + XMPPJIDCompareFull = 7, // 111
  11 +};
  12 +typedef enum XMPPJIDCompareOptions XMPPJIDCompareOptions;
  13 +
3 14
4 15 @interface XMPPJID : NSObject <NSCoding, NSCopying>
5 16 {
@@ -33,6 +44,7 @@
33 44 /**
34 45 * When you know both objects are JIDs, this method is a faster way to check equality than isEqual:.
35 46 **/
36   -- (BOOL)isEqualToJID:(XMPPJID *)aJID;
  47 +- (BOOL)isEqualToJID:(XMPPJID *)aJID;
  48 +- (BOOL)isEqualToJID:(XMPPJID *)aJID options:(XMPPJIDCompareOptions)mask;
37 49
38 50 @end
44 Core/XMPPJID.m
@@ -362,27 +362,41 @@ - (BOOL)isEqual:(id)anObject
362 362
363 363 - (BOOL)isEqualToJID:(XMPPJID *)aJID
364 364 {
  365 + return [self isEqualToJID:aJID options:XMPPJIDCompareFull];
  366 +}
  367 +
  368 +- (BOOL)isEqualToJID:(XMPPJID *)aJID options:(XMPPJIDCompareOptions)mask
  369 +{
365 370 if (aJID == nil) return NO;
366 371
367   - if (user) {
368   - if (![user isEqualToString:aJID->user]) return NO;
369   - }
370   - else {
371   - if (aJID->user) return NO;
  372 + if (mask & XMPPJIDCompareUser)
  373 + {
  374 + if (user) {
  375 + if (![user isEqualToString:aJID->user]) return NO;
  376 + }
  377 + else {
  378 + if (aJID->user) return NO;
  379 + }
372 380 }
373 381
374   - if (domain) {
375   - if (![domain isEqualToString:aJID->domain]) return NO;
376   - }
377   - else {
378   - if (aJID->domain) return NO;
  382 + if (mask & XMPPJIDCompareDomain)
  383 + {
  384 + if (domain) {
  385 + if (![domain isEqualToString:aJID->domain]) return NO;
  386 + }
  387 + else {
  388 + if (aJID->domain) return NO;
  389 + }
379 390 }
380 391
381   - if (resource) {
382   - if (![resource isEqualToString:aJID->resource]) return NO;
383   - }
384   - else {
385   - if (aJID->resource) return NO;
  392 + if (mask & XMPPJIDCompareResource)
  393 + {
  394 + if (resource) {
  395 + if (![resource isEqualToString:aJID->resource]) return NO;
  396 + }
  397 + else {
  398 + if (aJID->resource) return NO;
  399 + }
386 400 }
387 401
388 402 return YES;

0 comments on commit d10a11d

Please sign in to comment.
Something went wrong with that request. Please try again.