Plugins/Displays/SMS/GrowlSMSDisplay.m
author boredzo
Sun Jul 06 17:31:40 2008 +0000 (2008-07-06)
changeset 4141 494e5044075d
parent 3706 3fe9b5224f0c
child 4143 f673f14da226
permissions -rw-r--r--
Fixed some memory leaks reported by the clang static analyzer, by autoreleasing these objects immediately rather than releasing some of them later (and not all of the time).
boredzo@2402
     1
//
boredzo@2402
     2
//  GrowlSMSDisplay.m
boredzo@2402
     3
//  Growl Display Plugins
boredzo@2402
     4
//
boredzo@2402
     5
//  Created by Diggory Laycock
ingmarstein@3040
     6
//  Copyright 2005-2006 The Growl Project All rights reserved.
boredzo@2402
     7
//
boredzo@2402
     8
#import "GrowlSMSDisplay.h"
boredzo@2402
     9
#import "GrowlSMSPrefs.h"
boredzo@2402
    10
#import "NSStringAdditions.h"
boredzo@2402
    11
#import "GrowlDefinesInternal.h"
ingmarstein@2699
    12
#import "GrowlApplicationNotification.h"
ingmarstein@2695
    13
#include <Security/SecKeychain.h>
ingmarstein@2695
    14
#include <Security/SecKeychainItem.h>
boredzo@2402
    15
boredzo@2402
    16
#define keychainServiceName "GrowlSMS"
boredzo@2402
    17
#define keychainAccountName "SMSWebServicePassword"
boredzo@2402
    18
boredzo@2402
    19
#define GrowlSMSPrefDomain		@"com.Growl.SMS"
boredzo@2402
    20
#define accountNameKey			@"SMS - Account Name"
boredzo@2402
    21
#define accountAPIIDKey			@"SMS - Account API ID"
boredzo@2402
    22
#define destinationNumberKey	@"SMS - Destination Number"
boredzo@2402
    23
boredzo@2402
    24
boredzo@2402
    25
@implementation GrowlSMSDisplay
boredzo@2402
    26
boredzo@2402
    27
- (id) init {
boredzo@2402
    28
	if ((self = [super init])) {
boredzo@2402
    29
		commandQueue = [[NSMutableArray alloc] init];
boredzo@2402
    30
		xmlHoldingStringValue = [[NSMutableString alloc] init];
boredzo@2402
    31
		waitingForResponse = NO;
boredzo@2402
    32
		creditBalance = 0.0f;
boredzo@2402
    33
	}
boredzo@2402
    34
	return self;
boredzo@2402
    35
}
boredzo@2402
    36
boredzo@2402
    37
- (void) dealloc {
boredzo@2402
    38
	[commandQueue release];
boredzo@2402
    39
ofri@2716
    40
	[preferencePane release];
boredzo@2402
    41
	[super dealloc];
boredzo@2402
    42
}
boredzo@2402
    43
boredzo@2402
    44
- (NSPreferencePane *) preferencePane {
ofri@2716
    45
	if (!preferencePane)
ofri@2716
    46
		preferencePane = [[GrowlSMSPrefs alloc] initWithBundle:[NSBundle bundleWithIdentifier:@"com.Growl.SMS"]];
ofri@2716
    47
	return preferencePane;
boredzo@2402
    48
}
boredzo@2402
    49
ingmarstein@2695
    50
