mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
Fix problems with sites which require authentication if we don't have any
credentials git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24752 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7c6c308075
commit
4a89c7967e
3 changed files with 150 additions and 108 deletions
|
@ -1,3 +1,10 @@
|
|||
2007-03-02 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSHTTPURLHandle.m: Cope with nil authentication info
|
||||
* Source/GSHTTPAuthentication.m: Cope with nil credential and
|
||||
catch exceptions in lock protected areas (there shouldn't be
|
||||
any, but best to be safe).
|
||||
|
||||
2007-03-01 Nicola Pero <nicola.pero@meta-innovation.com>
|
||||
|
||||
* Source/NSBundle.m ([NSBundle +bundleForLibrary:]): Fixed paths
|
||||
|
|
|
@ -100,7 +100,8 @@ static GSMimeParser *mimeParser = nil;
|
|||
NSInvalidArgumentException);
|
||||
|
||||
[storeLock lock];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
/*
|
||||
* Keep track of known protection spaces so we don't make lots of
|
||||
* duplicate copies, but share one copy between authentication objects.
|
||||
|
@ -126,14 +127,23 @@ static GSMimeParser *mimeParser = nil;
|
|||
authentication = [[GSHTTPAuthentication alloc]
|
||||
initWithCredential: credential
|
||||
inProtectionSpace: space];
|
||||
[cDict setObject: authentication forKey: [authentication credential]];
|
||||
}
|
||||
else
|
||||
if (authentication != nil)
|
||||
{
|
||||
RETAIN(authentication);
|
||||
[cDict setObject: authentication
|
||||
forKey: [authentication credential]];
|
||||
RELEASE(authentication);
|
||||
}
|
||||
}
|
||||
AUTORELEASE(RETAIN(authentication));
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
[storeLock unlock];
|
||||
return AUTORELEASE(authentication);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[storeLock unlock];
|
||||
return authentication;
|
||||
}
|
||||
|
||||
+ (NSURLProtectionSpace*) protectionSpaceForAuthentication: (NSString*)auth
|
||||
|
@ -219,14 +229,9 @@ static GSMimeParser *mimeParser = nil;
|
|||
+ (NSURLProtectionSpace *) protectionSpaceForURL: (NSURL*)URL
|
||||
{
|
||||
NSURLProtectionSpace *space = nil;
|
||||
NSString *found = nil;
|
||||
NSString *scheme;
|
||||
NSNumber *port;
|
||||
NSString *server;
|
||||
NSDictionary *sDict;
|
||||
NSArray *keys;
|
||||
unsigned count;
|
||||
NSString *path;
|
||||
|
||||
scheme = [URL scheme];
|
||||
port = [URL port];
|
||||
|
@ -248,7 +253,16 @@ static GSMimeParser *mimeParser = nil;
|
|||
server = [NSString stringWithFormat: @"%@://%@:%@",
|
||||
scheme, [URL host], port];
|
||||
}
|
||||
|
||||
[storeLock lock];
|
||||
NS_DURING
|
||||
{
|
||||
NSString *found = nil;
|
||||
NSDictionary *sDict;
|
||||
NSArray *keys;
|
||||
unsigned count;
|
||||
NSString *path;
|
||||
|
||||
sDict = [domainMap objectForKey: server];
|
||||
keys = [sDict allKeys];
|
||||
count = [keys count];
|
||||
|
@ -268,19 +282,23 @@ static GSMimeParser *mimeParser = nil;
|
|||
}
|
||||
if (found != nil)
|
||||
{
|
||||
space = RETAIN([sDict objectForKey: found]);
|
||||
space = AUTORELEASE(RETAIN([sDict objectForKey: found]));
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
[storeLock unlock];
|
||||
return AUTORELEASE(space);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[storeLock unlock];
|
||||
return space;
|
||||
}
|
||||
|
||||
+ (void) setProtectionSpace: (NSURLProtectionSpace *)space
|
||||
forDomains: (NSArray*)domains
|
||||
baseURL: (NSURL*)base
|
||||
{
|
||||
NSEnumerator *e;
|
||||
NSString *domain;
|
||||
|
||||
/*
|
||||
* If there are no URIs specified, everything on the
|
||||
* host of the base URL is in the protection space
|
||||
|
@ -291,7 +309,11 @@ static GSMimeParser *mimeParser = nil;
|
|||
}
|
||||
|
||||
[storeLock lock];
|
||||
e = [domains objectEnumerator];
|
||||
NS_DURING
|
||||
{
|
||||
NSEnumerator *e = [domains objectEnumerator];
|
||||
NSString *domain;
|
||||
|
||||
while ((domain = [e nextObject]) != nil)
|
||||
{
|
||||
NSURL *u;
|
||||
|
@ -341,6 +363,13 @@ static GSMimeParser *mimeParser = nil;
|
|||
}
|
||||
[sDict setObject: space forKey: [u path]];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
[storeLock unlock];
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
[storeLock unlock];
|
||||
}
|
||||
|
||||
|
|
|
@ -452,19 +452,20 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
NSURLCredential *cred;
|
||||
NSString *method;
|
||||
|
||||
/*
|
||||
* Create credential from user and password
|
||||
* stored in the URL.
|
||||
/* Create credential from user and password stored in the URL.
|
||||
* Returns nil if we have no username or password.
|
||||
*/
|
||||
cred = [[NSURLCredential alloc]
|
||||
initWithUser: [u user]
|
||||
password: [u password]
|
||||
persistence: NSURLCredentialPersistenceForSession];
|
||||
|
||||
/* Create authentication from credential ... returns nil if
|
||||
* we have no credential.
|
||||
*/
|
||||
authentication = [GSHTTPAuthentication
|
||||
authenticationWithCredential: cred
|
||||
inProtectionSpace: space];
|
||||
|
||||
RELEASE(cred);
|
||||
|
||||
method = [request objectForKey: GSHTTPPropertyMethodKey];
|
||||
|
@ -483,8 +484,12 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
auth = [authentication authorizationForAuthentication: nil
|
||||
method: method
|
||||
path: [u path]];
|
||||
|
||||
NSMapInsert(wProperties, (void*)@"Authorization", (void*)auth);
|
||||
/* If authentication is nil then auth will also be nil
|
||||
*/
|
||||
if (auth != nil)
|
||||
{
|
||||
[self writeProperty: auth forKey: @"Authorization"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -634,7 +639,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
NSString *ac;
|
||||
GSHTTPAuthentication *authentication;
|
||||
NSString *method;
|
||||
NSString *a;
|
||||
NSString *auth;
|
||||
|
||||
ac = [ah value];
|
||||
space = [GSHTTPAuthentication
|
||||
|
@ -646,6 +651,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
/*
|
||||
* Create credential from user and password
|
||||
* stored in the URL.
|
||||
* Returns nil if we have no username or password.
|
||||
*/
|
||||
cred = [[NSURLCredential alloc]
|
||||
initWithUser: [url user]
|
||||
|
@ -655,11 +661,11 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
/*
|
||||
* Get the digest object and ask it for a header
|
||||
* to use for authorisation.
|
||||
* Returns nil if we have no credential.
|
||||
*/
|
||||
authentication = [GSHTTPAuthentication
|
||||
authenticationWithCredential: cred
|
||||
inProtectionSpace: space];
|
||||
|
||||
RELEASE(cred);
|
||||
}
|
||||
else
|
||||
|
@ -680,12 +686,12 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
|
|||
}
|
||||
}
|
||||
|
||||
a = [authentication authorizationForAuthentication: ac
|
||||
auth = [authentication authorizationForAuthentication: ac
|
||||
method: method
|
||||
path: [url path]];
|
||||
if (a != nil)
|
||||
if (auth != nil)
|
||||
{
|
||||
[self writeProperty: a forKey: @"Authorization"];
|
||||
[self writeProperty: auth forKey: @"Authorization"];
|
||||
[self _tryLoadInBackground: u];
|
||||
return; // Retrying.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue