adium 3429:45757f6732dd: Fix clang.

commits at adium.im commits at adium.im
Thu Oct 28 17:59:46 UTC 2010


details:	http://hg.adium.im/adium/rev/45757f6732dd
revision:	3429:45757f6732dd
author:		Frank Dowsett <wixardy at adium.im>
date:		Thu Oct 28 13:57:17 2010 -0400

Fix clang.
Subject: adium 3430:6f998f0fe450: Patch from shaynesweeney to add Imgur as an image uploader. Fixes #13186

details:	http://hg.adium.im/adium/rev/6f998f0fe450
revision:	3430:6f998f0fe450
author:		Frank Dowsett <wixardy at adium.im>
date:		Thu Oct 28 13:57:20 2010 -0400

Patch from shaynesweeney to add Imgur as an image uploader. Fixes #13186

diffs (240 lines):

diff -r 384648bd38d8 -r 6f998f0fe450 Adium.xcodeproj/project.pbxproj
--- a/Adium.xcodeproj/project.pbxproj	Thu Oct 28 00:18:28 2010 -0500
+++ b/Adium.xcodeproj/project.pbxproj	Thu Oct 28 13:57:20 2010 -0400
@@ -1149,6 +1149,7 @@
 		4F1CB6420D640DA40073A1E6 /* info_segment.png in Resources */ = {isa = PBXBuildFile; fileRef = 4F1CB63E0D640DA40073A1E6 /* info_segment.png */; };
 		4F1CB64C0D640F4F0073A1E6 /* ContactInfoInspector.nib in Resources */ = {isa = PBXBuildFile; fileRef = 4F1CB64B0D640F4F0073A1E6 /* ContactInfoInspector.nib */; };
 		5A1781860EC1215D00BA1E04 /* AIAutoScrollTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A1781850EC1215D00BA1E04 /* AIAutoScrollTextView.m */; };
+		5A94397B1279ECB800FDD81D /* AIImgurImageUploader.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A94397A1279ECB800FDD81D /* AIImgurImageUploader.m */; };
 		5A9A9F8911F2951400328DF9 /* AIDoNothingContactAlertPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A9A9F8811F2951400328DF9 /* AIDoNothingContactAlertPlugin.m */; };
 		5A9A9F8B11F295EB00328DF9 /* Stop sign.png in Resources */ = {isa = PBXBuildFile; fileRef = 5A9A9F8A11F295EB00328DF9 /* Stop sign.png */; };
 		63093C2F0892143500F118D3 /* newContentThreeDigits.png in Resources */ = {isa = PBXBuildFile; fileRef = 63093C2D0892143500F118D3 /* newContentThreeDigits.png */; };
@@ -4335,6 +4336,8 @@
 		5A80CCAC121F5A7B00D0670A /* uk_UA */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = uk_UA; path = Resources/uk_UA.lproj/StatusPreferences.nib; sourceTree = "<group>"; };
 		5A80CCAD121F5A7B00D0670A /* uk_UA */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = uk_UA; path = Resources/uk_UA.lproj/StatusSortConfiguration.nib; sourceTree = "<group>"; };
 		5A80CCAE121F5A7B00D0670A /* uk_UA */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = uk_UA; path = "Plugins/WebKit Message View/uk_UA.lproj/WebKitPreferencesView.nib"; sourceTree = "<group>"; };
+		5A9439791279ECB800FDD81D /* AIImgurImageUploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIImgurImageUploader.h; path = "Plugins/Image Uploading Plugin/AIImgurImageUploader.h"; sourceTree = "<group>"; };
+		5A94397A1279ECB800FDD81D /* AIImgurImageUploader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AIImgurImageUploader.m; path = "Plugins/Image Uploading Plugin/AIImgurImageUploader.m"; sourceTree = "<group>"; };
 		5A9A9F8711F2951400328DF9 /* AIDoNothingContactAlertPlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AIDoNothingContactAlertPlugin.h; sourceTree = "<group>"; };
 		5A9A9F8811F2951400328DF9 /* AIDoNothingContactAlertPlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AIDoNothingContactAlertPlugin.m; sourceTree = "<group>"; };
 		5A9A9F8A11F295EB00328DF9 /* Stop sign.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Stop sign.png"; path = "Resources/Stop sign.png"; sourceTree = SOURCE_ROOT; };
@@ -5190,6 +5193,8 @@
 				11BE28DE0FCC7D2B000E6A10 /* AIImageUploaderPlugin.m */,
 				11D915570FFC0E9C00B39713 /* AIImageShackImageUploader.h */,
 				11D915580FFC0E9C00B39713 /* AIImageShackImageUploader.m */,