- (void) displayNotification:(GrowlApplicationNotification *)notification {
boredzo@2402
    51
	NSString	*accountNameValue = nil;
boredzo@2402
    52
	NSString	*apiIDValue = nil;
boredzo@2402
    53
	NSString	*destinationNumberValue = nil;
boredzo@2402
    54
boredzo@2402
    55
	READ_GROWL_PREF_VALUE(destinationNumberKey, GrowlSMSPrefDomain, NSString *, &destinationNumberValue);
boredzo@4141
    56
	[destinationNumberValue autorelease];
boredzo@2402
    57
	READ_GROWL_PREF_VALUE(accountAPIIDKey, GrowlSMSPrefDomain, NSString *, &apiIDValue);
boredzo@4141
    58
	[apiIDValue autorelease];
boredzo@2402
    59
	READ_GROWL_PREF_VALUE(accountNameKey, GrowlSMSPrefDomain, NSString *, &accountNameValue);
boredzo@4141
    60
	[accountNameValue autorelease];
boredzo@2402
    61
boredzo@2402
    62
	if (!([destinationNumberValue length] && [apiIDValue length] && [accountNameValue length])) {
boredzo@2402
    63
		NSLog(@"Cannot send SMS - not enough details in preferences.");
boredzo@2402
    64
		return;
boredzo@2402
    65
	}
boredzo@2402
    66
ingmarstein@2695
    67
	NSDictionary *noteDict = [notification dictionaryRepresentation];
boredzo@2402
    68
	NSString *title = [noteDict objectForKey:GROWL_NOTIFICATION_TITLE];
boredzo@2402
    69
	NSString *desc = [noteDict objectForKey:GROWL_NOTIFICATION_DESCRIPTION];
boredzo@2402
    70
ingmarstein@2699
    71
	//	Fetch the SMS password from the keychain
ingmarstein@2634
    72
	unsigned char *password;
boredzo@2402
    73
	UInt32 passwordLength;
boredzo@2402
    74
	OSStatus status;
ingmarstein@2634
    75
	status = SecKeychainFindGenericPassword(NULL,
ingmarstein@2634
    76
											strlen(keychainServiceName), keychainServiceName,
ingmarstein@2634
    77
											strlen(keychainAccountName), keychainAccountName,
ingmarstein@2634
    78
											&passwordLength, (void **)&password, NULL);
ingmarstein@2634
    79
ingmarstein@2634
    80
	CFStringRef passwordString;
boredzo@2402
    81
	if (status == noErr) {
ingmarstein@2634
    82
		passwordString = CFStringCreateWithBytes(kCFAllocatorDefault, password, passwordLength, kCFStringEncodingUTF8, false);
boredzo@2402
    83
		SecKeychainItemFreeContent(NULL, password);
boredzo@2402
    84
	} else {
boredzo@2402
    85
		if (status != errSecItemNotFound)
boredzo@2402
    86
			NSLog(@"Failed to retrieve SMS Account password from keychain. Error: %d", status);
ingmarstein@2634
    87
		passwordString = CFSTR("");
boredzo@2402
    88
	}
boredzo@2402
    89
boredzo@2402
    90
boredzo@2402
    91
	NSString *localHostName = [[NSHost currentHost] name];
boredzo@2402
    92
	NSString *smsSendCommand = [[NSString alloc] initWithFormat:
boredzo@2402
    93
		@"<clickAPI><sendMsg><api_id>%@</api_id><user>%@</user><password>%@</password><to>+%@</to><text>(%@) %@ (%@)</text><from>Growl</from></sendMsg></clickAPI>",
boredzo@2402
    94
		apiIDValue,
boredzo@2402
    95
		accountNameValue,
boredzo@2402
    96
		passwordString,
boredzo@2402
    97
		destinationNumberValue,
boredzo@2402
    98
		title,
boredzo@2402
    99
		desc,
boredzo@2402
   100
		localHostName];
boredzo@2402
   101
boredzo@2402
   102
	NSLog(@"SMS Display...  %@" , smsSendCommand);
boredzo@2402
   103
	[self sendXMLCommand:smsSendCommand];
boredzo@2402
   104
	[smsSendCommand release];
boredzo@2402
   105
boredzo@2402
   106
	//	Check credit balance.
boredzo@2402
   107
	NSString *checkBalanceCommand = [[NSString alloc] initWithFormat:
boredzo@2402
   108
		@"<clickAPI><getBalance><api_id>%@</api_id><user>%@</user><password>%@</password></getBalance></clickAPI>",
boredzo@2402
   109
		apiIDValue,
boredzo@2402
   110
		accountNameValue,
boredzo@2402
   111
		passwordString];
boredzo@2402
   112
ingmarstein@2634
   113
	CFRelease(passwordString);
ingmarstein@2634
   114
boredzo@2402
   115
	[self sendXMLCommand:checkBalanceCommand];
boredzo@2402
   116
	[checkBalanceCommand release];
boredzo@2402
   117
boredzo@2402
   118
	id clickContext = [noteDict objectForKey:GROWL_NOTIFICATION_CLICK_CONTEXT];
boredzo@2402
   119
	if (clickContext) {
boredzo@2402
   120
		NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
boredzo@2402
   121
			[noteDict objectForKey:@"ClickHandlerEnabled"], @"ClickHandlerEnabled",
boredzo@2402
   122
			clickContext,                                   GROWL_KEY_CLICKED_CONTEXT,
boredzo@2402
   123
			[noteDict objectForKey:GROWL_APP_PID],          GROWL_APP_PID,
boredzo@2402
   124
			nil];
boredzo@2402
   125
		[[NSNotificationCenter defaultCenter] postNotificationName:GROWL_NOTIFICATION_TIMED_OUT
ingmarstein@2699
   126
															object:[notification applicationName]
boredzo@2402
   127
														  userInfo:userInfo];
boredzo@2402
   128
		[userInfo release];
boredzo@2402
   129
	}
