1999-09-16 07:21:34 +00:00
|
|
|
/* NSURLHandle.m - Class NSURLHandle
|
1999-02-13 00:50:41 +00:00
|
|
|
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
|
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
|
|
|
* functions are not implemented. If someone has documentation or ideas on
|
|
|
|
how it should work...
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <base/behavior.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSConcreteNumber.h>
|
|
|
|
#include <Foundation/NSURLHandle.h>
|
|
|
|
#include <Foundation/NSURL.h>
|
2000-09-19 18:49:43 +00:00
|
|
|
#include <Foundation/NSMapTable.h>
|
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 NSURLHandle
|
|
|
|
|
2000-09-19 18:49:43 +00:00
|
|
|
static NSMapTable *cache = 0;
|
2000-09-19 08:31:40 +00:00
|
|
|
static NSMutableArray *registry = nil;
|
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSURLHandle class])
|
|
|
|
{
|
2000-09-19 18:49:43 +00:00
|
|
|
cache = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
|
|
|
NSObjectMapValueCallBacks, 0);
|
2000-09-19 08:31:40 +00:00
|
|
|
registry = [NSMutableArray new];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
+ (void) registerURLHandleClass: (Class)_urlHandleSubclass
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
2000-09-19 18:49:43 +00:00
|
|
|
if ([registry indexOfObjectIdenticalTo: _urlHandleSubclass] == NSNotFound)
|
2000-09-19 08:31:40 +00:00
|
|
|
{
|
|
|
|
[registry addObject: _urlHandleSubclass];
|
|
|
|
}
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
2000-09-19 08:31:40 +00:00
|
|
|
+ (Class) URLHandleClassForURL: (NSURL*)_url
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
2000-09-19 08:31:40 +00:00
|
|
|
unsigned count = [registry count];
|
|
|
|
|
|
|
|
while (count-- > 0)
|
|
|
|
{
|
|
|
|
id found = [registry objectAtIndex: count];
|
|
|
|
|
|
|
|
if ([found canInitWithURL: _url] == YES)
|
|
|
|
{
|
|
|
|
return (Class)found;
|
|
|
|
}
|
|
|
|
}
|
1999-06-24 19:30:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
- (id) initWithURL: (NSURL*)_url
|
2000-09-19 08:31:40 +00:00
|
|
|
cached: (BOOL)_cached
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
2000-09-19 18:49:43 +00:00
|
|
|
Class concreteSubclass;
|
2000-09-19 08:31:40 +00:00
|
|
|
NSURLHandle *instance;
|
|
|
|
|
2000-09-19 18:49:43 +00:00
|
|
|
if (_cached == YES)
|
|
|
|
{
|
|
|
|
instance = (id)NSMapGet(cache, (void*)_url);
|
|
|
|
if (instance != nil)
|
|
|
|
{
|
|
|
|
RELEASE(self);
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
concreteSubclass = [NSURLHandle URLHandleClassForURL: _url];
|
2000-09-19 08:31:40 +00:00
|
|
|
if (concreteSubclass == 0)
|
|
|
|
{
|
|
|
|
NSLog(@"Attempt to init NSURLHandle with unsupported URL schema");
|
|
|
|
RELEASE(self);
|
|
|
|
}
|
|
|
|
RELEASE(self);
|
|
|
|
instance = [concreteSubclass alloc];
|
2000-09-19 18:49:43 +00:00
|
|
|
instance = [instance initWithURL: _url cached: _cached];
|
|
|
|
if (instance != nil)
|
|
|
|
{
|
|
|
|
NSMapInsert(cache, (void*)_url, (void*)instance);
|
|
|
|
}
|
|
|
|
return instance;
|
1999-06-24 19:30:29 +00:00
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSURLHandleStatus) status
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
[self notImplemented: _cmd];
|
1999-06-24 19:30:29 +00:00
|
|
|
return (NSURLHandleStatus)0;
|
|
|
|
}
|
1999-02-13 00:50:41 +00:00
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSString*) failureReason
|
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) addClient: (id <NSURLHandleClient>)_client
|
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) removeClient: (id <NSURLHandleClient>)_client
|
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) loadInBackground
|
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) cancelLoadInBackground
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSData*) resourceData
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSData*) availableResourceData
|
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) flushCachedData
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
2000-09-19 18:49:43 +00:00
|
|
|
NSResetMapTable(cache);
|
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) backgroundLoadDidFailWithReason: (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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (void) didLoadBytes: (NSData*)newData
|
|
|
|
loadComplete: (BOOL)_loadComplete
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
+ (BOOL) canInitWithURL: (NSURL*)_url
|
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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
+ (NSURLHandle*) cachedHandleForURL: (NSURL*)_url
|
1999-02-13 00:50:41 +00:00
|
|
|
{
|
2000-09-19 18:49:43 +00:00
|
|
|
return (NSURLHandle*) NSMapGet(cache, (void*)_url);
|
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) 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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (id) propertyForKeyIfAvailable: (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) writeProperty: (id)propertyValue
|
|
|
|
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
|
|
|
|
1999-06-24 19:30:29 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (BOOL) writeData: (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
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
- (NSData*) loadInForeground
|
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) beginLoadInBackground
|
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) endLoadInBackground
|
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
|