1
2
3
4
5
6
7
8
9
|
1
2
3
4
5
6
7
8
9
|
-
+
|
/*
* Copyright (c) 2011, 2012, 2013, Jonathan Schleifer <js@heap.zone>
* Copyright (c) 2011, 2012, 2013, 2019, Jonathan Schleifer <js@heap.zone>
* Copyright (c) 2011, 2012, 2013, Florian Zeitz <florob@babelmonkeys.de>
*
* https://heap.zone/objxmpp/
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice is present in all copies.
|
︙ | | |
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
|
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
|
-
-
-
-
+
+
-
-
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
|
+ (instancetype)JIDWithString: (OFString *)string
{
return [[[self alloc] initWithString: string] autorelease];
}
- (instancetype)initWithString: (OFString *)string
{
size_t nodesep, resourcesep;
self = [super init];
if (string == nil) {
[self release];
@try {
size_t nodesep, resourcesep;
return nil;
}
if (string == nil)
@throw [OFInvalidArgumentException exception];
nodesep = [string rangeOfString: @"@"].location;
resourcesep = [string rangeOfString: @"/"].location;
nodesep = [string rangeOfString: @"@"].location;
resourcesep = [string rangeOfString: @"/"].location;
if (nodesep == SIZE_MAX)
[self setNode: nil];
else
[self setNode:
[string substringWithRange: of_range(0, nodesep)]];
if (nodesep == SIZE_MAX)
self.node = nil;
else
self.node =
[string substringWithRange: of_range(0, nodesep)];
if (resourcesep == SIZE_MAX) {
[self setResource: nil];
resourcesep = [string length];
} else {
of_range_t range = of_range(resourcesep + 1,
[string length] - resourcesep - 1);
[self setResource: [string substringWithRange: range]];
}
if (resourcesep == SIZE_MAX) {
self.resource = nil;
resourcesep = string.length;
} else {
of_range_t range = of_range(resourcesep + 1,
string.length - resourcesep - 1);
self.resource = [string substringWithRange: range];
}
[self setDomain: [string substringWithRange:
of_range(nodesep + 1, resourcesep - nodesep - 1)]];
self.domain = [string substringWithRange:
of_range(nodesep + 1, resourcesep - nodesep - 1)];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_node release];
|
︙ | | |
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
-
+
|
if (node == nil) {
[old release];
_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
exceptionWithConnection: nil
profile: @"Nodeprep"
string: node];
|
︙ | | |
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
-
+
|
- (void)setDomain: (OFString *)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
exceptionWithConnection: nil
profile: @"Nameprep"
string: domain];
|
︙ | | |
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
-
+
|
if (resource == nil) {
[old release];
_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
exceptionWithConnection: nil
profile: @"Resourceprep"
string: resource];
|
︙ | | |
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
-
+
-
+
-
+
|
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)
return [self bareJID];
return self.bareJID;
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];
}
|
︙ | | |
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
-
-
-
+
+
+
|
- (uint32_t)hash
{
uint32_t hash;
OF_HASH_INIT(hash);
OF_HASH_ADD_HASH(hash, [_node hash]);
OF_HASH_ADD_HASH(hash, [_domain hash]);
OF_HASH_ADD_HASH(hash, [_resource hash]);
OF_HASH_ADD_HASH(hash, _node.hash);
OF_HASH_ADD_HASH(hash, _domain.hash);
OF_HASH_ADD_HASH(hash, _resource.hash);
OF_HASH_FINALIZE(hash);
return hash;
}
@end
|