Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -44,11 +44,11 @@ - (id)object; /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating there is not enough memory available. */ @@ -56,12 +56,10 @@ { size_t req_size; } /** - * Creates a new no memory exception. - * * \param obj The object which caused the exception * \param size The size of the memory that couldn't be allocated * \return A new no memory exception */ + newWithObject: (id)obj @@ -78,11 +76,11 @@ andSize: (size_t)size; /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; /** * \return The size of the memoory that couldn't be allocated */ - (size_t)requestedSize; @@ -95,12 +93,10 @@ { void *pointer; } /** - * Creates a new memory not part of object exception. - * * \param obj The object which caused the exception * \param ptr A pointer to the memory that is not part of the object * \return A new memory not part of object exception */ + newWithObject: (id)obj @@ -117,11 +113,11 @@ andPointer: (void*)ptr; /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; /** * \return A pointer to the memory which is not part of the object */ - (void*)pointer; @@ -132,21 +128,21 @@ */ @interface OFOutOfRangeException: OFException {} /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating that the conversation between two charsets failed. */ @interface OFCharsetConversionFailedException: OFException {} /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating the file couldn't be opened. */ @@ -155,12 +151,10 @@ char *path; char *mode; } /** - * Creates a new open file failed exception. - * * \param obj The object which caused the exception * \param p A C string of the path to the file tried to open * \param m A C string of the mode in which the file should have been opened * \return A new open file failed exception */ @@ -183,11 +177,11 @@ - free; /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; /** * \return A C string of the path to the file which couldn't be opened */ - (char*)path; @@ -207,12 +201,10 @@ size_t req_items; BOOL has_items; } /** - * Creates a new read or write failed exception. - * * \param obj The object which caused the exception * \param size The requested size of the data that couldn't be read / written * \param nitems The requested number of items that couldn't be read / written * \return A new open file failed exception */ @@ -219,12 +211,10 @@ + newWithObject: (id)obj andSize: (size_t)size andNItems: (size_t)nitems; /** - * Creates a new read or write failed exception. - * * \param obj The object which caused the exception * \param size The requested size of the data that couldn't be read / written * \return A new open file failed exception */ + newWithObject: (id)obj @@ -259,40 +249,45 @@ /** * \return The requested number of items that coudln't be read / written */ - (size_t)requestedItems; + +/** + * \return Whether NItems was specified + */ +- (BOOL)hasNItems; @end /** * An OFException indicating a read to the file failed. */ @interface OFReadFailedException: OFReadOrWriteFailedException {} /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating a write to the file failed. */ @interface OFWriteFailedException: OFReadOrWriteFailedException {} /** * \return An error message for the exception as a C String */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating a socket is not connected or bound. */ @interface OFNotConnectedException: OFException {} /** * \return An error message for the exception as a C string. */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating an attempt to connect or bind an already connected * or bound socket @@ -299,17 +294,64 @@ */ @interface OFAlreadyConnectedException: OFException {} /** * \return An error message for the exception as a C string. */ -- (char*)cString; +- (const char*)cString; @end /** * An OFException indicating that the specified port is invalid. */ -@interface OFInvalidPortException: OFException +@interface OFInvalidPortException: OFException {} +/** + * \return An error message for the exception as a C string. + */ +- (const char*)cString; +@end + +/** + * An OFException indicating the translation of an address failed. + */ +@interface OFAddressTranslationFailedException: OFException +{ + char *node; + char *service; +} + +/** + * \param n The node for which translation was requested + * \param s The service of the node for which translation was requested + * \return A new address translation failed exception + */ ++ newWithObject: (id)obj + andNode: (const char*)n + andService: (const char*)s; + +/** + * Initializes an already allocated address translation failed exception. + * + * \param n The node for which translation was requested + * \param s The service of the node for which translation was requested + * \return An initialized address translation failed exception + */ +- initWithObject: (id)obj + andNode: (const char*)n + andService: (const char*)s; + +- free; + /** * \return An error message for the exception as a C string. */ -- (char*)cString; +- (const char*)cString; + +/** + * /return The node for which translation was requested + */ +- (const char*)node; + +/** + * \return The service of the node for which translation was requested + */ +- (const char*)service; @end Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -55,11 +55,11 @@ - (id)object { return object; } -- (char*)cString +- (const char*)cString { return string; } @end @@ -78,11 +78,11 @@ req_size = size; return self; } -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "Could not allocate %zu bytes for object of class " @@ -112,11 +112,11 @@ pointer = ptr; return self; } -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "Memory at %p was not allocated as part of object " @@ -132,11 +132,11 @@ return pointer; } @end @implementation OFOutOfRangeException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "Value out of range in object of class %s!", @@ -145,11 +145,11 @@ return string; } @end @implementation OFCharsetConversionFailedException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "Charset conversion failed in object of classs %s!", @@ -172,12 +172,12 @@ - initWithObject: (id)obj andPath: (const char*)p andMode: (const char*)m { if ((self = [super initWithObject: obj])) { - path = p != NULL ? strdup(p) : NULL; - mode = m != NULL ? strdup(m) : NULL; + path = (p != NULL ? strdup(p) : NULL); + mode = (m != NULL ? strdup(m) : NULL); } return self; } @@ -189,11 +189,11 @@ free(mode); return [super free]; } -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "Failed to open file %s with mode %s in object of " @@ -262,14 +262,19 @@ - (size_t)requestedItems { return req_items; } + +- (BOOL)hasNItems +{ + return has_items; +} @end @implementation OFReadFailedException -- (char*)cString +- (const char*)cString { if (string != NULL) return string;; if (has_items) @@ -282,11 +287,11 @@ return string; } @end @implementation OFWriteFailedException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; if (has_items) @@ -299,11 +304,11 @@ return string; } @end @implementation OFNotConnectedException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "The socket of type %s is not connected or bound!", @@ -312,11 +317,11 @@ return string; } @end @implementation OFAlreadyConnectedException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "The socket of type %s is already connected or bound " @@ -325,11 +330,11 @@ return string; } @end @implementation OFInvalidPortException -- (char*)cString +- (const char*)cString { if (string != NULL) return string; asprintf(&string, "The port specified is not valid for a socket of " @@ -337,5 +342,63 @@ "invalid port.", [object name]); return string; } @end + +@implementation OFAddressTranslationFailedException ++ newWithObject: (id)obj + andNode: (const char*)n + andService: (const char*)s +{ + return [self newWithObject: obj + andNode: n + andService: s]; +} + +- initWithObject: (id)obj + andNode: (const char*)n + andService: (const char*)s +{ + if ((self = [super initWithObject: obj])) { + node = (n != NULL ? strdup(n) : NULL); + service = (s != NULL ? strdup(s) : NULL); + } + + return self; +} + +- free +{ + if (node != NULL) + free(node); + if (service != NULL) + free(node); + + return [super free]; +} + +- (const char*)cString +{ + if (string != NULL) + return string; + + asprintf(&string, "The specified node with the specified service could " + "not be translated to an address for an object of type %s. This " + "means that either the node was not found, there is no such " + "service on the specified node, there was a problem with the name " + "server, there was a problem with your network connection or you " + "specified an invalid node or service.", [object name]); + + return string; +} + +- (const char*)node +{ + return node; +} + +- (const char*)service +{ + return service; +} +@end Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -66,26 +66,26 @@ * \param str A wide C string to initialize the OFString with * \return An initialized OFString */ - initFromWideCString: (const wchar_t*)str; -/** - * \return The OFString as a C string, if possible (if not, returns NULL). - * If not needed anymore, it is usefull to call freeMem:. - */ -- (char*)getCString; - /** * \return The OFString as a wide C string */ -- (wchar_t*)wideCString; +- (const wchar_t*)wideCString; /** * \return The length of the OFString */ - (size_t)length; +/** + * \return The OFString as a C string, if possible (if not, returns NULL). + * If not needed anymore, it is usefull to call freeMem:. + */ +- (char*)getCString; + /** * Clones the OFString, creating a new one. * * \return A copy of the OFString */ Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -85,10 +85,20 @@ } } return self; } + +- (const wchar_t*)wideCString +{ + return string; +} + +- (size_t)length +{ + return length; +} - (char*)getCString { char *str; size_t len; @@ -104,20 +114,10 @@ } return str; } -- (wchar_t*)wideCString -{ - return string; -} - -- (size_t)length -{ - return length; -} - - (OFString*)clone { return [OFString newFromWideCString: string]; }