From 1002a9616fb3c3becc30958b3259b595bb46aad7 Mon Sep 17 00:00:00 2001 From: GRMrGecko Date: Thu, 10 Feb 2011 11:26:13 -0600 Subject: [PATCH] Made it check the path of the url and not the full url to prevent it from allowing urls with the parameters of an image extension. Made it not embed images from people that are strangers unless you set a default to allow images by strangers. --- Classes/MGMAdinline.h | 4 ++- Classes/MGMAdinline.m | 75 +++++++++++++++++++++++-------------------- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/Classes/MGMAdinline.h b/Classes/MGMAdinline.h index 8e6175b..1470778 100644 --- a/Classes/MGMAdinline.h +++ b/Classes/MGMAdinline.h @@ -10,13 +10,15 @@ #import #import #import +#import +#import #import #import #import #import "WebKit Message View/AIWebKitMessageViewController.h" @interface MGMAdinline : AIPlugin { - + BOOL allowsStrangers; } @end \ No newline at end of file diff --git a/Classes/MGMAdinline.m b/Classes/MGMAdinline.m index c858beb..9946491 100644 --- a/Classes/MGMAdinline.m +++ b/Classes/MGMAdinline.m @@ -9,6 +9,8 @@ #import "MGMAdinline.h" #import +NSString * const MGMAIAllowStrangers = @"MGMAIAllowStrangers"; + @protocol MGMChatViewController - (AIWebKitMessageViewController *)messageDisplayController; @end @@ -19,6 +21,7 @@ } - (void)installPlugin { + allowsStrangers = [[NSUserDefaults standardUserDefaults] boolForKey:MGMAIAllowStrangers]; [[adium contentController] registerHTMLContentFilter:self direction:AIFilterIncoming]; [[adium contentController] registerHTMLContentFilter:self direction:AIFilterOutgoing]; } @@ -28,44 +31,48 @@ } - (NSString *)filterHTMLString:(NSString *)theHTMLString content:(AIContentObject *)theContent { - NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil]; - NSMutableString *html = [[theHTMLString mutableCopy] autorelease]; - NSRange range = NSMakeRange(0, [html length]); - NSString *shouldScroll = nil; - while (range.length>1) { - NSAutoreleasePool *pool = [NSAutoreleasePool new]; - NSRange linkRange = [html rangeOfString:@"" options:NSCaseInsensitiveSearch range:range]; - if (linkStartRange.location==NSNotFound) - continue; - range.location = linkStartRange.location+linkStartRange.length; - range.length = [html length]-range.location; - NSRange linkEndRange = [html rangeOfString:@"<" options:NSCaseInsensitiveSearch range:range]; - if (linkEndRange.location==NSNotFound) - continue; - range.location = linkEndRange.location+linkEndRange.length; - range.length = [html length]-range.location; - linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length)); - NSString *link = [html substringWithRange:linkRange]; - if ([imageExtensions containsObject:[[link pathExtension] lowercaseString]]) { - if (shouldScroll==nil) { - WebView *webview = (WebView *)[[(id)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView]; - shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"]; - } - NSString *image = [NSString stringWithFormat:@"", link, shouldScroll]; - [html replaceCharactersInRange:linkRange withString:image]; - range.location += [image length]-linkRange.length; + AIListObject *source = [theContent source]; + if (allowsStrangers || ![source isStranger]) { + NSArray *imageExtensions = [NSArray arrayWithObjects:@"png", @"jpg", @"jpeg", @"tif", @"tiff", @"gif", @"bmp", nil]; + NSMutableString *html = [[theHTMLString mutableCopy] autorelease]; + NSRange range = NSMakeRange(0, [html length]); + NSString *shouldScroll = nil; + while (range.length>1) { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + NSRange linkRange = [html rangeOfString:@"" options:NSCaseInsensitiveSearch range:range]; + if (linkStartRange.location==NSNotFound) + continue; + range.location = linkStartRange.location+linkStartRange.length; + range.length = [html length]-range.location; + NSRange linkEndRange = [html rangeOfString:@"<" options:NSCaseInsensitiveSearch range:range]; + if (linkEndRange.location==NSNotFound) + continue; + range.location = linkEndRange.location+linkEndRange.length; + range.length = [html length]-range.location; + linkRange = NSMakeRange(linkStartRange.location+linkStartRange.length, linkEndRange.location-(linkStartRange.location+linkStartRange.length)); + NSString *link = [html substringWithRange:linkRange]; + if ([imageExtensions containsObject:[[[[NSURL URLWithString:link] path] pathExtension] lowercaseString]]) { + if (shouldScroll==nil) { + WebView *webview = (WebView *)[[(id)[[[theContent chat] chatContainer] chatViewController] messageDisplayController] messageView]; + shouldScroll = [webview stringByEvaluatingJavaScriptFromString:@"nearBottom();"]; + } + NSString *image = [NSString stringWithFormat:@"", link, shouldScroll]; + [html replaceCharactersInRange:linkRange withString:image]; + range.location += [image length]-linkRange.length; + range.length = [html length]-range.location; + } + } else { + break; } - } else { - break; + [pool drain]; } - [pool drain]; + return html; } - return html; + return theHTMLString; } - (CGFloat)filterPriority { return (CGFloat)LOWEST_FILTER_PRIORITY;