#import <Foundation/Foundation.h>

#import "Protocol.h"

@interface URLConnector : NSObject
@end

@implementation URLConnector

- (void) start;
{
	NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.quantum-step.com"]];
	NSURLConnection *c=[NSURLConnection connectionWithRequest:request delegate:self];
	[[NSRunLoop currentRunLoop] run];
}

- (void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error;
{
	NSLog(@"connection error: %@", error);
}

- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response;
{
	NSLog(@"response received: %@", response);
	NSLog(@"all headers: %@", [(NSHTTPURLResponse *) response allHeaderFields]);
}

- (void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data;
{
	NSLog(@"data received");
}

@end

int main(int argc, const char *argv[])
{
	NSAutoreleasePool *arp=[NSAutoreleasePool new];
	NSLog(@"started");
	
#if 0	// NSUserDefaults & domains
	NSLog(@"persistent %@", [[NSUserDefaults standardUserDefaults] persistentDomainNames]); 
	NSLog(@"volatile   %@", [[NSUserDefaults standardUserDefaults] volatileDomainNames]); 
#endif
	
#if 0	// NSPredicate
	{
		NSPredicate *p, *q;
		p=[NSPredicate predicateWithFormat:@"%K like %@+$b+$c", @"$single", @"b\""];
		NSLog(@"format=%@", [p predicateFormat]);
		if([p respondsToSelector:@selector(subpredicates)])
			NSLog(@"subpredicates=%@", [(NSCompoundPredicate *)p subpredicates]);
		if([p respondsToSelector:@selector(leftExpression)])
			NSLog(@"left=%@", [(NSComparisonPredicate *)p leftExpression]);
		if([p respondsToSelector:@selector(rightExpression)])
			NSLog(@"right=%@", [(NSComparisonPredicate *)p rightExpression]);
		q=[p predicateWithSubstitutionVariables:[NSDictionary dictionaryWithObjectsAndKeys:
			@"val_for_single_string", @"single",	// why %K does not make a variable
			@"val_for_$b", @"b",
			@"val_for_$c", @"c",
			nil]];
		NSLog(@"substituted=%@", [p predicateFormat]);
		NSLog(@"  should be \"$single\" like \"b\\\"\"+val_for_$b+val_for_$c");
	}
#endif


#if 0
{
	NSHTTPCookie *c1=[NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:
		@"name with ;", NSHTTPCookieName,
		@"http://www.origin.org", NSHTTPCookieOriginURL,	// or should we define NSHTTPCookieDomain
		@"cookie value with ;", NSHTTPCookieValue,
		@"1", NSHTTPCookieVersion,
		nil]];
	NSHTTPCookie *c2=[NSHTTPCookie cookieWithProperties:[NSDictionary dictionaryWithObjectsAndKeys:
		@"name2", NSHTTPCookieName,
																							@"http://www.origin.org", NSHTTPCookieOriginURL,
																								   // or NSHTTPCookieDomain
		@"cookie value2", NSHTTPCookieValue,
		@"1", NSHTTPCookieVersion,
		nil]];
	NSLog(@"cookie1=%@", c1);
	NSLog(@"cookie2=%@", c2);
	NSLog(@"header=%@",
		  [NSHTTPCookie requestHeaderFieldsWithCookies:
			  [NSArray arrayWithObjects:c1, c2, nil]]);
	[[[URLConnector alloc] init] start];
}
#endif

#if 1 // NSURL
{
	NSURL *url=[NSURL URLWithString:@"file%20name.htm;param1;param2?something=other&andmore=more#fragments"
					  relativeToURL:[NSURL URLWithString:@"scheme://user:password@host.domain.org:888/path/absfile.htm"]];
	NSLog(@"description: %@", [url description]);
	NSLog(@"absoluteString: %@", [url absoluteString]);
	NSLog(@"absoluteURL: %@", [url absoluteURL]);
	NSLog(@"baseURL: %@", [url baseURL]);
	NSLog(@"fragment: %@", [url fragment]);
	NSLog(@"host: %@", [url host]);
	NSLog(@"isFile: %@", [url isFileURL]?@"YES":@"NO");
	NSLog(@"parameterString: %@", [url parameterString]);
	NSLog(@"password: %@", [url password]);
	NSLog(@"path: %@", [url path]);
	NSLog(@"port: %@", [url port]);
	NSLog(@"query: %@", [url query]);
	NSLog(@"relativePath: %@", [url relativePath]);
	NSLog(@"relativeString: %@", [url relativeString]);
	NSLog(@"resourceSpecifier: %@", [url resourceSpecifier]);
	NSLog(@"scheme: %@", [url scheme]);
	NSLog(@"standardizedURL: %@", [url standardizedURL]);
	NSLog(@"user: %@", [url user]);
}
#endif
[arp release];
exit(0);
}
