2006-06-16 15:21:39 +00:00
|
|
|
/* Implementation for NSHTTPCookie for GNUstep
|
|
|
|
Copyright (C) 2006 Software Foundation, Inc.
|
|
|
|
|
2009-03-20 18:52:59 +00:00
|
|
|
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
2006-06-16 15:21:39 +00:00
|
|
|
Date: 2006
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2006-06-16 15:21:39 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2006-06-16 15:21:39 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2006-06-16 15:21:39 +00:00
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2007-03-01 17:35:43 +00:00
|
|
|
o->_NSHTTPCookieInternal = NSZoneCalloc(z, 1, sizeof(Internal));
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2009-02-23 20:42:32 +00:00
|
|
|
- (NSUInteger) version
|
2006-06-16 15:21:39 +00:00
|
|
|
{
|
2009-02-23 20:42:32 +00:00
|
|
|
return [[this->_properties objectForKey: NSHTTPCookieVersion] integerValue];
|
2006-06-16 15:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|