mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Skeletal implementation of new URL laoding scheme
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23065 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a5a2b746ad
commit
44ba76ce4f
33 changed files with 5024 additions and 28 deletions
43
ChangeLog
43
ChangeLog
|
@ -1,3 +1,46 @@
|
|||
2006-06-16 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/Foundation/NSURLCredential.h:
|
||||
* Headers/Foundation/NSHTTPCookieStorage.h:
|
||||
* Headers/Foundation/NSURLAuthenticationChallenge.h:
|
||||
* Headers/Foundation/NSHTTPCookie.h:
|
||||
* Headers/Foundation/NSURLError.h:
|
||||
* Headers/Foundation/NSURLProtectionSpace.h:
|
||||
* Headers/Foundation/NSURLDownload.h:
|
||||
* Headers/Foundation/NSURLRequest.h:
|
||||
* Headers/Foundation/NSURLCredentialStorage.h:
|
||||
* Headers/Foundation/Foundation.h:
|
||||
* Headers/Foundation/NSURLResponse.h:
|
||||
* Headers/Foundation/NSURLConnection.h:
|
||||
* Headers/Foundation/NSURLProtocol.h:
|
||||
* Headers/Foundation/NSURLCache.h:
|
||||
Headers for Apple's new URL loading scheme (including documentation).
|
||||
* Source/NSMapTable.m:
|
||||
* Source/NSURLCredential.m:
|
||||
* Source/NSURLAuthenticationChallenge.m:
|
||||
* Source/NSURLHandle.m:
|
||||
* Source/GNUmakefile:
|
||||
* Source/NSURLDownload.m:
|
||||
* Source/NSURLCredentialStorage.m:
|
||||
* Source/NSURLResponse.m:
|
||||
* Source/NSURLProtocol.m:
|
||||
* Source/NSURLCache.m:
|
||||
* Source/NSHTTPCookieStorage.m:
|
||||
* Source/NSURL.m:
|
||||
* Source/DocMakefile:
|
||||
* Source/NSHTTPCookie.m:
|
||||
* Source/NSURLProtectionSpace.m:
|
||||
* Source/NSURLRequest.m:
|
||||
* Source/NSSet.m:
|
||||
* Source/NSURLConnection.m:
|
||||
Skeleton code for Apple's new URL loading scheme (plus minor
|
||||
tweaks to comments in other files). This code is not expected
|
||||
to work yet. Major lacks are ...
|
||||
1. concrete implementations of protocols
|
||||
2. on disk cache/storage management
|
||||
3. thread safety (locking) for shared objects
|
||||
However, I hope it will provide a good starting framework.
|
||||
|
||||
2006-06-15 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Additions/GNUstepBase/GSXML.h: New XMLRPC settings to control
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __Foundation_h_GNUSTEP_BASE_INCLUDE
|
||||
|
@ -44,11 +45,11 @@
|
|||
#include <Foundation/NSComparisonPredicate.h>
|
||||
#include <Foundation/NSCompoundPredicate.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSDateFormatter.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSDateFormatter.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSDecimalNumber.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSDistantObject.h>
|
||||
#include <Foundation/NSDistributedLock.h>
|
||||
#include <Foundation/NSDistributedNotificationCenter.h>
|
||||
|
@ -59,14 +60,16 @@
|
|||
#include <Foundation/NSFileHandle.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSFormatter.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <Foundation/NSHTTPCookie.h>
|
||||
#include <Foundation/NSHTTPCookieStorage.h>
|
||||
#include <Foundation/NSIndexPath.h>
|
||||
#include <Foundation/NSIndexSet.h>
|
||||
#include <Foundation/NSInvocation.h>
|
||||
#include <Foundation/NSKeyValueCoding.h>
|
||||
#include <Foundation/NSKeyedArchiver.h>
|
||||
#include <Foundation/NSKeyValueCoding.h>
|
||||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSMethodSignature.h>
|
||||
|
@ -92,11 +95,22 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSTask.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSTimeZone.h>
|
||||
#include <Foundation/NSTimer.h>
|
||||
#include <Foundation/NSTimeZone.h>
|
||||
#include <Foundation/NSUndoManager.h>
|
||||
#include <Foundation/NSURLAuthenticationChallenge.h>
|
||||
#include <Foundation/NSURLCache.h>
|
||||
#include <Foundation/NSURLConnection.h>
|
||||
#include <Foundation/NSURLCredential.h>
|
||||
#include <Foundation/NSURLCredentialStorage.h>
|
||||
#include <Foundation/NSURLDownload.h>
|
||||
#include <Foundation/NSURLError.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include <Foundation/NSURLHandle.h>
|
||||
#include <Foundation/NSUndoManager.h>
|
||||
#include <Foundation/NSURLProtectionSpace.h>
|
||||
#include <Foundation/NSURLProtocol.h>
|
||||
#include <Foundation/NSURLRequest.h>
|
||||
#include <Foundation/NSURLResponse.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSXMLParser.h>
|
||||
|
|
246
Headers/Foundation/NSHTTPCookie.h
Normal file
246
Headers/Foundation/NSHTTPCookie.h
Normal file
|
@ -0,0 +1,246 @@
|
|||
/* Interface for NSHTTPCookie for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSHTTPCookie_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSHTTPCookie_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSArray;
|
||||
@class NSDate;
|
||||
@class NSDictionary;
|
||||
@class NSString;
|
||||
@class NSURL;
|
||||
|
||||
extern NSString * const NSHTTPCookieComment; /** Obtain text of the comment */
|
||||
extern NSString * const NSHTTPCookieCommentURL; /** Obtain the comment URL */
|
||||
extern NSString * const NSHTTPCookieDiscard; /** Obtain the sessions discard setting */
|
||||
extern NSString * const NSHTTPCookieDomain; /** Obrain cookie domain */
|
||||
extern NSString * const NSHTTPCookieExpires; /** Obrain cookie expiry date */
|
||||
extern NSString * const NSHTTPCookieMaximumAge; /** Obtain maximum age (expiry) */
|
||||
extern NSString * const NSHTTPCookieName; /** Obtain name of cookie */
|
||||
extern NSString * const NSHTTPCookieOriginURL; /** Obtain cookie origin URL */
|
||||
extern NSString * const NSHTTPCookiePath; /** Obtain cookie path */
|
||||
extern NSString * const NSHTTPCookiePort; /** Obtain cookie ports */
|
||||
extern NSString * const NSHTTPCookieSecure; /** Obtain cookie security */
|
||||
extern NSString * const NSHTTPCookieValue; /** Obtain value of cookie */
|
||||
extern NSString * const NSHTTPCookieVersion; /** Obtain cookie version */
|
||||
|
||||
|
||||
/**
|
||||
* An instance of the NSHTTPCookie class is a single, immutable http cookie.
|
||||
* It can be initialised with properties from a dictionary and has accessor
|
||||
* methods to obtain the cookie values.<br />
|
||||
* The class supports unversioned cookies (sometimes referred to as version 0)
|
||||
* as originally produced by netscape, as well as more recent standardised
|
||||
* and versioned cookies.
|
||||
*/
|
||||
@interface NSHTTPCookie : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSHTTPCookieInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates and returns an autoreleasd instance using -initWithProperties:
|
||||
* to initialise it from properties.
|
||||
*/
|
||||
+ (id) cookieWithProperties: (NSDictionary *)properties;
|
||||
|
||||
/**
|
||||
* Returns an array of cookies parsed from the headerFields and URL
|
||||
* (assuming that the headerFields came from a response to a request
|
||||
* sent to the URL).<br />
|
||||
* The headerFields dictionary must contain at least all the headers
|
||||
* relevant to cookie setting ... other headers are ignored.
|
||||
*/
|
||||
+ (NSArray *) cookiesWithResponseHeaderFields: (NSDictionary *)headerFields
|
||||
forURL: (NSURL *)URL;
|
||||
|
||||
/**
|
||||
* Returns a dictionary of header fields that can be used to add the
|
||||
* specified cookies to a request.
|
||||
*/
|
||||
+ (NSDictionary *) requestHeaderFieldsWithCookies: (NSArray *)cookies;
|
||||
|
||||
/**
|
||||
* Returns a string which may be used to describe the cookie to the
|
||||
* user, or nil if no comment is set.
|
||||
*/
|
||||
- (NSString *) comment;
|
||||
|
||||
/**
|
||||
* Returns a URL where the user can find out about the cookie, or nil
|
||||
* if no comment URL is set.
|
||||
*/
|
||||
- (NSURL *) commentURL;
|
||||
|
||||
/**
|
||||
* Returns the domain to which the cookie should be sent.<br />
|
||||
* If there is a leading dot then subdomains should also receive the
|
||||
* coockie as specified in RFC 2965.
|
||||
*/
|
||||
- (NSString *) domain;
|
||||
|
||||
/**
|
||||
* Returns the expiry date of the receiver or nil if there is no
|
||||
* such date.
|
||||
*/
|
||||
- (NSDate *) expiresDate;
|
||||
|
||||
/** <init />
|
||||
* Initialises the receiver with a dictionary of properties.<br />
|
||||
* Unrecognised keys are ignored.<br />
|
||||
* Returns nil if a required key is missing or if an illegal
|
||||
* value is specified for a key.
|
||||
* <deflist>
|
||||
* <term>NSHTTPCookieComment</term>
|
||||
* <desc>
|
||||
* The [NSString] comment for the cookie (if any).<br />
|
||||
* This is nil by default and for unversioned cookies.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieCommentURL</term>
|
||||
* <desc>
|
||||
* The [NSString] or [NSURL] URL to get the comment for the cookie.<br />
|
||||
* This is nil by default and for unversioned cookies.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieDomain</term>
|
||||
* <desc>
|
||||
* The [NSString] specified the domain to which the cookie applies.<br />
|
||||
* This is extracted from NSHTTPCookieOriginURL if not specified.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieDiscard</term>
|
||||
* <desc>
|
||||
* A [NSString] (either TRUE or FALSE) saying whether the cookie
|
||||
* is to be discarded when the session ends.<br />
|
||||
* Defaults to FALSE except for versioned cookies where
|
||||
* NSHTTPCookieMaximumAge is unspecified.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieExpires</term>
|
||||
* <desc>
|
||||
* The [NSDate] or [NSString] (format Wdy, DD-Mon-YYYY HH:MM:SS GMT)
|
||||
* specifying when an unversioned cookie expires and ignored for
|
||||
* versioned cookies.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieMaximumAge</term>
|
||||
* <desc>
|
||||
* An [NSString] containing an integer value specifying the longest time
|
||||
* (in seconds) for which the cookie is valid.<br />
|
||||
* This defaults to zero and is only meaningful for versioned cookies.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieName</term>
|
||||
* <desc>
|
||||
* An [NSString] ... obvious ... no default value.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieOriginURL</term>
|
||||
* <desc>
|
||||
* An [NSString] or [NSURL] specifying the URL which set the cookie.<br />
|
||||
* Must be supplied if NSHTTPCookieDomain is not.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookiePath</term>
|
||||
* <desc>
|
||||
* An [NSString] specifying the path from the cookie.<br />
|
||||
* If unspecified this value is determined from NSHTTPCookieOriginURL
|
||||
* or defaults to '/'.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookiePort</term>
|
||||
* <desc>
|
||||
* An [NSString] containing a comma separated list of integer port
|
||||
* numbers. This is valid for versioned cookies and defaults to
|
||||
* an empty string.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieSecure</term>
|
||||
* <desc>
|
||||
* An [NSString] saying whether the cookie may be sent over
|
||||
* insecure connections.<br />
|
||||
* The default is FALSE meaning that it may be sent insecurely.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieValue</term>
|
||||
* <desc>
|
||||
* An [NSString] containing the whole value of the cooke.<br />
|
||||
* This parameter <strong>must</strong> be provided.
|
||||
* </desc>
|
||||
* <term>NSHTTPCookieVersion</term>
|
||||
* <desc>
|
||||
* An [NSString] specifying the cookie version ... for an
|
||||
* unversioned cookie (the default) this is '0'.<br />
|
||||
* Also supports version '1'.
|
||||
* </desc>
|
||||
* </deflist>
|
||||
*/
|
||||
- (id) initWithProperties: (NSDictionary *)properties;
|
||||
|
||||
/**
|
||||
* Returns whether the receiver should only be sent over
|
||||
* secure connections.
|
||||
*/
|
||||
- (BOOL) isSecure;
|
||||
|
||||
/**
|
||||
* Returns whether the receiver should be destroyed at the end of the
|
||||
* session.
|
||||
*/
|
||||
- (BOOL) isSessionOnly;
|
||||
|
||||
/**
|
||||
* Returns the name of the receiver.
|
||||
*/
|
||||
- (NSString *) name;
|
||||
|
||||
/**
|
||||
* Returns the URL path within the cookie's domain for which
|
||||
* this cookie must be sent.
|
||||
*/
|
||||
- (NSString *) path;
|
||||
|
||||
/**
|
||||
* Returns the list of ports to which the receiver should be sent,
|
||||
* or nil if the cookie can be used for any port.
|
||||
*/
|
||||
- (NSArray *) portList;
|
||||
|
||||
/**
|
||||
* Returns a dictionary representation of the receiver which could be
|
||||
* used as the argument for -initWithProperties: to recreate a copy
|
||||
* of the receiver.
|
||||
*/
|
||||
- (NSDictionary *) properties;
|
||||
|
||||
/**
|
||||
* Returns the value of the receiver.
|
||||
*/
|
||||
- (NSString *) value;
|
||||
|
||||
/**
|
||||
* Returns 0 for an unversioned Netscape style cookie or a
|
||||
* positive integer for a versioned cookie.
|
||||
*/
|
||||
- (unsigned) version;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
118
Headers/Foundation/NSHTTPCookieStorage.h
Normal file
118
Headers/Foundation/NSHTTPCookieStorage.h
Normal file
|
@ -0,0 +1,118 @@
|
|||
/* Interface for NSHTTPCookieStorage for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSHTTPCookieStorage_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSHTTPCookieStorage_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSArray;
|
||||
@class NSHTTPCookie;
|
||||
@class NSURL;
|
||||
|
||||
/**
|
||||
* NSHTTPCookieAcceptPolicyAlways Accept all cookies
|
||||
* NSHTTPCookieAcceptPolicyNever Reject all cookies
|
||||
* NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain Accept cookies
|
||||
* only from the main document domain
|
||||
*/
|
||||
typedef enum {
|
||||
NSHTTPCookieAcceptPolicyAlways,
|
||||
NSHTTPCookieAcceptPolicyNever,
|
||||
NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain
|
||||
} NSHTTPCookieAcceptPolicy;
|
||||
|
||||
/**
|
||||
* Posted to the distributed notification center when the cookie
|
||||
* accept policy is changed.
|
||||
*/
|
||||
extern NSString * const NSHTTPCookieManagerAcceptPolicyChangedNotification;
|
||||
|
||||
/**
|
||||
* Posted when the set of cookies changes
|
||||
*/
|
||||
extern NSString * const NSHTTPCookieManagerCookiesChangedNotification;
|
||||
|
||||
|
||||
/**
|
||||
* The NSHTTPCookieStorage class provides a shared instance which handles
|
||||
* the shared cookie store.<br />
|
||||
*/
|
||||
|
||||
@interface NSHTTPCookieStorage : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSHTTPCookieStorageInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance.
|
||||
*/
|
||||
+ (NSHTTPCookieStorage *) sharedHTTPCookieStorage;
|
||||
|
||||
/**
|
||||
* Returns the current cookie accept policy.
|
||||
*/
|
||||
- (NSHTTPCookieAcceptPolicy) cookieAcceptPolicy;
|
||||
|
||||
/**
|
||||
* Returns an array of all managed cookies.
|
||||
*/
|
||||
- (NSArray *) cookies;
|
||||
|
||||
/**
|
||||
* Returns an array of all known cookies to send to URL.
|
||||
*/
|
||||
- (NSArray *) cookiesForURL: (NSURL *)URL;
|
||||
|
||||
/**
|
||||
* Deletes cookie from the shared store.
|
||||
*/
|
||||
- (void) deleteCookie: (NSHTTPCookie *)cookie;
|
||||
|
||||
/**
|
||||
* Sets a cookie in the store, replacing any existing cookie with the
|
||||
* same name, domain and path.
|
||||
*/
|
||||
- (void) setCookie: (NSHTTPCookie *)cookie;
|
||||
|
||||
/**
|
||||
* Sets the current cookie accept policy.
|
||||
*/
|
||||
- (void) setCookieAcceptPolicy: (NSHTTPCookieAcceptPolicy)cookieAcceptPolicy;
|
||||
|
||||
/**
|
||||
* Adds to the shared store following the policy for
|
||||
* NSHTTPCookieAcceptPolicyOnlyFromMainDocumentDomain
|
||||
*/
|
||||
- (void) setCookies: (NSArray *)cookies
|
||||
forURL: (NSURL *)URL
|
||||
mainDocumentURL: (NSURL *)mainDocumentURL;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
134
Headers/Foundation/NSURLAuthenticationChallenge.h
Normal file
134
Headers/Foundation/NSURLAuthenticationChallenge.h
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* Interface for NSURLAuthenticationChallenge for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLAuthenticationChallenge_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLAuthenticationChallenge_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSError;
|
||||
@class NSURLAuthenticationChallenge;
|
||||
@class NSURLCredential;
|
||||
@class NSURLProtectionSpace;
|
||||
@class NSURLResponse;
|
||||
|
||||
/**
|
||||
*/
|
||||
@protocol NSURLAuthenticationChallengeSender <NSObject>
|
||||
|
||||
/**
|
||||
*/
|
||||
- (void) cancelAuthenticationChallenge:
|
||||
(NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
*/
|
||||
- (void) continueWithoutCredentialForAuthenticationChallenge:
|
||||
(NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
*/
|
||||
- (void) useCredential: (NSURLCredential *)credential
|
||||
forAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
* Class to represent an authentication challenge and indicate when the
|
||||
* challenge is complete.
|
||||
*/
|
||||
@interface NSURLAuthenticationChallenge : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLAuthenticationChallengeInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error with which the reciver was initialised or nil
|
||||
* if it was not initialised with an error.<br />
|
||||
* The error may indicate the nature of the authentication failure.
|
||||
*/
|
||||
- (NSError *) error;
|
||||
|
||||
/**
|
||||
* Returns the response with which the receiver was initialised.<br />
|
||||
* This response contains the authentication failure corresponding to
|
||||
* this challenge object.<br />
|
||||
* If there was no failure or response, returns nil.
|
||||
*/
|
||||
- (NSURLResponse *) failureResponse;
|
||||
|
||||
/**
|
||||
* Initialises a new challenge by copying information from an old one.
|
||||
*/
|
||||
- (id) initWithAuthenticationChallenge:
|
||||
(NSURLAuthenticationChallenge *)challenge
|
||||
sender:
|
||||
(id<NSURLAuthenticationChallengeSender>)sender;
|
||||
|
||||
/**
|
||||
* Returns the receiver initialised in the specified protection space and
|
||||
* with the specified credential. The previousFailureCount says how many
|
||||
* requests have failed the challenge and response provide information
|
||||
* about the last failure (which caused this challenge to be created).<br />
|
||||
* The error provides information about the authentication failure and
|
||||
* the sender is the object to receive callbacks.
|
||||
*/
|
||||
- (id) initWithProtectionSpace: (NSURLProtectionSpace *)space
|
||||
proposedCredential: (NSURLCredential *)credential
|
||||
previousFailureCount: (int)previousFailureCount
|
||||
failureResponse: (NSURLResponse *)response
|
||||
error: (NSError *)error
|
||||
sender: (id<NSURLAuthenticationChallengeSender>)sender;
|
||||
|
||||
/**
|
||||
* Returns the count of failed authentication attempts.
|
||||
*/
|
||||
- (int) previousFailureCount;
|
||||
|
||||
/**
|
||||
* Returns a proposed credential to answer the challenge.<br />
|
||||
* If there is no credential available, this returns nil.<br />
|
||||
* The credential may come from storage or from the URL itsself.
|
||||
*/
|
||||
- (NSURLCredential *) proposedCredential;
|
||||
|
||||
/**
|
||||
* Returns the protection space needing authentication.
|
||||
*/
|
||||
- (NSURLProtectionSpace *) protectionSpace;
|
||||
|
||||
/**
|
||||
* Returns the sender of the challenge ... the object to which callbacks
|
||||
* should be made while processing the challenge.
|
||||
*/
|
||||
- (id<NSURLAuthenticationChallengeSender>) sender;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
193
Headers/Foundation/NSURLCache.h
Normal file
193
Headers/Foundation/NSURLCache.h
Normal file
|
@ -0,0 +1,193 @@
|
|||
/* Interface for NSURLCache for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLCache_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLCache_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSData;
|
||||
@class NSDictionary;
|
||||
@class NSURLRequest;
|
||||
@class NSURLRequest;
|
||||
@class NSURLResponse;
|
||||
|
||||
/**
|
||||
* Specifies the cache storage policy.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NSURLCacheStorageAllowed, /** Unrestricted caching */
|
||||
NSURLCacheStorageAllowedInMemoryOnly, /** In memory caching only */
|
||||
NSURLCacheStorageNotAllowed, /** No caching allowed */
|
||||
} NSURLCacheStoragePolicy;
|
||||
|
||||
|
||||
/**
|
||||
* Encapsulates a cached response to a URL load request.
|
||||
*/
|
||||
@interface NSCachedURLResponse : NSObject <NSCoding, NSCopying>
|
||||
{
|
||||
@private
|
||||
void *_NSCachedURLResponseInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data with which the receiver was initialised.
|
||||
*/
|
||||
- (NSData *) data;
|
||||
|
||||
/**
|
||||
* Uses the NSURLCacheStorageAllowed policy to cache the specified
|
||||
* response and data.<br />
|
||||
* Returns the cached response.
|
||||
*/
|
||||
- (id) initWithResponse: (NSURLResponse *)response data: (NSData *)data;
|
||||
|
||||
/**
|
||||
* Returns the receiver initialized with the provided parameters.
|
||||
*/
|
||||
- (id) initWithResponse: (NSURLResponse *)response
|
||||
data: (NSData *)data
|
||||
userInfo: (NSDictionary *)userInfo
|
||||
storagePolicy: (NSURLCacheStoragePolicy)storagePolicy;
|
||||
|
||||
/**
|
||||
* Returns the response with which the receiver was initialised.
|
||||
*/
|
||||
- (NSURLResponse *) response;
|
||||
|
||||
/**
|
||||
* Returns the storage policy with which the receiver was initialised.
|
||||
*/
|
||||
- (NSURLCacheStoragePolicy) storagePolicy;
|
||||
|
||||
/**
|
||||
* Returns the user info dictionary with which the receiver was initialised
|
||||
* (if any).
|
||||
*/
|
||||
- (NSDictionary *) userInfo;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface NSURLCache : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLCacheInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the shared [NSURLCache] used throughout the process.<br />
|
||||
* If you are going to call this method to specify an alternative to
|
||||
* the default cache, you should do so before the shared cache is used
|
||||
* in order to avoid loss of data that was in the old cache.
|
||||
*/
|
||||
+ (void) setSharedURLCache: (NSURLCache *)cache;
|
||||
|
||||
/**
|
||||
* Returns the shared cache instance set by +setSharedURLCache: or,
|
||||
* if none has been set, returns an instance initialised with<br />
|
||||
* <deflist>
|
||||
* <term>Memory capacity</term>
|
||||
* <desc>4 megabytes</desc>
|
||||
* <term>Disk capacity</term>
|
||||
* <desc>20 megabytes</desc>
|
||||
* <term>Disk path</term>
|
||||
* <desc>user-library-path/Caches/current-app-name</desc>
|
||||
* </deflist>
|
||||
*/
|
||||
+ (NSURLCache *) sharedURLCache;
|
||||
|
||||
/**
|
||||
* Returns the [NSCachedURLResponse] cached for the specified request
|
||||
* or nil if there is no matching response in tthe cache.
|
||||
*/
|
||||
- (NSCachedURLResponse *) cachedResponseForRequest: (NSURLRequest *)request;
|
||||
|
||||
/**
|
||||
* Returns the current size (butes) of the data stored in the on-disk
|
||||
* cache.
|
||||
*/
|
||||
- (unsigned) currentDiskUsage;
|
||||
|
||||
/**
|
||||
* Returns the current size (butes) of the data stored in the in-memory
|
||||
* cache.
|
||||
*/
|
||||
- (unsigned) currentMemoryUsage;
|
||||
|
||||
/**
|
||||
* Returns the disk capacity (in bytes) of the cache.
|
||||
*/
|
||||
- (unsigned) diskCapacity;
|
||||
|
||||
/**
|
||||
* Returns the receiver initialised with the specified capacities
|
||||
* (in bytes) and using the specified location on disk for persistent
|
||||
* storage.
|
||||
*/
|
||||
- (id) initWithMemoryCapacity: (unsigned)memoryCapacity
|
||||
diskCapacity: (unsigned)diskCapacity
|
||||
diskPath: (NSString *)path;
|
||||
|
||||
/**
|
||||
* Returns the memory capacity (in bytes) of the cache.
|
||||
*/
|
||||
- (unsigned) memoryCapacity;
|
||||
|
||||
/**
|
||||
* Empties the cache.
|
||||
*/
|
||||
- (void) removeAllCachedResponses;
|
||||
|
||||
/**
|
||||
* Removes from the cache (if present) the [NSCachedURLResponse]
|
||||
* which was stored using the specified request.
|
||||
*/
|
||||
- (void) removeCachedResponseForRequest: (NSURLRequest *)request;
|
||||
|
||||
/**
|
||||
* Sets the disk capacity (in bytes) truncating cache contents if necessary.
|
||||
*/
|
||||
- (void) setDiskCapacity: (unsigned)diskCapacity;
|
||||
|
||||
/**
|
||||
* Sets the memory capacity (in bytes) truncating cache contents if necessary.
|
||||
*/
|
||||
- (void) setMemoryCapacity: (unsigned)memoryCapacity;
|
||||
|
||||
/**
|
||||
* Stores cachedResponse in the cache, keyed on request.<br />
|
||||
* Replaces any existing response with the same key.
|
||||
*/
|
||||
- (void) storeCachedResponse: (NSCachedURLResponse *)cachedResponse
|
||||
forRequest: (NSURLRequest *)request;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
228
Headers/Foundation/NSURLConnection.h
Normal file
228
Headers/Foundation/NSURLConnection.h
Normal file
|
@ -0,0 +1,228 @@
|
|||
/* Interface for NSURLConnection for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLConnection_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLConnection_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSCachedURLResponse;
|
||||
@class NSData;
|
||||
@class NSError;
|
||||
@class NSURLAuthenticationChallenge;
|
||||
@class NSURLRequest;
|
||||
@class NSURLResponse;
|
||||
|
||||
/**
|
||||
*/
|
||||
@interface NSURLConnection : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLConnectionInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a preliminary check to see if a load of the specified
|
||||
* request can be handled by an instance of this class.<br />
|
||||
* The results of this method may be invalidated by subsequent
|
||||
* changes to the request or changes to the registered protocols
|
||||
* etc.
|
||||
*/
|
||||
+ (BOOL) canHandleRequest: (NSURLRequest *)request;
|
||||
|
||||
/**
|
||||
* Allocates and returns the autoreleased instance which it initialises
|
||||
* using the -initWithRequest:delegate: method.
|
||||
*/
|
||||
+ (NSURLConnection *) connectionWithRequest: (NSURLRequest *)request
|
||||
delegate: (id)delegate;
|
||||
|
||||
/**
|
||||
* Cancel the asynchronous load in progress (if any) for this connection.
|
||||
*/
|
||||
- (void) cancel;
|
||||
|
||||
/** <init />
|
||||
* Initialises the receiver with the specified request (performing
|
||||
* a deep copy so that ithe request does not change during loading)
|
||||
* and delegate.<br />
|
||||
* This automatically initiates an asynchronous load for the request.<br />
|
||||
* Processing of the request is done in the thread which calls this
|
||||
* method, so the thread must run its current run loop
|
||||
* (in NSDefaultRunLoopMode) for processing to continue/complete.<br />
|
||||
* The delegate will receive callbacks informing it of the progress
|
||||
* of the load.
|
||||
*/
|
||||
- (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This category is an informal protocol specifying how an NSURLConnection
|
||||
* instance will communicate with its delegate to inform it of (and allow
|
||||
* it to manage) the progress of a load request.<br />
|
||||
* A load operation is performed by asynchronous I/O using the
|
||||
* run loop of the thread in which it was initiated, so all callbacks
|
||||
* will occur in that thread.<br />
|
||||
* The process of loading a resource occurs as follows -<br />
|
||||
* <list>
|
||||
* <item>
|
||||
* Any number of -connection:willSendRequest:redirectResponse:
|
||||
* messages may be sent to the delegate before any other messages
|
||||
* in this list are sent. This permits a chain of redirects to
|
||||
* be followed before eventual loading of 'real' data.
|
||||
* </item>
|
||||
* <item>
|
||||
* A -connection:didReceiveAuthenticationChallenge: message may be
|
||||
* sent to the delegate (where authentication is required) before
|
||||
* response data can be downloaded.
|
||||
* </item>
|
||||
* <item>
|
||||
* Any number of -connection:didReceiveResponse: messages
|
||||
* may be be sent to the delegate before a
|
||||
* -connection:didReceiveData: message. Usually there is exactly one
|
||||
* of these, but for multipart/x-mixed-replace there may be multiple
|
||||
* responses for each part, and if an error occurs in the download
|
||||
* the delegate may not receive a response at all.<br />
|
||||
* Delegates should discard previously handled data when they
|
||||
* receive a new response.
|
||||
* </item>
|
||||
* <item>
|
||||
* Any number of -connection:didReceiveData: messages may
|
||||
* be sent before the load completes as described below.
|
||||
* </item>
|
||||
* <item>
|
||||
* A single -connection:willCacheResponse: message may
|
||||
* be sent to the delegate after any -connection:didReceiveData:
|
||||
* messages are sent but before a -connectionDidFinishLoading: message
|
||||
* is sent.
|
||||
* </item>
|
||||
* <item>
|
||||
* Unless the NSURLConnection receives a -cancel message,
|
||||
* the delegate will receive one and only one of
|
||||
* -connectionDidFinishLoading:, or
|
||||
* -connection:didFailWithError: message, but never
|
||||
* both.<br />
|
||||
* Once either of these terminal messages is sent the
|
||||
* delegate will receive no further messages from the
|
||||
* NSURLConnection.
|
||||
* </item>
|
||||
* </list>
|
||||
*/
|
||||
@interface NSObject (NSURLConnectionDelegate)
|
||||
|
||||
/**
|
||||
* Instructs the delegate that authentication for challenge has
|
||||
* been cancelled for the request loading on connection.
|
||||
*/
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/*
|
||||
* Called when an NSURLConnection has failed to load successfully.
|
||||
*/
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didFailWithError: (NSError *)error;
|
||||
|
||||
/**
|
||||
* Called when an NSURLConnection has finished loading successfully.
|
||||
*/
|
||||
- (void) connectionDidFinishLoading: (NSURLConnection *)connection;
|
||||
|
||||
/**
|
||||
* Called when an authentication challenge is received ... the delegate
|
||||
* should send -useCredential:forAuthenticationChallenge: or
|
||||
* -continueWithoutCredentialForAuthenticationChallenge: or
|
||||
* -cancelAuthenticationChallenge: to the challenge sender when done.
|
||||
*/
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
* Called when content data arrives during a load operations ... this
|
||||
* may be incremental or may be the compolete data for the load.
|
||||
*/
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveData: (NSData *)data;
|
||||
|
||||
/**
|
||||
* Called when enough information to build a NSURLResponse object has
|
||||
* been received.
|
||||
*/
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveResponse: (NSURLResponse *)response;
|
||||
|
||||
/**
|
||||
* Called with the cachedResponse to be stored in the cache.
|
||||
* The delegate can inspect the cachedResponse and return a modified
|
||||
* copy if if wants changed to what whill be stored.<br />
|
||||
* If it returns nil, nothing will be stored in the cache.
|
||||
*/
|
||||
- (NSCachedURLResponse *) connection: (NSURLConnection *)connection
|
||||
willCacheResponse: (NSCachedURLResponse *)cachedResponse;
|
||||
|
||||
/**
|
||||
* Informs the delegate that the connection must change the URL of
|
||||
* the request in order to continue with the load operation.<br />
|
||||
* This allows the delegate to ionspect and/or modify a copy of the request
|
||||
* before the connection continues loading it. Normally the delegate
|
||||
* can return the request unmodifield.<br />
|
||||
* The redirection can be rejectected by the delegate calling -cancel
|
||||
* or returning nil.<br />
|
||||
* Cancelling the load will simply stop it, but returning nil will
|
||||
* cause it to complete with a redirection failure.<br />
|
||||
* As a special case, this method may be called with a nil response,
|
||||
* indicating a change of URL made internally by the system rather than
|
||||
* due to a response from the server.
|
||||
*/
|
||||
- (NSURLRequest *) connection: (NSURLConnection *)connection
|
||||
willSendRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)response;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* An interface to perform synchronous loading of URL requests.
|
||||
*/
|
||||
@interface NSURLConnection (NSURLConnectionSynchronousLoading)
|
||||
|
||||
/**
|
||||
* Performs a synchronous load of request and returns the
|
||||
* [NSURLResponse] in response.<br />
|
||||
* Returns the result of the load or nil if the load failed.
|
||||
*/
|
||||
+ (NSData *) sendSynchronousRequest: (NSURLRequest *)request
|
||||
returningResponse: (NSURLResponse **)response
|
||||
error: (NSError **)error;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
98
Headers/Foundation/NSURLCredential.h
Normal file
98
Headers/Foundation/NSURLCredential.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/* Interface for NSURLCredential for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLCredential_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLCredential_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSString;
|
||||
|
||||
/**
|
||||
* Controls how long a credential is retained.
|
||||
*/
|
||||
typedef enum {
|
||||
NSURLCredentialPersistenceNone, /** Don't save at all */
|
||||
NSURLCredentialPersistenceForSession, /** Save for current session */
|
||||
NSURLCredentialPersistencePermanent /** Save forever (on disk) */
|
||||
} NSURLCredentialPersistence;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a user/password credential
|
||||
*/
|
||||
@interface NSURLCredential : NSObject <NSCopying>
|
||||
{
|
||||
@private
|
||||
void *_NSURLCredentialInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an autoreleased instance initialised using the
|
||||
* -initWithUser:password:persistence: method.
|
||||
*/
|
||||
+ (NSURLCredential *) credentialWithUser: (NSString *)user
|
||||
password: (NSString *)password
|
||||
persistence: (NSURLCredentialPersistence)persistence;
|
||||
|
||||
/**
|
||||
* Determine whether the credential has a password.
|
||||
*/
|
||||
- (BOOL) hasPassword;
|
||||
|
||||
/** <init />
|
||||
* Initialises and returns the receiver with a user name and password.<br />
|
||||
* The user identifies the credential and must be specified but the
|
||||
* password may be nil.
|
||||
*/
|
||||
- (id) initWithUser: (NSString *)user
|
||||
password: (NSString *)password
|
||||
persistence: (NSURLCredentialPersistence)persistence;
|
||||
|
||||
/**
|
||||
* Returns the password for the receiver.<br />
|
||||
* May require prompting of the user to authorize retrieval.<br />
|
||||
* May return nil if retrieval of the password fails (eg authorization
|
||||
* failure) even if the credential actually has a password. Call the
|
||||
* -hasPassword method to determine whether the credential has a
|
||||
* password
|
||||
*/
|
||||
- (NSString *) password;
|
||||
|
||||
/**
|
||||
* Return the presistence of this credential.
|
||||
*/
|
||||
- (NSURLCredentialPersistence) persistence;
|
||||
|
||||
/**
|
||||
* Returns the user string for the receiver
|
||||
*/
|
||||
- (NSString *) user;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
103
Headers/Foundation/NSURLCredentialStorage.h
Normal file
103
Headers/Foundation/NSURLCredentialStorage.h
Normal file
|
@ -0,0 +1,103 @@
|
|||
/* Interface for NSURLCredentialStorage for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLCredentialStorage_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLCredentialStorage_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSDictionary;
|
||||
@class NSString;
|
||||
@class NSURLCredential;
|
||||
@class NSURLProtectionSpace;
|
||||
|
||||
/**
|
||||
* Notification sent when the set of stored credentials changes.
|
||||
*/
|
||||
extern NSString *const NSURLCredentialStorageChangedNotification;
|
||||
|
||||
/**
|
||||
* Provides shared storage of credentials.
|
||||
*/
|
||||
@interface NSURLCredentialStorage : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLCredentialStorageInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shared credential storage object.
|
||||
*/
|
||||
+ (NSURLCredentialStorage *) sharedCredentialStorage;
|
||||
|
||||
/**
|
||||
* Returns a dictionary of dictionaries ... with [NSURLProtectionSpace]
|
||||
* objects as the keys in the outer dictionary, and values which are
|
||||
* dictionaries of the credentails within each protection space.
|
||||
*/
|
||||
- (NSDictionary *) allCredentials;
|
||||
|
||||
/**
|
||||
* Returns a dictionary mapping usernames to credentials
|
||||
* for the specified protection space.<br />
|
||||
* Each username is a unique identifier for a credential
|
||||
* within a protection space.
|
||||
*/
|
||||
- (NSDictionary *) credentialsForProtectionSpace: (NSURLProtectionSpace *)space;
|
||||
|
||||
/**
|
||||
* Returns the default credential for the specified protection space, or
|
||||
* nil if none is set.
|
||||
*/
|
||||
- (NSURLCredential *) defaultCredentialForProtectionSpace:
|
||||
(NSURLProtectionSpace *)space;
|
||||
|
||||
/**
|
||||
* Removes the credential from both in-memory and persistent storage
|
||||
* for the specified protection space.
|
||||
*/
|
||||
- (void) removeCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space;
|
||||
|
||||
/**
|
||||
* Sets credential in the storage for the protection space specified.<br />
|
||||
* This replaces any old value with the same username.
|
||||
*/
|
||||
- (void) setCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space;
|
||||
|
||||
/**
|
||||
* Sets the default credential for the protection space. Also calls
|
||||
* -setCredential:forProtectionSpace: if the credential has not already
|
||||
* been set in space.
|
||||
*/
|
||||
- (void) setDefaultCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
206
Headers/Foundation/NSURLDownload.h
Normal file
206
Headers/Foundation/NSURLDownload.h
Normal file
|
@ -0,0 +1,206 @@
|
|||
/* Interface for NSURLDownload for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLDownload_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLDownload_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSData;
|
||||
@class NSError;
|
||||
@class NSString;
|
||||
@class NSURLAuthenticationChallenge;
|
||||
@class NSURLRequest;
|
||||
@class NSURLResponse;
|
||||
|
||||
/**
|
||||
* Handles download to file.
|
||||
*/
|
||||
@interface NSURLDownload : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLDownloadInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a flag saying whether the class can resume a download
|
||||
* which was decoded with MIMEType.<br />
|
||||
*/
|
||||
+ (BOOL) canResumeDownloadDecodedWithEncodingMIMEType: (NSString *)MIMEType;
|
||||
|
||||
/**
|
||||
* Cancels the download and deletes any downloaded file.
|
||||
*/
|
||||
- (void) cancel;
|
||||
|
||||
/**
|
||||
* Returns a flag saying whether a partially downloaded file should be
|
||||
* deleted on failure ... YES by default.
|
||||
*/
|
||||
- (BOOL) deletesFileUponFailure;
|
||||
|
||||
/**
|
||||
* Initialises the receiver and start the download process.
|
||||
*/
|
||||
- (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate;
|
||||
|
||||
/** <init />
|
||||
* Initialises the receiver with data from a previous partial
|
||||
* download and resumes (or restarts) the downloading process.
|
||||
*/
|
||||
- (id) initWithResumeData: (NSData *)resumeData
|
||||
delegate: (id)delegate
|
||||
path: (NSString *)path;
|
||||
|
||||
/**
|
||||
* Returns the receiver's request.
|
||||
*/
|
||||
- (NSURLRequest *) request;
|
||||
|
||||
/**
|
||||
* Returns state data of an incomplete download ... this data should be
|
||||
* sufficient to resume/restart the download using the
|
||||
* -initWithResumeData:delegate:path: method.<br />
|
||||
* Returns nil if a resume is probably impossible.<br />
|
||||
* NB. You need to call -setDeletesFileUponFailure: to turn off deletion
|
||||
* if you wish to be able to resume an incomplete download.
|
||||
*/
|
||||
- (NSData *) resumeData;
|
||||
|
||||
/**
|
||||
* Sets a flag to determine if downloaded file is be deleted upon failure.
|
||||
* This is YES by default and needs to be set to NO if you want to be able
|
||||
* to attempt to resume a failed download.
|
||||
*/
|
||||
- (void) setDeletesFileUponFailure: (BOOL)deletesFileUponFailure;
|
||||
|
||||
/**
|
||||
* Sets the path to which the file is downloaded.<br />
|
||||
* May be called (once only) after initialisation of the receiver or when the
|
||||
* delegate receives a -decideDestinationWithSuggestedFilename: message.<br />
|
||||
* Appends a number to the filename if allowOverwrite is NO and a file
|
||||
* already exists at path.<br />
|
||||
* See -didCreateDestination: also.
|
||||
*/
|
||||
- (void) setDestination: (NSString *)path allowOverwrite: (BOOL)allowOverwrite;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* Protocol for delegate used to report the progress of the download.
|
||||
*/
|
||||
@interface NSObject (NSURLDownloadDelegate)
|
||||
|
||||
/**
|
||||
* Called immediately once the download has started.
|
||||
*/
|
||||
- (void) downloadDidBegin: (NSURLDownload *)download;
|
||||
|
||||
/**
|
||||
* Called when the download completes after having received all data.
|
||||
*/
|
||||
- (void) downloadDidFinish: (NSURLDownload *)download;
|
||||
|
||||
/**
|
||||
* Called when it's time to establish a name for the downloaded file ...
|
||||
* the delegate may decide a name by inspecting the response.<br />
|
||||
* The delegate should call -setDestination:allowOverwrite: to set the
|
||||
* filename to be used.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
decideDestinationWithSuggestedFilename: (NSString *)filename;
|
||||
|
||||
/**
|
||||
* Called when authentication of a request is cancelled.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
* Called when the download has created the downloaded file.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didCreateDestination: (NSString *)path;
|
||||
|
||||
/**
|
||||
* Called when the download fails.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download didFailWithError: (NSError *)error;
|
||||
|
||||
/**
|
||||
* Called when an authentication challenge is received.<br />
|
||||
* The delegate should send -useCredential:forAuthenticationChallenge: or
|
||||
* -continueWithoutCredentialForAuthenticationChallenge: or -cancel to
|
||||
* the connection sender when done.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
* Called when some data has been received.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveDataOfLength: (unsigned)length;
|
||||
|
||||
/**
|
||||
* Called when a response is received.<br />
|
||||
* Multiple responses may be received on the same download (eg with server push)
|
||||
* and the delegate should be prepared to treat each separately.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveResponse: (NSURLResponse *)response;
|
||||
|
||||
/**
|
||||
* Called if the download file is encoded ... the delegate should return
|
||||
* YES if the downloaded data is to be decoded, NO otherwise.
|
||||
*/
|
||||
- (BOOL) download: (NSURLDownload *)download
|
||||
shouldDecodeSourceDataOfMIMEType: (NSString *)encodingType;
|
||||
|
||||
/**
|
||||
* Called when a download is resuming from previously stored data and
|
||||
* a response has been received from the server.<br />
|
||||
* The startingBytes is the offset from which the downloaded data
|
||||
* will actually commence ... and may be zero if the entire download
|
||||
* must be redone.
|
||||
*/
|
||||
- (void) download: (NSURLDownload *)download
|
||||
willResumeWithResponse: (NSURLResponse *)response
|
||||
fromByte: (long long)startingByte;
|
||||
|
||||
/**
|
||||
* Called if a new request has to be sent due to redirection.<br />
|
||||
* Must return the request argument (or a modified copy of it)
|
||||
* to have the process continue.
|
||||
*/
|
||||
- (NSURLRequest *) download: (NSURLDownload *)download
|
||||
willSendRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)redirectResponse;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
88
Headers/Foundation/NSURLError.h
Normal file
88
Headers/Foundation/NSURLError.h
Normal file
|
@ -0,0 +1,88 @@
|
|||
/* Interface for NSURLError for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLError_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLError_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSString;
|
||||
|
||||
/**
|
||||
* The domain for a URL error.
|
||||
*/
|
||||
extern NSString * const NSURLErrorDomain;
|
||||
|
||||
/**
|
||||
* Obtain the URL which caused the failure
|
||||
*/
|
||||
extern NSString * const NSErrorFailingURLStringKey;
|
||||
|
||||
/**
|
||||
* Error codes for URL errors
|
||||
*/
|
||||
enum
|
||||
{
|
||||
NSURLErrorUnknown = -1,
|
||||
NSURLErrorCancelled = -999,
|
||||
NSURLErrorBadURL = -1000,
|
||||
NSURLErrorTimedOut = -1001,
|
||||
NSURLErrorUnsupportedURL = -1002,
|
||||
NSURLErrorCannotFindHost = -1003,
|
||||
NSURLErrorCannotConnectToHost = -1004,
|
||||
NSURLErrorNetworkConnectionLost = -1005,
|
||||
NSURLErrorDNSLookupFailed = -1006,
|
||||
NSURLErrorHTTPTooManyRedirects = -1007,
|
||||
NSURLErrorResourceUnavailable = -1008,
|
||||
NSURLErrorNotConnectedToInternet = -1009,
|
||||
NSURLErrorRedirectToNonExistentLocation = -1010,
|
||||
NSURLErrorBadServerResponse = -1011,
|
||||
NSURLErrorUserCancelledAuthentication = -1012,
|
||||
NSURLErrorUserAuthenticationRequired = -1013,
|
||||
NSURLErrorZeroByteResource = -1014,
|
||||
NSURLErrorFileDoesNotExist = -1100,
|
||||
NSURLErrorFileIsDirectory = -1101,
|
||||
NSURLErrorNoPermissionsToReadFile = -1102,
|
||||
NSURLErrorSecureConnectionFailed = -1200,
|
||||
NSURLErrorServerCertificateHasBadDate = -1201,
|
||||
NSURLErrorServerCertificateUntrusted = -1202,
|
||||
NSURLErrorServerCertificateHasUnknownRoot = -1203,
|
||||
NSURLErrorServerCertificateNotYetValid = -1204,
|
||||
NSURLErrorClientCertificateRejected = -1205,
|
||||
NSURLErrorCannotLoadFromNetwork = -2000,
|
||||
|
||||
NSURLErrorCannotCreateFile = -3000,
|
||||
NSURLErrorCannotOpenFile = -3001,
|
||||
NSURLErrorCannotCloseFile = -3002,
|
||||
NSURLErrorCannotWriteToFile = -3003,
|
||||
NSURLErrorCannotRemoveFile = -3004,
|
||||
NSURLErrorCannotMoveFile = -3005,
|
||||
NSURLErrorDownloadDecodingFailedMidStream = -3006,
|
||||
NSURLErrorDownloadDecodingFailedToComplete = -3007,
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
129
Headers/Foundation/NSURLProtectionSpace.h
Normal file
129
Headers/Foundation/NSURLProtectionSpace.h
Normal file
|
@ -0,0 +1,129 @@
|
|||
/* Interface for NSURLProtectionSpace for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLProtectionSpace_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLProtectionSpace_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSString;
|
||||
|
||||
extern NSString * const NSURLProtectionSpaceFTPProxy; /** An FTP proxy */
|
||||
extern NSString * const NSURLProtectionSpaceHTTPProxy; /** An HTTP proxy */
|
||||
extern NSString * const NSURLProtectionSpaceHTTPSProxy; /** An HTTPS proxy */
|
||||
extern NSString * const NSURLProtectionSpaceSOCKSProxy; /** A SOCKS proxy */
|
||||
|
||||
/** Default authentication */
|
||||
extern NSString * const NSURLAuthenticationMethodDefault;
|
||||
|
||||
/** HTML form authentication */
|
||||
extern NSString * const NSURLAuthenticationMethodHTMLForm;
|
||||
|
||||
/** HTTP Basic authentication */
|
||||
extern NSString * const NSURLAuthenticationMethodHTTPBasic;
|
||||
|
||||
/** HTTP Digest authentication */
|
||||
extern NSString * const NSURLAuthenticationMethodHTTPDigest;
|
||||
|
||||
|
||||
/**
|
||||
* Class to encapsulate a protection space ... where authentication is
|
||||
* required.
|
||||
*/
|
||||
@interface NSURLProtectionSpace : NSObject <NSCopying>
|
||||
{
|
||||
@private
|
||||
void *_NSURLProtectionSpaceInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the authentication method used for this protection space.
|
||||
*/
|
||||
- (NSString *) authenticationMethod;
|
||||
|
||||
/**
|
||||
* Returns the host (or proxy host) set in the receiver.
|
||||
*/
|
||||
- (NSString *) host;
|
||||
|
||||
/**
|
||||
* Initialises the receiver with host, port, and protocol identifying the
|
||||
* protection space. For some protocols the realm identifies a space
|
||||
* within the host, for others it may be nil.
|
||||
*/
|
||||
- (id) initWithHost: (NSString *)host
|
||||
port: (int)port
|
||||
protocol: (NSString *)protocol
|
||||
realm: (NSString *)realm
|
||||
authenticationMethod: (NSString *)authenticationMethod;
|
||||
|
||||
/**
|
||||
* This is like -initWithHost:port:protocol:realm:authenticationMethod:
|
||||
* except that it uses a proxy host and proxy type rather than an actual
|
||||
* host and a protocol.
|
||||
*/
|
||||
- (id) initWithProxyHost: (NSString *)host
|
||||
port: (int)port
|
||||
type: (NSString *)type
|
||||
realm: (NSString *)realm
|
||||
authenticationMethod: (NSString *)authenticationMethod;
|
||||
|
||||
/**
|
||||
* Returns a flag to indicate whether this protection space is on a proxy
|
||||
* server or not.
|
||||
*/
|
||||
- (BOOL) isProxy;
|
||||
|
||||
/**
|
||||
* Returns the port set for this receiver or zero if none was set.
|
||||
*/
|
||||
- (int) port;
|
||||
|
||||
/**
|
||||
* Returns the protocol of the receiver or nil if it is a proxy.
|
||||
*/
|
||||
- (NSString *) protocol;
|
||||
|
||||
/**
|
||||
* Returns the proxy type set for the receiver or nil if it's not a proxy.
|
||||
*/
|
||||
- (NSString *) proxyType;
|
||||
|
||||
/**
|
||||
* Returns the realm (or nil) which was set in the receiver upon initialisation.
|
||||
*/
|
||||
- (NSString *) realm;
|
||||
|
||||
/**
|
||||
* Returns a flag to indicate whether the password for this protection space
|
||||
* will be sent over a secure mechanism.
|
||||
*/
|
||||
- (BOOL) receivesCredentialSecurely;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
222
Headers/Foundation/NSURLProtocol.h
Normal file
222
Headers/Foundation/NSURLProtocol.h
Normal file
|
@ -0,0 +1,222 @@
|
|||
/* Interface for NSURLProtocol for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLProtocol_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLProtocol_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
#include <Foundation/NSURLCache.h>
|
||||
|
||||
@class NSCachedURLResponse;
|
||||
@class NSError;
|
||||
@class NSMutableURLRequest;
|
||||
@class NSURLAuthenticationChallenge;
|
||||
@class NSURLConnection;
|
||||
@class NSURLProtocol;
|
||||
@class NSURLRequest;
|
||||
@class NSURLResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Defines the API for NSURLProtocol loading
|
||||
*/
|
||||
@protocol NSURLProtocolClient <NSObject>
|
||||
|
||||
/**
|
||||
* Informs a client that a cached response is valid.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
cachedResponseIsValid: (NSCachedURLResponse *)cachedResponse;
|
||||
|
||||
/**
|
||||
* Informs a client that loading of a request has failed.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didFailWithError: (NSError *)error;
|
||||
|
||||
/**
|
||||
* Informs a client that data has been loaded. Only new data since the
|
||||
* last call to this method must be provided.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didLoadData: (NSData *)data;
|
||||
|
||||
/**
|
||||
* Informs a client that an authentication challenge has been received.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
/**
|
||||
* Informs a client that a response for the current load has been created.<br />
|
||||
* Also supplies the policy to be used for caching the response.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveResponse: (NSURLResponse *)response
|
||||
cacheStoragePolicy: (NSURLCacheStoragePolicy)policy;
|
||||
|
||||
/**
|
||||
* Informs a client that a redirect has occurred.<br />
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
wasRedirectedToRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)redirectResponse;
|
||||
|
||||
|
||||
/**
|
||||
* Informs a client that loading of a request has successfully finished.
|
||||
*/
|
||||
- (void) URLProtocolDidFinishLoading: (NSURLProtocol *)protocol;
|
||||
|
||||
/**
|
||||
* Informs a client that an authentication challenge has been cancelled.
|
||||
*/
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
* <p>Subclasses of NSURLProtocol implement basic handling of URL
|
||||
* loading for specific protocols. The NSURLProtocol class
|
||||
* itsself is a semi-abstract class giving the essential
|
||||
* structure for the subclasses.
|
||||
* </p>
|
||||
* <p>You never instantiate NSURLProtocol yourself ... it should only
|
||||
* ever be done by other classes within mthe URL loading system.
|
||||
* </p>
|
||||
*/
|
||||
@interface NSURLProtocol : NSObject
|
||||
{
|
||||
@private
|
||||
void *_NSURLProtocolInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows subclasses to provide access to proptocol specific
|
||||
* properties, returning the property of request stored by the
|
||||
* name key or nil if no property had been stored using that
|
||||
* key in the request.
|
||||
*/
|
||||
+ (id) propertyForKey: (NSString *)key inRequest: (NSURLRequest *)request;
|
||||
|
||||
/**
|
||||
* Registers the specified class so that it can be used to load requests.<br />
|
||||
* When the system is determining which class to use to handle a
|
||||
* request it examines them in a most recently registered first order.<br />
|
||||
* The +canInitWithRequest: method is used to determine whether a class
|
||||
* may be used to handle a particular request or not.
|
||||
* Returns YES if registered (ie the class is an NSURLProtocol subclass),
|
||||
* NO otherwise.
|
||||
*/
|
||||
+ (BOOL) registerClass: (Class)protocolClass;
|
||||
|
||||
/**
|
||||
* Allows subclasses to provide a way to set protocol specific properties,
|
||||
* setting the property named key to value in the request.
|
||||
*/
|
||||
+ (void) setProperty: (id)value
|
||||
forKey: (NSString *)key
|
||||
inRequest: (NSMutableURLRequest *)request;
|
||||
|
||||
/**
|
||||
* Unregisters a class which was previously registered using the
|
||||
* +registerClass: method.
|
||||
*/
|
||||
+ (void) unregisterClass: (Class)protocolClass;
|
||||
|
||||
/**
|
||||
* Returns the cachedResponse of the receiver.
|
||||
*/
|
||||
- (NSCachedURLResponse *) cachedResponse;
|
||||
|
||||
/**
|
||||
* Returns the client associated with the receiver.
|
||||
*/
|
||||
- (id <NSURLProtocolClient>) client;
|
||||
|
||||
/**
|
||||
* Initialises the receiver with request, cachedResponse and client.<br />
|
||||
* The cachedResponse may be the result of a previous load of the
|
||||
* request (in which case the protocol may validate and use it).<br />
|
||||
* The client is the object which receives messages about the progress
|
||||
* of the load.
|
||||
*/
|
||||
- (id) initWithRequest: (NSURLRequest *)request
|
||||
cachedResponse: (NSCachedURLResponse *)cachedResponse
|
||||
client: (id <NSURLProtocolClient>)client;
|
||||
|
||||
/**
|
||||
* Returns the request handled by the receiver.
|
||||
*/
|
||||
- (NSURLRequest *) request;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* This category lists the methods which a subclass must implement
|
||||
* in order to produce a working protocol.
|
||||
*/
|
||||
@interface NSURLProtocol (Subclassing)
|
||||
|
||||
/** <override-subclass />
|
||||
* This method is called to decide whether a class can deal with
|
||||
* the specified request. The abstract class implementation
|
||||
* raises an exception.
|
||||
*/
|
||||
+ (BOOL) canInitWithRequest: (NSURLRequest *)request;
|
||||
|
||||
/** <override-subclass />
|
||||
* Returns the 'canonical' version of the request.<br />
|
||||
* The canonical form is used to look up requests in the cache by
|
||||
* checking for equality.<br />
|
||||
* The abnstract class implementation simply returns request.
|
||||
*/
|
||||
+ (NSURLRequest *) canonicalRequestForRequest: (NSURLRequest *)request;
|
||||
|
||||
/** <override-subclass />
|
||||
* Compares two requests for equivalence for caching purposes.<br />
|
||||
* The abstract class implementaton just uses [NSObject-isEqual:]
|
||||
*/
|
||||
+ (BOOL) requestIsCacheEquivalent: (NSURLRequest *)a
|
||||
toRequest: (NSURLRequest *)b;
|
||||
|
||||
/** <override-subclass />
|
||||
* Starts loading of a request.
|
||||
*/
|
||||
- (void) startLoading;
|
||||
|
||||
/** <override-subclass />
|
||||
* Stops loading of a request (eg when the load is cancelled).
|
||||
*/
|
||||
- (void) stopLoading;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
275
Headers/Foundation/NSURLRequest.h
Normal file
275
Headers/Foundation/NSURLRequest.h
Normal file
|
@ -0,0 +1,275 @@
|
|||
/* Interface for NSURLRequest for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLRequest_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLRequest_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
@class NSData;
|
||||
@class NSDate;
|
||||
@class NSDictionary;
|
||||
@class NSInputStream;
|
||||
@class NSString;
|
||||
@class NSURL;
|
||||
|
||||
/**
|
||||
* <deflist>
|
||||
* <term>NSURLRequestUseProtocolCachePolicy</term>
|
||||
* <desc>
|
||||
* Says that any protocol specific cache policy should be
|
||||
* used ... this is the default.
|
||||
* </desc>
|
||||
* <term>NSURLRequestReloadIgnoringCacheData</term>
|
||||
* <desc>
|
||||
* Says the data should be re-loaded from source rather
|
||||
* than any cached data being used, irrespective of any
|
||||
* protocol standard.
|
||||
* </desc>
|
||||
* <term>NSURLRequestReturnCacheDataElseLoad</term>
|
||||
* <desc>
|
||||
* Says to use cached data if any is available, but to
|
||||
* load from source if the cache is empty. Ignores any
|
||||
* protocol specific logic (like cache aging).
|
||||
* </desc>
|
||||
* <term>NSURLRequestReturnCacheDataDontLoad</term>
|
||||
* <desc>
|
||||
* Says to use cached data if any is available, but to
|
||||
* return nil without loading if the cache is empty.
|
||||
* </desc>
|
||||
* </deflist>
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
NSURLRequestUseProtocolCachePolicy,
|
||||
NSURLRequestReloadIgnoringCacheData,
|
||||
NSURLRequestReturnCacheDataElseLoad,
|
||||
NSURLRequestReturnCacheDataDontLoad,
|
||||
} NSURLRequestCachePolicy;
|
||||
|
||||
|
||||
/**
|
||||
* This class encapsulates information about a request to load a
|
||||
* URL, how to cache the results, and when to deal with a slow/hung
|
||||
* load process by timing out.
|
||||
*/
|
||||
@interface NSURLRequest : NSObject <NSCoding, NSCopying, NSMutableCopying>
|
||||
{
|
||||
@private
|
||||
void *_NSURLRequestInternal;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an autoreleased instance initialised with the specified URL
|
||||
* and with the default cache policy (NSURLRequestUseProtocolCachePolicy)
|
||||
* and a sixty second timeout.
|
||||
*/
|
||||
+ (id) requestWithURL: (NSURL *)URL;
|
||||
|
||||
/**
|
||||
* Returns an autoreleased instance initialised with the specified URL,
|
||||
* cachePolicy, and timeoutInterval.
|
||||
*/
|
||||
+ (id) requestWithURL: (NSURL *)URL
|
||||
cachePolicy: (NSURLRequestCachePolicy)cachePolicy
|
||||
timeoutInterval: (NSTimeInterval)timeoutInterval;
|
||||
|
||||
/**
|
||||
* Returns the cache policy associated with the receiver.
|
||||
*/
|
||||
- (NSURLRequestCachePolicy) cachePolicy;
|
||||
|
||||
/**
|
||||
* Initialises the reveiver with the specified URL
|
||||
* and with the default cache policy (NSURLRequestUseProtocolCachePolicy)
|
||||
* and a sixty second timeout.
|
||||
*/
|
||||
- (id) initWithURL: (NSURL *)URL;
|
||||
|
||||
/**
|
||||
* Initialises the receiver with the specified URL,
|
||||
* cachePolicy, and timeoutInterval.
|
||||
*/
|
||||
- (id) initWithURL: (NSURL *)URL
|
||||
cachePolicy: (NSURLRequestCachePolicy)cachePolicy
|
||||
timeoutInterval: (NSTimeInterval)timeoutInterval;
|
||||
|
||||
/**
|
||||
* Returns the main document URL for the receiver.<br />
|
||||
* Currently unused.<br />
|
||||
* This is intended for use with frames and similar situations where
|
||||
* a main document has a large number of subsidiary documents.
|
||||
*/
|
||||
- (NSURL *) mainDocumentURL;
|
||||
|
||||
/**
|
||||
* Returns the timeout interval associated with the receiver.<br />
|
||||
* This is a value in seconds specifying how long the load process
|
||||
* may be inactive (waiting for data to arrive from the server)
|
||||
* before the load is mconsidered to have failed due to a timeout.
|
||||
*/
|
||||
- (NSTimeInterval) timeoutInterval;
|
||||
|
||||
/**
|
||||
* Returns the URL associated with the receiver.
|
||||
*/
|
||||
- (NSURL *) URL;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
@interface NSMutableURLRequest : NSURLRequest
|
||||
|
||||
/**
|
||||
* Sets the receiver's cache policy.
|
||||
*/
|
||||
- (void) setCachePolicy: (NSURLRequestCachePolicy)cachePolicy;
|
||||
|
||||
/**
|
||||
* Sets the receiver's main document.
|
||||
*/
|
||||
- (void) setMainDocumentURL: (NSURL *)URL;
|
||||
|
||||
/**
|
||||
* Sets the receiver's timeout policy.
|
||||
*/
|
||||
- (void) setTimeoutInterval: (NSTimeInterval)seconds;
|
||||
|
||||
/**
|
||||
* Sets the receiver's URL
|
||||
*/
|
||||
- (void) setURL: (NSURL *)URL;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HTTP specific additions to NSURLRequest
|
||||
*/
|
||||
@interface NSURLRequest (NSHTTPURLRequest)
|
||||
|
||||
/**
|
||||
* Returns a dictionary of the HTTP header fields associated with the
|
||||
* receiver.
|
||||
*/
|
||||
- (NSDictionary *) allHTTPHeaderFields;
|
||||
|
||||
/**
|
||||
* Returns the body of the reques ... this is the data sent in a POST
|
||||
* request.
|
||||
*/
|
||||
- (NSData *) HTTPBody;
|
||||
|
||||
#if OS_API_VERSION(100400,GS_API_LATEST)
|
||||
/**
|
||||
* Returns the currently set stream (if any) to be used to provide data
|
||||
* to send as the request body.<br />
|
||||
* Of course, any attempt to modify this stream may mess up the load
|
||||
* operation in progress.
|
||||
*/
|
||||
- (NSInputStream *) HTTPBodyStream;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the HTTP method assiciated with the receiver.
|
||||
*/
|
||||
- (NSString *) HTTPMethod;
|
||||
|
||||
/**
|
||||
* Returns a flag indicating whether this request should use standard
|
||||
* cookie handling (sending of cookies with the request and storing
|
||||
* any cookies returned in the response.
|
||||
*/
|
||||
- (BOOL) HTTPShouldHandleCookies;
|
||||
|
||||
/**
|
||||
* Returns the value for a particular HTTP header field (by case
|
||||
* insensitive comparison) or nil if no such header is set.
|
||||
*/
|
||||
- (NSString *) valueForHTTPHeaderField: (NSString *)field;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
@interface NSMutableURLRequest (NSMutableHTTPURLRequest)
|
||||
|
||||
/**
|
||||
* Appends the value to the specified header field, automatically inserting
|
||||
* a comman field delimiter if necessary.
|
||||
*/
|
||||
- (void) addValue: (NSString *)value forHTTPHeaderField: (NSString *)field;
|
||||
|
||||
/**
|
||||
* Sets all the string values in the supplied headerFields
|
||||
* dictionary as header values in the receiver.<br />
|
||||
* Non-string values are ignored.
|
||||
*/
|
||||
- (void) setAllHTTPHeaderFields: (NSDictionary *)headerFields;
|
||||
|
||||
#if OS_API_VERSION(100400,GS_API_LATEST)
|
||||
/**
|
||||
* Sets the request body to be the contents of the given stream.<br />
|
||||
* The stream should be unopened when it is set, and the load process
|
||||
* for the request will open the stream and read its entire content
|
||||
* forwarding it to the remote server.<br />
|
||||
* Clears any value previously set by -setHTTPBody: or -setHTTPBodyStream:
|
||||
*/
|
||||
- (void) setHTTPBodyStream: (NSInputStream *)inputStream;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets the data to be sent as the body of the HTTP request.<br />
|
||||
* Clears any value previously set by -setHTTPBodyStream: or -setHTTPBody:
|
||||
*/
|
||||
- (void) setHTTPBody: (NSData *)data;
|
||||
|
||||
/**
|
||||
* Sets the method of the receiver.
|
||||
*/
|
||||
- (void) setHTTPMethod: (NSString *)method;
|
||||
|
||||
/**
|
||||
* Sets a flag to say whether cookies should automatically be added
|
||||
* to the request and whether cookies in the response should be used.
|
||||
*/
|
||||
- (void) setHTTPShouldHandleCookies: (BOOL)should;
|
||||
|
||||
/**
|
||||
* Sets the value for the sapecified header field, replacing any
|
||||
* previously set value.
|
||||
*/
|
||||
- (void) setValue: (NSString *)value forHTTPHeaderField: (NSString *)field;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
120
Headers/Foundation/NSURLResponse.h
Normal file
120
Headers/Foundation/NSURLResponse.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* Interface for NSURLResponse for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#ifndef __NSURLResponse_h_GNUSTEP_BASE_INCLUDE
|
||||
#define __NSURLResponse_h_GNUSTEP_BASE_INCLUDE
|
||||
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
#if OS_API_VERSION(100200,GS_API_LATEST) && GS_API_VERSION(011300,GS_API_LATEST)
|
||||
|
||||
|
||||
@class NSDictionary;
|
||||
@class NSString;
|
||||
@class NSURL;
|
||||
|
||||
#define NSURLResponseUnknownLength ((long long)-1)
|
||||
|
||||
/**
|
||||
* The response to an NSURLRequest
|
||||
*/
|
||||
@interface NSURLResponse : NSObject <NSCoding, NSCopying>
|
||||
{
|
||||
@private
|
||||
void *_NSURLResponseInternal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected content length of the receiver or -1 if
|
||||
* there is no idea of what the content length might be.<br />
|
||||
* This value is advisory, not a definitive length.
|
||||
*/
|
||||
- (long long) expectedContentLength;
|
||||
|
||||
/**
|
||||
* Initialises the receiver with the URL, MIMEType, expected length and
|
||||
* text encoding name provided.
|
||||
*/
|
||||
- (id) initWithURL: (NSURL *)URL
|
||||
MIMEType: (NSString *)MIMEType
|
||||
expectedContentLength: (int)length
|
||||
textEncodingName: (NSString *)name;
|
||||
|
||||
/**
|
||||
* Returns the receiver's MIME type.
|
||||
*/
|
||||
- (NSString *) MIMEType;
|
||||
|
||||
/**
|
||||
* Returns a suggested file name for storing the response data, with
|
||||
* suggested names being found in the following order:<br />
|
||||
* <list>
|
||||
* <item>content-disposition header</item>
|
||||
* <item>last path component of URL</item>
|
||||
* <item>host name from URL</item>
|
||||
* <item>'unknown'</item>
|
||||
* </list>
|
||||
* If possible, an extension based on the MIME type of the response
|
||||
* is also appended.<br />
|
||||
* The result should always be a valid file name.
|
||||
*/
|
||||
- (NSString *) suggestedFilename;
|
||||
|
||||
/**
|
||||
* Returns the name of the character set used where response data is text
|
||||
*/
|
||||
- (NSString *) textEncodingName;
|
||||
|
||||
/**
|
||||
* Returns the receiver's URL.
|
||||
*/
|
||||
- (NSURL *) URL;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
* HTTP specific additions to an NSURLResponse
|
||||
*/
|
||||
@interface NSHTTPURLResponse : NSURLResponse
|
||||
|
||||
/**
|
||||
* Returns a string representation of a status code.
|
||||
*/
|
||||
+ (NSString *) localizedStringForStatusCode: (int)statusCode;
|
||||
|
||||
/**
|
||||
* Returns a dictionary containing all the HTTP header fields.
|
||||
*/
|
||||
- (NSDictionary *) allHeaderFields;
|
||||
|
||||
/**
|
||||
* Returns the HTTP status code for the response.
|
||||
*/
|
||||
- (int) statusCode;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -46,8 +46,8 @@ NSClassDescription.h \
|
|||
NSCoder.h \
|
||||
NSConnection.h \
|
||||
NSData.h \
|
||||
NSDate.h \
|
||||
NSDateFormatter.h \
|
||||
NSDate.h \
|
||||
NSDebug.h \
|
||||
NSDecimal.h \
|
||||
NSDecimalNumber.h \
|
||||
|
@ -64,6 +64,8 @@ NSFormatter.h \
|
|||
NSGeometry.h \
|
||||
NSHashTable.h \
|
||||
NSHost.h \
|
||||
NSHTTPCookie.h \
|
||||
NSHTTPCookieStorage.h \
|
||||
NSIndexPath.h \
|
||||
NSIndexSet.h \
|
||||
NSInvocation.h \
|
||||
|
@ -80,12 +82,12 @@ NSNumberFormatter.h \
|
|||
NSObjCRuntime.h \
|
||||
NSObject.h \
|
||||
NSPathUtilities.h \
|
||||
NSPort.h \
|
||||
NSPortCoder.h \
|
||||
NSPort.h \
|
||||
NSPortMessage.h \
|
||||
NSPortNameServer.h \
|
||||
NSPropertyList.h \
|
||||
NSProcessInfo.h \
|
||||
NSPropertyList.h \
|
||||
NSProtocolChecker.h \
|
||||
NSProxy.h \
|
||||
NSRange.h \
|
||||
|
@ -97,16 +99,29 @@ NSStream.h \
|
|||
NSString.h \
|
||||
NSTask.h \
|
||||
NSThread.h \
|
||||
NSTimeZone.h \
|
||||
NSTimer.h \
|
||||
NSTimeZone.h \
|
||||
NSUndoManager.h \
|
||||
NSURLAuthenticationChallenge.h \
|
||||
NSURLCache.h \
|
||||
NSURLConnection.h \
|
||||
NSURLCredential.h \
|
||||
NSURLCredentialStorage.h \
|
||||
NSURLDownload.h \
|
||||
NSURLError.h \
|
||||
NSURL.h \
|
||||
NSURLHandle.h \
|
||||
NSUndoManager.h \
|
||||
NSURLProtectionSpace.h \
|
||||
NSURLProtocol.h \
|
||||
NSURLRequest.h \
|
||||
NSURLResponse.h \
|
||||
NSUserDefaults.h \
|
||||
NSValue.h \
|
||||
NSXMLParser.h \
|
||||
NSZone.h
|
||||
|
||||
|
||||
|
||||
BaseAdditions_AGSDOC_FILES = \
|
||||
../Documentation/BaseAdditions.gsdoc \
|
||||
GSCategories.h \
|
||||
|
|
|
@ -150,6 +150,7 @@ NSArray.m \
|
|||
NSAssertionHandler.m \
|
||||
NSAutoreleasePool.m \
|
||||
NSBundle.m \
|
||||
NSCachedURLResponse.m \
|
||||
NSCalendarDate.m \
|
||||
NSCallBacks.m \
|
||||
NSCharacterSet.m \
|
||||
|
@ -178,6 +179,8 @@ NSFormatter.m \
|
|||
NSGeometry.m \
|
||||
NSHashTable.m \
|
||||
NSHost.m \
|
||||
NSHTTPCookie.m \
|
||||
NSHTTPCookieStorage.m \
|
||||
NSIndexPath.m \
|
||||
NSIndexSet.m \
|
||||
NSInvocation.m \
|
||||
|
@ -225,6 +228,16 @@ NSTimeZone.m \
|
|||
NSUnarchiver.m \
|
||||
NSUndoManager.m \
|
||||
NSURL.m \
|
||||
NSURLAuthenticationChallenge.m \
|
||||
NSURLCache.m \
|
||||
NSURLCredential.m \
|
||||
NSURLConnection.m \
|
||||
NSURLCredentialStorage.m \
|
||||
NSURLDownload.m \
|
||||
NSURLProtectionSpace.m \
|
||||
NSURLProtocol.m \
|
||||
NSURLRequest.m \
|
||||
NSURLResponse.m \
|
||||
NSURLHandle.m \
|
||||
NSUserDefaults.m \
|
||||
NSValue.m \
|
||||
|
@ -278,8 +291,8 @@ NSComparisonPredicate.h \
|
|||
NSCompoundPredicate.h \
|
||||
NSConnection.h \
|
||||
NSData.h \
|
||||
NSDate.h \
|
||||
NSDateFormatter.h \
|
||||
NSDate.h \
|
||||
NSDebug.h \
|
||||
NSDecimal.h \
|
||||
NSDecimalNumber.h \
|
||||
|
@ -297,6 +310,8 @@ NSFormatter.h \
|
|||
NSGeometry.h \
|
||||
NSHashTable.h \
|
||||
NSHost.h \
|
||||
NSHTTPCookie.h \
|
||||
NSHTTPCookieStorage.h \
|
||||
NSIndexPath.h \
|
||||
NSIndexSet.h \
|
||||
NSInvocation.h \
|
||||
|
@ -313,8 +328,8 @@ NSNumberFormatter.h \
|
|||
NSObjCRuntime.h \
|
||||
NSObject.h \
|
||||
NSPathUtilities.h \
|
||||
NSPort.h \
|
||||
NSPortCoder.h \
|
||||
NSPort.h \
|
||||
NSPortMessage.h \
|
||||
NSPortNameServer.h \
|
||||
NSPredicate.h \
|
||||
|
@ -332,11 +347,22 @@ NSStream.h \
|
|||
NSString.h \
|
||||
NSTask.h \
|
||||
NSThread.h \
|
||||
NSTimeZone.h \
|
||||
NSTimer.h \
|
||||
NSTimeZone.h \
|
||||
NSUndoManager.h \
|
||||
NSURLAuthenticationChallenge.h \
|
||||
NSURLCache.h \
|
||||
NSURLConnection.h \
|
||||
NSURLCredential.h \
|
||||
NSURLCredentialStorage.h \
|
||||
NSURLDownload.h \
|
||||
NSURLError.h \
|
||||
NSURL.h \
|
||||
NSURLHandle.h \
|
||||
NSUndoManager.h \
|
||||
NSURLProtectionSpace.h \
|
||||
NSURLProtocol.h \
|
||||
NSURLRequest.h \
|
||||
NSURLResponse.h \
|
||||
NSUserDefaults.h \
|
||||
NSUtilities.h \
|
||||
NSValue.h \
|
||||
|
|
173
Source/NSHTTPCookie.m
Normal file
173
Source/NSHTTPCookie.m
Normal file
|
@ -0,0 +1,173 @@
|
|||
/* Implementation for NSHTTPCookie for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
#include "Foundation/NSSet.h"
|
||||
|
||||
NSString * const NSHTTPCookieComment = @"NSHTTPCookieComment";
|
||||
NSString * const NSHTTPCookieCommentURL = @"NSHTTPCookieCommentURL";
|
||||
NSString * const NSHTTPCookieDiscard = @"NSHTTPCookieDiscard";
|
||||
NSString * const NSHTTPCookieDomain = @"NSHTTPCookieDomain";
|
||||
NSString * const NSHTTPCookieExpires = @"NSHTTPCookieExpires";
|
||||
NSString * const NSHTTPCookieMaximumAge = @"NSHTTPCookieMaximumAge";
|
||||
NSString * const NSHTTPCookieName = @"NSHTTPCookieName";
|
||||
NSString * const NSHTTPCookieOriginURL = @"NSHTTPCookieOriginURL";
|
||||
NSString * const NSHTTPCookiePath = @"NSHTTPCookiePath";
|
||||
NSString * const NSHTTPCookiePort = @"NSHTTPCookiePort";
|
||||
NSString * const NSHTTPCookieSecure = @"NSHTTPCookieSecure";
|
||||
NSString * const NSHTTPCookieValue = @"NSHTTPCookieValue";
|
||||
NSString * const NSHTTPCookieVersion = @"NSHTTPCookieVersion";
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSDictionary *_properties;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSHTTPCookie)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSHTTPCookieInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSHTTPCookieInternal))
|
||||
|
||||
@implementation NSHTTPCookie
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSHTTPCookie *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSHTTPCookieInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (id) cookieWithProperties: (NSDictionary *)properties
|
||||
{
|
||||
NSHTTPCookie *o;
|
||||
|
||||
o = [[self alloc] initWithProperties: properties];
|
||||
return AUTORELEASE(o);
|
||||
}
|
||||
|
||||
+ (NSArray *) cookiesWithResponseHeaderFields: (NSDictionary *)headerFields
|
||||
forURL: (NSURL *)URL
|
||||
{
|
||||
NSMutableArray *a = nil;
|
||||
|
||||
[self notImplemented: _cmd]; // FIXME
|
||||
return a;
|
||||
}
|
||||
|
||||
+ (NSDictionary *) requestHeaderFieldsWithCookies: (NSArray *)cookies
|
||||
{
|
||||
NSMutableDictionary *d = nil;
|
||||
|
||||
[self notImplemented: _cmd]; // FIXME
|
||||
return d;
|
||||
}
|
||||
|
||||
- (NSString *) comment
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieComment];
|
||||
}
|
||||
|
||||
- (NSURL *) commentURL
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieCommentURL];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->_properties);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) domain
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieDomain];
|
||||
}
|
||||
|
||||
- (NSDate *) expiresDate
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieExpires];
|
||||
}
|
||||
|
||||
- (id) initWithProperties: (NSDictionary *)properties
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->_properties = [properties copy];
|
||||
// FIXME ... parse and validate
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isSecure
|
||||
{
|
||||
return [[this->_properties objectForKey: NSHTTPCookieSecure] boolValue];
|
||||
}
|
||||
|
||||
- (BOOL) isSessionOnly
|
||||
{
|
||||
return [[this->_properties objectForKey: NSHTTPCookieDiscard] boolValue];
|
||||
}
|
||||
|
||||
- (NSString *) name
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieName];
|
||||
}
|
||||
|
||||
- (NSString *) path
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookiePath];
|
||||
}
|
||||
|
||||
- (NSArray *) portList
|
||||
{
|
||||
return [[this->_properties objectForKey: NSHTTPCookiePort]
|
||||
componentsSeparatedByString: @","];
|
||||
}
|
||||
|
||||
- (NSDictionary *) properties
|
||||
{
|
||||
return this->_properties;
|
||||
}
|
||||
|
||||
- (NSString *) value
|
||||
{
|
||||
return [this->_properties objectForKey: NSHTTPCookieValue];
|
||||
}
|
||||
|
||||
- (unsigned) version
|
||||
{
|
||||
return [[this->_properties objectForKey: NSHTTPCookieVersion] intValue];
|
||||
}
|
||||
|
||||
@end
|
||||
|
138
Source/NSHTTPCookieStorage.m
Normal file
138
Source/NSHTTPCookieStorage.m
Normal file
|
@ -0,0 +1,138 @@
|
|||
/* Implementation for NSHTTPCookieStorage for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
#include "Foundation/NSSet.h"
|
||||
|
||||
NSString * const NSHTTPCookieManagerAcceptPolicyChangedNotification
|
||||
= @"NSHTTPCookieManagerAcceptPolicyChangedNotification";
|
||||
|
||||
NSString * const NSHTTPCookieManagerCookiesChangedNotification
|
||||
= @"NSHTTPCookieManagerCookiesChangedNotification";
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSHTTPCookieAcceptPolicy _policy;
|
||||
NSMutableSet *_cookies;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSHTTPCookieStorage)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSHTTPCookieStorageInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSHTTPCookieStorageInternal))
|
||||
|
||||
|
||||
/* FIXME
|
||||
* handle persistent storage and use policies.
|
||||
*/
|
||||
@implementation NSHTTPCookieStorage
|
||||
|
||||
static NSHTTPCookieStorage *storage = nil;
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
return RETAIN([self sharedHTTPCookieStorage]);
|
||||
}
|
||||
|
||||
+ (NSHTTPCookieStorage *) sharedHTTPCookieStorage
|
||||
{
|
||||
if (storage == nil)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (storage == nil)
|
||||
{
|
||||
NSHTTPCookieStorage *o;
|
||||
|
||||
o = (NSHTTPCookieStorage*)
|
||||
NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
o->_NSHTTPCookieStorageInternal = (Internal*)
|
||||
NSZoneMalloc(NSDefaultMallocZone(), sizeof(Internal));
|
||||
inst->_policy = NSHTTPCookieAcceptPolicyAlways;
|
||||
inst->_cookies = [NSMutableSet new];
|
||||
storage = o;
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->_cookies);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSHTTPCookieAcceptPolicy) cookieAcceptPolicy
|
||||
{
|
||||
return this->_policy;
|
||||
}
|
||||
|
||||
- (NSArray *) cookies
|
||||
{
|
||||
return [this->_cookies allObjects];
|
||||
}
|
||||
|
||||
- (NSArray *) cookiesForURL: (NSURL *)URL
|
||||
{
|
||||
[self notImplemented: _cmd]; // FIXME
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) deleteCookie: (NSHTTPCookie *)cookie
|
||||
{
|
||||
[this->_cookies removeObject: cookie];
|
||||
}
|
||||
|
||||
- (void) setCookie: (NSHTTPCookie *)cookie
|
||||
{
|
||||
[this->_cookies addObject: cookie];
|
||||
}
|
||||
|
||||
- (void) setCookieAcceptPolicy: (NSHTTPCookieAcceptPolicy)cookieAcceptPolicy
|
||||
{
|
||||
this->_policy = cookieAcceptPolicy;
|
||||
}
|
||||
|
||||
- (void) setCookies: (NSArray *)cookies
|
||||
forURL: (NSURL *)URL
|
||||
mainDocumentURL: (NSURL *)mainDocumentURL
|
||||
{
|
||||
unsigned count = [cookies count];
|
||||
|
||||
while (count-- > 0)
|
||||
{
|
||||
NSHTTPCookie *c = [cookies objectAtIndex: count];
|
||||
|
||||
// FIXME check domain matches
|
||||
[this->_cookies addObject: c];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -21,7 +21,8 @@
|
|||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02111 USA.
|
||||
*
|
||||
* <title>NSMapTable class reference</title>
|
||||
* $Date$ $Revision$
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
<title>NSSet class reference</title>
|
||||
$Date$ $Revision$
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/** NSUrl.m - Class NSURL
|
||||
/** NSURL.m - Class NSURL
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Manuel Guesdon <mguesdon@sbuilders.com>
|
||||
|
@ -52,6 +52,9 @@ function may be incorrect
|
|||
#include "Foundation/NSValue.h"
|
||||
#include "Foundation/NSZone.h"
|
||||
|
||||
NSString * const NSURLErrorDomain = @"NSURLErrorDomain";
|
||||
NSString * const NSErrorFailingURLStringKey = @"NSErrorFailingURLStringKey";
|
||||
|
||||
/*
|
||||
* Structure describing a URL.
|
||||
* All the char* fields may be NULL pointers, except path, which
|
||||
|
|
131
Source/NSURLAuthenticationChallenge.m
Normal file
131
Source/NSURLAuthenticationChallenge.m
Normal file
|
@ -0,0 +1,131 @@
|
|||
/* Implementation for NSURLAuthenticationChallenge for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSURLProtectionSpace *space;
|
||||
NSURLCredential *credential;
|
||||
int previousFailureCount;
|
||||
NSURLResponse *response;
|
||||
NSError *error;
|
||||
id<NSURLAuthenticationChallengeSender> sender;
|
||||
} Internal;
|
||||
|
||||
#define this ((Internal*)(self->_NSURLAuthenticationChallengeInternal))
|
||||
|
||||
@implementation NSURLAuthenticationChallenge
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLAuthenticationChallenge *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLAuthenticationChallengeInternal
|
||||
= NSZoneMalloc(z, sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->space);
|
||||
RELEASE(this->credential);
|
||||
RELEASE(this->response);
|
||||
RELEASE(this->error);
|
||||
RELEASE(this->sender);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSError *) error
|
||||
{
|
||||
return this->error;
|
||||
}
|
||||
|
||||
- (NSURLResponse *) failureResponse
|
||||
{
|
||||
return this->response;
|
||||
}
|
||||
|
||||
- (id) initWithAuthenticationChallenge:
|
||||
(NSURLAuthenticationChallenge *)challenge
|
||||
sender:
|
||||
(id<NSURLAuthenticationChallengeSender>)sender
|
||||
{
|
||||
return [self initWithProtectionSpace: [challenge protectionSpace]
|
||||
proposedCredential: [challenge proposedCredential]
|
||||
previousFailureCount: [challenge previousFailureCount]
|
||||
failureResponse: [challenge failureResponse]
|
||||
error: [challenge error]
|
||||
sender: sender];
|
||||
}
|
||||
|
||||
- (id) initWithProtectionSpace: (NSURLProtectionSpace *)space
|
||||
proposedCredential: (NSURLCredential *)credential
|
||||
previousFailureCount: (int)previousFailureCount
|
||||
failureResponse: (NSURLResponse *)response
|
||||
error: (NSError *)error
|
||||
sender: (id<NSURLAuthenticationChallengeSender>)sender
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->space = [space copy];
|
||||
this->credential = [credential copy];
|
||||
this->response = [response copy];
|
||||
this->error = [error copy];
|
||||
this->sender = RETAIN(sender);
|
||||
this->previousFailureCount = previousFailureCount;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) previousFailureCount
|
||||
{
|
||||
return this->previousFailureCount;
|
||||
}
|
||||
|
||||
- (NSURLCredential *) proposedCredential
|
||||
{
|
||||
return this->credential;
|
||||
}
|
||||
|
||||
- (NSURLProtectionSpace *) protectionSpace
|
||||
{
|
||||
return this->space;
|
||||
}
|
||||
|
||||
- (id<NSURLAuthenticationChallengeSender>) sender
|
||||
{
|
||||
return this->sender;
|
||||
}
|
||||
|
||||
@end
|
||||
|
216
Source/NSURLCache.m
Normal file
216
Source/NSURLCache.m
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* Implementation for NSURLCache for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
// FIXME ... locking and disk storage needed
|
||||
typedef struct {
|
||||
unsigned diskCapacity;
|
||||
unsigned memoryCapacity;
|
||||
unsigned diskUsage;
|
||||
unsigned memoryUsage;
|
||||
NSString *path;
|
||||
NSMutableDictionary *memory;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLCache)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSURLCacheInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSURLCacheInternal))
|
||||
|
||||
|
||||
static NSURLCache *shared = nil;
|
||||
|
||||
@implementation NSURLCache
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLCache *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLCacheInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
memset(o->_NSURLCacheInternal, '\0', sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (void) setSharedURLCache: (NSURLCache *)cache
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
ASSIGN(shared, cache);
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->memory);
|
||||
RELEASE(this->path);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+ (NSURLCache *) sharedURLCache
|
||||
{
|
||||
NSURLCache *c;
|
||||
|
||||
[gnustep_global_lock lock];
|
||||
if (shared == nil)
|
||||
{
|
||||
NSString *path = nil;
|
||||
|
||||
// FIXME user-library-path/Caches/current-app-name
|
||||
|
||||
shared = [[self alloc] initWithMemoryCapacity: 4 * 1024 * 1024
|
||||
diskCapacity: 20 * 1024 * 1024
|
||||
diskPath: path];
|
||||
|
||||
}
|
||||
c = RETAIN(shared);
|
||||
[gnustep_global_lock unlock];
|
||||
return AUTORELEASE(c);
|
||||
}
|
||||
|
||||
- (NSCachedURLResponse *) cachedResponseForRequest: (NSURLRequest *)request
|
||||
{
|
||||
// FIXME ... handle disk cache
|
||||
return [this->memory objectForKey: request];
|
||||
}
|
||||
|
||||
- (unsigned) currentDiskUsage
|
||||
{
|
||||
return this->diskUsage;
|
||||
}
|
||||
|
||||
- (unsigned) currentMemoryUsage
|
||||
{
|
||||
return this->memoryUsage;
|
||||
}
|
||||
|
||||
- (unsigned) diskCapacity
|
||||
{
|
||||
return this->diskCapacity;
|
||||
}
|
||||
|
||||
- (id) initWithMemoryCapacity: (unsigned)memoryCapacity
|
||||
diskCapacity: (unsigned)diskCapacity
|
||||
diskPath: (NSString *)path
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->diskUsage = 0;
|
||||
this->diskCapacity = diskCapacity;
|
||||
this->memoryUsage = 0;
|
||||
this->memoryCapacity = memoryCapacity;
|
||||
this->path = [path copy];
|
||||
this->memory = [NSMutableDictionary new];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned) memoryCapacity
|
||||
{
|
||||
return this->memoryCapacity;
|
||||
}
|
||||
|
||||
- (void) removeAllCachedResponses
|
||||
{
|
||||
// FIXME ... disk storage
|
||||
[this->memory removeAllObjects];
|
||||
this->diskUsage = 0;
|
||||
this->memoryUsage = 0;
|
||||
}
|
||||
|
||||
- (void) removeCachedResponseForRequest: (NSURLRequest *)request
|
||||
{
|
||||
NSCachedURLResponse *item = [self cachedResponseForRequest: request];
|
||||
|
||||
if (item != nil)
|
||||
{
|
||||
// FIXME ... disk storage
|
||||
this->memoryUsage -= [[item data] length];
|
||||
[this->memory removeObjectForKey: request];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setDiskCapacity: (unsigned)diskCapacity
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void) setMemoryCapacity: (unsigned)memoryCapacity
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void) storeCachedResponse: (NSCachedURLResponse *)cachedResponse
|
||||
forRequest: (NSURLRequest *)request
|
||||
{
|
||||
switch ([cachedResponse storagePolicy])
|
||||
{
|
||||
case NSURLCacheStorageAllowed:
|
||||
// FIXME ... maybe on disk?
|
||||
|
||||
case NSURLCacheStorageAllowedInMemoryOnly:
|
||||
{
|
||||
unsigned size = [[cachedResponse data] length];
|
||||
|
||||
if (size < this->memoryCapacity)
|
||||
{
|
||||
NSCachedURLResponse *old;
|
||||
|
||||
old = [this->memory objectForKey: request];
|
||||
if (old != nil)
|
||||
{
|
||||
this->memoryUsage -= [[old data] length];
|
||||
[this->memory removeObjectForKey: request];
|
||||
}
|
||||
while (this->memoryUsage + size > this->memoryCapacity)
|
||||
{
|
||||
// FIXME ... should delete least recently used.
|
||||
[self removeCachedResponseForRequest:
|
||||
[[this->memory allKeys] lastObject]];
|
||||
}
|
||||
[this->memory setObject: cachedResponse forKey: request];
|
||||
this->memoryUsage += size;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NSURLCacheStorageNotAllowed:
|
||||
break;
|
||||
|
||||
default:
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"storing cached response with bad policy (%d)",
|
||||
[cachedResponse storagePolicy]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
252
Source/NSURLConnection.m
Normal file
252
Source/NSURLConnection.m
Normal file
|
@ -0,0 +1,252 @@
|
|||
/* Implementation for NSURLConnection for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
@interface GSURLConnection : NSObject <NSURLProtocolClient>
|
||||
{
|
||||
@public
|
||||
NSURLConnection *_parent; // Not retained
|
||||
NSURLRequest *_request;
|
||||
NSURLProtocol *_protocol;
|
||||
id _delegate;
|
||||
}
|
||||
@end
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLConnection)
|
||||
} priv;
|
||||
#define this ((GSURLConnection*)(((priv*)self)->_NSURLConnectionInternal))
|
||||
#define inst ((GSURLConnection*)(((priv*)o)->_NSURLConnectionInternal))
|
||||
|
||||
@implementation NSURLConnection
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLConnection *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLConnectionInternal
|
||||
= NSAllocateObject([GSURLConnection class], 0, z);
|
||||
inst->_parent = o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (BOOL) canHandleRequest: (NSURLRequest *)request
|
||||
{
|
||||
// FIXME
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSURLConnection *) connectionWithRequest: (NSURLRequest *)request
|
||||
delegate: (id)delegate
|
||||
{
|
||||
NSURLConnection *o = [self alloc];
|
||||
|
||||
o = [o initWithRequest: request delegate: delegate];
|
||||
return AUTORELEASE(o);
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(this);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) cancel
|
||||
{
|
||||
[this->_protocol stopLoading];
|
||||
DESTROY(this->_protocol);
|
||||
}
|
||||
|
||||
- (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->_request = [request copy];
|
||||
this->_delegate = [delegate retain];
|
||||
// FIXME ... start connection
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NSObject (NSURLConnectionDelegate)
|
||||
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didFailWithError: (NSError *)error
|
||||
{
|
||||
}
|
||||
|
||||
- (void) connectionDidFinishLoading: (NSURLConnection *)connection
|
||||
{
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[[challenge sender]
|
||||
continueWithoutCredentialForAuthenticationChallenge: challenge];
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveData: (NSData *)data
|
||||
{
|
||||
}
|
||||
|
||||
- (void) connection: (NSURLConnection *)connection
|
||||
didReceiveResponse: (NSURLResponse *)response
|
||||
{
|
||||
}
|
||||
|
||||
- (NSCachedURLResponse *) connection: (NSURLConnection *)connection
|
||||
willCacheResponse: (NSCachedURLResponse *)cachedResponse
|
||||
{
|
||||
return cachedResponse;
|
||||
}
|
||||
|
||||
- (NSURLRequest *) connection: (NSURLConnection *)connection
|
||||
willSendRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)response
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NSURLConnection (NSURLConnectionSynchronousLoading)
|
||||
|
||||
+ (NSData *) sendSynchronousRequest: (NSURLRequest *)request
|
||||
returningResponse: (NSURLResponse **)response
|
||||
error: (NSError **)error
|
||||
{
|
||||
NSData *data = nil;
|
||||
|
||||
if ([self canHandleRequest: request] == YES)
|
||||
{
|
||||
NSURLConnection *conn = [self alloc];
|
||||
|
||||
conn = [conn initWithRequest: request delegate: nil];
|
||||
// FIXME ... handle load and get results;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation GSURLConnection
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_protocol);
|
||||
RELEASE(_request);
|
||||
RELEASE(_delegate);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
cachedResponseIsValid: (NSCachedURLResponse *)cachedResponse
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didFailWithError: (NSError *)error
|
||||
{
|
||||
[_delegate connection: _parent didFailWithError: error];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didLoadData: (NSData *)data
|
||||
{
|
||||
[_delegate connection: _parent didReceiveData: data];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[_delegate connection: _parent didReceiveAuthenticationChallenge: challenge];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveResponse: (NSURLResponse *)response
|
||||
cacheStoragePolicy: (NSURLCacheStoragePolicy)policy
|
||||
{
|
||||
[_delegate connection: _parent didReceiveResponse: response];
|
||||
if (policy == NSURLCacheStorageAllowed
|
||||
|| policy == NSURLCacheStorageAllowedInMemoryOnly)
|
||||
{
|
||||
|
||||
// FIXME ... cache response here
|
||||
}
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
wasRedirectedToRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)redirectResponse
|
||||
{
|
||||
request = [_delegate connection: _parent
|
||||
willSendRequest: request
|
||||
redirectResponse: redirectResponse];
|
||||
// If we have been cancelled, our protocol will be nil
|
||||
if (_protocol != nil)
|
||||
{
|
||||
if (request == nil)
|
||||
{
|
||||
[_delegate connectionDidFinishLoading: _parent];
|
||||
}
|
||||
else
|
||||
{
|
||||
DESTROY(_protocol);
|
||||
// FIXME start new request loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) URLProtocolDidFinishLoading: (NSURLProtocol *)protocol
|
||||
{
|
||||
[_delegate connectionDidFinishLoading: _parent];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[_delegate connection: _parent didCancelAuthenticationChallenge: challenge];
|
||||
}
|
||||
|
||||
@end
|
||||
|
133
Source/NSURLCredential.m
Normal file
133
Source/NSURLCredential.m
Normal file
|
@ -0,0 +1,133 @@
|
|||
/* Implementation for NSURLCredential for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSString *user;
|
||||
NSString *password;
|
||||
NSURLCredentialPersistence persistence;
|
||||
BOOL hasPassword;
|
||||
} Internal;
|
||||
|
||||
#define this ((Internal*)(self->_NSURLCredentialInternal))
|
||||
|
||||
@implementation NSURLCredential
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLCredential *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLCredentialInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (NSURLCredential *) credentialWithUser: (NSString *)user
|
||||
password: (NSString *)password
|
||||
persistence: (NSURLCredentialPersistence)persistence
|
||||
{
|
||||
NSURLCredential *o = [self alloc];
|
||||
|
||||
o = [o initWithUser: user password: password persistence: persistence];
|
||||
return AUTORELEASE(o);
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLCredential *o;
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == YES)
|
||||
{
|
||||
o = RETAIN(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
o = [[self class] allocWithZone: z];
|
||||
o = [o initWithUser: this->user
|
||||
password: this->password
|
||||
persistence: this->persistence];
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->user);
|
||||
RELEASE(this->password);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (BOOL) hasPassword
|
||||
{
|
||||
return this->hasPassword;
|
||||
}
|
||||
|
||||
- (id) initWithUser: (NSString *)user
|
||||
password: (NSString *)password
|
||||
persistence: (NSURLCredentialPersistence)persistence
|
||||
{
|
||||
if (user == nil)
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->user = [user copy];
|
||||
this->password = [password copy];
|
||||
this->persistence = persistence;
|
||||
this->hasPassword = (this->password == nil) ? NO : YES;
|
||||
if (persistence == NSURLCredentialPersistencePermanent)
|
||||
{
|
||||
// FIXME ... should check to see if we really have a password
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *) password
|
||||
{
|
||||
return this->password;
|
||||
}
|
||||
|
||||
- (NSURLCredentialPersistence) persistence
|
||||
{
|
||||
return this->persistence;
|
||||
}
|
||||
|
||||
- (NSString *) user
|
||||
{
|
||||
return this->user;
|
||||
}
|
||||
|
||||
@end
|
||||
|
193
Source/NSURLCredentialStorage.m
Normal file
193
Source/NSURLCredentialStorage.m
Normal file
|
@ -0,0 +1,193 @@
|
|||
/* Implementation for NSURLCredentialStorage for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
NSString *const NSURLCredentialStorageChangedNotification
|
||||
= @"NSURLCredentialStorageChangedNotification";
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSMutableDictionary *credentials;
|
||||
NSMutableDictionary *defaults;
|
||||
} Internal;
|
||||
|
||||
#define this ((Internal*)(self->_NSURLCredentialStorageInternal))
|
||||
|
||||
@implementation NSURLCredentialStorage
|
||||
|
||||
static NSURLCredentialStorage *storage = nil;
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
return RETAIN([self sharedCredentialStorage]);
|
||||
}
|
||||
|
||||
+ (NSURLCredentialStorage *) sharedCredentialStorage
|
||||
{
|
||||
if (storage == nil)
|
||||
{
|
||||
[gnustep_global_lock lock];
|
||||
if (storage == nil)
|
||||
{
|
||||
NSURLCredentialStorage *o;
|
||||
|
||||
o = (NSURLCredentialStorage*)
|
||||
NSAllocateObject(self, 0, NSDefaultMallocZone());
|
||||
o->_NSURLCredentialStorageInternal = (Internal*)
|
||||
NSZoneMalloc(NSDefaultMallocZone(), sizeof(Internal));
|
||||
((Internal*)(o->_NSURLCredentialStorageInternal))->credentials
|
||||
= [NSMutableDictionary new];
|
||||
((Internal*)(o->_NSURLCredentialStorageInternal))->defaults
|
||||
= [NSMutableDictionary new];
|
||||
storage = o;
|
||||
}
|
||||
[gnustep_global_lock unlock];
|
||||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
- (NSDictionary *) allCredentials
|
||||
{
|
||||
NSMutableDictionary *all;
|
||||
NSEnumerator *enumerator;
|
||||
NSURLProtectionSpace *space;
|
||||
|
||||
all = [NSMutableDictionary dictionaryWithCapacity: [this->credentials count]];
|
||||
enumerator = [this->credentials keyEnumerator];
|
||||
while ((space = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSDictionary *info = [[this->credentials objectForKey: space] copy];
|
||||
|
||||
[all setObject: info forKey: space];
|
||||
RELEASE(info);
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
- (NSDictionary *) credentialsForProtectionSpace: (NSURLProtectionSpace *)space
|
||||
{
|
||||
return AUTORELEASE([[this->credentials objectForKey: space] copy]);
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Attempt to deallocate credential storage"];
|
||||
GSNOSUPERDEALLOC;
|
||||
}
|
||||
|
||||
- (NSURLCredential *) defaultCredentialForProtectionSpace:
|
||||
(NSURLProtectionSpace *)space
|
||||
{
|
||||
return [this->defaults objectForKey: space];
|
||||
}
|
||||
|
||||
// Should never be called.
|
||||
- (id) init
|
||||
{
|
||||
RELEASE(self);
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void) removeCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space
|
||||
{
|
||||
if (credential == nil || ![credential isKindOfClass: [NSURLCredential class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for credential",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
if (space == nil || ![space isKindOfClass: [NSURLProtectionSpace class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for space",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
[[this->credentials objectForKey: space]
|
||||
removeObjectForKey: [credential user]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets credential in the storage for the protection space specified.<br />
|
||||
* This replaces any old value with the same username.
|
||||
*/
|
||||
- (void) setCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space
|
||||
{
|
||||
NSMutableDictionary *info;
|
||||
|
||||
if (credential == nil || ![credential isKindOfClass: [NSURLCredential class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for credential",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
if (space == nil || ![space isKindOfClass: [NSURLProtectionSpace class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for space",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
info = [this->credentials objectForKey: space];
|
||||
if (info == nil)
|
||||
{
|
||||
info = [NSMutableDictionary new];
|
||||
[this->credentials setObject: info forKey: space];
|
||||
RELEASE(info);
|
||||
}
|
||||
[info setObject: credential forKey: [credential user]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default credential for the protection space. Also calls
|
||||
* -setCredential:forProtectionSpace: if the credential has not already
|
||||
* been set in space.
|
||||
*/
|
||||
- (void) setDefaultCredential: (NSURLCredential *)credential
|
||||
forProtectionSpace: (NSURLProtectionSpace *)space
|
||||
{
|
||||
if (credential == nil || ![credential isKindOfClass: [NSURLCredential class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for credential",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
if (space == nil || ![space isKindOfClass: [NSURLProtectionSpace class]])
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"[%@-%@] nil or bad class for space",
|
||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
||||
}
|
||||
[this->defaults setObject: credential forKey: space];
|
||||
if ([[this->credentials objectForKey: space] objectForKey: [credential user]]
|
||||
!= credential)
|
||||
{
|
||||
[self setCredential: credential forProtectionSpace: space];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
279
Source/NSURLDownload.m
Normal file
279
Source/NSURLDownload.m
Normal file
|
@ -0,0 +1,279 @@
|
|||
/* Implementation for NSURLDownload for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
@interface GSURLDownload : NSObject <NSURLProtocolClient>
|
||||
{
|
||||
@public
|
||||
NSURLDownload *_parent; // Not retained
|
||||
NSURLRequest *_request;
|
||||
NSURLProtocol *_protocol;
|
||||
NSData *_resumeData;
|
||||
NSString *_path;
|
||||
id _delegate;
|
||||
BOOL _deletesFileUponFailure;
|
||||
BOOL _allowOverwrite;
|
||||
}
|
||||
@end
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLDownload)
|
||||
} priv;
|
||||
#define this ((GSURLDownload*)(((priv*)self)->_NSURLDownloadInternal))
|
||||
#define inst ((GSURLDownload*)(((priv*)o)->_NSURLDownloadInternal))
|
||||
|
||||
@implementation NSURLDownload
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLDownload *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLDownloadInternal
|
||||
= NSAllocateObject([GSURLDownload class], 0, z);
|
||||
inst->_parent = o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (BOOL) canResumeDownloadDecodedWithEncodingMIMEType: (NSString *)MIMEType
|
||||
{
|
||||
return NO; // FIXME
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(this);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) cancel
|
||||
{
|
||||
[this->_protocol stopLoading];
|
||||
DESTROY(this->_protocol);
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (BOOL) deletesFileUponFailure
|
||||
{
|
||||
return this->_deletesFileUponFailure;
|
||||
}
|
||||
|
||||
- (id) initWithRequest: (NSURLRequest *)request delegate: (id)delegate
|
||||
{
|
||||
NSData *resumeData = nil;
|
||||
|
||||
// FIXME ... build resume data from request.
|
||||
return [self initWithResumeData: resumeData delegate: delegate path: nil];
|
||||
}
|
||||
|
||||
- (id) initWithResumeData: (NSData *)resumeData
|
||||
delegate: (id)delegate
|
||||
path: (NSString *)path
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->_resumeData = [resumeData copy];
|
||||
this->_delegate = [delegate retain];
|
||||
this->_path = [path copy];
|
||||
// FIXME ... start connection
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSURLRequest *) request
|
||||
{
|
||||
return this->_request;
|
||||
}
|
||||
|
||||
- (NSData *) resumeData
|
||||
{
|
||||
return nil; // FIXME
|
||||
}
|
||||
|
||||
- (void) setDeletesFileUponFailure: (BOOL)deletesFileUponFailure
|
||||
{
|
||||
this->_deletesFileUponFailure = deletesFileUponFailure;
|
||||
}
|
||||
|
||||
- (void) setDestination: (NSString *)path allowOverwrite: (BOOL)allowOverwrite
|
||||
{
|
||||
ASSIGN(this->_path, path);
|
||||
this->_allowOverwrite = allowOverwrite;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSObject (NSURLDownloadDelegate)
|
||||
|
||||
- (void) downloadDidBegin: (NSURLDownload *)download
|
||||
{
|
||||
}
|
||||
|
||||
- (void) downloadDidFinish: (NSURLDownload *)download
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
decideDestinationWithSuggestedFilename: (NSString *)filename
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didCreateDestination: (NSString *)path
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download didFailWithError: (NSError *)error
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveDataOfLength: (unsigned)length
|
||||
{
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
didReceiveResponse: (NSURLResponse *)response
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL) download: (NSURLDownload *)download
|
||||
shouldDecodeSourceDataOfMIMEType: (NSString *)encodingType
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) download: (NSURLDownload *)download
|
||||
willResumeWithResponse: (NSURLResponse *)response
|
||||
fromByte: (long long)startingByte
|
||||
{
|
||||
}
|
||||
|
||||
- (NSURLRequest *) download: (NSURLDownload *)download
|
||||
willSendRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)redirectResponse
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation GSURLDownload
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_protocol);
|
||||
RELEASE(_resumeData);
|
||||
RELEASE(_request);
|
||||
RELEASE(_delegate);
|
||||
RELEASE(_path);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
cachedResponseIsValid: (NSCachedURLResponse *)cachedResponse
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didFailWithError: (NSError *)error
|
||||
{
|
||||
[_delegate download: _parent didFailWithError: error];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didLoadData: (NSData *)data
|
||||
{
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[_delegate download: _parent didReceiveAuthenticationChallenge: challenge];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didReceiveResponse: (NSURLResponse *)response
|
||||
cacheStoragePolicy: (NSURLCacheStoragePolicy)policy
|
||||
{
|
||||
[_delegate download: _parent didReceiveResponse: response];
|
||||
if (policy == NSURLCacheStorageAllowed
|
||||
|| policy == NSURLCacheStorageAllowedInMemoryOnly)
|
||||
{
|
||||
|
||||
// FIXME ... cache response here
|
||||
}
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
wasRedirectedToRequest: (NSURLRequest *)request
|
||||
redirectResponse: (NSURLResponse *)redirectResponse
|
||||
{
|
||||
request = [_delegate download: _parent
|
||||
willSendRequest: request
|
||||
redirectResponse: redirectResponse];
|
||||
// If we have been cancelled, our protocol will be nil
|
||||
if (_protocol != nil)
|
||||
{
|
||||
if (request == nil)
|
||||
{
|
||||
[_delegate downloadDidFinish: _parent];
|
||||
}
|
||||
else
|
||||
{
|
||||
DESTROY(_protocol);
|
||||
// FIXME start new request loading
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) URLProtocolDidFinishLoading: (NSURLProtocol *)protocol
|
||||
{
|
||||
[_delegate downloadDidFinish: _parent];
|
||||
}
|
||||
|
||||
- (void) URLProtocol: (NSURLProtocol *)protocol
|
||||
didCancelAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge
|
||||
{
|
||||
[_delegate download: _parent didCancelAuthenticationChallenge: challenge];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -20,21 +20,17 @@
|
|||
|
||||
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
<title>NSURLHandle class reference</title>
|
||||
$Date$ $Revision$
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "Foundation/NSArray.h"
|
||||
#include "Foundation/NSData.h"
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
#include "Foundation/NSEnumerator.h"
|
||||
#include "Foundation/NSString.h"
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSLock.h"
|
||||
#include "Foundation/NSURLHandle.h"
|
||||
#include "Foundation/NSURL.h"
|
||||
#include "Foundation/NSRunLoop.h"
|
||||
#include "Foundation/NSFileManager.h"
|
||||
|
||||
|
|
198
Source/NSURLProtectionSpace.m
Normal file
198
Source/NSURLProtectionSpace.m
Normal file
|
@ -0,0 +1,198 @@
|
|||
/* Implementation for NSURLProtectionSpace for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
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;
|
||||
NSString *proxyType;
|
||||
NSString *authenticationMethod;
|
||||
BOOL isProxy;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLProtectionSpace)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSURLProtectionSpaceInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSURLProtectionSpaceInternal))
|
||||
|
||||
@implementation NSURLProtectionSpace
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLProtectionSpace *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLProtectionSpaceInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (NSString *) authenticationMethod
|
||||
{
|
||||
return this->authenticationMethod;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
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;
|
||||
ASSIGN(inst->proxyType, this->proxyType);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->host);
|
||||
RELEASE(this->protocol);
|
||||
RELEASE(this->proxyType);
|
||||
RELEASE(this->realm);
|
||||
RELEASE(this->authenticationMethod);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *) host
|
||||
{
|
||||
return this->host;
|
||||
}
|
||||
|
||||
- (id) initWithHost: (NSString *)host
|
||||
port: (int)port
|
||||
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];
|
||||
this->authenticationMethod = [authenticationMethod copy];
|
||||
this->port = port;
|
||||
this->proxyType = nil;
|
||||
this->isProxy = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initWithProxyHost: (NSString *)host
|
||||
port: (int)port
|
||||
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;
|
||||
ASSIGNCOPY(this->proxyType, type);
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isProxy
|
||||
{
|
||||
return this->isProxy;
|
||||
}
|
||||
|
||||
- (int) port
|
||||
{
|
||||
return this->port;
|
||||
}
|
||||
|
||||
- (NSString *) protocol
|
||||
{
|
||||
return this->protocol;
|
||||
}
|
||||
|
||||
- (NSString *) proxyType
|
||||
{
|
||||
return this->proxyType;
|
||||
}
|
||||
|
||||
- (NSString *) realm
|
||||
{
|
||||
return this->realm;
|
||||
}
|
||||
|
||||
- (BOOL) receivesCredentialSecurely
|
||||
{
|
||||
if ([this->authenticationMethod isEqual: NSURLAuthenticationMethodHTTPDigest])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
if (this->isProxy)
|
||||
{
|
||||
if ([this->proxyType isEqual: NSURLProtectionSpaceHTTPSProxy] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([this->protocol isEqual: @"https"] == YES)
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
174
Source/NSURLProtocol.m
Normal file
174
Source/NSURLProtocol.m
Normal file
|
@ -0,0 +1,174 @@
|
|||
/* Implementation for NSURLProtocol for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSInputStream *input;
|
||||
NSOutputStream *output;
|
||||
NSCachedURLResponse *cachedResponse;
|
||||
id <NSURLProtocolClient> client;
|
||||
NSURLRequest *request;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLProtocol)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSURLProtocolInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSURLProtocolInternal))
|
||||
|
||||
static NSMutableArray *registered = nil;
|
||||
static NSLock *regLock = nil;
|
||||
|
||||
@implementation NSURLProtocol
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLProtocol *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLProtocolInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (registered == nil)
|
||||
{
|
||||
registered = [NSMutableArray new];
|
||||
regLock = [NSLock new];
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL) registerClass: (Class)protocolClass
|
||||
{
|
||||
if ([protocolClass isSubclassOfClass: [NSURLProtocol class]] == YES)
|
||||
{
|
||||
[regLock lock];
|
||||
[registered addObject: protocolClass];
|
||||
[regLock unlock];
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (id) propertyForKey: (NSString *)key inRequest: (NSURLRequest *)request
|
||||
{
|
||||
return [request _propertyForKey: key];
|
||||
}
|
||||
|
||||
+ (void) setProperty: (id)value
|
||||
forKey: (NSString *)key
|
||||
inRequest: (NSMutableURLRequest *)request
|
||||
{
|
||||
[request _setProperty: value forKey: key];
|
||||
}
|
||||
|
||||
+ (void) unregisterClass: (Class)protocolClass
|
||||
{
|
||||
[regLock lock];
|
||||
[registered removeObjectIdenticalTo: protocolClass];
|
||||
[regLock unlock];
|
||||
}
|
||||
|
||||
- (NSCachedURLResponse *) cachedResponse
|
||||
{
|
||||
return this->cachedResponse;
|
||||
}
|
||||
|
||||
- (id <NSURLProtocolClient>) client
|
||||
{
|
||||
return this->client;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->input);
|
||||
RELEASE(this->output);
|
||||
RELEASE(this->cachedResponse);
|
||||
RELEASE(this->client);
|
||||
RELEASE(this->request);
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) initWithRequest: (NSURLRequest *)request
|
||||
cachedResponse: (NSCachedURLResponse *)cachedResponse
|
||||
client: (id <NSURLProtocolClient>)client
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->request = [request copy];
|
||||
this->cachedResponse = RETAIN(cachedResponse);
|
||||
this->client = RETAIN(client);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSURLRequest *) request
|
||||
{
|
||||
return this->request;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSURLProtocol (Subclassing)
|
||||
|
||||
+ (BOOL) canInitWithRequest: (NSURLRequest *)request
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSURLRequest *) canonicalRequestForRequest: (NSURLRequest *)request
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
+ (BOOL) requestIsCacheEquivalent: (NSURLRequest *)a
|
||||
toRequest: (NSURLRequest *)b
|
||||
{
|
||||
return [a isEqual: b];
|
||||
}
|
||||
|
||||
- (void) startLoading
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) stopLoading
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
@end
|
||||
|
512
Source/NSURLRequest.m
Normal file
512
Source/NSURLRequest.m
Normal file
|
@ -0,0 +1,512 @@
|
|||
/* Implementation for NSURLRequest for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
#include "Foundation/NSMapTable.h"
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include "NSCallBacks.h"
|
||||
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
NSData *body;
|
||||
NSInputStream *bodyStream;
|
||||
NSString *method;
|
||||
NSMapTable *headers;
|
||||
BOOL shouldHandleCookies;
|
||||
NSURL *URL;
|
||||
NSURL *mainDocumentURL;
|
||||
NSURLRequestCachePolicy cachePolicy;
|
||||
NSTimeInterval timeoutInterval;
|
||||
NSMutableDictionary *properties;
|
||||
} Internal;
|
||||
|
||||
/* Defines to get easy access to internals from mutable/immutable
|
||||
* versions of the class and from categories.
|
||||
*/
|
||||
typedef struct {
|
||||
@defs(NSURLRequest)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSURLRequestInternal))
|
||||
#define inst ((Internal*)(((priv*)o)->_NSURLRequestInternal))
|
||||
|
||||
@implementation NSURLRequest
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLRequest *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLRequestInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
memset(o->_NSURLRequestInternal, '\0', sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
+ (id) requestWithURL: (NSURL *)URL
|
||||
{
|
||||
return [self requestWithURL: URL
|
||||
cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 60.0];
|
||||
}
|
||||
|
||||
+ (id) requestWithURL: (NSURL *)URL
|
||||
cachePolicy: (NSURLRequestCachePolicy)cachePolicy
|
||||
timeoutInterval: (NSTimeInterval)timeoutInterval
|
||||
{
|
||||
NSURLRequest *o = [[self class] allocWithZone: NSDefaultMallocZone()];
|
||||
|
||||
o = [o initWithURL: URL
|
||||
cachePolicy: cachePolicy
|
||||
timeoutInterval: timeoutInterval];
|
||||
return AUTORELEASE(o);
|
||||
}
|
||||
|
||||
- (NSURLRequestCachePolicy) cachePolicy
|
||||
{
|
||||
return this->cachePolicy;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLRequest *o;
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == YES
|
||||
&& [self isKindOfClass: [NSMutableURLRequest class]] == NO)
|
||||
{
|
||||
o = RETAIN(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
o = [[self class] allocWithZone: z];
|
||||
o = [o initWithURL: [self URL]
|
||||
cachePolicy: [self cachePolicy]
|
||||
timeoutInterval: [self timeoutInterval]];
|
||||
if (o != nil)
|
||||
{
|
||||
inst->properties = [this->properties mutableCopy];
|
||||
ASSIGN(inst->mainDocumentURL, this->mainDocumentURL);
|
||||
ASSIGN(inst->body, this->body);
|
||||
ASSIGN(inst->bodyStream, this->bodyStream);
|
||||
ASSIGN(inst->method, this->method);
|
||||
inst->shouldHandleCookies = this->shouldHandleCookies;
|
||||
if (this->headers == 0)
|
||||
{
|
||||
inst->headers = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->headers = NSCopyMapTableWithZone(this->headers, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->body);
|
||||
RELEASE(this->bodyStream);
|
||||
RELEASE(this->method);
|
||||
RELEASE(this->URL);
|
||||
RELEASE(this->mainDocumentURL);
|
||||
RELEASE(this->properties);
|
||||
if (this->headers != 0)
|
||||
{
|
||||
NSFreeMapTable(this->headers);
|
||||
}
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString*) description
|
||||
{
|
||||
return [NSString stringWithFormat: @"<%@ %@>",
|
||||
NSStringFromClass([self class]), [[self URL] absoluteString]];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
// FIXME
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
// FIXME
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (unsigned) hash
|
||||
{
|
||||
return [this->URL hash];
|
||||
}
|
||||
|
||||
- (id) initWithURL: (NSURL *)URL
|
||||
{
|
||||
return [self initWithURL: URL
|
||||
cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||
timeoutInterval: 60.0];
|
||||
}
|
||||
|
||||
- (id) initWithURL: (NSURL *)URL
|
||||
cachePolicy: (NSURLRequestCachePolicy)cachePolicy
|
||||
timeoutInterval: (NSTimeInterval)timeoutInterval
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
this->URL = RETAIN(URL);
|
||||
this->cachePolicy = cachePolicy;
|
||||
this->timeoutInterval = timeoutInterval;
|
||||
this->mainDocumentURL = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)o
|
||||
{
|
||||
if ([o isKindOfClass: [NSURLRequest class]] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->URL != inst->URL
|
||||
&& [this->URL isEqual: inst->URL] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->mainDocumentURL != inst->mainDocumentURL
|
||||
&& [this->mainDocumentURL isEqual: inst->mainDocumentURL] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->method != inst->method
|
||||
&& [this->method isEqual: inst->method] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->body != inst->body
|
||||
&& [this->body isEqual: inst->body] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->bodyStream != inst->bodyStream
|
||||
&& [this->bodyStream isEqual: inst->bodyStream] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->properties != inst->properties
|
||||
&& [this->properties isEqual: inst->properties] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (this->headers != inst->headers)
|
||||
{
|
||||
NSMapEnumerator enumerator;
|
||||
id k;
|
||||
id v;
|
||||
|
||||
if (this->headers == 0 || inst->headers == 0)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
if (NSCountMapTable(this->headers) != NSCountMapTable(inst->headers))
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
enumerator = NSEnumerateMapTable(this->headers);
|
||||
while (NSNextMapEnumeratorPair(&enumerator, (void **)(&k), (void**)&v))
|
||||
{
|
||||
id ov = (id)NSMapGet(inst->headers, (void*)k);
|
||||
|
||||
if ([v isEqual: ov] == NO)
|
||||
{
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
NSEndMapTableEnumeration(&enumerator);
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSURL *) mainDocumentURL
|
||||
{
|
||||
return this->mainDocumentURL;
|
||||
}
|
||||
|
||||
- (id) mutableCopyWithZone: (NSZone*)z
|
||||
{
|
||||
NSMutableURLRequest *o;
|
||||
|
||||
o = [NSMutableURLRequest allocWithZone: z];
|
||||
o = [o initWithURL: [self URL]
|
||||
cachePolicy: [self cachePolicy]
|
||||
timeoutInterval: [self timeoutInterval]];
|
||||
if (o != nil)
|
||||
{
|
||||
[o setMainDocumentURL: this->mainDocumentURL];
|
||||
inst->properties = [this->properties mutableCopy];
|
||||
ASSIGN(inst->mainDocumentURL, this->mainDocumentURL);
|
||||
ASSIGN(inst->body, this->body);
|
||||
ASSIGN(inst->bodyStream, this->bodyStream);
|
||||
ASSIGN(inst->method, this->method);
|
||||
inst->shouldHandleCookies = this->shouldHandleCookies;
|
||||
if (this->headers == 0)
|
||||
{
|
||||
inst->headers = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->headers = NSCopyMapTableWithZone(this->headers, z);
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (NSTimeInterval) timeoutInterval
|
||||
{
|
||||
return this->timeoutInterval;
|
||||
}
|
||||
|
||||
- (NSURL *) URL
|
||||
{
|
||||
return this->URL;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSMutableURLRequest
|
||||
|
||||
- (void) setCachePolicy: (NSURLRequestCachePolicy)cachePolicy
|
||||
{
|
||||
this->cachePolicy = cachePolicy;
|
||||
}
|
||||
|
||||
- (void) setMainDocumentURL: (NSURL *)URL
|
||||
{
|
||||
ASSIGN(this->mainDocumentURL, URL);
|
||||
}
|
||||
|
||||
- (void) setTimeoutInterval: (NSTimeInterval)seconds
|
||||
{
|
||||
this->timeoutInterval = seconds;
|
||||
}
|
||||
|
||||
- (void) setURL: (NSURL *)URL
|
||||
{
|
||||
ASSIGN(this->URL, URL);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 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 NSURLRequest (NSHTTPURLRequest)
|
||||
|
||||
- (NSDictionary *) allHTTPHeaderFields
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
- (NSData *) HTTPBody
|
||||
{
|
||||
return this->body;
|
||||
}
|
||||
|
||||
- (NSInputStream *) HTTPBodyStream
|
||||
{
|
||||
return this->bodyStream;
|
||||
}
|
||||
|
||||
- (NSString *) HTTPMethod
|
||||
{
|
||||
return this->method;
|
||||
}
|
||||
|
||||
- (BOOL) HTTPShouldHandleCookies
|
||||
{
|
||||
return this->shouldHandleCookies;
|
||||
}
|
||||
|
||||
- (NSString *) valueForHTTPHeaderField: (NSString *)field
|
||||
{
|
||||
NSString *value = nil;
|
||||
|
||||
if (this->headers != 0)
|
||||
{
|
||||
value = (NSString*)NSMapGet(this->headers, (void*)field);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation NSMutableURLRequest (NSMutableHTTPURLRequest)
|
||||
|
||||
- (void) addValue: (NSString *)value forHTTPHeaderField: (NSString *)field
|
||||
{
|
||||
NSString *old = [self valueForHTTPHeaderField: field];
|
||||
|
||||
if (old != nil)
|
||||
{
|
||||
value = [old stringByAppendingFormat: @",%@", value];
|
||||
}
|
||||
[self setValue: value forHTTPHeaderField: field];
|
||||
}
|
||||
|
||||
- (void) setAllHTTPHeaderFields: (NSDictionary *)headerFields
|
||||
{
|
||||
NSEnumerator *enumerator = [headerFields keyEnumerator];
|
||||
NSString *field;
|
||||
|
||||
while ((field = [enumerator nextObject]) != nil)
|
||||
{
|
||||
id value = [headerFields objectForKey: field];
|
||||
|
||||
if ([value isKindOfClass: [NSString class]] == YES)
|
||||
{
|
||||
[self setValue: (NSString*)value forHTTPHeaderField: field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setHTTPBodyStream: (NSInputStream *)inputStream
|
||||
{
|
||||
DESTROY(this->body);
|
||||
ASSIGN(this->bodyStream, inputStream);
|
||||
}
|
||||
|
||||
- (void) setHTTPBody: (NSData *)data
|
||||
{
|
||||
DESTROY(this->bodyStream);
|
||||
ASSIGNCOPY(this->body, data);
|
||||
}
|
||||
|
||||
- (void) setHTTPMethod: (NSString *)method
|
||||
{
|
||||
ASSIGNCOPY(this->method, method);
|
||||
}
|
||||
|
||||
- (void) setHTTPShouldHandleCookies: (BOOL)should
|
||||
{
|
||||
this->shouldHandleCookies = should;
|
||||
}
|
||||
|
||||
- (void) setValue: (NSString *)value forHTTPHeaderField: (NSString *)field
|
||||
{
|
||||
if (this->headers == 0)
|
||||
{
|
||||
this->headers = NSCreateMapTable(headerKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 8);
|
||||
}
|
||||
NSMapInsert(this->headers, (void*)field, (void*)value);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSURLRequest (Private)
|
||||
- (id) _propertyForKey: (NSString*)key
|
||||
{
|
||||
return [this->properties objectForKey: key];
|
||||
}
|
||||
|
||||
- (void) _setProperty: (id)value forKey: (NSString*)key
|
||||
{
|
||||
if (this->properties == nil)
|
||||
{
|
||||
this->properties = [NSMutableDictionary new];
|
||||
[this->properties setObject: value forKey: key];
|
||||
}
|
||||
}
|
||||
@end
|
338
Source/NSURLResponse.m
Normal file
338
Source/NSURLResponse.m
Normal file
|
@ -0,0 +1,338 @@
|
|||
/* Implementation for NSURLResponse for GNUstep
|
||||
Copyright (C) 2006 Software Foundation, Inc.
|
||||
|
||||
Written by: Richard Frith-Macdonald <frm@gnu.org>
|
||||
Date: 2006
|
||||
|
||||
This file is part of the GNUstep Base 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., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include "GSURLPrivate.h"
|
||||
|
||||
#include "Foundation/NSCoder.h"
|
||||
#include "Foundation/NSMapTable.h"
|
||||
#include "Foundation/NSScanner.h"
|
||||
#include "NSCallBacks.h"
|
||||
#include "GNUstepBase/GSMime.h"
|
||||
|
||||
|
||||
// Internal data storage
|
||||
typedef struct {
|
||||
long long expectedContentLength;
|
||||
NSURL *URL;
|
||||
NSString *MIMEType;
|
||||
NSString *textEncodingName;
|
||||
NSString *statusText;
|
||||
NSMapTable *headers;
|
||||
int statusCode;
|
||||
} Internal;
|
||||
|
||||
typedef struct {
|
||||
@defs(NSURLResponse)
|
||||
} priv;
|
||||
#define this ((Internal*)(((priv*)self)->_NSURLResponseInternal))
|
||||
#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
|
||||
};
|
||||
|
||||
@interface NSURLResponse (Internal)
|
||||
- (void) setStatusCode: (int)code text: (NSString*)text;
|
||||
- (void) setValue: (NSString *)value forHTTPHeaderField: (NSString *)field;
|
||||
- (NSString *) valueForHTTPHeaderField: (NSString *)field;
|
||||
@end
|
||||
|
||||
@implementation NSURLResponse (Internal)
|
||||
- (void) setStatusCode: (int)code text: (NSString*)text
|
||||
{
|
||||
this->statusCode = code;
|
||||
ASSIGNCOPY(this->statusText, text);
|
||||
}
|
||||
- (void) setValue: (NSString *)value forHTTPHeaderField: (NSString *)field
|
||||
{
|
||||
if (this->headers == 0)
|
||||
{
|
||||
this->headers = NSCreateMapTable(headerKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 8);
|
||||
}
|
||||
NSMapInsert(this->headers, (void*)field, (void*)value);
|
||||
}
|
||||
- (NSString *) valueForHTTPHeaderField: (NSString *)field
|
||||
{
|
||||
NSString *value = nil;
|
||||
|
||||
if (this->headers != 0)
|
||||
{
|
||||
value = (NSString*)NSMapGet(this->headers, (void*)field);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSURLResponse
|
||||
|
||||
+ (id) allocWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLResponse *o = [super allocWithZone: z];
|
||||
|
||||
if (o != nil)
|
||||
{
|
||||
o->_NSURLResponseInternal = NSZoneMalloc(z, sizeof(Internal));
|
||||
memset(o->_NSURLResponseInternal, '\0', sizeof(Internal));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
NSURLResponse *o;
|
||||
|
||||
if (NSShouldRetainWithZone(self, z) == YES)
|
||||
{
|
||||
o = RETAIN(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
o = [[self class] allocWithZone: z];
|
||||
o = [o initWithURL: [self URL]
|
||||
MIMEType: [self MIMEType]
|
||||
expectedContentLength: [self expectedContentLength]
|
||||
textEncodingName: [self textEncodingName]];
|
||||
if (o != nil)
|
||||
{
|
||||
ASSIGN(inst->statusText, this->statusText);
|
||||
inst->statusCode = this->statusCode;
|
||||
if (this->headers == 0)
|
||||
{
|
||||
inst->headers = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->headers = NSCopyMapTableWithZone(this->headers, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (this != 0)
|
||||
{
|
||||
RELEASE(this->URL);
|
||||
RELEASE(this->MIMEType);
|
||||
RELEASE(this->textEncodingName);
|
||||
RELEASE(this->statusText);
|
||||
if (this->headers != 0)
|
||||
{
|
||||
NSFreeMapTable(this->headers);
|
||||
}
|
||||
NSZoneFree([self zone], this);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
// FIXME
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
- (long long) expectedContentLength
|
||||
{
|
||||
return this->expectedContentLength;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
// FIXME
|
||||
if ([aCoder allowsKeyedCoding])
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the receiver with the URL, MIMEType, expected length and
|
||||
* text encoding name provided.
|
||||
*/
|
||||
- (id) initWithURL: (NSURL *)URL
|
||||
MIMEType: (NSString *)MIMEType
|
||||
expectedContentLength: (int)length
|
||||
textEncodingName: (NSString *)name
|
||||
{
|
||||
if ((self = [super init]) != nil)
|
||||
{
|
||||
ASSIGN(this->URL, URL);
|
||||
ASSIGNCOPY(this->MIMEType, MIMEType);
|
||||
ASSIGNCOPY(this->textEncodingName, name);
|
||||
this->expectedContentLength = length;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *) MIMEType
|
||||
{
|
||||
return this->MIMEType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a suggested file name for storing the response data, with
|
||||
* suggested names being found in the following order:<br />
|
||||
* <list>
|
||||
* <item>content-disposition header</item>
|
||||
* <item>last path component of URL</item>
|
||||
* <item>host name from URL</item>
|
||||
* <item>'unknown'</item>
|
||||
* </list>
|
||||
* If possible, an extension based on the MIME type of the response
|
||||
* is also appended.<br />
|
||||
* The result should always be a valid file name.
|
||||
*/
|
||||
- (NSString *) suggestedFilename
|
||||
{
|
||||
NSString *disp = [self valueForHTTPHeaderField: @"content-disposition"];
|
||||
NSString *name = nil;
|
||||
|
||||
if (disp != nil)
|
||||
{
|
||||
GSMimeParser *p;
|
||||
GSMimeHeader *h;
|
||||
NSScanner *sc;
|
||||
|
||||
// Try to get name from content disposition header.
|
||||
p = AUTORELEASE([GSMimeParser new]);
|
||||
h = [[GSMimeHeader alloc] initWithName: @"content-displosition"
|
||||
value: disp];
|
||||
AUTORELEASE(h);
|
||||
sc = [NSScanner scannerWithString: [h value]];
|
||||
if ([p scanHeaderBody: sc into: h] == YES)
|
||||
{
|
||||
name = [h parameterForKey: @"filename"];
|
||||
name = [name stringByDeletingPathExtension];
|
||||
}
|
||||
}
|
||||
|
||||
if ([name length] == 0)
|
||||
{
|
||||
name = [[[self URL] absoluteString] lastPathComponent];
|
||||
name = [name stringByDeletingPathExtension];
|
||||
}
|
||||
if ([name length] == 0)
|
||||
{
|
||||
name = [[self URL] host];
|
||||
}
|
||||
if ([name length] == 0)
|
||||
{
|
||||
name = @"unknown";
|
||||
}
|
||||
// FIXME ... add type specific extension
|
||||
return name;
|
||||
}
|
||||
|
||||
- (NSString *) textEncodingName
|
||||
{
|
||||
return this->textEncodingName;
|
||||
}
|
||||
|
||||
- (NSURL *) URL
|
||||
{
|
||||
return this->URL;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation NSHTTPURLResponse
|
||||
|
||||
+ (NSString *) localizedStringForStatusCode: (int)statusCode
|
||||
{
|
||||
// FIXME ... put real responses in here
|
||||
return [NSString stringWithFormat: @"%d", statusCode];
|
||||
}
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
- (int) statusCode
|
||||
{
|
||||
return this->statusCode;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in a new issue