Changeset 5441
- Timestamp:
- 03/19/08 16:09:29 (7 months ago)
- Files:
-
- WiredAdditions/trunk/WIURL.h (modified) (1 diff)
- WiredAdditions/trunk/WIURL.m (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredAdditions/trunk/WIURL.h
r5102 r5441 54 54 - (void)setScheme:(NSString *)value; 55 55 - (NSString *)scheme; 56 - (void)setHostpair:(NSString *)value; 57 - (NSString *)hostpair; 56 58 - (void)setHost:(NSString *)value; 57 59 - (NSString *)host; 58 - (NSString *)hostpair;59 60 - (void)setPort:(NSUInteger)value; 60 61 - (NSUInteger)port; WiredAdditions/trunk/WIURL.m
r5102 r5441 45 45 if(!portmap) { 46 46 portmap = [[NSDictionary alloc] initWithObjectsAndKeys: 47 [NSNumber numberWithInt: 2000], @"wired",48 [NSNumber numberWithInt: 2002], @"wiredtracker",47 [NSNumber numberWithInt:4871], @"wired", 48 [NSNumber numberWithInt:4871], @"wiredtracker", 49 49 NULL]; 50 50 } … … 73 73 string = [string stringByReplacingURLPercentEscapes]; 74 74 75 // --- find SCHEME://host/76 75 range = [string rangeOfString:@"://"]; 77 76 … … 83 82 } 84 83 85 // --- find scheme://host/PATH86 84 range = [string rangeOfString:@"/"]; 87 85 … … 93 91 } 94 92 95 // --- find scheme://USER@host/96 93 range = [string rangeOfString:@"@"]; 97 94 … … 103 100 string = [string substringFromIndex:range.location + 1]; 104 101 105 // --- find scheme://user:PASSWORD@host/106 102 range = [auth rangeOfString:@":"]; 107 103 … … 128 124 return NULL; 129 125 130 url = [self URLWithScheme:scheme hostpair:string]; 126 url = [[self alloc] init]; 127 [url setScheme:scheme]; 128 [url setHostpair:string]; 131 129 [url setUser:user]; 132 130 [url setPassword:password]; … … 144 142 } 145 143 146 return url;144 return [url autorelease]; 147 145 } 148 146 … … 150 148 151 149 + (id)URLWithScheme:(NSString *)scheme hostpair:(NSString *)hostpair { 152 NSString *host; 153 NSRange range; 154 NSUInteger port; 155 156 if([[hostpair componentsSeparatedByString:@":"] count] == 2) { 157 range = [hostpair rangeOfString:@":" options:NSBackwardsSearch]; 158 159 if(range.location == NSNotFound || 160 range.location == 0 || 161 range.location == [hostpair length] - 1) { 162 host = hostpair; 163 port = 0; 164 } else { 165 host = [hostpair substringToIndex:range.location]; 166 port = [[hostpair substringFromIndex:range.location + 1] unsignedIntValue]; 167 } 168 } else { 169 host = hostpair; 170 port = 0; 171 } 172 173 if(port == 0) 174 port = [[[WIURL _portmap] objectForKey:scheme] unsignedIntValue]; 175 176 return [[[self alloc] initWithScheme:scheme host:host port:port] autorelease]; 150 WIURL *url; 151 152 url = [[self alloc] init]; 153 [url setScheme:scheme]; 154 [url setHostpair:hostpair]; 155 156 return [url autorelease]; 177 157 } 178 158 … … 342 322 if([[self host] length] > 0) { 343 323 if([[self user] length] > 0 && ![[self user] isEqualToString:@"guest"]) 344 [string appendFormat:@"%@ :@", [self user]];324 [string appendFormat:@"%@@", [self user]]; 345 325 346 326 [string appendString:[self hostpair]]; … … 400 380 401 381 382 - (void)setHostpair:(NSString *)value { 383 NSString *host; 384 NSRange range; 385 NSUInteger port; 386 387 if([value hasPrefix:@"["] && [value containsSubstring:@"]"]) { 388 value = [value substringFromIndex:1]; 389 range = [value rangeOfString:@"]" options:NSBackwardsSearch]; 390 host = [value substringToIndex:range.location]; 391 port = 0; 392 393 if([value containsSubstring:@"]:"]) { 394 range = [value rangeOfString:@"]:" options:NSBackwardsSearch]; 395 396 if(range.location != [value length] - 2) 397 port = [[value substringFromIndex:range.location + 2] unsignedIntValue]; 398 } 399 } 400 else if([[value componentsSeparatedByString:@":"] count] == 2) { 401 range = [value rangeOfString:@":" options:NSBackwardsSearch]; 402 403 if(range.location == NSNotFound || range.location == 0 || 404 range.location == [value length] - 1) { 405 host = value; 406 port = 0; 407 } else { 408 host = [value substringToIndex:range.location]; 409 port = [[value substringFromIndex:range.location + 1] unsignedIntValue]; 410 } 411 } else { 412 host = value; 413 port = 0; 414 } 415 416 if(port == 0) 417 port = [[[WIURL _portmap] objectForKey:_scheme] unsignedIntValue]; 418 419 [self setHost:host]; 420 [self setPort:port]; 421 } 422 423 424 425 - (NSString *)hostpair { 426 if([[[WIURL _portmap] objectForKey:[self scheme]] unsignedIntValue] == [self port]) 427 return [self host]; 428 429 return [NSSWF:@"%@:%lu", [self host], [self port]]; 430 } 431 432 433 402 434 - (void)setHost:(NSString *)value { 403 435 [value retain]; … … 411 443 - (NSString *)host { 412 444 return _host; 413 }414 415 416 417 - (NSString *)hostpair {418 if([[[WIURL _portmap] objectForKey:[self scheme]] unsignedIntValue] == [self port])419 return [self host];420 421 return [NSSWF:@"%@:%lu", [self host], [self port]];422 445 } 423 446
