ObjXMPP  Check-in [543fb8b84d]

Overview
Comment:Adjust to reworked exception API.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 543fb8b84deb86ba89f48cea91784016d4fc0b717d2297e9ffba0a34314f0d28
User & Date: js on 2013-06-23 14:19:42
Other Links: manifest | tags
Context
2013-06-23
19:57
Get rid of BOOL. check-in: dd2c1286f9 user: js tags: trunk
14:19
Adjust to reworked exception API. check-in: 543fb8b84d user: js tags: trunk
2013-06-12
12:53
XMPPDiscoEntity: Caps hash must be Base64 encoded SHA1 check-in: c74a473e92 user: florob@babelmonkeys.de tags: trunk
Changes

Modified src/XMPPConnection.m from [004473a420] to [8415025e4d].

167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
	if (username != nil) {
		char *node;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([username UTF8String], &node,
		    "SASLprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException
			    exceptionWithClass: [self class]
				    connection: self
				       profile: @"SASLprep"
					string: username];

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







<
|
|
|







167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
	if (username != nil) {
		char *node;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([username UTF8String], &node,
		    "SASLprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException

			    exceptionWithConnection: self
					    profile: @"SASLprep"
					     string: username];

		@try {
			_username = [[OFString alloc] initWithUTF8String: node];
		} @finally {
			free(node);
		}
	} else
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
	if (resource != nil) {
		char *res;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([resource UTF8String], &res,
		    "Resourceprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException
			    exceptionWithClass: [self class]
				    connection: self
				       profile: @"Resourceprep"
					string: resource];

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







<
|
|
|







198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
	if (resource != nil) {
		char *res;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([resource UTF8String], &res,
		    "Resourceprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException

			    exceptionWithConnection: self
					    profile: @"Resourceprep"
					     string: resource];

		@try {
			_resource = [[OFString alloc] initWithUTF8String: res];
		} @finally {
			free(res);
		}
	} else
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
	if (domain_ != nil) {
		char *srv;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([domain_ UTF8String], &srv,
		    "Nameprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException
			    exceptionWithClass: [self class]
				    connection: self
				       profile: @"Nameprep"
					string: domain_];

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








<
|
|
|







247
248
249
250
251
252
253

254
255
256
257
258
259
260
261
262
263
	if (domain_ != nil) {
		char *srv;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([domain_ UTF8String], &srv,
		    "Nameprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException

			    exceptionWithConnection: self
					    profile: @"Nameprep"
					     string: domain_];

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

286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
	if (password != nil) {
		char *pass;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([password UTF8String], &pass,
		    "SASLprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException
			    exceptionWithClass: [self class]
				    connection: self
				       profile: @"SASLprep"
					string: password];

		@try {
			_password = [[OFString alloc] initWithUTF8String: pass];
		} @finally {
			free(pass);
		}
	} else







<
|
|
|







283
284
285
286
287
288
289

290
291
292
293
294
295
296
297
298
299
	if (password != nil) {
		char *pass;
		Stringprep_rc rc;

		if ((rc = stringprep_profile([password UTF8String], &pass,
		    "SASLprep", 0)) != STRINGPREP_OK)
			@throw [XMPPStringPrepFailedException

			    exceptionWithConnection: self
					    profile: @"SASLprep"
					     string: password];

		@try {
			_password = [[OFString alloc] initWithUTF8String: pass];
		} @finally {
			free(pass);
		}
	} else
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	XMPPSRVEntry *candidate = nil;
	XMPPSRVLookup *SRVLookup = nil;
	OFEnumerator *enumerator;

	if (_socket != nil)
		@throw [OFAlreadyConnectedException
		    exceptionWithClass: [self class]];

	_socket = [[OFTCPSocket alloc] init];

	if (_server)
		[_socket connectToHost: _server
				  port: _port];
	else {







|
<







331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	XMPPSRVEntry *candidate = nil;
	XMPPSRVLookup *SRVLookup = nil;
	OFEnumerator *enumerator;

	if (_socket != nil)
		@throw [OFAlreadyConnectedException exception];


	_socket = [[OFTCPSocket alloc] init];

	if (_server)
		[_socket connectToHost: _server
				  port: _port];
	else {
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
		prefix: (OFString*)prefix
	     namespace: (OFString*)ns
{
	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: XMPP_NS_STREAM])
		@throw [OFMalformedXMLException
		    exceptionWithClass: [builder class]
				parser: nil];
	else {
		[self close];
	}
}

- (void)XMPP_startStream
{







|
<
<







682
683
684
685
686
687
688
689


690
691
692
693
694
695
696
- (void)elementBuilder: (OFXMLElementBuilder*)builder
  didNotExpectCloseTag: (OFString*)name
		prefix: (OFString*)prefix
	     namespace: (OFString*)ns
{
	if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
	    ![ns isEqual: XMPP_NS_STREAM])
		@throw [OFMalformedXMLException exception];


	else {
		[self close];
	}
}

- (void)XMPP_startStream
{
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
			condition = @"undefined";

		reason = [[element
		    elementForName: @"text"
			 namespace: XMPP_NS_XMPP_STREAM] stringValue];

		@throw [XMPPStreamErrorException
		    exceptionWithClass: [self class]
			    connection: self
			     condition: condition
				reason: reason];
		return;
	}

	assert(0);
}

- (void)XMPP_handleTLS: (OFXMLElement*)element







<
|
|
|







862
863
864
865
866
867
868

869
870
871
872
873
874
875
876
877
878
			condition = @"undefined";

		reason = [[element
		    elementForName: @"text"
			 namespace: XMPP_NS_XMPP_STREAM] stringValue];

		@throw [XMPPStreamErrorException

		    exceptionWithConnection: self
				  condition: condition
				     reason: reason];
		return;
	}

	assert(0);
}

- (void)XMPP_handleTLS: (OFXMLElement*)element
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
		[self XMPP_startStream];

		return;
	}

	if ([[element name] isEqual: @"failure"])
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exceptionWithClass: [self class]];

	assert(0);
}