boredzo@2402
   130
boredzo@2402
   131
}
boredzo@2402
   132
boredzo@2402
   133
boredzo@2402
   134
#pragma mark -
boredzo@2402
   135
#pragma mark Accessors
boredzo@2402
   136
boredzo@2402
   137
- (NSData *) responseData {
boredzo@2402
   138
	return responseData;
boredzo@2402
   139
}
boredzo@2402
   140
boredzo@2402
   141
- (void) setResponseData:(NSData *)newResponseData {
boredzo@2402
   142
	[newResponseData retain];
boredzo@2402
   143
	[responseData release];
boredzo@2402
   144
	responseData = newResponseData;
boredzo@2402
   145
boredzo@2402
   146
	NSLog(@"responseData:  %@", responseData);
boredzo@2402
   147
}
boredzo@2402
   148
boredzo@2402
   149
boredzo@2402
   150
#pragma mark -
boredzo@2402
   151
#pragma mark Instance Methods
boredzo@2402
   152
boredzo@2402
   153
boredzo@2402
   154
/*
boredzo@2402
   155
 <clickAPI>
boredzo@2402
   156
	 <sendMsg>
boredzo@2402
   157
		 <api_id>your_api_id</api_id>
boredzo@2402
   158
		 <user>your_user_name</user>
boredzo@2402
   159
		 <password>your_pass</password>
boredzo@2402
   160
		 <to>+12343455667</to>
boredzo@2402
   161
		 <text>Test text message.</text>
boredzo@2402
   162
		 <from>Growl</from>
boredzo@2402
   163
	 </sendMsg>
boredzo@2402
   164
 </clickAPI>
boredzo@2402
   165
boredzo@2402
   166
boredzo@2402
   167
 API URL:
boredzo@2402
   168
 ==========
boredzo@2402
   169
 https://api.clickatell.com/xml/xml
boredzo@2402
   170
 <input name="data" type="text" value="<clickAPI>$your_xml_data</clickAPI>">
boredzo@2402
   171
boredzo@2402
   172
 //	To do - use the unicode option - when needed - although, it halves the length of SMS we can send.
boredzo@2402
   173
boredzo@2402
   174
 */
boredzo@2402
   175
- (void) sendXMLCommand:(NSString *)commandString {
ingmarstein@2649
   176
	CFStringRef			dataString = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("data=%@"), commandString);
ingmarstein@2649
   177
	CFDataRef			postData = CFStringCreateExternalRepresentation(kCFAllocatorDefault, dataString, kCFStringEncodingUTF8, 0U);
ingmarstein@2649
   178
	CFURLRef			clickatellURL = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("https://api.clickatell.com/xml/xml"), NULL);
ingmarstein@2649
   179
	NSMutableURLRequest	*post = [[NSMutableURLRequest alloc] initWithURL:(NSURL *)clickatellURL];
ingmarstein@2649
   180
	CFStringRef			contentLength = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%u"), CFDataGetLength(postData));
ingmarstein@2649
   181
ingmarstein@2649
   182
	NSLog(@"Sending data: %@", postData);
ingmarstein@2649
   183
ingmarstein@2649
   184
	[post addValue:(NSString *)contentLength forHTTPHeaderField: @"Content-Length"];
boredzo@2402
   185
	[post setHTTPMethod:@"POST"];
ingmarstein@2649
   186
	[post setHTTPBody:(NSData *)postData];
