// // pithos_macosAppDelegate.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following // conditions are met: // // 1. Redistributions of source code must retain the above // copyright notice, this list of conditions and the following // disclaimer. // // 2. Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials // provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // // The views and conclusions contained in the software and // documentation are those of the authors and should not be // interpreted as representing official policies, either expressed // or implied, of GRNET S.A. #import "pithos_macosAppDelegate.h" #import "PithosBrowserController.h" @implementation pithos_macosAppDelegate @synthesize pithosBrowserController; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleAppleEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; [pithosBrowserController showWindow:self]; } - (void)handleAppleEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent { NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]]; NSString *host = [url host]; NSString *query = [url query]; NSLog(@"host : '%@', query: '%@'", host, query); NSProcessInfo *processInfo = [NSProcessInfo processInfo]; if ([host isEqualToString:[NSString stringWithFormat:@"%@_%d", [processInfo processName], [processInfo processIdentifier]]] && query) { // user= NSString *authUser; NSRange userRange = [query rangeOfString:@"user=" options:NSCaseInsensitiveSearch]; if (userRange.length == 0) // XXX maybe show an error message? return; NSUInteger authUserStartLocation = userRange.location + userRange.length; NSRange userEndRange = [query rangeOfString:@"&" options:NSCaseInsensitiveSearch range:NSMakeRange(authUserStartLocation, [query length] - authUserStartLocation)]; if (userEndRange.length) { authUser = [[query substringWithRange:NSMakeRange(authUserStartLocation, userEndRange.location - authUserStartLocation)] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } else { authUser = [[query substringFromIndex:authUserStartLocation] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } // token= NSString *authToken; NSRange tokenRange = [query rangeOfString:@"token=" options:NSCaseInsensitiveSearch]; if (tokenRange.length == 0) // XXX maybe show an error message? return; NSUInteger authTokenStartLocation = tokenRange.location + tokenRange.length; NSRange tokenEndRange = [query rangeOfString:@"&" options:NSCaseInsensitiveSearch range:NSMakeRange(authTokenStartLocation, [query length] - authTokenStartLocation)]; if (tokenEndRange.length) { authToken = [[query substringWithRange:NSMakeRange(authTokenStartLocation, tokenEndRange.location - authTokenStartLocation)] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } else { authToken = [[query substringFromIndex:authTokenStartLocation] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } NSLog(@"query authUser: '%@', authToken: '%@'", authUser, authToken); [pithosBrowserController authenticateFromURLWithAuthUser:authUser authToken:authToken]; } // XXX else maybe show an error message? } @end