aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPAppController.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-11 09:44:37 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-11 09:44:37 +0000
commitf633a067d2120cca67fd1b2782688424cadde9d4 (patch)
tree613f7364482c73e12b626da99897470cbb9687ed /Source/SPAppController.m
parentdb80c9b84be4326d2e2d36839c532159fb9d61fd (diff)
downloadsequelpro-f633a067d2120cca67fd1b2782688424cadde9d4.tar.gz
sequelpro-f633a067d2120cca67fd1b2782688424cadde9d4.tar.bz2
sequelpro-f633a067d2120cca67fd1b2782688424cadde9d4.zip
• some improvements for sequelpro://process_id/command/param1/param2 url scheme support
- introduced an unique process ID for each called bash command which will be set for the current SPDatabaseDocument and passed as environment shell variable SP_PROCESS_ID to ensure that such a scheme command will be executed by the correct SPDatabaseDocument, to avoid security issues ie one can authenticate such a sheme command, to enable url scheme process communication based on file shake-hands etc.
Diffstat (limited to 'Source/SPAppController.m')
-rw-r--r--Source/SPAppController.m48
1 files changed, 47 insertions, 1 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 4b5b997c..adb4eb95 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -508,11 +508,57 @@
/**
* “sequelpro://” url dispatcher
+ *
+ * sequelpro://PROCESS_ID@command/parameter1/parameter2/...
+ * parameters has to be escaped according to RFC 1808 eg %3F for a '?'
+ *
*/
- (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
+
NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
- NSLog(@"url = %@", url);
+
+ NSString *command = [url host];
+ NSString *passedProcessID = [url user];
+ NSArray *parameter;
+ NSArray *pathComponents = [url pathComponents];
+ if([pathComponents count] > 1)
+ parameter = [pathComponents subarrayWithRange:NSMakeRange(1,[[url pathComponents] count]-1)];
+ else
+ parameter = [NSArray array];
+
+ NSString *activeProcessID = [[[[self frontDocumentWindow] delegate] selectedTableDocument] processID];
+
+ SPDatabaseDocument *processDocument = nil;
+
+ // Try to find the SPDatabaseDocument which sent the the url scheme command
+ // For speed check the front most first otherwise iterate through all
+ if(passedProcessID) {
+ if([activeProcessID isEqualToString:passedProcessID]) {
+ processDocument = [[[self frontDocumentWindow] delegate] selectedTableDocument];
+ } else {
+ for (NSWindow *aWindow in [NSApp orderedWindows]) {
+ if([[aWindow windowController] isMemberOfClass:[SPWindowController class]]) {
+ for(SPDatabaseDocument *doc in [[aWindow windowController] documents]) {
+ if([doc processID] && [[doc processID] isEqualToString:passedProcessID]) {
+ processDocument = doc;
+ break;
+ }
+ }
+ }
+ if(processDocument) break;
+ }
+ }
+ }
+
+ if(processDocument)
+ NSLog(@"process doc ID: %@\n%@", [processDocument processID], [processDocument tabTitleForTooltip]);
+ else
+ NSLog(@"No corresponding doc found");
+ NSLog(@"param: %@", parameter);
+ NSLog(@"command: %@", command);
+ NSLog(@"command id: %@", passedProcessID);
+
}
#pragma mark -