boredzo@2402
   187
	[commandQueue addObject:post];
ingmarstein@2649
   188
	[post release];
ingmarstein@2649
   189
ingmarstein@2649
   190
	CFRelease(postData);
ingmarstein@2649
   191
	CFRelease(dataString);
ingmarstein@2649
   192
	CFRelease(clickatellURL);
ingmarstein@2649
   193
	CFRelease(contentLength);
boredzo@2402
   194
boredzo@2402
   195
	[self processQueue];
boredzo@2402
   196
}
boredzo@2402
   197
boredzo@2402
   198
boredzo@2402
   199
- (void) processQueue {
boredzo@2402
   200
	// NSLog(@"Processing HTTP Command Queue");
boredzo@2402
   201
	if (![commandQueue count]) {
boredzo@2402
   202
		// NSLog(@"Queue is empty...");
boredzo@2402
   203
		return;
boredzo@2402
   204
	}
boredzo@2402
   205
boredzo@2402
   206
	if (!waitingForResponse) {
boredzo@2402
   207
		waitingForResponse = YES;
boredzo@2402
   208
		NSLog(@"Beginning Command Request Connection...");
boredzo@2402
   209
		[NSURLConnection connectionWithRequest:[commandQueue objectAtIndex:0U] delegate: self];
boredzo@2402
   210
	} else {
boredzo@2402
   211
		NSLog(@"Can't process queue  - we are waiting on an existing command's resonse..");
boredzo@2402
   212
	}
boredzo@2402
   213
}
boredzo@2402
   214
boredzo@2402
   215
boredzo@2402
   216
- (void) connectionDidRespond {
boredzo@2402
   217
	NSLog(@"Request/Response transaction complete...");
boredzo@2402
   218
	waitingForResponse = NO;
boredzo@2402
   219
	[commandQueue removeObjectAtIndex:0U];
boredzo@2402
   220
	[self processQueue];
boredzo@2402
   221
}
boredzo@2402
   222
boredzo@2402
   223
- (void) handleResponse {
boredzo@2402
   224
	if (responseParser)
boredzo@2402
   225
		[responseParser release];
boredzo@2402
   226
	responseParser = [[NSXMLParser alloc] initWithData:[self responseData]];
boredzo@2402
   227
	[responseParser setDelegate:self];
boredzo@2402
   228
	[responseParser setShouldResolveExternalEntities:YES];
boredzo@2402
   229
	[responseParser parse]; // return value not used
boredzo@2402
   230
							// if not successful, delegate is informed of error}
boredzo@2402
   231
}
boredzo@2402
   232
boredzo@2402
   233
boredzo@2402
   234
#pragma mark -
boredzo@2402
   235
#pragma mark NSXMLParser Delegate methods:
boredzo@2402
   236
boredzo@2402
   237
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
boredzo@2402
   238
#pragma unused(parser,namespaceURI,qName,attributeDict)
boredzo@2402
   239
	if ([elementName isEqualToString:@"clickAPI"]) {
boredzo@2402
   240
//		NSLog(@"Found the clickAPI element in the response.  That means we got the HTTP part right.");
boredzo@2402
   241
	} else if ([elementName isEqualToString:@"xmlErrorResp"]) {
boredzo@2402
   242
		NSLog(@"Oh Noes! we got an error back from clickatell - we passed them a bad XML request...");
boredzo@2402
   243
	} else if ([elementName isEqualToString:@"fault"]) {
boredzo@2402
   244
//		NSLog(@"Here comes the fault:...");
boredzo@2402
   245
	} else if ([elementName isEqualToString:@"getBalanceResp"]) {
boredzo@2402
   246
//		NSLog(@"Here comes the Balance response:...");
boredzo@2402
   247
		inBalanceResponseElement = YES;
boredzo@2402
   248
	} else if ([elementName isEqualToString:@"ok"]) {
boredzo@2402
   249
//		NSLog(@"Command Success.");
boredzo@2402
   250
		if (inBalanceResponseElement) {
boredzo@2402
   251
//			NSLog(@"Here comes the Balance value:...");
boredzo@2402
   252
		}
boredzo@2402
   253
	} else if ([elementName isEqualToString:@"sendMsgResp"]) {
boredzo@2402
   254
//		NSLog(@"Here comes the Message Send response:...");
boredzo@2402
   255
		inMessageSendResponseElement = YES;
boredzo@2402
   256
	}