- (void)XMPP_handleSASL: (OFXMLElement*)element
{
	if ([[element name] isEqual: @"challenge"]) {







|







903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
		[self XMPP_startStream];

		return;
	}

	if ([[element name] isEqual: @"failure"])
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exception];

	assert(0);
}

- (void)XMPP_handleSASL: (OFXMLElement*)element
{
	if ([[element name] isEqual: @"challenge"]) {
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
		return;
	}

	if ([[element name] isEqual: @"failure"]) {
		of_log(@"Auth failed!");
		// FIXME: Do more parsing/handling
		@throw [XMPPAuthFailedException
		    exceptionWithClass: [self class]
			    connection: self
				reason: [element XMLString]];
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{







<
|
|







949
950
951
952
953
954
955

956
957
958
959
960
961
962
963
964
		return;
	}

	if ([[element name] isEqual: @"failure"]) {
		of_log(@"Auth failed!");
		// FIXME: Do more parsing/handling
		@throw [XMPPAuthFailedException

		    exceptionWithConnection: self
				     reason: [element XMLString]];
	}

	assert(0);
}

- (void)XMPP_handleIQ: (XMPPIQ*)iq
{
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
		    [OFXMLElement elementWithName: @"starttls"
					namespace: XMPP_NS_STARTTLS]];
		return;
	}

	if (_encryptionRequired && !_encrypted)
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exceptionWithClass: [self class]];

	if ([element elementForName: @"ver"
			  namespace: XMPP_NS_ROSTERVER] != nil)
		_supportsRosterVersioning = YES;

	if ([element elementForName: @"sm"
			  namespace: XMPP_NS_SM] != nil)







|







