1999-02-13 00:50:41 +00:00
|
|
|
/* NSUrl.m - Class NSURL
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
|
1999-02-13 00:50:41 +00:00
|
|
|
Date: Jan 1999
|
|
|
|
|
|
|
|
This file is part of the GNUstep Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
1999-02-13 00:50:41 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library; if not, write to the Free
|
1999-09-09 02:56:20 +00:00
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
1999-02-13 00:50:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1999-06-24 19:30:29 +00:00
|
|
|
Note from Manuel Guesdon:
|
1999-02-13 00:50:41 +00:00
|
|
|
* I've made some test to compare apple NSURL results
|
|
|
|
and GNUstep NSURL results but as there this class is not very documented, some
|
|
|
|
function may be incorrect
|
|
|
|
* I've put 2 functions to make tests. You can add your own tests
|
|
|
|
* Some functions are not implemented
|
|
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include <base/behavior.h>
|
|
|
|
#include <Foundation/NSObject.h>
|
|
|
|
#include <Foundation/NSCoder.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSConcreteNumber.h>
|
|
|
|
#include <Foundation/NSURLHandle.h>
|
|
|
|
#include <Foundation/NSURL.h>
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString* NSURLFileScheme = @"file";
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString* NSURLPartKey_host = @"host";
|
|
|
|
NSString* NSURLPartKey_port = @"port";
|
|
|
|
NSString* NSURLPartKey_user = @"user";
|
|
|
|
NSString* NSURLPartKey_password = @"password";
|
|
|
|
NSString* NSURLPartKey_path = @"path";
|
|
|
|
NSString* NSURLPartKey_fragment = @"fragment";
|
|
|
|
NSString* NSURLPartKey_parameterString = @"parameterString";
|
|
|
|
NSString* NSURLPartKey_query = @"query";
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//=============================================================================
|
1999-02-13 00:50:41 +00:00
|
|
|
@implementation NSURL
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) fileURLWithPath: (NSString*)aPath
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return AUTORELEASE([[NSURL alloc] initFileURLWithPath: aPath]);
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) URLWithString: (NSString*)aUrlString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return AUTORELEASE([[NSURL alloc] initWithString: aUrlString]);
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
+ (id) URLWithString: (NSString*)aUrlString
|
|
|
|
relativeToURL: (NSURL*)aBaseUrl
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return AUTORELEASE([[NSURL alloc] initWithString: aUrlString
|
|
|
|
relativeToURL: aBaseUrl]);
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithScheme: (NSString*)aScheme
|
|
|
|
host: (NSString*)aHost
|
|
|
|
path: (NSString*)aPath
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString *aUrlString = nil;
|
|
|
|
|
|
|
|
if (aHost)
|
|
|
|
aUrlString = [NSString stringWithFormat: @"%@://%@", aScheme, aHost];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
aUrlString = [NSString stringWithFormat: @"%@:", aScheme];
|
|
|
|
if (aPath)
|
|
|
|
aUrlString = [aUrlString stringByAppendingString: aPath];
|
|
|
|
self = [self initWithString: aUrlString];
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-02-13 00:50:41 +00:00
|
|
|
//Non Standard Function
|
1999-09-16 07:21:34 +00:00
|
|
|
- (id) initWithScheme: (NSString*)aScheme
|
|
|
|
host: (NSString*)aHost
|
|
|
|
port: (NSNumber*)aPort
|
|
|
|
path: (NSString*)aPath
|
|
|
|
{
|
|
|
|
NSString *tmpHost = nil;
|
|
|
|
|
|
|
|
if (aPort)
|
|
|
|
tmpHost = [NSString stringWithFormat: @"%@:%@", aHost, aPort];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
tmpHost = aHost;
|
|
|
|
self = [self initWithScheme: aScheme
|
1999-06-24 19:30:29 +00:00
|
|
|
host: tmpHost
|
1999-09-16 07:21:34 +00:00
|
|
|
path: aPath];
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
//Do a initWithScheme: NSFileScheme host: nil path: aPath
|
|
|
|
- (id) initFileURLWithPath: (NSString*)aPath
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
self = [self initWithScheme: NSURLFileScheme
|
1999-06-24 19:30:29 +00:00
|
|
|
host: nil
|
1999-09-16 07:21:34 +00:00
|
|
|
path: aPath];
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
// _urlString is escaped
|
|
|
|
- (id) initWithString: (NSString*)aUrlString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
self = [self init];
|
|
|
|
ASSIGNCOPY(_urlString, aUrlString);
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
//_urlString!= nil
|
|
|
|
// _urlString is escaped
|
|
|
|
- (id) initWithString: (NSString*)aUrlString
|
|
|
|
relativeToURL: (NSURL*)aBaseUrl
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
self = [self init];
|
|
|
|
ASSIGNCOPY(_urlString, aUrlString);
|
|
|
|
ASSIGNCOPY(_baseURL, aBaseUrl);
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) dealloc
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
DESTROY(_urlString);
|
|
|
|
DESTROY(_baseURL);
|
1999-02-13 00:50:41 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
if (NSShouldRetainWithZone(self, zone) == NO)
|
1999-09-16 07:21:34 +00:00
|
|
|
return [[isa allocWithZone: zone] initWithString: _urlString
|
|
|
|
relativeToURL: _baseURL];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-07-03 19:59:44 +00:00
|
|
|
return RETAIN(self);
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
[super encodeWithCoder: aCoder];
|
1999-09-16 07:21:34 +00:00
|
|
|
[aCoder encodeObject: _urlString];
|
|
|
|
[aCoder encodeObject: _baseURL];
|
|
|
|
//FIXME? _clients ?
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (id) initWithCoder: (NSCoder*)aCoder
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
self = [super initWithCoder: aCoder];
|
1999-09-16 07:21:34 +00:00
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_urlString];
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &_baseURL];
|
|
|
|
//FIXME? _clients ?
|
1999-02-13 00:50:41 +00:00
|
|
|
return self;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) description
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString *dscr = _urlString;
|
|
|
|
|
|
|
|
if (_baseURL)
|
|
|
|
dscr = [dscr stringByAppendingFormat: @" -- %@", _baseURL];
|
1999-02-13 00:50:41 +00:00
|
|
|
return dscr;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-02-13 00:50:41 +00:00
|
|
|
// Non Standard Function
|
1999-06-24 19:30:29 +00:00
|
|
|
- (NSString*) baseURLAbsolutePart
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (_baseURL)
|
|
|
|
{
|
|
|
|
NSString* suffix = [_baseURL path];
|
|
|
|
NSString* tmp = nil;
|
|
|
|
if ([_baseURL query])
|
|
|
|
suffix = [suffix stringByAppendingFormat: @"?%@", [_baseURL query]];
|
|
|
|
// /test?aa = bb&cc=dd -- http: //user: passwd@www.gnustep.org: 80/apache
|
|
|
|
// ==> http: //user: passwd@www.gnustep.org: 80/
|
|
|
|
tmp = [[_baseURL absoluteString]stringWithoutSuffix: suffix];
|
|
|
|
|
|
|
|
// ==> http: //user: passwd@www.gnustep.org: 80
|
|
|
|
if ([tmp hasSuffix: @"/"])
|
|
|
|
tmp = [tmp stringWithoutSuffix: @"/"];
|
|
|
|
return tmp;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
return @"";
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) absoluteString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString* absString = nil;
|
|
|
|
if (_baseURL)
|
|
|
|
{
|
|
|
|
// /test?aa = bb&cc=dd -- http: //user: passwd@www.gnustep.org: 80/apache
|
|
|
|
// ==> http: //user: passwd@www.gnustep.org: 80
|
|
|
|
absString = [self baseURLAbsolutePart];
|
|
|
|
|
|
|
|
if ([_urlString hasPrefix: @"/"])
|
|
|
|
absString = [absString stringByAppendingString: _urlString];
|
|
|
|
else
|
|
|
|
absString = [absString stringByAppendingFormat: @"/%@", _urlString];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
absString = _urlString;
|
1999-02-13 00:50:41 +00:00
|
|
|
return absString;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) relativeString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _urlString;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSURL*) baseURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
return _baseURL;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSURL*) absoluteURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (!_baseURL)
|
|
|
|
return self;
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
return [NSURL URLWithString: [self absoluteString]];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) scheme
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString *scheme = nil;
|
|
|
|
NSString *absoluteString = [self absoluteString];
|
|
|
|
NSRange range = [absoluteString rangeOfString: @": //"];
|
|
|
|
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
1999-09-16 07:21:34 +00:00
|
|
|
scheme = [absoluteString substringToIndex: range.location];
|
1999-02-13 00:50:41 +00:00
|
|
|
return scheme;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) resourceSpecifier
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSString *absoluteString = [self absoluteString];
|
|
|
|
NSRange range = [absoluteString rangeOfString: @"://"];
|
|
|
|
|
|
|
|
if (range.length > 0)
|
|
|
|
return [absoluteString substringFromIndex: range.location+1];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-09-16 07:21:34 +00:00
|
|
|
return absoluteString;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-02-13 00:50:41 +00:00
|
|
|
//Non Standard Function
|
1999-06-24 19:30:29 +00:00
|
|
|
- (NSDictionary*) explode
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
NSMutableDictionary *elements = nil;
|
|
|
|
NSString *resourceSpecifier = [self resourceSpecifier];
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
if ([resourceSpecifier hasPrefix: @"//"])
|
1999-09-16 07:21:34 +00:00
|
|
|
{
|
|
|
|
int index = 2;
|
|
|
|
NSRange range;
|
|
|
|
|
|
|
|
elements = [NSMutableDictionary dictionaryWithCapacity: 0];
|
|
|
|
if (![[self scheme] isEqualToString: NSURLFileScheme])
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
range = [resourceSpecifier rangeOfString: @"/" options: 0
|
|
|
|
range: NSMakeRange(index, [resourceSpecifier length]-index)];
|
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
NSString *userPasswordHostPort;
|
|
|
|
NSString *userPassword = nil;
|
|
|
|
NSString *hostPort = nil;
|
|
|
|
|
|
|
|
userPasswordHostPort
|
|
|
|
= [resourceSpecifier substringWithRange:
|
|
|
|
NSMakeRange(index, range.location-index)];
|
|
|
|
index = range.location;
|
|
|
|
range = [userPasswordHostPort rangeOfString: @"@"];
|
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
|
|
|
userPassword
|
|
|
|
= [userPasswordHostPort substringToIndex: range.location];
|
|
|
|
if (range.location+1<[userPasswordHostPort length])
|
|
|
|
hostPort = [userPasswordHostPort
|
|
|
|
substringFromIndex: range.location+1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hostPort = userPasswordHostPort;
|
|
|
|
if (userPassword)
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
range = [userPassword rangeOfString: @": "];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
1999-09-16 07:21:34 +00:00
|
|
|
{
|
|
|
|
if (range.location>0)
|
|
|
|
[elements setObject: [userPassword substringToIndex: range.location]
|
|
|
|
forKey: NSURLPartKey_user];
|
|
|
|
if (range.location+1<[userPassword length])
|
|
|
|
[elements setObject: [userPassword substringFromIndex: range.location+1]
|
|
|
|
forKey: NSURLPartKey_password];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[elements setObject: userPassword
|
|
|
|
forKey: NSURLPartKey_user];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
|
|
|
|
if (hostPort)
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
range = [hostPort rangeOfString: @": "];
|
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
|
|
|
[elements setObject: [hostPort substringToIndex: range.location]
|
|
|
|
forKey: NSURLPartKey_host];
|
|
|
|
if (range.location+1<[hostPort length])
|
|
|
|
[elements setObject: [NSNumber valueFromString:
|
|
|
|
[hostPort substringFromIndex: range.location+1]]
|
|
|
|
forKey: NSURLPartKey_port];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[elements setObject: hostPort
|
|
|
|
forKey: NSURLPartKey_host];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
else
|
|
|
|
index--; //To Take a /
|
|
|
|
range = [resourceSpecifier rangeOfString: @"?"
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(index, [resourceSpecifier length]-index)];
|
|
|
|
if (range.length>0)
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
if (range.location>0)
|
|
|
|
[elements setObject: [resourceSpecifier substringWithRange: NSMakeRange(index, range.location-index)]
|
|
|
|
forKey: NSURLPartKey_path];
|
|
|
|
if (range.location+1<[resourceSpecifier length])
|
|
|
|
[elements setObject: [resourceSpecifier substringFromIndex: range.location+1]
|
|
|
|
forKey: NSURLPartKey_query];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-09-16 07:21:34 +00:00
|
|
|
else
|
|
|
|
[elements setObject: [resourceSpecifier substringFromIndex: index]
|
|
|
|
forKey: NSURLPartKey_path];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[NSException raise: NSGenericException
|
|
|
|
format: @"'%@' is a bad URL", self];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
return elements;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) host
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_host];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSNumber*) port;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_port];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) user;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_user];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) password;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_password];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) path;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_path];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) fragment;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_fragment];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) parameterString;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_parameterString];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) query;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self explode] objectForKey: NSURLPartKey_query];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) relativePath
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME?
|
|
|
|
return [self path];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (BOOL) isFileURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[self scheme] isEqualToString: NSURLFileScheme];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSURL*) standardizedURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URLHandle: (NSURLHandle*)sender
|
|
|
|
resourceDataDidBecomeAvailable: (NSData*)newData
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void)URLHandleResourceDidBeginLoading: (NSURLHandle*)sender
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void)URLHandleResourceDidFinishLoading: (NSURLHandle*)sender
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void)URLHandleResourceDidCancelLoading: (NSURLHandle*)sender
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-09-16 07:21:34 +00:00
|
|
|
- (void) URLHandle: (NSURLHandle*)sender
|
1999-06-24 19:30:29 +00:00
|
|
|
resourceDidFailLoadingWithReason: (NSString*)reason
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-02-13 00:50:41 +00:00
|
|
|
//FIXME: delete these fn when NSURL will be validated
|
1999-06-24 19:30:29 +00:00
|
|
|
+ (void) test
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
NSURL* url2;
|
|
|
|
NSURL* url3;
|
1999-09-16 07:21:34 +00:00
|
|
|
NSURL* url = [NSURL URLWithString: @"http: //user: passwd@www.gnustep.org: 80/apache"];
|
|
|
|
url2= [NSURL URLWithString: @"/test?aa = bb&cc=dd" relativeToURL: url];
|
|
|
|
url3= [NSURL URLWithString: @"test?aa = bb&cc=dd" relativeToURL: url];
|
|
|
|
NSLog(@"=== url ===");
|
1999-06-24 19:30:29 +00:00
|
|
|
[NSURL testPrint: url];
|
1999-09-16 07:21:34 +00:00
|
|
|
NSLog(@"=== url2===");
|
1999-06-24 19:30:29 +00:00
|
|
|
[NSURL testPrint: url2];
|
1999-09-16 07:21:34 +00:00
|
|
|
NSLog(@"=== url3===");
|
1999-06-24 19:30:29 +00:00
|
|
|
[NSURL testPrint: url3];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
+ (void) testPrint: (NSURL*)url
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-09-16 07:21:34 +00:00
|
|
|
id aBaseUrl = nil;
|
|
|
|
id aUrlString = nil;
|
|
|
|
void* __clients =0;
|
|
|
|
GSGetInstanceVariable(url, @"_baseURL", &aBaseUrl);
|
|
|
|
GSGetInstanceVariable(url, @"_urlString", &aUrlString);
|
|
|
|
GSGetInstanceVariable(url, @"_clients", &__clients);
|
|
|
|
NSLog(@"*BaseURL: %ld", (long)aBaseUrl);
|
|
|
|
NSLog(@"*BaseURL: %@", [aBaseUrl description]);
|
|
|
|
NSLog(@"*_urlString: %@", aUrlString);
|
|
|
|
NSLog(@"*_clients: %ld", (long)__clients);
|
|
|
|
NSLog(@"*host: %@", [url host]);
|
|
|
|
NSLog(@"*port: %@", [url port]);
|
|
|
|
NSLog(@"*user: %@", [url user]);
|
|
|
|
NSLog(@"*password: %@", [url password]);
|
|
|
|
NSLog(@"*path: %@", [url path]);
|
|
|
|
NSLog(@"*fragment: %@", [url fragment]);
|
|
|
|
NSLog(@"*parameterString: %@", [url parameterString]);
|
|
|
|
NSLog(@"*query: %@", [url query]);
|
|
|
|
NSLog(@"*relativePath: %@", [url relativePath]);
|
|
|
|
NSLog(@"*absoluteString: %@", [url absoluteString]);
|
|
|
|
NSLog(@"*relativeString: %@", [url relativeString]);
|
|
|
|
NSLog(@"*_baseURL: %@", [[url baseURL] description]);
|
|
|
|
NSLog(@"*absoluteURL: %@", [[url absoluteURL] description]);
|
|
|
|
NSLog(@"*scheme: %@", [url scheme]);
|
|
|
|
NSLog(@"*resourceSpecifier: %@", [url resourceSpecifier]);
|
|
|
|
NSLog(@"*description: %@", [url description]);
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
@end
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//=============================================================================
|
1999-02-13 00:50:41 +00:00
|
|
|
@implementation NSURL (NSURLLoading)
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSData*) resourceDataUsingCache: (BOOL)shouldUseCache
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) loadResourceDataNotifyingClient: (id)client
|
1999-09-16 07:21:34 +00:00
|
|
|
usingCache: (BOOL)shouldUseCache
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSURLHandle*)URLHandleUsingCache: (BOOL)shouldUseCache
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (BOOL) setResourceData: (NSData*)data
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return NO;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (id) propertyForKey: (NSString*)propertyKey
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return nil;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (BOOL) setProperty: (id)property
|
|
|
|
forKey: (NSString*)propertyKey;
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return NO;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//=============================================================================
|
1999-02-13 00:50:41 +00:00
|
|
|
@implementation NSObject (NSURLClient)
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URL: (NSURL*)sender
|
|
|
|
resourceDataDidBecomeAvailable: (NSData*)newBytes
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URLResourceDidFinishLoading: (NSURL*)sender
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URLResourceDidCancelLoading: (NSURL*)sender
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URL: (NSURL*)sender
|
|
|
|
resourceDidFailLoadingWithReason: (NSString*)reason
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
|
|
|
@end
|