Various URL handling improvments.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@25154 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2007-05-14 16:55:16 +00:00
parent cc25eedb9e
commit 9a44af0e80
9 changed files with 969 additions and 278 deletions

View file

@ -23,9 +23,9 @@
*/
#include "GSURLPrivate.h"
#include "GSPrivate.h"
#include "Foundation/NSCoder.h"
#include "Foundation/NSMapTable.h"
#include "Foundation/NSScanner.h"
#include "NSCallBacks.h"
#include "GNUstepBase/GSMime.h"
@ -33,13 +33,13 @@
// Internal data storage
typedef struct {
long long expectedContentLength;
NSURL *URL;
NSString *MIMEType;
NSString *textEncodingName;
NSString *statusText;
NSMapTable *headers;
int statusCode;
long long expectedContentLength;
NSURL *URL;
NSString *MIMEType;
NSString *textEncodingName;
NSString *statusText;
_GSMutableInsensitiveDictionary *headers;
int statusCode;
} Internal;
typedef struct {
@ -49,41 +49,6 @@ typedef struct {
#define inst ((Internal*)(((priv*)o)->_NSURLResponseInternal))
/*
* Implement map keys for strings with case insensitive comparisons,
* so we can have case insensitive matching of http headers (correct
* behavior), but actually preserve case of headers stored and written
* in case the remote server is buggy and requires particular
* captialisation of headers (some http software is faulty like that).
*/
static unsigned int
_non_retained_id_hash(void *table, NSString* o)
{
return [[o uppercaseString] hash];
}
static BOOL
_non_retained_id_is_equal(void *table, NSString *o, NSString *p)
{
return ([o caseInsensitiveCompare: p] == NSOrderedSame) ? YES : NO;
}
typedef unsigned int (*NSMT_hash_func_t)(NSMapTable *, const void *);
typedef BOOL (*NSMT_is_equal_func_t)(NSMapTable *, const void *, const void *);
typedef void (*NSMT_retain_func_t)(NSMapTable *, const void *);
typedef void (*NSMT_release_func_t)(NSMapTable *, void *);
typedef NSString *(*NSMT_describe_func_t)(NSMapTable *, const void *);
static const NSMapTableKeyCallBacks headerKeyCallBacks =
{
(NSMT_hash_func_t) _non_retained_id_hash,
(NSMT_is_equal_func_t) _non_retained_id_is_equal,
(NSMT_retain_func_t) _NS_non_retained_id_retain,
(NSMT_release_func_t) _NS_non_retained_id_release,
(NSMT_describe_func_t) _NS_non_retained_id_describe,
NSNotAPointerMapKey
};
@implementation NSURLResponse (Private)
- (void) _setHeaders: (id)headers
{
@ -167,20 +132,13 @@ static const NSMapTableKeyCallBacks headerKeyCallBacks =
{
if (this->headers == 0)
{
this->headers = NSCreateMapTable(headerKeyCallBacks,
NSObjectMapValueCallBacks, 8);
this->headers = [_GSMutableInsensitiveDictionary new];
}
NSMapInsert(this->headers, (void*)field, (void*)value);
[this->headers setObject: value forKey: field];
}
- (NSString *) _valueForHTTPHeaderField: (NSString *)field
{
NSString *value = nil;
if (this->headers != 0)
{
value = (NSString*)NSMapGet(this->headers, (void*)field);
}
return value;
return [this->headers objectForKey: field];
}
@end
@ -223,7 +181,7 @@ static const NSMapTableKeyCallBacks headerKeyCallBacks =
}
else
{
inst->headers = NSCopyMapTableWithZone(this->headers, z);
inst->headers = [this->headers mutableCopy];
}
}
}
@ -238,10 +196,7 @@ static const NSMapTableKeyCallBacks headerKeyCallBacks =
RELEASE(this->MIMEType);
RELEASE(this->textEncodingName);
RELEASE(this->statusText);
if (this->headers != 0)
{
NSFreeMapTable(this->headers);
}
RELEASE(this->headers);
NSZoneFree([self zone], this);
}
[super dealloc];
@ -376,23 +331,7 @@ static const NSMapTableKeyCallBacks headerKeyCallBacks =
- (NSDictionary *) allHeaderFields
{
NSMutableDictionary *fields;
fields = [NSMutableDictionary dictionaryWithCapacity: 8];
if (this->headers != 0)
{
NSMapEnumerator enumerator;
NSString *k;
NSString *v;
enumerator = NSEnumerateMapTable(this->headers);
while (NSNextMapEnumeratorPair(&enumerator, (void **)(&k), (void**)&v))
{
[fields setObject: v forKey: k];
}
NSEndMapTableEnumeration(&enumerator);
}
return fields;
return AUTORELEASE([this->headers copy]);
}
- (int) statusCode