Adjust to reworked exception API.

This commit is contained in:
Jonathan Schleifer 2013-06-23 16:17:39 +02:00
parent bfdfabcf40
commit 7f5c58ffc7
14 changed files with 224 additions and 270 deletions

View file

@ -171,10 +171,9 @@
if ((rc = stringprep_profile([username UTF8String], &node, if ((rc = stringprep_profile([username UTF8String], &node,
"SASLprep", 0)) != STRINGPREP_OK) "SASLprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self profile: @"SASLprep"
profile: @"SASLprep" string: username];
string: username];
@try { @try {
_username = [[OFString alloc] initWithUTF8String: node]; _username = [[OFString alloc] initWithUTF8String: node];
@ -203,10 +202,9 @@
if ((rc = stringprep_profile([resource UTF8String], &res, if ((rc = stringprep_profile([resource UTF8String], &res,
"Resourceprep", 0)) != STRINGPREP_OK) "Resourceprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self profile: @"Resourceprep"
profile: @"Resourceprep" string: resource];
string: resource];
@try { @try {
_resource = [[OFString alloc] initWithUTF8String: res]; _resource = [[OFString alloc] initWithUTF8String: res];
@ -253,10 +251,9 @@
if ((rc = stringprep_profile([domain_ UTF8String], &srv, if ((rc = stringprep_profile([domain_ UTF8String], &srv,
"Nameprep", 0)) != STRINGPREP_OK) "Nameprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self profile: @"Nameprep"
profile: @"Nameprep" string: domain_];
string: domain_];
@try { @try {
_domain = [[OFString alloc] initWithUTF8String: srv]; _domain = [[OFString alloc] initWithUTF8String: srv];
@ -290,10 +287,9 @@
if ((rc = stringprep_profile([password UTF8String], &pass, if ((rc = stringprep_profile([password UTF8String], &pass,
"SASLprep", 0)) != STRINGPREP_OK) "SASLprep", 0)) != STRINGPREP_OK)
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self profile: @"SASLprep"
profile: @"SASLprep" string: password];
string: password];
@try { @try {
_password = [[OFString alloc] initWithUTF8String: pass]; _password = [[OFString alloc] initWithUTF8String: pass];
@ -339,8 +335,7 @@
OFEnumerator *enumerator; OFEnumerator *enumerator;
if (_socket != nil) if (_socket != nil)
@throw [OFAlreadyConnectedException @throw [OFAlreadyConnectedException exception];
exceptionWithClass: [self class]];
_socket = [[OFTCPSocket alloc] init]; _socket = [[OFTCPSocket alloc] init];
@ -691,9 +686,7 @@
{ {
if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] || if (![name isEqual: @"stream"] || ![prefix isEqual: @"stream"] ||
![ns isEqual: XMPP_NS_STREAM]) ![ns isEqual: XMPP_NS_STREAM])
@throw [OFMalformedXMLException @throw [OFMalformedXMLException exception];
exceptionWithClass: [builder class]
parser: nil];
else { else {
[self close]; [self close];
} }
@ -873,10 +866,9 @@
namespace: XMPP_NS_XMPP_STREAM] stringValue]; namespace: XMPP_NS_XMPP_STREAM] stringValue];
@throw [XMPPStreamErrorException @throw [XMPPStreamErrorException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self condition: condition
condition: condition reason: reason];
reason: reason];
return; return;
} }
@ -915,7 +907,7 @@
if ([[element name] isEqual: @"failure"]) if ([[element name] isEqual: @"failure"])
/* TODO: Find/create an exception to throw here */ /* TODO: Find/create an exception to throw here */
@throw [OFException exceptionWithClass: [self class]]; @throw [OFException exception];
assert(0); assert(0);
} }
@ -961,9 +953,8 @@
of_log(@"Auth failed!"); of_log(@"Auth failed!");
// FIXME: Do more parsing/handling // FIXME: Do more parsing/handling
@throw [XMPPAuthFailedException @throw [XMPPAuthFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self reason: [element XMLString]];
reason: [element XMLString]];
} }
assert(0); assert(0);
@ -1028,7 +1019,7 @@
if (_encryptionRequired && !_encrypted) if (_encryptionRequired && !_encrypted)
/* TODO: Find/create an exception to throw here */ /* TODO: Find/create an exception to throw here */
@throw [OFException exceptionWithClass: [self class]]; @throw [OFException exception];
if ([element elementForName: @"ver" if ([element elementForName: @"ver"
namespace: XMPP_NS_ROSTERVER] != nil) namespace: XMPP_NS_ROSTERVER] != nil)
@ -1221,10 +1212,9 @@
if ((rc = idna_to_ascii_8z([domain_ UTF8String], if ((rc = idna_to_ascii_8z([domain_ UTF8String],
&cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS) &cDomain, IDNA_USE_STD3_ASCII_RULES)) != IDNA_SUCCESS)
@throw [XMPPIDNATranslationFailedException @throw [XMPPIDNATranslationFailedException
exceptionWithClass: [self class] exceptionWithConnection: self
connection: self operation: @"ToASCII"
operation: @"ToASCII" string: domain_];
string: domain_];
@try { @try {
ret = [[OFString alloc] initWithUTF8String: cDomain]; ret = [[OFString alloc] initWithUTF8String: cDomain];
@ -1253,8 +1243,8 @@
- (void)setDataStorage: (id <XMPPStorage>)dataStorage - (void)setDataStorage: (id <XMPPStorage>)dataStorage
{ {
if (_streamOpen) if (_streamOpen)
@throw [OFInvalidArgumentException /* FIXME: Find a better exception! */
exceptionWithClass: [self class]]; @throw [OFInvalidArgumentException exception];
_dataStorage = dataStorage; _dataStorage = dataStorage;
} }

View file

@ -47,9 +47,7 @@
@try { @try {
if (category == nil || type == nil) if (category == nil || type == nil)
@throw [OFInvalidArgumentException @throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
_category = [category copy]; _category = [category copy];
_name = [name copy]; _name = [name copy];
@ -151,9 +149,7 @@
return OF_ORDERED_SAME; return OF_ORDERED_SAME;
if (![object isKindOfClass: [XMPPDiscoIdentity class]]) if (![object isKindOfClass: [XMPPDiscoIdentity class]])
@throw [OFInvalidArgumentException @throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
identity = (XMPPDiscoIdentity*)object; identity = (XMPPDiscoIdentity*)object;

View file

@ -60,8 +60,11 @@
self = [super init]; self = [super init];
@try { @try {
if (JID == nil)
@throw [OFInvalidArgumentException exception];
_JID = [JID copy]; _JID = [JID copy];
_node= [node copy]; _node = [node copy];
_name = [name copy]; _name = [name copy];
_identities = [OFSortedList new]; _identities = [OFSortedList new];
_features = [OFSortedList new]; _features = [OFSortedList new];

View file

@ -41,24 +41,20 @@
/** /**
* \brief Creates a new XMPPException. * \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 * \param connection The connection that received the data responsible
* for this exception * for this exception
* \return A new XMPPException * \return A new XMPPException
*/ */
+ exceptionWithClass: (Class)class_ + exceptionWithConnection: (XMPPConnection*)connection;
connection: (XMPPConnection*)connection;
/** /**
* \brief Initializes an already allocated XMPPException. * \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 * \param connection The connection that received the data responsible
* for this exception * for this exception
* \return An initialized XMPPException * \return An initialized XMPPException
*/ */
- initWithClass: (Class)class_ - initWithConnection: (XMPPConnection*)connection;
connection: (XMPPConnection*)connection;
- (XMPPConnection*)connection; - (XMPPConnection*)connection;
@end @end
@ -82,30 +78,26 @@
/** /**
* \brief Creates a new XMPPStreamErrorException. * \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 connection The connection that received the stream error
* \param condition The defined error condition specified by 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 * \param reason The descriptive free-form text specified by the stream error
* \return A new XMPPStreamErrorException * \return A new XMPPStreamErrorException
*/ */
+ exceptionWithClass: (Class)class_ + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection condition: (OFString*)condition
condition: (OFString*)condition reason: (OFString*)reason;
reason: (OFString*)reason;
/** /**
* \brief Initializes an already allocated XMPPStreamErrorException. * \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 connection The connection that received the stream error
* \param condition The defined error condition specified by 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 * \param reason The descriptive free-form text specified by the stream error
* \return An initialized XMPPStreamErrorException * \return An initialized XMPPStreamErrorException
*/ */
- initWithClass: (Class)class_ - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection condition: (OFString*)condition
condition: (OFString*)condition reason: (OFString*)reason;
reason: (OFString*)reason;
- (OFString*)condition; - (OFString*)condition;
- (OFString*)reason; - (OFString*)reason;
@ -131,30 +123,26 @@
/** /**
* \brief Creates a new XMPPStringPrepFailedException. * \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 connection The connection the string relates to
* \param profile The name of the stringprep profile that did not apply * \param profile The name of the stringprep profile that did not apply
* \param string The string that failed the stringprep profile * \param string The string that failed the stringprep profile
* \return A new XMPPStringPrepFailedException * \return A new XMPPStringPrepFailedException
*/ */
+ exceptionWithClass: (Class)class_ + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection profile: (OFString*)profile
profile: (OFString*)profile string: (OFString*)string;
string: (OFString*)string;
/** /**
* \brief Initializes an already allocated XMPPStringPrepFailedException. * \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 connection The connection the string relates to
* \param profile The name of the stringprep profile that did not apply * \param profile The name of the stringprep profile that did not apply
* \param string The string that failed the stringprep profile * \param string The string that failed the stringprep profile
* \return An initialized XMPPStringPrepFailedException * \return An initialized XMPPStringPrepFailedException
*/ */
- initWithClass: (Class)class_ - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection profile: (OFString*)profile
profile: (OFString*)profile string: (OFString*)string;
string: (OFString*)string;
- (OFString*)profile; - (OFString*)profile;
- (OFString*)string; - (OFString*)string;
@ -179,30 +167,26 @@
/** /**
* \brief Creates a new XMPPIDNATranslationFailedException. * \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 connection The connection the string relates to
* \param operation The name of the stringprep profile that did not apply * \param operation The name of the stringprep profile that did not apply
* \param string The string that could not be translated * \param string The string that could not be translated
* \return A new XMPPIDNATranslationFailedException * \return A new XMPPIDNATranslationFailedException
*/ */
+ exceptionWithClass: (Class)class_ + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection operation: (OFString*)operation
operation: (OFString*)operation string: (OFString*)string;
string: (OFString*)string;
/** /**
* \brief Initializes an already allocated XMPPIDNATranslationFailedException. * \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 connection The connection the string relates to
* \param operation The name of the stringprep profile that did not apply * \param operation The name of the stringprep profile that did not apply
* \param string The string that could not be translated * \param string The string that could not be translated
* \return An initialized XMPPIDNATranslationFailedException * \return An initialized XMPPIDNATranslationFailedException
*/ */
- initWithClass: (Class)class_ - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection operation: (OFString*)operation
operation: (OFString*)operation string: (OFString*)string;
string: (OFString*)string;
- (OFString*)operation; - (OFString*)operation;
- (OFString*)string; - (OFString*)string;
@ -224,26 +208,22 @@
/** /**
* \brief Creates a new XMPPAuthFailedException. * \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 connection The connection that could not be authenticated
* \param reason The reason the authentication failed * \param reason The reason the authentication failed
* \return A new XMPPAuthFailedException * \return A new XMPPAuthFailedException
*/ */
+ exceptionWithClass: (Class)class_ + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection reason: (OFString*)reason;
reason: (OFString*)reason;
/** /**
* \brief Initializes an already allocated XMPPAuthFailedException. * \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 connection The connection that could not be authenticated
* \param reason The reason the authentication failed * \param reason The reason the authentication failed
* \return An initialized XMPPAuthFailedException * \return An initialized XMPPAuthFailedException
*/ */
- initWithClass: (Class)class_ - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection reason: (OFString*)reason;
reason: (OFString*)reason;
- (OFString*)reason; - (OFString*)reason;
@end @end

View file

@ -24,29 +24,32 @@
# include "config.h" # include "config.h"
#endif #endif
#include <stdlib.h>
#import "XMPPExceptions.h" #import "XMPPExceptions.h"
#import "XMPPConnection.h" #import "XMPPConnection.h"
@implementation XMPPException @implementation XMPPException
+ exceptionWithClass: (Class)class + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection
{ {
return [[[self alloc] initWithClass: class return [[[self alloc] initWithConnection: connection] autorelease];
connection: connection] autorelease];
} }
- initWithClass: (Class)class - init
{ {
Class c = [self class]; @try {
[self release]; [self doesNotRecognizeSelector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c } @catch (id e) {
selector: _cmd]; [self release];
@throw e;
}
abort();
} }
- initWithClass: (Class)class - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection
{ {
self = [super initWithClass: class]; self = [super init];
@try { @try {
_connection = [connection retain]; _connection = [connection retain];
@ -67,38 +70,37 @@
- (XMPPConnection*)connection - (XMPPConnection*)connection
{ {
OF_GETTER(_connection, NO) OF_GETTER(_connection, false)
} }
@end @end
@implementation XMPPStreamErrorException @implementation XMPPStreamErrorException
+ exceptionWithClass: (Class)class + exceptionWithConnection: (XMPPConnection*)connection
connection: (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 condition: (OFString*)condition
reason: (OFString*)reason; reason: (OFString*)reason
{ {
return [[[self alloc] initWithClass: class self = [super initWithConnection: connection];
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 { @try {
_condition = [condition copy]; _condition = [condition copy];
@ -122,49 +124,47 @@
- (OFString*)description - (OFString*)description
{ {
return [OFString stringWithFormat: return [OFString stringWithFormat:
@"Got stream error in class %@: %@. Reason: %@!", [self inClass], @"Got stream error: %@. Reason: %@!", _condition, _reason];
_condition, _reason];
} }
- (OFString*)condition - (OFString*)condition
{ {
OF_GETTER(_condition, NO) OF_GETTER(_condition, false)
} }
- (OFString*)reason - (OFString*)reason
{ {
OF_GETTER(_reason, NO) OF_GETTER(_reason, false)
} }
@end @end
@implementation XMPPStringPrepFailedException @implementation XMPPStringPrepFailedException
+ exceptionWithClass: (Class)class + exceptionWithConnection: (XMPPConnection*)connection
connection: (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 profile: (OFString*)profile
string: (OFString*)string string: (OFString*)string
{ {
return [[[self alloc] initWithClass: class self = [super initWithConnection: connection];
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 { @try {
_profile = [profile copy]; _profile = [profile copy];
@ -188,49 +188,48 @@
- (OFString*)description - (OFString*)description
{ {
return [OFString stringWithFormat: return [OFString stringWithFormat:
@"Stringprep with profile %@ failed in class %@ on string '%@'!", @"Stringprep with profile %@ failed on string '%@'!",
_profile, [self inClass], _string]; _profile, _string];
} }
- (OFString*)profile - (OFString*)profile
{ {
OF_GETTER(_profile, NO) OF_GETTER(_profile, false)
} }
- (OFString*)string - (OFString*)string
{ {
OF_GETTER(_string, NO) OF_GETTER(_string, false)
} }
@end @end
@implementation XMPPIDNATranslationFailedException @implementation XMPPIDNATranslationFailedException
+ exceptionWithClass: (Class)class + exceptionWithConnection: (XMPPConnection*)connection
connection: (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 operation: (OFString*)operation
string: (OFString*)string string: (OFString*)string
{ {
return [[[self alloc] initWithClass: class self = [super initWithConnection: connection];
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 { @try {
_operation = [operation copy]; _operation = [operation copy];
@ -254,46 +253,44 @@
- (OFString*)description - (OFString*)description
{ {
return [OFString stringWithFormat: return [OFString stringWithFormat:
@"IDNA operation %@ failed in class %@ on string '%@'!", _operation, @"IDNA operation %@ failed on string '%@'!", _operation, _string];
[self inClass], _string];
} }
- (OFString*)operation - (OFString*)operation
{ {
OF_GETTER(_operation, NO) OF_GETTER(_operation, false)
} }
- (OFString*)string - (OFString*)string
{ {
OF_GETTER(_string, NO) OF_GETTER(_string, false)
} }
@end @end
@implementation XMPPAuthFailedException @implementation XMPPAuthFailedException
+ exceptionWithClass: (Class)class + exceptionWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection reason: (OFString*)reason;
reason: (OFString*)reason;
{ {
return [[[self alloc] initWithClass: class return [[[self alloc] initWithConnection: connection
connection: connection reason: reason] autorelease];
reason: reason] autorelease];
} }
- initWithClass: (Class)class - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection
{ {
Class c = [self class]; @try {
[self release]; [self doesNotRecognizeSelector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c } @catch (id e) {
selector: _cmd]; [self release];
@throw e;
}
abort();
} }
- initWithClass: (Class)class - initWithConnection: (XMPPConnection*)connection
connection: (XMPPConnection*)connection reason: (OFString*)reason
reason: (OFString*)reason
{ {
self = [super initWithClass: class self = [super initWithConnection: connection];
connection: connection];
@try { @try {
_reason = [reason copy]; _reason = [reason copy];
@ -315,12 +312,11 @@
- (OFString*)description - (OFString*)description
{ {
return [OFString stringWithFormat: return [OFString stringWithFormat:
@"Authentication failed in class %@. Reason: %@!", [self inClass], @"Authentication failed. Reason: %@!", _reason];
_reason];
} }
- (OFString*)reason - (OFString*)reason
{ {
OF_GETTER(_reason, NO) OF_GETTER(_reason, false)
} }
@end @end

View file

@ -24,6 +24,8 @@
# include "config.h" # include "config.h"
#endif #endif
#include <stdlib.h>
#import <ObjFW/OFString.h> #import <ObjFW/OFString.h>
#import <ObjFW/OFArray.h> #import <ObjFW/OFArray.h>
#import <ObjFW/OFDictionary.h> #import <ObjFW/OFDictionary.h>
@ -38,10 +40,14 @@
@implementation XMPPFileStorage @implementation XMPPFileStorage
- init - init
{ {
Class c = [self class]; @try {
[self release]; [self doesNotRecognizeSelector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c } @catch (id e) {
selector: _cmd]; [self release];
@throw e;
}
abort();
} }
- initWithFile: (OFString*)file - initWithFile: (OFString*)file
@ -54,7 +60,7 @@
_file = [file copy]; _file = [file copy];
@try { @try {
_data = [[[OFDataArray dataArrayWithContentsOfFile: _data = [[[OFDataArray dataArrayWithContentsOfFile:
file] binaryPackValue] retain]; file] messagePackValue] retain];
} @catch (id e) { } @catch (id e) {
_data = [OFMutableDictionary new]; _data = [OFMutableDictionary new];
} }
@ -78,7 +84,7 @@
- (void)save - (void)save
{ {
[[_data binaryPackRepresentation] writeToFile: _file]; [[_data messagePackRepresentation] writeToFile: _file];
} }
- (void)XMPP_setObject: (id)object - (void)XMPP_setObject: (id)object

View file

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

View file

@ -119,10 +119,9 @@
"Nodeprep", 0)) != STRINGPREP_OK) || (nodepart[0] == '\0') || "Nodeprep", 0)) != STRINGPREP_OK) || (nodepart[0] == '\0') ||
(strlen(nodepart) > 1023)) (strlen(nodepart) > 1023))
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: nil
connection: nil profile: @"Nodeprep"
profile: @"Nodeprep" string: node];
string: node];
@try { @try {
_node = [[OFString alloc] initWithUTF8String: nodepart]; _node = [[OFString alloc] initWithUTF8String: nodepart];
@ -148,10 +147,9 @@
"Nameprep", 0)) != STRINGPREP_OK) || (srv[0] == '\0') || "Nameprep", 0)) != STRINGPREP_OK) || (srv[0] == '\0') ||
(strlen(srv) > 1023)) (strlen(srv) > 1023))
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: nil
connection: nil profile: @"Nameprep"
profile: @"Nameprep" string: domain];
string: domain];
@try { @try {
_domain = [[OFString alloc] initWithUTF8String: srv]; _domain = [[OFString alloc] initWithUTF8String: srv];
@ -183,10 +181,9 @@
"Resourceprep", 0)) != STRINGPREP_OK) || (res[0] == '\0') || "Resourceprep", 0)) != STRINGPREP_OK) || (res[0] == '\0') ||
(strlen(res) > 1023)) (strlen(res) > 1023))
@throw [XMPPStringPrepFailedException @throw [XMPPStringPrepFailedException
exceptionWithClass: [self class] exceptionWithConnection: nil
connection: nil profile: @"Resourceprep"
profile: @"Resourceprep" string: resource];
string: resource];
@try { @try {
_resource = [[OFString alloc] initWithUTF8String: res]; _resource = [[OFString alloc] initWithUTF8String: res];

View file

@ -184,9 +184,7 @@ static int show_to_int(OFString *show)
intmax_t prio = [priority intMaxValue]; intmax_t prio = [priority intMaxValue];
if ((prio < -128) || (prio > 127)) if ((prio < -128) || (prio > 127))
@throw [OFInvalidArgumentException @throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
OFXMLElement *oldPriority = [self elementForName: @"priority" OFXMLElement *oldPriority = [self elementForName: @"priority"
namespace: XMPP_NS_CLIENT]; namespace: XMPP_NS_CLIENT];
@ -219,9 +217,7 @@ static int show_to_int(OFString *show)
return OF_ORDERED_SAME; return OF_ORDERED_SAME;
if (![object isKindOfClass: [XMPPPresence class]]) if (![object isKindOfClass: [XMPPPresence class]])
@throw [OFInvalidArgumentException @throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
otherPresence = (XMPPPresence*)object; otherPresence = (XMPPPresence*)object;
otherPriority = [otherPresence priority]; otherPriority = [otherPresence priority];

View file

@ -213,8 +213,8 @@
- (void)setDataStorage: (id <XMPPStorage>)dataStorage - (void)setDataStorage: (id <XMPPStorage>)dataStorage
{ {
if (_rosterRequested) if (_rosterRequested)
@throw [OFInvalidArgumentException /* FIXME: Find a better exception! */
exceptionWithClass: [self class]]; @throw [OFInvalidArgumentException exception];
_dataStorage = dataStorage; _dataStorage = dataStorage;
} }

View file

@ -168,9 +168,8 @@
[_clientFirstMessageBare release]; [_clientFirstMessageBare release];
_clientFirstMessageBare = nil; _clientFirstMessageBare = nil;
_clientFirstMessageBare = [[OFString alloc] initWithFormat: @"n=%@,r=%@", _clientFirstMessageBare = [[OFString alloc]
_authcid, initWithFormat: @"n=%@,r=%@", _authcid, _cNonce];
_cNonce];
[ret addItems: [_GS2Header UTF8String] [ret addItems: [_GS2Header UTF8String]
count: [_GS2Header UTF8StringLength]]; count: [_GS2Header UTF8StringLength]];
@ -230,10 +229,9 @@
if ([comp hasPrefix: @"r="]) { if ([comp hasPrefix: @"r="]) {
if (![entry hasPrefix: _cNonce]) if (![entry hasPrefix: _cNonce])
@throw [XMPPAuthFailedException @throw [XMPPAuthFailedException
exceptionWithClass: [self class] exceptionWithConnection: nil
connection: nil reason: @"Received wrong "
reason: @"Received wrong " @"nonce"];
@"nonce"];
sNonce = entry; sNonce = entry;
got |= GOT_SNONCE; got |= GOT_SNONCE;
@ -248,8 +246,7 @@
} }
if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT)) if (got != (GOT_SNONCE | GOT_SALT | GOT_ITERCOUNT))
@throw [OFInvalidServerReplyException @throw [OFInvalidServerReplyException exception];
exceptionWithClass: [self class]];
// Add c=<base64(GS2Header+channelBindingData)> // Add c=<base64(GS2Header+channelBindingData)>
tmpArray = [OFDataArray dataArray]; tmpArray = [OFDataArray dataArray];
@ -390,15 +387,13 @@
if ([mess hasPrefix: @"v="]) { if ([mess hasPrefix: @"v="]) {
if (![value isEqual: [_serverSignature stringByBase64Encoding]]) if (![value isEqual: [_serverSignature stringByBase64Encoding]])
@throw [XMPPAuthFailedException @throw [XMPPAuthFailedException
exceptionWithClass: [self class] exceptionWithConnection: nil
connection: nil reason: @"Received wrong "
reason: @"Received wrong " @"ServerSignature"];
@"ServerSignature"];
_authenticated = YES; _authenticated = YES;
} else } else
@throw [XMPPAuthFailedException exceptionWithClass: [self class] @throw [XMPPAuthFailedException exceptionWithConnection: nil
connection: nil reason: value];
reason: value];
return nil; return nil;
} }

View file

@ -25,6 +25,8 @@
# include "config.h" # include "config.h"
#endif #endif
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <arpa/inet.h> #include <arpa/inet.h>
@ -55,10 +57,14 @@
- init - init
{ {
Class c = [self class]; @try {
[self release]; [self doesNotRecognizeSelector: _cmd];
@throw [OFNotImplementedException exceptionWithClass: c } @catch (id e) {
selector: _cmd]; [self release];
@throw e;
}
abort();
} }
- initWithPriority: (uint16_t)priority - initWithPriority: (uint16_t)priority
@ -208,9 +214,7 @@
if (res_ninit(&_resState)) if (res_ninit(&_resState))
@throw [OFAddressTranslationFailedException @throw [OFAddressTranslationFailedException
exceptionWithClass: [self class] exceptionWithHost: _domain];
socket: nil
host: _domain];
answer = [self allocMemoryWithSize: pageSize]; answer = [self allocMemoryWithSize: pageSize];
answerLen = res_nsearch(&_resState, answerLen = res_nsearch(&_resState,
@ -221,18 +225,13 @@
(h_errno == NO_DATA))) (h_errno == NO_DATA)))
return; return;
if (answerLen < 1 || answerLen > pageSize) { if (answerLen < 1 || answerLen > pageSize)
@throw [OFAddressTranslationFailedException @throw [OFAddressTranslationFailedException
exceptionWithClass: [self class] exceptionWithHost: _domain];
socket: nil
host: _domain];
}
if (ns_initparse(answer, answerLen, &handle)) if (ns_initparse(answer, answerLen, &handle))
@throw [OFAddressTranslationFailedException @throw [OFAddressTranslationFailedException
exceptionWithClass: [self class] exceptionWithHost: _domain];
socket: nil
host: _domain];
resourceRecordCount = ns_msg_count(handle, ns_s_an); resourceRecordCount = ns_msg_count(handle, ns_s_an);
for (i = 0; i < resourceRecordCount; i++) { for (i = 0; i < resourceRecordCount; i++) {

View file

@ -96,9 +96,7 @@
@try { @try {
if (![name isEqual: @"iq"] && ![name isEqual: @"message"] && if (![name isEqual: @"iq"] && ![name isEqual: @"message"] &&
![name isEqual: @"presence"]) ![name isEqual: @"presence"])
@throw [OFInvalidArgumentException @throw [OFInvalidArgumentException exception];
exceptionWithClass: [self class]
selector: _cmd];
[self setDefaultNamespace: XMPP_NS_CLIENT]; [self setDefaultNamespace: XMPP_NS_CLIENT];
[self setPrefix: @"stream" [self setPrefix: @"stream"

View file

@ -32,12 +32,12 @@
- (void)parser: (OFXMLParser*)parser - (void)parser: (OFXMLParser*)parser
foundProcessingInstructions: (OFString*)pi foundProcessingInstructions: (OFString*)pi
{ {
@throw [OFMalformedXMLException exceptionWithClass: [self class]]; @throw [OFMalformedXMLException exception];
} }
- (void)parser: (OFXMLParser*)parser - (void)parser: (OFXMLParser*)parser
foundComment: (OFString*)comment foundComment: (OFString*)comment
{ {
@throw [OFMalformedXMLException exceptionWithClass: [self class]]; @throw [OFMalformedXMLException exception];
} }
@end @end