ObjXMPP  Diff

Differences From Artifact [e0809705cc]:

To Artifact [2b87940ac6]:


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

@implementation XMPPJID
+ JID
{
	return [[[self alloc] init] autorelease];
}

+ JIDWithString: (OFString*)str
{
	return [[[self alloc] initWithString: str] autorelease];
}

- initWithString: (OFString*)str
{
	size_t nodesep, resourcesep;

	self = [super init];

	if (str == nil) {
		[self release];
		return nil;
	}

	nodesep = [str rangeOfString: @"@"].location;
	resourcesep = [str rangeOfString: @"/"].location;

	if (nodesep == SIZE_MAX)
		[self setNode: nil];
	else

		[self setNode: [str 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:
	    of_range(nodesep + 1, resourcesep - nodesep - 1)]];

	return self;
}

- (void)dealloc
{
	[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];
	} @catch (id e) {
		[new release];
		@throw e;
	}

	return new;
}

- (void)setNode: (OFString*)node_
{
	OFString *old = node;
	char *nodepart;
	Stringprep_rc rc;

	if (node_ == nil) {
		[old release];
		node = nil;
		return;
	}

	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_];

	@try {
		node = [[OFString alloc] initWithUTF8String: nodepart];
	} @finally {
		free(nodepart);
	}

	[old release];
}

- (OFString*)node
{
	return [[node copy] autorelease];
}

- (void)setDomain: (OFString*)domain_
{
	OFString *old = domain;
	char *srv;
	Stringprep_rc rc;

	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_];

	@try {
		domain = [[OFString alloc] initWithUTF8String: srv];
	} @finally {
		free(srv);
	}

	[old release];
}

- (OFString*)domain
{
	return [[domain copy] autorelease];
}

- (void)setResource: (OFString*)resource_
{
	OFString *old = resource;
	char *res;
	Stringprep_rc rc;

	if (resource_ == nil) {
		[old release];
		resource = nil;
		return;
	}

	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_];

	@try {
		resource = [[OFString alloc] initWithUTF8String: res];
	} @finally {
		free(res);
	}

	[old release];
}

- (OFString*)resource
{
	return [[resource copy] autorelease];
}

- (OFString*)bareJID
{
	if (node != nil)
		return [OFString stringWithFormat: @"%@@%@", node, domain];
	else
		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];

	if (node != nil)
		return [OFString stringWithFormat: @"%@@%@/%@",
		       node, domain, resource];
	else
		return [OFString stringWithFormat: @"%@/%@",
		       domain, resource];
}

- (OFString*)description
{
	return [self fullJID];
}

- (BOOL)isEqual: (id)object
{
	XMPPJID *otherJID;

	if (object == self)
		return YES;

	if (![object isKindOfClass: [XMPPJID class]])
		return NO;

	otherJID = object;

	if ([node isEqual: [otherJID node]] &&
	    [domain isEqual: [otherJID domain]] &&
	    [resource isEqual: [otherJID resource]])
		return YES;

	return NO;
}

- (uint32_t) hash
{







|

|


|





|




|
|




>
|



|
|
|
|
>
|
>
|







|
|
|









|
|
|








|

|



|

|



|






|


|









|


|

|



|






|


|









|


|

|



|

|



|






|


|









|




|
|

|





|


|

|


|









|







|

<
|
|







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*)string
{
	return [[[self alloc] initWithString: string] autorelease];
}

- initWithString: (OFString*)string
{
	size_t nodesep, resourcesep;

	self = [super init];

	if (string == nil) {
		[self release];
		return nil;
	}

	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 (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]];
	}

	[self setDomain: [string substringWithRange:
	    of_range(nodesep + 1, resourcesep - nodesep - 1)]];

	return self;
}

- (void)dealloc
{
	[_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];
	} @catch (id e) {
		[new release];
		@throw e;
	}

	return new;
}

- (void)setNode: (OFString*)node
{
	OFString *old = _node;
	char *nodepart;
	Stringprep_rc rc;

	if (node == nil) {
		[old release];
		_node = nil;
		return;
	}

	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];

	@try {
		_node = [[OFString alloc] initWithUTF8String: nodepart];
	} @finally {
		free(nodepart);
	}

	[old release];
}

- (OFString*)node
{
	return [[_node copy] autorelease];
}

- (void)setDomain: (OFString*)domain
{
	OFString *old = _domain;
	char *srv;
	Stringprep_rc rc;

	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];

	@try {
		_domain = [[OFString alloc] initWithUTF8String: srv];
	} @finally {
		free(srv);
	}

	[old release];
}

- (OFString*)domain
{
	return [[_domain copy] autorelease];
}

- (void)setResource: (OFString*)resource
{
	OFString *old = _resource;
	char *res;
	Stringprep_rc rc;

	if (resource == nil) {
		[old release];
		_resource = nil;
		return;
	}

	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];

	@try {
		_resource = [[OFString alloc] initWithUTF8String: res];
	} @finally {
		free(res);
	}

	[old release];
}

- (OFString*)resource
{
	return [[_resource copy] autorelease];
}

- (OFString*)bareJID
{
	if (_node != nil)
		return [OFString stringWithFormat: @"%@@%@", _node, _domain];
	else
		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];

	if (_node != nil)
		return [OFString stringWithFormat: @"%@@%@/%@",
		       _node, _domain, _resource];
	else
		return [OFString stringWithFormat: @"%@/%@",
		       _domain, _resource];
}

- (OFString*)description
{
	return [self fullJID];
}

- (BOOL)isEqual: (id)object
{
	XMPPJID *JID;

	if (object == self)
		return YES;

	if (![object isKindOfClass: [XMPPJID class]])
		return NO;

	JID = object;


	if ([_node isEqual: JID->_node] && [_domain isEqual: JID->_domain] &&
	    [_resource isEqual: JID->_resource])
		return YES;

	return NO;
}

- (uint32_t) hash
{