boredzo@2402
   257
}
boredzo@2402
   258
boredzo@2402
   259
boredzo@2402
   260
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
boredzo@2402
   261
#pragma unused(parser)
boredzo@2402
   262
	if (!xmlHoldingStringValue)
boredzo@2402
   263
		xmlHoldingStringValue = [[NSMutableString alloc] initWithCapacity:50];
boredzo@2402
   264
	[xmlHoldingStringValue appendString:string];
boredzo@2402
   265
}
boredzo@2402
   266
boredzo@2402
   267
boredzo@2402
   268
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
boredzo@2402
   269
#pragma unused(parser,namespaceURI,qName)
boredzo@2402
   270
	if (   [elementName isEqualToString:@"clickAPI"]
boredzo@2402
   271
		|| [elementName isEqualToString:@"xmlErrorResp"]) {
boredzo@2402
   272
		// nothing to do
boredzo@2402
   273
		return;
boredzo@2402
   274
	} else if ([elementName isEqualToString:@"getBalanceResp"]) {
boredzo@2402
   275
		inBalanceResponseElement = NO;
boredzo@2402
   276
		[xmlHoldingStringValue release];
boredzo@2402
   277
		xmlHoldingStringValue = nil;
boredzo@2402
   278
	} else if ([elementName isEqualToString:@"sendMsgResp"]) {
boredzo@2402
   279
		inMessageSendResponseElement = NO;
boredzo@2402
   280
		[xmlHoldingStringValue release];
boredzo@2402
   281
		xmlHoldingStringValue = nil;
boredzo@2402
   282
	} else if ([elementName isEqualToString:@"fault"]) {
boredzo@2402
   283
		NSLog(@"The fault was: %@" , [xmlHoldingStringValue stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] );
boredzo@2402
   284
		[xmlHoldingStringValue release];
boredzo@2402
   285
		xmlHoldingStringValue = nil;
boredzo@2402
   286
	} else if ([elementName isEqualToString:@"ok"]) {
boredzo@2402
   287
		if (inBalanceResponseElement) {
boredzo@2402
   288
			creditBalance = [[xmlHoldingStringValue stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]] floatValue];
boredzo@2402
   289
			NSLog(@"Your Balance is: %4.1f 'credits'" , creditBalance);
boredzo@2402
   290
			[xmlHoldingStringValue release];
boredzo@2402
   291
			xmlHoldingStringValue = nil;
boredzo@2402
   292
		}
boredzo@2402
   293
	} else if ([elementName isEqualToString:@"apiMsgId"]) {
boredzo@2402
   294
		if (inMessageSendResponseElement) {
boredzo@2402
   295
			NSLog(@"SMS Message Sent (messageId: %@)" , [xmlHoldingStringValue stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]);
boredzo@2402
   296
			[xmlHoldingStringValue release];
boredzo@2402
   297
			xmlHoldingStringValue = nil;
boredzo@2402
   298
		}
boredzo@2402
   299
	} else {
boredzo@2402
   300
		NSLog(@"SMS display: unknown XML element: %@", elementName);
boredzo@2402
   301
	}
boredzo@2402
   302
}
boredzo@2402
   303
boredzo@2402
   304
- (void) parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
boredzo@2402
   305
	NSLog(@"Error Parsing XML response from SMS Gateway - %i, Description: %@, Line: %i, Column: %i",	[parseError code],
boredzo@2402
   306
		  [[parser parserError] localizedDescription],
boredzo@2402
   307
		  [parser lineNumber],
boredzo@2402
   308
		  [parser columnNumber]);
boredzo@2402
   309
}
boredzo@2402
   310
boredzo@2402
   311
boredzo@2402
   312
#pragma mark -
boredzo@2402
   313
#pragma mark NSURLConnection Delegate methods:
boredzo@2402
   314
boredzo@2402
   315
boredzo@2402
   316
/*
boredzo@2402
   317
	The delegate receives this message if connection has cancelled the authentication challenge specified by challenge.
boredzo@2402
   318
 */
boredzo@2402
   319
- (void) connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
boredzo@2402
   320
