2006-06-16 15:21:39 +00:00
|
|
|
/* Implementation for NSURLProtectionSpace for GNUstep
|
|
|
|
Copyright (C) 2006 Software Foundation, Inc.
|
|
|
|
|
2009-03-20 18:52:59 +00:00
|
|
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
2006-06-16 15:21:39 +00:00
|
|
|
Date: 2006
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2006-06-16 15:21:39 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2006-06-16 15:21:39 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-16 15:21:39 +00:00
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
|
|
|
*/
|
|
|
|
|
2010-02-11 19:57:31 +00:00
|
|
|
#define EXPOSE_NSURLProtectionSpace_IVARS 1
|
2007-11-29 20:53:26 +00:00
|
|
|
#import "GSURLPrivate.h"
|
2010-02-10 17:15:09 +00:00
|
|
|
#import "GNUstepBase/NSURL+GNUstepBase.h"
|
2006-06-16 15:21:39 +00:00
|
|
|
|
|
|
|
NSString * const NSURLProtectionSpaceFTPProxy = @"ftp";
|
|
|
|
NSString * const NSURLProtectionSpaceHTTPProxy = @"http";
|
|
|
|
NSString * const NSURLProtectionSpaceHTTPSProxy = @"https";
|
|
|
|
NSString * const NSURLProtectionSpaceSOCKSProxy = @"SOCKS";
|
|
|
|
NSString * const NSURLAuthenticationMethodDefault
|
|
|
|
= @"NSURLAuthenticationMethodDefault";
|
|
|
|
NSString * const NSURLAuthenticationMethodHTMLForm
|
|
|
|
= @"NSURLAuthenticationMethodHTMLForm";
|
|
|
|
NSString * const NSURLAuthenticationMethodHTTPBasic
|
|
|
|
= @"NSURLAuthenticationMethodHTTPBasic";
|
|
|
|
NSString * const NSURLAuthenticationMethodHTTPDigest
|
|
|
|
= @"NSURLAuthenticationMethodHTTPDigest";
|
|
|
|
|
|
|
|
// Internal data storage
|
|
|
|
typedef struct {
|
|
|
|
NSString *host;
|
|
|
|
int port;
|
|
|
|
NSString *protocol;
|
|
|
|
NSString *realm;
|
2006-07-04 10:54:12 +00:00
|
|
|
NSString *proxyType; // Not retained
|
|
|
|
NSString *authenticationMethod; // Not retained
|
2006-06-16 15:21:39 +00:00
|
|
|
BOOL isProxy;
|
|
|
|
} Internal;
|
|
|
|
|
2010-02-13 09:16:24 +00:00
|
|
|
#define this ((Internal*)(self->_NSURLProtectionSpaceInternal))
|
|
|
|
#define inst ((Internal*)(o->_NSURLProtectionSpaceInternal))
|
2006-06-16 15:21:39 +00:00
|
|
|
|
|
|
|
@implementation NSURLProtectionSpace
|
|
|
|
|
|
|
|
+ (id) allocWithZone: (NSZone*)z
|
|
|
|
{
|
|
|
|
NSURLProtectionSpace *o = [super allocWithZone: z];
|
|
|
|
|
|
|
|
if (o != nil)
|
|
|
|
{
|
2007-03-01 17:35:43 +00:00
|
|
|
o->_NSURLProtectionSpaceInternal = NSZoneCalloc(z, 1, sizeof(Internal));
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) authenticationMethod
|
|
|
|
{
|
|
|
|
return this->authenticationMethod;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone*)z
|
|
|
|
{
|
2006-06-19 11:20:17 +00:00
|
|
|
if (NSShouldRetainWithZone(self, z) == YES)
|
2006-06-16 15:21:39 +00:00
|
|
|
{
|
2006-06-19 11:20:17 +00:00
|
|
|
return RETAIN(self);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSURLProtectionSpace *o = [[self class] allocWithZone: z];
|
|
|
|
|
|
|
|
o = [o initWithHost: this->host
|
|
|
|
port: this->port
|
|
|
|
protocol: this->protocol
|
|
|
|
realm: this->realm
|
|
|
|
authenticationMethod: this->authenticationMethod];
|
|
|
|
if (o != nil)
|
|
|
|
{
|
|
|
|
inst->isProxy = this->isProxy;
|
2006-07-04 10:54:12 +00:00
|
|
|
inst->proxyType = this->proxyType;
|
2006-06-19 11:20:17 +00:00
|
|
|
}
|
|
|
|
return o;
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
if (this != 0)
|
|
|
|
{
|
|
|
|
RELEASE(this->host);
|
|
|
|
RELEASE(this->protocol);
|
|
|
|
RELEASE(this->realm);
|
|
|
|
NSZoneFree([self zone], this);
|
|
|
|
}
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSUInteger) hash
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
|
|
|
return [[self host] hash] + [self port]
|
|
|
|
+ [[self realm] hash] + [[self protocol] hash]
|
2006-07-04 10:54:12 +00:00
|
|
|
+ (uintptr_t)this->proxyType + (uintptr_t)this->authenticationMethod;
|
2006-06-19 11:20:17 +00:00
|
|
|
}
|
|
|
|
|
2006-06-16 15:21:39 +00:00
|
|
|
- (NSString *) host
|
|
|
|
{
|
|
|
|
return this->host;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithHost: (NSString *)host
|
2009-02-23 20:42:32 +00:00
|
|
|
port: (NSInteger)port
|
2006-06-16 15:21:39 +00:00
|
|
|
protocol: (NSString *)protocol
|
|
|
|
realm: (NSString *)realm
|
|
|
|
authenticationMethod: (NSString *)authenticationMethod
|
|
|
|
{
|
|
|
|
if ((self = [super init]) != nil)
|
|
|
|
{
|
|
|
|
this->host = [host copy];
|
|
|
|
this->protocol = [protocol copy];
|
|
|
|
this->realm = [realm copy];
|
2006-07-04 10:54:12 +00:00
|
|
|
if ([authenticationMethod isEqualToString:
|
|
|
|
NSURLAuthenticationMethodHTMLForm] == YES)
|
|
|
|
{
|
|
|
|
this->authenticationMethod = NSURLAuthenticationMethodHTMLForm;
|
|
|
|
}
|
|
|
|
else if ([authenticationMethod isEqualToString:
|
|
|
|
NSURLAuthenticationMethodHTTPBasic] == YES)
|
|
|
|
{
|
|
|
|
this->authenticationMethod = NSURLAuthenticationMethodHTTPBasic;
|
|
|
|
}
|
|
|
|
else if ([authenticationMethod isEqualToString:
|
|
|
|
NSURLAuthenticationMethodHTTPDigest] == YES)
|
|
|
|
{
|
|
|
|
this->authenticationMethod = NSURLAuthenticationMethodHTTPDigest;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->authenticationMethod = NSURLAuthenticationMethodDefault;
|
|
|
|
}
|
2006-06-16 15:21:39 +00:00
|
|
|
this->port = port;
|
|
|
|
this->proxyType = nil;
|
|
|
|
this->isProxy = NO;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithProxyHost: (NSString *)host
|
2009-02-23 20:42:32 +00:00
|
|
|
port: (NSInteger)port
|
2006-06-16 15:21:39 +00:00
|
|
|
type: (NSString *)type
|
|
|
|
realm: (NSString *)realm
|
|
|
|
authenticationMethod: (NSString *)authenticationMethod
|
|
|
|
{
|
|
|
|
self = [self initWithHost: host
|
|
|
|
port: port
|
|
|
|
protocol: nil
|
|
|
|
realm: realm
|
|
|
|
authenticationMethod: authenticationMethod];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
this->isProxy = YES;
|
2006-07-04 10:54:12 +00:00
|
|
|
if ([type isEqualToString: NSURLProtectionSpaceFTPProxy] == YES)
|
|
|
|
{
|
|
|
|
this->proxyType = NSURLProtectionSpaceFTPProxy;
|
|
|
|
}
|
|
|
|
else if ([type isEqualToString: NSURLProtectionSpaceHTTPProxy] == YES)
|
|
|
|
{
|
|
|
|
this->proxyType = NSURLProtectionSpaceHTTPProxy;
|
|
|
|
}
|
|
|
|
else if ([type isEqualToString: NSURLProtectionSpaceHTTPSProxy] == YES)
|
|
|
|
{
|
|
|
|
this->proxyType = NSURLProtectionSpaceHTTPSProxy;
|
|
|
|
}
|
|
|
|
else if ([type isEqualToString: NSURLProtectionSpaceSOCKSProxy] == YES)
|
|
|
|
{
|
|
|
|
this->proxyType = NSURLProtectionSpaceSOCKSProxy;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DESTROY(self); // Bad proxy type.
|
|
|
|
}
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
2006-07-04 10:54:12 +00:00
|
|
|
return self;
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 08:41:23 +00:00
|
|
|
- (BOOL) isEqual: (id)other
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
2006-06-19 15:37:50 +00:00
|
|
|
if ((id)self == other)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
2006-06-19 15:13:08 +00:00
|
|
|
if ([other isKindOfClass: [NSURLProtectionSpace class]] == NO)
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSURLProtectionSpace *o = (NSURLProtectionSpace*)other;
|
|
|
|
|
2006-06-19 12:01:13 +00:00
|
|
|
if ([[self host] isEqual: [o host]] == NO)
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2006-06-19 12:01:13 +00:00
|
|
|
if ([[self realm] isEqual: [o realm]] == NO)
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if ([self port] != [o port])
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
2006-06-19 12:01:13 +00:00
|
|
|
if ([[self authenticationMethod] isEqual: [o authenticationMethod]] == NO)
|
2006-06-19 11:20:17 +00:00
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
if ([self isProxy] == YES)
|
|
|
|
{
|
|
|
|
if ([o isProxy] == NO
|
|
|
|
|| [[self proxyType] isEqual: [o proxyType]] == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([o isProxy] == YES
|
|
|
|
|| [[self protocol] isEqual: [o protocol]] == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
2006-06-19 15:37:50 +00:00
|
|
|
return YES;
|
|
|
|
}
|
2006-06-19 11:20:17 +00:00
|
|
|
}
|
|
|
|
|
2006-06-16 15:21:39 +00:00
|
|
|
- (BOOL) isProxy
|
|
|
|
{
|
|
|
|
return this->isProxy;
|
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSInteger) port
|
2006-06-16 15:21:39 +00:00
|
|
|
{
|
|
|
|
return this->port;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) protocol
|
|
|
|
{
|
|
|
|
return this->protocol;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) proxyType
|
|
|
|
{
|
|
|
|
return this->proxyType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) realm
|
|
|
|
{
|
|
|
|
return this->realm;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) receivesCredentialSecurely
|
|
|
|
{
|
2006-07-04 10:54:12 +00:00
|
|
|
if (this->authenticationMethod == NSURLAuthenticationMethodHTTPDigest)
|
2006-06-16 15:21:39 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
if (this->isProxy)
|
|
|
|
{
|
2006-07-04 10:54:12 +00:00
|
|
|
if (this->proxyType == NSURLProtectionSpaceHTTPSProxy)
|
2006-06-16 15:21:39 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([this->protocol isEqual: @"https"] == YES)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|