@@ -16,10 +16,11 @@ #include "config.h" #include #include +#include #import "OFURL.h" #import "OFString.h" #import "OFArray.h" #import "OFXMLElement.h" @@ -55,28 +56,32 @@ @try { char *tmp, *tmp2; if ((UTF8String2 = of_strdup([string UTF8String])) == NULL) @throw [OFOutOfMemoryException - exceptionWithRequestedSize: [string - UTF8StringLength]]; + exceptionWithRequestedSize: + [string UTF8StringLength]]; UTF8String = UTF8String2; - if (!strncmp(UTF8String, "file://", 7)) { - _scheme = @"file"; + if ((tmp = strstr(UTF8String, "://")) == NULL) + @throw [OFInvalidFormatException exception]; + + for (tmp2 = UTF8String; tmp2 < tmp; tmp2++) + *tmp2 = tolower((int)*tmp2); + + _scheme = [[OFString alloc] + initWithUTF8String: UTF8String + length: tmp - UTF8String]; + + UTF8String = tmp + 3; + + if ([_scheme isEqual: @"file"]) { _path = [[OFString alloc] - initWithUTF8String: UTF8String + 7]; + initWithUTF8String: UTF8String]; return self; - } else if (!strncmp(UTF8String, "http://", 7)) { - _scheme = @"http"; - UTF8String += 7; - } else if (!strncmp(UTF8String, "https://", 8)) { - _scheme = @"https"; - UTF8String += 8; - } else - @throw [OFInvalidFormatException exception]; + } if ((tmp = strchr(UTF8String, '/')) != NULL) { *tmp = '\0'; tmp++; } @@ -118,24 +123,21 @@ if ([portString decimalValue] > 65535) @throw [OFInvalidFormatException exception]; _port = [portString decimalValue]; - if (_port == 0) - _port = 80; - objc_autoreleasePoolPop(pool); } else { _host = [[OFString alloc] initWithUTF8String: UTF8String]; if ([_scheme isEqual: @"http"]) _port = 80; else if ([_scheme isEqual: @"https"]) _port = 443; - else - OF_ENSURE(0); + else if ([_scheme isEqual: @"ftp"]) + _port = 21; } if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; @@ -364,13 +366,10 @@ OF_GETTER(_scheme, true) } - (void)setScheme: (OFString*)scheme { - if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) - @throw [OFInvalidArgumentException exception]; - OF_SETTER(_scheme, scheme, true, 1) } - (OFString*)host { @@ -417,14 +416,10 @@ OF_GETTER(_path, true) } - (void)setPath: (OFString*)path { - if (([_scheme isEqual: @"http"] || [_scheme isEqual: @"https"]) && - ![path hasPrefix: @"/"]) - @throw [OFInvalidArgumentException exception]; - OF_SETTER(_path, path, true, 1) } - (OFString*)parameters { @@ -475,11 +470,12 @@ if (_host != nil) [ret appendString: _host]; if (([_scheme isEqual: @"http"] && _port != 80) || - ([_scheme isEqual: @"https"] && _port != 443)) + ([_scheme isEqual: @"https"] && _port != 443) || + ([_scheme isEqual: @"ftp"] && _port != 21)) [ret appendFormat: @":%u", _port]; if (_path != nil) [ret appendFormat: @"/%@", _path];