#pragma unused(connection,challenge)
boredzo@2402
   321
	NSLog(@"didCancelAuthenticationChallenge:");
boredzo@2402
   322
	[self connectionDidRespond];
boredzo@2402
   323
}
boredzo@2402
   324
boredzo@2402
   325
boredzo@2402
   326
/*
boredzo@2402
   327
	The delegate receives this message if connection has failed to load the request successfully. The details of the failure are specified in error.
boredzo@2402
   328
	Once the delegate receives this message, it will receive no further messages for connection.
boredzo@2402
   329
 */
boredzo@2402
   330
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
boredzo@2402
   331
#pragma unused(connection)
boredzo@2402
   332
	NSLog(@"Connection to SMS Web API failed: (%@)", [error localizedDescription]);
boredzo@2402
   333
boredzo@2402
   334
	[self connectionDidRespond];
boredzo@2402
   335
}
boredzo@2402
   336
boredzo@2402
   337
boredzo@2402
   338
/*
boredzo@2402
   339
 The delegate receives this message when connection must authenticate challenge in order to download the request. This method gives the delegate the opportunity to determine the course of action taken for the challenge: provide credentials, continue without providing credentials or cancel the authentication challenge and the download.
boredzo@2402
   340
 The delegate can determine the number of previous authentication challenges by sending the message previousFailureCount to challenge.
boredzo@2402
   341
boredzo@2402
   342
 If the previous failure count is 0 and the value returned by proposedCredential is nil, the delegate can create a new NSURLCredential object, providing a user name and password, and send a useCredential:forAuthenticationChallenge: message to [challenge sender], passing the credential and challenge as parameters. If proposedCredential is not nil, the value is a credential from the URL or the shared credential storage that can be provided to the user as feedback.
boredzo@2402
   343
 The delegate may decide to abandon further attempts at authentication at any time by sending [challenge sender] a continueWithoutCredentialForAuthenticationChallenge: or a cancelAuthenticationChallenge: message. The specific action will be implementation dependent.
boredzo@2402
   344
boredzo@2402
   345
 If the delegate implements this method, the download will suspend until [challenge sender] is sent one of the following messages: useCredential:forAuthenticationChallenge:, continueWithoutCredentialForAuthenticationChallenge: or cancelAuthenticationChallenge:.
boredzo@2402
   346
 If the delegate does not implement this method the default implementation is used. If a valid credential for the request is provided as part of the URL, or is available from the NSURLCredentialStorage the [challenge sender] is sent a useCredential:forAuthenticationChallenge: with the credential. If the challenge has no credential or the credentials fail to authorize access, then continueWithoutCredentialForAuthenticationChallenge: is sent to [challenge sender] instead.
boredzo@2402
   347
evands@3706
   348
 See Also: – cancelAuthenticationChallenge:, – continueWithoutCredentialForAuthenticationChallenge:, – useCredential:forAuthenticationChallenge:
boredzo@2402
   349
 */
boredzo@2402
   350
- (void) connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
boredzo@2402
   351
	NSLog(@"didReceiveAuthenticationChallenge: %@", challenge);
boredzo@2402
   352
	//	It doesn't need web auth currently - so we're not going to handle this case.
boredzo@2402
   353
	[connection cancel];
boredzo@2402
   354
	//	[self connectionDidRespond];
boredzo@2402
   355
}
boredzo@2402
   356
boredzo@2402
   357
boredzo@2402
   358
/*
boredzo@2402
   359
	The delegate receives this message as connection loads data incrementally. The delegate should concatenate the contents of each data object delivered to build up the complete data for a URL load.
boredzo@2402
   360
	This method provides the only way for an asynchronous delegate to retrieve the loaded data. It is the responsibility of the delegate to retain or copy this data as it is delivered.
boredzo@2402
   361
 */
boredzo@2402
   362
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
boredzo@2402
   363
#pragma unused(connection)
boredzo@2402
   364
	//	NSLog(@"didReceiveData:  %@", data);
boredzo@2402
   365
	[self setResponseData: data];
boredzo@2402
   366
	[self handleResponse];
boredzo@2402
   367
}
boredzo@2402
   368
boredzo@2402
   369
boredzo@2402
   370
