@@ -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