forked from billymeltdown/cocoafob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added files to support custom URL scheme for application registration…
…; README updated with instructions
- Loading branch information
Gleb Dolgich
committed
Mar 20, 2009
1 parent
2edd097
commit 1d9c1ec
Showing
5 changed files
with
215 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Decloner.scriptSuite: | ||
{ | ||
Name = Decloner; | ||
AppleEventCode = "DeCl"; | ||
Commands = { | ||
"GetURL" = { | ||
CommandClass = DCDeclonerCommand; | ||
AppleEventCode = GURL; | ||
AppleEventClassCode = GURL; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Decloner.scriptTerminology: | ||
{ | ||
Name = "Decloner commands"; | ||
Description = "Commands to handle a URL"; | ||
Commands = { | ||
"GetURL" = { | ||
"Name" = "get URL"; | ||
"Description" = "Open a URL"; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// CocoaFob | ||
// | ||
// URLCommand.h | ||
// | ||
// Support for custom URL scheme for app registration | ||
// | ||
// Created by Gleb Dolgich on 20/03/2009. | ||
// Follow me on Twitter @gbd | ||
// Copyright (C) 2009 PixelEspresso. All rights reserved. | ||
// Licensed under CC Attribution License 3.0 <http://creativecommons.org/licenses/by/3.0/> | ||
// | ||
// Based on "Handling URL schemes in Cocoa", a blog post by Kimbro Staken | ||
// <http://www.xmldatabases.org/WK/blog/1154?t=item> | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface URLCommand : NSScriptCommand { | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// CocoaFob | ||
// | ||
// URLCommand.h | ||
// | ||
// Support for custom URL scheme for app registration. | ||
// Pay attention to the TODO: comments below. | ||
// | ||
// Created by Gleb Dolgich on 20/03/2009. | ||
// Follow me on Twitter @gbd | ||
// Copyright (C) 2009 PixelEspresso. All rights reserved. | ||
// Licensed under CC Attribution License 3.0 <http://creativecommons.org/licenses/by/3.0/> | ||
// | ||
// Based on "Handling URL schemes in Cocoa", a blog post by Kimbro Staken | ||
// <http://www.xmldatabases.org/WK/blog/1154?t=item> | ||
// | ||
|
||
#import "URLCommand.h" | ||
#import "NSString+PECrypt.h" | ||
|
||
@interface URLCommand () | ||
|
||
- (id)performWithURL:(NSString *)url; | ||
|
||
@end | ||
|
||
|
||
@implementation URLCommand | ||
|
||
- (id)performDefaultImplementation { | ||
NSString *url = [self directParameter]; | ||
NSLog(@"URL = %@", url); | ||
return [self performWithURL:url]; | ||
} | ||
|
||
- (id)performWithURL:(NSString *)url { | ||
// URL has the following format: | ||
// com.mycompany.myapp.lic://<base64-encoded-username>/<serial-number> | ||
NSArray *protocolAndTheRest = [url componentsSeparatedByString:@"://"]; | ||
if ([protocolAndTheRest count] != 2) { | ||
NSLog(@"License URL is invalid (no protocol)"); | ||
return nil; | ||
} | ||
// Separate user name and serial number | ||
NSArray *userNameAndSerialNumber = [[protocolAndTheRest objectAtIndex:1] componentsSeparatedByString:@"/"]; | ||
if ([userNameAndSerialNumber count] != 2) { | ||
NSLog(@"License URL is invalid (missing parts)"); | ||
return nil; | ||
} | ||
// Decode base64-encoded user name | ||
NSString *usernameb64 = (NSString *)[userNameAndSerialNumber objectAtIndex:0]; | ||
NSString *username = [usernameb64 base64Decode]; | ||
NSLog(@"User name: %@", username); | ||
NSString *serial = (NSString *)[userNameAndSerialNumber objectAtIndex:1]; | ||
NSLog(@"Serial: %@", serial); | ||
// TODO: Save registration to preferences. | ||
// TODO: Broadcast notification of a changed registration information. | ||
return nil; | ||
} | ||
|
||
@end |