1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
		    [OFXMLElement elementWithName: @"starttls"
					namespace: XMPP_NS_STARTTLS]];
		return;
	}

	if (_encryptionRequired && !_encrypted)
		/* TODO: Find/create an exception to throw here */
		@throw [OFException exception];

	if ([element elementForName: @"ver"
			  namespace: XMPP_NS_ROSTERVER] != nil)
		_supportsRosterVersioning = YES;

	if ([element elementForName: @"sm"
			  namespace: XMPP_NS_SM] != nil)
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
	OFString *ret;
	char *cDomain;
	Idna_rc rc;

	if ((rc = idna_to_ascii_8z([domain_ UTF8String],
	    &cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
		@throw [XMPPIDNATranslationFailedException
		    exceptionWithClass: [self class]
			    connection: self
			     operation: @"ToASCII"
				string: domain_];

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








<
|
|
|







1208
1209
1210
1211
1212
1213
1214

1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
	OFString *ret;
	char *cDomain;
	Idna_rc rc;

	if ((rc = idna_to_ascii_8z([domain_ UTF8String],
	    &cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
		@throw [XMPPIDNATranslationFailedException

		    exceptionWithConnection: self
				  operation: @"ToASCII"
				     string: domain_];

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

1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263
1264
{
	return _port;
}

- (void)setDataStorage: (id <XMPPStorage>)dataStorage
{
	if (_streamOpen)

		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]];

	_dataStorage = dataStorage;
}

- (id <XMPPStorage>)dataStorage
{
	return _dataStorage;







>
|
<







1239
1240
1241
1242
1243
1244
1245
1246
1247

1248
1249
1250
1251
1252
1253
1254
{
	return _port;
}

- (void)setDataStorage: (id <XMPPStorage>)dataStorage
{
	if (_streamOpen)
		/* FIXME: Find a better exception! */
		@throw [OFInvalidArgumentException exception];


	_dataStorage = dataStorage;
}

- (id <XMPPStorage>)dataStorage
{
	return _dataStorage;

Modified src/XMPPDiscoIdentity.m from [5bede0ee0a] to [16fe7db118].

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
	      type: (OFString*)type
	      name: (OFString*)name
{
	self = [super init];

	@try {
		if (category == nil || type == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		_category = [category copy];
		_name = [name copy];
		_type = [type copy];
	} @catch (id e) {
		[self release];
		@throw e;







|
<
<







43
44
45
46
47
48
49
50


51
52
53
54
55
56
57
	      type: (OFString*)type
	      name: (OFString*)name
{
	self = [super init];

	@try {
		if (category == nil || type == nil)
			@throw [OFInvalidArgumentException exception];



		_category = [category copy];
		_name = [name copy];
		_type = [type copy];
	} @catch (id e) {
		[self release];
		@throw e;
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
	of_comparison_result_t categoryResult;
	of_comparison_result_t typeResult;

	if (object == self)
		return OF_ORDERED_SAME;

	if (![object isKindOfClass: [XMPPDiscoIdentity class]])
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	identity = (XMPPDiscoIdentity*)object;

	categoryResult = [_category compare: identity->_category];
	if (categoryResult != OF_ORDERED_SAME)
		return categoryResult;








|
<
<







145
146
147
148
149
150
151
152


153
154
155
156
157
158
159
	of_comparison_result_t categoryResult;
	of_comparison_result_t typeResult;

	if (object == self)
		return OF_ORDERED_SAME;

	if (![object isKindOfClass: [XMPPDiscoIdentity class]])
		@throw [OFInvalidArgumentException exception];



	identity = (XMPPDiscoIdentity*)object;

	categoryResult = [_category compare: identity->_category];
	if (categoryResult != OF_ORDERED_SAME)
		return categoryResult;

Modified src/XMPPDiscoNode.m from [09821a03dd] to [bd94402de0].

56
57
58
59
60
61
62



63
64
65
66
67
68
69
70
71
- initWithJID: (XMPPJID*)JID
	 node: (OFString*)node
	 name: (OFString*)name
{
	self = [super init];

	@try {



		_JID = [JID copy];
		_node= [node copy];
		_name = [name copy];
		_identities = [OFSortedList new];
		_features = [OFSortedList new];
		_childNodes = [OFMutableDictionary new];

		[self addFeature: XMPP_NS_DISCO_ITEMS];
		[self addFeature: XMPP_NS_DISCO_INFO];







>
>
>

|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
- initWithJID: (XMPPJID*)JID
	 node: (OFString*)node
	 name: (OFString*)name
{
	self = [super init];

	@try {
		if (JID == nil)
			@throw [OFInvalidArgumentException exception];

		_JID = [JID copy];
		_node = [node copy];
		_name = [name copy];
		_identities = [OFSortedList new];
		_features = [OFSortedList new];
		_childNodes = [OFMutableDictionary new];

		[self addFeature: XMPP_NS_DISCO_ITEMS];
		[self addFeature: XMPP_NS_DISCO_INFO];

Modified src/XMPPExceptions.h from [5b24b061ea] to [43c3496d04].

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
/// \brief The connection the exception relates to
@property (readonly, assign) XMPPConnection *connection;
#endif

/**
 * \brief Creates a new XMPPException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that received the data responsible
 *	  for this exception
 * \return A new XMPPException
 */
+ exceptionWithClass: (Class)class_
	  connection: (XMPPConnection*)connection;

/**
 * \brief Initializes an already allocated XMPPException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that received the data responsible
 *	  for this exception
 * \return An initialized XMPPException
 */
- initWithClass: (Class)class_
     connection: (XMPPConnection*)connection;

- (XMPPConnection*)connection;
@end

/**
 * \brief An exception indicating a stream error was received
 */







<




<
|




<




<
|







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
/// \brief The connection the exception relates to
@property (readonly, assign) XMPPConnection *connection;
#endif

/**
 * \brief Creates a new XMPPException.
 *

 * \param connection The connection that received the data responsible
 *	  for this exception
 * \return A new XMPPException
 */

+ exceptionWithConnection: (XMPPConnection*)connection;

/**
 * \brief Initializes an already allocated XMPPException.
 *

 * \param connection The connection that received the data responsible
 *	  for this exception
 * \return An initialized XMPPException
 */

- initWithConnection: (XMPPConnection*)connection;

- (XMPPConnection*)connection;
@end

/**
 * \brief An exception indicating a stream error was received
 */
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
/// \brief The descriptive free-form text specified by the stream error
@property (readonly, assign) OFString *reason;
#endif

/**
 * \brief Creates a new XMPPStreamErrorException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that received the stream error
 * \param condition The defined error condition specified by the stream error
 * \param reason The descriptive free-form text specified by the stream error
 * \return A new XMPPStreamErrorException
 */
+ exceptionWithClass: (Class)class_
	  connection: (XMPPConnection*)connection
	   condition: (OFString*)condition
	      reason: (OFString*)reason;

/**
 * \brief Initializes an already allocated XMPPStreamErrorException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that received the stream error
 * \param condition The defined error condition specified by the stream error
 * \param reason The descriptive free-form text specified by the stream error
 * \return An initialized XMPPStreamErrorException
 */
- initWithClass: (Class)class_
     connection: (XMPPConnection*)connection
      condition: (OFString*)condition
	 reason: (OFString*)reason;

- (OFString*)condition;
- (OFString*)reason;
@end

/**
 * \brief An exception indicating a stringprep profile







<





<
|
|
|




<





<
|
|
|







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
/// \brief The descriptive free-form text specified by the stream error
@property (readonly, assign) OFString *reason;
#endif

/**
 * \brief Creates a new XMPPStreamErrorException.
 *

 * \param connection The connection that received the stream error
 * \param condition The defined error condition specified by the stream error
 * \param reason The descriptive free-form text specified by the stream error
 * \return A new XMPPStreamErrorException
 */

+ exceptionWithConnection: (XMPPConnection*)connection
		condition: (OFString*)condition
		   reason: (OFString*)reason;

/**
 * \brief Initializes an already allocated XMPPStreamErrorException.
 *

 * \param connection The connection that received the stream error
 * \param condition The defined error condition specified by the stream error
 * \param reason The descriptive free-form text specified by the stream error
 * \return An initialized XMPPStreamErrorException
 */

- initWithConnection: (XMPPConnection*)connection
	   condition: (OFString*)condition
	      reason: (OFString*)reason;

- (OFString*)condition;
- (OFString*)reason;
@end

/**
 * \brief An exception indicating a stringprep profile
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
/// \brief The string that failed the stringprep profile
@property (readonly, assign) OFString *string;
#endif

/**
 * \brief Creates a new XMPPStringPrepFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection the string relates to
 * \param profile The name of the stringprep profile that did not apply
 * \param string The string that failed the stringprep profile
 * \return A new XMPPStringPrepFailedException
 */
+ exceptionWithClass: (Class)class_
	  connection: (XMPPConnection*)connection
	     profile: (OFString*)profile
	      string: (OFString*)string;

/**
 * \brief Initializes an already allocated XMPPStringPrepFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection the string relates to
 * \param profile The name of the stringprep profile that did not apply
 * \param string The string that failed the stringprep profile
 * \return An initialized XMPPStringPrepFailedException
 */
- initWithClass: (Class)class_
     connection: (XMPPConnection*)connection
	profile: (OFString*)profile
	 string: (OFString*)string;

- (OFString*)profile;
- (OFString*)string;
@end

/**
 * \brief An exception indicating IDNA translation of a string failed







<





<
|
|
|




<





<
|
|
|







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
/// \brief The string that failed the stringprep profile
@property (readonly, assign) OFString *string;
#endif

/**
 * \brief Creates a new XMPPStringPrepFailedException.
 *

 * \param connection The connection the string relates to
 * \param profile The name of the stringprep profile that did not apply
 * \param string The string that failed the stringprep profile
 * \return A new XMPPStringPrepFailedException
 */

+ exceptionWithConnection: (XMPPConnection*)connection
		  profile: (OFString*)profile
		   string: (OFString*)string;

/**
 * \brief Initializes an already allocated XMPPStringPrepFailedException.
 *

 * \param connection The connection the string relates to
 * \param profile The name of the stringprep profile that did not apply
 * \param string The string that failed the stringprep profile
 * \return An initialized XMPPStringPrepFailedException
 */

- initWithConnection: (XMPPConnection*)connection
	     profile: (OFString*)profile
	      string: (OFString*)string;

- (OFString*)profile;
- (OFString*)string;
@end

/**
 * \brief An exception indicating IDNA translation of a string failed
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
/// \brief The string that could not be translated
@property (readonly, assign) OFString *string;
#endif

/**
 * \brief Creates a new XMPPIDNATranslationFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection the string relates to
 * \param operation The name of the stringprep profile that did not apply
 * \param string The string that could not be translated
 * \return A new XMPPIDNATranslationFailedException
 */
+ exceptionWithClass: (Class)class_
	  connection: (XMPPConnection*)connection
	   operation: (OFString*)operation
	      string: (OFString*)string;

/**
 * \brief Initializes an already allocated XMPPIDNATranslationFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection the string relates to
 * \param operation The name of the stringprep profile that did not apply
 * \param string The string that could not be translated
 * \return An initialized XMPPIDNATranslationFailedException
 */
- initWithClass: (Class)class_
     connection: (XMPPConnection*)connection
      operation: (OFString*)operation
	 string: (OFString*)string;

- (OFString*)operation;
- (OFString*)string;
@end

/**
 * \brief An exception indicating authentication failed







<





<
|
|
|




<





<
|
|
|







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
/// \brief The string that could not be translated
@property (readonly, assign) OFString *string;
#endif

/**
 * \brief Creates a new XMPPIDNATranslationFailedException.
 *

 * \param connection The connection the string relates to
 * \param operation The name of the stringprep profile that did not apply
 * \param string The string that could not be translated
 * \return A new XMPPIDNATranslationFailedException
 */

+ exceptionWithConnection: (XMPPConnection*)connection
		operation: (OFString*)operation
		   string: (OFString*)string;

/**
 * \brief Initializes an already allocated XMPPIDNATranslationFailedException.
 *

 * \param connection The connection the string relates to
 * \param operation The name of the stringprep profile that did not apply
 * \param string The string that could not be translated
 * \return An initialized XMPPIDNATranslationFailedException
 */

- initWithConnection: (XMPPConnection*)connection
	   operation: (OFString*)operation
	      string: (OFString*)string;

- (OFString*)operation;
- (OFString*)string;
@end

/**
 * \brief An exception indicating authentication failed
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
/// \brief The reason the authentication failed
@property (readonly, assign) OFString *reason;
#endif

/**
 * \brief Creates a new XMPPAuthFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that could not be authenticated
 * \param reason The reason the authentication failed
 * \return A new XMPPAuthFailedException
 */
+ exceptionWithClass: (Class)class_
	  connection: (XMPPConnection*)connection
	      reason: (OFString*)reason;

/**
 * \brief Initializes an already allocated XMPPAuthFailedException.
 *
 * \param class_ The class of the object which caused the exception
 * \param connection The connection that could not be authenticated
 * \param reason The reason the authentication failed
 * \return An initialized XMPPAuthFailedException
 */
- initWithClass: (Class)class_
     connection: (XMPPConnection*)connection
	 reason: (OFString*)reason;

- (OFString*)reason;
@end







<




<
|
|




<




<
|
|



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
/// \brief The reason the authentication failed
@property (readonly, assign) OFString *reason;
#endif

/**
 * \brief Creates a new XMPPAuthFailedException.
 *

 * \param connection The connection that could not be authenticated
 * \param reason The reason the authentication failed
 * \return A new XMPPAuthFailedException
 */

+ exceptionWithConnection: (XMPPConnection*)connection
		   reason: (OFString*)reason;

/**
 * \brief Initializes an already allocated XMPPAuthFailedException.
 *

 * \param connection The connection that could not be authenticated
 * \param reason The reason the authentication failed
 * \return An initialized XMPPAuthFailedException
 */

- initWithConnection: (XMPPConnection*)connection
	      reason: (OFString*)reason;

- (OFString*)reason;
@end

Modified src/XMPPExceptions.m from [8b80b6f458] to [376315cbbf].

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
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif



#import "XMPPExceptions.h"
#import "XMPPConnection.h"

@implementation XMPPException
+ exceptionWithClass: (Class)class
	  connection: (XMPPConnection*)connection
{
	return [[[self alloc] initWithClass: class
				 connection: connection] autorelease];
}

- initWithClass: (Class)class
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
{
	self = [super initWithClass: class];

	@try {
		_connection = [connection retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection release];

	[super dealloc];
}

- (XMPPConnection*)connection
{
	OF_GETTER(_connection, NO)
}
@end

@implementation XMPPStreamErrorException
+ exceptionWithClass: (Class)class
	  connection: (XMPPConnection*)connection
	   condition: (OFString*)condition
	      reason: (OFString*)reason;
{
	return [[[self alloc] initWithClass: class
				 connection: connection
				  condition: condition
				     reason: reason] autorelease];
}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
      condition: (OFString*)condition
	 reason: (OFString*)reason
{
	self = [super initWithClass: class
			 connection: connection];

	@try {
		_condition = [condition copy];
		_reason = [reason copy];
	} @catch (id e) {
		[self release];
		@throw e;








>
>




<
|

|
<


|

>
|
>
|
|
>
|
>


<
|

|




















|




<
|
|
|

|
<
|
|


<
|

>
|
>
|
|
>
|
>


<
|
|
|

|
<







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
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#import "XMPPExceptions.h"
#import "XMPPConnection.h"

@implementation XMPPException

+ exceptionWithConnection: (XMPPConnection*)connection
{
	return [[[self alloc] initWithConnection: connection] autorelease];

}

- init
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}


- initWithConnection: (XMPPConnection*)connection
{
	self = [super init];

	@try {
		_connection = [connection retain];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_connection release];

	[super dealloc];
}

- (XMPPConnection*)connection
{
	OF_GETTER(_connection, false)
}
@end

@implementation XMPPStreamErrorException

+ exceptionWithConnection: (XMPPConnection*)connection
		condition: (OFString*)condition
		   reason: (OFString*)reason;
{
	return [[[self alloc] initWithConnection: connection

				       condition: condition
					  reason: reason] autorelease];
}


- initWithConnection: (XMPPConnection*)connection
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}


- initWithConnection: (XMPPConnection*)connection
	   condition: (OFString*)condition
	      reason: (OFString*)reason
{
	self = [super initWithConnection: connection];


	@try {
		_condition = [condition copy];
		_reason = [reason copy];
	} @catch (id e) {
		[self release];
		@throw e;
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

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"Got stream error in class %@: %@. Reason: %@!", [self inClass],
	    _condition, _reason];
}

- (OFString*)condition
{
	OF_GETTER(_condition, NO)
}

- (OFString*)reason
{
	OF_GETTER(_reason, NO)
}
@end

@implementation XMPPStringPrepFailedException
+ exceptionWithClass: (Class)class
	  connection: (XMPPConnection*)connection
	     profile: (OFString*)profile
	      string: (OFString*)string
{
	return [[[self alloc] initWithClass: class
				 connection: connection
				    profile: profile
				     string: string] autorelease];
}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
	profile: (OFString*)profile
	 string: (OFString*)string
{
	self = [super initWithClass: class
			 connection: connection];

	@try {
		_profile = [profile copy];
		_string = [string copy];
	} @catch (id e) {
		[self release];
		@throw e;







<
|




|




|




<
|
|
|

|
<
|
|


<
|

>
|
>
|
|
>
|
>


<
|
|
|

|
<







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

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:

	    @"Got stream error: %@. Reason: %@!", _condition, _reason];
}

- (OFString*)condition
{
	OF_GETTER(_condition, false)
}

- (OFString*)reason
{
	OF_GETTER(_reason, false)
}
@end

@implementation XMPPStringPrepFailedException

+ exceptionWithConnection: (XMPPConnection*)connection
		  profile: (OFString*)profile
		   string: (OFString*)string
{
	return [[[self alloc] initWithConnection: connection

					 profile: profile
					  string: string] autorelease];
}


- initWithConnection: (XMPPConnection*)connection
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}


- initWithConnection: (XMPPConnection*)connection
	     profile: (OFString*)profile
	      string: (OFString*)string
{
	self = [super initWithConnection: connection];


	@try {
		_profile = [profile copy];
		_string = [string copy];
	} @catch (id e) {
		[self release];
		@throw e;
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

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"Stringprep with profile %@ failed in class %@ on string '%@'!",
	    _profile, [self inClass], _string];
}

- (OFString*)profile
{
	OF_GETTER(_profile, NO)
}

- (OFString*)string
{
	OF_GETTER(_string, NO)
}
@end

@implementation XMPPIDNATranslationFailedException
+ exceptionWithClass: (Class)class
	  connection: (XMPPConnection*)connection
	   operation: (OFString*)operation
	      string: (OFString*)string
{
	return [[[self alloc] initWithClass: class
				 connection: connection
				  operation: operation
				     string: string] autorelease];
}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
      operation: (OFString*)operation
	 string: (OFString*)string
{
	self = [super initWithClass: class
			 connection: connection];

	@try {
		_operation = [operation copy];
		_string = [string copy];
	} @catch (id e) {
		[self release];
		@throw e;







|
|




|




|




<
|
|
|

|
<
|
|


<
|

>
|
>
|
|
>
|
>


<
|
|
|

|
<







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

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"Stringprep with profile %@ failed on string '%@'!",
	    _profile, _string];
}

- (OFString*)profile
{
	OF_GETTER(_profile, false)
}

- (OFString*)string
{
	OF_GETTER(_string, false)
}
@end

@implementation XMPPIDNATranslationFailedException

+ exceptionWithConnection: (XMPPConnection*)connection
		operation: (OFString*)operation
		   string: (OFString*)string
{
	return [[[self alloc] initWithConnection: connection

				       operation: operation
					  string: string] autorelease];
}


- initWithConnection: (XMPPConnection*)connection
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}


- initWithConnection: (XMPPConnection*)connection
	   operation: (OFString*)operation
	      string: (OFString*)string
{
	self = [super initWithConnection: connection];


	@try {
		_operation = [operation copy];
		_string = [string copy];
	} @catch (id e) {
		[self release];
		@throw e;
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284

285

286
287

288

289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"IDNA operation %@ failed in class %@ on string '%@'!", _operation,
	    [self inClass], _string];
}

- (OFString*)operation
{
	OF_GETTER(_operation, NO)
}

- (OFString*)string
{
	OF_GETTER(_string, NO)
}
@end

@implementation XMPPAuthFailedException
+ exceptionWithClass: (Class)class
	  connection: (XMPPConnection*)connection
	      reason: (OFString*)reason;
{
	return [[[self alloc] initWithClass: class
				 connection: connection
				     reason: reason] autorelease];
}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithClass: (Class)class
     connection: (XMPPConnection*)connection
	 reason: (OFString*)reason
{
	self = [super initWithClass: class
			 connection: connection];

	@try {
		_reason = [reason copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}







|
<




|




|




<
|
|

|
<
|


<
|

>
|
>
|
|
>
|
>


<
|
|

|
<







249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272
273
274

275
276
277

278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293

294
295
296
297
298
299
300

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"IDNA operation %@ failed on string '%@'!", _operation, _string];

}

- (OFString*)operation
{
	OF_GETTER(_operation, false)
}

- (OFString*)string
{
	OF_GETTER(_string, false)
}
@end

@implementation XMPPAuthFailedException

+ exceptionWithConnection: (XMPPConnection*)connection
		   reason: (OFString*)reason;
{
	return [[[self alloc] initWithConnection: connection

					  reason: reason] autorelease];
}


- initWithConnection: (XMPPConnection*)connection
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}


- initWithConnection: (XMPPConnection*)connection
	      reason: (OFString*)reason
{
	self = [super initWithConnection: connection];


	@try {
		_reason = [reason copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"Authentication failed in class %@. Reason: %@!", [self inClass],
	    _reason];
}

- (OFString*)reason
{
	OF_GETTER(_reason, NO)
}
@end







|
<




|


308
309
310
311
312
313
314
315

316
317
318
319
320
321
322

	[super dealloc];
}

- (OFString*)description
{
	return [OFString stringWithFormat:
	    @"Authentication failed. Reason: %@!", _reason];

}

- (OFString*)reason
{
	OF_GETTER(_reason, false)
}
@end

Modified src/XMPPFileStorage.m from [b5f01ad0ba] to [e283a67940].

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
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif



#import <ObjFW/OFString.h>
#import <ObjFW/OFArray.h>
#import <ObjFW/OFDictionary.h>
#import <ObjFW/OFNumber.h>
#import <ObjFW/OFDataArray.h>
#import <ObjFW/OFAutoreleasePool.h>

#import <ObjFW/OFNotImplementedException.h>

#import "XMPPFileStorage.h"

@implementation XMPPFileStorage
- init
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithFile: (OFString*)file
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [OFAutoreleasePool new];

		_file = [file copy];
		@try {
			_data = [[[OFDataArray dataArrayWithContentsOfFile:
			    file] binaryPackValue] retain];
		} @catch (id e) {
			_data = [OFMutableDictionary new];
		}

		[pool release];
	} @catch (id e) {
		[self release];







>
>















>
|
>
|
|
>
|
>












|







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
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#import <ObjFW/OFString.h>
#import <ObjFW/OFArray.h>
#import <ObjFW/OFDictionary.h>
#import <ObjFW/OFNumber.h>
#import <ObjFW/OFDataArray.h>
#import <ObjFW/OFAutoreleasePool.h>

#import <ObjFW/OFNotImplementedException.h>

#import "XMPPFileStorage.h"

@implementation XMPPFileStorage
- init
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}

- initWithFile: (OFString*)file
{
	self = [super init];

	@try {
		OFAutoreleasePool *pool = [OFAutoreleasePool new];

		_file = [file copy];
		@try {
			_data = [[[OFDataArray dataArrayWithContentsOfFile:
			    file] messagePackValue] retain];
		} @catch (id e) {
			_data = [OFMutableDictionary new];
		}

		[pool release];
	} @catch (id e) {
		[self release];
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
	[_data release];

	[super dealloc];
}

- (void)save
{
	[[_data binaryPackRepresentation] writeToFile: _file];
}

- (void)XMPP_setObject: (id)object
	       forPath: (OFString*)path
{
	OFArray *pathComponents = [path componentsSeparatedByString: @"."];
	OFMutableDictionary *iter = _data;







|







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
	[_data release];

	[super dealloc];
}

- (void)save
{
	[[_data messagePackRepresentation] writeToFile: _file];
}

- (void)XMPP_setObject: (id)object
	       forPath: (OFString*)path
{
	OFArray *pathComponents = [path componentsSeparatedByString: @"."];
	OFMutableDictionary *iter = _data;

Modified src/XMPPIQ.m from [56a714ea1b] to [08cee60ca1].

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	self = [super initWithName: @"iq"
			      type: type
				ID: ID];

	@try {
		if (![type isEqual: @"get"] && ![type isEqual: @"set"] &&
		    ![type isEqual: @"result"] && ![type isEqual: @"error"])
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







|
<
<







42
43
44
45
46
47
48
49


50
51
52
53
54
55
56
	self = [super initWithName: @"iq"
			      type: type
				ID: ID];

	@try {
		if (![type isEqual: @"get"] && ![type isEqual: @"set"] &&
		    ![type isEqual: @"result"] && ![type isEqual: @"error"])
			@throw [OFInvalidArgumentException exception];


	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

Modified src/XMPPJID.m from [70fd287265] to [9c61bb91d6].

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
		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);
	}








<
|
|
|







115
116
117
118
119
120
121

122
123
124
125
126
127
128
129
130
131
		return;
	}

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

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

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	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);
	}








<
|
|
|







143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
	char *srv;
	Stringprep_rc rc;

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

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

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
		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);
	}








<
|
|
|







177
178
179
180
181
182
183

184
185
186
187
188
189
190
191
192
193
		return;
	}

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

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

Modified src/XMPPPresence.m from [cd7ef53266] to [71bd226691].

180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
}

- (void)setPriority: (OFNumber*)priority
{
	intmax_t prio = [priority intMaxValue];

	if ((prio < -128) || (prio > 127))
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	OFXMLElement *oldPriority = [self elementForName: @"priority"
					       namespace: XMPP_NS_CLIENT];

	if (oldPriority != nil)
		[self removeChild: oldPriority];








|
<
<







180
181
182
183
184
185
186
187


188
189
190
191
192
193
194
}

- (void)setPriority: (OFNumber*)priority
{
	intmax_t prio = [priority intMaxValue];

	if ((prio < -128) || (prio > 127))
		@throw [OFInvalidArgumentException exception];



	OFXMLElement *oldPriority = [self elementForName: @"priority"
					       namespace: XMPP_NS_CLIENT];

	if (oldPriority != nil)
		[self removeChild: oldPriority];

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
	OFString *otherShow;
	of_comparison_result_t priorityOrder;

	if (object == self)
		return OF_ORDERED_SAME;

	if (![object isKindOfClass: [XMPPPresence class]])
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	otherPresence = (XMPPPresence*)object;
	otherPriority = [otherPresence priority];
	if (otherPriority == nil)
		otherPriority = [OFNumber numberWithInt8: 0];

	if (_priority != nil)







|
<
<







213
214
215
216
217
218
219
220


221
222
223
224
225
226
227
	OFString *otherShow;
	of_comparison_result_t priorityOrder;

	if (object == self)
		return OF_ORDERED_SAME;

	if (![object isKindOfClass: [XMPPPresence class]])
		@throw [OFInvalidArgumentException exception];



	otherPresence = (XMPPPresence*)object;
	otherPriority = [otherPresence priority];
	if (otherPriority == nil)
		otherPriority = [OFNumber numberWithInt8: 0];

	if (_priority != nil)

Modified src/XMPPRoster.m from [1fa0d01ca6] to [265f350014].

209
210
211
212
213
214
215

216
217
218
219
220
221
222
223
224
{
	[_delegates removeDelegate: delegate];
}

- (void)setDataStorage: (id <XMPPStorage>)dataStorage
{
	if (_rosterRequested)

		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]];

	_dataStorage = dataStorage;
}

- (XMPPConnection*)connection
{
	return _connection;







>
|
<







209
210
211
212
213
214
215
216
217

218
219
220
221
222
223
224
{
	[_delegates removeDelegate: delegate];
}

- (void)setDataStorage: (id <XMPPStorage>)dataStorage
{
	if (_rosterRequested)
		/* FIXME: Find a better exception! */
		@throw [OFInvalidArgumentException exception];


	_dataStorage = dataStorage;
}

- (XMPPConnection*)connection
{
	return _connection;

Modified src/XMPPSCRAMAuth.m from [f160b76a65] to [764a5f4df5].

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
	else
		_GS2Header = (_plusAvailable ? @"p=tls-unique,," : @"y,,");

	_cNonce = [[self XMPP_genNonce] retain];

	[_clientFirstMessageBare release];
	_clientFirstMessageBare = nil;
	_clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@",
								   _authcid,
								   _cNonce];

	[ret addItems: [_GS2Header UTF8String]
		count: [_GS2Header UTF8StringLength]];

	[ret addItems: [_clientFirstMessageBare UTF8String]
		count: [_clientFirstMessageBare UTF8StringLength]];








|
|
<







164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
	else
		_GS2Header = (_plusAvailable ? @"p=tls-unique,," : @"y,,");

	_cNonce = [[self XMPP_genNonce] retain];

	[_clientFirstMessageBare release];
	_clientFirstMessageBare = nil;
	_clientFirstMessageBare = [[OFString alloc]
	    initWithFormat: @"n=%@,r=%@", _authcid, _cNonce];


	[ret addItems: [_GS2Header UTF8String]
		count: [_GS2Header UTF8StringLength]];

	[ret addItems: [_clientFirstMessageBare UTF8String]
		count: [_clientFirstMessageBare UTF8StringLength]];

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
253
254
255
256
257
258
259
	while ((comp = [enumerator nextObject]) != nil) {
		OFString *entry = [comp substringWithRange:
		    of_range(2, [comp length] - 2)];

		if ([comp hasPrefix: @"r="]) {
			if (![entry hasPrefix: _cNonce])
				@throw [XMPPAuthFailedException
				    exceptionWithClass: [self class]
					    connection: nil
						reason: @"Received wrong "
							@"nonce"];

			sNonce = entry;
			got |= GOT_SNONCE;
		} else if ([comp hasPrefix: @"s="]) {
			salt = [OFDataArray
			    dataArrayWithBase64EncodedString: entry];
			got |= GOT_SALT;
		} else if ([comp hasPrefix: @"i="]) {
			iterCount = [entry decimalValue];
			got |= GOT_ITERCOUNT;
		}
	}

	if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
		@throw [OFInvalidServerReplyException
		    exceptionWithClass: [self class]];

	// Add c=<base64(GS2Header+channelBindingData)>
	tmpArray = [OFDataArray dataArray];
	[tmpArray addItems: [_GS2Header UTF8String]
		     count: [_GS2Header UTF8StringLength]];
	if (_plusAvailable && [_connection encrypted]) {
		OFDataArray *channelBinding = [((SSLSocket*)[_connection socket])







<
|
|
|














|
<







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
253
254
255
256
	while ((comp = [enumerator nextObject]) != nil) {
		OFString *entry = [comp substringWithRange:
		    of_range(2, [comp length] - 2)];

		if ([comp hasPrefix: @"r="]) {
			if (![entry hasPrefix: _cNonce])
				@throw [XMPPAuthFailedException

				    exceptionWithConnection: nil
						     reason: @"Received wrong "
							     @"nonce"];

			sNonce = entry;
			got |= GOT_SNONCE;
		} else if ([comp hasPrefix: @"s="]) {
			salt = [OFDataArray
			    dataArrayWithBase64EncodedString: entry];
			got |= GOT_SALT;
		} else if ([comp hasPrefix: @"i="]) {
			iterCount = [entry decimalValue];
			got |= GOT_ITERCOUNT;
		}
	}

	if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
		@throw [OFInvalidServerReplyException exception];


	// Add c=<base64(GS2Header+channelBindingData)>
	tmpArray = [OFDataArray dataArray];
	[tmpArray addItems: [_GS2Header UTF8String]
		     count: [_GS2Header UTF8StringLength]];
	if (_plusAvailable && [_connection encrypted]) {
		OFDataArray *channelBinding = [((SSLSocket*)[_connection socket])
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
				       length: [data count] *
					       [data itemSize]];
	value = [mess substringWithRange: of_range(2, [mess length] - 2)];

	if ([mess hasPrefix: @"v="]) {
		if (![value isEqual: [_serverSignature stringByBase64Encoding]])
			@throw [XMPPAuthFailedException
			    exceptionWithClass: [self class]
				    connection: nil
					reason: @"Received wrong "
						@"ServerSignature"];
		_authenticated = YES;
	} else
		@throw [XMPPAuthFailedException exceptionWithClass: [self class]
							connection: nil
							    reason: value];

	return nil;
}

- (OFString*)XMPP_genNonce
{
	uint8_t buf[64];







<
|
|
|


|
<
|







383
384
385
386
387
388
389

390
391
392
393
394
395

396
397
398
399
400
401
402
403
				       length: [data count] *
					       [data itemSize]];
	value = [mess substringWithRange: of_range(2, [mess length] - 2)];

	if ([mess hasPrefix: @"v="]) {
		if (![value isEqual: [_serverSignature stringByBase64Encoding]])
			@throw [XMPPAuthFailedException

			    exceptionWithConnection: nil
					     reason: @"Received wrong "
						     @"ServerSignature"];
		_authenticated = YES;
	} else
		@throw [XMPPAuthFailedException exceptionWithConnection: nil

								 reason: value];

	return nil;
}

- (OFString*)XMPP_genNonce
{
	uint8_t buf[64];

Modified src/XMPPSRVLookup.m from [dde19bea60] to [54b7d6a8f6].

21
22
23
24
25
26
27


28
29
30
31
32
33
34
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif



#include <assert.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <openssl/rand.h>








>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#include <assert.h>

#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <openssl/rand.h>

51
52
53
54
55
56
57

58

59
60

61

62
63
64
65
66
67
68
{
	return [[[self alloc] initWithResourceRecord: resourceRecord
					      handle: handle] autorelease];
}

- init
{

	Class c = [self class];

	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c

						    selector: _cmd];

}

- initWithPriority: (uint16_t)priority
	    weight: (uint16_t)weight
	      port: (uint16_t)port
	    target: (OFString*)target
{







>
|
>
|
|
>
|
>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
{
	return [[[self alloc] initWithResourceRecord: resourceRecord
					      handle: handle] autorelease];
}

- init
{
	@try {
		[self doesNotRecognizeSelector: _cmd];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	abort();
}

- initWithPriority: (uint16_t)priority
	    weight: (uint16_t)weight
	      port: (uint16_t)port
	    target: (OFString*)target
{
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
	@try {
		int answerLen, resourceRecordCount, i;
		ns_rr resourceRecord;
		ns_msg handle;

		if (res_ninit(&_resState))
			@throw [OFAddressTranslationFailedException
			    exceptionWithClass: [self class]
					socket: nil
					  host: _domain];

		answer = [self allocMemoryWithSize: pageSize];
		answerLen = res_nsearch(&_resState,
		    [request cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
		    ns_c_in, ns_t_srv, answer, (int)pageSize);

		if ((answerLen == -1) && ((h_errno == HOST_NOT_FOUND) ||
		    (h_errno == NO_DATA)))
			return;

		if (answerLen < 1 || answerLen > pageSize) {
			@throw [OFAddressTranslationFailedException
			    exceptionWithClass: [self class]
					socket: nil
					  host: _domain];
		}

		if (ns_initparse(answer, answerLen, &handle))
			@throw [OFAddressTranslationFailedException
			    exceptionWithClass: [self class]
					socket: nil
					  host: _domain];

		resourceRecordCount = ns_msg_count(handle, ns_s_an);
		for (i = 0; i < resourceRecordCount; i++) {
			if (ns_parserr(&handle, ns_s_an, i, &resourceRecord))
				continue;

			if (ns_rr_type(resourceRecord) != ns_t_srv ||







<
<
|










|

<
<
|
<



<
<
|







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
	@try {
		int answerLen, resourceRecordCount, i;
		ns_rr resourceRecord;
		ns_msg handle;

		if (res_ninit(&_resState))
			@throw [OFAddressTranslationFailedException


			    exceptionWithHost: _domain];

		answer = [self allocMemoryWithSize: pageSize];
		answerLen = res_nsearch(&_resState,
		    [request cStringWithEncoding: OF_STRING_ENCODING_NATIVE],
		    ns_c_in, ns_t_srv, answer, (int)pageSize);

		if ((answerLen == -1) && ((h_errno == HOST_NOT_FOUND) ||
		    (h_errno == NO_DATA)))
			return;

		if (answerLen < 1 || answerLen > pageSize)
			@throw [OFAddressTranslationFailedException


			    exceptionWithHost: _domain];


		if (ns_initparse(answer, answerLen, &handle))
			@throw [OFAddressTranslationFailedException


			    exceptionWithHost: _domain];

		resourceRecordCount = ns_msg_count(handle, ns_s_an);
		for (i = 0; i < resourceRecordCount; i++) {
			if (ns_parserr(&handle, ns_s_an, i, &resourceRecord))
				continue;

			if (ns_rr_type(resourceRecord) != ns_t_srv ||

Modified src/XMPPStanza.m from [8ed21f56f2] to [bb69e66d09].

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
	self = [super initWithName: name
			 namespace: XMPP_NS_CLIENT];

	@try {
		if (![name isEqual: @"iq"] && ![name isEqual: @"message"] &&
		    ![name isEqual: @"presence"])
			@throw [OFInvalidArgumentException
			    exceptionWithClass: [self class]
				      selector: _cmd];

		[self setDefaultNamespace: XMPP_NS_CLIENT];
		[self setPrefix: @"stream"
		   forNamespace: XMPP_NS_STREAM];

		if (type != nil)
			[self setType: type];







|
<
<







92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
{
	self = [super initWithName: name
			 namespace: XMPP_NS_CLIENT];

	@try {
		if (![name isEqual: @"iq"] && ![name isEqual: @"message"] &&
		    ![name isEqual: @"presence"])
			@throw [OFInvalidArgumentException exception];



		[self setDefaultNamespace: XMPP_NS_CLIENT];
		[self setPrefix: @"stream"
		   forNamespace: XMPP_NS_STREAM];

		if (type != nil)
			[self setType: type];

Modified src/XMPPXMLElementBuilder.m from [2fa5bac2f8] to [a9f23e26ed].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#import <ObjFW/OFMalformedXMLException.h>

@implementation XMPPXMLElementBuilder
-		 (void)parser: (OFXMLParser*)parser
  foundProcessingInstructions: (OFString*)pi
{
	@throw [OFMalformedXMLException exceptionWithClass: [self class]];
}

- (void)parser: (OFXMLParser*)parser
  foundComment: (OFString*)comment
{
	@throw [OFMalformedXMLException exceptionWithClass: [self class]];
}
@end







|





|


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#import <ObjFW/OFMalformedXMLException.h>

@implementation XMPPXMLElementBuilder
-		 (void)parser: (OFXMLParser*)parser
  foundProcessingInstructions: (OFString*)pi
{
	@throw [OFMalformedXMLException exception];
}

- (void)parser: (OFXMLParser*)parser
  foundComment: (OFString*)comment
{
	@throw [OFMalformedXMLException exception];
}
@end