/*
boredzo@2402
   371
	The delegate receives this message when the URL loading system has received sufficient load data for connection to construct the NSURLResponse object, response.
boredzo@2402
   372
 The response is immutable and will not be modified by the URL loading system once it is presented to the delegate.
boredzo@2402
   373
boredzo@2402
   374
 In rare cases, for example in the case of a HTTP load where the content type of the load data is multipart/x-mixed-replace, the delegate will receive more than one connection:didReceiveResponse: message.
boredzo@2402
   375
 In the event this occurs, delegates should discard all data previously delivered by connection:didReceiveData:, and should be prepared to handle the, potentially different, MIME type reported by the NSURLResponse.
boredzo@2402
   376
boredzo@2402
   377
 Note that the only case where this message is not sent to the delegate is when the protocol implementation encounters an error before a response could be created.
boredzo@2402
   378
boredzo@2402
   379
 */
boredzo@2402
   380
boredzo@2402
   381
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
boredzo@2402
   382
#pragma unused(connection,response)
boredzo@2402
   383
//	NSLog(@"didReceiveResponse:  URL(%@) expectedDataLength:(%d)", [response URL], [response expectedContentLength]  );
boredzo@2402
   384
boredzo@2402
   385
//	NSLog(@" MIME:(%@)" , [response MIMEType]);
boredzo@2402
   386
//	NSLog(@" textEncoding:(%@)" , [response textEncodingName]);
boredzo@2402
   387
}
boredzo@2402
   388
boredzo@2402
   389
boredzo@2402
   390
- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
boredzo@2402
   391
#pragma unused(connection,cachedResponse)
boredzo@2402
   392
	//	No Caching please...  Since we're using HTTPS none should occur - but no harm in being cautious.
boredzo@2402
   393
	return nil;
boredzo@2402
   394
}
boredzo@2402
   395
boredzo@2402
   396
boredzo@2402
   397
/*
boredzo@2402
   398
boredzo@2402
   399
 The delegate receives this message when connection determines that it must change URLs in order to continue loading a request.
boredzo@2402
   400
 The delegate should inspect the redirected request specified by request and copy and modify request as necessary to change its attributes, or return request unmodified.
boredzo@2402
   401
 The NSURLResponse that caused the redirect is specified by redirectResponse.
boredzo@2402
   402
 The redirectResponse will be nil in cases where this method is not being sent as a result of involving the delegate in redirect processing.
evands@3706
   403
 If the delegate wishes to cancel the redirect, it should call the connection object’s cancel method.
boredzo@2402
   404
 Alternatively, the delegate method can return nil to cancel the redirect, and the connection will continue to process.
boredzo@2402
   405
 This has special relevance in the case where redirectResponse is not nil.
boredzo@2402
   406
 In this case, any data that is loaded for the connection will be sent to the delegate, and the delegate will receive a connectionDidFinishLoading or connection:didFailLoadingWithError: message, as appropriate.
boredzo@2402
   407
evands@3706
   408
 The delegate can receive this message as a result of transforming a request’s URL to its canonical form, or for protocol-specific reasons, such as an HTTP redirect.
boredzo@2402
   409
 The delegate implementation should be prepared to receive this message multiple times.
boredzo@2402
   410
boredzo@2402
   411
 */
boredzo@2402
   412
boredzo@2402
   413
- (NSURLRequest *) connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse {
boredzo@2402
   414
#pragma unused(request,redirectResponse)
boredzo@2402
   415
	NSLog(@"redirectResponse:");
boredzo@2402
   416
	[connection cancel];
boredzo@2402
   417
	return nil;
boredzo@2402
   418
}
boredzo@2402
   419
boredzo@2402
   420
boredzo@2402
   421
// This delegate method is called when connection has finished loading successfully. The delegate will receive no further messages for connection.
boredzo@2402
   422
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
boredzo@2402
   423
#pragma unused(connection)
boredzo@2402
   424
	// NSLog(@"connectionDidFinishLoading:");
boredzo@2402
   425
	[self connectionDidRespond];
boredzo@2402
   426
}
boredzo@2402
   427
bgannin@3280
   428
bgannin@3280
   429
- (BOOL) requiresPositioning {
bgannin@3280
   430
	return NO;
bgannin@3280
   431
}
bgannin@3280
   432
boredzo@2402
   433
@end