+				5A9439791279ECB800FDD81D /* AIImgurImageUploader.h */,
+				5A94397A1279ECB800FDD81D /* AIImgurImageUploader.m */,
 				11D915700FFC100700B39713 /* AIGenericMultipartImageUploader.h */,
 				11D915710FFC100700B39713 /* AIGenericMultipartImageUploader.m */,
 			);
@@ -10834,6 +10839,7 @@
 				1147FCC410D1CB4C004E9E8D /* AIMediaWindowController.m in Sources */,
 				5A9A9F8911F2951400328DF9 /* AIDoNothingContactAlertPlugin.m in Sources */,
 				76C1AF9C125A906A00D269A9 /* AIAdiumURLProtocol.m in Sources */,
+				5A94397B1279ECB800FDD81D /* AIImgurImageUploader.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff -r 384648bd38d8 -r 6f998f0fe450 Plugins/Image Uploading Plugin/AIGenericMultipartImageUploader.m
--- a/Plugins/Image Uploading Plugin/AIGenericMultipartImageUploader.m	Thu Oct 28 00:18:28 2010 -0500
+++ b/Plugins/Image Uploading Plugin/AIGenericMultipartImageUploader.m	Thu Oct 28 13:57:20 2010 -0400
@@ -50,6 +50,12 @@
 	return nil;	
 }
 
+
+- (NSArray *)additionalFields
+{	
+	return nil;
+}
+
 - (NSUInteger)maximumSize
 {
 	NSAssert1(NO, @"Implementation of %@ lacks maximumSize", self);
@@ -140,6 +146,11 @@
 	[body appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", (bestType == NSJPEGFileType) ? @"image/jpeg" : @"image/png"] dataUsingEncoding:NSUTF8StringEncoding]];
 	[body appendData:imageRepresentation];
 	[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", MULTIPART_FORM_BOUNDARY] dataUsingEncoding:NSUTF8StringEncoding]];
+	for (NSDictionary *field in [self additionalFields]) {
+		[body appendData:[[NSString stringWithFormat:@"--%@\r\n", MULTIPART_FORM_BOUNDARY] dataUsingEncoding:NSUTF8StringEncoding]];
+		[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name= \"%@\"\r\n\r\n", [field objectForKey:@"name"]] dataUsingEncoding:NSUTF8StringEncoding]];
+		[body appendData:[[NSString stringWithFormat:@"%@", [field objectForKey:@"value"]] dataUsingEncoding:NSUTF8StringEncoding]];
+	}
 	
 	NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:
 							 [NSString stringWithFormat:@"multipart/form-data; boundary=%@", MULTIPART_FORM_BOUNDARY], @"Content-type", nil];
diff -r 384648bd38d8 -r 6f998f0fe450 Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m
--- a/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m	Thu Oct 28 00:18:28 2010 -0500
+++ b/Plugins/Image Uploading Plugin/AIImageUploaderPlugin.m	Thu Oct 28 13:57:20 2010 -0400
@@ -8,6 +8,7 @@
 
 #import "AIImageUploaderPlugin.h"
 #import "AIImageShackImageUploader.h"
+#import "AIImgurImageUploader.h"
 #import "AIImageUploaderWindowController.h"
 
 #import <Adium/AIContentControllerProtocol.h>
@@ -36,6 +37,7 @@
 	uploadInstances = [[NSMutableDictionary alloc] init];
 	
 	[uploaders addObject:[AIImageShackImageUploader class]];
+	[uploaders addObject:[AIImgurImageUploader class]];
 	
 	NSMenuItem *menuItem;
 	
diff -r 384648bd38d8 -r 6f998f0fe450 Plugins/Image Uploading Plugin/AIImgurImageUploader.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Image Uploading Plugin/AIImgurImageUploader.h	Thu Oct 28 13:57:20 2010 -0400
@@ -0,0 +1,19 @@
+//
+//  AIImgurImageUploader.h
+//  Adium
+//
+
+#import "AIGenericMultipartImageUploader.h"
+
+ at interface AIImgurImageUploader : AIGenericMultipartImageUploader {
+	NSData						*resultData;
+	NSXMLParser					*responseParser;
+	
+	// Parsing
+	NSMutableDictionary			*lastElement;
+	NSString					*currentElementName;
+	NSMutableDictionary			*currentElement;
+	NSMutableDictionary			*response;
+}
+
+ at end
diff -r 384648bd38d8 -r 6f998f0fe450 Plugins/Image Uploading Plugin/AIImgurImageUploader.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Image Uploading Plugin/AIImgurImageUploader.m	Thu Oct 28 13:57:20 2010 -0400
@@ -0,0 +1,117 @@
+//
+//  AIImgurImageUploader.m
+//  Adium
+//
+
+#import "AIImgurImageUploader.h"
+#import <AIUtilities/AIStringAdditions.h>
+
+ at implementation AIImgurImageUploader
++ (NSString *)serviceName
+{
+	return @"Imgur";
+}
+
+- (NSString *)uploadURL
+{
+	return @"http://imgur.com/api/upload.xml";
+}
+
+- (NSString *)fieldName
+{
+	return @"image";
+}
+
+- (NSArray *)additionalFields
+{
+	return [NSArray arrayWithObject:[NSDictionary dictionaryWithObjectsAndKeys:@"key", @"name", @"c8f0b307b20aae0cbdb0b66b195eedf9", @"value", nil]];
+}
+
+- (NSUInteger)maximumSize
+{
+	return 2500000;
+}
+
+- (void)dealloc
+{
+	[resultData release]; resultData = nil;
+	[response release]; response = nil;
+	[responseParser release]; responseParser = nil;
+	
+	[super dealloc];
+}
+
+#pragma mark Response parsing
+- (void)parseResponse:(NSData *)data
+{
+	response = [[NSMutableDictionary alloc] init];
+	resultData = [data copy];
+	
+	AILogWithSignature(@"%@", [NSString stringWithData:data encoding:NSUTF8StringEncoding]);
+	
+	responseParser = [[NSXMLParser alloc] initWithData:resultData];
+	[responseParser setDelegate:self];
+	[responseParser parse];
+}
+
+- (void)parserDidStartDocument:(NSXMLParser *)parser
+{
+	currentElement = response;
+}
+
+- (void)parser:(NSXMLParser *)parser 
+parseErrorOccurred:(NSError *)error
+{
+	AILogWithSignature(@"%@", [error localizedDescription]);
+	
+	[uploader errorWithMessage:[error localizedDescription] forChat:chat];
+}
+
+- (void)parser:(NSXMLParser *)parser
+didStartElement:(NSString *)elementName 
+  namespaceURI:(NSString *)namespaceURI 
+ qualifiedName:(NSString *)qualifiedName
+	attributes:(NSDictionary *)attributes
+{	
+	if (elementName) {
+		NSMutableDictionary *dict = [NSMutableDictionary dictionary];
+		
+		[currentElement setValue:dict forKey:elementName];
+		
+		lastElement = currentElement;
+		currentElement = dict;
+	}
+	
+	[currentElement addEntriesFromDictionary:attributes];
+}
+
+- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
+{
+	// We don't see anything more than 2-deep. We don't need to check more.
+	currentElement = lastElement;
+}
+
+- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
+{
+	if (![currentElement objectForKey:@"value"]) {
+		[currentElement setValue:[NSMutableString string] forKey:@"value"];
+	}
+	
+	[[currentElement objectForKey:@"value"] appendString:string];
+}
+
+- (void)parserDidEndDocument:(NSXMLParser *)parser
+{
+	NSDictionary *rsp = [response objectForKey:@"rsp"];
+	NSString *status = [rsp objectForKey:@"stat"];
+	
+	if ([status isCaseInsensitivelyEqualToString:@"fail"]) {
+		[uploader errorWithMessage:[rsp valueForKeyPath:@"error_msg.value"] forChat:chat];
+	} else if ([status isCaseInsensitivelyEqualToString:@"ok"]) {
+		[uploader uploadedURL:[rsp valueForKeyPath:@"original_image.value"] forChat:chat];
+	} else {
+		[uploader errorWithMessage:AILocalizedString(@"Unable to upload", nil) forChat:chat];
+	}
+}
+
+ at end
diff -r 384648bd38d8 -r 6f998f0fe450 Plugins/WebKit Message View/AIWebKitDelegate.m
--- a/Plugins/WebKit Message View/AIWebKitDelegate.m	Thu Oct 28 00:18:28 2010 -0500
+++ b/Plugins/WebKit Message View/AIWebKitDelegate.m	Thu Oct 28 13:57:20 2010 -0400
@@ -101,7 +101,7 @@
     NSInteger actionKey = [[actionInformation objectForKey: WebActionNavigationTypeKey] integerValue];
     if (actionKey == WebNavigationTypeOther) {
 		[listener use];
-	} else if ([[((NSString *)LSCopyDefaultHandlerForURLScheme((CFStringRef)request.URL.scheme)) autorelease].lowercaseString isEqualToString:@"com.adiumx.adiumx"]) {
+	} else if ([[[((NSString *)LSCopyDefaultHandlerForURLScheme((CFStringRef)request.URL.scheme)) autorelease] lowercaseString] isEqualToString:@"com.adiumx.adiumx"]) {
 		// We're the default for this URL, let's open it ourself.
 		[[NSNotificationCenter defaultCenter] postNotificationName:@"AIURLHandleNotification" object:request.URL.absoluteString];
 		




More information about the commits mailing list