From f633a067d2120cca67fd1b2782688424cadde9d4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 11 Nov 2010 09:44:37 +0000 Subject: =?UTF-8?q?=E2=80=A2=20some=20improvements=20for=20sequelpro://pro?= =?UTF-8?q?cess=5Fid/command/param1/param2=20url=20scheme=20support=20-=20?= =?UTF-8?q?introduced=20an=20unique=20process=20ID=20for=20each=20called?= =?UTF-8?q?=20bash=20command=20which=20will=20be=20set=20for=20the=20curre?= =?UTF-8?q?nt=20SPDatabaseDocument=20and=20passed=20as=20environment=20she?= =?UTF-8?q?ll=20variable=20SP=5FPROCESS=5FID=20to=20ensure=20that=20such?= =?UTF-8?q?=20a=20scheme=20command=20will=20be=20executed=20by=20the=20cor?= =?UTF-8?q?rect=20SPDatabaseDocument,=20to=20avoid=20security=20issues=20i?= =?UTF-8?q?e=20one=20can=20authenticate=20such=20a=20sheme=20command,=20to?= =?UTF-8?q?=20enable=20url=20scheme=20process=20communication=20based=20on?= =?UTF-8?q?=20file=20shake-hands=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPAppController.m | 48 ++++++++++++++++++++++++++++++++++++++++++++- Source/SPDatabaseDocument.h | 2 ++ Source/SPDatabaseDocument.m | 2 ++ Source/SPStringAdditions.m | 11 ++++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) (limited to 'Source') 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 - diff --git a/Source/SPDatabaseDocument.h b/Source/SPDatabaseDocument.h index 31c35f7e..0934f1ff 100644 --- a/Source/SPDatabaseDocument.h +++ b/Source/SPDatabaseDocument.h @@ -202,11 +202,13 @@ NSWindow *parentWindow; NSTabViewItem *parentTabViewItem; BOOL isProcessing; + NSString *processID; } @property (readwrite, assign) SPWindowController *parentWindowController; @property (readwrite, assign) NSTabViewItem *parentTabViewItem; @property (readwrite, assign) BOOL isProcessing; +@property (readwrite, retain) NSString *processID; @property (readonly) SPServerSupport *serverSupport; - (BOOL)isUntitled; diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index f3f419d8..c8f7bc7d 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -72,6 +72,7 @@ @synthesize parentTabViewItem; @synthesize isProcessing; @synthesize serverSupport; +@synthesize processID; - (id)init { @@ -4626,6 +4627,7 @@ if (titleAccessoryView) [titleAccessoryView release]; if (taskProgressWindow) [taskProgressWindow release]; if (serverSupport) [serverSupport release]; + if (processID) [processID release]; [super dealloc]; } diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 9d9d1779..c57ccacb 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -419,8 +419,17 @@ NSTask *bashTask = [[NSTask alloc] init]; [bashTask setLaunchPath: @"/bin/bash"]; + NSMutableDictionary *theEnv = [NSMutableDictionary dictionary]; + [theEnv setDictionary:shellEnvironment]; + + // Create and set an unique process ID for each SPDatabaseDocument which has to passed + // for each sequelpro:// scheme command as user to be able to identify the url scheme command. + // Furthermore this id is used to communicate with the called command as file name. + NSString *processID = [NSString stringWithNewUUID]; + [theEnv setObject:processID forKey:@"SP_PROCESS_ID"]; + [[[[NSApp mainWindow] delegate] selectedTableDocument] setProcessID:processID]; if(shellEnvironment != nil && [shellEnvironment isKindOfClass:[NSDictionary class]] && [shellEnvironment count]) - [bashTask setEnvironment:shellEnvironment]; + [bashTask setEnvironment:theEnv]; if(path != nil) [bashTask setCurrentDirectoryPath:path]; -- cgit v1.2.3