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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
-
+
-
+
-
+
-
+
-
-
+
+
+
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
+
+
|
@implementation XMPPJID
+ JID
{
return [[[self alloc] init] autorelease];
}
+ JIDWithString: (OFString*)str
+ JIDWithString: (OFString*)string
{
return [[[self alloc] initWithString: str] autorelease];
return [[[self alloc] initWithString: string] autorelease];
}
- initWithString: (OFString*)str
- initWithString: (OFString*)string
{
size_t nodesep, resourcesep;
self = [super init];
if (str == nil) {
if (string == nil) {
[self release];
return nil;
}
nodesep = [str rangeOfString: @"@"].location;
resourcesep = [str rangeOfString: @"/"].location;
nodesep = [string rangeOfString: @"@"].location;
resourcesep = [string rangeOfString: @"/"].location;
if (nodesep == SIZE_MAX)
[self setNode: nil];
else
[self setNode:
[self setNode: [str substringWithRange: of_range(0, nodesep)]];
[string substringWithRange: of_range(0, nodesep)]];
if (resourcesep == SIZE_MAX) {
[self setResource: nil];
resourcesep = [str length];
} else
[self setResource: [str substringWithRange:
of_range(resourcesep + 1, [str length] - resourcesep - 1)]];
[self setDomain: [str substringWithRange:
resourcesep = [string length];
} else {
of_range_t range = of_range(resourcesep + 1,
[string length] - resourcesep - 1);
[self setResource: [string substringWithRange: range]];
}
[self setDomain: [string substringWithRange:
of_range(nodesep + 1, resourcesep - nodesep - 1)]];
return self;
}
- (void)dealloc
{
[node release];
[domain release];
[resource release];
[_node release];
[_domain release];
[_resource release];
[super dealloc];
}
- copy
{
XMPPJID *new = [[XMPPJID alloc] init];
@try {
new->node = [node copy];
new->domain = [domain copy];
new->resource = [resource copy];
new->_node = [_node copy];
new->_domain = [_domain copy];
new->_resource = [_resource copy];
} @catch (id e) {
[new release];
@throw e;
}
return new;
}
- (void)setNode: (OFString*)node_
- (void)setNode: (OFString*)node
{
OFString *old = node;
OFString *old = _node;
char *nodepart;
Stringprep_rc rc;
if (node_ == nil) {
if (node == nil) {
[old release];
node = nil;
_node = nil;
return;
}
if (((rc = stringprep_profile([node_ UTF8String], &nodepart,
if (((rc = stringprep_profile([node UTF8String], &nodepart,
"Nodeprep", 0)) != STRINGPREP_OK) || (nodepart[0] == '\0') ||
(strlen(nodepart) > 1023))
@throw [XMPPStringPrepFailedException
exceptionWithClass: [self class]
connection: nil
profile: @"Nodeprep"
string: node_];
string: node];
@try {
node = [[OFString alloc] initWithUTF8String: nodepart];
_node = [[OFString alloc] initWithUTF8String: nodepart];
} @finally {
free(nodepart);
}
[old release];
}
- (OFString*)node
{
return [[node copy] autorelease];
return [[_node copy] autorelease];
}
- (void)setDomain: (OFString*)domain_
- (void)setDomain: (OFString*)domain
{
OFString *old = domain;
OFString *old = _domain;
char *srv;
Stringprep_rc rc;
if (((rc = stringprep_profile([domain_ UTF8String], &srv,
if (((rc = stringprep_profile([domain UTF8String], &srv,
"Nameprep", 0)) != STRINGPREP_OK) || (srv[0] == '\0') ||
(strlen(srv) > 1023))
@throw [XMPPStringPrepFailedException
exceptionWithClass: [self class]
connection: nil
profile: @"Nameprep"
string: domain_];
string: domain];
@try {
domain = [[OFString alloc] initWithUTF8String: srv];
_domain = [[OFString alloc] initWithUTF8String: srv];
} @finally {
free(srv);
}
[old release];
}
- (OFString*)domain
{
return [[domain copy] autorelease];
return [[_domain copy] autorelease];
}
- (void)setResource: (OFString*)resource_
- (void)setResource: (OFString*)resource
{
OFString *old = resource;
OFString *old = _resource;
char *res;
Stringprep_rc rc;
if (resource_ == nil) {
if (resource == nil) {
[old release];
resource = nil;
_resource = nil;
return;
}
if (((rc = stringprep_profile([resource_ UTF8String], &res,
if (((rc = stringprep_profile([resource UTF8String], &res,
"Resourceprep", 0)) != STRINGPREP_OK) || (res[0] == '\0') ||
(strlen(res) > 1023))
@throw [XMPPStringPrepFailedException
exceptionWithClass: [self class]
connection: nil
profile: @"Resourceprep"
string: resource_];
string: resource];
@try {
resource = [[OFString alloc] initWithUTF8String: res];
_resource = [[OFString alloc] initWithUTF8String: res];
} @finally {
free(res);
}
[old release];
}
- (OFString*)resource
{
return [[resource copy] autorelease];
return [[_resource copy] autorelease];
}
- (OFString*)bareJID
{
if (node != nil)
return [OFString stringWithFormat: @"%@@%@", node, domain];
if (_node != nil)
return [OFString stringWithFormat: @"%@@%@", _node, _domain];
else
return [OFString stringWithFormat: @"%@", domain];
return [OFString stringWithFormat: @"%@", _domain];
}
- (OFString*)fullJID
{
/* If we don't have a resource, the full JID is equal to the bare JID */
if (resource == nil)
if (_resource == nil)
return [self bareJID];
if (node != nil)
if (_node != nil)
return [OFString stringWithFormat: @"%@@%@/%@",
node, domain, resource];
_node, _domain, _resource];
else
return [OFString stringWithFormat: @"%@/%@",
domain, resource];
_domain, _resource];
}
- (OFString*)description
{
return [self fullJID];
}
- (BOOL)isEqual: (id)object
{
XMPPJID *otherJID;
XMPPJID *JID;
if (object == self)
return YES;
if (![object isKindOfClass: [XMPPJID class]])
return NO;
otherJID = object;
JID = object;
if ([node isEqual: [otherJID node]] &&
[domain isEqual: [otherJID domain]] &&
[resource isEqual: [otherJID resource]])
if ([_node isEqual: JID->_node] && [_domain isEqual: JID->_domain] &&
[_resource isEqual: JID->_resource])
return YES;
return NO;
}
- (uint32_t) hash
{
|