-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathXMPPIdentity.m
158 lines (140 loc) · 2.65 KB
/
XMPPIdentity.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// XMPPIdentity.m
// Jabber
//
// Created by David Chisnall on 20/08/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import "XMPPIdentity.h"
#import "XMPPRootIdentity.h"
#import <EtoileXML/ETXMLString.h>
#import <EtoileFoundation/EtoileFoundation.h>
@implementation XMPPIdentity
- (id) initWithJID:(JID*)_jid withName:(NSString*)_name inGroup:(NSString*)_group forPerson:(id)_person
{
if (!(self = [self init])) return nil;
jid = _jid;
name = _name;
group = _group;
person = _person;
return self;
}
- (id) initWithXMLParser: (ETXMLParser*) aParser
key: (id) aKey
{
self = [super initWithXMLParser: aParser
key: aKey];
if (nil == self)
{
return nil;
}
presence = [[XMPPPresence alloc] init];
return self;
}
/*
<query xmlns='jabber:iq:roster'>
<item
jid='user@example.com'
subscription='to'
name='SomeUser'>
<group>SomeGroup</group>
</item>
</query>
*/
- (void)startElement:(NSString *)aName
attributes:(NSDictionary*)attributes
{
if([aName isEqualToString:@"item"])
{
depth++;
jid = [[JID alloc] initWithString:[attributes objectForKey:@"jid"]];
subscription = [attributes objectForKey:@"subscription"];
ask = [attributes objectForKey:@"ask"];
name = [attributes objectForKey:@"name"];
}
else if([aName isEqualToString:@"group"])
{
[[[ETXMLString alloc] initWithXMLParser:parser
key:@"group"] startElement:aName
attributes:attributes];
}
else
{
[[[ETXMLNullHandler alloc] initWithXMLParser:parser
key:nil] startElement:aName
attributes:attributes];
}
}
- (void) addgroup:(NSString*)aGroup
{
group = aGroup;
}
- (void) setPresence:(XMPPPresence*)_presence
{
presence = _presence;
priority = basePriority + 70 - [presence show] + [presence priority];
}
- (NSString*) name
{
if (name == nil)
{
return [jid node];
}
return name;
}
- (NSString*) group
{
return group;
}
- (void) setName:(NSString*)aName
{
name = aName;
}
- (void) setGroup:(NSString*)aGroup
{
group = aGroup;
}
- (JID*) jid
{
return jid;
}
- (XMPPPresence*) presence
{
return presence;
}
- (int) priority
{
return priority;
}
- (NSString*) subscription
{
return subscription;
}
- (NSString*) ask
{
return ask;
}
- (id) person
{
return person;
}
- (void) person:(id)_person
{
person = _person;
}
- (NSComparisonResult) compareByPriority:(XMPPIdentity*)_other
{
if(priority > [_other priority])
{
return NSOrderedAscending;
}
if(priority < [_other priority])
{
return NSOrderedDescending;
}
return NSOrderedSame;
}
- (NSComparisonResult) compareByJID:(XMPPIdentity*)_other
{
return NSOrderedAscending;
}
@end