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.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
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
|
|
|
|
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
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>
|
|
|
|
|
|
|
|
NSString* NSURLFileScheme=@"file";
|
|
|
|
|
|
|
|
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-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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
+ (id) fileURLWithPath: (NSString*)_path
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[[NSURL alloc] initFileURLWithPath: _path]
|
1999-02-13 00:50:41 +00:00
|
|
|
autorelease];
|
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)URLWithString: (NSString*)_urlString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[[NSURL alloc] initWithString: _urlString]
|
1999-02-13 00:50:41 +00:00
|
|
|
autorelease];
|
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)URLWithString: (NSString*)_urlString
|
|
|
|
relativeToURL: (NSURL*)_baseURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
return [[[NSURL alloc] initWithString: _urlString
|
|
|
|
relativeToURL: _baseURL]
|
1999-02-13 00:50:41 +00:00
|
|
|
autorelease];
|
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) initWithScheme: (NSString*)_scheme
|
|
|
|
host: (NSString*)_host
|
|
|
|
path: (NSString*)_path
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
NSString* _urlString=nil;
|
|
|
|
if (_host)
|
1999-06-24 19:30:29 +00:00
|
|
|
_urlString=[NSString stringWithFormat: @"%@: //%@",_scheme,_host];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
_urlString=[NSString stringWithFormat: @"%@: ",_scheme];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (_path)
|
1999-06-24 19:30:29 +00:00
|
|
|
_urlString=[_urlString stringByAppendingString: _path];
|
|
|
|
self=[self initWithString: _urlString];
|
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-06-24 19:30:29 +00:00
|
|
|
- (id) initWithScheme: (NSString*)_scheme
|
|
|
|
host: (NSString*)_host
|
|
|
|
port: (NSNumber*)_port
|
|
|
|
path: (NSString*)_path
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
NSString* tmpHost=nil;
|
|
|
|
if (_port)
|
1999-06-24 19:30:29 +00:00
|
|
|
tmpHost=[NSString stringWithFormat: @"%@: %@",_host,_port];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
|
|
|
tmpHost=_host;
|
1999-06-24 19:30:29 +00:00
|
|
|
self=[self initWithScheme: _scheme
|
|
|
|
host: tmpHost
|
|
|
|
path: _path];
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//Do a initWithScheme: NSFileScheme host: nil path: _path
|
|
|
|
- (id) initFileURLWithPath: (NSString*)_path
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
self=[self initWithScheme: NSURLFileScheme
|
|
|
|
host: nil
|
|
|
|
path: _path];
|
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
|
|
|
// urlString is escaped
|
1999-06-24 19:30:29 +00:00
|
|
|
- (id) initWithString: (NSString*)_urlString
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
self=[self init];
|
|
|
|
ASSIGNCOPY(urlString,_urlString);
|
|
|
|
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
|
|
|
//urlString!=nil
|
|
|
|
// urlString is escaped
|
1999-06-24 19:30:29 +00:00
|
|
|
- (id) initWithString: (NSString*)_urlString
|
|
|
|
relativeToURL: (NSURL*)_baseURL
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
self=[self init];
|
|
|
|
ASSIGNCOPY(urlString,_urlString);
|
|
|
|
ASSIGNCOPY(baseURL,_baseURL);
|
|
|
|
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
|
|
|
{
|
|
|
|
DESTROY(urlString);
|
|
|
|
DESTROY(baseURL);
|
|
|
|
[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-06-24 19:30:29 +00:00
|
|
|
return [[isa allocWithZone: zone] initWithString: urlString
|
|
|
|
relativeToURL: baseURL];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
|
|
|
return [self retain];
|
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-06-24 19:30:29 +00:00
|
|
|
[aCoder encodeObject: urlString];
|
|
|
|
[aCoder encodeObject: baseURL];
|
1999-02-13 00:50:41 +00:00
|
|
|
//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-06-24 19:30:29 +00:00
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &urlString];
|
|
|
|
[aCoder decodeValueOfObjCType: @encode(id) at: &baseURL];
|
1999-02-13 00:50:41 +00:00
|
|
|
//FIXME? clients ?
|
|
|
|
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
|
|
|
{
|
|
|
|
NSString* dscr=urlString;
|
|
|
|
if (baseURL)
|
1999-06-24 19:30:29 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
if (baseURL)
|
|
|
|
{
|
|
|
|
NSString* suffix=[baseURL path];
|
|
|
|
NSString* tmp=nil;
|
|
|
|
if ([baseURL query])
|
1999-06-24 19:30:29 +00:00
|
|
|
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: @"/"];
|
1999-02-13 00:50:41 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
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
|
|
|
{
|
|
|
|
NSString* absString=nil;
|
|
|
|
if (baseURL)
|
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
// /test?aa=bb&cc=dd -- http: //user: passwd@www.gnustep.org: 80/apache
|
|
|
|
// ==> http: //user: passwd@www.gnustep.org: 80
|
1999-02-13 00:50:41 +00:00
|
|
|
absString=[self baseURLAbsolutePart];
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
if ([urlString hasPrefix: @"/"])
|
|
|
|
absString=[absString stringByAppendingString: urlString];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
absString=[absString stringByAppendingFormat: @"/%@",urlString];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
absString=urlString;
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
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
|
|
|
{
|
|
|
|
if (!baseURL)
|
|
|
|
return self;
|
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
return [NSURL URLWithString: [self absoluteString]];
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
NSString* scheme=nil;
|
|
|
|
NSString* absoluteString=[self absoluteString];
|
1999-06-24 19:30:29 +00:00
|
|
|
NSRange range=[absoluteString rangeOfString: @": //"];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
1999-06-24 19:30:29 +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
|
|
|
{
|
|
|
|
NSString* absoluteString=[self absoluteString];
|
1999-06-24 19:30:29 +00:00
|
|
|
NSRange range=[absoluteString rangeOfString: @": //"];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
1999-06-24 19:30:29 +00:00
|
|
|
return [absoluteString substringFromIndex: range.location+1];
|
1999-02-13 00:50:41 +00:00
|
|
|
else
|
|
|
|
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
|
|
|
{
|
|
|
|
NSMutableDictionary* elements=nil;
|
|
|
|
NSString* resourceSpecifier=[self resourceSpecifier];
|
1999-06-24 19:30:29 +00:00
|
|
|
if ([resourceSpecifier hasPrefix: @"//"])
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
int index=2;
|
|
|
|
NSRange range;
|
|
|
|
elements=[[NSMutableDictionary new] autorelease];
|
1999-06-24 19:30:29 +00:00
|
|
|
if (![[self scheme] isEqualToString: NSURLFileScheme])
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
range=[resourceSpecifier rangeOfString: @"/"
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(index,[resourceSpecifier length]-index)];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
NSString* userPasswordHostPort=[resourceSpecifier substringWithRange: NSMakeRange(index,range.location-index)];
|
1999-02-13 00:50:41 +00:00
|
|
|
NSString* userPassword=nil;
|
|
|
|
NSString* hostPort=nil;
|
|
|
|
index=range.location;
|
1999-06-24 19:30:29 +00:00
|
|
|
range=[userPasswordHostPort rangeOfString: @"@"];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
1999-06-24 19:30:29 +00:00
|
|
|
userPassword=[userPasswordHostPort substringToIndex: range.location];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.location+1<[userPasswordHostPort length])
|
1999-06-24 19:30:29 +00:00
|
|
|
hostPort=[userPasswordHostPort substringFromIndex: range.location+1];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hostPort=userPasswordHostPort;
|
|
|
|
if (userPassword)
|
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
range=[userPassword rangeOfString: @": "];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [userPassword substringToIndex: range.location]
|
|
|
|
forKey: NSURLPartKey_user];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.location+1<[userPassword length])
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [userPassword substringFromIndex: range.location+1]
|
|
|
|
forKey: NSURLPartKey_password];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: userPassword
|
|
|
|
forKey: NSURLPartKey_user];
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
|
|
|
if (hostPort)
|
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
range=[hostPort rangeOfString: @": "];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [hostPort substringToIndex: range.location]
|
|
|
|
forKey: NSURLPartKey_host];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.location+1<[hostPort length])
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [NSNumber valueFromString:
|
|
|
|
[hostPort substringFromIndex: range.location+1]]
|
|
|
|
forKey: NSURLPartKey_port];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: hostPort
|
|
|
|
forKey: NSURLPartKey_host];
|
1999-02-13 00:50:41 +00:00
|
|
|
};
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
index--; //To Take a /
|
1999-06-24 19:30:29 +00:00
|
|
|
range=[resourceSpecifier rangeOfString: @"?"
|
|
|
|
options: 0
|
|
|
|
range: NSMakeRange(index,[resourceSpecifier length]-index)];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.length>0)
|
|
|
|
{
|
|
|
|
if (range.location>0)
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [resourceSpecifier substringWithRange: NSMakeRange(index,range.location-index)]
|
|
|
|
forKey: NSURLPartKey_path];
|
1999-02-13 00:50:41 +00:00
|
|
|
if (range.location+1<[resourceSpecifier length])
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [resourceSpecifier substringFromIndex: range.location+1]
|
|
|
|
forKey: NSURLPartKey_query];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
1999-06-24 19:30:29 +00:00
|
|
|
[elements setObject: [resourceSpecifier substringFromIndex: index]
|
|
|
|
forKey: NSURLPartKey_path];
|
1999-02-13 00:50:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-06-24 19:30:29 +00:00
|
|
|
[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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) URLHandle: (NSURLHandle*)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
|
|
|
|
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-06-24 19:30:29 +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];
|
1999-02-13 00:50:41 +00:00
|
|
|
NSLog(@"===url===");
|
1999-06-24 19:30:29 +00:00
|
|
|
[NSURL testPrint: url];
|
1999-02-13 00:50:41 +00:00
|
|
|
NSLog(@"===url2===");
|
1999-06-24 19:30:29 +00:00
|
|
|
[NSURL testPrint: url2];
|
1999-02-13 00:50:41 +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
|
|
|
{
|
|
|
|
id _baseURL=nil;
|
|
|
|
id _urlString=nil;
|
|
|
|
void* _clients=0;
|
|
|
|
GSGetInstanceVariable(url,@"baseURL",&_baseURL);
|
|
|
|
GSGetInstanceVariable(url,@"urlString",&_urlString);
|
|
|
|
GSGetInstanceVariable(url,@"clients",&_clients);
|
|
|
|
NSLog(@"*BaseURL: %ld",(long)_baseURL);
|
|
|
|
NSLog(@"*BaseURL: %@",[_baseURL description]);
|
|
|
|
NSLog(@"*urlString: %@",_urlString);
|
|
|
|
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
|
|
|
|
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
|